From eeb8467eec55dc5808bfc4ca1e1f6a49275c51d5 Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Wed, 16 May 2012 11:39:55 -0700 Subject: [PATCH 1/1] ovs-vsctl: Add "--all" option for "destroy" command in ovs-vsctl. 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 Signed-off-by: Arun Sharma Signed-off-by: Ben Pfaff --- AUTHORS | 1 + tests/ovs-vsctl.at | 48 ++++++++++++++++++++++++++++++++++++++++ utilities/ovs-vsctl.8.in | 5 ++++- utilities/ovs-vsctl.c | 35 +++++++++++++++++++++++------ 4 files changed, 81 insertions(+), 8 deletions(-) diff --git a/AUTHORS b/AUTHORS index 379b6ab07..6e344ab01 100644 --- a/AUTHORS +++ b/AUTHORS @@ -115,6 +115,7 @@ Jed Daniels openvswitch@jeddaniels.com Jeongkeun Lee jklee@hp.com Joan Cirer joan@ev0.net John Galgay john@galgay.net +Kevin Mancuso kevin.mancuso@rackspace.com Koichi Yagishita yagishita.koichi@jrc.co.jp Krishna Miriyala krishna@nicira.com Luca Falavigna dktrkranz@debian.org diff --git a/tests/ovs-vsctl.at b/tests/ovs-vsctl.at index 584ee79b9..7872bfee6 100644 --- a/tests/ovs-vsctl.at +++ b/tests/ovs-vsctl.at @@ -1041,3 +1041,51 @@ 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]) +CHECK_BRIDGES([a, a, 0]) +CHECK_PORTS([a], [a1], [a2]) +CHECK_IFACES([a], [a1], [a2]) +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=100000000], + [--id=@q1 create Queue other-config:min-rate=500000000])], [0], [ignore], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL( + [--columns=other_config,type list Qos])], [0], +[other_config : {max-rate="1000000000"} +type : linux-htb +], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL( + [--columns=other_config list Queue | sort | xargs echo])], [0], +[other_config : {max-rate=100000000, min-rate=100000000} other_config : {min-rate=500000000} +], [], [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( + [--columns=qos list Port a1 a2])], [0], +[[qos : [] + +qos : [] +]], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL( + [--all destroy Qos])], [0], [], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL( + [-- list Qos])], [0], [], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL( + [--all destroy Queue])], [0], [], [], [OVS_VSCTL_CLEANUP]) +AT_CHECK([RUN_OVS_VSCTL( + [-- list 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 57f76d5fb..9ec8d33ee 100644 --- a/utilities/ovs-vsctl.8.in +++ b/utilities/ovs-vsctl.8.in @@ -716,6 +716,8 @@ this. .IP "\fR[\fB\-\-if\-exists\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 "\fB\-\-all destroy \fItable\fR" +Deletes all records from the \fItable\fR. .IP The \fBdestroy\fR command is only useful for records in the \fBQoS\fR or \fBQueue\fR tables. Records in other tables are automatically @@ -844,7 +846,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 d8aeb53d8..bd4725807 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -3471,20 +3471,41 @@ 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 && ctx->argc > 2) { + vsctl_fatal("--all and records argument should not be specified together"); + } + + if (delete_all && !must_exist) { + vsctl_fatal("--all and --if-exists should not be specified together"); + } + + if (delete_all) { const struct ovsdb_idl_row *row; + const struct ovsdb_idl_row *next_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;) { + next_row = ovsdb_idl_next_row(row); + ovsdb_idl_txn_delete(row); + row = next_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); } @@ -4015,8 +4036,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}, -- 2.45.2