diff mbox series

[1/6] common/xfs: refactor commands to select a particular xfs backing device

Message ID 162146860674.2500122.8733670522999610459.stgit@magnolia (mailing list archive)
State New, archived
Headers show
Series fstests: miscellaneous fixes | expand

Commit Message

Darrick J. Wong May 19, 2021, 11:56 p.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

Refactor all the places where we try to force new file data allocations
to a specific xfs backing device so that we don't end up open-coding the
same xfs_io command lines over and over.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 common/populate   |    2 +-
 common/xfs        |   25 +++++++++++++++++++++++++
 tests/generic/223 |    3 ++-
 tests/generic/449 |    2 +-
 tests/xfs/004     |    2 +-
 tests/xfs/146     |    2 +-
 tests/xfs/147     |    2 +-
 tests/xfs/272     |    2 +-
 tests/xfs/318     |    2 +-
 tests/xfs/431     |    4 ++--
 tests/xfs/521     |    2 +-
 tests/xfs/528     |    2 +-
 tests/xfs/532     |    2 +-
 tests/xfs/533     |    2 +-
 tests/xfs/538     |    2 +-
 15 files changed, 41 insertions(+), 15 deletions(-)

Comments

Christoph Hellwig May 21, 2021, 7:51 a.m. UTC | #1
On Wed, May 19, 2021 at 04:56:46PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Refactor all the places where we try to force new file data allocations
> to a specific xfs backing device so that we don't end up open-coding the
> same xfs_io command lines over and over.

Eventually this might need generalization for other file systems for the
generic tests, but for now this looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/common/populate b/common/populate
index d484866a..867776cd 100644
--- a/common/populate
+++ b/common/populate
@@ -162,7 +162,7 @@  _scratch_xfs_populate() {
 	# Clear the rtinherit flag on the root directory so that files are
 	# always created on the data volume regardless of MKFS_OPTIONS.  We can
 	# set the realtime flag when needed.
-	$XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
+	_xfs_force_bdev data $SCRATCH_MNT
 
 	blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
 	dblksz="$($XFS_INFO_PROG "${SCRATCH_MNT}" | grep naming.*bsize | sed -e 's/^.*bsize=//g' -e 's/\([0-9]*\).*$/\1/g')"
diff --git a/common/xfs b/common/xfs
index 725819bd..d7f2a005 100644
--- a/common/xfs
+++ b/common/xfs
@@ -194,6 +194,31 @@  _xfs_get_file_block_size()
 	$XFS_INFO_PROG "$path" | grep realtime | sed -e 's/^.*extsz=\([0-9]*\).*$/\1/g'
 }
 
+# Set or clear the realtime status of every supplied path.  The first argument
+# is either 'data' or 'realtime'.  All other arguments should be paths to
+# existing directories or empty regular files.
+#
+# For each directory, each file subsequently created will target the given
+# device for file data allocations.  For each empty regular file, each
+# subsequent file data allocation will be on the given device.
+_xfs_force_bdev()
+{
+	local device="$1"
+	shift
+	local chattr_arg=""
+
+	case "$device" in
+	"data")		chattr_arg="-t";;
+	"realtime")	chattr_arg="+t";;
+	*)
+		echo "${device}: Don't know what device this is?"
+		return 1
+		;;
+	esac
+
+	$XFS_IO_PROG -c "chattr $chattr_arg" "$@"
+}
+
 _xfs_get_fsxattr()
 {
 	local field="$1"
diff --git a/tests/generic/223 b/tests/generic/223
index f6393293..078fd725 100755
--- a/tests/generic/223
+++ b/tests/generic/223
@@ -46,7 +46,8 @@  for SUNIT_K in 8 16 32 64 128; do
 	# This test checks for stripe alignments of space allocations on the
 	# filesystem.  Make sure all files get created on the main device,
 	# which for XFS means no rt files.
-	test "$FSTYP" = "xfs" && $XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
+	test "$FSTYP" = "xfs" && \
+		_xfs_force_bdev data $SCRATCH_MNT
 
 	for SIZE_MULT in 1 2 8 64 256; do
 		let SIZE=$SIZE_MULT*$SUNIT_BYTES
diff --git a/tests/generic/449 b/tests/generic/449
index 5fd15367..2a5065f6 100755
--- a/tests/generic/449
+++ b/tests/generic/449
@@ -46,7 +46,7 @@  _scratch_mount || _fail "mount failed"
 # This is a test of xattr behavior when we run out of disk space for xattrs,
 # so make sure the pwrite goes to the data device and not the rt volume.
 test "$FSTYP" = "xfs" && \
-	$XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
+	_xfs_force_bdev data $SCRATCH_MNT
 
 TFILE=$SCRATCH_MNT/testfile.$seq
 
diff --git a/tests/xfs/004 b/tests/xfs/004
index 7633071c..d3fb9c95 100755
--- a/tests/xfs/004
+++ b/tests/xfs/004
@@ -31,7 +31,7 @@  _populate_scratch()
 	# This test looks at specific behaviors of the xfs_db freesp command,
 	# which reports on the contents of the free space btrees for the data
 	# device.  Don't let anything get created on the realtime volume.
-	$XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
+	_xfs_force_bdev data $SCRATCH_MNT
 	dd if=/dev/zero of=$SCRATCH_MNT/foo count=200 bs=4096 >/dev/null 2>&1 &
 	dd if=/dev/zero of=$SCRATCH_MNT/goo count=400 bs=4096 >/dev/null 2>&1 &
 	dd if=/dev/zero of=$SCRATCH_MNT/moo count=800 bs=4096 >/dev/null 2>&1 &
diff --git a/tests/xfs/146 b/tests/xfs/146
index 8f85024d..49020e01 100755
--- a/tests/xfs/146
+++ b/tests/xfs/146
@@ -78,7 +78,7 @@  _scratch_mkfs -r size=$rtsize >> $seqres.full
 _scratch_mount >> $seqres.full
 
 # Make sure the root directory has rtinherit set so our test file will too
-$XFS_IO_PROG -c 'chattr +t' $SCRATCH_MNT
+_xfs_force_bdev realtime $SCRATCH_MNT
 
 # Allocate some stuff at the start, to force the first falloc of the ouch file
 # to happen somewhere in the middle of the rt volume
diff --git a/tests/xfs/147 b/tests/xfs/147
index da962f96..5cc363aa 100755
--- a/tests/xfs/147
+++ b/tests/xfs/147
@@ -50,7 +50,7 @@  rextblks=$((rextsize / blksz))
 echo "blksz $blksz rextsize $rextsize rextblks $rextblks" >> $seqres.full
 
 # Make sure the root directory has rtinherit set so our test file will too
-$XFS_IO_PROG -c 'chattr +t' $SCRATCH_MNT
+_xfs_force_bdev realtime $SCRATCH_MNT
 
 sz=$((rextsize * 100))
 range="$((blksz * 3)) $blksz"
diff --git a/tests/xfs/272 b/tests/xfs/272
index 6c0fede5..6a1372b8 100755
--- a/tests/xfs/272
+++ b/tests/xfs/272
@@ -38,7 +38,7 @@  _scratch_mkfs > "$seqres.full" 2>&1
 _scratch_mount
 
 # Make sure everything is on the data device
-$XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
+_xfs_force_bdev data $SCRATCH_MNT
 
 _pwrite_byte 0x80 0 737373 $SCRATCH_MNT/urk >> $seqres.full
 sync
diff --git a/tests/xfs/318 b/tests/xfs/318
index 07375b1f..07b4f7f1 100755
--- a/tests/xfs/318
+++ b/tests/xfs/318
@@ -44,7 +44,7 @@  _scratch_mount >> $seqres.full
 
 # This test depends on specific behaviors of the data device, so create all
 # files on it.
-$XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
+_xfs_force_bdev data $SCRATCH_MNT
 
 echo "Create files"
 touch $SCRATCH_MNT/file1
diff --git a/tests/xfs/431 b/tests/xfs/431
index e67906dc..797b8fcd 100755
--- a/tests/xfs/431
+++ b/tests/xfs/431
@@ -47,7 +47,7 @@  _scratch_mount
 
 # Set realtime inherit flag on scratch mount, suppress output
 # as this may simply error out on future kernels
-$XFS_IO_PROG -c 'chattr +t' $SCRATCH_MNT &> /dev/null
+_xfs_force_bdev realtime $SCRATCH_MNT &> /dev/null
 
 # Check if 't' is actually set, as xfs_io returns 0 even when it fails to set
 # an attribute. And erroring out here is fine, this would be desired behavior
@@ -60,7 +60,7 @@  if $XFS_IO_PROG -c 'lsattr' $SCRATCH_MNT | grep -q 't'; then
 	# Remove the testfile and rt inherit flag after we are done or
 	# xfs_repair will fail.
 	rm -f $SCRATCH_MNT/testfile
-	$XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT | tee -a $seqres.full 2>&1
+	_xfs_force_bdev data $SCRATCH_MNT | tee -a $seqres.full 2>&1
 fi
 
 # success, all done
diff --git a/tests/xfs/521 b/tests/xfs/521
index b8026d45..99408a06 100755
--- a/tests/xfs/521
+++ b/tests/xfs/521
@@ -55,7 +55,7 @@  testdir=$SCRATCH_MNT/test-$seq
 mkdir $testdir
 
 echo "Check rt volume stats"
-$XFS_IO_PROG -c 'chattr +t' $testdir
+_xfs_force_bdev realtime $testdir
 $XFS_INFO_PROG $SCRATCH_MNT >> $seqres.full
 before=$(stat -f -c '%b' $testdir)
 
diff --git a/tests/xfs/528 b/tests/xfs/528
index 7f98c5b8..d483ae82 100755
--- a/tests/xfs/528
+++ b/tests/xfs/528
@@ -77,7 +77,7 @@  test_ops() {
 		_notrun "Could not mount rextsize=$rextsize with synthetic rt volume"
 
 	# Force all files to be realtime files
-	$XFS_IO_PROG -c 'chattr +t' $SCRATCH_MNT
+	_xfs_force_bdev realtime $SCRATCH_MNT
 
 	log "Test regular write, rextsize=$rextsize"
 	mk_file $SCRATCH_MNT/write $rextsize
diff --git a/tests/xfs/532 b/tests/xfs/532
index 560af586..f421070a 100755
--- a/tests/xfs/532
+++ b/tests/xfs/532
@@ -47,7 +47,7 @@  _scratch_mount >> $seqres.full
 
 # Disable realtime inherit flag (if any) on root directory so that space on data
 # device gets fragmented rather than realtime device.
-$XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
+_xfs_force_bdev data $SCRATCH_MNT
 
 bsize=$(_get_block_size $SCRATCH_MNT)
 
diff --git a/tests/xfs/533 b/tests/xfs/533
index dd4cb4c4..1c8cc925 100755
--- a/tests/xfs/533
+++ b/tests/xfs/533
@@ -58,7 +58,7 @@  _scratch_mount >> $seqres.full
 
 # Disable realtime inherit flag (if any) on root directory so that space on data
 # device gets fragmented rather than realtime device.
-$XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
+_xfs_force_bdev data $SCRATCH_MNT
 
 echo "Consume free space"
 fillerdir=$SCRATCH_MNT/fillerdir
diff --git a/tests/xfs/538 b/tests/xfs/538
index 97273b88..dc0e5f28 100755
--- a/tests/xfs/538
+++ b/tests/xfs/538
@@ -44,7 +44,7 @@  _scratch_mount >> $seqres.full
 
 # Disable realtime inherit flag (if any) on root directory so that space on data
 # device gets fragmented rather than realtime device.
-$XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
+_xfs_force_bdev data $SCRATCH_MNT
 
 bsize=$(_get_file_block_size $SCRATCH_MNT)