2 * -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
3 * vim:expandtab:shiftwidth=8:tabstop=8:
7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 only,
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License version 2 for more details (a copy is included
17 * in the LICENSE file that accompanied this code).
19 * You should have received a copy of the GNU General Public License
20 * version 2 along with this program; If not, see [sun.com URL with a
23 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24 * CA 95054 USA or visit www.sun.com if you need additional information or
30 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
31 * Use is subject to license terms.
34 * This file is part of Lustre, http://www.lustre.org/
35 * Lustre is a trademark of Sun Microsystems, Inc.
37 * lnet/selftest/conctl.c
39 * Author: Liang Zhen <liangzhen@clusterfs.com>
50 #include <lnet/lnetctl.h>
51 #include <lnet/lnetst.h>
54 static command_t lst_cmdlist[];
55 static lst_sid_t session_id;
56 static int session_key;
57 static lstcon_trans_stat_t trans_stat;
59 typedef struct list_string {
60 struct list_string *lstr_next;
65 #define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
67 static int alloc_count = 0;
68 static int alloc_nob = 0;
73 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
76 fprintf(stderr, "Can't allocate lstr\n");
83 lstr->lstr_str[0] = 0;
89 free_lstr(lstr_t *lstr)
92 alloc_nob -= lstr->lstr_sz;
97 free_lstrs(lstr_t **list)
101 while ((lstr = *list) != NULL) {
102 *list = lstr->lstr_next;
108 new_lstrs(lstr_t **list, char *prefix, char *postfix,
109 int lo, int hi, int stride)
111 int n1 = strlen(prefix);
112 int n2 = strlen(postfix);
113 int sz = n1 + 20 + n2 + 1;
116 lstr_t *n = alloc_lstr(sz);
118 snprintf(n->lstr_str, sz - 1, "%s%u%s",
119 prefix, lo, postfix);
121 n->lstr_next = *list;
129 expand_lstr(lstr_t **list, lstr_t *l)
131 int nob = strlen(l->lstr_str);
141 b1 = strchr(l->lstr_str, '[');
143 l->lstr_next = *list;
148 b2 = strchr(b1, ']');
149 if (b2 == NULL || b2 == b1 + 1)
157 sep = strchr(expr, ',');
163 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
165 new_lstrs(list, l->lstr_str, b2, x, x, 1);
170 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
173 new_lstrs(list, l->lstr_str, b2, x, y, 1);
178 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
181 new_lstrs(list, l->lstr_str, b2, x, y, z);
187 } while ((expr = sep) != NULL);
195 expand_strs(char *str, lstr_t **head)
203 l = alloc_lstr(strlen(str) + 1);
204 memcpy(l->lstr_str, str, strlen(str) + 1);
212 while ((l = list) != NULL) {
215 rc = expand_lstr(&nlist, l);
217 fprintf(stderr, "Syntax error in \"%s\"\n", str);
225 /* re-order onto 'list' */
226 while ((l = nlist) != NULL) {
227 nlist = l->lstr_next;
232 } while (expanded && rc > 0);
239 while ((l = list) != NULL) {
248 lst_parse_nids(char *str, int *countp, lnet_process_id_t **idspp)
256 rc = expand_strs(str, &head);
266 *idspp = malloc(c * sizeof(lnet_process_id_t));
267 if (*idspp == NULL) {
268 fprintf(stderr, "Out of memory\n");
275 while ((l = head) != NULL) {
279 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
280 if ((*idspp)[i].nid == LNET_NID_ANY) {
281 fprintf(stderr, "Invalid nid: %s\n",
286 (*idspp)[i].pid = LUSTRE_LNET_PID;
303 lst_node_state2str(int state)
305 if (state == LST_NODE_ACTIVE)
307 if (state == LST_NODE_BUSY)
309 if (state == LST_NODE_DOWN)
316 lst_node_str2state(char *str)
318 if (strcasecmp(str, "active") == 0)
319 return LST_NODE_ACTIVE;
320 if (strcasecmp(str, "busy") == 0)
321 return LST_NODE_BUSY;
322 if (strcasecmp(str, "down") == 0)
323 return LST_NODE_DOWN;
324 if (strcasecmp(str, "unknown") == 0)
325 return LST_NODE_UNKNOWN;
326 if (strcasecmp(str, "invalid") == 0)
327 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
333 lst_test_type2name(int type)
335 if (type == LST_TEST_PING)
337 if (type == LST_TEST_BULK)
344 lst_test_name2type(char *name)
346 if (strcasecmp(name, "ping") == 0)
347 return LST_TEST_PING;
348 if (strcasecmp(name, "brw") == 0)
349 return LST_TEST_BULK;
355 lst_print_usage(char *cmd)
357 Parser_printhelp(cmd);
361 lst_print_error(char *sub, const char *def_format, ...)
365 /* local error returned from kernel */
368 fprintf(stderr, "No session exists\n");
371 fprintf(stderr, "Session is shutting down\n");
374 fprintf(stderr, "Unmatched session key or not root\n");
377 fprintf(stderr, "Can't find %s in current session\n", sub);
380 fprintf(stderr, "Invalid parameters list in command line\n");
383 fprintf(stderr, "Bad parameter address\n");
386 fprintf(stderr, "%s already exists\n", sub);
389 va_start(ap, def_format);
390 vfprintf(stderr, def_format, ap);
398 lst_free_rpcent(struct list_head *head)
400 lstcon_rpc_ent_t *ent;
402 while (!list_empty(head)) {
403 ent = list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
405 list_del(&ent->rpe_link);
411 lst_reset_rpcent(struct list_head *head)
413 lstcon_rpc_ent_t *ent;
415 list_for_each_entry(ent, head, rpe_link) {
416 ent->rpe_sid = LST_INVALID_SID;
417 ent->rpe_peer.nid = LNET_NID_ANY;
418 ent->rpe_peer.pid = LNET_PID_ANY;
419 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
424 lst_alloc_rpcent(struct list_head *head, int count, int offset)
426 lstcon_rpc_ent_t *ent;
429 for (i = 0; i < count; i++) {
430 ent = malloc(offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
432 lst_free_rpcent(head);
436 memset(ent, 0, offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
438 ent->rpe_sid = LST_INVALID_SID;
439 ent->rpe_peer.nid = LNET_NID_ANY;
440 ent->rpe_peer.pid = LNET_PID_ANY;
441 list_add(&ent->rpe_link, head);
448 lst_print_transerr(struct list_head *head, char *optstr)
450 lstcon_rpc_ent_t *ent;
452 list_for_each_entry(ent, head, rpe_link) {
453 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
456 if (ent->rpe_rpc_errno != 0) {
457 fprintf(stderr, "%s RPC failed on %s: %s\n",
458 optstr, libcfs_id2str(ent->rpe_peer),
459 strerror(ent->rpe_rpc_errno));
463 fprintf(stderr, "%s failed on %s: %s\n",
464 optstr, libcfs_id2str(ent->rpe_peer),
465 strerror(ent->rpe_fwk_errno));
469 int lst_info_batch_ioctl(char *batch, int test, int server,
470 lstcon_test_batch_ent_t *entp, int *idxp,
471 int *ndentp, lstcon_node_ent_t *dentsp);
473 int lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
474 int *idx, int *count, lstcon_node_ent_t *dents);
476 int lst_query_batch_ioctl(char *batch, int test, int server,
477 int timeout, struct list_head *head);
480 lst_ioctl(unsigned int opc, void *buf, int len)
482 struct libcfs_ioctl_data data;
485 LIBCFS_IOC_INIT (data);
486 data.ioc_u32[0] = opc;
487 data.ioc_plen1 = len;
488 data.ioc_pbuf1 = (char *)buf;
489 data.ioc_plen2 = sizeof(trans_stat);
490 data.ioc_pbuf2 = (char *)&trans_stat;
492 memset(&trans_stat, 0, sizeof(trans_stat));
494 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
496 /* local error, no valid RPC result */
501 if (trans_stat.trs_rpc_errno != 0)
504 /* Framework error */
505 if (trans_stat.trs_fwk_errno != 0)
512 lst_new_session_ioctl (char *name, int timeout, int force, lst_sid_t *sid)
514 lstio_session_new_args_t args = {
515 .lstio_ses_key = session_key,
516 .lstio_ses_timeout = timeout,
517 .lstio_ses_force = force,
518 .lstio_ses_idp = sid,
519 .lstio_ses_namep = name,
520 .lstio_ses_nmlen = strlen(name),
523 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
527 jt_lst_new_session(int argc, char **argv)
529 char buf[LST_NAME_SIZE];
537 static struct option session_opts[] =
539 {"timeout", required_argument, 0, 't' },
540 {"force", no_argument, 0, 'f' },
544 if (session_key == 0) {
546 "Can't find env LST_SESSION or value is not valid\n");
552 c = getopt_long(argc, argv, "ft:",
553 session_opts, &optidx);
563 timeout = atoi(optarg);
566 lst_print_usage(argv[0]);
572 fprintf(stderr, "Invalid timeout value\n");
576 if (optind == argc - 1) {
577 name = argv[optind ++];
578 if (strlen(name) >= LST_NAME_SIZE) {
579 fprintf(stderr, "Name size is limited to %d\n",
584 } else if (optind == argc) {
585 char user[LST_NAME_SIZE];
586 char host[LST_NAME_SIZE];
587 struct passwd *pw = getpwuid(getuid());
590 snprintf(user, sizeof(user), "%d", (int)getuid());
592 snprintf(user, sizeof(user), "%s", pw->pw_name);
594 rc = gethostname(host, sizeof(host));
596 snprintf(host, sizeof(host), "unknown_host");
598 snprintf(buf, LST_NAME_SIZE, "%s@%s", user, host);
602 lst_print_usage(argv[0]);
606 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
609 lst_print_error("session", "Failed to create session: %s\n",
614 fprintf(stdout, "SESSION: %s TIMEOUT: %d FORCE: %s\n",
615 name, timeout, force ? "Yes": "No");
621 lst_session_info_ioctl(char *name, int len, int *key,
622 lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
624 lstio_session_info_args_t args = {
625 .lstio_ses_keyp = key,
626 .lstio_ses_idp = sid,
627 .lstio_ses_ndinfo = ndinfo,
628 .lstio_ses_nmlen = len,
629 .lstio_ses_namep = name,
632 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
636 jt_lst_show_session(int argc, char **argv)
638 lstcon_ndlist_ent_t ndinfo;
640 char name[LST_NAME_SIZE];
644 rc = lst_session_info_ioctl(name, LST_NAME_SIZE, &key, &sid, &ndinfo);
647 lst_print_error("session", "Failed to show session: %s\n",
652 fprintf(stdout, "%s ID: %Lu@%s, KEY: %d NODES: %d\n",
653 name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
654 key, ndinfo.nle_nnode);
660 lst_end_session_ioctl(void)
662 lstio_session_end_args_t args = {
663 .lstio_ses_key = session_key,
666 return lst_ioctl (LSTIO_SESSION_END, &args, sizeof(args));
670 jt_lst_end_session(int argc, char **argv)
674 if (session_key == 0) {
676 "Can't find env LST_SESSION or value is not valid\n");
680 rc = lst_end_session_ioctl();
683 fprintf(stdout, "session is ended\n");
688 lst_print_error("session", "Failed to end session: %s\n",
693 if (trans_stat.trs_rpc_errno != 0) {
695 "[RPC] Failed to send %d session RPCs: %s\n",
696 lstcon_rpc_stat_failure(&trans_stat, 0),
697 strerror(trans_stat.trs_rpc_errno));
700 if (trans_stat.trs_fwk_errno != 0) {
702 "[FWK] Failed to end session on %d nodes: %s\n",
703 lstcon_sesop_stat_failure(&trans_stat, 0),
704 strerror(trans_stat.trs_fwk_errno));
711 lst_ping_ioctl(char *str, int type, int timeout,
712 int count, lnet_process_id_t *ids, struct list_head *head)
714 lstio_debug_args_t args = {
715 .lstio_dbg_key = session_key,
716 .lstio_dbg_type = type,
717 .lstio_dbg_flags = 0,
718 .lstio_dbg_timeout = timeout,
719 .lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str),
720 .lstio_dbg_namep = str,
721 .lstio_dbg_count = count,
722 .lstio_dbg_idsp = ids,
723 .lstio_dbg_resultp = head,
726 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
730 lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
732 char buf[LST_NAME_SIZE];
733 lstcon_test_batch_ent_t ent;
734 lstcon_ndlist_ent_t *entp = &ent.tbe_cli_nle;
740 case LST_OPC_SESSION:
741 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
745 case LST_OPC_BATCHSRV:
746 entp = &ent.tbe_srv_nle;
747 case LST_OPC_BATCHCLI:
748 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
752 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
756 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
765 *countp = entp->nle_nnode;
771 jt_lst_ping(int argc, char **argv)
773 struct list_head head;
774 lnet_process_id_t *ids = NULL;
775 lstcon_rpc_ent_t *ent = NULL;
785 static struct option ping_opts[] =
787 {"session", no_argument, 0, 's' },
788 {"server", no_argument, 0, 'v' },
789 {"batch", required_argument, 0, 'b' },
790 {"group", required_argument, 0, 'g' },
791 {"nodes", required_argument, 0, 'n' },
792 {"timeout", required_argument, 0, 't' },
796 if (session_key == 0) {
798 "Can't find env LST_SESSION or value is not valid\n");
804 c = getopt_long(argc, argv, "g:b:n:t:sv",
812 type = LST_OPC_SESSION;
816 type = LST_OPC_GROUP;
821 type = LST_OPC_BATCHCLI;
826 type = LST_OPC_NODES;
831 timeout = atoi(optarg);
839 lst_print_usage(argv[0]);
844 if (type == 0 || timeout <= 0 || optind != argc) {
845 lst_print_usage(argv[0]);
849 if (type == LST_OPC_BATCHCLI && server)
850 type = LST_OPC_BATCHSRV;
852 rc = lst_get_node_count(type, str, &count, &ids);
854 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
855 (str == NULL) ? "session" : str, strerror(errno));
859 CFS_INIT_LIST_HEAD(&head);
861 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
863 fprintf(stderr, "Out of memory\n");
868 fprintf(stdout, "Target %s is empty\n",
869 (str == NULL) ? "session" : str);
873 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
874 if (rc == -1) { /* local failure */
875 lst_print_error("debug", "Failed to ping %s: %s\n",
876 (str == NULL) ? "session" : str,
882 /* ignore RPC errors and framwork errors */
883 list_for_each_entry(ent, &head, rpe_link) {
884 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
885 libcfs_id2str(ent->rpe_peer),
886 lst_node_state2str(ent->rpe_state),
887 (ent->rpe_state == LST_NODE_ACTIVE ||
888 ent->rpe_state == LST_NODE_BUSY)?
889 (ent->rpe_rpc_errno == 0 ?
890 &ent->rpe_payload[0] : "Unknown") :
891 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
895 lst_free_rpcent(&head);
905 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
906 struct list_head *resultp)
908 lstio_group_nodes_args_t args = {
909 .lstio_grp_key = session_key,
910 .lstio_grp_nmlen = strlen(name),
911 .lstio_grp_namep = name,
912 .lstio_grp_count = count,
913 .lstio_grp_idsp = ids,
914 .lstio_grp_resultp = resultp,
917 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
921 lst_add_group_ioctl (char *name)
923 lstio_group_add_args_t args = {
924 .lstio_grp_key = session_key,
925 .lstio_grp_nmlen = strlen(name),
926 .lstio_grp_namep = name,
929 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
933 jt_lst_add_group(int argc, char **argv)
935 struct list_head head;
936 lnet_process_id_t *ids;
942 if (session_key == 0) {
944 "Can't find env LST_SESSION or value is not valid\n");
949 lst_print_usage(argv[0]);
954 if (strlen(name) >= LST_NAME_SIZE) {
955 fprintf(stderr, "Name length is limited to %d\n",
960 rc = lst_add_group_ioctl(name);
962 lst_print_error("group", "Failed to add group %s: %s\n",
963 name, strerror(errno));
967 CFS_INIT_LIST_HEAD(&head);
969 for (i = 2; i < argc; i++) {
970 /* parse address list */
971 rc = lst_parse_nids(argv[i], &count, &ids);
973 fprintf(stderr, "Ignore invalid id list %s\n",
981 rc = lst_alloc_rpcent(&head, count, 0);
983 fprintf(stderr, "Out of memory\n");
987 rc = lst_add_nodes_ioctl(name, count, ids, &head);
992 lst_free_rpcent(&head);
993 fprintf(stderr, "%s are added to session\n", argv[i]);
998 lst_free_rpcent(&head);
999 lst_print_error("group", "Failed to add nodes %s: %s\n",
1000 argv[i], strerror(errno));
1004 lst_print_transerr(&head, "create session");
1005 lst_free_rpcent(&head);
1012 lst_del_group_ioctl (char *name)
1014 lstio_group_del_args_t args = {
1015 .lstio_grp_key = session_key,
1016 .lstio_grp_nmlen = strlen(name),
1017 .lstio_grp_namep = name,
1020 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
1024 jt_lst_del_group(int argc, char **argv)
1028 if (session_key == 0) {
1030 "Can't find env LST_SESSION or value is not valid\n");
1035 lst_print_usage(argv[0]);
1039 rc = lst_del_group_ioctl(argv[1]);
1041 fprintf(stdout, "Group is deleted\n");
1046 lst_print_error("group", "Failed to delete group: %s\n",
1051 fprintf(stderr, "Group is deleted with some errors\n");
1053 if (trans_stat.trs_rpc_errno != 0) {
1054 fprintf(stderr, "[RPC] Failed to send %d end session RPCs: %s\n",
1055 lstcon_rpc_stat_failure(&trans_stat, 0),
1056 strerror(trans_stat.trs_rpc_errno));
1059 if (trans_stat.trs_fwk_errno != 0) {
1061 "[FWK] Failed to end session on %d nodes: %s\n",
1062 lstcon_sesop_stat_failure(&trans_stat, 0),
1063 strerror(trans_stat.trs_fwk_errno));
1070 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1071 lnet_process_id_t *ids, struct list_head *resultp)
1073 lstio_group_update_args_t args = {
1074 .lstio_grp_key = session_key,
1075 .lstio_grp_opc = opc,
1076 .lstio_grp_args = clean,
1077 .lstio_grp_nmlen = strlen(name),
1078 .lstio_grp_namep = name,
1079 .lstio_grp_count = count,
1080 .lstio_grp_idsp = ids,
1081 .lstio_grp_resultp = resultp,
1084 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1088 jt_lst_update_group(int argc, char **argv)
1090 struct list_head head;
1091 lnet_process_id_t *ids = NULL;
1101 static struct option update_group_opts[] =
1103 {"refresh", no_argument, 0, 'f' },
1104 {"clean", required_argument, 0, 'c' },
1105 {"remove", required_argument, 0, 'r' },
1109 if (session_key == 0) {
1111 "Can't find env LST_SESSION or value is not valid\n");
1116 c = getopt_long(argc, argv, "fc:r:",
1117 update_group_opts, &optidx);
1119 /* Detect the end of the options. */
1126 lst_print_usage(argv[0]);
1129 opc = LST_GROUP_REFRESH;
1134 lst_print_usage(argv[0]);
1137 opc = LST_GROUP_RMND;
1142 clean = lst_node_str2state(optarg);
1143 if (opc != 0 || clean <= 0) {
1144 lst_print_usage(argv[0]);
1147 opc = LST_GROUP_CLEAN;
1151 lst_print_usage(argv[0]);
1156 /* no OPC or group is specified */
1157 if (opc == 0 || optind != argc - 1) {
1158 lst_print_usage(argv[0]);
1164 CFS_INIT_LIST_HEAD(&head);
1166 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1167 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1169 opc == LST_GROUP_RMND ? str : grp,
1173 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1174 opc == LST_GROUP_RMND ? str : grp,
1179 rc = lst_alloc_rpcent(&head, count, 0);
1181 fprintf(stderr, "Out of memory\n");
1188 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1194 lst_free_rpcent(&head);
1199 lst_free_rpcent(&head);
1200 lst_print_error("group", "Failed to update group: %s\n",
1205 lst_print_transerr(&head, "Updating group");
1207 lst_free_rpcent(&head);
1213 lst_list_group_ioctl(int len, char *name, int idx)
1215 lstio_group_list_args_t args = {
1216 .lstio_grp_key = session_key,
1217 .lstio_grp_idx = idx,
1218 .lstio_grp_nmlen = len,
1219 .lstio_grp_namep = name,
1222 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1226 lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
1227 int *idx, int *count, lstcon_node_ent_t *dents)
1229 lstio_group_info_args_t args = {
1230 .lstio_grp_key = session_key,
1231 .lstio_grp_nmlen = strlen(name),
1232 .lstio_grp_namep = name,
1233 .lstio_grp_entp = gent,
1234 .lstio_grp_idxp = idx,
1235 .lstio_grp_ndentp = count,
1236 .lstio_grp_dentsp = dents,
1239 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1243 lst_list_group_all(void)
1245 char name[LST_NAME_SIZE];
1249 /* no group is specified, list name of all groups */
1250 for (i = 0; ; i++) {
1251 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1253 fprintf(stdout, "%d) %s\n", i + 1, name);
1257 if (errno == ENOENT)
1260 lst_print_error("group", "Failed to list group: %s\n",
1265 fprintf(stdout, "Total %d groups\n", i);
1270 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1273 jt_lst_list_group(int argc, char **argv)
1275 lstcon_ndlist_ent_t gent;
1276 lstcon_node_ent_t *dents;
1291 static struct option list_group_opts[] =
1293 {"active", no_argument, 0, 'a' },
1294 {"busy", no_argument, 0, 'b' },
1295 {"down", no_argument, 0, 'd' },
1296 {"unknown", no_argument, 0, 'u' },
1297 {"all", no_argument, 0, 'l' },
1301 if (session_key == 0) {
1303 "Can't find env LST_SESSION or value is not valid\n");
1308 c = getopt_long(argc, argv, "abdul",
1309 list_group_opts, &optidx);
1316 verbose = active = 1;
1328 verbose = unknown = 1;
1335 lst_print_usage(argv[0]);
1340 if (optind == argc) {
1341 /* no group is specified, list name of all groups */
1342 rc = lst_list_group_all();
1348 fprintf(stdout, LST_NODES_TITLE);
1350 /* list nodes in specified groups */
1351 for (i = optind; i < argc; i++) {
1352 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1354 if (errno == ENOENT) {
1359 lst_print_error("group", "Failed to list group\n",
1365 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1366 gent.nle_nactive, gent.nle_nbusy,
1367 gent.nle_ndown, gent.nle_nunknown,
1368 gent.nle_nnode, argv[i]);
1372 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1374 if (gent.nle_nnode == 0) {
1375 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1379 count = gent.nle_nnode;
1381 dents = malloc(count * sizeof(lstcon_node_ent_t));
1382 if (dents == NULL) {
1383 fprintf(stderr, "Failed to malloc: %s\n",
1389 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1391 lst_print_error("group", "Failed to list group: %s\n",
1397 for (j = 0, c = 0; j < count; j++) {
1399 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1400 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1401 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1402 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1404 fprintf(stdout, "\t%s: %s\n",
1405 libcfs_id2str(dents[j].nde_id),
1406 lst_node_state2str(dents[j].nde_state));
1411 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1420 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
1421 int timeout, struct list_head *resultp)
1423 lstio_stat_args_t args = {
1424 .lstio_sta_key = session_key,
1425 .lstio_sta_timeout = timeout,
1426 .lstio_sta_nmlen = strlen(name),
1427 .lstio_sta_namep = name,
1428 .lstio_sta_count = count,
1429 .lstio_sta_idsp = idsp,
1430 .lstio_sta_resultp = resultp,
1433 return lst_ioctl (LSTIO_STAT_QUERY, &args, sizeof(args));
1437 struct list_head srp_link;
1440 lnet_process_id_t *srp_ids;
1441 struct list_head srp_result[2];
1442 } lst_stat_req_param_t;
1445 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1449 for (i = 0; i < 2; i++)
1450 lst_free_rpcent(&srp->srp_result[i]);
1452 if (srp->srp_ids != NULL)
1459 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
1461 lst_stat_req_param_t *srp = NULL;
1462 int count = save_old ? 2 : 1;
1466 srp = malloc(sizeof(*srp));
1470 memset(srp, 0, sizeof(*srp));
1471 CFS_INIT_LIST_HEAD(&srp->srp_result[0]);
1472 CFS_INIT_LIST_HEAD(&srp->srp_result[1]);
1474 rc = lst_get_node_count(LST_OPC_GROUP, name,
1475 &srp->srp_count, NULL);
1476 if (rc != 0 && errno == ENOENT) {
1477 rc = lst_get_node_count(LST_OPC_NODES, name,
1478 &srp->srp_count, &srp->srp_ids);
1483 "Failed to get count of nodes from %s: %s\n",
1484 name, strerror(errno));
1485 lst_stat_req_param_free(srp);
1490 srp->srp_name = name;
1492 for (i = 0; i < count; i++) {
1493 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1494 sizeof(sfw_counters_t) +
1495 sizeof(srpc_counters_t) +
1496 sizeof(lnet_counters_t));
1498 fprintf(stderr, "Out of memory\n");
1508 lst_stat_req_param_free(srp);
1515 } lst_srpc_stat_result;
1517 #define LST_LNET_AVG 0
1518 #define LST_LNET_MIN 1
1519 #define LST_LNET_MAX 2
1522 float lnet_avg_sndrate;
1523 float lnet_min_sndrate;
1524 float lnet_max_sndrate;
1525 float lnet_total_sndrate;
1527 float lnet_avg_rcvrate;
1528 float lnet_min_rcvrate;
1529 float lnet_max_rcvrate;
1530 float lnet_total_rcvrate;
1532 float lnet_avg_sndperf;
1533 float lnet_min_sndperf;
1534 float lnet_max_sndperf;
1535 float lnet_total_sndperf;
1537 float lnet_avg_rcvperf;
1538 float lnet_min_rcvperf;
1539 float lnet_max_rcvperf;
1540 float lnet_total_rcvperf;
1542 int lnet_stat_count;
1543 } lst_lnet_stat_result_t;
1545 lst_lnet_stat_result_t lnet_stat_result;
1548 lst_lnet_stat_value(int bw, int send, int off)
1552 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1553 &lnet_stat_result.lnet_avg_sndrate;
1564 lst_timeval_diff(struct timeval *tv1,
1565 struct timeval *tv2, struct timeval *df)
1567 if (tv1->tv_usec >= tv2->tv_usec) {
1568 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1569 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1573 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1574 df->tv_usec = tv1->tv_sec + 1000000 - tv2->tv_usec;
1580 lst_cal_lnet_stat(float delta, lnet_counters_t *lnet_new,
1581 lnet_counters_t *lnet_old)
1586 perf = (float)(lnet_new->send_length -
1587 lnet_old->send_length) / (1024 * 1024) / delta;
1588 lnet_stat_result.lnet_total_sndperf += perf;
1590 if (lnet_stat_result.lnet_min_sndperf > perf ||
1591 lnet_stat_result.lnet_min_sndperf == 0)
1592 lnet_stat_result.lnet_min_sndperf = perf;
1594 if (lnet_stat_result.lnet_max_sndperf < perf)
1595 lnet_stat_result.lnet_max_sndperf = perf;
1597 perf = (float)(lnet_new->recv_length -
1598 lnet_old->recv_length) / (1024 * 1024) / delta;
1599 lnet_stat_result.lnet_total_rcvperf += perf;
1601 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1602 lnet_stat_result.lnet_min_rcvperf == 0)
1603 lnet_stat_result.lnet_min_rcvperf = perf;
1605 if (lnet_stat_result.lnet_max_rcvperf < perf)
1606 lnet_stat_result.lnet_max_rcvperf = perf;
1608 rate = (lnet_new->send_count - lnet_old->send_count) / delta;
1609 lnet_stat_result.lnet_total_sndrate += rate;
1611 if (lnet_stat_result.lnet_min_sndrate > rate ||
1612 lnet_stat_result.lnet_min_sndrate == 0)
1613 lnet_stat_result.lnet_min_sndrate = rate;
1615 if (lnet_stat_result.lnet_max_sndrate < rate)
1616 lnet_stat_result.lnet_max_sndrate = rate;
1618 rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
1619 lnet_stat_result.lnet_total_rcvrate += rate;
1621 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1622 lnet_stat_result.lnet_min_rcvrate == 0)
1623 lnet_stat_result.lnet_min_rcvrate = rate;
1625 if (lnet_stat_result.lnet_max_rcvrate < rate)
1626 lnet_stat_result.lnet_max_rcvrate = rate;
1628 lnet_stat_result.lnet_stat_count ++;
1630 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1631 lnet_stat_result.lnet_stat_count;
1632 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1633 lnet_stat_result.lnet_stat_count;
1635 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1636 lnet_stat_result.lnet_stat_count;
1637 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1638 lnet_stat_result.lnet_stat_count;
1643 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
1652 if (lnet_stat_result.lnet_stat_count == 0)
1655 if (bwrt == 1) /* bw only */
1658 if (bwrt == 2) /* rates only */
1661 if (rdwr == 1) /* recv only */
1664 if (rdwr == 2) /* send only */
1667 for (i = start1; i <= end1; i++) {
1668 fprintf(stdout, "[LNet %s of %s]\n",
1669 i == 0 ? "Rates" : "Bandwidth", name);
1671 for (j = start2; j <= end2; j++) {
1672 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
1674 if ((type & 1) != 0) {
1675 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1676 "Avg: %-8.2f MB/s ",
1677 lst_lnet_stat_value(i, j, 0));
1680 if ((type & 2) != 0) {
1681 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1682 "Min: %-8.2f MB/s ",
1683 lst_lnet_stat_value(i, j, 1));
1686 if ((type & 4) != 0) {
1687 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1689 lst_lnet_stat_value(i, j, 2));
1692 fprintf(stdout, "\n");
1698 lst_print_stat(char *name, struct list_head *resultp,
1699 int idx, int lnet, int bwrt, int rdwr, int type)
1701 struct list_head tmp[2];
1702 lstcon_rpc_ent_t *new;
1703 lstcon_rpc_ent_t *old;
1704 sfw_counters_t *sfwk_new;
1705 sfw_counters_t *sfwk_old;
1706 srpc_counters_t *srpc_new;
1707 srpc_counters_t *srpc_old;
1708 lnet_counters_t *lnet_new;
1709 lnet_counters_t *lnet_old;
1714 CFS_INIT_LIST_HEAD(&tmp[0]);
1715 CFS_INIT_LIST_HEAD(&tmp[1]);
1717 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1719 while (!list_empty(&resultp[idx])) {
1720 if (list_empty(&resultp[1 - idx])) {
1721 fprintf(stderr, "Group is changed, re-run stat\n");
1725 new = list_entry(resultp[idx].next, lstcon_rpc_ent_t, rpe_link);
1726 old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t, rpe_link);
1728 /* first time get stats result, can't calculate diff */
1729 if (new->rpe_peer.nid == LNET_NID_ANY)
1732 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1733 new->rpe_peer.pid != old->rpe_peer.pid) {
1734 /* Something wrong. i.e, somebody change the group */
1738 list_del(&new->rpe_link);
1739 list_add_tail(&new->rpe_link, &tmp[idx]);
1741 list_del(&old->rpe_link);
1742 list_add_tail(&old->rpe_link, &tmp[1 - idx]);
1744 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1745 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1750 sfwk_new = (sfw_counters_t *)&new->rpe_payload[0];
1751 sfwk_old = (sfw_counters_t *)&old->rpe_payload[0];
1753 srpc_new = (srpc_counters_t *)((char *)sfwk_new + sizeof(*sfwk_new));
1754 srpc_old = (srpc_counters_t *)((char *)sfwk_old + sizeof(*sfwk_old));
1756 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
1757 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
1759 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1761 delta = tv.tv_sec + (float)tv.tv_usec/1000000;
1763 if (!lnet) /* TODO */
1766 lst_cal_lnet_stat(delta, lnet_new, lnet_old);
1769 list_splice(&tmp[idx], &resultp[idx]);
1770 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1773 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1775 if (!lnet) /* TODO */
1778 lst_print_lnet_stat(name, bwrt, rdwr, type);
1782 jt_lst_stat(int argc, char **argv)
1784 struct list_head head;
1785 lst_stat_req_param_t *srp;
1788 int timeout = 5; /* default timeout, 5 sec */
1789 int delay = 5; /* default delay, 5 sec */
1790 int lnet = 1; /* lnet stat by default */
1798 static struct option stat_opts[] =
1800 {"timeout", required_argument, 0, 't' },
1801 {"delay" , required_argument, 0, 'd' },
1802 {"lnet" , no_argument, 0, 'l' },
1803 {"rpc" , no_argument, 0, 'c' },
1804 {"bw" , no_argument, 0, 'b' },
1805 {"rate" , no_argument, 0, 'a' },
1806 {"read" , no_argument, 0, 'r' },
1807 {"write" , no_argument, 0, 'w' },
1808 {"avg" , no_argument, 0, 'g' },
1809 {"min" , no_argument, 0, 'n' },
1810 {"max" , no_argument, 0, 'x' },
1814 if (session_key == 0) {
1816 "Can't find env LST_SESSION or value is not valid\n");
1821 c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
1828 timeout = atoi(optarg);
1831 delay = atoi(optarg);
1873 lst_print_usage(argv[0]);
1878 if (optind == argc) {
1879 lst_print_usage(argv[0]);
1883 if (timeout <= 0 || delay <= 0) {
1884 fprintf(stderr, "Invalid timeout or delay value\n");
1888 CFS_INIT_LIST_HEAD(&head);
1890 while (optind < argc) {
1891 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
1895 list_add_tail(&srp->srp_link, &head);
1899 time_t now = time(NULL);
1901 if (now - last < delay) {
1902 sleep(delay - now + last);
1908 list_for_each_entry(srp, &head, srp_link) {
1909 rc = lst_stat_ioctl(srp->srp_name,
1910 srp->srp_count, srp->srp_ids,
1911 timeout, &srp->srp_result[idx]);
1913 lst_print_error("stat", "Failed to stat %s: %s\n",
1914 srp->srp_name, strerror(errno));
1918 lst_print_stat(srp->srp_name, srp->srp_result,
1919 idx, lnet, bwrt, rdwr, type);
1921 lst_reset_rpcent(&srp->srp_result[1 - idx]);
1928 while (!list_empty(&head)) {
1929 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
1931 list_del(&srp->srp_link);
1932 lst_stat_req_param_free(srp);
1939 jt_lst_show_error(int argc, char **argv)
1941 struct list_head head;
1942 lst_stat_req_param_t *srp;
1943 lstcon_rpc_ent_t *ent;
1944 sfw_counters_t *sfwk;
1945 srpc_counters_t *srpc;
1946 lnet_counters_t *lnet;
1953 static struct option show_error_opts[] =
1955 {"session", no_argument, 0, 's' },
1959 if (session_key == 0) {
1961 "Can't find env LST_SESSION or value is not valid\n");
1966 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
1977 lst_print_usage(argv[0]);
1982 if (optind == argc) {
1983 lst_print_usage(argv[0]);
1987 CFS_INIT_LIST_HEAD(&head);
1989 while (optind < argc) {
1990 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
1994 list_add_tail(&srp->srp_link, &head);
1997 list_for_each_entry(srp, &head, srp_link) {
1998 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
1999 srp->srp_ids, 5, &srp->srp_result[0]);
2002 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2003 srp->srp_name, strerror(errno));
2007 fprintf(stdout, "%s:\n", srp->srp_name);
2011 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2012 if (ent->rpe_rpc_errno != 0) {
2014 fprintf(stderr, "RPC failure, can't show error on %s\n",
2015 libcfs_id2str(ent->rpe_peer));
2019 if (ent->rpe_fwk_errno != 0) {
2021 fprintf(stderr, "Framework failure, can't show error on %s\n",
2022 libcfs_id2str(ent->rpe_peer));
2026 sfwk = (sfw_counters_t *)&ent->rpe_payload[0];
2027 srpc = (srpc_counters_t *)((char *)sfwk + sizeof(*sfwk));
2028 lnet = (lnet_counters_t *)((char *)srpc + sizeof(*srpc));
2030 if (srpc->errors == 0 &&
2031 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2035 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2040 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2041 libcfs_id2str(ent->rpe_peer),
2042 sfwk->brw_errors, sfwk->ping_errors,
2043 show_rpc ? ' ' : '\n');
2048 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2049 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2052 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2055 while (!list_empty(&head)) {
2056 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2058 list_del(&srp->srp_link);
2059 lst_stat_req_param_free(srp);
2066 lst_add_batch_ioctl (char *name)
2068 lstio_batch_add_args_t args = {
2069 .lstio_bat_key = session_key,
2070 .lstio_bat_nmlen = strlen(name),
2071 .lstio_bat_namep = name,
2074 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2078 jt_lst_add_batch(int argc, char **argv)
2083 if (session_key == 0) {
2085 "Can't find env LST_SESSION or value is not valid\n");
2090 lst_print_usage(argv[0]);
2095 if (strlen(name) >= LST_NAME_SIZE) {
2096 fprintf(stderr, "Name length is limited to %d\n",
2101 rc = lst_add_batch_ioctl(name);
2105 lst_print_error("batch", "Failed to create batch: %s\n",
2112 lst_start_batch_ioctl (char *name, int timeout, struct list_head *resultp)
2114 lstio_batch_run_args_t args = {
2115 .lstio_bat_key = session_key,
2116 .lstio_bat_timeout = timeout,
2117 .lstio_bat_nmlen = strlen(name),
2118 .lstio_bat_namep = name,
2119 .lstio_bat_resultp = resultp,
2122 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2126 jt_lst_start_batch(int argc, char **argv)
2128 struct list_head head;
2136 static struct option start_batch_opts[] =
2138 {"timeout", required_argument, 0, 't' },
2142 if (session_key == 0) {
2144 "Can't find env LST_SESSION or value is not valid\n");
2149 c = getopt_long(argc, argv, "t:",
2150 start_batch_opts, &optidx);
2152 /* Detect the end of the options. */
2158 timeout = atoi(optarg);
2161 lst_print_usage(argv[0]);
2166 if (optind == argc) {
2167 batch = LST_DEFAULT_BATCH;
2169 } else if (optind == argc - 1) {
2170 batch = argv[optind];
2173 lst_print_usage(argv[0]);
2177 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2179 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2180 batch, strerror(errno));
2184 CFS_INIT_LIST_HEAD(&head);
2186 rc = lst_alloc_rpcent(&head, count, 0);
2188 fprintf(stderr, "Out of memory\n");
2192 rc = lst_start_batch_ioctl(batch, timeout, &head);
2195 fprintf(stdout, "%s is running now\n", batch);
2196 lst_free_rpcent(&head);
2201 lst_print_error("batch", "Failed to start batch: %s\n",
2203 lst_free_rpcent(&head);
2207 lst_print_transerr(&head, "Run batch");
2209 lst_free_rpcent(&head);
2215 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2217 lstio_batch_stop_args_t args = {
2218 .lstio_bat_key = session_key,
2219 .lstio_bat_force = force,
2220 .lstio_bat_nmlen = strlen(name),
2221 .lstio_bat_namep = name,
2222 .lstio_bat_resultp = resultp,
2225 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2229 jt_lst_stop_batch(int argc, char **argv)
2231 struct list_head head;
2239 static struct option stop_batch_opts[] =
2241 {"force", no_argument, 0, 'f' },
2245 if (session_key == 0) {
2247 "Can't find env LST_SESSION or value is not valid\n");
2252 c = getopt_long(argc, argv, "f",
2253 stop_batch_opts, &optidx);
2255 /* Detect the end of the options. */
2264 lst_print_usage(argv[0]);
2269 if (optind == argc) {
2270 batch = LST_DEFAULT_BATCH;
2272 } else if (optind == argc - 1) {
2273 batch = argv[optind];
2276 lst_print_usage(argv[0]);
2280 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2282 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2283 batch, strerror(errno));
2287 CFS_INIT_LIST_HEAD(&head);
2289 rc = lst_alloc_rpcent(&head, count, 0);
2291 fprintf(stderr, "Out of memory\n");
2295 rc = lst_stop_batch_ioctl(batch, force, &head);
2300 lst_reset_rpcent(&head);
2302 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2306 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2307 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2310 fprintf(stdout, "%d batch in stopping\n",
2311 lstcon_tsbqry_stat_run(&trans_stat, 0));
2315 fprintf(stdout, "Batch is stopped\n");
2316 lst_free_rpcent(&head);
2321 lst_print_error("batch", "Failed to stop batch: %s\n",
2323 lst_free_rpcent(&head);
2327 lst_print_transerr(&head, "stop batch");
2329 lst_free_rpcent(&head);
2335 lst_list_batch_ioctl(int len, char *name, int index)
2337 lstio_batch_list_args_t args = {
2338 .lstio_bat_key = session_key,
2339 .lstio_bat_idx = index,
2340 .lstio_bat_nmlen = len,
2341 .lstio_bat_namep = name,
2344 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2348 lst_info_batch_ioctl(char *batch, int test, int server,
2349 lstcon_test_batch_ent_t *entp, int *idxp,
2350 int *ndentp, lstcon_node_ent_t *dentsp)
2352 lstio_batch_info_args_t args = {
2353 .lstio_bat_key = session_key,
2354 .lstio_bat_nmlen = strlen(batch),
2355 .lstio_bat_namep = batch,
2356 .lstio_bat_server = server,
2357 .lstio_bat_testidx = test,
2358 .lstio_bat_entp = entp,
2359 .lstio_bat_idxp = idxp,
2360 .lstio_bat_ndentp = ndentp,
2361 .lstio_bat_dentsp = dentsp,
2364 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2368 lst_list_batch_all(void)
2370 char name[LST_NAME_SIZE];
2374 for (i = 0; ; i++) {
2375 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2377 fprintf(stdout, "%d) %s\n", i + 1, name);
2381 if (errno == ENOENT)
2384 lst_print_error("batch", "Failed to list batch: %s\n",
2389 fprintf(stdout, "Total %d batches\n", i);
2395 lst_list_tsb_nodes(char *batch, int test, int server,
2396 int count, int active, int invalid)
2398 lstcon_node_ent_t *dents;
2407 /* verbose list, show nodes in batch or test */
2408 dents = malloc(count * sizeof(lstcon_node_ent_t));
2409 if (dents == NULL) {
2410 fprintf(stdout, "Can't allocate memory\n");
2414 rc = lst_info_batch_ioctl(batch, test, server,
2415 NULL, &index, &count, dents);
2418 lst_print_error((test > 0) ? "test" : "batch",
2419 (test > 0) ? "Failed to query test: %s\n" :
2420 "Failed to query batch: %s\n",
2425 for (i = 0, c = 0; i < count; i++) {
2426 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2427 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2428 dents[i].nde_state == LST_NODE_DOWN ||
2429 dents[i].nde_state == LST_NODE_UNKNOWN)))
2432 fprintf(stdout, "\t%s: %s\n",
2433 libcfs_id2str(dents[i].nde_id),
2434 lst_node_state2str(dents[i].nde_state));
2438 fprintf(stdout, "Total %d nodes\n", c);
2445 jt_lst_list_batch(int argc, char **argv)
2447 lstcon_test_batch_ent_t ent;
2450 int verbose = 0; /* list nodes in batch or test */
2459 static struct option list_batch_opts[] =
2461 {"test", required_argument, 0, 't' },
2462 {"invalid", no_argument, 0, 'i' },
2463 {"active", no_argument, 0, 'a' },
2464 {"all", no_argument, 0, 'l' },
2465 {"server", no_argument, 0, 's' },
2469 if (session_key == 0) {
2471 "Can't find env LST_SESSION or value is not valid\n");
2476 c = getopt_long(argc, argv, "ailst:",
2477 list_batch_opts, &optidx);
2484 verbose = active = 1;
2487 verbose = invalid = 1;
2490 verbose = active = invalid = 1;
2496 test = atoi(optarg);
2500 lst_print_usage(argv[0]);
2505 if (optind == argc) {
2506 /* list all batches */
2507 rc = lst_list_batch_all();
2511 if (ntest == 1 && test <= 0) {
2512 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2516 if (optind != argc - 1) {
2517 lst_print_usage(argv[0]);
2521 batch = argv[optind];
2524 /* show detail of specified batch or test */
2525 rc = lst_info_batch_ioctl(batch, test, server,
2526 &ent, NULL, NULL, NULL);
2528 lst_print_error((test > 0) ? "test" : "batch",
2529 (test > 0) ? "Failed to query test: %s\n" :
2530 "Failed to query batch: %s\n",
2536 /* list nodes in test or batch */
2537 rc = lst_list_tsb_nodes(batch, test, server,
2538 server ? ent.tbe_srv_nle.nle_nnode :
2539 ent.tbe_cli_nle.nle_nnode,
2544 /* only show number of hosts in batch or test */
2546 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2547 batch, ent.u.tbe_batch.bae_ntest,
2548 ent.u.tbe_batch.bae_state);
2549 ntest = ent.u.tbe_batch.bae_ntest;
2550 test = 1; /* starting from test 1 */
2554 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2555 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2556 ent.u.tbe_test.tse_loop,
2557 ent.u.tbe_test.tse_concur);
2562 fprintf(stdout, LST_NODES_TITLE);
2563 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2564 "server\t%d\t%d\t%d\t%d\t%d\n",
2565 ent.tbe_cli_nle.nle_nactive,
2566 ent.tbe_cli_nle.nle_nbusy,
2567 ent.tbe_cli_nle.nle_ndown,
2568 ent.tbe_cli_nle.nle_nunknown,
2569 ent.tbe_cli_nle.nle_nnode,
2570 ent.tbe_srv_nle.nle_nactive,
2571 ent.tbe_srv_nle.nle_nbusy,
2572 ent.tbe_srv_nle.nle_ndown,
2573 ent.tbe_srv_nle.nle_nunknown,
2574 ent.tbe_srv_nle.nle_nnode);
2583 lst_query_batch_ioctl(char *batch, int test, int server,
2584 int timeout, struct list_head *head)
2586 lstio_batch_query_args_t args = {
2587 .lstio_bat_key = session_key,
2588 .lstio_bat_testidx = test,
2589 .lstio_bat_client = !(server),
2590 .lstio_bat_timeout = timeout,
2591 .lstio_bat_nmlen = strlen(batch),
2592 .lstio_bat_namep = batch,
2593 .lstio_bat_resultp = head,
2596 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2600 lst_print_tsb_verbose(struct list_head *head,
2601 int active, int idle, int error)
2603 lstcon_rpc_ent_t *ent;
2605 list_for_each_entry(ent, head, rpe_link) {
2606 if (ent->rpe_priv[0] == 0 && active)
2609 if (ent->rpe_priv[0] != 0 && idle)
2612 if (ent->rpe_fwk_errno == 0 && error)
2615 fprintf(stdout, "%s [%s]: %s\n",
2616 libcfs_id2str(ent->rpe_peer),
2617 lst_node_state2str(ent->rpe_state),
2618 ent->rpe_rpc_errno != 0 ?
2619 strerror(ent->rpe_rpc_errno) :
2620 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2625 jt_lst_query_batch(int argc, char **argv)
2627 lstcon_test_batch_ent_t ent;
2628 struct list_head head;
2634 int timeout = 5; /* default 5 seconds */
2635 int delay = 5; /* default 5 seconds */
2636 int loop = 1; /* default 1 loop */
2646 static struct option query_batch_opts[] =
2648 {"timeout", required_argument, 0, 'o' },
2649 {"delay", required_argument, 0, 'd' },
2650 {"loop", required_argument, 0, 'c' },
2651 {"test", required_argument, 0, 't' },
2652 {"server", no_argument, 0, 's' },
2653 {"active", no_argument, 0, 'a' },
2654 {"idle", no_argument, 0, 'i' },
2655 {"error", no_argument, 0, 'e' },
2656 {"all", no_argument, 0, 'l' },
2660 if (session_key == 0) {
2662 "Can't find env LST_SESSION or value is not valid\n");
2667 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2668 query_batch_opts, &optidx);
2670 /* Detect the end of the options. */
2676 timeout = atoi(optarg);
2679 delay = atoi(optarg);
2682 loop = atoi(optarg);
2685 test = atoi(optarg);
2691 active = verbose = 1;
2697 error = verbose = 1;
2703 lst_print_usage(argv[0]);
2708 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2709 lst_print_usage(argv[0]);
2713 if (optind == argc) {
2714 batch = LST_DEFAULT_BATCH;
2716 } else if (optind == argc - 1) {
2717 batch = argv[optind];
2720 lst_print_usage(argv[0]);
2725 CFS_INIT_LIST_HEAD(&head);
2728 rc = lst_info_batch_ioctl(batch, test, server,
2729 &ent, NULL, NULL, NULL);
2731 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2732 batch, test, strerror(errno));
2736 count = server ? ent.tbe_srv_nle.nle_nnode :
2737 ent.tbe_cli_nle.nle_nnode;
2739 fprintf(stdout, "Batch or test is empty\n");
2744 rc = lst_alloc_rpcent(&head, count, 0);
2746 fprintf(stderr, "Out of memory\n");
2750 for (i = 0; i < loop; i++) {
2751 time_t now = time(NULL);
2753 if (now - last < delay) {
2754 sleep(delay - now + last);
2760 rc = lst_query_batch_ioctl(batch, test,
2761 server, timeout, &head);
2763 fprintf(stderr, "Failed to query batch: %s\n",
2770 lst_print_tsb_verbose(&head, active, idle, error);
2774 fprintf(stdout, "%s [%d] ", batch, test);
2776 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2777 fprintf(stdout, "%d of %d nodes are unknown, ",
2778 lstcon_rpc_stat_failure(&trans_stat, 0),
2779 lstcon_rpc_stat_total(&trans_stat, 0));
2782 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2783 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2784 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2785 fprintf(stdout, "is stopped\n");
2789 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2790 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2791 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2792 fprintf(stdout, "is running\n");
2796 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2797 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2798 lstcon_tsbqry_stat_run(&trans_stat, 0),
2799 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2802 lst_free_rpcent(&head);
2808 lst_parse_distribute(char *dstr, int *dist, int *span)
2814 dstr = strchr(dstr, ':');
2818 *span = atoi(dstr + 1);
2826 lst_get_bulk_param(int argc, char **argv, lst_test_bulk_param_t *bulk)
2833 bulk->blk_size = 4096;
2834 bulk->blk_opc = LST_BRW_READ;
2835 bulk->blk_flags = LST_BRW_CHECK_NONE;
2838 if (strcasestr(argv[i], "check=") == argv[i] ||
2839 strcasestr(argv[i], "c=") == argv[i]) {
2840 tok = strchr(argv[i], '=') + 1;
2842 if (strcasecmp(tok, "full") == 0) {
2843 bulk->blk_flags = LST_BRW_CHECK_FULL;
2844 } else if (strcasecmp(tok, "simple") == 0) {
2845 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2847 fprintf(stderr, "Unknow flag %s\n", tok);
2851 } else if (strcasestr(argv[i], "size=") == argv[i] ||
2852 strcasestr(argv[i], "s=") == argv[i]) {
2853 tok = strchr(argv[i], '=') + 1;
2855 bulk->blk_size = strtol(tok, &end, 0);
2856 if (bulk->blk_size <= 0) {
2857 fprintf(stderr, "Invalid size %s\n", tok);
2864 if (*end == 'k' || *end == 'K')
2865 bulk->blk_size *= 1024;
2866 else if (*end == 'm' || *end == 'M')
2867 bulk->blk_size *= 1024 * 1024;
2869 if (bulk->blk_size > CFS_PAGE_SIZE * LNET_MAX_IOV) {
2870 fprintf(stderr, "Size exceed limitation: %d bytes\n",
2875 } else if (strcasecmp(argv[i], "read") == 0 ||
2876 strcasecmp(argv[i], "r") == 0) {
2877 bulk->blk_opc = LST_BRW_READ;
2879 } else if (strcasecmp(argv[i], "write") == 0 ||
2880 strcasecmp(argv[i], "w") == 0) {
2881 bulk->blk_opc = LST_BRW_WRITE;
2884 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
2895 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
2897 lst_test_bulk_param_t *bulk = NULL;
2900 type = lst_test_name2type(test);
2902 fprintf(stderr, "Unknow test name %s\n", test);
2911 bulk = malloc(sizeof(*bulk));
2913 fprintf(stderr, "Out of memory\n");
2917 memset(bulk, 0, sizeof(*bulk));
2919 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
2925 *plen = sizeof(*bulk);
2933 /* TODO: parse more parameter */
2938 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
2939 int dist, int span, char *sgrp, char *dgrp,
2940 void *param, int plen, int *retp, struct list_head *resultp)
2942 lstio_test_args_t args = {
2943 .lstio_tes_key = session_key,
2944 .lstio_tes_bat_nmlen = strlen(batch),
2945 .lstio_tes_bat_name = batch,
2946 .lstio_tes_type = type,
2947 .lstio_tes_loop = loop,
2948 .lstio_tes_concur = concur,
2949 .lstio_tes_dist = dist,
2950 .lstio_tes_span = span,
2951 .lstio_tes_sgrp_nmlen = strlen(sgrp),
2952 .lstio_tes_sgrp_name = sgrp,
2953 .lstio_tes_dgrp_nmlen = strlen(dgrp),
2954 .lstio_tes_dgrp_name = dgrp,
2955 .lstio_tes_param_len = plen,
2956 .lstio_tes_param = param,
2957 .lstio_tes_retp = retp,
2958 .lstio_tes_resultp = resultp,
2961 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
2965 jt_lst_add_test(int argc, char **argv)
2967 struct list_head head;
2987 static struct option add_test_opts[] =
2989 {"batch", required_argument, 0, 'b' },
2990 {"concurrency", required_argument, 0, 'c' },
2991 {"distribute", required_argument, 0, 'd' },
2992 {"from", required_argument, 0, 'f' },
2993 {"to", required_argument, 0, 't' },
2994 {"loop", required_argument, 0, 'l' },
2998 if (session_key == 0) {
3000 "Can't find env LST_SESSION or value is not valid\n");
3005 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3006 add_test_opts, &optidx);
3008 /* Detect the end of the options. */
3017 concur = atoi(optarg);
3026 loop = atoi(optarg);
3032 lst_print_usage(argv[0]);
3037 if (optind == argc || from == NULL || to == NULL) {
3038 lst_print_usage(argv[0]);
3042 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3043 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3048 batch = LST_DEFAULT_BATCH;
3051 rc = lst_parse_distribute(dstr, &dist, &span);
3053 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3058 test = argv[optind++];
3063 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3065 fprintf(stderr, "Failed to add test (%s)\n", test);
3069 CFS_INIT_LIST_HEAD(&head);
3071 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3073 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3074 from, strerror(errno));
3078 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3080 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3081 to, strerror(errno));
3085 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3087 fprintf(stderr, "Out of memory\n");
3091 rc = lst_add_test_ioctl(batch, type, loop, concur,
3092 dist, span, from, to, param, plen, &ret, &head);
3095 fprintf(stdout, "Test was added successfully\n");
3097 fprintf(stdout, "Server group contains userland test "
3098 "nodes, old version of tcplnd can't accept "
3099 "connection request\n");
3106 lst_print_error("test", "Failed to add test: %s\n",
3111 lst_print_transerr(&head, "add test");
3113 lst_free_rpcent(&head);
3121 static command_t lst_cmdlist[] = {
3122 {"new_session", jt_lst_new_session, NULL,
3123 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3124 {"end_session", jt_lst_end_session, NULL,
3125 "Usage: lst end_session" },
3126 {"show_session", jt_lst_show_session, NULL,
3127 "Usage: lst show_session" },
3128 {"ping", jt_lst_ping , NULL,
3129 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3130 {"add_group", jt_lst_add_group, NULL,
3131 "Usage: lst group NAME IDs [IDs]..." },
3132 {"del_group", jt_lst_del_group, NULL,
3133 "Usage: lst del_group NAME" },
3134 {"update_group", jt_lst_update_group, NULL,
3135 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3136 {"list_group", jt_lst_list_group, NULL,
3137 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3138 {"stat", jt_lst_stat, NULL,
3139 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3140 " [--timeout #] [--delay #] GROUP [GROUP]" },
3141 {"show_error", jt_lst_show_error, NULL,
3142 "Usage: lst show_error NAME | IDS ..." },
3143 {"add_batch", jt_lst_add_batch, NULL,
3144 "Usage: lst add_batch NAME" },
3145 {"run", jt_lst_start_batch, NULL,
3146 "Usage: lst run [--timeout TIME] [NAME]" },
3147 {"stop", jt_lst_stop_batch, NULL,
3148 "Usage: lst stop [--force] BATCH_NAME" },
3149 {"list_batch", jt_lst_list_batch, NULL,
3150 "Usage: lst list_batch NAME [--test ID] [--server]" },
3151 {"query", jt_lst_query_batch, NULL,
3152 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3153 {"add_test", jt_lst_add_test, NULL,
3154 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3155 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3156 {"help", Parser_help, 0, "help" },
3161 lst_initialize(void)
3165 key = getenv("LST_SESSION");
3172 session_key = atoi(key);
3178 main(int argc, char **argv)
3182 if (lst_initialize() < 0)
3185 if (ptl_initialize(argc, argv) < 0)
3188 Parser_init("lst > ", lst_cmdlist);
3191 return Parser_execarg(argc - 1, argv + 1, lst_cmdlist);