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 <nivedita@alum.mit.edu>
Reviewed-by: Allan Jude <allan@klarasystems.com>
Reviewed-by: Paul Dagnelie <pcd@delphix.com>
Reviewed-by: Igor Kozhukhov <igor@dilos.org>
Signed-off-by: Toomas Soome <tsoome@me.com>
Closes #10774
This commit is contained in:
Toomas Soome
2020-09-16 01:42:27 +03:00
committed by GitHub
parent 37325e4749
commit 1db9e6e4e4
29 changed files with 886 additions and 68 deletions
+10 -14
View File
@@ -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);
}