From: Ben Pfaff Date: Wed, 3 Mar 2010 20:55:39 +0000 (-0800) Subject: ovsdb-idl: New function ovsdb_idl_txn_commit_block(). X-Git-Tag: v1.0.0~259^2~56 X-Git-Url: http://git.cascardo.eti.br/?a=commitdiff_plain;h=af96ccd24690553a0f8e2dbe9ee72530f18629c6;p=cascardo%2Fovs.git ovsdb-idl: New function ovsdb_idl_txn_commit_block(). This commit factors out common code from multiple callers of ovsdb_idl_txn_commit() into a new function ovsdb_idl_txn_commit_block(). --- diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index f60ec4b10..fd4607de8 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -1264,6 +1264,23 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) return txn->status; } +/* Attempts to commit 'txn', blocking until the commit either succeeds or + * fails. Returns the final commit status, which may be any TXN_* value other + * than TXN_INCOMPLETE. */ +enum ovsdb_idl_txn_status +ovsdb_idl_txn_commit_block(struct ovsdb_idl_txn *txn) +{ + enum ovsdb_idl_txn_status status; + + while ((status = ovsdb_idl_txn_commit(txn)) == TXN_INCOMPLETE) { + ovsdb_idl_run(txn->idl); + ovsdb_idl_wait(txn->idl); + ovsdb_idl_txn_wait(txn); + poll_block(); + } + return status; +} + int64_t ovsdb_idl_txn_get_increment_new_value(const struct ovsdb_idl_txn *txn) { diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h index d45142727..cfbb97cc1 100644 --- a/lib/ovsdb-idl.h +++ b/lib/ovsdb-idl.h @@ -65,6 +65,7 @@ void ovsdb_idl_txn_increment(struct ovsdb_idl_txn *, const char *table, void ovsdb_idl_txn_destroy(struct ovsdb_idl_txn *); void ovsdb_idl_txn_wait(const struct ovsdb_idl_txn *); enum ovsdb_idl_txn_status ovsdb_idl_txn_commit(struct ovsdb_idl_txn *); +enum ovsdb_idl_txn_status ovsdb_idl_txn_commit_block(struct ovsdb_idl_txn *); void ovsdb_idl_txn_abort(struct ovsdb_idl_txn *); const char *ovsdb_idl_txn_get_error(const struct ovsdb_idl_txn *); diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c index 48a5007f3..b2ab4c600 100644 --- a/tests/test-ovsdb.c +++ b/tests/test-ovsdb.c @@ -1735,12 +1735,7 @@ idl_set(struct ovsdb_idl *idl, char *commands, int step) } } - while ((status = ovsdb_idl_txn_commit(txn)) == TXN_INCOMPLETE) { - ovsdb_idl_run(idl); - ovsdb_idl_wait(idl); - ovsdb_idl_txn_wait(txn); - poll_block(); - } + status = ovsdb_idl_txn_commit_block(txn); printf("%03d: commit, status=%s", step, ovsdb_idl_txn_status_to_string(status)); if (increment) { diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index 1c00f436e..4efb1d0f5 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -2386,12 +2386,7 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands, vsctl_context_done(&ctx, c); } - while ((status = ovsdb_idl_txn_commit(txn)) == TXN_INCOMPLETE) { - ovsdb_idl_run(idl); - ovsdb_idl_wait(idl); - ovsdb_idl_txn_wait(txn); - poll_block(); - } + status = ovsdb_idl_txn_commit_block(txn); if (wait_for_reload && status == TXN_SUCCESS) { next_cfg = ovsdb_idl_txn_get_increment_new_value(txn); } diff --git a/vswitchd/ovs-brcompatd.c b/vswitchd/ovs-brcompatd.c index dd7ea42f7..aa90c3940 100644 --- a/vswitchd/ovs-brcompatd.c +++ b/vswitchd/ovs-brcompatd.c @@ -1222,12 +1222,7 @@ main(int argc, char *argv[]) poll_timer_wait(prune_timeout); } - while ((status = ovsdb_idl_txn_commit(txn)) == TXN_INCOMPLETE) { - ovsdb_idl_run(idl); - ovsdb_idl_wait(idl); - ovsdb_idl_txn_wait(txn); - poll_block(); - } + status = ovsdb_idl_txn_commit_block(txn); switch (status) { case TXN_INCOMPLETE: