When using virtualization, new ports are created and removed all the time. These ports do not persist after a system reboot, for example. They may be created again by the virtualization manager, but that will happen after the vswitch is already running, and the virtualization manager will add them again to the bridge.
If a reboot happens without properly deleting such ports, all kinds of errors will happen. The absence of the ports will be logged as errors, and adding those ports again to the database will fail. This patch introduces the notion of transient ports. Ports may be added as transient, as a boolean in other_config smap. When openvswitch is restarted by using --delete-transient-ports ovs-ctl option, all transient ports will be removed. If the system administrator wants to remove all transient ports from a bridge, a new ovs-vsctl command, del-transient-ports may be used. Signed-off-by: Thadeu Lima de Souza Cascardo <casca...@redhat.com> --- tests/ovs-vsctl.at | 21 +++++++++++++++++++++ utilities/ovs-ctl.in | 6 ++++++ utilities/ovs-vsctl.8.in | 3 +++ utilities/ovs-vsctl.c | 30 ++++++++++++++++++++++++++++++ vswitchd/vswitch.xml | 8 ++++++++ 5 files changed, 68 insertions(+) diff --git a/tests/ovs-vsctl.at b/tests/ovs-vsctl.at index fef7b88..f877070 100644 --- a/tests/ovs-vsctl.at +++ b/tests/ovs-vsctl.at @@ -304,6 +304,27 @@ CHECK_IFACES([b], [b1]) OVS_VSCTL_CLEANUP AT_CLEANUP +AT_SETUP([add-br a, add-transient-port a a1 a2, del-transient-ports a]) +AT_KEYWORDS([ovs-vsctl del-transient-ports]) +OVS_VSCTL_SETUP +AT_CHECK([RUN_OVS_VSCTL( + [add-br a], + [--if-exists del-br b], + [add-port a a1], + [add-port a a2], + [set port a1 other_config:transient=true], + [set port a2 other_config:transient=true])], [0], [], [], [OVS_VSCTL_CLEANUP]) +CHECK_BRIDGES([a, a, 0]) +CHECK_PORTS([a], [a1], [a2]) +CHECK_IFACES([a], [a1], [a2]) +AT_CHECK([RUN_OVS_VSCTL( + [del-transient-ports a])], [0], [], [], [OVS_VSCTL_CLEANUP]) +CHECK_BRIDGES([a, a, 0]) +CHECK_PORTS([a]) +CHECK_IFACES([a]) +OVS_VSCTL_CLEANUP +AT_CLEANUP + AT_SETUP([add-br a, add-bond a bond0 a1 a2 a3]) AT_KEYWORDS([ovs-vsctl]) OVS_VSCTL_SETUP diff --git a/utilities/ovs-ctl.in b/utilities/ovs-ctl.in index 9bbbe0d..5beb0a2 100755 --- a/utilities/ovs-ctl.in +++ b/utilities/ovs-ctl.in @@ -219,6 +219,11 @@ start_ovsdb () { ovs_vsctl del-br $bridge done fi + if test X"$DELETE_TRANSIENT_PORTS" = Xyes; then + for bridge in `ovs_vsctl list-br`; do + ovs_vsctl del-transient-ports $bridge + done + fi fi } @@ -536,6 +541,7 @@ set_defaults () { SYSTEM_ID= DELETE_BRIDGES=no + DELETE_TRANSIENT_PORTS=no DAEMON_CWD=/ FORCE_COREFILES=yes diff --git a/utilities/ovs-vsctl.8.in b/utilities/ovs-vsctl.8.in index 265ffde..6229312 100644 --- a/utilities/ovs-vsctl.8.in +++ b/utilities/ovs-vsctl.8.in @@ -323,6 +323,9 @@ no effect. Prints the name of the bridge that contains \fIport\fR on standard output. . +.IP "\fBdel\-transient\-ports \fIbridge\fR" +Deletes ports configured as transient from the specified bridge. +. .SS "Interface Commands" . These commands examine the interfaces attached to an Open vSwitch diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index e177060..4526c90 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -380,6 +380,7 @@ Port commands (a bond is considered to be a single port):\n\ add-bond BRIDGE PORT IFACE... add bonded port PORT in BRIDGE from IFACES\n\ del-port [BRIDGE] PORT delete PORT (which may be bonded) from BRIDGE\n\ port-to-br PORT print name of bridge that contains PORT\n\ + del-transient-ports BRIDGE delete transient ports from BRIDGE\n\ \n\ Interface commands (a bond consists of multiple interfaces):\n\ list-ifaces BRIDGE print the names of all interfaces on BRIDGE\n\ @@ -1678,6 +1679,33 @@ cmd_del_port(struct ctl_context *ctx) } static void +pre_transient_ports(struct ctl_context *ctx) +{ + pre_get_info(ctx); + ovsdb_idl_add_column(ctx->idl, &ovsrec_port_col_other_config); +} + +static void +cmd_del_transient_ports(struct ctl_context *ctx) +{ + struct vsctl_context *vsctl_ctx = vsctl_context_cast(ctx); + const char *target = ctx->argv[1]; + struct vsctl_bridge *bridge; + struct vsctl_port *port, *next_port; + + vsctl_context_populate_cache(ctx); + bridge = find_bridge(vsctl_ctx, target, true); + + LIST_FOR_EACH_SAFE (port, next_port, ports_node, &bridge->ports) { + struct ovsrec_port *cfg = port->port_cfg; + bool transient = smap_get_bool(&cfg->other_config, "transient", false); + if (transient) { + del_port(vsctl_ctx, port); + } + } +} + +static void cmd_port_to_br(struct ctl_context *ctx) { struct vsctl_context *vsctl_ctx = vsctl_context_cast(ctx); @@ -2732,6 +2760,8 @@ static const struct ctl_command_syntax vsctl_commands[] = { {"del-port", 1, 2, "[BRIDGE] PORT|IFACE", pre_get_info, cmd_del_port, NULL, "--if-exists,--with-iface", RW}, {"port-to-br", 1, 1, "PORT", pre_get_info, cmd_port_to_br, NULL, "", RO}, + {"del-transient-ports", 1, 1, "BRIDGE", pre_transient_ports, + cmd_del_transient_ports, NULL, "", RW}, /* Interface commands. */ {"list-ifaces", 1, 1, "BRIDGE", pre_get_info, cmd_list_ifaces, NULL, "", diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml index 457f34a..1f9174d 100644 --- a/vswitchd/vswitch.xml +++ b/vswitchd/vswitch.xml @@ -1659,6 +1659,14 @@ <code>fake-bridge-</code>, e.g. <code>fake-bridge-xs-network-uuids</code>. </column> + + <column name="other_config" key="transient" + type='{"type": "boolean"}'> + <p> + If set to <code>true</code>, the port will be removed when + <code>ovs-vsctl del-transient-ports</code> is used on the bridge. + </p> + </column> </group> <column name="bond_active_slave"> -- 2.4.3 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev