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/nidstr.h>
23 #include <lnet/lnetctl.h>
24 #include <lnet/socklnd.h>
25 #include <lnet/lib-dlc.h>
29 unsigned int libcfs_debug;
30 unsigned int libcfs_printk = D_CANTMASK;
35 #define IOC_BUF_SIZE 8192
36 static char local_buf[IOC_BUF_SIZE];
37 static char *ioc_buf = local_buf;
39 /* Convert a string boolean to an int; "enable" -> 1 */
41 lnet_parse_bool (int *b, char *str)
43 if (!strcasecmp (str, "no") ||
44 !strcasecmp (str, "n") ||
45 !strcasecmp (str, "off") ||
46 !strcasecmp (str, "down") ||
47 !strcasecmp (str, "disable"))
53 if (!strcasecmp (str, "yes") ||
54 !strcasecmp (str, "y") ||
55 !strcasecmp (str, "on") ||
56 !strcasecmp (str, "up") ||
57 !strcasecmp (str, "enable"))
67 lnet_parse_port (int *port, char *str)
71 *port = strtol (str, &end, 0);
73 if (*end == 0 && /* parsed whole string */
74 *port > 0 && *port < 65536) /* minimal sanity check */
80 #ifdef HAVE_GETHOSTBYNAME
81 static struct hostent *
82 ptl_gethostbyname(char * hname) {
84 he = gethostbyname(hname);
89 fprintf(stderr, "Unable to resolve hostname: %s\n",
93 fprintf(stderr, "gethostbyname error for %s: %s\n",
94 hname, strerror(h_errno));
104 lnet_parse_ipquad (__u32 *ipaddrp, char *str)
111 if (sscanf (str, "%d.%d.%d.%d", &a, &b, &c, &d) == 4 &&
112 (a & ~0xff) == 0 && (b & ~0xff) == 0 &&
113 (c & ~0xff) == 0 && (d & ~0xff) == 0)
115 *ipaddrp = (a<<24)|(b<<16)|(c<<8)|d;
123 lnet_parse_ipaddr (__u32 *ipaddrp, char *str)
125 #ifdef HAVE_GETHOSTBYNAME
129 if (!strcmp (str, "_all_")) {
134 if (lnet_parse_ipquad(ipaddrp, str) == 0)
137 #ifdef HAVE_GETHOSTBYNAME
138 if ((('a' <= str[0] && str[0] <= 'z') ||
139 ('A' <= str[0] && str[0] <= 'Z')) &&
140 (he = ptl_gethostbyname (str)) != NULL) {
141 __u32 addr = *(__u32 *)he->h_addr;
143 *ipaddrp = ntohl(addr); /* HOST byte order */
152 ptl_ipaddr_2_str(__u32 ipaddr, char *str, size_t strsize, int lookup)
154 #ifdef HAVE_GETHOSTBYNAME
159 net_ip = htonl (ipaddr);
160 he = gethostbyaddr (&net_ip, sizeof (net_ip), AF_INET);
162 strlcpy(str, he->h_name, strsize);
168 sprintf (str, "%d.%d.%d.%d",
169 (ipaddr >> 24) & 0xff, (ipaddr >> 16) & 0xff,
170 (ipaddr >> 8) & 0xff, ipaddr & 0xff);
175 lnet_parse_time (time_t *t, char *str)
181 *t = strtol (str, &end, 0);
182 if (*end == 0) /* parsed whole string */
185 memset (&tm, 0, sizeof (tm));
186 n = sscanf (str, "%d-%d-%d-%d:%d:%d",
187 &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
188 &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
192 tm.tm_mon--; /* convert to 0 == Jan */
193 tm.tm_year -= 1900; /* y2k quirk */
194 tm.tm_isdst = -1; /* dunno if it's daylight savings... */
197 if (*t == (time_t)-1)
204 lnet_parse_nid(char *nid_str, lnet_process_id_t *id_ptr)
206 id_ptr->pid = LNET_PID_ANY;
207 id_ptr->nid = libcfs_str2nid(nid_str);
208 if (id_ptr->nid == LNET_NID_ANY) {
209 fprintf (stderr, "Can't parse nid \"%s\"\n", nid_str);
216 int g_net_is_set (char *cmd)
223 "You must run the 'network' command before '%s'.\n",
228 int g_net_is_compatible (char *cmd, ...)
233 if (!g_net_is_set(cmd))
239 nal = va_arg (ap, int);
240 if (nal == LNET_NETTYP(g_net)) {
250 "Command %s not compatible with %s NAL\n",
252 libcfs_lnd2str(LNET_NETTYP(g_net)));
256 int ptl_initialize(int argc, char **argv)
258 register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH,
259 LNET_DEV_MAJOR, LNET_DEV_MINOR);
264 int jt_ptl_network(int argc, char **argv)
266 struct libcfs_ioctl_data data;
267 __u32 net = LNET_NIDNET(LNET_NID_ANY);
271 fprintf(stderr, "usage: %s <net>|up|down\n", argv[0]);
275 if (!strcmp(argv[1], "unconfigure") ||
276 !strcmp(argv[1], "down")) {
277 LIBCFS_IOC_INIT(data);
278 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_UNCONFIGURE, &data);
281 printf ("LNET ready to unload\n");
286 fprintf(stderr, "LNET busy\n");
288 fprintf(stderr, "LNET unconfigure error %d: %s\n",
289 errno, strerror(errno));
293 if (!strcmp(argv[1], "configure") ||
294 !strcmp(argv[1], "up")) {
295 LIBCFS_IOC_INIT(data);
296 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIGURE, &data);
299 printf ("LNET configured\n");
303 fprintf(stderr, "LNET configure error %d: %s\n",
304 errno, strerror(errno));
308 net = libcfs_str2net(argv[1]);
309 if (net == LNET_NIDNET(LNET_NID_ANY)) {
310 fprintf(stderr, "Can't parse net %s\n", argv[1]);
314 if (LNET_NETTYP(net) == CIBLND ||
315 LNET_NETTYP(net) == OPENIBLND ||
316 LNET_NETTYP(net) == IIBLND ||
317 LNET_NETTYP(net) == VIBLND) {
318 fprintf(stderr, "Net %s obsoleted\n", libcfs_lnd2str(net));
328 jt_ptl_list_nids(int argc, char **argv)
330 struct libcfs_ioctl_data data;
331 int all = 0, return_nid = 0;
335 all = (argc == 2) && (strcmp(argv[1], "all") == 0);
336 /* Hack to pass back value */
337 return_nid = (argc == 2) && (argv[1][0] == 1);
339 if ((argc > 2) && !(all || return_nid)) {
340 fprintf(stderr, "usage: %s [all]\n", argv[0]);
344 for (count = 0;; count++) {
345 LIBCFS_IOC_INIT (data);
346 data.ioc_count = count;
347 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_NI, &data);
350 if ((count > 0) && (errno == ENOENT))
351 /* We found them all */
353 fprintf(stderr,"IOC_LIBCFS_GET_NI error %d: %s\n",
354 errno, strerror(errno));
358 if (all || (LNET_NETTYP(LNET_NIDNET(data.ioc_nid)) != LOLND)) {
359 printf("%s\n", libcfs_nid2str(data.ioc_nid));
361 *(__u64 *)(argv[1]) = data.ioc_nid;
371 jt_ptl_which_nid (int argc, char **argv)
373 struct libcfs_ioctl_data data;
376 lnet_nid_t best_nid = LNET_NID_ANY;
385 fprintf(stderr, "usage: %s NID [NID...]\n", argv[0]);
389 for (i = 1; i < argc; i++) {
391 nid = libcfs_str2nid(nidstr);
392 if (nid == LNET_NID_ANY) {
393 fprintf(stderr, "Can't parse NID %s\n", nidstr);
397 LIBCFS_IOC_INIT(data);
400 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNET_DIST, &data);
402 fprintf(stderr, "Can't get distance to %s: %s\n",
403 nidstr, strerror(errno));
407 dist = data.ioc_u32[0];
408 order = data.ioc_u32[1];
411 if (dist == -EHOSTUNREACH)
414 fprintf(stderr, "Unexpected distance to %s: %d\n",
419 if (best_nid == LNET_NID_ANY ||
421 (dist == best_dist && order < best_order)) {
428 if (best_nid == LNET_NID_ANY) {
429 fprintf(stderr, "No reachable NID\n");
433 printf("%s\n", libcfs_nid2str(best_nid));
438 jt_ptl_print_interfaces (int argc, char **argv)
440 struct libcfs_ioctl_data data;
441 char buffer[3][HOST_NAME_MAX + 1];
445 if (!g_net_is_compatible (argv[0], SOCKLND, 0))
448 for (index = 0;;index++) {
449 LIBCFS_IOC_INIT(data);
450 data.ioc_net = g_net;
451 data.ioc_count = index;
453 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_INTERFACE, &data);
457 printf ("%s: (%s/%s) npeer %d nroute %d\n",
458 ptl_ipaddr_2_str(data.ioc_u32[0], buffer[2],
459 sizeof(buffer[2]), 1),
460 ptl_ipaddr_2_str(data.ioc_u32[0], buffer[0],
461 sizeof(buffer[0]), 0),
462 ptl_ipaddr_2_str(data.ioc_u32[1], buffer[1],
463 sizeof(buffer[1]), 0),
464 data.ioc_u32[2], data.ioc_u32[3]);
468 if (errno == ENOENT) {
469 printf ("<no interfaces>\n");
471 fprintf(stderr, "Error getting interfaces: %s: "
481 jt_ptl_add_interface (int argc, char **argv)
483 struct libcfs_ioctl_data data;
486 __u32 netmask = 0xffffff00;
491 if (argc < 2 || argc > 3) {
492 fprintf (stderr, "usage: %s ipaddr [netmask]\n", argv[0]);
496 if (!g_net_is_compatible(argv[0], SOCKLND, 0))
499 if (lnet_parse_ipaddr(&ipaddr, argv[1]) != 0) {
500 fprintf (stderr, "Can't parse ip: %s\n", argv[1]);
505 count = strtol(argv[2], &end, 0);
506 if (count > 0 && count < 32 && *end == 0) {
508 for (i = count; i > 0; i--)
509 netmask = netmask|(1<<(32-i));
510 } else if (lnet_parse_ipquad(&netmask, argv[2]) != 0) {
511 fprintf (stderr, "Can't parse netmask: %s\n", argv[2]);
516 LIBCFS_IOC_INIT(data);
517 data.ioc_net = g_net;
518 data.ioc_u32[0] = ipaddr;
519 data.ioc_u32[1] = netmask;
521 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_INTERFACE, &data);
523 fprintf (stderr, "failed to add interface: %s\n",
532 jt_ptl_del_interface (int argc, char **argv)
534 struct libcfs_ioctl_data data;
539 fprintf (stderr, "usage: %s [ipaddr]\n", argv[0]);
543 if (!g_net_is_compatible(argv[0], SOCKLND, 0))
547 lnet_parse_ipaddr(&ipaddr, argv[1]) != 0) {
548 fprintf (stderr, "Can't parse ip: %s\n", argv[1]);
552 LIBCFS_IOC_INIT(data);
553 data.ioc_net = g_net;
554 data.ioc_u32[0] = ipaddr;
556 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_INTERFACE, &data);
558 fprintf (stderr, "failed to delete interface: %s\n",
567 jt_ptl_print_peers (int argc, char **argv)
569 struct libcfs_ioctl_data data;
570 lnet_process_id_t id;
571 char buffer[2][HOST_NAME_MAX + 1];
575 if (!g_net_is_compatible (argv[0], SOCKLND, RALND, MXLND,
579 for (index = 0;;index++) {
580 LIBCFS_IOC_INIT(data);
581 data.ioc_net = g_net;
582 data.ioc_count = index;
584 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER, &data);
588 if (g_net_is_compatible(NULL, SOCKLND, 0)) {
589 id.nid = data.ioc_nid;
590 id.pid = data.ioc_u32[4];
591 printf ("%-20s [%d]%s->%s:%d #%d\n",
593 data.ioc_count, /* persistence */
595 ptl_ipaddr_2_str(data.ioc_u32[2], buffer[0],
596 sizeof(buffer[0]), 1),
598 ptl_ipaddr_2_str(data.ioc_u32[0], buffer[1],
599 sizeof(buffer[1]), 1),
600 data.ioc_u32[1], /* peer port */
601 data.ioc_u32[3]); /* conn_count */
602 } else if (g_net_is_compatible(NULL, RALND, 0)) {
603 printf ("%-20s [%d]@%s:%d\n",
604 libcfs_nid2str(data.ioc_nid), /* peer nid */
605 data.ioc_count, /* peer persistence */
607 ptl_ipaddr_2_str(data.ioc_u32[0], buffer[1],
608 sizeof(buffer[1]), 1),
609 data.ioc_u32[1]); /* peer port */
610 } else if (g_net_is_compatible(NULL, GNILND, 0)) {
611 int disconn = data.ioc_flags >> 16;
617 state = data.ioc_flags & 0xffff ? "C" : "U";
619 printf ("%-20s (%d) %s [%d] "LPU64" "
620 "sq %d/%d tx %d/%d/%d\n",
621 libcfs_nid2str(data.ioc_nid), /* peer nid */
622 data.ioc_net, /* gemini device id */
623 state, /* peer is Connecting, Up, or Down */
624 data.ioc_count, /* peer refcount */
625 data.ioc_u64[0], /* peerstamp */
626 data.ioc_u32[2], data.ioc_u32[3], /* tx and rx seq */
627 /* fmaq, nfma, nrdma */
628 data.ioc_u32[0], data.ioc_u32[1], data.ioc_u32[4]
631 printf ("%-20s [%d]\n",
632 libcfs_nid2str(data.ioc_nid), data.ioc_count);
637 if (errno == ENOENT) {
638 printf ("<no peers>\n");
640 fprintf(stderr, "Error getting peer list: %s: "
649 jt_ptl_add_peer (int argc, char **argv)
651 struct libcfs_ioctl_data data;
657 if (!g_net_is_compatible (argv[0], SOCKLND, RALND,
662 fprintf (stderr, "usage(tcp,ra,gni): %s nid ipaddr port\n",
667 nid = libcfs_str2nid(argv[1]);
668 if (nid == LNET_NID_ANY) {
669 fprintf (stderr, "Can't parse NID: %s\n", argv[1]);
673 if (lnet_parse_ipaddr (&ip, argv[2]) != 0) {
674 fprintf (stderr, "Can't parse ip addr: %s\n", argv[2]);
678 if (lnet_parse_port (&port, argv[3]) != 0) {
679 fprintf (stderr, "Can't parse port: %s\n", argv[3]);
683 LIBCFS_IOC_INIT(data);
684 data.ioc_net = g_net;
686 data.ioc_u32[0] = ip;
687 data.ioc_u32[1] = port;
689 rc = l_ioctl (LNET_DEV_ID, IOC_LIBCFS_ADD_PEER, &data);
691 fprintf (stderr, "failed to add peer: %s\n",
700 jt_ptl_del_peer (int argc, char **argv)
702 struct libcfs_ioctl_data data;
703 lnet_nid_t nid = LNET_NID_ANY;
704 lnet_pid_t pid = LNET_PID_ANY;
708 if (!g_net_is_compatible (argv[0], SOCKLND, RALND, MXLND,
712 if (g_net_is_compatible(NULL, SOCKLND, 0)) {
714 fprintf (stderr, "usage: %s [nid] [ipaddr]\n",
718 } else if (argc > 2) {
719 fprintf (stderr, "usage: %s [nid]\n", argv[0]);
724 !libcfs_str2anynid(&nid, argv[1])) {
725 fprintf (stderr, "Can't parse nid: %s\n", argv[1]);
729 if (g_net_is_compatible(NULL, SOCKLND, 0)) {
731 lnet_parse_ipaddr (&ip, argv[2]) != 0) {
732 fprintf (stderr, "Can't parse ip addr: %s\n",
738 LIBCFS_IOC_INIT(data);
739 data.ioc_net = g_net;
741 data.ioc_u32[0] = ip;
742 data.ioc_u32[1] = pid;
744 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_PEER, &data);
746 fprintf (stderr, "failed to remove peer: %s\n",
755 jt_ptl_print_connections (int argc, char **argv)
757 struct libcfs_ioctl_data data;
758 lnet_process_id_t id;
759 char buffer[2][HOST_NAME_MAX + 1];
763 if (!g_net_is_compatible (argv[0], SOCKLND, RALND, MXLND, O2IBLND,
767 for (index = 0; ; index++) {
768 LIBCFS_IOC_INIT(data);
769 data.ioc_net = g_net;
770 data.ioc_count = index;
772 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_CONN, &data);
776 if (g_net_is_compatible (NULL, SOCKLND, 0)) {
777 id.nid = data.ioc_nid;
778 id.pid = data.ioc_u32[6];
779 printf ("%-20s %s[%d]%s->%s:%d %d/%d %s\n",
781 (data.ioc_u32[3] == SOCKLND_CONN_ANY) ? "A" :
782 (data.ioc_u32[3] == SOCKLND_CONN_CONTROL) ? "C" :
783 (data.ioc_u32[3] == SOCKLND_CONN_BULK_IN) ? "I" :
784 (data.ioc_u32[3] == SOCKLND_CONN_BULK_OUT) ? "O" : "?",
785 data.ioc_u32[4], /* scheduler */
787 ptl_ipaddr_2_str(data.ioc_u32[2], buffer[0],
788 sizeof(buffer[0]), 1),
790 ptl_ipaddr_2_str(data.ioc_u32[0], buffer[1],
791 sizeof(buffer[1]), 1),
792 data.ioc_u32[1], /* remote port */
793 data.ioc_count, /* tx buffer size */
794 data.ioc_u32[5], /* rx buffer size */
795 data.ioc_flags ? "nagle" : "nonagle");
796 } else if (g_net_is_compatible (NULL, RALND, 0)) {
797 printf ("%-20s [%d]\n",
798 libcfs_nid2str(data.ioc_nid),
799 data.ioc_u32[0] /* device id */);
800 } else if (g_net_is_compatible (NULL, O2IBLND, 0)) {
801 printf ("%s mtu %d\n",
802 libcfs_nid2str(data.ioc_nid),
803 data.ioc_u32[0]); /* path MTU */
804 } else if (g_net_is_compatible (NULL, GNILND, 0)) {
805 printf ("%-20s [%d]\n",
806 libcfs_nid2str(data.ioc_nid),
807 data.ioc_u32[0] /* device id */);
809 printf ("%s\n", libcfs_nid2str(data.ioc_nid));
814 if (errno == ENOENT) {
815 printf ("<no connections>\n");
817 fprintf(stderr, "Error getting connection list: %s: "
825 int jt_ptl_disconnect(int argc, char **argv)
827 struct libcfs_ioctl_data data;
828 lnet_nid_t nid = LNET_NID_ANY;
833 fprintf(stderr, "usage: %s [nid] [ipaddr]\n", argv[0]);
837 if (!g_net_is_compatible (NULL, SOCKLND, RALND, MXLND, O2IBLND,
842 !libcfs_str2anynid(&nid, argv[1])) {
843 fprintf (stderr, "Can't parse nid %s\n", argv[1]);
847 if (g_net_is_compatible (NULL, SOCKLND, 0) &&
849 lnet_parse_ipaddr (&ipaddr, argv[2]) != 0) {
850 fprintf (stderr, "Can't parse ip addr %s\n", argv[2]);
854 LIBCFS_IOC_INIT(data);
855 data.ioc_net = g_net;
857 data.ioc_u32[0] = ipaddr;
859 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CLOSE_CONNECTION, &data);
861 fprintf(stderr, "failed to remove connection: %s\n",
869 int jt_ptl_push_connection (int argc, char **argv)
871 struct libcfs_ioctl_data data;
873 lnet_nid_t nid = LNET_NID_ANY;
876 fprintf(stderr, "usage: %s [nid]\n", argv[0]);
880 if (!g_net_is_compatible (argv[0], SOCKLND, GNILND, 0))
884 !libcfs_str2anynid(&nid, argv[1])) {
885 fprintf(stderr, "Can't parse nid: %s\n", argv[1]);
889 LIBCFS_IOC_INIT(data);
890 data.ioc_net = g_net;
893 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_PUSH_CONNECTION, &data);
895 fprintf(stderr, "failed to push connection: %s\n",
904 jt_ptl_print_active_txs (int argc, char **argv)
906 struct libcfs_ioctl_data data;
910 if (!g_net_is_compatible (argv[0], QSWLND, 0))
913 for (index = 0;;index++) {
914 LIBCFS_IOC_INIT(data);
915 data.ioc_net = g_net;
916 data.ioc_count = index;
918 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_TXDESC, &data);
922 printf ("type %u payload %6d to %s via %s by pid %6d: "
923 "%s, %s, state %d\n",
926 libcfs_nid2str(data.ioc_nid),
927 libcfs_nid2str(data.ioc_u64[0]),
929 (data.ioc_flags & 1) ? "delayed" : "immediate",
930 (data.ioc_flags & 2) ? "nblk" : "normal",
931 data.ioc_flags >> 2);
935 if (errno == ENOENT) {
936 printf ("<no active descs>\n");
938 fprintf(stderr, "Error getting active transmits list: "
939 "%s: check dmesg.\n",
946 int jt_ptl_ping(int argc, char **argv)
950 lnet_process_id_t id;
951 lnet_process_id_t ids[16];
952 int maxids = sizeof(ids)/sizeof(ids[0]);
953 struct libcfs_ioctl_data data;
958 fprintf(stderr, "usage: %s id [timeout (secs)]\n", argv[0]);
962 sep = strchr(argv[1], '-');
964 rc = lnet_parse_nid(argv[1], &id);
970 if (argv[1][0] == 'u' ||
972 id.pid = strtoul(&argv[1][1], &end, 0) | LNET_PID_USERFLAG;
974 id.pid = strtoul(argv[1], &end, 0);
976 if (end != sep) { /* assuming '-' is part of hostname */
977 rc = lnet_parse_nid(argv[1], &id);
981 id.nid = libcfs_str2nid(sep + 1);
983 if (id.nid == LNET_NID_ANY) {
985 "Can't parse process id \"%s\"\n",
993 timeout = 1000 * atol(argv[2]);
995 timeout = 1000; /* default 1 second timeout */
997 LIBCFS_IOC_INIT (data);
998 data.ioc_nid = id.nid;
999 data.ioc_u32[0] = id.pid;
1000 data.ioc_u32[1] = timeout;
1001 data.ioc_plen1 = sizeof(ids);
1002 data.ioc_pbuf1 = (char *)ids;
1004 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_PING, &data);
1006 fprintf(stderr, "failed to ping %s: %s\n",
1007 id.pid == LNET_PID_ANY ?
1008 libcfs_nid2str(id.nid) : libcfs_id2str(id),
1013 for (i = 0; i < data.ioc_count && i < maxids; i++)
1014 printf("%s\n", libcfs_id2str(ids[i]));
1016 if (data.ioc_count > maxids)
1017 printf("%d out of %d ids listed\n", maxids, data.ioc_count);
1022 int jt_ptl_mynid(int argc, char **argv)
1024 struct libcfs_ioctl_data data;
1029 fprintf(stderr, "usage: %s NID\n", argv[0]);
1033 nid = libcfs_str2nid(argv[1]);
1034 if (nid == LNET_NID_ANY) {
1035 fprintf(stderr, "Can't parse NID '%s'\n", argv[1]);
1039 LIBCFS_IOC_INIT(data);
1040 data.ioc_net = LNET_NIDNET(nid);
1043 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_REGISTER_MYNID, &data);
1045 fprintf(stderr, "setting my NID failed: %s\n",
1048 printf("registered my nid %s\n", libcfs_nid2str(nid));
1054 jt_ptl_fail_nid (int argc, char **argv)
1059 struct libcfs_ioctl_data data;
1061 if (argc < 2 || argc > 3)
1063 fprintf (stderr, "usage: %s nid|\"*\" [count (0 == mend)]\n", argv[0]);
1067 if (!libcfs_str2anynid(&nid, argv[1]))
1069 fprintf (stderr, "Can't parse nid \"%s\"\n", argv[1]);
1074 threshold = LNET_MD_THRESH_INF;
1075 } else if (sscanf(argv[2], "%i", &threshold) != 1) {
1076 fprintf (stderr, "Can't parse count \"%s\"\n", argv[2]);
1080 LIBCFS_IOC_INIT (data);
1082 data.ioc_count = threshold;
1084 rc = l_ioctl (LNET_DEV_ID, IOC_LIBCFS_FAIL_NID, &data);
1086 fprintf (stderr, "IOC_LIBCFS_FAIL_NID failed: %s\n",
1089 printf ("%s %s\n", threshold == 0 ? "Unfailing" : "Failing", argv[1]);
1095 jt_ptl_add_route (int argc, char **argv)
1097 struct lnet_ioctl_config_data data;
1098 lnet_nid_t gateway_nid;
1099 unsigned int hops = 1;
1100 unsigned int priority = 0;
1104 if (argc < 2 || argc > 4) {
1105 fprintf(stderr, "usage: %s gateway [hopcount [priority]]\n",
1110 if (g_net_is_set(argv[0]) == 0)
1113 gateway_nid = libcfs_str2nid(argv[1]);
1114 if (gateway_nid == LNET_NID_ANY) {
1115 fprintf(stderr, "Can't parse gateway NID \"%s\"\n", argv[1]);
1120 hops = strtoul(argv[2], &end, 0);
1121 if (hops == 0 || hops >= 256 || (end != NULL && *end != 0)) {
1122 fprintf(stderr, "Can't parse hopcount \"%s\"\n",
1127 priority = strtoul(argv[3], &end, 0);
1128 if (end != NULL && *end != 0) {
1130 "Can't parse priority \"%s\"\n",
1137 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1138 data.cfg_net = g_net;
1139 data.cfg_config_u.cfg_route.rtr_hop = hops;
1140 data.cfg_nid = gateway_nid;
1141 data.cfg_config_u.cfg_route.rtr_priority = priority;
1143 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data);
1145 fprintf(stderr, "IOC_LIBCFS_ADD_ROUTE failed: %s\n",
1154 jt_ptl_del_route (int argc, char **argv)
1156 struct lnet_ioctl_config_data data;
1161 fprintf(stderr, "usage: %s gatewayNID\n", argv[0]);
1165 if (libcfs_str2anynid(&nid, argv[1]) == 0) {
1166 fprintf(stderr, "Can't parse gateway NID "
1167 "\"%s\"\n", argv[1]);
1171 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1172 data.cfg_net = g_net_set ? g_net : LNET_NIDNET(LNET_NID_ANY);
1175 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data);
1177 fprintf(stderr, "IOC_LIBCFS_DEL_ROUTE (%s) failed: %s\n",
1178 libcfs_nid2str(nid), strerror(errno));
1186 jt_ptl_notify_router (int argc, char **argv)
1188 struct libcfs_ioctl_data data;
1197 fprintf (stderr, "usage: %s targetNID <up/down> [<time>]\n",
1202 nid = libcfs_str2nid(argv[1]);
1203 if (nid == LNET_NID_ANY) {
1204 fprintf (stderr, "Can't parse target NID \"%s\"\n", argv[1]);
1208 if (lnet_parse_bool (&enable, argv[2]) != 0) {
1209 fprintf (stderr, "Can't parse boolean %s\n", argv[2]);
1213 gettimeofday(&now, NULL);
1217 } else if (lnet_parse_time (&when, argv[3]) != 0) {
1218 fprintf(stderr, "Can't parse time %s\n"
1219 "Please specify either 'YYYY-MM-DD-HH:MM:SS'\n"
1220 "or an absolute unix time in seconds\n", argv[3]);
1222 } else if (when > now.tv_sec) {
1223 fprintf (stderr, "%s specifies a time in the future\n",
1228 LIBCFS_IOC_INIT(data);
1230 data.ioc_flags = enable;
1231 /* Yeuch; 'cept I need a __u64 on 64 bit machines... */
1232 data.ioc_u64[0] = (__u64)when;
1234 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_NOTIFY_ROUTER, &data);
1236 fprintf (stderr, "IOC_LIBCFS_NOTIFY_ROUTER (%s) failed: %s\n",
1237 libcfs_nid2str(nid), strerror (errno));
1245 jt_ptl_print_routes (int argc, char **argv)
1247 struct lnet_ioctl_config_data data;
1256 for (index = 0; ; index++) {
1257 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1258 data.cfg_count = index;
1260 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1265 hops = data.cfg_config_u.cfg_route.rtr_hop;
1267 alive = data.cfg_config_u.cfg_route.rtr_flags;
1268 pri = data.cfg_config_u.cfg_route.rtr_priority;
1270 printf("net %18s hops %u gw %32s %s pri %u\n",
1271 libcfs_net2str(net), hops,
1272 libcfs_nid2str(nid), alive ? "up" : "down", pri);
1275 if (errno != ENOENT)
1276 fprintf(stderr, "Error getting routes: %s: check dmesg.\n",
1283 fault_attr_nid_parse(char *str, lnet_nid_t *nid_p)
1289 /* NB: can't support range ipaddress except * and *@net */
1290 if (strlen(str) > 2 && str[0] == '*' && str[1] == '@') {
1291 net = libcfs_str2net(str + 2);
1292 if (net == LNET_NIDNET(LNET_NID_ANY))
1295 nid = LNET_MKNID(net, LNET_NIDADDR(LNET_NID_ANY));
1297 rc = libcfs_str2anynid(&nid, str);
1305 fprintf(stderr, "Invalid NID : %s\n", str);
1310 fault_attr_msg_parse(char *msg_str, __u32 *mask_p)
1312 if (!strcasecmp(msg_str, "put")) {
1313 *mask_p |= LNET_PUT_BIT;
1316 } else if (!strcasecmp(msg_str, "ack")) {
1317 *mask_p |= LNET_ACK_BIT;
1320 } else if (!strcasecmp(msg_str, "get")) {
1321 *mask_p |= LNET_GET_BIT;
1324 } else if (!strcasecmp(msg_str, "reply")) {
1325 *mask_p |= LNET_REPLY_BIT;
1329 fprintf(stderr, "unknown message type %s\n", msg_str);
1334 fault_attr_ptl_parse(char *ptl_str, __u64 *mask_p)
1336 unsigned long rc = strtoul(optarg, NULL, 0);
1339 fprintf(stderr, "invalid portal: %lu\n", rc);
1343 *mask_p |= (1ULL << rc);
1348 fault_simul_rule_add(__u32 opc, char *name, int argc, char **argv)
1350 struct libcfs_ioctl_data data = {{0}};
1351 struct lnet_fault_attr attr;
1355 static struct option opts[] = {
1356 {"source", required_argument, 0, 's'},
1357 {"dest", required_argument, 0, 'd'},
1358 {"rate", required_argument, 0, 'r'},
1359 {"interval", required_argument, 0, 'i'},
1360 {"latency", required_argument, 0, 'l'},
1361 {"portal", required_argument, 0, 'p'},
1362 {"message", required_argument, 0, 'm'},
1367 fprintf(stderr, "Failed, please provide source, destination "
1368 "and rate of rule\n");
1372 optstr = opc == LNET_CTL_DROP_ADD ? "s:d:r:i:p:m:" : "s:d:r:l:p:m:";
1373 memset(&attr, 0, sizeof(attr));
1375 char c = getopt_long(argc, argv, optstr, opts, NULL);
1381 case 's': /* source NID/NET */
1382 rc = fault_attr_nid_parse(optarg, &attr.fa_src);
1387 case 'd': /* dest NID/NET */
1388 rc = fault_attr_nid_parse(optarg, &attr.fa_dst);
1393 case 'r': /* drop rate */
1394 if (opc == LNET_CTL_DROP_ADD)
1395 attr.u.drop.da_rate = strtoul(optarg, NULL, 0);
1397 attr.u.delay.la_rate = strtoul(optarg, NULL, 0);
1400 case 'i': /* time interval (# seconds) for message drop */
1401 if (opc == LNET_CTL_DROP_ADD)
1402 attr.u.drop.da_interval = strtoul(optarg,
1405 attr.u.delay.la_interval = strtoul(optarg,
1409 case 'l': /* seconds to wait before activating rule */
1410 attr.u.delay.la_latency = strtoul(optarg, NULL, 0);
1413 case 'p': /* portal to filter */
1414 rc = fault_attr_ptl_parse(optarg, &attr.fa_ptl_mask);
1419 case 'm': /* message types to filter */
1420 rc = fault_attr_msg_parse(optarg, &attr.fa_msg_mask);
1426 fprintf(stderr, "error: %s: option '%s' "
1427 "unrecognized\n", argv[0], argv[optind - 1]);
1433 if (opc == LNET_CTL_DROP_ADD) {
1434 /* NB: drop rate and interval are exclusive to each other */
1435 if (!((attr.u.drop.da_rate == 0) ^
1436 (attr.u.drop.da_interval == 0))) {
1438 "please provide either drop rate or interval "
1439 "but not both at the same time.\n");
1442 } else if (opc == LNET_CTL_DELAY_ADD) {
1443 if (!((attr.u.delay.la_rate == 0) ^
1444 (attr.u.delay.la_interval == 0))) {
1446 "please provide either delay rate or interval "
1447 "but not both at the same time.\n");
1451 if (attr.u.delay.la_latency == 0) {
1452 fprintf(stderr, "latency cannot be zero\n");
1457 if (attr.fa_src == 0 || attr.fa_dst == 0) {
1458 fprintf(stderr, "Please provide both source and destination "
1459 "of %s rule\n", name);
1463 data.ioc_flags = opc;
1464 data.ioc_inllen1 = sizeof(attr);
1465 data.ioc_inlbuf1 = (char *)&attr;
1466 if (libcfs_ioctl_pack(&data, &ioc_buf, IOC_BUF_SIZE) != 0) {
1467 fprintf(stderr, "libcfs_ioctl_pack failed\n");
1471 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNET_FAULT, ioc_buf);
1473 fprintf(stderr, "add %s rule %s->%s failed: %s\n",
1474 name, libcfs_nid2str(attr.fa_src),
1475 libcfs_nid2str(attr.fa_dst), strerror(errno));
1479 printf("Added %s rule %s->%s (1/%d)\n",
1480 name, libcfs_nid2str(attr.fa_src), libcfs_nid2str(attr.fa_dst),
1481 opc == LNET_CTL_DROP_ADD ?
1482 attr.u.drop.da_rate : attr.u.delay.la_rate);
1491 jt_ptl_drop_add(int argc, char **argv)
1493 return fault_simul_rule_add(LNET_CTL_DROP_ADD, "drop", argc, argv);
1497 jt_ptl_delay_add(int argc, char **argv)
1499 return fault_simul_rule_add(LNET_CTL_DELAY_ADD, "delay", argc, argv);
1503 fault_simul_rule_del(__u32 opc, char *name, int argc, char **argv)
1505 struct libcfs_ioctl_data data = {{0}};
1506 struct lnet_fault_attr attr;
1510 static struct option opts[] = {
1511 {"source", required_argument, 0, 's'},
1512 {"dest", required_argument, 0, 'd'},
1513 {"all", no_argument, 0, 'a'},
1518 fprintf(stderr, "Failed, please provide source and "
1519 "destination of rule\n");
1523 memset(&attr, 0, sizeof(attr));
1525 char c = getopt_long(argc, argv, "s:d:a", opts, NULL);
1532 rc = fault_attr_nid_parse(optarg, &attr.fa_src);
1537 rc = fault_attr_nid_parse(optarg, &attr.fa_dst);
1542 attr.fa_src = attr.fa_dst = 0;
1546 fprintf(stderr, "error: %s: option '%s' "
1547 "unrecognized\n", argv[0], argv[optind - 1]);
1553 data.ioc_flags = opc;
1554 data.ioc_inllen1 = sizeof(attr);
1555 data.ioc_inlbuf1 = (char *)&attr;
1556 if (libcfs_ioctl_pack(&data, &ioc_buf, IOC_BUF_SIZE) != 0) {
1557 fprintf(stderr, "libcfs_ioctl_pack failed\n");
1561 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNET_FAULT, ioc_buf);
1563 fprintf(stderr, "remove %s rule %s->%s failed: %s\n", name,
1564 all ? "all" : libcfs_nid2str(attr.fa_src),
1565 all ? "all" : libcfs_nid2str(attr.fa_dst),
1570 libcfs_ioctl_unpack(&data, ioc_buf);
1571 printf("Removed %d %s rules\n", data.ioc_count, name);
1580 jt_ptl_drop_del(int argc, char **argv)
1582 return fault_simul_rule_del(LNET_CTL_DROP_DEL, "drop", argc, argv);
1586 jt_ptl_delay_del(int argc, char **argv)
1588 return fault_simul_rule_del(LNET_CTL_DELAY_DEL, "delay", argc, argv);
1592 fault_simul_rule_reset(__u32 opc, char *name, int argc, char **argv)
1594 struct libcfs_ioctl_data data = {{0}};
1597 LIBCFS_IOC_INIT(data);
1598 data.ioc_flags = opc;
1600 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNET_FAULT, &data);
1602 fprintf(stderr, "failed to reset %s stats: %s\n",
1603 name, strerror(errno));
1610 jt_ptl_drop_reset(int argc, char **argv)
1612 return fault_simul_rule_reset(LNET_CTL_DROP_RESET, "drop", argc, argv);
1616 jt_ptl_delay_reset(int argc, char **argv)
1618 return fault_simul_rule_reset(LNET_CTL_DELAY_RESET, "delay",
1623 fault_simul_rule_list(__u32 opc, char *name, int argc, char **argv)
1625 struct libcfs_ioctl_data data = {{0}};
1626 struct lnet_fault_attr attr;
1627 struct lnet_fault_stat stat;
1630 printf("LNet %s rules:\n", name);
1631 for (pos = 0;; pos++) {
1634 memset(&attr, 0, sizeof(attr));
1635 memset(&stat, 0, sizeof(stat));
1637 data.ioc_count = pos;
1638 data.ioc_flags = opc;
1639 data.ioc_inllen1 = sizeof(attr);
1640 data.ioc_inlbuf1 = (char *)&attr;
1641 data.ioc_inllen2 = sizeof(stat);
1642 data.ioc_inlbuf2 = (char *)&stat;
1643 if (libcfs_ioctl_pack(&data, &ioc_buf, IOC_BUF_SIZE) != 0) {
1644 fprintf(stderr, "libcfs_ioctl_pack failed\n");
1648 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNET_FAULT, ioc_buf);
1652 libcfs_ioctl_unpack(&data, ioc_buf);
1654 if (opc == LNET_CTL_DROP_LIST) {
1655 printf("%s->%s (1/%d | %d) ptl "LPX64", msg %x, "
1656 LPU64"/"LPU64", PUT "LPU64", ACK "LPU64", GET "
1657 LPU64", REP "LPU64"\n",
1658 libcfs_nid2str(attr.fa_src),
1659 libcfs_nid2str(attr.fa_dst),
1660 attr.u.drop.da_rate, attr.u.drop.da_interval,
1661 attr.fa_ptl_mask, attr.fa_msg_mask,
1662 stat.u.drop.ds_dropped, stat.fs_count,
1663 stat.fs_put, stat.fs_ack,
1664 stat.fs_get, stat.fs_reply);
1666 } else if (opc == LNET_CTL_DELAY_LIST) {
1667 printf("%s->%s (1/%d | %d, latency %d) ptl "LPX64
1668 ", msg %x, "LPU64"/"LPU64", PUT "LPU64
1669 ", ACK "LPU64", GET "LPU64", REP "LPU64"\n",
1670 libcfs_nid2str(attr.fa_src),
1671 libcfs_nid2str(attr.fa_dst),
1672 attr.u.delay.la_rate, attr.u.delay.la_interval,
1673 attr.u.delay.la_latency,
1674 attr.fa_ptl_mask, attr.fa_msg_mask,
1675 stat.u.delay.ls_delayed, stat.fs_count,
1676 stat.fs_put, stat.fs_ack, stat.fs_get,
1680 printf("found total %d\n", pos);
1686 jt_ptl_drop_list(int argc, char **argv)
1688 return fault_simul_rule_list(LNET_CTL_DROP_LIST, "drop", argc, argv);
1692 jt_ptl_delay_list(int argc, char **argv)
1694 return fault_simul_rule_list(LNET_CTL_DELAY_LIST, "delay", argc, argv);
1698 get_cycles_per_usec ()
1700 FILE *f = fopen ("/proc/cpuinfo", "r");
1705 while (fgets (line, sizeof (line), f) != NULL)
1706 if (sscanf (line, "cpu MHz : %lf", &mhz) == 1) {
1713 fprintf (stderr, "Can't read/parse /proc/cpuinfo\n");
1717 int jt_ptl_memhog(int argc, char **argv)
1719 static int gfp = 0; /* sticky! */
1721 struct libcfs_ioctl_data data;
1727 fprintf(stderr, "usage: %s <npages> [<GFP flags>]\n", argv[0]);
1731 count = strtol(argv[1], &end, 0);
1732 if (count < 0 || *end != 0) {
1733 fprintf(stderr, "Can't parse page count '%s'\n", argv[1]);
1738 rc = strtol(argv[2], &end, 0);
1740 fprintf(stderr, "Can't parse gfp flags '%s'\n", argv[2]);
1746 LIBCFS_IOC_INIT(data);
1747 data.ioc_count = count;
1748 data.ioc_flags = gfp;
1749 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_MEMHOG, &data);
1752 fprintf(stderr, "memhog %d failed: %s\n", count, strerror(errno));
1756 printf("memhog %d OK\n", count);
1760 int jt_ptl_testprotocompat(int argc, char **argv)
1762 struct libcfs_ioctl_data data;
1768 fprintf(stderr, "usage: %s <number>\n", argv[0]);
1772 flags = strtol(argv[1], &end, 0);
1773 if (flags < 0 || *end != 0) {
1774 fprintf(stderr, "Can't parse flags '%s'\n", argv[1]);
1778 LIBCFS_IOC_INIT(data);
1779 data.ioc_flags = flags;
1780 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_TESTPROTOCOMPAT, &data);
1783 fprintf(stderr, "test proto compat %x failed: %s\n",
1784 flags, strerror(errno));
1788 printf("test proto compat %x OK\n", flags);