f30d899
commit e51995667279164a6c8ce4c3ba0217fffda22d6d
f30d899
Author: Mingming Cao <mmc@linux.vnet.ibm.com>
f30d899
Date:   Thu Nov 19 21:41:31 2020 -0800
f30d899
f30d899
    Clean up dead network config interface after inactive migration
f30d899
    
f30d899
    With inactive parition migration, we found there are
f30d899
    dead network interface asscoiated with the SR_IOV from
f30d899
    source LPAR that still exist.
f30d899
    
f30d899
    We need to cleanup the old network interface
f30d899
    related to this devname from source LPAR. Normally
f30d899
    in the active parition migration case, this was done
f30d899
    when HMC issue commands to OS remove the
f30d899
    VF from hybrid network. Because of the inactive
f30d899
    migration, the OS was not notified before migration
f30d899
    that the VF was removed, thus leaves the dead network
f30d899
    interface belongs on the original MVF on source lpar
f30d899
    not cleaned up. This cause the confusion of the network
f30d899
    manager to bring up the bondings with new MVFs at destination
f30d899
    LPAR.
f30d899
    
f30d899
    After inactive parition migration the same devname
f30d899
    could possiblily used at the destination LPAR.
f30d899
    It can be assigned to a different hybrid
f30d899
    network (different hcnid). At the OS boot time,
f30d899
    the same devname but with different hcnid will
f30d899
    be configured. However the old network work interface
f30d899
    associated with the same devname from the source LPAR
f30d899
    has not been cleaned up yet.
f30d899
    
f30d899
    This patch fix this by during the boot time scan and
f30d899
    if found an VFs has more than two bonding interfaces,
f30d899
    or has old VF ifcfg, removed the expired one.
f30d899
    
f30d899
    Signed-off-by: Mingming Cao <mmc@linux.vnet.ibm.com>
f30d899
    Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
f30d899
f30d899
diff --git a/scripts/hcnmgr b/scripts/hcnmgr
f30d899
index 0c09d8c..a76505e 100644
f30d899
--- a/scripts/hcnmgr
f30d899
+++ b/scripts/hcnmgr
f30d899
@@ -518,6 +518,27 @@ scanhcn() {
f30d899
 			[ -d "$dev" ] || continue
f30d899
 			if [ -e "$dev"/ibm,hcn-id ] && get_dev_hcn "$dev"; then
f30d899
 				hcnlog DEBUG "scanhcn found sr-iov device with hcnid "
f30d899
+
f30d899
+				# After online from inactive migration, destination
f30d899
+				# LPAR may have same mvf devname but associated with different
f30d899
+				# bonding than from source LPAR
f30d899
+				# clean up expired bonding SR_IOV connections
f30d899
+
f30d899
+				for cfg in $(ls $IFCONFIG_PATH | grep "$DEVNAME" | grep "bond"); do
f30d899
+					hid=$(echo "$cfg" | sed -e 's/ifcfg-//' | cut -d '-' -f 1 | sed -e 's/bond//')
f30d899
+					if [ -e "$IFCONFIG_PATH/ifcfg-$DEVNAME" ]; then
f30d899
+						rm "$IFCONFIG_PATH/ifcfg-$DEVNAME"
f30d899
+					fi
f30d899
+					if [[ $hid != "" && $hid != "$HCNID" ]] ; then
f30d899
+						hcnlog INFO "Delete dead bonding slave ifcfg file $IFCONFIG_PATH/$cfg"
f30d899
+						rm $IFCONFIG_PATH/"$cfg"
f30d899
+						if nmcli -f NAME con show | grep -q "bond$hid-$DEVNAME\s"; then
f30d899
+							hcnlog INFO "Delete dead bonding connection $connection"
f30d899
+							nmcli con delete "bond$hid-$DEVNAME"
f30d899
+						fi
f30d899
+					fi
f30d899
+				done
f30d899
+
f30d899
 				hcnlog INFO "scanhcn configure HCN and sr-iov device"
f30d899
 				do_config_vdevice
f30d899
 				# Save found HCN ids in array HcnIds
f30d899
@@ -558,13 +579,12 @@ scanhcn() {
f30d899
 
f30d899
 	# list of all HCN ids
f30d899
 	ids="${HcnIds[*]}"
f30d899
-
f30d899
 	# After inactive migration, LPAR may have old bonding connections
f30d899
 	# with network device on original LPAR
f30d899
-	# clean up dead bonding connections
f30d899
+    # clean up dead bonding connections
f30d899
 	for connection in $(nmcli -f NAME con show | grep "${ids// /\\|}"); do
f30d899
 		dev=$(echo "$connection" | cut -d '-' -f 2)
f30d899
-		if [ ! -e /sys/class/net/"$dev" ]; then
f30d899
+		if [[ $dev != "NAME" && ! -e /sys/class/net/"$dev" ]]; then
f30d899
 			hcnlog INFO "Delete dead bonding connection $connection"
f30d899
 			nmcli con delete "$connection"
f30d899
 		fi