From 7e4a9cbaeedc066adb78380bdf5d016d655070d0 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Mon, 8 May 2023 13:56:54 +1000 Subject: [PATCH] zpool_disable_datasets: on Linux, detach mounts when forcing export On Linux, MNT_FORCE makes the kernel inform that fileystem that its about to call its unmount method so it can begin to eject active IO, making it more likely that the unmount will succeed. This however does not arrange for the unmount method to always succeed; new IO between the two filesystem calls can dirty the filesystem. This is very difficult to lock out properly within ZFS, as not all operations that cause the kernel to dirty the filesystem can easily locked out (eg zfs_lookup). So, we add MNT_DETACH as well. This causes the kernel to first remove the mount from the user namespace, giving the appearance that it has been unmounted (ie no longer appears in /proc/mounts), so that userspace can't reference the filesystem anymore. The unmount then proceeds in the background. Signed-off-by: Rob Norris (cherry picked from commit d2e1634fc935288aa851b5915feaa670c791265c) --- lib/libzfs/libzfs_mount.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/libzfs/libzfs_mount.c b/lib/libzfs/libzfs_mount.c index 261288b768..aecb7a0dff 100644 --- a/lib/libzfs/libzfs_mount.c +++ b/lib/libzfs/libzfs_mount.c @@ -1538,6 +1538,10 @@ zpool_disable_datasets(zpool_handle_t *zhp, boolean_t force, int ret = -1; int flags = ((hardforce || force) ? MS_FORCE : 0); +#ifdef __linux__ + if (hardforce) flags |= MS_DETACH; +#endif + hdl->libzfs_force_export = flags & MS_FORCE; namelen = strlen(zhp->zpool_name);