summaryrefslogtreecommitdiff
path: root/ovsdb
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2010-02-10 15:37:52 -0800
committerBen Pfaff <blp@nicira.com>2010-02-15 11:31:05 -0800
commit58985e09eafe83a7fbe9c85626e44abe9d9eca8c (patch)
treee6a8b8157ebf489a8f7d97af5bcdb2910949fabe /ovsdb
parente5125481cf98eebb4ff49c7881410493629c9ec0 (diff)
downloadopenvswitch-58985e09eafe83a7fbe9c85626e44abe9d9eca8c.tar.gz
ovsdb: Add functions to clone schemas.
These will be used by an upcoming commit.
Diffstat (limited to 'ovsdb')
-rw-r--r--ovsdb/column.c10
-rw-r--r--ovsdb/column.h3
-rw-r--r--ovsdb/ovsdb.c16
-rw-r--r--ovsdb/ovsdb.h3
-rw-r--r--ovsdb/table.c20
-rw-r--r--ovsdb/table.h2
6 files changed, 52 insertions, 2 deletions
diff --git a/ovsdb/column.c b/ovsdb/column.c
index 0a1f6e4d9..58fff1084 100644
--- a/ovsdb/column.c
+++ b/ovsdb/column.c
@@ -31,6 +31,7 @@ ovsdb_column_create(const char *name, const char *comment,
bool mutable, bool persistent,
const struct ovsdb_type *type)
{
+ /* Doesn't set the new column's 'index': the caller must do that. */
struct ovsdb_column *column;
column = xzalloc(sizeof *column);
@@ -43,6 +44,15 @@ ovsdb_column_create(const char *name, const char *comment,
return column;
}
+struct ovsdb_column *
+ovsdb_column_clone(const struct ovsdb_column *old)
+{
+ /* Doesn't copy the column's 'index': the caller must do that. */
+ return ovsdb_column_create(old->name, old->comment,
+ old->mutable, old->persistent,
+ &old->type);
+}
+
void
ovsdb_column_destroy(struct ovsdb_column *column)
{
diff --git a/ovsdb/column.h b/ovsdb/column.h
index 5fd39ae10..eb1a3834a 100644
--- a/ovsdb/column.h
+++ b/ovsdb/column.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2010 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,6 +47,7 @@ enum {
struct ovsdb_column *ovsdb_column_create(
const char *name, const char *comment, bool mutable, bool persistent,
const struct ovsdb_type *);
+struct ovsdb_column *ovsdb_column_clone(const struct ovsdb_column *);
void ovsdb_column_destroy(struct ovsdb_column *);
struct ovsdb_error *ovsdb_column_from_json(const struct json *,
diff --git a/ovsdb/ovsdb.c b/ovsdb/ovsdb.c
index 2b5bdc32e..b5f6edb12 100644
--- a/ovsdb/ovsdb.c
+++ b/ovsdb/ovsdb.c
@@ -38,6 +38,22 @@ ovsdb_schema_create(const char *name, const char *comment)
return schema;
}
+struct ovsdb_schema *
+ovsdb_schema_clone(const struct ovsdb_schema *old)
+{
+ struct ovsdb_schema *new;
+ struct shash_node *node;
+
+ new = ovsdb_schema_create(old->name, old->comment);
+ SHASH_FOR_EACH (node, &old->tables) {
+ const struct ovsdb_table_schema *ts = node->data;
+
+ shash_add(&new->tables, node->name, ovsdb_table_schema_clone(ts));
+ }
+ return new;
+}
+
+
void
ovsdb_schema_destroy(struct ovsdb_schema *schema)
{
diff --git a/ovsdb/ovsdb.h b/ovsdb/ovsdb.h
index 24ebd9c67..9961620ac 100644
--- a/ovsdb/ovsdb.h
+++ b/ovsdb/ovsdb.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2010 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@ struct ovsdb_schema {
struct ovsdb_schema *ovsdb_schema_create(const char *name,
const char *comment);
+struct ovsdb_schema *ovsdb_schema_clone(const struct ovsdb_schema *);
void ovsdb_schema_destroy(struct ovsdb_schema *);
struct ovsdb_error *ovsdb_schema_from_file(const char *file_name,
diff --git a/ovsdb/table.c b/ovsdb/table.c
index 190185245..7ba47eb01 100644
--- a/ovsdb/table.c
+++ b/ovsdb/table.c
@@ -61,6 +61,26 @@ ovsdb_table_schema_create(const char *name, const char *comment, bool mutable)
return ts;
}
+struct ovsdb_table_schema *
+ovsdb_table_schema_clone(const struct ovsdb_table_schema *old)
+{
+ struct ovsdb_table_schema *new;
+ struct shash_node *node;
+
+ new = ovsdb_table_schema_create(old->name, old->comment, old->mutable);
+ SHASH_FOR_EACH (node, &old->columns) {
+ const struct ovsdb_column *column = node->data;
+
+ if (column->name[0] == '_') {
+ /* Added automatically by ovsdb_table_schema_create(). */
+ continue;
+ }
+
+ add_column(new, ovsdb_column_clone(column));
+ }
+ return new;
+}
+
void
ovsdb_table_schema_destroy(struct ovsdb_table_schema *ts)
{
diff --git a/ovsdb/table.h b/ovsdb/table.h
index 6e8a78596..67784e93c 100644
--- a/ovsdb/table.h
+++ b/ovsdb/table.h
@@ -35,6 +35,8 @@ struct ovsdb_table_schema {
struct ovsdb_table_schema *ovsdb_table_schema_create(const char *name,
const char *comment,
bool mutable);
+struct ovsdb_table_schema *ovsdb_table_schema_clone(
+ const struct ovsdb_table_schema *);
void ovsdb_table_schema_destroy(struct ovsdb_table_schema *);
struct ovsdb_error *ovsdb_table_schema_from_json(const struct json *,