Whamcloud - gitweb
land b1_4_bgl on HEAD (20050404_1913)
[fs/lustre-release.git] / lnet / utils / portals.c
index 09fdf5f..e3f5916 100644 (file)
 #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>
@@ -175,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);
@@ -579,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;
 }
 
@@ -694,7 +709,7 @@ 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, 0))
+                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),
@@ -704,8 +719,15 @@ jt_ptl_print_peers (int argc, char **argv)
                                 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;
 }
 
@@ -728,8 +750,14 @@ jt_ptl_add_peer (int argc, char **argv)
                                  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(iib,vib): %s nid\n", argv[0]);
+                fprintf (stderr, "usage(iib): %s nid\n", argv[0]);
                 return 0;
         }
 
@@ -739,16 +767,16 @@ jt_ptl_add_peer (int argc, char **argv)
                 return -1;
         }
 
-        if (g_nal_is_compatible (NULL, SOCKNAL, OPENIBNAL, RANAL, 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);
@@ -844,7 +872,7 @@ jt_ptl_print_connections (int argc, char **argv)
                                   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;
                 
@@ -875,8 +903,15 @@ jt_ptl_print_connections (int argc, char **argv)
                                 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;
 }
 
@@ -1125,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,
@@ -1140,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;
 }
 
@@ -1322,8 +1363,6 @@ int
 jt_ptl_loopback (int argc, char **argv)
 {
         int                      rc;
-        ptl_nid_t                nid;
-        unsigned int             threshold;
         int                      set;
         int                      enable;
         struct portal_ioctl_data data;
@@ -1576,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);
 }