From 1db9e6e4e4c355a89e52f156f63843d01f84866e Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Wed, 16 Sep 2020 01:42:27 +0300 Subject: zfs label bootenv should store data as nvlist nvlist does allow us to support different data types and systems. To encapsulate user data to/from nvlist, the libzfsbootenv library is provided. Reviewed-by: Arvind Sankar Reviewed-by: Allan Jude Reviewed-by: Paul Dagnelie Reviewed-by: Igor Kozhukhov Signed-off-by: Toomas Soome Closes #10774 --- lib/libzfs/libzfs_pool.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'lib/libzfs/libzfs_pool.c') diff --git a/lib/libzfs/libzfs_pool.c b/lib/libzfs/libzfs_pool.c index 2501965e4..00b0b6faf 100644 --- a/lib/libzfs/libzfs_pool.c +++ b/lib/libzfs/libzfs_pool.c @@ -4495,7 +4495,7 @@ zpool_wait_status(zpool_handle_t *zhp, zpool_wait_activity_t activity, } int -zpool_set_bootenv(zpool_handle_t *zhp, const char *envmap) +zpool_set_bootenv(zpool_handle_t *zhp, const nvlist_t *envmap) { int error = lzc_set_bootenv(zhp->zpool_name, envmap); if (error != 0) { @@ -4508,24 +4508,20 @@ zpool_set_bootenv(zpool_handle_t *zhp, const char *envmap) } int -zpool_get_bootenv(zpool_handle_t *zhp, char *outbuf, size_t size, off_t offset) +zpool_get_bootenv(zpool_handle_t *zhp, nvlist_t **nvlp) { - nvlist_t *nvl = NULL; - int error = lzc_get_bootenv(zhp->zpool_name, &nvl); + nvlist_t *nvl; + int error; + + nvl = NULL; + error = lzc_get_bootenv(zhp->zpool_name, &nvl); if (error != 0) { (void) zpool_standard_error_fmt(zhp->zpool_hdl, error, dgettext(TEXT_DOMAIN, "error getting bootenv in pool '%s'"), zhp->zpool_name); - return (-1); - } - char *envmap = fnvlist_lookup_string(nvl, "envmap"); - if (offset >= strlen(envmap)) { - fnvlist_free(nvl); - return (0); + } else { + *nvlp = nvl; } - strncpy(outbuf, envmap + offset, size); - int bytes = MIN(strlen(envmap + offset), size); - fnvlist_free(nvl); - return (bytes); + return (error); } -- cgit v1.2.3