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
This commit is contained in:
kevans 2019-02-11 04:00:01 +00:00
parent 5e8683b78d
commit 4d060aa696
2 changed files with 38 additions and 10 deletions

View File

@ -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

View File

@ -341,15 +341,18 @@ 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",
@ -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);
}