Whamcloud - gitweb
LU-6142 misc: declare static chars as const where possible. 21/38421/3
authorMr NeilBrown <neilb@suse.de>
Wed, 29 Apr 2020 23:39:04 +0000 (09:39 +1000)
committerOleg Drokin <green@whamcloud.com>
Thu, 14 May 2020 05:39:21 +0000 (05:39 +0000)
When a char * is statically initialized to a literal string, it is
best if the char is declared 'const' to ensure that literal string can
never be changed, and to allow it to be stored in read-only memory.

Unfortunately this is not possible for strings used as module
parameters.  Similarly osd_0copy_tag in osd-zfs cannot be made const,
so that is change to a simple array (no pointer).

But in many other places it is possible, and it requires all ultimate
users of the string to declare that they are working with const chars.

This patch changes a collection of static char*s to const, and in many
cases arrays of char * to "const char * const", and then propagates
the 'const' annotion as needed.

Test-Parameters: trivial
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: I3185a6cd0d1b8a7dbd83698f456f65f47b4f2954
Reviewed-on: https://review.whamcloud.com/38421
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/include/lnet/lib-lnet.h
lnet/lnet/api-ni.c
lnet/lnet/config.c
lnet/utils/lnetconfig/cyaml.c
lustre/include/lustre_import.h
lustre/mdt/mdt_lproc.c
lustre/obdclass/lprocfs_status.c
lustre/osd-ldiskfs/osd_handler.c
lustre/osd-zfs/osd_io.c
lustre/target/tgt_main.c
lustre/utils/mount_utils.h

index c414393..6db8a5d 100644 (file)
@@ -805,9 +805,9 @@ int lnet_push_target_post(struct lnet_ping_buffer *pbuf,
                          struct lnet_handle_md *mdh);
 void lnet_peer_push_event(struct lnet_event *ev);
 
                          struct lnet_handle_md *mdh);
 void lnet_peer_push_event(struct lnet_event *ev);
 
-int lnet_parse_ip2nets(char **networksp, char *ip2nets);
-int lnet_parse_routes(char *route_str, int *im_a_router);
-int lnet_parse_networks(struct list_head *nilist, char *networks,
+int lnet_parse_ip2nets(const char **networksp, const char *ip2nets);
+int lnet_parse_routes(const char *route_str, int *im_a_router);
+int lnet_parse_networks(struct list_head *nilist, const char *networks,
                        bool use_tcp_bonding);
 bool lnet_net_unique(__u32 net_id, struct list_head *nilist,
                     struct lnet_net **net);
                        bool use_tcp_bonding);
 bool lnet_net_unique(__u32 net_id, struct list_head *nilist,
                     struct lnet_net **net);
index 3fda86b..41b14f2 100644 (file)
@@ -536,17 +536,17 @@ intf_max_set(const char *val, cfs_kernel_param_arg_t *kp)
        return 0;
 }
 
        return 0;
 }
 
-static char *
+static const char *
 lnet_get_routes(void)
 {
        return routes;
 }
 
 lnet_get_routes(void)
 {
        return routes;
 }
 
-static char *
+static const char *
 lnet_get_networks(void)
 {
 lnet_get_networks(void)
 {
-       char   *nets;
-       int     rc;
+       const char *nets;
+       int rc;
 
        if (*networks != 0 && *ip2nets != 0) {
                LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
 
        if (*networks != 0 && *ip2nets != 0) {
                LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
@@ -3178,7 +3178,7 @@ static int lnet_handle_legacy_ip2nets(char *ip2nets,
                                      struct lnet_ioctl_config_lnd_tunables *tun)
 {
        struct lnet_net *net;
                                      struct lnet_ioctl_config_lnd_tunables *tun)
 {
        struct lnet_net *net;
-       char *nets;
+       const char *nets;
        int rc;
        LIST_HEAD(net_head);
 
        int rc;
        LIST_HEAD(net_head);
 
@@ -3361,7 +3361,7 @@ lnet_dyn_add_net(struct lnet_ioctl_config_data *conf)
        LIST_HEAD(net_head);
        int rc;
        struct lnet_ioctl_config_lnd_tunables tun;
        LIST_HEAD(net_head);
        int rc;
        struct lnet_ioctl_config_lnd_tunables tun;
-       char *nets = conf->cfg_config_u.cfg_net.net_intf;
+       const char *nets = conf->cfg_config_u.cfg_net.net_intf;
 
        /* Create a net/ni structures for the network string */
        rc = lnet_parse_networks(&net_head, nets, use_tcp_bonding);
 
        /* Create a net/ni structures for the network string */
        rc = lnet_parse_networks(&net_head, nets, use_tcp_bonding);
index b27306e..428098b 100644 (file)
@@ -578,7 +578,7 @@ failed:
  * nilist.
  */
 int
  * nilist.
  */
 int
-lnet_parse_networks(struct list_head *netlist, char *networks,
+lnet_parse_networks(struct list_head *netlist, const char *networks,
                    bool use_tcp_bonding)
 {
        struct cfs_expr_list *net_el = NULL;
                    bool use_tcp_bonding)
 {
        struct cfs_expr_list *net_el = NULL;
@@ -899,10 +899,10 @@ lnet_free_text_bufs(struct list_head *tbs)
 }
 
 static int
 }
 
 static int
-lnet_str2tbs_sep(struct list_head *tbs, char *str)
+lnet_str2tbs_sep(struct list_head *tbs, const char *str)
 {
        LIST_HEAD(pending);
 {
        LIST_HEAD(pending);
-       char *sep;
+       const char *sep;
        int nob;
        int i;
        struct lnet_text_buf *ltb;
        int nob;
        int i;
        struct lnet_text_buf *ltb;
@@ -1263,7 +1263,7 @@ lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router)
 }
 
 int
 }
 
 int
-lnet_parse_routes (char *routes, int *im_a_router)
+lnet_parse_routes(const char *routes, int *im_a_router)
 {
        LIST_HEAD(tbs);
        int rc = 0;
 {
        LIST_HEAD(tbs);
        int rc = 0;
@@ -1457,7 +1457,8 @@ lnet_splitnets(char *source, struct list_head *nets)
 }
 
 static int
 }
 
 static int
-lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
+lnet_match_networks(const char **networksp, const char *ip2nets,
+                   __u32 *ipaddrs, int nip)
 {
        static char       networks[LNET_SINGLE_TEXTBUF_NOB];
        static char       source[LNET_SINGLE_TEXTBUF_NOB];
 {
        static char       networks[LNET_SINGLE_TEXTBUF_NOB];
        static char       source[LNET_SINGLE_TEXTBUF_NOB];
@@ -1646,7 +1647,7 @@ unlock_rtnl:
 EXPORT_SYMBOL(lnet_inet_enumerate);
 
 int
 EXPORT_SYMBOL(lnet_inet_enumerate);
 
 int
-lnet_parse_ip2nets (char **networksp, char *ip2nets)
+lnet_parse_ip2nets(const char **networksp, const char *ip2nets)
 {
        struct lnet_inetdev *ifaces = NULL;
        __u32     *ipaddrs = NULL;
 {
        struct lnet_inetdev *ifaces = NULL;
        __u32     *ipaddrs = NULL;
index 9087bf0..8839315 100644 (file)
@@ -163,7 +163,7 @@ static yaml_token_handler dispatch_tbl[] = {
 };
 
 /* dispatch table */
 };
 
 /* dispatch table */
-static char *token_type_string[] = {
+static const char * const token_type_string[] = {
        [YAML_NO_TOKEN] = "YAML_NO_TOKEN",
        [YAML_STREAM_START_TOKEN] = "YAML_STREAM_START_TOKEN",
        [YAML_STREAM_END_TOKEN] = "YAML_STREAM_END_TOKEN",
        [YAML_NO_TOKEN] = "YAML_NO_TOKEN",
        [YAML_STREAM_START_TOKEN] = "YAML_STREAM_START_TOKEN",
        [YAML_STREAM_END_TOKEN] = "YAML_STREAM_END_TOKEN",
@@ -188,7 +188,7 @@ static char *token_type_string[] = {
        [YAML_SCALAR_TOKEN] = "YAML_SCALAR_TOKEN",
 };
 
        [YAML_SCALAR_TOKEN] = "YAML_SCALAR_TOKEN",
 };
 
-static char *state_string[] = {
+static const char * const state_string[] = {
        [TREE_STATE_COMPLETE] = "COMPLETE",
        [TREE_STATE_INITED] = "INITED",
        [TREE_STATE_TREE_STARTED] = "TREE_STARTED",
        [TREE_STATE_COMPLETE] = "COMPLETE",
        [TREE_STATE_INITED] = "INITED",
        [TREE_STATE_TREE_STARTED] = "TREE_STARTED",
index dd0fbdc..438dad9 100644 (file)
@@ -116,9 +116,9 @@ enum lustre_imp_state {
 };
 
 /** Returns test string representation of numeric import state \a state */
 };
 
 /** Returns test string representation of numeric import state \a state */
-static inline char * ptlrpc_import_state_name(enum lustre_imp_state state)
+static inline const char *ptlrpc_import_state_name(enum lustre_imp_state state)
 {
 {
-       static char *import_state_names[] = {
+       static const char * const import_state_names[] = {
                "<UNKNOWN>", "CLOSED",  "NEW", "DISCONN",
                "CONNECTING", "REPLAY", "REPLAY_LOCKS", "REPLAY_WAIT",
                "RECOVER", "FULL", "EVICTED", "IDLE",
                "<UNKNOWN>", "CLOSED",  "NEW", "DISCONN",
                "CONNECTING", "REPLAY", "REPLAY_LOCKS", "REPLAY_WAIT",
                "RECOVER", "FULL", "EVICTED", "IDLE",
index 7b99d27..81f80f4 100644 (file)
@@ -844,7 +844,7 @@ static ssize_t sync_count_store(struct kobject *kobj, struct attribute *attr,
 }
 LUSTRE_RW_ATTR(sync_count);
 
 }
 LUSTRE_RW_ATTR(sync_count);
 
-static char *dom_open_lock_modes[NUM_DOM_LOCK_ON_OPEN_MODES] = {
+static const char *dom_open_lock_modes[NUM_DOM_LOCK_ON_OPEN_MODES] = {
        [NO_DOM_LOCK_ON_OPEN] = "never",
        [TRYLOCK_DOM_ON_OPEN] = "trylock",
        [ALWAYS_DOM_LOCK_ON_OPEN] = "always",
        [NO_DOM_LOCK_ON_OPEN] = "never",
        [TRYLOCK_DOM_ON_OPEN] = "trylock",
        [ALWAYS_DOM_LOCK_ON_OPEN] = "always",
index 2cd696b..3f04296 100644 (file)
@@ -387,7 +387,7 @@ int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data)
 {
        struct obd_device *obd = data;
        struct obd_import *imp;
 {
        struct obd_device *obd = data;
        struct obd_import *imp;
-       char *imp_state_name = NULL;
+       const char *imp_state_name = NULL;
        int rc = 0;
 
        LASSERT(obd != NULL);
        int rc = 0;
 
        LASSERT(obd != NULL);
index 62df1ef..e3006f6 100644 (file)
@@ -7576,7 +7576,7 @@ static int osd_mount(const struct lu_env *env,
        *options = '\0';
        if (opts != NULL) {
                /* strip out the options for back compatiblity */
        *options = '\0';
        if (opts != NULL) {
                /* strip out the options for back compatiblity */
-               static char *sout[] = {
+               static const char * const sout[] = {
                        "mballoc",
                        "iopen",
                        "noiopen",
                        "mballoc",
                        "iopen",
                        "noiopen",
index a4c5f35..baef188 100644 (file)
@@ -61,8 +61,7 @@
 #include <sys/sa_impl.h>
 #include <sys/txg.h>
 
 #include <sys/sa_impl.h>
 #include <sys/txg.h>
 
-static char *osd_0copy_tag = "zerocopy";
-
+static char osd_0copy_tag[] = "zerocopy";
 
 static void dbuf_set_pending_evict(dmu_buf_t *db)
 {
 
 static void dbuf_set_pending_evict(dmu_buf_t *db)
 {
index ce15894..bdd05e7 100644 (file)
@@ -39,7 +39,7 @@
 
 /* This must be longer than the longest string below */
 #define SYNC_STATES_MAXLEN 16
 
 /* This must be longer than the longest string below */
 #define SYNC_STATES_MAXLEN 16
-static char *sync_lock_cancel_states[] = {
+static const char * const sync_lock_cancel_states[] = {
        [SYNC_LOCK_CANCEL_NEVER]        = "never",
        [SYNC_LOCK_CANCEL_BLOCKING]     = "blocking",
        [SYNC_LOCK_CANCEL_ALWAYS]       = "always",
        [SYNC_LOCK_CANCEL_NEVER]        = "never",
        [SYNC_LOCK_CANCEL_BLOCKING]     = "blocking",
        [SYNC_LOCK_CANCEL_ALWAYS]       = "always",
index f268392..604483d 100644 (file)
@@ -151,9 +151,9 @@ struct mount_opts {
 #ifdef HAVE_SERVER_SUPPORT
 int get_mountdata(char *, struct lustre_disk_data *);
 
 #ifdef HAVE_SERVER_SUPPORT
 int get_mountdata(char *, struct lustre_disk_data *);
 
-static inline char *mt_str(enum ldd_mount_type mt)
+static inline const char *mt_str(enum ldd_mount_type mt)
 {
 {
-       static char *mount_type_string[] = {
+       static const char * const mount_type_string[] = {
                "ext3",
                "ldiskfs",
                "smfs",
                "ext3",
                "ldiskfs",
                "smfs",
@@ -164,9 +164,9 @@ static inline char *mt_str(enum ldd_mount_type mt)
        return mount_type_string[mt];
 }
 
        return mount_type_string[mt];
 }
 
-static inline char *mt_type(enum ldd_mount_type mt)
+static inline const char *mt_type(enum ldd_mount_type mt)
 {
 {
-       static char *mount_type_string[] = {
+       static const char * const mount_type_string[] = {
                "osd-ldiskfs",
                "osd-ldiskfs",
                "osd-smfs",
                "osd-ldiskfs",
                "osd-ldiskfs",
                "osd-smfs",