2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
4 * This file is part of Portals, http://www.sf.net/projects/lustre/
6 * Portals is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
10 * Portals is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Portals; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <libcfs/libcfsutil.h>
22 #include <lnet/api-support.h>
23 #include <lnet/lnetctl.h>
24 #include <lnet/socklnd.h>
26 unsigned int libcfs_debug;
27 unsigned int libcfs_printk = D_CANTMASK;
32 /* Convert a string boolean to an int; "enable" -> 1 */
34 lnet_parse_bool (int *b, char *str)
36 if (!strcasecmp (str, "no") ||
37 !strcasecmp (str, "n") ||
38 !strcasecmp (str, "off") ||
39 !strcasecmp (str, "down") ||
40 !strcasecmp (str, "disable"))
46 if (!strcasecmp (str, "yes") ||
47 !strcasecmp (str, "y") ||
48 !strcasecmp (str, "on") ||
49 !strcasecmp (str, "up") ||
50 !strcasecmp (str, "enable"))
60 lnet_parse_port (int *port, char *str)
64 *port = strtol (str, &end, 0);
66 if (*end == 0 && /* parsed whole string */
67 *port > 0 && *port < 65536) /* minimal sanity check */
73 #ifdef HAVE_GETHOSTBYNAME
74 static struct hostent *
75 ptl_gethostbyname(char * hname) {
77 he = gethostbyname(hname);
82 fprintf(stderr, "Unable to resolve hostname: %s\n",
86 fprintf(stderr, "gethostbyname error for %s: %s\n",
87 hname, strerror(h_errno));
97 lnet_parse_ipquad (__u32 *ipaddrp, char *str)
104 if (sscanf (str, "%d.%d.%d.%d", &a, &b, &c, &d) == 4 &&
105 (a & ~0xff) == 0 && (b & ~0xff) == 0 &&
106 (c & ~0xff) == 0 && (d & ~0xff) == 0)
108 *ipaddrp = (a<<24)|(b<<16)|(c<<8)|d;
116 lnet_parse_ipaddr (__u32 *ipaddrp, char *str)
118 #ifdef HAVE_GETHOSTBYNAME
122 if (!strcmp (str, "_all_")) {
127 if (lnet_parse_ipquad(ipaddrp, str) == 0)
130 #ifdef HAVE_GETHOSTBYNAME
131 if ((('a' <= str[0] && str[0] <= 'z') ||
132 ('A' <= str[0] && str[0] <= 'Z')) &&
133 (he = ptl_gethostbyname (str)) != NULL) {
134 __u32 addr = *(__u32 *)he->h_addr;
136 *ipaddrp = ntohl(addr); /* HOST byte order */
145 ptl_ipaddr_2_str(__u32 ipaddr, char *str, size_t strsize, int lookup)
147 #ifdef HAVE_GETHOSTBYNAME
152 net_ip = htonl (ipaddr);
153 he = gethostbyaddr (&net_ip, sizeof (net_ip), AF_INET);
155 strlcpy(str, he->h_name, strsize);
161 sprintf (str, "%d.%d.%d.%d",
162 (ipaddr >> 24) & 0xff, (ipaddr >> 16) & 0xff,
163 (ipaddr >> 8) & 0xff, ipaddr & 0xff);
168 lnet_parse_time (time_t *t, char *str)
174 *t = strtol (str, &end, 0);
175 if (*end == 0) /* parsed whole string */
178 memset (&tm, 0, sizeof (tm));
179 n = sscanf (str, "%d-%d-%d-%d:%d:%d",
180 &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
181 &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
185 tm.tm_mon--; /* convert to 0 == Jan */
186 tm.tm_year -= 1900; /* y2k quirk */
187 tm.tm_isdst = -1; /* dunno if it's daylight savings... */
190 if (*t == (time_t)-1)
197 lnet_parse_nid(char *nid_str, lnet_process_id_t *id_ptr)
199 id_ptr->pid = LNET_PID_ANY;
200 id_ptr->nid = libcfs_str2nid(nid_str);
201 if (id_ptr->nid == LNET_NID_ANY) {
202 fprintf (stderr, "Can't parse nid \"%s\"\n", nid_str);
209 int g_net_is_set (char *cmd)
216 "You must run the 'network' command before '%s'.\n",
221 int g_net_is_compatible (char *cmd, ...)
226 if (!g_net_is_set(cmd))
232 nal = va_arg (ap, int);
233 if (nal == LNET_NETTYP(g_net)) {
243 "Command %s not compatible with %s NAL\n",
245 libcfs_lnd2str(LNET_NETTYP(g_net)));
249 int ptl_initialize(int argc, char **argv)
251 register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH,
252 LNET_DEV_MAJOR, LNET_DEV_MINOR);
257 int jt_ptl_network(int argc, char **argv)
259 struct libcfs_ioctl_data data;
260 __u32 net = LNET_NIDNET(LNET_NID_ANY);
264 fprintf(stderr, "usage: %s <net>|up|down\n", argv[0]);
268 if (!strcmp(argv[1], "unconfigure") ||
269 !strcmp(argv[1], "down")) {
270 LIBCFS_IOC_INIT(data);
271 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_UNCONFIGURE, &data);
274 printf ("LNET ready to unload\n");
279 fprintf(stderr, "LNET busy\n");
281 fprintf(stderr, "LNET unconfigure error %d: %s\n",
282 errno, strerror(errno));
286 if (!strcmp(argv[1], "configure") ||
287 !strcmp(argv[1], "up")) {
288 LIBCFS_IOC_INIT(data);
289 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIGURE, &data);
292 printf ("LNET configured\n");
296 fprintf(stderr, "LNET configure error %d: %s\n",
297 errno, strerror(errno));
301 net = libcfs_str2net(argv[1]);
302 if (net == LNET_NIDNET(LNET_NID_ANY)) {
303 fprintf(stderr, "Can't parse net %s\n", argv[1]);
307 if (LNET_NETTYP(net) == CIBLND ||
308 LNET_NETTYP(net) == OPENIBLND ||
309 LNET_NETTYP(net) == IIBLND ||
310 LNET_NETTYP(net) == VIBLND) {
311 fprintf(stderr, "Net %s obsoleted\n", libcfs_lnd2str(net));
321 jt_ptl_list_nids(int argc, char **argv)
323 struct libcfs_ioctl_data data;
324 int all = 0, return_nid = 0;
328 all = (argc == 2) && (strcmp(argv[1], "all") == 0);
329 /* Hack to pass back value */
330 return_nid = (argc == 2) && (argv[1][0] == 1);
332 if ((argc > 2) && !(all || return_nid)) {
333 fprintf(stderr, "usage: %s [all]\n", argv[0]);
337 for (count = 0;; count++) {
338 LIBCFS_IOC_INIT (data);
339 data.ioc_count = count;
340 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_NI, &data);
343 if ((count > 0) && (errno == ENOENT))
344 /* We found them all */
346 fprintf(stderr,"IOC_LIBCFS_GET_NI error %d: %s\n",
347 errno, strerror(errno));
351 if (all || (LNET_NETTYP(LNET_NIDNET(data.ioc_nid)) != LOLND)) {
352 printf("%s\n", libcfs_nid2str(data.ioc_nid));
354 *(__u64 *)(argv[1]) = data.ioc_nid;
364 jt_ptl_which_nid (int argc, char **argv)
366 struct libcfs_ioctl_data data;
369 lnet_nid_t best_nid = LNET_NID_ANY;
378 fprintf(stderr, "usage: %s NID [NID...]\n", argv[0]);
382 for (i = 1; i < argc; i++) {
384 nid = libcfs_str2nid(nidstr);
385 if (nid == LNET_NID_ANY) {
386 fprintf(stderr, "Can't parse NID %s\n", nidstr);
390 LIBCFS_IOC_INIT(data);
393 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNET_DIST, &data);
395 fprintf(stderr, "Can't get distance to %s: %s\n",
396 nidstr, strerror(errno));
400 dist = data.ioc_u32[0];
401 order = data.ioc_u32[1];
404 if (dist == -EHOSTUNREACH)
407 fprintf(stderr, "Unexpected distance to %s: %d\n",
412 if (best_nid == LNET_NID_ANY ||
414 (dist == best_dist && order < best_order)) {
421 if (best_nid == LNET_NID_ANY) {
422 fprintf(stderr, "No reachable NID\n");
426 printf("%s\n", libcfs_nid2str(best_nid));
431 jt_ptl_print_interfaces (int argc, char **argv)
433 struct libcfs_ioctl_data data;
434 char buffer[3][HOST_NAME_MAX + 1];
438 if (!g_net_is_compatible (argv[0], SOCKLND, 0))
441 for (index = 0;;index++) {
442 LIBCFS_IOC_INIT(data);
443 data.ioc_net = g_net;
444 data.ioc_count = index;
446 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_INTERFACE, &data);
450 printf ("%s: (%s/%s) npeer %d nroute %d\n",
451 ptl_ipaddr_2_str(data.ioc_u32[0], buffer[2],
452 sizeof(buffer[2]), 1),
453 ptl_ipaddr_2_str(data.ioc_u32[0], buffer[0],
454 sizeof(buffer[0]), 0),
455 ptl_ipaddr_2_str(data.ioc_u32[1], buffer[1],
456 sizeof(buffer[1]), 0),
457 data.ioc_u32[2], data.ioc_u32[3]);
461 if (errno == ENOENT) {
462 printf ("<no interfaces>\n");
464 fprintf(stderr, "Error getting interfaces: %s: "
474 jt_ptl_add_interface (int argc, char **argv)
476 struct libcfs_ioctl_data data;
479 __u32 netmask = 0xffffff00;
484 if (argc < 2 || argc > 3) {
485 fprintf (stderr, "usage: %s ipaddr [netmask]\n", argv[0]);
489 if (!g_net_is_compatible(argv[0], SOCKLND, 0))
492 if (lnet_parse_ipaddr(&ipaddr, argv[1]) != 0) {
493 fprintf (stderr, "Can't parse ip: %s\n", argv[1]);
498 count = strtol(argv[2], &end, 0);
499 if (count > 0 && count < 32 && *end == 0) {
501 for (i = count; i > 0; i--)
502 netmask = netmask|(1<<(32-i));
503 } else if (lnet_parse_ipquad(&netmask, argv[2]) != 0) {
504 fprintf (stderr, "Can't parse netmask: %s\n", argv[2]);
509 LIBCFS_IOC_INIT(data);
510 data.ioc_net = g_net;
511 data.ioc_u32[0] = ipaddr;
512 data.ioc_u32[1] = netmask;
514 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_INTERFACE, &data);
516 fprintf (stderr, "failed to add interface: %s\n",
525 jt_ptl_del_interface (int argc, char **argv)
527 struct libcfs_ioctl_data data;
532 fprintf (stderr, "usage: %s [ipaddr]\n", argv[0]);
536 if (!g_net_is_compatible(argv[0], SOCKLND, 0))
540 lnet_parse_ipaddr(&ipaddr, argv[1]) != 0) {
541 fprintf (stderr, "Can't parse ip: %s\n", argv[1]);
545 LIBCFS_IOC_INIT(data);
546 data.ioc_net = g_net;
547 data.ioc_u32[0] = ipaddr;
549 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_INTERFACE, &data);
551 fprintf (stderr, "failed to delete interface: %s\n",
560 jt_ptl_print_peers (int argc, char **argv)
562 struct libcfs_ioctl_data data;
563 lnet_process_id_t id;
564 char buffer[2][HOST_NAME_MAX + 1];
568 if (!g_net_is_compatible (argv[0], SOCKLND, RALND, MXLND,
572 for (index = 0;;index++) {
573 LIBCFS_IOC_INIT(data);
574 data.ioc_net = g_net;
575 data.ioc_count = index;
577 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER, &data);
581 if (g_net_is_compatible(NULL, SOCKLND, 0)) {
582 id.nid = data.ioc_nid;
583 id.pid = data.ioc_u32[4];
584 printf ("%-20s [%d]%s->%s:%d #%d\n",
586 data.ioc_count, /* persistence */
588 ptl_ipaddr_2_str(data.ioc_u32[2], buffer[0],
589 sizeof(buffer[0]), 1),
591 ptl_ipaddr_2_str(data.ioc_u32[0], buffer[1],
592 sizeof(buffer[1]), 1),
593 data.ioc_u32[1], /* peer port */
594 data.ioc_u32[3]); /* conn_count */
595 } else if (g_net_is_compatible(NULL, RALND, 0)) {
596 printf ("%-20s [%d]@%s:%d\n",
597 libcfs_nid2str(data.ioc_nid), /* peer nid */
598 data.ioc_count, /* peer persistence */
600 ptl_ipaddr_2_str(data.ioc_u32[0], buffer[1],
601 sizeof(buffer[1]), 1),
602 data.ioc_u32[1]); /* peer port */
603 } else if (g_net_is_compatible(NULL, GNILND, 0)) {
604 int disconn = data.ioc_flags >> 16;
610 state = data.ioc_flags & 0xffff ? "C" : "U";
612 printf ("%-20s (%d) %s [%d] "LPU64" "
613 "sq %d/%d tx %d/%d/%d\n",
614 libcfs_nid2str(data.ioc_nid), /* peer nid */
615 data.ioc_net, /* gemini device id */
616 state, /* peer is Connecting, Up, or Down */
617 data.ioc_count, /* peer refcount */
618 data.ioc_u64[0], /* peerstamp */
619 data.ioc_u32[2], data.ioc_u32[3], /* tx and rx seq */
620 /* fmaq, nfma, nrdma */
621 data.ioc_u32[0], data.ioc_u32[1], data.ioc_u32[4]
624 printf ("%-20s [%d]\n",
625 libcfs_nid2str(data.ioc_nid), data.ioc_count);
630 if (errno == ENOENT) {
631 printf ("<no peers>\n");
633 fprintf(stderr, "Error getting peer list: %s: "
642 jt_ptl_add_peer (int argc, char **argv)
644 struct libcfs_ioctl_data data;
650 if (!g_net_is_compatible (argv[0], SOCKLND, RALND,
655 fprintf (stderr, "usage(tcp,ra,gni): %s nid ipaddr port\n",
660 nid = libcfs_str2nid(argv[1]);
661 if (nid == LNET_NID_ANY) {
662 fprintf (stderr, "Can't parse NID: %s\n", argv[1]);
666 if (lnet_parse_ipaddr (&ip, argv[2]) != 0) {
667 fprintf (stderr, "Can't parse ip addr: %s\n", argv[2]);
671 if (lnet_parse_port (&port, argv[3]) != 0) {
672 fprintf (stderr, "Can't parse port: %s\n", argv[3]);
676 LIBCFS_IOC_INIT(data);
677 data.ioc_net = g_net;
679 data.ioc_u32[0] = ip;
680 data.ioc_u32[1] = port;
682 rc = l_ioctl (LNET_DEV_ID, IOC_LIBCFS_ADD_PEER, &data);
684 fprintf (stderr, "failed to add peer: %s\n",
693 jt_ptl_del_peer (int argc, char **argv)
695 struct libcfs_ioctl_data data;
696 lnet_nid_t nid = LNET_NID_ANY;
697 lnet_pid_t pid = LNET_PID_ANY;
701 if (!g_net_is_compatible (argv[0], SOCKLND, RALND, MXLND,
705 if (g_net_is_compatible(NULL, SOCKLND, 0)) {
707 fprintf (stderr, "usage: %s [nid] [ipaddr]\n",
711 } else if (argc > 2) {
712 fprintf (stderr, "usage: %s [nid]\n", argv[0]);
717 !libcfs_str2anynid(&nid, argv[1])) {
718 fprintf (stderr, "Can't parse nid: %s\n", argv[1]);
722 if (g_net_is_compatible(NULL, SOCKLND, 0)) {
724 lnet_parse_ipaddr (&ip, argv[2]) != 0) {
725 fprintf (stderr, "Can't parse ip addr: %s\n",
731 LIBCFS_IOC_INIT(data);
732 data.ioc_net = g_net;
734 data.ioc_u32[0] = ip;
735 data.ioc_u32[1] = pid;
737 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_PEER, &data);
739 fprintf (stderr, "failed to remove peer: %s\n",
748 jt_ptl_print_connections (int argc, char **argv)
750 struct libcfs_ioctl_data data;
751 lnet_process_id_t id;
752 char buffer[2][HOST_NAME_MAX + 1];
756 if (!g_net_is_compatible (argv[0], SOCKLND, RALND, MXLND, O2IBLND,
760 for (index = 0; ; index++) {
761 LIBCFS_IOC_INIT(data);
762 data.ioc_net = g_net;
763 data.ioc_count = index;
765 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_CONN, &data);
769 if (g_net_is_compatible (NULL, SOCKLND, 0)) {
770 id.nid = data.ioc_nid;
771 id.pid = data.ioc_u32[6];
772 printf ("%-20s %s[%d]%s->%s:%d %d/%d %s\n",
774 (data.ioc_u32[3] == SOCKLND_CONN_ANY) ? "A" :
775 (data.ioc_u32[3] == SOCKLND_CONN_CONTROL) ? "C" :
776 (data.ioc_u32[3] == SOCKLND_CONN_BULK_IN) ? "I" :
777 (data.ioc_u32[3] == SOCKLND_CONN_BULK_OUT) ? "O" : "?",
778 data.ioc_u32[4], /* scheduler */
780 ptl_ipaddr_2_str(data.ioc_u32[2], buffer[0],
781 sizeof(buffer[0]), 1),
783 ptl_ipaddr_2_str(data.ioc_u32[0], buffer[1],
784 sizeof(buffer[1]), 1),
785 data.ioc_u32[1], /* remote port */
786 data.ioc_count, /* tx buffer size */
787 data.ioc_u32[5], /* rx buffer size */
788 data.ioc_flags ? "nagle" : "nonagle");
789 } else if (g_net_is_compatible (NULL, RALND, 0)) {
790 printf ("%-20s [%d]\n",
791 libcfs_nid2str(data.ioc_nid),
792 data.ioc_u32[0] /* device id */);
793 } else if (g_net_is_compatible (NULL, O2IBLND, 0)) {
794 printf ("%s mtu %d\n",
795 libcfs_nid2str(data.ioc_nid),
796 data.ioc_u32[0]); /* path MTU */
797 } else if (g_net_is_compatible (NULL, GNILND, 0)) {
798 printf ("%-20s [%d]\n",
799 libcfs_nid2str(data.ioc_nid),
800 data.ioc_u32[0] /* device id */);
802 printf ("%s\n", libcfs_nid2str(data.ioc_nid));
807 if (errno == ENOENT) {
808 printf ("<no connections>\n");
810 fprintf(stderr, "Error getting connection list: %s: "
818 int jt_ptl_disconnect(int argc, char **argv)
820 struct libcfs_ioctl_data data;
821 lnet_nid_t nid = LNET_NID_ANY;
826 fprintf(stderr, "usage: %s [nid] [ipaddr]\n", argv[0]);
830 if (!g_net_is_compatible (NULL, SOCKLND, RALND, MXLND, O2IBLND,
835 !libcfs_str2anynid(&nid, argv[1])) {
836 fprintf (stderr, "Can't parse nid %s\n", argv[1]);
840 if (g_net_is_compatible (NULL, SOCKLND, 0) &&
842 lnet_parse_ipaddr (&ipaddr, argv[2]) != 0) {
843 fprintf (stderr, "Can't parse ip addr %s\n", argv[2]);
847 LIBCFS_IOC_INIT(data);
848 data.ioc_net = g_net;
850 data.ioc_u32[0] = ipaddr;
852 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CLOSE_CONNECTION, &data);
854 fprintf(stderr, "failed to remove connection: %s\n",
862 int jt_ptl_push_connection (int argc, char **argv)
864 struct libcfs_ioctl_data data;
866 lnet_nid_t nid = LNET_NID_ANY;
869 fprintf(stderr, "usage: %s [nid]\n", argv[0]);
873 if (!g_net_is_compatible (argv[0], SOCKLND, GNILND, 0))
877 !libcfs_str2anynid(&nid, argv[1])) {
878 fprintf(stderr, "Can't parse nid: %s\n", argv[1]);
882 LIBCFS_IOC_INIT(data);
883 data.ioc_net = g_net;
886 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_PUSH_CONNECTION, &data);
888 fprintf(stderr, "failed to push connection: %s\n",
897 jt_ptl_print_active_txs (int argc, char **argv)
899 struct libcfs_ioctl_data data;
903 if (!g_net_is_compatible (argv[0], QSWLND, 0))
906 for (index = 0;;index++) {
907 LIBCFS_IOC_INIT(data);
908 data.ioc_net = g_net;
909 data.ioc_count = index;
911 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_TXDESC, &data);
915 printf ("type %u payload %6d to %s via %s by pid %6d: "
916 "%s, %s, state %d\n",
919 libcfs_nid2str(data.ioc_nid),
920 libcfs_nid2str(data.ioc_u64[0]),
922 (data.ioc_flags & 1) ? "delayed" : "immediate",
923 (data.ioc_flags & 2) ? "nblk" : "normal",
924 data.ioc_flags >> 2);
928 if (errno == ENOENT) {
929 printf ("<no active descs>\n");
931 fprintf(stderr, "Error getting active transmits list: "
932 "%s: check dmesg.\n",
939 int jt_ptl_ping(int argc, char **argv)
943 lnet_process_id_t id;
944 lnet_process_id_t ids[16];
945 int maxids = sizeof(ids)/sizeof(ids[0]);
946 struct libcfs_ioctl_data data;
951 fprintf(stderr, "usage: %s id [timeout (secs)]\n", argv[0]);
955 sep = strchr(argv[1], '-');
957 rc = lnet_parse_nid(argv[1], &id);
963 if (argv[1][0] == 'u' ||
965 id.pid = strtoul(&argv[1][1], &end, 0) | LNET_PID_USERFLAG;
967 id.pid = strtoul(argv[1], &end, 0);
969 if (end != sep) { /* assuming '-' is part of hostname */
970 rc = lnet_parse_nid(argv[1], &id);
974 id.nid = libcfs_str2nid(sep + 1);
976 if (id.nid == LNET_NID_ANY) {
978 "Can't parse process id \"%s\"\n",
986 timeout = 1000 * atol(argv[2]);
988 timeout = 1000; /* default 1 second timeout */
990 LIBCFS_IOC_INIT (data);
991 data.ioc_nid = id.nid;
992 data.ioc_u32[0] = id.pid;
993 data.ioc_u32[1] = timeout;
994 data.ioc_plen1 = sizeof(ids);
995 data.ioc_pbuf1 = (char *)ids;
997 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_PING, &data);
999 fprintf(stderr, "failed to ping %s: %s\n",
1000 id.pid == LNET_PID_ANY ?
1001 libcfs_nid2str(id.nid) : libcfs_id2str(id),
1006 for (i = 0; i < data.ioc_count && i < maxids; i++)
1007 printf("%s\n", libcfs_id2str(ids[i]));
1009 if (data.ioc_count > maxids)
1010 printf("%d out of %d ids listed\n", maxids, data.ioc_count);
1015 int jt_ptl_mynid(int argc, char **argv)
1017 struct libcfs_ioctl_data data;
1022 fprintf(stderr, "usage: %s NID\n", argv[0]);
1026 nid = libcfs_str2nid(argv[1]);
1027 if (nid == LNET_NID_ANY) {
1028 fprintf(stderr, "Can't parse NID '%s'\n", argv[1]);
1032 LIBCFS_IOC_INIT(data);
1033 data.ioc_net = LNET_NIDNET(nid);
1036 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_REGISTER_MYNID, &data);
1038 fprintf(stderr, "setting my NID failed: %s\n",
1041 printf("registered my nid %s\n", libcfs_nid2str(nid));
1047 jt_ptl_fail_nid (int argc, char **argv)
1052 struct libcfs_ioctl_data data;
1054 if (argc < 2 || argc > 3)
1056 fprintf (stderr, "usage: %s nid|\"*\" [count (0 == mend)]\n", argv[0]);
1060 if (!libcfs_str2anynid(&nid, argv[1]))
1062 fprintf (stderr, "Can't parse nid \"%s\"\n", argv[1]);
1067 threshold = LNET_MD_THRESH_INF;
1068 } else if (sscanf(argv[2], "%i", &threshold) != 1) {
1069 fprintf (stderr, "Can't parse count \"%s\"\n", argv[2]);
1073 LIBCFS_IOC_INIT (data);
1075 data.ioc_count = threshold;
1077 rc = l_ioctl (LNET_DEV_ID, IOC_LIBCFS_FAIL_NID, &data);
1079 fprintf (stderr, "IOC_LIBCFS_FAIL_NID failed: %s\n",
1082 printf ("%s %s\n", threshold == 0 ? "Unfailing" : "Failing", argv[1]);
1088 jt_ptl_add_route (int argc, char **argv)
1090 struct libcfs_ioctl_data data;
1091 lnet_nid_t gateway_nid;
1092 unsigned int hops = 1;
1093 unsigned int priority = 0;
1097 if (argc < 2 || argc > 4) {
1098 fprintf(stderr, "usage: %s gateway [hopcount [priority]]\n",
1103 if (!g_net_is_set(argv[0]))
1106 gateway_nid = libcfs_str2nid(argv[1]);
1107 if (gateway_nid == LNET_NID_ANY) {
1108 fprintf (stderr, "Can't parse gateway NID \"%s\"\n", argv[1]);
1113 hops = strtoul(argv[2], &end, 0);
1114 if (hops == 0 || hops >= 256 || (end != NULL && *end != 0)) {
1115 fprintf(stderr, "Can't parse hopcount \"%s\"\n",
1120 priority = strtoul(argv[3], &end, 0);
1121 if (end != NULL && *end != 0) {
1123 "Can't parse priority \"%s\"\n",
1130 LIBCFS_IOC_INIT(data);
1131 data.ioc_net = g_net;
1132 data.ioc_count = hops;
1133 data.ioc_nid = gateway_nid;
1134 data.ioc_priority = priority;
1136 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data);
1138 fprintf (stderr, "IOC_LIBCFS_ADD_ROUTE failed: %s\n", strerror (errno));
1146 jt_ptl_del_route (int argc, char **argv)
1148 struct libcfs_ioctl_data data;
1153 fprintf (stderr, "usage: %s gatewayNID\n", argv[0]);
1157 if (!libcfs_str2anynid(&nid, argv[1])) {
1158 fprintf (stderr, "Can't parse gateway NID "
1159 "\"%s\"\n", argv[1]);
1163 LIBCFS_IOC_INIT(data);
1164 data.ioc_net = g_net_set ? g_net : LNET_NIDNET(LNET_NID_ANY);
1167 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data);
1169 fprintf (stderr, "IOC_LIBCFS_DEL_ROUTE (%s) failed: %s\n",
1170 libcfs_nid2str(nid), strerror (errno));
1178 jt_ptl_notify_router (int argc, char **argv)
1180 struct libcfs_ioctl_data data;
1189 fprintf (stderr, "usage: %s targetNID <up/down> [<time>]\n",
1194 nid = libcfs_str2nid(argv[1]);
1195 if (nid == LNET_NID_ANY) {
1196 fprintf (stderr, "Can't parse target NID \"%s\"\n", argv[1]);
1200 if (lnet_parse_bool (&enable, argv[2]) != 0) {
1201 fprintf (stderr, "Can't parse boolean %s\n", argv[2]);
1205 gettimeofday(&now, NULL);
1209 } else if (lnet_parse_time (&when, argv[3]) != 0) {
1210 fprintf(stderr, "Can't parse time %s\n"
1211 "Please specify either 'YYYY-MM-DD-HH:MM:SS'\n"
1212 "or an absolute unix time in seconds\n", argv[3]);
1214 } else if (when > now.tv_sec) {
1215 fprintf (stderr, "%s specifies a time in the future\n",
1220 LIBCFS_IOC_INIT(data);
1222 data.ioc_flags = enable;
1223 /* Yeuch; 'cept I need a __u64 on 64 bit machines... */
1224 data.ioc_u64[0] = (__u64)when;
1226 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_NOTIFY_ROUTER, &data);
1228 fprintf (stderr, "IOC_LIBCFS_NOTIFY_ROUTER (%s) failed: %s\n",
1229 libcfs_nid2str(nid), strerror (errno));
1237 jt_ptl_print_routes (int argc, char **argv)
1239 struct libcfs_ioctl_data data;
1248 for (index = 0;;index++)
1250 LIBCFS_IOC_INIT(data);
1251 data.ioc_count = index;
1253 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1258 hops = data.ioc_count;
1260 alive = data.ioc_flags;
1261 pri = data.ioc_priority;
1263 printf("net %18s hops %u gw %32s %s pri %u\n",
1264 libcfs_net2str(net), hops,
1265 libcfs_nid2str(nid), alive ? "up" : "down", pri);
1268 if (errno != ENOENT)
1269 fprintf(stderr, "Error getting routes: %s: check dmesg.\n",
1276 get_cycles_per_usec ()
1278 FILE *f = fopen ("/proc/cpuinfo", "r");
1283 while (fgets (line, sizeof (line), f) != NULL)
1284 if (sscanf (line, "cpu MHz : %lf", &mhz) == 1) {
1291 fprintf (stderr, "Can't read/parse /proc/cpuinfo\n");
1295 int jt_ptl_memhog(int argc, char **argv)
1297 static int gfp = 0; /* sticky! */
1299 struct libcfs_ioctl_data data;
1305 fprintf(stderr, "usage: %s <npages> [<GFP flags>]\n", argv[0]);
1309 count = strtol(argv[1], &end, 0);
1310 if (count < 0 || *end != 0) {
1311 fprintf(stderr, "Can't parse page count '%s'\n", argv[1]);
1316 rc = strtol(argv[2], &end, 0);
1318 fprintf(stderr, "Can't parse gfp flags '%s'\n", argv[2]);
1324 LIBCFS_IOC_INIT(data);
1325 data.ioc_count = count;
1326 data.ioc_flags = gfp;
1327 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_MEMHOG, &data);
1330 fprintf(stderr, "memhog %d failed: %s\n", count, strerror(errno));
1334 printf("memhog %d OK\n", count);
1338 int jt_ptl_testprotocompat(int argc, char **argv)
1340 struct libcfs_ioctl_data data;
1346 fprintf(stderr, "usage: %s <number>\n", argv[0]);
1350 flags = strtol(argv[1], &end, 0);
1351 if (flags < 0 || *end != 0) {
1352 fprintf(stderr, "Can't parse flags '%s'\n", argv[1]);
1356 LIBCFS_IOC_INIT(data);
1357 data.ioc_flags = flags;
1358 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_TESTPROTOCOMPAT, &data);
1361 fprintf(stderr, "test proto compat %x failed: %s\n",
1362 flags, strerror(errno));
1366 printf("test proto compat %x OK\n", flags);