public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcos Paulo de Souza <mpdesouza@suse.com>
To: linux-btrfs@vger.kernel.org, fstests@vger.kernel.org
Cc: dsterba@suse.com, guaneryu@gmail.com, wqu@suse.com,
	Marcos Paulo de Souza <mpdesouza@suse.com>
Subject: [PATCH v3] btrfs/177: Add filesystem resize filter
Date: Wed, 11 Aug 2021 11:49:03 -0300	[thread overview]
Message-ID: <20210811144903.1425-1-mpdesouza@suse.com> (raw)

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 filter to simplify the output message using
size in bytes.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---

 Changes since v2:
 * Check the output to verify if the resize really happened (Qu)

 Changes since v1:
 * Do not adapt the output message to the newer format (Qu)

 common/filter.btrfs | 24 ++++++++++++++++++++++++
 tests/btrfs/177     |  8 +++++---
 tests/btrfs/177.out |  4 ++--
 3 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/common/filter.btrfs b/common/filter.btrfs
index d4169cc6..fd422e08 100644
--- a/common/filter.btrfs
+++ b/common/filter.btrfs
@@ -72,6 +72,30 @@ _filter_btrfs_compress_property()
 	sed -e "s/compression=\(lzo\|zlib\|zstd\)/COMPRESSION=XXX/g"
 }
 
+# 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
+_filter_btrfs_filesystem_resize()
+{
+        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"
+}
+
 # filter error messages from btrfs prop, optionally verify against $1
 # recognized message(s):
 #  "object is not compatible with property: label"
diff --git a/tests/btrfs/177 b/tests/btrfs/177
index 966d29d7..ff241bed 100755
--- a/tests/btrfs/177
+++ b/tests/btrfs/177
@@ -10,6 +10,7 @@
 _begin_fstest auto quick swap balance
 
 . ./common/filter
+. ./common/filter.btrfs
 . ./common/btrfs
 
 # Modify as appropriate.
@@ -36,8 +37,8 @@ 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" |
+						_filter_btrfs_filesystem_resize
 _format_swapfile "$swapfile" $((32 * 1024 * 1024))
 swapon "$swapfile"
 
@@ -55,7 +56,8 @@ $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" |
+						_filter_btrfs_filesystem_resize
 
 status=0
 exit
diff --git a/tests/btrfs/177.out b/tests/btrfs/177.out
index 63aca0e5..eb374d34 100644
--- a/tests/btrfs/177.out
+++ b/tests/btrfs/177.out
@@ -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
-- 
2.31.1


             reply	other threads:[~2021-08-11 14:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-11 14:49 Marcos Paulo de Souza [this message]
2021-08-12  5:57 ` [PATCH v3] btrfs/177: Add filesystem resize filter Qu Wenruo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210811144903.1425-1-mpdesouza@suse.com \
    --to=mpdesouza@suse.com \
    --cc=dsterba@suse.com \
    --cc=fstests@vger.kernel.org \
    --cc=guaneryu@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox