4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/selftest/conctl.c
38 * Author: Liang Zhen <liangzhen@clusterfs.com>
41 #include <libcfs/libcfsutil.h>
42 #include <lnet/lnetctl.h>
43 #include <lnet/lnetst.h>
44 #include <lnet/nidstr.h>
45 /* NB: these includes are layering violation */
46 #include <lustre_ver.h>
47 #include <lustre/lustre_idl.h>
49 lst_sid_t LST_INVALID_SID = {LNET_NID_ANY, -1};
50 static lst_sid_t session_id;
51 static int session_key;
53 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 6, 50, 0)
54 /* assume all nodes can understand feature LST_FEAT_BULK_LEN */
55 static unsigned session_features = LST_FEATS_MASK;
57 static unsigned session_features = LST_FEATS_EMPTY;
60 static lstcon_trans_stat_t trans_stat;
62 typedef struct list_string {
63 struct list_string *lstr_next;
69 # define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
72 static int alloc_count = 0;
73 static int alloc_nob = 0;
78 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
81 fprintf(stderr, "Can't allocate lstr\n");
88 lstr->lstr_str[0] = 0;
94 free_lstr(lstr_t *lstr)
97 alloc_nob -= lstr->lstr_sz;
102 free_lstrs(lstr_t **list)
106 while ((lstr = *list) != NULL) {
107 *list = lstr->lstr_next;
113 new_lstrs(lstr_t **list, char *prefix, char *postfix,
114 int lo, int hi, int stride)
116 int n1 = strlen(prefix);
117 int n2 = strlen(postfix);
118 int sz = n1 + 20 + n2 + 1;
121 lstr_t *n = alloc_lstr(sz);
123 snprintf(n->lstr_str, sz - 1, "%s%u%s",
124 prefix, lo, postfix);
126 n->lstr_next = *list;
134 expand_lstr(lstr_t **list, lstr_t *l)
136 int nob = strlen(l->lstr_str);
146 b1 = strchr(l->lstr_str, '[');
148 l->lstr_next = *list;
153 b2 = strchr(b1, ']');
154 if (b2 == NULL || b2 == b1 + 1)
162 sep = strchr(expr, ',');
168 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
170 new_lstrs(list, l->lstr_str, b2, x, x, 1);
175 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
178 new_lstrs(list, l->lstr_str, b2, x, y, 1);
183 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
186 new_lstrs(list, l->lstr_str, b2, x, y, z);
192 } while ((expr = sep) != NULL);
200 expand_strs(char *str, lstr_t **head)
208 l = alloc_lstr(strlen(str) + 1);
209 memcpy(l->lstr_str, str, strlen(str) + 1);
217 while ((l = list) != NULL) {
220 rc = expand_lstr(&nlist, l);
222 fprintf(stderr, "Syntax error in \"%s\"\n", str);
230 /* re-order onto 'list' */
231 while ((l = nlist) != NULL) {
232 nlist = l->lstr_next;
237 } while (expanded && rc > 0);
244 while ((l = list) != NULL) {
253 lst_parse_nids(char *str, int *countp, lnet_process_id_t **idspp)
261 rc = expand_strs(str, &head);
271 *idspp = malloc(c * sizeof(lnet_process_id_t));
272 if (*idspp == NULL) {
273 fprintf(stderr, "Out of memory\n");
280 while ((l = head) != NULL) {
284 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
285 if ((*idspp)[i].nid == LNET_NID_ANY) {
286 fprintf(stderr, "Invalid nid: %s\n",
291 (*idspp)[i].pid = LUSTRE_LNET_PID;
308 lst_node_state2str(int state)
310 if (state == LST_NODE_ACTIVE)
312 if (state == LST_NODE_BUSY)
314 if (state == LST_NODE_DOWN)
321 lst_node_str2state(char *str)
323 if (strcasecmp(str, "active") == 0)
324 return LST_NODE_ACTIVE;
325 if (strcasecmp(str, "busy") == 0)
326 return LST_NODE_BUSY;
327 if (strcasecmp(str, "down") == 0)
328 return LST_NODE_DOWN;
329 if (strcasecmp(str, "unknown") == 0)
330 return LST_NODE_UNKNOWN;
331 if (strcasecmp(str, "invalid") == 0)
332 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
338 lst_test_type2name(int type)
340 if (type == LST_TEST_PING)
342 if (type == LST_TEST_BULK)
349 lst_test_name2type(char *name)
351 if (strcasecmp(name, "ping") == 0)
352 return LST_TEST_PING;
353 if (strcasecmp(name, "brw") == 0)
354 return LST_TEST_BULK;
360 lst_print_usage(char *cmd)
362 Parser_printhelp(cmd);
366 lst_print_error(char *sub, const char *def_format, ...)
370 /* local error returned from kernel */
373 fprintf(stderr, "No session exists\n");
376 fprintf(stderr, "Session is shutting down\n");
379 fprintf(stderr, "Unmatched session key or not root\n");
382 fprintf(stderr, "Can't find %s in current session\n", sub);
385 fprintf(stderr, "Invalid parameters list in command line\n");
388 fprintf(stderr, "Bad parameter address\n");
391 fprintf(stderr, "%s already exists\n", sub);
394 va_start(ap, def_format);
395 vfprintf(stderr, def_format, ap);
403 lst_free_rpcent(struct list_head *head)
405 lstcon_rpc_ent_t *ent;
407 while (!list_empty(head)) {
408 ent = list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
410 list_del(&ent->rpe_link);
416 lst_reset_rpcent(struct list_head *head)
418 lstcon_rpc_ent_t *ent;
420 list_for_each_entry(ent, head, rpe_link) {
421 ent->rpe_sid = LST_INVALID_SID;
422 ent->rpe_peer.nid = LNET_NID_ANY;
423 ent->rpe_peer.pid = LNET_PID_ANY;
424 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
429 lst_alloc_rpcent(struct list_head *head, int count, int offset)
431 lstcon_rpc_ent_t *ent;
434 for (i = 0; i < count; i++) {
435 ent = malloc(offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
437 lst_free_rpcent(head);
441 memset(ent, 0, offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
443 ent->rpe_sid = LST_INVALID_SID;
444 ent->rpe_peer.nid = LNET_NID_ANY;
445 ent->rpe_peer.pid = LNET_PID_ANY;
446 list_add(&ent->rpe_link, head);
453 lst_print_transerr(struct list_head *head, char *optstr)
455 lstcon_rpc_ent_t *ent;
457 list_for_each_entry(ent, head, rpe_link) {
458 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
461 if (ent->rpe_rpc_errno != 0) {
462 fprintf(stderr, "%s RPC failed on %s: %s\n",
463 optstr, libcfs_id2str(ent->rpe_peer),
464 strerror(ent->rpe_rpc_errno));
468 fprintf(stderr, "operation %s failed on %s: %s\n",
469 optstr, libcfs_id2str(ent->rpe_peer),
470 strerror(ent->rpe_fwk_errno));
474 int lst_info_batch_ioctl(char *batch, int test, int server,
475 lstcon_test_batch_ent_t *entp, int *idxp,
476 int *ndentp, lstcon_node_ent_t *dentsp);
478 int lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
479 int *idx, int *count, lstcon_node_ent_t *dents);
481 int lst_query_batch_ioctl(char *batch, int test, int server,
482 int timeout, struct list_head *head);
485 lst_ioctl(unsigned int opc, void *buf, int len)
487 struct libcfs_ioctl_data data;
490 LIBCFS_IOC_INIT (data);
491 data.ioc_u32[0] = opc;
492 data.ioc_plen1 = len;
493 data.ioc_pbuf1 = (char *)buf;
494 data.ioc_plen2 = sizeof(trans_stat);
495 data.ioc_pbuf2 = (char *)&trans_stat;
497 memset(&trans_stat, 0, sizeof(trans_stat));
499 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
501 /* local error, no valid RPC result */
506 if (trans_stat.trs_rpc_errno != 0)
509 /* Framework error */
510 if (trans_stat.trs_fwk_errno != 0)
517 lst_new_session_ioctl(char *name, int timeout, int force, lst_sid_t *sid)
519 lstio_session_new_args_t args = {0};
521 args.lstio_ses_key = session_key;
522 args.lstio_ses_timeout = timeout;
523 args.lstio_ses_force = force;
524 args.lstio_ses_idp = sid;
525 args.lstio_ses_feats = session_features;
526 args.lstio_ses_nmlen = strlen(name);
527 args.lstio_ses_namep = name;
529 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
533 jt_lst_new_session(int argc, char **argv)
535 char buf[LST_NAME_SIZE];
543 static struct option session_opts[] =
545 {"timeout", required_argument, 0, 't' },
546 {"force", no_argument, 0, 'f' },
550 if (session_key == 0) {
552 "Can't find env LST_SESSION or value is not valid\n");
558 c = getopt_long(argc, argv, "ft:",
559 session_opts, &optidx);
569 timeout = atoi(optarg);
572 lst_print_usage(argv[0]);
578 fprintf(stderr, "Invalid timeout value\n");
582 if (optind == argc - 1) {
583 name = argv[optind ++];
584 if (strlen(name) >= LST_NAME_SIZE) {
585 fprintf(stderr, "Name size is limited to %d\n",
590 } else if (optind == argc) {
591 char user[LST_NAME_SIZE];
592 char host[LST_NAME_SIZE];
593 struct passwd *pw = getpwuid(getuid());
596 snprintf(user, sizeof(user), "%d", (int)getuid());
598 snprintf(user, sizeof(user), "%s", pw->pw_name);
600 rc = gethostname(host, sizeof(host));
602 snprintf(host, sizeof(host), "unknown_host");
604 snprintf(buf, sizeof(buf), "%s@%s", user, host);
608 lst_print_usage(argv[0]);
612 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
614 lst_print_error("session", "Failed to create session: %s\n",
619 fprintf(stdout, "SESSION: %s FEATURES: %x TIMEOUT: %d FORCE: %s\n",
620 name, session_features, timeout, force ? "Yes" : "No");
625 lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp,
626 lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
628 lstio_session_info_args_t args = {0};
630 args.lstio_ses_idp = sid;
631 args.lstio_ses_keyp = key;
632 args.lstio_ses_featp = featp;
633 args.lstio_ses_ndinfo = ndinfo;
634 args.lstio_ses_nmlen = len;
635 args.lstio_ses_namep = name;
637 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
641 jt_lst_show_session(int argc, char **argv)
643 lstcon_ndlist_ent_t ndinfo;
645 char name[LST_NAME_SIZE];
650 rc = lst_session_info_ioctl(name, sizeof(name), &key,
651 &feats, &sid, &ndinfo);
654 lst_print_error("session", "Failed to show session: %s\n",
659 fprintf(stdout, "%s ID: "LPU64"@%s, KEY: %d FEATURES: %x NODES: %d\n",
660 name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
661 key, feats, ndinfo.nle_nnode);
667 lst_end_session_ioctl(void)
669 lstio_session_end_args_t args = {0};
671 args.lstio_ses_key = session_key;
672 return lst_ioctl (LSTIO_SESSION_END, &args, sizeof(args));
676 jt_lst_end_session(int argc, char **argv)
680 if (session_key == 0) {
682 "Can't find env LST_SESSION or value is not valid\n");
686 rc = lst_end_session_ioctl();
689 fprintf(stdout, "session is ended\n");
694 lst_print_error("session", "Failed to end session: %s\n",
699 if (trans_stat.trs_rpc_errno != 0) {
701 "[RPC] Failed to send %d session RPCs: %s\n",
702 lstcon_rpc_stat_failure(&trans_stat, 0),
703 strerror(trans_stat.trs_rpc_errno));
706 if (trans_stat.trs_fwk_errno != 0) {
708 "[FWK] Failed to end session on %d nodes: %s\n",
709 lstcon_sesop_stat_failure(&trans_stat, 0),
710 strerror(trans_stat.trs_fwk_errno));
717 lst_ping_ioctl(char *str, int type, int timeout,
718 int count, lnet_process_id_t *ids, struct list_head *head)
720 lstio_debug_args_t args = {0};
722 args.lstio_dbg_key = session_key;
723 args.lstio_dbg_type = type;
724 args.lstio_dbg_flags = 0;
725 args.lstio_dbg_timeout = timeout;
726 args.lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str);
727 args.lstio_dbg_namep = str;
728 args.lstio_dbg_count = count;
729 args.lstio_dbg_idsp = ids;
730 args.lstio_dbg_resultp = head;
732 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
736 lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
738 char buf[LST_NAME_SIZE];
739 lstcon_test_batch_ent_t ent;
740 lstcon_ndlist_ent_t *entp = &ent.tbe_cli_nle;
747 case LST_OPC_SESSION:
748 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
749 &key, &feats, &sid, entp);
752 case LST_OPC_BATCHSRV:
753 entp = &ent.tbe_srv_nle;
754 case LST_OPC_BATCHCLI:
755 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
759 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
763 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
772 *countp = entp->nle_nnode;
778 jt_lst_ping(int argc, char **argv)
780 struct list_head head;
781 lnet_process_id_t *ids = NULL;
782 lstcon_rpc_ent_t *ent = NULL;
792 static struct option ping_opts[] =
794 {"session", no_argument, 0, 's' },
795 {"server", no_argument, 0, 'v' },
796 {"batch", required_argument, 0, 'b' },
797 {"group", required_argument, 0, 'g' },
798 {"nodes", required_argument, 0, 'n' },
799 {"timeout", required_argument, 0, 't' },
803 if (session_key == 0) {
805 "Can't find env LST_SESSION or value is not valid\n");
811 c = getopt_long(argc, argv, "g:b:n:t:sv",
819 type = LST_OPC_SESSION;
823 type = LST_OPC_GROUP;
828 type = LST_OPC_BATCHCLI;
833 type = LST_OPC_NODES;
838 timeout = atoi(optarg);
846 lst_print_usage(argv[0]);
851 if (type == 0 || timeout <= 0 || optind != argc) {
852 lst_print_usage(argv[0]);
856 if (type == LST_OPC_BATCHCLI && server)
857 type = LST_OPC_BATCHSRV;
859 rc = lst_get_node_count(type, str, &count, &ids);
861 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
862 (str == NULL) ? "session" : str, strerror(errno));
866 INIT_LIST_HEAD(&head);
868 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
870 fprintf(stderr, "Out of memory\n");
875 fprintf(stdout, "Target %s is empty\n",
876 (str == NULL) ? "session" : str);
880 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
881 if (rc == -1) { /* local failure */
882 lst_print_error("debug", "Failed to ping %s: %s\n",
883 (str == NULL) ? "session" : str,
889 /* ignore RPC errors and framwork errors */
890 list_for_each_entry(ent, &head, rpe_link) {
891 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
892 libcfs_id2str(ent->rpe_peer),
893 lst_node_state2str(ent->rpe_state),
894 (ent->rpe_state == LST_NODE_ACTIVE ||
895 ent->rpe_state == LST_NODE_BUSY) ?
896 (ent->rpe_rpc_errno == 0 ?
897 &ent->rpe_payload[0] : "Unknown") :
898 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
902 lst_free_rpcent(&head);
912 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
913 unsigned *featp, struct list_head *resultp)
915 lstio_group_nodes_args_t args = {0};
917 args.lstio_grp_key = session_key;
918 args.lstio_grp_nmlen = strlen(name);
919 args.lstio_grp_namep = name;
920 args.lstio_grp_count = count;
921 args.lstio_grp_featp = featp;
922 args.lstio_grp_idsp = ids;
923 args.lstio_grp_resultp = resultp;
925 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
929 lst_del_group_ioctl(char *name)
931 lstio_group_del_args_t args = {0};
933 args.lstio_grp_key = session_key;
934 args.lstio_grp_nmlen = strlen(name);
935 args.lstio_grp_namep = name;
937 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
941 lst_del_group(char *grp_name)
945 rc = lst_del_group_ioctl(grp_name);
947 fprintf(stdout, "Group is deleted\n");
952 lst_print_error("group", "Failed to delete group: %s\n",
957 fprintf(stderr, "Group is deleted with some errors\n");
959 if (trans_stat.trs_rpc_errno != 0) {
961 "[RPC] Failed to send %d end session RPCs: %s\n",
962 lstcon_rpc_stat_failure(&trans_stat, 0),
963 strerror(trans_stat.trs_rpc_errno));
966 if (trans_stat.trs_fwk_errno != 0) {
968 "[FWK] Failed to end session on %d nodes: %s\n",
969 lstcon_sesop_stat_failure(&trans_stat, 0),
970 strerror(trans_stat.trs_fwk_errno));
977 lst_add_group_ioctl (char *name)
979 lstio_group_add_args_t args = {0};
981 args.lstio_grp_key = session_key;
982 args.lstio_grp_nmlen = strlen(name);
983 args.lstio_grp_namep = name;
985 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
989 jt_lst_add_group(int argc, char **argv)
991 struct list_head head;
992 lnet_process_id_t *ids;
994 unsigned feats = session_features;
998 bool nodes_added = false;
1000 if (session_key == 0) {
1002 "Can't find env LST_SESSION or value is not valid\n");
1007 lst_print_usage(argv[0]);
1012 if (strlen(name) >= LST_NAME_SIZE) {
1013 fprintf(stderr, "Name length is limited to %d\n",
1018 rc = lst_add_group_ioctl(name);
1020 lst_print_error("group", "Failed to add group %s: %s\n",
1021 name, strerror(errno));
1025 INIT_LIST_HEAD(&head);
1027 for (i = 2; i < argc; i++) {
1028 /* parse address list */
1029 rc = lst_parse_nids(argv[i], &count, &ids);
1031 fprintf(stderr, "Ignore invalid id list %s\n",
1039 rc = lst_alloc_rpcent(&head, count, 0);
1041 fprintf(stderr, "Out of memory\n");
1047 rc = lst_add_nodes_ioctl(name, count, ids, &feats, &head);
1054 fprintf(stdout, "%s are added to session\n", argv[i]);
1058 if ((feats & session_features) != session_features) {
1060 "Warning, this session will run with "
1061 "compatible mode because some test nodes "
1062 "might not understand these features: %x\n",
1063 (~feats & session_features));
1066 lst_free_rpcent(&head);
1071 * The selftest kernel module expects that a group should
1072 * have at least one node, since it doesn't make sense for
1073 * an empty group to be added to a test.
1076 "No nodes added successfully, deleting group %s\n",
1078 rc = lst_del_group(name);
1081 "Failed to delete group %s."
1082 " Group is empty.\n", name);
1090 lst_print_error("group", "Failed to add nodes %s: %s\n",
1091 argv[i], strerror(errno));
1094 if (trans_stat.trs_fwk_errno == EPROTO) {
1096 "test nodes might have different LST "
1097 "features, please disable some features by "
1098 "setting LST_FEATURES\n");
1101 lst_print_transerr(&head, "create session");
1104 lst_free_rpcent(&head);
1108 "No nodes added successfully, deleting group %s\n",
1110 if (lst_del_group(name) != 0) {
1112 "Failed to delete group %s."
1113 " Group is empty.\n", name);
1121 jt_lst_del_group(int argc, char **argv)
1125 if (session_key == 0) {
1127 "Can't find env LST_SESSION or value is not valid\n");
1132 lst_print_usage(argv[0]);
1136 rc = lst_del_group(argv[1]);
1142 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1143 lnet_process_id_t *ids, struct list_head *resultp)
1145 lstio_group_update_args_t args = {0};
1147 args.lstio_grp_key = session_key;
1148 args.lstio_grp_opc = opc;
1149 args.lstio_grp_args = clean;
1150 args.lstio_grp_nmlen = strlen(name);
1151 args.lstio_grp_namep = name;
1152 args.lstio_grp_count = count;
1153 args.lstio_grp_idsp = ids;
1154 args.lstio_grp_resultp = resultp;
1156 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1160 jt_lst_update_group(int argc, char **argv)
1162 struct list_head head;
1163 lnet_process_id_t *ids = NULL;
1173 static struct option update_group_opts[] =
1175 {"refresh", no_argument, 0, 'f' },
1176 {"clean", required_argument, 0, 'c' },
1177 {"remove", required_argument, 0, 'r' },
1181 if (session_key == 0) {
1183 "Can't find env LST_SESSION or value is not valid\n");
1188 c = getopt_long(argc, argv, "fc:r:",
1189 update_group_opts, &optidx);
1191 /* Detect the end of the options. */
1198 lst_print_usage(argv[0]);
1201 opc = LST_GROUP_REFRESH;
1206 lst_print_usage(argv[0]);
1209 opc = LST_GROUP_RMND;
1214 clean = lst_node_str2state(optarg);
1215 if (opc != 0 || clean <= 0) {
1216 lst_print_usage(argv[0]);
1219 opc = LST_GROUP_CLEAN;
1223 lst_print_usage(argv[0]);
1228 /* no OPC or group is specified */
1229 if (opc == 0 || optind != argc - 1) {
1230 lst_print_usage(argv[0]);
1236 INIT_LIST_HEAD(&head);
1238 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1239 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1241 opc == LST_GROUP_RMND ? str : grp,
1245 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1246 opc == LST_GROUP_RMND ? str : grp,
1251 rc = lst_alloc_rpcent(&head, count, 0);
1253 fprintf(stderr, "Out of memory\n");
1260 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1266 lst_free_rpcent(&head);
1271 lst_free_rpcent(&head);
1272 lst_print_error("group", "Failed to update group: %s\n",
1277 lst_print_transerr(&head, "Updating group");
1279 lst_free_rpcent(&head);
1285 lst_list_group_ioctl(int len, char *name, int idx)
1287 lstio_group_list_args_t args = {0};
1289 args.lstio_grp_key = session_key;
1290 args.lstio_grp_idx = idx;
1291 args.lstio_grp_nmlen = len;
1292 args.lstio_grp_namep = name;
1294 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1298 lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
1299 int *idx, int *count, lstcon_node_ent_t *dents)
1301 lstio_group_info_args_t args = {0};
1303 args.lstio_grp_key = session_key;
1304 args.lstio_grp_nmlen = strlen(name);
1305 args.lstio_grp_namep = name;
1306 args.lstio_grp_entp = gent;
1307 args.lstio_grp_idxp = idx;
1308 args.lstio_grp_ndentp = count;
1309 args.lstio_grp_dentsp = dents;
1311 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1315 lst_list_group_all(void)
1317 char name[LST_NAME_SIZE];
1321 /* no group is specified, list name of all groups */
1322 for (i = 0; ; i++) {
1323 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1325 fprintf(stdout, "%d) %s\n", i + 1, name);
1329 if (errno == ENOENT)
1332 lst_print_error("group", "Failed to list group: %s\n",
1337 fprintf(stdout, "Total %d groups\n", i);
1342 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1345 jt_lst_list_group(int argc, char **argv)
1347 lstcon_ndlist_ent_t gent;
1348 lstcon_node_ent_t *dents;
1363 static struct option list_group_opts[] =
1365 {"active", no_argument, 0, 'a' },
1366 {"busy", no_argument, 0, 'b' },
1367 {"down", no_argument, 0, 'd' },
1368 {"unknown", no_argument, 0, 'u' },
1369 {"all", no_argument, 0, 'l' },
1373 if (session_key == 0) {
1375 "Can't find env LST_SESSION or value is not valid\n");
1380 c = getopt_long(argc, argv, "abdul",
1381 list_group_opts, &optidx);
1388 verbose = active = 1;
1400 verbose = unknown = 1;
1407 lst_print_usage(argv[0]);
1412 if (optind == argc) {
1413 /* no group is specified, list name of all groups */
1414 rc = lst_list_group_all();
1420 fprintf(stdout, LST_NODES_TITLE);
1422 /* list nodes in specified groups */
1423 for (i = optind; i < argc; i++) {
1424 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1426 if (errno == ENOENT) {
1431 lst_print_error("group", "Failed to list group\n",
1437 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1438 gent.nle_nactive, gent.nle_nbusy,
1439 gent.nle_ndown, gent.nle_nunknown,
1440 gent.nle_nnode, argv[i]);
1444 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1446 if (gent.nle_nnode == 0) {
1447 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1451 count = gent.nle_nnode;
1453 dents = malloc(count * sizeof(lstcon_node_ent_t));
1454 if (dents == NULL) {
1455 fprintf(stderr, "Failed to malloc: %s\n",
1461 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1463 lst_print_error("group", "Failed to list group: %s\n",
1469 for (j = 0, c = 0; j < count; j++) {
1471 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1472 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1473 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1474 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1476 fprintf(stdout, "\t%s: %s\n",
1477 libcfs_id2str(dents[j].nde_id),
1478 lst_node_state2str(dents[j].nde_state));
1483 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1492 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
1493 int timeout, struct list_head *resultp)
1495 lstio_stat_args_t args = {0};
1497 args.lstio_sta_key = session_key;
1498 args.lstio_sta_timeout = timeout;
1499 args.lstio_sta_nmlen = strlen(name);
1500 args.lstio_sta_namep = name;
1501 args.lstio_sta_count = count;
1502 args.lstio_sta_idsp = idsp;
1503 args.lstio_sta_resultp = resultp;
1505 return lst_ioctl (LSTIO_STAT_QUERY, &args, sizeof(args));
1509 struct list_head srp_link;
1512 lnet_process_id_t *srp_ids;
1513 struct list_head srp_result[2];
1514 } lst_stat_req_param_t;
1517 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1521 for (i = 0; i < 2; i++)
1522 lst_free_rpcent(&srp->srp_result[i]);
1524 if (srp->srp_ids != NULL)
1531 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
1533 lst_stat_req_param_t *srp = NULL;
1534 int count = save_old ? 2 : 1;
1538 srp = malloc(sizeof(*srp));
1542 memset(srp, 0, sizeof(*srp));
1543 INIT_LIST_HEAD(&srp->srp_result[0]);
1544 INIT_LIST_HEAD(&srp->srp_result[1]);
1546 rc = lst_get_node_count(LST_OPC_GROUP, name,
1547 &srp->srp_count, NULL);
1548 if (rc != 0 && errno == ENOENT) {
1549 rc = lst_get_node_count(LST_OPC_NODES, name,
1550 &srp->srp_count, &srp->srp_ids);
1555 "Failed to get count of nodes from %s: %s\n",
1556 name, strerror(errno));
1557 lst_stat_req_param_free(srp);
1562 srp->srp_name = name;
1564 for (i = 0; i < count; i++) {
1565 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1566 sizeof(sfw_counters_t) +
1567 sizeof(srpc_counters_t) +
1568 sizeof(lnet_counters_t));
1570 fprintf(stderr, "Out of memory\n");
1580 lst_stat_req_param_free(srp);
1588 } lst_srpc_stat_result;
1590 #define LST_LNET_AVG 0
1591 #define LST_LNET_MIN 1
1592 #define LST_LNET_MAX 2
1595 float lnet_avg_sndrate;
1596 float lnet_min_sndrate;
1597 float lnet_max_sndrate;
1598 float lnet_total_sndrate;
1600 float lnet_avg_rcvrate;
1601 float lnet_min_rcvrate;
1602 float lnet_max_rcvrate;
1603 float lnet_total_rcvrate;
1605 float lnet_avg_sndperf;
1606 float lnet_min_sndperf;
1607 float lnet_max_sndperf;
1608 float lnet_total_sndperf;
1610 float lnet_avg_rcvperf;
1611 float lnet_min_rcvperf;
1612 float lnet_max_rcvperf;
1613 float lnet_total_rcvperf;
1615 int lnet_stat_count;
1616 } lst_lnet_stat_result_t;
1618 lst_lnet_stat_result_t lnet_stat_result;
1621 lst_lnet_stat_value(int bw, int send, int off)
1625 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1626 &lnet_stat_result.lnet_avg_sndrate;
1637 lst_timeval_diff(struct timeval *tv1,
1638 struct timeval *tv2, struct timeval *df)
1640 if (tv1->tv_usec >= tv2->tv_usec) {
1641 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1642 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1646 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1647 df->tv_usec = tv1->tv_usec + 1000000 - tv2->tv_usec;
1653 lst_cal_lnet_stat(float delta, lnet_counters_t *lnet_new,
1654 lnet_counters_t *lnet_old)
1659 perf = (float)(lnet_new->send_length -
1660 lnet_old->send_length) / (1024 * 1024) / delta;
1661 lnet_stat_result.lnet_total_sndperf += perf;
1663 if (lnet_stat_result.lnet_min_sndperf > perf ||
1664 lnet_stat_result.lnet_min_sndperf == 0)
1665 lnet_stat_result.lnet_min_sndperf = perf;
1667 if (lnet_stat_result.lnet_max_sndperf < perf)
1668 lnet_stat_result.lnet_max_sndperf = perf;
1670 perf = (float)(lnet_new->recv_length -
1671 lnet_old->recv_length) / (1024 * 1024) / delta;
1672 lnet_stat_result.lnet_total_rcvperf += perf;
1674 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1675 lnet_stat_result.lnet_min_rcvperf == 0)
1676 lnet_stat_result.lnet_min_rcvperf = perf;
1678 if (lnet_stat_result.lnet_max_rcvperf < perf)
1679 lnet_stat_result.lnet_max_rcvperf = perf;
1681 rate = (lnet_new->send_count - lnet_old->send_count) / delta;
1682 lnet_stat_result.lnet_total_sndrate += rate;
1684 if (lnet_stat_result.lnet_min_sndrate > rate ||
1685 lnet_stat_result.lnet_min_sndrate == 0)
1686 lnet_stat_result.lnet_min_sndrate = rate;
1688 if (lnet_stat_result.lnet_max_sndrate < rate)
1689 lnet_stat_result.lnet_max_sndrate = rate;
1691 rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
1692 lnet_stat_result.lnet_total_rcvrate += rate;
1694 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1695 lnet_stat_result.lnet_min_rcvrate == 0)
1696 lnet_stat_result.lnet_min_rcvrate = rate;
1698 if (lnet_stat_result.lnet_max_rcvrate < rate)
1699 lnet_stat_result.lnet_max_rcvrate = rate;
1701 lnet_stat_result.lnet_stat_count ++;
1703 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1704 lnet_stat_result.lnet_stat_count;
1705 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1706 lnet_stat_result.lnet_stat_count;
1708 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1709 lnet_stat_result.lnet_stat_count;
1710 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1711 lnet_stat_result.lnet_stat_count;
1716 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
1725 if (lnet_stat_result.lnet_stat_count == 0)
1728 if (bwrt == 1) /* bw only */
1731 if (bwrt == 2) /* rates only */
1734 if (rdwr == 1) /* recv only */
1737 if (rdwr == 2) /* send only */
1740 for (i = start1; i <= end1; i++) {
1741 fprintf(stdout, "[LNet %s of %s]\n",
1742 i == 0 ? "Rates" : "Bandwidth", name);
1744 for (j = start2; j <= end2; j++) {
1745 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
1747 if ((type & 1) != 0) {
1748 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1749 "Avg: %-8.2f MB/s ",
1750 lst_lnet_stat_value(i, j, 0));
1753 if ((type & 2) != 0) {
1754 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1755 "Min: %-8.2f MB/s ",
1756 lst_lnet_stat_value(i, j, 1));
1759 if ((type & 4) != 0) {
1760 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1762 lst_lnet_stat_value(i, j, 2));
1765 fprintf(stdout, "\n");
1771 lst_print_stat(char *name, struct list_head *resultp,
1772 int idx, int lnet, int bwrt, int rdwr, int type)
1774 struct list_head tmp[2];
1775 lstcon_rpc_ent_t *new;
1776 lstcon_rpc_ent_t *old;
1777 sfw_counters_t *sfwk_new;
1778 sfw_counters_t *sfwk_old;
1779 srpc_counters_t *srpc_new;
1780 srpc_counters_t *srpc_old;
1781 lnet_counters_t *lnet_new;
1782 lnet_counters_t *lnet_old;
1786 INIT_LIST_HEAD(&tmp[0]);
1787 INIT_LIST_HEAD(&tmp[1]);
1789 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1791 while (!list_empty(&resultp[idx])) {
1792 if (list_empty(&resultp[1 - idx])) {
1793 fprintf(stderr, "Group is changed, re-run stat\n");
1797 new = list_entry(resultp[idx].next, lstcon_rpc_ent_t,
1799 old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t,
1802 /* first time get stats result, can't calculate diff */
1803 if (new->rpe_peer.nid == LNET_NID_ANY)
1806 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1807 new->rpe_peer.pid != old->rpe_peer.pid) {
1808 /* Something wrong. i.e, somebody change the group */
1812 list_del(&new->rpe_link);
1813 list_add_tail(&new->rpe_link, &tmp[idx]);
1815 list_del(&old->rpe_link);
1816 list_add_tail(&old->rpe_link, &tmp[1 - idx]);
1818 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1819 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1824 sfwk_new = (sfw_counters_t *)&new->rpe_payload[0];
1825 sfwk_old = (sfw_counters_t *)&old->rpe_payload[0];
1827 srpc_new = (srpc_counters_t *)((char *)sfwk_new + sizeof(*sfwk_new));
1828 srpc_old = (srpc_counters_t *)((char *)sfwk_old + sizeof(*sfwk_old));
1830 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
1831 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
1833 /* Prior to version 2.3, the running_ms field was a counter for
1834 * the number of running tests. We are looking at this value
1835 * to determine if it is a millisecond timestamep (>= 2.3) or a
1836 * test counter (< 2.3). The number 500 is being used for this
1837 * barrier as the test counter should never get this high, and
1838 * the timestamp should never get this low. */
1840 if (sfwk_new->running_ms > 500) {
1841 /* use the timestamp from the remote node, not our
1842 * rpe_stamp from when we copied up the data out of
1845 delta = (float) (sfwk_new->running_ms -
1846 sfwk_old->running_ms) / 1000;
1850 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1851 delta = tv.tv_sec + (float)tv.tv_usec / 1000000;
1854 if (!lnet) /* TODO */
1857 lst_cal_lnet_stat(delta, lnet_new, lnet_old);
1860 list_splice(&tmp[idx], &resultp[idx]);
1861 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1864 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1866 if (!lnet) /* TODO */
1869 lst_print_lnet_stat(name, bwrt, rdwr, type);
1873 jt_lst_stat(int argc, char **argv)
1875 struct list_head head;
1876 lst_stat_req_param_t *srp;
1879 int timeout = 5; /* default timeout, 5 sec */
1880 int delay = 5; /* default delay, 5 sec */
1881 int count = -1; /* run forever */
1882 int lnet = 1; /* lnet stat by default */
1890 static struct option stat_opts[] =
1892 {"timeout" , required_argument, 0, 't' },
1893 {"delay" , required_argument, 0, 'd' },
1894 {"count" , required_argument, 0, 'o' },
1895 {"lnet" , no_argument, 0, 'l' },
1896 {"rpc" , no_argument, 0, 'c' },
1897 {"bw" , no_argument, 0, 'b' },
1898 {"rate" , no_argument, 0, 'a' },
1899 {"read" , no_argument, 0, 'r' },
1900 {"write" , no_argument, 0, 'w' },
1901 {"avg" , no_argument, 0, 'g' },
1902 {"min" , no_argument, 0, 'n' },
1903 {"max" , no_argument, 0, 'x' },
1907 if (session_key == 0) {
1909 "Can't find env LST_SESSION or value is not valid\n");
1914 c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
1921 timeout = atoi(optarg);
1924 delay = atoi(optarg);
1927 count = atoi(optarg);
1970 lst_print_usage(argv[0]);
1975 if (optind == argc) {
1976 lst_print_usage(argv[0]);
1980 if (timeout <= 0 || delay <= 0) {
1981 fprintf(stderr, "Invalid timeout or delay value\n");
1986 fprintf(stderr, "Invalid count value\n");
1990 /* extra count to get first data point */
1994 INIT_LIST_HEAD(&head);
1996 while (optind < argc) {
1997 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
2001 list_add_tail(&srp->srp_link, &head);
2005 time_t now = time(NULL);
2007 if (now - last < delay) {
2008 sleep(delay - now + last);
2013 list_for_each_entry(srp, &head, srp_link) {
2014 rc = lst_stat_ioctl(srp->srp_name,
2015 srp->srp_count, srp->srp_ids,
2016 timeout, &srp->srp_result[idx]);
2018 lst_print_error("stat", "Failed to stat %s: %s\n",
2019 srp->srp_name, strerror(errno));
2023 lst_print_stat(srp->srp_name, srp->srp_result,
2024 idx, lnet, bwrt, rdwr, type);
2026 lst_reset_rpcent(&srp->srp_result[1 - idx]);
2033 } while (count == -1 || count > 0);
2036 while (!list_empty(&head)) {
2037 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2039 list_del(&srp->srp_link);
2040 lst_stat_req_param_free(srp);
2047 jt_lst_show_error(int argc, char **argv)
2049 struct list_head head;
2050 lst_stat_req_param_t *srp;
2051 lstcon_rpc_ent_t *ent;
2052 sfw_counters_t *sfwk;
2053 srpc_counters_t *srpc;
2060 static struct option show_error_opts[] =
2062 {"session", no_argument, 0, 's' },
2066 if (session_key == 0) {
2068 "Can't find env LST_SESSION or value is not valid\n");
2073 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
2084 lst_print_usage(argv[0]);
2089 if (optind == argc) {
2090 lst_print_usage(argv[0]);
2094 INIT_LIST_HEAD(&head);
2096 while (optind < argc) {
2097 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
2101 list_add_tail(&srp->srp_link, &head);
2104 list_for_each_entry(srp, &head, srp_link) {
2105 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
2106 srp->srp_ids, 10, &srp->srp_result[0]);
2109 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2110 srp->srp_name, strerror(errno));
2114 fprintf(stdout, "%s:\n", srp->srp_name);
2118 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2119 if (ent->rpe_rpc_errno != 0) {
2121 fprintf(stderr, "RPC failure, can't show error on %s\n",
2122 libcfs_id2str(ent->rpe_peer));
2126 if (ent->rpe_fwk_errno != 0) {
2128 fprintf(stderr, "Framework failure, can't show error on %s\n",
2129 libcfs_id2str(ent->rpe_peer));
2133 sfwk = (sfw_counters_t *)&ent->rpe_payload[0];
2134 srpc = (srpc_counters_t *)((char *)sfwk + sizeof(*sfwk));
2136 if (srpc->errors == 0 &&
2137 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2141 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2146 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2147 libcfs_id2str(ent->rpe_peer),
2148 sfwk->brw_errors, sfwk->ping_errors,
2149 show_rpc ? ' ' : '\n');
2154 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2155 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2158 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2161 while (!list_empty(&head)) {
2162 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2164 list_del(&srp->srp_link);
2165 lst_stat_req_param_free(srp);
2172 lst_add_batch_ioctl (char *name)
2174 lstio_batch_add_args_t args = {0};
2176 args.lstio_bat_key = session_key;
2177 args.lstio_bat_nmlen = strlen(name);
2178 args.lstio_bat_namep = name;
2180 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2184 jt_lst_add_batch(int argc, char **argv)
2189 if (session_key == 0) {
2191 "Can't find env LST_SESSION or value is not valid\n");
2196 lst_print_usage(argv[0]);
2201 if (strlen(name) >= LST_NAME_SIZE) {
2202 fprintf(stderr, "Name length is limited to %d\n",
2207 rc = lst_add_batch_ioctl(name);
2211 lst_print_error("batch", "Failed to create batch: %s\n",
2218 lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp)
2220 lstio_batch_run_args_t args = {0};
2222 args.lstio_bat_key = session_key;
2223 args.lstio_bat_timeout = timeout;
2224 args.lstio_bat_nmlen = strlen(name);
2225 args.lstio_bat_namep = name;
2226 args.lstio_bat_resultp = resultp;
2228 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2232 jt_lst_start_batch(int argc, char **argv)
2234 struct list_head head;
2242 static struct option start_batch_opts[] =
2244 {"timeout", required_argument, 0, 't' },
2248 if (session_key == 0) {
2250 "Can't find env LST_SESSION or value is not valid\n");
2255 c = getopt_long(argc, argv, "t:",
2256 start_batch_opts, &optidx);
2258 /* Detect the end of the options. */
2264 timeout = atoi(optarg);
2267 lst_print_usage(argv[0]);
2272 if (optind == argc) {
2273 batch = LST_DEFAULT_BATCH;
2275 } else if (optind == argc - 1) {
2276 batch = argv[optind];
2279 lst_print_usage(argv[0]);
2283 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2285 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2286 batch, strerror(errno));
2290 INIT_LIST_HEAD(&head);
2292 rc = lst_alloc_rpcent(&head, count, 0);
2294 fprintf(stderr, "Out of memory\n");
2298 rc = lst_start_batch_ioctl(batch, timeout, &head);
2301 fprintf(stdout, "%s is running now\n", batch);
2302 lst_free_rpcent(&head);
2307 lst_print_error("batch", "Failed to start batch: %s\n",
2309 lst_free_rpcent(&head);
2313 lst_print_transerr(&head, "Run batch");
2315 lst_free_rpcent(&head);
2321 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2323 lstio_batch_stop_args_t args = {0};
2325 args.lstio_bat_key = session_key;
2326 args.lstio_bat_force = force;
2327 args.lstio_bat_nmlen = strlen(name);
2328 args.lstio_bat_namep = name;
2329 args.lstio_bat_resultp = resultp;
2331 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2335 jt_lst_stop_batch(int argc, char **argv)
2337 struct list_head head;
2345 static struct option stop_batch_opts[] =
2347 {"force", no_argument, 0, 'f' },
2351 if (session_key == 0) {
2353 "Can't find env LST_SESSION or value is not valid\n");
2358 c = getopt_long(argc, argv, "f",
2359 stop_batch_opts, &optidx);
2361 /* Detect the end of the options. */
2370 lst_print_usage(argv[0]);
2375 if (optind == argc) {
2376 batch = LST_DEFAULT_BATCH;
2378 } else if (optind == argc - 1) {
2379 batch = argv[optind];
2382 lst_print_usage(argv[0]);
2386 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2388 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2389 batch, strerror(errno));
2393 INIT_LIST_HEAD(&head);
2395 rc = lst_alloc_rpcent(&head, count, 0);
2397 fprintf(stderr, "Out of memory\n");
2401 rc = lst_stop_batch_ioctl(batch, force, &head);
2406 lst_reset_rpcent(&head);
2408 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2412 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2413 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2416 fprintf(stdout, "%d batch in stopping\n",
2417 lstcon_tsbqry_stat_run(&trans_stat, 0));
2421 fprintf(stdout, "Batch is stopped\n");
2422 lst_free_rpcent(&head);
2427 lst_print_error("batch", "Failed to stop batch: %s\n",
2429 lst_free_rpcent(&head);
2433 lst_print_transerr(&head, "stop batch");
2435 lst_free_rpcent(&head);
2441 lst_list_batch_ioctl(int len, char *name, int index)
2443 lstio_batch_list_args_t args = {0};
2445 args.lstio_bat_key = session_key;
2446 args.lstio_bat_idx = index;
2447 args.lstio_bat_nmlen = len;
2448 args.lstio_bat_namep = name;
2450 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2454 lst_info_batch_ioctl(char *batch, int test, int server,
2455 lstcon_test_batch_ent_t *entp, int *idxp,
2456 int *ndentp, lstcon_node_ent_t *dentsp)
2458 lstio_batch_info_args_t args = {0};
2460 args.lstio_bat_key = session_key;
2461 args.lstio_bat_nmlen = strlen(batch);
2462 args.lstio_bat_namep = batch;
2463 args.lstio_bat_server = server;
2464 args.lstio_bat_testidx = test;
2465 args.lstio_bat_entp = entp;
2466 args.lstio_bat_idxp = idxp;
2467 args.lstio_bat_ndentp = ndentp;
2468 args.lstio_bat_dentsp = dentsp;
2470 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2474 lst_list_batch_all(void)
2476 char name[LST_NAME_SIZE];
2480 for (i = 0; ; i++) {
2481 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2483 fprintf(stdout, "%d) %s\n", i + 1, name);
2487 if (errno == ENOENT)
2490 lst_print_error("batch", "Failed to list batch: %s\n",
2495 fprintf(stdout, "Total %d batches\n", i);
2501 lst_list_tsb_nodes(char *batch, int test, int server,
2502 int count, int active, int invalid)
2504 lstcon_node_ent_t *dents;
2513 /* verbose list, show nodes in batch or test */
2514 dents = malloc(count * sizeof(lstcon_node_ent_t));
2515 if (dents == NULL) {
2516 fprintf(stdout, "Can't allocate memory\n");
2520 rc = lst_info_batch_ioctl(batch, test, server,
2521 NULL, &index, &count, dents);
2524 lst_print_error((test > 0) ? "test" : "batch",
2525 (test > 0) ? "Failed to query test: %s\n" :
2526 "Failed to query batch: %s\n",
2531 for (i = 0, c = 0; i < count; i++) {
2532 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2533 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2534 dents[i].nde_state == LST_NODE_DOWN ||
2535 dents[i].nde_state == LST_NODE_UNKNOWN)))
2538 fprintf(stdout, "\t%s: %s\n",
2539 libcfs_id2str(dents[i].nde_id),
2540 lst_node_state2str(dents[i].nde_state));
2544 fprintf(stdout, "Total %d nodes\n", c);
2551 jt_lst_list_batch(int argc, char **argv)
2553 lstcon_test_batch_ent_t ent;
2556 int verbose = 0; /* list nodes in batch or test */
2565 static struct option list_batch_opts[] =
2567 {"test", required_argument, 0, 't' },
2568 {"invalid", no_argument, 0, 'i' },
2569 {"active", no_argument, 0, 'a' },
2570 {"all", no_argument, 0, 'l' },
2571 {"server", no_argument, 0, 's' },
2575 if (session_key == 0) {
2577 "Can't find env LST_SESSION or value is not valid\n");
2582 c = getopt_long(argc, argv, "ailst:",
2583 list_batch_opts, &optidx);
2590 verbose = active = 1;
2593 verbose = invalid = 1;
2596 verbose = active = invalid = 1;
2602 test = atoi(optarg);
2606 lst_print_usage(argv[0]);
2611 if (optind == argc) {
2612 /* list all batches */
2613 rc = lst_list_batch_all();
2617 if (ntest == 1 && test <= 0) {
2618 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2622 if (optind != argc - 1) {
2623 lst_print_usage(argv[0]);
2627 batch = argv[optind];
2630 /* show detail of specified batch or test */
2631 rc = lst_info_batch_ioctl(batch, test, server,
2632 &ent, NULL, NULL, NULL);
2634 lst_print_error((test > 0) ? "test" : "batch",
2635 (test > 0) ? "Failed to query test: %s\n" :
2636 "Failed to query batch: %s\n",
2642 /* list nodes in test or batch */
2643 rc = lst_list_tsb_nodes(batch, test, server,
2644 server ? ent.tbe_srv_nle.nle_nnode :
2645 ent.tbe_cli_nle.nle_nnode,
2650 /* only show number of hosts in batch or test */
2652 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2653 batch, ent.u.tbe_batch.bae_ntest,
2654 ent.u.tbe_batch.bae_state);
2655 ntest = ent.u.tbe_batch.bae_ntest;
2656 test = 1; /* starting from test 1 */
2660 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2661 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2662 ent.u.tbe_test.tse_loop,
2663 ent.u.tbe_test.tse_concur);
2668 fprintf(stdout, LST_NODES_TITLE);
2669 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2670 "server\t%d\t%d\t%d\t%d\t%d\n",
2671 ent.tbe_cli_nle.nle_nactive,
2672 ent.tbe_cli_nle.nle_nbusy,
2673 ent.tbe_cli_nle.nle_ndown,
2674 ent.tbe_cli_nle.nle_nunknown,
2675 ent.tbe_cli_nle.nle_nnode,
2676 ent.tbe_srv_nle.nle_nactive,
2677 ent.tbe_srv_nle.nle_nbusy,
2678 ent.tbe_srv_nle.nle_ndown,
2679 ent.tbe_srv_nle.nle_nunknown,
2680 ent.tbe_srv_nle.nle_nnode);
2689 lst_query_batch_ioctl(char *batch, int test, int server,
2690 int timeout, struct list_head *head)
2692 lstio_batch_query_args_t args = {0};
2694 args.lstio_bat_key = session_key;
2695 args.lstio_bat_testidx = test;
2696 args.lstio_bat_client = !(server);
2697 args.lstio_bat_timeout = timeout;
2698 args.lstio_bat_nmlen = strlen(batch);
2699 args.lstio_bat_namep = batch;
2700 args.lstio_bat_resultp = head;
2702 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2706 lst_print_tsb_verbose(struct list_head *head,
2707 int active, int idle, int error)
2709 lstcon_rpc_ent_t *ent;
2711 list_for_each_entry(ent, head, rpe_link) {
2712 if (ent->rpe_priv[0] == 0 && active)
2715 if (ent->rpe_priv[0] != 0 && idle)
2718 if (ent->rpe_fwk_errno == 0 && error)
2721 fprintf(stdout, "%s [%s]: %s\n",
2722 libcfs_id2str(ent->rpe_peer),
2723 lst_node_state2str(ent->rpe_state),
2724 ent->rpe_rpc_errno != 0 ?
2725 strerror(ent->rpe_rpc_errno) :
2726 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2731 jt_lst_query_batch(int argc, char **argv)
2733 lstcon_test_batch_ent_t ent;
2734 struct list_head head;
2740 int timeout = 5; /* default 5 seconds */
2741 int delay = 5; /* default 5 seconds */
2742 int loop = 1; /* default 1 loop */
2752 static struct option query_batch_opts[] =
2754 {"timeout", required_argument, 0, 'o' },
2755 {"delay", required_argument, 0, 'd' },
2756 {"loop", required_argument, 0, 'c' },
2757 {"test", required_argument, 0, 't' },
2758 {"server", no_argument, 0, 's' },
2759 {"active", no_argument, 0, 'a' },
2760 {"idle", no_argument, 0, 'i' },
2761 {"error", no_argument, 0, 'e' },
2762 {"all", no_argument, 0, 'l' },
2766 if (session_key == 0) {
2768 "Can't find env LST_SESSION or value is not valid\n");
2773 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2774 query_batch_opts, &optidx);
2776 /* Detect the end of the options. */
2782 timeout = atoi(optarg);
2785 delay = atoi(optarg);
2788 loop = atoi(optarg);
2791 test = atoi(optarg);
2797 active = verbose = 1;
2803 error = verbose = 1;
2809 lst_print_usage(argv[0]);
2814 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2815 lst_print_usage(argv[0]);
2819 if (optind == argc) {
2820 batch = LST_DEFAULT_BATCH;
2822 } else if (optind == argc - 1) {
2823 batch = argv[optind];
2826 lst_print_usage(argv[0]);
2831 INIT_LIST_HEAD(&head);
2834 rc = lst_info_batch_ioctl(batch, test, server,
2835 &ent, NULL, NULL, NULL);
2837 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2838 batch, test, strerror(errno));
2842 count = server ? ent.tbe_srv_nle.nle_nnode :
2843 ent.tbe_cli_nle.nle_nnode;
2845 fprintf(stdout, "Batch or test is empty\n");
2850 rc = lst_alloc_rpcent(&head, count, 0);
2852 fprintf(stderr, "Out of memory\n");
2856 for (i = 0; i < loop; i++) {
2857 time_t now = time(NULL);
2859 if (now - last < delay) {
2860 sleep(delay - now + last);
2866 rc = lst_query_batch_ioctl(batch, test,
2867 server, timeout, &head);
2869 fprintf(stderr, "Failed to query batch: %s\n",
2876 lst_print_tsb_verbose(&head, active, idle, error);
2880 fprintf(stdout, "%s [%d] ", batch, test);
2882 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2883 fprintf(stdout, "%d of %d nodes are unknown, ",
2884 lstcon_rpc_stat_failure(&trans_stat, 0),
2885 lstcon_rpc_stat_total(&trans_stat, 0));
2888 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2889 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2890 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2891 fprintf(stdout, "is stopped\n");
2895 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2896 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2897 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2898 fprintf(stdout, "is running\n");
2902 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2903 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2904 lstcon_tsbqry_stat_run(&trans_stat, 0),
2905 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2908 lst_free_rpcent(&head);
2914 lst_parse_distribute(char *dstr, int *dist, int *span)
2920 dstr = strchr(dstr, ':');
2924 *span = atoi(dstr + 1);
2932 lst_get_bulk_param(int argc, char **argv, lst_test_bulk_param_t *bulk)
2939 bulk->blk_size = 4096;
2940 bulk->blk_opc = LST_BRW_READ;
2941 bulk->blk_flags = LST_BRW_CHECK_NONE;
2944 if (strcasestr(argv[i], "check=") == argv[i] ||
2945 strcasestr(argv[i], "c=") == argv[i]) {
2946 tok = strchr(argv[i], '=') + 1;
2948 if (strcasecmp(tok, "full") == 0) {
2949 bulk->blk_flags = LST_BRW_CHECK_FULL;
2950 } else if (strcasecmp(tok, "simple") == 0) {
2951 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2953 fprintf(stderr, "Unknow flag %s\n", tok);
2957 } else if (strcasestr(argv[i], "size=") == argv[i] ||
2958 strcasestr(argv[i], "s=") == argv[i]) {
2959 tok = strchr(argv[i], '=') + 1;
2961 bulk->blk_size = strtol(tok, &end, 0);
2962 if (bulk->blk_size <= 0) {
2963 fprintf(stderr, "Invalid size %s\n", tok);
2970 if (*end == 'k' || *end == 'K')
2971 bulk->blk_size *= 1024;
2972 else if (*end == 'm' || *end == 'M')
2973 bulk->blk_size *= 1024 * 1024;
2975 if (bulk->blk_size > PAGE_CACHE_SIZE * LNET_MAX_IOV) {
2976 fprintf(stderr, "Size exceed limitation: %d bytes\n",
2981 } else if (strcasecmp(argv[i], "read") == 0 ||
2982 strcasecmp(argv[i], "r") == 0) {
2983 bulk->blk_opc = LST_BRW_READ;
2985 } else if (strcasecmp(argv[i], "write") == 0 ||
2986 strcasecmp(argv[i], "w") == 0) {
2987 bulk->blk_opc = LST_BRW_WRITE;
2990 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
3001 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
3003 lst_test_bulk_param_t *bulk = NULL;
3006 type = lst_test_name2type(test);
3008 fprintf(stderr, "Unknow test name %s\n", test);
3017 bulk = malloc(sizeof(*bulk));
3019 fprintf(stderr, "Out of memory\n");
3023 memset(bulk, 0, sizeof(*bulk));
3025 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
3031 *plen = sizeof(*bulk);
3039 /* TODO: parse more parameter */
3044 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
3045 int dist, int span, char *sgrp, char *dgrp,
3046 void *param, int plen, int *retp, struct list_head *resultp)
3048 lstio_test_args_t args = {0};
3050 args.lstio_tes_key = session_key;
3051 args.lstio_tes_bat_nmlen = strlen(batch);
3052 args.lstio_tes_bat_name = batch;
3053 args.lstio_tes_type = type;
3054 args.lstio_tes_oneside = 0;
3055 args.lstio_tes_loop = loop;
3056 args.lstio_tes_concur = concur;
3057 args.lstio_tes_dist = dist;
3058 args.lstio_tes_span = span;
3059 args.lstio_tes_sgrp_nmlen = strlen(sgrp);
3060 args.lstio_tes_sgrp_name = sgrp;
3061 args.lstio_tes_dgrp_nmlen = strlen(dgrp);
3062 args.lstio_tes_dgrp_name = dgrp;
3063 args.lstio_tes_param_len = plen;
3064 args.lstio_tes_param = param;
3065 args.lstio_tes_retp = retp;
3066 args.lstio_tes_resultp = resultp;
3068 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
3072 jt_lst_add_test(int argc, char **argv)
3074 struct list_head head;
3094 static struct option add_test_opts[] =
3096 {"batch", required_argument, 0, 'b' },
3097 {"concurrency", required_argument, 0, 'c' },
3098 {"distribute", required_argument, 0, 'd' },
3099 {"from", required_argument, 0, 'f' },
3100 {"to", required_argument, 0, 't' },
3101 {"loop", required_argument, 0, 'l' },
3105 if (session_key == 0) {
3107 "Can't find env LST_SESSION or value is not valid\n");
3112 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3113 add_test_opts, &optidx);
3115 /* Detect the end of the options. */
3124 concur = atoi(optarg);
3133 loop = atoi(optarg);
3139 lst_print_usage(argv[0]);
3144 if (optind == argc || from == NULL || to == NULL) {
3145 lst_print_usage(argv[0]);
3149 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3150 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3155 batch = LST_DEFAULT_BATCH;
3158 rc = lst_parse_distribute(dstr, &dist, &span);
3160 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3165 test = argv[optind++];
3170 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3172 fprintf(stderr, "Failed to add test (%s)\n", test);
3176 INIT_LIST_HEAD(&head);
3178 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3180 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3181 from, strerror(errno));
3185 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3187 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3188 to, strerror(errno));
3192 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3194 fprintf(stderr, "Out of memory\n");
3198 rc = lst_add_test_ioctl(batch, type, loop, concur,
3199 dist, span, from, to, param, plen, &ret, &head);
3202 fprintf(stdout, "Test was added successfully\n");
3204 fprintf(stdout, "Server group contains userland test "
3205 "nodes, old version of tcplnd can't accept "
3206 "connection request\n");
3213 lst_print_error("test", "Failed to add test: %s\n",
3218 lst_print_transerr(&head, "add test");
3220 lst_free_rpcent(&head);
3228 static command_t lst_cmdlist[] = {
3229 {"new_session", jt_lst_new_session, NULL,
3230 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3231 {"end_session", jt_lst_end_session, NULL,
3232 "Usage: lst end_session" },
3233 {"show_session", jt_lst_show_session, NULL,
3234 "Usage: lst show_session" },
3235 {"ping", jt_lst_ping , NULL,
3236 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3237 {"add_group", jt_lst_add_group, NULL,
3238 "Usage: lst group NAME IDs [IDs]..." },
3239 {"del_group", jt_lst_del_group, NULL,
3240 "Usage: lst del_group NAME" },
3241 {"update_group", jt_lst_update_group, NULL,
3242 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3243 {"list_group", jt_lst_list_group, NULL,
3244 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3245 {"stat", jt_lst_stat, NULL,
3246 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3247 " [--timeout #] [--delay #] [--count #] GROUP [GROUP]" },
3248 {"show_error", jt_lst_show_error, NULL,
3249 "Usage: lst show_error NAME | IDS ..." },
3250 {"add_batch", jt_lst_add_batch, NULL,
3251 "Usage: lst add_batch NAME" },
3252 {"run", jt_lst_start_batch, NULL,
3253 "Usage: lst run [--timeout TIME] [NAME]" },
3254 {"stop", jt_lst_stop_batch, NULL,
3255 "Usage: lst stop [--force] BATCH_NAME" },
3256 {"list_batch", jt_lst_list_batch, NULL,
3257 "Usage: lst list_batch NAME [--test ID] [--server]" },
3258 {"query", jt_lst_query_batch, NULL,
3259 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3260 {"add_test", jt_lst_add_test, NULL,
3261 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3262 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3263 {"help", Parser_help, 0, "help" },
3268 lst_initialize(void)
3273 feats = getenv("LST_FEATURES");
3275 session_features = strtol(feats, NULL, 16);
3277 if ((session_features & ~LST_FEATS_MASK) != 0) {
3279 "Unsupported session features %x, "
3280 "only support these features so far: %x\n",
3281 (session_features & ~LST_FEATS_MASK), LST_FEATS_MASK);
3285 key = getenv("LST_SESSION");
3292 session_key = atoi(key);
3298 main(int argc, char **argv)
3304 rc = libcfs_arch_init();
3308 rc = lst_initialize();
3312 rc = ptl_initialize(argc, argv);
3316 Parser_init("lst > ", lst_cmdlist);
3319 rc = Parser_execarg(argc - 1, argv + 1, lst_cmdlist);
3326 libcfs_arch_cleanup();