]> www.infradead.org Git - users/hch/xfstests-dev.git/commitdiff
btrfs/237: Use zone cap instead of zone size in fill_size and rest calculation
authorPankaj Raghav <p.raghav@samsung.com>
Fri, 25 Mar 2022 10:19:08 +0000 (11:19 +0100)
committerEryu Guan <guaneryu@gmail.com>
Sun, 10 Apr 2022 15:39:16 +0000 (23:39 +0800)
This test will break when zone capacity != zone size because the
calculation of the size to be filled is done using zone_size instead
of the actual capacity available per zone. Fix it by using zone
capacity.

As a zoned device can have variable capacity, use the btrfs utility
to get the zone capacity from the first data block group that the
test will be performed on.

The support to extract zone capacity was added to blkzone only from
version 2.37. So zcap will be used only when the blkzone version is
greater or equal to 2.37.

Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
common/filter
tests/btrfs/237

index 257227c2b1e9d8e0c215c211b66639b9eb805037..5fe86756ef6ed11444c0ddce416daa0b5aa637ab 100644 (file)
@@ -634,5 +634,18 @@ _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
index 96940549ea0061c77ce2e0e1dc2bb879fe8c4e08..f96031d51d8bda5da7f4d9c175336e678199ceba 100755 (executable)
@@ -35,8 +35,13 @@ get_data_bg()
                grep -Eo "CHUNK_ITEM [[:digit:]]+" | cut -d ' ' -f 2
 }
 
-zonesize=$(cat /sys/block/$(_short_dev $SCRATCH_DEV)/queue/chunk_sectors)
-zonesize=$((zonesize << 9))
+get_data_bg_physical()
+{
+       # Assumes SINGLE data profile
+       $BTRFS_UTIL_PROG inspect-internal dump-tree -t CHUNK $SCRATCH_DEV |\
+               grep -A 4 CHUNK_ITEM | grep -A 3 'type DATA\|SINGLE' |\
+               grep -Eo 'offset [[:digit:]]+'| cut -d ' ' -f 2
+}
 
 _scratch_mkfs >/dev/null 2>&1
 _scratch_mount -o commit=1 # 1s commit time to speed up test
@@ -49,12 +54,20 @@ if [[ "$uuid" == "" ]]; then
        exit 1
 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))
+
 reclaim_threshold=75
 echo $reclaim_threshold > /sys/fs/btrfs/"$uuid"/bg_reclaim_threshold
 fill_percent=$((reclaim_threshold + 2))
 rest_percent=$((90 - fill_percent)) # make sure we're not creating a new BG
-fill_size=$((zonesize * fill_percent / 100))
-rest=$((zonesize * rest_percent / 100))
+fill_size=$((size * fill_percent / 100))
+rest=$((size * rest_percent / 100))
 
 # step 1, fill FS over $fillsize
 $XFS_IO_PROG -fc "pwrite 0 $fill_size" $SCRATCH_MNT/$seq.test1 >> $seqres.full