fstests.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xiao Yang <yangx.jy@cn.fujitsu.com>
To: <fstests@vger.kernel.org>
Cc: <darrick.wong@oracle.com>, <ira.weiny@intel.com>,
	<guaneryu@gmail.com>, Xiao Yang <yangx.jy@cn.fujitsu.com>
Subject: [PATCH v9 6/8] generic: Verify if statx() can qurey S_DAX flag on regular file correctly
Date: Thu, 6 Aug 2020 10:13:40 +0800	[thread overview]
Message-ID: <20200806021342.10596-7-yangx.jy@cn.fujitsu.com> (raw)
In-Reply-To: <20200806021342.10596-1-yangx.jy@cn.fujitsu.com>

1) With new kernel(e.g. v5.8-rc1), statx() can be used to qurey S_DAX flag
   on regular file, so add a test to verify the feature.
2) Factor out _check_s_dax() so that other tests can use it in future.

Reference:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=712b2698e4c024b561694cbcc1abba13eb0fd9ce

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 common/rc             | 13 ++++++
 tests/generic/606     | 92 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/606.out |  2 +
 tests/generic/group   |  1 +
 4 files changed, 108 insertions(+)
 create mode 100644 tests/generic/606
 create mode 100644 tests/generic/606.out

diff --git a/common/rc b/common/rc
index 98bb1454..de431c7a 100644
--- a/common/rc
+++ b/common/rc
@@ -3196,6 +3196,19 @@ _require_scratch_shutdown()
 	_scratch_unmount
 }
 
+_check_s_dax()
+{
+	local target=$1
+	local exp_s_dax=$2
+
+	local attributes=$($XFS_IO_PROG -c 'statx -r' $target | awk '/stat.attributes / { print $3 }')
+	if [ $exp_s_dax -eq 0 ]; then
+		(( attributes & 0x2000 )) && echo "$target has unexpected S_DAX flag"
+	else
+		(( attributes & 0x2000 )) || echo "$target doen't have expected S_DAX flag"
+	fi
+}
+
 # Check if dax mount options are supported
 #
 # $1 can be either 'dax=always' or 'dax'
diff --git a/tests/generic/606 b/tests/generic/606
new file mode 100644
index 00000000..bf7d822d
--- /dev/null
+++ b/tests/generic/606
@@ -0,0 +1,92 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Fujitsu.  All Rights Reserved.
+#
+# FS QA Test 606
+#
+# By the following cases, verify if statx() can query S_DAX flag
+# on regular file correctly.
+# 1) With dax=always option, FS_XFLAG_DAX is ignored and S_DAX flag
+#    always exists on regular file.
+# 2) With dax=inode option, setting/clearing FS_XFLAG_DAX can change
+#    S_DAX flag on regular file.
+# 3) With dax=never option, FS_XFLAG_DAX is ignored and S_DAX flag
+#    never exists on regular file.
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1        # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+_supported_fs generic
+_supported_os Linux
+_require_scratch_dax_mountopt "dax=always"
+_require_dax_iflag
+_require_xfs_io_command "statx" "-r"
+
+PARENT_DIR=$SCRATCH_MNT/testdir
+TEST_FILE=$PARENT_DIR/testfile
+
+test_s_dax()
+{
+	local dax_option=$1
+	local exp_s_dax1=$2
+	local exp_s_dax2=$3
+
+	# Mount with specified dax option
+	_scratch_mount "$dax_option"
+
+	# Prepare directory
+	mkdir -p $PARENT_DIR
+
+	rm -f $TEST_FILE
+	$XFS_IO_PROG -c "chattr +x" $PARENT_DIR
+	touch $TEST_FILE
+	# Check if setting FS_XFLAG_DAX changes S_DAX flag
+	_check_s_dax $TEST_FILE $exp_s_dax1
+
+	rm -f $TEST_FILE
+	$XFS_IO_PROG -c "chattr -x" $PARENT_DIR
+	touch $TEST_FILE
+	# Check if clearing FS_XFLAG_DAX changes S_DAX flag
+	_check_s_dax $TEST_FILE $exp_s_dax2
+
+	_scratch_unmount
+}
+
+do_tests()
+{
+	_scratch_mkfs >> $seqres.full 2>&1
+
+	# Mount with specified dax option
+	test_s_dax "-o dax=always" 1 1
+	test_s_dax "-o dax=never" 0 0
+	test_s_dax "-o dax=inode" 1 0
+	# Mount without dax option
+	export MOUNT_OPTIONS=""
+	test_s_dax "" 1 0
+}
+
+do_tests
+
+# success, all done
+echo "Silence is golden"
+status=0
+exit
diff --git a/tests/generic/606.out b/tests/generic/606.out
new file mode 100644
index 00000000..09bf888e
--- /dev/null
+++ b/tests/generic/606.out
@@ -0,0 +1,2 @@
+QA output created by 606
+Silence is golden
diff --git a/tests/generic/group b/tests/generic/group
index d06c1bf6..05c6b02d 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -608,3 +608,4 @@
 603 auto quick quota
 604 auto quick mount
 605 auto attr quick dax
+606 auto attr quick dax
-- 
2.21.0




  parent reply	other threads:[~2020-08-06  2:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-06  2:13 [PATCH v9 0/8] Make fstests support new behavior of DAX Xiao Yang
2020-08-06  2:13 ` [PATCH v9 1/8] common/rc: Introduce helpers for new dax mount options and FS_XFLAG_DAX Xiao Yang
2020-08-06 15:16   ` Darrick J. Wong
2020-08-06  2:13 ` [PATCH v9 2/8] fstests: Use _require_scratch_dax_mountopt() and _require_dax_iflag() Xiao Yang
2020-08-06  2:13 ` [PATCH v9 3/8] generic/223: Don't clear MKFS_OPTION before calling _scratch_mkfs_geom() Xiao Yang
2020-08-06  2:13 ` [PATCH v9 4/8] generic/413, xfs/260: Improve format operation for PMD fault testing Xiao Yang
2020-08-06  2:13 ` [PATCH v9 5/8] xfs/260: Move and update xfs/260 Xiao Yang
2020-08-06  2:13 ` Xiao Yang [this message]
2020-08-06  2:13 ` [PATCH v9 7/8] generic: Verify the inheritance behavior of FS_XFLAG_DAX flag in various combinations Xiao Yang
2020-08-06  2:13 ` [PATCH v9 8/8] generic: Verify how to change the S_DAX flag on an existing file Xiao Yang
2020-08-07  1:45   ` Xiao Yang
2020-08-07 18:14 ` [PATCH v9 0/8] Make fstests support new behavior of DAX Ira Weiny
2020-08-09 17:12   ` Eryu Guan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200806021342.10596-7-yangx.jy@cn.fujitsu.com \
    --to=yangx.jy@cn.fujitsu.com \
    --cc=darrick.wong@oracle.com \
    --cc=fstests@vger.kernel.org \
    --cc=guaneryu@gmail.com \
    --cc=ira.weiny@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).