linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xfs/XXX: Add xfs/XXX
@ 2020-04-13  5:44 ira.weiny
  2020-04-13  7:54 ` Amir Goldstein
  2020-04-13 16:30 ` Darrick J. Wong
  0 siblings, 2 replies; 12+ messages in thread
From: ira.weiny @ 2020-04-13  5:44 UTC (permalink / raw)
  To: fstests
  Cc: Ira Weiny, linux-kernel, Darrick J. Wong, Dan Williams,
	Dave Chinner, Christoph Hellwig, Theodore Y. Ts'o, Jan Kara,
	Jeff Moyer, linux-ext4, linux-xfs, linux-fsdevel

From: Ira Weiny <ira.weiny@intel.com>

Add XXX to test per file DAX operations.

The following is tested[*]

 1. There exists an in-kernel access mode flag S_DAX that is set when
    file accesses go directly to persistent memory, bypassing the page
    cache.  Applications must call statx to discover the current S_DAX
    state (STATX_ATTR_DAX).

 2. There exists an advisory file inode flag FS_XFLAG_DAX that is
    inherited from the parent directory FS_XFLAG_DAX inode flag at file
    creation time.  This advisory flag can be set or cleared at any
    time, but doing so does not immediately affect the S_DAX state.

    Unless overridden by mount options (see (3)), if FS_XFLAG_DAX is set
    and the fs is on pmem then it will enable S_DAX at inode load time;
    if FS_XFLAG_DAX is not set, it will not enable S_DAX.

 3. There exists a dax= mount option.

    "-o dax=never"  means "never set S_DAX, ignore FS_XFLAG_DAX."

    "-o dax=always" means "always set S_DAX (at least on pmem),
                    and ignore FS_XFLAG_DAX."

    "-o dax"        is an alias for "dax=always".

    "-o dax=inode"  means "follow FS_XFLAG_DAX" and is the default.

 4. There exists an advisory directory inode flag FS_XFLAG_DAX that can
    be set or cleared at any time.  The flag state is copied into any
    files or subdirectories when they are created within that directory.

 5. Programs that require a specific file access mode (DAX or not DAX)
    can do one of the following:

    (a) Create files in directories that the FS_XFLAG_DAX flag set as
        needed; or

    (b) Have the administrator set an override via mount option; or

    (c) Set or clear the file's FS_XFLAG_DAX flag as needed.  Programs
        must then cause the kernel to evict the inode from memory.  This
        can be done by:

        i>  Closing the file and re-opening the file and using statx to
            see if the fs has changed the S_DAX flag; and

        ii> If the file still does not have the desired S_DAX access
            mode, either unmount and remount the filesystem, or close
            the file and use drop_caches.

 6. It's not unreasonable that users who want to squeeze every last bit
    of performance out of the particular rough and tumble bits of their
    storage also be exposed to the difficulties of what happens when the
    operating system can't totally virtualize those hardware
    capabilities.  Your high performance sports car is not a Toyota
    minivan, as it were.

[*] https://lore.kernel.org/lkml/20200409165927.GD6741@magnolia/

Signed-off-by: Ira Weiny <ira.weiny@intel.com>

---
Changes from v6 (kernel patch set):
	Start versions tracking the kernel patch set.
	Update for new requirements

Changes from V1 (xfstests patch):
	Add test to ensure moved files preserve their flag
	Check chattr of non-dax flags (check bug found by Darrick)
---
 tests/xfs/999     | 272 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/999.out |  22 ++++
 tests/xfs/group   |   1 +
 3 files changed, 295 insertions(+)
 create mode 100755 tests/xfs/999
 create mode 100644 tests/xfs/999.out

diff --git a/tests/xfs/999 b/tests/xfs/999
new file mode 100755
index 000000000000..3ca04b98c517
--- /dev/null
+++ b/tests/xfs/999
@@ -0,0 +1,272 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019 Intel, Corp.  All Rights Reserved.
+#
+# FSQA Test No. 999 (temporary)
+#
+# Test setting of DAX flag
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+status=1	# failure is the default!
+
+dax_dir=$TEST_DIR/dax-dir
+dax_sub_dir=$TEST_DIR/dax-dir/dax-sub-dir
+dax_inh_file=$dax_dir/dax-inh-file
+dax_non_inh_file=$dax_dir/dax-non-inh-file
+non_dax=$TEST_DIR/non-dax
+dax_file=$TEST_DIR/dax-dir/dax-file
+dax_file_copy=$TEST_DIR/dax-file-copy
+dax_file_move=$TEST_DIR/dax-file-move
+data_file=$TEST_DIR/non-dax-dir/data-file
+
+_cleanup() {
+	rm -rf $TEST_DIR/*
+}
+
+trap "_cleanup ; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common/rc
+
+# real QA test starts here
+_supported_os Linux
+_require_xfs_io_command "lsattr"
+_require_xfs_io_command "statx"
+_require_test
+
+#
+# mnt_opt's we expect
+# ''
+# '-o dax=off'
+# '-o dax=inode'
+# '-o dax'
+# '-o dax=always'
+function remount_w_option {
+	mnt_opt=$1
+	export MOUNT_OPTIONS=""
+	export TEST_FS_MOUNT_OPTS=""
+	_test_unmount &> /dev/null
+	_test_mount $mnt_opt &> /dev/null
+}
+
+function check_dax_mount_option {
+	mnt_opt=$1
+	_fs_options $TEST_DEV | grep -qw '$mnt_opt'
+	if [ "$?" == "0" ]; then
+		echo "FAILED: to mount FS with option '$mnt_opt'"
+	fi
+}
+
+function check_xflag_dax {
+	xfs_io -c 'lsattr' $1 | awk -e '{ print $1 }' | grep 'x' &> /dev/null
+	if [ "$?" != "0" ]; then
+		echo "FAILED: Did NOT find FS_XFLAG_DAX on $1"
+	fi
+}
+
+function check_s_dax {
+	attr=`xfs_io -c 'statx -r' $1 | grep 'stat.attributes' | awk -e '{ print $3 }'`
+	masked=$(( $attr & 0x2000 ))
+	if [ "$masked" != "8192" ]; then
+		echo "FAILED: Did NOT find S_DAX flag on $1"
+	fi
+}
+
+function check_no_xflag_dax {
+	xfs_io -c 'lsattr' $1 | awk -e '{ print $1 }' | grep 'x' &> /dev/null
+	if [ "$?" == "0" ]; then
+		echo "FAILED: Found FS_XFLAG_DAX on $1"
+	fi
+}
+
+function check_no_s_dax {
+	attr=`xfs_io -c 'statx -r' $1 | grep 'stat.attributes' | awk -e '{ print $3 }'`
+	masked=$(( $attr & 0x2000 ))
+	if [ "$masked" == "8192" ]; then
+		echo "FAILED: Found S_DAX flag on $1"
+	fi
+}
+
+echo "running tests..."
+
+remount_w_option ""
+check_dax_mount_option "dax=inode"
+
+echo "   *** mark dax-dir as dax enabled"
+mkdir $dax_dir
+xfs_io -c 'chattr +x' $dax_dir
+check_xflag_dax $dax_dir
+
+echo "   *** check file inheritance"
+touch $dax_inh_file
+check_xflag_dax $dax_inh_file
+check_s_dax $dax_inh_file
+
+echo "   *** check directory inheritance"
+mkdir $dax_sub_dir
+check_xflag_dax $dax_sub_dir
+
+echo "   *** check changing directory"
+xfs_io -c 'chattr -x' $dax_dir
+check_no_xflag_dax $dax_dir
+check_no_s_dax $dax_dir
+
+echo "   *** check non file inheritance"
+touch $dax_non_inh_file
+check_no_xflag_dax $dax_non_inh_file
+check_no_s_dax $dax_non_inh_file
+
+echo "   *** check that previous file stays enabled"
+check_xflag_dax $dax_inh_file
+check_s_dax $dax_inh_file
+
+echo "   *** Reset the directory"
+xfs_io -c 'chattr +x' $dax_dir
+check_xflag_dax $dax_dir
+
+# Set up for next test
+touch $dax_file
+touch $non_dax
+
+#
+#                      inode flag
+# ./
+#   + dax-dir/             X
+#     + dax-sub-dir/       X
+#     + dax-inh-file       X
+#     + dax-non-inh-file
+#     + dax-file           X
+#   + non-dax
+#
+
+# check mount overrides
+# =====================
+
+echo "   *** Check '-o dax'"
+remount_w_option "-o dax"
+check_dax_mount_option "dax=always"
+
+echo "   *** non-dax inode but overrides to be effective"
+check_no_xflag_dax $non_dax
+check_s_dax $non_dax
+
+echo "   *** Check for non-dax inode to be dax with mount option"
+check_no_xflag_dax $dax_non_inh_file
+check_s_dax $dax_non_inh_file
+
+
+echo "   *** Check '-o dax=never'"
+remount_w_option "-o dax=never"
+check_dax_mount_option "dax=never"
+
+check_xflag_dax $dax_dir
+check_xflag_dax $dax_sub_dir
+check_xflag_dax $dax_inh_file
+check_no_s_dax $dax_inh_file
+check_no_xflag_dax $dax_non_inh_file
+check_no_s_dax $dax_non_inh_file
+check_no_xflag_dax $non_dax
+check_no_s_dax $non_dax
+check_xflag_dax $dax_file
+check_no_s_dax $dax_file
+
+
+echo "   *** Check '-o dax=inode'"
+remount_w_option "-o dax=inode"
+check_dax_mount_option "dax=inode"
+
+check_xflag_dax $dax_dir
+check_xflag_dax $dax_sub_dir
+check_xflag_dax $dax_inh_file
+check_s_dax $dax_inh_file
+check_no_xflag_dax $dax_non_inh_file
+check_no_s_dax $dax_non_inh_file
+check_no_xflag_dax $non_dax
+check_no_s_dax $non_dax
+check_xflag_dax $dax_file
+check_s_dax $dax_file
+
+
+# Check non-zero file operations
+# ==============================
+
+echo "   *** Verify changing FS_XFLAG_DAX flag"
+
+mkdir $TEST_DIR/non-dax-dir
+$here/ltp/fsx $options -N 20000 $data_file > $tmp.log 2>&1 &
+pid=$!
+check_no_xflag_dax $data_file
+check_no_s_dax $data_file
+
+if [ ! -n "$pid" ]; then
+	echo "FAILED to start fsx"
+else
+	# toggle inode flag back and forth.
+	# s_dax should not change while fsx is using file.
+	xfs_io -c 'chattr +x' $data_file &> /dev/null
+	check_xflag_dax $data_file
+	check_no_s_dax $data_file
+	xfs_io -c 'chattr -x' $data_file &> /dev/null
+	check_no_xflag_dax $data_file
+	check_no_s_dax $data_file
+	xfs_io -c 'chattr +x' $data_file &> /dev/null
+	check_xflag_dax $data_file
+	check_no_s_dax $data_file
+fi
+
+wait $pid
+status=$?
+if [ "$status" != "0" ]; then
+	echo "FAILED: fsx exited with status : $status"
+	head $dax_file.fsxlog
+fi
+pid=""
+
+echo 2 > /proc/sys/vm/drop_caches
+
+echo "   *** Verify S_DAX change on drop_caches"
+# s_dax should change after drop_caches
+check_xflag_dax $data_file
+check_s_dax $data_file
+
+
+# Check inheritance on cp, mv
+# ===========================
+
+echo "   *** check making 'data' dax with cp"
+cp $non_dax $dax_dir/conv-dax
+check_xflag_dax $dax_dir/conv-dax
+check_s_dax $dax_dir/conv-dax
+
+echo "   *** check making 'data' non-dax with cp"
+rm -f $data_file
+cp $dax_dir/conv-dax $data_file
+check_no_xflag_dax $data_file
+check_no_s_dax $data_file
+
+echo "   *** Moved files 'don't inherit'"
+mv $non_dax $dax_dir/move-dax
+check_no_xflag_dax $dax_dir/move-dax
+check_no_s_dax $dax_dir/move-dax
+
+echo "   *** Moved files preserve their flag"
+mv $dax_file $TEST_DIR/move-dax
+check_xflag_dax $TEST_DIR/move-dax
+check_s_dax $TEST_DIR/move-dax
+
+echo "   *** Check file chattr of non-dax flags"
+xfs_io -c 'chattr +s' $dax_inh_file
+xfs_io -c 'chattr -s' $dax_inh_file
+
+echo "   *** Check '-o dax=garbage'"
+remount_w_option "-o dax=garbage"
+_check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR
+if [ "$?" == "0" ]; then
+	echo "ERROR: fs mounted with '-o dax=garbage'"
+fi
+
+status=0 ; exit
diff --git a/tests/xfs/999.out b/tests/xfs/999.out
new file mode 100644
index 000000000000..3a4f970a5073
--- /dev/null
+++ b/tests/xfs/999.out
@@ -0,0 +1,22 @@
+QA output created by 999
+running tests...
+   *** mark dax-dir as dax enabled
+   *** check file inheritance
+   *** check directory inheritance
+   *** check changing directory
+   *** check non file inheritance
+   *** check that previous file stays enabled
+   *** Reset the directory
+   *** Check '-o dax'
+   *** non-dax inode but overrides to be effective
+   *** Check for non-dax inode to be dax with mount option
+   *** Check '-o dax=never'
+   *** Check '-o dax=inode'
+   *** Verify changing FS_XFLAG_DAX flag
+   *** Verify S_DAX change on drop_caches
+   *** check making 'data' dax with cp
+   *** check making 'data' non-dax with cp
+   *** Moved files 'don't inherit'
+   *** Moved files preserve their flag
+   *** Check file chattr of non-dax flags
+   *** Check '-o dax=garbage'
diff --git a/tests/xfs/group b/tests/xfs/group
index 522d4bc44d1f..816883a268bf 100644
--- a/tests/xfs/group
+++ b/tests/xfs/group
@@ -511,3 +511,4 @@
 511 auto quick quota
 512 auto quick acl attr
 513 auto mount
+999 auto
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [PATCH] xfs/XXX: Add xfs/XXX
@ 2020-04-07 18:30 ira.weiny
  0 siblings, 0 replies; 12+ messages in thread
From: ira.weiny @ 2020-04-07 18:30 UTC (permalink / raw)
  To: fstests
  Cc: Ira Weiny, linux-kernel, Darrick J. Wong, Dan Williams,
	Dave Chinner, Christoph Hellwig, Theodore Y. Ts'o, Jan Kara,
	Jeff Moyer, linux-ext4, linux-xfs, linux-fsdevel

From: Ira Weiny <ira.weiny@intel.com>

Add XXX to test per file DAX operations.

The following is tested[*]

 - Applications must call statx to discover the current S_DAX state.

 - There exists an advisory file inode flag FS_XFLAG_DAX that is set based on
   the parent directory FS_XFLAG_DAX inode flag.  (There is no way to change
   this flag after file creation.)

   If FS_XFLAG_DAX is set and the fs is on pmem then it will enable S_DAX at
   inode load time; if FS_XFLAG_DAX is not set, it will not enable S_DAX.
   Unless overridden...

 - There exists a dax= mount option.

   "-o dax=never" means "never set S_DAX, ignore FS_XFLAG_DAX"
   "-o dax=always" means "always set S_DAX (at least on pmem), ignore FS_XFLAG_DAX"
	"-o dax" (old option) by itself means "dax=always"
   "-o dax=iflag" means "follow FS_XFLAG_DAX" and is the default

 - There exists an advisory directory inode flag FS_XFLAG_DAX that can be
   changed at any time.  The flag state is copied into any files or
   subdirectories when they are created within that directory.  If programs
   require file access runs in S_DAX mode, they must create those files
   inside a directory with FS_XFLAG_DAX set, or mount the fs with an
   appropriate dax mount option.

[*] https://lore.kernel.org/lkml/20200405061945.GA94792@iweiny-DESK2.sc.intel.com/

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 tests/xfs/999     | 231 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/999.out |  21 +++++
 tests/xfs/group   |   1 +
 3 files changed, 253 insertions(+)
 create mode 100755 tests/xfs/999
 create mode 100644 tests/xfs/999.out

diff --git a/tests/xfs/999 b/tests/xfs/999
new file mode 100755
index 000000000000..4d3048616715
--- /dev/null
+++ b/tests/xfs/999
@@ -0,0 +1,231 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019 Intel, Corp.  All Rights Reserved.
+#
+# FSQA Test No. 999 (temporary)
+#
+# Test setting of DAX flag
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+status=1	# failure is the default!
+
+dax_dir=$TEST_DIR/dax-dir
+dax_sub_dir=$TEST_DIR/dax-dir/dax-sub-dir
+dax_inh_file=$dax_dir/dax-inh-file
+dax_non_inh_file=$dax_dir/dax-non-inh-file
+non_dax=$TEST_DIR/non-dax
+dax_file=$TEST_DIR/dax-dir/dax-file
+dax_file_copy=$TEST_DIR/dax-file-copy
+dax_file_move=$TEST_DIR/dax-file-move
+data_file=$TEST_DIR/data-file
+
+_cleanup() {
+	rm -rf $TEST_DIR/*
+}
+
+trap "_cleanup ; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common/rc
+
+# real QA test starts here
+_supported_os Linux
+_require_xfs_io_command "lsattr"
+_require_xfs_io_command "statx"
+_require_test
+
+#
+# mnt_opt's we expect
+# ''
+# '-o dax=off'
+# '-o dax=iflag'
+# '-o dax'
+# '-o dax=always'
+function remount_w_option {
+	mnt_opt=$1
+	export MOUNT_OPTIONS=""
+	export TEST_FS_MOUNT_OPTS=""
+	_test_unmount
+	_test_mount $mnt_opt
+}
+
+function check_dax_mount_option {
+	mnt_opt=$1
+	_fs_options $TEST_DEV | grep -qw '$mnt_opt'
+	if [ "$?" == "0" ]; then
+		echo "FAILED: to mount FS with option '$mnt_opt'"
+		status=1; exit
+	fi
+}
+
+function check_xflag_dax {
+	xfs_io -c 'lsattr' $1 | awk -e '{ print $1 }' | grep 'x' &> /dev/null
+	if [ "$?" != "0" ]; then
+		echo "FAILED: Did NOT find FS_XFLAG_DAX on $1"
+		status=1; exit
+	fi
+}
+
+function check_s_dax {
+	attr=`xfs_io -c 'statx -r' $1 | grep 'stat.attributes' | awk -e '{ print $3 }'`
+	masked=$(( $attr & 0x2000 ))
+	if [ "$masked" != "8192" ]; then
+		echo "FAILED: Did NOT find S_DAX flag on $1"
+		status=1; exit
+	fi
+}
+
+function check_no_xflag_dax {
+	xfs_io -c 'lsattr' $1 | awk -e '{ print $1 }' | grep 'x' &> /dev/null
+	if [ "$?" == "0" ]; then
+		echo "FAILED: Found FS_XFLAG_DAX on $1"
+		status=1; exit
+	fi
+}
+
+function check_no_s_dax {
+	attr=`xfs_io -c 'statx -r' $1 | grep 'stat.attributes' | awk -e '{ print $3 }'`
+	masked=$(( $attr & 0x2000 ))
+	if [ "$masked" == "8192" ]; then
+		echo "FAILED: Found S_DAX flag on $1"
+		status=1; exit
+	fi
+}
+
+echo "running tests..."
+
+remount_w_option ""
+check_dax_mount_option "dax=iflag"
+
+echo "   *** mark dax-dir as dax enabled"
+mkdir $dax_dir
+xfs_io -c 'chattr +x' $dax_dir
+check_xflag_dax $dax_dir
+
+echo "   *** check file inheritance"
+touch $dax_inh_file
+check_xflag_dax $dax_inh_file
+check_s_dax $dax_inh_file
+
+echo "   *** check directory inheritance"
+mkdir $dax_sub_dir
+check_xflag_dax $dax_sub_dir
+
+echo "   *** check changing directory"
+xfs_io -c 'chattr -x' $dax_dir
+check_no_xflag_dax $dax_dir
+check_no_s_dax $dax_dir
+
+echo "   *** check non file inheritance"
+touch $dax_non_inh_file
+check_no_xflag_dax $dax_non_inh_file
+check_no_s_dax $dax_non_inh_file
+
+echo "   *** check that previous file stays enabled"
+check_xflag_dax $dax_inh_file
+check_s_dax $dax_inh_file
+
+echo "   *** Reset the directory"
+xfs_io -c 'chattr +x' $dax_dir
+check_xflag_dax $dax_dir
+
+# Set up for next test
+touch $dax_file
+touch $non_dax
+
+#
+#                      inode flag
+# ./
+#   + dax-dir/             X
+#     + dax-sub-dir/       X
+#     + dax-inh-file       X
+#     + dax-non-inh-file
+#     + dax-file           X
+#   + non-dax
+#
+
+# check mount overrides
+# =====================
+
+echo "   *** Check '-o dax'"
+remount_w_option "-o dax"
+check_dax_mount_option "dax=always"
+
+echo "   *** non-dax inode but overrides to be effective"
+check_no_xflag_dax $non_dax
+check_s_dax $non_dax
+
+echo "   *** Check for non-dax inode to be dax with mount option"
+check_no_xflag_dax $dax_non_inh_file
+check_s_dax $dax_non_inh_file
+
+
+echo "   *** Check '-o dax=never'"
+remount_w_option "-o dax=never"
+check_dax_mount_option "dax=never"
+
+check_xflag_dax $dax_dir
+check_xflag_dax $dax_sub_dir
+check_xflag_dax $dax_inh_file
+check_no_s_dax $dax_inh_file
+check_no_xflag_dax $dax_non_inh_file
+check_no_s_dax $dax_non_inh_file
+check_no_xflag_dax $non_dax
+check_no_s_dax $non_dax
+check_xflag_dax $dax_file
+check_no_s_dax $dax_file
+
+
+echo "   *** Check '-o dax=iflag'"
+remount_w_option "-o dax=iflag"
+check_dax_mount_option "dax=iflag"
+
+check_xflag_dax $dax_dir
+check_xflag_dax $dax_sub_dir
+check_xflag_dax $dax_inh_file
+check_s_dax $dax_inh_file
+check_no_xflag_dax $dax_non_inh_file
+check_no_s_dax $dax_non_inh_file
+check_no_xflag_dax $non_dax
+check_no_s_dax $non_dax
+check_xflag_dax $dax_file
+check_s_dax $dax_file
+
+
+# Check non-zero file operations
+# ==============================
+
+echo "   *** Verify setting FS_XFLAG_DAX flag fails"
+$XFS_IO_PROG -f -c "pwrite 0 10000" $data_file > /dev/null
+xfs_io -c 'chattr +x' $data_file
+check_no_xflag_dax $data_file
+check_no_s_dax $data_file
+
+
+# Check inheritance on cp, mv
+# ===========================
+
+echo "   *** check making 'data' dax with cp"
+cp $non_dax $dax_dir/conv-dax
+check_xflag_dax $dax_dir/conv-dax
+check_s_dax $dax_dir/conv-dax
+
+echo "   *** check making 'data' non-dax with cp"
+rm -f $data_file
+cp $dax_dir/conv-dax $data_file
+check_no_xflag_dax $data_file
+check_no_s_dax $data_file
+
+echo "   *** Moved files 'don't inherit'"
+mv $non_dax $dax_dir/move-dax
+check_no_xflag_dax $dax_dir/move-dax
+check_no_s_dax $dax_dir/move-dax
+
+echo "   *** Check '-o dax=garbage'"
+remount_w_option "-o dax=garbage"
+
+status=0 ; exit
diff --git a/tests/xfs/999.out b/tests/xfs/999.out
new file mode 100644
index 000000000000..3b204d4643a5
--- /dev/null
+++ b/tests/xfs/999.out
@@ -0,0 +1,21 @@
+QA output created by 999
+running tests...
+   *** mark dax-dir as dax enabled
+   *** check file inheritance
+   *** check directory inheritance
+   *** check changing directory
+   *** check non file inheritance
+   *** check that previous file stays enabled
+   *** Reset the directory
+   *** Check '-o dax'
+   *** non-dax inode but overrides to be effective
+   *** Check for non-dax inode to be dax with mount option
+   *** Check '-o dax=never'
+   *** Check '-o dax=iflag'
+   *** Verify setting FS_XFLAG_DAX flag fails
+xfs_io: cannot set flags on /mnt/xfstests_test/data-file: Invalid argument
+   *** check making 'data' dax with cp
+   *** check making 'data' non-dax with cp
+   *** Moved files 'don't inherit'
+   *** Check '-o dax=garbage'
+mount: /mnt/xfstests_test: wrong fs type, bad option, bad superblock on /dev/pmem0p1, missing codepage or helper program, or other error.
diff --git a/tests/xfs/group b/tests/xfs/group
index 522d4bc44d1f..816883a268bf 100644
--- a/tests/xfs/group
+++ b/tests/xfs/group
@@ -511,3 +511,4 @@
 511 auto quick quota
 512 auto quick acl attr
 513 auto mount
+999 auto
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [PATCH] xfs/XXX: Add xfs/XXX
@ 2020-02-27  5:38 ira.weiny
  0 siblings, 0 replies; 12+ messages in thread
From: ira.weiny @ 2020-02-27  5:38 UTC (permalink / raw)
  To: fstests
  Cc: Ira Weiny, linux-kernel, Alexander Viro, Darrick J. Wong,
	Dan Williams, Dave Chinner, Christoph Hellwig,
	Theodore Y. Ts'o, Jan Kara, Jeff Moyer, linux-ext4,
	linux-xfs, linux-fsdevel

From: Ira Weiny <ira.weiny@intel.com>

Add XXX to test the various setting of dax flags on files.

The final fsx test was derived from Christophs test here but I wanted
more direct function tests as well so I bundled this together.

https://www.spinics.net/lists/linux-xfs/msg10124.html

Signed-off-by: Ira Weiny <ira.weiny@intel.com>

---
This tests against V4 and V5:
https://lore.kernel.org/lkml/20200227052442.22524-1-ira.weiny@intel.com/
---
 tests/xfs/999     | 279 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/999.out |  21 ++++
 tests/xfs/group   |   1 +
 3 files changed, 301 insertions(+)
 create mode 100755 tests/xfs/999
 create mode 100644 tests/xfs/999.out

diff --git a/tests/xfs/999 b/tests/xfs/999
new file mode 100755
index 000000000000..b123f1f39894
--- /dev/null
+++ b/tests/xfs/999
@@ -0,0 +1,279 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019 Intel, Corp.  All Rights Reserved.
+#
+# FSQA Test No. 999 (temporary)
+#
+# Test setting of DAX flag
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+status=1	# failure is the default!
+
+dax_dir=$TEST_DIR/dax-dir
+dax_sub_dir=$TEST_DIR/dax-dir/dax-sub-dir
+dax_inh_file=$dax_dir/dax-inh-file
+dax_non_inh_file=$dax_dir/dax-non-inh-file
+non_dax=$TEST_DIR/non-dax
+dax_file=$TEST_DIR/dax-file
+dax_file_copy=$TEST_DIR/dax-file-copy
+dax_file_move=$TEST_DIR/dax-file-move
+data_file=$TEST_DIR/data-file
+
+_cleanup() {
+	rm -rf $TEST_DIR/*
+}
+
+trap "_cleanup ; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common/rc
+
+# real QA test starts here
+_supported_os Linux
+_require_xfs_io_command "lsattr"
+_require_xfs_io_command "chattr" "x"
+_require_xfs_io_command "statx"
+_require_test
+
+function mount_no_dax {
+	# mount SCRATCH_DEV with dax option, TEST_DEV not
+	export MOUNT_OPTIONS=""
+	export TEST_FS_MOUNT_OPTS=""
+	_test_unmount
+	_test_mount
+	_fs_options $TEST_DEV | grep -qw "dax"
+	if [ "$?" == "0" ]; then
+		_notrun "we need $TEST_DEV mount without dax"
+	fi
+}
+
+function mount_dax {
+	# mount SCRATCH_DEV with dax option, TEST_DEV not
+	export MOUNT_OPTIONS=""
+	export TEST_FS_MOUNT_OPTS=""
+	_test_unmount
+	_test_mount "-o dax"
+	_fs_options $TEST_DEV | grep -qw "dax"
+	if [ "$?" != "0" ]; then
+		_notrun "we need $TEST_DEV mount with dax"
+	fi
+}
+
+function check_phys_dax {
+	xfs_io -c 'lsattr' $1 | awk -e '{ print $1 }' | grep 'x' &> /dev/null
+	if [ "$?" != "0" ]; then
+		echo "FAILED: Did NOT find DAX flag on $1"
+		status=1; exit
+	fi
+}
+
+function check_effective_dax {
+	attr=`xfs_io -c 'statx -r' $1 | grep 'stat.attributes' | awk -e '{ print $3 }'`
+	masked=$(( $attr & 0x2000 ))
+	if [ "$masked" != "8192" ]; then
+		echo "FAILED: Did NOT find VFS DAX flag on $1"
+		status=1; exit
+	fi
+}
+
+function check_phys_no_dax {
+	xfs_io -c 'lsattr' $1 | awk -e '{ print $1 }' | grep 'x' &> /dev/null
+	if [ "$?" == "0" ]; then
+		echo "FAILED: Found DAX flag on $1"
+		status=1; exit
+	fi
+}
+
+function check_effective_no_dax {
+	attr=`xfs_io -c 'statx -r' $1 | grep 'stat.attributes' | awk -e '{ print $3 }'`
+	masked=$(( $attr & 0x2000 ))
+	if [ "$masked" == "8192" ]; then
+		echo "FAILED: Found VFS DAX flag on $1"
+		status=1; exit
+	fi
+}
+
+echo "running tests..."
+
+echo "   *** mount w/o dax flag."
+mount_no_dax
+
+echo "   *** mark dax-dir as dax enabled"
+mkdir $dax_dir
+xfs_io -c 'chattr +x' $dax_dir
+check_phys_dax $dax_dir
+
+echo "   *** check file inheritance"
+touch $dax_inh_file
+check_phys_dax $dax_inh_file
+check_effective_dax $dax_inh_file
+
+echo "   *** check directory inheritance"
+mkdir $dax_sub_dir
+check_phys_dax $dax_sub_dir
+
+echo "   *** check changing directory"
+xfs_io -c 'chattr -x' $dax_dir
+check_phys_no_dax $dax_dir
+check_effective_no_dax $dax_dir
+
+echo "   *** check non file inheritance"
+touch $dax_non_inh_file
+check_phys_no_dax $dax_non_inh_file
+check_effective_no_dax $dax_non_inh_file
+
+echo "   *** check that previous file stays enabled"
+check_phys_dax $dax_inh_file
+check_effective_dax $dax_inh_file
+
+echo "   *** Reset the directory"
+xfs_io -c 'chattr +x' $dax_dir
+check_phys_dax $dax_dir
+
+
+# check mount override
+# ====================
+
+echo "   *** Remount fs with mount flag"
+mount_dax
+touch $non_dax
+check_phys_no_dax $non_dax
+check_effective_dax $non_dax
+
+echo "   *** Check for non-dax files to be dax with mount option"
+check_effective_dax $dax_non_inh_file
+
+echo "   *** check for file dax flag 'sticky-ness' after remount"
+touch $dax_file
+xfs_io -c 'chattr +x' $dax_file
+check_phys_dax $dax_file
+check_effective_dax $dax_file
+
+echo "   *** remount w/o mount flag"
+mount_no_dax
+check_phys_dax $dax_file
+check_effective_dax $dax_file
+
+check_phys_no_dax $non_dax
+check_effective_no_dax $non_dax
+
+
+# Check non-zero file operations
+# ==============================
+
+echo "   *** file should change effective but page cache should be empty"
+$XFS_IO_PROG -f -c "pwrite 0 10000" $data_file > /dev/null
+xfs_io -c 'chattr +x' $data_file
+check_phys_dax $data_file
+check_effective_dax $data_file
+
+
+# Check inheritance on cp, mv
+# ===========================
+
+echo "   *** check inheritance on cp, mv"
+cp $non_dax $dax_dir/conv-dax
+check_phys_dax $dax_dir/conv-dax
+check_effective_dax $dax_dir/conv-dax
+
+echo "   *** Moved files 'don't inherit'"
+mv $non_dax $dax_dir/move-dax
+check_phys_no_dax $dax_dir/move-dax
+check_effective_no_dax $dax_dir/move-dax
+
+# Check preservation of phys on cp, mv
+# ====================================
+
+mv $dax_file $dax_file_move
+check_phys_dax $dax_file_move
+check_effective_dax $dax_file_move
+
+cp $dax_file_move $dax_file_copy
+check_phys_no_dax $dax_file_copy
+check_effective_no_dax $dax_file_copy
+
+
+# Verify no mode changes on mmap
+# ==============================
+
+echo "   *** check no mode change when mmaped"
+
+dd if=/dev/zero of=$dax_file bs=4096 count=10 > $tmp.log 2>&1
+
+# set known state.
+xfs_io -c 'chattr -x' $dax_file
+check_phys_no_dax $dax_file
+check_effective_no_dax $dax_file
+
+python3 - << EOF > $tmp.log 2>&1 &
+import mmap
+import time
+print ('mmaping "$dax_file"')
+f=open("$dax_file", "r+b")
+mm = mmap.mmap(f.fileno(), 0)
+print ('mmaped "$dax_file"')
+while True:
+	time.sleep(1)
+EOF
+pid=$!
+
+sleep 1
+
+# attempt to should fail
+xfs_io -c 'chattr +x' $dax_file > /dev/null 2>&1
+check_phys_no_dax $dax_file
+check_effective_no_dax $dax_file
+
+kill -TERM $pid > /dev/null 2>&1
+wait $pid > /dev/null 2>&1
+
+# after mmap released should work
+xfs_io -c 'chattr +x' $dax_file
+check_phys_dax $dax_file
+check_effective_dax $dax_file
+
+
+# Finally run the test stolen from Christoph Hellwig to test changing the mode
+# while performing a series of operations
+# =============================================================================
+
+function run_fsx {
+	options=$1
+
+	echo "   *** run 'fsx $options' racing with setting/clearing the DAX flag"
+	$here/ltp/fsx $options -N 20000 $dax_file > $tmp.log 2>&1 &
+	pid=$!
+
+	if [ ! -n "$pid" ]; then
+		echo "FAILED to start fsx"
+		exit 255
+	fi
+
+	# NOTE: fsx runs much faster than these mode changes.
+	for i in `seq 1 500`; do
+		xfs_io -c 'chattr +x' $dax_file > /dev/null 2>&1
+		xfs_io -c 'chattr -x' $dax_file > /dev/null 2>&1
+	done
+
+	wait $pid
+	status=$?
+	if [ "$status" != "0" ]; then
+		cat /sys/kernel/debug/tracing/trace > trace_output
+		echo "FAILED: fsx exited with status : $status"
+		echo "        see trace_output"
+		head $dax_file.fsxlog
+		exit $status
+	fi
+	pid=""
+}
+
+run_fsx ""
+run_fsx "-A"
+run_fsx "-Z -r 4096 -w 4096"
+
+
+status=0 ; exit
diff --git a/tests/xfs/999.out b/tests/xfs/999.out
new file mode 100644
index 000000000000..ccb13770ca4d
--- /dev/null
+++ b/tests/xfs/999.out
@@ -0,0 +1,21 @@
+QA output created by 999
+running tests...
+   *** mount w/o dax flag.
+   *** mark dax-dir as dax enabled
+   *** check file inheritance
+   *** check directory inheritance
+   *** check changing directory
+   *** check non file inheritance
+   *** check that previous file stays enabled
+   *** Reset the directory
+   *** Remount fs with mount flag
+   *** Check for non-dax files to be dax with mount option
+   *** check for file dax flag 'sticky-ness' after remount
+   *** remount w/o mount flag
+   *** file should change effective but page cache should be empty
+   *** check inheritance on cp, mv
+   *** Moved files 'don't inherit'
+   *** check no mode change when mmaped
+   *** run 'fsx ' racing with setting/clearing the DAX flag
+   *** run 'fsx -A' racing with setting/clearing the DAX flag
+   *** run 'fsx -Z -r 4096 -w 4096' racing with setting/clearing the DAX flag
diff --git a/tests/xfs/group b/tests/xfs/group
index 522d4bc44d1f..816883a268bf 100644
--- a/tests/xfs/group
+++ b/tests/xfs/group
@@ -511,3 +511,4 @@
 511 auto quick quota
 512 auto quick acl attr
 513 auto mount
+999 auto
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-06-03  3:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-13  5:44 [PATCH] xfs/XXX: Add xfs/XXX ira.weiny
2020-04-13  7:54 ` Amir Goldstein
2020-04-13 15:53   ` Ira Weiny
2020-04-13 16:11     ` Amir Goldstein
2020-04-13 16:22       ` Darrick J. Wong
2020-04-13 16:30 ` Darrick J. Wong
2020-06-02  8:51   ` Xiao Yang
2020-06-02 18:14     ` Darrick J. Wong
2020-06-03  1:56       ` Xiao Yang
2020-06-03  3:49         ` Darrick J. Wong
  -- strict thread matches above, loose matches on Subject: below --
2020-04-07 18:30 ira.weiny
2020-02-27  5:38 ira.weiny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).