mirror of
https://github.com/openvswitch/ovs
synced 2025-10-25 15:07:05 +00:00
ovsdb-idl: Simplify usage of ovsdb_idl_run().
It makes client code simpler if ovsdb_idl_run() simply lets the caller know whether anything changed.
This commit is contained in:
@@ -231,9 +231,10 @@ ovsdb_idl_clear(struct ovsdb_idl *idl)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
ovsdb_idl_run(struct ovsdb_idl *idl)
|
||||
{
|
||||
unsigned int initial_change_seqno = idl->change_seqno;
|
||||
int i;
|
||||
|
||||
assert(!idl->txn);
|
||||
@@ -290,6 +291,8 @@ ovsdb_idl_run(struct ovsdb_idl *idl)
|
||||
}
|
||||
jsonrpc_msg_destroy(msg);
|
||||
}
|
||||
|
||||
return initial_change_seqno != idl->change_seqno;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -31,7 +31,7 @@ struct ovsdb_idl *ovsdb_idl_create(const char *remote,
|
||||
const struct ovsdb_idl_class *);
|
||||
void ovsdb_idl_destroy(struct ovsdb_idl *);
|
||||
|
||||
void ovsdb_idl_run(struct ovsdb_idl *);
|
||||
bool ovsdb_idl_run(struct ovsdb_idl *);
|
||||
void ovsdb_idl_wait(struct ovsdb_idl *);
|
||||
|
||||
unsigned int ovsdb_idl_get_seqno(const struct ovsdb_idl *);
|
||||
|
||||
@@ -1565,31 +1565,6 @@ print_idl(struct ovsdb_idl *idl, int step)
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
print_updated_idl(struct ovsdb_idl *idl, struct jsonrpc *rpc,
|
||||
int step, unsigned int seqno)
|
||||
{
|
||||
for (;;) {
|
||||
unsigned int new_seqno;
|
||||
|
||||
if (rpc) {
|
||||
jsonrpc_run(rpc);
|
||||
}
|
||||
ovsdb_idl_run(idl);
|
||||
new_seqno = ovsdb_idl_get_seqno(idl);
|
||||
if (new_seqno != seqno) {
|
||||
print_idl(idl, step);
|
||||
return new_seqno;
|
||||
}
|
||||
|
||||
if (rpc) {
|
||||
jsonrpc_wait(rpc);
|
||||
}
|
||||
ovsdb_idl_wait(idl);
|
||||
poll_block();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
parse_uuids(const struct json *json, struct ovsdb_symbol_table *symtab,
|
||||
size_t *n)
|
||||
@@ -1786,8 +1761,19 @@ do_idl(int argc, char *argv[])
|
||||
/* The previous transaction didn't change anything. */
|
||||
arg++;
|
||||
} else {
|
||||
seqno = print_updated_idl(idl, rpc, step++, seqno);
|
||||
/* Wait for update. */
|
||||
while (ovsdb_idl_get_seqno(idl) == seqno && !ovsdb_idl_run(idl)) {
|
||||
jsonrpc_run(rpc);
|
||||
|
||||
ovsdb_idl_wait(idl);
|
||||
jsonrpc_wait(rpc);
|
||||
poll_block();
|
||||
}
|
||||
|
||||
/* Print update. */
|
||||
print_idl(idl, step++);
|
||||
}
|
||||
seqno = ovsdb_idl_get_seqno(idl);
|
||||
|
||||
if (!strcmp(arg, "reconnect")) {
|
||||
printf("%03d: reconnect\n", step++);
|
||||
@@ -1816,7 +1802,11 @@ do_idl(int argc, char *argv[])
|
||||
if (rpc) {
|
||||
jsonrpc_close(rpc);
|
||||
}
|
||||
print_updated_idl(idl, NULL, step++, seqno);
|
||||
while (ovsdb_idl_get_seqno(idl) == seqno && !ovsdb_idl_run(idl)) {
|
||||
ovsdb_idl_wait(idl);
|
||||
poll_block();
|
||||
}
|
||||
print_idl(idl, step++);
|
||||
ovsdb_idl_destroy(idl);
|
||||
printf("%03d: done\n", step);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,6 @@ int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct ovsdb_idl *idl;
|
||||
unsigned int seqno;
|
||||
struct vsctl_command *commands;
|
||||
size_t n_commands;
|
||||
char *args;
|
||||
@@ -147,19 +146,13 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Now execute the commands. */
|
||||
idl = the_idl = ovsdb_idl_create(db, &ovsrec_idl_class);
|
||||
seqno = ovsdb_idl_get_seqno(idl);
|
||||
trials = 0;
|
||||
for (;;) {
|
||||
unsigned int new_seqno;
|
||||
|
||||
ovsdb_idl_run(idl);
|
||||
new_seqno = ovsdb_idl_get_seqno(idl);
|
||||
if (new_seqno != seqno) {
|
||||
if (ovsdb_idl_run(idl)) {
|
||||
if (++trials > 5) {
|
||||
vsctl_fatal("too many database inconsistency failures");
|
||||
}
|
||||
do_vsctl(args, commands, n_commands, idl);
|
||||
seqno = new_seqno;
|
||||
}
|
||||
|
||||
ovsdb_idl_wait(idl);
|
||||
|
||||
@@ -62,9 +62,7 @@ main(int argc, char *argv[])
|
||||
struct signal *sighup;
|
||||
struct ovsdb_idl *idl;
|
||||
const char *remote;
|
||||
bool need_reconfigure;
|
||||
bool inited, exiting;
|
||||
unsigned int idl_seqno;
|
||||
int retval;
|
||||
|
||||
proctitle_init(argc, argv);
|
||||
@@ -89,27 +87,27 @@ main(int argc, char *argv[])
|
||||
daemonize_complete();
|
||||
|
||||
idl = ovsdb_idl_create(remote, &ovsrec_idl_class);
|
||||
idl_seqno = ovsdb_idl_get_seqno(idl);
|
||||
|
||||
need_reconfigure = false;
|
||||
inited = false;
|
||||
exiting = false;
|
||||
while (!exiting) {
|
||||
bool need_reconfigure;
|
||||
|
||||
if (signal_poll(sighup)) {
|
||||
vlog_reopen_log_file();
|
||||
}
|
||||
|
||||
need_reconfigure = false;
|
||||
if (inited && bridge_run()) {
|
||||
need_reconfigure = true;
|
||||
}
|
||||
ovsdb_idl_run(idl);
|
||||
if (idl_seqno != ovsdb_idl_get_seqno(idl)) {
|
||||
idl_seqno = ovsdb_idl_get_seqno(idl);
|
||||
if (ovsdb_idl_run(idl)) {
|
||||
need_reconfigure = true;
|
||||
}
|
||||
|
||||
if (need_reconfigure) {
|
||||
const struct ovsrec_open_vswitch *cfg;
|
||||
|
||||
need_reconfigure = false;
|
||||
cfg = ovsrec_open_vswitch_first(idl);
|
||||
if (cfg) {
|
||||
if (inited) {
|
||||
|
||||
Reference in New Issue
Block a user