From af96ccd24690553a0f8e2dbe9ee72530f18629c6 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 3 Mar 2010 12:55:39 -0800 Subject: [PATCH] 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(). --- lib/ovsdb-idl.c | 17 +++++++++++++++++ lib/ovsdb-idl.h | 1 + tests/test-ovsdb.c | 7 +------ utilities/ovs-vsctl.c | 7 +------ vswitchd/ovs-brcompatd.c | 7 +------ 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index f60ec4b1..fd4607de 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 d4514272..cfbb97cc 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 48a5007f..b2ab4c60 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 1c00f436..4efb1d0f 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 dd7ea42f..aa90c394 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: -- 2.30.2