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 (168 lines) | stat: -rwxr-xr-x 4,965 bytes parent folder | download
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
#
# Test filesystem resize --offline functionality
#
# Tests various resize operations on offline:
#
# - Incremental resize (+1G, 1:+1G)
# - Absolute resize (2G)
# - Invalid operations (multi-device, invalid syntax, shrinking)

source "$TEST_TOP/common" || exit

check_prereq mkfs.btrfs
check_prereq btrfs

setup_root_helper

get_filesystem_size()
{
	local mount="$1"

	size=$(run_check_stdout $SUDO_HELPER "$TOP/btrfs" filesystem usage -m "$mount" | \
		grep "Device size:" | awk '{print $3}' | sed 's/\..*//')
	echo "$size"
}

create_backing_file()
{
	local path="$1"
	local size_mb="$2"

	run_check truncate -s "${size_mb}M" "$path"
}

# Test offline resize with incremental size (+1G)
_log "Testing offline resize +1G"
backing="$(_mktemp backing)"
create_backing_file "$backing" 1024

run_check "$TOP/mkfs.btrfs" -f "$backing"
run_check "$TOP/btrfs" filesystem resize --offline "+1G" "$backing"

TEST_DEV="$backing"
run_check_mount_test_dev
actual_size=$(get_filesystem_size "$TEST_MNT")
if [ "$actual_size" != "2048" ]; then
	_fail "Size mismatch: expected 2048MiB, got ${actual_size}MiB"
fi
run_check_umount_test_dev
rm -f "$backing"

# Test offline resize with device-specific incremental size (1:+1G)
_log "Testing offline resize 1:+1G"
backing="$(_mktemp backing)"
create_backing_file "$backing" 1024

run_check "$TOP/mkfs.btrfs" -f "$backing"
run_check "$TOP/btrfs" filesystem resize --offline "1:+1G" "$backing"

TEST_DEV="$backing"
run_check_mount_test_dev
actual_size=$(get_filesystem_size "$TEST_MNT")
if [ "$actual_size" != "2048" ]; then
	_fail "Size mismatch: expected 2048MiB, got ${actual_size}MiB"
fi
run_check_umount_test_dev
rm -f "$backing"

# Test offline resize with absolute size (2G)
_log "Testing offline resize 2G"
backing="$(_mktemp backing)"
create_backing_file "$backing" 1024

run_check "$TOP/mkfs.btrfs" -f "$backing"
run_check "$TOP/btrfs" filesystem resize --offline "2G" "$backing"

TEST_DEV="$backing"
run_check_mount_test_dev
actual_size=$(get_filesystem_size "$TEST_MNT")
if [ "$actual_size" != "2048" ]; then
	_fail "Size mismatch: expected 2048MiB, got ${actual_size}MiB"
fi
run_check_umount_test_dev
rm -f "$backing"

# Test offline resize with invalid device id (2:+1G)
_log "Testing offline resize with invalid device id 2:+1G"
backing="$(_mktemp backing)"
create_backing_file "$backing" 1024

run_check "$TOP/mkfs.btrfs" -f "$backing"
run_mustfail "offline resize should fail with invalid device id" \
	"$TOP/btrfs" filesystem resize --offline "2:+1G" "$backing"
rm -f "$backing"

# Test offline resize with shrinking (not supported)
_log "Testing offline resize with shrinking -10M"
backing="$(_mktemp backing)"
create_backing_file "$backing" 1024

run_check "$TOP/mkfs.btrfs" -f "$backing"
run_mustfail "offline resize should not support shrinking" \
	"$TOP/btrfs" filesystem resize --offline "-10M" "$backing"
rm -f "$backing"

# Test offline resize with cancel (not supported)
_log "Testing offline resize with cancel"
backing="$(_mktemp backing)"
create_backing_file "$backing" 1024

run_check "$TOP/mkfs.btrfs" -f "$backing"
run_mustfail "offline resize should not support cancel" \
	"$TOP/btrfs" filesystem resize --offline "cancel" "$backing"
rm -f "$backing"

# Test offline resize with invalid size format
_log "Testing offline resize with invalid size format 1:+1a"
backing="$(_mktemp backing)"
create_backing_file "$backing" 1024

run_check "$TOP/mkfs.btrfs" -f "$backing"
run_mustfail "offline resize should fail with invalid size format" \
	"$TOP/btrfs" filesystem resize --offline "1:+1a" "$backing"
rm -f "$backing"

# Test offline resize on multi-device filesystem (should fail)
_log "Testing offline resize on multi-device filesystem"
backing1="$(_mktemp backing1)"
backing2="$(_mktemp backing2)"

create_backing_file "$backing1" 1024
create_backing_file "$backing2" 1024

run_check "$TOP/mkfs.btrfs" -f "$backing1" "$backing2"
run_mustfail "offline resize should fail on multi-device filesystem" \
	"$TOP/btrfs" filesystem resize --offline "+1G" "$backing1"

rm -f "$backing1" "$backing2"

# Test that --offline and --enqueue are incompatible
_log "Testing that --offline and --enqueue are incompatible"
backing="$(_mktemp backing)"
create_backing_file "$backing" 1024

run_check "$TOP/mkfs.btrfs" -f "$backing"
run_mustfail "--offline and --enqueue should be incompatible" \
	"$TOP/btrfs" filesystem resize --offline --enqueue "+1G" "$backing"

rm -f "$backing"

# Test offline resize on mounted filesystem (should fail)
_log "Testing offline resize on mounted filesystem"
setup_loopdevs 1
prepare_loopdevs

dev="${loopdevs[1]}"
run_check "$TOP/mkfs.btrfs" -f "$dev"

TEST_DEV="$dev"
run_check_mount_test_dev

# Get the backing file path from the loop device
backing=$(losetup -l "$dev" | tail -n1 | awk '{print $6}')
run_mustfail "offline resize should fail on mounted filesystem" \
	"$TOP/btrfs" filesystem resize --offline "+1G" "$backing"

run_check_umount_test_dev
cleanup_loopdevs