Skip to content

Commit

Permalink
ovn: Add '--restart' flag to ovn-controller exit.
Browse files Browse the repository at this point in the history
When "--restart" is passed to ovn-controller's exit command, then
database entries are not removed for this hypervisor. This means that
* Encaps
* Chassis
* OVS ports
are not removed.

The reasoning is that if the intent is to restart ovn-controller, this
will allow for tunnels to remain up and allow for traffic not to be
interrupted during the restart. When ovn-controller is started again, it
picks back up from where it was.

Signed-off-by: Mark Michelson <mmichels@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
  • Loading branch information
putnopvut authored and blp committed Aug 2, 2018
1 parent 50c9a84 commit f508fcc
Showing 1 changed file with 52 additions and 40 deletions.
92 changes: 52 additions & 40 deletions controller/ovn-controller.c
Expand Up @@ -544,11 +544,18 @@ ctrl_register_ovs_idl(struct ovsdb_idl *ovs_idl)
physical_register_ovs_idl(ovs_idl);
}

struct ovn_controller_exit_args {
bool *exiting;
bool *restart;
};

int
main(int argc, char *argv[])
{
struct unixctl_server *unixctl;
bool exiting;
bool restart;
struct ovn_controller_exit_args exit_args = {&exiting, &restart};
int retval;

ovs_cmdl_proctitle_init(argc, argv);
Expand All @@ -563,7 +570,8 @@ main(int argc, char *argv[])
if (retval) {
exit(EXIT_FAILURE);
}
unixctl_command_register("exit", "", 0, 0, ovn_controller_exit, &exiting);
unixctl_command_register("exit", "", 0, 1, ovn_controller_exit,
&exit_args);

/* Initialize group ids for loadbalancing. */
struct ovn_extend_table group_table;
Expand Down Expand Up @@ -641,6 +649,7 @@ main(int argc, char *argv[])
stopwatch_create(CONTROLLER_LOOP_STOPWATCH_NAME, SW_MS);
/* Main loop. */
exiting = false;
restart = false;
while (!exiting) {
/* Check OVN SB database. */
char *new_ovnsb_remote = get_ovnsb_remote(ovs_idl_loop.idl);
Expand Down Expand Up @@ -859,42 +868,45 @@ main(int argc, char *argv[])
}
}

/* It's time to exit. Clean up the databases. */
bool done = false;
while (!done) {
struct ovsdb_idl_txn *ovs_idl_txn = ovsdb_idl_loop_run(&ovs_idl_loop);
struct ovsdb_idl_txn *ovnsb_idl_txn
= ovsdb_idl_loop_run(&ovnsb_idl_loop);
/* It's time to exit. Clean up the databases if we are not restarting */
if (!restart) {
bool done = false;
while (!done) {
struct ovsdb_idl_txn *ovs_idl_txn
= ovsdb_idl_loop_run(&ovs_idl_loop);
struct ovsdb_idl_txn *ovnsb_idl_txn
= ovsdb_idl_loop_run(&ovnsb_idl_loop);

const struct ovsrec_bridge_table *bridge_table
= ovsrec_bridge_table_get(ovs_idl_loop.idl);
const struct ovsrec_open_vswitch_table *ovs_table
= ovsrec_open_vswitch_table_get(ovs_idl_loop.idl);

const struct sbrec_port_binding_table *port_binding_table
= sbrec_port_binding_table_get(ovnsb_idl_loop.idl);

const struct ovsrec_bridge *br_int = get_br_int(ovs_idl_txn,
bridge_table,
ovs_table);
const char *chassis_id = get_chassis_id(ovs_table);
const struct sbrec_chassis *chassis
= (chassis_id
? chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id)
: NULL);

/* Run all of the cleanup functions, even if one of them returns
* false. We're done if all of them return true. */
done = binding_cleanup(ovnsb_idl_txn, port_binding_table, chassis);
done = chassis_cleanup(ovnsb_idl_txn, chassis) && done;
done = encaps_cleanup(ovs_idl_txn, br_int) && done;
if (done) {
poll_immediate_wake();
}

const struct ovsrec_bridge_table *bridge_table
= ovsrec_bridge_table_get(ovs_idl_loop.idl);
const struct ovsrec_open_vswitch_table *ovs_table
= ovsrec_open_vswitch_table_get(ovs_idl_loop.idl);

const struct sbrec_port_binding_table *port_binding_table
= sbrec_port_binding_table_get(ovnsb_idl_loop.idl);

const struct ovsrec_bridge *br_int = get_br_int(ovs_idl_txn,
bridge_table,
ovs_table);
const char *chassis_id = get_chassis_id(ovs_table);
const struct sbrec_chassis *chassis
= (chassis_id
? chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id)
: NULL);

/* Run all of the cleanup functions, even if one of them returns false.
* We're done if all of them return true. */
done = binding_cleanup(ovnsb_idl_txn, port_binding_table, chassis);
done = chassis_cleanup(ovnsb_idl_txn, chassis) && done;
done = encaps_cleanup(ovs_idl_txn, br_int) && done;
if (done) {
poll_immediate_wake();
ovsdb_idl_loop_commit_and_wait(&ovnsb_idl_loop);
ovsdb_idl_loop_commit_and_wait(&ovs_idl_loop);
poll_block();
}

ovsdb_idl_loop_commit_and_wait(&ovnsb_idl_loop);
ovsdb_idl_loop_commit_and_wait(&ovs_idl_loop);
poll_block();
}

unixctl_server_destroy(unixctl);
Expand Down Expand Up @@ -1010,12 +1022,12 @@ usage(void)
}

static void
ovn_controller_exit(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED, void *exiting_)
ovn_controller_exit(struct unixctl_conn *conn, int argc,
const char *argv[], void *exit_args_)
{
bool *exiting = exiting_;
*exiting = true;

struct ovn_controller_exit_args *exit_args = exit_args_;
*exit_args->exiting = true;
*exit_args->restart = argc == 2 && !strcmp(argv[1], "--restart");
unixctl_command_reply(conn, NULL);
}

Expand Down

0 comments on commit f508fcc

Please sign in to comment.