[ovs-dev] [PATCH 2/2] stream: By default disable probing on unix sockets.

Ethan Jackson ethan at nicira.com
Thu Apr 12 05:02:10 UTC 2012


There isn't a lot of value in sending inactivity probes on unix
sockets.  This patch changes the default to disable them.

Signed-off-by: Ethan Jackson <ethan at nicira.com>
---
 lib/jsonrpc.c          |    7 +++++++
 lib/stream-fd.c        |    2 ++
 lib/stream-provider.h  |   10 ++++++++++
 lib/stream-ssl.c       |    2 ++
 lib/stream-tcp.c       |    2 ++
 lib/stream-unix.c      |    2 ++
 lib/stream.c           |   24 ++++++++++++++++++++++++
 lib/stream.h           |    2 ++
 ovsdb/jsonrpc-server.c |   13 ++++++++++++-
 ovsdb/jsonrpc-server.h |    3 ++-
 ovsdb/ovsdb-server.c   |    2 +-
 python/ovs/jsonrpc.py  |    5 +++++
 python/ovs/stream.py   |   18 ++++++++++++++++++
 13 files changed, 89 insertions(+), 3 deletions(-)

diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c
index fa3362d..0fc0995 100644
--- a/lib/jsonrpc.c
+++ b/lib/jsonrpc.c
@@ -762,6 +762,13 @@ jsonrpc_session_open(const char *name)
 
     if (!pstream_verify_name(name)) {
         reconnect_set_passive(s->reconnect, true, time_msec());
+        if (!pstream_needs_probes(name)) {
+            reconnect_set_probe_interval(s->reconnect, 0);
+        }
+    } else if (!stream_verify_name(name)) {
+        if (!stream_needs_probes(name)) {
+            reconnect_set_probe_interval(s->reconnect, 0);
+        }
     }
 
     return s;
diff --git a/lib/stream-fd.c b/lib/stream-fd.c
index 38dba7c..4113e3f 100644
--- a/lib/stream-fd.c
+++ b/lib/stream-fd.c
@@ -150,6 +150,7 @@ fd_wait(struct stream *stream, enum stream_wait_type wait)
 
 static const struct stream_class stream_fd_class = {
     "fd",                       /* name */
+    false,                      /* needs_probes */
     NULL,                       /* open */
     fd_close,                   /* close */
     fd_connect,                 /* connect */
@@ -255,6 +256,7 @@ pfd_wait(struct pstream *pstream)
 
 static struct pstream_class fd_pstream_class = {
     "pstream",
+    false,
     NULL,
     pfd_close,
     pfd_accept,
diff --git a/lib/stream-provider.h b/lib/stream-provider.h
index 77d0a10..3decb5a 100644
--- a/lib/stream-provider.h
+++ b/lib/stream-provider.h
@@ -54,6 +54,11 @@ struct stream_class {
     /* Prefix for connection names, e.g. "tcp", "ssl", "unix". */
     const char *name;
 
+    /* True if this stream needs periodic probes to verify connectivty.  For
+     * streams which need probes, it can take a long time to notice the
+     * connection was dropped. */
+    bool needs_probes;
+
     /* Attempts to connect to a peer.  'name' is the full connection name
      * provided by the user, e.g. "tcp:1.2.3.4".  This name is useful for error
      * messages but must not be modified.
@@ -151,6 +156,11 @@ struct pstream_class {
     /* Prefix for connection names, e.g. "ptcp", "pssl", "punix". */
     const char *name;
 
+    /* True if this pstream needs periodic probes to verify connectivty.  For
+     * pstreams which need probes, it can take a long time to notice the
+     * connection was dropped. */
+    bool needs_probes;
+
     /* Attempts to start listening for stream connections.  'name' is the full
      * connection name provided by the user, e.g. "ptcp:1234".  This name is
      * useful for error messages but must not be modified.
diff --git a/lib/stream-ssl.c b/lib/stream-ssl.c
index 5463388..ad572d3 100644
--- a/lib/stream-ssl.c
+++ b/lib/stream-ssl.c
@@ -755,6 +755,7 @@ ssl_wait(struct stream *stream, enum stream_wait_type wait)
 
 const struct stream_class ssl_stream_class = {
     "ssl",                      /* name */
+    true,                       /* needs_probes */
     ssl_open,                   /* open */
     ssl_close,                  /* close */
     ssl_connect,                /* connect */
@@ -861,6 +862,7 @@ pssl_wait(struct pstream *pstream)
 
 const struct pstream_class pssl_pstream_class = {
     "pssl",
+    true,
     pssl_open,
     pssl_close,
     pssl_accept,
diff --git a/lib/stream-tcp.c b/lib/stream-tcp.c
index c7a2ee2..9762f88 100644
--- a/lib/stream-tcp.c
+++ b/lib/stream-tcp.c
@@ -86,6 +86,7 @@ tcp_open(const char *name, char *suffix, struct stream **streamp, uint8_t dscp)
 
 const struct stream_class tcp_stream_class = {
     "tcp",                      /* name */
+    true,                       /* needs_probes */
     tcp_open,                   /* open */
     NULL,                       /* close */
     NULL,                       /* connect */
@@ -137,6 +138,7 @@ ptcp_accept(int fd, const struct sockaddr *sa, size_t sa_len,
 
 const struct pstream_class ptcp_pstream_class = {
     "ptcp",
+    true,
     ptcp_open,
     NULL,
     NULL,
diff --git a/lib/stream-unix.c b/lib/stream-unix.c
index a9d76f2..40ef012 100644
--- a/lib/stream-unix.c
+++ b/lib/stream-unix.c
@@ -57,6 +57,7 @@ unix_open(const char *name, char *suffix, struct stream **streamp,
 
 const struct stream_class unix_stream_class = {
     "unix",                     /* name */
+    false,                      /* needs_probes */
     unix_open,                  /* open */
     NULL,                       /* close */
     NULL,                       /* connect */
@@ -113,6 +114,7 @@ punix_accept(int fd, const struct sockaddr *sa, size_t sa_len,
 
 const struct pstream_class punix_pstream_class = {
     "punix",
+    false,
     punix_open,
     NULL,
     NULL,
diff --git a/lib/stream.c b/lib/stream.c
index 2f418c4..8a546b4 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -186,6 +186,18 @@ stream_verify_name(const char *name)
     return stream_lookup_class(name, &class);
 }
 
+/* True if the stream specified by 'name' needs periodic probes to verify
+ * connectivty.  For streams which need probes, it can take a long time to
+ * notice the connection was dropped. 'name' must be valid according to
+ * stream_verify_name(). */
+bool
+stream_needs_probes(const char *name)
+{
+    const struct stream_class *class;
+    stream_lookup_class(name, &class);
+    return class->needs_probes;
+}
+
 /* Attempts to connect a stream to a remote peer.  'name' is a connection name
  * in the form "TYPE:ARGS", where TYPE is an active stream class's name and
  * ARGS are stream class-specific.
@@ -489,6 +501,18 @@ pstream_verify_name(const char *name)
     return pstream_lookup_class(name, &class);
 }
 
+/* True if the pstream specified by 'name' needs periodic probes to verify
+ * connectivty.  For pstreams which need probes, it can take a long time to
+ * notice the connection was dropped. 'name' must be valid according to
+ * pstream_verify_name(). */
+bool
+pstream_needs_probes(const char *name)
+{
+    const struct pstream_class *class;
+    pstream_lookup_class(name, &class);
+    return class->needs_probes;
+}
+
 /* Attempts to start listening for remote stream connections.  'name' is a
  * connection name in the form "TYPE:ARGS", where TYPE is an passive stream
  * class's name and ARGS are stream class-specific.
diff --git a/lib/stream.h b/lib/stream.h
index c1f3adb..fb60b22 100644
--- a/lib/stream.h
+++ b/lib/stream.h
@@ -32,6 +32,7 @@ void stream_usage(const char *name, bool active, bool passive, bool bootstrap);
 
 /* Bidirectional byte streams. */
 int stream_verify_name(const char *name);
+bool stream_needs_probes(const char *name);
 int stream_open(const char *name, struct stream **, uint8_t dscp);
 int stream_open_block(int error, struct stream **);
 void stream_close(struct stream *);
@@ -59,6 +60,7 @@ void stream_send_wait(struct stream *);
 
 /* Passive streams: listeners for incoming stream connections. */
 int pstream_verify_name(const char *name);
+bool pstream_needs_probes(const char *name);
 int pstream_open(const char *name, struct pstream **, uint8_t dscp);
 const char *pstream_get_name(const struct pstream *);
 void pstream_close(struct pstream *);
diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c
index 1848bb9..636efb3 100644
--- a/ovsdb/jsonrpc-server.c
+++ b/ovsdb/jsonrpc-server.c
@@ -127,11 +127,22 @@ ovsdb_jsonrpc_server_destroy(struct ovsdb_jsonrpc_server *svr)
 }
 
 struct ovsdb_jsonrpc_options *
-ovsdb_jsonrpc_default_options(void)
+ovsdb_jsonrpc_default_options(const char *target)
 {
     struct ovsdb_jsonrpc_options *options = xzalloc(sizeof *options);
     options->probe_interval = RECONNECT_DEFAULT_PROBE_INTERVAL;
     options->max_backoff = RECONNECT_DEFAULT_MAX_BACKOFF;
+
+    if (!pstream_verify_name(target)) {
+        if (!pstream_needs_probes(target)) {
+            options->probe_interval = 0;
+        }
+    } else if (!stream_verify_name(target)) {
+        if (!stream_needs_probes(target)) {
+            options->probe_interval = 0;
+        }
+    }
+
     return options;
 }
 
diff --git a/ovsdb/jsonrpc-server.h b/ovsdb/jsonrpc-server.h
index c5ea6fa..344ed9d 100644
--- a/ovsdb/jsonrpc-server.h
+++ b/ovsdb/jsonrpc-server.h
@@ -30,7 +30,8 @@ struct ovsdb_jsonrpc_options {
     int probe_interval;         /* Max idle time before probing, in msec. */
     int dscp;                   /* Dscp value for manager connections */
 };
-struct ovsdb_jsonrpc_options *ovsdb_jsonrpc_default_options(void);
+struct ovsdb_jsonrpc_options *
+ovsdb_jsonrpc_default_options(const char *target);
 
 void ovsdb_jsonrpc_server_set_remotes(struct ovsdb_jsonrpc_server *,
                                       const struct shash *);
diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index 776bbb2..6994018 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -276,7 +276,7 @@ add_remote(struct shash *remotes, const char *target)
 
     options = shash_find_data(remotes, target);
     if (!options) {
-        options = ovsdb_jsonrpc_default_options();
+        options = ovsdb_jsonrpc_default_options(target);
         shash_add(remotes, target, options);
     }
 
diff --git a/python/ovs/jsonrpc.py b/python/ovs/jsonrpc.py
index 5f90b39..39ba628 100644
--- a/python/ovs/jsonrpc.py
+++ b/python/ovs/jsonrpc.py
@@ -371,6 +371,11 @@ class Session(object):
 
         if ovs.stream.PassiveStream.is_valid_name(name):
             reconnect.set_passive(True, ovs.timeval.msec())
+            if not ovs.stream.PassiveStream.needs_probes(name):
+                reconnect.set_probe_interval(0)
+        elif ovs.stream.Stream.is_valid_name(name):
+            if not ovs.stream.Stream.needs_probes(name):
+                reconnect.set_probe_interval(0)
 
         return Session(reconnect, None)
 
diff --git a/python/ovs/stream.py b/python/ovs/stream.py
index 08c6293..bc5c83e 100644
--- a/python/ovs/stream.py
+++ b/python/ovs/stream.py
@@ -45,6 +45,15 @@ class Stream(object):
         False."""
         return name.startswith("unix:")
 
+    @staticmethod
+    def needs_probes(name):
+        """ True if the stream specified by 'name' needs periodic probes to
+        verify connectivty.  For streams which need probes, it can take a long
+        time to notice the connection was dropped. 'name' must be valid
+        according to Stream.is_valid_name()."""
+        assert name.startswith("unix:")
+        return False
+
     def __init__(self, socket, name, status):
         self.socket = socket
         self.name = name
@@ -227,6 +236,15 @@ class PassiveStream(object):
         "punix:"), otherwise False."""
         return name.startswith("punix:")
 
+    @staticmethod
+    def needs_probes(name):
+        """True if the pstream specified by 'name' needs periodic probes to
+        verify connectivty.  For pstreams which need probes, it can take a long
+        time to notice the connection was dropped. 'name' must be valid
+        according to PassiveStream.pstream_is_valid_name()."""
+        assert name.statswith("punix:")
+        return False
+
     def __init__(self, sock, name, bind_path):
         self.name = name
         self.socket = sock
-- 
1.7.9.6




More information about the dev mailing list