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;
71 new_lstrs(lstr_t **list, char *prefix, char *postfix,
72 int lo, int hi, int stride)
74 int n1 = strlen(prefix);
75 int n2 = strlen(postfix);
76 int sz = n1 + 20 + n2 + 1;
79 lstr_t *n = alloc_lstr(sz);
81 snprintf(n->lstr_str, sz - 1, "%s%u%s",
92 expand_lstr(lstr_t **list, lstr_t *l)
94 int nob = strlen(l->lstr_str);
104 b1 = strchr(l->lstr_str, '[');
106 l->lstr_next = *list;
111 b2 = strchr(b1, ']');
112 if (b2 == NULL || b2 == b1 + 1)
120 sep = strchr(expr, ',');
126 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
128 new_lstrs(list, l->lstr_str, b2, x, x, 1);
133 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
136 new_lstrs(list, l->lstr_str, b2, x, y, 1);
141 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
144 new_lstrs(list, l->lstr_str, b2, x, y, z);
150 } while ((expr = sep) != NULL);
158 expand_strs(char *str, lstr_t **head)
166 l = alloc_lstr(strlen(str) + 1);
167 memcpy(l->lstr_str, str, strlen(str) + 1);
175 while ((l = list) != NULL) {
178 rc = expand_lstr(&nlist, l);
180 fprintf(stderr, "Syntax error in \"%s\"\n", str);
188 /* re-order onto 'list' */
189 while ((l = nlist) != NULL) {
190 nlist = l->lstr_next;
195 } while (expanded && rc > 0);
202 while ((l = list) != NULL) {
211 lst_parse_nids(char *str, int *countp, lnet_process_id_t **idspp)
219 rc = expand_strs(str, &head);
229 *idspp = malloc(c * sizeof(lnet_process_id_t));
230 if (*idspp == NULL) {
231 fprintf(stderr, "Out of memory\n");
238 while ((l = head) != NULL) {
242 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
243 if ((*idspp)[i].nid == LNET_NID_ANY) {
244 fprintf(stderr, "Invalid nid: %s\n",
249 (*idspp)[i].pid = LUSTRE_LNET_PID;
266 lst_node_state2str(int state)
268 if (state == LST_NODE_ACTIVE)
270 if (state == LST_NODE_BUSY)
272 if (state == LST_NODE_DOWN)
279 lst_node_str2state(char *str)
281 if (strcasecmp(str, "active") == 0)
282 return LST_NODE_ACTIVE;
283 if (strcasecmp(str, "busy") == 0)
284 return LST_NODE_BUSY;
285 if (strcasecmp(str, "down") == 0)
286 return LST_NODE_DOWN;
287 if (strcasecmp(str, "unknown") == 0)
288 return LST_NODE_UNKNOWN;
289 if (strcasecmp(str, "invalid") == 0)
290 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
296 lst_test_type2name(int type)
298 if (type == LST_TEST_PING)
300 if (type == LST_TEST_BULK)
307 lst_test_name2type(char *name)
309 if (strcasecmp(name, "ping") == 0)
310 return LST_TEST_PING;
311 if (strcasecmp(name, "brw") == 0)
312 return LST_TEST_BULK;
318 lst_print_usage(char *cmd)
320 Parser_printhelp(cmd);
324 lst_print_error(char *sub, const char *def_format, ...)
328 /* local error returned from kernel */
331 fprintf(stderr, "No session exists\n");
334 fprintf(stderr, "Session is shutting down\n");
337 fprintf(stderr, "Unmatched session key or not root\n");
340 fprintf(stderr, "Can't find %s in current session\n", sub);
343 fprintf(stderr, "Invalid parameters list in command line\n");
346 fprintf(stderr, "Bad parameter address\n");
349 fprintf(stderr, "%s already exists\n", sub);
352 va_start(ap, def_format);
353 vfprintf(stderr, def_format, ap);
361 lst_free_rpcent(struct list_head *head)
363 lstcon_rpc_ent_t *ent;
365 while (!list_empty(head)) {
366 ent = list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
368 list_del(&ent->rpe_link);
374 lst_reset_rpcent(struct list_head *head)
376 lstcon_rpc_ent_t *ent;
378 list_for_each_entry(ent, head, rpe_link) {
379 ent->rpe_sid = LST_INVALID_SID;
380 ent->rpe_peer.nid = LNET_NID_ANY;
381 ent->rpe_peer.pid = LNET_PID_ANY;
382 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
387 lst_alloc_rpcent(struct list_head *head, int count, int offset)
389 lstcon_rpc_ent_t *ent;
392 for (i = 0; i < count; i++) {
393 ent = malloc(offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
395 lst_free_rpcent(head);
399 memset(ent, 0, offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
401 ent->rpe_sid = LST_INVALID_SID;
402 ent->rpe_peer.nid = LNET_NID_ANY;
403 ent->rpe_peer.pid = LNET_PID_ANY;
404 list_add(&ent->rpe_link, head);
411 lst_print_transerr(struct list_head *head, char *optstr)
413 lstcon_rpc_ent_t *ent;
415 list_for_each_entry(ent, head, rpe_link) {
416 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
419 if (ent->rpe_rpc_errno != 0) {
420 fprintf(stderr, "%s RPC failed on %s: %s\n",
421 optstr, libcfs_id2str(ent->rpe_peer),
422 strerror(ent->rpe_rpc_errno));
426 fprintf(stderr, "%s failed on %s: %s\n",
427 optstr, libcfs_id2str(ent->rpe_peer),
428 strerror(ent->rpe_fwk_errno));
433 lst_ioctl(unsigned int opc, void *buf, int len)
435 struct libcfs_ioctl_data data;
438 LIBCFS_IOC_INIT (data);
439 data.ioc_u32[0] = opc;
440 data.ioc_plen1 = len;
441 data.ioc_pbuf1 = (char *)buf;
442 data.ioc_plen2 = sizeof(trans_stat);
443 data.ioc_pbuf2 = (char *)&trans_stat;
445 memset(&trans_stat, 0, sizeof(trans_stat));
447 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
449 /* local error, no valid RPC result */
454 if (trans_stat.trs_rpc_errno != 0)
457 /* Framework error */
458 if (trans_stat.trs_fwk_errno != 0)
465 lst_new_session_ioctl (char *name, int timeout, int force, lst_sid_t *sid)
467 lstio_session_new_args_t args = {
468 .lstio_ses_key = session_key,
469 .lstio_ses_timeout = timeout,
470 .lstio_ses_force = force,
471 .lstio_ses_idp = sid,
472 .lstio_ses_namep = name,
473 .lstio_ses_nmlen = strlen(name),
476 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
480 jt_lst_new_session(int argc, char **argv)
482 char buf[LST_NAME_SIZE];
490 static struct option session_opts[] =
492 {"timeout", required_argument, 0, 't' },
493 {"force", no_argument, 0, 'f' },
497 if (session_key == 0) {
499 "Can't find env LST_SESSION or value is not valid\n");
505 c = getopt_long(argc, argv, "ft:",
506 session_opts, &optidx);
516 timeout = atoi(optarg);
519 lst_print_usage(argv[0]);
525 fprintf(stderr, "Invalid timeout value\n");
529 if (optind == argc - 1) {
530 name = argv[optind ++];
531 if (strlen(name) >= LST_NAME_SIZE) {
532 fprintf(stderr, "Name size is limited to %d\n",
537 } else if (optind == argc) {
538 char user[LST_NAME_SIZE];
539 char host[LST_NAME_SIZE];
540 struct passwd *pw = getpwuid(getuid());
543 snprintf(user, sizeof(user), "%d", (int)getuid());
545 snprintf(user, sizeof(user), "%s", pw->pw_name);
547 rc = gethostname(host, sizeof(host));
549 snprintf(host, sizeof(host), "unknown_host");
551 snprintf(buf, LST_NAME_SIZE, "%s@%s", user, host);
555 lst_print_usage(argv[0]);
559 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
562 lst_print_error("session", "Failed to create session: %s\n",
567 fprintf(stdout, "SESSION: %s TIMEOUT: %d FORCE: %s\n",
568 name, timeout, force ? "Yes": "No");
574 lst_session_info_ioctl(char *name, int len, int *key,
575 lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
577 lstio_session_info_args_t args = {
578 .lstio_ses_keyp = key,
579 .lstio_ses_idp = sid,
580 .lstio_ses_ndinfo = ndinfo,
581 .lstio_ses_nmlen = len,
582 .lstio_ses_namep = name,
585 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
589 jt_lst_show_session(int argc, char **argv)
591 lstcon_ndlist_ent_t ndinfo;
593 char name[LST_NAME_SIZE];
597 rc = lst_session_info_ioctl(name, LST_NAME_SIZE, &key, &sid, &ndinfo);
600 lst_print_error("session", "Failed to show session: %s\n",
605 fprintf(stdout, "%s ID: %Lu@%s, KEY: %d NODES: %d\n",
606 name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
607 key, ndinfo.nle_nnode);
613 lst_end_session_ioctl(void)
615 lstio_session_end_args_t args = {
616 .lstio_ses_key = session_key,
619 return lst_ioctl (LSTIO_SESSION_END, &args, sizeof(args));
623 jt_lst_end_session(int argc, char **argv)
627 if (session_key == 0) {
629 "Can't find env LST_SESSION or value is not valid\n");
633 rc = lst_end_session_ioctl();
636 fprintf(stdout, "session is ended\n");
641 lst_print_error("session", "Failed to end session: %s\n",
646 if (trans_stat.trs_rpc_errno != 0) {
648 "[RPC] Failed to send %d session RPCs: %s\n",
649 lstcon_rpc_stat_failure(&trans_stat, 0),
650 strerror(trans_stat.trs_rpc_errno));
653 if (trans_stat.trs_fwk_errno != 0) {
655 "[FWK] Failed to end session on %d nodes: %s\n",
656 lstcon_sesop_stat_failure(&trans_stat, 0),
657 strerror(trans_stat.trs_fwk_errno));
664 lst_ping_ioctl(char *str, int type, int timeout,
665 int count, lnet_process_id_t *ids, struct list_head *head)
667 lstio_debug_args_t args = {
668 .lstio_dbg_key = session_key,
669 .lstio_dbg_type = type,
670 .lstio_dbg_flags = 0,
671 .lstio_dbg_timeout = timeout,
672 .lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str),
673 .lstio_dbg_namep = str,
674 .lstio_dbg_count = count,
675 .lstio_dbg_idsp = ids,
676 .lstio_dbg_resultp = head,
679 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
683 lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
685 char buf[LST_NAME_SIZE];
686 lstcon_test_batch_ent_t ent;
687 lstcon_ndlist_ent_t *entp = &ent.tbe_cli_nle;
693 case LST_OPC_SESSION:
694 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
698 case LST_OPC_BATCHSRV:
699 entp = &ent.tbe_srv_nle;
700 case LST_OPC_BATCHCLI:
701 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
705 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
709 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
718 *countp = entp->nle_nnode;
724 jt_lst_ping(int argc, char **argv)
726 struct list_head head;
727 lnet_process_id_t *ids = NULL;
728 lstcon_rpc_ent_t *ent = NULL;
739 static struct option ping_opts[] =
741 {"session", no_argument, 0, 's' },
742 {"server", no_argument, 0, 'v' },
743 {"batch", required_argument, 0, 'b' },
744 {"group", required_argument, 0, 'g' },
745 {"nodes", required_argument, 0, 'n' },
746 {"timeout", required_argument, 0, 't' },
750 if (session_key == 0) {
752 "Can't find env LST_SESSION or value is not valid\n");
758 c = getopt_long(argc, argv, "g:b:n:t:sv",
766 type = LST_OPC_SESSION;
770 type = LST_OPC_GROUP;
775 type = LST_OPC_BATCHCLI;
780 type = LST_OPC_NODES;
785 timeout = atoi(optarg);
793 lst_print_usage(argv[0]);
798 if (type == 0 || timeout <= 0 || optind != argc) {
799 lst_print_usage(argv[0]);
803 if (type == LST_OPC_BATCHCLI && server)
804 type = LST_OPC_BATCHSRV;
806 rc = lst_get_node_count(type, str, &count, &ids);
808 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
809 (str == NULL) ? "session" : str, strerror(errno));
813 CFS_INIT_LIST_HEAD(&head);
815 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
817 fprintf(stderr, "Out of memory\n");
822 fprintf(stdout, "Target %s is empty\n",
823 (str == NULL) ? "session" : str);
827 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
828 if (rc == -1) { /* local failure */
829 lst_print_error("debug", "Failed to ping %s: %s\n",
830 (str == NULL) ? "session" : str,
836 /* ignore RPC errors and framwork errors */
837 list_for_each_entry(ent, &head, rpe_link) {
838 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
839 libcfs_id2str(ent->rpe_peer),
840 lst_node_state2str(ent->rpe_state),
841 (ent->rpe_state == LST_NODE_ACTIVE ||
842 ent->rpe_state == LST_NODE_BUSY)?
843 (ent->rpe_rpc_errno == 0 ?
844 &ent->rpe_payload[0] : "Unknown") :
845 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
849 lst_free_rpcent(&head);
859 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
860 struct list_head *resultp)
862 lstio_group_nodes_args_t args = {
863 .lstio_grp_key = session_key,
864 .lstio_grp_nmlen = strlen(name),
865 .lstio_grp_namep = name,
866 .lstio_grp_count = count,
867 .lstio_grp_idsp = ids,
868 .lstio_grp_resultp = resultp,
871 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
875 lst_add_group_ioctl (char *name)
877 lstio_group_add_args_t args = {
878 .lstio_grp_key = session_key,
879 .lstio_grp_nmlen = strlen(name),
880 .lstio_grp_namep = name,
883 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
887 jt_lst_add_group(int argc, char **argv)
889 struct list_head head;
890 lnet_process_id_t *ids;
896 if (session_key == 0) {
898 "Can't find env LST_SESSION or value is not valid\n");
903 lst_print_usage(argv[0]);
908 if (strlen(name) >= LST_NAME_SIZE) {
909 fprintf(stderr, "Name length is limited to %d\n",
914 rc = lst_add_group_ioctl(name);
916 lst_print_error("group", "Failed to add group %s: %s\n",
917 name, strerror(errno));
921 CFS_INIT_LIST_HEAD(&head);
923 for (i = 2; i < argc; i++) {
924 /* parse address list */
925 rc = lst_parse_nids(argv[i], &count, &ids);
927 fprintf(stderr, "Ignore invalid id list %s\n",
935 rc = lst_alloc_rpcent(&head, count, 0);
937 fprintf(stderr, "Out of memory\n");
941 rc = lst_add_nodes_ioctl(name, count, ids, &head);
946 lst_free_rpcent(&head);
947 fprintf(stderr, "%s are added to session\n", argv[i]);
952 lst_free_rpcent(&head);
953 lst_print_error("group", "Failed to add nodes %s: %s\n",
954 argv[i], strerror(errno));
958 lst_print_transerr(&head, "create session");
959 lst_free_rpcent(&head);
966 lst_del_group_ioctl (char *name)
968 lstio_group_del_args_t args = {
969 .lstio_grp_key = session_key,
970 .lstio_grp_nmlen = strlen(name),
971 .lstio_grp_namep = name,
974 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
978 jt_lst_del_group(int argc, char **argv)
982 if (session_key == 0) {
984 "Can't find env LST_SESSION or value is not valid\n");
989 lst_print_usage(argv[0]);
993 rc = lst_del_group_ioctl(argv[1]);
995 fprintf(stdout, "Group is deleted\n");
1000 lst_print_error("group", "Failed to delete group: %s\n",
1005 fprintf(stderr, "Group is deleted with some errors\n");
1007 if (trans_stat.trs_rpc_errno != 0) {
1008 fprintf(stderr, "[RPC] Failed to send %d end session RPCs: %s\n",
1009 lstcon_rpc_stat_failure(&trans_stat, 0),
1010 strerror(trans_stat.trs_rpc_errno));
1013 if (trans_stat.trs_fwk_errno != 0) {
1015 "[FWK] Failed to end session on %d nodes: %s\n",
1016 lstcon_sesop_stat_failure(&trans_stat, 0),
1017 strerror(trans_stat.trs_fwk_errno));
1024 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1025 lnet_process_id_t *ids, struct list_head *resultp)
1027 lstio_group_update_args_t args = {
1028 .lstio_grp_key = session_key,
1029 .lstio_grp_opc = opc,
1030 .lstio_grp_args = clean,
1031 .lstio_grp_nmlen = strlen(name),
1032 .lstio_grp_namep = name,
1033 .lstio_grp_count = count,
1034 .lstio_grp_idsp = ids,
1035 .lstio_grp_resultp = resultp,
1038 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1042 jt_lst_update_group(int argc, char **argv)
1044 struct list_head head;
1045 lnet_process_id_t *ids = NULL;
1055 static struct option update_group_opts[] =
1057 {"refresh", no_argument, 0, 'f' },
1058 {"clean", required_argument, 0, 'c' },
1059 {"remove", required_argument, 0, 'r' },
1063 if (session_key == 0) {
1065 "Can't find env LST_SESSION or value is not valid\n");
1070 c = getopt_long(argc, argv, "fc:r:",
1071 update_group_opts, &optidx);
1073 /* Detect the end of the options. */
1080 lst_print_usage(argv[0]);
1083 opc = LST_GROUP_REFRESH;
1088 lst_print_usage(argv[0]);
1091 opc = LST_GROUP_RMND;
1096 clean = lst_node_str2state(optarg);
1097 if (opc != 0 || clean <= 0) {
1098 lst_print_usage(argv[0]);
1101 opc = LST_GROUP_CLEAN;
1105 lst_print_usage(argv[0]);
1110 /* no OPC or group is specified */
1111 if (opc == 0 || optind != argc - 1) {
1112 lst_print_usage(argv[0]);
1118 CFS_INIT_LIST_HEAD(&head);
1120 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1121 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1123 opc == LST_GROUP_RMND ? str : grp,
1127 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1128 opc == LST_GROUP_RMND ? str : grp,
1133 rc = lst_alloc_rpcent(&head, count, 0);
1135 fprintf(stderr, "Out of memory\n");
1142 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1148 lst_free_rpcent(&head);
1153 lst_free_rpcent(&head);
1154 lst_print_error("group", "Failed to update group: %s\n",
1159 lst_print_transerr(&head, "Updating group");
1161 lst_free_rpcent(&head);
1167 lst_list_group_ioctl(int len, char *name, int idx)
1169 lstio_group_list_args_t args = {
1170 .lstio_grp_key = session_key,
1171 .lstio_grp_idx = idx,
1172 .lstio_grp_nmlen = len,
1173 .lstio_grp_namep = name,
1176 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1180 lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
1181 int *idx, int *count, lstcon_node_ent_t *dents)
1183 lstio_group_info_args_t args = {
1184 .lstio_grp_key = session_key,
1185 .lstio_grp_nmlen = strlen(name),
1186 .lstio_grp_namep = name,
1187 .lstio_grp_entp = gent,
1188 .lstio_grp_idxp = idx,
1189 .lstio_grp_ndentp = count,
1190 .lstio_grp_dentsp = dents,
1193 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1197 lst_list_group_all(void)
1199 char name[LST_NAME_SIZE];
1203 /* no group is specified, list name of all groups */
1204 for (i = 0; ; i++) {
1205 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1207 fprintf(stdout, "%d) %s\n", i + 1, name);
1211 if (errno == ENOENT)
1214 lst_print_error("group", "Failed to list group: %s\n",
1219 fprintf(stdout, "Total %d groups\n", i);
1224 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1227 jt_lst_list_group(int argc, char **argv)
1229 lstcon_ndlist_ent_t gent;
1230 lstcon_node_ent_t *dents;
1245 static struct option list_group_opts[] =
1247 {"active", no_argument, 0, 'a' },
1248 {"busy", no_argument, 0, 'b' },
1249 {"down", no_argument, 0, 'd' },
1250 {"unknown", no_argument, 0, 'u' },
1251 {"all", no_argument, 0, 'l' },
1255 if (session_key == 0) {
1257 "Can't find env LST_SESSION or value is not valid\n");
1262 c = getopt_long(argc, argv, "abdul",
1263 list_group_opts, &optidx);
1270 verbose = active = 1;
1282 verbose = unknown = 1;
1289 lst_print_usage(argv[0]);
1294 if (optind == argc) {
1295 /* no group is specified, list name of all groups */
1296 rc = lst_list_group_all();
1302 fprintf(stdout, LST_NODES_TITLE);
1304 /* list nodes in specified groups */
1305 for (i = optind; i < argc; i++) {
1306 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1308 if (errno == ENOENT) {
1313 lst_print_error("group", "Failed to list group\n",
1319 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1320 gent.nle_nactive, gent.nle_nbusy,
1321 gent.nle_ndown, gent.nle_nunknown,
1322 gent.nle_nnode, argv[i]);
1326 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1328 if (gent.nle_nnode == 0) {
1329 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1333 count = gent.nle_nnode;
1335 dents = malloc(count * sizeof(lstcon_node_ent_t));
1336 if (dents == NULL) {
1337 fprintf(stderr, "Failed to malloc: %s\n",
1343 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1345 lst_print_error("group", "Failed to list group: %s\n",
1351 for (j = 0, c = 0; j < count; j++) {
1353 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1354 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1355 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1356 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1358 fprintf(stdout, "\t%s: %s\n",
1359 libcfs_id2str(dents[j].nde_id),
1360 lst_node_state2str(dents[j].nde_state));
1365 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1374 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
1375 int timeout, struct list_head *resultp)
1377 lstio_stat_args_t args = {
1378 .lstio_sta_key = session_key,
1379 .lstio_sta_timeout = timeout,
1380 .lstio_sta_nmlen = strlen(name),
1381 .lstio_sta_namep = name,
1382 .lstio_sta_count = count,
1383 .lstio_sta_idsp = idsp,
1384 .lstio_sta_resultp = resultp,
1387 return lst_ioctl (LSTIO_STAT_QUERY, &args, sizeof(args));
1391 struct list_head srp_link;
1394 lnet_process_id_t *srp_ids;
1395 struct list_head srp_result[2];
1396 } lst_stat_req_param_t;
1399 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1403 for (i = 0; i < 2; i++)
1404 lst_free_rpcent(&srp->srp_result[i]);
1406 if (srp->srp_ids != NULL)
1413 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp)
1415 lst_stat_req_param_t *srp = NULL;
1419 srp = malloc(sizeof(*srp));
1423 memset(srp, 0, sizeof(*srp));
1424 CFS_INIT_LIST_HEAD(&srp->srp_result[0]);
1425 CFS_INIT_LIST_HEAD(&srp->srp_result[1]);
1427 rc = lst_get_node_count(LST_OPC_GROUP, name,
1428 &srp->srp_count, NULL);
1430 rc = lst_get_node_count(LST_OPC_NODES, name,
1431 &srp->srp_count, &srp->srp_ids);
1436 "Failed to get count of nodes from %s\n", name);
1437 lst_stat_req_param_free(srp);
1442 srp->srp_name = name;
1444 for (i = 0; i < 2; i++) {
1445 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1446 sizeof(sfw_counters_t) +
1447 sizeof(srpc_counters_t) +
1448 sizeof(lnet_counters_t));
1450 fprintf(stderr, "Out of memory\n");
1460 lst_stat_req_param_free(srp);
1467 } lst_srpc_stat_result;
1469 #define LST_LNET_AVG 0
1470 #define LST_LNET_MIN 1
1471 #define LST_LNET_MAX 2
1474 float lnet_avg_sndrate;
1475 float lnet_min_sndrate;
1476 float lnet_max_sndrate;
1477 float lnet_total_sndrate;
1479 float lnet_avg_rcvrate;
1480 float lnet_min_rcvrate;
1481 float lnet_max_rcvrate;
1482 float lnet_total_rcvrate;
1484 float lnet_avg_sndperf;
1485 float lnet_min_sndperf;
1486 float lnet_max_sndperf;
1487 float lnet_total_sndperf;
1489 float lnet_avg_rcvperf;
1490 float lnet_min_rcvperf;
1491 float lnet_max_rcvperf;
1492 float lnet_total_rcvperf;
1494 int lnet_stat_count;
1495 } lst_lnet_stat_result_t;
1497 lst_lnet_stat_result_t lnet_stat_result;
1500 lst_lnet_stat_value(int bw, int send, int off)
1504 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1505 &lnet_stat_result.lnet_avg_sndrate;
1516 lst_timeval_diff(struct timeval *tv1,
1517 struct timeval *tv2, struct timeval *df)
1519 if (tv1->tv_usec >= tv2->tv_usec) {
1520 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1521 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1525 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1526 df->tv_usec = tv1->tv_sec + 1000000 - tv2->tv_usec;
1532 lst_cal_lnet_stat(float delta, lnet_counters_t *lnet_new,
1533 lnet_counters_t *lnet_old)
1538 perf = (float)(lnet_new->send_length -
1539 lnet_old->send_length) / (1024 * 1024) / delta;
1540 lnet_stat_result.lnet_total_sndperf += perf;
1542 if (lnet_stat_result.lnet_min_sndperf > perf ||
1543 lnet_stat_result.lnet_min_sndperf == 0)
1544 lnet_stat_result.lnet_min_sndperf = perf;
1546 if (lnet_stat_result.lnet_max_sndperf < perf)
1547 lnet_stat_result.lnet_max_sndperf = perf;
1549 perf = (float)(lnet_new->recv_length -
1550 lnet_old->recv_length) / (1024 * 1024) / delta;
1551 lnet_stat_result.lnet_total_rcvperf += perf;
1553 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1554 lnet_stat_result.lnet_min_rcvperf == 0)
1555 lnet_stat_result.lnet_min_rcvperf = perf;
1557 if (lnet_stat_result.lnet_max_rcvperf < perf)
1558 lnet_stat_result.lnet_max_rcvperf = perf;
1560 rate = (lnet_new->send_count - lnet_old->send_count) / delta;
1561 lnet_stat_result.lnet_total_sndrate += rate;
1563 if (lnet_stat_result.lnet_min_sndrate > rate ||
1564 lnet_stat_result.lnet_min_sndrate == 0)
1565 lnet_stat_result.lnet_min_sndrate = rate;
1567 if (lnet_stat_result.lnet_max_sndrate < rate)
1568 lnet_stat_result.lnet_max_sndrate = rate;
1570 rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
1571 lnet_stat_result.lnet_total_rcvrate += rate;
1573 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1574 lnet_stat_result.lnet_min_rcvrate == 0)
1575 lnet_stat_result.lnet_min_rcvrate = rate;
1577 if (lnet_stat_result.lnet_max_rcvrate < rate)
1578 lnet_stat_result.lnet_max_rcvrate = rate;
1580 lnet_stat_result.lnet_stat_count ++;
1582 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1583 lnet_stat_result.lnet_stat_count;
1584 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1585 lnet_stat_result.lnet_stat_count;
1587 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1588 lnet_stat_result.lnet_stat_count;
1589 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1590 lnet_stat_result.lnet_stat_count;
1595 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
1606 if (lnet_stat_result.lnet_stat_count == 0)
1609 if (bwrt == 1) /* bw only */
1612 if (bwrt == 2) /* rates only */
1615 if (rdwr == 1) /* recv only */
1618 if (rdwr == 2) /* send only */
1621 for (i = start1; i <= end1; i++) {
1622 fprintf(stdout, "[LNet %s of %s]\n",
1623 i == 0 ? "Rates" : "Bandwidth", name);
1625 for (j = start2; j <= end2; j++) {
1626 fprintf(stdout, "[%c] ", j == 0 ? 'W' : 'R');
1628 if ((type & 1) != 0) {
1629 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1630 "Avg: %-8.2f MB/s ",
1631 lst_lnet_stat_value(i, j, 0));
1634 if ((type & 2) != 0) {
1635 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1636 "Min: %-8.2f MB/s ",
1637 lst_lnet_stat_value(i, j, 1));
1640 if ((type & 4) != 0) {
1641 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1643 lst_lnet_stat_value(i, j, 2));
1646 fprintf(stdout, "\n");
1652 lst_print_stat(char *name, struct list_head *resultp,
1653 int idx, int lnet, int bwrt, int rdwr, int type)
1655 struct list_head tmp[2];
1656 lstcon_rpc_ent_t *new;
1657 lstcon_rpc_ent_t *old;
1658 sfw_counters_t *sfwk_new;
1659 sfw_counters_t *sfwk_old;
1660 srpc_counters_t *srpc_new;
1661 srpc_counters_t *srpc_old;
1662 lnet_counters_t *lnet_new;
1663 lnet_counters_t *lnet_old;
1668 CFS_INIT_LIST_HEAD(&tmp[0]);
1669 CFS_INIT_LIST_HEAD(&tmp[1]);
1671 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1673 while (!list_empty(&resultp[idx])) {
1674 if (list_empty(&resultp[1 - idx])) {
1675 fprintf(stderr, "Group is changed, re-run stat\n");
1679 new = list_entry(resultp[idx].next, lstcon_rpc_ent_t, rpe_link);
1680 old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t, rpe_link);
1682 /* first time get stats result, can't calculate diff */
1683 if (new->rpe_peer.nid == LNET_NID_ANY)
1686 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1687 new->rpe_peer.pid != old->rpe_peer.pid) {
1688 /* Something wrong. i.e, somebody change the group */
1692 list_del(&new->rpe_link);
1693 list_add_tail(&new->rpe_link, &tmp[idx]);
1695 list_del(&old->rpe_link);
1696 list_add_tail(&old->rpe_link, &tmp[1 - idx]);
1698 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1699 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1704 sfwk_new = (sfw_counters_t *)&new->rpe_payload[0];
1705 sfwk_old = (sfw_counters_t *)&old->rpe_payload[0];
1707 srpc_new = (srpc_counters_t *)((char *)sfwk_new + sizeof(*sfwk_new));
1708 srpc_old = (srpc_counters_t *)((char *)sfwk_old + sizeof(*sfwk_old));
1710 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
1711 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
1713 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1715 delta = tv.tv_sec + (float)tv.tv_usec/1000000;
1717 if (!lnet) /* TODO */
1720 lst_cal_lnet_stat(delta, lnet_new, lnet_old);
1723 list_splice(&tmp[idx], &resultp[idx]);
1724 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1727 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1729 if (!lnet) /* TODO */
1732 lst_print_lnet_stat(name, bwrt, rdwr, type);
1736 jt_lst_stat(int argc, char **argv)
1738 struct list_head head;
1739 lst_stat_req_param_t *srp;
1740 lstcon_rpc_ent_t *ent;
1745 int timeout = 5; /* default timeout, 5 sec */
1746 int delay = 5; /* default delay, 5 sec */
1747 int lnet = 1; /* lnet stat by default */
1756 static struct option stat_opts[] =
1758 {"timeout", required_argument, 0, 't' },
1759 {"delay" , required_argument, 0, 'd' },
1760 {"lnet" , no_argument, 0, 'l' },
1761 {"rpc" , no_argument, 0, 'c' },
1762 {"bw" , no_argument, 0, 'b' },
1763 {"rate" , no_argument, 0, 'a' },
1764 {"read" , no_argument, 0, 'r' },
1765 {"write" , no_argument, 0, 'w' },
1766 {"avg" , no_argument, 0, 'g' },
1767 {"min" , no_argument, 0, 'n' },
1768 {"max" , no_argument, 0, 'x' },
1772 if (session_key == 0) {
1774 "Can't find env LST_SESSION or value is not valid\n");
1779 c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
1786 timeout = atoi(optarg);
1789 delay = atoi(optarg);
1831 lst_print_usage(argv[0]);
1836 if (optind == argc) {
1837 lst_print_usage(argv[0]);
1841 if (timeout <= 0 || delay <= 0) {
1842 fprintf(stderr, "Invalid timeout or delay value\n");
1846 CFS_INIT_LIST_HEAD(&head);
1848 while (optind < argc) {
1849 name = argv[optind++];
1851 rc = lst_stat_req_param_alloc(name, &srp);
1855 list_add_tail(&srp->srp_link, &head);
1859 time_t now = time(NULL);
1861 if (now - last < delay) {
1862 sleep(delay - now + last);
1868 list_for_each_entry(srp, &head, srp_link) {
1869 rc = lst_stat_ioctl(srp->srp_name,
1870 srp->srp_count, srp->srp_ids,
1871 timeout, &srp->srp_result[idx]);
1873 lst_print_error("stat", "Failed to stat %s: %s\n",
1874 name, strerror(errno));
1878 lst_print_stat(srp->srp_name, srp->srp_result,
1879 idx, lnet, bwrt, rdwr, type);
1881 lst_reset_rpcent(&srp->srp_result[1 - idx]);
1888 while (!list_empty(&head)) {
1889 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
1891 list_del(&srp->srp_link);
1892 lst_stat_req_param_free(srp);
1899 lst_add_batch_ioctl (char *name)
1901 lstio_batch_add_args_t args = {
1902 .lstio_bat_key = session_key,
1903 .lstio_bat_nmlen = strlen(name),
1904 .lstio_bat_namep = name,
1907 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
1911 jt_lst_add_batch(int argc, char **argv)
1916 if (session_key == 0) {
1918 "Can't find env LST_SESSION or value is not valid\n");
1923 lst_print_usage(argv[0]);
1928 if (strlen(name) >= LST_NAME_SIZE) {
1929 fprintf(stderr, "Name length is limited to %d\n",
1934 rc = lst_add_batch_ioctl(name);
1938 lst_print_error("batch", "Failed to create batch: %s\n",
1945 lst_start_batch_ioctl (char *name, int timeout, struct list_head *resultp)
1947 lstio_batch_run_args_t args = {
1948 .lstio_bat_key = session_key,
1949 .lstio_bat_timeout = timeout,
1950 .lstio_bat_nmlen = strlen(name),
1951 .lstio_bat_namep = name,
1952 .lstio_bat_resultp = resultp,
1955 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
1959 jt_lst_start_batch(int argc, char **argv)
1961 struct list_head head;
1969 static struct option start_batch_opts[] =
1971 {"timeout", required_argument, 0, 't' },
1975 if (session_key == 0) {
1977 "Can't find env LST_SESSION or value is not valid\n");
1982 c = getopt_long(argc, argv, "t:",
1983 start_batch_opts, &optidx);
1985 /* Detect the end of the options. */
1991 timeout = atoi(optarg);
1994 lst_print_usage(argv[0]);
1999 if (optind == argc) {
2000 batch = LST_DEFAULT_BATCH;
2002 } else if (optind == argc - 1) {
2003 batch = argv[optind];
2006 lst_print_usage(argv[0]);
2010 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2012 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2013 batch, strerror(errno));
2017 CFS_INIT_LIST_HEAD(&head);
2019 rc = lst_alloc_rpcent(&head, count, 0);
2021 fprintf(stderr, "Out of memory\n");
2025 rc = lst_start_batch_ioctl(batch, timeout, &head);
2028 fprintf(stdout, "%s is running now\n", batch);
2029 lst_free_rpcent(&head);
2034 lst_print_error("batch", "Failed to start batch: %s\n",
2036 lst_free_rpcent(&head);
2040 lst_print_transerr(&head, "Run batch");
2042 lst_free_rpcent(&head);
2048 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2050 lstio_batch_stop_args_t args = {
2051 .lstio_bat_key = session_key,
2052 .lstio_bat_force = force,
2053 .lstio_bat_nmlen = strlen(name),
2054 .lstio_bat_namep = name,
2055 .lstio_bat_resultp = resultp,
2058 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2062 jt_lst_stop_batch(int argc, char **argv)
2064 struct list_head head;
2072 static struct option stop_batch_opts[] =
2074 {"force", no_argument, 0, 'f' },
2078 if (session_key == 0) {
2080 "Can't find env LST_SESSION or value is not valid\n");
2085 c = getopt_long(argc, argv, "f",
2086 stop_batch_opts, &optidx);
2088 /* Detect the end of the options. */
2097 lst_print_usage(argv[0]);
2102 if (optind == argc) {
2103 batch = LST_DEFAULT_BATCH;
2105 } else if (optind == argc - 1) {
2106 batch = argv[optind];
2109 lst_print_usage(argv[0]);
2113 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2115 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2116 batch, strerror(errno));
2120 CFS_INIT_LIST_HEAD(&head);
2122 rc = lst_alloc_rpcent(&head, count, 0);
2124 fprintf(stderr, "Out of memory\n");
2128 rc = lst_stop_batch_ioctl(batch, force, &head);
2133 lst_reset_rpcent(&head);
2135 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2139 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2140 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2143 fprintf(stdout, "%d batch in stopping\n",
2144 lstcon_tsbqry_stat_run(&trans_stat, 0));
2148 fprintf(stdout, "Batch is stopped\n");
2149 lst_free_rpcent(&head);
2154 lst_print_error("batch", "Failed to stop batch: %s\n",
2156 lst_free_rpcent(&head);
2160 lst_print_transerr(&head, "stop batch");
2162 lst_free_rpcent(&head);
2168 lst_list_batch_ioctl(int len, char *name, int index)
2170 lstio_batch_list_args_t args = {
2171 .lstio_bat_key = session_key,
2172 .lstio_bat_idx = index,
2173 .lstio_bat_nmlen = len,
2174 .lstio_bat_namep = name,
2177 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2181 lst_info_batch_ioctl(char *batch, int test, int server,
2182 lstcon_test_batch_ent_t *entp, int *idxp,
2183 int *ndentp, lstcon_node_ent_t *dentsp)
2185 lstio_batch_info_args_t args = {
2186 .lstio_bat_key = session_key,
2187 .lstio_bat_nmlen = strlen(batch),
2188 .lstio_bat_namep = batch,
2189 .lstio_bat_server = server,
2190 .lstio_bat_testidx = test,
2191 .lstio_bat_entp = entp,
2192 .lstio_bat_idxp = idxp,
2193 .lstio_bat_ndentp = ndentp,
2194 .lstio_bat_dentsp = dentsp,
2197 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2201 lst_list_batch_all(void)
2203 char name[LST_NAME_SIZE];
2207 for (i = 0; ; i++) {
2208 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2210 fprintf(stdout, "%d) %s\n", i + 1, name);
2214 if (errno == ENOENT)
2217 lst_print_error("batch", "Failed to list batch: %s\n",
2222 fprintf(stdout, "Total %d batches\n", i);
2228 lst_list_tsb_nodes(char *batch, int test, int server,
2229 int count, int active, int invalid)
2231 lstcon_node_ent_t *dents;
2240 /* verbose list, show nodes in batch or test */
2241 dents = malloc(count * sizeof(lstcon_node_ent_t));
2242 if (dents == NULL) {
2243 fprintf(stdout, "Can't allocate memory\n");
2247 rc = lst_info_batch_ioctl(batch, test, server,
2248 NULL, &index, &count, dents);
2251 lst_print_error((test > 0) ? "test" : "batch",
2252 (test > 0) ? "Failed to query test: %s\n" :
2253 "Failed to query batch: %s\n",
2258 for (i = 0, c = 0; i < count; i++) {
2259 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2260 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2261 dents[i].nde_state == LST_NODE_DOWN ||
2262 dents[i].nde_state == LST_NODE_UNKNOWN)))
2265 fprintf(stdout, "\t%s: %s\n",
2266 libcfs_id2str(dents[i].nde_id),
2267 lst_node_state2str(dents[i].nde_state));
2271 fprintf(stdout, "Total %d nodes\n", c);
2278 jt_lst_list_batch(int argc, char **argv)
2280 lstcon_test_batch_ent_t ent;
2283 int verbose = 0; /* list nodes in batch or test */
2293 static struct option list_batch_opts[] =
2295 {"test", required_argument, 0, 't' },
2296 {"invalid", no_argument, 0, 'i' },
2297 {"active", no_argument, 0, 'a' },
2298 {"all", no_argument, 0, 'l' },
2299 {"server", no_argument, 0, 's' },
2303 if (session_key == 0) {
2305 "Can't find env LST_SESSION or value is not valid\n");
2310 c = getopt_long(argc, argv, "ailst:",
2311 list_batch_opts, &optidx);
2318 verbose = active = 1;
2321 verbose = invalid = 1;
2324 verbose = active = invalid = 1;
2330 test = atoi(optarg);
2334 lst_print_usage(argv[0]);
2339 if (optind == argc) {
2340 /* list all batches */
2341 rc = lst_list_batch_all();
2345 if (ntest == 1 && test <= 0) {
2346 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2350 if (optind != argc - 1) {
2351 lst_print_usage(argv[0]);
2355 batch = argv[optind];
2358 /* show detail of specified batch or test */
2359 rc = lst_info_batch_ioctl(batch, test, server,
2360 &ent, NULL, NULL, NULL);
2362 lst_print_error((test > 0) ? "test" : "batch",
2363 (test > 0) ? "Failed to query test: %s\n" :
2364 "Failed to query batch: %s\n",
2370 /* list nodes in test or batch */
2371 rc = lst_list_tsb_nodes(batch, test, server,
2372 server ? ent.tbe_srv_nle.nle_nnode :
2373 ent.tbe_cli_nle.nle_nnode,
2378 /* only show number of hosts in batch or test */
2380 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2381 batch, ent.u.tbe_batch.bae_ntest,
2382 ent.u.tbe_batch.bae_state);
2383 ntest = ent.u.tbe_batch.bae_ntest;
2384 test = 1; /* starting from test 1 */
2388 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2389 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2390 ent.u.tbe_test.tse_loop,
2391 ent.u.tbe_test.tse_concur);
2396 fprintf(stdout, LST_NODES_TITLE);
2397 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2398 "server\t%d\t%d\t%d\t%d\t%d\n",
2399 ent.tbe_cli_nle.nle_nactive,
2400 ent.tbe_cli_nle.nle_nbusy,
2401 ent.tbe_cli_nle.nle_ndown,
2402 ent.tbe_cli_nle.nle_nunknown,
2403 ent.tbe_cli_nle.nle_nnode,
2404 ent.tbe_srv_nle.nle_nactive,
2405 ent.tbe_srv_nle.nle_nbusy,
2406 ent.tbe_srv_nle.nle_ndown,
2407 ent.tbe_srv_nle.nle_nunknown,
2408 ent.tbe_srv_nle.nle_nnode);
2417 lst_query_batch_ioctl(char *batch, int test, int server,
2418 int timeout, struct list_head *head)
2420 lstio_batch_query_args_t args = {
2421 .lstio_bat_key = session_key,
2422 .lstio_bat_testidx = test,
2423 .lstio_bat_client = !(server),
2424 .lstio_bat_timeout = timeout,
2425 .lstio_bat_nmlen = strlen(batch),
2426 .lstio_bat_namep = batch,
2427 .lstio_bat_resultp = head,
2430 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2434 lst_print_tsb_verbose(struct list_head *head,
2435 int active, int idle, int error)
2437 lstcon_rpc_ent_t *ent;
2439 list_for_each_entry(ent, head, rpe_link) {
2440 if (ent->rpe_priv[0] == 0 && active)
2443 if (ent->rpe_priv[0] != 0 && idle)
2446 if (ent->rpe_fwk_errno == 0 && error)
2449 fprintf(stdout, "%s [%s]: %s\n",
2450 libcfs_id2str(ent->rpe_peer),
2451 lst_node_state2str(ent->rpe_state),
2452 ent->rpe_rpc_errno != 0 ?
2453 strerror(ent->rpe_rpc_errno) :
2454 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2459 jt_lst_query_batch(int argc, char **argv)
2461 lstcon_test_batch_ent_t ent;
2462 struct list_head head;
2463 lstcon_rpc_ent_t *rent = NULL;
2470 int timeout = 5; /* default 5 seconds */
2471 int delay = 5; /* default 5 seconds */
2472 int loop = 1; /* default 1 loop */
2482 static struct option query_batch_opts[] =
2484 {"timeout", required_argument, 0, 'o' },
2485 {"delay", required_argument, 0, 'd' },
2486 {"loop", required_argument, 0, 'c' },
2487 {"test", required_argument, 0, 't' },
2488 {"server", no_argument, 0, 's' },
2489 {"active", no_argument, 0, 'a' },
2490 {"idle", no_argument, 0, 'i' },
2491 {"error", no_argument, 0, 'e' },
2492 {"all", no_argument, 0, 'l' },
2496 if (session_key == 0) {
2498 "Can't find env LST_SESSION or value is not valid\n");
2503 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2504 query_batch_opts, &optidx);
2506 /* Detect the end of the options. */
2512 timeout = atoi(optarg);
2515 delay = atoi(optarg);
2518 loop = atoi(optarg);
2521 test = atoi(optarg);
2527 active = verbose = 1;
2533 error = verbose = 1;
2539 lst_print_usage(argv[0]);
2544 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2545 lst_print_usage(argv[0]);
2549 if (optind == argc) {
2550 batch = LST_DEFAULT_BATCH;
2552 } else if (optind == argc - 1) {
2553 batch = argv[optind];
2556 lst_print_usage(argv[0]);
2561 CFS_INIT_LIST_HEAD(&head);
2564 rc = lst_info_batch_ioctl(batch, test, server,
2565 &ent, NULL, NULL, NULL);
2567 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2568 batch, test, strerror(errno));
2572 count = server ? ent.tbe_srv_nle.nle_nnode :
2573 ent.tbe_cli_nle.nle_nnode;
2575 fprintf(stdout, "Batch or test is empty\n");
2580 rc = lst_alloc_rpcent(&head, count, 0);
2582 fprintf(stderr, "Out of memory\n");
2586 for (i = 0; i < loop; i++) {
2587 time_t now = time(NULL);
2589 if (now - last < delay) {
2590 sleep(delay - now + last);
2596 rc = lst_query_batch_ioctl(batch, test,
2597 server, timeout, &head);
2599 fprintf(stderr, "Failed to query batch: %s\n",
2606 lst_print_tsb_verbose(&head, active, idle, error);
2610 fprintf(stdout, "%s [%d] ", batch, test);
2612 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2613 fprintf(stdout, "%d of %d nodes are unknown, ",
2614 lstcon_rpc_stat_failure(&trans_stat, 0),
2615 lstcon_rpc_stat_total(&trans_stat, 0));
2618 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2619 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2620 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2621 fprintf(stdout, "is stopped\n");
2625 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2626 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2627 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2628 fprintf(stdout, "is running\n");
2632 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2633 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2634 lstcon_tsbqry_stat_run(&trans_stat, 0),
2635 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2638 lst_free_rpcent(&head);
2644 lst_parse_distribute(char *dstr, int *dist, int *span)
2650 dstr = strchr(dstr, ':');
2654 *span = atoi(dstr + 1);
2662 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
2664 lst_test_bulk_param_t *bulk = NULL;
2665 lst_test_ping_param_t *ping = NULL;
2669 type = lst_test_name2type(test);
2681 bulk = malloc(sizeof(*bulk));
2685 memset(bulk, 0, sizeof(*bulk));
2687 if (strcmp(argv[i], "w") == 0)
2688 bulk->blk_opc = LST_BRW_WRITE;
2689 else /* read by default */
2690 bulk->blk_opc = LST_BRW_READ;
2693 /* 1 page by default */
2694 bulk->blk_flags = LST_BRW_CHECK_NONE;
2697 *plen = sizeof(*bulk);
2702 bulk->blk_npg = atoi(argv[i]);
2703 if (bulk->blk_npg <= 0 ||
2704 bulk->blk_npg >= LNET_MAX_IOV) {
2710 bulk->blk_flags = LST_BRW_CHECK_NONE;
2712 *plen = sizeof(*bulk);
2717 if (strcmp(argv[i], "s") == 0)
2718 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2719 else if (strcmp(argv[i], "f") == 0)
2720 bulk->blk_flags = LST_BRW_CHECK_FULL;
2722 bulk->blk_flags = LST_BRW_CHECK_NONE;
2725 *plen = sizeof(*bulk);
2733 /* TODO: parse more parameter */
2738 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
2739 int dist, int span, char *sgrp, char *dgrp,
2740 void *param, int plen, struct list_head *resultp)
2742 lstio_test_args_t args = {
2743 .lstio_tes_key = session_key,
2744 .lstio_tes_bat_nmlen = strlen(batch),
2745 .lstio_tes_bat_name = batch,
2746 .lstio_tes_type = type,
2747 .lstio_tes_loop = loop,
2748 .lstio_tes_concur = concur,
2749 .lstio_tes_dist = dist,
2750 .lstio_tes_span = span,
2751 .lstio_tes_sgrp_nmlen = strlen(sgrp),
2752 .lstio_tes_sgrp_name = sgrp,
2753 .lstio_tes_dgrp_nmlen = strlen(dgrp),
2754 .lstio_tes_dgrp_name = dgrp,
2755 .lstio_tes_param_len = plen,
2756 .lstio_tes_param = param,
2757 .lstio_tes_resultp = resultp,
2760 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
2764 jt_lst_add_test(int argc, char **argv)
2766 struct list_head head;
2785 static struct option add_test_opts[] =
2787 {"batch", required_argument, 0, 'b' },
2788 {"concurrency", required_argument, 0, 'c' },
2789 {"distribute", required_argument, 0, 'd' },
2790 {"from", required_argument, 0, 'f' },
2791 {"to", required_argument, 0, 't' },
2792 {"loop", required_argument, 0, 'l' },
2796 if (session_key == 0) {
2798 "Can't find env LST_SESSION or value is not valid\n");
2803 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
2804 add_test_opts, &optidx);
2806 /* Detect the end of the options. */
2815 concur = atoi(optarg);
2824 loop = atoi(optarg);
2830 lst_print_usage(argv[0]);
2835 if (optind == argc || from == NULL || to == NULL) {
2836 lst_print_usage(argv[0]);
2840 if (concur <= 0 || concur > LST_MAX_CONCUR) {
2841 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
2846 batch = LST_DEFAULT_BATCH;
2849 rc = lst_parse_distribute(dstr, &dist, &span);
2851 fprintf(stderr, "Invalid distribution: %s\n", dstr);
2856 test = argv[optind++];
2861 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
2863 fprintf(stderr, "Can't parse test (%s) parameter: %s\n",
2864 test, strerror(-type));
2868 CFS_INIT_LIST_HEAD(&head);
2870 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
2872 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
2873 from, strerror(errno));
2877 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
2879 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
2880 to, strerror(errno));
2884 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
2886 fprintf(stderr, "Out of memory\n");
2890 rc = lst_add_test_ioctl(batch, type, loop, concur,
2891 dist, span, from, to, param, plen, &head);
2894 fprintf(stdout, "Test was added successfully\n");
2899 lst_print_error("test", "Failed to add test: %s\n",
2904 lst_print_transerr(&head, "add test");
2906 lst_free_rpcent(&head);
2914 static command_t lst_cmdlist[] = {
2915 {"new_session", jt_lst_new_session, NULL,
2916 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
2917 {"end_session", jt_lst_end_session, NULL,
2918 "Usage: lst end_session" },
2919 {"show_session", jt_lst_show_session, NULL,
2920 "Usage: lst show_session" },
2921 {"ping", jt_lst_ping , NULL,
2922 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
2923 {"add_group", jt_lst_add_group, NULL,
2924 "Usage: lst group NAME IDs [IDs]..." },
2925 {"del_group", jt_lst_del_group, NULL,
2926 "Usage: lst del_group NAME" },
2927 {"update_group", jt_lst_update_group, NULL,
2928 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
2929 {"list_group", jt_lst_list_group, NULL,
2930 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
2931 {"stat", jt_lst_stat, NULL,
2932 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
2933 " [--timeout #] [--delay #] GROUP [GROUP]" },
2934 {"add_batch", jt_lst_add_batch, NULL,
2935 "Usage: lst add_batch NAME" },
2936 {"run", jt_lst_start_batch, NULL,
2937 "Usage: lst run [--timeout TIME] [NAME]" },
2938 {"stop", jt_lst_stop_batch, NULL,
2939 "Usage: lst stop [--force] BATCH_NAME" },
2940 {"list_batch", jt_lst_list_batch, NULL,
2941 "Usage: lst list_batch NAME [--test ID] [--server]" },
2942 {"query", jt_lst_query_batch, NULL,
2943 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
2944 {"add_test", jt_lst_add_test, NULL,
2945 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
2946 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
2947 {"help", Parser_help, 0, "help" },
2952 lst_initialize(void)
2956 key = getenv("LST_SESSION");
2963 session_key = atoi(key);
2969 main(int argc, char **argv)
2975 if (lst_initialize() < 0)
2978 if (ptl_initialize(argc, argv) < 0)
2981 Parser_init("lst > ", lst_cmdlist);
2984 return Parser_execarg(argc - 1, argv + 1, lst_cmdlist);