Adds the ability to delete all records from table. This will help users to destroy all records from Qos or Queue table using single command rather then current method.
Feature #11306 Suggested-by: Kevin Mancuso <kevin.manc...@rackspace.com> Signed-off-by: Arun Sharma <arun.sha...@calsoftinc.com> --- tests/ovs-vsctl.at | 26 ++++++++++++++++++++++++++ utilities/ovs-vsctl.8.in | 12 ++++++++++-- utilities/ovs-vsctl.c | 24 +++++++++++++++++------- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/tests/ovs-vsctl.at b/tests/ovs-vsctl.at index 584ee79..ec906cc 100644 --- a/tests/ovs-vsctl.at +++ b/tests/ovs-vsctl.at @@ -1041,3 +1041,29 @@ stp_enable : false ]], [ignore], [test ! -e pid || kill `cat pid`]) OVS_VSCTL_CLEANUP AT_CLEANUP + +dnl This test will create a linux-htb QoS record that +dnl points to a few queues and use it on a1 and a2 port. +dnl It also destroys all records from Qos and Queue table. +AT_SETUP([--all option on destroy command]) +AT_KEYWORDS([ovs-vsctl]) +OVS_VSCTL_SETUP +AT_CHECK([RUN_OVS_VSCTL( + [add-br a], + [add-port a a1], + [add-port a a2])], [0], [], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL_TOGETHER( + [set Port a1 qos=@newqos], + [set Port a2 qos=@newqos], + [--id=@newqos create QoS type=linux-htb other-config:max-rate=1000000000 queues=0=@q0,1=@q1], + [--id=@q0 create Queue other-config:min-rate=100000000 other-config:max-rate=10000000], + [--id=@q1 create Queue other-config:min-rate=500000000])], [0], [stdout], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL( + [clear Port a1 qos], + [clear Port a2 qos])], [0], [], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL( + [--all destroy Qos])], [0], [], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL( + [--all destroy Queue])], [0], [], [], [OVS_VSCTL_CLEANUP]) +OVS_VSCTL_CLEANUP +AT_CLEANUP diff --git a/utilities/ovs-vsctl.8.in b/utilities/ovs-vsctl.8.in index 57f76d5..397e453 100644 --- a/utilities/ovs-vsctl.8.in +++ b/utilities/ovs-vsctl.8.in @@ -713,10 +713,17 @@ newly created record from the top-level \fBOpen_vSwitch\fR record. The \fBEXAMPLES\fR section gives some examples that show how to do this. . -.IP "\fR[\fB\-\-if\-exists\fR] \fBdestroy \fItable record\fR..." +.IP "\fR[\fB\-\-if\-exists\fR] \fR[\fB\-\-all\fR] \fBdestroy \fItable [record\fR]..." Deletes each specified \fIrecord\fR from \fItable\fR. Unless \fB\-\-if\-exists\fR is specified, each \fIrecord\fRs must exist. .IP +If \fB\-\-all\fR is specified, then \fIrecord\fR... argument is not required. +All records from the \fItable\fR will be deleted. +.IP +Both \fB\-\-all\fR and \fIrecord\fR... argument are optional, but at least +one or the other should be specified. If both are omitted, then \fBdestroy\fR +has no effect in table. +.IP The \fBdestroy\fR command is only useful for records in the \fBQoS\fR or \fBQueue\fR tables. Records in other tables are automatically deleted from the database when they become unreachable from the @@ -844,7 +851,8 @@ unreferenced QoS records are not automatically destroyed): (This command will leave two unreferenced Queue records in the database. To delete them, use "\fBovs\-vsctl list Queue\fR" to find their UUIDs, then "\fBovs\-vsctl destroy Queue \fIuuid1\fR -\fIuuid2\fR" to destroy each of them.) +\fIuuid2\fR" to destroy each of them or use +"\fBovs\-vsctl -- --all destroy Queue\fR" to delete all records.) .SS "Connectivity Monitoring" .PP Monitor connectivity to a remote maintenance point on eth0. diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index 2fc87f0..9ed46ec 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -3471,20 +3471,30 @@ static void cmd_destroy(struct vsctl_context *ctx) { bool must_exist = !shash_find(&ctx->options, "--if-exists"); + bool delete_all = shash_find(&ctx->options, "--all"); const char *table_name = ctx->argv[1]; const struct vsctl_table_class *table; int i; table = get_table(table_name); - for (i = 2; i < ctx->argc; i++) { + + if (delete_all) { const struct ovsdb_idl_row *row; - row = (must_exist ? must_get_row : get_row)(ctx, table, ctx->argv[i]); - if (row) { - ovsdb_idl_txn_delete(row); + for (row = ovsdb_idl_first_row(ctx->idl, table->class); + row; row = ovsdb_idl_next_row(row)) { + ovsdb_idl_txn_delete(row); } - } + } else { + for (i = 2; i < ctx->argc; i++) { + const struct ovsdb_idl_row *row; + row = (must_exist ? must_get_row : get_row)(ctx, table, ctx->argv[i]); + if (row) { + ovsdb_idl_txn_delete(row); + } + } + } vsctl_context_invalidate_cache(ctx); } @@ -4017,8 +4027,8 @@ static const struct vsctl_command_syntax all_commands[] = { {"remove", 4, INT_MAX, pre_cmd_remove, cmd_remove, NULL, "", RW}, {"clear", 3, INT_MAX, pre_cmd_clear, cmd_clear, NULL, "", RW}, {"create", 2, INT_MAX, pre_create, cmd_create, post_create, "--id=", RW}, - {"destroy", 1, INT_MAX, pre_cmd_destroy, cmd_destroy, NULL, "--if-exists", - RW}, + {"destroy", 1, INT_MAX, pre_cmd_destroy, cmd_destroy, NULL, + "--if-exists,--all", RW}, {"wait-until", 2, INT_MAX, pre_cmd_wait_until, cmd_wait_until, NULL, "", RO}, -- 1.7.2.5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev