Skip to content

Commit 6e6ecde

Browse files
morbidrsakdave
authored andcommitted
btrfs: tests: implement case for partial RAID stripe-tree delete
Implement self-tests for partial deletion of RAID stripe-tree entries. These two new tests cover both the deletion of the front of a RAID stripe-tree stripe extent as well as truncation of an item to make it smaller. Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 6aea95e commit 6e6ecde

File tree

1 file changed

+221
-0
lines changed

1 file changed

+221
-0
lines changed

fs/btrfs/tests/raid-stripe-tree-tests.c

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,225 @@ static struct btrfs_device *btrfs_device_by_devid(struct btrfs_fs_devices *fs_de
2929
return NULL;
3030
}
3131

32+
/*
33+
* Test a 64K RST write on a 2 disk RAID1 at a logical address of 1M and then
34+
* delete the 1st 32K, making the new start address 1M+32K.
35+
*/
36+
static int test_front_delete(struct btrfs_trans_handle *trans)
37+
{
38+
struct btrfs_fs_info *fs_info = trans->fs_info;
39+
struct btrfs_io_context *bioc;
40+
struct btrfs_io_stripe io_stripe = { 0 };
41+
u64 map_type = RST_TEST_RAID1_TYPE;
42+
u64 logical = SZ_1M;
43+
u64 len = SZ_64K;
44+
int ret;
45+
46+
bioc = alloc_btrfs_io_context(fs_info, logical, RST_TEST_NUM_DEVICES);
47+
if (!bioc) {
48+
test_std_err(TEST_ALLOC_IO_CONTEXT);
49+
ret = -ENOMEM;
50+
goto out;
51+
}
52+
53+
io_stripe.dev = btrfs_device_by_devid(fs_info->fs_devices, 0);
54+
bioc->map_type = map_type;
55+
bioc->size = len;
56+
57+
for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) {
58+
struct btrfs_io_stripe *stripe = &bioc->stripes[i];
59+
60+
stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i);
61+
if (!stripe->dev) {
62+
test_err("cannot find device with devid %d", i);
63+
ret = -EINVAL;
64+
goto out;
65+
}
66+
67+
stripe->physical = logical + i * SZ_1G;
68+
}
69+
70+
ret = btrfs_insert_one_raid_extent(trans, bioc);
71+
if (ret) {
72+
test_err("inserting RAID extent failed: %d", ret);
73+
goto out;
74+
}
75+
76+
ret = btrfs_get_raid_extent_offset(fs_info, logical, &len, map_type, 0, &io_stripe);
77+
if (ret) {
78+
test_err("lookup of RAID extent [%llu, %llu] failed", logical,
79+
logical + len);
80+
goto out;
81+
}
82+
83+
if (io_stripe.physical != logical) {
84+
test_err("invalid physical address, expected %llu got %llu",
85+
logical, io_stripe.physical);
86+
ret = -EINVAL;
87+
goto out;
88+
}
89+
90+
if (len != SZ_64K) {
91+
test_err("invalid stripe length, expected %llu got %llu",
92+
(u64)SZ_64K, len);
93+
ret = -EINVAL;
94+
goto out;
95+
}
96+
97+
ret = btrfs_delete_raid_extent(trans, logical, SZ_32K);
98+
if (ret) {
99+
test_err("deleting RAID extent [%llu, %llu] failed", logical,
100+
logical + SZ_32K);
101+
goto out;
102+
}
103+
104+
len = SZ_32K;
105+
ret = btrfs_get_raid_extent_offset(fs_info, logical + SZ_32K, &len,
106+
map_type, 0, &io_stripe);
107+
if (ret) {
108+
test_err("lookup of RAID extent [%llu, %llu] failed",
109+
logical + SZ_32K, logical + SZ_32K + len);
110+
goto out;
111+
}
112+
113+
if (io_stripe.physical != logical + SZ_32K) {
114+
test_err("invalid physical address, expected %llu, got %llu",
115+
logical + SZ_32K, io_stripe.physical);
116+
ret = -EINVAL;
117+
goto out;
118+
}
119+
120+
if (len != SZ_32K) {
121+
test_err("invalid stripe length, expected %llu, got %llu",
122+
(u64)SZ_32K, len);
123+
ret = -EINVAL;
124+
goto out;
125+
}
126+
127+
ret = btrfs_get_raid_extent_offset(fs_info, logical, &len, map_type, 0, &io_stripe);
128+
if (!ret) {
129+
ret = -EINVAL;
130+
test_err("lookup of RAID extent [%llu, %llu] succeeded, should fail",
131+
logical, logical + SZ_32K);
132+
goto out;
133+
}
134+
135+
ret = btrfs_delete_raid_extent(trans, logical + SZ_32K, SZ_32K);
136+
out:
137+
btrfs_put_bioc(bioc);
138+
return ret;
139+
}
140+
141+
/*
142+
* Test a 64K RST write on a 2 disk RAID1 at a logical address of 1M and then
143+
* truncate the stripe extent down to 32K.
144+
*/
145+
static int test_tail_delete(struct btrfs_trans_handle *trans)
146+
{
147+
struct btrfs_fs_info *fs_info = trans->fs_info;
148+
struct btrfs_io_context *bioc;
149+
struct btrfs_io_stripe io_stripe = { 0 };
150+
u64 map_type = RST_TEST_RAID1_TYPE;
151+
u64 logical = SZ_1M;
152+
u64 len = SZ_64K;
153+
int ret;
154+
155+
bioc = alloc_btrfs_io_context(fs_info, logical, RST_TEST_NUM_DEVICES);
156+
if (!bioc) {
157+
test_std_err(TEST_ALLOC_IO_CONTEXT);
158+
ret = -ENOMEM;
159+
goto out;
160+
}
161+
162+
io_stripe.dev = btrfs_device_by_devid(fs_info->fs_devices, 0);
163+
bioc->map_type = map_type;
164+
bioc->size = len;
165+
166+
for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) {
167+
struct btrfs_io_stripe *stripe = &bioc->stripes[i];
168+
169+
stripe->dev = btrfs_device_by_devid(fs_info->fs_devices, i);
170+
if (!stripe->dev) {
171+
test_err("cannot find device with devid %d", i);
172+
ret = -EINVAL;
173+
goto out;
174+
}
175+
176+
stripe->physical = logical + i * SZ_1G;
177+
}
178+
179+
ret = btrfs_insert_one_raid_extent(trans, bioc);
180+
if (ret) {
181+
test_err("inserting RAID extent failed: %d", ret);
182+
goto out;
183+
}
184+
185+
io_stripe.dev = btrfs_device_by_devid(fs_info->fs_devices, 0);
186+
if (!io_stripe.dev) {
187+
ret = -EINVAL;
188+
goto out;
189+
}
190+
191+
ret = btrfs_get_raid_extent_offset(fs_info, logical, &len, map_type, 0, &io_stripe);
192+
if (ret) {
193+
test_err("lookup of RAID extent [%llu, %llu] failed", logical,
194+
logical + len);
195+
goto out;
196+
}
197+
198+
if (io_stripe.physical != logical) {
199+
test_err("invalid physical address, expected %llu got %llu",
200+
logical, io_stripe.physical);
201+
ret = -EINVAL;
202+
goto out;
203+
}
204+
205+
if (len != SZ_64K) {
206+
test_err("invalid stripe length, expected %llu got %llu",
207+
(u64)SZ_64K, len);
208+
ret = -EINVAL;
209+
goto out;
210+
}
211+
212+
ret = btrfs_delete_raid_extent(trans, logical + SZ_32K, SZ_32K);
213+
if (ret) {
214+
test_err("deleting RAID extent [%llu, %llu] failed",
215+
logical + SZ_32K, logical + SZ_64K);
216+
goto out;
217+
}
218+
219+
len = SZ_32K;
220+
ret = btrfs_get_raid_extent_offset(fs_info, logical, &len, map_type, 0, &io_stripe);
221+
if (ret) {
222+
test_err("lookup of RAID extent [%llu, %llu] failed", logical,
223+
logical + len);
224+
goto out;
225+
}
226+
227+
if (io_stripe.physical != logical) {
228+
test_err("invalid physical address, expected %llu, got %llu",
229+
logical, io_stripe.physical);
230+
ret = -EINVAL;
231+
goto out;
232+
}
233+
234+
if (len != SZ_32K) {
235+
test_err("invalid stripe length, expected %llu, got %llu",
236+
(u64)SZ_32K, len);
237+
ret = -EINVAL;
238+
goto out;
239+
}
240+
241+
ret = btrfs_delete_raid_extent(trans, logical, len);
242+
if (ret)
243+
test_err("deleting RAID extent [%llu, %llu] failed", logical,
244+
logical + len);
245+
246+
out:
247+
btrfs_put_bioc(bioc);
248+
return ret;
249+
}
250+
32251
/*
33252
* Test a 64K RST write on a 2 disk RAID1 at a logical address of 1M and then
34253
* overwrite the whole range giving it new physical address at an offset of 1G.
@@ -235,6 +454,8 @@ static int test_simple_create_delete(struct btrfs_trans_handle *trans)
235454
static const test_func_t tests[] = {
236455
test_simple_create_delete,
237456
test_create_update_delete,
457+
test_tail_delete,
458+
test_front_delete,
238459
};
239460

240461
static int run_test(test_func_t test, u32 sectorsize, u32 nodesize)

0 commit comments

Comments
 (0)