Cleanup default file locations and XenServer packaging
[sliver-openvswitch.git] / utilities / ovs-vsctl.c
index 9baca42..0bf87c2 100644 (file)
@@ -449,7 +449,7 @@ default_db(void)
 {
     static char *def;
     if (!def) {
-        def = xasprintf("unix:%s/ovsdb-server", ovs_rundir);
+        def = xasprintf("unix:%s/db.sock", ovs_rundir);
     }
     return def;
 }
@@ -824,7 +824,7 @@ ovs_delete_bridge(const struct ovsrec_open_vswitch *ovs,
 }
 
 static void
-cmd_init(struct vsctl_context *ctx UNUSED)
+cmd_init(struct vsctl_context *ctx OVS_UNUSED)
 {
 }
 
@@ -832,10 +832,9 @@ static void
 cmd_add_br(struct vsctl_context *ctx)
 {
     bool may_exist = shash_find(&ctx->options, "--may-exist") != 0;
-    const char *br_name = ctx->argv[1];
-    const char *parent_name = ctx->argc > 2 ? ctx->argv[2] : NULL;
-    int vlan = ctx->argc > 3 ? atoi(ctx->argv[3]) : 0;
+    const char *br_name, *parent_name;
     struct vsctl_info info;
+    int vlan;
 
     br_name = ctx->argv[1];
     if (ctx->argc == 2) {
@@ -1278,31 +1277,50 @@ static void
 cmd_del_port(struct vsctl_context *ctx)
 {
     bool must_exist = !shash_find(&ctx->options, "--if-exists");
+    bool with_iface = shash_find(&ctx->options, "--with-iface") != NULL;
+    struct vsctl_port *port;
     struct vsctl_info info;
 
     get_info(ctx->ovs, &info);
-    if (ctx->argc == 2) {
-        struct vsctl_port *port = find_port(&info, ctx->argv[1], must_exist);
-        if (port) {
-            del_port(&info, port);
+    if (!with_iface) {
+        port = find_port(&info, ctx->argv[ctx->argc - 1], must_exist);
+    } else {
+        const char *target = ctx->argv[ctx->argc - 1];
+        struct vsctl_iface *iface;
+
+        port = find_port(&info, target, false);
+        if (!port) {
+            iface = find_iface(&info, target, false);
+            if (iface) {
+                port = iface->port;
+            }
+        }
+        if (must_exist && !port) {
+            vsctl_fatal("no port or interface named %s", target);
         }
-    } else if (ctx->argc == 3) {
-        struct vsctl_bridge *bridge = find_bridge(&info, ctx->argv[1], true);
-        struct vsctl_port *port = find_port(&info, ctx->argv[2], must_exist);
+    }
 
-        if (port) {
-            if (port->bridge == bridge) {
-                del_port(&info, port);
-            } else if (port->bridge->parent == bridge) {
-                vsctl_fatal("bridge %s does not have a port %s (although its "
-                            "parent bridge %s does)",
-                            ctx->argv[1], ctx->argv[2], bridge->parent->name);
-            } else {
-                vsctl_fatal("bridge %s does not have a port %s",
-                            ctx->argv[1], ctx->argv[2]);
+    if (port) {
+        if (ctx->argc == 3) {
+            struct vsctl_bridge *bridge;
+
+            bridge = find_bridge(&info, ctx->argv[1], true);
+            if (port->bridge != bridge) {
+                if (port->bridge->parent == bridge) {
+                    vsctl_fatal("bridge %s does not have a port %s (although "
+                                "its parent bridge %s does)",
+                                ctx->argv[1], ctx->argv[2],
+                                bridge->parent->name);
+                } else {
+                    vsctl_fatal("bridge %s does not have a port %s",
+                                ctx->argv[1], ctx->argv[2]);
+                }
             }
         }
+
+        del_port(&info, port);
     }
+
     free_info(&info);
 }
 
@@ -2335,7 +2353,6 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands,
     enum ovsdb_idl_txn_status status;
     struct vsctl_command *c;
     int64_t next_cfg = 0;
-    char *comment;
     char *error;
 
     txn = the_idl_txn = ovsdb_idl_txn_create(idl);
@@ -2343,9 +2360,7 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands,
         ovsdb_idl_txn_set_dry_run(txn);
     }
 
-    comment = xasprintf("ovs-vsctl: %s", args);
-    ovsdb_idl_txn_add_comment(txn, comment);
-    free(comment);
+    ovsdb_idl_txn_add_comment(txn, "ovs-vsctl: %s", args);
 
     ovs = ovsrec_open_vswitch_first(idl);
     if (!ovs) {
@@ -2368,12 +2383,7 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands,
         vsctl_context_done(&ctx, c);
     }
 
-    while ((status = ovsdb_idl_txn_commit(txn)) == TXN_INCOMPLETE) {
-        ovsdb_idl_run(idl);
-        ovsdb_idl_wait(idl);
-        ovsdb_idl_txn_wait(txn);
-        poll_block();
-    }
+    status = ovsdb_idl_txn_commit_block(txn);
     if (wait_for_reload && status == TXN_SUCCESS) {
         next_cfg = ovsdb_idl_txn_get_increment_new_value(txn);
     }
@@ -2485,7 +2495,7 @@ static const struct vsctl_command_syntax all_commands[] = {
     {"list-ports", 1, 1, cmd_list_ports, NULL, ""},
     {"add-port", 2, 2, cmd_add_port, NULL, "--may-exist"},
     {"add-bond", 4, INT_MAX, cmd_add_bond, NULL, "--may-exist,--fake-iface"},
-    {"del-port", 1, 2, cmd_del_port, NULL, "--if-exists"},
+    {"del-port", 1, 2, cmd_del_port, NULL, "--if-exists,--with-iface"},
     {"port-to-br", 1, 1, cmd_port_to_br, NULL, ""},
 
     /* Interface commands. */