Skip to content

Commit

Permalink
libzfs: Convert to fnvpair functions
Browse files Browse the repository at this point in the history
Improves readability.  No functional change intended.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes #13197
  • Loading branch information
Ryan Moeller authored Mar 14, 2022
1 parent becc717 commit 8bb9ecf
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 200 deletions.
2 changes: 1 addition & 1 deletion lib/libzfs/libzfs_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ namespace_reload(libzfs_handle_t *hdl)
return (-1);
}

verify(nvpair_value_nvlist(elem, &child) == 0);
child = fnvpair_value_nvlist(elem);
if (nvlist_dup(child, &cn->cn_config, 0) != 0) {
free(cn->cn_name);
free(cn);
Expand Down
33 changes: 14 additions & 19 deletions lib/libzfs/libzfs_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ process_user_props(zfs_handle_t *zhp, nvlist_t *props)
{
libzfs_handle_t *hdl = zhp->zfs_hdl;
nvpair_t *elem;
nvlist_t *propval;
nvlist_t *nvl;

if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) {
Expand All @@ -247,7 +246,7 @@ process_user_props(zfs_handle_t *zhp, nvlist_t *props)
if (!zfs_prop_user(nvpair_name(elem)))
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) {
nvlist_free(nvl);
(void) no_memory(hdl);
Expand Down Expand Up @@ -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. */
(void) nvlist_remove(ret, zfs_prop_to_name(prop),
DATA_TYPE_STRING);
verify(nvlist_add_string(ret, zfs_prop_to_name(prop),
hex) == 0);
fnvlist_add_string(ret, zfs_prop_to_name(prop), hex);
free(hex);

break;
Expand Down Expand Up @@ -2056,7 +2054,7 @@ getprop_uint64(zfs_handle_t *zhp, zfs_prop_t prop, char **source)
*source = NULL;
if (nvlist_lookup_nvlist(zhp->zfs_props,
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);
} else {
verify(!zhp->zfs_props_table ||
Expand Down Expand Up @@ -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,
propname, &propval) != 0)
return (-1);
verify(nvlist_lookup_string(propval, ZPROP_VALUE,
&recvdval) == 0);
recvdval = fnvlist_lookup_string(propval, ZPROP_VALUE);
(void) strlcpy(propbuf, recvdval, proplen);
}

Expand Down Expand Up @@ -2500,13 +2497,11 @@ zfs_get_clones_nvl(zfs_handle_t *zhp)
}
nvlist_free(nv);
nvlist_free(value);
verify(0 == nvlist_lookup_nvlist(zhp->zfs_props,
zfs_prop_to_name(ZFS_PROP_CLONES), &nv));
nv = fnvlist_lookup_nvlist(zhp->zfs_props,
zfs_prop_to_name(ZFS_PROP_CLONES));
}

verify(nvlist_lookup_nvlist(nv, ZPROP_VALUE, &value) == 0);

return (value);
return (fnvlist_lookup_nvlist(nv, ZPROP_VALUE));
}

static int
Expand Down Expand Up @@ -3863,7 +3858,7 @@ zfs_check_snap_cb(zfs_handle_t *zhp, void *arg)
return (EINVAL);

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);
zfs_close(zhp);
Expand All @@ -3880,7 +3875,7 @@ zfs_destroy_snaps(zfs_handle_t *zhp, char *snapname, boolean_t defer)
struct destroydata dd = { 0 };

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);

if (nvlist_empty(dd.nvl)) {
Expand All @@ -3890,7 +3885,7 @@ zfs_destroy_snaps(zfs_handle_t *zhp, char *snapname, boolean_t defer)
} else {
ret = zfs_destroy_snaps_nvl(zhp->zfs_hdl, dd.nvl, defer);
}
nvlist_free(dd.nvl);
fnvlist_free(dd.nvl);
return (ret);
}

Expand Down Expand Up @@ -4221,15 +4216,15 @@ zfs_snapshot(libzfs_handle_t *hdl, const char *path, boolean_t recursive,
return (-1);
}

verify(nvlist_alloc(&sd.sd_nvl, NV_UNIQUE_NAME, 0) == 0);
sd.sd_nvl = fnvlist_alloc();
if (recursive) {
(void) zfs_snapshot_cb(zfs_handle_dup(zhp), &sd);
} else {
fnvlist_add_boolean(sd.sd_nvl, path);
}

ret = zfs_snapshot_nvl(hdl, sd.sd_nvl, props);
nvlist_free(sd.sd_nvl);
fnvlist_free(sd.sd_nvl);
zfs_close(zhp);
return (ret);
}
Expand Down Expand Up @@ -4712,8 +4707,8 @@ zfs_expand_proplist(zfs_handle_t *zhp, zprop_list_t **plp, boolean_t received,
} else {
if (nvlist_lookup_nvlist(userprops, entry->pl_user_prop,
&propval) == 0) {
verify(nvlist_lookup_string(propval,
ZPROP_VALUE, &strval) == 0);
strval = fnvlist_lookup_string(propval,
ZPROP_VALUE);
if (strlen(strval) > entry->pl_width)
entry->pl_width = strlen(strval);
}
Expand Down
45 changes: 17 additions & 28 deletions lib/libzfs/libzfs_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pool_active(libzfs_handle_t *hdl, const char *name, uint64_t guid,
boolean_t *isactive)
{
zpool_handle_t *zhp;
uint64_t theguid;

if (zpool_open_silent(hdl, name, &zhp) != 0)
return (-1);
Expand All @@ -58,8 +57,8 @@ pool_active(libzfs_handle_t *hdl, const char *name, uint64_t guid,
return (0);
}

verify(nvlist_lookup_uint64(zhp->zpool_config, ZPOOL_CONFIG_POOL_GUID,
&theguid) == 0);
uint64_t theguid = fnvlist_lookup_uint64(zhp->zpool_config,
ZPOOL_CONFIG_POOL_GUID);

zpool_close(zhp);

Expand Down Expand Up @@ -239,12 +238,10 @@ zpool_clear_label(int fd)
static boolean_t
find_guid(nvlist_t *nv, uint64_t guid)
{
uint64_t tmp;
nvlist_t **child;
uint_t c, children;

verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &tmp) == 0);
if (tmp == guid)
if (fnvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID) == guid)
return (B_TRUE);

if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
Expand All @@ -268,18 +265,16 @@ find_aux(zpool_handle_t *zhp, void *data)
{
aux_cbdata_t *cbp = data;
nvlist_t **list;
uint_t i, count;
uint64_t guid;
nvlist_t *nvroot;
uint_t count;

verify(nvlist_lookup_nvlist(zhp->zpool_config, ZPOOL_CONFIG_VDEV_TREE,
&nvroot) == 0);
nvlist_t *nvroot = fnvlist_lookup_nvlist(zhp->zpool_config,
ZPOOL_CONFIG_VDEV_TREE);

if (nvlist_lookup_nvlist_array(nvroot, cbp->cb_type,
&list, &count) == 0) {
for (i = 0; i < count; i++) {
verify(nvlist_lookup_uint64(list[i],
ZPOOL_CONFIG_GUID, &guid) == 0);
for (uint_t i = 0; i < count; i++) {
uint64_t guid = fnvlist_lookup_uint64(list[i],
ZPOOL_CONFIG_GUID);
if (guid == cbp->cb_guid) {
cbp->cb_zhp = zhp;
return (1);
Expand All @@ -301,9 +296,9 @@ zpool_in_use(libzfs_handle_t *hdl, int fd, pool_state_t *state, char **namestr,
boolean_t *inuse)
{
nvlist_t *config;
char *name;
char *name = NULL;
boolean_t ret;
uint64_t guid, vdev_guid;
uint64_t guid = 0, vdev_guid;
zpool_handle_t *zhp;
nvlist_t *pool_config;
uint64_t stateval, isspare;
Expand All @@ -320,16 +315,12 @@ zpool_in_use(libzfs_handle_t *hdl, int fd, pool_state_t *state, char **namestr,
if (config == NULL)
return (0);

verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
&stateval) == 0);
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_GUID,
&vdev_guid) == 0);
stateval = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE);
vdev_guid = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_GUID);

if (stateval != POOL_STATE_SPARE && stateval != POOL_STATE_L2CACHE) {
verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
&name) == 0);
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
&guid) == 0);
name = fnvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME);
guid = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID);
}

switch (stateval) {
Expand Down Expand Up @@ -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 &&
(pool_config = zpool_get_config(zhp, NULL))
!= NULL) {
nvlist_t *nvroot;

verify(nvlist_lookup_nvlist(pool_config,
ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0);
nvlist_t *nvroot = fnvlist_lookup_nvlist(
pool_config, ZPOOL_CONFIG_VDEV_TREE);
ret = find_guid(nvroot, vdev_guid);
} else {
ret = B_FALSE;
Expand Down
Loading

0 comments on commit 8bb9ecf

Please sign in to comment.