[PATCH v6.1 04/33] common/rc: skip test if swapon doesn't work

Darrick J. Wong
2025-11-12T22:29:21Z

In _require_scratch_swapfile, skip the test if swapon fails for whatever
reason, just like all the other filesystems. There are certain ext4
configurations where swapon isn't supported, such as S_DAX files on
pmem, and (for now) blocksize > pagesize filesystems.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
v6.1: clobber all the ext-specific stuff
---
common/rc | 25 ++++---------------------
1 file changed, 4 insertions(+), 21 deletions(-)

diff --git a/common/rc b/common/rc
index b62e21f778d938..564235ea2e995c 100644
--- a/common/rc
+++ b/common/rc
@@ -3268,27 +3268,10 @@ _require_scratch_swapfile()
# Minimum size for mkswap is 10 pages
_format_swapfile "$SCRATCH_MNT/swap" $(($(_get_page_size) * 10)) > /dev/null

- # ext* has supported all variants of swap files since their
- # introduction, so swapon should not fail.
- case "$FSTYP" in
- ext2|ext3|ext4)
- if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
- if _check_s_dax "$SCRATCH_MNT/swap" 1 >/dev/null; then
- _scratch_unmount
- _notrun "swapfiles are not supported"
- else
- _scratch_unmount
- _fail "swapon failed for $FSTYP"
- fi
- fi
- ;;
- *)
- if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
- _scratch_unmount
- _notrun "swapfiles are not supported"
- fi
- ;;
- esac
+ if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
+ _scratch_unmount
+ _notrun "swapon failed for $FSTYP"
+ fi

swapoff "$SCRATCH_MNT/swap" >/dev/null 2>&1
_scratch_unmount