2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 14:25:26 +00:00

db-ctl-base: Partially revert b8bf410a5.

The commit b8bf410a5 [0] broke the `ovs-vsctl add` command
which now overwrites the value if it existed already.

This patch reverts the code around the `cmd_add` function
to restore the previous behavior. It also adds testing coverage
for this functionality.

[0] b8bf410a5c

Fixes: b8bf410a5c ("db-ctl-base: Use partial map/set updates for last add/set commands.")
Reported-at: https://bugzilla.redhat.com/show_bug.cgi?id=2182767
Acked-by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Daniel Alvarez Sanchez <dalvarez@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
Daniel Alvarez Sanchez
2023-03-29 16:26:38 -04:00
committed by Ilya Maximets
parent 0f34ecbd5a
commit daeab9548a
2 changed files with 12 additions and 38 deletions

View File

@@ -1492,7 +1492,7 @@ cmd_add(struct ctl_context *ctx)
const struct ovsdb_idl_column *column;
const struct ovsdb_idl_row *row;
const struct ovsdb_type *type;
struct ovsdb_datum new;
struct ovsdb_datum old;
int i;
ctx->error = get_table(table_name, &table);
@@ -1516,13 +1516,7 @@ cmd_add(struct ctl_context *ctx)
}
type = &column->type;
if (ctx->last_command) {
ovsdb_datum_init_empty(&new);
} else {
ovsdb_datum_clone(&new, ovsdb_idl_read(row, column));
}
ovsdb_datum_clone(&old, ovsdb_idl_read(row, column));
for (i = 4; i < ctx->argc; i++) {
struct ovsdb_type add_type;
struct ovsdb_datum add;
@@ -1533,41 +1527,23 @@ cmd_add(struct ctl_context *ctx)
ctx->error = ovsdb_datum_from_string(&add, &add_type, ctx->argv[i],
ctx->symtab);
if (ctx->error) {
ovsdb_datum_destroy(&new, &column->type);
ovsdb_datum_destroy(&old, &column->type);
return;
}
ovsdb_datum_union(&new, &add, type);
ovsdb_datum_union(&old, &add, type);
ovsdb_datum_destroy(&add, type);
}
if (!ctx->last_command && new.n > type->n_max) {
if (old.n > type->n_max) {
ctl_error(ctx, "\"add\" operation would put %u %s in column %s of "
"table %s but the maximum number is %u",
new.n,
old.n,
type->value.type == OVSDB_TYPE_VOID ? "values" : "pairs",
column->name, table->name, type->n_max);
ovsdb_datum_destroy(&new, &column->type);
ovsdb_datum_destroy(&old, &column->type);
return;
}
if (ctx->last_command) {
/* Partial updates can only be made one by one. */
for (i = 0; i < new.n; i++) {
struct ovsdb_datum *datum = xmalloc(sizeof *datum);
ovsdb_datum_init_empty(datum);
ovsdb_datum_add_from_index_unsafe(datum, &new, i, type);
if (ovsdb_type_is_map(type)) {
ovsdb_idl_txn_write_partial_map(row, column, datum);
} else {
ovsdb_idl_txn_write_partial_set(row, column, datum);
}
}
ovsdb_datum_destroy(&new, &column->type);
} else {
ovsdb_idl_txn_verify(row, column);
ovsdb_idl_txn_write(row, column, &new);
}
ovsdb_idl_txn_verify(row, column);
ovsdb_idl_txn_write(row, column, &old);
invalidate_cache(ctx);
}