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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2014, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lnet/selftest/conctl.c
34 * Infrastructure of LST console
36 * Author: Liang Zhen <liangzhen@clusterfs.com>
39 #include <libcfs/libcfs.h>
40 #include <lnet/lib-lnet.h>
44 #define LST_NODE_STATE_COUNTER(nd, p) \
46 if ((nd)->nd_state == LST_NODE_ACTIVE) \
47 (p)->nle_nactive ++; \
48 else if ((nd)->nd_state == LST_NODE_BUSY) \
50 else if ((nd)->nd_state == LST_NODE_DOWN) \
53 (p)->nle_nunknown ++; \
57 struct lstcon_session console_session;
60 lstcon_node_get(struct lstcon_node *nd)
62 LASSERT (nd->nd_ref >= 1);
68 lstcon_node_find(struct lnet_process_id id, struct lstcon_node **ndpp,
71 struct lstcon_ndlink *ndl;
72 unsigned int idx = LNET_NIDADDR(id.nid) % LST_GLOBAL_HASHSIZE;
74 LASSERT(id.nid != LNET_NID_ANY);
76 list_for_each_entry(ndl, &console_session.ses_ndl_hash[idx],
78 if (ndl->ndl_node->nd_id.nid != id.nid ||
79 ndl->ndl_node->nd_id.pid != id.pid)
82 lstcon_node_get(ndl->ndl_node);
83 *ndpp = ndl->ndl_node;
90 LIBCFS_ALLOC(*ndpp, sizeof(**ndpp) + sizeof(*ndl));
94 ndl = (struct lstcon_ndlink *)(*ndpp + 1);
96 ndl->ndl_node = *ndpp;
98 ndl->ndl_node->nd_ref = 1;
99 ndl->ndl_node->nd_id = id;
100 ndl->ndl_node->nd_stamp = ktime_get();
101 ndl->ndl_node->nd_state = LST_NODE_UNKNOWN;
102 ndl->ndl_node->nd_timeout = 0;
103 memset(&ndl->ndl_node->nd_ping, 0, sizeof(ndl->ndl_node->nd_ping));
105 /* queued in global hash & list, no refcount is taken by
106 * global hash & list, if caller release his refcount,
107 * node will be released */
108 list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
109 list_add_tail(&ndl->ndl_link, &console_session.ses_ndl_list);
115 lstcon_node_put(struct lstcon_node *nd)
117 struct lstcon_ndlink *ndl;
119 LASSERT(nd->nd_ref > 0);
121 if (--nd->nd_ref > 0)
124 ndl = (struct lstcon_ndlink *)(nd + 1);
126 LASSERT(!list_empty(&ndl->ndl_link));
127 LASSERT(!list_empty(&ndl->ndl_hlink));
129 /* remove from session */
130 list_del(&ndl->ndl_link);
131 list_del(&ndl->ndl_hlink);
133 LIBCFS_FREE(nd, sizeof(*nd) + sizeof(*ndl));
137 lstcon_ndlink_find(struct list_head *hash, struct lnet_process_id id,
138 struct lstcon_ndlink **ndlpp, int create)
140 unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
141 struct lstcon_ndlink *ndl;
142 struct lstcon_node *nd;
145 if (id.nid == LNET_NID_ANY)
149 list_for_each_entry(ndl, &hash[idx], ndl_hlink) {
150 if (ndl->ndl_node->nd_id.nid != id.nid ||
151 ndl->ndl_node->nd_id.pid != id.pid)
161 /* find or create in session hash */
162 rc = lstcon_node_find(id, &nd, (create == 1) ? 1 : 0);
166 LIBCFS_ALLOC(ndl, sizeof(*ndl));
175 INIT_LIST_HEAD(&ndl->ndl_link);
176 list_add_tail(&ndl->ndl_hlink, &hash[idx]);
182 lstcon_ndlink_release(struct lstcon_ndlink *ndl)
184 LASSERT(list_empty(&ndl->ndl_link));
185 LASSERT(!list_empty(&ndl->ndl_hlink));
187 list_del(&ndl->ndl_hlink); /* delete from hash */
188 lstcon_node_put(ndl->ndl_node);
190 LIBCFS_FREE(ndl, sizeof(*ndl));
194 lstcon_group_alloc(char *name, struct lstcon_group **grpp)
196 struct lstcon_group *grp;
199 LIBCFS_ALLOC(grp, offsetof(struct lstcon_group,
200 grp_ndl_hash[LST_NODE_HASHSIZE]));
206 if (strlen(name) > sizeof(grp->grp_name)-1) {
207 LIBCFS_FREE(grp, offsetof(struct lstcon_group,
208 grp_ndl_hash[LST_NODE_HASHSIZE]));
211 strncpy(grp->grp_name, name, sizeof(grp->grp_name));
214 INIT_LIST_HEAD(&grp->grp_link);
215 INIT_LIST_HEAD(&grp->grp_ndl_list);
216 INIT_LIST_HEAD(&grp->grp_trans_list);
218 for (i = 0; i < LST_NODE_HASHSIZE; i++)
219 INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
227 lstcon_group_addref(struct lstcon_group *grp)
232 static void lstcon_group_ndlink_release(struct lstcon_group *,
233 struct lstcon_ndlink *);
236 lstcon_group_drain(struct lstcon_group *grp, int keep)
238 struct lstcon_ndlink *ndl;
239 struct lstcon_ndlink *tmp;
241 list_for_each_entry_safe(ndl, tmp, &grp->grp_ndl_list, ndl_link) {
242 if ((ndl->ndl_node->nd_state & keep) == 0)
243 lstcon_group_ndlink_release(grp, ndl);
248 lstcon_group_decref(struct lstcon_group *grp)
252 if (--grp->grp_ref > 0)
255 if (!list_empty(&grp->grp_link))
256 list_del(&grp->grp_link);
258 lstcon_group_drain(grp, 0);
260 for (i = 0; i < LST_NODE_HASHSIZE; i++)
261 LASSERT(list_empty(&grp->grp_ndl_hash[i]));
263 LIBCFS_FREE(grp, offsetof(struct lstcon_group,
264 grp_ndl_hash[LST_NODE_HASHSIZE]));
268 lstcon_group_find(const char *name, struct lstcon_group **grpp)
270 struct lstcon_group *grp;
272 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
273 if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
276 lstcon_group_addref(grp); /* +1 ref for caller */
285 lstcon_group_ndlink_find(struct lstcon_group *grp, struct lnet_process_id id,
286 struct lstcon_ndlink **ndlpp, int create)
290 rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
294 if (!list_empty(&(*ndlpp)->ndl_link))
297 list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
304 lstcon_group_ndlink_release(struct lstcon_group *grp, struct lstcon_ndlink *ndl)
306 list_del_init(&ndl->ndl_link);
307 lstcon_ndlink_release(ndl);
312 lstcon_group_ndlink_move(struct lstcon_group *old,
313 struct lstcon_group *new, struct lstcon_ndlink *ndl)
315 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
320 list_move_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
321 list_move_tail(&ndl->ndl_link, &new->grp_ndl_list);
326 lstcon_group_move(struct lstcon_group *old, struct lstcon_group *new)
328 struct lstcon_ndlink *ndl;
330 while (!list_empty(&old->grp_ndl_list)) {
331 ndl = list_entry(old->grp_ndl_list.next,
332 struct lstcon_ndlink, ndl_link);
333 lstcon_group_ndlink_move(old, new, ndl);
338 lstcon_sesrpc_condition(int transop, struct lstcon_node *nd, void *arg)
340 struct lstcon_group *grp = arg;
343 case LST_TRANS_SESNEW:
344 if (nd->nd_state == LST_NODE_ACTIVE)
348 case LST_TRANS_SESEND:
349 if (nd->nd_state != LST_NODE_ACTIVE)
352 if (grp != NULL && nd->nd_ref > 1)
356 case LST_TRANS_SESQRY:
367 lstcon_sesrpc_readent(int transop, struct srpc_msg *msg,
368 struct lstcon_rpc_ent __user *ent_up)
370 struct srpc_debug_reply *rep;
373 case LST_TRANS_SESNEW:
374 case LST_TRANS_SESEND:
377 case LST_TRANS_SESQRY:
378 rep = &msg->msg_body.dbg_reply;
380 if (copy_to_user(&ent_up->rpe_priv[0],
381 &rep->dbg_timeout, sizeof(int)) ||
382 copy_to_user(&ent_up->rpe_payload[0],
383 &rep->dbg_name, LST_NAME_SIZE))
396 lstcon_group_nodes_add(struct lstcon_group *grp,
397 int count, struct lnet_process_id __user *ids_up,
399 struct list_head __user *result_up)
401 struct lstcon_rpc_trans *trans;
402 struct lstcon_ndlink *ndl;
403 struct lstcon_group *tmp;
404 struct lnet_process_id id;
408 rc = lstcon_group_alloc(NULL, &tmp);
410 CERROR("Out of memory\n");
414 for (i = 0 ; i < count; i++) {
415 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
420 /* skip if it's in this group already */
421 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
425 /* add to tmp group */
426 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
428 CERROR("Can't create ndlink, out of memory\n");
434 lstcon_group_decref(tmp);
438 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
439 &tmp->grp_trans_list, LST_TRANS_SESNEW,
440 tmp, lstcon_sesrpc_condition, &trans);
442 CERROR("Can't create transaction: %d\n", rc);
443 lstcon_group_decref(tmp);
448 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
450 rc = lstcon_rpc_trans_interpreter(trans, result_up,
451 lstcon_sesrpc_readent);
452 *featp = trans->tas_features;
454 /* destroy all RPGs */
455 lstcon_rpc_trans_destroy(trans);
457 lstcon_group_move(tmp, grp);
458 lstcon_group_decref(tmp);
464 lstcon_group_nodes_remove(struct lstcon_group *grp,
465 int count, struct lnet_process_id __user *ids_up,
466 struct list_head __user *result_up)
468 struct lstcon_rpc_trans *trans;
469 struct lstcon_ndlink *ndl;
470 struct lstcon_group *tmp;
471 struct lnet_process_id id;
475 /* End session and remove node from the group */
477 rc = lstcon_group_alloc(NULL, &tmp);
479 CERROR("Out of memory\n");
483 for (i = 0; i < count; i++) {
484 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
489 /* move node to tmp group */
490 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
491 lstcon_group_ndlink_move(grp, tmp, ndl);
494 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
495 &tmp->grp_trans_list, LST_TRANS_SESEND,
496 tmp, lstcon_sesrpc_condition, &trans);
498 CERROR("Can't create transaction: %d\n", rc);
502 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
504 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
506 lstcon_rpc_trans_destroy(trans);
507 /* release nodes anyway, because we can't rollback status */
508 lstcon_group_decref(tmp);
512 lstcon_group_move(tmp, grp);
513 lstcon_group_decref(tmp);
519 lstcon_group_add(char *name)
521 struct lstcon_group *grp;
524 rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
526 /* find a group with same name */
527 lstcon_group_decref(grp);
531 rc = lstcon_group_alloc(name, &grp);
533 CERROR("Can't allocate descriptor for group %s\n", name);
537 list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
543 lstcon_nodes_add(char *name, int count, struct lnet_process_id __user *ids_up,
544 unsigned *featp, struct list_head __user *result_up)
546 struct lstcon_group *grp;
550 LASSERT (ids_up != NULL);
552 rc = lstcon_group_find(name, &grp);
554 CDEBUG(D_NET, "Can't find group %s\n", name);
558 if (grp->grp_ref > 2) {
559 /* referred by other threads or test */
560 CDEBUG(D_NET, "Group %s is busy\n", name);
561 lstcon_group_decref(grp);
566 rc = lstcon_group_nodes_add(grp, count, ids_up, featp, result_up);
568 lstcon_group_decref(grp);
574 lstcon_group_del(char *name)
576 struct lstcon_rpc_trans *trans;
577 struct lstcon_group *grp;
580 rc = lstcon_group_find(name, &grp);
582 CDEBUG(D_NET, "Can't find group: %s\n", name);
586 if (grp->grp_ref > 2) {
587 /* referred by others threads or test */
588 CDEBUG(D_NET, "Group %s is busy\n", name);
589 lstcon_group_decref(grp);
593 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
594 &grp->grp_trans_list, LST_TRANS_SESEND,
595 grp, lstcon_sesrpc_condition, &trans);
597 CERROR("Can't create transaction: %d\n", rc);
598 lstcon_group_decref(grp);
602 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
604 lstcon_rpc_trans_destroy(trans);
606 lstcon_group_decref(grp);
607 /* -ref for session, it's destroyed,
608 * status can't be rolled back, destroy group anway */
609 lstcon_group_decref(grp);
615 lstcon_group_clean(char *name, int args)
617 struct lstcon_group *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,
648 struct lnet_process_id __user *ids_up,
649 struct list_head __user *result_up)
651 struct lstcon_group *grp = NULL;
654 rc = lstcon_group_find(name, &grp);
656 CDEBUG(D_NET, "Can't find group: %s\n", name);
660 if (grp->grp_ref > 2) {
661 /* referred by test */
662 CDEBUG(D_NET, "Group %s is busy\n", name);
663 lstcon_group_decref(grp);
667 rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
669 lstcon_group_decref(grp);
670 /* release empty group */
671 if (list_empty(&grp->grp_ndl_list))
672 lstcon_group_decref(grp);
678 lstcon_group_refresh(char *name, struct list_head __user *result_up)
680 struct lstcon_rpc_trans *trans;
681 struct lstcon_group *grp;
684 rc = lstcon_group_find(name, &grp);
686 CDEBUG(D_NET, "Can't find group: %s\n", name);
690 if (grp->grp_ref > 2) {
691 /* referred by test */
692 CDEBUG(D_NET, "Group %s is busy\n", name);
693 lstcon_group_decref(grp);
697 /* re-invite all inactive nodes int the group */
698 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
699 &grp->grp_trans_list, LST_TRANS_SESNEW,
700 grp, lstcon_sesrpc_condition, &trans);
702 /* local error, return */
703 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
704 lstcon_group_decref(grp);
708 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
710 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
712 lstcon_rpc_trans_destroy(trans);
714 lstcon_group_decref(grp);
720 lstcon_group_list(int index, int len, char __user *name_up)
722 struct lstcon_group *grp;
725 LASSERT(name_up != NULL);
727 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
729 return copy_to_user(name_up, grp->grp_name, len) ?
738 lstcon_nodes_getent(struct list_head *head, int *index_p,
739 int *count_p, struct lstcon_node_ent __user *dents_up)
741 struct lstcon_ndlink *ndl;
742 struct lstcon_node *nd;
746 LASSERT(index_p != NULL && count_p != NULL);
747 LASSERT(dents_up != NULL);
748 LASSERT(*index_p >= 0);
749 LASSERT(*count_p > 0);
751 list_for_each_entry(ndl, head, ndl_link) {
752 if (index++ < *index_p)
755 if (count >= *count_p)
759 if (copy_to_user(&dents_up[count].nde_id,
760 &nd->nd_id, sizeof(nd->nd_id)) ||
761 copy_to_user(&dents_up[count].nde_state,
762 &nd->nd_state, sizeof(nd->nd_state)))
768 if (index <= *index_p)
778 lstcon_group_info(char *name, struct lstcon_ndlist_ent __user *gents_p,
779 int *index_p, int *count_p,
780 struct lstcon_node_ent __user *dents_up)
782 struct lstcon_ndlist_ent *gentp;
783 struct lstcon_group *grp;
784 struct lstcon_ndlink *ndl;
787 rc = lstcon_group_find(name, &grp);
789 CDEBUG(D_NET, "Can't find group %s\n", name);
793 if (dents_up != NULL) {
795 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
796 index_p, count_p, dents_up);
797 lstcon_group_decref(grp);
802 /* non-verbose query */
803 CFS_ALLOC_PTR(gentp);
805 CERROR("Can't allocate ndlist_ent\n");
806 lstcon_group_decref(grp);
811 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link)
812 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
814 rc = copy_to_user(gents_p, gentp,
815 sizeof(struct lstcon_ndlist_ent)) ? -EFAULT : 0;
819 lstcon_group_decref(grp);
825 lstcon_batch_find(const char *name, struct lstcon_batch **batpp)
827 struct lstcon_batch *bat;
829 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
830 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
840 lstcon_batch_add(char *name)
842 struct lstcon_batch *bat;
846 rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
848 CDEBUG(D_NET, "Batch %s already exists\n", name);
852 LIBCFS_ALLOC(bat, sizeof(*bat));
854 CERROR("Can't allocate descriptor for batch %s\n", name);
858 CFS_ALLOC_PTR_ARRAY(bat->bat_cli_hash, LST_NODE_HASHSIZE);
859 if (bat->bat_cli_hash == NULL) {
860 CERROR("Can't allocate hash for batch %s\n", name);
861 LIBCFS_FREE(bat, sizeof(*bat));
866 CFS_ALLOC_PTR_ARRAY(bat->bat_srv_hash, LST_NODE_HASHSIZE);
867 if (bat->bat_srv_hash == NULL) {
868 CERROR("Can't allocate hash for batch %s\n", name);
869 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
870 LIBCFS_FREE(bat, sizeof(*bat));
875 if (strlen(name) > sizeof(bat->bat_name)-1) {
876 LIBCFS_FREE(bat->bat_srv_hash, LST_NODE_HASHSIZE);
877 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
878 LIBCFS_FREE(bat, sizeof(*bat));
881 strncpy(bat->bat_name, name, sizeof(bat->bat_name));
882 bat->bat_hdr.tsb_index = 0;
883 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
886 bat->bat_state = LST_BATCH_IDLE;
888 INIT_LIST_HEAD(&bat->bat_cli_list);
889 INIT_LIST_HEAD(&bat->bat_srv_list);
890 INIT_LIST_HEAD(&bat->bat_test_list);
891 INIT_LIST_HEAD(&bat->bat_trans_list);
893 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
894 INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
895 INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
898 list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
904 lstcon_batch_list(int index, int len, char __user *name_up)
906 struct lstcon_batch *bat;
908 LASSERT(name_up != NULL);
911 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
913 return copy_to_user(name_up, bat->bat_name, len) ?
922 lstcon_batch_info(char *name, struct lstcon_test_batch_ent __user *ent_up,
923 int server, int testidx, int *index_p, int *ndent_p,
924 struct lstcon_node_ent __user *dents_up)
926 struct lstcon_test_batch_ent *entp;
927 struct list_head *clilst;
928 struct list_head *srvlst;
929 struct lstcon_test *test = NULL;
930 struct lstcon_batch *bat;
931 struct lstcon_ndlink *ndl;
934 rc = lstcon_batch_find(name, &bat);
936 CDEBUG(D_NET, "Can't find batch %s\n", name);
941 /* query test, test index start from 1 */
942 list_for_each_entry(test, &bat->bat_test_list, tes_link) {
948 CDEBUG(D_NET, "Can't find specified test in batch\n");
953 clilst = (test == NULL) ? &bat->bat_cli_list :
954 &test->tes_src_grp->grp_ndl_list;
955 srvlst = (test == NULL) ? &bat->bat_srv_list :
956 &test->tes_dst_grp->grp_ndl_list;
958 if (dents_up != NULL) {
959 rc = lstcon_nodes_getent((server ? srvlst: clilst),
960 index_p, ndent_p, dents_up);
964 /* non-verbose query */
970 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
971 entp->u.tbe_batch.bae_state = bat->bat_state;
975 entp->u.tbe_test.tse_type = test->tes_type;
976 entp->u.tbe_test.tse_loop = test->tes_loop;
977 entp->u.tbe_test.tse_concur = test->tes_concur;
980 list_for_each_entry(ndl, clilst, ndl_link)
981 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
983 list_for_each_entry(ndl, srvlst, ndl_link)
984 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
986 rc = copy_to_user(ent_up, entp,
987 sizeof(struct lstcon_test_batch_ent)) ? -EFAULT : 0;
995 lstcon_batrpc_condition(int transop, struct lstcon_node *nd, void *arg)
998 case LST_TRANS_TSBRUN:
999 if (nd->nd_state != LST_NODE_ACTIVE)
1003 case LST_TRANS_TSBSTOP:
1004 if (nd->nd_state != LST_NODE_ACTIVE)
1008 case LST_TRANS_TSBCLIQRY:
1009 case LST_TRANS_TSBSRVQRY:
1017 lstcon_batch_op(struct lstcon_batch *bat, int transop,
1018 struct list_head __user *result_up)
1020 struct lstcon_rpc_trans *trans;
1023 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1024 &bat->bat_trans_list, transop,
1025 bat, lstcon_batrpc_condition, &trans);
1027 CERROR("Can't create transaction: %d\n", rc);
1031 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1033 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1035 lstcon_rpc_trans_destroy(trans);
1041 lstcon_batch_run(char *name, int timeout, struct list_head __user *result_up)
1043 struct lstcon_batch *bat;
1046 if (lstcon_batch_find(name, &bat) != 0) {
1047 CDEBUG(D_NET, "Can't find batch %s\n", name);
1051 bat->bat_arg = timeout;
1053 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1055 /* mark batch as running if it's started in any node */
1056 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1057 bat->bat_state = LST_BATCH_RUNNING;
1063 lstcon_batch_stop(char *name, int force, struct list_head __user *result_up)
1065 struct lstcon_batch *bat;
1068 if (lstcon_batch_find(name, &bat) != 0) {
1069 CDEBUG(D_NET, "Can't find batch %s\n", name);
1073 bat->bat_arg = force;
1075 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1077 /* mark batch as stopped if all RPCs finished */
1078 if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1079 bat->bat_state = LST_BATCH_IDLE;
1085 lstcon_batch_destroy(struct lstcon_batch *bat)
1087 struct lstcon_ndlink *ndl;
1088 struct lstcon_test *test;
1091 list_del(&bat->bat_link);
1093 while (!list_empty(&bat->bat_test_list)) {
1094 test = list_entry(bat->bat_test_list.next,
1095 struct lstcon_test, tes_link);
1096 LASSERT(list_empty(&test->tes_trans_list));
1098 list_del(&test->tes_link);
1100 lstcon_group_decref(test->tes_src_grp);
1101 lstcon_group_decref(test->tes_dst_grp);
1103 LIBCFS_FREE(test, offsetof(struct lstcon_test,
1104 tes_param[test->tes_paramlen]));
1107 LASSERT(list_empty(&bat->bat_trans_list));
1109 while (!list_empty(&bat->bat_cli_list)) {
1110 ndl = list_entry(bat->bat_cli_list.next,
1111 struct lstcon_ndlink, ndl_link);
1112 list_del_init(&ndl->ndl_link);
1114 lstcon_ndlink_release(ndl);
1117 while (!list_empty(&bat->bat_srv_list)) {
1118 ndl = list_entry(bat->bat_srv_list.next,
1119 struct lstcon_ndlink, ndl_link);
1120 list_del_init(&ndl->ndl_link);
1122 lstcon_ndlink_release(ndl);
1125 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1126 LASSERT(list_empty(&bat->bat_cli_hash[i]));
1127 LASSERT(list_empty(&bat->bat_srv_hash[i]));
1130 LIBCFS_FREE(bat->bat_cli_hash,
1131 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1132 LIBCFS_FREE(bat->bat_srv_hash,
1133 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1134 LIBCFS_FREE(bat, sizeof(*bat));
1138 lstcon_testrpc_condition(int transop, struct lstcon_node *nd, void *arg)
1140 struct lstcon_test *test = arg;
1141 struct lstcon_batch *batch;
1142 struct lstcon_ndlink *ndl;
1143 struct list_head *hash;
1144 struct list_head *head;
1146 LASSERT(test != NULL);
1148 batch = test->tes_batch;
1149 LASSERT(batch != NULL);
1151 if (test->tes_oneside &&
1152 transop == LST_TRANS_TSBSRVADD)
1155 if (nd->nd_state != LST_NODE_ACTIVE)
1158 if (transop == LST_TRANS_TSBCLIADD) {
1159 hash = batch->bat_cli_hash;
1160 head = &batch->bat_cli_list;
1163 LASSERT (transop == LST_TRANS_TSBSRVADD);
1165 hash = batch->bat_srv_hash;
1166 head = &batch->bat_srv_list;
1169 LASSERT (nd->nd_id.nid != LNET_NID_ANY);
1171 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1174 if (list_empty(&ndl->ndl_link))
1175 list_add_tail(&ndl->ndl_link, head);
1181 lstcon_test_nodes_add(struct lstcon_test *test,
1182 struct list_head __user *result_up)
1184 struct lstcon_rpc_trans *trans;
1185 struct lstcon_group *grp;
1189 LASSERT (test->tes_src_grp != NULL);
1190 LASSERT (test->tes_dst_grp != NULL);
1192 transop = LST_TRANS_TSBSRVADD;
1193 grp = test->tes_dst_grp;
1195 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1196 &test->tes_trans_list, transop,
1197 test, lstcon_testrpc_condition, &trans);
1199 CERROR("Can't create transaction: %d\n", rc);
1203 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1205 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1206 lstcon_trans_stat()->trs_fwk_errno != 0) {
1207 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1209 lstcon_rpc_trans_destroy(trans);
1210 /* return if any error */
1211 CDEBUG(D_NET, "Failed to add test %s, "
1212 "RPC error %d, framework error %d\n",
1213 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1214 lstcon_trans_stat()->trs_rpc_errno,
1215 lstcon_trans_stat()->trs_fwk_errno);
1220 lstcon_rpc_trans_destroy(trans);
1222 if (transop == LST_TRANS_TSBCLIADD)
1225 transop = LST_TRANS_TSBCLIADD;
1226 grp = test->tes_src_grp;
1227 test->tes_cliidx = 0;
1229 /* requests to test clients */
1234 lstcon_verify_batch(const char *name, struct lstcon_batch **batch)
1238 rc = lstcon_batch_find(name, batch);
1240 CDEBUG(D_NET, "Can't find batch %s\n", name);
1244 if ((*batch)->bat_state != LST_BATCH_IDLE) {
1245 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1253 lstcon_verify_group(const char *name, struct lstcon_group **grp)
1256 struct lstcon_ndlink *ndl;
1258 rc = lstcon_group_find(name, grp);
1260 CDEBUG(D_NET, "can't find group %s\n", name);
1264 list_for_each_entry(ndl, &(*grp)->grp_ndl_list, ndl_link) {
1265 if (ndl->ndl_node->nd_state == LST_NODE_ACTIVE) {
1270 CDEBUG(D_NET, "Group %s has no ACTIVE nodes\n", name);
1276 lstcon_test_add(char *batch_name, int type, int loop,
1277 int concur, int dist, int span,
1278 char *src_name, char *dst_name,
1279 void *param, int paramlen, int *retp,
1280 struct list_head __user *result_up)
1282 struct lstcon_test *test = NULL;
1284 struct lstcon_group *src_grp = NULL;
1285 struct lstcon_group *dst_grp = NULL;
1286 struct lstcon_batch *batch = NULL;
1289 * verify that a batch of the given name exists, and the groups
1290 * that will be part of the batch exist and have at least one
1293 rc = lstcon_verify_batch(batch_name, &batch);
1297 rc = lstcon_verify_group(src_name, &src_grp);
1301 rc = lstcon_verify_group(dst_name, &dst_grp);
1305 if (dst_grp->grp_userland)
1308 LIBCFS_ALLOC(test, offsetof(struct lstcon_test, tes_param[paramlen]));
1310 CERROR("Can't allocate test descriptor\n");
1316 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1317 test->tes_batch = batch;
1318 test->tes_type = type;
1319 test->tes_oneside = 0; /* TODO */
1320 test->tes_loop = loop;
1321 test->tes_concur = concur;
1322 test->tes_stop_onerr = 1; /* TODO */
1323 test->tes_span = span;
1324 test->tes_dist = dist;
1325 test->tes_cliidx = 0; /* just used for creating RPC */
1326 test->tes_src_grp = src_grp;
1327 test->tes_dst_grp = dst_grp;
1328 INIT_LIST_HEAD(&test->tes_trans_list);
1330 if (param != NULL) {
1331 test->tes_paramlen = paramlen;
1332 memcpy(&test->tes_param[0], param, paramlen);
1335 rc = lstcon_test_nodes_add(test, result_up);
1340 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1341 lstcon_trans_stat()->trs_fwk_errno != 0)
1342 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type,
1345 /* add to test list anyway, so user can check what's going on */
1346 list_add_tail(&test->tes_link, &batch->bat_test_list);
1349 test->tes_hdr.tsb_index = batch->bat_ntest;
1351 /* hold groups so nobody can change them */
1355 LIBCFS_FREE(test, offsetof(struct lstcon_test,
1356 tes_param[paramlen]));
1358 if (dst_grp != NULL)
1359 lstcon_group_decref(dst_grp);
1361 if (src_grp != NULL)
1362 lstcon_group_decref(src_grp);
1368 lstcon_test_find(struct lstcon_batch *batch, int idx,
1369 struct lstcon_test **testpp)
1371 struct lstcon_test *test;
1373 list_for_each_entry(test, &batch->bat_test_list, tes_link) {
1374 if (idx == test->tes_hdr.tsb_index) {
1384 lstcon_tsbrpc_readent(int transop, struct srpc_msg *msg,
1385 struct lstcon_rpc_ent __user *ent_up)
1387 struct srpc_batch_reply *rep = &msg->msg_body.bat_reply;
1389 LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1390 transop == LST_TRANS_TSBSRVQRY);
1392 /* positive errno, framework error code */
1393 if (copy_to_user(&ent_up->rpe_priv[0],
1394 &rep->bar_active, sizeof(rep->bar_active)))
1401 lstcon_test_batch_query(char *name, int testidx, int client,
1402 int timeout, struct list_head __user *result_up)
1404 struct lstcon_rpc_trans *trans;
1405 struct list_head *translist;
1406 struct list_head *ndlist;
1407 struct lstcon_tsb_hdr *hdr;
1408 struct lstcon_batch *batch;
1409 struct lstcon_test *test = NULL;
1413 rc = lstcon_batch_find(name, &batch);
1415 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1420 translist = &batch->bat_trans_list;
1421 ndlist = &batch->bat_cli_list;
1422 hdr = &batch->bat_hdr;
1425 /* query specified test only */
1426 rc = lstcon_test_find(batch, testidx, &test);
1428 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1432 translist = &test->tes_trans_list;
1433 ndlist = &test->tes_src_grp->grp_ndl_list;
1434 hdr = &test->tes_hdr;
1437 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1439 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1440 lstcon_batrpc_condition, &trans);
1442 CERROR("Can't create transaction: %d\n", rc);
1446 lstcon_rpc_trans_postwait(trans, timeout);
1448 if (testidx == 0 && /* query a batch, not a test */
1449 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1450 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1451 /* all RPCs finished, and no active test */
1452 batch->bat_state = LST_BATCH_IDLE;
1455 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1456 lstcon_tsbrpc_readent);
1457 lstcon_rpc_trans_destroy(trans);
1463 lstcon_statrpc_readent(int transop, struct srpc_msg *msg,
1464 struct lstcon_rpc_ent __user *ent_up)
1466 struct srpc_stat_reply *rep = &msg->msg_body.stat_reply;
1467 struct sfw_counters __user *sfwk_stat;
1468 struct srpc_counters __user *srpc_stat;
1469 struct lnet_counters_common __user *lnet_stat;
1471 if (rep->str_status != 0)
1474 sfwk_stat = (struct sfw_counters __user *)&ent_up->rpe_payload[0];
1475 srpc_stat = (struct srpc_counters __user *)
1476 ((char __user *)sfwk_stat + sizeof(*sfwk_stat));
1477 lnet_stat = (struct lnet_counters_common __user *)
1478 ((char __user *)srpc_stat + sizeof(*srpc_stat));
1480 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1481 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1482 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1489 lstcon_ndlist_stat(struct list_head *ndlist,
1490 int timeout, struct list_head __user *result_up)
1493 struct lstcon_rpc_trans *trans;
1496 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1497 LST_TRANS_STATQRY, NULL, NULL, &trans);
1499 CERROR("Can't create transaction: %d\n", rc);
1503 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1505 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1506 lstcon_statrpc_readent);
1507 lstcon_rpc_trans_destroy(trans);
1513 lstcon_group_stat(char *grp_name, int timeout,
1514 struct list_head __user *result_up)
1516 struct lstcon_group *grp;
1519 rc = lstcon_group_find(grp_name, &grp);
1521 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1525 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1527 lstcon_group_decref(grp);
1533 lstcon_nodes_stat(int count, struct lnet_process_id __user *ids_up,
1534 int timeout, struct list_head __user *result_up)
1536 struct lstcon_ndlink *ndl;
1537 struct lstcon_group *tmp;
1538 struct lnet_process_id id;
1542 rc = lstcon_group_alloc(NULL, &tmp);
1544 CERROR("Out of memory\n");
1548 for (i = 0 ; i < count; i++) {
1549 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1554 /* add to tmp group */
1555 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1557 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1558 "Failed to find or create %s: %d\n",
1559 libcfs_id2str(id), rc);
1565 lstcon_group_decref(tmp);
1569 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1571 lstcon_group_decref(tmp);
1577 lstcon_debug_ndlist(struct list_head *ndlist,
1578 struct list_head *translist,
1579 int timeout, struct list_head __user *result_up)
1581 struct lstcon_rpc_trans *trans;
1584 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1585 NULL, lstcon_sesrpc_condition, &trans);
1587 CERROR("Can't create transaction: %d\n", rc);
1591 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1593 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1594 lstcon_sesrpc_readent);
1595 lstcon_rpc_trans_destroy(trans);
1601 lstcon_session_debug(int timeout, struct list_head __user *result_up)
1603 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1604 NULL, timeout, result_up);
1608 lstcon_batch_debug(int timeout, char *name,
1609 int client, struct list_head __user *result_up)
1611 struct lstcon_batch *bat;
1614 rc = lstcon_batch_find(name, &bat);
1618 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1620 NULL, timeout, result_up);
1626 lstcon_group_debug(int timeout, char *name,
1627 struct list_head __user *result_up)
1629 struct lstcon_group *grp;
1632 rc = lstcon_group_find(name, &grp);
1636 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1637 timeout, result_up);
1638 lstcon_group_decref(grp);
1644 lstcon_nodes_debug(int timeout, int count,
1645 struct lnet_process_id __user *ids_up,
1646 struct list_head __user *result_up)
1648 struct lnet_process_id id;
1649 struct lstcon_ndlink *ndl;
1650 struct lstcon_group *grp;
1654 rc = lstcon_group_alloc(NULL, &grp);
1656 CDEBUG(D_NET, "Out of memory\n");
1660 for (i = 0; i < count; i++) {
1661 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1666 /* node is added to tmp group */
1667 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1669 CERROR("Can't create node link\n");
1675 lstcon_group_decref(grp);
1679 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1680 timeout, result_up);
1682 lstcon_group_decref(grp);
1688 lstcon_session_match(struct lst_sid sid)
1690 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1691 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1: 0;
1695 lstcon_new_session_id(struct lst_sid *sid)
1697 struct lnet_process_id id;
1699 LASSERT(console_session.ses_state == LST_SESSION_NONE);
1702 sid->ses_nid = id.nid;
1703 sid->ses_stamp = div_u64(ktime_get_ns(), NSEC_PER_MSEC);
1707 lstcon_session_new(char *name, int key, unsigned feats,
1708 int timeout, int force, struct lst_sid __user *sid_up)
1713 if (console_session.ses_state != LST_SESSION_NONE) {
1714 /* session exists */
1716 CNETERR("Session %s already exists\n",
1717 console_session.ses_name);
1721 rc = lstcon_session_end();
1723 /* lstcon_session_end() only return local error */
1728 if ((feats & ~LST_FEATS_MASK) != 0) {
1729 CNETERR("Unknown session features %x\n",
1730 (feats & ~LST_FEATS_MASK));
1734 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1735 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
1737 lstcon_new_session_id(&console_session.ses_id);
1739 console_session.ses_key = key;
1740 console_session.ses_state = LST_SESSION_ACTIVE;
1741 console_session.ses_force = !!force;
1742 console_session.ses_features = feats;
1743 console_session.ses_feats_updated = 0;
1744 console_session.ses_timeout = (timeout <= 0) ?
1745 LST_CONSOLE_TIMEOUT : timeout;
1747 if (strlen(name) > sizeof(console_session.ses_name)-1)
1749 strlcpy(console_session.ses_name, name,
1750 sizeof(console_session.ses_name));
1752 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1756 rc = lstcon_rpc_pinger_start();
1758 struct lstcon_batch *bat = NULL;
1760 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1761 lstcon_batch_destroy(bat);
1766 if (copy_to_user(sid_up, &console_session.ses_id,
1767 sizeof(struct lst_sid)) == 0)
1770 lstcon_session_end();
1776 lstcon_session_info(struct lst_sid __user *sid_up, int __user *key_up,
1777 unsigned __user *featp,
1778 struct lstcon_ndlist_ent __user *ndinfo_up,
1779 char __user *name_up, int len)
1781 struct lstcon_ndlist_ent *entp;
1782 struct lstcon_ndlink *ndl;
1785 if (console_session.ses_state != LST_SESSION_ACTIVE)
1788 LIBCFS_ALLOC(entp, sizeof(*entp));
1792 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link)
1793 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1795 if (copy_to_user(sid_up, &console_session.ses_id,
1796 sizeof(struct lst_sid)) ||
1797 copy_to_user(key_up, &console_session.ses_key,
1799 copy_to_user(featp, &console_session.ses_features,
1801 copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1802 copy_to_user(name_up, console_session.ses_name, len))
1805 LIBCFS_FREE(entp, sizeof(*entp));
1811 lstcon_session_end(void)
1813 struct lstcon_rpc_trans *trans;
1814 struct lstcon_group *grp;
1815 struct lstcon_batch *bat;
1818 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1820 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1821 NULL, LST_TRANS_SESEND, NULL,
1822 lstcon_sesrpc_condition, &trans);
1824 CERROR("Can't create transaction: %d\n", rc);
1828 console_session.ses_shutdown = 1;
1830 lstcon_rpc_pinger_stop();
1832 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1834 lstcon_rpc_trans_destroy(trans);
1835 /* User can do nothing even rpc failed, so go on */
1837 /* waiting for orphan rpcs to die */
1838 lstcon_rpc_cleanup_wait();
1840 console_session.ses_id = LST_INVALID_SID;
1841 console_session.ses_state = LST_SESSION_NONE;
1842 console_session.ses_key = 0;
1843 console_session.ses_force = 0;
1844 console_session.ses_feats_updated = 0;
1846 /* destroy all batches */
1847 while (!list_empty(&console_session.ses_bat_list)) {
1848 bat = list_entry(console_session.ses_bat_list.next,
1849 struct lstcon_batch, bat_link);
1851 lstcon_batch_destroy(bat);
1854 /* destroy all groups */
1855 while (!list_empty(&console_session.ses_grp_list)) {
1856 grp = list_entry(console_session.ses_grp_list.next,
1857 struct lstcon_group, grp_link);
1858 LASSERT(grp->grp_ref == 1);
1860 lstcon_group_decref(grp);
1863 /* all nodes should be released */
1864 LASSERT(list_empty(&console_session.ses_ndl_list));
1866 console_session.ses_shutdown = 0;
1867 console_session.ses_expired = 0;
1873 lstcon_session_feats_check(unsigned feats)
1877 if ((feats & ~LST_FEATS_MASK) != 0) {
1878 CERROR("Can't support these features: %x\n",
1879 (feats & ~LST_FEATS_MASK));
1883 spin_lock(&console_session.ses_rpc_lock);
1885 if (!console_session.ses_feats_updated) {
1886 console_session.ses_feats_updated = 1;
1887 console_session.ses_features = feats;
1890 if (console_session.ses_features != feats)
1893 spin_unlock(&console_session.ses_rpc_lock);
1896 CERROR("remote features %x do not match with "
1897 "session features %x of console\n",
1898 feats, console_session.ses_features);
1905 lstcon_acceptor_handle(struct srpc_server_rpc *rpc)
1907 struct srpc_msg *rep = &rpc->srpc_replymsg;
1908 struct srpc_msg *req = &rpc->srpc_reqstbuf->buf_msg;
1909 struct srpc_join_reqst *jreq = &req->msg_body.join_reqst;
1910 struct srpc_join_reply *jrep = &rep->msg_body.join_reply;
1911 struct lstcon_group *grp = NULL;
1912 struct lstcon_ndlink *ndl;
1915 sfw_unpack_message(req);
1917 mutex_lock(&console_session.ses_mutex);
1919 jrep->join_sid = console_session.ses_id;
1921 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1922 jrep->join_status = ESRCH;
1926 if (lstcon_session_feats_check(req->msg_ses_feats) != 0) {
1927 jrep->join_status = EPROTO;
1931 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1932 !lstcon_session_match(jreq->join_sid)) {
1933 jrep->join_status = EBUSY;
1937 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1938 rc = lstcon_group_alloc(jreq->join_group, &grp);
1940 CERROR("Out of memory\n");
1944 list_add_tail(&grp->grp_link,
1945 &console_session.ses_grp_list);
1946 lstcon_group_addref(grp);
1949 if (grp->grp_ref > 2) {
1950 /* Group in using */
1951 jrep->join_status = EBUSY;
1955 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1957 jrep->join_status = EEXIST;
1961 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1963 CERROR("Out of memory\n");
1967 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1968 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1970 if (grp->grp_userland == 0)
1971 grp->grp_userland = 1;
1973 strlcpy(jrep->join_session, console_session.ses_name,
1974 sizeof(jrep->join_session));
1975 jrep->join_timeout = console_session.ses_timeout;
1976 jrep->join_status = 0;
1979 rep->msg_ses_feats = console_session.ses_features;
1981 lstcon_group_decref(grp);
1983 mutex_unlock(&console_session.ses_mutex);
1988 static struct srpc_service lstcon_acceptor_service;
1990 static void lstcon_init_acceptor_service(void)
1992 /* initialize selftest console acceptor service table */
1993 lstcon_acceptor_service.sv_name = "join session";
1994 lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
1995 lstcon_acceptor_service.sv_id = SRPC_SERVICE_JOIN;
1996 lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX;
1999 static struct notifier_block lstcon_ioctl_handler = {
2000 .notifier_call = lstcon_ioctl_entry,
2003 /* initialize console */
2005 lstcon_console_init(void)
2010 console_session.ses_id = LST_INVALID_SID;
2011 console_session.ses_state = LST_SESSION_NONE;
2012 console_session.ses_timeout = 0;
2013 console_session.ses_force = 0;
2014 console_session.ses_expired = 0;
2015 console_session.ses_feats_updated = 0;
2016 console_session.ses_features = LST_FEATS_MASK;
2017 console_session.ses_laststamp = ktime_get_real_seconds();
2019 mutex_init(&console_session.ses_mutex);
2021 INIT_LIST_HEAD(&console_session.ses_ndl_list);
2022 INIT_LIST_HEAD(&console_session.ses_grp_list);
2023 INIT_LIST_HEAD(&console_session.ses_bat_list);
2024 INIT_LIST_HEAD(&console_session.ses_trans_list);
2026 CFS_ALLOC_PTR_ARRAY(console_session.ses_ndl_hash,
2027 LST_GLOBAL_HASHSIZE);
2028 if (console_session.ses_ndl_hash == NULL)
2031 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
2032 INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
2035 /* initialize acceptor service table */
2036 lstcon_init_acceptor_service();
2038 rc = srpc_add_service(&lstcon_acceptor_service);
2039 LASSERT(rc != -EBUSY);
2041 CFS_FREE_PTR_ARRAY(console_session.ses_ndl_hash,
2042 LST_GLOBAL_HASHSIZE);
2046 rc = srpc_service_add_buffers(&lstcon_acceptor_service,
2047 lstcon_acceptor_service.sv_wi_total);
2053 rc = blocking_notifier_chain_register(&libcfs_ioctl_list,
2054 &lstcon_ioctl_handler);
2056 lstcon_rpc_module_init();
2061 srpc_shutdown_service(&lstcon_acceptor_service);
2062 srpc_remove_service(&lstcon_acceptor_service);
2064 CFS_FREE_PTR_ARRAY(console_session.ses_ndl_hash, LST_GLOBAL_HASHSIZE);
2066 srpc_wait_service_shutdown(&lstcon_acceptor_service);
2072 lstcon_console_fini(void)
2076 blocking_notifier_chain_unregister(&libcfs_ioctl_list,
2077 &lstcon_ioctl_handler);
2079 mutex_lock(&console_session.ses_mutex);
2081 srpc_shutdown_service(&lstcon_acceptor_service);
2082 srpc_remove_service(&lstcon_acceptor_service);
2084 if (console_session.ses_state != LST_SESSION_NONE)
2085 lstcon_session_end();
2087 lstcon_rpc_module_fini();
2089 mutex_unlock(&console_session.ses_mutex);
2091 LASSERT(list_empty(&console_session.ses_ndl_list));
2092 LASSERT(list_empty(&console_session.ses_grp_list));
2093 LASSERT(list_empty(&console_session.ses_bat_list));
2094 LASSERT(list_empty(&console_session.ses_trans_list));
2096 for (i = 0; i < LST_NODE_HASHSIZE; i++)
2097 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
2099 CFS_FREE_PTR_ARRAY(console_session.ses_ndl_hash,
2100 LST_GLOBAL_HASHSIZE);
2102 srpc_wait_service_shutdown(&lstcon_acceptor_service);