Skip to contentSkip to conversation

adjust btrfs/237 uuid heuristics and use AWK_PROG

PATCH In review Luis Chamberlain 3 participants 10 messages Feb 15, 2022 – Feb 17, 2022

lore
Share & tools
lore
#0 lore raw

v2 cover adjust btrfs/237 uuid heuristics and use AWK_PROG

This v2 makes the btrs/237 change use $AWK_PROG as requested by Johannes. But I noticed btrfs tests don't use this consistently. Let's address that by being consistent.

Luis Chamberlain (3):
btrfs/237: adjust uuid heuristics
common/btrfs: use $AWK_PROG
tests/btrfs: use $AWK_PROG instead of awk

 common/btrfs    |  6 +++---
 tests/btrfs/001 |  2 +-
 tests/btrfs/003 |  2 +-
 tests/btrfs/006 |  6 +++---
 tests/btrfs/011 |  2 +-
 tests/btrfs/022 | 12 ++++++------
 tests/btrfs/027 |  4 ++--
 tests/btrfs/035 |  4 ++--
 tests/btrfs/085 |  2 +-
 tests/btrfs/090 |  2 +-
 tests/btrfs/124 |  4 ++--
 tests/btrfs/125 |  6 +++---
 tests/btrfs/149 |  8 ++++----
 tests/btrfs/161 |  4 ++--
 tests/btrfs/162 |  6 +++---
 tests/btrfs/163 |  6 +++---
 tests/btrfs/164 |  4 ++--
 tests/btrfs/175 |  2 +-
 tests/btrfs/176 |  6 +++---
 tests/btrfs/181 |  2 +-
 tests/btrfs/184 |  2 +-
 tests/btrfs/185 |  8 ++++----
 tests/btrfs/194 |  4 ++--
 tests/btrfs/197 |  4 ++--
 tests/btrfs/198 |  4 ++--
 tests/btrfs/215 |  4 ++--
 tests/btrfs/216 |  4 ++--
 tests/btrfs/218 |  4 ++--
 tests/btrfs/237 |  9 ++++++++-
 tests/btrfs/254 |  4 ++--
 30 files changed, 72 insertions(+), 65 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/3 btrfs/237: adjust uuid heuristics

Using $(findmnt -n -o UUID mount-directory) only works on util-linux v2.38, not on 2.37. Even debian-testing has util-linux v2.37, so use a mechanism which has worked for longer to fetch the UUID.

Without this the test fails on permission failure on accessing the file /sys/fs/btrfs/"$uuid"/bg_reclaim_threshold as $uuid is empty. So while at it, add a check to ensure the UUID is never empty.

Use $AWK_PROG in case the preferred awk program is not the preferred awk program.

---
 tests/btrfs/237 | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tests/btrfs/237 +8 -1
index 5168777e..96940549 100755
@@ -41,7 +41,14 @@ zonesize=$((zonesize << 9))
 _scratch_mkfs >/dev/null 2>&1
 _scratch_mount -o commit=1 # 1s commit time to speed up test
 
-uuid=$(findmnt -n -o UUID "$SCRATCH_MNT")
+uuid=$($BTRFS_UTIL_PROG filesystem show $SCRATCH_DEV |grep uuid: |\
+        $AWK_PROG '{print $NF}')
+
+if [[ "$uuid" == "" ]]; then
+	echo "UUID for $SCRATCH_DEV is empty, this is not expected"
+	exit 1
+fi
+
 reclaim_threshold=75
 echo $reclaim_threshold > /sys/fs/btrfs/"$uuid"/bg_reclaim_threshold
 fill_percent=$((reclaim_threshold + 2))
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 2/3 common/btrfs: use $AWK_PROG

In reply to Luis Chamberlain

Use $AWK_PROG instead of just awk in case the preferred awk program is different.

---
 common/btrfs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
common/btrfs +3 -3
index 5de926dd..2fdefb18 100644
@@ -9,7 +9,7 @@ _btrfs_get_subvolid()
 	mnt=$1
 	name=$2
 
-	$BTRFS_UTIL_PROG sub list $mnt | egrep "\s$name$" | awk '{ print $2 }'
+	$BTRFS_UTIL_PROG sub list $mnt | egrep "\s$name$" | $AWK_PROG '{ print $2 }'
 }
 
 # _require_btrfs_command <command> [<subcommand>|<option>]
@@ -418,7 +418,7 @@ _run_btrfs_balance_start()
 _scratch_btrfs_sectorsize()
 {
 	$BTRFS_UTIL_PROG inspect-internal dump-super $SCRATCH_DEV |\
-		grep sectorsize | awk '{print $2}'
+		grep sectorsize | $AWK_PROG '{print $2}'
 }
 
 _btrfs_supports_forget()
@@ -460,7 +460,7 @@ _require_btrfs_sysfs_fsid()
 	local fsid
 
 	fsid=$($BTRFS_UTIL_PROG filesystem show $TEST_DIR |grep uuid: |\
-	       awk '{print $NF}')
+	       $AWK_PROG '{print $NF}')
 
 	# Check if the kernel has sysfs fsid support.
 	# Following kernel patch adds it:
Signature · 1 line
2.34.1
#7 lore raw

PATCH v2 3/3 tests/btrfs: use $AWK_PROG instead of awk

In reply to Luis Chamberlain

Use $AWK_PROG instead of awk in case the default awk program is not called awk.

---
 tests/btrfs/001 |  2 +-
 tests/btrfs/003 |  2 +-
 tests/btrfs/006 |  6 +++---
 tests/btrfs/011 |  2 +-
 tests/btrfs/022 | 12 ++++++------
 tests/btrfs/027 |  4 ++--
 tests/btrfs/035 |  4 ++--
 tests/btrfs/085 |  2 +-
 tests/btrfs/090 |  2 +-
 tests/btrfs/124 |  4 ++--
 tests/btrfs/125 |  6 +++---
 tests/btrfs/149 |  8 ++++----
 tests/btrfs/161 |  4 ++--
 tests/btrfs/162 |  6 +++---
 tests/btrfs/163 |  6 +++---
 tests/btrfs/164 |  4 ++--
 tests/btrfs/175 |  2 +-
 tests/btrfs/176 |  6 +++---
 tests/btrfs/181 |  2 +-
 tests/btrfs/184 |  2 +-
 tests/btrfs/185 |  8 ++++----
 tests/btrfs/194 |  4 ++--
 tests/btrfs/197 |  4 ++--
 tests/btrfs/198 |  4 ++--
 tests/btrfs/215 |  4 ++--
 tests/btrfs/216 |  4 ++--
 tests/btrfs/218 |  4 ++--
 tests/btrfs/254 |  4 ++--
 28 files changed, 61 insertions(+), 61 deletions(-)
tests/btrfs/001 +1 -1
index 000aeb34..6c263999 100755
@@ -66,7 +66,7 @@ ls $SCRATCH_MNT
 
 # Test listing the subvolumes
 echo "Listing subvolumes"
-$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{ print $NF }'
+$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | $AWK_PROG '{ print $NF }'
 
 # Delete the snapshot
 $BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/snap | _filter_btrfs_subvol_delete
tests/btrfs/003 +1 -1
index 0aa4c991..cf605730 100755
@@ -167,7 +167,7 @@ _test_remove()
 	_populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
 
 	# pick last dev in the list
-	dev_del=`echo ${SCRATCH_DEV_POOL} | awk '{print $NF}'`
+	dev_del=`echo ${SCRATCH_DEV_POOL} | $AWK_PROG '{print $NF}'`
 	$BTRFS_UTIL_PROG device delete $dev_del $SCRATCH_MNT || _fail "btrfs device delete failed"
 	$BTRFS_UTIL_PROG filesystem show $SCRATCH_DEV 2>&1 | grep $dev_del >> $seqres.full && _fail "btrfs still shows the deleted dev"
 	_scratch_unmount
tests/btrfs/006 +3 -3
index fd0f89e2..bff6f980 100755
@@ -20,8 +20,8 @@ _supported_fs btrfs
 _require_scratch
 _require_scratch_dev_pool
 
-FIRST_POOL_DEV=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
-LAST_POOL_DEV=`echo $SCRATCH_DEV_POOL | awk '{print $NF}'`
+FIRST_POOL_DEV=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}'`
+LAST_POOL_DEV=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`
 TOTAL_DEVS=`echo $SCRATCH_DEV_POOL | wc -w`
 LABEL=TestLabel.$seq
 
@@ -40,7 +40,7 @@ _scratch_mount
 
 echo "== Show filesystem by label"
 $BTRFS_UTIL_PROG filesystem show $LABEL | _filter_btrfs_filesystem_show $TOTAL_DEVS
-UUID=`$BTRFS_UTIL_PROG filesystem show $LABEL | grep uuid: | awk '{print $NF}'`
+UUID=`$BTRFS_UTIL_PROG filesystem show $LABEL | grep uuid: | $AWK_PROG '{print $NF}'`
 
 echo "UUID $UUID" >> $seqres.full
 
tests/btrfs/011 +1 -1
index 05ea96b9..0665e126 100755
@@ -107,7 +107,7 @@ workout()
 	local num_devs4raid="$2"
 	local with_cancel="$3"
 	local fssize="$4"
-	local source_dev="`echo ${SCRATCH_DEV_POOL} | awk '{print $1}'`"
+	local source_dev="`echo ${SCRATCH_DEV_POOL} | $AWK_PROG '{print $1}'`"
 	local quick="quick"
 
 	[[ $fssize != 64 ]] && quick="thorough"
tests/btrfs/022 +6 -6
index bfd6ac7f..e2d37b09 100755
@@ -35,12 +35,12 @@ _basic_test()
 	# the shared values of both the original subvol and snapshot should
 	# match
 	a_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid")
-	a_shared=$(echo $a_shared | awk '{ print $2 }')
+	a_shared=$(echo $a_shared | $AWK_PROG '{ print $2 }')
 	echo "subvol a id=$subvolid" >> $seqres.full
 	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
 	echo "subvol b id=$subvolid" >> $seqres.full
 	b_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid")
-	b_shared=$(echo $b_shared | awk '{ print $2 }')
+	b_shared=$(echo $b_shared | $AWK_PROG '{ print $2 }')
 	$BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT >> $seqres.full
 	[ $b_shared -eq $a_shared ] || _fail "shared values don't match"
 }
@@ -59,14 +59,14 @@ _rescan_test()
 	sync
 	output=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid")
 	echo "qgroup values before rescan: $output" >> $seqres.full
-	refer=$(echo $output | awk '{ print $2 }')
-	excl=$(echo $output | awk '{ print $3 }')
+	refer=$(echo $output | $AWK_PROG '{ print $2 }')
+	excl=$(echo $output | $AWK_PROG '{ print $3 }')
 	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
 	output=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid")
 	echo "qgroup values after rescan: $output" >> $seqres.full
-	[ $refer -eq $(echo $output | awk '{ print $2 }') ] || \
+	[ $refer -eq $(echo $output | $AWK_PROG '{ print $2 }') ] || \
 		_fail "reference values don't match after rescan"
-	[ $excl -eq $(echo $output | awk '{ print $3 }') ] || \
+	[ $excl -eq $(echo $output | $AWK_PROG '{ print $3 }') ] || \
 		_fail "exclusive values don't match after rescan"
 }
 
tests/btrfs/027 +2 -2
index e8679248..46c14b9c 100755
@@ -45,8 +45,8 @@ run_test()
 	fi
 	_scratch_mount >>$seqres.full 2>&1
 
-	local missing_dev=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
-	local missing_dev_id=`$BTRFS_UTIL_PROG filesystem show $SCRATCH_MNT | grep $missing_dev | awk '{print $2}'`
+	local missing_dev=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}'`
+	local missing_dev_id=`$BTRFS_UTIL_PROG filesystem show $SCRATCH_MNT | grep $missing_dev | $AWK_PROG '{print $2}'`
 
 	# get some data on the filesystem so there's something to replace
 	_ddt of="$SCRATCH_MNT"/file1 bs=1M count=1 >> $seqres.full 2>&1
tests/btrfs/035 +2 -2
index 4ddc5bf6..7e644ecf 100755
@@ -33,7 +33,7 @@ echo -n "$src_str" > $SCRATCH_MNT/src
 
 $CLONER_PROG $SCRATCH_MNT/src $SCRATCH_MNT/src.clone2
 
-snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone1 | awk '{print $5}'`
+snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone1 | $AWK_PROG '{print $5}'`
 echo "attempting ioctl (src.clone1 src)"
 $CLONER_PROG -s 0 -d 0 -l ${snap_src_sz} \
 	$SCRATCH_MNT/src.clone1 $SCRATCH_MNT/src | _filter_btrfs_cloner_error
@@ -48,7 +48,7 @@ $CLONER_PROG -s 0 -d 0 -l ${snap_src_sz} \
 echo "File src data after attempt to clone from src.clone1 into src:"
 od -t x1 $SCRATCH_MNT/src
 
-snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone2 | awk '{print $5}'`
+snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone2 | $AWK_PROG '{print $5}'`
 echo "attempting ioctl (src.clone2 src)"
 $CLONER_PROG -s 0 -d 0 -l ${snap_src_sz} \
 	$SCRATCH_MNT/src.clone2 $SCRATCH_MNT/src
tests/btrfs/085 +1 -1
index cef4da28..bcbf1a05 100755
@@ -112,7 +112,7 @@ new_subvolume()
 new_default()
 {
 	new_subvolume
-	SUB=$($BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT |awk '{print $2}')
+	SUB=$($BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | $AWK_PROG '{print $2}')
 	_run_btrfs_util_prog subvolume set-default $SUB $SCRATCH_MNT
 
 	_unmount_flakey
tests/btrfs/090 +1 -1
index 766c24cd..3693a3ad 100755
@@ -26,7 +26,7 @@ _supported_fs btrfs
 _require_scratch
 _require_scratch_dev_pool
 
-FIRST_POOL_DEV=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
+FIRST_POOL_DEV=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}'`
 TOTAL_DEVS=`echo $SCRATCH_DEV_POOL | wc -w`
 
 _scratch_pool_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
tests/btrfs/124 +2 -2
index 8771a3c1..e8d77aaa 100755
@@ -45,8 +45,8 @@ _require_btrfs_forget_or_module_loadable
 
 _scratch_dev_pool_get 2
 
-dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
-dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
+dev1=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}'`
+dev2=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}'`
 
 # RAID1 is not supported on zoned btrfs
 _require_non_zoned_device "$dev1"
tests/btrfs/125 +3 -3
index b6a28f5c..44ba49ec 100755
@@ -45,9 +45,9 @@ _require_btrfs_fs_feature raid56
 
 _scratch_dev_pool_get 3
 
-dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
-dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
-dev3=`echo $SCRATCH_DEV_POOL | awk '{print $3}'`
+dev1=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}'`
+dev2=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}'`
+dev3=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $3}'`
 
 echo dev1=$dev1 >> $seqres.full
 echo dev2=$dev2 >> $seqres.full
tests/btrfs/149 +4 -4
index 176d8ec5..d6dce45d 100755
@@ -75,8 +75,8 @@ $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
 		 $SCRATCH_MNT/mysnap2 2>&1 >/dev/null | _filter_scratch
 
-sum_src_snap1=$(md5sum $SCRATCH_MNT/mysnap1/foobar | awk '{print $1}')
-sum_src_snap2=$(md5sum $SCRATCH_MNT/mysnap2/foobar | awk '{print $1}')
+sum_src_snap1=$(md5sum $SCRATCH_MNT/mysnap1/foobar | $AWK_PROG '{print $1}')
+sum_src_snap2=$(md5sum $SCRATCH_MNT/mysnap2/foobar | $AWK_PROG '{print $1}')
 echo "File digests in the original filesystem:" >> $seqres.full
 echo "md5sum $SCRATCH_MNT/mysnap1/foobar " $sum_src_snap1 >> $seqres.full
 echo "md5sum $SCRATCH_MNT/mysnap2/foobar " $sum_src_snap2 >> $seqres.full
@@ -90,8 +90,8 @@ _scratch_mount "-o compress"
 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
 
-sum_dest_snap1=$(md5sum $SCRATCH_MNT/mysnap1/foobar | awk '{print $1}')
-sum_dest_snap2=$(md5sum $SCRATCH_MNT/mysnap2/foobar | awk '{print $1}')
+sum_dest_snap1=$(md5sum $SCRATCH_MNT/mysnap1/foobar | $AWK_PROG '{print $1}')
+sum_dest_snap2=$(md5sum $SCRATCH_MNT/mysnap2/foobar | $AWK_PROG '{print $1}')
 echo "File digests in the new filesystem:" | tee -a $seqres.full
 echo "md5sum $SCRATCH_MNT/mysnap1/foobar " $sum_src_snap1 >> $seqres.full
 echo "md5sum $SCRATCH_MNT/mysnap2/foobar " $sum_src_snap2 >> $seqres.full
tests/btrfs/161 +2 -2
index ed5b67fa..5aac8fe9 100755
@@ -23,8 +23,8 @@ _require_scratch_dev_pool 2
 
 _scratch_dev_pool_get 2
 
-dev_seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-dev_sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+dev_seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+dev_sprout=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 
 create_seed()
 {
tests/btrfs/162 +3 -3
index 7680e1e4..1d8dbf95 100755
@@ -25,9 +25,9 @@ _require_scratch_dev_pool 3
 
 _scratch_dev_pool_get 3
 
-dev_seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-dev_sprout_seed=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
-dev_sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $3}')
+dev_seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+dev_sprout_seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
+dev_sprout=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $3}')
 
 create_seed()
 {
tests/btrfs/163 +3 -3
index 59f0461b..c2a04791 100755
@@ -38,9 +38,9 @@ _require_btrfs_forget_or_module_loadable
 
 _scratch_dev_pool_get 3
 
-dev_seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-dev_sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
-dev_replace_tgt=$(echo $SCRATCH_DEV_POOL | awk '{print $3}')
+dev_seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+dev_sprout=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
+dev_replace_tgt=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $3}')
 
 create_seed()
 {
tests/btrfs/164 +2 -2
index 8fd6ab62..43c55c16 100755
@@ -29,8 +29,8 @@ _require_scratch_dev_pool 2
 
 _scratch_dev_pool_get 2
 
-dev_seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-dev_sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+dev_seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+dev_sprout=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 
 create_seed()
 {
tests/btrfs/175 +1 -1
index dc6c1921..db877d41 100755
@@ -48,7 +48,7 @@ _scratch_mount
 # Create the swap file, then add the device. That way we know it's all on one
 # device.
 _format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10)) > /dev/null
-scratch_dev2="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $2 }')"
+scratch_dev2="$(echo "${SCRATCH_DEV_POOL}" | $AWK_PROG '{ print $2 }')"
 $BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT" >> $seqres.full
 swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
 swapoff "$SCRATCH_MNT/swap" > /dev/null 2>&1
tests/btrfs/176 +3 -3
index 33f9a061..7080d860 100755
@@ -22,9 +22,9 @@ _require_scratch_swapfile
 # We check the filesystem manually because we move devices around.
 rm -f "${RESULT_DIR}/require_scratch"
 
-scratch_dev1="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $1 }')"
-scratch_dev2="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $2 }')"
-scratch_dev3="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $3 }')"
+scratch_dev1="$(echo "${SCRATCH_DEV_POOL}" | $AWK_PROG '{ print $1 }')"
+scratch_dev2="$(echo "${SCRATCH_DEV_POOL}" | $AWK_PROG '{ print $2 }')"
+scratch_dev3="$(echo "${SCRATCH_DEV_POOL}" | $AWK_PROG '{ print $3 }')"
 
 echo "Remove device"
 _scratch_mkfs >> $seqres.full 2>&1
tests/btrfs/181 +1 -1
index 843413fc..8a3c3c17 100755
@@ -32,7 +32,7 @@ nr_files=1024
 get_super_gen()
 {
 	local ret=$($BTRFS_UTIL_PROG inspect dump-super "$SCRATCH_DEV" |\
-		grep ^generation | awk '{print $2}')
+		grep ^generation | $AWK_PROG '{print $2}')
 	if [ -z $ret ]; then
 		_fail "failed to get super block generation"
 	fi
tests/btrfs/184 +1 -1
index 2efcfb64..ee43a8d3 100755
@@ -27,7 +27,7 @@ _scratch_pool_mkfs "-d raid0 -m raid0" >> $seqres.full 2>&1 || _fail "mkfs faile
 _scratch_mount
 
 # pick last dev in the list
-dev_del=`echo ${SCRATCH_DEV_POOL} | awk '{print $NF}'`
+dev_del=`echo ${SCRATCH_DEV_POOL} | $AWK_PROG '{print $NF}'`
 $BTRFS_UTIL_PROG device delete $dev_del $SCRATCH_MNT || _fail "btrfs device delete failed"
 for i in {0..2}; do
 	output=$($BTRFS_UTIL_PROG inspect-internal dump-super -s $i $dev_del 2>&1)
tests/btrfs/185 +4 -4
index 7850f1bc..ee97b626 100755
@@ -28,8 +28,8 @@ _supported_fs btrfs
 _require_scratch_dev_pool 2
 _scratch_dev_pool_get 2
 
-device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+device_1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+device_2=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 
 echo device_1=$device_1 device_2=$device_2 >> $seqres.full
 
@@ -38,7 +38,7 @@ mkdir $mnt
 _mkfs_dev $device_1
 _mount $device_1 $mnt
 
-[[ $(findmnt $mnt | grep -v TARGET | awk '{print $2}') != $device_1 ]] && \
+[[ $(findmnt $mnt | grep -v TARGET | $AWK_PROG '{print $2}') != $device_1 ]] && \
 						_fail "mounted device changed"
 
 for sb_bytenr in 65536 67108864; do
@@ -53,7 +53,7 @@ done
 $BTRFS_UTIL_PROG device scan $device_2 >> $seqres.full 2>&1
 [[ $? != 1 ]] && _fail "cloned device scan should fail"
 
-[[ $(findmnt $mnt | grep -v TARGET | awk '{print $2}') != $device_1 ]] && \
+[[ $(findmnt $mnt | grep -v TARGET | $AWK_PROG '{print $2}') != $device_1 ]] && \
 						_fail "mounted device changed"
 
 # Original device scan should be successful
tests/btrfs/194 +2 -2
index 2431692b..228576e4 100755
@@ -29,8 +29,8 @@ if [ $(get_page_size) != 4096 ]; then
 	_notrun "This test need 4k page size"
 fi
 
-device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+device_1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+device_2=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 
 echo device_1=$device_1 device_2=$device_2 >> $seqres.full
 
tests/btrfs/197 +2 -2
index 22b37b4b..d259fd99 100755
@@ -54,11 +54,11 @@ workout()
 
 	# don't test with the first device as auto fs check (_check_scratch_fs)
 	# picks the first device
-	device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+	device_1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 	$BTRFS_UTIL_PROG device add -f "$device_1" "$TEST_DIR/$seq.mnt" >> \
 		$seqres.full
 
-	device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+	device_2=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
 	_mount -o degraded $device_2 $SCRATCH_MNT
 	# Check if missing device is reported as in the .out
 	$BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
tests/btrfs/198 +2 -2
index 035c63fd..1edc8330 100755
@@ -39,10 +39,10 @@ workout()
 
 	# don't test with the first device as auto fs check (_check_scratch_fs)
 	# picks the first device
-	device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+	device_1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 	$WIPEFS_PROG -a $device_1 >> $seqres.full 2>&1
 
-	device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+	device_2=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
 	_mount -o degraded $device_2 $SCRATCH_MNT
 	# Check if missing device is reported as in the 196.out
 	$BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
tests/btrfs/215 +2 -2
index 9ee1a8b3..cbcd60e0 100755
@@ -72,14 +72,14 @@ echo 0 > /sys/fs/btrfs/$uuid/bdi/read_ahead_kb
 # buffered reads whould result in 2 * sectors_per_page errors since readahead code always submits
 # at least 1 page worth of IO and it will be counted as error(s) as well
 $XFS_IO_PROG -c "pread -b $filesize 0 $filesize" "$SCRATCH_MNT/foobar" > /dev/null 2>&1
-errs=$($BTRFS_UTIL_PROG device stats $SCRATCH_DEV | awk '/corruption_errs/ { print $2 }')
+errs=$($BTRFS_UTIL_PROG device stats $SCRATCH_DEV | $AWK_PROG '/corruption_errs/ { print $2 }')
 if [ $errs -ne $((2 * $sectors_per_page)) ]; then
 	_fail "Errors: $errs expected: 2"
 fi
 
 # DIO does check every sector
 $XFS_IO_PROG -d -c "pread -b $filesize 0 $filesize" "$SCRATCH_MNT/foobar" > /dev/null 2>&1
-errs=$($BTRFS_UTIL_PROG device stats $SCRATCH_DEV | awk '/corruption_errs/ { print $2 }')
+errs=$($BTRFS_UTIL_PROG device stats $SCRATCH_DEV | $AWK_PROG '/corruption_errs/ { print $2 }')
 if [ $errs -ne $((6 * $sectors_per_page)) ]; then
 	_fail "Errors: $errs expected: 6"
 fi
tests/btrfs/216 +2 -2
index 5d6cf902..2ed48668 100755
@@ -21,8 +21,8 @@ _require_scratch_dev_pool 2
 
 _scratch_dev_pool_get 2
 
-seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+sprout=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 
 _mkfs_dev $seed
 $BTRFS_TUNE_PROG -S 1 $seed
tests/btrfs/218 +2 -2
index 83ec785e..672ad0ff 100755
@@ -27,8 +27,8 @@ _require_scratch_dev_pool 2
 
 _scratch_dev_pool_get 2
 
-dev_seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-dev_sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+dev_seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+dev_sprout=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 
 # Create the seed device
 _mkfs_dev $dev_seed
tests/btrfs/254 +2 -2
index 2f3ae50f..5d6e33f4 100755
@@ -81,8 +81,8 @@ test_add_device()
 {
 	setup_dmdev
 	dmdev=$(realpath $lvdev)
-	scratch_dev2=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
-	scratch_dev3=$(echo $SCRATCH_DEV_POOL | awk '{print $3}')
+	scratch_dev2=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
+	scratch_dev3=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $3}')
 
 	_mkfs_dev $scratch_dev3
 	_mount $scratch_dev3 $seq_mnt
Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH v2 3/3] tests/btrfs: use $AWK_PROG instead of awk

In reply to Luis Chamberlain
Quoted 529 lines · Luis Chamberlain

Use $AWK_PROG instead of awk in case the default awk program is not called awk.

---
 tests/btrfs/001 |  2 +-
 tests/btrfs/003 |  2 +-
 tests/btrfs/006 |  6 +++---
 tests/btrfs/011 |  2 +-
 tests/btrfs/022 | 12 ++++++------
 tests/btrfs/027 |  4 ++--
 tests/btrfs/035 |  4 ++--
 tests/btrfs/085 |  2 +-
 tests/btrfs/090 |  2 +-
 tests/btrfs/124 |  4 ++--
 tests/btrfs/125 |  6 +++---
 tests/btrfs/149 |  8 ++++----
 tests/btrfs/161 |  4 ++--
 tests/btrfs/162 |  6 +++---
 tests/btrfs/163 |  6 +++---
 tests/btrfs/164 |  4 ++--
 tests/btrfs/175 |  2 +-
 tests/btrfs/176 |  6 +++---
 tests/btrfs/181 |  2 +-
 tests/btrfs/184 |  2 +-
 tests/btrfs/185 |  8 ++++----
 tests/btrfs/194 |  4 ++--
 tests/btrfs/197 |  4 ++--
 tests/btrfs/198 |  4 ++--
 tests/btrfs/215 |  4 ++--
 tests/btrfs/216 |  4 ++--
 tests/btrfs/218 |  4 ++--
 tests/btrfs/254 |  4 ++--
 28 files changed, 61 insertions(+), 61 deletions(-)
tests/btrfs/001 +1 -1
index 000aeb34..6c263999 100755
@@ -66,7 +66,7 @@ ls $SCRATCH_MNT
 
 # Test listing the subvolumes
 echo "Listing subvolumes"
-$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{ print $NF }'
+$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | $AWK_PROG '{ print $NF }'
 
 # Delete the snapshot
 $BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/snap | _filter_btrfs_subvol_delete
tests/btrfs/003 +1 -1
index 0aa4c991..cf605730 100755
@@ -167,7 +167,7 @@ _test_remove()
 	_populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10
 
 	# pick last dev in the list
-	dev_del=`echo ${SCRATCH_DEV_POOL} | awk '{print $NF}'`
+	dev_del=`echo ${SCRATCH_DEV_POOL} | $AWK_PROG '{print $NF}'`
 	$BTRFS_UTIL_PROG device delete $dev_del $SCRATCH_MNT || _fail "btrfs device delete failed"
 	$BTRFS_UTIL_PROG filesystem show $SCRATCH_DEV 2>&1 | grep $dev_del >> $seqres.full && _fail "btrfs still shows the deleted dev"
 	_scratch_unmount
tests/btrfs/006 +3 -3
index fd0f89e2..bff6f980 100755
@@ -20,8 +20,8 @@ _supported_fs btrfs
 _require_scratch
 _require_scratch_dev_pool
 
-FIRST_POOL_DEV=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
-LAST_POOL_DEV=`echo $SCRATCH_DEV_POOL | awk '{print $NF}'`
+FIRST_POOL_DEV=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}'`
+LAST_POOL_DEV=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $NF}'`
 TOTAL_DEVS=`echo $SCRATCH_DEV_POOL | wc -w`
 LABEL=TestLabel.$seq
 
@@ -40,7 +40,7 @@ _scratch_mount
 
 echo "== Show filesystem by label"
 $BTRFS_UTIL_PROG filesystem show $LABEL | _filter_btrfs_filesystem_show $TOTAL_DEVS
-UUID=`$BTRFS_UTIL_PROG filesystem show $LABEL | grep uuid: | awk '{print $NF}'`
+UUID=`$BTRFS_UTIL_PROG filesystem show $LABEL | grep uuid: | $AWK_PROG '{print $NF}'`
 
 echo "UUID $UUID" >> $seqres.full
 
tests/btrfs/011 +1 -1
index 05ea96b9..0665e126 100755
@@ -107,7 +107,7 @@ workout()
 	local num_devs4raid="$2"
 	local with_cancel="$3"
 	local fssize="$4"
-	local source_dev="`echo ${SCRATCH_DEV_POOL} | awk '{print $1}'`"
+	local source_dev="`echo ${SCRATCH_DEV_POOL} | $AWK_PROG '{print $1}'`"
 	local quick="quick"
 
 	[[ $fssize != 64 ]] && quick="thorough"
tests/btrfs/022 +6 -6
index bfd6ac7f..e2d37b09 100755
@@ -35,12 +35,12 @@ _basic_test()
 	# the shared values of both the original subvol and snapshot should
 	# match
 	a_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid")
-	a_shared=$(echo $a_shared | awk '{ print $2 }')
+	a_shared=$(echo $a_shared | $AWK_PROG '{ print $2 }')
 	echo "subvol a id=$subvolid" >> $seqres.full
 	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
 	echo "subvol b id=$subvolid" >> $seqres.full
 	b_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid")
-	b_shared=$(echo $b_shared | awk '{ print $2 }')
+	b_shared=$(echo $b_shared | $AWK_PROG '{ print $2 }')
 	$BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT >> $seqres.full
 	[ $b_shared -eq $a_shared ] || _fail "shared values don't match"
 }
@@ -59,14 +59,14 @@ _rescan_test()
 	sync
 	output=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid")
 	echo "qgroup values before rescan: $output" >> $seqres.full
-	refer=$(echo $output | awk '{ print $2 }')
-	excl=$(echo $output | awk '{ print $3 }')
+	refer=$(echo $output | $AWK_PROG '{ print $2 }')
+	excl=$(echo $output | $AWK_PROG '{ print $3 }')
 	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
 	output=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid")
 	echo "qgroup values after rescan: $output" >> $seqres.full
-	[ $refer -eq $(echo $output | awk '{ print $2 }') ] || \
+	[ $refer -eq $(echo $output | $AWK_PROG '{ print $2 }') ] || \
 		_fail "reference values don't match after rescan"
-	[ $excl -eq $(echo $output | awk '{ print $3 }') ] || \
+	[ $excl -eq $(echo $output | $AWK_PROG '{ print $3 }') ] || \
 		_fail "exclusive values don't match after rescan"
 }
 
tests/btrfs/027 +2 -2
index e8679248..46c14b9c 100755
@@ -45,8 +45,8 @@ run_test()
 	fi
 	_scratch_mount >>$seqres.full 2>&1
 
-	local missing_dev=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
-	local missing_dev_id=`$BTRFS_UTIL_PROG filesystem show $SCRATCH_MNT | grep $missing_dev | awk '{print $2}'`
+	local missing_dev=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}'`
+	local missing_dev_id=`$BTRFS_UTIL_PROG filesystem show $SCRATCH_MNT | grep $missing_dev | $AWK_PROG '{print $2}'`
 
 	# get some data on the filesystem so there's something to replace
 	_ddt of="$SCRATCH_MNT"/file1 bs=1M count=1 >> $seqres.full 2>&1
tests/btrfs/035 +2 -2
index 4ddc5bf6..7e644ecf 100755
@@ -33,7 +33,7 @@ echo -n "$src_str" > $SCRATCH_MNT/src
 
 $CLONER_PROG $SCRATCH_MNT/src $SCRATCH_MNT/src.clone2
 
-snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone1 | awk '{print $5}'`
+snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone1 | $AWK_PROG '{print $5}'`
 echo "attempting ioctl (src.clone1 src)"
 $CLONER_PROG -s 0 -d 0 -l ${snap_src_sz} \
 	$SCRATCH_MNT/src.clone1 $SCRATCH_MNT/src | _filter_btrfs_cloner_error
@@ -48,7 +48,7 @@ $CLONER_PROG -s 0 -d 0 -l ${snap_src_sz} \
 echo "File src data after attempt to clone from src.clone1 into src:"
 od -t x1 $SCRATCH_MNT/src
 
-snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone2 | awk '{print $5}'`
+snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone2 | $AWK_PROG '{print $5}'`
 echo "attempting ioctl (src.clone2 src)"
 $CLONER_PROG -s 0 -d 0 -l ${snap_src_sz} \
 	$SCRATCH_MNT/src.clone2 $SCRATCH_MNT/src
tests/btrfs/085 +1 -1
index cef4da28..bcbf1a05 100755
@@ -112,7 +112,7 @@ new_subvolume()
 new_default()
 {
 	new_subvolume
-	SUB=$($BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT |awk '{print $2}')
+	SUB=$($BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | $AWK_PROG '{print $2}')
 	_run_btrfs_util_prog subvolume set-default $SUB $SCRATCH_MNT
 
 	_unmount_flakey
tests/btrfs/090 +1 -1
index 766c24cd..3693a3ad 100755
@@ -26,7 +26,7 @@ _supported_fs btrfs
 _require_scratch
 _require_scratch_dev_pool
 
-FIRST_POOL_DEV=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
+FIRST_POOL_DEV=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}'`
 TOTAL_DEVS=`echo $SCRATCH_DEV_POOL | wc -w`
 
 _scratch_pool_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
tests/btrfs/124 +2 -2
index 8771a3c1..e8d77aaa 100755
@@ -45,8 +45,8 @@ _require_btrfs_forget_or_module_loadable
 
 _scratch_dev_pool_get 2
 
-dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
-dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
+dev1=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}'`
+dev2=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}'`
 
 # RAID1 is not supported on zoned btrfs
 _require_non_zoned_device "$dev1"
tests/btrfs/125 +3 -3
index b6a28f5c..44ba49ec 100755
@@ -45,9 +45,9 @@ _require_btrfs_fs_feature raid56
 
 _scratch_dev_pool_get 3
 
-dev1=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
-dev2=`echo $SCRATCH_DEV_POOL | awk '{print $2}'`
-dev3=`echo $SCRATCH_DEV_POOL | awk '{print $3}'`
+dev1=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}'`
+dev2=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}'`
+dev3=`echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $3}'`
 
 echo dev1=$dev1 >> $seqres.full
 echo dev2=$dev2 >> $seqres.full
tests/btrfs/149 +4 -4
index 176d8ec5..d6dce45d 100755
@@ -75,8 +75,8 @@ $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
 		 $SCRATCH_MNT/mysnap2 2>&1 >/dev/null | _filter_scratch
 
-sum_src_snap1=$(md5sum $SCRATCH_MNT/mysnap1/foobar | awk '{print $1}')
-sum_src_snap2=$(md5sum $SCRATCH_MNT/mysnap2/foobar | awk '{print $1}')
+sum_src_snap1=$(md5sum $SCRATCH_MNT/mysnap1/foobar | $AWK_PROG '{print $1}')
+sum_src_snap2=$(md5sum $SCRATCH_MNT/mysnap2/foobar | $AWK_PROG '{print $1}')
 echo "File digests in the original filesystem:" >> $seqres.full
 echo "md5sum $SCRATCH_MNT/mysnap1/foobar " $sum_src_snap1 >> $seqres.full
 echo "md5sum $SCRATCH_MNT/mysnap2/foobar " $sum_src_snap2 >> $seqres.full
@@ -90,8 +90,8 @@ _scratch_mount "-o compress"
 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
 
-sum_dest_snap1=$(md5sum $SCRATCH_MNT/mysnap1/foobar | awk '{print $1}')
-sum_dest_snap2=$(md5sum $SCRATCH_MNT/mysnap2/foobar | awk '{print $1}')
+sum_dest_snap1=$(md5sum $SCRATCH_MNT/mysnap1/foobar | $AWK_PROG '{print $1}')
+sum_dest_snap2=$(md5sum $SCRATCH_MNT/mysnap2/foobar | $AWK_PROG '{print $1}')
 echo "File digests in the new filesystem:" | tee -a $seqres.full
 echo "md5sum $SCRATCH_MNT/mysnap1/foobar " $sum_src_snap1 >> $seqres.full
 echo "md5sum $SCRATCH_MNT/mysnap2/foobar " $sum_src_snap2 >> $seqres.full
tests/btrfs/161 +2 -2
index ed5b67fa..5aac8fe9 100755
@@ -23,8 +23,8 @@ _require_scratch_dev_pool 2
 
 _scratch_dev_pool_get 2
 
-dev_seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-dev_sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+dev_seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+dev_sprout=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 
 create_seed()
 {
tests/btrfs/162 +3 -3
index 7680e1e4..1d8dbf95 100755
@@ -25,9 +25,9 @@ _require_scratch_dev_pool 3
 
 _scratch_dev_pool_get 3
 
-dev_seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-dev_sprout_seed=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
-dev_sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $3}')
+dev_seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+dev_sprout_seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
+dev_sprout=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $3}')
 
 create_seed()
 {
tests/btrfs/163 +3 -3
index 59f0461b..c2a04791 100755
@@ -38,9 +38,9 @@ _require_btrfs_forget_or_module_loadable
 
 _scratch_dev_pool_get 3
 
-dev_seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-dev_sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
-dev_replace_tgt=$(echo $SCRATCH_DEV_POOL | awk '{print $3}')
+dev_seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+dev_sprout=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
+dev_replace_tgt=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $3}')
 
 create_seed()
 {
tests/btrfs/164 +2 -2
index 8fd6ab62..43c55c16 100755
@@ -29,8 +29,8 @@ _require_scratch_dev_pool 2
 
 _scratch_dev_pool_get 2
 
-dev_seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-dev_sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+dev_seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+dev_sprout=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 
 create_seed()
 {
tests/btrfs/175 +1 -1
index dc6c1921..db877d41 100755
@@ -48,7 +48,7 @@ _scratch_mount
 # Create the swap file, then add the device. That way we know it's all on one
 # device.
 _format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10)) > /dev/null
-scratch_dev2="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $2 }')"
+scratch_dev2="$(echo "${SCRATCH_DEV_POOL}" | $AWK_PROG '{ print $2 }')"
 $BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT" >> $seqres.full
 swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
 swapoff "$SCRATCH_MNT/swap" > /dev/null 2>&1
tests/btrfs/176 +3 -3
index 33f9a061..7080d860 100755
@@ -22,9 +22,9 @@ _require_scratch_swapfile
 # We check the filesystem manually because we move devices around.
 rm -f "${RESULT_DIR}/require_scratch"
 
-scratch_dev1="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $1 }')"
-scratch_dev2="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $2 }')"
-scratch_dev3="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $3 }')"
+scratch_dev1="$(echo "${SCRATCH_DEV_POOL}" | $AWK_PROG '{ print $1 }')"
+scratch_dev2="$(echo "${SCRATCH_DEV_POOL}" | $AWK_PROG '{ print $2 }')"
+scratch_dev3="$(echo "${SCRATCH_DEV_POOL}" | $AWK_PROG '{ print $3 }')"
 
 echo "Remove device"
 _scratch_mkfs >> $seqres.full 2>&1
tests/btrfs/181 +1 -1
index 843413fc..8a3c3c17 100755
@@ -32,7 +32,7 @@ nr_files=1024
 get_super_gen()
 {
 	local ret=$($BTRFS_UTIL_PROG inspect dump-super "$SCRATCH_DEV" |\
-		grep ^generation | awk '{print $2}')
+		grep ^generation | $AWK_PROG '{print $2}')
 	if [ -z $ret ]; then
 		_fail "failed to get super block generation"
 	fi
tests/btrfs/184 +1 -1
index 2efcfb64..ee43a8d3 100755
@@ -27,7 +27,7 @@ _scratch_pool_mkfs "-d raid0 -m raid0" >> $seqres.full 2>&1 || _fail "mkfs faile
 _scratch_mount
 
 # pick last dev in the list
-dev_del=`echo ${SCRATCH_DEV_POOL} | awk '{print $NF}'`
+dev_del=`echo ${SCRATCH_DEV_POOL} | $AWK_PROG '{print $NF}'`
 $BTRFS_UTIL_PROG device delete $dev_del $SCRATCH_MNT || _fail "btrfs device delete failed"
 for i in {0..2}; do
 	output=$($BTRFS_UTIL_PROG inspect-internal dump-super -s $i $dev_del 2>&1)
tests/btrfs/185 +4 -4
index 7850f1bc..ee97b626 100755
@@ -28,8 +28,8 @@ _supported_fs btrfs
 _require_scratch_dev_pool 2
 _scratch_dev_pool_get 2
 
-device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+device_1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+device_2=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 
 echo device_1=$device_1 device_2=$device_2 >> $seqres.full
 
@@ -38,7 +38,7 @@ mkdir $mnt
 _mkfs_dev $device_1
 _mount $device_1 $mnt
 
-[[ $(findmnt $mnt | grep -v TARGET | awk '{print $2}') != $device_1 ]] && \
+[[ $(findmnt $mnt | grep -v TARGET | $AWK_PROG '{print $2}') != $device_1 ]] && \
 						_fail "mounted device changed"
 
 for sb_bytenr in 65536 67108864; do
@@ -53,7 +53,7 @@ done
 $BTRFS_UTIL_PROG device scan $device_2 >> $seqres.full 2>&1
 [[ $? != 1 ]] && _fail "cloned device scan should fail"
 
-[[ $(findmnt $mnt | grep -v TARGET | awk '{print $2}') != $device_1 ]] && \
+[[ $(findmnt $mnt | grep -v TARGET | $AWK_PROG '{print $2}') != $device_1 ]] && \
 						_fail "mounted device changed"
 
 # Original device scan should be successful
tests/btrfs/194 +2 -2
index 2431692b..228576e4 100755
@@ -29,8 +29,8 @@ if [ $(get_page_size) != 4096 ]; then
 	_notrun "This test need 4k page size"
 fi
 
-device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+device_1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+device_2=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 
 echo device_1=$device_1 device_2=$device_2 >> $seqres.full
 
tests/btrfs/197 +2 -2
index 22b37b4b..d259fd99 100755
@@ -54,11 +54,11 @@ workout()
 
 	# don't test with the first device as auto fs check (_check_scratch_fs)
 	# picks the first device
-	device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+	device_1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 	$BTRFS_UTIL_PROG device add -f "$device_1" "$TEST_DIR/$seq.mnt" >> \
 		$seqres.full
 
-	device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+	device_2=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
 	_mount -o degraded $device_2 $SCRATCH_MNT
 	# Check if missing device is reported as in the .out
 	$BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
tests/btrfs/198 +2 -2
index 035c63fd..1edc8330 100755
@@ -39,10 +39,10 @@ workout()
 
 	# don't test with the first device as auto fs check (_check_scratch_fs)
 	# picks the first device
-	device_1=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+	device_1=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 	$WIPEFS_PROG -a $device_1 >> $seqres.full 2>&1
 
-	device_2=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
+	device_2=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
 	_mount -o degraded $device_2 $SCRATCH_MNT
 	# Check if missing device is reported as in the 196.out
 	$BTRFS_UTIL_PROG filesystem show -m $SCRATCH_MNT | \
tests/btrfs/215 +2 -2
index 9ee1a8b3..cbcd60e0 100755
@@ -72,14 +72,14 @@ echo 0 > /sys/fs/btrfs/$uuid/bdi/read_ahead_kb
 # buffered reads whould result in 2 * sectors_per_page errors since readahead code always submits
 # at least 1 page worth of IO and it will be counted as error(s) as well
 $XFS_IO_PROG -c "pread -b $filesize 0 $filesize" "$SCRATCH_MNT/foobar" > /dev/null 2>&1
-errs=$($BTRFS_UTIL_PROG device stats $SCRATCH_DEV | awk '/corruption_errs/ { print $2 }')
+errs=$($BTRFS_UTIL_PROG device stats $SCRATCH_DEV | $AWK_PROG '/corruption_errs/ { print $2 }')
 if [ $errs -ne $((2 * $sectors_per_page)) ]; then
 	_fail "Errors: $errs expected: 2"
 fi
 
 # DIO does check every sector
 $XFS_IO_PROG -d -c "pread -b $filesize 0 $filesize" "$SCRATCH_MNT/foobar" > /dev/null 2>&1
-errs=$($BTRFS_UTIL_PROG device stats $SCRATCH_DEV | awk '/corruption_errs/ { print $2 }')
+errs=$($BTRFS_UTIL_PROG device stats $SCRATCH_DEV | $AWK_PROG '/corruption_errs/ { print $2 }')
 if [ $errs -ne $((6 * $sectors_per_page)) ]; then
 	_fail "Errors: $errs expected: 6"
 fi
tests/btrfs/216 +2 -2
index 5d6cf902..2ed48668 100755
@@ -21,8 +21,8 @@ _require_scratch_dev_pool 2
 
 _scratch_dev_pool_get 2
 
-seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+sprout=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 
 _mkfs_dev $seed
 $BTRFS_TUNE_PROG -S 1 $seed
tests/btrfs/218 +2 -2
index 83ec785e..672ad0ff 100755
@@ -27,8 +27,8 @@ _require_scratch_dev_pool 2
 
 _scratch_dev_pool_get 2
 
-dev_seed=$(echo $SCRATCH_DEV_POOL | awk '{print $1}')
-dev_sprout=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
+dev_seed=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $1}')
+dev_sprout=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
 
 # Create the seed device
 _mkfs_dev $dev_seed
tests/btrfs/254 +2 -2
index 2f3ae50f..5d6e33f4 100755
@@ -81,8 +81,8 @@ test_add_device()
 {
 	setup_dmdev
 	dmdev=$(realpath $lvdev)
-	scratch_dev2=$(echo $SCRATCH_DEV_POOL | awk '{print $2}')
-	scratch_dev3=$(echo $SCRATCH_DEV_POOL | awk '{print $3}')
+	scratch_dev2=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $2}')
+	scratch_dev3=$(echo $SCRATCH_DEV_POOL | $AWK_PROG '{print $3}')
 
 	_mkfs_dev $scratch_dev3
 	_mount $scratch_dev3 $seq_mnt
Signature · 1 line
2.34.1

Looks good.

Reviewed by: Adam Manzanares <[email protected]>

#6 lore raw

Re: [PATCH v2 2/3] common/btrfs: use $AWK_PROG

In reply to Luis Chamberlain
Quoted 42 lines · Luis Chamberlain

Use $AWK_PROG instead of just awk in case the preferred awk program is different.

---
 common/btrfs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
common/btrfs +3 -3
index 5de926dd..2fdefb18 100644
@@ -9,7 +9,7 @@ _btrfs_get_subvolid()
 	mnt=$1
 	name=$2
 
-	$BTRFS_UTIL_PROG sub list $mnt | egrep "\s$name$" | awk '{ print $2 }'
+	$BTRFS_UTIL_PROG sub list $mnt | egrep "\s$name$" | $AWK_PROG '{ print $2 }'
 }
 
 # _require_btrfs_command <command> [<subcommand>|<option>]
@@ -418,7 +418,7 @@ _run_btrfs_balance_start()
 _scratch_btrfs_sectorsize()
 {
 	$BTRFS_UTIL_PROG inspect-internal dump-super $SCRATCH_DEV |\
-		grep sectorsize | awk '{print $2}'
+		grep sectorsize | $AWK_PROG '{print $2}'
 }
 
 _btrfs_supports_forget()
@@ -460,7 +460,7 @@ _require_btrfs_sysfs_fsid()
 	local fsid
 
 	fsid=$($BTRFS_UTIL_PROG filesystem show $TEST_DIR |grep uuid: |\
-	       awk '{print $NF}')
+	       $AWK_PROG '{print $NF}')
 
 	# Check if the kernel has sysfs fsid support.
 	# Following kernel patch adds it:
Signature · 1 line
2.34.1

Looks good.

Reviewed by: Adam Manzanares <[email protected]>

#3 lore raw

Re: [PATCH v2 1/3] btrfs/237: adjust uuid heuristics

In reply to Luis Chamberlain
Quoted 43 lines · Luis Chamberlain

Using $(findmnt -n -o UUID mount-directory) only works on util-linux v2.38, not on 2.37. Even debian-testing has util-linux v2.37, so use a mechanism which has worked for longer to fetch the UUID.

Without this the test fails on permission failure on accessing the file /sys/fs/btrfs/"$uuid"/bg_reclaim_threshold as $uuid is empty. So while at it, add a check to ensure the UUID is never empty.

Use $AWK_PROG in case the preferred awk program is not the preferred awk program.

---
 tests/btrfs/237 | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tests/btrfs/237 +8 -1
index 5168777e..96940549 100755
@@ -41,7 +41,14 @@ zonesize=$((zonesize << 9))
 _scratch_mkfs >/dev/null 2>&1
 _scratch_mount -o commit=1 # 1s commit time to speed up test
 
-uuid=$(findmnt -n -o UUID "$SCRATCH_MNT")
+uuid=$($BTRFS_UTIL_PROG filesystem show $SCRATCH_DEV |grep uuid: |\
+        $AWK_PROG '{print $NF}')
+
+if [[ "$uuid" == "" ]]; then
+	echo "UUID for $SCRATCH_DEV is empty, this is not expected"
+	exit 1
+fi
+
 reclaim_threshold=75
 echo $reclaim_threshold > /sys/fs/btrfs/"$uuid"/bg_reclaim_threshold
 fill_percent=$((reclaim_threshold + 2))
Signature · 1 line
2.34.1

Looks good.

Tested by: Adam Manzanares <[email protected]>