Whamcloud - gitweb
LU-6142 lnet: use list_first_entry() in lnet/lnet subdirectory.
[fs/lustre-release.git] / lnet / lnet / nidstrings.c
index c3df95d..2af9d8a 100644 (file)
@@ -277,11 +277,11 @@ failed:
 static void
 free_addrranges(struct list_head *list)
 {
-       while (!list_empty(list)) {
-               struct addrrange *ar;
-
-               ar = list_entry(list->next, struct addrrange, ar_link);
+       struct addrrange *ar;
 
+       while ((ar = list_first_entry_or_null(list,
+                                             struct addrrange,
+                                             ar_link)) != NULL) {
                cfs_expr_list_free_list(&ar->ar_numaddr_ranges);
                list_del(&ar->ar_link);
                CFS_FREE_PTR(ar);
@@ -702,7 +702,7 @@ libcfs_num_match(__u32 addr, struct list_head *numaddr)
        struct cfs_expr_list *el;
 
        LASSERT(!list_empty(numaddr));
-       el = list_entry(numaddr->next, struct cfs_expr_list, el_link);
+       el = list_first_entry(numaddr, struct cfs_expr_list, el_link);
 
        return cfs_expr_list_match(addr, el);
 }
@@ -809,9 +809,9 @@ cfs_match_net(__u32 net_id, __u32 net_type, struct list_head *net_num_list)
 }
 
 int
-cfs_match_nid_net(lnet_nid_t nid, __u32 net_type,
-                 struct list_head *net_num_list,
-                 struct list_head *addr)
+cfs_match_nid_net(struct lnet_nid *nid, __u32 net_type,
+                  struct list_head *net_num_list,
+                  struct list_head *addr)
 {
        __u32 address;
        struct netstrfns *nf;
@@ -819,15 +819,16 @@ cfs_match_nid_net(lnet_nid_t nid, __u32 net_type,
        if (!addr || !net_num_list)
                return 0;
 
-       nf = type2net_info(LNET_NETTYP(LNET_NIDNET(nid)));
+       nf = type2net_info(LNET_NETTYP(LNET_NID_NET(nid)));
        if (!nf || !net_num_list || !addr)
                return 0;
 
-       address = LNET_NIDADDR(nid);
+       /* FIXME handle long-addr nid */
+       address = LNET_NIDADDR(lnet_nid_to_nid4(nid));
 
        /* if either the address or net number don't match then no match */
        if (!nf->nf_match_addr(address, addr) ||
-           !cfs_match_net(LNET_NIDNET(nid), net_type, net_num_list))
+           !cfs_match_net(LNET_NID_NET(nid), net_type, net_num_list))
                return 0;
 
        return 1;
@@ -972,8 +973,8 @@ EXPORT_SYMBOL(libcfs_nid2str_r);
 char *
 libcfs_nidstr_r(const struct lnet_nid *nid, char *buf, size_t buf_size)
 {
-       __u32 nnum = be16_to_cpu(nid->nid_num);
-       __u32 lnd  = nid->nid_type;
+       __u32 nnum;
+       __u32 lnd;
        struct netstrfns *nf;
 
        if (LNET_NID_IS_ANY(nid)) {
@@ -982,6 +983,8 @@ libcfs_nidstr_r(const struct lnet_nid *nid, char *buf, size_t buf_size)
                return buf;
        }
 
+       nnum = be16_to_cpu(nid->nid_num);
+       lnd = nid->nid_type;
        nf = libcfs_lnd2netstrfns(lnd);
        if (nf) {
                size_t addr_len;
@@ -1145,6 +1148,24 @@ libcfs_id2str(struct lnet_process_id id)
 }
 EXPORT_SYMBOL(libcfs_id2str);
 
+char *
+libcfs_idstr(struct lnet_processid *id)
+{
+       char *str = libcfs_next_nidstring();
+
+       if (id->pid == LNET_PID_ANY) {
+               snprintf(str, LNET_NIDSTR_SIZE,
+                        "LNET_PID_ANY-%s", libcfs_nidstr(&id->nid));
+               return str;
+       }
+
+       snprintf(str, LNET_NIDSTR_SIZE, "%s%u-%s",
+                ((id->pid & LNET_PID_USERFLAG) != 0) ? "U" : "",
+                (id->pid & ~LNET_PID_USERFLAG), libcfs_nidstr(&id->nid));
+       return str;
+}
+EXPORT_SYMBOL(libcfs_idstr);
+
 int
 libcfs_str2anynid(lnet_nid_t *nidp, const char *str)
 {