Whamcloud - gitweb
LU-16035 kfilnd: Initial kfilnd implementation
[fs/lustre-release.git] / lnet / utils / lnetconfig / liblnetconfig.c
index c5ac18a..ad11da2 100644 (file)
@@ -59,6 +59,7 @@
 #define RDMA_PS_TCP 0x0106
 #endif
 
+#define cxi_nic_addr_path "/sys/class/cxi/cxi%u/device/properties/"
 const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
                                 "dropped_stats"};
 
@@ -1151,6 +1152,40 @@ static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
        return LUSTRE_CFG_RC_NO_ERR;
 }
 
+static int lustre_lnet_kfi_intf2nid(struct lnet_dlc_intf_descr *intf,
+                                   __u32 *nid_addr)
+{
+       unsigned int nic_index;
+       int rc;
+       char *nic_addr_path;
+       char val[128];
+       int size;
+       long int addr;
+
+       rc = sscanf(intf->intf_name, "cxi%u", &nic_index);
+       if (rc != 1)
+               return LUSTRE_CFG_RC_NO_MATCH;
+
+       size = snprintf(NULL, 0, cxi_nic_addr_path, nic_index) + 1;
+       nic_addr_path = malloc(size);
+       if (!nic_addr_path)
+               return LUSTRE_CFG_RC_OUT_OF_MEM;
+       sprintf(nic_addr_path, cxi_nic_addr_path, nic_index);
+
+       rc = read_sysfs_file(nic_addr_path, "nic_addr", val, 1, sizeof(val));
+       free(nic_addr_path);
+       if (rc)
+               return LUSTRE_CFG_RC_NO_MATCH;
+
+       addr = strtol(val, NULL, 16);
+       if (addr == LONG_MIN || addr == LONG_MAX)
+               return LUSTRE_CFG_RC_NO_MATCH;
+
+       *nid_addr = addr;
+
+       return LUSTRE_CFG_RC_NO_ERR;
+}
+
 /*
  * for each interface in the array of interfaces find the IP address of
  * that interface, create its nid and add it to an array of NIDs.
@@ -1164,6 +1199,7 @@ static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
        struct lnet_dlc_intf_descr *intf;
        char val[LNET_MAX_STR_LEN];
        __u32 ip;
+       __u32 nic_addr;
        int gni_num;
        char *endp;
        unsigned int num;
@@ -1206,6 +1242,21 @@ static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
                (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
 
                goto out;
+       } else if (LNET_NETTYP(nw->nw_id) == KFILND) {
+               list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
+                       rc = lustre_lnet_kfi_intf2nid(intf, &nic_addr);
+                       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+                               snprintf(err_str, str_len,
+                                       "\"couldn't query kfi intf %s\"",
+                                       intf->intf_name);
+                               err_str[str_len - 1] = '\0';
+                               goto failed;
+                       }
+
+                       (*nids)[i] = LNET_MKNID(nw->nw_id, nic_addr);
+                       i++;
+               }
+               goto out;
        }
 
        /* look at the other interfaces */