ovsdb-data: Expose guts of ovsdb_symbol_table() to clients.
authorBen Pfaff <blp@nicira.com>
Tue, 1 Mar 2011 21:11:56 +0000 (13:11 -0800)
committerBen Pfaff <blp@nicira.com>
Thu, 10 Mar 2011 19:24:00 +0000 (11:24 -0800)
ovs-vsctl will, in upcoming commits, want to more closely examine its
ovsdb_symbol_table structures.  This could be done by providing a more
complete API, but it doesn't seem worth it to me.  This commit instead goes
the other way, exposing the internals to clients.  This commit also
eliminates the ovsdb_symbol_table_find_uncreated() function, which
ovs-vsctl can now implement itself.

lib/ovsdb-data.c
lib/ovsdb-data.h
utilities/ovs-vsctl.c

index c141e86..ac94864 100644 (file)
@@ -1795,10 +1795,6 @@ ovsdb_datum_subtract(struct ovsdb_datum *a, const struct ovsdb_type *a_type,
     }
 }
 \f
-struct ovsdb_symbol_table {
-    struct shash sh;
-};
-
 struct ovsdb_symbol_table *
 ovsdb_symbol_table_create(void)
 {
@@ -1852,21 +1848,6 @@ ovsdb_symbol_table_insert(struct ovsdb_symbol_table *symtab,
     }
     return symbol;
 }
-
-const char *
-ovsdb_symbol_table_find_uncreated(const struct ovsdb_symbol_table *symtab)
-{
-    struct shash_node *node;
-
-    SHASH_FOR_EACH (node, &symtab->sh) {
-        struct ovsdb_symbol *symbol = node->data;
-        if (!symbol->created) {
-            return node->name;
-        }
-    }
-
-    return NULL;
-}
 \f
 /* Extracts a token from the beginning of 's' and returns a pointer just after
  * the token.  Stores the token itself into '*outp', which the caller is
index fe279bc..fe71f90 100644 (file)
 #include <stdlib.h>
 #include "compiler.h"
 #include "ovsdb-types.h"
+#include "shash.h"
 
 struct ds;
 struct ovsdb_symbol_table;
-struct shash;
 
 /* One value of an atomic type (given by enum ovs_atomic_type). */
 union ovsdb_atom {
@@ -229,6 +229,10 @@ ovsdb_datum_conforms_to_type(const struct ovsdb_datum *datum,
 /* A table mapping from names to data items.  Currently the data items are
  * always UUIDs; perhaps this will be expanded in the future. */
 
+struct ovsdb_symbol_table {
+    struct shash sh;            /* Maps from name to struct ovsdb_symbol *. */
+};
+
 struct ovsdb_symbol {
     struct uuid uuid;           /* The UUID that the symbol represents. */
     bool created;               /* Already used to create row? */
@@ -243,8 +247,6 @@ struct ovsdb_symbol *ovsdb_symbol_table_put(struct ovsdb_symbol_table *,
                                             const struct uuid *, bool used);
 struct ovsdb_symbol *ovsdb_symbol_table_insert(struct ovsdb_symbol_table *,
                                                const char *name);
-const char *ovsdb_symbol_table_find_uncreated(
-    const struct ovsdb_symbol_table *);
 \f
 /* Tokenization
  *
index 2818a38..e5e03f7 100644 (file)
@@ -3354,8 +3354,8 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands,
     const struct ovsrec_open_vswitch *ovs;
     enum ovsdb_idl_txn_status status;
     struct ovsdb_symbol_table *symtab;
-    const char *uncreated;
     struct vsctl_command *c;
+    struct shash_node *node;
     int64_t next_cfg = 0;
     char *error = NULL;
 
@@ -3395,10 +3395,13 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands,
         }
     }
 
-    uncreated = ovsdb_symbol_table_find_uncreated(symtab);
-    if (uncreated) {
-        vsctl_fatal("row id \"%s\" is referenced but never created (e.g. "
-                    "with \"-- --id=%s create ...\")", uncreated, uncreated);
+    SHASH_FOR_EACH (node, &symtab->sh) {
+        struct ovsdb_symbol *symbol = node->data;
+        if (!symbol->created) {
+            vsctl_fatal("row id \"%s\" is referenced but never created (e.g. "
+                        "with \"-- --id=%s create ...\")",
+                        node->name, node->name);
+        }
     }
 
     status = ovsdb_idl_txn_commit_block(txn);