2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-22 09:58:01 +00:00

ovsdb: Add functions to clone schemas.

These will be used by an upcoming commit.
This commit is contained in:
Ben Pfaff 2010-02-10 15:37:52 -08:00
parent e5125481cf
commit 58985e09ea
6 changed files with 52 additions and 2 deletions

View File

@ -31,6 +31,7 @@ ovsdb_column_create(const char *name, const char *comment,
bool mutable, bool persistent, bool mutable, bool persistent,
const struct ovsdb_type *type) const struct ovsdb_type *type)
{ {
/* Doesn't set the new column's 'index': the caller must do that. */
struct ovsdb_column *column; struct ovsdb_column *column;
column = xzalloc(sizeof *column); column = xzalloc(sizeof *column);
@ -43,6 +44,15 @@ ovsdb_column_create(const char *name, const char *comment,
return column; 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 void
ovsdb_column_destroy(struct ovsdb_column *column) ovsdb_column_destroy(struct ovsdb_column *column)
{ {

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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( struct ovsdb_column *ovsdb_column_create(
const char *name, const char *comment, bool mutable, bool persistent, const char *name, const char *comment, bool mutable, bool persistent,
const struct ovsdb_type *); const struct ovsdb_type *);
struct ovsdb_column *ovsdb_column_clone(const struct ovsdb_column *);
void ovsdb_column_destroy(struct ovsdb_column *); void ovsdb_column_destroy(struct ovsdb_column *);
struct ovsdb_error *ovsdb_column_from_json(const struct json *, struct ovsdb_error *ovsdb_column_from_json(const struct json *,

View File

@ -38,6 +38,22 @@ ovsdb_schema_create(const char *name, const char *comment)
return schema; 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 void
ovsdb_schema_destroy(struct ovsdb_schema *schema) ovsdb_schema_destroy(struct ovsdb_schema *schema)
{ {

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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, struct ovsdb_schema *ovsdb_schema_create(const char *name,
const char *comment); const char *comment);
struct ovsdb_schema *ovsdb_schema_clone(const struct ovsdb_schema *);
void ovsdb_schema_destroy(struct ovsdb_schema *); void ovsdb_schema_destroy(struct ovsdb_schema *);
struct ovsdb_error *ovsdb_schema_from_file(const char *file_name, struct ovsdb_error *ovsdb_schema_from_file(const char *file_name,

View File

@ -61,6 +61,26 @@ ovsdb_table_schema_create(const char *name, const char *comment, bool mutable)
return ts; 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 void
ovsdb_table_schema_destroy(struct ovsdb_table_schema *ts) ovsdb_table_schema_destroy(struct ovsdb_table_schema *ts)
{ {

View File

@ -35,6 +35,8 @@ struct ovsdb_table_schema {
struct ovsdb_table_schema *ovsdb_table_schema_create(const char *name, struct ovsdb_table_schema *ovsdb_table_schema_create(const char *name,
const char *comment, const char *comment,
bool mutable); bool mutable);
struct ovsdb_table_schema *ovsdb_table_schema_clone(
const struct ovsdb_table_schema *);
void ovsdb_table_schema_destroy(struct ovsdb_table_schema *); void ovsdb_table_schema_destroy(struct ovsdb_table_schema *);
struct ovsdb_error *ovsdb_table_schema_from_json(const struct json *, struct ovsdb_error *ovsdb_table_schema_from_json(const struct json *,