diff options
author | Toomas Soome <[email protected]> | 2020-09-17 20:51:09 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2020-09-17 10:51:09 -0700 |
commit | 741b20ce0c8370d5c7cb31cb82c0b040a535e99b (patch) | |
tree | f80f3e7b722e43f771c1e2ac777261bdf114bce9 /lib/libzfsbootenv/lzbe_pair.c | |
parent | 7ead2be3d23d2ed7c541031ca25dd223589a7bd5 (diff) |
libzfsbootenv: lzbe_nvlist_set needs to store bootenv version VB_NVLIST
A small bug did slip into initial libzfsbootenv; while storing nvlist
in nvlist, we should make sure the bootenv is using VB_NVLIST format.
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Toomas Soome <[email protected]>
Closes #10937
Diffstat (limited to 'lib/libzfsbootenv/lzbe_pair.c')
-rw-r--r-- | lib/libzfsbootenv/lzbe_pair.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/libzfsbootenv/lzbe_pair.c b/lib/libzfsbootenv/lzbe_pair.c index e702a8585..831355ba4 100644 --- a/lib/libzfsbootenv/lzbe_pair.c +++ b/lib/libzfsbootenv/lzbe_pair.c @@ -16,6 +16,8 @@ #include <string.h> #include <libzfs.h> #include <libzfsbootenv.h> +#include <sys/zfs_bootenv.h> +#include <sys/vdev_impl.h> /* * Get or create nvlist. If key is not NULL, get nvlist from bootenv, @@ -74,6 +76,7 @@ lzbe_nvlist_set(const char *pool, const char *key, void *ptr) libzfs_handle_t *hdl; zpool_handle_t *zphdl; nvlist_t *nv; + uint64_t version; int rv = -1; if (pool == NULL || *pool == '\0') @@ -92,6 +95,21 @@ lzbe_nvlist_set(const char *pool, const char *key, void *ptr) if (key != NULL) { rv = zpool_get_bootenv(zphdl, &nv); if (rv == 0) { + /* + * We got the nvlist, check for version. + * if version is missing or is not VB_NVLIST, + * create new list. + */ + rv = nvlist_lookup_uint64(nv, BOOTENV_VERSION, + &version); + if (rv != 0 || version != VB_NVLIST) { + /* Drop this nvlist */ + fnvlist_free(nv); + /* Create and prepare new nvlist */ + nv = fnvlist_alloc(); + fnvlist_add_uint64(nv, BOOTENV_VERSION, + VB_NVLIST); + } rv = nvlist_add_nvlist(nv, key, ptr); if (rv == 0) rv = zpool_set_bootenv(zphdl, nv); |