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 lstcon_session_t console_session;
64 lstcon_node_get(lstcon_node_t *nd)
66 LASSERT(nd->nd_ref >= 1);
72 lstcon_node_find(lnet_process_id_t id, lstcon_node_t **ndpp, int create)
75 unsigned int idx = LNET_NIDADDR(id.nid) % LST_GLOBAL_HASHSIZE;
77 LASSERT(id.nid != LNET_NID_ANY);
79 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));
107 /* queued in global hash & list, no refcount is taken by
108 * global hash & list, if caller release his refcount,
109 * node will be released */
110 list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
111 list_add_tail(&ndl->ndl_link, &console_session.ses_ndl_list);
117 lstcon_node_put(lstcon_node_t *nd)
119 lstcon_ndlink_t *ndl;
121 LASSERT(nd->nd_ref > 0);
123 if (--nd->nd_ref > 0)
126 ndl = (lstcon_ndlink_t *)(nd + 1);
128 LASSERT(!list_empty(&ndl->ndl_link));
129 LASSERT(!list_empty(&ndl->ndl_hlink));
131 /* remove from session */
132 list_del(&ndl->ndl_link);
133 list_del(&ndl->ndl_hlink);
135 LIBCFS_FREE(nd, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
139 lstcon_ndlink_find(struct list_head *hash,
140 lnet_process_id_t id, lstcon_ndlink_t **ndlpp, int create)
142 unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
143 lstcon_ndlink_t *ndl;
147 if (id.nid == LNET_NID_ANY)
151 list_for_each_entry(ndl, &hash[idx], ndl_hlink) {
152 if (ndl->ndl_node->nd_id.nid != id.nid ||
153 ndl->ndl_node->nd_id.pid != id.pid)
163 /* find or create in session hash */
164 rc = lstcon_node_find(id, &nd, (create == 1) ? 1 : 0);
168 LIBCFS_ALLOC(ndl, sizeof(lstcon_ndlink_t));
177 INIT_LIST_HEAD(&ndl->ndl_link);
178 list_add_tail(&ndl->ndl_hlink, &hash[idx]);
184 lstcon_ndlink_release(lstcon_ndlink_t *ndl)
186 LASSERT(list_empty(&ndl->ndl_link));
187 LASSERT(!list_empty(&ndl->ndl_hlink));
189 list_del(&ndl->ndl_hlink); /* delete from hash */
190 lstcon_node_put(ndl->ndl_node);
192 LIBCFS_FREE(ndl, sizeof(*ndl));
196 lstcon_group_alloc(char *name, lstcon_group_t **grpp)
201 LIBCFS_ALLOC(grp, offsetof(lstcon_group_t,
202 grp_ndl_hash[LST_NODE_HASHSIZE]));
208 strcpy(grp->grp_name, name);
210 INIT_LIST_HEAD(&grp->grp_link);
211 INIT_LIST_HEAD(&grp->grp_ndl_list);
212 INIT_LIST_HEAD(&grp->grp_trans_list);
214 for (i = 0; i < LST_NODE_HASHSIZE; i++)
215 INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
223 lstcon_group_addref(lstcon_group_t *grp)
228 static void lstcon_group_ndlink_release(lstcon_group_t *, lstcon_ndlink_t *);
231 lstcon_group_drain(lstcon_group_t *grp, int keep)
233 lstcon_ndlink_t *ndl;
234 lstcon_ndlink_t *tmp;
236 list_for_each_entry_safe(ndl, tmp, &grp->grp_ndl_list, ndl_link) {
237 if ((ndl->ndl_node->nd_state & keep) == 0)
238 lstcon_group_ndlink_release(grp, ndl);
243 lstcon_group_decref(lstcon_group_t *grp)
247 if (--grp->grp_ref > 0)
250 if (!list_empty(&grp->grp_link))
251 list_del(&grp->grp_link);
253 lstcon_group_drain(grp, 0);
255 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
256 LASSERT(list_empty(&grp->grp_ndl_hash[i]));
259 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
260 grp_ndl_hash[LST_NODE_HASHSIZE]));
264 lstcon_group_find(const char *name, lstcon_group_t **grpp)
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(lstcon_group_t *grp, lnet_process_id_t id,
282 lstcon_ndlink_t **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(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
302 list_del_init(&ndl->ndl_link);
303 lstcon_ndlink_release(ndl);
308 lstcon_group_ndlink_move(lstcon_group_t *old,
309 lstcon_group_t *new, lstcon_ndlink_t *ndl)
311 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
314 list_del(&ndl->ndl_hlink);
315 list_del(&ndl->ndl_link);
318 list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
319 list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
324 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
326 lstcon_ndlink_t *ndl;
328 while (!list_empty(&old->grp_ndl_list)) {
329 ndl = list_entry(old->grp_ndl_list.next,
330 lstcon_ndlink_t, ndl_link);
331 lstcon_group_ndlink_move(old, new, ndl);
336 lstcon_sesrpc_condition(int transop, lstcon_node_t *nd, void *arg)
338 lstcon_group_t *grp = (lstcon_group_t *)arg;
341 case LST_TRANS_SESNEW:
342 if (nd->nd_state == LST_NODE_ACTIVE)
346 case LST_TRANS_SESEND:
347 if (nd->nd_state != LST_NODE_ACTIVE)
350 if (grp != NULL && nd->nd_ref > 1)
354 case LST_TRANS_SESQRY:
365 lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
366 lstcon_rpc_ent_t *ent_up)
368 srpc_debug_reply_t *rep;
371 case LST_TRANS_SESNEW:
372 case LST_TRANS_SESEND:
375 case LST_TRANS_SESQRY:
376 rep = &msg->msg_body.dbg_reply;
378 if (copy_to_user(&ent_up->rpe_priv[0],
379 &rep->dbg_timeout, sizeof(int)) ||
380 copy_to_user(&ent_up->rpe_payload[0],
381 &rep->dbg_name, LST_NAME_SIZE))
394 lstcon_group_nodes_add(lstcon_group_t *grp,
395 int count, lnet_process_id_t *ids_up,
396 unsigned *featp, struct list_head *result_up)
398 lstcon_rpc_trans_t *trans;
399 lstcon_ndlink_t *ndl;
401 lnet_process_id_t id;
405 rc = lstcon_group_alloc(NULL, &tmp);
407 CERROR("Out of memory\n");
411 for (i = 0 ; i < count; i++) {
412 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
417 /* skip if it's in this group already */
418 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
422 /* add to tmp group */
423 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
425 CERROR("Can't create ndlink, out of memory\n");
431 lstcon_group_decref(tmp);
435 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
436 &tmp->grp_trans_list, LST_TRANS_SESNEW,
437 tmp, lstcon_sesrpc_condition, &trans);
439 CERROR("Can't create transaction: %d\n", rc);
440 lstcon_group_decref(tmp);
445 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
447 rc = lstcon_rpc_trans_interpreter(trans, result_up,
448 lstcon_sesrpc_readent);
449 *featp = trans->tas_features;
451 /* destroy all RPGs */
452 lstcon_rpc_trans_destroy(trans);
454 lstcon_group_move(tmp, grp);
455 lstcon_group_decref(tmp);
461 lstcon_group_nodes_remove(lstcon_group_t *grp,
462 int count, lnet_process_id_t *ids_up,
463 struct list_head *result_up)
465 lstcon_rpc_trans_t *trans;
466 lstcon_ndlink_t *ndl;
468 lnet_process_id_t id;
472 /* End session and remove node from the group */
474 rc = lstcon_group_alloc(NULL, &tmp);
476 CERROR("Out of memory\n");
480 for (i = 0; i < count; i++) {
481 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
486 /* move node to tmp group */
487 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
488 lstcon_group_ndlink_move(grp, tmp, ndl);
491 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
492 &tmp->grp_trans_list, LST_TRANS_SESEND,
493 tmp, lstcon_sesrpc_condition, &trans);
495 CERROR("Can't create transaction: %d\n", rc);
499 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
501 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
503 lstcon_rpc_trans_destroy(trans);
504 /* release nodes anyway, because we can't rollback status */
505 lstcon_group_decref(tmp);
509 lstcon_group_move(tmp, grp);
510 lstcon_group_decref(tmp);
516 lstcon_group_add(char *name)
521 rc = (lstcon_group_find(name, &grp) == 0) ? -EEXIST : 0;
523 /* find a group with same name */
524 lstcon_group_decref(grp);
528 rc = lstcon_group_alloc(name, &grp);
530 CERROR("Can't allocate descriptor for group %s\n", name);
534 list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
540 lstcon_nodes_add(char *name, int count, lnet_process_id_t *ids_up,
541 unsigned *featp, struct list_head *result_up)
547 LASSERT(ids_up != NULL);
549 rc = lstcon_group_find(name, &grp);
551 CDEBUG(D_NET, "Can't find group %s\n", name);
555 if (grp->grp_ref > 2) {
556 /* referred by other threads or test */
557 CDEBUG(D_NET, "Group %s is busy\n", name);
558 lstcon_group_decref(grp);
563 rc = lstcon_group_nodes_add(grp, count, ids_up, featp, result_up);
565 lstcon_group_decref(grp);
571 lstcon_group_del(char *name)
573 lstcon_rpc_trans_t *trans;
577 rc = lstcon_group_find(name, &grp);
579 CDEBUG(D_NET, "Can't find group: %s\n", name);
583 if (grp->grp_ref > 2) {
584 /* referred by others threads or test */
585 CDEBUG(D_NET, "Group %s is busy\n", name);
586 lstcon_group_decref(grp);
590 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
591 &grp->grp_trans_list, LST_TRANS_SESEND,
592 grp, lstcon_sesrpc_condition, &trans);
594 CERROR("Can't create transaction: %d\n", rc);
595 lstcon_group_decref(grp);
599 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
601 lstcon_rpc_trans_destroy(trans);
603 lstcon_group_decref(grp);
604 /* -ref for session, it's destroyed,
605 * status can't be rolled back, destroy group anyway */
606 lstcon_group_decref(grp);
612 lstcon_group_clean(char *name, int args)
614 lstcon_group_t *grp = NULL;
617 rc = lstcon_group_find(name, &grp);
619 CDEBUG(D_NET, "Can't find group %s\n", name);
623 if (grp->grp_ref > 2) {
624 /* referred by test */
625 CDEBUG(D_NET, "Group %s is busy\n", name);
626 lstcon_group_decref(grp);
630 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
631 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
633 lstcon_group_drain(grp, args);
635 lstcon_group_decref(grp);
636 /* release empty group */
637 if (list_empty(&grp->grp_ndl_list))
638 lstcon_group_decref(grp);
644 lstcon_nodes_remove(char *name, int count,
645 lnet_process_id_t *ids_up, struct list_head *result_up)
647 lstcon_group_t *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 *result_up)
676 lstcon_rpc_trans_t *trans;
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_group_list(int index, int len, char *name_up)
721 LASSERT(name_up != NULL);
723 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
725 return copy_to_user(name_up, grp->grp_name, len) ?
734 lstcon_nodes_getent(struct list_head *head, int *index_p,
735 int *count_p, lstcon_node_ent_t *dents_up)
737 lstcon_ndlink_t *ndl;
742 LASSERT(index_p != NULL && count_p != NULL);
743 LASSERT(dents_up != NULL);
744 LASSERT(*index_p >= 0);
745 LASSERT(*count_p > 0);
747 list_for_each_entry(ndl, head, ndl_link) {
748 if (index++ < *index_p)
751 if (count >= *count_p)
755 if (copy_to_user(&dents_up[count].nde_id,
756 &nd->nd_id, sizeof(nd->nd_id)) ||
757 copy_to_user(&dents_up[count].nde_state,
758 &nd->nd_state, sizeof(nd->nd_state)))
764 if (index <= *index_p)
774 lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p,
775 int *index_p, int *count_p, lstcon_node_ent_t *dents_up)
777 lstcon_ndlist_ent_t *gentp;
779 lstcon_ndlink_t *ndl;
782 rc = lstcon_group_find(name, &grp);
784 CDEBUG(D_NET, "Can't find group %s\n", name);
790 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
791 index_p, count_p, dents_up);
792 lstcon_group_decref(grp);
797 /* non-verbose query */
798 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
800 CERROR("Can't allocate ndlist_ent\n");
801 lstcon_group_decref(grp);
806 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link)
807 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
809 rc = copy_to_user(gents_p, gentp,
810 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT : 0;
812 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
814 lstcon_group_decref(grp);
820 lstcon_batch_find(const char *name, lstcon_batch_t **batpp)
824 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
825 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
835 lstcon_batch_add(char *name)
841 rc = (lstcon_batch_find(name, &bat) == 0) ? -EEXIST : 0;
843 CDEBUG(D_NET, "Batch %s already exists\n", name);
847 LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
849 CERROR("Can't allocate descriptor for batch %s\n", name);
853 LIBCFS_ALLOC(bat->bat_cli_hash,
854 sizeof(struct list_head) * LST_NODE_HASHSIZE);
855 if (bat->bat_cli_hash == NULL) {
856 CERROR("Can't allocate hash for batch %s\n", name);
857 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
862 LIBCFS_ALLOC(bat->bat_srv_hash,
863 sizeof(struct list_head) * LST_NODE_HASHSIZE);
864 if (bat->bat_srv_hash == NULL) {
865 CERROR("Can't allocate hash for batch %s\n", name);
866 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
867 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
872 strcpy(bat->bat_name, name);
873 bat->bat_hdr.tsb_index = 0;
874 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
877 bat->bat_state = LST_BATCH_IDLE;
879 INIT_LIST_HEAD(&bat->bat_cli_list);
880 INIT_LIST_HEAD(&bat->bat_srv_list);
881 INIT_LIST_HEAD(&bat->bat_test_list);
882 INIT_LIST_HEAD(&bat->bat_trans_list);
884 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
885 INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
886 INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
889 list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
895 lstcon_batch_list(int index, int len, char *name_up)
899 LASSERT(name_up != NULL);
902 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
904 return copy_to_user(name_up, bat->bat_name, len) ?
913 lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
914 int testidx, int *index_p, int *ndent_p,
915 lstcon_node_ent_t *dents_up)
917 lstcon_test_batch_ent_t *entp;
918 struct list_head *clilst;
919 struct list_head *srvlst;
920 lstcon_test_t *test = NULL;
922 lstcon_ndlink_t *ndl;
925 rc = lstcon_batch_find(name, &bat);
927 CDEBUG(D_NET, "Can't find batch %s\n", name);
932 /* query test, test index start from 1 */
933 list_for_each_entry(test, &bat->bat_test_list, tes_link) {
939 CDEBUG(D_NET, "Can't find specified test in batch\n");
944 clilst = (test == NULL) ? &bat->bat_cli_list :
945 &test->tes_src_grp->grp_ndl_list;
946 srvlst = (test == NULL) ? &bat->bat_srv_list :
947 &test->tes_dst_grp->grp_ndl_list;
949 if (dents_up != NULL) {
950 rc = lstcon_nodes_getent((server ? srvlst : clilst),
951 index_p, ndent_p, dents_up);
955 /* non-verbose query */
956 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
961 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
962 entp->u.tbe_batch.bae_state = bat->bat_state;
966 entp->u.tbe_test.tse_type = test->tes_type;
967 entp->u.tbe_test.tse_loop = test->tes_loop;
968 entp->u.tbe_test.tse_concur = test->tes_concur;
971 list_for_each_entry(ndl, clilst, ndl_link)
972 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
974 list_for_each_entry(ndl, srvlst, ndl_link)
975 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
977 rc = copy_to_user(ent_up, entp,
978 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
980 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
986 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
989 case LST_TRANS_TSBRUN:
990 if (nd->nd_state != LST_NODE_ACTIVE)
994 case LST_TRANS_TSBSTOP:
995 if (nd->nd_state != LST_NODE_ACTIVE)
999 case LST_TRANS_TSBCLIQRY:
1000 case LST_TRANS_TSBSRVQRY:
1008 lstcon_batch_op(lstcon_batch_t *bat, int transop,
1009 struct list_head *result_up)
1011 lstcon_rpc_trans_t *trans;
1014 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1015 &bat->bat_trans_list, transop,
1016 bat, lstcon_batrpc_condition, &trans);
1018 CERROR("Can't create transaction: %d\n", rc);
1022 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1024 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1026 lstcon_rpc_trans_destroy(trans);
1032 lstcon_batch_run(char *name, int timeout, struct list_head *result_up)
1034 lstcon_batch_t *bat;
1037 if (lstcon_batch_find(name, &bat) != 0) {
1038 CDEBUG(D_NET, "Can't find batch %s\n", name);
1042 bat->bat_arg = timeout;
1044 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1046 /* mark batch as running if it's started in any node */
1047 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1048 bat->bat_state = LST_BATCH_RUNNING;
1054 lstcon_batch_stop(char *name, int force, struct list_head *result_up)
1056 lstcon_batch_t *bat;
1059 if (lstcon_batch_find(name, &bat) != 0) {
1060 CDEBUG(D_NET, "Can't find batch %s\n", name);
1064 bat->bat_arg = force;
1066 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1068 /* mark batch as stopped if all RPCs finished */
1069 if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1070 bat->bat_state = LST_BATCH_IDLE;
1076 lstcon_batch_destroy(lstcon_batch_t *bat)
1078 lstcon_ndlink_t *ndl;
1079 lstcon_test_t *test;
1082 list_del(&bat->bat_link);
1084 while (!list_empty(&bat->bat_test_list)) {
1085 test = list_entry(bat->bat_test_list.next,
1086 lstcon_test_t, tes_link);
1087 LASSERT(list_empty(&test->tes_trans_list));
1089 list_del(&test->tes_link);
1091 lstcon_group_decref(test->tes_src_grp);
1092 lstcon_group_decref(test->tes_dst_grp);
1094 LIBCFS_FREE(test, offsetof(lstcon_test_t,
1095 tes_param[test->tes_paramlen]));
1098 LASSERT(list_empty(&bat->bat_trans_list));
1100 while (!list_empty(&bat->bat_cli_list)) {
1101 ndl = list_entry(bat->bat_cli_list.next,
1102 lstcon_ndlink_t, ndl_link);
1103 list_del_init(&ndl->ndl_link);
1105 lstcon_ndlink_release(ndl);
1108 while (!list_empty(&bat->bat_srv_list)) {
1109 ndl = list_entry(bat->bat_srv_list.next,
1110 lstcon_ndlink_t, ndl_link);
1111 list_del_init(&ndl->ndl_link);
1113 lstcon_ndlink_release(ndl);
1116 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1117 LASSERT(list_empty(&bat->bat_cli_hash[i]));
1118 LASSERT(list_empty(&bat->bat_srv_hash[i]));
1121 LIBCFS_FREE(bat->bat_cli_hash,
1122 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1123 LIBCFS_FREE(bat->bat_srv_hash,
1124 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1125 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
1129 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1131 lstcon_test_t *test;
1132 lstcon_batch_t *batch;
1133 lstcon_ndlink_t *ndl;
1134 struct list_head *hash;
1135 struct list_head *head;
1137 test = (lstcon_test_t *)arg;
1138 LASSERT(test != NULL);
1140 batch = test->tes_batch;
1141 LASSERT(batch != NULL);
1143 if (test->tes_oneside &&
1144 transop == LST_TRANS_TSBSRVADD)
1147 if (nd->nd_state != LST_NODE_ACTIVE)
1150 if (transop == LST_TRANS_TSBCLIADD) {
1151 hash = batch->bat_cli_hash;
1152 head = &batch->bat_cli_list;
1155 LASSERT(transop == LST_TRANS_TSBSRVADD);
1157 hash = batch->bat_srv_hash;
1158 head = &batch->bat_srv_list;
1161 LASSERT(nd->nd_id.nid != LNET_NID_ANY);
1163 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1166 if (list_empty(&ndl->ndl_link))
1167 list_add_tail(&ndl->ndl_link, head);
1173 lstcon_test_nodes_add(lstcon_test_t *test, struct list_head *result_up)
1175 lstcon_rpc_trans_t *trans;
1176 lstcon_group_t *grp;
1180 LASSERT(test->tes_src_grp != NULL);
1181 LASSERT(test->tes_dst_grp != NULL);
1183 transop = LST_TRANS_TSBSRVADD;
1184 grp = test->tes_dst_grp;
1186 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1187 &test->tes_trans_list, transop,
1188 test, lstcon_testrpc_condition, &trans);
1190 CERROR("Can't create transaction: %d\n", rc);
1194 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1196 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1197 lstcon_trans_stat()->trs_fwk_errno != 0) {
1198 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1200 lstcon_rpc_trans_destroy(trans);
1201 /* return if any error */
1202 CDEBUG(D_NET, "Failed to add test %s, RPC error %d, framework error %d\n",
1203 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1204 lstcon_trans_stat()->trs_rpc_errno,
1205 lstcon_trans_stat()->trs_fwk_errno);
1210 lstcon_rpc_trans_destroy(trans);
1212 if (transop == LST_TRANS_TSBCLIADD)
1215 transop = LST_TRANS_TSBCLIADD;
1216 grp = test->tes_src_grp;
1217 test->tes_cliidx = 0;
1219 /* requests to test clients */
1224 lstcon_verify_batch(const char *name, lstcon_batch_t **batch)
1228 rc = lstcon_batch_find(name, batch);
1230 CDEBUG(D_NET, "Can't find batch %s\n", name);
1234 if ((*batch)->bat_state != LST_BATCH_IDLE) {
1235 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1243 lstcon_verify_group(const char *name, lstcon_group_t **grp)
1246 lstcon_ndlink_t *ndl;
1248 rc = lstcon_group_find(name, grp);
1250 CDEBUG(D_NET, "can't find group %s\n", name);
1254 list_for_each_entry(ndl, &(*grp)->grp_ndl_list, ndl_link) {
1255 if (ndl->ndl_node->nd_state == LST_NODE_ACTIVE)
1259 CDEBUG(D_NET, "Group %s has no ACTIVE nodes\n", name);
1265 lstcon_test_add(char *batch_name, int type, int loop,
1266 int concur, int dist, int span,
1267 char *src_name, char *dst_name,
1268 void *param, int paramlen, int *retp,
1269 struct list_head *result_up)
1271 lstcon_test_t *test = NULL;
1273 lstcon_group_t *src_grp = NULL;
1274 lstcon_group_t *dst_grp = NULL;
1275 lstcon_batch_t *batch = NULL;
1278 * verify that a batch of the given name exists, and the groups
1279 * that will be part of the batch exist and have at least one
1282 rc = lstcon_verify_batch(batch_name, &batch);
1286 rc = lstcon_verify_group(src_name, &src_grp);
1290 rc = lstcon_verify_group(dst_name, &dst_grp);
1294 if (dst_grp->grp_userland)
1297 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1299 CERROR("Can't allocate test descriptor\n");
1305 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1306 test->tes_batch = batch;
1307 test->tes_type = type;
1308 test->tes_oneside = 0; /* TODO */
1309 test->tes_loop = loop;
1310 test->tes_concur = concur;
1311 test->tes_stop_onerr = 1; /* TODO */
1312 test->tes_span = span;
1313 test->tes_dist = dist;
1314 test->tes_cliidx = 0; /* just used for creating RPC */
1315 test->tes_src_grp = src_grp;
1316 test->tes_dst_grp = dst_grp;
1317 INIT_LIST_HEAD(&test->tes_trans_list);
1319 if (param != NULL) {
1320 test->tes_paramlen = paramlen;
1321 memcpy(&test->tes_param[0], param, paramlen);
1324 rc = lstcon_test_nodes_add(test, result_up);
1329 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1330 lstcon_trans_stat()->trs_fwk_errno != 0)
1331 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type,
1334 /* add to test list anyway, so user can check what's going on */
1335 list_add_tail(&test->tes_link, &batch->bat_test_list);
1338 test->tes_hdr.tsb_index = batch->bat_ntest;
1340 /* hold groups so nobody can change them */
1344 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1346 if (dst_grp != NULL)
1347 lstcon_group_decref(dst_grp);
1349 if (src_grp != NULL)
1350 lstcon_group_decref(src_grp);
1356 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1358 lstcon_test_t *test;
1360 list_for_each_entry(test, &batch->bat_test_list, tes_link) {
1361 if (idx == test->tes_hdr.tsb_index) {
1371 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1372 lstcon_rpc_ent_t *ent_up)
1374 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1376 LASSERT(transop == LST_TRANS_TSBCLIQRY ||
1377 transop == LST_TRANS_TSBSRVQRY);
1379 /* positive errno, framework error code */
1380 if (copy_to_user(&ent_up->rpe_priv[0],
1381 &rep->bar_active, sizeof(rep->bar_active)))
1388 lstcon_test_batch_query(char *name, int testidx, int client,
1389 int timeout, struct list_head *result_up)
1391 lstcon_rpc_trans_t *trans;
1392 struct list_head *translist;
1393 struct list_head *ndlist;
1394 lstcon_tsb_hdr_t *hdr;
1395 lstcon_batch_t *batch;
1396 lstcon_test_t *test = NULL;
1400 rc = lstcon_batch_find(name, &batch);
1402 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1407 translist = &batch->bat_trans_list;
1408 ndlist = &batch->bat_cli_list;
1409 hdr = &batch->bat_hdr;
1412 /* query specified test only */
1413 rc = lstcon_test_find(batch, testidx, &test);
1415 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1419 translist = &test->tes_trans_list;
1420 ndlist = &test->tes_src_grp->grp_ndl_list;
1421 hdr = &test->tes_hdr;
1424 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1426 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1427 lstcon_batrpc_condition, &trans);
1429 CERROR("Can't create transaction: %d\n", rc);
1433 lstcon_rpc_trans_postwait(trans, timeout);
1435 if (testidx == 0 && /* query a batch, not a test */
1436 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1437 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1438 /* all RPCs finished, and no active test */
1439 batch->bat_state = LST_BATCH_IDLE;
1442 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1443 lstcon_tsbrpc_readent);
1444 lstcon_rpc_trans_destroy(trans);
1450 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1451 lstcon_rpc_ent_t *ent_up)
1453 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1454 sfw_counters_t *sfwk_stat;
1455 srpc_counters_t *srpc_stat;
1456 lnet_counters_t *lnet_stat;
1458 if (rep->str_status != 0)
1461 sfwk_stat = (sfw_counters_t *)&ent_up->rpe_payload[0];
1462 srpc_stat = (srpc_counters_t *)((char *)sfwk_stat + sizeof(*sfwk_stat));
1463 lnet_stat = (lnet_counters_t *)((char *)srpc_stat + sizeof(*srpc_stat));
1465 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1466 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1467 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1474 lstcon_ndlist_stat(struct list_head *ndlist,
1475 int timeout, struct list_head *result_up)
1477 struct list_head head;
1478 lstcon_rpc_trans_t *trans;
1481 INIT_LIST_HEAD(&head);
1483 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1484 LST_TRANS_STATQRY, NULL, NULL, &trans);
1486 CERROR("Can't create transaction: %d\n", rc);
1490 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1492 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1493 lstcon_statrpc_readent);
1494 lstcon_rpc_trans_destroy(trans);
1500 lstcon_group_stat(char *grp_name, int timeout, struct list_head *result_up)
1502 lstcon_group_t *grp;
1505 rc = lstcon_group_find(grp_name, &grp);
1507 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1511 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1513 lstcon_group_decref(grp);
1519 lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
1520 int timeout, struct list_head *result_up)
1522 lstcon_ndlink_t *ndl;
1523 lstcon_group_t *tmp;
1524 lnet_process_id_t id;
1528 rc = lstcon_group_alloc(NULL, &tmp);
1530 CERROR("Out of memory\n");
1534 for (i = 0 ; i < count; i++) {
1535 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1540 /* add to tmp group */
1541 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1543 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1544 "Failed to find or create %s: %d\n",
1545 libcfs_id2str(id), rc);
1551 lstcon_group_decref(tmp);
1555 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1557 lstcon_group_decref(tmp);
1563 lstcon_debug_ndlist(struct list_head *ndlist,
1564 struct list_head *translist,
1565 int timeout, struct list_head *result_up)
1567 lstcon_rpc_trans_t *trans;
1570 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1571 NULL, lstcon_sesrpc_condition, &trans);
1573 CERROR("Can't create transaction: %d\n", rc);
1577 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1579 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1580 lstcon_sesrpc_readent);
1581 lstcon_rpc_trans_destroy(trans);
1587 lstcon_session_debug(int timeout, struct list_head *result_up)
1589 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1590 NULL, timeout, result_up);
1594 lstcon_batch_debug(int timeout, char *name,
1595 int client, struct list_head *result_up)
1597 lstcon_batch_t *bat;
1600 rc = lstcon_batch_find(name, &bat);
1604 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1606 NULL, timeout, result_up);
1612 lstcon_group_debug(int timeout, char *name,
1613 struct list_head *result_up)
1615 lstcon_group_t *grp;
1618 rc = lstcon_group_find(name, &grp);
1622 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1623 timeout, result_up);
1624 lstcon_group_decref(grp);
1630 lstcon_nodes_debug(int timeout,
1631 int count, lnet_process_id_t *ids_up,
1632 struct list_head *result_up)
1634 lnet_process_id_t id;
1635 lstcon_ndlink_t *ndl;
1636 lstcon_group_t *grp;
1640 rc = lstcon_group_alloc(NULL, &grp);
1642 CDEBUG(D_NET, "Out of memory\n");
1646 for (i = 0; i < count; i++) {
1647 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1652 /* node is added to tmp group */
1653 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1655 CERROR("Can't create node link\n");
1661 lstcon_group_decref(grp);
1665 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1666 timeout, result_up);
1668 lstcon_group_decref(grp);
1674 lstcon_session_match(lst_sid_t sid)
1676 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1677 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1 : 0;
1681 lstcon_new_session_id(lst_sid_t *sid)
1683 lnet_process_id_t id;
1685 LASSERT(console_session.ses_state == LST_SESSION_NONE);
1688 sid->ses_nid = id.nid;
1689 sid->ses_stamp = cfs_time_current();
1692 extern srpc_service_t lstcon_acceptor_service;
1695 lstcon_session_new(char *name, int key, unsigned feats,
1696 int timeout, int force, lst_sid_t *sid_up)
1701 if (console_session.ses_state != LST_SESSION_NONE) {
1702 /* session exists */
1704 CNETERR("Session %s already exists\n",
1705 console_session.ses_name);
1709 rc = lstcon_session_end();
1711 /* lstcon_session_end() only return local error */
1716 if ((feats & ~LST_FEATS_MASK) != 0) {
1717 CNETERR("Unknown session features %x\n",
1718 (feats & ~LST_FEATS_MASK));
1722 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1723 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
1725 lstcon_new_session_id(&console_session.ses_id);
1727 console_session.ses_key = key;
1728 console_session.ses_state = LST_SESSION_ACTIVE;
1729 console_session.ses_force = !!force;
1730 console_session.ses_features = feats;
1731 console_session.ses_feats_updated = 0;
1732 console_session.ses_timeout = (timeout <= 0) ?
1733 LST_CONSOLE_TIMEOUT : timeout;
1734 strlcpy(console_session.ses_name, name,
1735 sizeof(console_session.ses_name));
1737 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1741 rc = lstcon_rpc_pinger_start();
1743 lstcon_batch_t *bat = NULL;
1745 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1746 lstcon_batch_destroy(bat);
1751 if (copy_to_user(sid_up, &console_session.ses_id,
1752 sizeof(lst_sid_t)) == 0)
1755 lstcon_session_end();
1761 lstcon_session_info(lst_sid_t *sid_up, int *key_up, unsigned *featp,
1762 lstcon_ndlist_ent_t *ndinfo_up, char *name_up, int len)
1764 lstcon_ndlist_ent_t *entp;
1765 lstcon_ndlink_t *ndl;
1768 if (console_session.ses_state != LST_SESSION_ACTIVE)
1771 LIBCFS_ALLOC(entp, sizeof(*entp));
1775 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link)
1776 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1778 if (copy_to_user(sid_up, &console_session.ses_id,
1779 sizeof(lst_sid_t)) ||
1780 copy_to_user(key_up, &console_session.ses_key,
1782 copy_to_user(featp, &console_session.ses_features,
1784 copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1785 copy_to_user(name_up, console_session.ses_name, len))
1788 LIBCFS_FREE(entp, sizeof(*entp));
1794 lstcon_session_end(void)
1796 lstcon_rpc_trans_t *trans;
1797 lstcon_group_t *grp;
1798 lstcon_batch_t *bat;
1801 LASSERT(console_session.ses_state == LST_SESSION_ACTIVE);
1803 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1804 NULL, LST_TRANS_SESEND, NULL,
1805 lstcon_sesrpc_condition, &trans);
1807 CERROR("Can't create transaction: %d\n", rc);
1811 console_session.ses_shutdown = 1;
1813 lstcon_rpc_pinger_stop();
1815 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1817 lstcon_rpc_trans_destroy(trans);
1818 /* User can do nothing even rpc failed, so go on */
1820 /* waiting for orphan rpcs to die */
1821 lstcon_rpc_cleanup_wait();
1823 console_session.ses_id = LST_INVALID_SID;
1824 console_session.ses_state = LST_SESSION_NONE;
1825 console_session.ses_key = 0;
1826 console_session.ses_force = 0;
1827 console_session.ses_feats_updated = 0;
1829 /* destroy all batches */
1830 while (!list_empty(&console_session.ses_bat_list)) {
1831 bat = list_entry(console_session.ses_bat_list.next,
1832 lstcon_batch_t, bat_link);
1834 lstcon_batch_destroy(bat);
1837 /* destroy all groups */
1838 while (!list_empty(&console_session.ses_grp_list)) {
1839 grp = list_entry(console_session.ses_grp_list.next,
1840 lstcon_group_t, grp_link);
1841 LASSERT(grp->grp_ref == 1);
1843 lstcon_group_decref(grp);
1846 /* all nodes should be released */
1847 LASSERT(list_empty(&console_session.ses_ndl_list));
1849 console_session.ses_shutdown = 0;
1850 console_session.ses_expired = 0;
1856 lstcon_session_feats_check(unsigned feats)
1860 if ((feats & ~LST_FEATS_MASK) != 0) {
1861 CERROR("Can't support these features: %x\n",
1862 (feats & ~LST_FEATS_MASK));
1866 spin_lock(&console_session.ses_rpc_lock);
1868 if (!console_session.ses_feats_updated) {
1869 console_session.ses_feats_updated = 1;
1870 console_session.ses_features = feats;
1873 if (console_session.ses_features != feats)
1876 spin_unlock(&console_session.ses_rpc_lock);
1879 CERROR("remote features %x do not match with session features %x of console\n",
1880 feats, console_session.ses_features);
1887 lstcon_acceptor_handle(struct srpc_server_rpc *rpc)
1889 srpc_msg_t *rep = &rpc->srpc_replymsg;
1890 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1891 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1892 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1893 lstcon_group_t *grp = NULL;
1894 lstcon_ndlink_t *ndl;
1897 sfw_unpack_message(req);
1899 mutex_lock(&console_session.ses_mutex);
1901 jrep->join_sid = console_session.ses_id;
1903 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1904 jrep->join_status = ESRCH;
1908 if (lstcon_session_feats_check(req->msg_ses_feats) != 0) {
1909 jrep->join_status = EPROTO;
1913 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1914 !lstcon_session_match(jreq->join_sid)) {
1915 jrep->join_status = EBUSY;
1919 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1920 rc = lstcon_group_alloc(jreq->join_group, &grp);
1922 CERROR("Out of memory\n");
1926 list_add_tail(&grp->grp_link,
1927 &console_session.ses_grp_list);
1928 lstcon_group_addref(grp);
1931 if (grp->grp_ref > 2) {
1932 /* Group in using */
1933 jrep->join_status = EBUSY;
1937 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1939 jrep->join_status = EEXIST;
1943 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1945 CERROR("Out of memory\n");
1949 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1950 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1952 if (grp->grp_userland == 0)
1953 grp->grp_userland = 1;
1955 strlcpy(jrep->join_session, console_session.ses_name,
1956 sizeof(jrep->join_session));
1957 jrep->join_timeout = console_session.ses_timeout;
1958 jrep->join_status = 0;
1961 rep->msg_ses_feats = console_session.ses_features;
1963 lstcon_group_decref(grp);
1965 mutex_unlock(&console_session.ses_mutex);
1970 srpc_service_t lstcon_acceptor_service;
1971 static void lstcon_init_acceptor_service(void)
1973 /* initialize selftest console acceptor service table */
1974 lstcon_acceptor_service.sv_name = "join session";
1975 lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
1976 lstcon_acceptor_service.sv_id = SRPC_SERVICE_JOIN;
1977 lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX;
1980 extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
1982 static DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
1984 /* initialize console */
1986 lstcon_console_init(void)
1991 memset(&console_session, 0, sizeof(lstcon_session_t));
1993 console_session.ses_id = LST_INVALID_SID;
1994 console_session.ses_state = LST_SESSION_NONE;
1995 console_session.ses_timeout = 0;
1996 console_session.ses_force = 0;
1997 console_session.ses_expired = 0;
1998 console_session.ses_feats_updated = 0;
1999 console_session.ses_features = LST_FEATS_MASK;
2000 console_session.ses_laststamp = ktime_get_real_seconds();
2002 mutex_init(&console_session.ses_mutex);
2004 INIT_LIST_HEAD(&console_session.ses_ndl_list);
2005 INIT_LIST_HEAD(&console_session.ses_grp_list);
2006 INIT_LIST_HEAD(&console_session.ses_bat_list);
2007 INIT_LIST_HEAD(&console_session.ses_trans_list);
2009 LIBCFS_ALLOC(console_session.ses_ndl_hash,
2010 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2011 if (console_session.ses_ndl_hash == NULL)
2014 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
2015 INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
2017 /* initialize acceptor service table */
2018 lstcon_init_acceptor_service();
2020 rc = srpc_add_service(&lstcon_acceptor_service);
2021 LASSERT(rc != -EBUSY);
2023 LIBCFS_FREE(console_session.ses_ndl_hash,
2024 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2028 rc = srpc_service_add_buffers(&lstcon_acceptor_service,
2029 lstcon_acceptor_service.sv_wi_total);
2035 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
2038 lstcon_rpc_module_init();
2043 srpc_shutdown_service(&lstcon_acceptor_service);
2044 srpc_remove_service(&lstcon_acceptor_service);
2046 LIBCFS_FREE(console_session.ses_ndl_hash,
2047 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2049 srpc_wait_service_shutdown(&lstcon_acceptor_service);
2055 lstcon_console_fini(void)
2059 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
2061 mutex_lock(&console_session.ses_mutex);
2063 srpc_shutdown_service(&lstcon_acceptor_service);
2064 srpc_remove_service(&lstcon_acceptor_service);
2066 if (console_session.ses_state != LST_SESSION_NONE)
2067 lstcon_session_end();
2069 lstcon_rpc_module_fini();
2071 mutex_unlock(&console_session.ses_mutex);
2073 LASSERT(list_empty(&console_session.ses_ndl_list));
2074 LASSERT(list_empty(&console_session.ses_grp_list));
2075 LASSERT(list_empty(&console_session.ses_bat_list));
2076 LASSERT(list_empty(&console_session.ses_trans_list));
2078 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
2079 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
2082 LIBCFS_FREE(console_session.ses_ndl_hash,
2083 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2085 srpc_wait_service_shutdown(&lstcon_acceptor_service);