common/rc: swapon should not fail for given FS in _require_scratch_swapfile()
authorRitesh Harjani <riteshh@linux.ibm.com>
Tue, 5 Jan 2021 14:31:42 +0000 (20:01 +0530)
committerEryu Guan <guaneryu@gmail.com>
Sun, 10 Jan 2021 09:07:21 +0000 (17:07 +0800)
Filesystems e.g. ext* and XFS supports swapon by default and an error
returned with swapon should be treated as a failure.

Signed-off-by: Ritesh Harjani <riteshh@linux.ibm.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
common/rc

index 33b5b598a1983cd06e8debd31469f87a517bcaef..649b1cfd884a267628366b38a55e33f7f08368f5 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -2401,10 +2401,22 @@ _require_scratch_swapfile()
        # Minimum size for mkswap is 10 pages
        _format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))
 
-       if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
-               _scratch_unmount
-               _notrun "swapfiles are not supported"
-       fi
+       # ext* and xfs have supported all variants of swap files since their
+       # introduction, so swapon should not fail.
+       case "$FSTYP" in
+       ext2|ext3|ext4|xfs)
+               if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
+                       _scratch_unmount
+                       _fail "swapon failed for $FSTYP"
+               fi
+               ;;
+       *)
+               if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
+                       _scratch_unmount
+                       _notrun "swapfiles are not supported"
+               fi
+               ;;
+       esac
 
        swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
        _scratch_unmount