4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lnet/selftest/conctl.c
33 * Author: Liang Zhen <liangzhen@clusterfs.com>
44 #include <sys/ioctl.h>
46 #include <linux/types.h>
48 #include <libcfs/util/list.h>
49 #include <libcfs/util/ioctl.h>
50 #include <libcfs/util/parser.h>
51 #include <linux/lnet/lnetctl.h>
52 #include <linux/lnet/lnetst.h>
53 #include <linux/lnet/nidstr.h>
54 #include "lnetconfig/liblnetconfig.h"
56 struct lst_sid LST_INVALID_SID = { .ses_nid = LNET_NID_ANY, .ses_stamp = -1 };
57 static unsigned int session_key;
59 /* All nodes running 2.6.50 or later understand feature LST_FEAT_BULK_LEN */
60 static unsigned int session_features = LST_FEATS_MASK;
61 static struct lstcon_trans_stat trans_stat;
63 typedef struct list_string {
64 struct list_string *lstr_next;
70 # define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
73 static int alloc_count = 0;
74 static int alloc_nob = 0;
79 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
82 fprintf(stderr, "Can't allocate lstr\n");
89 lstr->lstr_str[0] = 0;
95 free_lstr(lstr_t *lstr)
98 alloc_nob -= lstr->lstr_sz;
103 free_lstrs(lstr_t **list)
107 while ((lstr = *list) != NULL) {
108 *list = lstr->lstr_next;
114 new_lstrs(lstr_t **list, char *prefix, char *postfix,
115 int lo, int hi, int stride)
117 int n1 = strlen(prefix);
118 int n2 = strlen(postfix);
119 int sz = n1 + 20 + n2 + 1;
122 lstr_t *n = alloc_lstr(sz);
124 snprintf(n->lstr_str, sz - 1, "%s%u%s",
125 prefix, lo, postfix);
127 n->lstr_next = *list;
135 expand_lstr(lstr_t **list, lstr_t *l)
137 int nob = strlen(l->lstr_str);
147 b1 = strchr(l->lstr_str, '[');
149 l->lstr_next = *list;
154 b2 = strchr(b1, ']');
155 if (b2 == NULL || b2 == b1 + 1)
163 sep = strchr(expr, ',');
169 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
171 new_lstrs(list, l->lstr_str, b2, x, x, 1);
176 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
179 new_lstrs(list, l->lstr_str, b2, x, y, 1);
184 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
187 new_lstrs(list, l->lstr_str, b2, x, y, z);
193 } while ((expr = sep) != NULL);
201 expand_strs(char *str, lstr_t **head)
209 l = alloc_lstr(strlen(str) + 1);
210 memcpy(l->lstr_str, str, strlen(str) + 1);
218 while ((l = list) != NULL) {
221 rc = expand_lstr(&nlist, l);
223 fprintf(stderr, "Syntax error in \"%s\"\n", str);
231 /* re-order onto 'list' */
232 while ((l = nlist) != NULL) {
233 nlist = l->lstr_next;
238 } while (expanded && rc > 0);
245 while ((l = list) != NULL) {
254 lst_parse_nids(char *str, int *countp, struct lnet_process_id **idspp)
262 rc = expand_strs(str, &head);
272 *idspp = malloc(c * sizeof(struct lnet_process_id));
273 if (*idspp == NULL) {
274 fprintf(stderr, "Out of memory\n");
281 while ((l = head) != NULL) {
285 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
286 if ((*idspp)[i].nid == LNET_NID_ANY) {
287 fprintf(stderr, "Invalid nid: %s\n",
292 (*idspp)[i].pid = LNET_PID_LUSTRE;
309 lst_node_state2str(int state)
311 if (state == LST_NODE_ACTIVE)
313 if (state == LST_NODE_BUSY)
315 if (state == LST_NODE_DOWN)
322 lst_node_str2state(char *str)
324 if (strcasecmp(str, "active") == 0)
325 return LST_NODE_ACTIVE;
326 if (strcasecmp(str, "busy") == 0)
327 return LST_NODE_BUSY;
328 if (strcasecmp(str, "down") == 0)
329 return LST_NODE_DOWN;
330 if (strcasecmp(str, "unknown") == 0)
331 return LST_NODE_UNKNOWN;
332 if (strcasecmp(str, "invalid") == 0)
333 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
339 lst_test_type2name(int type)
341 if (type == LST_TEST_PING)
343 if (type == LST_TEST_BULK)
350 lst_test_name2type(char *name)
352 if (strcasecmp(name, "ping") == 0)
353 return LST_TEST_PING;
354 if (strcasecmp(name, "brw") == 0)
355 return LST_TEST_BULK;
361 lst_print_usage(char *cmd)
363 char *argv[] = { "help", cmd };
365 cfs_parser(2, argv, NULL);
369 lst_print_error(char *sub, const char *def_format, ...)
373 /* local error returned from kernel */
376 fprintf(stderr, "No session exists\n");
379 fprintf(stderr, "Session is shutting down\n");
382 fprintf(stderr, "Unmatched session key or not root\n");
385 fprintf(stderr, "Can't find %s in current session\n", sub);
388 fprintf(stderr, "Invalid parameters list in command line\n");
391 fprintf(stderr, "Bad parameter address\n");
394 fprintf(stderr, "%s already exists\n", sub);
397 va_start(ap, def_format);
398 vfprintf(stderr, def_format, ap);
406 lst_free_rpcent(struct list_head *head)
408 struct lstcon_rpc_ent *ent;
410 while (!list_empty(head)) {
411 ent = list_first_entry(head, struct lstcon_rpc_ent, rpe_link);
413 list_del(&ent->rpe_link);
419 lst_reset_rpcent(struct list_head *head)
421 struct lstcon_rpc_ent *ent;
423 list_for_each_entry(ent, head, rpe_link) {
424 ent->rpe_sid = LST_INVALID_SID;
425 ent->rpe_peer.nid = LNET_NID_ANY;
426 ent->rpe_peer.pid = LNET_PID_ANY;
427 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
432 lst_alloc_rpcent(struct list_head *head, int count, int offset)
434 struct lstcon_rpc_ent *ent;
437 for (i = 0; i < count; i++) {
438 ent = malloc(offsetof(struct lstcon_rpc_ent, rpe_payload[offset]));
440 lst_free_rpcent(head);
444 memset(ent, 0, offsetof(struct lstcon_rpc_ent, rpe_payload[offset]));
446 ent->rpe_sid = LST_INVALID_SID;
447 ent->rpe_peer.nid = LNET_NID_ANY;
448 ent->rpe_peer.pid = LNET_PID_ANY;
449 list_add(&ent->rpe_link, head);
456 lst_print_transerr(struct list_head *head, char *optstr)
458 struct lstcon_rpc_ent *ent;
460 list_for_each_entry(ent, head, rpe_link) {
461 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
464 if (ent->rpe_rpc_errno != 0) {
465 fprintf(stderr, "%s RPC failed on %s: %s\n",
466 optstr, libcfs_id2str(ent->rpe_peer),
467 strerror(ent->rpe_rpc_errno));
471 fprintf(stderr, "operation %s failed on %s: %s\n",
472 optstr, libcfs_id2str(ent->rpe_peer),
473 strerror(ent->rpe_fwk_errno));
477 int lst_info_batch_ioctl(char *batch, int test, int server,
478 struct lstcon_test_batch_ent *entp, int *idxp,
479 int *ndentp, struct lstcon_node_ent *dentsp);
481 int lst_info_group_ioctl(char *name, struct lstcon_ndlist_ent *gent,
482 int *idx, int *count, struct lstcon_node_ent *dents);
484 int lst_query_batch_ioctl(char *batch, int test, int server,
485 int timeout, struct list_head *head);
488 lst_ioctl(unsigned int opc, void *buf, int len)
490 struct libcfs_ioctl_data data;
493 LIBCFS_IOC_INIT (data);
494 data.ioc_u32[0] = opc;
495 data.ioc_plen1 = len;
496 data.ioc_pbuf1 = (char *)buf;
497 data.ioc_plen2 = sizeof(trans_stat);
498 data.ioc_pbuf2 = (char *)&trans_stat;
500 memset(&trans_stat, 0, sizeof(trans_stat));
502 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
504 /* local error, no valid RPC result */
509 if (trans_stat.trs_rpc_errno != 0)
512 /* Framework error */
513 if (trans_stat.trs_fwk_errno != 0)
519 int lst_yaml_session(const char *label, const char *timeout, int nlflags,
522 struct lstcon_ndlist_ent ndinfo = { };
523 struct lst_sid sid = LST_INVALID_SID;
524 /* nlflags being zero means we are destroying the session.
525 * No parsing of reply needed.
527 bool done = nlflags ? false : true;
528 char nid[LNET_NIDSTR_SIZE];
529 char name[LST_NAME_SIZE];
530 unsigned int key = 0;
531 yaml_emitter_t request;
537 sk = nl_socket_alloc();
541 /* Note: NL_AUTO_PID == zero which we use by default for the
542 * session_key when creating a new session. This is considered
543 * an invalid key so we need to get the real session key from
544 * the yaml parser yet to be created. If the user did request
545 * a specific session key then set the socket's port id to this
549 nl_socket_set_local_port(sk, session_key);
551 /* Setup reply parser to recieve Netlink packets */
552 rc = yaml_parser_initialize(&reply);
558 rc = yaml_parser_set_input_netlink(&reply, sk, false);
562 /* Create Netlink emitter to send request to kernel */
563 yaml_emitter_initialize(&request);
564 rc = yaml_emitter_set_output_netlink(&request, sk,
565 LNET_SELFTEST_GENL_NAME,
566 LNET_SELFTEST_GENL_VERSION,
567 LNET_SELFTEST_CMD_SESSIONS,
572 yaml_emitter_open(&request);
573 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
574 rc = yaml_emitter_emit(&request, &event);
578 yaml_mapping_start_event_initialize(&event, NULL,
579 (yaml_char_t *)YAML_MAP_TAG,
580 1, YAML_BLOCK_MAPPING_STYLE);
581 rc = yaml_emitter_emit(&request, &event);
585 yaml_scalar_event_initialize(&event, NULL,
586 (yaml_char_t *)YAML_STR_TAG,
587 (yaml_char_t *)"sessions",
588 strlen("sessions"), 1, 0,
589 YAML_PLAIN_SCALAR_STYLE);
590 rc = yaml_emitter_emit(&request, &event);
595 yaml_scalar_event_initialize(&event, NULL,
596 (yaml_char_t *)YAML_STR_TAG,
599 YAML_PLAIN_SCALAR_STYLE);
600 rc = yaml_emitter_emit(&request, &event);
606 /* sessions: { name: 'name', timeout: 300 }
612 yaml_mapping_start_event_initialize(&event, NULL,
613 (yaml_char_t *)YAML_MAP_TAG,
614 1, YAML_FLOW_MAPPING_STYLE);
615 rc = yaml_emitter_emit(&request, &event);
619 yaml_scalar_event_initialize(&event, NULL,
620 (yaml_char_t *)YAML_STR_TAG,
621 (yaml_char_t *)"name",
622 strlen("name"), 1, 0,
623 YAML_PLAIN_SCALAR_STYLE);
624 rc = yaml_emitter_emit(&request, &event);
628 yaml_scalar_event_initialize(&event, NULL,
629 (yaml_char_t *)YAML_STR_TAG,
630 (yaml_char_t *)label,
632 YAML_PLAIN_SCALAR_STYLE);
633 rc = yaml_emitter_emit(&request, &event);
638 yaml_scalar_event_initialize(&event, NULL,
639 (yaml_char_t *)YAML_STR_TAG,
640 (yaml_char_t *)"timeout",
641 strlen("timeout"), 1, 0,
642 YAML_PLAIN_SCALAR_STYLE);
643 rc = yaml_emitter_emit(&request, &event);
647 yaml_scalar_event_initialize(&event, NULL,
648 (yaml_char_t *)YAML_STR_TAG,
649 (yaml_char_t *)timeout,
650 strlen(timeout), 1, 0,
651 YAML_PLAIN_SCALAR_STYLE);
652 rc = yaml_emitter_emit(&request, &event);
657 yaml_mapping_end_event_initialize(&event);
658 rc = yaml_emitter_emit(&request, &event);
663 yaml_mapping_end_event_initialize(&event);
664 rc = yaml_emitter_emit(&request, &event);
668 yaml_document_end_event_initialize(&event, 0);
669 rc = yaml_emitter_emit(&request, &event);
673 rc = yaml_emitter_close(&request);
676 yaml_emitter_log_error(&request, stderr);
677 yaml_emitter_delete(&request);
681 yaml_emitter_delete(&request);
684 rc = yaml_parser_parse(&reply, &event);
688 if (event.type == YAML_SCALAR_EVENT) {
689 char *tmp, *endp = NULL;
691 if (strcmp((char *)event.data.scalar.value,
693 yaml_event_delete(&event);
694 rc = yaml_parser_parse(&reply, &event);
698 strncpy(name, (char *)event.data.scalar.value,
702 if (strcmp((char *)event.data.scalar.value,
704 yaml_event_delete(&event);
705 rc = yaml_parser_parse(&reply, &event);
709 tmp = (char *)event.data.scalar.value;
710 key = strtoul(tmp, &endp, 10);
715 if (strcmp((char *)event.data.scalar.value,
717 yaml_event_delete(&event);
718 rc = yaml_parser_parse(&reply, &event);
722 tmp = (char *)event.data.scalar.value;
723 sid.ses_stamp = strtoll(tmp, &endp, 10);
728 if (strcmp((char *)event.data.scalar.value,
730 yaml_event_delete(&event);
731 rc = yaml_parser_parse(&reply, &event);
735 strncpy(nid, (char *)event.data.scalar.value,
739 if (strcmp((char *)event.data.scalar.value,
741 yaml_event_delete(&event);
742 rc = yaml_parser_parse(&reply, &event);
746 tmp = (char *)event.data.scalar.value;
747 ndinfo.nle_nnode = strtoul(tmp, &endp, 10);
753 done = (event.type == YAML_STREAM_END_EVENT);
755 yaml_event_delete(&event);
758 if (nlflags & NLM_F_CREATE) {
759 session_features = yaml_parser_get_reader_proto_version(&reply);
763 if (rc == 0 && errmsg)
764 yaml_parser_log_error(&reply, stderr, errmsg);
765 yaml_parser_delete(&reply);
768 if (((nlflags & NLM_F_DUMP) == NLM_F_DUMP) && rc != 0) {
770 "%s ID: %ju@%s, KEY: %u FEATURES: %x NODES: %d\n",
771 name, (uintmax_t)sid.ses_stamp, nid,
772 key, session_features, ndinfo.nle_nnode);
775 return rc == 0 ? -1 : 0;
779 lst_new_session_ioctl(char *name, int timeout, int force, struct lst_sid *sid)
781 struct lstio_session_new_args args = { 0 };
783 args.lstio_ses_key = session_key;
784 args.lstio_ses_timeout = timeout;
785 args.lstio_ses_force = force;
786 args.lstio_ses_idp = sid;
787 args.lstio_ses_feats = session_features;
788 args.lstio_ses_nmlen = strlen(name);
789 args.lstio_ses_namep = name;
791 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
795 jt_lst_new_session(int argc, char **argv)
797 char buf[LST_NAME_SIZE * 2 + 1];
798 char *name, *timeout_s = NULL;
799 int nlflags = NLM_F_CREATE;
800 struct lst_sid session_id;
807 static const struct option session_opts[] = {
808 { .name = "timeout", .has_arg = required_argument, .val = 't' },
809 { .name = "force", .has_arg = no_argument, .val = 'f' },
813 c = getopt_long(argc, argv, "ft:",
814 session_opts, &optidx);
820 nlflags |= NLM_F_REPLACE;
827 lst_print_usage(argv[0]);
833 timeout = atoi(timeout_s);
835 fprintf(stderr, "Invalid timeout value\n");
840 if (optind == argc - 1) {
841 name = argv[optind ++];
842 if (strlen(name) >= LST_NAME_SIZE) {
843 fprintf(stderr, "Name size is limited to %d\n",
847 } else if (optind == argc) {
848 char user[LST_NAME_SIZE];
849 char host[LST_NAME_SIZE];
850 struct passwd *pw = getpwuid(getuid());
853 snprintf(user, sizeof(user), "%d", (int)getuid());
855 snprintf(user, sizeof(user), "%s", pw->pw_name);
857 rc = gethostname(host, sizeof(host));
859 snprintf(host, sizeof(host), "unknown_host");
861 snprintf(buf, sizeof(buf), "%s@%s", user, host);
864 lst_print_usage(argv[0]);
868 rc = lst_yaml_session(name, timeout_s, nlflags, "new session");
872 if (session_key == 0) {
874 "Can't find env LST_SESSION or value is not valid\n");
878 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
880 lst_print_error("session", "Failed to create session: %s\n",
885 fprintf(stdout, "SESSION: %s FEATURES: %x TIMEOUT: %d FORCE: %s\n",
886 name, session_features, timeout, force ? "Yes" : "No");
891 lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp,
892 struct lst_sid *sid, struct lstcon_ndlist_ent *ndinfo)
894 struct lstio_session_info_args args = { 0 };
896 args.lstio_ses_idp = sid;
897 args.lstio_ses_keyp = key;
898 args.lstio_ses_featp = featp;
899 args.lstio_ses_ndinfo = ndinfo;
900 args.lstio_ses_nmlen = len;
901 args.lstio_ses_namep = name;
903 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
907 jt_lst_show_session(int argc, char **argv)
909 struct lstcon_ndlist_ent ndinfo;
911 char name[LST_NAME_SIZE];
916 rc = lst_yaml_session(NULL, NULL, NLM_F_DUMP, "show session");
920 rc = lst_session_info_ioctl(name, sizeof(name), &key,
921 &feats, &sid, &ndinfo);
924 lst_print_error("session", "Failed to show session: %s\n",
929 fprintf(stdout, "%s ID: %ju@%s, KEY: %d FEATURES: %x NODES: %d\n",
930 name, (uintmax_t)sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
931 key, feats, ndinfo.nle_nnode);
937 lst_end_session_ioctl(void)
939 struct lstio_session_end_args args = { 0 };
941 args.lstio_ses_key = session_key;
942 return lst_ioctl(LSTIO_SESSION_END, &args, sizeof(args));
946 jt_lst_end_session(int argc, char **argv)
950 if (session_key == 0) {
952 "Can't find env LST_SESSION or value is not valid\n");
956 rc = lst_yaml_session(NULL, NULL, 0, "end session");
960 rc = lst_end_session_ioctl();
963 fprintf(stdout, "session is ended\n");
968 lst_print_error("session", "Failed to end session: %s\n",
973 if (trans_stat.trs_rpc_errno != 0) {
975 "[RPC] Failed to send %d session RPCs: %s\n",
976 lstcon_rpc_stat_failure(&trans_stat, 0),
977 strerror(trans_stat.trs_rpc_errno));
980 if (trans_stat.trs_fwk_errno != 0) {
982 "[FWK] Failed to end session on %d nodes: %s\n",
983 lstcon_sesop_stat_failure(&trans_stat, 0),
984 strerror(trans_stat.trs_fwk_errno));
990 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
992 static int lst_yaml_display_groups(yaml_parser_t *reply, char *group,
993 int states, bool print)
999 char name[LST_NAME_SIZE] = {};
1004 fprintf(stdout, LST_NODES_TITLE);
1007 rc = yaml_parser_parse(reply, &event);
1011 if (event.type == YAML_MAPPING_START_EVENT) {
1015 rc = yaml_parser_parse(reply, &next);
1019 if (next.type != YAML_SCALAR_EVENT) {
1020 yaml_event_delete(&next);
1024 value = (char *)next.data.scalar.value;
1025 if (strcmp(value, "groups") == 0) {
1026 yaml_event_delete(&next);
1027 } else if (strcmp(value, "nid") == 0) {
1031 rc = yaml_parser_parse(reply, &next);
1035 fprintf(stdout, "\t%s: ",
1036 (char *)next.data.scalar.value);
1038 rc = yaml_parser_parse(reply, &next);
1042 tmp = (char *)next.data.scalar.value;
1043 if (strcmp(tmp, "status") == 0) {
1046 rc = yaml_parser_parse(reply, &state);
1050 fprintf(stdout, "%s\n",
1051 (char *)state.data.scalar.value);
1057 rc = yaml_parser_parse(reply, &next);
1061 strncpy(name, value, sizeof(name) - 1);
1062 fprintf(stdout, "Group [ %s ]\n", name);
1065 if (next.type != YAML_SEQUENCE_START_EVENT) {
1067 "No nodes found [ %s ]\n",
1071 } else if (event.type == YAML_SEQUENCE_END_EVENT &&
1073 fprintf(stdout, "Total %d nodes [ %s ]\n",
1078 done = (event.type == YAML_STREAM_END_EVENT);
1079 yaml_event_delete(&event);
1082 int active = 0, busy = 0, down = 0, unknown = 0;
1083 char group[LST_NAME_SIZE];
1087 rc = yaml_parser_parse(reply, &event);
1091 if (event.type == YAML_SCALAR_EVENT) {
1092 char *value = (char *)event.data.scalar.value;
1095 value = (char *)event.data.scalar.value;
1096 if (strcmp(value, "groups") == 0) {
1097 yaml_event_delete(&event);
1101 rc = yaml_parser_parse(reply, &next);
1105 if (next.type == YAML_SCALAR_EVENT) {
1108 status = lst_node_str2state((char *)next.data.scalar.value);
1110 case LST_NODE_ACTIVE:
1119 case LST_NODE_UNKNOWN:
1124 } else if (next.type == YAML_SEQUENCE_START_EVENT) {
1125 strncpy(group, value, sizeof(group) - 1);
1131 yaml_event_delete(&next);
1132 } else if (event.type == YAML_SEQUENCE_END_EVENT) {
1133 if (strlen(group)) {
1134 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1135 active, busy, down, unknown,
1136 active + busy + down + unknown, group);
1138 memset(group, 0, sizeof(group));
1140 done = (event.type == YAML_STREAM_END_EVENT);
1141 yaml_event_delete(&event);
1148 rc = yaml_parser_parse(reply, &event);
1152 if (event.type == YAML_SCALAR_EVENT) {
1155 value = (char *)event.data.scalar.value;
1156 if (strlen(value) &&
1157 strcmp(value, "groups") != 0) {
1159 fprintf(stdout, "%d) %s\n",
1164 done = (event.type == YAML_STREAM_END_EVENT);
1166 yaml_event_delete(&event);
1169 fprintf(stdout, "Total %d groups\n", i - 1);
1177 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1179 static int lst_yaml_groups(int nlflags, char *name, int states, bool print)
1181 yaml_emitter_t request;
1182 yaml_parser_t reply;
1187 sk = nl_socket_alloc();
1191 /* Setup reply parser to recieve Netlink packets */
1192 rc = yaml_parser_initialize(&reply);
1198 rc = yaml_parser_set_input_netlink(&reply, sk, false);
1202 /* Create Netlink emitter to send request to kernel */
1203 yaml_emitter_initialize(&request);
1204 rc = yaml_emitter_set_output_netlink(&request, sk,
1205 LNET_SELFTEST_GENL_NAME,
1206 LNET_SELFTEST_GENL_VERSION,
1207 LNET_SELFTEST_CMD_GROUPS,
1212 yaml_emitter_open(&request);
1213 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
1214 rc = yaml_emitter_emit(&request, &event);
1218 yaml_mapping_start_event_initialize(&event, NULL,
1219 (yaml_char_t *)YAML_MAP_TAG,
1220 1, YAML_BLOCK_MAPPING_STYLE);
1221 rc = yaml_emitter_emit(&request, &event);
1225 yaml_scalar_event_initialize(&event, NULL,
1226 (yaml_char_t *)YAML_STR_TAG,
1227 (yaml_char_t *)"groups",
1228 strlen("groups"), 1, 0,
1229 YAML_PLAIN_SCALAR_STYLE);
1230 rc = yaml_emitter_emit(&request, &event);
1235 yaml_sequence_start_event_initialize(&event, NULL,
1236 (yaml_char_t *)YAML_SEQ_TAG,
1237 1, YAML_BLOCK_SEQUENCE_STYLE);
1238 rc = yaml_emitter_emit(&request, &event);
1242 yaml_mapping_start_event_initialize(&event, NULL,
1243 (yaml_char_t *)YAML_MAP_TAG,
1244 1, YAML_BLOCK_MAPPING_STYLE);
1245 rc = yaml_emitter_emit(&request, &event);
1249 yaml_scalar_event_initialize(&event, NULL,
1250 (yaml_char_t *)YAML_STR_TAG,
1251 (yaml_char_t *)name,
1253 YAML_PLAIN_SCALAR_STYLE);
1254 rc = yaml_emitter_emit(&request, &event);
1259 int max = ffs(LST_NODE_UNKNOWN) + 1, i;
1262 yaml_sequence_start_event_initialize(&event, NULL,
1263 (yaml_char_t *)YAML_SEQ_TAG,
1264 1, YAML_BLOCK_SEQUENCE_STYLE);
1265 rc = yaml_emitter_emit(&request, &event);
1270 for (i = 0; i < max; i++) {
1271 int mask = states & (1 << i);
1273 state = lst_node_state2str(mask);
1274 if (mask != LST_NODE_UNKNOWN && strcmp(state, "Unknown") == 0)
1277 yaml_mapping_start_event_initialize(&event, NULL,
1278 (yaml_char_t *)YAML_MAP_TAG,
1279 1, YAML_BLOCK_MAPPING_STYLE);
1280 rc = yaml_emitter_emit(&request, &event);
1284 yaml_scalar_event_initialize(&event, NULL,
1285 (yaml_char_t *)YAML_STR_TAG,
1286 (yaml_char_t *)"status",
1287 strlen("status"), 1, 0,
1288 YAML_PLAIN_SCALAR_STYLE);
1289 rc = yaml_emitter_emit(&request, &event);
1293 yaml_scalar_event_initialize(&event, NULL,
1294 (yaml_char_t *)YAML_STR_TAG,
1295 (yaml_char_t *)state,
1296 strlen(state), 1, 0,
1297 YAML_PLAIN_SCALAR_STYLE);
1298 rc = yaml_emitter_emit(&request, &event);
1302 yaml_mapping_end_event_initialize(&event);
1303 rc = yaml_emitter_emit(&request, &event);
1308 yaml_sequence_end_event_initialize(&event);
1309 rc = yaml_emitter_emit(&request, &event);
1313 yaml_scalar_event_initialize(&event, NULL,
1314 (yaml_char_t *)YAML_STR_TAG,
1317 YAML_PLAIN_SCALAR_STYLE);
1318 rc = yaml_emitter_emit(&request, &event);
1323 yaml_mapping_end_event_initialize(&event);
1324 rc = yaml_emitter_emit(&request, &event);
1328 yaml_sequence_end_event_initialize(&event);
1329 rc = yaml_emitter_emit(&request, &event);
1333 yaml_scalar_event_initialize(&event, NULL,
1334 (yaml_char_t *)YAML_STR_TAG,
1337 YAML_PLAIN_SCALAR_STYLE);
1338 rc = yaml_emitter_emit(&request, &event);
1342 yaml_mapping_end_event_initialize(&event);
1343 rc = yaml_emitter_emit(&request, &event);
1347 yaml_document_end_event_initialize(&event, 0);
1348 rc = yaml_emitter_emit(&request, &event);
1352 rc = yaml_emitter_close(&request);
1355 yaml_emitter_log_error(&request, stderr);
1356 yaml_emitter_delete(&request);
1360 yaml_emitter_delete(&request);
1362 /* display output */
1363 if (nlflags == NLM_F_DUMP)
1364 rc = lst_yaml_display_groups(&reply, name, states, print);
1367 yaml_parser_log_error(&reply, stderr, NULL);
1368 yaml_parser_delete(&reply);
1372 rc = rc == 1 ? 0 : -EINVAL;
1378 lst_ping_ioctl(char *str, int type, int timeout,
1379 int count, struct lnet_process_id *ids, struct list_head *head)
1381 struct lstio_debug_args args = { 0 };
1383 args.lstio_dbg_key = session_key;
1384 args.lstio_dbg_type = type;
1385 args.lstio_dbg_flags = 0;
1386 args.lstio_dbg_timeout = timeout;
1387 args.lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str);
1388 args.lstio_dbg_namep = str;
1389 args.lstio_dbg_count = count;
1390 args.lstio_dbg_idsp = ids;
1391 args.lstio_dbg_resultp = head;
1393 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
1397 lst_get_node_count(int type, char *str, int *countp,
1398 struct lnet_process_id **idspp)
1400 char buf[LST_NAME_SIZE];
1401 struct lstcon_test_batch_ent ent;
1402 struct lstcon_ndlist_ent *entp = &ent.tbe_cli_nle;
1409 case LST_OPC_SESSION:
1410 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
1411 &key, &feats, &sid, entp);
1414 case LST_OPC_BATCHSRV:
1415 entp = &ent.tbe_srv_nle;
1416 case LST_OPC_BATCHCLI:
1417 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
1421 rc = lst_yaml_groups(NLM_F_DUMP, NULL, 0, false);
1422 if (rc == -EOPNOTSUPP) {
1423 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
1424 } else if (rc > 0) {
1425 entp->nle_nnode = rc;
1431 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
1440 *countp = entp->nle_nnode;
1446 jt_lst_ping(int argc, char **argv)
1448 struct list_head head;
1449 struct lnet_process_id *ids = NULL;
1450 struct lstcon_rpc_ent *ent = NULL;
1460 static const struct option ping_opts[] = {
1461 { .name = "session", .has_arg = no_argument, .val = 's' },
1462 { .name = "server", .has_arg = no_argument, .val = 'v' },
1463 { .name = "batch", .has_arg = required_argument, .val = 'b' },
1464 { .name = "group", .has_arg = required_argument, .val = 'g' },
1465 { .name = "nodes", .has_arg = required_argument, .val = 'n' },
1466 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1467 { .name = NULL, } };
1469 if (session_key == 0) {
1471 "Can't find env LST_SESSION or value is not valid\n");
1477 c = getopt_long(argc, argv, "g:b:n:t:sv",
1478 ping_opts, &optidx);
1485 type = LST_OPC_SESSION;
1489 type = LST_OPC_GROUP;
1494 type = LST_OPC_BATCHCLI;
1499 type = LST_OPC_NODES;
1504 timeout = atoi(optarg);
1512 lst_print_usage(argv[0]);
1517 if (type == 0 || timeout <= 0 || optind != argc) {
1518 lst_print_usage(argv[0]);
1522 if (type == LST_OPC_BATCHCLI && server)
1523 type = LST_OPC_BATCHSRV;
1525 rc = lst_get_node_count(type, str, &count, &ids);
1527 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
1528 (str == NULL) ? "session" : str, strerror(errno));
1532 INIT_LIST_HEAD(&head);
1534 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
1536 fprintf(stderr, "Out of memory\n");
1541 fprintf(stdout, "Target %s is empty\n",
1542 (str == NULL) ? "session" : str);
1546 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
1547 if (rc == -1) { /* local failure */
1548 lst_print_error("debug", "Failed to ping %s: %s\n",
1549 (str == NULL) ? "session" : str,
1555 /* ignore RPC errors and framwork errors */
1556 list_for_each_entry(ent, &head, rpe_link) {
1557 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
1558 libcfs_id2str(ent->rpe_peer),
1559 lst_node_state2str(ent->rpe_state),
1560 (ent->rpe_state == LST_NODE_ACTIVE ||
1561 ent->rpe_state == LST_NODE_BUSY) ?
1562 (ent->rpe_rpc_errno == 0 ?
1563 &ent->rpe_payload[0] : "Unknown") :
1564 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
1568 lst_free_rpcent(&head);
1578 lst_add_nodes_ioctl(char *name, int count, struct lnet_process_id *ids,
1579 unsigned *featp, struct list_head *resultp)
1581 struct lstio_group_nodes_args args = { 0 };
1583 args.lstio_grp_key = session_key;
1584 args.lstio_grp_nmlen = strlen(name);
1585 args.lstio_grp_namep = name;
1586 args.lstio_grp_count = count;
1587 args.lstio_grp_featp = featp;
1588 args.lstio_grp_idsp = ids;
1589 args.lstio_grp_resultp = resultp;
1591 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
1595 lst_del_group_ioctl(char *name)
1597 struct lstio_group_del_args args = { 0 };
1599 args.lstio_grp_key = session_key;
1600 args.lstio_grp_nmlen = strlen(name);
1601 args.lstio_grp_namep = name;
1603 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
1607 lst_del_group(char *grp_name)
1611 rc = lst_del_group_ioctl(grp_name);
1613 fprintf(stdout, "Group is deleted\n");
1618 lst_print_error("group", "Failed to delete group: %s\n",
1623 fprintf(stderr, "Group is deleted with some errors\n");
1625 if (trans_stat.trs_rpc_errno != 0) {
1627 "[RPC] Failed to send %d end session RPCs: %s\n",
1628 lstcon_rpc_stat_failure(&trans_stat, 0),
1629 strerror(trans_stat.trs_rpc_errno));
1632 if (trans_stat.trs_fwk_errno != 0) {
1634 "[FWK] Failed to end session on %d nodes: %s\n",
1635 lstcon_sesop_stat_failure(&trans_stat, 0),
1636 strerror(trans_stat.trs_fwk_errno));
1643 lst_add_group_ioctl(char *name)
1645 struct lstio_group_add_args args = { 0 };
1647 args.lstio_grp_key = session_key;
1648 args.lstio_grp_nmlen = strlen(name);
1649 args.lstio_grp_namep = name;
1651 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
1655 jt_lst_add_group(int argc, char **argv)
1657 struct list_head head;
1658 struct lnet_process_id *ids;
1660 unsigned feats = session_features;
1664 bool nodes_added = false;
1666 if (session_key == 0) {
1668 "Can't find env LST_SESSION or value is not valid\n");
1673 lst_print_usage(argv[0]);
1678 if (strlen(name) >= LST_NAME_SIZE) {
1679 fprintf(stderr, "Name length is limited to %d\n",
1684 rc = lst_add_group_ioctl(name);
1686 lst_print_error("group", "Failed to add group %s: %s\n",
1687 name, strerror(errno));
1691 INIT_LIST_HEAD(&head);
1693 for (i = 2; i < argc; i++) {
1694 /* parse address list */
1695 rc = lst_parse_nids(argv[i], &count, &ids);
1697 fprintf(stderr, "Ignore invalid id list %s\n",
1705 rc = lst_alloc_rpcent(&head, count, 0);
1707 fprintf(stderr, "Out of memory\n");
1713 rc = lst_add_nodes_ioctl(name, count, ids, &feats, &head);
1720 fprintf(stdout, "%s are added to session\n", argv[i]);
1724 if ((feats & session_features) != session_features) {
1726 "Warning, this session will run with "
1727 "compatible mode because some test nodes "
1728 "might not understand these features: %x\n",
1729 (~feats & session_features));
1732 lst_free_rpcent(&head);
1737 * The selftest kernel module expects that a group should
1738 * have at least one node, since it doesn't make sense for
1739 * an empty group to be added to a test.
1742 "No nodes added successfully, deleting group %s\n",
1744 rc = lst_del_group(name);
1747 "Failed to delete group %s."
1748 " Group is empty.\n", name);
1756 lst_print_error("group", "Failed to add nodes %s: %s\n",
1757 argv[i], strerror(errno));
1760 if (trans_stat.trs_fwk_errno == EPROTO) {
1762 "test nodes might have different LST "
1763 "features, please disable some features by "
1764 "setting LST_FEATURES\n");
1767 lst_print_transerr(&head, "create session");
1770 lst_free_rpcent(&head);
1774 "No nodes added successfully, deleting group %s\n",
1776 if (lst_del_group(name) != 0) {
1778 "Failed to delete group %s."
1779 " Group is empty.\n", name);
1787 jt_lst_del_group(int argc, char **argv)
1791 if (session_key == 0) {
1793 "Can't find env LST_SESSION or value is not valid\n");
1798 lst_print_usage(argv[0]);
1802 rc = lst_del_group(argv[1]);
1808 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1809 struct lnet_process_id *ids, struct list_head *resultp)
1811 struct lstio_group_update_args args = { 0 };
1813 args.lstio_grp_key = session_key;
1814 args.lstio_grp_opc = opc;
1815 args.lstio_grp_args = clean;
1816 args.lstio_grp_nmlen = strlen(name);
1817 args.lstio_grp_namep = name;
1818 args.lstio_grp_count = count;
1819 args.lstio_grp_idsp = ids;
1820 args.lstio_grp_resultp = resultp;
1822 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1826 jt_lst_update_group(int argc, char **argv)
1828 struct list_head head;
1829 struct lnet_process_id *ids = NULL;
1839 static const struct option update_group_opts[] = {
1840 { .name = "refresh", .has_arg = no_argument, .val = 'f' },
1841 { .name = "clean", .has_arg = required_argument, .val = 'c' },
1842 { .name = "remove", .has_arg = required_argument, .val = 'r' },
1845 if (session_key == 0) {
1847 "Can't find env LST_SESSION or value is not valid\n");
1852 c = getopt_long(argc, argv, "fc:r:",
1853 update_group_opts, &optidx);
1855 /* Detect the end of the options. */
1862 lst_print_usage(argv[0]);
1865 opc = LST_GROUP_REFRESH;
1870 lst_print_usage(argv[0]);
1873 opc = LST_GROUP_RMND;
1878 clean = lst_node_str2state(optarg);
1879 if (opc != 0 || clean <= 0) {
1880 lst_print_usage(argv[0]);
1883 opc = LST_GROUP_CLEAN;
1887 lst_print_usage(argv[0]);
1892 /* no OPC or group is specified */
1893 if (opc == 0 || optind != argc - 1) {
1894 lst_print_usage(argv[0]);
1900 INIT_LIST_HEAD(&head);
1902 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1903 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1905 opc == LST_GROUP_RMND ? str : grp,
1909 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1910 opc == LST_GROUP_RMND ? str : grp,
1915 rc = lst_alloc_rpcent(&head, count, 0);
1917 fprintf(stderr, "Out of memory\n");
1924 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1930 lst_free_rpcent(&head);
1935 lst_free_rpcent(&head);
1936 lst_print_error("group", "Failed to update group: %s\n",
1941 lst_print_transerr(&head, "Updating group");
1943 lst_free_rpcent(&head);
1949 lst_list_group_ioctl(int len, char *name, int idx)
1951 struct lstio_group_list_args args = { 0 };
1953 args.lstio_grp_key = session_key;
1954 args.lstio_grp_idx = idx;
1955 args.lstio_grp_nmlen = len;
1956 args.lstio_grp_namep = name;
1958 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1962 lst_info_group_ioctl(char *name, struct lstcon_ndlist_ent *gent,
1963 int *idx, int *count, struct lstcon_node_ent *dents)
1965 struct lstio_group_info_args args = { 0 };
1967 args.lstio_grp_key = session_key;
1968 args.lstio_grp_nmlen = strlen(name);
1969 args.lstio_grp_namep = name;
1970 args.lstio_grp_entp = gent;
1971 args.lstio_grp_idxp = idx;
1972 args.lstio_grp_ndentp = count;
1973 args.lstio_grp_dentsp = dents;
1975 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1979 lst_list_group_all(void)
1981 char name[LST_NAME_SIZE];
1985 /* no group is specified, list name of all groups */
1986 for (i = 0; ; i++) {
1987 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1989 fprintf(stdout, "%d) %s\n", i + 1, name);
1993 if (errno == ENOENT)
1996 lst_print_error("group", "Failed to list group: %s\n",
2001 fprintf(stdout, "Total %d groups\n", i);
2007 jt_lst_list_group(int argc, char **argv)
2009 struct lstcon_ndlist_ent gent;
2010 struct lstcon_node_ent *dents;
2025 static const struct option list_group_opts[] = {
2026 { .name = "active", .has_arg = no_argument, .val = 'a' },
2027 { .name = "busy", .has_arg = no_argument, .val = 'b' },
2028 { .name = "down", .has_arg = no_argument, .val = 'd' },
2029 { .name = "unknown", .has_arg = no_argument, .val = 'u' },
2030 { .name = "all", .has_arg = no_argument, .val = 'l' },
2031 { .name = NULL, } };
2033 if (session_key == 0) {
2035 "Can't find env LST_SESSION or value is not valid\n");
2040 c = getopt_long(argc, argv, "abdul",
2041 list_group_opts, &optidx);
2048 verbose = active = 1;
2049 states |= LST_NODE_ACTIVE;
2054 states |= LST_NODE_BUSY;
2059 states |= LST_NODE_DOWN;
2063 verbose = unknown = 1;
2064 states |= LST_NODE_UNKNOWN;
2068 states |= LST_NODE_ACTIVE | LST_NODE_BUSY |
2069 LST_NODE_DOWN | LST_NODE_UNKNOWN;
2073 lst_print_usage(argv[0]);
2078 if (optind == argc) {
2079 rc = lst_yaml_groups(NLM_F_DUMP, NULL, 0, true);
2081 if (rc == -EOPNOTSUPP)
2086 for (i = optind; i < argc; i++) {
2087 rc = lst_yaml_groups(NLM_F_DUMP, argv[i], states,
2088 i == optind ? true : false);
2090 if (rc == -EOPNOTSUPP)
2098 if (optind == argc) {
2099 /* no group is specified, list name of all groups */
2100 rc = lst_list_group_all();
2106 fprintf(stdout, LST_NODES_TITLE);
2108 /* list nodes in specified groups */
2109 for (i = optind; i < argc; i++) {
2110 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
2112 if (errno == ENOENT) {
2117 lst_print_error("group", "Failed to list group\n",
2123 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
2124 gent.nle_nactive, gent.nle_nbusy,
2125 gent.nle_ndown, gent.nle_nunknown,
2126 gent.nle_nnode, argv[i]);
2130 fprintf(stdout, "Group [ %s ]\n", argv[i]);
2132 if (gent.nle_nnode == 0) {
2133 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
2137 count = gent.nle_nnode;
2139 dents = malloc(count * sizeof(struct lstcon_node_ent));
2140 if (dents == NULL) {
2141 fprintf(stderr, "Failed to malloc: %s\n",
2147 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
2149 lst_print_error("group", "Failed to list group: %s\n",
2155 for (j = 0, c = 0; j < count; j++) {
2157 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
2158 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
2159 (down && dents[j].nde_state == LST_NODE_DOWN) ||
2160 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
2162 fprintf(stdout, "\t%s: %s\n",
2163 libcfs_id2str(dents[j].nde_id),
2164 lst_node_state2str(dents[j].nde_state));
2169 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
2178 lst_stat_ioctl(char *name, int count, struct lnet_process_id *idsp,
2179 int timeout, struct list_head *resultp)
2181 struct lstio_stat_args args = { 0 };
2183 args.lstio_sta_key = session_key;
2184 args.lstio_sta_timeout = timeout;
2185 args.lstio_sta_nmlen = strlen(name);
2186 args.lstio_sta_namep = name;
2187 args.lstio_sta_count = count;
2188 args.lstio_sta_idsp = idsp;
2189 args.lstio_sta_resultp = resultp;
2191 return lst_ioctl(LSTIO_STAT_QUERY, &args, sizeof(args));
2195 struct list_head srp_link;
2198 struct lnet_process_id *srp_ids;
2199 struct list_head srp_result[2];
2200 } lst_stat_req_param_t;
2203 lst_stat_req_param_free(lst_stat_req_param_t *srp)
2207 for (i = 0; i < 2; i++)
2208 lst_free_rpcent(&srp->srp_result[i]);
2210 if (srp->srp_ids != NULL)
2217 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
2219 lst_stat_req_param_t *srp = NULL;
2220 int count = save_old ? 2 : 1;
2224 srp = malloc(sizeof(*srp));
2228 memset(srp, 0, sizeof(*srp));
2229 INIT_LIST_HEAD(&srp->srp_result[0]);
2230 INIT_LIST_HEAD(&srp->srp_result[1]);
2232 rc = lst_get_node_count(LST_OPC_GROUP, name,
2233 &srp->srp_count, NULL);
2234 if (rc != 0 && errno == ENOENT) {
2235 rc = lst_get_node_count(LST_OPC_NODES, name,
2236 &srp->srp_count, &srp->srp_ids);
2241 "Failed to get count of nodes from %s: %s\n",
2242 name, strerror(errno));
2243 lst_stat_req_param_free(srp);
2248 srp->srp_name = name;
2250 for (i = 0; i < count; i++) {
2251 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
2252 sizeof(struct sfw_counters) +
2253 sizeof(struct srpc_counters) +
2254 sizeof(struct lnet_counters_common));
2256 fprintf(stderr, "Out of memory\n");
2266 lst_stat_req_param_free(srp);
2274 } lst_srpc_stat_result;
2276 #define LST_LNET_AVG 0
2277 #define LST_LNET_MIN 1
2278 #define LST_LNET_MAX 2
2281 float lnet_avg_sndrate;
2282 float lnet_min_sndrate;
2283 float lnet_max_sndrate;
2284 float lnet_total_sndrate;
2286 float lnet_avg_rcvrate;
2287 float lnet_min_rcvrate;
2288 float lnet_max_rcvrate;
2289 float lnet_total_rcvrate;
2291 float lnet_avg_sndperf;
2292 float lnet_min_sndperf;
2293 float lnet_max_sndperf;
2294 float lnet_total_sndperf;
2296 float lnet_avg_rcvperf;
2297 float lnet_min_rcvperf;
2298 float lnet_max_rcvperf;
2299 float lnet_total_rcvperf;
2301 int lnet_stat_count;
2302 } lst_lnet_stat_result_t;
2304 lst_lnet_stat_result_t lnet_stat_result;
2307 lst_lnet_stat_value(int bw, int send, int off)
2311 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
2312 &lnet_stat_result.lnet_avg_sndrate;
2323 lst_cal_lnet_stat(float delta, struct lnet_counters_common *lnet_new,
2324 struct lnet_counters_common *lnet_old, int mbs)
2328 unsigned int unit_divisor;
2330 unit_divisor = (mbs) ? (1000 * 1000) : (1024 * 1024);
2331 perf = (float)(lnet_new->lcc_send_length -
2332 lnet_old->lcc_send_length) / unit_divisor / delta;
2333 lnet_stat_result.lnet_total_sndperf += perf;
2335 if (lnet_stat_result.lnet_min_sndperf > perf ||
2336 lnet_stat_result.lnet_min_sndperf == 0)
2337 lnet_stat_result.lnet_min_sndperf = perf;
2339 if (lnet_stat_result.lnet_max_sndperf < perf)
2340 lnet_stat_result.lnet_max_sndperf = perf;
2342 perf = (float)(lnet_new->lcc_recv_length -
2343 lnet_old->lcc_recv_length) / unit_divisor / delta;
2344 lnet_stat_result.lnet_total_rcvperf += perf;
2346 if (lnet_stat_result.lnet_min_rcvperf > perf ||
2347 lnet_stat_result.lnet_min_rcvperf == 0)
2348 lnet_stat_result.lnet_min_rcvperf = perf;
2350 if (lnet_stat_result.lnet_max_rcvperf < perf)
2351 lnet_stat_result.lnet_max_rcvperf = perf;
2353 rate = (lnet_new->lcc_send_count - lnet_old->lcc_send_count) / delta;
2354 lnet_stat_result.lnet_total_sndrate += rate;
2356 if (lnet_stat_result.lnet_min_sndrate > rate ||
2357 lnet_stat_result.lnet_min_sndrate == 0)
2358 lnet_stat_result.lnet_min_sndrate = rate;
2360 if (lnet_stat_result.lnet_max_sndrate < rate)
2361 lnet_stat_result.lnet_max_sndrate = rate;
2363 rate = (lnet_new->lcc_recv_count - lnet_old->lcc_recv_count) / delta;
2364 lnet_stat_result.lnet_total_rcvrate += rate;
2366 if (lnet_stat_result.lnet_min_rcvrate > rate ||
2367 lnet_stat_result.lnet_min_rcvrate == 0)
2368 lnet_stat_result.lnet_min_rcvrate = rate;
2370 if (lnet_stat_result.lnet_max_rcvrate < rate)
2371 lnet_stat_result.lnet_max_rcvrate = rate;
2373 lnet_stat_result.lnet_stat_count++;
2375 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
2376 lnet_stat_result.lnet_stat_count;
2377 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
2378 lnet_stat_result.lnet_stat_count;
2380 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
2381 lnet_stat_result.lnet_stat_count;
2382 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
2383 lnet_stat_result.lnet_stat_count;
2387 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type, int mbs)
2397 if (lnet_stat_result.lnet_stat_count == 0)
2400 units = (mbs) ? "MB/s " : "MiB/s ";
2402 if (bwrt == 1) /* bw only */
2405 if (bwrt == 2) /* rates only */
2408 if (rdwr == 1) /* recv only */
2411 if (rdwr == 2) /* send only */
2414 for (i = start1; i <= end1; i++) {
2415 fprintf(stdout, "[LNet %s of %s]\n",
2416 i == 0 ? "Rates" : "Bandwidth", name);
2418 for (j = start2; j <= end2; j++) {
2419 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
2421 if ((type & 1) != 0) {
2422 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
2424 lst_lnet_stat_value(i, j, 0), units);
2427 if ((type & 2) != 0) {
2428 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
2430 lst_lnet_stat_value(i, j, 1), units);
2433 if ((type & 4) != 0) {
2434 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
2436 lst_lnet_stat_value(i, j, 2), units);
2439 fprintf(stdout, "\n");
2445 lst_print_stat(char *name, struct list_head *resultp,
2446 int idx, int lnet, int bwrt, int rdwr, int type,
2449 struct list_head tmp[2];
2450 struct lstcon_rpc_ent *new;
2451 struct lstcon_rpc_ent *old;
2452 struct sfw_counters *sfwk_new;
2453 struct sfw_counters *sfwk_old;
2454 struct srpc_counters *srpc_new;
2455 struct srpc_counters *srpc_old;
2456 struct lnet_counters_common *lnet_new;
2457 struct lnet_counters_common *lnet_old;
2461 INIT_LIST_HEAD(&tmp[0]);
2462 INIT_LIST_HEAD(&tmp[1]);
2464 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
2466 while (!list_empty(&resultp[idx])) {
2467 if (list_empty(&resultp[1 - idx])) {
2468 fprintf(stderr, "Group is changed, re-run stat\n");
2472 new = list_first_entry(&resultp[idx], struct lstcon_rpc_ent,
2474 old = list_first_entry(&resultp[1 - idx], struct lstcon_rpc_ent,
2477 /* first time get stats result, can't calculate diff */
2478 if (new->rpe_peer.nid == LNET_NID_ANY)
2481 if (new->rpe_peer.nid != old->rpe_peer.nid ||
2482 new->rpe_peer.pid != old->rpe_peer.pid) {
2483 /* Something wrong. i.e, somebody change the group */
2487 list_move_tail(&new->rpe_link, &tmp[idx]);
2489 list_move_tail(&old->rpe_link, &tmp[1 - idx]);
2491 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
2492 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
2497 sfwk_new = (struct sfw_counters *)&new->rpe_payload[0];
2498 sfwk_old = (struct sfw_counters *)&old->rpe_payload[0];
2500 srpc_new = (struct srpc_counters *)((char *)sfwk_new +
2502 srpc_old = (struct srpc_counters *)((char *)sfwk_old +
2505 lnet_new = (struct lnet_counters_common *)((char *)srpc_new +
2507 lnet_old = (struct lnet_counters_common *)((char *)srpc_old +
2510 /* Prior to version 2.3, the running_ms was a counter for
2511 * the number of running tests. Since 2.3, running_ms is
2512 * changed to hold the millisecond since the start of
2513 * the work item. The rpe_stamp field was formerly used,
2514 * but is no longer. In 2.12 rpe_stamp was changed to
2515 * struct timespec64 and has nanosecond resolution, in
2516 * case it is needed in the future.
2518 delta = (float)(sfwk_new->running_ms -
2519 sfwk_old->running_ms) / 1000;
2521 if (!lnet) /* TODO */
2524 lst_cal_lnet_stat(delta, lnet_new, lnet_old, mbs);
2527 list_splice(&tmp[idx], &resultp[idx]);
2528 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
2531 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
2533 if (!lnet) /* TODO */
2536 lst_print_lnet_stat(name, bwrt, rdwr, type, mbs);
2540 jt_lst_stat(int argc, char **argv)
2542 struct list_head head;
2543 lst_stat_req_param_t *srp;
2546 int timeout = 5; /* default timeout, 5 sec */
2547 int delay = 5; /* default delay, 5 sec */
2548 int count = -1; /* run forever */
2549 int lnet = 1; /* lnet stat by default */
2556 int mbs = 0; /* report as MB/s */
2558 static const struct option stat_opts[] = {
2559 { .name = "timeout", .has_arg = required_argument, .val = 't' },
2560 { .name = "delay", .has_arg = required_argument, .val = 'd' },
2561 { .name = "count", .has_arg = required_argument, .val = 'o' },
2562 { .name = "lnet", .has_arg = no_argument, .val = 'l' },
2563 { .name = "rpc", .has_arg = no_argument, .val = 'c' },
2564 { .name = "bw", .has_arg = no_argument, .val = 'b' },
2565 { .name = "rate", .has_arg = no_argument, .val = 'a' },
2566 { .name = "read", .has_arg = no_argument, .val = 'r' },
2567 { .name = "write", .has_arg = no_argument, .val = 'w' },
2568 { .name = "avg", .has_arg = no_argument, .val = 'g' },
2569 { .name = "min", .has_arg = no_argument, .val = 'n' },
2570 { .name = "max", .has_arg = no_argument, .val = 'x' },
2571 { .name = "mbs", .has_arg = no_argument, .val = 'm' },
2574 if (session_key == 0) {
2576 "Can't find env LST_SESSION or value is not valid\n");
2581 c = getopt_long(argc, argv, "t:d:lcbarwgnxm", stat_opts,
2589 timeout = atoi(optarg);
2592 delay = atoi(optarg);
2595 count = atoi(optarg);
2641 lst_print_usage(argv[0]);
2646 if (optind == argc) {
2647 lst_print_usage(argv[0]);
2651 if (timeout <= 0 || delay <= 0) {
2652 fprintf(stderr, "Invalid timeout or delay value\n");
2657 fprintf(stderr, "Invalid count value\n");
2661 /* extra count to get first data point */
2665 INIT_LIST_HEAD(&head);
2667 while (optind < argc) {
2668 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
2672 list_add_tail(&srp->srp_link, &head);
2676 time_t now = time(NULL);
2678 if (now - last < delay) {
2679 sleep(delay - now + last);
2684 list_for_each_entry(srp, &head, srp_link) {
2685 rc = lst_stat_ioctl(srp->srp_name,
2686 srp->srp_count, srp->srp_ids,
2687 timeout, &srp->srp_result[idx]);
2689 lst_print_error("stat", "Failed to stat %s: %s\n",
2690 srp->srp_name, strerror(errno));
2694 lst_print_stat(srp->srp_name, srp->srp_result,
2695 idx, lnet, bwrt, rdwr, type, mbs);
2697 lst_reset_rpcent(&srp->srp_result[1 - idx]);
2704 } while (count == -1 || count > 0);
2707 while (!list_empty(&head)) {
2708 srp = list_first_entry(&head, lst_stat_req_param_t, srp_link);
2710 list_del(&srp->srp_link);
2711 lst_stat_req_param_free(srp);
2718 jt_lst_show_error(int argc, char **argv)
2720 struct list_head head;
2721 lst_stat_req_param_t *srp;
2722 struct lstcon_rpc_ent *ent;
2723 struct sfw_counters *sfwk;
2724 struct srpc_counters *srpc;
2731 static const struct option show_error_opts[] = {
2732 { .name = "session", .has_arg = no_argument, .val = 's' },
2733 { .name = NULL, } };
2735 if (session_key == 0) {
2737 "Can't find env LST_SESSION or value is not valid\n");
2742 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
2753 lst_print_usage(argv[0]);
2758 if (optind == argc) {
2759 lst_print_usage(argv[0]);
2763 INIT_LIST_HEAD(&head);
2765 while (optind < argc) {
2766 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
2770 list_add_tail(&srp->srp_link, &head);
2773 list_for_each_entry(srp, &head, srp_link) {
2774 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
2775 srp->srp_ids, 10, &srp->srp_result[0]);
2778 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2779 srp->srp_name, strerror(errno));
2783 fprintf(stdout, "%s:\n", srp->srp_name);
2787 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2788 if (ent->rpe_rpc_errno != 0) {
2790 fprintf(stderr, "RPC failure, can't show error on %s\n",
2791 libcfs_id2str(ent->rpe_peer));
2795 if (ent->rpe_fwk_errno != 0) {
2797 fprintf(stderr, "Framework failure, can't show error on %s\n",
2798 libcfs_id2str(ent->rpe_peer));
2802 sfwk = (struct sfw_counters *)&ent->rpe_payload[0];
2803 srpc = (struct srpc_counters *)((char *)sfwk + sizeof(*sfwk));
2805 if (srpc->errors == 0 &&
2806 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2810 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2815 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2816 libcfs_id2str(ent->rpe_peer),
2817 sfwk->brw_errors, sfwk->ping_errors,
2818 show_rpc ? ' ' : '\n');
2823 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2824 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2827 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2830 while (!list_empty(&head)) {
2831 srp = list_first_entry(&head, lst_stat_req_param_t, srp_link);
2833 list_del(&srp->srp_link);
2834 lst_stat_req_param_free(srp);
2841 lst_add_batch_ioctl(char *name)
2843 struct lstio_batch_add_args args = { 0 };
2845 args.lstio_bat_key = session_key;
2846 args.lstio_bat_nmlen = strlen(name);
2847 args.lstio_bat_namep = name;
2849 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2853 jt_lst_add_batch(int argc, char **argv)
2858 if (session_key == 0) {
2860 "Can't find env LST_SESSION or value is not valid\n");
2865 lst_print_usage(argv[0]);
2870 if (strlen(name) >= LST_NAME_SIZE) {
2871 fprintf(stderr, "Name length is limited to %d\n",
2876 rc = lst_add_batch_ioctl(name);
2880 lst_print_error("batch", "Failed to create batch: %s\n",
2887 lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp)
2889 struct lstio_batch_run_args args = { 0 };
2891 args.lstio_bat_key = session_key;
2892 args.lstio_bat_timeout = timeout;
2893 args.lstio_bat_nmlen = strlen(name);
2894 args.lstio_bat_namep = name;
2895 args.lstio_bat_resultp = resultp;
2897 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2901 jt_lst_start_batch(int argc, char **argv)
2903 struct list_head head;
2911 static const struct option start_batch_opts[] = {
2912 { .name = "timeout", .has_arg = required_argument, .val = 't' },
2915 if (session_key == 0) {
2917 "Can't find env LST_SESSION or value is not valid\n");
2922 c = getopt_long(argc, argv, "t:",
2923 start_batch_opts, &optidx);
2925 /* Detect the end of the options. */
2931 timeout = atoi(optarg);
2934 lst_print_usage(argv[0]);
2939 if (optind == argc) {
2940 batch = LST_DEFAULT_BATCH;
2942 } else if (optind == argc - 1) {
2943 batch = argv[optind];
2946 lst_print_usage(argv[0]);
2950 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2952 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2953 batch, strerror(errno));
2957 INIT_LIST_HEAD(&head);
2959 rc = lst_alloc_rpcent(&head, count, 0);
2961 fprintf(stderr, "Out of memory\n");
2965 rc = lst_start_batch_ioctl(batch, timeout, &head);
2968 fprintf(stdout, "%s is running now\n", batch);
2969 lst_free_rpcent(&head);
2974 lst_print_error("batch", "Failed to start batch: %s\n",
2976 lst_free_rpcent(&head);
2980 lst_print_transerr(&head, "Run batch");
2982 lst_free_rpcent(&head);
2988 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2990 struct lstio_batch_stop_args args = { 0 };
2992 args.lstio_bat_key = session_key;
2993 args.lstio_bat_force = force;
2994 args.lstio_bat_nmlen = strlen(name);
2995 args.lstio_bat_namep = name;
2996 args.lstio_bat_resultp = resultp;
2998 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
3002 jt_lst_stop_batch(int argc, char **argv)
3004 struct list_head head;
3012 static const struct option stop_batch_opts[] = {
3013 { .name = "force", .has_arg = no_argument, .val = 'f' },
3016 if (session_key == 0) {
3018 "Can't find env LST_SESSION or value is not valid\n");
3023 c = getopt_long(argc, argv, "f",
3024 stop_batch_opts, &optidx);
3026 /* Detect the end of the options. */
3035 lst_print_usage(argv[0]);
3040 if (optind == argc) {
3041 batch = LST_DEFAULT_BATCH;
3043 } else if (optind == argc - 1) {
3044 batch = argv[optind];
3047 lst_print_usage(argv[0]);
3051 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
3053 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
3054 batch, strerror(errno));
3058 INIT_LIST_HEAD(&head);
3060 rc = lst_alloc_rpcent(&head, count, 0);
3062 fprintf(stderr, "Out of memory\n");
3066 rc = lst_stop_batch_ioctl(batch, force, &head);
3071 lst_reset_rpcent(&head);
3073 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
3077 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
3078 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
3081 fprintf(stdout, "%d batch in stopping\n",
3082 lstcon_tsbqry_stat_run(&trans_stat, 0));
3086 fprintf(stdout, "Batch is stopped\n");
3087 lst_free_rpcent(&head);
3092 lst_print_error("batch", "Failed to stop batch: %s\n",
3094 lst_free_rpcent(&head);
3098 lst_print_transerr(&head, "stop batch");
3100 lst_free_rpcent(&head);
3106 lst_list_batch_ioctl(int len, char *name, int index)
3108 struct lstio_batch_list_args args = { 0 };
3110 args.lstio_bat_key = session_key;
3111 args.lstio_bat_idx = index;
3112 args.lstio_bat_nmlen = len;
3113 args.lstio_bat_namep = name;
3115 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
3119 lst_info_batch_ioctl(char *batch, int test, int server,
3120 struct lstcon_test_batch_ent *entp, int *idxp,
3121 int *ndentp, struct lstcon_node_ent *dentsp)
3123 struct lstio_batch_info_args args = { 0 };
3125 args.lstio_bat_key = session_key;
3126 args.lstio_bat_nmlen = strlen(batch);
3127 args.lstio_bat_namep = batch;
3128 args.lstio_bat_server = server;
3129 args.lstio_bat_testidx = test;
3130 args.lstio_bat_entp = entp;
3131 args.lstio_bat_idxp = idxp;
3132 args.lstio_bat_ndentp = ndentp;
3133 args.lstio_bat_dentsp = dentsp;
3135 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
3139 lst_list_batch_all(void)
3141 char name[LST_NAME_SIZE];
3145 for (i = 0; ; i++) {
3146 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
3148 fprintf(stdout, "%d) %s\n", i + 1, name);
3152 if (errno == ENOENT)
3155 lst_print_error("batch", "Failed to list batch: %s\n",
3160 fprintf(stdout, "Total %d batches\n", i);
3166 lst_list_tsb_nodes(char *batch, int test, int server,
3167 int count, int active, int invalid)
3169 struct lstcon_node_ent *dents;
3178 /* verbose list, show nodes in batch or test */
3179 dents = malloc(count * sizeof(struct lstcon_node_ent));
3180 if (dents == NULL) {
3181 fprintf(stdout, "Can't allocate memory\n");
3185 rc = lst_info_batch_ioctl(batch, test, server,
3186 NULL, &index, &count, dents);
3189 lst_print_error((test > 0) ? "test" : "batch",
3190 (test > 0) ? "Failed to query test: %s\n" :
3191 "Failed to query batch: %s\n",
3196 for (i = 0, c = 0; i < count; i++) {
3197 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
3198 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
3199 dents[i].nde_state == LST_NODE_DOWN ||
3200 dents[i].nde_state == LST_NODE_UNKNOWN)))
3203 fprintf(stdout, "\t%s: %s\n",
3204 libcfs_id2str(dents[i].nde_id),
3205 lst_node_state2str(dents[i].nde_state));
3209 fprintf(stdout, "Total %d nodes\n", c);
3216 jt_lst_list_batch(int argc, char **argv)
3218 struct lstcon_test_batch_ent ent;
3221 int verbose = 0; /* list nodes in batch or test */
3230 static const struct option list_batch_opts[] = {
3231 { .name = "test", .has_arg = required_argument, .val = 't' },
3232 { .name = "invalid", .has_arg = no_argument, .val = 'i' },
3233 { .name = "active", .has_arg = no_argument, .val = 'a' },
3234 { .name = "all", .has_arg = no_argument, .val = 'l' },
3235 { .name = "server", .has_arg = no_argument, .val = 's' },
3236 { .name = NULL, } };
3238 if (session_key == 0) {
3240 "Can't find env LST_SESSION or value is not valid\n");
3245 c = getopt_long(argc, argv, "ailst:",
3246 list_batch_opts, &optidx);
3253 verbose = active = 1;
3256 verbose = invalid = 1;
3259 verbose = active = invalid = 1;
3265 test = atoi(optarg);
3269 lst_print_usage(argv[0]);
3274 if (optind == argc) {
3275 /* list all batches */
3276 rc = lst_list_batch_all();
3280 if (ntest == 1 && test <= 0) {
3281 fprintf(stderr, "Invalid test id, test id starts from 1\n");
3285 if (optind != argc - 1) {
3286 lst_print_usage(argv[0]);
3290 batch = argv[optind];
3293 /* show detail of specified batch or test */
3294 rc = lst_info_batch_ioctl(batch, test, server,
3295 &ent, NULL, NULL, NULL);
3297 lst_print_error((test > 0) ? "test" : "batch",
3298 (test > 0) ? "Failed to query test: %s\n" :
3299 "Failed to query batch: %s\n",
3305 /* list nodes in test or batch */
3306 rc = lst_list_tsb_nodes(batch, test, server,
3307 server ? ent.tbe_srv_nle.nle_nnode :
3308 ent.tbe_cli_nle.nle_nnode,
3313 /* only show number of hosts in batch or test */
3315 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
3316 batch, ent.u.tbe_batch.bae_ntest,
3317 ent.u.tbe_batch.bae_state);
3318 ntest = ent.u.tbe_batch.bae_ntest;
3319 test = 1; /* starting from test 1 */
3323 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
3324 test, lst_test_type2name(ent.u.tbe_test.tse_type),
3325 ent.u.tbe_test.tse_loop,
3326 ent.u.tbe_test.tse_concur);
3331 fprintf(stdout, LST_NODES_TITLE);
3332 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
3333 "server\t%d\t%d\t%d\t%d\t%d\n",
3334 ent.tbe_cli_nle.nle_nactive,
3335 ent.tbe_cli_nle.nle_nbusy,
3336 ent.tbe_cli_nle.nle_ndown,
3337 ent.tbe_cli_nle.nle_nunknown,
3338 ent.tbe_cli_nle.nle_nnode,
3339 ent.tbe_srv_nle.nle_nactive,
3340 ent.tbe_srv_nle.nle_nbusy,
3341 ent.tbe_srv_nle.nle_ndown,
3342 ent.tbe_srv_nle.nle_nunknown,
3343 ent.tbe_srv_nle.nle_nnode);
3352 lst_query_batch_ioctl(char *batch, int test, int server,
3353 int timeout, struct list_head *head)
3355 struct lstio_batch_query_args args = { 0 };
3357 args.lstio_bat_key = session_key;
3358 args.lstio_bat_testidx = test;
3359 args.lstio_bat_client = !(server);
3360 args.lstio_bat_timeout = timeout;
3361 args.lstio_bat_nmlen = strlen(batch);
3362 args.lstio_bat_namep = batch;
3363 args.lstio_bat_resultp = head;
3365 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
3369 lst_print_tsb_verbose(struct list_head *head,
3370 int active, int idle, int error)
3372 struct lstcon_rpc_ent *ent;
3374 list_for_each_entry(ent, head, rpe_link) {
3375 if (ent->rpe_priv[0] == 0 && active)
3378 if (ent->rpe_priv[0] != 0 && idle)
3381 if (ent->rpe_fwk_errno == 0 && error)
3384 fprintf(stdout, "%s [%s]: %s\n",
3385 libcfs_id2str(ent->rpe_peer),
3386 lst_node_state2str(ent->rpe_state),
3387 ent->rpe_rpc_errno != 0 ?
3388 strerror(ent->rpe_rpc_errno) :
3389 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
3394 jt_lst_query_batch(int argc, char **argv)
3396 struct lstcon_test_batch_ent ent;
3397 struct list_head head;
3403 int timeout = 5; /* default 5 seconds */
3404 int delay = 5; /* default 5 seconds */
3405 int loop = 1; /* default 1 loop */
3415 static const struct option query_batch_opts[] = {
3416 { .name = "timeout", .has_arg = required_argument, .val = 'o' },
3417 { .name = "delay", .has_arg = required_argument, .val = 'd' },
3418 { .name = "loop", .has_arg = required_argument, .val = 'c' },
3419 { .name = "test", .has_arg = required_argument, .val = 't' },
3420 { .name = "server", .has_arg = no_argument, .val = 's' },
3421 { .name = "active", .has_arg = no_argument, .val = 'a' },
3422 { .name = "idle", .has_arg = no_argument, .val = 'i' },
3423 { .name = "error", .has_arg = no_argument, .val = 'e' },
3424 { .name = "all", .has_arg = no_argument, .val = 'l' },
3425 { .name = NULL, } };
3427 if (session_key == 0) {
3429 "Can't find env LST_SESSION or value is not valid\n");
3434 c = getopt_long(argc, argv, "o:d:c:t:saiel",
3435 query_batch_opts, &optidx);
3437 /* Detect the end of the options. */
3443 timeout = atoi(optarg);
3446 delay = atoi(optarg);
3449 loop = atoi(optarg);
3452 test = atoi(optarg);
3458 active = verbose = 1;
3464 error = verbose = 1;
3470 lst_print_usage(argv[0]);
3475 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
3476 lst_print_usage(argv[0]);
3480 if (optind == argc) {
3481 batch = LST_DEFAULT_BATCH;
3483 } else if (optind == argc - 1) {
3484 batch = argv[optind];
3487 lst_print_usage(argv[0]);
3492 INIT_LIST_HEAD(&head);
3495 rc = lst_info_batch_ioctl(batch, test, server,
3496 &ent, NULL, NULL, NULL);
3498 fprintf(stderr, "Failed to query %s [%d]: %s\n",
3499 batch, test, strerror(errno));
3503 count = server ? ent.tbe_srv_nle.nle_nnode :
3504 ent.tbe_cli_nle.nle_nnode;
3506 fprintf(stdout, "Batch or test is empty\n");
3511 rc = lst_alloc_rpcent(&head, count, 0);
3513 fprintf(stderr, "Out of memory\n");
3517 for (i = 0; i < loop; i++) {
3518 time_t now = time(NULL);
3520 if (now - last < delay) {
3521 sleep(delay - now + last);
3527 rc = lst_query_batch_ioctl(batch, test,
3528 server, timeout, &head);
3530 fprintf(stderr, "Failed to query batch: %s\n",
3537 lst_print_tsb_verbose(&head, active, idle, error);
3541 fprintf(stdout, "%s [%d] ", batch, test);
3543 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
3544 fprintf(stdout, "%d of %d nodes are unknown, ",
3545 lstcon_rpc_stat_failure(&trans_stat, 0),
3546 lstcon_rpc_stat_total(&trans_stat, 0));
3549 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
3550 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
3551 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
3552 fprintf(stdout, "is stopped\n");
3556 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
3557 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
3558 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
3559 fprintf(stdout, "is running\n");
3563 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
3564 lstcon_tsbqry_stat_idle(&trans_stat, 0),
3565 lstcon_tsbqry_stat_run(&trans_stat, 0),
3566 lstcon_tsbqry_stat_failure(&trans_stat, 0));
3569 lst_free_rpcent(&head);
3575 lst_parse_distribute(char *dstr, int *dist, int *span)
3581 dstr = strchr(dstr, ':');
3585 *span = atoi(dstr + 1);
3593 lst_get_bulk_param(int argc, char **argv, struct lst_test_bulk_param *bulk)
3600 bulk->blk_size = 4096;
3601 bulk->blk_opc = LST_BRW_READ;
3602 bulk->blk_flags = LST_BRW_CHECK_NONE;
3603 bulk->blk_srv_off = bulk->blk_cli_off = 0;
3606 if (strcasestr(argv[i], "check=") == argv[i] ||
3607 strcasestr(argv[i], "c=") == argv[i]) {
3608 tok = strchr(argv[i], '=') + 1;
3610 if (strcasecmp(tok, "full") == 0) {
3611 bulk->blk_flags = LST_BRW_CHECK_FULL;
3612 } else if (strcasecmp(tok, "simple") == 0) {
3613 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
3615 fprintf(stderr, "Unknow flag %s\n", tok);
3619 } else if (strcasestr(argv[i], "size=") == argv[i] ||
3620 strcasestr(argv[i], "s=") == argv[i]) {
3621 tok = strchr(argv[i], '=') + 1;
3623 bulk->blk_size = strtol(tok, &end, 0);
3624 if (bulk->blk_size <= 0) {
3625 fprintf(stderr, "Invalid size %s\n", tok);
3632 if (*end == 'k' || *end == 'K')
3633 bulk->blk_size *= 1024;
3634 else if (*end == 'm' || *end == 'M')
3635 bulk->blk_size *= 1024 * 1024;
3637 if (bulk->blk_size > LNET_MTU) {
3638 fprintf(stderr, "Size exceed limitation: %d bytes\n",
3643 } else if (strcasestr(argv[i], "off=") == argv[i]) {
3646 tok = strchr(argv[i], '=') + 1;
3648 off = strtol(tok, &end, 0);
3649 /* NB: align with sizeof(__u64) to simplify page
3650 * checking implementation */
3651 if (off < 0 || off % sizeof(__u64) != 0) {
3653 "Invalid offset %s/%d, it should be "
3654 "postive value and multiple of %d\n",
3655 tok, off, (int)sizeof(__u64));
3659 /* NB: blk_srv_off is reserved so far */
3660 bulk->blk_cli_off = bulk->blk_srv_off = off;
3664 } else if (strcasecmp(argv[i], "read") == 0 ||
3665 strcasecmp(argv[i], "r") == 0) {
3666 bulk->blk_opc = LST_BRW_READ;
3668 } else if (strcasecmp(argv[i], "write") == 0 ||
3669 strcasecmp(argv[i], "w") == 0) {
3670 bulk->blk_opc = LST_BRW_WRITE;
3673 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
3684 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
3686 struct lst_test_bulk_param *bulk = NULL;
3687 struct lst_test_ping_param *ping = NULL;
3690 type = lst_test_name2type(test);
3692 fprintf(stderr, "Unknow test name %s\n", test);
3698 /* unused but needs for kernel part */
3699 ping = malloc(sizeof(*ping));
3701 fprintf(stderr, "Out of memory\n");
3704 memset(ping, 0, sizeof(*ping));
3707 *plen = sizeof(*ping);
3712 bulk = malloc(sizeof(*bulk));
3714 fprintf(stderr, "Out of memory\n");
3718 memset(bulk, 0, sizeof(*bulk));
3720 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
3726 *plen = sizeof(*bulk);
3734 /* TODO: parse more parameter */
3739 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
3740 int dist, int span, char *sgrp, char *dgrp,
3741 void *param, int plen, int *retp, struct list_head *resultp)
3743 struct lstio_test_args args = { 0 };
3745 args.lstio_tes_key = session_key;
3746 args.lstio_tes_bat_nmlen = strlen(batch);
3747 args.lstio_tes_bat_name = batch;
3748 args.lstio_tes_type = type;
3749 args.lstio_tes_oneside = 0;
3750 args.lstio_tes_loop = loop;
3751 args.lstio_tes_concur = concur;
3752 args.lstio_tes_dist = dist;
3753 args.lstio_tes_span = span;
3754 args.lstio_tes_sgrp_nmlen = strlen(sgrp);
3755 args.lstio_tes_sgrp_name = sgrp;
3756 args.lstio_tes_dgrp_nmlen = strlen(dgrp);
3757 args.lstio_tes_dgrp_name = dgrp;
3758 args.lstio_tes_param_len = plen;
3759 args.lstio_tes_param = param;
3760 args.lstio_tes_retp = retp;
3761 args.lstio_tes_resultp = resultp;
3763 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
3767 jt_lst_add_test(int argc, char **argv)
3769 struct list_head head;
3789 static const struct option add_test_opts[] = {
3790 { .name = "batch", .has_arg = required_argument, .val = 'b' },
3791 { .name = "concurrency", .has_arg = required_argument, .val = 'c' },
3792 { .name = "distribute", .has_arg = required_argument, .val = 'd' },
3793 { .name = "from", .has_arg = required_argument, .val = 'f' },
3794 { .name = "to", .has_arg = required_argument, .val = 't' },
3795 { .name = "loop", .has_arg = required_argument, .val = 'l' },
3798 if (session_key == 0) {
3800 "Can't find env LST_SESSION or value is not valid\n");
3805 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3806 add_test_opts, &optidx);
3808 /* Detect the end of the options. */
3817 concur = atoi(optarg);
3826 loop = atoi(optarg);
3832 lst_print_usage(argv[0]);
3837 if (optind == argc || from == NULL || to == NULL) {
3838 lst_print_usage(argv[0]);
3842 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3843 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3848 batch = LST_DEFAULT_BATCH;
3851 rc = lst_parse_distribute(dstr, &dist, &span);
3853 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3858 test = argv[optind++];
3863 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3865 fprintf(stderr, "Failed to add test (%s)\n", test);
3869 INIT_LIST_HEAD(&head);
3871 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3873 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3874 from, strerror(errno));
3878 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3880 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3881 to, strerror(errno));
3885 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3887 fprintf(stderr, "Out of memory\n");
3891 rc = lst_add_test_ioctl(batch, type, loop, concur,
3892 dist, span, from, to, param, plen, &ret, &head);
3895 fprintf(stdout, "Test was added successfully\n");
3897 fprintf(stdout, "Server group contains userland test "
3898 "nodes, old version of tcplnd can't accept "
3899 "connection request\n");
3906 lst_print_error("test", "Failed to add test: %s\n",
3911 lst_print_transerr(&head, "add test");
3913 lst_free_rpcent(&head);
3921 static command_t lst_cmdlist[] = {
3922 {"new_session", jt_lst_new_session, NULL,
3923 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3924 {"end_session", jt_lst_end_session, NULL,
3925 "Usage: lst end_session" },
3926 {"show_session", jt_lst_show_session, NULL,
3927 "Usage: lst show_session" },
3928 {"ping", jt_lst_ping , NULL,
3929 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3930 {"add_group", jt_lst_add_group, NULL,
3931 "Usage: lst group NAME IDs [IDs]..." },
3932 {"del_group", jt_lst_del_group, NULL,
3933 "Usage: lst del_group NAME" },
3934 {"update_group", jt_lst_update_group, NULL,
3935 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3936 {"list_group", jt_lst_list_group, NULL,
3937 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3938 {"stat", jt_lst_stat, NULL,
3939 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3940 " [--mbs] [--timeout #] [--delay #] [--count #] GROUP [GROUP]" },
3941 {"show_error", jt_lst_show_error, NULL,
3942 "Usage: lst show_error NAME | IDS ..." },
3943 {"add_batch", jt_lst_add_batch, NULL,
3944 "Usage: lst add_batch NAME" },
3945 {"run", jt_lst_start_batch, NULL,
3946 "Usage: lst run [--timeout TIME] [NAME]" },
3947 {"stop", jt_lst_stop_batch, NULL,
3948 "Usage: lst stop [--force] BATCH_NAME" },
3949 {"list_batch", jt_lst_list_batch, NULL,
3950 "Usage: lst list_batch NAME [--test ID] [--server]" },
3951 {"query", jt_lst_query_batch, NULL,
3952 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3953 {"add_test", jt_lst_add_test, NULL,
3954 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3955 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3960 lst_initialize(void)
3965 feats = getenv("LST_FEATURES");
3967 session_features = strtol(feats, NULL, 16);
3969 if ((session_features & ~LST_FEATS_MASK) != 0) {
3971 "Unsupported session features %x, "
3972 "only support these features so far: %x\n",
3973 (session_features & ~LST_FEATS_MASK), LST_FEATS_MASK);
3977 key = getenv("LST_SESSION");
3984 session_key = atoi(key);
3989 int main(int argc, char **argv)
3995 rc = lst_initialize();
3999 rc = lustre_lnet_config_lib_init();
4003 rc = cfs_parser(argc, argv, lst_cmdlist);