X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ovsdb%2Fovsdb.c;h=d4a27d40ea3491c87305aa4e1892f29527895951;hb=356180a825c94314f3d1667003e64526d1b69da5;hp=2a54a7b908b8283fe96d3b323cdaf7b80b8b90b5;hpb=403e3a25f89ba9f2efb9a8c43e4e585f4af2ac67;p=openvswitch diff --git a/ovsdb/ovsdb.c b/ovsdb/ovsdb.c index 2a54a7b9..d4a27d40 100644 --- a/ovsdb/ovsdb.c +++ b/ovsdb/ovsdb.c @@ -123,10 +123,25 @@ static bool is_valid_version(const char *s) { int n = -1; - sscanf(s, "%*[0-9].%*[0-9].%*[0-9]%n", &n); + ignore(sscanf(s, "%*[0-9].%*[0-9].%*[0-9]%n", &n)); 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);