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>
43 #include "../../include/linux/libcfs/libcfs.h"
44 #include "../../include/linux/lnet/lib-lnet.h"
48 #define LST_NODE_STATE_COUNTER(nd, p) \
50 if ((nd)->nd_state == LST_NODE_ACTIVE) \
52 else if ((nd)->nd_state == LST_NODE_BUSY) \
54 else if ((nd)->nd_state == LST_NODE_DOWN) \
57 (p)->nle_nunknown++; \
61 struct lstcon_session 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 list_for_each_entry(ndl, &console_session.ses_ndl_hash[idx], ndl_hlink) {
80 if (ndl->ndl_node->nd_id.nid != id.nid ||
81 ndl->ndl_node->nd_id.pid != id.pid)
84 lstcon_node_get(ndl->ndl_node);
85 *ndpp = ndl->ndl_node;
92 LIBCFS_ALLOC(*ndpp, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
96 ndl = (lstcon_ndlink_t *)(*ndpp + 1);
98 ndl->ndl_node = *ndpp;
100 ndl->ndl_node->nd_ref = 1;
101 ndl->ndl_node->nd_id = id;
102 ndl->ndl_node->nd_stamp = cfs_time_current();
103 ndl->ndl_node->nd_state = LST_NODE_UNKNOWN;
104 ndl->ndl_node->nd_timeout = 0;
105 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
112 list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
113 list_add_tail(&ndl->ndl_link, &console_session.ses_ndl_list);
119 lstcon_node_put(lstcon_node_t *nd)
121 lstcon_ndlink_t *ndl;
123 LASSERT(nd->nd_ref > 0);
125 if (--nd->nd_ref > 0)
128 ndl = (lstcon_ndlink_t *)(nd + 1);
130 LASSERT(!list_empty(&ndl->ndl_link));
131 LASSERT(!list_empty(&ndl->ndl_hlink));
133 /* remove from session */
134 list_del(&ndl->ndl_link);
135 list_del(&ndl->ndl_hlink);
137 LIBCFS_FREE(nd, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
141 lstcon_ndlink_find(struct list_head *hash,
142 lnet_process_id_t id, lstcon_ndlink_t **ndlpp, int create)
144 unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
145 lstcon_ndlink_t *ndl;
149 if (id.nid == LNET_NID_ANY)
153 list_for_each_entry(ndl, &hash[idx], ndl_hlink) {
154 if (ndl->ndl_node->nd_id.nid != id.nid ||
155 ndl->ndl_node->nd_id.pid != id.pid)
165 /* find or create in session hash */
166 rc = lstcon_node_find(id, &nd, (create == 1) ? 1 : 0);
170 LIBCFS_ALLOC(ndl, sizeof(lstcon_ndlink_t));
179 INIT_LIST_HEAD(&ndl->ndl_link);
180 list_add_tail(&ndl->ndl_hlink, &hash[idx]);
186 lstcon_ndlink_release(lstcon_ndlink_t *ndl)
188 LASSERT(list_empty(&ndl->ndl_link));
189 LASSERT(!list_empty(&ndl->ndl_hlink));
191 list_del(&ndl->ndl_hlink); /* delete from hash */
192 lstcon_node_put(ndl->ndl_node);
194 LIBCFS_FREE(ndl, sizeof(*ndl));
198 lstcon_group_alloc(char *name, lstcon_group_t **grpp)
203 LIBCFS_ALLOC(grp, offsetof(lstcon_group_t,
204 grp_ndl_hash[LST_NODE_HASHSIZE]));
210 strcpy(grp->grp_name, name);
212 INIT_LIST_HEAD(&grp->grp_link);
213 INIT_LIST_HEAD(&grp->grp_ndl_list);
214 INIT_LIST_HEAD(&grp->grp_trans_list);
216 for (i = 0; i < LST_NODE_HASHSIZE; i++)
217 INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
225 lstcon_group_addref(lstcon_group_t *grp)
230 static void lstcon_group_ndlink_release(lstcon_group_t *, lstcon_ndlink_t *);
233 lstcon_group_drain(lstcon_group_t *grp, int keep)
235 lstcon_ndlink_t *ndl;
236 lstcon_ndlink_t *tmp;
238 list_for_each_entry_safe(ndl, tmp, &grp->grp_ndl_list, ndl_link) {
239 if (!(ndl->ndl_node->nd_state & keep))
240 lstcon_group_ndlink_release(grp, ndl);
245 lstcon_group_decref(lstcon_group_t *grp)
249 if (--grp->grp_ref > 0)
252 if (!list_empty(&grp->grp_link))
253 list_del(&grp->grp_link);
255 lstcon_group_drain(grp, 0);
257 for (i = 0; i < LST_NODE_HASHSIZE; i++)
258 LASSERT(list_empty(&grp->grp_ndl_hash[i]));
260 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
261 grp_ndl_hash[LST_NODE_HASHSIZE]));
265 lstcon_group_find(const char *name, lstcon_group_t **grpp)
269 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
270 if (strncmp(grp->grp_name, name, LST_NAME_SIZE))
273 lstcon_group_addref(grp); /* +1 ref for caller */
282 lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id,
283 lstcon_ndlink_t **ndlpp, int create)
287 rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
291 if (!list_empty(&(*ndlpp)->ndl_link))
294 list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
301 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
303 list_del_init(&ndl->ndl_link);
304 lstcon_ndlink_release(ndl);
309 lstcon_group_ndlink_move(lstcon_group_t *old,
310 lstcon_group_t *new, lstcon_ndlink_t *ndl)
312 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
315 list_del(&ndl->ndl_hlink);
316 list_del(&ndl->ndl_link);
319 list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
320 list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
325 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
327 lstcon_ndlink_t *ndl;
329 while (!list_empty(&old->grp_ndl_list)) {
330 ndl = list_entry(old->grp_ndl_list.next,
331 lstcon_ndlink_t, ndl_link);
332 lstcon_group_ndlink_move(old, new, ndl);
337 lstcon_sesrpc_condition(int transop, lstcon_node_t *nd, void *arg)
339 lstcon_group_t *grp = (lstcon_group_t *)arg;
342 case LST_TRANS_SESNEW:
343 if (nd->nd_state == LST_NODE_ACTIVE)
347 case LST_TRANS_SESEND:
348 if (nd->nd_state != LST_NODE_ACTIVE)
351 if (grp && nd->nd_ref > 1)
355 case LST_TRANS_SESQRY:
366 lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
367 lstcon_rpc_ent_t __user *ent_up)
369 srpc_debug_reply_t *rep;
372 case LST_TRANS_SESNEW:
373 case LST_TRANS_SESEND:
376 case LST_TRANS_SESQRY:
377 rep = &msg->msg_body.dbg_reply;
379 if (copy_to_user(&ent_up->rpe_priv[0],
380 &rep->dbg_timeout, sizeof(int)) ||
381 copy_to_user(&ent_up->rpe_payload[0],
382 &rep->dbg_name, LST_NAME_SIZE))
395 lstcon_group_nodes_add(lstcon_group_t *grp,
396 int count, lnet_process_id_t __user *ids_up,
397 unsigned *featp, struct list_head __user *result_up)
399 lstcon_rpc_trans_t *trans;
400 lstcon_ndlink_t *ndl;
402 lnet_process_id_t id;
406 rc = lstcon_group_alloc(NULL, &tmp);
408 CERROR("Out of memory\n");
412 for (i = 0 ; i < count; i++) {
413 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
418 /* skip if it's in this group already */
419 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
423 /* add to tmp group */
424 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
426 CERROR("Can't create ndlink, out of memory\n");
432 lstcon_group_decref(tmp);
436 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
437 &tmp->grp_trans_list, LST_TRANS_SESNEW,
438 tmp, lstcon_sesrpc_condition, &trans);
440 CERROR("Can't create transaction: %d\n", rc);
441 lstcon_group_decref(tmp);
446 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
448 rc = lstcon_rpc_trans_interpreter(trans, result_up,
449 lstcon_sesrpc_readent);
450 *featp = trans->tas_features;
452 /* destroy all RPGs */
453 lstcon_rpc_trans_destroy(trans);
455 lstcon_group_move(tmp, grp);
456 lstcon_group_decref(tmp);
462 lstcon_group_nodes_remove(lstcon_group_t *grp,
463 int count, lnet_process_id_t __user *ids_up,
464 struct list_head __user *result_up)
466 lstcon_rpc_trans_t *trans;
467 lstcon_ndlink_t *ndl;
469 lnet_process_id_t id;
473 /* End session and remove node from the group */
475 rc = lstcon_group_alloc(NULL, &tmp);
477 CERROR("Out of memory\n");
481 for (i = 0; i < count; i++) {
482 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
487 /* move node to tmp group */
488 if (!lstcon_group_ndlink_find(grp, id, &ndl, 0))
489 lstcon_group_ndlink_move(grp, tmp, ndl);
492 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
493 &tmp->grp_trans_list, LST_TRANS_SESEND,
494 tmp, lstcon_sesrpc_condition, &trans);
496 CERROR("Can't create transaction: %d\n", rc);
500 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
502 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
504 lstcon_rpc_trans_destroy(trans);
505 /* release nodes anyway, because we can't rollback status */
506 lstcon_group_decref(tmp);
510 lstcon_group_move(tmp, grp);
511 lstcon_group_decref(tmp);
517 lstcon_group_add(char *name)
522 rc = lstcon_group_find(name, &grp) ? 0: -EEXIST;
524 /* find a group with same name */
525 lstcon_group_decref(grp);
529 rc = lstcon_group_alloc(name, &grp);
531 CERROR("Can't allocate descriptor for group %s\n", name);
535 list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
541 lstcon_nodes_add(char *name, int count, lnet_process_id_t __user *ids_up,
542 unsigned *featp, struct list_head __user *result_up)
550 rc = lstcon_group_find(name, &grp);
552 CDEBUG(D_NET, "Can't find group %s\n", name);
556 if (grp->grp_ref > 2) {
557 /* referred by other threads or test */
558 CDEBUG(D_NET, "Group %s is busy\n", name);
559 lstcon_group_decref(grp);
564 rc = lstcon_group_nodes_add(grp, count, ids_up, featp, result_up);
566 lstcon_group_decref(grp);
572 lstcon_group_del(char *name)
574 lstcon_rpc_trans_t *trans;
578 rc = lstcon_group_find(name, &grp);
580 CDEBUG(D_NET, "Can't find group: %s\n", name);
584 if (grp->grp_ref > 2) {
585 /* referred by others threads or test */
586 CDEBUG(D_NET, "Group %s is busy\n", name);
587 lstcon_group_decref(grp);
591 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
592 &grp->grp_trans_list, LST_TRANS_SESEND,
593 grp, lstcon_sesrpc_condition, &trans);
595 CERROR("Can't create transaction: %d\n", rc);
596 lstcon_group_decref(grp);
600 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
602 lstcon_rpc_trans_destroy(trans);
604 lstcon_group_decref(grp);
606 * -ref for session, it's destroyed,
607 * status can't be rolled back, destroy group anyway
609 lstcon_group_decref(grp);
615 lstcon_group_clean(char *name, int args)
617 lstcon_group_t *grp = NULL;
620 rc = lstcon_group_find(name, &grp);
622 CDEBUG(D_NET, "Can't find group %s\n", name);
626 if (grp->grp_ref > 2) {
627 /* referred by test */
628 CDEBUG(D_NET, "Group %s is busy\n", name);
629 lstcon_group_decref(grp);
633 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
634 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
636 lstcon_group_drain(grp, args);
638 lstcon_group_decref(grp);
639 /* release empty group */
640 if (list_empty(&grp->grp_ndl_list))
641 lstcon_group_decref(grp);
647 lstcon_nodes_remove(char *name, int count, lnet_process_id_t __user *ids_up,
648 struct list_head __user *result_up)
650 lstcon_group_t *grp = NULL;
653 rc = lstcon_group_find(name, &grp);
655 CDEBUG(D_NET, "Can't find group: %s\n", name);
659 if (grp->grp_ref > 2) {
660 /* referred by test */
661 CDEBUG(D_NET, "Group %s is busy\n", name);
662 lstcon_group_decref(grp);
666 rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
668 lstcon_group_decref(grp);
669 /* release empty group */
670 if (list_empty(&grp->grp_ndl_list))
671 lstcon_group_decref(grp);
677 lstcon_group_refresh(char *name, struct list_head __user *result_up)
679 lstcon_rpc_trans_t *trans;
683 rc = lstcon_group_find(name, &grp);
685 CDEBUG(D_NET, "Can't find group: %s\n", name);
689 if (grp->grp_ref > 2) {
690 /* referred by test */
691 CDEBUG(D_NET, "Group %s is busy\n", name);
692 lstcon_group_decref(grp);
696 /* re-invite all inactive nodes int the group */
697 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
698 &grp->grp_trans_list, LST_TRANS_SESNEW,
699 grp, lstcon_sesrpc_condition, &trans);
701 /* local error, return */
702 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
703 lstcon_group_decref(grp);
707 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
709 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
711 lstcon_rpc_trans_destroy(trans);
713 lstcon_group_decref(grp);
719 lstcon_group_list(int index, int len, char __user *name_up)
726 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
728 return copy_to_user(name_up, grp->grp_name, len) ?
737 lstcon_nodes_getent(struct list_head *head, int *index_p,
738 int *count_p, lstcon_node_ent_t __user *dents_up)
740 lstcon_ndlink_t *ndl;
745 LASSERT(index_p && count_p);
747 LASSERT(*index_p >= 0);
748 LASSERT(*count_p > 0);
750 list_for_each_entry(ndl, head, ndl_link) {
751 if (index++ < *index_p)
754 if (count >= *count_p)
758 if (copy_to_user(&dents_up[count].nde_id,
759 &nd->nd_id, sizeof(nd->nd_id)) ||
760 copy_to_user(&dents_up[count].nde_state,
761 &nd->nd_state, sizeof(nd->nd_state)))
767 if (index <= *index_p)
777 lstcon_group_info(char *name, lstcon_ndlist_ent_t __user *gents_p,
778 int *index_p, int *count_p,
779 lstcon_node_ent_t __user *dents_up)
781 lstcon_ndlist_ent_t *gentp;
783 lstcon_ndlink_t *ndl;
786 rc = lstcon_group_find(name, &grp);
788 CDEBUG(D_NET, "Can't find group %s\n", name);
794 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
795 index_p, count_p, dents_up);
796 lstcon_group_decref(grp);
801 /* non-verbose query */
802 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
804 CERROR("Can't allocate ndlist_ent\n");
805 lstcon_group_decref(grp);
810 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link)
811 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
813 rc = copy_to_user(gents_p, gentp,
814 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT : 0;
816 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
818 lstcon_group_decref(grp);
824 lstcon_batch_find(const char *name, lstcon_batch_t **batpp)
828 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
829 if (!strncmp(bat->bat_name, name, LST_NAME_SIZE)) {
839 lstcon_batch_add(char *name)
845 rc = !lstcon_batch_find(name, &bat) ? -EEXIST : 0;
847 CDEBUG(D_NET, "Batch %s already exists\n", name);
851 LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
853 CERROR("Can't allocate descriptor for batch %s\n", name);
857 LIBCFS_ALLOC(bat->bat_cli_hash,
858 sizeof(struct list_head) * LST_NODE_HASHSIZE);
859 if (!bat->bat_cli_hash) {
860 CERROR("Can't allocate hash for batch %s\n", name);
861 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
866 LIBCFS_ALLOC(bat->bat_srv_hash,
867 sizeof(struct list_head) * LST_NODE_HASHSIZE);
868 if (!bat->bat_srv_hash) {
869 CERROR("Can't allocate hash for batch %s\n", name);
870 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
871 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
876 strcpy(bat->bat_name, name);
877 bat->bat_hdr.tsb_index = 0;
878 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
881 bat->bat_state = LST_BATCH_IDLE;
883 INIT_LIST_HEAD(&bat->bat_cli_list);
884 INIT_LIST_HEAD(&bat->bat_srv_list);
885 INIT_LIST_HEAD(&bat->bat_test_list);
886 INIT_LIST_HEAD(&bat->bat_trans_list);
888 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
889 INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
890 INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
893 list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
899 lstcon_batch_list(int index, int len, char __user *name_up)
906 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
908 return copy_to_user(name_up, bat->bat_name, len) ?
917 lstcon_batch_info(char *name, lstcon_test_batch_ent_t __user *ent_up,
918 int server, int testidx, int *index_p, int *ndent_p,
919 lstcon_node_ent_t __user *dents_up)
921 lstcon_test_batch_ent_t *entp;
922 struct list_head *clilst;
923 struct list_head *srvlst;
924 lstcon_test_t *test = NULL;
926 lstcon_ndlink_t *ndl;
929 rc = lstcon_batch_find(name, &bat);
931 CDEBUG(D_NET, "Can't find batch %s\n", name);
936 /* query test, test index start from 1 */
937 list_for_each_entry(test, &bat->bat_test_list, tes_link) {
943 CDEBUG(D_NET, "Can't find specified test in batch\n");
948 clilst = !test ? &bat->bat_cli_list :
949 &test->tes_src_grp->grp_ndl_list;
950 srvlst = !test ? &bat->bat_srv_list :
951 &test->tes_dst_grp->grp_ndl_list;
954 rc = lstcon_nodes_getent((server ? srvlst : clilst),
955 index_p, ndent_p, dents_up);
959 /* non-verbose query */
960 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
965 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
966 entp->u.tbe_batch.bae_state = bat->bat_state;
969 entp->u.tbe_test.tse_type = test->tes_type;
970 entp->u.tbe_test.tse_loop = test->tes_loop;
971 entp->u.tbe_test.tse_concur = test->tes_concur;
974 list_for_each_entry(ndl, clilst, ndl_link)
975 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
977 list_for_each_entry(ndl, srvlst, ndl_link)
978 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
980 rc = copy_to_user(ent_up, entp,
981 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
983 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
989 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
992 case LST_TRANS_TSBRUN:
993 if (nd->nd_state != LST_NODE_ACTIVE)
997 case LST_TRANS_TSBSTOP:
998 if (nd->nd_state != LST_NODE_ACTIVE)
1002 case LST_TRANS_TSBCLIQRY:
1003 case LST_TRANS_TSBSRVQRY:
1011 lstcon_batch_op(lstcon_batch_t *bat, int transop,
1012 struct list_head __user *result_up)
1014 lstcon_rpc_trans_t *trans;
1017 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1018 &bat->bat_trans_list, transop,
1019 bat, lstcon_batrpc_condition, &trans);
1021 CERROR("Can't create transaction: %d\n", rc);
1025 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1027 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1029 lstcon_rpc_trans_destroy(trans);
1035 lstcon_batch_run(char *name, int timeout, struct list_head __user *result_up)
1037 lstcon_batch_t *bat;
1040 if (lstcon_batch_find(name, &bat)) {
1041 CDEBUG(D_NET, "Can't find batch %s\n", name);
1045 bat->bat_arg = timeout;
1047 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1049 /* mark batch as running if it's started in any node */
1050 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0))
1051 bat->bat_state = LST_BATCH_RUNNING;
1057 lstcon_batch_stop(char *name, int force, struct list_head __user *result_up)
1059 lstcon_batch_t *bat;
1062 if (lstcon_batch_find(name, &bat)) {
1063 CDEBUG(D_NET, "Can't find batch %s\n", name);
1067 bat->bat_arg = force;
1069 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1071 /* mark batch as stopped if all RPCs finished */
1072 if (!lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0))
1073 bat->bat_state = LST_BATCH_IDLE;
1079 lstcon_batch_destroy(lstcon_batch_t *bat)
1081 lstcon_ndlink_t *ndl;
1082 lstcon_test_t *test;
1085 list_del(&bat->bat_link);
1087 while (!list_empty(&bat->bat_test_list)) {
1088 test = list_entry(bat->bat_test_list.next,
1089 lstcon_test_t, tes_link);
1090 LASSERT(list_empty(&test->tes_trans_list));
1092 list_del(&test->tes_link);
1094 lstcon_group_decref(test->tes_src_grp);
1095 lstcon_group_decref(test->tes_dst_grp);
1097 LIBCFS_FREE(test, offsetof(lstcon_test_t,
1098 tes_param[test->tes_paramlen]));
1101 LASSERT(list_empty(&bat->bat_trans_list));
1103 while (!list_empty(&bat->bat_cli_list)) {
1104 ndl = list_entry(bat->bat_cli_list.next,
1105 lstcon_ndlink_t, ndl_link);
1106 list_del_init(&ndl->ndl_link);
1108 lstcon_ndlink_release(ndl);
1111 while (!list_empty(&bat->bat_srv_list)) {
1112 ndl = list_entry(bat->bat_srv_list.next,
1113 lstcon_ndlink_t, ndl_link);
1114 list_del_init(&ndl->ndl_link);
1116 lstcon_ndlink_release(ndl);
1119 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1120 LASSERT(list_empty(&bat->bat_cli_hash[i]));
1121 LASSERT(list_empty(&bat->bat_srv_hash[i]));
1124 LIBCFS_FREE(bat->bat_cli_hash,
1125 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1126 LIBCFS_FREE(bat->bat_srv_hash,
1127 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1128 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
1132 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1134 lstcon_test_t *test;
1135 lstcon_batch_t *batch;
1136 lstcon_ndlink_t *ndl;
1137 struct list_head *hash;
1138 struct list_head *head;
1140 test = (lstcon_test_t *)arg;
1143 batch = test->tes_batch;
1146 if (test->tes_oneside &&
1147 transop == LST_TRANS_TSBSRVADD)
1150 if (nd->nd_state != LST_NODE_ACTIVE)
1153 if (transop == LST_TRANS_TSBCLIADD) {
1154 hash = batch->bat_cli_hash;
1155 head = &batch->bat_cli_list;
1158 LASSERT(transop == LST_TRANS_TSBSRVADD);
1160 hash = batch->bat_srv_hash;
1161 head = &batch->bat_srv_list;
1164 LASSERT(nd->nd_id.nid != LNET_NID_ANY);
1166 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1))
1169 if (list_empty(&ndl->ndl_link))
1170 list_add_tail(&ndl->ndl_link, head);
1176 lstcon_test_nodes_add(lstcon_test_t *test, struct list_head __user *result_up)
1178 lstcon_rpc_trans_t *trans;
1179 lstcon_group_t *grp;
1183 LASSERT(test->tes_src_grp);
1184 LASSERT(test->tes_dst_grp);
1186 transop = LST_TRANS_TSBSRVADD;
1187 grp = test->tes_dst_grp;
1189 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1190 &test->tes_trans_list, transop,
1191 test, lstcon_testrpc_condition, &trans);
1193 CERROR("Can't create transaction: %d\n", rc);
1197 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1199 if (lstcon_trans_stat()->trs_rpc_errno ||
1200 lstcon_trans_stat()->trs_fwk_errno) {
1201 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1203 lstcon_rpc_trans_destroy(trans);
1204 /* return if any error */
1205 CDEBUG(D_NET, "Failed to add test %s, RPC error %d, framework error %d\n",
1206 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1207 lstcon_trans_stat()->trs_rpc_errno,
1208 lstcon_trans_stat()->trs_fwk_errno);
1213 lstcon_rpc_trans_destroy(trans);
1215 if (transop == LST_TRANS_TSBCLIADD)
1218 transop = LST_TRANS_TSBCLIADD;
1219 grp = test->tes_src_grp;
1220 test->tes_cliidx = 0;
1222 /* requests to test clients */
1227 lstcon_verify_batch(const char *name, lstcon_batch_t **batch)
1231 rc = lstcon_batch_find(name, batch);
1233 CDEBUG(D_NET, "Can't find batch %s\n", name);
1237 if ((*batch)->bat_state != LST_BATCH_IDLE) {
1238 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1246 lstcon_verify_group(const char *name, lstcon_group_t **grp)
1249 lstcon_ndlink_t *ndl;
1251 rc = lstcon_group_find(name, grp);
1253 CDEBUG(D_NET, "can't find group %s\n", name);
1257 list_for_each_entry(ndl, &(*grp)->grp_ndl_list, ndl_link) {
1258 if (ndl->ndl_node->nd_state == LST_NODE_ACTIVE)
1262 CDEBUG(D_NET, "Group %s has no ACTIVE nodes\n", name);
1268 lstcon_test_add(char *batch_name, int type, int loop,
1269 int concur, int dist, int span,
1270 char *src_name, char *dst_name,
1271 void *param, int paramlen, int *retp,
1272 struct list_head __user *result_up)
1274 lstcon_test_t *test = NULL;
1276 lstcon_group_t *src_grp = NULL;
1277 lstcon_group_t *dst_grp = NULL;
1278 lstcon_batch_t *batch = NULL;
1281 * verify that a batch of the given name exists, and the groups
1282 * that will be part of the batch exist and have at least one
1285 rc = lstcon_verify_batch(batch_name, &batch);
1289 rc = lstcon_verify_group(src_name, &src_grp);
1293 rc = lstcon_verify_group(dst_name, &dst_grp);
1297 if (dst_grp->grp_userland)
1300 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1302 CERROR("Can't allocate test descriptor\n");
1308 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1309 test->tes_batch = batch;
1310 test->tes_type = type;
1311 test->tes_oneside = 0; /* TODO */
1312 test->tes_loop = loop;
1313 test->tes_concur = concur;
1314 test->tes_stop_onerr = 1; /* TODO */
1315 test->tes_span = span;
1316 test->tes_dist = dist;
1317 test->tes_cliidx = 0; /* just used for creating RPC */
1318 test->tes_src_grp = src_grp;
1319 test->tes_dst_grp = dst_grp;
1320 INIT_LIST_HEAD(&test->tes_trans_list);
1323 test->tes_paramlen = paramlen;
1324 memcpy(&test->tes_param[0], param, paramlen);
1327 rc = lstcon_test_nodes_add(test, result_up);
1332 if (lstcon_trans_stat()->trs_rpc_errno ||
1333 lstcon_trans_stat()->trs_fwk_errno)
1334 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type,
1337 /* add to test list anyway, so user can check what's going on */
1338 list_add_tail(&test->tes_link, &batch->bat_test_list);
1341 test->tes_hdr.tsb_index = batch->bat_ntest;
1343 /* hold groups so nobody can change them */
1347 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1350 lstcon_group_decref(dst_grp);
1353 lstcon_group_decref(src_grp);
1359 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1361 lstcon_test_t *test;
1363 list_for_each_entry(test, &batch->bat_test_list, tes_link) {
1364 if (idx == test->tes_hdr.tsb_index) {
1374 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1375 lstcon_rpc_ent_t __user *ent_up)
1377 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1379 LASSERT(transop == LST_TRANS_TSBCLIQRY ||
1380 transop == LST_TRANS_TSBSRVQRY);
1382 /* positive errno, framework error code */
1383 if (copy_to_user(&ent_up->rpe_priv[0], &rep->bar_active,
1384 sizeof(rep->bar_active)))
1391 lstcon_test_batch_query(char *name, int testidx, int client,
1392 int timeout, struct list_head __user *result_up)
1394 lstcon_rpc_trans_t *trans;
1395 struct list_head *translist;
1396 struct list_head *ndlist;
1397 lstcon_tsb_hdr_t *hdr;
1398 lstcon_batch_t *batch;
1399 lstcon_test_t *test = NULL;
1403 rc = lstcon_batch_find(name, &batch);
1405 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1410 translist = &batch->bat_trans_list;
1411 ndlist = &batch->bat_cli_list;
1412 hdr = &batch->bat_hdr;
1415 /* query specified test only */
1416 rc = lstcon_test_find(batch, testidx, &test);
1418 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1422 translist = &test->tes_trans_list;
1423 ndlist = &test->tes_src_grp->grp_ndl_list;
1424 hdr = &test->tes_hdr;
1427 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1429 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1430 lstcon_batrpc_condition, &trans);
1432 CERROR("Can't create transaction: %d\n", rc);
1436 lstcon_rpc_trans_postwait(trans, timeout);
1438 if (!testidx && /* query a batch, not a test */
1439 !lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) &&
1440 !lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0)) {
1441 /* all RPCs finished, and no active test */
1442 batch->bat_state = LST_BATCH_IDLE;
1445 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1446 lstcon_tsbrpc_readent);
1447 lstcon_rpc_trans_destroy(trans);
1453 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1454 lstcon_rpc_ent_t __user *ent_up)
1456 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1457 sfw_counters_t __user *sfwk_stat;
1458 srpc_counters_t __user *srpc_stat;
1459 lnet_counters_t __user *lnet_stat;
1461 if (rep->str_status)
1464 sfwk_stat = (sfw_counters_t __user *)&ent_up->rpe_payload[0];
1465 srpc_stat = (srpc_counters_t __user *)(sfwk_stat + 1);
1466 lnet_stat = (lnet_counters_t __user *)(srpc_stat + 1);
1468 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1469 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1470 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1477 lstcon_ndlist_stat(struct list_head *ndlist,
1478 int timeout, struct list_head __user *result_up)
1480 struct list_head head;
1481 lstcon_rpc_trans_t *trans;
1484 INIT_LIST_HEAD(&head);
1486 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1487 LST_TRANS_STATQRY, NULL, NULL, &trans);
1489 CERROR("Can't create transaction: %d\n", rc);
1493 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1495 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1496 lstcon_statrpc_readent);
1497 lstcon_rpc_trans_destroy(trans);
1503 lstcon_group_stat(char *grp_name, int timeout,
1504 struct list_head __user *result_up)
1506 lstcon_group_t *grp;
1509 rc = lstcon_group_find(grp_name, &grp);
1511 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1515 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1517 lstcon_group_decref(grp);
1523 lstcon_nodes_stat(int count, lnet_process_id_t __user *ids_up,
1524 int timeout, struct list_head __user *result_up)
1526 lstcon_ndlink_t *ndl;
1527 lstcon_group_t *tmp;
1528 lnet_process_id_t id;
1532 rc = lstcon_group_alloc(NULL, &tmp);
1534 CERROR("Out of memory\n");
1538 for (i = 0 ; i < count; i++) {
1539 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1544 /* add to tmp group */
1545 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1547 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1548 "Failed to find or create %s: %d\n",
1549 libcfs_id2str(id), rc);
1555 lstcon_group_decref(tmp);
1559 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1561 lstcon_group_decref(tmp);
1567 lstcon_debug_ndlist(struct list_head *ndlist,
1568 struct list_head *translist,
1569 int timeout, struct list_head __user *result_up)
1571 lstcon_rpc_trans_t *trans;
1574 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1575 NULL, lstcon_sesrpc_condition, &trans);
1577 CERROR("Can't create transaction: %d\n", rc);
1581 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1583 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1584 lstcon_sesrpc_readent);
1585 lstcon_rpc_trans_destroy(trans);
1591 lstcon_session_debug(int timeout, struct list_head __user *result_up)
1593 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1594 NULL, timeout, result_up);
1598 lstcon_batch_debug(int timeout, char *name,
1599 int client, struct list_head __user *result_up)
1601 lstcon_batch_t *bat;
1604 rc = lstcon_batch_find(name, &bat);
1608 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1610 NULL, timeout, result_up);
1616 lstcon_group_debug(int timeout, char *name,
1617 struct list_head __user *result_up)
1619 lstcon_group_t *grp;
1622 rc = lstcon_group_find(name, &grp);
1626 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1627 timeout, result_up);
1628 lstcon_group_decref(grp);
1634 lstcon_nodes_debug(int timeout,
1635 int count, lnet_process_id_t __user *ids_up,
1636 struct list_head __user *result_up)
1638 lnet_process_id_t id;
1639 lstcon_ndlink_t *ndl;
1640 lstcon_group_t *grp;
1644 rc = lstcon_group_alloc(NULL, &grp);
1646 CDEBUG(D_NET, "Out of memory\n");
1650 for (i = 0; i < count; i++) {
1651 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1656 /* node is added to tmp group */
1657 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1659 CERROR("Can't create node link\n");
1665 lstcon_group_decref(grp);
1669 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1670 timeout, result_up);
1672 lstcon_group_decref(grp);
1678 lstcon_session_match(lst_sid_t sid)
1680 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1681 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1 : 0;
1685 lstcon_new_session_id(lst_sid_t *sid)
1687 lnet_process_id_t id;
1689 LASSERT(console_session.ses_state == LST_SESSION_NONE);
1692 sid->ses_nid = id.nid;
1693 sid->ses_stamp = cfs_time_current();
1696 extern srpc_service_t lstcon_acceptor_service;
1699 lstcon_session_new(char *name, int key, unsigned feats,
1700 int timeout, int force, lst_sid_t __user *sid_up)
1705 if (console_session.ses_state != LST_SESSION_NONE) {
1706 /* session exists */
1708 CNETERR("Session %s already exists\n",
1709 console_session.ses_name);
1713 rc = lstcon_session_end();
1715 /* lstcon_session_end() only return local error */
1720 if (feats & ~LST_FEATS_MASK) {
1721 CNETERR("Unknown session features %x\n",
1722 (feats & ~LST_FEATS_MASK));
1726 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1727 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
1729 lstcon_new_session_id(&console_session.ses_id);
1731 console_session.ses_key = key;
1732 console_session.ses_state = LST_SESSION_ACTIVE;
1733 console_session.ses_force = !!force;
1734 console_session.ses_features = feats;
1735 console_session.ses_feats_updated = 0;
1736 console_session.ses_timeout = (timeout <= 0) ?
1737 LST_CONSOLE_TIMEOUT : timeout;
1738 strlcpy(console_session.ses_name, name,
1739 sizeof(console_session.ses_name));
1741 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1745 rc = lstcon_rpc_pinger_start();
1747 lstcon_batch_t *bat = NULL;
1749 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1750 lstcon_batch_destroy(bat);
1755 if (!copy_to_user(sid_up, &console_session.ses_id,
1759 lstcon_session_end();
1765 lstcon_session_info(lst_sid_t __user *sid_up, int __user *key_up,
1766 unsigned __user *featp,
1767 lstcon_ndlist_ent_t __user *ndinfo_up,
1768 char __user *name_up, int len)
1770 lstcon_ndlist_ent_t *entp;
1771 lstcon_ndlink_t *ndl;
1774 if (console_session.ses_state != LST_SESSION_ACTIVE)
1777 LIBCFS_ALLOC(entp, sizeof(*entp));
1781 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link)
1782 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1784 if (copy_to_user(sid_up, &console_session.ses_id,
1785 sizeof(lst_sid_t)) ||
1786 copy_to_user(key_up, &console_session.ses_key,
1788 copy_to_user(featp, &console_session.ses_features,
1790 copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1791 copy_to_user(name_up, console_session.ses_name, len))
1794 LIBCFS_FREE(entp, sizeof(*entp));
1800 lstcon_session_end(void)
1802 lstcon_rpc_trans_t *trans;
1803 lstcon_group_t *grp;
1804 lstcon_batch_t *bat;
1807 LASSERT(console_session.ses_state == LST_SESSION_ACTIVE);
1809 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1810 NULL, LST_TRANS_SESEND, NULL,
1811 lstcon_sesrpc_condition, &trans);
1813 CERROR("Can't create transaction: %d\n", rc);
1817 console_session.ses_shutdown = 1;
1819 lstcon_rpc_pinger_stop();
1821 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1823 lstcon_rpc_trans_destroy(trans);
1824 /* User can do nothing even rpc failed, so go on */
1826 /* waiting for orphan rpcs to die */
1827 lstcon_rpc_cleanup_wait();
1829 console_session.ses_id = LST_INVALID_SID;
1830 console_session.ses_state = LST_SESSION_NONE;
1831 console_session.ses_key = 0;
1832 console_session.ses_force = 0;
1833 console_session.ses_feats_updated = 0;
1835 /* destroy all batches */
1836 while (!list_empty(&console_session.ses_bat_list)) {
1837 bat = list_entry(console_session.ses_bat_list.next,
1838 lstcon_batch_t, bat_link);
1840 lstcon_batch_destroy(bat);
1843 /* destroy all groups */
1844 while (!list_empty(&console_session.ses_grp_list)) {
1845 grp = list_entry(console_session.ses_grp_list.next,
1846 lstcon_group_t, grp_link);
1847 LASSERT(grp->grp_ref == 1);
1849 lstcon_group_decref(grp);
1852 /* all nodes should be released */
1853 LASSERT(list_empty(&console_session.ses_ndl_list));
1855 console_session.ses_shutdown = 0;
1856 console_session.ses_expired = 0;
1862 lstcon_session_feats_check(unsigned feats)
1866 if (feats & ~LST_FEATS_MASK) {
1867 CERROR("Can't support these features: %x\n",
1868 (feats & ~LST_FEATS_MASK));
1872 spin_lock(&console_session.ses_rpc_lock);
1874 if (!console_session.ses_feats_updated) {
1875 console_session.ses_feats_updated = 1;
1876 console_session.ses_features = feats;
1879 if (console_session.ses_features != feats)
1882 spin_unlock(&console_session.ses_rpc_lock);
1885 CERROR("remote features %x do not match with session features %x of console\n",
1886 feats, console_session.ses_features);
1893 lstcon_acceptor_handle(struct srpc_server_rpc *rpc)
1895 srpc_msg_t *rep = &rpc->srpc_replymsg;
1896 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1897 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1898 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1899 lstcon_group_t *grp = NULL;
1900 lstcon_ndlink_t *ndl;
1903 sfw_unpack_message(req);
1905 mutex_lock(&console_session.ses_mutex);
1907 jrep->join_sid = console_session.ses_id;
1909 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1910 jrep->join_status = ESRCH;
1914 if (lstcon_session_feats_check(req->msg_ses_feats)) {
1915 jrep->join_status = EPROTO;
1919 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1920 !lstcon_session_match(jreq->join_sid)) {
1921 jrep->join_status = EBUSY;
1925 if (lstcon_group_find(jreq->join_group, &grp)) {
1926 rc = lstcon_group_alloc(jreq->join_group, &grp);
1928 CERROR("Out of memory\n");
1932 list_add_tail(&grp->grp_link,
1933 &console_session.ses_grp_list);
1934 lstcon_group_addref(grp);
1937 if (grp->grp_ref > 2) {
1938 /* Group in using */
1939 jrep->join_status = EBUSY;
1943 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1945 jrep->join_status = EEXIST;
1949 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1951 CERROR("Out of memory\n");
1955 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1956 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1958 if (!grp->grp_userland)
1959 grp->grp_userland = 1;
1961 strlcpy(jrep->join_session, console_session.ses_name,
1962 sizeof(jrep->join_session));
1963 jrep->join_timeout = console_session.ses_timeout;
1964 jrep->join_status = 0;
1967 rep->msg_ses_feats = console_session.ses_features;
1969 lstcon_group_decref(grp);
1971 mutex_unlock(&console_session.ses_mutex);
1976 srpc_service_t lstcon_acceptor_service;
1977 static void lstcon_init_acceptor_service(void)
1979 /* initialize selftest console acceptor service table */
1980 lstcon_acceptor_service.sv_name = "join session";
1981 lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
1982 lstcon_acceptor_service.sv_id = SRPC_SERVICE_JOIN;
1983 lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX;
1986 extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
1988 static DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
1990 /* initialize console */
1992 lstcon_console_init(void)
1997 memset(&console_session, 0, sizeof(struct lstcon_session));
1999 console_session.ses_id = LST_INVALID_SID;
2000 console_session.ses_state = LST_SESSION_NONE;
2001 console_session.ses_timeout = 0;
2002 console_session.ses_force = 0;
2003 console_session.ses_expired = 0;
2004 console_session.ses_feats_updated = 0;
2005 console_session.ses_features = LST_FEATS_MASK;
2006 console_session.ses_laststamp = ktime_get_real_seconds();
2008 mutex_init(&console_session.ses_mutex);
2010 INIT_LIST_HEAD(&console_session.ses_ndl_list);
2011 INIT_LIST_HEAD(&console_session.ses_grp_list);
2012 INIT_LIST_HEAD(&console_session.ses_bat_list);
2013 INIT_LIST_HEAD(&console_session.ses_trans_list);
2015 LIBCFS_ALLOC(console_session.ses_ndl_hash,
2016 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2017 if (!console_session.ses_ndl_hash)
2020 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
2021 INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
2023 /* initialize acceptor service table */
2024 lstcon_init_acceptor_service();
2026 rc = srpc_add_service(&lstcon_acceptor_service);
2027 LASSERT(rc != -EBUSY);
2029 LIBCFS_FREE(console_session.ses_ndl_hash,
2030 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2034 rc = srpc_service_add_buffers(&lstcon_acceptor_service,
2035 lstcon_acceptor_service.sv_wi_total);
2041 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
2044 lstcon_rpc_module_init();
2049 srpc_shutdown_service(&lstcon_acceptor_service);
2050 srpc_remove_service(&lstcon_acceptor_service);
2052 LIBCFS_FREE(console_session.ses_ndl_hash,
2053 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2055 srpc_wait_service_shutdown(&lstcon_acceptor_service);
2061 lstcon_console_fini(void)
2065 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
2067 mutex_lock(&console_session.ses_mutex);
2069 srpc_shutdown_service(&lstcon_acceptor_service);
2070 srpc_remove_service(&lstcon_acceptor_service);
2072 if (console_session.ses_state != LST_SESSION_NONE)
2073 lstcon_session_end();
2075 lstcon_rpc_module_fini();
2077 mutex_unlock(&console_session.ses_mutex);
2079 LASSERT(list_empty(&console_session.ses_ndl_list));
2080 LASSERT(list_empty(&console_session.ses_grp_list));
2081 LASSERT(list_empty(&console_session.ses_bat_list));
2082 LASSERT(list_empty(&console_session.ses_trans_list));
2084 for (i = 0; i < LST_NODE_HASHSIZE; i++)
2085 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
2087 LIBCFS_FREE(console_session.ses_ndl_hash,
2088 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2090 srpc_wait_service_shutdown(&lstcon_acceptor_service);