common/xfs: refactor commands to select a particular xfs backing device
authorDarrick J. Wong <djwong@kernel.org>
Wed, 19 May 2021 23:56:46 +0000 (16:56 -0700)
committerEryu Guan <guaneryu@gmail.com>
Sun, 23 May 2021 13:31:14 +0000 (21:31 +0800)
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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
15 files changed:
common/populate
common/xfs
tests/generic/223
tests/generic/449
tests/xfs/004
tests/xfs/146
tests/xfs/147
tests/xfs/272
tests/xfs/318
tests/xfs/431
tests/xfs/521
tests/xfs/528
tests/xfs/532
tests/xfs/533
tests/xfs/538

index d484866abbfe4f5b2f3eb7e189d605c11f11268e..867776cdd189bf6184cc058692f1cd5d52e3ff47 100644 (file)
@@ -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')"
index 725819bd66acef33af9fca82605a393337c40b38..d7f2a0054d4652929bf6b769233e4d0317229761 100644 (file)
@@ -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"
index f63932938c9bf620ec326941f2a17f679bfd87c5..078fd72573044122f97ad1c26c56138d280e9e75 100755 (executable)
@@ -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
index 5fd15367878f7b53ee4fa0831f182f61a7454ee4..2a5065f64bba21b7c47fa515b57cf70247230a4f 100755 (executable)
@@ -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
 
index 7633071cc4f07884e39935ba44df6979c48722f9..d3fb9c958cf496bc73e131e3ed9b62347c9706e1 100755 (executable)
@@ -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 &
index 8f85024d9d5961531ef45ec819384cd5804d9a3f..49020e01cbec7197bc78c04b800a1cebda6a341c 100755 (executable)
@@ -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
index da962f96ad9f2a194730e054a4e3e1717c6271fc..5cc363aab11d58410d7b8f18fd50a7582759142b 100755 (executable)
@@ -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"
index 6c0fede5ab17ebc78aa6548b2d37787f1b3e64f6..6a1372b871181aff303e7104dd9cd8fff5e13ff7 100755 (executable)
@@ -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
index 07375b1f80de21479324b5ee581f4c8153f3b5af..07b4f7f130fc8d88926be1495e4c7f32e9c6a577 100755 (executable)
@@ -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
index e67906dc0277010da26c14132312da4c4c7c2f10..797b8fcdcb84385042cb683cd72283c327e601c4 100755 (executable)
@@ -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
index b8026d458005c96e0e93696413bde8d8896783d8..99408a06884bc3968d46690af5b6dc6994696437 100755 (executable)
@@ -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)
 
index 7f98c5b8038876ca24d7dea4a2832a644da80cec..d483ae8271fb36ca8aa4482124c51f380219f026 100755 (executable)
@@ -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
index 560af586100d28b200ecf77207961e1d2453b689..f421070a3ad3489dbd0e809a48aff4c32fe36935 100755 (executable)
@@ -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)
 
index dd4cb4c4e6277650381ec8687f41f6d687e28d07..1c8cc925792ec8dadde25248920311bfe181ad02 100755 (executable)
@@ -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
index 97273b887c6e7bb2279fc1a23affed4a31bcb3ba..dc0e5f28a3ae955921b7a9e0e2143a83fe70ca5d 100755 (executable)
@@ -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)