[ovs-dev] [PATCH] ovs-vsctl: reconnect to the database if connection was dropped
Ansis Atteka
aatteka at nicira.com
Tue Feb 18 22:34:58 UTC 2014
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 <spiro at nicira.com>
Signed-Off-By: Ansis Atteka <aatteka at nicira.com>
---
lib/jsonrpc.c | 8 ++++++++
lib/jsonrpc.h | 1 +
lib/ovsdb-idl.c | 8 ++++++++
lib/ovsdb-idl.h | 1 +
utilities/ovs-vsctl.c | 5 +++++
5 files changed, 23 insertions(+)
diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c
index cef96a9..643a3c5 100644
--- a/lib/jsonrpc.c
+++ b/lib/jsonrpc.c
@@ -1091,6 +1091,14 @@ jsonrpc_session_get_reconnect_stats(const struct jsonrpc_session *s,
}
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)
{
reconnect_force_reconnect(s->reconnect, time_msec());
diff --git a/lib/jsonrpc.h b/lib/jsonrpc.h
index 5397200..b711d1a 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 02bee75..7556b7f 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 6b5e198..cb0ad11 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 918ca67..c8ee16a 100644
--- a/utilities/ovs-vsctl.c
+++ b/utilities/ovs-vsctl.c
@@ -4147,6 +4147,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) {
--
1.8.1.2
More information about the dev
mailing list