]> xenbits.xensource.com Git - people/sstabellini/xen-unstable.git/.git/commitdiff
tools/hotplug/Linux: add remove_from_bridge()
authorPaul Durrant <pdurrant@amazon.com>
Tue, 11 Aug 2020 08:01:57 +0000 (09:01 +0100)
committerWei Liu <wl@xen.org>
Thu, 27 Aug 2020 10:04:10 +0000 (10:04 +0000)
This patch adds a remove_from_bridge() function into xen-network-common.sh
to partner with the existing add_to_bridge() function. The vif-bridge
script is then modified to use it.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
Acked-by: Wei Liu <wl@xen.org>
tools/hotplug/Linux/vif-bridge
tools/hotplug/Linux/xen-network-common.sh

index e722090ca8d41d785d1c6a9f4a34b124f6093b56..c3e409926d4caf4f6cc61babd018db8024e67e30 100644 (file)
@@ -84,12 +84,7 @@ case "$command" in
         ;;
 
     offline)
-        if which brctl >&/dev/null; then
-            do_without_error brctl delif "$bridge" "$dev"
-        else
-            do_without_error ip link set "$dev" nomaster
-        fi
-        do_without_error ifconfig "$dev" down
+        remove_from_bridge "$bridge" "$dev"
         ;;
 
     add)
index ec3bd4ec4ac965532d3132a3c0a87bd2f76d1ab4..6a0904361f32a119ff3ad2588fea1de5ab851e90 100644 (file)
@@ -141,6 +141,25 @@ add_to_bridge () {
     ip link set dev ${dev} up
 }
 
+remove_from_bridge () {
+    local bridge=$1
+    local dev=$2
+
+    do_without_error ip link set dev ${dev} down
+
+    # Don't remove $dev from $bridge if it's not on the bridge.
+    if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
+        log debug "removing $dev from bridge $bridge"
+        if which brctl >&/dev/null; then
+            do_without_error brctl delif ${bridge} ${dev}
+        else
+            do_without_error ip link set ${dev} nomaster
+        fi
+    else
+        log debug "$dev not on bridge $bridge"
+    fi
+}
+
 # Usage: set_mtu bridge dev
 set_mtu () {
     local bridge=$1