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, 2014, 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>
44 #include <libcfs/libcfs.h>
45 #include <lnet/lib-lnet.h>
49 #define LST_NODE_STATE_COUNTER(nd, p) \
51 if ((nd)->nd_state == LST_NODE_ACTIVE) \
52 (p)->nle_nactive ++; \
53 else if ((nd)->nd_state == LST_NODE_BUSY) \
55 else if ((nd)->nd_state == LST_NODE_DOWN) \
58 (p)->nle_nunknown ++; \
62 lstcon_session_t console_session;
65 lstcon_node_get(lstcon_node_t *nd)
67 LASSERT (nd->nd_ref >= 1);
73 lstcon_node_find(lnet_process_id_t id, lstcon_node_t **ndpp, int create)
76 unsigned int idx = LNET_NIDADDR(id.nid) % LST_GLOBAL_HASHSIZE;
78 LASSERT(id.nid != LNET_NID_ANY);
80 list_for_each_entry(ndl, &console_session.ses_ndl_hash[idx],
82 if (ndl->ndl_node->nd_id.nid != id.nid ||
83 ndl->ndl_node->nd_id.pid != id.pid)
86 lstcon_node_get(ndl->ndl_node);
87 *ndpp = ndl->ndl_node;
94 LIBCFS_ALLOC(*ndpp, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
98 ndl = (lstcon_ndlink_t *)(*ndpp + 1);
100 ndl->ndl_node = *ndpp;
102 ndl->ndl_node->nd_ref = 1;
103 ndl->ndl_node->nd_id = id;
104 ndl->ndl_node->nd_stamp = cfs_time_current();
105 ndl->ndl_node->nd_state = LST_NODE_UNKNOWN;
106 ndl->ndl_node->nd_timeout = 0;
107 memset(&ndl->ndl_node->nd_ping, 0, sizeof(lstcon_rpc_t));
109 /* queued in global hash & list, no refcount is taken by
110 * global hash & list, if caller release his refcount,
111 * node will be released */
112 list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
113 list_add_tail(&ndl->ndl_link, &console_session.ses_ndl_list);
119 lstcon_node_put(lstcon_node_t *nd)
121 lstcon_ndlink_t *ndl;
123 LASSERT(nd->nd_ref > 0);
125 if (--nd->nd_ref > 0)
128 ndl = (lstcon_ndlink_t *)(nd + 1);
130 LASSERT(!list_empty(&ndl->ndl_link));
131 LASSERT(!list_empty(&ndl->ndl_hlink));
133 /* remove from session */
134 list_del(&ndl->ndl_link);
135 list_del(&ndl->ndl_hlink);
137 LIBCFS_FREE(nd, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
141 lstcon_ndlink_find(struct list_head *hash,
142 lnet_process_id_t id, lstcon_ndlink_t **ndlpp, int create)
144 unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
145 lstcon_ndlink_t *ndl;
149 if (id.nid == LNET_NID_ANY)
153 list_for_each_entry(ndl, &hash[idx], ndl_hlink) {
154 if (ndl->ndl_node->nd_id.nid != id.nid ||
155 ndl->ndl_node->nd_id.pid != id.pid)
165 /* find or create in session hash */
166 rc = lstcon_node_find(id, &nd, (create == 1) ? 1 : 0);
170 LIBCFS_ALLOC(ndl, sizeof(lstcon_ndlink_t));
179 INIT_LIST_HEAD(&ndl->ndl_link);
180 list_add_tail(&ndl->ndl_hlink, &hash[idx]);
186 lstcon_ndlink_release(lstcon_ndlink_t *ndl)
188 LASSERT(list_empty(&ndl->ndl_link));
189 LASSERT(!list_empty(&ndl->ndl_hlink));
191 list_del(&ndl->ndl_hlink); /* delete from hash */
192 lstcon_node_put(ndl->ndl_node);
194 LIBCFS_FREE(ndl, sizeof(*ndl));
198 lstcon_group_alloc(char *name, lstcon_group_t **grpp)
203 LIBCFS_ALLOC(grp, offsetof(lstcon_group_t,
204 grp_ndl_hash[LST_NODE_HASHSIZE]));
210 if (strlen(name) > sizeof(grp->grp_name)-1) {
211 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
212 grp_ndl_hash[LST_NODE_HASHSIZE]));
215 strncpy(grp->grp_name, name, sizeof(grp->grp_name));
218 INIT_LIST_HEAD(&grp->grp_link);
219 INIT_LIST_HEAD(&grp->grp_ndl_list);
220 INIT_LIST_HEAD(&grp->grp_trans_list);
222 for (i = 0; i < LST_NODE_HASHSIZE; i++)
223 INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
231 lstcon_group_addref(lstcon_group_t *grp)
236 static void lstcon_group_ndlink_release(lstcon_group_t *, lstcon_ndlink_t *);
239 lstcon_group_drain(lstcon_group_t *grp, int keep)
241 lstcon_ndlink_t *ndl;
242 lstcon_ndlink_t *tmp;
244 list_for_each_entry_safe(ndl, tmp, &grp->grp_ndl_list, ndl_link) {
245 if ((ndl->ndl_node->nd_state & keep) == 0)
246 lstcon_group_ndlink_release(grp, ndl);
251 lstcon_group_decref(lstcon_group_t *grp)
255 if (--grp->grp_ref > 0)
258 if (!list_empty(&grp->grp_link))
259 list_del(&grp->grp_link);
261 lstcon_group_drain(grp, 0);
263 for (i = 0; i < LST_NODE_HASHSIZE; i++)
264 LASSERT(list_empty(&grp->grp_ndl_hash[i]));
266 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
267 grp_ndl_hash[LST_NODE_HASHSIZE]));
271 lstcon_group_find(const char *name, lstcon_group_t **grpp)
275 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
276 if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
279 lstcon_group_addref(grp); /* +1 ref for caller */
288 lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id,
289 lstcon_ndlink_t **ndlpp, int create)
293 rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
297 if (!list_empty(&(*ndlpp)->ndl_link))
300 list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
307 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
309 list_del_init(&ndl->ndl_link);
310 lstcon_ndlink_release(ndl);
315 lstcon_group_ndlink_move(lstcon_group_t *old,
316 lstcon_group_t *new, lstcon_ndlink_t *ndl)
318 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
321 list_del(&ndl->ndl_hlink);
322 list_del(&ndl->ndl_link);
325 list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
326 list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
333 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
335 lstcon_ndlink_t *ndl;
337 while (!list_empty(&old->grp_ndl_list)) {
338 ndl = list_entry(old->grp_ndl_list.next,
339 lstcon_ndlink_t, ndl_link);
340 lstcon_group_ndlink_move(old, new, ndl);
345 lstcon_sesrpc_condition(int transop, lstcon_node_t *nd, void *arg)
347 lstcon_group_t *grp = (lstcon_group_t *)arg;
350 case LST_TRANS_SESNEW:
351 if (nd->nd_state == LST_NODE_ACTIVE)
355 case LST_TRANS_SESEND:
356 if (nd->nd_state != LST_NODE_ACTIVE)
359 if (grp != NULL && nd->nd_ref > 1)
363 case LST_TRANS_SESQRY:
374 lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
375 lstcon_rpc_ent_t __user *ent_up)
377 srpc_debug_reply_t *rep;
380 case LST_TRANS_SESNEW:
381 case LST_TRANS_SESEND:
384 case LST_TRANS_SESQRY:
385 rep = &msg->msg_body.dbg_reply;
387 if (copy_to_user(&ent_up->rpe_priv[0],
388 &rep->dbg_timeout, sizeof(int)) ||
389 copy_to_user(&ent_up->rpe_payload[0],
390 &rep->dbg_name, LST_NAME_SIZE))
403 lstcon_group_nodes_add(lstcon_group_t *grp,
404 int count, lnet_process_id_t __user *ids_up,
405 unsigned *featp, struct list_head __user *result_up)
407 lstcon_rpc_trans_t *trans;
408 lstcon_ndlink_t *ndl;
410 lnet_process_id_t id;
414 rc = lstcon_group_alloc(NULL, &tmp);
416 CERROR("Out of memory\n");
420 for (i = 0 ; i < count; i++) {
421 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
426 /* skip if it's in this group already */
427 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
431 /* add to tmp group */
432 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
434 CERROR("Can't create ndlink, out of memory\n");
440 lstcon_group_decref(tmp);
444 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
445 &tmp->grp_trans_list, LST_TRANS_SESNEW,
446 tmp, lstcon_sesrpc_condition, &trans);
448 CERROR("Can't create transaction: %d\n", rc);
449 lstcon_group_decref(tmp);
454 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
456 rc = lstcon_rpc_trans_interpreter(trans, result_up,
457 lstcon_sesrpc_readent);
458 *featp = trans->tas_features;
460 /* destroy all RPGs */
461 lstcon_rpc_trans_destroy(trans);
463 lstcon_group_move(tmp, grp);
464 lstcon_group_decref(tmp);
470 lstcon_group_nodes_remove(lstcon_group_t *grp,
471 int count, lnet_process_id_t __user *ids_up,
472 struct list_head __user *result_up)
474 lstcon_rpc_trans_t *trans;
475 lstcon_ndlink_t *ndl;
477 lnet_process_id_t id;
481 /* End session and remove node from the group */
483 rc = lstcon_group_alloc(NULL, &tmp);
485 CERROR("Out of memory\n");
489 for (i = 0; i < count; i++) {
490 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
495 /* move node to tmp group */
496 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
497 lstcon_group_ndlink_move(grp, tmp, ndl);
500 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
501 &tmp->grp_trans_list, LST_TRANS_SESEND,
502 tmp, lstcon_sesrpc_condition, &trans);
504 CERROR("Can't create transaction: %d\n", rc);
508 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
510 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
512 lstcon_rpc_trans_destroy(trans);
513 /* release nodes anyway, because we can't rollback status */
514 lstcon_group_decref(tmp);
518 lstcon_group_move(tmp, grp);
519 lstcon_group_decref(tmp);
525 lstcon_group_add(char *name)
530 rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
532 /* find a group with same name */
533 lstcon_group_decref(grp);
537 rc = lstcon_group_alloc(name, &grp);
539 CERROR("Can't allocate descriptor for group %s\n", name);
543 list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
549 lstcon_nodes_add(char *name, int count, lnet_process_id_t __user *ids_up,
550 unsigned *featp, struct list_head __user *result_up)
556 LASSERT (ids_up != NULL);
558 rc = lstcon_group_find(name, &grp);
560 CDEBUG(D_NET, "Can't find group %s\n", name);
564 if (grp->grp_ref > 2) {
565 /* referred by other threads or test */
566 CDEBUG(D_NET, "Group %s is busy\n", name);
567 lstcon_group_decref(grp);
572 rc = lstcon_group_nodes_add(grp, count, ids_up, featp, result_up);
574 lstcon_group_decref(grp);
580 lstcon_group_del(char *name)
582 lstcon_rpc_trans_t *trans;
586 rc = lstcon_group_find(name, &grp);
588 CDEBUG(D_NET, "Can't find group: %s\n", name);
592 if (grp->grp_ref > 2) {
593 /* referred by others threads or test */
594 CDEBUG(D_NET, "Group %s is busy\n", name);
595 lstcon_group_decref(grp);
599 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
600 &grp->grp_trans_list, LST_TRANS_SESEND,
601 grp, lstcon_sesrpc_condition, &trans);
603 CERROR("Can't create transaction: %d\n", rc);
604 lstcon_group_decref(grp);
608 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
610 lstcon_rpc_trans_destroy(trans);
612 lstcon_group_decref(grp);
613 /* -ref for session, it's destroyed,
614 * status can't be rolled back, destroy group anway */
615 lstcon_group_decref(grp);
621 lstcon_group_clean(char *name, int args)
623 lstcon_group_t *grp = NULL;
626 rc = lstcon_group_find(name, &grp);
628 CDEBUG(D_NET, "Can't find group %s\n", name);
632 if (grp->grp_ref > 2) {
633 /* referred by test */
634 CDEBUG(D_NET, "Group %s is busy\n", name);
635 lstcon_group_decref(grp);
639 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
640 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
642 lstcon_group_drain(grp, args);
644 lstcon_group_decref(grp);
645 /* release empty group */
646 if (list_empty(&grp->grp_ndl_list))
647 lstcon_group_decref(grp);
653 lstcon_nodes_remove(char *name, int count,
654 lnet_process_id_t __user *ids_up,
655 struct list_head __user *result_up)
657 lstcon_group_t *grp = NULL;
660 rc = lstcon_group_find(name, &grp);
662 CDEBUG(D_NET, "Can't find group: %s\n", name);
666 if (grp->grp_ref > 2) {
667 /* referred by test */
668 CDEBUG(D_NET, "Group %s is busy\n", name);
669 lstcon_group_decref(grp);
673 rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
675 lstcon_group_decref(grp);
676 /* release empty group */
677 if (list_empty(&grp->grp_ndl_list))
678 lstcon_group_decref(grp);
684 lstcon_group_refresh(char *name, struct list_head __user *result_up)
686 lstcon_rpc_trans_t *trans;
690 rc = lstcon_group_find(name, &grp);
692 CDEBUG(D_NET, "Can't find group: %s\n", name);
696 if (grp->grp_ref > 2) {
697 /* referred by test */
698 CDEBUG(D_NET, "Group %s is busy\n", name);
699 lstcon_group_decref(grp);
703 /* re-invite all inactive nodes int the group */
704 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
705 &grp->grp_trans_list, LST_TRANS_SESNEW,
706 grp, lstcon_sesrpc_condition, &trans);
708 /* local error, return */
709 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
710 lstcon_group_decref(grp);
714 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
716 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
718 lstcon_rpc_trans_destroy(trans);
720 lstcon_group_decref(grp);
726 lstcon_group_list(int index, int len, char __user *name_up)
731 LASSERT(name_up != NULL);
733 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
735 return copy_to_user(name_up, grp->grp_name, len) ?
744 lstcon_nodes_getent(struct list_head *head, int *index_p,
745 int *count_p, lstcon_node_ent_t __user *dents_up)
747 lstcon_ndlink_t *ndl;
752 LASSERT(index_p != NULL && count_p != NULL);
753 LASSERT(dents_up != NULL);
754 LASSERT(*index_p >= 0);
755 LASSERT(*count_p > 0);
757 list_for_each_entry(ndl, head, ndl_link) {
758 if (index++ < *index_p)
761 if (count >= *count_p)
765 if (copy_to_user(&dents_up[count].nde_id,
766 &nd->nd_id, sizeof(nd->nd_id)) ||
767 copy_to_user(&dents_up[count].nde_state,
768 &nd->nd_state, sizeof(nd->nd_state)))
774 if (index <= *index_p)
784 lstcon_group_info(char *name, lstcon_ndlist_ent_t __user *gents_p,
785 int *index_p, int *count_p,
786 lstcon_node_ent_t __user *dents_up)
788 lstcon_ndlist_ent_t *gentp;
790 lstcon_ndlink_t *ndl;
793 rc = lstcon_group_find(name, &grp);
795 CDEBUG(D_NET, "Can't find group %s\n", name);
799 if (dents_up != NULL) {
801 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
802 index_p, count_p, dents_up);
803 lstcon_group_decref(grp);
808 /* non-verbose query */
809 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
811 CERROR("Can't allocate ndlist_ent\n");
812 lstcon_group_decref(grp);
817 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link)
818 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
820 rc = copy_to_user(gents_p, gentp,
821 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT : 0;
823 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
825 lstcon_group_decref(grp);
831 lstcon_batch_find(const char *name, lstcon_batch_t **batpp)
835 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
836 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
846 lstcon_batch_add(char *name)
852 rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
854 CDEBUG(D_NET, "Batch %s already exists\n", name);
858 LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
860 CERROR("Can't allocate descriptor for batch %s\n", name);
864 LIBCFS_ALLOC(bat->bat_cli_hash,
865 sizeof(struct list_head) * LST_NODE_HASHSIZE);
866 if (bat->bat_cli_hash == NULL) {
867 CERROR("Can't allocate hash for batch %s\n", name);
868 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
873 LIBCFS_ALLOC(bat->bat_srv_hash,
874 sizeof(struct list_head) * LST_NODE_HASHSIZE);
875 if (bat->bat_srv_hash == NULL) {
876 CERROR("Can't allocate hash for batch %s\n", name);
877 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
878 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
883 if (strlen(name) > sizeof(bat->bat_name)-1) {
884 LIBCFS_FREE(bat->bat_srv_hash, LST_NODE_HASHSIZE);
885 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
886 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
889 strncpy(bat->bat_name, name, sizeof(bat->bat_name));
890 bat->bat_hdr.tsb_index = 0;
891 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
894 bat->bat_state = LST_BATCH_IDLE;
896 INIT_LIST_HEAD(&bat->bat_cli_list);
897 INIT_LIST_HEAD(&bat->bat_srv_list);
898 INIT_LIST_HEAD(&bat->bat_test_list);
899 INIT_LIST_HEAD(&bat->bat_trans_list);
901 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
902 INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
903 INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
906 list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
912 lstcon_batch_list(int index, int len, char __user *name_up)
916 LASSERT(name_up != NULL);
919 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
921 return copy_to_user(name_up, bat->bat_name, len) ?
930 lstcon_batch_info(char *name, lstcon_test_batch_ent_t __user *ent_up,
931 int server, int testidx, int *index_p, int *ndent_p,
932 lstcon_node_ent_t __user *dents_up)
934 lstcon_test_batch_ent_t *entp;
935 struct list_head *clilst;
936 struct list_head *srvlst;
937 lstcon_test_t *test = NULL;
939 lstcon_ndlink_t *ndl;
942 rc = lstcon_batch_find(name, &bat);
944 CDEBUG(D_NET, "Can't find batch %s\n", name);
949 /* query test, test index start from 1 */
950 list_for_each_entry(test, &bat->bat_test_list, tes_link) {
956 CDEBUG(D_NET, "Can't find specified test in batch\n");
961 clilst = (test == NULL) ? &bat->bat_cli_list :
962 &test->tes_src_grp->grp_ndl_list;
963 srvlst = (test == NULL) ? &bat->bat_srv_list :
964 &test->tes_dst_grp->grp_ndl_list;
966 if (dents_up != NULL) {
967 rc = lstcon_nodes_getent((server ? srvlst: clilst),
968 index_p, ndent_p, dents_up);
972 /* non-verbose query */
973 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
978 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
979 entp->u.tbe_batch.bae_state = bat->bat_state;
983 entp->u.tbe_test.tse_type = test->tes_type;
984 entp->u.tbe_test.tse_loop = test->tes_loop;
985 entp->u.tbe_test.tse_concur = test->tes_concur;
988 list_for_each_entry(ndl, clilst, ndl_link)
989 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
991 list_for_each_entry(ndl, srvlst, ndl_link)
992 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
994 rc = copy_to_user(ent_up, entp,
995 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
997 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
1003 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1006 case LST_TRANS_TSBRUN:
1007 if (nd->nd_state != LST_NODE_ACTIVE)
1011 case LST_TRANS_TSBSTOP:
1012 if (nd->nd_state != LST_NODE_ACTIVE)
1016 case LST_TRANS_TSBCLIQRY:
1017 case LST_TRANS_TSBSRVQRY:
1025 lstcon_batch_op(lstcon_batch_t *bat, int transop,
1026 struct list_head __user *result_up)
1028 lstcon_rpc_trans_t *trans;
1031 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1032 &bat->bat_trans_list, transop,
1033 bat, lstcon_batrpc_condition, &trans);
1035 CERROR("Can't create transaction: %d\n", rc);
1039 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1041 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1043 lstcon_rpc_trans_destroy(trans);
1049 lstcon_batch_run(char *name, int timeout, struct list_head __user *result_up)
1051 lstcon_batch_t *bat;
1054 if (lstcon_batch_find(name, &bat) != 0) {
1055 CDEBUG(D_NET, "Can't find batch %s\n", name);
1059 bat->bat_arg = timeout;
1061 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1063 /* mark batch as running if it's started in any node */
1064 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1065 bat->bat_state = LST_BATCH_RUNNING;
1071 lstcon_batch_stop(char *name, int force, struct list_head __user *result_up)
1073 lstcon_batch_t *bat;
1076 if (lstcon_batch_find(name, &bat) != 0) {
1077 CDEBUG(D_NET, "Can't find batch %s\n", name);
1081 bat->bat_arg = force;
1083 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1085 /* mark batch as stopped if all RPCs finished */
1086 if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1087 bat->bat_state = LST_BATCH_IDLE;
1093 lstcon_batch_destroy(lstcon_batch_t *bat)
1095 lstcon_ndlink_t *ndl;
1096 lstcon_test_t *test;
1099 list_del(&bat->bat_link);
1101 while (!list_empty(&bat->bat_test_list)) {
1102 test = list_entry(bat->bat_test_list.next,
1103 lstcon_test_t, tes_link);
1104 LASSERT(list_empty(&test->tes_trans_list));
1106 list_del(&test->tes_link);
1108 lstcon_group_decref(test->tes_src_grp);
1109 lstcon_group_decref(test->tes_dst_grp);
1111 LIBCFS_FREE(test, offsetof(lstcon_test_t,
1112 tes_param[test->tes_paramlen]));
1115 LASSERT(list_empty(&bat->bat_trans_list));
1117 while (!list_empty(&bat->bat_cli_list)) {
1118 ndl = list_entry(bat->bat_cli_list.next,
1119 lstcon_ndlink_t, ndl_link);
1120 list_del_init(&ndl->ndl_link);
1122 lstcon_ndlink_release(ndl);
1125 while (!list_empty(&bat->bat_srv_list)) {
1126 ndl = list_entry(bat->bat_srv_list.next,
1127 lstcon_ndlink_t, ndl_link);
1128 list_del_init(&ndl->ndl_link);
1130 lstcon_ndlink_release(ndl);
1133 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1134 LASSERT(list_empty(&bat->bat_cli_hash[i]));
1135 LASSERT(list_empty(&bat->bat_srv_hash[i]));
1138 LIBCFS_FREE(bat->bat_cli_hash,
1139 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1140 LIBCFS_FREE(bat->bat_srv_hash,
1141 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1142 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
1146 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1148 lstcon_test_t *test;
1149 lstcon_batch_t *batch;
1150 lstcon_ndlink_t *ndl;
1151 struct list_head *hash;
1152 struct list_head *head;
1154 test = (lstcon_test_t *)arg;
1155 LASSERT(test != NULL);
1157 batch = test->tes_batch;
1158 LASSERT(batch != NULL);
1160 if (test->tes_oneside &&
1161 transop == LST_TRANS_TSBSRVADD)
1164 if (nd->nd_state != LST_NODE_ACTIVE)
1167 if (transop == LST_TRANS_TSBCLIADD) {
1168 hash = batch->bat_cli_hash;
1169 head = &batch->bat_cli_list;
1172 LASSERT (transop == LST_TRANS_TSBSRVADD);
1174 hash = batch->bat_srv_hash;
1175 head = &batch->bat_srv_list;
1178 LASSERT (nd->nd_id.nid != LNET_NID_ANY);
1180 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1183 if (list_empty(&ndl->ndl_link))
1184 list_add_tail(&ndl->ndl_link, head);
1190 lstcon_test_nodes_add(lstcon_test_t *test, struct list_head __user *result_up)
1192 lstcon_rpc_trans_t *trans;
1193 lstcon_group_t *grp;
1197 LASSERT (test->tes_src_grp != NULL);
1198 LASSERT (test->tes_dst_grp != NULL);
1200 transop = LST_TRANS_TSBSRVADD;
1201 grp = test->tes_dst_grp;
1203 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1204 &test->tes_trans_list, transop,
1205 test, lstcon_testrpc_condition, &trans);
1207 CERROR("Can't create transaction: %d\n", rc);
1211 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1213 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1214 lstcon_trans_stat()->trs_fwk_errno != 0) {
1215 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1217 lstcon_rpc_trans_destroy(trans);
1218 /* return if any error */
1219 CDEBUG(D_NET, "Failed to add test %s, "
1220 "RPC error %d, framework error %d\n",
1221 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1222 lstcon_trans_stat()->trs_rpc_errno,
1223 lstcon_trans_stat()->trs_fwk_errno);
1228 lstcon_rpc_trans_destroy(trans);
1230 if (transop == LST_TRANS_TSBCLIADD)
1233 transop = LST_TRANS_TSBCLIADD;
1234 grp = test->tes_src_grp;
1235 test->tes_cliidx = 0;
1237 /* requests to test clients */
1242 lstcon_verify_batch(const char *name, lstcon_batch_t **batch)
1246 rc = lstcon_batch_find(name, batch);
1248 CDEBUG(D_NET, "Can't find batch %s\n", name);
1252 if ((*batch)->bat_state != LST_BATCH_IDLE) {
1253 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1261 lstcon_verify_group(const char *name, lstcon_group_t **grp)
1264 lstcon_ndlink_t *ndl;
1266 rc = lstcon_group_find(name, grp);
1268 CDEBUG(D_NET, "can't find group %s\n", name);
1272 list_for_each_entry(ndl, &(*grp)->grp_ndl_list, ndl_link) {
1273 if (ndl->ndl_node->nd_state == LST_NODE_ACTIVE) {
1278 CDEBUG(D_NET, "Group %s has no ACTIVE nodes\n", name);
1284 lstcon_test_add(char *batch_name, int type, int loop,
1285 int concur, int dist, int span,
1286 char *src_name, char *dst_name,
1287 void *param, int paramlen, int *retp,
1288 struct list_head __user *result_up)
1290 lstcon_test_t *test = NULL;
1292 lstcon_group_t *src_grp = NULL;
1293 lstcon_group_t *dst_grp = NULL;
1294 lstcon_batch_t *batch = NULL;
1297 * verify that a batch of the given name exists, and the groups
1298 * that will be part of the batch exist and have at least one
1301 rc = lstcon_verify_batch(batch_name, &batch);
1305 rc = lstcon_verify_group(src_name, &src_grp);
1309 rc = lstcon_verify_group(dst_name, &dst_grp);
1313 if (dst_grp->grp_userland)
1316 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1318 CERROR("Can't allocate test descriptor\n");
1324 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1325 test->tes_batch = batch;
1326 test->tes_type = type;
1327 test->tes_oneside = 0; /* TODO */
1328 test->tes_loop = loop;
1329 test->tes_concur = concur;
1330 test->tes_stop_onerr = 1; /* TODO */
1331 test->tes_span = span;
1332 test->tes_dist = dist;
1333 test->tes_cliidx = 0; /* just used for creating RPC */
1334 test->tes_src_grp = src_grp;
1335 test->tes_dst_grp = dst_grp;
1336 INIT_LIST_HEAD(&test->tes_trans_list);
1338 if (param != NULL) {
1339 test->tes_paramlen = paramlen;
1340 memcpy(&test->tes_param[0], param, paramlen);
1343 rc = lstcon_test_nodes_add(test, result_up);
1348 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1349 lstcon_trans_stat()->trs_fwk_errno != 0)
1350 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type,
1353 /* add to test list anyway, so user can check what's going on */
1354 list_add_tail(&test->tes_link, &batch->bat_test_list);
1357 test->tes_hdr.tsb_index = batch->bat_ntest;
1359 /* hold groups so nobody can change them */
1363 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1365 if (dst_grp != NULL)
1366 lstcon_group_decref(dst_grp);
1368 if (src_grp != NULL)
1369 lstcon_group_decref(src_grp);
1375 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1377 lstcon_test_t *test;
1379 list_for_each_entry(test, &batch->bat_test_list, tes_link) {
1380 if (idx == test->tes_hdr.tsb_index) {
1390 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1391 lstcon_rpc_ent_t __user *ent_up)
1393 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1395 LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1396 transop == LST_TRANS_TSBSRVQRY);
1398 /* positive errno, framework error code */
1399 if (copy_to_user(&ent_up->rpe_priv[0],
1400 &rep->bar_active, sizeof(rep->bar_active)))
1407 lstcon_test_batch_query(char *name, int testidx, int client,
1408 int timeout, struct list_head __user *result_up)
1410 lstcon_rpc_trans_t *trans;
1411 struct list_head *translist;
1412 struct list_head *ndlist;
1413 lstcon_tsb_hdr_t *hdr;
1414 lstcon_batch_t *batch;
1415 lstcon_test_t *test = NULL;
1419 rc = lstcon_batch_find(name, &batch);
1421 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1426 translist = &batch->bat_trans_list;
1427 ndlist = &batch->bat_cli_list;
1428 hdr = &batch->bat_hdr;
1431 /* query specified test only */
1432 rc = lstcon_test_find(batch, testidx, &test);
1434 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1438 translist = &test->tes_trans_list;
1439 ndlist = &test->tes_src_grp->grp_ndl_list;
1440 hdr = &test->tes_hdr;
1443 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1445 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1446 lstcon_batrpc_condition, &trans);
1448 CERROR("Can't create transaction: %d\n", rc);
1452 lstcon_rpc_trans_postwait(trans, timeout);
1454 if (testidx == 0 && /* query a batch, not a test */
1455 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1456 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1457 /* all RPCs finished, and no active test */
1458 batch->bat_state = LST_BATCH_IDLE;
1461 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1462 lstcon_tsbrpc_readent);
1463 lstcon_rpc_trans_destroy(trans);
1469 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1470 lstcon_rpc_ent_t __user *ent_up)
1472 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1473 sfw_counters_t __user *sfwk_stat;
1474 srpc_counters_t __user *srpc_stat;
1475 lnet_counters_t __user *lnet_stat;
1477 if (rep->str_status != 0)
1480 sfwk_stat = (sfw_counters_t __user *)&ent_up->rpe_payload[0];
1481 srpc_stat = (srpc_counters_t __user *)
1482 ((char __user *)sfwk_stat + sizeof(*sfwk_stat));
1483 lnet_stat = (lnet_counters_t __user *)
1484 ((char __user *)srpc_stat + sizeof(*srpc_stat));
1486 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1487 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1488 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1495 lstcon_ndlist_stat(struct list_head *ndlist,
1496 int timeout, struct list_head __user *result_up)
1498 struct list_head head;
1499 lstcon_rpc_trans_t *trans;
1502 INIT_LIST_HEAD(&head);
1504 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1505 LST_TRANS_STATQRY, NULL, NULL, &trans);
1507 CERROR("Can't create transaction: %d\n", rc);
1511 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1513 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1514 lstcon_statrpc_readent);
1515 lstcon_rpc_trans_destroy(trans);
1521 lstcon_group_stat(char *grp_name, int timeout,
1522 struct list_head __user *result_up)
1524 lstcon_group_t *grp;
1527 rc = lstcon_group_find(grp_name, &grp);
1529 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1533 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1535 lstcon_group_decref(grp);
1541 lstcon_nodes_stat(int count, lnet_process_id_t __user *ids_up,
1542 int timeout, struct list_head __user *result_up)
1544 lstcon_ndlink_t *ndl;
1545 lstcon_group_t *tmp;
1546 lnet_process_id_t id;
1550 rc = lstcon_group_alloc(NULL, &tmp);
1552 CERROR("Out of memory\n");
1556 for (i = 0 ; i < count; i++) {
1557 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1562 /* add to tmp group */
1563 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1565 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1566 "Failed to find or create %s: %d\n",
1567 libcfs_id2str(id), rc);
1573 lstcon_group_decref(tmp);
1577 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1579 lstcon_group_decref(tmp);
1585 lstcon_debug_ndlist(struct list_head *ndlist,
1586 struct list_head *translist,
1587 int timeout, struct list_head __user *result_up)
1589 lstcon_rpc_trans_t *trans;
1592 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1593 NULL, lstcon_sesrpc_condition, &trans);
1595 CERROR("Can't create transaction: %d\n", rc);
1599 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1601 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1602 lstcon_sesrpc_readent);
1603 lstcon_rpc_trans_destroy(trans);
1609 lstcon_session_debug(int timeout, struct list_head __user *result_up)
1611 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1612 NULL, timeout, result_up);
1616 lstcon_batch_debug(int timeout, char *name,
1617 int client, struct list_head __user *result_up)
1619 lstcon_batch_t *bat;
1622 rc = lstcon_batch_find(name, &bat);
1626 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1628 NULL, timeout, result_up);
1634 lstcon_group_debug(int timeout, char *name,
1635 struct list_head __user *result_up)
1637 lstcon_group_t *grp;
1640 rc = lstcon_group_find(name, &grp);
1644 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1645 timeout, result_up);
1646 lstcon_group_decref(grp);
1652 lstcon_nodes_debug(int timeout,
1653 int count, lnet_process_id_t __user *ids_up,
1654 struct list_head __user *result_up)
1656 lnet_process_id_t id;
1657 lstcon_ndlink_t *ndl;
1658 lstcon_group_t *grp;
1662 rc = lstcon_group_alloc(NULL, &grp);
1664 CDEBUG(D_NET, "Out of memory\n");
1668 for (i = 0; i < count; i++) {
1669 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1674 /* node is added to tmp group */
1675 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1677 CERROR("Can't create node link\n");
1683 lstcon_group_decref(grp);
1687 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1688 timeout, result_up);
1690 lstcon_group_decref(grp);
1696 lstcon_session_match(lst_sid_t sid)
1698 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1699 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1: 0;
1703 lstcon_new_session_id(lst_sid_t *sid)
1705 lnet_process_id_t id;
1707 LASSERT (console_session.ses_state == LST_SESSION_NONE);
1710 sid->ses_nid = id.nid;
1711 sid->ses_stamp = cfs_time_current();
1715 lstcon_session_new(char *name, int key, unsigned feats,
1716 int timeout, int force, lst_sid_t __user *sid_up)
1721 if (console_session.ses_state != LST_SESSION_NONE) {
1722 /* session exists */
1724 CNETERR("Session %s already exists\n",
1725 console_session.ses_name);
1729 rc = lstcon_session_end();
1731 /* lstcon_session_end() only return local error */
1736 if ((feats & ~LST_FEATS_MASK) != 0) {
1737 CNETERR("Unknown session features %x\n",
1738 (feats & ~LST_FEATS_MASK));
1742 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1743 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
1745 lstcon_new_session_id(&console_session.ses_id);
1747 console_session.ses_key = key;
1748 console_session.ses_state = LST_SESSION_ACTIVE;
1749 console_session.ses_force = !!force;
1750 console_session.ses_features = feats;
1751 console_session.ses_feats_updated = 0;
1752 console_session.ses_timeout = (timeout <= 0) ?
1753 LST_CONSOLE_TIMEOUT : timeout;
1755 if (strlen(name) > sizeof(console_session.ses_name)-1)
1757 strlcpy(console_session.ses_name, name,
1758 sizeof(console_session.ses_name));
1760 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1764 rc = lstcon_rpc_pinger_start();
1766 lstcon_batch_t *bat = NULL;
1768 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1769 lstcon_batch_destroy(bat);
1774 if (copy_to_user(sid_up, &console_session.ses_id,
1775 sizeof(lst_sid_t)) == 0)
1778 lstcon_session_end();
1784 lstcon_session_info(lst_sid_t __user *sid_up, int __user *key_up,
1785 unsigned __user *featp,
1786 lstcon_ndlist_ent_t __user *ndinfo_up,
1787 char __user *name_up, int len)
1789 lstcon_ndlist_ent_t *entp;
1790 lstcon_ndlink_t *ndl;
1793 if (console_session.ses_state != LST_SESSION_ACTIVE)
1796 LIBCFS_ALLOC(entp, sizeof(*entp));
1800 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link)
1801 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1803 if (copy_to_user(sid_up, &console_session.ses_id,
1804 sizeof(lst_sid_t)) ||
1805 copy_to_user(key_up, &console_session.ses_key,
1807 copy_to_user(featp, &console_session.ses_features,
1809 copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1810 copy_to_user(name_up, console_session.ses_name, len))
1813 LIBCFS_FREE(entp, sizeof(*entp));
1819 lstcon_session_end()
1821 lstcon_rpc_trans_t *trans;
1822 lstcon_group_t *grp;
1823 lstcon_batch_t *bat;
1826 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1828 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1829 NULL, LST_TRANS_SESEND, NULL,
1830 lstcon_sesrpc_condition, &trans);
1832 CERROR("Can't create transaction: %d\n", rc);
1836 console_session.ses_shutdown = 1;
1838 lstcon_rpc_pinger_stop();
1840 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1842 lstcon_rpc_trans_destroy(trans);
1843 /* User can do nothing even rpc failed, so go on */
1845 /* waiting for orphan rpcs to die */
1846 lstcon_rpc_cleanup_wait();
1848 console_session.ses_id = LST_INVALID_SID;
1849 console_session.ses_state = LST_SESSION_NONE;
1850 console_session.ses_key = 0;
1851 console_session.ses_force = 0;
1852 console_session.ses_feats_updated = 0;
1854 /* destroy all batches */
1855 while (!list_empty(&console_session.ses_bat_list)) {
1856 bat = list_entry(console_session.ses_bat_list.next,
1857 lstcon_batch_t, bat_link);
1859 lstcon_batch_destroy(bat);
1862 /* destroy all groups */
1863 while (!list_empty(&console_session.ses_grp_list)) {
1864 grp = list_entry(console_session.ses_grp_list.next,
1865 lstcon_group_t, grp_link);
1866 LASSERT(grp->grp_ref == 1);
1868 lstcon_group_decref(grp);
1871 /* all nodes should be released */
1872 LASSERT(list_empty(&console_session.ses_ndl_list));
1874 console_session.ses_shutdown = 0;
1875 console_session.ses_expired = 0;
1881 lstcon_session_feats_check(unsigned feats)
1885 if ((feats & ~LST_FEATS_MASK) != 0) {
1886 CERROR("Can't support these features: %x\n",
1887 (feats & ~LST_FEATS_MASK));
1891 spin_lock(&console_session.ses_rpc_lock);
1893 if (!console_session.ses_feats_updated) {
1894 console_session.ses_feats_updated = 1;
1895 console_session.ses_features = feats;
1898 if (console_session.ses_features != feats)
1901 spin_unlock(&console_session.ses_rpc_lock);
1904 CERROR("remote features %x do not match with "
1905 "session features %x of console\n",
1906 feats, console_session.ses_features);
1913 lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
1915 srpc_msg_t *rep = &rpc->srpc_replymsg;
1916 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1917 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1918 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1919 lstcon_group_t *grp = NULL;
1920 lstcon_ndlink_t *ndl;
1923 sfw_unpack_message(req);
1925 mutex_lock(&console_session.ses_mutex);
1927 jrep->join_sid = console_session.ses_id;
1929 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1930 jrep->join_status = ESRCH;
1934 if (lstcon_session_feats_check(req->msg_ses_feats) != 0) {
1935 jrep->join_status = EPROTO;
1939 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1940 !lstcon_session_match(jreq->join_sid)) {
1941 jrep->join_status = EBUSY;
1945 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1946 rc = lstcon_group_alloc(jreq->join_group, &grp);
1948 CERROR("Out of memory\n");
1952 list_add_tail(&grp->grp_link,
1953 &console_session.ses_grp_list);
1954 lstcon_group_addref(grp);
1957 if (grp->grp_ref > 2) {
1958 /* Group in using */
1959 jrep->join_status = EBUSY;
1963 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1965 jrep->join_status = EEXIST;
1969 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1971 CERROR("Out of memory\n");
1975 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1976 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1978 if (grp->grp_userland == 0)
1979 grp->grp_userland = 1;
1981 strlcpy(jrep->join_session, console_session.ses_name,
1982 sizeof(jrep->join_session));
1983 jrep->join_timeout = console_session.ses_timeout;
1984 jrep->join_status = 0;
1987 rep->msg_ses_feats = console_session.ses_features;
1989 lstcon_group_decref(grp);
1991 mutex_unlock(&console_session.ses_mutex);
1996 static srpc_service_t lstcon_acceptor_service;
1997 static void lstcon_init_acceptor_service(void)
1999 /* initialize selftest console acceptor service table */
2000 lstcon_acceptor_service.sv_name = "join session";
2001 lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
2002 lstcon_acceptor_service.sv_id = SRPC_SERVICE_JOIN;
2003 lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX;
2006 int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
2008 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
2010 /* initialize console */
2012 lstcon_console_init(void)
2017 memset(&console_session, 0, sizeof(lstcon_session_t));
2019 console_session.ses_id = LST_INVALID_SID;
2020 console_session.ses_state = LST_SESSION_NONE;
2021 console_session.ses_timeout = 0;
2022 console_session.ses_force = 0;
2023 console_session.ses_expired = 0;
2024 console_session.ses_feats_updated = 0;
2025 console_session.ses_features = LST_FEATS_MASK;
2026 console_session.ses_laststamp = cfs_time_current_sec();
2028 mutex_init(&console_session.ses_mutex);
2030 INIT_LIST_HEAD(&console_session.ses_ndl_list);
2031 INIT_LIST_HEAD(&console_session.ses_grp_list);
2032 INIT_LIST_HEAD(&console_session.ses_bat_list);
2033 INIT_LIST_HEAD(&console_session.ses_trans_list);
2035 LIBCFS_ALLOC(console_session.ses_ndl_hash,
2036 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2037 if (console_session.ses_ndl_hash == NULL)
2040 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
2041 INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
2044 /* initialize acceptor service table */
2045 lstcon_init_acceptor_service();
2047 rc = srpc_add_service(&lstcon_acceptor_service);
2048 LASSERT(rc != -EBUSY);
2050 LIBCFS_FREE(console_session.ses_ndl_hash,
2051 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2055 rc = srpc_service_add_buffers(&lstcon_acceptor_service,
2056 lstcon_acceptor_service.sv_wi_total);
2062 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
2065 lstcon_rpc_module_init();
2070 srpc_shutdown_service(&lstcon_acceptor_service);
2071 srpc_remove_service(&lstcon_acceptor_service);
2073 LIBCFS_FREE(console_session.ses_ndl_hash,
2074 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2076 srpc_wait_service_shutdown(&lstcon_acceptor_service);
2082 lstcon_console_fini(void)
2086 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
2088 mutex_lock(&console_session.ses_mutex);
2090 srpc_shutdown_service(&lstcon_acceptor_service);
2091 srpc_remove_service(&lstcon_acceptor_service);
2093 if (console_session.ses_state != LST_SESSION_NONE)
2094 lstcon_session_end();
2096 lstcon_rpc_module_fini();
2098 mutex_unlock(&console_session.ses_mutex);
2100 LASSERT(list_empty(&console_session.ses_ndl_list));
2101 LASSERT(list_empty(&console_session.ses_grp_list));
2102 LASSERT(list_empty(&console_session.ses_bat_list));
2103 LASSERT(list_empty(&console_session.ses_trans_list));
2105 for (i = 0; i < LST_NODE_HASHSIZE; i++)
2106 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
2108 LIBCFS_FREE(console_session.ses_ndl_hash,
2109 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2111 srpc_wait_service_shutdown(&lstcon_acceptor_service);