Skip to content

Commit

Permalink
db-ctl-base: add uuid specified method for create cmd
Browse files Browse the repository at this point in the history
Commit a529e3c (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 <liuchang@cmss.chinamobile.com>
Co-authored-by: Rong Yin <rongyin@cmss.chinamobile.com>
Signed-off-by: Tao YunXiang <taoyunxiang@cmss.chinamobile.com>
Signed-off-by: Liu Chang <liuchang@cmss.chinamobile.com>
Signed-off-by: Rong Yin <rongyin@cmss.chinamobile.com>

CC: Han Zhou <hzhou@ovn.org>
Signed-off-by: 0-day Robot <robot@bytheb.org>
  • Loading branch information
Tao YunXiang authored and ovsrobot committed Feb 18, 2020
1 parent 486139d commit ca784f3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -48,6 +48,7 @@ v2.13.0 - 14 Feb 2020
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".
Expand Down
16 changes: 14 additions & 2 deletions lib/db-ctl-base.c
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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]...",
Expand Down
7 changes: 6 additions & 1 deletion lib/db-ctl-base.xml
Expand Up @@ -290,7 +290,7 @@
</p>
</dd>

<dt>[<code>--id=@</code><var>name</var>] <code>create</code> <var>table column</var>[<code>:</code><var>key</var>]<code>=</code><var>value</var>...</dt>
<dt>[<code>--id=@</code><var>name</var>] [<code>--row_uuid=</code><var>uuid</var>] <code>create</code> <var>table column</var>[<code>:</code><var>key</var>]<code>=</code><var>value</var>...</dt>
<dd>
<p>
Creates a new record in <var>table</var> and sets the initial values of
Expand All @@ -303,6 +303,11 @@
invocation in contexts where a UUID is expected. Such references may
precede or follow the <code>create</code> command.
</p>
<p>
If <code></code><var>uuid</var> is specified, then the UUID for the new row may be
specified as expected. Such references may precede or follow the <code>create</code>
command.
</p>
<dl>
<dt>Caution (ovs-vsctl as example)</dt>
<dd>
Expand Down
2 changes: 1 addition & 1 deletion lib/ovsdb-data.c
Expand Up @@ -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)
{
Expand Down
13 changes: 13 additions & 0 deletions lib/ovsdb-idl.c
Expand Up @@ -281,6 +281,7 @@ struct ovsdb_idl_txn {
char *error;
bool dry_run;
struct ds comment;
bool uuid_specified;

/* Increments. */
const char *inc_table;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/ovsdb-idl.h
Expand Up @@ -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 *,
Expand Down

0 comments on commit ca784f3

Please sign in to comment.