+/* Forces all of the JSON-RPC sessions managed by 'remote' to disconnect and
+ * reconnect. */
+static void
+ovsdb_jsonrpc_session_reconnect_all(struct ovsdb_jsonrpc_remote *remote)
+{
+ struct ovsdb_jsonrpc_session *s, *next;
+
+ LIST_FOR_EACH_SAFE (s, next, node, &remote->sessions) {
+ jsonrpc_session_force_reconnect(s->js);
+ if (!jsonrpc_session_is_alive(s->js)) {
+ ovsdb_jsonrpc_session_close(s);
+ }
+ }
+}
+
+/* Sets the options for all of the JSON-RPC sessions managed by 'remote' to
+ * 'options'. */
+static void
+ovsdb_jsonrpc_session_set_all_options(
+ struct ovsdb_jsonrpc_remote *remote,
+ const struct ovsdb_jsonrpc_options *options)
+{
+ struct ovsdb_jsonrpc_session *s;
+
+ LIST_FOR_EACH (s, node, &remote->sessions) {
+ ovsdb_jsonrpc_session_set_options(s, 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->sec_since_connect = rstats.msec_since_connect == UINT_MAX
+ ? UINT_MAX : rstats.msec_since_connect / 1000;
+ status->sec_since_disconnect = rstats.msec_since_disconnect == UINT_MAX
+ ? UINT_MAX : rstats.msec_since_disconnect / 1000;
+
+ return;
+}
+
+static const char *
+get_db_name(const struct ovsdb_jsonrpc_session *s)
+{
+ return s->remote->server->db->schema->name;
+}
+
+static struct jsonrpc_msg *
+ovsdb_jsonrpc_check_db_name(const struct ovsdb_jsonrpc_session *s,
+ const struct jsonrpc_msg *request)
+{
+ struct json_array *params;
+ const char *want_db_name;
+ const char *have_db_name;
+ struct ovsdb_error *error;
+ struct jsonrpc_msg *reply;
+
+ params = json_array(request->params);
+ if (!params->n || params->elems[0]->type != JSON_STRING) {
+ error = ovsdb_syntax_error(
+ request->params, NULL,
+ "%s request params must begin with <db-name>", request->method);
+ goto error;
+ }
+
+ want_db_name = params->elems[0]->u.string;
+ have_db_name = get_db_name(s);
+ if (strcmp(want_db_name, have_db_name)) {
+ error = ovsdb_syntax_error(
+ request->params, "unknown database",
+ "%s request specifies unknown database %s",
+ request->method, want_db_name);
+ goto error;
+ }
+
+ return NULL;
+
+error:
+ reply = jsonrpc_create_reply(ovsdb_error_to_json(error), request->id);
+ ovsdb_error_destroy(error);
+ return reply;
+}
+