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 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 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 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 list_add_tail(&ndl->ndl_hlink, &hash[idx]);
188 lstcon_ndlink_release(lstcon_ndlink_t *ndl)
190 LASSERT (list_empty(&ndl->ndl_link));
191 LASSERT (!list_empty(&ndl->ndl_hlink));
193 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 (!list_empty(&grp->grp_link))
259 list_del(&grp->grp_link);
261 lstcon_group_drain(grp, 0);
263 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
264 LASSERT (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 (!list_empty(&(*ndlpp)->ndl_link))
308 list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
315 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
317 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 list_del(&ndl->ndl_hlink);
330 list_del(&ndl->ndl_link);
333 list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
334 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 (!list_empty(&old->grp_ndl_list)) {
346 ndl = 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 (copy_to_user(&ent_up->rpe_priv[0],
396 &rep->dbg_timeout, sizeof(int)) ||
397 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, struct list_head *result_up)
414 lstcon_rpc_trans_t *trans;
415 lstcon_ndlink_t *ndl;
417 lnet_process_id_t id;
421 rc = lstcon_group_alloc(NULL, &tmp);
423 CERROR("Out of memory\n");
427 for (i = 0 ; i < count; i++) {
428 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
433 /* skip if it's in this group already */
434 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
438 /* add to tmp group */
439 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
441 CERROR("Can't create ndlink, out of memory\n");
447 lstcon_group_put(tmp);
451 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
452 &tmp->grp_trans_list, LST_TRANS_SESNEW,
453 tmp, lstcon_sesrpc_condition, &trans);
455 CERROR("Can't create transaction: %d\n", rc);
456 lstcon_group_put(tmp);
461 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
463 rc = lstcon_rpc_trans_interpreter(trans, result_up,
464 lstcon_sesrpc_readent);
465 /* destroy all RPGs */
466 lstcon_rpc_trans_destroy(trans);
468 lstcon_group_move(tmp, grp);
469 lstcon_group_put(tmp);
475 lstcon_group_nodes_remove(lstcon_group_t *grp,
476 int count, lnet_process_id_t *ids_up,
477 struct list_head *result_up)
479 lstcon_rpc_trans_t *trans;
480 lstcon_ndlink_t *ndl;
482 lnet_process_id_t id;
486 /* End session and remove node from the group */
488 rc = lstcon_group_alloc(NULL, &tmp);
490 CERROR("Out of memory\n");
494 for (i = 0; i < count; i++) {
495 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
500 /* move node to tmp group */
501 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
502 lstcon_group_ndlink_move(grp, tmp, ndl);
505 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
506 &tmp->grp_trans_list, LST_TRANS_SESEND,
507 tmp, lstcon_sesrpc_condition, &trans);
509 CERROR("Can't create transaction: %d\n", rc);
513 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
515 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
517 lstcon_rpc_trans_destroy(trans);
518 /* release nodes anyway, because we can't rollback status */
519 lstcon_group_put(tmp);
523 lstcon_group_move(tmp, grp);
524 lstcon_group_put(tmp);
530 lstcon_group_add(char *name)
535 rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
537 /* find a group with same name */
538 lstcon_group_put(grp);
542 rc = lstcon_group_alloc(name, &grp);
544 CERROR("Can't allocate descriptor for group %s\n", name);
548 list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
554 lstcon_nodes_add(char *name, int count,
555 lnet_process_id_t *ids_up, struct list_head *result_up)
561 LASSERT (ids_up != NULL);
563 rc = lstcon_group_find(name, &grp);
565 CDEBUG(D_NET, "Can't find group %s\n", name);
569 if (grp->grp_ref > 2) {
570 /* referred by other threads or test */
571 CDEBUG(D_NET, "Group %s is busy\n", name);
572 lstcon_group_put(grp);
577 rc = lstcon_group_nodes_add(grp, count, ids_up, result_up);
579 lstcon_group_put(grp);
585 lstcon_group_del(char *name)
587 lstcon_rpc_trans_t *trans;
591 rc = lstcon_group_find(name, &grp);
593 CDEBUG(D_NET, "Can't find group: %s\n", name);
597 if (grp->grp_ref > 2) {
598 /* referred by others threads or test */
599 CDEBUG(D_NET, "Group %s is busy\n", name);
600 lstcon_group_put(grp);
604 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
605 &grp->grp_trans_list, LST_TRANS_SESEND,
606 grp, lstcon_sesrpc_condition, &trans);
608 CERROR("Can't create transaction: %d\n", rc);
609 lstcon_group_put(grp);
613 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
615 lstcon_rpc_trans_destroy(trans);
617 lstcon_group_put(grp);
618 /* -ref for session, it's destroyed,
619 * status can't be rolled back, destroy group anway */
620 lstcon_group_put(grp);
626 lstcon_group_clean(char *name, int args)
628 lstcon_group_t *grp = NULL;
631 rc = lstcon_group_find(name, &grp);
633 CDEBUG(D_NET, "Can't find group %s\n", name);
637 if (grp->grp_ref > 2) {
638 /* referred by test */
639 CDEBUG(D_NET, "Group %s is busy\n", name);
640 lstcon_group_put(grp);
644 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
645 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
647 lstcon_group_drain(grp, args);
649 lstcon_group_put(grp);
650 /* release empty group */
651 if (list_empty(&grp->grp_ndl_list))
652 lstcon_group_put(grp);
658 lstcon_nodes_remove(char *name, int count,
659 lnet_process_id_t *ids_up, struct list_head *result_up)
661 lstcon_group_t *grp = NULL;
664 rc = lstcon_group_find(name, &grp);
666 CDEBUG(D_NET, "Can't find group: %s\n", name);
670 if (grp->grp_ref > 2) {
671 /* referred by test */
672 CDEBUG(D_NET, "Group %s is busy\n", name);
673 lstcon_group_put(grp);
677 rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
679 lstcon_group_put(grp);
680 /* release empty group */
681 if (list_empty(&grp->grp_ndl_list))
682 lstcon_group_put(grp);
688 lstcon_group_refresh(char *name, struct list_head *result_up)
690 lstcon_rpc_trans_t *trans;
694 rc = lstcon_group_find(name, &grp);
696 CDEBUG(D_NET, "Can't find group: %s\n", name);
700 if (grp->grp_ref > 2) {
701 /* referred by test */
702 CDEBUG(D_NET, "Group %s is busy\n", name);
703 lstcon_group_put(grp);
707 /* re-invite all inactive nodes int the group */
708 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
709 &grp->grp_trans_list, LST_TRANS_SESNEW,
710 grp, lstcon_sesrpc_condition, &trans);
712 /* local error, return */
713 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
714 lstcon_group_put(grp);
718 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
720 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
722 lstcon_rpc_trans_destroy(trans);
724 lstcon_group_put(grp);
730 lstcon_group_list(int index, int len, char *name_up)
734 LASSERT (index >= 0);
735 LASSERT (name_up != NULL);
737 cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list,
738 lstcon_group_t, grp_link) {
740 return copy_to_user(name_up, grp->grp_name, len) ?
749 lstcon_nodes_getent(struct list_head *head, int *index_p,
750 int *count_p, lstcon_node_ent_t *dents_up)
752 lstcon_ndlink_t *ndl;
757 LASSERT (index_p != NULL && count_p != NULL);
758 LASSERT (dents_up != NULL);
759 LASSERT (*index_p >= 0);
760 LASSERT (*count_p > 0);
762 cfs_list_for_each_entry_typed(ndl, head, lstcon_ndlink_t, ndl_link) {
763 if (index++ < *index_p)
766 if (count >= *count_p)
770 if (copy_to_user(&dents_up[count].nde_id,
771 &nd->nd_id, sizeof(nd->nd_id)) ||
772 copy_to_user(&dents_up[count].nde_state,
773 &nd->nd_state, sizeof(nd->nd_state)))
779 if (index <= *index_p)
789 lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p,
790 int *index_p, int *count_p, lstcon_node_ent_t *dents_up)
792 lstcon_ndlist_ent_t *gentp;
794 lstcon_ndlink_t *ndl;
797 rc = lstcon_group_find(name, &grp);
799 CDEBUG(D_NET, "Can't find group %s\n", name);
805 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
806 index_p, count_p, dents_up);
807 lstcon_group_put(grp);
812 /* non-verbose query */
813 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
815 CERROR("Can't allocate ndlist_ent\n");
816 lstcon_group_put(grp);
821 memset(gentp, 0, sizeof(lstcon_ndlist_ent_t));
823 cfs_list_for_each_entry_typed(ndl, &grp->grp_ndl_list,
824 lstcon_ndlink_t, ndl_link)
825 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
827 rc = copy_to_user(gents_p, gentp,
828 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT: 0;
830 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
832 lstcon_group_put(grp);
838 lstcon_batch_find(char *name, lstcon_batch_t **batpp)
842 cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list,
843 lstcon_batch_t, bat_link) {
844 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
854 lstcon_batch_add(char *name)
860 rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
862 CDEBUG(D_NET, "Batch %s already exists\n", name);
866 LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
868 CERROR("Can't allocate descriptor for batch %s\n", name);
872 LIBCFS_ALLOC(bat->bat_cli_hash,
873 sizeof(struct list_head) * LST_NODE_HASHSIZE);
874 if (bat->bat_cli_hash == NULL) {
875 CERROR("Can't allocate hash for batch %s\n", name);
876 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
881 LIBCFS_ALLOC(bat->bat_srv_hash,
882 sizeof(struct list_head) * LST_NODE_HASHSIZE);
883 if (bat->bat_srv_hash == NULL) {
884 CERROR("Can't allocate hash for batch %s\n", name);
885 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
886 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
891 strcpy(bat->bat_name, name);
892 bat->bat_hdr.tsb_index = 0;
893 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
896 bat->bat_state = LST_BATCH_IDLE;
898 CFS_INIT_LIST_HEAD(&bat->bat_cli_list);
899 CFS_INIT_LIST_HEAD(&bat->bat_srv_list);
900 CFS_INIT_LIST_HEAD(&bat->bat_test_list);
901 CFS_INIT_LIST_HEAD(&bat->bat_trans_list);
903 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
904 CFS_INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
905 CFS_INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
908 list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
914 lstcon_batch_list(int index, int len, char *name_up)
918 LASSERT (name_up != NULL);
919 LASSERT (index >= 0);
921 cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list,
922 lstcon_batch_t, bat_link) {
924 return copy_to_user(name_up,bat->bat_name, len) ?
933 lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
934 int testidx, int *index_p, int *ndent_p,
935 lstcon_node_ent_t *dents_up)
937 lstcon_test_batch_ent_t *entp;
938 struct list_head *clilst;
939 struct list_head *srvlst;
940 lstcon_test_t *test = NULL;
942 lstcon_ndlink_t *ndl;
945 rc = lstcon_batch_find(name, &bat);
947 CDEBUG(D_NET, "Can't find batch %s\n", name);
952 /* query test, test index start from 1 */
953 cfs_list_for_each_entry_typed(test, &bat->bat_test_list,
954 lstcon_test_t, tes_link) {
960 CDEBUG(D_NET, "Can't find specified test in batch\n");
965 clilst = (test == NULL) ? &bat->bat_cli_list :
966 &test->tes_src_grp->grp_ndl_list;
967 srvlst = (test == NULL) ? &bat->bat_srv_list :
968 &test->tes_dst_grp->grp_ndl_list;
970 if (dents_up != NULL) {
971 rc = lstcon_nodes_getent((server ? srvlst: clilst),
972 index_p, ndent_p, dents_up);
976 /* non-verbose query */
977 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
981 memset(entp, 0, sizeof(lstcon_test_batch_ent_t));
984 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
985 entp->u.tbe_batch.bae_state = bat->bat_state;
989 entp->u.tbe_test.tse_type = test->tes_type;
990 entp->u.tbe_test.tse_loop = test->tes_loop;
991 entp->u.tbe_test.tse_concur = test->tes_concur;
994 cfs_list_for_each_entry_typed(ndl, clilst, lstcon_ndlink_t, ndl_link)
995 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
997 cfs_list_for_each_entry_typed(ndl, srvlst, lstcon_ndlink_t, ndl_link)
998 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
1000 rc = copy_to_user(ent_up, entp,
1001 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
1003 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
1009 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1012 case LST_TRANS_TSBRUN:
1013 if (nd->nd_state != LST_NODE_ACTIVE)
1017 case LST_TRANS_TSBSTOP:
1018 if (nd->nd_state != LST_NODE_ACTIVE)
1022 case LST_TRANS_TSBCLIQRY:
1023 case LST_TRANS_TSBSRVQRY:
1031 lstcon_batch_op(lstcon_batch_t *bat, int transop, struct list_head *result_up)
1033 lstcon_rpc_trans_t *trans;
1036 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1037 &bat->bat_trans_list, transop,
1038 bat, lstcon_batrpc_condition, &trans);
1040 CERROR("Can't create transaction: %d\n", rc);
1044 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1046 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1048 lstcon_rpc_trans_destroy(trans);
1054 lstcon_batch_run(char *name, int timeout, struct list_head *result_up)
1056 lstcon_batch_t *bat;
1059 if (lstcon_batch_find(name, &bat) != 0) {
1060 CDEBUG(D_NET, "Can't find batch %s\n", name);
1064 bat->bat_arg = timeout;
1066 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1068 /* mark batch as running if it's started in any node */
1069 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1070 bat->bat_state = LST_BATCH_RUNNING;
1076 lstcon_batch_stop(char *name, int force, struct list_head *result_up)
1078 lstcon_batch_t *bat;
1081 if (lstcon_batch_find(name, &bat) != 0) {
1082 CDEBUG(D_NET, "Can't find batch %s\n", name);
1086 bat->bat_arg = force;
1088 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1090 /* mark batch as stopped if all RPCs finished */
1091 if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1092 bat->bat_state = LST_BATCH_IDLE;
1098 lstcon_batch_destroy(lstcon_batch_t *bat)
1100 lstcon_ndlink_t *ndl;
1101 lstcon_test_t *test;
1104 list_del(&bat->bat_link);
1106 while (!list_empty(&bat->bat_test_list)) {
1107 test = list_entry(bat->bat_test_list.next,
1108 lstcon_test_t, tes_link);
1109 LASSERT (list_empty(&test->tes_trans_list));
1111 list_del(&test->tes_link);
1113 lstcon_group_put(test->tes_src_grp);
1114 lstcon_group_put(test->tes_dst_grp);
1116 LIBCFS_FREE(test, offsetof(lstcon_test_t,
1117 tes_param[test->tes_paramlen]));
1120 LASSERT (list_empty(&bat->bat_trans_list));
1122 while (!list_empty(&bat->bat_cli_list)) {
1123 ndl = list_entry(bat->bat_cli_list.next,
1124 lstcon_ndlink_t, ndl_link);
1125 list_del_init(&ndl->ndl_link);
1127 lstcon_ndlink_release(ndl);
1130 while (!list_empty(&bat->bat_srv_list)) {
1131 ndl = list_entry(bat->bat_srv_list.next,
1132 lstcon_ndlink_t, ndl_link);
1133 list_del_init(&ndl->ndl_link);
1135 lstcon_ndlink_release(ndl);
1138 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1139 LASSERT (list_empty(&bat->bat_cli_hash[i]));
1140 LASSERT (list_empty(&bat->bat_srv_hash[i]));
1143 LIBCFS_FREE(bat->bat_cli_hash,
1144 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1145 LIBCFS_FREE(bat->bat_srv_hash,
1146 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1147 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
1151 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1153 lstcon_test_t *test;
1154 lstcon_batch_t *batch;
1155 lstcon_ndlink_t *ndl;
1156 struct list_head *hash;
1157 struct list_head *head;
1159 test = (lstcon_test_t *)arg;
1160 LASSERT (test != NULL);
1162 batch = test->tes_batch;
1163 LASSERT (batch != NULL);
1165 if (test->tes_oneside &&
1166 transop == LST_TRANS_TSBSRVADD)
1169 if (nd->nd_state != LST_NODE_ACTIVE)
1172 if (transop == LST_TRANS_TSBCLIADD) {
1173 hash = batch->bat_cli_hash;
1174 head = &batch->bat_cli_list;
1177 LASSERT (transop == LST_TRANS_TSBSRVADD);
1179 hash = batch->bat_srv_hash;
1180 head = &batch->bat_srv_list;
1183 LASSERT (nd->nd_id.nid != LNET_NID_ANY);
1185 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1188 if (list_empty(&ndl->ndl_link))
1189 list_add_tail(&ndl->ndl_link, head);
1195 lstcon_test_nodes_add(lstcon_test_t *test, struct list_head *result_up)
1197 lstcon_rpc_trans_t *trans;
1198 lstcon_group_t *grp;
1202 LASSERT (test->tes_src_grp != NULL);
1203 LASSERT (test->tes_dst_grp != NULL);
1205 transop = LST_TRANS_TSBSRVADD;
1206 grp = test->tes_dst_grp;
1208 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1209 &test->tes_trans_list, transop,
1210 test, lstcon_testrpc_condition, &trans);
1212 CERROR("Can't create transaction: %d\n", rc);
1216 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1218 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1219 lstcon_trans_stat()->trs_fwk_errno != 0) {
1220 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1222 lstcon_rpc_trans_destroy(trans);
1223 /* return if any error */
1224 CDEBUG(D_NET, "Failed to add test %s, "
1225 "RPC error %d, framework error %d\n",
1226 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1227 lstcon_trans_stat()->trs_rpc_errno,
1228 lstcon_trans_stat()->trs_fwk_errno);
1233 lstcon_rpc_trans_destroy(trans);
1235 if (transop == LST_TRANS_TSBCLIADD)
1238 transop = LST_TRANS_TSBCLIADD;
1239 grp = test->tes_src_grp;
1240 test->tes_cliidx = 0;
1242 /* requests to test clients */
1247 lstcon_test_add(char *name, int type, int loop, int concur,
1248 int dist, int span, char *src_name, char * dst_name,
1249 void *param, int paramlen, int *retp, struct list_head *result_up)
1252 lstcon_group_t *src_grp = NULL;
1253 lstcon_group_t *dst_grp = NULL;
1254 lstcon_test_t *test = NULL;
1255 lstcon_batch_t *batch;
1258 rc = lstcon_batch_find(name, &batch);
1260 CDEBUG(D_NET, "Can't find batch %s\n", name);
1264 if (batch->bat_state != LST_BATCH_IDLE) {
1265 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1269 rc = lstcon_group_find(src_name, &src_grp);
1271 CDEBUG(D_NET, "Can't find group %s\n", src_name);
1275 rc = lstcon_group_find(dst_name, &dst_grp);
1277 CDEBUG(D_NET, "Can't find group %s\n", dst_name);
1281 if (dst_grp->grp_userland)
1284 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1286 CERROR("Can't allocate test descriptor\n");
1292 memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen]));
1293 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1294 test->tes_batch = batch;
1295 test->tes_type = type;
1296 test->tes_oneside = 0; /* TODO */
1297 test->tes_loop = loop;
1298 test->tes_concur = concur;
1299 test->tes_stop_onerr = 1; /* TODO */
1300 test->tes_span = span;
1301 test->tes_dist = dist;
1302 test->tes_cliidx = 0; /* just used for creating RPC */
1303 test->tes_src_grp = src_grp;
1304 test->tes_dst_grp = dst_grp;
1305 CFS_INIT_LIST_HEAD(&test->tes_trans_list);
1307 if (param != NULL) {
1308 test->tes_paramlen = paramlen;
1309 memcpy(&test->tes_param[0], param, paramlen);
1312 rc = lstcon_test_nodes_add(test, result_up);
1317 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1318 lstcon_trans_stat()->trs_fwk_errno != 0)
1319 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type, name);
1321 /* add to test list anyway, so user can check what's going on */
1322 list_add_tail(&test->tes_link, &batch->bat_test_list);
1324 batch->bat_ntest ++;
1325 test->tes_hdr.tsb_index = batch->bat_ntest;
1327 /* hold groups so nobody can change them */
1331 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1333 if (dst_grp != NULL)
1334 lstcon_group_put(dst_grp);
1336 if (src_grp != NULL)
1337 lstcon_group_put(src_grp);
1343 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1345 lstcon_test_t *test;
1347 cfs_list_for_each_entry_typed(test, &batch->bat_test_list,
1348 lstcon_test_t, tes_link) {
1349 if (idx == test->tes_hdr.tsb_index) {
1359 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1360 lstcon_rpc_ent_t *ent_up)
1362 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1364 LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1365 transop == LST_TRANS_TSBSRVQRY);
1367 /* positive errno, framework error code */
1368 if (copy_to_user(&ent_up->rpe_priv[0],
1369 &rep->bar_active, sizeof(rep->bar_active)))
1376 lstcon_test_batch_query(char *name, int testidx, int client,
1377 int timeout, struct list_head *result_up)
1379 lstcon_rpc_trans_t *trans;
1380 struct list_head *translist;
1381 struct list_head *ndlist;
1382 lstcon_tsb_hdr_t *hdr;
1383 lstcon_batch_t *batch;
1384 lstcon_test_t *test = NULL;
1388 rc = lstcon_batch_find(name, &batch);
1390 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1395 translist = &batch->bat_trans_list;
1396 ndlist = &batch->bat_cli_list;
1397 hdr = &batch->bat_hdr;
1400 /* query specified test only */
1401 rc = lstcon_test_find(batch, testidx, &test);
1403 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1407 translist = &test->tes_trans_list;
1408 ndlist = &test->tes_src_grp->grp_ndl_list;
1409 hdr = &test->tes_hdr;
1412 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1414 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1415 lstcon_batrpc_condition, &trans);
1417 CERROR("Can't create transaction: %d\n", rc);
1421 lstcon_rpc_trans_postwait(trans, timeout);
1423 if (testidx == 0 && /* query a batch, not a test */
1424 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1425 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1426 /* all RPCs finished, and no active test */
1427 batch->bat_state = LST_BATCH_IDLE;
1430 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1431 lstcon_tsbrpc_readent);
1432 lstcon_rpc_trans_destroy(trans);
1438 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1439 lstcon_rpc_ent_t *ent_up)
1441 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1442 sfw_counters_t *sfwk_stat;
1443 srpc_counters_t *srpc_stat;
1444 lnet_counters_t *lnet_stat;
1446 if (rep->str_status != 0)
1449 sfwk_stat = (sfw_counters_t *)&ent_up->rpe_payload[0];
1450 srpc_stat = (srpc_counters_t *)((char *)sfwk_stat + sizeof(*sfwk_stat));
1451 lnet_stat = (lnet_counters_t *)((char *)srpc_stat + sizeof(*srpc_stat));
1453 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1454 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1455 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1462 lstcon_ndlist_stat(struct list_head *ndlist,
1463 int timeout, struct list_head *result_up)
1465 struct list_head head;
1466 lstcon_rpc_trans_t *trans;
1469 CFS_INIT_LIST_HEAD(&head);
1471 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1472 LST_TRANS_STATQRY, NULL, NULL, &trans);
1474 CERROR("Can't create transaction: %d\n", rc);
1478 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1480 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1481 lstcon_statrpc_readent);
1482 lstcon_rpc_trans_destroy(trans);
1488 lstcon_group_stat(char *grp_name, int timeout, struct list_head *result_up)
1490 lstcon_group_t *grp;
1493 rc = lstcon_group_find(grp_name, &grp);
1495 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1499 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1501 lstcon_group_put(grp);
1507 lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
1508 int timeout, struct list_head *result_up)
1510 lstcon_ndlink_t *ndl;
1511 lstcon_group_t *tmp;
1512 lnet_process_id_t id;
1516 rc = lstcon_group_alloc(NULL, &tmp);
1518 CERROR("Out of memory\n");
1522 for (i = 0 ; i < count; i++) {
1523 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1528 /* add to tmp group */
1529 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1531 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1532 "Failed to find or create %s: %d\n",
1533 libcfs_id2str(id), rc);
1539 lstcon_group_put(tmp);
1543 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1545 lstcon_group_put(tmp);
1551 lstcon_debug_ndlist(struct list_head *ndlist,
1552 struct list_head *translist,
1553 int timeout, struct list_head *result_up)
1555 lstcon_rpc_trans_t *trans;
1558 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1559 NULL, lstcon_sesrpc_condition, &trans);
1561 CERROR("Can't create transaction: %d\n", rc);
1565 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1567 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1568 lstcon_sesrpc_readent);
1569 lstcon_rpc_trans_destroy(trans);
1575 lstcon_session_debug(int timeout, struct list_head *result_up)
1577 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1578 NULL, timeout, result_up);
1582 lstcon_batch_debug(int timeout, char *name,
1583 int client, struct list_head *result_up)
1585 lstcon_batch_t *bat;
1588 rc = lstcon_batch_find(name, &bat);
1592 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1594 NULL, timeout, result_up);
1600 lstcon_group_debug(int timeout, char *name,
1601 struct list_head *result_up)
1603 lstcon_group_t *grp;
1606 rc = lstcon_group_find(name, &grp);
1610 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1611 timeout, result_up);
1612 lstcon_group_put(grp);
1618 lstcon_nodes_debug(int timeout,
1619 int count, lnet_process_id_t *ids_up,
1620 struct list_head *result_up)
1622 lnet_process_id_t id;
1623 lstcon_ndlink_t *ndl;
1624 lstcon_group_t *grp;
1628 rc = lstcon_group_alloc(NULL, &grp);
1630 CDEBUG(D_NET, "Out of memory\n");
1634 for (i = 0; i < count; i++) {
1635 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1640 /* node is added to tmp group */
1641 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1643 CERROR("Can't create node link\n");
1649 lstcon_group_put(grp);
1653 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1654 timeout, result_up);
1656 lstcon_group_put(grp);
1662 lstcon_session_match(lst_sid_t sid)
1664 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1665 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1: 0;
1669 lstcon_new_session_id(lst_sid_t *sid)
1671 lnet_process_id_t id;
1673 LASSERT (console_session.ses_state == LST_SESSION_NONE);
1676 sid->ses_nid = id.nid;
1677 sid->ses_stamp = cfs_time_current();
1680 extern srpc_service_t lstcon_acceptor_service;
1683 lstcon_session_new(char *name, int key,
1684 int timeout,int force, lst_sid_t *sid_up)
1689 if (console_session.ses_state != LST_SESSION_NONE) {
1690 /* session exists */
1692 CERROR("Session %s already exists\n",
1693 console_session.ses_name);
1697 rc = lstcon_session_end();
1699 /* lstcon_session_end() only return local error */
1704 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++) {
1705 LASSERT (list_empty(&console_session.ses_ndl_hash[i]));
1708 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1712 rc = lstcon_rpc_pinger_start();
1714 lstcon_batch_t *bat = NULL;
1716 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1717 lstcon_batch_destroy(bat);
1722 lstcon_new_session_id(&console_session.ses_id);
1724 console_session.ses_key = key;
1725 console_session.ses_state = LST_SESSION_ACTIVE;
1726 console_session.ses_force = !!force;
1727 console_session.ses_timeout = (timeout <= 0)? LST_CONSOLE_TIMEOUT:
1729 strcpy(console_session.ses_name, name);
1731 if (copy_to_user(sid_up, &console_session.ses_id,
1732 sizeof(lst_sid_t)) == 0)
1735 lstcon_session_end();
1741 lstcon_session_info(lst_sid_t *sid_up, int *key_up,
1742 lstcon_ndlist_ent_t *ndinfo_up, char *name_up, int len)
1744 lstcon_ndlist_ent_t *entp;
1745 lstcon_ndlink_t *ndl;
1748 if (console_session.ses_state != LST_SESSION_ACTIVE)
1751 LIBCFS_ALLOC(entp, sizeof(*entp));
1755 memset(entp, 0, sizeof(*entp));
1757 cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_list,
1758 lstcon_ndlink_t, ndl_link)
1759 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1761 if (copy_to_user(sid_up, &console_session.ses_id, sizeof(lst_sid_t)) ||
1762 copy_to_user(key_up, &console_session.ses_key, sizeof(int)) ||
1763 copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1764 copy_to_user(name_up, console_session.ses_name, len))
1767 LIBCFS_FREE(entp, sizeof(*entp));
1773 lstcon_session_end()
1775 lstcon_rpc_trans_t *trans;
1776 lstcon_group_t *grp;
1777 lstcon_batch_t *bat;
1780 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1782 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1783 NULL, LST_TRANS_SESEND, NULL,
1784 lstcon_sesrpc_condition, &trans);
1786 CERROR("Can't create transaction: %d\n", rc);
1790 console_session.ses_shutdown = 1;
1792 lstcon_rpc_pinger_stop();
1794 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1796 lstcon_rpc_trans_destroy(trans);
1797 /* User can do nothing even rpc failed, so go on */
1799 /* waiting for orphan rpcs to die */
1800 lstcon_rpc_cleanup_wait();
1802 console_session.ses_id = LST_INVALID_SID;
1803 console_session.ses_state = LST_SESSION_NONE;
1804 console_session.ses_key = 0;
1805 console_session.ses_force = 0;
1807 /* destroy all batches */
1808 while (!list_empty(&console_session.ses_bat_list)) {
1809 bat = list_entry(console_session.ses_bat_list.next,
1810 lstcon_batch_t, bat_link);
1812 lstcon_batch_destroy(bat);
1815 /* destroy all groups */
1816 while (!list_empty(&console_session.ses_grp_list)) {
1817 grp = list_entry(console_session.ses_grp_list.next,
1818 lstcon_group_t, grp_link);
1819 LASSERT (grp->grp_ref == 1);
1821 lstcon_group_put(grp);
1824 /* all nodes should be released */
1825 LASSERT (list_empty(&console_session.ses_ndl_list));
1827 console_session.ses_shutdown = 0;
1828 console_session.ses_expired = 0;
1834 lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
1836 srpc_msg_t *rep = &rpc->srpc_replymsg;
1837 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1838 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1839 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1840 lstcon_group_t *grp = NULL;
1841 lstcon_ndlink_t *ndl;
1844 sfw_unpack_message(req);
1846 mutex_down(&console_session.ses_mutex);
1848 jrep->join_sid = console_session.ses_id;
1850 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1851 jrep->join_status = ESRCH;
1855 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1856 !lstcon_session_match(jreq->join_sid)) {
1857 jrep->join_status = EBUSY;
1861 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1862 rc = lstcon_group_alloc(jreq->join_group, &grp);
1864 CERROR("Out of memory\n");
1868 list_add_tail(&grp->grp_link,
1869 &console_session.ses_grp_list);
1870 lstcon_group_addref(grp);
1873 if (grp->grp_ref > 2) {
1874 /* Group in using */
1875 jrep->join_status = EBUSY;
1879 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1881 jrep->join_status = EEXIST;
1885 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1887 CERROR("Out of memory\n");
1891 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1892 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1894 if (grp->grp_userland == 0)
1895 grp->grp_userland = 1;
1897 strcpy(jrep->join_session, console_session.ses_name);
1898 jrep->join_timeout = console_session.ses_timeout;
1899 jrep->join_status = 0;
1903 lstcon_group_put(grp);
1905 mutex_up(&console_session.ses_mutex);
1910 srpc_service_t lstcon_acceptor_service;
1911 void lstcon_init_acceptor_service(void)
1913 /* initialize selftest console acceptor service table */
1914 lstcon_acceptor_service.sv_name = "join session";
1915 lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
1916 lstcon_acceptor_service.sv_id = SRPC_SERVICE_JOIN;
1917 lstcon_acceptor_service.sv_concur = SFW_SERVICE_CONCURRENCY;
1920 extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
1922 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
1924 /* initialize console */
1926 lstcon_console_init(void)
1932 memset(&console_session, 0, sizeof(lstcon_session_t));
1934 console_session.ses_id = LST_INVALID_SID;
1935 console_session.ses_state = LST_SESSION_NONE;
1936 console_session.ses_timeout = 0;
1937 console_session.ses_force = 0;
1938 console_session.ses_expired = 0;
1939 console_session.ses_laststamp = cfs_time_current_sec();
1941 init_mutex(&console_session.ses_mutex);
1943 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_list);
1944 CFS_INIT_LIST_HEAD(&console_session.ses_grp_list);
1945 CFS_INIT_LIST_HEAD(&console_session.ses_bat_list);
1946 CFS_INIT_LIST_HEAD(&console_session.ses_trans_list);
1948 LIBCFS_ALLOC(console_session.ses_ndl_hash,
1949 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1950 if (console_session.ses_ndl_hash == NULL)
1953 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1954 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
1957 /* initialize acceptor service table */
1958 lstcon_init_acceptor_service();
1960 rc = srpc_add_service(&lstcon_acceptor_service);
1961 LASSERT (rc != -EBUSY);
1963 LIBCFS_FREE(console_session.ses_ndl_hash,
1964 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1968 n = srpc_service_add_buffers(&lstcon_acceptor_service, SFW_POST_BUFFERS);
1969 if (n != SFW_POST_BUFFERS) {
1974 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
1977 lstcon_rpc_module_init();
1982 srpc_shutdown_service(&lstcon_acceptor_service);
1983 srpc_remove_service(&lstcon_acceptor_service);
1985 LIBCFS_FREE(console_session.ses_ndl_hash,
1986 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1988 srpc_wait_service_shutdown(&lstcon_acceptor_service);
1994 lstcon_console_fini(void)
1998 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
2000 mutex_down(&console_session.ses_mutex);
2002 srpc_shutdown_service(&lstcon_acceptor_service);
2003 srpc_remove_service(&lstcon_acceptor_service);
2005 if (console_session.ses_state != LST_SESSION_NONE)
2006 lstcon_session_end();
2008 lstcon_rpc_module_fini();
2010 mutex_up(&console_session.ses_mutex);
2012 LASSERT (list_empty(&console_session.ses_ndl_list));
2013 LASSERT (list_empty(&console_session.ses_grp_list));
2014 LASSERT (list_empty(&console_session.ses_bat_list));
2015 LASSERT (list_empty(&console_session.ses_trans_list));
2017 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
2018 LASSERT (list_empty(&console_session.ses_ndl_hash[i]));
2021 LIBCFS_FREE(console_session.ses_ndl_hash,
2022 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2024 srpc_wait_service_shutdown(&lstcon_acceptor_service);