From patchwork Tue Feb 18 07:24:25 2020
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: taoyunxiang
X-Patchwork-Id: 1239790
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=none (p=none dis=none)
header.from=cmss.chinamobile.com
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 48MC7J2D1Gz9sRG
for ;
Tue, 18 Feb 2020 18:25:32 +1100 (AEDT)
Received: from localhost (localhost [127.0.0.1])
by fraxinus.osuosl.org (Postfix) with ESMTP id CD669857D5;
Tue, 18 Feb 2020 07:25:28 +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 Qav7YYzGCvpz; Tue, 18 Feb 2020 07:25:24 +0000 (UTC)
Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56])
by fraxinus.osuosl.org (Postfix) with ESMTP id 53CE9845D1;
Tue, 18 Feb 2020 07:25:24 +0000 (UTC)
Received: from lf-lists.osuosl.org (localhost [127.0.0.1])
by lists.linuxfoundation.org (Postfix) with ESMTP id 42921C089F;
Tue, 18 Feb 2020 07:25:24 +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 CB89BC013E
for ; Tue, 18 Feb 2020 07:25:22 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
by silver.osuosl.org (Postfix) with ESMTP id B3262203C8
for ; Tue, 18 Feb 2020 07:25:22 +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 BQnJ0iDh7wku for ;
Tue, 18 Feb 2020 07:25:19 +0000 (UTC)
X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6
Received: from cmccmta2.chinamobile.com (cmccmta2.chinamobile.com
[221.176.66.80])
by silver.osuosl.org (Postfix) with ESMTP id 3E3362041A
for ; Tue, 18 Feb 2020 07:25:17 +0000 (UTC)
Received: from spf.mail.chinamobile.com (unknown[172.16.121.17]) by
rmmx-syy-dmz-app06-12006 (RichMail) with SMTP id
2ee65e4b913c1fc-ab9ed; Tue, 18 Feb 2020 15:24:44 +0800 (CST)
X-RM-TRANSID: 2ee65e4b913c1fc-ab9ed
X-RM-TagInfo: emlType=0
X-RM-SPAM-FLAG: 00000000
Received: from yun.localdomain (unknown[112.25.154.146])
by rmsmtp-syy-appsvr09-12009 (RichMail) with SMTP id
2ee95e4b9139bf1-53cef; Tue, 18 Feb 2020 15:24:44 +0800 (CST)
X-RM-TRANSID: 2ee95e4b9139bf1-53cef
From: Tao YunXiang
To: ovs-dev@openvswitch.org
Date: Tue, 18 Feb 2020 15:24:25 +0800
Message-Id: <20200218072425.72210-1-taoyunxiang@cmss.chinamobile.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <3>
References: <3>
Cc: Liu Chang , Han Zhou ,
Rong Yin ,
Tao YunXiang
Subject: [ovs-dev] [PATCH v3] 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
---
NEWS | 1 +
lib/db-ctl-base.c | 16 ++++++++++++++--
lib/db-ctl-base.xml | 7 ++++++-
lib/ovsdb-data.c | 2 +-
lib/ovsdb-idl.c | 13 +++++++++++++
lib/ovsdb-idl.h | 1 +
6 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/NEWS b/NEWS
index 9bbe71d9e..19d509519 100644
--- a/NEWS
+++ b/NEWS
@@ -48,6 +48,7 @@ v2.13.0 - xx xxx xxxx
replication server. This value is configurable with the unixctl
command - ovsdb-server/set-active-ovsdb-server-probe-interval.
* ovsdb-server: New OVSDB extension to allow clients to specify row UUIDs.
+ * db-ctl-base: New row_uuid parameter specified for create cmd
- 'ovs-appctl dpctl/dump-flows' can now show offloaded=partial for
partially offloaded flows, dp:dpdk for fully offloaded by dpdk, and
type filter supports new filters: "dpdk" and "partially-offloaded".
diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c
index ab2af9eda..1f3502f3f 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,17 @@ 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)) {
+ ctl_error(ctx, "row_uuid '%s' is not a valid UUID", 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 +2477,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/db-ctl-base.xml b/lib/db-ctl-base.xml
index 10124c3ad..cc6414a8e 100644
--- a/lib/db-ctl-base.xml
+++ b/lib/db-ctl-base.xml
@@ -290,7 +290,7 @@
- [--id=@
name] create
table column[:
key]=
value...
+ [--id=@
name] [--row_uuid=
uuid] create
table column[:
key]=
value...
Creates a new record in table and sets the initial values of
@@ -303,6 +303,11 @@
invocation in contexts where a UUID is expected. Such references may
precede or follow the create
command.
+
+ If
uuid is specified, then the UUID for the new row may be
+ specified as expected. Such references may precede or follow the create
+ command.
+
- Caution (ovs-vsctl as example)
-
diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c
index 4828624f6..0ea8d4494 100644
--- a/lib/ovsdb-data.c
+++ b/lib/ovsdb-data.c
@@ -2223,7 +2223,7 @@ ovsdb_atom_range_check_size(int64_t range_start, int64_t range_end)
}
return NULL;
}
-
+
char *
ovsdb_data_row_name(const struct uuid *uuid)
{
diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
index 190143f36..c8f207e4e 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(
+ xasprintf(UUID_FMT, UUID_ARGS(&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 *,