diff options
author | Ilya Maximets <i.maximets@ovn.org> | 2021-11-22 01:09:32 +0100 |
---|---|---|
committer | Ilya Maximets <i.maximets@ovn.org> | 2021-11-30 13:34:03 +0100 |
commit | dec429168461052b62f205d211cb630c201bc28a (patch) | |
tree | f18cc07b5c8546d6ba082d95e67a9b25c3537405 /ovsdb | |
parent | 9d29990c21578a9a28b56b2ecdf8c18a1cb16b00 (diff) | |
download | openvswitch-dec429168461052b62f205d211cb630c201bc28a.tar.gz |
ovsdb-data: Consolidate ovsdb atom and json strings.
ovsdb_atom_string and json_string are basically the same data structure
and ovsdb-server frequently needs to convert one to another. We can
avoid that by using json_string from the beginning for all ovsdb
strings. So, the conversion turns into simple json_clone(), i.e.
increment of a reference counter. This change gives a moderate
performance boost in some scenarios, improves the code clarity and
may be useful for future development.
Acked-by: Mike Pattrick <mkp@redhat.com>
Acked-by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Diffstat (limited to 'ovsdb')
-rwxr-xr-x | ovsdb/ovsdb-idlc.in | 5 | ||||
-rw-r--r-- | ovsdb/ovsdb-server.c | 7 | ||||
-rw-r--r-- | ovsdb/rbac.c | 8 |
3 files changed, 11 insertions, 9 deletions
diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in index e589c1bdf..5a02c8f93 100755 --- a/ovsdb/ovsdb-idlc.in +++ b/ovsdb/ovsdb-idlc.in @@ -192,6 +192,7 @@ def printCIDLHeader(schemaFile): #include <stdbool.h> #include <stddef.h> #include <stdint.h> +#include "openvswitch/json.h" #include "ovsdb-data.h" #include "ovsdb-idl-provider.h" #include "smap.h" @@ -577,8 +578,8 @@ static void print(" smap_init(&row->%s);" % columnName) print(" for (size_t i = 0; i < datum->n; i++) {") print(" smap_add(&row->%s," % columnName) - print(" datum->keys[i].s->string,") - print(" datum->values[i].s->string);") + print(" json_string(datum->keys[i].s),") + print(" json_string(datum->values[i].s));") print(" }") elif (type.n_min == 1 and type.n_max == 1) or type.is_optional_pointer(): print("") diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index b34d97e29..9fe90592e 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -904,8 +904,9 @@ query_db_string(const struct shash *all_dbs, const char *name, datum = &row->fields[column->index]; for (i = 0; i < datum->n; i++) { - if (datum->keys[i].s->string[0]) { - return datum->keys[i].s->string; + const char *key = json_string(datum->keys[i].s); + if (key[0]) { + return key; } } } @@ -1018,7 +1019,7 @@ query_db_remotes(const char *name, const struct shash *all_dbs, datum = &row->fields[column->index]; for (i = 0; i < datum->n; i++) { - add_remote(remotes, datum->keys[i].s->string); + add_remote(remotes, json_string(datum->keys[i].s)); } } } else if (column->type.key.type == OVSDB_TYPE_UUID diff --git a/ovsdb/rbac.c b/ovsdb/rbac.c index ff411675f..a3fe97120 100644 --- a/ovsdb/rbac.c +++ b/ovsdb/rbac.c @@ -53,8 +53,8 @@ ovsdb_find_row_by_string_key(const struct ovsdb_table *table, HMAP_FOR_EACH (row, hmap_node, &table->rows) { const struct ovsdb_datum *datum = &row->fields[column->index]; for (size_t i = 0; i < datum->n; i++) { - if (datum->keys[i].s->string[0] && - !strcmp(key, datum->keys[i].s->string)) { + const char *row_key = json_string(datum->keys[i].s); + if (row_key[0] && !strcmp(key, row_key)) { return row; } } @@ -113,7 +113,7 @@ ovsdb_rbac_authorized(const struct ovsdb_row *perms, } for (i = 0; i < datum->n; i++) { - const char *name = datum->keys[i].s->string; + const char *name = json_string(datum->keys[i].s); const char *value = NULL; bool is_map; @@ -271,7 +271,7 @@ rbac_column_modification_permitted(const struct ovsdb_column *column, size_t i; for (i = 0; i < modifiable->n; i++) { - char *name = modifiable->keys[i].s->string; + const char *name = json_string(modifiable->keys[i].s); if (!strcmp(name, column->name)) { return true; |