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/
31 * lnet/selftest/conctl.c
33 * Infrastructure of LST console
35 * Author: Liang Zhen <liangzhen@clusterfs.com>
38 #include <libcfs/libcfs.h>
39 #include <lnet/lib-lnet.h>
43 #define LST_NODE_STATE_COUNTER(nd, p) \
45 if ((nd)->nd_state == LST_NODE_ACTIVE) \
46 (p)->nle_nactive ++; \
47 else if ((nd)->nd_state == LST_NODE_BUSY) \
49 else if ((nd)->nd_state == LST_NODE_DOWN) \
52 (p)->nle_nunknown ++; \
56 struct lstcon_session console_session;
59 lstcon_node_get(struct lstcon_node *nd)
61 LASSERT (nd->nd_ref >= 1);
67 lstcon_node_find(struct lnet_process_id id, struct lstcon_node **ndpp,
70 struct lstcon_ndlink *ndl;
71 unsigned int idx = LNET_NIDADDR(id.nid) % LST_GLOBAL_HASHSIZE;
73 LASSERT(id.nid != LNET_NID_ANY);
75 list_for_each_entry(ndl, &console_session.ses_ndl_hash[idx],
77 if (ndl->ndl_node->nd_id.nid != id.nid ||
78 ndl->ndl_node->nd_id.pid != id.pid)
81 lstcon_node_get(ndl->ndl_node);
82 *ndpp = ndl->ndl_node;
89 LIBCFS_ALLOC(*ndpp, sizeof(**ndpp) + sizeof(*ndl));
93 ndl = (struct lstcon_ndlink *)(*ndpp + 1);
95 ndl->ndl_node = *ndpp;
97 ndl->ndl_node->nd_ref = 1;
98 ndl->ndl_node->nd_id = id;
99 ndl->ndl_node->nd_stamp = ktime_get();
100 ndl->ndl_node->nd_state = LST_NODE_UNKNOWN;
101 ndl->ndl_node->nd_timeout = 0;
102 memset(&ndl->ndl_node->nd_ping, 0, sizeof(ndl->ndl_node->nd_ping));
104 /* queued in global hash & list, no refcount is taken by
105 * global hash & list, if caller release his refcount,
106 * node will be released */
107 list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
108 list_add_tail(&ndl->ndl_link, &console_session.ses_ndl_list);
114 lstcon_node_put(struct lstcon_node *nd)
116 struct lstcon_ndlink *ndl;
118 LASSERT(nd->nd_ref > 0);
120 if (--nd->nd_ref > 0)
123 ndl = (struct lstcon_ndlink *)(nd + 1);
125 LASSERT(!list_empty(&ndl->ndl_link));
126 LASSERT(!list_empty(&ndl->ndl_hlink));
128 /* remove from session */
129 list_del(&ndl->ndl_link);
130 list_del(&ndl->ndl_hlink);
132 LIBCFS_FREE(nd, sizeof(*nd) + sizeof(*ndl));
136 lstcon_ndlink_find(struct list_head *hash, struct lnet_process_id id,
137 struct lstcon_ndlink **ndlpp, int create)
139 unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
140 struct lstcon_ndlink *ndl;
141 struct lstcon_node *nd;
144 if (id.nid == LNET_NID_ANY)
148 list_for_each_entry(ndl, &hash[idx], ndl_hlink) {
149 if (ndl->ndl_node->nd_id.nid != id.nid ||
150 ndl->ndl_node->nd_id.pid != id.pid)
160 /* find or create in session hash */
161 rc = lstcon_node_find(id, &nd, (create == 1) ? 1 : 0);
165 LIBCFS_ALLOC(ndl, sizeof(*ndl));
174 INIT_LIST_HEAD(&ndl->ndl_link);
175 list_add_tail(&ndl->ndl_hlink, &hash[idx]);
181 lstcon_ndlink_release(struct lstcon_ndlink *ndl)
183 LASSERT(list_empty(&ndl->ndl_link));
184 LASSERT(!list_empty(&ndl->ndl_hlink));
186 list_del(&ndl->ndl_hlink); /* delete from hash */
187 lstcon_node_put(ndl->ndl_node);
189 LIBCFS_FREE(ndl, sizeof(*ndl));
193 lstcon_group_alloc(char *name, struct lstcon_group **grpp)
195 struct lstcon_group *grp;
198 LIBCFS_ALLOC(grp, offsetof(struct lstcon_group,
199 grp_ndl_hash[LST_NODE_HASHSIZE]));
205 if (strlen(name) > sizeof(grp->grp_name)-1) {
206 LIBCFS_FREE(grp, offsetof(struct lstcon_group,
207 grp_ndl_hash[LST_NODE_HASHSIZE]));
210 strncpy(grp->grp_name, name, sizeof(grp->grp_name));
213 INIT_LIST_HEAD(&grp->grp_link);
214 INIT_LIST_HEAD(&grp->grp_ndl_list);
215 INIT_LIST_HEAD(&grp->grp_trans_list);
217 for (i = 0; i < LST_NODE_HASHSIZE; i++)
218 INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
225 void lstcon_group_addref(struct lstcon_group *grp)
230 static void lstcon_group_ndlink_release(struct lstcon_group *,
231 struct lstcon_ndlink *);
234 lstcon_group_drain(struct lstcon_group *grp, int keep)
236 struct lstcon_ndlink *ndl;
237 struct lstcon_ndlink *tmp;
239 list_for_each_entry_safe(ndl, tmp, &grp->grp_ndl_list, ndl_link) {
240 if ((ndl->ndl_node->nd_state & keep) == 0)
241 lstcon_group_ndlink_release(grp, ndl);
245 void lstcon_group_decref(struct lstcon_group *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(struct lstcon_group,
261 grp_ndl_hash[LST_NODE_HASHSIZE]));
264 int lstcon_group_find(const char *name, struct lstcon_group **grpp)
266 struct lstcon_group *grp;
268 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
269 if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
272 lstcon_group_addref(grp); /* +1 ref for caller */
281 lstcon_group_ndlink_find(struct lstcon_group *grp, struct lnet_process_id id,
282 struct lstcon_ndlink **ndlpp, int create)
286 rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
290 if (!list_empty(&(*ndlpp)->ndl_link))
293 list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
300 lstcon_group_ndlink_release(struct lstcon_group *grp, struct lstcon_ndlink *ndl)
302 list_del_init(&ndl->ndl_link);
303 lstcon_ndlink_release(ndl);
308 lstcon_group_ndlink_move(struct lstcon_group *old,
309 struct lstcon_group *new, struct lstcon_ndlink *ndl)
311 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
316 list_move_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
317 list_move_tail(&ndl->ndl_link, &new->grp_ndl_list);
322 lstcon_group_move(struct lstcon_group *old, struct lstcon_group *new)
324 struct lstcon_ndlink *ndl;
326 while (!list_empty(&old->grp_ndl_list)) {
327 ndl = list_first_entry(&old->grp_ndl_list,
328 struct lstcon_ndlink, ndl_link);
329 lstcon_group_ndlink_move(old, new, ndl);
334 lstcon_sesrpc_condition(int transop, struct lstcon_node *nd, void *arg)
336 struct lstcon_group *grp = arg;
339 case LST_TRANS_SESNEW:
340 if (nd->nd_state == LST_NODE_ACTIVE)
344 case LST_TRANS_SESEND:
345 if (nd->nd_state != LST_NODE_ACTIVE)
348 if (grp != NULL && nd->nd_ref > 1)
352 case LST_TRANS_SESQRY:
363 lstcon_sesrpc_readent(int transop, struct srpc_msg *msg,
364 struct lstcon_rpc_ent __user *ent_up)
366 struct srpc_debug_reply *rep;
369 case LST_TRANS_SESNEW:
370 case LST_TRANS_SESEND:
373 case LST_TRANS_SESQRY:
374 rep = &msg->msg_body.dbg_reply;
376 if (copy_to_user(&ent_up->rpe_priv[0],
377 &rep->dbg_timeout, sizeof(int)) ||
378 copy_to_user(&ent_up->rpe_payload[0],
379 &rep->dbg_name, LST_NAME_SIZE))
392 lstcon_group_nodes_add(struct lstcon_group *grp,
393 int count, struct lnet_process_id __user *ids_up,
395 struct list_head __user *result_up)
397 struct lstcon_rpc_trans *trans;
398 struct lstcon_ndlink *ndl;
399 struct lstcon_group *tmp;
400 struct lnet_process_id id;
404 rc = lstcon_group_alloc(NULL, &tmp);
406 CERROR("Out of memory\n");
410 for (i = 0 ; i < count; i++) {
411 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
416 /* skip if it's in this group already */
417 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
421 /* add to tmp group */
422 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
424 CERROR("Can't create ndlink, out of memory\n");
430 lstcon_group_decref(tmp);
434 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
435 &tmp->grp_trans_list, LST_TRANS_SESNEW,
436 tmp, lstcon_sesrpc_condition, &trans);
438 CERROR("Can't create transaction: %d\n", rc);
439 lstcon_group_decref(tmp);
444 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
446 rc = lstcon_rpc_trans_interpreter(trans, result_up,
447 lstcon_sesrpc_readent);
448 *featp = trans->tas_features;
450 /* destroy all RPGs */
451 lstcon_rpc_trans_destroy(trans);
453 lstcon_group_move(tmp, grp);
454 lstcon_group_decref(tmp);
460 lstcon_group_nodes_remove(struct lstcon_group *grp,
461 int count, struct lnet_process_id __user *ids_up,
462 struct list_head __user *result_up)
464 struct lstcon_rpc_trans *trans;
465 struct lstcon_ndlink *ndl;
466 struct lstcon_group *tmp;
467 struct lnet_process_id id;
471 /* End session and remove node from the group */
473 rc = lstcon_group_alloc(NULL, &tmp);
475 CERROR("Out of memory\n");
479 for (i = 0; i < count; i++) {
480 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
485 /* move node to tmp group */
486 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
487 lstcon_group_ndlink_move(grp, tmp, ndl);
490 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
491 &tmp->grp_trans_list, LST_TRANS_SESEND,
492 tmp, lstcon_sesrpc_condition, &trans);
494 CERROR("Can't create transaction: %d\n", rc);
498 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
500 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
502 lstcon_rpc_trans_destroy(trans);
503 /* release nodes anyway, because we can't rollback status */
504 lstcon_group_decref(tmp);
508 lstcon_group_move(tmp, grp);
509 lstcon_group_decref(tmp);
515 lstcon_group_add(char *name)
517 struct lstcon_group *grp;
520 rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
522 /* find a group with same name */
523 lstcon_group_decref(grp);
527 rc = lstcon_group_alloc(name, &grp);
529 CERROR("Can't allocate descriptor for group %s\n", name);
533 list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
539 lstcon_nodes_add(char *name, int count, struct lnet_process_id __user *ids_up,
540 unsigned *featp, struct list_head __user *result_up)
542 struct lstcon_group *grp;
546 LASSERT (ids_up != NULL);
548 rc = lstcon_group_find(name, &grp);
550 CDEBUG(D_NET, "Can't find group %s\n", name);
554 if (grp->grp_ref > 2) {
555 /* referred by other threads or test */
556 CDEBUG(D_NET, "Group %s is busy\n", name);
557 lstcon_group_decref(grp);
562 rc = lstcon_group_nodes_add(grp, count, ids_up, featp, result_up);
564 lstcon_group_decref(grp);
570 lstcon_group_del(char *name)
572 struct lstcon_rpc_trans *trans;
573 struct lstcon_group *grp;
576 rc = lstcon_group_find(name, &grp);
578 CDEBUG(D_NET, "Can't find group: %s\n", name);
582 if (grp->grp_ref > 2) {
583 /* referred by others threads or test */
584 CDEBUG(D_NET, "Group %s is busy\n", name);
585 lstcon_group_decref(grp);
589 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
590 &grp->grp_trans_list, LST_TRANS_SESEND,
591 grp, lstcon_sesrpc_condition, &trans);
593 CERROR("Can't create transaction: %d\n", rc);
594 lstcon_group_decref(grp);
598 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
600 lstcon_rpc_trans_destroy(trans);
602 lstcon_group_decref(grp);
603 /* -ref for session, it's destroyed,
604 * status can't be rolled back, destroy group anway */
605 lstcon_group_decref(grp);
611 lstcon_group_clean(char *name, int args)
613 struct lstcon_group *grp = NULL;
616 rc = lstcon_group_find(name, &grp);
618 CDEBUG(D_NET, "Can't find group %s\n", name);
622 if (grp->grp_ref > 2) {
623 /* referred by test */
624 CDEBUG(D_NET, "Group %s is busy\n", name);
625 lstcon_group_decref(grp);
629 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
630 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
632 lstcon_group_drain(grp, args);
634 lstcon_group_decref(grp);
635 /* release empty group */
636 if (list_empty(&grp->grp_ndl_list))
637 lstcon_group_decref(grp);
643 lstcon_nodes_remove(char *name, int count,
644 struct lnet_process_id __user *ids_up,
645 struct list_head __user *result_up)
647 struct lstcon_group *grp = NULL;
650 rc = lstcon_group_find(name, &grp);
652 CDEBUG(D_NET, "Can't find group: %s\n", name);
656 if (grp->grp_ref > 2) {
657 /* referred by test */
658 CDEBUG(D_NET, "Group %s is busy\n", name);
659 lstcon_group_decref(grp);
663 rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
665 lstcon_group_decref(grp);
666 /* release empty group */
667 if (list_empty(&grp->grp_ndl_list))
668 lstcon_group_decref(grp);
674 lstcon_group_refresh(char *name, struct list_head __user *result_up)
676 struct lstcon_rpc_trans *trans;
677 struct lstcon_group *grp;
680 rc = lstcon_group_find(name, &grp);
682 CDEBUG(D_NET, "Can't find group: %s\n", name);
686 if (grp->grp_ref > 2) {
687 /* referred by test */
688 CDEBUG(D_NET, "Group %s is busy\n", name);
689 lstcon_group_decref(grp);
693 /* re-invite all inactive nodes int the group */
694 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
695 &grp->grp_trans_list, LST_TRANS_SESNEW,
696 grp, lstcon_sesrpc_condition, &trans);
698 /* local error, return */
699 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
700 lstcon_group_decref(grp);
704 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
706 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
708 lstcon_rpc_trans_destroy(trans);
710 lstcon_group_decref(grp);
716 lstcon_nodes_getent(struct list_head *head, int *index_p,
717 int *count_p, struct lstcon_node_ent __user *dents_up)
719 struct lstcon_ndlink *ndl;
720 struct lstcon_node *nd;
724 LASSERT(index_p != NULL && count_p != NULL);
725 LASSERT(dents_up != NULL);
726 LASSERT(*index_p >= 0);
727 LASSERT(*count_p > 0);
729 list_for_each_entry(ndl, head, ndl_link) {
730 if (index++ < *index_p)
733 if (count >= *count_p)
737 if (copy_to_user(&dents_up[count].nde_id,
738 &nd->nd_id, sizeof(nd->nd_id)) ||
739 copy_to_user(&dents_up[count].nde_state,
740 &nd->nd_state, sizeof(nd->nd_state)))
746 if (index <= *index_p)
756 lstcon_group_info(char *name, struct lstcon_ndlist_ent __user *gents_p,
757 int *index_p, int *count_p,
758 struct lstcon_node_ent __user *dents_up)
760 struct lstcon_ndlist_ent *gentp;
761 struct lstcon_group *grp;
762 struct lstcon_ndlink *ndl;
765 rc = lstcon_group_find(name, &grp);
767 CDEBUG(D_NET, "Can't find group %s\n", name);
771 if (dents_up != NULL) {
773 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
774 index_p, count_p, dents_up);
775 lstcon_group_decref(grp);
780 /* non-verbose query */
781 CFS_ALLOC_PTR(gentp);
783 CERROR("Can't allocate ndlist_ent\n");
784 lstcon_group_decref(grp);
789 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link)
790 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
792 rc = copy_to_user(gents_p, gentp,
793 sizeof(struct lstcon_ndlist_ent)) ? -EFAULT : 0;
797 lstcon_group_decref(grp);
803 lstcon_batch_find(const char *name, struct lstcon_batch **batpp)
805 struct lstcon_batch *bat;
807 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
808 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
818 lstcon_batch_add(char *name)
820 struct lstcon_batch *bat;
824 rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
826 CDEBUG(D_NET, "Batch %s already exists\n", name);
830 LIBCFS_ALLOC(bat, sizeof(*bat));
832 CERROR("Can't allocate descriptor for batch %s\n", name);
836 CFS_ALLOC_PTR_ARRAY(bat->bat_cli_hash, LST_NODE_HASHSIZE);
837 if (bat->bat_cli_hash == NULL) {
838 CERROR("Can't allocate hash for batch %s\n", name);
839 LIBCFS_FREE(bat, sizeof(*bat));
844 CFS_ALLOC_PTR_ARRAY(bat->bat_srv_hash, LST_NODE_HASHSIZE);
845 if (bat->bat_srv_hash == NULL) {
846 CERROR("Can't allocate hash for batch %s\n", name);
847 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
848 LIBCFS_FREE(bat, sizeof(*bat));
853 if (strlen(name) > sizeof(bat->bat_name)-1) {
854 LIBCFS_FREE(bat->bat_srv_hash, LST_NODE_HASHSIZE);
855 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
856 LIBCFS_FREE(bat, sizeof(*bat));
859 strncpy(bat->bat_name, name, sizeof(bat->bat_name));
860 bat->bat_hdr.tsb_index = 0;
861 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
864 bat->bat_state = LST_BATCH_IDLE;
866 INIT_LIST_HEAD(&bat->bat_cli_list);
867 INIT_LIST_HEAD(&bat->bat_srv_list);
868 INIT_LIST_HEAD(&bat->bat_test_list);
869 INIT_LIST_HEAD(&bat->bat_trans_list);
871 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
872 INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
873 INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
876 list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
882 lstcon_batch_list(int index, int len, char __user *name_up)
884 struct lstcon_batch *bat;
886 LASSERT(name_up != NULL);
889 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
891 return copy_to_user(name_up, bat->bat_name, len) ?
900 lstcon_batch_info(char *name, struct lstcon_test_batch_ent __user *ent_up,
901 int server, int testidx, int *index_p, int *ndent_p,
902 struct lstcon_node_ent __user *dents_up)
904 struct lstcon_test_batch_ent *entp;
905 struct list_head *clilst;
906 struct list_head *srvlst;
907 struct lstcon_test *test = NULL;
908 struct lstcon_batch *bat;
909 struct lstcon_ndlink *ndl;
912 rc = lstcon_batch_find(name, &bat);
914 CDEBUG(D_NET, "Can't find batch %s\n", name);
919 /* query test, test index start from 1 */
920 list_for_each_entry(test, &bat->bat_test_list, tes_link) {
926 CDEBUG(D_NET, "Can't find specified test in batch\n");
931 clilst = (test == NULL) ? &bat->bat_cli_list :
932 &test->tes_src_grp->grp_ndl_list;
933 srvlst = (test == NULL) ? &bat->bat_srv_list :
934 &test->tes_dst_grp->grp_ndl_list;
936 if (dents_up != NULL) {
937 rc = lstcon_nodes_getent((server ? srvlst: clilst),
938 index_p, ndent_p, dents_up);
942 /* non-verbose query */
948 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
949 entp->u.tbe_batch.bae_state = bat->bat_state;
953 entp->u.tbe_test.tse_type = test->tes_type;
954 entp->u.tbe_test.tse_loop = test->tes_loop;
955 entp->u.tbe_test.tse_concur = test->tes_concur;
958 list_for_each_entry(ndl, clilst, ndl_link)
959 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
961 list_for_each_entry(ndl, srvlst, ndl_link)
962 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
964 rc = copy_to_user(ent_up, entp,
965 sizeof(struct lstcon_test_batch_ent)) ? -EFAULT : 0;
973 lstcon_batrpc_condition(int transop, struct lstcon_node *nd, void *arg)
976 case LST_TRANS_TSBRUN:
977 if (nd->nd_state != LST_NODE_ACTIVE)
981 case LST_TRANS_TSBSTOP:
982 if (nd->nd_state != LST_NODE_ACTIVE)
986 case LST_TRANS_TSBCLIQRY:
987 case LST_TRANS_TSBSRVQRY:
995 lstcon_batch_op(struct lstcon_batch *bat, int transop,
996 struct list_head __user *result_up)
998 struct lstcon_rpc_trans *trans;
1001 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1002 &bat->bat_trans_list, transop,
1003 bat, lstcon_batrpc_condition, &trans);
1005 CERROR("Can't create transaction: %d\n", rc);
1009 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1011 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1013 lstcon_rpc_trans_destroy(trans);
1019 lstcon_batch_run(char *name, int timeout, struct list_head __user *result_up)
1021 struct lstcon_batch *bat;
1024 if (lstcon_batch_find(name, &bat) != 0) {
1025 CDEBUG(D_NET, "Can't find batch %s\n", name);
1029 bat->bat_arg = timeout;
1031 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1033 /* mark batch as running if it's started in any node */
1034 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1035 bat->bat_state = LST_BATCH_RUNNING;
1041 lstcon_batch_stop(char *name, int force, 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 = force;
1053 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1055 /* mark batch as stopped if all RPCs finished */
1056 if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1057 bat->bat_state = LST_BATCH_IDLE;
1063 lstcon_batch_destroy(struct lstcon_batch *bat)
1065 struct lstcon_ndlink *ndl;
1066 struct lstcon_test *test;
1069 list_del(&bat->bat_link);
1071 while (!list_empty(&bat->bat_test_list)) {
1072 test = list_first_entry(&bat->bat_test_list,
1073 struct lstcon_test, tes_link);
1074 LASSERT(list_empty(&test->tes_trans_list));
1076 list_del(&test->tes_link);
1078 lstcon_group_decref(test->tes_src_grp);
1079 lstcon_group_decref(test->tes_dst_grp);
1081 LIBCFS_FREE(test, offsetof(struct lstcon_test,
1082 tes_param[test->tes_paramlen]));
1085 LASSERT(list_empty(&bat->bat_trans_list));
1087 while (!list_empty(&bat->bat_cli_list)) {
1088 ndl = list_first_entry(&bat->bat_cli_list,
1089 struct lstcon_ndlink, ndl_link);
1090 list_del_init(&ndl->ndl_link);
1092 lstcon_ndlink_release(ndl);
1095 while (!list_empty(&bat->bat_srv_list)) {
1096 ndl = list_first_entry(&bat->bat_srv_list,
1097 struct lstcon_ndlink, ndl_link);
1098 list_del_init(&ndl->ndl_link);
1100 lstcon_ndlink_release(ndl);
1103 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1104 LASSERT(list_empty(&bat->bat_cli_hash[i]));
1105 LASSERT(list_empty(&bat->bat_srv_hash[i]));
1108 LIBCFS_FREE(bat->bat_cli_hash,
1109 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1110 LIBCFS_FREE(bat->bat_srv_hash,
1111 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1112 LIBCFS_FREE(bat, sizeof(*bat));
1116 lstcon_testrpc_condition(int transop, struct lstcon_node *nd, void *arg)
1118 struct lstcon_test *test = arg;
1119 struct lstcon_batch *batch;
1120 struct lstcon_ndlink *ndl;
1121 struct list_head *hash;
1122 struct list_head *head;
1124 LASSERT(test != NULL);
1126 batch = test->tes_batch;
1127 LASSERT(batch != NULL);
1129 if (test->tes_oneside &&
1130 transop == LST_TRANS_TSBSRVADD)
1133 if (nd->nd_state != LST_NODE_ACTIVE)
1136 if (transop == LST_TRANS_TSBCLIADD) {
1137 hash = batch->bat_cli_hash;
1138 head = &batch->bat_cli_list;
1141 LASSERT (transop == LST_TRANS_TSBSRVADD);
1143 hash = batch->bat_srv_hash;
1144 head = &batch->bat_srv_list;
1147 LASSERT (nd->nd_id.nid != LNET_NID_ANY);
1149 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1152 if (list_empty(&ndl->ndl_link))
1153 list_add_tail(&ndl->ndl_link, head);
1159 lstcon_test_nodes_add(struct lstcon_test *test,
1160 struct list_head __user *result_up)
1162 struct lstcon_rpc_trans *trans;
1163 struct lstcon_group *grp;
1167 LASSERT (test->tes_src_grp != NULL);
1168 LASSERT (test->tes_dst_grp != NULL);
1170 transop = LST_TRANS_TSBSRVADD;
1171 grp = test->tes_dst_grp;
1173 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1174 &test->tes_trans_list, transop,
1175 test, lstcon_testrpc_condition, &trans);
1177 CERROR("Can't create transaction: %d\n", rc);
1181 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1183 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1184 lstcon_trans_stat()->trs_fwk_errno != 0) {
1185 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1187 lstcon_rpc_trans_destroy(trans);
1188 /* return if any error */
1189 CDEBUG(D_NET, "Failed to add test %s, "
1190 "RPC error %d, framework error %d\n",
1191 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1192 lstcon_trans_stat()->trs_rpc_errno,
1193 lstcon_trans_stat()->trs_fwk_errno);
1198 lstcon_rpc_trans_destroy(trans);
1200 if (transop == LST_TRANS_TSBCLIADD)
1203 transop = LST_TRANS_TSBCLIADD;
1204 grp = test->tes_src_grp;
1205 test->tes_cliidx = 0;
1207 /* requests to test clients */
1212 lstcon_verify_batch(const char *name, struct lstcon_batch **batch)
1216 rc = lstcon_batch_find(name, batch);
1218 CDEBUG(D_NET, "Can't find batch %s\n", name);
1222 if ((*batch)->bat_state != LST_BATCH_IDLE) {
1223 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1231 lstcon_verify_group(const char *name, struct lstcon_group **grp)
1234 struct lstcon_ndlink *ndl;
1236 rc = lstcon_group_find(name, grp);
1238 CDEBUG(D_NET, "can't find group %s\n", name);
1242 list_for_each_entry(ndl, &(*grp)->grp_ndl_list, ndl_link) {
1243 if (ndl->ndl_node->nd_state == LST_NODE_ACTIVE) {
1248 CDEBUG(D_NET, "Group %s has no ACTIVE nodes\n", name);
1254 lstcon_test_add(char *batch_name, int type, int loop,
1255 int concur, int dist, int span,
1256 char *src_name, char *dst_name,
1257 void *param, int paramlen, int *retp,
1258 struct list_head __user *result_up)
1260 struct lstcon_test *test = NULL;
1262 struct lstcon_group *src_grp = NULL;
1263 struct lstcon_group *dst_grp = NULL;
1264 struct lstcon_batch *batch = NULL;
1267 * verify that a batch of the given name exists, and the groups
1268 * that will be part of the batch exist and have at least one
1271 rc = lstcon_verify_batch(batch_name, &batch);
1275 rc = lstcon_verify_group(src_name, &src_grp);
1279 rc = lstcon_verify_group(dst_name, &dst_grp);
1283 if (dst_grp->grp_userland)
1286 LIBCFS_ALLOC(test, offsetof(struct lstcon_test, tes_param[paramlen]));
1288 CERROR("Can't allocate test descriptor\n");
1294 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1295 test->tes_batch = batch;
1296 test->tes_type = type;
1297 test->tes_oneside = 0; /* TODO */
1298 test->tes_loop = loop;
1299 test->tes_concur = concur;
1300 test->tes_stop_onerr = 1; /* TODO */
1301 test->tes_span = span;
1302 test->tes_dist = dist;
1303 test->tes_cliidx = 0; /* just used for creating RPC */
1304 test->tes_src_grp = src_grp;
1305 test->tes_dst_grp = dst_grp;
1306 INIT_LIST_HEAD(&test->tes_trans_list);
1308 if (param != NULL) {
1309 test->tes_paramlen = paramlen;
1310 memcpy(&test->tes_param[0], param, paramlen);
1313 rc = lstcon_test_nodes_add(test, result_up);
1318 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1319 lstcon_trans_stat()->trs_fwk_errno != 0)
1320 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type,
1323 /* add to test list anyway, so user can check what's going on */
1324 list_add_tail(&test->tes_link, &batch->bat_test_list);
1327 test->tes_hdr.tsb_index = batch->bat_ntest;
1329 /* hold groups so nobody can change them */
1333 LIBCFS_FREE(test, offsetof(struct lstcon_test,
1334 tes_param[paramlen]));
1336 if (dst_grp != NULL)
1337 lstcon_group_decref(dst_grp);
1339 if (src_grp != NULL)
1340 lstcon_group_decref(src_grp);
1346 lstcon_test_find(struct lstcon_batch *batch, int idx,
1347 struct lstcon_test **testpp)
1349 struct lstcon_test *test;
1351 list_for_each_entry(test, &batch->bat_test_list, tes_link) {
1352 if (idx == test->tes_hdr.tsb_index) {
1362 lstcon_tsbrpc_readent(int transop, struct srpc_msg *msg,
1363 struct lstcon_rpc_ent __user *ent_up)
1365 struct srpc_batch_reply *rep = &msg->msg_body.bat_reply;
1367 LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1368 transop == LST_TRANS_TSBSRVQRY);
1370 /* positive errno, framework error code */
1371 if (copy_to_user(&ent_up->rpe_priv[0],
1372 &rep->bar_active, sizeof(rep->bar_active)))
1379 lstcon_test_batch_query(char *name, int testidx, int client,
1380 int timeout, struct list_head __user *result_up)
1382 struct lstcon_rpc_trans *trans;
1383 struct list_head *translist;
1384 struct list_head *ndlist;
1385 struct lstcon_tsb_hdr *hdr;
1386 struct lstcon_batch *batch;
1387 struct lstcon_test *test = NULL;
1391 rc = lstcon_batch_find(name, &batch);
1393 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1398 translist = &batch->bat_trans_list;
1399 ndlist = &batch->bat_cli_list;
1400 hdr = &batch->bat_hdr;
1403 /* query specified test only */
1404 rc = lstcon_test_find(batch, testidx, &test);
1406 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1410 translist = &test->tes_trans_list;
1411 ndlist = &test->tes_src_grp->grp_ndl_list;
1412 hdr = &test->tes_hdr;
1415 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1417 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1418 lstcon_batrpc_condition, &trans);
1420 CERROR("Can't create transaction: %d\n", rc);
1424 lstcon_rpc_trans_postwait(trans, timeout);
1426 if (testidx == 0 && /* query a batch, not a test */
1427 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1428 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1429 /* all RPCs finished, and no active test */
1430 batch->bat_state = LST_BATCH_IDLE;
1433 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1434 lstcon_tsbrpc_readent);
1435 lstcon_rpc_trans_destroy(trans);
1441 lstcon_statrpc_readent(int transop, struct srpc_msg *msg,
1442 struct lstcon_rpc_ent __user *ent_up)
1444 struct srpc_stat_reply *rep = &msg->msg_body.stat_reply;
1445 struct sfw_counters __user *sfwk_stat;
1446 struct srpc_counters __user *srpc_stat;
1447 struct lnet_counters_common __user *lnet_stat;
1449 if (rep->str_status != 0)
1452 sfwk_stat = (struct sfw_counters __user *)&ent_up->rpe_payload[0];
1453 srpc_stat = (struct srpc_counters __user *)
1454 ((char __user *)sfwk_stat + sizeof(*sfwk_stat));
1455 lnet_stat = (struct lnet_counters_common __user *)
1456 ((char __user *)srpc_stat + sizeof(*srpc_stat));
1458 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1459 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1460 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1467 lstcon_ndlist_stat(struct list_head *ndlist,
1468 int timeout, struct list_head __user *result_up)
1471 struct lstcon_rpc_trans *trans;
1474 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1475 LST_TRANS_STATQRY, NULL, NULL, &trans);
1477 CERROR("Can't create transaction: %d\n", rc);
1481 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1483 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1484 lstcon_statrpc_readent);
1485 lstcon_rpc_trans_destroy(trans);
1491 lstcon_group_stat(char *grp_name, int timeout,
1492 struct list_head __user *result_up)
1494 struct lstcon_group *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_decref(grp);
1511 lstcon_nodes_stat(int count, struct lnet_process_id __user *ids_up,
1512 int timeout, struct list_head __user *result_up)
1514 struct lstcon_ndlink *ndl;
1515 struct lstcon_group *tmp;
1516 struct lnet_process_id id;
1520 rc = lstcon_group_alloc(NULL, &tmp);
1522 CERROR("Out of memory\n");
1526 for (i = 0 ; i < count; i++) {
1527 if (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_decref(tmp);
1547 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1549 lstcon_group_decref(tmp);
1555 lstcon_debug_ndlist(struct list_head *ndlist,
1556 struct list_head *translist,
1557 int timeout, struct list_head __user *result_up)
1559 struct lstcon_rpc_trans *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, struct list_head __user *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, struct list_head __user *result_up)
1589 struct lstcon_batch *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 struct list_head __user *result_up)
1607 struct lstcon_group *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_decref(grp);
1622 lstcon_nodes_debug(int timeout, int count,
1623 struct lnet_process_id __user *ids_up,
1624 struct list_head __user *result_up)
1626 struct lnet_process_id id;
1627 struct lstcon_ndlink *ndl;
1628 struct lstcon_group *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 (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_decref(grp);
1657 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1658 timeout, result_up);
1660 lstcon_group_decref(grp);
1666 lstcon_session_match(struct lst_sid id)
1668 struct lst_session_id sid;
1670 sid.ses_stamp = id.ses_stamp;
1671 lnet_nid4_to_nid(id.ses_nid, &sid.ses_nid);
1673 return (nid_same(&console_session.ses_id.ses_nid, &sid.ses_nid) &&
1674 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1 : 0;
1678 lstcon_new_session_id(struct lst_session_id *sid)
1680 struct lnet_processid id;
1682 LASSERT(console_session.ses_state == LST_SESSION_NONE);
1685 sid->ses_nid = id.nid;
1686 sid->ses_stamp = div_u64(ktime_get_ns(), NSEC_PER_MSEC);
1690 lstcon_session_new(char *name, int key, unsigned feats,
1691 int timeout, int force)
1696 if (console_session.ses_state != LST_SESSION_NONE) {
1697 /* session exists */
1699 CNETERR("Session %s already exists\n",
1700 console_session.ses_name);
1704 rc = lstcon_session_end();
1706 /* lstcon_session_end() only return local error */
1711 if ((feats & ~LST_FEATS_MASK) != 0) {
1712 CNETERR("Unknown session features %x\n",
1713 (feats & ~LST_FEATS_MASK));
1717 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1718 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
1720 lstcon_new_session_id(&console_session.ses_id);
1722 console_session.ses_key = key;
1723 console_session.ses_force = !!force;
1724 console_session.ses_features = feats;
1725 console_session.ses_feats_updated = 0;
1726 console_session.ses_timeout = (timeout <= 0) ?
1727 LST_CONSOLE_TIMEOUT : timeout;
1729 if (strlen(name) > sizeof(console_session.ses_name)-1)
1731 strlcpy(console_session.ses_name, name,
1732 sizeof(console_session.ses_name));
1734 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1738 rc = lstcon_rpc_pinger_start();
1740 struct lstcon_batch *bat = NULL;
1742 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1743 lstcon_batch_destroy(bat);
1748 console_session.ses_state = LST_SESSION_ACTIVE;
1753 int lstcon_session_end(void)
1755 struct lstcon_rpc_trans *trans;
1756 struct lstcon_group *grp;
1757 struct lstcon_batch *bat;
1760 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1762 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1763 NULL, LST_TRANS_SESEND, NULL,
1764 lstcon_sesrpc_condition, &trans);
1766 CERROR("Can't create transaction: %d\n", rc);
1770 console_session.ses_shutdown = 1;
1772 lstcon_rpc_pinger_stop();
1774 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1776 lstcon_rpc_trans_destroy(trans);
1777 /* User can do nothing even rpc failed, so go on */
1779 /* waiting for orphan rpcs to die */
1780 lstcon_rpc_cleanup_wait();
1782 console_session.ses_id = LST_INVALID_SID;
1783 console_session.ses_state = LST_SESSION_NONE;
1784 console_session.ses_key = 0;
1785 console_session.ses_force = 0;
1786 console_session.ses_feats_updated = 0;
1788 /* destroy all batches */
1789 while (!list_empty(&console_session.ses_bat_list)) {
1790 bat = list_first_entry(&console_session.ses_bat_list,
1791 struct lstcon_batch, bat_link);
1793 lstcon_batch_destroy(bat);
1796 /* destroy all groups */
1797 while (!list_empty(&console_session.ses_grp_list)) {
1798 grp = list_first_entry(&console_session.ses_grp_list,
1799 struct lstcon_group, grp_link);
1800 LASSERT(grp->grp_ref == 1);
1802 lstcon_group_decref(grp);
1805 /* all nodes should be released */
1806 LASSERT(list_empty(&console_session.ses_ndl_list));
1808 console_session.ses_shutdown = 0;
1809 console_session.ses_expired = 0;
1815 lstcon_session_feats_check(unsigned feats)
1819 if ((feats & ~LST_FEATS_MASK) != 0) {
1820 CERROR("Can't support these features: %x\n",
1821 (feats & ~LST_FEATS_MASK));
1825 spin_lock(&console_session.ses_rpc_lock);
1827 if (!console_session.ses_feats_updated) {
1828 console_session.ses_feats_updated = 1;
1829 console_session.ses_features = feats;
1832 if (console_session.ses_features != feats)
1835 spin_unlock(&console_session.ses_rpc_lock);
1838 CERROR("remote features %x do not match with "
1839 "session features %x of console\n",
1840 feats, console_session.ses_features);
1847 lstcon_acceptor_handle(struct srpc_server_rpc *rpc)
1849 struct srpc_msg *rep = &rpc->srpc_replymsg;
1850 struct srpc_msg *req = &rpc->srpc_reqstbuf->buf_msg;
1851 struct srpc_join_reqst *jreq = &req->msg_body.join_reqst;
1852 struct srpc_join_reply *jrep = &rep->msg_body.join_reply;
1853 struct lstcon_group *grp = NULL;
1854 struct lstcon_ndlink *ndl;
1857 sfw_unpack_message(req);
1859 mutex_lock(&console_session.ses_mutex);
1861 jrep->join_sid.ses_stamp = console_session.ses_id.ses_stamp;
1862 jrep->join_sid.ses_nid = lnet_nid_to_nid4(&console_session.ses_id.ses_nid);
1864 if (LNET_NID_IS_ANY(&console_session.ses_id.ses_nid)) {
1865 jrep->join_status = ESRCH;
1869 if (lstcon_session_feats_check(req->msg_ses_feats) != 0) {
1870 jrep->join_status = EPROTO;
1874 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1875 !lstcon_session_match(jreq->join_sid)) {
1876 jrep->join_status = EBUSY;
1880 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1881 rc = lstcon_group_alloc(jreq->join_group, &grp);
1883 CERROR("Out of memory\n");
1887 list_add_tail(&grp->grp_link,
1888 &console_session.ses_grp_list);
1889 lstcon_group_addref(grp);
1892 if (grp->grp_ref > 2) {
1893 /* Group in using */
1894 jrep->join_status = EBUSY;
1898 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1900 jrep->join_status = EEXIST;
1904 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1906 CERROR("Out of memory\n");
1910 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1911 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1913 if (grp->grp_userland == 0)
1914 grp->grp_userland = 1;
1916 strlcpy(jrep->join_session, console_session.ses_name,
1917 sizeof(jrep->join_session));
1918 jrep->join_timeout = console_session.ses_timeout;
1919 jrep->join_status = 0;
1922 rep->msg_ses_feats = console_session.ses_features;
1924 lstcon_group_decref(grp);
1926 mutex_unlock(&console_session.ses_mutex);
1931 static struct srpc_service lstcon_acceptor_service;
1933 static void lstcon_init_acceptor_service(void)
1935 /* initialize selftest console acceptor service table */
1936 lstcon_acceptor_service.sv_name = "join session";
1937 lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
1938 lstcon_acceptor_service.sv_id = SRPC_SERVICE_JOIN;
1939 lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX;
1942 static struct notifier_block lstcon_ioctl_handler = {
1943 .notifier_call = lstcon_ioctl_entry,
1946 /* initialize console */
1948 lstcon_console_init(void)
1953 console_session.ses_id = LST_INVALID_SID;
1954 console_session.ses_state = LST_SESSION_NONE;
1955 console_session.ses_timeout = 0;
1956 console_session.ses_force = 0;
1957 console_session.ses_expired = 0;
1958 console_session.ses_feats_updated = 0;
1959 console_session.ses_features = LST_FEATS_MASK;
1960 console_session.ses_laststamp = ktime_get_real_seconds();
1962 mutex_init(&console_session.ses_mutex);
1964 INIT_LIST_HEAD(&console_session.ses_ndl_list);
1965 INIT_LIST_HEAD(&console_session.ses_grp_list);
1966 INIT_LIST_HEAD(&console_session.ses_bat_list);
1967 INIT_LIST_HEAD(&console_session.ses_trans_list);
1969 CFS_ALLOC_PTR_ARRAY(console_session.ses_ndl_hash,
1970 LST_GLOBAL_HASHSIZE);
1971 if (console_session.ses_ndl_hash == NULL)
1974 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1975 INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
1978 /* initialize acceptor service table */
1979 lstcon_init_acceptor_service();
1981 rc = srpc_add_service(&lstcon_acceptor_service);
1982 LASSERT(rc != -EBUSY);
1984 CFS_FREE_PTR_ARRAY(console_session.ses_ndl_hash,
1985 LST_GLOBAL_HASHSIZE);
1989 rc = srpc_service_add_buffers(&lstcon_acceptor_service,
1990 lstcon_acceptor_service.sv_wi_total);
1996 rc = lstcon_init_netlink();
2000 rc = blocking_notifier_chain_register(&libcfs_ioctl_list,
2001 &lstcon_ioctl_handler);
2003 lstcon_fini_netlink();
2007 lstcon_rpc_module_init();
2011 srpc_shutdown_service(&lstcon_acceptor_service);
2012 srpc_remove_service(&lstcon_acceptor_service);
2014 CFS_FREE_PTR_ARRAY(console_session.ses_ndl_hash, LST_GLOBAL_HASHSIZE);
2016 srpc_wait_service_shutdown(&lstcon_acceptor_service);
2022 lstcon_console_fini(void)
2026 blocking_notifier_chain_unregister(&libcfs_ioctl_list,
2027 &lstcon_ioctl_handler);
2028 lstcon_fini_netlink();
2030 mutex_lock(&console_session.ses_mutex);
2032 srpc_shutdown_service(&lstcon_acceptor_service);
2033 srpc_remove_service(&lstcon_acceptor_service);
2035 if (console_session.ses_state != LST_SESSION_NONE)
2036 lstcon_session_end();
2038 lstcon_rpc_module_fini();
2040 mutex_unlock(&console_session.ses_mutex);
2042 LASSERT(list_empty(&console_session.ses_ndl_list));
2043 LASSERT(list_empty(&console_session.ses_grp_list));
2044 LASSERT(list_empty(&console_session.ses_bat_list));
2045 LASSERT(list_empty(&console_session.ses_trans_list));
2047 for (i = 0; i < LST_NODE_HASHSIZE; i++)
2048 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
2050 CFS_FREE_PTR_ARRAY(console_session.ses_ndl_hash,
2051 LST_GLOBAL_HASHSIZE);
2053 srpc_wait_service_shutdown(&lstcon_acceptor_service);