diff options
author | Qu Wenruo <wqu@suse.com> | 2022-09-16 15:28:36 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2022-12-05 18:00:47 +0100 |
commit | affc5424338682641829cc84293ec90f36425034 (patch) | |
tree | 8963a801828ffe95364a9e2089fe259da0f87e44 /fs/btrfs/inode.c | |
parent | d52a1365258b5781c2635937afa91af66322d981 (diff) | |
download | linux-affc5424338682641829cc84293ec90f36425034.tar.bz2 |
btrfs: make inline extent read calculation much simpler
Currently we calculate inline extent read in a way that inline extent
can start at non-zero offset.
This is consistent with the inode selftests, which puts an inline extent
at file offset 5.
Meanwhile the inline extent creation code will only create inline extent
at file offset 0.
Furthermore with the introduction of tree-checker on file extents, we are
actively rejecting inline extent which starts at non-zero file offset.
And so far we haven't yet seen any report of rejected inline extents at
non-zero file offset.
This all means, the extra calculation to support inline extents at
non-zero file offset is mostly paper weight, and damaging the
readability of the code.
Thus this patch will:
- Add extra ASSERT()s to make sure involved file offset are all 0
- Remove @extent_offset calculation
- Simplify the involved code
As several variables are now single-use, no need to declare them as
a variable anymore.
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 9abed40ade11..a374dd718315 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7064,41 +7064,43 @@ next: extent_type == BTRFS_FILE_EXTENT_PREALLOC) { goto insert; } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { - unsigned long ptr; char *map; - size_t size; - size_t extent_offset; size_t copy_size; if (!page) goto out; - size = btrfs_file_extent_ram_bytes(leaf, item); - extent_offset = page_offset(page) + pg_offset - extent_start; - copy_size = min_t(u64, PAGE_SIZE - pg_offset, - size - extent_offset); - em->start = extent_start + extent_offset; + /* + * Inline extent can only exist at file offset 0. This is + * ensured by tree-checker and inline extent creation path. + * Thus all members representing file offsets should be zero. + */ + ASSERT(page_offset(page) == 0); + ASSERT(pg_offset == 0); + ASSERT(extent_start == 0); + ASSERT(em->start == 0); + + copy_size = min_t(u64, PAGE_SIZE, + btrfs_file_extent_ram_bytes(leaf, item)); + em->start = extent_start; em->len = ALIGN(copy_size, fs_info->sectorsize); em->orig_block_len = em->len; em->orig_start = em->start; - ptr = btrfs_file_extent_inline_start(item) + extent_offset; if (!PageUptodate(page)) { if (btrfs_file_extent_compression(leaf, item) != BTRFS_COMPRESS_NONE) { - ret = uncompress_inline(path, page, pg_offset, - extent_offset, item); + ret = uncompress_inline(path, page, 0, 0, item); if (ret) goto out; } else { map = kmap_local_page(page); - read_extent_buffer(leaf, map + pg_offset, ptr, - copy_size); - if (pg_offset + copy_size < PAGE_SIZE) { - memset(map + pg_offset + copy_size, 0, - PAGE_SIZE - pg_offset - - copy_size); - } + read_extent_buffer(leaf, map, + btrfs_file_extent_inline_start(item), + copy_size); + if (copy_size < PAGE_SIZE) + memset(map + copy_size, 0, + PAGE_SIZE - copy_size); kunmap_local(map); } flush_dcache_page(page); |