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
+3 -3
View File
@@ -264,7 +264,7 @@ get_vdev_name(nvlist_t *nvroot, const char *parent_name)
static char vdev_name[256];
uint64_t vdev_id = 0;
char *vdev_type = (char *)"unknown";
const char *vdev_type = "unknown";
(void) nvlist_lookup_string(nvroot, ZPOOL_CONFIG_TYPE, &vdev_type);
if (nvlist_lookup_uint64(
@@ -299,9 +299,9 @@ get_vdev_desc(nvlist_t *nvroot, const char *parent_name)
char vdev_value[MAXPATHLEN];
char *s, *t;
char *vdev_type = (char *)"unknown";
const char *vdev_type = "unknown";
uint64_t vdev_id = UINT64_MAX;
char *vdev_path = NULL;
const char *vdev_path = NULL;
(void) nvlist_lookup_string(nvroot, ZPOOL_CONFIG_TYPE, &vdev_type);
(void) nvlist_lookup_uint64(nvroot, ZPOOL_CONFIG_ID, &vdev_id);
(void) nvlist_lookup_string(nvroot, ZPOOL_CONFIG_PATH, &vdev_path);