From e1ee62302a50aff33edfd3f8487baee199cab9ec Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Mon, 1 Apr 2019 17:44:20 +0000 Subject: libbe: Fix zfs_is_mounted check w/ snapshots 'be_destroy' can destroy a boot environment (by name) or a given snapshot. If the target to be destroyed is a dataset, check if it's mounted. We don't want to check if the origin dataset is mounted when destroying a snapshot. PR: 236043 Submitted by: Rob Fairbanks MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D19650 --- lib/libbe/be.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'lib/libbe') diff --git a/lib/libbe/be.c b/lib/libbe/be.c index 13c1f66d36280..103ce2aa7ce71 100644 --- a/lib/libbe/be.c +++ b/lib/libbe/be.c @@ -265,6 +265,16 @@ be_destroy(libbe_handle_t *lbh, const char *name, int options) zfs_prop_get(fs, ZFS_PROP_ORIGIN, origin, sizeof(origin), NULL, NULL, 0, 1) != 0) return (set_error(lbh, BE_ERR_NOORIGIN)); + + /* Don't destroy a mounted dataset unless force is specified */ + if ((mounted = zfs_is_mounted(fs, NULL)) != 0) { + if (force) { + zfs_unmount(fs, NULL, 0); + } else { + free(bdd.snapname); + return (set_error(lbh, BE_ERR_DESTROYMNT)); + } + } } else { if (!zfs_dataset_exists(lbh->lzh, path, ZFS_TYPE_SNAPSHOT)) return (set_error(lbh, BE_ERR_NOENT)); @@ -280,16 +290,6 @@ be_destroy(libbe_handle_t *lbh, const char *name, int options) } } - /* Check if mounted, unmount if force is specified */ - if ((mounted = zfs_is_mounted(fs, NULL)) != 0) { - if (force) { - zfs_unmount(fs, NULL, 0); - } else { - free(bdd.snapname); - return (set_error(lbh, BE_ERR_DESTROYMNT)); - } - } - err = be_destroy_cb(fs, &bdd); zfs_close(fs); free(bdd.snapname); -- cgit v1.3