Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 1 Apr 2019 17:44:20 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r345769 - in head: lib/libbe sbin/bectl/tests
Message-ID:  <201904011744.x31HiK7G051602@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Mon Apr  1 17:44:20 2019
New Revision: 345769
URL: https://svnweb.freebsd.org/changeset/base/345769

Log:
  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 <rob.fx907 gmail com>
  MFC after:	1 week
  Differential Revision:	https://reviews.freebsd.org/D19650

Modified:
  head/lib/libbe/be.c
  head/sbin/bectl/tests/bectl_test.sh

Modified: head/lib/libbe/be.c
==============================================================================
--- head/lib/libbe/be.c	Mon Apr  1 16:36:02 2019	(r345768)
+++ head/lib/libbe/be.c	Mon Apr  1 17:44:20 2019	(r345769)
@@ -265,6 +265,16 @@ be_destroy(libbe_handle_t *lbh, const char *name, int 
 		    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));
@@ -277,16 +287,6 @@ be_destroy(libbe_handle_t *lbh, const char *name, int 
 		if (fs == NULL) {
 			free(bdd.snapname);
 			return (set_error(lbh, BE_ERR_ZFSOPEN));
-		}
-	}
-
-	/* 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));
 		}
 	}
 

Modified: head/sbin/bectl/tests/bectl_test.sh
==============================================================================
--- head/sbin/bectl/tests/bectl_test.sh	Mon Apr  1 16:36:02 2019	(r345768)
+++ head/sbin/bectl/tests/bectl_test.sh	Mon Apr  1 17:44:20 2019	(r345769)
@@ -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()
 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904011744.x31HiK7G051602>