btrfs-progs: hunt down the stray fd close causing race with udev scan
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest3 patches 6 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | btrfs-progs: rescue: properly close the fs for clear-ino-cachecmds/ | +1 | 1 reply | |
| 2/3 | btrfs-progs: tune: fix the missing close()tune/ | +1 | 1 reply | |
| 3/3 | btrfs-progs: fix the stray fd close in open_ctree_fs_info()kernel-shared/ kernel-shared/ | +16 | 3 replies |
Reviews trailers per patch
2 of 3 patches have a Reviewed-by or Acked-by.
| Patch | Anand Jain |
|---|---|
| 1/3 | R-b |
| 2/3 | R-b |
| 3/3 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH 0/3] btrfs-progs: hunt down the stray fd close causing race with udev scan
Although my previous flock() based solution is preventing udev scan to get pre-mature super blocks, it in fact masks the root problem:
There is a stray close() on writeable fd.
Commit b2a1be83b85f ("btrfs-progs: mkfs: keep file descriptors open during whole time") tries to solve the problem by extending the lifespan of writeable fds, so that when the fds are closed, the fs is ensured to be properly populated.
The problem is, that patch is not covering all cases, there is a stray fd close just under our noses: open_ctree_fs_info().
The function would open the initial device, then use that initial fd to open the btrfs, then we immediately close the initial fd, as later IO would all go with the device fd.
That close() call is causing problem, especially for mkfs, as at that stage the fs is still using a temporary super block, not using the valid btrfs super magic number.
Thus udev scan would race with mkfs, and if udev wins the race, it would get the temporary super block, making libblk not to detect the new btrfs.
This patchset would address the problem by:
- Make sure open_ctree*() calls all have corresponding close_ctree() The first patch, as later we will only close the initial fd caused by open_ctree_fs_info() during close_ctree().
- Save the initial fd into btrfs_fs_info for open_ctree_fs_info() And later close the initial fd during close_ctree().
- Make sure open_ctree_fd() callers to properly close the fd Just an extra cleanup.
This patchset would work even without the usage of flock() to block udev scan, and since without flock() calls, the procedure is much simpler.
Qu Wenruo (3):
btrfs-progs: rescue: properly close the fs for clear-ino-cache
btrfs-progs: tune: fix the missing close()
btrfs-progs: fix the stray fd close in open_ctree_fs_info()
cmds/rescue.c | 1 + kernel-shared/ctree.h | 9 +++++++++ kernel-shared/disk-io.c | 8 +++++++- tune/main.c | 1 + 4 files changed, 18 insertions(+), 1 deletion(-)
--
2.43.0