From 524555d18bda66f4f2c4bcb7bfb83b22bf50a942 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 11 Dec 2009 10:40:55 -0800 Subject: [PATCH] ovs-vsctl: Initialize the database automatically. --- utilities/ovs-vsctl.8.in | 10 ++++++++++ utilities/ovs-vsctl.c | 19 +++++++++++++------ xenserver/etc_init.d_vswitch | 4 +--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/utilities/ovs-vsctl.8.in b/utilities/ovs-vsctl.8.in index 46bbbe288..a836fb739 100644 --- a/utilities/ovs-vsctl.8.in +++ b/utilities/ovs-vsctl.8.in @@ -101,6 +101,16 @@ Prints a blank line for each command that has no output. .SH COMMANDS The commands implemented by \fBovs\-vsctl\fR are described in the sections below. +.SS "Open vSwitch Commands" +These commands work with an Open vSwitch as a whole. +. +.IP "\fBinit\fR" +Initializes the Open vSwitch database, if it is empty. If the +database has already been initialized, this command has no effect. +.IP +Any successful \fBovs\-vsctl\fR command automatically initializes the +Open vSwitch database if it is empty. This command is provided to +initialize the database without executing any other command. . .SS "Bridge Commands" These commands examine and manipulate Open vSwitch bridges. diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index 8de6ae112..e86cb7cd9 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -94,7 +94,7 @@ main(int argc, char *argv[]) vsctl_fatal("missing command name (use --help for help)"); } - /* Now execut the commands. */ + /* Now execute the commands. */ idl = ovsdb_idl_create(db, &ovsrec_idl_class); seqno = ovsdb_idl_get_seqno(idl); trials = 0; @@ -623,6 +623,11 @@ ovs_delete_bridge(const struct ovsrec_open_vswitch *ovs, free(bridges); } +static void +cmd_init(struct vsctl_context *ctx UNUSED) +{ +} + static void cmd_add_br(struct vsctl_context *ctx) { @@ -1186,15 +1191,14 @@ do_vsctl(int argc, char *argv[], struct ovsdb_idl *idl) int n_output; int i, start; + txn = ovsdb_idl_txn_create(idl); + ovs = ovsrec_open_vswitch_first(idl); if (!ovs) { - /* XXX it would be more user-friendly to create a record ourselves - * (while verifying that the table is empty before doing so). */ - vsctl_fatal("%s: database does not contain any Open vSwitch " - "configuration", db); + /* XXX add verification that table is empty */ + ovs = ovsrec_open_vswitch_insert(txn); } - txn = ovsdb_idl_txn_create(idl); output = xmalloc(argc * sizeof *output); n_output = 0; for (start = i = 0; i <= argc; i++) { @@ -1273,6 +1277,9 @@ static vsctl_handler_func * get_vsctl_handler(int argc, char *argv[], struct vsctl_context *ctx) { static const struct vsctl_command all_commands[] = { + /* Open vSwitch commands. */ + {"init", 0, 0, cmd_init, ""}, + /* Bridge commands. */ {"add-br", 1, 3, cmd_add_br, ""}, {"del-br", 1, 1, cmd_del_br, "--if-exists"}, diff --git a/xenserver/etc_init.d_vswitch b/xenserver/etc_init.d_vswitch index 7460a212b..60bbd055c 100755 --- a/xenserver/etc_init.d_vswitch +++ b/xenserver/etc_init.d_vswitch @@ -336,12 +336,10 @@ function start { action "Creating empty database $OVSDB_SERVER_DB" true $ovsdb_tool create "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA" - - action "Creating initial table in $OVSDB_SERVER_DB" true - $ovsdb_tool transact "$OVSDB_SERVER_DB" '[{"op": "insert", "table": "Open_vSwitch", "row": {}}]' fi start_ovsdb_server + $vsctl --no-wait init if [ ! -e /var/run/vswitch.booted ]; then touch /var/run/vswitch.booted for bridge in $($vsctl list-br); do -- 2.45.2