From patchwork Mon Aug 3 15:05:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1340341 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WzeRZM6I; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BL1RD5vLDz9sRN for ; Tue, 4 Aug 2020 01:05:43 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id F388F85D4C; Mon, 3 Aug 2020 15:05:41 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j5ndNdwcXwfw; Mon, 3 Aug 2020 15:05:41 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 2845385B04; Mon, 3 Aug 2020 15:05:41 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 17AA0C0050; Mon, 3 Aug 2020 15:05:41 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0AFFFC004C for ; Mon, 3 Aug 2020 15:05:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id E79F0867AC for ; Mon, 3 Aug 2020 15:05:39 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id beluwV6svLwC for ; Mon, 3 Aug 2020 15:05:39 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by whitealder.osuosl.org (Postfix) with ESMTPS id 03F0686416 for ; Mon, 3 Aug 2020 15:05:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596467137; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:content-type:content-type; bh=L3TYMqrL1pXA0/qO2uLl5z7Vdbn+EOPFzbZY5SB3sAo=; b=WzeRZM6IutbCb4f9gkvzowtA/+P3fjHSh2TFL3ISp8NZ4lqZjlsW78zcd/5onzz1i7Xq2c fyjGUQGWpJAkgPTFSjSAvLIBU1ynv51psEkyvGVyfR33OL54rB0kHh2hXKA4xnbsC0JZWG FQcRarLAH5CKWJhbKjLzEkcikdMGTr0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-456-F800lvaKOluncjhVxIB6Ew-1; Mon, 03 Aug 2020 11:05:35 -0400 X-MC-Unique: F800lvaKOluncjhVxIB6Ew-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1B89E101C8A9 for ; Mon, 3 Aug 2020 15:05:35 +0000 (UTC) Received: from dceara.remote.csb (ovpn-113-37.ams2.redhat.com [10.36.113.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9621B7176B for ; Mon, 3 Aug 2020 15:05:34 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Mon, 3 Aug 2020 17:05:28 +0200 Message-Id: <1596467128-13004-1-git-send-email-dceara@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH] ovsdb: Add unixctl command to show storage status. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" If a database enters an error state, e.g., in case of RAFT when reading the DB file contents if applying the RAFT records triggers constraint violations, there's no way to determine this unless a client generates a write transaction. Such write transactions would fail with "ovsdb-error: inconsistent data". This commit adds a new command to show the status of the storage that's backing a database. Example, on an inconsistent database: $ ovs-appctl -t /tmp/test.ctl ovsdb-server/get-db-storage-status DB status: ovsdb error: inconsistent data Example, on a consistent database: $ ovs-appctl -t /tmp/test.ctl ovsdb-server/get-db-storage-status DB status: ok Signed-off-by: Dumitru Ceara Acked-by: Han Zhou --- ovsdb/ovsdb-server.c | 39 +++++++++++++++++++++++++++++++++++++++ ovsdb/storage.c | 10 ++++++++++ ovsdb/storage.h | 1 + 3 files changed, 50 insertions(+) diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index ef4e996..52107f0 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -90,6 +90,7 @@ static unixctl_cb_func ovsdb_server_set_active_ovsdb_server_probe_interval; static unixctl_cb_func ovsdb_server_set_sync_exclude_tables; static unixctl_cb_func ovsdb_server_get_sync_exclude_tables; static unixctl_cb_func ovsdb_server_get_sync_status; +static unixctl_cb_func ovsdb_server_get_db_storage_status; struct server_config { struct sset *remotes; @@ -453,6 +454,9 @@ main(int argc, char *argv[]) unixctl_command_register("ovsdb-server/sync-status", "", 0, 0, ovsdb_server_get_sync_status, &server_config); + unixctl_command_register("ovsdb-server/get-db-storage-status", "DB", 1, 1, + ovsdb_server_get_db_storage_status, + &server_config); /* Simulate the behavior of OVS release prior to version 2.5 that * does not support the monitor_cond method. */ @@ -1697,6 +1701,41 @@ ovsdb_server_get_sync_status(struct unixctl_conn *conn, int argc OVS_UNUSED, } static void +ovsdb_server_get_db_storage_status(struct unixctl_conn *conn, + int argc OVS_UNUSED, + const char *argv[], + void *config_) +{ + struct server_config *config = config_; + struct shash_node *node; + + node = shash_find(config->all_dbs, argv[1]); + if (!node) { + unixctl_command_reply_error(conn, "Failed to find the database."); + return; + } + + struct db *db = node->data; + + if (!db->db) { + unixctl_command_reply_error(conn, "Failed to find the database."); + return; + } + + struct ds ds = DS_EMPTY_INITIALIZER; + char *error = ovsdb_storage_get_error(db->db->storage); + + if (!error) { + ds_put_cstr(&ds, "status: ok"); + } else { + ds_put_format(&ds, "status: %s", error); + free(error); + } + unixctl_command_reply(conn, ds_cstr(&ds)); + ds_destroy(&ds); +} + +static void parse_options(int argc, char *argv[], struct sset *db_filenames, struct sset *remotes, char **unixctl_pathp, char **run_command, diff --git a/ovsdb/storage.c b/ovsdb/storage.c index 7b4ad16..f662e90 100644 --- a/ovsdb/storage.c +++ b/ovsdb/storage.c @@ -198,6 +198,16 @@ ovsdb_storage_get_memory_usage(const struct ovsdb_storage *storage, } } +char * +ovsdb_storage_get_error(const struct ovsdb_storage *storage) +{ + if (storage->error) { + return ovsdb_error_to_string(storage->error); + } + + return NULL; +} + void ovsdb_storage_run(struct ovsdb_storage *storage) { diff --git a/ovsdb/storage.h b/ovsdb/storage.h index a223968..02b6e7e 100644 --- a/ovsdb/storage.h +++ b/ovsdb/storage.h @@ -42,6 +42,7 @@ const struct uuid *ovsdb_storage_get_sid(const struct ovsdb_storage *); uint64_t ovsdb_storage_get_applied_index(const struct ovsdb_storage *); void ovsdb_storage_get_memory_usage(const struct ovsdb_storage *, struct simap *usage); +char *ovsdb_storage_get_error(const struct ovsdb_storage *); void ovsdb_storage_run(struct ovsdb_storage *); void ovsdb_storage_wait(struct ovsdb_storage *);