btrfs/177: Handle the different fi resize output formats
authorMarcos Paulo de Souza <mpdesouza@suse.com>
Thu, 12 Aug 2021 11:30:48 +0000 (08:30 -0300)
committerEryu Guan <guaneryu@gmail.com>
Sun, 15 Aug 2021 10:52:04 +0000 (18:52 +0800)
Commit 78aa1d95dd99 ("btrfs-progs: fi resize: make output more
readable") added the device id of the resized fs along with a pretty
printed size. Create a new function to simplify the output message
using size in bytes.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/btrfs/177
tests/btrfs/177.out

index 966d29d72cb718f400511052760e7188c0953e71..b20502368bd269ea322b09720584acde16c7a98b 100755 (executable)
@@ -16,6 +16,32 @@ _begin_fstest auto quick swap balance
 _supported_fs btrfs
 _require_scratch_swapfile
 
+# Eliminate the differences between the old and new output formats
+# Old format:
+#      Resize 'SCRATCH_MNT' of '1073741824'
+# New format:
+#      Resize device id 1 (SCRATCH_DEV) from 3.00GiB to 1.00GiB
+# Convert both outputs to:
+#      Resized to 1073741824
+convert_resize_output()
+{
+        local _field
+        local _val
+        local _suffix
+        _field=`$AWK_PROG '{print $NF}' | tr -d "'"`
+        # remove trailing zeroes
+        _val=`echo $_field | $AWK_PROG '{print $1 * 1}'`
+        # get the first unit char, for example return G in case we have GiB
+        _suffix=`echo $_field | grep -o "[GMB]"`
+        if [ -z "$_suffix" ]; then
+                _suffix="B"
+        fi
+        _val=`echo "$_val$_suffix" | _filter_size_to_bytes`
+       echo "Resized to $_val"
+}
+
+
+
 swapfile="$SCRATCH_MNT/swap"
 
 _require_scratch_size $((3 * 1024 * 1024)) #kB
@@ -36,8 +62,7 @@ dd if=/dev/zero of="$SCRATCH_MNT/refill" bs=4096 >> $seqres.full 2>&1
 # Now add more space and create a swap file. We know that the first $fssize
 # of the filesystem was used, so the swap file must be in the new part of the
 # filesystem.
-$BTRFS_UTIL_PROG filesystem resize $((3 * fssize)) "$SCRATCH_MNT" | \
-                                                       _filter_scratch
+$BTRFS_UTIL_PROG filesystem resize $((3 * fssize)) "$SCRATCH_MNT" | convert_resize_output
 _format_swapfile "$swapfile" $((32 * 1024 * 1024))
 swapon "$swapfile"
 
@@ -55,7 +80,7 @@ $BTRFS_UTIL_PROG filesystem resize 1G "$SCRATCH_MNT" 2>&1 | grep -o "Text file b
 swapoff "$swapfile"
 
 # It should work again after swapoff.
-$BTRFS_UTIL_PROG filesystem resize $fssize "$SCRATCH_MNT" | _filter_scratch
+$BTRFS_UTIL_PROG filesystem resize $fssize "$SCRATCH_MNT" | convert_resize_output
 
 status=0
 exit
index 63aca0e5362dd45be69e7776d9d94c6d10a4a7a2..eb374d345671ec97b615ca4837b45fc72754aa98 100644 (file)
@@ -1,4 +1,4 @@
 QA output created by 177
-Resize 'SCRATCH_MNT' of '3221225472'
+Resized to 3221225472
 Text file busy
-Resize 'SCRATCH_MNT' of '1073741824'
+Resized to 1073741824