]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
common: introduce zone_capacity() to return a zone capacity
authorNaohiro Aota <naohiro.aota@wdc.com>
Wed, 5 Oct 2022 05:46:43 +0000 (14:46 +0900)
committerZorro Lang <zlang@kernel.org>
Sat, 8 Oct 2022 11:20:25 +0000 (19:20 +0800)
Introduce _zone_capacity() to return a zone capacity of the given address
in the given device (optional). Move _filter_blkzone_report() for it, and
rewrite btrfs/237 with it.

Reviewed-by: Zorro Lang <zlang@redhat.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
common/filter
common/zoned [new file with mode: 0644]
tests/btrfs/237

index 6433a30e53c2defb3cef96e56dce8c929228891c..3e3fea7ea02eda622f0b4c5c8f10753315c39602 100644 (file)
@@ -651,18 +651,5 @@ _filter_bash()
        sed -e "s/^bash: line 1: /bash: /"
 }
 
-#
-# blkzone report added zone capacity to be printed from v2.37.
-# This filter will add an extra column 'cap' with the same value of
-# 'len'(zone size) for blkzone version < 2.37
-#
-# Before: start: 0x000100000, len 0x040000, wptr 0x000000 ..
-# After: start: 0x000100000, len 0x040000, cap 0x040000, wptr 0x000000 ..
-_filter_blkzone_report()
-{
-       $AWK_PROG -F "," 'BEGIN{OFS=",";} $3 !~ /cap/ {$2=$2","$2;} {print;}' |\
-       sed -e 's/len/cap/2'
-}
-
 # make sure this script returns success
 /bin/true
diff --git a/common/zoned b/common/zoned
new file mode 100644 (file)
index 0000000..d1bc60f
--- /dev/null
@@ -0,0 +1,28 @@
+#
+# Common zoned block device specific functions
+#
+
+#
+# blkzone report added zone capacity to be printed from v2.37.
+# This filter will add an extra column 'cap' with the same value of
+# 'len'(zone size) for blkzone version < 2.37
+#
+# Before: start: 0x000100000, len 0x040000, wptr 0x000000 ..
+# After: start: 0x000100000, len 0x040000, cap 0x040000, wptr 0x000000 ..
+_filter_blkzone_report()
+{
+       $AWK_PROG -F "," 'BEGIN{OFS=",";} $3 !~ /cap/ {$2=$2","$2;} {print;}' |\
+       sed -e 's/len/cap/2'
+}
+
+_zone_capacity() {
+    local phy=$1
+    local dev=$2
+
+    [ -z "$dev" ] && dev=$SCRATCH_DEV
+
+    size=$($BLKZONE_PROG report -o $phy -l 1 $dev |\
+              _filter_blkzone_report |\
+              grep -Po "cap 0x[[:xdigit:]]+" | cut -d ' ' -f 2)
+    echo $((size << 9))
+}
index f96031d51d8bda5da7f4d9c175336e678199ceba..3c660edbe27d3b281e75f3188cd6fbe75a50984d 100755 (executable)
@@ -13,7 +13,7 @@
 _begin_fstest auto quick zone balance
 
 # Import common functions.
-. ./common/filter
+. ./common/zoned
 
 # real QA test starts here
 
@@ -56,11 +56,7 @@ fi
 
 start_data_bg_phy=$(get_data_bg_physical)
 start_data_bg_phy=$((start_data_bg_phy >> 9))
-
-size=$($BLKZONE_PROG report -o $start_data_bg_phy -l 1 $SCRATCH_DEV |\
-       _filter_blkzone_report |\
-       grep -Po "cap 0x[[:xdigit:]]+" | cut -d ' ' -f 2)
-size=$((size << 9))
+size=$(_zone_capacity $start_data_bg_phy)
 
 reclaim_threshold=75
 echo $reclaim_threshold > /sys/fs/btrfs/"$uuid"/bg_reclaim_threshold