[ovs-dev] [PATCH] ovsdb-server: Drop unnecessary find_db() function.

Ben Pfaff blp at ovn.org
Mon Mar 20 17:50:45 UTC 2017


'all_dbs' maps from a schema name to its struct db, so there's no need to
iterate the whole thing to find a database by schema name; instead, just
use the shash in the usual way.

Also, avoid trying too hard in ovsdb_replication_init() in a similar way.

Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 ovsdb/ovsdb-server.c | 19 ++-----------------
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index 4f88500a054d..3305aa8e541e 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -145,7 +145,7 @@ ovsdb_replication_init(const char *sync_from, const char *exclude,
     struct shash_node *node;
     SHASH_FOR_EACH (node, all_dbs) {
         struct db *db = node->data;
-        replication_add_local_db(db->db->schema->name, db->db);
+        replication_add_local_db(node->name, db->db);
     }
 }
 
@@ -529,21 +529,6 @@ open_db(struct server_config *config, const char *filename)
     return error;
 }
 
-static const struct db *
-find_db(const struct shash *all_dbs, const char *db_name)
-{
-    struct shash_node *node;
-
-    SHASH_FOR_EACH (node, all_dbs) {
-        struct db *db = node->data;
-        if (!strcmp(db->db->schema->name, db_name)) {
-            return db;
-        }
-    }
-
-    return NULL;
-}
-
 static char * OVS_WARN_UNUSED_RESULT
 parse_db_column__(const struct shash *all_dbs,
                   const char *name_, char *name,
@@ -574,7 +559,7 @@ parse_db_column__(const struct shash *all_dbs,
     table_name = tokens[1];
     column_name = tokens[2];
 
-    db = find_db(all_dbs, tokens[0]);
+    db = shash_find_data(all_dbs, tokens[0]);
     if (!db) {
         return xasprintf("\"%s\": no database named %s", name_, db_name);
     }
-- 
2.10.2



More information about the dev mailing list