Add const to nvlist functions to properly expose their real behavior

Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Tony Nguyen <tony.nguyen@delphix.com>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Paul Dagnelie <pcd@delphix.com>
Closes #12728
This commit is contained in:
Paul Dagnelie
2021-12-06 17:19:13 -08:00
committed by GitHub
parent 14ba514af6
commit 795075e638
28 changed files with 728 additions and 621 deletions
+40 -34
View File
@@ -102,7 +102,7 @@ fnvlist_unpack(char *buf, size_t buflen)
}
nvlist_t *
fnvlist_dup(nvlist_t *nvl)
fnvlist_dup(const nvlist_t *nvl)
{
nvlist_t *rv;
VERIFY0(nvlist_dup(nvl, &rv, KM_SLEEP));
@@ -213,78 +213,84 @@ fnvlist_add_nvpair(nvlist_t *nvl, nvpair_t *pair)
void
fnvlist_add_boolean_array(nvlist_t *nvl, const char *name,
boolean_t *val, uint_t n)
const boolean_t *val, uint_t n)
{
VERIFY0(nvlist_add_boolean_array(nvl, name, val, n));
}
void
fnvlist_add_byte_array(nvlist_t *nvl, const char *name, uchar_t *val, uint_t n)
fnvlist_add_byte_array(nvlist_t *nvl, const char *name, const uchar_t *val,
uint_t n)
{
VERIFY0(nvlist_add_byte_array(nvl, name, val, n));
}
void
fnvlist_add_int8_array(nvlist_t *nvl, const char *name, int8_t *val, uint_t n)
fnvlist_add_int8_array(nvlist_t *nvl, const char *name, const int8_t *val,
uint_t n)
{
VERIFY0(nvlist_add_int8_array(nvl, name, val, n));
}
void
fnvlist_add_uint8_array(nvlist_t *nvl, const char *name, uint8_t *val, uint_t n)
fnvlist_add_uint8_array(nvlist_t *nvl, const char *name, const uint8_t *val,
uint_t n)
{
VERIFY0(nvlist_add_uint8_array(nvl, name, val, n));
}
void
fnvlist_add_int16_array(nvlist_t *nvl, const char *name, int16_t *val, uint_t n)
fnvlist_add_int16_array(nvlist_t *nvl, const char *name, const int16_t *val,
uint_t n)
{
VERIFY0(nvlist_add_int16_array(nvl, name, val, n));
}
void
fnvlist_add_uint16_array(nvlist_t *nvl, const char *name,
uint16_t *val, uint_t n)
const uint16_t *val, uint_t n)
{
VERIFY0(nvlist_add_uint16_array(nvl, name, val, n));
}
void
fnvlist_add_int32_array(nvlist_t *nvl, const char *name, int32_t *val, uint_t n)
fnvlist_add_int32_array(nvlist_t *nvl, const char *name, const int32_t *val,
uint_t n)
{
VERIFY0(nvlist_add_int32_array(nvl, name, val, n));
}
void
fnvlist_add_uint32_array(nvlist_t *nvl, const char *name,
uint32_t *val, uint_t n)
const uint32_t *val, uint_t n)
{
VERIFY0(nvlist_add_uint32_array(nvl, name, val, n));
}
void
fnvlist_add_int64_array(nvlist_t *nvl, const char *name, int64_t *val, uint_t n)
fnvlist_add_int64_array(nvlist_t *nvl, const char *name, const int64_t *val,
uint_t n)
{
VERIFY0(nvlist_add_int64_array(nvl, name, val, n));
}
void
fnvlist_add_uint64_array(nvlist_t *nvl, const char *name,
uint64_t *val, uint_t n)
const uint64_t *val, uint_t n)
{
VERIFY0(nvlist_add_uint64_array(nvl, name, val, n));
}
void
fnvlist_add_string_array(nvlist_t *nvl, const char *name,
char * const *val, uint_t n)
const char * const *val, uint_t n)
{
VERIFY0(nvlist_add_string_array(nvl, name, val, n));
}
void
fnvlist_add_nvlist_array(nvlist_t *nvl, const char *name,
nvlist_t **val, uint_t n)
const nvlist_t * const *val, uint_t n)
{
VERIFY0(nvlist_add_nvlist_array(nvl, name, val, n));
}
@@ -311,13 +317,13 @@ fnvlist_lookup_nvpair(nvlist_t *nvl, const char *name)
/* returns B_TRUE if the entry exists */
boolean_t
fnvlist_lookup_boolean(nvlist_t *nvl, const char *name)
fnvlist_lookup_boolean(const nvlist_t *nvl, const char *name)
{
return (nvlist_lookup_boolean(nvl, name) == 0);
}
boolean_t
fnvlist_lookup_boolean_value(nvlist_t *nvl, const char *name)
fnvlist_lookup_boolean_value(const nvlist_t *nvl, const char *name)
{
boolean_t rv;
VERIFY0(nvlist_lookup_boolean_value(nvl, name, &rv));
@@ -325,7 +331,7 @@ fnvlist_lookup_boolean_value(nvlist_t *nvl, const char *name)
}
uchar_t
fnvlist_lookup_byte(nvlist_t *nvl, const char *name)
fnvlist_lookup_byte(const nvlist_t *nvl, const char *name)
{
uchar_t rv;
VERIFY0(nvlist_lookup_byte(nvl, name, &rv));
@@ -333,7 +339,7 @@ fnvlist_lookup_byte(nvlist_t *nvl, const char *name)
}
int8_t
fnvlist_lookup_int8(nvlist_t *nvl, const char *name)
fnvlist_lookup_int8(const nvlist_t *nvl, const char *name)
{
int8_t rv;
VERIFY0(nvlist_lookup_int8(nvl, name, &rv));
@@ -341,7 +347,7 @@ fnvlist_lookup_int8(nvlist_t *nvl, const char *name)
}
int16_t
fnvlist_lookup_int16(nvlist_t *nvl, const char *name)
fnvlist_lookup_int16(const nvlist_t *nvl, const char *name)
{
int16_t rv;
VERIFY0(nvlist_lookup_int16(nvl, name, &rv));
@@ -349,7 +355,7 @@ fnvlist_lookup_int16(nvlist_t *nvl, const char *name)
}
int32_t
fnvlist_lookup_int32(nvlist_t *nvl, const char *name)
fnvlist_lookup_int32(const nvlist_t *nvl, const char *name)
{
int32_t rv;
VERIFY0(nvlist_lookup_int32(nvl, name, &rv));
@@ -357,7 +363,7 @@ fnvlist_lookup_int32(nvlist_t *nvl, const char *name)
}
int64_t
fnvlist_lookup_int64(nvlist_t *nvl, const char *name)
fnvlist_lookup_int64(const nvlist_t *nvl, const char *name)
{
int64_t rv;
VERIFY0(nvlist_lookup_int64(nvl, name, &rv));
@@ -365,7 +371,7 @@ fnvlist_lookup_int64(nvlist_t *nvl, const char *name)
}
uint8_t
fnvlist_lookup_uint8(nvlist_t *nvl, const char *name)
fnvlist_lookup_uint8(const nvlist_t *nvl, const char *name)
{
uint8_t rv;
VERIFY0(nvlist_lookup_uint8(nvl, name, &rv));
@@ -373,7 +379,7 @@ fnvlist_lookup_uint8(nvlist_t *nvl, const char *name)
}
uint16_t
fnvlist_lookup_uint16(nvlist_t *nvl, const char *name)
fnvlist_lookup_uint16(const nvlist_t *nvl, const char *name)
{
uint16_t rv;
VERIFY0(nvlist_lookup_uint16(nvl, name, &rv));
@@ -381,7 +387,7 @@ fnvlist_lookup_uint16(nvlist_t *nvl, const char *name)
}
uint32_t
fnvlist_lookup_uint32(nvlist_t *nvl, const char *name)
fnvlist_lookup_uint32(const nvlist_t *nvl, const char *name)
{
uint32_t rv;
VERIFY0(nvlist_lookup_uint32(nvl, name, &rv));
@@ -389,7 +395,7 @@ fnvlist_lookup_uint32(nvlist_t *nvl, const char *name)
}
uint64_t
fnvlist_lookup_uint64(nvlist_t *nvl, const char *name)
fnvlist_lookup_uint64(const nvlist_t *nvl, const char *name)
{
uint64_t rv;
VERIFY0(nvlist_lookup_uint64(nvl, name, &rv));
@@ -492,7 +498,7 @@ fnvlist_lookup_uint64_array(nvlist_t *nvl, const char *name, uint_t *n)
}
boolean_t
fnvpair_value_boolean_value(nvpair_t *nvp)
fnvpair_value_boolean_value(const nvpair_t *nvp)
{
boolean_t rv;
VERIFY0(nvpair_value_boolean_value(nvp, &rv));
@@ -500,7 +506,7 @@ fnvpair_value_boolean_value(nvpair_t *nvp)
}
uchar_t
fnvpair_value_byte(nvpair_t *nvp)
fnvpair_value_byte(const nvpair_t *nvp)
{
uchar_t rv;
VERIFY0(nvpair_value_byte(nvp, &rv));
@@ -508,7 +514,7 @@ fnvpair_value_byte(nvpair_t *nvp)
}
int8_t
fnvpair_value_int8(nvpair_t *nvp)
fnvpair_value_int8(const nvpair_t *nvp)
{
int8_t rv;
VERIFY0(nvpair_value_int8(nvp, &rv));
@@ -516,7 +522,7 @@ fnvpair_value_int8(nvpair_t *nvp)
}
int16_t
fnvpair_value_int16(nvpair_t *nvp)
fnvpair_value_int16(const nvpair_t *nvp)
{
int16_t rv;
VERIFY0(nvpair_value_int16(nvp, &rv));
@@ -524,7 +530,7 @@ fnvpair_value_int16(nvpair_t *nvp)
}
int32_t
fnvpair_value_int32(nvpair_t *nvp)
fnvpair_value_int32(const nvpair_t *nvp)
{
int32_t rv;
VERIFY0(nvpair_value_int32(nvp, &rv));
@@ -532,7 +538,7 @@ fnvpair_value_int32(nvpair_t *nvp)
}
int64_t
fnvpair_value_int64(nvpair_t *nvp)
fnvpair_value_int64(const nvpair_t *nvp)
{
int64_t rv;
VERIFY0(nvpair_value_int64(nvp, &rv));
@@ -540,7 +546,7 @@ fnvpair_value_int64(nvpair_t *nvp)
}
uint8_t
fnvpair_value_uint8(nvpair_t *nvp)
fnvpair_value_uint8(const nvpair_t *nvp)
{
uint8_t rv;
VERIFY0(nvpair_value_uint8(nvp, &rv));
@@ -548,7 +554,7 @@ fnvpair_value_uint8(nvpair_t *nvp)
}
uint16_t
fnvpair_value_uint16(nvpair_t *nvp)
fnvpair_value_uint16(const nvpair_t *nvp)
{
uint16_t rv;
VERIFY0(nvpair_value_uint16(nvp, &rv));
@@ -556,7 +562,7 @@ fnvpair_value_uint16(nvpair_t *nvp)
}
uint32_t
fnvpair_value_uint32(nvpair_t *nvp)
fnvpair_value_uint32(const nvpair_t *nvp)
{
uint32_t rv;
VERIFY0(nvpair_value_uint32(nvp, &rv));
@@ -564,7 +570,7 @@ fnvpair_value_uint32(nvpair_t *nvp)
}
uint64_t
fnvpair_value_uint64(nvpair_t *nvp)
fnvpair_value_uint64(const nvpair_t *nvp)
{
uint64_t rv;
VERIFY0(nvpair_value_uint64(nvp, &rv));
+82 -62
View File
@@ -308,7 +308,7 @@ nvt_hash(const char *p)
}
static boolean_t
nvt_nvpair_match(nvpair_t *nvp1, nvpair_t *nvp2, uint32_t nvflag)
nvt_nvpair_match(const nvpair_t *nvp1, const nvpair_t *nvp2, uint32_t nvflag)
{
boolean_t match = B_FALSE;
if (nvflag & NV_UNIQUE_NAME_TYPE) {
@@ -324,9 +324,9 @@ nvt_nvpair_match(nvpair_t *nvp1, nvpair_t *nvp2, uint32_t nvflag)
}
static nvpair_t *
nvt_lookup_name_type(nvlist_t *nvl, const char *name, data_type_t type)
nvt_lookup_name_type(const nvlist_t *nvl, const char *name, data_type_t type)
{
nvpriv_t *priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv;
const nvpriv_t *priv = (const nvpriv_t *)(uintptr_t)nvl->nvl_priv;
ASSERT(priv != NULL);
i_nvp_t **tab = priv->nvp_hashtable;
@@ -356,7 +356,7 @@ nvt_lookup_name_type(nvlist_t *nvl, const char *name, data_type_t type)
}
static nvpair_t *
nvt_lookup_name(nvlist_t *nvl, const char *name)
nvt_lookup_name(const nvlist_t *nvl, const char *name)
{
return (nvt_lookup_name_type(nvl, name, DATA_TYPE_DONTCARE));
}
@@ -462,7 +462,7 @@ nvt_shrink(nvpriv_t *priv)
}
static int
nvt_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp)
nvt_remove_nvpair(nvlist_t *nvl, const nvpair_t *nvp)
{
nvpriv_t *priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv;
@@ -816,16 +816,16 @@ i_validate_nvpair(nvpair_t *nvp)
}
static int
nvlist_copy_pairs(nvlist_t *snvl, nvlist_t *dnvl)
nvlist_copy_pairs(const nvlist_t *snvl, nvlist_t *dnvl)
{
nvpriv_t *priv;
i_nvp_t *curr;
const nvpriv_t *priv;
const i_nvp_t *curr;
if ((priv = (nvpriv_t *)(uintptr_t)snvl->nvl_priv) == NULL)
if ((priv = (const nvpriv_t *)(uintptr_t)snvl->nvl_priv) == NULL)
return (EINVAL);
for (curr = priv->nvp_list; curr != NULL; curr = curr->nvi_next) {
nvpair_t *nvp = &curr->nvi_nvp;
const nvpair_t *nvp = &curr->nvi_nvp;
int err;
if ((err = nvlist_add_common(dnvl, NVP_NAME(nvp), NVP_TYPE(nvp),
@@ -896,10 +896,10 @@ nvlist_free(nvlist_t *nvl)
}
static int
nvlist_contains_nvp(nvlist_t *nvl, nvpair_t *nvp)
nvlist_contains_nvp(const nvlist_t *nvl, const nvpair_t *nvp)
{
nvpriv_t *priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv;
i_nvp_t *curr;
const nvpriv_t *priv = (const nvpriv_t *)(uintptr_t)nvl->nvl_priv;
const i_nvp_t *curr;
if (nvp == NULL)
return (0);
@@ -915,13 +915,13 @@ nvlist_contains_nvp(nvlist_t *nvl, nvpair_t *nvp)
* Make a copy of nvlist
*/
int
nvlist_dup(nvlist_t *nvl, nvlist_t **nvlp, int kmflag)
nvlist_dup(const nvlist_t *nvl, nvlist_t **nvlp, int kmflag)
{
return (nvlist_xdup(nvl, nvlp, nvlist_nv_alloc(kmflag)));
}
int
nvlist_xdup(nvlist_t *nvl, nvlist_t **nvlp, nv_alloc_t *nva)
nvlist_xdup(const nvlist_t *nvl, nvlist_t **nvlp, nv_alloc_t *nva)
{
int err;
nvlist_t *ret;
@@ -1356,68 +1356,77 @@ nvlist_add_string(nvlist_t *nvl, const char *name, const char *val)
int
nvlist_add_boolean_array(nvlist_t *nvl, const char *name,
boolean_t *a, uint_t n)
const boolean_t *a, uint_t n)
{
return (nvlist_add_common(nvl, name, DATA_TYPE_BOOLEAN_ARRAY, n, a));
}
int
nvlist_add_byte_array(nvlist_t *nvl, const char *name, uchar_t *a, uint_t n)
nvlist_add_byte_array(nvlist_t *nvl, const char *name, const uchar_t *a,
uint_t n)
{
return (nvlist_add_common(nvl, name, DATA_TYPE_BYTE_ARRAY, n, a));
}
int
nvlist_add_int8_array(nvlist_t *nvl, const char *name, int8_t *a, uint_t n)
nvlist_add_int8_array(nvlist_t *nvl, const char *name, const int8_t *a,
uint_t n)
{
return (nvlist_add_common(nvl, name, DATA_TYPE_INT8_ARRAY, n, a));
}
int
nvlist_add_uint8_array(nvlist_t *nvl, const char *name, uint8_t *a, uint_t n)
nvlist_add_uint8_array(nvlist_t *nvl, const char *name, const uint8_t *a,
uint_t n)
{
return (nvlist_add_common(nvl, name, DATA_TYPE_UINT8_ARRAY, n, a));
}
int
nvlist_add_int16_array(nvlist_t *nvl, const char *name, int16_t *a, uint_t n)
nvlist_add_int16_array(nvlist_t *nvl, const char *name, const int16_t *a,
uint_t n)
{
return (nvlist_add_common(nvl, name, DATA_TYPE_INT16_ARRAY, n, a));
}
int
nvlist_add_uint16_array(nvlist_t *nvl, const char *name, uint16_t *a, uint_t n)
nvlist_add_uint16_array(nvlist_t *nvl, const char *name, const uint16_t *a,
uint_t n)
{
return (nvlist_add_common(nvl, name, DATA_TYPE_UINT16_ARRAY, n, a));
}
int
nvlist_add_int32_array(nvlist_t *nvl, const char *name, int32_t *a, uint_t n)
nvlist_add_int32_array(nvlist_t *nvl, const char *name, const int32_t *a,
uint_t n)
{
return (nvlist_add_common(nvl, name, DATA_TYPE_INT32_ARRAY, n, a));
}
int
nvlist_add_uint32_array(nvlist_t *nvl, const char *name, uint32_t *a, uint_t n)
nvlist_add_uint32_array(nvlist_t *nvl, const char *name, const uint32_t *a,
uint_t n)
{
return (nvlist_add_common(nvl, name, DATA_TYPE_UINT32_ARRAY, n, a));
}
int
nvlist_add_int64_array(nvlist_t *nvl, const char *name, int64_t *a, uint_t n)
nvlist_add_int64_array(nvlist_t *nvl, const char *name, const int64_t *a,
uint_t n)
{
return (nvlist_add_common(nvl, name, DATA_TYPE_INT64_ARRAY, n, a));
}
int
nvlist_add_uint64_array(nvlist_t *nvl, const char *name, uint64_t *a, uint_t n)
nvlist_add_uint64_array(nvlist_t *nvl, const char *name, const uint64_t *a,
uint_t n)
{
return (nvlist_add_common(nvl, name, DATA_TYPE_UINT64_ARRAY, n, a));
}
int
nvlist_add_string_array(nvlist_t *nvl, const char *name,
char *const *a, uint_t n)
const char *const *a, uint_t n)
{
return (nvlist_add_common(nvl, name, DATA_TYPE_STRING_ARRAY, n, a));
}
@@ -1429,20 +1438,21 @@ nvlist_add_hrtime(nvlist_t *nvl, const char *name, hrtime_t val)
}
int
nvlist_add_nvlist(nvlist_t *nvl, const char *name, nvlist_t *val)
nvlist_add_nvlist(nvlist_t *nvl, const char *name, const nvlist_t *val)
{
return (nvlist_add_common(nvl, name, DATA_TYPE_NVLIST, 1, val));
}
int
nvlist_add_nvlist_array(nvlist_t *nvl, const char *name, nvlist_t **a, uint_t n)
nvlist_add_nvlist_array(nvlist_t *nvl, const char *name,
const nvlist_t * const *a, uint_t n)
{
return (nvlist_add_common(nvl, name, DATA_TYPE_NVLIST_ARRAY, n, a));
}
/* reading name-value pairs */
nvpair_t *
nvlist_next_nvpair(nvlist_t *nvl, nvpair_t *nvp)
nvlist_next_nvpair(nvlist_t *nvl, const nvpair_t *nvp)
{
nvpriv_t *priv;
i_nvp_t *curr;
@@ -1471,7 +1481,7 @@ nvlist_next_nvpair(nvlist_t *nvl, nvpair_t *nvp)
}
nvpair_t *
nvlist_prev_nvpair(nvlist_t *nvl, nvpair_t *nvp)
nvlist_prev_nvpair(nvlist_t *nvl, const nvpair_t *nvp)
{
nvpriv_t *priv;
i_nvp_t *curr;
@@ -1495,31 +1505,31 @@ nvlist_prev_nvpair(nvlist_t *nvl, nvpair_t *nvp)
}
boolean_t
nvlist_empty(nvlist_t *nvl)
nvlist_empty(const nvlist_t *nvl)
{
nvpriv_t *priv;
const nvpriv_t *priv;
if (nvl == NULL ||
(priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv) == NULL)
(priv = (const nvpriv_t *)(uintptr_t)nvl->nvl_priv) == NULL)
return (B_TRUE);
return (priv->nvp_list == NULL);
}
char *
nvpair_name(nvpair_t *nvp)
nvpair_name(const nvpair_t *nvp)
{
return (NVP_NAME(nvp));
}
data_type_t
nvpair_type(nvpair_t *nvp)
nvpair_type(const nvpair_t *nvp)
{
return (NVP_TYPE(nvp));
}
int
nvpair_type_is_array(nvpair_t *nvp)
nvpair_type_is_array(const nvpair_t *nvp)
{
data_type_t type = NVP_TYPE(nvp);
@@ -1541,7 +1551,8 @@ nvpair_type_is_array(nvpair_t *nvp)
}
static int
nvpair_value_common(nvpair_t *nvp, data_type_t type, uint_t *nelem, void *data)
nvpair_value_common(const nvpair_t *nvp, data_type_t type, uint_t *nelem,
void *data)
{
int value_sz;
@@ -1585,6 +1596,10 @@ nvpair_value_common(nvpair_t *nvp, data_type_t type, uint_t *nelem, void *data)
case DATA_TYPE_STRING:
if (data == NULL)
return (EINVAL);
/*
* This discards the const from nvp, so all callers for these
* types must not accept const nvpairs.
*/
*(void **)data = (void *)NVP_VALUE(nvp);
if (nelem != NULL)
*nelem = 1;
@@ -1604,6 +1619,10 @@ nvpair_value_common(nvpair_t *nvp, data_type_t type, uint_t *nelem, void *data)
case DATA_TYPE_NVLIST_ARRAY:
if (nelem == NULL || data == NULL)
return (EINVAL);
/*
* This discards the const from nvp, so all callers for these
* types must not accept const nvpairs.
*/
if ((*nelem = NVP_NELEM(nvp)) != 0)
*(void **)data = (void *)NVP_VALUE(nvp);
else
@@ -1618,7 +1637,7 @@ nvpair_value_common(nvpair_t *nvp, data_type_t type, uint_t *nelem, void *data)
}
static int
nvlist_lookup_common(nvlist_t *nvl, const char *name, data_type_t type,
nvlist_lookup_common(const nvlist_t *nvl, const char *name, data_type_t type,
uint_t *nelem, void *data)
{
if (name == NULL || nvl == NULL || nvl->nvl_priv == 0)
@@ -1635,75 +1654,76 @@ nvlist_lookup_common(nvlist_t *nvl, const char *name, data_type_t type,
}
int
nvlist_lookup_boolean(nvlist_t *nvl, const char *name)
nvlist_lookup_boolean(const nvlist_t *nvl, const char *name)
{
return (nvlist_lookup_common(nvl, name, DATA_TYPE_BOOLEAN, NULL, NULL));
}
int
nvlist_lookup_boolean_value(nvlist_t *nvl, const char *name, boolean_t *val)
nvlist_lookup_boolean_value(const nvlist_t *nvl, const char *name,
boolean_t *val)
{
return (nvlist_lookup_common(nvl, name,
DATA_TYPE_BOOLEAN_VALUE, NULL, val));
}
int
nvlist_lookup_byte(nvlist_t *nvl, const char *name, uchar_t *val)
nvlist_lookup_byte(const nvlist_t *nvl, const char *name, uchar_t *val)
{
return (nvlist_lookup_common(nvl, name, DATA_TYPE_BYTE, NULL, val));
}
int
nvlist_lookup_int8(nvlist_t *nvl, const char *name, int8_t *val)
nvlist_lookup_int8(const nvlist_t *nvl, const char *name, int8_t *val)
{
return (nvlist_lookup_common(nvl, name, DATA_TYPE_INT8, NULL, val));
}
int
nvlist_lookup_uint8(nvlist_t *nvl, const char *name, uint8_t *val)
nvlist_lookup_uint8(const nvlist_t *nvl, const char *name, uint8_t *val)
{
return (nvlist_lookup_common(nvl, name, DATA_TYPE_UINT8, NULL, val));
}
int
nvlist_lookup_int16(nvlist_t *nvl, const char *name, int16_t *val)
nvlist_lookup_int16(const nvlist_t *nvl, const char *name, int16_t *val)
{
return (nvlist_lookup_common(nvl, name, DATA_TYPE_INT16, NULL, val));
}
int
nvlist_lookup_uint16(nvlist_t *nvl, const char *name, uint16_t *val)
nvlist_lookup_uint16(const nvlist_t *nvl, const char *name, uint16_t *val)
{
return (nvlist_lookup_common(nvl, name, DATA_TYPE_UINT16, NULL, val));
}
int
nvlist_lookup_int32(nvlist_t *nvl, const char *name, int32_t *val)
nvlist_lookup_int32(const nvlist_t *nvl, const char *name, int32_t *val)
{
return (nvlist_lookup_common(nvl, name, DATA_TYPE_INT32, NULL, val));
}
int
nvlist_lookup_uint32(nvlist_t *nvl, const char *name, uint32_t *val)
nvlist_lookup_uint32(const nvlist_t *nvl, const char *name, uint32_t *val)
{
return (nvlist_lookup_common(nvl, name, DATA_TYPE_UINT32, NULL, val));
}
int
nvlist_lookup_int64(nvlist_t *nvl, const char *name, int64_t *val)
nvlist_lookup_int64(const nvlist_t *nvl, const char *name, int64_t *val)
{
return (nvlist_lookup_common(nvl, name, DATA_TYPE_INT64, NULL, val));
}
int
nvlist_lookup_uint64(nvlist_t *nvl, const char *name, uint64_t *val)
nvlist_lookup_uint64(const nvlist_t *nvl, const char *name, uint64_t *val)
{
return (nvlist_lookup_common(nvl, name, DATA_TYPE_UINT64, NULL, val));
}
#if !defined(_KERNEL)
int
nvlist_lookup_double(nvlist_t *nvl, const char *name, double *val)
nvlist_lookup_double(const nvlist_t *nvl, const char *name, double *val)
{
return (nvlist_lookup_common(nvl, name, DATA_TYPE_DOUBLE, NULL, val));
}
@@ -2079,7 +2099,7 @@ int nvlist_lookup_nvpair_embedded_index(nvlist_t *nvl,
}
boolean_t
nvlist_exists(nvlist_t *nvl, const char *name)
nvlist_exists(const nvlist_t *nvl, const char *name)
{
nvpriv_t *priv;
nvpair_t *nvp;
@@ -2100,68 +2120,68 @@ nvlist_exists(nvlist_t *nvl, const char *name)
}
int
nvpair_value_boolean_value(nvpair_t *nvp, boolean_t *val)
nvpair_value_boolean_value(const nvpair_t *nvp, boolean_t *val)
{
return (nvpair_value_common(nvp, DATA_TYPE_BOOLEAN_VALUE, NULL, val));
}
int
nvpair_value_byte(nvpair_t *nvp, uchar_t *val)
nvpair_value_byte(const nvpair_t *nvp, uchar_t *val)
{
return (nvpair_value_common(nvp, DATA_TYPE_BYTE, NULL, val));
}
int
nvpair_value_int8(nvpair_t *nvp, int8_t *val)
nvpair_value_int8(const nvpair_t *nvp, int8_t *val)
{
return (nvpair_value_common(nvp, DATA_TYPE_INT8, NULL, val));
}
int
nvpair_value_uint8(nvpair_t *nvp, uint8_t *val)
nvpair_value_uint8(const nvpair_t *nvp, uint8_t *val)
{
return (nvpair_value_common(nvp, DATA_TYPE_UINT8, NULL, val));
}
int
nvpair_value_int16(nvpair_t *nvp, int16_t *val)
nvpair_value_int16(const nvpair_t *nvp, int16_t *val)
{
return (nvpair_value_common(nvp, DATA_TYPE_INT16, NULL, val));
}
int
nvpair_value_uint16(nvpair_t *nvp, uint16_t *val)
nvpair_value_uint16(const nvpair_t *nvp, uint16_t *val)
{
return (nvpair_value_common(nvp, DATA_TYPE_UINT16, NULL, val));
}
int
nvpair_value_int32(nvpair_t *nvp, int32_t *val)
nvpair_value_int32(const nvpair_t *nvp, int32_t *val)
{
return (nvpair_value_common(nvp, DATA_TYPE_INT32, NULL, val));
}
int
nvpair_value_uint32(nvpair_t *nvp, uint32_t *val)
nvpair_value_uint32(const nvpair_t *nvp, uint32_t *val)
{
return (nvpair_value_common(nvp, DATA_TYPE_UINT32, NULL, val));
}
int
nvpair_value_int64(nvpair_t *nvp, int64_t *val)
nvpair_value_int64(const nvpair_t *nvp, int64_t *val)
{
return (nvpair_value_common(nvp, DATA_TYPE_INT64, NULL, val));
}
int
nvpair_value_uint64(nvpair_t *nvp, uint64_t *val)
nvpair_value_uint64(const nvpair_t *nvp, uint64_t *val)
{
return (nvpair_value_common(nvp, DATA_TYPE_UINT64, NULL, val));
}
#if !defined(_KERNEL)
int
nvpair_value_double(nvpair_t *nvp, double *val)
nvpair_value_double(const nvpair_t *nvp, double *val)
{
return (nvpair_value_common(nvp, DATA_TYPE_DOUBLE, NULL, val));
}
+2 -2
View File
@@ -152,8 +152,8 @@ spa_generate_rootconf(const char *name)
fnvlist_add_string(nvroot, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT);
fnvlist_add_uint64(nvroot, ZPOOL_CONFIG_ID, 0ULL);
fnvlist_add_uint64(nvroot, ZPOOL_CONFIG_GUID, pgid);
fnvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN, tops,
nchildren);
fnvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
(const nvlist_t * const *)tops, nchildren);
/*
* Replace the existing vdev_tree with the new root vdev in
+8 -6
View File
@@ -702,7 +702,7 @@ i_fm_payload_set(nvlist_t *payload, const char *name, va_list ap)
case DATA_TYPE_STRING_ARRAY:
nelem = va_arg(ap, int);
ret = nvlist_add_string_array(payload, name,
va_arg(ap, char **), nelem);
va_arg(ap, const char **), nelem);
break;
case DATA_TYPE_NVLIST:
ret = nvlist_add_nvlist(payload, name,
@@ -711,7 +711,7 @@ i_fm_payload_set(nvlist_t *payload, const char *name, va_list ap)
case DATA_TYPE_NVLIST_ARRAY:
nelem = va_arg(ap, int);
ret = nvlist_add_nvlist_array(payload, name,
va_arg(ap, nvlist_t **), nelem);
va_arg(ap, const nvlist_t **), nelem);
break;
default:
ret = EINVAL;
@@ -867,8 +867,10 @@ fm_fmri_hc_set(nvlist_t *fmri, int version, const nvlist_t *auth,
}
va_end(ap);
if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST, pairs, npairs) != 0)
if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST,
(const nvlist_t **)pairs, npairs) != 0) {
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
}
for (i = 0; i < npairs; i++)
fm_nvlist_destroy(pairs[i], FM_NVA_RETAIN);
@@ -961,8 +963,8 @@ fm_fmri_hc_create(nvlist_t *fmri, int version, const nvlist_t *auth,
/*
* Create the fmri hc list
*/
if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST, pairs,
npairs + n) != 0) {
if (nvlist_add_nvlist_array(fmri, FM_FMRI_HC_LIST,
(const nvlist_t **)pairs, npairs + n) != 0) {
atomic_inc_64(&erpt_kstat_data.fmri_set_failed.value.ui64);
return;
}
@@ -1128,7 +1130,7 @@ fm_fmri_mem_set(nvlist_t *fmri, int version, const nvlist_t *auth,
if (serial != NULL) {
if (nvlist_add_string_array(fmri, FM_FMRI_MEM_SERIAL_ID,
(char **)&serial, 1) != 0) {
(const char **)&serial, 1) != 0) {
atomic_inc_64(
&erpt_kstat_data.fmri_set_failed.value.ui64);
}
+28 -19
View File
@@ -1851,7 +1851,8 @@ spa_load_spares(spa_t *spa)
spares[i] = vdev_config_generate(spa,
spa->spa_spares.sav_vdevs[i], B_TRUE, VDEV_CONFIG_SPARE);
fnvlist_add_nvlist_array(spa->spa_spares.sav_config,
ZPOOL_CONFIG_SPARES, spares, spa->spa_spares.sav_count);
ZPOOL_CONFIG_SPARES, (const nvlist_t * const *)spares,
spa->spa_spares.sav_count);
for (i = 0; i < spa->spa_spares.sav_count; i++)
nvlist_free(spares[i]);
kmem_free(spares, spa->spa_spares.sav_count * sizeof (void *));
@@ -1978,8 +1979,8 @@ spa_load_l2cache(spa_t *spa)
for (i = 0; i < sav->sav_count; i++)
l2cache[i] = vdev_config_generate(spa,
sav->sav_vdevs[i], B_TRUE, VDEV_CONFIG_L2CACHE);
fnvlist_add_nvlist_array(sav->sav_config, ZPOOL_CONFIG_L2CACHE, l2cache,
sav->sav_count);
fnvlist_add_nvlist_array(sav->sav_config, ZPOOL_CONFIG_L2CACHE,
(const nvlist_t * const *)l2cache, sav->sav_count);
out:
/*
@@ -2107,8 +2108,8 @@ spa_check_for_missing_logs(spa_t *spa)
}
if (idx > 0) {
fnvlist_add_nvlist_array(nv,
ZPOOL_CONFIG_CHILDREN, child, idx);
fnvlist_add_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
(const nvlist_t * const *)child, idx);
fnvlist_add_nvlist(spa->spa_load_info,
ZPOOL_CONFIG_MISSING_DEVICES, nv);
@@ -5292,8 +5293,8 @@ spa_add_spares(spa_t *spa, nvlist_t *config)
VERIFY0(nvlist_lookup_nvlist_array(spa->spa_spares.sav_config,
ZPOOL_CONFIG_SPARES, &spares, &nspares));
if (nspares != 0) {
fnvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, spares,
nspares);
fnvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
(const nvlist_t * const *)spares, nspares);
VERIFY0(nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
&spares, &nspares));
@@ -5340,8 +5341,8 @@ spa_add_l2cache(spa_t *spa, nvlist_t *config)
VERIFY0(nvlist_lookup_nvlist_array(spa->spa_l2cache.sav_config,
ZPOOL_CONFIG_L2CACHE, &l2cache, &nl2cache));
if (nl2cache != 0) {
fnvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE, l2cache,
nl2cache);
fnvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
(const nvlist_t * const *)l2cache, nl2cache);
VERIFY0(nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
&l2cache, &nl2cache));
@@ -5648,8 +5649,8 @@ spa_set_aux_vdevs(spa_aux_vdev_t *sav, nvlist_t **devs, int ndevs,
fnvlist_remove(sav->sav_config, config);
fnvlist_add_nvlist_array(sav->sav_config, config, newdevs,
ndevs + oldndevs);
fnvlist_add_nvlist_array(sav->sav_config, config,
(const nvlist_t * const *)newdevs, ndevs + oldndevs);
for (i = 0; i < oldndevs + ndevs; i++)
nvlist_free(newdevs[i]);
kmem_free(newdevs, (oldndevs + ndevs) * sizeof (void *));
@@ -5658,7 +5659,8 @@ spa_set_aux_vdevs(spa_aux_vdev_t *sav, nvlist_t **devs, int ndevs,
* Generate a new dev list.
*/
sav->sav_config = fnvlist_alloc();
fnvlist_add_nvlist_array(sav->sav_config, config, devs, ndevs);
fnvlist_add_nvlist_array(sav->sav_config, config,
(const nvlist_t * const *)devs, ndevs);
}
}
@@ -5869,7 +5871,8 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
&spares, &nspares) == 0) {
spa->spa_spares.sav_config = fnvlist_alloc();
fnvlist_add_nvlist_array(spa->spa_spares.sav_config,
ZPOOL_CONFIG_SPARES, spares, nspares);
ZPOOL_CONFIG_SPARES, (const nvlist_t * const *)spares,
nspares);
spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
spa_load_spares(spa);
spa_config_exit(spa, SCL_ALL, FTAG);
@@ -5881,9 +5884,11 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
*/
if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
&l2cache, &nl2cache) == 0) {
spa->spa_l2cache.sav_config = fnvlist_alloc();
VERIFY0(nvlist_alloc(&spa->spa_l2cache.sav_config,
NV_UNIQUE_NAME, KM_SLEEP));
fnvlist_add_nvlist_array(spa->spa_l2cache.sav_config,
ZPOOL_CONFIG_L2CACHE, l2cache, nl2cache);
ZPOOL_CONFIG_L2CACHE, (const nvlist_t * const *)l2cache,
nl2cache);
spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
spa_load_l2cache(spa);
spa_config_exit(spa, SCL_ALL, FTAG);
@@ -6131,7 +6136,8 @@ spa_import(char *pool, nvlist_t *config, nvlist_t *props, uint64_t flags)
else
spa->spa_spares.sav_config = fnvlist_alloc();
fnvlist_add_nvlist_array(spa->spa_spares.sav_config,
ZPOOL_CONFIG_SPARES, spares, nspares);
ZPOOL_CONFIG_SPARES, (const nvlist_t * const *)spares,
nspares);
spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
spa_load_spares(spa);
spa_config_exit(spa, SCL_ALL, FTAG);
@@ -6145,7 +6151,8 @@ spa_import(char *pool, nvlist_t *config, nvlist_t *props, uint64_t flags)
else
spa->spa_l2cache.sav_config = fnvlist_alloc();
fnvlist_add_nvlist_array(spa->spa_l2cache.sav_config,
ZPOOL_CONFIG_L2CACHE, l2cache, nl2cache);
ZPOOL_CONFIG_L2CACHE, (const nvlist_t * const *)l2cache,
nl2cache);
spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
spa_load_l2cache(spa);
spa_config_exit(spa, SCL_ALL, FTAG);
@@ -8472,13 +8479,15 @@ spa_sync_aux_dev(spa_t *spa, spa_aux_vdev_t *sav, dmu_tx_t *tx,
nvroot = fnvlist_alloc();
if (sav->sav_count == 0) {
fnvlist_add_nvlist_array(nvroot, config, NULL, 0);
fnvlist_add_nvlist_array(nvroot, config,
(const nvlist_t * const *)NULL, 0);
} else {
list = kmem_alloc(sav->sav_count*sizeof (void *), KM_SLEEP);
for (i = 0; i < sav->sav_count; i++)
list[i] = vdev_config_generate(spa, sav->sav_vdevs[i],
B_FALSE, VDEV_CONFIG_L2CACHE);
fnvlist_add_nvlist_array(nvroot, config, list, sav->sav_count);
fnvlist_add_nvlist_array(nvroot, config,
(const nvlist_t * const *)list, sav->sav_count);
for (i = 0; i < sav->sav_count; i++)
nvlist_free(list[i]);
kmem_free(list, sav->sav_count * sizeof (void *));
+1 -1
View File
@@ -1707,7 +1707,7 @@ vdev_draid_spare_create(nvlist_t *nvroot, vdev_t *vd, uint64_t *ndraidp,
if (n > 0) {
(void) nvlist_remove_all(nvroot, ZPOOL_CONFIG_SPARES);
fnvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
new_spares, n);
(const nvlist_t **)new_spares, n);
}
for (int i = 0; i < n; i++)
+1 -1
View File
@@ -669,7 +669,7 @@ vdev_config_generate(spa_t *spa, vdev_t *vd, boolean_t getstats,
if (idx) {
fnvlist_add_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
child, idx);
(const nvlist_t * const *)child, idx);
}
for (c = 0; c < idx; c++)
+2 -1
View File
@@ -353,7 +353,8 @@ spa_vdev_remove_aux(nvlist_t *config, char *name, nvlist_t **dev, int count,
}
VERIFY(nvlist_remove(config, name, DATA_TYPE_NVLIST_ARRAY) == 0);
VERIFY(nvlist_add_nvlist_array(config, name, newdev, count - 1) == 0);
fnvlist_add_nvlist_array(config, name, (const nvlist_t * const *)newdev,
count - 1);
for (int i = 0; i < count - 1; i++)
nvlist_free(newdev[i]);
+2 -2
View File
@@ -258,8 +258,8 @@ zfs_fuid_sync(zfsvfs_t *zfsvfs, dmu_tx_t *tx)
VERIFY(nvlist_add_string(fuids[i], FUID_DOMAIN,
domnode->f_ksid->kd_name) == 0);
}
VERIFY(nvlist_add_nvlist_array(nvp, FUID_NVP_ARRAY,
fuids, numnodes) == 0);
fnvlist_add_nvlist_array(nvp, FUID_NVP_ARRAY,
(const nvlist_t * const *)fuids, numnodes);
for (i = 0; i != numnodes; i++)
nvlist_free(fuids[i]);
kmem_free(fuids, numnodes * sizeof (void *));