X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Frconn.c;h=06f36264ed51a4954437c677d1c7cf6bce2f6a34;hb=3c8552c1db717d2018adbc5e17cbf2583f0a6639;hp=b833e651aa50cbfc95327930e61b4501fb3e8fdf;hpb=46816c3498e58a7a543001b4cc67aa6e31964831;p=openvswitch diff --git a/lib/rconn.c b/lib/rconn.c index b833e651..06f36264 100644 --- a/lib/rconn.c +++ b/lib/rconn.c @@ -30,10 +30,10 @@ #include "timeval.h" #include "util.h" #include "vconn.h" - -#define THIS_MODULE VLM_rconn #include "vlog.h" +VLOG_DEFINE_THIS_MODULE(rconn) + #define STATES \ STATE(VOID, 1 << 0) \ STATE(BACKOFF, 1 << 1) \ @@ -147,6 +147,7 @@ static void question_connectivity(struct rconn *); static void copy_to_monitor(struct rconn *, const struct ofpbuf *); static bool is_connected_state(enum state); static bool is_admitted_msg(const struct ofpbuf *); +static bool rconn_logging_connection_attempts__(const struct rconn *); /* Creates and returns a new rconn. * @@ -337,7 +338,9 @@ reconnect(struct rconn *rc) { int retval; - VLOG_INFO("%s: connecting...", rc->name); + if (rconn_logging_connection_attempts__(rc)) { + VLOG_INFO("%s: connecting...", rc->name); + } rc->n_attempted_connections++; retval = vconn_open(rc->target, OFP_VERSION, &rc->vconn); if (!retval) { @@ -383,10 +386,15 @@ run_CONNECTING(struct rconn *rc) state_transition(rc, S_ACTIVE); rc->last_connected = rc->state_entered; } else if (retval != EAGAIN) { - VLOG_INFO("%s: connection failed (%s)", rc->name, strerror(retval)); + if (rconn_logging_connection_attempts__(rc)) { + VLOG_INFO("%s: connection failed (%s)", + rc->name, strerror(retval)); + } disconnect(rc, retval); } else if (timed_out(rc)) { - VLOG_INFO("%s: connection timed out", rc->name); + if (rconn_logging_connection_attempts__(rc)) { + VLOG_INFO("%s: connection timed out", rc->name); + } rc->backoff_deadline = TIME_MAX; /* Prevent resetting backoff. */ disconnect(rc, ETIMEDOUT); } @@ -702,7 +710,7 @@ rconn_failure_duration(const struct rconn *rconn) /* Returns the IP address of the peer, or 0 if the peer's IP address is not * known. */ uint32_t -rconn_get_remote_ip(const struct rconn *rconn) +rconn_get_remote_ip(const struct rconn *rconn) { return rconn->remote_ip; } @@ -710,16 +718,16 @@ rconn_get_remote_ip(const struct rconn *rconn) /* Returns the transport port of the peer, or 0 if the peer's port is not * known. */ uint16_t -rconn_get_remote_port(const struct rconn *rconn) +rconn_get_remote_port(const struct rconn *rconn) { return rconn->remote_port; } /* Returns the IP address used to connect to the peer, or 0 if the - * connection is not an IP-based protocol or if its IP address is not + * connection is not an IP-based protocol or if its IP address is not * known. */ uint32_t -rconn_get_local_ip(const struct rconn *rconn) +rconn_get_local_ip(const struct rconn *rconn) { return rconn->local_ip; } @@ -727,7 +735,7 @@ rconn_get_local_ip(const struct rconn *rconn) /* Returns the transport port used to connect to the peer, or 0 if the * connection does not contain a port or if the port is not known. */ uint16_t -rconn_get_local_port(const struct rconn *rconn) +rconn_get_local_port(const struct rconn *rconn) { return rconn->vconn ? vconn_get_local_port(rconn->vconn) : 0; } @@ -969,10 +977,17 @@ disconnect(struct rconn *rc, int error) if (now >= rc->backoff_deadline) { rc->backoff = 1; - } else { - rc->backoff = MIN(rc->max_backoff, MAX(1, 2 * rc->backoff)); + } else if (rc->backoff < rc->max_backoff / 2) { + rc->backoff = MAX(1, 2 * rc->backoff); VLOG_INFO("%s: waiting %d seconds before reconnect", rc->name, rc->backoff); + } else { + if (rconn_logging_connection_attempts__(rc)) { + VLOG_INFO("%s: continuing to retry connections in the " + "background but suppressing further logging", + rc->name); + } + rc->backoff = rc->max_backoff; } rc->backoff_deadline = now + rc->backoff; state_transition(rc, S_BACKOFF); @@ -1044,7 +1059,7 @@ state_transition(struct rconn *rc, enum state state) } static void -question_connectivity(struct rconn *rc) +question_connectivity(struct rconn *rc) { time_t now = time_now(); if (now - rc->last_questioned > 60) { @@ -1082,7 +1097,7 @@ copy_to_monitor(struct rconn *rc, const struct ofpbuf *b) } static bool -is_connected_state(enum state state) +is_connected_state(enum state state) { return (state & (S_ACTIVE | S_IDLE)) != 0; } @@ -1104,3 +1119,12 @@ is_admitted_msg(const struct ofpbuf *b) (1u << OFPT_GET_CONFIG_REPLY) | (1u << OFPT_SET_CONFIG))); } + +/* Returns true if 'rc' is currently logging information about connection + * attempts, false if logging should be suppressed because 'rc' hasn't + * successuflly connected in too long. */ +static bool +rconn_logging_connection_attempts__(const struct rconn *rc) +{ + return rc->backoff < rc->max_backoff; +}