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 2008 Sun Microsystems, Inc. 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>
51 #include <libcfs/libcfsutil.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;
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 = LUSTRE_LNET_PID;
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, "%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 = {
516 .lstio_ses_key = session_key,
517 .lstio_ses_timeout = timeout,
518 .lstio_ses_force = force,
519 .lstio_ses_idp = sid,
520 .lstio_ses_namep = name,
521 .lstio_ses_nmlen = strlen(name),
524 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
528 jt_lst_new_session(int argc, char **argv)
530 char buf[LST_NAME_SIZE];
538 static struct option session_opts[] =
540 {"timeout", required_argument, 0, 't' },
541 {"force", no_argument, 0, 'f' },
545 if (session_key == 0) {
547 "Can't find env LST_SESSION or value is not valid\n");
553 c = getopt_long(argc, argv, "ft:",
554 session_opts, &optidx);
564 timeout = atoi(optarg);
567 lst_print_usage(argv[0]);
573 fprintf(stderr, "Invalid timeout value\n");
577 if (optind == argc - 1) {
578 name = argv[optind ++];
579 if (strlen(name) >= LST_NAME_SIZE) {
580 fprintf(stderr, "Name size is limited to %d\n",
585 } else if (optind == argc) {
586 char user[LST_NAME_SIZE];
587 char host[LST_NAME_SIZE];
588 struct passwd *pw = getpwuid(getuid());
591 snprintf(user, sizeof(user), "%d", (int)getuid());
593 snprintf(user, sizeof(user), "%s", pw->pw_name);
595 rc = gethostname(host, sizeof(host));
597 snprintf(host, sizeof(host), "unknown_host");
599 snprintf(buf, LST_NAME_SIZE, "%s@%s", user, host);
603 lst_print_usage(argv[0]);
607 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 TIMEOUT: %d FORCE: %s\n",
616 name, timeout, force ? "Yes": "No");
622 lst_session_info_ioctl(char *name, int len, int *key,
623 lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
625 lstio_session_info_args_t args = {
626 .lstio_ses_keyp = key,
627 .lstio_ses_idp = sid,
628 .lstio_ses_ndinfo = ndinfo,
629 .lstio_ses_nmlen = len,
630 .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];
645 rc = lst_session_info_ioctl(name, LST_NAME_SIZE, &key, &sid, &ndinfo);
648 lst_print_error("session", "Failed to show session: %s\n",
653 fprintf(stdout, "%s ID: %Lu@%s, KEY: %d NODES: %d\n",
654 name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
655 key, ndinfo.nle_nnode);
661 lst_end_session_ioctl(void)
663 lstio_session_end_args_t args = {
664 .lstio_ses_key = session_key,
667 return lst_ioctl (LSTIO_SESSION_END, &args, sizeof(args));
671 jt_lst_end_session(int argc, char **argv)
675 if (session_key == 0) {
677 "Can't find env LST_SESSION or value is not valid\n");
681 rc = lst_end_session_ioctl();
684 fprintf(stdout, "session is ended\n");
689 lst_print_error("session", "Failed to end session: %s\n",
694 if (trans_stat.trs_rpc_errno != 0) {
696 "[RPC] Failed to send %d session RPCs: %s\n",
697 lstcon_rpc_stat_failure(&trans_stat, 0),
698 strerror(trans_stat.trs_rpc_errno));
701 if (trans_stat.trs_fwk_errno != 0) {
703 "[FWK] Failed to end session on %d nodes: %s\n",
704 lstcon_sesop_stat_failure(&trans_stat, 0),
705 strerror(trans_stat.trs_fwk_errno));
712 lst_ping_ioctl(char *str, int type, int timeout,
713 int count, lnet_process_id_t *ids, struct list_head *head)
715 lstio_debug_args_t args = {
716 .lstio_dbg_key = session_key,
717 .lstio_dbg_type = type,
718 .lstio_dbg_flags = 0,
719 .lstio_dbg_timeout = timeout,
720 .lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str),
721 .lstio_dbg_namep = str,
722 .lstio_dbg_count = count,
723 .lstio_dbg_idsp = ids,
724 .lstio_dbg_resultp = head,
727 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
731 lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
733 char buf[LST_NAME_SIZE];
734 lstcon_test_batch_ent_t ent;
735 lstcon_ndlist_ent_t *entp = &ent.tbe_cli_nle;
741 case LST_OPC_SESSION:
742 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
746 case LST_OPC_BATCHSRV:
747 entp = &ent.tbe_srv_nle;
748 case LST_OPC_BATCHCLI:
749 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
753 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
757 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
766 *countp = entp->nle_nnode;
772 jt_lst_ping(int argc, char **argv)
774 struct list_head head;
775 lnet_process_id_t *ids = NULL;
776 lstcon_rpc_ent_t *ent = NULL;
786 static struct option ping_opts[] =
788 {"session", no_argument, 0, 's' },
789 {"server", no_argument, 0, 'v' },
790 {"batch", required_argument, 0, 'b' },
791 {"group", required_argument, 0, 'g' },
792 {"nodes", required_argument, 0, 'n' },
793 {"timeout", required_argument, 0, 't' },
797 if (session_key == 0) {
799 "Can't find env LST_SESSION or value is not valid\n");
805 c = getopt_long(argc, argv, "g:b:n:t:sv",
813 type = LST_OPC_SESSION;
817 type = LST_OPC_GROUP;
822 type = LST_OPC_BATCHCLI;
827 type = LST_OPC_NODES;
832 timeout = atoi(optarg);
840 lst_print_usage(argv[0]);
845 if (type == 0 || timeout <= 0 || optind != argc) {
846 lst_print_usage(argv[0]);
850 if (type == LST_OPC_BATCHCLI && server)
851 type = LST_OPC_BATCHSRV;
853 rc = lst_get_node_count(type, str, &count, &ids);
855 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
856 (str == NULL) ? "session" : str, strerror(errno));
860 CFS_INIT_LIST_HEAD(&head);
862 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
864 fprintf(stderr, "Out of memory\n");
869 fprintf(stdout, "Target %s is empty\n",
870 (str == NULL) ? "session" : str);
874 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
875 if (rc == -1) { /* local failure */
876 lst_print_error("debug", "Failed to ping %s: %s\n",
877 (str == NULL) ? "session" : str,
883 /* ignore RPC errors and framwork errors */
884 list_for_each_entry(ent, &head, rpe_link) {
885 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
886 libcfs_id2str(ent->rpe_peer),
887 lst_node_state2str(ent->rpe_state),
888 (ent->rpe_state == LST_NODE_ACTIVE ||
889 ent->rpe_state == LST_NODE_BUSY)?
890 (ent->rpe_rpc_errno == 0 ?
891 &ent->rpe_payload[0] : "Unknown") :
892 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
896 lst_free_rpcent(&head);
906 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
907 struct list_head *resultp)
909 lstio_group_nodes_args_t args = {
910 .lstio_grp_key = session_key,
911 .lstio_grp_nmlen = strlen(name),
912 .lstio_grp_namep = name,
913 .lstio_grp_count = count,
914 .lstio_grp_idsp = ids,
915 .lstio_grp_resultp = resultp,
918 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
922 lst_add_group_ioctl (char *name)
924 lstio_group_add_args_t args = {
925 .lstio_grp_key = session_key,
926 .lstio_grp_nmlen = strlen(name),
927 .lstio_grp_namep = name,
930 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
934 jt_lst_add_group(int argc, char **argv)
936 struct list_head head;
937 lnet_process_id_t *ids;
943 if (session_key == 0) {
945 "Can't find env LST_SESSION or value is not valid\n");
950 lst_print_usage(argv[0]);
955 if (strlen(name) >= LST_NAME_SIZE) {
956 fprintf(stderr, "Name length is limited to %d\n",
961 rc = lst_add_group_ioctl(name);
963 lst_print_error("group", "Failed to add group %s: %s\n",
964 name, strerror(errno));
968 CFS_INIT_LIST_HEAD(&head);
970 for (i = 2; i < argc; i++) {
971 /* parse address list */
972 rc = lst_parse_nids(argv[i], &count, &ids);
974 fprintf(stderr, "Ignore invalid id list %s\n",
982 rc = lst_alloc_rpcent(&head, count, 0);
984 fprintf(stderr, "Out of memory\n");
988 rc = lst_add_nodes_ioctl(name, count, ids, &head);
993 lst_free_rpcent(&head);
994 fprintf(stderr, "%s are added to session\n", argv[i]);
999 lst_free_rpcent(&head);
1000 lst_print_error("group", "Failed to add nodes %s: %s\n",
1001 argv[i], strerror(errno));
1005 lst_print_transerr(&head, "create session");
1006 lst_free_rpcent(&head);
1013 lst_del_group_ioctl (char *name)
1015 lstio_group_del_args_t args = {
1016 .lstio_grp_key = session_key,
1017 .lstio_grp_nmlen = strlen(name),
1018 .lstio_grp_namep = name,
1021 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
1025 jt_lst_del_group(int argc, char **argv)
1029 if (session_key == 0) {
1031 "Can't find env LST_SESSION or value is not valid\n");
1036 lst_print_usage(argv[0]);
1040 rc = lst_del_group_ioctl(argv[1]);
1042 fprintf(stdout, "Group is deleted\n");
1047 lst_print_error("group", "Failed to delete group: %s\n",
1052 fprintf(stderr, "Group is deleted with some errors\n");
1054 if (trans_stat.trs_rpc_errno != 0) {
1055 fprintf(stderr, "[RPC] Failed to send %d end session RPCs: %s\n",
1056 lstcon_rpc_stat_failure(&trans_stat, 0),
1057 strerror(trans_stat.trs_rpc_errno));
1060 if (trans_stat.trs_fwk_errno != 0) {
1062 "[FWK] Failed to end session on %d nodes: %s\n",
1063 lstcon_sesop_stat_failure(&trans_stat, 0),
1064 strerror(trans_stat.trs_fwk_errno));
1071 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1072 lnet_process_id_t *ids, struct list_head *resultp)
1074 lstio_group_update_args_t args = {
1075 .lstio_grp_key = session_key,
1076 .lstio_grp_opc = opc,
1077 .lstio_grp_args = clean,
1078 .lstio_grp_nmlen = strlen(name),
1079 .lstio_grp_namep = name,
1080 .lstio_grp_count = count,
1081 .lstio_grp_idsp = ids,
1082 .lstio_grp_resultp = resultp,
1085 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1089 jt_lst_update_group(int argc, char **argv)
1091 struct list_head head;
1092 lnet_process_id_t *ids = NULL;
1102 static struct option update_group_opts[] =
1104 {"refresh", no_argument, 0, 'f' },
1105 {"clean", required_argument, 0, 'c' },
1106 {"remove", required_argument, 0, 'r' },
1110 if (session_key == 0) {
1112 "Can't find env LST_SESSION or value is not valid\n");
1117 c = getopt_long(argc, argv, "fc:r:",
1118 update_group_opts, &optidx);
1120 /* Detect the end of the options. */
1127 lst_print_usage(argv[0]);
1130 opc = LST_GROUP_REFRESH;
1135 lst_print_usage(argv[0]);
1138 opc = LST_GROUP_RMND;
1143 clean = lst_node_str2state(optarg);
1144 if (opc != 0 || clean <= 0) {
1145 lst_print_usage(argv[0]);
1148 opc = LST_GROUP_CLEAN;
1152 lst_print_usage(argv[0]);
1157 /* no OPC or group is specified */
1158 if (opc == 0 || optind != argc - 1) {
1159 lst_print_usage(argv[0]);
1165 CFS_INIT_LIST_HEAD(&head);
1167 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1168 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1170 opc == LST_GROUP_RMND ? str : grp,
1174 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1175 opc == LST_GROUP_RMND ? str : grp,
1180 rc = lst_alloc_rpcent(&head, count, 0);
1182 fprintf(stderr, "Out of memory\n");
1189 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1195 lst_free_rpcent(&head);
1200 lst_free_rpcent(&head);
1201 lst_print_error("group", "Failed to update group: %s\n",
1206 lst_print_transerr(&head, "Updating group");
1208 lst_free_rpcent(&head);
1214 lst_list_group_ioctl(int len, char *name, int idx)
1216 lstio_group_list_args_t args = {
1217 .lstio_grp_key = session_key,
1218 .lstio_grp_idx = idx,
1219 .lstio_grp_nmlen = len,
1220 .lstio_grp_namep = name,
1223 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1227 lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
1228 int *idx, int *count, lstcon_node_ent_t *dents)
1230 lstio_group_info_args_t args = {
1231 .lstio_grp_key = session_key,
1232 .lstio_grp_nmlen = strlen(name),
1233 .lstio_grp_namep = name,
1234 .lstio_grp_entp = gent,
1235 .lstio_grp_idxp = idx,
1236 .lstio_grp_ndentp = count,
1237 .lstio_grp_dentsp = dents,
1240 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1244 lst_list_group_all(void)
1246 char name[LST_NAME_SIZE];
1250 /* no group is specified, list name of all groups */
1251 for (i = 0; ; i++) {
1252 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1254 fprintf(stdout, "%d) %s\n", i + 1, name);
1258 if (errno == ENOENT)
1261 lst_print_error("group", "Failed to list group: %s\n",
1266 fprintf(stdout, "Total %d groups\n", i);
1271 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1274 jt_lst_list_group(int argc, char **argv)
1276 lstcon_ndlist_ent_t gent;
1277 lstcon_node_ent_t *dents;
1292 static struct option list_group_opts[] =
1294 {"active", no_argument, 0, 'a' },
1295 {"busy", no_argument, 0, 'b' },
1296 {"down", no_argument, 0, 'd' },
1297 {"unknown", no_argument, 0, 'u' },
1298 {"all", no_argument, 0, 'l' },
1302 if (session_key == 0) {
1304 "Can't find env LST_SESSION or value is not valid\n");
1309 c = getopt_long(argc, argv, "abdul",
1310 list_group_opts, &optidx);
1317 verbose = active = 1;
1329 verbose = unknown = 1;
1336 lst_print_usage(argv[0]);
1341 if (optind == argc) {
1342 /* no group is specified, list name of all groups */
1343 rc = lst_list_group_all();
1349 fprintf(stdout, LST_NODES_TITLE);
1351 /* list nodes in specified groups */
1352 for (i = optind; i < argc; i++) {
1353 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
1355 if (errno == ENOENT) {
1360 lst_print_error("group", "Failed to list group\n",
1366 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1367 gent.nle_nactive, gent.nle_nbusy,
1368 gent.nle_ndown, gent.nle_nunknown,
1369 gent.nle_nnode, argv[i]);
1373 fprintf(stdout, "Group [ %s ]\n", argv[i]);
1375 if (gent.nle_nnode == 0) {
1376 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
1380 count = gent.nle_nnode;
1382 dents = malloc(count * sizeof(lstcon_node_ent_t));
1383 if (dents == NULL) {
1384 fprintf(stderr, "Failed to malloc: %s\n",
1390 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
1392 lst_print_error("group", "Failed to list group: %s\n",
1398 for (j = 0, c = 0; j < count; j++) {
1400 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
1401 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
1402 (down && dents[j].nde_state == LST_NODE_DOWN) ||
1403 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
1405 fprintf(stdout, "\t%s: %s\n",
1406 libcfs_id2str(dents[j].nde_id),
1407 lst_node_state2str(dents[j].nde_state));
1412 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
1421 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
1422 int timeout, struct list_head *resultp)
1424 lstio_stat_args_t args = {
1425 .lstio_sta_key = session_key,
1426 .lstio_sta_timeout = timeout,
1427 .lstio_sta_nmlen = strlen(name),
1428 .lstio_sta_namep = name,
1429 .lstio_sta_count = count,
1430 .lstio_sta_idsp = idsp,
1431 .lstio_sta_resultp = resultp,
1434 return lst_ioctl (LSTIO_STAT_QUERY, &args, sizeof(args));
1438 struct list_head srp_link;
1441 lnet_process_id_t *srp_ids;
1442 struct list_head srp_result[2];
1443 } lst_stat_req_param_t;
1446 lst_stat_req_param_free(lst_stat_req_param_t *srp)
1450 for (i = 0; i < 2; i++)
1451 lst_free_rpcent(&srp->srp_result[i]);
1453 if (srp->srp_ids != NULL)
1460 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
1462 lst_stat_req_param_t *srp = NULL;
1463 int count = save_old ? 2 : 1;
1467 srp = malloc(sizeof(*srp));
1471 memset(srp, 0, sizeof(*srp));
1472 CFS_INIT_LIST_HEAD(&srp->srp_result[0]);
1473 CFS_INIT_LIST_HEAD(&srp->srp_result[1]);
1475 rc = lst_get_node_count(LST_OPC_GROUP, name,
1476 &srp->srp_count, NULL);
1477 if (rc != 0 && errno == ENOENT) {
1478 rc = lst_get_node_count(LST_OPC_NODES, name,
1479 &srp->srp_count, &srp->srp_ids);
1484 "Failed to get count of nodes from %s: %s\n",
1485 name, strerror(errno));
1486 lst_stat_req_param_free(srp);
1491 srp->srp_name = name;
1493 for (i = 0; i < count; i++) {
1494 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
1495 sizeof(sfw_counters_t) +
1496 sizeof(srpc_counters_t) +
1497 sizeof(lnet_counters_t));
1499 fprintf(stderr, "Out of memory\n");
1509 lst_stat_req_param_free(srp);
1516 } lst_srpc_stat_result;
1518 #define LST_LNET_AVG 0
1519 #define LST_LNET_MIN 1
1520 #define LST_LNET_MAX 2
1523 float lnet_avg_sndrate;
1524 float lnet_min_sndrate;
1525 float lnet_max_sndrate;
1526 float lnet_total_sndrate;
1528 float lnet_avg_rcvrate;
1529 float lnet_min_rcvrate;
1530 float lnet_max_rcvrate;
1531 float lnet_total_rcvrate;
1533 float lnet_avg_sndperf;
1534 float lnet_min_sndperf;
1535 float lnet_max_sndperf;
1536 float lnet_total_sndperf;
1538 float lnet_avg_rcvperf;
1539 float lnet_min_rcvperf;
1540 float lnet_max_rcvperf;
1541 float lnet_total_rcvperf;
1543 int lnet_stat_count;
1544 } lst_lnet_stat_result_t;
1546 lst_lnet_stat_result_t lnet_stat_result;
1549 lst_lnet_stat_value(int bw, int send, int off)
1553 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
1554 &lnet_stat_result.lnet_avg_sndrate;
1565 lst_timeval_diff(struct timeval *tv1,
1566 struct timeval *tv2, struct timeval *df)
1568 if (tv1->tv_usec >= tv2->tv_usec) {
1569 df->tv_sec = tv1->tv_sec - tv2->tv_sec;
1570 df->tv_usec = tv1->tv_usec - tv2->tv_usec;
1574 df->tv_sec = tv1->tv_sec - 1 - tv2->tv_sec;
1575 df->tv_usec = tv1->tv_sec + 1000000 - tv2->tv_usec;
1581 lst_cal_lnet_stat(float delta, lnet_counters_t *lnet_new,
1582 lnet_counters_t *lnet_old)
1587 perf = (float)(lnet_new->send_length -
1588 lnet_old->send_length) / (1024 * 1024) / delta;
1589 lnet_stat_result.lnet_total_sndperf += perf;
1591 if (lnet_stat_result.lnet_min_sndperf > perf ||
1592 lnet_stat_result.lnet_min_sndperf == 0)
1593 lnet_stat_result.lnet_min_sndperf = perf;
1595 if (lnet_stat_result.lnet_max_sndperf < perf)
1596 lnet_stat_result.lnet_max_sndperf = perf;
1598 perf = (float)(lnet_new->recv_length -
1599 lnet_old->recv_length) / (1024 * 1024) / delta;
1600 lnet_stat_result.lnet_total_rcvperf += perf;
1602 if (lnet_stat_result.lnet_min_rcvperf > perf ||
1603 lnet_stat_result.lnet_min_rcvperf == 0)
1604 lnet_stat_result.lnet_min_rcvperf = perf;
1606 if (lnet_stat_result.lnet_max_rcvperf < perf)
1607 lnet_stat_result.lnet_max_rcvperf = perf;
1609 rate = (lnet_new->send_count - lnet_old->send_count) / delta;
1610 lnet_stat_result.lnet_total_sndrate += rate;
1612 if (lnet_stat_result.lnet_min_sndrate > rate ||
1613 lnet_stat_result.lnet_min_sndrate == 0)
1614 lnet_stat_result.lnet_min_sndrate = rate;
1616 if (lnet_stat_result.lnet_max_sndrate < rate)
1617 lnet_stat_result.lnet_max_sndrate = rate;
1619 rate = (lnet_new->recv_count - lnet_old->recv_count) / delta;
1620 lnet_stat_result.lnet_total_rcvrate += rate;
1622 if (lnet_stat_result.lnet_min_rcvrate > rate ||
1623 lnet_stat_result.lnet_min_rcvrate == 0)
1624 lnet_stat_result.lnet_min_rcvrate = rate;
1626 if (lnet_stat_result.lnet_max_rcvrate < rate)
1627 lnet_stat_result.lnet_max_rcvrate = rate;
1629 lnet_stat_result.lnet_stat_count ++;
1631 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
1632 lnet_stat_result.lnet_stat_count;
1633 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
1634 lnet_stat_result.lnet_stat_count;
1636 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
1637 lnet_stat_result.lnet_stat_count;
1638 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
1639 lnet_stat_result.lnet_stat_count;
1644 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
1653 if (lnet_stat_result.lnet_stat_count == 0)
1656 if (bwrt == 1) /* bw only */
1659 if (bwrt == 2) /* rates only */
1662 if (rdwr == 1) /* recv only */
1665 if (rdwr == 2) /* send only */
1668 for (i = start1; i <= end1; i++) {
1669 fprintf(stdout, "[LNet %s of %s]\n",
1670 i == 0 ? "Rates" : "Bandwidth", name);
1672 for (j = start2; j <= end2; j++) {
1673 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
1675 if ((type & 1) != 0) {
1676 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
1677 "Avg: %-8.2f MB/s ",
1678 lst_lnet_stat_value(i, j, 0));
1681 if ((type & 2) != 0) {
1682 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
1683 "Min: %-8.2f MB/s ",
1684 lst_lnet_stat_value(i, j, 1));
1687 if ((type & 4) != 0) {
1688 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
1690 lst_lnet_stat_value(i, j, 2));
1693 fprintf(stdout, "\n");
1699 lst_print_stat(char *name, struct list_head *resultp,
1700 int idx, int lnet, int bwrt, int rdwr, int type)
1702 struct list_head tmp[2];
1703 lstcon_rpc_ent_t *new;
1704 lstcon_rpc_ent_t *old;
1705 sfw_counters_t *sfwk_new;
1706 sfw_counters_t *sfwk_old;
1707 srpc_counters_t *srpc_new;
1708 srpc_counters_t *srpc_old;
1709 lnet_counters_t *lnet_new;
1710 lnet_counters_t *lnet_old;
1715 CFS_INIT_LIST_HEAD(&tmp[0]);
1716 CFS_INIT_LIST_HEAD(&tmp[1]);
1718 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
1720 while (!list_empty(&resultp[idx])) {
1721 if (list_empty(&resultp[1 - idx])) {
1722 fprintf(stderr, "Group is changed, re-run stat\n");
1726 new = list_entry(resultp[idx].next, lstcon_rpc_ent_t, rpe_link);
1727 old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t, rpe_link);
1729 /* first time get stats result, can't calculate diff */
1730 if (new->rpe_peer.nid == LNET_NID_ANY)
1733 if (new->rpe_peer.nid != old->rpe_peer.nid ||
1734 new->rpe_peer.pid != old->rpe_peer.pid) {
1735 /* Something wrong. i.e, somebody change the group */
1739 list_del(&new->rpe_link);
1740 list_add_tail(&new->rpe_link, &tmp[idx]);
1742 list_del(&old->rpe_link);
1743 list_add_tail(&old->rpe_link, &tmp[1 - idx]);
1745 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
1746 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
1751 sfwk_new = (sfw_counters_t *)&new->rpe_payload[0];
1752 sfwk_old = (sfw_counters_t *)&old->rpe_payload[0];
1754 srpc_new = (srpc_counters_t *)((char *)sfwk_new + sizeof(*sfwk_new));
1755 srpc_old = (srpc_counters_t *)((char *)sfwk_old + sizeof(*sfwk_old));
1757 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
1758 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
1760 lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
1762 delta = tv.tv_sec + (float)tv.tv_usec/1000000;
1764 if (!lnet) /* TODO */
1767 lst_cal_lnet_stat(delta, lnet_new, lnet_old);
1770 list_splice(&tmp[idx], &resultp[idx]);
1771 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
1774 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
1776 if (!lnet) /* TODO */
1779 lst_print_lnet_stat(name, bwrt, rdwr, type);
1783 jt_lst_stat(int argc, char **argv)
1785 struct list_head head;
1786 lst_stat_req_param_t *srp;
1789 int timeout = 5; /* default timeout, 5 sec */
1790 int delay = 5; /* default delay, 5 sec */
1791 int lnet = 1; /* lnet stat by default */
1799 static struct option stat_opts[] =
1801 {"timeout", required_argument, 0, 't' },
1802 {"delay" , required_argument, 0, 'd' },
1803 {"lnet" , no_argument, 0, 'l' },
1804 {"rpc" , no_argument, 0, 'c' },
1805 {"bw" , no_argument, 0, 'b' },
1806 {"rate" , no_argument, 0, 'a' },
1807 {"read" , no_argument, 0, 'r' },
1808 {"write" , no_argument, 0, 'w' },
1809 {"avg" , no_argument, 0, 'g' },
1810 {"min" , no_argument, 0, 'n' },
1811 {"max" , no_argument, 0, 'x' },
1815 if (session_key == 0) {
1817 "Can't find env LST_SESSION or value is not valid\n");
1822 c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
1829 timeout = atoi(optarg);
1832 delay = atoi(optarg);
1874 lst_print_usage(argv[0]);
1879 if (optind == argc) {
1880 lst_print_usage(argv[0]);
1884 if (timeout <= 0 || delay <= 0) {
1885 fprintf(stderr, "Invalid timeout or delay value\n");
1889 CFS_INIT_LIST_HEAD(&head);
1891 while (optind < argc) {
1892 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
1896 list_add_tail(&srp->srp_link, &head);
1900 time_t now = time(NULL);
1902 if (now - last < delay) {
1903 sleep(delay - now + last);
1909 list_for_each_entry(srp, &head, srp_link) {
1910 rc = lst_stat_ioctl(srp->srp_name,
1911 srp->srp_count, srp->srp_ids,
1912 timeout, &srp->srp_result[idx]);
1914 lst_print_error("stat", "Failed to stat %s: %s\n",
1915 srp->srp_name, strerror(errno));
1919 lst_print_stat(srp->srp_name, srp->srp_result,
1920 idx, lnet, bwrt, rdwr, type);
1922 lst_reset_rpcent(&srp->srp_result[1 - idx]);
1929 while (!list_empty(&head)) {
1930 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
1932 list_del(&srp->srp_link);
1933 lst_stat_req_param_free(srp);
1940 jt_lst_show_error(int argc, char **argv)
1942 struct list_head head;
1943 lst_stat_req_param_t *srp;
1944 lstcon_rpc_ent_t *ent;
1945 sfw_counters_t *sfwk;
1946 srpc_counters_t *srpc;
1947 lnet_counters_t *lnet;
1954 static struct option show_error_opts[] =
1956 {"session", no_argument, 0, 's' },
1960 if (session_key == 0) {
1962 "Can't find env LST_SESSION or value is not valid\n");
1967 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
1978 lst_print_usage(argv[0]);
1983 if (optind == argc) {
1984 lst_print_usage(argv[0]);
1988 CFS_INIT_LIST_HEAD(&head);
1990 while (optind < argc) {
1991 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
1995 list_add_tail(&srp->srp_link, &head);
1998 list_for_each_entry(srp, &head, srp_link) {
1999 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
2000 srp->srp_ids, 5, &srp->srp_result[0]);
2003 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2004 srp->srp_name, strerror(errno));
2008 fprintf(stdout, "%s:\n", srp->srp_name);
2012 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2013 if (ent->rpe_rpc_errno != 0) {
2015 fprintf(stderr, "RPC failure, can't show error on %s\n",
2016 libcfs_id2str(ent->rpe_peer));
2020 if (ent->rpe_fwk_errno != 0) {
2022 fprintf(stderr, "Framework failure, can't show error on %s\n",
2023 libcfs_id2str(ent->rpe_peer));
2027 sfwk = (sfw_counters_t *)&ent->rpe_payload[0];
2028 srpc = (srpc_counters_t *)((char *)sfwk + sizeof(*sfwk));
2029 lnet = (lnet_counters_t *)((char *)srpc + sizeof(*srpc));
2031 if (srpc->errors == 0 &&
2032 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2036 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2041 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2042 libcfs_id2str(ent->rpe_peer),
2043 sfwk->brw_errors, sfwk->ping_errors,
2044 show_rpc ? ' ' : '\n');
2049 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2050 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2053 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2056 while (!list_empty(&head)) {
2057 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2059 list_del(&srp->srp_link);
2060 lst_stat_req_param_free(srp);
2067 lst_add_batch_ioctl (char *name)
2069 lstio_batch_add_args_t args = {
2070 .lstio_bat_key = session_key,
2071 .lstio_bat_nmlen = strlen(name),
2072 .lstio_bat_namep = name,
2075 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2079 jt_lst_add_batch(int argc, char **argv)
2084 if (session_key == 0) {
2086 "Can't find env LST_SESSION or value is not valid\n");
2091 lst_print_usage(argv[0]);
2096 if (strlen(name) >= LST_NAME_SIZE) {
2097 fprintf(stderr, "Name length is limited to %d\n",
2102 rc = lst_add_batch_ioctl(name);
2106 lst_print_error("batch", "Failed to create batch: %s\n",
2113 lst_start_batch_ioctl (char *name, int timeout, struct list_head *resultp)
2115 lstio_batch_run_args_t args = {
2116 .lstio_bat_key = session_key,
2117 .lstio_bat_timeout = timeout,
2118 .lstio_bat_nmlen = strlen(name),
2119 .lstio_bat_namep = name,
2120 .lstio_bat_resultp = resultp,
2123 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2127 jt_lst_start_batch(int argc, char **argv)
2129 struct list_head head;
2137 static struct option start_batch_opts[] =
2139 {"timeout", required_argument, 0, 't' },
2143 if (session_key == 0) {
2145 "Can't find env LST_SESSION or value is not valid\n");
2150 c = getopt_long(argc, argv, "t:",
2151 start_batch_opts, &optidx);
2153 /* Detect the end of the options. */
2159 timeout = atoi(optarg);
2162 lst_print_usage(argv[0]);
2167 if (optind == argc) {
2168 batch = LST_DEFAULT_BATCH;
2170 } else if (optind == argc - 1) {
2171 batch = argv[optind];
2174 lst_print_usage(argv[0]);
2178 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2180 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2181 batch, strerror(errno));
2185 CFS_INIT_LIST_HEAD(&head);
2187 rc = lst_alloc_rpcent(&head, count, 0);
2189 fprintf(stderr, "Out of memory\n");
2193 rc = lst_start_batch_ioctl(batch, timeout, &head);
2196 fprintf(stdout, "%s is running now\n", batch);
2197 lst_free_rpcent(&head);
2202 lst_print_error("batch", "Failed to start batch: %s\n",
2204 lst_free_rpcent(&head);
2208 lst_print_transerr(&head, "Run batch");
2210 lst_free_rpcent(&head);
2216 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2218 lstio_batch_stop_args_t args = {
2219 .lstio_bat_key = session_key,
2220 .lstio_bat_force = force,
2221 .lstio_bat_nmlen = strlen(name),
2222 .lstio_bat_namep = name,
2223 .lstio_bat_resultp = resultp,
2226 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
2230 jt_lst_stop_batch(int argc, char **argv)
2232 struct list_head head;
2240 static struct option stop_batch_opts[] =
2242 {"force", no_argument, 0, 'f' },
2246 if (session_key == 0) {
2248 "Can't find env LST_SESSION or value is not valid\n");
2253 c = getopt_long(argc, argv, "f",
2254 stop_batch_opts, &optidx);
2256 /* Detect the end of the options. */
2265 lst_print_usage(argv[0]);
2270 if (optind == argc) {
2271 batch = LST_DEFAULT_BATCH;
2273 } else if (optind == argc - 1) {
2274 batch = argv[optind];
2277 lst_print_usage(argv[0]);
2281 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2283 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2284 batch, strerror(errno));
2288 CFS_INIT_LIST_HEAD(&head);
2290 rc = lst_alloc_rpcent(&head, count, 0);
2292 fprintf(stderr, "Out of memory\n");
2296 rc = lst_stop_batch_ioctl(batch, force, &head);
2301 lst_reset_rpcent(&head);
2303 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
2307 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2308 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
2311 fprintf(stdout, "%d batch in stopping\n",
2312 lstcon_tsbqry_stat_run(&trans_stat, 0));
2316 fprintf(stdout, "Batch is stopped\n");
2317 lst_free_rpcent(&head);
2322 lst_print_error("batch", "Failed to stop batch: %s\n",
2324 lst_free_rpcent(&head);
2328 lst_print_transerr(&head, "stop batch");
2330 lst_free_rpcent(&head);
2336 lst_list_batch_ioctl(int len, char *name, int index)
2338 lstio_batch_list_args_t args = {
2339 .lstio_bat_key = session_key,
2340 .lstio_bat_idx = index,
2341 .lstio_bat_nmlen = len,
2342 .lstio_bat_namep = name,
2345 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
2349 lst_info_batch_ioctl(char *batch, int test, int server,
2350 lstcon_test_batch_ent_t *entp, int *idxp,
2351 int *ndentp, lstcon_node_ent_t *dentsp)
2353 lstio_batch_info_args_t args = {
2354 .lstio_bat_key = session_key,
2355 .lstio_bat_nmlen = strlen(batch),
2356 .lstio_bat_namep = batch,
2357 .lstio_bat_server = server,
2358 .lstio_bat_testidx = test,
2359 .lstio_bat_entp = entp,
2360 .lstio_bat_idxp = idxp,
2361 .lstio_bat_ndentp = ndentp,
2362 .lstio_bat_dentsp = dentsp,
2365 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
2369 lst_list_batch_all(void)
2371 char name[LST_NAME_SIZE];
2375 for (i = 0; ; i++) {
2376 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
2378 fprintf(stdout, "%d) %s\n", i + 1, name);
2382 if (errno == ENOENT)
2385 lst_print_error("batch", "Failed to list batch: %s\n",
2390 fprintf(stdout, "Total %d batches\n", i);
2396 lst_list_tsb_nodes(char *batch, int test, int server,
2397 int count, int active, int invalid)
2399 lstcon_node_ent_t *dents;
2408 /* verbose list, show nodes in batch or test */
2409 dents = malloc(count * sizeof(lstcon_node_ent_t));
2410 if (dents == NULL) {
2411 fprintf(stdout, "Can't allocate memory\n");
2415 rc = lst_info_batch_ioctl(batch, test, server,
2416 NULL, &index, &count, dents);
2419 lst_print_error((test > 0) ? "test" : "batch",
2420 (test > 0) ? "Failed to query test: %s\n" :
2421 "Failed to query batch: %s\n",
2426 for (i = 0, c = 0; i < count; i++) {
2427 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
2428 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
2429 dents[i].nde_state == LST_NODE_DOWN ||
2430 dents[i].nde_state == LST_NODE_UNKNOWN)))
2433 fprintf(stdout, "\t%s: %s\n",
2434 libcfs_id2str(dents[i].nde_id),
2435 lst_node_state2str(dents[i].nde_state));
2439 fprintf(stdout, "Total %d nodes\n", c);
2446 jt_lst_list_batch(int argc, char **argv)
2448 lstcon_test_batch_ent_t ent;
2451 int verbose = 0; /* list nodes in batch or test */
2460 static struct option list_batch_opts[] =
2462 {"test", required_argument, 0, 't' },
2463 {"invalid", no_argument, 0, 'i' },
2464 {"active", no_argument, 0, 'a' },
2465 {"all", no_argument, 0, 'l' },
2466 {"server", no_argument, 0, 's' },
2470 if (session_key == 0) {
2472 "Can't find env LST_SESSION or value is not valid\n");
2477 c = getopt_long(argc, argv, "ailst:",
2478 list_batch_opts, &optidx);
2485 verbose = active = 1;
2488 verbose = invalid = 1;
2491 verbose = active = invalid = 1;
2497 test = atoi(optarg);
2501 lst_print_usage(argv[0]);
2506 if (optind == argc) {
2507 /* list all batches */
2508 rc = lst_list_batch_all();
2512 if (ntest == 1 && test <= 0) {
2513 fprintf(stderr, "Invalid test id, test id starts from 1\n");
2517 if (optind != argc - 1) {
2518 lst_print_usage(argv[0]);
2522 batch = argv[optind];
2525 /* show detail of specified batch or test */
2526 rc = lst_info_batch_ioctl(batch, test, server,
2527 &ent, NULL, NULL, NULL);
2529 lst_print_error((test > 0) ? "test" : "batch",
2530 (test > 0) ? "Failed to query test: %s\n" :
2531 "Failed to query batch: %s\n",
2537 /* list nodes in test or batch */
2538 rc = lst_list_tsb_nodes(batch, test, server,
2539 server ? ent.tbe_srv_nle.nle_nnode :
2540 ent.tbe_cli_nle.nle_nnode,
2545 /* only show number of hosts in batch or test */
2547 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
2548 batch, ent.u.tbe_batch.bae_ntest,
2549 ent.u.tbe_batch.bae_state);
2550 ntest = ent.u.tbe_batch.bae_ntest;
2551 test = 1; /* starting from test 1 */
2555 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
2556 test, lst_test_type2name(ent.u.tbe_test.tse_type),
2557 ent.u.tbe_test.tse_loop,
2558 ent.u.tbe_test.tse_concur);
2563 fprintf(stdout, LST_NODES_TITLE);
2564 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
2565 "server\t%d\t%d\t%d\t%d\t%d\n",
2566 ent.tbe_cli_nle.nle_nactive,
2567 ent.tbe_cli_nle.nle_nbusy,
2568 ent.tbe_cli_nle.nle_ndown,
2569 ent.tbe_cli_nle.nle_nunknown,
2570 ent.tbe_cli_nle.nle_nnode,
2571 ent.tbe_srv_nle.nle_nactive,
2572 ent.tbe_srv_nle.nle_nbusy,
2573 ent.tbe_srv_nle.nle_ndown,
2574 ent.tbe_srv_nle.nle_nunknown,
2575 ent.tbe_srv_nle.nle_nnode);
2584 lst_query_batch_ioctl(char *batch, int test, int server,
2585 int timeout, struct list_head *head)
2587 lstio_batch_query_args_t args = {
2588 .lstio_bat_key = session_key,
2589 .lstio_bat_testidx = test,
2590 .lstio_bat_client = !(server),
2591 .lstio_bat_timeout = timeout,
2592 .lstio_bat_nmlen = strlen(batch),
2593 .lstio_bat_namep = batch,
2594 .lstio_bat_resultp = head,
2597 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
2601 lst_print_tsb_verbose(struct list_head *head,
2602 int active, int idle, int error)
2604 lstcon_rpc_ent_t *ent;
2606 list_for_each_entry(ent, head, rpe_link) {
2607 if (ent->rpe_priv[0] == 0 && active)
2610 if (ent->rpe_priv[0] != 0 && idle)
2613 if (ent->rpe_fwk_errno == 0 && error)
2616 fprintf(stdout, "%s [%s]: %s\n",
2617 libcfs_id2str(ent->rpe_peer),
2618 lst_node_state2str(ent->rpe_state),
2619 ent->rpe_rpc_errno != 0 ?
2620 strerror(ent->rpe_rpc_errno) :
2621 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
2626 jt_lst_query_batch(int argc, char **argv)
2628 lstcon_test_batch_ent_t ent;
2629 struct list_head head;
2635 int timeout = 5; /* default 5 seconds */
2636 int delay = 5; /* default 5 seconds */
2637 int loop = 1; /* default 1 loop */
2647 static struct option query_batch_opts[] =
2649 {"timeout", required_argument, 0, 'o' },
2650 {"delay", required_argument, 0, 'd' },
2651 {"loop", required_argument, 0, 'c' },
2652 {"test", required_argument, 0, 't' },
2653 {"server", no_argument, 0, 's' },
2654 {"active", no_argument, 0, 'a' },
2655 {"idle", no_argument, 0, 'i' },
2656 {"error", no_argument, 0, 'e' },
2657 {"all", no_argument, 0, 'l' },
2661 if (session_key == 0) {
2663 "Can't find env LST_SESSION or value is not valid\n");
2668 c = getopt_long(argc, argv, "o:d:c:t:saiel",
2669 query_batch_opts, &optidx);
2671 /* Detect the end of the options. */
2677 timeout = atoi(optarg);
2680 delay = atoi(optarg);
2683 loop = atoi(optarg);
2686 test = atoi(optarg);
2692 active = verbose = 1;
2698 error = verbose = 1;
2704 lst_print_usage(argv[0]);
2709 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
2710 lst_print_usage(argv[0]);
2714 if (optind == argc) {
2715 batch = LST_DEFAULT_BATCH;
2717 } else if (optind == argc - 1) {
2718 batch = argv[optind];
2721 lst_print_usage(argv[0]);
2726 CFS_INIT_LIST_HEAD(&head);
2729 rc = lst_info_batch_ioctl(batch, test, server,
2730 &ent, NULL, NULL, NULL);
2732 fprintf(stderr, "Failed to query %s [%d]: %s\n",
2733 batch, test, strerror(errno));
2737 count = server ? ent.tbe_srv_nle.nle_nnode :
2738 ent.tbe_cli_nle.nle_nnode;
2740 fprintf(stdout, "Batch or test is empty\n");
2745 rc = lst_alloc_rpcent(&head, count, 0);
2747 fprintf(stderr, "Out of memory\n");
2751 for (i = 0; i < loop; i++) {
2752 time_t now = time(NULL);
2754 if (now - last < delay) {
2755 sleep(delay - now + last);
2761 rc = lst_query_batch_ioctl(batch, test,
2762 server, timeout, &head);
2764 fprintf(stderr, "Failed to query batch: %s\n",
2771 lst_print_tsb_verbose(&head, active, idle, error);
2775 fprintf(stdout, "%s [%d] ", batch, test);
2777 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
2778 fprintf(stdout, "%d of %d nodes are unknown, ",
2779 lstcon_rpc_stat_failure(&trans_stat, 0),
2780 lstcon_rpc_stat_total(&trans_stat, 0));
2783 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2784 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
2785 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2786 fprintf(stdout, "is stopped\n");
2790 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
2791 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
2792 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
2793 fprintf(stdout, "is running\n");
2797 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
2798 lstcon_tsbqry_stat_idle(&trans_stat, 0),
2799 lstcon_tsbqry_stat_run(&trans_stat, 0),
2800 lstcon_tsbqry_stat_failure(&trans_stat, 0));
2803 lst_free_rpcent(&head);
2809 lst_parse_distribute(char *dstr, int *dist, int *span)
2815 dstr = strchr(dstr, ':');
2819 *span = atoi(dstr + 1);
2827 lst_get_bulk_param(int argc, char **argv, lst_test_bulk_param_t *bulk)
2834 bulk->blk_size = 4096;
2835 bulk->blk_opc = LST_BRW_READ;
2836 bulk->blk_flags = LST_BRW_CHECK_NONE;
2839 if (strcasestr(argv[i], "check=") == argv[i] ||
2840 strcasestr(argv[i], "c=") == argv[i]) {
2841 tok = strchr(argv[i], '=') + 1;
2843 if (strcasecmp(tok, "full") == 0) {
2844 bulk->blk_flags = LST_BRW_CHECK_FULL;
2845 } else if (strcasecmp(tok, "simple") == 0) {
2846 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
2848 fprintf(stderr, "Unknow flag %s\n", tok);
2852 } else if (strcasestr(argv[i], "size=") == argv[i] ||
2853 strcasestr(argv[i], "s=") == argv[i]) {
2854 tok = strchr(argv[i], '=') + 1;
2856 bulk->blk_size = strtol(tok, &end, 0);
2857 if (bulk->blk_size <= 0) {
2858 fprintf(stderr, "Invalid size %s\n", tok);
2865 if (*end == 'k' || *end == 'K')
2866 bulk->blk_size *= 1024;
2867 else if (*end == 'm' || *end == 'M')
2868 bulk->blk_size *= 1024 * 1024;
2870 if (bulk->blk_size > CFS_PAGE_SIZE * LNET_MAX_IOV) {
2871 fprintf(stderr, "Size exceed limitation: %d bytes\n",
2876 } else if (strcasecmp(argv[i], "read") == 0 ||
2877 strcasecmp(argv[i], "r") == 0) {
2878 bulk->blk_opc = LST_BRW_READ;
2880 } else if (strcasecmp(argv[i], "write") == 0 ||
2881 strcasecmp(argv[i], "w") == 0) {
2882 bulk->blk_opc = LST_BRW_WRITE;
2885 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
2896 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
2898 lst_test_bulk_param_t *bulk = NULL;
2901 type = lst_test_name2type(test);
2903 fprintf(stderr, "Unknow test name %s\n", test);
2912 bulk = malloc(sizeof(*bulk));
2914 fprintf(stderr, "Out of memory\n");
2918 memset(bulk, 0, sizeof(*bulk));
2920 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
2926 *plen = sizeof(*bulk);
2934 /* TODO: parse more parameter */
2939 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
2940 int dist, int span, char *sgrp, char *dgrp,
2941 void *param, int plen, int *retp, struct list_head *resultp)
2943 lstio_test_args_t args = {
2944 .lstio_tes_key = session_key,
2945 .lstio_tes_bat_nmlen = strlen(batch),
2946 .lstio_tes_bat_name = batch,
2947 .lstio_tes_type = type,
2948 .lstio_tes_loop = loop,
2949 .lstio_tes_concur = concur,
2950 .lstio_tes_dist = dist,
2951 .lstio_tes_span = span,
2952 .lstio_tes_sgrp_nmlen = strlen(sgrp),
2953 .lstio_tes_sgrp_name = sgrp,
2954 .lstio_tes_dgrp_nmlen = strlen(dgrp),
2955 .lstio_tes_dgrp_name = dgrp,
2956 .lstio_tes_param_len = plen,
2957 .lstio_tes_param = param,
2958 .lstio_tes_retp = retp,
2959 .lstio_tes_resultp = resultp,
2962 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
2966 jt_lst_add_test(int argc, char **argv)
2968 struct list_head head;
2988 static struct option add_test_opts[] =
2990 {"batch", required_argument, 0, 'b' },
2991 {"concurrency", required_argument, 0, 'c' },
2992 {"distribute", required_argument, 0, 'd' },
2993 {"from", required_argument, 0, 'f' },
2994 {"to", required_argument, 0, 't' },
2995 {"loop", required_argument, 0, 'l' },
2999 if (session_key == 0) {
3001 "Can't find env LST_SESSION or value is not valid\n");
3006 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3007 add_test_opts, &optidx);
3009 /* Detect the end of the options. */
3018 concur = atoi(optarg);
3027 loop = atoi(optarg);
3033 lst_print_usage(argv[0]);
3038 if (optind == argc || from == NULL || to == NULL) {
3039 lst_print_usage(argv[0]);
3043 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3044 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3049 batch = LST_DEFAULT_BATCH;
3052 rc = lst_parse_distribute(dstr, &dist, &span);
3054 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3059 test = argv[optind++];
3064 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3066 fprintf(stderr, "Failed to add test (%s)\n", test);
3070 CFS_INIT_LIST_HEAD(&head);
3072 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3074 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3075 from, strerror(errno));
3079 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3081 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3082 to, strerror(errno));
3086 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3088 fprintf(stderr, "Out of memory\n");
3092 rc = lst_add_test_ioctl(batch, type, loop, concur,
3093 dist, span, from, to, param, plen, &ret, &head);
3096 fprintf(stdout, "Test was added successfully\n");
3098 fprintf(stdout, "Server group contains userland test "
3099 "nodes, old version of tcplnd can't accept "
3100 "connection request\n");
3107 lst_print_error("test", "Failed to add test: %s\n",
3112 lst_print_transerr(&head, "add test");
3114 lst_free_rpcent(&head);
3122 static command_t lst_cmdlist[] = {
3123 {"new_session", jt_lst_new_session, NULL,
3124 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3125 {"end_session", jt_lst_end_session, NULL,
3126 "Usage: lst end_session" },
3127 {"show_session", jt_lst_show_session, NULL,
3128 "Usage: lst show_session" },
3129 {"ping", jt_lst_ping , NULL,
3130 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3131 {"add_group", jt_lst_add_group, NULL,
3132 "Usage: lst group NAME IDs [IDs]..." },
3133 {"del_group", jt_lst_del_group, NULL,
3134 "Usage: lst del_group NAME" },
3135 {"update_group", jt_lst_update_group, NULL,
3136 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3137 {"list_group", jt_lst_list_group, NULL,
3138 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3139 {"stat", jt_lst_stat, NULL,
3140 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3141 " [--timeout #] [--delay #] GROUP [GROUP]" },
3142 {"show_error", jt_lst_show_error, NULL,
3143 "Usage: lst show_error NAME | IDS ..." },
3144 {"add_batch", jt_lst_add_batch, NULL,
3145 "Usage: lst add_batch NAME" },
3146 {"run", jt_lst_start_batch, NULL,
3147 "Usage: lst run [--timeout TIME] [NAME]" },
3148 {"stop", jt_lst_stop_batch, NULL,
3149 "Usage: lst stop [--force] BATCH_NAME" },
3150 {"list_batch", jt_lst_list_batch, NULL,
3151 "Usage: lst list_batch NAME [--test ID] [--server]" },
3152 {"query", jt_lst_query_batch, NULL,
3153 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3154 {"add_test", jt_lst_add_test, NULL,
3155 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3156 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3157 {"help", Parser_help, 0, "help" },
3162 lst_initialize(void)
3166 key = getenv("LST_SESSION");
3173 session_key = atoi(key);
3179 main(int argc, char **argv)
3183 if (lst_initialize() < 0)
3186 if (ptl_initialize(argc, argv) < 0)
3189 Parser_init("lst > ", lst_cmdlist);
3192 return Parser_execarg(argc - 1, argv + 1, lst_cmdlist);