1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Author: Liang Zhen <liangzhen@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org
14 #include <lnet/lnetctl.h>
15 #include <lnet/lnetst.h>
18 static command_t lst_cmdlist[];
19 static lst_sid_t session_id;
20 static int session_key;
21 static lstcon_trans_stat_t trans_stat;
23 typedef struct list_string {
24 struct list_string *lstr_next;
29 #define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
31 static int alloc_count = 0;
32 static int alloc_nob = 0;
37 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
40 fprintf(stderr, "Can't allocate lstr\n");
47 lstr->lstr_str[0] = 0;
53 free_lstr(lstr_t *lstr)
56 alloc_nob -= lstr->lstr_sz;
61 free_lstrs(lstr_t **list)
65 while ((lstr = *list) != NULL) {
66 *list = lstr->lstr_next;
72 new_lstrs(lstr_t **list, char *prefix, char *postfix,
73 int lo, int hi, int stride)
75 int n1 = strlen(prefix);
76 int n2 = strlen(postfix);
77 int sz = n1 + 20 + n2 + 1;
80 lstr_t *n = alloc_lstr(sz);
82 snprintf(n->lstr_str, sz - 1, "%s%u%s",
93 expand_lstr(lstr_t **list, lstr_t *l)
95 int nob = strlen(l->lstr_str);
105 b1 = strchr(l->lstr_str, '[');
107 l->lstr_next = *list;
112 b2 = strchr(b1, ']');
113 if (b2 == NULL || b2 == b1 + 1)
121 sep = strchr(expr, ',');
127 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
129 new_lstrs(list, l->lstr_str, b2, x, x, 1);
134 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
137 new_lstrs(list, l->lstr_str, b2, x, y, 1);
142 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
145 new_lstrs(list, l->lstr_str, b2, x, y, z);
151 } while ((expr = sep) != NULL);
159 expand_strs(char *str, lstr_t **head)
167 l = alloc_lstr(strlen(str) + 1);
168 memcpy(l->lstr_str, str, strlen(str) + 1);
176 while ((l = list) != NULL) {
179 rc = expand_lstr(&nlist, l);
181 fprintf(stderr, "Syntax error in \"%s\"\n", str);
189 /* re-order onto 'list' */
190 while ((l = nlist) != NULL) {
191 nlist = l->lstr_next;
196 } while (expanded && rc > 0);
203 while ((l = list) != NULL) {
212 lst_parse_nids(char *str, int *countp, lnet_process_id_t **idspp)
220 rc = expand_strs(str, &head);
230 *idspp = malloc(c * sizeof(lnet_process_id_t));
231 if (*idspp == NULL) {
232 fprintf(stderr, "Out of memory\n");
239 while ((l = head) != NULL) {
243 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
244 if ((*idspp)[i].nid == LNET_NID_ANY) {
245 fprintf(stderr, "Invalid nid: %s\n",
250 (*idspp)[i].pid = LUSTRE_LNET_PID;
267 lst_node_state2str(int state)
269 if (state == LST_NODE_ACTIVE)
271 if (state == LST_NODE_BUSY)
273 if (state == LST_NODE_DOWN)
280 lst_node_str2state(char *str)
282 if (strcasecmp(str, "active") == 0)
283 return LST_NODE_ACTIVE;
284 if (strcasecmp(str, "busy") == 0)
285 return LST_NODE_BUSY;
286 if (strcasecmp(str, "down") == 0)
287 return LST_NODE_DOWN;
288 if (strcasecmp(str, "unknown") == 0)
289 return LST_NODE_UNKNOWN;
290 if (strcasecmp(str, "invalid") == 0)
291 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
297 lst_test_type2name(int type)
299 if (type == LST_TEST_PING)
301 if (type == LST_TEST_BULK)
308 lst_test_name2type(char *name)
310 if (strcasecmp(name, "ping") == 0)
311 return LST_TEST_PING;
312 if (strcasecmp(name, "brw") == 0)
313 return LST_TEST_BULK;
319 lst_print_usage(char *cmd)
321 Parser_printhelp(cmd);
325 lst_print_error(char *sub, const char *def_format, ...)
329 /* local error returned from kernel */
332 fprintf(stderr, "No session exists\n");
335 fprintf(stderr, "Session is shutting down\n");
338 fprintf(stderr, "Unmatched session key or not root\n");
341 fprintf(stderr, "Can't find %s in current session\n", sub);
344 fprintf(stderr, "Invalid parameters list in command line\n");
347 fprintf(stderr, "Bad parameter address\n");
350 fprintf(stderr, "%s already exists\n", sub);
353 va_start(ap, def_format);
354 vfprintf(stderr, def_format, ap);
362 lst_free_rpcent(struct list_head *head)
364 lstcon_rpc_ent_t *ent;
366 while (!list_empty(head)) {
367 ent = list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
369 list_del(&ent->rpe_link);
375 lst_reset_rpcent(struct list_head *head)
377 lstcon_rpc_ent_t *ent;
379 list_for_each_entry(ent, head, rpe_link) {
380 ent->rpe_sid = LST_INVALID_SID;
381 ent->rpe_peer.nid = LNET_NID_ANY;
382 ent->rpe_peer.pid = LNET_PID_ANY;
383 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
388 lst_alloc_rpcent(struct list_head *head, int count, int offset)
390 lstcon_rpc_ent_t *ent;
393 for (i = 0; i < count; i++) {
394 ent = malloc(offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
396 lst_free_rpcent(head);
400 memset(ent, 0, offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
402 ent->rpe_sid = LST_INVALID_SID;
403 ent->rpe_peer.nid = LNET_NID_ANY;
404 ent->rpe_peer.pid = LNET_PID_ANY;
405 list_add(&ent->rpe_link, head);
412 lst_print_transerr(struct list_head *head, char *optstr)
414 lstcon_rpc_ent_t *ent;
416 list_for_each_entry(ent, head, rpe_link) {
417 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
420 if (ent->rpe_rpc_errno != 0) {
421 fprintf(stderr, "%s RPC failed on %s: %s\n",
422 optstr, libcfs_id2str(ent->rpe_peer),
423 strerror(ent->rpe_rpc_errno));
427 fprintf(stderr, "%s failed on %s: %s\n",
428 optstr, libcfs_id2str(ent->rpe_peer),
429 strerror(ent->rpe_fwk_errno));
434 lst_ioctl(unsigned int opc, void *buf, int len)
436 struct libcfs_ioctl_data data;
439 LIBCFS_IOC_INIT (data);
440 data.ioc_u32[0] = opc;
441 data.ioc_plen1 = len;
442 data.ioc_pbuf1 = (char *)buf;
443 data.ioc_plen2 = sizeof(trans_stat);
444 data.ioc_pbuf2 = (char *)&trans_stat;
446 memset(&trans_stat, 0, sizeof(trans_stat));
448 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
450 /* local error, no valid RPC result */
455 if (trans_stat.trs_rpc_errno != 0)
458 /* Framework error */
459 if (trans_stat.trs_fwk_errno != 0)
466 lst_new_session_ioctl (char *name, int timeout, int force, lst_sid_t *sid)
468 lstio_session_new_args_t args = {
469 .lstio_ses_key = session_key,
470 .lstio_ses_timeout = timeout,
471 .lstio_ses_force = force,
472 .lstio_ses_idp = sid,
473 .lstio_ses_namep = name,
474 .lstio_ses_nmlen = strlen(name),
477 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
481 jt_lst_new_session(int argc, char **argv)
483 char buf[LST_NAME_SIZE];
491 static struct option session_opts[] =
493 {"timeout", required_argument, 0, 't' },
494 {"force", no_argument, 0, 'f' },
498 if (session_key == 0) {
500 "Can't find env LST_SESSION or value is not valid\n");
506 c = getopt_long(argc, argv, "ft:",
507 session_opts, &optidx);
517 timeout = atoi(optarg);
520 lst_print_usage(argv[0]);
526 fprintf(stderr, "Invalid timeout value\n");
530 if (optind == argc - 1) {
531 name = argv[optind ++];
532 if (strlen(name) >= LST_NAME_SIZE) {
533 fprintf(stderr, "Name size is limited to %d\n",
538 } else if (optind == argc) {
539 char user[LST_NAME_SIZE];
540 char host[LST_NAME_SIZE];
541 struct passwd *pw = getpwuid(getuid());
544 snprintf(user, sizeof(user), "%d", (int)getuid());
546 snprintf(user, sizeof(user), "%s", pw->pw_name);
548 rc = gethostname(host, sizeof(host));
550 snprintf(host, sizeof(host), "unknown_host");
552 snprintf(buf, LST_NAME_SIZE, "%s@%s", user, host);
556 lst_print_usage(argv[0]);
560 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
563 lst_print_error("session", "Failed to create session: %s\n",
568 fprintf(stdout, "SESSION: %s TIMEOUT: %d FORCE: %s\n",
569 name, timeout, force ? "Yes": "No");
575 lst_session_info_ioctl(char *name, int len, int *key,
576 lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
578 lstio_session_info_args_t args = {
579 .lstio_ses_keyp = key,
580 .lstio_ses_idp = sid,
581 .lstio_ses_ndinfo = ndinfo,
582 .lstio_ses_nmlen = len,
583 .lstio_ses_namep = name,
586 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
590 jt_lst_show_session(int argc, char **argv)
592 lstcon_ndlist_ent_t ndinfo;
594 char name[LST_NAME_SIZE];
598 rc = lst_session_info_ioctl(name, LST_NAME_SIZE, &key, &sid, &ndinfo);
601 lst_print_error("session", "Failed to show session: %s\n",
606 fprintf(stdout, "%s ID: %Lu@%s, KEY: %d NODES: %d\n",
607 name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
608 key, ndinfo.nle_nnode);
614 lst_end_session_ioctl(void)
616 lstio_session_end_args_t args = {
617 .lstio_ses_key = session_key,
620 return lst_ioctl (LSTIO_SESSION_END, &args, sizeof(args));
624 jt_lst_end_session(int argc, char **argv)
628 if (session_key == 0) {
630 "Can't find env LST_SESSION or value is not valid\n");
634 rc = lst_end_session_ioctl();
637 fprintf(stdout, "session is ended\n");
642 lst_print_error("session", "Failed to end session: %s\n",
647 if (trans_stat.trs_rpc_errno != 0) {
649 "[RPC] Failed to send %d session RPCs: %s\n",
650 lstcon_rpc_stat_failure(&trans_stat, 0),
651 strerror(trans_stat.trs_rpc_errno));
654 if (trans_stat.trs_fwk_errno != 0) {
656 "[FWK] Failed to end session on %d nodes: %s\n",
657 lstcon_sesop_stat_failure(&trans_stat, 0),
658 strerror(trans_stat.trs_fwk_errno));
665 lst_ping_ioctl(char *str, int type, int timeout,
666 int count, lnet_process_id_t *ids, struct list_head *head)
668 lstio_debug_args_t args = {
669 .lstio_dbg_key = session_key,
670 .lstio_dbg_type = type,
671 .lstio_dbg_flags = 0,
672 .lstio_dbg_timeout = timeout,
673 .lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str),
674 .lstio_dbg_namep = str,
675 .lstio_dbg_count = count,
676 .lstio_dbg_idsp = ids,
677 .lstio_dbg_resultp = head,
680 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
683 int lst_info_batch_ioctl(char *batch, int test, int server,
684 lstcon_test_batch_ent_t *entp, int *idxp,
685 int *ndentp, lstcon_node_ent_t *dentsp);
687 int lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
688 int *idx, int *count, lstcon_node_ent_t *dents);
690 int lst_query_batch_ioctl(char *batch, int test, int server,
691 int timeout, struct list_head *head);
694 lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
696 char buf[LST_NAME_SIZE];
697 lstcon_test_batch_ent_t ent;
698 lstcon_ndlist_ent_t *entp = &ent.tbe_cli_nle;
704 case LST_OPC_SESSION:
705 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
709 case LST_OPC_BATCHSRV:
710 entp = &ent.tbe_srv_nle;
711 case LST_OPC_BATCHCLI:
712 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
716 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
720 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
729 *countp = entp->nle_nnode;
735 jt_lst_ping(int argc, char **argv)
737 struct list_head head;
738 lnet_process_id_t *ids = NULL;
739 lstcon_rpc_ent_t *ent = NULL;
749 static struct option ping_opts[] =
751 {"session", no_argument, 0, 's' },
752 {"server", no_argument, 0, 'v' },
753 {"batch", required_argument, 0, 'b' },
754 {"group", required_argument, 0, 'g' },
755 {"nodes", required_argument, 0, 'n' },
756 {"timeout", required_argument, 0, 't' },
760 if (session_key == 0) {
762 "Can't find env LST_SESSION or value is not valid\n");
768 c = getopt_long(argc, argv, "g:b:n:t:sv",
776 type = LST_OPC_SESSION;
780 type = LST_OPC_GROUP;
785 type = LST_OPC_BATCHCLI;
790 type = LST_OPC_NODES;
795 timeout = atoi(optarg);
803 lst_print_usage(argv[0]);
808 if (type == 0 || timeout <= 0 || optind != argc) {
809 lst_print_usage(argv[0]);
813 if (type == LST_OPC_BATCHCLI && server)
814 type = LST_OPC_BATCHSRV;
816 rc = lst_get_node_count(type, str, &count, &ids);
818 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
819 (str == NULL) ? "session" : str, strerror(errno));
823 CFS_INIT_LIST_HEAD(&head);
825 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
827 fprintf(stderr, "Out of memory\n");
832 fprintf(stdout, "Target %s is empty\n",
833 (str == NULL) ? "session" : str);
837 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
838 if (rc == -1) { /* local failure */
839 lst_print_error("debug", "Failed to ping %s: %s\n",
840 (str == NULL) ? "session" : str,
846 /* ignore RPC errors and framwork errors */
847 list_for_each_entry(ent, &head, rpe_link) {
848 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
849 libcfs_id2str(ent->rpe_peer),
850 lst_node_state2str(ent->rpe_state),
851 (ent->rpe_state == LST_NODE_ACTIVE ||
852 ent->rpe_state == LST_NODE_BUSY)?
853 (ent->rpe_rpc_errno == 0 ?
854 &ent->rpe_payload[0] : "Unknown") :
855 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
859 lst_free_rpcent(&head);
869 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
870 struct list_head *resultp)
872 lstio_group_nodes_args_t args = {
873 .lstio_grp_key = session_key,
874 .lstio_grp_nmlen = strlen(name),
875 .lstio_grp_namep = name,
876 .lstio_grp_count = count,
877 .lstio_grp_idsp = ids,
878 .lstio_grp_resultp = resultp,
881 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
885 lst_add_group_ioctl (char *name)
887 lstio_group_add_args_t args = {
888 .lstio_grp_key = session_key,
889 .lstio_grp_nmlen = strlen(name),
890 .lstio_grp_namep = name,
893 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
897 jt_lst_add_group(int argc, char **argv)
899 struct list_head head;
900 lnet_process_id_t *ids;
906 if (session_key == 0) {
908 "Can't find env LST_SESSION or value is not valid\n");
913 lst_print_usage(argv[0]);
918 if (strlen(name) >= LST_NAME_SIZE) {
919 fprintf(stderr, "Name length is limited to %d\n",
924 rc = lst_add_group_ioctl(name);
926 lst_print_error("group", "Failed to add group %s: %s\n",
927 name, strerror(errno));
931 CFS_INIT_LIST_HEAD(&head);
933 for (i = 2; i < argc; i++) {
934 /* parse address list */
935 rc = lst_parse_nids(argv[i], &count, &ids);
937 fprintf(stderr, "Ignore invalid id list %s\n",
945 rc = lst_alloc_rpcent(&head, count, 0);
947 fprintf(stderr, "Out of memory\n");
951 rc = lst_add_nodes_ioctl(name, count, ids, &head);
956 lst_free_rpcent(&head);
957 fprintf(stderr, "%s are added to session\n", argv[i]);
962 lst_free_rpcent(&head);
963 lst_print_error("group", "Failed to add nodes %s: %s\n",
964 argv[i], strerror(errno));
968 lst_print_transerr(&head, "create session");
969 lst_free_rpcent(&head);
976 lst_del_group_ioctl (char *name)
978 lstio_group_del_args_t args = {
979 .lstio_grp_key = session_key,
980 .lstio_grp_nmlen = strlen(name),
981 .lstio_grp_namep = name,
984 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
988 jt_lst_del_group(int argc, char **argv)
992 if (session_key == 0) {
994 "Can't find env LST_SESSION or value is not valid\n");
999 lst_print_usage(argv[0]);
1003 rc = lst_del_group_ioctl(argv[1]);
1005 fprintf(stdout, "Group is deleted\n");
1010 lst_print_error("group", "Failed to delete group: %s\n",
1015 fprintf(stderr, "Group is deleted with some errors\n");
1017 if (trans_stat.trs_rpc_errno != 0) {
1018 fprintf(stderr, "[RPC] Failed to send %d end session RPCs: %s\n",
1019 lstcon_rpc_stat_failure(&trans_stat, 0),
1020 strerror(trans_stat.trs_rpc_errno));
1023 if (trans_stat.trs_fwk_errno != 0) {
1025 "[FWK] Failed to end session on %d nodes: %s\n",
1026 lstcon_sesop_stat_failure(&trans_stat, 0),
1027 strerror(trans_stat.trs_fwk_errno));
1034 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1035 lnet_process_id_t *ids, struct list_head *resultp)
1037 lstio_group_update_args_t args = {
1038 .lstio_grp_key = session_key,
1039 .lstio_grp_opc = opc,
1040 .lstio_grp_args = clean,
1041 .lstio_grp_nmlen = strlen(name),
1042 .lstio_grp_namep = name,
1043 .lstio_grp_count = count,
1044 .lstio_grp_idsp = ids,
1045 .lstio_grp_resultp = resultp,
1048 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1052 jt_lst_update_group(int argc, char **argv)
1054 struct list_head head;
1055 lnet_process_id_t *ids = NULL;
1065 static struct option update_group_opts[] =
1067 {"refresh", no_argument, 0, 'f' },
1068 {"clean", required_argument, 0, 'c' },
1069 {"remove", required_argument, 0, 'r' },
1073 if (session_key == 0) {
1075 "Can't find env LST_SESSION or value is not valid\n");
1080 c = getopt_long(argc, argv, "fc:r:",
1081 update_group_opts, &optidx);
1083 /* Detect the end of the options. */
1090 lst_print_usage(argv[0]);
1093 opc = LST_GROUP_REFRESH;
1098 lst_print_usage(argv[0]);
1101 opc = LST_GROUP_RMND;
1106 clean = lst_node_str2state(optarg);
1107 if (opc != 0 || clean <= 0) {
1108 lst_print_usage(argv[0]);
1111 opc = LST_GROUP_CLEAN;
1115 lst_print_usage(argv[0]);
1120 /* no OPC or group is specified */
1121 if (opc == 0 || optind != argc - 1) {
1122 lst_print_usage(argv[0]);
1128 CFS_INIT_LIST_HEAD(&head);
1130 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1131 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1133 opc == LST_GROUP_RMND ? str : grp,
1137 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1138 opc == LST_GROUP_RMND ? str : grp,
1143 rc = lst_alloc_rpcent(&head, count, 0);
1145 fprintf(stderr, "Out of memory\n");
1152 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1158 lst_free_rpcent(&head);
1163 lst_free_rpcent(&head);
1164 lst_print_error("group", "Failed to update group: %s\n",
1169 lst_print_transerr(&head, "Updating group");
1171 lst_free_rpcent(&head);
1177 lst_list_group_ioctl(int len, char *name, int idx)
1179 lstio_group_list_args_t args = {
1180 .lstio_grp_key = session_key,
1181 .lstio_grp_idx = idx,
1182 .lstio_grp_nmlen = len,
1183 .lstio_grp_namep = name,
1186 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1190 lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
1191 int *idx, int *count, lstcon_node_ent_t *dents)
1193 lstio_group_info_args_t args = {
1194 .lstio_grp_key = session_key,
1195 .lstio_grp_nmlen = strlen(name),
1196 .lstio_grp_namep = name,
1197 .lstio_grp_entp = gent,
1198 .lstio_grp_idxp = idx,
1199 .lstio_grp_ndentp = count,
1200 .lstio_grp_dentsp = dents,
1203 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1207 lst_list_group_all(void)
1209 char name[LST_NAME_SIZE];
1213 /* no group is specified, list name of all groups */
1214 for (i = 0; ; i++) {
1215 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1217 fprintf(stdout, "%d) %s\n", i + 1, name);
1221 if (errno == ENOENT)
1224 lst_print_error("group", "Failed to list group: %s\n",
1229 fprintf(stdout, "Total %d groups\n", i);
1234 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1237 jt_lst_list_group(int argc, char **argv)
1239 lstcon_ndlist_ent_t gent;
1240 lstcon_node_ent_t *dents;
1255 static struct option list_group_opts[] =
1257 {"active", no_argument, 0, 'a' },
1258 {"busy", no_argument, 0, 'b' },
1259 {"down", no_argument, 0, 'd' },
1260 {"unknown", no_argument, 0, 'u' },
1261 {"all", no_argument, 0, 'l' },
1265 if (session_key == 0) {
1267 "Can't find env LST_SESSION or value is not valid\n");
1272 c = getopt_long(argc, argv, "abdul",
1273 list_group_opts, &optidx);
1280 verbose = active = 1;
1292 verbose = unknown = 1;
1299 lst_print_usage(argv[0]);
1304 if (optind == argc) {
1305 /* no group is specified, list name of all groups */
1306 rc = lst_list_group_all();
1312 fprintf(stdout, LST_NODES_TITLE);
1314 /* list nodes in specified groups */
1315 for (i = optind; i < argc; i++) {
1316 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1318 if (errno == ENOENT) {
1323 lst_print_error("group", "Failed to list group\n",
1329 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1330 gent.nle_nactive, gent.nle_nbusy,
1331 gent.nle_ndown, gent.nle_nunknown,
1332 gent.nle_nnode, argv[i]);
1336 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1338 if (gent.nle_nnode == 0) {
1339 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1343 count = gent.nle_nnode;
1345 dents = malloc(count * sizeof(lstcon_node_ent_t));
1346 if (dents == NULL) {
1347 fprintf(stderr, "Failed to malloc: %s\n",
1353 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1355 lst_print_error("group", "Failed to list group: %s\n",
1361 for (j = 0, c = 0; j < count; j++) {
1363 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1364 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1365 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1366 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1368 fprintf(stdout, "\t%s: %s\n",
1369 libcfs_id2str(dents[j].nde_id),
1370 lst_node_state2str(dents[j].nde_state));
1375 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1384 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
1385 int timeout, struct list_head *resultp)
1387 lstio_stat_args_t args = {
1388 .lstio_sta_key = session_key,
1389 .lstio_sta_timeout = timeout,
1390 .lstio_sta_nmlen = strlen(name),
1391 .lstio_sta_namep = name,
1392 .lstio_sta_count = count,
1393 .lstio_sta_idsp = idsp,
1394 .lstio_sta_resultp = resultp,
1397 return lst_ioctl (LSTIO_STAT_QUERY, &args, sizeof(args));
1401 struct list_head srp_link;
1404 lnet_process_id_t *srp_ids;
1405 struct list_head srp_result[2];
1406 } lst_stat_req_param_t;
1409 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1413 for (i = 0; i < 2; i++)
1414 lst_free_rpcent(&srp->srp_result[i]);
1416 if (srp->srp_ids != NULL)
1423 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp)
1425 lst_stat_req_param_t *srp = NULL;
1429 srp = malloc(sizeof(*srp));
1433 memset(srp, 0, sizeof(*srp));
1434 CFS_INIT_LIST_HEAD(&srp->srp_result[0]);
1435 CFS_INIT_LIST_HEAD(&srp->srp_result[1]);
1437 rc = lst_get_node_count(LST_OPC_GROUP, name,
1438 &srp->srp_count, NULL);
1440 rc = lst_get_node_count(LST_OPC_NODES, name,
1441 &srp->srp_count, &srp->srp_ids);
1446 "Failed to get count of nodes from %s\n", name);
1447 lst_stat_req_param_free(srp);
1452 srp->srp_name = name;
1454 for (i = 0; i < 2; i++) {
1455 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1456 sizeof(sfw_counters_t) +
1457 sizeof(srpc_counters_t) +
1458 sizeof(lnet_counters_t));
1460 fprintf(stderr, "Out of memory\n");
1470 lst_stat_req_param_free(srp);
1477 } lst_srpc_stat_result;
1479 #define LST_LNET_AVG 0
1480 #define LST_LNET_MIN 1
1481 #define LST_LNET_MAX 2
1484 float lnet_avg_sndrate;
1485 float lnet_min_sndrate;
1486 float lnet_max_sndrate;
1487 float lnet_total_sndrate;
1489 float lnet_avg_rcvrate;
1490 float lnet_min_rcvrate;
1491 float lnet_max_rcvrate;
1492 float lnet_total_rcvrate;
1494 float lnet_avg_sndperf;
1495 float lnet_min_sndperf;
1496 float lnet_max_sndperf;
1497 float lnet_total_sndperf;
1499 float lnet_avg_rcvperf;
1500 float lnet_min_rcvperf;
1501 float lnet_max_rcvperf;
1502 float lnet_total_rcvperf;
1504 int lnet_stat_count;
1505 } lst_lnet_stat_result_t;
1507 lst_lnet_stat_result_t lnet_stat_result;
1510 lst_lnet_stat_value(int bw, int send, int off)
1514 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1515 &lnet_stat_result.lnet_avg_sndrate;
1526 lst_timeval_diff(struct timeval *tv1,
1527 struct timeval *tv2, struct timeval *df)
1529 if (tv1->tv_usec >= tv2->tv_usec) {
1530 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1531 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1535 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1536 df->tv_usec = tv1->tv_sec + 1000000 - tv2->tv_usec;
1542 lst_cal_lnet_stat(float delta, lnet_counters_t *lnet_new,
1543 lnet_counters_t *lnet_old)
1548 perf = (float)(lnet_new->send_length -
1549 lnet_old->send_length) / (1024 * 1024) / delta;
1550 lnet_stat_result.lnet_total_sndperf += perf;
1552 if (lnet_stat_result.lnet_min_sndperf > perf ||
1553 lnet_stat_result.lnet_min_sndperf == 0)
1554 lnet_stat_result.lnet_min_sndperf = perf;
1556 if (lnet_stat_result.lnet_max_sndperf < perf)
1557 lnet_stat_result.lnet_max_sndperf = perf;
1559 perf = (float)(lnet_new->recv_length -
1560 lnet_old->recv_length) / (1024 * 1024) / delta;
1561 lnet_stat_result.lnet_total_rcvperf += perf;
1563 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1564 lnet_stat_result.lnet_min_rcvperf == 0)
1565 lnet_stat_result.lnet_min_rcvperf = perf;
1567 if (lnet_stat_result.lnet_max_rcvperf < perf)
1568 lnet_stat_result.lnet_max_rcvperf = perf;
1570 rate = (lnet_new->send_count - lnet_old->send_count) / delta;
1571 lnet_stat_result.lnet_total_sndrate += rate;
1573 if (lnet_stat_result.lnet_min_sndrate > rate ||
1574 lnet_stat_result.lnet_min_sndrate == 0)
1575 lnet_stat_result.lnet_min_sndrate = rate;
1577 if (lnet_stat_result.lnet_max_sndrate < rate)
1578 lnet_stat_result.lnet_max_sndrate = rate;
1580 rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
1581 lnet_stat_result.lnet_total_rcvrate += rate;
1583 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1584 lnet_stat_result.lnet_min_rcvrate == 0)
1585 lnet_stat_result.lnet_min_rcvrate = rate;
1587 if (lnet_stat_result.lnet_max_rcvrate < rate)
1588 lnet_stat_result.lnet_max_rcvrate = rate;
1590 lnet_stat_result.lnet_stat_count ++;
1592 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1593 lnet_stat_result.lnet_stat_count;
1594 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1595 lnet_stat_result.lnet_stat_count;
1597 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1598 lnet_stat_result.lnet_stat_count;
1599 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1600 lnet_stat_result.lnet_stat_count;
1605 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
1614 if (lnet_stat_result.lnet_stat_count == 0)
1617 if (bwrt == 1) /* bw only */
1620 if (bwrt == 2) /* rates only */
1623 if (rdwr == 1) /* recv only */
1626 if (rdwr == 2) /* send only */
1629 for (i = start1; i <= end1; i++) {
1630 fprintf(stdout, "[LNet %s of %s]\n",
1631 i == 0 ? "Rates" : "Bandwidth", name);
1633 for (j = start2; j <= end2; j++) {
1634 fprintf(stdout, "[%c] ", j == 0 ? 'W' : 'R');
1636 if ((type & 1) != 0) {
1637 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1638 "Avg: %-8.2f MB/s ",
1639 lst_lnet_stat_value(i, j, 0));
1642 if ((type & 2) != 0) {
1643 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1644 "Min: %-8.2f MB/s ",
1645 lst_lnet_stat_value(i, j, 1));
1648 if ((type & 4) != 0) {
1649 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1651 lst_lnet_stat_value(i, j, 2));
1654 fprintf(stdout, "\n");
1660 lst_print_stat(char *name, struct list_head *resultp,
1661 int idx, int lnet, int bwrt, int rdwr, int type)
1663 struct list_head tmp[2];
1664 lstcon_rpc_ent_t *new;
1665 lstcon_rpc_ent_t *old;
1666 sfw_counters_t *sfwk_new;
1667 sfw_counters_t *sfwk_old;
1668 srpc_counters_t *srpc_new;
1669 srpc_counters_t *srpc_old;
1670 lnet_counters_t *lnet_new;
1671 lnet_counters_t *lnet_old;
1676 CFS_INIT_LIST_HEAD(&tmp[0]);
1677 CFS_INIT_LIST_HEAD(&tmp[1]);
1679 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1681 while (!list_empty(&resultp[idx])) {
1682 if (list_empty(&resultp[1 - idx])) {
1683 fprintf(stderr, "Group is changed, re-run stat\n");
1687 new = list_entry(resultp[idx].next, lstcon_rpc_ent_t, rpe_link);
1688 old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t, rpe_link);
1690 /* first time get stats result, can't calculate diff */
1691 if (new->rpe_peer.nid == LNET_NID_ANY)
1694 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1695 new->rpe_peer.pid != old->rpe_peer.pid) {
1696 /* Something wrong. i.e, somebody change the group */
1700 list_del(&new->rpe_link);
1701 list_add_tail(&new->rpe_link, &tmp[idx]);
1703 list_del(&old->rpe_link);
1704 list_add_tail(&old->rpe_link, &tmp[1 - idx]);
1706 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1707 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1712 sfwk_new = (sfw_counters_t *)&new->rpe_payload[0];
1713 sfwk_old = (sfw_counters_t *)&old->rpe_payload[0];
1715 srpc_new = (srpc_counters_t *)((char *)sfwk_new + sizeof(*sfwk_new));
1716 srpc_old = (srpc_counters_t *)((char *)sfwk_old + sizeof(*sfwk_old));
1718 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
1719 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
1721 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1723 delta = tv.tv_sec + (float)tv.tv_usec/1000000;
1725 if (!lnet) /* TODO */
1728 lst_cal_lnet_stat(delta, lnet_new, lnet_old);
1731 list_splice(&tmp[idx], &resultp[idx]);
1732 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1735 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1737 if (!lnet) /* TODO */
1740 lst_print_lnet_stat(name, bwrt, rdwr, type);
1744 jt_lst_stat(int argc, char **argv)
1746 struct list_head head;
1747 lst_stat_req_param_t *srp;
1751 int timeout = 5; /* default timeout, 5 sec */
1752 int delay = 5; /* default delay, 5 sec */
1753 int lnet = 1; /* lnet stat by default */
1761 static struct option stat_opts[] =
1763 {"timeout", required_argument, 0, 't' },
1764 {"delay" , required_argument, 0, 'd' },
1765 {"lnet" , no_argument, 0, 'l' },
1766 {"rpc" , no_argument, 0, 'c' },
1767 {"bw" , no_argument, 0, 'b' },
1768 {"rate" , no_argument, 0, 'a' },
1769 {"read" , no_argument, 0, 'r' },
1770 {"write" , no_argument, 0, 'w' },
1771 {"avg" , no_argument, 0, 'g' },
1772 {"min" , no_argument, 0, 'n' },
1773 {"max" , no_argument, 0, 'x' },
1777 if (session_key == 0) {
1779 "Can't find env LST_SESSION or value is not valid\n");
1784 c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
1791 timeout = atoi(optarg);
1794 delay = atoi(optarg);
1836 lst_print_usage(argv[0]);
1841 if (optind == argc) {
1842 lst_print_usage(argv[0]);
1846 if (timeout <= 0 || delay <= 0) {
1847 fprintf(stderr, "Invalid timeout or delay value\n");
1851 CFS_INIT_LIST_HEAD(&head);
1853 while (optind < argc) {
1854 name = argv[optind++];
1856 rc = lst_stat_req_param_alloc(name, &srp);
1860 list_add_tail(&srp->srp_link, &head);
1864 time_t now = time(NULL);
1866 if (now - last < delay) {
1867 sleep(delay - now + last);
1873 list_for_each_entry(srp, &head, srp_link) {
1874 rc = lst_stat_ioctl(srp->srp_name,
1875 srp->srp_count, srp->srp_ids,
1876 timeout, &srp->srp_result[idx]);
1878 lst_print_error("stat", "Failed to stat %s: %s\n",
1879 name, strerror(errno));
1883 lst_print_stat(srp->srp_name, srp->srp_result,
1884 idx, lnet, bwrt, rdwr, type);
1886 lst_reset_rpcent(&srp->srp_result[1 - idx]);
1893 while (!list_empty(&head)) {
1894 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
1896 list_del(&srp->srp_link);
1897 lst_stat_req_param_free(srp);
1904 jt_lst_show_error(int argc, char **argv)
1906 struct list_head head;
1907 lstcon_rpc_ent_t *ent;
1908 sfw_counters_t *sfwk;
1909 srpc_counters_t *srpc;
1910 lnet_counters_t *lnet;
1911 lnet_process_id_t *idsp = NULL;
1922 static struct option show_error_opts[] =
1924 {"group" , required_argument, 0, 'g' },
1925 {"nodes" , required_argument, 0, 'n' },
1929 if (session_key == 0) {
1931 "Can't find env LST_SESSION or value is not valid\n");
1936 c = getopt_long(argc, argv, "g:n:", show_error_opts, &optidx);
1943 type = LST_OPC_GROUP;
1947 type = LST_OPC_NODES;
1951 lst_print_usage(argv[0]);
1956 if (optind != argc || type == 0) {
1957 lst_print_usage(argv[0]);
1962 fprintf(stderr, "Missing name of target (group | nodes)\n");
1966 rc = lst_get_node_count(type, name, &count, &idsp);
1968 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
1969 name, strerror(errno));
1973 CFS_INIT_LIST_HEAD(&head);
1975 rc = lst_alloc_rpcent(&head, count, sizeof(sfw_counters_t) +
1976 sizeof(srpc_counters_t) +
1977 sizeof(lnet_counters_t));
1979 fprintf(stderr, "Out of memory\n");
1983 rc = lst_stat_ioctl(name, count, idsp, timeout, &head);
1985 lst_print_error(name, "Failed to show errors of %s: %s\n",
1986 name, strerror(errno));
1990 list_for_each_entry(ent, &head, rpe_link) {
1991 if (ent->rpe_rpc_errno != 0) {
1993 fprintf(stderr, "RPC failure, can't show error on %s\n",
1994 libcfs_id2str(ent->rpe_peer));
1998 if (ent->rpe_fwk_errno != 0) {
2000 fprintf(stderr, "Framework failure, can't show error on %s\n",
2001 libcfs_id2str(ent->rpe_peer));
2005 sfwk = (sfw_counters_t *)&ent->rpe_payload[0];
2006 srpc = (srpc_counters_t *)((char *)sfwk + sizeof(*sfwk));
2007 lnet = (lnet_counters_t *)((char *)srpc + sizeof(*srpc));
2009 if (srpc->errors == 0 &&
2010 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2014 fprintf(stderr, "[%s]: %d RPC errors, %d brw errors, %d ping errors\n",
2015 libcfs_id2str(ent->rpe_peer), srpc->errors,
2016 sfwk->brw_errors, sfwk->ping_errors);
2019 fprintf(stdout, "Total %d errors in %s\n", ecount, name);
2021 lst_free_rpcent(&head);
2029 lst_add_batch_ioctl (char *name)
2031 lstio_batch_add_args_t args = {
2032 .lstio_bat_key = session_key,
2033 .lstio_bat_nmlen = strlen(name),
2034 .lstio_bat_namep = name,
2037 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2041 jt_lst_add_batch(int argc, char **argv)
2046 if (session_key == 0) {
2048 "Can't find env LST_SESSION or value is not valid\n");
2053 lst_print_usage(argv[0]);
2058 if (strlen(name) >= LST_NAME_SIZE) {
2059 fprintf(stderr, "Name length is limited to %d\n",
2064 rc = lst_add_batch_ioctl(name);
2068 lst_print_error("batch", "Failed to create batch: %s\n",
2075 lst_start_batch_ioctl (char *name, int timeout, struct list_head *resultp)
2077 lstio_batch_run_args_t args = {
2078 .lstio_bat_key = session_key,
2079 .lstio_bat_timeout = timeout,
2080 .lstio_bat_nmlen = strlen(name),
2081 .lstio_bat_namep = name,
2082 .lstio_bat_resultp = resultp,
2085 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2089 jt_lst_start_batch(int argc, char **argv)
2091 struct list_head head;
2099 static struct option start_batch_opts[] =
2101 {"timeout", required_argument, 0, 't' },
2105 if (session_key == 0) {
2107 "Can't find env LST_SESSION or value is not valid\n");
2112 c = getopt_long(argc, argv, "t:",
2113 start_batch_opts, &optidx);
2115 /* Detect the end of the options. */
2121 timeout = atoi(optarg);
2124 lst_print_usage(argv[0]);
2129 if (optind == argc) {
2130 batch = LST_DEFAULT_BATCH;
2132 } else if (optind == argc - 1) {
2133 batch = argv[optind];
2136 lst_print_usage(argv[0]);
2140 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2142 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2143 batch, strerror(errno));
2147 CFS_INIT_LIST_HEAD(&head);
2149 rc = lst_alloc_rpcent(&head, count, 0);
2151 fprintf(stderr, "Out of memory\n");
2155 rc = lst_start_batch_ioctl(batch, timeout, &head);
2158 fprintf(stdout, "%s is running now\n", batch);
2159 lst_free_rpcent(&head);
2164 lst_print_error("batch", "Failed to start batch: %s\n",
2166 lst_free_rpcent(&head);
2170 lst_print_transerr(&head, "Run batch");
2172 lst_free_rpcent(&head);
2178 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2180 lstio_batch_stop_args_t args = {
2181 .lstio_bat_key = session_key,
2182 .lstio_bat_force = force,
2183 .lstio_bat_nmlen = strlen(name),
2184 .lstio_bat_namep = name,
2185 .lstio_bat_resultp = resultp,
2188 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2192 jt_lst_stop_batch(int argc, char **argv)
2194 struct list_head head;
2202 static struct option stop_batch_opts[] =
2204 {"force", no_argument, 0, 'f' },
2208 if (session_key == 0) {
2210 "Can't find env LST_SESSION or value is not valid\n");
2215 c = getopt_long(argc, argv, "f",
2216 stop_batch_opts, &optidx);
2218 /* Detect the end of the options. */
2227 lst_print_usage(argv[0]);
2232 if (optind == argc) {
2233 batch = LST_DEFAULT_BATCH;
2235 } else if (optind == argc - 1) {
2236 batch = argv[optind];
2239 lst_print_usage(argv[0]);
2243 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2245 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2246 batch, strerror(errno));
2250 CFS_INIT_LIST_HEAD(&head);
2252 rc = lst_alloc_rpcent(&head, count, 0);
2254 fprintf(stderr, "Out of memory\n");
2258 rc = lst_stop_batch_ioctl(batch, force, &head);
2263 lst_reset_rpcent(&head);
2265 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2269 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2270 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2273 fprintf(stdout, "%d batch in stopping\n",
2274 lstcon_tsbqry_stat_run(&trans_stat, 0));
2278 fprintf(stdout, "Batch is stopped\n");
2279 lst_free_rpcent(&head);
2284 lst_print_error("batch", "Failed to stop batch: %s\n",
2286 lst_free_rpcent(&head);
2290 lst_print_transerr(&head, "stop batch");
2292 lst_free_rpcent(&head);
2298 lst_list_batch_ioctl(int len, char *name, int index)
2300 lstio_batch_list_args_t args = {
2301 .lstio_bat_key = session_key,
2302 .lstio_bat_idx = index,
2303 .lstio_bat_nmlen = len,
2304 .lstio_bat_namep = name,
2307 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2311 lst_info_batch_ioctl(char *batch, int test, int server,
2312 lstcon_test_batch_ent_t *entp, int *idxp,
2313 int *ndentp, lstcon_node_ent_t *dentsp)
2315 lstio_batch_info_args_t args = {
2316 .lstio_bat_key = session_key,
2317 .lstio_bat_nmlen = strlen(batch),
2318 .lstio_bat_namep = batch,
2319 .lstio_bat_server = server,
2320 .lstio_bat_testidx = test,
2321 .lstio_bat_entp = entp,
2322 .lstio_bat_idxp = idxp,
2323 .lstio_bat_ndentp = ndentp,
2324 .lstio_bat_dentsp = dentsp,
2327 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2331 lst_list_batch_all(void)
2333 char name[LST_NAME_SIZE];
2337 for (i = 0; ; i++) {
2338 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2340 fprintf(stdout, "%d) %s\n", i + 1, name);
2344 if (errno == ENOENT)
2347 lst_print_error("batch", "Failed to list batch: %s\n",
2352 fprintf(stdout, "Total %d batches\n", i);
2358 lst_list_tsb_nodes(char *batch, int test, int server,
2359 int count, int active, int invalid)
2361 lstcon_node_ent_t *dents;
2370 /* verbose list, show nodes in batch or test */
2371 dents = malloc(count * sizeof(lstcon_node_ent_t));
2372 if (dents == NULL) {
2373 fprintf(stdout, "Can't allocate memory\n");
2377 rc = lst_info_batch_ioctl(batch, test, server,
2378 NULL, &index, &count, dents);
2381 lst_print_error((test > 0) ? "test" : "batch",
2382 (test > 0) ? "Failed to query test: %s\n" :
2383 "Failed to query batch: %s\n",
2388 for (i = 0, c = 0; i < count; i++) {
2389 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2390 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2391 dents[i].nde_state == LST_NODE_DOWN ||
2392 dents[i].nde_state == LST_NODE_UNKNOWN)))
2395 fprintf(stdout, "\t%s: %s\n",
2396 libcfs_id2str(dents[i].nde_id),
2397 lst_node_state2str(dents[i].nde_state));
2401 fprintf(stdout, "Total %d nodes\n", c);
2408 jt_lst_list_batch(int argc, char **argv)
2410 lstcon_test_batch_ent_t ent;
2413 int verbose = 0; /* list nodes in batch or test */
2422 static struct option list_batch_opts[] =
2424 {"test", required_argument, 0, 't' },
2425 {"invalid", no_argument, 0, 'i' },
2426 {"active", no_argument, 0, 'a' },
2427 {"all", no_argument, 0, 'l' },
2428 {"server", no_argument, 0, 's' },
2432 if (session_key == 0) {
2434 "Can't find env LST_SESSION or value is not valid\n");
2439 c = getopt_long(argc, argv, "ailst:",
2440 list_batch_opts, &optidx);
2447 verbose = active = 1;
2450 verbose = invalid = 1;
2453 verbose = active = invalid = 1;
2459 test = atoi(optarg);
2463 lst_print_usage(argv[0]);
2468 if (optind == argc) {
2469 /* list all batches */
2470 rc = lst_list_batch_all();
2474 if (ntest == 1 && test <= 0) {
2475 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2479 if (optind != argc - 1) {
2480 lst_print_usage(argv[0]);
2484 batch = argv[optind];
2487 /* show detail of specified batch or test */
2488 rc = lst_info_batch_ioctl(batch, test, server,
2489 &ent, NULL, NULL, NULL);
2491 lst_print_error((test > 0) ? "test" : "batch",
2492 (test > 0) ? "Failed to query test: %s\n" :
2493 "Failed to query batch: %s\n",
2499 /* list nodes in test or batch */
2500 rc = lst_list_tsb_nodes(batch, test, server,
2501 server ? ent.tbe_srv_nle.nle_nnode :
2502 ent.tbe_cli_nle.nle_nnode,
2507 /* only show number of hosts in batch or test */
2509 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2510 batch, ent.u.tbe_batch.bae_ntest,
2511 ent.u.tbe_batch.bae_state);
2512 ntest = ent.u.tbe_batch.bae_ntest;
2513 test = 1; /* starting from test 1 */
2517 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2518 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2519 ent.u.tbe_test.tse_loop,
2520 ent.u.tbe_test.tse_concur);
2525 fprintf(stdout, LST_NODES_TITLE);
2526 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2527 "server\t%d\t%d\t%d\t%d\t%d\n",
2528 ent.tbe_cli_nle.nle_nactive,
2529 ent.tbe_cli_nle.nle_nbusy,
2530 ent.tbe_cli_nle.nle_ndown,
2531 ent.tbe_cli_nle.nle_nunknown,
2532 ent.tbe_cli_nle.nle_nnode,
2533 ent.tbe_srv_nle.nle_nactive,
2534 ent.tbe_srv_nle.nle_nbusy,
2535 ent.tbe_srv_nle.nle_ndown,
2536 ent.tbe_srv_nle.nle_nunknown,
2537 ent.tbe_srv_nle.nle_nnode);
2546 lst_query_batch_ioctl(char *batch, int test, int server,
2547 int timeout, struct list_head *head)
2549 lstio_batch_query_args_t args = {
2550 .lstio_bat_key = session_key,
2551 .lstio_bat_testidx = test,
2552 .lstio_bat_client = !(server),
2553 .lstio_bat_timeout = timeout,
2554 .lstio_bat_nmlen = strlen(batch),
2555 .lstio_bat_namep = batch,
2556 .lstio_bat_resultp = head,
2559 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2563 lst_print_tsb_verbose(struct list_head *head,
2564 int active, int idle, int error)
2566 lstcon_rpc_ent_t *ent;
2568 list_for_each_entry(ent, head, rpe_link) {
2569 if (ent->rpe_priv[0] == 0 && active)
2572 if (ent->rpe_priv[0] != 0 && idle)
2575 if (ent->rpe_fwk_errno == 0 && error)
2578 fprintf(stdout, "%s [%s]: %s\n",
2579 libcfs_id2str(ent->rpe_peer),
2580 lst_node_state2str(ent->rpe_state),
2581 ent->rpe_rpc_errno != 0 ?
2582 strerror(ent->rpe_rpc_errno) :
2583 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2588 jt_lst_query_batch(int argc, char **argv)
2590 lstcon_test_batch_ent_t ent;
2591 struct list_head head;
2597 int timeout = 5; /* default 5 seconds */
2598 int delay = 5; /* default 5 seconds */
2599 int loop = 1; /* default 1 loop */
2609 static struct option query_batch_opts[] =
2611 {"timeout", required_argument, 0, 'o' },
2612 {"delay", required_argument, 0, 'd' },
2613 {"loop", required_argument, 0, 'c' },
2614 {"test", required_argument, 0, 't' },
2615 {"server", no_argument, 0, 's' },
2616 {"active", no_argument, 0, 'a' },
2617 {"idle", no_argument, 0, 'i' },
2618 {"error", no_argument, 0, 'e' },
2619 {"all", no_argument, 0, 'l' },
2623 if (session_key == 0) {
2625 "Can't find env LST_SESSION or value is not valid\n");
2630 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2631 query_batch_opts, &optidx);
2633 /* Detect the end of the options. */
2639 timeout = atoi(optarg);
2642 delay = atoi(optarg);
2645 loop = atoi(optarg);
2648 test = atoi(optarg);
2654 active = verbose = 1;
2660 error = verbose = 1;
2666 lst_print_usage(argv[0]);
2671 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2672 lst_print_usage(argv[0]);
2676 if (optind == argc) {
2677 batch = LST_DEFAULT_BATCH;
2679 } else if (optind == argc - 1) {
2680 batch = argv[optind];
2683 lst_print_usage(argv[0]);
2688 CFS_INIT_LIST_HEAD(&head);
2691 rc = lst_info_batch_ioctl(batch, test, server,
2692 &ent, NULL, NULL, NULL);
2694 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2695 batch, test, strerror(errno));
2699 count = server ? ent.tbe_srv_nle.nle_nnode :
2700 ent.tbe_cli_nle.nle_nnode;
2702 fprintf(stdout, "Batch or test is empty\n");
2707 rc = lst_alloc_rpcent(&head, count, 0);
2709 fprintf(stderr, "Out of memory\n");
2713 for (i = 0; i < loop; i++) {
2714 time_t now = time(NULL);
2716 if (now - last < delay) {
2717 sleep(delay - now + last);
2723 rc = lst_query_batch_ioctl(batch, test,
2724 server, timeout, &head);
2726 fprintf(stderr, "Failed to query batch: %s\n",
2733 lst_print_tsb_verbose(&head, active, idle, error);
2737 fprintf(stdout, "%s [%d] ", batch, test);
2739 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2740 fprintf(stdout, "%d of %d nodes are unknown, ",
2741 lstcon_rpc_stat_failure(&trans_stat, 0),
2742 lstcon_rpc_stat_total(&trans_stat, 0));
2745 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2746 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2747 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2748 fprintf(stdout, "is stopped\n");
2752 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2753 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2754 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2755 fprintf(stdout, "is running\n");
2759 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2760 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2761 lstcon_tsbqry_stat_run(&trans_stat, 0),
2762 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2765 lst_free_rpcent(&head);
2771 lst_parse_distribute(char *dstr, int *dist, int *span)
2777 dstr = strchr(dstr, ':');
2781 *span = atoi(dstr + 1);
2789 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
2791 lst_test_bulk_param_t *bulk = NULL;
2795 type = lst_test_name2type(test);
2807 bulk = malloc(sizeof(*bulk));
2811 memset(bulk, 0, sizeof(*bulk));
2813 if (strcmp(argv[i], "w") == 0)
2814 bulk->blk_opc = LST_BRW_WRITE;
2815 else /* read by default */
2816 bulk->blk_opc = LST_BRW_READ;
2819 /* 1 page by default */
2820 bulk->blk_flags = LST_BRW_CHECK_NONE;
2823 *plen = sizeof(*bulk);
2828 bulk->blk_npg = atoi(argv[i]);
2829 if (bulk->blk_npg <= 0 ||
2830 bulk->blk_npg >= LNET_MAX_IOV) {
2836 bulk->blk_flags = LST_BRW_CHECK_NONE;
2838 *plen = sizeof(*bulk);
2843 if (strcmp(argv[i], "s") == 0)
2844 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2845 else if (strcmp(argv[i], "f") == 0)
2846 bulk->blk_flags = LST_BRW_CHECK_FULL;
2848 bulk->blk_flags = LST_BRW_CHECK_NONE;
2851 *plen = sizeof(*bulk);
2859 /* TODO: parse more parameter */
2864 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
2865 int dist, int span, char *sgrp, char *dgrp,
2866 void *param, int plen, int *retp, struct list_head *resultp)
2868 lstio_test_args_t args = {
2869 .lstio_tes_key = session_key,
2870 .lstio_tes_bat_nmlen = strlen(batch),
2871 .lstio_tes_bat_name = batch,
2872 .lstio_tes_type = type,
2873 .lstio_tes_loop = loop,
2874 .lstio_tes_concur = concur,
2875 .lstio_tes_dist = dist,
2876 .lstio_tes_span = span,
2877 .lstio_tes_sgrp_nmlen = strlen(sgrp),
2878 .lstio_tes_sgrp_name = sgrp,
2879 .lstio_tes_dgrp_nmlen = strlen(dgrp),
2880 .lstio_tes_dgrp_name = dgrp,
2881 .lstio_tes_param_len = plen,
2882 .lstio_tes_param = param,
2883 .lstio_tes_retp = retp,
2884 .lstio_tes_resultp = resultp,
2887 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
2891 jt_lst_add_test(int argc, char **argv)
2893 struct list_head head;
2913 static struct option add_test_opts[] =
2915 {"batch", required_argument, 0, 'b' },
2916 {"concurrency", required_argument, 0, 'c' },
2917 {"distribute", required_argument, 0, 'd' },
2918 {"from", required_argument, 0, 'f' },
2919 {"to", required_argument, 0, 't' },
2920 {"loop", required_argument, 0, 'l' },
2924 if (session_key == 0) {
2926 "Can't find env LST_SESSION or value is not valid\n");
2931 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
2932 add_test_opts, &optidx);
2934 /* Detect the end of the options. */
2943 concur = atoi(optarg);
2952 loop = atoi(optarg);
2958 lst_print_usage(argv[0]);
2963 if (optind == argc || from == NULL || to == NULL) {
2964 lst_print_usage(argv[0]);
2968 if (concur <= 0 || concur > LST_MAX_CONCUR) {
2969 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
2974 batch = LST_DEFAULT_BATCH;
2977 rc = lst_parse_distribute(dstr, &dist, &span);
2979 fprintf(stderr, "Invalid distribution: %s\n", dstr);
2984 test = argv[optind++];
2989 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
2991 fprintf(stderr, "Can't parse test (%s) parameter: %s\n",
2992 test, strerror(-type));
2996 CFS_INIT_LIST_HEAD(&head);
2998 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3000 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3001 from, strerror(errno));
3005 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3007 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3008 to, strerror(errno));
3012 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3014 fprintf(stderr, "Out of memory\n");
3018 rc = lst_add_test_ioctl(batch, type, loop, concur,
3019 dist, span, from, to, param, plen, &ret, &head);
3022 fprintf(stdout, "Test was added successfully\n");
3024 fprintf(stdout, "Server group contains userland test "
3025 "nodes, old version of tcplnd can't accept "
3026 "connection request\n");
3033 lst_print_error("test", "Failed to add test: %s\n",
3038 lst_print_transerr(&head, "add test");
3040 lst_free_rpcent(&head);
3048 static command_t lst_cmdlist[] = {
3049 {"new_session", jt_lst_new_session, NULL,
3050 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3051 {"end_session", jt_lst_end_session, NULL,
3052 "Usage: lst end_session" },
3053 {"show_session", jt_lst_show_session, NULL,
3054 "Usage: lst show_session" },
3055 {"ping", jt_lst_ping , NULL,
3056 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3057 {"add_group", jt_lst_add_group, NULL,
3058 "Usage: lst group NAME IDs [IDs]..." },
3059 {"del_group", jt_lst_del_group, NULL,
3060 "Usage: lst del_group NAME" },
3061 {"update_group", jt_lst_update_group, NULL,
3062 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3063 {"list_group", jt_lst_list_group, NULL,
3064 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3065 {"stat", jt_lst_stat, NULL,
3066 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3067 " [--timeout #] [--delay #] GROUP [GROUP]" },
3068 {"show_error", jt_lst_show_error, NULL,
3069 "Usage: lst show_error [--group NAME] | [--nodes IDS]" },
3070 {"add_batch", jt_lst_add_batch, NULL,
3071 "Usage: lst add_batch NAME" },
3072 {"run", jt_lst_start_batch, NULL,
3073 "Usage: lst run [--timeout TIME] [NAME]" },
3074 {"stop", jt_lst_stop_batch, NULL,
3075 "Usage: lst stop [--force] BATCH_NAME" },
3076 {"list_batch", jt_lst_list_batch, NULL,
3077 "Usage: lst list_batch NAME [--test ID] [--server]" },
3078 {"query", jt_lst_query_batch, NULL,
3079 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3080 {"add_test", jt_lst_add_test, NULL,
3081 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3082 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3083 {"help", Parser_help, 0, "help" },
3088 lst_initialize(void)
3092 key = getenv("LST_SESSION");
3099 session_key = atoi(key);
3105 main(int argc, char **argv)
3109 if (lst_initialize() < 0)
3112 if (ptl_initialize(argc, argv) < 0)
3115 Parser_init("lst > ", lst_cmdlist);
3118 return Parser_execarg(argc - 1, argv + 1, lst_cmdlist);