[ovs-dev] [v2] ovsdb-server: Refactoring and clean up remote status reporting.

Andy Zhou azhou at ovn.org
Sat Feb 27 03:17:46 UTC 2016


When reporting remote status, A listening remote will randomly
pick a session and report its session status. This does not seem
to make much sense. It is probably better to leave those fields
untouched.

Update ovs-vswitchd.conf.db(5) to match the change in implementation.

Signed-off-by: Andy Zhou <azhou at ovn.org>

------
v1->v2:  * fix xml file styles and typos.
         * alwyas set n_connections in
           ovsdb_jsonrpc_server_get_remote_status();
         * fix function comment of
           ovsdb_jsonrpc_server_get_remote_status();
---
 ovsdb/jsonrpc-server.c | 58 +++++++++++++++++++++++++++++++++++---------------
 vswitchd/vswitch.xml   | 40 +++++++++++++++++++++++-----------
 2 files changed, 68 insertions(+), 30 deletions(-)

diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c
index 6f46dbc..15dbc4e 100644
--- a/ovsdb/jsonrpc-server.c
+++ b/ovsdb/jsonrpc-server.c
@@ -63,9 +63,12 @@ static void ovsdb_jsonrpc_session_close_all(struct ovsdb_jsonrpc_remote *);
 static void ovsdb_jsonrpc_session_reconnect_all(struct ovsdb_jsonrpc_remote *);
 static void ovsdb_jsonrpc_session_set_all_options(
     struct ovsdb_jsonrpc_remote *, const struct ovsdb_jsonrpc_options *);
-static bool ovsdb_jsonrpc_session_get_status(
+static bool ovsdb_jsonrpc_active_session_get_status(
     const struct ovsdb_jsonrpc_remote *,
     struct ovsdb_jsonrpc_remote_status *);
+static void ovsdb_jsonrpc_session_get_status(
+    const struct ovsdb_jsonrpc_session *,
+    struct ovsdb_jsonrpc_remote_status *);
 static void ovsdb_jsonrpc_session_unlock_all(struct ovsdb_jsonrpc_session *);
 static void ovsdb_jsonrpc_session_unlock__(struct ovsdb_lock_waiter *);
 static void ovsdb_jsonrpc_session_send(struct ovsdb_jsonrpc_session *,
@@ -275,7 +278,7 @@ ovsdb_jsonrpc_server_del_remote(struct shash_node *node)
 /* Stores status information for the remote named 'target', which should have
  * been configured on 'svr' with a call to ovsdb_jsonrpc_server_set_remotes(),
  * into '*status'.  On success returns true, on failure (if 'svr' doesn't have
- * a remote named 'target' or if that remote is an inbound remote that has no
+ * a remote named 'target' or if that remote is an outbound remote that has no
  * active connections) returns false.  On failure, 'status' will be zeroed.
  */
 bool
@@ -288,7 +291,19 @@ ovsdb_jsonrpc_server_get_remote_status(
     memset(status, 0, sizeof *status);
 
     remote = shash_find_data(&svr->remotes, target);
-    return remote && ovsdb_jsonrpc_session_get_status(remote, status);
+
+    if (!remote) {
+        return false;
+    }
+
+    if (remote->listener) {
+        status->bound_port = pstream_get_bound_port(remote->listener);
+        status->is_connected = !list_is_empty(&remote->sessions);
+        status->n_connections = list_size(&remote->sessions);
+        return true;
+    }
+
+    return ovsdb_jsonrpc_active_session_get_status(remote, status);
 }
 
 void
@@ -583,24 +598,37 @@ ovsdb_jsonrpc_session_set_all_options(
     }
 }
 
+/* Sets the 'status' of for the 'remote' with an outgoing connection.   */
 static bool
-ovsdb_jsonrpc_session_get_status(const struct ovsdb_jsonrpc_remote *remote,
-                                 struct ovsdb_jsonrpc_remote_status *status)
+ovsdb_jsonrpc_active_session_get_status(
+    const struct ovsdb_jsonrpc_remote *remote,
+    struct ovsdb_jsonrpc_remote_status *status)
 {
+    const struct ovs_list *sessions = &remote->sessions;
     const struct ovsdb_jsonrpc_session *s;
+
+    if (list_is_empty(sessions)) {
+        return false;
+    }
+
+    ovs_assert(list_is_singleton(sessions));
+    s = CONTAINER_OF(list_front(sessions), struct ovsdb_jsonrpc_session, node);
+    ovsdb_jsonrpc_session_get_status(s, status);
+    status->n_connections = 1;
+
+    return true;
+}
+
+static void
+ovsdb_jsonrpc_session_get_status(const struct ovsdb_jsonrpc_session *session,
+                                 struct ovsdb_jsonrpc_remote_status *status)
+{
+    const struct ovsdb_jsonrpc_session *s = session;
     const struct jsonrpc_session *js;
     struct ovsdb_lock_waiter *waiter;
     struct reconnect_stats rstats;
     struct ds locks_held, locks_waiting, locks_lost;
 
-    status->bound_port = (remote->listener
-                          ? pstream_get_bound_port(remote->listener)
-                          : htons(0));
-
-    if (list_is_empty(&remote->sessions)) {
-        return false;
-    }
-    s = CONTAINER_OF(remote->sessions.next, struct ovsdb_jsonrpc_session, node);
     js = s->js;
 
     status->is_connected = jsonrpc_session_is_connected(js);
@@ -630,10 +658,6 @@ ovsdb_jsonrpc_session_get_status(const struct ovsdb_jsonrpc_remote *remote,
     status->locks_held = ds_steal_cstr(&locks_held);
     status->locks_waiting = ds_steal_cstr(&locks_waiting);
     status->locks_lost = ds_steal_cstr(&locks_lost);
-
-    status->n_connections = list_size(&remote->sessions);
-
-    return true;
 }
 
 /* Examines 'request' to determine the database to which it relates, and then
diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml
index bccea55..15f71de 100644
--- a/vswitchd/vswitch.xml
+++ b/vswitchd/vswitch.xml
@@ -4193,7 +4193,28 @@
     </group>
 
     <group title="Status">
-      <column name="is_connected">
+      <p>
+        Key-value pair of <ref column="is_connected"/> is always updated.
+        Other key-value pairs in the status columns may be updated depends
+        on the <ref column="target"/> type.
+      </p>
+
+      <p>
+        When <ref column="target"/> specifies a connection method that
+        listens for inbound connections (e.g. <code>ptcp:</code> or
+        <code>punix:</code>), both <ref column="n_connections"/> and
+        <ref column="is_connected"/> may also be updated while the
+        remaining key-value pairs are omitted.
+      </p>
+
+      <p>
+        On the other hand, when <ref column="target"/> specifies an
+        outbound connection, all key-value pairs may be updated, except
+        the above-mentioned two key-value pairs associated with inbound
+        connection targets. They are omitted.
+      </p>
+
+    <column name="is_connected">
         <code>true</code> if currently connected to this manager,
         <code>false</code> otherwise.
       </column>
@@ -4264,18 +4285,11 @@
 
       <column name="status" key="n_connections"
               type='{"type": "integer", "minInteger": 2}'>
-        <p>
-          When <ref column="target"/> specifies a connection method that
-          listens for inbound connections (e.g. <code>ptcp:</code> or
-          <code>pssl:</code>) and more than one connection is actually active,
-          the value is the number of active connections.  Otherwise, this
-          key-value pair is omitted.
-        </p>
-        <p>
-          When multiple connections are active, status columns and key-value
-          pairs (other than this one) report the status of one arbitrarily
-          chosen connection.
-        </p>
+        When <ref column="target"/> specifies a connection method that
+        listens for inbound connections (e.g. <code>ptcp:</code> or
+        <code>pssl:</code>) and more than one connection is actually active,
+        the value is the number of active connections.  Otherwise, this
+        key-value pair is omitted.
       </column>
 
       <column name="status" key="bound_port" type='{"type": "integer"}'>
-- 
1.9.1




More information about the dev mailing list