From: Ben Pfaff Date: Wed, 9 Jun 2010 22:18:17 +0000 (-0700) Subject: ovsdb-idl: Simplify usage of ovsdb_idl_run(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ea21243f5a6002528d33d2bd58ce41a9d03a4c4;p=openvswitch 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. --- diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index ca77cc2e..da975793 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -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 diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h index 31fae984..88bd7b3a 100644 --- a/lib/ovsdb-idl.h +++ b/lib/ovsdb-idl.h @@ -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 *); diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c index 21825d74..2c8470e1 100644 --- a/tests/test-ovsdb.c +++ b/tests/test-ovsdb.c @@ -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); } diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index c16767d7..9d34267b 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -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); diff --git a/vswitchd/ovs-vswitchd.c b/vswitchd/ovs-vswitchd.c index 64781560..5c8c80a5 100644 --- a/vswitchd/ovs-vswitchd.c +++ b/vswitchd/ovs-vswitchd.c @@ -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) {