From: Ansis Atteka Date: Tue, 18 Feb 2014 21:19:36 +0000 (-0800) Subject: ovs-vsctl: reconnect to the database if connection was dropped X-Git-Url: http://git.onelab.eu/?p=sliver-openvswitch.git;a=commitdiff_plain;h=705d7a393005054a78ede0394b0f7451e60136b4 ovs-vsctl: reconnect to the database if connection was dropped If ovs-vsctl has to wait for ovs-vswitchd to reconfigure itself according to the new database, then sometimes ovs-vsctl could end up stuck in the event loop if OVSDB connection was dropped while ovs-vsctl was still running. This patch fixes this problem by letting ovs-vsctl to reconnect to the OVSDB, if it has to wait cur_cfg field to be updated. Issue: 1191997 Reported-by: Spiro Kourtessis Signed-Off-By: Ansis Atteka --- diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c index cef96a9cc..643a3c5d0 100644 --- a/lib/jsonrpc.c +++ b/lib/jsonrpc.c @@ -1090,6 +1090,14 @@ jsonrpc_session_get_reconnect_stats(const struct jsonrpc_session *s, reconnect_get_stats(s->reconnect, time_msec(), stats); } +void +jsonrpc_session_enable_reconnect(struct jsonrpc_session *s) +{ + reconnect_set_max_tries(s->reconnect, UINT_MAX); + reconnect_set_backoff(s->reconnect, RECONNECT_DEFAULT_MIN_BACKOFF, + RECONNECT_DEFAULT_MAX_BACKOFF); +} + void jsonrpc_session_force_reconnect(struct jsonrpc_session *s) { diff --git a/lib/jsonrpc.h b/lib/jsonrpc.h index 539720027..b711d1ab6 100644 --- a/lib/jsonrpc.h +++ b/lib/jsonrpc.h @@ -123,6 +123,7 @@ int jsonrpc_session_get_last_error(const struct jsonrpc_session *); void jsonrpc_session_get_reconnect_stats(const struct jsonrpc_session *, struct reconnect_stats *); +void jsonrpc_session_enable_reconnect(struct jsonrpc_session *); void jsonrpc_session_force_reconnect(struct jsonrpc_session *); void jsonrpc_session_set_max_backoff(struct jsonrpc_session *, diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 02bee7520..7556b7f39 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -394,6 +394,14 @@ ovsdb_idl_has_ever_connected(const struct ovsdb_idl *idl) return ovsdb_idl_get_seqno(idl) != 0; } +/* Reconfigures 'idl' so that it would reconnect to the database, if + * connection was dropped. */ +void +ovsdb_idl_enable_reconnect(struct ovsdb_idl *idl) +{ + jsonrpc_session_enable_reconnect(idl->session); +} + /* Forces 'idl' to drop its connection to the database and reconnect. In the * meantime, the contents of 'idl' will not change. */ void diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h index 6b5e198b2..cb0ad1190 100644 --- a/lib/ovsdb-idl.h +++ b/lib/ovsdb-idl.h @@ -57,6 +57,7 @@ bool ovsdb_idl_is_lock_contended(const struct ovsdb_idl *); unsigned int ovsdb_idl_get_seqno(const struct ovsdb_idl *); bool ovsdb_idl_has_ever_connected(const struct ovsdb_idl *); +void ovsdb_idl_enable_reconnect(struct ovsdb_idl *); void ovsdb_idl_force_reconnect(struct ovsdb_idl *); void ovsdb_idl_verify_write_only(struct ovsdb_idl *); diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index af6ae5f2e..c563eee65 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -4123,6 +4123,11 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands, free(commands); if (wait_for_reload && status != TXN_UNCHANGED) { + /* Even, if --retry flag was not specified, ovs-vsctl still + * has to retry to establish OVSDB connection, if wait_for_reload + * was set. Otherwise, ovs-vsctl would end up waiting forever + * until cur_cfg would be updated. */ + ovsdb_idl_enable_reconnect(idl); for (;;) { ovsdb_idl_run(idl); OVSREC_OPEN_VSWITCH_FOR_EACH (ovs, idl) {