tools/hotplug/Linux: re-factor add_to_bridge() in xen-network-common.sh
authorPaul Durrant <pdurrant@amazon.com>
Tue, 11 Aug 2020 08:01:56 +0000 (09:01 +0100)
committerWei Liu <wl@xen.org>
Thu, 27 Aug 2020 10:04:04 +0000 (10:04 +0000)
Remove duplication of 'ip link set dev'. It is perfectly fine to call it
even if the device has already been added to the bridge.

NOTE: This patch also adds code to write a debug log entry if the device
      was already on the bridge.

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

index 8dd3a62068b949cb5eb76a5d490dfd449be0066a..ec3bd4ec4ac965532d3132a3c0a87bd2f76d1ab4 100644 (file)
@@ -126,16 +126,18 @@ add_to_bridge () {
     local bridge=$1
     local dev=$2
 
-    # Don't add $dev to $bridge if it's already on a bridge.
-    if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
-       ip link set dev ${dev} up || true
-       return
-    fi
-    if which brctl >&/dev/null; then
-        brctl addif ${bridge} ${dev}
+    # Don't add $dev to $bridge if it's already on the bridge.
+    if [ ! -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
+        log debug "adding $dev to bridge $bridge"
+        if which brctl >&/dev/null; then
+            brctl addif ${bridge} ${dev}
+        else
+            ip link set ${dev} master ${bridge}
+        fi
     else
-        ip link set ${dev} master ${bridge}
+        log debug "$dev already on bridge $bridge"
     fi
+
     ip link set dev ${dev} up
 }