2021-01-05 14:33:40

by Ritesh Harjani

[permalink] [raw]
Subject: [PATCHv3 1/2] common/rc: swapon should not fail for given FS in _require_scratch_swapfile()

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 <[email protected]>
---
v2 -> v3:
1. Removed whitelisted naming convention.
2. Added ext2/ext3 as well as supported FS for swapon.
3. Removed local variable $fstyp, instead used $FSTYP directly in switch case.

common/rc | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/common/rc b/common/rc
index 33b5b598a198..649b1cfd884a 100644
--- 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
--
2.26.2


2021-01-05 14:34:18

by Ritesh Harjani

[permalink] [raw]
Subject: [PATCHv3 2/2] generic/496: ext4 and xfs supports swapon on fallocated file

ext4, xfs should not fail swapon on fallocated file. Currently if this
fails the fstst was not returning a failure. Fix those for given
filesystems (for now added ext4/xfs).
There were some regressions which went unnoticed due to this in ext4
tree, which later got fixed as part of this patch [1]

[1]: https://patchwork.ozlabs.org/patch/1357275

Signed-off-by: Ritesh Harjani <[email protected]>
---
v2 -> v3:
1. Removed whitelisted naming convention.

tests/generic/496 | 16 +++++++++++++---
tests/generic/group | 2 +-
2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/tests/generic/496 b/tests/generic/496
index 805c6ac1c0ea..1bfd16411b8a 100755
--- a/tests/generic/496
+++ b/tests/generic/496
@@ -5,7 +5,7 @@
# FS QA Test No. 496
#
# Test various swapfile activation oddities on filesystems that support
-# fallocated swapfiles.
+# fallocated swapfiles (for given fs ext4/xfs)
#
seq=`basename $0`
seqres=$RESULT_DIR/$seq
@@ -61,8 +61,18 @@ touch $swapfile
$CHATTR_PROG +C $swapfile >> $seqres.full 2>&1
$XFS_IO_PROG -f -c "falloc 0 $len" $swapfile >> $seqres.full
"$here/src/mkswap" $swapfile
-"$here/src/swapon" $swapfile >> $seqres.full 2>&1 || \
- _notrun "fallocated swap not supported here"
+
+# ext4/xfs should not fail for swapon on fallocated files
+case $FSTYP in
+ext4|xfs)
+ "$here/src/swapon" $swapfile >> $seqres.full 2>&1 || \
+ _fail "swapon failed on fallocated file"
+ ;;
+*)
+ "$here/src/swapon" $swapfile >> $seqres.full 2>&1 || \
+ _notrun "fallocated swap not supported here"
+ ;;
+esac
swapoff $swapfile

# Create a fallocated swap file and touch every other $PAGE_SIZE to create
diff --git a/tests/generic/group b/tests/generic/group
index fec35d8e7b12..30a73605610d 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -498,7 +498,7 @@
493 auto quick swap dedupe
494 auto quick swap punch
495 auto quick swap
-496 auto quick swap
+496 auto quick swap prealloc
497 auto quick swap collapse
498 auto quick log
499 auto quick rw collapse zero
--
2.26.2

2021-01-05 19:06:29

by Darrick J. Wong

[permalink] [raw]
Subject: Re: [PATCHv3 1/2] common/rc: swapon should not fail for given FS in _require_scratch_swapfile()

On Tue, Jan 05, 2021 at 08:01:42PM +0530, Ritesh Harjani wrote:
> 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 <[email protected]>

Looks ok,
Reviewed-by: Darrick J. Wong <[email protected]>

--D

> ---
> v2 -> v3:
> 1. Removed whitelisted naming convention.
> 2. Added ext2/ext3 as well as supported FS for swapon.
> 3. Removed local variable $fstyp, instead used $FSTYP directly in switch case.
>
> common/rc | 20 ++++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/common/rc b/common/rc
> index 33b5b598a198..649b1cfd884a 100644
> --- 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
> --
> 2.26.2
>

2021-01-05 19:06:38

by Darrick J. Wong

[permalink] [raw]
Subject: Re: [PATCHv3 2/2] generic/496: ext4 and xfs supports swapon on fallocated file

On Tue, Jan 05, 2021 at 08:01:43PM +0530, Ritesh Harjani wrote:
> ext4, xfs should not fail swapon on fallocated file. Currently if this
> fails the fstst was not returning a failure. Fix those for given
> filesystems (for now added ext4/xfs).
> There were some regressions which went unnoticed due to this in ext4
> tree, which later got fixed as part of this patch [1]
>
> [1]: https://patchwork.ozlabs.org/patch/1357275
>
> Signed-off-by: Ritesh Harjani <[email protected]>

Looks ok,
Reviewed-by: Darrick J. Wong <[email protected]>

--D

> ---
> v2 -> v3:
> 1. Removed whitelisted naming convention.
>
> tests/generic/496 | 16 +++++++++++++---
> tests/generic/group | 2 +-
> 2 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/tests/generic/496 b/tests/generic/496
> index 805c6ac1c0ea..1bfd16411b8a 100755
> --- a/tests/generic/496
> +++ b/tests/generic/496
> @@ -5,7 +5,7 @@
> # FS QA Test No. 496
> #
> # Test various swapfile activation oddities on filesystems that support
> -# fallocated swapfiles.
> +# fallocated swapfiles (for given fs ext4/xfs)
> #
> seq=`basename $0`
> seqres=$RESULT_DIR/$seq
> @@ -61,8 +61,18 @@ touch $swapfile
> $CHATTR_PROG +C $swapfile >> $seqres.full 2>&1
> $XFS_IO_PROG -f -c "falloc 0 $len" $swapfile >> $seqres.full
> "$here/src/mkswap" $swapfile
> -"$here/src/swapon" $swapfile >> $seqres.full 2>&1 || \
> - _notrun "fallocated swap not supported here"
> +
> +# ext4/xfs should not fail for swapon on fallocated files
> +case $FSTYP in
> +ext4|xfs)
> + "$here/src/swapon" $swapfile >> $seqres.full 2>&1 || \
> + _fail "swapon failed on fallocated file"
> + ;;
> +*)
> + "$here/src/swapon" $swapfile >> $seqres.full 2>&1 || \
> + _notrun "fallocated swap not supported here"
> + ;;
> +esac
> swapoff $swapfile
>
> # Create a fallocated swap file and touch every other $PAGE_SIZE to create
> diff --git a/tests/generic/group b/tests/generic/group
> index fec35d8e7b12..30a73605610d 100644
> --- a/tests/generic/group
> +++ b/tests/generic/group
> @@ -498,7 +498,7 @@
> 493 auto quick swap dedupe
> 494 auto quick swap punch
> 495 auto quick swap
> -496 auto quick swap
> +496 auto quick swap prealloc
> 497 auto quick swap collapse
> 498 auto quick log
> 499 auto quick rw collapse zero
> --
> 2.26.2
>