X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lnet%2Futils%2Fportals.c;h=a9f2e356758bc1706f6d4ba60f273588a4460a2f;hp=0e109cb62400f0d32031d5cd7ca4e2487c7c6c3e;hb=e7516aebc27066b2ab4e00f8a3c4ff2bd5946339;hpb=9d4b898b1c1c7c318fda5f0c345ed726c774c06a diff --git a/lnet/utils/portals.c b/lnet/utils/portals.c index 0e109cb..a9f2e35 100644 --- a/lnet/utils/portals.c +++ b/lnet/utils/portals.c @@ -22,27 +22,39 @@ #include #include +#ifdef HAVE_NETDB_H #include +#endif #include +#ifdef HAVE_NETINET_TCP_H #include -#include +#endif #include #include #include +#ifdef HAVE_SYS_IOCTL_H #include +#endif +#ifndef _IOWR +#include "ioctl.h" +#endif #include #include #include #include +#ifdef HAVE_ENDIAN_H #include - -#ifdef __CYGWIN__ -#include #endif - +#if CRAY_PORTALS +#ifdef REDSTORM +#define __QK__ +#endif +#include +#endif + +#include #include #include -#include #include #include #include "parser.h" @@ -52,17 +64,28 @@ unsigned int portal_printk; static unsigned int g_nal = 0; -typedef struct { +typedef struct +{ char *name; int num; } name2num_t; 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} }; @@ -157,6 +180,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); @@ -202,6 +228,7 @@ nal2name (int nal) return ((e == NULL) ? "???" : e->name); } +#ifdef HAVE_GETHOSTBYNAME static struct hostent * ptl_gethostbyname(char * hname) { struct hostent *he; @@ -214,14 +241,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) @@ -288,26 +316,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); } @@ -315,6 +345,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; @@ -326,7 +357,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); @@ -340,19 +372,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); } @@ -360,6 +391,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)) { @@ -379,6 +421,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 @@ -387,12 +430,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); @@ -517,7 +561,6 @@ int jt_ptl_network(int argc, char **argv) return (-1); } - int jt_ptl_print_interfaces (int argc, char **argv) { @@ -544,8 +587,16 @@ jt_ptl_print_interfaces (int argc, char **argv) pcfg.pcfg_fd, pcfg.pcfg_count); } - if (index == 0) - printf ("\n"); + if (index == 0) { + if (errno == ENOENT) { + printf ("\n"); + } else { + fprintf(stderr, "Error getting interfaces: %s: " + "check dmesg.\n", + strerror(errno)); + } + } + return 0; } @@ -556,6 +607,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]); @@ -569,13 +623,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; @@ -586,7 +646,7 @@ jt_ptl_add_interface (int argc, char **argv) strerror (errno)); return -1; } - + return 0; } @@ -620,11 +680,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; @@ -632,7 +692,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++) { @@ -649,13 +710,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 ("\n"); + if (index == 0) { + if (errno == ENOENT) { + printf ("\n"); + } else { + fprintf(stderr, "Error getting peer list: %s: " + "check dmesg.\n", + strerror(errno)); + } + } return 0; } @@ -668,17 +741,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; } @@ -688,16 +768,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); @@ -725,7 +805,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)) { @@ -740,7 +821,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; } @@ -757,7 +838,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]); @@ -788,10 +869,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; @@ -813,25 +895,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 ("\n"); + if (index == 0) { + if (errno == ENOENT) { + printf ("\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]); @@ -886,20 +985,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; } @@ -930,6 +1057,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) @@ -944,11 +1072,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; } @@ -990,7 +1119,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; } @@ -1032,12 +1161,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" : "", + pcfg.pcfg_count == PTL_MSG_REPLY ? "REPLY" : "", pcfg.pcfg_size, pcfg.pcfg_nid, pcfg.pcfg_nid2, @@ -1047,8 +1175,15 @@ jt_ptl_print_active_txs (int argc, char **argv) pcfg.pcfg_flags >> 2); } - if (index == 0) - printf ("\n"); + if (index == 0) { + if (errno == ENOENT) { + printf ("\n"); + } else { + fprintf(stderr, "Error getting active transmits list: " + "%s: check dmesg.\n", + strerror(errno)); + } + } return 0; } @@ -1197,7 +1332,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); @@ -1226,6 +1361,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; @@ -1443,6 +1616,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); } @@ -1484,11 +1662,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); } @@ -1566,12 +1744,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, @@ -1580,6 +1767,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