]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
generic: add swapfile maxpages regression test
authorDarrick J. Wong <djwong@kernel.org>
Thu, 19 Aug 2021 01:43:26 +0000 (18:43 -0700)
committerEryu Guan <guaneryu@gmail.com>
Sun, 22 Aug 2021 10:31:47 +0000 (18:31 +0800)
Add regression test for "mm/swap: consider max pages in
iomap_swapfile_add_extent".

Cc: Gang Deng <gavin.dg@linux.alibaba.com>
Cc: Xu Yu <xuyu@linux.alibaba.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/generic/643 [new file with mode: 0755]
tests/generic/643.out [new file with mode: 0644]

diff --git a/tests/generic/643 b/tests/generic/643
new file mode 100755 (executable)
index 0000000..2bb9d22
--- /dev/null
@@ -0,0 +1,62 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2021 Oracle.  All Rights Reserved.
+#
+# FS QA Test No. 643
+#
+# Regression test for "mm/swap: consider max pages in iomap_swapfile_add_extent"
+
+# Xu Yu found that the iomap swapfile activation code failed to constrain
+# itself to activating however many swap pages that the mm asked us for.  This
+# is an deviation in behavior from the classic swapfile code.  It also leads to
+# kernel memory corruption if the swapfile is cleverly constructed.
+#
+. ./common/preamble
+_begin_fstest auto swap
+
+# Override the default cleanup function.
+_cleanup()
+{
+       cd /
+       rm -f $tmp.*
+       test -n "$swapfile" && swapoff $swapfile &> /dev/null
+}
+
+# real QA test starts here
+_supported_fs generic
+_require_scratch_swapfile
+
+_scratch_mkfs >> $seqres.full
+_scratch_mount >> $seqres.full
+
+# Assuming we're not borrowing a FAT16 partition from Windows 3.1, we need an
+# unlikely enough name that we can grep /proc/swaps for this.
+swapfile=$SCRATCH_MNT/386spart.par
+_format_swapfile $swapfile 1m >> $seqres.full
+
+swapfile_pages() {
+       local swapfile="$1"
+
+       grep "$swapfile" /proc/swaps | awk '{print $3}'
+}
+
+_swapon_file $swapfile
+before_pages=$(swapfile_pages "$swapfile")
+swapoff $swapfile
+
+# Extend the length of the swapfile but do not rewrite the header.
+# The subsequent swapon should set up 1MB worth of pages, not 2MB.
+$XFS_IO_PROG -f -c 'pwrite 1m 1m' $swapfile >> $seqres.full
+
+_swapon_file $swapfile
+after_pages=$(swapfile_pages "$swapfile")
+swapoff $swapfile
+
+# Both swapon attempts should have found the same number of pages.
+test "$before_pages" -eq "$after_pages" || \
+       echo "swapon added $after_pages pages, expected $before_pages"
+
+# success, all done
+echo Silence is golden
+status=0
+exit
diff --git a/tests/generic/643.out b/tests/generic/643.out
new file mode 100644 (file)
index 0000000..32f1c62
--- /dev/null
@@ -0,0 +1,2 @@
+QA output created by 643
+Silence is golden