Skip to content

Commit

Permalink
ovsdb-idl: Move get_initial_snapshot() to ovsdb-idl.
Browse files Browse the repository at this point in the history
The same function is defined in both ovn-controller.c and
ovn-controller-vtep.c, so worth librarizing.

Signed-off-by: Alex Wang <[email protected]>
Acked-by: Russell Bryant <[email protected]>
  • Loading branch information
yew011 committed Aug 11, 2015
1 parent 00db2a6 commit a660eac
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
15 changes: 15 additions & 0 deletions lib/ovsdb-idl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/ovsdb-idl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 2 additions & 15 deletions ovn/controller-vtep/ovn-controller-vtep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[])
{
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 2 additions & 15 deletions ovn/controller/ovn-controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a660eac

Please sign in to comment.