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) \
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)
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);
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, RPC error %d, framework error %d\n",
1212 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1213 lstcon_trans_stat()->trs_rpc_errno,
1214 lstcon_trans_stat()->trs_fwk_errno);
1219 lstcon_rpc_trans_destroy(trans);
1221 if (transop == LST_TRANS_TSBCLIADD)
1224 transop = LST_TRANS_TSBCLIADD;
1225 grp = test->tes_src_grp;
1226 test->tes_cliidx = 0;
1228 /* requests to test clients */
1233 lstcon_verify_batch(const char *name, lstcon_batch_t **batch)
1237 rc = lstcon_batch_find(name, batch);
1239 CDEBUG(D_NET, "Can't find batch %s\n", name);
1243 if ((*batch)->bat_state != LST_BATCH_IDLE) {
1244 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1252 lstcon_verify_group(const char *name, lstcon_group_t **grp)
1255 lstcon_ndlink_t *ndl;
1257 rc = lstcon_group_find(name, grp);
1259 CDEBUG(D_NET, "can't find group %s\n", name);
1263 list_for_each_entry(ndl, &(*grp)->grp_ndl_list, ndl_link) {
1264 if (ndl->ndl_node->nd_state == LST_NODE_ACTIVE)
1268 CDEBUG(D_NET, "Group %s has no ACTIVE nodes\n", name);
1274 lstcon_test_add(char *batch_name, int type, int loop,
1275 int concur, int dist, int span,
1276 char *src_name, char *dst_name,
1277 void *param, int paramlen, int *retp,
1278 struct list_head *result_up)
1280 lstcon_test_t *test = NULL;
1282 lstcon_group_t *src_grp = NULL;
1283 lstcon_group_t *dst_grp = NULL;
1284 lstcon_batch_t *batch = NULL;
1287 * verify that a batch of the given name exists, and the groups
1288 * that will be part of the batch exist and have at least one
1291 rc = lstcon_verify_batch(batch_name, &batch);
1295 rc = lstcon_verify_group(src_name, &src_grp);
1299 rc = lstcon_verify_group(dst_name, &dst_grp);
1303 if (dst_grp->grp_userland)
1306 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1308 CERROR("Can't allocate test descriptor\n");
1314 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1315 test->tes_batch = batch;
1316 test->tes_type = type;
1317 test->tes_oneside = 0; /* TODO */
1318 test->tes_loop = loop;
1319 test->tes_concur = concur;
1320 test->tes_stop_onerr = 1; /* TODO */
1321 test->tes_span = span;
1322 test->tes_dist = dist;
1323 test->tes_cliidx = 0; /* just used for creating RPC */
1324 test->tes_src_grp = src_grp;
1325 test->tes_dst_grp = dst_grp;
1326 INIT_LIST_HEAD(&test->tes_trans_list);
1328 if (param != NULL) {
1329 test->tes_paramlen = paramlen;
1330 memcpy(&test->tes_param[0], param, paramlen);
1333 rc = lstcon_test_nodes_add(test, result_up);
1338 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1339 lstcon_trans_stat()->trs_fwk_errno != 0)
1340 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type,
1343 /* add to test list anyway, so user can check what's going on */
1344 list_add_tail(&test->tes_link, &batch->bat_test_list);
1347 test->tes_hdr.tsb_index = batch->bat_ntest;
1349 /* hold groups so nobody can change them */
1353 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1355 if (dst_grp != NULL)
1356 lstcon_group_put(dst_grp);
1358 if (src_grp != NULL)
1359 lstcon_group_put(src_grp);
1365 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1367 lstcon_test_t *test;
1369 list_for_each_entry(test, &batch->bat_test_list, tes_link) {
1370 if (idx == test->tes_hdr.tsb_index) {
1380 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1381 lstcon_rpc_ent_t *ent_up)
1383 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1385 LASSERT(transop == LST_TRANS_TSBCLIQRY ||
1386 transop == LST_TRANS_TSBSRVQRY);
1388 /* positive errno, framework error code */
1389 if (copy_to_user(&ent_up->rpe_priv[0],
1390 &rep->bar_active, sizeof(rep->bar_active)))
1397 lstcon_test_batch_query(char *name, int testidx, int client,
1398 int timeout, struct list_head *result_up)
1400 lstcon_rpc_trans_t *trans;
1401 struct list_head *translist;
1402 struct list_head *ndlist;
1403 lstcon_tsb_hdr_t *hdr;
1404 lstcon_batch_t *batch;
1405 lstcon_test_t *test = NULL;
1409 rc = lstcon_batch_find(name, &batch);
1411 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1416 translist = &batch->bat_trans_list;
1417 ndlist = &batch->bat_cli_list;
1418 hdr = &batch->bat_hdr;
1421 /* query specified test only */
1422 rc = lstcon_test_find(batch, testidx, &test);
1424 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1428 translist = &test->tes_trans_list;
1429 ndlist = &test->tes_src_grp->grp_ndl_list;
1430 hdr = &test->tes_hdr;
1433 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1435 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1436 lstcon_batrpc_condition, &trans);
1438 CERROR("Can't create transaction: %d\n", rc);
1442 lstcon_rpc_trans_postwait(trans, timeout);
1444 if (testidx == 0 && /* query a batch, not a test */
1445 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1446 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1447 /* all RPCs finished, and no active test */
1448 batch->bat_state = LST_BATCH_IDLE;
1451 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1452 lstcon_tsbrpc_readent);
1453 lstcon_rpc_trans_destroy(trans);
1459 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1460 lstcon_rpc_ent_t *ent_up)
1462 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1463 sfw_counters_t *sfwk_stat;
1464 srpc_counters_t *srpc_stat;
1465 lnet_counters_t *lnet_stat;
1467 if (rep->str_status != 0)
1470 sfwk_stat = (sfw_counters_t *)&ent_up->rpe_payload[0];
1471 srpc_stat = (srpc_counters_t *)((char *)sfwk_stat + sizeof(*sfwk_stat));
1472 lnet_stat = (lnet_counters_t *)((char *)srpc_stat + sizeof(*srpc_stat));
1474 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1475 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1476 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1483 lstcon_ndlist_stat(struct list_head *ndlist,
1484 int timeout, struct list_head *result_up)
1486 struct list_head head;
1487 lstcon_rpc_trans_t *trans;
1490 INIT_LIST_HEAD(&head);
1492 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1493 LST_TRANS_STATQRY, NULL, NULL, &trans);
1495 CERROR("Can't create transaction: %d\n", rc);
1499 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1501 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1502 lstcon_statrpc_readent);
1503 lstcon_rpc_trans_destroy(trans);
1509 lstcon_group_stat(char *grp_name, int timeout, struct list_head *result_up)
1511 lstcon_group_t *grp;
1514 rc = lstcon_group_find(grp_name, &grp);
1516 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1520 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1522 lstcon_group_put(grp);
1528 lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
1529 int timeout, struct list_head *result_up)
1531 lstcon_ndlink_t *ndl;
1532 lstcon_group_t *tmp;
1533 lnet_process_id_t id;
1537 rc = lstcon_group_alloc(NULL, &tmp);
1539 CERROR("Out of memory\n");
1543 for (i = 0 ; i < count; i++) {
1544 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1549 /* add to tmp group */
1550 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1552 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1553 "Failed to find or create %s: %d\n",
1554 libcfs_id2str(id), rc);
1560 lstcon_group_put(tmp);
1564 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1566 lstcon_group_put(tmp);
1572 lstcon_debug_ndlist(struct list_head *ndlist,
1573 struct list_head *translist,
1574 int timeout, struct list_head *result_up)
1576 lstcon_rpc_trans_t *trans;
1579 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1580 NULL, lstcon_sesrpc_condition, &trans);
1582 CERROR("Can't create transaction: %d\n", rc);
1586 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1588 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1589 lstcon_sesrpc_readent);
1590 lstcon_rpc_trans_destroy(trans);
1596 lstcon_session_debug(int timeout, struct list_head *result_up)
1598 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1599 NULL, timeout, result_up);
1603 lstcon_batch_debug(int timeout, char *name,
1604 int client, struct list_head *result_up)
1606 lstcon_batch_t *bat;
1609 rc = lstcon_batch_find(name, &bat);
1613 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1615 NULL, timeout, result_up);
1621 lstcon_group_debug(int timeout, char *name,
1622 struct list_head *result_up)
1624 lstcon_group_t *grp;
1627 rc = lstcon_group_find(name, &grp);
1631 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1632 timeout, result_up);
1633 lstcon_group_put(grp);
1639 lstcon_nodes_debug(int timeout,
1640 int count, lnet_process_id_t *ids_up,
1641 struct list_head *result_up)
1643 lnet_process_id_t id;
1644 lstcon_ndlink_t *ndl;
1645 lstcon_group_t *grp;
1649 rc = lstcon_group_alloc(NULL, &grp);
1651 CDEBUG(D_NET, "Out of memory\n");
1655 for (i = 0; i < count; i++) {
1656 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1661 /* node is added to tmp group */
1662 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1664 CERROR("Can't create node link\n");
1670 lstcon_group_put(grp);
1674 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1675 timeout, result_up);
1677 lstcon_group_put(grp);
1683 lstcon_session_match(lst_sid_t sid)
1685 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1686 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1: 0;
1690 lstcon_new_session_id(lst_sid_t *sid)
1692 lnet_process_id_t id;
1694 LASSERT(console_session.ses_state == LST_SESSION_NONE);
1697 sid->ses_nid = id.nid;
1698 sid->ses_stamp = cfs_time_current();
1701 extern srpc_service_t lstcon_acceptor_service;
1704 lstcon_session_new(char *name, int key, unsigned feats,
1705 int timeout, int force, lst_sid_t *sid_up)
1710 if (console_session.ses_state != LST_SESSION_NONE) {
1711 /* session exists */
1713 CNETERR("Session %s already exists\n",
1714 console_session.ses_name);
1718 rc = lstcon_session_end();
1720 /* lstcon_session_end() only return local error */
1725 if ((feats & ~LST_FEATS_MASK) != 0) {
1726 CNETERR("Unknown session features %x\n",
1727 (feats & ~LST_FEATS_MASK));
1731 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1732 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
1734 lstcon_new_session_id(&console_session.ses_id);
1736 console_session.ses_key = key;
1737 console_session.ses_state = LST_SESSION_ACTIVE;
1738 console_session.ses_force = !!force;
1739 console_session.ses_features = feats;
1740 console_session.ses_feats_updated = 0;
1741 console_session.ses_timeout = (timeout <= 0) ?
1742 LST_CONSOLE_TIMEOUT : timeout;
1743 strcpy(console_session.ses_name, name);
1745 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1749 rc = lstcon_rpc_pinger_start();
1751 lstcon_batch_t *bat = NULL;
1753 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1754 lstcon_batch_destroy(bat);
1759 if (copy_to_user(sid_up, &console_session.ses_id,
1760 sizeof(lst_sid_t)) == 0)
1763 lstcon_session_end();
1769 lstcon_session_info(lst_sid_t *sid_up, int *key_up, unsigned *featp,
1770 lstcon_ndlist_ent_t *ndinfo_up, char *name_up, int len)
1772 lstcon_ndlist_ent_t *entp;
1773 lstcon_ndlink_t *ndl;
1776 if (console_session.ses_state != LST_SESSION_ACTIVE)
1779 LIBCFS_ALLOC(entp, sizeof(*entp));
1783 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link)
1784 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1786 if (copy_to_user(sid_up, &console_session.ses_id,
1787 sizeof(lst_sid_t)) ||
1788 copy_to_user(key_up, &console_session.ses_key,
1790 copy_to_user(featp, &console_session.ses_features,
1792 copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1793 copy_to_user(name_up, console_session.ses_name, len))
1796 LIBCFS_FREE(entp, sizeof(*entp));
1802 lstcon_session_end(void)
1804 lstcon_rpc_trans_t *trans;
1805 lstcon_group_t *grp;
1806 lstcon_batch_t *bat;
1809 LASSERT(console_session.ses_state == LST_SESSION_ACTIVE);
1811 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1812 NULL, LST_TRANS_SESEND, NULL,
1813 lstcon_sesrpc_condition, &trans);
1815 CERROR("Can't create transaction: %d\n", rc);
1819 console_session.ses_shutdown = 1;
1821 lstcon_rpc_pinger_stop();
1823 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1825 lstcon_rpc_trans_destroy(trans);
1826 /* User can do nothing even rpc failed, so go on */
1828 /* waiting for orphan rpcs to die */
1829 lstcon_rpc_cleanup_wait();
1831 console_session.ses_id = LST_INVALID_SID;
1832 console_session.ses_state = LST_SESSION_NONE;
1833 console_session.ses_key = 0;
1834 console_session.ses_force = 0;
1835 console_session.ses_feats_updated = 0;
1837 /* destroy all batches */
1838 while (!list_empty(&console_session.ses_bat_list)) {
1839 bat = list_entry(console_session.ses_bat_list.next,
1840 lstcon_batch_t, bat_link);
1842 lstcon_batch_destroy(bat);
1845 /* destroy all groups */
1846 while (!list_empty(&console_session.ses_grp_list)) {
1847 grp = list_entry(console_session.ses_grp_list.next,
1848 lstcon_group_t, grp_link);
1849 LASSERT(grp->grp_ref == 1);
1851 lstcon_group_put(grp);
1854 /* all nodes should be released */
1855 LASSERT(list_empty(&console_session.ses_ndl_list));
1857 console_session.ses_shutdown = 0;
1858 console_session.ses_expired = 0;
1864 lstcon_session_feats_check(unsigned feats)
1868 if ((feats & ~LST_FEATS_MASK) != 0) {
1869 CERROR("Can't support these features: %x\n",
1870 (feats & ~LST_FEATS_MASK));
1874 spin_lock(&console_session.ses_rpc_lock);
1876 if (!console_session.ses_feats_updated) {
1877 console_session.ses_feats_updated = 1;
1878 console_session.ses_features = feats;
1881 if (console_session.ses_features != feats)
1884 spin_unlock(&console_session.ses_rpc_lock);
1887 CERROR("remote features %x do not match with session features %x of console\n",
1888 feats, console_session.ses_features);
1895 lstcon_acceptor_handle(srpc_server_rpc_t *rpc)
1897 srpc_msg_t *rep = &rpc->srpc_replymsg;
1898 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1899 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1900 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1901 lstcon_group_t *grp = NULL;
1902 lstcon_ndlink_t *ndl;
1905 sfw_unpack_message(req);
1907 mutex_lock(&console_session.ses_mutex);
1909 jrep->join_sid = console_session.ses_id;
1911 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1912 jrep->join_status = ESRCH;
1916 if (lstcon_session_feats_check(req->msg_ses_feats) != 0) {
1917 jrep->join_status = EPROTO;
1921 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1922 !lstcon_session_match(jreq->join_sid)) {
1923 jrep->join_status = EBUSY;
1927 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1928 rc = lstcon_group_alloc(jreq->join_group, &grp);
1930 CERROR("Out of memory\n");
1934 list_add_tail(&grp->grp_link,
1935 &console_session.ses_grp_list);
1936 lstcon_group_addref(grp);
1939 if (grp->grp_ref > 2) {
1940 /* Group in using */
1941 jrep->join_status = EBUSY;
1945 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1947 jrep->join_status = EEXIST;
1951 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1953 CERROR("Out of memory\n");
1957 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1958 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1960 if (grp->grp_userland == 0)
1961 grp->grp_userland = 1;
1963 strcpy(jrep->join_session, console_session.ses_name);
1964 jrep->join_timeout = console_session.ses_timeout;
1965 jrep->join_status = 0;
1968 rep->msg_ses_feats = console_session.ses_features;
1970 lstcon_group_put(grp);
1972 mutex_unlock(&console_session.ses_mutex);
1977 srpc_service_t lstcon_acceptor_service;
1978 static void lstcon_init_acceptor_service(void)
1980 /* initialize selftest console acceptor service table */
1981 lstcon_acceptor_service.sv_name = "join session";
1982 lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
1983 lstcon_acceptor_service.sv_id = SRPC_SERVICE_JOIN;
1984 lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX;
1987 extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
1989 static DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
1991 /* initialize console */
1993 lstcon_console_init(void)
1998 memset(&console_session, 0, sizeof(lstcon_session_t));
2000 console_session.ses_id = LST_INVALID_SID;
2001 console_session.ses_state = LST_SESSION_NONE;
2002 console_session.ses_timeout = 0;
2003 console_session.ses_force = 0;
2004 console_session.ses_expired = 0;
2005 console_session.ses_feats_updated = 0;
2006 console_session.ses_features = LST_FEATS_MASK;
2007 console_session.ses_laststamp = get_seconds();
2009 mutex_init(&console_session.ses_mutex);
2011 INIT_LIST_HEAD(&console_session.ses_ndl_list);
2012 INIT_LIST_HEAD(&console_session.ses_grp_list);
2013 INIT_LIST_HEAD(&console_session.ses_bat_list);
2014 INIT_LIST_HEAD(&console_session.ses_trans_list);
2016 LIBCFS_ALLOC(console_session.ses_ndl_hash,
2017 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2018 if (console_session.ses_ndl_hash == NULL)
2021 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
2022 INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
2025 /* initialize acceptor service table */
2026 lstcon_init_acceptor_service();
2028 rc = srpc_add_service(&lstcon_acceptor_service);
2029 LASSERT(rc != -EBUSY);
2031 LIBCFS_FREE(console_session.ses_ndl_hash,
2032 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2036 rc = srpc_service_add_buffers(&lstcon_acceptor_service,
2037 lstcon_acceptor_service.sv_wi_total);
2043 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
2046 lstcon_rpc_module_init();
2051 srpc_shutdown_service(&lstcon_acceptor_service);
2052 srpc_remove_service(&lstcon_acceptor_service);
2054 LIBCFS_FREE(console_session.ses_ndl_hash,
2055 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2057 srpc_wait_service_shutdown(&lstcon_acceptor_service);
2063 lstcon_console_fini(void)
2067 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
2069 mutex_lock(&console_session.ses_mutex);
2071 srpc_shutdown_service(&lstcon_acceptor_service);
2072 srpc_remove_service(&lstcon_acceptor_service);
2074 if (console_session.ses_state != LST_SESSION_NONE)
2075 lstcon_session_end();
2077 lstcon_rpc_module_fini();
2079 mutex_unlock(&console_session.ses_mutex);
2081 LASSERT(list_empty(&console_session.ses_ndl_list));
2082 LASSERT(list_empty(&console_session.ses_grp_list));
2083 LASSERT(list_empty(&console_session.ses_bat_list));
2084 LASSERT(list_empty(&console_session.ses_trans_list));
2086 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
2087 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
2090 LIBCFS_FREE(console_session.ses_ndl_hash,
2091 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2093 srpc_wait_service_shutdown(&lstcon_acceptor_service);