Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Feb 2019 04:00:01 +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: r343993 - head/sbin/bectl
Message-ID:  <201902110400.x1B401Bb063347@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Mon Feb 11 04:00:01 2019
New Revision: 343993
URL: https://svnweb.freebsd.org/changeset/base/343993

Log:
  bectl(8): Add -o flag to destroy to clean up the origin snapshot of BE
  
  We can't predict when destruction of origin is needed, and currently we have
  a precedent for not prompting for things. Leave the decision up to the user
  of bectl(8) if they want the origin snapshot to be destroyed or not.
  
  Emits a warning when -o isn't used and an origin snapshot is left to be
  cleaned up, for the time being. This is handy when one drops the -o flag but
  really did want to clean up the origin.
  
  A couple of -e ignore's have been sprinkled around the test suite for places
  that we don't care that the origin's not been cleaned up. -o functionality
  tests will be added in the future, but are omitted for now to reduce
  conflicts with work in flight to fix bits of the tests.
  
  Reported by:	Shawn Webb
  MFC after:	1 week

Modified:
  head/sbin/bectl/bectl.8
  head/sbin/bectl/bectl.c

Modified: head/sbin/bectl/bectl.8
==============================================================================
--- head/sbin/bectl/bectl.8	Mon Feb 11 00:31:58 2019	(r343992)
+++ head/sbin/bectl/bectl.8	Mon Feb 11 04:00:01 2019	(r343993)
@@ -18,7 +18,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd December 25, 2018
+.Dd February 10, 2019
 .Dt BECTL 8
 .Os
 .Sh NAME
@@ -40,7 +40,7 @@
 .Ar beName@snapshot
 .Nm
 .Cm destroy
-.Op Fl F
+.Op Fl \&Fo
 .Brq Ar beName | beName@snapshot
 .Nm
 .Cm export
@@ -124,7 +124,7 @@ If the
 flag is given, a recursive boot environment will be made.
 .It Xo
 .Cm destroy
-.Op Fl F
+.Op Fl \&Fo
 .Brq Ar beName | beName@snapshot
 .Xc
 Destroys the given
@@ -136,6 +136,14 @@ snapshot without confirmation, unlike in
 Specifying
 .Fl F
 will automatically unmount without confirmation.
+.Pp
+By default,
+.Nm
+will warn that it is not destroying the origin of
+.Ar beName .
+The
+.Fl o
+flag may be specified to destroy the origin as well.
 .It Cm export Ar sourceBe
 Export
 .Ar sourceBe

Modified: head/sbin/bectl/bectl.c
==============================================================================
--- head/sbin/bectl/bectl.c	Mon Feb 11 00:31:58 2019	(r343992)
+++ head/sbin/bectl/bectl.c	Mon Feb 11 04:00:01 2019	(r343993)
@@ -341,16 +341,19 @@ bectl_cmd_add(int argc, char *argv[])
 static int
 bectl_cmd_destroy(int argc, char *argv[])
 {
-	char *target;
-	int opt, err;
-	bool force;
+	nvlist_t *props;
+	char *origin, *target, targetds[BE_MAXPATHLEN];
+	int err, flags, opt;
 
-	force = false;
-	while ((opt = getopt(argc, argv, "F")) != -1) {
+	flags = 0;
+	while ((opt = getopt(argc, argv, "Fo")) != -1) {
 		switch (opt) {
 		case 'F':
-			force = true;
+			flags |= BE_DESTROY_FORCE;
 			break;
+		case 'o':
+			flags |= BE_DESTROY_ORIGIN;
+			break;
 		default:
 			fprintf(stderr, "bectl destroy: unknown option '-%c'\n",
 			    optopt);
@@ -368,7 +371,24 @@ bectl_cmd_destroy(int argc, char *argv[])
 
 	target = argv[0];
 
-	err = be_destroy(be, target, force);
+	/* We'll emit a notice if there's an origin to be cleaned up */
+	if ((flags & BE_DESTROY_ORIGIN) == 0 && strchr(target, '@') == NULL) {
+		if (be_root_concat(be, target, targetds) != 0)
+			goto destroy;
+		if (be_prop_list_alloc(&props) != 0)
+			goto destroy;
+		if (be_get_dataset_props(be, targetds, props) != 0) {
+			be_prop_list_free(props);
+			goto destroy;
+		}
+		if (nvlist_lookup_string(props, "origin", &origin) == 0)
+			fprintf(stderr, "bectl destroy: leaving origin '%s' intact\n",
+			    origin);
+		be_prop_list_free(props);
+	}
+
+destroy:
+	err = be_destroy(be, target, flags);
 
 	return (err);
 }



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