*/
/*
* This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
*
* libcfs/libcfs/util/nidstrings.c
*
return rc;
}
+int
+cfs_expr2str(struct list_head *list, char *str, size_t size)
+{
+ struct cfs_expr_list *expr;
+ struct cfs_range_expr *range;
+ char tmp[LNET_NIDSTR_SIZE];
+ size_t len;
+ bool first;
+ bool bracket = false;
+ char *format;
+ char *tmpc;
+
+ list_for_each_entry(expr, list, el_link) {
+ first = true;
+ list_for_each_entry(range, &expr->el_exprs, re_link) {
+ if (range->re_lo == range->re_hi) {
+ snprintf(tmp,
+ LNET_NIDSTR_SIZE,
+ "%u.", range->re_lo);
+ } else if (range->re_lo < range->re_hi) {
+ if (range->re_stride > 1) {
+ if (first)
+ format = "[%u-%u/%u,";
+ else
+ format = "%u-%u/%u,";
+ snprintf(tmp, LNET_NIDSTR_SIZE,
+ format, range->re_lo,
+ range->re_hi, range->re_stride);
+ bracket = true;
+ } else {
+ if (first)
+ format = "[%u-%u,";
+ else
+ format = "%u-%u,";
+ snprintf(tmp, LNET_NIDSTR_SIZE,
+ format, range->re_lo,
+ range->re_hi);
+ bracket = true;
+ }
+ } else {
+ return -EINVAL;
+ }
+ len = strlen(tmp);
+ size -= (len + 1);
+ if (size < 0)
+ return -ENOBUFS;
+
+ strncat(str, tmp, size + len);
+ first = false;
+ }
+ if (bracket) {
+ tmpc = str + (strlen(str) - 1);
+ size -= 1;
+ if (size < 0)
+ return -ENOBUFS;
+ *tmpc = ']';
+ *(tmpc+1) = '.';
+ bracket = false;
+ }
+ }
+
+ /*
+ * get rid of the trailing '.' at the end of the string
+ * only if we actually had something on the list passed in.
+ * otherwise we could write outside the array
+ */
+ if (!list_empty(list))
+ str[strlen(str)-1] = '\0';
+ return size;
+}
+
static int
libcfs_num_addr_range_expand(struct list_head *addrranges, __u32 *addrs,
int max_addrs)
.nf_match_addr = libcfs_num_match,
.nf_min_max = cfs_num_min_max,
.nf_expand_addrrange = libcfs_num_addr_range_expand
+ },
+ {
+ .nf_type = KFILND,
+ .nf_name = "kfi",
+ .nf_modname = "kkfilnd",
+ .nf_addr2str = libcfs_decnum_addr2str,
+ .nf_str2addr = libcfs_num_str2addr,
+ .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_expand_addrrange = libcfs_num_addr_range_expand
}
};
return 0;
}
-static struct netstrfns *
-type2net_info(__u32 net_type)
-{
- int i;
-
- for (i = 0; i < libcfs_nnetstrfns; i++) {
- if (libcfs_netstrfns[i].nf_type == net_type)
- return &libcfs_netstrfns[i];
- }
-
- return NULL;
-}
-
int
cfs_match_net(__u32 net_id, __u32 net_type, struct list_head *net_num_list)
{
return 1;
}
-int
-cfs_match_nid_net(lnet_nid_t nid, __u32 net_type,
- struct list_head *net_num_list,
- struct list_head *addr)
-{
- __u32 address;
- struct netstrfns *fns;
-
- if (!addr || !net_num_list)
- return 0;
-
- fns = type2net_info(LNET_NETTYP(LNET_NIDNET(nid)));
- if (!fns || !net_num_list || !addr)
- return 0;
-
- address = LNET_NIDADDR(nid);
-
- /* if either the address or net number don't match then no match */
- if (!fns->nf_match_addr(address, addr) ||
- !cfs_match_net(LNET_NIDNET(nid), net_type, net_num_list))
- return 0;
-
- return 1;
-}
/**
* Print the network part of the nidrange \a nr into the specified \a buffer.
*
struct netstrfns *nf = nr->nr_netstrfns;
if (nr->nr_netnum == 0)
- return snprintf(buffer, count, "@%s", nf->nf_name);
+ return scnprintf(buffer, count, "@%s", nf->nf_name);
else
- return snprintf(buffer, count, "@%s%u",
- nf->nf_name, nr->nr_netnum);
+ return scnprintf(buffer, count, "@%s%u",
+ nf->nf_name, nr->nr_netnum);
}