summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/db-ctl-base.c20
-rw-r--r--lib/db-ctl-base.h4
-rw-r--r--utilities/ovs-vsctl.c26
-rw-r--r--vtep/vtep-ctl.c22
4 files changed, 38 insertions, 34 deletions
diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c
index 09efd8d9f..a1d6e4ea9 100644
--- a/lib/db-ctl-base.c
+++ b/lib/db-ctl-base.c
@@ -34,6 +34,7 @@
#include "ovsdb-idl.h"
#include "ovsdb-idl-provider.h"
#include "shash.h"
+#include "sset.h"
#include "string.h"
#include "table.h"
#include "util.h"
@@ -1648,9 +1649,12 @@ cmd_show_find_table_by_name(const char *name)
return NULL;
}
+/* 'shown' records the tables that has been displayed by the current
+ * command to avoid duplicated prints.
+ */
static void
cmd_show_row(struct ctl_context *ctx, const struct ovsdb_idl_row *row,
- int level)
+ int level, struct sset *shown)
{
struct cmd_show_table *show = cmd_show_find_table_by_row(row);
size_t i;
@@ -1667,11 +1671,11 @@ cmd_show_row(struct ctl_context *ctx, const struct ovsdb_idl_row *row,
}
ds_put_char(&ctx->output, '\n');
- if (!show || show->recurse) {
+ if (!show || sset_find(shown, show->table->name)) {
return;
}
- show->recurse = true;
+ sset_add(shown, show->table->name);
for (i = 0; i < ARRAY_SIZE(show->columns); i++) {
const struct ovsdb_idl_column *column = show->columns[i];
const struct ovsdb_datum *datum;
@@ -1696,7 +1700,7 @@ cmd_show_row(struct ctl_context *ctx, const struct ovsdb_idl_row *row,
ref_show->table,
&datum->keys[j].uuid);
if (ref_row) {
- cmd_show_row(ctx, ref_row, level + 1);
+ cmd_show_row(ctx, ref_row, level + 1, shown);
}
}
continue;
@@ -1749,18 +1753,22 @@ cmd_show_row(struct ctl_context *ctx, const struct ovsdb_idl_row *row,
ds_put_char(&ctx->output, '\n');
}
}
- show->recurse = false;
+ sset_find_and_delete_assert(shown, show->table->name);
}
static void
cmd_show(struct ctl_context *ctx)
{
const struct ovsdb_idl_row *row;
+ struct sset shown = SSET_INITIALIZER(&shown);
for (row = ovsdb_idl_first_row(ctx->idl, cmd_show_tables[0].table);
row; row = ovsdb_idl_next_row(row)) {
- cmd_show_row(ctx, row, 0);
+ cmd_show_row(ctx, row, 0, &shown);
}
+
+ ovs_assert(sset_is_empty(&shown));
+ sset_destroy(&shown);
}
diff --git a/lib/db-ctl-base.h b/lib/db-ctl-base.h
index 9220ecec6..aff242bf9 100644
--- a/lib/db-ctl-base.h
+++ b/lib/db-ctl-base.h
@@ -157,15 +157,11 @@ struct ctl_command *ctl_parse_commands(int argc, char *argv[],
*
* - 'columns[]' allows user to specify the print of additional columns
* in 'table'.
- *
- * - 'recurse' is used to avoid duplicate print.
- *
* */
struct cmd_show_table {
const struct ovsdb_idl_table_class *table;
const struct ovsdb_idl_column *name_column;
const struct ovsdb_idl_column *columns[3]; /* Seems like a good number. */
- bool recurse;
};
/* This array defines the 'show' command output format. User can check the
diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c
index 4fb88b117..ce05c470e 100644
--- a/utilities/ovs-vsctl.c
+++ b/utilities/ovs-vsctl.c
@@ -980,45 +980,45 @@ struct cmd_show_table cmd_show_tables[] = {
NULL,
{&ovsrec_open_vswitch_col_manager_options,
&ovsrec_open_vswitch_col_bridges,
- &ovsrec_open_vswitch_col_ovs_version},
- false},
+ &ovsrec_open_vswitch_col_ovs_version}
+ },
{&ovsrec_table_bridge,
&ovsrec_bridge_col_name,
{&ovsrec_bridge_col_controller,
&ovsrec_bridge_col_fail_mode,
- &ovsrec_bridge_col_ports},
- false},
+ &ovsrec_bridge_col_ports}
+ },
{&ovsrec_table_port,
&ovsrec_port_col_name,
{&ovsrec_port_col_tag,
&ovsrec_port_col_trunks,
- &ovsrec_port_col_interfaces},
- false},
+ &ovsrec_port_col_interfaces}
+ },
{&ovsrec_table_interface,
&ovsrec_interface_col_name,
{&ovsrec_interface_col_type,
&ovsrec_interface_col_options,
- &ovsrec_interface_col_error},
- false},
+ &ovsrec_interface_col_error}
+ },
{&ovsrec_table_controller,
&ovsrec_controller_col_target,
{&ovsrec_controller_col_is_connected,
NULL,
- NULL},
- false},
+ NULL}
+ },
{&ovsrec_table_manager,
&ovsrec_manager_col_target,
{&ovsrec_manager_col_is_connected,
NULL,
- NULL},
- false},
+ NULL}
+ },
- {NULL, NULL, {NULL, NULL, NULL}, false}
+ {NULL, NULL, {NULL, NULL, NULL}}
};
static void
diff --git a/vtep/vtep-ctl.c b/vtep/vtep-ctl.c
index be8fd5648..98afbdada 100644
--- a/vtep/vtep-ctl.c
+++ b/vtep/vtep-ctl.c
@@ -369,38 +369,38 @@ struct cmd_show_table cmd_show_tables[] = {
NULL,
{&vteprec_global_col_managers,
&vteprec_global_col_switches,
- NULL},
- false},
+ NULL}
+ },
{&vteprec_table_manager,
&vteprec_manager_col_target,
{&vteprec_manager_col_is_connected,
NULL,
- NULL},
- false},
+ NULL}
+ },
{&vteprec_table_physical_switch,
&vteprec_physical_switch_col_name,
{&vteprec_physical_switch_col_management_ips,
&vteprec_physical_switch_col_tunnel_ips,
- &vteprec_physical_switch_col_ports},
- false},
+ &vteprec_physical_switch_col_ports}
+ },
{&vteprec_table_physical_port,
&vteprec_physical_port_col_name,
{&vteprec_physical_port_col_vlan_bindings,
NULL,
- NULL},
- false},
+ NULL}
+ },
{&vteprec_table_logical_switch,
&vteprec_logical_switch_col_name,
{NULL,
NULL,
- NULL},
- false},
+ NULL}
+ },
- {NULL, NULL, {NULL, NULL, NULL}, false}
+ {NULL, NULL, {NULL, NULL, NULL}}
};
/* vtep-ctl specific context. Inherits the 'struct ctl_context' as base. */