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>
47 #include <linux/types.h>
49 #include <libcfs/util/list.h>
50 #include <libcfs/util/ioctl.h>
51 #include <libcfs/util/parser.h>
52 #include <linux/lnet/lnetctl.h>
53 #include <linux/lnet/lnetst.h>
54 #include <linux/lnet/nidstr.h>
55 #include "lnetconfig/liblnetconfig.h"
57 struct lst_sid LST_INVALID_SID = { .ses_nid = LNET_NID_ANY, .ses_stamp = -1 };
58 static struct lst_sid session_id;
59 static int session_key;
60 static int lst_list_commands(int argc, char **argv);
62 /* All nodes running 2.6.50 or later understand feature LST_FEAT_BULK_LEN */
63 static unsigned session_features = LST_FEATS_MASK;
64 static struct lstcon_trans_stat trans_stat;
66 typedef struct list_string {
67 struct list_string *lstr_next;
73 # define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
76 static int alloc_count = 0;
77 static int alloc_nob = 0;
82 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
85 fprintf(stderr, "Can't allocate lstr\n");
92 lstr->lstr_str[0] = 0;
98 free_lstr(lstr_t *lstr)
101 alloc_nob -= lstr->lstr_sz;
106 free_lstrs(lstr_t **list)
110 while ((lstr = *list) != NULL) {
111 *list = lstr->lstr_next;
117 new_lstrs(lstr_t **list, char *prefix, char *postfix,
118 int lo, int hi, int stride)
120 int n1 = strlen(prefix);
121 int n2 = strlen(postfix);
122 int sz = n1 + 20 + n2 + 1;
125 lstr_t *n = alloc_lstr(sz);
127 snprintf(n->lstr_str, sz - 1, "%s%u%s",
128 prefix, lo, postfix);
130 n->lstr_next = *list;
138 expand_lstr(lstr_t **list, lstr_t *l)
140 int nob = strlen(l->lstr_str);
150 b1 = strchr(l->lstr_str, '[');
152 l->lstr_next = *list;
157 b2 = strchr(b1, ']');
158 if (b2 == NULL || b2 == b1 + 1)
166 sep = strchr(expr, ',');
172 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
174 new_lstrs(list, l->lstr_str, b2, x, x, 1);
179 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
182 new_lstrs(list, l->lstr_str, b2, x, y, 1);
187 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
190 new_lstrs(list, l->lstr_str, b2, x, y, z);
196 } while ((expr = sep) != NULL);
204 expand_strs(char *str, lstr_t **head)
212 l = alloc_lstr(strlen(str) + 1);
213 memcpy(l->lstr_str, str, strlen(str) + 1);
221 while ((l = list) != NULL) {
224 rc = expand_lstr(&nlist, l);
226 fprintf(stderr, "Syntax error in \"%s\"\n", str);
234 /* re-order onto 'list' */
235 while ((l = nlist) != NULL) {
236 nlist = l->lstr_next;
241 } while (expanded && rc > 0);
248 while ((l = list) != NULL) {
257 lst_parse_nids(char *str, int *countp, struct lnet_process_id **idspp)
265 rc = expand_strs(str, &head);
275 *idspp = malloc(c * sizeof(struct lnet_process_id));
276 if (*idspp == NULL) {
277 fprintf(stderr, "Out of memory\n");
284 while ((l = head) != NULL) {
288 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
289 if ((*idspp)[i].nid == LNET_NID_ANY) {
290 fprintf(stderr, "Invalid nid: %s\n",
295 (*idspp)[i].pid = LNET_PID_LUSTRE;
312 lst_node_state2str(int state)
314 if (state == LST_NODE_ACTIVE)
316 if (state == LST_NODE_BUSY)
318 if (state == LST_NODE_DOWN)
325 lst_node_str2state(char *str)
327 if (strcasecmp(str, "active") == 0)
328 return LST_NODE_ACTIVE;
329 if (strcasecmp(str, "busy") == 0)
330 return LST_NODE_BUSY;
331 if (strcasecmp(str, "down") == 0)
332 return LST_NODE_DOWN;
333 if (strcasecmp(str, "unknown") == 0)
334 return LST_NODE_UNKNOWN;
335 if (strcasecmp(str, "invalid") == 0)
336 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
342 lst_test_type2name(int type)
344 if (type == LST_TEST_PING)
346 if (type == LST_TEST_BULK)
353 lst_test_name2type(char *name)
355 if (strcasecmp(name, "ping") == 0)
356 return LST_TEST_PING;
357 if (strcasecmp(name, "brw") == 0)
358 return LST_TEST_BULK;
364 lst_print_usage(char *cmd)
366 Parser_printhelp(cmd);
370 lst_print_error(char *sub, const char *def_format, ...)
374 /* local error returned from kernel */
377 fprintf(stderr, "No session exists\n");
380 fprintf(stderr, "Session is shutting down\n");
383 fprintf(stderr, "Unmatched session key or not root\n");
386 fprintf(stderr, "Can't find %s in current session\n", sub);
389 fprintf(stderr, "Invalid parameters list in command line\n");
392 fprintf(stderr, "Bad parameter address\n");
395 fprintf(stderr, "%s already exists\n", sub);
398 va_start(ap, def_format);
399 vfprintf(stderr, def_format, ap);
407 lst_free_rpcent(struct list_head *head)
409 struct lstcon_rpc_ent *ent;
411 while (!list_empty(head)) {
412 ent = list_entry(head->next, struct lstcon_rpc_ent, rpe_link);
414 list_del(&ent->rpe_link);
420 lst_reset_rpcent(struct list_head *head)
422 struct lstcon_rpc_ent *ent;
424 list_for_each_entry(ent, head, rpe_link) {
425 ent->rpe_sid = LST_INVALID_SID;
426 ent->rpe_peer.nid = LNET_NID_ANY;
427 ent->rpe_peer.pid = LNET_PID_ANY;
428 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
433 lst_alloc_rpcent(struct list_head *head, int count, int offset)
435 struct lstcon_rpc_ent *ent;
438 for (i = 0; i < count; i++) {
439 ent = malloc(offsetof(struct lstcon_rpc_ent, rpe_payload[offset]));
441 lst_free_rpcent(head);
445 memset(ent, 0, offsetof(struct lstcon_rpc_ent, rpe_payload[offset]));
447 ent->rpe_sid = LST_INVALID_SID;
448 ent->rpe_peer.nid = LNET_NID_ANY;
449 ent->rpe_peer.pid = LNET_PID_ANY;
450 list_add(&ent->rpe_link, head);
457 lst_print_transerr(struct list_head *head, char *optstr)
459 struct lstcon_rpc_ent *ent;
461 list_for_each_entry(ent, head, rpe_link) {
462 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
465 if (ent->rpe_rpc_errno != 0) {
466 fprintf(stderr, "%s RPC failed on %s: %s\n",
467 optstr, libcfs_id2str(ent->rpe_peer),
468 strerror(ent->rpe_rpc_errno));
472 fprintf(stderr, "operation %s failed on %s: %s\n",
473 optstr, libcfs_id2str(ent->rpe_peer),
474 strerror(ent->rpe_fwk_errno));
478 int lst_info_batch_ioctl(char *batch, int test, int server,
479 struct lstcon_test_batch_ent *entp, int *idxp,
480 int *ndentp, struct lstcon_node_ent *dentsp);
482 int lst_info_group_ioctl(char *name, struct lstcon_ndlist_ent *gent,
483 int *idx, int *count, struct lstcon_node_ent *dents);
485 int lst_query_batch_ioctl(char *batch, int test, int server,
486 int timeout, struct list_head *head);
489 lst_ioctl(unsigned int opc, void *buf, int len)
491 struct libcfs_ioctl_data data;
494 LIBCFS_IOC_INIT (data);
495 data.ioc_u32[0] = opc;
496 data.ioc_plen1 = len;
497 data.ioc_pbuf1 = (char *)buf;
498 data.ioc_plen2 = sizeof(trans_stat);
499 data.ioc_pbuf2 = (char *)&trans_stat;
501 memset(&trans_stat, 0, sizeof(trans_stat));
503 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
505 /* local error, no valid RPC result */
510 if (trans_stat.trs_rpc_errno != 0)
513 /* Framework error */
514 if (trans_stat.trs_fwk_errno != 0)
521 lst_new_session_ioctl(char *name, int timeout, int force, struct lst_sid *sid)
523 struct lstio_session_new_args args = { 0 };
525 args.lstio_ses_key = session_key;
526 args.lstio_ses_timeout = timeout;
527 args.lstio_ses_force = force;
528 args.lstio_ses_idp = sid;
529 args.lstio_ses_feats = session_features;
530 args.lstio_ses_nmlen = strlen(name);
531 args.lstio_ses_namep = name;
533 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
537 jt_lst_new_session(int argc, char **argv)
539 char buf[LST_NAME_SIZE * 2 + 1];
547 static const struct option session_opts[] = {
548 { .name = "timeout", .has_arg = required_argument, .val = 't' },
549 { .name = "force", .has_arg = no_argument, .val = 'f' },
552 if (session_key == 0) {
554 "Can't find env LST_SESSION or value is not valid\n");
560 c = getopt_long(argc, argv, "ft:",
561 session_opts, &optidx);
571 timeout = atoi(optarg);
574 lst_print_usage(argv[0]);
580 fprintf(stderr, "Invalid timeout value\n");
584 if (optind == argc - 1) {
585 name = argv[optind ++];
586 if (strlen(name) >= LST_NAME_SIZE) {
587 fprintf(stderr, "Name size is limited to %d\n",
592 } else if (optind == argc) {
593 char user[LST_NAME_SIZE];
594 char host[LST_NAME_SIZE];
595 struct passwd *pw = getpwuid(getuid());
598 snprintf(user, sizeof(user), "%d", (int)getuid());
600 snprintf(user, sizeof(user), "%s", pw->pw_name);
602 rc = gethostname(host, sizeof(host));
604 snprintf(host, sizeof(host), "unknown_host");
606 snprintf(buf, sizeof(buf), "%s@%s", user, host);
610 lst_print_usage(argv[0]);
614 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
616 lst_print_error("session", "Failed to create session: %s\n",
621 fprintf(stdout, "SESSION: %s FEATURES: %x TIMEOUT: %d FORCE: %s\n",
622 name, session_features, timeout, force ? "Yes" : "No");
627 lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp,
628 struct lst_sid *sid, struct lstcon_ndlist_ent *ndinfo)
630 struct lstio_session_info_args args = { 0 };
632 args.lstio_ses_idp = sid;
633 args.lstio_ses_keyp = key;
634 args.lstio_ses_featp = featp;
635 args.lstio_ses_ndinfo = ndinfo;
636 args.lstio_ses_nmlen = len;
637 args.lstio_ses_namep = name;
639 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
643 jt_lst_show_session(int argc, char **argv)
645 struct lstcon_ndlist_ent ndinfo;
647 char name[LST_NAME_SIZE];
652 rc = lst_session_info_ioctl(name, sizeof(name), &key,
653 &feats, &sid, &ndinfo);
656 lst_print_error("session", "Failed to show session: %s\n",
661 fprintf(stdout, "%s ID: %ju@%s, KEY: %d FEATURES: %x NODES: %d\n",
662 name, (uintmax_t)sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
663 key, feats, ndinfo.nle_nnode);
669 lst_end_session_ioctl(void)
671 struct lstio_session_end_args args = { 0 };
673 args.lstio_ses_key = session_key;
674 return lst_ioctl(LSTIO_SESSION_END, &args, sizeof(args));
678 jt_lst_end_session(int argc, char **argv)
682 if (session_key == 0) {
684 "Can't find env LST_SESSION or value is not valid\n");
688 rc = lst_end_session_ioctl();
691 fprintf(stdout, "session is ended\n");
696 lst_print_error("session", "Failed to end session: %s\n",
701 if (trans_stat.trs_rpc_errno != 0) {
703 "[RPC] Failed to send %d session RPCs: %s\n",
704 lstcon_rpc_stat_failure(&trans_stat, 0),
705 strerror(trans_stat.trs_rpc_errno));
708 if (trans_stat.trs_fwk_errno != 0) {
710 "[FWK] Failed to end session on %d nodes: %s\n",
711 lstcon_sesop_stat_failure(&trans_stat, 0),
712 strerror(trans_stat.trs_fwk_errno));
719 lst_ping_ioctl(char *str, int type, int timeout,
720 int count, struct lnet_process_id *ids, struct list_head *head)
722 struct lstio_debug_args args = { 0 };
724 args.lstio_dbg_key = session_key;
725 args.lstio_dbg_type = type;
726 args.lstio_dbg_flags = 0;
727 args.lstio_dbg_timeout = timeout;
728 args.lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str);
729 args.lstio_dbg_namep = str;
730 args.lstio_dbg_count = count;
731 args.lstio_dbg_idsp = ids;
732 args.lstio_dbg_resultp = head;
734 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
738 lst_get_node_count(int type, char *str, int *countp,
739 struct lnet_process_id **idspp)
741 char buf[LST_NAME_SIZE];
742 struct lstcon_test_batch_ent ent;
743 struct lstcon_ndlist_ent *entp = &ent.tbe_cli_nle;
750 case LST_OPC_SESSION:
751 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
752 &key, &feats, &sid, entp);
755 case LST_OPC_BATCHSRV:
756 entp = &ent.tbe_srv_nle;
757 case LST_OPC_BATCHCLI:
758 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
762 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
766 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
775 *countp = entp->nle_nnode;
781 jt_lst_ping(int argc, char **argv)
783 struct list_head head;
784 struct lnet_process_id *ids = NULL;
785 struct lstcon_rpc_ent *ent = NULL;
795 static const struct option ping_opts[] = {
796 { .name = "session", .has_arg = no_argument, .val = 's' },
797 { .name = "server", .has_arg = no_argument, .val = 'v' },
798 { .name = "batch", .has_arg = required_argument, .val = 'b' },
799 { .name = "group", .has_arg = required_argument, .val = 'g' },
800 { .name = "nodes", .has_arg = required_argument, .val = 'n' },
801 { .name = "timeout", .has_arg = required_argument, .val = 't' },
804 if (session_key == 0) {
806 "Can't find env LST_SESSION or value is not valid\n");
812 c = getopt_long(argc, argv, "g:b:n:t:sv",
820 type = LST_OPC_SESSION;
824 type = LST_OPC_GROUP;
829 type = LST_OPC_BATCHCLI;
834 type = LST_OPC_NODES;
839 timeout = atoi(optarg);
847 lst_print_usage(argv[0]);
852 if (type == 0 || timeout <= 0 || optind != argc) {
853 lst_print_usage(argv[0]);
857 if (type == LST_OPC_BATCHCLI && server)
858 type = LST_OPC_BATCHSRV;
860 rc = lst_get_node_count(type, str, &count, &ids);
862 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
863 (str == NULL) ? "session" : str, strerror(errno));
867 INIT_LIST_HEAD(&head);
869 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
871 fprintf(stderr, "Out of memory\n");
876 fprintf(stdout, "Target %s is empty\n",
877 (str == NULL) ? "session" : str);
881 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
882 if (rc == -1) { /* local failure */
883 lst_print_error("debug", "Failed to ping %s: %s\n",
884 (str == NULL) ? "session" : str,
890 /* ignore RPC errors and framwork errors */
891 list_for_each_entry(ent, &head, rpe_link) {
892 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
893 libcfs_id2str(ent->rpe_peer),
894 lst_node_state2str(ent->rpe_state),
895 (ent->rpe_state == LST_NODE_ACTIVE ||
896 ent->rpe_state == LST_NODE_BUSY) ?
897 (ent->rpe_rpc_errno == 0 ?
898 &ent->rpe_payload[0] : "Unknown") :
899 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
903 lst_free_rpcent(&head);
913 lst_add_nodes_ioctl(char *name, int count, struct lnet_process_id *ids,
914 unsigned *featp, struct list_head *resultp)
916 struct lstio_group_nodes_args args = { 0 };
918 args.lstio_grp_key = session_key;
919 args.lstio_grp_nmlen = strlen(name);
920 args.lstio_grp_namep = name;
921 args.lstio_grp_count = count;
922 args.lstio_grp_featp = featp;
923 args.lstio_grp_idsp = ids;
924 args.lstio_grp_resultp = resultp;
926 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
930 lst_del_group_ioctl(char *name)
932 struct lstio_group_del_args args = { 0 };
934 args.lstio_grp_key = session_key;
935 args.lstio_grp_nmlen = strlen(name);
936 args.lstio_grp_namep = name;
938 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
942 lst_del_group(char *grp_name)
946 rc = lst_del_group_ioctl(grp_name);
948 fprintf(stdout, "Group is deleted\n");
953 lst_print_error("group", "Failed to delete group: %s\n",
958 fprintf(stderr, "Group is deleted with some errors\n");
960 if (trans_stat.trs_rpc_errno != 0) {
962 "[RPC] Failed to send %d end session RPCs: %s\n",
963 lstcon_rpc_stat_failure(&trans_stat, 0),
964 strerror(trans_stat.trs_rpc_errno));
967 if (trans_stat.trs_fwk_errno != 0) {
969 "[FWK] Failed to end session on %d nodes: %s\n",
970 lstcon_sesop_stat_failure(&trans_stat, 0),
971 strerror(trans_stat.trs_fwk_errno));
978 lst_add_group_ioctl(char *name)
980 struct lstio_group_add_args args = { 0 };
982 args.lstio_grp_key = session_key;
983 args.lstio_grp_nmlen = strlen(name);
984 args.lstio_grp_namep = name;
986 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
990 jt_lst_add_group(int argc, char **argv)
992 struct list_head head;
993 struct lnet_process_id *ids;
995 unsigned feats = session_features;
999 bool nodes_added = false;
1001 if (session_key == 0) {
1003 "Can't find env LST_SESSION or value is not valid\n");
1008 lst_print_usage(argv[0]);
1013 if (strlen(name) >= LST_NAME_SIZE) {
1014 fprintf(stderr, "Name length is limited to %d\n",
1019 rc = lst_add_group_ioctl(name);
1021 lst_print_error("group", "Failed to add group %s: %s\n",
1022 name, strerror(errno));
1026 INIT_LIST_HEAD(&head);
1028 for (i = 2; i < argc; i++) {
1029 /* parse address list */
1030 rc = lst_parse_nids(argv[i], &count, &ids);
1032 fprintf(stderr, "Ignore invalid id list %s\n",
1040 rc = lst_alloc_rpcent(&head, count, 0);
1042 fprintf(stderr, "Out of memory\n");
1048 rc = lst_add_nodes_ioctl(name, count, ids, &feats, &head);
1055 fprintf(stdout, "%s are added to session\n", argv[i]);
1059 if ((feats & session_features) != session_features) {
1061 "Warning, this session will run with "
1062 "compatible mode because some test nodes "
1063 "might not understand these features: %x\n",
1064 (~feats & session_features));
1067 lst_free_rpcent(&head);
1072 * The selftest kernel module expects that a group should
1073 * have at least one node, since it doesn't make sense for
1074 * an empty group to be added to a test.
1077 "No nodes added successfully, deleting group %s\n",
1079 rc = lst_del_group(name);
1082 "Failed to delete group %s."
1083 " Group is empty.\n", name);
1091 lst_print_error("group", "Failed to add nodes %s: %s\n",
1092 argv[i], strerror(errno));
1095 if (trans_stat.trs_fwk_errno == EPROTO) {
1097 "test nodes might have different LST "
1098 "features, please disable some features by "
1099 "setting LST_FEATURES\n");
1102 lst_print_transerr(&head, "create session");
1105 lst_free_rpcent(&head);
1109 "No nodes added successfully, deleting group %s\n",
1111 if (lst_del_group(name) != 0) {
1113 "Failed to delete group %s."
1114 " Group is empty.\n", name);
1122 jt_lst_del_group(int argc, char **argv)
1126 if (session_key == 0) {
1128 "Can't find env LST_SESSION or value is not valid\n");
1133 lst_print_usage(argv[0]);
1137 rc = lst_del_group(argv[1]);
1143 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1144 struct lnet_process_id *ids, struct list_head *resultp)
1146 struct lstio_group_update_args args = { 0 };
1148 args.lstio_grp_key = session_key;
1149 args.lstio_grp_opc = opc;
1150 args.lstio_grp_args = clean;
1151 args.lstio_grp_nmlen = strlen(name);
1152 args.lstio_grp_namep = name;
1153 args.lstio_grp_count = count;
1154 args.lstio_grp_idsp = ids;
1155 args.lstio_grp_resultp = resultp;
1157 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1161 jt_lst_update_group(int argc, char **argv)
1163 struct list_head head;
1164 struct lnet_process_id *ids = NULL;
1174 static const struct option update_group_opts[] = {
1175 { .name = "refresh", .has_arg = no_argument, .val = 'f' },
1176 { .name = "clean", .has_arg = required_argument, .val = 'c' },
1177 { .name = "remove", .has_arg = required_argument, .val = 'r' },
1180 if (session_key == 0) {
1182 "Can't find env LST_SESSION or value is not valid\n");
1187 c = getopt_long(argc, argv, "fc:r:",
1188 update_group_opts, &optidx);
1190 /* Detect the end of the options. */
1197 lst_print_usage(argv[0]);
1200 opc = LST_GROUP_REFRESH;
1205 lst_print_usage(argv[0]);
1208 opc = LST_GROUP_RMND;
1213 clean = lst_node_str2state(optarg);
1214 if (opc != 0 || clean <= 0) {
1215 lst_print_usage(argv[0]);
1218 opc = LST_GROUP_CLEAN;
1222 lst_print_usage(argv[0]);
1227 /* no OPC or group is specified */
1228 if (opc == 0 || optind != argc - 1) {
1229 lst_print_usage(argv[0]);
1235 INIT_LIST_HEAD(&head);
1237 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1238 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1240 opc == LST_GROUP_RMND ? str : grp,
1244 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1245 opc == LST_GROUP_RMND ? str : grp,
1250 rc = lst_alloc_rpcent(&head, count, 0);
1252 fprintf(stderr, "Out of memory\n");
1259 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1265 lst_free_rpcent(&head);
1270 lst_free_rpcent(&head);
1271 lst_print_error("group", "Failed to update group: %s\n",
1276 lst_print_transerr(&head, "Updating group");
1278 lst_free_rpcent(&head);
1284 lst_list_group_ioctl(int len, char *name, int idx)
1286 struct lstio_group_list_args args = { 0 };
1288 args.lstio_grp_key = session_key;
1289 args.lstio_grp_idx = idx;
1290 args.lstio_grp_nmlen = len;
1291 args.lstio_grp_namep = name;
1293 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1297 lst_info_group_ioctl(char *name, struct lstcon_ndlist_ent *gent,
1298 int *idx, int *count, struct lstcon_node_ent *dents)
1300 struct lstio_group_info_args args = { 0 };
1302 args.lstio_grp_key = session_key;
1303 args.lstio_grp_nmlen = strlen(name);
1304 args.lstio_grp_namep = name;
1305 args.lstio_grp_entp = gent;
1306 args.lstio_grp_idxp = idx;
1307 args.lstio_grp_ndentp = count;
1308 args.lstio_grp_dentsp = dents;
1310 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1314 lst_list_group_all(void)
1316 char name[LST_NAME_SIZE];
1320 /* no group is specified, list name of all groups */
1321 for (i = 0; ; i++) {
1322 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1324 fprintf(stdout, "%d) %s\n", i + 1, name);
1328 if (errno == ENOENT)
1331 lst_print_error("group", "Failed to list group: %s\n",
1336 fprintf(stdout, "Total %d groups\n", i);
1341 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1344 jt_lst_list_group(int argc, char **argv)
1346 struct lstcon_ndlist_ent gent;
1347 struct lstcon_node_ent *dents;
1362 static const struct option list_group_opts[] = {
1363 { .name = "active", .has_arg = no_argument, .val = 'a' },
1364 { .name = "busy", .has_arg = no_argument, .val = 'b' },
1365 { .name = "down", .has_arg = no_argument, .val = 'd' },
1366 { .name = "unknown", .has_arg = no_argument, .val = 'u' },
1367 { .name = "all", .has_arg = no_argument, .val = 'l' },
1368 { .name = NULL, } };
1370 if (session_key == 0) {
1372 "Can't find env LST_SESSION or value is not valid\n");
1377 c = getopt_long(argc, argv, "abdul",
1378 list_group_opts, &optidx);
1385 verbose = active = 1;
1397 verbose = unknown = 1;
1404 lst_print_usage(argv[0]);
1409 if (optind == argc) {
1410 /* no group is specified, list name of all groups */
1411 rc = lst_list_group_all();
1417 fprintf(stdout, LST_NODES_TITLE);
1419 /* list nodes in specified groups */
1420 for (i = optind; i < argc; i++) {
1421 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1423 if (errno == ENOENT) {
1428 lst_print_error("group", "Failed to list group\n",
1434 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1435 gent.nle_nactive, gent.nle_nbusy,
1436 gent.nle_ndown, gent.nle_nunknown,
1437 gent.nle_nnode, argv[i]);
1441 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1443 if (gent.nle_nnode == 0) {
1444 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1448 count = gent.nle_nnode;
1450 dents = malloc(count * sizeof(struct lstcon_node_ent));
1451 if (dents == NULL) {
1452 fprintf(stderr, "Failed to malloc: %s\n",
1458 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1460 lst_print_error("group", "Failed to list group: %s\n",
1466 for (j = 0, c = 0; j < count; j++) {
1468 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1469 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1470 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1471 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1473 fprintf(stdout, "\t%s: %s\n",
1474 libcfs_id2str(dents[j].nde_id),
1475 lst_node_state2str(dents[j].nde_state));
1480 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1489 lst_stat_ioctl(char *name, int count, struct lnet_process_id *idsp,
1490 int timeout, struct list_head *resultp)
1492 struct lstio_stat_args args = { 0 };
1494 args.lstio_sta_key = session_key;
1495 args.lstio_sta_timeout = timeout;
1496 args.lstio_sta_nmlen = strlen(name);
1497 args.lstio_sta_namep = name;
1498 args.lstio_sta_count = count;
1499 args.lstio_sta_idsp = idsp;
1500 args.lstio_sta_resultp = resultp;
1502 return lst_ioctl(LSTIO_STAT_QUERY, &args, sizeof(args));
1506 struct list_head srp_link;
1509 struct lnet_process_id *srp_ids;
1510 struct list_head srp_result[2];
1511 } lst_stat_req_param_t;
1514 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1518 for (i = 0; i < 2; i++)
1519 lst_free_rpcent(&srp->srp_result[i]);
1521 if (srp->srp_ids != NULL)
1528 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
1530 lst_stat_req_param_t *srp = NULL;
1531 int count = save_old ? 2 : 1;
1535 srp = malloc(sizeof(*srp));
1539 memset(srp, 0, sizeof(*srp));
1540 INIT_LIST_HEAD(&srp->srp_result[0]);
1541 INIT_LIST_HEAD(&srp->srp_result[1]);
1543 rc = lst_get_node_count(LST_OPC_GROUP, name,
1544 &srp->srp_count, NULL);
1545 if (rc != 0 && errno == ENOENT) {
1546 rc = lst_get_node_count(LST_OPC_NODES, name,
1547 &srp->srp_count, &srp->srp_ids);
1552 "Failed to get count of nodes from %s: %s\n",
1553 name, strerror(errno));
1554 lst_stat_req_param_free(srp);
1559 srp->srp_name = name;
1561 for (i = 0; i < count; i++) {
1562 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1563 sizeof(struct sfw_counters) +
1564 sizeof(struct srpc_counters) +
1565 sizeof(struct lnet_counters_common));
1567 fprintf(stderr, "Out of memory\n");
1577 lst_stat_req_param_free(srp);
1585 } lst_srpc_stat_result;
1587 #define LST_LNET_AVG 0
1588 #define LST_LNET_MIN 1
1589 #define LST_LNET_MAX 2
1592 float lnet_avg_sndrate;
1593 float lnet_min_sndrate;
1594 float lnet_max_sndrate;
1595 float lnet_total_sndrate;
1597 float lnet_avg_rcvrate;
1598 float lnet_min_rcvrate;
1599 float lnet_max_rcvrate;
1600 float lnet_total_rcvrate;
1602 float lnet_avg_sndperf;
1603 float lnet_min_sndperf;
1604 float lnet_max_sndperf;
1605 float lnet_total_sndperf;
1607 float lnet_avg_rcvperf;
1608 float lnet_min_rcvperf;
1609 float lnet_max_rcvperf;
1610 float lnet_total_rcvperf;
1612 int lnet_stat_count;
1613 } lst_lnet_stat_result_t;
1615 lst_lnet_stat_result_t lnet_stat_result;
1618 lst_lnet_stat_value(int bw, int send, int off)
1622 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1623 &lnet_stat_result.lnet_avg_sndrate;
1634 lst_cal_lnet_stat(float delta, struct lnet_counters_common *lnet_new,
1635 struct lnet_counters_common *lnet_old, int mbs)
1639 unsigned int unit_divisor;
1641 unit_divisor = (mbs) ? (1000 * 1000) : (1024 * 1024);
1642 perf = (float)(lnet_new->lcc_send_length -
1643 lnet_old->lcc_send_length) / unit_divisor / delta;
1644 lnet_stat_result.lnet_total_sndperf += perf;
1646 if (lnet_stat_result.lnet_min_sndperf > perf ||
1647 lnet_stat_result.lnet_min_sndperf == 0)
1648 lnet_stat_result.lnet_min_sndperf = perf;
1650 if (lnet_stat_result.lnet_max_sndperf < perf)
1651 lnet_stat_result.lnet_max_sndperf = perf;
1653 perf = (float)(lnet_new->lcc_recv_length -
1654 lnet_old->lcc_recv_length) / unit_divisor / delta;
1655 lnet_stat_result.lnet_total_rcvperf += perf;
1657 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1658 lnet_stat_result.lnet_min_rcvperf == 0)
1659 lnet_stat_result.lnet_min_rcvperf = perf;
1661 if (lnet_stat_result.lnet_max_rcvperf < perf)
1662 lnet_stat_result.lnet_max_rcvperf = perf;
1664 rate = (lnet_new->lcc_send_count - lnet_old->lcc_send_count) / delta;
1665 lnet_stat_result.lnet_total_sndrate += rate;
1667 if (lnet_stat_result.lnet_min_sndrate > rate ||
1668 lnet_stat_result.lnet_min_sndrate == 0)
1669 lnet_stat_result.lnet_min_sndrate = rate;
1671 if (lnet_stat_result.lnet_max_sndrate < rate)
1672 lnet_stat_result.lnet_max_sndrate = rate;
1674 rate = (lnet_new->lcc_recv_count - lnet_old->lcc_recv_count) / delta;
1675 lnet_stat_result.lnet_total_rcvrate += rate;
1677 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1678 lnet_stat_result.lnet_min_rcvrate == 0)
1679 lnet_stat_result.lnet_min_rcvrate = rate;
1681 if (lnet_stat_result.lnet_max_rcvrate < rate)
1682 lnet_stat_result.lnet_max_rcvrate = rate;
1684 lnet_stat_result.lnet_stat_count++;
1686 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1687 lnet_stat_result.lnet_stat_count;
1688 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1689 lnet_stat_result.lnet_stat_count;
1691 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1692 lnet_stat_result.lnet_stat_count;
1693 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1694 lnet_stat_result.lnet_stat_count;
1698 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type, int mbs)
1708 if (lnet_stat_result.lnet_stat_count == 0)
1711 units = (mbs) ? "MB/s " : "MiB/s ";
1713 if (bwrt == 1) /* bw only */
1716 if (bwrt == 2) /* rates only */
1719 if (rdwr == 1) /* recv only */
1722 if (rdwr == 2) /* send only */
1725 for (i = start1; i <= end1; i++) {
1726 fprintf(stdout, "[LNet %s of %s]\n",
1727 i == 0 ? "Rates" : "Bandwidth", name);
1729 for (j = start2; j <= end2; j++) {
1730 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
1732 if ((type & 1) != 0) {
1733 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1735 lst_lnet_stat_value(i, j, 0), units);
1738 if ((type & 2) != 0) {
1739 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1741 lst_lnet_stat_value(i, j, 1), units);
1744 if ((type & 4) != 0) {
1745 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1747 lst_lnet_stat_value(i, j, 2), units);
1750 fprintf(stdout, "\n");
1756 lst_print_stat(char *name, struct list_head *resultp,
1757 int idx, int lnet, int bwrt, int rdwr, int type,
1760 struct list_head tmp[2];
1761 struct lstcon_rpc_ent *new;
1762 struct lstcon_rpc_ent *old;
1763 struct sfw_counters *sfwk_new;
1764 struct sfw_counters *sfwk_old;
1765 struct srpc_counters *srpc_new;
1766 struct srpc_counters *srpc_old;
1767 struct lnet_counters_common *lnet_new;
1768 struct lnet_counters_common *lnet_old;
1772 INIT_LIST_HEAD(&tmp[0]);
1773 INIT_LIST_HEAD(&tmp[1]);
1775 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1777 while (!list_empty(&resultp[idx])) {
1778 if (list_empty(&resultp[1 - idx])) {
1779 fprintf(stderr, "Group is changed, re-run stat\n");
1783 new = list_entry(resultp[idx].next, struct lstcon_rpc_ent,
1785 old = list_entry(resultp[1 - idx].next, struct lstcon_rpc_ent,
1788 /* first time get stats result, can't calculate diff */
1789 if (new->rpe_peer.nid == LNET_NID_ANY)
1792 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1793 new->rpe_peer.pid != old->rpe_peer.pid) {
1794 /* Something wrong. i.e, somebody change the group */
1798 list_move_tail(&new->rpe_link, &tmp[idx]);
1800 list_move_tail(&old->rpe_link, &tmp[1 - idx]);
1802 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1803 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1808 sfwk_new = (struct sfw_counters *)&new->rpe_payload[0];
1809 sfwk_old = (struct sfw_counters *)&old->rpe_payload[0];
1811 srpc_new = (struct srpc_counters *)((char *)sfwk_new +
1813 srpc_old = (struct srpc_counters *)((char *)sfwk_old +
1816 lnet_new = (struct lnet_counters_common *)((char *)srpc_new +
1818 lnet_old = (struct lnet_counters_common *)((char *)srpc_old +
1821 /* Prior to version 2.3, the running_ms was a counter for
1822 * the number of running tests. Since 2.3, running_ms is
1823 * changed to hold the millisecond since the start of
1824 * the work item. The rpe_stamp field was formerly used,
1825 * but is no longer. In 2.12 rpe_stamp was changed to
1826 * struct timespec64 and has nanosecond resolution, in
1827 * case it is needed in the future.
1829 delta = (float)(sfwk_new->running_ms -
1830 sfwk_old->running_ms) / 1000;
1832 if (!lnet) /* TODO */
1835 lst_cal_lnet_stat(delta, lnet_new, lnet_old, mbs);
1838 list_splice(&tmp[idx], &resultp[idx]);
1839 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1842 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1844 if (!lnet) /* TODO */
1847 lst_print_lnet_stat(name, bwrt, rdwr, type, mbs);
1851 jt_lst_stat(int argc, char **argv)
1853 struct list_head head;
1854 lst_stat_req_param_t *srp;
1857 int timeout = 5; /* default timeout, 5 sec */
1858 int delay = 5; /* default delay, 5 sec */
1859 int count = -1; /* run forever */
1860 int lnet = 1; /* lnet stat by default */
1867 int mbs = 0; /* report as MB/s */
1869 static const struct option stat_opts[] = {
1870 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1871 { .name = "delay", .has_arg = required_argument, .val = 'd' },
1872 { .name = "count", .has_arg = required_argument, .val = 'o' },
1873 { .name = "lnet", .has_arg = no_argument, .val = 'l' },
1874 { .name = "rpc", .has_arg = no_argument, .val = 'c' },
1875 { .name = "bw", .has_arg = no_argument, .val = 'b' },
1876 { .name = "rate", .has_arg = no_argument, .val = 'a' },
1877 { .name = "read", .has_arg = no_argument, .val = 'r' },
1878 { .name = "write", .has_arg = no_argument, .val = 'w' },
1879 { .name = "avg", .has_arg = no_argument, .val = 'g' },
1880 { .name = "min", .has_arg = no_argument, .val = 'n' },
1881 { .name = "max", .has_arg = no_argument, .val = 'x' },
1882 { .name = "mbs", .has_arg = no_argument, .val = 'm' },
1885 if (session_key == 0) {
1887 "Can't find env LST_SESSION or value is not valid\n");
1892 c = getopt_long(argc, argv, "t:d:lcbarwgnxm", stat_opts,
1900 timeout = atoi(optarg);
1903 delay = atoi(optarg);
1906 count = atoi(optarg);
1952 lst_print_usage(argv[0]);
1957 if (optind == argc) {
1958 lst_print_usage(argv[0]);
1962 if (timeout <= 0 || delay <= 0) {
1963 fprintf(stderr, "Invalid timeout or delay value\n");
1968 fprintf(stderr, "Invalid count value\n");
1972 /* extra count to get first data point */
1976 INIT_LIST_HEAD(&head);
1978 while (optind < argc) {
1979 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
1983 list_add_tail(&srp->srp_link, &head);
1987 time_t now = time(NULL);
1989 if (now - last < delay) {
1990 sleep(delay - now + last);
1995 list_for_each_entry(srp, &head, srp_link) {
1996 rc = lst_stat_ioctl(srp->srp_name,
1997 srp->srp_count, srp->srp_ids,
1998 timeout, &srp->srp_result[idx]);
2000 lst_print_error("stat", "Failed to stat %s: %s\n",
2001 srp->srp_name, strerror(errno));
2005 lst_print_stat(srp->srp_name, srp->srp_result,
2006 idx, lnet, bwrt, rdwr, type, mbs);
2008 lst_reset_rpcent(&srp->srp_result[1 - idx]);
2015 } while (count == -1 || count > 0);
2018 while (!list_empty(&head)) {
2019 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2021 list_del(&srp->srp_link);
2022 lst_stat_req_param_free(srp);
2029 jt_lst_show_error(int argc, char **argv)
2031 struct list_head head;
2032 lst_stat_req_param_t *srp;
2033 struct lstcon_rpc_ent *ent;
2034 struct sfw_counters *sfwk;
2035 struct srpc_counters *srpc;
2042 static const struct option show_error_opts[] = {
2043 { .name = "session", .has_arg = no_argument, .val = 's' },
2044 { .name = NULL, } };
2046 if (session_key == 0) {
2048 "Can't find env LST_SESSION or value is not valid\n");
2053 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
2064 lst_print_usage(argv[0]);
2069 if (optind == argc) {
2070 lst_print_usage(argv[0]);
2074 INIT_LIST_HEAD(&head);
2076 while (optind < argc) {
2077 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
2081 list_add_tail(&srp->srp_link, &head);
2084 list_for_each_entry(srp, &head, srp_link) {
2085 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
2086 srp->srp_ids, 10, &srp->srp_result[0]);
2089 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2090 srp->srp_name, strerror(errno));
2094 fprintf(stdout, "%s:\n", srp->srp_name);
2098 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2099 if (ent->rpe_rpc_errno != 0) {
2101 fprintf(stderr, "RPC failure, can't show error on %s\n",
2102 libcfs_id2str(ent->rpe_peer));
2106 if (ent->rpe_fwk_errno != 0) {
2108 fprintf(stderr, "Framework failure, can't show error on %s\n",
2109 libcfs_id2str(ent->rpe_peer));
2113 sfwk = (struct sfw_counters *)&ent->rpe_payload[0];
2114 srpc = (struct srpc_counters *)((char *)sfwk + sizeof(*sfwk));
2116 if (srpc->errors == 0 &&
2117 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2121 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2126 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2127 libcfs_id2str(ent->rpe_peer),
2128 sfwk->brw_errors, sfwk->ping_errors,
2129 show_rpc ? ' ' : '\n');
2134 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2135 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2138 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2141 while (!list_empty(&head)) {
2142 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2144 list_del(&srp->srp_link);
2145 lst_stat_req_param_free(srp);
2152 lst_add_batch_ioctl(char *name)
2154 struct lstio_batch_add_args args = { 0 };
2156 args.lstio_bat_key = session_key;
2157 args.lstio_bat_nmlen = strlen(name);
2158 args.lstio_bat_namep = name;
2160 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2164 jt_lst_add_batch(int argc, char **argv)
2169 if (session_key == 0) {
2171 "Can't find env LST_SESSION or value is not valid\n");
2176 lst_print_usage(argv[0]);
2181 if (strlen(name) >= LST_NAME_SIZE) {
2182 fprintf(stderr, "Name length is limited to %d\n",
2187 rc = lst_add_batch_ioctl(name);
2191 lst_print_error("batch", "Failed to create batch: %s\n",
2198 lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp)
2200 struct lstio_batch_run_args args = { 0 };
2202 args.lstio_bat_key = session_key;
2203 args.lstio_bat_timeout = timeout;
2204 args.lstio_bat_nmlen = strlen(name);
2205 args.lstio_bat_namep = name;
2206 args.lstio_bat_resultp = resultp;
2208 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2212 jt_lst_start_batch(int argc, char **argv)
2214 struct list_head head;
2222 static const struct option start_batch_opts[] = {
2223 { .name = "timeout", .has_arg = required_argument, .val = 't' },
2226 if (session_key == 0) {
2228 "Can't find env LST_SESSION or value is not valid\n");
2233 c = getopt_long(argc, argv, "t:",
2234 start_batch_opts, &optidx);
2236 /* Detect the end of the options. */
2242 timeout = atoi(optarg);
2245 lst_print_usage(argv[0]);
2250 if (optind == argc) {
2251 batch = LST_DEFAULT_BATCH;
2253 } else if (optind == argc - 1) {
2254 batch = argv[optind];
2257 lst_print_usage(argv[0]);
2261 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2263 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2264 batch, strerror(errno));
2268 INIT_LIST_HEAD(&head);
2270 rc = lst_alloc_rpcent(&head, count, 0);
2272 fprintf(stderr, "Out of memory\n");
2276 rc = lst_start_batch_ioctl(batch, timeout, &head);
2279 fprintf(stdout, "%s is running now\n", batch);
2280 lst_free_rpcent(&head);
2285 lst_print_error("batch", "Failed to start batch: %s\n",
2287 lst_free_rpcent(&head);
2291 lst_print_transerr(&head, "Run batch");
2293 lst_free_rpcent(&head);
2299 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2301 struct lstio_batch_stop_args args = { 0 };
2303 args.lstio_bat_key = session_key;
2304 args.lstio_bat_force = force;
2305 args.lstio_bat_nmlen = strlen(name);
2306 args.lstio_bat_namep = name;
2307 args.lstio_bat_resultp = resultp;
2309 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2313 jt_lst_stop_batch(int argc, char **argv)
2315 struct list_head head;
2323 static const struct option stop_batch_opts[] = {
2324 { .name = "force", .has_arg = no_argument, .val = 'f' },
2327 if (session_key == 0) {
2329 "Can't find env LST_SESSION or value is not valid\n");
2334 c = getopt_long(argc, argv, "f",
2335 stop_batch_opts, &optidx);
2337 /* Detect the end of the options. */
2346 lst_print_usage(argv[0]);
2351 if (optind == argc) {
2352 batch = LST_DEFAULT_BATCH;
2354 } else if (optind == argc - 1) {
2355 batch = argv[optind];
2358 lst_print_usage(argv[0]);
2362 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2364 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2365 batch, strerror(errno));
2369 INIT_LIST_HEAD(&head);
2371 rc = lst_alloc_rpcent(&head, count, 0);
2373 fprintf(stderr, "Out of memory\n");
2377 rc = lst_stop_batch_ioctl(batch, force, &head);
2382 lst_reset_rpcent(&head);
2384 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2388 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2389 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2392 fprintf(stdout, "%d batch in stopping\n",
2393 lstcon_tsbqry_stat_run(&trans_stat, 0));
2397 fprintf(stdout, "Batch is stopped\n");
2398 lst_free_rpcent(&head);
2403 lst_print_error("batch", "Failed to stop batch: %s\n",
2405 lst_free_rpcent(&head);
2409 lst_print_transerr(&head, "stop batch");
2411 lst_free_rpcent(&head);
2417 lst_list_batch_ioctl(int len, char *name, int index)
2419 struct lstio_batch_list_args args = { 0 };
2421 args.lstio_bat_key = session_key;
2422 args.lstio_bat_idx = index;
2423 args.lstio_bat_nmlen = len;
2424 args.lstio_bat_namep = name;
2426 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2430 lst_info_batch_ioctl(char *batch, int test, int server,
2431 struct lstcon_test_batch_ent *entp, int *idxp,
2432 int *ndentp, struct lstcon_node_ent *dentsp)
2434 struct lstio_batch_info_args args = { 0 };
2436 args.lstio_bat_key = session_key;
2437 args.lstio_bat_nmlen = strlen(batch);
2438 args.lstio_bat_namep = batch;
2439 args.lstio_bat_server = server;
2440 args.lstio_bat_testidx = test;
2441 args.lstio_bat_entp = entp;
2442 args.lstio_bat_idxp = idxp;
2443 args.lstio_bat_ndentp = ndentp;
2444 args.lstio_bat_dentsp = dentsp;
2446 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2450 lst_list_batch_all(void)
2452 char name[LST_NAME_SIZE];
2456 for (i = 0; ; i++) {
2457 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2459 fprintf(stdout, "%d) %s\n", i + 1, name);
2463 if (errno == ENOENT)
2466 lst_print_error("batch", "Failed to list batch: %s\n",
2471 fprintf(stdout, "Total %d batches\n", i);
2477 lst_list_tsb_nodes(char *batch, int test, int server,
2478 int count, int active, int invalid)
2480 struct lstcon_node_ent *dents;
2489 /* verbose list, show nodes in batch or test */
2490 dents = malloc(count * sizeof(struct lstcon_node_ent));
2491 if (dents == NULL) {
2492 fprintf(stdout, "Can't allocate memory\n");
2496 rc = lst_info_batch_ioctl(batch, test, server,
2497 NULL, &index, &count, dents);
2500 lst_print_error((test > 0) ? "test" : "batch",
2501 (test > 0) ? "Failed to query test: %s\n" :
2502 "Failed to query batch: %s\n",
2507 for (i = 0, c = 0; i < count; i++) {
2508 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2509 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2510 dents[i].nde_state == LST_NODE_DOWN ||
2511 dents[i].nde_state == LST_NODE_UNKNOWN)))
2514 fprintf(stdout, "\t%s: %s\n",
2515 libcfs_id2str(dents[i].nde_id),
2516 lst_node_state2str(dents[i].nde_state));
2520 fprintf(stdout, "Total %d nodes\n", c);
2527 jt_lst_list_batch(int argc, char **argv)
2529 struct lstcon_test_batch_ent ent;
2532 int verbose = 0; /* list nodes in batch or test */
2541 static const struct option list_batch_opts[] = {
2542 { .name = "test", .has_arg = required_argument, .val = 't' },
2543 { .name = "invalid", .has_arg = no_argument, .val = 'i' },
2544 { .name = "active", .has_arg = no_argument, .val = 'a' },
2545 { .name = "all", .has_arg = no_argument, .val = 'l' },
2546 { .name = "server", .has_arg = no_argument, .val = 's' },
2547 { .name = NULL, } };
2549 if (session_key == 0) {
2551 "Can't find env LST_SESSION or value is not valid\n");
2556 c = getopt_long(argc, argv, "ailst:",
2557 list_batch_opts, &optidx);
2564 verbose = active = 1;
2567 verbose = invalid = 1;
2570 verbose = active = invalid = 1;
2576 test = atoi(optarg);
2580 lst_print_usage(argv[0]);
2585 if (optind == argc) {
2586 /* list all batches */
2587 rc = lst_list_batch_all();
2591 if (ntest == 1 && test <= 0) {
2592 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2596 if (optind != argc - 1) {
2597 lst_print_usage(argv[0]);
2601 batch = argv[optind];
2604 /* show detail of specified batch or test */
2605 rc = lst_info_batch_ioctl(batch, test, server,
2606 &ent, NULL, NULL, NULL);
2608 lst_print_error((test > 0) ? "test" : "batch",
2609 (test > 0) ? "Failed to query test: %s\n" :
2610 "Failed to query batch: %s\n",
2616 /* list nodes in test or batch */
2617 rc = lst_list_tsb_nodes(batch, test, server,
2618 server ? ent.tbe_srv_nle.nle_nnode :
2619 ent.tbe_cli_nle.nle_nnode,
2624 /* only show number of hosts in batch or test */
2626 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2627 batch, ent.u.tbe_batch.bae_ntest,
2628 ent.u.tbe_batch.bae_state);
2629 ntest = ent.u.tbe_batch.bae_ntest;
2630 test = 1; /* starting from test 1 */
2634 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2635 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2636 ent.u.tbe_test.tse_loop,
2637 ent.u.tbe_test.tse_concur);
2642 fprintf(stdout, LST_NODES_TITLE);
2643 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2644 "server\t%d\t%d\t%d\t%d\t%d\n",
2645 ent.tbe_cli_nle.nle_nactive,
2646 ent.tbe_cli_nle.nle_nbusy,
2647 ent.tbe_cli_nle.nle_ndown,
2648 ent.tbe_cli_nle.nle_nunknown,
2649 ent.tbe_cli_nle.nle_nnode,
2650 ent.tbe_srv_nle.nle_nactive,
2651 ent.tbe_srv_nle.nle_nbusy,
2652 ent.tbe_srv_nle.nle_ndown,
2653 ent.tbe_srv_nle.nle_nunknown,
2654 ent.tbe_srv_nle.nle_nnode);
2663 lst_query_batch_ioctl(char *batch, int test, int server,
2664 int timeout, struct list_head *head)
2666 struct lstio_batch_query_args args = { 0 };
2668 args.lstio_bat_key = session_key;
2669 args.lstio_bat_testidx = test;
2670 args.lstio_bat_client = !(server);
2671 args.lstio_bat_timeout = timeout;
2672 args.lstio_bat_nmlen = strlen(batch);
2673 args.lstio_bat_namep = batch;
2674 args.lstio_bat_resultp = head;
2676 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2680 lst_print_tsb_verbose(struct list_head *head,
2681 int active, int idle, int error)
2683 struct lstcon_rpc_ent *ent;
2685 list_for_each_entry(ent, head, rpe_link) {
2686 if (ent->rpe_priv[0] == 0 && active)
2689 if (ent->rpe_priv[0] != 0 && idle)
2692 if (ent->rpe_fwk_errno == 0 && error)
2695 fprintf(stdout, "%s [%s]: %s\n",
2696 libcfs_id2str(ent->rpe_peer),
2697 lst_node_state2str(ent->rpe_state),
2698 ent->rpe_rpc_errno != 0 ?
2699 strerror(ent->rpe_rpc_errno) :
2700 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2705 jt_lst_query_batch(int argc, char **argv)
2707 struct lstcon_test_batch_ent ent;
2708 struct list_head head;
2714 int timeout = 5; /* default 5 seconds */
2715 int delay = 5; /* default 5 seconds */
2716 int loop = 1; /* default 1 loop */
2726 static const struct option query_batch_opts[] = {
2727 { .name = "timeout", .has_arg = required_argument, .val = 'o' },
2728 { .name = "delay", .has_arg = required_argument, .val = 'd' },
2729 { .name = "loop", .has_arg = required_argument, .val = 'c' },
2730 { .name = "test", .has_arg = required_argument, .val = 't' },
2731 { .name = "server", .has_arg = no_argument, .val = 's' },
2732 { .name = "active", .has_arg = no_argument, .val = 'a' },
2733 { .name = "idle", .has_arg = no_argument, .val = 'i' },
2734 { .name = "error", .has_arg = no_argument, .val = 'e' },
2735 { .name = "all", .has_arg = no_argument, .val = 'l' },
2736 { .name = NULL, } };
2738 if (session_key == 0) {
2740 "Can't find env LST_SESSION or value is not valid\n");
2745 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2746 query_batch_opts, &optidx);
2748 /* Detect the end of the options. */
2754 timeout = atoi(optarg);
2757 delay = atoi(optarg);
2760 loop = atoi(optarg);
2763 test = atoi(optarg);
2769 active = verbose = 1;
2775 error = verbose = 1;
2781 lst_print_usage(argv[0]);
2786 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2787 lst_print_usage(argv[0]);
2791 if (optind == argc) {
2792 batch = LST_DEFAULT_BATCH;
2794 } else if (optind == argc - 1) {
2795 batch = argv[optind];
2798 lst_print_usage(argv[0]);
2803 INIT_LIST_HEAD(&head);
2806 rc = lst_info_batch_ioctl(batch, test, server,
2807 &ent, NULL, NULL, NULL);
2809 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2810 batch, test, strerror(errno));
2814 count = server ? ent.tbe_srv_nle.nle_nnode :
2815 ent.tbe_cli_nle.nle_nnode;
2817 fprintf(stdout, "Batch or test is empty\n");
2822 rc = lst_alloc_rpcent(&head, count, 0);
2824 fprintf(stderr, "Out of memory\n");
2828 for (i = 0; i < loop; i++) {
2829 time_t now = time(NULL);
2831 if (now - last < delay) {
2832 sleep(delay - now + last);
2838 rc = lst_query_batch_ioctl(batch, test,
2839 server, timeout, &head);
2841 fprintf(stderr, "Failed to query batch: %s\n",
2848 lst_print_tsb_verbose(&head, active, idle, error);
2852 fprintf(stdout, "%s [%d] ", batch, test);
2854 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2855 fprintf(stdout, "%d of %d nodes are unknown, ",
2856 lstcon_rpc_stat_failure(&trans_stat, 0),
2857 lstcon_rpc_stat_total(&trans_stat, 0));
2860 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2861 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2862 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2863 fprintf(stdout, "is stopped\n");
2867 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2868 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2869 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2870 fprintf(stdout, "is running\n");
2874 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2875 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2876 lstcon_tsbqry_stat_run(&trans_stat, 0),
2877 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2880 lst_free_rpcent(&head);
2886 lst_parse_distribute(char *dstr, int *dist, int *span)
2892 dstr = strchr(dstr, ':');
2896 *span = atoi(dstr + 1);
2904 lst_get_bulk_param(int argc, char **argv, struct lst_test_bulk_param *bulk)
2911 bulk->blk_size = 4096;
2912 bulk->blk_opc = LST_BRW_READ;
2913 bulk->blk_flags = LST_BRW_CHECK_NONE;
2914 bulk->blk_srv_off = bulk->blk_cli_off = 0;
2917 if (strcasestr(argv[i], "check=") == argv[i] ||
2918 strcasestr(argv[i], "c=") == argv[i]) {
2919 tok = strchr(argv[i], '=') + 1;
2921 if (strcasecmp(tok, "full") == 0) {
2922 bulk->blk_flags = LST_BRW_CHECK_FULL;
2923 } else if (strcasecmp(tok, "simple") == 0) {
2924 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2926 fprintf(stderr, "Unknow flag %s\n", tok);
2930 } else if (strcasestr(argv[i], "size=") == argv[i] ||
2931 strcasestr(argv[i], "s=") == argv[i]) {
2932 tok = strchr(argv[i], '=') + 1;
2934 bulk->blk_size = strtol(tok, &end, 0);
2935 if (bulk->blk_size <= 0) {
2936 fprintf(stderr, "Invalid size %s\n", tok);
2943 if (*end == 'k' || *end == 'K')
2944 bulk->blk_size *= 1024;
2945 else if (*end == 'm' || *end == 'M')
2946 bulk->blk_size *= 1024 * 1024;
2948 if (bulk->blk_size > LNET_MTU) {
2949 fprintf(stderr, "Size exceed limitation: %d bytes\n",
2954 } else if (strcasestr(argv[i], "off=") == argv[i]) {
2957 tok = strchr(argv[i], '=') + 1;
2959 off = strtol(tok, &end, 0);
2960 /* NB: align with sizeof(__u64) to simplify page
2961 * checking implementation */
2962 if (off < 0 || off % sizeof(__u64) != 0) {
2964 "Invalid offset %s/%d, it should be "
2965 "postive value and multiple of %d\n",
2966 tok, off, (int)sizeof(__u64));
2970 /* NB: blk_srv_off is reserved so far */
2971 bulk->blk_cli_off = bulk->blk_srv_off = off;
2975 } else if (strcasecmp(argv[i], "read") == 0 ||
2976 strcasecmp(argv[i], "r") == 0) {
2977 bulk->blk_opc = LST_BRW_READ;
2979 } else if (strcasecmp(argv[i], "write") == 0 ||
2980 strcasecmp(argv[i], "w") == 0) {
2981 bulk->blk_opc = LST_BRW_WRITE;
2984 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
2995 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
2997 struct lst_test_bulk_param *bulk = NULL;
3000 type = lst_test_name2type(test);
3002 fprintf(stderr, "Unknow test name %s\n", test);
3011 bulk = malloc(sizeof(*bulk));
3013 fprintf(stderr, "Out of memory\n");
3017 memset(bulk, 0, sizeof(*bulk));
3019 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
3025 *plen = sizeof(*bulk);
3033 /* TODO: parse more parameter */
3038 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
3039 int dist, int span, char *sgrp, char *dgrp,
3040 void *param, int plen, int *retp, struct list_head *resultp)
3042 struct lstio_test_args args = { 0 };
3044 args.lstio_tes_key = session_key;
3045 args.lstio_tes_bat_nmlen = strlen(batch);
3046 args.lstio_tes_bat_name = batch;
3047 args.lstio_tes_type = type;
3048 args.lstio_tes_oneside = 0;
3049 args.lstio_tes_loop = loop;
3050 args.lstio_tes_concur = concur;
3051 args.lstio_tes_dist = dist;
3052 args.lstio_tes_span = span;
3053 args.lstio_tes_sgrp_nmlen = strlen(sgrp);
3054 args.lstio_tes_sgrp_name = sgrp;
3055 args.lstio_tes_dgrp_nmlen = strlen(dgrp);
3056 args.lstio_tes_dgrp_name = dgrp;
3057 args.lstio_tes_param_len = plen;
3058 args.lstio_tes_param = param;
3059 args.lstio_tes_retp = retp;
3060 args.lstio_tes_resultp = resultp;
3062 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
3066 jt_lst_add_test(int argc, char **argv)
3068 struct list_head head;
3088 static const struct option add_test_opts[] = {
3089 { .name = "batch", .has_arg = required_argument, .val = 'b' },
3090 { .name = "concurrency", .has_arg = required_argument, .val = 'c' },
3091 { .name = "distribute", .has_arg = required_argument, .val = 'd' },
3092 { .name = "from", .has_arg = required_argument, .val = 'f' },
3093 { .name = "to", .has_arg = required_argument, .val = 't' },
3094 { .name = "loop", .has_arg = required_argument, .val = 'l' },
3097 if (session_key == 0) {
3099 "Can't find env LST_SESSION or value is not valid\n");
3104 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3105 add_test_opts, &optidx);
3107 /* Detect the end of the options. */
3116 concur = atoi(optarg);
3125 loop = atoi(optarg);
3131 lst_print_usage(argv[0]);
3136 if (optind == argc || from == NULL || to == NULL) {
3137 lst_print_usage(argv[0]);
3141 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3142 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3147 batch = LST_DEFAULT_BATCH;
3150 rc = lst_parse_distribute(dstr, &dist, &span);
3152 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3157 test = argv[optind++];
3162 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3164 fprintf(stderr, "Failed to add test (%s)\n", test);
3168 INIT_LIST_HEAD(&head);
3170 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3172 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3173 from, strerror(errno));
3177 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3179 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3180 to, strerror(errno));
3184 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3186 fprintf(stderr, "Out of memory\n");
3190 rc = lst_add_test_ioctl(batch, type, loop, concur,
3191 dist, span, from, to, param, plen, &ret, &head);
3194 fprintf(stdout, "Test was added successfully\n");
3196 fprintf(stdout, "Server group contains userland test "
3197 "nodes, old version of tcplnd can't accept "
3198 "connection request\n");
3205 lst_print_error("test", "Failed to add test: %s\n",
3210 lst_print_transerr(&head, "add test");
3212 lst_free_rpcent(&head);
3220 static command_t lst_cmdlist[] = {
3221 {"new_session", jt_lst_new_session, NULL,
3222 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3223 {"end_session", jt_lst_end_session, NULL,
3224 "Usage: lst end_session" },
3225 {"show_session", jt_lst_show_session, NULL,
3226 "Usage: lst show_session" },
3227 {"ping", jt_lst_ping , NULL,
3228 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3229 {"add_group", jt_lst_add_group, NULL,
3230 "Usage: lst group NAME IDs [IDs]..." },
3231 {"del_group", jt_lst_del_group, NULL,
3232 "Usage: lst del_group NAME" },
3233 {"update_group", jt_lst_update_group, NULL,
3234 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3235 {"list_group", jt_lst_list_group, NULL,
3236 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3237 {"stat", jt_lst_stat, NULL,
3238 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3239 " [--mbs] [--timeout #] [--delay #] [--count #] GROUP [GROUP]" },
3240 {"show_error", jt_lst_show_error, NULL,
3241 "Usage: lst show_error NAME | IDS ..." },
3242 {"add_batch", jt_lst_add_batch, NULL,
3243 "Usage: lst add_batch NAME" },
3244 {"run", jt_lst_start_batch, NULL,
3245 "Usage: lst run [--timeout TIME] [NAME]" },
3246 {"stop", jt_lst_stop_batch, NULL,
3247 "Usage: lst stop [--force] BATCH_NAME" },
3248 {"list_batch", jt_lst_list_batch, NULL,
3249 "Usage: lst list_batch NAME [--test ID] [--server]" },
3250 {"query", jt_lst_query_batch, NULL,
3251 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3252 {"add_test", jt_lst_add_test, NULL,
3253 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3254 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3255 {"help", Parser_help, 0, "help" },
3256 {"--list-commands", lst_list_commands, 0, "list commands" },
3261 lst_initialize(void)
3266 feats = getenv("LST_FEATURES");
3268 session_features = strtol(feats, NULL, 16);
3270 if ((session_features & ~LST_FEATS_MASK) != 0) {
3272 "Unsupported session features %x, "
3273 "only support these features so far: %x\n",
3274 (session_features & ~LST_FEATS_MASK), LST_FEATS_MASK);
3278 key = getenv("LST_SESSION");
3285 session_key = atoi(key);
3290 static int lst_list_commands(int argc, char **argv)
3292 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
3294 Parser_list_commands(lst_cmdlist, buffer, sizeof(buffer), NULL, 0, 4);
3300 main(int argc, char **argv)
3306 rc = lst_initialize();
3310 rc = lustre_lnet_config_lib_init();
3314 Parser_init("lst > ", lst_cmdlist);
3317 rc = Parser_execarg(argc - 1, argv + 1, lst_cmdlist);