}
static int
+libcfs_num_addr_range_expand(struct list_head *addrranges, __u32 *addrs,
+ int max_addrs)
+{
+ struct cfs_expr_list *expr_list;
+ struct cfs_range_expr *range;
+ int i;
+ int max_idx = max_addrs - 1;
+ int addrs_idx = max_idx;
+
+ list_for_each_entry(expr_list, addrranges, el_link) {
+ list_for_each_entry(range, &expr_list->el_exprs, re_link) {
+ for (i = range->re_lo; i <= range->re_hi;
+ i += range->re_stride) {
+ if (addrs_idx < 0)
+ return -1;
+
+ addrs[addrs_idx] = i;
+ addrs_idx--;
+ }
+ }
+ }
+
+ return max_idx - addrs_idx;
+}
+
+static int
+libcfs_ip_addr_range_expand(struct list_head *addrranges, __u32 *addrs,
+ int max_addrs)
+{
+ int rc = 0;
+
+ rc = cfs_ip_addr_range_gen(addrs, max_addrs, addrranges);
+
+ if (rc == -1)
+ return rc;
+ else
+ return max_addrs - rc - 1;
+}
+
+static int
libcfs_ip_addr_range_print(char *buffer, int count, struct list_head *list)
{
int i = 0, j = 0;
.nf_parse_addrlist = libcfs_num_parse,
.nf_print_addrlist = libcfs_num_addr_range_print,
.nf_match_addr = libcfs_num_match,
- .nf_min_max = cfs_num_min_max
+ .nf_min_max = cfs_num_min_max,
+ .nf_expand_addrrange = libcfs_num_addr_range_expand
},
{
.nf_type = SOCKLND,
.nf_parse_addrlist = cfs_ip_addr_parse,
.nf_print_addrlist = libcfs_ip_addr_range_print,
.nf_match_addr = cfs_ip_addr_match,
- .nf_min_max = cfs_ip_min_max
+ .nf_min_max = cfs_ip_min_max,
+ .nf_expand_addrrange = libcfs_ip_addr_range_expand
},
{
.nf_type = O2IBLND,
.nf_parse_addrlist = cfs_ip_addr_parse,
.nf_print_addrlist = libcfs_ip_addr_range_print,
.nf_match_addr = cfs_ip_addr_match,
- .nf_min_max = cfs_ip_min_max
+ .nf_min_max = cfs_ip_min_max,
+ .nf_expand_addrrange = libcfs_ip_addr_range_expand
},
{
.nf_type = GNILND,
.nf_parse_addrlist = libcfs_num_parse,
.nf_print_addrlist = libcfs_num_addr_range_print,
.nf_match_addr = libcfs_num_match,
- .nf_min_max = cfs_num_min_max
+ .nf_min_max = cfs_num_min_max,
+ .nf_expand_addrrange = libcfs_num_addr_range_expand
},
{
.nf_type = GNIIPLND,
.nf_parse_addrlist = cfs_ip_addr_parse,
.nf_print_addrlist = libcfs_ip_addr_range_print,
.nf_match_addr = cfs_ip_addr_match,
- .nf_min_max = cfs_ip_min_max
+ .nf_min_max = cfs_ip_min_max,
+ .nf_expand_addrrange = libcfs_ip_addr_range_expand
},
{
.nf_type = PTL4LND,
.nf_parse_addrlist = libcfs_num_parse,
.nf_print_addrlist = libcfs_num_addr_range_print,
.nf_match_addr = libcfs_num_match,
- .nf_min_max = cfs_num_min_max
+ .nf_min_max = cfs_num_min_max,
+ .nf_expand_addrrange = libcfs_num_addr_range_expand
}
};
return 0;
}
+
+static int
+libcfs_expand_nidrange(struct nidrange *nr, __u32 *addrs, int max_nids)
+{
+ struct addrrange *ar;
+ int rc = 0, count = max_nids;
+ struct netstrfns *nf = nr->nr_netstrfns;
+
+ list_for_each_entry(ar, &nr->nr_addrranges, ar_link) {
+ rc = nf->nf_expand_addrrange(&ar->ar_numaddr_ranges, addrs,
+ count);
+ if (rc < 0)
+ return rc;
+
+ count -= rc;
+ }
+
+ return max_nids - count;
+}
+
+int cfs_expand_nidlist(struct list_head *nidlist, lnet_nid_t *lnet_nidlist,
+ int max_nids)
+{
+ struct nidrange *nr;
+ int rc = 0, count = max_nids;
+ int i, j = 0;
+ __u32 *addrs;
+ struct netstrfns *nf;
+ __u32 net;
+
+ addrs = calloc(max_nids, sizeof(__u32));
+ if (!addrs)
+ return -ENOMEM;
+
+ list_for_each_entry(nr, nidlist, nr_link) {
+ rc = libcfs_expand_nidrange(nr, addrs, count);
+
+ if (rc < 0) {
+ free(addrs);
+ return rc;
+ }
+
+ nf = nr->nr_netstrfns;
+ net = LNET_MKNET(nf->nf_type, nr->nr_netnum);
+
+ for (i = count - 1; i >= count - rc; i--)
+ lnet_nidlist[j++] = LNET_MKNID(net, addrs[i]);
+
+ count -= rc;
+ }
+
+ free(addrs);
+ return max_nids - count;
+}
int cfs_parse_nidlist(char *str, int len, struct list_head *list);
int cfs_print_nidlist(char *buffer, int count, struct list_head *list);
int cfs_match_nid(lnet_nid_t nid, struct list_head *list);
-
+int cfs_expand_nidlist(struct list_head *nidlist, lnet_nid_t *lnet_nidlist,
+ int max_nids);
int cfs_ip_addr_parse(char *str, int len, struct list_head *list);
int cfs_ip_addr_match(__u32 addr, struct list_head *list);
int cfs_nidrange_find_min_max(struct list_head *nidlist, char *min_nid,
int (*nf_match_addr)(__u32 addr, struct list_head *list);
int (*nf_min_max)(struct list_head *nidlist, __u32 *min_nid,
__u32 *max_nid);
+ int (*nf_expand_addrrange)(struct list_head *addrranges,
+ __u32 *addrs, int max_addrs);
};
#endif /* _LNET_NIDSTRINGS_H */