nvpair: Constify string functions

After addressing coverity complaints involving `nvpair_name()`, the
compiler started complaining about dropping const. This lead to a rabbit
hole where not only `nvpair_name()` needed to be constified, but also
`nvpair_value_string()`, `fnvpair_value_string()` and a few other static
functions, plus variable pointers throughout the code. The result became
a fairly big change, so it has been split out into its own patch.

Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14612
This commit is contained in:
Richard Yao
2023-03-11 13:39:24 -05:00
committed by Brian Behlendorf
parent 50f6934b9c
commit d1807f168e
72 changed files with 442 additions and 402 deletions
+19 -16
View File
@@ -233,7 +233,7 @@ fix_paths(libpc_handle_t *hdl, nvlist_t *nv, name_entry_t *names)
uint_t c, children;
uint64_t guid;
name_entry_t *ne, *best;
char *path;
const char *path;
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
&child, &children) == 0) {
@@ -497,7 +497,7 @@ get_configs(libpc_handle_t *hdl, pool_list_t *pl, boolean_t active_ok,
uint_t i, nspares, nl2cache;
boolean_t config_seen;
uint64_t best_txg;
char *name, *hostname = NULL;
const char *name, *hostname = NULL;
uint64_t guid;
uint_t children = 0;
nvlist_t **child = NULL;
@@ -591,8 +591,8 @@ get_configs(libpc_handle_t *hdl, pool_list_t *pl, boolean_t active_ok,
* hostname (if available)
*/
uint64_t state, version;
char *comment = NULL;
char *compatibility = NULL;
const char *comment = NULL;
const char *compatibility = NULL;
version = fnvlist_lookup_uint64(tmp,
ZPOOL_CONFIG_VERSION);
@@ -1161,12 +1161,12 @@ slice_cache_compare(const void *arg1, const void *arg2)
static int
label_paths_impl(libpc_handle_t *hdl, nvlist_t *nvroot, uint64_t pool_guid,
uint64_t vdev_guid, char **path, char **devid)
uint64_t vdev_guid, const char **path, const char **devid)
{
nvlist_t **child;
uint_t c, children;
uint64_t guid;
char *val;
const char *val;
int error;
if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
@@ -1204,7 +1204,8 @@ label_paths_impl(libpc_handle_t *hdl, nvlist_t *nvroot, uint64_t pool_guid,
* The returned pointers are only valid as long as label remains valid.
*/
int
label_paths(libpc_handle_t *hdl, nvlist_t *label, char **path, char **devid)
label_paths(libpc_handle_t *hdl, nvlist_t *label, const char **path,
const char **devid)
{
nvlist_t *nvroot;
uint64_t pool_guid;
@@ -1473,7 +1474,7 @@ zpool_find_import_impl(libpc_handle_t *hdl, importargs_t *iarg,
}
if (iarg->poolname != NULL && !aux) {
char *pname;
const char *pname;
matched = nvlist_lookup_string(config,
ZPOOL_CONFIG_POOL_NAME, &pname) == 0 &&
@@ -1547,7 +1548,7 @@ static int
discover_cached_paths(libpc_handle_t *hdl, nvlist_t *nv,
avl_tree_t *cache, pthread_mutex_t *lock)
{
char *path = NULL;
const char *path = NULL;
ssize_t dl;
uint_t children;
nvlist_t **child;
@@ -1567,15 +1568,17 @@ discover_cached_paths(libpc_handle_t *hdl, nvlist_t *nv,
int ret;
char c = '\0';
if ((dl = zfs_dirnamelen(path)) == -1) {
path = (char *)".";
path = ".";
} else {
c = path[dl];
path[dl] = '\0';
((char *)path)[dl] = '\0';
}
ret = zpool_find_import_scan_dir(hdl, lock, cache,
path, 0);
if (c != '\0')
path[dl] = c;
((char *)path)[dl] = c;
return (ret);
}
return (0);
@@ -1595,7 +1598,7 @@ zpool_find_import_cached(libpc_handle_t *hdl, importargs_t *iarg)
nvlist_t *raw, *src, *dst;
nvlist_t *pools;
nvpair_t *elem;
char *name;
const char *name;
uint64_t this_guid;
boolean_t active;
@@ -1825,10 +1828,10 @@ zpool_search_import(libpc_handle_t *hdl, importargs_t *import)
}
static boolean_t
pool_match(nvlist_t *cfg, char *tgt)
pool_match(nvlist_t *cfg, const char *tgt)
{
uint64_t v, guid = strtoull(tgt, NULL, 0);
char *s;
const char *s;
if (guid != 0) {
if (nvlist_lookup_uint64(cfg, ZPOOL_CONFIG_POOL_GUID, &v) == 0)
@@ -1913,7 +1916,7 @@ for_each_vdev_cb(void *zhp, nvlist_t *nv, pool_vdev_iter_f func,
uint_t c, children;
int ret = 0;
int i;
char *type;
const char *type;
const char *list[] = {
ZPOOL_CONFIG_SPARES,