From cd5104fdd7d2422a9a574ebd8524821757357d09 Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Wed, 11 Apr 2012 20:18:34 -0700 Subject: stream: By default disable probing on unix sockets. 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 --- lib/jsonrpc.c | 4 ++++ 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 | 19 +++++++++++++++++++ lib/stream.h | 1 + ovsdb/jsonrpc-server.c | 6 ++++-- ovsdb/jsonrpc-server.h | 3 ++- ovsdb/ovsdb-server.c | 2 +- python/ovs/jsonrpc.py | 3 +++ python/ovs/stream.py | 13 +++++++++++++ 13 files changed, 65 insertions(+), 4 deletions(-) diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c index 4bcd4afe..291ce594 100644 --- a/lib/jsonrpc.c +++ b/lib/jsonrpc.c @@ -704,6 +704,10 @@ jsonrpc_session_open(const char *name) reconnect_set_passive(s->reconnect, true, time_msec()); } + if (!stream_or_pstream_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 7bf5ebd4..1832a4cc 100644 --- a/lib/stream-fd.c +++ b/lib/stream-fd.c @@ -156,6 +156,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 */ @@ -261,6 +262,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 03bf777b..120879d0 100644 --- a/lib/stream-provider.h +++ b/lib/stream-provider.h @@ -53,6 +53,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. @@ -145,6 +150,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 22d4c99a..57e0b6f9 100644 --- a/lib/stream-ssl.c +++ b/lib/stream-ssl.c @@ -754,6 +754,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 */ @@ -859,6 +860,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 9a7614db..56a1091a 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) const struct stream_class tcp_stream_class = { "tcp", /* name */ + true, /* needs_probes */ tcp_open, /* open */ NULL, /* close */ NULL, /* connect */ @@ -136,6 +137,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 d7dde8fc..de5adc62 100644 --- a/lib/stream-unix.c +++ b/lib/stream-unix.c @@ -65,6 +65,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 */ @@ -121,6 +122,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 4c3583c4..1ff860de 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -489,6 +489,25 @@ pstream_verify_name(const char *name) return pstream_lookup_class(name, &class); } +/* Returns 1 if the stream or pstream specified by 'name' needs periodic probes + * to verify connectivity. For [p]streams which need probes, it can take a + * long time to notice the connection has been dropped. Returns 0 if the + * stream or pstream does not need probes, and -1 if 'name' is not valid. */ +int +stream_or_pstream_needs_probes(const char *name) +{ + const struct pstream_class *pclass; + const struct stream_class *class; + + if (!stream_lookup_class(name, &class)) { + return class->needs_probes; + } else if (!pstream_lookup_class(name, &pclass)) { + return pclass->needs_probes; + } else { + return -1; + } +} + /* 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 5c111f99..73c3238e 100644 --- a/lib/stream.h +++ b/lib/stream.h @@ -80,6 +80,7 @@ bool stream_parse_target_with_default_ports(const char *target, uint16_t default_tcp_port, uint16_t default_ssl_port, struct sockaddr_in *sin); +int stream_or_pstream_needs_probes(const char *name); /* Error reporting. */ diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c index 147dadc7..08393c1e 100644 --- a/ovsdb/jsonrpc-server.c +++ b/ovsdb/jsonrpc-server.c @@ -125,11 +125,13 @@ 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; + options->probe_interval = (stream_or_pstream_needs_probes(target) + ? RECONNECT_DEFAULT_PROBE_INTERVAL + : 0); return options; } diff --git a/ovsdb/jsonrpc-server.h b/ovsdb/jsonrpc-server.h index 78ddb82d..08e37b90 100644 --- a/ovsdb/jsonrpc-server.h +++ b/ovsdb/jsonrpc-server.h @@ -29,7 +29,8 @@ struct ovsdb_jsonrpc_options { int max_backoff; /* Maximum reconnection backoff, in msec. */ int probe_interval; /* Max idle time before probing, in msec. */ }; -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 9e0636e9..9d69aa1f 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 5f90b396..b72af77c 100644 --- a/python/ovs/jsonrpc.py +++ b/python/ovs/jsonrpc.py @@ -372,6 +372,9 @@ class Session(object): if ovs.stream.PassiveStream.is_valid_name(name): reconnect.set_passive(True, ovs.timeval.msec()) + if ovs.stream.stream_or_pstream_needs_probes(name): + reconnect.set_probe_interval(0) + return Session(reconnect, None) @staticmethod diff --git a/python/ovs/stream.py b/python/ovs/stream.py index 7ea9e46e..4264b443 100644 --- a/python/ovs/stream.py +++ b/python/ovs/stream.py @@ -24,6 +24,19 @@ import ovs.vlog vlog = ovs.vlog.Vlog("stream") +def stream_or_pstream_needs_probes(name): + """ 1 if the stream or pstream specified by 'name' needs periodic probes to + verify connectivty. For [p]streams which need probes, it can take a long + time to notice the connection was dropped. Returns 0 if probes aren't + needed, and -1 if 'name' is invalid""" + + if PassiveStream.is_valid_name(name) or Stream.is_valid_name(name): + # Only unix and punix are supported currently. + return 0 + else: + return -1 + + class Stream(object): """Bidirectional byte stream. Currently only Unix domain sockets are implemented.""" -- cgit v1.2.3