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>
45 #include <libcfs/libcfsutil.h>
46 #include <lnet/lnetctl.h>
47 #include <lnet/lnetst.h>
48 #include <lnet/lnet.h>
50 lst_sid_t LST_INVALID_SID = {LNET_NID_ANY, -1};
51 static lst_sid_t session_id;
52 static int session_key;
54 /* All nodes running 2.6.50 or later understand feature LST_FEAT_BULK_LEN */
55 static unsigned session_features = LST_FEATS_MASK;
56 static lstcon_trans_stat_t trans_stat;
58 typedef struct list_string {
59 struct list_string *lstr_next;
65 # define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
68 static int alloc_count = 0;
69 static int alloc_nob = 0;
74 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
77 fprintf(stderr, "Can't allocate lstr\n");
84 lstr->lstr_str[0] = 0;
90 free_lstr(lstr_t *lstr)
93 alloc_nob -= lstr->lstr_sz;
98 free_lstrs(lstr_t **list)
102 while ((lstr = *list) != NULL) {
103 *list = lstr->lstr_next;
109 new_lstrs(lstr_t **list, char *prefix, char *postfix,
110 int lo, int hi, int stride)
112 int n1 = strlen(prefix);
113 int n2 = strlen(postfix);
114 int sz = n1 + 20 + n2 + 1;
117 lstr_t *n = alloc_lstr(sz);
119 snprintf(n->lstr_str, sz - 1, "%s%u%s",
120 prefix, lo, postfix);
122 n->lstr_next = *list;
130 expand_lstr(lstr_t **list, lstr_t *l)
132 int nob = strlen(l->lstr_str);
142 b1 = strchr(l->lstr_str, '[');
144 l->lstr_next = *list;
149 b2 = strchr(b1, ']');
150 if (b2 == NULL || b2 == b1 + 1)
158 sep = strchr(expr, ',');
164 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
166 new_lstrs(list, l->lstr_str, b2, x, x, 1);
171 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
174 new_lstrs(list, l->lstr_str, b2, x, y, 1);
179 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
182 new_lstrs(list, l->lstr_str, b2, x, y, z);
188 } while ((expr = sep) != NULL);
196 expand_strs(char *str, lstr_t **head)
204 l = alloc_lstr(strlen(str) + 1);
205 memcpy(l->lstr_str, str, strlen(str) + 1);
213 while ((l = list) != NULL) {
216 rc = expand_lstr(&nlist, l);
218 fprintf(stderr, "Syntax error in \"%s\"\n", str);
226 /* re-order onto 'list' */
227 while ((l = nlist) != NULL) {
228 nlist = l->lstr_next;
233 } while (expanded && rc > 0);
240 while ((l = list) != NULL) {
249 lst_parse_nids(char *str, int *countp, lnet_process_id_t **idspp)
257 rc = expand_strs(str, &head);
267 *idspp = malloc(c * sizeof(lnet_process_id_t));
268 if (*idspp == NULL) {
269 fprintf(stderr, "Out of memory\n");
276 while ((l = head) != NULL) {
280 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
281 if ((*idspp)[i].nid == LNET_NID_ANY) {
282 fprintf(stderr, "Invalid nid: %s\n",
287 (*idspp)[i].pid = LNET_PID_LUSTRE;
304 lst_node_state2str(int state)
306 if (state == LST_NODE_ACTIVE)
308 if (state == LST_NODE_BUSY)
310 if (state == LST_NODE_DOWN)
317 lst_node_str2state(char *str)
319 if (strcasecmp(str, "active") == 0)
320 return LST_NODE_ACTIVE;
321 if (strcasecmp(str, "busy") == 0)
322 return LST_NODE_BUSY;
323 if (strcasecmp(str, "down") == 0)
324 return LST_NODE_DOWN;
325 if (strcasecmp(str, "unknown") == 0)
326 return LST_NODE_UNKNOWN;
327 if (strcasecmp(str, "invalid") == 0)
328 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
334 lst_test_type2name(int type)
336 if (type == LST_TEST_PING)
338 if (type == LST_TEST_BULK)
345 lst_test_name2type(char *name)
347 if (strcasecmp(name, "ping") == 0)
348 return LST_TEST_PING;
349 if (strcasecmp(name, "brw") == 0)
350 return LST_TEST_BULK;
356 lst_print_usage(char *cmd)
358 Parser_printhelp(cmd);
362 lst_print_error(char *sub, const char *def_format, ...)
366 /* local error returned from kernel */
369 fprintf(stderr, "No session exists\n");
372 fprintf(stderr, "Session is shutting down\n");
375 fprintf(stderr, "Unmatched session key or not root\n");
378 fprintf(stderr, "Can't find %s in current session\n", sub);
381 fprintf(stderr, "Invalid parameters list in command line\n");
384 fprintf(stderr, "Bad parameter address\n");
387 fprintf(stderr, "%s already exists\n", sub);
390 va_start(ap, def_format);
391 vfprintf(stderr, def_format, ap);
399 lst_free_rpcent(struct list_head *head)
401 lstcon_rpc_ent_t *ent;
403 while (!list_empty(head)) {
404 ent = list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
406 list_del(&ent->rpe_link);
412 lst_reset_rpcent(struct list_head *head)
414 lstcon_rpc_ent_t *ent;
416 list_for_each_entry(ent, head, rpe_link) {
417 ent->rpe_sid = LST_INVALID_SID;
418 ent->rpe_peer.nid = LNET_NID_ANY;
419 ent->rpe_peer.pid = LNET_PID_ANY;
420 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
425 lst_alloc_rpcent(struct list_head *head, int count, int offset)
427 lstcon_rpc_ent_t *ent;
430 for (i = 0; i < count; i++) {
431 ent = malloc(offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
433 lst_free_rpcent(head);
437 memset(ent, 0, offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
439 ent->rpe_sid = LST_INVALID_SID;
440 ent->rpe_peer.nid = LNET_NID_ANY;
441 ent->rpe_peer.pid = LNET_PID_ANY;
442 list_add(&ent->rpe_link, head);
449 lst_print_transerr(struct list_head *head, char *optstr)
451 lstcon_rpc_ent_t *ent;
453 list_for_each_entry(ent, head, rpe_link) {
454 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
457 if (ent->rpe_rpc_errno != 0) {
458 fprintf(stderr, "%s RPC failed on %s: %s\n",
459 optstr, libcfs_id2str(ent->rpe_peer),
460 strerror(ent->rpe_rpc_errno));
464 fprintf(stderr, "operation %s failed on %s: %s\n",
465 optstr, libcfs_id2str(ent->rpe_peer),
466 strerror(ent->rpe_fwk_errno));
470 int lst_info_batch_ioctl(char *batch, int test, int server,
471 lstcon_test_batch_ent_t *entp, int *idxp,
472 int *ndentp, lstcon_node_ent_t *dentsp);
474 int lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
475 int *idx, int *count, lstcon_node_ent_t *dents);
477 int lst_query_batch_ioctl(char *batch, int test, int server,
478 int timeout, struct list_head *head);
481 lst_ioctl(unsigned int opc, void *buf, int len)
483 struct libcfs_ioctl_data data;
486 LIBCFS_IOC_INIT (data);
487 data.ioc_u32[0] = opc;
488 data.ioc_plen1 = len;
489 data.ioc_pbuf1 = (char *)buf;
490 data.ioc_plen2 = sizeof(trans_stat);
491 data.ioc_pbuf2 = (char *)&trans_stat;
493 memset(&trans_stat, 0, sizeof(trans_stat));
495 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
497 /* local error, no valid RPC result */
502 if (trans_stat.trs_rpc_errno != 0)
505 /* Framework error */
506 if (trans_stat.trs_fwk_errno != 0)
513 lst_new_session_ioctl(char *name, int timeout, int force, lst_sid_t *sid)
515 lstio_session_new_args_t args = {0};
517 args.lstio_ses_key = session_key;
518 args.lstio_ses_timeout = timeout;
519 args.lstio_ses_force = force;
520 args.lstio_ses_idp = sid;
521 args.lstio_ses_feats = session_features;
522 args.lstio_ses_nmlen = strlen(name);
523 args.lstio_ses_namep = name;
525 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
529 jt_lst_new_session(int argc, char **argv)
531 char buf[LST_NAME_SIZE];
539 static struct option session_opts[] =
541 {"timeout", required_argument, 0, 't' },
542 {"force", no_argument, 0, 'f' },
546 if (session_key == 0) {
548 "Can't find env LST_SESSION or value is not valid\n");
554 c = getopt_long(argc, argv, "ft:",
555 session_opts, &optidx);
565 timeout = atoi(optarg);
568 lst_print_usage(argv[0]);
574 fprintf(stderr, "Invalid timeout value\n");
578 if (optind == argc - 1) {
579 name = argv[optind ++];
580 if (strlen(name) >= LST_NAME_SIZE) {
581 fprintf(stderr, "Name size is limited to %d\n",
586 } else if (optind == argc) {
587 char user[LST_NAME_SIZE];
588 char host[LST_NAME_SIZE];
589 struct passwd *pw = getpwuid(getuid());
592 snprintf(user, sizeof(user), "%d", (int)getuid());
594 snprintf(user, sizeof(user), "%s", pw->pw_name);
596 rc = gethostname(host, sizeof(host));
598 snprintf(host, sizeof(host), "unknown_host");
600 snprintf(buf, sizeof(buf), "%s@%s", user, host);
604 lst_print_usage(argv[0]);
608 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
610 lst_print_error("session", "Failed to create session: %s\n",
615 fprintf(stdout, "SESSION: %s FEATURES: %x TIMEOUT: %d FORCE: %s\n",
616 name, session_features, timeout, force ? "Yes" : "No");
621 lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp,
622 lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
624 lstio_session_info_args_t args = {0};
626 args.lstio_ses_idp = sid;
627 args.lstio_ses_keyp = key;
628 args.lstio_ses_featp = featp;
629 args.lstio_ses_ndinfo = ndinfo;
630 args.lstio_ses_nmlen = len;
631 args.lstio_ses_namep = name;
633 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
637 jt_lst_show_session(int argc, char **argv)
639 lstcon_ndlist_ent_t ndinfo;
641 char name[LST_NAME_SIZE];
646 rc = lst_session_info_ioctl(name, sizeof(name), &key,
647 &feats, &sid, &ndinfo);
650 lst_print_error("session", "Failed to show session: %s\n",
655 fprintf(stdout, "%s ID: "LPU64"@%s, KEY: %d FEATURES: %x NODES: %d\n",
656 name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
657 key, feats, ndinfo.nle_nnode);
663 lst_end_session_ioctl(void)
665 lstio_session_end_args_t args = {0};
667 args.lstio_ses_key = session_key;
668 return lst_ioctl (LSTIO_SESSION_END, &args, sizeof(args));
672 jt_lst_end_session(int argc, char **argv)
676 if (session_key == 0) {
678 "Can't find env LST_SESSION or value is not valid\n");
682 rc = lst_end_session_ioctl();
685 fprintf(stdout, "session is ended\n");
690 lst_print_error("session", "Failed to end session: %s\n",
695 if (trans_stat.trs_rpc_errno != 0) {
697 "[RPC] Failed to send %d session RPCs: %s\n",
698 lstcon_rpc_stat_failure(&trans_stat, 0),
699 strerror(trans_stat.trs_rpc_errno));
702 if (trans_stat.trs_fwk_errno != 0) {
704 "[FWK] Failed to end session on %d nodes: %s\n",
705 lstcon_sesop_stat_failure(&trans_stat, 0),
706 strerror(trans_stat.trs_fwk_errno));
713 lst_ping_ioctl(char *str, int type, int timeout,
714 int count, lnet_process_id_t *ids, struct list_head *head)
716 lstio_debug_args_t args = {0};
718 args.lstio_dbg_key = session_key;
719 args.lstio_dbg_type = type;
720 args.lstio_dbg_flags = 0;
721 args.lstio_dbg_timeout = timeout;
722 args.lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str);
723 args.lstio_dbg_namep = str;
724 args.lstio_dbg_count = count;
725 args.lstio_dbg_idsp = ids;
726 args.lstio_dbg_resultp = head;
728 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
732 lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
734 char buf[LST_NAME_SIZE];
735 lstcon_test_batch_ent_t ent;
736 lstcon_ndlist_ent_t *entp = &ent.tbe_cli_nle;
743 case LST_OPC_SESSION:
744 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
745 &key, &feats, &sid, entp);
748 case LST_OPC_BATCHSRV:
749 entp = &ent.tbe_srv_nle;
750 case LST_OPC_BATCHCLI:
751 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
755 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
759 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
768 *countp = entp->nle_nnode;
774 jt_lst_ping(int argc, char **argv)
776 struct list_head head;
777 lnet_process_id_t *ids = NULL;
778 lstcon_rpc_ent_t *ent = NULL;
788 static struct option ping_opts[] =
790 {"session", no_argument, 0, 's' },
791 {"server", no_argument, 0, 'v' },
792 {"batch", required_argument, 0, 'b' },
793 {"group", required_argument, 0, 'g' },
794 {"nodes", required_argument, 0, 'n' },
795 {"timeout", required_argument, 0, 't' },
799 if (session_key == 0) {
801 "Can't find env LST_SESSION or value is not valid\n");
807 c = getopt_long(argc, argv, "g:b:n:t:sv",
815 type = LST_OPC_SESSION;
819 type = LST_OPC_GROUP;
824 type = LST_OPC_BATCHCLI;
829 type = LST_OPC_NODES;
834 timeout = atoi(optarg);
842 lst_print_usage(argv[0]);
847 if (type == 0 || timeout <= 0 || optind != argc) {
848 lst_print_usage(argv[0]);
852 if (type == LST_OPC_BATCHCLI && server)
853 type = LST_OPC_BATCHSRV;
855 rc = lst_get_node_count(type, str, &count, &ids);
857 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
858 (str == NULL) ? "session" : str, strerror(errno));
862 INIT_LIST_HEAD(&head);
864 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
866 fprintf(stderr, "Out of memory\n");
871 fprintf(stdout, "Target %s is empty\n",
872 (str == NULL) ? "session" : str);
876 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
877 if (rc == -1) { /* local failure */
878 lst_print_error("debug", "Failed to ping %s: %s\n",
879 (str == NULL) ? "session" : str,
885 /* ignore RPC errors and framwork errors */
886 list_for_each_entry(ent, &head, rpe_link) {
887 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
888 libcfs_id2str(ent->rpe_peer),
889 lst_node_state2str(ent->rpe_state),
890 (ent->rpe_state == LST_NODE_ACTIVE ||
891 ent->rpe_state == LST_NODE_BUSY) ?
892 (ent->rpe_rpc_errno == 0 ?
893 &ent->rpe_payload[0] : "Unknown") :
894 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
898 lst_free_rpcent(&head);
908 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
909 unsigned *featp, struct list_head *resultp)
911 lstio_group_nodes_args_t args = {0};
913 args.lstio_grp_key = session_key;
914 args.lstio_grp_nmlen = strlen(name);
915 args.lstio_grp_namep = name;
916 args.lstio_grp_count = count;
917 args.lstio_grp_featp = featp;
918 args.lstio_grp_idsp = ids;
919 args.lstio_grp_resultp = resultp;
921 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
925 lst_del_group_ioctl(char *name)
927 lstio_group_del_args_t args = {0};
929 args.lstio_grp_key = session_key;
930 args.lstio_grp_nmlen = strlen(name);
931 args.lstio_grp_namep = name;
933 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
937 lst_del_group(char *grp_name)
941 rc = lst_del_group_ioctl(grp_name);
943 fprintf(stdout, "Group is deleted\n");
948 lst_print_error("group", "Failed to delete group: %s\n",
953 fprintf(stderr, "Group is deleted with some errors\n");
955 if (trans_stat.trs_rpc_errno != 0) {
957 "[RPC] Failed to send %d end session RPCs: %s\n",
958 lstcon_rpc_stat_failure(&trans_stat, 0),
959 strerror(trans_stat.trs_rpc_errno));
962 if (trans_stat.trs_fwk_errno != 0) {
964 "[FWK] Failed to end session on %d nodes: %s\n",
965 lstcon_sesop_stat_failure(&trans_stat, 0),
966 strerror(trans_stat.trs_fwk_errno));
973 lst_add_group_ioctl (char *name)
975 lstio_group_add_args_t args = {0};
977 args.lstio_grp_key = session_key;
978 args.lstio_grp_nmlen = strlen(name);
979 args.lstio_grp_namep = name;
981 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
985 jt_lst_add_group(int argc, char **argv)
987 struct list_head head;
988 lnet_process_id_t *ids;
990 unsigned feats = session_features;
994 bool nodes_added = false;
996 if (session_key == 0) {
998 "Can't find env LST_SESSION or value is not valid\n");
1003 lst_print_usage(argv[0]);
1008 if (strlen(name) >= LST_NAME_SIZE) {
1009 fprintf(stderr, "Name length is limited to %d\n",
1014 rc = lst_add_group_ioctl(name);
1016 lst_print_error("group", "Failed to add group %s: %s\n",
1017 name, strerror(errno));
1021 INIT_LIST_HEAD(&head);
1023 for (i = 2; i < argc; i++) {
1024 /* parse address list */
1025 rc = lst_parse_nids(argv[i], &count, &ids);
1027 fprintf(stderr, "Ignore invalid id list %s\n",
1035 rc = lst_alloc_rpcent(&head, count, 0);
1037 fprintf(stderr, "Out of memory\n");
1043 rc = lst_add_nodes_ioctl(name, count, ids, &feats, &head);
1050 fprintf(stdout, "%s are added to session\n", argv[i]);
1054 if ((feats & session_features) != session_features) {
1056 "Warning, this session will run with "
1057 "compatible mode because some test nodes "
1058 "might not understand these features: %x\n",
1059 (~feats & session_features));
1062 lst_free_rpcent(&head);
1067 * The selftest kernel module expects that a group should
1068 * have at least one node, since it doesn't make sense for
1069 * an empty group to be added to a test.
1072 "No nodes added successfully, deleting group %s\n",
1074 rc = lst_del_group(name);
1077 "Failed to delete group %s."
1078 " Group is empty.\n", name);
1086 lst_print_error("group", "Failed to add nodes %s: %s\n",
1087 argv[i], strerror(errno));
1090 if (trans_stat.trs_fwk_errno == EPROTO) {
1092 "test nodes might have different LST "
1093 "features, please disable some features by "
1094 "setting LST_FEATURES\n");
1097 lst_print_transerr(&head, "create session");
1100 lst_free_rpcent(&head);
1104 "No nodes added successfully, deleting group %s\n",
1106 if (lst_del_group(name) != 0) {
1108 "Failed to delete group %s."
1109 " Group is empty.\n", name);
1117 jt_lst_del_group(int argc, char **argv)
1121 if (session_key == 0) {
1123 "Can't find env LST_SESSION or value is not valid\n");
1128 lst_print_usage(argv[0]);
1132 rc = lst_del_group(argv[1]);
1138 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1139 lnet_process_id_t *ids, struct list_head *resultp)
1141 lstio_group_update_args_t args = {0};
1143 args.lstio_grp_key = session_key;
1144 args.lstio_grp_opc = opc;
1145 args.lstio_grp_args = clean;
1146 args.lstio_grp_nmlen = strlen(name);
1147 args.lstio_grp_namep = name;
1148 args.lstio_grp_count = count;
1149 args.lstio_grp_idsp = ids;
1150 args.lstio_grp_resultp = resultp;
1152 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1156 jt_lst_update_group(int argc, char **argv)
1158 struct list_head head;
1159 lnet_process_id_t *ids = NULL;
1169 static struct option update_group_opts[] =
1171 {"refresh", no_argument, 0, 'f' },
1172 {"clean", required_argument, 0, 'c' },
1173 {"remove", required_argument, 0, 'r' },
1177 if (session_key == 0) {
1179 "Can't find env LST_SESSION or value is not valid\n");
1184 c = getopt_long(argc, argv, "fc:r:",
1185 update_group_opts, &optidx);
1187 /* Detect the end of the options. */
1194 lst_print_usage(argv[0]);
1197 opc = LST_GROUP_REFRESH;
1202 lst_print_usage(argv[0]);
1205 opc = LST_GROUP_RMND;
1210 clean = lst_node_str2state(optarg);
1211 if (opc != 0 || clean <= 0) {
1212 lst_print_usage(argv[0]);
1215 opc = LST_GROUP_CLEAN;
1219 lst_print_usage(argv[0]);
1224 /* no OPC or group is specified */
1225 if (opc == 0 || optind != argc - 1) {
1226 lst_print_usage(argv[0]);
1232 INIT_LIST_HEAD(&head);
1234 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1235 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1237 opc == LST_GROUP_RMND ? str : grp,
1241 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1242 opc == LST_GROUP_RMND ? str : grp,
1247 rc = lst_alloc_rpcent(&head, count, 0);
1249 fprintf(stderr, "Out of memory\n");
1256 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1262 lst_free_rpcent(&head);
1267 lst_free_rpcent(&head);
1268 lst_print_error("group", "Failed to update group: %s\n",
1273 lst_print_transerr(&head, "Updating group");
1275 lst_free_rpcent(&head);
1281 lst_list_group_ioctl(int len, char *name, int idx)
1283 lstio_group_list_args_t args = {0};
1285 args.lstio_grp_key = session_key;
1286 args.lstio_grp_idx = idx;
1287 args.lstio_grp_nmlen = len;
1288 args.lstio_grp_namep = name;
1290 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1294 lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
1295 int *idx, int *count, lstcon_node_ent_t *dents)
1297 lstio_group_info_args_t args = {0};
1299 args.lstio_grp_key = session_key;
1300 args.lstio_grp_nmlen = strlen(name);
1301 args.lstio_grp_namep = name;
1302 args.lstio_grp_entp = gent;
1303 args.lstio_grp_idxp = idx;
1304 args.lstio_grp_ndentp = count;
1305 args.lstio_grp_dentsp = dents;
1307 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1311 lst_list_group_all(void)
1313 char name[LST_NAME_SIZE];
1317 /* no group is specified, list name of all groups */
1318 for (i = 0; ; i++) {
1319 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1321 fprintf(stdout, "%d) %s\n", i + 1, name);
1325 if (errno == ENOENT)
1328 lst_print_error("group", "Failed to list group: %s\n",
1333 fprintf(stdout, "Total %d groups\n", i);
1338 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1341 jt_lst_list_group(int argc, char **argv)
1343 lstcon_ndlist_ent_t gent;
1344 lstcon_node_ent_t *dents;
1359 static struct option list_group_opts[] =
1361 {"active", no_argument, 0, 'a' },
1362 {"busy", no_argument, 0, 'b' },
1363 {"down", no_argument, 0, 'd' },
1364 {"unknown", no_argument, 0, 'u' },
1365 {"all", no_argument, 0, 'l' },
1369 if (session_key == 0) {
1371 "Can't find env LST_SESSION or value is not valid\n");
1376 c = getopt_long(argc, argv, "abdul",
1377 list_group_opts, &optidx);
1384 verbose = active = 1;
1396 verbose = unknown = 1;
1403 lst_print_usage(argv[0]);
1408 if (optind == argc) {
1409 /* no group is specified, list name of all groups */
1410 rc = lst_list_group_all();
1416 fprintf(stdout, LST_NODES_TITLE);
1418 /* list nodes in specified groups */
1419 for (i = optind; i < argc; i++) {
1420 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1422 if (errno == ENOENT) {
1427 lst_print_error("group", "Failed to list group\n",
1433 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1434 gent.nle_nactive, gent.nle_nbusy,
1435 gent.nle_ndown, gent.nle_nunknown,
1436 gent.nle_nnode, argv[i]);
1440 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1442 if (gent.nle_nnode == 0) {
1443 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1447 count = gent.nle_nnode;
1449 dents = malloc(count * sizeof(lstcon_node_ent_t));
1450 if (dents == NULL) {
1451 fprintf(stderr, "Failed to malloc: %s\n",
1457 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1459 lst_print_error("group", "Failed to list group: %s\n",
1465 for (j = 0, c = 0; j < count; j++) {
1467 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1468 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1469 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1470 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1472 fprintf(stdout, "\t%s: %s\n",
1473 libcfs_id2str(dents[j].nde_id),
1474 lst_node_state2str(dents[j].nde_state));
1479 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1488 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
1489 int timeout, struct list_head *resultp)
1491 lstio_stat_args_t args = {0};
1493 args.lstio_sta_key = session_key;
1494 args.lstio_sta_timeout = timeout;
1495 args.lstio_sta_nmlen = strlen(name);
1496 args.lstio_sta_namep = name;
1497 args.lstio_sta_count = count;
1498 args.lstio_sta_idsp = idsp;
1499 args.lstio_sta_resultp = resultp;
1501 return lst_ioctl (LSTIO_STAT_QUERY, &args, sizeof(args));
1505 struct list_head srp_link;
1508 lnet_process_id_t *srp_ids;
1509 struct list_head srp_result[2];
1510 } lst_stat_req_param_t;
1513 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1517 for (i = 0; i < 2; i++)
1518 lst_free_rpcent(&srp->srp_result[i]);
1520 if (srp->srp_ids != NULL)
1527 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
1529 lst_stat_req_param_t *srp = NULL;
1530 int count = save_old ? 2 : 1;
1534 srp = malloc(sizeof(*srp));
1538 memset(srp, 0, sizeof(*srp));
1539 INIT_LIST_HEAD(&srp->srp_result[0]);
1540 INIT_LIST_HEAD(&srp->srp_result[1]);
1542 rc = lst_get_node_count(LST_OPC_GROUP, name,
1543 &srp->srp_count, NULL);
1544 if (rc != 0 && errno == ENOENT) {
1545 rc = lst_get_node_count(LST_OPC_NODES, name,
1546 &srp->srp_count, &srp->srp_ids);
1551 "Failed to get count of nodes from %s: %s\n",
1552 name, strerror(errno));
1553 lst_stat_req_param_free(srp);
1558 srp->srp_name = name;
1560 for (i = 0; i < count; i++) {
1561 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1562 sizeof(sfw_counters_t) +
1563 sizeof(srpc_counters_t) +
1564 sizeof(lnet_counters_t));
1566 fprintf(stderr, "Out of memory\n");
1576 lst_stat_req_param_free(srp);
1584 } lst_srpc_stat_result;
1586 #define LST_LNET_AVG 0
1587 #define LST_LNET_MIN 1
1588 #define LST_LNET_MAX 2
1591 float lnet_avg_sndrate;
1592 float lnet_min_sndrate;
1593 float lnet_max_sndrate;
1594 float lnet_total_sndrate;
1596 float lnet_avg_rcvrate;
1597 float lnet_min_rcvrate;
1598 float lnet_max_rcvrate;
1599 float lnet_total_rcvrate;
1601 float lnet_avg_sndperf;
1602 float lnet_min_sndperf;
1603 float lnet_max_sndperf;
1604 float lnet_total_sndperf;
1606 float lnet_avg_rcvperf;
1607 float lnet_min_rcvperf;
1608 float lnet_max_rcvperf;
1609 float lnet_total_rcvperf;
1611 int lnet_stat_count;
1612 } lst_lnet_stat_result_t;
1614 lst_lnet_stat_result_t lnet_stat_result;
1617 lst_lnet_stat_value(int bw, int send, int off)
1621 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1622 &lnet_stat_result.lnet_avg_sndrate;
1633 lst_timeval_diff(struct timeval *tv1,
1634 struct timeval *tv2, struct timeval *df)
1636 if (tv1->tv_usec >= tv2->tv_usec) {
1637 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1638 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1642 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1643 df->tv_usec = tv1->tv_usec + 1000000 - tv2->tv_usec;
1649 lst_cal_lnet_stat(float delta, lnet_counters_t *lnet_new,
1650 lnet_counters_t *lnet_old)
1655 perf = (float)(lnet_new->send_length -
1656 lnet_old->send_length) / (1024 * 1024) / delta;
1657 lnet_stat_result.lnet_total_sndperf += perf;
1659 if (lnet_stat_result.lnet_min_sndperf > perf ||
1660 lnet_stat_result.lnet_min_sndperf == 0)
1661 lnet_stat_result.lnet_min_sndperf = perf;
1663 if (lnet_stat_result.lnet_max_sndperf < perf)
1664 lnet_stat_result.lnet_max_sndperf = perf;
1666 perf = (float)(lnet_new->recv_length -
1667 lnet_old->recv_length) / (1024 * 1024) / delta;
1668 lnet_stat_result.lnet_total_rcvperf += perf;
1670 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1671 lnet_stat_result.lnet_min_rcvperf == 0)
1672 lnet_stat_result.lnet_min_rcvperf = perf;
1674 if (lnet_stat_result.lnet_max_rcvperf < perf)
1675 lnet_stat_result.lnet_max_rcvperf = perf;
1677 rate = (lnet_new->send_count - lnet_old->send_count) / delta;
1678 lnet_stat_result.lnet_total_sndrate += rate;
1680 if (lnet_stat_result.lnet_min_sndrate > rate ||
1681 lnet_stat_result.lnet_min_sndrate == 0)
1682 lnet_stat_result.lnet_min_sndrate = rate;
1684 if (lnet_stat_result.lnet_max_sndrate < rate)
1685 lnet_stat_result.lnet_max_sndrate = rate;
1687 rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
1688 lnet_stat_result.lnet_total_rcvrate += rate;
1690 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1691 lnet_stat_result.lnet_min_rcvrate == 0)
1692 lnet_stat_result.lnet_min_rcvrate = rate;
1694 if (lnet_stat_result.lnet_max_rcvrate < rate)
1695 lnet_stat_result.lnet_max_rcvrate = rate;
1697 lnet_stat_result.lnet_stat_count ++;
1699 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1700 lnet_stat_result.lnet_stat_count;
1701 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1702 lnet_stat_result.lnet_stat_count;
1704 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1705 lnet_stat_result.lnet_stat_count;
1706 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1707 lnet_stat_result.lnet_stat_count;
1712 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
1721 if (lnet_stat_result.lnet_stat_count == 0)
1724 if (bwrt == 1) /* bw only */
1727 if (bwrt == 2) /* rates only */
1730 if (rdwr == 1) /* recv only */
1733 if (rdwr == 2) /* send only */
1736 for (i = start1; i <= end1; i++) {
1737 fprintf(stdout, "[LNet %s of %s]\n",
1738 i == 0 ? "Rates" : "Bandwidth", name);
1740 for (j = start2; j <= end2; j++) {
1741 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
1743 if ((type & 1) != 0) {
1744 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1745 "Avg: %-8.2f MB/s ",
1746 lst_lnet_stat_value(i, j, 0));
1749 if ((type & 2) != 0) {
1750 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1751 "Min: %-8.2f MB/s ",
1752 lst_lnet_stat_value(i, j, 1));
1755 if ((type & 4) != 0) {
1756 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1758 lst_lnet_stat_value(i, j, 2));
1761 fprintf(stdout, "\n");
1767 lst_print_stat(char *name, struct list_head *resultp,
1768 int idx, int lnet, int bwrt, int rdwr, int type)
1770 struct list_head tmp[2];
1771 lstcon_rpc_ent_t *new;
1772 lstcon_rpc_ent_t *old;
1773 sfw_counters_t *sfwk_new;
1774 sfw_counters_t *sfwk_old;
1775 srpc_counters_t *srpc_new;
1776 srpc_counters_t *srpc_old;
1777 lnet_counters_t *lnet_new;
1778 lnet_counters_t *lnet_old;
1782 INIT_LIST_HEAD(&tmp[0]);
1783 INIT_LIST_HEAD(&tmp[1]);
1785 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1787 while (!list_empty(&resultp[idx])) {
1788 if (list_empty(&resultp[1 - idx])) {
1789 fprintf(stderr, "Group is changed, re-run stat\n");
1793 new = list_entry(resultp[idx].next, lstcon_rpc_ent_t,
1795 old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t,
1798 /* first time get stats result, can't calculate diff */
1799 if (new->rpe_peer.nid == LNET_NID_ANY)
1802 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1803 new->rpe_peer.pid != old->rpe_peer.pid) {
1804 /* Something wrong. i.e, somebody change the group */
1808 list_del(&new->rpe_link);
1809 list_add_tail(&new->rpe_link, &tmp[idx]);
1811 list_del(&old->rpe_link);
1812 list_add_tail(&old->rpe_link, &tmp[1 - idx]);
1814 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1815 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1820 sfwk_new = (sfw_counters_t *)&new->rpe_payload[0];
1821 sfwk_old = (sfw_counters_t *)&old->rpe_payload[0];
1823 srpc_new = (srpc_counters_t *)((char *)sfwk_new + sizeof(*sfwk_new));
1824 srpc_old = (srpc_counters_t *)((char *)sfwk_old + sizeof(*sfwk_old));
1826 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
1827 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
1829 /* Prior to version 2.3, the running_ms field was a counter for
1830 * the number of running tests. We are looking at this value
1831 * to determine if it is a millisecond timestamep (>= 2.3) or a
1832 * test counter (< 2.3). The number 500 is being used for this
1833 * barrier as the test counter should never get this high, and
1834 * the timestamp should never get this low. */
1836 if (sfwk_new->running_ms > 500) {
1837 /* use the timestamp from the remote node, not our
1838 * rpe_stamp from when we copied up the data out of
1841 delta = (float) (sfwk_new->running_ms -
1842 sfwk_old->running_ms) / 1000;
1846 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1847 delta = tv.tv_sec + (float)tv.tv_usec / 1000000;
1850 if (!lnet) /* TODO */
1853 lst_cal_lnet_stat(delta, lnet_new, lnet_old);
1856 list_splice(&tmp[idx], &resultp[idx]);
1857 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1860 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1862 if (!lnet) /* TODO */
1865 lst_print_lnet_stat(name, bwrt, rdwr, type);
1869 jt_lst_stat(int argc, char **argv)
1871 struct list_head head;
1872 lst_stat_req_param_t *srp;
1875 int timeout = 5; /* default timeout, 5 sec */
1876 int delay = 5; /* default delay, 5 sec */
1877 int count = -1; /* run forever */
1878 int lnet = 1; /* lnet stat by default */
1886 static struct option stat_opts[] =
1888 {"timeout" , required_argument, 0, 't' },
1889 {"delay" , required_argument, 0, 'd' },
1890 {"count" , required_argument, 0, 'o' },
1891 {"lnet" , no_argument, 0, 'l' },
1892 {"rpc" , no_argument, 0, 'c' },
1893 {"bw" , no_argument, 0, 'b' },
1894 {"rate" , no_argument, 0, 'a' },
1895 {"read" , no_argument, 0, 'r' },
1896 {"write" , no_argument, 0, 'w' },
1897 {"avg" , no_argument, 0, 'g' },
1898 {"min" , no_argument, 0, 'n' },
1899 {"max" , no_argument, 0, 'x' },
1903 if (session_key == 0) {
1905 "Can't find env LST_SESSION or value is not valid\n");
1910 c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
1917 timeout = atoi(optarg);
1920 delay = atoi(optarg);
1923 count = atoi(optarg);
1966 lst_print_usage(argv[0]);
1971 if (optind == argc) {
1972 lst_print_usage(argv[0]);
1976 if (timeout <= 0 || delay <= 0) {
1977 fprintf(stderr, "Invalid timeout or delay value\n");
1982 fprintf(stderr, "Invalid count value\n");
1986 /* extra count to get first data point */
1990 INIT_LIST_HEAD(&head);
1992 while (optind < argc) {
1993 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
1997 list_add_tail(&srp->srp_link, &head);
2001 time_t now = time(NULL);
2003 if (now - last < delay) {
2004 sleep(delay - now + last);
2009 list_for_each_entry(srp, &head, srp_link) {
2010 rc = lst_stat_ioctl(srp->srp_name,
2011 srp->srp_count, srp->srp_ids,
2012 timeout, &srp->srp_result[idx]);
2014 lst_print_error("stat", "Failed to stat %s: %s\n",
2015 srp->srp_name, strerror(errno));
2019 lst_print_stat(srp->srp_name, srp->srp_result,
2020 idx, lnet, bwrt, rdwr, type);
2022 lst_reset_rpcent(&srp->srp_result[1 - idx]);
2029 } while (count == -1 || count > 0);
2032 while (!list_empty(&head)) {
2033 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2035 list_del(&srp->srp_link);
2036 lst_stat_req_param_free(srp);
2043 jt_lst_show_error(int argc, char **argv)
2045 struct list_head head;
2046 lst_stat_req_param_t *srp;
2047 lstcon_rpc_ent_t *ent;
2048 sfw_counters_t *sfwk;
2049 srpc_counters_t *srpc;
2056 static struct option show_error_opts[] =
2058 {"session", no_argument, 0, 's' },
2062 if (session_key == 0) {
2064 "Can't find env LST_SESSION or value is not valid\n");
2069 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
2080 lst_print_usage(argv[0]);
2085 if (optind == argc) {
2086 lst_print_usage(argv[0]);
2090 INIT_LIST_HEAD(&head);
2092 while (optind < argc) {
2093 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
2097 list_add_tail(&srp->srp_link, &head);
2100 list_for_each_entry(srp, &head, srp_link) {
2101 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
2102 srp->srp_ids, 10, &srp->srp_result[0]);
2105 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2106 srp->srp_name, strerror(errno));
2110 fprintf(stdout, "%s:\n", srp->srp_name);
2114 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2115 if (ent->rpe_rpc_errno != 0) {
2117 fprintf(stderr, "RPC failure, can't show error on %s\n",
2118 libcfs_id2str(ent->rpe_peer));
2122 if (ent->rpe_fwk_errno != 0) {
2124 fprintf(stderr, "Framework failure, can't show error on %s\n",
2125 libcfs_id2str(ent->rpe_peer));
2129 sfwk = (sfw_counters_t *)&ent->rpe_payload[0];
2130 srpc = (srpc_counters_t *)((char *)sfwk + sizeof(*sfwk));
2132 if (srpc->errors == 0 &&
2133 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2137 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2142 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2143 libcfs_id2str(ent->rpe_peer),
2144 sfwk->brw_errors, sfwk->ping_errors,
2145 show_rpc ? ' ' : '\n');
2150 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2151 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2154 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2157 while (!list_empty(&head)) {
2158 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2160 list_del(&srp->srp_link);
2161 lst_stat_req_param_free(srp);
2168 lst_add_batch_ioctl (char *name)
2170 lstio_batch_add_args_t args = {0};
2172 args.lstio_bat_key = session_key;
2173 args.lstio_bat_nmlen = strlen(name);
2174 args.lstio_bat_namep = name;
2176 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2180 jt_lst_add_batch(int argc, char **argv)
2185 if (session_key == 0) {
2187 "Can't find env LST_SESSION or value is not valid\n");
2192 lst_print_usage(argv[0]);
2197 if (strlen(name) >= LST_NAME_SIZE) {
2198 fprintf(stderr, "Name length is limited to %d\n",
2203 rc = lst_add_batch_ioctl(name);
2207 lst_print_error("batch", "Failed to create batch: %s\n",
2214 lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp)
2216 lstio_batch_run_args_t args = {0};
2218 args.lstio_bat_key = session_key;
2219 args.lstio_bat_timeout = timeout;
2220 args.lstio_bat_nmlen = strlen(name);
2221 args.lstio_bat_namep = name;
2222 args.lstio_bat_resultp = resultp;
2224 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2228 jt_lst_start_batch(int argc, char **argv)
2230 struct list_head head;
2238 static struct option start_batch_opts[] =
2240 {"timeout", required_argument, 0, 't' },
2244 if (session_key == 0) {
2246 "Can't find env LST_SESSION or value is not valid\n");
2251 c = getopt_long(argc, argv, "t:",
2252 start_batch_opts, &optidx);
2254 /* Detect the end of the options. */
2260 timeout = atoi(optarg);
2263 lst_print_usage(argv[0]);
2268 if (optind == argc) {
2269 batch = LST_DEFAULT_BATCH;
2271 } else if (optind == argc - 1) {
2272 batch = argv[optind];
2275 lst_print_usage(argv[0]);
2279 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2281 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2282 batch, strerror(errno));
2286 INIT_LIST_HEAD(&head);
2288 rc = lst_alloc_rpcent(&head, count, 0);
2290 fprintf(stderr, "Out of memory\n");
2294 rc = lst_start_batch_ioctl(batch, timeout, &head);
2297 fprintf(stdout, "%s is running now\n", batch);
2298 lst_free_rpcent(&head);
2303 lst_print_error("batch", "Failed to start batch: %s\n",
2305 lst_free_rpcent(&head);
2309 lst_print_transerr(&head, "Run batch");
2311 lst_free_rpcent(&head);
2317 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2319 lstio_batch_stop_args_t args = {0};
2321 args.lstio_bat_key = session_key;
2322 args.lstio_bat_force = force;
2323 args.lstio_bat_nmlen = strlen(name);
2324 args.lstio_bat_namep = name;
2325 args.lstio_bat_resultp = resultp;
2327 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2331 jt_lst_stop_batch(int argc, char **argv)
2333 struct list_head head;
2341 static struct option stop_batch_opts[] =
2343 {"force", no_argument, 0, 'f' },
2347 if (session_key == 0) {
2349 "Can't find env LST_SESSION or value is not valid\n");
2354 c = getopt_long(argc, argv, "f",
2355 stop_batch_opts, &optidx);
2357 /* Detect the end of the options. */
2366 lst_print_usage(argv[0]);
2371 if (optind == argc) {
2372 batch = LST_DEFAULT_BATCH;
2374 } else if (optind == argc - 1) {
2375 batch = argv[optind];
2378 lst_print_usage(argv[0]);
2382 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2384 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2385 batch, strerror(errno));
2389 INIT_LIST_HEAD(&head);
2391 rc = lst_alloc_rpcent(&head, count, 0);
2393 fprintf(stderr, "Out of memory\n");
2397 rc = lst_stop_batch_ioctl(batch, force, &head);
2402 lst_reset_rpcent(&head);
2404 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2408 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2409 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2412 fprintf(stdout, "%d batch in stopping\n",
2413 lstcon_tsbqry_stat_run(&trans_stat, 0));
2417 fprintf(stdout, "Batch is stopped\n");
2418 lst_free_rpcent(&head);
2423 lst_print_error("batch", "Failed to stop batch: %s\n",
2425 lst_free_rpcent(&head);
2429 lst_print_transerr(&head, "stop batch");
2431 lst_free_rpcent(&head);
2437 lst_list_batch_ioctl(int len, char *name, int index)
2439 lstio_batch_list_args_t args = {0};
2441 args.lstio_bat_key = session_key;
2442 args.lstio_bat_idx = index;
2443 args.lstio_bat_nmlen = len;
2444 args.lstio_bat_namep = name;
2446 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2450 lst_info_batch_ioctl(char *batch, int test, int server,
2451 lstcon_test_batch_ent_t *entp, int *idxp,
2452 int *ndentp, lstcon_node_ent_t *dentsp)
2454 lstio_batch_info_args_t args = {0};
2456 args.lstio_bat_key = session_key;
2457 args.lstio_bat_nmlen = strlen(batch);
2458 args.lstio_bat_namep = batch;
2459 args.lstio_bat_server = server;
2460 args.lstio_bat_testidx = test;
2461 args.lstio_bat_entp = entp;
2462 args.lstio_bat_idxp = idxp;
2463 args.lstio_bat_ndentp = ndentp;
2464 args.lstio_bat_dentsp = dentsp;
2466 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2470 lst_list_batch_all(void)
2472 char name[LST_NAME_SIZE];
2476 for (i = 0; ; i++) {
2477 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2479 fprintf(stdout, "%d) %s\n", i + 1, name);
2483 if (errno == ENOENT)
2486 lst_print_error("batch", "Failed to list batch: %s\n",
2491 fprintf(stdout, "Total %d batches\n", i);
2497 lst_list_tsb_nodes(char *batch, int test, int server,
2498 int count, int active, int invalid)
2500 lstcon_node_ent_t *dents;
2509 /* verbose list, show nodes in batch or test */
2510 dents = malloc(count * sizeof(lstcon_node_ent_t));
2511 if (dents == NULL) {
2512 fprintf(stdout, "Can't allocate memory\n");
2516 rc = lst_info_batch_ioctl(batch, test, server,
2517 NULL, &index, &count, dents);
2520 lst_print_error((test > 0) ? "test" : "batch",
2521 (test > 0) ? "Failed to query test: %s\n" :
2522 "Failed to query batch: %s\n",
2527 for (i = 0, c = 0; i < count; i++) {
2528 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2529 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2530 dents[i].nde_state == LST_NODE_DOWN ||
2531 dents[i].nde_state == LST_NODE_UNKNOWN)))
2534 fprintf(stdout, "\t%s: %s\n",
2535 libcfs_id2str(dents[i].nde_id),
2536 lst_node_state2str(dents[i].nde_state));
2540 fprintf(stdout, "Total %d nodes\n", c);
2547 jt_lst_list_batch(int argc, char **argv)
2549 lstcon_test_batch_ent_t ent;
2552 int verbose = 0; /* list nodes in batch or test */
2561 static struct option list_batch_opts[] =
2563 {"test", required_argument, 0, 't' },
2564 {"invalid", no_argument, 0, 'i' },
2565 {"active", no_argument, 0, 'a' },
2566 {"all", no_argument, 0, 'l' },
2567 {"server", no_argument, 0, 's' },
2571 if (session_key == 0) {
2573 "Can't find env LST_SESSION or value is not valid\n");
2578 c = getopt_long(argc, argv, "ailst:",
2579 list_batch_opts, &optidx);
2586 verbose = active = 1;
2589 verbose = invalid = 1;
2592 verbose = active = invalid = 1;
2598 test = atoi(optarg);
2602 lst_print_usage(argv[0]);
2607 if (optind == argc) {
2608 /* list all batches */
2609 rc = lst_list_batch_all();
2613 if (ntest == 1 && test <= 0) {
2614 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2618 if (optind != argc - 1) {
2619 lst_print_usage(argv[0]);
2623 batch = argv[optind];
2626 /* show detail of specified batch or test */
2627 rc = lst_info_batch_ioctl(batch, test, server,
2628 &ent, NULL, NULL, NULL);
2630 lst_print_error((test > 0) ? "test" : "batch",
2631 (test > 0) ? "Failed to query test: %s\n" :
2632 "Failed to query batch: %s\n",
2638 /* list nodes in test or batch */
2639 rc = lst_list_tsb_nodes(batch, test, server,
2640 server ? ent.tbe_srv_nle.nle_nnode :
2641 ent.tbe_cli_nle.nle_nnode,
2646 /* only show number of hosts in batch or test */
2648 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2649 batch, ent.u.tbe_batch.bae_ntest,
2650 ent.u.tbe_batch.bae_state);
2651 ntest = ent.u.tbe_batch.bae_ntest;
2652 test = 1; /* starting from test 1 */
2656 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2657 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2658 ent.u.tbe_test.tse_loop,
2659 ent.u.tbe_test.tse_concur);
2664 fprintf(stdout, LST_NODES_TITLE);
2665 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2666 "server\t%d\t%d\t%d\t%d\t%d\n",
2667 ent.tbe_cli_nle.nle_nactive,
2668 ent.tbe_cli_nle.nle_nbusy,
2669 ent.tbe_cli_nle.nle_ndown,
2670 ent.tbe_cli_nle.nle_nunknown,
2671 ent.tbe_cli_nle.nle_nnode,
2672 ent.tbe_srv_nle.nle_nactive,
2673 ent.tbe_srv_nle.nle_nbusy,
2674 ent.tbe_srv_nle.nle_ndown,
2675 ent.tbe_srv_nle.nle_nunknown,
2676 ent.tbe_srv_nle.nle_nnode);
2685 lst_query_batch_ioctl(char *batch, int test, int server,
2686 int timeout, struct list_head *head)
2688 lstio_batch_query_args_t args = {0};
2690 args.lstio_bat_key = session_key;
2691 args.lstio_bat_testidx = test;
2692 args.lstio_bat_client = !(server);
2693 args.lstio_bat_timeout = timeout;
2694 args.lstio_bat_nmlen = strlen(batch);
2695 args.lstio_bat_namep = batch;
2696 args.lstio_bat_resultp = head;
2698 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2702 lst_print_tsb_verbose(struct list_head *head,
2703 int active, int idle, int error)
2705 lstcon_rpc_ent_t *ent;
2707 list_for_each_entry(ent, head, rpe_link) {
2708 if (ent->rpe_priv[0] == 0 && active)
2711 if (ent->rpe_priv[0] != 0 && idle)
2714 if (ent->rpe_fwk_errno == 0 && error)
2717 fprintf(stdout, "%s [%s]: %s\n",
2718 libcfs_id2str(ent->rpe_peer),
2719 lst_node_state2str(ent->rpe_state),
2720 ent->rpe_rpc_errno != 0 ?
2721 strerror(ent->rpe_rpc_errno) :
2722 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2727 jt_lst_query_batch(int argc, char **argv)
2729 lstcon_test_batch_ent_t ent;
2730 struct list_head head;
2736 int timeout = 5; /* default 5 seconds */
2737 int delay = 5; /* default 5 seconds */
2738 int loop = 1; /* default 1 loop */
2748 static struct option query_batch_opts[] =
2750 {"timeout", required_argument, 0, 'o' },
2751 {"delay", required_argument, 0, 'd' },
2752 {"loop", required_argument, 0, 'c' },
2753 {"test", required_argument, 0, 't' },
2754 {"server", no_argument, 0, 's' },
2755 {"active", no_argument, 0, 'a' },
2756 {"idle", no_argument, 0, 'i' },
2757 {"error", no_argument, 0, 'e' },
2758 {"all", no_argument, 0, 'l' },
2762 if (session_key == 0) {
2764 "Can't find env LST_SESSION or value is not valid\n");
2769 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2770 query_batch_opts, &optidx);
2772 /* Detect the end of the options. */
2778 timeout = atoi(optarg);
2781 delay = atoi(optarg);
2784 loop = atoi(optarg);
2787 test = atoi(optarg);
2793 active = verbose = 1;
2799 error = verbose = 1;
2805 lst_print_usage(argv[0]);
2810 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2811 lst_print_usage(argv[0]);
2815 if (optind == argc) {
2816 batch = LST_DEFAULT_BATCH;
2818 } else if (optind == argc - 1) {
2819 batch = argv[optind];
2822 lst_print_usage(argv[0]);
2827 INIT_LIST_HEAD(&head);
2830 rc = lst_info_batch_ioctl(batch, test, server,
2831 &ent, NULL, NULL, NULL);
2833 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2834 batch, test, strerror(errno));
2838 count = server ? ent.tbe_srv_nle.nle_nnode :
2839 ent.tbe_cli_nle.nle_nnode;
2841 fprintf(stdout, "Batch or test is empty\n");
2846 rc = lst_alloc_rpcent(&head, count, 0);
2848 fprintf(stderr, "Out of memory\n");
2852 for (i = 0; i < loop; i++) {
2853 time_t now = time(NULL);
2855 if (now - last < delay) {
2856 sleep(delay - now + last);
2862 rc = lst_query_batch_ioctl(batch, test,
2863 server, timeout, &head);
2865 fprintf(stderr, "Failed to query batch: %s\n",
2872 lst_print_tsb_verbose(&head, active, idle, error);
2876 fprintf(stdout, "%s [%d] ", batch, test);
2878 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2879 fprintf(stdout, "%d of %d nodes are unknown, ",
2880 lstcon_rpc_stat_failure(&trans_stat, 0),
2881 lstcon_rpc_stat_total(&trans_stat, 0));
2884 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2885 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2886 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2887 fprintf(stdout, "is stopped\n");
2891 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2892 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2893 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2894 fprintf(stdout, "is running\n");
2898 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2899 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2900 lstcon_tsbqry_stat_run(&trans_stat, 0),
2901 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2904 lst_free_rpcent(&head);
2910 lst_parse_distribute(char *dstr, int *dist, int *span)
2916 dstr = strchr(dstr, ':');
2920 *span = atoi(dstr + 1);
2928 lst_get_bulk_param(int argc, char **argv, lst_test_bulk_param_t *bulk)
2935 bulk->blk_size = 4096;
2936 bulk->blk_opc = LST_BRW_READ;
2937 bulk->blk_flags = LST_BRW_CHECK_NONE;
2940 if (strcasestr(argv[i], "check=") == argv[i] ||
2941 strcasestr(argv[i], "c=") == argv[i]) {
2942 tok = strchr(argv[i], '=') + 1;
2944 if (strcasecmp(tok, "full") == 0) {
2945 bulk->blk_flags = LST_BRW_CHECK_FULL;
2946 } else if (strcasecmp(tok, "simple") == 0) {
2947 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2949 fprintf(stderr, "Unknow flag %s\n", tok);
2953 } else if (strcasestr(argv[i], "size=") == argv[i] ||
2954 strcasestr(argv[i], "s=") == argv[i]) {
2955 int max_size = sysconf(_SC_PAGESIZE) * LNET_MAX_IOV;
2957 tok = strchr(argv[i], '=') + 1;
2959 bulk->blk_size = strtol(tok, &end, 0);
2960 if (bulk->blk_size <= 0) {
2961 fprintf(stderr, "Invalid size %s\n", tok);
2968 if (*end == 'k' || *end == 'K')
2969 bulk->blk_size *= 1024;
2970 else if (*end == 'm' || *end == 'M')
2971 bulk->blk_size *= 1024 * 1024;
2973 if (bulk->blk_size > max_size) {
2974 fprintf(stderr, "Size exceed limitation: %d bytes\n",
2979 } else if (strcasecmp(argv[i], "read") == 0 ||
2980 strcasecmp(argv[i], "r") == 0) {
2981 bulk->blk_opc = LST_BRW_READ;
2983 } else if (strcasecmp(argv[i], "write") == 0 ||
2984 strcasecmp(argv[i], "w") == 0) {
2985 bulk->blk_opc = LST_BRW_WRITE;
2988 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
2999 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
3001 lst_test_bulk_param_t *bulk = NULL;
3004 type = lst_test_name2type(test);
3006 fprintf(stderr, "Unknow test name %s\n", test);
3015 bulk = malloc(sizeof(*bulk));
3017 fprintf(stderr, "Out of memory\n");
3021 memset(bulk, 0, sizeof(*bulk));
3023 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
3029 *plen = sizeof(*bulk);
3037 /* TODO: parse more parameter */
3042 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
3043 int dist, int span, char *sgrp, char *dgrp,
3044 void *param, int plen, int *retp, struct list_head *resultp)
3046 lstio_test_args_t args = {0};
3048 args.lstio_tes_key = session_key;
3049 args.lstio_tes_bat_nmlen = strlen(batch);
3050 args.lstio_tes_bat_name = batch;
3051 args.lstio_tes_type = type;
3052 args.lstio_tes_oneside = 0;
3053 args.lstio_tes_loop = loop;
3054 args.lstio_tes_concur = concur;
3055 args.lstio_tes_dist = dist;
3056 args.lstio_tes_span = span;
3057 args.lstio_tes_sgrp_nmlen = strlen(sgrp);
3058 args.lstio_tes_sgrp_name = sgrp;
3059 args.lstio_tes_dgrp_nmlen = strlen(dgrp);
3060 args.lstio_tes_dgrp_name = dgrp;
3061 args.lstio_tes_param_len = plen;
3062 args.lstio_tes_param = param;
3063 args.lstio_tes_retp = retp;
3064 args.lstio_tes_resultp = resultp;
3066 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
3070 jt_lst_add_test(int argc, char **argv)
3072 struct list_head head;
3092 static struct option add_test_opts[] =
3094 {"batch", required_argument, 0, 'b' },
3095 {"concurrency", required_argument, 0, 'c' },
3096 {"distribute", required_argument, 0, 'd' },
3097 {"from", required_argument, 0, 'f' },
3098 {"to", required_argument, 0, 't' },
3099 {"loop", required_argument, 0, 'l' },
3103 if (session_key == 0) {
3105 "Can't find env LST_SESSION or value is not valid\n");
3110 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3111 add_test_opts, &optidx);
3113 /* Detect the end of the options. */
3122 concur = atoi(optarg);
3131 loop = atoi(optarg);
3137 lst_print_usage(argv[0]);
3142 if (optind == argc || from == NULL || to == NULL) {
3143 lst_print_usage(argv[0]);
3147 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3148 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3153 batch = LST_DEFAULT_BATCH;
3156 rc = lst_parse_distribute(dstr, &dist, &span);
3158 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3163 test = argv[optind++];
3168 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3170 fprintf(stderr, "Failed to add test (%s)\n", test);
3174 INIT_LIST_HEAD(&head);
3176 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3178 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3179 from, strerror(errno));
3183 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3185 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3186 to, strerror(errno));
3190 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3192 fprintf(stderr, "Out of memory\n");
3196 rc = lst_add_test_ioctl(batch, type, loop, concur,
3197 dist, span, from, to, param, plen, &ret, &head);
3200 fprintf(stdout, "Test was added successfully\n");
3202 fprintf(stdout, "Server group contains userland test "
3203 "nodes, old version of tcplnd can't accept "
3204 "connection request\n");
3211 lst_print_error("test", "Failed to add test: %s\n",
3216 lst_print_transerr(&head, "add test");
3218 lst_free_rpcent(&head);
3226 static command_t lst_cmdlist[] = {
3227 {"new_session", jt_lst_new_session, NULL,
3228 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3229 {"end_session", jt_lst_end_session, NULL,
3230 "Usage: lst end_session" },
3231 {"show_session", jt_lst_show_session, NULL,
3232 "Usage: lst show_session" },
3233 {"ping", jt_lst_ping , NULL,
3234 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3235 {"add_group", jt_lst_add_group, NULL,
3236 "Usage: lst group NAME IDs [IDs]..." },
3237 {"del_group", jt_lst_del_group, NULL,
3238 "Usage: lst del_group NAME" },
3239 {"update_group", jt_lst_update_group, NULL,
3240 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3241 {"list_group", jt_lst_list_group, NULL,
3242 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3243 {"stat", jt_lst_stat, NULL,
3244 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3245 " [--timeout #] [--delay #] [--count #] GROUP [GROUP]" },
3246 {"show_error", jt_lst_show_error, NULL,
3247 "Usage: lst show_error NAME | IDS ..." },
3248 {"add_batch", jt_lst_add_batch, NULL,
3249 "Usage: lst add_batch NAME" },
3250 {"run", jt_lst_start_batch, NULL,
3251 "Usage: lst run [--timeout TIME] [NAME]" },
3252 {"stop", jt_lst_stop_batch, NULL,
3253 "Usage: lst stop [--force] BATCH_NAME" },
3254 {"list_batch", jt_lst_list_batch, NULL,
3255 "Usage: lst list_batch NAME [--test ID] [--server]" },
3256 {"query", jt_lst_query_batch, NULL,
3257 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3258 {"add_test", jt_lst_add_test, NULL,
3259 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3260 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3261 {"help", Parser_help, 0, "help" },
3266 lst_initialize(void)
3271 feats = getenv("LST_FEATURES");
3273 session_features = strtol(feats, NULL, 16);
3275 if ((session_features & ~LST_FEATS_MASK) != 0) {
3277 "Unsupported session features %x, "
3278 "only support these features so far: %x\n",
3279 (session_features & ~LST_FEATS_MASK), LST_FEATS_MASK);
3283 key = getenv("LST_SESSION");
3290 session_key = atoi(key);
3296 main(int argc, char **argv)
3302 rc = libcfs_arch_init();
3306 rc = lst_initialize();
3310 rc = ptl_initialize(argc, argv);
3314 Parser_init("lst > ", lst_cmdlist);
3317 rc = Parser_execarg(argc - 1, argv + 1, lst_cmdlist);
3324 libcfs_arch_cleanup();