2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Copyright (c) 2013, 2017, Intel Corporation.
6 * This file is part of Lustre, https://wiki.whamcloud.com/
8 * Portals is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Portals is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Portals; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <sys/ioctl.h>
36 #include <linux/types.h>
38 #include <libcfs/util/ioctl.h>
39 #include <linux/lnet/libcfs_debug.h>
40 #include <linux/lnet/lnet-dlc.h>
41 #include <linux/lnet/lnetctl.h>
42 #include <linux/lnet/nidstr.h>
43 #include <linux/lnet/socklnd.h>
44 #include <lnetconfig/liblnetconfig.h>
45 #include <lustre/lustreapi.h>
46 #include <lustre_ioctl_old.h>
48 unsigned int libcfs_debug;
49 unsigned int libcfs_printk = D_CANTMASK;
51 static bool g_net_interactive;
52 static bool g_net_set;
55 #define IOC_BUF_SIZE 8192
56 static char local_buf[IOC_BUF_SIZE];
57 static char *ioc_buf = local_buf;
59 /* Convert a string boolean to an int; "enable" -> 1 */
61 lnet_parse_bool (int *b, char *str)
63 if (!strcasecmp(str, "no") ||
64 !strcasecmp(str, "n") ||
65 !strcasecmp(str, "off") ||
66 !strcasecmp(str, "down") ||
67 !strcasecmp(str, "disable")) {
73 if (!strcasecmp(str, "yes") ||
74 !strcasecmp(str, "y") ||
75 !strcasecmp(str, "on") ||
76 !strcasecmp(str, "up") ||
77 !strcasecmp(str, "enable")) {
87 lnet_parse_port(int *port, char *str)
91 *port = strtol(str, &end, 0);
93 if (*end == 0 && /* parsed whole string */
94 *port > 0 && *port < 65536) /* minimal sanity check */
100 #ifdef HAVE_GETHOSTBYNAME
101 static struct hostent *
102 ptl_gethostbyname(char *hname)
106 he = gethostbyname(hname);
111 fprintf(stderr, "Unable to resolve hostname: %s\n",
115 fprintf(stderr, "gethostbyname error for %s: %s\n",
116 hname, strerror(h_errno));
126 lnet_parse_ipquad(__u32 *ipaddrp, char *str)
130 if (sscanf(str, "%d.%d.%d.%d", &a, &b, &c, &d) == 4 &&
131 (a & ~0xff) == 0 && (b & ~0xff) == 0 &&
132 (c & ~0xff) == 0 && (d & ~0xff) == 0) {
133 *ipaddrp = (a << 24) | (b << 16) | (c << 8) | d;
142 lnet_parse_ipaddr(__u32 *ipaddrp, char *str)
144 #ifdef HAVE_GETHOSTBYNAME
148 if (!strcmp(str, "_all_")) {
153 if (lnet_parse_ipquad(ipaddrp, str) == 0)
156 #ifdef HAVE_GETHOSTBYNAME
157 if ((('a' <= str[0] && str[0] <= 'z') ||
158 ('A' <= str[0] && str[0] <= 'Z')) &&
159 (he = ptl_gethostbyname(str)) != NULL) {
160 __u32 addr = *(__u32 *)he->h_addr;
162 *ipaddrp = ntohl(addr); /* HOST byte order */
171 ptl_ipaddr_2_str(__u32 ipaddr, char *str, size_t strsize, int lookup)
173 #ifdef HAVE_GETHOSTBYNAME
178 net_ip = htonl(ipaddr);
179 he = gethostbyaddr(&net_ip, sizeof(net_ip), AF_INET);
181 snprintf(str, strsize, "%s", he->h_name);
187 sprintf(str, "%d.%d.%d.%d",
188 (ipaddr >> 24) & 0xff, (ipaddr >> 16) & 0xff,
189 (ipaddr >> 8) & 0xff, ipaddr & 0xff);
194 lnet_parse_time(time_t *t, char *str)
200 *t = strtol(str, &end, 0);
201 if (*end == 0) /* parsed whole string */
204 memset(&tm, 0, sizeof(tm));
205 n = sscanf(str, "%d-%d-%d-%d:%d:%d",
206 &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
207 &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
211 tm.tm_mon--; /* convert to 0 == Jan */
212 tm.tm_year -= 1900; /* y2k quirk */
213 tm.tm_isdst = -1; /* dunno if it's daylight savings... */
216 if (*t == (time_t)-1)
223 lnet_parse_nid(char *nid_str, struct lnet_process_id *id_ptr)
225 id_ptr->pid = LNET_PID_ANY;
226 id_ptr->nid = libcfs_str2nid(nid_str);
227 if (id_ptr->nid == LNET_NID_ANY) {
228 fprintf(stderr, "Can't parse nid \"%s\"\n", nid_str);
235 static int g_net_is_set(char *cmd)
243 if (g_net_interactive)
249 "You must run '%s <network>' command before '%s'\n",
257 static int g_net_is_compatible(char *cmd, ...)
262 if (!g_net_is_set(cmd))
268 nal = va_arg(ap, int);
269 if (nal == LNET_NETTYP(g_net)) {
278 fprintf(stderr, "Command %s not compatible with %s NAL\n",
279 cmd, libcfs_lnd2str(LNET_NETTYP(g_net)));
284 int ptl_initialize(int argc, char **argv)
287 g_net_interactive = true;
289 register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
294 int jt_ptl_network(int argc, char **argv)
296 struct libcfs_ioctl_data data;
297 __u32 net = LNET_NET_ANY;
301 fprintf(stderr, "usage: %s <net>|up|down\n", argv[0]);
305 if (!strcmp(argv[1], "unconfigure") || !strcmp(argv[1], "down")) {
306 LIBCFS_IOC_INIT(data);
307 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_UNCONFIGURE, &data);
310 printf("LNET ready to unload\n");
314 if (errno == ENODEV) {
315 printf("LNET is currently not loaded.");
320 fprintf(stderr, "LNET busy\n");
322 fprintf(stderr, "LNET unconfigure error %d: %s\n",
323 errno, strerror(errno));
325 } else if (!strcmp(argv[1], "configure") || !strcmp(argv[1], "up")) {
326 LIBCFS_IOC_INIT(data);
327 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIGURE, &data);
330 printf("LNET configured\n");
334 fprintf(stderr, "LNET configure error %d: %s\n",
335 errno, strerror(errno));
339 net = libcfs_str2net(argv[1]);
340 if (net == LNET_NET_ANY) {
341 fprintf(stderr, "Can't parse net %s\n", argv[1]);
350 #ifndef IOC_LIBCFS_GET_NI
351 #define IOC_LIBCFS_GET_NI _IOWR('e', 50, IOCTL_LIBCFS_TYPE)
355 jt_ptl_list_nids(int argc, char **argv)
357 int all = 0, return_nid = 0;
358 yaml_emitter_t request;
365 all = (argc == 2) && (strcmp(argv[1], "all") == 0);
366 /* Hack to pass back value */
367 return_nid = (argc == 2) && (argv[1][0] == 1);
369 if ((argc > 2) && !(all || return_nid)) {
370 fprintf(stderr, "usage: %s [all]\n", argv[0]);
374 sk = nl_socket_alloc();
378 /* Setup parser to receive Netlink packets */
379 rc = yaml_parser_initialize(&reply);
381 yaml_parser_log_error(&reply, stderr, NULL);
385 rc = yaml_parser_set_input_netlink(&reply, sk, false);
387 yaml_parser_log_error(&reply, stderr, NULL);
388 yaml_parser_delete(&reply);
392 /* Create Netlink emitter to send request to kernel */
393 rc = yaml_emitter_initialize(&request);
395 yaml_parser_log_error(&reply, stderr, NULL);
396 yaml_parser_delete(&reply);
400 rc = yaml_emitter_set_output_netlink(&request, sk, LNET_GENL_NAME, 1,
401 LNET_CMD_NETS, NLM_F_DUMP);
403 yaml_emitter_log_error(&request, stderr);
404 yaml_emitter_delete(&request);
405 yaml_parser_delete(&reply);
409 yaml_emitter_open(&request);
410 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
411 rc = yaml_emitter_emit(&request, &event);
415 yaml_mapping_start_event_initialize(&event, NULL,
416 (yaml_char_t *)YAML_MAP_TAG,
417 1, YAML_ANY_MAPPING_STYLE);
418 rc = yaml_emitter_emit(&request, &event);
422 yaml_scalar_event_initialize(&event, NULL,
423 (yaml_char_t *)YAML_STR_TAG,
424 (yaml_char_t *)"net",
426 YAML_PLAIN_SCALAR_STYLE);
427 rc = yaml_emitter_emit(&request, &event);
432 if (!g_net_set || g_net == LNET_NET_ANY) {
433 yaml_scalar_event_initialize(&event, NULL,
434 (yaml_char_t *)YAML_STR_TAG,
437 YAML_PLAIN_SCALAR_STYLE);
438 rc = yaml_emitter_emit(&request, &event);
442 char *net_id = libcfs_net2str(g_net);
444 yaml_sequence_start_event_initialize(&event, NULL,
445 (yaml_char_t *)YAML_SEQ_TAG,
446 1, YAML_ANY_SEQUENCE_STYLE);
447 rc = yaml_emitter_emit(&request, &event);
451 yaml_mapping_start_event_initialize(&event, NULL,
452 (yaml_char_t *)YAML_MAP_TAG,
453 1, YAML_ANY_MAPPING_STYLE);
454 rc = yaml_emitter_emit(&request, &event);
458 yaml_scalar_event_initialize(&event, NULL,
459 (yaml_char_t *)YAML_STR_TAG,
460 (yaml_char_t *)"net type",
462 1, 0, YAML_PLAIN_SCALAR_STYLE);
463 rc = yaml_emitter_emit(&request, &event);
467 yaml_scalar_event_initialize(&event, NULL,
468 (yaml_char_t *)YAML_STR_TAG,
469 (yaml_char_t *)net_id,
470 strlen(net_id), 1, 0,
471 YAML_PLAIN_SCALAR_STYLE);
472 rc = yaml_emitter_emit(&request, &event);
476 yaml_mapping_end_event_initialize(&event);
477 rc = yaml_emitter_emit(&request, &event);
481 yaml_sequence_end_event_initialize(&event);
482 rc = yaml_emitter_emit(&request, &event);
486 yaml_mapping_end_event_initialize(&event);
487 rc = yaml_emitter_emit(&request, &event);
491 yaml_document_end_event_initialize(&event, 0);
492 rc = yaml_emitter_emit(&request, &event);
496 rc = yaml_emitter_close(&request);
499 yaml_emitter_log_error(&request, stderr);
502 yaml_emitter_delete(&request);
505 rc = yaml_parser_parse(&reply, &event);
509 if (event.type == YAML_SCALAR_EVENT &&
510 strcmp((char *)event.data.scalar.value, "nid") == 0) {
513 yaml_event_delete(&event);
514 rc = yaml_parser_parse(&reply, &event);
516 yaml_event_delete(&event);
520 tmp = (char *)event.data.scalar.value;
521 if (all || strcmp(tmp, "0@lo") != 0) {
524 *(__u64 *)(argv[1]) = libcfs_str2nid(tmp);
529 done = (event.type == YAML_STREAM_END_EVENT);
530 yaml_event_delete(&event);
534 yaml_parser_log_error(&reply, stderr, NULL);
535 yaml_parser_delete(&reply);
537 #ifdef IOC_LIBCFS_GET_NI
545 for (count = 0;; count++) {
546 struct libcfs_ioctl_data data;
548 LIBCFS_IOC_INIT(data);
549 data.ioc_count = count;
550 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_NI, &data);
553 if ((count > 0) && (errno == ENOENT))
554 /* We found them all */
556 fprintf(stderr, "IOC_LIBCFS_GET_NI error %d: %s\n",
557 errno, strerror(errno));
561 if (all || (data.ioc_nid != LNET_NID_LO_0)) {
562 printf("%s\n", libcfs_nid2str(data.ioc_nid));
564 *(__u64 *)(argv[1]) = data.ioc_nid;
578 jt_ptl_which_nid(int argc, char **argv)
580 struct libcfs_ioctl_data data;
583 lnet_nid_t best_nid = LNET_NID_ANY;
592 fprintf(stderr, "usage: %s NID [NID...]\n", argv[0]);
596 for (i = 1; i < argc; i++) {
598 nid = libcfs_str2nid(nidstr);
599 if (nid == LNET_NID_ANY) {
600 fprintf(stderr, "Can't parse NID %s\n", nidstr);
604 LIBCFS_IOC_INIT(data);
607 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNET_DIST, &data);
609 fprintf(stderr, "Can't get distance to %s: %s\n",
610 nidstr, strerror(errno));
614 dist = data.ioc_u32[0];
615 order = data.ioc_u32[1];
618 if (dist == -EHOSTUNREACH)
621 fprintf(stderr, "Unexpected distance to %s: %d\n",
626 if (best_nid == LNET_NID_ANY ||
628 (dist == best_dist && order < best_order)) {
635 if (best_nid == LNET_NID_ANY) {
636 fprintf(stderr, "No reachable NID\n");
640 printf("%s\n", libcfs_nid2str(best_nid));
645 jt_ptl_print_interfaces(int argc, char **argv)
647 struct libcfs_ioctl_data data;
648 char buffer[3][HOST_NAME_MAX + 1];
652 if (!g_net_is_compatible(argv[0], SOCKLND, 0))
655 for (index = 0; ; index++) {
656 LIBCFS_IOC_INIT(data);
657 data.ioc_net = g_net;
658 data.ioc_count = index;
660 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_INTERFACE, &data);
664 printf("%s: (%s/%s) npeer %d nroute %d\n",
665 ptl_ipaddr_2_str(data.ioc_u32[0], buffer[2],
666 sizeof(buffer[2]), 1),
667 ptl_ipaddr_2_str(data.ioc_u32[0], buffer[0],
668 sizeof(buffer[0]), 0),
669 ptl_ipaddr_2_str(data.ioc_u32[1], buffer[1],
670 sizeof(buffer[1]), 0),
671 data.ioc_u32[2], data.ioc_u32[3]);
675 if (errno == ENOENT) {
676 printf("<no interfaces>\n");
679 "Error getting interfaces: %s: check dmesg.\n",
688 jt_ptl_add_interface(int argc, char **argv)
690 struct libcfs_ioctl_data data;
693 __u32 netmask = 0xffffff00;
698 if (argc < 2 || argc > 3) {
699 fprintf(stderr, "usage: %s ipaddr [netmask]\n", argv[0]);
703 if (!g_net_is_compatible(argv[0], SOCKLND, 0))
706 if (lnet_parse_ipaddr(&ipaddr, argv[1]) != 0) {
707 fprintf(stderr, "Can't parse ip: %s\n", argv[1]);
712 count = strtol(argv[2], &end, 0);
713 if (count > 0 && count < 32 && *end == 0) {
715 for (i = count; i > 0; i--)
716 netmask = netmask | (1 << (32 - i));
717 } else if (lnet_parse_ipquad(&netmask, argv[2]) != 0) {
718 fprintf(stderr, "Can't parse netmask: %s\n", argv[2]);
723 LIBCFS_IOC_INIT(data);
724 data.ioc_net = g_net;
725 data.ioc_u32[0] = ipaddr;
726 data.ioc_u32[1] = netmask;
728 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_INTERFACE, &data);
730 fprintf(stderr, "failed to add interface: %s\n",
739 jt_ptl_del_interface(int argc, char **argv)
741 struct libcfs_ioctl_data data;
746 fprintf(stderr, "usage: %s [ipaddr]\n", argv[0]);
750 if (!g_net_is_compatible(argv[0], SOCKLND, 0))
754 lnet_parse_ipaddr(&ipaddr, argv[1]) != 0) {
755 fprintf(stderr, "Can't parse ip: %s\n", argv[1]);
759 LIBCFS_IOC_INIT(data);
760 data.ioc_net = g_net;
761 data.ioc_u32[0] = ipaddr;
763 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_INTERFACE, &data);
765 fprintf(stderr, "failed to delete interface: %s\n",
774 jt_ptl_print_peers(int argc, char **argv)
776 struct libcfs_ioctl_data data;
777 struct lnet_process_id id;
778 char buffer[2][HOST_NAME_MAX + 1];
782 if (!g_net_is_compatible(argv[0], SOCKLND, O2IBLND, GNILND,
786 for (index = 0; ; index++) {
787 LIBCFS_IOC_INIT(data);
788 data.ioc_net = g_net;
789 data.ioc_count = index;
791 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER, &data);
795 if (g_net_is_compatible(NULL, SOCKLND, 0)) {
796 id.nid = data.ioc_nid;
797 id.pid = data.ioc_u32[4];
798 printf("%-20s [%d]%s->%s:%d #%d\n",
800 data.ioc_count, /* persistence */
802 ptl_ipaddr_2_str(data.ioc_u32[2], buffer[0],
803 sizeof(buffer[0]), 1),
805 ptl_ipaddr_2_str(data.ioc_u32[0], buffer[1],
806 sizeof(buffer[1]), 1),
807 data.ioc_u32[1], /* peer port */
808 data.ioc_u32[3]); /* conn_count */
809 } else if (g_net_is_compatible(NULL, GNILND, 0)) {
810 int disconn = data.ioc_flags >> 16;
816 state = data.ioc_flags & 0xffff ? "C" : "U";
818 printf("%-20s (%d) %s [%d] %ju sq %d/%d tx %d/%d/%d\n",
819 libcfs_nid2str(data.ioc_nid), /* peer nid */
820 data.ioc_net, /* gemini device id */
821 state, /* peer is Connecting, Up, or Down */
822 data.ioc_count, /* peer refcount */
823 (uintmax_t)data.ioc_u64[0], /* peerstamp */
824 data.ioc_u32[2], data.ioc_u32[3], /* tx and rx seq */
825 /* fmaq, nfma, nrdma */
826 data.ioc_u32[0], data.ioc_u32[1],
829 printf("%-20s [%d]\n",
830 libcfs_nid2str(data.ioc_nid), data.ioc_count);
835 if (errno == ENOENT) {
836 printf("<no peers>\n");
839 "Error getting peer list: %s: check dmesg.\n",
846 int jt_ptl_add_peer(int argc, char **argv)
848 struct libcfs_ioctl_data data;
854 if (!g_net_is_compatible(argv[0], SOCKLND, GNILND, 0))
858 fprintf(stderr, "usage(tcp,gni): %s nid ipaddr port\n",
863 nid = libcfs_str2nid(argv[1]);
864 if (nid == LNET_NID_ANY) {
865 fprintf(stderr, "Can't parse NID: %s\n", argv[1]);
869 if (lnet_parse_ipaddr(&ip, argv[2]) != 0) {
870 fprintf(stderr, "Can't parse ip addr: %s\n", argv[2]);
874 if (lnet_parse_port(&port, argv[3]) != 0) {
875 fprintf(stderr, "Can't parse port: %s\n", argv[3]);
879 LIBCFS_IOC_INIT(data);
880 data.ioc_net = g_net;
882 data.ioc_u32[0] = ip;
883 data.ioc_u32[1] = port;
885 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_PEER, &data);
887 fprintf(stderr, "failed to add peer: %s\n",
896 jt_ptl_del_peer(int argc, char **argv)
898 struct libcfs_ioctl_data data;
899 lnet_nid_t nid = LNET_NID_ANY;
900 lnet_pid_t pid = LNET_PID_ANY;
904 if (!g_net_is_compatible(argv[0], SOCKLND, O2IBLND, GNILND,
908 if (g_net_is_compatible(NULL, SOCKLND, 0)) {
910 fprintf(stderr, "usage: %s [nid] [ipaddr]\n", argv[0]);
913 } else if (argc > 2) {
914 fprintf(stderr, "usage: %s [nid]\n", argv[0]);
918 if (argc > 1 && !libcfs_str2anynid(&nid, argv[1])) {
919 fprintf(stderr, "Can't parse nid: %s\n", argv[1]);
923 if (g_net_is_compatible(NULL, SOCKLND, 0)) {
924 if (argc > 2 && lnet_parse_ipaddr(&ip, argv[2]) != 0) {
925 fprintf(stderr, "Can't parse ip addr: %s\n", argv[2]);
930 LIBCFS_IOC_INIT(data);
931 data.ioc_net = g_net;
933 data.ioc_u32[0] = ip;
934 data.ioc_u32[1] = pid;
936 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_PEER, &data);
938 fprintf(stderr, "failed to remove peer: %s\n", strerror(errno));
946 jt_ptl_print_connections(int argc, char **argv)
948 struct libcfs_ioctl_data data;
949 struct lnet_process_id id;
950 char buffer[2][HOST_NAME_MAX + 1];
954 if (!g_net_is_compatible(argv[0], SOCKLND, O2IBLND, GNILND, 0))
957 for (index = 0; ; index++) {
958 LIBCFS_IOC_INIT(data);
959 data.ioc_net = g_net;
960 data.ioc_count = index;
962 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_CONN, &data);
966 if (g_net_is_compatible(NULL, SOCKLND, 0)) {
967 id.nid = data.ioc_nid;
968 id.pid = data.ioc_u32[6];
969 printf("%-20s %s[%d]%s->%s:%d %d/%d %s\n",
971 (data.ioc_u32[3] == SOCKLND_CONN_ANY) ? "A" :
972 (data.ioc_u32[3] == SOCKLND_CONN_CONTROL) ? "C" :
973 (data.ioc_u32[3] == SOCKLND_CONN_BULK_IN) ? "I" :
974 (data.ioc_u32[3] == SOCKLND_CONN_BULK_OUT) ? "O" : "?",
975 data.ioc_u32[4], /* scheduler */
977 ptl_ipaddr_2_str(data.ioc_u32[2], buffer[0],
978 sizeof(buffer[0]), 1),
980 ptl_ipaddr_2_str(data.ioc_u32[0], buffer[1],
981 sizeof(buffer[1]), 1),
982 data.ioc_u32[1], /* remote port */
983 data.ioc_count, /* tx buffer size */
984 data.ioc_u32[5], /* rx buffer size */
985 data.ioc_flags ? "nagle" : "nonagle");
986 } else if (g_net_is_compatible(NULL, O2IBLND, 0)) {
987 printf("%s mtu %d\n",
988 libcfs_nid2str(data.ioc_nid),
989 data.ioc_u32[0]); /* path MTU */
990 } else if (g_net_is_compatible(NULL, GNILND, 0)) {
991 printf("%-20s [%d]\n",
992 libcfs_nid2str(data.ioc_nid),
993 data.ioc_u32[0] /* device id */);
995 printf("%s\n", libcfs_nid2str(data.ioc_nid));
1000 if (errno == ENOENT) {
1001 printf("<no connections>\n");
1004 "Error getting connection list: %s: check dmesg.\n",
1011 int jt_ptl_disconnect(int argc, char **argv)
1013 struct libcfs_ioctl_data data;
1014 lnet_nid_t nid = LNET_NID_ANY;
1019 fprintf(stderr, "usage: %s [nid] [ipaddr]\n", argv[0]);
1023 if (!g_net_is_compatible(NULL, SOCKLND, O2IBLND, GNILND, 0))
1026 if (argc >= 2 && !libcfs_str2anynid(&nid, argv[1])) {
1027 fprintf(stderr, "Can't parse nid %s\n", argv[1]);
1031 if (g_net_is_compatible(NULL, SOCKLND, 0) && argc >= 3 &&
1032 lnet_parse_ipaddr(&ipaddr, argv[2]) != 0) {
1033 fprintf(stderr, "Can't parse ip addr %s\n", argv[2]);
1037 LIBCFS_IOC_INIT(data);
1038 data.ioc_net = g_net;
1040 data.ioc_u32[0] = ipaddr;
1042 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CLOSE_CONNECTION, &data);
1044 fprintf(stderr, "failed to remove connection: %s\n",
1052 int jt_ptl_push_connection(int argc, char **argv)
1054 struct libcfs_ioctl_data data;
1056 lnet_nid_t nid = LNET_NID_ANY;
1059 fprintf(stderr, "usage: %s [nid]\n", argv[0]);
1063 if (!g_net_is_compatible(argv[0], SOCKLND, GNILND, 0))
1066 if (argc > 1 && !libcfs_str2anynid(&nid, argv[1])) {
1067 fprintf(stderr, "Can't parse nid: %s\n", argv[1]);
1071 LIBCFS_IOC_INIT(data);
1072 data.ioc_net = g_net;
1075 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_PUSH_CONNECTION, &data);
1077 fprintf(stderr, "failed to push connection: %s\n",
1085 #ifndef IOC_LIBCFS_PING_PEER
1086 #define IOC_LIBCFS_PING_PEER _IOWR('e', 62, IOCTL_LIBCFS_TYPE)
1089 int jt_ptl_ping(int argc, char **argv)
1091 bool done = false, print = true;
1094 struct lnet_process_id id;
1095 yaml_emitter_t request;
1096 yaml_parser_t reply;
1102 fprintf(stderr, "usage: %s id [timeout (secs)]\n", argv[0]);
1106 sep = strchr(argv[1], '-');
1108 rc = lnet_parse_nid(argv[1], &id);
1114 if (argv[1][0] == 'u' || argv[1][0] == 'U')
1115 id.pid = strtoul(&argv[1][1], &end, 0) |
1118 id.pid = strtoul(argv[1], &end, 0);
1120 if (end != sep) { /* assuming '-' is part of hostname */
1121 rc = lnet_parse_nid(argv[1], &id);
1125 id.nid = libcfs_str2nid(sep + 1);
1127 if (id.nid == LNET_NID_ANY) {
1129 "Can't parse process id \"%s\"\n",
1137 timeout = 1000 * atol(argv[2]);
1138 if (timeout > 120 * 1000) {
1139 fprintf(stderr, "Timeout %s is to large\n",
1144 timeout = 1000; /* default 1 second timeout */
1147 /* Create Netlink emitter to send request to kernel */
1148 sk = nl_socket_alloc();
1152 /* Setup parser to recieve Netlink packets */
1153 rc = yaml_parser_initialize(&reply);
1157 rc = yaml_parser_set_input_netlink(&reply, sk, false);
1161 /* Create Netlink emitter to send request to kernel */
1162 rc = yaml_emitter_initialize(&request);
1166 rc = yaml_emitter_set_output_netlink(&request, sk, LNET_GENL_NAME,
1167 LNET_GENL_VERSION, LNET_CMD_PING,
1172 yaml_emitter_open(&request);
1173 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
1174 rc = yaml_emitter_emit(&request, &event);
1178 yaml_mapping_start_event_initialize(&event, NULL,
1179 (yaml_char_t *)YAML_MAP_TAG,
1180 1, YAML_ANY_MAPPING_STYLE);
1181 rc = yaml_emitter_emit(&request, &event);
1185 yaml_scalar_event_initialize(&event, NULL,
1186 (yaml_char_t *)YAML_STR_TAG,
1187 (yaml_char_t *)"ping",
1188 strlen("ping"), 1, 0,
1189 YAML_PLAIN_SCALAR_STYLE);
1190 rc = yaml_emitter_emit(&request, &event);
1194 yaml_mapping_start_event_initialize(&event, NULL,
1195 (yaml_char_t *)YAML_MAP_TAG,
1196 1, YAML_ANY_MAPPING_STYLE);
1197 rc = yaml_emitter_emit(&request, &event);
1201 if (timeout != 1000) {
1202 yaml_scalar_event_initialize(&event, NULL,
1203 (yaml_char_t *)YAML_STR_TAG,
1204 (yaml_char_t *)"timeout",
1205 strlen("timeout"), 1, 0,
1206 YAML_PLAIN_SCALAR_STYLE);
1207 rc = yaml_emitter_emit(&request, &event);
1211 yaml_scalar_event_initialize(&event, NULL,
1212 (yaml_char_t *)YAML_INT_TAG,
1213 (yaml_char_t *)argv[2],
1214 strlen(argv[2]), 1, 0,
1215 YAML_PLAIN_SCALAR_STYLE);
1216 rc = yaml_emitter_emit(&request, &event);
1221 yaml_scalar_event_initialize(&event, NULL,
1222 (yaml_char_t *)YAML_STR_TAG,
1223 (yaml_char_t *)"nids",
1224 strlen("nids"), 1, 0,
1225 YAML_PLAIN_SCALAR_STYLE);
1226 rc = yaml_emitter_emit(&request, &event);
1230 yaml_sequence_start_event_initialize(&event, NULL,
1231 (yaml_char_t *)YAML_SEQ_TAG,
1232 1, YAML_FLOW_SEQUENCE_STYLE);
1233 rc = yaml_emitter_emit(&request, &event);
1237 /* convert NID to string, in case libcfs_str2nid() did name lookup */
1238 yaml_scalar_event_initialize(&event, NULL,
1239 (yaml_char_t *)YAML_STR_TAG,
1240 (yaml_char_t *)libcfs_nid2str(id.nid),
1241 strlen(libcfs_nid2str(id.nid)), 1, 0,
1242 YAML_PLAIN_SCALAR_STYLE);
1243 rc = yaml_emitter_emit(&request, &event);
1247 yaml_sequence_end_event_initialize(&event);
1248 rc = yaml_emitter_emit(&request, &event);
1252 yaml_mapping_end_event_initialize(&event);
1253 rc = yaml_emitter_emit(&request, &event);
1257 yaml_mapping_end_event_initialize(&event);
1258 rc = yaml_emitter_emit(&request, &event);
1262 yaml_document_end_event_initialize(&event, 0);
1263 rc = yaml_emitter_emit(&request, &event);
1267 rc = yaml_emitter_close(&request);
1270 yaml_emitter_log_error(&request, stderr);
1274 yaml_emitter_delete(&request);
1276 /* Now parse the reply results */
1278 rc = yaml_parser_parse(&reply, &event);
1282 if (event.type != YAML_SCALAR_EVENT)
1285 if (strcmp((char *)event.data.scalar.value, "nid") == 0) {
1286 yaml_event_delete(&event);
1287 rc = yaml_parser_parse(&reply, &event);
1289 yaml_event_delete(&event);
1293 /* Print 0@lo. Its not sent */
1294 printf("12345-0@lo\n");
1297 printf("%s\n", (char *)event.data.scalar.value);
1298 } else if (strcmp((char *)event.data.scalar.value,
1300 yaml_event_delete(&event);
1301 rc = yaml_parser_parse(&reply, &event);
1303 yaml_event_delete(&event);
1306 rc = strtol((char *)event.data.scalar.value, NULL, 10);
1307 fprintf(stdout, "failed to ping %s: %s\n",
1308 argv[1], strerror(-rc));
1309 break; /* "rc" is clobbered if loop is run again */
1312 done = (event.type == YAML_STREAM_END_EVENT);
1313 yaml_event_delete(&event);
1317 /* yaml_* functions return 0 for error */
1318 const char *msg = yaml_parser_get_reader_error(&reply);
1320 rc = errno ? -errno : -EHOSTUNREACH;
1321 if (strcmp(msg, "Unspecific failure") != 0) {
1322 fprintf(stdout, "failed to ping %s: %s\n",
1325 fprintf(stdout, "failed to ping %s: %s\n",
1326 argv[1], strerror(errno));
1328 } else if (rc == 1) {
1329 /* yaml_* functions return 1 for success */
1332 yaml_parser_delete(&reply);
1336 #ifdef IOC_LIBCFS_PING_PEER
1338 struct lnet_process_id ids[LNET_INTERFACES_MAX_DEFAULT];
1339 int maxids = sizeof(ids) / sizeof(ids[0]);
1340 struct lnet_ioctl_ping_data ping = { { 0 } };
1346 LIBCFS_IOC_INIT_V2(ping, ping_hdr);
1347 ping.ping_hdr.ioc_len = sizeof(ping);
1349 ping.ping_src = LNET_NID_ANY;
1350 ping.op_param = timeout;
1351 ping.ping_count = maxids;
1352 ping.ping_buf = ids;
1354 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_PING_PEER, &ping);
1356 fprintf(stderr, "failed to ping %s: %s\n", argv[1],
1361 for (i = 0; i < ping.ping_count && i < maxids; i++)
1362 printf("%s\n", libcfs_id2str(ids[i]));
1364 if (ping.ping_count > maxids)
1365 printf("%d out of %d ids listed\n", maxids, ping.ping_count);
1373 int jt_ptl_mynid(int argc, char **argv)
1375 struct libcfs_ioctl_data data;
1380 fprintf(stderr, "usage: %s NID\n", argv[0]);
1384 nid = libcfs_str2nid(argv[1]);
1385 if (nid == LNET_NID_ANY) {
1386 fprintf(stderr, "Can't parse NID '%s'\n", argv[1]);
1390 LIBCFS_IOC_INIT(data);
1391 data.ioc_net = LNET_NIDNET(nid);
1394 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_REGISTER_MYNID, &data);
1396 fprintf(stderr, "setting my NID failed: %s\n",
1399 printf("registered my nid %s\n", libcfs_nid2str(nid));
1405 jt_ptl_fail_nid(int argc, char **argv)
1410 struct libcfs_ioctl_data data;
1412 if (argc < 2 || argc > 3) {
1413 fprintf(stderr, "usage: %s nid|\"*\" [count (0 == mend)]\n",
1418 if (!libcfs_str2anynid(&nid, argv[1])) {
1419 fprintf(stderr, "Can't parse nid \"%s\"\n", argv[1]);
1424 threshold = LNET_MD_THRESH_INF;
1425 } else if (sscanf(argv[2], "%i", &threshold) != 1) {
1426 fprintf(stderr, "Can't parse count \"%s\"\n", argv[2]);
1430 LIBCFS_IOC_INIT(data);
1432 data.ioc_count = threshold;
1434 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_FAIL_NID, &data);
1436 fprintf(stderr, "IOC_LIBCFS_FAIL_NID failed: %s\n",
1440 threshold == 0 ? "Unfailing" : "Failing", argv[1]);
1446 jt_ptl_add_route(int argc, char **argv)
1448 struct lnet_ioctl_config_data data;
1449 lnet_nid_t gateway_nid;
1450 __u32 hops = LNET_UNDEFINED_HOPS;
1451 unsigned int priority = 0;
1455 if (argc < 2 || argc > 4) {
1456 fprintf(stderr, "usage: %s gateway [hopcount [priority]]\n",
1461 if (g_net_is_set(argv[0]) == 0)
1464 gateway_nid = libcfs_str2nid(argv[1]);
1465 if (gateway_nid == LNET_NID_ANY) {
1466 fprintf(stderr, "Can't parse gateway NID \"%s\"\n", argv[1]);
1471 hops = strtol(argv[2], &end, 0);
1472 if (hops == 0 || hops >= 256 ||
1473 (end && *end != 0)) {
1474 fprintf(stderr, "Can't parse hopcount \"%s\"\n",
1479 priority = strtoul(argv[3], &end, 0);
1480 if (end && *end != 0) {
1482 "Can't parse priority \"%s\"\n",
1489 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1490 data.cfg_net = g_net;
1491 data.cfg_config_u.cfg_route.rtr_hop = hops;
1492 data.cfg_nid = gateway_nid;
1493 data.cfg_config_u.cfg_route.rtr_priority = priority;
1495 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data);
1497 fprintf(stderr, "IOC_LIBCFS_ADD_ROUTE failed: %s\n",
1506 jt_ptl_del_route(int argc, char **argv)
1508 struct lnet_ioctl_config_data data;
1513 fprintf(stderr, "usage: %s gatewayNID\n", argv[0]);
1517 if (libcfs_str2anynid(&nid, argv[1]) == 0) {
1518 fprintf(stderr, "Can't parse gateway NID \"%s\"\n", argv[1]);
1522 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1523 data.cfg_net = g_net_set ? g_net : LNET_NET_ANY;
1526 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data);
1528 fprintf(stderr, "IOC_LIBCFS_DEL_ROUTE (%s) failed: %s\n",
1529 libcfs_nid2str(nid), strerror(errno));
1537 jt_ptl_notify_router(int argc, char **argv)
1539 struct libcfs_ioctl_data data;
1547 fprintf(stderr, "usage: %s targetNID <up/down> [<time>]\n",
1552 nid = libcfs_str2nid(argv[1]);
1553 if (nid == LNET_NID_ANY) {
1554 fprintf(stderr, "Can't parse target NID \"%s\"\n", argv[1]);
1558 if (lnet_parse_bool (&enable, argv[2]) != 0) {
1559 fprintf(stderr, "Can't parse boolean %s\n", argv[2]);
1563 gettimeofday(&now, NULL);
1567 } else if (lnet_parse_time(&when, argv[3]) != 0) {
1569 "Can't parse time %s\n Please specify either 'YYYY-MM-DD-HH:MM:SS'\n or an absolute unix time in seconds\n",
1572 } else if (when > now.tv_sec) {
1573 fprintf(stderr, "%s specifies a time in the future\n",
1578 LIBCFS_IOC_INIT(data);
1580 data.ioc_flags = enable;
1581 /* Yeuch; 'cept I need a __u64 on 64 bit machines... */
1582 data.ioc_u64[0] = (__u64)when;
1584 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_NOTIFY_ROUTER, &data);
1586 fprintf(stderr, "IOC_LIBCFS_NOTIFY_ROUTER (%s) failed: %s\n",
1587 libcfs_nid2str(nid), strerror(errno));
1595 jt_ptl_print_routes(int argc, char **argv)
1597 struct lnet_ioctl_config_data data;
1606 for (index = 0; ; index++) {
1607 LIBCFS_IOC_INIT_V2(data, cfg_hdr);
1608 data.cfg_count = index;
1610 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
1615 hops = data.cfg_config_u.cfg_route.rtr_hop;
1617 alive = data.cfg_config_u.cfg_route.rtr_flags & LNET_RT_ALIVE;
1618 pri = data.cfg_config_u.cfg_route.rtr_priority;
1620 printf("net %18s hops %u gw %32s %s pri %u\n",
1621 libcfs_net2str(net), hops,
1622 libcfs_nid2str(nid), alive ? "up" : "down", pri);
1625 if (errno != ENOENT)
1626 fprintf(stderr, "Error getting routes: %s: check dmesg.\n",
1633 fault_attr_nid_parse(char *str, lnet_nid_t *nid_p)
1639 /* NB: can't support range ipaddress except * and *@net */
1640 if (strlen(str) > 2 && str[0] == '*' && str[1] == '@') {
1641 net = libcfs_str2net(str + 2);
1642 if (net == LNET_NET_ANY)
1645 nid = LNET_MKNID(net, LNET_NIDADDR(LNET_NID_ANY));
1647 rc = libcfs_str2anynid(&nid, str);
1655 fprintf(stderr, "Invalid NID : %s\n", str);
1660 fault_attr_msg_parse(char *msg_str, __u32 *mask_p)
1662 if (!strcasecmp(msg_str, "put")) {
1663 *mask_p |= LNET_PUT_BIT;
1666 } else if (!strcasecmp(msg_str, "ack")) {
1667 *mask_p |= LNET_ACK_BIT;
1670 } else if (!strcasecmp(msg_str, "get")) {
1671 *mask_p |= LNET_GET_BIT;
1674 } else if (!strcasecmp(msg_str, "reply")) {
1675 *mask_p |= LNET_REPLY_BIT;
1679 fprintf(stderr, "unknown message type %s\n", msg_str);
1684 fault_attr_ptl_parse(char *ptl_str, __u64 *mask_p)
1686 unsigned long rc = strtoul(optarg, NULL, 0);
1689 fprintf(stderr, "invalid portal: %lu\n", rc);
1693 *mask_p |= (1ULL << rc);
1698 fault_attr_health_error_parse(char *error, __u32 *mask)
1700 if (!strcasecmp(error, "local_interrupt")) {
1701 *mask |= HSTATUS_LOCAL_INTERRUPT_BIT;
1704 if (!strcasecmp(error, "local_dropped")) {
1705 *mask |= HSTATUS_LOCAL_DROPPED_BIT;
1708 if (!strcasecmp(error, "local_aborted")) {
1709 *mask |= HSTATUS_LOCAL_ABORTED_BIT;
1712 if (!strcasecmp(error, "local_no_route")) {
1713 *mask |= HSTATUS_LOCAL_NO_ROUTE_BIT;
1716 if (!strcasecmp(error, "local_error")) {
1717 *mask |= HSTATUS_LOCAL_ERROR_BIT;
1720 if (!strcasecmp(error, "local_timeout")) {
1721 *mask |= HSTATUS_LOCAL_TIMEOUT_BIT;
1724 if (!strcasecmp(error, "remote_error")) {
1725 *mask |= HSTATUS_REMOTE_ERROR_BIT;
1728 if (!strcasecmp(error, "remote_dropped")) {
1729 *mask |= HSTATUS_REMOTE_DROPPED_BIT;
1732 if (!strcasecmp(error, "remote_timeout")) {
1733 *mask |= HSTATUS_REMOTE_TIMEOUT_BIT;
1736 if (!strcasecmp(error, "network_timeout")) {
1737 *mask |= HSTATUS_NETWORK_TIMEOUT_BIT;
1740 if (!strcasecmp(error, "random")) {
1741 *mask = HSTATUS_RANDOM;
1749 fault_simul_rule_add(__u32 opc, char *name, int argc, char **argv)
1751 struct libcfs_ioctl_data data = { { 0 } };
1752 struct lnet_fault_attr attr;
1756 static const struct option opts[] = {
1757 { .name = "source", .has_arg = required_argument, .val = 's' },
1758 { .name = "dest", .has_arg = required_argument, .val = 'd' },
1759 { .name = "rate", .has_arg = required_argument, .val = 'r' },
1760 { .name = "interval", .has_arg = required_argument, .val = 'i' },
1761 { .name = "random", .has_arg = no_argument, .val = 'n' },
1762 { .name = "latency", .has_arg = required_argument, .val = 'l' },
1763 { .name = "portal", .has_arg = required_argument, .val = 'p' },
1764 { .name = "message", .has_arg = required_argument, .val = 'm' },
1765 { .name = "health_error", .has_arg = required_argument, .val = 'e' },
1766 { .name = "local_nid", .has_arg = required_argument, .val = 'o' },
1767 { .name = "drop_all", .has_arg = no_argument, .val = 'x' },
1772 "Failed, please provide source, destination and rate of rule\n");
1776 optstr = opc == LNET_CTL_DROP_ADD ? "s:d:o:r:i:p:m:e:nx" : "s:d:o:r:l:p:m:";
1777 memset(&attr, 0, sizeof(attr));
1779 int c = getopt_long(argc, argv, optstr, opts, NULL);
1786 rc = fault_attr_nid_parse(optarg, &attr.fa_local_nid);
1790 case 's': /* source NID/NET */
1791 rc = fault_attr_nid_parse(optarg, &attr.fa_src);
1796 case 'd': /* dest NID/NET */
1797 rc = fault_attr_nid_parse(optarg, &attr.fa_dst);
1802 case 'r': /* drop rate */
1803 if (opc == LNET_CTL_DROP_ADD)
1804 attr.u.drop.da_rate = strtoul(optarg, NULL, 0);
1806 attr.u.delay.la_rate = strtoul(optarg, NULL, 0);
1810 if (opc == LNET_CTL_DROP_ADD) {
1811 rc = fault_attr_health_error_parse(optarg,
1812 &attr.u.drop.da_health_error_mask);
1819 if (opc == LNET_CTL_DROP_ADD)
1820 attr.u.drop.da_drop_all = true;
1824 if (opc == LNET_CTL_DROP_ADD)
1825 attr.u.drop.da_random = true;
1828 case 'i': /* time interval (# seconds) for message drop */
1829 if (opc == LNET_CTL_DROP_ADD)
1830 attr.u.drop.da_interval = strtoul(optarg,
1833 attr.u.delay.la_interval = strtoul(optarg,
1837 case 'l': /* seconds to wait before activating rule */
1838 attr.u.delay.la_latency = strtoul(optarg, NULL, 0);
1841 case 'p': /* portal to filter */
1842 rc = fault_attr_ptl_parse(optarg, &attr.fa_ptl_mask);
1847 case 'm': /* message types to filter */
1848 rc = fault_attr_msg_parse(optarg, &attr.fa_msg_mask);
1854 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
1855 argv[0], argv[optind - 1]);
1861 if (opc == LNET_CTL_DROP_ADD) {
1862 /* NB: drop rate and interval are exclusive to each other */
1863 if (!((attr.u.drop.da_rate == 0) ^
1864 (attr.u.drop.da_interval == 0))) {
1866 "please provide either drop rate or interval but not both at the same time.\n");
1870 if (attr.u.drop.da_random &&
1871 attr.u.drop.da_interval == 0) {
1873 "please provide an interval to randomize\n");
1876 } else if (opc == LNET_CTL_DELAY_ADD) {
1877 if (!((attr.u.delay.la_rate == 0) ^
1878 (attr.u.delay.la_interval == 0))) {
1880 "please provide either delay rate or interval but not both at the same time.\n");
1884 if (attr.u.delay.la_latency == 0) {
1885 fprintf(stderr, "latency cannot be zero\n");
1890 if (attr.fa_src == 0 || attr.fa_dst == 0) {
1892 "Please provide both source and destination of %s rule\n",
1897 if (attr.fa_local_nid == 0)
1898 attr.fa_local_nid = LNET_NID_ANY;
1900 data.ioc_flags = opc;
1901 data.ioc_inllen1 = sizeof(attr);
1902 data.ioc_inlbuf1 = (char *)&attr;
1903 if (libcfs_ioctl_pack(&data, &ioc_buf, IOC_BUF_SIZE) != 0) {
1904 fprintf(stderr, "libcfs_ioctl_pack failed\n");
1908 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNET_FAULT, ioc_buf);
1910 fprintf(stderr, "add %s rule %s->%s failed: %s\n",
1911 name, libcfs_nid2str(attr.fa_src),
1912 libcfs_nid2str(attr.fa_dst), strerror(errno));
1916 printf("Added %s rule %s->%s (1/%d)\n",
1917 name, libcfs_nid2str(attr.fa_src), libcfs_nid2str(attr.fa_dst),
1918 opc == LNET_CTL_DROP_ADD ?
1919 attr.u.drop.da_rate : attr.u.delay.la_rate);
1928 jt_ptl_drop_add(int argc, char **argv)
1930 return fault_simul_rule_add(LNET_CTL_DROP_ADD, "drop", argc, argv);
1934 jt_ptl_delay_add(int argc, char **argv)
1936 return fault_simul_rule_add(LNET_CTL_DELAY_ADD, "delay", argc, argv);
1940 fault_simul_rule_del(__u32 opc, char *name, int argc, char **argv)
1942 struct libcfs_ioctl_data data = { { 0 } };
1943 struct lnet_fault_attr attr;
1947 static const struct option opts[] = {
1948 { .name = "source", .has_arg = required_argument, .val = 's' },
1949 { .name = "dest", .has_arg = required_argument, .val = 'd' },
1950 { .name = "all", .has_arg = no_argument, .val = 'a' },
1955 "Failed, please provide source and destination of rule\n");
1959 memset(&attr, 0, sizeof(attr));
1961 int c = getopt_long(argc, argv, "s:d:a", opts, NULL);
1968 rc = fault_attr_nid_parse(optarg, &attr.fa_src);
1973 rc = fault_attr_nid_parse(optarg, &attr.fa_dst);
1984 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
1985 argv[0], argv[optind - 1]);
1991 data.ioc_flags = opc;
1992 data.ioc_inllen1 = sizeof(attr);
1993 data.ioc_inlbuf1 = (char *)&attr;
1994 if (libcfs_ioctl_pack(&data, &ioc_buf, IOC_BUF_SIZE) != 0) {
1995 fprintf(stderr, "libcfs_ioctl_pack failed\n");
1999 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNET_FAULT, ioc_buf);
2001 fprintf(stderr, "remove %s rule %s->%s failed: %s\n", name,
2002 all ? "all" : libcfs_nid2str(attr.fa_src),
2003 all ? "all" : libcfs_nid2str(attr.fa_dst),
2008 libcfs_ioctl_unpack(&data, ioc_buf);
2009 printf("Removed %d %s rules\n", data.ioc_count, name);
2018 jt_ptl_drop_del(int argc, char **argv)
2020 return fault_simul_rule_del(LNET_CTL_DROP_DEL, "drop", argc, argv);
2024 jt_ptl_delay_del(int argc, char **argv)
2026 return fault_simul_rule_del(LNET_CTL_DELAY_DEL, "delay", argc, argv);
2030 fault_simul_rule_reset(__u32 opc, char *name, int argc, char **argv)
2032 struct libcfs_ioctl_data data = { { 0 } };
2035 LIBCFS_IOC_INIT(data);
2036 data.ioc_flags = opc;
2038 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNET_FAULT, &data);
2040 fprintf(stderr, "failed to reset %s stats: %s\n",
2041 name, strerror(errno));
2048 jt_ptl_drop_reset(int argc, char **argv)
2050 return fault_simul_rule_reset(LNET_CTL_DROP_RESET, "drop", argc, argv);
2054 jt_ptl_delay_reset(int argc, char **argv)
2056 return fault_simul_rule_reset(LNET_CTL_DELAY_RESET, "delay",
2061 fault_simul_rule_list(__u32 opc, char *name, int argc, char **argv)
2063 struct libcfs_ioctl_data data = { { 0 } };
2064 struct lnet_fault_attr attr;
2065 struct lnet_fault_stat stat;
2068 printf("LNet %s rules:\n", name);
2069 for (pos = 0;; pos++) {
2072 memset(&attr, 0, sizeof(attr));
2073 memset(&stat, 0, sizeof(stat));
2075 data.ioc_count = pos;
2076 data.ioc_flags = opc;
2077 data.ioc_inllen1 = sizeof(attr);
2078 data.ioc_inlbuf1 = (char *)&attr;
2079 data.ioc_inllen2 = sizeof(stat);
2080 data.ioc_inlbuf2 = (char *)&stat;
2081 if (libcfs_ioctl_pack(&data, &ioc_buf, IOC_BUF_SIZE) != 0) {
2082 fprintf(stderr, "libcfs_ioctl_pack failed\n");
2086 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNET_FAULT, ioc_buf);
2090 libcfs_ioctl_unpack(&data, ioc_buf);
2092 if (opc == LNET_CTL_DROP_LIST) {
2093 printf("%s->%s (1/%d | %d) ptl %#jx, msg %x, %ju/%ju, PUT %ju, ACK %ju, GET %ju, REP %ju\n",
2094 libcfs_nid2str(attr.fa_src),
2095 libcfs_nid2str(attr.fa_dst),
2096 attr.u.drop.da_rate, attr.u.drop.da_interval,
2097 (uintmax_t)attr.fa_ptl_mask, attr.fa_msg_mask,
2098 (uintmax_t)stat.u.drop.ds_dropped,
2099 (uintmax_t)stat.fs_count,
2100 (uintmax_t)stat.fs_put,
2101 (uintmax_t)stat.fs_ack,
2102 (uintmax_t)stat.fs_get,
2103 (uintmax_t)stat.fs_reply);
2105 } else if (opc == LNET_CTL_DELAY_LIST) {
2106 printf("%s->%s (1/%d | %d, latency %d) ptl %#jx, msg %x, %ju/%ju, PUT %ju, ACK %ju, GET %ju, REP %ju\n",
2107 libcfs_nid2str(attr.fa_src),
2108 libcfs_nid2str(attr.fa_dst),
2109 attr.u.delay.la_rate, attr.u.delay.la_interval,
2110 attr.u.delay.la_latency,
2111 (uintmax_t)attr.fa_ptl_mask, attr.fa_msg_mask,
2112 (uintmax_t)stat.u.delay.ls_delayed,
2113 (uintmax_t)stat.fs_count,
2114 (uintmax_t)stat.fs_put,
2115 (uintmax_t)stat.fs_ack,
2116 (uintmax_t)stat.fs_get,
2117 (uintmax_t)stat.fs_reply);
2120 printf("found total %d\n", pos);
2126 jt_ptl_drop_list(int argc, char **argv)
2128 return fault_simul_rule_list(LNET_CTL_DROP_LIST, "drop", argc, argv);
2132 jt_ptl_delay_list(int argc, char **argv)
2134 return fault_simul_rule_list(LNET_CTL_DELAY_LIST, "delay", argc, argv);
2138 get_cycles_per_usec()
2140 FILE *f = fopen("/proc/cpuinfo", "r");
2145 while (fgets(line, sizeof(line), f))
2146 if (sscanf(line, "cpu MHz : %lf", &mhz) == 1) {
2153 fprintf(stderr, "Can't read/parse /proc/cpuinfo\n");
2157 int jt_ptl_testprotocompat(int argc, char **argv)
2159 struct libcfs_ioctl_data data;
2165 fprintf(stderr, "usage: %s <number>\n", argv[0]);
2169 flags = strtol(argv[1], &end, 0);
2170 if (flags < 0 || *end != 0) {
2171 fprintf(stderr, "Can't parse flags '%s'\n", argv[1]);
2175 LIBCFS_IOC_INIT(data);
2176 data.ioc_flags = flags;
2177 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_TESTPROTOCOMPAT, &data);
2180 fprintf(stderr, "test proto compat %x failed: %s\n",
2181 flags, strerror(errno));
2185 printf("test proto compat %x OK\n", flags);