[ovs-dev] [PATCH 2/3 v2] ovsdb-server: Make database name mandatory when specifying db paths.

Gurucharan Shetty shettyg at nicira.com
Tue Jun 25 08:02:31 UTC 2013


Currently, if we have just one database, we can optionally skip the
database name when providing the DB path for certain options (ex:
--remote=db:[db,]table,column). But in case we have multiple databases,
it is mandatory.

With this commit, we make the database name mandatory. This provides
increased flexibility for an upcoming commit that provides the ability
to add and remove databases during run time.

Feature #14595.
Signed-off-by: Gurucharan Shetty <gshetty at nicira.com>
---
 ovsdb/ovsdb-server.1.in |   18 ++++++++----------
 ovsdb/ovsdb-server.c    |   31 +++++++++----------------------
 tests/ovsdb-server.at   |    8 ++++----
 3 files changed, 21 insertions(+), 36 deletions(-)

diff --git a/ovsdb/ovsdb-server.1.in b/ovsdb/ovsdb-server.1.in
index 82dd9c6..ceefef5 100644
--- a/ovsdb/ovsdb-server.1.in
+++ b/ovsdb/ovsdb-server.1.in
@@ -45,12 +45,10 @@ Adds \fIremote\fR as a connection method used by \fBovsdb\-server\fR.
 .so ovsdb/remote-passive.man
 .so ovsdb/remote-active.man
 .
-.IP "\fBdb:\fR[\fIdb\fB,\fR]\fItable\fB,\fIcolumn\fR"
+.IP "\fBdb:\fIdb\fB,\fItable\fB,\fIcolumn\fR"
 Reads additional connection methods from \fIcolumn\fR in all of the
-rows in \fItable\fR within \fIdb\fR.  (If \fBovsdb\-server\fR is
-providing access to only one database, then \fIdb\fR is optional.)  As
-the contents of \fIcolumn\fR changes, \fBovsdb\-server\fR also adds
-and drops connection methods accordingly.
+rows in \fItable\fR within \fIdb\fR.  As the contents of \fIcolumn\fR changes,
+\fBovsdb\-server\fR also adds and drops connection methods accordingly.
 .IP
 If \fIcolumn\fR's type is string or set of strings, then the
 connection methods are taken directly from the column.  The connection
@@ -98,9 +96,9 @@ configured remotes.
 The options described below for configuring the SSL public key
 infrastructure accept a special syntax for obtaining their
 configuration from the database.  If any of these options is given
-\fBdb:\fR[\fIdb\fB,\fR]\fItable\fB,\fIcolumn\fR as its argument, then the
+\fBdb:\fIdb\fB,\fItable\fB,\fIcolumn\fR as its argument, then the
 actual file name is read from the specified \fIcolumn\fR in \fItable\fR
-within the \fBovsdb\-server\fR database.  The \fIcolumn\fR must have type
+within the \fIdb\fR database.  The \fIcolumn\fR must have type
 string or set of strings.  The first nonempty string in the table is taken
 as the file name.  (This means that ordinarily there should be at most
 one row in \fItable\fR.)
@@ -140,9 +138,9 @@ with an error if \fIremote\fR is not configured as a remote.  This
 command only works with remotes that were named on \fB\-\-remote\fR or
 \fBovsdb\-server/add\-remote\fR, that is, it will not remove remotes
 added indirectly because they were read from the database by
-configuring a \fBdb:\fR[\fIdb\fB,\fR]\fItable\fB,\fIcolumn\fR remote.
+configuring a \fBdb:\fIdb\fB,\fItable\fB,\fIcolumn\fR remote.
 (You can remove a database source with \fBovsdb\-server/remove\-remote
-\fBdb:\fR[\fIdb\fB,\fR]\fItable\fB,\fIcolumn\fR, but not individual
+\fBdb:\fIdb\fB,\fItable\fB,\fIcolumn\fR, but not individual
 remotes found indirectly through the database.)
 .
 .IP "\fBovsdb\-server/list\-remotes"
@@ -150,7 +148,7 @@ Outputs a list of the currently configured remotes named on
 \fB\-\-remote\fR or \fBovsdb\-server/add\-remote\fR, that is, it does
 not list remotes added indirectly because they were read from the
 database by configuring a
-\fBdb:\fR[\fIdb\fB,\fR]\fItable\fB,\fIcolumn\fR remote.
+\fBdb:\fIdb\fB,\fItable\fB,\fIcolumn\fR remote.
 .
 .so lib/vlog-unixctl.man
 .so lib/memory-unixctl.man
diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index 47b9932..72c13c6 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -342,7 +342,7 @@ parse_db_column__(const struct shash *all_dbs,
                   const struct ovsdb_table **tablep,
                   const struct ovsdb_column **columnp)
 {
-    const char *table_name, *column_name;
+    const char *db_name, *table_name, *column_name;
     const struct ovsdb_column *column;
     const struct ovsdb_table *table;
     const char *tokens[3];
@@ -357,30 +357,17 @@ parse_db_column__(const struct shash *all_dbs,
     tokens[0] = strtok_r(NULL, ",", &save_ptr);
     tokens[1] = strtok_r(NULL, ",", &save_ptr);
     tokens[2] = strtok_r(NULL, ",", &save_ptr);
-    if (!tokens[0] || !tokens[1]) {
+    if (!tokens[0] || !tokens[1] || !tokens[2]) {
         return xasprintf("\"%s\": invalid syntax", name_);
     }
-    if (tokens[2]) {
-        const char *db_name = tokens[0];
-        table_name = tokens[1];
-        column_name = tokens[2];
-
-        db = find_db(all_dbs, tokens[0]);
-        if (!db) {
-            return xasprintf("\"%s\": no database named %s", name_, db_name);
-        }
-    } else {
-        struct shash_node *node;
-        if (shash_count(all_dbs) > 1) {
-            return xasprintf("\"%s\": database name must be specified "
-                             "(because multiple databases are configured)",
-                             name_);
-        }
 
-        table_name = tokens[0];
-        column_name = tokens[1];
-        node = shash_first(all_dbs);
-        db = (struct db *)node->data;
+    db_name = tokens[0];
+    table_name = tokens[1];
+    column_name = tokens[2];
+
+    db = find_db(all_dbs, tokens[0]);
+    if (!db) {
+        return xasprintf("\"%s\": no database named %s", name_, db_name);
     }
 
     table = ovsdb_get_table(db->db, table_name);
diff --git a/tests/ovsdb-server.at b/tests/ovsdb-server.at
index acb5a44..2368cbc 100644
--- a/tests/ovsdb-server.at
+++ b/tests/ovsdb-server.at
@@ -207,7 +207,7 @@ AT_CHECK(
         "uuid-name": "x",
         "row": {"target": "punix:socket2"}}]']], [0], [ignore], [ignore])
 ON_EXIT([kill `cat ovsdb-server.pid`])
-AT_CHECK([ovsdb-server --enable-dummy --detach --no-chdir --pidfile --remote=db:Root,managers --remote=db:Root,manager_options --log-file db], [0], [ignore], [ignore])
+AT_CHECK([ovsdb-server --enable-dummy --detach --no-chdir --pidfile --remote=db:mydb,Root,managers --remote=db:mydb,Root,manager_options --log-file db], [0], [ignore], [ignore])
 for i in 1 2 3 4 5 6; do ovs-appctl -t ovsdb-server time/warp 1000; done
 AT_CHECK(
   [[ovsdb-client transact unix:socket1 \
@@ -344,9 +344,9 @@ AT_CHECK(
 OVS_LOGDIR=`pwd`; export OVS_LOGDIR
 AT_CHECK(
   [ovsdb-server --log-file --detach --no-chdir --pidfile="`pwd`"/pid \
-        --private-key=db:SSL,private_key \
-        --certificate=db:SSL,certificate \
-        --ca-cert=db:SSL,ca_cert \
+        --private-key=db:mydb,SSL,private_key \
+        --certificate=db:mydb,SSL,certificate \
+        --ca-cert=db:mydb,SSL,ca_cert \
         --remote=pssl:0:127.0.0.1 --unixctl="`pwd`"/unixctl db],
   [0], [ignore], [ignore])
 SSL_PORT=`parse_listening_port < ovsdb-server.log`
-- 
1.7.9.5




More information about the dev mailing list