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>
49 #include <sys/ioctl.h>
52 #include <libcfs/util/list.h>
53 #include <libcfs/util/ioctl.h>
54 #include <libcfs/util/parser.h>
55 #include <lnet/lnetctl.h>
56 #include <lnet/lnetst.h>
57 #include <lnet/lnet.h>
58 #include <utils/obdctl.h>
60 lst_sid_t LST_INVALID_SID = {LNET_NID_ANY, -1};
61 static lst_sid_t session_id;
62 static int session_key;
64 /* All nodes running 2.6.50 or later understand feature LST_FEAT_BULK_LEN */
65 static unsigned session_features = LST_FEATS_MASK;
66 static lstcon_trans_stat_t trans_stat;
68 typedef struct list_string {
69 struct list_string *lstr_next;
75 # define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
78 static int alloc_count = 0;
79 static int alloc_nob = 0;
84 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
87 fprintf(stderr, "Can't allocate lstr\n");
94 lstr->lstr_str[0] = 0;
100 free_lstr(lstr_t *lstr)
103 alloc_nob -= lstr->lstr_sz;
108 free_lstrs(lstr_t **list)
112 while ((lstr = *list) != NULL) {
113 *list = lstr->lstr_next;
119 new_lstrs(lstr_t **list, char *prefix, char *postfix,
120 int lo, int hi, int stride)
122 int n1 = strlen(prefix);
123 int n2 = strlen(postfix);
124 int sz = n1 + 20 + n2 + 1;
127 lstr_t *n = alloc_lstr(sz);
129 snprintf(n->lstr_str, sz - 1, "%s%u%s",
130 prefix, lo, postfix);
132 n->lstr_next = *list;
140 expand_lstr(lstr_t **list, lstr_t *l)
142 int nob = strlen(l->lstr_str);
152 b1 = strchr(l->lstr_str, '[');
154 l->lstr_next = *list;
159 b2 = strchr(b1, ']');
160 if (b2 == NULL || b2 == b1 + 1)
168 sep = strchr(expr, ',');
174 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
176 new_lstrs(list, l->lstr_str, b2, x, x, 1);
181 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
184 new_lstrs(list, l->lstr_str, b2, x, y, 1);
189 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
192 new_lstrs(list, l->lstr_str, b2, x, y, z);
198 } while ((expr = sep) != NULL);
206 expand_strs(char *str, lstr_t **head)
214 l = alloc_lstr(strlen(str) + 1);
215 memcpy(l->lstr_str, str, strlen(str) + 1);
223 while ((l = list) != NULL) {
226 rc = expand_lstr(&nlist, l);
228 fprintf(stderr, "Syntax error in \"%s\"\n", str);
236 /* re-order onto 'list' */
237 while ((l = nlist) != NULL) {
238 nlist = l->lstr_next;
243 } while (expanded && rc > 0);
250 while ((l = list) != NULL) {
259 lst_parse_nids(char *str, int *countp, lnet_process_id_t **idspp)
267 rc = expand_strs(str, &head);
277 *idspp = malloc(c * sizeof(lnet_process_id_t));
278 if (*idspp == NULL) {
279 fprintf(stderr, "Out of memory\n");
286 while ((l = head) != NULL) {
290 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
291 if ((*idspp)[i].nid == LNET_NID_ANY) {
292 fprintf(stderr, "Invalid nid: %s\n",
297 (*idspp)[i].pid = LNET_PID_LUSTRE;
314 lst_node_state2str(int state)
316 if (state == LST_NODE_ACTIVE)
318 if (state == LST_NODE_BUSY)
320 if (state == LST_NODE_DOWN)
327 lst_node_str2state(char *str)
329 if (strcasecmp(str, "active") == 0)
330 return LST_NODE_ACTIVE;
331 if (strcasecmp(str, "busy") == 0)
332 return LST_NODE_BUSY;
333 if (strcasecmp(str, "down") == 0)
334 return LST_NODE_DOWN;
335 if (strcasecmp(str, "unknown") == 0)
336 return LST_NODE_UNKNOWN;
337 if (strcasecmp(str, "invalid") == 0)
338 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
344 lst_test_type2name(int type)
346 if (type == LST_TEST_PING)
348 if (type == LST_TEST_BULK)
355 lst_test_name2type(char *name)
357 if (strcasecmp(name, "ping") == 0)
358 return LST_TEST_PING;
359 if (strcasecmp(name, "brw") == 0)
360 return LST_TEST_BULK;
366 lst_print_usage(char *cmd)
368 Parser_printhelp(cmd);
372 lst_print_error(char *sub, const char *def_format, ...)
376 /* local error returned from kernel */
379 fprintf(stderr, "No session exists\n");
382 fprintf(stderr, "Session is shutting down\n");
385 fprintf(stderr, "Unmatched session key or not root\n");
388 fprintf(stderr, "Can't find %s in current session\n", sub);
391 fprintf(stderr, "Invalid parameters list in command line\n");
394 fprintf(stderr, "Bad parameter address\n");
397 fprintf(stderr, "%s already exists\n", sub);
400 va_start(ap, def_format);
401 vfprintf(stderr, def_format, ap);
409 lst_free_rpcent(struct list_head *head)
411 lstcon_rpc_ent_t *ent;
413 while (!list_empty(head)) {
414 ent = list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
416 list_del(&ent->rpe_link);
422 lst_reset_rpcent(struct list_head *head)
424 lstcon_rpc_ent_t *ent;
426 list_for_each_entry(ent, head, rpe_link) {
427 ent->rpe_sid = LST_INVALID_SID;
428 ent->rpe_peer.nid = LNET_NID_ANY;
429 ent->rpe_peer.pid = LNET_PID_ANY;
430 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
435 lst_alloc_rpcent(struct list_head *head, int count, int offset)
437 lstcon_rpc_ent_t *ent;
440 for (i = 0; i < count; i++) {
441 ent = malloc(offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
443 lst_free_rpcent(head);
447 memset(ent, 0, offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
449 ent->rpe_sid = LST_INVALID_SID;
450 ent->rpe_peer.nid = LNET_NID_ANY;
451 ent->rpe_peer.pid = LNET_PID_ANY;
452 list_add(&ent->rpe_link, head);
459 lst_print_transerr(struct list_head *head, char *optstr)
461 lstcon_rpc_ent_t *ent;
463 list_for_each_entry(ent, head, rpe_link) {
464 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
467 if (ent->rpe_rpc_errno != 0) {
468 fprintf(stderr, "%s RPC failed on %s: %s\n",
469 optstr, libcfs_id2str(ent->rpe_peer),
470 strerror(ent->rpe_rpc_errno));
474 fprintf(stderr, "operation %s failed on %s: %s\n",
475 optstr, libcfs_id2str(ent->rpe_peer),
476 strerror(ent->rpe_fwk_errno));
480 int lst_info_batch_ioctl(char *batch, int test, int server,
481 lstcon_test_batch_ent_t *entp, int *idxp,
482 int *ndentp, lstcon_node_ent_t *dentsp);
484 int lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
485 int *idx, int *count, lstcon_node_ent_t *dents);
487 int lst_query_batch_ioctl(char *batch, int test, int server,
488 int timeout, struct list_head *head);
491 lst_ioctl(unsigned int opc, void *buf, int len)
493 struct libcfs_ioctl_data data;
496 LIBCFS_IOC_INIT (data);
497 data.ioc_u32[0] = opc;
498 data.ioc_plen1 = len;
499 data.ioc_pbuf1 = (char *)buf;
500 data.ioc_plen2 = sizeof(trans_stat);
501 data.ioc_pbuf2 = (char *)&trans_stat;
503 memset(&trans_stat, 0, sizeof(trans_stat));
505 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
507 /* local error, no valid RPC result */
512 if (trans_stat.trs_rpc_errno != 0)
515 /* Framework error */
516 if (trans_stat.trs_fwk_errno != 0)
523 lst_new_session_ioctl(char *name, int timeout, int force, lst_sid_t *sid)
525 lstio_session_new_args_t args = {0};
527 args.lstio_ses_key = session_key;
528 args.lstio_ses_timeout = timeout;
529 args.lstio_ses_force = force;
530 args.lstio_ses_idp = sid;
531 args.lstio_ses_feats = session_features;
532 args.lstio_ses_nmlen = strlen(name);
533 args.lstio_ses_namep = name;
535 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
539 jt_lst_new_session(int argc, char **argv)
541 char buf[LST_NAME_SIZE];
549 static struct option session_opts[] =
551 {"timeout", required_argument, 0, 't' },
552 {"force", no_argument, 0, 'f' },
556 if (session_key == 0) {
558 "Can't find env LST_SESSION or value is not valid\n");
564 c = getopt_long(argc, argv, "ft:",
565 session_opts, &optidx);
575 timeout = atoi(optarg);
578 lst_print_usage(argv[0]);
584 fprintf(stderr, "Invalid timeout value\n");
588 if (optind == argc - 1) {
589 name = argv[optind ++];
590 if (strlen(name) >= LST_NAME_SIZE) {
591 fprintf(stderr, "Name size is limited to %d\n",
596 } else if (optind == argc) {
597 char user[LST_NAME_SIZE];
598 char host[LST_NAME_SIZE];
599 struct passwd *pw = getpwuid(getuid());
602 snprintf(user, sizeof(user), "%d", (int)getuid());
604 snprintf(user, sizeof(user), "%s", pw->pw_name);
606 rc = gethostname(host, sizeof(host));
608 snprintf(host, sizeof(host), "unknown_host");
610 snprintf(buf, sizeof(buf), "%s@%s", user, host);
614 lst_print_usage(argv[0]);
618 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
620 lst_print_error("session", "Failed to create session: %s\n",
625 fprintf(stdout, "SESSION: %s FEATURES: %x TIMEOUT: %d FORCE: %s\n",
626 name, session_features, timeout, force ? "Yes" : "No");
631 lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp,
632 lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
634 lstio_session_info_args_t args = {0};
636 args.lstio_ses_idp = sid;
637 args.lstio_ses_keyp = key;
638 args.lstio_ses_featp = featp;
639 args.lstio_ses_ndinfo = ndinfo;
640 args.lstio_ses_nmlen = len;
641 args.lstio_ses_namep = name;
643 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
647 jt_lst_show_session(int argc, char **argv)
649 lstcon_ndlist_ent_t ndinfo;
651 char name[LST_NAME_SIZE];
656 rc = lst_session_info_ioctl(name, sizeof(name), &key,
657 &feats, &sid, &ndinfo);
660 lst_print_error("session", "Failed to show session: %s\n",
665 fprintf(stdout, "%s ID: %ju@%s, KEY: %d FEATURES: %x NODES: %d\n",
666 name, (uintmax_t)sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
667 key, feats, ndinfo.nle_nnode);
673 lst_end_session_ioctl(void)
675 lstio_session_end_args_t args = {0};
677 args.lstio_ses_key = session_key;
678 return lst_ioctl (LSTIO_SESSION_END, &args, sizeof(args));
682 jt_lst_end_session(int argc, char **argv)
686 if (session_key == 0) {
688 "Can't find env LST_SESSION or value is not valid\n");
692 rc = lst_end_session_ioctl();
695 fprintf(stdout, "session is ended\n");
700 lst_print_error("session", "Failed to end session: %s\n",
705 if (trans_stat.trs_rpc_errno != 0) {
707 "[RPC] Failed to send %d session RPCs: %s\n",
708 lstcon_rpc_stat_failure(&trans_stat, 0),
709 strerror(trans_stat.trs_rpc_errno));
712 if (trans_stat.trs_fwk_errno != 0) {
714 "[FWK] Failed to end session on %d nodes: %s\n",
715 lstcon_sesop_stat_failure(&trans_stat, 0),
716 strerror(trans_stat.trs_fwk_errno));
723 lst_ping_ioctl(char *str, int type, int timeout,
724 int count, lnet_process_id_t *ids, struct list_head *head)
726 lstio_debug_args_t args = {0};
728 args.lstio_dbg_key = session_key;
729 args.lstio_dbg_type = type;
730 args.lstio_dbg_flags = 0;
731 args.lstio_dbg_timeout = timeout;
732 args.lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str);
733 args.lstio_dbg_namep = str;
734 args.lstio_dbg_count = count;
735 args.lstio_dbg_idsp = ids;
736 args.lstio_dbg_resultp = head;
738 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
742 lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
744 char buf[LST_NAME_SIZE];
745 lstcon_test_batch_ent_t ent;
746 lstcon_ndlist_ent_t *entp = &ent.tbe_cli_nle;
753 case LST_OPC_SESSION:
754 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
755 &key, &feats, &sid, entp);
758 case LST_OPC_BATCHSRV:
759 entp = &ent.tbe_srv_nle;
760 case LST_OPC_BATCHCLI:
761 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
765 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
769 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
778 *countp = entp->nle_nnode;
784 jt_lst_ping(int argc, char **argv)
786 struct list_head head;
787 lnet_process_id_t *ids = NULL;
788 lstcon_rpc_ent_t *ent = NULL;
798 static struct option ping_opts[] =
800 {"session", no_argument, 0, 's' },
801 {"server", no_argument, 0, 'v' },
802 {"batch", required_argument, 0, 'b' },
803 {"group", required_argument, 0, 'g' },
804 {"nodes", required_argument, 0, 'n' },
805 {"timeout", required_argument, 0, 't' },
809 if (session_key == 0) {
811 "Can't find env LST_SESSION or value is not valid\n");
817 c = getopt_long(argc, argv, "g:b:n:t:sv",
825 type = LST_OPC_SESSION;
829 type = LST_OPC_GROUP;
834 type = LST_OPC_BATCHCLI;
839 type = LST_OPC_NODES;
844 timeout = atoi(optarg);
852 lst_print_usage(argv[0]);
857 if (type == 0 || timeout <= 0 || optind != argc) {
858 lst_print_usage(argv[0]);
862 if (type == LST_OPC_BATCHCLI && server)
863 type = LST_OPC_BATCHSRV;
865 rc = lst_get_node_count(type, str, &count, &ids);
867 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
868 (str == NULL) ? "session" : str, strerror(errno));
872 INIT_LIST_HEAD(&head);
874 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
876 fprintf(stderr, "Out of memory\n");
881 fprintf(stdout, "Target %s is empty\n",
882 (str == NULL) ? "session" : str);
886 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
887 if (rc == -1) { /* local failure */
888 lst_print_error("debug", "Failed to ping %s: %s\n",
889 (str == NULL) ? "session" : str,
895 /* ignore RPC errors and framwork errors */
896 list_for_each_entry(ent, &head, rpe_link) {
897 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
898 libcfs_id2str(ent->rpe_peer),
899 lst_node_state2str(ent->rpe_state),
900 (ent->rpe_state == LST_NODE_ACTIVE ||
901 ent->rpe_state == LST_NODE_BUSY) ?
902 (ent->rpe_rpc_errno == 0 ?
903 &ent->rpe_payload[0] : "Unknown") :
904 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
908 lst_free_rpcent(&head);
918 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
919 unsigned *featp, struct list_head *resultp)
921 lstio_group_nodes_args_t args = {0};
923 args.lstio_grp_key = session_key;
924 args.lstio_grp_nmlen = strlen(name);
925 args.lstio_grp_namep = name;
926 args.lstio_grp_count = count;
927 args.lstio_grp_featp = featp;
928 args.lstio_grp_idsp = ids;
929 args.lstio_grp_resultp = resultp;
931 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
935 lst_del_group_ioctl(char *name)
937 lstio_group_del_args_t args = {0};
939 args.lstio_grp_key = session_key;
940 args.lstio_grp_nmlen = strlen(name);
941 args.lstio_grp_namep = name;
943 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
947 lst_del_group(char *grp_name)
951 rc = lst_del_group_ioctl(grp_name);
953 fprintf(stdout, "Group is deleted\n");
958 lst_print_error("group", "Failed to delete group: %s\n",
963 fprintf(stderr, "Group is deleted with some errors\n");
965 if (trans_stat.trs_rpc_errno != 0) {
967 "[RPC] Failed to send %d end session RPCs: %s\n",
968 lstcon_rpc_stat_failure(&trans_stat, 0),
969 strerror(trans_stat.trs_rpc_errno));
972 if (trans_stat.trs_fwk_errno != 0) {
974 "[FWK] Failed to end session on %d nodes: %s\n",
975 lstcon_sesop_stat_failure(&trans_stat, 0),
976 strerror(trans_stat.trs_fwk_errno));
983 lst_add_group_ioctl (char *name)
985 lstio_group_add_args_t args = {0};
987 args.lstio_grp_key = session_key;
988 args.lstio_grp_nmlen = strlen(name);
989 args.lstio_grp_namep = name;
991 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
995 jt_lst_add_group(int argc, char **argv)
997 struct list_head head;
998 lnet_process_id_t *ids;
1000 unsigned feats = session_features;
1004 bool nodes_added = false;
1006 if (session_key == 0) {
1008 "Can't find env LST_SESSION or value is not valid\n");
1013 lst_print_usage(argv[0]);
1018 if (strlen(name) >= LST_NAME_SIZE) {
1019 fprintf(stderr, "Name length is limited to %d\n",
1024 rc = lst_add_group_ioctl(name);
1026 lst_print_error("group", "Failed to add group %s: %s\n",
1027 name, strerror(errno));
1031 INIT_LIST_HEAD(&head);
1033 for (i = 2; i < argc; i++) {
1034 /* parse address list */
1035 rc = lst_parse_nids(argv[i], &count, &ids);
1037 fprintf(stderr, "Ignore invalid id list %s\n",
1045 rc = lst_alloc_rpcent(&head, count, 0);
1047 fprintf(stderr, "Out of memory\n");
1053 rc = lst_add_nodes_ioctl(name, count, ids, &feats, &head);
1060 fprintf(stdout, "%s are added to session\n", argv[i]);
1064 if ((feats & session_features) != session_features) {
1066 "Warning, this session will run with "
1067 "compatible mode because some test nodes "
1068 "might not understand these features: %x\n",
1069 (~feats & session_features));
1072 lst_free_rpcent(&head);
1077 * The selftest kernel module expects that a group should
1078 * have at least one node, since it doesn't make sense for
1079 * an empty group to be added to a test.
1082 "No nodes added successfully, deleting group %s\n",
1084 rc = lst_del_group(name);
1087 "Failed to delete group %s."
1088 " Group is empty.\n", name);
1096 lst_print_error("group", "Failed to add nodes %s: %s\n",
1097 argv[i], strerror(errno));
1100 if (trans_stat.trs_fwk_errno == EPROTO) {
1102 "test nodes might have different LST "
1103 "features, please disable some features by "
1104 "setting LST_FEATURES\n");
1107 lst_print_transerr(&head, "create session");
1110 lst_free_rpcent(&head);
1114 "No nodes added successfully, deleting group %s\n",
1116 if (lst_del_group(name) != 0) {
1118 "Failed to delete group %s."
1119 " Group is empty.\n", name);
1127 jt_lst_del_group(int argc, char **argv)
1131 if (session_key == 0) {
1133 "Can't find env LST_SESSION or value is not valid\n");
1138 lst_print_usage(argv[0]);
1142 rc = lst_del_group(argv[1]);
1148 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1149 lnet_process_id_t *ids, struct list_head *resultp)
1151 lstio_group_update_args_t args = {0};
1153 args.lstio_grp_key = session_key;
1154 args.lstio_grp_opc = opc;
1155 args.lstio_grp_args = clean;
1156 args.lstio_grp_nmlen = strlen(name);
1157 args.lstio_grp_namep = name;
1158 args.lstio_grp_count = count;
1159 args.lstio_grp_idsp = ids;
1160 args.lstio_grp_resultp = resultp;
1162 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1166 jt_lst_update_group(int argc, char **argv)
1168 struct list_head head;
1169 lnet_process_id_t *ids = NULL;
1179 static struct option update_group_opts[] =
1181 {"refresh", no_argument, 0, 'f' },
1182 {"clean", required_argument, 0, 'c' },
1183 {"remove", required_argument, 0, 'r' },
1187 if (session_key == 0) {
1189 "Can't find env LST_SESSION or value is not valid\n");
1194 c = getopt_long(argc, argv, "fc:r:",
1195 update_group_opts, &optidx);
1197 /* Detect the end of the options. */
1204 lst_print_usage(argv[0]);
1207 opc = LST_GROUP_REFRESH;
1212 lst_print_usage(argv[0]);
1215 opc = LST_GROUP_RMND;
1220 clean = lst_node_str2state(optarg);
1221 if (opc != 0 || clean <= 0) {
1222 lst_print_usage(argv[0]);
1225 opc = LST_GROUP_CLEAN;
1229 lst_print_usage(argv[0]);
1234 /* no OPC or group is specified */
1235 if (opc == 0 || optind != argc - 1) {
1236 lst_print_usage(argv[0]);
1242 INIT_LIST_HEAD(&head);
1244 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1245 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1247 opc == LST_GROUP_RMND ? str : grp,
1251 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1252 opc == LST_GROUP_RMND ? str : grp,
1257 rc = lst_alloc_rpcent(&head, count, 0);
1259 fprintf(stderr, "Out of memory\n");
1266 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1272 lst_free_rpcent(&head);
1277 lst_free_rpcent(&head);
1278 lst_print_error("group", "Failed to update group: %s\n",
1283 lst_print_transerr(&head, "Updating group");
1285 lst_free_rpcent(&head);
1291 lst_list_group_ioctl(int len, char *name, int idx)
1293 lstio_group_list_args_t args = {0};
1295 args.lstio_grp_key = session_key;
1296 args.lstio_grp_idx = idx;
1297 args.lstio_grp_nmlen = len;
1298 args.lstio_grp_namep = name;
1300 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1304 lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
1305 int *idx, int *count, lstcon_node_ent_t *dents)
1307 lstio_group_info_args_t args = {0};
1309 args.lstio_grp_key = session_key;
1310 args.lstio_grp_nmlen = strlen(name);
1311 args.lstio_grp_namep = name;
1312 args.lstio_grp_entp = gent;
1313 args.lstio_grp_idxp = idx;
1314 args.lstio_grp_ndentp = count;
1315 args.lstio_grp_dentsp = dents;
1317 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1321 lst_list_group_all(void)
1323 char name[LST_NAME_SIZE];
1327 /* no group is specified, list name of all groups */
1328 for (i = 0; ; i++) {
1329 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1331 fprintf(stdout, "%d) %s\n", i + 1, name);
1335 if (errno == ENOENT)
1338 lst_print_error("group", "Failed to list group: %s\n",
1343 fprintf(stdout, "Total %d groups\n", i);
1348 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1351 jt_lst_list_group(int argc, char **argv)
1353 lstcon_ndlist_ent_t gent;
1354 lstcon_node_ent_t *dents;
1369 static struct option list_group_opts[] =
1371 {"active", no_argument, 0, 'a' },
1372 {"busy", no_argument, 0, 'b' },
1373 {"down", no_argument, 0, 'd' },
1374 {"unknown", no_argument, 0, 'u' },
1375 {"all", no_argument, 0, 'l' },
1379 if (session_key == 0) {
1381 "Can't find env LST_SESSION or value is not valid\n");
1386 c = getopt_long(argc, argv, "abdul",
1387 list_group_opts, &optidx);
1394 verbose = active = 1;
1406 verbose = unknown = 1;
1413 lst_print_usage(argv[0]);
1418 if (optind == argc) {
1419 /* no group is specified, list name of all groups */
1420 rc = lst_list_group_all();
1426 fprintf(stdout, LST_NODES_TITLE);
1428 /* list nodes in specified groups */
1429 for (i = optind; i < argc; i++) {
1430 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1432 if (errno == ENOENT) {
1437 lst_print_error("group", "Failed to list group\n",
1443 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1444 gent.nle_nactive, gent.nle_nbusy,
1445 gent.nle_ndown, gent.nle_nunknown,
1446 gent.nle_nnode, argv[i]);
1450 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1452 if (gent.nle_nnode == 0) {
1453 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1457 count = gent.nle_nnode;
1459 dents = malloc(count * sizeof(lstcon_node_ent_t));
1460 if (dents == NULL) {
1461 fprintf(stderr, "Failed to malloc: %s\n",
1467 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1469 lst_print_error("group", "Failed to list group: %s\n",
1475 for (j = 0, c = 0; j < count; j++) {
1477 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1478 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1479 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1480 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1482 fprintf(stdout, "\t%s: %s\n",
1483 libcfs_id2str(dents[j].nde_id),
1484 lst_node_state2str(dents[j].nde_state));
1489 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1498 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
1499 int timeout, struct list_head *resultp)
1501 lstio_stat_args_t args = {0};
1503 args.lstio_sta_key = session_key;
1504 args.lstio_sta_timeout = timeout;
1505 args.lstio_sta_nmlen = strlen(name);
1506 args.lstio_sta_namep = name;
1507 args.lstio_sta_count = count;
1508 args.lstio_sta_idsp = idsp;
1509 args.lstio_sta_resultp = resultp;
1511 return lst_ioctl(LSTIO_STAT_QUERY, &args, sizeof(args));
1515 struct list_head srp_link;
1518 lnet_process_id_t *srp_ids;
1519 struct list_head srp_result[2];
1520 } lst_stat_req_param_t;
1523 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1527 for (i = 0; i < 2; i++)
1528 lst_free_rpcent(&srp->srp_result[i]);
1530 if (srp->srp_ids != NULL)
1537 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
1539 lst_stat_req_param_t *srp = NULL;
1540 int count = save_old ? 2 : 1;
1544 srp = malloc(sizeof(*srp));
1548 memset(srp, 0, sizeof(*srp));
1549 INIT_LIST_HEAD(&srp->srp_result[0]);
1550 INIT_LIST_HEAD(&srp->srp_result[1]);
1552 rc = lst_get_node_count(LST_OPC_GROUP, name,
1553 &srp->srp_count, NULL);
1554 if (rc != 0 && errno == ENOENT) {
1555 rc = lst_get_node_count(LST_OPC_NODES, name,
1556 &srp->srp_count, &srp->srp_ids);
1561 "Failed to get count of nodes from %s: %s\n",
1562 name, strerror(errno));
1563 lst_stat_req_param_free(srp);
1568 srp->srp_name = name;
1570 for (i = 0; i < count; i++) {
1571 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1572 sizeof(sfw_counters_t) +
1573 sizeof(srpc_counters_t) +
1574 sizeof(lnet_counters_t));
1576 fprintf(stderr, "Out of memory\n");
1586 lst_stat_req_param_free(srp);
1594 } lst_srpc_stat_result;
1596 #define LST_LNET_AVG 0
1597 #define LST_LNET_MIN 1
1598 #define LST_LNET_MAX 2
1601 float lnet_avg_sndrate;
1602 float lnet_min_sndrate;
1603 float lnet_max_sndrate;
1604 float lnet_total_sndrate;
1606 float lnet_avg_rcvrate;
1607 float lnet_min_rcvrate;
1608 float lnet_max_rcvrate;
1609 float lnet_total_rcvrate;
1611 float lnet_avg_sndperf;
1612 float lnet_min_sndperf;
1613 float lnet_max_sndperf;
1614 float lnet_total_sndperf;
1616 float lnet_avg_rcvperf;
1617 float lnet_min_rcvperf;
1618 float lnet_max_rcvperf;
1619 float lnet_total_rcvperf;
1621 int lnet_stat_count;
1622 } lst_lnet_stat_result_t;
1624 lst_lnet_stat_result_t lnet_stat_result;
1627 lst_lnet_stat_value(int bw, int send, int off)
1631 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1632 &lnet_stat_result.lnet_avg_sndrate;
1643 lst_timeval_diff(struct timeval *tv1,
1644 struct timeval *tv2, struct timeval *df)
1646 if (tv1->tv_usec >= tv2->tv_usec) {
1647 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1648 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1652 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1653 df->tv_usec = tv1->tv_usec + 1000000 - tv2->tv_usec;
1659 lst_cal_lnet_stat(float delta, lnet_counters_t *lnet_new,
1660 lnet_counters_t *lnet_old, int mbs)
1664 unsigned int unit_divisor;
1666 unit_divisor = (mbs) ? (1000 * 1000) : (1024 * 1024);
1667 perf = (float)(lnet_new->send_length -
1668 lnet_old->send_length) / unit_divisor / delta;
1669 lnet_stat_result.lnet_total_sndperf += perf;
1671 if (lnet_stat_result.lnet_min_sndperf > perf ||
1672 lnet_stat_result.lnet_min_sndperf == 0)
1673 lnet_stat_result.lnet_min_sndperf = perf;
1675 if (lnet_stat_result.lnet_max_sndperf < perf)
1676 lnet_stat_result.lnet_max_sndperf = perf;
1678 perf = (float)(lnet_new->recv_length -
1679 lnet_old->recv_length) / unit_divisor / delta;
1680 lnet_stat_result.lnet_total_rcvperf += perf;
1682 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1683 lnet_stat_result.lnet_min_rcvperf == 0)
1684 lnet_stat_result.lnet_min_rcvperf = perf;
1686 if (lnet_stat_result.lnet_max_rcvperf < perf)
1687 lnet_stat_result.lnet_max_rcvperf = perf;
1689 rate = (lnet_new->send_count - lnet_old->send_count) / delta;
1690 lnet_stat_result.lnet_total_sndrate += rate;
1692 if (lnet_stat_result.lnet_min_sndrate > rate ||
1693 lnet_stat_result.lnet_min_sndrate == 0)
1694 lnet_stat_result.lnet_min_sndrate = rate;
1696 if (lnet_stat_result.lnet_max_sndrate < rate)
1697 lnet_stat_result.lnet_max_sndrate = rate;
1699 rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
1700 lnet_stat_result.lnet_total_rcvrate += rate;
1702 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1703 lnet_stat_result.lnet_min_rcvrate == 0)
1704 lnet_stat_result.lnet_min_rcvrate = rate;
1706 if (lnet_stat_result.lnet_max_rcvrate < rate)
1707 lnet_stat_result.lnet_max_rcvrate = rate;
1709 lnet_stat_result.lnet_stat_count++;
1711 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1712 lnet_stat_result.lnet_stat_count;
1713 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1714 lnet_stat_result.lnet_stat_count;
1716 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1717 lnet_stat_result.lnet_stat_count;
1718 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1719 lnet_stat_result.lnet_stat_count;
1723 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type, int mbs)
1733 if (lnet_stat_result.lnet_stat_count == 0)
1736 units = (mbs) ? "MB/s " : "MiB/s ";
1738 if (bwrt == 1) /* bw only */
1741 if (bwrt == 2) /* rates only */
1744 if (rdwr == 1) /* recv only */
1747 if (rdwr == 2) /* send only */
1750 for (i = start1; i <= end1; i++) {
1751 fprintf(stdout, "[LNet %s of %s]\n",
1752 i == 0 ? "Rates" : "Bandwidth", name);
1754 for (j = start2; j <= end2; j++) {
1755 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
1757 if ((type & 1) != 0) {
1758 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1760 lst_lnet_stat_value(i, j, 0), units);
1763 if ((type & 2) != 0) {
1764 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1766 lst_lnet_stat_value(i, j, 1), units);
1769 if ((type & 4) != 0) {
1770 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1772 lst_lnet_stat_value(i, j, 2), units);
1775 fprintf(stdout, "\n");
1781 lst_print_stat(char *name, struct list_head *resultp,
1782 int idx, int lnet, int bwrt, int rdwr, int type,
1785 struct list_head tmp[2];
1786 lstcon_rpc_ent_t *new;
1787 lstcon_rpc_ent_t *old;
1788 sfw_counters_t *sfwk_new;
1789 sfw_counters_t *sfwk_old;
1790 srpc_counters_t *srpc_new;
1791 srpc_counters_t *srpc_old;
1792 lnet_counters_t *lnet_new;
1793 lnet_counters_t *lnet_old;
1797 INIT_LIST_HEAD(&tmp[0]);
1798 INIT_LIST_HEAD(&tmp[1]);
1800 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1802 while (!list_empty(&resultp[idx])) {
1803 if (list_empty(&resultp[1 - idx])) {
1804 fprintf(stderr, "Group is changed, re-run stat\n");
1808 new = list_entry(resultp[idx].next, lstcon_rpc_ent_t,
1810 old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t,
1813 /* first time get stats result, can't calculate diff */
1814 if (new->rpe_peer.nid == LNET_NID_ANY)
1817 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1818 new->rpe_peer.pid != old->rpe_peer.pid) {
1819 /* Something wrong. i.e, somebody change the group */
1823 list_del(&new->rpe_link);
1824 list_add_tail(&new->rpe_link, &tmp[idx]);
1826 list_del(&old->rpe_link);
1827 list_add_tail(&old->rpe_link, &tmp[1 - idx]);
1829 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1830 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1835 sfwk_new = (sfw_counters_t *)&new->rpe_payload[0];
1836 sfwk_old = (sfw_counters_t *)&old->rpe_payload[0];
1838 srpc_new = (srpc_counters_t *)((char *)sfwk_new + sizeof(*sfwk_new));
1839 srpc_old = (srpc_counters_t *)((char *)sfwk_old + sizeof(*sfwk_old));
1841 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
1842 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
1844 /* Prior to version 2.3, the running_ms field was a counter for
1845 * the number of running tests. We are looking at this value
1846 * to determine if it is a millisecond timestamep (>= 2.3) or a
1847 * test counter (< 2.3). The number 500 is being used for this
1848 * barrier as the test counter should never get this high, and
1849 * the timestamp should never get this low. */
1851 if (sfwk_new->running_ms > 500) {
1852 /* use the timestamp from the remote node, not our
1853 * rpe_stamp from when we copied up the data out of
1856 delta = (float) (sfwk_new->running_ms -
1857 sfwk_old->running_ms) / 1000;
1861 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1862 delta = tv.tv_sec + (float)tv.tv_usec / 1000000;
1865 if (!lnet) /* TODO */
1868 lst_cal_lnet_stat(delta, lnet_new, lnet_old, mbs);
1871 list_splice(&tmp[idx], &resultp[idx]);
1872 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1875 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1877 if (!lnet) /* TODO */
1880 lst_print_lnet_stat(name, bwrt, rdwr, type, mbs);
1884 jt_lst_stat(int argc, char **argv)
1886 struct list_head head;
1887 lst_stat_req_param_t *srp;
1890 int timeout = 5; /* default timeout, 5 sec */
1891 int delay = 5; /* default delay, 5 sec */
1892 int count = -1; /* run forever */
1893 int lnet = 1; /* lnet stat by default */
1900 int mbs = 0; /* report as MB/s */
1902 static struct option stat_opts[] = {
1903 {"timeout" , required_argument, 0, 't' },
1904 {"delay" , required_argument, 0, 'd' },
1905 {"count" , required_argument, 0, 'o' },
1906 {"lnet" , no_argument, 0, 'l' },
1907 {"rpc" , no_argument, 0, 'c' },
1908 {"bw" , no_argument, 0, 'b' },
1909 {"rate" , no_argument, 0, 'a' },
1910 {"read" , no_argument, 0, 'r' },
1911 {"write" , no_argument, 0, 'w' },
1912 {"avg" , no_argument, 0, 'g' },
1913 {"min" , no_argument, 0, 'n' },
1914 {"max" , no_argument, 0, 'x' },
1915 {"mbs" , no_argument, 0, 'm' },
1919 if (session_key == 0) {
1921 "Can't find env LST_SESSION or value is not valid\n");
1926 c = getopt_long(argc, argv, "t:d:lcbarwgnxm", stat_opts,
1934 timeout = atoi(optarg);
1937 delay = atoi(optarg);
1940 count = atoi(optarg);
1986 lst_print_usage(argv[0]);
1991 if (optind == argc) {
1992 lst_print_usage(argv[0]);
1996 if (timeout <= 0 || delay <= 0) {
1997 fprintf(stderr, "Invalid timeout or delay value\n");
2002 fprintf(stderr, "Invalid count value\n");
2006 /* extra count to get first data point */
2010 INIT_LIST_HEAD(&head);
2012 while (optind < argc) {
2013 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
2017 list_add_tail(&srp->srp_link, &head);
2021 time_t now = time(NULL);
2023 if (now - last < delay) {
2024 sleep(delay - now + last);
2029 list_for_each_entry(srp, &head, srp_link) {
2030 rc = lst_stat_ioctl(srp->srp_name,
2031 srp->srp_count, srp->srp_ids,
2032 timeout, &srp->srp_result[idx]);
2034 lst_print_error("stat", "Failed to stat %s: %s\n",
2035 srp->srp_name, strerror(errno));
2039 lst_print_stat(srp->srp_name, srp->srp_result,
2040 idx, lnet, bwrt, rdwr, type, mbs);
2042 lst_reset_rpcent(&srp->srp_result[1 - idx]);
2049 } while (count == -1 || count > 0);
2052 while (!list_empty(&head)) {
2053 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2055 list_del(&srp->srp_link);
2056 lst_stat_req_param_free(srp);
2063 jt_lst_show_error(int argc, char **argv)
2065 struct list_head head;
2066 lst_stat_req_param_t *srp;
2067 lstcon_rpc_ent_t *ent;
2068 sfw_counters_t *sfwk;
2069 srpc_counters_t *srpc;
2076 static struct option show_error_opts[] =
2078 {"session", no_argument, 0, 's' },
2082 if (session_key == 0) {
2084 "Can't find env LST_SESSION or value is not valid\n");
2089 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
2100 lst_print_usage(argv[0]);
2105 if (optind == argc) {
2106 lst_print_usage(argv[0]);
2110 INIT_LIST_HEAD(&head);
2112 while (optind < argc) {
2113 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
2117 list_add_tail(&srp->srp_link, &head);
2120 list_for_each_entry(srp, &head, srp_link) {
2121 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
2122 srp->srp_ids, 10, &srp->srp_result[0]);
2125 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2126 srp->srp_name, strerror(errno));
2130 fprintf(stdout, "%s:\n", srp->srp_name);
2134 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2135 if (ent->rpe_rpc_errno != 0) {
2137 fprintf(stderr, "RPC failure, can't show error on %s\n",
2138 libcfs_id2str(ent->rpe_peer));
2142 if (ent->rpe_fwk_errno != 0) {
2144 fprintf(stderr, "Framework failure, can't show error on %s\n",
2145 libcfs_id2str(ent->rpe_peer));
2149 sfwk = (sfw_counters_t *)&ent->rpe_payload[0];
2150 srpc = (srpc_counters_t *)((char *)sfwk + sizeof(*sfwk));
2152 if (srpc->errors == 0 &&
2153 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2157 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2162 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2163 libcfs_id2str(ent->rpe_peer),
2164 sfwk->brw_errors, sfwk->ping_errors,
2165 show_rpc ? ' ' : '\n');
2170 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2171 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2174 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2177 while (!list_empty(&head)) {
2178 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2180 list_del(&srp->srp_link);
2181 lst_stat_req_param_free(srp);
2188 lst_add_batch_ioctl (char *name)
2190 lstio_batch_add_args_t args = {0};
2192 args.lstio_bat_key = session_key;
2193 args.lstio_bat_nmlen = strlen(name);
2194 args.lstio_bat_namep = name;
2196 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2200 jt_lst_add_batch(int argc, char **argv)
2205 if (session_key == 0) {
2207 "Can't find env LST_SESSION or value is not valid\n");
2212 lst_print_usage(argv[0]);
2217 if (strlen(name) >= LST_NAME_SIZE) {
2218 fprintf(stderr, "Name length is limited to %d\n",
2223 rc = lst_add_batch_ioctl(name);
2227 lst_print_error("batch", "Failed to create batch: %s\n",
2234 lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp)
2236 lstio_batch_run_args_t args = {0};
2238 args.lstio_bat_key = session_key;
2239 args.lstio_bat_timeout = timeout;
2240 args.lstio_bat_nmlen = strlen(name);
2241 args.lstio_bat_namep = name;
2242 args.lstio_bat_resultp = resultp;
2244 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2248 jt_lst_start_batch(int argc, char **argv)
2250 struct list_head head;
2258 static struct option start_batch_opts[] =
2260 {"timeout", required_argument, 0, 't' },
2264 if (session_key == 0) {
2266 "Can't find env LST_SESSION or value is not valid\n");
2271 c = getopt_long(argc, argv, "t:",
2272 start_batch_opts, &optidx);
2274 /* Detect the end of the options. */
2280 timeout = atoi(optarg);
2283 lst_print_usage(argv[0]);
2288 if (optind == argc) {
2289 batch = LST_DEFAULT_BATCH;
2291 } else if (optind == argc - 1) {
2292 batch = argv[optind];
2295 lst_print_usage(argv[0]);
2299 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2301 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2302 batch, strerror(errno));
2306 INIT_LIST_HEAD(&head);
2308 rc = lst_alloc_rpcent(&head, count, 0);
2310 fprintf(stderr, "Out of memory\n");
2314 rc = lst_start_batch_ioctl(batch, timeout, &head);
2317 fprintf(stdout, "%s is running now\n", batch);
2318 lst_free_rpcent(&head);
2323 lst_print_error("batch", "Failed to start batch: %s\n",
2325 lst_free_rpcent(&head);
2329 lst_print_transerr(&head, "Run batch");
2331 lst_free_rpcent(&head);
2337 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2339 lstio_batch_stop_args_t args = {0};
2341 args.lstio_bat_key = session_key;
2342 args.lstio_bat_force = force;
2343 args.lstio_bat_nmlen = strlen(name);
2344 args.lstio_bat_namep = name;
2345 args.lstio_bat_resultp = resultp;
2347 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2351 jt_lst_stop_batch(int argc, char **argv)
2353 struct list_head head;
2361 static struct option stop_batch_opts[] =
2363 {"force", no_argument, 0, 'f' },
2367 if (session_key == 0) {
2369 "Can't find env LST_SESSION or value is not valid\n");
2374 c = getopt_long(argc, argv, "f",
2375 stop_batch_opts, &optidx);
2377 /* Detect the end of the options. */
2386 lst_print_usage(argv[0]);
2391 if (optind == argc) {
2392 batch = LST_DEFAULT_BATCH;
2394 } else if (optind == argc - 1) {
2395 batch = argv[optind];
2398 lst_print_usage(argv[0]);
2402 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2404 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2405 batch, strerror(errno));
2409 INIT_LIST_HEAD(&head);
2411 rc = lst_alloc_rpcent(&head, count, 0);
2413 fprintf(stderr, "Out of memory\n");
2417 rc = lst_stop_batch_ioctl(batch, force, &head);
2422 lst_reset_rpcent(&head);
2424 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2428 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2429 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2432 fprintf(stdout, "%d batch in stopping\n",
2433 lstcon_tsbqry_stat_run(&trans_stat, 0));
2437 fprintf(stdout, "Batch is stopped\n");
2438 lst_free_rpcent(&head);
2443 lst_print_error("batch", "Failed to stop batch: %s\n",
2445 lst_free_rpcent(&head);
2449 lst_print_transerr(&head, "stop batch");
2451 lst_free_rpcent(&head);
2457 lst_list_batch_ioctl(int len, char *name, int index)
2459 lstio_batch_list_args_t args = {0};
2461 args.lstio_bat_key = session_key;
2462 args.lstio_bat_idx = index;
2463 args.lstio_bat_nmlen = len;
2464 args.lstio_bat_namep = name;
2466 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2470 lst_info_batch_ioctl(char *batch, int test, int server,
2471 lstcon_test_batch_ent_t *entp, int *idxp,
2472 int *ndentp, lstcon_node_ent_t *dentsp)
2474 lstio_batch_info_args_t args = {0};
2476 args.lstio_bat_key = session_key;
2477 args.lstio_bat_nmlen = strlen(batch);
2478 args.lstio_bat_namep = batch;
2479 args.lstio_bat_server = server;
2480 args.lstio_bat_testidx = test;
2481 args.lstio_bat_entp = entp;
2482 args.lstio_bat_idxp = idxp;
2483 args.lstio_bat_ndentp = ndentp;
2484 args.lstio_bat_dentsp = dentsp;
2486 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2490 lst_list_batch_all(void)
2492 char name[LST_NAME_SIZE];
2496 for (i = 0; ; i++) {
2497 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2499 fprintf(stdout, "%d) %s\n", i + 1, name);
2503 if (errno == ENOENT)
2506 lst_print_error("batch", "Failed to list batch: %s\n",
2511 fprintf(stdout, "Total %d batches\n", i);
2517 lst_list_tsb_nodes(char *batch, int test, int server,
2518 int count, int active, int invalid)
2520 lstcon_node_ent_t *dents;
2529 /* verbose list, show nodes in batch or test */
2530 dents = malloc(count * sizeof(lstcon_node_ent_t));
2531 if (dents == NULL) {
2532 fprintf(stdout, "Can't allocate memory\n");
2536 rc = lst_info_batch_ioctl(batch, test, server,
2537 NULL, &index, &count, dents);
2540 lst_print_error((test > 0) ? "test" : "batch",
2541 (test > 0) ? "Failed to query test: %s\n" :
2542 "Failed to query batch: %s\n",
2547 for (i = 0, c = 0; i < count; i++) {
2548 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2549 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2550 dents[i].nde_state == LST_NODE_DOWN ||
2551 dents[i].nde_state == LST_NODE_UNKNOWN)))
2554 fprintf(stdout, "\t%s: %s\n",
2555 libcfs_id2str(dents[i].nde_id),
2556 lst_node_state2str(dents[i].nde_state));
2560 fprintf(stdout, "Total %d nodes\n", c);
2567 jt_lst_list_batch(int argc, char **argv)
2569 lstcon_test_batch_ent_t ent;
2572 int verbose = 0; /* list nodes in batch or test */
2581 static struct option list_batch_opts[] =
2583 {"test", required_argument, 0, 't' },
2584 {"invalid", no_argument, 0, 'i' },
2585 {"active", no_argument, 0, 'a' },
2586 {"all", no_argument, 0, 'l' },
2587 {"server", no_argument, 0, 's' },
2591 if (session_key == 0) {
2593 "Can't find env LST_SESSION or value is not valid\n");
2598 c = getopt_long(argc, argv, "ailst:",
2599 list_batch_opts, &optidx);
2606 verbose = active = 1;
2609 verbose = invalid = 1;
2612 verbose = active = invalid = 1;
2618 test = atoi(optarg);
2622 lst_print_usage(argv[0]);
2627 if (optind == argc) {
2628 /* list all batches */
2629 rc = lst_list_batch_all();
2633 if (ntest == 1 && test <= 0) {
2634 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2638 if (optind != argc - 1) {
2639 lst_print_usage(argv[0]);
2643 batch = argv[optind];
2646 /* show detail of specified batch or test */
2647 rc = lst_info_batch_ioctl(batch, test, server,
2648 &ent, NULL, NULL, NULL);
2650 lst_print_error((test > 0) ? "test" : "batch",
2651 (test > 0) ? "Failed to query test: %s\n" :
2652 "Failed to query batch: %s\n",
2658 /* list nodes in test or batch */
2659 rc = lst_list_tsb_nodes(batch, test, server,
2660 server ? ent.tbe_srv_nle.nle_nnode :
2661 ent.tbe_cli_nle.nle_nnode,
2666 /* only show number of hosts in batch or test */
2668 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2669 batch, ent.u.tbe_batch.bae_ntest,
2670 ent.u.tbe_batch.bae_state);
2671 ntest = ent.u.tbe_batch.bae_ntest;
2672 test = 1; /* starting from test 1 */
2676 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2677 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2678 ent.u.tbe_test.tse_loop,
2679 ent.u.tbe_test.tse_concur);
2684 fprintf(stdout, LST_NODES_TITLE);
2685 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2686 "server\t%d\t%d\t%d\t%d\t%d\n",
2687 ent.tbe_cli_nle.nle_nactive,
2688 ent.tbe_cli_nle.nle_nbusy,
2689 ent.tbe_cli_nle.nle_ndown,
2690 ent.tbe_cli_nle.nle_nunknown,
2691 ent.tbe_cli_nle.nle_nnode,
2692 ent.tbe_srv_nle.nle_nactive,
2693 ent.tbe_srv_nle.nle_nbusy,
2694 ent.tbe_srv_nle.nle_ndown,
2695 ent.tbe_srv_nle.nle_nunknown,
2696 ent.tbe_srv_nle.nle_nnode);
2705 lst_query_batch_ioctl(char *batch, int test, int server,
2706 int timeout, struct list_head *head)
2708 lstio_batch_query_args_t args = {0};
2710 args.lstio_bat_key = session_key;
2711 args.lstio_bat_testidx = test;
2712 args.lstio_bat_client = !(server);
2713 args.lstio_bat_timeout = timeout;
2714 args.lstio_bat_nmlen = strlen(batch);
2715 args.lstio_bat_namep = batch;
2716 args.lstio_bat_resultp = head;
2718 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2722 lst_print_tsb_verbose(struct list_head *head,
2723 int active, int idle, int error)
2725 lstcon_rpc_ent_t *ent;
2727 list_for_each_entry(ent, head, rpe_link) {
2728 if (ent->rpe_priv[0] == 0 && active)
2731 if (ent->rpe_priv[0] != 0 && idle)
2734 if (ent->rpe_fwk_errno == 0 && error)
2737 fprintf(stdout, "%s [%s]: %s\n",
2738 libcfs_id2str(ent->rpe_peer),
2739 lst_node_state2str(ent->rpe_state),
2740 ent->rpe_rpc_errno != 0 ?
2741 strerror(ent->rpe_rpc_errno) :
2742 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2747 jt_lst_query_batch(int argc, char **argv)
2749 lstcon_test_batch_ent_t ent;
2750 struct list_head head;
2756 int timeout = 5; /* default 5 seconds */
2757 int delay = 5; /* default 5 seconds */
2758 int loop = 1; /* default 1 loop */
2768 static struct option query_batch_opts[] =
2770 {"timeout", required_argument, 0, 'o' },
2771 {"delay", required_argument, 0, 'd' },
2772 {"loop", required_argument, 0, 'c' },
2773 {"test", required_argument, 0, 't' },
2774 {"server", no_argument, 0, 's' },
2775 {"active", no_argument, 0, 'a' },
2776 {"idle", no_argument, 0, 'i' },
2777 {"error", no_argument, 0, 'e' },
2778 {"all", no_argument, 0, 'l' },
2782 if (session_key == 0) {
2784 "Can't find env LST_SESSION or value is not valid\n");
2789 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2790 query_batch_opts, &optidx);
2792 /* Detect the end of the options. */
2798 timeout = atoi(optarg);
2801 delay = atoi(optarg);
2804 loop = atoi(optarg);
2807 test = atoi(optarg);
2813 active = verbose = 1;
2819 error = verbose = 1;
2825 lst_print_usage(argv[0]);
2830 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2831 lst_print_usage(argv[0]);
2835 if (optind == argc) {
2836 batch = LST_DEFAULT_BATCH;
2838 } else if (optind == argc - 1) {
2839 batch = argv[optind];
2842 lst_print_usage(argv[0]);
2847 INIT_LIST_HEAD(&head);
2850 rc = lst_info_batch_ioctl(batch, test, server,
2851 &ent, NULL, NULL, NULL);
2853 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2854 batch, test, strerror(errno));
2858 count = server ? ent.tbe_srv_nle.nle_nnode :
2859 ent.tbe_cli_nle.nle_nnode;
2861 fprintf(stdout, "Batch or test is empty\n");
2866 rc = lst_alloc_rpcent(&head, count, 0);
2868 fprintf(stderr, "Out of memory\n");
2872 for (i = 0; i < loop; i++) {
2873 time_t now = time(NULL);
2875 if (now - last < delay) {
2876 sleep(delay - now + last);
2882 rc = lst_query_batch_ioctl(batch, test,
2883 server, timeout, &head);
2885 fprintf(stderr, "Failed to query batch: %s\n",
2892 lst_print_tsb_verbose(&head, active, idle, error);
2896 fprintf(stdout, "%s [%d] ", batch, test);
2898 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2899 fprintf(stdout, "%d of %d nodes are unknown, ",
2900 lstcon_rpc_stat_failure(&trans_stat, 0),
2901 lstcon_rpc_stat_total(&trans_stat, 0));
2904 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2905 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2906 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2907 fprintf(stdout, "is stopped\n");
2911 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2912 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2913 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2914 fprintf(stdout, "is running\n");
2918 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2919 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2920 lstcon_tsbqry_stat_run(&trans_stat, 0),
2921 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2924 lst_free_rpcent(&head);
2930 lst_parse_distribute(char *dstr, int *dist, int *span)
2936 dstr = strchr(dstr, ':');
2940 *span = atoi(dstr + 1);
2948 lst_get_bulk_param(int argc, char **argv, lst_test_bulk_param_t *bulk)
2955 bulk->blk_size = 4096;
2956 bulk->blk_opc = LST_BRW_READ;
2957 bulk->blk_flags = LST_BRW_CHECK_NONE;
2960 if (strcasestr(argv[i], "check=") == argv[i] ||
2961 strcasestr(argv[i], "c=") == argv[i]) {
2962 tok = strchr(argv[i], '=') + 1;
2964 if (strcasecmp(tok, "full") == 0) {
2965 bulk->blk_flags = LST_BRW_CHECK_FULL;
2966 } else if (strcasecmp(tok, "simple") == 0) {
2967 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2969 fprintf(stderr, "Unknow flag %s\n", tok);
2973 } else if (strcasestr(argv[i], "size=") == argv[i] ||
2974 strcasestr(argv[i], "s=") == argv[i]) {
2975 int max_size = sysconf(_SC_PAGESIZE) * LNET_MAX_IOV;
2977 tok = strchr(argv[i], '=') + 1;
2979 bulk->blk_size = strtol(tok, &end, 0);
2980 if (bulk->blk_size <= 0) {
2981 fprintf(stderr, "Invalid size %s\n", tok);
2988 if (*end == 'k' || *end == 'K')
2989 bulk->blk_size *= 1024;
2990 else if (*end == 'm' || *end == 'M')
2991 bulk->blk_size *= 1024 * 1024;
2993 if (bulk->blk_size > max_size) {
2994 fprintf(stderr, "Size exceed limitation: %d bytes\n",
2999 } else if (strcasecmp(argv[i], "read") == 0 ||
3000 strcasecmp(argv[i], "r") == 0) {
3001 bulk->blk_opc = LST_BRW_READ;
3003 } else if (strcasecmp(argv[i], "write") == 0 ||
3004 strcasecmp(argv[i], "w") == 0) {
3005 bulk->blk_opc = LST_BRW_WRITE;
3008 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
3019 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
3021 lst_test_bulk_param_t *bulk = NULL;
3024 type = lst_test_name2type(test);
3026 fprintf(stderr, "Unknow test name %s\n", test);
3035 bulk = malloc(sizeof(*bulk));
3037 fprintf(stderr, "Out of memory\n");
3041 memset(bulk, 0, sizeof(*bulk));
3043 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
3049 *plen = sizeof(*bulk);
3057 /* TODO: parse more parameter */
3062 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
3063 int dist, int span, char *sgrp, char *dgrp,
3064 void *param, int plen, int *retp, struct list_head *resultp)
3066 lstio_test_args_t args = {0};
3068 args.lstio_tes_key = session_key;
3069 args.lstio_tes_bat_nmlen = strlen(batch);
3070 args.lstio_tes_bat_name = batch;
3071 args.lstio_tes_type = type;
3072 args.lstio_tes_oneside = 0;
3073 args.lstio_tes_loop = loop;
3074 args.lstio_tes_concur = concur;
3075 args.lstio_tes_dist = dist;
3076 args.lstio_tes_span = span;
3077 args.lstio_tes_sgrp_nmlen = strlen(sgrp);
3078 args.lstio_tes_sgrp_name = sgrp;
3079 args.lstio_tes_dgrp_nmlen = strlen(dgrp);
3080 args.lstio_tes_dgrp_name = dgrp;
3081 args.lstio_tes_param_len = plen;
3082 args.lstio_tes_param = param;
3083 args.lstio_tes_retp = retp;
3084 args.lstio_tes_resultp = resultp;
3086 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
3090 jt_lst_add_test(int argc, char **argv)
3092 struct list_head head;
3112 static struct option add_test_opts[] =
3114 {"batch", required_argument, 0, 'b' },
3115 {"concurrency", required_argument, 0, 'c' },
3116 {"distribute", required_argument, 0, 'd' },
3117 {"from", required_argument, 0, 'f' },
3118 {"to", required_argument, 0, 't' },
3119 {"loop", required_argument, 0, 'l' },
3123 if (session_key == 0) {
3125 "Can't find env LST_SESSION or value is not valid\n");
3130 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3131 add_test_opts, &optidx);
3133 /* Detect the end of the options. */
3142 concur = atoi(optarg);
3151 loop = atoi(optarg);
3157 lst_print_usage(argv[0]);
3162 if (optind == argc || from == NULL || to == NULL) {
3163 lst_print_usage(argv[0]);
3167 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3168 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3173 batch = LST_DEFAULT_BATCH;
3176 rc = lst_parse_distribute(dstr, &dist, &span);
3178 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3183 test = argv[optind++];
3188 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3190 fprintf(stderr, "Failed to add test (%s)\n", test);
3194 INIT_LIST_HEAD(&head);
3196 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3198 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3199 from, strerror(errno));
3203 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3205 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3206 to, strerror(errno));
3210 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3212 fprintf(stderr, "Out of memory\n");
3216 rc = lst_add_test_ioctl(batch, type, loop, concur,
3217 dist, span, from, to, param, plen, &ret, &head);
3220 fprintf(stdout, "Test was added successfully\n");
3222 fprintf(stdout, "Server group contains userland test "
3223 "nodes, old version of tcplnd can't accept "
3224 "connection request\n");
3231 lst_print_error("test", "Failed to add test: %s\n",
3236 lst_print_transerr(&head, "add test");
3238 lst_free_rpcent(&head);
3246 static command_t lst_cmdlist[] = {
3247 {"new_session", jt_lst_new_session, NULL,
3248 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3249 {"end_session", jt_lst_end_session, NULL,
3250 "Usage: lst end_session" },
3251 {"show_session", jt_lst_show_session, NULL,
3252 "Usage: lst show_session" },
3253 {"ping", jt_lst_ping , NULL,
3254 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3255 {"add_group", jt_lst_add_group, NULL,
3256 "Usage: lst group NAME IDs [IDs]..." },
3257 {"del_group", jt_lst_del_group, NULL,
3258 "Usage: lst del_group NAME" },
3259 {"update_group", jt_lst_update_group, NULL,
3260 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3261 {"list_group", jt_lst_list_group, NULL,
3262 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3263 {"stat", jt_lst_stat, NULL,
3264 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3265 " [--mbs] [--timeout #] [--delay #] [--count #] GROUP [GROUP]" },
3266 {"show_error", jt_lst_show_error, NULL,
3267 "Usage: lst show_error NAME | IDS ..." },
3268 {"add_batch", jt_lst_add_batch, NULL,
3269 "Usage: lst add_batch NAME" },
3270 {"run", jt_lst_start_batch, NULL,
3271 "Usage: lst run [--timeout TIME] [NAME]" },
3272 {"stop", jt_lst_stop_batch, NULL,
3273 "Usage: lst stop [--force] BATCH_NAME" },
3274 {"list_batch", jt_lst_list_batch, NULL,
3275 "Usage: lst list_batch NAME [--test ID] [--server]" },
3276 {"query", jt_lst_query_batch, NULL,
3277 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3278 {"add_test", jt_lst_add_test, NULL,
3279 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3280 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3281 {"help", Parser_help, 0, "help" },
3286 lst_initialize(void)
3291 feats = getenv("LST_FEATURES");
3293 session_features = strtol(feats, NULL, 16);
3295 if ((session_features & ~LST_FEATS_MASK) != 0) {
3297 "Unsupported session features %x, "
3298 "only support these features so far: %x\n",
3299 (session_features & ~LST_FEATS_MASK), LST_FEATS_MASK);
3303 key = getenv("LST_SESSION");
3310 session_key = atoi(key);
3316 main(int argc, char **argv)
3322 rc = lst_initialize();
3326 rc = ptl_initialize(argc, argv);
3330 Parser_init("lst > ", lst_cmdlist);
3333 rc = Parser_execarg(argc - 1, argv + 1, lst_cmdlist);