From patchwork Thu Feb 6 09:17:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: taoyunxiang X-Patchwork-Id: 1234175 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.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cmss.chinamobile.com Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48CtCc1Krpz9sRm for ; Thu, 6 Feb 2020 20:18:52 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 96F04204E9; Thu, 6 Feb 2020 09:18:49 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OzMfWEpk5OhN; Thu, 6 Feb 2020 09:18:47 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 510FF2045A; Thu, 6 Feb 2020 09:18:47 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 32048C1D81; Thu, 6 Feb 2020 09:18:47 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8F202C013E for ; Thu, 6 Feb 2020 09:18:46 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 86B4A204E9 for ; Thu, 6 Feb 2020 09:18:46 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PitbtRRNB4vH for ; Thu, 6 Feb 2020 09:18:42 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from cmccmta1.chinamobile.com (cmccmta1.chinamobile.com [221.176.66.79]) by silver.osuosl.org (Postfix) with ESMTP id 1D5DB2045A for ; Thu, 6 Feb 2020 09:18:36 +0000 (UTC) Received: from spf.mail.chinamobile.com (unknown[172.16.121.15]) by rmmx-syy-dmz-app04-12004 (RichMail) with SMTP id 2ee45e3bd9becfe-db3e9; Thu, 06 Feb 2020 17:17:51 +0800 (CST) X-RM-TRANSID: 2ee45e3bd9becfe-db3e9 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from yun.localdomain (unknown[112.25.154.146]) by rmsmtp-syy-appsvr08-12008 (RichMail) with SMTP id 2ee85e3bd9bdc94-f959d; Thu, 06 Feb 2020 17:17:50 +0800 (CST) X-RM-TRANSID: 2ee85e3bd9bdc94-f959d From: Tao YunXiang To: ovs-dev@openvswitch.org Date: Thu, 6 Feb 2020 17:17:33 +0800 Message-Id: <20200206091733.27899-1-taoyunxiang@cmss.chinamobile.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <8> References: <8> Cc: Liu Chang , Han Zhou , Rong Yin , Tao YunXiang Subject: [ovs-dev] [PATCH v2] db-ctl-base: add uuid specified method for create cmd 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" Commit a529e3cd1f (ovsdb-server: Allow OVSDB clients to specify the UUID for inserted rows) solves ovsdb-client specifing the UUID for insert operation. OVSDB now can support directly using uuid to identify a row. But for xxxctl tool,specifying uuid when creating a row is not yet supported . This patch tried to specify uuid when creating a row by the ctl tools. A new parameter --row_uuid is added to setup row's UUID. e.g. ovn-nbctl --row_uuid=3da0398b-a5a8-4bc9-808d-fa662865138f create logical_switch name='abc' Co-authored-by: Liu Chang Co-authored-by: Rong Yin Signed-off-by: Tao YunXiang Signed-off-by: Liu Chang Signed-off-by: Rong Yin CC: Han Zhou --- lib/db-ctl-base.c | 15 +++++++++++++-- lib/ovsdb-data.c | 9 +++++++++ lib/ovsdb-data.h | 1 + lib/ovsdb-idl.c | 13 +++++++++++++ lib/ovsdb-idl.h | 1 + 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c index ab2af9eda..522273210 100644 --- a/lib/db-ctl-base.c +++ b/lib/db-ctl-base.c @@ -1718,10 +1718,12 @@ static void cmd_create(struct ctl_context *ctx) { const char *id = shash_find_data(&ctx->options, "--id"); + const char *row_uuid = shash_find_data(&ctx->options, "--row_uuid"); const char *table_name = ctx->argv[1]; const struct ovsdb_idl_table_class *table; const struct ovsdb_idl_row *row; const struct uuid *uuid = NULL; + struct uuid uuid_from_cmd; int i; ctx->error = get_table(table_name, &table); @@ -1741,7 +1743,16 @@ cmd_create(struct ctl_context *ctx) * warnings about that by pretending that there is a reference. */ symbol->strong_ref = true; } - uuid = &symbol->uuid; + if (!row_uuid) { + uuid = &symbol->uuid; + } + } + if (row_uuid) { + if (!uuid_from_string(&uuid_from_cmd, row_uuid)) { + return ; + } + uuid = &uuid_from_cmd; + ovsdb_idl_txn_set_uuid_specified(ctx->txn); } row = ovsdb_idl_txn_insert(ctx->txn, table, uuid); @@ -2465,7 +2476,7 @@ static const struct ctl_command_syntax db_ctl_commands[] = { {"clear", 3, INT_MAX, "TABLE RECORD COLUMN...", pre_cmd_clear, cmd_clear, NULL, "--if-exists", RW}, {"create", 2, INT_MAX, "TABLE COLUMN[:KEY]=VALUE...", pre_create, - cmd_create, post_create, "--id=", RW}, + cmd_create, post_create, "--id=,--row_uuid=", RW}, {"destroy", 1, INT_MAX, "TABLE [RECORD]...", pre_cmd_destroy, cmd_destroy, NULL, "--if-exists,--all", RW}, {"wait-until", 2, INT_MAX, "TABLE RECORD [COLUMN[:KEY]=VALUE]...", diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c index 4828624f6..ea87206a7 100644 --- a/lib/ovsdb-data.c +++ b/lib/ovsdb-data.c @@ -2239,3 +2239,12 @@ ovsdb_data_row_name(const struct uuid *uuid) return name; } + +char * +ovsdb_data_row_uuid(const struct uuid *uuid) +{ + char *row_uuid; + + row_uuid = xasprintf(UUID_FMT, UUID_ARGS(uuid)); + return row_uuid; +} diff --git a/lib/ovsdb-data.h b/lib/ovsdb-data.h index c5a80ee39..3b0439b3e 100644 --- a/lib/ovsdb-data.h +++ b/lib/ovsdb-data.h @@ -259,6 +259,7 @@ void ovsdb_datum_add_unsafe(struct ovsdb_datum *, struct json *ovsdb_datum_to_json_with_row_names(const struct ovsdb_datum *, const struct ovsdb_type *); char *ovsdb_data_row_name(const struct uuid *); +char *ovsdb_data_row_uuid(const struct uuid *); /* Type checking. */ static inline bool diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 190143f36..d801c22a0 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -281,6 +281,7 @@ struct ovsdb_idl_txn { char *error; bool dry_run; struct ds comment; + bool uuid_specified; /* Increments. */ const char *inc_table; @@ -3550,6 +3551,7 @@ ovsdb_idl_txn_create(struct ovsdb_idl *idl) txn->status = TXN_UNCOMMITTED; txn->error = NULL; txn->dry_run = false; + txn->uuid_specified = false; ds_init(&txn->comment); txn->inc_table = NULL; @@ -3591,6 +3593,11 @@ ovsdb_idl_txn_set_dry_run(struct ovsdb_idl_txn *txn) txn->dry_run = true; } +void +ovsdb_idl_txn_set_uuid_specified(struct ovsdb_idl_txn *txn) +{ + txn->uuid_specified = true; +} /* Causes 'txn', when committed, to increment the value of 'column' within * 'row' by 1. 'column' must have an integer type. After 'txn' commits * successfully, the client may retrieve the final (incremented) value of @@ -4157,6 +4164,12 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) json_string_create_nocopy( ovsdb_data_row_name(&row->uuid))); + if (txn->uuid_specified) { + json_object_put(op, "uuid", + json_string_create_nocopy( + ovsdb_data_row_uuid(&row->uuid))); + } + insert = xmalloc(sizeof *insert); insert->dummy = row->uuid; insert->op_index = operations->array.n - 1; diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h index 9f12ce320..ae9dc10e4 100644 --- a/lib/ovsdb-idl.h +++ b/lib/ovsdb-idl.h @@ -316,6 +316,7 @@ struct ovsdb_idl_txn *ovsdb_idl_txn_create(struct ovsdb_idl *); void ovsdb_idl_txn_add_comment(struct ovsdb_idl_txn *, const char *, ...) OVS_PRINTF_FORMAT (2, 3); void ovsdb_idl_txn_set_dry_run(struct ovsdb_idl_txn *); +void ovsdb_idl_txn_set_uuid_specified(struct ovsdb_idl_txn *); void ovsdb_idl_txn_increment(struct ovsdb_idl_txn *, const struct ovsdb_idl_row *, const struct ovsdb_idl_column *,