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>
43 #include <libcfs/libcfsutil.h>
44 #include <lnet/lnetctl.h>
45 #include <lnet/lnetst.h>
46 #include <lnet/nidstr.h>
47 /* NB: these includes are layering violation */
48 #include <lustre_ver.h>
49 #include <lustre/lustre_idl.h>
51 lst_sid_t LST_INVALID_SID = {LNET_NID_ANY, -1};
52 static lst_sid_t session_id;
53 static int session_key;
55 /* All nodes running 2.6.50 or later understand feature LST_FEAT_BULK_LEN */
56 static unsigned session_features = LST_FEATS_MASK;
57 static lstcon_trans_stat_t trans_stat;
59 typedef struct list_string {
60 struct list_string *lstr_next;
66 # define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
69 static int alloc_count = 0;
70 static int alloc_nob = 0;
75 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
78 fprintf(stderr, "Can't allocate lstr\n");
85 lstr->lstr_str[0] = 0;
91 free_lstr(lstr_t *lstr)
94 alloc_nob -= lstr->lstr_sz;
99 free_lstrs(lstr_t **list)
103 while ((lstr = *list) != NULL) {
104 *list = lstr->lstr_next;
110 new_lstrs(lstr_t **list, char *prefix, char *postfix,
111 int lo, int hi, int stride)
113 int n1 = strlen(prefix);
114 int n2 = strlen(postfix);
115 int sz = n1 + 20 + n2 + 1;
118 lstr_t *n = alloc_lstr(sz);
120 snprintf(n->lstr_str, sz - 1, "%s%u%s",
121 prefix, lo, postfix);
123 n->lstr_next = *list;
131 expand_lstr(lstr_t **list, lstr_t *l)
133 int nob = strlen(l->lstr_str);
143 b1 = strchr(l->lstr_str, '[');
145 l->lstr_next = *list;
150 b2 = strchr(b1, ']');
151 if (b2 == NULL || b2 == b1 + 1)
159 sep = strchr(expr, ',');
165 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
167 new_lstrs(list, l->lstr_str, b2, x, x, 1);
172 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
175 new_lstrs(list, l->lstr_str, b2, x, y, 1);
180 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
183 new_lstrs(list, l->lstr_str, b2, x, y, z);
189 } while ((expr = sep) != NULL);
197 expand_strs(char *str, lstr_t **head)
205 l = alloc_lstr(strlen(str) + 1);
206 memcpy(l->lstr_str, str, strlen(str) + 1);
214 while ((l = list) != NULL) {
217 rc = expand_lstr(&nlist, l);
219 fprintf(stderr, "Syntax error in \"%s\"\n", str);
227 /* re-order onto 'list' */
228 while ((l = nlist) != NULL) {
229 nlist = l->lstr_next;
234 } while (expanded && rc > 0);
241 while ((l = list) != NULL) {
250 lst_parse_nids(char *str, int *countp, lnet_process_id_t **idspp)
258 rc = expand_strs(str, &head);
268 *idspp = malloc(c * sizeof(lnet_process_id_t));
269 if (*idspp == NULL) {
270 fprintf(stderr, "Out of memory\n");
277 while ((l = head) != NULL) {
281 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
282 if ((*idspp)[i].nid == LNET_NID_ANY) {
283 fprintf(stderr, "Invalid nid: %s\n",
288 (*idspp)[i].pid = LNET_PID_LUSTRE;
305 lst_node_state2str(int state)
307 if (state == LST_NODE_ACTIVE)
309 if (state == LST_NODE_BUSY)
311 if (state == LST_NODE_DOWN)
318 lst_node_str2state(char *str)
320 if (strcasecmp(str, "active") == 0)
321 return LST_NODE_ACTIVE;
322 if (strcasecmp(str, "busy") == 0)
323 return LST_NODE_BUSY;
324 if (strcasecmp(str, "down") == 0)
325 return LST_NODE_DOWN;
326 if (strcasecmp(str, "unknown") == 0)
327 return LST_NODE_UNKNOWN;
328 if (strcasecmp(str, "invalid") == 0)
329 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
335 lst_test_type2name(int type)
337 if (type == LST_TEST_PING)
339 if (type == LST_TEST_BULK)
346 lst_test_name2type(char *name)
348 if (strcasecmp(name, "ping") == 0)
349 return LST_TEST_PING;
350 if (strcasecmp(name, "brw") == 0)
351 return LST_TEST_BULK;
357 lst_print_usage(char *cmd)
359 Parser_printhelp(cmd);
363 lst_print_error(char *sub, const char *def_format, ...)
367 /* local error returned from kernel */
370 fprintf(stderr, "No session exists\n");
373 fprintf(stderr, "Session is shutting down\n");
376 fprintf(stderr, "Unmatched session key or not root\n");
379 fprintf(stderr, "Can't find %s in current session\n", sub);
382 fprintf(stderr, "Invalid parameters list in command line\n");
385 fprintf(stderr, "Bad parameter address\n");
388 fprintf(stderr, "%s already exists\n", sub);
391 va_start(ap, def_format);
392 vfprintf(stderr, def_format, ap);
400 lst_free_rpcent(struct list_head *head)
402 lstcon_rpc_ent_t *ent;
404 while (!list_empty(head)) {
405 ent = list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
407 list_del(&ent->rpe_link);
413 lst_reset_rpcent(struct list_head *head)
415 lstcon_rpc_ent_t *ent;
417 list_for_each_entry(ent, head, rpe_link) {
418 ent->rpe_sid = LST_INVALID_SID;
419 ent->rpe_peer.nid = LNET_NID_ANY;
420 ent->rpe_peer.pid = LNET_PID_ANY;
421 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
426 lst_alloc_rpcent(struct list_head *head, int count, int offset)
428 lstcon_rpc_ent_t *ent;
431 for (i = 0; i < count; i++) {
432 ent = malloc(offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
434 lst_free_rpcent(head);
438 memset(ent, 0, offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
440 ent->rpe_sid = LST_INVALID_SID;
441 ent->rpe_peer.nid = LNET_NID_ANY;
442 ent->rpe_peer.pid = LNET_PID_ANY;
443 list_add(&ent->rpe_link, head);
450 lst_print_transerr(struct list_head *head, char *optstr)
452 lstcon_rpc_ent_t *ent;
454 list_for_each_entry(ent, head, rpe_link) {
455 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
458 if (ent->rpe_rpc_errno != 0) {
459 fprintf(stderr, "%s RPC failed on %s: %s\n",
460 optstr, libcfs_id2str(ent->rpe_peer),
461 strerror(ent->rpe_rpc_errno));
465 fprintf(stderr, "operation %s failed on %s: %s\n",
466 optstr, libcfs_id2str(ent->rpe_peer),
467 strerror(ent->rpe_fwk_errno));
471 int lst_info_batch_ioctl(char *batch, int test, int server,
472 lstcon_test_batch_ent_t *entp, int *idxp,
473 int *ndentp, lstcon_node_ent_t *dentsp);
475 int lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
476 int *idx, int *count, lstcon_node_ent_t *dents);
478 int lst_query_batch_ioctl(char *batch, int test, int server,
479 int timeout, struct list_head *head);
482 lst_ioctl(unsigned int opc, void *buf, int len)
484 struct libcfs_ioctl_data data;
487 LIBCFS_IOC_INIT (data);
488 data.ioc_u32[0] = opc;
489 data.ioc_plen1 = len;
490 data.ioc_pbuf1 = (char *)buf;
491 data.ioc_plen2 = sizeof(trans_stat);
492 data.ioc_pbuf2 = (char *)&trans_stat;
494 memset(&trans_stat, 0, sizeof(trans_stat));
496 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
498 /* local error, no valid RPC result */
503 if (trans_stat.trs_rpc_errno != 0)
506 /* Framework error */
507 if (trans_stat.trs_fwk_errno != 0)
514 lst_new_session_ioctl(char *name, int timeout, int force, lst_sid_t *sid)
516 lstio_session_new_args_t args = {0};
518 args.lstio_ses_key = session_key;
519 args.lstio_ses_timeout = timeout;
520 args.lstio_ses_force = force;
521 args.lstio_ses_idp = sid;
522 args.lstio_ses_feats = session_features;
523 args.lstio_ses_nmlen = strlen(name);
524 args.lstio_ses_namep = name;
526 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
530 jt_lst_new_session(int argc, char **argv)
532 char buf[LST_NAME_SIZE];
540 static struct option session_opts[] =
542 {"timeout", required_argument, 0, 't' },
543 {"force", no_argument, 0, 'f' },
547 if (session_key == 0) {
549 "Can't find env LST_SESSION or value is not valid\n");
555 c = getopt_long(argc, argv, "ft:",
556 session_opts, &optidx);
566 timeout = atoi(optarg);
569 lst_print_usage(argv[0]);
575 fprintf(stderr, "Invalid timeout value\n");
579 if (optind == argc - 1) {
580 name = argv[optind ++];
581 if (strlen(name) >= LST_NAME_SIZE) {
582 fprintf(stderr, "Name size is limited to %d\n",
587 } else if (optind == argc) {
588 char user[LST_NAME_SIZE];
589 char host[LST_NAME_SIZE];
590 struct passwd *pw = getpwuid(getuid());
593 snprintf(user, sizeof(user), "%d", (int)getuid());
595 snprintf(user, sizeof(user), "%s", pw->pw_name);
597 rc = gethostname(host, sizeof(host));
599 snprintf(host, sizeof(host), "unknown_host");
601 snprintf(buf, sizeof(buf), "%s@%s", user, host);
605 lst_print_usage(argv[0]);
609 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
611 lst_print_error("session", "Failed to create session: %s\n",
616 fprintf(stdout, "SESSION: %s FEATURES: %x TIMEOUT: %d FORCE: %s\n",
617 name, session_features, timeout, force ? "Yes" : "No");
622 lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp,
623 lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
625 lstio_session_info_args_t args = {0};
627 args.lstio_ses_idp = sid;
628 args.lstio_ses_keyp = key;
629 args.lstio_ses_featp = featp;
630 args.lstio_ses_ndinfo = ndinfo;
631 args.lstio_ses_nmlen = len;
632 args.lstio_ses_namep = name;
634 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
638 jt_lst_show_session(int argc, char **argv)
640 lstcon_ndlist_ent_t ndinfo;
642 char name[LST_NAME_SIZE];
647 rc = lst_session_info_ioctl(name, sizeof(name), &key,
648 &feats, &sid, &ndinfo);
651 lst_print_error("session", "Failed to show session: %s\n",
656 fprintf(stdout, "%s ID: "LPU64"@%s, KEY: %d FEATURES: %x NODES: %d\n",
657 name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
658 key, feats, ndinfo.nle_nnode);
664 lst_end_session_ioctl(void)
666 lstio_session_end_args_t args = {0};
668 args.lstio_ses_key = session_key;
669 return lst_ioctl (LSTIO_SESSION_END, &args, sizeof(args));
673 jt_lst_end_session(int argc, char **argv)
677 if (session_key == 0) {
679 "Can't find env LST_SESSION or value is not valid\n");
683 rc = lst_end_session_ioctl();
686 fprintf(stdout, "session is ended\n");
691 lst_print_error("session", "Failed to end session: %s\n",
696 if (trans_stat.trs_rpc_errno != 0) {
698 "[RPC] Failed to send %d session RPCs: %s\n",
699 lstcon_rpc_stat_failure(&trans_stat, 0),
700 strerror(trans_stat.trs_rpc_errno));
703 if (trans_stat.trs_fwk_errno != 0) {
705 "[FWK] Failed to end session on %d nodes: %s\n",
706 lstcon_sesop_stat_failure(&trans_stat, 0),
707 strerror(trans_stat.trs_fwk_errno));
714 lst_ping_ioctl(char *str, int type, int timeout,
715 int count, lnet_process_id_t *ids, struct list_head *head)
717 lstio_debug_args_t args = {0};
719 args.lstio_dbg_key = session_key;
720 args.lstio_dbg_type = type;
721 args.lstio_dbg_flags = 0;
722 args.lstio_dbg_timeout = timeout;
723 args.lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str);
724 args.lstio_dbg_namep = str;
725 args.lstio_dbg_count = count;
726 args.lstio_dbg_idsp = ids;
727 args.lstio_dbg_resultp = head;
729 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
733 lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
735 char buf[LST_NAME_SIZE];
736 lstcon_test_batch_ent_t ent;
737 lstcon_ndlist_ent_t *entp = &ent.tbe_cli_nle;
744 case LST_OPC_SESSION:
745 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
746 &key, &feats, &sid, entp);
749 case LST_OPC_BATCHSRV:
750 entp = &ent.tbe_srv_nle;
751 case LST_OPC_BATCHCLI:
752 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
756 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
760 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
769 *countp = entp->nle_nnode;
775 jt_lst_ping(int argc, char **argv)
777 struct list_head head;
778 lnet_process_id_t *ids = NULL;
779 lstcon_rpc_ent_t *ent = NULL;
789 static struct option ping_opts[] =
791 {"session", no_argument, 0, 's' },
792 {"server", no_argument, 0, 'v' },
793 {"batch", required_argument, 0, 'b' },
794 {"group", required_argument, 0, 'g' },
795 {"nodes", required_argument, 0, 'n' },
796 {"timeout", required_argument, 0, 't' },
800 if (session_key == 0) {
802 "Can't find env LST_SESSION or value is not valid\n");
808 c = getopt_long(argc, argv, "g:b:n:t:sv",
816 type = LST_OPC_SESSION;
820 type = LST_OPC_GROUP;
825 type = LST_OPC_BATCHCLI;
830 type = LST_OPC_NODES;
835 timeout = atoi(optarg);
843 lst_print_usage(argv[0]);
848 if (type == 0 || timeout <= 0 || optind != argc) {
849 lst_print_usage(argv[0]);
853 if (type == LST_OPC_BATCHCLI && server)
854 type = LST_OPC_BATCHSRV;
856 rc = lst_get_node_count(type, str, &count, &ids);
858 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
859 (str == NULL) ? "session" : str, strerror(errno));
863 INIT_LIST_HEAD(&head);
865 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
867 fprintf(stderr, "Out of memory\n");
872 fprintf(stdout, "Target %s is empty\n",
873 (str == NULL) ? "session" : str);
877 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
878 if (rc == -1) { /* local failure */
879 lst_print_error("debug", "Failed to ping %s: %s\n",
880 (str == NULL) ? "session" : str,
886 /* ignore RPC errors and framwork errors */
887 list_for_each_entry(ent, &head, rpe_link) {
888 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
889 libcfs_id2str(ent->rpe_peer),
890 lst_node_state2str(ent->rpe_state),
891 (ent->rpe_state == LST_NODE_ACTIVE ||
892 ent->rpe_state == LST_NODE_BUSY) ?
893 (ent->rpe_rpc_errno == 0 ?
894 &ent->rpe_payload[0] : "Unknown") :
895 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
899 lst_free_rpcent(&head);
909 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
910 unsigned *featp, struct list_head *resultp)
912 lstio_group_nodes_args_t args = {0};
914 args.lstio_grp_key = session_key;
915 args.lstio_grp_nmlen = strlen(name);
916 args.lstio_grp_namep = name;
917 args.lstio_grp_count = count;
918 args.lstio_grp_featp = featp;
919 args.lstio_grp_idsp = ids;
920 args.lstio_grp_resultp = resultp;
922 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
926 lst_del_group_ioctl(char *name)
928 lstio_group_del_args_t args = {0};
930 args.lstio_grp_key = session_key;
931 args.lstio_grp_nmlen = strlen(name);
932 args.lstio_grp_namep = name;
934 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
938 lst_del_group(char *grp_name)
942 rc = lst_del_group_ioctl(grp_name);
944 fprintf(stdout, "Group is deleted\n");
949 lst_print_error("group", "Failed to delete group: %s\n",
954 fprintf(stderr, "Group is deleted with some errors\n");
956 if (trans_stat.trs_rpc_errno != 0) {
958 "[RPC] Failed to send %d end session RPCs: %s\n",
959 lstcon_rpc_stat_failure(&trans_stat, 0),
960 strerror(trans_stat.trs_rpc_errno));
963 if (trans_stat.trs_fwk_errno != 0) {
965 "[FWK] Failed to end session on %d nodes: %s\n",
966 lstcon_sesop_stat_failure(&trans_stat, 0),
967 strerror(trans_stat.trs_fwk_errno));
974 lst_add_group_ioctl (char *name)
976 lstio_group_add_args_t args = {0};
978 args.lstio_grp_key = session_key;
979 args.lstio_grp_nmlen = strlen(name);
980 args.lstio_grp_namep = name;
982 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
986 jt_lst_add_group(int argc, char **argv)
988 struct list_head head;
989 lnet_process_id_t *ids;
991 unsigned feats = session_features;
995 bool nodes_added = false;
997 if (session_key == 0) {
999 "Can't find env LST_SESSION or value is not valid\n");
1004 lst_print_usage(argv[0]);
1009 if (strlen(name) >= LST_NAME_SIZE) {
1010 fprintf(stderr, "Name length is limited to %d\n",
1015 rc = lst_add_group_ioctl(name);
1017 lst_print_error("group", "Failed to add group %s: %s\n",
1018 name, strerror(errno));
1022 INIT_LIST_HEAD(&head);
1024 for (i = 2; i < argc; i++) {
1025 /* parse address list */
1026 rc = lst_parse_nids(argv[i], &count, &ids);
1028 fprintf(stderr, "Ignore invalid id list %s\n",
1036 rc = lst_alloc_rpcent(&head, count, 0);
1038 fprintf(stderr, "Out of memory\n");
1044 rc = lst_add_nodes_ioctl(name, count, ids, &feats, &head);
1051 fprintf(stdout, "%s are added to session\n", argv[i]);
1055 if ((feats & session_features) != session_features) {
1057 "Warning, this session will run with "
1058 "compatible mode because some test nodes "
1059 "might not understand these features: %x\n",
1060 (~feats & session_features));
1063 lst_free_rpcent(&head);
1068 * The selftest kernel module expects that a group should
1069 * have at least one node, since it doesn't make sense for
1070 * an empty group to be added to a test.
1073 "No nodes added successfully, deleting group %s\n",
1075 rc = lst_del_group(name);
1078 "Failed to delete group %s."
1079 " Group is empty.\n", name);
1087 lst_print_error("group", "Failed to add nodes %s: %s\n",
1088 argv[i], strerror(errno));
1091 if (trans_stat.trs_fwk_errno == EPROTO) {
1093 "test nodes might have different LST "
1094 "features, please disable some features by "
1095 "setting LST_FEATURES\n");
1098 lst_print_transerr(&head, "create session");
1101 lst_free_rpcent(&head);
1105 "No nodes added successfully, deleting group %s\n",
1107 if (lst_del_group(name) != 0) {
1109 "Failed to delete group %s."
1110 " Group is empty.\n", name);
1118 jt_lst_del_group(int argc, char **argv)
1122 if (session_key == 0) {
1124 "Can't find env LST_SESSION or value is not valid\n");
1129 lst_print_usage(argv[0]);
1133 rc = lst_del_group(argv[1]);
1139 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1140 lnet_process_id_t *ids, struct list_head *resultp)
1142 lstio_group_update_args_t args = {0};
1144 args.lstio_grp_key = session_key;
1145 args.lstio_grp_opc = opc;
1146 args.lstio_grp_args = clean;
1147 args.lstio_grp_nmlen = strlen(name);
1148 args.lstio_grp_namep = name;
1149 args.lstio_grp_count = count;
1150 args.lstio_grp_idsp = ids;
1151 args.lstio_grp_resultp = resultp;
1153 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1157 jt_lst_update_group(int argc, char **argv)
1159 struct list_head head;
1160 lnet_process_id_t *ids = NULL;
1170 static struct option update_group_opts[] =
1172 {"refresh", no_argument, 0, 'f' },
1173 {"clean", required_argument, 0, 'c' },
1174 {"remove", required_argument, 0, 'r' },
1178 if (session_key == 0) {
1180 "Can't find env LST_SESSION or value is not valid\n");
1185 c = getopt_long(argc, argv, "fc:r:",
1186 update_group_opts, &optidx);
1188 /* Detect the end of the options. */
1195 lst_print_usage(argv[0]);
1198 opc = LST_GROUP_REFRESH;
1203 lst_print_usage(argv[0]);
1206 opc = LST_GROUP_RMND;
1211 clean = lst_node_str2state(optarg);
1212 if (opc != 0 || clean <= 0) {
1213 lst_print_usage(argv[0]);
1216 opc = LST_GROUP_CLEAN;
1220 lst_print_usage(argv[0]);
1225 /* no OPC or group is specified */
1226 if (opc == 0 || optind != argc - 1) {
1227 lst_print_usage(argv[0]);
1233 INIT_LIST_HEAD(&head);
1235 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1236 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1238 opc == LST_GROUP_RMND ? str : grp,
1242 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1243 opc == LST_GROUP_RMND ? str : grp,
1248 rc = lst_alloc_rpcent(&head, count, 0);
1250 fprintf(stderr, "Out of memory\n");
1257 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1263 lst_free_rpcent(&head);
1268 lst_free_rpcent(&head);
1269 lst_print_error("group", "Failed to update group: %s\n",
1274 lst_print_transerr(&head, "Updating group");
1276 lst_free_rpcent(&head);
1282 lst_list_group_ioctl(int len, char *name, int idx)
1284 lstio_group_list_args_t args = {0};
1286 args.lstio_grp_key = session_key;
1287 args.lstio_grp_idx = idx;
1288 args.lstio_grp_nmlen = len;
1289 args.lstio_grp_namep = name;
1291 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1295 lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
1296 int *idx, int *count, lstcon_node_ent_t *dents)
1298 lstio_group_info_args_t args = {0};
1300 args.lstio_grp_key = session_key;
1301 args.lstio_grp_nmlen = strlen(name);
1302 args.lstio_grp_namep = name;
1303 args.lstio_grp_entp = gent;
1304 args.lstio_grp_idxp = idx;
1305 args.lstio_grp_ndentp = count;
1306 args.lstio_grp_dentsp = dents;
1308 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1312 lst_list_group_all(void)
1314 char name[LST_NAME_SIZE];
1318 /* no group is specified, list name of all groups */
1319 for (i = 0; ; i++) {
1320 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1322 fprintf(stdout, "%d) %s\n", i + 1, name);
1326 if (errno == ENOENT)
1329 lst_print_error("group", "Failed to list group: %s\n",
1334 fprintf(stdout, "Total %d groups\n", i);
1339 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1342 jt_lst_list_group(int argc, char **argv)
1344 lstcon_ndlist_ent_t gent;
1345 lstcon_node_ent_t *dents;
1360 static struct option list_group_opts[] =
1362 {"active", no_argument, 0, 'a' },
1363 {"busy", no_argument, 0, 'b' },
1364 {"down", no_argument, 0, 'd' },
1365 {"unknown", no_argument, 0, 'u' },
1366 {"all", no_argument, 0, 'l' },
1370 if (session_key == 0) {
1372 "Can't find env LST_SESSION or value is not valid\n");
1377 c = getopt_long(argc, argv, "abdul",
1378 list_group_opts, &optidx);
1385 verbose = active = 1;
1397 verbose = unknown = 1;
1404 lst_print_usage(argv[0]);
1409 if (optind == argc) {
1410 /* no group is specified, list name of all groups */
1411 rc = lst_list_group_all();
1417 fprintf(stdout, LST_NODES_TITLE);
1419 /* list nodes in specified groups */
1420 for (i = optind; i < argc; i++) {
1421 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1423 if (errno == ENOENT) {
1428 lst_print_error("group", "Failed to list group\n",
1434 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1435 gent.nle_nactive, gent.nle_nbusy,
1436 gent.nle_ndown, gent.nle_nunknown,
1437 gent.nle_nnode, argv[i]);
1441 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1443 if (gent.nle_nnode == 0) {
1444 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1448 count = gent.nle_nnode;
1450 dents = malloc(count * sizeof(lstcon_node_ent_t));
1451 if (dents == NULL) {
1452 fprintf(stderr, "Failed to malloc: %s\n",
1458 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1460 lst_print_error("group", "Failed to list group: %s\n",
1466 for (j = 0, c = 0; j < count; j++) {
1468 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1469 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1470 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1471 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1473 fprintf(stdout, "\t%s: %s\n",
1474 libcfs_id2str(dents[j].nde_id),
1475 lst_node_state2str(dents[j].nde_state));
1480 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1489 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
1490 int timeout, struct list_head *resultp)
1492 lstio_stat_args_t args = {0};
1494 args.lstio_sta_key = session_key;
1495 args.lstio_sta_timeout = timeout;
1496 args.lstio_sta_nmlen = strlen(name);
1497 args.lstio_sta_namep = name;
1498 args.lstio_sta_count = count;
1499 args.lstio_sta_idsp = idsp;
1500 args.lstio_sta_resultp = resultp;
1502 return lst_ioctl (LSTIO_STAT_QUERY, &args, sizeof(args));
1506 struct list_head srp_link;
1509 lnet_process_id_t *srp_ids;
1510 struct list_head srp_result[2];
1511 } lst_stat_req_param_t;
1514 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1518 for (i = 0; i < 2; i++)
1519 lst_free_rpcent(&srp->srp_result[i]);
1521 if (srp->srp_ids != NULL)
1528 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
1530 lst_stat_req_param_t *srp = NULL;
1531 int count = save_old ? 2 : 1;
1535 srp = malloc(sizeof(*srp));
1539 memset(srp, 0, sizeof(*srp));
1540 INIT_LIST_HEAD(&srp->srp_result[0]);
1541 INIT_LIST_HEAD(&srp->srp_result[1]);
1543 rc = lst_get_node_count(LST_OPC_GROUP, name,
1544 &srp->srp_count, NULL);
1545 if (rc != 0 && errno == ENOENT) {
1546 rc = lst_get_node_count(LST_OPC_NODES, name,
1547 &srp->srp_count, &srp->srp_ids);
1552 "Failed to get count of nodes from %s: %s\n",
1553 name, strerror(errno));
1554 lst_stat_req_param_free(srp);
1559 srp->srp_name = name;
1561 for (i = 0; i < count; i++) {
1562 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1563 sizeof(sfw_counters_t) +
1564 sizeof(srpc_counters_t) +
1565 sizeof(lnet_counters_t));
1567 fprintf(stderr, "Out of memory\n");
1577 lst_stat_req_param_free(srp);
1585 } lst_srpc_stat_result;
1587 #define LST_LNET_AVG 0
1588 #define LST_LNET_MIN 1
1589 #define LST_LNET_MAX 2
1592 float lnet_avg_sndrate;
1593 float lnet_min_sndrate;
1594 float lnet_max_sndrate;
1595 float lnet_total_sndrate;
1597 float lnet_avg_rcvrate;
1598 float lnet_min_rcvrate;
1599 float lnet_max_rcvrate;
1600 float lnet_total_rcvrate;
1602 float lnet_avg_sndperf;
1603 float lnet_min_sndperf;
1604 float lnet_max_sndperf;
1605 float lnet_total_sndperf;
1607 float lnet_avg_rcvperf;
1608 float lnet_min_rcvperf;
1609 float lnet_max_rcvperf;
1610 float lnet_total_rcvperf;
1612 int lnet_stat_count;
1613 } lst_lnet_stat_result_t;
1615 lst_lnet_stat_result_t lnet_stat_result;
1618 lst_lnet_stat_value(int bw, int send, int off)
1622 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1623 &lnet_stat_result.lnet_avg_sndrate;
1634 lst_timeval_diff(struct timeval *tv1,
1635 struct timeval *tv2, struct timeval *df)
1637 if (tv1->tv_usec >= tv2->tv_usec) {
1638 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1639 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1643 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1644 df->tv_usec = tv1->tv_usec + 1000000 - tv2->tv_usec;
1650 lst_cal_lnet_stat(float delta, lnet_counters_t *lnet_new,
1651 lnet_counters_t *lnet_old)
1656 perf = (float)(lnet_new->send_length -
1657 lnet_old->send_length) / (1024 * 1024) / delta;
1658 lnet_stat_result.lnet_total_sndperf += perf;
1660 if (lnet_stat_result.lnet_min_sndperf > perf ||
1661 lnet_stat_result.lnet_min_sndperf == 0)
1662 lnet_stat_result.lnet_min_sndperf = perf;
1664 if (lnet_stat_result.lnet_max_sndperf < perf)
1665 lnet_stat_result.lnet_max_sndperf = perf;
1667 perf = (float)(lnet_new->recv_length -
1668 lnet_old->recv_length) / (1024 * 1024) / delta;
1669 lnet_stat_result.lnet_total_rcvperf += perf;
1671 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1672 lnet_stat_result.lnet_min_rcvperf == 0)
1673 lnet_stat_result.lnet_min_rcvperf = perf;
1675 if (lnet_stat_result.lnet_max_rcvperf < perf)
1676 lnet_stat_result.lnet_max_rcvperf = perf;
1678 rate = (lnet_new->send_count - lnet_old->send_count) / delta;
1679 lnet_stat_result.lnet_total_sndrate += rate;
1681 if (lnet_stat_result.lnet_min_sndrate > rate ||
1682 lnet_stat_result.lnet_min_sndrate == 0)
1683 lnet_stat_result.lnet_min_sndrate = rate;
1685 if (lnet_stat_result.lnet_max_sndrate < rate)
1686 lnet_stat_result.lnet_max_sndrate = rate;
1688 rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
1689 lnet_stat_result.lnet_total_rcvrate += rate;
1691 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1692 lnet_stat_result.lnet_min_rcvrate == 0)
1693 lnet_stat_result.lnet_min_rcvrate = rate;
1695 if (lnet_stat_result.lnet_max_rcvrate < rate)
1696 lnet_stat_result.lnet_max_rcvrate = rate;
1698 lnet_stat_result.lnet_stat_count ++;
1700 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1701 lnet_stat_result.lnet_stat_count;
1702 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1703 lnet_stat_result.lnet_stat_count;
1705 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1706 lnet_stat_result.lnet_stat_count;
1707 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1708 lnet_stat_result.lnet_stat_count;
1713 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
1722 if (lnet_stat_result.lnet_stat_count == 0)
1725 if (bwrt == 1) /* bw only */
1728 if (bwrt == 2) /* rates only */
1731 if (rdwr == 1) /* recv only */
1734 if (rdwr == 2) /* send only */
1737 for (i = start1; i <= end1; i++) {
1738 fprintf(stdout, "[LNet %s of %s]\n",
1739 i == 0 ? "Rates" : "Bandwidth", name);
1741 for (j = start2; j <= end2; j++) {
1742 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
1744 if ((type & 1) != 0) {
1745 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1746 "Avg: %-8.2f MB/s ",
1747 lst_lnet_stat_value(i, j, 0));
1750 if ((type & 2) != 0) {
1751 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1752 "Min: %-8.2f MB/s ",
1753 lst_lnet_stat_value(i, j, 1));
1756 if ((type & 4) != 0) {
1757 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1759 lst_lnet_stat_value(i, j, 2));
1762 fprintf(stdout, "\n");
1768 lst_print_stat(char *name, struct list_head *resultp,
1769 int idx, int lnet, int bwrt, int rdwr, int type)
1771 struct list_head tmp[2];
1772 lstcon_rpc_ent_t *new;
1773 lstcon_rpc_ent_t *old;
1774 sfw_counters_t *sfwk_new;
1775 sfw_counters_t *sfwk_old;
1776 srpc_counters_t *srpc_new;
1777 srpc_counters_t *srpc_old;
1778 lnet_counters_t *lnet_new;
1779 lnet_counters_t *lnet_old;
1783 INIT_LIST_HEAD(&tmp[0]);
1784 INIT_LIST_HEAD(&tmp[1]);
1786 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1788 while (!list_empty(&resultp[idx])) {
1789 if (list_empty(&resultp[1 - idx])) {
1790 fprintf(stderr, "Group is changed, re-run stat\n");
1794 new = list_entry(resultp[idx].next, lstcon_rpc_ent_t,
1796 old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t,
1799 /* first time get stats result, can't calculate diff */
1800 if (new->rpe_peer.nid == LNET_NID_ANY)
1803 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1804 new->rpe_peer.pid != old->rpe_peer.pid) {
1805 /* Something wrong. i.e, somebody change the group */
1809 list_del(&new->rpe_link);
1810 list_add_tail(&new->rpe_link, &tmp[idx]);
1812 list_del(&old->rpe_link);
1813 list_add_tail(&old->rpe_link, &tmp[1 - idx]);
1815 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1816 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1821 sfwk_new = (sfw_counters_t *)&new->rpe_payload[0];
1822 sfwk_old = (sfw_counters_t *)&old->rpe_payload[0];
1824 srpc_new = (srpc_counters_t *)((char *)sfwk_new + sizeof(*sfwk_new));
1825 srpc_old = (srpc_counters_t *)((char *)sfwk_old + sizeof(*sfwk_old));
1827 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
1828 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
1830 /* Prior to version 2.3, the running_ms field was a counter for
1831 * the number of running tests. We are looking at this value
1832 * to determine if it is a millisecond timestamep (>= 2.3) or a
1833 * test counter (< 2.3). The number 500 is being used for this
1834 * barrier as the test counter should never get this high, and
1835 * the timestamp should never get this low. */
1837 if (sfwk_new->running_ms > 500) {
1838 /* use the timestamp from the remote node, not our
1839 * rpe_stamp from when we copied up the data out of
1842 delta = (float) (sfwk_new->running_ms -
1843 sfwk_old->running_ms) / 1000;
1847 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1848 delta = tv.tv_sec + (float)tv.tv_usec / 1000000;
1851 if (!lnet) /* TODO */
1854 lst_cal_lnet_stat(delta, lnet_new, lnet_old);
1857 list_splice(&tmp[idx], &resultp[idx]);
1858 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1861 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1863 if (!lnet) /* TODO */
1866 lst_print_lnet_stat(name, bwrt, rdwr, type);
1870 jt_lst_stat(int argc, char **argv)
1872 struct list_head head;
1873 lst_stat_req_param_t *srp;
1876 int timeout = 5; /* default timeout, 5 sec */
1877 int delay = 5; /* default delay, 5 sec */
1878 int count = -1; /* run forever */
1879 int lnet = 1; /* lnet stat by default */
1887 static struct option stat_opts[] =
1889 {"timeout" , required_argument, 0, 't' },
1890 {"delay" , required_argument, 0, 'd' },
1891 {"count" , required_argument, 0, 'o' },
1892 {"lnet" , no_argument, 0, 'l' },
1893 {"rpc" , no_argument, 0, 'c' },
1894 {"bw" , no_argument, 0, 'b' },
1895 {"rate" , no_argument, 0, 'a' },
1896 {"read" , no_argument, 0, 'r' },
1897 {"write" , no_argument, 0, 'w' },
1898 {"avg" , no_argument, 0, 'g' },
1899 {"min" , no_argument, 0, 'n' },
1900 {"max" , no_argument, 0, 'x' },
1904 if (session_key == 0) {
1906 "Can't find env LST_SESSION or value is not valid\n");
1911 c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
1918 timeout = atoi(optarg);
1921 delay = atoi(optarg);
1924 count = atoi(optarg);
1967 lst_print_usage(argv[0]);
1972 if (optind == argc) {
1973 lst_print_usage(argv[0]);
1977 if (timeout <= 0 || delay <= 0) {
1978 fprintf(stderr, "Invalid timeout or delay value\n");
1983 fprintf(stderr, "Invalid count value\n");
1987 /* extra count to get first data point */
1991 INIT_LIST_HEAD(&head);
1993 while (optind < argc) {
1994 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
1998 list_add_tail(&srp->srp_link, &head);
2002 time_t now = time(NULL);
2004 if (now - last < delay) {
2005 sleep(delay - now + last);
2010 list_for_each_entry(srp, &head, srp_link) {
2011 rc = lst_stat_ioctl(srp->srp_name,
2012 srp->srp_count, srp->srp_ids,
2013 timeout, &srp->srp_result[idx]);
2015 lst_print_error("stat", "Failed to stat %s: %s\n",
2016 srp->srp_name, strerror(errno));
2020 lst_print_stat(srp->srp_name, srp->srp_result,
2021 idx, lnet, bwrt, rdwr, type);
2023 lst_reset_rpcent(&srp->srp_result[1 - idx]);
2030 } while (count == -1 || count > 0);
2033 while (!list_empty(&head)) {
2034 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2036 list_del(&srp->srp_link);
2037 lst_stat_req_param_free(srp);
2044 jt_lst_show_error(int argc, char **argv)
2046 struct list_head head;
2047 lst_stat_req_param_t *srp;
2048 lstcon_rpc_ent_t *ent;
2049 sfw_counters_t *sfwk;
2050 srpc_counters_t *srpc;
2057 static struct option show_error_opts[] =
2059 {"session", no_argument, 0, 's' },
2063 if (session_key == 0) {
2065 "Can't find env LST_SESSION or value is not valid\n");
2070 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
2081 lst_print_usage(argv[0]);
2086 if (optind == argc) {
2087 lst_print_usage(argv[0]);
2091 INIT_LIST_HEAD(&head);
2093 while (optind < argc) {
2094 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
2098 list_add_tail(&srp->srp_link, &head);
2101 list_for_each_entry(srp, &head, srp_link) {
2102 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
2103 srp->srp_ids, 10, &srp->srp_result[0]);
2106 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2107 srp->srp_name, strerror(errno));
2111 fprintf(stdout, "%s:\n", srp->srp_name);
2115 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2116 if (ent->rpe_rpc_errno != 0) {
2118 fprintf(stderr, "RPC failure, can't show error on %s\n",
2119 libcfs_id2str(ent->rpe_peer));
2123 if (ent->rpe_fwk_errno != 0) {
2125 fprintf(stderr, "Framework failure, can't show error on %s\n",
2126 libcfs_id2str(ent->rpe_peer));
2130 sfwk = (sfw_counters_t *)&ent->rpe_payload[0];
2131 srpc = (srpc_counters_t *)((char *)sfwk + sizeof(*sfwk));
2133 if (srpc->errors == 0 &&
2134 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2138 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2143 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2144 libcfs_id2str(ent->rpe_peer),
2145 sfwk->brw_errors, sfwk->ping_errors,
2146 show_rpc ? ' ' : '\n');
2151 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2152 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2155 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2158 while (!list_empty(&head)) {
2159 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2161 list_del(&srp->srp_link);
2162 lst_stat_req_param_free(srp);
2169 lst_add_batch_ioctl (char *name)
2171 lstio_batch_add_args_t args = {0};
2173 args.lstio_bat_key = session_key;
2174 args.lstio_bat_nmlen = strlen(name);
2175 args.lstio_bat_namep = name;
2177 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2181 jt_lst_add_batch(int argc, char **argv)
2186 if (session_key == 0) {
2188 "Can't find env LST_SESSION or value is not valid\n");
2193 lst_print_usage(argv[0]);
2198 if (strlen(name) >= LST_NAME_SIZE) {
2199 fprintf(stderr, "Name length is limited to %d\n",
2204 rc = lst_add_batch_ioctl(name);
2208 lst_print_error("batch", "Failed to create batch: %s\n",
2215 lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp)
2217 lstio_batch_run_args_t args = {0};
2219 args.lstio_bat_key = session_key;
2220 args.lstio_bat_timeout = timeout;
2221 args.lstio_bat_nmlen = strlen(name);
2222 args.lstio_bat_namep = name;
2223 args.lstio_bat_resultp = resultp;
2225 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2229 jt_lst_start_batch(int argc, char **argv)
2231 struct list_head head;
2239 static struct option start_batch_opts[] =
2241 {"timeout", required_argument, 0, 't' },
2245 if (session_key == 0) {
2247 "Can't find env LST_SESSION or value is not valid\n");
2252 c = getopt_long(argc, argv, "t:",
2253 start_batch_opts, &optidx);
2255 /* Detect the end of the options. */
2261 timeout = atoi(optarg);
2264 lst_print_usage(argv[0]);
2269 if (optind == argc) {
2270 batch = LST_DEFAULT_BATCH;
2272 } else if (optind == argc - 1) {
2273 batch = argv[optind];
2276 lst_print_usage(argv[0]);
2280 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2282 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2283 batch, strerror(errno));
2287 INIT_LIST_HEAD(&head);
2289 rc = lst_alloc_rpcent(&head, count, 0);
2291 fprintf(stderr, "Out of memory\n");
2295 rc = lst_start_batch_ioctl(batch, timeout, &head);
2298 fprintf(stdout, "%s is running now\n", batch);
2299 lst_free_rpcent(&head);
2304 lst_print_error("batch", "Failed to start batch: %s\n",
2306 lst_free_rpcent(&head);
2310 lst_print_transerr(&head, "Run batch");
2312 lst_free_rpcent(&head);
2318 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2320 lstio_batch_stop_args_t args = {0};
2322 args.lstio_bat_key = session_key;
2323 args.lstio_bat_force = force;
2324 args.lstio_bat_nmlen = strlen(name);
2325 args.lstio_bat_namep = name;
2326 args.lstio_bat_resultp = resultp;
2328 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2332 jt_lst_stop_batch(int argc, char **argv)
2334 struct list_head head;
2342 static struct option stop_batch_opts[] =
2344 {"force", no_argument, 0, 'f' },
2348 if (session_key == 0) {
2350 "Can't find env LST_SESSION or value is not valid\n");
2355 c = getopt_long(argc, argv, "f",
2356 stop_batch_opts, &optidx);
2358 /* Detect the end of the options. */
2367 lst_print_usage(argv[0]);
2372 if (optind == argc) {
2373 batch = LST_DEFAULT_BATCH;
2375 } else if (optind == argc - 1) {
2376 batch = argv[optind];
2379 lst_print_usage(argv[0]);
2383 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2385 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2386 batch, strerror(errno));
2390 INIT_LIST_HEAD(&head);
2392 rc = lst_alloc_rpcent(&head, count, 0);
2394 fprintf(stderr, "Out of memory\n");
2398 rc = lst_stop_batch_ioctl(batch, force, &head);
2403 lst_reset_rpcent(&head);
2405 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2409 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2410 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2413 fprintf(stdout, "%d batch in stopping\n",
2414 lstcon_tsbqry_stat_run(&trans_stat, 0));
2418 fprintf(stdout, "Batch is stopped\n");
2419 lst_free_rpcent(&head);
2424 lst_print_error("batch", "Failed to stop batch: %s\n",
2426 lst_free_rpcent(&head);
2430 lst_print_transerr(&head, "stop batch");
2432 lst_free_rpcent(&head);
2438 lst_list_batch_ioctl(int len, char *name, int index)
2440 lstio_batch_list_args_t args = {0};
2442 args.lstio_bat_key = session_key;
2443 args.lstio_bat_idx = index;
2444 args.lstio_bat_nmlen = len;
2445 args.lstio_bat_namep = name;
2447 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2451 lst_info_batch_ioctl(char *batch, int test, int server,
2452 lstcon_test_batch_ent_t *entp, int *idxp,
2453 int *ndentp, lstcon_node_ent_t *dentsp)
2455 lstio_batch_info_args_t args = {0};
2457 args.lstio_bat_key = session_key;
2458 args.lstio_bat_nmlen = strlen(batch);
2459 args.lstio_bat_namep = batch;
2460 args.lstio_bat_server = server;
2461 args.lstio_bat_testidx = test;
2462 args.lstio_bat_entp = entp;
2463 args.lstio_bat_idxp = idxp;
2464 args.lstio_bat_ndentp = ndentp;
2465 args.lstio_bat_dentsp = dentsp;
2467 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2471 lst_list_batch_all(void)
2473 char name[LST_NAME_SIZE];
2477 for (i = 0; ; i++) {
2478 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2480 fprintf(stdout, "%d) %s\n", i + 1, name);
2484 if (errno == ENOENT)
2487 lst_print_error("batch", "Failed to list batch: %s\n",
2492 fprintf(stdout, "Total %d batches\n", i);
2498 lst_list_tsb_nodes(char *batch, int test, int server,
2499 int count, int active, int invalid)
2501 lstcon_node_ent_t *dents;
2510 /* verbose list, show nodes in batch or test */
2511 dents = malloc(count * sizeof(lstcon_node_ent_t));
2512 if (dents == NULL) {
2513 fprintf(stdout, "Can't allocate memory\n");
2517 rc = lst_info_batch_ioctl(batch, test, server,
2518 NULL, &index, &count, dents);
2521 lst_print_error((test > 0) ? "test" : "batch",
2522 (test > 0) ? "Failed to query test: %s\n" :
2523 "Failed to query batch: %s\n",
2528 for (i = 0, c = 0; i < count; i++) {
2529 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2530 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2531 dents[i].nde_state == LST_NODE_DOWN ||
2532 dents[i].nde_state == LST_NODE_UNKNOWN)))
2535 fprintf(stdout, "\t%s: %s\n",
2536 libcfs_id2str(dents[i].nde_id),
2537 lst_node_state2str(dents[i].nde_state));
2541 fprintf(stdout, "Total %d nodes\n", c);
2548 jt_lst_list_batch(int argc, char **argv)
2550 lstcon_test_batch_ent_t ent;
2553 int verbose = 0; /* list nodes in batch or test */
2562 static struct option list_batch_opts[] =
2564 {"test", required_argument, 0, 't' },
2565 {"invalid", no_argument, 0, 'i' },
2566 {"active", no_argument, 0, 'a' },
2567 {"all", no_argument, 0, 'l' },
2568 {"server", no_argument, 0, 's' },
2572 if (session_key == 0) {
2574 "Can't find env LST_SESSION or value is not valid\n");
2579 c = getopt_long(argc, argv, "ailst:",
2580 list_batch_opts, &optidx);
2587 verbose = active = 1;
2590 verbose = invalid = 1;
2593 verbose = active = invalid = 1;
2599 test = atoi(optarg);
2603 lst_print_usage(argv[0]);
2608 if (optind == argc) {
2609 /* list all batches */
2610 rc = lst_list_batch_all();
2614 if (ntest == 1 && test <= 0) {
2615 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2619 if (optind != argc - 1) {
2620 lst_print_usage(argv[0]);
2624 batch = argv[optind];
2627 /* show detail of specified batch or test */
2628 rc = lst_info_batch_ioctl(batch, test, server,
2629 &ent, NULL, NULL, NULL);
2631 lst_print_error((test > 0) ? "test" : "batch",
2632 (test > 0) ? "Failed to query test: %s\n" :
2633 "Failed to query batch: %s\n",
2639 /* list nodes in test or batch */
2640 rc = lst_list_tsb_nodes(batch, test, server,
2641 server ? ent.tbe_srv_nle.nle_nnode :
2642 ent.tbe_cli_nle.nle_nnode,
2647 /* only show number of hosts in batch or test */
2649 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2650 batch, ent.u.tbe_batch.bae_ntest,
2651 ent.u.tbe_batch.bae_state);
2652 ntest = ent.u.tbe_batch.bae_ntest;
2653 test = 1; /* starting from test 1 */
2657 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2658 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2659 ent.u.tbe_test.tse_loop,
2660 ent.u.tbe_test.tse_concur);
2665 fprintf(stdout, LST_NODES_TITLE);
2666 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2667 "server\t%d\t%d\t%d\t%d\t%d\n",
2668 ent.tbe_cli_nle.nle_nactive,
2669 ent.tbe_cli_nle.nle_nbusy,
2670 ent.tbe_cli_nle.nle_ndown,
2671 ent.tbe_cli_nle.nle_nunknown,
2672 ent.tbe_cli_nle.nle_nnode,
2673 ent.tbe_srv_nle.nle_nactive,
2674 ent.tbe_srv_nle.nle_nbusy,
2675 ent.tbe_srv_nle.nle_ndown,
2676 ent.tbe_srv_nle.nle_nunknown,
2677 ent.tbe_srv_nle.nle_nnode);
2686 lst_query_batch_ioctl(char *batch, int test, int server,
2687 int timeout, struct list_head *head)
2689 lstio_batch_query_args_t args = {0};
2691 args.lstio_bat_key = session_key;
2692 args.lstio_bat_testidx = test;
2693 args.lstio_bat_client = !(server);
2694 args.lstio_bat_timeout = timeout;
2695 args.lstio_bat_nmlen = strlen(batch);
2696 args.lstio_bat_namep = batch;
2697 args.lstio_bat_resultp = head;
2699 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2703 lst_print_tsb_verbose(struct list_head *head,
2704 int active, int idle, int error)
2706 lstcon_rpc_ent_t *ent;
2708 list_for_each_entry(ent, head, rpe_link) {
2709 if (ent->rpe_priv[0] == 0 && active)
2712 if (ent->rpe_priv[0] != 0 && idle)
2715 if (ent->rpe_fwk_errno == 0 && error)
2718 fprintf(stdout, "%s [%s]: %s\n",
2719 libcfs_id2str(ent->rpe_peer),
2720 lst_node_state2str(ent->rpe_state),
2721 ent->rpe_rpc_errno != 0 ?
2722 strerror(ent->rpe_rpc_errno) :
2723 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2728 jt_lst_query_batch(int argc, char **argv)
2730 lstcon_test_batch_ent_t ent;
2731 struct list_head head;
2737 int timeout = 5; /* default 5 seconds */
2738 int delay = 5; /* default 5 seconds */
2739 int loop = 1; /* default 1 loop */
2749 static struct option query_batch_opts[] =
2751 {"timeout", required_argument, 0, 'o' },
2752 {"delay", required_argument, 0, 'd' },
2753 {"loop", required_argument, 0, 'c' },
2754 {"test", required_argument, 0, 't' },
2755 {"server", no_argument, 0, 's' },
2756 {"active", no_argument, 0, 'a' },
2757 {"idle", no_argument, 0, 'i' },
2758 {"error", no_argument, 0, 'e' },
2759 {"all", no_argument, 0, 'l' },
2763 if (session_key == 0) {
2765 "Can't find env LST_SESSION or value is not valid\n");
2770 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2771 query_batch_opts, &optidx);
2773 /* Detect the end of the options. */
2779 timeout = atoi(optarg);
2782 delay = atoi(optarg);
2785 loop = atoi(optarg);
2788 test = atoi(optarg);
2794 active = verbose = 1;
2800 error = verbose = 1;
2806 lst_print_usage(argv[0]);
2811 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2812 lst_print_usage(argv[0]);
2816 if (optind == argc) {
2817 batch = LST_DEFAULT_BATCH;
2819 } else if (optind == argc - 1) {
2820 batch = argv[optind];
2823 lst_print_usage(argv[0]);
2828 INIT_LIST_HEAD(&head);
2831 rc = lst_info_batch_ioctl(batch, test, server,
2832 &ent, NULL, NULL, NULL);
2834 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2835 batch, test, strerror(errno));
2839 count = server ? ent.tbe_srv_nle.nle_nnode :
2840 ent.tbe_cli_nle.nle_nnode;
2842 fprintf(stdout, "Batch or test is empty\n");
2847 rc = lst_alloc_rpcent(&head, count, 0);
2849 fprintf(stderr, "Out of memory\n");
2853 for (i = 0; i < loop; i++) {
2854 time_t now = time(NULL);
2856 if (now - last < delay) {
2857 sleep(delay - now + last);
2863 rc = lst_query_batch_ioctl(batch, test,
2864 server, timeout, &head);
2866 fprintf(stderr, "Failed to query batch: %s\n",
2873 lst_print_tsb_verbose(&head, active, idle, error);
2877 fprintf(stdout, "%s [%d] ", batch, test);
2879 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2880 fprintf(stdout, "%d of %d nodes are unknown, ",
2881 lstcon_rpc_stat_failure(&trans_stat, 0),
2882 lstcon_rpc_stat_total(&trans_stat, 0));
2885 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2886 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2887 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2888 fprintf(stdout, "is stopped\n");
2892 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2893 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2894 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2895 fprintf(stdout, "is running\n");
2899 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2900 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2901 lstcon_tsbqry_stat_run(&trans_stat, 0),
2902 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2905 lst_free_rpcent(&head);
2911 lst_parse_distribute(char *dstr, int *dist, int *span)
2917 dstr = strchr(dstr, ':');
2921 *span = atoi(dstr + 1);
2929 lst_get_bulk_param(int argc, char **argv, lst_test_bulk_param_t *bulk)
2936 bulk->blk_size = 4096;
2937 bulk->blk_opc = LST_BRW_READ;
2938 bulk->blk_flags = LST_BRW_CHECK_NONE;
2941 if (strcasestr(argv[i], "check=") == argv[i] ||
2942 strcasestr(argv[i], "c=") == argv[i]) {
2943 tok = strchr(argv[i], '=') + 1;
2945 if (strcasecmp(tok, "full") == 0) {
2946 bulk->blk_flags = LST_BRW_CHECK_FULL;
2947 } else if (strcasecmp(tok, "simple") == 0) {
2948 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2950 fprintf(stderr, "Unknow flag %s\n", tok);
2954 } else if (strcasestr(argv[i], "size=") == argv[i] ||
2955 strcasestr(argv[i], "s=") == argv[i]) {
2956 tok = strchr(argv[i], '=') + 1;
2958 bulk->blk_size = strtol(tok, &end, 0);
2959 if (bulk->blk_size <= 0) {
2960 fprintf(stderr, "Invalid size %s\n", tok);
2967 if (*end == 'k' || *end == 'K')
2968 bulk->blk_size *= 1024;
2969 else if (*end == 'm' || *end == 'M')
2970 bulk->blk_size *= 1024 * 1024;
2972 if (bulk->blk_size > PAGE_CACHE_SIZE * LNET_MAX_IOV) {
2973 fprintf(stderr, "Size exceed limitation: %d bytes\n",
2978 } else if (strcasecmp(argv[i], "read") == 0 ||
2979 strcasecmp(argv[i], "r") == 0) {
2980 bulk->blk_opc = LST_BRW_READ;
2982 } else if (strcasecmp(argv[i], "write") == 0 ||
2983 strcasecmp(argv[i], "w") == 0) {
2984 bulk->blk_opc = LST_BRW_WRITE;
2987 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
2998 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
3000 lst_test_bulk_param_t *bulk = NULL;
3003 type = lst_test_name2type(test);
3005 fprintf(stderr, "Unknow test name %s\n", test);
3014 bulk = malloc(sizeof(*bulk));
3016 fprintf(stderr, "Out of memory\n");
3020 memset(bulk, 0, sizeof(*bulk));
3022 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
3028 *plen = sizeof(*bulk);
3036 /* TODO: parse more parameter */
3041 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
3042 int dist, int span, char *sgrp, char *dgrp,
3043 void *param, int plen, int *retp, struct list_head *resultp)
3045 lstio_test_args_t args = {0};
3047 args.lstio_tes_key = session_key;
3048 args.lstio_tes_bat_nmlen = strlen(batch);
3049 args.lstio_tes_bat_name = batch;
3050 args.lstio_tes_type = type;
3051 args.lstio_tes_oneside = 0;
3052 args.lstio_tes_loop = loop;
3053 args.lstio_tes_concur = concur;
3054 args.lstio_tes_dist = dist;
3055 args.lstio_tes_span = span;
3056 args.lstio_tes_sgrp_nmlen = strlen(sgrp);
3057 args.lstio_tes_sgrp_name = sgrp;
3058 args.lstio_tes_dgrp_nmlen = strlen(dgrp);
3059 args.lstio_tes_dgrp_name = dgrp;
3060 args.lstio_tes_param_len = plen;
3061 args.lstio_tes_param = param;
3062 args.lstio_tes_retp = retp;
3063 args.lstio_tes_resultp = resultp;
3065 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
3069 jt_lst_add_test(int argc, char **argv)
3071 struct list_head head;
3091 static struct option add_test_opts[] =
3093 {"batch", required_argument, 0, 'b' },
3094 {"concurrency", required_argument, 0, 'c' },
3095 {"distribute", required_argument, 0, 'd' },
3096 {"from", required_argument, 0, 'f' },
3097 {"to", required_argument, 0, 't' },
3098 {"loop", required_argument, 0, 'l' },
3102 if (session_key == 0) {
3104 "Can't find env LST_SESSION or value is not valid\n");
3109 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3110 add_test_opts, &optidx);
3112 /* Detect the end of the options. */
3121 concur = atoi(optarg);
3130 loop = atoi(optarg);
3136 lst_print_usage(argv[0]);
3141 if (optind == argc || from == NULL || to == NULL) {
3142 lst_print_usage(argv[0]);
3146 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3147 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3152 batch = LST_DEFAULT_BATCH;
3155 rc = lst_parse_distribute(dstr, &dist, &span);
3157 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3162 test = argv[optind++];
3167 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3169 fprintf(stderr, "Failed to add test (%s)\n", test);
3173 INIT_LIST_HEAD(&head);
3175 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3177 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3178 from, strerror(errno));
3182 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3184 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3185 to, strerror(errno));
3189 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3191 fprintf(stderr, "Out of memory\n");
3195 rc = lst_add_test_ioctl(batch, type, loop, concur,
3196 dist, span, from, to, param, plen, &ret, &head);
3199 fprintf(stdout, "Test was added successfully\n");
3201 fprintf(stdout, "Server group contains userland test "
3202 "nodes, old version of tcplnd can't accept "
3203 "connection request\n");
3210 lst_print_error("test", "Failed to add test: %s\n",
3215 lst_print_transerr(&head, "add test");
3217 lst_free_rpcent(&head);
3225 static command_t lst_cmdlist[] = {
3226 {"new_session", jt_lst_new_session, NULL,
3227 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3228 {"end_session", jt_lst_end_session, NULL,
3229 "Usage: lst end_session" },
3230 {"show_session", jt_lst_show_session, NULL,
3231 "Usage: lst show_session" },
3232 {"ping", jt_lst_ping , NULL,
3233 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3234 {"add_group", jt_lst_add_group, NULL,
3235 "Usage: lst group NAME IDs [IDs]..." },
3236 {"del_group", jt_lst_del_group, NULL,
3237 "Usage: lst del_group NAME" },
3238 {"update_group", jt_lst_update_group, NULL,
3239 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3240 {"list_group", jt_lst_list_group, NULL,
3241 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3242 {"stat", jt_lst_stat, NULL,
3243 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3244 " [--timeout #] [--delay #] [--count #] GROUP [GROUP]" },
3245 {"show_error", jt_lst_show_error, NULL,
3246 "Usage: lst show_error NAME | IDS ..." },
3247 {"add_batch", jt_lst_add_batch, NULL,
3248 "Usage: lst add_batch NAME" },
3249 {"run", jt_lst_start_batch, NULL,
3250 "Usage: lst run [--timeout TIME] [NAME]" },
3251 {"stop", jt_lst_stop_batch, NULL,
3252 "Usage: lst stop [--force] BATCH_NAME" },
3253 {"list_batch", jt_lst_list_batch, NULL,
3254 "Usage: lst list_batch NAME [--test ID] [--server]" },
3255 {"query", jt_lst_query_batch, NULL,
3256 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3257 {"add_test", jt_lst_add_test, NULL,
3258 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3259 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3260 {"help", Parser_help, 0, "help" },
3265 lst_initialize(void)
3270 feats = getenv("LST_FEATURES");
3272 session_features = strtol(feats, NULL, 16);
3274 if ((session_features & ~LST_FEATS_MASK) != 0) {
3276 "Unsupported session features %x, "
3277 "only support these features so far: %x\n",
3278 (session_features & ~LST_FEATS_MASK), LST_FEATS_MASK);
3282 key = getenv("LST_SESSION");
3289 session_key = atoi(key);
3295 main(int argc, char **argv)
3301 rc = libcfs_arch_init();
3305 rc = lst_initialize();
3309 rc = ptl_initialize(argc, argv);
3313 Parser_init("lst > ", lst_cmdlist);
3316 rc = Parser_execarg(argc - 1, argv + 1, lst_cmdlist);
3323 libcfs_arch_cleanup();