From 6c4ccfb9a839671b94ee267aec653ed2422b08c2 Mon Sep 17 00:00:00 2001 From: szubersk Date: Mon, 14 Feb 2022 18:44:44 +0100 Subject: [PATCH] Correct compilation errors reported by GCC 10/11 New `zfs_type_t` value `ZFS_TYPE_INVALID` is introduced. Variable initialization is now possible to make GCC happy. Close #12167. Signed-off-by: szubersk --- cmd/zfs/zfs_iter.c | 8 +++----- cmd/zpool_influxdb/zpool_influxdb.c | 2 +- include/sys/fs/zfs.h | 1 + lib/libzfs/libzfs_dataset.c | 7 ++----- lib/libzfs/libzfs_sendrecv.c | 2 +- module/zfs/zcp_get.c | 11 +++++------ 6 files changed, 13 insertions(+), 18 deletions(-) diff --git a/cmd/zfs/zfs_iter.c b/cmd/zfs/zfs_iter.c index 69b802f77a78..8b6a49a79290 100644 --- a/cmd/zfs/zfs_iter.c +++ b/cmd/zfs/zfs_iter.c @@ -453,23 +453,21 @@ zfs_for_each(int argc, char **argv, int flags, zfs_type_t types, cb.cb_flags |= ZFS_ITER_RECURSE; ret = zfs_iter_root(g_zfs, zfs_callback, &cb); } else { - int i; - zfs_handle_t *zhp; - zfs_type_t argtype; + zfs_handle_t *zhp = NULL; + zfs_type_t argtype = types; /* * If we're recursive, then we always allow filesystems as * arguments. If we also are interested in snapshots or * bookmarks, then we can take volumes as well. */ - argtype = types; if (flags & ZFS_ITER_RECURSE) { argtype |= ZFS_TYPE_FILESYSTEM; if (types & (ZFS_TYPE_SNAPSHOT | ZFS_TYPE_BOOKMARK)) argtype |= ZFS_TYPE_VOLUME; } - for (i = 0; i < argc; i++) { + for (int i = 0; i < argc; i++) { if (flags & ZFS_ITER_ARGS_CAN_BE_PATHS) { zhp = zfs_path_to_zhandle(g_zfs, argv[i], argtype); diff --git a/cmd/zpool_influxdb/zpool_influxdb.c b/cmd/zpool_influxdb/zpool_influxdb.c index 85a3f1f29248..5675409358e8 100644 --- a/cmd/zpool_influxdb/zpool_influxdb.c +++ b/cmd/zpool_influxdb/zpool_influxdb.c @@ -278,7 +278,7 @@ get_vdev_name(nvlist_t *nvroot, const char *parent_name) vdev_type); } else { (void) snprintf(vdev_name, sizeof (vdev_name), - "%s/%s-%llu", + "%.220s/%s-%llu", parent_name, vdev_type, (u_longlong_t)vdev_id); } return (vdev_name); diff --git a/include/sys/fs/zfs.h b/include/sys/fs/zfs.h index e7fc2f459e18..aec987a6887d 100644 --- a/include/sys/fs/zfs.h +++ b/include/sys/fs/zfs.h @@ -50,6 +50,7 @@ extern "C" { * combined into masks that can be passed to various functions. */ typedef enum { + ZFS_TYPE_INVALID = 0, ZFS_TYPE_FILESYSTEM = (1 << 0), ZFS_TYPE_SNAPSHOT = (1 << 1), ZFS_TYPE_VOLUME = (1 << 2), diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c index bbc12877dc05..4a9f986d2d1a 100644 --- a/lib/libzfs/libzfs_dataset.c +++ b/lib/libzfs/libzfs_dataset.c @@ -3967,13 +3967,10 @@ zfs_clone(zfs_handle_t *zhp, const char *target, nvlist_t *props) /* do the clone */ if (props) { - zfs_type_t type; + zfs_type_t type = ZFS_TYPE_FILESYSTEM; - if (ZFS_IS_VOLUME(zhp)) { + if (ZFS_IS_VOLUME(zhp)) type = ZFS_TYPE_VOLUME; - } else { - type = ZFS_TYPE_FILESYSTEM; - } if ((props = zfs_valid_proplist(hdl, type, props, zoned, zhp, zhp->zpool_hdl, B_TRUE, errbuf)) == NULL) return (-1); diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c index ab5b2b38188d..8c1a50c469b5 100644 --- a/lib/libzfs/libzfs_sendrecv.c +++ b/lib/libzfs/libzfs_sendrecv.c @@ -4194,7 +4194,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, nvlist_t *rcvprops = NULL; /* props received from the send stream */ nvlist_t *oxprops = NULL; /* override (-o) and exclude (-x) props */ nvlist_t *origprops = NULL; /* original props (if destination exists) */ - zfs_type_t type; + zfs_type_t type = ZFS_TYPE_INVALID; boolean_t toplevel = B_FALSE; boolean_t zoned = B_FALSE; boolean_t hastoken = B_FALSE; diff --git a/module/zfs/zcp_get.c b/module/zfs/zcp_get.c index eb2c606163e1..bd717f2104c5 100644 --- a/module/zfs/zcp_get.c +++ b/module/zfs/zcp_get.c @@ -76,9 +76,8 @@ get_objset_type(dsl_dataset_t *ds, zfs_type_t *type) static int get_objset_type_name(dsl_dataset_t *ds, char *str) { - int error; - zfs_type_t type; - error = get_objset_type(ds, &type); + zfs_type_t type = ZFS_TYPE_INVALID; + int error = get_objset_type(ds, &type); if (error != 0) return (error); switch (type) { @@ -230,7 +229,7 @@ get_special_prop(lua_State *state, dsl_dataset_t *ds, const char *dsname, char *strval = kmem_alloc(ZAP_MAXVALUELEN, KM_SLEEP); char setpoint[ZFS_MAX_DATASET_NAME_LEN] = "Internal error - setpoint not determined"; - zfs_type_t ds_type; + zfs_type_t ds_type = ZFS_TYPE_INVALID; zprop_type_t prop_type = zfs_prop_get_type(zfs_prop); (void) get_objset_type(ds, &ds_type); @@ -497,8 +496,8 @@ get_zap_prop(lua_State *state, dsl_dataset_t *ds, zfs_prop_t zfs_prop) boolean_t prop_valid_for_ds(dsl_dataset_t *ds, zfs_prop_t zfs_prop) { - int error; - zfs_type_t zfs_type; + int error = 0; + zfs_type_t zfs_type = ZFS_TYPE_INVALID; /* properties not supported */ if ((zfs_prop == ZFS_PROP_ISCSIOPTIONS) ||