X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lnet%2Futils%2Fportals.c;h=e50037f002b53213c3d7afa842c24e8577143c49;hb=1a6613ee0bd6628dad994da64d73e313008f696b;hp=1acddcdf4ef8ca6e777a5cb6df1830fb09fe21f7;hpb=3a655f60de084823da81f52d0da2510784b97e4e;p=fs%2Flustre-release.git diff --git a/lnet/utils/portals.c b/lnet/utils/portals.c index 1acddcd..e50037f 100644 --- a/lnet/utils/portals.c +++ b/lnet/utils/portals.c @@ -1,7 +1,7 @@ /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * - * Copyright (C) 2001, 2002 Cluster File Systems, Inc. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * * This file is part of Portals, http://www.sf.net/projects/lustre/ * @@ -20,37 +20,10 @@ * */ -#include -#include -#ifdef HAVE_NETDB_H -#include -#endif -#include -#ifdef HAVE_NETINET_TCP_H -#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 -#endif - -#include +#include #include #include #include -#include "parser.h" unsigned int libcfs_debug; unsigned int libcfs_printk = D_CANTMASK; @@ -59,8 +32,8 @@ static int g_net_set; static __u32 g_net; /* Convert a string boolean to an int; "enable" -> 1 */ -int -lnet_parse_bool (int *b, char *str) +int +lnet_parse_bool (int *b, char *str) { if (!strcasecmp (str, "no") || !strcasecmp (str, "n") || @@ -71,7 +44,7 @@ lnet_parse_bool (int *b, char *str) *b = 0; return (0); } - + if (!strcasecmp (str, "yes") || !strcasecmp (str, "y") || !strcasecmp (str, "on") || @@ -81,7 +54,7 @@ lnet_parse_bool (int *b, char *str) *b = 1; return (0); } - + return (-1); } @@ -89,13 +62,13 @@ int lnet_parse_port (int *port, char *str) { char *end; - + *port = strtol (str, &end, 0); if (*end == 0 && /* parsed whole string */ *port > 0 && *port < 65536) /* minimal sanity check */ return (0); - + return (-1); } @@ -194,41 +167,41 @@ ptl_ipaddr_2_str (__u32 ipaddr, char *str, int lookup) } int -lnet_parse_time (time_t *t, char *str) +lnet_parse_time (time_t *t, char *str) { char *end; int n; struct tm tm; - + *t = strtol (str, &end, 0); if (*end == 0) /* parsed whole string */ return (0); - + memset (&tm, 0, sizeof (tm)); n = sscanf (str, "%d-%d-%d-%d:%d:%d", - &tm.tm_year, &tm.tm_mon, &tm.tm_mday, + &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec); if (n != 6) return (-1); - + tm.tm_mon--; /* convert to 0 == Jan */ tm.tm_year -= 1900; /* y2k quirk */ tm.tm_isdst = -1; /* dunno if it's daylight savings... */ - + *t = mktime (&tm); if (*t == (time_t)-1) return (-1); - + return (0); } -int g_net_is_set (char *cmd) +int g_net_is_set (char *cmd) { if (g_net_set) return 1; - + if (cmd != NULL) - fprintf(stderr, + fprintf(stderr, "You must run the 'network' command before '%s'.\n", cmd); return 0; @@ -251,18 +224,18 @@ int g_net_is_compatible (char *cmd, ...) return 1; } } while (nal != 0); - + va_end (ap); - + if (cmd != NULL) - fprintf (stderr, + fprintf (stderr, "Command %s not compatible with %s NAL\n", - cmd, + cmd, libcfs_lnd2str(LNET_NETTYP(g_net))); return 0; } -int ptl_initialize(int argc, char **argv) +int ptl_initialize(int argc, char **argv) { register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH, LNET_DEV_MAJOR, LNET_DEV_MINOR); @@ -346,7 +319,7 @@ jt_ptl_list_nids(int argc, char **argv) LIBCFS_IOC_INIT (data); data.ioc_count = count; rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_NI, &data); - + if (rc < 0) { if ((count > 0) && (errno == ENOENT)) /* We found them all */ @@ -358,7 +331,7 @@ jt_ptl_list_nids(int argc, char **argv) if (all || (LNET_NETTYP(LNET_NIDNET(data.ioc_nid)) != LOLND)) { printf("%s\n", libcfs_nid2str(data.ioc_nid)); - if (return_nid) { + if (return_nid) { *(__u64 *)(argv[1]) = data.ioc_nid; return_nid--; } @@ -386,7 +359,7 @@ jt_ptl_which_nid (int argc, char **argv) fprintf(stderr, "usage: %s NID [NID...]\n", argv[0]); return 0; } - + for (i = 1; i < argc; i++) { nidstr = argv[i]; nid = libcfs_str2nid(nidstr); @@ -394,10 +367,10 @@ jt_ptl_which_nid (int argc, char **argv) fprintf(stderr, "Can't parse NID %s\n", nidstr); return -1; } - + LIBCFS_IOC_INIT(data); data.ioc_nid = nid; - + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNET_DIST, &data); if (rc != 0) { fprintf(stderr, "Can't get distance to %s: %s\n", @@ -411,12 +384,12 @@ jt_ptl_which_nid (int argc, char **argv) if (dist < 0) { if (dist == -EHOSTUNREACH) continue; - + fprintf(stderr, "Unexpected distance to %s: %d\n", nidstr, dist); return -1; } - + if (best_nid == LNET_NID_ANY || dist < best_dist || (dist == best_dist && order < best_order)) { @@ -430,7 +403,7 @@ jt_ptl_which_nid (int argc, char **argv) fprintf(stderr, "No reachable NID\n"); return -1; } - + printf("%s\n", libcfs_nid2str(best_nid)); return 0; } @@ -450,7 +423,7 @@ jt_ptl_print_interfaces (int argc, char **argv) LIBCFS_IOC_INIT(data); data.ioc_net = g_net; data.ioc_count = index; - + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_INTERFACE, &data); if (rc != 0) break; @@ -546,7 +519,7 @@ jt_ptl_del_interface (int argc, char **argv) fprintf (stderr, "Can't parse ip: %s\n", argv[1]); return -1; } - + LIBCFS_IOC_INIT(data); data.ioc_net = g_net; data.ioc_u32[0] = ipaddr; @@ -578,7 +551,7 @@ jt_ptl_print_peers (int argc, char **argv) LIBCFS_IOC_INIT(data); data.ioc_net = g_net; data.ioc_count = index; - + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER, &data); if (rc != 0) break; @@ -636,7 +609,7 @@ jt_ptl_print_peers (int argc, char **argv) return 0; } -int +int jt_ptl_add_peer (int argc, char **argv) { struct libcfs_ioctl_data data; @@ -645,19 +618,19 @@ jt_ptl_add_peer (int argc, char **argv) int port = 0; int rc; - if (!g_net_is_compatible (argv[0], SOCKLND, RALND, + if (!g_net_is_compatible (argv[0], SOCKLND, RALND, OPENIBLND, CIBLND, IIBLND, VIBLND, 0)) return -1; if (g_net_is_compatible(NULL, SOCKLND, OPENIBLND, CIBLND, RALND, 0)) { if (argc != 4) { - fprintf (stderr, "usage(tcp,openib,cib,ra): %s nid ipaddr port\n", + fprintf (stderr, "usage(tcp,openib,cib,ra): %s nid ipaddr port\n", argv[0]); return 0; } } else if (g_net_is_compatible(NULL, VIBLND, 0)) { if (argc != 3) { - fprintf (stderr, "usage(vib): %s nid ipaddr\n", + fprintf (stderr, "usage(vib): %s nid ipaddr\n", argv[0]); return 0; } @@ -696,11 +669,11 @@ jt_ptl_add_peer (int argc, char **argv) strerror (errno)); return -1; } - + return 0; } -int +int jt_ptl_del_peer (int argc, char **argv) { struct libcfs_ioctl_data data; @@ -730,7 +703,7 @@ jt_ptl_del_peer (int argc, char **argv) fprintf (stderr, "usage: %s [nid]\n", argv[0]); return 0; } - + if (argc > 1 && !libcfs_str2anynid(&nid, argv[1])) { fprintf (stderr, "Can't parse nid: %s\n", argv[1]); @@ -754,7 +727,7 @@ jt_ptl_del_peer (int argc, char **argv) } } } - + LIBCFS_IOC_INIT(data); data.ioc_net = g_net; data.ioc_nid = nid; @@ -767,11 +740,11 @@ jt_ptl_del_peer (int argc, char **argv) strerror (errno)); return -1; } - + return 0; } -int +int jt_ptl_print_connections (int argc, char **argv) { struct libcfs_ioctl_data data; @@ -780,7 +753,7 @@ jt_ptl_print_connections (int argc, char **argv) int index; int rc; - if (!g_net_is_compatible (argv[0], SOCKLND, RALND, + if (!g_net_is_compatible (argv[0], SOCKLND, RALND, MXLND, OPENIBLND, CIBLND, IIBLND, VIBLND, O2IBLND, 0)) return -1; @@ -813,6 +786,10 @@ jt_ptl_print_connections (int argc, char **argv) printf ("%-20s [%d]\n", libcfs_nid2str(data.ioc_nid), data.ioc_u32[0] /* device id */); + } else if (g_net_is_compatible (NULL, O2IBLND, 0)) { + printf ("%s mtu %d\n", + libcfs_nid2str(data.ioc_nid), + data.ioc_u32[0]); /* path MTU */ } else { printf ("%s\n", libcfs_nid2str(data.ioc_nid)); } @@ -863,7 +840,7 @@ int jt_ptl_disconnect(int argc, char **argv) data.ioc_net = g_net; data.ioc_nid = nid; data.ioc_u32[0] = ipaddr; - + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CLOSE_CONNECTION, &data); if (rc != 0) { fprintf(stderr, "failed to remove connection: %s\n", @@ -887,17 +864,17 @@ int jt_ptl_push_connection (int argc, char **argv) if (!g_net_is_compatible (argv[0], SOCKLND, 0)) return -1; - + if (argc > 1 && !libcfs_str2anynid(&nid, argv[1])) { fprintf(stderr, "Can't parse nid: %s\n", argv[1]); return -1; } - + LIBCFS_IOC_INIT(data); data.ioc_net = g_net; data.ioc_nid = nid; - + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_PUSH_CONNECTION, &data); if (rc != 0) { fprintf(stderr, "failed to push connection: %s\n", @@ -908,7 +885,7 @@ int jt_ptl_push_connection (int argc, char **argv) return 0; } -int +int jt_ptl_print_active_txs (int argc, char **argv) { struct libcfs_ioctl_data data; @@ -977,7 +954,7 @@ int jt_ptl_ping(int argc, char **argv) } } else { char *end; - + if (argv[1][0] == 'u' || argv[1][0] == 'U') id.pid = strtoul(&argv[1][1], &end, 0) | LNET_PID_USERFLAG; @@ -985,7 +962,7 @@ int jt_ptl_ping(int argc, char **argv) id.pid = strtoul(argv[1], &end, 0); id.nid = libcfs_str2nid(sep + 1); - + if (end != sep || id.nid == LNET_NID_ANY) { fprintf(stderr, "Can't parse process id \"%s\"\n", argv[1]); @@ -1067,7 +1044,7 @@ jt_ptl_fail_nid (int argc, char **argv) fprintf (stderr, "usage: %s nid|\"*\" [count (0 == mend)]\n", argv[0]); return (0); } - + if (!libcfs_str2anynid(&nid, argv[1])) { fprintf (stderr, "Can't parse nid \"%s\"\n", argv[1]); @@ -1080,18 +1057,18 @@ jt_ptl_fail_nid (int argc, char **argv) fprintf (stderr, "Can't parse count \"%s\"\n", argv[2]); return (-1); } - + LIBCFS_IOC_INIT (data); data.ioc_nid = nid; data.ioc_count = threshold; - + rc = l_ioctl (LNET_DEV_ID, IOC_LIBCFS_FAIL_NID, &data); if (rc < 0) fprintf (stderr, "IOC_LIBCFS_FAIL_NID failed: %s\n", strerror (errno)); else printf ("%s %s\n", threshold == 0 ? "Unfailing" : "Failing", argv[1]); - + return (0); } @@ -1103,7 +1080,7 @@ jt_ptl_add_route (int argc, char **argv) unsigned int hops = 1; char *end; int rc; - + if (argc < 2 || argc > 3) { fprintf (stderr, "usage: %s gateway [hopcount]\n", argv[0]); @@ -1126,7 +1103,7 @@ jt_ptl_add_route (int argc, char **argv) return -1; } } - + LIBCFS_IOC_INIT(data); data.ioc_net = g_net; data.ioc_count = hops; @@ -1137,7 +1114,7 @@ jt_ptl_add_route (int argc, char **argv) fprintf (stderr, "IOC_LIBCFS_ADD_ROUTE failed: %s\n", strerror (errno)); return (-1); } - + return (0); } @@ -1147,7 +1124,7 @@ jt_ptl_del_route (int argc, char **argv) struct libcfs_ioctl_data data; lnet_nid_t nid; int rc; - + if (argc != 2) { fprintf (stderr, "usage: %s gatewayNID\n", argv[0]); return (0); @@ -1165,11 +1142,11 @@ jt_ptl_del_route (int argc, char **argv) rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data); if (rc != 0) { - fprintf (stderr, "IOC_LIBCFS_DEL_ROUTE (%s) failed: %s\n", + fprintf (stderr, "IOC_LIBCFS_DEL_ROUTE (%s) failed: %s\n", libcfs_nid2str(nid), strerror (errno)); return (-1); } - + return (0); } @@ -1202,7 +1179,7 @@ jt_ptl_notify_router (int argc, char **argv) } gettimeofday(&now, NULL); - + if (argc < 4) { when = now.tv_sec; } else if (lnet_parse_time (&when, argv[3]) != 0) { @@ -1221,14 +1198,14 @@ jt_ptl_notify_router (int argc, char **argv) data.ioc_flags = enable; /* Yeuch; 'cept I need a __u64 on 64 bit machines... */ data.ioc_u64[0] = (__u64)when; - + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_NOTIFY_ROUTER, &data); if (rc != 0) { fprintf (stderr, "IOC_LIBCFS_NOTIFY_ROUTER (%s) failed: %s\n", libcfs_nid2str(nid), strerror (errno)); return (-1); } - + return (0); } @@ -1247,7 +1224,7 @@ jt_ptl_print_routes (int argc, char **argv) { LIBCFS_IOC_INIT(data); data.ioc_count = index; - + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data); if (rc != 0) break; @@ -1288,7 +1265,7 @@ lwt_control(int enable, int clear) } static int -lwt_snapshot(cycles_t *now, int *ncpu, int *totalsize, +lwt_snapshot(cycles_t *now, int *ncpu, int *totalsize, lwt_event_t *events, int size) { struct libcfs_ioctl_data data; @@ -1419,7 +1396,7 @@ get_cycles_per_usec () FILE *f = fopen ("/proc/cpuinfo", "r"); double mhz; char line[64]; - + if (f != NULL) { while (fgets (line, sizeof (line), f) != NULL) if (sscanf (line, "cpu MHz : %lf", &mhz) == 1) { @@ -1433,17 +1410,18 @@ get_cycles_per_usec () return (1000.0); } +#define LWT_MAX_CPUS (32) + 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; @@ -1465,7 +1443,7 @@ jt_ptl_lwt(int argc, char **argv) " %s stop [fname]\n", argv[0], argv[0]); return (-1); } - + if (!strcmp(argv[1], "start")) { /* disable */ if (lwt_control(0, 0) != 0) @@ -1481,13 +1459,13 @@ jt_ptl_lwt(int argc, char **argv) return (0); } - + if (lwt_snapshot(NULL, &ncpus, &totalspace, NULL, 0) != 0) return (-1); - if (ncpus > lwt_max_cpus) { - fprintf(stderr, "Too many cpus: %d (%d)\n", - ncpus, lwt_max_cpus); + if (ncpus > LWT_MAX_CPUS) { + fprintf(stderr, "Too many cpus: %d (%d)\n", + ncpus, LWT_MAX_CPUS); return (-1); } @@ -1520,7 +1498,7 @@ jt_ptl_lwt(int argc, char **argv) } mhz = get_cycles_per_usec(); - + /* carve events into per-cpu slices */ nevents_per_cpu = totalspace / (ncpus * sizeof(lwt_event_t)); for (cpu = 0; cpu <= ncpus; cpu++) @@ -1548,17 +1526,17 @@ jt_ptl_lwt(int argc, char **argv) e = first_event[cpu]; if (e == NULL) /* no events this cpu */ continue; - + if (e == cpu_event[cpu]) e = cpu_event[cpu + 1] - 1; - else + else e = e - 1; - + /* If there's an event immediately before the first one, this * cpu wrapped its event buffer */ if (e->lwte_where == NULL) continue; - + /* We should only start outputting events from the most recent * first event in any wrapped cpu. Events before this time on * other cpus won't have any events from this CPU to interleave @@ -1587,20 +1565,20 @@ jt_ptl_lwt(int argc, char **argv) /* no wrapped cpus and this is he first ever event */ t0 = next_event[cpu]->lwte_when; } - + if (t0 <= next_event[cpu]->lwte_when) { /* on or after the first event */ if (!printed_date) { cycles_t du = (tnow - t0) / mhz; time_t then = tvnow.tv_sec - du/1000000; - + if (du % 1000000 > tvnow.tv_usec) then--; fprintf(f, "%s", ctime(&then)); printed_date = 1; } - + rc = lwt_print(f, t0, tlast, mhz, cpu, next_event[cpu]); if (rc != 0) break; @@ -1613,7 +1591,7 @@ jt_ptl_lwt(int argc, char **argv) } tlast = next_event[cpu]->lwte_when; - + next_event[cpu]++; if (next_event[cpu] == cpu_event[cpu + 1]) next_event[cpu] = cpu_event[cpu]; @@ -1640,7 +1618,7 @@ int jt_ptl_memhog(int argc, char **argv) int rc; int count; char *end; - + if (argc < 2) { fprintf(stderr, "usage: %s []\n", argv[0]); return 0; @@ -1660,7 +1638,7 @@ int jt_ptl_memhog(int argc, char **argv) } gfp = rc; } - + LIBCFS_IOC_INIT(data); data.ioc_count = count; data.ioc_flags = gfp; @@ -1670,7 +1648,7 @@ int jt_ptl_memhog(int argc, char **argv) fprintf(stderr, "memhog %d failed: %s\n", count, strerror(errno)); return -1; } - + printf("memhog %d OK\n", count); return 0; }