From patchwork Sun Apr 30 23:22:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 756962 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wGP4M1BRWz9sCX for ; Mon, 1 May 2017 09:33:07 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A01F0BE4; Sun, 30 Apr 2017 23:23:39 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp2.linuxfoundation.org (smtp2.linux-foundation.org [172.17.192.36]) by mail.linuxfoundation.org (Postfix) with ESMTPS id E384EBDE for ; Sun, 30 Apr 2017 23:23:37 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by smtp2.linuxfoundation.org (Postfix) with ESMTPS id 1ED731DEE0 for ; Sun, 30 Apr 2017 23:23:37 +0000 (UTC) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by relay8-d.mail.gandi.net (Postfix) with ESMTPS id AB917405B6; Mon, 1 May 2017 01:23:35 +0200 (CEST) Received: from mfilter11-d.gandi.net (mfilter11-d.gandi.net [217.70.178.131]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 989BD41C089; Mon, 1 May 2017 01:23:35 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter11-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter11-d.gandi.net (mfilter11-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id d4IIfURqdPki; Mon, 1 May 2017 01:23:34 +0200 (CEST) X-Originating-IP: 173.228.112.23 Received: from sigabrt.gateway.sonic.net (173-228-112-23.dsl.dynamic.fusionbroadband.com [173.228.112.23]) (Authenticated sender: blp@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 4E61F41C07D; Mon, 1 May 2017 01:23:31 +0200 (CEST) From: Ben Pfaff To: dev@openvswitch.org Date: Sun, 30 Apr 2017 16:22:23 -0700 Message-Id: <20170430232231.15151-20-blp@ovn.org> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170430232231.15151-1-blp@ovn.org> References: <20170430232231.15151-1-blp@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp2.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH 19/27] ovn-sbctl: Get rid of redundant code by using function from db-ctl-base. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org This renames get_row() to ctl_get_row() and makes it public. It's unfortunate that it adds a cast, but getting rid of redundant code seems worth it to me. Signed-off-by: Ben Pfaff --- lib/db-ctl-base.c | 24 ++++++++++++------------ lib/db-ctl-base.h | 7 ++++++- ovn/utilities/ovn-sbctl.c | 31 +++---------------------------- 3 files changed, 21 insertions(+), 41 deletions(-) diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c index f844a38f65a0..3177d39472e9 100644 --- a/lib/db-ctl-base.c +++ b/lib/db-ctl-base.c @@ -351,10 +351,10 @@ get_row_by_id(struct ctl_context *ctx, return final; } -static const struct ovsdb_idl_row * -get_row(struct ctl_context *ctx, - const struct ovsdb_idl_table_class *table, const char *record_id, - bool must_exist) +const struct ovsdb_idl_row * +ctl_get_row(struct ctl_context *ctx, + const struct ovsdb_idl_table_class *table, const char *record_id, + bool must_exist) { const struct ovsdb_idl_row *row = NULL; struct uuid uuid; @@ -837,7 +837,7 @@ cmd_get(struct ctl_context *ctx) } table = get_table(table_name); - row = get_row(ctx, table, record_id, must_exist); + row = ctl_get_row(ctx, table, record_id, must_exist); if (!row) { return; } @@ -1065,7 +1065,7 @@ cmd_list(struct ctl_context *ctx) out = ctx->table = list_make_table(columns, n_columns); if (ctx->argc > 2) { for (i = 2; i < ctx->argc; i++) { - list_record(get_row(ctx, table, ctx->argv[i], must_exist), + list_record(ctl_get_row(ctx, table, ctx->argv[i], must_exist), columns, n_columns, out); } } else { @@ -1231,7 +1231,7 @@ cmd_set(struct ctl_context *ctx) int i; table = get_table(table_name); - row = get_row(ctx, table, record_id, must_exist); + row = ctl_get_row(ctx, table, record_id, must_exist); if (!row) { return; } @@ -1271,7 +1271,7 @@ cmd_add(struct ctl_context *ctx) table = get_table(table_name); die_if_error(get_column(table, column_name, &column)); - row = get_row(ctx, table, record_id, must_exist); + row = ctl_get_row(ctx, table, record_id, must_exist); if (!row) { return; } @@ -1332,7 +1332,7 @@ cmd_remove(struct ctl_context *ctx) table = get_table(table_name); die_if_error(get_column(table, column_name, &column)); - row = get_row(ctx, table, record_id, must_exist); + row = ctl_get_row(ctx, table, record_id, must_exist); if (!row) { return; } @@ -1403,7 +1403,7 @@ cmd_clear(struct ctl_context *ctx) int i; table = get_table(table_name); - row = get_row(ctx, table, record_id, must_exist); + row = ctl_get_row(ctx, table, record_id, must_exist); if (!row) { return; } @@ -1541,7 +1541,7 @@ cmd_destroy(struct ctl_context *ctx) for (i = 2; i < ctx->argc; i++) { const struct ovsdb_idl_row *row; - row = get_row(ctx, table, ctx->argv[i], must_exist); + row = ctl_get_row(ctx, table, ctx->argv[i], must_exist); if (row) { ovsdb_idl_txn_delete(row); } @@ -1575,7 +1575,7 @@ cmd_wait_until(struct ctl_context *ctx) table = get_table(table_name); - row = get_row(ctx, table, record_id, false); + row = ctl_get_row(ctx, table, record_id, false); if (!row) { ctx->try_again = true; return; diff --git a/lib/db-ctl-base.h b/lib/db-ctl-base.h index 29fea2bd94d9..2838921044bd 100644 --- a/lib/db-ctl-base.h +++ b/lib/db-ctl-base.h @@ -257,9 +257,14 @@ struct ctl_row_id { }; struct ctl_table_class { - struct ctl_row_id row_ids[2]; + struct ctl_row_id row_ids[3]; }; +const struct ovsdb_idl_row *ctl_get_row(struct ctl_context *, + const struct ovsdb_idl_table_class *, + const char *record_id, + bool must_exist); + void ctl_set_column(const char *table_name, const struct ovsdb_idl_row *, const char *arg, struct ovsdb_symbol_table *); diff --git a/ovn/utilities/ovn-sbctl.c b/ovn/utilities/ovn-sbctl.c index c77121e39273..69f461176572 100644 --- a/ovn/utilities/ovn-sbctl.c +++ b/ovn/utilities/ovn-sbctl.c @@ -736,39 +736,14 @@ is_partial_uuid_match(const struct uuid *uuid, const char *match) return !strncmp(s1, s2, strlen(s2)); } -static const struct sbrec_datapath_binding * -lookup_datapath(struct ovsdb_idl *idl, const char *s) -{ - struct uuid uuid; - if (uuid_from_string(&uuid, s)) { - const struct sbrec_datapath_binding *datapath; - datapath = sbrec_datapath_binding_get_for_uuid(idl, &uuid); - if (datapath) { - return datapath; - } - } - - const struct sbrec_datapath_binding *found = NULL; - const struct sbrec_datapath_binding *datapath; - SBREC_DATAPATH_BINDING_FOR_EACH (datapath, idl) { - const char *name = smap_get(&datapath->external_ids, "name"); - if (name && !strcmp(name, s)) { - if (!found) { - found = datapath; - } else { - ctl_fatal("%s: multiple datapaths with this name", s); - } - } - } - return found; -} - static void cmd_lflow_list(struct ctl_context *ctx) { const struct sbrec_datapath_binding *datapath = NULL; if (ctx->argc > 1) { - datapath = lookup_datapath(ctx->idl, ctx->argv[1]); + datapath = (const struct sbrec_datapath_binding *) + ctl_get_row(ctx, &sbrec_table_datapath_binding, + ctx->argv[1], false); if (datapath) { ctx->argc--; ctx->argv++;