ovsdb: Move ovsdb_table_put_row() into test program.
authorBen Pfaff <blp@nicira.com>
Wed, 1 Jun 2011 23:17:00 +0000 (16:17 -0700)
committerBen Pfaff <blp@nicira.com>
Mon, 6 Jun 2011 15:58:02 +0000 (08:58 -0700)
This function is not useful inside ovsdb itself but only in the
"test-ovsdb" test program.  To avoid the temptation to use it incorrectly
inside ovsdb, this commit moves it into the test program.

ovsdb/table.c
ovsdb/table.h
tests/test-ovsdb.c

index 2ea73bf..44a205e 100644 (file)
@@ -251,17 +251,3 @@ ovsdb_table_get_row(const struct ovsdb_table *table, const struct uuid *uuid)
 
     return NULL;
 }
-
-/* 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);
-    if (!ovsdb_table_get_row(table, uuid)) {
-        hmap_insert(&table->rows, &row->hmap_node, uuid_hash(uuid));
-        return true;
-    } else {
-        return false;
-    }
-}
index 95da740..8e93343 100644 (file)
@@ -62,6 +62,5 @@ void ovsdb_table_destroy(struct ovsdb_table *);
 
 const struct ovsdb_row *ovsdb_table_get_row(const struct ovsdb_table *,
                                             const struct uuid *);
-bool ovsdb_table_put_row(struct ovsdb_table *, struct ovsdb_row *);
 
 #endif /* ovsdb/table.h */
index 5b8f451..5594b40 100644 (file)
@@ -975,6 +975,16 @@ do_execute_mutations(int argc OVS_UNUSED, char *argv[])
     ovsdb_table_destroy(table); /* Also destroys 'ts'. */
 }
 
+/* Inserts a row, without bothering to update metadata such as refcounts. */
+static void
+put_row(struct ovsdb_table *table, struct ovsdb_row *row)
+{
+    const struct uuid *uuid = ovsdb_row_get_uuid(row);
+    if (!ovsdb_table_get_row(table, uuid)) {
+        hmap_insert(&table->rows, &row->hmap_node, uuid_hash(uuid));
+    }
+}
+
 struct do_query_cbdata {
     struct uuid *row_uuids;
     int *counts;
@@ -1031,7 +1041,7 @@ do_query(int argc OVS_UNUSED, char *argv[])
                       UUID_ARGS(ovsdb_row_get_uuid(row)));
         }
         cbdata.row_uuids[i] = *ovsdb_row_get_uuid(row);
-        ovsdb_table_put_row(table, row);
+        put_row(table, row);
     }
     json_destroy(json);
 
@@ -1152,7 +1162,7 @@ do_query_distinct(int argc OVS_UNUSED, char *argv[])
             ovs_fatal(0, "duplicate UUID "UUID_FMT" in table",
                       UUID_ARGS(ovsdb_row_get_uuid(row)));
         }
-        ovsdb_table_put_row(table, row);
+        put_row(table, row);
 
     }
     json_destroy(json);