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>
43 #include <libcfs/libcfsutil.h>
44 #include <lnet/lnetctl.h>
45 #include <lnet/lnetst.h>
46 /* NB: these includes are layering violation */
47 #include <lustre_ver.h>
48 #include <lustre/lustre_idl.h>
50 lst_sid_t LST_INVALID_SID = {LNET_NID_ANY, -1};
51 static lst_sid_t session_id;
52 static int session_key;
54 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 6, 50, 0)
55 /* assume all nodes can understand feature LST_FEAT_BULK_LEN */
56 static unsigned session_features = LST_FEATS_MASK;
58 static unsigned session_features = LST_FEATS_EMPTY;
61 static lstcon_trans_stat_t trans_stat;
63 typedef struct list_string {
64 struct list_string *lstr_next;
70 # define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
73 static int alloc_count = 0;
74 static int alloc_nob = 0;
79 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
82 fprintf(stderr, "Can't allocate lstr\n");
89 lstr->lstr_str[0] = 0;
95 free_lstr(lstr_t *lstr)
98 alloc_nob -= lstr->lstr_sz;
103 free_lstrs(lstr_t **list)
107 while ((lstr = *list) != NULL) {
108 *list = lstr->lstr_next;
114 new_lstrs(lstr_t **list, char *prefix, char *postfix,
115 int lo, int hi, int stride)
117 int n1 = strlen(prefix);
118 int n2 = strlen(postfix);
119 int sz = n1 + 20 + n2 + 1;
122 lstr_t *n = alloc_lstr(sz);
124 snprintf(n->lstr_str, sz - 1, "%s%u%s",
125 prefix, lo, postfix);
127 n->lstr_next = *list;
135 expand_lstr(lstr_t **list, lstr_t *l)
137 int nob = strlen(l->lstr_str);
147 b1 = strchr(l->lstr_str, '[');
149 l->lstr_next = *list;
154 b2 = strchr(b1, ']');
155 if (b2 == NULL || b2 == b1 + 1)
163 sep = strchr(expr, ',');
169 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
171 new_lstrs(list, l->lstr_str, b2, x, x, 1);
176 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
179 new_lstrs(list, l->lstr_str, b2, x, y, 1);
184 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
187 new_lstrs(list, l->lstr_str, b2, x, y, z);
193 } while ((expr = sep) != NULL);
201 expand_strs(char *str, lstr_t **head)
209 l = alloc_lstr(strlen(str) + 1);
210 memcpy(l->lstr_str, str, strlen(str) + 1);
218 while ((l = list) != NULL) {
221 rc = expand_lstr(&nlist, l);
223 fprintf(stderr, "Syntax error in \"%s\"\n", str);
231 /* re-order onto 'list' */
232 while ((l = nlist) != NULL) {
233 nlist = l->lstr_next;
238 } while (expanded && rc > 0);
245 while ((l = list) != NULL) {
254 lst_parse_nids(char *str, int *countp, lnet_process_id_t **idspp)
262 rc = expand_strs(str, &head);
272 *idspp = malloc(c * sizeof(lnet_process_id_t));
273 if (*idspp == NULL) {
274 fprintf(stderr, "Out of memory\n");
281 while ((l = head) != NULL) {
285 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
286 if ((*idspp)[i].nid == LNET_NID_ANY) {
287 fprintf(stderr, "Invalid nid: %s\n",
292 (*idspp)[i].pid = LUSTRE_LNET_PID;
309 lst_node_state2str(int state)
311 if (state == LST_NODE_ACTIVE)
313 if (state == LST_NODE_BUSY)
315 if (state == LST_NODE_DOWN)
322 lst_node_str2state(char *str)
324 if (strcasecmp(str, "active") == 0)
325 return LST_NODE_ACTIVE;
326 if (strcasecmp(str, "busy") == 0)
327 return LST_NODE_BUSY;
328 if (strcasecmp(str, "down") == 0)
329 return LST_NODE_DOWN;
330 if (strcasecmp(str, "unknown") == 0)
331 return LST_NODE_UNKNOWN;
332 if (strcasecmp(str, "invalid") == 0)
333 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
339 lst_test_type2name(int type)
341 if (type == LST_TEST_PING)
343 if (type == LST_TEST_BULK)
350 lst_test_name2type(char *name)
352 if (strcasecmp(name, "ping") == 0)
353 return LST_TEST_PING;
354 if (strcasecmp(name, "brw") == 0)
355 return LST_TEST_BULK;
361 lst_print_usage(char *cmd)
363 Parser_printhelp(cmd);
367 lst_print_error(char *sub, const char *def_format, ...)
371 /* local error returned from kernel */
374 fprintf(stderr, "No session exists\n");
377 fprintf(stderr, "Session is shutting down\n");
380 fprintf(stderr, "Unmatched session key or not root\n");
383 fprintf(stderr, "Can't find %s in current session\n", sub);
386 fprintf(stderr, "Invalid parameters list in command line\n");
389 fprintf(stderr, "Bad parameter address\n");
392 fprintf(stderr, "%s already exists\n", sub);
395 va_start(ap, def_format);
396 vfprintf(stderr, def_format, ap);
404 lst_free_rpcent(struct list_head *head)
406 lstcon_rpc_ent_t *ent;
408 while (!list_empty(head)) {
409 ent = list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
411 list_del(&ent->rpe_link);
417 lst_reset_rpcent(struct list_head *head)
419 lstcon_rpc_ent_t *ent;
421 list_for_each_entry(ent, head, rpe_link) {
422 ent->rpe_sid = LST_INVALID_SID;
423 ent->rpe_peer.nid = LNET_NID_ANY;
424 ent->rpe_peer.pid = LNET_PID_ANY;
425 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
430 lst_alloc_rpcent(struct list_head *head, int count, int offset)
432 lstcon_rpc_ent_t *ent;
435 for (i = 0; i < count; i++) {
436 ent = malloc(offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
438 lst_free_rpcent(head);
442 memset(ent, 0, offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
444 ent->rpe_sid = LST_INVALID_SID;
445 ent->rpe_peer.nid = LNET_NID_ANY;
446 ent->rpe_peer.pid = LNET_PID_ANY;
447 list_add(&ent->rpe_link, head);
454 lst_print_transerr(struct list_head *head, char *optstr)
456 lstcon_rpc_ent_t *ent;
458 list_for_each_entry(ent, head, rpe_link) {
459 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
462 if (ent->rpe_rpc_errno != 0) {
463 fprintf(stderr, "%s RPC failed on %s: %s\n",
464 optstr, libcfs_id2str(ent->rpe_peer),
465 strerror(ent->rpe_rpc_errno));
469 fprintf(stderr, "operation %s failed on %s: %s\n",
470 optstr, libcfs_id2str(ent->rpe_peer),
471 strerror(ent->rpe_fwk_errno));
475 int lst_info_batch_ioctl(char *batch, int test, int server,
476 lstcon_test_batch_ent_t *entp, int *idxp,
477 int *ndentp, lstcon_node_ent_t *dentsp);
479 int lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
480 int *idx, int *count, lstcon_node_ent_t *dents);
482 int lst_query_batch_ioctl(char *batch, int test, int server,
483 int timeout, struct list_head *head);
486 lst_ioctl(unsigned int opc, void *buf, int len)
488 struct libcfs_ioctl_data data;
491 LIBCFS_IOC_INIT (data);
492 data.ioc_u32[0] = opc;
493 data.ioc_plen1 = len;
494 data.ioc_pbuf1 = (char *)buf;
495 data.ioc_plen2 = sizeof(trans_stat);
496 data.ioc_pbuf2 = (char *)&trans_stat;
498 memset(&trans_stat, 0, sizeof(trans_stat));
500 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
502 /* local error, no valid RPC result */
507 if (trans_stat.trs_rpc_errno != 0)
510 /* Framework error */
511 if (trans_stat.trs_fwk_errno != 0)
518 lst_new_session_ioctl(char *name, int timeout, int force, lst_sid_t *sid)
520 lstio_session_new_args_t args = {0};
522 args.lstio_ses_key = session_key;
523 args.lstio_ses_timeout = timeout;
524 args.lstio_ses_force = force;
525 args.lstio_ses_idp = sid;
526 args.lstio_ses_feats = session_features;
527 args.lstio_ses_nmlen = strlen(name);
528 args.lstio_ses_namep = name;
530 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
534 jt_lst_new_session(int argc, char **argv)
536 char buf[LST_NAME_SIZE];
544 static struct option session_opts[] =
546 {"timeout", required_argument, 0, 't' },
547 {"force", no_argument, 0, 'f' },
551 if (session_key == 0) {
553 "Can't find env LST_SESSION or value is not valid\n");
559 c = getopt_long(argc, argv, "ft:",
560 session_opts, &optidx);
570 timeout = atoi(optarg);
573 lst_print_usage(argv[0]);
579 fprintf(stderr, "Invalid timeout value\n");
583 if (optind == argc - 1) {
584 name = argv[optind ++];
585 if (strlen(name) >= LST_NAME_SIZE) {
586 fprintf(stderr, "Name size is limited to %d\n",
591 } else if (optind == argc) {
592 char user[LST_NAME_SIZE];
593 char host[LST_NAME_SIZE];
594 struct passwd *pw = getpwuid(getuid());
597 snprintf(user, sizeof(user), "%d", (int)getuid());
599 snprintf(user, sizeof(user), "%s", pw->pw_name);
601 rc = gethostname(host, sizeof(host));
603 snprintf(host, sizeof(host), "unknown_host");
605 snprintf(buf, sizeof(buf), "%s@%s", user, host);
609 lst_print_usage(argv[0]);
613 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
615 lst_print_error("session", "Failed to create session: %s\n",
620 fprintf(stdout, "SESSION: %s FEATURES: %x TIMEOUT: %d FORCE: %s\n",
621 name, session_features, timeout, force ? "Yes" : "No");
626 lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp,
627 lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
629 lstio_session_info_args_t args = {0};
631 args.lstio_ses_idp = sid;
632 args.lstio_ses_keyp = key;
633 args.lstio_ses_featp = featp;
634 args.lstio_ses_ndinfo = ndinfo;
635 args.lstio_ses_nmlen = len;
636 args.lstio_ses_namep = name;
638 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
642 jt_lst_show_session(int argc, char **argv)
644 lstcon_ndlist_ent_t ndinfo;
646 char name[LST_NAME_SIZE];
651 rc = lst_session_info_ioctl(name, sizeof(name), &key,
652 &feats, &sid, &ndinfo);
655 lst_print_error("session", "Failed to show session: %s\n",
660 fprintf(stdout, "%s ID: "LPU64"@%s, KEY: %d FEATURES: %x NODES: %d\n",
661 name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
662 key, feats, ndinfo.nle_nnode);
668 lst_end_session_ioctl(void)
670 lstio_session_end_args_t args = {0};
672 args.lstio_ses_key = session_key;
673 return lst_ioctl (LSTIO_SESSION_END, &args, sizeof(args));
677 jt_lst_end_session(int argc, char **argv)
681 if (session_key == 0) {
683 "Can't find env LST_SESSION or value is not valid\n");
687 rc = lst_end_session_ioctl();
690 fprintf(stdout, "session is ended\n");
695 lst_print_error("session", "Failed to end session: %s\n",
700 if (trans_stat.trs_rpc_errno != 0) {
702 "[RPC] Failed to send %d session RPCs: %s\n",
703 lstcon_rpc_stat_failure(&trans_stat, 0),
704 strerror(trans_stat.trs_rpc_errno));
707 if (trans_stat.trs_fwk_errno != 0) {
709 "[FWK] Failed to end session on %d nodes: %s\n",
710 lstcon_sesop_stat_failure(&trans_stat, 0),
711 strerror(trans_stat.trs_fwk_errno));
718 lst_ping_ioctl(char *str, int type, int timeout,
719 int count, lnet_process_id_t *ids, struct list_head *head)
721 lstio_debug_args_t args = {0};
723 args.lstio_dbg_key = session_key;
724 args.lstio_dbg_type = type;
725 args.lstio_dbg_flags = 0;
726 args.lstio_dbg_timeout = timeout;
727 args.lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str);
728 args.lstio_dbg_namep = str;
729 args.lstio_dbg_count = count;
730 args.lstio_dbg_idsp = ids;
731 args.lstio_dbg_resultp = head;
733 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
737 lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
739 char buf[LST_NAME_SIZE];
740 lstcon_test_batch_ent_t ent;
741 lstcon_ndlist_ent_t *entp = &ent.tbe_cli_nle;
748 case LST_OPC_SESSION:
749 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
750 &key, &feats, &sid, entp);
753 case LST_OPC_BATCHSRV:
754 entp = &ent.tbe_srv_nle;
755 case LST_OPC_BATCHCLI:
756 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
760 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
764 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
773 *countp = entp->nle_nnode;
779 jt_lst_ping(int argc, char **argv)
781 struct list_head head;
782 lnet_process_id_t *ids = NULL;
783 lstcon_rpc_ent_t *ent = NULL;
793 static struct option ping_opts[] =
795 {"session", no_argument, 0, 's' },
796 {"server", no_argument, 0, 'v' },
797 {"batch", required_argument, 0, 'b' },
798 {"group", required_argument, 0, 'g' },
799 {"nodes", required_argument, 0, 'n' },
800 {"timeout", required_argument, 0, 't' },
804 if (session_key == 0) {
806 "Can't find env LST_SESSION or value is not valid\n");
812 c = getopt_long(argc, argv, "g:b:n:t:sv",
820 type = LST_OPC_SESSION;
824 type = LST_OPC_GROUP;
829 type = LST_OPC_BATCHCLI;
834 type = LST_OPC_NODES;
839 timeout = atoi(optarg);
847 lst_print_usage(argv[0]);
852 if (type == 0 || timeout <= 0 || optind != argc) {
853 lst_print_usage(argv[0]);
857 if (type == LST_OPC_BATCHCLI && server)
858 type = LST_OPC_BATCHSRV;
860 rc = lst_get_node_count(type, str, &count, &ids);
862 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
863 (str == NULL) ? "session" : str, strerror(errno));
867 INIT_LIST_HEAD(&head);
869 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
871 fprintf(stderr, "Out of memory\n");
876 fprintf(stdout, "Target %s is empty\n",
877 (str == NULL) ? "session" : str);
881 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
882 if (rc == -1) { /* local failure */
883 lst_print_error("debug", "Failed to ping %s: %s\n",
884 (str == NULL) ? "session" : str,
890 /* ignore RPC errors and framwork errors */
891 list_for_each_entry(ent, &head, rpe_link) {
892 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
893 libcfs_id2str(ent->rpe_peer),
894 lst_node_state2str(ent->rpe_state),
895 (ent->rpe_state == LST_NODE_ACTIVE ||
896 ent->rpe_state == LST_NODE_BUSY) ?
897 (ent->rpe_rpc_errno == 0 ?
898 &ent->rpe_payload[0] : "Unknown") :
899 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
903 lst_free_rpcent(&head);
913 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
914 unsigned *featp, struct list_head *resultp)
916 lstio_group_nodes_args_t args = {0};
918 args.lstio_grp_key = session_key;
919 args.lstio_grp_nmlen = strlen(name);
920 args.lstio_grp_namep = name;
921 args.lstio_grp_count = count;
922 args.lstio_grp_featp = featp;
923 args.lstio_grp_idsp = ids;
924 args.lstio_grp_resultp = resultp;
926 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
930 lst_del_group_ioctl(char *name)
932 lstio_group_del_args_t args = {0};
934 args.lstio_grp_key = session_key;
935 args.lstio_grp_nmlen = strlen(name);
936 args.lstio_grp_namep = name;
938 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
942 lst_del_group(char *grp_name)
946 rc = lst_del_group_ioctl(grp_name);
948 fprintf(stdout, "Group is deleted\n");
953 lst_print_error("group", "Failed to delete group: %s\n",
958 fprintf(stderr, "Group is deleted with some errors\n");
960 if (trans_stat.trs_rpc_errno != 0) {
962 "[RPC] Failed to send %d end session RPCs: %s\n",
963 lstcon_rpc_stat_failure(&trans_stat, 0),
964 strerror(trans_stat.trs_rpc_errno));
967 if (trans_stat.trs_fwk_errno != 0) {
969 "[FWK] Failed to end session on %d nodes: %s\n",
970 lstcon_sesop_stat_failure(&trans_stat, 0),
971 strerror(trans_stat.trs_fwk_errno));
978 lst_add_group_ioctl (char *name)
980 lstio_group_add_args_t args = {0};
982 args.lstio_grp_key = session_key;
983 args.lstio_grp_nmlen = strlen(name);
984 args.lstio_grp_namep = name;
986 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
990 jt_lst_add_group(int argc, char **argv)
992 struct list_head head;
993 lnet_process_id_t *ids;
995 unsigned feats = session_features;
999 bool nodes_added = false;
1001 if (session_key == 0) {
1003 "Can't find env LST_SESSION or value is not valid\n");
1008 lst_print_usage(argv[0]);
1013 if (strlen(name) >= LST_NAME_SIZE) {
1014 fprintf(stderr, "Name length is limited to %d\n",
1019 rc = lst_add_group_ioctl(name);
1021 lst_print_error("group", "Failed to add group %s: %s\n",
1022 name, strerror(errno));
1026 INIT_LIST_HEAD(&head);
1028 for (i = 2; i < argc; i++) {
1029 /* parse address list */
1030 rc = lst_parse_nids(argv[i], &count, &ids);
1032 fprintf(stderr, "Ignore invalid id list %s\n",
1040 rc = lst_alloc_rpcent(&head, count, 0);
1042 fprintf(stderr, "Out of memory\n");
1048 rc = lst_add_nodes_ioctl(name, count, ids, &feats, &head);
1055 fprintf(stdout, "%s are added to session\n", argv[i]);
1059 if ((feats & session_features) != session_features) {
1061 "Warning, this session will run with "
1062 "compatible mode because some test nodes "
1063 "might not understand these features: %x\n",
1064 (~feats & session_features));
1067 lst_free_rpcent(&head);
1072 * The selftest kernel module expects that a group should
1073 * have at least one node, since it doesn't make sense for
1074 * an empty group to be added to a test.
1077 "No nodes added successfully, deleting group %s\n",
1079 rc = lst_del_group(name);
1082 "Failed to delete group %s."
1083 " Group is empty.\n", name);
1091 lst_print_error("group", "Failed to add nodes %s: %s\n",
1092 argv[i], strerror(errno));
1095 if (trans_stat.trs_fwk_errno == EPROTO) {
1097 "test nodes might have different LST "
1098 "features, please disable some features by "
1099 "setting LST_FEATURES\n");
1102 lst_print_transerr(&head, "create session");
1105 lst_free_rpcent(&head);
1109 "No nodes added successfully, deleting group %s\n",
1111 if (lst_del_group(name) != 0) {
1113 "Failed to delete group %s."
1114 " Group is empty.\n", name);
1122 jt_lst_del_group(int argc, char **argv)
1126 if (session_key == 0) {
1128 "Can't find env LST_SESSION or value is not valid\n");
1133 lst_print_usage(argv[0]);
1137 rc = lst_del_group(argv[1]);
1143 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1144 lnet_process_id_t *ids, struct list_head *resultp)
1146 lstio_group_update_args_t args = {0};
1148 args.lstio_grp_key = session_key;
1149 args.lstio_grp_opc = opc;
1150 args.lstio_grp_args = clean;
1151 args.lstio_grp_nmlen = strlen(name);
1152 args.lstio_grp_namep = name;
1153 args.lstio_grp_count = count;
1154 args.lstio_grp_idsp = ids;
1155 args.lstio_grp_resultp = resultp;
1157 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1161 jt_lst_update_group(int argc, char **argv)
1163 struct list_head head;
1164 lnet_process_id_t *ids = NULL;
1174 static struct option update_group_opts[] =
1176 {"refresh", no_argument, 0, 'f' },
1177 {"clean", required_argument, 0, 'c' },
1178 {"remove", required_argument, 0, 'r' },
1182 if (session_key == 0) {
1184 "Can't find env LST_SESSION or value is not valid\n");
1189 c = getopt_long(argc, argv, "fc:r:",
1190 update_group_opts, &optidx);
1192 /* Detect the end of the options. */
1199 lst_print_usage(argv[0]);
1202 opc = LST_GROUP_REFRESH;
1207 lst_print_usage(argv[0]);
1210 opc = LST_GROUP_RMND;
1215 clean = lst_node_str2state(optarg);
1216 if (opc != 0 || clean <= 0) {
1217 lst_print_usage(argv[0]);
1220 opc = LST_GROUP_CLEAN;
1224 lst_print_usage(argv[0]);
1229 /* no OPC or group is specified */
1230 if (opc == 0 || optind != argc - 1) {
1231 lst_print_usage(argv[0]);
1237 INIT_LIST_HEAD(&head);
1239 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1240 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1242 opc == LST_GROUP_RMND ? str : grp,
1246 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1247 opc == LST_GROUP_RMND ? str : grp,
1252 rc = lst_alloc_rpcent(&head, count, 0);
1254 fprintf(stderr, "Out of memory\n");
1261 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1267 lst_free_rpcent(&head);
1272 lst_free_rpcent(&head);
1273 lst_print_error("group", "Failed to update group: %s\n",
1278 lst_print_transerr(&head, "Updating group");
1280 lst_free_rpcent(&head);
1286 lst_list_group_ioctl(int len, char *name, int idx)
1288 lstio_group_list_args_t args = {0};
1290 args.lstio_grp_key = session_key;
1291 args.lstio_grp_idx = idx;
1292 args.lstio_grp_nmlen = len;
1293 args.lstio_grp_namep = name;
1295 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1299 lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
1300 int *idx, int *count, lstcon_node_ent_t *dents)
1302 lstio_group_info_args_t args = {0};
1304 args.lstio_grp_key = session_key;
1305 args.lstio_grp_nmlen = strlen(name);
1306 args.lstio_grp_namep = name;
1307 args.lstio_grp_entp = gent;
1308 args.lstio_grp_idxp = idx;
1309 args.lstio_grp_ndentp = count;
1310 args.lstio_grp_dentsp = dents;
1312 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1316 lst_list_group_all(void)
1318 char name[LST_NAME_SIZE];
1322 /* no group is specified, list name of all groups */
1323 for (i = 0; ; i++) {
1324 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1326 fprintf(stdout, "%d) %s\n", i + 1, name);
1330 if (errno == ENOENT)
1333 lst_print_error("group", "Failed to list group: %s\n",
1338 fprintf(stdout, "Total %d groups\n", i);
1343 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1346 jt_lst_list_group(int argc, char **argv)
1348 lstcon_ndlist_ent_t gent;
1349 lstcon_node_ent_t *dents;
1364 static struct option list_group_opts[] =
1366 {"active", no_argument, 0, 'a' },
1367 {"busy", no_argument, 0, 'b' },
1368 {"down", no_argument, 0, 'd' },
1369 {"unknown", no_argument, 0, 'u' },
1370 {"all", no_argument, 0, 'l' },
1374 if (session_key == 0) {
1376 "Can't find env LST_SESSION or value is not valid\n");
1381 c = getopt_long(argc, argv, "abdul",
1382 list_group_opts, &optidx);
1389 verbose = active = 1;
1401 verbose = unknown = 1;
1408 lst_print_usage(argv[0]);
1413 if (optind == argc) {
1414 /* no group is specified, list name of all groups */
1415 rc = lst_list_group_all();
1421 fprintf(stdout, LST_NODES_TITLE);
1423 /* list nodes in specified groups */
1424 for (i = optind; i < argc; i++) {
1425 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1427 if (errno == ENOENT) {
1432 lst_print_error("group", "Failed to list group\n",
1438 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1439 gent.nle_nactive, gent.nle_nbusy,
1440 gent.nle_ndown, gent.nle_nunknown,
1441 gent.nle_nnode, argv[i]);
1445 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1447 if (gent.nle_nnode == 0) {
1448 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1452 count = gent.nle_nnode;
1454 dents = malloc(count * sizeof(lstcon_node_ent_t));
1455 if (dents == NULL) {
1456 fprintf(stderr, "Failed to malloc: %s\n",
1462 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1464 lst_print_error("group", "Failed to list group: %s\n",
1470 for (j = 0, c = 0; j < count; j++) {
1472 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1473 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1474 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1475 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1477 fprintf(stdout, "\t%s: %s\n",
1478 libcfs_id2str(dents[j].nde_id),
1479 lst_node_state2str(dents[j].nde_state));
1484 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1493 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
1494 int timeout, struct list_head *resultp)
1496 lstio_stat_args_t args = {0};
1498 args.lstio_sta_key = session_key;
1499 args.lstio_sta_timeout = timeout;
1500 args.lstio_sta_nmlen = strlen(name);
1501 args.lstio_sta_namep = name;
1502 args.lstio_sta_count = count;
1503 args.lstio_sta_idsp = idsp;
1504 args.lstio_sta_resultp = resultp;
1506 return lst_ioctl (LSTIO_STAT_QUERY, &args, sizeof(args));
1510 struct list_head srp_link;
1513 lnet_process_id_t *srp_ids;
1514 struct list_head srp_result[2];
1515 } lst_stat_req_param_t;
1518 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1522 for (i = 0; i < 2; i++)
1523 lst_free_rpcent(&srp->srp_result[i]);
1525 if (srp->srp_ids != NULL)
1532 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
1534 lst_stat_req_param_t *srp = NULL;
1535 int count = save_old ? 2 : 1;
1539 srp = malloc(sizeof(*srp));
1543 memset(srp, 0, sizeof(*srp));
1544 INIT_LIST_HEAD(&srp->srp_result[0]);
1545 INIT_LIST_HEAD(&srp->srp_result[1]);
1547 rc = lst_get_node_count(LST_OPC_GROUP, name,
1548 &srp->srp_count, NULL);
1549 if (rc != 0 && errno == ENOENT) {
1550 rc = lst_get_node_count(LST_OPC_NODES, name,
1551 &srp->srp_count, &srp->srp_ids);
1556 "Failed to get count of nodes from %s: %s\n",
1557 name, strerror(errno));
1558 lst_stat_req_param_free(srp);
1563 srp->srp_name = name;
1565 for (i = 0; i < count; i++) {
1566 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1567 sizeof(sfw_counters_t) +
1568 sizeof(srpc_counters_t) +
1569 sizeof(lnet_counters_t));
1571 fprintf(stderr, "Out of memory\n");
1581 lst_stat_req_param_free(srp);
1589 } lst_srpc_stat_result;
1591 #define LST_LNET_AVG 0
1592 #define LST_LNET_MIN 1
1593 #define LST_LNET_MAX 2
1596 float lnet_avg_sndrate;
1597 float lnet_min_sndrate;
1598 float lnet_max_sndrate;
1599 float lnet_total_sndrate;
1601 float lnet_avg_rcvrate;
1602 float lnet_min_rcvrate;
1603 float lnet_max_rcvrate;
1604 float lnet_total_rcvrate;
1606 float lnet_avg_sndperf;
1607 float lnet_min_sndperf;
1608 float lnet_max_sndperf;
1609 float lnet_total_sndperf;
1611 float lnet_avg_rcvperf;
1612 float lnet_min_rcvperf;
1613 float lnet_max_rcvperf;
1614 float lnet_total_rcvperf;
1616 int lnet_stat_count;
1617 } lst_lnet_stat_result_t;
1619 lst_lnet_stat_result_t lnet_stat_result;
1622 lst_lnet_stat_value(int bw, int send, int off)
1626 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1627 &lnet_stat_result.lnet_avg_sndrate;
1638 lst_timeval_diff(struct timeval *tv1,
1639 struct timeval *tv2, struct timeval *df)
1641 if (tv1->tv_usec >= tv2->tv_usec) {
1642 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1643 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1647 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1648 df->tv_usec = tv1->tv_usec + 1000000 - tv2->tv_usec;
1654 lst_cal_lnet_stat(float delta, lnet_counters_t *lnet_new,
1655 lnet_counters_t *lnet_old)
1660 perf = (float)(lnet_new->send_length -
1661 lnet_old->send_length) / (1024 * 1024) / delta;
1662 lnet_stat_result.lnet_total_sndperf += perf;
1664 if (lnet_stat_result.lnet_min_sndperf > perf ||
1665 lnet_stat_result.lnet_min_sndperf == 0)
1666 lnet_stat_result.lnet_min_sndperf = perf;
1668 if (lnet_stat_result.lnet_max_sndperf < perf)
1669 lnet_stat_result.lnet_max_sndperf = perf;
1671 perf = (float)(lnet_new->recv_length -
1672 lnet_old->recv_length) / (1024 * 1024) / delta;
1673 lnet_stat_result.lnet_total_rcvperf += perf;
1675 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1676 lnet_stat_result.lnet_min_rcvperf == 0)
1677 lnet_stat_result.lnet_min_rcvperf = perf;
1679 if (lnet_stat_result.lnet_max_rcvperf < perf)
1680 lnet_stat_result.lnet_max_rcvperf = perf;
1682 rate = (lnet_new->send_count - lnet_old->send_count) / delta;
1683 lnet_stat_result.lnet_total_sndrate += rate;
1685 if (lnet_stat_result.lnet_min_sndrate > rate ||
1686 lnet_stat_result.lnet_min_sndrate == 0)
1687 lnet_stat_result.lnet_min_sndrate = rate;
1689 if (lnet_stat_result.lnet_max_sndrate < rate)
1690 lnet_stat_result.lnet_max_sndrate = rate;
1692 rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
1693 lnet_stat_result.lnet_total_rcvrate += rate;
1695 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1696 lnet_stat_result.lnet_min_rcvrate == 0)
1697 lnet_stat_result.lnet_min_rcvrate = rate;
1699 if (lnet_stat_result.lnet_max_rcvrate < rate)
1700 lnet_stat_result.lnet_max_rcvrate = rate;
1702 lnet_stat_result.lnet_stat_count ++;
1704 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1705 lnet_stat_result.lnet_stat_count;
1706 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1707 lnet_stat_result.lnet_stat_count;
1709 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1710 lnet_stat_result.lnet_stat_count;
1711 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1712 lnet_stat_result.lnet_stat_count;
1717 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
1726 if (lnet_stat_result.lnet_stat_count == 0)
1729 if (bwrt == 1) /* bw only */
1732 if (bwrt == 2) /* rates only */
1735 if (rdwr == 1) /* recv only */
1738 if (rdwr == 2) /* send only */
1741 for (i = start1; i <= end1; i++) {
1742 fprintf(stdout, "[LNet %s of %s]\n",
1743 i == 0 ? "Rates" : "Bandwidth", name);
1745 for (j = start2; j <= end2; j++) {
1746 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
1748 if ((type & 1) != 0) {
1749 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1750 "Avg: %-8.2f MB/s ",
1751 lst_lnet_stat_value(i, j, 0));
1754 if ((type & 2) != 0) {
1755 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1756 "Min: %-8.2f MB/s ",
1757 lst_lnet_stat_value(i, j, 1));
1760 if ((type & 4) != 0) {
1761 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1763 lst_lnet_stat_value(i, j, 2));
1766 fprintf(stdout, "\n");
1772 lst_print_stat(char *name, struct list_head *resultp,
1773 int idx, int lnet, int bwrt, int rdwr, int type)
1775 struct list_head tmp[2];
1776 lstcon_rpc_ent_t *new;
1777 lstcon_rpc_ent_t *old;
1778 sfw_counters_t *sfwk_new;
1779 sfw_counters_t *sfwk_old;
1780 srpc_counters_t *srpc_new;
1781 srpc_counters_t *srpc_old;
1782 lnet_counters_t *lnet_new;
1783 lnet_counters_t *lnet_old;
1787 INIT_LIST_HEAD(&tmp[0]);
1788 INIT_LIST_HEAD(&tmp[1]);
1790 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1792 while (!list_empty(&resultp[idx])) {
1793 if (list_empty(&resultp[1 - idx])) {
1794 fprintf(stderr, "Group is changed, re-run stat\n");
1798 new = list_entry(resultp[idx].next, lstcon_rpc_ent_t,
1800 old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t,
1803 /* first time get stats result, can't calculate diff */
1804 if (new->rpe_peer.nid == LNET_NID_ANY)
1807 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1808 new->rpe_peer.pid != old->rpe_peer.pid) {
1809 /* Something wrong. i.e, somebody change the group */
1813 list_del(&new->rpe_link);
1814 list_add_tail(&new->rpe_link, &tmp[idx]);
1816 list_del(&old->rpe_link);
1817 list_add_tail(&old->rpe_link, &tmp[1 - idx]);
1819 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1820 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1825 sfwk_new = (sfw_counters_t *)&new->rpe_payload[0];
1826 sfwk_old = (sfw_counters_t *)&old->rpe_payload[0];
1828 srpc_new = (srpc_counters_t *)((char *)sfwk_new + sizeof(*sfwk_new));
1829 srpc_old = (srpc_counters_t *)((char *)sfwk_old + sizeof(*sfwk_old));
1831 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
1832 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
1834 /* Prior to version 2.3, the running_ms field was a counter for
1835 * the number of running tests. We are looking at this value
1836 * to determine if it is a millisecond timestamep (>= 2.3) or a
1837 * test counter (< 2.3). The number 500 is being used for this
1838 * barrier as the test counter should never get this high, and
1839 * the timestamp should never get this low. */
1841 if (sfwk_new->running_ms > 500) {
1842 /* use the timestamp from the remote node, not our
1843 * rpe_stamp from when we copied up the data out of
1846 delta = (float) (sfwk_new->running_ms -
1847 sfwk_old->running_ms) / 1000;
1851 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1852 delta = tv.tv_sec + (float)tv.tv_usec / 1000000;
1855 if (!lnet) /* TODO */
1858 lst_cal_lnet_stat(delta, lnet_new, lnet_old);
1861 list_splice(&tmp[idx], &resultp[idx]);
1862 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1865 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1867 if (!lnet) /* TODO */
1870 lst_print_lnet_stat(name, bwrt, rdwr, type);
1874 jt_lst_stat(int argc, char **argv)
1876 struct list_head head;
1877 lst_stat_req_param_t *srp;
1880 int timeout = 5; /* default timeout, 5 sec */
1881 int delay = 5; /* default delay, 5 sec */
1882 int count = -1; /* run forever */
1883 int lnet = 1; /* lnet stat by default */
1891 static struct option stat_opts[] =
1893 {"timeout" , required_argument, 0, 't' },
1894 {"delay" , required_argument, 0, 'd' },
1895 {"count" , required_argument, 0, 'o' },
1896 {"lnet" , no_argument, 0, 'l' },
1897 {"rpc" , no_argument, 0, 'c' },
1898 {"bw" , no_argument, 0, 'b' },
1899 {"rate" , no_argument, 0, 'a' },
1900 {"read" , no_argument, 0, 'r' },
1901 {"write" , no_argument, 0, 'w' },
1902 {"avg" , no_argument, 0, 'g' },
1903 {"min" , no_argument, 0, 'n' },
1904 {"max" , no_argument, 0, 'x' },
1908 if (session_key == 0) {
1910 "Can't find env LST_SESSION or value is not valid\n");
1915 c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
1922 timeout = atoi(optarg);
1925 delay = atoi(optarg);
1928 count = atoi(optarg);
1971 lst_print_usage(argv[0]);
1976 if (optind == argc) {
1977 lst_print_usage(argv[0]);
1981 if (timeout <= 0 || delay <= 0) {
1982 fprintf(stderr, "Invalid timeout or delay value\n");
1987 fprintf(stderr, "Invalid count value\n");
1991 /* extra count to get first data point */
1995 INIT_LIST_HEAD(&head);
1997 while (optind < argc) {
1998 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
2002 list_add_tail(&srp->srp_link, &head);
2006 time_t now = time(NULL);
2008 if (now - last < delay) {
2009 sleep(delay - now + last);
2014 list_for_each_entry(srp, &head, srp_link) {
2015 rc = lst_stat_ioctl(srp->srp_name,
2016 srp->srp_count, srp->srp_ids,
2017 timeout, &srp->srp_result[idx]);
2019 lst_print_error("stat", "Failed to stat %s: %s\n",
2020 srp->srp_name, strerror(errno));
2024 lst_print_stat(srp->srp_name, srp->srp_result,
2025 idx, lnet, bwrt, rdwr, type);
2027 lst_reset_rpcent(&srp->srp_result[1 - idx]);
2034 } while (count == -1 || count > 0);
2037 while (!list_empty(&head)) {
2038 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2040 list_del(&srp->srp_link);
2041 lst_stat_req_param_free(srp);
2048 jt_lst_show_error(int argc, char **argv)
2050 struct list_head head;
2051 lst_stat_req_param_t *srp;
2052 lstcon_rpc_ent_t *ent;
2053 sfw_counters_t *sfwk;
2054 srpc_counters_t *srpc;
2061 static struct option show_error_opts[] =
2063 {"session", no_argument, 0, 's' },
2067 if (session_key == 0) {
2069 "Can't find env LST_SESSION or value is not valid\n");
2074 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
2085 lst_print_usage(argv[0]);
2090 if (optind == argc) {
2091 lst_print_usage(argv[0]);
2095 INIT_LIST_HEAD(&head);
2097 while (optind < argc) {
2098 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
2102 list_add_tail(&srp->srp_link, &head);
2105 list_for_each_entry(srp, &head, srp_link) {
2106 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
2107 srp->srp_ids, 10, &srp->srp_result[0]);
2110 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2111 srp->srp_name, strerror(errno));
2115 fprintf(stdout, "%s:\n", srp->srp_name);
2119 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2120 if (ent->rpe_rpc_errno != 0) {
2122 fprintf(stderr, "RPC failure, can't show error on %s\n",
2123 libcfs_id2str(ent->rpe_peer));
2127 if (ent->rpe_fwk_errno != 0) {
2129 fprintf(stderr, "Framework failure, can't show error on %s\n",
2130 libcfs_id2str(ent->rpe_peer));
2134 sfwk = (sfw_counters_t *)&ent->rpe_payload[0];
2135 srpc = (srpc_counters_t *)((char *)sfwk + sizeof(*sfwk));
2137 if (srpc->errors == 0 &&
2138 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2142 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2147 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2148 libcfs_id2str(ent->rpe_peer),
2149 sfwk->brw_errors, sfwk->ping_errors,
2150 show_rpc ? ' ' : '\n');
2155 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2156 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2159 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2162 while (!list_empty(&head)) {
2163 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2165 list_del(&srp->srp_link);
2166 lst_stat_req_param_free(srp);
2173 lst_add_batch_ioctl (char *name)
2175 lstio_batch_add_args_t args = {0};
2177 args.lstio_bat_key = session_key;
2178 args.lstio_bat_nmlen = strlen(name);
2179 args.lstio_bat_namep = name;
2181 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2185 jt_lst_add_batch(int argc, char **argv)
2190 if (session_key == 0) {
2192 "Can't find env LST_SESSION or value is not valid\n");
2197 lst_print_usage(argv[0]);
2202 if (strlen(name) >= LST_NAME_SIZE) {
2203 fprintf(stderr, "Name length is limited to %d\n",
2208 rc = lst_add_batch_ioctl(name);
2212 lst_print_error("batch", "Failed to create batch: %s\n",
2219 lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp)
2221 lstio_batch_run_args_t args = {0};
2223 args.lstio_bat_key = session_key;
2224 args.lstio_bat_timeout = timeout;
2225 args.lstio_bat_nmlen = strlen(name);
2226 args.lstio_bat_namep = name;
2227 args.lstio_bat_resultp = resultp;
2229 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2233 jt_lst_start_batch(int argc, char **argv)
2235 struct list_head head;
2243 static struct option start_batch_opts[] =
2245 {"timeout", required_argument, 0, 't' },
2249 if (session_key == 0) {
2251 "Can't find env LST_SESSION or value is not valid\n");
2256 c = getopt_long(argc, argv, "t:",
2257 start_batch_opts, &optidx);
2259 /* Detect the end of the options. */
2265 timeout = atoi(optarg);
2268 lst_print_usage(argv[0]);
2273 if (optind == argc) {
2274 batch = LST_DEFAULT_BATCH;
2276 } else if (optind == argc - 1) {
2277 batch = argv[optind];
2280 lst_print_usage(argv[0]);
2284 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2286 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2287 batch, strerror(errno));
2291 INIT_LIST_HEAD(&head);
2293 rc = lst_alloc_rpcent(&head, count, 0);
2295 fprintf(stderr, "Out of memory\n");
2299 rc = lst_start_batch_ioctl(batch, timeout, &head);
2302 fprintf(stdout, "%s is running now\n", batch);
2303 lst_free_rpcent(&head);
2308 lst_print_error("batch", "Failed to start batch: %s\n",
2310 lst_free_rpcent(&head);
2314 lst_print_transerr(&head, "Run batch");
2316 lst_free_rpcent(&head);
2322 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2324 lstio_batch_stop_args_t args = {0};
2326 args.lstio_bat_key = session_key;
2327 args.lstio_bat_force = force;
2328 args.lstio_bat_nmlen = strlen(name);
2329 args.lstio_bat_namep = name;
2330 args.lstio_bat_resultp = resultp;
2332 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2336 jt_lst_stop_batch(int argc, char **argv)
2338 struct list_head head;
2346 static struct option stop_batch_opts[] =
2348 {"force", no_argument, 0, 'f' },
2352 if (session_key == 0) {
2354 "Can't find env LST_SESSION or value is not valid\n");
2359 c = getopt_long(argc, argv, "f",
2360 stop_batch_opts, &optidx);
2362 /* Detect the end of the options. */
2371 lst_print_usage(argv[0]);
2376 if (optind == argc) {
2377 batch = LST_DEFAULT_BATCH;
2379 } else if (optind == argc - 1) {
2380 batch = argv[optind];
2383 lst_print_usage(argv[0]);
2387 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2389 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2390 batch, strerror(errno));
2394 INIT_LIST_HEAD(&head);
2396 rc = lst_alloc_rpcent(&head, count, 0);
2398 fprintf(stderr, "Out of memory\n");
2402 rc = lst_stop_batch_ioctl(batch, force, &head);
2407 lst_reset_rpcent(&head);
2409 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2413 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2414 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2417 fprintf(stdout, "%d batch in stopping\n",
2418 lstcon_tsbqry_stat_run(&trans_stat, 0));
2422 fprintf(stdout, "Batch is stopped\n");
2423 lst_free_rpcent(&head);
2428 lst_print_error("batch", "Failed to stop batch: %s\n",
2430 lst_free_rpcent(&head);
2434 lst_print_transerr(&head, "stop batch");
2436 lst_free_rpcent(&head);
2442 lst_list_batch_ioctl(int len, char *name, int index)
2444 lstio_batch_list_args_t args = {0};
2446 args.lstio_bat_key = session_key;
2447 args.lstio_bat_idx = index;
2448 args.lstio_bat_nmlen = len;
2449 args.lstio_bat_namep = name;
2451 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2455 lst_info_batch_ioctl(char *batch, int test, int server,
2456 lstcon_test_batch_ent_t *entp, int *idxp,
2457 int *ndentp, lstcon_node_ent_t *dentsp)
2459 lstio_batch_info_args_t args = {0};
2461 args.lstio_bat_key = session_key;
2462 args.lstio_bat_nmlen = strlen(batch);
2463 args.lstio_bat_namep = batch;
2464 args.lstio_bat_server = server;
2465 args.lstio_bat_testidx = test;
2466 args.lstio_bat_entp = entp;
2467 args.lstio_bat_idxp = idxp;
2468 args.lstio_bat_ndentp = ndentp;
2469 args.lstio_bat_dentsp = dentsp;
2471 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2475 lst_list_batch_all(void)
2477 char name[LST_NAME_SIZE];
2481 for (i = 0; ; i++) {
2482 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2484 fprintf(stdout, "%d) %s\n", i + 1, name);
2488 if (errno == ENOENT)
2491 lst_print_error("batch", "Failed to list batch: %s\n",
2496 fprintf(stdout, "Total %d batches\n", i);
2502 lst_list_tsb_nodes(char *batch, int test, int server,
2503 int count, int active, int invalid)
2505 lstcon_node_ent_t *dents;
2514 /* verbose list, show nodes in batch or test */
2515 dents = malloc(count * sizeof(lstcon_node_ent_t));
2516 if (dents == NULL) {
2517 fprintf(stdout, "Can't allocate memory\n");
2521 rc = lst_info_batch_ioctl(batch, test, server,
2522 NULL, &index, &count, dents);
2525 lst_print_error((test > 0) ? "test" : "batch",
2526 (test > 0) ? "Failed to query test: %s\n" :
2527 "Failed to query batch: %s\n",
2532 for (i = 0, c = 0; i < count; i++) {
2533 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2534 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2535 dents[i].nde_state == LST_NODE_DOWN ||
2536 dents[i].nde_state == LST_NODE_UNKNOWN)))
2539 fprintf(stdout, "\t%s: %s\n",
2540 libcfs_id2str(dents[i].nde_id),
2541 lst_node_state2str(dents[i].nde_state));
2545 fprintf(stdout, "Total %d nodes\n", c);
2552 jt_lst_list_batch(int argc, char **argv)
2554 lstcon_test_batch_ent_t ent;
2557 int verbose = 0; /* list nodes in batch or test */
2566 static struct option list_batch_opts[] =
2568 {"test", required_argument, 0, 't' },
2569 {"invalid", no_argument, 0, 'i' },
2570 {"active", no_argument, 0, 'a' },
2571 {"all", no_argument, 0, 'l' },
2572 {"server", no_argument, 0, 's' },
2576 if (session_key == 0) {
2578 "Can't find env LST_SESSION or value is not valid\n");
2583 c = getopt_long(argc, argv, "ailst:",
2584 list_batch_opts, &optidx);
2591 verbose = active = 1;
2594 verbose = invalid = 1;
2597 verbose = active = invalid = 1;
2603 test = atoi(optarg);
2607 lst_print_usage(argv[0]);
2612 if (optind == argc) {
2613 /* list all batches */
2614 rc = lst_list_batch_all();
2618 if (ntest == 1 && test <= 0) {
2619 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2623 if (optind != argc - 1) {
2624 lst_print_usage(argv[0]);
2628 batch = argv[optind];
2631 /* show detail of specified batch or test */
2632 rc = lst_info_batch_ioctl(batch, test, server,
2633 &ent, NULL, NULL, NULL);
2635 lst_print_error((test > 0) ? "test" : "batch",
2636 (test > 0) ? "Failed to query test: %s\n" :
2637 "Failed to query batch: %s\n",
2643 /* list nodes in test or batch */
2644 rc = lst_list_tsb_nodes(batch, test, server,
2645 server ? ent.tbe_srv_nle.nle_nnode :
2646 ent.tbe_cli_nle.nle_nnode,
2651 /* only show number of hosts in batch or test */
2653 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2654 batch, ent.u.tbe_batch.bae_ntest,
2655 ent.u.tbe_batch.bae_state);
2656 ntest = ent.u.tbe_batch.bae_ntest;
2657 test = 1; /* starting from test 1 */
2661 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2662 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2663 ent.u.tbe_test.tse_loop,
2664 ent.u.tbe_test.tse_concur);
2669 fprintf(stdout, LST_NODES_TITLE);
2670 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2671 "server\t%d\t%d\t%d\t%d\t%d\n",
2672 ent.tbe_cli_nle.nle_nactive,
2673 ent.tbe_cli_nle.nle_nbusy,
2674 ent.tbe_cli_nle.nle_ndown,
2675 ent.tbe_cli_nle.nle_nunknown,
2676 ent.tbe_cli_nle.nle_nnode,
2677 ent.tbe_srv_nle.nle_nactive,
2678 ent.tbe_srv_nle.nle_nbusy,
2679 ent.tbe_srv_nle.nle_ndown,
2680 ent.tbe_srv_nle.nle_nunknown,
2681 ent.tbe_srv_nle.nle_nnode);
2690 lst_query_batch_ioctl(char *batch, int test, int server,
2691 int timeout, struct list_head *head)
2693 lstio_batch_query_args_t args = {0};
2695 args.lstio_bat_key = session_key;
2696 args.lstio_bat_testidx = test;
2697 args.lstio_bat_client = !(server);
2698 args.lstio_bat_timeout = timeout;
2699 args.lstio_bat_nmlen = strlen(batch);
2700 args.lstio_bat_namep = batch;
2701 args.lstio_bat_resultp = head;
2703 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2707 lst_print_tsb_verbose(struct list_head *head,
2708 int active, int idle, int error)
2710 lstcon_rpc_ent_t *ent;
2712 list_for_each_entry(ent, head, rpe_link) {
2713 if (ent->rpe_priv[0] == 0 && active)
2716 if (ent->rpe_priv[0] != 0 && idle)
2719 if (ent->rpe_fwk_errno == 0 && error)
2722 fprintf(stdout, "%s [%s]: %s\n",
2723 libcfs_id2str(ent->rpe_peer),
2724 lst_node_state2str(ent->rpe_state),
2725 ent->rpe_rpc_errno != 0 ?
2726 strerror(ent->rpe_rpc_errno) :
2727 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2732 jt_lst_query_batch(int argc, char **argv)
2734 lstcon_test_batch_ent_t ent;
2735 struct list_head head;
2741 int timeout = 5; /* default 5 seconds */
2742 int delay = 5; /* default 5 seconds */
2743 int loop = 1; /* default 1 loop */
2753 static struct option query_batch_opts[] =
2755 {"timeout", required_argument, 0, 'o' },
2756 {"delay", required_argument, 0, 'd' },
2757 {"loop", required_argument, 0, 'c' },
2758 {"test", required_argument, 0, 't' },
2759 {"server", no_argument, 0, 's' },
2760 {"active", no_argument, 0, 'a' },
2761 {"idle", no_argument, 0, 'i' },
2762 {"error", no_argument, 0, 'e' },
2763 {"all", no_argument, 0, 'l' },
2767 if (session_key == 0) {
2769 "Can't find env LST_SESSION or value is not valid\n");
2774 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2775 query_batch_opts, &optidx);
2777 /* Detect the end of the options. */
2783 timeout = atoi(optarg);
2786 delay = atoi(optarg);
2789 loop = atoi(optarg);
2792 test = atoi(optarg);
2798 active = verbose = 1;
2804 error = verbose = 1;
2810 lst_print_usage(argv[0]);
2815 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2816 lst_print_usage(argv[0]);
2820 if (optind == argc) {
2821 batch = LST_DEFAULT_BATCH;
2823 } else if (optind == argc - 1) {
2824 batch = argv[optind];
2827 lst_print_usage(argv[0]);
2832 INIT_LIST_HEAD(&head);
2835 rc = lst_info_batch_ioctl(batch, test, server,
2836 &ent, NULL, NULL, NULL);
2838 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2839 batch, test, strerror(errno));
2843 count = server ? ent.tbe_srv_nle.nle_nnode :
2844 ent.tbe_cli_nle.nle_nnode;
2846 fprintf(stdout, "Batch or test is empty\n");
2851 rc = lst_alloc_rpcent(&head, count, 0);
2853 fprintf(stderr, "Out of memory\n");
2857 for (i = 0; i < loop; i++) {
2858 time_t now = time(NULL);
2860 if (now - last < delay) {
2861 sleep(delay - now + last);
2867 rc = lst_query_batch_ioctl(batch, test,
2868 server, timeout, &head);
2870 fprintf(stderr, "Failed to query batch: %s\n",
2877 lst_print_tsb_verbose(&head, active, idle, error);
2881 fprintf(stdout, "%s [%d] ", batch, test);
2883 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2884 fprintf(stdout, "%d of %d nodes are unknown, ",
2885 lstcon_rpc_stat_failure(&trans_stat, 0),
2886 lstcon_rpc_stat_total(&trans_stat, 0));
2889 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2890 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2891 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2892 fprintf(stdout, "is stopped\n");
2896 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2897 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2898 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2899 fprintf(stdout, "is running\n");
2903 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2904 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2905 lstcon_tsbqry_stat_run(&trans_stat, 0),
2906 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2909 lst_free_rpcent(&head);
2915 lst_parse_distribute(char *dstr, int *dist, int *span)
2921 dstr = strchr(dstr, ':');
2925 *span = atoi(dstr + 1);
2933 lst_get_bulk_param(int argc, char **argv, lst_test_bulk_param_t *bulk)
2940 bulk->blk_size = 4096;
2941 bulk->blk_opc = LST_BRW_READ;
2942 bulk->blk_flags = LST_BRW_CHECK_NONE;
2945 if (strcasestr(argv[i], "check=") == argv[i] ||
2946 strcasestr(argv[i], "c=") == argv[i]) {
2947 tok = strchr(argv[i], '=') + 1;
2949 if (strcasecmp(tok, "full") == 0) {
2950 bulk->blk_flags = LST_BRW_CHECK_FULL;
2951 } else if (strcasecmp(tok, "simple") == 0) {
2952 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2954 fprintf(stderr, "Unknow flag %s\n", tok);
2958 } else if (strcasestr(argv[i], "size=") == argv[i] ||
2959 strcasestr(argv[i], "s=") == argv[i]) {
2960 tok = strchr(argv[i], '=') + 1;
2962 bulk->blk_size = strtol(tok, &end, 0);
2963 if (bulk->blk_size <= 0) {
2964 fprintf(stderr, "Invalid size %s\n", tok);
2971 if (*end == 'k' || *end == 'K')
2972 bulk->blk_size *= 1024;
2973 else if (*end == 'm' || *end == 'M')
2974 bulk->blk_size *= 1024 * 1024;
2976 if (bulk->blk_size > PAGE_CACHE_SIZE * LNET_MAX_IOV) {
2977 fprintf(stderr, "Size exceed limitation: %d bytes\n",
2982 } else if (strcasecmp(argv[i], "read") == 0 ||
2983 strcasecmp(argv[i], "r") == 0) {
2984 bulk->blk_opc = LST_BRW_READ;
2986 } else if (strcasecmp(argv[i], "write") == 0 ||
2987 strcasecmp(argv[i], "w") == 0) {
2988 bulk->blk_opc = LST_BRW_WRITE;
2991 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
3002 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
3004 lst_test_bulk_param_t *bulk = NULL;
3007 type = lst_test_name2type(test);
3009 fprintf(stderr, "Unknow test name %s\n", test);
3018 bulk = malloc(sizeof(*bulk));
3020 fprintf(stderr, "Out of memory\n");
3024 memset(bulk, 0, sizeof(*bulk));
3026 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
3032 *plen = sizeof(*bulk);
3040 /* TODO: parse more parameter */
3045 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
3046 int dist, int span, char *sgrp, char *dgrp,
3047 void *param, int plen, int *retp, struct list_head *resultp)
3049 lstio_test_args_t args = {0};
3051 args.lstio_tes_key = session_key;
3052 args.lstio_tes_bat_nmlen = strlen(batch);
3053 args.lstio_tes_bat_name = batch;
3054 args.lstio_tes_type = type;
3055 args.lstio_tes_oneside = 0;
3056 args.lstio_tes_loop = loop;
3057 args.lstio_tes_concur = concur;
3058 args.lstio_tes_dist = dist;
3059 args.lstio_tes_span = span;
3060 args.lstio_tes_sgrp_nmlen = strlen(sgrp);
3061 args.lstio_tes_sgrp_name = sgrp;
3062 args.lstio_tes_dgrp_nmlen = strlen(dgrp);
3063 args.lstio_tes_dgrp_name = dgrp;
3064 args.lstio_tes_param_len = plen;
3065 args.lstio_tes_param = param;
3066 args.lstio_tes_retp = retp;
3067 args.lstio_tes_resultp = resultp;
3069 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
3073 jt_lst_add_test(int argc, char **argv)
3075 struct list_head head;
3095 static struct option add_test_opts[] =
3097 {"batch", required_argument, 0, 'b' },
3098 {"concurrency", required_argument, 0, 'c' },
3099 {"distribute", required_argument, 0, 'd' },
3100 {"from", required_argument, 0, 'f' },
3101 {"to", required_argument, 0, 't' },
3102 {"loop", required_argument, 0, 'l' },
3106 if (session_key == 0) {
3108 "Can't find env LST_SESSION or value is not valid\n");
3113 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3114 add_test_opts, &optidx);
3116 /* Detect the end of the options. */
3125 concur = atoi(optarg);
3134 loop = atoi(optarg);
3140 lst_print_usage(argv[0]);
3145 if (optind == argc || from == NULL || to == NULL) {
3146 lst_print_usage(argv[0]);
3150 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3151 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3156 batch = LST_DEFAULT_BATCH;
3159 rc = lst_parse_distribute(dstr, &dist, &span);
3161 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3166 test = argv[optind++];
3171 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3173 fprintf(stderr, "Failed to add test (%s)\n", test);
3177 INIT_LIST_HEAD(&head);
3179 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3181 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3182 from, strerror(errno));
3186 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3188 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3189 to, strerror(errno));
3193 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3195 fprintf(stderr, "Out of memory\n");
3199 rc = lst_add_test_ioctl(batch, type, loop, concur,
3200 dist, span, from, to, param, plen, &ret, &head);
3203 fprintf(stdout, "Test was added successfully\n");
3205 fprintf(stdout, "Server group contains userland test "
3206 "nodes, old version of tcplnd can't accept "
3207 "connection request\n");
3214 lst_print_error("test", "Failed to add test: %s\n",
3219 lst_print_transerr(&head, "add test");
3221 lst_free_rpcent(&head);
3229 static command_t lst_cmdlist[] = {
3230 {"new_session", jt_lst_new_session, NULL,
3231 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3232 {"end_session", jt_lst_end_session, NULL,
3233 "Usage: lst end_session" },
3234 {"show_session", jt_lst_show_session, NULL,
3235 "Usage: lst show_session" },
3236 {"ping", jt_lst_ping , NULL,
3237 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3238 {"add_group", jt_lst_add_group, NULL,
3239 "Usage: lst group NAME IDs [IDs]..." },
3240 {"del_group", jt_lst_del_group, NULL,
3241 "Usage: lst del_group NAME" },
3242 {"update_group", jt_lst_update_group, NULL,
3243 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3244 {"list_group", jt_lst_list_group, NULL,
3245 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3246 {"stat", jt_lst_stat, NULL,
3247 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3248 " [--timeout #] [--delay #] [--count #] GROUP [GROUP]" },
3249 {"show_error", jt_lst_show_error, NULL,
3250 "Usage: lst show_error NAME | IDS ..." },
3251 {"add_batch", jt_lst_add_batch, NULL,
3252 "Usage: lst add_batch NAME" },
3253 {"run", jt_lst_start_batch, NULL,
3254 "Usage: lst run [--timeout TIME] [NAME]" },
3255 {"stop", jt_lst_stop_batch, NULL,
3256 "Usage: lst stop [--force] BATCH_NAME" },
3257 {"list_batch", jt_lst_list_batch, NULL,
3258 "Usage: lst list_batch NAME [--test ID] [--server]" },
3259 {"query", jt_lst_query_batch, NULL,
3260 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3261 {"add_test", jt_lst_add_test, NULL,
3262 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3263 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3264 {"help", Parser_help, 0, "help" },
3269 lst_initialize(void)
3274 feats = getenv("LST_FEATURES");
3276 session_features = strtol(feats, NULL, 16);
3278 if ((session_features & ~LST_FEATS_MASK) != 0) {
3280 "Unsupported session features %x, "
3281 "only support these features so far: %x\n",
3282 (session_features & ~LST_FEATS_MASK), LST_FEATS_MASK);
3286 key = getenv("LST_SESSION");
3293 session_key = atoi(key);
3299 main(int argc, char **argv)
3305 rc = libcfs_arch_init();
3309 rc = lst_initialize();
3313 rc = ptl_initialize(argc, argv);
3317 Parser_init("lst > ", lst_cmdlist);
3320 rc = Parser_execarg(argc - 1, argv + 1, lst_cmdlist);
3327 libcfs_arch_cleanup();