From 4fb18a1e7b47e30fbacaff177b6c355dd0c8f87e Mon Sep 17 00:00:00 2001 From: Wenjia Zhang Date: Mon, 12 Apr 2021 21:59:31 +0200 Subject: [PATCH] znetconf: avoid conflict with "chzdev -e" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using "chzdev -e" to configurate a device persistently, the corresponding udev rule is also created, which will trigger a uevent that sets the device online as soon as the group device is created. If 'znetconf -r/R' is first used to remove such a configured device (which won't remove the corresponding udev rule) and then 'znetconf -a/A' afterwards on the same device, either the error "Failed to make online" or "Failed to configure layer2=1" will occur. For the first error, the udev queue might not have been fully processed and hence the check whether a device is online may fail due to that race. Call 'udevadm settle' to ensure a fully processed queue before checking whether a device is online. The second error occurs, because configure_ccwgroupdev_option() does not check whether the device is online. Add the check and set the device offline if necessary. Also, log any details for debugging purposes. Signed-off-by: Wenjia Zhang Reviewed-by: Alexandra Winter Reviewed-by: Jan Hoeppner Signed-off-by: Jan Höppner --- zconf/znetconf | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/zconf/znetconf b/zconf/znetconf index 497e97f6..5d657a94 100755 --- a/zconf/znetconf +++ b/zconf/znetconf @@ -630,6 +630,21 @@ function configure_ccwgroupdev_option() # check if attribute exists local ATTRFILE="$CCWGROUPBUS_DEVICEDIR/$CCWGROUPDEVID/$OPTION_NAME" + + if [ "`cat $CCWGROUPBUS_DEVICEDIR/$CCWGROUPDEVID/online`" == "1" ] + then + # Could be done by udev rule or else + logger "znetconf: Device $CCWGROUPDEVID is already online." + if [ "$OPTION_VALUE" != "`cat $ATTRFILE`" ] + then + logger "znetconf: Device $CCWGROUPDEVID is set offline to set $OPTION_NAME=$OPTION_VALUE" + echo "0" >> "$CCWGROUPBUS_DEVICEDIR/$CCWGROUPDEVID/online" 2> /dev/null + else + logger "znetconf: Device $CCWGROUPDEVID has $OPTION_NAME=`cat $ATTRFILE` already set, skipping...." + return 0 + fi + fi + if [ -f $ATTRFILE ] then echo $OPTION_VALUE >> $ATTRFILE 2> /dev/null @@ -646,6 +661,7 @@ function configure_ccwgroupdev_option() print_error "$ATTRFILE does not exist" return 2 fi + return 0 } @@ -681,6 +697,13 @@ function add_net_device() return $? fi + # To avoid conflict with unfinished uevents triggered potentially by creating groupe device + prepare_udevsettle_cmd + if [ "$UDEVSETTLE" != "" ] + then + $UDEVSETTLE_CALL + fi + local i=0 local SOMEOPTION_FAILED=0 local HAS_LAYER2_OPTION=0 @@ -707,8 +730,11 @@ function add_net_device() local LAYER2=$? if [ $LAYER2 -eq 0 ] || [ $LAYER2 -eq 1 ] then - configure_ccwgroupdev_option $CCWGROUPDEVID \ + if ! configure_ccwgroupdev_option $CCWGROUPDEVID \ "layer2" "$LAYER2" + then + SOMEOPTION_FAILED=1 + fi fi fi @@ -717,16 +743,16 @@ function add_net_device() return $RC_COULD_NOT_SET_DEV_ONLINE fi - if ! wait_for_net_device $CCWGROUPDEVNO - then - return $RC_NET_DEVICE_NOT_ONLINE - fi - if [ $SOMEOPTION_FAILED -ne 0 ] then return $RC_OPTION_NOT_CONFIGURED fi + if ! wait_for_net_device $CCWGROUPDEVNO + then + return $RC_NET_DEVICE_NOT_ONLINE + fi + return 0 }