X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ovsdb%2Fjsonrpc-server.c;h=92228be856fb438ac7fb61203a74305ecbe60223;hb=92dbd5c9e3134eabc6e57b397dd18493bc96c9b8;hp=3edcfffbdaa2ecdc5f3d2c5e22c7fc913bfa3170;hpb=cbb7baddb826a7e0fda8d6cd352101276cd7c774;p=openvswitch diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c index 3edcfffb..92228be8 100644 --- a/ovsdb/jsonrpc-server.c +++ b/ovsdb/jsonrpc-server.c @@ -53,6 +53,9 @@ 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 void ovsdb_jsonrpc_session_get_status( + const struct ovsdb_jsonrpc_remote *, + struct shash *); /* Triggers. */ static void ovsdb_jsonrpc_trigger_create(struct ovsdb_jsonrpc_session *, @@ -194,6 +197,21 @@ ovsdb_jsonrpc_server_del_remote(struct shash_node *node) free(remote); } +void +ovsdb_jsonrpc_server_get_remote_status(const struct ovsdb_jsonrpc_server *svr, + struct shash *statuses) +{ + struct shash_node *node; + + shash_init(statuses); + + SHASH_FOR_EACH (node, &svr->remotes) { + const struct ovsdb_jsonrpc_remote *remote = node->data; + + ovsdb_jsonrpc_session_get_status(remote, statuses); + } +} + /* Forces all of the JSON-RPC sessions managed by 'svr' to disconnect and * reconnect. */ void @@ -420,6 +438,43 @@ ovsdb_jsonrpc_session_set_all_options( } } +static void +ovsdb_jsonrpc_session_get_status(const struct ovsdb_jsonrpc_remote *remote, + struct shash *shash) +{ + const struct ovsdb_jsonrpc_session *s; + const struct jsonrpc_session *js; + const char *name; + struct ovsdb_jsonrpc_remote_status *status; + struct reconnect_stats rstats; + + /* We only look at the first session in the list. There should be only one + * node in the list for outbound connections. We don't track status for + * each individual inbound connection if someone configures the DB that + * way. Since outbound connections are the norm, this is fine. */ + if (list_is_empty(&remote->sessions)) { + return; + } + s = CONTAINER_OF(remote->sessions.next, struct ovsdb_jsonrpc_session, node); + js = s->js; + if (!js) { + return; + } + name = jsonrpc_session_get_name(js); + + status = xzalloc(sizeof *status); + shash_add(shash, name, status); + + status->is_connected = jsonrpc_session_is_connected(js); + status->last_error = jsonrpc_session_get_status(js); + + jsonrpc_session_get_reconnect_stats(js, &rstats); + status->state = rstats.state; + status->state_elapsed = rstats.state_elapsed; + + return; +} + static const char * get_db_name(const struct ovsdb_jsonrpc_session *s) {