Skip to content

Commit

Permalink
generic: enable swapfile tests on Btrfs
Browse files Browse the repository at this point in the history
Commit 8c96cfb ("generic/35[67]: disable swapfile tests on
Btrfs") disabled the swapfile tests on Btrfs because it did not
support swapfiles at the time. Now that we're adding support, we
want these tests to run, but they don't. _require_scratch_swapfile
always fails for Btrfs because swapfiles on Btrfs must be set to
nocow. After fixing that, generic/356 and generic/357 fail for the
same reason. After fixing _that_, both tests still fail because we
don't allow reflinking a non-checksummed extent (which nocow
implies) to a checksummed extent.

Add a helper for formatting a swap file which does the chattr, and
chattr the second file, which gets these tests running on kernels
supporting Btrfs swapfiles.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
  • Loading branch information
osandov authored and guaneryu committed May 23, 2018
1 parent 39aca57 commit bd6d67e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
17 changes: 14 additions & 3 deletions common/rc
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,19 @@ _require_odirect()
rm -f $testfile 2>&1 > /dev/null
}

_format_swapfile() {
local fname="$1"
local sz="$2"

rm -f "$fname"
touch "$fname"
chmod 0600 "$fname"
# Swap files must be nocow on Btrfs.
$CHATTR_PROG +C "$fname" > /dev/null 2>&1
_pwrite_byte 0x61 0 "$sz" "$fname" >> $seqres.full
mkswap "$fname" >> $seqres.full
}

# Check that the filesystem supports swapfiles
_require_scratch_swapfile()
{
Expand All @@ -2234,10 +2247,8 @@ _require_scratch_swapfile()
_scratch_mount

# Minimum size for mkswap is 10 pages
local size=$(($(get_page_size) * 10))
_format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))

_pwrite_byte 0x61 0 "$size" "$SCRATCH_MNT/swap" >/dev/null 2>&1
mkswap "$SCRATCH_MNT/swap" >/dev/null 2>&1
if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
_scratch_unmount
_notrun "swapfiles are not supported"
Expand Down
7 changes: 4 additions & 3 deletions tests/generic/356
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ blocks=160
blksz=65536

echo "Initialize file"
echo >> $seqres.full
_pwrite_byte 0x61 0 $((blocks * blksz)) $testdir/file1 >> $seqres.full
mkswap -U 27376b42-ff65-42ca-919f-6c9b62292a5c $testdir/file1 >> $seqres.full
_format_swapfile "$testdir/file1" $((blocks * blksz))
swapon $testdir/file1

touch "$testdir/file2"
$CHATTR_PROG +C "$testdir/file2" >/dev/null 2>&1

echo "Try to reflink"
_cp_reflink $testdir/file1 $testdir/file2 2>&1 | _filter_scratch

Expand Down
6 changes: 3 additions & 3 deletions tests/generic/357
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ blocks=160
blksz=65536

echo "Initialize file"
echo >> $seqres.full
_pwrite_byte 0x61 0 $((blocks * blksz)) $testdir/file1 >> $seqres.full
mkswap -U 27376b42-ff65-42ca-919f-6c9b62292a5c $testdir/file1 >> $seqres.full
_format_swapfile "$testdir/file1" $((blocks * blksz))
touch "$testdir/file2"
$CHATTR_PROG +C "$testdir/file2" >/dev/null 2>&1
_cp_reflink $testdir/file1 $testdir/file2 2>&1 | _filter_scratch

echo "Try to swapon"
Expand Down

0 comments on commit bd6d67e

Please sign in to comment.