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, 2017, 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>
54 #include "lnetconfig/liblnetconfig.h"
56 struct lst_sid LST_INVALID_SID = { .ses_nid = LNET_NID_ANY, .ses_stamp = -1 };
57 static struct lst_sid session_id;
58 static int session_key;
59 static int lst_list_commands(int argc, char **argv);
61 /* All nodes running 2.6.50 or later understand feature LST_FEAT_BULK_LEN */
62 static unsigned session_features = LST_FEATS_MASK;
63 static struct lstcon_trans_stat trans_stat;
65 typedef struct list_string {
66 struct list_string *lstr_next;
72 # define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
75 static int alloc_count = 0;
76 static int alloc_nob = 0;
81 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
84 fprintf(stderr, "Can't allocate lstr\n");
91 lstr->lstr_str[0] = 0;
97 free_lstr(lstr_t *lstr)
100 alloc_nob -= lstr->lstr_sz;
105 free_lstrs(lstr_t **list)
109 while ((lstr = *list) != NULL) {
110 *list = lstr->lstr_next;
116 new_lstrs(lstr_t **list, char *prefix, char *postfix,
117 int lo, int hi, int stride)
119 int n1 = strlen(prefix);
120 int n2 = strlen(postfix);
121 int sz = n1 + 20 + n2 + 1;
124 lstr_t *n = alloc_lstr(sz);
126 snprintf(n->lstr_str, sz - 1, "%s%u%s",
127 prefix, lo, postfix);
129 n->lstr_next = *list;
137 expand_lstr(lstr_t **list, lstr_t *l)
139 int nob = strlen(l->lstr_str);
149 b1 = strchr(l->lstr_str, '[');
151 l->lstr_next = *list;
156 b2 = strchr(b1, ']');
157 if (b2 == NULL || b2 == b1 + 1)
165 sep = strchr(expr, ',');
171 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
173 new_lstrs(list, l->lstr_str, b2, x, x, 1);
178 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
181 new_lstrs(list, l->lstr_str, b2, x, y, 1);
186 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
189 new_lstrs(list, l->lstr_str, b2, x, y, z);
195 } while ((expr = sep) != NULL);
203 expand_strs(char *str, lstr_t **head)
211 l = alloc_lstr(strlen(str) + 1);
212 memcpy(l->lstr_str, str, strlen(str) + 1);
220 while ((l = list) != NULL) {
223 rc = expand_lstr(&nlist, l);
225 fprintf(stderr, "Syntax error in \"%s\"\n", str);
233 /* re-order onto 'list' */
234 while ((l = nlist) != NULL) {
235 nlist = l->lstr_next;
240 } while (expanded && rc > 0);
247 while ((l = list) != NULL) {
256 lst_parse_nids(char *str, int *countp, struct lnet_process_id **idspp)
264 rc = expand_strs(str, &head);
274 *idspp = malloc(c * sizeof(struct lnet_process_id));
275 if (*idspp == NULL) {
276 fprintf(stderr, "Out of memory\n");
283 while ((l = head) != NULL) {
287 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
288 if ((*idspp)[i].nid == LNET_NID_ANY) {
289 fprintf(stderr, "Invalid nid: %s\n",
294 (*idspp)[i].pid = LNET_PID_LUSTRE;
311 lst_node_state2str(int state)
313 if (state == LST_NODE_ACTIVE)
315 if (state == LST_NODE_BUSY)
317 if (state == LST_NODE_DOWN)
324 lst_node_str2state(char *str)
326 if (strcasecmp(str, "active") == 0)
327 return LST_NODE_ACTIVE;
328 if (strcasecmp(str, "busy") == 0)
329 return LST_NODE_BUSY;
330 if (strcasecmp(str, "down") == 0)
331 return LST_NODE_DOWN;
332 if (strcasecmp(str, "unknown") == 0)
333 return LST_NODE_UNKNOWN;
334 if (strcasecmp(str, "invalid") == 0)
335 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
341 lst_test_type2name(int type)
343 if (type == LST_TEST_PING)
345 if (type == LST_TEST_BULK)
352 lst_test_name2type(char *name)
354 if (strcasecmp(name, "ping") == 0)
355 return LST_TEST_PING;
356 if (strcasecmp(name, "brw") == 0)
357 return LST_TEST_BULK;
363 lst_print_usage(char *cmd)
365 Parser_printhelp(cmd);
369 lst_print_error(char *sub, const char *def_format, ...)
373 /* local error returned from kernel */
376 fprintf(stderr, "No session exists\n");
379 fprintf(stderr, "Session is shutting down\n");
382 fprintf(stderr, "Unmatched session key or not root\n");
385 fprintf(stderr, "Can't find %s in current session\n", sub);
388 fprintf(stderr, "Invalid parameters list in command line\n");
391 fprintf(stderr, "Bad parameter address\n");
394 fprintf(stderr, "%s already exists\n", sub);
397 va_start(ap, def_format);
398 vfprintf(stderr, def_format, ap);
406 lst_free_rpcent(struct list_head *head)
408 struct lstcon_rpc_ent *ent;
410 while (!list_empty(head)) {
411 ent = list_entry(head->next, struct lstcon_rpc_ent, rpe_link);
413 list_del(&ent->rpe_link);
419 lst_reset_rpcent(struct list_head *head)
421 struct lstcon_rpc_ent *ent;
423 list_for_each_entry(ent, head, rpe_link) {
424 ent->rpe_sid = LST_INVALID_SID;
425 ent->rpe_peer.nid = LNET_NID_ANY;
426 ent->rpe_peer.pid = LNET_PID_ANY;
427 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
432 lst_alloc_rpcent(struct list_head *head, int count, int offset)
434 struct lstcon_rpc_ent *ent;
437 for (i = 0; i < count; i++) {
438 ent = malloc(offsetof(struct lstcon_rpc_ent, rpe_payload[offset]));
440 lst_free_rpcent(head);
444 memset(ent, 0, offsetof(struct lstcon_rpc_ent, rpe_payload[offset]));
446 ent->rpe_sid = LST_INVALID_SID;
447 ent->rpe_peer.nid = LNET_NID_ANY;
448 ent->rpe_peer.pid = LNET_PID_ANY;
449 list_add(&ent->rpe_link, head);
456 lst_print_transerr(struct list_head *head, char *optstr)
458 struct lstcon_rpc_ent *ent;
460 list_for_each_entry(ent, head, rpe_link) {
461 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
464 if (ent->rpe_rpc_errno != 0) {
465 fprintf(stderr, "%s RPC failed on %s: %s\n",
466 optstr, libcfs_id2str(ent->rpe_peer),
467 strerror(ent->rpe_rpc_errno));
471 fprintf(stderr, "operation %s failed on %s: %s\n",
472 optstr, libcfs_id2str(ent->rpe_peer),
473 strerror(ent->rpe_fwk_errno));
477 int lst_info_batch_ioctl(char *batch, int test, int server,
478 struct lstcon_test_batch_ent *entp, int *idxp,
479 int *ndentp, struct lstcon_node_ent *dentsp);
481 int lst_info_group_ioctl(char *name, struct lstcon_ndlist_ent *gent,
482 int *idx, int *count, struct lstcon_node_ent *dents);
484 int lst_query_batch_ioctl(char *batch, int test, int server,
485 int timeout, struct list_head *head);
488 lst_ioctl(unsigned int opc, void *buf, int len)
490 struct libcfs_ioctl_data data;
493 LIBCFS_IOC_INIT (data);
494 data.ioc_u32[0] = opc;
495 data.ioc_plen1 = len;
496 data.ioc_pbuf1 = (char *)buf;
497 data.ioc_plen2 = sizeof(trans_stat);
498 data.ioc_pbuf2 = (char *)&trans_stat;
500 memset(&trans_stat, 0, sizeof(trans_stat));
502 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
504 /* local error, no valid RPC result */
509 if (trans_stat.trs_rpc_errno != 0)
512 /* Framework error */
513 if (trans_stat.trs_fwk_errno != 0)
520 lst_new_session_ioctl(char *name, int timeout, int force, struct lst_sid *sid)
522 struct lstio_session_new_args args = { 0 };
524 args.lstio_ses_key = session_key;
525 args.lstio_ses_timeout = timeout;
526 args.lstio_ses_force = force;
527 args.lstio_ses_idp = sid;
528 args.lstio_ses_feats = session_features;
529 args.lstio_ses_nmlen = strlen(name);
530 args.lstio_ses_namep = name;
532 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
536 jt_lst_new_session(int argc, char **argv)
538 char buf[LST_NAME_SIZE * 2 + 1];
546 static const struct option session_opts[] = {
547 { .name = "timeout", .has_arg = required_argument, .val = 't' },
548 { .name = "force", .has_arg = no_argument, .val = 'f' },
551 if (session_key == 0) {
553 "Can't find env LST_SESSION or value is not valid\n");
559 c = getopt_long(argc, argv, "ft:",
560 session_opts, &optidx);
570 timeout = atoi(optarg);
573 lst_print_usage(argv[0]);
579 fprintf(stderr, "Invalid timeout value\n");
583 if (optind == argc - 1) {
584 name = argv[optind ++];
585 if (strlen(name) >= LST_NAME_SIZE) {
586 fprintf(stderr, "Name size is limited to %d\n",
591 } else if (optind == argc) {
592 char user[LST_NAME_SIZE];
593 char host[LST_NAME_SIZE];
594 struct passwd *pw = getpwuid(getuid());
597 snprintf(user, sizeof(user), "%d", (int)getuid());
599 snprintf(user, sizeof(user), "%s", pw->pw_name);
601 rc = gethostname(host, sizeof(host));
603 snprintf(host, sizeof(host), "unknown_host");
605 snprintf(buf, sizeof(buf), "%s@%s", user, host);
609 lst_print_usage(argv[0]);
613 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
615 lst_print_error("session", "Failed to create session: %s\n",
620 fprintf(stdout, "SESSION: %s FEATURES: %x TIMEOUT: %d FORCE: %s\n",
621 name, session_features, timeout, force ? "Yes" : "No");
626 lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp,
627 struct lst_sid *sid, struct lstcon_ndlist_ent *ndinfo)
629 struct lstio_session_info_args args = { 0 };
631 args.lstio_ses_idp = sid;
632 args.lstio_ses_keyp = key;
633 args.lstio_ses_featp = featp;
634 args.lstio_ses_ndinfo = ndinfo;
635 args.lstio_ses_nmlen = len;
636 args.lstio_ses_namep = name;
638 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
642 jt_lst_show_session(int argc, char **argv)
644 struct lstcon_ndlist_ent ndinfo;
646 char name[LST_NAME_SIZE];
651 rc = lst_session_info_ioctl(name, sizeof(name), &key,
652 &feats, &sid, &ndinfo);
655 lst_print_error("session", "Failed to show session: %s\n",
660 fprintf(stdout, "%s ID: %ju@%s, KEY: %d FEATURES: %x NODES: %d\n",
661 name, (uintmax_t)sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
662 key, feats, ndinfo.nle_nnode);
668 lst_end_session_ioctl(void)
670 struct lstio_session_end_args args = { 0 };
672 args.lstio_ses_key = session_key;
673 return lst_ioctl(LSTIO_SESSION_END, &args, sizeof(args));
677 jt_lst_end_session(int argc, char **argv)
681 if (session_key == 0) {
683 "Can't find env LST_SESSION or value is not valid\n");
687 rc = lst_end_session_ioctl();
690 fprintf(stdout, "session is ended\n");
695 lst_print_error("session", "Failed to end session: %s\n",
700 if (trans_stat.trs_rpc_errno != 0) {
702 "[RPC] Failed to send %d session RPCs: %s\n",
703 lstcon_rpc_stat_failure(&trans_stat, 0),
704 strerror(trans_stat.trs_rpc_errno));
707 if (trans_stat.trs_fwk_errno != 0) {
709 "[FWK] Failed to end session on %d nodes: %s\n",
710 lstcon_sesop_stat_failure(&trans_stat, 0),
711 strerror(trans_stat.trs_fwk_errno));
718 lst_ping_ioctl(char *str, int type, int timeout,
719 int count, struct lnet_process_id *ids, struct list_head *head)
721 struct lstio_debug_args args = { 0 };
723 args.lstio_dbg_key = session_key;
724 args.lstio_dbg_type = type;
725 args.lstio_dbg_flags = 0;
726 args.lstio_dbg_timeout = timeout;
727 args.lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str);
728 args.lstio_dbg_namep = str;
729 args.lstio_dbg_count = count;
730 args.lstio_dbg_idsp = ids;
731 args.lstio_dbg_resultp = head;
733 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
737 lst_get_node_count(int type, char *str, int *countp,
738 struct lnet_process_id **idspp)
740 char buf[LST_NAME_SIZE];
741 struct lstcon_test_batch_ent ent;
742 struct lstcon_ndlist_ent *entp = &ent.tbe_cli_nle;
749 case LST_OPC_SESSION:
750 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
751 &key, &feats, &sid, entp);
754 case LST_OPC_BATCHSRV:
755 entp = &ent.tbe_srv_nle;
756 case LST_OPC_BATCHCLI:
757 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
761 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
765 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
774 *countp = entp->nle_nnode;
780 jt_lst_ping(int argc, char **argv)
782 struct list_head head;
783 struct lnet_process_id *ids = NULL;
784 struct lstcon_rpc_ent *ent = NULL;
794 static const struct option ping_opts[] = {
795 { .name = "session", .has_arg = no_argument, .val = 's' },
796 { .name = "server", .has_arg = no_argument, .val = 'v' },
797 { .name = "batch", .has_arg = required_argument, .val = 'b' },
798 { .name = "group", .has_arg = required_argument, .val = 'g' },
799 { .name = "nodes", .has_arg = required_argument, .val = 'n' },
800 { .name = "timeout", .has_arg = required_argument, .val = 't' },
803 if (session_key == 0) {
805 "Can't find env LST_SESSION or value is not valid\n");
811 c = getopt_long(argc, argv, "g:b:n:t:sv",
819 type = LST_OPC_SESSION;
823 type = LST_OPC_GROUP;
828 type = LST_OPC_BATCHCLI;
833 type = LST_OPC_NODES;
838 timeout = atoi(optarg);
846 lst_print_usage(argv[0]);
851 if (type == 0 || timeout <= 0 || optind != argc) {
852 lst_print_usage(argv[0]);
856 if (type == LST_OPC_BATCHCLI && server)
857 type = LST_OPC_BATCHSRV;
859 rc = lst_get_node_count(type, str, &count, &ids);
861 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
862 (str == NULL) ? "session" : str, strerror(errno));
866 INIT_LIST_HEAD(&head);
868 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
870 fprintf(stderr, "Out of memory\n");
875 fprintf(stdout, "Target %s is empty\n",
876 (str == NULL) ? "session" : str);
880 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
881 if (rc == -1) { /* local failure */
882 lst_print_error("debug", "Failed to ping %s: %s\n",
883 (str == NULL) ? "session" : str,
889 /* ignore RPC errors and framwork errors */
890 list_for_each_entry(ent, &head, rpe_link) {
891 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
892 libcfs_id2str(ent->rpe_peer),
893 lst_node_state2str(ent->rpe_state),
894 (ent->rpe_state == LST_NODE_ACTIVE ||
895 ent->rpe_state == LST_NODE_BUSY) ?
896 (ent->rpe_rpc_errno == 0 ?
897 &ent->rpe_payload[0] : "Unknown") :
898 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
902 lst_free_rpcent(&head);
912 lst_add_nodes_ioctl(char *name, int count, struct lnet_process_id *ids,
913 unsigned *featp, struct list_head *resultp)
915 struct lstio_group_nodes_args args = { 0 };
917 args.lstio_grp_key = session_key;
918 args.lstio_grp_nmlen = strlen(name);
919 args.lstio_grp_namep = name;
920 args.lstio_grp_count = count;
921 args.lstio_grp_featp = featp;
922 args.lstio_grp_idsp = ids;
923 args.lstio_grp_resultp = resultp;
925 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
929 lst_del_group_ioctl(char *name)
931 struct lstio_group_del_args args = { 0 };
933 args.lstio_grp_key = session_key;
934 args.lstio_grp_nmlen = strlen(name);
935 args.lstio_grp_namep = name;
937 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
941 lst_del_group(char *grp_name)
945 rc = lst_del_group_ioctl(grp_name);
947 fprintf(stdout, "Group is deleted\n");
952 lst_print_error("group", "Failed to delete group: %s\n",
957 fprintf(stderr, "Group is deleted with some errors\n");
959 if (trans_stat.trs_rpc_errno != 0) {
961 "[RPC] Failed to send %d end session RPCs: %s\n",
962 lstcon_rpc_stat_failure(&trans_stat, 0),
963 strerror(trans_stat.trs_rpc_errno));
966 if (trans_stat.trs_fwk_errno != 0) {
968 "[FWK] Failed to end session on %d nodes: %s\n",
969 lstcon_sesop_stat_failure(&trans_stat, 0),
970 strerror(trans_stat.trs_fwk_errno));
977 lst_add_group_ioctl(char *name)
979 struct lstio_group_add_args args = { 0 };
981 args.lstio_grp_key = session_key;
982 args.lstio_grp_nmlen = strlen(name);
983 args.lstio_grp_namep = name;
985 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
989 jt_lst_add_group(int argc, char **argv)
991 struct list_head head;
992 struct lnet_process_id *ids;
994 unsigned feats = session_features;
998 bool nodes_added = false;
1000 if (session_key == 0) {
1002 "Can't find env LST_SESSION or value is not valid\n");
1007 lst_print_usage(argv[0]);
1012 if (strlen(name) >= LST_NAME_SIZE) {
1013 fprintf(stderr, "Name length is limited to %d\n",
1018 rc = lst_add_group_ioctl(name);
1020 lst_print_error("group", "Failed to add group %s: %s\n",
1021 name, strerror(errno));
1025 INIT_LIST_HEAD(&head);
1027 for (i = 2; i < argc; i++) {
1028 /* parse address list */
1029 rc = lst_parse_nids(argv[i], &count, &ids);
1031 fprintf(stderr, "Ignore invalid id list %s\n",
1039 rc = lst_alloc_rpcent(&head, count, 0);
1041 fprintf(stderr, "Out of memory\n");
1047 rc = lst_add_nodes_ioctl(name, count, ids, &feats, &head);
1054 fprintf(stdout, "%s are added to session\n", argv[i]);
1058 if ((feats & session_features) != session_features) {
1060 "Warning, this session will run with "
1061 "compatible mode because some test nodes "
1062 "might not understand these features: %x\n",
1063 (~feats & session_features));
1066 lst_free_rpcent(&head);
1071 * The selftest kernel module expects that a group should
1072 * have at least one node, since it doesn't make sense for
1073 * an empty group to be added to a test.
1076 "No nodes added successfully, deleting group %s\n",
1078 rc = lst_del_group(name);
1081 "Failed to delete group %s."
1082 " Group is empty.\n", name);
1090 lst_print_error("group", "Failed to add nodes %s: %s\n",
1091 argv[i], strerror(errno));
1094 if (trans_stat.trs_fwk_errno == EPROTO) {
1096 "test nodes might have different LST "
1097 "features, please disable some features by "
1098 "setting LST_FEATURES\n");
1101 lst_print_transerr(&head, "create session");
1104 lst_free_rpcent(&head);
1108 "No nodes added successfully, deleting group %s\n",
1110 if (lst_del_group(name) != 0) {
1112 "Failed to delete group %s."
1113 " Group is empty.\n", name);
1121 jt_lst_del_group(int argc, char **argv)
1125 if (session_key == 0) {
1127 "Can't find env LST_SESSION or value is not valid\n");
1132 lst_print_usage(argv[0]);
1136 rc = lst_del_group(argv[1]);
1142 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1143 struct lnet_process_id *ids, struct list_head *resultp)
1145 struct lstio_group_update_args args = { 0 };
1147 args.lstio_grp_key = session_key;
1148 args.lstio_grp_opc = opc;
1149 args.lstio_grp_args = clean;
1150 args.lstio_grp_nmlen = strlen(name);
1151 args.lstio_grp_namep = name;
1152 args.lstio_grp_count = count;
1153 args.lstio_grp_idsp = ids;
1154 args.lstio_grp_resultp = resultp;
1156 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1160 jt_lst_update_group(int argc, char **argv)
1162 struct list_head head;
1163 struct lnet_process_id *ids = NULL;
1173 static const struct option update_group_opts[] = {
1174 { .name = "refresh", .has_arg = no_argument, .val = 'f' },
1175 { .name = "clean", .has_arg = required_argument, .val = 'c' },
1176 { .name = "remove", .has_arg = required_argument, .val = 'r' },
1179 if (session_key == 0) {
1181 "Can't find env LST_SESSION or value is not valid\n");
1186 c = getopt_long(argc, argv, "fc:r:",
1187 update_group_opts, &optidx);
1189 /* Detect the end of the options. */
1196 lst_print_usage(argv[0]);
1199 opc = LST_GROUP_REFRESH;
1204 lst_print_usage(argv[0]);
1207 opc = LST_GROUP_RMND;
1212 clean = lst_node_str2state(optarg);
1213 if (opc != 0 || clean <= 0) {
1214 lst_print_usage(argv[0]);
1217 opc = LST_GROUP_CLEAN;
1221 lst_print_usage(argv[0]);
1226 /* no OPC or group is specified */
1227 if (opc == 0 || optind != argc - 1) {
1228 lst_print_usage(argv[0]);
1234 INIT_LIST_HEAD(&head);
1236 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1237 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1239 opc == LST_GROUP_RMND ? str : grp,
1243 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1244 opc == LST_GROUP_RMND ? str : grp,
1249 rc = lst_alloc_rpcent(&head, count, 0);
1251 fprintf(stderr, "Out of memory\n");
1258 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1264 lst_free_rpcent(&head);
1269 lst_free_rpcent(&head);
1270 lst_print_error("group", "Failed to update group: %s\n",
1275 lst_print_transerr(&head, "Updating group");
1277 lst_free_rpcent(&head);
1283 lst_list_group_ioctl(int len, char *name, int idx)
1285 struct lstio_group_list_args args = { 0 };
1287 args.lstio_grp_key = session_key;
1288 args.lstio_grp_idx = idx;
1289 args.lstio_grp_nmlen = len;
1290 args.lstio_grp_namep = name;
1292 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1296 lst_info_group_ioctl(char *name, struct lstcon_ndlist_ent *gent,
1297 int *idx, int *count, struct lstcon_node_ent *dents)
1299 struct lstio_group_info_args args = { 0 };
1301 args.lstio_grp_key = session_key;
1302 args.lstio_grp_nmlen = strlen(name);
1303 args.lstio_grp_namep = name;
1304 args.lstio_grp_entp = gent;
1305 args.lstio_grp_idxp = idx;
1306 args.lstio_grp_ndentp = count;
1307 args.lstio_grp_dentsp = dents;
1309 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1313 lst_list_group_all(void)
1315 char name[LST_NAME_SIZE];
1319 /* no group is specified, list name of all groups */
1320 for (i = 0; ; i++) {
1321 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1323 fprintf(stdout, "%d) %s\n", i + 1, name);
1327 if (errno == ENOENT)
1330 lst_print_error("group", "Failed to list group: %s\n",
1335 fprintf(stdout, "Total %d groups\n", i);
1340 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1343 jt_lst_list_group(int argc, char **argv)
1345 struct lstcon_ndlist_ent gent;
1346 struct lstcon_node_ent *dents;
1361 static const struct option list_group_opts[] = {
1362 { .name = "active", .has_arg = no_argument, .val = 'a' },
1363 { .name = "busy", .has_arg = no_argument, .val = 'b' },
1364 { .name = "down", .has_arg = no_argument, .val = 'd' },
1365 { .name = "unknown", .has_arg = no_argument, .val = 'u' },
1366 { .name = "all", .has_arg = no_argument, .val = 'l' },
1367 { .name = NULL, } };
1369 if (session_key == 0) {
1371 "Can't find env LST_SESSION or value is not valid\n");
1376 c = getopt_long(argc, argv, "abdul",
1377 list_group_opts, &optidx);
1384 verbose = active = 1;
1396 verbose = unknown = 1;
1403 lst_print_usage(argv[0]);
1408 if (optind == argc) {
1409 /* no group is specified, list name of all groups */
1410 rc = lst_list_group_all();
1416 fprintf(stdout, LST_NODES_TITLE);
1418 /* list nodes in specified groups */
1419 for (i = optind; i < argc; i++) {
1420 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1422 if (errno == ENOENT) {
1427 lst_print_error("group", "Failed to list group\n",
1433 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1434 gent.nle_nactive, gent.nle_nbusy,
1435 gent.nle_ndown, gent.nle_nunknown,
1436 gent.nle_nnode, argv[i]);
1440 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1442 if (gent.nle_nnode == 0) {
1443 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1447 count = gent.nle_nnode;
1449 dents = malloc(count * sizeof(struct lstcon_node_ent));
1450 if (dents == NULL) {
1451 fprintf(stderr, "Failed to malloc: %s\n",
1457 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1459 lst_print_error("group", "Failed to list group: %s\n",
1465 for (j = 0, c = 0; j < count; j++) {
1467 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1468 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1469 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1470 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1472 fprintf(stdout, "\t%s: %s\n",
1473 libcfs_id2str(dents[j].nde_id),
1474 lst_node_state2str(dents[j].nde_state));
1479 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1488 lst_stat_ioctl(char *name, int count, struct lnet_process_id *idsp,
1489 int timeout, struct list_head *resultp)
1491 struct lstio_stat_args args = { 0 };
1493 args.lstio_sta_key = session_key;
1494 args.lstio_sta_timeout = timeout;
1495 args.lstio_sta_nmlen = strlen(name);
1496 args.lstio_sta_namep = name;
1497 args.lstio_sta_count = count;
1498 args.lstio_sta_idsp = idsp;
1499 args.lstio_sta_resultp = resultp;
1501 return lst_ioctl(LSTIO_STAT_QUERY, &args, sizeof(args));
1505 struct list_head srp_link;
1508 struct lnet_process_id *srp_ids;
1509 struct list_head srp_result[2];
1510 } lst_stat_req_param_t;
1513 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1517 for (i = 0; i < 2; i++)
1518 lst_free_rpcent(&srp->srp_result[i]);
1520 if (srp->srp_ids != NULL)
1527 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
1529 lst_stat_req_param_t *srp = NULL;
1530 int count = save_old ? 2 : 1;
1534 srp = malloc(sizeof(*srp));
1538 memset(srp, 0, sizeof(*srp));
1539 INIT_LIST_HEAD(&srp->srp_result[0]);
1540 INIT_LIST_HEAD(&srp->srp_result[1]);
1542 rc = lst_get_node_count(LST_OPC_GROUP, name,
1543 &srp->srp_count, NULL);
1544 if (rc != 0 && errno == ENOENT) {
1545 rc = lst_get_node_count(LST_OPC_NODES, name,
1546 &srp->srp_count, &srp->srp_ids);
1551 "Failed to get count of nodes from %s: %s\n",
1552 name, strerror(errno));
1553 lst_stat_req_param_free(srp);
1558 srp->srp_name = name;
1560 for (i = 0; i < count; i++) {
1561 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1562 sizeof(struct sfw_counters) +
1563 sizeof(struct srpc_counters) +
1564 sizeof(struct lnet_counters_common));
1566 fprintf(stderr, "Out of memory\n");
1576 lst_stat_req_param_free(srp);
1584 } lst_srpc_stat_result;
1586 #define LST_LNET_AVG 0
1587 #define LST_LNET_MIN 1
1588 #define LST_LNET_MAX 2
1591 float lnet_avg_sndrate;
1592 float lnet_min_sndrate;
1593 float lnet_max_sndrate;
1594 float lnet_total_sndrate;
1596 float lnet_avg_rcvrate;
1597 float lnet_min_rcvrate;
1598 float lnet_max_rcvrate;
1599 float lnet_total_rcvrate;
1601 float lnet_avg_sndperf;
1602 float lnet_min_sndperf;
1603 float lnet_max_sndperf;
1604 float lnet_total_sndperf;
1606 float lnet_avg_rcvperf;
1607 float lnet_min_rcvperf;
1608 float lnet_max_rcvperf;
1609 float lnet_total_rcvperf;
1611 int lnet_stat_count;
1612 } lst_lnet_stat_result_t;
1614 lst_lnet_stat_result_t lnet_stat_result;
1617 lst_lnet_stat_value(int bw, int send, int off)
1621 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1622 &lnet_stat_result.lnet_avg_sndrate;
1633 lst_timeval_diff(struct timeval *tv1,
1634 struct timeval *tv2, struct timeval *df)
1636 if (tv1->tv_usec >= tv2->tv_usec) {
1637 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1638 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1642 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1643 df->tv_usec = tv1->tv_usec + 1000000 - tv2->tv_usec;
1647 lst_cal_lnet_stat(float delta, struct lnet_counters_common *lnet_new,
1648 struct lnet_counters_common *lnet_old, int mbs)
1652 unsigned int unit_divisor;
1654 unit_divisor = (mbs) ? (1000 * 1000) : (1024 * 1024);
1655 perf = (float)(lnet_new->lcc_send_length -
1656 lnet_old->lcc_send_length) / unit_divisor / delta;
1657 lnet_stat_result.lnet_total_sndperf += perf;
1659 if (lnet_stat_result.lnet_min_sndperf > perf ||
1660 lnet_stat_result.lnet_min_sndperf == 0)
1661 lnet_stat_result.lnet_min_sndperf = perf;
1663 if (lnet_stat_result.lnet_max_sndperf < perf)
1664 lnet_stat_result.lnet_max_sndperf = perf;
1666 perf = (float)(lnet_new->lcc_recv_length -
1667 lnet_old->lcc_recv_length) / unit_divisor / delta;
1668 lnet_stat_result.lnet_total_rcvperf += perf;
1670 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1671 lnet_stat_result.lnet_min_rcvperf == 0)
1672 lnet_stat_result.lnet_min_rcvperf = perf;
1674 if (lnet_stat_result.lnet_max_rcvperf < perf)
1675 lnet_stat_result.lnet_max_rcvperf = perf;
1677 rate = (lnet_new->lcc_send_count - lnet_old->lcc_send_count) / delta;
1678 lnet_stat_result.lnet_total_sndrate += rate;
1680 if (lnet_stat_result.lnet_min_sndrate > rate ||
1681 lnet_stat_result.lnet_min_sndrate == 0)
1682 lnet_stat_result.lnet_min_sndrate = rate;
1684 if (lnet_stat_result.lnet_max_sndrate < rate)
1685 lnet_stat_result.lnet_max_sndrate = rate;
1687 rate = (lnet_new->lcc_recv_count - lnet_old->lcc_recv_count) / delta;
1688 lnet_stat_result.lnet_total_rcvrate += rate;
1690 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1691 lnet_stat_result.lnet_min_rcvrate == 0)
1692 lnet_stat_result.lnet_min_rcvrate = rate;
1694 if (lnet_stat_result.lnet_max_rcvrate < rate)
1695 lnet_stat_result.lnet_max_rcvrate = rate;
1697 lnet_stat_result.lnet_stat_count++;
1699 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1700 lnet_stat_result.lnet_stat_count;
1701 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1702 lnet_stat_result.lnet_stat_count;
1704 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1705 lnet_stat_result.lnet_stat_count;
1706 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1707 lnet_stat_result.lnet_stat_count;
1711 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type, int mbs)
1721 if (lnet_stat_result.lnet_stat_count == 0)
1724 units = (mbs) ? "MB/s " : "MiB/s ";
1726 if (bwrt == 1) /* bw only */
1729 if (bwrt == 2) /* rates only */
1732 if (rdwr == 1) /* recv only */
1735 if (rdwr == 2) /* send only */
1738 for (i = start1; i <= end1; i++) {
1739 fprintf(stdout, "[LNet %s of %s]\n",
1740 i == 0 ? "Rates" : "Bandwidth", name);
1742 for (j = start2; j <= end2; j++) {
1743 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
1745 if ((type & 1) != 0) {
1746 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1748 lst_lnet_stat_value(i, j, 0), units);
1751 if ((type & 2) != 0) {
1752 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1754 lst_lnet_stat_value(i, j, 1), units);
1757 if ((type & 4) != 0) {
1758 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1760 lst_lnet_stat_value(i, j, 2), units);
1763 fprintf(stdout, "\n");
1769 lst_print_stat(char *name, struct list_head *resultp,
1770 int idx, int lnet, int bwrt, int rdwr, int type,
1773 struct list_head tmp[2];
1774 struct lstcon_rpc_ent *new;
1775 struct lstcon_rpc_ent *old;
1776 struct sfw_counters *sfwk_new;
1777 struct sfw_counters *sfwk_old;
1778 struct srpc_counters *srpc_new;
1779 struct srpc_counters *srpc_old;
1780 struct lnet_counters_common *lnet_new;
1781 struct lnet_counters_common *lnet_old;
1785 INIT_LIST_HEAD(&tmp[0]);
1786 INIT_LIST_HEAD(&tmp[1]);
1788 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1790 while (!list_empty(&resultp[idx])) {
1791 if (list_empty(&resultp[1 - idx])) {
1792 fprintf(stderr, "Group is changed, re-run stat\n");
1796 new = list_entry(resultp[idx].next, struct lstcon_rpc_ent,
1798 old = list_entry(resultp[1 - idx].next, struct lstcon_rpc_ent,
1801 /* first time get stats result, can't calculate diff */
1802 if (new->rpe_peer.nid == LNET_NID_ANY)
1805 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1806 new->rpe_peer.pid != old->rpe_peer.pid) {
1807 /* Something wrong. i.e, somebody change the group */
1811 list_move_tail(&new->rpe_link, &tmp[idx]);
1813 list_move_tail(&old->rpe_link, &tmp[1 - idx]);
1815 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1816 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1821 sfwk_new = (struct sfw_counters *)&new->rpe_payload[0];
1822 sfwk_old = (struct sfw_counters *)&old->rpe_payload[0];
1824 srpc_new = (struct srpc_counters *)((char *)sfwk_new +
1826 srpc_old = (struct srpc_counters *)((char *)sfwk_old +
1829 lnet_new = (struct lnet_counters_common *)((char *)srpc_new +
1831 lnet_old = (struct lnet_counters_common *)((char *)srpc_old +
1834 /* Prior to version 2.3, the running_ms field was a counter for
1835 * the number of running tests. We are looking at this value
1836 * to determine if it is a millisecond timestamep (>= 2.3) or a
1837 * test counter (< 2.3). The number 500 is being used for this
1838 * barrier as the test counter should never get this high, and
1839 * the timestamp should never get this low.
1841 if (sfwk_new->running_ms > 500) {
1842 /* use the timestamp from the remote node, not our
1843 * rpe_stamp from when we copied up the data out of
1846 delta = (float)(sfwk_new->running_ms -
1847 sfwk_old->running_ms) / 1000;
1851 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1852 delta = tv.tv_sec + (float)tv.tv_usec / 1000000;
1855 if (!lnet) /* TODO */
1858 lst_cal_lnet_stat(delta, lnet_new, lnet_old, mbs);
1861 list_splice(&tmp[idx], &resultp[idx]);
1862 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1865 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1867 if (!lnet) /* TODO */
1870 lst_print_lnet_stat(name, bwrt, rdwr, type, mbs);
1874 jt_lst_stat(int argc, char **argv)
1876 struct list_head head;
1877 lst_stat_req_param_t *srp;
1880 int timeout = 5; /* default timeout, 5 sec */
1881 int delay = 5; /* default delay, 5 sec */
1882 int count = -1; /* run forever */
1883 int lnet = 1; /* lnet stat by default */
1890 int mbs = 0; /* report as MB/s */
1892 static const struct option stat_opts[] = {
1893 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1894 { .name = "delay", .has_arg = required_argument, .val = 'd' },
1895 { .name = "count", .has_arg = required_argument, .val = 'o' },
1896 { .name = "lnet", .has_arg = no_argument, .val = 'l' },
1897 { .name = "rpc", .has_arg = no_argument, .val = 'c' },
1898 { .name = "bw", .has_arg = no_argument, .val = 'b' },
1899 { .name = "rate", .has_arg = no_argument, .val = 'a' },
1900 { .name = "read", .has_arg = no_argument, .val = 'r' },
1901 { .name = "write", .has_arg = no_argument, .val = 'w' },
1902 { .name = "avg", .has_arg = no_argument, .val = 'g' },
1903 { .name = "min", .has_arg = no_argument, .val = 'n' },
1904 { .name = "max", .has_arg = no_argument, .val = 'x' },
1905 { .name = "mbs", .has_arg = no_argument, .val = 'm' },
1908 if (session_key == 0) {
1910 "Can't find env LST_SESSION or value is not valid\n");
1915 c = getopt_long(argc, argv, "t:d:lcbarwgnxm", stat_opts,
1923 timeout = atoi(optarg);
1926 delay = atoi(optarg);
1929 count = atoi(optarg);
1975 lst_print_usage(argv[0]);
1980 if (optind == argc) {
1981 lst_print_usage(argv[0]);
1985 if (timeout <= 0 || delay <= 0) {
1986 fprintf(stderr, "Invalid timeout or delay value\n");
1991 fprintf(stderr, "Invalid count value\n");
1995 /* extra count to get first data point */
1999 INIT_LIST_HEAD(&head);
2001 while (optind < argc) {
2002 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
2006 list_add_tail(&srp->srp_link, &head);
2010 time_t now = time(NULL);
2012 if (now - last < delay) {
2013 sleep(delay - now + last);
2018 list_for_each_entry(srp, &head, srp_link) {
2019 rc = lst_stat_ioctl(srp->srp_name,
2020 srp->srp_count, srp->srp_ids,
2021 timeout, &srp->srp_result[idx]);
2023 lst_print_error("stat", "Failed to stat %s: %s\n",
2024 srp->srp_name, strerror(errno));
2028 lst_print_stat(srp->srp_name, srp->srp_result,
2029 idx, lnet, bwrt, rdwr, type, mbs);
2031 lst_reset_rpcent(&srp->srp_result[1 - idx]);
2038 } while (count == -1 || count > 0);
2041 while (!list_empty(&head)) {
2042 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2044 list_del(&srp->srp_link);
2045 lst_stat_req_param_free(srp);
2052 jt_lst_show_error(int argc, char **argv)
2054 struct list_head head;
2055 lst_stat_req_param_t *srp;
2056 struct lstcon_rpc_ent *ent;
2057 struct sfw_counters *sfwk;
2058 struct srpc_counters *srpc;
2065 static const struct option show_error_opts[] = {
2066 { .name = "session", .has_arg = no_argument, .val = 's' },
2067 { .name = NULL, } };
2069 if (session_key == 0) {
2071 "Can't find env LST_SESSION or value is not valid\n");
2076 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
2087 lst_print_usage(argv[0]);
2092 if (optind == argc) {
2093 lst_print_usage(argv[0]);
2097 INIT_LIST_HEAD(&head);
2099 while (optind < argc) {
2100 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
2104 list_add_tail(&srp->srp_link, &head);
2107 list_for_each_entry(srp, &head, srp_link) {
2108 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
2109 srp->srp_ids, 10, &srp->srp_result[0]);
2112 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2113 srp->srp_name, strerror(errno));
2117 fprintf(stdout, "%s:\n", srp->srp_name);
2121 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2122 if (ent->rpe_rpc_errno != 0) {
2124 fprintf(stderr, "RPC failure, can't show error on %s\n",
2125 libcfs_id2str(ent->rpe_peer));
2129 if (ent->rpe_fwk_errno != 0) {
2131 fprintf(stderr, "Framework failure, can't show error on %s\n",
2132 libcfs_id2str(ent->rpe_peer));
2136 sfwk = (struct sfw_counters *)&ent->rpe_payload[0];
2137 srpc = (struct srpc_counters *)((char *)sfwk + sizeof(*sfwk));
2139 if (srpc->errors == 0 &&
2140 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2144 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2149 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2150 libcfs_id2str(ent->rpe_peer),
2151 sfwk->brw_errors, sfwk->ping_errors,
2152 show_rpc ? ' ' : '\n');
2157 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2158 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2161 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2164 while (!list_empty(&head)) {
2165 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2167 list_del(&srp->srp_link);
2168 lst_stat_req_param_free(srp);
2175 lst_add_batch_ioctl(char *name)
2177 struct lstio_batch_add_args args = { 0 };
2179 args.lstio_bat_key = session_key;
2180 args.lstio_bat_nmlen = strlen(name);
2181 args.lstio_bat_namep = name;
2183 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2187 jt_lst_add_batch(int argc, char **argv)
2192 if (session_key == 0) {
2194 "Can't find env LST_SESSION or value is not valid\n");
2199 lst_print_usage(argv[0]);
2204 if (strlen(name) >= LST_NAME_SIZE) {
2205 fprintf(stderr, "Name length is limited to %d\n",
2210 rc = lst_add_batch_ioctl(name);
2214 lst_print_error("batch", "Failed to create batch: %s\n",
2221 lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp)
2223 struct lstio_batch_run_args args = { 0 };
2225 args.lstio_bat_key = session_key;
2226 args.lstio_bat_timeout = timeout;
2227 args.lstio_bat_nmlen = strlen(name);
2228 args.lstio_bat_namep = name;
2229 args.lstio_bat_resultp = resultp;
2231 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2235 jt_lst_start_batch(int argc, char **argv)
2237 struct list_head head;
2245 static const struct option start_batch_opts[] = {
2246 { .name = "timeout", .has_arg = required_argument, .val = 't' },
2249 if (session_key == 0) {
2251 "Can't find env LST_SESSION or value is not valid\n");
2256 c = getopt_long(argc, argv, "t:",
2257 start_batch_opts, &optidx);
2259 /* Detect the end of the options. */
2265 timeout = atoi(optarg);
2268 lst_print_usage(argv[0]);
2273 if (optind == argc) {
2274 batch = LST_DEFAULT_BATCH;
2276 } else if (optind == argc - 1) {
2277 batch = argv[optind];
2280 lst_print_usage(argv[0]);
2284 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2286 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2287 batch, strerror(errno));
2291 INIT_LIST_HEAD(&head);
2293 rc = lst_alloc_rpcent(&head, count, 0);
2295 fprintf(stderr, "Out of memory\n");
2299 rc = lst_start_batch_ioctl(batch, timeout, &head);
2302 fprintf(stdout, "%s is running now\n", batch);
2303 lst_free_rpcent(&head);
2308 lst_print_error("batch", "Failed to start batch: %s\n",
2310 lst_free_rpcent(&head);
2314 lst_print_transerr(&head, "Run batch");
2316 lst_free_rpcent(&head);
2322 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2324 struct lstio_batch_stop_args args = { 0 };
2326 args.lstio_bat_key = session_key;
2327 args.lstio_bat_force = force;
2328 args.lstio_bat_nmlen = strlen(name);
2329 args.lstio_bat_namep = name;
2330 args.lstio_bat_resultp = resultp;
2332 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2336 jt_lst_stop_batch(int argc, char **argv)
2338 struct list_head head;
2346 static const struct option stop_batch_opts[] = {
2347 { .name = "force", .has_arg = no_argument, .val = 'f' },
2350 if (session_key == 0) {
2352 "Can't find env LST_SESSION or value is not valid\n");
2357 c = getopt_long(argc, argv, "f",
2358 stop_batch_opts, &optidx);
2360 /* Detect the end of the options. */
2369 lst_print_usage(argv[0]);
2374 if (optind == argc) {
2375 batch = LST_DEFAULT_BATCH;
2377 } else if (optind == argc - 1) {
2378 batch = argv[optind];
2381 lst_print_usage(argv[0]);
2385 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2387 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2388 batch, strerror(errno));
2392 INIT_LIST_HEAD(&head);
2394 rc = lst_alloc_rpcent(&head, count, 0);
2396 fprintf(stderr, "Out of memory\n");
2400 rc = lst_stop_batch_ioctl(batch, force, &head);
2405 lst_reset_rpcent(&head);
2407 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2411 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2412 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2415 fprintf(stdout, "%d batch in stopping\n",
2416 lstcon_tsbqry_stat_run(&trans_stat, 0));
2420 fprintf(stdout, "Batch is stopped\n");
2421 lst_free_rpcent(&head);
2426 lst_print_error("batch", "Failed to stop batch: %s\n",
2428 lst_free_rpcent(&head);
2432 lst_print_transerr(&head, "stop batch");
2434 lst_free_rpcent(&head);
2440 lst_list_batch_ioctl(int len, char *name, int index)
2442 struct lstio_batch_list_args args = { 0 };
2444 args.lstio_bat_key = session_key;
2445 args.lstio_bat_idx = index;
2446 args.lstio_bat_nmlen = len;
2447 args.lstio_bat_namep = name;
2449 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2453 lst_info_batch_ioctl(char *batch, int test, int server,
2454 struct lstcon_test_batch_ent *entp, int *idxp,
2455 int *ndentp, struct lstcon_node_ent *dentsp)
2457 struct lstio_batch_info_args args = { 0 };
2459 args.lstio_bat_key = session_key;
2460 args.lstio_bat_nmlen = strlen(batch);
2461 args.lstio_bat_namep = batch;
2462 args.lstio_bat_server = server;
2463 args.lstio_bat_testidx = test;
2464 args.lstio_bat_entp = entp;
2465 args.lstio_bat_idxp = idxp;
2466 args.lstio_bat_ndentp = ndentp;
2467 args.lstio_bat_dentsp = dentsp;
2469 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2473 lst_list_batch_all(void)
2475 char name[LST_NAME_SIZE];
2479 for (i = 0; ; i++) {
2480 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2482 fprintf(stdout, "%d) %s\n", i + 1, name);
2486 if (errno == ENOENT)
2489 lst_print_error("batch", "Failed to list batch: %s\n",
2494 fprintf(stdout, "Total %d batches\n", i);
2500 lst_list_tsb_nodes(char *batch, int test, int server,
2501 int count, int active, int invalid)
2503 struct lstcon_node_ent *dents;
2512 /* verbose list, show nodes in batch or test */
2513 dents = malloc(count * sizeof(struct lstcon_node_ent));
2514 if (dents == NULL) {
2515 fprintf(stdout, "Can't allocate memory\n");
2519 rc = lst_info_batch_ioctl(batch, test, server,
2520 NULL, &index, &count, dents);
2523 lst_print_error((test > 0) ? "test" : "batch",
2524 (test > 0) ? "Failed to query test: %s\n" :
2525 "Failed to query batch: %s\n",
2530 for (i = 0, c = 0; i < count; i++) {
2531 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2532 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2533 dents[i].nde_state == LST_NODE_DOWN ||
2534 dents[i].nde_state == LST_NODE_UNKNOWN)))
2537 fprintf(stdout, "\t%s: %s\n",
2538 libcfs_id2str(dents[i].nde_id),
2539 lst_node_state2str(dents[i].nde_state));
2543 fprintf(stdout, "Total %d nodes\n", c);
2550 jt_lst_list_batch(int argc, char **argv)
2552 struct lstcon_test_batch_ent ent;
2555 int verbose = 0; /* list nodes in batch or test */
2564 static const struct option list_batch_opts[] = {
2565 { .name = "test", .has_arg = required_argument, .val = 't' },
2566 { .name = "invalid", .has_arg = no_argument, .val = 'i' },
2567 { .name = "active", .has_arg = no_argument, .val = 'a' },
2568 { .name = "all", .has_arg = no_argument, .val = 'l' },
2569 { .name = "server", .has_arg = no_argument, .val = 's' },
2570 { .name = NULL, } };
2572 if (session_key == 0) {
2574 "Can't find env LST_SESSION or value is not valid\n");
2579 c = getopt_long(argc, argv, "ailst:",
2580 list_batch_opts, &optidx);
2587 verbose = active = 1;
2590 verbose = invalid = 1;
2593 verbose = active = invalid = 1;
2599 test = atoi(optarg);
2603 lst_print_usage(argv[0]);
2608 if (optind == argc) {
2609 /* list all batches */
2610 rc = lst_list_batch_all();
2614 if (ntest == 1 && test <= 0) {
2615 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2619 if (optind != argc - 1) {
2620 lst_print_usage(argv[0]);
2624 batch = argv[optind];
2627 /* show detail of specified batch or test */
2628 rc = lst_info_batch_ioctl(batch, test, server,
2629 &ent, NULL, NULL, NULL);
2631 lst_print_error((test > 0) ? "test" : "batch",
2632 (test > 0) ? "Failed to query test: %s\n" :
2633 "Failed to query batch: %s\n",
2639 /* list nodes in test or batch */
2640 rc = lst_list_tsb_nodes(batch, test, server,
2641 server ? ent.tbe_srv_nle.nle_nnode :
2642 ent.tbe_cli_nle.nle_nnode,
2647 /* only show number of hosts in batch or test */
2649 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2650 batch, ent.u.tbe_batch.bae_ntest,
2651 ent.u.tbe_batch.bae_state);
2652 ntest = ent.u.tbe_batch.bae_ntest;
2653 test = 1; /* starting from test 1 */
2657 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2658 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2659 ent.u.tbe_test.tse_loop,
2660 ent.u.tbe_test.tse_concur);
2665 fprintf(stdout, LST_NODES_TITLE);
2666 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2667 "server\t%d\t%d\t%d\t%d\t%d\n",
2668 ent.tbe_cli_nle.nle_nactive,
2669 ent.tbe_cli_nle.nle_nbusy,
2670 ent.tbe_cli_nle.nle_ndown,
2671 ent.tbe_cli_nle.nle_nunknown,
2672 ent.tbe_cli_nle.nle_nnode,
2673 ent.tbe_srv_nle.nle_nactive,
2674 ent.tbe_srv_nle.nle_nbusy,
2675 ent.tbe_srv_nle.nle_ndown,
2676 ent.tbe_srv_nle.nle_nunknown,
2677 ent.tbe_srv_nle.nle_nnode);
2686 lst_query_batch_ioctl(char *batch, int test, int server,
2687 int timeout, struct list_head *head)
2689 struct lstio_batch_query_args args = { 0 };
2691 args.lstio_bat_key = session_key;
2692 args.lstio_bat_testidx = test;
2693 args.lstio_bat_client = !(server);
2694 args.lstio_bat_timeout = timeout;
2695 args.lstio_bat_nmlen = strlen(batch);
2696 args.lstio_bat_namep = batch;
2697 args.lstio_bat_resultp = head;
2699 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2703 lst_print_tsb_verbose(struct list_head *head,
2704 int active, int idle, int error)
2706 struct lstcon_rpc_ent *ent;
2708 list_for_each_entry(ent, head, rpe_link) {
2709 if (ent->rpe_priv[0] == 0 && active)
2712 if (ent->rpe_priv[0] != 0 && idle)
2715 if (ent->rpe_fwk_errno == 0 && error)
2718 fprintf(stdout, "%s [%s]: %s\n",
2719 libcfs_id2str(ent->rpe_peer),
2720 lst_node_state2str(ent->rpe_state),
2721 ent->rpe_rpc_errno != 0 ?
2722 strerror(ent->rpe_rpc_errno) :
2723 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2728 jt_lst_query_batch(int argc, char **argv)
2730 struct lstcon_test_batch_ent ent;
2731 struct list_head head;
2737 int timeout = 5; /* default 5 seconds */
2738 int delay = 5; /* default 5 seconds */
2739 int loop = 1; /* default 1 loop */
2749 static const struct option query_batch_opts[] = {
2750 { .name = "timeout", .has_arg = required_argument, .val = 'o' },
2751 { .name = "delay", .has_arg = required_argument, .val = 'd' },
2752 { .name = "loop", .has_arg = required_argument, .val = 'c' },
2753 { .name = "test", .has_arg = required_argument, .val = 't' },
2754 { .name = "server", .has_arg = no_argument, .val = 's' },
2755 { .name = "active", .has_arg = no_argument, .val = 'a' },
2756 { .name = "idle", .has_arg = no_argument, .val = 'i' },
2757 { .name = "error", .has_arg = no_argument, .val = 'e' },
2758 { .name = "all", .has_arg = no_argument, .val = 'l' },
2759 { .name = NULL, } };
2761 if (session_key == 0) {
2763 "Can't find env LST_SESSION or value is not valid\n");
2768 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2769 query_batch_opts, &optidx);
2771 /* Detect the end of the options. */
2777 timeout = atoi(optarg);
2780 delay = atoi(optarg);
2783 loop = atoi(optarg);
2786 test = atoi(optarg);
2792 active = verbose = 1;
2798 error = verbose = 1;
2804 lst_print_usage(argv[0]);
2809 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2810 lst_print_usage(argv[0]);
2814 if (optind == argc) {
2815 batch = LST_DEFAULT_BATCH;
2817 } else if (optind == argc - 1) {
2818 batch = argv[optind];
2821 lst_print_usage(argv[0]);
2826 INIT_LIST_HEAD(&head);
2829 rc = lst_info_batch_ioctl(batch, test, server,
2830 &ent, NULL, NULL, NULL);
2832 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2833 batch, test, strerror(errno));
2837 count = server ? ent.tbe_srv_nle.nle_nnode :
2838 ent.tbe_cli_nle.nle_nnode;
2840 fprintf(stdout, "Batch or test is empty\n");
2845 rc = lst_alloc_rpcent(&head, count, 0);
2847 fprintf(stderr, "Out of memory\n");
2851 for (i = 0; i < loop; i++) {
2852 time_t now = time(NULL);
2854 if (now - last < delay) {
2855 sleep(delay - now + last);
2861 rc = lst_query_batch_ioctl(batch, test,
2862 server, timeout, &head);
2864 fprintf(stderr, "Failed to query batch: %s\n",
2871 lst_print_tsb_verbose(&head, active, idle, error);
2875 fprintf(stdout, "%s [%d] ", batch, test);
2877 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2878 fprintf(stdout, "%d of %d nodes are unknown, ",
2879 lstcon_rpc_stat_failure(&trans_stat, 0),
2880 lstcon_rpc_stat_total(&trans_stat, 0));
2883 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2884 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2885 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2886 fprintf(stdout, "is stopped\n");
2890 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2891 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2892 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2893 fprintf(stdout, "is running\n");
2897 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2898 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2899 lstcon_tsbqry_stat_run(&trans_stat, 0),
2900 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2903 lst_free_rpcent(&head);
2909 lst_parse_distribute(char *dstr, int *dist, int *span)
2915 dstr = strchr(dstr, ':');
2919 *span = atoi(dstr + 1);
2927 lst_get_bulk_param(int argc, char **argv, struct lst_test_bulk_param *bulk)
2934 bulk->blk_size = 4096;
2935 bulk->blk_opc = LST_BRW_READ;
2936 bulk->blk_flags = LST_BRW_CHECK_NONE;
2937 bulk->blk_srv_off = bulk->blk_cli_off = 0;
2940 if (strcasestr(argv[i], "check=") == argv[i] ||
2941 strcasestr(argv[i], "c=") == argv[i]) {
2942 tok = strchr(argv[i], '=') + 1;
2944 if (strcasecmp(tok, "full") == 0) {
2945 bulk->blk_flags = LST_BRW_CHECK_FULL;
2946 } else if (strcasecmp(tok, "simple") == 0) {
2947 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2949 fprintf(stderr, "Unknow flag %s\n", tok);
2953 } else if (strcasestr(argv[i], "size=") == argv[i] ||
2954 strcasestr(argv[i], "s=") == argv[i]) {
2955 tok = strchr(argv[i], '=') + 1;
2957 bulk->blk_size = strtol(tok, &end, 0);
2958 if (bulk->blk_size <= 0) {
2959 fprintf(stderr, "Invalid size %s\n", tok);
2966 if (*end == 'k' || *end == 'K')
2967 bulk->blk_size *= 1024;
2968 else if (*end == 'm' || *end == 'M')
2969 bulk->blk_size *= 1024 * 1024;
2971 if (bulk->blk_size > LNET_MTU) {
2972 fprintf(stderr, "Size exceed limitation: %d bytes\n",
2977 } else if (strcasestr(argv[i], "off=") == argv[i]) {
2980 tok = strchr(argv[i], '=') + 1;
2982 off = strtol(tok, &end, 0);
2983 /* NB: align with sizeof(__u64) to simplify page
2984 * checking implementation */
2985 if (off < 0 || off % sizeof(__u64) != 0) {
2987 "Invalid offset %s/%d, it should be "
2988 "postive value and multiple of %d\n",
2989 tok, off, (int)sizeof(__u64));
2993 /* NB: blk_srv_off is reserved so far */
2994 bulk->blk_cli_off = bulk->blk_srv_off = off;
2998 } else if (strcasecmp(argv[i], "read") == 0 ||
2999 strcasecmp(argv[i], "r") == 0) {
3000 bulk->blk_opc = LST_BRW_READ;
3002 } else if (strcasecmp(argv[i], "write") == 0 ||
3003 strcasecmp(argv[i], "w") == 0) {
3004 bulk->blk_opc = LST_BRW_WRITE;
3007 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
3018 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
3020 struct lst_test_bulk_param *bulk = NULL;
3023 type = lst_test_name2type(test);
3025 fprintf(stderr, "Unknow test name %s\n", test);
3034 bulk = malloc(sizeof(*bulk));
3036 fprintf(stderr, "Out of memory\n");
3040 memset(bulk, 0, sizeof(*bulk));
3042 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
3048 *plen = sizeof(*bulk);
3056 /* TODO: parse more parameter */
3061 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
3062 int dist, int span, char *sgrp, char *dgrp,
3063 void *param, int plen, int *retp, struct list_head *resultp)
3065 struct lstio_test_args args = { 0 };
3067 args.lstio_tes_key = session_key;
3068 args.lstio_tes_bat_nmlen = strlen(batch);
3069 args.lstio_tes_bat_name = batch;
3070 args.lstio_tes_type = type;
3071 args.lstio_tes_oneside = 0;
3072 args.lstio_tes_loop = loop;
3073 args.lstio_tes_concur = concur;
3074 args.lstio_tes_dist = dist;
3075 args.lstio_tes_span = span;
3076 args.lstio_tes_sgrp_nmlen = strlen(sgrp);
3077 args.lstio_tes_sgrp_name = sgrp;
3078 args.lstio_tes_dgrp_nmlen = strlen(dgrp);
3079 args.lstio_tes_dgrp_name = dgrp;
3080 args.lstio_tes_param_len = plen;
3081 args.lstio_tes_param = param;
3082 args.lstio_tes_retp = retp;
3083 args.lstio_tes_resultp = resultp;
3085 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
3089 jt_lst_add_test(int argc, char **argv)
3091 struct list_head head;
3111 static const struct option add_test_opts[] = {
3112 { .name = "batch", .has_arg = required_argument, .val = 'b' },
3113 { .name = "concurrency", .has_arg = required_argument, .val = 'c' },
3114 { .name = "distribute", .has_arg = required_argument, .val = 'd' },
3115 { .name = "from", .has_arg = required_argument, .val = 'f' },
3116 { .name = "to", .has_arg = required_argument, .val = 't' },
3117 { .name = "loop", .has_arg = required_argument, .val = 'l' },
3120 if (session_key == 0) {
3122 "Can't find env LST_SESSION or value is not valid\n");
3127 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3128 add_test_opts, &optidx);
3130 /* Detect the end of the options. */
3139 concur = atoi(optarg);
3148 loop = atoi(optarg);
3154 lst_print_usage(argv[0]);
3159 if (optind == argc || from == NULL || to == NULL) {
3160 lst_print_usage(argv[0]);
3164 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3165 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3170 batch = LST_DEFAULT_BATCH;
3173 rc = lst_parse_distribute(dstr, &dist, &span);
3175 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3180 test = argv[optind++];
3185 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3187 fprintf(stderr, "Failed to add test (%s)\n", test);
3191 INIT_LIST_HEAD(&head);
3193 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3195 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3196 from, strerror(errno));
3200 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3202 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3203 to, strerror(errno));
3207 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3209 fprintf(stderr, "Out of memory\n");
3213 rc = lst_add_test_ioctl(batch, type, loop, concur,
3214 dist, span, from, to, param, plen, &ret, &head);
3217 fprintf(stdout, "Test was added successfully\n");
3219 fprintf(stdout, "Server group contains userland test "
3220 "nodes, old version of tcplnd can't accept "
3221 "connection request\n");
3228 lst_print_error("test", "Failed to add test: %s\n",
3233 lst_print_transerr(&head, "add test");
3235 lst_free_rpcent(&head);
3243 static command_t lst_cmdlist[] = {
3244 {"new_session", jt_lst_new_session, NULL,
3245 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3246 {"end_session", jt_lst_end_session, NULL,
3247 "Usage: lst end_session" },
3248 {"show_session", jt_lst_show_session, NULL,
3249 "Usage: lst show_session" },
3250 {"ping", jt_lst_ping , NULL,
3251 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3252 {"add_group", jt_lst_add_group, NULL,
3253 "Usage: lst group NAME IDs [IDs]..." },
3254 {"del_group", jt_lst_del_group, NULL,
3255 "Usage: lst del_group NAME" },
3256 {"update_group", jt_lst_update_group, NULL,
3257 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3258 {"list_group", jt_lst_list_group, NULL,
3259 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3260 {"stat", jt_lst_stat, NULL,
3261 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3262 " [--mbs] [--timeout #] [--delay #] [--count #] GROUP [GROUP]" },
3263 {"show_error", jt_lst_show_error, NULL,
3264 "Usage: lst show_error NAME | IDS ..." },
3265 {"add_batch", jt_lst_add_batch, NULL,
3266 "Usage: lst add_batch NAME" },
3267 {"run", jt_lst_start_batch, NULL,
3268 "Usage: lst run [--timeout TIME] [NAME]" },
3269 {"stop", jt_lst_stop_batch, NULL,
3270 "Usage: lst stop [--force] BATCH_NAME" },
3271 {"list_batch", jt_lst_list_batch, NULL,
3272 "Usage: lst list_batch NAME [--test ID] [--server]" },
3273 {"query", jt_lst_query_batch, NULL,
3274 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3275 {"add_test", jt_lst_add_test, NULL,
3276 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3277 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3278 {"help", Parser_help, 0, "help" },
3279 {"--list-commands", lst_list_commands, 0, "list commands" },
3284 lst_initialize(void)
3289 feats = getenv("LST_FEATURES");
3291 session_features = strtol(feats, NULL, 16);
3293 if ((session_features & ~LST_FEATS_MASK) != 0) {
3295 "Unsupported session features %x, "
3296 "only support these features so far: %x\n",
3297 (session_features & ~LST_FEATS_MASK), LST_FEATS_MASK);
3301 key = getenv("LST_SESSION");
3308 session_key = atoi(key);
3313 static int lst_list_commands(int argc, char **argv)
3315 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
3317 Parser_list_commands(lst_cmdlist, buffer, sizeof(buffer), NULL, 0, 4);
3323 main(int argc, char **argv)
3329 rc = lst_initialize();
3333 rc = lustre_lnet_config_lib_init();
3337 Parser_init("lst > ", lst_cmdlist);
3340 rc = Parser_execarg(argc - 1, argv + 1, lst_cmdlist);