xfs: refactor minimum log size formatting code
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 7 May 2019 16:56:56 +0000 (09:56 -0700)
committerEryu Guan <guaneryu@gmail.com>
Fri, 10 May 2019 09:29:57 +0000 (17:29 +0800)
Create a new helper function to discover the minimum log size that will
work with the mkfs options provided, then remove all the hardcoded block
sizes from various xfs tests.  This will be necessary when we turn on
reflink or rmap by default and the minimum log size increases.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Tested-by: Yang Xu<xuyang2018.jy@cn.fujitsu.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
common/xfs
tests/xfs/104
tests/xfs/119
tests/xfs/291
tests/xfs/295
tests/xfs/297

index af2b62ba920a8a069fe31abd58963800aae783f7..42f02ff73b36bd11754d68593153ce44fb1409a9 100644 (file)
@@ -77,6 +77,42 @@ _scratch_mkfs_xfs_supported()
        return $mkfs_status
 }
 
+# Returns the minimum XFS log size, in units of log blocks.
+_scratch_find_xfs_min_logblocks()
+{
+       local mkfs_cmd="`_scratch_mkfs_xfs_opts`"
+
+       # The smallest log size we can specify is 2M (XFS_MIN_LOG_BYTES) so
+       # pass that in and see if mkfs succeeds or tells us what is the
+       # minimum log size.
+       local XFS_MIN_LOG_BYTES=2097152
+
+       _scratch_do_mkfs "$mkfs_cmd" "cat" $* -N -l size=$XFS_MIN_LOG_BYTES \
+               2>$tmp.mkfserr 1>$tmp.mkfsstd
+       local mkfs_status=$?
+
+       # mkfs suceeded, so we must pick out the log block size to do the
+       # unit conversion
+       if [ $mkfs_status -eq 0 ]; then
+               local blksz="$(grep '^log.*bsize' $tmp.mkfsstd | \
+                       sed -e 's/log.*bsize=\([0-9]*\).*$/\1/g')"
+               echo $((XFS_MIN_LOG_BYTES / blksz))
+               return
+       fi
+
+       # Usually mkfs will tell us the minimum log size...
+       if grep -q 'minimum size is' $tmp.mkfserr; then
+               grep 'minimum size is' $tmp.mkfserr | \
+                       sed -e 's/^.*minimum size is \([0-9]*\) blocks/\1/g'
+               return
+       fi
+
+       # Don't know what to do, so fail
+       echo "Cannot determine minimum log size" >&2
+       cat $tmp.mkfsstd >> $seqres.full
+       cat $tmp.mkfserr >> $seqres.full
+}
+
 _scratch_mkfs_xfs()
 {
        local mkfs_cmd="`_scratch_mkfs_xfs_opts`"
index bc38f9696076af2cde30d723b1c633e5c8816a12..679aced4d2f0930bbcda2714d0dd5cee56543520 100755 (executable)
@@ -71,7 +71,8 @@ nags=4
 size=`expr 125 \* 1048576`     # 120 megabytes initially
 sizeb=`expr $size / $dbsize`   # in data blocks
 echo "*** creating scratch filesystem"
-_create_scratch -lsize=10m -dsize=${size} -dagcount=${nags}
+logblks=$(_scratch_find_xfs_min_logblocks -dsize=${size} -dagcount=${nags})
+_create_scratch -lsize=${logblks}b -dsize=${size} -dagcount=${nags}
 
 echo "*** using some initial space on scratch filesystem"
 for i in `seq 125 -1 90`; do
index bf7f1ca887ede64b0506ee2c5d05ceb2b9f74ed7..8825a5c3bf30a86e4c07894440ccfd45f90b699a 100755 (executable)
@@ -38,7 +38,8 @@ _require_scratch
 # this may hang
 sync
 
-export MKFS_OPTIONS="-l version=2,size=2560b,su=64k" 
+logblks=$(_scratch_find_xfs_min_logblocks -l version=2,su=64k)
+export MKFS_OPTIONS="-l version=2,size=${logblks}b,su=64k"
 export MOUNT_OPTIONS="-o logbsize=64k"
 _scratch_mkfs_xfs >/dev/null
 
index 349d0cd0efd57001f3330034e42d4e739b04ff91..8a4b1354acb6e5136c06e83ad54fceeab605aff4 100755 (executable)
@@ -31,7 +31,8 @@ _supported_os Linux
 # real QA test starts here
 rm -f $seqres.full
 _require_scratch
-_scratch_mkfs_xfs -n size=16k -l size=10m -d size=133m >> $seqres.full 2>&1
+logblks=$(_scratch_find_xfs_min_logblocks -n size=16k -d size=133m)
+_scratch_mkfs_xfs -n size=16k -l size=${logblks}b -d size=133m >> $seqres.full 2>&1
 _scratch_mount
 
 # First we cause very badly fragmented freespace, then
index 7d1c8faff0e9f0e5b97cb3238a2e1d85188cc3ba..65da7d65194446b2bb7020f66d3134ea91892b7d 100755 (executable)
@@ -36,7 +36,8 @@ _require_attrs
 
 rm -f $seqres.full
 
-_scratch_mkfs -l size=2560b >/dev/null 2>&1
+logblks=$(_scratch_find_xfs_min_logblocks)
+_scratch_mkfs -l size=${logblks}b >/dev/null 2>&1
 
 # Should yield a multiply-logged inode, thanks to xattr
 # Old logprint says this, then coredumps:
@@ -53,7 +54,7 @@ _scratch_xfs_logprint 2>&1 >> $seqres.full
 # match, not as a continued transaction.  If that happens we'll see:
 #      xfs_logprint: unknown log operation type (494e)
 
-_scratch_mkfs -l size=2560b >/dev/null 2>&1
+_scratch_mkfs -l size=${logblks}b >/dev/null 2>&1
 _scratch_mount
 for I in `seq 0 8192`; do
         echo a >> $SCRATCH_MNT/cat
index 1a048b4b6f3a41d599f4c5bab4ca967df9b55e3a..4f564add6cbb151bff33b0d6b05e82dbcc79af63 100755 (executable)
@@ -36,7 +36,8 @@ _require_freeze
 _require_command "$KILLALL_PROG" killall
 
 rm -f $seqres.full
-_scratch_mkfs_xfs -d agcount=16,su=256k,sw=12 -l su=256k,size=5120b >/dev/null 2>&1
+logblks=$(_scratch_find_xfs_min_logblocks -d agcount=16,su=256k,sw=12 -l su=256k)
+_scratch_mkfs_xfs -d agcount=16,su=256k,sw=12 -l su=256k,size=${logblks}b >/dev/null 2>&1
 _scratch_mount
 
 STRESS_DIR="$SCRATCH_MNT/testdir"