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;
58 static int lst_list_commands(int argc, char **argv);
60 /* All nodes running 2.6.50 or later understand feature LST_FEAT_BULK_LEN */
61 static unsigned int session_features = LST_FEATS_MASK;
62 static struct lstcon_trans_stat trans_stat;
64 typedef struct list_string {
65 struct list_string *lstr_next;
71 # define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
74 static int alloc_count = 0;
75 static int alloc_nob = 0;
80 lstr_t *lstr = malloc(offsetof(lstr_t, lstr_str[sz]));
83 fprintf(stderr, "Can't allocate lstr\n");
90 lstr->lstr_str[0] = 0;
96 free_lstr(lstr_t *lstr)
99 alloc_nob -= lstr->lstr_sz;
104 free_lstrs(lstr_t **list)
108 while ((lstr = *list) != NULL) {
109 *list = lstr->lstr_next;
115 new_lstrs(lstr_t **list, char *prefix, char *postfix,
116 int lo, int hi, int stride)
118 int n1 = strlen(prefix);
119 int n2 = strlen(postfix);
120 int sz = n1 + 20 + n2 + 1;
123 lstr_t *n = alloc_lstr(sz);
125 snprintf(n->lstr_str, sz - 1, "%s%u%s",
126 prefix, lo, postfix);
128 n->lstr_next = *list;
136 expand_lstr(lstr_t **list, lstr_t *l)
138 int nob = strlen(l->lstr_str);
148 b1 = strchr(l->lstr_str, '[');
150 l->lstr_next = *list;
155 b2 = strchr(b1, ']');
156 if (b2 == NULL || b2 == b1 + 1)
164 sep = strchr(expr, ',');
170 if (sscanf(expr, "%u%n", &x, &n) >= 1 && n == nob) {
172 new_lstrs(list, l->lstr_str, b2, x, x, 1);
177 if (sscanf(expr, "%u-%u%n", &x, &y, &n) >= 2 && n == nob &&
180 new_lstrs(list, l->lstr_str, b2, x, y, 1);
185 if (sscanf(expr, "%u-%u/%u%n", &x, &y, &z, &n) >= 3 && n == nob &&
188 new_lstrs(list, l->lstr_str, b2, x, y, z);
194 } while ((expr = sep) != NULL);
202 expand_strs(char *str, lstr_t **head)
210 l = alloc_lstr(strlen(str) + 1);
211 memcpy(l->lstr_str, str, strlen(str) + 1);
219 while ((l = list) != NULL) {
222 rc = expand_lstr(&nlist, l);
224 fprintf(stderr, "Syntax error in \"%s\"\n", str);
232 /* re-order onto 'list' */
233 while ((l = nlist) != NULL) {
234 nlist = l->lstr_next;
239 } while (expanded && rc > 0);
246 while ((l = list) != NULL) {
255 lst_parse_nids(char *str, int *countp, struct lnet_process_id **idspp)
263 rc = expand_strs(str, &head);
273 *idspp = malloc(c * sizeof(struct lnet_process_id));
274 if (*idspp == NULL) {
275 fprintf(stderr, "Out of memory\n");
282 while ((l = head) != NULL) {
286 (*idspp)[i].nid = libcfs_str2nid(l->lstr_str);
287 if ((*idspp)[i].nid == LNET_NID_ANY) {
288 fprintf(stderr, "Invalid nid: %s\n",
293 (*idspp)[i].pid = LNET_PID_LUSTRE;
310 lst_node_state2str(int state)
312 if (state == LST_NODE_ACTIVE)
314 if (state == LST_NODE_BUSY)
316 if (state == LST_NODE_DOWN)
323 lst_node_str2state(char *str)
325 if (strcasecmp(str, "active") == 0)
326 return LST_NODE_ACTIVE;
327 if (strcasecmp(str, "busy") == 0)
328 return LST_NODE_BUSY;
329 if (strcasecmp(str, "down") == 0)
330 return LST_NODE_DOWN;
331 if (strcasecmp(str, "unknown") == 0)
332 return LST_NODE_UNKNOWN;
333 if (strcasecmp(str, "invalid") == 0)
334 return (LST_NODE_UNKNOWN | LST_NODE_DOWN | LST_NODE_BUSY);
340 lst_test_type2name(int type)
342 if (type == LST_TEST_PING)
344 if (type == LST_TEST_BULK)
351 lst_test_name2type(char *name)
353 if (strcasecmp(name, "ping") == 0)
354 return LST_TEST_PING;
355 if (strcasecmp(name, "brw") == 0)
356 return LST_TEST_BULK;
362 lst_print_usage(char *cmd)
364 Parser_printhelp(cmd);
368 lst_print_error(char *sub, const char *def_format, ...)
372 /* local error returned from kernel */
375 fprintf(stderr, "No session exists\n");
378 fprintf(stderr, "Session is shutting down\n");
381 fprintf(stderr, "Unmatched session key or not root\n");
384 fprintf(stderr, "Can't find %s in current session\n", sub);
387 fprintf(stderr, "Invalid parameters list in command line\n");
390 fprintf(stderr, "Bad parameter address\n");
393 fprintf(stderr, "%s already exists\n", sub);
396 va_start(ap, def_format);
397 vfprintf(stderr, def_format, ap);
405 lst_free_rpcent(struct list_head *head)
407 struct lstcon_rpc_ent *ent;
409 while (!list_empty(head)) {
410 ent = list_entry(head->next, struct lstcon_rpc_ent, rpe_link);
412 list_del(&ent->rpe_link);
418 lst_reset_rpcent(struct list_head *head)
420 struct lstcon_rpc_ent *ent;
422 list_for_each_entry(ent, head, rpe_link) {
423 ent->rpe_sid = LST_INVALID_SID;
424 ent->rpe_peer.nid = LNET_NID_ANY;
425 ent->rpe_peer.pid = LNET_PID_ANY;
426 ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
431 lst_alloc_rpcent(struct list_head *head, int count, int offset)
433 struct lstcon_rpc_ent *ent;
436 for (i = 0; i < count; i++) {
437 ent = malloc(offsetof(struct lstcon_rpc_ent, rpe_payload[offset]));
439 lst_free_rpcent(head);
443 memset(ent, 0, offsetof(struct lstcon_rpc_ent, rpe_payload[offset]));
445 ent->rpe_sid = LST_INVALID_SID;
446 ent->rpe_peer.nid = LNET_NID_ANY;
447 ent->rpe_peer.pid = LNET_PID_ANY;
448 list_add(&ent->rpe_link, head);
455 lst_print_transerr(struct list_head *head, char *optstr)
457 struct lstcon_rpc_ent *ent;
459 list_for_each_entry(ent, head, rpe_link) {
460 if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
463 if (ent->rpe_rpc_errno != 0) {
464 fprintf(stderr, "%s RPC failed on %s: %s\n",
465 optstr, libcfs_id2str(ent->rpe_peer),
466 strerror(ent->rpe_rpc_errno));
470 fprintf(stderr, "operation %s failed on %s: %s\n",
471 optstr, libcfs_id2str(ent->rpe_peer),
472 strerror(ent->rpe_fwk_errno));
476 int lst_info_batch_ioctl(char *batch, int test, int server,
477 struct lstcon_test_batch_ent *entp, int *idxp,
478 int *ndentp, struct lstcon_node_ent *dentsp);
480 int lst_info_group_ioctl(char *name, struct lstcon_ndlist_ent *gent,
481 int *idx, int *count, struct lstcon_node_ent *dents);
483 int lst_query_batch_ioctl(char *batch, int test, int server,
484 int timeout, struct list_head *head);
487 lst_ioctl(unsigned int opc, void *buf, int len)
489 struct libcfs_ioctl_data data;
492 LIBCFS_IOC_INIT (data);
493 data.ioc_u32[0] = opc;
494 data.ioc_plen1 = len;
495 data.ioc_pbuf1 = (char *)buf;
496 data.ioc_plen2 = sizeof(trans_stat);
497 data.ioc_pbuf2 = (char *)&trans_stat;
499 memset(&trans_stat, 0, sizeof(trans_stat));
501 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNETST, &data);
503 /* local error, no valid RPC result */
508 if (trans_stat.trs_rpc_errno != 0)
511 /* Framework error */
512 if (trans_stat.trs_fwk_errno != 0)
518 int lst_yaml_session(const char *label, const char *timeout, int nlflags,
521 struct lstcon_ndlist_ent ndinfo = { };
522 struct lst_sid sid = LST_INVALID_SID;
523 /* nlflags being zero means we are destroying the session.
524 * No parsing of reply needed.
526 bool done = nlflags ? false : true;
527 char nid[LNET_NIDSTR_SIZE];
528 char name[LST_NAME_SIZE];
529 unsigned int key = 0;
530 yaml_emitter_t request;
536 sk = nl_socket_alloc();
540 /* Note: NL_AUTO_PID == zero which we use by default for the
541 * session_key when creating a new session. This is considered
542 * an invalid key so we need to get the real session key from
543 * the yaml parser yet to be created. If the user did request
544 * a specific session key then set the socket's port id to this
548 nl_socket_set_local_port(sk, session_key);
550 /* Setup reply parser to recieve Netlink packets */
551 rc = yaml_parser_initialize(&reply);
557 rc = yaml_parser_set_input_netlink(&reply, sk, false);
561 /* Create Netlink emitter to send request to kernel */
562 yaml_emitter_initialize(&request);
563 rc = yaml_emitter_set_output_netlink(&request, sk,
564 LNET_SELFTEST_GENL_NAME,
565 LNET_SELFTEST_GENL_VERSION,
566 LNET_SELFTEST_CMD_SESSIONS,
571 yaml_emitter_open(&request);
572 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
573 rc = yaml_emitter_emit(&request, &event);
577 yaml_mapping_start_event_initialize(&event, NULL,
578 (yaml_char_t *)YAML_MAP_TAG,
579 1, YAML_BLOCK_MAPPING_STYLE);
580 rc = yaml_emitter_emit(&request, &event);
584 yaml_scalar_event_initialize(&event, NULL,
585 (yaml_char_t *)YAML_STR_TAG,
586 (yaml_char_t *)"sessions",
587 strlen("sessions"), 1, 0,
588 YAML_PLAIN_SCALAR_STYLE);
589 rc = yaml_emitter_emit(&request, &event);
594 yaml_scalar_event_initialize(&event, NULL,
595 (yaml_char_t *)YAML_STR_TAG,
598 YAML_PLAIN_SCALAR_STYLE);
599 rc = yaml_emitter_emit(&request, &event);
605 /* sessions: { name: 'name', timeout: 300 }
611 yaml_mapping_start_event_initialize(&event, NULL,
612 (yaml_char_t *)YAML_MAP_TAG,
613 1, YAML_FLOW_MAPPING_STYLE);
614 rc = yaml_emitter_emit(&request, &event);
618 yaml_scalar_event_initialize(&event, NULL,
619 (yaml_char_t *)YAML_STR_TAG,
620 (yaml_char_t *)"name",
621 strlen("name"), 1, 0,
622 YAML_PLAIN_SCALAR_STYLE);
623 rc = yaml_emitter_emit(&request, &event);
627 yaml_scalar_event_initialize(&event, NULL,
628 (yaml_char_t *)YAML_STR_TAG,
629 (yaml_char_t *)label,
631 YAML_PLAIN_SCALAR_STYLE);
632 rc = yaml_emitter_emit(&request, &event);
637 yaml_scalar_event_initialize(&event, NULL,
638 (yaml_char_t *)YAML_STR_TAG,
639 (yaml_char_t *)"timeout",
640 strlen("timeout"), 1, 0,
641 YAML_PLAIN_SCALAR_STYLE);
642 rc = yaml_emitter_emit(&request, &event);
646 yaml_scalar_event_initialize(&event, NULL,
647 (yaml_char_t *)YAML_STR_TAG,
648 (yaml_char_t *)timeout,
649 strlen(timeout), 1, 0,
650 YAML_PLAIN_SCALAR_STYLE);
651 rc = yaml_emitter_emit(&request, &event);
656 yaml_mapping_end_event_initialize(&event);
657 rc = yaml_emitter_emit(&request, &event);
662 yaml_mapping_end_event_initialize(&event);
663 rc = yaml_emitter_emit(&request, &event);
667 yaml_document_end_event_initialize(&event, 0);
668 rc = yaml_emitter_emit(&request, &event);
672 rc = yaml_emitter_close(&request);
675 yaml_emitter_log_error(&request, stderr);
676 yaml_emitter_delete(&request);
680 yaml_emitter_delete(&request);
683 rc = yaml_parser_parse(&reply, &event);
687 if (event.type == YAML_SCALAR_EVENT) {
688 char *tmp, *endp = NULL;
690 if (strcmp((char *)event.data.scalar.value,
692 yaml_event_delete(&event);
693 rc = yaml_parser_parse(&reply, &event);
697 strncpy(name, (char *)event.data.scalar.value,
701 if (strcmp((char *)event.data.scalar.value,
703 yaml_event_delete(&event);
704 rc = yaml_parser_parse(&reply, &event);
708 tmp = (char *)event.data.scalar.value;
709 key = strtoul(tmp, &endp, 10);
714 if (strcmp((char *)event.data.scalar.value,
716 yaml_event_delete(&event);
717 rc = yaml_parser_parse(&reply, &event);
721 tmp = (char *)event.data.scalar.value;
722 sid.ses_stamp = strtoll(tmp, &endp, 10);
727 if (strcmp((char *)event.data.scalar.value,
729 yaml_event_delete(&event);
730 rc = yaml_parser_parse(&reply, &event);
734 strncpy(nid, (char *)event.data.scalar.value,
738 if (strcmp((char *)event.data.scalar.value,
740 yaml_event_delete(&event);
741 rc = yaml_parser_parse(&reply, &event);
745 tmp = (char *)event.data.scalar.value;
746 ndinfo.nle_nnode = strtoul(tmp, &endp, 10);
752 done = (event.type == YAML_STREAM_END_EVENT);
754 yaml_event_delete(&event);
757 if (nlflags & NLM_F_CREATE) {
758 session_features = yaml_parser_get_reader_proto_version(&reply);
762 if (rc == 0 && errmsg)
763 yaml_parser_log_error(&reply, stderr, errmsg);
764 yaml_parser_delete(&reply);
767 if (((nlflags & NLM_F_DUMP) == NLM_F_DUMP) && rc != 0) {
769 "%s ID: %ju@%s, KEY: %u FEATURES: %x NODES: %d\n",
770 name, (uintmax_t)sid.ses_stamp, nid,
771 key, session_features, ndinfo.nle_nnode);
774 return rc == 0 ? -1 : 0;
778 lst_new_session_ioctl(char *name, int timeout, int force, struct lst_sid *sid)
780 struct lstio_session_new_args args = { 0 };
782 args.lstio_ses_key = session_key;
783 args.lstio_ses_timeout = timeout;
784 args.lstio_ses_force = force;
785 args.lstio_ses_idp = sid;
786 args.lstio_ses_feats = session_features;
787 args.lstio_ses_nmlen = strlen(name);
788 args.lstio_ses_namep = name;
790 return lst_ioctl (LSTIO_SESSION_NEW, &args, sizeof(args));
794 jt_lst_new_session(int argc, char **argv)
796 char buf[LST_NAME_SIZE * 2 + 1];
797 char *name, *timeout_s = NULL;
798 int nlflags = NLM_F_CREATE;
799 struct lst_sid session_id;
806 static const struct option session_opts[] = {
807 { .name = "timeout", .has_arg = required_argument, .val = 't' },
808 { .name = "force", .has_arg = no_argument, .val = 'f' },
812 c = getopt_long(argc, argv, "ft:",
813 session_opts, &optidx);
819 nlflags |= NLM_F_REPLACE;
826 lst_print_usage(argv[0]);
832 timeout = atoi(timeout_s);
834 fprintf(stderr, "Invalid timeout value\n");
839 if (optind == argc - 1) {
840 name = argv[optind ++];
841 if (strlen(name) >= LST_NAME_SIZE) {
842 fprintf(stderr, "Name size is limited to %d\n",
846 } else if (optind == argc) {
847 char user[LST_NAME_SIZE];
848 char host[LST_NAME_SIZE];
849 struct passwd *pw = getpwuid(getuid());
852 snprintf(user, sizeof(user), "%d", (int)getuid());
854 snprintf(user, sizeof(user), "%s", pw->pw_name);
856 rc = gethostname(host, sizeof(host));
858 snprintf(host, sizeof(host), "unknown_host");
860 snprintf(buf, sizeof(buf), "%s@%s", user, host);
863 lst_print_usage(argv[0]);
867 rc = lst_yaml_session(name, timeout_s, nlflags, "new session");
871 if (session_key == 0) {
873 "Can't find env LST_SESSION or value is not valid\n");
877 rc = lst_new_session_ioctl(name, timeout, force, &session_id);
879 lst_print_error("session", "Failed to create session: %s\n",
884 fprintf(stdout, "SESSION: %s FEATURES: %x TIMEOUT: %d FORCE: %s\n",
885 name, session_features, timeout, force ? "Yes" : "No");
890 lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp,
891 struct lst_sid *sid, struct lstcon_ndlist_ent *ndinfo)
893 struct lstio_session_info_args args = { 0 };
895 args.lstio_ses_idp = sid;
896 args.lstio_ses_keyp = key;
897 args.lstio_ses_featp = featp;
898 args.lstio_ses_ndinfo = ndinfo;
899 args.lstio_ses_nmlen = len;
900 args.lstio_ses_namep = name;
902 return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
906 jt_lst_show_session(int argc, char **argv)
908 struct lstcon_ndlist_ent ndinfo;
910 char name[LST_NAME_SIZE];
915 rc = lst_yaml_session(NULL, NULL, NLM_F_DUMP, "show session");
919 rc = lst_session_info_ioctl(name, sizeof(name), &key,
920 &feats, &sid, &ndinfo);
923 lst_print_error("session", "Failed to show session: %s\n",
928 fprintf(stdout, "%s ID: %ju@%s, KEY: %d FEATURES: %x NODES: %d\n",
929 name, (uintmax_t)sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
930 key, feats, ndinfo.nle_nnode);
936 lst_end_session_ioctl(void)
938 struct lstio_session_end_args args = { 0 };
940 args.lstio_ses_key = session_key;
941 return lst_ioctl(LSTIO_SESSION_END, &args, sizeof(args));
945 jt_lst_end_session(int argc, char **argv)
949 if (session_key == 0) {
951 "Can't find env LST_SESSION or value is not valid\n");
955 rc = lst_yaml_session(NULL, NULL, 0, "end session");
959 rc = lst_end_session_ioctl();
962 fprintf(stdout, "session is ended\n");
967 lst_print_error("session", "Failed to end session: %s\n",
972 if (trans_stat.trs_rpc_errno != 0) {
974 "[RPC] Failed to send %d session RPCs: %s\n",
975 lstcon_rpc_stat_failure(&trans_stat, 0),
976 strerror(trans_stat.trs_rpc_errno));
979 if (trans_stat.trs_fwk_errno != 0) {
981 "[FWK] Failed to end session on %d nodes: %s\n",
982 lstcon_sesop_stat_failure(&trans_stat, 0),
983 strerror(trans_stat.trs_fwk_errno));
989 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
991 static int lst_yaml_display_groups(yaml_parser_t *reply, char *group,
992 int states, bool print)
998 char name[LST_NAME_SIZE] = {};
1003 fprintf(stdout, LST_NODES_TITLE);
1006 rc = yaml_parser_parse(reply, &event);
1010 if (event.type == YAML_MAPPING_START_EVENT) {
1014 rc = yaml_parser_parse(reply, &next);
1018 if (next.type != YAML_SCALAR_EVENT) {
1019 yaml_event_delete(&next);
1023 value = (char *)next.data.scalar.value;
1024 if (strcmp(value, "groups") == 0) {
1025 yaml_event_delete(&next);
1026 } else if (strcmp(value, "nid") == 0) {
1030 rc = yaml_parser_parse(reply, &next);
1034 fprintf(stdout, "\t%s: ",
1035 (char *)next.data.scalar.value);
1037 rc = yaml_parser_parse(reply, &next);
1041 tmp = (char *)next.data.scalar.value;
1042 if (strcmp(tmp, "status") == 0) {
1045 rc = yaml_parser_parse(reply, &state);
1049 fprintf(stdout, "%s\n",
1050 (char *)state.data.scalar.value);
1056 rc = yaml_parser_parse(reply, &next);
1060 strncpy(name, value, sizeof(name) - 1);
1061 fprintf(stdout, "Group [ %s ]\n", name);
1064 if (next.type != YAML_SEQUENCE_START_EVENT) {
1066 "No nodes found [ %s ]\n",
1070 } else if (event.type == YAML_SEQUENCE_END_EVENT &&
1072 fprintf(stdout, "Total %d nodes [ %s ]\n",
1077 done = (event.type == YAML_STREAM_END_EVENT);
1078 yaml_event_delete(&event);
1081 int active = 0, busy = 0, down = 0, unknown = 0;
1082 char group[LST_NAME_SIZE];
1086 rc = yaml_parser_parse(reply, &event);
1090 if (event.type == YAML_SCALAR_EVENT) {
1091 char *value = (char *)event.data.scalar.value;
1094 value = (char *)event.data.scalar.value;
1095 if (strcmp(value, "groups") == 0) {
1096 yaml_event_delete(&event);
1100 rc = yaml_parser_parse(reply, &next);
1104 if (next.type == YAML_SCALAR_EVENT) {
1107 status = lst_node_str2state((char *)next.data.scalar.value);
1109 case LST_NODE_ACTIVE:
1118 case LST_NODE_UNKNOWN:
1123 } else if (next.type == YAML_SEQUENCE_START_EVENT) {
1124 strncpy(group, value, sizeof(group) - 1);
1130 yaml_event_delete(&next);
1131 } else if (event.type == YAML_SEQUENCE_END_EVENT) {
1132 if (strlen(group)) {
1133 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
1134 active, busy, down, unknown,
1135 active + busy + down + unknown, group);
1137 memset(group, 0, sizeof(group));
1139 done = (event.type == YAML_STREAM_END_EVENT);
1140 yaml_event_delete(&event);
1147 rc = yaml_parser_parse(reply, &event);
1151 if (event.type == YAML_SCALAR_EVENT) {
1154 value = (char *)event.data.scalar.value;
1155 if (strlen(value) &&
1156 strcmp(value, "groups") != 0) {
1158 fprintf(stdout, "%d) %s\n",
1163 done = (event.type == YAML_STREAM_END_EVENT);
1165 yaml_event_delete(&event);
1168 fprintf(stdout, "Total %d groups\n", i - 1);
1176 #define LST_NODES_TITLE "\tACTIVE\tBUSY\tDOWN\tUNKNOWN\tTOTAL\n"
1178 static int lst_yaml_groups(int nlflags, char *name, int states, bool print)
1180 yaml_emitter_t request;
1181 yaml_parser_t reply;
1186 sk = nl_socket_alloc();
1190 /* Setup reply parser to recieve Netlink packets */
1191 rc = yaml_parser_initialize(&reply);
1197 rc = yaml_parser_set_input_netlink(&reply, sk, false);
1201 /* Create Netlink emitter to send request to kernel */
1202 yaml_emitter_initialize(&request);
1203 rc = yaml_emitter_set_output_netlink(&request, sk,
1204 LNET_SELFTEST_GENL_NAME,
1205 LNET_SELFTEST_GENL_VERSION,
1206 LNET_SELFTEST_CMD_GROUPS,
1211 yaml_emitter_open(&request);
1212 yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
1213 rc = yaml_emitter_emit(&request, &event);
1217 yaml_mapping_start_event_initialize(&event, NULL,
1218 (yaml_char_t *)YAML_MAP_TAG,
1219 1, YAML_BLOCK_MAPPING_STYLE);
1220 rc = yaml_emitter_emit(&request, &event);
1224 yaml_scalar_event_initialize(&event, NULL,
1225 (yaml_char_t *)YAML_STR_TAG,
1226 (yaml_char_t *)"groups",
1227 strlen("groups"), 1, 0,
1228 YAML_PLAIN_SCALAR_STYLE);
1229 rc = yaml_emitter_emit(&request, &event);
1234 yaml_sequence_start_event_initialize(&event, NULL,
1235 (yaml_char_t *)YAML_SEQ_TAG,
1236 1, YAML_BLOCK_SEQUENCE_STYLE);
1237 rc = yaml_emitter_emit(&request, &event);
1241 yaml_mapping_start_event_initialize(&event, NULL,
1242 (yaml_char_t *)YAML_MAP_TAG,
1243 1, YAML_BLOCK_MAPPING_STYLE);
1244 rc = yaml_emitter_emit(&request, &event);
1248 yaml_scalar_event_initialize(&event, NULL,
1249 (yaml_char_t *)YAML_STR_TAG,
1250 (yaml_char_t *)name,
1252 YAML_PLAIN_SCALAR_STYLE);
1253 rc = yaml_emitter_emit(&request, &event);
1258 int max = ffs(LST_NODE_UNKNOWN) + 1, i;
1261 yaml_sequence_start_event_initialize(&event, NULL,
1262 (yaml_char_t *)YAML_SEQ_TAG,
1263 1, YAML_BLOCK_SEQUENCE_STYLE);
1264 rc = yaml_emitter_emit(&request, &event);
1269 for (i = 0; i < max; i++) {
1270 int mask = states & (1 << i);
1272 state = lst_node_state2str(mask);
1273 if (mask != LST_NODE_UNKNOWN && strcmp(state, "Unknown") == 0)
1276 yaml_mapping_start_event_initialize(&event, NULL,
1277 (yaml_char_t *)YAML_MAP_TAG,
1278 1, YAML_BLOCK_MAPPING_STYLE);
1279 rc = yaml_emitter_emit(&request, &event);
1283 yaml_scalar_event_initialize(&event, NULL,
1284 (yaml_char_t *)YAML_STR_TAG,
1285 (yaml_char_t *)"status",
1286 strlen("status"), 1, 0,
1287 YAML_PLAIN_SCALAR_STYLE);
1288 rc = yaml_emitter_emit(&request, &event);
1292 yaml_scalar_event_initialize(&event, NULL,
1293 (yaml_char_t *)YAML_STR_TAG,
1294 (yaml_char_t *)state,
1295 strlen(state), 1, 0,
1296 YAML_PLAIN_SCALAR_STYLE);
1297 rc = yaml_emitter_emit(&request, &event);
1301 yaml_mapping_end_event_initialize(&event);
1302 rc = yaml_emitter_emit(&request, &event);
1307 yaml_sequence_end_event_initialize(&event);
1308 rc = yaml_emitter_emit(&request, &event);
1312 yaml_scalar_event_initialize(&event, NULL,
1313 (yaml_char_t *)YAML_STR_TAG,
1316 YAML_PLAIN_SCALAR_STYLE);
1317 rc = yaml_emitter_emit(&request, &event);
1322 yaml_mapping_end_event_initialize(&event);
1323 rc = yaml_emitter_emit(&request, &event);
1327 yaml_sequence_end_event_initialize(&event);
1328 rc = yaml_emitter_emit(&request, &event);
1332 yaml_scalar_event_initialize(&event, NULL,
1333 (yaml_char_t *)YAML_STR_TAG,
1336 YAML_PLAIN_SCALAR_STYLE);
1337 rc = yaml_emitter_emit(&request, &event);
1341 yaml_mapping_end_event_initialize(&event);
1342 rc = yaml_emitter_emit(&request, &event);
1346 yaml_document_end_event_initialize(&event, 0);
1347 rc = yaml_emitter_emit(&request, &event);
1351 rc = yaml_emitter_close(&request);
1354 yaml_emitter_log_error(&request, stderr);
1355 yaml_emitter_delete(&request);
1359 yaml_emitter_delete(&request);
1361 /* display output */
1362 if (nlflags == NLM_F_DUMP)
1363 rc = lst_yaml_display_groups(&reply, name, states, print);
1366 yaml_parser_log_error(&reply, stderr, NULL);
1367 yaml_parser_delete(&reply);
1371 rc = rc == 1 ? 0 : -EINVAL;
1377 lst_ping_ioctl(char *str, int type, int timeout,
1378 int count, struct lnet_process_id *ids, struct list_head *head)
1380 struct lstio_debug_args args = { 0 };
1382 args.lstio_dbg_key = session_key;
1383 args.lstio_dbg_type = type;
1384 args.lstio_dbg_flags = 0;
1385 args.lstio_dbg_timeout = timeout;
1386 args.lstio_dbg_nmlen = (str == NULL) ? 0: strlen(str);
1387 args.lstio_dbg_namep = str;
1388 args.lstio_dbg_count = count;
1389 args.lstio_dbg_idsp = ids;
1390 args.lstio_dbg_resultp = head;
1392 return lst_ioctl (LSTIO_DEBUG, &args, sizeof(args));
1396 lst_get_node_count(int type, char *str, int *countp,
1397 struct lnet_process_id **idspp)
1399 char buf[LST_NAME_SIZE];
1400 struct lstcon_test_batch_ent ent;
1401 struct lstcon_ndlist_ent *entp = &ent.tbe_cli_nle;
1408 case LST_OPC_SESSION:
1409 rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
1410 &key, &feats, &sid, entp);
1413 case LST_OPC_BATCHSRV:
1414 entp = &ent.tbe_srv_nle;
1415 case LST_OPC_BATCHCLI:
1416 rc = lst_info_batch_ioctl(str, 0, 0, &ent, NULL, NULL, NULL);
1420 rc = lst_yaml_groups(NLM_F_DUMP, NULL, 0, false);
1421 if (rc == -EOPNOTSUPP) {
1422 rc = lst_info_group_ioctl(str, entp, NULL, NULL, NULL);
1423 } else if (rc > 0) {
1424 entp->nle_nnode = rc;
1430 rc = lst_parse_nids(str, &entp->nle_nnode, idspp) < 0 ? -1 : 0;
1439 *countp = entp->nle_nnode;
1445 jt_lst_ping(int argc, char **argv)
1447 struct list_head head;
1448 struct lnet_process_id *ids = NULL;
1449 struct lstcon_rpc_ent *ent = NULL;
1459 static const struct option ping_opts[] = {
1460 { .name = "session", .has_arg = no_argument, .val = 's' },
1461 { .name = "server", .has_arg = no_argument, .val = 'v' },
1462 { .name = "batch", .has_arg = required_argument, .val = 'b' },
1463 { .name = "group", .has_arg = required_argument, .val = 'g' },
1464 { .name = "nodes", .has_arg = required_argument, .val = 'n' },
1465 { .name = "timeout", .has_arg = required_argument, .val = 't' },
1466 { .name = NULL, } };
1468 if (session_key == 0) {
1470 "Can't find env LST_SESSION or value is not valid\n");
1476 c = getopt_long(argc, argv, "g:b:n:t:sv",
1477 ping_opts, &optidx);
1484 type = LST_OPC_SESSION;
1488 type = LST_OPC_GROUP;
1493 type = LST_OPC_BATCHCLI;
1498 type = LST_OPC_NODES;
1503 timeout = atoi(optarg);
1511 lst_print_usage(argv[0]);
1516 if (type == 0 || timeout <= 0 || optind != argc) {
1517 lst_print_usage(argv[0]);
1521 if (type == LST_OPC_BATCHCLI && server)
1522 type = LST_OPC_BATCHSRV;
1524 rc = lst_get_node_count(type, str, &count, &ids);
1526 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
1527 (str == NULL) ? "session" : str, strerror(errno));
1531 INIT_LIST_HEAD(&head);
1533 rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
1535 fprintf(stderr, "Out of memory\n");
1540 fprintf(stdout, "Target %s is empty\n",
1541 (str == NULL) ? "session" : str);
1545 rc = lst_ping_ioctl(str, type, timeout, count, ids, &head);
1546 if (rc == -1) { /* local failure */
1547 lst_print_error("debug", "Failed to ping %s: %s\n",
1548 (str == NULL) ? "session" : str,
1554 /* ignore RPC errors and framwork errors */
1555 list_for_each_entry(ent, &head, rpe_link) {
1556 fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
1557 libcfs_id2str(ent->rpe_peer),
1558 lst_node_state2str(ent->rpe_state),
1559 (ent->rpe_state == LST_NODE_ACTIVE ||
1560 ent->rpe_state == LST_NODE_BUSY) ?
1561 (ent->rpe_rpc_errno == 0 ?
1562 &ent->rpe_payload[0] : "Unknown") :
1563 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
1567 lst_free_rpcent(&head);
1577 lst_add_nodes_ioctl(char *name, int count, struct lnet_process_id *ids,
1578 unsigned *featp, struct list_head *resultp)
1580 struct lstio_group_nodes_args args = { 0 };
1582 args.lstio_grp_key = session_key;
1583 args.lstio_grp_nmlen = strlen(name);
1584 args.lstio_grp_namep = name;
1585 args.lstio_grp_count = count;
1586 args.lstio_grp_featp = featp;
1587 args.lstio_grp_idsp = ids;
1588 args.lstio_grp_resultp = resultp;
1590 return lst_ioctl(LSTIO_NODES_ADD, &args, sizeof(args));
1594 lst_del_group_ioctl(char *name)
1596 struct lstio_group_del_args args = { 0 };
1598 args.lstio_grp_key = session_key;
1599 args.lstio_grp_nmlen = strlen(name);
1600 args.lstio_grp_namep = name;
1602 return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
1606 lst_del_group(char *grp_name)
1610 rc = lst_del_group_ioctl(grp_name);
1612 fprintf(stdout, "Group is deleted\n");
1617 lst_print_error("group", "Failed to delete group: %s\n",
1622 fprintf(stderr, "Group is deleted with some errors\n");
1624 if (trans_stat.trs_rpc_errno != 0) {
1626 "[RPC] Failed to send %d end session RPCs: %s\n",
1627 lstcon_rpc_stat_failure(&trans_stat, 0),
1628 strerror(trans_stat.trs_rpc_errno));
1631 if (trans_stat.trs_fwk_errno != 0) {
1633 "[FWK] Failed to end session on %d nodes: %s\n",
1634 lstcon_sesop_stat_failure(&trans_stat, 0),
1635 strerror(trans_stat.trs_fwk_errno));
1642 lst_add_group_ioctl(char *name)
1644 struct lstio_group_add_args args = { 0 };
1646 args.lstio_grp_key = session_key;
1647 args.lstio_grp_nmlen = strlen(name);
1648 args.lstio_grp_namep = name;
1650 return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
1654 jt_lst_add_group(int argc, char **argv)
1656 struct list_head head;
1657 struct lnet_process_id *ids;
1659 unsigned feats = session_features;
1663 bool nodes_added = false;
1665 if (session_key == 0) {
1667 "Can't find env LST_SESSION or value is not valid\n");
1672 lst_print_usage(argv[0]);
1677 if (strlen(name) >= LST_NAME_SIZE) {
1678 fprintf(stderr, "Name length is limited to %d\n",
1683 rc = lst_add_group_ioctl(name);
1685 lst_print_error("group", "Failed to add group %s: %s\n",
1686 name, strerror(errno));
1690 INIT_LIST_HEAD(&head);
1692 for (i = 2; i < argc; i++) {
1693 /* parse address list */
1694 rc = lst_parse_nids(argv[i], &count, &ids);
1696 fprintf(stderr, "Ignore invalid id list %s\n",
1704 rc = lst_alloc_rpcent(&head, count, 0);
1706 fprintf(stderr, "Out of memory\n");
1712 rc = lst_add_nodes_ioctl(name, count, ids, &feats, &head);
1719 fprintf(stdout, "%s are added to session\n", argv[i]);
1723 if ((feats & session_features) != session_features) {
1725 "Warning, this session will run with "
1726 "compatible mode because some test nodes "
1727 "might not understand these features: %x\n",
1728 (~feats & session_features));
1731 lst_free_rpcent(&head);
1736 * The selftest kernel module expects that a group should
1737 * have at least one node, since it doesn't make sense for
1738 * an empty group to be added to a test.
1741 "No nodes added successfully, deleting group %s\n",
1743 rc = lst_del_group(name);
1746 "Failed to delete group %s."
1747 " Group is empty.\n", name);
1755 lst_print_error("group", "Failed to add nodes %s: %s\n",
1756 argv[i], strerror(errno));
1759 if (trans_stat.trs_fwk_errno == EPROTO) {
1761 "test nodes might have different LST "
1762 "features, please disable some features by "
1763 "setting LST_FEATURES\n");
1766 lst_print_transerr(&head, "create session");
1769 lst_free_rpcent(&head);
1773 "No nodes added successfully, deleting group %s\n",
1775 if (lst_del_group(name) != 0) {
1777 "Failed to delete group %s."
1778 " Group is empty.\n", name);
1786 jt_lst_del_group(int argc, char **argv)
1790 if (session_key == 0) {
1792 "Can't find env LST_SESSION or value is not valid\n");
1797 lst_print_usage(argv[0]);
1801 rc = lst_del_group(argv[1]);
1807 lst_update_group_ioctl(int opc, char *name, int clean, int count,
1808 struct lnet_process_id *ids, struct list_head *resultp)
1810 struct lstio_group_update_args args = { 0 };
1812 args.lstio_grp_key = session_key;
1813 args.lstio_grp_opc = opc;
1814 args.lstio_grp_args = clean;
1815 args.lstio_grp_nmlen = strlen(name);
1816 args.lstio_grp_namep = name;
1817 args.lstio_grp_count = count;
1818 args.lstio_grp_idsp = ids;
1819 args.lstio_grp_resultp = resultp;
1821 return lst_ioctl(LSTIO_GROUP_UPDATE, &args, sizeof(args));
1825 jt_lst_update_group(int argc, char **argv)
1827 struct list_head head;
1828 struct lnet_process_id *ids = NULL;
1838 static const struct option update_group_opts[] = {
1839 { .name = "refresh", .has_arg = no_argument, .val = 'f' },
1840 { .name = "clean", .has_arg = required_argument, .val = 'c' },
1841 { .name = "remove", .has_arg = required_argument, .val = 'r' },
1844 if (session_key == 0) {
1846 "Can't find env LST_SESSION or value is not valid\n");
1851 c = getopt_long(argc, argv, "fc:r:",
1852 update_group_opts, &optidx);
1854 /* Detect the end of the options. */
1861 lst_print_usage(argv[0]);
1864 opc = LST_GROUP_REFRESH;
1869 lst_print_usage(argv[0]);
1872 opc = LST_GROUP_RMND;
1877 clean = lst_node_str2state(optarg);
1878 if (opc != 0 || clean <= 0) {
1879 lst_print_usage(argv[0]);
1882 opc = LST_GROUP_CLEAN;
1886 lst_print_usage(argv[0]);
1891 /* no OPC or group is specified */
1892 if (opc == 0 || optind != argc - 1) {
1893 lst_print_usage(argv[0]);
1899 INIT_LIST_HEAD(&head);
1901 if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
1902 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
1904 opc == LST_GROUP_RMND ? str : grp,
1908 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
1909 opc == LST_GROUP_RMND ? str : grp,
1914 rc = lst_alloc_rpcent(&head, count, 0);
1916 fprintf(stderr, "Out of memory\n");
1923 rc = lst_update_group_ioctl(opc, grp, clean, count, ids, &head);
1929 lst_free_rpcent(&head);
1934 lst_free_rpcent(&head);
1935 lst_print_error("group", "Failed to update group: %s\n",
1940 lst_print_transerr(&head, "Updating group");
1942 lst_free_rpcent(&head);
1948 lst_list_group_ioctl(int len, char *name, int idx)
1950 struct lstio_group_list_args args = { 0 };
1952 args.lstio_grp_key = session_key;
1953 args.lstio_grp_idx = idx;
1954 args.lstio_grp_nmlen = len;
1955 args.lstio_grp_namep = name;
1957 return lst_ioctl(LSTIO_GROUP_LIST, &args, sizeof(args));
1961 lst_info_group_ioctl(char *name, struct lstcon_ndlist_ent *gent,
1962 int *idx, int *count, struct lstcon_node_ent *dents)
1964 struct lstio_group_info_args args = { 0 };
1966 args.lstio_grp_key = session_key;
1967 args.lstio_grp_nmlen = strlen(name);
1968 args.lstio_grp_namep = name;
1969 args.lstio_grp_entp = gent;
1970 args.lstio_grp_idxp = idx;
1971 args.lstio_grp_ndentp = count;
1972 args.lstio_grp_dentsp = dents;
1974 return lst_ioctl(LSTIO_GROUP_INFO, &args, sizeof(args));
1978 lst_list_group_all(void)
1980 char name[LST_NAME_SIZE];
1984 /* no group is specified, list name of all groups */
1985 for (i = 0; ; i++) {
1986 rc = lst_list_group_ioctl(LST_NAME_SIZE, name, i);
1988 fprintf(stdout, "%d) %s\n", i + 1, name);
1992 if (errno == ENOENT)
1995 lst_print_error("group", "Failed to list group: %s\n",
2000 fprintf(stdout, "Total %d groups\n", i);
2006 jt_lst_list_group(int argc, char **argv)
2008 struct lstcon_ndlist_ent gent;
2009 struct lstcon_node_ent *dents;
2024 static const struct option list_group_opts[] = {
2025 { .name = "active", .has_arg = no_argument, .val = 'a' },
2026 { .name = "busy", .has_arg = no_argument, .val = 'b' },
2027 { .name = "down", .has_arg = no_argument, .val = 'd' },
2028 { .name = "unknown", .has_arg = no_argument, .val = 'u' },
2029 { .name = "all", .has_arg = no_argument, .val = 'l' },
2030 { .name = NULL, } };
2032 if (session_key == 0) {
2034 "Can't find env LST_SESSION or value is not valid\n");
2039 c = getopt_long(argc, argv, "abdul",
2040 list_group_opts, &optidx);
2047 verbose = active = 1;
2048 states |= LST_NODE_ACTIVE;
2053 states |= LST_NODE_BUSY;
2058 states |= LST_NODE_DOWN;
2062 verbose = unknown = 1;
2063 states |= LST_NODE_UNKNOWN;
2067 states |= LST_NODE_ACTIVE | LST_NODE_BUSY |
2068 LST_NODE_DOWN | LST_NODE_UNKNOWN;
2072 lst_print_usage(argv[0]);
2077 if (optind == argc) {
2078 rc = lst_yaml_groups(NLM_F_DUMP, NULL, 0, true);
2080 if (rc == -EOPNOTSUPP)
2085 for (i = optind; i < argc; i++) {
2086 rc = lst_yaml_groups(NLM_F_DUMP, argv[i], states,
2087 i == optind ? true : false);
2089 if (rc == -EOPNOTSUPP)
2097 if (optind == argc) {
2098 /* no group is specified, list name of all groups */
2099 rc = lst_list_group_all();
2105 fprintf(stdout, LST_NODES_TITLE);
2107 /* list nodes in specified groups */
2108 for (i = optind; i < argc; i++) {
2109 rc = lst_info_group_ioctl(argv[i], &gent, NULL, NULL, NULL);
2111 if (errno == ENOENT) {
2116 lst_print_error("group", "Failed to list group\n",
2122 fprintf(stdout, "\t%d\t%d\t%d\t%d\t%d\t%s\n",
2123 gent.nle_nactive, gent.nle_nbusy,
2124 gent.nle_ndown, gent.nle_nunknown,
2125 gent.nle_nnode, argv[i]);
2129 fprintf(stdout, "Group [ %s ]\n", argv[i]);
2131 if (gent.nle_nnode == 0) {
2132 fprintf(stdout, "No nodes found [ %s ]\n", argv[i]);
2136 count = gent.nle_nnode;
2138 dents = malloc(count * sizeof(struct lstcon_node_ent));
2139 if (dents == NULL) {
2140 fprintf(stderr, "Failed to malloc: %s\n",
2146 rc = lst_info_group_ioctl(argv[i], &gent, &index, &count, dents);
2148 lst_print_error("group", "Failed to list group: %s\n",
2154 for (j = 0, c = 0; j < count; j++) {
2156 ((active && dents[j].nde_state == LST_NODE_ACTIVE) ||
2157 (busy && dents[j].nde_state == LST_NODE_BUSY) ||
2158 (down && dents[j].nde_state == LST_NODE_DOWN) ||
2159 (unknown && dents[j].nde_state == LST_NODE_UNKNOWN))) {
2161 fprintf(stdout, "\t%s: %s\n",
2162 libcfs_id2str(dents[j].nde_id),
2163 lst_node_state2str(dents[j].nde_state));
2168 fprintf(stdout, "Total %d nodes [ %s ]\n", c, argv[i]);
2177 lst_stat_ioctl(char *name, int count, struct lnet_process_id *idsp,
2178 int timeout, struct list_head *resultp)
2180 struct lstio_stat_args args = { 0 };
2182 args.lstio_sta_key = session_key;
2183 args.lstio_sta_timeout = timeout;
2184 args.lstio_sta_nmlen = strlen(name);
2185 args.lstio_sta_namep = name;
2186 args.lstio_sta_count = count;
2187 args.lstio_sta_idsp = idsp;
2188 args.lstio_sta_resultp = resultp;
2190 return lst_ioctl(LSTIO_STAT_QUERY, &args, sizeof(args));
2194 struct list_head srp_link;
2197 struct lnet_process_id *srp_ids;
2198 struct list_head srp_result[2];
2199 } lst_stat_req_param_t;
2202 lst_stat_req_param_free(lst_stat_req_param_t *srp)
2206 for (i = 0; i < 2; i++)
2207 lst_free_rpcent(&srp->srp_result[i]);
2209 if (srp->srp_ids != NULL)
2216 lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
2218 lst_stat_req_param_t *srp = NULL;
2219 int count = save_old ? 2 : 1;
2223 srp = malloc(sizeof(*srp));
2227 memset(srp, 0, sizeof(*srp));
2228 INIT_LIST_HEAD(&srp->srp_result[0]);
2229 INIT_LIST_HEAD(&srp->srp_result[1]);
2231 rc = lst_get_node_count(LST_OPC_GROUP, name,
2232 &srp->srp_count, NULL);
2233 if (rc != 0 && errno == ENOENT) {
2234 rc = lst_get_node_count(LST_OPC_NODES, name,
2235 &srp->srp_count, &srp->srp_ids);
2240 "Failed to get count of nodes from %s: %s\n",
2241 name, strerror(errno));
2242 lst_stat_req_param_free(srp);
2247 srp->srp_name = name;
2249 for (i = 0; i < count; i++) {
2250 rc = lst_alloc_rpcent(&srp->srp_result[i], srp->srp_count,
2251 sizeof(struct sfw_counters) +
2252 sizeof(struct srpc_counters) +
2253 sizeof(struct lnet_counters_common));
2255 fprintf(stderr, "Out of memory\n");
2265 lst_stat_req_param_free(srp);
2273 } lst_srpc_stat_result;
2275 #define LST_LNET_AVG 0
2276 #define LST_LNET_MIN 1
2277 #define LST_LNET_MAX 2
2280 float lnet_avg_sndrate;
2281 float lnet_min_sndrate;
2282 float lnet_max_sndrate;
2283 float lnet_total_sndrate;
2285 float lnet_avg_rcvrate;
2286 float lnet_min_rcvrate;
2287 float lnet_max_rcvrate;
2288 float lnet_total_rcvrate;
2290 float lnet_avg_sndperf;
2291 float lnet_min_sndperf;
2292 float lnet_max_sndperf;
2293 float lnet_total_sndperf;
2295 float lnet_avg_rcvperf;
2296 float lnet_min_rcvperf;
2297 float lnet_max_rcvperf;
2298 float lnet_total_rcvperf;
2300 int lnet_stat_count;
2301 } lst_lnet_stat_result_t;
2303 lst_lnet_stat_result_t lnet_stat_result;
2306 lst_lnet_stat_value(int bw, int send, int off)
2310 p = bw ? &lnet_stat_result.lnet_avg_sndperf :
2311 &lnet_stat_result.lnet_avg_sndrate;
2322 lst_cal_lnet_stat(float delta, struct lnet_counters_common *lnet_new,
2323 struct lnet_counters_common *lnet_old, int mbs)
2327 unsigned int unit_divisor;
2329 unit_divisor = (mbs) ? (1000 * 1000) : (1024 * 1024);
2330 perf = (float)(lnet_new->lcc_send_length -
2331 lnet_old->lcc_send_length) / unit_divisor / delta;
2332 lnet_stat_result.lnet_total_sndperf += perf;
2334 if (lnet_stat_result.lnet_min_sndperf > perf ||
2335 lnet_stat_result.lnet_min_sndperf == 0)
2336 lnet_stat_result.lnet_min_sndperf = perf;
2338 if (lnet_stat_result.lnet_max_sndperf < perf)
2339 lnet_stat_result.lnet_max_sndperf = perf;
2341 perf = (float)(lnet_new->lcc_recv_length -
2342 lnet_old->lcc_recv_length) / unit_divisor / delta;
2343 lnet_stat_result.lnet_total_rcvperf += perf;
2345 if (lnet_stat_result.lnet_min_rcvperf > perf ||
2346 lnet_stat_result.lnet_min_rcvperf == 0)
2347 lnet_stat_result.lnet_min_rcvperf = perf;
2349 if (lnet_stat_result.lnet_max_rcvperf < perf)
2350 lnet_stat_result.lnet_max_rcvperf = perf;
2352 rate = (lnet_new->lcc_send_count - lnet_old->lcc_send_count) / delta;
2353 lnet_stat_result.lnet_total_sndrate += rate;
2355 if (lnet_stat_result.lnet_min_sndrate > rate ||
2356 lnet_stat_result.lnet_min_sndrate == 0)
2357 lnet_stat_result.lnet_min_sndrate = rate;
2359 if (lnet_stat_result.lnet_max_sndrate < rate)
2360 lnet_stat_result.lnet_max_sndrate = rate;
2362 rate = (lnet_new->lcc_recv_count - lnet_old->lcc_recv_count) / delta;
2363 lnet_stat_result.lnet_total_rcvrate += rate;
2365 if (lnet_stat_result.lnet_min_rcvrate > rate ||
2366 lnet_stat_result.lnet_min_rcvrate == 0)
2367 lnet_stat_result.lnet_min_rcvrate = rate;
2369 if (lnet_stat_result.lnet_max_rcvrate < rate)
2370 lnet_stat_result.lnet_max_rcvrate = rate;
2372 lnet_stat_result.lnet_stat_count++;
2374 lnet_stat_result.lnet_avg_sndrate = lnet_stat_result.lnet_total_sndrate /
2375 lnet_stat_result.lnet_stat_count;
2376 lnet_stat_result.lnet_avg_rcvrate = lnet_stat_result.lnet_total_rcvrate /
2377 lnet_stat_result.lnet_stat_count;
2379 lnet_stat_result.lnet_avg_sndperf = lnet_stat_result.lnet_total_sndperf /
2380 lnet_stat_result.lnet_stat_count;
2381 lnet_stat_result.lnet_avg_rcvperf = lnet_stat_result.lnet_total_rcvperf /
2382 lnet_stat_result.lnet_stat_count;
2386 lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type, int mbs)
2396 if (lnet_stat_result.lnet_stat_count == 0)
2399 units = (mbs) ? "MB/s " : "MiB/s ";
2401 if (bwrt == 1) /* bw only */
2404 if (bwrt == 2) /* rates only */
2407 if (rdwr == 1) /* recv only */
2410 if (rdwr == 2) /* send only */
2413 for (i = start1; i <= end1; i++) {
2414 fprintf(stdout, "[LNet %s of %s]\n",
2415 i == 0 ? "Rates" : "Bandwidth", name);
2417 for (j = start2; j <= end2; j++) {
2418 fprintf(stdout, "[%c] ", j == 0 ? 'R' : 'W');
2420 if ((type & 1) != 0) {
2421 fprintf(stdout, i == 0 ? "Avg: %-8.0f RPC/s " :
2423 lst_lnet_stat_value(i, j, 0), units);
2426 if ((type & 2) != 0) {
2427 fprintf(stdout, i == 0 ? "Min: %-8.0f RPC/s " :
2429 lst_lnet_stat_value(i, j, 1), units);
2432 if ((type & 4) != 0) {
2433 fprintf(stdout, i == 0 ? "Max: %-8.0f RPC/s" :
2435 lst_lnet_stat_value(i, j, 2), units);
2438 fprintf(stdout, "\n");
2444 lst_print_stat(char *name, struct list_head *resultp,
2445 int idx, int lnet, int bwrt, int rdwr, int type,
2448 struct list_head tmp[2];
2449 struct lstcon_rpc_ent *new;
2450 struct lstcon_rpc_ent *old;
2451 struct sfw_counters *sfwk_new;
2452 struct sfw_counters *sfwk_old;
2453 struct srpc_counters *srpc_new;
2454 struct srpc_counters *srpc_old;
2455 struct lnet_counters_common *lnet_new;
2456 struct lnet_counters_common *lnet_old;
2460 INIT_LIST_HEAD(&tmp[0]);
2461 INIT_LIST_HEAD(&tmp[1]);
2463 memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
2465 while (!list_empty(&resultp[idx])) {
2466 if (list_empty(&resultp[1 - idx])) {
2467 fprintf(stderr, "Group is changed, re-run stat\n");
2471 new = list_entry(resultp[idx].next, struct lstcon_rpc_ent,
2473 old = list_entry(resultp[1 - idx].next, struct lstcon_rpc_ent,
2476 /* first time get stats result, can't calculate diff */
2477 if (new->rpe_peer.nid == LNET_NID_ANY)
2480 if (new->rpe_peer.nid != old->rpe_peer.nid ||
2481 new->rpe_peer.pid != old->rpe_peer.pid) {
2482 /* Something wrong. i.e, somebody change the group */
2486 list_move_tail(&new->rpe_link, &tmp[idx]);
2488 list_move_tail(&old->rpe_link, &tmp[1 - idx]);
2490 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
2491 old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
2496 sfwk_new = (struct sfw_counters *)&new->rpe_payload[0];
2497 sfwk_old = (struct sfw_counters *)&old->rpe_payload[0];
2499 srpc_new = (struct srpc_counters *)((char *)sfwk_new +
2501 srpc_old = (struct srpc_counters *)((char *)sfwk_old +
2504 lnet_new = (struct lnet_counters_common *)((char *)srpc_new +
2506 lnet_old = (struct lnet_counters_common *)((char *)srpc_old +
2509 /* Prior to version 2.3, the running_ms was a counter for
2510 * the number of running tests. Since 2.3, running_ms is
2511 * changed to hold the millisecond since the start of
2512 * the work item. The rpe_stamp field was formerly used,
2513 * but is no longer. In 2.12 rpe_stamp was changed to
2514 * struct timespec64 and has nanosecond resolution, in
2515 * case it is needed in the future.
2517 delta = (float)(sfwk_new->running_ms -
2518 sfwk_old->running_ms) / 1000;
2520 if (!lnet) /* TODO */
2523 lst_cal_lnet_stat(delta, lnet_new, lnet_old, mbs);
2526 list_splice(&tmp[idx], &resultp[idx]);
2527 list_splice(&tmp[1 - idx], &resultp[1 - idx]);
2530 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
2532 if (!lnet) /* TODO */
2535 lst_print_lnet_stat(name, bwrt, rdwr, type, mbs);
2539 jt_lst_stat(int argc, char **argv)
2541 struct list_head head;
2542 lst_stat_req_param_t *srp;
2545 int timeout = 5; /* default timeout, 5 sec */
2546 int delay = 5; /* default delay, 5 sec */
2547 int count = -1; /* run forever */
2548 int lnet = 1; /* lnet stat by default */
2555 int mbs = 0; /* report as MB/s */
2557 static const struct option stat_opts[] = {
2558 { .name = "timeout", .has_arg = required_argument, .val = 't' },
2559 { .name = "delay", .has_arg = required_argument, .val = 'd' },
2560 { .name = "count", .has_arg = required_argument, .val = 'o' },
2561 { .name = "lnet", .has_arg = no_argument, .val = 'l' },
2562 { .name = "rpc", .has_arg = no_argument, .val = 'c' },
2563 { .name = "bw", .has_arg = no_argument, .val = 'b' },
2564 { .name = "rate", .has_arg = no_argument, .val = 'a' },
2565 { .name = "read", .has_arg = no_argument, .val = 'r' },
2566 { .name = "write", .has_arg = no_argument, .val = 'w' },
2567 { .name = "avg", .has_arg = no_argument, .val = 'g' },
2568 { .name = "min", .has_arg = no_argument, .val = 'n' },
2569 { .name = "max", .has_arg = no_argument, .val = 'x' },
2570 { .name = "mbs", .has_arg = no_argument, .val = 'm' },
2573 if (session_key == 0) {
2575 "Can't find env LST_SESSION or value is not valid\n");
2580 c = getopt_long(argc, argv, "t:d:lcbarwgnxm", stat_opts,
2588 timeout = atoi(optarg);
2591 delay = atoi(optarg);
2594 count = atoi(optarg);
2640 lst_print_usage(argv[0]);
2645 if (optind == argc) {
2646 lst_print_usage(argv[0]);
2650 if (timeout <= 0 || delay <= 0) {
2651 fprintf(stderr, "Invalid timeout or delay value\n");
2656 fprintf(stderr, "Invalid count value\n");
2660 /* extra count to get first data point */
2664 INIT_LIST_HEAD(&head);
2666 while (optind < argc) {
2667 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
2671 list_add_tail(&srp->srp_link, &head);
2675 time_t now = time(NULL);
2677 if (now - last < delay) {
2678 sleep(delay - now + last);
2683 list_for_each_entry(srp, &head, srp_link) {
2684 rc = lst_stat_ioctl(srp->srp_name,
2685 srp->srp_count, srp->srp_ids,
2686 timeout, &srp->srp_result[idx]);
2688 lst_print_error("stat", "Failed to stat %s: %s\n",
2689 srp->srp_name, strerror(errno));
2693 lst_print_stat(srp->srp_name, srp->srp_result,
2694 idx, lnet, bwrt, rdwr, type, mbs);
2696 lst_reset_rpcent(&srp->srp_result[1 - idx]);
2703 } while (count == -1 || count > 0);
2706 while (!list_empty(&head)) {
2707 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2709 list_del(&srp->srp_link);
2710 lst_stat_req_param_free(srp);
2717 jt_lst_show_error(int argc, char **argv)
2719 struct list_head head;
2720 lst_stat_req_param_t *srp;
2721 struct lstcon_rpc_ent *ent;
2722 struct sfw_counters *sfwk;
2723 struct srpc_counters *srpc;
2730 static const struct option show_error_opts[] = {
2731 { .name = "session", .has_arg = no_argument, .val = 's' },
2732 { .name = NULL, } };
2734 if (session_key == 0) {
2736 "Can't find env LST_SESSION or value is not valid\n");
2741 c = getopt_long(argc, argv, "s", show_error_opts, &optidx);
2752 lst_print_usage(argv[0]);
2757 if (optind == argc) {
2758 lst_print_usage(argv[0]);
2762 INIT_LIST_HEAD(&head);
2764 while (optind < argc) {
2765 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
2769 list_add_tail(&srp->srp_link, &head);
2772 list_for_each_entry(srp, &head, srp_link) {
2773 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
2774 srp->srp_ids, 10, &srp->srp_result[0]);
2777 lst_print_error(srp->srp_name, "Failed to show errors of %s: %s\n",
2778 srp->srp_name, strerror(errno));
2782 fprintf(stdout, "%s:\n", srp->srp_name);
2786 list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
2787 if (ent->rpe_rpc_errno != 0) {
2789 fprintf(stderr, "RPC failure, can't show error on %s\n",
2790 libcfs_id2str(ent->rpe_peer));
2794 if (ent->rpe_fwk_errno != 0) {
2796 fprintf(stderr, "Framework failure, can't show error on %s\n",
2797 libcfs_id2str(ent->rpe_peer));
2801 sfwk = (struct sfw_counters *)&ent->rpe_payload[0];
2802 srpc = (struct srpc_counters *)((char *)sfwk + sizeof(*sfwk));
2804 if (srpc->errors == 0 &&
2805 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2809 sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
2814 fprintf(stderr, "%s: [Session %d brw errors, %d ping errors]%c",
2815 libcfs_id2str(ent->rpe_peer),
2816 sfwk->brw_errors, sfwk->ping_errors,
2817 show_rpc ? ' ' : '\n');
2822 fprintf(stderr, "[RPC: %d errors, %d dropped, %d expired]\n",
2823 srpc->errors, srpc->rpcs_dropped, srpc->rpcs_expired);
2826 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
2829 while (!list_empty(&head)) {
2830 srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
2832 list_del(&srp->srp_link);
2833 lst_stat_req_param_free(srp);
2840 lst_add_batch_ioctl(char *name)
2842 struct lstio_batch_add_args args = { 0 };
2844 args.lstio_bat_key = session_key;
2845 args.lstio_bat_nmlen = strlen(name);
2846 args.lstio_bat_namep = name;
2848 return lst_ioctl (LSTIO_BATCH_ADD, &args, sizeof(args));
2852 jt_lst_add_batch(int argc, char **argv)
2857 if (session_key == 0) {
2859 "Can't find env LST_SESSION or value is not valid\n");
2864 lst_print_usage(argv[0]);
2869 if (strlen(name) >= LST_NAME_SIZE) {
2870 fprintf(stderr, "Name length is limited to %d\n",
2875 rc = lst_add_batch_ioctl(name);
2879 lst_print_error("batch", "Failed to create batch: %s\n",
2886 lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp)
2888 struct lstio_batch_run_args args = { 0 };
2890 args.lstio_bat_key = session_key;
2891 args.lstio_bat_timeout = timeout;
2892 args.lstio_bat_nmlen = strlen(name);
2893 args.lstio_bat_namep = name;
2894 args.lstio_bat_resultp = resultp;
2896 return lst_ioctl(LSTIO_BATCH_START, &args, sizeof(args));
2900 jt_lst_start_batch(int argc, char **argv)
2902 struct list_head head;
2910 static const struct option start_batch_opts[] = {
2911 { .name = "timeout", .has_arg = required_argument, .val = 't' },
2914 if (session_key == 0) {
2916 "Can't find env LST_SESSION or value is not valid\n");
2921 c = getopt_long(argc, argv, "t:",
2922 start_batch_opts, &optidx);
2924 /* Detect the end of the options. */
2930 timeout = atoi(optarg);
2933 lst_print_usage(argv[0]);
2938 if (optind == argc) {
2939 batch = LST_DEFAULT_BATCH;
2941 } else if (optind == argc - 1) {
2942 batch = argv[optind];
2945 lst_print_usage(argv[0]);
2949 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
2951 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
2952 batch, strerror(errno));
2956 INIT_LIST_HEAD(&head);
2958 rc = lst_alloc_rpcent(&head, count, 0);
2960 fprintf(stderr, "Out of memory\n");
2964 rc = lst_start_batch_ioctl(batch, timeout, &head);
2967 fprintf(stdout, "%s is running now\n", batch);
2968 lst_free_rpcent(&head);
2973 lst_print_error("batch", "Failed to start batch: %s\n",
2975 lst_free_rpcent(&head);
2979 lst_print_transerr(&head, "Run batch");
2981 lst_free_rpcent(&head);
2987 lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
2989 struct lstio_batch_stop_args args = { 0 };
2991 args.lstio_bat_key = session_key;
2992 args.lstio_bat_force = force;
2993 args.lstio_bat_nmlen = strlen(name);
2994 args.lstio_bat_namep = name;
2995 args.lstio_bat_resultp = resultp;
2997 return lst_ioctl(LSTIO_BATCH_STOP, &args, sizeof(args));
3001 jt_lst_stop_batch(int argc, char **argv)
3003 struct list_head head;
3011 static const struct option stop_batch_opts[] = {
3012 { .name = "force", .has_arg = no_argument, .val = 'f' },
3015 if (session_key == 0) {
3017 "Can't find env LST_SESSION or value is not valid\n");
3022 c = getopt_long(argc, argv, "f",
3023 stop_batch_opts, &optidx);
3025 /* Detect the end of the options. */
3034 lst_print_usage(argv[0]);
3039 if (optind == argc) {
3040 batch = LST_DEFAULT_BATCH;
3042 } else if (optind == argc - 1) {
3043 batch = argv[optind];
3046 lst_print_usage(argv[0]);
3050 rc = lst_get_node_count(LST_OPC_BATCHCLI, batch, &count, NULL);
3052 fprintf(stderr, "Failed to get count of nodes from %s: %s\n",
3053 batch, strerror(errno));
3057 INIT_LIST_HEAD(&head);
3059 rc = lst_alloc_rpcent(&head, count, 0);
3061 fprintf(stderr, "Out of memory\n");
3065 rc = lst_stop_batch_ioctl(batch, force, &head);
3070 lst_reset_rpcent(&head);
3072 rc = lst_query_batch_ioctl(batch, 0, 0, 30, &head);
3076 if (lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
3077 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0)
3080 fprintf(stdout, "%d batch in stopping\n",
3081 lstcon_tsbqry_stat_run(&trans_stat, 0));
3085 fprintf(stdout, "Batch is stopped\n");
3086 lst_free_rpcent(&head);
3091 lst_print_error("batch", "Failed to stop batch: %s\n",
3093 lst_free_rpcent(&head);
3097 lst_print_transerr(&head, "stop batch");
3099 lst_free_rpcent(&head);
3105 lst_list_batch_ioctl(int len, char *name, int index)
3107 struct lstio_batch_list_args args = { 0 };
3109 args.lstio_bat_key = session_key;
3110 args.lstio_bat_idx = index;
3111 args.lstio_bat_nmlen = len;
3112 args.lstio_bat_namep = name;
3114 return lst_ioctl(LSTIO_BATCH_LIST, &args, sizeof(args));
3118 lst_info_batch_ioctl(char *batch, int test, int server,
3119 struct lstcon_test_batch_ent *entp, int *idxp,
3120 int *ndentp, struct lstcon_node_ent *dentsp)
3122 struct lstio_batch_info_args args = { 0 };
3124 args.lstio_bat_key = session_key;
3125 args.lstio_bat_nmlen = strlen(batch);
3126 args.lstio_bat_namep = batch;
3127 args.lstio_bat_server = server;
3128 args.lstio_bat_testidx = test;
3129 args.lstio_bat_entp = entp;
3130 args.lstio_bat_idxp = idxp;
3131 args.lstio_bat_ndentp = ndentp;
3132 args.lstio_bat_dentsp = dentsp;
3134 return lst_ioctl(LSTIO_BATCH_INFO, &args, sizeof(args));
3138 lst_list_batch_all(void)
3140 char name[LST_NAME_SIZE];
3144 for (i = 0; ; i++) {
3145 rc = lst_list_batch_ioctl(LST_NAME_SIZE, name, i);
3147 fprintf(stdout, "%d) %s\n", i + 1, name);
3151 if (errno == ENOENT)
3154 lst_print_error("batch", "Failed to list batch: %s\n",
3159 fprintf(stdout, "Total %d batches\n", i);
3165 lst_list_tsb_nodes(char *batch, int test, int server,
3166 int count, int active, int invalid)
3168 struct lstcon_node_ent *dents;
3177 /* verbose list, show nodes in batch or test */
3178 dents = malloc(count * sizeof(struct lstcon_node_ent));
3179 if (dents == NULL) {
3180 fprintf(stdout, "Can't allocate memory\n");
3184 rc = lst_info_batch_ioctl(batch, test, server,
3185 NULL, &index, &count, dents);
3188 lst_print_error((test > 0) ? "test" : "batch",
3189 (test > 0) ? "Failed to query test: %s\n" :
3190 "Failed to query batch: %s\n",
3195 for (i = 0, c = 0; i < count; i++) {
3196 if ((!active && dents[i].nde_state == LST_NODE_ACTIVE) ||
3197 (!invalid && (dents[i].nde_state == LST_NODE_BUSY ||
3198 dents[i].nde_state == LST_NODE_DOWN ||
3199 dents[i].nde_state == LST_NODE_UNKNOWN)))
3202 fprintf(stdout, "\t%s: %s\n",
3203 libcfs_id2str(dents[i].nde_id),
3204 lst_node_state2str(dents[i].nde_state));
3208 fprintf(stdout, "Total %d nodes\n", c);
3215 jt_lst_list_batch(int argc, char **argv)
3217 struct lstcon_test_batch_ent ent;
3220 int verbose = 0; /* list nodes in batch or test */
3229 static const struct option list_batch_opts[] = {
3230 { .name = "test", .has_arg = required_argument, .val = 't' },
3231 { .name = "invalid", .has_arg = no_argument, .val = 'i' },
3232 { .name = "active", .has_arg = no_argument, .val = 'a' },
3233 { .name = "all", .has_arg = no_argument, .val = 'l' },
3234 { .name = "server", .has_arg = no_argument, .val = 's' },
3235 { .name = NULL, } };
3237 if (session_key == 0) {
3239 "Can't find env LST_SESSION or value is not valid\n");
3244 c = getopt_long(argc, argv, "ailst:",
3245 list_batch_opts, &optidx);
3252 verbose = active = 1;
3255 verbose = invalid = 1;
3258 verbose = active = invalid = 1;
3264 test = atoi(optarg);
3268 lst_print_usage(argv[0]);
3273 if (optind == argc) {
3274 /* list all batches */
3275 rc = lst_list_batch_all();
3279 if (ntest == 1 && test <= 0) {
3280 fprintf(stderr, "Invalid test id, test id starts from 1\n");
3284 if (optind != argc - 1) {
3285 lst_print_usage(argv[0]);
3289 batch = argv[optind];
3292 /* show detail of specified batch or test */
3293 rc = lst_info_batch_ioctl(batch, test, server,
3294 &ent, NULL, NULL, NULL);
3296 lst_print_error((test > 0) ? "test" : "batch",
3297 (test > 0) ? "Failed to query test: %s\n" :
3298 "Failed to query batch: %s\n",
3304 /* list nodes in test or batch */
3305 rc = lst_list_tsb_nodes(batch, test, server,
3306 server ? ent.tbe_srv_nle.nle_nnode :
3307 ent.tbe_cli_nle.nle_nnode,
3312 /* only show number of hosts in batch or test */
3314 fprintf(stdout, "Batch: %s Tests: %d State: %d\n",
3315 batch, ent.u.tbe_batch.bae_ntest,
3316 ent.u.tbe_batch.bae_state);
3317 ntest = ent.u.tbe_batch.bae_ntest;
3318 test = 1; /* starting from test 1 */
3322 "\tTest %d(%s) (loop: %d, concurrency: %d)\n",
3323 test, lst_test_type2name(ent.u.tbe_test.tse_type),
3324 ent.u.tbe_test.tse_loop,
3325 ent.u.tbe_test.tse_concur);
3330 fprintf(stdout, LST_NODES_TITLE);
3331 fprintf(stdout, "client\t%d\t%d\t%d\t%d\t%d\n"
3332 "server\t%d\t%d\t%d\t%d\t%d\n",
3333 ent.tbe_cli_nle.nle_nactive,
3334 ent.tbe_cli_nle.nle_nbusy,
3335 ent.tbe_cli_nle.nle_ndown,
3336 ent.tbe_cli_nle.nle_nunknown,
3337 ent.tbe_cli_nle.nle_nnode,
3338 ent.tbe_srv_nle.nle_nactive,
3339 ent.tbe_srv_nle.nle_nbusy,
3340 ent.tbe_srv_nle.nle_ndown,
3341 ent.tbe_srv_nle.nle_nunknown,
3342 ent.tbe_srv_nle.nle_nnode);
3351 lst_query_batch_ioctl(char *batch, int test, int server,
3352 int timeout, struct list_head *head)
3354 struct lstio_batch_query_args args = { 0 };
3356 args.lstio_bat_key = session_key;
3357 args.lstio_bat_testidx = test;
3358 args.lstio_bat_client = !(server);
3359 args.lstio_bat_timeout = timeout;
3360 args.lstio_bat_nmlen = strlen(batch);
3361 args.lstio_bat_namep = batch;
3362 args.lstio_bat_resultp = head;
3364 return lst_ioctl(LSTIO_BATCH_QUERY, &args, sizeof(args));
3368 lst_print_tsb_verbose(struct list_head *head,
3369 int active, int idle, int error)
3371 struct lstcon_rpc_ent *ent;
3373 list_for_each_entry(ent, head, rpe_link) {
3374 if (ent->rpe_priv[0] == 0 && active)
3377 if (ent->rpe_priv[0] != 0 && idle)
3380 if (ent->rpe_fwk_errno == 0 && error)
3383 fprintf(stdout, "%s [%s]: %s\n",
3384 libcfs_id2str(ent->rpe_peer),
3385 lst_node_state2str(ent->rpe_state),
3386 ent->rpe_rpc_errno != 0 ?
3387 strerror(ent->rpe_rpc_errno) :
3388 (ent->rpe_priv[0] > 0 ? "Running" : "Idle"));
3393 jt_lst_query_batch(int argc, char **argv)
3395 struct lstcon_test_batch_ent ent;
3396 struct list_head head;
3402 int timeout = 5; /* default 5 seconds */
3403 int delay = 5; /* default 5 seconds */
3404 int loop = 1; /* default 1 loop */
3414 static const struct option query_batch_opts[] = {
3415 { .name = "timeout", .has_arg = required_argument, .val = 'o' },
3416 { .name = "delay", .has_arg = required_argument, .val = 'd' },
3417 { .name = "loop", .has_arg = required_argument, .val = 'c' },
3418 { .name = "test", .has_arg = required_argument, .val = 't' },
3419 { .name = "server", .has_arg = no_argument, .val = 's' },
3420 { .name = "active", .has_arg = no_argument, .val = 'a' },
3421 { .name = "idle", .has_arg = no_argument, .val = 'i' },
3422 { .name = "error", .has_arg = no_argument, .val = 'e' },
3423 { .name = "all", .has_arg = no_argument, .val = 'l' },
3424 { .name = NULL, } };
3426 if (session_key == 0) {
3428 "Can't find env LST_SESSION or value is not valid\n");
3433 c = getopt_long(argc, argv, "o:d:c:t:saiel",
3434 query_batch_opts, &optidx);
3436 /* Detect the end of the options. */
3442 timeout = atoi(optarg);
3445 delay = atoi(optarg);
3448 loop = atoi(optarg);
3451 test = atoi(optarg);
3457 active = verbose = 1;
3463 error = verbose = 1;
3469 lst_print_usage(argv[0]);
3474 if (test < 0 || timeout <= 0 || delay <= 0 || loop <= 0) {
3475 lst_print_usage(argv[0]);
3479 if (optind == argc) {
3480 batch = LST_DEFAULT_BATCH;
3482 } else if (optind == argc - 1) {
3483 batch = argv[optind];
3486 lst_print_usage(argv[0]);
3491 INIT_LIST_HEAD(&head);
3494 rc = lst_info_batch_ioctl(batch, test, server,
3495 &ent, NULL, NULL, NULL);
3497 fprintf(stderr, "Failed to query %s [%d]: %s\n",
3498 batch, test, strerror(errno));
3502 count = server ? ent.tbe_srv_nle.nle_nnode :
3503 ent.tbe_cli_nle.nle_nnode;
3505 fprintf(stdout, "Batch or test is empty\n");
3510 rc = lst_alloc_rpcent(&head, count, 0);
3512 fprintf(stderr, "Out of memory\n");
3516 for (i = 0; i < loop; i++) {
3517 time_t now = time(NULL);
3519 if (now - last < delay) {
3520 sleep(delay - now + last);
3526 rc = lst_query_batch_ioctl(batch, test,
3527 server, timeout, &head);
3529 fprintf(stderr, "Failed to query batch: %s\n",
3536 lst_print_tsb_verbose(&head, active, idle, error);
3540 fprintf(stdout, "%s [%d] ", batch, test);
3542 if (lstcon_rpc_stat_failure(&trans_stat, 0) != 0) {
3543 fprintf(stdout, "%d of %d nodes are unknown, ",
3544 lstcon_rpc_stat_failure(&trans_stat, 0),
3545 lstcon_rpc_stat_total(&trans_stat, 0));
3548 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
3549 lstcon_tsbqry_stat_run(&trans_stat, 0) == 0 &&
3550 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
3551 fprintf(stdout, "is stopped\n");
3555 if (lstcon_rpc_stat_failure(&trans_stat, 0) == 0 &&
3556 lstcon_tsbqry_stat_idle(&trans_stat, 0) == 0 &&
3557 lstcon_tsbqry_stat_failure(&trans_stat, 0) == 0) {
3558 fprintf(stdout, "is running\n");
3562 fprintf(stdout, "stopped: %d , running: %d, failed: %d\n",
3563 lstcon_tsbqry_stat_idle(&trans_stat, 0),
3564 lstcon_tsbqry_stat_run(&trans_stat, 0),
3565 lstcon_tsbqry_stat_failure(&trans_stat, 0));
3568 lst_free_rpcent(&head);
3574 lst_parse_distribute(char *dstr, int *dist, int *span)
3580 dstr = strchr(dstr, ':');
3584 *span = atoi(dstr + 1);
3592 lst_get_bulk_param(int argc, char **argv, struct lst_test_bulk_param *bulk)
3599 bulk->blk_size = 4096;
3600 bulk->blk_opc = LST_BRW_READ;
3601 bulk->blk_flags = LST_BRW_CHECK_NONE;
3602 bulk->blk_srv_off = bulk->blk_cli_off = 0;
3605 if (strcasestr(argv[i], "check=") == argv[i] ||
3606 strcasestr(argv[i], "c=") == argv[i]) {
3607 tok = strchr(argv[i], '=') + 1;
3609 if (strcasecmp(tok, "full") == 0) {
3610 bulk->blk_flags = LST_BRW_CHECK_FULL;
3611 } else if (strcasecmp(tok, "simple") == 0) {
3612 bulk->blk_flags = LST_BRW_CHECK_SIMPLE;
3614 fprintf(stderr, "Unknow flag %s\n", tok);
3618 } else if (strcasestr(argv[i], "size=") == argv[i] ||
3619 strcasestr(argv[i], "s=") == argv[i]) {
3620 tok = strchr(argv[i], '=') + 1;
3622 bulk->blk_size = strtol(tok, &end, 0);
3623 if (bulk->blk_size <= 0) {
3624 fprintf(stderr, "Invalid size %s\n", tok);
3631 if (*end == 'k' || *end == 'K')
3632 bulk->blk_size *= 1024;
3633 else if (*end == 'm' || *end == 'M')
3634 bulk->blk_size *= 1024 * 1024;
3636 if (bulk->blk_size > LNET_MTU) {
3637 fprintf(stderr, "Size exceed limitation: %d bytes\n",
3642 } else if (strcasestr(argv[i], "off=") == argv[i]) {
3645 tok = strchr(argv[i], '=') + 1;
3647 off = strtol(tok, &end, 0);
3648 /* NB: align with sizeof(__u64) to simplify page
3649 * checking implementation */
3650 if (off < 0 || off % sizeof(__u64) != 0) {
3652 "Invalid offset %s/%d, it should be "
3653 "postive value and multiple of %d\n",
3654 tok, off, (int)sizeof(__u64));
3658 /* NB: blk_srv_off is reserved so far */
3659 bulk->blk_cli_off = bulk->blk_srv_off = off;
3663 } else if (strcasecmp(argv[i], "read") == 0 ||
3664 strcasecmp(argv[i], "r") == 0) {
3665 bulk->blk_opc = LST_BRW_READ;
3667 } else if (strcasecmp(argv[i], "write") == 0 ||
3668 strcasecmp(argv[i], "w") == 0) {
3669 bulk->blk_opc = LST_BRW_WRITE;
3672 fprintf(stderr, "Unknow parameter: %s\n", argv[i]);
3683 lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
3685 struct lst_test_bulk_param *bulk = NULL;
3686 struct lst_test_ping_param *ping = NULL;
3689 type = lst_test_name2type(test);
3691 fprintf(stderr, "Unknow test name %s\n", test);
3697 /* unused but needs for kernel part */
3698 ping = malloc(sizeof(*ping));
3700 fprintf(stderr, "Out of memory\n");
3703 memset(ping, 0, sizeof(*ping));
3706 *plen = sizeof(*ping);
3711 bulk = malloc(sizeof(*bulk));
3713 fprintf(stderr, "Out of memory\n");
3717 memset(bulk, 0, sizeof(*bulk));
3719 if (lst_get_bulk_param(argc, argv, bulk) != 0) {
3725 *plen = sizeof(*bulk);
3733 /* TODO: parse more parameter */
3738 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
3739 int dist, int span, char *sgrp, char *dgrp,
3740 void *param, int plen, int *retp, struct list_head *resultp)
3742 struct lstio_test_args args = { 0 };
3744 args.lstio_tes_key = session_key;
3745 args.lstio_tes_bat_nmlen = strlen(batch);
3746 args.lstio_tes_bat_name = batch;
3747 args.lstio_tes_type = type;
3748 args.lstio_tes_oneside = 0;
3749 args.lstio_tes_loop = loop;
3750 args.lstio_tes_concur = concur;
3751 args.lstio_tes_dist = dist;
3752 args.lstio_tes_span = span;
3753 args.lstio_tes_sgrp_nmlen = strlen(sgrp);
3754 args.lstio_tes_sgrp_name = sgrp;
3755 args.lstio_tes_dgrp_nmlen = strlen(dgrp);
3756 args.lstio_tes_dgrp_name = dgrp;
3757 args.lstio_tes_param_len = plen;
3758 args.lstio_tes_param = param;
3759 args.lstio_tes_retp = retp;
3760 args.lstio_tes_resultp = resultp;
3762 return lst_ioctl(LSTIO_TEST_ADD, &args, sizeof(args));
3766 jt_lst_add_test(int argc, char **argv)
3768 struct list_head head;
3788 static const struct option add_test_opts[] = {
3789 { .name = "batch", .has_arg = required_argument, .val = 'b' },
3790 { .name = "concurrency", .has_arg = required_argument, .val = 'c' },
3791 { .name = "distribute", .has_arg = required_argument, .val = 'd' },
3792 { .name = "from", .has_arg = required_argument, .val = 'f' },
3793 { .name = "to", .has_arg = required_argument, .val = 't' },
3794 { .name = "loop", .has_arg = required_argument, .val = 'l' },
3797 if (session_key == 0) {
3799 "Can't find env LST_SESSION or value is not valid\n");
3804 c = getopt_long(argc, argv, "b:c:d:f:l:t:",
3805 add_test_opts, &optidx);
3807 /* Detect the end of the options. */
3816 concur = atoi(optarg);
3825 loop = atoi(optarg);
3831 lst_print_usage(argv[0]);
3836 if (optind == argc || from == NULL || to == NULL) {
3837 lst_print_usage(argv[0]);
3841 if (concur <= 0 || concur > LST_MAX_CONCUR) {
3842 fprintf(stderr, "Invalid concurrency of test: %d\n", concur);
3847 batch = LST_DEFAULT_BATCH;
3850 rc = lst_parse_distribute(dstr, &dist, &span);
3852 fprintf(stderr, "Invalid distribution: %s\n", dstr);
3857 test = argv[optind++];
3862 type = lst_get_test_param(test, argc, argv, ¶m, &plen);
3864 fprintf(stderr, "Failed to add test (%s)\n", test);
3868 INIT_LIST_HEAD(&head);
3870 rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
3872 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3873 from, strerror(errno));
3877 rc = lst_get_node_count(LST_OPC_GROUP, to, &tcount, NULL);
3879 fprintf(stderr, "Can't get count of nodes from %s: %s\n",
3880 to, strerror(errno));
3884 rc = lst_alloc_rpcent(&head, fcount > tcount ? fcount : tcount, 0);
3886 fprintf(stderr, "Out of memory\n");
3890 rc = lst_add_test_ioctl(batch, type, loop, concur,
3891 dist, span, from, to, param, plen, &ret, &head);
3894 fprintf(stdout, "Test was added successfully\n");
3896 fprintf(stdout, "Server group contains userland test "
3897 "nodes, old version of tcplnd can't accept "
3898 "connection request\n");
3905 lst_print_error("test", "Failed to add test: %s\n",
3910 lst_print_transerr(&head, "add test");
3912 lst_free_rpcent(&head);
3920 static command_t lst_cmdlist[] = {
3921 {"new_session", jt_lst_new_session, NULL,
3922 "Usage: lst new_session [--timeout TIME] [--force] [NAME]" },
3923 {"end_session", jt_lst_end_session, NULL,
3924 "Usage: lst end_session" },
3925 {"show_session", jt_lst_show_session, NULL,
3926 "Usage: lst show_session" },
3927 {"ping", jt_lst_ping , NULL,
3928 "Usage: lst ping [--group NAME] [--batch NAME] [--session] [--nodes IDS]" },
3929 {"add_group", jt_lst_add_group, NULL,
3930 "Usage: lst group NAME IDs [IDs]..." },
3931 {"del_group", jt_lst_del_group, NULL,
3932 "Usage: lst del_group NAME" },
3933 {"update_group", jt_lst_update_group, NULL,
3934 "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]" },
3935 {"list_group", jt_lst_list_group, NULL,
3936 "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..." },
3937 {"stat", jt_lst_stat, NULL,
3938 "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
3939 " [--mbs] [--timeout #] [--delay #] [--count #] GROUP [GROUP]" },
3940 {"show_error", jt_lst_show_error, NULL,
3941 "Usage: lst show_error NAME | IDS ..." },
3942 {"add_batch", jt_lst_add_batch, NULL,
3943 "Usage: lst add_batch NAME" },
3944 {"run", jt_lst_start_batch, NULL,
3945 "Usage: lst run [--timeout TIME] [NAME]" },
3946 {"stop", jt_lst_stop_batch, NULL,
3947 "Usage: lst stop [--force] BATCH_NAME" },
3948 {"list_batch", jt_lst_list_batch, NULL,
3949 "Usage: lst list_batch NAME [--test ID] [--server]" },
3950 {"query", jt_lst_query_batch, NULL,
3951 "Usage: lst query [--test ID] [--server] [--timeout TIME] NAME" },
3952 {"add_test", jt_lst_add_test, NULL,
3953 "Usage: lst add_test [--batch BATCH] [--loop #] [--concurrency #] "
3954 " [--distribute #:#] [--from GROUP] [--to GROUP] TEST..." },
3955 {"help", Parser_help, 0, "help" },
3956 {"--list-commands", lst_list_commands, 0, "list commands" },
3961 lst_initialize(void)
3966 feats = getenv("LST_FEATURES");
3968 session_features = strtol(feats, NULL, 16);
3970 if ((session_features & ~LST_FEATS_MASK) != 0) {
3972 "Unsupported session features %x, "
3973 "only support these features so far: %x\n",
3974 (session_features & ~LST_FEATS_MASK), LST_FEATS_MASK);
3978 key = getenv("LST_SESSION");
3985 session_key = atoi(key);
3990 static int lst_list_commands(int argc, char **argv)
3992 char buffer[81] = ""; /* 80 printable chars + terminating NUL */
3994 Parser_list_commands(lst_cmdlist, buffer, sizeof(buffer), NULL, 0, 4);
4000 main(int argc, char **argv)
4006 rc = lst_initialize();
4010 rc = lustre_lnet_config_lib_init();
4014 Parser_init("lst > ", lst_cmdlist);
4017 rc = Parser_execarg(argc - 1, argv + 1, lst_cmdlist);