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
17 #include <lnet/lnetctl.h>
18 #include <lnet/lnetst.h>
21 static command_t lst_cmdlist[];
22 static lst_sid_t session_id;
23 static int session_key;
24 static lstcon_trans_stat_t trans_stat;
26 typedef struct list_string {
27 struct list_string *lstr_next;
32 #define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
34 static int alloc_count = 0;
35 static int alloc_nob = 0;
40 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
43 fprintf(stderr, "Can't allocate lstr\n");
50 lstr->lstr_str[0] = 0;
56 free_lstr(lstr_t *lstr)
59 alloc_nob -= lstr->lstr_sz;
64 free_lstrs(lstr_t **list)
68 while ((lstr = *list) != NULL) {
69 *list = lstr->lstr_next;
75 new_lstrs(lstr_t **list, char *prefix, char *postfix,
76 int lo, int hi, int stride)
78 int n1 = strlen(prefix);
79 int n2 = strlen(postfix);
80 int sz = n1 + 20 + n2 + 1;
83 lstr_t *n = alloc_lstr(sz);
85 snprintf(n->lstr_str, sz - 1, "%s%u%s",
96 expand_lstr(lstr_t **list, lstr_t *l)
98 int nob = strlen(l->lstr_str);
108 b1 = strchr(l->lstr_str, '[');
110 l->lstr_next = *list;
115 b2 = strchr(b1, ']');
116 if (b2 == NULL || b2 == b1 + 1)
124 sep = strchr(expr, ',');
130 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
132 new_lstrs(list, l->lstr_str, b2, x, x, 1);
137 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
140 new_lstrs(list, l->lstr_str, b2, x, y, 1);
145 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
148 new_lstrs(list, l->lstr_str, b2, x, y, z);
154 } while ((expr = sep) != NULL);
162 expand_strs(char *str, lstr_t **head)
170 l = alloc_lstr(strlen(str) + 1);
171 memcpy(l->lstr_str, str, strlen(str) + 1);
179 while ((l = list) != NULL) {
182 rc = expand_lstr(&nlist, l);
184 fprintf(stderr, "Syntax error in \"%s\"\n", str);
192 /* re-order onto 'list' */
193 while ((l = nlist) != NULL) {
194 nlist = l->lstr_next;
199 } while (expanded && rc > 0);
206 while ((l = list) != NULL) {
215 lst_parse_nids(char *str, int *countp, lnet_process_id_t **idspp)
223 rc = expand_strs(str, &head);
233 *idspp = malloc(c * sizeof(lnet_process_id_t));
234 if (*idspp == NULL) {
235 fprintf(stderr, "Out of memory\n");
242 while ((l = head) != NULL) {
246 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
247 if ((*idspp)[i].nid == LNET_NID_ANY) {
248 fprintf(stderr, "Invalid nid: %s\n",
253 (*idspp)[i].pid = LUSTRE_LNET_PID;
270 lst_node_state2str(int state)
272 if (state == LST_NODE_ACTIVE)
274 if (state == LST_NODE_BUSY)
276 if (state == LST_NODE_DOWN)
283 lst_node_str2state(char *str)
285 if (strcasecmp(str, "active") == 0)
286 return LST_NODE_ACTIVE;
287 if (strcasecmp(str, "busy") == 0)
288 return LST_NODE_BUSY;
289 if (strcasecmp(str, "down") == 0)
290 return LST_NODE_DOWN;
291 if (strcasecmp(str, "unknown") == 0)
292 return LST_NODE_UNKNOWN;
293 if (strcasecmp(str, "invalid") == 0)
294 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
300 lst_test_type2name(int type)
302 if (type == LST_TEST_PING)
304 if (type == LST_TEST_BULK)
311 lst_test_name2type(char *name)
313 if (strcasecmp(name, "ping") == 0)
314 return LST_TEST_PING;
315 if (strcasecmp(name, "brw") == 0)
316 return LST_TEST_BULK;
322 lst_print_usage(char *cmd)
324 Parser_printhelp(cmd);
328 lst_print_error(char *sub, const char *def_format, ...)
332 /* local error returned from kernel */
335 fprintf(stderr, "No session exists\n");
338 fprintf(stderr, "Session is shutting down\n");
341 fprintf(stderr, "Unmatched session key or not root\n");
344 fprintf(stderr, "Can't find %s in current session\n", sub);
347 fprintf(stderr, "Invalid parameters list in command line\n");
350 fprintf(stderr, "Bad parameter address\n");
353 fprintf(stderr, "%s already exists\n", sub);
356 va_start(ap, def_format);
357 vfprintf(stderr, def_format, ap);
365 lst_free_rpcent(struct list_head *head)
367 lstcon_rpc_ent_t *ent;
369 while (!list_empty(head)) {
370 ent = list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
372 list_del(&ent->rpe_link);
378 lst_reset_rpcent(struct list_head *head)
380 lstcon_rpc_ent_t *ent;
382 list_for_each_entry(ent, head, rpe_link) {
383 ent->rpe_sid = LST_INVALID_SID;
384 ent->rpe_peer.nid = LNET_NID_ANY;
385 ent->rpe_peer.pid = LNET_PID_ANY;
386 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
391 lst_alloc_rpcent(struct list_head *head, int count, int offset)
393 lstcon_rpc_ent_t *ent;
396 for (i = 0; i < count; i++) {
397 ent = malloc(offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
399 lst_free_rpcent(head);
403 memset(ent, 0, offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
405 ent->rpe_sid = LST_INVALID_SID;
406 ent->rpe_peer.nid = LNET_NID_ANY;
407 ent->rpe_peer.pid = LNET_PID_ANY;
408 list_add(&ent->rpe_link, head);
415 lst_print_transerr(struct list_head *head, char *optstr)
417 lstcon_rpc_ent_t *ent;
419 list_for_each_entry(ent, head, rpe_link) {
420 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
423 if (ent->rpe_rpc_errno != 0) {
424 fprintf(stderr, "%s RPC failed on %s: %s\n",
425 optstr, libcfs_id2str(ent->rpe_peer),
426 strerror(ent->rpe_rpc_errno));
430 fprintf(stderr, "%s failed on %s: %s\n",
431 optstr, libcfs_id2str(ent->rpe_peer),
432 strerror(ent->rpe_fwk_errno));
436 int lst_info_batch_ioctl(char *batch, int test, int server,
437 lstcon_test_batch_ent_t *entp, int *idxp,
438 int *ndentp, lstcon_node_ent_t *dentsp);
440 int lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
441 int *idx, int *count, lstcon_node_ent_t *dents);
443 int lst_query_batch_ioctl(char *batch, int test, int server,
444 int timeout, struct list_head *head);
447 lst_ioctl(unsigned int opc, void *buf, int len)
449 struct libcfs_ioctl_data data;
452 LIBCFS_IOC_INIT (data);
453 data.ioc_u32[0] = opc;
454 data.ioc_plen1 = len;
455 data.ioc_pbuf1 = (char *)buf;
456 data.ioc_plen2 = sizeof(trans_stat);
457 data.ioc_pbuf2 = (char *)&trans_stat;
459 memset(&trans_stat, 0, sizeof(trans_stat));
461 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
463 /* local error, no valid RPC result */
468 if (trans_stat.trs_rpc_errno != 0)
471 /* Framework error */
472 if (trans_stat.trs_fwk_errno != 0)
479 lst_new_session_ioctl (char *name, int timeout, int force, lst_sid_t *sid)
481 lstio_session_new_args_t args = {
482 .lstio_ses_key = session_key,
483 .lstio_ses_timeout = timeout,
484 .lstio_ses_force = force,
485 .lstio_ses_idp = sid,
486 .lstio_ses_namep = name,
487 .lstio_ses_nmlen = strlen(name),
490 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
494 jt_lst_new_session(int argc, char **argv)
496 char buf[LST_NAME_SIZE];
504 static struct option session_opts[] =
506 {"timeout", required_argument, 0, 't' },
507 {"force", no_argument, 0, 'f' },
511 if (session_key == 0) {
513 "Can't find env LST_SESSION or value is not valid\n");
519 c = getopt_long(argc, argv, "ft:",
520 session_opts, &optidx);
530 timeout = atoi(optarg);
533 lst_print_usage(argv[0]);
539 fprintf(stderr, "Invalid timeout value\n");
543 if (optind == argc - 1) {
544 name = argv[optind ++];
545 if (strlen(name) >= LST_NAME_SIZE) {
546 fprintf(stderr, "Name size is limited to %d\n",
551 } else if (optind == argc) {
552 char user[LST_NAME_SIZE];
553 char host[LST_NAME_SIZE];
554 struct passwd *pw = getpwuid(getuid());
557 snprintf(user, sizeof(user), "%d", (int)getuid());
559 snprintf(user, sizeof(user), "%s", pw->pw_name);
561 rc = gethostname(host, sizeof(host));
563 snprintf(host, sizeof(host), "unknown_host");
565 snprintf(buf, LST_NAME_SIZE, "%s@%s", user, host);
569 lst_print_usage(argv[0]);
573 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
576 lst_print_error("session", "Failed to create session: %s\n",
581 fprintf(stdout, "SESSION: %s TIMEOUT: %d FORCE: %s\n",
582 name, timeout, force ? "Yes": "No");
588 lst_session_info_ioctl(char *name, int len, int *key,
589 lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
591 lstio_session_info_args_t args = {
592 .lstio_ses_keyp = key,
593 .lstio_ses_idp = sid,
594 .lstio_ses_ndinfo = ndinfo,
595 .lstio_ses_nmlen = len,
596 .lstio_ses_namep = name,
599 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
603 jt_lst_show_session(int argc, char **argv)
605 lstcon_ndlist_ent_t ndinfo;
607 char name[LST_NAME_SIZE];
611 rc = lst_session_info_ioctl(name, LST_NAME_SIZE, &key, &sid, &ndinfo);
614 lst_print_error("session", "Failed to show session: %s\n",
619 fprintf(stdout, "%s ID: %Lu@%s, KEY: %d NODES: %d\n",
620 name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
621 key, ndinfo.nle_nnode);
627 lst_end_session_ioctl(void)
629 lstio_session_end_args_t args = {
630 .lstio_ses_key = session_key,
633 return lst_ioctl (LSTIO_SESSION_END, &args, sizeof(args));
637 jt_lst_end_session(int argc, char **argv)
641 if (session_key == 0) {
643 "Can't find env LST_SESSION or value is not valid\n");
647 rc = lst_end_session_ioctl();
650 fprintf(stdout, "session is ended\n");
655 lst_print_error("session", "Failed to end session: %s\n",
660 if (trans_stat.trs_rpc_errno != 0) {
662 "[RPC] Failed to send %d session RPCs: %s\n",
663 lstcon_rpc_stat_failure(&trans_stat, 0),
664 strerror(trans_stat.trs_rpc_errno));
667 if (trans_stat.trs_fwk_errno != 0) {
669 "[FWK] Failed to end session on %d nodes: %s\n",
670 lstcon_sesop_stat_failure(&trans_stat, 0),
671 strerror(trans_stat.trs_fwk_errno));
678 lst_ping_ioctl(char *str, int type, int timeout,
679 int count, lnet_process_id_t *ids, struct list_head *head)
681 lstio_debug_args_t args = {
682 .lstio_dbg_key = session_key,
683 .lstio_dbg_type = type,
684 .lstio_dbg_flags = 0,
685 .lstio_dbg_timeout = timeout,
686 .lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str),
687 .lstio_dbg_namep = str,
688 .lstio_dbg_count = count,
689 .lstio_dbg_idsp = ids,
690 .lstio_dbg_resultp = head,
693 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
697 lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
699 char buf[LST_NAME_SIZE];
700 lstcon_test_batch_ent_t ent;
701 lstcon_ndlist_ent_t *entp = &ent.tbe_cli_nle;
707 case LST_OPC_SESSION:
708 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
712 case LST_OPC_BATCHSRV:
713 entp = &ent.tbe_srv_nle;
714 case LST_OPC_BATCHCLI:
715 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
719 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
723 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
732 *countp = entp->nle_nnode;
738 jt_lst_ping(int argc, char **argv)
740 struct list_head head;
741 lnet_process_id_t *ids = NULL;
742 lstcon_rpc_ent_t *ent = NULL;
752 static struct option ping_opts[] =
754 {"session", no_argument, 0, 's' },
755 {"server", no_argument, 0, 'v' },
756 {"batch", required_argument, 0, 'b' },
757 {"group", required_argument, 0, 'g' },
758 {"nodes", required_argument, 0, 'n' },
759 {"timeout", required_argument, 0, 't' },
763 if (session_key == 0) {
765 "Can't find env LST_SESSION or value is not valid\n");
771 c = getopt_long(argc, argv, "g:b:n:t:sv",
779 type = LST_OPC_SESSION;
783 type = LST_OPC_GROUP;
788 type = LST_OPC_BATCHCLI;
793 type = LST_OPC_NODES;
798 timeout = atoi(optarg);
806 lst_print_usage(argv[0]);
811 if (type == 0 || timeout <= 0 || optind != argc) {
812 lst_print_usage(argv[0]);
816 if (type == LST_OPC_BATCHCLI && server)
817 type = LST_OPC_BATCHSRV;
819 rc = lst_get_node_count(type, str, &count, &ids);
821 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
822 (str == NULL) ? "session" : str, strerror(errno));
826 CFS_INIT_LIST_HEAD(&head);
828 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
830 fprintf(stderr, "Out of memory\n");
835 fprintf(stdout, "Target %s is empty\n",
836 (str == NULL) ? "session" : str);
840 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
841 if (rc == -1) { /* local failure */
842 lst_print_error("debug", "Failed to ping %s: %s\n",
843 (str == NULL) ? "session" : str,
849 /* ignore RPC errors and framwork errors */
850 list_for_each_entry(ent, &head, rpe_link) {
851 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
852 libcfs_id2str(ent->rpe_peer),
853 lst_node_state2str(ent->rpe_state),
854 (ent->rpe_state == LST_NODE_ACTIVE ||
855 ent->rpe_state == LST_NODE_BUSY)?
856 (ent->rpe_rpc_errno == 0 ?
857 &ent->rpe_payload[0] : "Unknown") :
858 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
862 lst_free_rpcent(&head);
872 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
873 struct list_head *resultp)
875 lstio_group_nodes_args_t args = {
876 .lstio_grp_key = session_key,
877 .lstio_grp_nmlen = strlen(name),
878 .lstio_grp_namep = name,
879 .lstio_grp_count = count,
880 .lstio_grp_idsp = ids,
881 .lstio_grp_resultp = resultp,
884 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
888 lst_add_group_ioctl (char *name)
890 lstio_group_add_args_t args = {
891 .lstio_grp_key = session_key,
892 .lstio_grp_nmlen = strlen(name),
893 .lstio_grp_namep = name,
896 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
900 jt_lst_add_group(int argc, char **argv)
902 struct list_head head;
903 lnet_process_id_t *ids;
909 if (session_key == 0) {
911 "Can't find env LST_SESSION or value is not valid\n");
916 lst_print_usage(argv[0]);
921 if (strlen(name) >= LST_NAME_SIZE) {
922 fprintf(stderr, "Name length is limited to %d\n",
927 rc = lst_add_group_ioctl(name);
929 lst_print_error("group", "Failed to add group %s: %s\n",
930 name, strerror(errno));
934 CFS_INIT_LIST_HEAD(&head);
936 for (i = 2; i < argc; i++) {
937 /* parse address list */
938 rc = lst_parse_nids(argv[i], &count, &ids);
940 fprintf(stderr, "Ignore invalid id list %s\n",
948 rc = lst_alloc_rpcent(&head, count, 0);
950 fprintf(stderr, "Out of memory\n");
954 rc = lst_add_nodes_ioctl(name, count, ids, &head);
959 lst_free_rpcent(&head);
960 fprintf(stderr, "%s are added to session\n", argv[i]);
965 lst_free_rpcent(&head);
966 lst_print_error("group", "Failed to add nodes %s: %s\n",
967 argv[i], strerror(errno));
971 lst_print_transerr(&head, "create session");
972 lst_free_rpcent(&head);
979 lst_del_group_ioctl (char *name)
981 lstio_group_del_args_t args = {
982 .lstio_grp_key = session_key,
983 .lstio_grp_nmlen = strlen(name),
984 .lstio_grp_namep = name,
987 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
991 jt_lst_del_group(int argc, char **argv)
995 if (session_key == 0) {
997 "Can't find env LST_SESSION or value is not valid\n");
1002 lst_print_usage(argv[0]);
1006 rc = lst_del_group_ioctl(argv[1]);
1008 fprintf(stdout, "Group is deleted\n");
1013 lst_print_error("group", "Failed to delete group: %s\n",
1018 fprintf(stderr, "Group is deleted with some errors\n");
1020 if (trans_stat.trs_rpc_errno != 0) {
1021 fprintf(stderr, "[RPC] Failed to send %d end session RPCs: %s\n",
1022 lstcon_rpc_stat_failure(&trans_stat, 0),
1023 strerror(trans_stat.trs_rpc_errno));
1026 if (trans_stat.trs_fwk_errno != 0) {
1028 "[FWK] Failed to end session on %d nodes: %s\n",
1029 lstcon_sesop_stat_failure(&trans_stat, 0),
1030 strerror(trans_stat.trs_fwk_errno));
1037 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1038 lnet_process_id_t *ids, struct list_head *resultp)
1040 lstio_group_update_args_t args = {
1041 .lstio_grp_key = session_key,
1042 .lstio_grp_opc = opc,
1043 .lstio_grp_args = clean,
1044 .lstio_grp_nmlen = strlen(name),
1045 .lstio_grp_namep = name,
1046 .lstio_grp_count = count,
1047 .lstio_grp_idsp = ids,
1048 .lstio_grp_resultp = resultp,
1051 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1055 jt_lst_update_group(int argc, char **argv)
1057 struct list_head head;
1058 lnet_process_id_t *ids = NULL;
1068 static struct option update_group_opts[] =
1070 {"refresh", no_argument, 0, 'f' },
1071 {"clean", required_argument, 0, 'c' },
1072 {"remove", required_argument, 0, 'r' },
1076 if (session_key == 0) {
1078 "Can't find env LST_SESSION or value is not valid\n");
1083 c = getopt_long(argc, argv, "fc:r:",
1084 update_group_opts, &optidx);
1086 /* Detect the end of the options. */
1093 lst_print_usage(argv[0]);
1096 opc = LST_GROUP_REFRESH;
1101 lst_print_usage(argv[0]);
1104 opc = LST_GROUP_RMND;
1109 clean = lst_node_str2state(optarg);
1110 if (opc != 0 || clean <= 0) {
1111 lst_print_usage(argv[0]);
1114 opc = LST_GROUP_CLEAN;
1118 lst_print_usage(argv[0]);
1123 /* no OPC or group is specified */
1124 if (opc == 0 || optind != argc - 1) {
1125 lst_print_usage(argv[0]);
1131 CFS_INIT_LIST_HEAD(&head);
1133 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1134 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1136 opc == LST_GROUP_RMND ? str : grp,
1140 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1141 opc == LST_GROUP_RMND ? str : grp,
1146 rc = lst_alloc_rpcent(&head, count, 0);
1148 fprintf(stderr, "Out of memory\n");
1155 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1161 lst_free_rpcent(&head);
1166 lst_free_rpcent(&head);
1167 lst_print_error("group", "Failed to update group: %s\n",
1172 lst_print_transerr(&head, "Updating group");
1174 lst_free_rpcent(&head);
1180 lst_list_group_ioctl(int len, char *name, int idx)
1182 lstio_group_list_args_t args = {
1183 .lstio_grp_key = session_key,
1184 .lstio_grp_idx = idx,
1185 .lstio_grp_nmlen = len,
1186 .lstio_grp_namep = name,
1189 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1193 lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
1194 int *idx, int *count, lstcon_node_ent_t *dents)
1196 lstio_group_info_args_t args = {
1197 .lstio_grp_key = session_key,
1198 .lstio_grp_nmlen = strlen(name),
1199 .lstio_grp_namep = name,
1200 .lstio_grp_entp = gent,
1201 .lstio_grp_idxp = idx,
1202 .lstio_grp_ndentp = count,
1203 .lstio_grp_dentsp = dents,
1206 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1210 lst_list_group_all(void)
1212 char name[LST_NAME_SIZE];
1216 /* no group is specified, list name of all groups */
1217 for (i = 0; ; i++) {
1218 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1220 fprintf(stdout, "%d) %s\n", i + 1, name);
1224 if (errno == ENOENT)
1227 lst_print_error("group", "Failed to list group: %s\n",
1232 fprintf(stdout, "Total %d groups\n", i);
1237 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1240 jt_lst_list_group(int argc, char **argv)
1242 lstcon_ndlist_ent_t gent;
1243 lstcon_node_ent_t *dents;
1258 static struct option list_group_opts[] =
1260 {"active", no_argument, 0, 'a' },
1261 {"busy", no_argument, 0, 'b' },
1262 {"down", no_argument, 0, 'd' },
1263 {"unknown", no_argument, 0, 'u' },
1264 {"all", no_argument, 0, 'l' },
1268 if (session_key == 0) {
1270 "Can't find env LST_SESSION or value is not valid\n");
1275 c = getopt_long(argc, argv, "abdul",
1276 list_group_opts, &optidx);
1283 verbose = active = 1;
1295 verbose = unknown = 1;
1302 lst_print_usage(argv[0]);
1307 if (optind == argc) {
1308 /* no group is specified, list name of all groups */
1309 rc = lst_list_group_all();
1315 fprintf(stdout, LST_NODES_TITLE);
1317 /* list nodes in specified groups */
1318 for (i = optind; i < argc; i++) {
1319 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1321 if (errno == ENOENT) {
1326 lst_print_error("group", "Failed to list group\n",
1332 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1333 gent.nle_nactive, gent.nle_nbusy,
1334 gent.nle_ndown, gent.nle_nunknown,
1335 gent.nle_nnode, argv[i]);
1339 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1341 if (gent.nle_nnode == 0) {
1342 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1346 count = gent.nle_nnode;
1348 dents = malloc(count * sizeof(lstcon_node_ent_t));
1349 if (dents == NULL) {
1350 fprintf(stderr, "Failed to malloc: %s\n",
1356 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1358 lst_print_error("group", "Failed to list group: %s\n",
1364 for (j = 0, c = 0; j < count; j++) {
1366 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1367 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1368 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1369 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1371 fprintf(stdout, "\t%s: %s\n",
1372 libcfs_id2str(dents[j].nde_id),
1373 lst_node_state2str(dents[j].nde_state));
1378 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1387 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
1388 int timeout, struct list_head *resultp)
1390 lstio_stat_args_t args = {
1391 .lstio_sta_key = session_key,
1392 .lstio_sta_timeout = timeout,
1393 .lstio_sta_nmlen = strlen(name),
1394 .lstio_sta_namep = name,
1395 .lstio_sta_count = count,
1396 .lstio_sta_idsp = idsp,
1397 .lstio_sta_resultp = resultp,
1400 return lst_ioctl (LSTIO_STAT_QUERY, &args, sizeof(args));
1404 struct list_head srp_link;
1407 lnet_process_id_t *srp_ids;
1408 struct list_head srp_result[2];
1409 } lst_stat_req_param_t;
1412 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1416 for (i = 0; i < 2; i++)
1417 lst_free_rpcent(&srp->srp_result[i]);
1419 if (srp->srp_ids != NULL)
1426 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
1428 lst_stat_req_param_t *srp = NULL;
1429 int count = save_old ? 2 : 1;
1433 srp = malloc(sizeof(*srp));
1437 memset(srp, 0, sizeof(*srp));
1438 CFS_INIT_LIST_HEAD(&srp->srp_result[0]);
1439 CFS_INIT_LIST_HEAD(&srp->srp_result[1]);
1441 rc = lst_get_node_count(LST_OPC_GROUP, name,
1442 &srp->srp_count, NULL);
1443 if (rc != 0 && errno == ENOENT) {
1444 rc = lst_get_node_count(LST_OPC_NODES, name,
1445 &srp->srp_count, &srp->srp_ids);
1450 "Failed to get count of nodes from %s: %s\n",
1451 name, strerror(errno));
1452 lst_stat_req_param_free(srp);
1457 srp->srp_name = name;
1459 for (i = 0; i < count; i++) {
1460 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1461 sizeof(sfw_counters_t) +
1462 sizeof(srpc_counters_t) +
1463 sizeof(lnet_counters_t));
1465 fprintf(stderr, "Out of memory\n");
1475 lst_stat_req_param_free(srp);
1482 } lst_srpc_stat_result;
1484 #define LST_LNET_AVG 0
1485 #define LST_LNET_MIN 1
1486 #define LST_LNET_MAX 2
1489 float lnet_avg_sndrate;
1490 float lnet_min_sndrate;
1491 float lnet_max_sndrate;
1492 float lnet_total_sndrate;
1494 float lnet_avg_rcvrate;
1495 float lnet_min_rcvrate;
1496 float lnet_max_rcvrate;
1497 float lnet_total_rcvrate;
1499 float lnet_avg_sndperf;
1500 float lnet_min_sndperf;
1501 float lnet_max_sndperf;
1502 float lnet_total_sndperf;
1504 float lnet_avg_rcvperf;
1505 float lnet_min_rcvperf;
1506 float lnet_max_rcvperf;
1507 float lnet_total_rcvperf;
1509 int lnet_stat_count;
1510 } lst_lnet_stat_result_t;
1512 lst_lnet_stat_result_t lnet_stat_result;
1515 lst_lnet_stat_value(int bw, int send, int off)
1519 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1520 &lnet_stat_result.lnet_avg_sndrate;
1531 lst_timeval_diff(struct timeval *tv1,
1532 struct timeval *tv2, struct timeval *df)
1534 if (tv1->tv_usec >= tv2->tv_usec) {
1535 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1536 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1540 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1541 df->tv_usec = tv1->tv_sec + 1000000 - tv2->tv_usec;
1547 lst_cal_lnet_stat(float delta, lnet_counters_t *lnet_new,
1548 lnet_counters_t *lnet_old)
1553 perf = (float)(lnet_new->send_length -
1554 lnet_old->send_length) / (1024 * 1024) / delta;
1555 lnet_stat_result.lnet_total_sndperf += perf;
1557 if (lnet_stat_result.lnet_min_sndperf > perf ||
1558 lnet_stat_result.lnet_min_sndperf == 0)
1559 lnet_stat_result.lnet_min_sndperf = perf;
1561 if (lnet_stat_result.lnet_max_sndperf < perf)
1562 lnet_stat_result.lnet_max_sndperf = perf;
1564 perf = (float)(lnet_new->recv_length -
1565 lnet_old->recv_length) / (1024 * 1024) / delta;
1566 lnet_stat_result.lnet_total_rcvperf += perf;
1568 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1569 lnet_stat_result.lnet_min_rcvperf == 0)
1570 lnet_stat_result.lnet_min_rcvperf = perf;
1572 if (lnet_stat_result.lnet_max_rcvperf < perf)
1573 lnet_stat_result.lnet_max_rcvperf = perf;
1575 rate = (lnet_new->send_count - lnet_old->send_count) / delta;
1576 lnet_stat_result.lnet_total_sndrate += rate;
1578 if (lnet_stat_result.lnet_min_sndrate > rate ||
1579 lnet_stat_result.lnet_min_sndrate == 0)
1580 lnet_stat_result.lnet_min_sndrate = rate;
1582 if (lnet_stat_result.lnet_max_sndrate < rate)
1583 lnet_stat_result.lnet_max_sndrate = rate;
1585 rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
1586 lnet_stat_result.lnet_total_rcvrate += rate;
1588 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1589 lnet_stat_result.lnet_min_rcvrate == 0)
1590 lnet_stat_result.lnet_min_rcvrate = rate;
1592 if (lnet_stat_result.lnet_max_rcvrate < rate)
1593 lnet_stat_result.lnet_max_rcvrate = rate;
1595 lnet_stat_result.lnet_stat_count ++;
1597 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1598 lnet_stat_result.lnet_stat_count;
1599 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1600 lnet_stat_result.lnet_stat_count;
1602 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1603 lnet_stat_result.lnet_stat_count;
1604 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1605 lnet_stat_result.lnet_stat_count;
1610 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
1619 if (lnet_stat_result.lnet_stat_count == 0)
1622 if (bwrt == 1) /* bw only */
1625 if (bwrt == 2) /* rates only */
1628 if (rdwr == 1) /* recv only */
1631 if (rdwr == 2) /* send only */
1634 for (i = start1; i <= end1; i++) {
1635 fprintf(stdout, "[LNet %s of %s]\n",
1636 i == 0 ? "Rates" : "Bandwidth", name);
1638 for (j = start2; j <= end2; j++) {
1639 fprintf(stdout, "[%c] ", j == 0 ? 'W' : 'R');
1641 if ((type & 1) != 0) {
1642 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1643 "Avg: %-8.2f MB/s ",
1644 lst_lnet_stat_value(i, j, 0));
1647 if ((type & 2) != 0) {
1648 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1649 "Min: %-8.2f MB/s ",
1650 lst_lnet_stat_value(i, j, 1));
1653 if ((type & 4) != 0) {
1654 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1656 lst_lnet_stat_value(i, j, 2));
1659 fprintf(stdout, "\n");
1665 lst_print_stat(char *name, struct list_head *resultp,
1666 int idx, int lnet, int bwrt, int rdwr, int type)
1668 struct list_head tmp[2];
1669 lstcon_rpc_ent_t *new;
1670 lstcon_rpc_ent_t *old;
1671 sfw_counters_t *sfwk_new;
1672 sfw_counters_t *sfwk_old;
1673 srpc_counters_t *srpc_new;
1674 srpc_counters_t *srpc_old;
1675 lnet_counters_t *lnet_new;
1676 lnet_counters_t *lnet_old;
1681 CFS_INIT_LIST_HEAD(&tmp[0]);
1682 CFS_INIT_LIST_HEAD(&tmp[1]);
1684 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1686 while (!list_empty(&resultp[idx])) {
1687 if (list_empty(&resultp[1 - idx])) {
1688 fprintf(stderr, "Group is changed, re-run stat\n");
1692 new = list_entry(resultp[idx].next, lstcon_rpc_ent_t, rpe_link);
1693 old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t, rpe_link);
1695 /* first time get stats result, can't calculate diff */
1696 if (new->rpe_peer.nid == LNET_NID_ANY)
1699 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1700 new->rpe_peer.pid != old->rpe_peer.pid) {
1701 /* Something wrong. i.e, somebody change the group */
1705 list_del(&new->rpe_link);
1706 list_add_tail(&new->rpe_link, &tmp[idx]);
1708 list_del(&old->rpe_link);
1709 list_add_tail(&old->rpe_link, &tmp[1 - idx]);
1711 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1712 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1717 sfwk_new = (sfw_counters_t *)&new->rpe_payload[0];
1718 sfwk_old = (sfw_counters_t *)&old->rpe_payload[0];
1720 srpc_new = (srpc_counters_t *)((char *)sfwk_new + sizeof(*sfwk_new));
1721 srpc_old = (srpc_counters_t *)((char *)sfwk_old + sizeof(*sfwk_old));
1723 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
1724 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
1726 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1728 delta = tv.tv_sec + (float)tv.tv_usec/1000000;
1730 if (!lnet) /* TODO */
1733 lst_cal_lnet_stat(delta, lnet_new, lnet_old);
1736 list_splice(&tmp[idx], &resultp[idx]);
1737 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1740 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1742 if (!lnet) /* TODO */
1745 lst_print_lnet_stat(name, bwrt, rdwr, type);
1749 jt_lst_stat(int argc, char **argv)
1751 struct list_head head;
1752 lst_stat_req_param_t *srp;
1755 int timeout = 5; /* default timeout, 5 sec */
1756 int delay = 5; /* default delay, 5 sec */
1757 int lnet = 1; /* lnet stat by default */
1765 static struct option stat_opts[] =
1767 {"timeout", required_argument, 0, 't' },
1768 {"delay" , required_argument, 0, 'd' },
1769 {"lnet" , no_argument, 0, 'l' },
1770 {"rpc" , no_argument, 0, 'c' },
1771 {"bw" , no_argument, 0, 'b' },
1772 {"rate" , no_argument, 0, 'a' },
1773 {"read" , no_argument, 0, 'r' },
1774 {"write" , no_argument, 0, 'w' },
1775 {"avg" , no_argument, 0, 'g' },
1776 {"min" , no_argument, 0, 'n' },
1777 {"max" , no_argument, 0, 'x' },
1781 if (session_key == 0) {
1783 "Can't find env LST_SESSION or value is not valid\n");
1788 c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
1795 timeout = atoi(optarg);
1798 delay = atoi(optarg);
1840 lst_print_usage(argv[0]);
1845 if (optind == argc) {
1846 lst_print_usage(argv[0]);
1850 if (timeout <= 0 || delay <= 0) {
1851 fprintf(stderr, "Invalid timeout or delay value\n");
1855 CFS_INIT_LIST_HEAD(&head);
1857 while (optind < argc) {
1858 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
1862 list_add_tail(&srp->srp_link, &head);
1866 time_t now = time(NULL);
1868 if (now - last < delay) {
1869 sleep(delay - now + last);
1875 list_for_each_entry(srp, &head, srp_link) {
1876 rc = lst_stat_ioctl(srp->srp_name,
1877 srp->srp_count, srp->srp_ids,
1878 timeout, &srp->srp_result[idx]);
1880 lst_print_error("stat", "Failed to stat %s: %s\n",
1881 srp->srp_name, strerror(errno));
1885 lst_print_stat(srp->srp_name, srp->srp_result,
1886 idx, lnet, bwrt, rdwr, type);
1888 lst_reset_rpcent(&srp->srp_result[1 - idx]);
1895 while (!list_empty(&head)) {
1896 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
1898 list_del(&srp->srp_link);
1899 lst_stat_req_param_free(srp);
1906 jt_lst_show_error(int argc, char **argv)
1908 struct list_head head;
1909 lst_stat_req_param_t *srp;
1910 lstcon_rpc_ent_t *ent;
1911 sfw_counters_t *sfwk;
1912 srpc_counters_t *srpc;
1913 lnet_counters_t *lnet;
1920 static struct option show_error_opts[] =
1922 {"session", no_argument, 0, 's' },
1926 if (session_key == 0) {
1928 "Can't find env LST_SESSION or value is not valid\n");
1933 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
1944 lst_print_usage(argv[0]);
1949 if (optind == argc) {
1950 lst_print_usage(argv[0]);
1954 CFS_INIT_LIST_HEAD(&head);
1956 while (optind < argc) {
1957 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
1961 list_add_tail(&srp->srp_link, &head);
1964 list_for_each_entry(srp, &head, srp_link) {
1965 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
1966 srp->srp_ids, 5, &srp->srp_result[0]);
1969 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
1970 srp->srp_name, strerror(errno));
1974 fprintf(stdout, "%s:\n", srp->srp_name);
1978 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
1979 if (ent->rpe_rpc_errno != 0) {
1981 fprintf(stderr, "RPC failure, can't show error on %s\n",
1982 libcfs_id2str(ent->rpe_peer));
1986 if (ent->rpe_fwk_errno != 0) {
1988 fprintf(stderr, "Framework failure, can't show error on %s\n",
1989 libcfs_id2str(ent->rpe_peer));
1993 sfwk = (sfw_counters_t *)&ent->rpe_payload[0];
1994 srpc = (srpc_counters_t *)((char *)sfwk + sizeof(*sfwk));
1995 lnet = (lnet_counters_t *)((char *)srpc + sizeof(*srpc));
1997 if (srpc->errors == 0 &&
1998 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2002 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2007 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2008 libcfs_id2str(ent->rpe_peer),
2009 sfwk->brw_errors, sfwk->ping_errors,
2010 show_rpc ? ' ' : '\n');
2015 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2016 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2019 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2022 while (!list_empty(&head)) {
2023 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2025 list_del(&srp->srp_link);
2026 lst_stat_req_param_free(srp);
2033 lst_add_batch_ioctl (char *name)
2035 lstio_batch_add_args_t args = {
2036 .lstio_bat_key = session_key,
2037 .lstio_bat_nmlen = strlen(name),
2038 .lstio_bat_namep = name,
2041 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2045 jt_lst_add_batch(int argc, char **argv)
2050 if (session_key == 0) {
2052 "Can't find env LST_SESSION or value is not valid\n");
2057 lst_print_usage(argv[0]);
2062 if (strlen(name) >= LST_NAME_SIZE) {
2063 fprintf(stderr, "Name length is limited to %d\n",
2068 rc = lst_add_batch_ioctl(name);
2072 lst_print_error("batch", "Failed to create batch: %s\n",
2079 lst_start_batch_ioctl (char *name, int timeout, struct list_head *resultp)
2081 lstio_batch_run_args_t args = {
2082 .lstio_bat_key = session_key,
2083 .lstio_bat_timeout = timeout,
2084 .lstio_bat_nmlen = strlen(name),
2085 .lstio_bat_namep = name,
2086 .lstio_bat_resultp = resultp,
2089 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2093 jt_lst_start_batch(int argc, char **argv)
2095 struct list_head head;
2103 static struct option start_batch_opts[] =
2105 {"timeout", required_argument, 0, 't' },
2109 if (session_key == 0) {
2111 "Can't find env LST_SESSION or value is not valid\n");
2116 c = getopt_long(argc, argv, "t:",
2117 start_batch_opts, &optidx);
2119 /* Detect the end of the options. */
2125 timeout = atoi(optarg);
2128 lst_print_usage(argv[0]);
2133 if (optind == argc) {
2134 batch = LST_DEFAULT_BATCH;
2136 } else if (optind == argc - 1) {
2137 batch = argv[optind];
2140 lst_print_usage(argv[0]);
2144 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2146 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2147 batch, strerror(errno));
2151 CFS_INIT_LIST_HEAD(&head);
2153 rc = lst_alloc_rpcent(&head, count, 0);
2155 fprintf(stderr, "Out of memory\n");
2159 rc = lst_start_batch_ioctl(batch, timeout, &head);
2162 fprintf(stdout, "%s is running now\n", batch);
2163 lst_free_rpcent(&head);
2168 lst_print_error("batch", "Failed to start batch: %s\n",
2170 lst_free_rpcent(&head);
2174 lst_print_transerr(&head, "Run batch");
2176 lst_free_rpcent(&head);
2182 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2184 lstio_batch_stop_args_t args = {
2185 .lstio_bat_key = session_key,
2186 .lstio_bat_force = force,
2187 .lstio_bat_nmlen = strlen(name),
2188 .lstio_bat_namep = name,
2189 .lstio_bat_resultp = resultp,
2192 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2196 jt_lst_stop_batch(int argc, char **argv)
2198 struct list_head head;
2206 static struct option stop_batch_opts[] =
2208 {"force", no_argument, 0, 'f' },
2212 if (session_key == 0) {
2214 "Can't find env LST_SESSION or value is not valid\n");
2219 c = getopt_long(argc, argv, "f",
2220 stop_batch_opts, &optidx);
2222 /* Detect the end of the options. */
2231 lst_print_usage(argv[0]);
2236 if (optind == argc) {
2237 batch = LST_DEFAULT_BATCH;
2239 } else if (optind == argc - 1) {
2240 batch = argv[optind];
2243 lst_print_usage(argv[0]);
2247 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2249 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2250 batch, strerror(errno));
2254 CFS_INIT_LIST_HEAD(&head);
2256 rc = lst_alloc_rpcent(&head, count, 0);
2258 fprintf(stderr, "Out of memory\n");
2262 rc = lst_stop_batch_ioctl(batch, force, &head);
2267 lst_reset_rpcent(&head);
2269 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2273 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2274 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2277 fprintf(stdout, "%d batch in stopping\n",
2278 lstcon_tsbqry_stat_run(&trans_stat, 0));
2282 fprintf(stdout, "Batch is stopped\n");
2283 lst_free_rpcent(&head);
2288 lst_print_error("batch", "Failed to stop batch: %s\n",
2290 lst_free_rpcent(&head);
2294 lst_print_transerr(&head, "stop batch");
2296 lst_free_rpcent(&head);
2302 lst_list_batch_ioctl(int len, char *name, int index)
2304 lstio_batch_list_args_t args = {
2305 .lstio_bat_key = session_key,
2306 .lstio_bat_idx = index,
2307 .lstio_bat_nmlen = len,
2308 .lstio_bat_namep = name,
2311 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2315 lst_info_batch_ioctl(char *batch, int test, int server,
2316 lstcon_test_batch_ent_t *entp, int *idxp,
2317 int *ndentp, lstcon_node_ent_t *dentsp)
2319 lstio_batch_info_args_t args = {
2320 .lstio_bat_key = session_key,
2321 .lstio_bat_nmlen = strlen(batch),
2322 .lstio_bat_namep = batch,
2323 .lstio_bat_server = server,
2324 .lstio_bat_testidx = test,
2325 .lstio_bat_entp = entp,
2326 .lstio_bat_idxp = idxp,
2327 .lstio_bat_ndentp = ndentp,
2328 .lstio_bat_dentsp = dentsp,
2331 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2335 lst_list_batch_all(void)
2337 char name[LST_NAME_SIZE];
2341 for (i = 0; ; i++) {
2342 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2344 fprintf(stdout, "%d) %s\n", i + 1, name);
2348 if (errno == ENOENT)
2351 lst_print_error("batch", "Failed to list batch: %s\n",
2356 fprintf(stdout, "Total %d batches\n", i);
2362 lst_list_tsb_nodes(char *batch, int test, int server,
2363 int count, int active, int invalid)
2365 lstcon_node_ent_t *dents;
2374 /* verbose list, show nodes in batch or test */
2375 dents = malloc(count * sizeof(lstcon_node_ent_t));
2376 if (dents == NULL) {
2377 fprintf(stdout, "Can't allocate memory\n");
2381 rc = lst_info_batch_ioctl(batch, test, server,
2382 NULL, &index, &count, dents);
2385 lst_print_error((test > 0) ? "test" : "batch",
2386 (test > 0) ? "Failed to query test: %s\n" :
2387 "Failed to query batch: %s\n",
2392 for (i = 0, c = 0; i < count; i++) {
2393 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2394 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2395 dents[i].nde_state == LST_NODE_DOWN ||
2396 dents[i].nde_state == LST_NODE_UNKNOWN)))
2399 fprintf(stdout, "\t%s: %s\n",
2400 libcfs_id2str(dents[i].nde_id),
2401 lst_node_state2str(dents[i].nde_state));
2405 fprintf(stdout, "Total %d nodes\n", c);
2412 jt_lst_list_batch(int argc, char **argv)
2414 lstcon_test_batch_ent_t ent;
2417 int verbose = 0; /* list nodes in batch or test */
2426 static struct option list_batch_opts[] =
2428 {"test", required_argument, 0, 't' },
2429 {"invalid", no_argument, 0, 'i' },
2430 {"active", no_argument, 0, 'a' },
2431 {"all", no_argument, 0, 'l' },
2432 {"server", no_argument, 0, 's' },
2436 if (session_key == 0) {
2438 "Can't find env LST_SESSION or value is not valid\n");
2443 c = getopt_long(argc, argv, "ailst:",
2444 list_batch_opts, &optidx);
2451 verbose = active = 1;
2454 verbose = invalid = 1;
2457 verbose = active = invalid = 1;
2463 test = atoi(optarg);
2467 lst_print_usage(argv[0]);
2472 if (optind == argc) {
2473 /* list all batches */
2474 rc = lst_list_batch_all();
2478 if (ntest == 1 && test <= 0) {
2479 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2483 if (optind != argc - 1) {
2484 lst_print_usage(argv[0]);
2488 batch = argv[optind];
2491 /* show detail of specified batch or test */
2492 rc = lst_info_batch_ioctl(batch, test, server,
2493 &ent, NULL, NULL, NULL);
2495 lst_print_error((test > 0) ? "test" : "batch",
2496 (test > 0) ? "Failed to query test: %s\n" :
2497 "Failed to query batch: %s\n",
2503 /* list nodes in test or batch */
2504 rc = lst_list_tsb_nodes(batch, test, server,
2505 server ? ent.tbe_srv_nle.nle_nnode :
2506 ent.tbe_cli_nle.nle_nnode,
2511 /* only show number of hosts in batch or test */
2513 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2514 batch, ent.u.tbe_batch.bae_ntest,
2515 ent.u.tbe_batch.bae_state);
2516 ntest = ent.u.tbe_batch.bae_ntest;
2517 test = 1; /* starting from test 1 */
2521 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2522 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2523 ent.u.tbe_test.tse_loop,
2524 ent.u.tbe_test.tse_concur);
2529 fprintf(stdout, LST_NODES_TITLE);
2530 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2531 "server\t%d\t%d\t%d\t%d\t%d\n",
2532 ent.tbe_cli_nle.nle_nactive,
2533 ent.tbe_cli_nle.nle_nbusy,
2534 ent.tbe_cli_nle.nle_ndown,
2535 ent.tbe_cli_nle.nle_nunknown,
2536 ent.tbe_cli_nle.nle_nnode,
2537 ent.tbe_srv_nle.nle_nactive,
2538 ent.tbe_srv_nle.nle_nbusy,
2539 ent.tbe_srv_nle.nle_ndown,
2540 ent.tbe_srv_nle.nle_nunknown,
2541 ent.tbe_srv_nle.nle_nnode);
2550 lst_query_batch_ioctl(char *batch, int test, int server,
2551 int timeout, struct list_head *head)
2553 lstio_batch_query_args_t args = {
2554 .lstio_bat_key = session_key,
2555 .lstio_bat_testidx = test,
2556 .lstio_bat_client = !(server),
2557 .lstio_bat_timeout = timeout,
2558 .lstio_bat_nmlen = strlen(batch),
2559 .lstio_bat_namep = batch,
2560 .lstio_bat_resultp = head,
2563 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2567 lst_print_tsb_verbose(struct list_head *head,
2568 int active, int idle, int error)
2570 lstcon_rpc_ent_t *ent;
2572 list_for_each_entry(ent, head, rpe_link) {
2573 if (ent->rpe_priv[0] == 0 && active)
2576 if (ent->rpe_priv[0] != 0 && idle)
2579 if (ent->rpe_fwk_errno == 0 && error)
2582 fprintf(stdout, "%s [%s]: %s\n",
2583 libcfs_id2str(ent->rpe_peer),
2584 lst_node_state2str(ent->rpe_state),
2585 ent->rpe_rpc_errno != 0 ?
2586 strerror(ent->rpe_rpc_errno) :
2587 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2592 jt_lst_query_batch(int argc, char **argv)
2594 lstcon_test_batch_ent_t ent;
2595 struct list_head head;
2601 int timeout = 5; /* default 5 seconds */
2602 int delay = 5; /* default 5 seconds */
2603 int loop = 1; /* default 1 loop */
2613 static struct option query_batch_opts[] =
2615 {"timeout", required_argument, 0, 'o' },
2616 {"delay", required_argument, 0, 'd' },
2617 {"loop", required_argument, 0, 'c' },
2618 {"test", required_argument, 0, 't' },
2619 {"server", no_argument, 0, 's' },
2620 {"active", no_argument, 0, 'a' },
2621 {"idle", no_argument, 0, 'i' },
2622 {"error", no_argument, 0, 'e' },
2623 {"all", no_argument, 0, 'l' },
2627 if (session_key == 0) {
2629 "Can't find env LST_SESSION or value is not valid\n");
2634 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2635 query_batch_opts, &optidx);
2637 /* Detect the end of the options. */
2643 timeout = atoi(optarg);
2646 delay = atoi(optarg);
2649 loop = atoi(optarg);
2652 test = atoi(optarg);
2658 active = verbose = 1;
2664 error = verbose = 1;
2670 lst_print_usage(argv[0]);
2675 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2676 lst_print_usage(argv[0]);
2680 if (optind == argc) {
2681 batch = LST_DEFAULT_BATCH;
2683 } else if (optind == argc - 1) {
2684 batch = argv[optind];
2687 lst_print_usage(argv[0]);
2692 CFS_INIT_LIST_HEAD(&head);
2695 rc = lst_info_batch_ioctl(batch, test, server,
2696 &ent, NULL, NULL, NULL);
2698 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2699 batch, test, strerror(errno));
2703 count = server ? ent.tbe_srv_nle.nle_nnode :
2704 ent.tbe_cli_nle.nle_nnode;
2706 fprintf(stdout, "Batch or test is empty\n");
2711 rc = lst_alloc_rpcent(&head, count, 0);
2713 fprintf(stderr, "Out of memory\n");
2717 for (i = 0; i < loop; i++) {
2718 time_t now = time(NULL);
2720 if (now - last < delay) {
2721 sleep(delay - now + last);
2727 rc = lst_query_batch_ioctl(batch, test,
2728 server, timeout, &head);
2730 fprintf(stderr, "Failed to query batch: %s\n",
2737 lst_print_tsb_verbose(&head, active, idle, error);
2741 fprintf(stdout, "%s [%d] ", batch, test);
2743 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2744 fprintf(stdout, "%d of %d nodes are unknown, ",
2745 lstcon_rpc_stat_failure(&trans_stat, 0),
2746 lstcon_rpc_stat_total(&trans_stat, 0));
2749 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2750 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2751 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2752 fprintf(stdout, "is stopped\n");
2756 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2757 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2758 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2759 fprintf(stdout, "is running\n");
2763 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2764 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2765 lstcon_tsbqry_stat_run(&trans_stat, 0),
2766 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2769 lst_free_rpcent(&head);
2775 lst_parse_distribute(char *dstr, int *dist, int *span)
2781 dstr = strchr(dstr, ':');
2785 *span = atoi(dstr + 1);
2793 lst_get_bulk_param(int argc, char **argv, lst_test_bulk_param_t *bulk)
2800 bulk->blk_size = 4096;
2801 bulk->blk_opc = LST_BRW_READ;
2802 bulk->blk_flags = LST_BRW_CHECK_NONE;
2805 if (strcasestr(argv[i], "check=") == argv[i] ||
2806 strcasestr(argv[i], "c=") == argv[i]) {
2807 tok = strchr(argv[i], '=') + 1;
2809 if (strcasecmp(tok, "full") == 0) {
2810 bulk->blk_flags = LST_BRW_CHECK_FULL;
2811 } else if (strcasecmp(tok, "simple") == 0) {
2812 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2814 fprintf(stderr, "Unknow flag %s\n", tok);
2818 } else if (strcasestr(argv[i], "size=") == argv[i] ||
2819 strcasestr(argv[i], "s=") == argv[i]) {
2820 tok = strchr(argv[i], '=') + 1;
2822 bulk->blk_size = strtol(tok, &end, 0);
2823 if (bulk->blk_size <= 0) {
2824 fprintf(stderr, "Invalid size %s\n", tok);
2831 if (*end == 'k' || *end == 'K')
2832 bulk->blk_size *= 1024;
2833 else if (*end == 'm' || *end == 'M')
2834 bulk->blk_size *= 1024 * 1024;
2836 if (bulk->blk_size > CFS_PAGE_SIZE * LNET_MAX_IOV) {
2837 fprintf(stderr, "Size exceed limitation: %d bytes\n",
2842 } else if (strcasecmp(argv[i], "read") == 0 ||
2843 strcasecmp(argv[i], "r") == 0) {
2844 bulk->blk_opc = LST_BRW_READ;
2846 } else if (strcasecmp(argv[i], "write") == 0 ||
2847 strcasecmp(argv[i], "w") == 0) {
2848 bulk->blk_opc = LST_BRW_WRITE;
2851 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
2862 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
2864 lst_test_bulk_param_t *bulk = NULL;
2867 type = lst_test_name2type(test);
2869 fprintf(stderr, "Unknow test name %s\n", test);
2878 bulk = malloc(sizeof(*bulk));
2880 fprintf(stderr, "Out of memory\n");
2884 memset(bulk, 0, sizeof(*bulk));
2886 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
2892 *plen = sizeof(*bulk);
2900 /* TODO: parse more parameter */
2905 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
2906 int dist, int span, char *sgrp, char *dgrp,
2907 void *param, int plen, int *retp, struct list_head *resultp)
2909 lstio_test_args_t args = {
2910 .lstio_tes_key = session_key,
2911 .lstio_tes_bat_nmlen = strlen(batch),
2912 .lstio_tes_bat_name = batch,
2913 .lstio_tes_type = type,
2914 .lstio_tes_loop = loop,
2915 .lstio_tes_concur = concur,
2916 .lstio_tes_dist = dist,
2917 .lstio_tes_span = span,
2918 .lstio_tes_sgrp_nmlen = strlen(sgrp),
2919 .lstio_tes_sgrp_name = sgrp,
2920 .lstio_tes_dgrp_nmlen = strlen(dgrp),
2921 .lstio_tes_dgrp_name = dgrp,
2922 .lstio_tes_param_len = plen,
2923 .lstio_tes_param = param,
2924 .lstio_tes_retp = retp,
2925 .lstio_tes_resultp = resultp,
2928 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
2932 jt_lst_add_test(int argc, char **argv)
2934 struct list_head head;
2954 static struct option add_test_opts[] =
2956 {"batch", required_argument, 0, 'b' },
2957 {"concurrency", required_argument, 0, 'c' },
2958 {"distribute", required_argument, 0, 'd' },
2959 {"from", required_argument, 0, 'f' },
2960 {"to", required_argument, 0, 't' },
2961 {"loop", required_argument, 0, 'l' },
2965 if (session_key == 0) {
2967 "Can't find env LST_SESSION or value is not valid\n");
2972 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
2973 add_test_opts, &optidx);
2975 /* Detect the end of the options. */
2984 concur = atoi(optarg);
2993 loop = atoi(optarg);
2999 lst_print_usage(argv[0]);
3004 if (optind == argc || from == NULL || to == NULL) {
3005 lst_print_usage(argv[0]);
3009 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3010 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3015 batch = LST_DEFAULT_BATCH;
3018 rc = lst_parse_distribute(dstr, &dist, &span);
3020 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3025 test = argv[optind++];
3030 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3032 fprintf(stderr, "Failed to add test (%s)\n", test);
3036 CFS_INIT_LIST_HEAD(&head);
3038 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3040 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3041 from, strerror(errno));
3045 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3047 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3048 to, strerror(errno));
3052 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3054 fprintf(stderr, "Out of memory\n");
3058 rc = lst_add_test_ioctl(batch, type, loop, concur,
3059 dist, span, from, to, param, plen, &ret, &head);
3062 fprintf(stdout, "Test was added successfully\n");
3064 fprintf(stdout, "Server group contains userland test "
3065 "nodes, old version of tcplnd can't accept "
3066 "connection request\n");
3073 lst_print_error("test", "Failed to add test: %s\n",
3078 lst_print_transerr(&head, "add test");
3080 lst_free_rpcent(&head);
3088 static command_t lst_cmdlist[] = {
3089 {"new_session", jt_lst_new_session, NULL,
3090 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3091 {"end_session", jt_lst_end_session, NULL,
3092 "Usage: lst end_session" },
3093 {"show_session", jt_lst_show_session, NULL,
3094 "Usage: lst show_session" },
3095 {"ping", jt_lst_ping , NULL,
3096 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3097 {"add_group", jt_lst_add_group, NULL,
3098 "Usage: lst group NAME IDs [IDs]..." },
3099 {"del_group", jt_lst_del_group, NULL,
3100 "Usage: lst del_group NAME" },
3101 {"update_group", jt_lst_update_group, NULL,
3102 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3103 {"list_group", jt_lst_list_group, NULL,
3104 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3105 {"stat", jt_lst_stat, NULL,
3106 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3107 " [--timeout #] [--delay #] GROUP [GROUP]" },
3108 {"show_error", jt_lst_show_error, NULL,
3109 "Usage: lst show_error NAME | IDS ..." },
3110 {"add_batch", jt_lst_add_batch, NULL,
3111 "Usage: lst add_batch NAME" },
3112 {"run", jt_lst_start_batch, NULL,
3113 "Usage: lst run [--timeout TIME] [NAME]" },
3114 {"stop", jt_lst_stop_batch, NULL,
3115 "Usage: lst stop [--force] BATCH_NAME" },
3116 {"list_batch", jt_lst_list_batch, NULL,
3117 "Usage: lst list_batch NAME [--test ID] [--server]" },
3118 {"query", jt_lst_query_batch, NULL,
3119 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3120 {"add_test", jt_lst_add_test, NULL,
3121 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3122 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3123 {"help", Parser_help, 0, "help" },
3128 lst_initialize(void)
3132 key = getenv("LST_SESSION");
3139 session_key = atoi(key);
3145 main(int argc, char **argv)
3149 if (lst_initialize() < 0)
3152 if (ptl_initialize(argc, argv) < 0)
3155 Parser_init("lst > ", lst_cmdlist);
3158 return Parser_execarg(argc - 1, argv + 1, lst_cmdlist);