ovsdb-idl: New function ovsdb_idl_txn_commit_block().
authorBen Pfaff <blp@nicira.com>
Wed, 3 Mar 2010 20:55:39 +0000 (12:55 -0800)
committerBen Pfaff <blp@nicira.com>
Wed, 3 Mar 2010 20:55:39 +0000 (12:55 -0800)
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
lib/ovsdb-idl.h
tests/test-ovsdb.c
utilities/ovs-vsctl.c
vswitchd/ovs-brcompatd.c

index f60ec4b..fd4607d 100644 (file)
@@ -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)
 {
index d451427..cfbb97c 100644 (file)
@@ -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 *);
index 48a5007..b2ab4c6 100644 (file)
@@ -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) {
index 1c00f43..4efb1d0 100644 (file)
@@ -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);
     }
index dd7ea42..aa90c39 100644 (file)
@@ -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: