mirror of
https://github.com/torvalds/linux.git
synced 2024-11-26 06:02:05 +00:00
btrfs: selftests: remove impossible inline extent at non-zero file offset
In our inode-tests.c, we create an inline offset at file offset 5, which is no longer possible since the introduction of tree-checker. Thus I don't think we should spend time maintaining some corner cases which are already ruled out by tree-checker. So this patch will: - Change the inline extent to start at file offset 0 Also change its length to 6 to cover the original length - Add an extra ASSERT() for btrfs_add_extent_mapping() This is to make sure tree-checker is working correctly. - Update the inode selftest Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
aa5d3003dd
commit
d52a136525
@ -638,6 +638,13 @@ int btrfs_add_extent_mapping(struct btrfs_fs_info *fs_info,
|
||||
int ret;
|
||||
struct extent_map *em = *em_in;
|
||||
|
||||
/*
|
||||
* Tree-checker should have rejected any inline extent with non-zero
|
||||
* file offset. Here just do a sanity check.
|
||||
*/
|
||||
if (em->block_start == EXTENT_MAP_INLINE)
|
||||
ASSERT(em->start == 0);
|
||||
|
||||
ret = add_extent_mapping(em_tree, em, 0);
|
||||
/* it is possible that someone inserted the extent into the tree
|
||||
* while we had the lock dropped. It is also possible that
|
||||
|
@ -73,8 +73,8 @@ static void insert_inode_item_key(struct btrfs_root *root)
|
||||
* diagram of how the extents will look though this may not be possible we still
|
||||
* want to make sure everything acts normally (the last number is not inclusive)
|
||||
*
|
||||
* [0 - 5][5 - 6][ 6 - 4096 ][ 4096 - 4100][4100 - 8195][8195 - 12291]
|
||||
* [hole ][inline][hole but no extent][ hole ][ regular ][regular1 split]
|
||||
* [0 - 6][ 6 - 4096 ][ 4096 - 4100][4100 - 8195][8195 - 12291]
|
||||
* [inline][hole but no extent][ hole ][ regular ][regular1 split]
|
||||
*
|
||||
* [12291 - 16387][16387 - 24579][24579 - 28675][ 28675 - 32771][32771 - 36867 ]
|
||||
* [ hole ][regular1 split][ prealloc ][ prealloc1 ][prealloc1 written]
|
||||
@ -91,19 +91,12 @@ static void setup_file_extents(struct btrfs_root *root, u32 sectorsize)
|
||||
u64 disk_bytenr = SZ_1M;
|
||||
u64 offset = 0;
|
||||
|
||||
/* First we want a hole */
|
||||
insert_extent(root, offset, 5, 5, 0, 0, 0, BTRFS_FILE_EXTENT_REG, 0,
|
||||
slot);
|
||||
slot++;
|
||||
offset += 5;
|
||||
|
||||
/*
|
||||
* Now we want an inline extent, I don't think this is possible but hey
|
||||
* why not? Also keep in mind if we have an inline extent it counts as
|
||||
* the whole first page. If we were to expand it we would have to cow
|
||||
* and we wouldn't have an inline extent anymore.
|
||||
* Tree-checker has strict limits on inline extents that they can only
|
||||
* exist at file offset 0, thus we can only have one inline file extent
|
||||
* at most.
|
||||
*/
|
||||
insert_extent(root, offset, 1, 1, 0, 0, 0, BTRFS_FILE_EXTENT_INLINE, 0,
|
||||
insert_extent(root, offset, 6, 6, 0, 0, 0, BTRFS_FILE_EXTENT_INLINE, 0,
|
||||
slot);
|
||||
slot++;
|
||||
offset = sectorsize;
|
||||
@ -282,37 +275,25 @@ static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize)
|
||||
test_err("got an error when we shouldn't have");
|
||||
goto out;
|
||||
}
|
||||
if (em->block_start != EXTENT_MAP_HOLE) {
|
||||
test_err("expected a hole, got %llu", em->block_start);
|
||||
goto out;
|
||||
}
|
||||
if (em->start != 0 || em->len != 5) {
|
||||
test_err(
|
||||
"unexpected extent wanted start 0 len 5, got start %llu len %llu",
|
||||
em->start, em->len);
|
||||
goto out;
|
||||
}
|
||||
if (em->flags != 0) {
|
||||
test_err("unexpected flags set, want 0 have %lu", em->flags);
|
||||
goto out;
|
||||
}
|
||||
offset = em->start + em->len;
|
||||
free_extent_map(em);
|
||||
|
||||
em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize);
|
||||
if (IS_ERR(em)) {
|
||||
test_err("got an error when we shouldn't have");
|
||||
goto out;
|
||||
}
|
||||
if (em->block_start != EXTENT_MAP_INLINE) {
|
||||
test_err("expected an inline, got %llu", em->block_start);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (em->start != offset || em->len != (sectorsize - 5)) {
|
||||
/*
|
||||
* For inline extent, we always round up the em to sectorsize, as
|
||||
* they are either:
|
||||
*
|
||||
* a) a hidden hole
|
||||
* The range will be zeroed at inline extent read time.
|
||||
*
|
||||
* b) a file extent with unaligned bytenr
|
||||
* Tree checker will reject it.
|
||||
*/
|
||||
if (em->start != 0 || em->len != sectorsize) {
|
||||
test_err(
|
||||
"unexpected extent wanted start %llu len 1, got start %llu len %llu",
|
||||
offset, em->start, em->len);
|
||||
"unexpected extent wanted start 0 len %u, got start %llu len %llu",
|
||||
sectorsize, em->start, em->len);
|
||||
goto out;
|
||||
}
|
||||
if (em->flags != 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user