diff mbox series

common/rc: teach _require_scratch_swapfile() that swap does not work with DAX

Message ID 20210418161925.240995-1-tytso@mit.edu (mailing list archive)
State New, archived
Headers show
Series common/rc: teach _require_scratch_swapfile() that swap does not work with DAX | expand

Commit Message

Theodore Ts'o April 18, 2021, 4:19 p.m. UTC
The statement, "ext* and xfs have supported all variants of swap files
since their introduction, so swapon should not fail," is not quite
completely true.  In particular, swapon does not work if the DAX is
active on a swapfile, and that would be true if the file system is
mounted with -o dax.

So if swapon fails, check to see if the swapfile has the
STATX_ATTR_DAX attribute set, and if so, issue a _notrun instead of a
_fail.

Fixes: 725feeff94cc ("common/rc: swapon should not fail for given FS in _require_scratch_swapfile()")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 common/rc | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Christoph Hellwig April 20, 2021, 6:25 a.m. UTC | #1
On Sun, Apr 18, 2021 at 12:19:25PM -0400, Theodore Ts'o wrote:
> The statement, "ext* and xfs have supported all variants of swap files
> since their introduction, so swapon should not fail," is not quite
> completely true.  In particular, swapon does not work if the DAX is
> active on a swapfile, and that would be true if the file system is
> mounted with -o dax.
> 
> So if swapon fails, check to see if the swapfile has the
> STATX_ATTR_DAX attribute set, and if so, issue a _notrun instead of a
> _fail.

Isn't the fact that swapon doesn't work on DAX files a back?  The
swap I/O path couldn't care less if the file is marked as DAX or not.
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index 0f91340f..d2fd5c5c 100644
--- a/common/rc
+++ b/common/rc
@@ -2495,8 +2495,17 @@  _require_scratch_swapfile()
 	case "$FSTYP" in
 	ext2|ext3|ext4|xfs)
 		if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
+			local attributes=$($XFS_IO_PROG -c 'statx -r' \
+					"$SCRATCH_MNT/swap" 2>/dev/null | \
+					awk '/stat.attributes / { print $3 }')
 			_scratch_unmount
-			_fail "swapon failed for $FSTYP"
+			if test -n "$attributes" -a \
+				$((attributes & 0x00200000)) -eq $((0x00200000)) ;
+			then
+			    _notrun "DAX swapfiles are not supported"
+			else
+			    _fail "swapon failed for $FSTYP"
+			fi
 		fi
 		;;
 	*)