datapath: Set datapath device MTU to minimum of MTU of ports.
[openvswitch] / utilities / ovs-vsctl.c
index 60ab0f5b825abf4127c84aaefe58433920772129..733536894a73295645be10cc4bc085c01b736a3e 100644 (file)
@@ -1496,15 +1496,15 @@ struct vsctl_column {
 };
 
 static const struct vsctl_column bridge_columns[] = {
+    {&ovsrec_bridge_col_controller, VSCF_READONLY, NULL},
     {&ovsrec_bridge_col_datapath_id, VSCF_READONLY, NULL},
     {&ovsrec_bridge_col_datapath_type, VSCF_READONLY, NULL},
-    {&ovsrec_bridge_col_name, VSCF_READONLY, NULL},
-    {&ovsrec_bridge_col_mirrors, VSCF_READONLY, NULL},
-    {&ovsrec_bridge_col_other_config, 0, NULL},
+    {&ovsrec_bridge_col_external_ids, 0, NULL},
     {&ovsrec_bridge_col_flood_vlans, 0, "[1,4095]"},
-    {&ovsrec_bridge_col_controller, VSCF_READONLY, NULL},
+    {&ovsrec_bridge_col_mirrors, VSCF_READONLY, NULL},
+    {&ovsrec_bridge_col_name, VSCF_READONLY, NULL},
     {&ovsrec_bridge_col_netflow, VSCF_READONLY, NULL},
-    {&ovsrec_bridge_col_external_ids, 0, NULL},
+    {&ovsrec_bridge_col_other_config, 0, NULL},
     {&ovsrec_bridge_col_ports, VSCF_READONLY, NULL},
     {NULL, 0, NULL},
 };
@@ -1550,9 +1550,9 @@ static const struct vsctl_column mirror_columns[] = {
 static const struct vsctl_column netflow_columns[] = {
     {&ovsrec_netflow_col_active_timeout, 0, "[-1,]"},
     {&ovsrec_netflow_col_add_id_to_interface, 0, NULL},
-    {&ovsrec_netflow_col_targets, 0, IP_RE":"PORT_RE},
-    {&ovsrec_netflow_col_engine_type, 0, "[0,255]"},
     {&ovsrec_netflow_col_engine_id, 0, "[0,255]"},
+    {&ovsrec_netflow_col_engine_type, 0, "[0,255]"},
+    {&ovsrec_netflow_col_targets, 0, IP_RE":"PORT_RE},
     {NULL, 0, NULL},
 };
 
@@ -1560,7 +1560,6 @@ static const struct vsctl_column open_vswitch_columns[] = {
     {&ovsrec_open_vswitch_col_bridges, VSCF_READONLY, NULL},
     {&ovsrec_open_vswitch_col_controller, VSCF_READONLY, NULL},
     {&ovsrec_open_vswitch_col_cur_cfg, VSCF_HIDDEN, NULL},
-    {&ovsrec_open_vswitch_col_management_id, 0, "[0-9a-fA-F]{12}"},
     {&ovsrec_open_vswitch_col_managers, 0, "p?(ssl|tcp|unix):.*"},
     {&ovsrec_open_vswitch_col_next_cfg, VSCF_HIDDEN, NULL},
     {&ovsrec_open_vswitch_col_ssl, VSCF_READONLY, NULL},
@@ -1568,9 +1567,9 @@ static const struct vsctl_column open_vswitch_columns[] = {
 };
 
 static const struct vsctl_column port_columns[] = {
-    {&ovsrec_port_col_bond_updelay, 0, "[0,]"},
     {&ovsrec_port_col_bond_downdelay, 0, "[0,]"},
     {&ovsrec_port_col_bond_fake_iface, VSCF_READONLY, NULL},
+    {&ovsrec_port_col_bond_updelay, 0, "[0,]"},
     {&ovsrec_port_col_external_ids, 0, NULL},
     {&ovsrec_port_col_fake_bridge, VSCF_READONLY, NULL},
     {&ovsrec_port_col_interfaces, VSCF_READONLY, NULL},
@@ -1746,6 +1745,10 @@ get_row_by_id(struct vsctl_context *ctx, const struct vsctl_table_class *table,
             }
             ovsdb_datum_destroy(&name, &id->name_column->type);
         }
+        if (best_score && !referrer) {
+            ovs_fatal(0, "multiple rows in %s match \"%s\"",
+                      table->class->name, record_id);
+        }
     }
     if (!referrer) {
         return NULL;
@@ -1902,8 +1905,8 @@ parse_column_key_value(const char *arg, const struct vsctl_table_class *table,
             *valuep = NULL;
         }
         if (*p != '\0') {
-            error = xasprintf("%s: trailing garbage in argument at offset %td",
-                              arg, p - arg);
+            error = xasprintf("%s: trailing garbage \"%s\" in argument",
+                              arg, p);
             goto error;
         }
     }
@@ -1927,6 +1930,7 @@ error:
 static void
 cmd_get(struct vsctl_context *ctx)
 {
+    bool if_exists = shash_find(&ctx->options, "--if-exists");
     const char *table_name = ctx->argv[1];
     const char *record_id = ctx->argv[2];
     const struct vsctl_table_class *table;
@@ -1961,14 +1965,15 @@ cmd_get(struct vsctl_context *ctx)
             idx = ovsdb_datum_find_key(&datum, &key,
                                        column->idl->type.key_type);
             if (idx == UINT_MAX) {
-                ovs_fatal(0, "no key %s in %s record \"%s\" column %s",
-                          key_string, table_name, record_id,
-                          column->idl->name);
-
+                if (!if_exists) {
+                    ovs_fatal(0, "no key \"%s\" in %s record \"%s\" column %s",
+                              key_string, table->class->name, record_id,
+                              column->idl->name);
+                }
+            } else {
+                ovsdb_atom_to_string(&datum.values[idx],
+                                     column->idl->type.value_type, out);
             }
-            ovsdb_atom_to_string(&datum.values[idx],
-                                 column->idl->type.value_type, out);
-
             ovsdb_atom_destroy(&key, column->idl->type.key_type);
         } else {
             ovsdb_datum_to_string(&datum, &column->idl->type, out);
@@ -2214,17 +2219,17 @@ cmd_add(struct vsctl_context *ctx)
     table = get_table(table_name);
     row = must_get_row(ctx, table, record_id);
     die_if_error(get_column(table, column_name, &column));
+    if (column->flags & VSCF_READONLY && !force) {
+        ovs_fatal(0, "cannot modify read-only column %s in table %s",
+                   column->idl->name, table->class->name);
+    }
+
     type = &column->idl->type;
     ovsdb_idl_txn_read(row, column->idl, &old);
     for (i = 4; i < ctx->argc; i++) {
         struct ovsdb_type add_type;
         struct ovsdb_datum add;
 
-        if (column->flags & VSCF_READONLY && !force) {
-            ovs_fatal(0, "%s: cannot modify read-only column %s in table %s",
-                      ctx->argv[i], column->idl->name, table_name);
-        }
-
         add_type = *type;
         add_type.n_min = 1;
         add_type.n_max = UINT_MAX;
@@ -2234,10 +2239,10 @@ cmd_add(struct vsctl_context *ctx)
     }
     if (old.n > type->n_max) {
         ovs_fatal(0, "\"add\" operation would put %u %s in column %s of "
-                  "table %s but at most %u are allowed",
+                  "table %s but the maximum number is %u",
                   old.n,
                   type->value_type == OVSDB_TYPE_VOID ? "values" : "pairs",
-                  column->idl->name, table_name, type->n_max);
+                  column->idl->name, table->class->name, type->n_max);
     }
     ovsdb_idl_txn_write(row, column->idl, &old);
 }
@@ -2259,6 +2264,11 @@ cmd_remove(struct vsctl_context *ctx)
     table = get_table(table_name);
     row = must_get_row(ctx, table, record_id);
     die_if_error(get_column(table, column_name, &column));
+    if (column->flags & VSCF_READONLY && !force) {
+        ovs_fatal(0, "cannot modify read-only column %s in table %s",
+                   column->idl->name, table->class->name);
+    }
+
     type = &column->idl->type;
     ovsdb_idl_txn_read(row, column->idl, &old);
     for (i = 4; i < ctx->argc; i++) {
@@ -2266,11 +2276,6 @@ cmd_remove(struct vsctl_context *ctx)
         struct ovsdb_datum rm;
         char *error;
 
-        if (column->flags & VSCF_READONLY && !force) {
-            ovs_fatal(0, "%s: cannot modify read-only column %s in table %s",
-                      ctx->argv[i], column->idl->name, table_name);
-        }
-
         rm_type = *type;
         rm_type.n_min = 1;
         rm_type.n_max = UINT_MAX;
@@ -2285,10 +2290,10 @@ cmd_remove(struct vsctl_context *ctx)
     }
     if (old.n < type->n_min) {
         ovs_fatal(0, "\"remove\" operation would put %u %s in column %s of "
-                  "table %s but at least %u are required",
+                  "table %s but the minimun number is %u",
                   old.n,
                   type->value_type == OVSDB_TYPE_VOID ? "values" : "pairs",
-                  column->idl->name, table_name, type->n_min);
+                  column->idl->name, table->class->name, type->n_min);
     }
     ovsdb_idl_txn_write(row, column->idl, &old);
 }
@@ -2314,12 +2319,12 @@ cmd_clear(struct vsctl_context *ctx)
 
         type = &column->idl->type;
         if (column->flags & VSCF_READONLY && !force) {
-            ovs_fatal(0, "%s: cannot modify read-only column %s in table %s",
-                      ctx->argv[i], column->idl->name, table_name);
+            ovs_fatal(0, "cannot modify read-only column %s in table %s",
+                      column->idl->name, table->class->name);
         } else if (type->n_min > 0) {
             ovs_fatal(0, "\"clear\" operation cannot be applied to column %s "
                       "of table %s, which is not allowed to be empty",
-                      column->idl->name, table_name);
+                      column->idl->name, table->class->name);
         }
 
         ovsdb_datum_init_empty(&datum);
@@ -2603,7 +2608,7 @@ static const struct vsctl_command_syntax all_commands[] = {
     {"set-ssl", 3, 3, cmd_set_ssl, NULL, "--bootstrap"},
 
     /* Parameter commands. */
-    {"get", 3, INT_MAX, cmd_get, NULL, ""},
+    {"get", 3, INT_MAX, cmd_get, NULL, "--if-exists"},
     {"list", 1, INT_MAX, cmd_list, NULL, ""},
     {"set", 3, INT_MAX, cmd_set, NULL, "--force"},
     {"add", 4, INT_MAX, cmd_add, NULL, "--force"},