btrfs-progs/common
Qu Wenruo 85225ea00a btrfs-progs: fix a false failure for inode cache cleanup
[BUG]
There is one report about `btrfs rescue clear-ino-cache` failed with
tree block level mismatch:

 # btrfs rescue clear-ino-cache /dev/mapper/rootext
 Successfully cleaned up ino cache for root id: 5
 Successfully cleaned up ino cache for root id: 257
 Successfully cleaned up ino cache for root id: 258
 corrupt node: root=7 block=647369064448 slot=0, invalid level for leaf, have 1 expect 0
 node 647369064448 level 1 items 252 free space 241 generation 6065173 owner CSUM_TREE
 node 647369064448 flags 0x1(WRITTEN) backref revision 1
 fs uuid e6614f01-6f56-4776-8b0a-c260089c35e7
 chunk uuid f665f535-4cfd-49e0-8be9-7f94bf59b75d
     key (EXTENT_CSUM EXTENT_CSUM 3714473984) block 677126111232 gen 6065002
     [...]
     key (EXTENT_CSUM EXTENT_CSUM 6192357376) block 646396493824 gen 6065032
 ERROR: failed to clear ino cache: Input/output error

[CAUSE]
During `btrfs rescue clear-ino-cache`, btrfs-progs will iterate through
all the subvolumes, and clear the inode cache inode from each subvolume.

The problem is in how we iterate the subvolumes.

We hold a path of tree root, and go modifiy the fs for each found
subvolume, then call btrfs_next_item().

This is not safe, because the path to tree root is not longer reliable
if we modified the fs.

So the btrfs_next_item() call will fail because the fs is modified
halfway, resulting the above problem.

[FIX]
Instead of holding a path to a subvolume root item, and modify the fs
halfway, here introduce a helper, find_next_root(), to locate the root
item whose objectid >= our target rootid, and return the found item key.

The path to root tree is only hold then released inside
find_next_root().

By this, we won't hold any unrelated path while modifying the
filesystem.

And since we're here, also adding back the missing new line when all ino
cache is cleared.

Pull-request: #890
Reported-by: Archange <archange@archlinux.org>
Link: https://lore.kernel.org/linux-btrfs/4803f696-2dc5-4987-a353-fce1272e93e7@archlinux.org/
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-09-17 14:33:22 +02:00
..
array.c btrfs-progs: run codespell throughout fixing typos automagically 2024-07-30 19:56:08 +02:00
array.h btrfs-progs: add an extensible pointer array struct 2023-08-28 17:24:24 +02:00
box.h btrfs-progs: add btrfs-find-root to btrfs.box 2023-07-26 15:00:48 +02:00
clear-cache.c btrfs-progs: fix a false failure for inode cache cleanup 2024-09-17 14:33:22 +02:00
clear-cache.h btrfs-progs: move clear-cache.[ch] from check/ to common/ directory 2023-10-13 18:13:12 +02:00
cpu-utils.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
cpu-utils.h btrfs-progs: detect PCLMUL CPU support for accelerated crc32c 2023-09-13 00:38:50 +02:00
defs.h
device-scan.c btrfs-progs: rename and move __strncpy_null to string-utils 2024-06-24 19:18:46 +02:00
device-scan.h btrfs-progs: replace btrfs_open_dir with btrfs_open_dir_fd 2024-02-20 11:40:08 +01:00
device-utils.c btrfs-progs: support byte length for zone resetting 2024-06-03 21:26:39 +02:00
device-utils.h btrfs-progs: convert defined constants to enums 2024-02-08 08:30:37 +01:00
extent-cache.c btrfs-progs: make all parameters of rb_tree search/insert const 2024-03-12 21:43:54 +01:00
extent-cache.h
extent-tree-utils.c btrfs-progs: reorder key initializations 2024-04-30 21:49:15 +02:00
extent-tree-utils.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
filesystem-utils.c btrfs-progs: open the devices exclusively for writes 2024-09-17 14:33:22 +02:00
filesystem-utils.h
format-output.c btrfs-progs: properly close va_copy in fmt_set_unquoted() 2024-04-18 19:16:15 +02:00
format-output.h btrfs-progs: rename time-long format name to date-time 2023-08-28 17:24:23 +02:00
fsfeatures.c btrfs-progs: move RST back to experimental 2024-06-24 19:18:32 +02:00
fsfeatures.h btrfs-progs: convert: remove raid-stripe-tree support 2024-06-24 19:18:25 +02:00
help.c btrfs-progs: use strncpy_null everywhere 2024-06-24 19:18:48 +02:00
help.h btrfs-progs: add support for dry-run options 2023-11-03 18:04:37 +01:00
inject-error.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
inject-error.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
internal.h btrfs-progs: pull in the full max/min/clamp implementation from kernel 2023-10-10 19:16:29 +02:00
messages.c btrfs-progs: handle write errors in btrfs_add_to_fsid() 2024-03-16 22:25:50 +01:00
messages.h btrfs-progs: add uClibc-ng compatibility for printf format %pV 2024-07-30 19:53:33 +02:00
open-utils.c btrfs-progs: use strncpy_null everywhere 2024-06-24 19:18:48 +02:00
open-utils.h btrfs-progs: rename btrfs_open_fd2() to btrfs_open_path() 2024-02-20 12:59:29 +01:00
parse-utils.c btrfs-progs: implement arg_strtou64_with_suffix() with a new helper 2024-01-18 02:14:23 +01:00
parse-utils.h btrfs-progs: implement arg_strtou64_with_suffix() with a new helper 2024-01-18 02:14:23 +01:00
path-utils.c btrfs-progs: rename and move __strncpy_null to string-utils 2024-06-24 19:18:46 +02:00
path-utils.h btrfs-progs: rename and move __strncpy_null to string-utils 2024-06-24 19:18:46 +02:00
rbtree-utils.c btrfs-progs: make all parameters of rb_tree search/insert const 2024-03-12 21:43:54 +01:00
rbtree-utils.h btrfs-progs: make all parameters of rb_tree search/insert const 2024-03-12 21:43:54 +01:00
root-tree-utils.c btrfs-progs: introduce btrfs_rebuild_uuid_tree() for mkfs and btrfs-convert 2024-07-30 20:02:56 +02:00
root-tree-utils.h btrfs-progs: introduce btrfs_rebuild_uuid_tree() for mkfs and btrfs-convert 2024-07-30 20:02:56 +02:00
send-stream.c btrfs-progs: run codespell throughout fixing typos automagically 2024-07-30 19:56:08 +02:00
send-stream.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
send-utils.c btrfs-progs: move uuid-tree definitions to kernel-shared/uuid-tree.h 2024-07-30 20:01:59 +02:00
send-utils.h btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
sort-utils.c btrfs-progs: run codespell throughout fixing typos automagically 2024-07-30 19:56:08 +02:00
sort-utils.h btrfs-progs: run codespell throughout fixing typos automagically 2024-07-30 19:56:08 +02:00
string-table.c btrfs-progs: string-table: fix memory leak on exit path in table_vprintf() 2024-04-18 19:16:15 +02:00
string-table.h
string-utils.c btrfs-progs: factor string escaping helpers from receive dump 2024-07-30 19:53:33 +02:00
string-utils.h btrfs-progs: factor string escaping helpers from receive dump 2024-07-30 19:53:33 +02:00
sysfs-utils.c btrfs-progs: change all sysfs helpers to return errno 2023-12-09 01:17:22 +01:00
sysfs-utils.h btrfs-progs: add write helpers for sysfs files 2023-12-09 01:17:22 +01:00
task-utils.c
task-utils.h
tree-search.h btrfs-progs: add API for selecting tree search support and ioctl 2024-03-16 18:08:38 +01:00
units.c
units.h
utils.c btrfs-progs: reorder key initializations 2024-04-30 21:49:15 +02:00
utils.h btrfs-progs: convert: insert a dummy inode item before inode ref for ext2/4 2024-01-17 01:47:39 +01:00