X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ovsdb%2Fovsdb.c;h=d4a27d40ea3491c87305aa4e1892f29527895951;hb=77fdfa9bf71aff101219b249955842f6dc59b5c9;hp=e76544e36253347da7a33e7dcf9c20207d7ab345;hpb=1883ed0f727bd10f0b8b6b80832029c349138595;p=openvswitch diff --git a/ovsdb/ovsdb.c b/ovsdb/ovsdb.c index e76544e3..d4a27d40 100644 --- a/ovsdb/ovsdb.c +++ b/ovsdb/ovsdb.c @@ -127,6 +127,21 @@ is_valid_version(const char *s) return n != -1 && s[n] == '\0'; } +/* Returns the number of tables in 'schema''s root set. */ +static size_t +root_set_size(const struct ovsdb_schema *schema) +{ + struct shash_node *node; + size_t n_root = 0; + + SHASH_FOR_EACH (node, &schema->tables) { + struct ovsdb_table_schema *table = node->data; + + n_root += table->is_root; + } + return n_root; +} + struct ovsdb_error * ovsdb_schema_from_json(struct json *json, struct ovsdb_schema **schemap) { @@ -205,6 +220,18 @@ ovsdb_schema_from_json(struct json *json, struct ovsdb_schema **schemap) } } + /* "isRoot" was not part of the original schema definition. Before it was + * added, there was no support for garbage collection. So, for backward + * compatibility, if the root set is empty then assume that every table is + * in the root set. */ + if (root_set_size(schema) == 0) { + SHASH_FOR_EACH (node, &schema->tables) { + struct ovsdb_table_schema *table = node->data; + + table->is_root = true; + } + } + *schemap = schema; return 0; } @@ -214,6 +241,7 @@ ovsdb_schema_to_json(const struct ovsdb_schema *schema) { struct json *json, *tables; struct shash_node *node; + bool default_is_root; json = json_object_create(); json_object_put_string(json, "name", schema->name); @@ -224,12 +252,18 @@ ovsdb_schema_to_json(const struct ovsdb_schema *schema) json_object_put_string(json, "cksum", schema->cksum); } + /* "isRoot" was not part of the original schema definition. Before it was + * added, there was no support for garbage collection. So, for backward + * compatibility, if every table is in the root set then do not output + * "isRoot" in table schemas. */ + default_is_root = root_set_size(schema) == shash_count(&schema->tables); + tables = json_object_create(); SHASH_FOR_EACH (node, &schema->tables) { struct ovsdb_table_schema *table = node->data; json_object_put(tables, table->name, - ovsdb_table_schema_to_json(table)); + ovsdb_table_schema_to_json(table, default_is_root)); } json_object_put(json, "tables", tables);