4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/selftest/conctl.c
38 * Author: Liang Zhen <liangzhen@clusterfs.com>
48 #include <sys/ioctl.h>
51 #include <libcfs/list.h>
52 #include <libcfs/util/ioctl.h>
53 #include <libcfs/util/parser.h>
54 #include <lnet/lnetctl.h>
55 #include <lnet/lnetst.h>
56 #include <lnet/lnet.h>
57 #include <utils/obdctl.h>
59 lst_sid_t LST_INVALID_SID = {LNET_NID_ANY, -1};
60 static lst_sid_t session_id;
61 static int session_key;
63 /* All nodes running 2.6.50 or later understand feature LST_FEAT_BULK_LEN */
64 static unsigned session_features = LST_FEATS_MASK;
65 static lstcon_trans_stat_t trans_stat;
67 typedef struct list_string {
68 struct list_string *lstr_next;
74 # define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
77 static int alloc_count = 0;
78 static int alloc_nob = 0;
83 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
86 fprintf(stderr, "Can't allocate lstr\n");
93 lstr->lstr_str[0] = 0;
99 free_lstr(lstr_t *lstr)
102 alloc_nob -= lstr->lstr_sz;
107 free_lstrs(lstr_t **list)
111 while ((lstr = *list) != NULL) {
112 *list = lstr->lstr_next;
118 new_lstrs(lstr_t **list, char *prefix, char *postfix,
119 int lo, int hi, int stride)
121 int n1 = strlen(prefix);
122 int n2 = strlen(postfix);
123 int sz = n1 + 20 + n2 + 1;
126 lstr_t *n = alloc_lstr(sz);
128 snprintf(n->lstr_str, sz - 1, "%s%u%s",
129 prefix, lo, postfix);
131 n->lstr_next = *list;
139 expand_lstr(lstr_t **list, lstr_t *l)
141 int nob = strlen(l->lstr_str);
151 b1 = strchr(l->lstr_str, '[');
153 l->lstr_next = *list;
158 b2 = strchr(b1, ']');
159 if (b2 == NULL || b2 == b1 + 1)
167 sep = strchr(expr, ',');
173 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
175 new_lstrs(list, l->lstr_str, b2, x, x, 1);
180 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
183 new_lstrs(list, l->lstr_str, b2, x, y, 1);
188 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
191 new_lstrs(list, l->lstr_str, b2, x, y, z);
197 } while ((expr = sep) != NULL);
205 expand_strs(char *str, lstr_t **head)
213 l = alloc_lstr(strlen(str) + 1);
214 memcpy(l->lstr_str, str, strlen(str) + 1);
222 while ((l = list) != NULL) {
225 rc = expand_lstr(&nlist, l);
227 fprintf(stderr, "Syntax error in \"%s\"\n", str);
235 /* re-order onto 'list' */
236 while ((l = nlist) != NULL) {
237 nlist = l->lstr_next;
242 } while (expanded && rc > 0);
249 while ((l = list) != NULL) {
258 lst_parse_nids(char *str, int *countp, lnet_process_id_t **idspp)
266 rc = expand_strs(str, &head);
276 *idspp = malloc(c * sizeof(lnet_process_id_t));
277 if (*idspp == NULL) {
278 fprintf(stderr, "Out of memory\n");
285 while ((l = head) != NULL) {
289 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
290 if ((*idspp)[i].nid == LNET_NID_ANY) {
291 fprintf(stderr, "Invalid nid: %s\n",
296 (*idspp)[i].pid = LNET_PID_LUSTRE;
313 lst_node_state2str(int state)
315 if (state == LST_NODE_ACTIVE)
317 if (state == LST_NODE_BUSY)
319 if (state == LST_NODE_DOWN)
326 lst_node_str2state(char *str)
328 if (strcasecmp(str, "active") == 0)
329 return LST_NODE_ACTIVE;
330 if (strcasecmp(str, "busy") == 0)
331 return LST_NODE_BUSY;
332 if (strcasecmp(str, "down") == 0)
333 return LST_NODE_DOWN;
334 if (strcasecmp(str, "unknown") == 0)
335 return LST_NODE_UNKNOWN;
336 if (strcasecmp(str, "invalid") == 0)
337 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
343 lst_test_type2name(int type)
345 if (type == LST_TEST_PING)
347 if (type == LST_TEST_BULK)
354 lst_test_name2type(char *name)
356 if (strcasecmp(name, "ping") == 0)
357 return LST_TEST_PING;
358 if (strcasecmp(name, "brw") == 0)
359 return LST_TEST_BULK;
365 lst_print_usage(char *cmd)
367 Parser_printhelp(cmd);
371 lst_print_error(char *sub, const char *def_format, ...)
375 /* local error returned from kernel */
378 fprintf(stderr, "No session exists\n");
381 fprintf(stderr, "Session is shutting down\n");
384 fprintf(stderr, "Unmatched session key or not root\n");
387 fprintf(stderr, "Can't find %s in current session\n", sub);
390 fprintf(stderr, "Invalid parameters list in command line\n");
393 fprintf(stderr, "Bad parameter address\n");
396 fprintf(stderr, "%s already exists\n", sub);
399 va_start(ap, def_format);
400 vfprintf(stderr, def_format, ap);
408 lst_free_rpcent(struct list_head *head)
410 lstcon_rpc_ent_t *ent;
412 while (!list_empty(head)) {
413 ent = list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
415 list_del(&ent->rpe_link);
421 lst_reset_rpcent(struct list_head *head)
423 lstcon_rpc_ent_t *ent;
425 list_for_each_entry(ent, head, rpe_link) {
426 ent->rpe_sid = LST_INVALID_SID;
427 ent->rpe_peer.nid = LNET_NID_ANY;
428 ent->rpe_peer.pid = LNET_PID_ANY;
429 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
434 lst_alloc_rpcent(struct list_head *head, int count, int offset)
436 lstcon_rpc_ent_t *ent;
439 for (i = 0; i < count; i++) {
440 ent = malloc(offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
442 lst_free_rpcent(head);
446 memset(ent, 0, offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
448 ent->rpe_sid = LST_INVALID_SID;
449 ent->rpe_peer.nid = LNET_NID_ANY;
450 ent->rpe_peer.pid = LNET_PID_ANY;
451 list_add(&ent->rpe_link, head);
458 lst_print_transerr(struct list_head *head, char *optstr)
460 lstcon_rpc_ent_t *ent;
462 list_for_each_entry(ent, head, rpe_link) {
463 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
466 if (ent->rpe_rpc_errno != 0) {
467 fprintf(stderr, "%s RPC failed on %s: %s\n",
468 optstr, libcfs_id2str(ent->rpe_peer),
469 strerror(ent->rpe_rpc_errno));
473 fprintf(stderr, "operation %s failed on %s: %s\n",
474 optstr, libcfs_id2str(ent->rpe_peer),
475 strerror(ent->rpe_fwk_errno));
479 int lst_info_batch_ioctl(char *batch, int test, int server,
480 lstcon_test_batch_ent_t *entp, int *idxp,
481 int *ndentp, lstcon_node_ent_t *dentsp);
483 int lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
484 int *idx, int *count, lstcon_node_ent_t *dents);
486 int lst_query_batch_ioctl(char *batch, int test, int server,
487 int timeout, struct list_head *head);
490 lst_ioctl(unsigned int opc, void *buf, int len)
492 struct libcfs_ioctl_data data;
495 LIBCFS_IOC_INIT (data);
496 data.ioc_u32[0] = opc;
497 data.ioc_plen1 = len;
498 data.ioc_pbuf1 = (char *)buf;
499 data.ioc_plen2 = sizeof(trans_stat);
500 data.ioc_pbuf2 = (char *)&trans_stat;
502 memset(&trans_stat, 0, sizeof(trans_stat));
504 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
506 /* local error, no valid RPC result */
511 if (trans_stat.trs_rpc_errno != 0)
514 /* Framework error */
515 if (trans_stat.trs_fwk_errno != 0)
522 lst_new_session_ioctl(char *name, int timeout, int force, lst_sid_t *sid)
524 lstio_session_new_args_t args = {0};
526 args.lstio_ses_key = session_key;
527 args.lstio_ses_timeout = timeout;
528 args.lstio_ses_force = force;
529 args.lstio_ses_idp = sid;
530 args.lstio_ses_feats = session_features;
531 args.lstio_ses_nmlen = strlen(name);
532 args.lstio_ses_namep = name;
534 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
538 jt_lst_new_session(int argc, char **argv)
540 char buf[LST_NAME_SIZE];
548 static struct option session_opts[] =
550 {"timeout", required_argument, 0, 't' },
551 {"force", no_argument, 0, 'f' },
555 if (session_key == 0) {
557 "Can't find env LST_SESSION or value is not valid\n");
563 c = getopt_long(argc, argv, "ft:",
564 session_opts, &optidx);
574 timeout = atoi(optarg);
577 lst_print_usage(argv[0]);
583 fprintf(stderr, "Invalid timeout value\n");
587 if (optind == argc - 1) {
588 name = argv[optind ++];
589 if (strlen(name) >= LST_NAME_SIZE) {
590 fprintf(stderr, "Name size is limited to %d\n",
595 } else if (optind == argc) {
596 char user[LST_NAME_SIZE];
597 char host[LST_NAME_SIZE];
598 struct passwd *pw = getpwuid(getuid());
601 snprintf(user, sizeof(user), "%d", (int)getuid());
603 snprintf(user, sizeof(user), "%s", pw->pw_name);
605 rc = gethostname(host, sizeof(host));
607 snprintf(host, sizeof(host), "unknown_host");
609 snprintf(buf, sizeof(buf), "%s@%s", user, host);
613 lst_print_usage(argv[0]);
617 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
619 lst_print_error("session", "Failed to create session: %s\n",
624 fprintf(stdout, "SESSION: %s FEATURES: %x TIMEOUT: %d FORCE: %s\n",
625 name, session_features, timeout, force ? "Yes" : "No");
630 lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp,
631 lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
633 lstio_session_info_args_t args = {0};
635 args.lstio_ses_idp = sid;
636 args.lstio_ses_keyp = key;
637 args.lstio_ses_featp = featp;
638 args.lstio_ses_ndinfo = ndinfo;
639 args.lstio_ses_nmlen = len;
640 args.lstio_ses_namep = name;
642 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
646 jt_lst_show_session(int argc, char **argv)
648 lstcon_ndlist_ent_t ndinfo;
650 char name[LST_NAME_SIZE];
655 rc = lst_session_info_ioctl(name, sizeof(name), &key,
656 &feats, &sid, &ndinfo);
659 lst_print_error("session", "Failed to show session: %s\n",
664 fprintf(stdout, "%s ID: "LPU64"@%s, KEY: %d FEATURES: %x NODES: %d\n",
665 name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
666 key, feats, ndinfo.nle_nnode);
672 lst_end_session_ioctl(void)
674 lstio_session_end_args_t args = {0};
676 args.lstio_ses_key = session_key;
677 return lst_ioctl (LSTIO_SESSION_END, &args, sizeof(args));
681 jt_lst_end_session(int argc, char **argv)
685 if (session_key == 0) {
687 "Can't find env LST_SESSION or value is not valid\n");
691 rc = lst_end_session_ioctl();
694 fprintf(stdout, "session is ended\n");
699 lst_print_error("session", "Failed to end session: %s\n",
704 if (trans_stat.trs_rpc_errno != 0) {
706 "[RPC] Failed to send %d session RPCs: %s\n",
707 lstcon_rpc_stat_failure(&trans_stat, 0),
708 strerror(trans_stat.trs_rpc_errno));
711 if (trans_stat.trs_fwk_errno != 0) {
713 "[FWK] Failed to end session on %d nodes: %s\n",
714 lstcon_sesop_stat_failure(&trans_stat, 0),
715 strerror(trans_stat.trs_fwk_errno));
722 lst_ping_ioctl(char *str, int type, int timeout,
723 int count, lnet_process_id_t *ids, struct list_head *head)
725 lstio_debug_args_t args = {0};
727 args.lstio_dbg_key = session_key;
728 args.lstio_dbg_type = type;
729 args.lstio_dbg_flags = 0;
730 args.lstio_dbg_timeout = timeout;
731 args.lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str);
732 args.lstio_dbg_namep = str;
733 args.lstio_dbg_count = count;
734 args.lstio_dbg_idsp = ids;
735 args.lstio_dbg_resultp = head;
737 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
741 lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
743 char buf[LST_NAME_SIZE];
744 lstcon_test_batch_ent_t ent;
745 lstcon_ndlist_ent_t *entp = &ent.tbe_cli_nle;
752 case LST_OPC_SESSION:
753 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
754 &key, &feats, &sid, entp);
757 case LST_OPC_BATCHSRV:
758 entp = &ent.tbe_srv_nle;
759 case LST_OPC_BATCHCLI:
760 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
764 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
768 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
777 *countp = entp->nle_nnode;
783 jt_lst_ping(int argc, char **argv)
785 struct list_head head;
786 lnet_process_id_t *ids = NULL;
787 lstcon_rpc_ent_t *ent = NULL;
797 static struct option ping_opts[] =
799 {"session", no_argument, 0, 's' },
800 {"server", no_argument, 0, 'v' },
801 {"batch", required_argument, 0, 'b' },
802 {"group", required_argument, 0, 'g' },
803 {"nodes", required_argument, 0, 'n' },
804 {"timeout", required_argument, 0, 't' },
808 if (session_key == 0) {
810 "Can't find env LST_SESSION or value is not valid\n");
816 c = getopt_long(argc, argv, "g:b:n:t:sv",
824 type = LST_OPC_SESSION;
828 type = LST_OPC_GROUP;
833 type = LST_OPC_BATCHCLI;
838 type = LST_OPC_NODES;
843 timeout = atoi(optarg);
851 lst_print_usage(argv[0]);
856 if (type == 0 || timeout <= 0 || optind != argc) {
857 lst_print_usage(argv[0]);
861 if (type == LST_OPC_BATCHCLI && server)
862 type = LST_OPC_BATCHSRV;
864 rc = lst_get_node_count(type, str, &count, &ids);
866 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
867 (str == NULL) ? "session" : str, strerror(errno));
871 INIT_LIST_HEAD(&head);
873 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
875 fprintf(stderr, "Out of memory\n");
880 fprintf(stdout, "Target %s is empty\n",
881 (str == NULL) ? "session" : str);
885 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
886 if (rc == -1) { /* local failure */
887 lst_print_error("debug", "Failed to ping %s: %s\n",
888 (str == NULL) ? "session" : str,
894 /* ignore RPC errors and framwork errors */
895 list_for_each_entry(ent, &head, rpe_link) {
896 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
897 libcfs_id2str(ent->rpe_peer),
898 lst_node_state2str(ent->rpe_state),
899 (ent->rpe_state == LST_NODE_ACTIVE ||
900 ent->rpe_state == LST_NODE_BUSY) ?
901 (ent->rpe_rpc_errno == 0 ?
902 &ent->rpe_payload[0] : "Unknown") :
903 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
907 lst_free_rpcent(&head);
917 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
918 unsigned *featp, struct list_head *resultp)
920 lstio_group_nodes_args_t args = {0};
922 args.lstio_grp_key = session_key;
923 args.lstio_grp_nmlen = strlen(name);
924 args.lstio_grp_namep = name;
925 args.lstio_grp_count = count;
926 args.lstio_grp_featp = featp;
927 args.lstio_grp_idsp = ids;
928 args.lstio_grp_resultp = resultp;
930 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
934 lst_del_group_ioctl(char *name)
936 lstio_group_del_args_t args = {0};
938 args.lstio_grp_key = session_key;
939 args.lstio_grp_nmlen = strlen(name);
940 args.lstio_grp_namep = name;
942 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
946 lst_del_group(char *grp_name)
950 rc = lst_del_group_ioctl(grp_name);
952 fprintf(stdout, "Group is deleted\n");
957 lst_print_error("group", "Failed to delete group: %s\n",
962 fprintf(stderr, "Group is deleted with some errors\n");
964 if (trans_stat.trs_rpc_errno != 0) {
966 "[RPC] Failed to send %d end session RPCs: %s\n",
967 lstcon_rpc_stat_failure(&trans_stat, 0),
968 strerror(trans_stat.trs_rpc_errno));
971 if (trans_stat.trs_fwk_errno != 0) {
973 "[FWK] Failed to end session on %d nodes: %s\n",
974 lstcon_sesop_stat_failure(&trans_stat, 0),
975 strerror(trans_stat.trs_fwk_errno));
982 lst_add_group_ioctl (char *name)
984 lstio_group_add_args_t args = {0};
986 args.lstio_grp_key = session_key;
987 args.lstio_grp_nmlen = strlen(name);
988 args.lstio_grp_namep = name;
990 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
994 jt_lst_add_group(int argc, char **argv)
996 struct list_head head;
997 lnet_process_id_t *ids;
999 unsigned feats = session_features;
1003 bool nodes_added = false;
1005 if (session_key == 0) {
1007 "Can't find env LST_SESSION or value is not valid\n");
1012 lst_print_usage(argv[0]);
1017 if (strlen(name) >= LST_NAME_SIZE) {
1018 fprintf(stderr, "Name length is limited to %d\n",
1023 rc = lst_add_group_ioctl(name);
1025 lst_print_error("group", "Failed to add group %s: %s\n",
1026 name, strerror(errno));
1030 INIT_LIST_HEAD(&head);
1032 for (i = 2; i < argc; i++) {
1033 /* parse address list */
1034 rc = lst_parse_nids(argv[i], &count, &ids);
1036 fprintf(stderr, "Ignore invalid id list %s\n",
1044 rc = lst_alloc_rpcent(&head, count, 0);
1046 fprintf(stderr, "Out of memory\n");
1052 rc = lst_add_nodes_ioctl(name, count, ids, &feats, &head);
1059 fprintf(stdout, "%s are added to session\n", argv[i]);
1063 if ((feats & session_features) != session_features) {
1065 "Warning, this session will run with "
1066 "compatible mode because some test nodes "
1067 "might not understand these features: %x\n",
1068 (~feats & session_features));
1071 lst_free_rpcent(&head);
1076 * The selftest kernel module expects that a group should
1077 * have at least one node, since it doesn't make sense for
1078 * an empty group to be added to a test.
1081 "No nodes added successfully, deleting group %s\n",
1083 rc = lst_del_group(name);
1086 "Failed to delete group %s."
1087 " Group is empty.\n", name);
1095 lst_print_error("group", "Failed to add nodes %s: %s\n",
1096 argv[i], strerror(errno));
1099 if (trans_stat.trs_fwk_errno == EPROTO) {
1101 "test nodes might have different LST "
1102 "features, please disable some features by "
1103 "setting LST_FEATURES\n");
1106 lst_print_transerr(&head, "create session");
1109 lst_free_rpcent(&head);
1113 "No nodes added successfully, deleting group %s\n",
1115 if (lst_del_group(name) != 0) {
1117 "Failed to delete group %s."
1118 " Group is empty.\n", name);
1126 jt_lst_del_group(int argc, char **argv)
1130 if (session_key == 0) {
1132 "Can't find env LST_SESSION or value is not valid\n");
1137 lst_print_usage(argv[0]);
1141 rc = lst_del_group(argv[1]);
1147 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1148 lnet_process_id_t *ids, struct list_head *resultp)
1150 lstio_group_update_args_t args = {0};
1152 args.lstio_grp_key = session_key;
1153 args.lstio_grp_opc = opc;
1154 args.lstio_grp_args = clean;
1155 args.lstio_grp_nmlen = strlen(name);
1156 args.lstio_grp_namep = name;
1157 args.lstio_grp_count = count;
1158 args.lstio_grp_idsp = ids;
1159 args.lstio_grp_resultp = resultp;
1161 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1165 jt_lst_update_group(int argc, char **argv)
1167 struct list_head head;
1168 lnet_process_id_t *ids = NULL;
1178 static struct option update_group_opts[] =
1180 {"refresh", no_argument, 0, 'f' },
1181 {"clean", required_argument, 0, 'c' },
1182 {"remove", required_argument, 0, 'r' },
1186 if (session_key == 0) {
1188 "Can't find env LST_SESSION or value is not valid\n");
1193 c = getopt_long(argc, argv, "fc:r:",
1194 update_group_opts, &optidx);
1196 /* Detect the end of the options. */
1203 lst_print_usage(argv[0]);
1206 opc = LST_GROUP_REFRESH;
1211 lst_print_usage(argv[0]);
1214 opc = LST_GROUP_RMND;
1219 clean = lst_node_str2state(optarg);
1220 if (opc != 0 || clean <= 0) {
1221 lst_print_usage(argv[0]);
1224 opc = LST_GROUP_CLEAN;
1228 lst_print_usage(argv[0]);
1233 /* no OPC or group is specified */
1234 if (opc == 0 || optind != argc - 1) {
1235 lst_print_usage(argv[0]);
1241 INIT_LIST_HEAD(&head);
1243 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1244 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1246 opc == LST_GROUP_RMND ? str : grp,
1250 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1251 opc == LST_GROUP_RMND ? str : grp,
1256 rc = lst_alloc_rpcent(&head, count, 0);
1258 fprintf(stderr, "Out of memory\n");
1265 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1271 lst_free_rpcent(&head);
1276 lst_free_rpcent(&head);
1277 lst_print_error("group", "Failed to update group: %s\n",
1282 lst_print_transerr(&head, "Updating group");
1284 lst_free_rpcent(&head);
1290 lst_list_group_ioctl(int len, char *name, int idx)
1292 lstio_group_list_args_t args = {0};
1294 args.lstio_grp_key = session_key;
1295 args.lstio_grp_idx = idx;
1296 args.lstio_grp_nmlen = len;
1297 args.lstio_grp_namep = name;
1299 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1303 lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
1304 int *idx, int *count, lstcon_node_ent_t *dents)
1306 lstio_group_info_args_t args = {0};
1308 args.lstio_grp_key = session_key;
1309 args.lstio_grp_nmlen = strlen(name);
1310 args.lstio_grp_namep = name;
1311 args.lstio_grp_entp = gent;
1312 args.lstio_grp_idxp = idx;
1313 args.lstio_grp_ndentp = count;
1314 args.lstio_grp_dentsp = dents;
1316 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1320 lst_list_group_all(void)
1322 char name[LST_NAME_SIZE];
1326 /* no group is specified, list name of all groups */
1327 for (i = 0; ; i++) {
1328 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1330 fprintf(stdout, "%d) %s\n", i + 1, name);
1334 if (errno == ENOENT)
1337 lst_print_error("group", "Failed to list group: %s\n",
1342 fprintf(stdout, "Total %d groups\n", i);
1347 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1350 jt_lst_list_group(int argc, char **argv)
1352 lstcon_ndlist_ent_t gent;
1353 lstcon_node_ent_t *dents;
1368 static struct option list_group_opts[] =
1370 {"active", no_argument, 0, 'a' },
1371 {"busy", no_argument, 0, 'b' },
1372 {"down", no_argument, 0, 'd' },
1373 {"unknown", no_argument, 0, 'u' },
1374 {"all", no_argument, 0, 'l' },
1378 if (session_key == 0) {
1380 "Can't find env LST_SESSION or value is not valid\n");
1385 c = getopt_long(argc, argv, "abdul",
1386 list_group_opts, &optidx);
1393 verbose = active = 1;
1405 verbose = unknown = 1;
1412 lst_print_usage(argv[0]);
1417 if (optind == argc) {
1418 /* no group is specified, list name of all groups */
1419 rc = lst_list_group_all();
1425 fprintf(stdout, LST_NODES_TITLE);
1427 /* list nodes in specified groups */
1428 for (i = optind; i < argc; i++) {
1429 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1431 if (errno == ENOENT) {
1436 lst_print_error("group", "Failed to list group\n",
1442 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1443 gent.nle_nactive, gent.nle_nbusy,
1444 gent.nle_ndown, gent.nle_nunknown,
1445 gent.nle_nnode, argv[i]);
1449 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1451 if (gent.nle_nnode == 0) {
1452 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1456 count = gent.nle_nnode;
1458 dents = malloc(count * sizeof(lstcon_node_ent_t));
1459 if (dents == NULL) {
1460 fprintf(stderr, "Failed to malloc: %s\n",
1466 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1468 lst_print_error("group", "Failed to list group: %s\n",
1474 for (j = 0, c = 0; j < count; j++) {
1476 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1477 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1478 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1479 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1481 fprintf(stdout, "\t%s: %s\n",
1482 libcfs_id2str(dents[j].nde_id),
1483 lst_node_state2str(dents[j].nde_state));
1488 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1497 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
1498 int timeout, struct list_head *resultp)
1500 lstio_stat_args_t args = {0};
1502 args.lstio_sta_key = session_key;
1503 args.lstio_sta_timeout = timeout;
1504 args.lstio_sta_nmlen = strlen(name);
1505 args.lstio_sta_namep = name;
1506 args.lstio_sta_count = count;
1507 args.lstio_sta_idsp = idsp;
1508 args.lstio_sta_resultp = resultp;
1510 return lst_ioctl (LSTIO_STAT_QUERY, &args, sizeof(args));
1514 struct list_head srp_link;
1517 lnet_process_id_t *srp_ids;
1518 struct list_head srp_result[2];
1519 } lst_stat_req_param_t;
1522 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1526 for (i = 0; i < 2; i++)
1527 lst_free_rpcent(&srp->srp_result[i]);
1529 if (srp->srp_ids != NULL)
1536 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
1538 lst_stat_req_param_t *srp = NULL;
1539 int count = save_old ? 2 : 1;
1543 srp = malloc(sizeof(*srp));
1547 memset(srp, 0, sizeof(*srp));
1548 INIT_LIST_HEAD(&srp->srp_result[0]);
1549 INIT_LIST_HEAD(&srp->srp_result[1]);
1551 rc = lst_get_node_count(LST_OPC_GROUP, name,
1552 &srp->srp_count, NULL);
1553 if (rc != 0 && errno == ENOENT) {
1554 rc = lst_get_node_count(LST_OPC_NODES, name,
1555 &srp->srp_count, &srp->srp_ids);
1560 "Failed to get count of nodes from %s: %s\n",
1561 name, strerror(errno));
1562 lst_stat_req_param_free(srp);
1567 srp->srp_name = name;
1569 for (i = 0; i < count; i++) {
1570 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1571 sizeof(sfw_counters_t) +
1572 sizeof(srpc_counters_t) +
1573 sizeof(lnet_counters_t));
1575 fprintf(stderr, "Out of memory\n");
1585 lst_stat_req_param_free(srp);
1593 } lst_srpc_stat_result;
1595 #define LST_LNET_AVG 0
1596 #define LST_LNET_MIN 1
1597 #define LST_LNET_MAX 2
1600 float lnet_avg_sndrate;
1601 float lnet_min_sndrate;
1602 float lnet_max_sndrate;
1603 float lnet_total_sndrate;
1605 float lnet_avg_rcvrate;
1606 float lnet_min_rcvrate;
1607 float lnet_max_rcvrate;
1608 float lnet_total_rcvrate;
1610 float lnet_avg_sndperf;
1611 float lnet_min_sndperf;
1612 float lnet_max_sndperf;
1613 float lnet_total_sndperf;
1615 float lnet_avg_rcvperf;
1616 float lnet_min_rcvperf;
1617 float lnet_max_rcvperf;
1618 float lnet_total_rcvperf;
1620 int lnet_stat_count;
1621 } lst_lnet_stat_result_t;
1623 lst_lnet_stat_result_t lnet_stat_result;
1626 lst_lnet_stat_value(int bw, int send, int off)
1630 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1631 &lnet_stat_result.lnet_avg_sndrate;
1642 lst_timeval_diff(struct timeval *tv1,
1643 struct timeval *tv2, struct timeval *df)
1645 if (tv1->tv_usec >= tv2->tv_usec) {
1646 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1647 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1651 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1652 df->tv_usec = tv1->tv_usec + 1000000 - tv2->tv_usec;
1658 lst_cal_lnet_stat(float delta, lnet_counters_t *lnet_new,
1659 lnet_counters_t *lnet_old)
1664 perf = (float)(lnet_new->send_length -
1665 lnet_old->send_length) / (1024 * 1024) / delta;
1666 lnet_stat_result.lnet_total_sndperf += perf;
1668 if (lnet_stat_result.lnet_min_sndperf > perf ||
1669 lnet_stat_result.lnet_min_sndperf == 0)
1670 lnet_stat_result.lnet_min_sndperf = perf;
1672 if (lnet_stat_result.lnet_max_sndperf < perf)
1673 lnet_stat_result.lnet_max_sndperf = perf;
1675 perf = (float)(lnet_new->recv_length -
1676 lnet_old->recv_length) / (1024 * 1024) / delta;
1677 lnet_stat_result.lnet_total_rcvperf += perf;
1679 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1680 lnet_stat_result.lnet_min_rcvperf == 0)
1681 lnet_stat_result.lnet_min_rcvperf = perf;
1683 if (lnet_stat_result.lnet_max_rcvperf < perf)
1684 lnet_stat_result.lnet_max_rcvperf = perf;
1686 rate = (lnet_new->send_count - lnet_old->send_count) / delta;
1687 lnet_stat_result.lnet_total_sndrate += rate;
1689 if (lnet_stat_result.lnet_min_sndrate > rate ||
1690 lnet_stat_result.lnet_min_sndrate == 0)
1691 lnet_stat_result.lnet_min_sndrate = rate;
1693 if (lnet_stat_result.lnet_max_sndrate < rate)
1694 lnet_stat_result.lnet_max_sndrate = rate;
1696 rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
1697 lnet_stat_result.lnet_total_rcvrate += rate;
1699 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1700 lnet_stat_result.lnet_min_rcvrate == 0)
1701 lnet_stat_result.lnet_min_rcvrate = rate;
1703 if (lnet_stat_result.lnet_max_rcvrate < rate)
1704 lnet_stat_result.lnet_max_rcvrate = rate;
1706 lnet_stat_result.lnet_stat_count ++;
1708 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1709 lnet_stat_result.lnet_stat_count;
1710 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1711 lnet_stat_result.lnet_stat_count;
1713 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1714 lnet_stat_result.lnet_stat_count;
1715 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1716 lnet_stat_result.lnet_stat_count;
1721 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
1730 if (lnet_stat_result.lnet_stat_count == 0)
1733 if (bwrt == 1) /* bw only */
1736 if (bwrt == 2) /* rates only */
1739 if (rdwr == 1) /* recv only */
1742 if (rdwr == 2) /* send only */
1745 for (i = start1; i <= end1; i++) {
1746 fprintf(stdout, "[LNet %s of %s]\n",
1747 i == 0 ? "Rates" : "Bandwidth", name);
1749 for (j = start2; j <= end2; j++) {
1750 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
1752 if ((type & 1) != 0) {
1753 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1754 "Avg: %-8.2f MB/s ",
1755 lst_lnet_stat_value(i, j, 0));
1758 if ((type & 2) != 0) {
1759 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1760 "Min: %-8.2f MB/s ",
1761 lst_lnet_stat_value(i, j, 1));
1764 if ((type & 4) != 0) {
1765 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1767 lst_lnet_stat_value(i, j, 2));
1770 fprintf(stdout, "\n");
1776 lst_print_stat(char *name, struct list_head *resultp,
1777 int idx, int lnet, int bwrt, int rdwr, int type)
1779 struct list_head tmp[2];
1780 lstcon_rpc_ent_t *new;
1781 lstcon_rpc_ent_t *old;
1782 sfw_counters_t *sfwk_new;
1783 sfw_counters_t *sfwk_old;
1784 srpc_counters_t *srpc_new;
1785 srpc_counters_t *srpc_old;
1786 lnet_counters_t *lnet_new;
1787 lnet_counters_t *lnet_old;
1791 INIT_LIST_HEAD(&tmp[0]);
1792 INIT_LIST_HEAD(&tmp[1]);
1794 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1796 while (!list_empty(&resultp[idx])) {
1797 if (list_empty(&resultp[1 - idx])) {
1798 fprintf(stderr, "Group is changed, re-run stat\n");
1802 new = list_entry(resultp[idx].next, lstcon_rpc_ent_t,
1804 old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t,
1807 /* first time get stats result, can't calculate diff */
1808 if (new->rpe_peer.nid == LNET_NID_ANY)
1811 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1812 new->rpe_peer.pid != old->rpe_peer.pid) {
1813 /* Something wrong. i.e, somebody change the group */
1817 list_del(&new->rpe_link);
1818 list_add_tail(&new->rpe_link, &tmp[idx]);
1820 list_del(&old->rpe_link);
1821 list_add_tail(&old->rpe_link, &tmp[1 - idx]);
1823 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1824 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1829 sfwk_new = (sfw_counters_t *)&new->rpe_payload[0];
1830 sfwk_old = (sfw_counters_t *)&old->rpe_payload[0];
1832 srpc_new = (srpc_counters_t *)((char *)sfwk_new + sizeof(*sfwk_new));
1833 srpc_old = (srpc_counters_t *)((char *)sfwk_old + sizeof(*sfwk_old));
1835 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
1836 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
1838 /* Prior to version 2.3, the running_ms field was a counter for
1839 * the number of running tests. We are looking at this value
1840 * to determine if it is a millisecond timestamep (>= 2.3) or a
1841 * test counter (< 2.3). The number 500 is being used for this
1842 * barrier as the test counter should never get this high, and
1843 * the timestamp should never get this low. */
1845 if (sfwk_new->running_ms > 500) {
1846 /* use the timestamp from the remote node, not our
1847 * rpe_stamp from when we copied up the data out of
1850 delta = (float) (sfwk_new->running_ms -
1851 sfwk_old->running_ms) / 1000;
1855 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1856 delta = tv.tv_sec + (float)tv.tv_usec / 1000000;
1859 if (!lnet) /* TODO */
1862 lst_cal_lnet_stat(delta, lnet_new, lnet_old);
1865 list_splice(&tmp[idx], &resultp[idx]);
1866 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1869 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1871 if (!lnet) /* TODO */
1874 lst_print_lnet_stat(name, bwrt, rdwr, type);
1878 jt_lst_stat(int argc, char **argv)
1880 struct list_head head;
1881 lst_stat_req_param_t *srp;
1884 int timeout = 5; /* default timeout, 5 sec */
1885 int delay = 5; /* default delay, 5 sec */
1886 int count = -1; /* run forever */
1887 int lnet = 1; /* lnet stat by default */
1895 static struct option stat_opts[] =
1897 {"timeout" , required_argument, 0, 't' },
1898 {"delay" , required_argument, 0, 'd' },
1899 {"count" , required_argument, 0, 'o' },
1900 {"lnet" , no_argument, 0, 'l' },
1901 {"rpc" , no_argument, 0, 'c' },
1902 {"bw" , no_argument, 0, 'b' },
1903 {"rate" , no_argument, 0, 'a' },
1904 {"read" , no_argument, 0, 'r' },
1905 {"write" , no_argument, 0, 'w' },
1906 {"avg" , no_argument, 0, 'g' },
1907 {"min" , no_argument, 0, 'n' },
1908 {"max" , no_argument, 0, 'x' },
1912 if (session_key == 0) {
1914 "Can't find env LST_SESSION or value is not valid\n");
1919 c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
1926 timeout = atoi(optarg);
1929 delay = atoi(optarg);
1932 count = atoi(optarg);
1975 lst_print_usage(argv[0]);
1980 if (optind == argc) {
1981 lst_print_usage(argv[0]);
1985 if (timeout <= 0 || delay <= 0) {
1986 fprintf(stderr, "Invalid timeout or delay value\n");
1991 fprintf(stderr, "Invalid count value\n");
1995 /* extra count to get first data point */
1999 INIT_LIST_HEAD(&head);
2001 while (optind < argc) {
2002 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
2006 list_add_tail(&srp->srp_link, &head);
2010 time_t now = time(NULL);
2012 if (now - last < delay) {
2013 sleep(delay - now + last);
2018 list_for_each_entry(srp, &head, srp_link) {
2019 rc = lst_stat_ioctl(srp->srp_name,
2020 srp->srp_count, srp->srp_ids,
2021 timeout, &srp->srp_result[idx]);
2023 lst_print_error("stat", "Failed to stat %s: %s\n",
2024 srp->srp_name, strerror(errno));
2028 lst_print_stat(srp->srp_name, srp->srp_result,
2029 idx, lnet, bwrt, rdwr, type);
2031 lst_reset_rpcent(&srp->srp_result[1 - idx]);
2038 } while (count == -1 || count > 0);
2041 while (!list_empty(&head)) {
2042 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2044 list_del(&srp->srp_link);
2045 lst_stat_req_param_free(srp);
2052 jt_lst_show_error(int argc, char **argv)
2054 struct list_head head;
2055 lst_stat_req_param_t *srp;
2056 lstcon_rpc_ent_t *ent;
2057 sfw_counters_t *sfwk;
2058 srpc_counters_t *srpc;
2065 static struct option show_error_opts[] =
2067 {"session", no_argument, 0, 's' },
2071 if (session_key == 0) {
2073 "Can't find env LST_SESSION or value is not valid\n");
2078 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
2089 lst_print_usage(argv[0]);
2094 if (optind == argc) {
2095 lst_print_usage(argv[0]);
2099 INIT_LIST_HEAD(&head);
2101 while (optind < argc) {
2102 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
2106 list_add_tail(&srp->srp_link, &head);
2109 list_for_each_entry(srp, &head, srp_link) {
2110 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
2111 srp->srp_ids, 10, &srp->srp_result[0]);
2114 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2115 srp->srp_name, strerror(errno));
2119 fprintf(stdout, "%s:\n", srp->srp_name);
2123 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2124 if (ent->rpe_rpc_errno != 0) {
2126 fprintf(stderr, "RPC failure, can't show error on %s\n",
2127 libcfs_id2str(ent->rpe_peer));
2131 if (ent->rpe_fwk_errno != 0) {
2133 fprintf(stderr, "Framework failure, can't show error on %s\n",
2134 libcfs_id2str(ent->rpe_peer));
2138 sfwk = (sfw_counters_t *)&ent->rpe_payload[0];
2139 srpc = (srpc_counters_t *)((char *)sfwk + sizeof(*sfwk));
2141 if (srpc->errors == 0 &&
2142 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2146 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2151 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2152 libcfs_id2str(ent->rpe_peer),
2153 sfwk->brw_errors, sfwk->ping_errors,
2154 show_rpc ? ' ' : '\n');
2159 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2160 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2163 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2166 while (!list_empty(&head)) {
2167 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2169 list_del(&srp->srp_link);
2170 lst_stat_req_param_free(srp);
2177 lst_add_batch_ioctl (char *name)
2179 lstio_batch_add_args_t args = {0};
2181 args.lstio_bat_key = session_key;
2182 args.lstio_bat_nmlen = strlen(name);
2183 args.lstio_bat_namep = name;
2185 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2189 jt_lst_add_batch(int argc, char **argv)
2194 if (session_key == 0) {
2196 "Can't find env LST_SESSION or value is not valid\n");
2201 lst_print_usage(argv[0]);
2206 if (strlen(name) >= LST_NAME_SIZE) {
2207 fprintf(stderr, "Name length is limited to %d\n",
2212 rc = lst_add_batch_ioctl(name);
2216 lst_print_error("batch", "Failed to create batch: %s\n",
2223 lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp)
2225 lstio_batch_run_args_t args = {0};
2227 args.lstio_bat_key = session_key;
2228 args.lstio_bat_timeout = timeout;
2229 args.lstio_bat_nmlen = strlen(name);
2230 args.lstio_bat_namep = name;
2231 args.lstio_bat_resultp = resultp;
2233 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2237 jt_lst_start_batch(int argc, char **argv)
2239 struct list_head head;
2247 static struct option start_batch_opts[] =
2249 {"timeout", required_argument, 0, 't' },
2253 if (session_key == 0) {
2255 "Can't find env LST_SESSION or value is not valid\n");
2260 c = getopt_long(argc, argv, "t:",
2261 start_batch_opts, &optidx);
2263 /* Detect the end of the options. */
2269 timeout = atoi(optarg);
2272 lst_print_usage(argv[0]);
2277 if (optind == argc) {
2278 batch = LST_DEFAULT_BATCH;
2280 } else if (optind == argc - 1) {
2281 batch = argv[optind];
2284 lst_print_usage(argv[0]);
2288 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2290 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2291 batch, strerror(errno));
2295 INIT_LIST_HEAD(&head);
2297 rc = lst_alloc_rpcent(&head, count, 0);
2299 fprintf(stderr, "Out of memory\n");
2303 rc = lst_start_batch_ioctl(batch, timeout, &head);
2306 fprintf(stdout, "%s is running now\n", batch);
2307 lst_free_rpcent(&head);
2312 lst_print_error("batch", "Failed to start batch: %s\n",
2314 lst_free_rpcent(&head);
2318 lst_print_transerr(&head, "Run batch");
2320 lst_free_rpcent(&head);
2326 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2328 lstio_batch_stop_args_t args = {0};
2330 args.lstio_bat_key = session_key;
2331 args.lstio_bat_force = force;
2332 args.lstio_bat_nmlen = strlen(name);
2333 args.lstio_bat_namep = name;
2334 args.lstio_bat_resultp = resultp;
2336 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2340 jt_lst_stop_batch(int argc, char **argv)
2342 struct list_head head;
2350 static struct option stop_batch_opts[] =
2352 {"force", no_argument, 0, 'f' },
2356 if (session_key == 0) {
2358 "Can't find env LST_SESSION or value is not valid\n");
2363 c = getopt_long(argc, argv, "f",
2364 stop_batch_opts, &optidx);
2366 /* Detect the end of the options. */
2375 lst_print_usage(argv[0]);
2380 if (optind == argc) {
2381 batch = LST_DEFAULT_BATCH;
2383 } else if (optind == argc - 1) {
2384 batch = argv[optind];
2387 lst_print_usage(argv[0]);
2391 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2393 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2394 batch, strerror(errno));
2398 INIT_LIST_HEAD(&head);
2400 rc = lst_alloc_rpcent(&head, count, 0);
2402 fprintf(stderr, "Out of memory\n");
2406 rc = lst_stop_batch_ioctl(batch, force, &head);
2411 lst_reset_rpcent(&head);
2413 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2417 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2418 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2421 fprintf(stdout, "%d batch in stopping\n",
2422 lstcon_tsbqry_stat_run(&trans_stat, 0));
2426 fprintf(stdout, "Batch is stopped\n");
2427 lst_free_rpcent(&head);
2432 lst_print_error("batch", "Failed to stop batch: %s\n",
2434 lst_free_rpcent(&head);
2438 lst_print_transerr(&head, "stop batch");
2440 lst_free_rpcent(&head);
2446 lst_list_batch_ioctl(int len, char *name, int index)
2448 lstio_batch_list_args_t args = {0};
2450 args.lstio_bat_key = session_key;
2451 args.lstio_bat_idx = index;
2452 args.lstio_bat_nmlen = len;
2453 args.lstio_bat_namep = name;
2455 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2459 lst_info_batch_ioctl(char *batch, int test, int server,
2460 lstcon_test_batch_ent_t *entp, int *idxp,
2461 int *ndentp, lstcon_node_ent_t *dentsp)
2463 lstio_batch_info_args_t args = {0};
2465 args.lstio_bat_key = session_key;
2466 args.lstio_bat_nmlen = strlen(batch);
2467 args.lstio_bat_namep = batch;
2468 args.lstio_bat_server = server;
2469 args.lstio_bat_testidx = test;
2470 args.lstio_bat_entp = entp;
2471 args.lstio_bat_idxp = idxp;
2472 args.lstio_bat_ndentp = ndentp;
2473 args.lstio_bat_dentsp = dentsp;
2475 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2479 lst_list_batch_all(void)
2481 char name[LST_NAME_SIZE];
2485 for (i = 0; ; i++) {
2486 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2488 fprintf(stdout, "%d) %s\n", i + 1, name);
2492 if (errno == ENOENT)
2495 lst_print_error("batch", "Failed to list batch: %s\n",
2500 fprintf(stdout, "Total %d batches\n", i);
2506 lst_list_tsb_nodes(char *batch, int test, int server,
2507 int count, int active, int invalid)
2509 lstcon_node_ent_t *dents;
2518 /* verbose list, show nodes in batch or test */
2519 dents = malloc(count * sizeof(lstcon_node_ent_t));
2520 if (dents == NULL) {
2521 fprintf(stdout, "Can't allocate memory\n");
2525 rc = lst_info_batch_ioctl(batch, test, server,
2526 NULL, &index, &count, dents);
2529 lst_print_error((test > 0) ? "test" : "batch",
2530 (test > 0) ? "Failed to query test: %s\n" :
2531 "Failed to query batch: %s\n",
2536 for (i = 0, c = 0; i < count; i++) {
2537 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2538 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2539 dents[i].nde_state == LST_NODE_DOWN ||
2540 dents[i].nde_state == LST_NODE_UNKNOWN)))
2543 fprintf(stdout, "\t%s: %s\n",
2544 libcfs_id2str(dents[i].nde_id),
2545 lst_node_state2str(dents[i].nde_state));
2549 fprintf(stdout, "Total %d nodes\n", c);
2556 jt_lst_list_batch(int argc, char **argv)
2558 lstcon_test_batch_ent_t ent;
2561 int verbose = 0; /* list nodes in batch or test */
2570 static struct option list_batch_opts[] =
2572 {"test", required_argument, 0, 't' },
2573 {"invalid", no_argument, 0, 'i' },
2574 {"active", no_argument, 0, 'a' },
2575 {"all", no_argument, 0, 'l' },
2576 {"server", no_argument, 0, 's' },
2580 if (session_key == 0) {
2582 "Can't find env LST_SESSION or value is not valid\n");
2587 c = getopt_long(argc, argv, "ailst:",
2588 list_batch_opts, &optidx);
2595 verbose = active = 1;
2598 verbose = invalid = 1;
2601 verbose = active = invalid = 1;
2607 test = atoi(optarg);
2611 lst_print_usage(argv[0]);
2616 if (optind == argc) {
2617 /* list all batches */
2618 rc = lst_list_batch_all();
2622 if (ntest == 1 && test <= 0) {
2623 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2627 if (optind != argc - 1) {
2628 lst_print_usage(argv[0]);
2632 batch = argv[optind];
2635 /* show detail of specified batch or test */
2636 rc = lst_info_batch_ioctl(batch, test, server,
2637 &ent, NULL, NULL, NULL);
2639 lst_print_error((test > 0) ? "test" : "batch",
2640 (test > 0) ? "Failed to query test: %s\n" :
2641 "Failed to query batch: %s\n",
2647 /* list nodes in test or batch */
2648 rc = lst_list_tsb_nodes(batch, test, server,
2649 server ? ent.tbe_srv_nle.nle_nnode :
2650 ent.tbe_cli_nle.nle_nnode,
2655 /* only show number of hosts in batch or test */
2657 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2658 batch, ent.u.tbe_batch.bae_ntest,
2659 ent.u.tbe_batch.bae_state);
2660 ntest = ent.u.tbe_batch.bae_ntest;
2661 test = 1; /* starting from test 1 */
2665 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2666 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2667 ent.u.tbe_test.tse_loop,
2668 ent.u.tbe_test.tse_concur);
2673 fprintf(stdout, LST_NODES_TITLE);
2674 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2675 "server\t%d\t%d\t%d\t%d\t%d\n",
2676 ent.tbe_cli_nle.nle_nactive,
2677 ent.tbe_cli_nle.nle_nbusy,
2678 ent.tbe_cli_nle.nle_ndown,
2679 ent.tbe_cli_nle.nle_nunknown,
2680 ent.tbe_cli_nle.nle_nnode,
2681 ent.tbe_srv_nle.nle_nactive,
2682 ent.tbe_srv_nle.nle_nbusy,
2683 ent.tbe_srv_nle.nle_ndown,
2684 ent.tbe_srv_nle.nle_nunknown,
2685 ent.tbe_srv_nle.nle_nnode);
2694 lst_query_batch_ioctl(char *batch, int test, int server,
2695 int timeout, struct list_head *head)
2697 lstio_batch_query_args_t args = {0};
2699 args.lstio_bat_key = session_key;
2700 args.lstio_bat_testidx = test;
2701 args.lstio_bat_client = !(server);
2702 args.lstio_bat_timeout = timeout;
2703 args.lstio_bat_nmlen = strlen(batch);
2704 args.lstio_bat_namep = batch;
2705 args.lstio_bat_resultp = head;
2707 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2711 lst_print_tsb_verbose(struct list_head *head,
2712 int active, int idle, int error)
2714 lstcon_rpc_ent_t *ent;
2716 list_for_each_entry(ent, head, rpe_link) {
2717 if (ent->rpe_priv[0] == 0 && active)
2720 if (ent->rpe_priv[0] != 0 && idle)
2723 if (ent->rpe_fwk_errno == 0 && error)
2726 fprintf(stdout, "%s [%s]: %s\n",
2727 libcfs_id2str(ent->rpe_peer),
2728 lst_node_state2str(ent->rpe_state),
2729 ent->rpe_rpc_errno != 0 ?
2730 strerror(ent->rpe_rpc_errno) :
2731 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2736 jt_lst_query_batch(int argc, char **argv)
2738 lstcon_test_batch_ent_t ent;
2739 struct list_head head;
2745 int timeout = 5; /* default 5 seconds */
2746 int delay = 5; /* default 5 seconds */
2747 int loop = 1; /* default 1 loop */
2757 static struct option query_batch_opts[] =
2759 {"timeout", required_argument, 0, 'o' },
2760 {"delay", required_argument, 0, 'd' },
2761 {"loop", required_argument, 0, 'c' },
2762 {"test", required_argument, 0, 't' },
2763 {"server", no_argument, 0, 's' },
2764 {"active", no_argument, 0, 'a' },
2765 {"idle", no_argument, 0, 'i' },
2766 {"error", no_argument, 0, 'e' },
2767 {"all", no_argument, 0, 'l' },
2771 if (session_key == 0) {
2773 "Can't find env LST_SESSION or value is not valid\n");
2778 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2779 query_batch_opts, &optidx);
2781 /* Detect the end of the options. */
2787 timeout = atoi(optarg);
2790 delay = atoi(optarg);
2793 loop = atoi(optarg);
2796 test = atoi(optarg);
2802 active = verbose = 1;
2808 error = verbose = 1;
2814 lst_print_usage(argv[0]);
2819 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2820 lst_print_usage(argv[0]);
2824 if (optind == argc) {
2825 batch = LST_DEFAULT_BATCH;
2827 } else if (optind == argc - 1) {
2828 batch = argv[optind];
2831 lst_print_usage(argv[0]);
2836 INIT_LIST_HEAD(&head);
2839 rc = lst_info_batch_ioctl(batch, test, server,
2840 &ent, NULL, NULL, NULL);
2842 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2843 batch, test, strerror(errno));
2847 count = server ? ent.tbe_srv_nle.nle_nnode :
2848 ent.tbe_cli_nle.nle_nnode;
2850 fprintf(stdout, "Batch or test is empty\n");
2855 rc = lst_alloc_rpcent(&head, count, 0);
2857 fprintf(stderr, "Out of memory\n");
2861 for (i = 0; i < loop; i++) {
2862 time_t now = time(NULL);
2864 if (now - last < delay) {
2865 sleep(delay - now + last);
2871 rc = lst_query_batch_ioctl(batch, test,
2872 server, timeout, &head);
2874 fprintf(stderr, "Failed to query batch: %s\n",
2881 lst_print_tsb_verbose(&head, active, idle, error);
2885 fprintf(stdout, "%s [%d] ", batch, test);
2887 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2888 fprintf(stdout, "%d of %d nodes are unknown, ",
2889 lstcon_rpc_stat_failure(&trans_stat, 0),
2890 lstcon_rpc_stat_total(&trans_stat, 0));
2893 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2894 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2895 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2896 fprintf(stdout, "is stopped\n");
2900 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2901 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2902 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2903 fprintf(stdout, "is running\n");
2907 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2908 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2909 lstcon_tsbqry_stat_run(&trans_stat, 0),
2910 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2913 lst_free_rpcent(&head);
2919 lst_parse_distribute(char *dstr, int *dist, int *span)
2925 dstr = strchr(dstr, ':');
2929 *span = atoi(dstr + 1);
2937 lst_get_bulk_param(int argc, char **argv, lst_test_bulk_param_t *bulk)
2944 bulk->blk_size = 4096;
2945 bulk->blk_opc = LST_BRW_READ;
2946 bulk->blk_flags = LST_BRW_CHECK_NONE;
2949 if (strcasestr(argv[i], "check=") == argv[i] ||
2950 strcasestr(argv[i], "c=") == argv[i]) {
2951 tok = strchr(argv[i], '=') + 1;
2953 if (strcasecmp(tok, "full") == 0) {
2954 bulk->blk_flags = LST_BRW_CHECK_FULL;
2955 } else if (strcasecmp(tok, "simple") == 0) {
2956 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2958 fprintf(stderr, "Unknow flag %s\n", tok);
2962 } else if (strcasestr(argv[i], "size=") == argv[i] ||
2963 strcasestr(argv[i], "s=") == argv[i]) {
2964 int max_size = sysconf(_SC_PAGESIZE) * LNET_MAX_IOV;
2966 tok = strchr(argv[i], '=') + 1;
2968 bulk->blk_size = strtol(tok, &end, 0);
2969 if (bulk->blk_size <= 0) {
2970 fprintf(stderr, "Invalid size %s\n", tok);
2977 if (*end == 'k' || *end == 'K')
2978 bulk->blk_size *= 1024;
2979 else if (*end == 'm' || *end == 'M')
2980 bulk->blk_size *= 1024 * 1024;
2982 if (bulk->blk_size > max_size) {
2983 fprintf(stderr, "Size exceed limitation: %d bytes\n",
2988 } else if (strcasecmp(argv[i], "read") == 0 ||
2989 strcasecmp(argv[i], "r") == 0) {
2990 bulk->blk_opc = LST_BRW_READ;
2992 } else if (strcasecmp(argv[i], "write") == 0 ||
2993 strcasecmp(argv[i], "w") == 0) {
2994 bulk->blk_opc = LST_BRW_WRITE;
2997 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
3008 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
3010 lst_test_bulk_param_t *bulk = NULL;
3013 type = lst_test_name2type(test);
3015 fprintf(stderr, "Unknow test name %s\n", test);
3024 bulk = malloc(sizeof(*bulk));
3026 fprintf(stderr, "Out of memory\n");
3030 memset(bulk, 0, sizeof(*bulk));
3032 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
3038 *plen = sizeof(*bulk);
3046 /* TODO: parse more parameter */
3051 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
3052 int dist, int span, char *sgrp, char *dgrp,
3053 void *param, int plen, int *retp, struct list_head *resultp)
3055 lstio_test_args_t args = {0};
3057 args.lstio_tes_key = session_key;
3058 args.lstio_tes_bat_nmlen = strlen(batch);
3059 args.lstio_tes_bat_name = batch;
3060 args.lstio_tes_type = type;
3061 args.lstio_tes_oneside = 0;
3062 args.lstio_tes_loop = loop;
3063 args.lstio_tes_concur = concur;
3064 args.lstio_tes_dist = dist;
3065 args.lstio_tes_span = span;
3066 args.lstio_tes_sgrp_nmlen = strlen(sgrp);
3067 args.lstio_tes_sgrp_name = sgrp;
3068 args.lstio_tes_dgrp_nmlen = strlen(dgrp);
3069 args.lstio_tes_dgrp_name = dgrp;
3070 args.lstio_tes_param_len = plen;
3071 args.lstio_tes_param = param;
3072 args.lstio_tes_retp = retp;
3073 args.lstio_tes_resultp = resultp;
3075 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
3079 jt_lst_add_test(int argc, char **argv)
3081 struct list_head head;
3101 static struct option add_test_opts[] =
3103 {"batch", required_argument, 0, 'b' },
3104 {"concurrency", required_argument, 0, 'c' },
3105 {"distribute", required_argument, 0, 'd' },
3106 {"from", required_argument, 0, 'f' },
3107 {"to", required_argument, 0, 't' },
3108 {"loop", required_argument, 0, 'l' },
3112 if (session_key == 0) {
3114 "Can't find env LST_SESSION or value is not valid\n");
3119 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3120 add_test_opts, &optidx);
3122 /* Detect the end of the options. */
3131 concur = atoi(optarg);
3140 loop = atoi(optarg);
3146 lst_print_usage(argv[0]);
3151 if (optind == argc || from == NULL || to == NULL) {
3152 lst_print_usage(argv[0]);
3156 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3157 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3162 batch = LST_DEFAULT_BATCH;
3165 rc = lst_parse_distribute(dstr, &dist, &span);
3167 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3172 test = argv[optind++];
3177 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3179 fprintf(stderr, "Failed to add test (%s)\n", test);
3183 INIT_LIST_HEAD(&head);
3185 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3187 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3188 from, strerror(errno));
3192 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3194 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3195 to, strerror(errno));
3199 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3201 fprintf(stderr, "Out of memory\n");
3205 rc = lst_add_test_ioctl(batch, type, loop, concur,
3206 dist, span, from, to, param, plen, &ret, &head);
3209 fprintf(stdout, "Test was added successfully\n");
3211 fprintf(stdout, "Server group contains userland test "
3212 "nodes, old version of tcplnd can't accept "
3213 "connection request\n");
3220 lst_print_error("test", "Failed to add test: %s\n",
3225 lst_print_transerr(&head, "add test");
3227 lst_free_rpcent(&head);
3235 static command_t lst_cmdlist[] = {
3236 {"new_session", jt_lst_new_session, NULL,
3237 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3238 {"end_session", jt_lst_end_session, NULL,
3239 "Usage: lst end_session" },
3240 {"show_session", jt_lst_show_session, NULL,
3241 "Usage: lst show_session" },
3242 {"ping", jt_lst_ping , NULL,
3243 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3244 {"add_group", jt_lst_add_group, NULL,
3245 "Usage: lst group NAME IDs [IDs]..." },
3246 {"del_group", jt_lst_del_group, NULL,
3247 "Usage: lst del_group NAME" },
3248 {"update_group", jt_lst_update_group, NULL,
3249 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3250 {"list_group", jt_lst_list_group, NULL,
3251 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3252 {"stat", jt_lst_stat, NULL,
3253 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3254 " [--timeout #] [--delay #] [--count #] GROUP [GROUP]" },
3255 {"show_error", jt_lst_show_error, NULL,
3256 "Usage: lst show_error NAME | IDS ..." },
3257 {"add_batch", jt_lst_add_batch, NULL,
3258 "Usage: lst add_batch NAME" },
3259 {"run", jt_lst_start_batch, NULL,
3260 "Usage: lst run [--timeout TIME] [NAME]" },
3261 {"stop", jt_lst_stop_batch, NULL,
3262 "Usage: lst stop [--force] BATCH_NAME" },
3263 {"list_batch", jt_lst_list_batch, NULL,
3264 "Usage: lst list_batch NAME [--test ID] [--server]" },
3265 {"query", jt_lst_query_batch, NULL,
3266 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3267 {"add_test", jt_lst_add_test, NULL,
3268 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3269 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3270 {"help", Parser_help, 0, "help" },
3275 lst_initialize(void)
3280 feats = getenv("LST_FEATURES");
3282 session_features = strtol(feats, NULL, 16);
3284 if ((session_features & ~LST_FEATS_MASK) != 0) {
3286 "Unsupported session features %x, "
3287 "only support these features so far: %x\n",
3288 (session_features & ~LST_FEATS_MASK), LST_FEATS_MASK);
3292 key = getenv("LST_SESSION");
3299 session_key = atoi(key);
3305 main(int argc, char **argv)
3311 rc = lst_initialize();
3315 rc = ptl_initialize(argc, argv);
3319 Parser_init("lst > ", lst_cmdlist);
3322 rc = Parser_execarg(argc - 1, argv + 1, lst_cmdlist);