+}
+
+static bool
+ovsdb_jsonrpc_session_get_status(const struct ovsdb_jsonrpc_remote *remote,
+ struct ovsdb_jsonrpc_remote_status *status)
+{
+ const struct ovsdb_jsonrpc_session *s;
+ const struct jsonrpc_session *js;
+ struct ovsdb_lock_waiter *waiter;
+ struct reconnect_stats rstats;
+ struct ds locks_held, locks_waiting, locks_lost;
+
+ status->bound_port = (remote->listener
+ ? pstream_get_bound_port(remote->listener)
+ : htons(0));
+
+ if (list_is_empty(&remote->sessions)) {
+ return false;
+ }
+ s = CONTAINER_OF(remote->sessions.next, struct ovsdb_jsonrpc_session, node);
+ js = s->js;
+
+ 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;
+
+ ds_init(&locks_held);
+ ds_init(&locks_waiting);
+ ds_init(&locks_lost);
+ HMAP_FOR_EACH (waiter, session_node, &s->up.waiters) {
+ struct ds *string;
+
+ string = (ovsdb_lock_waiter_is_owner(waiter) ? &locks_held
+ : waiter->mode == OVSDB_LOCK_WAIT ? &locks_waiting
+ : &locks_lost);
+ if (string->length) {
+ ds_put_char(string, ' ');
+ }
+ ds_put_cstr(string, waiter->lock_name);
+ }
+ status->locks_held = ds_steal_cstr(&locks_held);
+ status->locks_waiting = ds_steal_cstr(&locks_waiting);
+ status->locks_lost = ds_steal_cstr(&locks_lost);
+
+ status->n_connections = list_size(&remote->sessions);
+
+ return true;
+}
+
+/* Examines 'request' to determine the database to which it relates, and then
+ * searches 's' to find that database:
+ *
+ * - If successful, returns the database and sets '*replyp' to NULL.
+ *
+ * - If no such database exists, returns NULL and sets '*replyp' to an
+ * appropriate JSON-RPC error reply, owned by the caller. */
+static struct ovsdb *
+ovsdb_jsonrpc_lookup_db(const struct ovsdb_jsonrpc_session *s,
+ const struct jsonrpc_msg *request,
+ struct jsonrpc_msg **replyp)
+{
+ struct json_array *params;
+ struct ovsdb_error *error;
+ const char *db_name;
+ struct ovsdb *db;
+
+ 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;
+ }
+
+ db_name = params->elems[0]->u.string;
+ db = shash_find_data(&s->up.server->dbs, db_name);
+ if (!db) {
+ error = ovsdb_syntax_error(
+ request->params, "unknown database",
+ "%s request specifies unknown database %s",
+ request->method, db_name);
+ goto error;
+ }
+
+ *replyp = NULL;
+ return db;
+
+error:
+ *replyp = jsonrpc_create_reply(ovsdb_error_to_json(error), request->id);
+ ovsdb_error_destroy(error);
+ return NULL;
+}
+
+static struct ovsdb_error *
+ovsdb_jsonrpc_session_parse_lock_name(const struct jsonrpc_msg *request,
+ const char **lock_namep)
+{
+ const struct json_array *params;
+
+ params = json_array(request->params);
+ if (params->n != 1 || params->elems[0]->type != JSON_STRING ||
+ !ovsdb_parser_is_id(json_string(params->elems[0]))) {
+ *lock_namep = NULL;
+ return ovsdb_syntax_error(request->params, NULL,
+ "%s request params must be <id>",
+ request->method);
+ }
+
+ *lock_namep = json_string(params->elems[0]);
+ return NULL;