1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/selftest/conctl.c
38 * Infrastructure of LST console
40 * Author: Liang Zhen <liangzhen@clusterfs.com>
45 #include <libcfs/libcfs.h>
46 #include <lnet/lib-lnet.h>
50 #define LST_NODE_STATE_COUNTER(nd, p) \
52 if ((nd)->nd_state == LST_NODE_ACTIVE) \
53 (p)->nle_nactive ++; \
54 else if ((nd)->nd_state == LST_NODE_BUSY) \
56 else if ((nd)->nd_state == LST_NODE_DOWN) \
59 (p)->nle_nunknown ++; \
63 lstcon_session_t console_session;
66 lstcon_node_get(lstcon_node_t *nd)
68 LASSERT (nd->nd_ref >= 1);
74 lstcon_node_find(lnet_process_id_t id, lstcon_node_t **ndpp, int create)
77 unsigned int idx = LNET_NIDADDR(id.nid) % LST_GLOBAL_HASHSIZE;
79 LASSERT (id.nid != LNET_NID_ANY);
81 cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_hash[idx],
82 lstcon_ndlink_t, ndl_hlink) {
83 if (ndl->ndl_node->nd_id.nid != id.nid ||
84 ndl->ndl_node->nd_id.pid != id.pid)
87 lstcon_node_get(ndl->ndl_node);
88 *ndpp = ndl->ndl_node;
95 LIBCFS_ALLOC(*ndpp, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
99 ndl = (lstcon_ndlink_t *)(*ndpp + 1);
101 ndl->ndl_node = *ndpp;
103 ndl->ndl_node->nd_ref = 1;
104 ndl->ndl_node->nd_id = id;
105 ndl->ndl_node->nd_stamp = cfs_time_current();
106 ndl->ndl_node->nd_state = LST_NODE_UNKNOWN;
107 ndl->ndl_node->nd_timeout = 0;
108 memset(&ndl->ndl_node->nd_ping, 0, sizeof(lstcon_rpc_t));
110 /* queued in global hash & list, no refcount is taken by
111 * global hash & list, if caller release his refcount,
112 * node will be released */
113 cfs_list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
114 cfs_list_add_tail(&ndl->ndl_link, &console_session.ses_ndl_list);
120 lstcon_node_put(lstcon_node_t *nd)
122 lstcon_ndlink_t *ndl;
124 LASSERT (nd->nd_ref > 0);
126 if (--nd->nd_ref > 0)
129 ndl = (lstcon_ndlink_t *)(nd + 1);
131 LASSERT (!cfs_list_empty(&ndl->ndl_link));
132 LASSERT (!cfs_list_empty(&ndl->ndl_hlink));
134 /* remove from session */
135 cfs_list_del(&ndl->ndl_link);
136 cfs_list_del(&ndl->ndl_hlink);
138 LIBCFS_FREE(nd, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
142 lstcon_ndlink_find(cfs_list_t *hash,
143 lnet_process_id_t id, lstcon_ndlink_t **ndlpp, int create)
145 unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
146 lstcon_ndlink_t *ndl;
150 if (id.nid == LNET_NID_ANY)
154 cfs_list_for_each_entry_typed(ndl, &hash[idx],
155 lstcon_ndlink_t, ndl_hlink) {
156 if (ndl->ndl_node->nd_id.nid != id.nid ||
157 ndl->ndl_node->nd_id.pid != id.pid)
167 /* find or create in session hash */
168 rc = lstcon_node_find(id, &nd, (create == 1) ? 1 : 0);
172 LIBCFS_ALLOC(ndl, sizeof(lstcon_ndlink_t));
181 CFS_INIT_LIST_HEAD(&ndl->ndl_link);
182 cfs_list_add_tail(&ndl->ndl_hlink, &hash[idx]);
188 lstcon_ndlink_release(lstcon_ndlink_t *ndl)
190 LASSERT (cfs_list_empty(&ndl->ndl_link));
191 LASSERT (!cfs_list_empty(&ndl->ndl_hlink));
193 cfs_list_del(&ndl->ndl_hlink); /* delete from hash */
194 lstcon_node_put(ndl->ndl_node);
196 LIBCFS_FREE(ndl, sizeof(*ndl));
200 lstcon_group_alloc(char *name, lstcon_group_t **grpp)
205 LIBCFS_ALLOC(grp, offsetof(lstcon_group_t,
206 grp_ndl_hash[LST_NODE_HASHSIZE]));
210 memset(grp, 0, offsetof(lstcon_group_t,
211 grp_ndl_hash[LST_NODE_HASHSIZE]));
215 strcpy(grp->grp_name, name);
217 CFS_INIT_LIST_HEAD(&grp->grp_link);
218 CFS_INIT_LIST_HEAD(&grp->grp_ndl_list);
219 CFS_INIT_LIST_HEAD(&grp->grp_trans_list);
221 for (i = 0; i < LST_NODE_HASHSIZE; i++)
222 CFS_INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
230 lstcon_group_addref(lstcon_group_t *grp)
235 static void lstcon_group_ndlink_release(lstcon_group_t *, lstcon_ndlink_t *);
238 lstcon_group_drain(lstcon_group_t *grp, int keep)
240 lstcon_ndlink_t *ndl;
241 lstcon_ndlink_t *tmp;
243 cfs_list_for_each_entry_safe_typed(ndl, tmp, &grp->grp_ndl_list,
244 lstcon_ndlink_t, ndl_link) {
245 if ((ndl->ndl_node->nd_state & keep) == 0)
246 lstcon_group_ndlink_release(grp, ndl);
251 lstcon_group_decref(lstcon_group_t *grp)
255 if (--grp->grp_ref > 0)
258 if (!cfs_list_empty(&grp->grp_link))
259 cfs_list_del(&grp->grp_link);
261 lstcon_group_drain(grp, 0);
263 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
264 LASSERT (cfs_list_empty(&grp->grp_ndl_hash[i]));
267 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
268 grp_ndl_hash[LST_NODE_HASHSIZE]));
272 lstcon_group_find(char *name, lstcon_group_t **grpp)
276 cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list,
277 lstcon_group_t, grp_link) {
278 if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
281 lstcon_group_addref(grp); /* +1 ref for caller */
290 lstcon_group_put(lstcon_group_t *grp)
292 lstcon_group_decref(grp);
296 lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id,
297 lstcon_ndlink_t **ndlpp, int create)
301 rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
305 if (!cfs_list_empty(&(*ndlpp)->ndl_link))
308 cfs_list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
315 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
317 cfs_list_del_init(&ndl->ndl_link);
318 lstcon_ndlink_release(ndl);
323 lstcon_group_ndlink_move(lstcon_group_t *old,
324 lstcon_group_t *new, lstcon_ndlink_t *ndl)
326 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
329 cfs_list_del(&ndl->ndl_hlink);
330 cfs_list_del(&ndl->ndl_link);
333 cfs_list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
334 cfs_list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
341 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
343 lstcon_ndlink_t *ndl;
345 while (!cfs_list_empty(&old->grp_ndl_list)) {
346 ndl = cfs_list_entry(old->grp_ndl_list.next,
347 lstcon_ndlink_t, ndl_link);
348 lstcon_group_ndlink_move(old, new, ndl);
353 lstcon_sesrpc_condition(int transop, lstcon_node_t *nd, void *arg)
355 lstcon_group_t *grp = (lstcon_group_t *)arg;
358 case LST_TRANS_SESNEW:
359 if (nd->nd_state == LST_NODE_ACTIVE)
363 case LST_TRANS_SESEND:
364 if (nd->nd_state != LST_NODE_ACTIVE)
367 if (grp != NULL && nd->nd_ref > 1)
371 case LST_TRANS_SESQRY:
382 lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
383 lstcon_rpc_ent_t *ent_up)
385 srpc_debug_reply_t *rep;
388 case LST_TRANS_SESNEW:
389 case LST_TRANS_SESEND:
392 case LST_TRANS_SESQRY:
393 rep = &msg->msg_body.dbg_reply;
395 if (cfs_copy_to_user(&ent_up->rpe_priv[0],
396 &rep->dbg_timeout, sizeof(int)) ||
397 cfs_copy_to_user(&ent_up->rpe_payload[0],
398 &rep->dbg_name, LST_NAME_SIZE))
411 lstcon_group_nodes_add(lstcon_group_t *grp, int count,
412 lnet_process_id_t *ids_up,
413 cfs_list_t *result_up)
415 lstcon_rpc_trans_t *trans;
416 lstcon_ndlink_t *ndl;
418 lnet_process_id_t id;
422 rc = lstcon_group_alloc(NULL, &tmp);
424 CERROR("Out of memory\n");
428 for (i = 0 ; i < count; i++) {
429 if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) {
434 /* skip if it's in this group already */
435 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
439 /* add to tmp group */
440 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
442 CERROR("Can't create ndlink, out of memory\n");
448 lstcon_group_put(tmp);
452 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
453 &tmp->grp_trans_list, LST_TRANS_SESNEW,
454 tmp, lstcon_sesrpc_condition, &trans);
456 CERROR("Can't create transaction: %d\n", rc);
457 lstcon_group_put(tmp);
462 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
464 rc = lstcon_rpc_trans_interpreter(trans, result_up,
465 lstcon_sesrpc_readent);
466 /* destroy all RPGs */
467 lstcon_rpc_trans_destroy(trans);
469 lstcon_group_move(tmp, grp);
470 lstcon_group_put(tmp);
476 lstcon_group_nodes_remove(lstcon_group_t *grp,
477 int count, lnet_process_id_t *ids_up,
478 cfs_list_t *result_up)
480 lstcon_rpc_trans_t *trans;
481 lstcon_ndlink_t *ndl;
483 lnet_process_id_t id;
487 /* End session and remove node from the group */
489 rc = lstcon_group_alloc(NULL, &tmp);
491 CERROR("Out of memory\n");
495 for (i = 0; i < count; i++) {
496 if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) {
501 /* move node to tmp group */
502 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
503 lstcon_group_ndlink_move(grp, tmp, ndl);
506 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
507 &tmp->grp_trans_list, LST_TRANS_SESEND,
508 tmp, lstcon_sesrpc_condition, &trans);
510 CERROR("Can't create transaction: %d\n", rc);
514 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
516 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
518 lstcon_rpc_trans_destroy(trans);
519 /* release nodes anyway, because we can't rollback status */
520 lstcon_group_put(tmp);
524 lstcon_group_move(tmp, grp);
525 lstcon_group_put(tmp);
531 lstcon_group_add(char *name)
536 rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
538 /* find a group with same name */
539 lstcon_group_put(grp);
543 rc = lstcon_group_alloc(name, &grp);
545 CERROR("Can't allocate descriptor for group %s\n", name);
549 cfs_list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
555 lstcon_nodes_add(char *name, int count,
556 lnet_process_id_t *ids_up, cfs_list_t *result_up)
562 LASSERT (ids_up != NULL);
564 rc = lstcon_group_find(name, &grp);
566 CDEBUG(D_NET, "Can't find group %s\n", name);
570 if (grp->grp_ref > 2) {
571 /* referred by other threads or test */
572 CDEBUG(D_NET, "Group %s is busy\n", name);
573 lstcon_group_put(grp);
578 rc = lstcon_group_nodes_add(grp, count, ids_up, result_up);
580 lstcon_group_put(grp);
586 lstcon_group_del(char *name)
588 lstcon_rpc_trans_t *trans;
592 rc = lstcon_group_find(name, &grp);
594 CDEBUG(D_NET, "Can't find group: %s\n", name);
598 if (grp->grp_ref > 2) {
599 /* referred by others threads or test */
600 CDEBUG(D_NET, "Group %s is busy\n", name);
601 lstcon_group_put(grp);
605 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
606 &grp->grp_trans_list, LST_TRANS_SESEND,
607 grp, lstcon_sesrpc_condition, &trans);
609 CERROR("Can't create transaction: %d\n", rc);
610 lstcon_group_put(grp);
614 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
616 lstcon_rpc_trans_destroy(trans);
618 lstcon_group_put(grp);
619 /* -ref for session, it's destroyed,
620 * status can't be rolled back, destroy group anway */
621 lstcon_group_put(grp);
627 lstcon_group_clean(char *name, int args)
629 lstcon_group_t *grp = NULL;
632 rc = lstcon_group_find(name, &grp);
634 CDEBUG(D_NET, "Can't find group %s\n", name);
638 if (grp->grp_ref > 2) {
639 /* referred by test */
640 CDEBUG(D_NET, "Group %s is busy\n", name);
641 lstcon_group_put(grp);
645 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
646 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
648 lstcon_group_drain(grp, args);
650 lstcon_group_put(grp);
651 /* release empty group */
652 if (cfs_list_empty(&grp->grp_ndl_list))
653 lstcon_group_put(grp);
659 lstcon_nodes_remove(char *name, int count,
660 lnet_process_id_t *ids_up, cfs_list_t *result_up)
662 lstcon_group_t *grp = NULL;
665 rc = lstcon_group_find(name, &grp);
667 CDEBUG(D_NET, "Can't find group: %s\n", name);
671 if (grp->grp_ref > 2) {
672 /* referred by test */
673 CDEBUG(D_NET, "Group %s is busy\n", name);
674 lstcon_group_put(grp);
678 rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
680 lstcon_group_put(grp);
681 /* release empty group */
682 if (cfs_list_empty(&grp->grp_ndl_list))
683 lstcon_group_put(grp);
689 lstcon_group_refresh(char *name, cfs_list_t *result_up)
691 lstcon_rpc_trans_t *trans;
695 rc = lstcon_group_find(name, &grp);
697 CDEBUG(D_NET, "Can't find group: %s\n", name);
701 if (grp->grp_ref > 2) {
702 /* referred by test */
703 CDEBUG(D_NET, "Group %s is busy\n", name);
704 lstcon_group_put(grp);
708 /* re-invite all inactive nodes int the group */
709 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
710 &grp->grp_trans_list, LST_TRANS_SESNEW,
711 grp, lstcon_sesrpc_condition, &trans);
713 /* local error, return */
714 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
715 lstcon_group_put(grp);
719 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
721 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
723 lstcon_rpc_trans_destroy(trans);
725 lstcon_group_put(grp);
731 lstcon_group_list(int index, int len, char *name_up)
735 LASSERT (index >= 0);
736 LASSERT (name_up != NULL);
738 cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list,
739 lstcon_group_t, grp_link) {
741 return cfs_copy_to_user(name_up, grp->grp_name, len) ?
750 lstcon_nodes_getent(cfs_list_t *head, int *index_p,
751 int *count_p, lstcon_node_ent_t *dents_up)
753 lstcon_ndlink_t *ndl;
758 LASSERT (index_p != NULL && count_p != NULL);
759 LASSERT (dents_up != NULL);
760 LASSERT (*index_p >= 0);
761 LASSERT (*count_p > 0);
763 cfs_list_for_each_entry_typed(ndl, head, lstcon_ndlink_t, ndl_link) {
764 if (index++ < *index_p)
767 if (count >= *count_p)
771 if (cfs_copy_to_user(&dents_up[count].nde_id,
772 &nd->nd_id, sizeof(nd->nd_id)) ||
773 cfs_copy_to_user(&dents_up[count].nde_state,
774 &nd->nd_state, sizeof(nd->nd_state)))
780 if (index <= *index_p)
790 lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p,
791 int *index_p, int *count_p, lstcon_node_ent_t *dents_up)
793 lstcon_ndlist_ent_t *gentp;
795 lstcon_ndlink_t *ndl;
798 rc = lstcon_group_find(name, &grp);
800 CDEBUG(D_NET, "Can't find group %s\n", name);
806 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
807 index_p, count_p, dents_up);
808 lstcon_group_put(grp);
813 /* non-verbose query */
814 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
816 CERROR("Can't allocate ndlist_ent\n");
817 lstcon_group_put(grp);
822 memset(gentp, 0, sizeof(lstcon_ndlist_ent_t));
824 cfs_list_for_each_entry_typed(ndl, &grp->grp_ndl_list,
825 lstcon_ndlink_t, ndl_link)
826 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
828 rc = cfs_copy_to_user(gents_p, gentp,
829 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT: 0;
831 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
833 lstcon_group_put(grp);
839 lstcon_batch_find(char *name, lstcon_batch_t **batpp)
843 cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list,
844 lstcon_batch_t, bat_link) {
845 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
855 lstcon_batch_add(char *name)
861 rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
863 CDEBUG(D_NET, "Batch %s already exists\n", name);
867 LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
869 CERROR("Can't allocate descriptor for batch %s\n", name);
873 LIBCFS_ALLOC(bat->bat_cli_hash,
874 sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
875 if (bat->bat_cli_hash == NULL) {
876 CERROR("Can't allocate hash for batch %s\n", name);
877 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
882 LIBCFS_ALLOC(bat->bat_srv_hash,
883 sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
884 if (bat->bat_srv_hash == NULL) {
885 CERROR("Can't allocate hash for batch %s\n", name);
886 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
887 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
892 strcpy(bat->bat_name, name);
893 bat->bat_hdr.tsb_index = 0;
894 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
897 bat->bat_state = LST_BATCH_IDLE;
899 CFS_INIT_LIST_HEAD(&bat->bat_cli_list);
900 CFS_INIT_LIST_HEAD(&bat->bat_srv_list);
901 CFS_INIT_LIST_HEAD(&bat->bat_test_list);
902 CFS_INIT_LIST_HEAD(&bat->bat_trans_list);
904 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
905 CFS_INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
906 CFS_INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
909 cfs_list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
915 lstcon_batch_list(int index, int len, char *name_up)
919 LASSERT (name_up != NULL);
920 LASSERT (index >= 0);
922 cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list,
923 lstcon_batch_t, bat_link) {
925 return cfs_copy_to_user(name_up,bat->bat_name, len) ?
934 lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
935 int testidx, int *index_p, int *ndent_p,
936 lstcon_node_ent_t *dents_up)
938 lstcon_test_batch_ent_t *entp;
941 lstcon_test_t *test = NULL;
943 lstcon_ndlink_t *ndl;
946 rc = lstcon_batch_find(name, &bat);
948 CDEBUG(D_NET, "Can't find batch %s\n", name);
953 /* query test, test index start from 1 */
954 cfs_list_for_each_entry_typed(test, &bat->bat_test_list,
955 lstcon_test_t, tes_link) {
961 CDEBUG(D_NET, "Can't find specified test in batch\n");
966 clilst = (test == NULL) ? &bat->bat_cli_list :
967 &test->tes_src_grp->grp_ndl_list;
968 srvlst = (test == NULL) ? &bat->bat_srv_list :
969 &test->tes_dst_grp->grp_ndl_list;
971 if (dents_up != NULL) {
972 rc = lstcon_nodes_getent((server ? srvlst: clilst),
973 index_p, ndent_p, dents_up);
977 /* non-verbose query */
978 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
982 memset(entp, 0, sizeof(lstcon_test_batch_ent_t));
985 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
986 entp->u.tbe_batch.bae_state = bat->bat_state;
990 entp->u.tbe_test.tse_type = test->tes_type;
991 entp->u.tbe_test.tse_loop = test->tes_loop;
992 entp->u.tbe_test.tse_concur = test->tes_concur;
995 cfs_list_for_each_entry_typed(ndl, clilst, lstcon_ndlink_t, ndl_link)
996 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
998 cfs_list_for_each_entry_typed(ndl, srvlst, lstcon_ndlink_t, ndl_link)
999 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
1001 rc = cfs_copy_to_user(ent_up, entp,
1002 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
1004 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
1010 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1013 case LST_TRANS_TSBRUN:
1014 if (nd->nd_state != LST_NODE_ACTIVE)
1018 case LST_TRANS_TSBSTOP:
1019 if (nd->nd_state != LST_NODE_ACTIVE)
1023 case LST_TRANS_TSBCLIQRY:
1024 case LST_TRANS_TSBSRVQRY:
1032 lstcon_batch_op(lstcon_batch_t *bat, int transop,
1033 cfs_list_t *result_up)
1035 lstcon_rpc_trans_t *trans;
1038 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1039 &bat->bat_trans_list, transop,
1040 bat, lstcon_batrpc_condition, &trans);
1042 CERROR("Can't create transaction: %d\n", rc);
1046 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1048 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1050 lstcon_rpc_trans_destroy(trans);
1056 lstcon_batch_run(char *name, int timeout, cfs_list_t *result_up)
1058 lstcon_batch_t *bat;
1061 if (lstcon_batch_find(name, &bat) != 0) {
1062 CDEBUG(D_NET, "Can't find batch %s\n", name);
1066 bat->bat_arg = timeout;
1068 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1070 /* mark batch as running if it's started in any node */
1071 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1072 bat->bat_state = LST_BATCH_RUNNING;
1078 lstcon_batch_stop(char *name, int force, cfs_list_t *result_up)
1080 lstcon_batch_t *bat;
1083 if (lstcon_batch_find(name, &bat) != 0) {
1084 CDEBUG(D_NET, "Can't find batch %s\n", name);
1088 bat->bat_arg = force;
1090 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1092 /* mark batch as stopped if all RPCs finished */
1093 if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1094 bat->bat_state = LST_BATCH_IDLE;
1100 lstcon_batch_destroy(lstcon_batch_t *bat)
1102 lstcon_ndlink_t *ndl;
1103 lstcon_test_t *test;
1106 cfs_list_del(&bat->bat_link);
1108 while (!cfs_list_empty(&bat->bat_test_list)) {
1109 test = cfs_list_entry(bat->bat_test_list.next,
1110 lstcon_test_t, tes_link);
1111 LASSERT (cfs_list_empty(&test->tes_trans_list));
1113 cfs_list_del(&test->tes_link);
1115 lstcon_group_put(test->tes_src_grp);
1116 lstcon_group_put(test->tes_dst_grp);
1118 LIBCFS_FREE(test, offsetof(lstcon_test_t,
1119 tes_param[test->tes_paramlen]));
1122 LASSERT (cfs_list_empty(&bat->bat_trans_list));
1124 while (!cfs_list_empty(&bat->bat_cli_list)) {
1125 ndl = cfs_list_entry(bat->bat_cli_list.next,
1126 lstcon_ndlink_t, ndl_link);
1127 cfs_list_del_init(&ndl->ndl_link);
1129 lstcon_ndlink_release(ndl);
1132 while (!cfs_list_empty(&bat->bat_srv_list)) {
1133 ndl = cfs_list_entry(bat->bat_srv_list.next,
1134 lstcon_ndlink_t, ndl_link);
1135 cfs_list_del_init(&ndl->ndl_link);
1137 lstcon_ndlink_release(ndl);
1140 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1141 LASSERT (cfs_list_empty(&bat->bat_cli_hash[i]));
1142 LASSERT (cfs_list_empty(&bat->bat_srv_hash[i]));
1145 LIBCFS_FREE(bat->bat_cli_hash,
1146 sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
1147 LIBCFS_FREE(bat->bat_srv_hash,
1148 sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
1149 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
1153 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1155 lstcon_test_t *test;
1156 lstcon_batch_t *batch;
1157 lstcon_ndlink_t *ndl;
1161 test = (lstcon_test_t *)arg;
1162 LASSERT (test != NULL);
1164 batch = test->tes_batch;
1165 LASSERT (batch != NULL);
1167 if (test->tes_oneside &&
1168 transop == LST_TRANS_TSBSRVADD)
1171 if (nd->nd_state != LST_NODE_ACTIVE)
1174 if (transop == LST_TRANS_TSBCLIADD) {
1175 hash = batch->bat_cli_hash;
1176 head = &batch->bat_cli_list;
1179 LASSERT (transop == LST_TRANS_TSBSRVADD);
1181 hash = batch->bat_srv_hash;
1182 head = &batch->bat_srv_list;
1185 LASSERT (nd->nd_id.nid != LNET_NID_ANY);
1187 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1190 if (cfs_list_empty(&ndl->ndl_link))
1191 cfs_list_add_tail(&ndl->ndl_link, head);
1197 lstcon_test_nodes_add(lstcon_test_t *test, cfs_list_t *result_up)
1199 lstcon_rpc_trans_t *trans;
1200 lstcon_group_t *grp;
1204 LASSERT (test->tes_src_grp != NULL);
1205 LASSERT (test->tes_dst_grp != NULL);
1207 transop = LST_TRANS_TSBSRVADD;
1208 grp = test->tes_dst_grp;
1210 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1211 &test->tes_trans_list, transop,
1212 test, lstcon_testrpc_condition, &trans);
1214 CERROR("Can't create transaction: %d\n", rc);
1218 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1220 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1221 lstcon_trans_stat()->trs_fwk_errno != 0) {
1222 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1224 lstcon_rpc_trans_destroy(trans);
1225 /* return if any error */
1226 CDEBUG(D_NET, "Failed to add test %s, "
1227 "RPC error %d, framework error %d\n",
1228 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1229 lstcon_trans_stat()->trs_rpc_errno,
1230 lstcon_trans_stat()->trs_fwk_errno);
1235 lstcon_rpc_trans_destroy(trans);
1237 if (transop == LST_TRANS_TSBCLIADD)
1240 transop = LST_TRANS_TSBCLIADD;
1241 grp = test->tes_src_grp;
1242 test->tes_cliidx = 0;
1244 /* requests to test clients */
1249 lstcon_test_add(char *name, int type, int loop, int concur,
1250 int dist, int span, char *src_name, char * dst_name,
1251 void *param, int paramlen, int *retp,
1252 cfs_list_t *result_up)
1254 lstcon_group_t *src_grp = NULL;
1255 lstcon_group_t *dst_grp = NULL;
1256 lstcon_test_t *test = NULL;
1257 lstcon_batch_t *batch;
1260 rc = lstcon_batch_find(name, &batch);
1262 CDEBUG(D_NET, "Can't find batch %s\n", name);
1266 if (batch->bat_state != LST_BATCH_IDLE) {
1267 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1271 rc = lstcon_group_find(src_name, &src_grp);
1273 CDEBUG(D_NET, "Can't find group %s\n", src_name);
1277 rc = lstcon_group_find(dst_name, &dst_grp);
1279 CDEBUG(D_NET, "Can't find group %s\n", dst_name);
1283 if (dst_grp->grp_userland)
1286 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1288 CERROR("Can't allocate test descriptor\n");
1294 memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen]));
1295 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1296 test->tes_batch = batch;
1297 test->tes_type = type;
1298 test->tes_oneside = 0; /* TODO */
1299 test->tes_loop = loop;
1300 test->tes_concur = concur;
1301 test->tes_stop_onerr = 1; /* TODO */
1302 test->tes_span = span;
1303 test->tes_dist = dist;
1304 test->tes_cliidx = 0; /* just used for creating RPC */
1305 test->tes_src_grp = src_grp;
1306 test->tes_dst_grp = dst_grp;
1307 CFS_INIT_LIST_HEAD(&test->tes_trans_list);
1309 if (param != NULL) {
1310 test->tes_paramlen = paramlen;
1311 memcpy(&test->tes_param[0], param, paramlen);
1314 rc = lstcon_test_nodes_add(test, result_up);
1319 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1320 lstcon_trans_stat()->trs_fwk_errno != 0)
1321 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type, name);
1323 /* add to test list anyway, so user can check what's going on */
1324 cfs_list_add_tail(&test->tes_link, &batch->bat_test_list);
1326 batch->bat_ntest ++;
1327 test->tes_hdr.tsb_index = batch->bat_ntest;
1329 /* hold groups so nobody can change them */
1333 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1335 if (dst_grp != NULL)
1336 lstcon_group_put(dst_grp);
1338 if (src_grp != NULL)
1339 lstcon_group_put(src_grp);
1345 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1347 lstcon_test_t *test;
1349 cfs_list_for_each_entry_typed(test, &batch->bat_test_list,
1350 lstcon_test_t, tes_link) {
1351 if (idx == test->tes_hdr.tsb_index) {
1361 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1362 lstcon_rpc_ent_t *ent_up)
1364 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1366 LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1367 transop == LST_TRANS_TSBSRVQRY);
1369 /* positive errno, framework error code */
1370 if (cfs_copy_to_user(&ent_up->rpe_priv[0],
1371 &rep->bar_active, sizeof(rep->bar_active)))
1378 lstcon_test_batch_query(char *name, int testidx, int client,
1379 int timeout, cfs_list_t *result_up)
1381 lstcon_rpc_trans_t *trans;
1382 cfs_list_t *translist;
1384 lstcon_tsb_hdr_t *hdr;
1385 lstcon_batch_t *batch;
1386 lstcon_test_t *test = NULL;
1390 rc = lstcon_batch_find(name, &batch);
1392 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1397 translist = &batch->bat_trans_list;
1398 ndlist = &batch->bat_cli_list;
1399 hdr = &batch->bat_hdr;
1402 /* query specified test only */
1403 rc = lstcon_test_find(batch, testidx, &test);
1405 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1409 translist = &test->tes_trans_list;
1410 ndlist = &test->tes_src_grp->grp_ndl_list;
1411 hdr = &test->tes_hdr;
1414 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1416 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1417 lstcon_batrpc_condition, &trans);
1419 CERROR("Can't create transaction: %d\n", rc);
1423 lstcon_rpc_trans_postwait(trans, timeout);
1425 if (testidx == 0 && /* query a batch, not a test */
1426 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1427 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1428 /* all RPCs finished, and no active test */
1429 batch->bat_state = LST_BATCH_IDLE;
1432 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1433 lstcon_tsbrpc_readent);
1434 lstcon_rpc_trans_destroy(trans);
1440 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1441 lstcon_rpc_ent_t *ent_up)
1443 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1444 sfw_counters_t *sfwk_stat;
1445 srpc_counters_t *srpc_stat;
1446 lnet_counters_t *lnet_stat;
1448 if (rep->str_status != 0)
1451 sfwk_stat = (sfw_counters_t *)&ent_up->rpe_payload[0];
1452 srpc_stat = (srpc_counters_t *)((char *)sfwk_stat + sizeof(*sfwk_stat));
1453 lnet_stat = (lnet_counters_t *)((char *)srpc_stat + sizeof(*srpc_stat));
1455 if (cfs_copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1456 cfs_copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1457 cfs_copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1464 lstcon_ndlist_stat(cfs_list_t *ndlist,
1465 int timeout, cfs_list_t *result_up)
1468 lstcon_rpc_trans_t *trans;
1471 CFS_INIT_LIST_HEAD(&head);
1473 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1474 LST_TRANS_STATQRY, NULL, NULL, &trans);
1476 CERROR("Can't create transaction: %d\n", rc);
1480 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1482 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1483 lstcon_statrpc_readent);
1484 lstcon_rpc_trans_destroy(trans);
1490 lstcon_group_stat(char *grp_name, int timeout, cfs_list_t *result_up)
1492 lstcon_group_t *grp;
1495 rc = lstcon_group_find(grp_name, &grp);
1497 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1501 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1503 lstcon_group_put(grp);
1509 lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
1510 int timeout, cfs_list_t *result_up)
1512 lstcon_ndlink_t *ndl;
1513 lstcon_group_t *tmp;
1514 lnet_process_id_t id;
1518 rc = lstcon_group_alloc(NULL, &tmp);
1520 CERROR("Out of memory\n");
1524 for (i = 0 ; i < count; i++) {
1525 if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) {
1530 /* add to tmp group */
1531 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1533 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1534 "Failed to find or create %s: %d\n",
1535 libcfs_id2str(id), rc);
1541 lstcon_group_put(tmp);
1545 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1547 lstcon_group_put(tmp);
1553 lstcon_debug_ndlist(cfs_list_t *ndlist,
1554 cfs_list_t *translist,
1555 int timeout, cfs_list_t *result_up)
1557 lstcon_rpc_trans_t *trans;
1560 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1561 NULL, lstcon_sesrpc_condition, &trans);
1563 CERROR("Can't create transaction: %d\n", rc);
1567 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1569 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1570 lstcon_sesrpc_readent);
1571 lstcon_rpc_trans_destroy(trans);
1577 lstcon_session_debug(int timeout, cfs_list_t *result_up)
1579 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1580 NULL, timeout, result_up);
1584 lstcon_batch_debug(int timeout, char *name,
1585 int client, cfs_list_t *result_up)
1587 lstcon_batch_t *bat;
1590 rc = lstcon_batch_find(name, &bat);
1594 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1596 NULL, timeout, result_up);
1602 lstcon_group_debug(int timeout, char *name,
1603 cfs_list_t *result_up)
1605 lstcon_group_t *grp;
1608 rc = lstcon_group_find(name, &grp);
1612 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1613 timeout, result_up);
1614 lstcon_group_put(grp);
1620 lstcon_nodes_debug(int timeout,
1621 int count, lnet_process_id_t *ids_up,
1622 cfs_list_t *result_up)
1624 lnet_process_id_t id;
1625 lstcon_ndlink_t *ndl;
1626 lstcon_group_t *grp;
1630 rc = lstcon_group_alloc(NULL, &grp);
1632 CDEBUG(D_NET, "Out of memory\n");
1636 for (i = 0; i < count; i++) {
1637 if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) {
1642 /* node is added to tmp group */
1643 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1645 CERROR("Can't create node link\n");
1651 lstcon_group_put(grp);
1655 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1656 timeout, result_up);
1658 lstcon_group_put(grp);
1664 lstcon_session_match(lst_sid_t sid)
1666 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1667 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1: 0;
1671 lstcon_new_session_id(lst_sid_t *sid)
1673 lnet_process_id_t id;
1675 LASSERT (console_session.ses_state == LST_SESSION_NONE);
1678 sid->ses_nid = id.nid;
1679 sid->ses_stamp = cfs_time_current();
1682 extern srpc_service_t lstcon_acceptor_service;
1685 lstcon_session_new(char *name, int key,
1686 int timeout,int force, lst_sid_t *sid_up)
1691 if (console_session.ses_state != LST_SESSION_NONE) {
1692 /* session exists */
1694 CERROR("Session %s already exists\n",
1695 console_session.ses_name);
1699 rc = lstcon_session_end();
1701 /* lstcon_session_end() only return local error */
1706 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++) {
1707 LASSERT (cfs_list_empty(&console_session.ses_ndl_hash[i]));
1710 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1714 rc = lstcon_rpc_pinger_start();
1716 lstcon_batch_t *bat = NULL;
1718 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1719 lstcon_batch_destroy(bat);
1724 lstcon_new_session_id(&console_session.ses_id);
1726 console_session.ses_key = key;
1727 console_session.ses_state = LST_SESSION_ACTIVE;
1728 console_session.ses_force = !!force;
1729 console_session.ses_timeout = (timeout <= 0)? LST_CONSOLE_TIMEOUT:
1731 strcpy(console_session.ses_name, name);
1733 if (cfs_copy_to_user(sid_up, &console_session.ses_id,
1734 sizeof(lst_sid_t)) == 0)
1737 lstcon_session_end();
1743 lstcon_session_info(lst_sid_t *sid_up, int *key_up,
1744 lstcon_ndlist_ent_t *ndinfo_up, char *name_up, int len)
1746 lstcon_ndlist_ent_t *entp;
1747 lstcon_ndlink_t *ndl;
1750 if (console_session.ses_state != LST_SESSION_ACTIVE)
1753 LIBCFS_ALLOC(entp, sizeof(*entp));
1757 memset(entp, 0, sizeof(*entp));
1759 cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_list,
1760 lstcon_ndlink_t, ndl_link)
1761 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1763 if (cfs_copy_to_user(sid_up, &console_session.ses_id,
1764 sizeof(lst_sid_t)) ||
1765 cfs_copy_to_user(key_up, &console_session.ses_key, sizeof(int)) ||
1766 cfs_copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1767 cfs_copy_to_user(name_up, console_session.ses_name, len))
1770 LIBCFS_FREE(entp, sizeof(*entp));
1776 lstcon_session_end()
1778 lstcon_rpc_trans_t *trans;
1779 lstcon_group_t *grp;
1780 lstcon_batch_t *bat;
1783 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1785 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1786 NULL, LST_TRANS_SESEND, NULL,
1787 lstcon_sesrpc_condition, &trans);
1789 CERROR("Can't create transaction: %d\n", rc);
1793 console_session.ses_shutdown = 1;
1795 lstcon_rpc_pinger_stop();
1797 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1799 lstcon_rpc_trans_destroy(trans);
1800 /* User can do nothing even rpc failed, so go on */
1802 /* waiting for orphan rpcs to die */
1803 lstcon_rpc_cleanup_wait();
1805 console_session.ses_id = LST_INVALID_SID;
1806 console_session.ses_state = LST_SESSION_NONE;
1807 console_session.ses_key = 0;
1808 console_session.ses_force = 0;
1810 /* destroy all batches */
1811 while (!cfs_list_empty(&console_session.ses_bat_list)) {
1812 bat = cfs_list_entry(console_session.ses_bat_list.next,
1813 lstcon_batch_t, bat_link);
1815 lstcon_batch_destroy(bat);
1818 /* destroy all groups */
1819 while (!cfs_list_empty(&console_session.ses_grp_list)) {
1820 grp = cfs_list_entry(console_session.ses_grp_list.next,
1821 lstcon_group_t, grp_link);
1822 LASSERT (grp->grp_ref == 1);
1824 lstcon_group_put(grp);
1827 /* all nodes should be released */
1828 LASSERT (cfs_list_empty(&console_session.ses_ndl_list));
1830 console_session.ses_shutdown = 0;
1831 console_session.ses_expired = 0;
1837 lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
1839 srpc_msg_t *rep = &rpc->srpc_replymsg;
1840 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1841 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1842 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1843 lstcon_group_t *grp = NULL;
1844 lstcon_ndlink_t *ndl;
1847 sfw_unpack_message(req);
1849 cfs_mutex_down(&console_session.ses_mutex);
1851 jrep->join_sid = console_session.ses_id;
1853 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1854 jrep->join_status = ESRCH;
1858 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1859 !lstcon_session_match(jreq->join_sid)) {
1860 jrep->join_status = EBUSY;
1864 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1865 rc = lstcon_group_alloc(jreq->join_group, &grp);
1867 CERROR("Out of memory\n");
1871 cfs_list_add_tail(&grp->grp_link,
1872 &console_session.ses_grp_list);
1873 lstcon_group_addref(grp);
1876 if (grp->grp_ref > 2) {
1877 /* Group in using */
1878 jrep->join_status = EBUSY;
1882 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1884 jrep->join_status = EEXIST;
1888 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1890 CERROR("Out of memory\n");
1894 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1895 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1897 if (grp->grp_userland == 0)
1898 grp->grp_userland = 1;
1900 strcpy(jrep->join_session, console_session.ses_name);
1901 jrep->join_timeout = console_session.ses_timeout;
1902 jrep->join_status = 0;
1906 lstcon_group_put(grp);
1908 cfs_mutex_up(&console_session.ses_mutex);
1913 srpc_service_t lstcon_acceptor_service;
1914 void lstcon_init_acceptor_service(void)
1916 /* initialize selftest console acceptor service table */
1917 lstcon_acceptor_service.sv_name = "join session";
1918 lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
1919 lstcon_acceptor_service.sv_id = SRPC_SERVICE_JOIN;
1920 lstcon_acceptor_service.sv_concur = SFW_SERVICE_CONCURRENCY;
1923 extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
1925 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
1927 /* initialize console */
1929 lstcon_console_init(void)
1935 memset(&console_session, 0, sizeof(lstcon_session_t));
1937 console_session.ses_id = LST_INVALID_SID;
1938 console_session.ses_state = LST_SESSION_NONE;
1939 console_session.ses_timeout = 0;
1940 console_session.ses_force = 0;
1941 console_session.ses_expired = 0;
1942 console_session.ses_laststamp = cfs_time_current_sec();
1944 cfs_init_mutex(&console_session.ses_mutex);
1946 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_list);
1947 CFS_INIT_LIST_HEAD(&console_session.ses_grp_list);
1948 CFS_INIT_LIST_HEAD(&console_session.ses_bat_list);
1949 CFS_INIT_LIST_HEAD(&console_session.ses_trans_list);
1951 LIBCFS_ALLOC(console_session.ses_ndl_hash,
1952 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
1953 if (console_session.ses_ndl_hash == NULL)
1956 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1957 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
1960 /* initialize acceptor service table */
1961 lstcon_init_acceptor_service();
1963 rc = srpc_add_service(&lstcon_acceptor_service);
1964 LASSERT (rc != -EBUSY);
1966 LIBCFS_FREE(console_session.ses_ndl_hash,
1967 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
1971 n = srpc_service_add_buffers(&lstcon_acceptor_service, SFW_POST_BUFFERS);
1972 if (n != SFW_POST_BUFFERS) {
1977 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
1980 lstcon_rpc_module_init();
1985 srpc_shutdown_service(&lstcon_acceptor_service);
1986 srpc_remove_service(&lstcon_acceptor_service);
1988 LIBCFS_FREE(console_session.ses_ndl_hash,
1989 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
1991 srpc_wait_service_shutdown(&lstcon_acceptor_service);
1997 lstcon_console_fini(void)
2001 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
2003 cfs_mutex_down(&console_session.ses_mutex);
2005 srpc_shutdown_service(&lstcon_acceptor_service);
2006 srpc_remove_service(&lstcon_acceptor_service);
2008 if (console_session.ses_state != LST_SESSION_NONE)
2009 lstcon_session_end();
2011 lstcon_rpc_module_fini();
2013 cfs_mutex_up(&console_session.ses_mutex);
2015 LASSERT (cfs_list_empty(&console_session.ses_ndl_list));
2016 LASSERT (cfs_list_empty(&console_session.ses_grp_list));
2017 LASSERT (cfs_list_empty(&console_session.ses_bat_list));
2018 LASSERT (cfs_list_empty(&console_session.ses_trans_list));
2020 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
2021 LASSERT (cfs_list_empty(&console_session.ses_ndl_hash[i]));
2024 LIBCFS_FREE(console_session.ses_ndl_hash,
2025 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
2027 srpc_wait_service_shutdown(&lstcon_acceptor_service);