mirror of
https://github.com/openvswitch/ovs
synced 2025-08-22 18:07:40 +00:00
ovsdb: row: Add support for xor-based row updates.
This will be used to apply update3 type updates to ovsdb tables while processing updates for future ovsdb 'relay' service model. 'ovsdb_datum_apply_diff' is allowed to fail, so adding support to return this error. Acked-by: Mark D. Gray <mark.d.gray@redhat.com> Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
parent
85dbbe275b
commit
b4cef64c83
@ -483,8 +483,9 @@ update_row_cb(const struct ovsdb_row *row, void *ur_)
|
|||||||
|
|
||||||
ur->n_matches++;
|
ur->n_matches++;
|
||||||
if (!ovsdb_row_equal_columns(row, ur->row, ur->columns)) {
|
if (!ovsdb_row_equal_columns(row, ur->row, ur->columns)) {
|
||||||
ovsdb_row_update_columns(ovsdb_txn_row_modify(ur->txn, row),
|
ovsdb_error_assert(ovsdb_row_update_columns(
|
||||||
ur->row, ur->columns);
|
ovsdb_txn_row_modify(ur->txn, row),
|
||||||
|
ur->row, ur->columns, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -677,7 +677,7 @@ process_table_update(struct json *table_update, const char *table_name,
|
|||||||
struct ovsdb_error *error;
|
struct ovsdb_error *error;
|
||||||
error = (!new ? ovsdb_table_execute_delete(txn, &uuid, table)
|
error = (!new ? ovsdb_table_execute_delete(txn, &uuid, table)
|
||||||
: !old ? ovsdb_table_execute_insert(txn, &uuid, table, new)
|
: !old ? ovsdb_table_execute_insert(txn, &uuid, table, new)
|
||||||
: ovsdb_table_execute_update(txn, &uuid, table, new));
|
: ovsdb_table_execute_update(txn, &uuid, table, new, false));
|
||||||
if (error) {
|
if (error) {
|
||||||
if (!strcmp(ovsdb_error_get_tag(error), "consistency violation")) {
|
if (!strcmp(ovsdb_error_get_tag(error), "consistency violation")) {
|
||||||
ovsdb_error_assert(error);
|
ovsdb_error_assert(error);
|
||||||
|
30
ovsdb/row.c
30
ovsdb/row.c
@ -163,20 +163,40 @@ ovsdb_row_equal_columns(const struct ovsdb_row *a,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
struct ovsdb_error *
|
||||||
ovsdb_row_update_columns(struct ovsdb_row *dst,
|
ovsdb_row_update_columns(struct ovsdb_row *dst,
|
||||||
const struct ovsdb_row *src,
|
const struct ovsdb_row *src,
|
||||||
const struct ovsdb_column_set *columns)
|
const struct ovsdb_column_set *columns,
|
||||||
|
bool xor)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < columns->n_columns; i++) {
|
for (i = 0; i < columns->n_columns; i++) {
|
||||||
const struct ovsdb_column *column = columns->columns[i];
|
const struct ovsdb_column *column = columns->columns[i];
|
||||||
|
struct ovsdb_datum xor_datum;
|
||||||
|
struct ovsdb_error *error;
|
||||||
|
|
||||||
|
if (xor) {
|
||||||
|
error = ovsdb_datum_apply_diff(&xor_datum,
|
||||||
|
&dst->fields[column->index],
|
||||||
|
&src->fields[column->index],
|
||||||
|
&column->type);
|
||||||
|
if (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ovsdb_datum_destroy(&dst->fields[column->index], &column->type);
|
ovsdb_datum_destroy(&dst->fields[column->index], &column->type);
|
||||||
ovsdb_datum_clone(&dst->fields[column->index],
|
|
||||||
&src->fields[column->index],
|
if (xor) {
|
||||||
&column->type);
|
ovsdb_datum_swap(&dst->fields[column->index], &xor_datum);
|
||||||
|
} else {
|
||||||
|
ovsdb_datum_clone(&dst->fields[column->index],
|
||||||
|
&src->fields[column->index],
|
||||||
|
&column->type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Appends the string form of the value in 'row' of each of the columns in
|
/* Appends the string form of the value in 'row' of each of the columns in
|
||||||
|
@ -82,8 +82,10 @@ bool ovsdb_row_equal_columns(const struct ovsdb_row *,
|
|||||||
int ovsdb_row_compare_columns_3way(const struct ovsdb_row *,
|
int ovsdb_row_compare_columns_3way(const struct ovsdb_row *,
|
||||||
const struct ovsdb_row *,
|
const struct ovsdb_row *,
|
||||||
const struct ovsdb_column_set *);
|
const struct ovsdb_column_set *);
|
||||||
void ovsdb_row_update_columns(struct ovsdb_row *, const struct ovsdb_row *,
|
struct ovsdb_error *ovsdb_row_update_columns(struct ovsdb_row *,
|
||||||
const struct ovsdb_column_set *);
|
const struct ovsdb_row *,
|
||||||
|
const struct ovsdb_column_set *,
|
||||||
|
bool xor);
|
||||||
void ovsdb_row_columns_to_string(const struct ovsdb_row *,
|
void ovsdb_row_columns_to_string(const struct ovsdb_row *,
|
||||||
const struct ovsdb_column_set *, struct ds *);
|
const struct ovsdb_column_set *, struct ds *);
|
||||||
struct ovsdb_error *ovsdb_row_from_json(struct ovsdb_row *,
|
struct ovsdb_error *ovsdb_row_from_json(struct ovsdb_row *,
|
||||||
|
@ -384,7 +384,8 @@ ovsdb_table_execute_delete(struct ovsdb_txn *txn, const struct uuid *row_uuid,
|
|||||||
|
|
||||||
struct ovsdb_error *
|
struct ovsdb_error *
|
||||||
ovsdb_table_execute_update(struct ovsdb_txn *txn, const struct uuid *row_uuid,
|
ovsdb_table_execute_update(struct ovsdb_txn *txn, const struct uuid *row_uuid,
|
||||||
struct ovsdb_table *table, struct json *json_row)
|
struct ovsdb_table *table, struct json *json_row,
|
||||||
|
bool xor)
|
||||||
{
|
{
|
||||||
const struct ovsdb_row *row = ovsdb_table_get_row(table, row_uuid);
|
const struct ovsdb_row *row = ovsdb_table_get_row(table, row_uuid);
|
||||||
if (!row) {
|
if (!row) {
|
||||||
@ -399,9 +400,9 @@ ovsdb_table_execute_update(struct ovsdb_txn *txn, const struct uuid *row_uuid,
|
|||||||
struct ovsdb_error *error = ovsdb_row_from_json(update, json_row,
|
struct ovsdb_error *error = ovsdb_row_from_json(update, json_row,
|
||||||
NULL, &columns);
|
NULL, &columns);
|
||||||
|
|
||||||
if (!error && !ovsdb_row_equal_columns(row, update, &columns)) {
|
if (!error && (xor || !ovsdb_row_equal_columns(row, update, &columns))) {
|
||||||
ovsdb_row_update_columns(ovsdb_txn_row_modify(txn, row),
|
error = ovsdb_row_update_columns(ovsdb_txn_row_modify(txn, row),
|
||||||
update, &columns);
|
update, &columns, xor);
|
||||||
}
|
}
|
||||||
|
|
||||||
ovsdb_column_set_destroy(&columns);
|
ovsdb_column_set_destroy(&columns);
|
||||||
|
@ -82,6 +82,6 @@ struct ovsdb_error *ovsdb_table_execute_delete(struct ovsdb_txn *txn,
|
|||||||
struct ovsdb_error *ovsdb_table_execute_update(struct ovsdb_txn *txn,
|
struct ovsdb_error *ovsdb_table_execute_update(struct ovsdb_txn *txn,
|
||||||
const struct uuid *row_uuid,
|
const struct uuid *row_uuid,
|
||||||
struct ovsdb_table *table,
|
struct ovsdb_table *table,
|
||||||
struct json *new);
|
struct json *new, bool xor);
|
||||||
|
|
||||||
#endif /* ovsdb/table.h */
|
#endif /* ovsdb/table.h */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user