Tools like fsck and smartctl are usually used when something bad happens on your disk. But, what if such tools have a problem and also need to be fixed? Well, that’s what we are going to see today.
The command btrfs inspect-internal logical-resolve, as stated in a previous post, is useful when the btrfs filesystem reports a problem related to data consistency, for example:
|
|
Btrfs uses blocks groups and chunks to map logical and physical addresses, respectively. The logical address is needed since btrfs has built-in support for multi device and raid.
To find what is corruped, we need to find what is the file corresponding to the reported logical address, and this is what logical-resolve was designed to do. This tool is currently failing on some cases, as shown below:
|
|
As we can see, the command returned -ENOENT and reported an odd path: ’//@/home’. If you had a similar issue, this is most likely because you are using openSUSE/SLE as your Linux distribution, since these systems use @ as it’s top subvolume. For more details about the subvolume layout used in openSUSE check this post from Richard Brown.
By looking at the problematic path returned we can assume that logical-resolve is using the full subvolume path when searching for the file. This won’t work because the subvolume @ is not mounted, only it’s child subvolume home:
|
|
In this case the tool should start looking at /home, or in other words, it should be looking at where the subvolume is mounted, not at the subvolume path.
Resolving the resolver
We can describe the functionality of logical-resolve in the following steps:
- Execute ioctl BTRFS_IOC_LOGICAL_INO to get all inodes related to the logical address (519704576 in our example), in the root filesystem (/ in our case)
- For each returned inode
- Call btrfs_list_path_for_root to get the subvolume path
- Concatenate the filesystem path (/ in our case) plus the returned subvolume path (/@/home in the example)
- Call btrfs_open_dir using the path create above (//@/home), returning an fd
- Call __ino_to_path_fd using the directory fd from btrfs_open_dir and the inode number
- If __ino_to_path_fd found a valid filename, print the full path (//@/home) plus the filename found.
From the steps shown above we can see that step 2.3 will fail. The path /@ is not accessible, only /home. We can fix the problem by changing the behavior and getting the subvolue mount point instead of the subvolume path.
An astute reader would think that we can get wrong mount points too, like a bind mount that points to a directory within our desired mount point. This was fixed by the commit mentioned in a previous post.
With the bind mount problem resolved, the fixing is a matter of changing step 2.2, like what was done in this patch:
|
|
The new behavior searches for all currently mounted filesystems in order to find the correct mount point related to the subvolume name and subvolume id returned from the BTRFS_IOC_LOGICAL_INO ioctl. This is done by function find_mount_fsroot.
With the most recent version of btrfs-progs, logical-resolve works as expected:
|
|
The package btrfs-progs v5.10 already contains the fixes pointed in this post, so make sure to upgrade your package in order to have a working logical-resolve.
Thanks for reading!