Skip to content

Commit c643e3e

Browse files
committed
btrfs-progs: add test for offline filesystem resize
Add comprehensive test coverage for the new --offline resize feature. The test suite covers: - Valid resize operations: incremental (+1G, 1:+1G) and absolute (2G) - Invalid operations that should fail: shrinking, multi-device, cancel - Error conditions: invalid device IDs, malformed size arguments - Option compatibility: --offline with --enqueue should be rejected - Mount state validation: offline resize should fail on mounted filesystems Each test creates temporary filesystem images, performs resize operations, and verifies the resulting filesystem size matches expectations. Error cases use run_mustfail to ensure proper failure handling. Signed-off-by: Leo Martins <[email protected]>
1 parent c6e70ee commit c643e3e

File tree

1 file changed

+167
-0
lines changed
  • tests/misc-tests/070-offline-resize

1 file changed

+167
-0
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#!/bin/bash
2+
#
3+
# Test btrfs filesystem resize --offline functionality
4+
# Tests various resize operations on offline filesystems including:
5+
# - Incremental resize (+1G, 1:+1G)
6+
# - Absolute resize (2G)
7+
# - Invalid operations (multi-device, invalid syntax, shrinking)
8+
#
9+
10+
source "$TEST_TOP/common" || exit
11+
12+
check_prereq mkfs.btrfs
13+
check_prereq btrfs
14+
15+
setup_root_helper
16+
17+
_get_filesystem_size()
18+
{
19+
local mount_point="$1"
20+
21+
size=$(run_check_stdout $SUDO_HELPER "$TOP/btrfs" filesystem usage -m "$mount_point" | \
22+
grep "Device size:" | awk '{print $3}' | sed 's/\..*//')
23+
echo "$size"
24+
}
25+
26+
_create_backing_file()
27+
{
28+
local path="$1"
29+
local size_mb="$2"
30+
31+
run_check truncate -s "${size_mb}M" "$path"
32+
}
33+
34+
# Test offline resize with incremental size (+1G)
35+
_log "Testing offline resize +1G"
36+
backing_file="$(_mktemp backing)"
37+
_create_backing_file "$backing_file" 1024
38+
39+
run_check "$TOP/mkfs.btrfs" -f "$backing_file"
40+
run_check "$TOP/btrfs" filesystem resize --offline "+1G" "$backing_file"
41+
42+
TEST_DEV="$backing_file"
43+
run_check_mount_test_dev
44+
actual_size=$(_get_filesystem_size "$TEST_MNT")
45+
if [ "$actual_size" != "2048" ]; then
46+
_fail "Size mismatch: expected 2048MiB, got ${actual_size}MiB"
47+
fi
48+
run_check_umount_test_dev
49+
rm -f "$backing_file"
50+
51+
# Test offline resize with device-specific incremental size (1:+1G)
52+
_log "Testing offline resize 1:+1G"
53+
backing_file="$(_mktemp backing)"
54+
_create_backing_file "$backing_file" 1024
55+
56+
run_check "$TOP/mkfs.btrfs" -f "$backing_file"
57+
run_check "$TOP/btrfs" filesystem resize --offline "1:+1G" "$backing_file"
58+
59+
TEST_DEV="$backing_file"
60+
run_check_mount_test_dev
61+
actual_size=$(_get_filesystem_size "$TEST_MNT")
62+
if [ "$actual_size" != "2048" ]; then
63+
_fail "Size mismatch: expected 2048MiB, got ${actual_size}MiB"
64+
fi
65+
run_check_umount_test_dev
66+
rm -f "$backing_file"
67+
68+
# Test offline resize with absolute size (2G)
69+
_log "Testing offline resize 2G"
70+
backing_file="$(_mktemp backing)"
71+
_create_backing_file "$backing_file" 1024
72+
73+
run_check "$TOP/mkfs.btrfs" -f "$backing_file"
74+
run_check "$TOP/btrfs" filesystem resize --offline "2G" "$backing_file"
75+
76+
TEST_DEV="$backing_file"
77+
run_check_mount_test_dev
78+
actual_size=$(_get_filesystem_size "$TEST_MNT")
79+
if [ "$actual_size" != "2048" ]; then
80+
_fail "Size mismatch: expected 2048MiB, got ${actual_size}MiB"
81+
fi
82+
run_check_umount_test_dev
83+
rm -f "$backing_file"
84+
85+
# Test offline resize with invalid device id (2:+1G)
86+
_log "Testing offline resize with invalid device id 2:+1G"
87+
backing_file="$(_mktemp backing)"
88+
_create_backing_file "$backing_file" 1024
89+
90+
run_check "$TOP/mkfs.btrfs" -f "$backing_file"
91+
run_mustfail "offline resize should fail with invalid device id" \
92+
"$TOP/btrfs" filesystem resize --offline "2:+1G" "$backing_file"
93+
rm -f "$backing_file"
94+
95+
# Test offline resize with shrinking (not supported)
96+
_log "Testing offline resize with shrinking -10M"
97+
backing_file="$(_mktemp backing)"
98+
_create_backing_file "$backing_file" 1024
99+
100+
run_check "$TOP/mkfs.btrfs" -f "$backing_file"
101+
run_mustfail "offline resize should not support shrinking" \
102+
"$TOP/btrfs" filesystem resize --offline "-10M" "$backing_file"
103+
rm -f "$backing_file"
104+
105+
# Test offline resize with cancel (not supported)
106+
_log "Testing offline resize with cancel"
107+
backing_file="$(_mktemp backing)"
108+
_create_backing_file "$backing_file" 1024
109+
110+
run_check "$TOP/mkfs.btrfs" -f "$backing_file"
111+
run_mustfail "offline resize should not support cancel" \
112+
"$TOP/btrfs" filesystem resize --offline "cancel" "$backing_file"
113+
rm -f "$backing_file"
114+
115+
# Test offline resize with invalid size format
116+
_log "Testing offline resize with invalid size format 1:+1a"
117+
backing_file="$(_mktemp backing)"
118+
_create_backing_file "$backing_file" 1024
119+
120+
run_check "$TOP/mkfs.btrfs" -f "$backing_file"
121+
run_mustfail "offline resize should fail with invalid size format" \
122+
"$TOP/btrfs" filesystem resize --offline "1:+1a" "$backing_file"
123+
rm -f "$backing_file"
124+
125+
# Test offline resize on multi-device filesystem (should fail)
126+
_log "Testing offline resize on multi-device filesystem"
127+
backing_file1="$(_mktemp backing1)"
128+
backing_file2="$(_mktemp backing2)"
129+
130+
_create_backing_file "$backing_file1" 1024
131+
_create_backing_file "$backing_file2" 1024
132+
133+
run_check "$TOP/mkfs.btrfs" -f "$backing_file1" "$backing_file2"
134+
run_mustfail "offline resize should fail on multi-device filesystem" \
135+
"$TOP/btrfs" filesystem resize --offline "+1G" "$backing_file1"
136+
137+
rm -f "$backing_file1" "$backing_file2"
138+
139+
# Test that --offline and --enqueue are incompatible
140+
_log "Testing that --offline and --enqueue are incompatible"
141+
backing_file="$(_mktemp backing)"
142+
_create_backing_file "$backing_file" 1024
143+
144+
run_check "$TOP/mkfs.btrfs" -f "$backing_file"
145+
run_mustfail "--offline and --enqueue should be incompatible" \
146+
"$TOP/btrfs" filesystem resize --offline --enqueue "+1G" "$backing_file"
147+
148+
rm -f "$backing_file"
149+
150+
# Test offline resize on mounted filesystem (should fail)
151+
_log "Testing offline resize on mounted filesystem"
152+
setup_loopdevs 1
153+
prepare_loopdevs
154+
155+
dev="${loopdevs[1]}"
156+
run_check "$TOP/mkfs.btrfs" -f "$dev"
157+
158+
TEST_DEV="$dev"
159+
run_check_mount_test_dev
160+
161+
# Get the backing file path from the loop device
162+
backing_file=$(losetup -l "$dev" | tail -n1 | awk '{print $6}')
163+
run_mustfail "offline resize should fail on mounted filesystem" \
164+
"$TOP/btrfs" filesystem resize --offline "+1G" "$backing_file"
165+
166+
run_check_umount_test_dev
167+
cleanup_loopdevs

0 commit comments

Comments
 (0)