From patchwork Thu Aug 19 00:42:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Numan Siddique X-Patchwork-Id: 1518276 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=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GqmG20H3cz9sxS for ; Thu, 19 Aug 2021 10:43:05 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id A024960723; Thu, 19 Aug 2021 00:43:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WCjVcvGH-uxw; Thu, 19 Aug 2021 00:42:59 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id DDC5A605A1; Thu, 19 Aug 2021 00:42:58 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id BC181C0010; Thu, 19 Aug 2021 00:42:58 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id D6131C000E for ; Thu, 19 Aug 2021 00:42:57 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id BDF2440217 for ; Thu, 19 Aug 2021 00:42:57 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uzG4KQQVUtIy for ; Thu, 19 Aug 2021 00:42:56 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by smtp2.osuosl.org (Postfix) with ESMTPS id 6511540162 for ; Thu, 19 Aug 2021 00:42:56 +0000 (UTC) Received: (Authenticated sender: numans@ovn.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 81A6F40005; Thu, 19 Aug 2021 00:42:52 +0000 (UTC) From: numans@ovn.org To: dev@openvswitch.org Date: Wed, 18 Aug 2021 20:42:47 -0400 Message-Id: <20210819004247.3369975-1-numans@ovn.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [ovs-dev] [PATCH] ovsdb-idl : Add APIs to query if a table and a column is present or not. 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: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Numan Siddique This patch adds 2 new APIs in the ovsdb-idl client library - ovsdb_idl_has_table() and ovsdb_idl_has_column_in_table() to query if a table and a column is present in the IDL or not. This is required for scenarios where the server schema is old and missing a table or column and the client (built with a new schema version) does a transaction with the missing table or column. This results in a continuous loop of transaction failures. OVN would require the API - ovsdb_idl_has_table() to address this issue when an old ovsdb-server is used (OVS 2.11) which has the 'datapath' table missing. A recent commit in OVN creates a 'datapath' row in the local ovsdb-server. ovsdb_idl_has_column_in_table() would be useful to have. Related issue: https://bugzilla.redhat.com/show_bug.cgi?id=1992705 Signed-off-by: Numan Siddique --- lib/ovsdb-idl.c | 25 +++++++++++++++++++++++++ lib/ovsdb-idl.h | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 2198c69c6..c5795fb7f 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -4256,3 +4256,28 @@ ovsdb_idl_loop_commit_and_wait(struct ovsdb_idl_loop *loop) return retval; } + +bool +ovsdb_idl_has_table(struct ovsdb_idl *idl, const char *table_name) +{ + struct ovsdb_idl_table *table = shash_find_data(&idl->table_by_name, + table_name); + return table ? true: false; +} + +bool +ovsdb_idl_has_column_in_table(struct ovsdb_idl *idl, const char *table_name, + const char *column_name) +{ + struct ovsdb_idl_table *table = shash_find_data(&idl->table_by_name, + table_name); + if (!table) { + return false; + } + + if (shash_find_data(&table->columns, column_name)) { + return true; + } + + return false; +} diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h index d93483245..216db4c6d 100644 --- a/lib/ovsdb-idl.h +++ b/lib/ovsdb-idl.h @@ -474,6 +474,10 @@ void ovsdb_idl_cursor_next_eq(struct ovsdb_idl_cursor *); struct ovsdb_idl_row *ovsdb_idl_cursor_data(struct ovsdb_idl_cursor *); +bool ovsdb_idl_has_table(struct ovsdb_idl *idl, const char *table_name); +bool ovsdb_idl_has_column_in_table(struct ovsdb_idl *idl, + const char *table_name, + const char *column_name); #ifdef __cplusplus } #endif