generic: add test for DAX MAP_SYNC support
authorRoss Zwisler <ross.zwisler@linux.intel.com>
Thu, 7 Dec 2017 23:19:50 +0000 (16:19 -0700)
committerEryu Guan <eguan@redhat.com>
Sun, 10 Dec 2017 09:46:05 +0000 (17:46 +0800)
This test creates a file and writes to it via an mmap(), but never
syncs via fsync/msync. This process is tracked via dm-log-writes,
then replayed.

If MAP_SYNC is working the dm-log-writes replay will show the test
file with 1 MiB of on-media block allocations.  This is because each
allocating page fault included an implicit metadata sync.  If
MAP_SYNC isn't working (which you can test by removing the "-S" flag
to xfs_io mmap) the file will be smaller or missing entirely.

Note that dm-log-writes doesn't track the data that we write via the
mmap(), so we can't do any data integrity checking.  We can only
verify that the metadata writes for the page faults happened.

[eguan: add comments on _require_log_writes_dax and fix its cleanup]

Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
common/dmlogwrites
tests/generic/470 [new file with mode: 0755]
tests/generic/470.out [new file with mode: 0644]
tests/generic/group

index 05829dbc0a03093e49b0a2eb7703ded63b2d1d17..467b872e246f0bc994020cb5ccda57c0084baea8 100644 (file)
@@ -28,6 +28,37 @@ _require_log_writes()
        _require_test_program "log-writes/replay-log"
 }
 
+# Starting from v4.15-rc1, DAX support was added to dm-log-writes, but note
+# that it doesn't track the data that we write via the mmap(), so we can't do
+# any data integrity checking. We can only verify that the metadata writes for
+# the page faults happened, e.g. when mmap(2) with MAP_SYNC flag.
+#
+# Introduce a new helper to check if dm-log-writes target supports DAX
+# explicitly. But this is considered as a temporary workaround, we want to move
+# all the DAX check back to _require_log_writes when dm-log-writes gains full
+# DAX support and remove this helper.
+_require_log_writes_dax()
+{
+       [ -z "$LOGWRITES_DEV" -o ! -b "$LOGWRITES_DEV" ] && \
+               _notrun "This test requires a valid \$LOGWRITES_DEV"
+
+       _require_dm_target log-writes
+       _require_test_program "log-writes/replay-log"
+
+       local ret=0
+       _log_writes_init
+       _log_writes_mkfs > /dev/null 2>&1
+       _log_writes_mount -o dax > /dev/null 2>&1
+       # Check options to be sure. XFS ignores dax option
+       # and goes on if dev underneath does not support dax.
+       _fs_options $LOGWRITES_DMDEV | grep -qw "dax"
+       ret=$?
+       _log_writes_cleanup
+       if [ $ret -ne 0 ]; then
+               _notrun "$LOGWRITES_DMDEV $FSTYP does not support -o dax"
+       fi
+}
+
 _log_writes_init()
 {
        local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
@@ -90,5 +121,8 @@ _log_writes_remove()
 _log_writes_cleanup()
 {
        $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
+       # wait for device to be fully settled so that 'dmsetup remove' doesn't
+       # fail due to EBUSY
+       $UDEV_SETTLE_PROG >/dev/null 2>&1
        _log_writes_remove
 }
diff --git a/tests/generic/470 b/tests/generic/470
new file mode 100755 (executable)
index 0000000..bda0557
--- /dev/null
@@ -0,0 +1,83 @@
+#! /bin/bash
+# FS QA Test No. 470
+#
+# Use dm-log-writes to verify that MAP_SYNC actually syncs metadata during
+# page faults.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2017 Intel Corporation.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+tmp=/tmp/$$
+here=`pwd`
+status=1       # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       _log_writes_cleanup
+       rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/dmlogwrites
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_scratch
+_require_log_writes_dax
+_require_xfs_io_command "mmap" "-S"
+_require_xfs_io_command "log_writes"
+
+_log_writes_init
+_log_writes_mkfs >> $seqres.full 2>&1
+_log_writes_mount -o dax
+
+LEN=$((1024 * 1024)) # 1 MiB
+
+$XFS_IO_PROG -t -c "truncate $LEN" -c "mmap -S 0 $LEN" -c "mwrite 0 $LEN" \
+       -c "log_writes -d $LOGWRITES_NAME -m preunmap" \
+       -f $SCRATCH_MNT/test
+
+# Unmount the scratch dir and tear down the log writes target
+_log_writes_unmount
+_log_writes_remove
+_check_scratch_fs
+
+# destroy previous filesystem so we can be sure our rebuild works
+_scratch_mkfs >> $seqres.full 2>&1
+
+# check pre-unmap state
+_log_writes_replay_log preunmap
+_scratch_mount
+
+# We should see $SCRATCH_MNT/test as having 1 MiB in block allocations
+du -sh $SCRATCH_MNT/test | _filter_scratch | _filter_spaces
+
+status=0
+exit
diff --git a/tests/generic/470.out b/tests/generic/470.out
new file mode 100644 (file)
index 0000000..9f83128
--- /dev/null
@@ -0,0 +1,2 @@
+QA output created by 470
+1.0M SCRATCH_MNT/test
index 6c3bb03a9973de11072abfb49131ed4faceb14f5..1e6072225a8fb942e4b425b1148adbb9c5506a9e 100644 (file)
 467 auto quick exportfs
 468 shutdown auto quick metadata
 469 auto quick
+470 auto quick dax