Skip to content

Commit a0afdec

Browse files
morbidrsakdave
authored andcommitted
btrfs: selftests: don't split RAID extents in half
The selftests for partially deleting the start or tail of RAID stripe-extents split these extents in half. This can hide errors in the calculation, so don't split the RAID stripe-extents in half but delete the first or last 16K of the 64K extents. Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Johannes Thumshirn <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent d44d3d7 commit a0afdec

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

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

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#define RST_TEST_NUM_DEVICES (2)
1515
#define RST_TEST_RAID1_TYPE (BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_RAID1)
1616

17+
#define SZ_48K (SZ_32K + SZ_16K)
18+
1719
typedef int (*test_func_t)(struct btrfs_trans_handle *trans);
1820

1921
static struct btrfs_device *btrfs_device_by_devid(struct btrfs_fs_devices *fs_devices,
@@ -94,32 +96,32 @@ static int test_front_delete(struct btrfs_trans_handle *trans)
9496
goto out;
9597
}
9698

97-
ret = btrfs_delete_raid_extent(trans, logical, SZ_32K);
99+
ret = btrfs_delete_raid_extent(trans, logical, SZ_16K);
98100
if (ret) {
99101
test_err("deleting RAID extent [%llu, %llu] failed", logical,
100-
logical + SZ_32K);
102+
logical + SZ_16K);
101103
goto out;
102104
}
103105

104-
len = SZ_32K;
105-
ret = btrfs_get_raid_extent_offset(fs_info, logical + SZ_32K, &len,
106+
len -= SZ_16K;
107+
ret = btrfs_get_raid_extent_offset(fs_info, logical + SZ_16K, &len,
106108
map_type, 0, &io_stripe);
107109
if (ret) {
108110
test_err("lookup of RAID extent [%llu, %llu] failed",
109-
logical + SZ_32K, logical + SZ_32K + len);
111+
logical + SZ_16K, logical + SZ_64K);
110112
goto out;
111113
}
112114

113-
if (io_stripe.physical != logical + SZ_32K) {
115+
if (io_stripe.physical != logical + SZ_16K) {
114116
test_err("invalid physical address, expected %llu, got %llu",
115-
logical + SZ_32K, io_stripe.physical);
117+
logical + SZ_16K, io_stripe.physical);
116118
ret = -EINVAL;
117119
goto out;
118120
}
119121

120-
if (len != SZ_32K) {
122+
if (len != SZ_48K) {
121123
test_err("invalid stripe length, expected %llu, got %llu",
122-
(u64)SZ_32K, len);
124+
(u64)SZ_48K, len);
123125
ret = -EINVAL;
124126
goto out;
125127
}
@@ -128,11 +130,11 @@ static int test_front_delete(struct btrfs_trans_handle *trans)
128130
if (ret != -ENODATA) {
129131
ret = -EINVAL;
130132
test_err("lookup of RAID extent [%llu, %llu] succeeded, should fail",
131-
logical, logical + SZ_32K);
133+
logical, logical + SZ_16K);
132134
goto out;
133135
}
134136

135-
ret = btrfs_delete_raid_extent(trans, logical + SZ_32K, SZ_32K);
137+
ret = btrfs_delete_raid_extent(trans, logical + SZ_16K, SZ_48K);
136138
out:
137139
btrfs_put_bioc(bioc);
138140
return ret;
@@ -209,14 +211,14 @@ static int test_tail_delete(struct btrfs_trans_handle *trans)
209211
goto out;
210212
}
211213

212-
ret = btrfs_delete_raid_extent(trans, logical + SZ_32K, SZ_32K);
214+
ret = btrfs_delete_raid_extent(trans, logical + SZ_48K, SZ_16K);
213215
if (ret) {
214216
test_err("deleting RAID extent [%llu, %llu] failed",
215-
logical + SZ_32K, logical + SZ_64K);
217+
logical + SZ_48K, logical + SZ_64K);
216218
goto out;
217219
}
218220

219-
len = SZ_32K;
221+
len = SZ_48K;
220222
ret = btrfs_get_raid_extent_offset(fs_info, logical, &len, map_type, 0, &io_stripe);
221223
if (ret) {
222224
test_err("lookup of RAID extent [%llu, %llu] failed", logical,
@@ -231,9 +233,19 @@ static int test_tail_delete(struct btrfs_trans_handle *trans)
231233
goto out;
232234
}
233235

234-
if (len != SZ_32K) {
236+
if (len != SZ_48K) {
235237
test_err("invalid stripe length, expected %llu, got %llu",
236-
(u64)SZ_32K, len);
238+
(u64)SZ_48K, len);
239+
ret = -EINVAL;
240+
goto out;
241+
}
242+
243+
len = SZ_16K;
244+
ret = btrfs_get_raid_extent_offset(fs_info, logical + SZ_48K, &len,
245+
map_type, 0, &io_stripe);
246+
if (ret != -ENODATA) {
247+
test_err("lookup of RAID extent [%llu, %llu] succeeded should fail",
248+
logical + SZ_48K, logical + SZ_64K);
237249
ret = -EINVAL;
238250
goto out;
239251
}

0 commit comments

Comments
 (0)