libbe(3): Fix destroy of imported BE w/ AUTOORIGIN

Imported BE, much like the activated BE, will not have an origin that we can
fetch/examine for destruction. be_destroy should not return BE_ERR_NOORIGIN
for failure to get the origin property for BE_DESTROY_AUTOORIGIN, because
we don't really know going into it that there's even an origin to be
destroyed.

BE_DESTROY_NEEDORIGIN has been renamed to BE_DESTROY_WANTORIGIN because only
a subset of it *needs* the origin, so 'need' is too strong of verbiage.

This was caught by jenkins and the bectl tests, but kevans failed to run the
bectl tests prior to commit.

Reported by:	lwhsu
This commit is contained in:
Kyle Evans 2019-10-16 18:33:31 +00:00
parent f677fed5a2
commit 1dc8556358

View File

@ -229,7 +229,7 @@ be_destroy_cb(zfs_handle_t *zfs_hdl, void *data)
return (0);
}
#define BE_DESTROY_NEEDORIGIN (BE_DESTROY_ORIGIN | BE_DESTROY_AUTOORIGIN)
#define BE_DESTROY_WANTORIGIN (BE_DESTROY_ORIGIN | BE_DESTROY_AUTOORIGIN)
/*
* Destroy the boot environment or snapshot specified by the name
* parameter. Options are or'd together with the possible values:
@ -265,9 +265,10 @@ be_destroy(libbe_handle_t *lbh, const char *name, int options)
if (fs == NULL)
return (set_error(lbh, BE_ERR_ZFSOPEN));
if ((options & BE_DESTROY_NEEDORIGIN) != 0 &&
if ((options & BE_DESTROY_WANTORIGIN) != 0 &&
zfs_prop_get(fs, ZFS_PROP_ORIGIN, origin, sizeof(origin),
NULL, NULL, 0, 1) != 0)
NULL, NULL, 0, 1) != 0 &&
(options & BE_DESTROY_ORIGIN) != 0)
return (set_error(lbh, BE_ERR_NOORIGIN));
/*
@ -279,7 +280,7 @@ be_destroy(libbe_handle_t *lbh, const char *name, int options)
* the caller can determine if it needs to warn about the origin
* not being destroyed or not.
*/
if ((options & BE_DESTROY_AUTOORIGIN) != 0 &&
if ((options & BE_DESTROY_AUTOORIGIN) != 0 && *origin != '\0' &&
be_is_auto_snapshot_name(lbh, origin))
options |= BE_DESTROY_ORIGIN;