From 809809a85b4d2eee42d1366e0f5d9b991a92efac Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Thu, 28 Mar 2024 16:39:27 -0700 Subject: [PATCH] LU-8191 lnet: convert functions in utils to static Static analysis shows that a number of functions could be made static. This patch declares several functions in various LNet utils and lnetconfig to static. In LNet selftest (lst), one unused function was removed entirely. Some declarations were moved to made static. Lustre-change: https://review.whamcloud.com/51427 Lustre-commit: d9cd9992b9e04bfad1ebd755f78d3e96850eaa32 Test-Parameters: trivial Signed-off-by: Timothy Day Change-Id: Ia4528281b3c87d77e46abb95f47ab0bdc72168c0 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/54619 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- lnet/utils/lnetconfig/cyaml.c | 2 +- lnet/utils/lnetconfig/liblnetconfig.c | 34 ++++---- lnet/utils/lst.c | 151 ++++++++++++++++------------------ lnet/utils/routerstat.c | 14 ++-- lnet/utils/wirecheck.c | 10 +-- 5 files changed, 99 insertions(+), 112 deletions(-) diff --git a/lnet/utils/lnetconfig/cyaml.c b/lnet/utils/lnetconfig/cyaml.c index 0c859a1..3a54947 100644 --- a/lnet/utils/lnetconfig/cyaml.c +++ b/lnet/utils/lnetconfig/cyaml.c @@ -750,7 +750,7 @@ bool cYAML_is_sequence(struct cYAML *node) return (node != NULL ? node->cy_type == CYAML_TYPE_ARRAY : 0); } -void cYAML_tree_recursive_walk(struct cYAML *node, cYAML_walk_cb cb, +static void cYAML_tree_recursive_walk(struct cYAML *node, cYAML_walk_cb cb, bool cb_first, void *usr_data, void **out) diff --git a/lnet/utils/lnetconfig/liblnetconfig.c b/lnet/utils/lnetconfig/liblnetconfig.c index bf62252..2b937d1 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.c +++ b/lnet/utils/lnetconfig/liblnetconfig.c @@ -95,7 +95,7 @@ struct lustre_lnet_ip2nets { struct list_head ip2nets_ip_ranges; }; -int open_sysfs_file(const char *path, const char *attr, const int mode) +static int open_sysfs_file(const char *path, const char *attr, const int mode) { int fd; char filename[LNET_MAX_STR_LEN]; @@ -155,7 +155,7 @@ close_fd: * free_intf_descr * frees the memory allocated for an intf descriptor. */ -void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr) +static void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr) { if (!intf_descr) return; @@ -177,7 +177,7 @@ void free_intf_descr(struct lnet_dlc_intf_descr *intf_descr) * As a result of lnetctl command * When building a NID or P2P selection rules */ -int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range) +static int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range) { struct lustre_lnet_ip_range_descr *ip_range; int rc; @@ -199,7 +199,8 @@ int lustre_lnet_add_ip_range(struct list_head *list, char *str_ip_range) return LUSTRE_CFG_RC_NO_ERR; } -int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len) +static int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, + int len) { char *open_sq_bracket = NULL, *close_sq_bracket = NULL, *intf_name; @@ -802,9 +803,9 @@ out: return rc; } -int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio, - int sen, int seq_no, struct cYAML **err_rc, - int cmd) +static int lustre_lnet_route_common(char *nw, char *nidstr, int hops, int prio, + int sen, int seq_no, struct cYAML **err_rc, + int cmd) { int rc, num_nids, idx; __u32 rnet; @@ -1288,9 +1289,9 @@ failed: * * The result is that all the interfaces have to match. */ -int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa, - struct list_head *intf_list, - struct list_head *ip_ranges) +static int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa, + struct list_head *intf_list, + struct list_head *ip_ranges) { int rc; __u32 ip; @@ -1539,7 +1540,7 @@ lustre_lnet_ioctl_config_ni(struct list_head *intf_list, return LUSTRE_CFG_RC_NO_ERR; } -int +static int lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets, struct lnet_ioctl_config_lnd_tunables *tunables, struct cfs_expr_list *global_cpts, @@ -2381,8 +2382,8 @@ out: return rc; } -int ioctl_set_value(__u32 val, int ioc, char *name, - int seq_no, struct cYAML **err_rc) +static int ioctl_set_value(__u32 val, int ioc, char *name, + int seq_no, struct cYAML **err_rc) { struct lnet_ioctl_set_value data; int rc = LUSTRE_CFG_RC_NO_ERR; @@ -3693,7 +3694,7 @@ out: return rc; } -unsigned int +static unsigned int lnet_nid_cpt_hash(lnet_nid_t nid, long int number) { __u64 key = nid; @@ -3735,8 +3736,9 @@ int lustre_lnet_calc_cpt_of_nid(char *nidc, long int ncpts) return (int)lnet_nid_cpt_hash(nid, ncpts); } -int show_recovery_queue(enum lnet_health_type type, char *name, int seq_no, - struct cYAML **show_rc, struct cYAML **err_rc) +static int show_recovery_queue(enum lnet_health_type type, char *name, + int seq_no, struct cYAML **show_rc, + struct cYAML **err_rc) { struct lnet_ioctl_recovery_list nid_list; struct cYAML *root = NULL, *nids = NULL; diff --git a/lnet/utils/lst.c b/lnet/utils/lst.c index 3ea8834..ac3c29f 100644 --- a/lnet/utils/lst.c +++ b/lnet/utils/lst.c @@ -54,6 +54,14 @@ #include #include "lnetconfig/liblnetconfig.h" +static int lst_info_batch_ioctl(char *batch, int test, int server, + struct lstcon_test_batch_ent *entp, int *idxp, + int *ndentp, struct lstcon_node_ent *dentsp); +static int lst_info_group_ioctl(char *name, struct lstcon_ndlist_ent *gent, + int *idx, int *count, struct lstcon_node_ent *dents); +static int lst_query_batch_ioctl(char *batch, int test, int server, + int timeout, struct list_head *head); + struct lst_sid LST_INVALID_SID = { .ses_nid = LNET_NID_ANY, .ses_stamp = -1 }; static struct lst_sid session_id; static int session_key; @@ -76,7 +84,7 @@ typedef struct list_string { static int alloc_count = 0; static int alloc_nob = 0; -lstr_t * +static lstr_t * alloc_lstr(int sz) { lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz])); @@ -94,7 +102,7 @@ alloc_lstr(int sz) return lstr; } -void +static void free_lstr(lstr_t *lstr) { alloc_count--; @@ -102,18 +110,7 @@ free_lstr(lstr_t *lstr) free(lstr); } -void -free_lstrs(lstr_t **list) -{ - lstr_t *lstr; - - while ((lstr = *list) != NULL) { - *list = lstr->lstr_next; - free_lstr(lstr); - } -} - -void +static void new_lstrs(lstr_t **list, char *prefix, char *postfix, int lo, int hi, int stride) { @@ -134,7 +131,7 @@ new_lstrs(lstr_t **list, char *prefix, char *postfix, } while (lo <= hi); } -int +static int expand_lstr(lstr_t **list, lstr_t *l) { int nob = strlen(l->lstr_str); @@ -200,7 +197,7 @@ expand_lstr(lstr_t **list, lstr_t *l) return 1; } -int +static int expand_strs(char *str, lstr_t **head) { lstr_t *list = NULL; @@ -253,7 +250,7 @@ expand_strs(char *str, lstr_t **head) return rc; } -int +static int lst_parse_nids(char *str, int *countp, struct lnet_process_id **idspp) { lstr_t *head = NULL; @@ -308,7 +305,7 @@ out: return rc; } -char * +static char * lst_node_state2str(int state) { if (state == LST_NODE_ACTIVE) @@ -321,7 +318,7 @@ lst_node_state2str(int state) return "Unknown"; } -int +static int lst_node_str2state(char *str) { if (strcasecmp(str, "active") == 0) @@ -338,7 +335,7 @@ lst_node_str2state(char *str) return -1; } -char * +static char * lst_test_type2name(int type) { if (type == LST_TEST_PING) @@ -349,7 +346,7 @@ lst_test_type2name(int type) return "unknown"; } -int +static int lst_test_name2type(char *name) { if (strcasecmp(name, "ping") == 0) @@ -360,13 +357,13 @@ lst_test_name2type(char *name) return -1; } -void +static void lst_print_usage(char *cmd) { Parser_printhelp(cmd); } -void +static void lst_print_error(char *sub, const char *def_format, ...) { va_list ap; @@ -403,7 +400,7 @@ lst_print_error(char *sub, const char *def_format, ...) } } -void +static void lst_free_rpcent(struct list_head *head) { struct lstcon_rpc_ent *ent; @@ -416,7 +413,7 @@ lst_free_rpcent(struct list_head *head) } } -void +static void lst_reset_rpcent(struct list_head *head) { struct lstcon_rpc_ent *ent; @@ -429,7 +426,7 @@ lst_reset_rpcent(struct list_head *head) } } -int +static int lst_alloc_rpcent(struct list_head *head, int count, int offset) { struct lstcon_rpc_ent *ent; @@ -453,7 +450,7 @@ lst_alloc_rpcent(struct list_head *head, int count, int offset) return 0; } -void +static void lst_print_transerr(struct list_head *head, char *optstr) { struct lstcon_rpc_ent *ent; @@ -475,17 +472,7 @@ lst_print_transerr(struct list_head *head, char *optstr) } } -int lst_info_batch_ioctl(char *batch, int test, int server, - struct lstcon_test_batch_ent *entp, int *idxp, - int *ndentp, struct lstcon_node_ent *dentsp); - -int lst_info_group_ioctl(char *name, struct lstcon_ndlist_ent *gent, - int *idx, int *count, struct lstcon_node_ent *dents); - -int lst_query_batch_ioctl(char *batch, int test, int server, - int timeout, struct list_head *head); - -int +static int lst_ioctl(unsigned int opc, void *buf, int len) { struct libcfs_ioctl_data data; @@ -517,7 +504,7 @@ lst_ioctl(unsigned int opc, void *buf, int len) return 0; } -int +static int lst_new_session_ioctl(char *name, int timeout, int force, struct lst_sid *sid) { struct lstio_session_new_args args = { 0 }; @@ -533,7 +520,7 @@ lst_new_session_ioctl(char *name, int timeout, int force, struct lst_sid *sid) return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args)); } -int +static int jt_lst_new_session(int argc, char **argv) { char buf[LST_NAME_SIZE * 2 + 1]; @@ -623,7 +610,7 @@ jt_lst_new_session(int argc, char **argv) return 0; } -int +static int lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp, struct lst_sid *sid, struct lstcon_ndlist_ent *ndinfo) { @@ -639,7 +626,7 @@ lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp, return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args)); } -int +static int jt_lst_show_session(int argc, char **argv) { struct lstcon_ndlist_ent ndinfo; @@ -665,7 +652,7 @@ jt_lst_show_session(int argc, char **argv) return 0; } -int +static int lst_end_session_ioctl(void) { struct lstio_session_end_args args = { 0 }; @@ -674,7 +661,7 @@ lst_end_session_ioctl(void) return lst_ioctl(LSTIO_SESSION_END, &args, sizeof(args)); } -int +static int jt_lst_end_session(int argc, char **argv) { int rc; @@ -715,7 +702,7 @@ jt_lst_end_session(int argc, char **argv) return rc; } -int +static int lst_ping_ioctl(char *str, int type, int timeout, int count, struct lnet_process_id *ids, struct list_head *head) { @@ -734,7 +721,7 @@ lst_ping_ioctl(char *str, int type, int timeout, return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args)); } -int +static int lst_get_node_count(int type, char *str, int *countp, struct lnet_process_id **idspp) { @@ -777,7 +764,7 @@ lst_get_node_count(int type, char *str, int *countp, return rc; } -int +static int jt_lst_ping(int argc, char **argv) { struct list_head head; @@ -909,7 +896,7 @@ out: } -int +static int lst_add_nodes_ioctl(char *name, int count, struct lnet_process_id *ids, unsigned *featp, struct list_head *resultp) { @@ -926,7 +913,7 @@ lst_add_nodes_ioctl(char *name, int count, struct lnet_process_id *ids, return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args)); } -int +static int lst_del_group_ioctl(char *name) { struct lstio_group_del_args args = { 0 }; @@ -938,7 +925,7 @@ lst_del_group_ioctl(char *name) return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args)); } -int +static int lst_del_group(char *grp_name) { int rc; @@ -974,7 +961,7 @@ lst_del_group(char *grp_name) return -1; } -int +static int lst_add_group_ioctl(char *name) { struct lstio_group_add_args args = { 0 }; @@ -986,7 +973,7 @@ lst_add_group_ioctl(char *name) return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args)); } -int +static int jt_lst_add_group(int argc, char **argv) { struct list_head head; @@ -1118,7 +1105,7 @@ failed: return rc; } -int +static int jt_lst_del_group(int argc, char **argv) { int rc; @@ -1139,7 +1126,7 @@ jt_lst_del_group(int argc, char **argv) return rc; } -int +static int lst_update_group_ioctl(int opc, char *name, int clean, int count, struct lnet_process_id *ids, struct list_head *resultp) { @@ -1157,7 +1144,7 @@ lst_update_group_ioctl(int opc, char *name, int clean, int count, return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args)); } -int +static int jt_lst_update_group(int argc, char **argv) { struct list_head head; @@ -1280,7 +1267,7 @@ jt_lst_update_group(int argc, char **argv) return rc; } -int +static int lst_list_group_ioctl(int len, char *name, int idx) { struct lstio_group_list_args args = { 0 }; @@ -1293,7 +1280,7 @@ lst_list_group_ioctl(int len, char *name, int idx) return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args)); } -int +static int lst_info_group_ioctl(char *name, struct lstcon_ndlist_ent *gent, int *idx, int *count, struct lstcon_node_ent *dents) { @@ -1310,7 +1297,7 @@ lst_info_group_ioctl(char *name, struct lstcon_ndlist_ent *gent, return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args)); } -int +static int lst_list_group_all(void) { char name[LST_NAME_SIZE]; @@ -1340,7 +1327,7 @@ lst_list_group_all(void) #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n" -int +static int jt_lst_list_group(int argc, char **argv) { struct lstcon_ndlist_ent gent; @@ -1485,7 +1472,7 @@ jt_lst_list_group(int argc, char **argv) return rc; } -int +static int lst_stat_ioctl(char *name, int count, struct lnet_process_id *idsp, int timeout, struct list_head *resultp) { @@ -1847,7 +1834,7 @@ lst_print_stat(char *name, struct list_head *resultp, lst_print_lnet_stat(name, bwrt, rdwr, type, mbs); } -int +static int jt_lst_stat(int argc, char **argv) { struct list_head head; @@ -2025,7 +2012,7 @@ out: return rc; } -int +static int jt_lst_show_error(int argc, char **argv) { struct list_head head; @@ -2148,7 +2135,7 @@ out: return rc; } -int +static int lst_add_batch_ioctl(char *name) { struct lstio_batch_add_args args = { 0 }; @@ -2160,7 +2147,7 @@ lst_add_batch_ioctl(char *name) return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args)); } -int +static int jt_lst_add_batch(int argc, char **argv) { char *name; @@ -2194,7 +2181,7 @@ jt_lst_add_batch(int argc, char **argv) return -1; } -int +static int lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp) { struct lstio_batch_run_args args = { 0 }; @@ -2208,7 +2195,7 @@ lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp) return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args)); } -int +static int jt_lst_start_batch(int argc, char **argv) { struct list_head head; @@ -2295,7 +2282,7 @@ jt_lst_start_batch(int argc, char **argv) return rc; } -int +static int lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp) { struct lstio_batch_stop_args args = { 0 }; @@ -2309,7 +2296,7 @@ lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp) return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args)); } -int +static int jt_lst_stop_batch(int argc, char **argv) { struct list_head head; @@ -2413,7 +2400,7 @@ out: return rc; } -int +static int lst_list_batch_ioctl(int len, char *name, int index) { struct lstio_batch_list_args args = { 0 }; @@ -2426,7 +2413,7 @@ lst_list_batch_ioctl(int len, char *name, int index) return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args)); } -int +static int lst_info_batch_ioctl(char *batch, int test, int server, struct lstcon_test_batch_ent *entp, int *idxp, int *ndentp, struct lstcon_node_ent *dentsp) @@ -2446,7 +2433,7 @@ lst_info_batch_ioctl(char *batch, int test, int server, return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args)); } -int +static int lst_list_batch_all(void) { char name[LST_NAME_SIZE]; @@ -2473,7 +2460,7 @@ lst_list_batch_all(void) return 0; } -int +static int lst_list_tsb_nodes(char *batch, int test, int server, int count, int active, int invalid) { @@ -2523,7 +2510,7 @@ lst_list_tsb_nodes(char *batch, int test, int server, return 0; } -int +static int jt_lst_list_batch(int argc, char **argv) { struct lstcon_test_batch_ent ent; @@ -2659,7 +2646,7 @@ loop: return 0; } -int +static int lst_query_batch_ioctl(char *batch, int test, int server, int timeout, struct list_head *head) { @@ -2676,7 +2663,7 @@ lst_query_batch_ioctl(char *batch, int test, int server, return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args)); } -void +static void lst_print_tsb_verbose(struct list_head *head, int active, int idle, int error) { @@ -2701,7 +2688,7 @@ lst_print_tsb_verbose(struct list_head *head, } } -int +static int jt_lst_query_batch(int argc, char **argv) { struct lstcon_test_batch_ent ent; @@ -2882,7 +2869,7 @@ jt_lst_query_batch(int argc, char **argv) return rc; } -int +static int lst_parse_distribute(char *dstr, int *dist, int *span) { *dist = atoi(dstr); @@ -2900,7 +2887,7 @@ lst_parse_distribute(char *dstr, int *dist, int *span) return 0; } -int +static int lst_get_bulk_param(int argc, char **argv, struct lst_test_bulk_param *bulk) { char *tok = NULL; @@ -2991,7 +2978,7 @@ lst_get_bulk_param(int argc, char **argv, struct lst_test_bulk_param *bulk) return rc; } -int +static int lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen) { struct lst_test_bulk_param *bulk = NULL; @@ -3034,7 +3021,7 @@ lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen) return type; } -int +static int lst_add_test_ioctl(char *batch, int type, int loop, int concur, int dist, int span, char *sgrp, char *dgrp, void *param, int plen, int *retp, struct list_head *resultp) @@ -3062,7 +3049,7 @@ lst_add_test_ioctl(char *batch, int type, int loop, int concur, return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args)); } -int +static int jt_lst_add_test(int argc, char **argv) { struct list_head head; @@ -3257,7 +3244,7 @@ static command_t lst_cmdlist[] = { {0, 0, 0, NULL } }; -int +static int lst_initialize(void) { char *key; diff --git a/lnet/utils/routerstat.c b/lnet/utils/routerstat.c index 2071ac9..78a9baf 100644 --- a/lnet/utils/routerstat.c +++ b/lnet/utils/routerstat.c @@ -43,8 +43,7 @@ #include -double -timenow () +static double timenow(void) { struct timeval tv; @@ -66,7 +65,7 @@ typedef struct { unsigned long long drop_length; } counters_t; -unsigned long long subull(unsigned long long a, unsigned long long b) +static unsigned long long subull(unsigned long long a, unsigned long long b) { if (a < b) return -1ULL - b + a + 1; @@ -74,7 +73,7 @@ unsigned long long subull(unsigned long long a, unsigned long long b) return a - b; } -unsigned long long subul(unsigned long a, unsigned long b) +static unsigned long long subul(unsigned long a, unsigned long b) { if (a < b) return -1UL - b + a + 1; @@ -82,18 +81,17 @@ unsigned long long subul(unsigned long a, unsigned long b) return a - b; } -double rul(unsigned long a, double secs) +static double rul(unsigned long a, double secs) { return (double)a/secs; } -double rull(unsigned long long a, double secs) +static double rull(unsigned long long a, double secs) { return (double)a/secs; } -void -do_stat (int fd) +static void do_stat(int fd) { static char buffer[1024]; static double last = 0.0; diff --git a/lnet/utils/wirecheck.c b/lnet/utils/wirecheck.c index b233b6f..7a7db6b 100644 --- a/lnet/utils/wirecheck.c +++ b/lnet/utils/wirecheck.c @@ -101,7 +101,7 @@ do { \ CHECK_VALUE((int)sizeof(s)); \ } while (0) -void +static void check_lnet_handle_wire(void) { CHECK_STRUCT(struct lnet_handle_wire); @@ -109,7 +109,7 @@ check_lnet_handle_wire(void) CHECK_MEMBER(struct lnet_handle_wire, wh_object_cookie); } -void +static void check_lnet_magicversion (void) { CHECK_STRUCT(struct lnet_magicversion); @@ -162,7 +162,7 @@ check_lnet_hdr (void) CHECK_MEMBER(struct lnet_hdr, msg.hello.type); } -void +static void check_lnet_ni_status(void) { BLANK_LINE(); @@ -178,7 +178,7 @@ check_lnet_ni_status(void) CHECK_MEMBER(struct lnet_ni_status, ns_unused); } -void +static void check_lnet_ping_info(void) { BLANK_LINE(); @@ -201,7 +201,7 @@ check_lnet_ping_info(void) CHECK_MEMBER_IS_FLEXIBLE(struct lnet_ping_info, pi_ni); } -void +static void system_string(char *cmdline, char *str, int len) { int fds[2]; -- 1.8.3.1