X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lnet%2Flnet%2Fconfig.c;h=b18c103ccd2b5277b7c9116e83faf4ab01bbd7cd;hb=c4677f0d97dff8d1084baa1792c0ad6af1000158;hp=f8d6dea053085299cf168ce31049c596a3e19189;hpb=5e1e6a6756d3b4ca19a0d7e0defcf974dbfed13c;p=fs%2Flustre-release.git diff --git a/lnet/lnet/config.c b/lnet/lnet/config.c index f8d6dea..b18c103 100644 --- a/lnet/lnet/config.c +++ b/lnet/lnet/config.c @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -26,8 +24,10 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2012, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -37,26 +37,17 @@ #define DEBUG_SUBSYSTEM S_LNET #include -typedef struct { /* tmp struct for parsing routes */ - struct list_head ltb_list; /* stash on lists */ - int ltb_size; /* allocated size */ - char ltb_text[0]; /* text buffer */ +typedef struct { /* tmp struct for parsing routes */ + cfs_list_t ltb_list; /* stash on lists */ + int ltb_size; /* allocated size */ + char ltb_text[0]; /* text buffer */ } lnet_text_buf_t; static int lnet_tbnob = 0; /* track text buf allocation */ #define LNET_MAX_TEXTBUF_NOB (64<<10) /* bound allocation */ #define LNET_SINGLE_TEXTBUF_NOB (4<<10) -typedef struct { - struct list_head lre_list; /* stash in a list */ - int lre_min; /* min value */ - int lre_max; /* max value */ - int lre_stride; /* stride */ -} lnet_range_expr_t; - -static int lnet_re_alloc = 0; /* track expr allocation */ - -void +void lnet_syntax(char *name, char *str, int offset, int width) { static char dots[LNET_SINGLE_TEXTBUF_NOB]; @@ -86,33 +77,14 @@ lnet_issep (char c) } } -char * -lnet_trimwhite(char *str) -{ - char *end; - - while (cfs_iswhite(*str)) - str++; - - end = str + strlen(str); - while (end > str) { - if (!cfs_iswhite(end[-1])) - break; - end--; - } - - *end = 0; - return str; -} - int -lnet_net_unique(__u32 net, struct list_head *nilist) +lnet_net_unique(__u32 net, cfs_list_t *nilist) { - struct list_head *tmp; + cfs_list_t *tmp; lnet_ni_t *ni; - list_for_each (tmp, nilist) { - ni = list_entry(tmp, lnet_ni_t, ni_list); + cfs_list_for_each (tmp, nilist) { + ni = cfs_list_entry(tmp, lnet_ni_t, ni_list); if (LNET_NIDNET(ni->ni_nid) == net) return 0; @@ -121,10 +93,33 @@ lnet_net_unique(__u32 net, struct list_head *nilist) return 1; } +void +lnet_ni_free(struct lnet_ni *ni) +{ + if (ni->ni_refs != NULL) + cfs_percpt_free(ni->ni_refs); + + if (ni->ni_tx_queues != NULL) + cfs_percpt_free(ni->ni_tx_queues); + + if (ni->ni_cpts != NULL) + cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts); + +#ifndef __KERNEL__ +# ifdef HAVE_LIBPTHREAD + pthread_mutex_destroy(&ni->ni_lock); +# endif +#endif + LIBCFS_FREE(ni, sizeof(*ni)); +} + lnet_ni_t * -lnet_new_ni(__u32 net, struct list_head *nilist) +lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, cfs_list_t *nilist) { - lnet_ni_t *ni; + 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", @@ -139,27 +134,68 @@ lnet_new_ni(__u32 net, struct list_head *nilist) return NULL; } - /* zero counters/flags, NULL pointers... */ - memset(ni, 0, sizeof(*ni)); +#ifdef __KERNEL__ + spin_lock_init(&ni->ni_lock); +#else +# ifdef HAVE_LIBPTHREAD + pthread_mutex_init(&ni->ni_lock, NULL); +# endif +#endif + CFS_INIT_LIST_HEAD(&ni->ni_cptlist); + ni->ni_refs = cfs_percpt_alloc(lnet_cpt_table(), + sizeof(*ni->ni_refs[0])); + if (ni->ni_refs == NULL) + goto failed; + + ni->ni_tx_queues = cfs_percpt_alloc(lnet_cpt_table(), + sizeof(*ni->ni_tx_queues[0])); + if (ni->ni_tx_queues == NULL) + goto failed; + + cfs_percpt_for_each(tq, i, ni->ni_tx_queues) + CFS_INIT_LIST_HEAD(&tq->tq_delayed); + + if (el == NULL) { + ni->ni_cpts = NULL; + ni->ni_ncpts = LNET_CPT_NUMBER; + } else { + rc = cfs_expr_list_values(el, LNET_CPT_NUMBER, &ni->ni_cpts); + if (rc <= 0) { + CERROR("Failed to set CPTs for NI %s: %d\n", + libcfs_net2str(net), rc); + goto failed; + } - /* LND will fill in the address part of the NID */ - ni->ni_nid = LNET_MKNID(net, 0); - CFS_INIT_LIST_HEAD(&ni->ni_txq); - ni->ni_last_alive = cfs_time_current(); + LASSERT(rc <= LNET_CPT_NUMBER); + if (rc == LNET_CPT_NUMBER) { + LIBCFS_FREE(ni->ni_cpts, rc * sizeof(ni->ni_cpts[0])); + ni->ni_cpts = NULL; + } - list_add_tail(&ni->ni_list, nilist); - return ni; + ni->ni_ncpts = rc; + } + + /* LND will fill in the address part of the NID */ + ni->ni_nid = LNET_MKNID(net, 0); + ni->ni_last_alive = cfs_time_current_sec(); + cfs_list_add_tail(&ni->ni_list, nilist); + return ni; + failed: + lnet_ni_free(ni); + return NULL; } int -lnet_parse_networks(struct list_head *nilist, char *networks) +lnet_parse_networks(cfs_list_t *nilist, char *networks) { - int tokensize = strlen(networks) + 1; - char *tokens; - char *str; - lnet_ni_t *ni; - __u32 net; - int nnets = 0; + 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; if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) { /* _WAY_ conservative */ @@ -177,21 +213,48 @@ lnet_parse_networks(struct list_head *nilist, char *networks) the_lnet.ln_network_tokens = tokens; the_lnet.ln_network_tokens_nob = tokensize; memcpy (tokens, networks, tokensize); - str = tokens; - - /* Add in the loopback network */ - ni = lnet_new_ni(LNET_MKNET(LOLND, 0), nilist); - if (ni == NULL) - goto failed; - - while (str != NULL && *str != 0) { - char *comma = strchr(str, ','); - char *bracket = strchr(str, '('); - int niface; - char *iface; + str = tmp = tokens; + + /* Add in the loopback network */ + ni = lnet_ni_alloc(LNET_MKNET(LOLND, 0), NULL, nilist); + if (ni == NULL) + 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; + + /* NB we don't check interface conflicts here; it's the LNDs + * responsibility (if it cares at all) */ + + if (square != NULL && (comma == NULL || square < comma)) { + /* i.e: o2ib0(ib0)[1,2], number between square + * brackets are CPTs this NI needs to be bond */ + if (bracket != NULL && bracket > square) { + tmp = square; + goto failed_syntax; + } + + tmp = strchr(square, ']'); + if (tmp == NULL) { + tmp = square; + goto failed_syntax; + } - /* NB we don't check interface conflicts here; it's the LNDs - * responsibility (if it cares at all) */ + rc = cfs_expr_list_parse(square, tmp - square + 1, + 0, LNET_CPT_NUMBER - 1, &el); + if (rc != 0) { + tmp = square; + goto failed_syntax; + } + + while (square <= tmp) + *square++ = ' '; + } if (bracket == NULL || (comma != NULL && comma < bracket)) { @@ -200,45 +263,52 @@ lnet_parse_networks(struct list_head *nilist, char *networks) if (comma != NULL) *comma++ = 0; - net = libcfs_str2net(lnet_trimwhite(str)); - + net = libcfs_str2net(cfs_trimwhite(str)); + if (net == LNET_NIDNET(LNET_NID_ANY)) { - lnet_syntax("networks", networks, - (int)(str - tokens), strlen(str)); LCONSOLE_ERROR_MSG(0x113, "Unrecognised network" " type\n"); - goto failed; + tmp = str; + goto failed_syntax; } - if (LNET_NETTYP(net) != LOLND && /* loopback is implicit */ - lnet_new_ni(net, nilist) == NULL) - goto failed; + if (LNET_NETTYP(net) != LOLND && /* LO is implicit */ + lnet_ni_alloc(net, el, nilist) == NULL) + goto failed; + + if (el != NULL) { + cfs_expr_list_free(el); + el = NULL; + } str = comma; continue; } *bracket = 0; - net = libcfs_str2net(lnet_trimwhite(str)); + net = libcfs_str2net(cfs_trimwhite(str)); if (net == LNET_NIDNET(LNET_NID_ANY)) { - lnet_syntax("networks", networks, - (int)(str - tokens), strlen(str)); - goto failed; - } + tmp = str; + goto failed_syntax; + } - nnets++; - ni = lnet_new_ni(net, nilist); - if (ni == NULL) - goto failed; + nnets++; + ni = lnet_ni_alloc(net, el, nilist); + if (ni == NULL) + goto failed; + + if (el != NULL) { + cfs_expr_list_free(el); + el = NULL; + } - niface = 0; + niface = 0; iface = bracket + 1; bracket = strchr(iface, ')'); if (bracket == NULL) { - lnet_syntax("networks", networks, - (int)(iface - tokens), strlen(iface)); - goto failed; + tmp = iface; + goto failed_syntax; } *bracket = 0; @@ -246,12 +316,11 @@ lnet_parse_networks(struct list_head *nilist, char *networks) comma = strchr(iface, ','); if (comma != NULL) *comma++ = 0; - - iface = lnet_trimwhite(iface); + + iface = cfs_trimwhite(iface); if (*iface == 0) { - lnet_syntax("networks", networks, - (int)(iface - tokens), strlen(iface)); - goto failed; + tmp = iface; + goto failed_syntax; } if (niface == LNET_MAX_INTERFACES) { @@ -269,38 +338,42 @@ lnet_parse_networks(struct list_head *nilist, char *networks) comma = strchr(bracket + 1, ','); if (comma != NULL) { *comma = 0; - str = lnet_trimwhite(str); + str = cfs_trimwhite(str); if (*str != 0) { - lnet_syntax("networks", networks, - (int)(str - tokens), strlen(str)); - goto failed; + tmp = str; + goto failed_syntax; } str = comma + 1; continue; } - - str = lnet_trimwhite(str); + + str = cfs_trimwhite(str); if (*str != 0) { - lnet_syntax("networks", networks, - (int)(str - tokens), strlen(str)); - goto failed; - } + tmp = str; + goto failed_syntax; + } } - LASSERT (!list_empty(nilist)); - return 0; + LASSERT(!cfs_list_empty(nilist)); + return 0; + failed_syntax: + lnet_syntax("networks", networks, (int)(tmp - tokens), strlen(tmp)); failed: - while (!list_empty(nilist)) { - ni = list_entry(nilist->next, lnet_ni_t, ni_list); - - list_del(&ni->ni_list); - LIBCFS_FREE(ni, sizeof(*ni)); - } + while (!cfs_list_empty(nilist)) { + ni = cfs_list_entry(nilist->next, lnet_ni_t, ni_list); + + cfs_list_del(&ni->ni_list); + lnet_ni_free(ni); + } + + if (el != NULL) + cfs_expr_list_free(el); + LIBCFS_FREE(tokens, tokensize); - the_lnet.ln_network_tokens = NULL; + the_lnet.ln_network_tokens = NULL; - return -EINVAL; + return -EINVAL; } lnet_text_buf_t * @@ -340,26 +413,26 @@ lnet_free_text_buf (lnet_text_buf_t *ltb) } void -lnet_free_text_bufs(struct list_head *tbs) +lnet_free_text_bufs(cfs_list_t *tbs) { lnet_text_buf_t *ltb; - - while (!list_empty(tbs)) { - ltb = list_entry(tbs->next, lnet_text_buf_t, ltb_list); - - list_del(<b->ltb_list); + + while (!cfs_list_empty(tbs)) { + ltb = cfs_list_entry(tbs->next, lnet_text_buf_t, ltb_list); + + cfs_list_del(<b->ltb_list); lnet_free_text_buf(ltb); } } void -lnet_print_text_bufs(struct list_head *tbs) +lnet_print_text_bufs(cfs_list_t *tbs) { - struct list_head *tmp; + cfs_list_t *tmp; lnet_text_buf_t *ltb; - list_for_each (tmp, tbs) { - ltb = list_entry(tmp, lnet_text_buf_t, ltb_list); + cfs_list_for_each (tmp, tbs) { + ltb = cfs_list_entry(tmp, lnet_text_buf_t, ltb_list); CDEBUG(D_WARNING, "%s\n", ltb->ltb_text); } @@ -368,9 +441,9 @@ lnet_print_text_bufs(struct list_head *tbs) } int -lnet_str2tbs_sep (struct list_head *tbs, char *str) +lnet_str2tbs_sep (cfs_list_t *tbs, char *str) { - struct list_head pending; + cfs_list_t pending; char *sep; int nob; int i; @@ -405,7 +478,7 @@ lnet_str2tbs_sep (struct list_head *tbs, char *str) ltb->ltb_text[nob] = 0; - list_add_tail(<b->ltb_list, &pending); + cfs_list_add_tail(<b->ltb_list, &pending); } if (*sep == '#') { @@ -421,12 +494,12 @@ lnet_str2tbs_sep (struct list_head *tbs, char *str) str = sep + 1; } - list_splice(&pending, tbs->prev); + cfs_list_splice(&pending, tbs->prev); return 0; } int -lnet_expand1tb (struct list_head *list, +lnet_expand1tb (cfs_list_t *list, char *str, char *sep1, char *sep2, char *item, int itemlen) { @@ -440,21 +513,21 @@ lnet_expand1tb (struct list_head *list, ltb = lnet_new_text_buf(len1 + itemlen + len2); if (ltb == NULL) return -ENOMEM; - + memcpy(ltb->ltb_text, str, len1); memcpy(<b->ltb_text[len1], item, itemlen); memcpy(<b->ltb_text[len1+itemlen], sep2 + 1, len2); ltb->ltb_text[len1 + itemlen + len2] = 0; - - list_add_tail(<b->ltb_list, list); + + cfs_list_add_tail(<b->ltb_list, list); return 0; } int -lnet_str2tbs_expand (struct list_head *tbs, char *str) +lnet_str2tbs_expand (cfs_list_t *tbs, char *str) { char num[16]; - struct list_head pending; + cfs_list_t pending; char *sep; char *sep2; char *parsed; @@ -467,7 +540,7 @@ lnet_str2tbs_expand (struct list_head *tbs, char *str) int scanned; CFS_INIT_LIST_HEAD(&pending); - + sep = strchr(str, '['); if (sep == NULL) /* nothing to expand */ return 0; @@ -522,7 +595,7 @@ lnet_str2tbs_expand (struct list_head *tbs, char *str) } } - list_splice(&pending, tbs->prev); + cfs_list_splice(&pending, tbs->prev); return 1; failed: @@ -535,7 +608,7 @@ lnet_parse_hops (char *str, unsigned int *hops) { int len = strlen(str); int nob = len; - + return (sscanf(str, "%u%n", hops, &nob) >= 1 && nob == len && *hops > 0 && *hops < 256); @@ -548,10 +621,10 @@ 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; + cfs_list_t nets; + cfs_list_t gateways; + cfs_list_t *tmp1; + cfs_list_t *tmp2; __u32 net; lnet_nid_t nid; lnet_text_buf_t *ltb; @@ -606,10 +679,10 @@ lnet_parse_route (char *str, int *im_a_router) strcpy(ltb->ltb_text, token); tmp1 = <b->ltb_list; - list_add_tail(tmp1, tmp2); + cfs_list_add_tail(tmp1, tmp2); while (tmp1 != tmp2) { - ltb = list_entry(tmp1, lnet_text_buf_t, ltb_list); + ltb = cfs_list_entry(tmp1, lnet_text_buf_t, ltb_list); rc = lnet_str2tbs_expand(tmp1->next, ltb->ltb_text); if (rc < 0) @@ -618,7 +691,7 @@ lnet_parse_route (char *str, int *im_a_router) tmp1 = tmp1->next; if (rc > 0) { /* expanded! */ - list_del(<b->ltb_list); + cfs_list_del(<b->ltb_list); lnet_free_text_buf(ltb); continue; } @@ -640,16 +713,16 @@ lnet_parse_route (char *str, int *im_a_router) if (!got_hops) hops = 1; - LASSERT (!list_empty(&nets)); - LASSERT (!list_empty(&gateways)); + LASSERT (!cfs_list_empty(&nets)); + LASSERT (!cfs_list_empty(&gateways)); - list_for_each (tmp1, &nets) { - ltb = list_entry(tmp1, lnet_text_buf_t, ltb_list); + cfs_list_for_each (tmp1, &nets) { + ltb = cfs_list_entry(tmp1, lnet_text_buf_t, ltb_list); net = libcfs_str2net(ltb->ltb_text); LASSERT (net != LNET_NIDNET(LNET_NID_ANY)); - list_for_each (tmp2, &gateways) { - ltb = list_entry(tmp2, lnet_text_buf_t, ltb_list); + cfs_list_for_each (tmp2, &gateways) { + ltb = cfs_list_entry(tmp2, lnet_text_buf_t, ltb_list); nid = libcfs_str2nid(ltb->ltb_text); LASSERT (nid != LNET_NID_ANY); @@ -681,19 +754,19 @@ lnet_parse_route (char *str, int *im_a_router) } int -lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router) +lnet_parse_route_tbs(cfs_list_t *tbs, int *im_a_router) { lnet_text_buf_t *ltb; - while (!list_empty(tbs)) { - ltb = list_entry(tbs->next, lnet_text_buf_t, ltb_list); + while (!cfs_list_empty(tbs)) { + ltb = cfs_list_entry(tbs->next, lnet_text_buf_t, ltb_list); if (lnet_parse_route(ltb->ltb_text, im_a_router) < 0) { lnet_free_text_bufs(tbs); return -EINVAL; } - list_del(<b->ltb_list); + cfs_list_del(<b->ltb_list); lnet_free_text_buf(ltb); } @@ -703,7 +776,7 @@ 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; + cfs_list_t tbs; int rc = 0; *im_a_router = 0; @@ -721,195 +794,22 @@ lnet_parse_routes (char *routes, int *im_a_router) return rc; } -void -lnet_print_range_exprs(struct list_head *exprs) -{ - struct list_head *e; - lnet_range_expr_t *lre; - - list_for_each(e, exprs) { - lre = list_entry(exprs->next, lnet_range_expr_t, lre_list); - - CDEBUG(D_WARNING, "%d-%d/%d\n", - lre->lre_min, lre->lre_max, lre->lre_stride); - } - - CDEBUG(D_WARNING, "%d allocated\n", lnet_re_alloc); -} - int -lnet_new_range_expr(struct list_head *exprs, int min, int max, int stride) +lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip) { - lnet_range_expr_t *lre; + CFS_LIST_HEAD (list); + int rc; + int i; - CDEBUG(D_NET, "%d-%d/%d\n", min, max, stride); + rc = cfs_ip_addr_parse(token, len, &list); + if (rc != 0) + return rc; - if (min < 0 || min > 255 || min > max || stride < 0) - return -EINVAL; - - LIBCFS_ALLOC(lre, sizeof(*lre)); - if (lre == NULL) - return -ENOMEM; + for (rc = i = 0; !rc && i < nip; i++) + rc = cfs_ip_addr_match(ipaddrs[i], &list); - lnet_re_alloc++; + cfs_ip_addr_free(&list); - lre->lre_min = min; - lre->lre_max = max; - lre->lre_stride = stride; - - list_add(&lre->lre_list, exprs); - return 0; -} - -void -lnet_destroy_range_exprs(struct list_head *exprs) -{ - lnet_range_expr_t *lre; - - while (!list_empty(exprs)) { - lre = list_entry(exprs->next, lnet_range_expr_t, lre_list); - - list_del(&lre->lre_list); - LIBCFS_FREE(lre, sizeof(*lre)); - lnet_re_alloc--; - } -} - -int -lnet_parse_range_expr(struct list_head *exprs, char *str) -{ - int nob = strlen(str); - char *sep; - int n; - int x; - int y; - int z; - int rc; - - if (nob == 0) - return -EINVAL; - - if (!strcmp(str, "*")) /* match all */ - return lnet_new_range_expr(exprs, 0, 255, 1); - - n = nob; - if (sscanf(str, "%u%n", &x, &n) >= 1 && n == nob) { - /* simple number */ - return lnet_new_range_expr(exprs, x, x, 1); - } - - /* Has to be an expansion */ - if (!(str[0] == '[' && nob > 2 && str[nob-1] == ']')) - return -EINVAL; - - nob -= 2; - str++; - str[nob] = 0; - - do { - /* Comma separated list of expressions... */ - sep = strchr(str, ','); - if (sep != NULL) - *sep++ = 0; - - nob = strlen(str); - n = nob; - if (sscanf(str, "%u%n", &x, &n) >= 1 && n == nob) { - /* simple number */ - rc = lnet_new_range_expr(exprs, x, x, 1); - if (rc != 0) - return rc; - - continue; - } - - n = nob; - if (sscanf(str, "%u-%u%n", &x, &y, &n) >= 2 && n == nob) { - /* simple range */ - rc = lnet_new_range_expr(exprs, x, y, 1); - if (rc != 0) - return rc; - continue; - } - - n = nob; - if (sscanf(str, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob) { - /* strided range */ - rc = lnet_new_range_expr(exprs, x, y, z); - if (rc != 0) - return rc; - continue; - } - - return -EINVAL; - - } while ((str = sep) != NULL); - - return 0; -} - -int -lnet_match_network_token(char *token, __u32 *ipaddrs, int nip) -{ - struct list_head exprs[4]; - struct list_head *e; - lnet_range_expr_t *re; - char *str; - int i; - int j; - __u32 ip; - int n; - int match; - int rc; - - for (i = 0; i < 4; i++) - CFS_INIT_LIST_HEAD(&exprs[i]); - - for (i = 0; i < 4; i++) { - str = token; - if (i != 3) { - token = strchr(token, '.'); - if (token == NULL) { - rc = -EINVAL; - goto out; - } - *token++ = 0; - } - - rc = lnet_parse_range_expr(&exprs[i], str); - if (rc != 0) { - LASSERT (rc < 0); - goto out; - } - } - - for (match = i = 0; !match && i < nip; i++) { - ip = ipaddrs[i]; - - for (match = 1, j = 0; match && j < 4; j++) { - n = (ip >> (8 * (3 - j))) & 0xff; - match = 0; - - list_for_each(e, &exprs[j]) { - re = list_entry(e, lnet_range_expr_t, lre_list); - - if (re->lre_min <= n && - re->lre_max >= n && - (n - re->lre_min) % re->lre_stride == 0) { - match = 1; - break; - } - } - } - } - - rc = match ? 1 : 0; - - out: - for (i = 0; i < 4; i++) - lnet_destroy_range_exprs(&exprs[i]); - LASSERT (lnet_re_alloc == 0); - return rc; } @@ -952,8 +852,8 @@ lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip) } len = strlen(token); - - rc = lnet_match_network_token(token, ipaddrs, nip); + + rc = lnet_match_network_token(token, len, ipaddrs, nip); if (rc < 0) { lnet_syntax("ip2nets", net_entry, (int)(token - tokens), len); @@ -970,7 +870,7 @@ lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip) return 1; } -__u32 +__u32 lnet_netspec2net(char *netspec) { char *bracket = strchr(netspec, '('); @@ -983,27 +883,27 @@ lnet_netspec2net(char *netspec) if (bracket != NULL) *bracket = '('; - + return net; } int -lnet_splitnets(char *source, struct list_head *nets) +lnet_splitnets(char *source, cfs_list_t *nets) { int offset = 0; int offset2; int len; lnet_text_buf_t *tb; lnet_text_buf_t *tb2; - struct list_head *t; + cfs_list_t *t; char *sep; char *bracket; __u32 net; - LASSERT (!list_empty(nets)); + LASSERT (!cfs_list_empty(nets)); LASSERT (nets->next == nets->prev); /* single entry */ - - tb = list_entry(nets->next, lnet_text_buf_t, ltb_list); + + tb = cfs_list_entry(nets->next, lnet_text_buf_t, ltb_list); for (;;) { sep = strchr(tb->ltb_text, ','); @@ -1038,8 +938,8 @@ lnet_splitnets(char *source, struct list_head *nets) return -EINVAL; } - list_for_each(t, nets) { - tb2 = list_entry(t, lnet_text_buf_t, ltb_list); + cfs_list_for_each(t, nets) { + tb2 = cfs_list_entry(t, lnet_text_buf_t, ltb_list); if (tb2 == tb) continue; @@ -1051,7 +951,7 @@ lnet_splitnets(char *source, struct list_head *nets) return -EINVAL; } } - + if (sep == NULL) return 0; @@ -1059,9 +959,9 @@ lnet_splitnets(char *source, struct list_head *nets) tb2 = lnet_new_text_buf(strlen(sep)); if (tb2 == NULL) return -ENOMEM; - + strcpy(tb2->ltb_text, sep); - list_add_tail(&tb2->ltb_list, nets); + cfs_list_add_tail(&tb2->ltb_list, nets); tb = tb2; } @@ -1070,14 +970,14 @@ lnet_splitnets(char *source, struct list_head *nets) 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; + static char networks[LNET_SINGLE_TEXTBUF_NOB]; + static char source[LNET_SINGLE_TEXTBUF_NOB]; + + cfs_list_t raw_entries; + cfs_list_t matched_nets; + cfs_list_t current_nets; + cfs_list_t *t; + cfs_list_t *t2; lnet_text_buf_t *tb; lnet_text_buf_t *tb2; __u32 net1; @@ -1101,8 +1001,9 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip) len = 0; rc = 0; - while (!list_empty(&raw_entries)) { - tb = list_entry(raw_entries.next, lnet_text_buf_t, ltb_list); + while (!cfs_list_empty(&raw_entries)) { + tb = cfs_list_entry(raw_entries.next, lnet_text_buf_t, + ltb_list); strncpy(source, tb->ltb_text, sizeof(source)-1); source[sizeof(source)-1] = 0; @@ -1112,7 +1013,7 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip) if (rc < 0) break; - list_del(&tb->ltb_list); + cfs_list_del(&tb->ltb_list); if (rc == 0) { /* no match */ lnet_free_text_buf(tb); @@ -1121,19 +1022,20 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip) /* split into separate networks */ CFS_INIT_LIST_HEAD(¤t_nets); - list_add(&tb->ltb_list, ¤t_nets); + cfs_list_add(&tb->ltb_list, ¤t_nets); rc = lnet_splitnets(source, ¤t_nets); if (rc < 0) break; dup = 0; - list_for_each (t, ¤t_nets) { - tb = list_entry(t, lnet_text_buf_t, ltb_list); + cfs_list_for_each (t, ¤t_nets) { + tb = cfs_list_entry(t, lnet_text_buf_t, ltb_list); net1 = lnet_netspec2net(tb->ltb_text); LASSERT (net1 != LNET_NIDNET(LNET_NID_ANY)); - list_for_each(t2, &matched_nets) { - tb2 = list_entry(t2, lnet_text_buf_t, ltb_list); + cfs_list_for_each(t2, &matched_nets) { + tb2 = cfs_list_entry(t2, lnet_text_buf_t, + ltb_list); net2 = lnet_netspec2net(tb2->ltb_text); LASSERT (net2 != LNET_NIDNET(LNET_NID_ANY)); @@ -1152,11 +1054,11 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip) continue; } - list_for_each_safe(t, t2, ¤t_nets) { - tb = list_entry(t, lnet_text_buf_t, ltb_list); + cfs_list_for_each_safe(t, t2, ¤t_nets) { + tb = cfs_list_entry(t, lnet_text_buf_t, ltb_list); - list_del(&tb->ltb_list); - list_add_tail(&tb->ltb_list, &matched_nets); + cfs_list_del(&tb->ltb_list); + cfs_list_add_tail(&tb->ltb_list, &matched_nets); len += snprintf(networks + len, sizeof(networks) - len, "%s%s", (len == 0) ? "" : ",", @@ -1180,7 +1082,7 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip) if (rc < 0) return rc; - + *networksp = networks; return count; } @@ -1207,7 +1109,7 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp) if (nif <= 0) return nif; - + LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs)); if (ipaddrs == NULL) { CERROR("Can't allocate ipaddrs[%d]\n", nif); @@ -1218,8 +1120,8 @@ lnet_ipaddr_enumerate (__u32 **ipaddrsp) for (i = nip = 0; i < nif; i++) { if (!strcmp(ifnames[i], "lo")) continue; - - rc = libcfs_ipif_query(ifnames[i], &up, + + rc = libcfs_ipif_query(ifnames[i], &up, &ipaddrs[nip], &netmask); if (rc != 0) { CWARN("Can't query interface %s: %d\n", @@ -1295,7 +1197,7 @@ lnet_parse_ip2nets (char **networksp, char *ip2nets) } int -lnet_set_ip_niaddr (lnet_ni_t *ni) +lnet_set_ip_niaddr (lnet_ni_t *ni) { __u32 net = LNET_NIDNET(ni->ni_nid); char **names; @@ -1318,7 +1220,7 @@ lnet_set_ip_niaddr (lnet_ni_t *ni) libcfs_net2str(net)); return -EPERM; } - + rc = libcfs_ipif_query(ni->ni_interfaces[0], &up, &ip, &netmask); if (rc != 0) { @@ -1332,14 +1234,14 @@ lnet_set_ip_niaddr (lnet_ni_t *ni) 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", + CERROR("Net %s can't enumerate interfaces: %d\n", libcfs_net2str(net), n); return 0; } @@ -1347,15 +1249,15 @@ lnet_set_ip_niaddr (lnet_ni_t *ni) 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]);