4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/selftest/conctl.c
38 * Infrastructure of LST console
40 * Author: Liang Zhen <liangzhen@clusterfs.com>
44 #include "../../include/linux/libcfs/libcfs.h"
45 #include "../../include/linux/lnet/lib-lnet.h"
49 #define LST_NODE_STATE_COUNTER(nd, p) \
51 if ((nd)->nd_state == LST_NODE_ACTIVE) \
52 (p)->nle_nactive ++; \
53 else if ((nd)->nd_state == LST_NODE_BUSY) \
55 else if ((nd)->nd_state == LST_NODE_DOWN) \
58 (p)->nle_nunknown ++; \
62 lstcon_session_t console_session;
65 lstcon_node_get(lstcon_node_t *nd)
67 LASSERT (nd->nd_ref >= 1);
73 lstcon_node_find(lnet_process_id_t id, lstcon_node_t **ndpp, int create)
76 unsigned int idx = LNET_NIDADDR(id.nid) % LST_GLOBAL_HASHSIZE;
78 LASSERT (id.nid != LNET_NID_ANY);
80 list_for_each_entry(ndl, &console_session.ses_ndl_hash[idx], ndl_hlink) {
81 if (ndl->ndl_node->nd_id.nid != id.nid ||
82 ndl->ndl_node->nd_id.pid != id.pid)
85 lstcon_node_get(ndl->ndl_node);
86 *ndpp = ndl->ndl_node;
93 LIBCFS_ALLOC(*ndpp, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
97 ndl = (lstcon_ndlink_t *)(*ndpp + 1);
99 ndl->ndl_node = *ndpp;
101 ndl->ndl_node->nd_ref = 1;
102 ndl->ndl_node->nd_id = id;
103 ndl->ndl_node->nd_stamp = cfs_time_current();
104 ndl->ndl_node->nd_state = LST_NODE_UNKNOWN;
105 ndl->ndl_node->nd_timeout = 0;
106 memset(&ndl->ndl_node->nd_ping, 0, sizeof(lstcon_rpc_t));
108 /* queued in global hash & list, no refcount is taken by
109 * global hash & list, if caller release his refcount,
110 * node will be released */
111 list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
112 list_add_tail(&ndl->ndl_link, &console_session.ses_ndl_list);
118 lstcon_node_put(lstcon_node_t *nd)
120 lstcon_ndlink_t *ndl;
122 LASSERT (nd->nd_ref > 0);
124 if (--nd->nd_ref > 0)
127 ndl = (lstcon_ndlink_t *)(nd + 1);
129 LASSERT (!list_empty(&ndl->ndl_link));
130 LASSERT (!list_empty(&ndl->ndl_hlink));
132 /* remove from session */
133 list_del(&ndl->ndl_link);
134 list_del(&ndl->ndl_hlink);
136 LIBCFS_FREE(nd, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
140 lstcon_ndlink_find(struct list_head *hash,
141 lnet_process_id_t id, lstcon_ndlink_t **ndlpp, int create)
143 unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
144 lstcon_ndlink_t *ndl;
148 if (id.nid == LNET_NID_ANY)
152 list_for_each_entry(ndl, &hash[idx], ndl_hlink) {
153 if (ndl->ndl_node->nd_id.nid != id.nid ||
154 ndl->ndl_node->nd_id.pid != id.pid)
164 /* find or create in session hash */
165 rc = lstcon_node_find(id, &nd, (create == 1) ? 1 : 0);
169 LIBCFS_ALLOC(ndl, sizeof(lstcon_ndlink_t));
178 INIT_LIST_HEAD(&ndl->ndl_link);
179 list_add_tail(&ndl->ndl_hlink, &hash[idx]);
185 lstcon_ndlink_release(lstcon_ndlink_t *ndl)
187 LASSERT (list_empty(&ndl->ndl_link));
188 LASSERT (!list_empty(&ndl->ndl_hlink));
190 list_del(&ndl->ndl_hlink); /* delete from hash */
191 lstcon_node_put(ndl->ndl_node);
193 LIBCFS_FREE(ndl, sizeof(*ndl));
197 lstcon_group_alloc(char *name, lstcon_group_t **grpp)
202 LIBCFS_ALLOC(grp, offsetof(lstcon_group_t,
203 grp_ndl_hash[LST_NODE_HASHSIZE]));
209 strcpy(grp->grp_name, name);
211 INIT_LIST_HEAD(&grp->grp_link);
212 INIT_LIST_HEAD(&grp->grp_ndl_list);
213 INIT_LIST_HEAD(&grp->grp_trans_list);
215 for (i = 0; i < LST_NODE_HASHSIZE; i++)
216 INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
224 lstcon_group_addref(lstcon_group_t *grp)
229 static void lstcon_group_ndlink_release(lstcon_group_t *, lstcon_ndlink_t *);
232 lstcon_group_drain(lstcon_group_t *grp, int keep)
234 lstcon_ndlink_t *ndl;
235 lstcon_ndlink_t *tmp;
237 list_for_each_entry_safe(ndl, tmp, &grp->grp_ndl_list, ndl_link) {
238 if ((ndl->ndl_node->nd_state & keep) == 0)
239 lstcon_group_ndlink_release(grp, ndl);
244 lstcon_group_decref(lstcon_group_t *grp)
248 if (--grp->grp_ref > 0)
251 if (!list_empty(&grp->grp_link))
252 list_del(&grp->grp_link);
254 lstcon_group_drain(grp, 0);
256 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
257 LASSERT (list_empty(&grp->grp_ndl_hash[i]));
260 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
261 grp_ndl_hash[LST_NODE_HASHSIZE]));
265 lstcon_group_find(const char *name, lstcon_group_t **grpp)
269 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
270 if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
273 lstcon_group_addref(grp); /* +1 ref for caller */
282 lstcon_group_put(lstcon_group_t *grp)
284 lstcon_group_decref(grp);
288 lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id,
289 lstcon_ndlink_t **ndlpp, int create)
293 rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
297 if (!list_empty(&(*ndlpp)->ndl_link))
300 list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
307 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
309 list_del_init(&ndl->ndl_link);
310 lstcon_ndlink_release(ndl);
315 lstcon_group_ndlink_move(lstcon_group_t *old,
316 lstcon_group_t *new, lstcon_ndlink_t *ndl)
318 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
321 list_del(&ndl->ndl_hlink);
322 list_del(&ndl->ndl_link);
325 list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
326 list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
333 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
335 lstcon_ndlink_t *ndl;
337 while (!list_empty(&old->grp_ndl_list)) {
338 ndl = list_entry(old->grp_ndl_list.next,
339 lstcon_ndlink_t, ndl_link);
340 lstcon_group_ndlink_move(old, new, ndl);
345 lstcon_sesrpc_condition(int transop, lstcon_node_t *nd, void *arg)
347 lstcon_group_t *grp = (lstcon_group_t *)arg;
350 case LST_TRANS_SESNEW:
351 if (nd->nd_state == LST_NODE_ACTIVE)
355 case LST_TRANS_SESEND:
356 if (nd->nd_state != LST_NODE_ACTIVE)
359 if (grp != NULL && nd->nd_ref > 1)
363 case LST_TRANS_SESQRY:
374 lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
375 lstcon_rpc_ent_t *ent_up)
377 srpc_debug_reply_t *rep;
380 case LST_TRANS_SESNEW:
381 case LST_TRANS_SESEND:
384 case LST_TRANS_SESQRY:
385 rep = &msg->msg_body.dbg_reply;
387 if (copy_to_user(&ent_up->rpe_priv[0],
388 &rep->dbg_timeout, sizeof(int)) ||
389 copy_to_user(&ent_up->rpe_payload[0],
390 &rep->dbg_name, LST_NAME_SIZE))
403 lstcon_group_nodes_add(lstcon_group_t *grp,
404 int count, lnet_process_id_t *ids_up,
405 unsigned *featp, struct list_head *result_up)
407 lstcon_rpc_trans_t *trans;
408 lstcon_ndlink_t *ndl;
410 lnet_process_id_t id;
414 rc = lstcon_group_alloc(NULL, &tmp);
416 CERROR("Out of memory\n");
420 for (i = 0 ; i < count; i++) {
421 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
426 /* skip if it's in this group already */
427 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
431 /* add to tmp group */
432 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
434 CERROR("Can't create ndlink, out of memory\n");
440 lstcon_group_put(tmp);
444 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
445 &tmp->grp_trans_list, LST_TRANS_SESNEW,
446 tmp, lstcon_sesrpc_condition, &trans);
448 CERROR("Can't create transaction: %d\n", rc);
449 lstcon_group_put(tmp);
454 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
456 rc = lstcon_rpc_trans_interpreter(trans, result_up,
457 lstcon_sesrpc_readent);
458 *featp = trans->tas_features;
460 /* destroy all RPGs */
461 lstcon_rpc_trans_destroy(trans);
463 lstcon_group_move(tmp, grp);
464 lstcon_group_put(tmp);
470 lstcon_group_nodes_remove(lstcon_group_t *grp,
471 int count, lnet_process_id_t *ids_up,
472 struct list_head *result_up)
474 lstcon_rpc_trans_t *trans;
475 lstcon_ndlink_t *ndl;
477 lnet_process_id_t id;
481 /* End session and remove node from the group */
483 rc = lstcon_group_alloc(NULL, &tmp);
485 CERROR("Out of memory\n");
489 for (i = 0; i < count; i++) {
490 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
495 /* move node to tmp group */
496 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
497 lstcon_group_ndlink_move(grp, tmp, ndl);
500 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
501 &tmp->grp_trans_list, LST_TRANS_SESEND,
502 tmp, lstcon_sesrpc_condition, &trans);
504 CERROR("Can't create transaction: %d\n", rc);
508 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
510 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
512 lstcon_rpc_trans_destroy(trans);
513 /* release nodes anyway, because we can't rollback status */
514 lstcon_group_put(tmp);
518 lstcon_group_move(tmp, grp);
519 lstcon_group_put(tmp);
525 lstcon_group_add(char *name)
530 rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
532 /* find a group with same name */
533 lstcon_group_put(grp);
537 rc = lstcon_group_alloc(name, &grp);
539 CERROR("Can't allocate descriptor for group %s\n", name);
543 list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
549 lstcon_nodes_add(char *name, int count, lnet_process_id_t *ids_up,
550 unsigned *featp, struct list_head *result_up)
556 LASSERT (ids_up != NULL);
558 rc = lstcon_group_find(name, &grp);
560 CDEBUG(D_NET, "Can't find group %s\n", name);
564 if (grp->grp_ref > 2) {
565 /* referred by other threads or test */
566 CDEBUG(D_NET, "Group %s is busy\n", name);
567 lstcon_group_put(grp);
572 rc = lstcon_group_nodes_add(grp, count, ids_up, featp, result_up);
574 lstcon_group_put(grp);
580 lstcon_group_del(char *name)
582 lstcon_rpc_trans_t *trans;
586 rc = lstcon_group_find(name, &grp);
588 CDEBUG(D_NET, "Can't find group: %s\n", name);
592 if (grp->grp_ref > 2) {
593 /* referred by others threads or test */
594 CDEBUG(D_NET, "Group %s is busy\n", name);
595 lstcon_group_put(grp);
599 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
600 &grp->grp_trans_list, LST_TRANS_SESEND,
601 grp, lstcon_sesrpc_condition, &trans);
603 CERROR("Can't create transaction: %d\n", rc);
604 lstcon_group_put(grp);
608 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
610 lstcon_rpc_trans_destroy(trans);
612 lstcon_group_put(grp);
613 /* -ref for session, it's destroyed,
614 * status can't be rolled back, destroy group anyway */
615 lstcon_group_put(grp);
621 lstcon_group_clean(char *name, int args)
623 lstcon_group_t *grp = NULL;
626 rc = lstcon_group_find(name, &grp);
628 CDEBUG(D_NET, "Can't find group %s\n", name);
632 if (grp->grp_ref > 2) {
633 /* referred by test */
634 CDEBUG(D_NET, "Group %s is busy\n", name);
635 lstcon_group_put(grp);
639 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
640 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
642 lstcon_group_drain(grp, args);
644 lstcon_group_put(grp);
645 /* release empty group */
646 if (list_empty(&grp->grp_ndl_list))
647 lstcon_group_put(grp);
653 lstcon_nodes_remove(char *name, int count,
654 lnet_process_id_t *ids_up, struct list_head *result_up)
656 lstcon_group_t *grp = NULL;
659 rc = lstcon_group_find(name, &grp);
661 CDEBUG(D_NET, "Can't find group: %s\n", name);
665 if (grp->grp_ref > 2) {
666 /* referred by test */
667 CDEBUG(D_NET, "Group %s is busy\n", name);
668 lstcon_group_put(grp);
672 rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
674 lstcon_group_put(grp);
675 /* release empty group */
676 if (list_empty(&grp->grp_ndl_list))
677 lstcon_group_put(grp);
683 lstcon_group_refresh(char *name, struct list_head *result_up)
685 lstcon_rpc_trans_t *trans;
689 rc = lstcon_group_find(name, &grp);
691 CDEBUG(D_NET, "Can't find group: %s\n", name);
695 if (grp->grp_ref > 2) {
696 /* referred by test */
697 CDEBUG(D_NET, "Group %s is busy\n", name);
698 lstcon_group_put(grp);
702 /* re-invite all inactive nodes int the group */
703 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
704 &grp->grp_trans_list, LST_TRANS_SESNEW,
705 grp, lstcon_sesrpc_condition, &trans);
707 /* local error, return */
708 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
709 lstcon_group_put(grp);
713 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
715 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
717 lstcon_rpc_trans_destroy(trans);
719 lstcon_group_put(grp);
725 lstcon_group_list(int index, int len, char *name_up)
729 LASSERT (index >= 0);
730 LASSERT (name_up != NULL);
732 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
734 return copy_to_user(name_up, grp->grp_name, len) ?
743 lstcon_nodes_getent(struct list_head *head, int *index_p,
744 int *count_p, lstcon_node_ent_t *dents_up)
746 lstcon_ndlink_t *ndl;
751 LASSERT (index_p != NULL && count_p != NULL);
752 LASSERT (dents_up != NULL);
753 LASSERT (*index_p >= 0);
754 LASSERT (*count_p > 0);
756 list_for_each_entry(ndl, head, ndl_link) {
757 if (index++ < *index_p)
760 if (count >= *count_p)
764 if (copy_to_user(&dents_up[count].nde_id,
765 &nd->nd_id, sizeof(nd->nd_id)) ||
766 copy_to_user(&dents_up[count].nde_state,
767 &nd->nd_state, sizeof(nd->nd_state)))
773 if (index <= *index_p)
783 lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p,
784 int *index_p, int *count_p, lstcon_node_ent_t *dents_up)
786 lstcon_ndlist_ent_t *gentp;
788 lstcon_ndlink_t *ndl;
791 rc = lstcon_group_find(name, &grp);
793 CDEBUG(D_NET, "Can't find group %s\n", name);
799 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
800 index_p, count_p, dents_up);
801 lstcon_group_put(grp);
806 /* non-verbose query */
807 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
809 CERROR("Can't allocate ndlist_ent\n");
810 lstcon_group_put(grp);
815 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link)
816 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
818 rc = copy_to_user(gents_p, gentp,
819 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT: 0;
821 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
823 lstcon_group_put(grp);
829 lstcon_batch_find(const char *name, lstcon_batch_t **batpp)
833 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
834 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
844 lstcon_batch_add(char *name)
850 rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
852 CDEBUG(D_NET, "Batch %s already exists\n", name);
856 LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
858 CERROR("Can't allocate descriptor for batch %s\n", name);
862 LIBCFS_ALLOC(bat->bat_cli_hash,
863 sizeof(struct list_head) * LST_NODE_HASHSIZE);
864 if (bat->bat_cli_hash == NULL) {
865 CERROR("Can't allocate hash for batch %s\n", name);
866 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
871 LIBCFS_ALLOC(bat->bat_srv_hash,
872 sizeof(struct list_head) * LST_NODE_HASHSIZE);
873 if (bat->bat_srv_hash == NULL) {
874 CERROR("Can't allocate hash for batch %s\n", name);
875 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
876 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
881 strcpy(bat->bat_name, name);
882 bat->bat_hdr.tsb_index = 0;
883 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
886 bat->bat_state = LST_BATCH_IDLE;
888 INIT_LIST_HEAD(&bat->bat_cli_list);
889 INIT_LIST_HEAD(&bat->bat_srv_list);
890 INIT_LIST_HEAD(&bat->bat_test_list);
891 INIT_LIST_HEAD(&bat->bat_trans_list);
893 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
894 INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
895 INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
898 list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
904 lstcon_batch_list(int index, int len, char *name_up)
908 LASSERT (name_up != NULL);
909 LASSERT (index >= 0);
911 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
913 return copy_to_user(name_up, bat->bat_name, len) ?
922 lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
923 int testidx, int *index_p, int *ndent_p,
924 lstcon_node_ent_t *dents_up)
926 lstcon_test_batch_ent_t *entp;
927 struct list_head *clilst;
928 struct list_head *srvlst;
929 lstcon_test_t *test = NULL;
931 lstcon_ndlink_t *ndl;
934 rc = lstcon_batch_find(name, &bat);
936 CDEBUG(D_NET, "Can't find batch %s\n", name);
941 /* query test, test index start from 1 */
942 list_for_each_entry(test, &bat->bat_test_list, tes_link) {
948 CDEBUG(D_NET, "Can't find specified test in batch\n");
953 clilst = (test == NULL) ? &bat->bat_cli_list :
954 &test->tes_src_grp->grp_ndl_list;
955 srvlst = (test == NULL) ? &bat->bat_srv_list :
956 &test->tes_dst_grp->grp_ndl_list;
958 if (dents_up != NULL) {
959 rc = lstcon_nodes_getent((server ? srvlst: clilst),
960 index_p, ndent_p, dents_up);
964 /* non-verbose query */
965 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
970 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
971 entp->u.tbe_batch.bae_state = bat->bat_state;
975 entp->u.tbe_test.tse_type = test->tes_type;
976 entp->u.tbe_test.tse_loop = test->tes_loop;
977 entp->u.tbe_test.tse_concur = test->tes_concur;
980 list_for_each_entry(ndl, clilst, ndl_link)
981 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
983 list_for_each_entry(ndl, srvlst, ndl_link)
984 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
986 rc = copy_to_user(ent_up, entp,
987 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
989 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
995 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
998 case LST_TRANS_TSBRUN:
999 if (nd->nd_state != LST_NODE_ACTIVE)
1003 case LST_TRANS_TSBSTOP:
1004 if (nd->nd_state != LST_NODE_ACTIVE)
1008 case LST_TRANS_TSBCLIQRY:
1009 case LST_TRANS_TSBSRVQRY:
1017 lstcon_batch_op(lstcon_batch_t *bat, int transop,
1018 struct list_head *result_up)
1020 lstcon_rpc_trans_t *trans;
1023 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1024 &bat->bat_trans_list, transop,
1025 bat, lstcon_batrpc_condition, &trans);
1027 CERROR("Can't create transaction: %d\n", rc);
1031 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1033 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1035 lstcon_rpc_trans_destroy(trans);
1041 lstcon_batch_run(char *name, int timeout, struct list_head *result_up)
1043 lstcon_batch_t *bat;
1046 if (lstcon_batch_find(name, &bat) != 0) {
1047 CDEBUG(D_NET, "Can't find batch %s\n", name);
1051 bat->bat_arg = timeout;
1053 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1055 /* mark batch as running if it's started in any node */
1056 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1057 bat->bat_state = LST_BATCH_RUNNING;
1063 lstcon_batch_stop(char *name, int force, struct list_head *result_up)
1065 lstcon_batch_t *bat;
1068 if (lstcon_batch_find(name, &bat) != 0) {
1069 CDEBUG(D_NET, "Can't find batch %s\n", name);
1073 bat->bat_arg = force;
1075 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1077 /* mark batch as stopped if all RPCs finished */
1078 if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1079 bat->bat_state = LST_BATCH_IDLE;
1085 lstcon_batch_destroy(lstcon_batch_t *bat)
1087 lstcon_ndlink_t *ndl;
1088 lstcon_test_t *test;
1091 list_del(&bat->bat_link);
1093 while (!list_empty(&bat->bat_test_list)) {
1094 test = list_entry(bat->bat_test_list.next,
1095 lstcon_test_t, tes_link);
1096 LASSERT (list_empty(&test->tes_trans_list));
1098 list_del(&test->tes_link);
1100 lstcon_group_put(test->tes_src_grp);
1101 lstcon_group_put(test->tes_dst_grp);
1103 LIBCFS_FREE(test, offsetof(lstcon_test_t,
1104 tes_param[test->tes_paramlen]));
1107 LASSERT (list_empty(&bat->bat_trans_list));
1109 while (!list_empty(&bat->bat_cli_list)) {
1110 ndl = list_entry(bat->bat_cli_list.next,
1111 lstcon_ndlink_t, ndl_link);
1112 list_del_init(&ndl->ndl_link);
1114 lstcon_ndlink_release(ndl);
1117 while (!list_empty(&bat->bat_srv_list)) {
1118 ndl = list_entry(bat->bat_srv_list.next,
1119 lstcon_ndlink_t, ndl_link);
1120 list_del_init(&ndl->ndl_link);
1122 lstcon_ndlink_release(ndl);
1125 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1126 LASSERT (list_empty(&bat->bat_cli_hash[i]));
1127 LASSERT (list_empty(&bat->bat_srv_hash[i]));
1130 LIBCFS_FREE(bat->bat_cli_hash,
1131 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1132 LIBCFS_FREE(bat->bat_srv_hash,
1133 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1134 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
1138 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1140 lstcon_test_t *test;
1141 lstcon_batch_t *batch;
1142 lstcon_ndlink_t *ndl;
1143 struct list_head *hash;
1144 struct list_head *head;
1146 test = (lstcon_test_t *)arg;
1147 LASSERT (test != NULL);
1149 batch = test->tes_batch;
1150 LASSERT (batch != NULL);
1152 if (test->tes_oneside &&
1153 transop == LST_TRANS_TSBSRVADD)
1156 if (nd->nd_state != LST_NODE_ACTIVE)
1159 if (transop == LST_TRANS_TSBCLIADD) {
1160 hash = batch->bat_cli_hash;
1161 head = &batch->bat_cli_list;
1164 LASSERT (transop == LST_TRANS_TSBSRVADD);
1166 hash = batch->bat_srv_hash;
1167 head = &batch->bat_srv_list;
1170 LASSERT (nd->nd_id.nid != LNET_NID_ANY);
1172 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1175 if (list_empty(&ndl->ndl_link))
1176 list_add_tail(&ndl->ndl_link, head);
1182 lstcon_test_nodes_add(lstcon_test_t *test, struct list_head *result_up)
1184 lstcon_rpc_trans_t *trans;
1185 lstcon_group_t *grp;
1189 LASSERT (test->tes_src_grp != NULL);
1190 LASSERT (test->tes_dst_grp != NULL);
1192 transop = LST_TRANS_TSBSRVADD;
1193 grp = test->tes_dst_grp;
1195 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1196 &test->tes_trans_list, transop,
1197 test, lstcon_testrpc_condition, &trans);
1199 CERROR("Can't create transaction: %d\n", rc);
1203 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1205 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1206 lstcon_trans_stat()->trs_fwk_errno != 0) {
1207 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1209 lstcon_rpc_trans_destroy(trans);
1210 /* return if any error */
1211 CDEBUG(D_NET, "Failed to add test %s, "
1212 "RPC error %d, framework error %d\n",
1213 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1214 lstcon_trans_stat()->trs_rpc_errno,
1215 lstcon_trans_stat()->trs_fwk_errno);
1220 lstcon_rpc_trans_destroy(trans);
1222 if (transop == LST_TRANS_TSBCLIADD)
1225 transop = LST_TRANS_TSBCLIADD;
1226 grp = test->tes_src_grp;
1227 test->tes_cliidx = 0;
1229 /* requests to test clients */
1234 lstcon_verify_batch(const char *name, lstcon_batch_t **batch)
1238 rc = lstcon_batch_find(name, batch);
1240 CDEBUG(D_NET, "Can't find batch %s\n", name);
1244 if ((*batch)->bat_state != LST_BATCH_IDLE) {
1245 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1253 lstcon_verify_group(const char *name, lstcon_group_t **grp)
1256 lstcon_ndlink_t *ndl;
1258 rc = lstcon_group_find(name, grp);
1260 CDEBUG(D_NET, "can't find group %s\n", name);
1264 list_for_each_entry(ndl, &(*grp)->grp_ndl_list, ndl_link) {
1265 if (ndl->ndl_node->nd_state == LST_NODE_ACTIVE)
1269 CDEBUG(D_NET, "Group %s has no ACTIVE nodes\n", name);
1275 lstcon_test_add(char *batch_name, int type, int loop,
1276 int concur, int dist, int span,
1277 char *src_name, char *dst_name,
1278 void *param, int paramlen, int *retp,
1279 struct list_head *result_up)
1281 lstcon_test_t *test = NULL;
1283 lstcon_group_t *src_grp = NULL;
1284 lstcon_group_t *dst_grp = NULL;
1285 lstcon_batch_t *batch = NULL;
1288 * verify that a batch of the given name exists, and the groups
1289 * that will be part of the batch exist and have at least one
1292 rc = lstcon_verify_batch(batch_name, &batch);
1296 rc = lstcon_verify_group(src_name, &src_grp);
1300 rc = lstcon_verify_group(dst_name, &dst_grp);
1304 if (dst_grp->grp_userland)
1307 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1309 CERROR("Can't allocate test descriptor\n");
1315 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1316 test->tes_batch = batch;
1317 test->tes_type = type;
1318 test->tes_oneside = 0; /* TODO */
1319 test->tes_loop = loop;
1320 test->tes_concur = concur;
1321 test->tes_stop_onerr = 1; /* TODO */
1322 test->tes_span = span;
1323 test->tes_dist = dist;
1324 test->tes_cliidx = 0; /* just used for creating RPC */
1325 test->tes_src_grp = src_grp;
1326 test->tes_dst_grp = dst_grp;
1327 INIT_LIST_HEAD(&test->tes_trans_list);
1329 if (param != NULL) {
1330 test->tes_paramlen = paramlen;
1331 memcpy(&test->tes_param[0], param, paramlen);
1334 rc = lstcon_test_nodes_add(test, result_up);
1339 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1340 lstcon_trans_stat()->trs_fwk_errno != 0)
1341 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type,
1344 /* add to test list anyway, so user can check what's going on */
1345 list_add_tail(&test->tes_link, &batch->bat_test_list);
1347 batch->bat_ntest ++;
1348 test->tes_hdr.tsb_index = batch->bat_ntest;
1350 /* hold groups so nobody can change them */
1354 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1356 if (dst_grp != NULL)
1357 lstcon_group_put(dst_grp);
1359 if (src_grp != NULL)
1360 lstcon_group_put(src_grp);
1366 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1368 lstcon_test_t *test;
1370 list_for_each_entry(test, &batch->bat_test_list, tes_link) {
1371 if (idx == test->tes_hdr.tsb_index) {
1381 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1382 lstcon_rpc_ent_t *ent_up)
1384 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1386 LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1387 transop == LST_TRANS_TSBSRVQRY);
1389 /* positive errno, framework error code */
1390 if (copy_to_user(&ent_up->rpe_priv[0],
1391 &rep->bar_active, sizeof(rep->bar_active)))
1398 lstcon_test_batch_query(char *name, int testidx, int client,
1399 int timeout, struct list_head *result_up)
1401 lstcon_rpc_trans_t *trans;
1402 struct list_head *translist;
1403 struct list_head *ndlist;
1404 lstcon_tsb_hdr_t *hdr;
1405 lstcon_batch_t *batch;
1406 lstcon_test_t *test = NULL;
1410 rc = lstcon_batch_find(name, &batch);
1412 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1417 translist = &batch->bat_trans_list;
1418 ndlist = &batch->bat_cli_list;
1419 hdr = &batch->bat_hdr;
1422 /* query specified test only */
1423 rc = lstcon_test_find(batch, testidx, &test);
1425 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1429 translist = &test->tes_trans_list;
1430 ndlist = &test->tes_src_grp->grp_ndl_list;
1431 hdr = &test->tes_hdr;
1434 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1436 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1437 lstcon_batrpc_condition, &trans);
1439 CERROR("Can't create transaction: %d\n", rc);
1443 lstcon_rpc_trans_postwait(trans, timeout);
1445 if (testidx == 0 && /* query a batch, not a test */
1446 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1447 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1448 /* all RPCs finished, and no active test */
1449 batch->bat_state = LST_BATCH_IDLE;
1452 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1453 lstcon_tsbrpc_readent);
1454 lstcon_rpc_trans_destroy(trans);
1460 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1461 lstcon_rpc_ent_t *ent_up)
1463 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1464 sfw_counters_t *sfwk_stat;
1465 srpc_counters_t *srpc_stat;
1466 lnet_counters_t *lnet_stat;
1468 if (rep->str_status != 0)
1471 sfwk_stat = (sfw_counters_t *)&ent_up->rpe_payload[0];
1472 srpc_stat = (srpc_counters_t *)((char *)sfwk_stat + sizeof(*sfwk_stat));
1473 lnet_stat = (lnet_counters_t *)((char *)srpc_stat + sizeof(*srpc_stat));
1475 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1476 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1477 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1484 lstcon_ndlist_stat(struct list_head *ndlist,
1485 int timeout, struct list_head *result_up)
1487 struct list_head head;
1488 lstcon_rpc_trans_t *trans;
1491 INIT_LIST_HEAD(&head);
1493 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1494 LST_TRANS_STATQRY, NULL, NULL, &trans);
1496 CERROR("Can't create transaction: %d\n", rc);
1500 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1502 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1503 lstcon_statrpc_readent);
1504 lstcon_rpc_trans_destroy(trans);
1510 lstcon_group_stat(char *grp_name, int timeout, struct list_head *result_up)
1512 lstcon_group_t *grp;
1515 rc = lstcon_group_find(grp_name, &grp);
1517 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1521 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1523 lstcon_group_put(grp);
1529 lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
1530 int timeout, struct list_head *result_up)
1532 lstcon_ndlink_t *ndl;
1533 lstcon_group_t *tmp;
1534 lnet_process_id_t id;
1538 rc = lstcon_group_alloc(NULL, &tmp);
1540 CERROR("Out of memory\n");
1544 for (i = 0 ; i < count; i++) {
1545 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1550 /* add to tmp group */
1551 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1553 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1554 "Failed to find or create %s: %d\n",
1555 libcfs_id2str(id), rc);
1561 lstcon_group_put(tmp);
1565 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1567 lstcon_group_put(tmp);
1573 lstcon_debug_ndlist(struct list_head *ndlist,
1574 struct list_head *translist,
1575 int timeout, struct list_head *result_up)
1577 lstcon_rpc_trans_t *trans;
1580 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1581 NULL, lstcon_sesrpc_condition, &trans);
1583 CERROR("Can't create transaction: %d\n", rc);
1587 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1589 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1590 lstcon_sesrpc_readent);
1591 lstcon_rpc_trans_destroy(trans);
1597 lstcon_session_debug(int timeout, struct list_head *result_up)
1599 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1600 NULL, timeout, result_up);
1604 lstcon_batch_debug(int timeout, char *name,
1605 int client, struct list_head *result_up)
1607 lstcon_batch_t *bat;
1610 rc = lstcon_batch_find(name, &bat);
1614 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1616 NULL, timeout, result_up);
1622 lstcon_group_debug(int timeout, char *name,
1623 struct list_head *result_up)
1625 lstcon_group_t *grp;
1628 rc = lstcon_group_find(name, &grp);
1632 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1633 timeout, result_up);
1634 lstcon_group_put(grp);
1640 lstcon_nodes_debug(int timeout,
1641 int count, lnet_process_id_t *ids_up,
1642 struct list_head *result_up)
1644 lnet_process_id_t id;
1645 lstcon_ndlink_t *ndl;
1646 lstcon_group_t *grp;
1650 rc = lstcon_group_alloc(NULL, &grp);
1652 CDEBUG(D_NET, "Out of memory\n");
1656 for (i = 0; i < count; i++) {
1657 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1662 /* node is added to tmp group */
1663 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1665 CERROR("Can't create node link\n");
1671 lstcon_group_put(grp);
1675 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1676 timeout, result_up);
1678 lstcon_group_put(grp);
1684 lstcon_session_match(lst_sid_t sid)
1686 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1687 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1: 0;
1691 lstcon_new_session_id(lst_sid_t *sid)
1693 lnet_process_id_t id;
1695 LASSERT (console_session.ses_state == LST_SESSION_NONE);
1698 sid->ses_nid = id.nid;
1699 sid->ses_stamp = cfs_time_current();
1702 extern srpc_service_t lstcon_acceptor_service;
1705 lstcon_session_new(char *name, int key, unsigned feats,
1706 int timeout, int force, lst_sid_t *sid_up)
1711 if (console_session.ses_state != LST_SESSION_NONE) {
1712 /* session exists */
1714 CNETERR("Session %s already exists\n",
1715 console_session.ses_name);
1719 rc = lstcon_session_end();
1721 /* lstcon_session_end() only return local error */
1726 if ((feats & ~LST_FEATS_MASK) != 0) {
1727 CNETERR("Unknown session features %x\n",
1728 (feats & ~LST_FEATS_MASK));
1732 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1733 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
1735 lstcon_new_session_id(&console_session.ses_id);
1737 console_session.ses_key = key;
1738 console_session.ses_state = LST_SESSION_ACTIVE;
1739 console_session.ses_force = !!force;
1740 console_session.ses_features = feats;
1741 console_session.ses_feats_updated = 0;
1742 console_session.ses_timeout = (timeout <= 0) ?
1743 LST_CONSOLE_TIMEOUT : timeout;
1744 strcpy(console_session.ses_name, name);
1746 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1750 rc = lstcon_rpc_pinger_start();
1752 lstcon_batch_t *bat = NULL;
1754 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1755 lstcon_batch_destroy(bat);
1760 if (copy_to_user(sid_up, &console_session.ses_id,
1761 sizeof(lst_sid_t)) == 0)
1764 lstcon_session_end();
1770 lstcon_session_info(lst_sid_t *sid_up, int *key_up, unsigned *featp,
1771 lstcon_ndlist_ent_t *ndinfo_up, char *name_up, int len)
1773 lstcon_ndlist_ent_t *entp;
1774 lstcon_ndlink_t *ndl;
1777 if (console_session.ses_state != LST_SESSION_ACTIVE)
1780 LIBCFS_ALLOC(entp, sizeof(*entp));
1784 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link)
1785 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1787 if (copy_to_user(sid_up, &console_session.ses_id,
1788 sizeof(lst_sid_t)) ||
1789 copy_to_user(key_up, &console_session.ses_key,
1791 copy_to_user(featp, &console_session.ses_features,
1793 copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1794 copy_to_user(name_up, console_session.ses_name, len))
1797 LIBCFS_FREE(entp, sizeof(*entp));
1803 lstcon_session_end(void)
1805 lstcon_rpc_trans_t *trans;
1806 lstcon_group_t *grp;
1807 lstcon_batch_t *bat;
1810 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1812 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1813 NULL, LST_TRANS_SESEND, NULL,
1814 lstcon_sesrpc_condition, &trans);
1816 CERROR("Can't create transaction: %d\n", rc);
1820 console_session.ses_shutdown = 1;
1822 lstcon_rpc_pinger_stop();
1824 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1826 lstcon_rpc_trans_destroy(trans);
1827 /* User can do nothing even rpc failed, so go on */
1829 /* waiting for orphan rpcs to die */
1830 lstcon_rpc_cleanup_wait();
1832 console_session.ses_id = LST_INVALID_SID;
1833 console_session.ses_state = LST_SESSION_NONE;
1834 console_session.ses_key = 0;
1835 console_session.ses_force = 0;
1836 console_session.ses_feats_updated = 0;
1838 /* destroy all batches */
1839 while (!list_empty(&console_session.ses_bat_list)) {
1840 bat = list_entry(console_session.ses_bat_list.next,
1841 lstcon_batch_t, bat_link);
1843 lstcon_batch_destroy(bat);
1846 /* destroy all groups */
1847 while (!list_empty(&console_session.ses_grp_list)) {
1848 grp = list_entry(console_session.ses_grp_list.next,
1849 lstcon_group_t, grp_link);
1850 LASSERT (grp->grp_ref == 1);
1852 lstcon_group_put(grp);
1855 /* all nodes should be released */
1856 LASSERT (list_empty(&console_session.ses_ndl_list));
1858 console_session.ses_shutdown = 0;
1859 console_session.ses_expired = 0;
1865 lstcon_session_feats_check(unsigned feats)
1869 if ((feats & ~LST_FEATS_MASK) != 0) {
1870 CERROR("Can't support these features: %x\n",
1871 (feats & ~LST_FEATS_MASK));
1875 spin_lock(&console_session.ses_rpc_lock);
1877 if (!console_session.ses_feats_updated) {
1878 console_session.ses_feats_updated = 1;
1879 console_session.ses_features = feats;
1882 if (console_session.ses_features != feats)
1885 spin_unlock(&console_session.ses_rpc_lock);
1888 CERROR("remote features %x do not match with "
1889 "session features %x of console\n",
1890 feats, console_session.ses_features);
1897 lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
1899 srpc_msg_t *rep = &rpc->srpc_replymsg;
1900 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1901 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1902 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1903 lstcon_group_t *grp = NULL;
1904 lstcon_ndlink_t *ndl;
1907 sfw_unpack_message(req);
1909 mutex_lock(&console_session.ses_mutex);
1911 jrep->join_sid = console_session.ses_id;
1913 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1914 jrep->join_status = ESRCH;
1918 if (lstcon_session_feats_check(req->msg_ses_feats) != 0) {
1919 jrep->join_status = EPROTO;
1923 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1924 !lstcon_session_match(jreq->join_sid)) {
1925 jrep->join_status = EBUSY;
1929 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1930 rc = lstcon_group_alloc(jreq->join_group, &grp);
1932 CERROR("Out of memory\n");
1936 list_add_tail(&grp->grp_link,
1937 &console_session.ses_grp_list);
1938 lstcon_group_addref(grp);
1941 if (grp->grp_ref > 2) {
1942 /* Group in using */
1943 jrep->join_status = EBUSY;
1947 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1949 jrep->join_status = EEXIST;
1953 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1955 CERROR("Out of memory\n");
1959 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1960 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1962 if (grp->grp_userland == 0)
1963 grp->grp_userland = 1;
1965 strcpy(jrep->join_session, console_session.ses_name);
1966 jrep->join_timeout = console_session.ses_timeout;
1967 jrep->join_status = 0;
1970 rep->msg_ses_feats = console_session.ses_features;
1972 lstcon_group_put(grp);
1974 mutex_unlock(&console_session.ses_mutex);
1979 srpc_service_t lstcon_acceptor_service;
1980 static void lstcon_init_acceptor_service(void)
1982 /* initialize selftest console acceptor service table */
1983 lstcon_acceptor_service.sv_name = "join session";
1984 lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
1985 lstcon_acceptor_service.sv_id = SRPC_SERVICE_JOIN;
1986 lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX;
1989 extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
1991 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
1993 /* initialize console */
1995 lstcon_console_init(void)
2000 memset(&console_session, 0, sizeof(lstcon_session_t));
2002 console_session.ses_id = LST_INVALID_SID;
2003 console_session.ses_state = LST_SESSION_NONE;
2004 console_session.ses_timeout = 0;
2005 console_session.ses_force = 0;
2006 console_session.ses_expired = 0;
2007 console_session.ses_feats_updated = 0;
2008 console_session.ses_features = LST_FEATS_MASK;
2009 console_session.ses_laststamp = get_seconds();
2011 mutex_init(&console_session.ses_mutex);
2013 INIT_LIST_HEAD(&console_session.ses_ndl_list);
2014 INIT_LIST_HEAD(&console_session.ses_grp_list);
2015 INIT_LIST_HEAD(&console_session.ses_bat_list);
2016 INIT_LIST_HEAD(&console_session.ses_trans_list);
2018 LIBCFS_ALLOC(console_session.ses_ndl_hash,
2019 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2020 if (console_session.ses_ndl_hash == NULL)
2023 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
2024 INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
2027 /* initialize acceptor service table */
2028 lstcon_init_acceptor_service();
2030 rc = srpc_add_service(&lstcon_acceptor_service);
2031 LASSERT (rc != -EBUSY);
2033 LIBCFS_FREE(console_session.ses_ndl_hash,
2034 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2038 rc = srpc_service_add_buffers(&lstcon_acceptor_service,
2039 lstcon_acceptor_service.sv_wi_total);
2045 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
2048 lstcon_rpc_module_init();
2053 srpc_shutdown_service(&lstcon_acceptor_service);
2054 srpc_remove_service(&lstcon_acceptor_service);
2056 LIBCFS_FREE(console_session.ses_ndl_hash,
2057 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2059 srpc_wait_service_shutdown(&lstcon_acceptor_service);
2065 lstcon_console_fini(void)
2069 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
2071 mutex_lock(&console_session.ses_mutex);
2073 srpc_shutdown_service(&lstcon_acceptor_service);
2074 srpc_remove_service(&lstcon_acceptor_service);
2076 if (console_session.ses_state != LST_SESSION_NONE)
2077 lstcon_session_end();
2079 lstcon_rpc_module_fini();
2081 mutex_unlock(&console_session.ses_mutex);
2083 LASSERT (list_empty(&console_session.ses_ndl_list));
2084 LASSERT (list_empty(&console_session.ses_grp_list));
2085 LASSERT (list_empty(&console_session.ses_bat_list));
2086 LASSERT (list_empty(&console_session.ses_trans_list));
2088 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
2089 LASSERT (list_empty(&console_session.ses_ndl_hash[i]));
2092 LIBCFS_FREE(console_session.ses_ndl_hash,
2093 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2095 srpc_wait_service_shutdown(&lstcon_acceptor_service);