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, 2014, 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>
48 #include <sys/ioctl.h>
51 #include <libcfs/list.h>
52 #include <libcfs/util/ioctl.h>
53 #include <libcfs/util/parser.h>
54 #include <lnet/lnetctl.h>
55 #include <lnet/lnetst.h>
56 #include <lnet/lnet.h>
58 lst_sid_t LST_INVALID_SID = {LNET_NID_ANY, -1};
59 static lst_sid_t session_id;
60 static int session_key;
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 lstcon_trans_stat_t 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, lnet_process_id_t **idspp)
265 rc = expand_strs(str, &head);
275 *idspp = malloc(c * sizeof(lnet_process_id_t));
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 lstcon_rpc_ent_t *ent;
411 while (!list_empty(head)) {
412 ent = list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
414 list_del(&ent->rpe_link);
420 lst_reset_rpcent(struct list_head *head)
422 lstcon_rpc_ent_t *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 lstcon_rpc_ent_t *ent;
438 for (i = 0; i < count; i++) {
439 ent = malloc(offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
441 lst_free_rpcent(head);
445 memset(ent, 0, offsetof(lstcon_rpc_ent_t, 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 lstcon_rpc_ent_t *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 lstcon_test_batch_ent_t *entp, int *idxp,
480 int *ndentp, lstcon_node_ent_t *dentsp);
482 int lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
483 int *idx, int *count, lstcon_node_ent_t *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, lst_sid_t *sid)
523 lstio_session_new_args_t 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];
547 static struct option session_opts[] =
549 {"timeout", required_argument, 0, 't' },
550 {"force", no_argument, 0, 'f' },
554 if (session_key == 0) {
556 "Can't find env LST_SESSION or value is not valid\n");
562 c = getopt_long(argc, argv, "ft:",
563 session_opts, &optidx);
573 timeout = atoi(optarg);
576 lst_print_usage(argv[0]);
582 fprintf(stderr, "Invalid timeout value\n");
586 if (optind == argc - 1) {
587 name = argv[optind ++];
588 if (strlen(name) >= LST_NAME_SIZE) {
589 fprintf(stderr, "Name size is limited to %d\n",
594 } else if (optind == argc) {
595 char user[LST_NAME_SIZE];
596 char host[LST_NAME_SIZE];
597 struct passwd *pw = getpwuid(getuid());
600 snprintf(user, sizeof(user), "%d", (int)getuid());
602 snprintf(user, sizeof(user), "%s", pw->pw_name);
604 rc = gethostname(host, sizeof(host));
606 snprintf(host, sizeof(host), "unknown_host");
608 snprintf(buf, sizeof(buf), "%s@%s", user, host);
612 lst_print_usage(argv[0]);
616 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
618 lst_print_error("session", "Failed to create session: %s\n",
623 fprintf(stdout, "SESSION: %s FEATURES: %x TIMEOUT: %d FORCE: %s\n",
624 name, session_features, timeout, force ? "Yes" : "No");
629 lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp,
630 lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
632 lstio_session_info_args_t args = {0};
634 args.lstio_ses_idp = sid;
635 args.lstio_ses_keyp = key;
636 args.lstio_ses_featp = featp;
637 args.lstio_ses_ndinfo = ndinfo;
638 args.lstio_ses_nmlen = len;
639 args.lstio_ses_namep = name;
641 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
645 jt_lst_show_session(int argc, char **argv)
647 lstcon_ndlist_ent_t ndinfo;
649 char name[LST_NAME_SIZE];
654 rc = lst_session_info_ioctl(name, sizeof(name), &key,
655 &feats, &sid, &ndinfo);
658 lst_print_error("session", "Failed to show session: %s\n",
663 fprintf(stdout, "%s ID: "LPU64"@%s, KEY: %d FEATURES: %x NODES: %d\n",
664 name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
665 key, feats, ndinfo.nle_nnode);
671 lst_end_session_ioctl(void)
673 lstio_session_end_args_t args = {0};
675 args.lstio_ses_key = session_key;
676 return lst_ioctl (LSTIO_SESSION_END, &args, sizeof(args));
680 jt_lst_end_session(int argc, char **argv)
684 if (session_key == 0) {
686 "Can't find env LST_SESSION or value is not valid\n");
690 rc = lst_end_session_ioctl();
693 fprintf(stdout, "session is ended\n");
698 lst_print_error("session", "Failed to end session: %s\n",
703 if (trans_stat.trs_rpc_errno != 0) {
705 "[RPC] Failed to send %d session RPCs: %s\n",
706 lstcon_rpc_stat_failure(&trans_stat, 0),
707 strerror(trans_stat.trs_rpc_errno));
710 if (trans_stat.trs_fwk_errno != 0) {
712 "[FWK] Failed to end session on %d nodes: %s\n",
713 lstcon_sesop_stat_failure(&trans_stat, 0),
714 strerror(trans_stat.trs_fwk_errno));
721 lst_ping_ioctl(char *str, int type, int timeout,
722 int count, lnet_process_id_t *ids, struct list_head *head)
724 lstio_debug_args_t args = {0};
726 args.lstio_dbg_key = session_key;
727 args.lstio_dbg_type = type;
728 args.lstio_dbg_flags = 0;
729 args.lstio_dbg_timeout = timeout;
730 args.lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str);
731 args.lstio_dbg_namep = str;
732 args.lstio_dbg_count = count;
733 args.lstio_dbg_idsp = ids;
734 args.lstio_dbg_resultp = head;
736 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
740 lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
742 char buf[LST_NAME_SIZE];
743 lstcon_test_batch_ent_t ent;
744 lstcon_ndlist_ent_t *entp = &ent.tbe_cli_nle;
751 case LST_OPC_SESSION:
752 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
753 &key, &feats, &sid, entp);
756 case LST_OPC_BATCHSRV:
757 entp = &ent.tbe_srv_nle;
758 case LST_OPC_BATCHCLI:
759 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
763 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
767 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
776 *countp = entp->nle_nnode;
782 jt_lst_ping(int argc, char **argv)
784 struct list_head head;
785 lnet_process_id_t *ids = NULL;
786 lstcon_rpc_ent_t *ent = NULL;
796 static struct option ping_opts[] =
798 {"session", no_argument, 0, 's' },
799 {"server", no_argument, 0, 'v' },
800 {"batch", required_argument, 0, 'b' },
801 {"group", required_argument, 0, 'g' },
802 {"nodes", required_argument, 0, 'n' },
803 {"timeout", required_argument, 0, 't' },
807 if (session_key == 0) {
809 "Can't find env LST_SESSION or value is not valid\n");
815 c = getopt_long(argc, argv, "g:b:n:t:sv",
823 type = LST_OPC_SESSION;
827 type = LST_OPC_GROUP;
832 type = LST_OPC_BATCHCLI;
837 type = LST_OPC_NODES;
842 timeout = atoi(optarg);
850 lst_print_usage(argv[0]);
855 if (type == 0 || timeout <= 0 || optind != argc) {
856 lst_print_usage(argv[0]);
860 if (type == LST_OPC_BATCHCLI && server)
861 type = LST_OPC_BATCHSRV;
863 rc = lst_get_node_count(type, str, &count, &ids);
865 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
866 (str == NULL) ? "session" : str, strerror(errno));
870 INIT_LIST_HEAD(&head);
872 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
874 fprintf(stderr, "Out of memory\n");
879 fprintf(stdout, "Target %s is empty\n",
880 (str == NULL) ? "session" : str);
884 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
885 if (rc == -1) { /* local failure */
886 lst_print_error("debug", "Failed to ping %s: %s\n",
887 (str == NULL) ? "session" : str,
893 /* ignore RPC errors and framwork errors */
894 list_for_each_entry(ent, &head, rpe_link) {
895 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
896 libcfs_id2str(ent->rpe_peer),
897 lst_node_state2str(ent->rpe_state),
898 (ent->rpe_state == LST_NODE_ACTIVE ||
899 ent->rpe_state == LST_NODE_BUSY) ?
900 (ent->rpe_rpc_errno == 0 ?
901 &ent->rpe_payload[0] : "Unknown") :
902 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
906 lst_free_rpcent(&head);
916 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
917 unsigned *featp, struct list_head *resultp)
919 lstio_group_nodes_args_t args = {0};
921 args.lstio_grp_key = session_key;
922 args.lstio_grp_nmlen = strlen(name);
923 args.lstio_grp_namep = name;
924 args.lstio_grp_count = count;
925 args.lstio_grp_featp = featp;
926 args.lstio_grp_idsp = ids;
927 args.lstio_grp_resultp = resultp;
929 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
933 lst_del_group_ioctl(char *name)
935 lstio_group_del_args_t args = {0};
937 args.lstio_grp_key = session_key;
938 args.lstio_grp_nmlen = strlen(name);
939 args.lstio_grp_namep = name;
941 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
945 lst_del_group(char *grp_name)
949 rc = lst_del_group_ioctl(grp_name);
951 fprintf(stdout, "Group is deleted\n");
956 lst_print_error("group", "Failed to delete group: %s\n",
961 fprintf(stderr, "Group is deleted with some errors\n");
963 if (trans_stat.trs_rpc_errno != 0) {
965 "[RPC] Failed to send %d end session RPCs: %s\n",
966 lstcon_rpc_stat_failure(&trans_stat, 0),
967 strerror(trans_stat.trs_rpc_errno));
970 if (trans_stat.trs_fwk_errno != 0) {
972 "[FWK] Failed to end session on %d nodes: %s\n",
973 lstcon_sesop_stat_failure(&trans_stat, 0),
974 strerror(trans_stat.trs_fwk_errno));
981 lst_add_group_ioctl (char *name)
983 lstio_group_add_args_t args = {0};
985 args.lstio_grp_key = session_key;
986 args.lstio_grp_nmlen = strlen(name);
987 args.lstio_grp_namep = name;
989 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
993 jt_lst_add_group(int argc, char **argv)
995 struct list_head head;
996 lnet_process_id_t *ids;
998 unsigned feats = session_features;
1002 bool nodes_added = false;
1004 if (session_key == 0) {
1006 "Can't find env LST_SESSION or value is not valid\n");
1011 lst_print_usage(argv[0]);
1016 if (strlen(name) >= LST_NAME_SIZE) {
1017 fprintf(stderr, "Name length is limited to %d\n",
1022 rc = lst_add_group_ioctl(name);
1024 lst_print_error("group", "Failed to add group %s: %s\n",
1025 name, strerror(errno));
1029 INIT_LIST_HEAD(&head);
1031 for (i = 2; i < argc; i++) {
1032 /* parse address list */
1033 rc = lst_parse_nids(argv[i], &count, &ids);
1035 fprintf(stderr, "Ignore invalid id list %s\n",
1043 rc = lst_alloc_rpcent(&head, count, 0);
1045 fprintf(stderr, "Out of memory\n");
1051 rc = lst_add_nodes_ioctl(name, count, ids, &feats, &head);
1058 fprintf(stdout, "%s are added to session\n", argv[i]);
1062 if ((feats & session_features) != session_features) {
1064 "Warning, this session will run with "
1065 "compatible mode because some test nodes "
1066 "might not understand these features: %x\n",
1067 (~feats & session_features));
1070 lst_free_rpcent(&head);
1075 * The selftest kernel module expects that a group should
1076 * have at least one node, since it doesn't make sense for
1077 * an empty group to be added to a test.
1080 "No nodes added successfully, deleting group %s\n",
1082 rc = lst_del_group(name);
1085 "Failed to delete group %s."
1086 " Group is empty.\n", name);
1094 lst_print_error("group", "Failed to add nodes %s: %s\n",
1095 argv[i], strerror(errno));
1098 if (trans_stat.trs_fwk_errno == EPROTO) {
1100 "test nodes might have different LST "
1101 "features, please disable some features by "
1102 "setting LST_FEATURES\n");
1105 lst_print_transerr(&head, "create session");
1108 lst_free_rpcent(&head);
1112 "No nodes added successfully, deleting group %s\n",
1114 if (lst_del_group(name) != 0) {
1116 "Failed to delete group %s."
1117 " Group is empty.\n", name);
1125 jt_lst_del_group(int argc, char **argv)
1129 if (session_key == 0) {
1131 "Can't find env LST_SESSION or value is not valid\n");
1136 lst_print_usage(argv[0]);
1140 rc = lst_del_group(argv[1]);
1146 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1147 lnet_process_id_t *ids, struct list_head *resultp)
1149 lstio_group_update_args_t args = {0};
1151 args.lstio_grp_key = session_key;
1152 args.lstio_grp_opc = opc;
1153 args.lstio_grp_args = clean;
1154 args.lstio_grp_nmlen = strlen(name);
1155 args.lstio_grp_namep = name;
1156 args.lstio_grp_count = count;
1157 args.lstio_grp_idsp = ids;
1158 args.lstio_grp_resultp = resultp;
1160 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1164 jt_lst_update_group(int argc, char **argv)
1166 struct list_head head;
1167 lnet_process_id_t *ids = NULL;
1177 static struct option update_group_opts[] =
1179 {"refresh", no_argument, 0, 'f' },
1180 {"clean", required_argument, 0, 'c' },
1181 {"remove", required_argument, 0, 'r' },
1185 if (session_key == 0) {
1187 "Can't find env LST_SESSION or value is not valid\n");
1192 c = getopt_long(argc, argv, "fc:r:",
1193 update_group_opts, &optidx);
1195 /* Detect the end of the options. */
1202 lst_print_usage(argv[0]);
1205 opc = LST_GROUP_REFRESH;
1210 lst_print_usage(argv[0]);
1213 opc = LST_GROUP_RMND;
1218 clean = lst_node_str2state(optarg);
1219 if (opc != 0 || clean <= 0) {
1220 lst_print_usage(argv[0]);
1223 opc = LST_GROUP_CLEAN;
1227 lst_print_usage(argv[0]);
1232 /* no OPC or group is specified */
1233 if (opc == 0 || optind != argc - 1) {
1234 lst_print_usage(argv[0]);
1240 INIT_LIST_HEAD(&head);
1242 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1243 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1245 opc == LST_GROUP_RMND ? str : grp,
1249 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1250 opc == LST_GROUP_RMND ? str : grp,
1255 rc = lst_alloc_rpcent(&head, count, 0);
1257 fprintf(stderr, "Out of memory\n");
1264 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1270 lst_free_rpcent(&head);
1275 lst_free_rpcent(&head);
1276 lst_print_error("group", "Failed to update group: %s\n",
1281 lst_print_transerr(&head, "Updating group");
1283 lst_free_rpcent(&head);
1289 lst_list_group_ioctl(int len, char *name, int idx)
1291 lstio_group_list_args_t args = {0};
1293 args.lstio_grp_key = session_key;
1294 args.lstio_grp_idx = idx;
1295 args.lstio_grp_nmlen = len;
1296 args.lstio_grp_namep = name;
1298 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1302 lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
1303 int *idx, int *count, lstcon_node_ent_t *dents)
1305 lstio_group_info_args_t args = {0};
1307 args.lstio_grp_key = session_key;
1308 args.lstio_grp_nmlen = strlen(name);
1309 args.lstio_grp_namep = name;
1310 args.lstio_grp_entp = gent;
1311 args.lstio_grp_idxp = idx;
1312 args.lstio_grp_ndentp = count;
1313 args.lstio_grp_dentsp = dents;
1315 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1319 lst_list_group_all(void)
1321 char name[LST_NAME_SIZE];
1325 /* no group is specified, list name of all groups */
1326 for (i = 0; ; i++) {
1327 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1329 fprintf(stdout, "%d) %s\n", i + 1, name);
1333 if (errno == ENOENT)
1336 lst_print_error("group", "Failed to list group: %s\n",
1341 fprintf(stdout, "Total %d groups\n", i);
1346 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1349 jt_lst_list_group(int argc, char **argv)
1351 lstcon_ndlist_ent_t gent;
1352 lstcon_node_ent_t *dents;
1367 static struct option list_group_opts[] =
1369 {"active", no_argument, 0, 'a' },
1370 {"busy", no_argument, 0, 'b' },
1371 {"down", no_argument, 0, 'd' },
1372 {"unknown", no_argument, 0, 'u' },
1373 {"all", no_argument, 0, 'l' },
1377 if (session_key == 0) {
1379 "Can't find env LST_SESSION or value is not valid\n");
1384 c = getopt_long(argc, argv, "abdul",
1385 list_group_opts, &optidx);
1392 verbose = active = 1;
1404 verbose = unknown = 1;
1411 lst_print_usage(argv[0]);
1416 if (optind == argc) {
1417 /* no group is specified, list name of all groups */
1418 rc = lst_list_group_all();
1424 fprintf(stdout, LST_NODES_TITLE);
1426 /* list nodes in specified groups */
1427 for (i = optind; i < argc; i++) {
1428 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1430 if (errno == ENOENT) {
1435 lst_print_error("group", "Failed to list group\n",
1441 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1442 gent.nle_nactive, gent.nle_nbusy,
1443 gent.nle_ndown, gent.nle_nunknown,
1444 gent.nle_nnode, argv[i]);
1448 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1450 if (gent.nle_nnode == 0) {
1451 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1455 count = gent.nle_nnode;
1457 dents = malloc(count * sizeof(lstcon_node_ent_t));
1458 if (dents == NULL) {
1459 fprintf(stderr, "Failed to malloc: %s\n",
1465 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1467 lst_print_error("group", "Failed to list group: %s\n",
1473 for (j = 0, c = 0; j < count; j++) {
1475 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1476 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1477 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1478 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1480 fprintf(stdout, "\t%s: %s\n",
1481 libcfs_id2str(dents[j].nde_id),
1482 lst_node_state2str(dents[j].nde_state));
1487 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1496 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
1497 int timeout, struct list_head *resultp)
1499 lstio_stat_args_t args = {0};
1501 args.lstio_sta_key = session_key;
1502 args.lstio_sta_timeout = timeout;
1503 args.lstio_sta_nmlen = strlen(name);
1504 args.lstio_sta_namep = name;
1505 args.lstio_sta_count = count;
1506 args.lstio_sta_idsp = idsp;
1507 args.lstio_sta_resultp = resultp;
1509 return lst_ioctl (LSTIO_STAT_QUERY, &args, sizeof(args));
1513 struct list_head srp_link;
1516 lnet_process_id_t *srp_ids;
1517 struct list_head srp_result[2];
1518 } lst_stat_req_param_t;
1521 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1525 for (i = 0; i < 2; i++)
1526 lst_free_rpcent(&srp->srp_result[i]);
1528 if (srp->srp_ids != NULL)
1535 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
1537 lst_stat_req_param_t *srp = NULL;
1538 int count = save_old ? 2 : 1;
1542 srp = malloc(sizeof(*srp));
1546 memset(srp, 0, sizeof(*srp));
1547 INIT_LIST_HEAD(&srp->srp_result[0]);
1548 INIT_LIST_HEAD(&srp->srp_result[1]);
1550 rc = lst_get_node_count(LST_OPC_GROUP, name,
1551 &srp->srp_count, NULL);
1552 if (rc != 0 && errno == ENOENT) {
1553 rc = lst_get_node_count(LST_OPC_NODES, name,
1554 &srp->srp_count, &srp->srp_ids);
1559 "Failed to get count of nodes from %s: %s\n",
1560 name, strerror(errno));
1561 lst_stat_req_param_free(srp);
1566 srp->srp_name = name;
1568 for (i = 0; i < count; i++) {
1569 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1570 sizeof(sfw_counters_t) +
1571 sizeof(srpc_counters_t) +
1572 sizeof(lnet_counters_t));
1574 fprintf(stderr, "Out of memory\n");
1584 lst_stat_req_param_free(srp);
1592 } lst_srpc_stat_result;
1594 #define LST_LNET_AVG 0
1595 #define LST_LNET_MIN 1
1596 #define LST_LNET_MAX 2
1599 float lnet_avg_sndrate;
1600 float lnet_min_sndrate;
1601 float lnet_max_sndrate;
1602 float lnet_total_sndrate;
1604 float lnet_avg_rcvrate;
1605 float lnet_min_rcvrate;
1606 float lnet_max_rcvrate;
1607 float lnet_total_rcvrate;
1609 float lnet_avg_sndperf;
1610 float lnet_min_sndperf;
1611 float lnet_max_sndperf;
1612 float lnet_total_sndperf;
1614 float lnet_avg_rcvperf;
1615 float lnet_min_rcvperf;
1616 float lnet_max_rcvperf;
1617 float lnet_total_rcvperf;
1619 int lnet_stat_count;
1620 } lst_lnet_stat_result_t;
1622 lst_lnet_stat_result_t lnet_stat_result;
1625 lst_lnet_stat_value(int bw, int send, int off)
1629 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1630 &lnet_stat_result.lnet_avg_sndrate;
1641 lst_timeval_diff(struct timeval *tv1,
1642 struct timeval *tv2, struct timeval *df)
1644 if (tv1->tv_usec >= tv2->tv_usec) {
1645 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1646 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1650 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1651 df->tv_usec = tv1->tv_usec + 1000000 - tv2->tv_usec;
1657 lst_cal_lnet_stat(float delta, lnet_counters_t *lnet_new,
1658 lnet_counters_t *lnet_old)
1663 perf = (float)(lnet_new->send_length -
1664 lnet_old->send_length) / (1024 * 1024) / delta;
1665 lnet_stat_result.lnet_total_sndperf += perf;
1667 if (lnet_stat_result.lnet_min_sndperf > perf ||
1668 lnet_stat_result.lnet_min_sndperf == 0)
1669 lnet_stat_result.lnet_min_sndperf = perf;
1671 if (lnet_stat_result.lnet_max_sndperf < perf)
1672 lnet_stat_result.lnet_max_sndperf = perf;
1674 perf = (float)(lnet_new->recv_length -
1675 lnet_old->recv_length) / (1024 * 1024) / delta;
1676 lnet_stat_result.lnet_total_rcvperf += perf;
1678 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1679 lnet_stat_result.lnet_min_rcvperf == 0)
1680 lnet_stat_result.lnet_min_rcvperf = perf;
1682 if (lnet_stat_result.lnet_max_rcvperf < perf)
1683 lnet_stat_result.lnet_max_rcvperf = perf;
1685 rate = (lnet_new->send_count - lnet_old->send_count) / delta;
1686 lnet_stat_result.lnet_total_sndrate += rate;
1688 if (lnet_stat_result.lnet_min_sndrate > rate ||
1689 lnet_stat_result.lnet_min_sndrate == 0)
1690 lnet_stat_result.lnet_min_sndrate = rate;
1692 if (lnet_stat_result.lnet_max_sndrate < rate)
1693 lnet_stat_result.lnet_max_sndrate = rate;
1695 rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
1696 lnet_stat_result.lnet_total_rcvrate += rate;
1698 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1699 lnet_stat_result.lnet_min_rcvrate == 0)
1700 lnet_stat_result.lnet_min_rcvrate = rate;
1702 if (lnet_stat_result.lnet_max_rcvrate < rate)
1703 lnet_stat_result.lnet_max_rcvrate = rate;
1705 lnet_stat_result.lnet_stat_count ++;
1707 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1708 lnet_stat_result.lnet_stat_count;
1709 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1710 lnet_stat_result.lnet_stat_count;
1712 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1713 lnet_stat_result.lnet_stat_count;
1714 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1715 lnet_stat_result.lnet_stat_count;
1720 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
1729 if (lnet_stat_result.lnet_stat_count == 0)
1732 if (bwrt == 1) /* bw only */
1735 if (bwrt == 2) /* rates only */
1738 if (rdwr == 1) /* recv only */
1741 if (rdwr == 2) /* send only */
1744 for (i = start1; i <= end1; i++) {
1745 fprintf(stdout, "[LNet %s of %s]\n",
1746 i == 0 ? "Rates" : "Bandwidth", name);
1748 for (j = start2; j <= end2; j++) {
1749 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
1751 if ((type & 1) != 0) {
1752 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1753 "Avg: %-8.2f MB/s ",
1754 lst_lnet_stat_value(i, j, 0));
1757 if ((type & 2) != 0) {
1758 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1759 "Min: %-8.2f MB/s ",
1760 lst_lnet_stat_value(i, j, 1));
1763 if ((type & 4) != 0) {
1764 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1766 lst_lnet_stat_value(i, j, 2));
1769 fprintf(stdout, "\n");
1775 lst_print_stat(char *name, struct list_head *resultp,
1776 int idx, int lnet, int bwrt, int rdwr, int type)
1778 struct list_head tmp[2];
1779 lstcon_rpc_ent_t *new;
1780 lstcon_rpc_ent_t *old;
1781 sfw_counters_t *sfwk_new;
1782 sfw_counters_t *sfwk_old;
1783 srpc_counters_t *srpc_new;
1784 srpc_counters_t *srpc_old;
1785 lnet_counters_t *lnet_new;
1786 lnet_counters_t *lnet_old;
1790 INIT_LIST_HEAD(&tmp[0]);
1791 INIT_LIST_HEAD(&tmp[1]);
1793 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1795 while (!list_empty(&resultp[idx])) {
1796 if (list_empty(&resultp[1 - idx])) {
1797 fprintf(stderr, "Group is changed, re-run stat\n");
1801 new = list_entry(resultp[idx].next, lstcon_rpc_ent_t,
1803 old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t,
1806 /* first time get stats result, can't calculate diff */
1807 if (new->rpe_peer.nid == LNET_NID_ANY)
1810 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1811 new->rpe_peer.pid != old->rpe_peer.pid) {
1812 /* Something wrong. i.e, somebody change the group */
1816 list_del(&new->rpe_link);
1817 list_add_tail(&new->rpe_link, &tmp[idx]);
1819 list_del(&old->rpe_link);
1820 list_add_tail(&old->rpe_link, &tmp[1 - idx]);
1822 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1823 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1828 sfwk_new = (sfw_counters_t *)&new->rpe_payload[0];
1829 sfwk_old = (sfw_counters_t *)&old->rpe_payload[0];
1831 srpc_new = (srpc_counters_t *)((char *)sfwk_new + sizeof(*sfwk_new));
1832 srpc_old = (srpc_counters_t *)((char *)sfwk_old + sizeof(*sfwk_old));
1834 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
1835 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
1837 /* Prior to version 2.3, the running_ms field was a counter for
1838 * the number of running tests. We are looking at this value
1839 * to determine if it is a millisecond timestamep (>= 2.3) or a
1840 * test counter (< 2.3). The number 500 is being used for this
1841 * barrier as the test counter should never get this high, and
1842 * the timestamp should never get this low. */
1844 if (sfwk_new->running_ms > 500) {
1845 /* use the timestamp from the remote node, not our
1846 * rpe_stamp from when we copied up the data out of
1849 delta = (float) (sfwk_new->running_ms -
1850 sfwk_old->running_ms) / 1000;
1854 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1855 delta = tv.tv_sec + (float)tv.tv_usec / 1000000;
1858 if (!lnet) /* TODO */
1861 lst_cal_lnet_stat(delta, lnet_new, lnet_old);
1864 list_splice(&tmp[idx], &resultp[idx]);
1865 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1868 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1870 if (!lnet) /* TODO */
1873 lst_print_lnet_stat(name, bwrt, rdwr, type);
1877 jt_lst_stat(int argc, char **argv)
1879 struct list_head head;
1880 lst_stat_req_param_t *srp;
1883 int timeout = 5; /* default timeout, 5 sec */
1884 int delay = 5; /* default delay, 5 sec */
1885 int count = -1; /* run forever */
1886 int lnet = 1; /* lnet stat by default */
1894 static struct option stat_opts[] =
1896 {"timeout" , required_argument, 0, 't' },
1897 {"delay" , required_argument, 0, 'd' },
1898 {"count" , required_argument, 0, 'o' },
1899 {"lnet" , no_argument, 0, 'l' },
1900 {"rpc" , no_argument, 0, 'c' },
1901 {"bw" , no_argument, 0, 'b' },
1902 {"rate" , no_argument, 0, 'a' },
1903 {"read" , no_argument, 0, 'r' },
1904 {"write" , no_argument, 0, 'w' },
1905 {"avg" , no_argument, 0, 'g' },
1906 {"min" , no_argument, 0, 'n' },
1907 {"max" , no_argument, 0, 'x' },
1911 if (session_key == 0) {
1913 "Can't find env LST_SESSION or value is not valid\n");
1918 c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
1925 timeout = atoi(optarg);
1928 delay = atoi(optarg);
1931 count = atoi(optarg);
1974 lst_print_usage(argv[0]);
1979 if (optind == argc) {
1980 lst_print_usage(argv[0]);
1984 if (timeout <= 0 || delay <= 0) {
1985 fprintf(stderr, "Invalid timeout or delay value\n");
1990 fprintf(stderr, "Invalid count value\n");
1994 /* extra count to get first data point */
1998 INIT_LIST_HEAD(&head);
2000 while (optind < argc) {
2001 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
2005 list_add_tail(&srp->srp_link, &head);
2009 time_t now = time(NULL);
2011 if (now - last < delay) {
2012 sleep(delay - now + last);
2017 list_for_each_entry(srp, &head, srp_link) {
2018 rc = lst_stat_ioctl(srp->srp_name,
2019 srp->srp_count, srp->srp_ids,
2020 timeout, &srp->srp_result[idx]);
2022 lst_print_error("stat", "Failed to stat %s: %s\n",
2023 srp->srp_name, strerror(errno));
2027 lst_print_stat(srp->srp_name, srp->srp_result,
2028 idx, lnet, bwrt, rdwr, type);
2030 lst_reset_rpcent(&srp->srp_result[1 - idx]);
2037 } while (count == -1 || count > 0);
2040 while (!list_empty(&head)) {
2041 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2043 list_del(&srp->srp_link);
2044 lst_stat_req_param_free(srp);
2051 jt_lst_show_error(int argc, char **argv)
2053 struct list_head head;
2054 lst_stat_req_param_t *srp;
2055 lstcon_rpc_ent_t *ent;
2056 sfw_counters_t *sfwk;
2057 srpc_counters_t *srpc;
2064 static struct option show_error_opts[] =
2066 {"session", no_argument, 0, 's' },
2070 if (session_key == 0) {
2072 "Can't find env LST_SESSION or value is not valid\n");
2077 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
2088 lst_print_usage(argv[0]);
2093 if (optind == argc) {
2094 lst_print_usage(argv[0]);
2098 INIT_LIST_HEAD(&head);
2100 while (optind < argc) {
2101 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
2105 list_add_tail(&srp->srp_link, &head);
2108 list_for_each_entry(srp, &head, srp_link) {
2109 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
2110 srp->srp_ids, 10, &srp->srp_result[0]);
2113 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2114 srp->srp_name, strerror(errno));
2118 fprintf(stdout, "%s:\n", srp->srp_name);
2122 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2123 if (ent->rpe_rpc_errno != 0) {
2125 fprintf(stderr, "RPC failure, can't show error on %s\n",
2126 libcfs_id2str(ent->rpe_peer));
2130 if (ent->rpe_fwk_errno != 0) {
2132 fprintf(stderr, "Framework failure, can't show error on %s\n",
2133 libcfs_id2str(ent->rpe_peer));
2137 sfwk = (sfw_counters_t *)&ent->rpe_payload[0];
2138 srpc = (srpc_counters_t *)((char *)sfwk + sizeof(*sfwk));
2140 if (srpc->errors == 0 &&
2141 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2145 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2150 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2151 libcfs_id2str(ent->rpe_peer),
2152 sfwk->brw_errors, sfwk->ping_errors,
2153 show_rpc ? ' ' : '\n');
2158 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2159 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2162 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2165 while (!list_empty(&head)) {
2166 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2168 list_del(&srp->srp_link);
2169 lst_stat_req_param_free(srp);
2176 lst_add_batch_ioctl (char *name)
2178 lstio_batch_add_args_t args = {0};
2180 args.lstio_bat_key = session_key;
2181 args.lstio_bat_nmlen = strlen(name);
2182 args.lstio_bat_namep = name;
2184 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2188 jt_lst_add_batch(int argc, char **argv)
2193 if (session_key == 0) {
2195 "Can't find env LST_SESSION or value is not valid\n");
2200 lst_print_usage(argv[0]);
2205 if (strlen(name) >= LST_NAME_SIZE) {
2206 fprintf(stderr, "Name length is limited to %d\n",
2211 rc = lst_add_batch_ioctl(name);
2215 lst_print_error("batch", "Failed to create batch: %s\n",
2222 lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp)
2224 lstio_batch_run_args_t args = {0};
2226 args.lstio_bat_key = session_key;
2227 args.lstio_bat_timeout = timeout;
2228 args.lstio_bat_nmlen = strlen(name);
2229 args.lstio_bat_namep = name;
2230 args.lstio_bat_resultp = resultp;
2232 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2236 jt_lst_start_batch(int argc, char **argv)
2238 struct list_head head;
2246 static struct option start_batch_opts[] =
2248 {"timeout", required_argument, 0, 't' },
2252 if (session_key == 0) {
2254 "Can't find env LST_SESSION or value is not valid\n");
2259 c = getopt_long(argc, argv, "t:",
2260 start_batch_opts, &optidx);
2262 /* Detect the end of the options. */
2268 timeout = atoi(optarg);
2271 lst_print_usage(argv[0]);
2276 if (optind == argc) {
2277 batch = LST_DEFAULT_BATCH;
2279 } else if (optind == argc - 1) {
2280 batch = argv[optind];
2283 lst_print_usage(argv[0]);
2287 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2289 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2290 batch, strerror(errno));
2294 INIT_LIST_HEAD(&head);
2296 rc = lst_alloc_rpcent(&head, count, 0);
2298 fprintf(stderr, "Out of memory\n");
2302 rc = lst_start_batch_ioctl(batch, timeout, &head);
2305 fprintf(stdout, "%s is running now\n", batch);
2306 lst_free_rpcent(&head);
2311 lst_print_error("batch", "Failed to start batch: %s\n",
2313 lst_free_rpcent(&head);
2317 lst_print_transerr(&head, "Run batch");
2319 lst_free_rpcent(&head);
2325 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2327 lstio_batch_stop_args_t args = {0};
2329 args.lstio_bat_key = session_key;
2330 args.lstio_bat_force = force;
2331 args.lstio_bat_nmlen = strlen(name);
2332 args.lstio_bat_namep = name;
2333 args.lstio_bat_resultp = resultp;
2335 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2339 jt_lst_stop_batch(int argc, char **argv)
2341 struct list_head head;
2349 static struct option stop_batch_opts[] =
2351 {"force", no_argument, 0, 'f' },
2355 if (session_key == 0) {
2357 "Can't find env LST_SESSION or value is not valid\n");
2362 c = getopt_long(argc, argv, "f",
2363 stop_batch_opts, &optidx);
2365 /* Detect the end of the options. */
2374 lst_print_usage(argv[0]);
2379 if (optind == argc) {
2380 batch = LST_DEFAULT_BATCH;
2382 } else if (optind == argc - 1) {
2383 batch = argv[optind];
2386 lst_print_usage(argv[0]);
2390 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2392 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2393 batch, strerror(errno));
2397 INIT_LIST_HEAD(&head);
2399 rc = lst_alloc_rpcent(&head, count, 0);
2401 fprintf(stderr, "Out of memory\n");
2405 rc = lst_stop_batch_ioctl(batch, force, &head);
2410 lst_reset_rpcent(&head);
2412 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2416 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2417 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2420 fprintf(stdout, "%d batch in stopping\n",
2421 lstcon_tsbqry_stat_run(&trans_stat, 0));
2425 fprintf(stdout, "Batch is stopped\n");
2426 lst_free_rpcent(&head);
2431 lst_print_error("batch", "Failed to stop batch: %s\n",
2433 lst_free_rpcent(&head);
2437 lst_print_transerr(&head, "stop batch");
2439 lst_free_rpcent(&head);
2445 lst_list_batch_ioctl(int len, char *name, int index)
2447 lstio_batch_list_args_t args = {0};
2449 args.lstio_bat_key = session_key;
2450 args.lstio_bat_idx = index;
2451 args.lstio_bat_nmlen = len;
2452 args.lstio_bat_namep = name;
2454 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2458 lst_info_batch_ioctl(char *batch, int test, int server,
2459 lstcon_test_batch_ent_t *entp, int *idxp,
2460 int *ndentp, lstcon_node_ent_t *dentsp)
2462 lstio_batch_info_args_t args = {0};
2464 args.lstio_bat_key = session_key;
2465 args.lstio_bat_nmlen = strlen(batch);
2466 args.lstio_bat_namep = batch;
2467 args.lstio_bat_server = server;
2468 args.lstio_bat_testidx = test;
2469 args.lstio_bat_entp = entp;
2470 args.lstio_bat_idxp = idxp;
2471 args.lstio_bat_ndentp = ndentp;
2472 args.lstio_bat_dentsp = dentsp;
2474 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2478 lst_list_batch_all(void)
2480 char name[LST_NAME_SIZE];
2484 for (i = 0; ; i++) {
2485 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2487 fprintf(stdout, "%d) %s\n", i + 1, name);
2491 if (errno == ENOENT)
2494 lst_print_error("batch", "Failed to list batch: %s\n",
2499 fprintf(stdout, "Total %d batches\n", i);
2505 lst_list_tsb_nodes(char *batch, int test, int server,
2506 int count, int active, int invalid)
2508 lstcon_node_ent_t *dents;
2517 /* verbose list, show nodes in batch or test */
2518 dents = malloc(count * sizeof(lstcon_node_ent_t));
2519 if (dents == NULL) {
2520 fprintf(stdout, "Can't allocate memory\n");
2524 rc = lst_info_batch_ioctl(batch, test, server,
2525 NULL, &index, &count, dents);
2528 lst_print_error((test > 0) ? "test" : "batch",
2529 (test > 0) ? "Failed to query test: %s\n" :
2530 "Failed to query batch: %s\n",
2535 for (i = 0, c = 0; i < count; i++) {
2536 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2537 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2538 dents[i].nde_state == LST_NODE_DOWN ||
2539 dents[i].nde_state == LST_NODE_UNKNOWN)))
2542 fprintf(stdout, "\t%s: %s\n",
2543 libcfs_id2str(dents[i].nde_id),
2544 lst_node_state2str(dents[i].nde_state));
2548 fprintf(stdout, "Total %d nodes\n", c);
2555 jt_lst_list_batch(int argc, char **argv)
2557 lstcon_test_batch_ent_t ent;
2560 int verbose = 0; /* list nodes in batch or test */
2569 static struct option list_batch_opts[] =
2571 {"test", required_argument, 0, 't' },
2572 {"invalid", no_argument, 0, 'i' },
2573 {"active", no_argument, 0, 'a' },
2574 {"all", no_argument, 0, 'l' },
2575 {"server", no_argument, 0, 's' },
2579 if (session_key == 0) {
2581 "Can't find env LST_SESSION or value is not valid\n");
2586 c = getopt_long(argc, argv, "ailst:",
2587 list_batch_opts, &optidx);
2594 verbose = active = 1;
2597 verbose = invalid = 1;
2600 verbose = active = invalid = 1;
2606 test = atoi(optarg);
2610 lst_print_usage(argv[0]);
2615 if (optind == argc) {
2616 /* list all batches */
2617 rc = lst_list_batch_all();
2621 if (ntest == 1 && test <= 0) {
2622 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2626 if (optind != argc - 1) {
2627 lst_print_usage(argv[0]);
2631 batch = argv[optind];
2634 /* show detail of specified batch or test */
2635 rc = lst_info_batch_ioctl(batch, test, server,
2636 &ent, NULL, NULL, NULL);
2638 lst_print_error((test > 0) ? "test" : "batch",
2639 (test > 0) ? "Failed to query test: %s\n" :
2640 "Failed to query batch: %s\n",
2646 /* list nodes in test or batch */
2647 rc = lst_list_tsb_nodes(batch, test, server,
2648 server ? ent.tbe_srv_nle.nle_nnode :
2649 ent.tbe_cli_nle.nle_nnode,
2654 /* only show number of hosts in batch or test */
2656 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2657 batch, ent.u.tbe_batch.bae_ntest,
2658 ent.u.tbe_batch.bae_state);
2659 ntest = ent.u.tbe_batch.bae_ntest;
2660 test = 1; /* starting from test 1 */
2664 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2665 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2666 ent.u.tbe_test.tse_loop,
2667 ent.u.tbe_test.tse_concur);
2672 fprintf(stdout, LST_NODES_TITLE);
2673 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2674 "server\t%d\t%d\t%d\t%d\t%d\n",
2675 ent.tbe_cli_nle.nle_nactive,
2676 ent.tbe_cli_nle.nle_nbusy,
2677 ent.tbe_cli_nle.nle_ndown,
2678 ent.tbe_cli_nle.nle_nunknown,
2679 ent.tbe_cli_nle.nle_nnode,
2680 ent.tbe_srv_nle.nle_nactive,
2681 ent.tbe_srv_nle.nle_nbusy,
2682 ent.tbe_srv_nle.nle_ndown,
2683 ent.tbe_srv_nle.nle_nunknown,
2684 ent.tbe_srv_nle.nle_nnode);
2693 lst_query_batch_ioctl(char *batch, int test, int server,
2694 int timeout, struct list_head *head)
2696 lstio_batch_query_args_t args = {0};
2698 args.lstio_bat_key = session_key;
2699 args.lstio_bat_testidx = test;
2700 args.lstio_bat_client = !(server);
2701 args.lstio_bat_timeout = timeout;
2702 args.lstio_bat_nmlen = strlen(batch);
2703 args.lstio_bat_namep = batch;
2704 args.lstio_bat_resultp = head;
2706 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2710 lst_print_tsb_verbose(struct list_head *head,
2711 int active, int idle, int error)
2713 lstcon_rpc_ent_t *ent;
2715 list_for_each_entry(ent, head, rpe_link) {
2716 if (ent->rpe_priv[0] == 0 && active)
2719 if (ent->rpe_priv[0] != 0 && idle)
2722 if (ent->rpe_fwk_errno == 0 && error)
2725 fprintf(stdout, "%s [%s]: %s\n",
2726 libcfs_id2str(ent->rpe_peer),
2727 lst_node_state2str(ent->rpe_state),
2728 ent->rpe_rpc_errno != 0 ?
2729 strerror(ent->rpe_rpc_errno) :
2730 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2735 jt_lst_query_batch(int argc, char **argv)
2737 lstcon_test_batch_ent_t ent;
2738 struct list_head head;
2744 int timeout = 5; /* default 5 seconds */
2745 int delay = 5; /* default 5 seconds */
2746 int loop = 1; /* default 1 loop */
2756 static struct option query_batch_opts[] =
2758 {"timeout", required_argument, 0, 'o' },
2759 {"delay", required_argument, 0, 'd' },
2760 {"loop", required_argument, 0, 'c' },
2761 {"test", required_argument, 0, 't' },
2762 {"server", no_argument, 0, 's' },
2763 {"active", no_argument, 0, 'a' },
2764 {"idle", no_argument, 0, 'i' },
2765 {"error", no_argument, 0, 'e' },
2766 {"all", no_argument, 0, 'l' },
2770 if (session_key == 0) {
2772 "Can't find env LST_SESSION or value is not valid\n");
2777 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2778 query_batch_opts, &optidx);
2780 /* Detect the end of the options. */
2786 timeout = atoi(optarg);
2789 delay = atoi(optarg);
2792 loop = atoi(optarg);
2795 test = atoi(optarg);
2801 active = verbose = 1;
2807 error = verbose = 1;
2813 lst_print_usage(argv[0]);
2818 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2819 lst_print_usage(argv[0]);
2823 if (optind == argc) {
2824 batch = LST_DEFAULT_BATCH;
2826 } else if (optind == argc - 1) {
2827 batch = argv[optind];
2830 lst_print_usage(argv[0]);
2835 INIT_LIST_HEAD(&head);
2838 rc = lst_info_batch_ioctl(batch, test, server,
2839 &ent, NULL, NULL, NULL);
2841 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2842 batch, test, strerror(errno));
2846 count = server ? ent.tbe_srv_nle.nle_nnode :
2847 ent.tbe_cli_nle.nle_nnode;
2849 fprintf(stdout, "Batch or test is empty\n");
2854 rc = lst_alloc_rpcent(&head, count, 0);
2856 fprintf(stderr, "Out of memory\n");
2860 for (i = 0; i < loop; i++) {
2861 time_t now = time(NULL);
2863 if (now - last < delay) {
2864 sleep(delay - now + last);
2870 rc = lst_query_batch_ioctl(batch, test,
2871 server, timeout, &head);
2873 fprintf(stderr, "Failed to query batch: %s\n",
2880 lst_print_tsb_verbose(&head, active, idle, error);
2884 fprintf(stdout, "%s [%d] ", batch, test);
2886 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2887 fprintf(stdout, "%d of %d nodes are unknown, ",
2888 lstcon_rpc_stat_failure(&trans_stat, 0),
2889 lstcon_rpc_stat_total(&trans_stat, 0));
2892 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2893 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2894 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2895 fprintf(stdout, "is stopped\n");
2899 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2900 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2901 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2902 fprintf(stdout, "is running\n");
2906 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2907 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2908 lstcon_tsbqry_stat_run(&trans_stat, 0),
2909 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2912 lst_free_rpcent(&head);
2918 lst_parse_distribute(char *dstr, int *dist, int *span)
2924 dstr = strchr(dstr, ':');
2928 *span = atoi(dstr + 1);
2936 lst_get_bulk_param(int argc, char **argv, lst_test_bulk_param_t *bulk)
2943 bulk->blk_size = 4096;
2944 bulk->blk_opc = LST_BRW_READ;
2945 bulk->blk_flags = LST_BRW_CHECK_NONE;
2948 if (strcasestr(argv[i], "check=") == argv[i] ||
2949 strcasestr(argv[i], "c=") == argv[i]) {
2950 tok = strchr(argv[i], '=') + 1;
2952 if (strcasecmp(tok, "full") == 0) {
2953 bulk->blk_flags = LST_BRW_CHECK_FULL;
2954 } else if (strcasecmp(tok, "simple") == 0) {
2955 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2957 fprintf(stderr, "Unknow flag %s\n", tok);
2961 } else if (strcasestr(argv[i], "size=") == argv[i] ||
2962 strcasestr(argv[i], "s=") == argv[i]) {
2963 int max_size = sysconf(_SC_PAGESIZE) * LNET_MAX_IOV;
2965 tok = strchr(argv[i], '=') + 1;
2967 bulk->blk_size = strtol(tok, &end, 0);
2968 if (bulk->blk_size <= 0) {
2969 fprintf(stderr, "Invalid size %s\n", tok);
2976 if (*end == 'k' || *end == 'K')
2977 bulk->blk_size *= 1024;
2978 else if (*end == 'm' || *end == 'M')
2979 bulk->blk_size *= 1024 * 1024;
2981 if (bulk->blk_size > max_size) {
2982 fprintf(stderr, "Size exceed limitation: %d bytes\n",
2987 } else if (strcasecmp(argv[i], "read") == 0 ||
2988 strcasecmp(argv[i], "r") == 0) {
2989 bulk->blk_opc = LST_BRW_READ;
2991 } else if (strcasecmp(argv[i], "write") == 0 ||
2992 strcasecmp(argv[i], "w") == 0) {
2993 bulk->blk_opc = LST_BRW_WRITE;
2996 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
3007 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
3009 lst_test_bulk_param_t *bulk = NULL;
3012 type = lst_test_name2type(test);
3014 fprintf(stderr, "Unknow test name %s\n", test);
3023 bulk = malloc(sizeof(*bulk));
3025 fprintf(stderr, "Out of memory\n");
3029 memset(bulk, 0, sizeof(*bulk));
3031 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
3037 *plen = sizeof(*bulk);
3045 /* TODO: parse more parameter */
3050 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
3051 int dist, int span, char *sgrp, char *dgrp,
3052 void *param, int plen, int *retp, struct list_head *resultp)
3054 lstio_test_args_t args = {0};
3056 args.lstio_tes_key = session_key;
3057 args.lstio_tes_bat_nmlen = strlen(batch);
3058 args.lstio_tes_bat_name = batch;
3059 args.lstio_tes_type = type;
3060 args.lstio_tes_oneside = 0;
3061 args.lstio_tes_loop = loop;
3062 args.lstio_tes_concur = concur;
3063 args.lstio_tes_dist = dist;
3064 args.lstio_tes_span = span;
3065 args.lstio_tes_sgrp_nmlen = strlen(sgrp);
3066 args.lstio_tes_sgrp_name = sgrp;
3067 args.lstio_tes_dgrp_nmlen = strlen(dgrp);
3068 args.lstio_tes_dgrp_name = dgrp;
3069 args.lstio_tes_param_len = plen;
3070 args.lstio_tes_param = param;
3071 args.lstio_tes_retp = retp;
3072 args.lstio_tes_resultp = resultp;
3074 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
3078 jt_lst_add_test(int argc, char **argv)
3080 struct list_head head;
3100 static struct option add_test_opts[] =
3102 {"batch", required_argument, 0, 'b' },
3103 {"concurrency", required_argument, 0, 'c' },
3104 {"distribute", required_argument, 0, 'd' },
3105 {"from", required_argument, 0, 'f' },
3106 {"to", required_argument, 0, 't' },
3107 {"loop", required_argument, 0, 'l' },
3111 if (session_key == 0) {
3113 "Can't find env LST_SESSION or value is not valid\n");
3118 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3119 add_test_opts, &optidx);
3121 /* Detect the end of the options. */
3130 concur = atoi(optarg);
3139 loop = atoi(optarg);
3145 lst_print_usage(argv[0]);
3150 if (optind == argc || from == NULL || to == NULL) {
3151 lst_print_usage(argv[0]);
3155 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3156 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3161 batch = LST_DEFAULT_BATCH;
3164 rc = lst_parse_distribute(dstr, &dist, &span);
3166 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3171 test = argv[optind++];
3176 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3178 fprintf(stderr, "Failed to add test (%s)\n", test);
3182 INIT_LIST_HEAD(&head);
3184 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3186 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3187 from, strerror(errno));
3191 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3193 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3194 to, strerror(errno));
3198 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3200 fprintf(stderr, "Out of memory\n");
3204 rc = lst_add_test_ioctl(batch, type, loop, concur,
3205 dist, span, from, to, param, plen, &ret, &head);
3208 fprintf(stdout, "Test was added successfully\n");
3210 fprintf(stdout, "Server group contains userland test "
3211 "nodes, old version of tcplnd can't accept "
3212 "connection request\n");
3219 lst_print_error("test", "Failed to add test: %s\n",
3224 lst_print_transerr(&head, "add test");
3226 lst_free_rpcent(&head);
3234 static command_t lst_cmdlist[] = {
3235 {"new_session", jt_lst_new_session, NULL,
3236 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3237 {"end_session", jt_lst_end_session, NULL,
3238 "Usage: lst end_session" },
3239 {"show_session", jt_lst_show_session, NULL,
3240 "Usage: lst show_session" },
3241 {"ping", jt_lst_ping , NULL,
3242 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3243 {"add_group", jt_lst_add_group, NULL,
3244 "Usage: lst group NAME IDs [IDs]..." },
3245 {"del_group", jt_lst_del_group, NULL,
3246 "Usage: lst del_group NAME" },
3247 {"update_group", jt_lst_update_group, NULL,
3248 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3249 {"list_group", jt_lst_list_group, NULL,
3250 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3251 {"stat", jt_lst_stat, NULL,
3252 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3253 " [--timeout #] [--delay #] [--count #] GROUP [GROUP]" },
3254 {"show_error", jt_lst_show_error, NULL,
3255 "Usage: lst show_error NAME | IDS ..." },
3256 {"add_batch", jt_lst_add_batch, NULL,
3257 "Usage: lst add_batch NAME" },
3258 {"run", jt_lst_start_batch, NULL,
3259 "Usage: lst run [--timeout TIME] [NAME]" },
3260 {"stop", jt_lst_stop_batch, NULL,
3261 "Usage: lst stop [--force] BATCH_NAME" },
3262 {"list_batch", jt_lst_list_batch, NULL,
3263 "Usage: lst list_batch NAME [--test ID] [--server]" },
3264 {"query", jt_lst_query_batch, NULL,
3265 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3266 {"add_test", jt_lst_add_test, NULL,
3267 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3268 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3269 {"help", Parser_help, 0, "help" },
3274 lst_initialize(void)
3279 feats = getenv("LST_FEATURES");
3281 session_features = strtol(feats, NULL, 16);
3283 if ((session_features & ~LST_FEATS_MASK) != 0) {
3285 "Unsupported session features %x, "
3286 "only support these features so far: %x\n",
3287 (session_features & ~LST_FEATS_MASK), LST_FEATS_MASK);
3291 key = getenv("LST_SESSION");
3298 session_key = atoi(key);
3304 main(int argc, char **argv)
3310 rc = lst_initialize();
3314 rc = ptl_initialize(argc, argv);
3318 Parser_init("lst > ", lst_cmdlist);
3321 rc = Parser_execarg(argc - 1, argv + 1, lst_cmdlist);