]> www.infradead.org Git - users/hch/blktests.git/commitdiff
common/cpuhotplug: allow _offline_cpu() call in sub-shell
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Tue, 19 Jul 2022 02:52:16 +0000 (11:52 +0900)
committerShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Sun, 24 Jul 2022 23:52:35 +0000 (08:52 +0900)
The helper function _offline_cpu() sets a value to RESTORE_CPUS_ONLINE.
However, the commit bd6b882b2650 ("block/008: check CPU offline failure
due to many IRQs") put _offline_cpu() call in sub-shell, then the set
value to RESTORE_CPUS_ONLINE no longer affects function caller's
environment. This resulted in off-lined CPUs not restored by _cleanup()
when the test case block/008 calls only _offline_cpu() and does not call
_online_cpu().

To fix the issue, set RESTORE_CPUS_ONLINE in _have_cpu_hotplug() in
place of _offline_cpu(). _have_cpu_hotplug() is less likely to be called
in sub-shell. In same manner, do not set RESTORE_CPUS_ONLINE in
_online_cpu() either. Check that RESTORE_CPUS_ONLINE is set in
_offline_cpu() to avoid unexpected CPUs left off-lined. This check also
avoids a shellcheck warning.

Fixes: bd6b882b2650 ("block/008: check CPU offline failure due to many IRQs")
Reported-by: Yi Zhang <yi.zhang@redhat.com>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
common/cpuhotplug

index 7facd0de955e5e08e274d85c344298cbf1808e7e..e91c3bca8efb081631623c1cef9b7b0b5ed089b9 100644 (file)
@@ -27,17 +27,20 @@ _have_cpu_hotplug() {
                SKIP_REASONS+=("CPU hotplugging is not supported")
                return 1
        fi
+
+       RESTORE_CPUS_ONLINE=1
        return 0
 }
 
 _online_cpu() {
-       # shellcheck disable=SC2034
-       RESTORE_CPUS_ONLINE=1
        echo 1 > "/sys/devices/system/cpu/cpu$1/online"
 }
 
 _offline_cpu() {
-       # shellcheck disable=SC2034
-       RESTORE_CPUS_ONLINE=1
+       if [[ -z ${RESTORE_CPUS_ONLINE} ]]; then
+               echo "offlining cpu but RESTORE_CPUS_ONLINE is not set"
+               return 1
+       fi
+
        echo 0 > "/sys/devices/system/cpu/cpu$1/online"
 }