ovsdb-idl: Move get_initial_snapshot() to ovsdb-idl.
authorAlex Wang <alexw@nicira.com>
Tue, 4 Aug 2015 21:49:11 +0000 (14:49 -0700)
committerAlex Wang <alexw@nicira.com>
Tue, 11 Aug 2015 02:53:49 +0000 (19:53 -0700)
The same function is defined in both ovn-controller.c and
ovn-controller-vtep.c, so worth librarizing.

Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Russell Bryant <rbryant@redhat.com>
lib/ovsdb-idl.c
lib/ovsdb-idl.h
ovn/controller-vtep/ovn-controller-vtep.c
ovn/controller/ovn-controller.c

index f0d5d9c..00b900d 100644 (file)
@@ -2496,6 +2496,21 @@ ovsdb_idl_txn_get_idl (struct ovsdb_idl_txn *txn)
 {
     return txn->idl;
 }
+
+/* Blocks until 'idl' successfully connects to the remote database and
+ * retrieves its contents. */
+void
+ovsdb_idl_get_initial_snapshot(struct ovsdb_idl *idl)
+{
+    while (1) {
+        ovsdb_idl_run(idl);
+        if (ovsdb_idl_has_ever_connected(idl)) {
+            return;
+        }
+        ovsdb_idl_wait(idl);
+        poll_block();
+    }
+}
 \f
 /* If 'lock_name' is nonnull, configures 'idl' to obtain the named lock from
  * the database server and to avoid modifying the database when the lock cannot
index 5194122..ac63ec9 100644 (file)
@@ -222,6 +222,7 @@ const struct ovsdb_idl_row *ovsdb_idl_txn_insert(
     const struct uuid *);
 
 struct ovsdb_idl *ovsdb_idl_txn_get_idl (struct ovsdb_idl_txn *);
+void ovsdb_idl_get_initial_snapshot(struct ovsdb_idl *);
 \f
 
 /* ovsdb_idl_loop provides an easy way to manage the transactions related
index c83218f..21a92de 100644 (file)
@@ -47,19 +47,6 @@ OVS_NO_RETURN static void usage(void);
 static char *vtep_remote;
 static char *ovnsb_remote;
 
-static void
-get_initial_snapshot(struct ovsdb_idl *idl)
-{
-    while (1) {
-        ovsdb_idl_run(idl);
-        if (ovsdb_idl_has_ever_connected(idl)) {
-            return;
-        }
-        ovsdb_idl_wait(idl);
-        poll_block();
-    }
-}
-
 int
 main(int argc, char *argv[])
 {
@@ -89,12 +76,12 @@ main(int argc, char *argv[])
     /* Connect to VTEP database. */
     struct ovsdb_idl_loop vtep_idl_loop = OVSDB_IDL_LOOP_INITIALIZER(
         ovsdb_idl_create(vtep_remote, &vteprec_idl_class, true, true));
-    get_initial_snapshot(vtep_idl_loop.idl);
+    ovsdb_idl_get_initial_snapshot(vtep_idl_loop.idl);
 
     /* Connect to OVN SB database. */
     struct ovsdb_idl_loop ovnsb_idl_loop = OVSDB_IDL_LOOP_INITIALIZER(
         ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class, true, true));
-    get_initial_snapshot(ovnsb_idl_loop.idl);
+    ovsdb_idl_get_initial_snapshot(ovnsb_idl_loop.idl);
 
     /* Main loop. */
     exiting = false;
index bb2b840..8e93a0f 100644 (file)
@@ -57,19 +57,6 @@ OVS_NO_RETURN static void usage(void);
 
 static char *ovs_remote;
 
-static void
-get_initial_snapshot(struct ovsdb_idl *idl)
-{
-    while (1) {
-        ovsdb_idl_run(idl);
-        if (ovsdb_idl_has_ever_connected(idl)) {
-            return;
-        }
-        ovsdb_idl_wait(idl);
-        poll_block();
-    }
-}
-
 static const struct ovsrec_bridge *
 get_br_int(struct ovsdb_idl *ovs_idl)
 {
@@ -167,13 +154,13 @@ main(int argc, char *argv[])
     encaps_register_ovs_idl(ovs_idl_loop.idl);
     binding_register_ovs_idl(ovs_idl_loop.idl);
     physical_register_ovs_idl(ovs_idl_loop.idl);
-    get_initial_snapshot(ovs_idl_loop.idl);
+    ovsdb_idl_get_initial_snapshot(ovs_idl_loop.idl);
 
     /* Connect to OVN SB database. */
     char *ovnsb_remote = get_ovnsb_remote(ovs_idl_loop.idl);
     struct ovsdb_idl_loop ovnsb_idl_loop = OVSDB_IDL_LOOP_INITIALIZER(
         ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class, true, true));
-    get_initial_snapshot(ovnsb_idl_loop.idl);
+    ovsdb_idl_get_initial_snapshot(ovnsb_idl_loop.idl);
 
     /* Main loop. */
     exiting = false;