2 * -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
3 * vim:expandtab:shiftwidth=8:tabstop=8:
7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 only,
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License version 2 for more details (a copy is included
17 * in the LICENSE file that accompanied this code).
19 * You should have received a copy of the GNU General Public License
20 * version 2 along with this program; If not, see [sun.com URL with a
23 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24 * CA 95054 USA or visit www.sun.com if you need additional information or
30 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
31 * Use is subject to license terms.
34 * This file is part of Lustre, http://www.lustre.org/
35 * Lustre is a trademark of Sun Microsystems, Inc.
37 * lnet/selftest/conctl.c
39 * Infrastructure of LST console
41 * Author: Liang Zhen <liangzhen@clusterfs.com>
46 #include <libcfs/libcfs.h>
47 #include <lnet/lib-lnet.h>
51 #define LST_NODE_STATE_COUNTER(nd, p) \
53 if ((nd)->nd_state == LST_NODE_ACTIVE) \
54 (p)->nle_nactive ++; \
55 else if ((nd)->nd_state == LST_NODE_BUSY) \
57 else if ((nd)->nd_state == LST_NODE_DOWN) \
60 (p)->nle_nunknown ++; \
64 lstcon_session_t console_session;
67 lstcon_node_get(lstcon_node_t *nd)
69 LASSERT (nd->nd_ref >= 1);
75 lstcon_node_find(lnet_process_id_t id, lstcon_node_t **ndpp, int create)
78 unsigned int idx = LNET_NIDADDR(id.nid) % LST_GLOBAL_HASHSIZE;
80 LASSERT (id.nid != LNET_NID_ANY);
82 list_for_each_entry(ndl, &console_session.ses_ndl_hash[idx], 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 list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
114 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 (!list_empty(&ndl->ndl_link));
132 LASSERT (!list_empty(&ndl->ndl_hlink));
134 /* remove from session */
135 list_del(&ndl->ndl_link);
136 list_del(&ndl->ndl_hlink);
138 LIBCFS_FREE(nd, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
142 lstcon_ndlink_find(struct list_head *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 list_for_each_entry(ndl, &hash[idx], ndl_hlink) {
155 if (ndl->ndl_node->nd_id.nid != id.nid ||
156 ndl->ndl_node->nd_id.pid != id.pid)
166 /* find or create in session hash */
167 rc = lstcon_node_find(id, &nd, (create == 1) ? 1 : 0);
171 LIBCFS_ALLOC(ndl, sizeof(lstcon_ndlink_t));
180 CFS_INIT_LIST_HEAD(&ndl->ndl_link);
181 list_add_tail(&ndl->ndl_hlink, &hash[idx]);
187 lstcon_ndlink_release(lstcon_ndlink_t *ndl)
189 LASSERT (list_empty(&ndl->ndl_link));
190 LASSERT (!list_empty(&ndl->ndl_hlink));
192 list_del(&ndl->ndl_hlink); /* delete from hash */
193 lstcon_node_put(ndl->ndl_node);
195 LIBCFS_FREE(ndl, sizeof(*ndl));
199 lstcon_group_alloc(char *name, lstcon_group_t **grpp)
204 LIBCFS_ALLOC(grp, offsetof(lstcon_group_t,
205 grp_ndl_hash[LST_NODE_HASHSIZE]));
209 memset(grp, 0, offsetof(lstcon_group_t,
210 grp_ndl_hash[LST_NODE_HASHSIZE]));
214 strcpy(grp->grp_name, name);
216 CFS_INIT_LIST_HEAD(&grp->grp_link);
217 CFS_INIT_LIST_HEAD(&grp->grp_ndl_list);
218 CFS_INIT_LIST_HEAD(&grp->grp_trans_list);
220 for (i = 0; i < LST_NODE_HASHSIZE; i++)
221 CFS_INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
229 lstcon_group_addref(lstcon_group_t *grp)
234 static void lstcon_group_ndlink_release(lstcon_group_t *, lstcon_ndlink_t *);
237 lstcon_group_drain(lstcon_group_t *grp, int keep)
239 lstcon_ndlink_t *ndl;
240 lstcon_ndlink_t *tmp;
242 list_for_each_entry_safe(ndl, tmp, &grp->grp_ndl_list, ndl_link) {
243 if ((ndl->ndl_node->nd_state & keep) == 0)
244 lstcon_group_ndlink_release(grp, ndl);
249 lstcon_group_decref(lstcon_group_t *grp)
253 if (--grp->grp_ref > 0)
256 if (!list_empty(&grp->grp_link))
257 list_del(&grp->grp_link);
259 lstcon_group_drain(grp, 0);
261 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
262 LASSERT (list_empty(&grp->grp_ndl_hash[i]));
265 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
266 grp_ndl_hash[LST_NODE_HASHSIZE]));
270 lstcon_group_find(char *name, lstcon_group_t **grpp)
274 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
275 if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
278 lstcon_group_addref(grp); /* +1 ref for caller */
287 lstcon_group_put(lstcon_group_t *grp)
289 lstcon_group_decref(grp);
293 lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id,
294 lstcon_ndlink_t **ndlpp, int create)
298 rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
302 if (!list_empty(&(*ndlpp)->ndl_link))
305 list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
312 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
314 list_del_init(&ndl->ndl_link);
315 lstcon_ndlink_release(ndl);
320 lstcon_group_ndlink_move(lstcon_group_t *old,
321 lstcon_group_t *new, lstcon_ndlink_t *ndl)
323 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
326 list_del(&ndl->ndl_hlink);
327 list_del(&ndl->ndl_link);
330 list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
331 list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
338 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
340 lstcon_ndlink_t *ndl;
342 while (!list_empty(&old->grp_ndl_list)) {
343 ndl = list_entry(old->grp_ndl_list.next,
344 lstcon_ndlink_t, ndl_link);
345 lstcon_group_ndlink_move(old, new, ndl);
350 lstcon_sesrpc_condition(int transop, lstcon_node_t *nd, void *arg)
352 lstcon_group_t *grp = (lstcon_group_t *)arg;
355 case LST_TRANS_SESNEW:
356 if (nd->nd_state == LST_NODE_ACTIVE)
360 case LST_TRANS_SESEND:
361 if (nd->nd_state != LST_NODE_ACTIVE)
364 if (grp != NULL && nd->nd_ref > 1)
368 case LST_TRANS_SESQRY:
379 lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
380 lstcon_rpc_ent_t *ent_up)
382 srpc_debug_reply_t *rep;
385 case LST_TRANS_SESNEW:
386 case LST_TRANS_SESEND:
389 case LST_TRANS_SESQRY:
390 rep = &msg->msg_body.dbg_reply;
392 if (copy_to_user(&ent_up->rpe_priv[0],
393 &rep->dbg_timeout, sizeof(int)) ||
394 copy_to_user(&ent_up->rpe_payload[0],
395 &rep->dbg_name, LST_NAME_SIZE))
408 lstcon_group_nodes_add(lstcon_group_t *grp, int count,
409 lnet_process_id_t *ids_up, struct list_head *result_up)
411 lstcon_rpc_trans_t *trans;
412 lstcon_ndlink_t *ndl;
414 lnet_process_id_t id;
418 rc = lstcon_group_alloc(NULL, &tmp);
420 CERROR("Out of memory\n");
424 for (i = 0 ; i < count; i++) {
425 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
430 /* skip if it's in this group already */
431 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
435 /* add to tmp group */
436 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
438 CERROR("Can't create ndlink, out of memory\n");
444 lstcon_group_put(tmp);
448 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
449 &tmp->grp_trans_list, LST_TRANS_SESNEW,
450 tmp, lstcon_sesrpc_condition, &trans);
452 CERROR("Can't create transaction: %d\n", rc);
453 lstcon_group_put(tmp);
458 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
460 rc = lstcon_rpc_trans_interpreter(trans, result_up,
461 lstcon_sesrpc_readent);
462 /* destroy all RPGs */
463 lstcon_rpc_trans_destroy(trans);
465 lstcon_group_move(tmp, grp);
466 lstcon_group_put(tmp);
472 lstcon_group_nodes_remove(lstcon_group_t *grp,
473 int count, lnet_process_id_t *ids_up,
474 struct list_head *result_up)
476 lstcon_rpc_trans_t *trans;
477 lstcon_ndlink_t *ndl;
479 lnet_process_id_t id;
483 /* End session and remove node from the group */
485 rc = lstcon_group_alloc(NULL, &tmp);
487 CERROR("Out of memory\n");
491 for (i = 0; i < count; i++) {
492 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
497 /* move node to tmp group */
498 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
499 lstcon_group_ndlink_move(grp, tmp, ndl);
502 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
503 &tmp->grp_trans_list, LST_TRANS_SESEND,
504 tmp, lstcon_sesrpc_condition, &trans);
506 CERROR("Can't create transaction: %d\n", rc);
510 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
512 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
514 lstcon_rpc_trans_destroy(trans);
515 /* release nodes anyway, because we can't rollback status */
516 lstcon_group_put(tmp);
520 lstcon_group_move(tmp, grp);
521 lstcon_group_put(tmp);
527 lstcon_group_add(char *name)
532 rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
534 /* find a group with same name */
535 lstcon_group_put(grp);
539 rc = lstcon_group_alloc(name, &grp);
541 CERROR("Can't allocate descriptor for group %s\n", name);
545 list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
551 lstcon_nodes_add(char *name, int count,
552 lnet_process_id_t *ids_up, struct list_head *result_up)
558 LASSERT (ids_up != NULL);
560 rc = lstcon_group_find(name, &grp);
562 CDEBUG(D_NET, "Can't find group %s\n", name);
566 if (grp->grp_ref > 2) {
567 /* referred by other threads or test */
568 CDEBUG(D_NET, "Group %s is busy\n", name);
569 lstcon_group_put(grp);
574 rc = lstcon_group_nodes_add(grp, count, ids_up, result_up);
576 lstcon_group_put(grp);
582 lstcon_group_del(char *name)
584 lstcon_rpc_trans_t *trans;
588 rc = lstcon_group_find(name, &grp);
590 CDEBUG(D_NET, "Can't find group: %s\n", name);
594 if (grp->grp_ref > 2) {
595 /* referred by others threads or test */
596 CDEBUG(D_NET, "Group %s is busy\n", name);
597 lstcon_group_put(grp);
601 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
602 &grp->grp_trans_list, LST_TRANS_SESEND,
603 grp, lstcon_sesrpc_condition, &trans);
605 CERROR("Can't create transaction: %d\n", rc);
606 lstcon_group_put(grp);
610 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
612 lstcon_rpc_trans_destroy(trans);
614 lstcon_group_put(grp);
615 /* -ref for session, it's destroyed,
616 * status can't be rolled back, destroy group anway */
617 lstcon_group_put(grp);
623 lstcon_group_clean(char *name, int args)
625 lstcon_group_t *grp = NULL;
628 rc = lstcon_group_find(name, &grp);
630 CDEBUG(D_NET, "Can't find group %s\n", name);
634 if (grp->grp_ref > 2) {
635 /* referred by test */
636 CDEBUG(D_NET, "Group %s is busy\n", name);
637 lstcon_group_put(grp);
641 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
642 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
644 lstcon_group_drain(grp, args);
646 lstcon_group_put(grp);
647 /* release empty group */
648 if (list_empty(&grp->grp_ndl_list))
649 lstcon_group_put(grp);
655 lstcon_nodes_remove(char *name, int count,
656 lnet_process_id_t *ids_up, struct list_head *result_up)
658 lstcon_group_t *grp = NULL;
661 rc = lstcon_group_find(name, &grp);
663 CDEBUG(D_NET, "Can't find group: %s\n", name);
667 if (grp->grp_ref > 2) {
668 /* referred by test */
669 CDEBUG(D_NET, "Group %s is busy\n", name);
670 lstcon_group_put(grp);
674 rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
676 lstcon_group_put(grp);
677 /* release empty group */
678 if (list_empty(&grp->grp_ndl_list))
679 lstcon_group_put(grp);
685 lstcon_group_refresh(char *name, struct list_head *result_up)
687 lstcon_rpc_trans_t *trans;
691 rc = lstcon_group_find(name, &grp);
693 CDEBUG(D_NET, "Can't find group: %s\n", name);
697 if (grp->grp_ref > 2) {
698 /* referred by test */
699 CDEBUG(D_NET, "Group %s is busy\n", name);
700 lstcon_group_put(grp);
704 /* re-invite all inactive nodes int the group */
705 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
706 &grp->grp_trans_list, LST_TRANS_SESNEW,
707 grp, lstcon_sesrpc_condition, &trans);
709 /* local error, return */
710 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
711 lstcon_group_put(grp);
715 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
717 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
719 lstcon_rpc_trans_destroy(trans);
721 lstcon_group_put(grp);
727 lstcon_group_list(int index, int len, char *name_up)
731 LASSERT (index >= 0);
732 LASSERT (name_up != NULL);
734 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
736 return copy_to_user(name_up, grp->grp_name, len) ?
745 lstcon_nodes_getent(struct list_head *head, int *index_p,
746 int *count_p, lstcon_node_ent_t *dents_up)
748 lstcon_ndlink_t *ndl;
753 LASSERT (index_p != NULL && count_p != NULL);
754 LASSERT (dents_up != NULL);
755 LASSERT (*index_p >= 0);
756 LASSERT (*count_p > 0);
758 list_for_each_entry(ndl, head, ndl_link) {
759 if (index++ < *index_p)
762 if (count >= *count_p)
766 if (copy_to_user(&dents_up[count].nde_id,
767 &nd->nd_id, sizeof(nd->nd_id)) ||
768 copy_to_user(&dents_up[count].nde_state,
769 &nd->nd_state, sizeof(nd->nd_state)))
775 if (index <= *index_p)
785 lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p,
786 int *index_p, int *count_p, lstcon_node_ent_t *dents_up)
788 lstcon_ndlist_ent_t *gentp;
790 lstcon_ndlink_t *ndl;
793 rc = lstcon_group_find(name, &grp);
795 CDEBUG(D_NET, "Can't find group %s\n", name);
801 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
802 index_p, count_p, dents_up);
803 lstcon_group_put(grp);
808 /* non-verbose query */
809 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
811 CERROR("Can't allocate ndlist_ent\n");
812 lstcon_group_put(grp);
817 memset(gentp, 0, sizeof(lstcon_ndlist_ent_t));
819 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link)
820 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
822 rc = copy_to_user(gents_p, gentp,
823 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT: 0;
825 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
827 lstcon_group_put(grp);
833 lstcon_batch_find(char *name, lstcon_batch_t **batpp)
837 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
838 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
848 lstcon_batch_add(char *name)
854 rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
856 CDEBUG(D_NET, "Batch %s already exists\n", name);
860 LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
862 CERROR("Can't allocate descriptor for batch %s\n", name);
866 LIBCFS_ALLOC(bat->bat_cli_hash,
867 sizeof(struct list_head) * LST_NODE_HASHSIZE);
868 if (bat->bat_cli_hash == NULL) {
869 CERROR("Can't allocate hash for batch %s\n", name);
870 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
875 LIBCFS_ALLOC(bat->bat_srv_hash,
876 sizeof(struct list_head) * LST_NODE_HASHSIZE);
877 if (bat->bat_srv_hash == NULL) {
878 CERROR("Can't allocate hash for batch %s\n", name);
879 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
880 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
885 strcpy(bat->bat_name, name);
886 bat->bat_hdr.tsb_index = 0;
887 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
890 bat->bat_state = LST_BATCH_IDLE;
892 CFS_INIT_LIST_HEAD(&bat->bat_cli_list);
893 CFS_INIT_LIST_HEAD(&bat->bat_srv_list);
894 CFS_INIT_LIST_HEAD(&bat->bat_test_list);
895 CFS_INIT_LIST_HEAD(&bat->bat_trans_list);
897 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
898 CFS_INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
899 CFS_INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
902 list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
908 lstcon_batch_list(int index, int len, char *name_up)
912 LASSERT (name_up != NULL);
913 LASSERT (index >= 0);
915 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
917 return copy_to_user(name_up,bat->bat_name, len) ?
926 lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
927 int testidx, int *index_p, int *ndent_p,
928 lstcon_node_ent_t *dents_up)
930 lstcon_test_batch_ent_t *entp;
931 struct list_head *clilst;
932 struct list_head *srvlst;
933 lstcon_test_t *test = NULL;
935 lstcon_ndlink_t *ndl;
938 rc = lstcon_batch_find(name, &bat);
940 CDEBUG(D_NET, "Can't find batch %s\n", name);
945 /* query test, test index start from 1 */
946 list_for_each_entry(test, &bat->bat_test_list, tes_link) {
952 CDEBUG(D_NET, "Can't find specified test in batch\n");
957 clilst = (test == NULL) ? &bat->bat_cli_list :
958 &test->tes_src_grp->grp_ndl_list;
959 srvlst = (test == NULL) ? &bat->bat_srv_list :
960 &test->tes_dst_grp->grp_ndl_list;
962 if (dents_up != NULL) {
963 rc = lstcon_nodes_getent((server ? srvlst: clilst),
964 index_p, ndent_p, dents_up);
968 /* non-verbose query */
969 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
973 memset(entp, 0, sizeof(lstcon_test_batch_ent_t));
976 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
977 entp->u.tbe_batch.bae_state = bat->bat_state;
981 entp->u.tbe_test.tse_type = test->tes_type;
982 entp->u.tbe_test.tse_loop = test->tes_loop;
983 entp->u.tbe_test.tse_concur = test->tes_concur;
986 list_for_each_entry(ndl, clilst, ndl_link)
987 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
989 list_for_each_entry(ndl, srvlst, ndl_link)
990 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
992 rc = copy_to_user(ent_up, entp,
993 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
995 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
1001 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1004 case LST_TRANS_TSBRUN:
1005 if (nd->nd_state != LST_NODE_ACTIVE)
1009 case LST_TRANS_TSBSTOP:
1010 if (nd->nd_state != LST_NODE_ACTIVE)
1014 case LST_TRANS_TSBCLIQRY:
1015 case LST_TRANS_TSBSRVQRY:
1023 lstcon_batch_op(lstcon_batch_t *bat, int transop, struct list_head *result_up)
1025 lstcon_rpc_trans_t *trans;
1028 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1029 &bat->bat_trans_list, transop,
1030 bat, lstcon_batrpc_condition, &trans);
1032 CERROR("Can't create transaction: %d\n", rc);
1036 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1038 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1040 lstcon_rpc_trans_destroy(trans);
1046 lstcon_batch_run(char *name, int timeout, struct list_head *result_up)
1048 lstcon_batch_t *bat;
1051 if (lstcon_batch_find(name, &bat) != 0) {
1052 CDEBUG(D_NET, "Can't find batch %s\n", name);
1056 bat->bat_arg = timeout;
1058 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1060 /* mark batch as running if it's started in any node */
1061 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1062 bat->bat_state = LST_BATCH_RUNNING;
1068 lstcon_batch_stop(char *name, int force, struct list_head *result_up)
1070 lstcon_batch_t *bat;
1073 if (lstcon_batch_find(name, &bat) != 0) {
1074 CDEBUG(D_NET, "Can't find batch %s\n", name);
1078 bat->bat_arg = force;
1080 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1082 /* mark batch as stopped if all RPCs finished */
1083 if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1084 bat->bat_state = LST_BATCH_IDLE;
1090 lstcon_batch_destroy(lstcon_batch_t *bat)
1092 lstcon_ndlink_t *ndl;
1093 lstcon_test_t *test;
1096 list_del(&bat->bat_link);
1098 while (!list_empty(&bat->bat_test_list)) {
1099 test = list_entry(bat->bat_test_list.next,
1100 lstcon_test_t, tes_link);
1101 LASSERT (list_empty(&test->tes_trans_list));
1103 list_del(&test->tes_link);
1105 lstcon_group_put(test->tes_src_grp);
1106 lstcon_group_put(test->tes_dst_grp);
1108 LIBCFS_FREE(test, offsetof(lstcon_test_t,
1109 tes_param[test->tes_paramlen]));
1112 LASSERT (list_empty(&bat->bat_trans_list));
1114 while (!list_empty(&bat->bat_cli_list)) {
1115 ndl = list_entry(bat->bat_cli_list.next,
1116 lstcon_ndlink_t, ndl_link);
1117 list_del_init(&ndl->ndl_link);
1119 lstcon_ndlink_release(ndl);
1122 while (!list_empty(&bat->bat_srv_list)) {
1123 ndl = list_entry(bat->bat_srv_list.next,
1124 lstcon_ndlink_t, ndl_link);
1125 list_del_init(&ndl->ndl_link);
1127 lstcon_ndlink_release(ndl);
1130 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1131 LASSERT (list_empty(&bat->bat_cli_hash[i]));
1132 LASSERT (list_empty(&bat->bat_srv_hash[i]));
1135 LIBCFS_FREE(bat->bat_cli_hash,
1136 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1137 LIBCFS_FREE(bat->bat_srv_hash,
1138 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1139 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
1143 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1145 lstcon_test_t *test;
1146 lstcon_batch_t *batch;
1147 lstcon_ndlink_t *ndl;
1148 struct list_head *hash;
1149 struct list_head *head;
1151 test = (lstcon_test_t *)arg;
1152 LASSERT (test != NULL);
1154 batch = test->tes_batch;
1155 LASSERT (batch != NULL);
1157 if (test->tes_oneside &&
1158 transop == LST_TRANS_TSBSRVADD)
1161 if (nd->nd_state != LST_NODE_ACTIVE)
1164 if (transop == LST_TRANS_TSBCLIADD) {
1165 hash = batch->bat_cli_hash;
1166 head = &batch->bat_cli_list;
1169 LASSERT (transop == LST_TRANS_TSBSRVADD);
1171 hash = batch->bat_srv_hash;
1172 head = &batch->bat_srv_list;
1175 LASSERT (nd->nd_id.nid != LNET_NID_ANY);
1177 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1180 if (list_empty(&ndl->ndl_link))
1181 list_add_tail(&ndl->ndl_link, head);
1187 lstcon_test_nodes_add(lstcon_test_t *test, struct list_head *result_up)
1189 lstcon_rpc_trans_t *trans;
1190 lstcon_group_t *grp;
1194 LASSERT (test->tes_src_grp != NULL);
1195 LASSERT (test->tes_dst_grp != NULL);
1197 transop = LST_TRANS_TSBSRVADD;
1198 grp = test->tes_dst_grp;
1200 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1201 &test->tes_trans_list, transop,
1202 test, lstcon_testrpc_condition, &trans);
1204 CERROR("Can't create transaction: %d\n", rc);
1208 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1210 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1211 lstcon_trans_stat()->trs_fwk_errno != 0) {
1212 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1214 lstcon_rpc_trans_destroy(trans);
1215 /* return if any error */
1216 CDEBUG(D_NET, "Failed to add test %s, "
1217 "RPC error %d, framework error %d\n",
1218 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1219 lstcon_trans_stat()->trs_rpc_errno,
1220 lstcon_trans_stat()->trs_fwk_errno);
1225 lstcon_rpc_trans_destroy(trans);
1227 if (transop == LST_TRANS_TSBCLIADD)
1230 transop = LST_TRANS_TSBCLIADD;
1231 grp = test->tes_src_grp;
1232 test->tes_cliidx = 0;
1234 /* requests to test clients */
1239 lstcon_test_add(char *name, int type, int loop, int concur,
1240 int dist, int span, char *src_name, char * dst_name,
1241 void *param, int paramlen, int *retp, struct list_head *result_up)
1244 lstcon_group_t *src_grp = NULL;
1245 lstcon_group_t *dst_grp = NULL;
1246 lstcon_test_t *test = NULL;
1247 lstcon_batch_t *batch;
1250 rc = lstcon_batch_find(name, &batch);
1252 CDEBUG(D_NET, "Can't find batch %s\n", name);
1256 if (batch->bat_state != LST_BATCH_IDLE) {
1257 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1261 rc = lstcon_group_find(src_name, &src_grp);
1263 CDEBUG(D_NET, "Can't find group %s\n", src_name);
1267 rc = lstcon_group_find(dst_name, &dst_grp);
1269 CDEBUG(D_NET, "Can't find group %s\n", dst_name);
1273 if (dst_grp->grp_userland)
1276 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1278 CERROR("Can't allocate test descriptor\n");
1284 memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen]));
1285 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1286 test->tes_batch = batch;
1287 test->tes_type = type;
1288 test->tes_oneside = 0; /* TODO */
1289 test->tes_loop = loop;
1290 test->tes_concur = concur;
1291 test->tes_stop_onerr = 1; /* TODO */
1292 test->tes_span = span;
1293 test->tes_dist = dist;
1294 test->tes_cliidx = 0; /* just used for creating RPC */
1295 test->tes_src_grp = src_grp;
1296 test->tes_dst_grp = dst_grp;
1297 CFS_INIT_LIST_HEAD(&test->tes_trans_list);
1299 if (param != NULL) {
1300 test->tes_paramlen = paramlen;
1301 memcpy(&test->tes_param[0], param, paramlen);
1304 rc = lstcon_test_nodes_add(test, result_up);
1309 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1310 lstcon_trans_stat()->trs_fwk_errno != 0)
1311 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type, name);
1313 /* add to test list anyway, so user can check what's going on */
1314 list_add_tail(&test->tes_link, &batch->bat_test_list);
1316 batch->bat_ntest ++;
1317 test->tes_hdr.tsb_index = batch->bat_ntest;
1319 /* hold groups so nobody can change them */
1323 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1325 if (dst_grp != NULL)
1326 lstcon_group_put(dst_grp);
1328 if (src_grp != NULL)
1329 lstcon_group_put(src_grp);
1335 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1337 lstcon_test_t *test;
1339 list_for_each_entry(test, &batch->bat_test_list, tes_link) {
1340 if (idx == test->tes_hdr.tsb_index) {
1350 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1351 lstcon_rpc_ent_t *ent_up)
1353 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1355 LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1356 transop == LST_TRANS_TSBSRVQRY);
1358 /* positive errno, framework error code */
1359 if (copy_to_user(&ent_up->rpe_priv[0],
1360 &rep->bar_active, sizeof(rep->bar_active)))
1367 lstcon_test_batch_query(char *name, int testidx, int client,
1368 int timeout, struct list_head *result_up)
1370 lstcon_rpc_trans_t *trans;
1371 struct list_head *translist;
1372 struct list_head *ndlist;
1373 lstcon_tsb_hdr_t *hdr;
1374 lstcon_batch_t *batch;
1375 lstcon_test_t *test = NULL;
1379 rc = lstcon_batch_find(name, &batch);
1381 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1386 translist = &batch->bat_trans_list;
1387 ndlist = &batch->bat_cli_list;
1388 hdr = &batch->bat_hdr;
1391 /* query specified test only */
1392 rc = lstcon_test_find(batch, testidx, &test);
1394 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1398 translist = &test->tes_trans_list;
1399 ndlist = &test->tes_src_grp->grp_ndl_list;
1400 hdr = &test->tes_hdr;
1403 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1405 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1406 lstcon_batrpc_condition, &trans);
1408 CERROR("Can't create transaction: %d\n", rc);
1412 lstcon_rpc_trans_postwait(trans, timeout);
1414 if (testidx == 0 && /* query a batch, not a test */
1415 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1416 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1417 /* all RPCs finished, and no active test */
1418 batch->bat_state = LST_BATCH_IDLE;
1421 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1422 lstcon_tsbrpc_readent);
1423 lstcon_rpc_trans_destroy(trans);
1429 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1430 lstcon_rpc_ent_t *ent_up)
1432 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1433 sfw_counters_t *sfwk_stat;
1434 srpc_counters_t *srpc_stat;
1435 lnet_counters_t *lnet_stat;
1437 if (rep->str_status != 0)
1440 sfwk_stat = (sfw_counters_t *)&ent_up->rpe_payload[0];
1441 srpc_stat = (srpc_counters_t *)((char *)sfwk_stat + sizeof(*sfwk_stat));
1442 lnet_stat = (lnet_counters_t *)((char *)srpc_stat + sizeof(*srpc_stat));
1444 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1445 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1446 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1453 lstcon_ndlist_stat(struct list_head *ndlist,
1454 int timeout, struct list_head *result_up)
1456 struct list_head head;
1457 lstcon_rpc_trans_t *trans;
1460 CFS_INIT_LIST_HEAD(&head);
1462 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1463 LST_TRANS_STATQRY, NULL, NULL, &trans);
1465 CERROR("Can't create transaction: %d\n", rc);
1469 timeout = (timeout > LST_TRANS_MIN_TIMEOUT) ? timeout :
1470 LST_TRANS_MIN_TIMEOUT;
1471 lstcon_rpc_trans_postwait(trans, timeout);
1473 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1474 lstcon_statrpc_readent);
1475 lstcon_rpc_trans_destroy(trans);
1481 lstcon_group_stat(char *grp_name, int timeout, struct list_head *result_up)
1483 lstcon_group_t *grp;
1486 rc = lstcon_group_find(grp_name, &grp);
1488 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1492 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1494 lstcon_group_put(grp);
1500 lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
1501 int timeout, struct list_head *result_up)
1503 lstcon_ndlink_t *ndl;
1504 lstcon_group_t *tmp;
1505 lnet_process_id_t id;
1509 rc = lstcon_group_alloc(NULL, &tmp);
1511 CERROR("Out of memory\n");
1515 for (i = 0 ; i < count; i++) {
1516 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1521 /* add to tmp group */
1522 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1524 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1525 "Failed to find or create %s: %d\n",
1526 libcfs_id2str(id), rc);
1532 lstcon_group_put(tmp);
1536 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1538 lstcon_group_put(tmp);
1544 lstcon_debug_ndlist(struct list_head *ndlist,
1545 struct list_head *translist,
1546 int timeout, struct list_head *result_up)
1548 lstcon_rpc_trans_t *trans;
1551 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1552 NULL, lstcon_sesrpc_condition, &trans);
1554 CERROR("Can't create transaction: %d\n", rc);
1558 timeout = (timeout > LST_TRANS_MIN_TIMEOUT) ? timeout :
1559 LST_TRANS_MIN_TIMEOUT;
1561 lstcon_rpc_trans_postwait(trans, timeout);
1563 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1564 lstcon_sesrpc_readent);
1565 lstcon_rpc_trans_destroy(trans);
1571 lstcon_session_debug(int timeout, struct list_head *result_up)
1573 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1574 NULL, timeout, result_up);
1578 lstcon_batch_debug(int timeout, char *name,
1579 int client, struct list_head *result_up)
1581 lstcon_batch_t *bat;
1584 rc = lstcon_batch_find(name, &bat);
1588 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1590 NULL, timeout, result_up);
1596 lstcon_group_debug(int timeout, char *name,
1597 struct list_head *result_up)
1599 lstcon_group_t *grp;
1602 rc = lstcon_group_find(name, &grp);
1606 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1607 timeout, result_up);
1608 lstcon_group_put(grp);
1614 lstcon_nodes_debug(int timeout,
1615 int count, lnet_process_id_t *ids_up,
1616 struct list_head *result_up)
1618 lnet_process_id_t id;
1619 lstcon_ndlink_t *ndl;
1620 lstcon_group_t *grp;
1624 rc = lstcon_group_alloc(NULL, &grp);
1626 CDEBUG(D_NET, "Out of memory\n");
1630 for (i = 0; i < count; i++) {
1631 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1636 /* node is added to tmp group */
1637 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1639 CERROR("Can't create node link\n");
1645 lstcon_group_put(grp);
1649 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1650 timeout, result_up);
1652 lstcon_group_put(grp);
1658 lstcon_session_match(lst_sid_t sid)
1660 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1661 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1: 0;
1665 lstcon_new_session_id(lst_sid_t *sid)
1667 lnet_process_id_t id;
1669 LASSERT (console_session.ses_state == LST_SESSION_NONE);
1672 sid->ses_nid = id.nid;
1673 sid->ses_stamp = cfs_time_current();
1676 extern srpc_service_t lstcon_acceptor_service;
1679 lstcon_session_new(char *name, int key,
1680 int timeout,int force, lst_sid_t *sid_up)
1685 if (console_session.ses_state != LST_SESSION_NONE) {
1686 /* session exists */
1688 CERROR("Session %s already exists\n",
1689 console_session.ses_name);
1693 rc = lstcon_session_end();
1695 /* lstcon_session_end() only return local error */
1700 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++) {
1701 LASSERT (list_empty(&console_session.ses_ndl_hash[i]));
1704 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1708 rc = lstcon_rpc_pinger_start();
1710 lstcon_batch_t *bat;
1712 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1713 lstcon_batch_destroy(bat);
1718 lstcon_new_session_id(&console_session.ses_id);
1720 console_session.ses_key = key;
1721 console_session.ses_state = LST_SESSION_ACTIVE;
1722 console_session.ses_force = !!force;
1723 console_session.ses_timeout = (timeout <= 0)? LST_CONSOLE_TIMEOUT:
1725 strcpy(console_session.ses_name, name);
1727 if (copy_to_user(sid_up, &console_session.ses_id,
1728 sizeof(lst_sid_t)) == 0)
1731 lstcon_session_end();
1737 lstcon_session_info(lst_sid_t *sid_up, int *key_up,
1738 lstcon_ndlist_ent_t *ndinfo_up, char *name_up, int len)
1740 lstcon_ndlist_ent_t *entp;
1741 lstcon_ndlink_t *ndl;
1744 if (console_session.ses_state != LST_SESSION_ACTIVE)
1747 LIBCFS_ALLOC(entp, sizeof(*entp));
1751 memset(entp, 0, sizeof(*entp));
1753 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link)
1754 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1756 if (copy_to_user(sid_up, &console_session.ses_id, sizeof(lst_sid_t)) ||
1757 copy_to_user(key_up, &console_session.ses_key, sizeof(int)) ||
1758 copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1759 copy_to_user(name_up, console_session.ses_name, len))
1762 LIBCFS_FREE(entp, sizeof(*entp));
1768 lstcon_session_end()
1770 lstcon_rpc_trans_t *trans;
1771 lstcon_group_t *grp;
1772 lstcon_batch_t *bat;
1775 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1777 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1778 NULL, LST_TRANS_SESEND, NULL,
1779 lstcon_sesrpc_condition, &trans);
1781 CERROR("Can't create transaction: %d\n", rc);
1785 console_session.ses_shutdown = 1;
1787 lstcon_rpc_pinger_stop();
1789 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1791 lstcon_rpc_trans_destroy(trans);
1792 /* User can do nothing even rpc failed, so go on */
1794 /* waiting for orphan rpcs to die */
1795 lstcon_rpc_cleanup_wait();
1797 console_session.ses_id = LST_INVALID_SID;
1798 console_session.ses_state = LST_SESSION_NONE;
1799 console_session.ses_key = 0;
1800 console_session.ses_force = 0;
1802 /* destroy all batches */
1803 while (!list_empty(&console_session.ses_bat_list)) {
1804 bat = list_entry(console_session.ses_bat_list.next,
1805 lstcon_batch_t, bat_link);
1807 lstcon_batch_destroy(bat);
1810 /* destroy all groups */
1811 while (!list_empty(&console_session.ses_grp_list)) {
1812 grp = list_entry(console_session.ses_grp_list.next,
1813 lstcon_group_t, grp_link);
1814 LASSERT (grp->grp_ref == 1);
1816 lstcon_group_put(grp);
1819 /* all nodes should be released */
1820 LASSERT (list_empty(&console_session.ses_ndl_list));
1822 console_session.ses_shutdown = 0;
1823 console_session.ses_expired = 0;
1829 lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
1831 srpc_msg_t *rep = &rpc->srpc_replymsg;
1832 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1833 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1834 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1835 lstcon_group_t *grp = NULL;
1836 lstcon_ndlink_t *ndl;
1839 sfw_unpack_message(req);
1841 mutex_down(&console_session.ses_mutex);
1843 jrep->join_sid = console_session.ses_id;
1845 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1846 jrep->join_status = ESRCH;
1850 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1851 !lstcon_session_match(jreq->join_sid)) {
1852 jrep->join_status = EBUSY;
1856 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1857 rc = lstcon_group_alloc(jreq->join_group, &grp);
1859 CERROR("Out of memory\n");
1863 list_add_tail(&grp->grp_link,
1864 &console_session.ses_grp_list);
1865 lstcon_group_addref(grp);
1868 if (grp->grp_ref > 2) {
1869 /* Group in using */
1870 jrep->join_status = EBUSY;
1874 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1876 jrep->join_status = EEXIST;
1880 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1882 CERROR("Out of memory\n");
1886 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1887 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1889 if (grp->grp_userland == 0)
1890 grp->grp_userland = 1;
1892 strcpy(jrep->join_session, console_session.ses_name);
1893 jrep->join_timeout = console_session.ses_timeout;
1894 jrep->join_status = 0;
1898 lstcon_group_put(grp);
1900 mutex_up(&console_session.ses_mutex);
1905 srpc_service_t lstcon_acceptor_service =
1907 .sv_name = "join session",
1908 .sv_handler = lstcon_acceptor_handle,
1909 .sv_bulk_ready = NULL,
1910 .sv_id = SRPC_SERVICE_JOIN,
1911 .sv_concur = SFW_SERVICE_CONCURRENCY,
1914 extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
1916 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
1918 /* initialize console */
1920 lstcon_console_init(void)
1926 memset(&console_session, 0, sizeof(lstcon_session_t));
1928 console_session.ses_id = LST_INVALID_SID;
1929 console_session.ses_state = LST_SESSION_NONE;
1930 console_session.ses_timeout = 0;
1931 console_session.ses_force = 0;
1932 console_session.ses_expired = 0;
1933 console_session.ses_laststamp = cfs_time_current_sec();
1935 init_mutex(&console_session.ses_mutex);
1937 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_list);
1938 CFS_INIT_LIST_HEAD(&console_session.ses_grp_list);
1939 CFS_INIT_LIST_HEAD(&console_session.ses_bat_list);
1940 CFS_INIT_LIST_HEAD(&console_session.ses_trans_list);
1942 LIBCFS_ALLOC(console_session.ses_ndl_hash,
1943 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1944 if (console_session.ses_ndl_hash == NULL)
1947 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1948 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
1950 rc = srpc_add_service(&lstcon_acceptor_service);
1951 LASSERT (rc != -EBUSY);
1953 LIBCFS_FREE(console_session.ses_ndl_hash,
1954 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1958 n = srpc_service_add_buffers(&lstcon_acceptor_service, SFW_POST_BUFFERS);
1959 if (n != SFW_POST_BUFFERS) {
1964 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
1967 lstcon_rpc_module_init();
1972 srpc_shutdown_service(&lstcon_acceptor_service);
1973 srpc_remove_service(&lstcon_acceptor_service);
1975 LIBCFS_FREE(console_session.ses_ndl_hash,
1976 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1978 srpc_wait_service_shutdown(&lstcon_acceptor_service);
1984 lstcon_console_fini(void)
1988 mutex_down(&console_session.ses_mutex);
1990 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
1992 srpc_shutdown_service(&lstcon_acceptor_service);
1993 srpc_remove_service(&lstcon_acceptor_service);
1995 if (console_session.ses_state != LST_SESSION_NONE)
1996 lstcon_session_end();
1998 lstcon_rpc_module_fini();
2000 mutex_up(&console_session.ses_mutex);
2002 LASSERT (list_empty(&console_session.ses_ndl_list));
2003 LASSERT (list_empty(&console_session.ses_grp_list));
2004 LASSERT (list_empty(&console_session.ses_bat_list));
2005 LASSERT (list_empty(&console_session.ses_trans_list));
2007 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
2008 LASSERT (list_empty(&console_session.ses_ndl_hash[i]));
2011 LIBCFS_FREE(console_session.ses_ndl_hash,
2012 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2014 srpc_wait_service_shutdown(&lstcon_acceptor_service);