btrfs-progs: tests: update or fix shell script coding style

Fix the following issues in the test suite:

- lack of quoting for variables
- declare function variables local when missing (prevent accidental
  overwrite of global variables)
- for variables with underscore in the name use plain "$VAR_NAME"
  instead of { } (unless necessary)
- minor style adjustments like moving quotes to the end of the same
  string

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2024-06-13 01:39:06 +02:00
parent 859d78e5a7
commit 9957162313
38 changed files with 112 additions and 92 deletions

View File

@ -20,7 +20,7 @@ _mktemp_local img2 1G
run_check $SUDO_HELPER mkdir -p "$TEST_MNT"/mnt2
run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=10 of="$TEST_MNT"/mnt2/hiddenfile
run_check $SUDO_HELPER "$TOP"/mkfs.btrfs -f img2
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f img2
run_check $SUDO_HELPER mount -o loop img2 "$TEST_MNT"/mnt2
run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=10 of="$TEST_MNT"/mnt2/file21
run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=10 of="$TEST_MNT"/mnt2/file22

View File

@ -63,14 +63,14 @@ test_raid1()
set -- $i
IFS=$OLDIFS
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d$1 ${loopdevs[@]}
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d"$1" ${loopdevs[@]}
run_check_mount_test_dev
vars=($(report_numbers))
data_chunk_size=${vars[1]}
used_on_dev=${vars[2]}
data_ratio=${vars[0]}
[[ $used_on_dev -eq $data_chunk_size ]] ||
[[ "$used_on_dev" -eq "$data_chunk_size" ]] ||
_fail "$1 inconsistent chunk/device usage. Chunk: $data_chunk_size Device: $used_on_dev"
[[ "$data_ratio" = "$2" ]] ||
@ -95,10 +95,10 @@ test_raid0()
data_ratio=${vars[0]}
# Divide by 4 since 4 loopp devices are setup
[[ $used_on_dev -eq $(($data_chunk_size / 4)) ]] ||
[[ "$used_on_dev" -eq $(($data_chunk_size / 4)) ]] ||
_fail "raid0 inconsistent chunk/device usage. Chunk: $data_chunk_size Device: $used_on_dev"
[[ $data_ratio = "1.00" ]] ||
[[ "$data_ratio" = "1.00" ]] ||
_fail "raid0: Unexpected data ratio: $data_ratio (must be 1.5)"
run_check_umount_test_dev
}
@ -118,17 +118,17 @@ test_raid56()
set -- $i
IFS=$OLDIFS
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d$1 ${loopdevs[@]}
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d"$1" ${loopdevs[@]}
run_check_mount_test_dev
vars=($(report_numbers))
data_chunk_size=${vars[1]}
used_on_dev=${vars[2]}
data_ratio=${vars[0]}
[[ $used_on_dev -eq $(($data_chunk_size / $3)) ]] ||
[[ "$used_on_dev" -eq $(($data_chunk_size / $3)) ]] ||
_fail "$i inconsistent chunk/device usage. Chunk: $data_chunk_size Device: $used_on_dev"
[[ $data_ratio = "$2" ]] ||
[[ "$data_ratio" = "$2" ]] ||
_fail "$1: Unexpected data ratio: $data_ratio (must be $2)"
run_check_umount_test_dev

View File

@ -21,7 +21,7 @@ run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d raid1 "${loopdevs[@]}"
run_check $SUDO_HELPER mv "$dev2" /dev/loop-non-existent
cond_wait_for_loopdevs
run_check $SUDO_HELPER mount -o degraded $dev1 $TEST_MNT
run_check $SUDO_HELPER mount -o degraded "$dev1" "$TEST_MNT"
if ! run_check_stdout $SUDO_HELPER "$TOP/btrfs" filesystem show "$TEST_MNT" | \
grep -q -e "devid[[:space:]]\+2.*MISSING"; then

View File

@ -739,9 +739,9 @@ _get_subvolid()
DATASET_SIZE=50
generate_dataset() {
local dataset_type="$1"
local dirpath="$TEST_MNT/$dataset_type"
dataset_type="$1"
dirpath=$TEST_MNT/$dataset_type
run_check $SUDO_HELPER mkdir -p "$dirpath"
case "$dataset_type" in
@ -843,7 +843,7 @@ setup_loopdevs()
# create all loop devices from a given loopdev environment
prepare_loopdevs()
{
for i in `seq $nloopdevs`; do
for i in `seq "$nloopdevs"`; do
touch "$loopdev_prefix$i"
chmod a+rw "$loopdev_prefix$i"
truncate -s0 "$loopdev_prefix$i"
@ -921,14 +921,14 @@ prepare_nullbdevs()
# Record any other pre-existing devices in case creation fails
run_check $SUDO_HELPER "$nullb" ls
for i in `seq ${nullb_count}`; do
for i in `seq "$nullb_count"`; do
# Last line has the name of the device node path
out=$(run_check_stdout $SUDO_HELPER "$nullb" create -s "${nullb_size}" -z "${nullb_zone_size}")
out=$(run_check_stdout $SUDO_HELPER "$nullb" create -s "$nullb_size" -z "$nullb_zone_size")
if [ $? != 0 ]; then
_fail "cannot create nullb zoned device $i"
fi
dev=$(echo "$out" | tail -n 1)
nullb_devs[$i]=${dev}
nullb_devs[$i]="$dev"
done
run_check $SUDO_HELPER "$nullb" ls

View File

@ -63,7 +63,7 @@ do_test() {
convert_test_post_check_checksums "$CHECKSUMTMP"
run_check_umount_test_dev
rm "$CHECKSUMTMP"
rm -- "$CHECKSUMTMP"
}
# Iterate over defaults and options that are not tied to hardware capabilities

View File

@ -29,7 +29,7 @@ fi
# Now fill the underlying range with non-zeros.
# For properly converted fs, we should not read the contents anyway
run_check $SUDO_HELPER dd if=/dev/urandom of=$TEST_DEV bs=4096 seek="$physical" conv=notrunc count=8
run_check $SUDO_HELPER dd if=/dev/urandom of="$TEST_DEV" bs=4096 seek="$physical" conv=notrunc count=8
# Write some thing into the file range.
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file" bs=4096 count=1 conv=notrunc

View File

@ -48,11 +48,14 @@ generate_leaf_corrupt_no_data_ext()
check_inode()
{
path=$1
ino=$2
size=$3
mode=$4
name=$5
local path=$1
local ino=$2
local size=$3
local mode=$4
local name=$5
local exists
local found_mode
local found_size
# Check whether the inode exists
exists=$($SUDO_HELPER find "$path" -inum "$ino")
@ -84,11 +87,13 @@ check_inode()
# Check salvaged data in the recovered image
check_leaf_corrupt_no_data_ext()
{
image=$1
local image=$1
local i
$SUDO_HELPER mount -o loop -t btrfs "$image" -o ro "$TEST_MNT"
i=0
while [ $i -lt ${#leaf_no_data_ext_list[@]} ]; do
while [ "$i" -lt ${#leaf_no_data_ext_list[@]} ]; do
check_inode "$TEST_MNT/lost+found" \
${leaf_no_data_ext_list[i]} \
${leaf_no_data_ext_list[i + 1]} \

View File

@ -23,7 +23,7 @@ sync
# Remove file 1 3 5 to create holes
for i in 1 3 5; do
run_check $SUDO_HELPER rm "$TEST_MNT/file_${i}"
run_check $SUDO_HELPER rm "$TEST_MNT/file_$i"
done
sync

View File

@ -27,7 +27,7 @@ corrupt_fst_item()
local offset
type="$1"
if [[ $type == "bitmap" ]]; then
if [[ "$type" == "bitmap" ]]; then
type=200
objectid=$("$TOP/btrfs" inspect-internal dump-tree -t 10 "$TEST_DEV" | \
grep -o "[[:digit:]]* FREE_SPACE_BITMAP [[:digit:]]*" | \
@ -40,7 +40,7 @@ corrupt_fst_item()
return 1
fi
_log "Corrupting $objectid,FREE_SPACE_BITMAP,$offset"
elif [[ $type == "extent" ]]; then
elif [[ "$type" == "extent" ]]; then
type=199
objectid=$("$TOP/btrfs" inspect-internal dump-tree -t 10 "$TEST_DEV" | \
grep -o "[[:digit:]]* FREE_SPACE_EXTENT [[:digit:]]*" | \

View File

@ -20,17 +20,17 @@ dev3=${loopdevs[3]}
# Run 1: victim is dev1
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -m raid5 -d raid5 "${loopdevs[@]}"
run_check $SUDO_HELPER wipefs -fa $dev1
run_check $SUDO_HELPER "$TOP/btrfs" check $dev2
run_check $SUDO_HELPER wipefs -fa "$dev1"
run_check $SUDO_HELPER "$TOP/btrfs" check "$dev2"
# Run 2: victim is dev2
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -m raid5 -d raid5 "${loopdevs[@]}"
run_check $SUDO_HELPER wipefs -fa $dev2
run_check $SUDO_HELPER "$TOP/btrfs" check $dev3
run_check $SUDO_HELPER wipefs -fa "$dev2"
run_check $SUDO_HELPER "$TOP/btrfs" check "$dev3"
# Run 3: victim is dev3
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -m raid5 -d raid5 "${loopdevs[@]}"
run_check $SUDO_HELPER wipefs -fa $dev3
run_check $SUDO_HELPER "$TOP/btrfs" check $dev1
run_check $SUDO_HELPER wipefs -fa "$dev3"
run_check $SUDO_HELPER "$TOP/btrfs" check "$dev1"
cleanup_loopdevs

View File

@ -13,7 +13,7 @@ setup_root_helper
check_image() {
local image
image=$1
image="$1"
run_mayfail $TOP/btrfs check -s 1 "$image"
run_mayfail $TOP/btrfs check --force --init-csum-tree "$image"
run_mayfail $TOP/btrfs check --repair --force --init-extent-tree "$image"

View File

@ -10,7 +10,7 @@ setup_root_helper
check_image() {
local image
image=$1
image="$1"
run_mayfail "$TOP/btrfs" inspect-internal dump-super "$image"
run_mayfail "$TOP/btrfs" inspect-internal dump-super -Ffa "$image"
}

View File

@ -16,6 +16,6 @@ check_image() {
rm -- "$image".scratch
}
check_all_images $TEST_TOP/fuzz-tests/images
check_all_images "$TEST_TOP/fuzz-tests/images"
exit 0

View File

@ -10,7 +10,7 @@ setup_root_helper
check_image() {
local image
image=$1
image="$1"
run_check cp "$image" "$image".scratch
run_mayfail "$TOP/btrfs" rescue chunk-recover -y -v "$image".scratch
rm -- "$image".scratch

View File

@ -10,7 +10,7 @@ setup_root_helper
check_image() {
local image
image=$1
image="$1"
run_check cp "$image" "$image".scratch
run_mayfail "$TOP/btrfs" rescue zero-log "$image".scratch
rm -- "$image".scratch

View File

@ -17,6 +17,7 @@ get_fs_uuid() {
test_uuid_random()
{
local origuuid
local currentfsid
origuuid=11111111-a101-4031-b29a-379d4f8b7a2d
@ -37,6 +38,7 @@ test_uuid_user()
{
local origuuid
local newuuid
local fsid
origuuid=22222222-d324-4f92-80e9-7658bf3b845f
newuuid=33333333-bfc9-4045-9399-a396dc6893b3

View File

@ -19,6 +19,9 @@ get_log_root_level() {
test_zero_log()
{
local log_root
local log_root_level
# FIXME: we need an image with existing log_root
run_check_mkfs_test_dev --rootdir "$INTERNAL_BIN/Documentation"
run_check "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV"

View File

@ -18,11 +18,11 @@ run_check $SUDO_HELPER chmod a+rw "$TEST_MNT"
cd "$TEST_MNT"
for i in `seq 5`; do
run_check dd if=/dev/zero of=file$i bs=1M count=10
run_check dd if=/dev/zero of="file$i" bs=1M count=10
done
for sn in `seq 4`;do
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot . snap$sn
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot . "snap$sn"
for i in `seq 10`; do
run_check dd if=/dev/zero of="snap$sn/file$i" bs=1M count=10
done

View File

@ -26,6 +26,8 @@ test_wipefs()
}
test_delete_missing()
{
local out
run_check_mount_test_dev -o degraded
run_check $SUDO_HELPER "$TOP/btrfs" filesystem show "$TEST_MNT"
run_check $SUDO_HELPER "$TOP/btrfs" device delete missing "$TEST_MNT"
@ -33,7 +35,6 @@ test_delete_missing()
run_check_umount_test_dev
run_check_mount_test_dev
local out
out=$(run_check_stdout $SUDO_HELPER "$TOP/btrfs" filesystem show "$TEST_MNT")
if echo "$out" | grep -q -- "$devtodel"; then
_fail "device $devtodel not deleted"

View File

@ -18,12 +18,12 @@ run_check $SUDO_HELPER chmod a+rw "$TEST_MNT"
cd "$TEST_MNT"
for i in `seq 5`; do
run_check dd if=/dev/zero of=file$i bs=1M count=10
run_check dd if=/dev/zero of="file$i" bs=1M count=10
done
# 128 is minimum
for sn in `seq 130`;do
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot . snap$sn
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot . "snap$sn"
for i in `seq 10`; do
run_check dd if=/dev/zero of="snap$sn/file$i" bs=1M count=1
done

View File

@ -19,14 +19,14 @@ cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT"
run_check $SUDO_HELPER "$TOP/btrfs" subvolume create subv-parent1
for i in 1 2 3; do
run_check $SUDO_HELPER dd if=/dev/zero of=subv-parent1/file1_$i bs=1M count=1
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv-parent1 subv-snap1_$i
run_check $SUDO_HELPER dd if=/dev/zero of="subv-parent1/file1_$i" bs=1M count=1
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv-parent1 "subv-snap1_$i"
done
run_check $SUDO_HELPER "$TOP/btrfs" subvolume create subv-parent2
for i in 1 2 3; do
run_check $SUDO_HELPER dd if=/dev/zero of=subv-parent2/file2_$i bs=1M count=1
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv-parent2 subv-snap2_$i
run_check $SUDO_HELPER dd if=/dev/zero of="subv-parent2/file2_$i" bs=1M count=1
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv-parent2 "subv-snap2_$i"
done
_mktemp_local "$here/send-stream.img"

View File

@ -52,7 +52,7 @@ test_full_simple_stream() {
run_check $SUDO_HELPER "$TOP/btrfs" subvolume create subv1
for i in 1 2 3; do
run_check $SUDO_HELPER dd if=/dev/zero of=subv1/file1_$i bs=1M count=1
run_check $SUDO_HELPER dd if=/dev/zero of="subv1/file1_$i" bs=1M count=1
done
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv1 subv1-snap
@ -104,7 +104,8 @@ test_incr_empty_stream() {
}
test_incr_simple_stream() {
local str
local fstr
local istr
fstr="$here/stream-full-simple.stream"
istr="$here/stream-incr-simple.stream"
@ -115,13 +116,13 @@ test_incr_simple_stream() {
run_check $SUDO_HELPER "$TOP/btrfs" subvolume create subv1
for i in 1 2 3; do
run_check $SUDO_HELPER dd if=/dev/zero of=subv1/file1_$i bs=1M count=1
run_check $SUDO_HELPER dd if=/dev/zero of="subv1/file1_$i" bs=1M count=1
done
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv1 subv1-snap
for i in 1 2 3; do
run_check $SUDO_HELPER dd if=/dev/urandom of=subv1/file1_$i bs=1M count=1
run_check $SUDO_HELPER dd if=/dev/urandom of="subv1/file1_$i" bs=1M count=1
done
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv1 subv2-snap

View File

@ -14,6 +14,8 @@ FIRST_SUPERBLOCK_OFFSET=65536
test_superblock_restore()
{
local seek
run_check_mkfs_test_dev
# Corrupt superblock checksum

View File

@ -13,8 +13,8 @@ prepare_test_dev 260G
run_check_mkfs_test_dev
check_corruption() {
local sb_offset=$1
local source_sb=$2
local sb_offset="$1"
local source_sb="$2"
# First we ensure we can mount it successfully
run_check_mount_test_dev
@ -37,7 +37,7 @@ check_corruption() {
# Now run btrfs rescue which should fix the superblock. It uses 2
# to signal success of recovery use mayfail to ignore that retval
# but still log the output of the command
run_mayfail $SUDO_HELPER "$TOP"/btrfs rescue super-recover -yv "$TEST_DEV"
run_mayfail $SUDO_HELPER "$TOP/btrfs" rescue super-recover -yv "$TEST_DEV"
if [ $? != 2 ]; then
_fail "couldn't rescue super"
fi

View File

@ -24,7 +24,7 @@ test_missing()
local good_num
local good_dev
bad_num=$1
bad_num="$1"
bad_dev=${loopdevs[$bad_num]}
good_num=$((3 - $bad_num))
good_dev=${loopdevs[$good_num]}

View File

@ -43,13 +43,11 @@ read_metadata_uuid() {
echo $(run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal \
dump-super "$dev" | awk '/metadata_uuid/ {print $2}')
else
read_fsid $dev
read_fsid "$dev"
fi
}
check_btrfstune() {
local fsid
_log "Checking btrfstune logic"
# test with random uuid
run_check $SUDO_HELPER "$TOP/btrfstune" -m "$TEST_DEV"
@ -89,17 +87,16 @@ check_dump_super_output() {
# assert that metadata/fsid match on non-changed fs
fsid=$(read_fsid "$TEST_DEV")
metadata_uuid=$(read_metadata_uuid "$TEST_DEV")
[ "$fsid" = "$metadata_uuid" ] || _fail "fsid ("$fsid") doesn't match metadata_uuid ("$metadata_uuid")"
[ "$fsid" = "$metadata_uuid" ] || _fail "fsid ($fsid) doesn't match metadata_uuid ($metadata_uuid)"
dev_item_match=$(run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super \
"$TEST_DEV" | awk '/dev_item.fsid/ {print $3}')
[ $dev_item_match = "[match]" ] || _fail "dev_item.fsid doesn't match on non-metadata uuid fs"
[ "$dev_item_match" = "[match]" ] || _fail "dev_item.fsid doesn't match on non-metadata uuid fs"
_log "Checking output after fsid change"
# change metadatauuid and ensure everything in the output is still correct
old_metadata_uuid=$metadata_uuid
old_metadata_uuid="$metadata_uuid"
run_check $SUDO_HELPER "$TOP/btrfstune" -M d88c8333-a652-4476-b225-2e9284eb59f1 "$TEST_DEV"
fsid=$(read_fsid "$TEST_DEV")
metadata_uuid=$(read_metadata_uuid "$TEST_DEV")

View File

@ -68,5 +68,5 @@ _log "After the backup usage:"
_log "$(dump_super)"
if [ "$main_root_ptr" -ne "$backup_new_root_ptr" ]; then
_fail "Backup ${slot_num} not overwritten"
_fail "Backup $slot_num not overwritten"
fi

View File

@ -22,9 +22,9 @@ run_check_mkfs_test_dev -L BTRFS-TESTS-SEED
run_check_mount_test_dev
for i in `seq 6`; do
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file${i}" bs=1M count=1 status=none
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file$i" bs=1M count=1 status=none
# Something to distinguish the contents
run_check md5sum "$TEST_MNT/file${i}"
run_check md5sum "$TEST_MNT/file$i"
done
run_check_umount_test_dev
@ -34,6 +34,9 @@ TEST_DEV=${loopdevs[1]}
nextdevice() {
local nextdev
local mnt
local md5sum
local md5sum2
nextdev="$1"
# Mount again, as seeding device

View File

@ -22,7 +22,8 @@ here=`pwd`
# assumes the filesystem exists, and does mount, write, snapshot, send, unmount
# for the specified encoding option
send_one() {
local str
local algorithm
local file
local subv
local snap

View File

@ -13,9 +13,9 @@ count=24
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT"/file bs=1M count=1
run_check $SUDO_HELPER "$TOP/btrfs" quota enable "$TEST_MNT"
for i in `seq $count`; do
run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/subv${i}"
run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/subv$i"
if [ "$(($i % 2))" = "0" ]; then
run_check $SUDO_HELPER "$TOP/btrfs" subvolume delete "$TEST_MNT/subv${i}"
run_check $SUDO_HELPER "$TOP/btrfs" subvolume delete "$TEST_MNT/subv$i"
fi
done
run_check $SUDO_HELPER "$TOP/btrfs" qgroup show --sort path "$TEST_MNT"

View File

@ -15,29 +15,29 @@ run_check "$TOP/btrfs" check "$image"
# Check for FREE_INO items for toplevel subvol
item_count=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t fs "$image" |
grep -c 'item [0-9].* key (FREE_INO')
[ $item_count -eq 0 ] || _fail "FREE_INO items for toplevel subvolume present"
[ "$item_count" -eq 0 ] || _fail "FREE_INO items for toplevel subvolume present"
# Check for bitmap item for toplevel subvol
item_count=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t fs "$image" |
grep -c '(FREE_SPACE')
[ $item_count -eq 0 ] || _fail "FREE_SPACE items for toplevel subvolume present"
[ "$item_count" -eq 0 ] || _fail "FREE_SPACE items for toplevel subvolume present"
# Check for FREE_INO items for subvolume
item_count=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t 256 "$image" |
grep -c 'item [0-9].* key (FREE_INO')
[ $item_count -eq 0 ] || _fail "ino cache items for subvolume present"
[ "$item_count" -eq 0 ] || _fail "ino cache items for subvolume present"
# Check for bitmap item for subvolume
item_count=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t 256 "$image" |
grep -c '(FREE_SPACE')
[ $item_count -eq 0 ] || _fail "FREE_SPACE items for subvolume present"
[ "$item_count" -eq 0 ] || _fail "FREE_SPACE items for subvolume present"
# Check for FREE_INO items for snapshot
item_count=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t 257 "$image" |
grep -c 'item [0-9].* key (FREE_INO')
[ $item_count -eq 0 ] || _fail "ino cache items for snapshot present"
[ "$item_count" -eq 0 ] || _fail "ino cache items for snapshot present"
# Check for bitmap item for snapshot
item_count=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t 257 "$image" |
grep -c '(FREE_SPACE')
[ $item_count -eq 0 ] || _fail "FREE_SPACE items for snapshot present"
[ "$item_count" -eq 0 ] || _fail "FREE_SPACE items for snapshot present"
# Finally test that the csum tree is empty as ino cache also uses it. At this
# point all ino items/extents should have been deleted hence the csum tree should
@ -45,6 +45,6 @@ item_count=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t 257 "$i
item_count=$(run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t csum "$image" |
sed -n -e 's/^.* items \([0-9]*\).*/\1/p')
[ $item_count -eq 0 ] || _fail "csum tree not empty"
[ "$item_count" -eq 0 ] || _fail "csum tree not empty"
rm -f -- "$image"

View File

@ -25,31 +25,31 @@ if [ $? != 0 ]; then
_fail "cannot create nullb zoned device $i"
fi
dev=$(echo "$out" | tail -n 1)
name=$(basename "${dev}")
name=$(basename "$dev")
run_check $SUDO_HELPER "$nullb" ls
TEST_DEV="${dev}"
TEST_DEV="$dev"
# Create the fs without bgt
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -m single -d single -O ^block-group-tree "${dev}"
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -m single -d single -O ^block-group-tree "$dev"
run_check_mount_test_dev
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT"/file1 bs=1M count=1
run_check $SUDO_HELPER "$TOP/btrfs" filesystem usage -T "$TEST_MNT"
run_check_umount_test_dev
# Convert to bgt
run_check $SUDO_HELPER "$TOP/btrfstune" --convert-to-block-group-tree "${dev}"
run_check $SUDO_HELPER "$TOP/btrfstune" --convert-to-block-group-tree "$dev"
run_check_mount_test_dev
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT"/file2 bs=1M count=1
run_check $SUDO_HELPER "$TOP/btrfs" filesystem usage -T "$TEST_MNT"
run_check_umount_test_dev
# And convert back to old extent tree
run_check $SUDO_HELPER "$TOP/btrfstune" --convert-from-block-group-tree "${dev}"
run_check $SUDO_HELPER "$TOP/btrfstune" --convert-from-block-group-tree "$dev"
run_check_mount_test_dev
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT"/file3 bs=1M count=1
run_check $SUDO_HELPER "$TOP/btrfs" filesystem usage -T "$TEST_MNT"
run_check_umount_test_dev
run_check $SUDO_HELPER "$nullb" rm "${name}"
run_check $SUDO_HELPER "$nullb" rm "$name"

View File

@ -36,6 +36,7 @@ test_get_info()
run_check $SUDO_HELPER "$TOP/btrfs" device usage "$TEST_MNT"
run_check $SUDO_HELPER umount "$TEST_MNT"
}
test_do_mkfs()
{
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$@"

View File

@ -17,8 +17,10 @@ features="^mixed-bg"
# caller need to check whether the combination is valid
do_test()
{
sectorsize=$1
nodesize=$2
local sectorsize=$1
local nodesize=$2
local ret
run_mayfail "$TOP/mkfs.btrfs" -f -O "$features" -n "$nodesize" -s "$sectorsize" \
"$TEST_DEV"
ret=$?

View File

@ -15,6 +15,8 @@ prepare_test_dev
do_one_test ()
{
local first_dev_extent
run_check_mkfs_test_dev "$@"
# Use dev-extent tree to find first device extent

View File

@ -21,7 +21,7 @@ create_file()
test_mkfs_rootdir()
{
nodesize=$1
local nodesize=$1
run_check_mkfs_test_dev --nodesize "$nodesize" --rootdir "$tmp"
run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV"
}

View File

@ -11,7 +11,7 @@ prepare_nullbdevs
TEST_DEV="${nullb_devs[1]}"
# Use single as it's supported on more kernels
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -m single -d single -O block-group-tree "${TEST_DEV}"
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -m single -d single -O block-group-tree "$TEST_DEV"
run_check_mount_test_dev
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT"/file bs=1M count=1
run_check $SUDO_HELPER "$TOP/btrfs" filesystem usage -T "$TEST_MNT"

View File

@ -13,29 +13,29 @@ prepare_nullbdevs
TEST_DEV="${nullb_devs[1]}"
last_zone_sector=$(( 4 * 31 * 1024 * 1024 / 512 ))
# Write some data to the last zone
run_check $SUDO_HELPER dd if=/dev/urandom of="${TEST_DEV}" bs=1M count=4 seek=$(( 4 * 31 ))
run_check $SUDO_HELPER dd if=/dev/urandom of="$TEST_DEV" bs=1M count=4 seek=$(( 4 * 31 ))
# Use single as it's supported on more kernels
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -m single -d single "${TEST_DEV}"
# Check if the lat zone is empty
run_check_stdout $SUDO_HELPER blkzone report -o ${last_zone_sector} -c 1 "${TEST_DEV}" | grep -Fq '(em)'
run_check_stdout $SUDO_HELPER blkzone report -o "$last_zone_sector" -c 1 "$TEST_DEV" | grep -Fq '(em)'
if [ $? != 0 ]; then
_fail "last zone is not empty"
fi
# Write some data to the last zone
run_check $SUDO_HELPER dd if=/dev/urandom of="${TEST_DEV}" bs=1M count=1 seek=$(( 4 * 31 ))
run_check $SUDO_HELPER dd if=/dev/urandom of="$TEST_DEV" bs=1M count=1 seek=$(( 4 * 31 ))
# Create a FS excluding the last zone
run_mayfail $SUDO_HELPER "$TOP/mkfs.btrfs" -f -b $(( 4 * 31 ))M -m single -d single "${TEST_DEV}"
run_mayfail $SUDO_HELPER "$TOP/mkfs.btrfs" -f -b $(( 4 * 31 ))M -m single -d single "$TEST_DEV"
if [ $? == 0 ]; then
_fail "mkfs.btrfs should detect active zone outside of FS range"
fi
# Fill the last zone to finish it
run_check $SUDO_HELPER dd if=/dev/urandom of="${TEST_DEV}" bs=1M count=3 seek=$(( 4 * 31 + 1 ))
run_check $SUDO_HELPER dd if=/dev/urandom of="$TEST_DEV" bs=1M count=3 seek=$(( 4 * 31 + 1 ))
# Create a FS excluding the last zone
run_mayfail $SUDO_HELPER "$TOP/mkfs.btrfs" -f -b $(( 4 * 31 ))M -m single -d single "${TEST_DEV}"
run_mayfail $SUDO_HELPER "$TOP/mkfs.btrfs" -f -b $(( 4 * 31 ))M -m single -d single "$TEST_DEV"
# Check if the lat zone is not empty
run_check_stdout $SUDO_HELPER blkzone report -o ${last_zone_sector} -c 1 "${TEST_DEV}" | grep -Fq '(em)'
run_check_stdout $SUDO_HELPER blkzone report -o "$last_zone_sector" -c 1 "$TEST_DEV" | grep -Fq '(em)'
if [ $? == 0 ]; then
_fail "last zone is empty"
fi