diff options
Diffstat (limited to 'drivers/staging/lustre/lnet/lnet/config.c')
-rw-r--r-- | drivers/staging/lustre/lnet/lnet/config.c | 310 |
1 files changed, 115 insertions, 195 deletions
diff --git a/drivers/staging/lustre/lnet/lnet/config.c b/drivers/staging/lustre/lnet/lnet/config.c index 2dc4c4a1afd0..9c576ce2f455 100644 --- a/drivers/staging/lustre/lnet/lnet/config.c +++ b/drivers/staging/lustre/lnet/lnet/config.c @@ -38,9 +38,9 @@ #include "../../include/linux/lnet/lib-lnet.h" struct lnet_text_buf_t { /* tmp struct for parsing routes */ - struct list_head ltb_list; /* stash on lists */ - int ltb_size; /* allocated size */ - char ltb_text[0]; /* text buffer */ + struct list_head ltb_list; /* stash on lists */ + int ltb_size; /* allocated size */ + char ltb_text[0]; /* text buffer */ }; static int lnet_tbnob; /* track text buf allocation */ @@ -80,8 +80,8 @@ lnet_issep(char c) static int lnet_net_unique(__u32 net, struct list_head *nilist) { - struct list_head *tmp; - lnet_ni_t *ni; + struct list_head *tmp; + lnet_ni_t *ni; list_for_each(tmp, nilist) { ni = list_entry(tmp, lnet_ni_t, ni_list); @@ -111,10 +111,10 @@ lnet_ni_free(struct lnet_ni *ni) static lnet_ni_t * lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist) { - struct lnet_tx_queue *tq; - struct lnet_ni *ni; - int rc; - int i; + struct lnet_tx_queue *tq; + struct lnet_ni *ni; + int rc; + int i; if (!lnet_net_unique(net, nilist)) { LCONSOLE_ERROR_MSG(0x111, "Duplicate network specified: %s\n", @@ -178,13 +178,13 @@ int lnet_parse_networks(struct list_head *nilist, char *networks) { struct cfs_expr_list *el = NULL; - int tokensize = strlen(networks) + 1; - char *tokens; - char *str; - char *tmp; - struct lnet_ni *ni; - __u32 net; - int nnets = 0; + int tokensize = strlen(networks) + 1; + char *tokens; + char *str; + char *tmp; + struct lnet_ni *ni; + __u32 net; + int nnets = 0; if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) { /* _WAY_ conservative */ @@ -210,12 +210,12 @@ lnet_parse_networks(struct list_head *nilist, char *networks) goto failed; while (str != NULL && *str != 0) { - char *comma = strchr(str, ','); - char *bracket = strchr(str, '('); - char *square = strchr(str, '['); - char *iface; - int niface; - int rc; + char *comma = strchr(str, ','); + char *bracket = strchr(str, '('); + char *square = strchr(str, '['); + char *iface; + int niface; + int rc; /* NB we don't check interface conflicts here; it's the LNDs * responsibility (if it cares at all) */ @@ -369,7 +369,7 @@ static struct lnet_text_buf_t * lnet_new_text_buf(int str_len) { struct lnet_text_buf_t *ltb; - int nob; + int nob; /* NB allocate space for the terminating 0 */ nob = offsetof(struct lnet_text_buf_t, ltb_text[str_len + 1]); @@ -404,7 +404,7 @@ lnet_free_text_buf(struct lnet_text_buf_t *ltb) static void lnet_free_text_bufs(struct list_head *tbs) { - struct lnet_text_buf_t *ltb; + struct lnet_text_buf_t *ltb; while (!list_empty(tbs)) { ltb = list_entry(tbs->next, struct lnet_text_buf_t, ltb_list); @@ -417,11 +417,11 @@ lnet_free_text_bufs(struct list_head *tbs) static int lnet_str2tbs_sep(struct list_head *tbs, char *str) { - struct list_head pending; - char *sep; - int nob; - int i; - struct lnet_text_buf_t *ltb; + struct list_head pending; + char *sep; + int nob; + int i; + struct lnet_text_buf_t *ltb; INIT_LIST_HEAD(&pending); @@ -477,8 +477,8 @@ lnet_expand1tb(struct list_head *list, char *str, char *sep1, char *sep2, char *item, int itemlen) { - int len1 = (int)(sep1 - str); - int len2 = strlen(sep2 + 1); + int len1 = (int)(sep1 - str); + int len2 = strlen(sep2 + 1); struct lnet_text_buf_t *ltb; LASSERT(*sep1 == '['); @@ -500,18 +500,18 @@ lnet_expand1tb(struct list_head *list, static int lnet_str2tbs_expand(struct list_head *tbs, char *str) { - char num[16]; - struct list_head pending; - char *sep; - char *sep2; - char *parsed; - char *enditem; - int lo; - int hi; - int stride; - int i; - int nob; - int scanned; + char num[16]; + struct list_head pending; + char *sep; + char *sep2; + char *parsed; + char *enditem; + int lo; + int hi; + int stride; + int i; + int nob; + int scanned; INIT_LIST_HEAD(&pending); @@ -584,8 +584,8 @@ lnet_str2tbs_expand(struct list_head *tbs, char *str) static int lnet_parse_hops(char *str, unsigned int *hops) { - int len = strlen(str); - int nob = len; + int len = strlen(str); + int nob = len; return (sscanf(str, "%u%n", hops, &nob) >= 1 && nob == len && @@ -597,9 +597,9 @@ lnet_parse_hops(char *str, unsigned int *hops) static int lnet_parse_priority(char *str, unsigned int *priority, char **token) { - int nob; + int nob; char *sep; - int len; + int len; sep = strchr(str, LNET_PRIORITY_SEPARATOR); if (sep == NULL) { @@ -628,23 +628,23 @@ static int lnet_parse_route(char *str, int *im_a_router) { /* static scratch buffer OK (single threaded) */ - static char cmd[LNET_SINGLE_TEXTBUF_NOB]; - - struct list_head nets; - struct list_head gateways; - struct list_head *tmp1; - struct list_head *tmp2; - __u32 net; - lnet_nid_t nid; - struct lnet_text_buf_t *ltb; - int rc; - char *sep; - char *token = str; - int ntokens = 0; - int myrc = -1; - unsigned int hops; - int got_hops = 0; - unsigned int priority = 0; + static char cmd[LNET_SINGLE_TEXTBUF_NOB]; + + struct list_head nets; + struct list_head gateways; + struct list_head *tmp1; + struct list_head *tmp2; + __u32 net; + lnet_nid_t nid; + struct lnet_text_buf_t *ltb; + int rc; + char *sep; + char *token = str; + int ntokens = 0; + int myrc = -1; + unsigned int hops; + int got_hops = 0; + unsigned int priority = 0; INIT_LIST_HEAD(&gateways); INIT_LIST_HEAD(&nets); @@ -772,7 +772,7 @@ lnet_parse_route(char *str, int *im_a_router) static int lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router) { - struct lnet_text_buf_t *ltb; + struct lnet_text_buf_t *ltb; while (!list_empty(tbs)) { ltb = list_entry(tbs->next, struct lnet_text_buf_t, ltb_list); @@ -792,8 +792,8 @@ lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router) int lnet_parse_routes(char *routes, int *im_a_router) { - struct list_head tbs; - int rc = 0; + struct list_head tbs; + int rc = 0; *im_a_router = 0; @@ -814,8 +814,8 @@ static int lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip) { LIST_HEAD(list); - int rc; - int i; + int rc; + int i; rc = cfs_ip_addr_parse(token, len, &list); if (rc != 0) @@ -834,13 +834,13 @@ lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip) { static char tokens[LNET_SINGLE_TEXTBUF_NOB]; - int matched = 0; - int ntokens = 0; - int len; + int matched = 0; + int ntokens = 0; + int len; char *net = NULL; char *sep; char *token; - int rc; + int rc; LASSERT(strlen(net_entry) < sizeof(tokens)); @@ -889,8 +889,8 @@ lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip) static __u32 lnet_netspec2net(char *netspec) { - char *bracket = strchr(netspec, '('); - __u32 net; + char *bracket = strchr(netspec, '('); + __u32 net; if (bracket != NULL) *bracket = 0; @@ -906,15 +906,15 @@ lnet_netspec2net(char *netspec) static int lnet_splitnets(char *source, struct list_head *nets) { - int offset = 0; - int offset2; - int len; - struct lnet_text_buf_t *tb; - struct lnet_text_buf_t *tb2; - struct list_head *t; - char *sep; - char *bracket; - __u32 net; + int offset = 0; + int offset2; + int len; + struct lnet_text_buf_t *tb; + struct lnet_text_buf_t *tb2; + struct list_head *t; + char *sep; + char *bracket; + __u32 net; LASSERT(!list_empty(nets)); LASSERT(nets->next == nets->prev); /* single entry */ @@ -986,22 +986,22 @@ lnet_splitnets(char *source, struct list_head *nets) static int lnet_match_networks(char **networksp, char *ip2nets, __u32 *ipaddrs, int nip) { - static char networks[LNET_SINGLE_TEXTBUF_NOB]; - static char source[LNET_SINGLE_TEXTBUF_NOB]; - - struct list_head raw_entries; - struct list_head matched_nets; - struct list_head current_nets; - struct list_head *t; - struct list_head *t2; - struct lnet_text_buf_t *tb; - struct lnet_text_buf_t *tb2; - __u32 net1; - __u32 net2; - int len; - int count; - int dup; - int rc; + static char networks[LNET_SINGLE_TEXTBUF_NOB]; + static char source[LNET_SINGLE_TEXTBUF_NOB]; + + struct list_head raw_entries; + struct list_head matched_nets; + struct list_head current_nets; + struct list_head *t; + struct list_head *t2; + struct lnet_text_buf_t *tb; + struct lnet_text_buf_t *tb2; + __u32 net1; + __u32 net2; + int len; + int count; + int dup; + int rc; INIT_LIST_HEAD(&raw_entries); if (lnet_str2tbs_sep(&raw_entries, ip2nets) < 0) { @@ -1112,15 +1112,15 @@ lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip) static int lnet_ipaddr_enumerate(__u32 **ipaddrsp) { - int up; - __u32 netmask; - __u32 *ipaddrs; - __u32 *ipaddrs2; - int nip; - char **ifnames; - int nif = libcfs_ipif_enumerate(&ifnames); - int i; - int rc; + int up; + __u32 netmask; + __u32 *ipaddrs; + __u32 *ipaddrs2; + int nip; + char **ifnames; + int nif = lnet_ipif_enumerate(&ifnames); + int i; + int rc; if (nif <= 0) return nif; @@ -1128,7 +1128,7 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp) LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs)); if (ipaddrs == NULL) { CERROR("Can't allocate ipaddrs[%d]\n", nif); - libcfs_ipif_free_enumeration(ifnames, nif); + lnet_ipif_free_enumeration(ifnames, nif); return -ENOMEM; } @@ -1136,8 +1136,7 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp) if (!strcmp(ifnames[i], "lo")) continue; - rc = libcfs_ipif_query(ifnames[i], &up, - &ipaddrs[nip], &netmask); + rc = lnet_ipif_query(ifnames[i], &up, &ipaddrs[nip], &netmask); if (rc != 0) { CWARN("Can't query interface %s: %d\n", ifnames[i], rc); @@ -1153,7 +1152,7 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp) nip++; } - libcfs_ipif_free_enumeration(ifnames, nif); + lnet_ipif_free_enumeration(ifnames, nif); if (nip == nif) { *ipaddrsp = ipaddrs; @@ -1178,9 +1177,9 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp) int lnet_parse_ip2nets(char **networksp, char *ip2nets) { - __u32 *ipaddrs = NULL; - int nip = lnet_ipaddr_enumerate(&ipaddrs); - int rc; + __u32 *ipaddrs = NULL; + int nip = lnet_ipaddr_enumerate(&ipaddrs); + int rc; if (nip < 0) { LCONSOLE_ERROR_MSG(0x117, @@ -1211,82 +1210,3 @@ lnet_parse_ip2nets(char **networksp, char *ip2nets) return 0; } - -int -lnet_set_ip_niaddr(lnet_ni_t *ni) -{ - __u32 net = LNET_NIDNET(ni->ni_nid); - char **names; - int n; - __u32 ip; - __u32 netmask; - int up; - int i; - int rc; - - /* Convenience for LNDs that use the IP address of a local interface as - * the local address part of their NID */ - - if (ni->ni_interfaces[0] != NULL) { - - CLASSERT(LNET_MAX_INTERFACES > 1); - - if (ni->ni_interfaces[1] != NULL) { - CERROR("Net %s doesn't support multiple interfaces\n", - libcfs_net2str(net)); - return -EPERM; - } - - rc = libcfs_ipif_query(ni->ni_interfaces[0], - &up, &ip, &netmask); - if (rc != 0) { - CERROR("Net %s can't query interface %s: %d\n", - libcfs_net2str(net), ni->ni_interfaces[0], rc); - return -EPERM; - } - - if (!up) { - CERROR("Net %s can't use interface %s: it's down\n", - libcfs_net2str(net), ni->ni_interfaces[0]); - return -ENETDOWN; - } - - ni->ni_nid = LNET_MKNID(net, ip); - return 0; - } - - n = libcfs_ipif_enumerate(&names); - if (n <= 0) { - CERROR("Net %s can't enumerate interfaces: %d\n", - libcfs_net2str(net), n); - return 0; - } - - for (i = 0; i < n; i++) { - if (!strcmp(names[i], "lo")) /* skip the loopback IF */ - continue; - - rc = libcfs_ipif_query(names[i], &up, &ip, &netmask); - - if (rc != 0) { - CWARN("Net %s can't query interface %s: %d\n", - libcfs_net2str(net), names[i], rc); - continue; - } - - if (!up) { - CWARN("Net %s ignoring interface %s (down)\n", - libcfs_net2str(net), names[i]); - continue; - } - - libcfs_ipif_free_enumeration(names, n); - ni->ni_nid = LNET_MKNID(net, ip); - return 0; - } - - CERROR("Net %s can't find any interfaces\n", libcfs_net2str(net)); - libcfs_ipif_free_enumeration(names, n); - return -ENOENT; -} -EXPORT_SYMBOL(lnet_set_ip_niaddr); |