[ovs-dev] [ovn-controller-vtep V5 07/12] ovsdb-idl: Move get_initial_snapshot() to ovsdb-idl.
Alex Wang
alexw at nicira.com
Fri Aug 7 07:46:48 UTC 2015
The same function is defined in both ovn-controller.c and
ovn-controller-vtep.c, so worth librarizing.
Signed-off-by: Alex Wang <alexw at nicira.com>
---
V5:
- new patch.
---
lib/ovsdb-idl.c | 15 +++++++++++++++
lib/ovsdb-idl.h | 1 +
ovn/controller-vtep/ovn-controller-vtep.c | 17 ++---------------
ovn/controller/ovn-controller.c | 17 ++---------------
4 files changed, 20 insertions(+), 30 deletions(-)
diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
index f0d5d9c..00b900d 100644
--- a/lib/ovsdb-idl.c
+++ b/lib/ovsdb-idl.c
@@ -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();
+ }
+}
/* 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
diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h
index 28aa787..003ff60 100644
--- a/lib/ovsdb-idl.h
+++ b/lib/ovsdb-idl.h
@@ -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 *);
/* ovsdb_idl_loop provides an easy way to manage the transactions related
diff --git a/ovn/controller-vtep/ovn-controller-vtep.c b/ovn/controller-vtep/ovn-controller-vtep.c
index e8bfcbd..2f9dc10 100644
--- a/ovn/controller-vtep/ovn-controller-vtep.c
+++ b/ovn/controller-vtep/ovn-controller-vtep.c
@@ -49,19 +49,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[])
{
@@ -94,12 +81,12 @@ main(int argc, char *argv[])
ovsdb_idl_add_table(vtep_idl_loop.idl, &vteprec_table_global);
ovsdb_idl_add_column(vtep_idl_loop.idl,
&vteprec_global_col_switches);
- 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, false, true));
- get_initial_snapshot(ovnsb_idl_loop.idl);
+ ovsdb_idl_get_initial_snapshot(ovnsb_idl_loop.idl);
/* Main loop. */
exiting = false;
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index bb2b840..8e93a0f 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -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;
--
1.7.9.5
More information about the dev
mailing list