ovs-vsctl: Add context pointer to struct vsctl_info.
[sliver-openvswitch.git] / utilities / ovs-vsctl.c
index d68e474..f370d6b 100644 (file)
@@ -85,7 +85,7 @@ static bool dry_run;
 static bool wait_for_reload = true;
 
 /* --timeout: Time to wait for a connection to 'db'. */
-static int timeout = 5;
+static int timeout;
 
 /* All supported commands. */
 static const struct vsctl_command_syntax all_commands[];
@@ -182,12 +182,16 @@ parse_options(int argc, char *argv[])
 #endif
         {0, 0, 0, 0},
     };
+    char *tmp, *short_options;
 
+    tmp = long_options_to_short_options(long_options);
+    short_options = xasprintf("+%s", tmp);
+    free(tmp);
 
     for (;;) {
         int c;
 
-        c = getopt_long(argc, argv, "+v::hVt:", long_options, NULL);
+        c = getopt_long(argc, argv, short_options, long_options, NULL);
         if (c == -1) {
             break;
         }
@@ -245,6 +249,7 @@ parse_options(int argc, char *argv[])
             abort();
         }
     }
+    free(short_options);
 
     if (!db) {
         db = default_db();
@@ -529,6 +534,7 @@ struct vsctl_iface {
 };
 
 struct vsctl_info {
+    struct vsctl_context *ctx;
     struct shash bridges;
     struct shash ports;
     struct shash ifaces;
@@ -622,11 +628,13 @@ free_info(struct vsctl_info *info)
 }
 
 static void
-get_info(const struct ovsrec_open_vswitch *ovs, struct vsctl_info *info)
+get_info(struct vsctl_context *ctx, struct vsctl_info *info)
 {
+    const struct ovsrec_open_vswitch *ovs = ctx->ovs;
     struct shash bridges, ports;
     size_t i;
 
+    info->ctx = ctx;
     shash_init(&info->bridges);
     shash_init(&info->ports);
     shash_init(&info->ifaces);
@@ -967,7 +975,7 @@ cmd_add_br(struct vsctl_context *ctx)
                     ctx->argv[0]);
     }
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     if (may_exist) {
         struct vsctl_bridge *br;
 
@@ -1075,7 +1083,7 @@ cmd_del_br(struct vsctl_context *ctx)
     struct vsctl_bridge *bridge;
     struct vsctl_info info;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     bridge = find_bridge(&info, ctx->argv[1], must_exist);
     if (bridge) {
         struct shash_node *node;
@@ -1114,7 +1122,7 @@ cmd_list_br(struct vsctl_context *ctx)
     struct vsctl_info info;
     struct svec bridges;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
 
     svec_init(&bridges);
     SHASH_FOR_EACH (node, &info.bridges) {
@@ -1132,7 +1140,7 @@ cmd_br_exists(struct vsctl_context *ctx)
 {
     struct vsctl_info info;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     if (!find_bridge(&info, ctx->argv[1], false)) {
         vsctl_exit(2);
     }
@@ -1186,7 +1194,7 @@ cmd_br_set_external_id(struct vsctl_context *ctx)
     char **keys, **values;
     size_t n;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     bridge = find_bridge(&info, ctx->argv[1], true);
     if (bridge->br_cfg) {
         set_external_id(bridge->br_cfg->key_external_ids,
@@ -1241,7 +1249,7 @@ cmd_br_get_external_id(struct vsctl_context *ctx)
     struct vsctl_info info;
     struct vsctl_bridge *bridge;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     bridge = find_bridge(&info, ctx->argv[1], true);
     if (bridge->br_cfg) {
         get_external_id(bridge->br_cfg->key_external_ids,
@@ -1268,7 +1276,7 @@ cmd_list_ports(struct vsctl_context *ctx)
     struct vsctl_info info;
     struct svec ports;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     br = find_bridge(&info, ctx->argv[1], true);
 
     svec_init(&ports);
@@ -1298,7 +1306,7 @@ add_port(struct vsctl_context *ctx,
     struct ovsrec_port *port;
     size_t i;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     if (may_exist) {
         struct vsctl_port *port;
 
@@ -1418,7 +1426,7 @@ cmd_del_port(struct vsctl_context *ctx)
     struct vsctl_port *port;
     struct vsctl_info info;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     if (!with_iface) {
         port = find_port(&info, ctx->argv[ctx->argc - 1], must_exist);
     } else {
@@ -1467,7 +1475,7 @@ cmd_port_to_br(struct vsctl_context *ctx)
     struct vsctl_port *port;
     struct vsctl_info info;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     port = find_port(&info, ctx->argv[1], true);
     ds_put_format(&ctx->output, "%s\n", port->bridge->name);
     free_info(&info);
@@ -1479,7 +1487,7 @@ cmd_br_to_vlan(struct vsctl_context *ctx)
     struct vsctl_bridge *bridge;
     struct vsctl_info info;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     bridge = find_bridge(&info, ctx->argv[1], true);
     ds_put_format(&ctx->output, "%d\n", bridge->vlan);
     free_info(&info);
@@ -1491,7 +1499,7 @@ cmd_br_to_parent(struct vsctl_context *ctx)
     struct vsctl_bridge *bridge;
     struct vsctl_info info;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     bridge = find_bridge(&info, ctx->argv[1], true);
     if (bridge->parent) {
         bridge = bridge->parent;
@@ -1508,7 +1516,7 @@ cmd_list_ifaces(struct vsctl_context *ctx)
     struct vsctl_info info;
     struct svec ifaces;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     br = find_bridge(&info, ctx->argv[1], true);
 
     svec_init(&ifaces);
@@ -1532,7 +1540,7 @@ cmd_iface_to_br(struct vsctl_context *ctx)
     struct vsctl_iface *iface;
     struct vsctl_info info;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     iface = find_iface(&info, ctx->argv[1], true);
     ds_put_format(&ctx->output, "%s\n", iface->port->bridge->name);
     free_info(&info);
@@ -1546,7 +1554,7 @@ cmd_get_controller(struct vsctl_context *ctx)
     struct svec targets;
     size_t i;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     br = find_bridge(&info, ctx->argv[1], true);
 
     /* Print the targets in sorted order for reproducibility. */
@@ -1581,7 +1589,7 @@ cmd_del_controller(struct vsctl_context *ctx)
     struct vsctl_info info;
     struct vsctl_bridge *br;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     br = find_real_bridge(&info, ctx->argv[1], true);
 
     if (br->ctrl) {
@@ -1615,7 +1623,7 @@ cmd_set_controller(struct vsctl_context *ctx)
     struct ovsrec_controller **controllers;
     size_t n;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     br = find_real_bridge(&info, ctx->argv[1], true);
 
     delete_controllers(br->ctrl, br->n_ctrl);
@@ -1634,7 +1642,7 @@ cmd_get_fail_mode(struct vsctl_context *ctx)
     struct vsctl_info info;
     struct vsctl_bridge *br;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     br = find_bridge(&info, ctx->argv[1], true);
 
     if (br->fail_mode && strlen(br->fail_mode)) {
@@ -1650,7 +1658,7 @@ cmd_del_fail_mode(struct vsctl_context *ctx)
     struct vsctl_info info;
     struct vsctl_bridge *br;
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     br = find_real_bridge(&info, ctx->argv[1], true);
 
     ovsrec_bridge_set_fail_mode(br->br_cfg, NULL);
@@ -1665,7 +1673,7 @@ cmd_set_fail_mode(struct vsctl_context *ctx)
     struct vsctl_bridge *br;
     const char *fail_mode = ctx->argv[2];
 
-    get_info(ctx->ovs, &info);
+    get_info(ctx, &info);
     br = find_real_bridge(&info, ctx->argv[1], true);
 
     if (strcmp(fail_mode, "standalone") && strcmp(fail_mode, "secure")) {