Skip to content

Commit

Permalink
Add const to nvlist functions to properly expose their real behavior
Browse files Browse the repository at this point in the history
Reviewed-by: Matthew Ahrens <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Tony Nguyen <[email protected]>
Reviewed-by: Ryan Moeller <[email protected]>
Signed-off-by: Paul Dagnelie <[email protected]>
Closes openzfs#12728
  • Loading branch information
pcd1193182 authored Dec 7, 2021
1 parent 14ba514 commit 795075e
Show file tree
Hide file tree
Showing 28 changed files with 728 additions and 621 deletions.
3 changes: 2 additions & 1 deletion cmd/zed/agents/fmd_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ fmd_case_add_suspect(fmd_hdl_t *hdl, fmd_case_t *cp, nvlist_t *fault)
err |= nvlist_add_string(nvl, FM_SUSPECT_DIAG_CODE, code);
err |= nvlist_add_int64_array(nvl, FM_SUSPECT_DIAG_TIME, tod, 2);
err |= nvlist_add_uint32(nvl, FM_SUSPECT_FAULT_SZ, 1);
err |= nvlist_add_nvlist_array(nvl, FM_SUSPECT_FAULT_LIST, &fault, 1);
err |= nvlist_add_nvlist_array(nvl, FM_SUSPECT_FAULT_LIST,
(const nvlist_t **)&fault, 1);

if (err)
zed_log_die("failed to populate nvlist");
Expand Down
4 changes: 2 additions & 2 deletions cmd/zed/agents/zfs_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ zfs_process_add(zpool_handle_t *zhp, nvlist_t *vdev, boolean_t labeled)
ZPOOL_CONFIG_VDEV_ENC_SYSFS_PATH, enc_sysfs_path) != 0) ||
nvlist_add_uint64(newvd, ZPOOL_CONFIG_WHOLE_DISK, wholedisk) != 0 ||
nvlist_add_string(nvroot, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT) != 0 ||
nvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN, &newvd,
1) != 0) {
nvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
(const nvlist_t **)&newvd, 1) != 0) {
zed_log_msg(LOG_WARNING, "zfs_mod: unable to add nvlist pairs");
nvlist_free(newvd);
nvlist_free(nvroot);
Expand Down
2 changes: 1 addition & 1 deletion cmd/zed/agents/zfs_retire.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ replace_with_spare(fmd_hdl_t *hdl, zpool_handle_t *zhp, nvlist_t *vdev)
ZPOOL_CONFIG_ASHIFT, ashift);

(void) nvlist_add_nvlist_array(replacement,
ZPOOL_CONFIG_CHILDREN, &spares[s], 1);
ZPOOL_CONFIG_CHILDREN, (const nvlist_t **)&spares[s], 1);

fmd_hdl_debug(hdl, "zpool_vdev_replace '%s' with spare '%s'",
dev_name, zfs_basename(spare_name));
Expand Down
3 changes: 2 additions & 1 deletion cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8010,7 +8010,8 @@ zfs_do_channel_program(int argc, char **argv)
* }
*/
nvlist_t *argnvl = fnvlist_alloc();
fnvlist_add_string_array(argnvl, ZCP_ARG_CLIARGV, argv + 2, argc - 2);
fnvlist_add_string_array(argnvl, ZCP_ARG_CLIARGV,
(const char **)argv + 2, argc - 2);

if (sync_flag) {
ret = lzc_channel_program(poolname, progbuf,
Expand Down
10 changes: 5 additions & 5 deletions cmd/zpool/zpool_vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1647,8 +1647,8 @@ construct_spec(nvlist_t *props, int argc, char **argv)
}
}
verify(nvlist_add_nvlist_array(nv,
ZPOOL_CONFIG_CHILDREN, child,
children) == 0);
ZPOOL_CONFIG_CHILDREN,
(const nvlist_t **)child, children) == 0);

for (c = 0; c < children; c++)
nvlist_free(child[c]);
Expand Down Expand Up @@ -1713,13 +1713,13 @@ construct_spec(nvlist_t *props, int argc, char **argv)
verify(nvlist_add_string(nvroot, ZPOOL_CONFIG_TYPE,
VDEV_TYPE_ROOT) == 0);
verify(nvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
top, toplevels) == 0);
(const nvlist_t **)top, toplevels) == 0);
if (nspares != 0)
verify(nvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
spares, nspares) == 0);
(const nvlist_t **)spares, nspares) == 0);
if (nl2cache != 0)
verify(nvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
l2cache, nl2cache) == 0);
(const nvlist_t **)l2cache, nl2cache) == 0);

spec_out:
for (t = 0; t < toplevels; t++)
Expand Down
12 changes: 7 additions & 5 deletions cmd/ztest/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,8 @@ make_vdev_raid(char *path, char *aux, char *pool, size_t size,
ztest_opts.zo_raid_type);
fnvlist_add_uint64(raid, ZPOOL_CONFIG_NPARITY,
ztest_opts.zo_raid_parity);
fnvlist_add_nvlist_array(raid, ZPOOL_CONFIG_CHILDREN, child, r);
fnvlist_add_nvlist_array(raid, ZPOOL_CONFIG_CHILDREN,
(const nvlist_t **)child, r);

if (strcmp(ztest_opts.zo_raid_type, VDEV_TYPE_DRAID) == 0) {
uint64_t ndata = ztest_opts.zo_draid_data;
Expand Down Expand Up @@ -1335,7 +1336,8 @@ make_vdev_mirror(char *path, char *aux, char *pool, size_t size,

mirror = fnvlist_alloc();
fnvlist_add_string(mirror, ZPOOL_CONFIG_TYPE, VDEV_TYPE_MIRROR);
fnvlist_add_nvlist_array(mirror, ZPOOL_CONFIG_CHILDREN, child, m);
fnvlist_add_nvlist_array(mirror, ZPOOL_CONFIG_CHILDREN,
(const nvlist_t **)child, m);

for (c = 0; c < m; c++)
fnvlist_free(child[c]);
Expand Down Expand Up @@ -1374,7 +1376,7 @@ make_vdev_root(char *path, char *aux, char *pool, size_t size, uint64_t ashift,
root = fnvlist_alloc();
fnvlist_add_string(root, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT);
fnvlist_add_nvlist_array(root, aux ? aux : ZPOOL_CONFIG_CHILDREN,
child, t);
(const nvlist_t **)child, t);

for (c = 0; c < t; c++)
fnvlist_free(child[c]);
Expand Down Expand Up @@ -3550,8 +3552,8 @@ ztest_split_pool(ztest_ds_t *zd, uint64_t id)
/* OK, create a config that can be used to split */
split = fnvlist_alloc();
fnvlist_add_string(split, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT);
fnvlist_add_nvlist_array(split, ZPOOL_CONFIG_CHILDREN, schild,
lastlogid != 0 ? lastlogid : schildren);
fnvlist_add_nvlist_array(split, ZPOOL_CONFIG_CHILDREN,
(const nvlist_t **)schild, lastlogid != 0 ? lastlogid : schildren);

config = fnvlist_alloc();
fnvlist_add_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, split);
Expand Down
38 changes: 24 additions & 14 deletions contrib/pyzfs/libzfs_core/bindings/libnvpair.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,30 @@
int nvlist_add_uint64(nvlist_t *, const char *, uint64_t);
int nvlist_add_string(nvlist_t *, const char *, const char *);
int nvlist_add_nvlist(nvlist_t *, const char *, nvlist_t *);
int nvlist_add_boolean_array(nvlist_t *, const char *, boolean_t *,
uint_t);
int nvlist_add_byte_array(nvlist_t *, const char *, uchar_t *, uint_t);
int nvlist_add_int8_array(nvlist_t *, const char *, int8_t *, uint_t);
int nvlist_add_uint8_array(nvlist_t *, const char *, uint8_t *, uint_t);
int nvlist_add_int16_array(nvlist_t *, const char *, int16_t *, uint_t);
int nvlist_add_uint16_array(nvlist_t *, const char *, uint16_t *, uint_t);
int nvlist_add_int32_array(nvlist_t *, const char *, int32_t *, uint_t);
int nvlist_add_uint32_array(nvlist_t *, const char *, uint32_t *, uint_t);
int nvlist_add_int64_array(nvlist_t *, const char *, int64_t *, uint_t);
int nvlist_add_uint64_array(nvlist_t *, const char *, uint64_t *, uint_t);
int nvlist_add_string_array(nvlist_t *, const char *, char *const *,
uint_t);
int nvlist_add_nvlist_array(nvlist_t *, const char *, nvlist_t **, uint_t);
int nvlist_add_boolean_array(nvlist_t *, const char *,
const boolean_t *, uint_t);
int nvlist_add_byte_array(nvlist_t *, const char *,
const uchar_t *, uint_t);
int nvlist_add_int8_array(nvlist_t *, const char *,
const int8_t *, uint_t);
int nvlist_add_uint8_array(nvlist_t *, const char *,
const uint8_t *, uint_t);
int nvlist_add_int16_array(nvlist_t *, const char *,
const int16_t *, uint_t);
int nvlist_add_uint16_array(nvlist_t *, const char *,
const uint16_t *, uint_t);
int nvlist_add_int32_array(nvlist_t *, const char *,
const int32_t *, uint_t);
int nvlist_add_uint32_array(nvlist_t *, const char *,
const uint32_t *, uint_t);
int nvlist_add_int64_array(nvlist_t *, const char *,
const int64_t *, uint_t);
int nvlist_add_uint64_array(nvlist_t *, const char *,
const uint64_t *, uint_t);
int nvlist_add_string_array(nvlist_t *, const char *,
const char * const *, uint_t);
int nvlist_add_nvlist_array(nvlist_t *, const char *,
const nvlist_t * const *, uint_t);
nvpair_t *nvlist_next_nvpair(nvlist_t *, nvpair_t *);
nvpair_t *nvlist_prev_nvpair(nvlist_t *, nvpair_t *);
Expand Down
Loading

0 comments on commit 795075e

Please sign in to comment.