xfs: test inode allocation with fragmented free space
[xfstests-dev.git] / common / rc
index 6ea107e1efea33e7112952882b070574daaf6b9d..0562360134393739026dd40cf212b5a9ac3bf127 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -308,6 +308,11 @@ _scratch_mkfs_xfs_opts()
 {
        mkfs_opts=$*
 
+       # remove crc related mkfs options if mkfs.xfs doesn't support v5 xfs
+       if [ -n "$XFS_MKFS_HAS_NO_META_SUPPORT" ]; then
+               mkfs_opts=`echo $mkfs_opts | sed "s/-m\s\+crc=.//"`
+       fi
+
        _scratch_options mkfs
 
        $MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
@@ -365,9 +370,12 @@ _scratch_mkfs_xfs()
                mkfs_status=$?
        fi
 
-       # output stored mkfs output
-       cat $tmp_dir.mkfserr >&2
+       # output stored mkfs output, filtering unnecessary warnings from stderr
        cat $tmp_dir.mkfsstd
+       cat $tmp_dir.mkfserr | sed \
+               -e '/less than device physical sector/d' \
+               -e '/switching to logical sector/d' \
+               >&2
        rm -f $tmp_dir.mkfserr $tmp_dir.mkfsstd
 
        return $mkfs_status
@@ -967,11 +975,11 @@ _is_block_dev()
 
     _dev=$1
     if [ -L "${_dev}" ]; then
-        _dev=`readlink -f ${_dev}`
+        _dev=`readlink -f "${_dev}"`
     fi
 
     if [ -b "${_dev}" ]; then
-        src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
+        src/lstat64 "${_dev}" | $AWK_PROG '/Device type:/ { print $9 }'
     fi
 }
 
@@ -1105,11 +1113,11 @@ _require_scratch_nocheck()
                fi
                ;;
        *)
-                if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ]
+                if [ -z "$SCRATCH_DEV" -o "`_is_block_dev "$SCRATCH_DEV"`" = "" ]
                 then
                     _notrun "this test requires a valid \$SCRATCH_DEV"
                 fi
-                if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
+                if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
                 then
                     _notrun "this test requires a valid \$SCRATCH_DEV"
                 fi
@@ -1179,11 +1187,11 @@ _require_test()
                fi
                ;;
        *)
-                if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ]
+                if [ -z "$TEST_DEV" ] || [ "`_is_block_dev "$TEST_DEV"`" = "" ]
                 then
                     _notrun "this test requires a valid \$TEST_DEV"
                 fi
-                if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
+                if [ "`_is_block_dev "$SCRATCH_DEV"`" = "`_is_block_dev "$TEST_DEV"`" ]
                 then
                     _notrun "this test requires a valid \$TEST_DEV"
                 fi
@@ -1299,7 +1307,7 @@ _require_command()
        fi
 
        _command=`echo "$1" | awk '{ print $1 }'`
-       if [ ! -x $command ]; then
+       if [ ! -x "$_command" ]; then
                _notrun "$_name utility required, skipped this test"
        fi
 }
@@ -1441,6 +1449,18 @@ _require_xfs_sysfs()
        fi
 }
 
+# this test requires the xfs sparse inode feature
+#
+_require_xfs_sparse_inodes()
+{
+       _scratch_mkfs_xfs_supported -m crc=1 -i sparse > /dev/null 2>&1 \
+               || _notrun "mkfs.xfs does not support sparse inodes"
+       _scratch_mkfs_xfs -m crc=1 -i sparse > /dev/null 2>&1
+       _scratch_mount >/dev/null 2>&1 \
+               || _notrun "kernel does not support sparse inodes"
+       umount $SCRATCH_MNT
+}
+
 # this test requires that external log/realtime devices are not in use
 #
 _require_nonexternal()
@@ -2282,10 +2302,10 @@ _require_scratch_dev_pool()
        esac
 
        for i in $SCRATCH_DEV_POOL; do
-               if [ "`_is_block_dev $i`" = "" ]; then
+               if [ "`_is_block_dev "$i"`" = "" ]; then
                        _notrun "this test requires valid block disk $i"
                fi
-               if [ "`_is_block_dev $i`" = "`_is_block_dev $TEST_DEV`" ]; then
+               if [ "`_is_block_dev "$i"`" = "`_is_block_dev "$TEST_DEV"`" ]; then
                        _notrun "$i is part of TEST_DEV, this test requires unique disks"
                fi
                if _mount | grep -q $i; then
@@ -2716,6 +2736,18 @@ _get_used_inode()
        echo $nr_inode
 }
 
+_get_used_inode_percent()
+{
+       if [ -z "$1" ]; then
+               echo "Usage: _get_used_inode_percent <mnt>"
+               exit 1
+       fi
+       local pct_inode;
+       pct_inode=`$DF_PROG -i $1 | tail -1 | awk '{ print $6 }' | \
+                  sed -e 's/%//'`
+       echo $pct_inode
+}
+
 _get_free_inode()
 {
        if [ -z "$1" ]; then
@@ -2727,6 +2759,19 @@ _get_free_inode()
        echo $nr_inode
 }
 
+# get the available space in bytes
+#
+_get_available_space()
+{
+       if [ -z "$1" ]; then
+               echo "Usage: _get_available_space <mnt>"
+               exit 1
+       fi
+       local avail_kb;
+       avail_kb=`$DF_PROG $1 | tail -n1 | awk '{ print $5 }'`
+       echo $((avail_kb * 1024))
+}
+
 # get btrfs profile configs being tested
 #
 # A set of pre-set profile configs are exported via _btrfs_profile_configs
@@ -2995,6 +3040,16 @@ _short_dev()
        echo `basename $(_real_dev $1)`
 }
 
+_sysfs_dev()
+{
+       local _dev=$1
+       local _maj=$(stat -c%t $_dev | tr [:lower:] [:upper:])
+       local _min=$(stat -c%T $_dev | tr [:lower:] [:upper:])
+       _maj=$(echo "ibase=16; $_maj" | bc)
+       _min=$(echo "ibase=16; $_min" | bc)
+       echo /sys/dev/block/$_maj:$_min
+}
+
 get_block_size()
 {
        if [ -z $1 ] || [ ! -d $1 ]; then