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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/selftest/conctl.c
38 * Author: Liang Zhen <liangzhen@clusterfs.com>
41 #include <libcfs/libcfsutil.h>
42 #include <lnet/lnetctl.h>
43 #include <lnet/lnetst.h>
44 #include <lnet/nidstr.h>
45 /* NB: these includes are layering violation */
46 #include <lustre_ver.h>
47 #include <lustre/lustre_idl.h>
49 lst_sid_t LST_INVALID_SID = {LNET_NID_ANY, -1};
50 static lst_sid_t session_id;
51 static int session_key;
53 /* All nodes running 2.6.50 or later understand feature LST_FEAT_BULK_LEN */
54 static unsigned session_features = LST_FEATS_MASK;
55 static lstcon_trans_stat_t trans_stat;
57 typedef struct list_string {
58 struct list_string *lstr_next;
64 # define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
67 static int alloc_count = 0;
68 static int alloc_nob = 0;
73 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
76 fprintf(stderr, "Can't allocate lstr\n");
83 lstr->lstr_str[0] = 0;
89 free_lstr(lstr_t *lstr)
92 alloc_nob -= lstr->lstr_sz;
97 free_lstrs(lstr_t **list)
101 while ((lstr = *list) != NULL) {
102 *list = lstr->lstr_next;
108 new_lstrs(lstr_t **list, char *prefix, char *postfix,
109 int lo, int hi, int stride)
111 int n1 = strlen(prefix);
112 int n2 = strlen(postfix);
113 int sz = n1 + 20 + n2 + 1;
116 lstr_t *n = alloc_lstr(sz);
118 snprintf(n->lstr_str, sz - 1, "%s%u%s",
119 prefix, lo, postfix);
121 n->lstr_next = *list;
129 expand_lstr(lstr_t **list, lstr_t *l)
131 int nob = strlen(l->lstr_str);
141 b1 = strchr(l->lstr_str, '[');
143 l->lstr_next = *list;
148 b2 = strchr(b1, ']');
149 if (b2 == NULL || b2 == b1 + 1)
157 sep = strchr(expr, ',');
163 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
165 new_lstrs(list, l->lstr_str, b2, x, x, 1);
170 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
173 new_lstrs(list, l->lstr_str, b2, x, y, 1);
178 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
181 new_lstrs(list, l->lstr_str, b2, x, y, z);
187 } while ((expr = sep) != NULL);
195 expand_strs(char *str, lstr_t **head)
203 l = alloc_lstr(strlen(str) + 1);
204 memcpy(l->lstr_str, str, strlen(str) + 1);
212 while ((l = list) != NULL) {
215 rc = expand_lstr(&nlist, l);
217 fprintf(stderr, "Syntax error in \"%s\"\n", str);
225 /* re-order onto 'list' */
226 while ((l = nlist) != NULL) {
227 nlist = l->lstr_next;
232 } while (expanded && rc > 0);
239 while ((l = list) != NULL) {
248 lst_parse_nids(char *str, int *countp, lnet_process_id_t **idspp)
256 rc = expand_strs(str, &head);
266 *idspp = malloc(c * sizeof(lnet_process_id_t));
267 if (*idspp == NULL) {
268 fprintf(stderr, "Out of memory\n");
275 while ((l = head) != NULL) {
279 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
280 if ((*idspp)[i].nid == LNET_NID_ANY) {
281 fprintf(stderr, "Invalid nid: %s\n",
286 (*idspp)[i].pid = LNET_PID_LUSTRE;
303 lst_node_state2str(int state)
305 if (state == LST_NODE_ACTIVE)
307 if (state == LST_NODE_BUSY)
309 if (state == LST_NODE_DOWN)
316 lst_node_str2state(char *str)
318 if (strcasecmp(str, "active") == 0)
319 return LST_NODE_ACTIVE;
320 if (strcasecmp(str, "busy") == 0)
321 return LST_NODE_BUSY;
322 if (strcasecmp(str, "down") == 0)
323 return LST_NODE_DOWN;
324 if (strcasecmp(str, "unknown") == 0)
325 return LST_NODE_UNKNOWN;
326 if (strcasecmp(str, "invalid") == 0)
327 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
333 lst_test_type2name(int type)
335 if (type == LST_TEST_PING)
337 if (type == LST_TEST_BULK)
344 lst_test_name2type(char *name)
346 if (strcasecmp(name, "ping") == 0)
347 return LST_TEST_PING;
348 if (strcasecmp(name, "brw") == 0)
349 return LST_TEST_BULK;
355 lst_print_usage(char *cmd)
357 Parser_printhelp(cmd);
361 lst_print_error(char *sub, const char *def_format, ...)
365 /* local error returned from kernel */
368 fprintf(stderr, "No session exists\n");
371 fprintf(stderr, "Session is shutting down\n");
374 fprintf(stderr, "Unmatched session key or not root\n");
377 fprintf(stderr, "Can't find %s in current session\n", sub);
380 fprintf(stderr, "Invalid parameters list in command line\n");
383 fprintf(stderr, "Bad parameter address\n");
386 fprintf(stderr, "%s already exists\n", sub);
389 va_start(ap, def_format);
390 vfprintf(stderr, def_format, ap);
398 lst_free_rpcent(struct list_head *head)
400 lstcon_rpc_ent_t *ent;
402 while (!list_empty(head)) {
403 ent = list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
405 list_del(&ent->rpe_link);
411 lst_reset_rpcent(struct list_head *head)
413 lstcon_rpc_ent_t *ent;
415 list_for_each_entry(ent, head, rpe_link) {
416 ent->rpe_sid = LST_INVALID_SID;
417 ent->rpe_peer.nid = LNET_NID_ANY;
418 ent->rpe_peer.pid = LNET_PID_ANY;
419 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
424 lst_alloc_rpcent(struct list_head *head, int count, int offset)
426 lstcon_rpc_ent_t *ent;
429 for (i = 0; i < count; i++) {
430 ent = malloc(offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
432 lst_free_rpcent(head);
436 memset(ent, 0, offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
438 ent->rpe_sid = LST_INVALID_SID;
439 ent->rpe_peer.nid = LNET_NID_ANY;
440 ent->rpe_peer.pid = LNET_PID_ANY;
441 list_add(&ent->rpe_link, head);
448 lst_print_transerr(struct list_head *head, char *optstr)
450 lstcon_rpc_ent_t *ent;
452 list_for_each_entry(ent, head, rpe_link) {
453 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
456 if (ent->rpe_rpc_errno != 0) {
457 fprintf(stderr, "%s RPC failed on %s: %s\n",
458 optstr, libcfs_id2str(ent->rpe_peer),
459 strerror(ent->rpe_rpc_errno));
463 fprintf(stderr, "operation %s failed on %s: %s\n",
464 optstr, libcfs_id2str(ent->rpe_peer),
465 strerror(ent->rpe_fwk_errno));
469 int lst_info_batch_ioctl(char *batch, int test, int server,
470 lstcon_test_batch_ent_t *entp, int *idxp,
471 int *ndentp, lstcon_node_ent_t *dentsp);
473 int lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
474 int *idx, int *count, lstcon_node_ent_t *dents);
476 int lst_query_batch_ioctl(char *batch, int test, int server,
477 int timeout, struct list_head *head);
480 lst_ioctl(unsigned int opc, void *buf, int len)
482 struct libcfs_ioctl_data data;
485 LIBCFS_IOC_INIT (data);
486 data.ioc_u32[0] = opc;
487 data.ioc_plen1 = len;
488 data.ioc_pbuf1 = (char *)buf;
489 data.ioc_plen2 = sizeof(trans_stat);
490 data.ioc_pbuf2 = (char *)&trans_stat;
492 memset(&trans_stat, 0, sizeof(trans_stat));
494 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
496 /* local error, no valid RPC result */
501 if (trans_stat.trs_rpc_errno != 0)
504 /* Framework error */
505 if (trans_stat.trs_fwk_errno != 0)
512 lst_new_session_ioctl(char *name, int timeout, int force, lst_sid_t *sid)
514 lstio_session_new_args_t args = {0};
516 args.lstio_ses_key = session_key;
517 args.lstio_ses_timeout = timeout;
518 args.lstio_ses_force = force;
519 args.lstio_ses_idp = sid;
520 args.lstio_ses_feats = session_features;
521 args.lstio_ses_nmlen = strlen(name);
522 args.lstio_ses_namep = name;
524 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
528 jt_lst_new_session(int argc, char **argv)
530 char buf[LST_NAME_SIZE];
538 static struct option session_opts[] =
540 {"timeout", required_argument, 0, 't' },
541 {"force", no_argument, 0, 'f' },
545 if (session_key == 0) {
547 "Can't find env LST_SESSION or value is not valid\n");
553 c = getopt_long(argc, argv, "ft:",
554 session_opts, &optidx);
564 timeout = atoi(optarg);
567 lst_print_usage(argv[0]);
573 fprintf(stderr, "Invalid timeout value\n");
577 if (optind == argc - 1) {
578 name = argv[optind ++];
579 if (strlen(name) >= LST_NAME_SIZE) {
580 fprintf(stderr, "Name size is limited to %d\n",
585 } else if (optind == argc) {
586 char user[LST_NAME_SIZE];
587 char host[LST_NAME_SIZE];
588 struct passwd *pw = getpwuid(getuid());
591 snprintf(user, sizeof(user), "%d", (int)getuid());
593 snprintf(user, sizeof(user), "%s", pw->pw_name);
595 rc = gethostname(host, sizeof(host));
597 snprintf(host, sizeof(host), "unknown_host");
599 snprintf(buf, sizeof(buf), "%s@%s", user, host);
603 lst_print_usage(argv[0]);
607 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
609 lst_print_error("session", "Failed to create session: %s\n",
614 fprintf(stdout, "SESSION: %s FEATURES: %x TIMEOUT: %d FORCE: %s\n",
615 name, session_features, timeout, force ? "Yes" : "No");
620 lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp,
621 lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
623 lstio_session_info_args_t args = {0};
625 args.lstio_ses_idp = sid;
626 args.lstio_ses_keyp = key;
627 args.lstio_ses_featp = featp;
628 args.lstio_ses_ndinfo = ndinfo;
629 args.lstio_ses_nmlen = len;
630 args.lstio_ses_namep = name;
632 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
636 jt_lst_show_session(int argc, char **argv)
638 lstcon_ndlist_ent_t ndinfo;
640 char name[LST_NAME_SIZE];
645 rc = lst_session_info_ioctl(name, sizeof(name), &key,
646 &feats, &sid, &ndinfo);
649 lst_print_error("session", "Failed to show session: %s\n",
654 fprintf(stdout, "%s ID: "LPU64"@%s, KEY: %d FEATURES: %x NODES: %d\n",
655 name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
656 key, feats, ndinfo.nle_nnode);
662 lst_end_session_ioctl(void)
664 lstio_session_end_args_t args = {0};
666 args.lstio_ses_key = session_key;
667 return lst_ioctl (LSTIO_SESSION_END, &args, sizeof(args));
671 jt_lst_end_session(int argc, char **argv)
675 if (session_key == 0) {
677 "Can't find env LST_SESSION or value is not valid\n");
681 rc = lst_end_session_ioctl();
684 fprintf(stdout, "session is ended\n");
689 lst_print_error("session", "Failed to end session: %s\n",
694 if (trans_stat.trs_rpc_errno != 0) {
696 "[RPC] Failed to send %d session RPCs: %s\n",
697 lstcon_rpc_stat_failure(&trans_stat, 0),
698 strerror(trans_stat.trs_rpc_errno));
701 if (trans_stat.trs_fwk_errno != 0) {
703 "[FWK] Failed to end session on %d nodes: %s\n",
704 lstcon_sesop_stat_failure(&trans_stat, 0),
705 strerror(trans_stat.trs_fwk_errno));
712 lst_ping_ioctl(char *str, int type, int timeout,
713 int count, lnet_process_id_t *ids, struct list_head *head)
715 lstio_debug_args_t args = {0};
717 args.lstio_dbg_key = session_key;
718 args.lstio_dbg_type = type;
719 args.lstio_dbg_flags = 0;
720 args.lstio_dbg_timeout = timeout;
721 args.lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str);
722 args.lstio_dbg_namep = str;
723 args.lstio_dbg_count = count;
724 args.lstio_dbg_idsp = ids;
725 args.lstio_dbg_resultp = head;
727 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
731 lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
733 char buf[LST_NAME_SIZE];
734 lstcon_test_batch_ent_t ent;
735 lstcon_ndlist_ent_t *entp = &ent.tbe_cli_nle;
742 case LST_OPC_SESSION:
743 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
744 &key, &feats, &sid, entp);
747 case LST_OPC_BATCHSRV:
748 entp = &ent.tbe_srv_nle;
749 case LST_OPC_BATCHCLI:
750 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
754 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
758 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
767 *countp = entp->nle_nnode;
773 jt_lst_ping(int argc, char **argv)
775 struct list_head head;
776 lnet_process_id_t *ids = NULL;
777 lstcon_rpc_ent_t *ent = NULL;
787 static struct option ping_opts[] =
789 {"session", no_argument, 0, 's' },
790 {"server", no_argument, 0, 'v' },
791 {"batch", required_argument, 0, 'b' },
792 {"group", required_argument, 0, 'g' },
793 {"nodes", required_argument, 0, 'n' },
794 {"timeout", required_argument, 0, 't' },
798 if (session_key == 0) {
800 "Can't find env LST_SESSION or value is not valid\n");
806 c = getopt_long(argc, argv, "g:b:n:t:sv",
814 type = LST_OPC_SESSION;
818 type = LST_OPC_GROUP;
823 type = LST_OPC_BATCHCLI;
828 type = LST_OPC_NODES;
833 timeout = atoi(optarg);
841 lst_print_usage(argv[0]);
846 if (type == 0 || timeout <= 0 || optind != argc) {
847 lst_print_usage(argv[0]);
851 if (type == LST_OPC_BATCHCLI && server)
852 type = LST_OPC_BATCHSRV;
854 rc = lst_get_node_count(type, str, &count, &ids);
856 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
857 (str == NULL) ? "session" : str, strerror(errno));
861 INIT_LIST_HEAD(&head);
863 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
865 fprintf(stderr, "Out of memory\n");
870 fprintf(stdout, "Target %s is empty\n",
871 (str == NULL) ? "session" : str);
875 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
876 if (rc == -1) { /* local failure */
877 lst_print_error("debug", "Failed to ping %s: %s\n",
878 (str == NULL) ? "session" : str,
884 /* ignore RPC errors and framwork errors */
885 list_for_each_entry(ent, &head, rpe_link) {
886 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
887 libcfs_id2str(ent->rpe_peer),
888 lst_node_state2str(ent->rpe_state),
889 (ent->rpe_state == LST_NODE_ACTIVE ||
890 ent->rpe_state == LST_NODE_BUSY) ?
891 (ent->rpe_rpc_errno == 0 ?
892 &ent->rpe_payload[0] : "Unknown") :
893 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
897 lst_free_rpcent(&head);
907 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
908 unsigned *featp, struct list_head *resultp)
910 lstio_group_nodes_args_t args = {0};
912 args.lstio_grp_key = session_key;
913 args.lstio_grp_nmlen = strlen(name);
914 args.lstio_grp_namep = name;
915 args.lstio_grp_count = count;
916 args.lstio_grp_featp = featp;
917 args.lstio_grp_idsp = ids;
918 args.lstio_grp_resultp = resultp;
920 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
924 lst_del_group_ioctl(char *name)
926 lstio_group_del_args_t args = {0};
928 args.lstio_grp_key = session_key;
929 args.lstio_grp_nmlen = strlen(name);
930 args.lstio_grp_namep = name;
932 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
936 lst_del_group(char *grp_name)
940 rc = lst_del_group_ioctl(grp_name);
942 fprintf(stdout, "Group is deleted\n");
947 lst_print_error("group", "Failed to delete group: %s\n",
952 fprintf(stderr, "Group is deleted with some errors\n");
954 if (trans_stat.trs_rpc_errno != 0) {
956 "[RPC] Failed to send %d end session RPCs: %s\n",
957 lstcon_rpc_stat_failure(&trans_stat, 0),
958 strerror(trans_stat.trs_rpc_errno));
961 if (trans_stat.trs_fwk_errno != 0) {
963 "[FWK] Failed to end session on %d nodes: %s\n",
964 lstcon_sesop_stat_failure(&trans_stat, 0),
965 strerror(trans_stat.trs_fwk_errno));
972 lst_add_group_ioctl (char *name)
974 lstio_group_add_args_t args = {0};
976 args.lstio_grp_key = session_key;
977 args.lstio_grp_nmlen = strlen(name);
978 args.lstio_grp_namep = name;
980 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
984 jt_lst_add_group(int argc, char **argv)
986 struct list_head head;
987 lnet_process_id_t *ids;
989 unsigned feats = session_features;
993 bool nodes_added = false;
995 if (session_key == 0) {
997 "Can't find env LST_SESSION or value is not valid\n");
1002 lst_print_usage(argv[0]);
1007 if (strlen(name) >= LST_NAME_SIZE) {
1008 fprintf(stderr, "Name length is limited to %d\n",
1013 rc = lst_add_group_ioctl(name);
1015 lst_print_error("group", "Failed to add group %s: %s\n",
1016 name, strerror(errno));
1020 INIT_LIST_HEAD(&head);
1022 for (i = 2; i < argc; i++) {
1023 /* parse address list */
1024 rc = lst_parse_nids(argv[i], &count, &ids);
1026 fprintf(stderr, "Ignore invalid id list %s\n",
1034 rc = lst_alloc_rpcent(&head, count, 0);
1036 fprintf(stderr, "Out of memory\n");
1042 rc = lst_add_nodes_ioctl(name, count, ids, &feats, &head);
1049 fprintf(stdout, "%s are added to session\n", argv[i]);
1053 if ((feats & session_features) != session_features) {
1055 "Warning, this session will run with "
1056 "compatible mode because some test nodes "
1057 "might not understand these features: %x\n",
1058 (~feats & session_features));
1061 lst_free_rpcent(&head);
1066 * The selftest kernel module expects that a group should
1067 * have at least one node, since it doesn't make sense for
1068 * an empty group to be added to a test.
1071 "No nodes added successfully, deleting group %s\n",
1073 rc = lst_del_group(name);
1076 "Failed to delete group %s."
1077 " Group is empty.\n", name);
1085 lst_print_error("group", "Failed to add nodes %s: %s\n",
1086 argv[i], strerror(errno));
1089 if (trans_stat.trs_fwk_errno == EPROTO) {
1091 "test nodes might have different LST "
1092 "features, please disable some features by "
1093 "setting LST_FEATURES\n");
1096 lst_print_transerr(&head, "create session");
1099 lst_free_rpcent(&head);
1103 "No nodes added successfully, deleting group %s\n",
1105 if (lst_del_group(name) != 0) {
1107 "Failed to delete group %s."
1108 " Group is empty.\n", name);
1116 jt_lst_del_group(int argc, char **argv)
1120 if (session_key == 0) {
1122 "Can't find env LST_SESSION or value is not valid\n");
1127 lst_print_usage(argv[0]);
1131 rc = lst_del_group(argv[1]);
1137 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1138 lnet_process_id_t *ids, struct list_head *resultp)
1140 lstio_group_update_args_t args = {0};
1142 args.lstio_grp_key = session_key;
1143 args.lstio_grp_opc = opc;
1144 args.lstio_grp_args = clean;
1145 args.lstio_grp_nmlen = strlen(name);
1146 args.lstio_grp_namep = name;
1147 args.lstio_grp_count = count;
1148 args.lstio_grp_idsp = ids;
1149 args.lstio_grp_resultp = resultp;
1151 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1155 jt_lst_update_group(int argc, char **argv)
1157 struct list_head head;
1158 lnet_process_id_t *ids = NULL;
1168 static struct option update_group_opts[] =
1170 {"refresh", no_argument, 0, 'f' },
1171 {"clean", required_argument, 0, 'c' },
1172 {"remove", required_argument, 0, 'r' },
1176 if (session_key == 0) {
1178 "Can't find env LST_SESSION or value is not valid\n");
1183 c = getopt_long(argc, argv, "fc:r:",
1184 update_group_opts, &optidx);
1186 /* Detect the end of the options. */
1193 lst_print_usage(argv[0]);
1196 opc = LST_GROUP_REFRESH;
1201 lst_print_usage(argv[0]);
1204 opc = LST_GROUP_RMND;
1209 clean = lst_node_str2state(optarg);
1210 if (opc != 0 || clean <= 0) {
1211 lst_print_usage(argv[0]);
1214 opc = LST_GROUP_CLEAN;
1218 lst_print_usage(argv[0]);
1223 /* no OPC or group is specified */
1224 if (opc == 0 || optind != argc - 1) {
1225 lst_print_usage(argv[0]);
1231 INIT_LIST_HEAD(&head);
1233 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1234 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1236 opc == LST_GROUP_RMND ? str : grp,
1240 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1241 opc == LST_GROUP_RMND ? str : grp,
1246 rc = lst_alloc_rpcent(&head, count, 0);
1248 fprintf(stderr, "Out of memory\n");
1255 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1261 lst_free_rpcent(&head);
1266 lst_free_rpcent(&head);
1267 lst_print_error("group", "Failed to update group: %s\n",
1272 lst_print_transerr(&head, "Updating group");
1274 lst_free_rpcent(&head);
1280 lst_list_group_ioctl(int len, char *name, int idx)
1282 lstio_group_list_args_t args = {0};
1284 args.lstio_grp_key = session_key;
1285 args.lstio_grp_idx = idx;
1286 args.lstio_grp_nmlen = len;
1287 args.lstio_grp_namep = name;
1289 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1293 lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
1294 int *idx, int *count, lstcon_node_ent_t *dents)
1296 lstio_group_info_args_t args = {0};
1298 args.lstio_grp_key = session_key;
1299 args.lstio_grp_nmlen = strlen(name);
1300 args.lstio_grp_namep = name;
1301 args.lstio_grp_entp = gent;
1302 args.lstio_grp_idxp = idx;
1303 args.lstio_grp_ndentp = count;
1304 args.lstio_grp_dentsp = dents;
1306 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1310 lst_list_group_all(void)
1312 char name[LST_NAME_SIZE];
1316 /* no group is specified, list name of all groups */
1317 for (i = 0; ; i++) {
1318 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1320 fprintf(stdout, "%d) %s\n", i + 1, name);
1324 if (errno == ENOENT)
1327 lst_print_error("group", "Failed to list group: %s\n",
1332 fprintf(stdout, "Total %d groups\n", i);
1337 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1340 jt_lst_list_group(int argc, char **argv)
1342 lstcon_ndlist_ent_t gent;
1343 lstcon_node_ent_t *dents;
1358 static struct option list_group_opts[] =
1360 {"active", no_argument, 0, 'a' },
1361 {"busy", no_argument, 0, 'b' },
1362 {"down", no_argument, 0, 'd' },
1363 {"unknown", no_argument, 0, 'u' },
1364 {"all", no_argument, 0, 'l' },
1368 if (session_key == 0) {
1370 "Can't find env LST_SESSION or value is not valid\n");
1375 c = getopt_long(argc, argv, "abdul",
1376 list_group_opts, &optidx);
1383 verbose = active = 1;
1395 verbose = unknown = 1;
1402 lst_print_usage(argv[0]);
1407 if (optind == argc) {
1408 /* no group is specified, list name of all groups */
1409 rc = lst_list_group_all();
1415 fprintf(stdout, LST_NODES_TITLE);
1417 /* list nodes in specified groups */
1418 for (i = optind; i < argc; i++) {
1419 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1421 if (errno == ENOENT) {
1426 lst_print_error("group", "Failed to list group\n",
1432 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1433 gent.nle_nactive, gent.nle_nbusy,
1434 gent.nle_ndown, gent.nle_nunknown,
1435 gent.nle_nnode, argv[i]);
1439 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1441 if (gent.nle_nnode == 0) {
1442 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1446 count = gent.nle_nnode;
1448 dents = malloc(count * sizeof(lstcon_node_ent_t));
1449 if (dents == NULL) {
1450 fprintf(stderr, "Failed to malloc: %s\n",
1456 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1458 lst_print_error("group", "Failed to list group: %s\n",
1464 for (j = 0, c = 0; j < count; j++) {
1466 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1467 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1468 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1469 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1471 fprintf(stdout, "\t%s: %s\n",
1472 libcfs_id2str(dents[j].nde_id),
1473 lst_node_state2str(dents[j].nde_state));
1478 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1487 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
1488 int timeout, struct list_head *resultp)
1490 lstio_stat_args_t args = {0};
1492 args.lstio_sta_key = session_key;
1493 args.lstio_sta_timeout = timeout;
1494 args.lstio_sta_nmlen = strlen(name);
1495 args.lstio_sta_namep = name;
1496 args.lstio_sta_count = count;
1497 args.lstio_sta_idsp = idsp;
1498 args.lstio_sta_resultp = resultp;
1500 return lst_ioctl (LSTIO_STAT_QUERY, &args, sizeof(args));
1504 struct list_head srp_link;
1507 lnet_process_id_t *srp_ids;
1508 struct list_head srp_result[2];
1509 } lst_stat_req_param_t;
1512 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1516 for (i = 0; i < 2; i++)
1517 lst_free_rpcent(&srp->srp_result[i]);
1519 if (srp->srp_ids != NULL)
1526 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
1528 lst_stat_req_param_t *srp = NULL;
1529 int count = save_old ? 2 : 1;
1533 srp = malloc(sizeof(*srp));
1537 memset(srp, 0, sizeof(*srp));
1538 INIT_LIST_HEAD(&srp->srp_result[0]);
1539 INIT_LIST_HEAD(&srp->srp_result[1]);
1541 rc = lst_get_node_count(LST_OPC_GROUP, name,
1542 &srp->srp_count, NULL);
1543 if (rc != 0 && errno == ENOENT) {
1544 rc = lst_get_node_count(LST_OPC_NODES, name,
1545 &srp->srp_count, &srp->srp_ids);
1550 "Failed to get count of nodes from %s: %s\n",
1551 name, strerror(errno));
1552 lst_stat_req_param_free(srp);
1557 srp->srp_name = name;
1559 for (i = 0; i < count; i++) {
1560 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1561 sizeof(sfw_counters_t) +
1562 sizeof(srpc_counters_t) +
1563 sizeof(lnet_counters_t));
1565 fprintf(stderr, "Out of memory\n");
1575 lst_stat_req_param_free(srp);
1583 } lst_srpc_stat_result;
1585 #define LST_LNET_AVG 0
1586 #define LST_LNET_MIN 1
1587 #define LST_LNET_MAX 2
1590 float lnet_avg_sndrate;
1591 float lnet_min_sndrate;
1592 float lnet_max_sndrate;
1593 float lnet_total_sndrate;
1595 float lnet_avg_rcvrate;
1596 float lnet_min_rcvrate;
1597 float lnet_max_rcvrate;
1598 float lnet_total_rcvrate;
1600 float lnet_avg_sndperf;
1601 float lnet_min_sndperf;
1602 float lnet_max_sndperf;
1603 float lnet_total_sndperf;
1605 float lnet_avg_rcvperf;
1606 float lnet_min_rcvperf;
1607 float lnet_max_rcvperf;
1608 float lnet_total_rcvperf;
1610 int lnet_stat_count;
1611 } lst_lnet_stat_result_t;
1613 lst_lnet_stat_result_t lnet_stat_result;
1616 lst_lnet_stat_value(int bw, int send, int off)
1620 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1621 &lnet_stat_result.lnet_avg_sndrate;
1632 lst_timeval_diff(struct timeval *tv1,
1633 struct timeval *tv2, struct timeval *df)
1635 if (tv1->tv_usec >= tv2->tv_usec) {
1636 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1637 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1641 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1642 df->tv_usec = tv1->tv_usec + 1000000 - tv2->tv_usec;
1648 lst_cal_lnet_stat(float delta, lnet_counters_t *lnet_new,
1649 lnet_counters_t *lnet_old)
1654 perf = (float)(lnet_new->send_length -
1655 lnet_old->send_length) / (1024 * 1024) / delta;
1656 lnet_stat_result.lnet_total_sndperf += perf;
1658 if (lnet_stat_result.lnet_min_sndperf > perf ||
1659 lnet_stat_result.lnet_min_sndperf == 0)
1660 lnet_stat_result.lnet_min_sndperf = perf;
1662 if (lnet_stat_result.lnet_max_sndperf < perf)
1663 lnet_stat_result.lnet_max_sndperf = perf;
1665 perf = (float)(lnet_new->recv_length -
1666 lnet_old->recv_length) / (1024 * 1024) / delta;
1667 lnet_stat_result.lnet_total_rcvperf += perf;
1669 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1670 lnet_stat_result.lnet_min_rcvperf == 0)
1671 lnet_stat_result.lnet_min_rcvperf = perf;
1673 if (lnet_stat_result.lnet_max_rcvperf < perf)
1674 lnet_stat_result.lnet_max_rcvperf = perf;
1676 rate = (lnet_new->send_count - lnet_old->send_count) / delta;
1677 lnet_stat_result.lnet_total_sndrate += rate;
1679 if (lnet_stat_result.lnet_min_sndrate > rate ||
1680 lnet_stat_result.lnet_min_sndrate == 0)
1681 lnet_stat_result.lnet_min_sndrate = rate;
1683 if (lnet_stat_result.lnet_max_sndrate < rate)
1684 lnet_stat_result.lnet_max_sndrate = rate;
1686 rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
1687 lnet_stat_result.lnet_total_rcvrate += rate;
1689 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1690 lnet_stat_result.lnet_min_rcvrate == 0)
1691 lnet_stat_result.lnet_min_rcvrate = rate;
1693 if (lnet_stat_result.lnet_max_rcvrate < rate)
1694 lnet_stat_result.lnet_max_rcvrate = rate;
1696 lnet_stat_result.lnet_stat_count ++;
1698 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1699 lnet_stat_result.lnet_stat_count;
1700 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1701 lnet_stat_result.lnet_stat_count;
1703 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1704 lnet_stat_result.lnet_stat_count;
1705 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1706 lnet_stat_result.lnet_stat_count;
1711 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
1720 if (lnet_stat_result.lnet_stat_count == 0)
1723 if (bwrt == 1) /* bw only */
1726 if (bwrt == 2) /* rates only */
1729 if (rdwr == 1) /* recv only */
1732 if (rdwr == 2) /* send only */
1735 for (i = start1; i <= end1; i++) {
1736 fprintf(stdout, "[LNet %s of %s]\n",
1737 i == 0 ? "Rates" : "Bandwidth", name);
1739 for (j = start2; j <= end2; j++) {
1740 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
1742 if ((type & 1) != 0) {
1743 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1744 "Avg: %-8.2f MB/s ",
1745 lst_lnet_stat_value(i, j, 0));
1748 if ((type & 2) != 0) {
1749 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1750 "Min: %-8.2f MB/s ",
1751 lst_lnet_stat_value(i, j, 1));
1754 if ((type & 4) != 0) {
1755 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1757 lst_lnet_stat_value(i, j, 2));
1760 fprintf(stdout, "\n");
1766 lst_print_stat(char *name, struct list_head *resultp,
1767 int idx, int lnet, int bwrt, int rdwr, int type)
1769 struct list_head tmp[2];
1770 lstcon_rpc_ent_t *new;
1771 lstcon_rpc_ent_t *old;
1772 sfw_counters_t *sfwk_new;
1773 sfw_counters_t *sfwk_old;
1774 srpc_counters_t *srpc_new;
1775 srpc_counters_t *srpc_old;
1776 lnet_counters_t *lnet_new;
1777 lnet_counters_t *lnet_old;
1781 INIT_LIST_HEAD(&tmp[0]);
1782 INIT_LIST_HEAD(&tmp[1]);
1784 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1786 while (!list_empty(&resultp[idx])) {
1787 if (list_empty(&resultp[1 - idx])) {
1788 fprintf(stderr, "Group is changed, re-run stat\n");
1792 new = list_entry(resultp[idx].next, lstcon_rpc_ent_t,
1794 old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t,
1797 /* first time get stats result, can't calculate diff */
1798 if (new->rpe_peer.nid == LNET_NID_ANY)
1801 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1802 new->rpe_peer.pid != old->rpe_peer.pid) {
1803 /* Something wrong. i.e, somebody change the group */
1807 list_del(&new->rpe_link);
1808 list_add_tail(&new->rpe_link, &tmp[idx]);
1810 list_del(&old->rpe_link);
1811 list_add_tail(&old->rpe_link, &tmp[1 - idx]);
1813 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1814 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1819 sfwk_new = (sfw_counters_t *)&new->rpe_payload[0];
1820 sfwk_old = (sfw_counters_t *)&old->rpe_payload[0];
1822 srpc_new = (srpc_counters_t *)((char *)sfwk_new + sizeof(*sfwk_new));
1823 srpc_old = (srpc_counters_t *)((char *)sfwk_old + sizeof(*sfwk_old));
1825 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
1826 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
1828 /* Prior to version 2.3, the running_ms field was a counter for
1829 * the number of running tests. We are looking at this value
1830 * to determine if it is a millisecond timestamep (>= 2.3) or a
1831 * test counter (< 2.3). The number 500 is being used for this
1832 * barrier as the test counter should never get this high, and
1833 * the timestamp should never get this low. */
1835 if (sfwk_new->running_ms > 500) {
1836 /* use the timestamp from the remote node, not our
1837 * rpe_stamp from when we copied up the data out of
1840 delta = (float) (sfwk_new->running_ms -
1841 sfwk_old->running_ms) / 1000;
1845 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1846 delta = tv.tv_sec + (float)tv.tv_usec / 1000000;
1849 if (!lnet) /* TODO */
1852 lst_cal_lnet_stat(delta, lnet_new, lnet_old);
1855 list_splice(&tmp[idx], &resultp[idx]);
1856 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1859 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1861 if (!lnet) /* TODO */
1864 lst_print_lnet_stat(name, bwrt, rdwr, type);
1868 jt_lst_stat(int argc, char **argv)
1870 struct list_head head;
1871 lst_stat_req_param_t *srp;
1874 int timeout = 5; /* default timeout, 5 sec */
1875 int delay = 5; /* default delay, 5 sec */
1876 int count = -1; /* run forever */
1877 int lnet = 1; /* lnet stat by default */
1885 static struct option stat_opts[] =
1887 {"timeout" , required_argument, 0, 't' },
1888 {"delay" , required_argument, 0, 'd' },
1889 {"count" , required_argument, 0, 'o' },
1890 {"lnet" , no_argument, 0, 'l' },
1891 {"rpc" , no_argument, 0, 'c' },
1892 {"bw" , no_argument, 0, 'b' },
1893 {"rate" , no_argument, 0, 'a' },
1894 {"read" , no_argument, 0, 'r' },
1895 {"write" , no_argument, 0, 'w' },
1896 {"avg" , no_argument, 0, 'g' },
1897 {"min" , no_argument, 0, 'n' },
1898 {"max" , no_argument, 0, 'x' },
1902 if (session_key == 0) {
1904 "Can't find env LST_SESSION or value is not valid\n");
1909 c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
1916 timeout = atoi(optarg);
1919 delay = atoi(optarg);
1922 count = atoi(optarg);
1965 lst_print_usage(argv[0]);
1970 if (optind == argc) {
1971 lst_print_usage(argv[0]);
1975 if (timeout <= 0 || delay <= 0) {
1976 fprintf(stderr, "Invalid timeout or delay value\n");
1981 fprintf(stderr, "Invalid count value\n");
1985 /* extra count to get first data point */
1989 INIT_LIST_HEAD(&head);
1991 while (optind < argc) {
1992 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
1996 list_add_tail(&srp->srp_link, &head);
2000 time_t now = time(NULL);
2002 if (now - last < delay) {
2003 sleep(delay - now + last);
2008 list_for_each_entry(srp, &head, srp_link) {
2009 rc = lst_stat_ioctl(srp->srp_name,
2010 srp->srp_count, srp->srp_ids,
2011 timeout, &srp->srp_result[idx]);
2013 lst_print_error("stat", "Failed to stat %s: %s\n",
2014 srp->srp_name, strerror(errno));
2018 lst_print_stat(srp->srp_name, srp->srp_result,
2019 idx, lnet, bwrt, rdwr, type);
2021 lst_reset_rpcent(&srp->srp_result[1 - idx]);
2028 } while (count == -1 || count > 0);
2031 while (!list_empty(&head)) {
2032 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2034 list_del(&srp->srp_link);
2035 lst_stat_req_param_free(srp);
2042 jt_lst_show_error(int argc, char **argv)
2044 struct list_head head;
2045 lst_stat_req_param_t *srp;
2046 lstcon_rpc_ent_t *ent;
2047 sfw_counters_t *sfwk;
2048 srpc_counters_t *srpc;
2055 static struct option show_error_opts[] =
2057 {"session", no_argument, 0, 's' },
2061 if (session_key == 0) {
2063 "Can't find env LST_SESSION or value is not valid\n");
2068 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
2079 lst_print_usage(argv[0]);
2084 if (optind == argc) {
2085 lst_print_usage(argv[0]);
2089 INIT_LIST_HEAD(&head);
2091 while (optind < argc) {
2092 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
2096 list_add_tail(&srp->srp_link, &head);
2099 list_for_each_entry(srp, &head, srp_link) {
2100 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
2101 srp->srp_ids, 10, &srp->srp_result[0]);
2104 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2105 srp->srp_name, strerror(errno));
2109 fprintf(stdout, "%s:\n", srp->srp_name);
2113 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2114 if (ent->rpe_rpc_errno != 0) {
2116 fprintf(stderr, "RPC failure, can't show error on %s\n",
2117 libcfs_id2str(ent->rpe_peer));
2121 if (ent->rpe_fwk_errno != 0) {
2123 fprintf(stderr, "Framework failure, can't show error on %s\n",
2124 libcfs_id2str(ent->rpe_peer));
2128 sfwk = (sfw_counters_t *)&ent->rpe_payload[0];
2129 srpc = (srpc_counters_t *)((char *)sfwk + sizeof(*sfwk));
2131 if (srpc->errors == 0 &&
2132 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2136 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2141 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2142 libcfs_id2str(ent->rpe_peer),
2143 sfwk->brw_errors, sfwk->ping_errors,
2144 show_rpc ? ' ' : '\n');
2149 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2150 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2153 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2156 while (!list_empty(&head)) {
2157 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2159 list_del(&srp->srp_link);
2160 lst_stat_req_param_free(srp);
2167 lst_add_batch_ioctl (char *name)
2169 lstio_batch_add_args_t args = {0};
2171 args.lstio_bat_key = session_key;
2172 args.lstio_bat_nmlen = strlen(name);
2173 args.lstio_bat_namep = name;
2175 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2179 jt_lst_add_batch(int argc, char **argv)
2184 if (session_key == 0) {
2186 "Can't find env LST_SESSION or value is not valid\n");
2191 lst_print_usage(argv[0]);
2196 if (strlen(name) >= LST_NAME_SIZE) {
2197 fprintf(stderr, "Name length is limited to %d\n",
2202 rc = lst_add_batch_ioctl(name);
2206 lst_print_error("batch", "Failed to create batch: %s\n",
2213 lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp)
2215 lstio_batch_run_args_t args = {0};
2217 args.lstio_bat_key = session_key;
2218 args.lstio_bat_timeout = timeout;
2219 args.lstio_bat_nmlen = strlen(name);
2220 args.lstio_bat_namep = name;
2221 args.lstio_bat_resultp = resultp;
2223 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2227 jt_lst_start_batch(int argc, char **argv)
2229 struct list_head head;
2237 static struct option start_batch_opts[] =
2239 {"timeout", required_argument, 0, 't' },
2243 if (session_key == 0) {
2245 "Can't find env LST_SESSION or value is not valid\n");
2250 c = getopt_long(argc, argv, "t:",
2251 start_batch_opts, &optidx);
2253 /* Detect the end of the options. */
2259 timeout = atoi(optarg);
2262 lst_print_usage(argv[0]);
2267 if (optind == argc) {
2268 batch = LST_DEFAULT_BATCH;
2270 } else if (optind == argc - 1) {
2271 batch = argv[optind];
2274 lst_print_usage(argv[0]);
2278 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2280 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2281 batch, strerror(errno));
2285 INIT_LIST_HEAD(&head);
2287 rc = lst_alloc_rpcent(&head, count, 0);
2289 fprintf(stderr, "Out of memory\n");
2293 rc = lst_start_batch_ioctl(batch, timeout, &head);
2296 fprintf(stdout, "%s is running now\n", batch);
2297 lst_free_rpcent(&head);
2302 lst_print_error("batch", "Failed to start batch: %s\n",
2304 lst_free_rpcent(&head);
2308 lst_print_transerr(&head, "Run batch");
2310 lst_free_rpcent(&head);
2316 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2318 lstio_batch_stop_args_t args = {0};
2320 args.lstio_bat_key = session_key;
2321 args.lstio_bat_force = force;
2322 args.lstio_bat_nmlen = strlen(name);
2323 args.lstio_bat_namep = name;
2324 args.lstio_bat_resultp = resultp;
2326 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2330 jt_lst_stop_batch(int argc, char **argv)
2332 struct list_head head;
2340 static struct option stop_batch_opts[] =
2342 {"force", no_argument, 0, 'f' },
2346 if (session_key == 0) {
2348 "Can't find env LST_SESSION or value is not valid\n");
2353 c = getopt_long(argc, argv, "f",
2354 stop_batch_opts, &optidx);
2356 /* Detect the end of the options. */
2365 lst_print_usage(argv[0]);
2370 if (optind == argc) {
2371 batch = LST_DEFAULT_BATCH;
2373 } else if (optind == argc - 1) {
2374 batch = argv[optind];
2377 lst_print_usage(argv[0]);
2381 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2383 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2384 batch, strerror(errno));
2388 INIT_LIST_HEAD(&head);
2390 rc = lst_alloc_rpcent(&head, count, 0);
2392 fprintf(stderr, "Out of memory\n");
2396 rc = lst_stop_batch_ioctl(batch, force, &head);
2401 lst_reset_rpcent(&head);
2403 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2407 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2408 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2411 fprintf(stdout, "%d batch in stopping\n",
2412 lstcon_tsbqry_stat_run(&trans_stat, 0));
2416 fprintf(stdout, "Batch is stopped\n");
2417 lst_free_rpcent(&head);
2422 lst_print_error("batch", "Failed to stop batch: %s\n",
2424 lst_free_rpcent(&head);
2428 lst_print_transerr(&head, "stop batch");
2430 lst_free_rpcent(&head);
2436 lst_list_batch_ioctl(int len, char *name, int index)
2438 lstio_batch_list_args_t args = {0};
2440 args.lstio_bat_key = session_key;
2441 args.lstio_bat_idx = index;
2442 args.lstio_bat_nmlen = len;
2443 args.lstio_bat_namep = name;
2445 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2449 lst_info_batch_ioctl(char *batch, int test, int server,
2450 lstcon_test_batch_ent_t *entp, int *idxp,
2451 int *ndentp, lstcon_node_ent_t *dentsp)
2453 lstio_batch_info_args_t args = {0};
2455 args.lstio_bat_key = session_key;
2456 args.lstio_bat_nmlen = strlen(batch);
2457 args.lstio_bat_namep = batch;
2458 args.lstio_bat_server = server;
2459 args.lstio_bat_testidx = test;
2460 args.lstio_bat_entp = entp;
2461 args.lstio_bat_idxp = idxp;
2462 args.lstio_bat_ndentp = ndentp;
2463 args.lstio_bat_dentsp = dentsp;
2465 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2469 lst_list_batch_all(void)
2471 char name[LST_NAME_SIZE];
2475 for (i = 0; ; i++) {
2476 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2478 fprintf(stdout, "%d) %s\n", i + 1, name);
2482 if (errno == ENOENT)
2485 lst_print_error("batch", "Failed to list batch: %s\n",
2490 fprintf(stdout, "Total %d batches\n", i);
2496 lst_list_tsb_nodes(char *batch, int test, int server,
2497 int count, int active, int invalid)
2499 lstcon_node_ent_t *dents;
2508 /* verbose list, show nodes in batch or test */
2509 dents = malloc(count * sizeof(lstcon_node_ent_t));
2510 if (dents == NULL) {
2511 fprintf(stdout, "Can't allocate memory\n");
2515 rc = lst_info_batch_ioctl(batch, test, server,
2516 NULL, &index, &count, dents);
2519 lst_print_error((test > 0) ? "test" : "batch",
2520 (test > 0) ? "Failed to query test: %s\n" :
2521 "Failed to query batch: %s\n",
2526 for (i = 0, c = 0; i < count; i++) {
2527 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2528 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2529 dents[i].nde_state == LST_NODE_DOWN ||
2530 dents[i].nde_state == LST_NODE_UNKNOWN)))
2533 fprintf(stdout, "\t%s: %s\n",
2534 libcfs_id2str(dents[i].nde_id),
2535 lst_node_state2str(dents[i].nde_state));
2539 fprintf(stdout, "Total %d nodes\n", c);
2546 jt_lst_list_batch(int argc, char **argv)
2548 lstcon_test_batch_ent_t ent;
2551 int verbose = 0; /* list nodes in batch or test */
2560 static struct option list_batch_opts[] =
2562 {"test", required_argument, 0, 't' },
2563 {"invalid", no_argument, 0, 'i' },
2564 {"active", no_argument, 0, 'a' },
2565 {"all", no_argument, 0, 'l' },
2566 {"server", no_argument, 0, 's' },
2570 if (session_key == 0) {
2572 "Can't find env LST_SESSION or value is not valid\n");
2577 c = getopt_long(argc, argv, "ailst:",
2578 list_batch_opts, &optidx);
2585 verbose = active = 1;
2588 verbose = invalid = 1;
2591 verbose = active = invalid = 1;
2597 test = atoi(optarg);
2601 lst_print_usage(argv[0]);
2606 if (optind == argc) {
2607 /* list all batches */
2608 rc = lst_list_batch_all();
2612 if (ntest == 1 && test <= 0) {
2613 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2617 if (optind != argc - 1) {
2618 lst_print_usage(argv[0]);
2622 batch = argv[optind];
2625 /* show detail of specified batch or test */
2626 rc = lst_info_batch_ioctl(batch, test, server,
2627 &ent, NULL, NULL, NULL);
2629 lst_print_error((test > 0) ? "test" : "batch",
2630 (test > 0) ? "Failed to query test: %s\n" :
2631 "Failed to query batch: %s\n",
2637 /* list nodes in test or batch */
2638 rc = lst_list_tsb_nodes(batch, test, server,
2639 server ? ent.tbe_srv_nle.nle_nnode :
2640 ent.tbe_cli_nle.nle_nnode,
2645 /* only show number of hosts in batch or test */
2647 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2648 batch, ent.u.tbe_batch.bae_ntest,
2649 ent.u.tbe_batch.bae_state);
2650 ntest = ent.u.tbe_batch.bae_ntest;
2651 test = 1; /* starting from test 1 */
2655 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2656 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2657 ent.u.tbe_test.tse_loop,
2658 ent.u.tbe_test.tse_concur);
2663 fprintf(stdout, LST_NODES_TITLE);
2664 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2665 "server\t%d\t%d\t%d\t%d\t%d\n",
2666 ent.tbe_cli_nle.nle_nactive,
2667 ent.tbe_cli_nle.nle_nbusy,
2668 ent.tbe_cli_nle.nle_ndown,
2669 ent.tbe_cli_nle.nle_nunknown,
2670 ent.tbe_cli_nle.nle_nnode,
2671 ent.tbe_srv_nle.nle_nactive,
2672 ent.tbe_srv_nle.nle_nbusy,
2673 ent.tbe_srv_nle.nle_ndown,
2674 ent.tbe_srv_nle.nle_nunknown,
2675 ent.tbe_srv_nle.nle_nnode);
2684 lst_query_batch_ioctl(char *batch, int test, int server,
2685 int timeout, struct list_head *head)
2687 lstio_batch_query_args_t args = {0};
2689 args.lstio_bat_key = session_key;
2690 args.lstio_bat_testidx = test;
2691 args.lstio_bat_client = !(server);
2692 args.lstio_bat_timeout = timeout;
2693 args.lstio_bat_nmlen = strlen(batch);
2694 args.lstio_bat_namep = batch;
2695 args.lstio_bat_resultp = head;
2697 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2701 lst_print_tsb_verbose(struct list_head *head,
2702 int active, int idle, int error)
2704 lstcon_rpc_ent_t *ent;
2706 list_for_each_entry(ent, head, rpe_link) {
2707 if (ent->rpe_priv[0] == 0 && active)
2710 if (ent->rpe_priv[0] != 0 && idle)
2713 if (ent->rpe_fwk_errno == 0 && error)
2716 fprintf(stdout, "%s [%s]: %s\n",
2717 libcfs_id2str(ent->rpe_peer),
2718 lst_node_state2str(ent->rpe_state),
2719 ent->rpe_rpc_errno != 0 ?
2720 strerror(ent->rpe_rpc_errno) :
2721 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2726 jt_lst_query_batch(int argc, char **argv)
2728 lstcon_test_batch_ent_t ent;
2729 struct list_head head;
2735 int timeout = 5; /* default 5 seconds */
2736 int delay = 5; /* default 5 seconds */
2737 int loop = 1; /* default 1 loop */
2747 static struct option query_batch_opts[] =
2749 {"timeout", required_argument, 0, 'o' },
2750 {"delay", required_argument, 0, 'd' },
2751 {"loop", required_argument, 0, 'c' },
2752 {"test", required_argument, 0, 't' },
2753 {"server", no_argument, 0, 's' },
2754 {"active", no_argument, 0, 'a' },
2755 {"idle", no_argument, 0, 'i' },
2756 {"error", no_argument, 0, 'e' },
2757 {"all", no_argument, 0, 'l' },
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, lst_test_bulk_param_t *bulk)
2934 bulk->blk_size = 4096;
2935 bulk->blk_opc = LST_BRW_READ;
2936 bulk->blk_flags = LST_BRW_CHECK_NONE;
2939 if (strcasestr(argv[i], "check=") == argv[i] ||
2940 strcasestr(argv[i], "c=") == argv[i]) {
2941 tok = strchr(argv[i], '=') + 1;
2943 if (strcasecmp(tok, "full") == 0) {
2944 bulk->blk_flags = LST_BRW_CHECK_FULL;
2945 } else if (strcasecmp(tok, "simple") == 0) {
2946 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2948 fprintf(stderr, "Unknow flag %s\n", tok);
2952 } else if (strcasestr(argv[i], "size=") == argv[i] ||
2953 strcasestr(argv[i], "s=") == argv[i]) {
2954 tok = strchr(argv[i], '=') + 1;
2956 bulk->blk_size = strtol(tok, &end, 0);
2957 if (bulk->blk_size <= 0) {
2958 fprintf(stderr, "Invalid size %s\n", tok);
2965 if (*end == 'k' || *end == 'K')
2966 bulk->blk_size *= 1024;
2967 else if (*end == 'm' || *end == 'M')
2968 bulk->blk_size *= 1024 * 1024;
2970 if (bulk->blk_size > PAGE_CACHE_SIZE * LNET_MAX_IOV) {
2971 fprintf(stderr, "Size exceed limitation: %d bytes\n",
2976 } else if (strcasecmp(argv[i], "read") == 0 ||
2977 strcasecmp(argv[i], "r") == 0) {
2978 bulk->blk_opc = LST_BRW_READ;
2980 } else if (strcasecmp(argv[i], "write") == 0 ||
2981 strcasecmp(argv[i], "w") == 0) {
2982 bulk->blk_opc = LST_BRW_WRITE;
2985 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
2996 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
2998 lst_test_bulk_param_t *bulk = NULL;
3001 type = lst_test_name2type(test);
3003 fprintf(stderr, "Unknow test name %s\n", test);
3012 bulk = malloc(sizeof(*bulk));
3014 fprintf(stderr, "Out of memory\n");
3018 memset(bulk, 0, sizeof(*bulk));
3020 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
3026 *plen = sizeof(*bulk);
3034 /* TODO: parse more parameter */
3039 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
3040 int dist, int span, char *sgrp, char *dgrp,
3041 void *param, int plen, int *retp, struct list_head *resultp)
3043 lstio_test_args_t args = {0};
3045 args.lstio_tes_key = session_key;
3046 args.lstio_tes_bat_nmlen = strlen(batch);
3047 args.lstio_tes_bat_name = batch;
3048 args.lstio_tes_type = type;
3049 args.lstio_tes_oneside = 0;
3050 args.lstio_tes_loop = loop;
3051 args.lstio_tes_concur = concur;
3052 args.lstio_tes_dist = dist;
3053 args.lstio_tes_span = span;
3054 args.lstio_tes_sgrp_nmlen = strlen(sgrp);
3055 args.lstio_tes_sgrp_name = sgrp;
3056 args.lstio_tes_dgrp_nmlen = strlen(dgrp);
3057 args.lstio_tes_dgrp_name = dgrp;
3058 args.lstio_tes_param_len = plen;
3059 args.lstio_tes_param = param;
3060 args.lstio_tes_retp = retp;
3061 args.lstio_tes_resultp = resultp;
3063 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
3067 jt_lst_add_test(int argc, char **argv)
3069 struct list_head head;
3089 static struct option add_test_opts[] =
3091 {"batch", required_argument, 0, 'b' },
3092 {"concurrency", required_argument, 0, 'c' },
3093 {"distribute", required_argument, 0, 'd' },
3094 {"from", required_argument, 0, 'f' },
3095 {"to", required_argument, 0, 't' },
3096 {"loop", required_argument, 0, 'l' },
3100 if (session_key == 0) {
3102 "Can't find env LST_SESSION or value is not valid\n");
3107 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3108 add_test_opts, &optidx);
3110 /* Detect the end of the options. */
3119 concur = atoi(optarg);
3128 loop = atoi(optarg);
3134 lst_print_usage(argv[0]);
3139 if (optind == argc || from == NULL || to == NULL) {
3140 lst_print_usage(argv[0]);
3144 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3145 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3150 batch = LST_DEFAULT_BATCH;
3153 rc = lst_parse_distribute(dstr, &dist, &span);
3155 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3160 test = argv[optind++];
3165 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3167 fprintf(stderr, "Failed to add test (%s)\n", test);
3171 INIT_LIST_HEAD(&head);
3173 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3175 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3176 from, strerror(errno));
3180 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3182 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3183 to, strerror(errno));
3187 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3189 fprintf(stderr, "Out of memory\n");
3193 rc = lst_add_test_ioctl(batch, type, loop, concur,
3194 dist, span, from, to, param, plen, &ret, &head);
3197 fprintf(stdout, "Test was added successfully\n");
3199 fprintf(stdout, "Server group contains userland test "
3200 "nodes, old version of tcplnd can't accept "
3201 "connection request\n");
3208 lst_print_error("test", "Failed to add test: %s\n",
3213 lst_print_transerr(&head, "add test");
3215 lst_free_rpcent(&head);
3223 static command_t lst_cmdlist[] = {
3224 {"new_session", jt_lst_new_session, NULL,
3225 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3226 {"end_session", jt_lst_end_session, NULL,
3227 "Usage: lst end_session" },
3228 {"show_session", jt_lst_show_session, NULL,
3229 "Usage: lst show_session" },
3230 {"ping", jt_lst_ping , NULL,
3231 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3232 {"add_group", jt_lst_add_group, NULL,
3233 "Usage: lst group NAME IDs [IDs]..." },
3234 {"del_group", jt_lst_del_group, NULL,
3235 "Usage: lst del_group NAME" },
3236 {"update_group", jt_lst_update_group, NULL,
3237 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3238 {"list_group", jt_lst_list_group, NULL,
3239 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3240 {"stat", jt_lst_stat, NULL,
3241 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3242 " [--timeout #] [--delay #] [--count #] GROUP [GROUP]" },
3243 {"show_error", jt_lst_show_error, NULL,
3244 "Usage: lst show_error NAME | IDS ..." },
3245 {"add_batch", jt_lst_add_batch, NULL,
3246 "Usage: lst add_batch NAME" },
3247 {"run", jt_lst_start_batch, NULL,
3248 "Usage: lst run [--timeout TIME] [NAME]" },
3249 {"stop", jt_lst_stop_batch, NULL,
3250 "Usage: lst stop [--force] BATCH_NAME" },
3251 {"list_batch", jt_lst_list_batch, NULL,
3252 "Usage: lst list_batch NAME [--test ID] [--server]" },
3253 {"query", jt_lst_query_batch, NULL,
3254 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3255 {"add_test", jt_lst_add_test, NULL,
3256 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3257 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3258 {"help", Parser_help, 0, "help" },
3263 lst_initialize(void)
3268 feats = getenv("LST_FEATURES");
3270 session_features = strtol(feats, NULL, 16);
3272 if ((session_features & ~LST_FEATS_MASK) != 0) {
3274 "Unsupported session features %x, "
3275 "only support these features so far: %x\n",
3276 (session_features & ~LST_FEATS_MASK), LST_FEATS_MASK);
3280 key = getenv("LST_SESSION");
3287 session_key = atoi(key);
3293 main(int argc, char **argv)
3299 rc = libcfs_arch_init();
3303 rc = lst_initialize();
3307 rc = ptl_initialize(argc, argv);
3311 Parser_init("lst > ", lst_cmdlist);
3314 rc = Parser_execarg(argc - 1, argv + 1, lst_cmdlist);
3321 libcfs_arch_cleanup();