From owner-svn-src-projects@freebsd.org Tue Aug 7 03:39:30 2018 Return-Path: Delivered-To: svn-src-projects@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 D56071071F1F for ; Tue, 7 Aug 2018 03:39:30 +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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 84FC97A01C; Tue, 7 Aug 2018 03:39:30 +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 63C29165C7; Tue, 7 Aug 2018 03:39:30 +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 w773dUlp023310; Tue, 7 Aug 2018 03:39:30 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w773dUru023309; Tue, 7 Aug 2018 03:39:30 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808070339.w773dUru023309@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 7 Aug 2018 03:39:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r337409 - projects/bectl/lib/libbe X-SVN-Group: projects X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: projects/bectl/lib/libbe X-SVN-Commit-Revision: 337409 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Aug 2018 03:39:31 -0000 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); }