[ovs-dev] [join ovsdb schema v2 4/8] ovsdb: add schemas into ovsdb run time data structure

Andy Zhou azhou at nicira.com
Thu Jun 25 21:53:36 UTC 2015


It turns out ovsdb in memory data structure needs to store both
joined schema and the original schemas, so that it can recreate
DB file laster.

This patch adds 'schemas' to 'struct ovsdb' and fixes corresponding
APIs for maintaining this information.

Signed-off-by: Andy Zhou <azhou at nicira.com>
---
 ovsdb/file.c       | 3 ++-
 ovsdb/ovsdb.c      | 6 +++++-
 ovsdb/ovsdb.h      | 9 +++++----
 tests/test-ovsdb.c | 6 +++---
 4 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/ovsdb/file.c b/ovsdb/file.c
index 8c3c31b..033d6f9 100644
--- a/ovsdb/file.c
+++ b/ovsdb/file.c
@@ -199,7 +199,8 @@ ovsdb_file_open__(const char *file_name,
         goto error;
     }
 
-    db = ovsdb_create(schema ? schema : ovsdb_schema_clone(alternate_schema));
+    db = ovsdb_create(schema ? schema : ovsdb_schema_clone(alternate_schema),
+                      NULL);
 
     n_transactions = 0;
     while ((error = ovsdb_log_read(log, &json)) == NULL && json) {
diff --git a/ovsdb/ovsdb.c b/ovsdb/ovsdb.c
index 39e6103..5929306 100644
--- a/ovsdb/ovsdb.c
+++ b/ovsdb/ovsdb.c
@@ -361,13 +361,14 @@ ovsdb_set_ref_table(const struct shash *tables,
 }
 
 struct ovsdb *
-ovsdb_create(struct ovsdb_schema *schema)
+ovsdb_create(struct ovsdb_schema *schema, struct shash *schemas)
 {
     struct shash_node *node;
     struct ovsdb *db;
 
     db = xmalloc(sizeof *db);
     db->schema = schema;
+    db->schemas = schemas;
     list_init(&db->replicas);
     list_init(&db->triggers);
     db->run_triggers = false;
@@ -421,6 +422,9 @@ ovsdb_destroy(struct ovsdb *db)
         shash_clear(&db->schema->tables);
 
         ovsdb_schema_destroy(db->schema);
+        if (db->schemas) {
+            ovsdb_schemas_destroy(db->schemas);
+        }
         free(db);
     }
 }
diff --git a/ovsdb/ovsdb.h b/ovsdb/ovsdb.h
index 771ff41..2e7f7e0 100644
--- a/ovsdb/ovsdb.h
+++ b/ovsdb/ovsdb.h
@@ -92,16 +92,17 @@ struct ovsdb_error *ovsdb_schemas_join(const struct shash *schemas,
 
 /* Database. */
 struct ovsdb {
-    struct ovsdb_schema *schema;
-    struct ovs_list replicas;   /* Contains "struct ovsdb_replica"s. */
-    struct shash tables;        /* Contains "struct ovsdb_table *"s. */
+    struct ovsdb_schema *schema; /* The joined schema for run time.  */
+    struct shash *schemas;       /* The schemas stored in the DB file. */
+    struct ovs_list replicas;    /* Contains "struct ovsdb_replica"s. */
+    struct shash tables;         /* Contains "struct ovsdb_table *"s. */
 
     /* Triggers. */
     struct ovs_list triggers;   /* Contains "struct ovsdb_trigger"s. */
     bool run_triggers;
 };
 
-struct ovsdb *ovsdb_create(struct ovsdb_schema *);
+struct ovsdb *ovsdb_create(struct ovsdb_schema *schema, struct shash *schemas);
 void ovsdb_destroy(struct ovsdb *);
 
 void ovsdb_get_memory_usage(const struct ovsdb *, struct simap *usage);
diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c
index 7913763..58a5fb7 100644
--- a/tests/test-ovsdb.c
+++ b/tests/test-ovsdb.c
@@ -1253,7 +1253,7 @@ do_execute(struct ovs_cmdl_context *ctx)
     json = parse_json(ctx->argv[1]);
     check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
     json_destroy(json);
-    db = ovsdb_create(schema);
+    db = ovsdb_create(schema, NULL);
 
     for (i = 2; i < ctx->argc; i++) {
         struct json *params, *result;
@@ -1307,7 +1307,7 @@ do_trigger(struct ovs_cmdl_context *ctx)
     json = parse_json(ctx->argv[1]);
     check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
     json_destroy(json);
-    db = ovsdb_create(schema);
+    db = ovsdb_create(schema, NULL);
 
     ovsdb_server_init(&server);
     ovsdb_server_add_db(&server, db);
@@ -1533,7 +1533,7 @@ do_transact(struct ovs_cmdl_context *ctx)
                       "       \"j\": {\"type\": \"integer\"}}}}}");
     check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
     json_destroy(json);
-    do_transact_db = ovsdb_create(schema);
+    do_transact_db = ovsdb_create(schema, NULL);
     do_transact_table = ovsdb_get_table(do_transact_db, "mytable");
     assert(do_transact_table != NULL);
 
-- 
1.9.1




More information about the dev mailing list