From 09a3bbfcc5a1a87143d57d5d72afe03c1e31d325 Mon Sep 17 00:00:00 2001 From: kevans Date: Mon, 1 Oct 2018 14:57:33 +0000 Subject: [PATCH] libbe(3): Fix BE activation promoting activated BE This allows older BEs to be destroyed as they become replaced by a BE created from them: e.g. bectl create -e brokenworld fixedworld bectl activate fixedworld bectl destroy brokenworld Submitted by: Shawn Webb Approved by: re (gjb) Obtained from: HardenedBSD (5948c0581e) --- lib/libbe/be.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/libbe/be.c b/lib/libbe/be.c index c1cdd55825fe..2872abed6dec 100644 --- a/lib/libbe/be.c +++ b/lib/libbe/be.c @@ -928,8 +928,9 @@ be_activate(libbe_handle_t *lbh, const char *bootenv, bool temporary) { char be_path[BE_MAXPATHLEN]; char buf[BE_MAXPATHLEN]; - uint64_t pool_guid; nvlist_t *config, *vdevs; + uint64_t pool_guid; + zfs_handle_t *zhp; int err; be_root_concat(lbh, bootenv, be_path); @@ -961,14 +962,19 @@ be_activate(libbe_handle_t *lbh, const char *bootenv, bool temporary) } else { /* Obtain bootenv zpool */ err = zpool_set_prop(lbh->active_phandle, "bootfs", be_path); - - switch (err) { - case 0: - return (BE_ERR_SUCCESS); - - default: - /* XXX TODO correct errors */ + if (err) + return (-1); + + zhp = zfs_open(lbh->lzh, be_path, ZFS_TYPE_FILESYSTEM); + if (zhp == NULL) + return (-1); + + err = zfs_promote(zhp); + zfs_close(zhp); + + if (err) return (-1); - } } + + return (BE_ERR_SUCCESS); }