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)
This commit is contained in:
kevans 2018-10-01 14:57:33 +00:00
parent fef3b3efcb
commit 09a3bbfcc5

View File

@ -928,8 +928,9 @@ be_activate(libbe_handle_t *lbh, const char *bootenv, bool temporary)
{ {
char be_path[BE_MAXPATHLEN]; char be_path[BE_MAXPATHLEN];
char buf[BE_MAXPATHLEN]; char buf[BE_MAXPATHLEN];
uint64_t pool_guid;
nvlist_t *config, *vdevs; nvlist_t *config, *vdevs;
uint64_t pool_guid;
zfs_handle_t *zhp;
int err; int err;
be_root_concat(lbh, bootenv, be_path); be_root_concat(lbh, bootenv, be_path);
@ -961,14 +962,19 @@ be_activate(libbe_handle_t *lbh, const char *bootenv, bool temporary)
} else { } else {
/* Obtain bootenv zpool */ /* Obtain bootenv zpool */
err = zpool_set_prop(lbh->active_phandle, "bootfs", be_path); err = zpool_set_prop(lbh->active_phandle, "bootfs", be_path);
if (err)
switch (err) { return (-1);
case 0:
return (BE_ERR_SUCCESS); zhp = zfs_open(lbh->lzh, be_path, ZFS_TYPE_FILESYSTEM);
if (zhp == NULL)
default: return (-1);
/* XXX TODO correct errors */
err = zfs_promote(zhp);
zfs_close(zhp);
if (err)
return (-1); return (-1);
}
} }
return (BE_ERR_SUCCESS);
} }