libzfs: Convert to fnvpair functions

Improves readability.  No functional change intended.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes #13197
This commit is contained in:
Ryan Moeller 2022-03-14 18:44:56 -04:00 committed by GitHub
parent becc717f61
commit 8bb9ecf4bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 125 additions and 200 deletions

View File

@ -193,7 +193,7 @@ namespace_reload(libzfs_handle_t *hdl)
return (-1); return (-1);
} }
verify(nvpair_value_nvlist(elem, &child) == 0); child = fnvpair_value_nvlist(elem);
if (nvlist_dup(child, &cn->cn_config, 0) != 0) { if (nvlist_dup(child, &cn->cn_config, 0) != 0) {
free(cn->cn_name); free(cn->cn_name);
free(cn); free(cn);

View File

@ -234,7 +234,6 @@ process_user_props(zfs_handle_t *zhp, nvlist_t *props)
{ {
libzfs_handle_t *hdl = zhp->zfs_hdl; libzfs_handle_t *hdl = zhp->zfs_hdl;
nvpair_t *elem; nvpair_t *elem;
nvlist_t *propval;
nvlist_t *nvl; nvlist_t *nvl;
if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) { if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) {
@ -247,7 +246,7 @@ process_user_props(zfs_handle_t *zhp, nvlist_t *props)
if (!zfs_prop_user(nvpair_name(elem))) if (!zfs_prop_user(nvpair_name(elem)))
continue; continue;
verify(nvpair_value_nvlist(elem, &propval) == 0); nvlist_t *propval = fnvpair_value_nvlist(elem);
if (nvlist_add_nvlist(nvl, nvpair_name(elem), propval) != 0) { if (nvlist_add_nvlist(nvl, nvpair_name(elem), propval) != 0) {
nvlist_free(nvl); nvlist_free(nvl);
(void) no_memory(hdl); (void) no_memory(hdl);
@ -1315,8 +1314,7 @@ zfs_valid_proplist(libzfs_handle_t *hdl, zfs_type_t type, nvlist_t *nvl,
/* Replace the label string with the internal form. */ /* Replace the label string with the internal form. */
(void) nvlist_remove(ret, zfs_prop_to_name(prop), (void) nvlist_remove(ret, zfs_prop_to_name(prop),
DATA_TYPE_STRING); DATA_TYPE_STRING);
verify(nvlist_add_string(ret, zfs_prop_to_name(prop), fnvlist_add_string(ret, zfs_prop_to_name(prop), hex);
hex) == 0);
free(hex); free(hex);
break; break;
@ -2056,7 +2054,7 @@ getprop_uint64(zfs_handle_t *zhp, zfs_prop_t prop, char **source)
*source = NULL; *source = NULL;
if (nvlist_lookup_nvlist(zhp->zfs_props, if (nvlist_lookup_nvlist(zhp->zfs_props,
zfs_prop_to_name(prop), &nv) == 0) { zfs_prop_to_name(prop), &nv) == 0) {
verify(nvlist_lookup_uint64(nv, ZPROP_VALUE, &value) == 0); value = fnvlist_lookup_uint64(nv, ZPROP_VALUE);
(void) nvlist_lookup_string(nv, ZPROP_SOURCE, source); (void) nvlist_lookup_string(nv, ZPROP_SOURCE, source);
} else { } else {
verify(!zhp->zfs_props_table || verify(!zhp->zfs_props_table ||
@ -2385,8 +2383,7 @@ zfs_prop_get_recvd(zfs_handle_t *zhp, const char *propname, char *propbuf,
if (nvlist_lookup_nvlist(zhp->zfs_recvd_props, if (nvlist_lookup_nvlist(zhp->zfs_recvd_props,
propname, &propval) != 0) propname, &propval) != 0)
return (-1); return (-1);
verify(nvlist_lookup_string(propval, ZPROP_VALUE, recvdval = fnvlist_lookup_string(propval, ZPROP_VALUE);
&recvdval) == 0);
(void) strlcpy(propbuf, recvdval, proplen); (void) strlcpy(propbuf, recvdval, proplen);
} }
@ -2500,13 +2497,11 @@ zfs_get_clones_nvl(zfs_handle_t *zhp)
} }
nvlist_free(nv); nvlist_free(nv);
nvlist_free(value); nvlist_free(value);
verify(0 == nvlist_lookup_nvlist(zhp->zfs_props, nv = fnvlist_lookup_nvlist(zhp->zfs_props,
zfs_prop_to_name(ZFS_PROP_CLONES), &nv)); zfs_prop_to_name(ZFS_PROP_CLONES));
} }
verify(nvlist_lookup_nvlist(nv, ZPROP_VALUE, &value) == 0); return (fnvlist_lookup_nvlist(nv, ZPROP_VALUE));
return (value);
} }
static int static int
@ -3863,7 +3858,7 @@ zfs_check_snap_cb(zfs_handle_t *zhp, void *arg)
return (EINVAL); return (EINVAL);
if (lzc_exists(name)) if (lzc_exists(name))
verify(nvlist_add_boolean(dd->nvl, name) == 0); fnvlist_add_boolean(dd->nvl, name);
rv = zfs_iter_filesystems(zhp, zfs_check_snap_cb, dd); rv = zfs_iter_filesystems(zhp, zfs_check_snap_cb, dd);
zfs_close(zhp); zfs_close(zhp);
@ -3880,7 +3875,7 @@ zfs_destroy_snaps(zfs_handle_t *zhp, char *snapname, boolean_t defer)
struct destroydata dd = { 0 }; struct destroydata dd = { 0 };
dd.snapname = snapname; dd.snapname = snapname;
verify(nvlist_alloc(&dd.nvl, NV_UNIQUE_NAME, 0) == 0); dd.nvl = fnvlist_alloc();
(void) zfs_check_snap_cb(zfs_handle_dup(zhp), &dd); (void) zfs_check_snap_cb(zfs_handle_dup(zhp), &dd);
if (nvlist_empty(dd.nvl)) { if (nvlist_empty(dd.nvl)) {
@ -3890,7 +3885,7 @@ zfs_destroy_snaps(zfs_handle_t *zhp, char *snapname, boolean_t defer)
} else { } else {
ret = zfs_destroy_snaps_nvl(zhp->zfs_hdl, dd.nvl, defer); ret = zfs_destroy_snaps_nvl(zhp->zfs_hdl, dd.nvl, defer);
} }
nvlist_free(dd.nvl); fnvlist_free(dd.nvl);
return (ret); return (ret);
} }
@ -4221,7 +4216,7 @@ zfs_snapshot(libzfs_handle_t *hdl, const char *path, boolean_t recursive,
return (-1); return (-1);
} }
verify(nvlist_alloc(&sd.sd_nvl, NV_UNIQUE_NAME, 0) == 0); sd.sd_nvl = fnvlist_alloc();
if (recursive) { if (recursive) {
(void) zfs_snapshot_cb(zfs_handle_dup(zhp), &sd); (void) zfs_snapshot_cb(zfs_handle_dup(zhp), &sd);
} else { } else {
@ -4229,7 +4224,7 @@ zfs_snapshot(libzfs_handle_t *hdl, const char *path, boolean_t recursive,
} }
ret = zfs_snapshot_nvl(hdl, sd.sd_nvl, props); ret = zfs_snapshot_nvl(hdl, sd.sd_nvl, props);
nvlist_free(sd.sd_nvl); fnvlist_free(sd.sd_nvl);
zfs_close(zhp); zfs_close(zhp);
return (ret); return (ret);
} }
@ -4712,8 +4707,8 @@ zfs_expand_proplist(zfs_handle_t *zhp, zprop_list_t **plp, boolean_t received,
} else { } else {
if (nvlist_lookup_nvlist(userprops, entry->pl_user_prop, if (nvlist_lookup_nvlist(userprops, entry->pl_user_prop,
&propval) == 0) { &propval) == 0) {
verify(nvlist_lookup_string(propval, strval = fnvlist_lookup_string(propval,
ZPROP_VALUE, &strval) == 0); ZPROP_VALUE);
if (strlen(strval) > entry->pl_width) if (strlen(strval) > entry->pl_width)
entry->pl_width = strlen(strval); entry->pl_width = strlen(strval);
} }

View File

@ -48,7 +48,6 @@ pool_active(libzfs_handle_t *hdl, const char *name, uint64_t guid,
boolean_t *isactive) boolean_t *isactive)
{ {
zpool_handle_t *zhp; zpool_handle_t *zhp;
uint64_t theguid;
if (zpool_open_silent(hdl, name, &zhp) != 0) if (zpool_open_silent(hdl, name, &zhp) != 0)
return (-1); return (-1);
@ -58,8 +57,8 @@ pool_active(libzfs_handle_t *hdl, const char *name, uint64_t guid,
return (0); return (0);
} }
verify(nvlist_lookup_uint64(zhp->zpool_config, ZPOOL_CONFIG_POOL_GUID, uint64_t theguid = fnvlist_lookup_uint64(zhp->zpool_config,
&theguid) == 0); ZPOOL_CONFIG_POOL_GUID);
zpool_close(zhp); zpool_close(zhp);
@ -239,12 +238,10 @@ zpool_clear_label(int fd)
static boolean_t static boolean_t
find_guid(nvlist_t *nv, uint64_t guid) find_guid(nvlist_t *nv, uint64_t guid)
{ {
uint64_t tmp;
nvlist_t **child; nvlist_t **child;
uint_t c, children; uint_t c, children;
verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &tmp) == 0); if (fnvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID) == guid)
if (tmp == guid)
return (B_TRUE); return (B_TRUE);
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
@ -268,18 +265,16 @@ find_aux(zpool_handle_t *zhp, void *data)
{ {
aux_cbdata_t *cbp = data; aux_cbdata_t *cbp = data;
nvlist_t **list; nvlist_t **list;
uint_t i, count; uint_t count;
uint64_t guid;
nvlist_t *nvroot;
verify(nvlist_lookup_nvlist(zhp->zpool_config, ZPOOL_CONFIG_VDEV_TREE, nvlist_t *nvroot = fnvlist_lookup_nvlist(zhp->zpool_config,
&nvroot) == 0); ZPOOL_CONFIG_VDEV_TREE);
if (nvlist_lookup_nvlist_array(nvroot, cbp->cb_type, if (nvlist_lookup_nvlist_array(nvroot, cbp->cb_type,
&list, &count) == 0) { &list, &count) == 0) {
for (i = 0; i < count; i++) { for (uint_t i = 0; i < count; i++) {
verify(nvlist_lookup_uint64(list[i], uint64_t guid = fnvlist_lookup_uint64(list[i],
ZPOOL_CONFIG_GUID, &guid) == 0); ZPOOL_CONFIG_GUID);
if (guid == cbp->cb_guid) { if (guid == cbp->cb_guid) {
cbp->cb_zhp = zhp; cbp->cb_zhp = zhp;
return (1); return (1);
@ -301,9 +296,9 @@ zpool_in_use(libzfs_handle_t *hdl, int fd, pool_state_t *state, char **namestr,
boolean_t *inuse) boolean_t *inuse)
{ {
nvlist_t *config; nvlist_t *config;
char *name; char *name = NULL;
boolean_t ret; boolean_t ret;
uint64_t guid, vdev_guid; uint64_t guid = 0, vdev_guid;
zpool_handle_t *zhp; zpool_handle_t *zhp;
nvlist_t *pool_config; nvlist_t *pool_config;
uint64_t stateval, isspare; uint64_t stateval, isspare;
@ -320,16 +315,12 @@ zpool_in_use(libzfs_handle_t *hdl, int fd, pool_state_t *state, char **namestr,
if (config == NULL) if (config == NULL)
return (0); return (0);
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE, stateval = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE);
&stateval) == 0); vdev_guid = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_GUID);
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_GUID,
&vdev_guid) == 0);
if (stateval != POOL_STATE_SPARE && stateval != POOL_STATE_L2CACHE) { if (stateval != POOL_STATE_SPARE && stateval != POOL_STATE_L2CACHE) {
verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME, name = fnvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME);
&name) == 0); guid = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID);
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
&guid) == 0);
} }
switch (stateval) { switch (stateval) {
@ -378,10 +369,8 @@ zpool_in_use(libzfs_handle_t *hdl, int fd, pool_state_t *state, char **namestr,
if ((zhp = zpool_open_canfail(hdl, name)) != NULL && if ((zhp = zpool_open_canfail(hdl, name)) != NULL &&
(pool_config = zpool_get_config(zhp, NULL)) (pool_config = zpool_get_config(zhp, NULL))
!= NULL) { != NULL) {
nvlist_t *nvroot; nvlist_t *nvroot = fnvlist_lookup_nvlist(
pool_config, ZPOOL_CONFIG_VDEV_TREE);
verify(nvlist_lookup_nvlist(pool_config,
ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0);
ret = find_guid(nvroot, vdev_guid); ret = find_guid(nvroot, vdev_guid);
} else { } else {
ret = B_FALSE; ret = B_FALSE;

View File

@ -123,15 +123,13 @@ zpool_get_prop_string(zpool_handle_t *zhp, zpool_prop_t prop,
zprop_source_t *src) zprop_source_t *src)
{ {
nvlist_t *nv, *nvl; nvlist_t *nv, *nvl;
uint64_t ival;
char *value; char *value;
zprop_source_t source; zprop_source_t source;
nvl = zhp->zpool_props; nvl = zhp->zpool_props;
if (nvlist_lookup_nvlist(nvl, zpool_prop_to_name(prop), &nv) == 0) { if (nvlist_lookup_nvlist(nvl, zpool_prop_to_name(prop), &nv) == 0) {
verify(nvlist_lookup_uint64(nv, ZPROP_SOURCE, &ival) == 0); source = fnvlist_lookup_uint64(nv, ZPROP_SOURCE);
source = ival; value = fnvlist_lookup_string(nv, ZPROP_VALUE);
verify(nvlist_lookup_string(nv, ZPROP_VALUE, &value) == 0);
} else { } else {
source = ZPROP_SRC_DEFAULT; source = ZPROP_SRC_DEFAULT;
if ((value = (char *)zpool_prop_default_string(prop)) == NULL) if ((value = (char *)zpool_prop_default_string(prop)) == NULL)
@ -169,9 +167,8 @@ zpool_get_prop_int(zpool_handle_t *zhp, zpool_prop_t prop, zprop_source_t *src)
nvl = zhp->zpool_props; nvl = zhp->zpool_props;
if (nvlist_lookup_nvlist(nvl, zpool_prop_to_name(prop), &nv) == 0) { if (nvlist_lookup_nvlist(nvl, zpool_prop_to_name(prop), &nv) == 0) {
verify(nvlist_lookup_uint64(nv, ZPROP_SOURCE, &value) == 0); source = fnvlist_lookup_uint64(nv, ZPROP_SOURCE);
source = value; value = fnvlist_lookup_uint64(nv, ZPROP_VALUE);
verify(nvlist_lookup_uint64(nv, ZPROP_VALUE, &value) == 0);
} else { } else {
source = ZPROP_SRC_DEFAULT; source = ZPROP_SRC_DEFAULT;
value = zpool_prop_default_numeric(prop); value = zpool_prop_default_numeric(prop);
@ -255,9 +252,6 @@ zpool_get_state_str(zpool_handle_t *zhp)
{ {
zpool_errata_t errata; zpool_errata_t errata;
zpool_status_t status; zpool_status_t status;
nvlist_t *nvroot;
vdev_stat_t *vs;
uint_t vsc;
const char *str; const char *str;
status = zpool_get_status(zhp, NULL, &errata); status = zpool_get_status(zhp, NULL, &errata);
@ -268,11 +262,11 @@ zpool_get_state_str(zpool_handle_t *zhp)
status == ZPOOL_STATUS_IO_FAILURE_MMP) { status == ZPOOL_STATUS_IO_FAILURE_MMP) {
str = gettext("SUSPENDED"); str = gettext("SUSPENDED");
} else { } else {
verify(nvlist_lookup_nvlist(zpool_get_config(zhp, NULL), nvlist_t *nvroot = fnvlist_lookup_nvlist(
ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); zpool_get_config(zhp, NULL), ZPOOL_CONFIG_VDEV_TREE);
verify(nvlist_lookup_uint64_array(nvroot, uint_t vsc;
ZPOOL_CONFIG_VDEV_STATS, (uint64_t **)&vs, &vsc) vdev_stat_t *vs = (vdev_stat_t *)fnvlist_lookup_uint64_array(
== 0); nvroot, ZPOOL_CONFIG_VDEV_STATS, &vsc);
str = zpool_state_to_name(vs->vs_state, vs->vs_aux); str = zpool_state_to_name(vs->vs_state, vs->vs_aux);
} }
return (str); return (str);
@ -986,8 +980,7 @@ vdev_expand_proplist(zpool_handle_t *zhp, const char *vdevname,
if (nvpair_value_nvlist(elem, &propval) != 0) if (nvpair_value_nvlist(elem, &propval) != 0)
continue; continue;
verify(nvlist_lookup_string(propval, ZPROP_VALUE, strval = fnvlist_lookup_string(propval, ZPROP_VALUE);
&strval) == 0);
if ((entry = zfs_alloc(zhp->zpool_hdl, if ((entry = zfs_alloc(zhp->zpool_hdl,
sizeof (zprop_list_t))) == NULL) sizeof (zprop_list_t))) == NULL)
@ -1996,20 +1989,13 @@ void
zpool_print_unsup_feat(nvlist_t *config) zpool_print_unsup_feat(nvlist_t *config)
{ {
nvlist_t *nvinfo, *unsup_feat; nvlist_t *nvinfo, *unsup_feat;
nvpair_t *nvp;
verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO, &nvinfo) == nvinfo = fnvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO);
0); unsup_feat = fnvlist_lookup_nvlist(nvinfo, ZPOOL_CONFIG_UNSUP_FEAT);
verify(nvlist_lookup_nvlist(nvinfo, ZPOOL_CONFIG_UNSUP_FEAT,
&unsup_feat) == 0);
for (nvp = nvlist_next_nvpair(unsup_feat, NULL); nvp != NULL;
nvp = nvlist_next_nvpair(unsup_feat, nvp)) {
char *desc;
verify(nvpair_type(nvp) == DATA_TYPE_STRING);
verify(nvpair_value_string(nvp, &desc) == 0);
for (nvpair_t *nvp = nvlist_next_nvpair(unsup_feat, NULL);
nvp != NULL; nvp = nvlist_next_nvpair(unsup_feat, nvp)) {
char *desc = fnvpair_value_string(nvp);
if (strlen(desc) > 0) if (strlen(desc) > 0)
(void) printf("\t%s (%s)\n", nvpair_name(nvp), desc); (void) printf("\t%s (%s)\n", nvpair_name(nvp), desc);
else else
@ -2038,8 +2024,7 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
int error = 0; int error = 0;
char errbuf[1024]; char errbuf[1024];
verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME, origname = fnvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME);
&origname) == 0);
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
"cannot import pool '%s'"), origname); "cannot import pool '%s'"), origname);
@ -2058,8 +2043,7 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
uint64_t version; uint64_t version;
prop_flags_t flags = { .create = B_FALSE, .import = B_TRUE }; prop_flags_t flags = { .create = B_FALSE, .import = B_TRUE };
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION, version = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION);
&version) == 0);
if ((props = zpool_valid_proplist(hdl, origname, if ((props = zpool_valid_proplist(hdl, origname,
props, version, flags, errbuf)) == NULL) props, version, flags, errbuf)) == NULL)
@ -2073,8 +2057,7 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
(void) strlcpy(zc.zc_name, thename, sizeof (zc.zc_name)); (void) strlcpy(zc.zc_name, thename, sizeof (zc.zc_name));
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, zc.zc_guid = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID);
&zc.zc_guid) == 0);
if (zcmd_write_conf_nvlist(hdl, &zc, config) != 0) { if (zcmd_write_conf_nvlist(hdl, &zc, config) != 0) {
zcmd_free_nvlists(&zc); zcmd_free_nvlists(&zc);
@ -2635,8 +2618,8 @@ zpool_scan(zpool_handle_t *zhp, pool_scan_func_t func, pool_scrub_cmd_t cmd)
pool_scan_stat_t *ps = NULL; pool_scan_stat_t *ps = NULL;
uint_t psc; uint_t psc;
verify(nvlist_lookup_nvlist(zhp->zpool_config, nvroot = fnvlist_lookup_nvlist(zhp->zpool_config,
ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); ZPOOL_CONFIG_VDEV_TREE);
(void) nvlist_lookup_uint64_array(nvroot, (void) nvlist_lookup_uint64_array(nvroot,
ZPOOL_CONFIG_SCAN_STATS, (uint64_t **)&ps, &psc); ZPOOL_CONFIG_SCAN_STATS, (uint64_t **)&ps, &psc);
if (ps && ps->pss_func == POOL_SCAN_SCRUB && if (ps && ps->pss_func == POOL_SCAN_SCRUB &&
@ -2684,11 +2667,9 @@ vdev_to_nvlist_iter(nvlist_t *nv, nvlist_t *search, boolean_t *avail_spare,
switch (nvpair_type(pair)) { switch (nvpair_type(pair)) {
case DATA_TYPE_UINT64: case DATA_TYPE_UINT64:
if (strcmp(srchkey, ZPOOL_CONFIG_GUID) == 0) { if (strcmp(srchkey, ZPOOL_CONFIG_GUID) == 0) {
uint64_t srchval, theguid; uint64_t srchval = fnvpair_value_uint64(pair);
uint64_t theguid = fnvlist_lookup_uint64(nv,
verify(nvpair_value_uint64(pair, &srchval) == 0); ZPOOL_CONFIG_GUID);
verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID,
&theguid) == 0);
if (theguid == srchval) if (theguid == srchval)
return (nv); return (nv);
} }
@ -2697,7 +2678,7 @@ vdev_to_nvlist_iter(nvlist_t *nv, nvlist_t *search, boolean_t *avail_spare,
case DATA_TYPE_STRING: { case DATA_TYPE_STRING: {
char *srchval, *val; char *srchval, *val;
verify(nvpair_value_string(pair, &srchval) == 0); srchval = fnvpair_value_string(pair);
if (nvlist_lookup_string(nv, srchkey, &val) != 0) if (nvlist_lookup_string(nv, srchkey, &val) != 0)
break; break;
@ -2749,9 +2730,8 @@ vdev_to_nvlist_iter(nvlist_t *nv, nvlist_t *search, boolean_t *avail_spare,
} }
verify(zpool_vdev_is_interior(type)); verify(zpool_vdev_is_interior(type));
verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ID,
&id) == 0);
id = fnvlist_lookup_uint64(nv, ZPOOL_CONFIG_ID);
errno = 0; errno = 0;
vdev_id = strtoull(idx, &end, 10); vdev_id = strtoull(idx, &end, 10);
@ -2777,8 +2757,8 @@ vdev_to_nvlist_iter(nvlist_t *nv, nvlist_t *search, boolean_t *avail_spare,
free(type); free(type);
return (NULL); return (NULL);
} }
verify(nvlist_lookup_uint64(nv, vdev_parity = fnvlist_lookup_uint64(nv,
ZPOOL_CONFIG_NPARITY, &vdev_parity) == 0); ZPOOL_CONFIG_NPARITY);
if ((int)vdev_parity != parity) { if ((int)vdev_parity != parity) {
free(type); free(type);
break; break;
@ -2867,25 +2847,24 @@ zpool_find_vdev_by_physpath(zpool_handle_t *zhp, const char *ppath,
uint64_t guid; uint64_t guid;
char *end; char *end;
verify(nvlist_alloc(&search, NV_UNIQUE_NAME, KM_SLEEP) == 0); search = fnvlist_alloc();
guid = strtoull(ppath, &end, 0); guid = strtoull(ppath, &end, 0);
if (guid != 0 && *end == '\0') { if (guid != 0 && *end == '\0') {
verify(nvlist_add_uint64(search, ZPOOL_CONFIG_GUID, guid) == 0); fnvlist_add_uint64(search, ZPOOL_CONFIG_GUID, guid);
} else { } else {
verify(nvlist_add_string(search, ZPOOL_CONFIG_PHYS_PATH, fnvlist_add_string(search, ZPOOL_CONFIG_PHYS_PATH, ppath);
ppath) == 0);
} }
verify(nvlist_lookup_nvlist(zhp->zpool_config, ZPOOL_CONFIG_VDEV_TREE, nvroot = fnvlist_lookup_nvlist(zhp->zpool_config,
&nvroot) == 0); ZPOOL_CONFIG_VDEV_TREE);
*avail_spare = B_FALSE; *avail_spare = B_FALSE;
*l2cache = B_FALSE; *l2cache = B_FALSE;
if (log != NULL) if (log != NULL)
*log = B_FALSE; *log = B_FALSE;
ret = vdev_to_nvlist_iter(nvroot, search, avail_spare, l2cache, log); ret = vdev_to_nvlist_iter(nvroot, search, avail_spare, l2cache, log);
nvlist_free(search); fnvlist_free(search);
return (ret); return (ret);
} }
@ -2918,26 +2897,26 @@ zpool_find_vdev(zpool_handle_t *zhp, const char *path, boolean_t *avail_spare,
nvlist_t *nvroot, *search, *ret; nvlist_t *nvroot, *search, *ret;
uint64_t guid; uint64_t guid;
verify(nvlist_alloc(&search, NV_UNIQUE_NAME, KM_SLEEP) == 0); search = fnvlist_alloc();
guid = strtoull(path, &end, 0); guid = strtoull(path, &end, 0);
if (guid != 0 && *end == '\0') { if (guid != 0 && *end == '\0') {
verify(nvlist_add_uint64(search, ZPOOL_CONFIG_GUID, guid) == 0); fnvlist_add_uint64(search, ZPOOL_CONFIG_GUID, guid);
} else if (zpool_vdev_is_interior(path)) { } else if (zpool_vdev_is_interior(path)) {
verify(nvlist_add_string(search, ZPOOL_CONFIG_TYPE, path) == 0); fnvlist_add_string(search, ZPOOL_CONFIG_TYPE, path);
} else { } else {
verify(nvlist_add_string(search, ZPOOL_CONFIG_PATH, path) == 0); fnvlist_add_string(search, ZPOOL_CONFIG_PATH, path);
} }
verify(nvlist_lookup_nvlist(zhp->zpool_config, ZPOOL_CONFIG_VDEV_TREE, nvroot = fnvlist_lookup_nvlist(zhp->zpool_config,
&nvroot) == 0); ZPOOL_CONFIG_VDEV_TREE);
*avail_spare = B_FALSE; *avail_spare = B_FALSE;
*l2cache = B_FALSE; *l2cache = B_FALSE;
if (log != NULL) if (log != NULL)
*log = B_FALSE; *log = B_FALSE;
ret = vdev_to_nvlist_iter(nvroot, search, avail_spare, l2cache, log); ret = vdev_to_nvlist_iter(nvroot, search, avail_spare, l2cache, log);
nvlist_free(search); fnvlist_free(search);
return (ret); return (ret);
} }
@ -3101,7 +3080,6 @@ static uint64_t
zpool_vdev_path_to_guid_impl(zpool_handle_t *zhp, const char *path, zpool_vdev_path_to_guid_impl(zpool_handle_t *zhp, const char *path,
boolean_t *is_spare, boolean_t *is_l2cache, boolean_t *is_log) boolean_t *is_spare, boolean_t *is_l2cache, boolean_t *is_log)
{ {
uint64_t guid;
boolean_t spare = B_FALSE, l2cache = B_FALSE, log = B_FALSE; boolean_t spare = B_FALSE, l2cache = B_FALSE, log = B_FALSE;
nvlist_t *tgt; nvlist_t *tgt;
@ -3109,7 +3087,6 @@ zpool_vdev_path_to_guid_impl(zpool_handle_t *zhp, const char *path,
&log)) == NULL) &log)) == NULL)
return (0); return (0);
verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &guid) == 0);
if (is_spare != NULL) if (is_spare != NULL)
*is_spare = spare; *is_spare = spare;
if (is_l2cache != NULL) if (is_l2cache != NULL)
@ -3117,7 +3094,7 @@ zpool_vdev_path_to_guid_impl(zpool_handle_t *zhp, const char *path,
if (is_log != NULL) if (is_log != NULL)
*is_log = log; *is_log = log;
return (guid); return (fnvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID));
} }
/* Convert a vdev path to a GUID. Returns GUID or 0 on error. */ /* Convert a vdev path to a GUID. Returns GUID or 0 on error. */
@ -3154,7 +3131,7 @@ zpool_vdev_online(zpool_handle_t *zhp, const char *path, int flags,
&islog)) == NULL) &islog)) == NULL)
return (zfs_error(hdl, EZFS_NODEVICE, msg)); return (zfs_error(hdl, EZFS_NODEVICE, msg));
verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0); zc.zc_guid = fnvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID);
if (avail_spare) if (avail_spare)
return (zfs_error(hdl, EZFS_ISSPARE, msg)); return (zfs_error(hdl, EZFS_ISSPARE, msg));
@ -3237,7 +3214,7 @@ zpool_vdev_offline(zpool_handle_t *zhp, const char *path, boolean_t istmp)
NULL)) == NULL) NULL)) == NULL)
return (zfs_error(hdl, EZFS_NODEVICE, msg)); return (zfs_error(hdl, EZFS_NODEVICE, msg));
verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0); zc.zc_guid = fnvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID);
if (avail_spare) if (avail_spare)
return (zfs_error(hdl, EZFS_ISSPARE, msg)); return (zfs_error(hdl, EZFS_ISSPARE, msg));
@ -3335,13 +3312,10 @@ is_replacing_spare(nvlist_t *search, nvlist_t *tgt, int which)
{ {
nvlist_t **child; nvlist_t **child;
uint_t c, children; uint_t c, children;
char *type;
if (nvlist_lookup_nvlist_array(search, ZPOOL_CONFIG_CHILDREN, &child, if (nvlist_lookup_nvlist_array(search, ZPOOL_CONFIG_CHILDREN, &child,
&children) == 0) { &children) == 0) {
verify(nvlist_lookup_string(search, ZPOOL_CONFIG_TYPE, char *type = fnvlist_lookup_string(search, ZPOOL_CONFIG_TYPE);
&type) == 0);
if ((strcmp(type, VDEV_TYPE_SPARE) == 0 || if ((strcmp(type, VDEV_TYPE_SPARE) == 0 ||
strcmp(type, VDEV_TYPE_DRAID_SPARE) == 0) && strcmp(type, VDEV_TYPE_DRAID_SPARE) == 0) &&
children == 2 && child[which] == tgt) children == 2 && child[which] == tgt)
@ -3393,7 +3367,7 @@ zpool_vdev_attach(zpool_handle_t *zhp, const char *old_disk,
if (l2cache) if (l2cache)
return (zfs_error(hdl, EZFS_ISL2CACHE, msg)); return (zfs_error(hdl, EZFS_ISL2CACHE, msg));
verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0); zc.zc_guid = fnvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID);
zc.zc_cookie = replacing; zc.zc_cookie = replacing;
zc.zc_simple = rebuild; zc.zc_simple = rebuild;
@ -3411,8 +3385,8 @@ zpool_vdev_attach(zpool_handle_t *zhp, const char *old_disk,
return (zfs_error(hdl, EZFS_INVALCONFIG, msg)); return (zfs_error(hdl, EZFS_INVALCONFIG, msg));
} }
verify(nvlist_lookup_nvlist(zpool_get_config(zhp, NULL), config_root = fnvlist_lookup_nvlist(zpool_get_config(zhp, NULL),
ZPOOL_CONFIG_VDEV_TREE, &config_root) == 0); ZPOOL_CONFIG_VDEV_TREE);
if ((newname = zpool_vdev_name(NULL, NULL, child[0], 0)) == NULL) if ((newname = zpool_vdev_name(NULL, NULL, child[0], 0)) == NULL)
return (-1); return (-1);
@ -3566,7 +3540,7 @@ zpool_vdev_detach(zpool_handle_t *zhp, const char *path)
if (l2cache) if (l2cache)
return (zfs_error(hdl, EZFS_ISL2CACHE, msg)); return (zfs_error(hdl, EZFS_ISL2CACHE, msg));
verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0); zc.zc_guid = fnvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID);
if (zfs_ioctl(hdl, ZFS_IOC_VDEV_DETACH, &zc) == 0) if (zfs_ioctl(hdl, ZFS_IOC_VDEV_DETACH, &zc) == 0)
return (0); return (0);
@ -3666,9 +3640,8 @@ zpool_vdev_split(zpool_handle_t *zhp, char *newname, nvlist_t **newroot,
return (-1); return (-1);
} }
verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, &tree) tree = fnvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE);
== 0); vers = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION);
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION, &vers) == 0);
if (props) { if (props) {
prop_flags_t flags = { .create = B_FALSE, .import = B_TRUE }; prop_flags_t flags = { .create = B_FALSE, .import = B_TRUE };
@ -3735,8 +3708,7 @@ zpool_vdev_split(zpool_handle_t *zhp, char *newname, nvlist_t **newroot,
continue; continue;
} }
lastlog = 0; lastlog = 0;
verify(nvlist_lookup_string(child[c], ZPOOL_CONFIG_TYPE, &type) type = fnvlist_lookup_string(child[c], ZPOOL_CONFIG_TYPE);
== 0);
if (strcmp(type, VDEV_TYPE_INDIRECT) == 0) { if (strcmp(type, VDEV_TYPE_INDIRECT) == 0) {
vdev = child[c]; vdev = child[c];
@ -4043,8 +4015,7 @@ zpool_clear(zpool_handle_t *zhp, const char *path, nvlist_t *rewindnvl)
if (avail_spare) if (avail_spare)
return (zfs_error(hdl, EZFS_ISSPARE, msg)); return (zfs_error(hdl, EZFS_ISSPARE, msg));
verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, zc.zc_guid = fnvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID);
&zc.zc_guid) == 0);
} }
zpool_get_load_policy(rewindnvl, &policy); zpool_get_load_policy(rewindnvl, &policy);
@ -4197,7 +4168,7 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
* vdev_name will be "root"/"root-0" for the root vdev, but it is the * vdev_name will be "root"/"root-0" for the root vdev, but it is the
* zpool name that will be displayed to the user. * zpool name that will be displayed to the user.
*/ */
verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) == 0); type = fnvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE);
if (zhp != NULL && strcmp(type, "root") == 0) if (zhp != NULL && strcmp(type, "root") == 0)
return (zfs_strdup(hdl, zpool_get_name(zhp))); return (zfs_strdup(hdl, zpool_get_name(zhp)));
@ -4254,8 +4225,7 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
* If it's a raidz device, we need to stick in the parity level. * If it's a raidz device, we need to stick in the parity level.
*/ */
if (strcmp(path, VDEV_TYPE_RAIDZ) == 0) { if (strcmp(path, VDEV_TYPE_RAIDZ) == 0) {
verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NPARITY, value = fnvlist_lookup_uint64(nv, ZPOOL_CONFIG_NPARITY);
&value) == 0);
(void) snprintf(buf, sizeof (buf), "%s%llu", path, (void) snprintf(buf, sizeof (buf), "%s%llu", path,
(u_longlong_t)value); (u_longlong_t)value);
path = buf; path = buf;
@ -4271,12 +4241,12 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
verify(nvlist_lookup_nvlist_array(nv, verify(nvlist_lookup_nvlist_array(nv,
ZPOOL_CONFIG_CHILDREN, &child, &children) == 0); ZPOOL_CONFIG_CHILDREN, &child, &children) == 0);
verify(nvlist_lookup_uint64(nv, nparity = fnvlist_lookup_uint64(nv,
ZPOOL_CONFIG_NPARITY, &nparity) == 0); ZPOOL_CONFIG_NPARITY);
verify(nvlist_lookup_uint64(nv, ndata = fnvlist_lookup_uint64(nv,
ZPOOL_CONFIG_DRAID_NDATA, &ndata) == 0); ZPOOL_CONFIG_DRAID_NDATA);
verify(nvlist_lookup_uint64(nv, nspares = fnvlist_lookup_uint64(nv,
ZPOOL_CONFIG_DRAID_NSPARES, &nspares) == 0); ZPOOL_CONFIG_DRAID_NSPARES);
path = zpool_draid_name(buf, sizeof (buf), ndata, path = zpool_draid_name(buf, sizeof (buf), ndata,
nparity, nspares, children); nparity, nspares, children);
@ -4287,9 +4257,8 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
* naming convention. * naming convention.
*/ */
if (name_flags & VDEV_NAME_TYPE_ID) { if (name_flags & VDEV_NAME_TYPE_ID) {
uint64_t id; uint64_t id = fnvlist_lookup_uint64(nv,
verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ID, ZPOOL_CONFIG_ID);
&id) == 0);
(void) snprintf(tmpbuf, sizeof (tmpbuf), "%s-%llu", (void) snprintf(tmpbuf, sizeof (tmpbuf), "%s-%llu",
path, (u_longlong_t)id); path, (u_longlong_t)id);
path = tmpbuf; path = tmpbuf;
@ -4323,8 +4292,7 @@ zpool_get_errlog(zpool_handle_t *zhp, nvlist_t **nverrlistp)
* has increased, allocate more space and continue until we get the * has increased, allocate more space and continue until we get the
* entire list. * entire list.
*/ */
verify(nvlist_lookup_uint64(zhp->zpool_config, ZPOOL_CONFIG_ERRCOUNT, count = fnvlist_lookup_uint64(zhp->zpool_config, ZPOOL_CONFIG_ERRCOUNT);
&count) == 0);
if (count == 0) if (count == 0)
return (0); return (0);
zc.zc_nvlist_dst = (uintptr_t)zfs_alloc(zhp->zpool_hdl, zc.zc_nvlist_dst = (uintptr_t)zfs_alloc(zhp->zpool_hdl,
@ -4553,9 +4521,9 @@ zpool_get_history(zpool_handle_t *zhp, nvlist_t **nvhisp, uint64_t *off,
free(buf); free(buf);
if (!err) { if (!err) {
verify(nvlist_alloc(nvhisp, NV_UNIQUE_NAME, 0) == 0); *nvhisp = fnvlist_alloc();
verify(nvlist_add_nvlist_array(*nvhisp, ZPOOL_HIST_RECORD, fnvlist_add_nvlist_array(*nvhisp, ZPOOL_HIST_RECORD,
(const nvlist_t **)records, numrecords) == 0); (const nvlist_t **)records, numrecords);
} }
for (i = 0; i < numrecords; i++) for (i = 0; i < numrecords; i++)
nvlist_free(records[i]); nvlist_free(records[i]);
@ -5092,7 +5060,7 @@ zpool_vdev_guid(zpool_handle_t *zhp, const char *vdevname, uint64_t *vdev_guid)
return (zfs_error(zhp->zpool_hdl, EZFS_NODEVICE, errbuf)); return (zfs_error(zhp->zpool_hdl, EZFS_NODEVICE, errbuf));
} }
verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, vdev_guid) == 0); *vdev_guid = fnvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID);
return (0); return (0);
} }
@ -5105,19 +5073,16 @@ zpool_get_vdev_prop_value(nvlist_t *nvprop, vdev_prop_t prop, char *prop_name,
char *buf, size_t len, zprop_source_t *srctype, boolean_t literal) char *buf, size_t len, zprop_source_t *srctype, boolean_t literal)
{ {
nvlist_t *nv; nvlist_t *nv;
uint64_t intval;
char *strval; char *strval;
uint64_t intval;
zprop_source_t src = ZPROP_SRC_NONE; zprop_source_t src = ZPROP_SRC_NONE;
if (prop == VDEV_PROP_USER) { if (prop == VDEV_PROP_USER) {
/* user property, prop_name must contain the property name */ /* user property, prop_name must contain the property name */
assert(prop_name != NULL); assert(prop_name != NULL);
if (nvlist_lookup_nvlist(nvprop, prop_name, &nv) == 0) { if (nvlist_lookup_nvlist(nvprop, prop_name, &nv) == 0) {
verify(nvlist_lookup_uint64(nv, ZPROP_SOURCE, src = fnvlist_lookup_uint64(nv, ZPROP_SOURCE);
&intval) == 0); strval = fnvlist_lookup_string(nv, ZPROP_VALUE);
src = intval;
verify(nvlist_lookup_string(nv, ZPROP_VALUE,
&strval) == 0);
} else { } else {
/* user prop not found */ /* user prop not found */
return (-1); return (-1);
@ -5134,11 +5099,8 @@ zpool_get_vdev_prop_value(nvlist_t *nvprop, vdev_prop_t prop, char *prop_name,
switch (vdev_prop_get_type(prop)) { switch (vdev_prop_get_type(prop)) {
case PROP_TYPE_STRING: case PROP_TYPE_STRING:
if (nvlist_lookup_nvlist(nvprop, prop_name, &nv) == 0) { if (nvlist_lookup_nvlist(nvprop, prop_name, &nv) == 0) {
verify(nvlist_lookup_uint64(nv, ZPROP_SOURCE, src = fnvlist_lookup_uint64(nv, ZPROP_SOURCE);
&intval) == 0); strval = fnvlist_lookup_string(nv, ZPROP_VALUE);
src = intval;
verify(nvlist_lookup_string(nv, ZPROP_VALUE,
&strval) == 0);
} else { } else {
src = ZPROP_SRC_DEFAULT; src = ZPROP_SRC_DEFAULT;
if ((strval = (char *)vdev_prop_default_string(prop)) if ((strval = (char *)vdev_prop_default_string(prop))
@ -5150,11 +5112,8 @@ zpool_get_vdev_prop_value(nvlist_t *nvprop, vdev_prop_t prop, char *prop_name,
case PROP_TYPE_NUMBER: case PROP_TYPE_NUMBER:
if (nvlist_lookup_nvlist(nvprop, prop_name, &nv) == 0) { if (nvlist_lookup_nvlist(nvprop, prop_name, &nv) == 0) {
verify(nvlist_lookup_uint64(nv, ZPROP_SOURCE, src = fnvlist_lookup_uint64(nv, ZPROP_SOURCE);
&intval) == 0); intval = fnvlist_lookup_uint64(nv, ZPROP_VALUE);
src = intval;
verify(nvlist_lookup_uint64(nv, ZPROP_VALUE,
&intval) == 0);
} else { } else {
src = ZPROP_SRC_DEFAULT; src = ZPROP_SRC_DEFAULT;
intval = vdev_prop_default_numeric(prop); intval = vdev_prop_default_numeric(prop);
@ -5234,11 +5193,8 @@ zpool_get_vdev_prop_value(nvlist_t *nvprop, vdev_prop_t prop, char *prop_name,
case PROP_TYPE_INDEX: case PROP_TYPE_INDEX:
if (nvlist_lookup_nvlist(nvprop, prop_name, &nv) == 0) { if (nvlist_lookup_nvlist(nvprop, prop_name, &nv) == 0) {
verify(nvlist_lookup_uint64(nv, ZPROP_SOURCE, src = fnvlist_lookup_uint64(nv, ZPROP_SOURCE);
&intval) == 0); intval = fnvlist_lookup_uint64(nv, ZPROP_VALUE);
src = intval;
verify(nvlist_lookup_uint64(nv, ZPROP_VALUE,
&intval) == 0);
} else { } else {
src = ZPROP_SRC_DEFAULT; src = ZPROP_SRC_DEFAULT;
intval = vdev_prop_default_numeric(prop); intval = vdev_prop_default_numeric(prop);

View File

@ -159,8 +159,7 @@ find_vdev_problem(nvlist_t *vdev, int (*func)(vdev_stat_t *, uint_t),
boolean_t ignore_replacing) boolean_t ignore_replacing)
{ {
nvlist_t **child; nvlist_t **child;
vdev_stat_t *vs; uint_t c, children;
uint_t c, vsc, children;
/* /*
* Ignore problems within a 'replacing' vdev, since we're presumably in * Ignore problems within a 'replacing' vdev, since we're presumably in
@ -169,10 +168,7 @@ find_vdev_problem(nvlist_t *vdev, int (*func)(vdev_stat_t *, uint_t),
* later. * later.
*/ */
if (ignore_replacing == B_TRUE) { if (ignore_replacing == B_TRUE) {
char *type; char *type = fnvlist_lookup_string(vdev, ZPOOL_CONFIG_TYPE);
verify(nvlist_lookup_string(vdev, ZPOOL_CONFIG_TYPE,
&type) == 0);
if (strcmp(type, VDEV_TYPE_REPLACING) == 0) if (strcmp(type, VDEV_TYPE_REPLACING) == 0)
return (B_FALSE); return (B_FALSE);
} }
@ -183,9 +179,9 @@ find_vdev_problem(nvlist_t *vdev, int (*func)(vdev_stat_t *, uint_t),
if (find_vdev_problem(child[c], func, ignore_replacing)) if (find_vdev_problem(child[c], func, ignore_replacing))
return (B_TRUE); return (B_TRUE);
} else { } else {
verify(nvlist_lookup_uint64_array(vdev, ZPOOL_CONFIG_VDEV_STATS, uint_t vsc;
(uint64_t **)&vs, &vsc) == 0); vdev_stat_t *vs = (vdev_stat_t *)fnvlist_lookup_uint64_array(
vdev, ZPOOL_CONFIG_VDEV_STATS, &vsc);
if (func(vs, vsc) != 0) if (func(vs, vsc) != 0)
return (B_TRUE); return (B_TRUE);
} }
@ -224,26 +220,21 @@ static zpool_status_t
check_status(nvlist_t *config, boolean_t isimport, check_status(nvlist_t *config, boolean_t isimport,
zpool_errata_t *erratap, const char *compat) zpool_errata_t *erratap, const char *compat)
{ {
nvlist_t *nvroot;
vdev_stat_t *vs;
pool_scan_stat_t *ps = NULL; pool_scan_stat_t *ps = NULL;
uint_t vsc, psc; uint_t vsc, psc;
uint64_t nerr; uint64_t nerr;
uint64_t version;
uint64_t stateval;
uint64_t suspended; uint64_t suspended;
uint64_t hostid = 0; uint64_t hostid = 0;
uint64_t errata = 0; uint64_t errata = 0;
unsigned long system_hostid = get_system_hostid(); unsigned long system_hostid = get_system_hostid();
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION, uint64_t version = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION);
&version) == 0); nvlist_t *nvroot = fnvlist_lookup_nvlist(config,
verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, ZPOOL_CONFIG_VDEV_TREE);
&nvroot) == 0); vdev_stat_t *vs = (vdev_stat_t *)fnvlist_lookup_uint64_array(nvroot,
verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS, ZPOOL_CONFIG_VDEV_STATS, &vsc);
(uint64_t **)&vs, &vsc) == 0); uint64_t stateval = fnvlist_lookup_uint64(config,
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE, ZPOOL_CONFIG_POOL_STATE);
&stateval) == 0);
/* /*
* Currently resilvering a vdev * Currently resilvering a vdev
@ -337,10 +328,8 @@ check_status(nvlist_t *config, boolean_t isimport,
*/ */
if (vs->vs_state == VDEV_STATE_CANT_OPEN && if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
vs->vs_aux == VDEV_AUX_UNSUP_FEAT) { vs->vs_aux == VDEV_AUX_UNSUP_FEAT) {
nvlist_t *nvinfo; nvlist_t *nvinfo = fnvlist_lookup_nvlist(config,
ZPOOL_CONFIG_LOAD_INFO);
verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO,
&nvinfo) == 0);
if (nvlist_exists(nvinfo, ZPOOL_CONFIG_CAN_RDONLY)) if (nvlist_exists(nvinfo, ZPOOL_CONFIG_CAN_RDONLY))
return (ZPOOL_STATUS_UNSUP_FEAT_WRITE); return (ZPOOL_STATUS_UNSUP_FEAT_WRITE);
return (ZPOOL_STATUS_UNSUP_FEAT_READ); return (ZPOOL_STATUS_UNSUP_FEAT_READ);

View File

@ -1199,10 +1199,8 @@ zcmd_write_nvlist_com(libzfs_handle_t *hdl, uint64_t *outnv, uint64_t *outlen,
nvlist_t *nvl) nvlist_t *nvl)
{ {
char *packed; char *packed;
size_t len;
verify(nvlist_size(nvl, &len, NV_ENCODE_NATIVE) == 0);
size_t len = fnvlist_size(nvl);
if ((packed = zfs_alloc(hdl, len)) == NULL) if ((packed = zfs_alloc(hdl, len)) == NULL)
return (-1); return (-1);

View File

@ -224,10 +224,8 @@ zpool_label_disk(libzfs_handle_t *hdl, zpool_handle_t *zhp, const char *name)
dgettext(TEXT_DOMAIN, "cannot label '%s'"), name); dgettext(TEXT_DOMAIN, "cannot label '%s'"), name);
if (zhp) { if (zhp) {
nvlist_t *nvroot; nvlist_t *nvroot = fnvlist_lookup_nvlist(zhp->zpool_config,
ZPOOL_CONFIG_VDEV_TREE);
verify(nvlist_lookup_nvlist(zhp->zpool_config,
ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0);
if (zhp->zpool_start_block == 0) if (zhp->zpool_start_block == 0)
start_block = find_start_block(nvroot); start_block = find_start_block(nvroot);