4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lnet/selftest/conctl.c
34 * Author: Liang Zhen <liangzhen@clusterfs.com>
45 #include <sys/ioctl.h>
48 #include <libcfs/util/list.h>
49 #include <libcfs/util/ioctl.h>
50 #include <libcfs/util/parser.h>
51 #include <linux/lnet/lnetctl.h>
52 #include <linux/lnet/lnetst.h>
53 #include <linux/lnet/nidstr.h>
55 #include "lnetconfig/liblnetconfig.h"
58 struct lst_sid LST_INVALID_SID = { .ses_nid = LNET_NID_ANY, .ses_stamp = -1 };
59 static struct lst_sid session_id;
60 static int session_key;
61 static int lst_list_commands(int argc, char **argv);
63 /* All nodes running 2.6.50 or later understand feature LST_FEAT_BULK_LEN */
64 static unsigned session_features = LST_FEATS_MASK;
65 static struct lstcon_trans_stat trans_stat;
67 typedef struct list_string {
68 struct list_string *lstr_next;
74 # define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
77 static int alloc_count = 0;
78 static int alloc_nob = 0;
83 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
86 fprintf(stderr, "Can't allocate lstr\n");
93 lstr->lstr_str[0] = 0;
99 free_lstr(lstr_t *lstr)
102 alloc_nob -= lstr->lstr_sz;
107 free_lstrs(lstr_t **list)
111 while ((lstr = *list) != NULL) {
112 *list = lstr->lstr_next;
118 new_lstrs(lstr_t **list, char *prefix, char *postfix,
119 int lo, int hi, int stride)
121 int n1 = strlen(prefix);
122 int n2 = strlen(postfix);
123 int sz = n1 + 20 + n2 + 1;
126 lstr_t *n = alloc_lstr(sz);
128 snprintf(n->lstr_str, sz - 1, "%s%u%s",
129 prefix, lo, postfix);
131 n->lstr_next = *list;
139 expand_lstr(lstr_t **list, lstr_t *l)
141 int nob = strlen(l->lstr_str);
151 b1 = strchr(l->lstr_str, '[');
153 l->lstr_next = *list;
158 b2 = strchr(b1, ']');
159 if (b2 == NULL || b2 == b1 + 1)
167 sep = strchr(expr, ',');
173 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
175 new_lstrs(list, l->lstr_str, b2, x, x, 1);
180 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
183 new_lstrs(list, l->lstr_str, b2, x, y, 1);
188 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
191 new_lstrs(list, l->lstr_str, b2, x, y, z);
197 } while ((expr = sep) != NULL);
205 expand_strs(char *str, lstr_t **head)
213 l = alloc_lstr(strlen(str) + 1);
214 memcpy(l->lstr_str, str, strlen(str) + 1);
222 while ((l = list) != NULL) {
225 rc = expand_lstr(&nlist, l);
227 fprintf(stderr, "Syntax error in \"%s\"\n", str);
235 /* re-order onto 'list' */
236 while ((l = nlist) != NULL) {
237 nlist = l->lstr_next;
242 } while (expanded && rc > 0);
249 while ((l = list) != NULL) {
258 lst_parse_nids(char *str, int *countp, struct lnet_process_id **idspp)
266 rc = expand_strs(str, &head);
276 *idspp = malloc(c * sizeof(struct lnet_process_id));
277 if (*idspp == NULL) {
278 fprintf(stderr, "Out of memory\n");
285 while ((l = head) != NULL) {
289 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
290 if ((*idspp)[i].nid == LNET_NID_ANY) {
291 fprintf(stderr, "Invalid nid: %s\n",
296 (*idspp)[i].pid = LNET_PID_LUSTRE;
313 lst_node_state2str(int state)
315 if (state == LST_NODE_ACTIVE)
317 if (state == LST_NODE_BUSY)
319 if (state == LST_NODE_DOWN)
326 lst_node_str2state(char *str)
328 if (strcasecmp(str, "active") == 0)
329 return LST_NODE_ACTIVE;
330 if (strcasecmp(str, "busy") == 0)
331 return LST_NODE_BUSY;
332 if (strcasecmp(str, "down") == 0)
333 return LST_NODE_DOWN;
334 if (strcasecmp(str, "unknown") == 0)
335 return LST_NODE_UNKNOWN;
336 if (strcasecmp(str, "invalid") == 0)
337 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
343 lst_test_type2name(int type)
345 if (type == LST_TEST_PING)
347 if (type == LST_TEST_BULK)
354 lst_test_name2type(char *name)
356 if (strcasecmp(name, "ping") == 0)
357 return LST_TEST_PING;
358 if (strcasecmp(name, "brw") == 0)
359 return LST_TEST_BULK;
365 lst_print_usage(char *cmd)
367 Parser_printhelp(cmd);
371 lst_print_error(char *sub, const char *def_format, ...)
375 /* local error returned from kernel */
378 fprintf(stderr, "No session exists\n");
381 fprintf(stderr, "Session is shutting down\n");
384 fprintf(stderr, "Unmatched session key or not root\n");
387 fprintf(stderr, "Can't find %s in current session\n", sub);
390 fprintf(stderr, "Invalid parameters list in command line\n");
393 fprintf(stderr, "Bad parameter address\n");
396 fprintf(stderr, "%s already exists\n", sub);
399 va_start(ap, def_format);
400 vfprintf(stderr, def_format, ap);
408 lst_free_rpcent(struct list_head *head)
410 struct lstcon_rpc_ent *ent;
412 while (!list_empty(head)) {
413 ent = list_entry(head->next, struct lstcon_rpc_ent, rpe_link);
415 list_del(&ent->rpe_link);
421 lst_reset_rpcent(struct list_head *head)
423 struct lstcon_rpc_ent *ent;
425 list_for_each_entry(ent, head, rpe_link) {
426 ent->rpe_sid = LST_INVALID_SID;
427 ent->rpe_peer.nid = LNET_NID_ANY;
428 ent->rpe_peer.pid = LNET_PID_ANY;
429 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
434 lst_alloc_rpcent(struct list_head *head, int count, int offset)
436 struct lstcon_rpc_ent *ent;
439 for (i = 0; i < count; i++) {
440 ent = malloc(offsetof(struct lstcon_rpc_ent, rpe_payload[offset]));
442 lst_free_rpcent(head);
446 memset(ent, 0, offsetof(struct lstcon_rpc_ent, rpe_payload[offset]));
448 ent->rpe_sid = LST_INVALID_SID;
449 ent->rpe_peer.nid = LNET_NID_ANY;
450 ent->rpe_peer.pid = LNET_PID_ANY;
451 list_add(&ent->rpe_link, head);
458 lst_print_transerr(struct list_head *head, char *optstr)
460 struct lstcon_rpc_ent *ent;
462 list_for_each_entry(ent, head, rpe_link) {
463 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
466 if (ent->rpe_rpc_errno != 0) {
467 fprintf(stderr, "%s RPC failed on %s: %s\n",
468 optstr, libcfs_id2str(ent->rpe_peer),
469 strerror(ent->rpe_rpc_errno));
473 fprintf(stderr, "operation %s failed on %s: %s\n",
474 optstr, libcfs_id2str(ent->rpe_peer),
475 strerror(ent->rpe_fwk_errno));
479 int lst_info_batch_ioctl(char *batch, int test, int server,
480 struct lstcon_test_batch_ent *entp, int *idxp,
481 int *ndentp, struct lstcon_node_ent *dentsp);
483 int lst_info_group_ioctl(char *name, struct lstcon_ndlist_ent *gent,
484 int *idx, int *count, struct lstcon_node_ent *dents);
486 int lst_query_batch_ioctl(char *batch, int test, int server,
487 int timeout, struct list_head *head);
490 lst_ioctl(unsigned int opc, void *buf, int len)
492 struct libcfs_ioctl_data data;
495 LIBCFS_IOC_INIT (data);
496 data.ioc_u32[0] = opc;
497 data.ioc_plen1 = len;
498 data.ioc_pbuf1 = (char *)buf;
499 data.ioc_plen2 = sizeof(trans_stat);
500 data.ioc_pbuf2 = (char *)&trans_stat;
502 memset(&trans_stat, 0, sizeof(trans_stat));
504 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
506 /* local error, no valid RPC result */
511 if (trans_stat.trs_rpc_errno != 0)
514 /* Framework error */
515 if (trans_stat.trs_fwk_errno != 0)
522 lst_new_session_ioctl(char *name, int timeout, int force, struct lst_sid *sid)
524 struct lstio_session_new_args args = { 0 };
526 args.lstio_ses_key = session_key;
527 args.lstio_ses_timeout = timeout;
528 args.lstio_ses_force = force;
529 args.lstio_ses_idp = sid;
530 args.lstio_ses_feats = session_features;
531 args.lstio_ses_nmlen = strlen(name);
532 args.lstio_ses_namep = name;
534 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
538 jt_lst_new_session(int argc, char **argv)
540 char buf[LST_NAME_SIZE];
548 static const struct option session_opts[] = {
549 { .name = "timeout", .has_arg = required_argument, .val = 't' },
550 { .name = "force", .has_arg = no_argument, .val = 'f' },
553 if (session_key == 0) {
555 "Can't find env LST_SESSION or value is not valid\n");
561 c = getopt_long(argc, argv, "ft:",
562 session_opts, &optidx);
572 timeout = atoi(optarg);
575 lst_print_usage(argv[0]);
581 fprintf(stderr, "Invalid timeout value\n");
585 if (optind == argc - 1) {
586 name = argv[optind ++];
587 if (strlen(name) >= LST_NAME_SIZE) {
588 fprintf(stderr, "Name size is limited to %d\n",
593 } else if (optind == argc) {
594 char user[LST_NAME_SIZE];
595 char host[LST_NAME_SIZE];
596 struct passwd *pw = getpwuid(getuid());
599 snprintf(user, sizeof(user), "%d", (int)getuid());
601 snprintf(user, sizeof(user), "%s", pw->pw_name);
603 rc = gethostname(host, sizeof(host));
605 snprintf(host, sizeof(host), "unknown_host");
607 snprintf(buf, sizeof(buf), "%s@%s", user, host);
611 lst_print_usage(argv[0]);
615 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
617 lst_print_error("session", "Failed to create session: %s\n",
622 fprintf(stdout, "SESSION: %s FEATURES: %x TIMEOUT: %d FORCE: %s\n",
623 name, session_features, timeout, force ? "Yes" : "No");
628 lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp,
629 struct lst_sid *sid, struct lstcon_ndlist_ent *ndinfo)
631 struct lstio_session_info_args args = { 0 };
633 args.lstio_ses_idp = sid;
634 args.lstio_ses_keyp = key;
635 args.lstio_ses_featp = featp;
636 args.lstio_ses_ndinfo = ndinfo;
637 args.lstio_ses_nmlen = len;
638 args.lstio_ses_namep = name;
640 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
644 jt_lst_show_session(int argc, char **argv)
646 struct lstcon_ndlist_ent ndinfo;
648 char name[LST_NAME_SIZE];
653 rc = lst_session_info_ioctl(name, sizeof(name), &key,
654 &feats, &sid, &ndinfo);
657 lst_print_error("session", "Failed to show session: %s\n",
662 fprintf(stdout, "%s ID: %ju@%s, KEY: %d FEATURES: %x NODES: %d\n",
663 name, (uintmax_t)sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
664 key, feats, ndinfo.nle_nnode);
670 lst_end_session_ioctl(void)
672 struct lstio_session_end_args args = { 0 };
674 args.lstio_ses_key = session_key;
675 return lst_ioctl(LSTIO_SESSION_END, &args, sizeof(args));
679 jt_lst_end_session(int argc, char **argv)
683 if (session_key == 0) {
685 "Can't find env LST_SESSION or value is not valid\n");
689 rc = lst_end_session_ioctl();
692 fprintf(stdout, "session is ended\n");
697 lst_print_error("session", "Failed to end session: %s\n",
702 if (trans_stat.trs_rpc_errno != 0) {
704 "[RPC] Failed to send %d session RPCs: %s\n",
705 lstcon_rpc_stat_failure(&trans_stat, 0),
706 strerror(trans_stat.trs_rpc_errno));
709 if (trans_stat.trs_fwk_errno != 0) {
711 "[FWK] Failed to end session on %d nodes: %s\n",
712 lstcon_sesop_stat_failure(&trans_stat, 0),
713 strerror(trans_stat.trs_fwk_errno));
720 lst_ping_ioctl(char *str, int type, int timeout,
721 int count, struct lnet_process_id *ids, struct list_head *head)
723 struct lstio_debug_args args = { 0 };
725 args.lstio_dbg_key = session_key;
726 args.lstio_dbg_type = type;
727 args.lstio_dbg_flags = 0;
728 args.lstio_dbg_timeout = timeout;
729 args.lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str);
730 args.lstio_dbg_namep = str;
731 args.lstio_dbg_count = count;
732 args.lstio_dbg_idsp = ids;
733 args.lstio_dbg_resultp = head;
735 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
739 lst_get_node_count(int type, char *str, int *countp,
740 struct lnet_process_id **idspp)
742 char buf[LST_NAME_SIZE];
743 struct lstcon_test_batch_ent ent;
744 struct lstcon_ndlist_ent *entp = &ent.tbe_cli_nle;
751 case LST_OPC_SESSION:
752 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
753 &key, &feats, &sid, entp);
756 case LST_OPC_BATCHSRV:
757 entp = &ent.tbe_srv_nle;
758 case LST_OPC_BATCHCLI:
759 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
763 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
767 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
776 *countp = entp->nle_nnode;
782 jt_lst_ping(int argc, char **argv)
784 struct list_head head;
785 struct lnet_process_id *ids = NULL;
786 struct lstcon_rpc_ent *ent = NULL;
796 static const struct option ping_opts[] = {
797 { .name = "session", .has_arg = no_argument, .val = 's' },
798 { .name = "server", .has_arg = no_argument, .val = 'v' },
799 { .name = "batch", .has_arg = required_argument, .val = 'b' },
800 { .name = "group", .has_arg = required_argument, .val = 'g' },
801 { .name = "nodes", .has_arg = required_argument, .val = 'n' },
802 { .name = "timeout", .has_arg = required_argument, .val = 't' },
805 if (session_key == 0) {
807 "Can't find env LST_SESSION or value is not valid\n");
813 c = getopt_long(argc, argv, "g:b:n:t:sv",
821 type = LST_OPC_SESSION;
825 type = LST_OPC_GROUP;
830 type = LST_OPC_BATCHCLI;
835 type = LST_OPC_NODES;
840 timeout = atoi(optarg);
848 lst_print_usage(argv[0]);
853 if (type == 0 || timeout <= 0 || optind != argc) {
854 lst_print_usage(argv[0]);
858 if (type == LST_OPC_BATCHCLI && server)
859 type = LST_OPC_BATCHSRV;
861 rc = lst_get_node_count(type, str, &count, &ids);
863 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
864 (str == NULL) ? "session" : str, strerror(errno));
868 INIT_LIST_HEAD(&head);
870 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
872 fprintf(stderr, "Out of memory\n");
877 fprintf(stdout, "Target %s is empty\n",
878 (str == NULL) ? "session" : str);
882 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
883 if (rc == -1) { /* local failure */
884 lst_print_error("debug", "Failed to ping %s: %s\n",
885 (str == NULL) ? "session" : str,
891 /* ignore RPC errors and framwork errors */
892 list_for_each_entry(ent, &head, rpe_link) {
893 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
894 libcfs_id2str(ent->rpe_peer),
895 lst_node_state2str(ent->rpe_state),
896 (ent->rpe_state == LST_NODE_ACTIVE ||
897 ent->rpe_state == LST_NODE_BUSY) ?
898 (ent->rpe_rpc_errno == 0 ?
899 &ent->rpe_payload[0] : "Unknown") :
900 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
904 lst_free_rpcent(&head);
914 lst_add_nodes_ioctl(char *name, int count, struct lnet_process_id *ids,
915 unsigned *featp, struct list_head *resultp)
917 struct lstio_group_nodes_args args = { 0 };
919 args.lstio_grp_key = session_key;
920 args.lstio_grp_nmlen = strlen(name);
921 args.lstio_grp_namep = name;
922 args.lstio_grp_count = count;
923 args.lstio_grp_featp = featp;
924 args.lstio_grp_idsp = ids;
925 args.lstio_grp_resultp = resultp;
927 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
931 lst_del_group_ioctl(char *name)
933 struct lstio_group_del_args args = { 0 };
935 args.lstio_grp_key = session_key;
936 args.lstio_grp_nmlen = strlen(name);
937 args.lstio_grp_namep = name;
939 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
943 lst_del_group(char *grp_name)
947 rc = lst_del_group_ioctl(grp_name);
949 fprintf(stdout, "Group is deleted\n");
954 lst_print_error("group", "Failed to delete group: %s\n",
959 fprintf(stderr, "Group is deleted with some errors\n");
961 if (trans_stat.trs_rpc_errno != 0) {
963 "[RPC] Failed to send %d end session RPCs: %s\n",
964 lstcon_rpc_stat_failure(&trans_stat, 0),
965 strerror(trans_stat.trs_rpc_errno));
968 if (trans_stat.trs_fwk_errno != 0) {
970 "[FWK] Failed to end session on %d nodes: %s\n",
971 lstcon_sesop_stat_failure(&trans_stat, 0),
972 strerror(trans_stat.trs_fwk_errno));
979 lst_add_group_ioctl(char *name)
981 struct lstio_group_add_args args = { 0 };
983 args.lstio_grp_key = session_key;
984 args.lstio_grp_nmlen = strlen(name);
985 args.lstio_grp_namep = name;
987 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
991 jt_lst_add_group(int argc, char **argv)
993 struct list_head head;
994 struct lnet_process_id *ids;
996 unsigned feats = session_features;
1000 bool nodes_added = false;
1002 if (session_key == 0) {
1004 "Can't find env LST_SESSION or value is not valid\n");
1009 lst_print_usage(argv[0]);
1014 if (strlen(name) >= LST_NAME_SIZE) {
1015 fprintf(stderr, "Name length is limited to %d\n",
1020 rc = lst_add_group_ioctl(name);
1022 lst_print_error("group", "Failed to add group %s: %s\n",
1023 name, strerror(errno));
1027 INIT_LIST_HEAD(&head);
1029 for (i = 2; i < argc; i++) {
1030 /* parse address list */
1031 rc = lst_parse_nids(argv[i], &count, &ids);
1033 fprintf(stderr, "Ignore invalid id list %s\n",
1041 rc = lst_alloc_rpcent(&head, count, 0);
1043 fprintf(stderr, "Out of memory\n");
1049 rc = lst_add_nodes_ioctl(name, count, ids, &feats, &head);
1056 fprintf(stdout, "%s are added to session\n", argv[i]);
1060 if ((feats & session_features) != session_features) {
1062 "Warning, this session will run with "
1063 "compatible mode because some test nodes "
1064 "might not understand these features: %x\n",
1065 (~feats & session_features));
1068 lst_free_rpcent(&head);
1073 * The selftest kernel module expects that a group should
1074 * have at least one node, since it doesn't make sense for
1075 * an empty group to be added to a test.
1078 "No nodes added successfully, deleting group %s\n",
1080 rc = lst_del_group(name);
1083 "Failed to delete group %s."
1084 " Group is empty.\n", name);
1092 lst_print_error("group", "Failed to add nodes %s: %s\n",
1093 argv[i], strerror(errno));
1096 if (trans_stat.trs_fwk_errno == EPROTO) {
1098 "test nodes might have different LST "
1099 "features, please disable some features by "
1100 "setting LST_FEATURES\n");
1103 lst_print_transerr(&head, "create session");
1106 lst_free_rpcent(&head);
1110 "No nodes added successfully, deleting group %s\n",
1112 if (lst_del_group(name) != 0) {
1114 "Failed to delete group %s."
1115 " Group is empty.\n", name);
1123 jt_lst_del_group(int argc, char **argv)
1127 if (session_key == 0) {
1129 "Can't find env LST_SESSION or value is not valid\n");
1134 lst_print_usage(argv[0]);
1138 rc = lst_del_group(argv[1]);
1144 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1145 struct lnet_process_id *ids, struct list_head *resultp)
1147 struct lstio_group_update_args args = { 0 };
1149 args.lstio_grp_key = session_key;
1150 args.lstio_grp_opc = opc;
1151 args.lstio_grp_args = clean;
1152 args.lstio_grp_nmlen = strlen(name);
1153 args.lstio_grp_namep = name;
1154 args.lstio_grp_count = count;
1155 args.lstio_grp_idsp = ids;
1156 args.lstio_grp_resultp = resultp;
1158 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1162 jt_lst_update_group(int argc, char **argv)
1164 struct list_head head;
1165 struct lnet_process_id *ids = NULL;
1175 static const struct option update_group_opts[] = {
1176 { .name = "refresh", .has_arg = no_argument, .val = 'f' },
1177 { .name = "clean", .has_arg = required_argument, .val = 'c' },
1178 { .name = "remove", .has_arg = required_argument, .val = 'r' },
1181 if (session_key == 0) {
1183 "Can't find env LST_SESSION or value is not valid\n");
1188 c = getopt_long(argc, argv, "fc:r:",
1189 update_group_opts, &optidx);
1191 /* Detect the end of the options. */
1198 lst_print_usage(argv[0]);
1201 opc = LST_GROUP_REFRESH;
1206 lst_print_usage(argv[0]);
1209 opc = LST_GROUP_RMND;
1214 clean = lst_node_str2state(optarg);
1215 if (opc != 0 || clean <= 0) {
1216 lst_print_usage(argv[0]);
1219 opc = LST_GROUP_CLEAN;
1223 lst_print_usage(argv[0]);
1228 /* no OPC or group is specified */
1229 if (opc == 0 || optind != argc - 1) {
1230 lst_print_usage(argv[0]);
1236 INIT_LIST_HEAD(&head);
1238 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1239 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1241 opc == LST_GROUP_RMND ? str : grp,
1245 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1246 opc == LST_GROUP_RMND ? str : grp,
1251 rc = lst_alloc_rpcent(&head, count, 0);
1253 fprintf(stderr, "Out of memory\n");
1260 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1266 lst_free_rpcent(&head);
1271 lst_free_rpcent(&head);
1272 lst_print_error("group", "Failed to update group: %s\n",
1277 lst_print_transerr(&head, "Updating group");
1279 lst_free_rpcent(&head);
1285 lst_list_group_ioctl(int len, char *name, int idx)
1287 struct lstio_group_list_args args = { 0 };
1289 args.lstio_grp_key = session_key;
1290 args.lstio_grp_idx = idx;
1291 args.lstio_grp_nmlen = len;
1292 args.lstio_grp_namep = name;
1294 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1298 lst_info_group_ioctl(char *name, struct lstcon_ndlist_ent *gent,
1299 int *idx, int *count, struct lstcon_node_ent *dents)
1301 struct lstio_group_info_args args = { 0 };
1303 args.lstio_grp_key = session_key;
1304 args.lstio_grp_nmlen = strlen(name);
1305 args.lstio_grp_namep = name;
1306 args.lstio_grp_entp = gent;
1307 args.lstio_grp_idxp = idx;
1308 args.lstio_grp_ndentp = count;
1309 args.lstio_grp_dentsp = dents;
1311 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1315 lst_list_group_all(void)
1317 char name[LST_NAME_SIZE];
1321 /* no group is specified, list name of all groups */
1322 for (i = 0; ; i++) {
1323 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1325 fprintf(stdout, "%d) %s\n", i + 1, name);
1329 if (errno == ENOENT)
1332 lst_print_error("group", "Failed to list group: %s\n",
1337 fprintf(stdout, "Total %d groups\n", i);
1342 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1345 jt_lst_list_group(int argc, char **argv)
1347 struct lstcon_ndlist_ent gent;
1348 struct lstcon_node_ent *dents;
1363 static const struct option list_group_opts[] = {
1364 { .name = "active", .has_arg = no_argument, .val = 'a' },
1365 { .name = "busy", .has_arg = no_argument, .val = 'b' },
1366 { .name = "down", .has_arg = no_argument, .val = 'd' },
1367 { .name = "unknown", .has_arg = no_argument, .val = 'u' },
1368 { .name = "all", .has_arg = no_argument, .val = 'l' },
1369 { .name = NULL, } };
1371 if (session_key == 0) {
1373 "Can't find env LST_SESSION or value is not valid\n");
1378 c = getopt_long(argc, argv, "abdul",
1379 list_group_opts, &optidx);
1386 verbose = active = 1;
1398 verbose = unknown = 1;
1405 lst_print_usage(argv[0]);
1410 if (optind == argc) {
1411 /* no group is specified, list name of all groups */
1412 rc = lst_list_group_all();
1418 fprintf(stdout, LST_NODES_TITLE);
1420 /* list nodes in specified groups */
1421 for (i = optind; i < argc; i++) {
1422 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1424 if (errno == ENOENT) {
1429 lst_print_error("group", "Failed to list group\n",
1435 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1436 gent.nle_nactive, gent.nle_nbusy,
1437 gent.nle_ndown, gent.nle_nunknown,
1438 gent.nle_nnode, argv[i]);
1442 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1444 if (gent.nle_nnode == 0) {
1445 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1449 count = gent.nle_nnode;
1451 dents = malloc(count * sizeof(struct lstcon_node_ent));
1452 if (dents == NULL) {
1453 fprintf(stderr, "Failed to malloc: %s\n",
1459 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1461 lst_print_error("group", "Failed to list group: %s\n",
1467 for (j = 0, c = 0; j < count; j++) {
1469 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1470 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1471 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1472 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1474 fprintf(stdout, "\t%s: %s\n",
1475 libcfs_id2str(dents[j].nde_id),
1476 lst_node_state2str(dents[j].nde_state));
1481 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1490 lst_stat_ioctl(char *name, int count, struct lnet_process_id *idsp,
1491 int timeout, struct list_head *resultp)
1493 struct lstio_stat_args args = { 0 };
1495 args.lstio_sta_key = session_key;
1496 args.lstio_sta_timeout = timeout;
1497 args.lstio_sta_nmlen = strlen(name);
1498 args.lstio_sta_namep = name;
1499 args.lstio_sta_count = count;
1500 args.lstio_sta_idsp = idsp;
1501 args.lstio_sta_resultp = resultp;
1503 return lst_ioctl(LSTIO_STAT_QUERY, &args, sizeof(args));
1507 struct list_head srp_link;
1510 struct lnet_process_id *srp_ids;
1511 struct list_head srp_result[2];
1512 } lst_stat_req_param_t;
1515 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1519 for (i = 0; i < 2; i++)
1520 lst_free_rpcent(&srp->srp_result[i]);
1522 if (srp->srp_ids != NULL)
1529 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
1531 lst_stat_req_param_t *srp = NULL;
1532 int count = save_old ? 2 : 1;
1536 srp = malloc(sizeof(*srp));
1540 memset(srp, 0, sizeof(*srp));
1541 INIT_LIST_HEAD(&srp->srp_result[0]);
1542 INIT_LIST_HEAD(&srp->srp_result[1]);
1544 rc = lst_get_node_count(LST_OPC_GROUP, name,
1545 &srp->srp_count, NULL);
1546 if (rc != 0 && errno == ENOENT) {
1547 rc = lst_get_node_count(LST_OPC_NODES, name,
1548 &srp->srp_count, &srp->srp_ids);
1553 "Failed to get count of nodes from %s: %s\n",
1554 name, strerror(errno));
1555 lst_stat_req_param_free(srp);
1560 srp->srp_name = name;
1562 for (i = 0; i < count; i++) {
1563 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1564 sizeof(struct sfw_counters) +
1565 sizeof(struct srpc_counters) +
1566 sizeof(struct lnet_counters));
1568 fprintf(stderr, "Out of memory\n");
1578 lst_stat_req_param_free(srp);
1586 } lst_srpc_stat_result;
1588 #define LST_LNET_AVG 0
1589 #define LST_LNET_MIN 1
1590 #define LST_LNET_MAX 2
1593 float lnet_avg_sndrate;
1594 float lnet_min_sndrate;
1595 float lnet_max_sndrate;
1596 float lnet_total_sndrate;
1598 float lnet_avg_rcvrate;
1599 float lnet_min_rcvrate;
1600 float lnet_max_rcvrate;
1601 float lnet_total_rcvrate;
1603 float lnet_avg_sndperf;
1604 float lnet_min_sndperf;
1605 float lnet_max_sndperf;
1606 float lnet_total_sndperf;
1608 float lnet_avg_rcvperf;
1609 float lnet_min_rcvperf;
1610 float lnet_max_rcvperf;
1611 float lnet_total_rcvperf;
1613 int lnet_stat_count;
1614 } lst_lnet_stat_result_t;
1616 lst_lnet_stat_result_t lnet_stat_result;
1619 lst_lnet_stat_value(int bw, int send, int off)
1623 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1624 &lnet_stat_result.lnet_avg_sndrate;
1635 lst_timeval_diff(struct timeval *tv1,
1636 struct timeval *tv2, struct timeval *df)
1638 if (tv1->tv_usec >= tv2->tv_usec) {
1639 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1640 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1644 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1645 df->tv_usec = tv1->tv_usec + 1000000 - tv2->tv_usec;
1651 lst_cal_lnet_stat(float delta, struct lnet_counters *lnet_new,
1652 struct lnet_counters *lnet_old, int mbs)
1656 unsigned int unit_divisor;
1658 unit_divisor = (mbs) ? (1000 * 1000) : (1024 * 1024);
1659 perf = (float)(lnet_new->send_length -
1660 lnet_old->send_length) / unit_divisor / delta;
1661 lnet_stat_result.lnet_total_sndperf += perf;
1663 if (lnet_stat_result.lnet_min_sndperf > perf ||
1664 lnet_stat_result.lnet_min_sndperf == 0)
1665 lnet_stat_result.lnet_min_sndperf = perf;
1667 if (lnet_stat_result.lnet_max_sndperf < perf)
1668 lnet_stat_result.lnet_max_sndperf = perf;
1670 perf = (float)(lnet_new->recv_length -
1671 lnet_old->recv_length) / unit_divisor / delta;
1672 lnet_stat_result.lnet_total_rcvperf += perf;
1674 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1675 lnet_stat_result.lnet_min_rcvperf == 0)
1676 lnet_stat_result.lnet_min_rcvperf = perf;
1678 if (lnet_stat_result.lnet_max_rcvperf < perf)
1679 lnet_stat_result.lnet_max_rcvperf = perf;
1681 rate = (lnet_new->send_count - lnet_old->send_count) / delta;
1682 lnet_stat_result.lnet_total_sndrate += rate;
1684 if (lnet_stat_result.lnet_min_sndrate > rate ||
1685 lnet_stat_result.lnet_min_sndrate == 0)
1686 lnet_stat_result.lnet_min_sndrate = rate;
1688 if (lnet_stat_result.lnet_max_sndrate < rate)
1689 lnet_stat_result.lnet_max_sndrate = rate;
1691 rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
1692 lnet_stat_result.lnet_total_rcvrate += rate;
1694 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1695 lnet_stat_result.lnet_min_rcvrate == 0)
1696 lnet_stat_result.lnet_min_rcvrate = rate;
1698 if (lnet_stat_result.lnet_max_rcvrate < rate)
1699 lnet_stat_result.lnet_max_rcvrate = rate;
1701 lnet_stat_result.lnet_stat_count++;
1703 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1704 lnet_stat_result.lnet_stat_count;
1705 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1706 lnet_stat_result.lnet_stat_count;
1708 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1709 lnet_stat_result.lnet_stat_count;
1710 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1711 lnet_stat_result.lnet_stat_count;
1715 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type, int mbs)
1725 if (lnet_stat_result.lnet_stat_count == 0)
1728 units = (mbs) ? "MB/s " : "MiB/s ";
1730 if (bwrt == 1) /* bw only */
1733 if (bwrt == 2) /* rates only */
1736 if (rdwr == 1) /* recv only */
1739 if (rdwr == 2) /* send only */
1742 for (i = start1; i <= end1; i++) {
1743 fprintf(stdout, "[LNet %s of %s]\n",
1744 i == 0 ? "Rates" : "Bandwidth", name);
1746 for (j = start2; j <= end2; j++) {
1747 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
1749 if ((type & 1) != 0) {
1750 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1752 lst_lnet_stat_value(i, j, 0), units);
1755 if ((type & 2) != 0) {
1756 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1758 lst_lnet_stat_value(i, j, 1), units);
1761 if ((type & 4) != 0) {
1762 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1764 lst_lnet_stat_value(i, j, 2), units);
1767 fprintf(stdout, "\n");
1773 lst_print_stat(char *name, struct list_head *resultp,
1774 int idx, int lnet, int bwrt, int rdwr, int type,
1777 struct list_head tmp[2];
1778 struct lstcon_rpc_ent *new;
1779 struct lstcon_rpc_ent *old;
1780 struct sfw_counters *sfwk_new;
1781 struct sfw_counters *sfwk_old;
1782 struct srpc_counters *srpc_new;
1783 struct srpc_counters *srpc_old;
1784 struct lnet_counters *lnet_new;
1785 struct lnet_counters *lnet_old;
1789 INIT_LIST_HEAD(&tmp[0]);
1790 INIT_LIST_HEAD(&tmp[1]);
1792 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1794 while (!list_empty(&resultp[idx])) {
1795 if (list_empty(&resultp[1 - idx])) {
1796 fprintf(stderr, "Group is changed, re-run stat\n");
1800 new = list_entry(resultp[idx].next, struct lstcon_rpc_ent,
1802 old = list_entry(resultp[1 - idx].next, struct lstcon_rpc_ent,
1805 /* first time get stats result, can't calculate diff */
1806 if (new->rpe_peer.nid == LNET_NID_ANY)
1809 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1810 new->rpe_peer.pid != old->rpe_peer.pid) {
1811 /* Something wrong. i.e, somebody change the group */
1815 list_del(&new->rpe_link);
1816 list_add_tail(&new->rpe_link, &tmp[idx]);
1818 list_del(&old->rpe_link);
1819 list_add_tail(&old->rpe_link, &tmp[1 - idx]);
1821 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1822 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1827 sfwk_new = (struct sfw_counters *)&new->rpe_payload[0];
1828 sfwk_old = (struct sfw_counters *)&old->rpe_payload[0];
1830 srpc_new = (struct srpc_counters *)((char *)sfwk_new + sizeof(*sfwk_new));
1831 srpc_old = (struct srpc_counters *)((char *)sfwk_old + sizeof(*sfwk_old));
1833 lnet_new = (struct lnet_counters *)((char *)srpc_new + sizeof(*srpc_new));
1834 lnet_old = (struct lnet_counters *)((char *)srpc_old + sizeof(*srpc_old));
1836 /* Prior to version 2.3, the running_ms field was a counter for
1837 * the number of running tests. We are looking at this value
1838 * to determine if it is a millisecond timestamep (>= 2.3) or a
1839 * test counter (< 2.3). The number 500 is being used for this
1840 * barrier as the test counter should never get this high, and
1841 * the timestamp should never get this low. */
1843 if (sfwk_new->running_ms > 500) {
1844 /* use the timestamp from the remote node, not our
1845 * rpe_stamp from when we copied up the data out of
1848 delta = (float) (sfwk_new->running_ms -
1849 sfwk_old->running_ms) / 1000;
1853 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1854 delta = tv.tv_sec + (float)tv.tv_usec / 1000000;
1857 if (!lnet) /* TODO */
1860 lst_cal_lnet_stat(delta, lnet_new, lnet_old, mbs);
1863 list_splice(&tmp[idx], &resultp[idx]);
1864 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1867 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1869 if (!lnet) /* TODO */
1872 lst_print_lnet_stat(name, bwrt, rdwr, type, mbs);
1876 jt_lst_stat(int argc, char **argv)
1878 struct list_head head;
1879 lst_stat_req_param_t *srp;
1882 int timeout = 5; /* default timeout, 5 sec */
1883 int delay = 5; /* default delay, 5 sec */
1884 int count = -1; /* run forever */
1885 int lnet = 1; /* lnet stat by default */
1892 int mbs = 0; /* report as MB/s */
1894 static const struct option stat_opts[] = {
1895 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1896 { .name = "delay", .has_arg = required_argument, .val = 'd' },
1897 { .name = "count", .has_arg = required_argument, .val = 'o' },
1898 { .name = "lnet", .has_arg = no_argument, .val = 'l' },
1899 { .name = "rpc", .has_arg = no_argument, .val = 'c' },
1900 { .name = "bw", .has_arg = no_argument, .val = 'b' },
1901 { .name = "rate", .has_arg = no_argument, .val = 'a' },
1902 { .name = "read", .has_arg = no_argument, .val = 'r' },
1903 { .name = "write", .has_arg = no_argument, .val = 'w' },
1904 { .name = "avg", .has_arg = no_argument, .val = 'g' },
1905 { .name = "min", .has_arg = no_argument, .val = 'n' },
1906 { .name = "max", .has_arg = no_argument, .val = 'x' },
1907 { .name = "mbs", .has_arg = no_argument, .val = 'm' },
1910 if (session_key == 0) {
1912 "Can't find env LST_SESSION or value is not valid\n");
1917 c = getopt_long(argc, argv, "t:d:lcbarwgnxm", stat_opts,
1925 timeout = atoi(optarg);
1928 delay = atoi(optarg);
1931 count = atoi(optarg);
1977 lst_print_usage(argv[0]);
1982 if (optind == argc) {
1983 lst_print_usage(argv[0]);
1987 if (timeout <= 0 || delay <= 0) {
1988 fprintf(stderr, "Invalid timeout or delay value\n");
1993 fprintf(stderr, "Invalid count value\n");
1997 /* extra count to get first data point */
2001 INIT_LIST_HEAD(&head);
2003 while (optind < argc) {
2004 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
2008 list_add_tail(&srp->srp_link, &head);
2012 time_t now = time(NULL);
2014 if (now - last < delay) {
2015 sleep(delay - now + last);
2020 list_for_each_entry(srp, &head, srp_link) {
2021 rc = lst_stat_ioctl(srp->srp_name,
2022 srp->srp_count, srp->srp_ids,
2023 timeout, &srp->srp_result[idx]);
2025 lst_print_error("stat", "Failed to stat %s: %s\n",
2026 srp->srp_name, strerror(errno));
2030 lst_print_stat(srp->srp_name, srp->srp_result,
2031 idx, lnet, bwrt, rdwr, type, mbs);
2033 lst_reset_rpcent(&srp->srp_result[1 - idx]);
2040 } while (count == -1 || count > 0);
2043 while (!list_empty(&head)) {
2044 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2046 list_del(&srp->srp_link);
2047 lst_stat_req_param_free(srp);
2054 jt_lst_show_error(int argc, char **argv)
2056 struct list_head head;
2057 lst_stat_req_param_t *srp;
2058 struct lstcon_rpc_ent *ent;
2059 struct sfw_counters *sfwk;
2060 struct srpc_counters *srpc;
2067 static const struct option show_error_opts[] = {
2068 { .name = "session", .has_arg = no_argument, .val = 's' },
2069 { .name = NULL, } };
2071 if (session_key == 0) {
2073 "Can't find env LST_SESSION or value is not valid\n");
2078 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
2089 lst_print_usage(argv[0]);
2094 if (optind == argc) {
2095 lst_print_usage(argv[0]);
2099 INIT_LIST_HEAD(&head);
2101 while (optind < argc) {
2102 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
2106 list_add_tail(&srp->srp_link, &head);
2109 list_for_each_entry(srp, &head, srp_link) {
2110 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
2111 srp->srp_ids, 10, &srp->srp_result[0]);
2114 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2115 srp->srp_name, strerror(errno));
2119 fprintf(stdout, "%s:\n", srp->srp_name);
2123 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2124 if (ent->rpe_rpc_errno != 0) {
2126 fprintf(stderr, "RPC failure, can't show error on %s\n",
2127 libcfs_id2str(ent->rpe_peer));
2131 if (ent->rpe_fwk_errno != 0) {
2133 fprintf(stderr, "Framework failure, can't show error on %s\n",
2134 libcfs_id2str(ent->rpe_peer));
2138 sfwk = (struct sfw_counters *)&ent->rpe_payload[0];
2139 srpc = (struct srpc_counters *)((char *)sfwk + sizeof(*sfwk));
2141 if (srpc->errors == 0 &&
2142 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2146 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2151 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2152 libcfs_id2str(ent->rpe_peer),
2153 sfwk->brw_errors, sfwk->ping_errors,
2154 show_rpc ? ' ' : '\n');
2159 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2160 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2163 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2166 while (!list_empty(&head)) {
2167 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2169 list_del(&srp->srp_link);
2170 lst_stat_req_param_free(srp);
2177 lst_add_batch_ioctl(char *name)
2179 struct lstio_batch_add_args args = { 0 };
2181 args.lstio_bat_key = session_key;
2182 args.lstio_bat_nmlen = strlen(name);
2183 args.lstio_bat_namep = name;
2185 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2189 jt_lst_add_batch(int argc, char **argv)
2194 if (session_key == 0) {
2196 "Can't find env LST_SESSION or value is not valid\n");
2201 lst_print_usage(argv[0]);
2206 if (strlen(name) >= LST_NAME_SIZE) {
2207 fprintf(stderr, "Name length is limited to %d\n",
2212 rc = lst_add_batch_ioctl(name);
2216 lst_print_error("batch", "Failed to create batch: %s\n",
2223 lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp)
2225 struct lstio_batch_run_args args = { 0 };
2227 args.lstio_bat_key = session_key;
2228 args.lstio_bat_timeout = timeout;
2229 args.lstio_bat_nmlen = strlen(name);
2230 args.lstio_bat_namep = name;
2231 args.lstio_bat_resultp = resultp;
2233 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2237 jt_lst_start_batch(int argc, char **argv)
2239 struct list_head head;
2247 static const struct option start_batch_opts[] = {
2248 { .name = "timeout", .has_arg = required_argument, .val = 't' },
2251 if (session_key == 0) {
2253 "Can't find env LST_SESSION or value is not valid\n");
2258 c = getopt_long(argc, argv, "t:",
2259 start_batch_opts, &optidx);
2261 /* Detect the end of the options. */
2267 timeout = atoi(optarg);
2270 lst_print_usage(argv[0]);
2275 if (optind == argc) {
2276 batch = LST_DEFAULT_BATCH;
2278 } else if (optind == argc - 1) {
2279 batch = argv[optind];
2282 lst_print_usage(argv[0]);
2286 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2288 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2289 batch, strerror(errno));
2293 INIT_LIST_HEAD(&head);
2295 rc = lst_alloc_rpcent(&head, count, 0);
2297 fprintf(stderr, "Out of memory\n");
2301 rc = lst_start_batch_ioctl(batch, timeout, &head);
2304 fprintf(stdout, "%s is running now\n", batch);
2305 lst_free_rpcent(&head);
2310 lst_print_error("batch", "Failed to start batch: %s\n",
2312 lst_free_rpcent(&head);
2316 lst_print_transerr(&head, "Run batch");
2318 lst_free_rpcent(&head);
2324 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2326 struct lstio_batch_stop_args args = { 0 };
2328 args.lstio_bat_key = session_key;
2329 args.lstio_bat_force = force;
2330 args.lstio_bat_nmlen = strlen(name);
2331 args.lstio_bat_namep = name;
2332 args.lstio_bat_resultp = resultp;
2334 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2338 jt_lst_stop_batch(int argc, char **argv)
2340 struct list_head head;
2348 static const struct option stop_batch_opts[] = {
2349 { .name = "force", .has_arg = no_argument, .val = 'f' },
2352 if (session_key == 0) {
2354 "Can't find env LST_SESSION or value is not valid\n");
2359 c = getopt_long(argc, argv, "f",
2360 stop_batch_opts, &optidx);
2362 /* Detect the end of the options. */
2371 lst_print_usage(argv[0]);
2376 if (optind == argc) {
2377 batch = LST_DEFAULT_BATCH;
2379 } else if (optind == argc - 1) {
2380 batch = argv[optind];
2383 lst_print_usage(argv[0]);
2387 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2389 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2390 batch, strerror(errno));
2394 INIT_LIST_HEAD(&head);
2396 rc = lst_alloc_rpcent(&head, count, 0);
2398 fprintf(stderr, "Out of memory\n");
2402 rc = lst_stop_batch_ioctl(batch, force, &head);
2407 lst_reset_rpcent(&head);
2409 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2413 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2414 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2417 fprintf(stdout, "%d batch in stopping\n",
2418 lstcon_tsbqry_stat_run(&trans_stat, 0));
2422 fprintf(stdout, "Batch is stopped\n");
2423 lst_free_rpcent(&head);
2428 lst_print_error("batch", "Failed to stop batch: %s\n",
2430 lst_free_rpcent(&head);
2434 lst_print_transerr(&head, "stop batch");
2436 lst_free_rpcent(&head);
2442 lst_list_batch_ioctl(int len, char *name, int index)
2444 struct lstio_batch_list_args args = { 0 };
2446 args.lstio_bat_key = session_key;
2447 args.lstio_bat_idx = index;
2448 args.lstio_bat_nmlen = len;
2449 args.lstio_bat_namep = name;
2451 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2455 lst_info_batch_ioctl(char *batch, int test, int server,
2456 struct lstcon_test_batch_ent *entp, int *idxp,
2457 int *ndentp, struct lstcon_node_ent *dentsp)
2459 struct lstio_batch_info_args args = { 0 };
2461 args.lstio_bat_key = session_key;
2462 args.lstio_bat_nmlen = strlen(batch);
2463 args.lstio_bat_namep = batch;
2464 args.lstio_bat_server = server;
2465 args.lstio_bat_testidx = test;
2466 args.lstio_bat_entp = entp;
2467 args.lstio_bat_idxp = idxp;
2468 args.lstio_bat_ndentp = ndentp;
2469 args.lstio_bat_dentsp = dentsp;
2471 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2475 lst_list_batch_all(void)
2477 char name[LST_NAME_SIZE];
2481 for (i = 0; ; i++) {
2482 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2484 fprintf(stdout, "%d) %s\n", i + 1, name);
2488 if (errno == ENOENT)
2491 lst_print_error("batch", "Failed to list batch: %s\n",
2496 fprintf(stdout, "Total %d batches\n", i);
2502 lst_list_tsb_nodes(char *batch, int test, int server,
2503 int count, int active, int invalid)
2505 struct lstcon_node_ent *dents;
2514 /* verbose list, show nodes in batch or test */
2515 dents = malloc(count * sizeof(struct lstcon_node_ent));
2516 if (dents == NULL) {
2517 fprintf(stdout, "Can't allocate memory\n");
2521 rc = lst_info_batch_ioctl(batch, test, server,
2522 NULL, &index, &count, dents);
2525 lst_print_error((test > 0) ? "test" : "batch",
2526 (test > 0) ? "Failed to query test: %s\n" :
2527 "Failed to query batch: %s\n",
2532 for (i = 0, c = 0; i < count; i++) {
2533 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2534 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2535 dents[i].nde_state == LST_NODE_DOWN ||
2536 dents[i].nde_state == LST_NODE_UNKNOWN)))
2539 fprintf(stdout, "\t%s: %s\n",
2540 libcfs_id2str(dents[i].nde_id),
2541 lst_node_state2str(dents[i].nde_state));
2545 fprintf(stdout, "Total %d nodes\n", c);
2552 jt_lst_list_batch(int argc, char **argv)
2554 struct lstcon_test_batch_ent ent;
2557 int verbose = 0; /* list nodes in batch or test */
2566 static const struct option list_batch_opts[] = {
2567 { .name = "test", .has_arg = required_argument, .val = 't' },
2568 { .name = "invalid", .has_arg = no_argument, .val = 'i' },
2569 { .name = "active", .has_arg = no_argument, .val = 'a' },
2570 { .name = "all", .has_arg = no_argument, .val = 'l' },
2571 { .name = "server", .has_arg = no_argument, .val = 's' },
2572 { .name = NULL, } };
2574 if (session_key == 0) {
2576 "Can't find env LST_SESSION or value is not valid\n");
2581 c = getopt_long(argc, argv, "ailst:",
2582 list_batch_opts, &optidx);
2589 verbose = active = 1;
2592 verbose = invalid = 1;
2595 verbose = active = invalid = 1;
2601 test = atoi(optarg);
2605 lst_print_usage(argv[0]);
2610 if (optind == argc) {
2611 /* list all batches */
2612 rc = lst_list_batch_all();
2616 if (ntest == 1 && test <= 0) {
2617 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2621 if (optind != argc - 1) {
2622 lst_print_usage(argv[0]);
2626 batch = argv[optind];
2629 /* show detail of specified batch or test */
2630 rc = lst_info_batch_ioctl(batch, test, server,
2631 &ent, NULL, NULL, NULL);
2633 lst_print_error((test > 0) ? "test" : "batch",
2634 (test > 0) ? "Failed to query test: %s\n" :
2635 "Failed to query batch: %s\n",
2641 /* list nodes in test or batch */
2642 rc = lst_list_tsb_nodes(batch, test, server,
2643 server ? ent.tbe_srv_nle.nle_nnode :
2644 ent.tbe_cli_nle.nle_nnode,
2649 /* only show number of hosts in batch or test */
2651 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2652 batch, ent.u.tbe_batch.bae_ntest,
2653 ent.u.tbe_batch.bae_state);
2654 ntest = ent.u.tbe_batch.bae_ntest;
2655 test = 1; /* starting from test 1 */
2659 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2660 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2661 ent.u.tbe_test.tse_loop,
2662 ent.u.tbe_test.tse_concur);
2667 fprintf(stdout, LST_NODES_TITLE);
2668 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2669 "server\t%d\t%d\t%d\t%d\t%d\n",
2670 ent.tbe_cli_nle.nle_nactive,
2671 ent.tbe_cli_nle.nle_nbusy,
2672 ent.tbe_cli_nle.nle_ndown,
2673 ent.tbe_cli_nle.nle_nunknown,
2674 ent.tbe_cli_nle.nle_nnode,
2675 ent.tbe_srv_nle.nle_nactive,
2676 ent.tbe_srv_nle.nle_nbusy,
2677 ent.tbe_srv_nle.nle_ndown,
2678 ent.tbe_srv_nle.nle_nunknown,
2679 ent.tbe_srv_nle.nle_nnode);
2688 lst_query_batch_ioctl(char *batch, int test, int server,
2689 int timeout, struct list_head *head)
2691 struct lstio_batch_query_args args = { 0 };
2693 args.lstio_bat_key = session_key;
2694 args.lstio_bat_testidx = test;
2695 args.lstio_bat_client = !(server);
2696 args.lstio_bat_timeout = timeout;
2697 args.lstio_bat_nmlen = strlen(batch);
2698 args.lstio_bat_namep = batch;
2699 args.lstio_bat_resultp = head;
2701 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2705 lst_print_tsb_verbose(struct list_head *head,
2706 int active, int idle, int error)
2708 struct lstcon_rpc_ent *ent;
2710 list_for_each_entry(ent, head, rpe_link) {
2711 if (ent->rpe_priv[0] == 0 && active)
2714 if (ent->rpe_priv[0] != 0 && idle)
2717 if (ent->rpe_fwk_errno == 0 && error)
2720 fprintf(stdout, "%s [%s]: %s\n",
2721 libcfs_id2str(ent->rpe_peer),
2722 lst_node_state2str(ent->rpe_state),
2723 ent->rpe_rpc_errno != 0 ?
2724 strerror(ent->rpe_rpc_errno) :
2725 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2730 jt_lst_query_batch(int argc, char **argv)
2732 struct lstcon_test_batch_ent ent;
2733 struct list_head head;
2739 int timeout = 5; /* default 5 seconds */
2740 int delay = 5; /* default 5 seconds */
2741 int loop = 1; /* default 1 loop */
2751 static const struct option query_batch_opts[] = {
2752 { .name = "timeout", .has_arg = required_argument, .val = 'o' },
2753 { .name = "delay", .has_arg = required_argument, .val = 'd' },
2754 { .name = "loop", .has_arg = required_argument, .val = 'c' },
2755 { .name = "test", .has_arg = required_argument, .val = 't' },
2756 { .name = "server", .has_arg = no_argument, .val = 's' },
2757 { .name = "active", .has_arg = no_argument, .val = 'a' },
2758 { .name = "idle", .has_arg = no_argument, .val = 'i' },
2759 { .name = "error", .has_arg = no_argument, .val = 'e' },
2760 { .name = "all", .has_arg = no_argument, .val = 'l' },
2761 { .name = NULL, } };
2763 if (session_key == 0) {
2765 "Can't find env LST_SESSION or value is not valid\n");
2770 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2771 query_batch_opts, &optidx);
2773 /* Detect the end of the options. */
2779 timeout = atoi(optarg);
2782 delay = atoi(optarg);
2785 loop = atoi(optarg);
2788 test = atoi(optarg);
2794 active = verbose = 1;
2800 error = verbose = 1;
2806 lst_print_usage(argv[0]);
2811 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2812 lst_print_usage(argv[0]);
2816 if (optind == argc) {
2817 batch = LST_DEFAULT_BATCH;
2819 } else if (optind == argc - 1) {
2820 batch = argv[optind];
2823 lst_print_usage(argv[0]);
2828 INIT_LIST_HEAD(&head);
2831 rc = lst_info_batch_ioctl(batch, test, server,
2832 &ent, NULL, NULL, NULL);
2834 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2835 batch, test, strerror(errno));
2839 count = server ? ent.tbe_srv_nle.nle_nnode :
2840 ent.tbe_cli_nle.nle_nnode;
2842 fprintf(stdout, "Batch or test is empty\n");
2847 rc = lst_alloc_rpcent(&head, count, 0);
2849 fprintf(stderr, "Out of memory\n");
2853 for (i = 0; i < loop; i++) {
2854 time_t now = time(NULL);
2856 if (now - last < delay) {
2857 sleep(delay - now + last);
2863 rc = lst_query_batch_ioctl(batch, test,
2864 server, timeout, &head);
2866 fprintf(stderr, "Failed to query batch: %s\n",
2873 lst_print_tsb_verbose(&head, active, idle, error);
2877 fprintf(stdout, "%s [%d] ", batch, test);
2879 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2880 fprintf(stdout, "%d of %d nodes are unknown, ",
2881 lstcon_rpc_stat_failure(&trans_stat, 0),
2882 lstcon_rpc_stat_total(&trans_stat, 0));
2885 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2886 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2887 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2888 fprintf(stdout, "is stopped\n");
2892 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2893 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2894 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2895 fprintf(stdout, "is running\n");
2899 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2900 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2901 lstcon_tsbqry_stat_run(&trans_stat, 0),
2902 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2905 lst_free_rpcent(&head);
2911 lst_parse_distribute(char *dstr, int *dist, int *span)
2917 dstr = strchr(dstr, ':');
2921 *span = atoi(dstr + 1);
2929 lst_get_bulk_param(int argc, char **argv, struct lst_test_bulk_param *bulk)
2936 bulk->blk_size = 4096;
2937 bulk->blk_opc = LST_BRW_READ;
2938 bulk->blk_flags = LST_BRW_CHECK_NONE;
2939 bulk->blk_srv_off = bulk->blk_cli_off = 0;
2942 if (strcasestr(argv[i], "check=") == argv[i] ||
2943 strcasestr(argv[i], "c=") == argv[i]) {
2944 tok = strchr(argv[i], '=') + 1;
2946 if (strcasecmp(tok, "full") == 0) {
2947 bulk->blk_flags = LST_BRW_CHECK_FULL;
2948 } else if (strcasecmp(tok, "simple") == 0) {
2949 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2951 fprintf(stderr, "Unknow flag %s\n", tok);
2955 } else if (strcasestr(argv[i], "size=") == argv[i] ||
2956 strcasestr(argv[i], "s=") == argv[i]) {
2957 int max_size = sysconf(_SC_PAGESIZE) * LNET_MAX_IOV;
2959 tok = strchr(argv[i], '=') + 1;
2961 bulk->blk_size = strtol(tok, &end, 0);
2962 if (bulk->blk_size <= 0) {
2963 fprintf(stderr, "Invalid size %s\n", tok);
2970 if (*end == 'k' || *end == 'K')
2971 bulk->blk_size *= 1024;
2972 else if (*end == 'm' || *end == 'M')
2973 bulk->blk_size *= 1024 * 1024;
2975 if (bulk->blk_size > max_size) {
2976 fprintf(stderr, "Size exceed limitation: %d bytes\n",
2981 } else if (strcasestr(argv[i], "off=") == argv[i]) {
2984 tok = strchr(argv[i], '=') + 1;
2986 off = strtol(tok, &end, 0);
2987 /* NB: align with sizeof(__u64) to simplify page
2988 * checking implementation */
2989 if (off < 0 || off % sizeof(__u64) != 0) {
2991 "Invalid offset %s/%d, it should be "
2992 "postive value and multiple of %d\n",
2993 tok, off, (int)sizeof(__u64));
2997 /* NB: blk_srv_off is reserved so far */
2998 bulk->blk_cli_off = bulk->blk_srv_off = off;
3002 } else if (strcasecmp(argv[i], "read") == 0 ||
3003 strcasecmp(argv[i], "r") == 0) {
3004 bulk->blk_opc = LST_BRW_READ;
3006 } else if (strcasecmp(argv[i], "write") == 0 ||
3007 strcasecmp(argv[i], "w") == 0) {
3008 bulk->blk_opc = LST_BRW_WRITE;
3011 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
3022 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
3024 struct lst_test_bulk_param *bulk = NULL;
3027 type = lst_test_name2type(test);
3029 fprintf(stderr, "Unknow test name %s\n", test);
3038 bulk = malloc(sizeof(*bulk));
3040 fprintf(stderr, "Out of memory\n");
3044 memset(bulk, 0, sizeof(*bulk));
3046 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
3052 *plen = sizeof(*bulk);
3060 /* TODO: parse more parameter */
3065 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
3066 int dist, int span, char *sgrp, char *dgrp,
3067 void *param, int plen, int *retp, struct list_head *resultp)
3069 struct lstio_test_args args = { 0 };
3071 args.lstio_tes_key = session_key;
3072 args.lstio_tes_bat_nmlen = strlen(batch);
3073 args.lstio_tes_bat_name = batch;
3074 args.lstio_tes_type = type;
3075 args.lstio_tes_oneside = 0;
3076 args.lstio_tes_loop = loop;
3077 args.lstio_tes_concur = concur;
3078 args.lstio_tes_dist = dist;
3079 args.lstio_tes_span = span;
3080 args.lstio_tes_sgrp_nmlen = strlen(sgrp);
3081 args.lstio_tes_sgrp_name = sgrp;
3082 args.lstio_tes_dgrp_nmlen = strlen(dgrp);
3083 args.lstio_tes_dgrp_name = dgrp;
3084 args.lstio_tes_param_len = plen;
3085 args.lstio_tes_param = param;
3086 args.lstio_tes_retp = retp;
3087 args.lstio_tes_resultp = resultp;
3089 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
3093 jt_lst_add_test(int argc, char **argv)
3095 struct list_head head;
3115 static const struct option add_test_opts[] = {
3116 { .name = "batch", .has_arg = required_argument, .val = 'b' },
3117 { .name = "concurrency", .has_arg = required_argument, .val = 'c' },
3118 { .name = "distribute", .has_arg = required_argument, .val = 'd' },
3119 { .name = "from", .has_arg = required_argument, .val = 'f' },
3120 { .name = "to", .has_arg = required_argument, .val = 't' },
3121 { .name = "loop", .has_arg = required_argument, .val = 'l' },
3124 if (session_key == 0) {
3126 "Can't find env LST_SESSION or value is not valid\n");
3131 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3132 add_test_opts, &optidx);
3134 /* Detect the end of the options. */
3143 concur = atoi(optarg);
3152 loop = atoi(optarg);
3158 lst_print_usage(argv[0]);
3163 if (optind == argc || from == NULL || to == NULL) {
3164 lst_print_usage(argv[0]);
3168 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3169 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3174 batch = LST_DEFAULT_BATCH;
3177 rc = lst_parse_distribute(dstr, &dist, &span);
3179 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3184 test = argv[optind++];
3189 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3191 fprintf(stderr, "Failed to add test (%s)\n", test);
3195 INIT_LIST_HEAD(&head);
3197 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3199 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3200 from, strerror(errno));
3204 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3206 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3207 to, strerror(errno));
3211 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3213 fprintf(stderr, "Out of memory\n");
3217 rc = lst_add_test_ioctl(batch, type, loop, concur,
3218 dist, span, from, to, param, plen, &ret, &head);
3221 fprintf(stdout, "Test was added successfully\n");
3223 fprintf(stdout, "Server group contains userland test "
3224 "nodes, old version of tcplnd can't accept "
3225 "connection request\n");
3232 lst_print_error("test", "Failed to add test: %s\n",
3237 lst_print_transerr(&head, "add test");
3239 lst_free_rpcent(&head);
3247 static command_t lst_cmdlist[] = {
3248 {"new_session", jt_lst_new_session, NULL,
3249 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3250 {"end_session", jt_lst_end_session, NULL,
3251 "Usage: lst end_session" },
3252 {"show_session", jt_lst_show_session, NULL,
3253 "Usage: lst show_session" },
3254 {"ping", jt_lst_ping , NULL,
3255 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3256 {"add_group", jt_lst_add_group, NULL,
3257 "Usage: lst group NAME IDs [IDs]..." },
3258 {"del_group", jt_lst_del_group, NULL,
3259 "Usage: lst del_group NAME" },
3260 {"update_group", jt_lst_update_group, NULL,
3261 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3262 {"list_group", jt_lst_list_group, NULL,
3263 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3264 {"stat", jt_lst_stat, NULL,
3265 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3266 " [--mbs] [--timeout #] [--delay #] [--count #] GROUP [GROUP]" },
3267 {"show_error", jt_lst_show_error, NULL,
3268 "Usage: lst show_error NAME | IDS ..." },
3269 {"add_batch", jt_lst_add_batch, NULL,
3270 "Usage: lst add_batch NAME" },
3271 {"run", jt_lst_start_batch, NULL,
3272 "Usage: lst run [--timeout TIME] [NAME]" },
3273 {"stop", jt_lst_stop_batch, NULL,
3274 "Usage: lst stop [--force] BATCH_NAME" },
3275 {"list_batch", jt_lst_list_batch, NULL,
3276 "Usage: lst list_batch NAME [--test ID] [--server]" },
3277 {"query", jt_lst_query_batch, NULL,
3278 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3279 {"add_test", jt_lst_add_test, NULL,
3280 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3281 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3282 {"help", Parser_help, 0, "help" },
3283 {"--list-commands", lst_list_commands, 0, "list commands" },
3288 lst_initialize(void)
3293 feats = getenv("LST_FEATURES");
3295 session_features = strtol(feats, NULL, 16);
3297 if ((session_features & ~LST_FEATS_MASK) != 0) {
3299 "Unsupported session features %x, "
3300 "only support these features so far: %x\n",
3301 (session_features & ~LST_FEATS_MASK), LST_FEATS_MASK);
3305 key = getenv("LST_SESSION");
3312 session_key = atoi(key);
3317 static int lst_list_commands(int argc, char **argv)
3319 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
3321 Parser_list_commands(lst_cmdlist, buffer, sizeof(buffer), NULL, 0, 4);
3327 main(int argc, char **argv)
3333 rc = lst_initialize();
3337 rc = lustre_lnet_config_lib_init();
3339 rc = register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
3344 Parser_init("lst > ", lst_cmdlist);
3347 rc = Parser_execarg(argc - 1, argv + 1, lst_cmdlist);