stand/zfs: Refactor zfs_get_bootonce
Lookup the spa and pass it into zfs_get_bootonce_spa to process the boot once protocol. Sponsored by: Netflix Reviewed by: tsoome, kevans Differential Revision: https://reviews.freebsd.org/D39411
This commit is contained in:
parent
4dcae288fe
commit
b765cfa380
@ -827,27 +827,12 @@ zfs_set_bootenv(void *vdev, nvlist_t *benv)
|
||||
int
|
||||
zfs_get_bootonce(void *vdev, const char *key, char *buf, size_t size)
|
||||
{
|
||||
nvlist_t *benv;
|
||||
char *result = NULL;
|
||||
int result_size, rv;
|
||||
spa_t *spa;
|
||||
|
||||
if ((rv = zfs_get_bootenv(vdev, &benv)) != 0)
|
||||
return (rv);
|
||||
if ((spa = spa_find_by_dev((struct zfs_devdesc *)vdev)) == NULL)
|
||||
return (ENXIO);
|
||||
|
||||
if ((rv = nvlist_find(benv, key, DATA_TYPE_STRING, NULL,
|
||||
&result, &result_size)) == 0) {
|
||||
if (result_size == 0) {
|
||||
/* ignore empty string */
|
||||
rv = ENOENT;
|
||||
} else {
|
||||
size = MIN((size_t)result_size + 1, size);
|
||||
strlcpy(buf, result, size);
|
||||
}
|
||||
(void) nvlist_remove(benv, key, DATA_TYPE_STRING);
|
||||
(void) zfs_set_bootenv(vdev, benv);
|
||||
}
|
||||
|
||||
return (rv);
|
||||
return (zfs_get_bootonce_spa(spa, key, buf, size));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -3899,3 +3899,36 @@ zfs_set_bootenv_spa(spa_t *spa, nvlist_t *benv)
|
||||
spa->spa_bootenv = benv;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get bootonce value by key. The bootonce <key, value> pair is removed from the
|
||||
* bootenv nvlist and the remaining nvlist is committed back to disk. This process
|
||||
* the bootonce flag since we've reached the point in the boot that we've 'used'
|
||||
* the BE. For chained boot scenarios, we may reach this point multiple times (but
|
||||
* only remove it and return 0 the first time).
|
||||
*/
|
||||
static int
|
||||
zfs_get_bootonce_spa(spa_t *spa, const char *key, char *buf, size_t size)
|
||||
{
|
||||
nvlist_t *benv;
|
||||
char *result = NULL;
|
||||
int result_size, rv;
|
||||
|
||||
if ((rv = zfs_get_bootenv_spa(spa, &benv)) != 0)
|
||||
return (rv);
|
||||
|
||||
if ((rv = nvlist_find(benv, key, DATA_TYPE_STRING, NULL,
|
||||
&result, &result_size)) == 0) {
|
||||
if (result_size == 0) {
|
||||
/* ignore empty string */
|
||||
rv = ENOENT;
|
||||
} else if (buf != NULL) {
|
||||
size = MIN((size_t)result_size + 1, size);
|
||||
strlcpy(buf, result, size);
|
||||
}
|
||||
(void)nvlist_remove(benv, key, DATA_TYPE_STRING);
|
||||
(void)zfs_set_bootenv_spa(spa, benv);
|
||||
}
|
||||
|
||||
return (rv);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user