ovs-brcompatd: Fix dangling reference in del_port().
[openvswitch] / ovsdb / table.c
index b520580c09439b68dd8f80bbf5617da576423442..7ba47eb012a4c8a194b29fb5c89d7c389780fdf0 100644 (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");
  * you may not use this file except in compliance with the License.
@@ -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)
 {
@@ -144,7 +164,7 @@ ovsdb_table_schema_to_json(const struct ovsdb_table_schema *ts)
     columns = json_object_create();
 
     SHASH_FOR_EACH (node, &ts->columns) {
-        struct ovsdb_column *column = node->data;
+        const struct ovsdb_column *column = node->data;
         if (node->name[0] != '_') {
             json_object_put(columns, column->name,
                             ovsdb_column_to_json(column));
@@ -169,6 +189,7 @@ ovsdb_table_create(struct ovsdb_table_schema *ts)
 
     table = xmalloc(sizeof *table);
     table->schema = ts;
+    table->txn_table = NULL;
     hmap_init(&table->rows);
 
     return table;
@@ -191,13 +212,12 @@ ovsdb_table_destroy(struct ovsdb_table *table)
     }
 }
 
-static const struct ovsdb_row *
-ovsdb_table_get_row__(const struct ovsdb_table *table, const struct uuid *uuid,
-                      size_t hash)
+const struct ovsdb_row *
+ovsdb_table_get_row(const struct ovsdb_table *table, const struct uuid *uuid)
 {
     struct ovsdb_row *row;
 
-    HMAP_FOR_EACH_WITH_HASH (row, struct ovsdb_row, hmap_node, hash,
+    HMAP_FOR_EACH_WITH_HASH (row, struct ovsdb_row, hmap_node, uuid_hash(uuid),
                              &table->rows) {
         if (uuid_equals(ovsdb_row_get_uuid(row), uuid)) {
             return row;
@@ -207,22 +227,14 @@ ovsdb_table_get_row__(const struct ovsdb_table *table, const struct uuid *uuid,
     return NULL;
 }
 
-const struct ovsdb_row *
-ovsdb_table_get_row(const struct ovsdb_table *table, const struct uuid *uuid)
-{
-    return ovsdb_table_get_row__(table, uuid, uuid_hash(uuid));
-}
-
 /* This is probably not the function you want.  Use ovsdb_txn_row_modify()
  * instead. */
 bool
 ovsdb_table_put_row(struct ovsdb_table *table, struct ovsdb_row *row)
 {
     const struct uuid *uuid = ovsdb_row_get_uuid(row);
-    size_t hash = uuid_hash(uuid);
-
-    if (!ovsdb_table_get_row__(table, uuid, hash)) {
-        hmap_insert(&table->rows, &row->hmap_node, hash);
+    if (!ovsdb_table_get_row(table, uuid)) {
+        hmap_insert(&table->rows, &row->hmap_node, uuid_hash(uuid));
         return true;
     } else {
         return false;