1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/selftest/conctl.c
38 * Author: Liang Zhen <liangzhen@clusterfs.com>
49 #include <lnet/lnetctl.h>
50 #include <lnet/lnetst.h>
53 static command_t lst_cmdlist[];
54 static lst_sid_t session_id;
55 static int session_key;
56 static lstcon_trans_stat_t trans_stat;
58 typedef struct list_string {
59 struct list_string *lstr_next;
64 #define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
66 static int alloc_count = 0;
67 static int alloc_nob = 0;
72 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
75 fprintf(stderr, "Can't allocate lstr\n");
82 lstr->lstr_str[0] = 0;
88 free_lstr(lstr_t *lstr)
91 alloc_nob -= lstr->lstr_sz;
96 free_lstrs(lstr_t **list)
100 while ((lstr = *list) != NULL) {
101 *list = lstr->lstr_next;
107 new_lstrs(lstr_t **list, char *prefix, char *postfix,
108 int lo, int hi, int stride)
110 int n1 = strlen(prefix);
111 int n2 = strlen(postfix);
112 int sz = n1 + 20 + n2 + 1;
115 lstr_t *n = alloc_lstr(sz);
117 snprintf(n->lstr_str, sz - 1, "%s%u%s",
118 prefix, lo, postfix);
120 n->lstr_next = *list;
128 expand_lstr(lstr_t **list, lstr_t *l)
130 int nob = strlen(l->lstr_str);
140 b1 = strchr(l->lstr_str, '[');
142 l->lstr_next = *list;
147 b2 = strchr(b1, ']');
148 if (b2 == NULL || b2 == b1 + 1)
156 sep = strchr(expr, ',');
162 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
164 new_lstrs(list, l->lstr_str, b2, x, x, 1);
169 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
172 new_lstrs(list, l->lstr_str, b2, x, y, 1);
177 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
180 new_lstrs(list, l->lstr_str, b2, x, y, z);
186 } while ((expr = sep) != NULL);
194 expand_strs(char *str, lstr_t **head)
202 l = alloc_lstr(strlen(str) + 1);
203 memcpy(l->lstr_str, str, strlen(str) + 1);
211 while ((l = list) != NULL) {
214 rc = expand_lstr(&nlist, l);
216 fprintf(stderr, "Syntax error in \"%s\"\n", str);
224 /* re-order onto 'list' */
225 while ((l = nlist) != NULL) {
226 nlist = l->lstr_next;
231 } while (expanded && rc > 0);
238 while ((l = list) != NULL) {
247 lst_parse_nids(char *str, int *countp, lnet_process_id_t **idspp)
255 rc = expand_strs(str, &head);
265 *idspp = malloc(c * sizeof(lnet_process_id_t));
266 if (*idspp == NULL) {
267 fprintf(stderr, "Out of memory\n");
274 while ((l = head) != NULL) {
278 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
279 if ((*idspp)[i].nid == LNET_NID_ANY) {
280 fprintf(stderr, "Invalid nid: %s\n",
285 (*idspp)[i].pid = LUSTRE_LNET_PID;
302 lst_node_state2str(int state)
304 if (state == LST_NODE_ACTIVE)
306 if (state == LST_NODE_BUSY)
308 if (state == LST_NODE_DOWN)
315 lst_node_str2state(char *str)
317 if (strcasecmp(str, "active") == 0)
318 return LST_NODE_ACTIVE;
319 if (strcasecmp(str, "busy") == 0)
320 return LST_NODE_BUSY;
321 if (strcasecmp(str, "down") == 0)
322 return LST_NODE_DOWN;
323 if (strcasecmp(str, "unknown") == 0)
324 return LST_NODE_UNKNOWN;
325 if (strcasecmp(str, "invalid") == 0)
326 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
332 lst_test_type2name(int type)
334 if (type == LST_TEST_PING)
336 if (type == LST_TEST_BULK)
343 lst_test_name2type(char *name)
345 if (strcasecmp(name, "ping") == 0)
346 return LST_TEST_PING;
347 if (strcasecmp(name, "brw") == 0)
348 return LST_TEST_BULK;
354 lst_print_usage(char *cmd)
356 Parser_printhelp(cmd);
360 lst_print_error(char *sub, const char *def_format, ...)
364 /* local error returned from kernel */
367 fprintf(stderr, "No session exists\n");
370 fprintf(stderr, "Session is shutting down\n");
373 fprintf(stderr, "Unmatched session key or not root\n");
376 fprintf(stderr, "Can't find %s in current session\n", sub);
379 fprintf(stderr, "Invalid parameters list in command line\n");
382 fprintf(stderr, "Bad parameter address\n");
385 fprintf(stderr, "%s already exists\n", sub);
388 va_start(ap, def_format);
389 vfprintf(stderr, def_format, ap);
397 lst_free_rpcent(struct list_head *head)
399 lstcon_rpc_ent_t *ent;
401 while (!list_empty(head)) {
402 ent = list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
404 list_del(&ent->rpe_link);
410 lst_reset_rpcent(struct list_head *head)
412 lstcon_rpc_ent_t *ent;
414 list_for_each_entry(ent, head, rpe_link) {
415 ent->rpe_sid = LST_INVALID_SID;
416 ent->rpe_peer.nid = LNET_NID_ANY;
417 ent->rpe_peer.pid = LNET_PID_ANY;
418 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
423 lst_alloc_rpcent(struct list_head *head, int count, int offset)
425 lstcon_rpc_ent_t *ent;
428 for (i = 0; i < count; i++) {
429 ent = malloc(offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
431 lst_free_rpcent(head);
435 memset(ent, 0, offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
437 ent->rpe_sid = LST_INVALID_SID;
438 ent->rpe_peer.nid = LNET_NID_ANY;
439 ent->rpe_peer.pid = LNET_PID_ANY;
440 list_add(&ent->rpe_link, head);
447 lst_print_transerr(struct list_head *head, char *optstr)
449 lstcon_rpc_ent_t *ent;
451 list_for_each_entry(ent, head, rpe_link) {
452 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
455 if (ent->rpe_rpc_errno != 0) {
456 fprintf(stderr, "%s RPC failed on %s: %s\n",
457 optstr, libcfs_id2str(ent->rpe_peer),
458 strerror(ent->rpe_rpc_errno));
462 fprintf(stderr, "%s failed on %s: %s\n",
463 optstr, libcfs_id2str(ent->rpe_peer),
464 strerror(ent->rpe_fwk_errno));
468 int lst_info_batch_ioctl(char *batch, int test, int server,
469 lstcon_test_batch_ent_t *entp, int *idxp,
470 int *ndentp, lstcon_node_ent_t *dentsp);
472 int lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
473 int *idx, int *count, lstcon_node_ent_t *dents);
475 int lst_query_batch_ioctl(char *batch, int test, int server,
476 int timeout, struct list_head *head);
479 lst_ioctl(unsigned int opc, void *buf, int len)
481 struct libcfs_ioctl_data data;
484 LIBCFS_IOC_INIT (data);
485 data.ioc_u32[0] = opc;
486 data.ioc_plen1 = len;
487 data.ioc_pbuf1 = (char *)buf;
488 data.ioc_plen2 = sizeof(trans_stat);
489 data.ioc_pbuf2 = (char *)&trans_stat;
491 memset(&trans_stat, 0, sizeof(trans_stat));
493 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
495 /* local error, no valid RPC result */
500 if (trans_stat.trs_rpc_errno != 0)
503 /* Framework error */
504 if (trans_stat.trs_fwk_errno != 0)
511 lst_new_session_ioctl (char *name, int timeout, int force, lst_sid_t *sid)
513 lstio_session_new_args_t args = {
514 .lstio_ses_key = session_key,
515 .lstio_ses_timeout = timeout,
516 .lstio_ses_force = force,
517 .lstio_ses_idp = sid,
518 .lstio_ses_namep = name,
519 .lstio_ses_nmlen = strlen(name),
522 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
526 jt_lst_new_session(int argc, char **argv)
528 char buf[LST_NAME_SIZE];
536 static struct option session_opts[] =
538 {"timeout", required_argument, 0, 't' },
539 {"force", no_argument, 0, 'f' },
543 if (session_key == 0) {
545 "Can't find env LST_SESSION or value is not valid\n");
551 c = getopt_long(argc, argv, "ft:",
552 session_opts, &optidx);
562 timeout = atoi(optarg);
565 lst_print_usage(argv[0]);
571 fprintf(stderr, "Invalid timeout value\n");
575 if (optind == argc - 1) {
576 name = argv[optind ++];
577 if (strlen(name) >= LST_NAME_SIZE) {
578 fprintf(stderr, "Name size is limited to %d\n",
583 } else if (optind == argc) {
584 char user[LST_NAME_SIZE];
585 char host[LST_NAME_SIZE];
586 struct passwd *pw = getpwuid(getuid());
589 snprintf(user, sizeof(user), "%d", (int)getuid());
591 snprintf(user, sizeof(user), "%s", pw->pw_name);
593 rc = gethostname(host, sizeof(host));
595 snprintf(host, sizeof(host), "unknown_host");
597 snprintf(buf, LST_NAME_SIZE, "%s@%s", user, host);
601 lst_print_usage(argv[0]);
605 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
608 lst_print_error("session", "Failed to create session: %s\n",
613 fprintf(stdout, "SESSION: %s TIMEOUT: %d FORCE: %s\n",
614 name, timeout, force ? "Yes": "No");
620 lst_session_info_ioctl(char *name, int len, int *key,
621 lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
623 lstio_session_info_args_t args = {
624 .lstio_ses_keyp = key,
625 .lstio_ses_idp = sid,
626 .lstio_ses_ndinfo = ndinfo,
627 .lstio_ses_nmlen = len,
628 .lstio_ses_namep = name,
631 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
635 jt_lst_show_session(int argc, char **argv)
637 lstcon_ndlist_ent_t ndinfo;
639 char name[LST_NAME_SIZE];
643 rc = lst_session_info_ioctl(name, LST_NAME_SIZE, &key, &sid, &ndinfo);
646 lst_print_error("session", "Failed to show session: %s\n",
651 fprintf(stdout, "%s ID: %Lu@%s, KEY: %d NODES: %d\n",
652 name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
653 key, ndinfo.nle_nnode);
659 lst_end_session_ioctl(void)
661 lstio_session_end_args_t args = {
662 .lstio_ses_key = session_key,
665 return lst_ioctl (LSTIO_SESSION_END, &args, sizeof(args));
669 jt_lst_end_session(int argc, char **argv)
673 if (session_key == 0) {
675 "Can't find env LST_SESSION or value is not valid\n");
679 rc = lst_end_session_ioctl();
682 fprintf(stdout, "session is ended\n");
687 lst_print_error("session", "Failed to end session: %s\n",
692 if (trans_stat.trs_rpc_errno != 0) {
694 "[RPC] Failed to send %d session RPCs: %s\n",
695 lstcon_rpc_stat_failure(&trans_stat, 0),
696 strerror(trans_stat.trs_rpc_errno));
699 if (trans_stat.trs_fwk_errno != 0) {
701 "[FWK] Failed to end session on %d nodes: %s\n",
702 lstcon_sesop_stat_failure(&trans_stat, 0),
703 strerror(trans_stat.trs_fwk_errno));
710 lst_ping_ioctl(char *str, int type, int timeout,
711 int count, lnet_process_id_t *ids, struct list_head *head)
713 lstio_debug_args_t args = {
714 .lstio_dbg_key = session_key,
715 .lstio_dbg_type = type,
716 .lstio_dbg_flags = 0,
717 .lstio_dbg_timeout = timeout,
718 .lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str),
719 .lstio_dbg_namep = str,
720 .lstio_dbg_count = count,
721 .lstio_dbg_idsp = ids,
722 .lstio_dbg_resultp = head,
725 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
729 lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
731 char buf[LST_NAME_SIZE];
732 lstcon_test_batch_ent_t ent;
733 lstcon_ndlist_ent_t *entp = &ent.tbe_cli_nle;
739 case LST_OPC_SESSION:
740 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
744 case LST_OPC_BATCHSRV:
745 entp = &ent.tbe_srv_nle;
746 case LST_OPC_BATCHCLI:
747 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
751 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
755 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
764 *countp = entp->nle_nnode;
770 jt_lst_ping(int argc, char **argv)
772 struct list_head head;
773 lnet_process_id_t *ids = NULL;
774 lstcon_rpc_ent_t *ent = NULL;
784 static struct option ping_opts[] =
786 {"session", no_argument, 0, 's' },
787 {"server", no_argument, 0, 'v' },
788 {"batch", required_argument, 0, 'b' },
789 {"group", required_argument, 0, 'g' },
790 {"nodes", required_argument, 0, 'n' },
791 {"timeout", required_argument, 0, 't' },
795 if (session_key == 0) {
797 "Can't find env LST_SESSION or value is not valid\n");
803 c = getopt_long(argc, argv, "g:b:n:t:sv",
811 type = LST_OPC_SESSION;
815 type = LST_OPC_GROUP;
820 type = LST_OPC_BATCHCLI;
825 type = LST_OPC_NODES;
830 timeout = atoi(optarg);
838 lst_print_usage(argv[0]);
843 if (type == 0 || timeout <= 0 || optind != argc) {
844 lst_print_usage(argv[0]);
848 if (type == LST_OPC_BATCHCLI && server)
849 type = LST_OPC_BATCHSRV;
851 rc = lst_get_node_count(type, str, &count, &ids);
853 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
854 (str == NULL) ? "session" : str, strerror(errno));
858 CFS_INIT_LIST_HEAD(&head);
860 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
862 fprintf(stderr, "Out of memory\n");
867 fprintf(stdout, "Target %s is empty\n",
868 (str == NULL) ? "session" : str);
872 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
873 if (rc == -1) { /* local failure */
874 lst_print_error("debug", "Failed to ping %s: %s\n",
875 (str == NULL) ? "session" : str,
881 /* ignore RPC errors and framwork errors */
882 list_for_each_entry(ent, &head, rpe_link) {
883 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
884 libcfs_id2str(ent->rpe_peer),
885 lst_node_state2str(ent->rpe_state),
886 (ent->rpe_state == LST_NODE_ACTIVE ||
887 ent->rpe_state == LST_NODE_BUSY)?
888 (ent->rpe_rpc_errno == 0 ?
889 &ent->rpe_payload[0] : "Unknown") :
890 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
894 lst_free_rpcent(&head);
904 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
905 struct list_head *resultp)
907 lstio_group_nodes_args_t args = {
908 .lstio_grp_key = session_key,
909 .lstio_grp_nmlen = strlen(name),
910 .lstio_grp_namep = name,
911 .lstio_grp_count = count,
912 .lstio_grp_idsp = ids,
913 .lstio_grp_resultp = resultp,
916 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
920 lst_add_group_ioctl (char *name)
922 lstio_group_add_args_t args = {
923 .lstio_grp_key = session_key,
924 .lstio_grp_nmlen = strlen(name),
925 .lstio_grp_namep = name,
928 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
932 jt_lst_add_group(int argc, char **argv)
934 struct list_head head;
935 lnet_process_id_t *ids;
941 if (session_key == 0) {
943 "Can't find env LST_SESSION or value is not valid\n");
948 lst_print_usage(argv[0]);
953 if (strlen(name) >= LST_NAME_SIZE) {
954 fprintf(stderr, "Name length is limited to %d\n",
959 rc = lst_add_group_ioctl(name);
961 lst_print_error("group", "Failed to add group %s: %s\n",
962 name, strerror(errno));
966 CFS_INIT_LIST_HEAD(&head);
968 for (i = 2; i < argc; i++) {
969 /* parse address list */
970 rc = lst_parse_nids(argv[i], &count, &ids);
972 fprintf(stderr, "Ignore invalid id list %s\n",
980 rc = lst_alloc_rpcent(&head, count, 0);
982 fprintf(stderr, "Out of memory\n");
986 rc = lst_add_nodes_ioctl(name, count, ids, &head);
991 lst_free_rpcent(&head);
992 fprintf(stderr, "%s are added to session\n", argv[i]);
997 lst_free_rpcent(&head);
998 lst_print_error("group", "Failed to add nodes %s: %s\n",
999 argv[i], strerror(errno));
1003 lst_print_transerr(&head, "create session");
1004 lst_free_rpcent(&head);
1011 lst_del_group_ioctl (char *name)
1013 lstio_group_del_args_t args = {
1014 .lstio_grp_key = session_key,
1015 .lstio_grp_nmlen = strlen(name),
1016 .lstio_grp_namep = name,
1019 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
1023 jt_lst_del_group(int argc, char **argv)
1027 if (session_key == 0) {
1029 "Can't find env LST_SESSION or value is not valid\n");
1034 lst_print_usage(argv[0]);
1038 rc = lst_del_group_ioctl(argv[1]);
1040 fprintf(stdout, "Group is deleted\n");
1045 lst_print_error("group", "Failed to delete group: %s\n",
1050 fprintf(stderr, "Group is deleted with some errors\n");
1052 if (trans_stat.trs_rpc_errno != 0) {
1053 fprintf(stderr, "[RPC] Failed to send %d end session RPCs: %s\n",
1054 lstcon_rpc_stat_failure(&trans_stat, 0),
1055 strerror(trans_stat.trs_rpc_errno));
1058 if (trans_stat.trs_fwk_errno != 0) {
1060 "[FWK] Failed to end session on %d nodes: %s\n",
1061 lstcon_sesop_stat_failure(&trans_stat, 0),
1062 strerror(trans_stat.trs_fwk_errno));
1069 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1070 lnet_process_id_t *ids, struct list_head *resultp)
1072 lstio_group_update_args_t args = {
1073 .lstio_grp_key = session_key,
1074 .lstio_grp_opc = opc,
1075 .lstio_grp_args = clean,
1076 .lstio_grp_nmlen = strlen(name),
1077 .lstio_grp_namep = name,
1078 .lstio_grp_count = count,
1079 .lstio_grp_idsp = ids,
1080 .lstio_grp_resultp = resultp,
1083 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1087 jt_lst_update_group(int argc, char **argv)
1089 struct list_head head;
1090 lnet_process_id_t *ids = NULL;
1100 static struct option update_group_opts[] =
1102 {"refresh", no_argument, 0, 'f' },
1103 {"clean", required_argument, 0, 'c' },
1104 {"remove", required_argument, 0, 'r' },
1108 if (session_key == 0) {
1110 "Can't find env LST_SESSION or value is not valid\n");
1115 c = getopt_long(argc, argv, "fc:r:",
1116 update_group_opts, &optidx);
1118 /* Detect the end of the options. */
1125 lst_print_usage(argv[0]);
1128 opc = LST_GROUP_REFRESH;
1133 lst_print_usage(argv[0]);
1136 opc = LST_GROUP_RMND;
1141 clean = lst_node_str2state(optarg);
1142 if (opc != 0 || clean <= 0) {
1143 lst_print_usage(argv[0]);
1146 opc = LST_GROUP_CLEAN;
1150 lst_print_usage(argv[0]);
1155 /* no OPC or group is specified */
1156 if (opc == 0 || optind != argc - 1) {
1157 lst_print_usage(argv[0]);
1163 CFS_INIT_LIST_HEAD(&head);
1165 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1166 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1168 opc == LST_GROUP_RMND ? str : grp,
1172 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1173 opc == LST_GROUP_RMND ? str : grp,
1178 rc = lst_alloc_rpcent(&head, count, 0);
1180 fprintf(stderr, "Out of memory\n");
1187 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1193 lst_free_rpcent(&head);
1198 lst_free_rpcent(&head);
1199 lst_print_error("group", "Failed to update group: %s\n",
1204 lst_print_transerr(&head, "Updating group");
1206 lst_free_rpcent(&head);
1212 lst_list_group_ioctl(int len, char *name, int idx)
1214 lstio_group_list_args_t args = {
1215 .lstio_grp_key = session_key,
1216 .lstio_grp_idx = idx,
1217 .lstio_grp_nmlen = len,
1218 .lstio_grp_namep = name,
1221 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1225 lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
1226 int *idx, int *count, lstcon_node_ent_t *dents)
1228 lstio_group_info_args_t args = {
1229 .lstio_grp_key = session_key,
1230 .lstio_grp_nmlen = strlen(name),
1231 .lstio_grp_namep = name,
1232 .lstio_grp_entp = gent,
1233 .lstio_grp_idxp = idx,
1234 .lstio_grp_ndentp = count,
1235 .lstio_grp_dentsp = dents,
1238 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1242 lst_list_group_all(void)
1244 char name[LST_NAME_SIZE];
1248 /* no group is specified, list name of all groups */
1249 for (i = 0; ; i++) {
1250 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1252 fprintf(stdout, "%d) %s\n", i + 1, name);
1256 if (errno == ENOENT)
1259 lst_print_error("group", "Failed to list group: %s\n",
1264 fprintf(stdout, "Total %d groups\n", i);
1269 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1272 jt_lst_list_group(int argc, char **argv)
1274 lstcon_ndlist_ent_t gent;
1275 lstcon_node_ent_t *dents;
1290 static struct option list_group_opts[] =
1292 {"active", no_argument, 0, 'a' },
1293 {"busy", no_argument, 0, 'b' },
1294 {"down", no_argument, 0, 'd' },
1295 {"unknown", no_argument, 0, 'u' },
1296 {"all", no_argument, 0, 'l' },
1300 if (session_key == 0) {
1302 "Can't find env LST_SESSION or value is not valid\n");
1307 c = getopt_long(argc, argv, "abdul",
1308 list_group_opts, &optidx);
1315 verbose = active = 1;
1327 verbose = unknown = 1;
1334 lst_print_usage(argv[0]);
1339 if (optind == argc) {
1340 /* no group is specified, list name of all groups */
1341 rc = lst_list_group_all();
1347 fprintf(stdout, LST_NODES_TITLE);
1349 /* list nodes in specified groups */
1350 for (i = optind; i < argc; i++) {
1351 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1353 if (errno == ENOENT) {
1358 lst_print_error("group", "Failed to list group\n",
1364 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1365 gent.nle_nactive, gent.nle_nbusy,
1366 gent.nle_ndown, gent.nle_nunknown,
1367 gent.nle_nnode, argv[i]);
1371 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1373 if (gent.nle_nnode == 0) {
1374 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1378 count = gent.nle_nnode;
1380 dents = malloc(count * sizeof(lstcon_node_ent_t));
1381 if (dents == NULL) {
1382 fprintf(stderr, "Failed to malloc: %s\n",
1388 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1390 lst_print_error("group", "Failed to list group: %s\n",
1396 for (j = 0, c = 0; j < count; j++) {
1398 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1399 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1400 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1401 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1403 fprintf(stdout, "\t%s: %s\n",
1404 libcfs_id2str(dents[j].nde_id),
1405 lst_node_state2str(dents[j].nde_state));
1410 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1419 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
1420 int timeout, struct list_head *resultp)
1422 lstio_stat_args_t args = {
1423 .lstio_sta_key = session_key,
1424 .lstio_sta_timeout = timeout,
1425 .lstio_sta_nmlen = strlen(name),
1426 .lstio_sta_namep = name,
1427 .lstio_sta_count = count,
1428 .lstio_sta_idsp = idsp,
1429 .lstio_sta_resultp = resultp,
1432 return lst_ioctl (LSTIO_STAT_QUERY, &args, sizeof(args));
1436 struct list_head srp_link;
1439 lnet_process_id_t *srp_ids;
1440 struct list_head srp_result[2];
1441 } lst_stat_req_param_t;
1444 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1448 for (i = 0; i < 2; i++)
1449 lst_free_rpcent(&srp->srp_result[i]);
1451 if (srp->srp_ids != NULL)
1458 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
1460 lst_stat_req_param_t *srp = NULL;
1461 int count = save_old ? 2 : 1;
1465 srp = malloc(sizeof(*srp));
1469 memset(srp, 0, sizeof(*srp));
1470 CFS_INIT_LIST_HEAD(&srp->srp_result[0]);
1471 CFS_INIT_LIST_HEAD(&srp->srp_result[1]);
1473 rc = lst_get_node_count(LST_OPC_GROUP, name,
1474 &srp->srp_count, NULL);
1475 if (rc != 0 && errno == ENOENT) {
1476 rc = lst_get_node_count(LST_OPC_NODES, name,
1477 &srp->srp_count, &srp->srp_ids);
1482 "Failed to get count of nodes from %s: %s\n",
1483 name, strerror(errno));
1484 lst_stat_req_param_free(srp);
1489 srp->srp_name = name;
1491 for (i = 0; i < count; i++) {
1492 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1493 sizeof(sfw_counters_t) +
1494 sizeof(srpc_counters_t) +
1495 sizeof(lnet_counters_t));
1497 fprintf(stderr, "Out of memory\n");
1507 lst_stat_req_param_free(srp);
1514 } lst_srpc_stat_result;
1516 #define LST_LNET_AVG 0
1517 #define LST_LNET_MIN 1
1518 #define LST_LNET_MAX 2
1521 float lnet_avg_sndrate;
1522 float lnet_min_sndrate;
1523 float lnet_max_sndrate;
1524 float lnet_total_sndrate;
1526 float lnet_avg_rcvrate;
1527 float lnet_min_rcvrate;
1528 float lnet_max_rcvrate;
1529 float lnet_total_rcvrate;
1531 float lnet_avg_sndperf;
1532 float lnet_min_sndperf;
1533 float lnet_max_sndperf;
1534 float lnet_total_sndperf;
1536 float lnet_avg_rcvperf;
1537 float lnet_min_rcvperf;
1538 float lnet_max_rcvperf;
1539 float lnet_total_rcvperf;
1541 int lnet_stat_count;
1542 } lst_lnet_stat_result_t;
1544 lst_lnet_stat_result_t lnet_stat_result;
1547 lst_lnet_stat_value(int bw, int send, int off)
1551 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1552 &lnet_stat_result.lnet_avg_sndrate;
1563 lst_timeval_diff(struct timeval *tv1,
1564 struct timeval *tv2, struct timeval *df)
1566 if (tv1->tv_usec >= tv2->tv_usec) {
1567 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1568 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1572 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1573 df->tv_usec = tv1->tv_sec + 1000000 - tv2->tv_usec;
1579 lst_cal_lnet_stat(float delta, lnet_counters_t *lnet_new,
1580 lnet_counters_t *lnet_old)
1585 perf = (float)(lnet_new->send_length -
1586 lnet_old->send_length) / (1024 * 1024) / delta;
1587 lnet_stat_result.lnet_total_sndperf += perf;
1589 if (lnet_stat_result.lnet_min_sndperf > perf ||
1590 lnet_stat_result.lnet_min_sndperf == 0)
1591 lnet_stat_result.lnet_min_sndperf = perf;
1593 if (lnet_stat_result.lnet_max_sndperf < perf)
1594 lnet_stat_result.lnet_max_sndperf = perf;
1596 perf = (float)(lnet_new->recv_length -
1597 lnet_old->recv_length) / (1024 * 1024) / delta;
1598 lnet_stat_result.lnet_total_rcvperf += perf;
1600 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1601 lnet_stat_result.lnet_min_rcvperf == 0)
1602 lnet_stat_result.lnet_min_rcvperf = perf;
1604 if (lnet_stat_result.lnet_max_rcvperf < perf)
1605 lnet_stat_result.lnet_max_rcvperf = perf;
1607 rate = (lnet_new->send_count - lnet_old->send_count) / delta;
1608 lnet_stat_result.lnet_total_sndrate += rate;
1610 if (lnet_stat_result.lnet_min_sndrate > rate ||
1611 lnet_stat_result.lnet_min_sndrate == 0)
1612 lnet_stat_result.lnet_min_sndrate = rate;
1614 if (lnet_stat_result.lnet_max_sndrate < rate)
1615 lnet_stat_result.lnet_max_sndrate = rate;
1617 rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
1618 lnet_stat_result.lnet_total_rcvrate += rate;
1620 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1621 lnet_stat_result.lnet_min_rcvrate == 0)
1622 lnet_stat_result.lnet_min_rcvrate = rate;
1624 if (lnet_stat_result.lnet_max_rcvrate < rate)
1625 lnet_stat_result.lnet_max_rcvrate = rate;
1627 lnet_stat_result.lnet_stat_count ++;
1629 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1630 lnet_stat_result.lnet_stat_count;
1631 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1632 lnet_stat_result.lnet_stat_count;
1634 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1635 lnet_stat_result.lnet_stat_count;
1636 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1637 lnet_stat_result.lnet_stat_count;
1642 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
1651 if (lnet_stat_result.lnet_stat_count == 0)
1654 if (bwrt == 1) /* bw only */
1657 if (bwrt == 2) /* rates only */
1660 if (rdwr == 1) /* recv only */
1663 if (rdwr == 2) /* send only */
1666 for (i = start1; i <= end1; i++) {
1667 fprintf(stdout, "[LNet %s of %s]\n",
1668 i == 0 ? "Rates" : "Bandwidth", name);
1670 for (j = start2; j <= end2; j++) {
1671 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
1673 if ((type & 1) != 0) {
1674 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1675 "Avg: %-8.2f MB/s ",
1676 lst_lnet_stat_value(i, j, 0));
1679 if ((type & 2) != 0) {
1680 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1681 "Min: %-8.2f MB/s ",
1682 lst_lnet_stat_value(i, j, 1));
1685 if ((type & 4) != 0) {
1686 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1688 lst_lnet_stat_value(i, j, 2));
1691 fprintf(stdout, "\n");
1697 lst_print_stat(char *name, struct list_head *resultp,
1698 int idx, int lnet, int bwrt, int rdwr, int type)
1700 struct list_head tmp[2];
1701 lstcon_rpc_ent_t *new;
1702 lstcon_rpc_ent_t *old;
1703 sfw_counters_t *sfwk_new;
1704 sfw_counters_t *sfwk_old;
1705 srpc_counters_t *srpc_new;
1706 srpc_counters_t *srpc_old;
1707 lnet_counters_t *lnet_new;
1708 lnet_counters_t *lnet_old;
1713 CFS_INIT_LIST_HEAD(&tmp[0]);
1714 CFS_INIT_LIST_HEAD(&tmp[1]);
1716 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1718 while (!list_empty(&resultp[idx])) {
1719 if (list_empty(&resultp[1 - idx])) {
1720 fprintf(stderr, "Group is changed, re-run stat\n");
1724 new = list_entry(resultp[idx].next, lstcon_rpc_ent_t, rpe_link);
1725 old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t, rpe_link);
1727 /* first time get stats result, can't calculate diff */
1728 if (new->rpe_peer.nid == LNET_NID_ANY)
1731 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1732 new->rpe_peer.pid != old->rpe_peer.pid) {
1733 /* Something wrong. i.e, somebody change the group */
1737 list_del(&new->rpe_link);
1738 list_add_tail(&new->rpe_link, &tmp[idx]);
1740 list_del(&old->rpe_link);
1741 list_add_tail(&old->rpe_link, &tmp[1 - idx]);
1743 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1744 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1749 sfwk_new = (sfw_counters_t *)&new->rpe_payload[0];
1750 sfwk_old = (sfw_counters_t *)&old->rpe_payload[0];
1752 srpc_new = (srpc_counters_t *)((char *)sfwk_new + sizeof(*sfwk_new));
1753 srpc_old = (srpc_counters_t *)((char *)sfwk_old + sizeof(*sfwk_old));
1755 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
1756 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
1758 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1760 delta = tv.tv_sec + (float)tv.tv_usec/1000000;
1762 if (!lnet) /* TODO */
1765 lst_cal_lnet_stat(delta, lnet_new, lnet_old);
1768 list_splice(&tmp[idx], &resultp[idx]);
1769 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1772 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1774 if (!lnet) /* TODO */
1777 lst_print_lnet_stat(name, bwrt, rdwr, type);
1781 jt_lst_stat(int argc, char **argv)
1783 struct list_head head;
1784 lst_stat_req_param_t *srp;
1787 int timeout = 5; /* default timeout, 5 sec */
1788 int delay = 5; /* default delay, 5 sec */
1789 int lnet = 1; /* lnet stat by default */
1797 static struct option stat_opts[] =
1799 {"timeout", required_argument, 0, 't' },
1800 {"delay" , required_argument, 0, 'd' },
1801 {"lnet" , no_argument, 0, 'l' },
1802 {"rpc" , no_argument, 0, 'c' },
1803 {"bw" , no_argument, 0, 'b' },
1804 {"rate" , no_argument, 0, 'a' },
1805 {"read" , no_argument, 0, 'r' },
1806 {"write" , no_argument, 0, 'w' },
1807 {"avg" , no_argument, 0, 'g' },
1808 {"min" , no_argument, 0, 'n' },
1809 {"max" , no_argument, 0, 'x' },
1813 if (session_key == 0) {
1815 "Can't find env LST_SESSION or value is not valid\n");
1820 c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
1827 timeout = atoi(optarg);
1830 delay = atoi(optarg);
1872 lst_print_usage(argv[0]);
1877 if (optind == argc) {
1878 lst_print_usage(argv[0]);
1882 if (timeout <= 0 || delay <= 0) {
1883 fprintf(stderr, "Invalid timeout or delay value\n");
1887 CFS_INIT_LIST_HEAD(&head);
1889 while (optind < argc) {
1890 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
1894 list_add_tail(&srp->srp_link, &head);
1898 time_t now = time(NULL);
1900 if (now - last < delay) {
1901 sleep(delay - now + last);
1907 list_for_each_entry(srp, &head, srp_link) {
1908 rc = lst_stat_ioctl(srp->srp_name,
1909 srp->srp_count, srp->srp_ids,
1910 timeout, &srp->srp_result[idx]);
1912 lst_print_error("stat", "Failed to stat %s: %s\n",
1913 srp->srp_name, strerror(errno));
1917 lst_print_stat(srp->srp_name, srp->srp_result,
1918 idx, lnet, bwrt, rdwr, type);
1920 lst_reset_rpcent(&srp->srp_result[1 - idx]);
1927 while (!list_empty(&head)) {
1928 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
1930 list_del(&srp->srp_link);
1931 lst_stat_req_param_free(srp);
1938 jt_lst_show_error(int argc, char **argv)
1940 struct list_head head;
1941 lst_stat_req_param_t *srp;
1942 lstcon_rpc_ent_t *ent;
1943 sfw_counters_t *sfwk;
1944 srpc_counters_t *srpc;
1945 lnet_counters_t *lnet;
1952 static struct option show_error_opts[] =
1954 {"session", no_argument, 0, 's' },
1958 if (session_key == 0) {
1960 "Can't find env LST_SESSION or value is not valid\n");
1965 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
1976 lst_print_usage(argv[0]);
1981 if (optind == argc) {
1982 lst_print_usage(argv[0]);
1986 CFS_INIT_LIST_HEAD(&head);
1988 while (optind < argc) {
1989 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
1993 list_add_tail(&srp->srp_link, &head);
1996 list_for_each_entry(srp, &head, srp_link) {
1997 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
1998 srp->srp_ids, 10, &srp->srp_result[0]);
2001 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2002 srp->srp_name, strerror(errno));
2006 fprintf(stdout, "%s:\n", srp->srp_name);
2010 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2011 if (ent->rpe_rpc_errno != 0) {
2013 fprintf(stderr, "RPC failure, can't show error on %s\n",
2014 libcfs_id2str(ent->rpe_peer));
2018 if (ent->rpe_fwk_errno != 0) {
2020 fprintf(stderr, "Framework failure, can't show error on %s\n",
2021 libcfs_id2str(ent->rpe_peer));
2025 sfwk = (sfw_counters_t *)&ent->rpe_payload[0];
2026 srpc = (srpc_counters_t *)((char *)sfwk + sizeof(*sfwk));
2027 lnet = (lnet_counters_t *)((char *)srpc + sizeof(*srpc));
2029 if (srpc->errors == 0 &&
2030 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2034 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2039 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2040 libcfs_id2str(ent->rpe_peer),
2041 sfwk->brw_errors, sfwk->ping_errors,
2042 show_rpc ? ' ' : '\n');
2047 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2048 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2051 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2054 while (!list_empty(&head)) {
2055 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2057 list_del(&srp->srp_link);
2058 lst_stat_req_param_free(srp);
2065 lst_add_batch_ioctl (char *name)
2067 lstio_batch_add_args_t args = {
2068 .lstio_bat_key = session_key,
2069 .lstio_bat_nmlen = strlen(name),
2070 .lstio_bat_namep = name,
2073 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2077 jt_lst_add_batch(int argc, char **argv)
2082 if (session_key == 0) {
2084 "Can't find env LST_SESSION or value is not valid\n");
2089 lst_print_usage(argv[0]);
2094 if (strlen(name) >= LST_NAME_SIZE) {
2095 fprintf(stderr, "Name length is limited to %d\n",
2100 rc = lst_add_batch_ioctl(name);
2104 lst_print_error("batch", "Failed to create batch: %s\n",
2111 lst_start_batch_ioctl (char *name, int timeout, struct list_head *resultp)
2113 lstio_batch_run_args_t args = {
2114 .lstio_bat_key = session_key,
2115 .lstio_bat_timeout = timeout,
2116 .lstio_bat_nmlen = strlen(name),
2117 .lstio_bat_namep = name,
2118 .lstio_bat_resultp = resultp,
2121 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2125 jt_lst_start_batch(int argc, char **argv)
2127 struct list_head head;
2135 static struct option start_batch_opts[] =
2137 {"timeout", required_argument, 0, 't' },
2141 if (session_key == 0) {
2143 "Can't find env LST_SESSION or value is not valid\n");
2148 c = getopt_long(argc, argv, "t:",
2149 start_batch_opts, &optidx);
2151 /* Detect the end of the options. */
2157 timeout = atoi(optarg);
2160 lst_print_usage(argv[0]);
2165 if (optind == argc) {
2166 batch = LST_DEFAULT_BATCH;
2168 } else if (optind == argc - 1) {
2169 batch = argv[optind];
2172 lst_print_usage(argv[0]);
2176 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2178 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2179 batch, strerror(errno));
2183 CFS_INIT_LIST_HEAD(&head);
2185 rc = lst_alloc_rpcent(&head, count, 0);
2187 fprintf(stderr, "Out of memory\n");
2191 rc = lst_start_batch_ioctl(batch, timeout, &head);
2194 fprintf(stdout, "%s is running now\n", batch);
2195 lst_free_rpcent(&head);
2200 lst_print_error("batch", "Failed to start batch: %s\n",
2202 lst_free_rpcent(&head);
2206 lst_print_transerr(&head, "Run batch");
2208 lst_free_rpcent(&head);
2214 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2216 lstio_batch_stop_args_t args = {
2217 .lstio_bat_key = session_key,
2218 .lstio_bat_force = force,
2219 .lstio_bat_nmlen = strlen(name),
2220 .lstio_bat_namep = name,
2221 .lstio_bat_resultp = resultp,
2224 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2228 jt_lst_stop_batch(int argc, char **argv)
2230 struct list_head head;
2238 static struct option stop_batch_opts[] =
2240 {"force", no_argument, 0, 'f' },
2244 if (session_key == 0) {
2246 "Can't find env LST_SESSION or value is not valid\n");
2251 c = getopt_long(argc, argv, "f",
2252 stop_batch_opts, &optidx);
2254 /* Detect the end of the options. */
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 CFS_INIT_LIST_HEAD(&head);
2288 rc = lst_alloc_rpcent(&head, count, 0);
2290 fprintf(stderr, "Out of memory\n");
2294 rc = lst_stop_batch_ioctl(batch, force, &head);
2299 lst_reset_rpcent(&head);
2301 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2305 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2306 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2309 fprintf(stdout, "%d batch in stopping\n",
2310 lstcon_tsbqry_stat_run(&trans_stat, 0));
2314 fprintf(stdout, "Batch is stopped\n");
2315 lst_free_rpcent(&head);
2320 lst_print_error("batch", "Failed to stop batch: %s\n",
2322 lst_free_rpcent(&head);
2326 lst_print_transerr(&head, "stop batch");
2328 lst_free_rpcent(&head);
2334 lst_list_batch_ioctl(int len, char *name, int index)
2336 lstio_batch_list_args_t args = {
2337 .lstio_bat_key = session_key,
2338 .lstio_bat_idx = index,
2339 .lstio_bat_nmlen = len,
2340 .lstio_bat_namep = name,
2343 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2347 lst_info_batch_ioctl(char *batch, int test, int server,
2348 lstcon_test_batch_ent_t *entp, int *idxp,
2349 int *ndentp, lstcon_node_ent_t *dentsp)
2351 lstio_batch_info_args_t args = {
2352 .lstio_bat_key = session_key,
2353 .lstio_bat_nmlen = strlen(batch),
2354 .lstio_bat_namep = batch,
2355 .lstio_bat_server = server,
2356 .lstio_bat_testidx = test,
2357 .lstio_bat_entp = entp,
2358 .lstio_bat_idxp = idxp,
2359 .lstio_bat_ndentp = ndentp,
2360 .lstio_bat_dentsp = dentsp,
2363 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2367 lst_list_batch_all(void)
2369 char name[LST_NAME_SIZE];
2373 for (i = 0; ; i++) {
2374 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2376 fprintf(stdout, "%d) %s\n", i + 1, name);
2380 if (errno == ENOENT)
2383 lst_print_error("batch", "Failed to list batch: %s\n",
2388 fprintf(stdout, "Total %d batches\n", i);
2394 lst_list_tsb_nodes(char *batch, int test, int server,
2395 int count, int active, int invalid)
2397 lstcon_node_ent_t *dents;
2406 /* verbose list, show nodes in batch or test */
2407 dents = malloc(count * sizeof(lstcon_node_ent_t));
2408 if (dents == NULL) {
2409 fprintf(stdout, "Can't allocate memory\n");
2413 rc = lst_info_batch_ioctl(batch, test, server,
2414 NULL, &index, &count, dents);
2417 lst_print_error((test > 0) ? "test" : "batch",
2418 (test > 0) ? "Failed to query test: %s\n" :
2419 "Failed to query batch: %s\n",
2424 for (i = 0, c = 0; i < count; i++) {
2425 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2426 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2427 dents[i].nde_state == LST_NODE_DOWN ||
2428 dents[i].nde_state == LST_NODE_UNKNOWN)))
2431 fprintf(stdout, "\t%s: %s\n",
2432 libcfs_id2str(dents[i].nde_id),
2433 lst_node_state2str(dents[i].nde_state));
2437 fprintf(stdout, "Total %d nodes\n", c);
2444 jt_lst_list_batch(int argc, char **argv)
2446 lstcon_test_batch_ent_t ent;
2449 int verbose = 0; /* list nodes in batch or test */
2458 static struct option list_batch_opts[] =
2460 {"test", required_argument, 0, 't' },
2461 {"invalid", no_argument, 0, 'i' },
2462 {"active", no_argument, 0, 'a' },
2463 {"all", no_argument, 0, 'l' },
2464 {"server", no_argument, 0, 's' },
2468 if (session_key == 0) {
2470 "Can't find env LST_SESSION or value is not valid\n");
2475 c = getopt_long(argc, argv, "ailst:",
2476 list_batch_opts, &optidx);
2483 verbose = active = 1;
2486 verbose = invalid = 1;
2489 verbose = active = invalid = 1;
2495 test = atoi(optarg);
2499 lst_print_usage(argv[0]);
2504 if (optind == argc) {
2505 /* list all batches */
2506 rc = lst_list_batch_all();
2510 if (ntest == 1 && test <= 0) {
2511 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2515 if (optind != argc - 1) {
2516 lst_print_usage(argv[0]);
2520 batch = argv[optind];
2523 /* show detail of specified batch or test */
2524 rc = lst_info_batch_ioctl(batch, test, server,
2525 &ent, NULL, NULL, NULL);
2527 lst_print_error((test > 0) ? "test" : "batch",
2528 (test > 0) ? "Failed to query test: %s\n" :
2529 "Failed to query batch: %s\n",
2535 /* list nodes in test or batch */
2536 rc = lst_list_tsb_nodes(batch, test, server,
2537 server ? ent.tbe_srv_nle.nle_nnode :
2538 ent.tbe_cli_nle.nle_nnode,
2543 /* only show number of hosts in batch or test */
2545 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2546 batch, ent.u.tbe_batch.bae_ntest,
2547 ent.u.tbe_batch.bae_state);
2548 ntest = ent.u.tbe_batch.bae_ntest;
2549 test = 1; /* starting from test 1 */
2553 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2554 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2555 ent.u.tbe_test.tse_loop,
2556 ent.u.tbe_test.tse_concur);
2561 fprintf(stdout, LST_NODES_TITLE);
2562 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2563 "server\t%d\t%d\t%d\t%d\t%d\n",
2564 ent.tbe_cli_nle.nle_nactive,
2565 ent.tbe_cli_nle.nle_nbusy,
2566 ent.tbe_cli_nle.nle_ndown,
2567 ent.tbe_cli_nle.nle_nunknown,
2568 ent.tbe_cli_nle.nle_nnode,
2569 ent.tbe_srv_nle.nle_nactive,
2570 ent.tbe_srv_nle.nle_nbusy,
2571 ent.tbe_srv_nle.nle_ndown,
2572 ent.tbe_srv_nle.nle_nunknown,
2573 ent.tbe_srv_nle.nle_nnode);
2582 lst_query_batch_ioctl(char *batch, int test, int server,
2583 int timeout, struct list_head *head)
2585 lstio_batch_query_args_t args = {
2586 .lstio_bat_key = session_key,
2587 .lstio_bat_testidx = test,
2588 .lstio_bat_client = !(server),
2589 .lstio_bat_timeout = timeout,
2590 .lstio_bat_nmlen = strlen(batch),
2591 .lstio_bat_namep = batch,
2592 .lstio_bat_resultp = head,
2595 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2599 lst_print_tsb_verbose(struct list_head *head,
2600 int active, int idle, int error)
2602 lstcon_rpc_ent_t *ent;
2604 list_for_each_entry(ent, head, rpe_link) {
2605 if (ent->rpe_priv[0] == 0 && active)
2608 if (ent->rpe_priv[0] != 0 && idle)
2611 if (ent->rpe_fwk_errno == 0 && error)
2614 fprintf(stdout, "%s [%s]: %s\n",
2615 libcfs_id2str(ent->rpe_peer),
2616 lst_node_state2str(ent->rpe_state),
2617 ent->rpe_rpc_errno != 0 ?
2618 strerror(ent->rpe_rpc_errno) :
2619 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2624 jt_lst_query_batch(int argc, char **argv)
2626 lstcon_test_batch_ent_t ent;
2627 struct list_head head;
2633 int timeout = 5; /* default 5 seconds */
2634 int delay = 5; /* default 5 seconds */
2635 int loop = 1; /* default 1 loop */
2645 static struct option query_batch_opts[] =
2647 {"timeout", required_argument, 0, 'o' },
2648 {"delay", required_argument, 0, 'd' },
2649 {"loop", required_argument, 0, 'c' },
2650 {"test", required_argument, 0, 't' },
2651 {"server", no_argument, 0, 's' },
2652 {"active", no_argument, 0, 'a' },
2653 {"idle", no_argument, 0, 'i' },
2654 {"error", no_argument, 0, 'e' },
2655 {"all", no_argument, 0, 'l' },
2659 if (session_key == 0) {
2661 "Can't find env LST_SESSION or value is not valid\n");
2666 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2667 query_batch_opts, &optidx);
2669 /* Detect the end of the options. */
2675 timeout = atoi(optarg);
2678 delay = atoi(optarg);
2681 loop = atoi(optarg);
2684 test = atoi(optarg);
2690 active = verbose = 1;
2696 error = verbose = 1;
2702 lst_print_usage(argv[0]);
2707 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2708 lst_print_usage(argv[0]);
2712 if (optind == argc) {
2713 batch = LST_DEFAULT_BATCH;
2715 } else if (optind == argc - 1) {
2716 batch = argv[optind];
2719 lst_print_usage(argv[0]);
2724 CFS_INIT_LIST_HEAD(&head);
2727 rc = lst_info_batch_ioctl(batch, test, server,
2728 &ent, NULL, NULL, NULL);
2730 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2731 batch, test, strerror(errno));
2735 count = server ? ent.tbe_srv_nle.nle_nnode :
2736 ent.tbe_cli_nle.nle_nnode;
2738 fprintf(stdout, "Batch or test is empty\n");
2743 rc = lst_alloc_rpcent(&head, count, 0);
2745 fprintf(stderr, "Out of memory\n");
2749 for (i = 0; i < loop; i++) {
2750 time_t now = time(NULL);
2752 if (now - last < delay) {
2753 sleep(delay - now + last);
2759 rc = lst_query_batch_ioctl(batch, test,
2760 server, timeout, &head);
2762 fprintf(stderr, "Failed to query batch: %s\n",
2769 lst_print_tsb_verbose(&head, active, idle, error);
2773 fprintf(stdout, "%s [%d] ", batch, test);
2775 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2776 fprintf(stdout, "%d of %d nodes are unknown, ",
2777 lstcon_rpc_stat_failure(&trans_stat, 0),
2778 lstcon_rpc_stat_total(&trans_stat, 0));
2781 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2782 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2783 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2784 fprintf(stdout, "is stopped\n");
2788 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2789 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2790 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2791 fprintf(stdout, "is running\n");
2795 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2796 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2797 lstcon_tsbqry_stat_run(&trans_stat, 0),
2798 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2801 lst_free_rpcent(&head);
2807 lst_parse_distribute(char *dstr, int *dist, int *span)
2813 dstr = strchr(dstr, ':');
2817 *span = atoi(dstr + 1);
2825 lst_get_bulk_param(int argc, char **argv, lst_test_bulk_param_t *bulk)
2832 bulk->blk_size = 4096;
2833 bulk->blk_opc = LST_BRW_READ;
2834 bulk->blk_flags = LST_BRW_CHECK_NONE;
2837 if (strcasestr(argv[i], "check=") == argv[i] ||
2838 strcasestr(argv[i], "c=") == argv[i]) {
2839 tok = strchr(argv[i], '=') + 1;
2841 if (strcasecmp(tok, "full") == 0) {
2842 bulk->blk_flags = LST_BRW_CHECK_FULL;
2843 } else if (strcasecmp(tok, "simple") == 0) {
2844 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2846 fprintf(stderr, "Unknow flag %s\n", tok);
2850 } else if (strcasestr(argv[i], "size=") == argv[i] ||
2851 strcasestr(argv[i], "s=") == argv[i]) {
2852 tok = strchr(argv[i], '=') + 1;
2854 bulk->blk_size = strtol(tok, &end, 0);
2855 if (bulk->blk_size <= 0) {
2856 fprintf(stderr, "Invalid size %s\n", tok);
2863 if (*end == 'k' || *end == 'K')
2864 bulk->blk_size *= 1024;
2865 else if (*end == 'm' || *end == 'M')
2866 bulk->blk_size *= 1024 * 1024;
2868 if (bulk->blk_size > CFS_PAGE_SIZE * LNET_MAX_IOV) {
2869 fprintf(stderr, "Size exceed limitation: %d bytes\n",
2874 } else if (strcasecmp(argv[i], "read") == 0 ||
2875 strcasecmp(argv[i], "r") == 0) {
2876 bulk->blk_opc = LST_BRW_READ;
2878 } else if (strcasecmp(argv[i], "write") == 0 ||
2879 strcasecmp(argv[i], "w") == 0) {
2880 bulk->blk_opc = LST_BRW_WRITE;
2883 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
2894 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
2896 lst_test_bulk_param_t *bulk = NULL;
2899 type = lst_test_name2type(test);
2901 fprintf(stderr, "Unknow test name %s\n", test);
2910 bulk = malloc(sizeof(*bulk));
2912 fprintf(stderr, "Out of memory\n");
2916 memset(bulk, 0, sizeof(*bulk));
2918 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
2924 *plen = sizeof(*bulk);
2932 /* TODO: parse more parameter */
2937 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
2938 int dist, int span, char *sgrp, char *dgrp,
2939 void *param, int plen, int *retp, struct list_head *resultp)
2941 lstio_test_args_t args = {
2942 .lstio_tes_key = session_key,
2943 .lstio_tes_bat_nmlen = strlen(batch),
2944 .lstio_tes_bat_name = batch,
2945 .lstio_tes_type = type,
2946 .lstio_tes_loop = loop,
2947 .lstio_tes_concur = concur,
2948 .lstio_tes_dist = dist,
2949 .lstio_tes_span = span,
2950 .lstio_tes_sgrp_nmlen = strlen(sgrp),
2951 .lstio_tes_sgrp_name = sgrp,
2952 .lstio_tes_dgrp_nmlen = strlen(dgrp),
2953 .lstio_tes_dgrp_name = dgrp,
2954 .lstio_tes_param_len = plen,
2955 .lstio_tes_param = param,
2956 .lstio_tes_retp = retp,
2957 .lstio_tes_resultp = resultp,
2960 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
2964 jt_lst_add_test(int argc, char **argv)
2966 struct list_head head;
2986 static struct option add_test_opts[] =
2988 {"batch", required_argument, 0, 'b' },
2989 {"concurrency", required_argument, 0, 'c' },
2990 {"distribute", required_argument, 0, 'd' },
2991 {"from", required_argument, 0, 'f' },
2992 {"to", required_argument, 0, 't' },
2993 {"loop", required_argument, 0, 'l' },
2997 if (session_key == 0) {
2999 "Can't find env LST_SESSION or value is not valid\n");
3004 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3005 add_test_opts, &optidx);
3007 /* Detect the end of the options. */
3016 concur = atoi(optarg);
3025 loop = atoi(optarg);
3031 lst_print_usage(argv[0]);
3036 if (optind == argc || from == NULL || to == NULL) {
3037 lst_print_usage(argv[0]);
3041 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3042 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3047 batch = LST_DEFAULT_BATCH;
3050 rc = lst_parse_distribute(dstr, &dist, &span);
3052 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3057 test = argv[optind++];
3062 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3064 fprintf(stderr, "Failed to add test (%s)\n", test);
3068 CFS_INIT_LIST_HEAD(&head);
3070 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3072 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3073 from, strerror(errno));
3077 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3079 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3080 to, strerror(errno));
3084 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3086 fprintf(stderr, "Out of memory\n");
3090 rc = lst_add_test_ioctl(batch, type, loop, concur,
3091 dist, span, from, to, param, plen, &ret, &head);
3094 fprintf(stdout, "Test was added successfully\n");
3096 fprintf(stdout, "Server group contains userland test "
3097 "nodes, old version of tcplnd can't accept "
3098 "connection request\n");
3105 lst_print_error("test", "Failed to add test: %s\n",
3110 lst_print_transerr(&head, "add test");
3112 lst_free_rpcent(&head);
3120 static command_t lst_cmdlist[] = {
3121 {"new_session", jt_lst_new_session, NULL,
3122 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3123 {"end_session", jt_lst_end_session, NULL,
3124 "Usage: lst end_session" },
3125 {"show_session", jt_lst_show_session, NULL,
3126 "Usage: lst show_session" },
3127 {"ping", jt_lst_ping , NULL,
3128 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3129 {"add_group", jt_lst_add_group, NULL,
3130 "Usage: lst group NAME IDs [IDs]..." },
3131 {"del_group", jt_lst_del_group, NULL,
3132 "Usage: lst del_group NAME" },
3133 {"update_group", jt_lst_update_group, NULL,
3134 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3135 {"list_group", jt_lst_list_group, NULL,
3136 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3137 {"stat", jt_lst_stat, NULL,
3138 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3139 " [--timeout #] [--delay #] GROUP [GROUP]" },
3140 {"show_error", jt_lst_show_error, NULL,
3141 "Usage: lst show_error NAME | IDS ..." },
3142 {"add_batch", jt_lst_add_batch, NULL,
3143 "Usage: lst add_batch NAME" },
3144 {"run", jt_lst_start_batch, NULL,
3145 "Usage: lst run [--timeout TIME] [NAME]" },
3146 {"stop", jt_lst_stop_batch, NULL,
3147 "Usage: lst stop [--force] BATCH_NAME" },
3148 {"list_batch", jt_lst_list_batch, NULL,
3149 "Usage: lst list_batch NAME [--test ID] [--server]" },
3150 {"query", jt_lst_query_batch, NULL,
3151 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3152 {"add_test", jt_lst_add_test, NULL,
3153 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3154 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3155 {"help", Parser_help, 0, "help" },
3160 lst_initialize(void)
3164 key = getenv("LST_SESSION");
3171 session_key = atoi(key);
3177 main(int argc, char **argv)
3181 if (lst_initialize() < 0)
3184 if (ptl_initialize(argc, argv) < 0)
3187 Parser_init("lst > ", lst_cmdlist);
3190 return Parser_execarg(argc - 1, argv + 1, lst_cmdlist);