File: test.sh

package info (click to toggle)
btrfs-progs 6.17.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,612 kB
  • sloc: ansic: 127,282; sh: 7,915; python: 1,384; makefile: 900; asm: 296
file content (51 lines) | stat: -rwxr-xr-x 1,364 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Test that btrfs-image can dump image correctly for a missing device (RAID1)
#
# At least for RAID1, btrfs-image should be able to handle one missing device
# without any problem. Only space cache v2 supported.

source "$TEST_TOP/common" || exit

check_prereq btrfs-image
check_prereq mkfs.btrfs
check_prereq btrfs

setup_root_helper
setup_loopdevs 2
prepare_loopdevs
dev1=${loopdevs[1]}
dev2=${loopdevs[2]}

# $1:	device number to remove (either 1 or 2)
test_missing()
{
	local bad_num
	local bad_dev
	local good_num
	local good_dev

	bad_num="$1"
	bad_dev=${loopdevs[$bad_num]}
	good_num=$((3 - $bad_num))
	good_dev=${loopdevs[$good_num]}

	run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d raid1 -m raid1 "$dev1" "$dev2"

	# fill the fs with some data, we could create space cache
	cond_wait_for_loopdevs
	run_check $SUDO_HELPER mount "$dev1" "$TEST_MNT"
	run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/a" bs=1M count=10
	run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/b" bs=4k count=1000 conv=sync
	run_check $SUDO_HELPER umount "$TEST_MNT"

	# now wipe the device
	run_check wipefs -fa "$bad_dev"

	# we don't care about the image but btrfs-image must not fail
	run_check "$TOP/btrfs-image" "$good_dev" /dev/null
}

# Test with either device missing, so we're ensured to hit missing device
test_missing 1
test_missing 2
cleanup_loopdevs