mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 18:40:43 +03:00
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:
committed by
Brian Behlendorf
parent
50f6934b9c
commit
d1807f168e
@@ -168,9 +168,9 @@ zpool_open_func(void *arg)
|
||||
* Add additional entries for paths described by this label.
|
||||
*/
|
||||
if (rn->rn_labelpaths) {
|
||||
char *path = NULL;
|
||||
char *devid = NULL;
|
||||
char *env = NULL;
|
||||
const char *path = NULL;
|
||||
const char *devid = NULL;
|
||||
const char *env = NULL;
|
||||
rdsk_node_t *slice;
|
||||
avl_index_t where;
|
||||
int timeout;
|
||||
@@ -769,7 +769,7 @@ no_dev:
|
||||
* vdev_enc_sysfs_path: '/sys/class/enclosure/11:0:1:0/SLOT 4'
|
||||
*/
|
||||
static void
|
||||
update_vdev_config_dev_sysfs_path(nvlist_t *nv, char *path)
|
||||
update_vdev_config_dev_sysfs_path(nvlist_t *nv, const char *path)
|
||||
{
|
||||
char *upath, *spath;
|
||||
|
||||
@@ -795,7 +795,7 @@ sysfs_path_pool_vdev_iter_f(void *hdl_data, nvlist_t *nv, void *data)
|
||||
{
|
||||
(void) hdl_data, (void) data;
|
||||
|
||||
char *path = NULL;
|
||||
const char *path = NULL;
|
||||
if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) != 0)
|
||||
return (1);
|
||||
|
||||
@@ -841,7 +841,7 @@ void
|
||||
update_vdev_config_dev_strs(nvlist_t *nv)
|
||||
{
|
||||
vdev_dev_strs_t vds;
|
||||
char *env, *type, *path;
|
||||
const char *env, *type, *path;
|
||||
uint64_t wholedisk = 0;
|
||||
|
||||
/*
|
||||
|
||||
+19
-16
@@ -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,
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
#define IMPORT_ORDER_SCAN_OFFSET 10
|
||||
#define IMPORT_ORDER_DEFAULT 100
|
||||
|
||||
int label_paths(libpc_handle_t *hdl, nvlist_t *label, char **path,
|
||||
char **devid);
|
||||
int label_paths(libpc_handle_t *hdl, nvlist_t *label, const char **path,
|
||||
const char **devid);
|
||||
int zpool_find_import_blkid(libpc_handle_t *hdl, pthread_mutex_t *lock,
|
||||
avl_tree_t **slice_cache);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user