From 1dc85563587263c6b3c7d04dfdcbdc17865b5e8b Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Wed, 16 Oct 2019 18:33:31 +0000 Subject: [PATCH] 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 --- lib/libbe/be.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/libbe/be.c b/lib/libbe/be.c index fb27d7a2855..fd7d05c408e 100644 --- a/lib/libbe/be.c +++ b/lib/libbe/be.c @@ -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;