X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lnet%2Futils%2Fportals.c;h=4efca9845c8e9236bdd53945d20296cbd19fe9e6;hb=4ab1d51e7bbd98006a21a1655f7e5bffec3cf0d4;hp=f8107d8068603fa41ade8ec3e9c4404bb20a81cb;hpb=2dc9c16e770415d56839e1996015fec5fab93f29;p=fs%2Flustre-release.git diff --git a/lnet/utils/portals.c b/lnet/utils/portals.c index f8107d8..4efca98 100644 --- a/lnet/utils/portals.c +++ b/lnet/utils/portals.c @@ -22,33 +22,34 @@ #include #include +#ifdef HAVE_NETDB_H #include +#endif #include +#ifdef HAVE_NETINET_TCP_H #include -#include +#endif #include #include #include +#include "ioctl.h" #include #include #include #include #include #include +#if CRAY_PORTALS +#ifdef REDSTORM +#define __QK__ +#endif +#include +#endif #ifdef __CYGWIN__ #include -#warning assuming little endian - -#define __cpu_to_le64(x) ((__u64)(x)) -#define __le64_to_cpu(x) ((__u64)(x)) -#define __cpu_to_le32(x) ((__u32)(x)) -#define __le32_to_cpu(x) ((__u32)(x)) -#define __cpu_to_le16(x) ((__u16)(x)) -#define __le16_to_cpu(x) ((__u16)(x)) - #endif /* __CYGWIN__ */ #include @@ -60,15 +61,9 @@ unsigned int portal_debug; unsigned int portal_printk; -unsigned int portal_stack; -unsigned int portal_cerror = 1; 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; @@ -77,10 +72,20 @@ typedef struct static name2num_t nalnames[] = { {"any", 0}, +#if !CRAY_PORTALS {"tcp", SOCKNAL}, {"elan", QSWNAL}, {"gm", GMNAL}, - {"ib", IBNAL}, + {"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} }; @@ -220,6 +225,7 @@ nal2name (int nal) return ((e == NULL) ? "???" : e->name); } +#ifdef HAVE_GETHOSTBYNAME static struct hostent * ptl_gethostbyname(char * hname) { struct hostent *he; @@ -232,14 +238,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) @@ -285,20 +292,13 @@ ptl_parse_time (time_t *t, char *str) } int -ptl_parse_ipaddr (__u32 *ipaddrp, char *str) +ptl_parse_ipquad (__u32 *ipaddrp, char *str) { - struct hostent *he; int a; int b; int c; int d; - if (!strcmp (str, "_all_")) - { - *ipaddrp = 0; - return (0); - } - if (sscanf (str, "%d.%d.%d.%d", &a, &b, &c, &d) == 4 && (a & ~0xff) == 0 && (b & ~0xff) == 0 && (c & ~0xff) == 0 && (d & ~0xff) == 0) @@ -306,31 +306,56 @@ ptl_parse_ipaddr (__u32 *ipaddrp, char *str) *ipaddrp = (a<<24)|(b<<16)|(c<<8)|d; return (0); } - + + return (-1); +} + +int +ptl_parse_ipaddr (__u32 *ipaddrp, char *str) +{ +#ifdef HAVE_GETHOSTBYNAME + struct hostent *he; +#endif + + 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); } char * -ptl_ipaddr_2_str (__u32 ipaddr, char *str) +ptl_ipaddr_2_str (__u32 ipaddr, char *str, int lookup) { +#ifdef HAVE_GETHOSTBYNAME __u32 net_ip; struct hostent *he; - - net_ip = htonl (ipaddr); - he = gethostbyaddr (&net_ip, sizeof (net_ip), AF_INET); - if (he != NULL) - return (he->h_name); - + + if (lookup) { + net_ip = htonl (ipaddr); + he = gethostbyaddr (&net_ip, sizeof (net_ip), AF_INET); + if (he != NULL) { + strcpy(str, he->h_name); + return (str); + } + } +#endif + sprintf (str, "%d.%d.%d.%d", (ipaddr >> 24) & 0xff, (ipaddr >> 16) & 0xff, (ipaddr >> 8) & 0xff, ipaddr & 0xff); @@ -344,19 +369,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); } @@ -364,6 +388,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)) { @@ -383,22 +418,24 @@ char * ptl_nid2str (char *buffer, ptl_nid_t nid) { __u64 nid64 = ptl_nid2u64(nid); - struct hostent *he; +#ifdef HAVE_GETHOSTBYNAME + struct hostent *he = 0; - if ((nid64 & ~((__u64)((__u32)-1))) != 0) { - /* top bits set */ - he = NULL; - } else { + /* Don't try to resolve NIDs that are e.g. Elan host IDs. Assume + * TCP addresses in the 0.x.x.x subnet are not in use. This can + * happen on routers and slows things down a _lot_. Bug 3442. */ + 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) - strcpy (buffer, he->h_name); + sprintf(buffer, "%#x:%s", (int)(nid64 >> 32), he->h_name); else - sprintf (buffer, LPX64, nid64); - +#endif /* HAVE_GETHOSTBYNAME */ + sprintf(buffer, LPX64, nid64); + return (buffer); } @@ -521,11 +558,11 @@ int jt_ptl_network(int argc, char **argv) return (-1); } -int -jt_ptl_print_autoconnects (int argc, char **argv) +int +jt_ptl_print_interfaces (int argc, char **argv) { - struct portals_cfg pcfg; - char buffer[64]; + struct portals_cfg pcfg; + char buffer[3][64]; int index; int rc; @@ -533,99 +570,200 @@ jt_ptl_print_autoconnects (int argc, char **argv) return -1; for (index = 0;;index++) { - PCFG_INIT (pcfg, NAL_CMD_GET_AUTOCONN); - pcfg.pcfg_count = index; + PCFG_INIT (pcfg, NAL_CMD_GET_INTERFACE); + pcfg.pcfg_count = index; rc = pcfg_ioctl (&pcfg); if (rc != 0) break; - printf (LPX64"@%s:%d #%d buffer %d " - "nonagle %s affinity %s eager %s share %d\n", - pcfg.pcfg_nid, ptl_ipaddr_2_str (pcfg.pcfg_id, buffer), - pcfg.pcfg_misc, pcfg.pcfg_count, pcfg.pcfg_size, - (pcfg.pcfg_flags & 1) ? "on" : "off", - (pcfg.pcfg_flags & 2) ? "on" : "off", - (pcfg.pcfg_flags & 4) ? "on" : "off", - pcfg.pcfg_wait); + printf ("%s: (%s/%s) npeer %d nroute %d\n", + ptl_ipaddr_2_str(pcfg.pcfg_id, buffer[2], 1), + ptl_ipaddr_2_str(pcfg.pcfg_id, buffer[0], 0), + ptl_ipaddr_2_str(pcfg.pcfg_misc, buffer[1], 0), + pcfg.pcfg_fd, pcfg.pcfg_count); } if (index == 0) - printf ("\n"); + printf ("\n"); return 0; } -int -jt_ptl_add_autoconnect (int argc, char **argv) +int +jt_ptl_add_interface (int argc, char **argv) { - struct portals_cfg pcfg; - ptl_nid_t nid; - __u32 ip; - int port; - int irq_affinity = 0; - int share = 0; - int eager = 0; + struct portals_cfg pcfg; + __u32 ipaddr; int rc; + __u32 netmask = 0xffffff00; + int i; + int count; + char *end; - if (argc < 4 || argc > 5) { - fprintf (stderr, "usage: %s nid ipaddr port [ise]\n", argv[0]); + if (argc < 2 || argc > 3) { + fprintf (stderr, "usage: %s ipaddr [netmask]\n", argv[0]); return 0; } - if (!g_nal_is_compatible (argv[0], SOCKNAL, 0)) + if (!g_nal_is_compatible(argv[0], SOCKNAL, 0)) return -1; - if (ptl_parse_nid (&nid, argv[1]) != 0 || - nid == PTL_NID_ANY) { - fprintf (stderr, "Can't parse NID: %s\n", argv[1]); + if (ptl_parse_ipaddr(&ipaddr, argv[1]) != 0) { + fprintf (stderr, "Can't parse ip: %s\n", argv[1]); return -1; } - if (ptl_parse_ipaddr (&ip, argv[2]) != 0) { - fprintf (stderr, "Can't parse ip addr: %s\n", argv[2]); + 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; + + rc = pcfg_ioctl (&pcfg); + if (rc != 0) { + fprintf (stderr, "failed to add interface: %s\n", + strerror (errno)); return -1; } - if (ptl_parse_port (&port, argv[3]) != 0) { - fprintf (stderr, "Can't parse port: %s\n", argv[3]); + return 0; +} + +int +jt_ptl_del_interface (int argc, char **argv) +{ + struct portals_cfg pcfg; + int rc; + __u32 ipaddr = 0; + + if (argc > 2) { + fprintf (stderr, "usage: %s [ipaddr]\n", argv[0]); + return 0; + } + + if (!g_nal_is_compatible(argv[0], SOCKNAL, 0)) + return -1; + + if (argc == 2 && + ptl_parse_ipaddr(&ipaddr, argv[1]) != 0) { + fprintf (stderr, "Can't parse ip: %s\n", argv[1]); return -1; } + + PCFG_INIT(pcfg, NAL_CMD_DEL_INTERFACE); + pcfg.pcfg_id = ipaddr; - if (argc > 4) { - char *opts = argv[4]; - - while (*opts != 0) - switch (*opts++) { - case 'i': - irq_affinity = 1; - break; - case 's': - share = 1; - break; - case 'e': - eager = 1; - break; - default: - fprintf (stderr, "Can't parse options: %s\n", - argv[4]); - return -1; - } + rc = pcfg_ioctl (&pcfg); + if (rc != 0) { + fprintf (stderr, "failed to delete interface: %s\n", + strerror (errno)); + return -1; + } + + return 0; +} + +int +jt_ptl_print_peers (int argc, char **argv) +{ + struct portals_cfg pcfg; + char buffer[2][64]; + int index; + int rc; + + if (!g_nal_is_compatible (argv[0], SOCKNAL, RANAL, + OPENIBNAL, IIBNAL, VIBNAL, 0)) + return -1; + + for (index = 0;;index++) { + PCFG_INIT (pcfg, NAL_CMD_GET_PEER); + pcfg.pcfg_count = index; + + rc = pcfg_ioctl (&pcfg); + if (rc != 0) + break; + + if (g_nal_is_compatible(NULL, SOCKNAL, 0)) + printf (LPX64"[%d]%s@%s:%d #%d\n", + pcfg.pcfg_nid, pcfg.pcfg_wait, + 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)) + 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); } - PCFG_INIT(pcfg, NAL_CMD_ADD_AUTOCONN); + if (index == 0) + printf ("\n"); + return 0; +} + +int +jt_ptl_add_peer (int argc, char **argv) +{ + struct portals_cfg pcfg; + ptl_nid_t nid; + __u32 ip = 0; + int port = 0; + int rc; + + if (!g_nal_is_compatible (argv[0], SOCKNAL, RANAL, + OPENIBNAL, IIBNAL, VIBNAL, 0)) + return -1; + + if (g_nal_is_compatible(NULL, SOCKNAL, OPENIBNAL, RANAL, 0)) { + if (argc != 4) { + fprintf (stderr, "usage(tcp,openib,ra): %s nid ipaddr port\n", + argv[0]); + return 0; + } + } else if (argc != 2) { + fprintf (stderr, "usage(iib,vib): %s nid\n", argv[0]); + return 0; + } + + if (ptl_parse_nid (&nid, argv[1]) != 0 || + nid == PTL_NID_ANY) { + fprintf (stderr, "Can't parse NID: %s\n", argv[1]); + 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 (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); pcfg.pcfg_nid = nid; pcfg.pcfg_id = ip; pcfg.pcfg_misc = port; - /* only passing one buffer size! */ - pcfg.pcfg_size = MAX (g_socket_rxmem, g_socket_txmem); - pcfg.pcfg_flags = (g_socket_nonagle ? 0x01 : 0) | - (irq_affinity ? 0x02 : 0) | - (share ? 0x04 : 0) | - (eager ? 0x08 : 0); rc = pcfg_ioctl (&pcfg); if (rc != 0) { - fprintf (stderr, "failed to enable autoconnect: %s\n", + fprintf (stderr, "failed to add peer: %s\n", strerror (errno)); return -1; } @@ -634,63 +772,64 @@ jt_ptl_add_autoconnect (int argc, char **argv) } int -jt_ptl_del_autoconnect (int argc, char **argv) +jt_ptl_del_peer (int argc, char **argv) { struct portals_cfg pcfg; ptl_nid_t nid = PTL_NID_ANY; - __u32 ip = 0; - int share = 0; - int keep_conn = 0; + __u32 ip = 0; + int single_share = 0; + int argidx; int rc; - if (argc > 4) { - fprintf (stderr, "usage: %s [nid] [ipaddr] [sk]\n", - argv[0]); - return 0; - } - - if (!g_nal_is_compatible (argv[0], SOCKNAL, 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 (argc > 4) { + fprintf (stderr, "usage: %s [nid] [ipaddr] [single_share]\n", + argv[0]); + return 0; + } + } else if (argc > 3) { + fprintf (stderr, "usage: %s [nid] [single_share]\n", argv[0]); + return 0; + } + 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; } - if (argc > 2 && - ptl_parse_ipaddr (&ip, argv[2]) != 0) { - fprintf (stderr, "Can't parse ip addr: %s\n", argv[2]); - return -1; + argidx = 2; + if (g_nal_is_compatible(NULL, SOCKNAL, 0)) { + if (argc > argidx && + ptl_parse_ipaddr (&ip, argv[argidx]) != 0) { + fprintf (stderr, "Can't parse ip addr: %s\n", + argv[argidx]); + return -1; + } + argidx++; } - - if (argc > 3) { - char *opts = argv[3]; - - while (*opts != 0) - switch (*opts++) { - case 's': - share = 1; - break; - case 'k': - keep_conn = 1; - break; - default: - fprintf (stderr, "Can't parse flags: %s\n", - argv[3]); - return -1; - } + + if (argc > argidx) { + if (!strcmp (argv[argidx], "single_share")) { + single_share = 1; + } else { + fprintf (stderr, "Unrecognised arg %s'\n", argv[3]); + return -1; + } } - PCFG_INIT(pcfg, NAL_CMD_DEL_AUTOCONN); - pcfg.pcfg_nid = nid; - pcfg.pcfg_id = ip; - pcfg.pcfg_flags = (share ? 1 : 0) | - (keep_conn ? 2 : 0); + PCFG_INIT(pcfg, NAL_CMD_DEL_PEER); + pcfg.pcfg_nid = nid; + pcfg.pcfg_id = ip; + pcfg.pcfg_flags = single_share; rc = pcfg_ioctl (&pcfg); if (rc != 0) { - fprintf (stderr, "failed to remove autoconnect route: %s\n", + fprintf (stderr, "failed to remove peer: %s\n", strerror (errno)); return -1; } @@ -702,11 +841,12 @@ int jt_ptl_print_connections (int argc, char **argv) { struct portals_cfg pcfg; - char buffer[64]; + char buffer[2][64]; int index; int rc; - if (!g_nal_is_compatible (argv[0], SOCKNAL, 0)) + if (!g_nal_is_compatible (argv[0], SOCKNAL, RANAL, + OPENIBNAL, IIBNAL, VIBNAL, 0)) return -1; for (index = 0;;index++) { @@ -717,14 +857,27 @@ jt_ptl_print_connections (int argc, char **argv) if (rc != 0) break; - printf (LPX64"@%s:%d:%s\n", - pcfg.pcfg_nid, - ptl_ipaddr_2_str (pcfg.pcfg_id, buffer), - pcfg.pcfg_misc, - (pcfg.pcfg_flags == SOCKNAL_CONN_ANY) ? "A" : - (pcfg.pcfg_flags == SOCKNAL_CONN_CONTROL) ? "C" : - (pcfg.pcfg_flags == SOCKNAL_CONN_BULK_IN) ? "I" : - (pcfg.pcfg_flags == SOCKNAL_CONN_BULK_OUT) ? "O" : "?"); + if (g_nal_is_compatible (NULL, SOCKNAL, 0)) + printf ("[%d]%s:"LPX64"@%s:%d:%s %d/%d %s\n", + pcfg.pcfg_gw_nal, /* scheduler */ + ptl_ipaddr_2_str (pcfg.pcfg_fd, buffer[0], 1), /* local IP addr */ + pcfg.pcfg_nid, + ptl_ipaddr_2_str (pcfg.pcfg_id, buffer[1], 1), /* remote IP addr */ + pcfg.pcfg_misc, /* remote port */ + (pcfg.pcfg_flags == SOCKNAL_CONN_ANY) ? "A" : + (pcfg.pcfg_flags == SOCKNAL_CONN_CONTROL) ? "C" : + (pcfg.pcfg_flags == SOCKNAL_CONN_BULK_IN) ? "I" : + (pcfg.pcfg_flags == SOCKNAL_CONN_BULK_OUT) ? "O" : "?", + 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) @@ -734,22 +887,22 @@ jt_ptl_print_connections (int argc, char **argv) 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 nonagle = 0; - int rxmem = 0; - int txmem = 0; - int bind_irq = 0; int type = SOCKNAL_CONN_ANY; - int port; + int port, rport; int o; - int olen; if (argc < 3) { - fprintf(stderr, "usage: %s ip port [xibctr]\n", argv[0]); + fprintf(stderr, "usage: %s ip port [type]\n", argv[0]); return 0; } @@ -771,10 +924,6 @@ int jt_ptl_connect(int argc, char **argv) for (flag = argv[3]; *flag != 0; flag++) switch (*flag) { - case 'i': - bind_irq = 1; - break; - case 'I': if (type != SOCKNAL_CONN_ANY) { fprintf(stderr, "Can't flag type twice\n"); @@ -805,60 +954,53 @@ 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; - } - - if (g_socket_nonagle) - { - o = 1; - if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &o, sizeof (o)) != 0) { - fprintf(stderr, "cannot disable nagle: %s\n", strerror(errno)); - return (-1); - } - } - if (g_socket_rxmem != 0) { - o = g_socket_rxmem; - if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &o, sizeof (o)) != 0) { - fprintf(stderr, "cannot set receive buffer size: %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; } - } - if (g_socket_txmem != 0) { - o = g_socket_txmem; - if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &o, sizeof (o)) != 0) { - fprintf(stderr, "cannot set send buffer size: %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; } - olen = sizeof (txmem); - if (getsockopt (fd, SOL_SOCKET, SO_SNDBUF, &txmem, &olen) != 0) - fprintf (stderr, "Can't get send buffer size: %s\n", strerror (errno)); - olen = sizeof (rxmem); - if (getsockopt (fd, SOL_SOCKET, SO_RCVBUF, &rxmem, &olen) != 0) - fprintf (stderr, "Can't get receive buffer size: %s\n", strerror (errno)); - olen = sizeof (nonagle); - if (getsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &nonagle, &olen) != 0) - fprintf (stderr, "Can't get nagle: %s\n", strerror (errno)); - - printf("Connected host: %s snd: %d rcv: %d nagle: %s type: %s\n", - argv[1], txmem, rxmem, nonagle ? "Disabled" : "Enabled", + printf("Connected host: %s type: %s\n", + argv[1], (type == SOCKNAL_CONN_ANY) ? "A" : (type == SOCKNAL_CONN_CONTROL) ? "C" : (type == SOCKNAL_CONN_BULK_IN) ? "I" : @@ -867,7 +1009,6 @@ int jt_ptl_connect(int argc, char **argv) PCFG_INIT(pcfg, NAL_CMD_REGISTER_PEER_FD); pcfg.pcfg_nal = g_nal; pcfg.pcfg_fd = fd; - pcfg.pcfg_flags = bind_irq; pcfg.pcfg_misc = type; rc = pcfg_ioctl(&pcfg); @@ -885,11 +1026,12 @@ 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) { - struct portals_cfg pcfg; + struct portals_cfg pcfg; ptl_nid_t nid = PTL_NID_ANY; __u32 ipaddr = 0; int rc; @@ -899,16 +1041,18 @@ int jt_ptl_disconnect(int argc, char **argv) return 0; } - if (!g_nal_is_compatible (NULL, SOCKNAL, 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; } - if (argc >= 3 && + if (g_nal_is_compatible (NULL, SOCKNAL, 0) && + argc >= 3 && ptl_parse_ipaddr (&ipaddr, argv[2]) != 0) { fprintf (stderr, "Can't parse ip addr %s\n", argv[2]); return -1; @@ -930,7 +1074,7 @@ int jt_ptl_disconnect(int argc, char **argv) int jt_ptl_push_connection (int argc, char **argv) { - struct portals_cfg pcfg; + struct portals_cfg pcfg; int rc; ptl_nid_t nid = PTL_NID_ANY; __u32 ipaddr = 0; @@ -944,7 +1088,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; } @@ -971,7 +1115,7 @@ int jt_ptl_push_connection (int argc, char **argv) int jt_ptl_print_active_txs (int argc, char **argv) { - struct portals_cfg pcfg; + struct portals_cfg pcfg; int index; int rc; @@ -1151,7 +1295,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); @@ -1180,61 +1324,6 @@ jt_ptl_fail_nid (int argc, char **argv) } int -jt_ptl_rxmem (int argc, char **argv) -{ - int size; - - if (argc > 1) - { - if (ptl_parse_size (&size, argv[1]) != 0 || size < 0) - { - fprintf (stderr, "Can't parse size %s\n", argv[1]); - return (0); - } - - g_socket_rxmem = size; - } - printf ("Socket rmem = %d\n", g_socket_rxmem); - return (0); -} - -int -jt_ptl_txmem (int argc, char **argv) -{ - int size; - - if (argc > 1) - { - if (ptl_parse_size (&size, argv[1]) != 0 || size < 0) - { - fprintf (stderr, "Can't parse size %s\n", argv[1]); - return (0); - } - g_socket_txmem = size; - } - printf ("Socket txmem = %d\n", g_socket_txmem); - return (0); -} - -int -jt_ptl_nagle (int argc, char **argv) -{ - int enable; - - if (argc > 1) - { - if (ptl_parse_bool (&enable, argv[1]) != 0) - { - fprintf (stderr, "Can't parse boolean %s\n", argv[1]); - return (-1); - } - g_socket_nonagle = !enable; - } - printf ("Nagle %s\n", g_socket_nonagle ? "disabled" : "enabled"); - return (0); -} - -int jt_ptl_add_route (int argc, char **argv) { struct portals_cfg pcfg; @@ -1492,9 +1581,19 @@ lwt_snapshot(cycles_t *now, int *ncpu, int *totalsize, return (-1); } + /* crappy overloads */ + 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_nid2, sizeof(lwt_event_t), + (int)data.ioc_nid3, + (int)offsetof(lwt_event_t, lwte_where)); + return (-1); + } + LASSERT (data.ioc_count != 0); LASSERT (data.ioc_misc != 0); - + if (now != NULL) *now = data.ioc_nid; @@ -1565,12 +1664,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, @@ -1579,6 +1687,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 @@ -1604,13 +1713,14 @@ get_cycles_per_usec () int jt_ptl_lwt(int argc, char **argv) { + const int lwt_max_cpus = 32; int ncpus; int totalspace; int nevents_per_cpu; lwt_event_t *events; - lwt_event_t *cpu_event[LWT_MAX_CPUS + 1]; - lwt_event_t *next_event[LWT_MAX_CPUS]; - lwt_event_t *first_event[LWT_MAX_CPUS]; + lwt_event_t *cpu_event[lwt_max_cpus + 1]; + lwt_event_t *next_event[lwt_max_cpus]; + lwt_event_t *first_event[lwt_max_cpus]; int cpu; lwt_event_t *e; int rc; @@ -1652,9 +1762,9 @@ jt_ptl_lwt(int argc, char **argv) if (lwt_snapshot(NULL, &ncpus, &totalspace, NULL, 0) != 0) return (-1); - if (ncpus > LWT_MAX_CPUS) { + if (ncpus > lwt_max_cpus) { fprintf(stderr, "Too many cpus: %d (%d)\n", - ncpus, LWT_MAX_CPUS); + ncpus, lwt_max_cpus); return (-1); }