Enable -Wwrite-strings

Also, fix leak from ztest_global_vars_to_zdb_args()

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #13348
This commit is contained in:
наб
2022-04-19 20:38:30 +02:00
committed by Brian Behlendorf
parent e7d90362e5
commit a926aab902
99 changed files with 633 additions and 717 deletions
+1 -1
View File
@@ -74,7 +74,7 @@ extern int getmntany(FILE *fp, struct mnttab *mp, struct mnttab *mpref);
extern int _sol_getmntent(FILE *fp, struct mnttab *mp);
extern int getextmntent(const char *path, struct extmnttab *mp,
struct stat64 *statbuf);
static inline char *_sol_hasmntopt(struct mnttab *mnt, char *opt)
static inline char *_sol_hasmntopt(struct mnttab *mnt, const char *opt)
{
struct mntent mnt_new;
+1 -1
View File
@@ -140,7 +140,7 @@ umem_nofail_callback(umem_nofail_callback_t *cb __maybe_unused)
static inline umem_cache_t *
umem_cache_create(
char *name, size_t bufsize, size_t align,
const char *name, size_t bufsize, size_t align,
umem_constructor_t *constructor,
umem_destructor_t *destructor,
umem_reclaim_t *reclaim,
+4 -3
View File
@@ -849,7 +849,8 @@ encryption_feature_is_enabled(zpool_handle_t *zph)
static int
populate_create_encryption_params_nvlists(libzfs_handle_t *hdl,
zfs_handle_t *zhp, boolean_t newkey, zfs_keyformat_t keyformat,
char *keylocation, nvlist_t *props, uint8_t **wkeydata, uint_t *wkeylen)
const char *keylocation, nvlist_t *props, uint8_t **wkeydata,
uint_t *wkeylen)
{
int ret;
uint64_t iters = 0, salt = 0;
@@ -1121,7 +1122,7 @@ zfs_crypto_create(libzfs_handle_t *hdl, char *parent_name, nvlist_t *props,
/* default to prompt if no keylocation is specified */
if (keyformat != ZFS_KEYFORMAT_NONE && keylocation == NULL) {
keylocation = "prompt";
keylocation = (char *)"prompt";
ret = nvlist_add_string(props,
zfs_prop_to_name(ZFS_PROP_KEYLOCATION), keylocation);
if (ret != 0)
@@ -1699,7 +1700,7 @@ zfs_crypto_rewrap(zfs_handle_t *zhp, nvlist_t *raw_props, boolean_t inheritkey)
/* default to prompt if no keylocation is specified */
if (keylocation == NULL) {
keylocation = "prompt";
keylocation = (char *)"prompt";
ret = nvlist_add_string(props,
zfs_prop_to_name(ZFS_PROP_KEYLOCATION),
keylocation);
+6 -6
View File
@@ -882,7 +882,7 @@ libzfs_mnttab_find(libzfs_handle_t *hdl, const char *fsname,
return (ENOENT);
srch.mnt_special = (char *)fsname;
srch.mnt_fstype = MNTTYPE_ZFS;
srch.mnt_fstype = (char *)MNTTYPE_ZFS;
ret = getmntany(mnttab, entry, &srch) ? ENOENT : 0;
(void) fclose(mnttab);
return (ret);
@@ -2051,7 +2051,7 @@ getprop_uint64(zfs_handle_t *zhp, zfs_prop_t prop, char **source)
verify(!zhp->zfs_props_table ||
zhp->zfs_props_table[prop] == B_TRUE);
value = zfs_prop_default_numeric(prop);
*source = "";
*source = (char *)"";
}
return (value);
@@ -2072,7 +2072,7 @@ getprop_string(zfs_handle_t *zhp, zfs_prop_t prop, char **source)
verify(!zhp->zfs_props_table ||
zhp->zfs_props_table[prop] == B_TRUE);
value = zfs_prop_default_string(prop);
*source = "";
*source = (char *)"";
}
return (value);
@@ -2114,8 +2114,8 @@ get_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zprop_source_t *src,
zfs_cmd_t zc = {"\0"};
nvlist_t *zplprops = NULL;
struct mnttab mnt;
char *mntopt_on = NULL;
char *mntopt_off = NULL;
const char *mntopt_on = NULL;
const char *mntopt_off = NULL;
boolean_t received = zfs_is_recvd_props_mode(zhp);
*source = NULL;
@@ -2194,7 +2194,7 @@ get_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zprop_source_t *src,
}
if (zhp->zfs_mntopts == NULL)
mnt.mnt_mntopts = "";
mnt.mnt_mntopts = (char *)"";
else
mnt.mnt_mntopts = zhp->zfs_mntopts;
+1 -1
View File
@@ -223,7 +223,7 @@ typedef struct differ_info {
int datafd;
} differ_info_t;
extern int do_mount(zfs_handle_t *zhp, const char *mntpt, char *opts,
extern int do_mount(zfs_handle_t *zhp, const char *mntpt, const char *opts,
int flags);
extern int do_unmount(zfs_handle_t *zhp, const char *mntpt, int flags);
extern int libzfs_load_module(void);
+1 -1
View File
@@ -289,7 +289,7 @@ zfs_is_mountable(zfs_handle_t *zhp, char *buf, size_t buflen,
static int
zfs_add_option(zfs_handle_t *zhp, char *options, int len,
zfs_prop_t prop, char *on, char *off)
zfs_prop_t prop, const char *on, const char *off)
{
char *source;
uint64_t value;
+5 -6
View File
@@ -119,7 +119,7 @@ zpool_get_prop_string(zpool_handle_t *zhp, zpool_prop_t prop,
zprop_source_t *src)
{
nvlist_t *nv, *nvl;
char *value;
const char *value;
zprop_source_t source;
nvl = zhp->zpool_props;
@@ -128,7 +128,7 @@ zpool_get_prop_string(zpool_handle_t *zhp, zpool_prop_t prop,
value = fnvlist_lookup_string(nv, ZPROP_VALUE);
} else {
source = ZPROP_SRC_DEFAULT;
if ((value = (char *)zpool_prop_default_string(prop)) == NULL)
if ((value = zpool_prop_default_string(prop)) == NULL)
value = "-";
}
@@ -2111,7 +2111,7 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
case EREMOTEIO:
if (nv != NULL && nvlist_lookup_nvlist(nv,
ZPOOL_CONFIG_LOAD_INFO, &nvinfo) == 0) {
char *hostname = "<unknown>";
const char *hostname = "<unknown>";
uint64_t hostid = 0;
mmp_state_t mmp_state;
@@ -5029,7 +5029,7 @@ zpool_get_vdev_prop_value(nvlist_t *nvprop, vdev_prop_t prop, char *prop_name,
char *buf, size_t len, zprop_source_t *srctype, boolean_t literal)
{
nvlist_t *nv;
char *strval;
const char *strval;
uint64_t intval;
zprop_source_t src = ZPROP_SRC_NONE;
@@ -5059,8 +5059,7 @@ zpool_get_vdev_prop_value(nvlist_t *nvprop, vdev_prop_t prop, char *prop_name,
strval = fnvlist_lookup_string(nv, ZPROP_VALUE);
} else {
src = ZPROP_SRC_DEFAULT;
if ((strval = (char *)vdev_prop_default_string(prop))
== NULL)
if ((strval = vdev_prop_default_string(prop)) == NULL)
strval = "-";
}
(void) strlcpy(buf, strval, len);
+1 -1
View File
@@ -2065,7 +2065,7 @@ send_prelim_records(zfs_handle_t *zhp, const char *from, int fd,
/* name of filesystem/volume that contains snapshot we are sending */
char tofs[ZFS_MAX_DATASET_NAME_LEN];
/* short name of snap we are sending */
char *tosnap = "";
const char *tosnap = "";
char errbuf[ERRBUFLEN];
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
+5 -3
View File
@@ -56,7 +56,7 @@
* in include/libzfs.h. Note that there are some status results which go past
* the end of this table, and hence have no associated message ID.
*/
static char *zfs_msgid_table[] = {
static const char *const zfs_msgid_table[] = {
"ZFS-8000-14", /* ZPOOL_STATUS_CORRUPT_CACHE */
"ZFS-8000-2Q", /* ZPOOL_STATUS_MISSING_DEV_R */
"ZFS-8000-3C", /* ZPOOL_STATUS_MISSING_DEV_NR */
@@ -495,7 +495,8 @@ check_status(nvlist_t *config, boolean_t isimport,
}
zpool_status_t
zpool_get_status(zpool_handle_t *zhp, char **msgid, zpool_errata_t *errata)
zpool_get_status(zpool_handle_t *zhp, const char **msgid,
zpool_errata_t *errata)
{
/*
* pass in the desired feature set, as
@@ -519,7 +520,8 @@ zpool_get_status(zpool_handle_t *zhp, char **msgid, zpool_errata_t *errata)
}
zpool_status_t
zpool_import_status(nvlist_t *config, char **msgid, zpool_errata_t *errata)
zpool_import_status(nvlist_t *config, const char **msgid,
zpool_errata_t *errata)
{
zpool_status_t ret = check_status(config, B_TRUE, errata, NULL);
+8 -11
View File
@@ -999,16 +999,13 @@ libzfs_free_str_array(char **strs, int count)
*
* Returns 0 otherwise.
*/
int
libzfs_envvar_is_set(char *envvar)
boolean_t
libzfs_envvar_is_set(const char *envvar)
{
char *env = getenv(envvar);
if (env && (strtoul(env, NULL, 0) > 0 ||
return (env && (strtoul(env, NULL, 0) > 0 ||
(!strncasecmp(env, "YES", 3) && strnlen(env, 4) == 3) ||
(!strncasecmp(env, "ON", 2) && strnlen(env, 3) == 2)))
return (1);
return (0);
(!strncasecmp(env, "ON", 2) && strnlen(env, 3) == 2)));
}
libzfs_handle_t *
@@ -2002,22 +1999,22 @@ use_color(void)
* color_end();
*/
void
color_start(char *color)
color_start(const char *color)
{
if (use_color())
printf("%s", color);
fputs(color, stdout);
}
void
color_end(void)
{
if (use_color())
printf(ANSI_RESET);
fputs(ANSI_RESET, stdout);
}
/* printf() with a color. If color is NULL, then do a normal printf. */
int
printf_color(char *color, char *format, ...)
printf_color(const char *color, const char *format, ...)
{
va_list aptr;
int rc;
+5 -6
View File
@@ -74,7 +74,7 @@ build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val,
}
static int
do_mount_(const char *spec, const char *dir, int mflag, char *fstype,
do_mount_(const char *spec, const char *dir, int mflag,
char *dataptr, int datalen, char *optptr, int optlen)
{
struct iovec *iov;
@@ -83,8 +83,6 @@ do_mount_(const char *spec, const char *dir, int mflag, char *fstype,
assert(spec != NULL);
assert(dir != NULL);
assert(fstype != NULL);
assert(strcmp(fstype, MNTTYPE_ZFS) == 0);
assert(dataptr == NULL), (void) dataptr;
assert(datalen == 0), (void) datalen;
assert(optptr != NULL);
@@ -99,7 +97,8 @@ do_mount_(const char *spec, const char *dir, int mflag, char *fstype,
build_iovec(&iov, &iovlen, "update", NULL, 0);
if (mflag & MS_RDONLY)
build_iovec(&iov, &iovlen, "ro", NULL, 0);
build_iovec(&iov, &iovlen, "fstype", fstype, (size_t)-1);
build_iovec(&iov, &iovlen, "fstype", __DECONST(char *, MNTTYPE_ZFS),
(size_t)-1);
build_iovec(&iov, &iovlen, "fspath", __DECONST(char *, dir),
(size_t)-1);
build_iovec(&iov, &iovlen, "from", __DECONST(char *, spec), (size_t)-1);
@@ -113,10 +112,10 @@ do_mount_(const char *spec, const char *dir, int mflag, char *fstype,
}
int
do_mount(zfs_handle_t *zhp, const char *mntpt, char *opts, int flags)
do_mount(zfs_handle_t *zhp, const char *mntpt, const char *opts, int flags)
{
return (do_mount_(zfs_get_name(zhp), mntpt, flags, MNTTYPE_ZFS, NULL, 0,
return (do_mount_(zfs_get_name(zhp), mntpt, flags, NULL, 0,
opts, sizeof (mntpt)));
}
+12 -18
View File
@@ -180,7 +180,7 @@ out:
* otherwise they are considered fatal are copied in to badopt.
*/
int
zfs_parse_mount_options(char *mntopts, unsigned long *mntflags,
zfs_parse_mount_options(const char *mntopts, unsigned long *mntflags,
unsigned long *zfsflags, int sloppy, char *badopt, char *mtabopt)
{
int error = 0, quote = 0, flag = 0, count = 0;
@@ -320,7 +320,7 @@ zfs_adjust_mount_options(zfs_handle_t *zhp, const char *mntpoint,
* make due with return value from the mount process.
*/
int
do_mount(zfs_handle_t *zhp, const char *mntpt, char *opts, int flags)
do_mount(zfs_handle_t *zhp, const char *mntpt, const char *opts, int flags)
{
const char *src = zfs_get_name(zhp);
int error = 0;
@@ -341,10 +341,10 @@ do_mount(zfs_handle_t *zhp, const char *mntpt, char *opts, int flags)
}
} else {
char *argv[9] = {
"/bin/mount",
"--no-canonicalize",
"-t", MNTTYPE_ZFS,
"-o", opts,
(char *)"/bin/mount",
(char *)"--no-canonicalize",
(char *)"-t", (char *)MNTTYPE_ZFS,
(char *)"-o", (char *)opts,
(char *)src,
(char *)mntpt,
(char *)NULL };
@@ -384,23 +384,17 @@ do_unmount(zfs_handle_t *zhp, const char *mntpt, int flags)
return (rv < 0 ? errno : 0);
}
char force_opt[] = "-f";
char lazy_opt[] = "-l";
char *argv[7] = {
"/bin/umount",
"-t", MNTTYPE_ZFS,
(char *)"/bin/umount",
(char *)"-t", (char *)MNTTYPE_ZFS,
NULL, NULL, NULL, NULL };
int rc, count = 3;
if (flags & MS_FORCE) {
argv[count] = force_opt;
count++;
}
if (flags & MS_FORCE)
argv[count++] = (char *)"-f";
if (flags & MS_DETACH) {
argv[count] = lazy_opt;
count++;
}
if (flags & MS_DETACH)
argv[count++] = (char *)"-l";
argv[count] = (char *)mntpt;
rc = libzfs_run_process(argv[0], argv, STDOUT_VERBOSE|STDERR_VERBOSE);
+1 -1
View File
@@ -99,7 +99,7 @@ libzfs_load_module(void)
return (0);
if (access(ZFS_SYSFS_DIR, F_OK) != 0) {
char *argv[] = {"modprobe", "zfs", NULL};
char *argv[] = {(char *)"modprobe", (char *)"zfs", NULL};
if (libzfs_run_process("modprobe", argv, 0))
return (ENOEXEC);
-2
View File
@@ -1002,8 +1002,6 @@ kmem_cache_reap_active(void)
return (0);
}
void *zvol_tag = "zvol_tag";
void
zvol_create_minor(const char *name)
{
+3 -2
View File
@@ -64,7 +64,8 @@ show_vdev_stats(const char *desc, const char *ctype, nvlist_t *nv, int indent)
}
if (desc != NULL) {
char *suffix = "", *bias = NULL;
const char *suffix = "";
char *bias = NULL;
char bias_suffix[32];
(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_LOG, &is_log);
@@ -117,7 +118,7 @@ show_vdev_stats(const char *desc, const char *ctype, nvlist_t *nv, int indent)
int len;
if (nvlist_lookup_string(cnv, ZPOOL_CONFIG_PATH, &cname) &&
nvlist_lookup_string(cnv, ZPOOL_CONFIG_TYPE, &cname))
cname = "<unknown>";
cname = (char *)"<unknown>";
len = strlen(cname) + 2;
tname = umem_zalloc(len, UMEM_NOFAIL);
(void) strlcpy(tname, cname, len);
+3 -1
View File
@@ -328,7 +328,9 @@ zpool_find_import_blkid(libpc_handle_t *hdl, pthread_mutex_t *lock,
return (EINVAL);
}
error = blkid_dev_set_search(iter, "TYPE", "zfs_member");
/* Only const char *s since 2.32 */
error = blkid_dev_set_search(iter,
(char *)"TYPE", (char *)"zfs_member");
if (error != 0) {
blkid_dev_iterate_end(iter);
blkid_put_cache(cache);
+1 -1
View File
@@ -1543,7 +1543,7 @@ discover_cached_paths(libpc_handle_t *hdl, nvlist_t *nv,
*/
if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0) {
if ((dl = zfs_dirnamelen(path)) == -1)
path = ".";
path = (char *)".";
else
path[dl] = '\0';
return (zpool_find_import_scan_dir(hdl, lock, cache,