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.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/selftest/conctl.c
38 * Infrastructure of LST console
40 * Author: Liang Zhen <liangzhen@clusterfs.com>
45 #include <libcfs/libcfs.h>
46 #include <lnet/lib-lnet.h>
50 #define LST_NODE_STATE_COUNTER(nd, p) \
52 if ((nd)->nd_state == LST_NODE_ACTIVE) \
53 (p)->nle_nactive ++; \
54 else if ((nd)->nd_state == LST_NODE_BUSY) \
56 else if ((nd)->nd_state == LST_NODE_DOWN) \
59 (p)->nle_nunknown ++; \
63 lstcon_session_t console_session;
66 lstcon_node_get(lstcon_node_t *nd)
68 LASSERT (nd->nd_ref >= 1);
74 lstcon_node_find(lnet_process_id_t id, lstcon_node_t **ndpp, int create)
77 unsigned int idx = LNET_NIDADDR(id.nid) % LST_GLOBAL_HASHSIZE;
79 LASSERT (id.nid != LNET_NID_ANY);
81 cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_hash[idx],
82 lstcon_ndlink_t, ndl_hlink) {
83 if (ndl->ndl_node->nd_id.nid != id.nid ||
84 ndl->ndl_node->nd_id.pid != id.pid)
87 lstcon_node_get(ndl->ndl_node);
88 *ndpp = ndl->ndl_node;
95 LIBCFS_ALLOC(*ndpp, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
99 ndl = (lstcon_ndlink_t *)(*ndpp + 1);
101 ndl->ndl_node = *ndpp;
103 ndl->ndl_node->nd_ref = 1;
104 ndl->ndl_node->nd_id = id;
105 ndl->ndl_node->nd_stamp = cfs_time_current();
106 ndl->ndl_node->nd_state = LST_NODE_UNKNOWN;
107 ndl->ndl_node->nd_timeout = 0;
108 memset(&ndl->ndl_node->nd_ping, 0, sizeof(lstcon_rpc_t));
110 /* queued in global hash & list, no refcount is taken by
111 * global hash & list, if caller release his refcount,
112 * node will be released */
113 cfs_list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
114 cfs_list_add_tail(&ndl->ndl_link, &console_session.ses_ndl_list);
120 lstcon_node_put(lstcon_node_t *nd)
122 lstcon_ndlink_t *ndl;
124 LASSERT (nd->nd_ref > 0);
126 if (--nd->nd_ref > 0)
129 ndl = (lstcon_ndlink_t *)(nd + 1);
131 LASSERT (!cfs_list_empty(&ndl->ndl_link));
132 LASSERT (!cfs_list_empty(&ndl->ndl_hlink));
134 /* remove from session */
135 cfs_list_del(&ndl->ndl_link);
136 cfs_list_del(&ndl->ndl_hlink);
138 LIBCFS_FREE(nd, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
142 lstcon_ndlink_find(cfs_list_t *hash,
143 lnet_process_id_t id, lstcon_ndlink_t **ndlpp, int create)
145 unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
146 lstcon_ndlink_t *ndl;
150 if (id.nid == LNET_NID_ANY)
154 cfs_list_for_each_entry_typed(ndl, &hash[idx],
155 lstcon_ndlink_t, ndl_hlink) {
156 if (ndl->ndl_node->nd_id.nid != id.nid ||
157 ndl->ndl_node->nd_id.pid != id.pid)
167 /* find or create in session hash */
168 rc = lstcon_node_find(id, &nd, (create == 1) ? 1 : 0);
172 LIBCFS_ALLOC(ndl, sizeof(lstcon_ndlink_t));
181 CFS_INIT_LIST_HEAD(&ndl->ndl_link);
182 cfs_list_add_tail(&ndl->ndl_hlink, &hash[idx]);
188 lstcon_ndlink_release(lstcon_ndlink_t *ndl)
190 LASSERT (cfs_list_empty(&ndl->ndl_link));
191 LASSERT (!cfs_list_empty(&ndl->ndl_hlink));
193 cfs_list_del(&ndl->ndl_hlink); /* delete from hash */
194 lstcon_node_put(ndl->ndl_node);
196 LIBCFS_FREE(ndl, sizeof(*ndl));
200 lstcon_group_alloc(char *name, lstcon_group_t **grpp)
205 LIBCFS_ALLOC(grp, offsetof(lstcon_group_t,
206 grp_ndl_hash[LST_NODE_HASHSIZE]));
210 memset(grp, 0, offsetof(lstcon_group_t,
211 grp_ndl_hash[LST_NODE_HASHSIZE]));
215 strcpy(grp->grp_name, name);
217 CFS_INIT_LIST_HEAD(&grp->grp_link);
218 CFS_INIT_LIST_HEAD(&grp->grp_ndl_list);
219 CFS_INIT_LIST_HEAD(&grp->grp_trans_list);
221 for (i = 0; i < LST_NODE_HASHSIZE; i++)
222 CFS_INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
230 lstcon_group_addref(lstcon_group_t *grp)
235 static void lstcon_group_ndlink_release(lstcon_group_t *, lstcon_ndlink_t *);
238 lstcon_group_drain(lstcon_group_t *grp, int keep)
240 lstcon_ndlink_t *ndl;
241 lstcon_ndlink_t *tmp;
243 cfs_list_for_each_entry_safe_typed(ndl, tmp, &grp->grp_ndl_list,
244 lstcon_ndlink_t, ndl_link) {
245 if ((ndl->ndl_node->nd_state & keep) == 0)
246 lstcon_group_ndlink_release(grp, ndl);
251 lstcon_group_decref(lstcon_group_t *grp)
255 if (--grp->grp_ref > 0)
258 if (!cfs_list_empty(&grp->grp_link))
259 cfs_list_del(&grp->grp_link);
261 lstcon_group_drain(grp, 0);
263 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
264 LASSERT (cfs_list_empty(&grp->grp_ndl_hash[i]));
267 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
268 grp_ndl_hash[LST_NODE_HASHSIZE]));
272 lstcon_group_find(char *name, lstcon_group_t **grpp)
276 cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list,
277 lstcon_group_t, grp_link) {
278 if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
281 lstcon_group_addref(grp); /* +1 ref for caller */
290 lstcon_group_put(lstcon_group_t *grp)
292 lstcon_group_decref(grp);
296 lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id,
297 lstcon_ndlink_t **ndlpp, int create)
301 rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
305 if (!cfs_list_empty(&(*ndlpp)->ndl_link))
308 cfs_list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
315 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
317 cfs_list_del_init(&ndl->ndl_link);
318 lstcon_ndlink_release(ndl);
323 lstcon_group_ndlink_move(lstcon_group_t *old,
324 lstcon_group_t *new, lstcon_ndlink_t *ndl)
326 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
329 cfs_list_del(&ndl->ndl_hlink);
330 cfs_list_del(&ndl->ndl_link);
333 cfs_list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
334 cfs_list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
341 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
343 lstcon_ndlink_t *ndl;
345 while (!cfs_list_empty(&old->grp_ndl_list)) {
346 ndl = cfs_list_entry(old->grp_ndl_list.next,
347 lstcon_ndlink_t, ndl_link);
348 lstcon_group_ndlink_move(old, new, ndl);
353 lstcon_sesrpc_condition(int transop, lstcon_node_t *nd, void *arg)
355 lstcon_group_t *grp = (lstcon_group_t *)arg;
358 case LST_TRANS_SESNEW:
359 if (nd->nd_state == LST_NODE_ACTIVE)
363 case LST_TRANS_SESEND:
364 if (nd->nd_state != LST_NODE_ACTIVE)
367 if (grp != NULL && nd->nd_ref > 1)
371 case LST_TRANS_SESQRY:
382 lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
383 lstcon_rpc_ent_t *ent_up)
385 srpc_debug_reply_t *rep;
388 case LST_TRANS_SESNEW:
389 case LST_TRANS_SESEND:
392 case LST_TRANS_SESQRY:
393 rep = &msg->msg_body.dbg_reply;
395 if (cfs_copy_to_user(&ent_up->rpe_priv[0],
396 &rep->dbg_timeout, sizeof(int)) ||
397 cfs_copy_to_user(&ent_up->rpe_payload[0],
398 &rep->dbg_name, LST_NAME_SIZE))
411 lstcon_group_nodes_add(lstcon_group_t *grp,
412 int count, lnet_process_id_t *ids_up,
413 unsigned *featp, cfs_list_t *result_up)
415 lstcon_rpc_trans_t *trans;
416 lstcon_ndlink_t *ndl;
418 lnet_process_id_t id;
422 rc = lstcon_group_alloc(NULL, &tmp);
424 CERROR("Out of memory\n");
428 for (i = 0 ; i < count; i++) {
429 if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) {
434 /* skip if it's in this group already */
435 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
439 /* add to tmp group */
440 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
442 CERROR("Can't create ndlink, out of memory\n");
448 lstcon_group_put(tmp);
452 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
453 &tmp->grp_trans_list, LST_TRANS_SESNEW,
454 tmp, lstcon_sesrpc_condition, &trans);
456 CERROR("Can't create transaction: %d\n", rc);
457 lstcon_group_put(tmp);
462 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
464 rc = lstcon_rpc_trans_interpreter(trans, result_up,
465 lstcon_sesrpc_readent);
466 *featp = trans->tas_features;
468 /* destroy all RPGs */
469 lstcon_rpc_trans_destroy(trans);
471 lstcon_group_move(tmp, grp);
472 lstcon_group_put(tmp);
478 lstcon_group_nodes_remove(lstcon_group_t *grp,
479 int count, lnet_process_id_t *ids_up,
480 cfs_list_t *result_up)
482 lstcon_rpc_trans_t *trans;
483 lstcon_ndlink_t *ndl;
485 lnet_process_id_t id;
489 /* End session and remove node from the group */
491 rc = lstcon_group_alloc(NULL, &tmp);
493 CERROR("Out of memory\n");
497 for (i = 0; i < count; i++) {
498 if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) {
503 /* move node to tmp group */
504 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
505 lstcon_group_ndlink_move(grp, tmp, ndl);
508 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
509 &tmp->grp_trans_list, LST_TRANS_SESEND,
510 tmp, lstcon_sesrpc_condition, &trans);
512 CERROR("Can't create transaction: %d\n", rc);
516 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
518 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
520 lstcon_rpc_trans_destroy(trans);
521 /* release nodes anyway, because we can't rollback status */
522 lstcon_group_put(tmp);
526 lstcon_group_move(tmp, grp);
527 lstcon_group_put(tmp);
533 lstcon_group_add(char *name)
538 rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
540 /* find a group with same name */
541 lstcon_group_put(grp);
545 rc = lstcon_group_alloc(name, &grp);
547 CERROR("Can't allocate descriptor for group %s\n", name);
551 cfs_list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
557 lstcon_nodes_add(char *name, int count, lnet_process_id_t *ids_up,
558 unsigned *featp, cfs_list_t *result_up)
564 LASSERT (ids_up != NULL);
566 rc = lstcon_group_find(name, &grp);
568 CDEBUG(D_NET, "Can't find group %s\n", name);
572 if (grp->grp_ref > 2) {
573 /* referred by other threads or test */
574 CDEBUG(D_NET, "Group %s is busy\n", name);
575 lstcon_group_put(grp);
580 rc = lstcon_group_nodes_add(grp, count, ids_up, featp, result_up);
582 lstcon_group_put(grp);
588 lstcon_group_del(char *name)
590 lstcon_rpc_trans_t *trans;
594 rc = lstcon_group_find(name, &grp);
596 CDEBUG(D_NET, "Can't find group: %s\n", name);
600 if (grp->grp_ref > 2) {
601 /* referred by others threads or test */
602 CDEBUG(D_NET, "Group %s is busy\n", name);
603 lstcon_group_put(grp);
607 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
608 &grp->grp_trans_list, LST_TRANS_SESEND,
609 grp, lstcon_sesrpc_condition, &trans);
611 CERROR("Can't create transaction: %d\n", rc);
612 lstcon_group_put(grp);
616 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
618 lstcon_rpc_trans_destroy(trans);
620 lstcon_group_put(grp);
621 /* -ref for session, it's destroyed,
622 * status can't be rolled back, destroy group anway */
623 lstcon_group_put(grp);
629 lstcon_group_clean(char *name, int args)
631 lstcon_group_t *grp = NULL;
634 rc = lstcon_group_find(name, &grp);
636 CDEBUG(D_NET, "Can't find group %s\n", name);
640 if (grp->grp_ref > 2) {
641 /* referred by test */
642 CDEBUG(D_NET, "Group %s is busy\n", name);
643 lstcon_group_put(grp);
647 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
648 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
650 lstcon_group_drain(grp, args);
652 lstcon_group_put(grp);
653 /* release empty group */
654 if (cfs_list_empty(&grp->grp_ndl_list))
655 lstcon_group_put(grp);
661 lstcon_nodes_remove(char *name, int count,
662 lnet_process_id_t *ids_up, cfs_list_t *result_up)
664 lstcon_group_t *grp = NULL;
667 rc = lstcon_group_find(name, &grp);
669 CDEBUG(D_NET, "Can't find group: %s\n", name);
673 if (grp->grp_ref > 2) {
674 /* referred by test */
675 CDEBUG(D_NET, "Group %s is busy\n", name);
676 lstcon_group_put(grp);
680 rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
682 lstcon_group_put(grp);
683 /* release empty group */
684 if (cfs_list_empty(&grp->grp_ndl_list))
685 lstcon_group_put(grp);
691 lstcon_group_refresh(char *name, cfs_list_t *result_up)
693 lstcon_rpc_trans_t *trans;
697 rc = lstcon_group_find(name, &grp);
699 CDEBUG(D_NET, "Can't find group: %s\n", name);
703 if (grp->grp_ref > 2) {
704 /* referred by test */
705 CDEBUG(D_NET, "Group %s is busy\n", name);
706 lstcon_group_put(grp);
710 /* re-invite all inactive nodes int the group */
711 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
712 &grp->grp_trans_list, LST_TRANS_SESNEW,
713 grp, lstcon_sesrpc_condition, &trans);
715 /* local error, return */
716 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
717 lstcon_group_put(grp);
721 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
723 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
725 lstcon_rpc_trans_destroy(trans);
727 lstcon_group_put(grp);
733 lstcon_group_list(int index, int len, char *name_up)
737 LASSERT (index >= 0);
738 LASSERT (name_up != NULL);
740 cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list,
741 lstcon_group_t, grp_link) {
743 return cfs_copy_to_user(name_up, grp->grp_name, len) ?
752 lstcon_nodes_getent(cfs_list_t *head, int *index_p,
753 int *count_p, lstcon_node_ent_t *dents_up)
755 lstcon_ndlink_t *ndl;
760 LASSERT (index_p != NULL && count_p != NULL);
761 LASSERT (dents_up != NULL);
762 LASSERT (*index_p >= 0);
763 LASSERT (*count_p > 0);
765 cfs_list_for_each_entry_typed(ndl, head, lstcon_ndlink_t, ndl_link) {
766 if (index++ < *index_p)
769 if (count >= *count_p)
773 if (cfs_copy_to_user(&dents_up[count].nde_id,
774 &nd->nd_id, sizeof(nd->nd_id)) ||
775 cfs_copy_to_user(&dents_up[count].nde_state,
776 &nd->nd_state, sizeof(nd->nd_state)))
782 if (index <= *index_p)
792 lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p,
793 int *index_p, int *count_p, lstcon_node_ent_t *dents_up)
795 lstcon_ndlist_ent_t *gentp;
797 lstcon_ndlink_t *ndl;
800 rc = lstcon_group_find(name, &grp);
802 CDEBUG(D_NET, "Can't find group %s\n", name);
808 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
809 index_p, count_p, dents_up);
810 lstcon_group_put(grp);
815 /* non-verbose query */
816 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
818 CERROR("Can't allocate ndlist_ent\n");
819 lstcon_group_put(grp);
824 memset(gentp, 0, sizeof(lstcon_ndlist_ent_t));
826 cfs_list_for_each_entry_typed(ndl, &grp->grp_ndl_list,
827 lstcon_ndlink_t, ndl_link)
828 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
830 rc = cfs_copy_to_user(gents_p, gentp,
831 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT: 0;
833 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
835 lstcon_group_put(grp);
841 lstcon_batch_find(char *name, lstcon_batch_t **batpp)
845 cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list,
846 lstcon_batch_t, bat_link) {
847 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
857 lstcon_batch_add(char *name)
863 rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
865 CDEBUG(D_NET, "Batch %s already exists\n", name);
869 LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
871 CERROR("Can't allocate descriptor for batch %s\n", name);
875 LIBCFS_ALLOC(bat->bat_cli_hash,
876 sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
877 if (bat->bat_cli_hash == NULL) {
878 CERROR("Can't allocate hash for batch %s\n", name);
879 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
884 LIBCFS_ALLOC(bat->bat_srv_hash,
885 sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
886 if (bat->bat_srv_hash == NULL) {
887 CERROR("Can't allocate hash for batch %s\n", name);
888 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
889 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
894 strcpy(bat->bat_name, name);
895 bat->bat_hdr.tsb_index = 0;
896 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
899 bat->bat_state = LST_BATCH_IDLE;
901 CFS_INIT_LIST_HEAD(&bat->bat_cli_list);
902 CFS_INIT_LIST_HEAD(&bat->bat_srv_list);
903 CFS_INIT_LIST_HEAD(&bat->bat_test_list);
904 CFS_INIT_LIST_HEAD(&bat->bat_trans_list);
906 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
907 CFS_INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
908 CFS_INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
911 cfs_list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
917 lstcon_batch_list(int index, int len, char *name_up)
921 LASSERT (name_up != NULL);
922 LASSERT (index >= 0);
924 cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list,
925 lstcon_batch_t, bat_link) {
927 return cfs_copy_to_user(name_up,bat->bat_name, len) ?
936 lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
937 int testidx, int *index_p, int *ndent_p,
938 lstcon_node_ent_t *dents_up)
940 lstcon_test_batch_ent_t *entp;
943 lstcon_test_t *test = NULL;
945 lstcon_ndlink_t *ndl;
948 rc = lstcon_batch_find(name, &bat);
950 CDEBUG(D_NET, "Can't find batch %s\n", name);
955 /* query test, test index start from 1 */
956 cfs_list_for_each_entry_typed(test, &bat->bat_test_list,
957 lstcon_test_t, tes_link) {
963 CDEBUG(D_NET, "Can't find specified test in batch\n");
968 clilst = (test == NULL) ? &bat->bat_cli_list :
969 &test->tes_src_grp->grp_ndl_list;
970 srvlst = (test == NULL) ? &bat->bat_srv_list :
971 &test->tes_dst_grp->grp_ndl_list;
973 if (dents_up != NULL) {
974 rc = lstcon_nodes_getent((server ? srvlst: clilst),
975 index_p, ndent_p, dents_up);
979 /* non-verbose query */
980 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
984 memset(entp, 0, sizeof(lstcon_test_batch_ent_t));
987 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
988 entp->u.tbe_batch.bae_state = bat->bat_state;
992 entp->u.tbe_test.tse_type = test->tes_type;
993 entp->u.tbe_test.tse_loop = test->tes_loop;
994 entp->u.tbe_test.tse_concur = test->tes_concur;
997 cfs_list_for_each_entry_typed(ndl, clilst, lstcon_ndlink_t, ndl_link)
998 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
1000 cfs_list_for_each_entry_typed(ndl, srvlst, lstcon_ndlink_t, ndl_link)
1001 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
1003 rc = cfs_copy_to_user(ent_up, entp,
1004 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
1006 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
1012 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1015 case LST_TRANS_TSBRUN:
1016 if (nd->nd_state != LST_NODE_ACTIVE)
1020 case LST_TRANS_TSBSTOP:
1021 if (nd->nd_state != LST_NODE_ACTIVE)
1025 case LST_TRANS_TSBCLIQRY:
1026 case LST_TRANS_TSBSRVQRY:
1034 lstcon_batch_op(lstcon_batch_t *bat, int transop,
1035 cfs_list_t *result_up)
1037 lstcon_rpc_trans_t *trans;
1040 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1041 &bat->bat_trans_list, transop,
1042 bat, lstcon_batrpc_condition, &trans);
1044 CERROR("Can't create transaction: %d\n", rc);
1048 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1050 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1052 lstcon_rpc_trans_destroy(trans);
1058 lstcon_batch_run(char *name, int timeout, cfs_list_t *result_up)
1060 lstcon_batch_t *bat;
1063 if (lstcon_batch_find(name, &bat) != 0) {
1064 CDEBUG(D_NET, "Can't find batch %s\n", name);
1068 bat->bat_arg = timeout;
1070 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1072 /* mark batch as running if it's started in any node */
1073 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1074 bat->bat_state = LST_BATCH_RUNNING;
1080 lstcon_batch_stop(char *name, int force, cfs_list_t *result_up)
1082 lstcon_batch_t *bat;
1085 if (lstcon_batch_find(name, &bat) != 0) {
1086 CDEBUG(D_NET, "Can't find batch %s\n", name);
1090 bat->bat_arg = force;
1092 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1094 /* mark batch as stopped if all RPCs finished */
1095 if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1096 bat->bat_state = LST_BATCH_IDLE;
1102 lstcon_batch_destroy(lstcon_batch_t *bat)
1104 lstcon_ndlink_t *ndl;
1105 lstcon_test_t *test;
1108 cfs_list_del(&bat->bat_link);
1110 while (!cfs_list_empty(&bat->bat_test_list)) {
1111 test = cfs_list_entry(bat->bat_test_list.next,
1112 lstcon_test_t, tes_link);
1113 LASSERT (cfs_list_empty(&test->tes_trans_list));
1115 cfs_list_del(&test->tes_link);
1117 lstcon_group_put(test->tes_src_grp);
1118 lstcon_group_put(test->tes_dst_grp);
1120 LIBCFS_FREE(test, offsetof(lstcon_test_t,
1121 tes_param[test->tes_paramlen]));
1124 LASSERT (cfs_list_empty(&bat->bat_trans_list));
1126 while (!cfs_list_empty(&bat->bat_cli_list)) {
1127 ndl = cfs_list_entry(bat->bat_cli_list.next,
1128 lstcon_ndlink_t, ndl_link);
1129 cfs_list_del_init(&ndl->ndl_link);
1131 lstcon_ndlink_release(ndl);
1134 while (!cfs_list_empty(&bat->bat_srv_list)) {
1135 ndl = cfs_list_entry(bat->bat_srv_list.next,
1136 lstcon_ndlink_t, ndl_link);
1137 cfs_list_del_init(&ndl->ndl_link);
1139 lstcon_ndlink_release(ndl);
1142 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1143 LASSERT (cfs_list_empty(&bat->bat_cli_hash[i]));
1144 LASSERT (cfs_list_empty(&bat->bat_srv_hash[i]));
1147 LIBCFS_FREE(bat->bat_cli_hash,
1148 sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
1149 LIBCFS_FREE(bat->bat_srv_hash,
1150 sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
1151 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
1155 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1157 lstcon_test_t *test;
1158 lstcon_batch_t *batch;
1159 lstcon_ndlink_t *ndl;
1163 test = (lstcon_test_t *)arg;
1164 LASSERT (test != NULL);
1166 batch = test->tes_batch;
1167 LASSERT (batch != NULL);
1169 if (test->tes_oneside &&
1170 transop == LST_TRANS_TSBSRVADD)
1173 if (nd->nd_state != LST_NODE_ACTIVE)
1176 if (transop == LST_TRANS_TSBCLIADD) {
1177 hash = batch->bat_cli_hash;
1178 head = &batch->bat_cli_list;
1181 LASSERT (transop == LST_TRANS_TSBSRVADD);
1183 hash = batch->bat_srv_hash;
1184 head = &batch->bat_srv_list;
1187 LASSERT (nd->nd_id.nid != LNET_NID_ANY);
1189 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1192 if (cfs_list_empty(&ndl->ndl_link))
1193 cfs_list_add_tail(&ndl->ndl_link, head);
1199 lstcon_test_nodes_add(lstcon_test_t *test, cfs_list_t *result_up)
1201 lstcon_rpc_trans_t *trans;
1202 lstcon_group_t *grp;
1206 LASSERT (test->tes_src_grp != NULL);
1207 LASSERT (test->tes_dst_grp != NULL);
1209 transop = LST_TRANS_TSBSRVADD;
1210 grp = test->tes_dst_grp;
1212 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1213 &test->tes_trans_list, transop,
1214 test, lstcon_testrpc_condition, &trans);
1216 CERROR("Can't create transaction: %d\n", rc);
1220 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1222 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1223 lstcon_trans_stat()->trs_fwk_errno != 0) {
1224 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1226 lstcon_rpc_trans_destroy(trans);
1227 /* return if any error */
1228 CDEBUG(D_NET, "Failed to add test %s, "
1229 "RPC error %d, framework error %d\n",
1230 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1231 lstcon_trans_stat()->trs_rpc_errno,
1232 lstcon_trans_stat()->trs_fwk_errno);
1237 lstcon_rpc_trans_destroy(trans);
1239 if (transop == LST_TRANS_TSBCLIADD)
1242 transop = LST_TRANS_TSBCLIADD;
1243 grp = test->tes_src_grp;
1244 test->tes_cliidx = 0;
1246 /* requests to test clients */
1251 lstcon_test_add(char *name, int type, int loop, int concur,
1252 int dist, int span, char *src_name, char * dst_name,
1253 void *param, int paramlen, int *retp,
1254 cfs_list_t *result_up)
1256 lstcon_group_t *src_grp = NULL;
1257 lstcon_group_t *dst_grp = NULL;
1258 lstcon_test_t *test = NULL;
1259 lstcon_batch_t *batch;
1262 rc = lstcon_batch_find(name, &batch);
1264 CDEBUG(D_NET, "Can't find batch %s\n", name);
1268 if (batch->bat_state != LST_BATCH_IDLE) {
1269 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1273 rc = lstcon_group_find(src_name, &src_grp);
1275 CDEBUG(D_NET, "Can't find group %s\n", src_name);
1279 rc = lstcon_group_find(dst_name, &dst_grp);
1281 CDEBUG(D_NET, "Can't find group %s\n", dst_name);
1285 if (dst_grp->grp_userland)
1288 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1290 CERROR("Can't allocate test descriptor\n");
1296 memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen]));
1297 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1298 test->tes_batch = batch;
1299 test->tes_type = type;
1300 test->tes_oneside = 0; /* TODO */
1301 test->tes_loop = loop;
1302 test->tes_concur = concur;
1303 test->tes_stop_onerr = 1; /* TODO */
1304 test->tes_span = span;
1305 test->tes_dist = dist;
1306 test->tes_cliidx = 0; /* just used for creating RPC */
1307 test->tes_src_grp = src_grp;
1308 test->tes_dst_grp = dst_grp;
1309 CFS_INIT_LIST_HEAD(&test->tes_trans_list);
1311 if (param != NULL) {
1312 test->tes_paramlen = paramlen;
1313 memcpy(&test->tes_param[0], param, paramlen);
1316 rc = lstcon_test_nodes_add(test, result_up);
1321 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1322 lstcon_trans_stat()->trs_fwk_errno != 0)
1323 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type, name);
1325 /* add to test list anyway, so user can check what's going on */
1326 cfs_list_add_tail(&test->tes_link, &batch->bat_test_list);
1328 batch->bat_ntest ++;
1329 test->tes_hdr.tsb_index = batch->bat_ntest;
1331 /* hold groups so nobody can change them */
1335 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1337 if (dst_grp != NULL)
1338 lstcon_group_put(dst_grp);
1340 if (src_grp != NULL)
1341 lstcon_group_put(src_grp);
1347 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1349 lstcon_test_t *test;
1351 cfs_list_for_each_entry_typed(test, &batch->bat_test_list,
1352 lstcon_test_t, tes_link) {
1353 if (idx == test->tes_hdr.tsb_index) {
1363 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1364 lstcon_rpc_ent_t *ent_up)
1366 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1368 LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1369 transop == LST_TRANS_TSBSRVQRY);
1371 /* positive errno, framework error code */
1372 if (cfs_copy_to_user(&ent_up->rpe_priv[0],
1373 &rep->bar_active, sizeof(rep->bar_active)))
1380 lstcon_test_batch_query(char *name, int testidx, int client,
1381 int timeout, cfs_list_t *result_up)
1383 lstcon_rpc_trans_t *trans;
1384 cfs_list_t *translist;
1386 lstcon_tsb_hdr_t *hdr;
1387 lstcon_batch_t *batch;
1388 lstcon_test_t *test = NULL;
1392 rc = lstcon_batch_find(name, &batch);
1394 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1399 translist = &batch->bat_trans_list;
1400 ndlist = &batch->bat_cli_list;
1401 hdr = &batch->bat_hdr;
1404 /* query specified test only */
1405 rc = lstcon_test_find(batch, testidx, &test);
1407 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1411 translist = &test->tes_trans_list;
1412 ndlist = &test->tes_src_grp->grp_ndl_list;
1413 hdr = &test->tes_hdr;
1416 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1418 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1419 lstcon_batrpc_condition, &trans);
1421 CERROR("Can't create transaction: %d\n", rc);
1425 lstcon_rpc_trans_postwait(trans, timeout);
1427 if (testidx == 0 && /* query a batch, not a test */
1428 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1429 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1430 /* all RPCs finished, and no active test */
1431 batch->bat_state = LST_BATCH_IDLE;
1434 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1435 lstcon_tsbrpc_readent);
1436 lstcon_rpc_trans_destroy(trans);
1442 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1443 lstcon_rpc_ent_t *ent_up)
1445 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1446 sfw_counters_t *sfwk_stat;
1447 srpc_counters_t *srpc_stat;
1448 lnet_counters_t *lnet_stat;
1450 if (rep->str_status != 0)
1453 sfwk_stat = (sfw_counters_t *)&ent_up->rpe_payload[0];
1454 srpc_stat = (srpc_counters_t *)((char *)sfwk_stat + sizeof(*sfwk_stat));
1455 lnet_stat = (lnet_counters_t *)((char *)srpc_stat + sizeof(*srpc_stat));
1457 if (cfs_copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1458 cfs_copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1459 cfs_copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1466 lstcon_ndlist_stat(cfs_list_t *ndlist,
1467 int timeout, cfs_list_t *result_up)
1470 lstcon_rpc_trans_t *trans;
1473 CFS_INIT_LIST_HEAD(&head);
1475 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1476 LST_TRANS_STATQRY, NULL, NULL, &trans);
1478 CERROR("Can't create transaction: %d\n", rc);
1482 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1484 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1485 lstcon_statrpc_readent);
1486 lstcon_rpc_trans_destroy(trans);
1492 lstcon_group_stat(char *grp_name, int timeout, cfs_list_t *result_up)
1494 lstcon_group_t *grp;
1497 rc = lstcon_group_find(grp_name, &grp);
1499 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1503 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1505 lstcon_group_put(grp);
1511 lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
1512 int timeout, cfs_list_t *result_up)
1514 lstcon_ndlink_t *ndl;
1515 lstcon_group_t *tmp;
1516 lnet_process_id_t id;
1520 rc = lstcon_group_alloc(NULL, &tmp);
1522 CERROR("Out of memory\n");
1526 for (i = 0 ; i < count; i++) {
1527 if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) {
1532 /* add to tmp group */
1533 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1535 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1536 "Failed to find or create %s: %d\n",
1537 libcfs_id2str(id), rc);
1543 lstcon_group_put(tmp);
1547 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1549 lstcon_group_put(tmp);
1555 lstcon_debug_ndlist(cfs_list_t *ndlist,
1556 cfs_list_t *translist,
1557 int timeout, cfs_list_t *result_up)
1559 lstcon_rpc_trans_t *trans;
1562 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1563 NULL, lstcon_sesrpc_condition, &trans);
1565 CERROR("Can't create transaction: %d\n", rc);
1569 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1571 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1572 lstcon_sesrpc_readent);
1573 lstcon_rpc_trans_destroy(trans);
1579 lstcon_session_debug(int timeout, cfs_list_t *result_up)
1581 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1582 NULL, timeout, result_up);
1586 lstcon_batch_debug(int timeout, char *name,
1587 int client, cfs_list_t *result_up)
1589 lstcon_batch_t *bat;
1592 rc = lstcon_batch_find(name, &bat);
1596 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1598 NULL, timeout, result_up);
1604 lstcon_group_debug(int timeout, char *name,
1605 cfs_list_t *result_up)
1607 lstcon_group_t *grp;
1610 rc = lstcon_group_find(name, &grp);
1614 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1615 timeout, result_up);
1616 lstcon_group_put(grp);
1622 lstcon_nodes_debug(int timeout,
1623 int count, lnet_process_id_t *ids_up,
1624 cfs_list_t *result_up)
1626 lnet_process_id_t id;
1627 lstcon_ndlink_t *ndl;
1628 lstcon_group_t *grp;
1632 rc = lstcon_group_alloc(NULL, &grp);
1634 CDEBUG(D_NET, "Out of memory\n");
1638 for (i = 0; i < count; i++) {
1639 if (cfs_copy_from_user(&id, &ids_up[i], sizeof(id))) {
1644 /* node is added to tmp group */
1645 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1647 CERROR("Can't create node link\n");
1653 lstcon_group_put(grp);
1657 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1658 timeout, result_up);
1660 lstcon_group_put(grp);
1666 lstcon_session_match(lst_sid_t sid)
1668 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1669 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1: 0;
1673 lstcon_new_session_id(lst_sid_t *sid)
1675 lnet_process_id_t id;
1677 LASSERT (console_session.ses_state == LST_SESSION_NONE);
1680 sid->ses_nid = id.nid;
1681 sid->ses_stamp = cfs_time_current();
1684 extern srpc_service_t lstcon_acceptor_service;
1687 lstcon_session_new(char *name, int key, unsigned feats,
1688 int timeout, int force, lst_sid_t *sid_up)
1693 if (console_session.ses_state != LST_SESSION_NONE) {
1694 /* session exists */
1696 CNETERR("Session %s already exists\n",
1697 console_session.ses_name);
1701 rc = lstcon_session_end();
1703 /* lstcon_session_end() only return local error */
1708 if ((feats & ~LST_FEATS_MASK) != 0) {
1709 CNETERR("Unknown session features %x\n",
1710 (feats & ~LST_FEATS_MASK));
1714 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1715 LASSERT(cfs_list_empty(&console_session.ses_ndl_hash[i]));
1717 lstcon_new_session_id(&console_session.ses_id);
1719 console_session.ses_key = key;
1720 console_session.ses_state = LST_SESSION_ACTIVE;
1721 console_session.ses_force = !!force;
1722 console_session.ses_features = feats;
1723 console_session.ses_feats_updated = 0;
1724 console_session.ses_timeout = (timeout <= 0) ?
1725 LST_CONSOLE_TIMEOUT : timeout;
1726 strcpy(console_session.ses_name, name);
1728 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1732 rc = lstcon_rpc_pinger_start();
1734 lstcon_batch_t *bat = NULL;
1736 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1737 lstcon_batch_destroy(bat);
1742 if (cfs_copy_to_user(sid_up, &console_session.ses_id,
1743 sizeof(lst_sid_t)) == 0)
1746 lstcon_session_end();
1752 lstcon_session_info(lst_sid_t *sid_up, int *key_up, unsigned *featp,
1753 lstcon_ndlist_ent_t *ndinfo_up, char *name_up, int len)
1755 lstcon_ndlist_ent_t *entp;
1756 lstcon_ndlink_t *ndl;
1759 if (console_session.ses_state != LST_SESSION_ACTIVE)
1762 LIBCFS_ALLOC(entp, sizeof(*entp));
1766 memset(entp, 0, sizeof(*entp));
1768 cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_list,
1769 lstcon_ndlink_t, ndl_link)
1770 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1772 if (cfs_copy_to_user(sid_up, &console_session.ses_id,
1773 sizeof(lst_sid_t)) ||
1774 cfs_copy_to_user(key_up, &console_session.ses_key,
1776 cfs_copy_to_user(featp, &console_session.ses_features,
1778 cfs_copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1779 cfs_copy_to_user(name_up, console_session.ses_name, len))
1782 LIBCFS_FREE(entp, sizeof(*entp));
1788 lstcon_session_end()
1790 lstcon_rpc_trans_t *trans;
1791 lstcon_group_t *grp;
1792 lstcon_batch_t *bat;
1795 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1797 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1798 NULL, LST_TRANS_SESEND, NULL,
1799 lstcon_sesrpc_condition, &trans);
1801 CERROR("Can't create transaction: %d\n", rc);
1805 console_session.ses_shutdown = 1;
1807 lstcon_rpc_pinger_stop();
1809 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1811 lstcon_rpc_trans_destroy(trans);
1812 /* User can do nothing even rpc failed, so go on */
1814 /* waiting for orphan rpcs to die */
1815 lstcon_rpc_cleanup_wait();
1817 console_session.ses_id = LST_INVALID_SID;
1818 console_session.ses_state = LST_SESSION_NONE;
1819 console_session.ses_key = 0;
1820 console_session.ses_force = 0;
1821 console_session.ses_feats_updated = 0;
1823 /* destroy all batches */
1824 while (!cfs_list_empty(&console_session.ses_bat_list)) {
1825 bat = cfs_list_entry(console_session.ses_bat_list.next,
1826 lstcon_batch_t, bat_link);
1828 lstcon_batch_destroy(bat);
1831 /* destroy all groups */
1832 while (!cfs_list_empty(&console_session.ses_grp_list)) {
1833 grp = cfs_list_entry(console_session.ses_grp_list.next,
1834 lstcon_group_t, grp_link);
1835 LASSERT (grp->grp_ref == 1);
1837 lstcon_group_put(grp);
1840 /* all nodes should be released */
1841 LASSERT (cfs_list_empty(&console_session.ses_ndl_list));
1843 console_session.ses_shutdown = 0;
1844 console_session.ses_expired = 0;
1850 lstcon_session_feats_check(unsigned feats)
1854 if ((feats & ~LST_FEATS_MASK) != 0) {
1855 CERROR("Can't support these features: %x\n",
1856 (feats & ~LST_FEATS_MASK));
1860 spin_lock(&console_session.ses_rpc_lock);
1862 if (!console_session.ses_feats_updated) {
1863 console_session.ses_feats_updated = 1;
1864 console_session.ses_features = feats;
1867 if (console_session.ses_features != feats)
1870 spin_unlock(&console_session.ses_rpc_lock);
1873 CERROR("remote features %x do not match with "
1874 "session features %x of console\n",
1875 feats, console_session.ses_features);
1882 lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
1884 srpc_msg_t *rep = &rpc->srpc_replymsg;
1885 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1886 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1887 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1888 lstcon_group_t *grp = NULL;
1889 lstcon_ndlink_t *ndl;
1892 sfw_unpack_message(req);
1894 mutex_lock(&console_session.ses_mutex);
1896 jrep->join_sid = console_session.ses_id;
1898 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1899 jrep->join_status = ESRCH;
1903 if (lstcon_session_feats_check(req->msg_ses_feats) != 0) {
1904 jrep->join_status = EPROTO;
1908 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1909 !lstcon_session_match(jreq->join_sid)) {
1910 jrep->join_status = EBUSY;
1914 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1915 rc = lstcon_group_alloc(jreq->join_group, &grp);
1917 CERROR("Out of memory\n");
1921 cfs_list_add_tail(&grp->grp_link,
1922 &console_session.ses_grp_list);
1923 lstcon_group_addref(grp);
1926 if (grp->grp_ref > 2) {
1927 /* Group in using */
1928 jrep->join_status = EBUSY;
1932 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1934 jrep->join_status = EEXIST;
1938 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1940 CERROR("Out of memory\n");
1944 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1945 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1947 if (grp->grp_userland == 0)
1948 grp->grp_userland = 1;
1950 strcpy(jrep->join_session, console_session.ses_name);
1951 jrep->join_timeout = console_session.ses_timeout;
1952 jrep->join_status = 0;
1955 rep->msg_ses_feats = console_session.ses_features;
1957 lstcon_group_put(grp);
1959 mutex_unlock(&console_session.ses_mutex);
1964 srpc_service_t lstcon_acceptor_service;
1965 void lstcon_init_acceptor_service(void)
1967 /* initialize selftest console acceptor service table */
1968 lstcon_acceptor_service.sv_name = "join session";
1969 lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
1970 lstcon_acceptor_service.sv_id = SRPC_SERVICE_JOIN;
1971 lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX;
1974 extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
1976 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
1978 /* initialize console */
1980 lstcon_console_init(void)
1985 memset(&console_session, 0, sizeof(lstcon_session_t));
1987 console_session.ses_id = LST_INVALID_SID;
1988 console_session.ses_state = LST_SESSION_NONE;
1989 console_session.ses_timeout = 0;
1990 console_session.ses_force = 0;
1991 console_session.ses_expired = 0;
1992 console_session.ses_feats_updated = 0;
1993 console_session.ses_features = LST_FEATS_MASK;
1994 console_session.ses_laststamp = cfs_time_current_sec();
1996 mutex_init(&console_session.ses_mutex);
1998 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_list);
1999 CFS_INIT_LIST_HEAD(&console_session.ses_grp_list);
2000 CFS_INIT_LIST_HEAD(&console_session.ses_bat_list);
2001 CFS_INIT_LIST_HEAD(&console_session.ses_trans_list);
2003 LIBCFS_ALLOC(console_session.ses_ndl_hash,
2004 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
2005 if (console_session.ses_ndl_hash == NULL)
2008 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
2009 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
2012 /* initialize acceptor service table */
2013 lstcon_init_acceptor_service();
2015 rc = srpc_add_service(&lstcon_acceptor_service);
2016 LASSERT (rc != -EBUSY);
2018 LIBCFS_FREE(console_session.ses_ndl_hash,
2019 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
2023 rc = srpc_service_add_buffers(&lstcon_acceptor_service,
2024 lstcon_acceptor_service.sv_wi_total);
2030 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
2033 lstcon_rpc_module_init();
2038 srpc_shutdown_service(&lstcon_acceptor_service);
2039 srpc_remove_service(&lstcon_acceptor_service);
2041 LIBCFS_FREE(console_session.ses_ndl_hash,
2042 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
2044 srpc_wait_service_shutdown(&lstcon_acceptor_service);
2050 lstcon_console_fini(void)
2054 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
2056 mutex_lock(&console_session.ses_mutex);
2058 srpc_shutdown_service(&lstcon_acceptor_service);
2059 srpc_remove_service(&lstcon_acceptor_service);
2061 if (console_session.ses_state != LST_SESSION_NONE)
2062 lstcon_session_end();
2064 lstcon_rpc_module_fini();
2066 mutex_unlock(&console_session.ses_mutex);
2068 LASSERT (cfs_list_empty(&console_session.ses_ndl_list));
2069 LASSERT (cfs_list_empty(&console_session.ses_grp_list));
2070 LASSERT (cfs_list_empty(&console_session.ses_bat_list));
2071 LASSERT (cfs_list_empty(&console_session.ses_trans_list));
2073 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
2074 LASSERT (cfs_list_empty(&console_session.ses_ndl_hash[i]));
2077 LIBCFS_FREE(console_session.ses_ndl_hash,
2078 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
2080 srpc_wait_service_shutdown(&lstcon_acceptor_service);