From 1d901c3ee5965e9b3b4c33cd40942bcf9df2531a Mon Sep 17 00:00:00 2001 From: Jorgen Lundman Date: Tue, 21 Sep 2021 00:29:59 +0900 Subject: [PATCH] Upstream: unmount snapshots before destroying them on macOS Add function zfs_destroy_snaps_nvl_os() call. The main issue is that macOS needs to unmount any mounted snapshots before they can be destroyed. Other platforms can handle this in the kernel, but sending a storm of zed events to unmount seems undesirable when we can do it in userland to start with. Reviewed-by: Brian Behlendorf Reviewed-by: John Kennedy Signed-off-by: Jorgen Lundman Co-authored-by: ilovezfs Closes #12550 --- include/libzfs.h | 1 + lib/libzfs/libzfs.abi | 6 ++++++ lib/libzfs/libzfs_dataset.c | 5 ++++- lib/libzfs/os/freebsd/libzfs_compat.c | 6 ++++++ lib/libzfs/os/linux/libzfs_util_os.c | 6 ++++++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/libzfs.h b/include/libzfs.h index 270f810027..c0883a9836 100644 --- a/include/libzfs.h +++ b/include/libzfs.h @@ -650,6 +650,7 @@ _LIBZFS_H int zfs_create_ancestors(libzfs_handle_t *, const char *); _LIBZFS_H int zfs_destroy(zfs_handle_t *, boolean_t); _LIBZFS_H int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t); _LIBZFS_H int zfs_destroy_snaps_nvl(libzfs_handle_t *, nvlist_t *, boolean_t); +_LIBZFS_H int zfs_destroy_snaps_nvl_os(libzfs_handle_t *, nvlist_t *); _LIBZFS_H int zfs_clone(zfs_handle_t *, const char *, nvlist_t *); _LIBZFS_H int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *); diff --git a/lib/libzfs/libzfs.abi b/lib/libzfs/libzfs.abi index a2c79c8568..c5b0975258 100644 --- a/lib/libzfs/libzfs.abi +++ b/lib/libzfs/libzfs.abi @@ -97,6 +97,7 @@ + @@ -4161,6 +4162,11 @@ + + + + + diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c index 20251e9e7a..fb337ca3f0 100644 --- a/lib/libzfs/libzfs_dataset.c +++ b/lib/libzfs/libzfs_dataset.c @@ -3884,10 +3884,13 @@ zfs_destroy_snaps(zfs_handle_t *zhp, char *snapname, boolean_t defer) int zfs_destroy_snaps_nvl(libzfs_handle_t *hdl, nvlist_t *snaps, boolean_t defer) { - int ret; nvlist_t *errlist = NULL; nvpair_t *pair; + int ret = zfs_destroy_snaps_nvl_os(hdl, snaps); + if (ret != 0) + return (ret); + ret = lzc_destroy_snaps(snaps, defer, &errlist); if (ret == 0) { diff --git a/lib/libzfs/os/freebsd/libzfs_compat.c b/lib/libzfs/os/freebsd/libzfs_compat.c index 4d7421df8d..2c9d52bb0f 100644 --- a/lib/libzfs/os/freebsd/libzfs_compat.c +++ b/lib/libzfs/os/freebsd/libzfs_compat.c @@ -267,6 +267,12 @@ find_shares_object(differ_info_t *di) return (0); } +int +zfs_destroy_snaps_nvl_os(libzfs_handle_t *hdl, nvlist_t *snaps) +{ + return (0); +} + /* * Attach/detach the given filesystem to/from the given jail. */ diff --git a/lib/libzfs/os/linux/libzfs_util_os.c b/lib/libzfs/os/linux/libzfs_util_os.c index b116f92d97..2ac31f1077 100644 --- a/lib/libzfs/os/linux/libzfs_util_os.c +++ b/lib/libzfs/os/linux/libzfs_util_os.c @@ -184,6 +184,12 @@ find_shares_object(differ_info_t *di) return (0); } +int +zfs_destroy_snaps_nvl_os(libzfs_handle_t *hdl, nvlist_t *snaps) +{ + return (0); +} + /* * Fill given version buffer with zfs kernel version read from ZFS_SYSFS_DIR * Returns 0 on success, and -1 on error (with errno set)