linux-stable/fs/btrfs
Filipe Manana 636048d4cd btrfs: fix backref walking not returning all inode refs
commit 0cad8f14d7 upstream.

When using the logical to ino ioctl v2, if the flag to ignore offsets of
file extent items (BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET) is given, the
backref walking code ends up not returning references for all file offsets
of an inode that point to the given logical bytenr. This happens since
kernel 6.2, commit 6ce6ba5344 ("btrfs: use a single argument for extent
offset in backref walking functions") because:

1) It mistakenly skipped the search for file extent items in a leaf that
   point to the target extent if that flag is given. Instead it should
   only skip the filtering done by check_extent_in_eb() - that is, it
   should not avoid the calls to that function (or find_extent_in_eb(),
   which uses it).

2) It was also not building a list of inode extent elements (struct
   extent_inode_elem) if we have multiple inode references for an extent
   when the ignore offset flag is given to the logical to ino ioctl - it
   would leave a single element, only the last one that was found.

These stem from the confusing old interface for backref walking functions
where we had an extent item offset argument that was a pointer to a u64
and another boolean argument that indicated if the offset should be
ignored, but the pointer could be NULL. That NULL case is used by
relocation, qgroup extent accounting and fiemap, simply to avoid building
the inode extent list for each reference, as it's not necessary for those
use cases and therefore avoids memory allocations and some computations.

Fix this by adding a boolean argument to the backref walk context
structure to indicate that the inode extent list should not be built,
make relocation set that argument to true and fix the backref walking
logic to skip the calls to check_extent_in_eb() and find_extent_in_eb()
only if this new argument is true, instead of 'ignore_extent_item_pos'
being true.

A test case for fstests will be added soon, to provide cover not only
for these cases but to the logical to ino ioctl in general as well, as
currently we do not have a test case for it.

Reported-by: Vladimir Panteleev <git@vladimir.panteleev.md>
Link: https://lore.kernel.org/linux-btrfs/CAHhfkvwo=nmzrJSqZ2qMfF-rZB-ab6ahHnCD_sq9h4o8v+M7QQ@mail.gmail.com/
Fixes: 6ce6ba5344 ("btrfs: use a single argument for extent offset in backref walking functions")
CC: stable@vger.kernel.org # 6.2+
Tested-by: Vladimir Panteleev <git@vladimir.panteleev.md>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-05-17 13:58:58 +02:00
..
tests btrfs: drop private_data parameter from extent_io_tree_init 2022-12-05 18:00:54 +01:00
Kconfig btrfs: use generic Kconfig option for 256kB page size limit 2022-01-20 08:52:55 +02:00
Makefile btrfs: split the bio submission path into a separate file 2022-12-05 18:00:57 +01:00
accessors.c btrfs: add eb to btrfs_node_key_ptr_offset 2022-12-05 18:00:58 +01:00
accessors.h btrfs: add stack helpers for a few btrfs items 2022-12-05 18:00:58 +01:00
acl.c for-6.2-tag 2022-12-12 20:47:51 -08:00
acl.h for-6.2-tag 2022-12-12 20:47:51 -08:00
async-thread.c btrfs: simplify WQ_HIGHPRI handling in struct btrfs_workqueue 2022-05-16 17:03:15 +02:00
async-thread.h btrfs: remove unused typedefs get_extent_t and btrfs_work_func_t 2022-07-25 17:45:36 +02:00
backref.c btrfs: fix backref walking not returning all inode refs 2023-05-17 13:58:58 +02:00
backref.h btrfs: fix backref walking not returning all inode refs 2023-05-17 13:58:58 +02:00
bio.c btrfs: fix unnecessary increment of read error stat on write error 2023-03-17 08:57:45 +01:00
bio.h btrfs: split the bio submission path into a separate file 2022-12-05 18:00:57 +01:00
block-group.c btrfs: use temporary variable for space_info in btrfs_update_block_group 2023-04-06 12:12:31 +02:00
block-group.h btrfs: convert btrfs_block_group::seq_zone to runtime flag 2022-12-05 18:00:51 +01:00
block-rsv.c btrfs: don't free qgroup space unless specified 2023-05-17 13:58:57 +02:00
block-rsv.h btrfs: simplify percent calculation helpers, rename div_factor 2022-12-05 18:00:48 +01:00
btrfs_inode.h btrfs: pass btrfs_inode to btrfs_add_delayed_iput 2022-12-05 18:00:55 +01:00
check-integrity.c btrfs: use btrfs_dev_name() helper to handle missing devices better 2022-12-05 18:00:57 +01:00
check-integrity.h btrfs: check-integrity: split submit_bio from btrfsic checking 2022-05-16 17:03:12 +02:00
compression.c btrfs: split the bio submission path into a separate file 2022-12-05 18:00:57 +01:00
compression.h btrfs: constify input buffer parameter in compression code 2022-12-05 18:00:55 +01:00
ctree.c btrfs: fix btrfs_prev_leaf() to not return the same key twice 2023-05-17 13:58:56 +02:00
ctree.h fs.acl.rework.v6.2 2022-12-12 18:46:39 -08:00
defrag.c btrfs: fix an error handling path in btrfs_defrag_leaves() 2022-12-15 19:16:50 +01:00
defrag.h btrfs: move defrag related prototypes to their own header 2022-12-05 18:00:46 +01:00
delalloc-space.c btrfs: update function comments 2022-12-05 18:00:45 +01:00
delalloc-space.h btrfs: move delalloc space related prototypes to delalloc-space.h 2022-12-05 18:00:44 +01:00
delayed-inode.c btrfs: pass btrfs_inode to btrfs_inode_unlock 2022-12-05 18:00:53 +01:00
delayed-inode.h btrfs: extend btrfs_dir_item type to store encryption status 2022-12-05 18:00:43 +01:00
delayed-ref.c btrfs: update function comments 2022-12-05 18:00:45 +01:00
delayed-ref.h btrfs: remove btrfs_delayed_extent_op::is_data 2022-05-16 17:17:31 +02:00
dev-replace.c btrfs: use btrfs_dev_name() helper to handle missing devices better 2022-12-05 18:00:57 +01:00
dev-replace.h btrfs: move dev-replace prototypes into dev-replace.h 2022-12-05 18:00:47 +01:00
dir-item.c btrfs: move dir-item prototypes into dir-item.h 2022-12-05 18:00:46 +01:00
dir-item.h btrfs: move dir-item prototypes into dir-item.h 2022-12-05 18:00:46 +01:00
discard.c btrfs: reinterpret async discard iops_limit=0 as no delay 2023-04-26 14:30:02 +02:00
discard.h btrfs: cleanup btrfs_discard_update_discardable usage 2020-12-08 15:54:02 +01:00
disk-io.c btrfs: make clear_cache mount option to rebuild FST without disabling it 2023-05-17 13:58:57 +02:00
disk-io.h btrfs: fix compat_ro checks against remount 2023-01-03 16:22:13 +01:00
export.c btrfs: move super_block specific helpers into super.h 2022-12-05 18:00:47 +01:00
export.h btrfs: simplify generation check in btrfs_get_dentry 2022-12-05 18:00:41 +01:00
extent-io-tree.c btrfs: fix off-by-one in delalloc search during lseek 2023-01-03 15:53:18 +01:00
extent-io-tree.h btrfs: allow passing a cached state record to count_range_bits() 2022-12-05 18:00:56 +01:00
extent-tree.c btrfs: always report error in run_one_delayed_ref() 2023-01-03 16:22:10 +01:00
extent-tree.h btrfs: move the snapshot drop related prototypes to extent-tree.h 2022-12-05 18:00:46 +01:00
extent_io.c btrfs: lock the inode in shared mode before starting fiemap 2023-02-09 17:02:27 +01:00
extent_io.h btrfs: move eb offset helpers into extent_io.h 2022-12-05 18:00:58 +01:00
extent_map.c btrfs: fix extent map logging bit not cleared for split maps after dropping range 2023-03-17 08:57:56 +01:00
extent_map.h btrfs: remove no longer used btrfs_next_extent_map() 2022-12-05 18:00:56 +01:00
file-item.c btrfs: fix encoded write i_size corruption with no-holes 2023-05-17 13:58:57 +02:00
file-item.h btrfs: move file_extent_item helpers into file-item.h 2022-12-05 18:00:58 +01:00
file.c btrfs: fix invalid leaf access due to inline extent during lseek 2023-01-16 19:46:38 +01:00
file.h btrfs: use cached state when looking for delalloc ranges with fiemap 2022-12-05 18:00:56 +01:00
free-space-cache.c btrfs: fix space cache inconsistency after error loading it from disk 2023-05-17 13:58:58 +02:00
free-space-cache.h btrfs: convert discard stat defs to enum 2022-12-05 18:00:45 +01:00
free-space-tree.c btrfs: make clear_cache mount option to rebuild FST without disabling it 2023-05-17 13:58:57 +02:00
free-space-tree.h btrfs: make clear_cache mount option to rebuild FST without disabling it 2023-05-17 13:58:57 +02:00
fs.c btrfs: sysfs: update fs features directory asynchronously 2023-03-10 09:29:27 +01:00
fs.h btrfs: rename BTRFS_FS_NO_OVERCOMMIT to BTRFS_FS_ACTIVE_ZONE_TRACKING 2023-04-06 12:12:23 +02:00
inode-item.c btrfs: move file-item prototypes into their own header 2022-12-05 18:00:46 +01:00
inode-item.h btrfs: use struct fscrypt_str instead of struct qstr 2022-12-05 18:00:43 +01:00
inode.c btrfs: zoned: zone finish data relocation BG with last IO 2023-05-17 13:58:58 +02:00
ioctl.c btrfs: fix assertion of exclop condition when starting balance 2023-05-17 13:58:57 +02:00
ioctl.h btrfs: move ioctl prototypes into ioctl.h 2022-12-05 18:00:46 +01:00
locking.c btrfs: move accessor helpers into accessors.h 2022-12-05 18:00:42 +01:00
locking.h btrfs: move the lockdep helpers into locking.h 2022-12-05 18:00:44 +01:00
lzo.c btrfs: constify input buffer parameter in compression code 2022-12-05 18:00:55 +01:00
messages.c btrfs: move super_block specific helpers into super.h 2022-12-05 18:00:47 +01:00
messages.h btrfs: print transaction aborted messages with an error level 2022-12-05 18:00:59 +01:00
misc.h btrfs: simplify percent calculation helpers, rename div_factor 2022-12-05 18:00:48 +01:00
ordered-data.c for-6.2-tag 2022-12-12 20:47:51 -08:00
ordered-data.h btrfs: use cached_state for btrfs_check_nocow_lock 2022-12-05 18:00:36 +01:00
orphan.c btrfs: move orphan prototypes into orphan.h 2022-12-05 18:00:47 +01:00
orphan.h btrfs: move orphan prototypes into orphan.h 2022-12-05 18:00:47 +01:00
print-tree.c btrfs: print-tree: parent bytenr must be aligned to sector size 2023-05-17 13:58:57 +02:00
print-tree.h btrfs: print the actual offset in btrfs_root_name 2021-01-07 17:25:05 +01:00
props.c btrfs: move super_block specific helpers into super.h 2022-12-05 18:00:47 +01:00
props.h btrfs: make module init/exit match their sequence 2022-12-05 18:00:40 +01:00
qgroup.c btrfs: fix race between quota disable and quota assign ioctls 2023-04-06 12:12:41 +02:00
qgroup.h btrfs: sink gfp_t parameter to btrfs_qgroup_trace_extent 2022-12-05 18:00:43 +01:00
raid56.c btrfs: raid56: make error_bitmap update atomic 2023-01-27 14:57:10 +01:00
raid56.h btrfs: raid56: prepare data checksums for later RMW verification 2022-12-05 18:00:57 +01:00
rcu-string.h btrfs: replace strncpy() with strscpy() 2022-12-05 18:00:59 +01:00
ref-verify.c btrfs: move accessor helpers into accessors.h 2022-12-05 18:00:42 +01:00
ref-verify.h
reflink.c btrfs: pass btrfs_inode to btrfs_inode_unlock 2022-12-05 18:00:53 +01:00
reflink.h
relocation.c btrfs: fix backref walking not returning all inode refs 2023-05-17 13:58:58 +02:00
relocation.h btrfs: move relocation prototypes into relocation.h 2022-12-05 18:00:47 +01:00
root-tree.c btrfs: move orphan prototypes into orphan.h 2022-12-05 18:00:47 +01:00
root-tree.h btrfs: move root tree prototypes to their own header 2022-12-05 18:00:44 +01:00
scrub.c btrfs: scrub: improve tree block error reporting 2023-03-10 09:29:06 +01:00
scrub.h btrfs: move scrub prototypes into scrub.h 2022-12-05 18:00:47 +01:00
send.c btrfs: fix uninitialized variable warnings 2023-05-01 08:29:23 +09:00
send.h btrfs: send add define for v2 buffer size 2022-12-05 18:00:41 +01:00
space-info.c btrfs: zoned: drop space_info->active_total_bytes 2023-04-06 12:12:24 +02:00
space-info.h btrfs: zoned: drop space_info->active_total_bytes 2023-04-06 12:12:24 +02:00
subpage.c btrfs: move the printk helpers out of ctree.h 2022-12-05 18:00:41 +01:00
subpage.h btrfs: make nodesize >= PAGE_SIZE case to reuse the non-subpage routine 2022-05-16 17:03:11 +02:00
super.c btrfs: make clear_cache mount option to rebuild FST without disabling it 2023-05-17 13:58:57 +02:00
super.h btrfs: move super_block specific helpers into super.h 2022-12-05 18:00:47 +01:00
sysfs.c btrfs: sysfs: update fs features directory asynchronously 2023-03-10 09:29:27 +01:00
sysfs.h btrfs: sysfs: update fs features directory asynchronously 2023-03-10 09:29:27 +01:00
transaction.c btrfs: fix deadlock when aborting transaction during relocation with scrub 2023-04-06 12:12:41 +02:00
transaction.h btrfs: remove fs_info::pending_changes and related code 2022-12-05 18:00:42 +01:00
tree-checker.c btrfs: pass the extent buffer for the btrfs_item_nr helpers 2022-12-05 18:00:58 +01:00
tree-checker.h btrfs: move struct btrfs_tree_parent_check out of disk-io.h 2022-12-05 18:00:57 +01:00
tree-log.c btrfs: simplify update of last_dir_index_offset when logging a directory 2023-02-06 23:08:17 +01:00
tree-log.h btrfs: simplify update of last_dir_index_offset when logging a directory 2023-02-06 23:08:17 +01:00
tree-mod-log.c btrfs: add eb to btrfs_node_key_ptr_offset 2022-12-05 18:00:58 +01:00
tree-mod-log.h btrfs: fix SPDX comment in tree-mod-log.h 2022-12-05 18:00:48 +01:00
ulist.c btrfs: constify ulist parameter of ulist_next() 2022-12-05 18:00:50 +01:00
ulist.h btrfs: constify ulist parameter of ulist_next() 2022-12-05 18:00:50 +01:00
uuid-tree.c btrfs: move uuid tree prototypes to uuid-tree.h 2022-12-05 18:00:46 +01:00
uuid-tree.h btrfs: move uuid tree prototypes to uuid-tree.h 2022-12-05 18:00:46 +01:00
verity.c btrfs: move orphan prototypes into orphan.h 2022-12-05 18:00:47 +01:00
verity.h btrfs: move verity prototypes into verity.h 2022-12-05 18:00:47 +01:00
volumes.c btrfs: fix uninitialized variable warnings 2023-05-01 08:29:23 +09:00
volumes.h btrfs: split the bio submission path into a separate file 2022-12-05 18:00:57 +01:00
xattr.c btrfs: move dir-item prototypes into dir-item.h 2022-12-05 18:00:46 +01:00
xattr.h
zlib.c btrfs: zlib: zero-initialize zlib workspace 2023-01-25 20:11:08 +01:00
zoned.c btrfs: zoned: fix full zone super block reading on ZNS 2023-05-17 13:58:58 +02:00
zoned.h btrfs: move the printk helpers out of ctree.h 2022-12-05 18:00:41 +01:00
zstd.c btrfs: constify input buffer parameter in compression code 2022-12-05 18:00:55 +01:00