-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lazy unmount issues #876
Comments
Each btrfs subvol has its own minor number. As a result, the proposed Other possible solutions for the original problem:
IMHO option 3 and 4 are the easiest to implement within btrfs, and support the greatest number of immediately useful use cases. Option 1 requires no changes to btrfs at all. Option 2 is presented for completeness as it's the solution other operating systems use, but there would be challenges implementing it on a Linux kernel. |
1, seems reasonable as it doesn't hide the issue. Lazy unmounts have caused headaches for me in the past. This leads me to option 2, which I think is the best solution. It is what users expect should be possible, like with the USB device or other portable media. Option 3 seems dangerous. What happens if the open fd starts writing data? How would existing tools and workflow handle a suddenly new UUID? Not sure about option 4. What device should be dropped if a process is holding the filesystem mounted? |
Option 4 is there to address some of the risks of option 3 (none of the options are mutually exclusive). If the underlying device is disconnected, a FD will get IO errors whenever it touches the disconnected device, and btrfs will force read-only at the next transaction commit. It is up to each process to close all file descriptors on the filesystem, and the last one to do so completes the umount. If a process with an open FD never exits and never closes the FD, the filesystem is never umounted. If the underlying device is not disconnected, then the open FD on the lazy-umounted filesystem behaves like a FD on a normally-mounted filesystem. In that case, we want things to continue as they do now, with the btrfs UUID locked against allowing any other device to mount with the same fs UUID.
The same way they currently handle running
Whichever device is specified through the sysfs interface, e.g. This could be used as a proactive measure to ensure a filesystem that was lazy-umounted and UUID-changed does not have any lingering connections to physical devices. In the normal USB disconnect case this isn't a problem, but in other cases, such as when a dm-crypt layer is inserted in between, or when the user mistakenly believes the filesystem is disconnected when it is not, the deletion events from the device layer might not reach the filesystem. So you'd do something like
that would disconnect all the devices and change the uuid of the filesystem. This would allow the same filesystem to be mounted again when the devices are reconnected, while not changing anything else about lazy umounts (neither the kernel nor systemd/udevd). Note that after applying options 3 and 4, the original filesystem remains mounted, but with no accessible mount points, and with no readable or writable devices. It's going to dump a ton of noise into the kernel log until the last FDs on the filesystem are closed. lsof and similar tools will not be able to resolve the paths to these files, but it will be possible to mount the filesystem if its block devices are reconnected, similar to what happens to ext4 in this situation. |
Hello!
Lazy unmount happens automatically when device removed by (udev or systemd) when USB sticks with btrfs on got disconnected.
As result if any process holding any files (cwd, root, fd) from target lazy unmounted fs it will cause to lock down and as result will required to reboot the system.
For ext4 you can remount it second time no problem while previous lazy unmount keep busy waiting. But btrfs does not allow that.
Simple solution would be looking for opened files using 'lsof' but because of lazy unmount all path are cut that makes it impossible to find which process is holding btrfs file system and underlaying (md-luks device).
That is very old and known issues by users. You can google it.
It would be possible to find lazy unmouted process using lsof, but you have to know device major and minor number. For all btrfs mounts it is virtual devices with major == 0. When file system is mounted you can run 'stat /media/root/LABEL' to see device minor number which can be used to identify process working with that fs. But if device got disconnected that would be not possible to know device minor number.
Right now here is no way fixing that only option is to reboot.
It would be possible to fix if /sys/fs/btrfs/*/device_minor property will show device minor number used to mount filesystem.
In that case 'lsof | grep 0,MINOR' will show all processes holding btrfs filesystem.
The text was updated successfully, but these errors were encountered: