Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Aug 2018 03:39:30 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r337409 - projects/bectl/lib/libbe
Message-ID:  <201808070339.w773dUru023309@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Tue Aug  7 03:39:29 2018
New Revision: 337409
URL: https://svnweb.freebsd.org/changeset/base/337409

Log:
  libbe(3): Destroy all children of a BE dataset, too
  
  This fixes destruction of a deep BE returning an EBUSY because child
  datasets still exist.

Modified:
  projects/bectl/lib/libbe/be.c

Modified: projects/bectl/lib/libbe/be.c
==============================================================================
--- projects/bectl/lib/libbe/be.c	Tue Aug  7 03:26:32 2018	(r337408)
+++ projects/bectl/lib/libbe/be.c	Tue Aug  7 03:39:29 2018	(r337409)
@@ -181,11 +181,22 @@ be_nicenum(uint64_t num, char *buf, size_t buflen)
 	zfs_nicenum(num, buf, buflen);
 }
 
+static int
+be_destroy_cb(zfs_handle_t *zfs_hdl, void *data)
+{
+	int err;
+
+	if ((err = zfs_iter_children(zfs_hdl, be_destroy_cb, data)) != 0)
+		return (err);
+	if ((err = zfs_destroy(zfs_hdl, false)) != 0)
+		return (err);
+	return (0);
+}
+
 /*
  * Destroy the boot environment or snapshot specified by the name
  * parameter. Options are or'd together with the possible values:
  * BE_DESTROY_FORCE : forces operation on mounted datasets
- * TODO: Test destroying a non active but mounted be
  */
 int
 be_destroy(libbe_handle_t *lbh, char *name, int options)
@@ -228,13 +239,14 @@ be_destroy(libbe_handle_t *lbh, char *name, int option
 			return (set_error(lbh, BE_ERR_DESTROYMNT));
 	}
 
+	if ((err = be_destroy_cb(fs, NULL)) != 0) {
+		/* Children are still present or the mount is referenced */
+		if (err == EBUSY)
+			return (set_error(lbh, BE_ERR_DESTROYMNT));
+		return (set_error(lbh, BE_ERR_UNKNOWN));
+	}
 
-	/* XXX TODO: convert this to use zfs_iter_children first for deep BEs */
-	/* XXX Note: errno 16 (device busy) occurs when chilren are present */
-	if ((err = zfs_destroy(fs, false)) != 0)
-		fprintf(stderr, "delete failed errno: %d\n", errno);
-
-	return (err);
+	return (0);
 }
 
 



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