Whamcloud - gitweb
land b1_4_bgl on HEAD (20050404_1913)
[fs/lustre-release.git] / lnet / utils / portals.c
index 07fada2..e3f5916 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <fcntl.h>
-#include "ioctl.h"
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#else
+#include "ioctl.h"
+#endif
 #include <errno.h>
 #include <unistd.h>
 #include <time.h>
 #include <stdarg.h>
+#ifdef HAVE_ENDIAN_H
 #include <endian.h>
+#endif
+#if CRAY_PORTALS
+#ifdef REDSTORM
+#define __QK__
+#endif
+#include <portals/ipmap.h>
+#endif
 
-#ifdef __CYGWIN__
-
-#include <netinet/in.h>
-
-#endif /* __CYGWIN__ */
+#include <libcfs/portals_utils.h>
 #include <portals/api-support.h>
 #include <portals/ptlctl.h>
-#include <portals/list.h>
 #include <portals/lib-types.h>
 #include <portals/socknal.h>
 #include "parser.h"
@@ -66,12 +71,20 @@ typedef struct
 
 static name2num_t nalnames[] = {
         {"any",         0},
+#if !CRAY_PORTALS
         {"tcp",                SOCKNAL},
         {"elan",       QSWNAL},
         {"gm",         GMNAL},
         {"openib",      OPENIBNAL},
         {"iib",         IIBNAL},
+        {"vib",         VIBNAL},
         {"lo",          LONAL},
+        {"ra",          RANAL},
+#else
+        {"cray_kern_nal", CRAY_KERN_NAL},
+        {"cray_user_nal", CRAY_USER_NAL},
+        {"cray_qk_nal",   CRAY_QK_NAL},
+#endif
         {NULL,         -1}
 };
 
@@ -166,6 +179,9 @@ pcfg_ioctl(struct portals_cfg *pcfg)
                 data.ioc_nid = pcfg->pcfg_nid;
 
                 rc = l_ioctl (PORTALS_DEV_ID, IOC_PORTAL_NAL_CMD, &data);
+
+                if (rc == 0 && pcfg->pcfg_version != PORTALS_CFG_VERSION)
+                        return -EINVAL;
         }
 
         return (rc);
@@ -224,8 +240,8 @@ ptl_gethostbyname(char * hname) {
                                 hname);
                         break;
                 default:
-                        fprintf(stderr, "gethostbyname error: %s\n",
-                                strerror(errno));
+                        fprintf(stderr, "gethostbyname error for %s: %s\n",
+                                hname, strerror(h_errno));
                         break;
                 }
                 return NULL;
@@ -303,8 +319,7 @@ ptl_parse_ipaddr (__u32 *ipaddrp, char *str)
         struct hostent *he;
 #endif
 
-        if (!strcmp (str, "_all_")) 
-        {
+        if (!strcmp (str, "_all_")) {
                 *ipaddrp = 0;
                 return (0);
         }
@@ -312,11 +327,10 @@ ptl_parse_ipaddr (__u32 *ipaddrp, char *str)
         if (ptl_parse_ipquad(ipaddrp, str) == 0)
                 return (0);
 
-#if HAVE_GETHOSTBYNAME        
+#ifdef HAVE_GETHOSTBYNAME
         if ((('a' <= str[0] && str[0] <= 'z') ||
              ('A' <= str[0] && str[0] <= 'Z')) &&
-             (he = ptl_gethostbyname (str)) != NULL)
-        {
+             (he = ptl_gethostbyname (str)) != NULL) {
                 __u32 addr = *(__u32 *)he->h_addr;
 
                 *ipaddrp = ntohl(addr);         /* HOST byte order */
@@ -357,19 +371,18 @@ ptl_parse_nid (ptl_nid_t *nidp, char *str)
         char               *end;
         unsigned long long  ullval;
         
-        if (!strcmp (str, "_all_")) {
-                *nidp = PTL_NID_ANY;
-                return (0);
-        }
-
         if (ptl_parse_ipaddr (&ipaddr, str) == 0) {
+#if !CRAY_PORTALS
                 *nidp = (ptl_nid_t)ipaddr;
+#else
+                *nidp = (((ptl_nid_t)ipaddr & PNAL_HOSTID_MASK) << PNAL_VNODE_SHIFT);
+#endif
                 return (0);
         }
 
         ullval = strtoull(str, &end, 0);
-        if (*end == 0) {
-                /* parsed whole string */
+        if (end != str && *end == 0) {
+                /* parsed whole non-empty string */
                 *nidp = (ptl_nid_t)ullval;
                 return (0);
         }
@@ -377,6 +390,17 @@ ptl_parse_nid (ptl_nid_t *nidp, char *str)
         return (-1);
 }
 
+int
+ptl_parse_anynid (ptl_nid_t *nidp, char *str)
+{
+        if (!strcmp (str, "_all_")) {
+                *nidp = PTL_NID_ANY;
+                return 0;
+        }
+
+        return ptl_parse_nid(nidp, str);
+}
+
 __u64 ptl_nid2u64(ptl_nid_t nid)
 {
         switch (sizeof (nid)) {
@@ -405,7 +429,7 @@ ptl_nid2str (char *buffer, ptl_nid_t nid)
         if (nid & 0xff000000) {
                 __u32 addr = htonl((__u32)nid); /* back to NETWORK byte order */
 
-                he = gethostbyaddr ((const char *)&addr, sizeof (addr), AF_INET);
+                he = gethostbyaddr((const char *)&addr, sizeof(addr), AF_INET);
         }
 
         if (he != NULL)
@@ -562,8 +586,16 @@ jt_ptl_print_interfaces (int argc, char **argv)
                         pcfg.pcfg_fd, pcfg.pcfg_count);
         }
 
-        if (index == 0)
-                printf ("<no interfaces>\n");
+        if (index == 0) {
+                if (errno == ENOENT) {
+                        printf ("<no interfaces>\n");
+                } else {
+                        fprintf(stderr, "Error getting interfaces: %s: "
+                                "check dmesg.\n",
+                                strerror(errno));
+                }
+        }
+
         return 0;
 }
 
@@ -659,7 +691,8 @@ jt_ptl_print_peers (int argc, char **argv)
         int                      index;
         int                      rc;
 
-        if (!g_nal_is_compatible (argv[0], SOCKNAL, OPENIBNAL, IIBNAL, 0))
+        if (!g_nal_is_compatible (argv[0], SOCKNAL, RANAL, 
+                                  OPENIBNAL, IIBNAL, VIBNAL, 0))
                 return -1;
 
         for (index = 0;;index++) {
@@ -676,13 +709,25 @@ jt_ptl_print_peers (int argc, char **argv)
                                 ptl_ipaddr_2_str (pcfg.pcfg_size, buffer[0], 1),
                                 ptl_ipaddr_2_str (pcfg.pcfg_id, buffer[1], 1),
                                 pcfg.pcfg_misc, pcfg.pcfg_count);
+                else if (g_nal_is_compatible(NULL, RANAL, OPENIBNAL, VIBNAL, 0))
+                        printf (LPX64"[%d]@%s:%d\n",
+                                pcfg.pcfg_nid, pcfg.pcfg_wait,
+                                ptl_ipaddr_2_str (pcfg.pcfg_id, buffer[1], 1),
+                                pcfg.pcfg_misc);
                 else
                         printf (LPX64"[%d]\n",
                                 pcfg.pcfg_nid, pcfg.pcfg_wait);
         }
 
-        if (index == 0)
-                printf ("<no peers>\n");
+        if (index == 0) {
+                if (errno == ENOENT) {
+                        printf ("<no peers>\n");
+                } else {
+                        fprintf(stderr, "Error getting peer list: %s: "
+                                "check dmesg.\n",
+                                strerror(errno));
+                }
+        }
         return 0;
 }
 
@@ -695,17 +740,24 @@ jt_ptl_add_peer (int argc, char **argv)
         int                      port = 0;
         int                      rc;
 
-        if (!g_nal_is_compatible (argv[0], SOCKNAL, OPENIBNAL, IIBNAL, 0))
+        if (!g_nal_is_compatible (argv[0], SOCKNAL, RANAL, 
+                                  OPENIBNAL, IIBNAL, VIBNAL, 0))
                 return -1;
 
-        if (g_nal_is_compatible(NULL, SOCKNAL, 0)) {
+        if (g_nal_is_compatible(NULL, SOCKNAL, OPENIBNAL, RANAL, 0)) {
                 if (argc != 4) {
-                        fprintf (stderr, "usage(tcp): %s nid ipaddr port\n", 
+                        fprintf (stderr, "usage(tcp,openib,ra): %s nid ipaddr port\n", 
+                                 argv[0]);
+                        return 0;
+                }
+        } else if (g_nal_is_compatible(NULL, VIBNAL, 0)) {
+                if (argc != 3) {
+                        fprintf (stderr, "usage(vib): %s nid ipaddr\n", 
                                  argv[0]);
                         return 0;
                 }
         } else if (argc != 2) {
-                fprintf (stderr, "usage(openib,iib): %s nid\n", argv[0]);
+                fprintf (stderr, "usage(iib): %s nid\n", argv[0]);
                 return 0;
         }
 
@@ -715,16 +767,16 @@ jt_ptl_add_peer (int argc, char **argv)
                 return -1;
         }
 
-        if (g_nal_is_compatible (NULL, SOCKNAL, 0)) {
-                if (ptl_parse_ipaddr (&ip, argv[2]) != 0) {
-                        fprintf (stderr, "Can't parse ip addr: %s\n", argv[2]);
-                        return -1;
-                }
+        if (g_nal_is_compatible (NULL, SOCKNAL, OPENIBNAL, VIBNAL, RANAL, 0) &&
+            ptl_parse_ipaddr (&ip, argv[2]) != 0) {
+                fprintf (stderr, "Can't parse ip addr: %s\n", argv[2]);
+                return -1;
+        }
 
-                if (ptl_parse_port (&port, argv[3]) != 0) {
-                        fprintf (stderr, "Can't parse port: %s\n", argv[3]);
-                        return -1;
-                }
+        if (g_nal_is_compatible (NULL, SOCKNAL, OPENIBNAL, RANAL, 0) &&
+            ptl_parse_port (&port, argv[3]) != 0) {
+                fprintf (stderr, "Can't parse port: %s\n", argv[3]);
+                return -1;
         }
 
         PCFG_INIT(pcfg, NAL_CMD_ADD_PEER);
@@ -752,7 +804,8 @@ jt_ptl_del_peer (int argc, char **argv)
         int                      argidx;
         int                      rc;
 
-        if (!g_nal_is_compatible (argv[0], SOCKNAL, OPENIBNAL, IIBNAL, 0))
+        if (!g_nal_is_compatible (argv[0], SOCKNAL, RANAL, 
+                                  OPENIBNAL, IIBNAL, VIBNAL, 0))
                 return -1;
 
         if (g_nal_is_compatible(NULL, SOCKNAL, 0)) {
@@ -767,7 +820,7 @@ jt_ptl_del_peer (int argc, char **argv)
         }
                 
         if (argc > 1 &&
-            ptl_parse_nid (&nid, argv[1]) != 0) {
+            ptl_parse_anynid (&nid, argv[1]) != 0) {
                 fprintf (stderr, "Can't parse nid: %s\n", argv[1]);
                 return -1;
         }
@@ -815,10 +868,11 @@ jt_ptl_print_connections (int argc, char **argv)
         int                      index;
         int                      rc;
 
-        if (!g_nal_is_compatible (argv[0], SOCKNAL, OPENIBNAL, IIBNAL, 0))
+        if (!g_nal_is_compatible (argv[0], SOCKNAL, RANAL, 
+                                  OPENIBNAL, IIBNAL, VIBNAL, 0))
                 return -1;
 
-        for (index = 0;;index++) {
+        for (index = 0; ; index++) {
                 PCFG_INIT (pcfg,  NAL_CMD_GET_CONN);
                 pcfg.pcfg_count   = index;
                 
@@ -840,13 +894,24 @@ jt_ptl_print_connections (int argc, char **argv)
                                 pcfg.pcfg_count,        /* tx buffer size */
                                 pcfg.pcfg_size,         /* rx buffer size */
                                 pcfg.pcfg_wait ? "nagle" : "nonagle");
+                else if (g_nal_is_compatible (NULL, RANAL, 0))
+                        printf ("[%d]"LPX64"\n",
+                                pcfg.pcfg_id,       /* device id */
+                                pcfg.pcfg_nid);
                 else
                         printf (LPX64"\n",
                                 pcfg.pcfg_nid);
         }
 
-        if (index == 0)
-                printf ("<no connections>\n");
+        if (index == 0) {
+                if (errno == ENOENT) {
+                        printf ("<no connections>\n");
+                } else {
+                        fprintf(stderr, "Error getting connection list: %s: "
+                                "check dmesg.\n",
+                                strerror(errno));
+                }
+        }
         return 0;
 }
 
@@ -1006,11 +1071,12 @@ int jt_ptl_disconnect(int argc, char **argv)
                 return 0;
         }
 
-        if (!g_nal_is_compatible (NULL, SOCKNAL, OPENIBNAL, IIBNAL, 0))
+        if (!g_nal_is_compatible (NULL, SOCKNAL, RANAL, 
+                                  OPENIBNAL, IIBNAL, VIBNAL, 0))
                 return 0;
 
         if (argc >= 2 &&
-            ptl_parse_nid (&nid, argv[1]) != 0) {
+            ptl_parse_anynid (&nid, argv[1]) != 0) {
                 fprintf (stderr, "Can't parse nid %s\n", argv[1]);
                 return -1;
         }
@@ -1052,7 +1118,7 @@ int jt_ptl_push_connection (int argc, char **argv)
                 return -1;
         
         if (argc > 1 &&
-            ptl_parse_nid (&nid, argv[1]) != 0) {
+            ptl_parse_anynid (&nid, argv[1]) != 0) {
                 fprintf(stderr, "Can't parse nid: %s\n", argv[1]);
                 return -1;
         }
@@ -1094,12 +1160,11 @@ jt_ptl_print_active_txs (int argc, char **argv)
                 if (rc != 0)
                         break;
 
-                printf ("%p: %5s payload %6d bytes to "LPX64" via "LPX64" by pid %6d: %s, %s, state %d\n",
-                        pcfg.pcfg_pbuf1,
+                printf ("%5s payload %6d bytes to "LPX64" via "LPX64" by pid %6d: %s, %s, state %d\n",
                         pcfg.pcfg_count == PTL_MSG_ACK ? "ACK" :
                         pcfg.pcfg_count == PTL_MSG_PUT ? "PUT" :
                         pcfg.pcfg_count == PTL_MSG_GET ? "GET" :
-                        pcfg.pcfg_count == PTL_MSG_REPLY ? "REPLY" : "<wierd message>",
+                        pcfg.pcfg_count == PTL_MSG_REPLY ? "REPLY" : "<weird message>",
                         pcfg.pcfg_size,
                         pcfg.pcfg_nid,
                         pcfg.pcfg_nid2,
@@ -1109,8 +1174,15 @@ jt_ptl_print_active_txs (int argc, char **argv)
                         pcfg.pcfg_flags >> 2);
         }
 
-        if (index == 0)
-                printf ("<no active descs>\n");
+        if (index == 0) {
+                if (errno == ENOENT) {
+                        printf ("<no active descs>\n");
+                } else {
+                        fprintf(stderr, "Error getting active transmits list: "
+                                "%s: check dmesg.\n",
+                                strerror(errno));
+                }
+        }
         return 0;
 }
 
@@ -1259,7 +1331,7 @@ jt_ptl_fail_nid (int argc, char **argv)
 
         if (!strcmp (argv[1], "_all_"))
                 nid = PTL_NID_ANY;
-        else if (ptl_parse_nid (&nid, argv[1]) != 0)
+        else if (ptl_parse_anynid (&nid, argv[1]) != 0)
         {
                 fprintf (stderr, "Can't parse nid \"%s\"\n", argv[1]);
                 return (-1);
@@ -1288,6 +1360,44 @@ jt_ptl_fail_nid (int argc, char **argv)
 }
 
 int
+jt_ptl_loopback (int argc, char **argv)
+{
+        int                      rc;
+        int                      set;
+        int                      enable;
+        struct portal_ioctl_data data;
+
+        if (argc > 2)
+        {
+                fprintf (stderr, "usage: %s [on|off]\n", argv[0]);
+                return (0);
+        }
+        
+        if (!g_nal_is_set())
+                return (-1);
+
+        set = argc > 1;
+        if (set && ptl_parse_bool (&enable, argv[1]) != 0) {
+                fprintf (stderr, "Can't parse boolean %s\n", argv[1]);
+                return (-1);
+        }
+
+        PORTAL_IOC_INIT (data);
+        data.ioc_nal = g_nal;
+        data.ioc_flags = enable;
+        data.ioc_misc = set;
+        
+        rc = l_ioctl (PORTALS_DEV_ID, IOC_PORTAL_LOOPBACK, &data);
+        if (rc < 0)
+                fprintf (stderr, "IOC_PORTAL_FAIL_NID failed: %s\n",
+                         strerror (errno));
+        else
+                printf ("loopback %s\n", data.ioc_flags ? "enabled" : "disabled");
+        
+        return (0);
+}
+
+int
 jt_ptl_add_route (int argc, char **argv)
 {
         struct portals_cfg       pcfg;
@@ -1505,6 +1615,11 @@ jt_ptl_print_routes (int argc, char **argv)
                         ptl_nid2str (buffer[2], nid2),
                         alive ? "up" : "down");
         }
+
+        if (index == 0 && errno != ENOENT) {
+                fprintf(stderr, "Error getting routes: %s: check dmesg.\n",
+                        strerror(errno));
+        }
         return (0);
 }