From owner-svn-src-all@freebsd.org Mon Feb 11 04:00:02 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7477D14E76BB; Mon, 11 Feb 2019 04:00:02 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 19D8E81DF5; Mon, 11 Feb 2019 04:00:02 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 086D02256D; Mon, 11 Feb 2019 04:00:02 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x1B401wZ063349; Mon, 11 Feb 2019 04:00:01 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x1B401Bb063347; Mon, 11 Feb 2019 04:00:01 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201902110400.x1B401Bb063347@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Mon, 11 Feb 2019 04:00:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r343993 - head/sbin/bectl X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/sbin/bectl X-SVN-Commit-Revision: 343993 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 19D8E81DF5 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_SHORT(-0.97)[-0.972,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Feb 2019 04:00:02 -0000 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); }