Whamcloud - gitweb
land b1_4_bgl on HEAD (20050404_1913)
authorjacob <jacob>
Mon, 4 Apr 2005 23:33:18 +0000 (23:33 +0000)
committerjacob <jacob>
Mon, 4 Apr 2005 23:33:18 +0000 (23:33 +0000)
13 files changed:
lnet/ChangeLog
lnet/autoconf/lustre-lnet.m4
lnet/include/libcfs/kp30.h
lnet/include/libcfs/libcfs.h
lnet/include/libcfs/list.h
lnet/klnds/gmlnd/gmlnd_module.c
lnet/klnds/qswlnd/qswlnd.c
lnet/libcfs/debug.c
lnet/libcfs/module.c
lnet/libcfs/tracefile.c
lnet/utils/debug.c
lnet/utils/gmlndnid.c
lnet/utils/portals.c

index 3d7f2b0..9351115 100644 (file)
@@ -1,3 +1,8 @@
+2005-02-04  Cluster File Systems, Inc. <info@clusterfs.com>
+       * miscellania
+       - update vibnal (Voltaire IB NAL)
+       - update gmnal (Myrinet NAL), gmnalid
+
 2005-02-04  Eric Barton  <eeb@bartonsoftware.com>
 
        * Landed portals:b_port_step as follows...
 2005-02-04  Eric Barton  <eeb@bartonsoftware.com>
 
        * Landed portals:b_port_step as follows...
index 4611dee..8a937e3 100644 (file)
@@ -586,7 +586,7 @@ AC_DEFUN([LP_PATH_DEFAULTS],
 #
 AC_DEFUN([LP_CONFIGURE],
 [# portals/utils/portals.c
 #
 AC_DEFUN([LP_CONFIGURE],
 [# portals/utils/portals.c
-AC_CHECK_HEADERS([netdb.h netinet/tcp.h asm/types.h endian.h])
+AC_CHECK_HEADERS([netdb.h netinet/tcp.h asm/types.h endian.h sys/ioctl.h])
 AC_CHECK_FUNCS([gethostbyname socket connect])
 
 # portals/utils/debug.c
 AC_CHECK_FUNCS([gethostbyname socket connect])
 
 # portals/utils/debug.c
index efb6523..4c3f225 100644 (file)
@@ -262,7 +262,7 @@ struct portals_device_userstate
  * USER LEVEL STUFF BELOW
  */
 
  * USER LEVEL STUFF BELOW
  */
 
-#define PORTAL_IOCTL_VERSION 0x00010007
+#define PORTAL_IOCTL_VERSION 0x00010008
 #define PING_SYNC       0
 #define PING_ASYNC      1
 
 #define PING_SYNC       0
 #define PING_ASYNC      1
 
index b6f582c..7b45d89 100644 (file)
@@ -110,6 +110,7 @@ extern unsigned int portal_printk;
 # define DEBUG_SUBSYSTEM S_UNDEFINED
 #endif
 
 # define DEBUG_SUBSYSTEM S_UNDEFINED
 #endif
 
+#ifdef __KERNEL__
 #if 1
 #define CDEBUG(mask, format, a...)                                            \
 do {                                                                          \
 #if 1
 #define CDEBUG(mask, format, a...)                                            \
 do {                                                                          \
@@ -207,7 +208,7 @@ do {                                                                    \
         CDEBUG(D_TRACE, "Process leaving\n");                           \
         EXIT_NESTING;                                                   \
 } while(0)
         CDEBUG(D_TRACE, "Process leaving\n");                           \
         EXIT_NESTING;                                                   \
 } while(0)
-#else
+#else /* !1 */
 
 #define RETURN(rc) return (rc)
 #define ENTRY
 
 #define RETURN(rc) return (rc)
 #define ENTRY
@@ -220,15 +221,50 @@ do {                                                                    \
 #define CWARN(format, a...)             printk(KERN_WARNING format, ## a)
 #define CERROR(format, a...)            printk(KERN_ERR format, ## a)
 #define CEMERG(format, a...)            printk(KERN_EMERG format, ## a)
 #define CWARN(format, a...)             printk(KERN_WARNING format, ## a)
 #define CERROR(format, a...)            printk(KERN_ERR format, ## a)
 #define CEMERG(format, a...)            printk(KERN_EMERG format, ## a)
+#define LCONSOLE(mask, format, a...)    do { } while (0)
+#define LCONSOLE_INFO(format, a...)     printk(KERN_INFO format, ## a)
+#define LCONSOLE_WARN(format, a...)     printk(KERN_WARNING format, ## a)
+#define LCONSOLE_ERROR(format, a...)    printk(KERN_ERROR format, ## a)
+#define LCONSOLE_EMERG(format, a...)    printk(KERN_EMERG format, ## a)
 #define GOTO(label, rc)                 do { (void)(rc); goto label; } while (0)
 #define RETURN(rc)                      return (rc)
 #define ENTRY                           do { } while (0)
 #define EXIT                            do { } while (0)
 #define GOTO(label, rc)                 do { (void)(rc); goto label; } while (0)
 #define RETURN(rc)                      return (rc)
 #define ENTRY                           do { } while (0)
 #define EXIT                            do { } while (0)
-#endif
+#endif /* !1 */
+#else /* !__KERNEL__ */
+#define CDEBUG(mask, format, a...)      do { } while (0)
+#define LCONSOLE(mask, format, a...)    do { } while (0)
+#ifdef stderr
+#define CWARN(format, a...)             fprintf(stderr, "<4>" format, ## a)
+#define CERROR(format, a...)            fprintf(stderr, "<3>" format, ## a)
+#define CEMERG(format, a...)            fprintf(stderr, "<0>" format, ## a)
+#define LCONSOLE_INFO(format, a...)     fprintf(stderr, format, ## a)
+#define LCONSOLE_WARN(format, a...)     fprintf(stderr, format, ## a)
+#define LCONSOLE_ERROR(format, a...)    fprintf(stderr, format, ## a)
+#define LCONSOLE_EMERG(format, a...)    fprintf(stderr, format, ## a)
+#else
+#define CWARN(format, a...)             do { } while (0)
+#define CERROR(format, a...)            do { } while (0)
+#define CEMERG(format, a...)            do { } while (0)
+#define LCONSOLE_INFO(format, a...)     do { } while (0)
+#define LCONSOLE_WARN(format, a...)     do { } while (0)
+#define LCONSOLE_ERROR(format, a...)    do { } while (0)
+#define LCONSOLE_EMERG(format, a...)    do { } while (0)
+#endif /* !stderr */
+#define GOTO(label, rc)                 do { (void)(rc); goto label; } while (0)
+#define RETURN(rc)                      return (rc)
+#define ENTRY                           do { } while (0)
+#define EXIT                            do { } while (0)
+#endif /* !__KERNEL__ */
 
 #define LUSTRE_SRV_PTL_PID      LUSTRE_PTL_PID
 
 
 #define LUSTRE_SRV_PTL_PID      LUSTRE_PTL_PID
 
-#define PORTALS_CFG_VERSION 0x00010001
+/*
+ * eeb cfg
+ * ecf6
+ * ecfG
+ */
+#define PORTALS_CFG_VERSION 0xecf60001
 
 struct portals_cfg {
         __u32 pcfg_version;
 
 struct portals_cfg {
         __u32 pcfg_version;
@@ -238,6 +274,8 @@ struct portals_cfg {
         __u32 pcfg_flags;
 
         __u32 pcfg_gw_nal;
         __u32 pcfg_flags;
 
         __u32 pcfg_gw_nal;
+        __u32 pcfg_padding1;
+
         __u64 pcfg_nid;
         __u64 pcfg_nid2;
         __u64 pcfg_nid3;
         __u64 pcfg_nid;
         __u64 pcfg_nid2;
         __u64 pcfg_nid3;
@@ -249,19 +287,43 @@ struct portals_cfg {
         __u32 pcfg_wait;
 
         __u32 pcfg_plen1; /* buffers in userspace */
         __u32 pcfg_wait;
 
         __u32 pcfg_plen1; /* buffers in userspace */
-        char *pcfg_pbuf1;
         __u32 pcfg_plen2; /* buffers in userspace */
         __u32 pcfg_plen2; /* buffers in userspace */
-        char *pcfg_pbuf2;
+        __u32 pcfg_alloc_size;  /* size of this allocated portals_cfg */
+        char  pcfg_pbuf[0];
 };
 
 #define PCFG_INIT(pcfg, cmd)                            \
 do {                                                    \
 };
 
 #define PCFG_INIT(pcfg, cmd)                            \
 do {                                                    \
-        memset(&pcfg, 0, sizeof(pcfg));                 \
-        pcfg.pcfg_version = PORTALS_CFG_VERSION;        \
-        pcfg.pcfg_command = (cmd);                      \
+        memset(&(pcfg), 0, sizeof((pcfg)));             \
+        (pcfg).pcfg_version = PORTALS_CFG_VERSION;      \
+        (pcfg).pcfg_command = (cmd);                    \
                                                         \
 } while (0)
 
                                                         \
 } while (0)
 
+#define PCFG_INIT_PBUF(pcfg, cmd, plen1, plen2)                         \
+        do {                                                            \
+                int bufsize = size_round(sizeof(*(pcfg)));              \
+                bufsize += size_round(plen1) + size_round(plen2);       \
+                PORTAL_ALLOC((pcfg), bufsize);                          \
+                if ((pcfg)) {                                           \
+                        memset((pcfg), 0, bufsize);                     \
+                        (pcfg)->pcfg_version = PORTALS_CFG_VERSION;     \
+                        (pcfg)->pcfg_command = (cmd);                   \
+                        (pcfg)->pcfg_plen1 = (plen1);                   \
+                        (pcfg)->pcfg_plen2 = (plen2);                   \
+                        (pcfg)->pcfg_alloc_size = bufsize;              \
+                }                                                       \
+        } while (0)
+
+#define PCFG_FREE_PBUF(pcfg) PORTAL_FREE((pcfg), (pcfg)->pcfg_alloc_size)
+
+#define PCFG_PBUF(pcfg, idx)                                            \
+        (0 == (idx)                                                     \
+         ? ((char *)(pcfg) + size_round(sizeof(*(pcfg))))               \
+         : (1 == (idx)                                                  \
+            ? ((char *)(pcfg) + size_round(sizeof(*(pcfg))) + size_round(pcfg->pcfg_plen1)) \
+            : (NULL)))
+
 typedef int (nal_cmd_handler_fn)(struct portals_cfg *, void *);
 int libcfs_nal_cmd_register(int nal, nal_cmd_handler_fn *handler, void *arg);
 int libcfs_nal_cmd(struct portals_cfg *pcfg);
 typedef int (nal_cmd_handler_fn)(struct portals_cfg *, void *);
 int libcfs_nal_cmd_register(int nal, nal_cmd_handler_fn *handler, void *arg);
 int libcfs_nal_cmd(struct portals_cfg *pcfg);
index eebb7b6..7bd40d6 100644 (file)
@@ -9,7 +9,7 @@
 #define CFS_LIST_HEAD(n)               LIST_HEAD(n)
 #define CFS_INIT_LIST_HEAD(p)          INIT_LIST_HEAD(p)
 
 #define CFS_LIST_HEAD(n)               LIST_HEAD(n)
 #define CFS_INIT_LIST_HEAD(p)          INIT_LIST_HEAD(p)
 
-#else /* !defined (__linux__) && defined(__KERNEL__) */
+#else /* !defined (__linux__) || !defined(__KERNEL__) */
 
 /*
  * Simple doubly linked list implementation.
 
 /*
  * Simple doubly linked list implementation.
index 9fd2182..6cd622f 100644 (file)
@@ -52,7 +52,7 @@ gmnal_cmd(struct portals_cfg *pcfg, void *private)
        case(GMNAL_IOC_GET_GNID):
 
                PORTAL_ALLOC(name, pcfg->pcfg_plen1);
        case(GMNAL_IOC_GET_GNID):
 
                PORTAL_ALLOC(name, pcfg->pcfg_plen1);
-               copy_from_user(name, pcfg->pcfg_pbuf1, pcfg->pcfg_plen1);
+               copy_from_user(name, PCFG_PBUF(pcfg, 1), pcfg->pcfg_plen1);
        
                GMNAL_GM_LOCK(nal_data);
                //nid = gm_host_name_to_node_id(nal_data->gm_port, name);
        
                GMNAL_GM_LOCK(nal_data);
                //nid = gm_host_name_to_node_id(nal_data->gm_port, name);
@@ -74,7 +74,7 @@ gmnal_cmd(struct portals_cfg *pcfg, void *private)
                        return(-1);
                }
                CDEBUG(D_INFO, "Global node is is [%u][%x]\n", gnid, gnid);
                        return(-1);
                }
                CDEBUG(D_INFO, "Global node is is [%u][%x]\n", gnid, gnid);
-               copy_to_user(pcfg->pcfg_pbuf2, &gnid, pcfg->pcfg_plen2);
+               copy_to_user(PCFG_PBUF(pcfg, 2), &gnid, pcfg->pcfg_plen2);
        break;
        default:
                CDEBUG(D_INFO, "gmnal_cmd UNKNOWN[%d]\n", pcfg->pcfg_command);
        break;
        default:
                CDEBUG(D_INFO, "gmnal_cmd UNKNOWN[%d]\n", pcfg->pcfg_command);
index 0e8929f..be01f5d 100644 (file)
@@ -74,7 +74,8 @@ kqswnal_get_tx_desc (struct portals_cfg *pcfg)
                ktx = list_entry (tmp, kqswnal_tx_t, ktx_list);
                hdr = (ptl_hdr_t *)ktx->ktx_buffer;
 
                ktx = list_entry (tmp, kqswnal_tx_t, ktx_list);
                hdr = (ptl_hdr_t *)ktx->ktx_buffer;
 
-               pcfg->pcfg_pbuf1 = (char *)ktx;
+               memcpy(pcfg->pcfg_pbuf, ktx,
+                      MIN(sizeof(*ktx), pcfg->pcfg_plen1));
                pcfg->pcfg_count = le32_to_cpu(hdr->type);
                pcfg->pcfg_size  = le32_to_cpu(hdr->payload_length);
                pcfg->pcfg_nid   = le64_to_cpu(hdr->dest_nid);
                pcfg->pcfg_count = le32_to_cpu(hdr->type);
                pcfg->pcfg_size  = le32_to_cpu(hdr->payload_length);
                pcfg->pcfg_nid   = le64_to_cpu(hdr->dest_nid);
index f5dfaba..b7fd218 100644 (file)
@@ -208,15 +208,18 @@ char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
         case VIBNAL:
         case OPENIBNAL:
         case RANAL:
         case VIBNAL:
         case OPENIBNAL:
         case RANAL:
-        case SOCKNAL:
+        case SOCKNAL: {
+                /* HIPQUAD requires __u32, but we can't cast in it */
+                __u32 nid32 = (__u32)nid;
                 if ((__u32)(nid >> 32)) {
                         snprintf(str, PTL_NALFMT_SIZE, "%u:%u.%u.%u.%u",
                 if ((__u32)(nid >> 32)) {
                         snprintf(str, PTL_NALFMT_SIZE, "%u:%u.%u.%u.%u",
-                                 (__u32)(nid >> 32), HIPQUAD(nid));
+                                 (__u32)(nid >> 32), HIPQUAD(nid32));
                 } else {
                         snprintf(str, PTL_NALFMT_SIZE, "%u.%u.%u.%u",
                 } else {
                         snprintf(str, PTL_NALFMT_SIZE, "%u.%u.%u.%u",
-                                 HIPQUAD(nid));
+                                 HIPQUAD(nid32));
                 }
                 break;
                 }
                 break;
+        }
         case QSWNAL:
         case GMNAL:
         case LONAL:
         case QSWNAL:
         case GMNAL:
         case LONAL:
index 5fe401b..84c124c 100644 (file)
@@ -274,6 +274,10 @@ libcfs_nal_cmd(struct portals_cfg *pcfg)
         int   rc = -EINVAL;
         ENTRY;
 
         int   rc = -EINVAL;
         ENTRY;
 
+        if (pcfg->pcfg_version != PORTALS_CFG_VERSION) {
+                RETURN(-EINVAL);
+        }
+
         mutex_down(&nal_cmd_mutex);
         cmd = libcfs_find_nal_cmd_handler(nal);
         if (cmd != NULL) {
         mutex_down(&nal_cmd_mutex);
         cmd = libcfs_find_nal_cmd_handler(nal);
         if (cmd != NULL) {
@@ -408,12 +412,25 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, unsigned long cmd, void *a
 
                 CDEBUG (D_IOCTL, "nal command nal %x cmd %d\n", pcfg.pcfg_nal,
                         pcfg.pcfg_command);
 
                 CDEBUG (D_IOCTL, "nal command nal %x cmd %d\n", pcfg.pcfg_nal,
                         pcfg.pcfg_command);
-                err = libcfs_nal_cmd(&pcfg);
+                if (pcfg.pcfg_version != PORTALS_CFG_VERSION) {
+                        /* set this so userspace can tell when they
+                         * have an incompatible version and print a
+                         * decent message to the user
+                         */
+                        pcfg.pcfg_version = PORTALS_CFG_VERSION;
+                        if (copy_to_user((char *)data->ioc_pbuf1, &pcfg,
+                                         sizeof (pcfg)))
+                                err = -EFAULT;
+                        else
+                                err = -EINVAL;
+                } else {
+                        err = libcfs_nal_cmd(&pcfg);
 
 
-                if (err == 0 &&
-                    copy_to_user((char *)data->ioc_pbuf1, &pcfg,
-                                 sizeof (pcfg)))
-                        err = -EFAULT;
+                        if (err == 0 &&
+                            copy_to_user((char *)data->ioc_pbuf1, &pcfg,
+                                         sizeof (pcfg)))
+                                err = -EFAULT;
+                }
                 break;
         }
 
                 break;
         }
 
index 6ab716b..a1dab74 100644 (file)
@@ -250,10 +250,12 @@ static void collect_pages_on_cpu(void *info)
         tcd = trace_get_tcd(flags);
 
         spin_lock(&pc->pc_lock);
         tcd = trace_get_tcd(flags);
 
         spin_lock(&pc->pc_lock);
-        list_splice_init(&tcd->tcd_pages, &pc->pc_pages);
+        list_splice(&tcd->tcd_pages, &pc->pc_pages);
+        CFS_INIT_LIST_HEAD(&tcd->tcd_pages);
         tcd->tcd_cur_pages = 0;
         if (pc->pc_want_daemon_pages) {
         tcd->tcd_cur_pages = 0;
         if (pc->pc_want_daemon_pages) {
-                list_splice_init(&tcd->tcd_daemon_pages, &pc->pc_pages);
+                list_splice(&tcd->tcd_daemon_pages, &pc->pc_pages);
+                CFS_INIT_LIST_HEAD(&tcd->tcd_pages);
                 tcd->tcd_cur_daemon_pages = 0;
         }
         spin_unlock(&pc->pc_lock);
                 tcd->tcd_cur_daemon_pages = 0;
         }
         spin_unlock(&pc->pc_lock);
@@ -576,8 +578,8 @@ static int tracefiled(void *arg)
                         }
                 }
                 CFS_MMSPACE_CLOSE;
                         }
                 }
                 CFS_MMSPACE_CLOSE;
-                cfs_filp_close(filp);
 
 
+                cfs_filp_close(filp);
                 put_pages_on_daemon_list(&pc);
         }
         complete(&tctl->tctl_stop);
                 put_pages_on_daemon_list(&pc);
         }
         complete(&tctl->tctl_stop);
index df78d08..ba8b790 100644 (file)
 #endif
 #include <stdlib.h>
 #include <string.h>
 #endif
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#else
+#include "ioctl.h"
+#endif
 #include <fcntl.h>
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <unistd.h>
@@ -704,7 +709,7 @@ static int jt_dbg_modules_2_4(int argc, char **argv)
 #ifdef HAVE_LINUX_VERSION_H
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
         struct mod_paths *mp;
 #ifdef HAVE_LINUX_VERSION_H
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
         struct mod_paths *mp;
-        char *path = "..";
+        char *path = "";
         char *kernel = "linux";
 
         if (argc >= 2)
         char *kernel = "linux";
 
         if (argc >= 2)
@@ -730,8 +735,8 @@ static int jt_dbg_modules_2_4(int argc, char **argv)
                                 printf("query_module(%s) failed: %s\n",
                                        mp->name, strerror(errno));
                 } else {
                                 printf("query_module(%s) failed: %s\n",
                                        mp->name, strerror(errno));
                 } else {
-                        printf("add-symbol-file %s/%s/%s.o 0x%0lx\n", path,
-                               mp->path, mp->name,
+                        printf("add-symbol-file %s%s%s/%s.o 0x%0lx\n", path,
+                               path[0] ? "/" : "", mp->path, mp->name,
                                info.addr + sizeof(struct module));
                 }
         }
                                info.addr + sizeof(struct module));
                 }
         }
@@ -745,7 +750,7 @@ static int jt_dbg_modules_2_4(int argc, char **argv)
 static int jt_dbg_modules_2_5(int argc, char **argv)
 {
         struct mod_paths *mp;
 static int jt_dbg_modules_2_5(int argc, char **argv)
 {
         struct mod_paths *mp;
-        char *path = "..";
+        char *path = "";
         char *kernel = "linux";
         const char *proc = "/proc/modules";
         char modname[128], others[128];
         char *kernel = "linux";
         const char *proc = "/proc/modules";
         char modname[128], others[128];
@@ -775,8 +780,8 @@ static int jt_dbg_modules_2_5(int argc, char **argv)
                                 break;
                 }
                 if (mp->name) {
                                 break;
                 }
                 if (mp->name) {
-                        printf("add-symbol-file %s/%s/%s.o 0x%0lx\n", path,
-                               mp->path, mp->name, modaddr);
+                        printf("add-symbol-file %s%s%s/%s.o 0x%0lx\n", path,
+                               path[0] ? "/" : "", mp->path, mp->name, modaddr);
                 }
         }
 
                 }
         }
 
index c4dbe25..7fbe8ef 100644 (file)
  */
 #define GM_UNIT 0
 
  */
 #define GM_UNIT 0
 
-/*
- * prototypes
- */
-unsigned u_getgmnid(char *name, int get_local_id);
-void usage(char *prg, int h);
-
-int main(int argc, char **argv)
+void
+usage(char *prg, int h)
 {
 {
-    unsigned int        nid = 0;
-    char               *name = NULL;
-    int                        c;
-    int                        get_local_id = 0;
-
-
-
-    while ((c = getopt(argc, argv, "n:lh")) != -1) {
-        switch(c) {
-            case('n'):
-                if (get_local_id) {
-                    usage(argv[0], 0);
-                    exit(-1);
-                }
-            name = optarg;     
-            break;
-            case('h'):
-                usage(argv[0], 1);
-                exit(-1);
-            break;
-            case('l'):
-                if (name) {
-                    usage(argv[0], 0);
-                    exit(-1);
-                }
-                get_local_id = 1;
-            break;
-            default:
-                usage(argv[0], 0);
-                exit(-1);
-            }
-    }
-
-    if (!name && !get_local_id) {
-        usage(argv[0], 0);
-        exit(-1);
-    }
-
-    nid = u_getgmnid(name, get_local_id);
-    printf("%u\n", nid);
-    exit(0);
+        fprintf(stderr, "usage %s -n hostname | -l | -h\n", prg);
+        if (h) {
+                printf("\nGet Myrinet Global network ids for specified host\n"
+                       "-l gets network id for local host\n");
+        }
 }
 
 unsigned
 u_getgmnid(char *name, int get_local_id)
 {
 }
 
 unsigned
 u_getgmnid(char *name, int get_local_id)
 {
-    struct gm_port     *gm_port;
-    int                gm_port_id = 2;
-    gm_status_t     gm_status = GM_SUCCESS;
+        struct gm_port *gm_port;
+        int             gm_port_id = 2;
+        gm_status_t     gm_status = GM_SUCCESS;
+        unsigned        global_nid = 0, local_nid = 0; /* gm ids never 0 */
 
 
-    /*
-     * gm global or local ids are never 0
-     */
-    unsigned   global_nid = 0, local_nid = 0;
+        gm_status = gm_init();
+        if (gm_status != GM_SUCCESS) {
+                fprintf(stderr, "gm_init: %s\n", gm_strerror(gm_status));
+                return(0);
+        }
 
 
-    gm_status = gm_init();
-    if (gm_status != GM_SUCCESS) {
-        fprintf(stderr, "gm_init :: %s\n", gm_strerror(gm_status));
-        return(0);
-    }
-       
-    gm_status = gm_open(&gm_port, GM_UNIT, gm_port_id,  
-                           "gmnalnid", GM_API_VERSION);
+        gm_status = gm_open(&gm_port, GM_UNIT, gm_port_id, "gmnalnid",
+                            GM_API_VERSION);
+        if (gm_status != GM_SUCCESS) {
+                /* Couldn't open port 2, try 4 5 6 7 */
+                for (gm_port_id = 4; gm_port_id < 8; gm_port_id++) {
+                        gm_status = gm_open(&gm_port, GM_UNIT, gm_port_id,
+                                            "gmnalnid", GM_API_VERSION);
+                        if (gm_status == GM_SUCCESS)
+                                break;
+
+                        fprintf(stderr, "gm_open: %s\n",gm_strerror(gm_status));
+                        gm_finalize();
+                        return(0);
+                }
+        }
 
 
-    if (gm_status != GM_SUCCESS) {
-        /*
-         *     Couldn't open port 2 
-         *     try 4 5 6 7 
-         */
-       
-        for (gm_port_id=4; gm_port_id<8; gm_port_id++) {
-            gm_status = gm_open(&gm_port, 
-                                GM_UNIT, 
-                                gm_port_id,  
-                                "gmnalnid", 
-                                GM_API_VERSION);
-            if (gm_status == GM_SUCCESS) {
-                break;
-            }
-        fprintf(stderr, "gm_open :: %s\n", 
-        gm_strerror(gm_status));
-        gm_finalize();
-        return(0);
+        if (get_local_id) {
+                local_nid = 1;
+        } else {
+                gm_status = gm_host_name_to_node_id_ex(gm_port, 1000000, name,
+                                                       &local_nid);
+                if (gm_status != GM_SUCCESS) {
+                        fprintf(stderr, "gm_host_name_to_node_id_ex: %s\n",
+                                gm_strerror(gm_status));
+                        gm_close(gm_port);
+                        gm_finalize();
+                        return(0);
+                }
         }
         }
-    }
 
 
-    if (get_local_id) {
-        local_nid = 1;
-    } else {
-        gm_status = gm_host_name_to_node_id_ex(gm_port, 1000000, name, 
-                                               &local_nid);
+        gm_status = gm_node_id_to_global_id(gm_port, local_nid, &global_nid) ;
         if (gm_status != GM_SUCCESS) {
         if (gm_status != GM_SUCCESS) {
-            fprintf(stderr, "gm_host_name_to_node_id_ex :: %s\n", 
-            gm_strerror(gm_status));
-            gm_close(gm_port);
-            gm_finalize();
-            return(0);
+                fprintf(stderr, "gm_node_id_to_global_id: %s\n",
+                        gm_strerror(gm_status));
+                gm_close(gm_port);
+                gm_finalize();
+                return(0);
         }
         }
-    }
-
-    gm_status = gm_node_id_to_global_id(gm_port, local_nid, &global_nid) ;
-    if (gm_status != GM_SUCCESS) {
-        fprintf(stderr, "gm_node_id_to_global_id :: %s\n", 
-        gm_strerror(gm_status));
         gm_close(gm_port);
         gm_finalize();
         gm_close(gm_port);
         gm_finalize();
-        return(0);
-    }
-    gm_close(gm_port);
-    gm_finalize();
-    return(global_nid);
+        return(global_nid);
 }
 
 }
 
-void 
-usage(char *prg, int h)
+int main(int argc, char **argv)
 {
 {
+        unsigned int        nid = 0;
+        char               *name = NULL;
+        int                 c;
+        int                 get_local_id = 0;
+
+        while ((c = getopt(argc, argv, "n:lh")) != -1) {
+                switch(c) {
+                case('n'):
+                        if (get_local_id) {
+                                usage(argv[0], 0);
+                                exit(-1);
+                        }
+                        name = optarg;
+                        break;
+                case('h'):
+                        usage(argv[0], 1);
+                        exit(-1);
+                        break;
+                case('l'):
+                        if (name) {
+                                usage(argv[0], 0);
+                                exit(-1);
+                        }
+                        get_local_id = 1;
+                        break;
+                default:
+                        usage(argv[0], 0);
+                        exit(-1);
+                }
+        }
+
+        if (!name && !get_local_id) {
+                usage(argv[0], 0);
+                exit(-1);
+        }
 
 
-    fprintf(stderr, "usage %s -n hostname | -l | -h\n", prg);
-    if (h) {
-        printf("\nGet Myrinet Global network ids for specified host\n");
-        printf("-l gets network id for local host\n");
-    }
-    return;
+        nid = u_getgmnid(name, get_local_id);
+        printf("%u\n", nid);
+        exit(0);
 }
 }
index b82f9ee..e3f5916 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
 #include <fcntl.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #include <sys/ioctl.h>
+#else
+#include "ioctl.h"
+#endif
 #include <errno.h>
 #include <unistd.h>
 #include <time.h>
 #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);
                 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);
         }
 
         return (rc);
@@ -579,8 +586,16 @@ jt_ptl_print_interfaces (int argc, char **argv)
                         pcfg.pcfg_fd, pcfg.pcfg_count);
         }
 
                         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;
 }
 
         return 0;
 }
 
@@ -704,8 +719,15 @@ jt_ptl_print_peers (int argc, char **argv)
                                 pcfg.pcfg_nid, pcfg.pcfg_wait);
         }
 
                                 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;
 }
 
         return 0;
 }
 
@@ -850,7 +872,7 @@ jt_ptl_print_connections (int argc, char **argv)
                                   OPENIBNAL, IIBNAL, VIBNAL, 0))
                 return -1;
 
                                   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;
                 
                 PCFG_INIT (pcfg,  NAL_CMD_GET_CONN);
                 pcfg.pcfg_count   = index;
                 
@@ -881,8 +903,15 @@ jt_ptl_print_connections (int argc, char **argv)
                                 pcfg.pcfg_nid);
         }
 
                                 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;
 }
 
         return 0;
 }
 
@@ -1131,12 +1160,11 @@ jt_ptl_print_active_txs (int argc, char **argv)
                 if (rc != 0)
                         break;
 
                 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_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,
                         pcfg.pcfg_size,
                         pcfg.pcfg_nid,
                         pcfg.pcfg_nid2,
@@ -1146,8 +1174,15 @@ jt_ptl_print_active_txs (int argc, char **argv)
                         pcfg.pcfg_flags >> 2);
         }
 
                         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;
 }
 
         return 0;
 }
 
@@ -1580,6 +1615,11 @@ jt_ptl_print_routes (int argc, char **argv)
                         ptl_nid2str (buffer[2], nid2),
                         alive ? "up" : "down");
         }
                         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);
 }
 
         return (0);
 }