4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lnet/selftest/conctl.c
36 * Infrastructure of LST console
38 * Author: Liang Zhen <liangzhen@clusterfs.com>
43 #include <libcfs/libcfs.h>
44 #include <lnet/lib-lnet.h>
48 #define LST_NODE_STATE_COUNTER(nd, p) \
50 if ((nd)->nd_state == LST_NODE_ACTIVE) \
51 (p)->nle_nactive ++; \
52 else if ((nd)->nd_state == LST_NODE_BUSY) \
54 else if ((nd)->nd_state == LST_NODE_DOWN) \
57 (p)->nle_nunknown ++; \
61 lstcon_session_t console_session;
64 lstcon_node_get(lstcon_node_t *nd)
66 LASSERT (nd->nd_ref >= 1);
72 lstcon_node_find(lnet_process_id_t id, lstcon_node_t **ndpp, int create)
75 unsigned int idx = LNET_NIDADDR(id.nid) % LST_GLOBAL_HASHSIZE;
77 LASSERT (id.nid != LNET_NID_ANY);
79 cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_hash[idx],
80 lstcon_ndlink_t, ndl_hlink) {
81 if (ndl->ndl_node->nd_id.nid != id.nid ||
82 ndl->ndl_node->nd_id.pid != id.pid)
85 lstcon_node_get(ndl->ndl_node);
86 *ndpp = ndl->ndl_node;
93 LIBCFS_ALLOC(*ndpp, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
97 ndl = (lstcon_ndlink_t *)(*ndpp + 1);
99 ndl->ndl_node = *ndpp;
101 ndl->ndl_node->nd_ref = 1;
102 ndl->ndl_node->nd_id = id;
103 ndl->ndl_node->nd_stamp = cfs_time_current();
104 ndl->ndl_node->nd_state = LST_NODE_UNKNOWN;
105 ndl->ndl_node->nd_timeout = 0;
106 memset(&ndl->ndl_node->nd_ping, 0, sizeof(lstcon_rpc_t));
108 /* queued in global hash & list, no refcount is taken by
109 * global hash & list, if caller release his refcount,
110 * node will be released */
111 cfs_list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
112 cfs_list_add_tail(&ndl->ndl_link, &console_session.ses_ndl_list);
118 lstcon_node_put(lstcon_node_t *nd)
120 lstcon_ndlink_t *ndl;
122 LASSERT (nd->nd_ref > 0);
124 if (--nd->nd_ref > 0)
127 ndl = (lstcon_ndlink_t *)(nd + 1);
129 LASSERT (!cfs_list_empty(&ndl->ndl_link));
130 LASSERT (!cfs_list_empty(&ndl->ndl_hlink));
132 /* remove from session */
133 cfs_list_del(&ndl->ndl_link);
134 cfs_list_del(&ndl->ndl_hlink);
136 LIBCFS_FREE(nd, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
140 lstcon_ndlink_find(cfs_list_t *hash,
141 lnet_process_id_t id, lstcon_ndlink_t **ndlpp, int create)
143 unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
144 lstcon_ndlink_t *ndl;
148 if (id.nid == LNET_NID_ANY)
152 cfs_list_for_each_entry_typed(ndl, &hash[idx],
153 lstcon_ndlink_t, 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 cfs_list_add_tail(&ndl->ndl_hlink, &hash[idx]);
186 lstcon_ndlink_release(lstcon_ndlink_t *ndl)
188 LASSERT (cfs_list_empty(&ndl->ndl_link));
189 LASSERT (!cfs_list_empty(&ndl->ndl_hlink));
191 cfs_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 cfs_list_for_each_entry_safe_typed(ndl, tmp, &grp->grp_ndl_list,
242 lstcon_ndlink_t, 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 (!cfs_list_empty(&grp->grp_link))
257 cfs_list_del(&grp->grp_link);
259 lstcon_group_drain(grp, 0);
261 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
262 LASSERT (cfs_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 cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list,
275 lstcon_group_t, grp_link) {
276 if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
279 lstcon_group_addref(grp); /* +1 ref for caller */
288 lstcon_group_put(lstcon_group_t *grp)
290 lstcon_group_decref(grp);
294 lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id,
295 lstcon_ndlink_t **ndlpp, int create)
299 rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
303 if (!cfs_list_empty(&(*ndlpp)->ndl_link))
306 cfs_list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
313 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
315 cfs_list_del_init(&ndl->ndl_link);
316 lstcon_ndlink_release(ndl);
321 lstcon_group_ndlink_move(lstcon_group_t *old,
322 lstcon_group_t *new, lstcon_ndlink_t *ndl)
324 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
327 cfs_list_del(&ndl->ndl_hlink);
328 cfs_list_del(&ndl->ndl_link);
331 cfs_list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
332 cfs_list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
339 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
341 lstcon_ndlink_t *ndl;
343 while (!cfs_list_empty(&old->grp_ndl_list)) {
344 ndl = cfs_list_entry(old->grp_ndl_list.next,
345 lstcon_ndlink_t, ndl_link);
346 lstcon_group_ndlink_move(old, new, ndl);
351 lstcon_sesrpc_condition(int transop, lstcon_node_t *nd, void *arg)
353 lstcon_group_t *grp = (lstcon_group_t *)arg;
356 case LST_TRANS_SESNEW:
357 if (nd->nd_state == LST_NODE_ACTIVE)
361 case LST_TRANS_SESEND:
362 if (nd->nd_state != LST_NODE_ACTIVE)
365 if (grp != NULL && nd->nd_ref > 1)
369 case LST_TRANS_SESQRY:
380 lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
381 lstcon_rpc_ent_t *ent_up)
383 srpc_debug_reply_t *rep;
386 case LST_TRANS_SESNEW:
387 case LST_TRANS_SESEND:
390 case LST_TRANS_SESQRY:
391 rep = &msg->msg_body.dbg_reply;
393 if (cfs_copy_to_user(&ent_up->rpe_priv[0],
394 &rep->dbg_timeout, sizeof(int)) ||
395 cfs_copy_to_user(&ent_up->rpe_payload[0],
396 &rep->dbg_name, LST_NAME_SIZE))
409 lstcon_group_nodes_add(lstcon_group_t *grp, int count,
410 lnet_process_id_t *ids_up,
411 cfs_list_t *result_up)
413 lstcon_rpc_trans_t *trans;
414 lstcon_ndlink_t *ndl;
416 lnet_process_id_t id;
420 rc = lstcon_group_alloc(NULL, &tmp);
422 CERROR("Out of memory\n");
426 for (i = 0 ; i < count; i++) {
427 if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) {
432 /* skip if it's in this group already */
433 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
437 /* add to tmp group */
438 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
440 CERROR("Can't create ndlink, out of memory\n");
446 lstcon_group_put(tmp);
450 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
451 &tmp->grp_trans_list, LST_TRANS_SESNEW,
452 tmp, lstcon_sesrpc_condition, &trans);
454 CERROR("Can't create transaction: %d\n", rc);
455 lstcon_group_put(tmp);
460 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
462 rc = lstcon_rpc_trans_interpreter(trans, result_up,
463 lstcon_sesrpc_readent);
464 /* destroy all RPGs */
465 lstcon_rpc_trans_destroy(trans);
467 lstcon_group_move(tmp, grp);
468 lstcon_group_put(tmp);
474 lstcon_group_nodes_remove(lstcon_group_t *grp,
475 int count, lnet_process_id_t *ids_up,
476 cfs_list_t *result_up)
478 lstcon_rpc_trans_t *trans;
479 lstcon_ndlink_t *ndl;
481 lnet_process_id_t id;
485 /* End session and remove node from the group */
487 rc = lstcon_group_alloc(NULL, &tmp);
489 CERROR("Out of memory\n");
493 for (i = 0; i < count; i++) {
494 if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) {
499 /* move node to tmp group */
500 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
501 lstcon_group_ndlink_move(grp, tmp, ndl);
504 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
505 &tmp->grp_trans_list, LST_TRANS_SESEND,
506 tmp, lstcon_sesrpc_condition, &trans);
508 CERROR("Can't create transaction: %d\n", rc);
512 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
514 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
516 lstcon_rpc_trans_destroy(trans);
517 /* release nodes anyway, because we can't rollback status */
518 lstcon_group_put(tmp);
522 lstcon_group_move(tmp, grp);
523 lstcon_group_put(tmp);
529 lstcon_group_add(char *name)
534 rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
536 /* find a group with same name */
537 lstcon_group_put(grp);
541 rc = lstcon_group_alloc(name, &grp);
543 CERROR("Can't allocate descriptor for group %s\n", name);
547 cfs_list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
553 lstcon_nodes_add(char *name, int count,
554 lnet_process_id_t *ids_up, cfs_list_t *result_up)
560 LASSERT (ids_up != NULL);
562 rc = lstcon_group_find(name, &grp);
564 CDEBUG(D_NET, "Can't find group %s\n", name);
568 if (grp->grp_ref > 2) {
569 /* referred by other threads or test */
570 CDEBUG(D_NET, "Group %s is busy\n", name);
571 lstcon_group_put(grp);
576 rc = lstcon_group_nodes_add(grp, count, ids_up, result_up);
578 lstcon_group_put(grp);
584 lstcon_group_del(char *name)
586 lstcon_rpc_trans_t *trans;
590 rc = lstcon_group_find(name, &grp);
592 CDEBUG(D_NET, "Can't find group: %s\n", name);
596 if (grp->grp_ref > 2) {
597 /* referred by others threads or test */
598 CDEBUG(D_NET, "Group %s is busy\n", name);
599 lstcon_group_put(grp);
603 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
604 &grp->grp_trans_list, LST_TRANS_SESEND,
605 grp, lstcon_sesrpc_condition, &trans);
607 CERROR("Can't create transaction: %d\n", rc);
608 lstcon_group_put(grp);
612 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
614 lstcon_rpc_trans_destroy(trans);
616 lstcon_group_put(grp);
617 /* -ref for session, it's destroyed,
618 * status can't be rolled back, destroy group anway */
619 lstcon_group_put(grp);
625 lstcon_group_clean(char *name, int args)
627 lstcon_group_t *grp = NULL;
630 rc = lstcon_group_find(name, &grp);
632 CDEBUG(D_NET, "Can't find group %s\n", name);
636 if (grp->grp_ref > 2) {
637 /* referred by test */
638 CDEBUG(D_NET, "Group %s is busy\n", name);
639 lstcon_group_put(grp);
643 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
644 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
646 lstcon_group_drain(grp, args);
648 lstcon_group_put(grp);
649 /* release empty group */
650 if (cfs_list_empty(&grp->grp_ndl_list))
651 lstcon_group_put(grp);
657 lstcon_nodes_remove(char *name, int count,
658 lnet_process_id_t *ids_up, cfs_list_t *result_up)
660 lstcon_group_t *grp = NULL;
663 rc = lstcon_group_find(name, &grp);
665 CDEBUG(D_NET, "Can't find group: %s\n", name);
669 if (grp->grp_ref > 2) {
670 /* referred by test */
671 CDEBUG(D_NET, "Group %s is busy\n", name);
672 lstcon_group_put(grp);
676 rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
678 lstcon_group_put(grp);
679 /* release empty group */
680 if (cfs_list_empty(&grp->grp_ndl_list))
681 lstcon_group_put(grp);
687 lstcon_group_refresh(char *name, cfs_list_t *result_up)
689 lstcon_rpc_trans_t *trans;
693 rc = lstcon_group_find(name, &grp);
695 CDEBUG(D_NET, "Can't find group: %s\n", name);
699 if (grp->grp_ref > 2) {
700 /* referred by test */
701 CDEBUG(D_NET, "Group %s is busy\n", name);
702 lstcon_group_put(grp);
706 /* re-invite all inactive nodes int the group */
707 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
708 &grp->grp_trans_list, LST_TRANS_SESNEW,
709 grp, lstcon_sesrpc_condition, &trans);
711 /* local error, return */
712 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
713 lstcon_group_put(grp);
717 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
719 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
721 lstcon_rpc_trans_destroy(trans);
723 lstcon_group_put(grp);
729 lstcon_group_list(int index, int len, char *name_up)
733 LASSERT (index >= 0);
734 LASSERT (name_up != NULL);
736 cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list,
737 lstcon_group_t, grp_link) {
739 return cfs_copy_to_user(name_up, grp->grp_name, len) ?
748 lstcon_nodes_getent(cfs_list_t *head, int *index_p,
749 int *count_p, lstcon_node_ent_t *dents_up)
751 lstcon_ndlink_t *ndl;
756 LASSERT (index_p != NULL && count_p != NULL);
757 LASSERT (dents_up != NULL);
758 LASSERT (*index_p >= 0);
759 LASSERT (*count_p > 0);
761 cfs_list_for_each_entry_typed(ndl, head, lstcon_ndlink_t, ndl_link) {
762 if (index++ < *index_p)
765 if (count >= *count_p)
769 if (cfs_copy_to_user(&dents_up[count].nde_id,
770 &nd->nd_id, sizeof(nd->nd_id)) ||
771 cfs_copy_to_user(&dents_up[count].nde_state,
772 &nd->nd_state, sizeof(nd->nd_state)))
778 if (index <= *index_p)
788 lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p,
789 int *index_p, int *count_p, lstcon_node_ent_t *dents_up)
791 lstcon_ndlist_ent_t *gentp;
793 lstcon_ndlink_t *ndl;
796 rc = lstcon_group_find(name, &grp);
798 CDEBUG(D_NET, "Can't find group %s\n", name);
804 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
805 index_p, count_p, dents_up);
806 lstcon_group_put(grp);
811 /* non-verbose query */
812 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
814 CERROR("Can't allocate ndlist_ent\n");
815 lstcon_group_put(grp);
820 memset(gentp, 0, sizeof(lstcon_ndlist_ent_t));
822 cfs_list_for_each_entry_typed(ndl, &grp->grp_ndl_list,
823 lstcon_ndlink_t, ndl_link)
824 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
826 rc = cfs_copy_to_user(gents_p, gentp,
827 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT: 0;
829 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
831 lstcon_group_put(grp);
837 lstcon_batch_find(char *name, lstcon_batch_t **batpp)
841 cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list,
842 lstcon_batch_t, bat_link) {
843 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
853 lstcon_batch_add(char *name)
859 rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
861 CDEBUG(D_NET, "Batch %s already exists\n", name);
865 LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
867 CERROR("Can't allocate descriptor for batch %s\n", name);
871 LIBCFS_ALLOC(bat->bat_cli_hash,
872 sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
873 if (bat->bat_cli_hash == NULL) {
874 CERROR("Can't allocate hash for batch %s\n", name);
875 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
880 LIBCFS_ALLOC(bat->bat_srv_hash,
881 sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
882 if (bat->bat_srv_hash == NULL) {
883 CERROR("Can't allocate hash for batch %s\n", name);
884 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
885 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
890 strcpy(bat->bat_name, name);
891 bat->bat_hdr.tsb_index = 0;
892 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
895 bat->bat_state = LST_BATCH_IDLE;
897 CFS_INIT_LIST_HEAD(&bat->bat_cli_list);
898 CFS_INIT_LIST_HEAD(&bat->bat_srv_list);
899 CFS_INIT_LIST_HEAD(&bat->bat_test_list);
900 CFS_INIT_LIST_HEAD(&bat->bat_trans_list);
902 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
903 CFS_INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
904 CFS_INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
907 cfs_list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
913 lstcon_batch_list(int index, int len, char *name_up)
917 LASSERT (name_up != NULL);
918 LASSERT (index >= 0);
920 cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list,
921 lstcon_batch_t, bat_link) {
923 return cfs_copy_to_user(name_up,bat->bat_name, len) ?
932 lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
933 int testidx, int *index_p, int *ndent_p,
934 lstcon_node_ent_t *dents_up)
936 lstcon_test_batch_ent_t *entp;
939 lstcon_test_t *test = NULL;
941 lstcon_ndlink_t *ndl;
944 rc = lstcon_batch_find(name, &bat);
946 CDEBUG(D_NET, "Can't find batch %s\n", name);
951 /* query test, test index start from 1 */
952 cfs_list_for_each_entry_typed(test, &bat->bat_test_list,
953 lstcon_test_t, tes_link) {
959 CDEBUG(D_NET, "Can't find specified test in batch\n");
964 clilst = (test == NULL) ? &bat->bat_cli_list :
965 &test->tes_src_grp->grp_ndl_list;
966 srvlst = (test == NULL) ? &bat->bat_srv_list :
967 &test->tes_dst_grp->grp_ndl_list;
969 if (dents_up != NULL) {
970 rc = lstcon_nodes_getent((server ? srvlst: clilst),
971 index_p, ndent_p, dents_up);
975 /* non-verbose query */
976 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
980 memset(entp, 0, sizeof(lstcon_test_batch_ent_t));
983 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
984 entp->u.tbe_batch.bae_state = bat->bat_state;
988 entp->u.tbe_test.tse_type = test->tes_type;
989 entp->u.tbe_test.tse_loop = test->tes_loop;
990 entp->u.tbe_test.tse_concur = test->tes_concur;
993 cfs_list_for_each_entry_typed(ndl, clilst, lstcon_ndlink_t, ndl_link)
994 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
996 cfs_list_for_each_entry_typed(ndl, srvlst, lstcon_ndlink_t, ndl_link)
997 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
999 rc = cfs_copy_to_user(ent_up, entp,
1000 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
1002 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
1008 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1011 case LST_TRANS_TSBRUN:
1012 if (nd->nd_state != LST_NODE_ACTIVE)
1016 case LST_TRANS_TSBSTOP:
1017 if (nd->nd_state != LST_NODE_ACTIVE)
1021 case LST_TRANS_TSBCLIQRY:
1022 case LST_TRANS_TSBSRVQRY:
1030 lstcon_batch_op(lstcon_batch_t *bat, int transop,
1031 cfs_list_t *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, cfs_list_t *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, cfs_list_t *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 cfs_list_del(&bat->bat_link);
1106 while (!cfs_list_empty(&bat->bat_test_list)) {
1107 test = cfs_list_entry(bat->bat_test_list.next,
1108 lstcon_test_t, tes_link);
1109 LASSERT (cfs_list_empty(&test->tes_trans_list));
1111 cfs_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 (cfs_list_empty(&bat->bat_trans_list));
1122 while (!cfs_list_empty(&bat->bat_cli_list)) {
1123 ndl = cfs_list_entry(bat->bat_cli_list.next,
1124 lstcon_ndlink_t, ndl_link);
1125 cfs_list_del_init(&ndl->ndl_link);
1127 lstcon_ndlink_release(ndl);
1130 while (!cfs_list_empty(&bat->bat_srv_list)) {
1131 ndl = cfs_list_entry(bat->bat_srv_list.next,
1132 lstcon_ndlink_t, ndl_link);
1133 cfs_list_del_init(&ndl->ndl_link);
1135 lstcon_ndlink_release(ndl);
1138 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1139 LASSERT (cfs_list_empty(&bat->bat_cli_hash[i]));
1140 LASSERT (cfs_list_empty(&bat->bat_srv_hash[i]));
1143 LIBCFS_FREE(bat->bat_cli_hash,
1144 sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
1145 LIBCFS_FREE(bat->bat_srv_hash,
1146 sizeof(cfs_list_t) * 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;
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 (cfs_list_empty(&ndl->ndl_link))
1189 cfs_list_add_tail(&ndl->ndl_link, head);
1195 lstcon_test_nodes_add(lstcon_test_t *test, cfs_list_t *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,
1250 cfs_list_t *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 cfs_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 (cfs_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, cfs_list_t *result_up)
1379 lstcon_rpc_trans_t *trans;
1380 cfs_list_t *translist;
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 (cfs_copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1454 cfs_copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1455 cfs_copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1462 lstcon_ndlist_stat(cfs_list_t *ndlist,
1463 int timeout, cfs_list_t *result_up)
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, cfs_list_t *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, cfs_list_t *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 (cfs_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(cfs_list_t *ndlist,
1552 cfs_list_t *translist,
1553 int timeout, cfs_list_t *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, cfs_list_t *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, cfs_list_t *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 cfs_list_t *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 cfs_list_t *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 (cfs_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 (cfs_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 (cfs_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 (cfs_copy_to_user(sid_up, &console_session.ses_id,
1762 sizeof(lst_sid_t)) ||
1763 cfs_copy_to_user(key_up, &console_session.ses_key, sizeof(int)) ||
1764 cfs_copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1765 cfs_copy_to_user(name_up, console_session.ses_name, len))
1768 LIBCFS_FREE(entp, sizeof(*entp));
1774 lstcon_session_end()
1776 lstcon_rpc_trans_t *trans;
1777 lstcon_group_t *grp;
1778 lstcon_batch_t *bat;
1781 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1783 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1784 NULL, LST_TRANS_SESEND, NULL,
1785 lstcon_sesrpc_condition, &trans);
1787 CERROR("Can't create transaction: %d\n", rc);
1791 console_session.ses_shutdown = 1;
1793 lstcon_rpc_pinger_stop();
1795 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1797 lstcon_rpc_trans_destroy(trans);
1798 /* User can do nothing even rpc failed, so go on */
1800 /* waiting for orphan rpcs to die */
1801 lstcon_rpc_cleanup_wait();
1803 console_session.ses_id = LST_INVALID_SID;
1804 console_session.ses_state = LST_SESSION_NONE;
1805 console_session.ses_key = 0;
1806 console_session.ses_force = 0;
1808 /* destroy all batches */
1809 while (!cfs_list_empty(&console_session.ses_bat_list)) {
1810 bat = cfs_list_entry(console_session.ses_bat_list.next,
1811 lstcon_batch_t, bat_link);
1813 lstcon_batch_destroy(bat);
1816 /* destroy all groups */
1817 while (!cfs_list_empty(&console_session.ses_grp_list)) {
1818 grp = cfs_list_entry(console_session.ses_grp_list.next,
1819 lstcon_group_t, grp_link);
1820 LASSERT (grp->grp_ref == 1);
1822 lstcon_group_put(grp);
1825 /* all nodes should be released */
1826 LASSERT (cfs_list_empty(&console_session.ses_ndl_list));
1828 console_session.ses_shutdown = 0;
1829 console_session.ses_expired = 0;
1835 lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
1837 srpc_msg_t *rep = &rpc->srpc_replymsg;
1838 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1839 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1840 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1841 lstcon_group_t *grp = NULL;
1842 lstcon_ndlink_t *ndl;
1845 sfw_unpack_message(req);
1847 cfs_mutex_lock(&console_session.ses_mutex);
1849 jrep->join_sid = console_session.ses_id;
1851 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1852 jrep->join_status = ESRCH;
1856 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1857 !lstcon_session_match(jreq->join_sid)) {
1858 jrep->join_status = EBUSY;
1862 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1863 rc = lstcon_group_alloc(jreq->join_group, &grp);
1865 CERROR("Out of memory\n");
1869 cfs_list_add_tail(&grp->grp_link,
1870 &console_session.ses_grp_list);
1871 lstcon_group_addref(grp);
1874 if (grp->grp_ref > 2) {
1875 /* Group in using */
1876 jrep->join_status = EBUSY;
1880 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1882 jrep->join_status = EEXIST;
1886 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1888 CERROR("Out of memory\n");
1892 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1893 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1895 if (grp->grp_userland == 0)
1896 grp->grp_userland = 1;
1898 strcpy(jrep->join_session, console_session.ses_name);
1899 jrep->join_timeout = console_session.ses_timeout;
1900 jrep->join_status = 0;
1904 lstcon_group_put(grp);
1906 cfs_mutex_unlock(&console_session.ses_mutex);
1911 srpc_service_t lstcon_acceptor_service;
1912 void lstcon_init_acceptor_service(void)
1914 /* initialize selftest console acceptor service table */
1915 lstcon_acceptor_service.sv_name = "join session";
1916 lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
1917 lstcon_acceptor_service.sv_id = SRPC_SERVICE_JOIN;
1918 lstcon_acceptor_service.sv_concur = SFW_SERVICE_CONCURRENCY;
1921 extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
1923 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
1925 /* initialize console */
1927 lstcon_console_init(void)
1933 memset(&console_session, 0, sizeof(lstcon_session_t));
1935 console_session.ses_id = LST_INVALID_SID;
1936 console_session.ses_state = LST_SESSION_NONE;
1937 console_session.ses_timeout = 0;
1938 console_session.ses_force = 0;
1939 console_session.ses_expired = 0;
1940 console_session.ses_laststamp = cfs_time_current_sec();
1942 cfs_mutex_init(&console_session.ses_mutex);
1944 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_list);
1945 CFS_INIT_LIST_HEAD(&console_session.ses_grp_list);
1946 CFS_INIT_LIST_HEAD(&console_session.ses_bat_list);
1947 CFS_INIT_LIST_HEAD(&console_session.ses_trans_list);
1949 LIBCFS_ALLOC(console_session.ses_ndl_hash,
1950 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
1951 if (console_session.ses_ndl_hash == NULL)
1954 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1955 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
1958 /* initialize acceptor service table */
1959 lstcon_init_acceptor_service();
1961 rc = srpc_add_service(&lstcon_acceptor_service);
1962 LASSERT (rc != -EBUSY);
1964 LIBCFS_FREE(console_session.ses_ndl_hash,
1965 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
1969 n = srpc_service_add_buffers(&lstcon_acceptor_service, SFW_POST_BUFFERS);
1970 if (n != SFW_POST_BUFFERS) {
1975 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
1978 lstcon_rpc_module_init();
1983 srpc_shutdown_service(&lstcon_acceptor_service);
1984 srpc_remove_service(&lstcon_acceptor_service);
1986 LIBCFS_FREE(console_session.ses_ndl_hash,
1987 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
1989 srpc_wait_service_shutdown(&lstcon_acceptor_service);
1995 lstcon_console_fini(void)
1999 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
2001 cfs_mutex_lock(&console_session.ses_mutex);
2003 srpc_shutdown_service(&lstcon_acceptor_service);
2004 srpc_remove_service(&lstcon_acceptor_service);
2006 if (console_session.ses_state != LST_SESSION_NONE)
2007 lstcon_session_end();
2009 lstcon_rpc_module_fini();
2011 cfs_mutex_unlock(&console_session.ses_mutex);
2013 LASSERT (cfs_list_empty(&console_session.ses_ndl_list));
2014 LASSERT (cfs_list_empty(&console_session.ses_grp_list));
2015 LASSERT (cfs_list_empty(&console_session.ses_bat_list));
2016 LASSERT (cfs_list_empty(&console_session.ses_trans_list));
2018 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
2019 LASSERT (cfs_list_empty(&console_session.ses_ndl_hash[i]));
2022 LIBCFS_FREE(console_session.ses_ndl_hash,
2023 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
2025 srpc_wait_service_shutdown(&lstcon_acceptor_service);