Whamcloud - gitweb
land b1_4_bgl on HEAD (20050404_1913)
[fs/lustre-release.git] / lnet / utils / portals.c
index 1bde59f..e3f5916 100644 (file)
 
 #include <stdio.h>
 #include <sys/types.h>
+#ifdef HAVE_NETDB_H
 #include <netdb.h>
+#endif
 #include <sys/socket.h>
+#ifdef HAVE_NETINET_TCP_H
 #include <netinet/tcp.h>
-#include <netdb.h>
+#endif
 #include <stdlib.h>
 #include <string.h>
 #include <fcntl.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>
-
-#ifdef __CYGWIN__
-
-#include <netinet/in.h>
-
-#endif /* __CYGWIN__ */
+#endif
+#if CRAY_PORTALS
+#ifdef REDSTORM
+#define __QK__
+#endif
+#include <portals/ipmap.h>
+#endif
+
+#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"
@@ -54,10 +63,6 @@ unsigned int portal_printk;
 
 static unsigned int g_nal = 0;
 
-static int g_socket_txmem = 0;
-static int g_socket_rxmem = 0;
-static int g_socket_nonagle = 1;
-
 typedef struct
 {
         char *name;
@@ -66,10 +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}
 };
 
@@ -164,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);
@@ -209,6 +227,7 @@ nal2name (int nal)
         return ((e == NULL) ? "???" : e->name);
 }
 
+#ifdef HAVE_GETHOSTBYNAME
 static struct hostent *
 ptl_gethostbyname(char * hname) {
         struct hostent *he;
@@ -221,14 +240,15 @@ 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;
         }
         return he;
 }
+#endif
 
 int
 ptl_parse_port (int *port, char *str)
@@ -295,26 +315,28 @@ ptl_parse_ipquad (__u32 *ipaddrp, char *str)
 int
 ptl_parse_ipaddr (__u32 *ipaddrp, char *str)
 {
+#ifdef HAVE_GETHOSTBYNAME
         struct hostent *he;
+#endif
 
-        if (!strcmp (str, "_all_")) 
-        {
+        if (!strcmp (str, "_all_")) {
                 *ipaddrp = 0;
                 return (0);
         }
 
         if (ptl_parse_ipquad(ipaddrp, str) == 0)
                 return (0);
-        
+
+#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 */
                 return (0);
         }
+#endif
 
         return (-1);
 }
@@ -322,6 +344,7 @@ ptl_parse_ipaddr (__u32 *ipaddrp, char *str)
 char *
 ptl_ipaddr_2_str (__u32 ipaddr, char *str, int lookup)
 {
+#ifdef HAVE_GETHOSTBYNAME
         __u32           net_ip;
         struct hostent *he;
 
@@ -333,7 +356,8 @@ ptl_ipaddr_2_str (__u32 ipaddr, char *str, int lookup)
                         return (str);
                 }
         }
-        
+#endif
+
         sprintf (str, "%d.%d.%d.%d",
                  (ipaddr >> 24) & 0xff, (ipaddr >> 16) & 0xff,
                  (ipaddr >> 8) & 0xff, ipaddr & 0xff);
@@ -347,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);
         }
@@ -367,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)) {
@@ -386,6 +420,7 @@ char *
 ptl_nid2str (char *buffer, ptl_nid_t nid)
 {
         __u64           nid64 = ptl_nid2u64(nid);
+#ifdef HAVE_GETHOSTBYNAME
         struct hostent *he = 0;
 
         /* Don't try to resolve NIDs that are e.g. Elan host IDs.  Assume
@@ -394,12 +429,13 @@ 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)
                 sprintf(buffer, "%#x:%s", (int)(nid64 >> 32), he->h_name);
         else
+#endif /* HAVE_GETHOSTBYNAME */
                 sprintf(buffer, LPX64, nid64);
 
         return (buffer);
@@ -524,7 +560,6 @@ int jt_ptl_network(int argc, char **argv)
         return (-1);
 }
 
-
 int
 jt_ptl_print_interfaces (int argc, char **argv)
 {
@@ -551,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;
 }
 
@@ -563,6 +606,9 @@ jt_ptl_add_interface (int argc, char **argv)
         __u32                    ipaddr;
         int                      rc;
         __u32                    netmask = 0xffffff00;
+        int                      i;
+        int                      count;
+        char                    *end;
 
         if (argc < 2 || argc > 3) {
                 fprintf (stderr, "usage: %s ipaddr [netmask]\n", argv[0]);
@@ -576,13 +622,19 @@ jt_ptl_add_interface (int argc, char **argv)
                 fprintf (stderr, "Can't parse ip: %s\n", argv[1]);
                 return -1;
         }
-        
-        if (argc > 2 &&
-            ptl_parse_ipquad(&netmask, argv[2]) != 0) {
-                fprintf (stderr, "Can't parse netmask: %s\n", argv[2]);
-                return -1;
+
+        if (argc > 2 ) {
+                count = strtol(argv[2], &end, 0);
+                if (count > 0 && count < 32 && *end == 0) {
+                        netmask = 0;
+                        for (i = count; i > 0; i--)
+                                netmask = netmask|(1<<(32-i));
+                } else if (ptl_parse_ipquad(&netmask, argv[2]) != 0) {
+                        fprintf (stderr, "Can't parse netmask: %s\n", argv[2]);
+                        return -1;
+                }
         }
-        
+
         PCFG_INIT(pcfg, NAL_CMD_ADD_INTERFACE);
         pcfg.pcfg_id     = ipaddr;
         pcfg.pcfg_misc   = netmask;
@@ -593,7 +645,7 @@ jt_ptl_add_interface (int argc, char **argv)
                          strerror (errno));
                 return -1;
         }
-        
+
         return 0;
 }
 
@@ -627,11 +679,11 @@ jt_ptl_del_interface (int argc, char **argv)
                          strerror (errno));
                 return -1;
         }
-        
+
         return 0;
 }
 
-int 
+int
 jt_ptl_print_peers (int argc, char **argv)
 {
         struct portals_cfg       pcfg;
@@ -639,7 +691,8 @@ jt_ptl_print_peers (int argc, char **argv)
         int                      index;
         int                      rc;
 
-        if (!g_nal_is_compatible (argv[0], SOCKNAL, OPENIBNAL, 0))
+        if (!g_nal_is_compatible (argv[0], SOCKNAL, RANAL, 
+                                  OPENIBNAL, IIBNAL, VIBNAL, 0))
                 return -1;
 
         for (index = 0;;index++) {
@@ -656,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;
 }
 
@@ -675,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, 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): %s nid\n", argv[0]);
+                fprintf (stderr, "usage(iib): %s nid\n", argv[0]);
                 return 0;
         }
 
@@ -695,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);
@@ -732,7 +804,8 @@ jt_ptl_del_peer (int argc, char **argv)
         int                      argidx;
         int                      rc;
 
-        if (!g_nal_is_compatible (argv[0], SOCKNAL, OPENIBNAL, 0))
+        if (!g_nal_is_compatible (argv[0], SOCKNAL, RANAL, 
+                                  OPENIBNAL, IIBNAL, VIBNAL, 0))
                 return -1;
 
         if (g_nal_is_compatible(NULL, SOCKNAL, 0)) {
@@ -747,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;
         }
@@ -764,7 +837,7 @@ jt_ptl_del_peer (int argc, char **argv)
         }
         
         if (argc > argidx) {
-                if (!strcmp (argv[3], "single_share")) {
+                if (!strcmp (argv[argidx], "single_share")) {
                         single_share = 1;
                 } else {
                         fprintf (stderr, "Unrecognised arg %s'\n", argv[3]);
@@ -795,10 +868,11 @@ jt_ptl_print_connections (int argc, char **argv)
         int                      index;
         int                      rc;
 
-        if (!g_nal_is_compatible (argv[0], SOCKNAL, OPENIBNAL, 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;
                 
@@ -820,25 +894,42 @@ 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;
 }
 
 int jt_ptl_connect(int argc, char **argv)
 {
+#ifndef HAVE_CONNECT
+        /* no connect() support */
+        return -1;
+#else /* HAVE_CONNECT */
         struct portals_cfg pcfg;
         struct sockaddr_in srvaddr;
+        struct sockaddr_in locaddr;
         __u32 ipaddr;
         char *flag;
         int fd, rc;
         int type = SOCKNAL_CONN_ANY;
-        int port;
+        int port, rport;
+        int o;
 
         if (argc < 3) {
                 fprintf(stderr, "usage: %s ip port [type]\n", argv[0]);
@@ -893,20 +984,48 @@ int jt_ptl_connect(int argc, char **argv)
                                 return (-1);
                         }
 
+        memset(&locaddr, 0, sizeof(locaddr)); 
+        locaddr.sin_family = AF_INET; 
+        locaddr.sin_addr.s_addr = INADDR_ANY;
+
         memset(&srvaddr, 0, sizeof(srvaddr));
         srvaddr.sin_family = AF_INET;
         srvaddr.sin_port = htons(port);
         srvaddr.sin_addr.s_addr = htonl(ipaddr);
 
-        fd = socket(PF_INET, SOCK_STREAM, 0);
-        if ( fd < 0 ) {
-                fprintf(stderr, "socket() failed: %s\n", strerror(errno));
-                return -1;
+
+        for (rport = IPPORT_RESERVED - 1; rport > IPPORT_RESERVED / 2; --rport) {
+                fd = socket(PF_INET, SOCK_STREAM, 0); 
+                if ( fd < 0 ) { 
+                        fprintf(stderr, "socket() failed: %s\n", strerror(errno)); 
+                        return -1; 
+                }
+
+                o = 1;
+                rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, 
+                                &o, sizeof(o));
+                
+                locaddr.sin_port = htons(rport);
+                rc = bind(fd, (struct sockaddr *)&locaddr, sizeof(locaddr)); 
+                if (rc == 0 || errno == EACCES) {
+                        rc = connect(fd, (struct sockaddr *)&srvaddr, sizeof(srvaddr));
+                        if (rc == 0) {
+                                break;
+                        } else if (errno != EADDRINUSE) {
+                                fprintf(stderr, "Error connecting to host: %s\n", strerror(errno));
+                                close(fd);
+                                return -1;
+                        }
+                } else if (errno != EADDRINUSE) {
+                        fprintf(stderr, "Error binding to port %d: %d: %s\n", port, errno, strerror(errno));
+                        close(fd);
+                        return -1;
+                }
         }
 
-        rc = connect(fd, (struct sockaddr *)&srvaddr, sizeof(srvaddr));
-        if ( rc == -1 ) { 
-                fprintf(stderr, "connect() failed: %s\n", strerror(errno));
+        if (rport == IPPORT_RESERVED / 2) {
+                fprintf(stderr,
+                        "Warning: all privileged ports are in use.\n"); 
                 return -1;
         }
 
@@ -937,6 +1056,7 @@ int jt_ptl_connect(int argc, char **argv)
                 fprintf(stderr, "close failed: %d\n", rc);
 
         return 0;
+#endif /* HAVE_CONNECT */
 }
 
 int jt_ptl_disconnect(int argc, char **argv)
@@ -951,11 +1071,12 @@ int jt_ptl_disconnect(int argc, char **argv)
                 return 0;
         }
 
-        if (!g_nal_is_compatible (NULL, SOCKNAL, OPENIBNAL, 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;
         }
@@ -997,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;
         }
@@ -1039,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,
@@ -1054,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;
 }
 
@@ -1204,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);
@@ -1233,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;
@@ -1450,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);
 }
 
@@ -1491,11 +1661,11 @@ lwt_snapshot(cycles_t *now, int *ncpu, int *totalsize,
         }
 
         /* crappy overloads */
-        if (data.ioc_nid != sizeof(lwt_event_t) ||
-            data.ioc_nid2 != offsetof(lwt_event_t, lwte_where)) {
+        if (data.ioc_nid2 != sizeof(lwt_event_t) ||
+            data.ioc_nid3 != offsetof(lwt_event_t, lwte_where)) {
                 fprintf(stderr,"kernel/user LWT event mismatch %d(%d),%d(%d)\n",
-                        (int)data.ioc_nid, sizeof(lwt_event_t),
-                        (int)data.ioc_nid2,
+                        (int)data.ioc_nid2, sizeof(lwt_event_t),
+                        (int)data.ioc_nid3,
                         (int)offsetof(lwt_event_t, lwte_where));
                 return (-1);
         }
@@ -1573,12 +1743,21 @@ lwt_put_string(char *ustr)
 static int
 lwt_print(FILE *f, cycles_t t0, cycles_t tlast, double mhz, int cpu, lwt_event_t *e)
 {
+#ifndef __WORDSIZE
+# error "__WORDSIZE not defined"
+#elif __WORDSIZE == 32
+# define XFMT "%#010lx"
+#elif __WORDSIZE== 64
+# define XFMT "%#018lx"
+#else
+# error "Unexpected __WORDSIZE"
+#endif
         char           *where = lwt_get_string(e->lwte_where);
 
         if (where == NULL)
                 return (-1);
 
-        fprintf(f, "%#010lx %#010lx %#010lx %#010lx: %#010lx %1d %10.6f %10.2f %s\n",
+        fprintf(f, XFMT" "XFMT" "XFMT" "XFMT": "XFMT" %2d %10.6f %10.2f %s\n",
                 e->lwte_p1, e->lwte_p2, e->lwte_p3, e->lwte_p4,
                 (long)e->lwte_task, cpu, (e->lwte_when - t0) / (mhz * 1000000.0),
                 (t0 == e->lwte_when) ? 0.0 : (e->lwte_when - tlast) / mhz,
@@ -1587,6 +1766,7 @@ lwt_print(FILE *f, cycles_t t0, cycles_t tlast, double mhz, int cpu, lwt_event_t
         lwt_put_string(where);
 
         return (0);
+#undef XFMT
 }
 
 double