diff options
| author | Kyle Evans <kevans@FreeBSD.org> | 2019-04-01 17:44:20 +0000 |
|---|---|---|
| committer | Kyle Evans <kevans@FreeBSD.org> | 2019-04-01 17:44:20 +0000 |
| commit | e1ee62302a50aff33edfd3f8487baee199cab9ec (patch) | |
| tree | ce69916de4c56523fd02ae493c669e94d52b25ad | |
| parent | 8f462da4f3cf6cabcbac87c971634bcdec12fe06 (diff) | |
Notes
| -rw-r--r-- | lib/libbe/be.c | 20 | ||||
| -rwxr-xr-x | sbin/bectl/tests/bectl_test.sh | 9 |
2 files changed, 19 insertions, 10 deletions
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); diff --git a/sbin/bectl/tests/bectl_test.sh b/sbin/bectl/tests/bectl_test.sh index 02aac6aae0099..d1aa7fe8c18a2 100755 --- a/sbin/bectl/tests/bectl_test.sh +++ b/sbin/bectl/tests/bectl_test.sh @@ -123,12 +123,21 @@ bectl_destroy_body() zpool=$(make_zpool_name) disk=${cwd}/disk.img mount=${cwd}/mnt + root=${mount}/root bectl_create_setup ${zpool} ${disk} ${mount} atf_check bectl -r ${zpool}/ROOT create -e default default2 atf_check -o not-empty zfs get mountpoint ${zpool}/ROOT/default2 atf_check -e ignore bectl -r ${zpool}/ROOT destroy default2 atf_check -e not-empty -s not-exit:0 zfs get mountpoint ${zpool}/ROOT/default2 + + # Test origin snapshot deletion when the snapshot to be destroyed + # belongs to a mounted dataset, see PR 236043. + atf_check mkdir -p ${root} + atf_check -o not-empty bectl -r ${zpool}/ROOT mount default ${root} + atf_check bectl -r ${zpool}/ROOT create -e default default3 + atf_check bectl -r ${zpool}/ROOT destroy -o default3 + atf_check bectl -r ${zpool}/ROOT unmount default } bectl_destroy_cleanup() { |
