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 2008 Sun Microsystems, Inc. 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 list_for_each_entry(ndl, &console_session.ses_ndl_hash[idx], ndl_hlink) {
82 if (ndl->ndl_node->nd_id.nid != id.nid ||
83 ndl->ndl_node->nd_id.pid != id.pid)
86 lstcon_node_get(ndl->ndl_node);
87 *ndpp = ndl->ndl_node;
94 LIBCFS_ALLOC(*ndpp, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
98 ndl = (lstcon_ndlink_t *)(*ndpp + 1);
100 ndl->ndl_node = *ndpp;
102 ndl->ndl_node->nd_ref = 1;
103 ndl->ndl_node->nd_id = id;
104 ndl->ndl_node->nd_stamp = cfs_time_current();
105 ndl->ndl_node->nd_state = LST_NODE_UNKNOWN;
106 ndl->ndl_node->nd_timeout = 0;
107 memset(&ndl->ndl_node->nd_ping, 0, sizeof(lstcon_rpc_t));
109 /* queued in global hash & list, no refcount is taken by
110 * global hash & list, if caller release his refcount,
111 * node will be released */
112 list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
113 list_add_tail(&ndl->ndl_link, &console_session.ses_ndl_list);
119 lstcon_node_put(lstcon_node_t *nd)
121 lstcon_ndlink_t *ndl;
123 LASSERT (nd->nd_ref > 0);
125 if (--nd->nd_ref > 0)
128 ndl = (lstcon_ndlink_t *)(nd + 1);
130 LASSERT (!list_empty(&ndl->ndl_link));
131 LASSERT (!list_empty(&ndl->ndl_hlink));
133 /* remove from session */
134 list_del(&ndl->ndl_link);
135 list_del(&ndl->ndl_hlink);
137 LIBCFS_FREE(nd, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
141 lstcon_ndlink_find(struct list_head *hash,
142 lnet_process_id_t id, lstcon_ndlink_t **ndlpp, int create)
144 unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
145 lstcon_ndlink_t *ndl;
149 if (id.nid == LNET_NID_ANY)
153 list_for_each_entry(ndl, &hash[idx], ndl_hlink) {
154 if (ndl->ndl_node->nd_id.nid != id.nid ||
155 ndl->ndl_node->nd_id.pid != id.pid)
165 /* find or create in session hash */
166 rc = lstcon_node_find(id, &nd, (create == 1) ? 1 : 0);
170 LIBCFS_ALLOC(ndl, sizeof(lstcon_ndlink_t));
179 CFS_INIT_LIST_HEAD(&ndl->ndl_link);
180 list_add_tail(&ndl->ndl_hlink, &hash[idx]);
186 lstcon_ndlink_release(lstcon_ndlink_t *ndl)
188 LASSERT (list_empty(&ndl->ndl_link));
189 LASSERT (!list_empty(&ndl->ndl_hlink));
191 list_del(&ndl->ndl_hlink); /* delete from hash */
192 lstcon_node_put(ndl->ndl_node);
194 LIBCFS_FREE(ndl, sizeof(*ndl));
198 lstcon_group_alloc(char *name, lstcon_group_t **grpp)
203 LIBCFS_ALLOC(grp, offsetof(lstcon_group_t,
204 grp_ndl_hash[LST_NODE_HASHSIZE]));
208 memset(grp, 0, offsetof(lstcon_group_t,
209 grp_ndl_hash[LST_NODE_HASHSIZE]));
213 strcpy(grp->grp_name, name);
215 CFS_INIT_LIST_HEAD(&grp->grp_link);
216 CFS_INIT_LIST_HEAD(&grp->grp_ndl_list);
217 CFS_INIT_LIST_HEAD(&grp->grp_trans_list);
219 for (i = 0; i < LST_NODE_HASHSIZE; i++)
220 CFS_INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
228 lstcon_group_addref(lstcon_group_t *grp)
233 static void lstcon_group_ndlink_release(lstcon_group_t *, lstcon_ndlink_t *);
236 lstcon_group_drain(lstcon_group_t *grp, int keep)
238 lstcon_ndlink_t *ndl;
239 lstcon_ndlink_t *tmp;
241 list_for_each_entry_safe(ndl, tmp, &grp->grp_ndl_list, ndl_link) {
242 if ((ndl->ndl_node->nd_state & keep) == 0)
243 lstcon_group_ndlink_release(grp, ndl);
248 lstcon_group_decref(lstcon_group_t *grp)
252 if (--grp->grp_ref > 0)
255 if (!list_empty(&grp->grp_link))
256 list_del(&grp->grp_link);
258 lstcon_group_drain(grp, 0);
260 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
261 LASSERT (list_empty(&grp->grp_ndl_hash[i]));
264 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
265 grp_ndl_hash[LST_NODE_HASHSIZE]));
269 lstcon_group_find(char *name, lstcon_group_t **grpp)
273 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
274 if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
277 lstcon_group_addref(grp); /* +1 ref for caller */
286 lstcon_group_put(lstcon_group_t *grp)
288 lstcon_group_decref(grp);
292 lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id,
293 lstcon_ndlink_t **ndlpp, int create)
297 rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
301 if (!list_empty(&(*ndlpp)->ndl_link))
304 list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
311 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
313 list_del_init(&ndl->ndl_link);
314 lstcon_ndlink_release(ndl);
319 lstcon_group_ndlink_move(lstcon_group_t *old,
320 lstcon_group_t *new, lstcon_ndlink_t *ndl)
322 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
325 list_del(&ndl->ndl_hlink);
326 list_del(&ndl->ndl_link);
329 list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
330 list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
337 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
339 lstcon_ndlink_t *ndl;
341 while (!list_empty(&old->grp_ndl_list)) {
342 ndl = list_entry(old->grp_ndl_list.next,
343 lstcon_ndlink_t, ndl_link);
344 lstcon_group_ndlink_move(old, new, ndl);
349 lstcon_sesrpc_condition(int transop, lstcon_node_t *nd, void *arg)
351 lstcon_group_t *grp = (lstcon_group_t *)arg;
354 case LST_TRANS_SESNEW:
355 if (nd->nd_state == LST_NODE_ACTIVE)
359 case LST_TRANS_SESEND:
360 if (nd->nd_state != LST_NODE_ACTIVE)
363 if (grp != NULL && nd->nd_ref > 1)
367 case LST_TRANS_SESQRY:
378 lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
379 lstcon_rpc_ent_t *ent_up)
381 srpc_debug_reply_t *rep;
384 case LST_TRANS_SESNEW:
385 case LST_TRANS_SESEND:
388 case LST_TRANS_SESQRY:
389 rep = &msg->msg_body.dbg_reply;
391 if (copy_to_user(&ent_up->rpe_priv[0],
392 &rep->dbg_timeout, sizeof(int)) ||
393 copy_to_user(&ent_up->rpe_payload[0],
394 &rep->dbg_name, LST_NAME_SIZE))
407 lstcon_group_nodes_add(lstcon_group_t *grp, int count,
408 lnet_process_id_t *ids_up, struct list_head *result_up)
410 lstcon_rpc_trans_t *trans;
411 lstcon_ndlink_t *ndl;
413 lnet_process_id_t id;
417 rc = lstcon_group_alloc(NULL, &tmp);
419 CERROR("Out of memory\n");
423 for (i = 0 ; i < count; i++) {
424 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
429 /* skip if it's in this group already */
430 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
434 /* add to tmp group */
435 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
437 CERROR("Can't create ndlink, out of memory\n");
443 lstcon_group_put(tmp);
447 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
448 &tmp->grp_trans_list, LST_TRANS_SESNEW,
449 tmp, lstcon_sesrpc_condition, &trans);
451 CERROR("Can't create transaction: %d\n", rc);
452 lstcon_group_put(tmp);
457 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
459 rc = lstcon_rpc_trans_interpreter(trans, result_up,
460 lstcon_sesrpc_readent);
461 /* destroy all RPGs */
462 lstcon_rpc_trans_destroy(trans);
464 lstcon_group_move(tmp, grp);
465 lstcon_group_put(tmp);
471 lstcon_group_nodes_remove(lstcon_group_t *grp,
472 int count, lnet_process_id_t *ids_up,
473 struct list_head *result_up)
475 lstcon_rpc_trans_t *trans;
476 lstcon_ndlink_t *ndl;
478 lnet_process_id_t id;
482 /* End session and remove node from the group */
484 rc = lstcon_group_alloc(NULL, &tmp);
486 CERROR("Out of memory\n");
490 for (i = 0; i < count; i++) {
491 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
496 /* move node to tmp group */
497 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
498 lstcon_group_ndlink_move(grp, tmp, ndl);
501 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
502 &tmp->grp_trans_list, LST_TRANS_SESEND,
503 tmp, lstcon_sesrpc_condition, &trans);
505 CERROR("Can't create transaction: %d\n", rc);
509 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
511 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
513 lstcon_rpc_trans_destroy(trans);
514 /* release nodes anyway, because we can't rollback status */
515 lstcon_group_put(tmp);
519 lstcon_group_move(tmp, grp);
520 lstcon_group_put(tmp);
526 lstcon_group_add(char *name)
531 rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
533 /* find a group with same name */
534 lstcon_group_put(grp);
538 rc = lstcon_group_alloc(name, &grp);
540 CERROR("Can't allocate descriptor for group %s\n", name);
544 list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
550 lstcon_nodes_add(char *name, int count,
551 lnet_process_id_t *ids_up, struct list_head *result_up)
557 LASSERT (ids_up != NULL);
559 rc = lstcon_group_find(name, &grp);
561 CDEBUG(D_NET, "Can't find group %s\n", name);
565 if (grp->grp_ref > 2) {
566 /* referred by other threads or test */
567 CDEBUG(D_NET, "Group %s is busy\n", name);
568 lstcon_group_put(grp);
573 rc = lstcon_group_nodes_add(grp, count, ids_up, result_up);
575 lstcon_group_put(grp);
581 lstcon_group_del(char *name)
583 lstcon_rpc_trans_t *trans;
587 rc = lstcon_group_find(name, &grp);
589 CDEBUG(D_NET, "Can't find group: %s\n", name);
593 if (grp->grp_ref > 2) {
594 /* referred by others threads or test */
595 CDEBUG(D_NET, "Group %s is busy\n", name);
596 lstcon_group_put(grp);
600 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
601 &grp->grp_trans_list, LST_TRANS_SESEND,
602 grp, lstcon_sesrpc_condition, &trans);
604 CERROR("Can't create transaction: %d\n", rc);
605 lstcon_group_put(grp);
609 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
611 lstcon_rpc_trans_destroy(trans);
613 lstcon_group_put(grp);
614 /* -ref for session, it's destroyed,
615 * status can't be rolled back, destroy group anway */
616 lstcon_group_put(grp);
622 lstcon_group_clean(char *name, int args)
624 lstcon_group_t *grp = NULL;
627 rc = lstcon_group_find(name, &grp);
629 CDEBUG(D_NET, "Can't find group %s\n", name);
633 if (grp->grp_ref > 2) {
634 /* referred by test */
635 CDEBUG(D_NET, "Group %s is busy\n", name);
636 lstcon_group_put(grp);
640 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
641 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
643 lstcon_group_drain(grp, args);
645 lstcon_group_put(grp);
646 /* release empty group */
647 if (list_empty(&grp->grp_ndl_list))
648 lstcon_group_put(grp);
654 lstcon_nodes_remove(char *name, int count,
655 lnet_process_id_t *ids_up, struct list_head *result_up)
657 lstcon_group_t *grp = NULL;
660 rc = lstcon_group_find(name, &grp);
662 CDEBUG(D_NET, "Can't find group: %s\n", name);
666 if (grp->grp_ref > 2) {
667 /* referred by test */
668 CDEBUG(D_NET, "Group %s is busy\n", name);
669 lstcon_group_put(grp);
673 rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
675 lstcon_group_put(grp);
676 /* release empty group */
677 if (list_empty(&grp->grp_ndl_list))
678 lstcon_group_put(grp);
684 lstcon_group_refresh(char *name, struct list_head *result_up)
686 lstcon_rpc_trans_t *trans;
690 rc = lstcon_group_find(name, &grp);
692 CDEBUG(D_NET, "Can't find group: %s\n", name);
696 if (grp->grp_ref > 2) {
697 /* referred by test */
698 CDEBUG(D_NET, "Group %s is busy\n", name);
699 lstcon_group_put(grp);
703 /* re-invite all inactive nodes int the group */
704 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
705 &grp->grp_trans_list, LST_TRANS_SESNEW,
706 grp, lstcon_sesrpc_condition, &trans);
708 /* local error, return */
709 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
710 lstcon_group_put(grp);
714 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
716 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
718 lstcon_rpc_trans_destroy(trans);
720 lstcon_group_put(grp);
726 lstcon_group_list(int index, int len, char *name_up)
730 LASSERT (index >= 0);
731 LASSERT (name_up != NULL);
733 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
735 return copy_to_user(name_up, grp->grp_name, len) ?
744 lstcon_nodes_getent(struct list_head *head, int *index_p,
745 int *count_p, lstcon_node_ent_t *dents_up)
747 lstcon_ndlink_t *ndl;
752 LASSERT (index_p != NULL && count_p != NULL);
753 LASSERT (dents_up != NULL);
754 LASSERT (*index_p >= 0);
755 LASSERT (*count_p > 0);
757 list_for_each_entry(ndl, head, ndl_link) {
758 if (index++ < *index_p)
761 if (count >= *count_p)
765 if (copy_to_user(&dents_up[count].nde_id,
766 &nd->nd_id, sizeof(nd->nd_id)) ||
767 copy_to_user(&dents_up[count].nde_state,
768 &nd->nd_state, sizeof(nd->nd_state)))
774 if (index <= *index_p)
784 lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p,
785 int *index_p, int *count_p, lstcon_node_ent_t *dents_up)
787 lstcon_ndlist_ent_t *gentp;
789 lstcon_ndlink_t *ndl;
792 rc = lstcon_group_find(name, &grp);
794 CDEBUG(D_NET, "Can't find group %s\n", name);
800 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
801 index_p, count_p, dents_up);
802 lstcon_group_put(grp);
807 /* non-verbose query */
808 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
810 CERROR("Can't allocate ndlist_ent\n");
811 lstcon_group_put(grp);
816 memset(gentp, 0, sizeof(lstcon_ndlist_ent_t));
818 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link)
819 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
821 rc = copy_to_user(gents_p, gentp,
822 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT: 0;
824 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
826 lstcon_group_put(grp);
832 lstcon_batch_find(char *name, lstcon_batch_t **batpp)
836 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
837 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
847 lstcon_batch_add(char *name)
853 rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
855 CDEBUG(D_NET, "Batch %s already exists\n", name);
859 LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
861 CERROR("Can't allocate descriptor for batch %s\n", name);
865 LIBCFS_ALLOC(bat->bat_cli_hash,
866 sizeof(struct list_head) * LST_NODE_HASHSIZE);
867 if (bat->bat_cli_hash == NULL) {
868 CERROR("Can't allocate hash for batch %s\n", name);
869 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
874 LIBCFS_ALLOC(bat->bat_srv_hash,
875 sizeof(struct list_head) * LST_NODE_HASHSIZE);
876 if (bat->bat_srv_hash == NULL) {
877 CERROR("Can't allocate hash for batch %s\n", name);
878 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
879 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
884 strcpy(bat->bat_name, name);
885 bat->bat_hdr.tsb_index = 0;
886 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
889 bat->bat_state = LST_BATCH_IDLE;
891 CFS_INIT_LIST_HEAD(&bat->bat_cli_list);
892 CFS_INIT_LIST_HEAD(&bat->bat_srv_list);
893 CFS_INIT_LIST_HEAD(&bat->bat_test_list);
894 CFS_INIT_LIST_HEAD(&bat->bat_trans_list);
896 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
897 CFS_INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
898 CFS_INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
901 list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
907 lstcon_batch_list(int index, int len, char *name_up)
911 LASSERT (name_up != NULL);
912 LASSERT (index >= 0);
914 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
916 return copy_to_user(name_up,bat->bat_name, len) ?
925 lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
926 int testidx, int *index_p, int *ndent_p,
927 lstcon_node_ent_t *dents_up)
929 lstcon_test_batch_ent_t *entp;
930 struct list_head *clilst;
931 struct list_head *srvlst;
932 lstcon_test_t *test = NULL;
934 lstcon_ndlink_t *ndl;
937 rc = lstcon_batch_find(name, &bat);
939 CDEBUG(D_NET, "Can't find batch %s\n", name);
944 /* query test, test index start from 1 */
945 list_for_each_entry(test, &bat->bat_test_list, tes_link) {
951 CDEBUG(D_NET, "Can't find specified test in batch\n");
956 clilst = (test == NULL) ? &bat->bat_cli_list :
957 &test->tes_src_grp->grp_ndl_list;
958 srvlst = (test == NULL) ? &bat->bat_srv_list :
959 &test->tes_dst_grp->grp_ndl_list;
961 if (dents_up != NULL) {
962 rc = lstcon_nodes_getent((server ? srvlst: clilst),
963 index_p, ndent_p, dents_up);
967 /* non-verbose query */
968 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
972 memset(entp, 0, sizeof(lstcon_test_batch_ent_t));
975 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
976 entp->u.tbe_batch.bae_state = bat->bat_state;
980 entp->u.tbe_test.tse_type = test->tes_type;
981 entp->u.tbe_test.tse_loop = test->tes_loop;
982 entp->u.tbe_test.tse_concur = test->tes_concur;
985 list_for_each_entry(ndl, clilst, ndl_link)
986 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
988 list_for_each_entry(ndl, srvlst, ndl_link)
989 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
991 rc = copy_to_user(ent_up, entp,
992 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
994 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
1000 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1003 case LST_TRANS_TSBRUN:
1004 if (nd->nd_state != LST_NODE_ACTIVE)
1008 case LST_TRANS_TSBSTOP:
1009 if (nd->nd_state != LST_NODE_ACTIVE)
1013 case LST_TRANS_TSBCLIQRY:
1014 case LST_TRANS_TSBSRVQRY:
1022 lstcon_batch_op(lstcon_batch_t *bat, int transop, struct list_head *result_up)
1024 lstcon_rpc_trans_t *trans;
1027 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1028 &bat->bat_trans_list, transop,
1029 bat, lstcon_batrpc_condition, &trans);
1031 CERROR("Can't create transaction: %d\n", rc);
1035 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1037 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1039 lstcon_rpc_trans_destroy(trans);
1045 lstcon_batch_run(char *name, int timeout, struct list_head *result_up)
1047 lstcon_batch_t *bat;
1050 if (lstcon_batch_find(name, &bat) != 0) {
1051 CDEBUG(D_NET, "Can't find batch %s\n", name);
1055 bat->bat_arg = timeout;
1057 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1059 /* mark batch as running if it's started in any node */
1060 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1061 bat->bat_state = LST_BATCH_RUNNING;
1067 lstcon_batch_stop(char *name, int force, struct list_head *result_up)
1069 lstcon_batch_t *bat;
1072 if (lstcon_batch_find(name, &bat) != 0) {
1073 CDEBUG(D_NET, "Can't find batch %s\n", name);
1077 bat->bat_arg = force;
1079 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1081 /* mark batch as stopped if all RPCs finished */
1082 if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1083 bat->bat_state = LST_BATCH_IDLE;
1089 lstcon_batch_destroy(lstcon_batch_t *bat)
1091 lstcon_ndlink_t *ndl;
1092 lstcon_test_t *test;
1095 list_del(&bat->bat_link);
1097 while (!list_empty(&bat->bat_test_list)) {
1098 test = list_entry(bat->bat_test_list.next,
1099 lstcon_test_t, tes_link);
1100 LASSERT (list_empty(&test->tes_trans_list));
1102 list_del(&test->tes_link);
1104 lstcon_group_put(test->tes_src_grp);
1105 lstcon_group_put(test->tes_dst_grp);
1107 LIBCFS_FREE(test, offsetof(lstcon_test_t,
1108 tes_param[test->tes_paramlen]));
1111 LASSERT (list_empty(&bat->bat_trans_list));
1113 while (!list_empty(&bat->bat_cli_list)) {
1114 ndl = list_entry(bat->bat_cli_list.next,
1115 lstcon_ndlink_t, ndl_link);
1116 list_del_init(&ndl->ndl_link);
1118 lstcon_ndlink_release(ndl);
1121 while (!list_empty(&bat->bat_srv_list)) {
1122 ndl = list_entry(bat->bat_srv_list.next,
1123 lstcon_ndlink_t, ndl_link);
1124 list_del_init(&ndl->ndl_link);
1126 lstcon_ndlink_release(ndl);
1129 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1130 LASSERT (list_empty(&bat->bat_cli_hash[i]));
1131 LASSERT (list_empty(&bat->bat_srv_hash[i]));
1134 LIBCFS_FREE(bat->bat_cli_hash,
1135 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1136 LIBCFS_FREE(bat->bat_srv_hash,
1137 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1138 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
1142 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1144 lstcon_test_t *test;
1145 lstcon_batch_t *batch;
1146 lstcon_ndlink_t *ndl;
1147 struct list_head *hash;
1148 struct list_head *head;
1150 test = (lstcon_test_t *)arg;
1151 LASSERT (test != NULL);
1153 batch = test->tes_batch;
1154 LASSERT (batch != NULL);
1156 if (test->tes_oneside &&
1157 transop == LST_TRANS_TSBSRVADD)
1160 if (nd->nd_state != LST_NODE_ACTIVE)
1163 if (transop == LST_TRANS_TSBCLIADD) {
1164 hash = batch->bat_cli_hash;
1165 head = &batch->bat_cli_list;
1168 LASSERT (transop == LST_TRANS_TSBSRVADD);
1170 hash = batch->bat_srv_hash;
1171 head = &batch->bat_srv_list;
1174 LASSERT (nd->nd_id.nid != LNET_NID_ANY);
1176 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1179 if (list_empty(&ndl->ndl_link))
1180 list_add_tail(&ndl->ndl_link, head);
1186 lstcon_test_nodes_add(lstcon_test_t *test, struct list_head *result_up)
1188 lstcon_rpc_trans_t *trans;
1189 lstcon_group_t *grp;
1193 LASSERT (test->tes_src_grp != NULL);
1194 LASSERT (test->tes_dst_grp != NULL);
1196 transop = LST_TRANS_TSBSRVADD;
1197 grp = test->tes_dst_grp;
1199 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1200 &test->tes_trans_list, transop,
1201 test, lstcon_testrpc_condition, &trans);
1203 CERROR("Can't create transaction: %d\n", rc);
1207 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1209 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1210 lstcon_trans_stat()->trs_fwk_errno != 0) {
1211 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1213 lstcon_rpc_trans_destroy(trans);
1214 /* return if any error */
1215 CDEBUG(D_NET, "Failed to add test %s, "
1216 "RPC error %d, framework error %d\n",
1217 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1218 lstcon_trans_stat()->trs_rpc_errno,
1219 lstcon_trans_stat()->trs_fwk_errno);
1224 lstcon_rpc_trans_destroy(trans);
1226 if (transop == LST_TRANS_TSBCLIADD)
1229 transop = LST_TRANS_TSBCLIADD;
1230 grp = test->tes_src_grp;
1231 test->tes_cliidx = 0;
1233 /* requests to test clients */
1238 lstcon_test_add(char *name, int type, int loop, int concur,
1239 int dist, int span, char *src_name, char * dst_name,
1240 void *param, int paramlen, int *retp, struct list_head *result_up)
1243 lstcon_group_t *src_grp = NULL;
1244 lstcon_group_t *dst_grp = NULL;
1245 lstcon_test_t *test = NULL;
1246 lstcon_batch_t *batch;
1249 rc = lstcon_batch_find(name, &batch);
1251 CDEBUG(D_NET, "Can't find batch %s\n", name);
1255 if (batch->bat_state != LST_BATCH_IDLE) {
1256 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1260 rc = lstcon_group_find(src_name, &src_grp);
1262 CDEBUG(D_NET, "Can't find group %s\n", src_name);
1266 rc = lstcon_group_find(dst_name, &dst_grp);
1268 CDEBUG(D_NET, "Can't find group %s\n", dst_name);
1272 if (dst_grp->grp_userland)
1275 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1277 CERROR("Can't allocate test descriptor\n");
1283 memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen]));
1284 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1285 test->tes_batch = batch;
1286 test->tes_type = type;
1287 test->tes_oneside = 0; /* TODO */
1288 test->tes_loop = loop;
1289 test->tes_concur = concur;
1290 test->tes_stop_onerr = 1; /* TODO */
1291 test->tes_span = span;
1292 test->tes_dist = dist;
1293 test->tes_cliidx = 0; /* just used for creating RPC */
1294 test->tes_src_grp = src_grp;
1295 test->tes_dst_grp = dst_grp;
1296 CFS_INIT_LIST_HEAD(&test->tes_trans_list);
1298 if (param != NULL) {
1299 test->tes_paramlen = paramlen;
1300 memcpy(&test->tes_param[0], param, paramlen);
1303 rc = lstcon_test_nodes_add(test, result_up);
1308 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1309 lstcon_trans_stat()->trs_fwk_errno != 0)
1310 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type, name);
1312 /* add to test list anyway, so user can check what's going on */
1313 list_add_tail(&test->tes_link, &batch->bat_test_list);
1315 batch->bat_ntest ++;
1316 test->tes_hdr.tsb_index = batch->bat_ntest;
1318 /* hold groups so nobody can change them */
1322 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1324 if (dst_grp != NULL)
1325 lstcon_group_put(dst_grp);
1327 if (src_grp != NULL)
1328 lstcon_group_put(src_grp);
1334 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1336 lstcon_test_t *test;
1338 list_for_each_entry(test, &batch->bat_test_list, tes_link) {
1339 if (idx == test->tes_hdr.tsb_index) {
1349 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1350 lstcon_rpc_ent_t *ent_up)
1352 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1354 LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1355 transop == LST_TRANS_TSBSRVQRY);
1357 /* positive errno, framework error code */
1358 if (copy_to_user(&ent_up->rpe_priv[0],
1359 &rep->bar_active, sizeof(rep->bar_active)))
1366 lstcon_test_batch_query(char *name, int testidx, int client,
1367 int timeout, struct list_head *result_up)
1369 lstcon_rpc_trans_t *trans;
1370 struct list_head *translist;
1371 struct list_head *ndlist;
1372 lstcon_tsb_hdr_t *hdr;
1373 lstcon_batch_t *batch;
1374 lstcon_test_t *test = NULL;
1378 rc = lstcon_batch_find(name, &batch);
1380 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1385 translist = &batch->bat_trans_list;
1386 ndlist = &batch->bat_cli_list;
1387 hdr = &batch->bat_hdr;
1390 /* query specified test only */
1391 rc = lstcon_test_find(batch, testidx, &test);
1393 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1397 translist = &test->tes_trans_list;
1398 ndlist = &test->tes_src_grp->grp_ndl_list;
1399 hdr = &test->tes_hdr;
1402 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1404 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1405 lstcon_batrpc_condition, &trans);
1407 CERROR("Can't create transaction: %d\n", rc);
1411 lstcon_rpc_trans_postwait(trans, timeout);
1413 if (testidx == 0 && /* query a batch, not a test */
1414 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1415 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1416 /* all RPCs finished, and no active test */
1417 batch->bat_state = LST_BATCH_IDLE;
1420 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1421 lstcon_tsbrpc_readent);
1422 lstcon_rpc_trans_destroy(trans);
1428 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1429 lstcon_rpc_ent_t *ent_up)
1431 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1432 sfw_counters_t *sfwk_stat;
1433 srpc_counters_t *srpc_stat;
1434 lnet_counters_t *lnet_stat;
1436 if (rep->str_status != 0)
1439 sfwk_stat = (sfw_counters_t *)&ent_up->rpe_payload[0];
1440 srpc_stat = (srpc_counters_t *)((char *)sfwk_stat + sizeof(*sfwk_stat));
1441 lnet_stat = (lnet_counters_t *)((char *)srpc_stat + sizeof(*srpc_stat));
1443 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1444 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1445 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1452 lstcon_ndlist_stat(struct list_head *ndlist,
1453 int timeout, struct list_head *result_up)
1455 struct list_head head;
1456 lstcon_rpc_trans_t *trans;
1459 CFS_INIT_LIST_HEAD(&head);
1461 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1462 LST_TRANS_STATQRY, NULL, NULL, &trans);
1464 CERROR("Can't create transaction: %d\n", rc);
1468 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1470 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1471 lstcon_statrpc_readent);
1472 lstcon_rpc_trans_destroy(trans);
1478 lstcon_group_stat(char *grp_name, int timeout, struct list_head *result_up)
1480 lstcon_group_t *grp;
1483 rc = lstcon_group_find(grp_name, &grp);
1485 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1489 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1491 lstcon_group_put(grp);
1497 lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
1498 int timeout, struct list_head *result_up)
1500 lstcon_ndlink_t *ndl;
1501 lstcon_group_t *tmp;
1502 lnet_process_id_t id;
1506 rc = lstcon_group_alloc(NULL, &tmp);
1508 CERROR("Out of memory\n");
1512 for (i = 0 ; i < count; i++) {
1513 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1518 /* add to tmp group */
1519 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1521 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1522 "Failed to find or create %s: %d\n",
1523 libcfs_id2str(id), rc);
1529 lstcon_group_put(tmp);
1533 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1535 lstcon_group_put(tmp);
1541 lstcon_debug_ndlist(struct list_head *ndlist,
1542 struct list_head *translist,
1543 int timeout, struct list_head *result_up)
1545 lstcon_rpc_trans_t *trans;
1548 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1549 NULL, lstcon_sesrpc_condition, &trans);
1551 CERROR("Can't create transaction: %d\n", rc);
1555 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1557 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1558 lstcon_sesrpc_readent);
1559 lstcon_rpc_trans_destroy(trans);
1565 lstcon_session_debug(int timeout, struct list_head *result_up)
1567 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1568 NULL, timeout, result_up);
1572 lstcon_batch_debug(int timeout, char *name,
1573 int client, struct list_head *result_up)
1575 lstcon_batch_t *bat;
1578 rc = lstcon_batch_find(name, &bat);
1582 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1584 NULL, timeout, result_up);
1590 lstcon_group_debug(int timeout, char *name,
1591 struct list_head *result_up)
1593 lstcon_group_t *grp;
1596 rc = lstcon_group_find(name, &grp);
1600 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1601 timeout, result_up);
1602 lstcon_group_put(grp);
1608 lstcon_nodes_debug(int timeout,
1609 int count, lnet_process_id_t *ids_up,
1610 struct list_head *result_up)
1612 lnet_process_id_t id;
1613 lstcon_ndlink_t *ndl;
1614 lstcon_group_t *grp;
1618 rc = lstcon_group_alloc(NULL, &grp);
1620 CDEBUG(D_NET, "Out of memory\n");
1624 for (i = 0; i < count; i++) {
1625 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1630 /* node is added to tmp group */
1631 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1633 CERROR("Can't create node link\n");
1639 lstcon_group_put(grp);
1643 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1644 timeout, result_up);
1646 lstcon_group_put(grp);
1652 lstcon_session_match(lst_sid_t sid)
1654 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1655 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1: 0;
1659 lstcon_new_session_id(lst_sid_t *sid)
1661 lnet_process_id_t id;
1663 LASSERT (console_session.ses_state == LST_SESSION_NONE);
1666 sid->ses_nid = id.nid;
1667 sid->ses_stamp = cfs_time_current();
1670 extern srpc_service_t lstcon_acceptor_service;
1673 lstcon_session_new(char *name, int key,
1674 int timeout,int force, lst_sid_t *sid_up)
1679 if (console_session.ses_state != LST_SESSION_NONE) {
1680 /* session exists */
1682 CERROR("Session %s already exists\n",
1683 console_session.ses_name);
1687 rc = lstcon_session_end();
1689 /* lstcon_session_end() only return local error */
1694 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++) {
1695 LASSERT (list_empty(&console_session.ses_ndl_hash[i]));
1698 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1702 rc = lstcon_rpc_pinger_start();
1704 lstcon_batch_t *bat;
1706 if (lstcon_batch_find(LST_DEFAULT_BATCH, &bat) == 0)
1707 lstcon_batch_destroy(bat);
1712 lstcon_new_session_id(&console_session.ses_id);
1714 console_session.ses_key = key;
1715 console_session.ses_state = LST_SESSION_ACTIVE;
1716 console_session.ses_force = !!force;
1717 console_session.ses_timeout = (timeout <= 0)? LST_CONSOLE_TIMEOUT:
1719 strcpy(console_session.ses_name, name);
1721 if (copy_to_user(sid_up, &console_session.ses_id,
1722 sizeof(lst_sid_t)) == 0)
1725 lstcon_session_end();
1731 lstcon_session_info(lst_sid_t *sid_up, int *key_up,
1732 lstcon_ndlist_ent_t *ndinfo_up, char *name_up, int len)
1734 lstcon_ndlist_ent_t *entp;
1735 lstcon_ndlink_t *ndl;
1738 if (console_session.ses_state != LST_SESSION_ACTIVE)
1741 LIBCFS_ALLOC(entp, sizeof(*entp));
1745 memset(entp, 0, sizeof(*entp));
1747 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link)
1748 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1750 if (copy_to_user(sid_up, &console_session.ses_id, sizeof(lst_sid_t)) ||
1751 copy_to_user(key_up, &console_session.ses_key, sizeof(int)) ||
1752 copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1753 copy_to_user(name_up, console_session.ses_name, len))
1756 LIBCFS_FREE(entp, sizeof(*entp));
1762 lstcon_session_end()
1764 lstcon_rpc_trans_t *trans;
1765 lstcon_group_t *grp;
1766 lstcon_batch_t *bat;
1769 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1771 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1772 NULL, LST_TRANS_SESEND, NULL,
1773 lstcon_sesrpc_condition, &trans);
1775 CERROR("Can't create transaction: %d\n", rc);
1779 console_session.ses_shutdown = 1;
1781 lstcon_rpc_pinger_stop();
1783 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1785 lstcon_rpc_trans_destroy(trans);
1786 /* User can do nothing even rpc failed, so go on */
1788 /* waiting for orphan rpcs to die */
1789 lstcon_rpc_cleanup_wait();
1791 console_session.ses_id = LST_INVALID_SID;
1792 console_session.ses_state = LST_SESSION_NONE;
1793 console_session.ses_key = 0;
1794 console_session.ses_force = 0;
1796 /* destroy all batches */
1797 while (!list_empty(&console_session.ses_bat_list)) {
1798 bat = list_entry(console_session.ses_bat_list.next,
1799 lstcon_batch_t, bat_link);
1801 lstcon_batch_destroy(bat);
1804 /* destroy all groups */
1805 while (!list_empty(&console_session.ses_grp_list)) {
1806 grp = list_entry(console_session.ses_grp_list.next,
1807 lstcon_group_t, grp_link);
1808 LASSERT (grp->grp_ref == 1);
1810 lstcon_group_put(grp);
1813 /* all nodes should be released */
1814 LASSERT (list_empty(&console_session.ses_ndl_list));
1816 console_session.ses_shutdown = 0;
1817 console_session.ses_expired = 0;
1823 lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
1825 srpc_msg_t *rep = &rpc->srpc_replymsg;
1826 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1827 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1828 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1829 lstcon_group_t *grp = NULL;
1830 lstcon_ndlink_t *ndl;
1833 sfw_unpack_message(req);
1835 mutex_down(&console_session.ses_mutex);
1837 jrep->join_sid = console_session.ses_id;
1839 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1840 jrep->join_status = ESRCH;
1844 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1845 !lstcon_session_match(jreq->join_sid)) {
1846 jrep->join_status = EBUSY;
1850 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1851 rc = lstcon_group_alloc(jreq->join_group, &grp);
1853 CERROR("Out of memory\n");
1857 list_add_tail(&grp->grp_link,
1858 &console_session.ses_grp_list);
1859 lstcon_group_addref(grp);
1862 if (grp->grp_ref > 2) {
1863 /* Group in using */
1864 jrep->join_status = EBUSY;
1868 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1870 jrep->join_status = EEXIST;
1874 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1876 CERROR("Out of memory\n");
1880 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1881 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1883 if (grp->grp_userland == 0)
1884 grp->grp_userland = 1;
1886 strcpy(jrep->join_session, console_session.ses_name);
1887 jrep->join_timeout = console_session.ses_timeout;
1888 jrep->join_status = 0;
1892 lstcon_group_put(grp);
1894 mutex_up(&console_session.ses_mutex);
1899 srpc_service_t lstcon_acceptor_service =
1901 .sv_name = "join session",
1902 .sv_handler = lstcon_acceptor_handle,
1903 .sv_bulk_ready = NULL,
1904 .sv_id = SRPC_SERVICE_JOIN,
1905 .sv_concur = SFW_SERVICE_CONCURRENCY,
1908 extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
1910 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
1912 /* initialize console */
1914 lstcon_console_init(void)
1920 memset(&console_session, 0, sizeof(lstcon_session_t));
1922 console_session.ses_id = LST_INVALID_SID;
1923 console_session.ses_state = LST_SESSION_NONE;
1924 console_session.ses_timeout = 0;
1925 console_session.ses_force = 0;
1926 console_session.ses_expired = 0;
1927 console_session.ses_laststamp = cfs_time_current_sec();
1929 init_mutex(&console_session.ses_mutex);
1931 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_list);
1932 CFS_INIT_LIST_HEAD(&console_session.ses_grp_list);
1933 CFS_INIT_LIST_HEAD(&console_session.ses_bat_list);
1934 CFS_INIT_LIST_HEAD(&console_session.ses_trans_list);
1936 LIBCFS_ALLOC(console_session.ses_ndl_hash,
1937 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1938 if (console_session.ses_ndl_hash == NULL)
1941 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1942 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
1944 rc = srpc_add_service(&lstcon_acceptor_service);
1945 LASSERT (rc != -EBUSY);
1947 LIBCFS_FREE(console_session.ses_ndl_hash,
1948 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1952 n = srpc_service_add_buffers(&lstcon_acceptor_service, SFW_POST_BUFFERS);
1953 if (n != SFW_POST_BUFFERS) {
1958 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
1961 lstcon_rpc_module_init();
1966 srpc_shutdown_service(&lstcon_acceptor_service);
1967 srpc_remove_service(&lstcon_acceptor_service);
1969 LIBCFS_FREE(console_session.ses_ndl_hash,
1970 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1972 srpc_wait_service_shutdown(&lstcon_acceptor_service);
1978 lstcon_console_fini(void)
1982 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
1984 mutex_down(&console_session.ses_mutex);
1986 srpc_shutdown_service(&lstcon_acceptor_service);
1987 srpc_remove_service(&lstcon_acceptor_service);
1989 if (console_session.ses_state != LST_SESSION_NONE)
1990 lstcon_session_end();
1992 lstcon_rpc_module_fini();
1994 mutex_up(&console_session.ses_mutex);
1996 LASSERT (list_empty(&console_session.ses_ndl_list));
1997 LASSERT (list_empty(&console_session.ses_grp_list));
1998 LASSERT (list_empty(&console_session.ses_bat_list));
1999 LASSERT (list_empty(&console_session.ses_trans_list));
2001 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
2002 LASSERT (list_empty(&console_session.ses_ndl_hash[i]));
2005 LIBCFS_FREE(console_session.ses_ndl_hash,
2006 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2008 srpc_wait_service_shutdown(&lstcon_acceptor_service);