From 7c79588e006eb28e51ca8b715e22abce0c81f5d4 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 22 Feb 2010 16:36:30 -0800 Subject: [PATCH] xenserver: Delete ports by interface name. ovs-vsctl command "--if-exists del-port eth0" does nothing if eth0 is on a bridge as part of a bond, because the bond's port name is not eth0 but something else. But interface-reconfigure needs to do that, so this commit adds that ability to ovs-vsctl and modifies interface-reconfigure to use it. Signed-off-by: Ben Pfaff --- utilities/ovs-vsctl.8.in | 11 ++++ utilities/ovs-vsctl.c | 55 +++++++++++++------ ...rce_libexec_InterfaceReconfigureVswitch.py | 6 +- 3 files changed, 51 insertions(+), 21 deletions(-) diff --git a/utilities/ovs-vsctl.8.in b/utilities/ovs-vsctl.8.in index 2f60fbda6..7db3ddcdc 100644 --- a/utilities/ovs-vsctl.8.in +++ b/utilities/ovs-vsctl.8.in @@ -256,6 +256,17 @@ Without \fB\-\-if\-exists\fR, attempting to delete a port that does not exist is an error. With \fB\-\-if\-exists\fR, attempting to delete a port that does not exist has no effect. . +.IP "[\fB\-\-if\-exists\fR] \fB\-\-with\-iface del\-port \fR[\fIbridge\fR] \fIiface\fR" +Deletes the port named \fIiface\fR or that has an interface named +\fIiface\fR. If \fIbridge\fR is omitted, the port is removed from +whatever bridge contains it; if \fIbridge\fR is specified, it must be +the real or fake bridge that contains the port. +.IP +Without \fB\-\-if\-exists\fR, attempting to delete the port for an +interface that does not exist is an error. With \fB\-\-if\-exists\fR, +attempting to delete the port for an interface that does not exist has +no effect. +. .IP "\fBport\-to\-br \fIport\fR" Prints the name of the bridge that contains \fIport\fR on standard output. diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index 84db728bc..1c00f436e 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -1277,31 +1277,50 @@ static void cmd_del_port(struct vsctl_context *ctx) { bool must_exist = !shash_find(&ctx->options, "--if-exists"); + bool with_iface = shash_find(&ctx->options, "--with-iface") != NULL; + struct vsctl_port *port; struct vsctl_info info; get_info(ctx->ovs, &info); - if (ctx->argc == 2) { - struct vsctl_port *port = find_port(&info, ctx->argv[1], must_exist); - if (port) { - del_port(&info, port); + if (!with_iface) { + port = find_port(&info, ctx->argv[ctx->argc - 1], must_exist); + } else { + const char *target = ctx->argv[ctx->argc - 1]; + struct vsctl_iface *iface; + + port = find_port(&info, target, false); + if (!port) { + iface = find_iface(&info, target, false); + if (iface) { + port = iface->port; + } + } + if (must_exist && !port) { + vsctl_fatal("no port or interface named %s", target); } - } else if (ctx->argc == 3) { - struct vsctl_bridge *bridge = find_bridge(&info, ctx->argv[1], true); - struct vsctl_port *port = find_port(&info, ctx->argv[2], must_exist); + } - if (port) { - if (port->bridge == bridge) { - del_port(&info, port); - } else if (port->bridge->parent == bridge) { - vsctl_fatal("bridge %s does not have a port %s (although its " - "parent bridge %s does)", - ctx->argv[1], ctx->argv[2], bridge->parent->name); - } else { - vsctl_fatal("bridge %s does not have a port %s", - ctx->argv[1], ctx->argv[2]); + if (port) { + if (ctx->argc == 3) { + struct vsctl_bridge *bridge; + + bridge = find_bridge(&info, ctx->argv[1], true); + if (port->bridge != bridge) { + if (port->bridge->parent == bridge) { + vsctl_fatal("bridge %s does not have a port %s (although " + "its parent bridge %s does)", + ctx->argv[1], ctx->argv[2], + bridge->parent->name); + } else { + vsctl_fatal("bridge %s does not have a port %s", + ctx->argv[1], ctx->argv[2]); + } } } + + del_port(&info, port); } + free_info(&info); } @@ -2484,7 +2503,7 @@ static const struct vsctl_command_syntax all_commands[] = { {"list-ports", 1, 1, cmd_list_ports, NULL, ""}, {"add-port", 2, 2, cmd_add_port, NULL, "--may-exist"}, {"add-bond", 4, INT_MAX, cmd_add_bond, NULL, "--may-exist,--fake-iface"}, - {"del-port", 1, 2, cmd_del_port, NULL, "--if-exists"}, + {"del-port", 1, 2, cmd_del_port, NULL, "--if-exists,--with-iface"}, {"port-to-br", 1, 1, cmd_port_to_br, NULL, ""}, /* Interface commands. */ diff --git a/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py b/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py index ef3ed090e..e938d1a0c 100644 --- a/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py +++ b/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py @@ -119,7 +119,7 @@ A VLAN PIF cannot be a datapath PIF. return [pif] def datapath_deconfigure_physical(netdev): - return ['--', '--if-exists', 'del-port', netdev] + return ['--', '--with-iface', '--if-exists', 'del-port', netdev] def datapath_configure_bond(pif,slaves): bridge = pif_bridge_name(pif) @@ -156,10 +156,10 @@ def datapath_configure_bond(pif,slaves): return argv def datapath_deconfigure_bond(netdev): - return ['--', '--if-exists', 'del-port', netdev] + return ['--', '--with-iface', '--if-exists', 'del-port', netdev] def datapath_deconfigure_ipdev(interface): - return ['--', '--if-exists', 'del-port', interface] + return ['--', '--with-iface', '--if-exists', 'del-port', interface] def datapath_modify_config(commands): #log("modifying configuration:") -- 2.43.0