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>
45 #include <libcfs/libcfs.h>
46 #include <lnet/lib-lnet.h>
50 #define LST_NODE_STATE_COUNTER(nd, p) \
52 if ((nd)->nd_state == LST_NODE_ACTIVE) \
53 (p)->nle_nactive ++; \
54 else if ((nd)->nd_state == LST_NODE_BUSY) \
56 else if ((nd)->nd_state == LST_NODE_DOWN) \
59 (p)->nle_nunknown ++; \
63 lstcon_session_t console_session;
66 lstcon_node_get(lstcon_node_t *nd)
68 LASSERT (nd->nd_ref >= 1);
74 lstcon_node_find(lnet_process_id_t id, lstcon_node_t **ndpp, int create)
77 unsigned int idx = LNET_NIDADDR(id.nid) % LST_GLOBAL_HASHSIZE;
79 LASSERT(id.nid != LNET_NID_ANY);
81 list_for_each_entry(ndl, &console_session.ses_ndl_hash[idx],
83 if (ndl->ndl_node->nd_id.nid != id.nid ||
84 ndl->ndl_node->nd_id.pid != id.pid)
87 lstcon_node_get(ndl->ndl_node);
88 *ndpp = ndl->ndl_node;
95 LIBCFS_ALLOC(*ndpp, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
99 ndl = (lstcon_ndlink_t *)(*ndpp + 1);
101 ndl->ndl_node = *ndpp;
103 ndl->ndl_node->nd_ref = 1;
104 ndl->ndl_node->nd_id = id;
105 ndl->ndl_node->nd_stamp = cfs_time_current();
106 ndl->ndl_node->nd_state = LST_NODE_UNKNOWN;
107 ndl->ndl_node->nd_timeout = 0;
108 memset(&ndl->ndl_node->nd_ping, 0, sizeof(lstcon_rpc_t));
110 /* queued in global hash & list, no refcount is taken by
111 * global hash & list, if caller release his refcount,
112 * node will be released */
113 list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
114 list_add_tail(&ndl->ndl_link, &console_session.ses_ndl_list);
120 lstcon_node_put(lstcon_node_t *nd)
122 lstcon_ndlink_t *ndl;
124 LASSERT(nd->nd_ref > 0);
126 if (--nd->nd_ref > 0)
129 ndl = (lstcon_ndlink_t *)(nd + 1);
131 LASSERT(!list_empty(&ndl->ndl_link));
132 LASSERT(!list_empty(&ndl->ndl_hlink));
134 /* remove from session */
135 list_del(&ndl->ndl_link);
136 list_del(&ndl->ndl_hlink);
138 LIBCFS_FREE(nd, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
142 lstcon_ndlink_find(struct list_head *hash,
143 lnet_process_id_t id, lstcon_ndlink_t **ndlpp, int create)
145 unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
146 lstcon_ndlink_t *ndl;
150 if (id.nid == LNET_NID_ANY)
154 list_for_each_entry(ndl, &hash[idx], ndl_hlink) {
155 if (ndl->ndl_node->nd_id.nid != id.nid ||
156 ndl->ndl_node->nd_id.pid != id.pid)
166 /* find or create in session hash */
167 rc = lstcon_node_find(id, &nd, (create == 1) ? 1 : 0);
171 LIBCFS_ALLOC(ndl, sizeof(lstcon_ndlink_t));
180 INIT_LIST_HEAD(&ndl->ndl_link);
181 list_add_tail(&ndl->ndl_hlink, &hash[idx]);
187 lstcon_ndlink_release(lstcon_ndlink_t *ndl)
189 LASSERT(list_empty(&ndl->ndl_link));
190 LASSERT(!list_empty(&ndl->ndl_hlink));
192 list_del(&ndl->ndl_hlink); /* delete from hash */
193 lstcon_node_put(ndl->ndl_node);
195 LIBCFS_FREE(ndl, sizeof(*ndl));
199 lstcon_group_alloc(char *name, lstcon_group_t **grpp)
204 LIBCFS_ALLOC(grp, offsetof(lstcon_group_t,
205 grp_ndl_hash[LST_NODE_HASHSIZE]));
209 memset(grp, 0, offsetof(lstcon_group_t,
210 grp_ndl_hash[LST_NODE_HASHSIZE]));
214 if (strlen(name) > sizeof(grp->grp_name)-1) {
215 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
216 grp_ndl_hash[LST_NODE_HASHSIZE]));
219 strncpy(grp->grp_name, name, sizeof(grp->grp_name));
222 INIT_LIST_HEAD(&grp->grp_link);
223 INIT_LIST_HEAD(&grp->grp_ndl_list);
224 INIT_LIST_HEAD(&grp->grp_trans_list);
226 for (i = 0; i < LST_NODE_HASHSIZE; i++)
227 INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
235 lstcon_group_addref(lstcon_group_t *grp)
240 static void lstcon_group_ndlink_release(lstcon_group_t *, lstcon_ndlink_t *);
243 lstcon_group_drain(lstcon_group_t *grp, int keep)
245 lstcon_ndlink_t *ndl;
246 lstcon_ndlink_t *tmp;
248 list_for_each_entry_safe(ndl, tmp, &grp->grp_ndl_list, ndl_link) {
249 if ((ndl->ndl_node->nd_state & keep) == 0)
250 lstcon_group_ndlink_release(grp, ndl);
255 lstcon_group_decref(lstcon_group_t *grp)
259 if (--grp->grp_ref > 0)
262 if (!list_empty(&grp->grp_link))
263 list_del(&grp->grp_link);
265 lstcon_group_drain(grp, 0);
267 for (i = 0; i < LST_NODE_HASHSIZE; i++)
268 LASSERT(list_empty(&grp->grp_ndl_hash[i]));
270 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
271 grp_ndl_hash[LST_NODE_HASHSIZE]));
275 lstcon_group_find(const char *name, lstcon_group_t **grpp)
279 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
280 if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
283 lstcon_group_addref(grp); /* +1 ref for caller */
292 lstcon_group_put(lstcon_group_t *grp)
294 lstcon_group_decref(grp);
298 lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id,
299 lstcon_ndlink_t **ndlpp, int create)
303 rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
307 if (!list_empty(&(*ndlpp)->ndl_link))
310 list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
317 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
319 list_del_init(&ndl->ndl_link);
320 lstcon_ndlink_release(ndl);
325 lstcon_group_ndlink_move(lstcon_group_t *old,
326 lstcon_group_t *new, lstcon_ndlink_t *ndl)
328 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
331 list_del(&ndl->ndl_hlink);
332 list_del(&ndl->ndl_link);
335 list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
336 list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
343 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
345 lstcon_ndlink_t *ndl;
347 while (!list_empty(&old->grp_ndl_list)) {
348 ndl = list_entry(old->grp_ndl_list.next,
349 lstcon_ndlink_t, ndl_link);
350 lstcon_group_ndlink_move(old, new, ndl);
355 lstcon_sesrpc_condition(int transop, lstcon_node_t *nd, void *arg)
357 lstcon_group_t *grp = (lstcon_group_t *)arg;
360 case LST_TRANS_SESNEW:
361 if (nd->nd_state == LST_NODE_ACTIVE)
365 case LST_TRANS_SESEND:
366 if (nd->nd_state != LST_NODE_ACTIVE)
369 if (grp != NULL && nd->nd_ref > 1)
373 case LST_TRANS_SESQRY:
384 lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
385 lstcon_rpc_ent_t *ent_up)
387 srpc_debug_reply_t *rep;
390 case LST_TRANS_SESNEW:
391 case LST_TRANS_SESEND:
394 case LST_TRANS_SESQRY:
395 rep = &msg->msg_body.dbg_reply;
397 if (copy_to_user(&ent_up->rpe_priv[0],
398 &rep->dbg_timeout, sizeof(int)) ||
399 copy_to_user(&ent_up->rpe_payload[0],
400 &rep->dbg_name, LST_NAME_SIZE))
413 lstcon_group_nodes_add(lstcon_group_t *grp,
414 int count, lnet_process_id_t *ids_up,
415 unsigned *featp, struct list_head *result_up)
417 lstcon_rpc_trans_t *trans;
418 lstcon_ndlink_t *ndl;
420 lnet_process_id_t id;
424 rc = lstcon_group_alloc(NULL, &tmp);
426 CERROR("Out of memory\n");
430 for (i = 0 ; i < count; i++) {
431 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
436 /* skip if it's in this group already */
437 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
441 /* add to tmp group */
442 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
444 CERROR("Can't create ndlink, out of memory\n");
450 lstcon_group_put(tmp);
454 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
455 &tmp->grp_trans_list, LST_TRANS_SESNEW,
456 tmp, lstcon_sesrpc_condition, &trans);
458 CERROR("Can't create transaction: %d\n", rc);
459 lstcon_group_put(tmp);
464 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
466 rc = lstcon_rpc_trans_interpreter(trans, result_up,
467 lstcon_sesrpc_readent);
468 *featp = trans->tas_features;
470 /* destroy all RPGs */
471 lstcon_rpc_trans_destroy(trans);
473 lstcon_group_move(tmp, grp);
474 lstcon_group_put(tmp);
480 lstcon_group_nodes_remove(lstcon_group_t *grp,
481 int count, lnet_process_id_t *ids_up,
482 struct list_head *result_up)
484 lstcon_rpc_trans_t *trans;
485 lstcon_ndlink_t *ndl;
487 lnet_process_id_t id;
491 /* End session and remove node from the group */
493 rc = lstcon_group_alloc(NULL, &tmp);
495 CERROR("Out of memory\n");
499 for (i = 0; i < count; i++) {
500 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
505 /* move node to tmp group */
506 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
507 lstcon_group_ndlink_move(grp, tmp, ndl);
510 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
511 &tmp->grp_trans_list, LST_TRANS_SESEND,
512 tmp, lstcon_sesrpc_condition, &trans);
514 CERROR("Can't create transaction: %d\n", rc);
518 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
520 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
522 lstcon_rpc_trans_destroy(trans);
523 /* release nodes anyway, because we can't rollback status */
524 lstcon_group_put(tmp);
528 lstcon_group_move(tmp, grp);
529 lstcon_group_put(tmp);
535 lstcon_group_add(char *name)
540 rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
542 /* find a group with same name */
543 lstcon_group_put(grp);
547 rc = lstcon_group_alloc(name, &grp);
549 CERROR("Can't allocate descriptor for group %s\n", name);
553 list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
559 lstcon_nodes_add(char *name, int count, lnet_process_id_t *ids_up,
560 unsigned *featp, struct list_head *result_up)
566 LASSERT (ids_up != NULL);
568 rc = lstcon_group_find(name, &grp);
570 CDEBUG(D_NET, "Can't find group %s\n", name);
574 if (grp->grp_ref > 2) {
575 /* referred by other threads or test */
576 CDEBUG(D_NET, "Group %s is busy\n", name);
577 lstcon_group_put(grp);
582 rc = lstcon_group_nodes_add(grp, count, ids_up, featp, result_up);
584 lstcon_group_put(grp);
590 lstcon_group_del(char *name)
592 lstcon_rpc_trans_t *trans;
596 rc = lstcon_group_find(name, &grp);
598 CDEBUG(D_NET, "Can't find group: %s\n", name);
602 if (grp->grp_ref > 2) {
603 /* referred by others threads or test */
604 CDEBUG(D_NET, "Group %s is busy\n", name);
605 lstcon_group_put(grp);
609 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
610 &grp->grp_trans_list, LST_TRANS_SESEND,
611 grp, lstcon_sesrpc_condition, &trans);
613 CERROR("Can't create transaction: %d\n", rc);
614 lstcon_group_put(grp);
618 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
620 lstcon_rpc_trans_destroy(trans);
622 lstcon_group_put(grp);
623 /* -ref for session, it's destroyed,
624 * status can't be rolled back, destroy group anway */
625 lstcon_group_put(grp);
631 lstcon_group_clean(char *name, int args)
633 lstcon_group_t *grp = NULL;
636 rc = lstcon_group_find(name, &grp);
638 CDEBUG(D_NET, "Can't find group %s\n", name);
642 if (grp->grp_ref > 2) {
643 /* referred by test */
644 CDEBUG(D_NET, "Group %s is busy\n", name);
645 lstcon_group_put(grp);
649 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
650 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
652 lstcon_group_drain(grp, args);
654 lstcon_group_put(grp);
655 /* release empty group */
656 if (list_empty(&grp->grp_ndl_list))
657 lstcon_group_put(grp);
663 lstcon_nodes_remove(char *name, int count,
664 lnet_process_id_t *ids_up, struct list_head *result_up)
666 lstcon_group_t *grp = NULL;
669 rc = lstcon_group_find(name, &grp);
671 CDEBUG(D_NET, "Can't find group: %s\n", name);
675 if (grp->grp_ref > 2) {
676 /* referred by test */
677 CDEBUG(D_NET, "Group %s is busy\n", name);
678 lstcon_group_put(grp);
682 rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
684 lstcon_group_put(grp);
685 /* release empty group */
686 if (list_empty(&grp->grp_ndl_list))
687 lstcon_group_put(grp);
693 lstcon_group_refresh(char *name, struct list_head *result_up)
695 lstcon_rpc_trans_t *trans;
699 rc = lstcon_group_find(name, &grp);
701 CDEBUG(D_NET, "Can't find group: %s\n", name);
705 if (grp->grp_ref > 2) {
706 /* referred by test */
707 CDEBUG(D_NET, "Group %s is busy\n", name);
708 lstcon_group_put(grp);
712 /* re-invite all inactive nodes int the group */
713 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
714 &grp->grp_trans_list, LST_TRANS_SESNEW,
715 grp, lstcon_sesrpc_condition, &trans);
717 /* local error, return */
718 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
719 lstcon_group_put(grp);
723 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
725 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
727 lstcon_rpc_trans_destroy(trans);
729 lstcon_group_put(grp);
735 lstcon_group_list(int index, int len, char __user *name_up)
740 LASSERT(name_up != NULL);
742 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
744 return copy_to_user(name_up, grp->grp_name, len) ?
753 lstcon_nodes_getent(struct list_head *head, int *index_p,
754 int *count_p, lstcon_node_ent_t *dents_up)
756 lstcon_ndlink_t *ndl;
761 LASSERT(index_p != NULL && count_p != NULL);
762 LASSERT(dents_up != NULL);
763 LASSERT(*index_p >= 0);
764 LASSERT(*count_p > 0);
766 list_for_each_entry(ndl, head, ndl_link) {
767 if (index++ < *index_p)
770 if (count >= *count_p)
774 if (copy_to_user(&dents_up[count].nde_id,
775 &nd->nd_id, sizeof(nd->nd_id)) ||
776 copy_to_user(&dents_up[count].nde_state,
777 &nd->nd_state, sizeof(nd->nd_state)))
783 if (index <= *index_p)
793 lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p,
794 int *index_p, int *count_p, lstcon_node_ent_t *dents_up)
796 lstcon_ndlist_ent_t *gentp;
798 lstcon_ndlink_t *ndl;
801 rc = lstcon_group_find(name, &grp);
803 CDEBUG(D_NET, "Can't find group %s\n", name);
809 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
810 index_p, count_p, dents_up);
811 lstcon_group_put(grp);
816 /* non-verbose query */
817 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
819 CERROR("Can't allocate ndlist_ent\n");
820 lstcon_group_put(grp);
825 memset(gentp, 0, sizeof(lstcon_ndlist_ent_t));
827 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link)
828 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
830 rc = copy_to_user(gents_p, gentp,
831 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT : 0;
833 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
835 lstcon_group_put(grp);
841 lstcon_batch_find(const char *name, lstcon_batch_t **batpp)
845 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
846 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
856 lstcon_batch_add(char *name)
862 rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
864 CDEBUG(D_NET, "Batch %s already exists\n", name);
868 LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
870 CERROR("Can't allocate descriptor for batch %s\n", name);
874 LIBCFS_ALLOC(bat->bat_cli_hash,
875 sizeof(struct list_head) * LST_NODE_HASHSIZE);
876 if (bat->bat_cli_hash == NULL) {
877 CERROR("Can't allocate hash for batch %s\n", name);
878 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
883 LIBCFS_ALLOC(bat->bat_srv_hash,
884 sizeof(struct list_head) * LST_NODE_HASHSIZE);
885 if (bat->bat_srv_hash == NULL) {
886 CERROR("Can't allocate hash for batch %s\n", name);
887 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
888 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
893 if (strlen(name) > sizeof(bat->bat_name)-1) {
894 LIBCFS_FREE(bat->bat_srv_hash, LST_NODE_HASHSIZE);
895 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
896 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
899 strncpy(bat->bat_name, name, sizeof(bat->bat_name));
900 bat->bat_hdr.tsb_index = 0;
901 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
904 bat->bat_state = LST_BATCH_IDLE;
906 INIT_LIST_HEAD(&bat->bat_cli_list);
907 INIT_LIST_HEAD(&bat->bat_srv_list);
908 INIT_LIST_HEAD(&bat->bat_test_list);
909 INIT_LIST_HEAD(&bat->bat_trans_list);
911 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
912 INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
913 INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
916 list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
922 lstcon_batch_list(int index, int len, char __user *name_up)
926 LASSERT(name_up != NULL);
929 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
931 return copy_to_user(name_up, bat->bat_name, len) ?
940 lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
941 int testidx, int *index_p, int *ndent_p,
942 lstcon_node_ent_t *dents_up)
944 lstcon_test_batch_ent_t *entp;
945 struct list_head *clilst;
946 struct list_head *srvlst;
947 lstcon_test_t *test = NULL;
949 lstcon_ndlink_t *ndl;
952 rc = lstcon_batch_find(name, &bat);
954 CDEBUG(D_NET, "Can't find batch %s\n", name);
959 /* query test, test index start from 1 */
960 list_for_each_entry(test, &bat->bat_test_list, tes_link) {
966 CDEBUG(D_NET, "Can't find specified test in batch\n");
971 clilst = (test == NULL) ? &bat->bat_cli_list :
972 &test->tes_src_grp->grp_ndl_list;
973 srvlst = (test == NULL) ? &bat->bat_srv_list :
974 &test->tes_dst_grp->grp_ndl_list;
976 if (dents_up != NULL) {
977 rc = lstcon_nodes_getent((server ? srvlst: clilst),
978 index_p, ndent_p, dents_up);
982 /* non-verbose query */
983 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
987 memset(entp, 0, sizeof(lstcon_test_batch_ent_t));
990 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
991 entp->u.tbe_batch.bae_state = bat->bat_state;
995 entp->u.tbe_test.tse_type = test->tes_type;
996 entp->u.tbe_test.tse_loop = test->tes_loop;
997 entp->u.tbe_test.tse_concur = test->tes_concur;
1000 list_for_each_entry(ndl, clilst, ndl_link)
1001 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
1003 list_for_each_entry(ndl, srvlst, ndl_link)
1004 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
1006 rc = copy_to_user(ent_up, entp,
1007 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
1009 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
1015 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1018 case LST_TRANS_TSBRUN:
1019 if (nd->nd_state != LST_NODE_ACTIVE)
1023 case LST_TRANS_TSBSTOP:
1024 if (nd->nd_state != LST_NODE_ACTIVE)
1028 case LST_TRANS_TSBCLIQRY:
1029 case LST_TRANS_TSBSRVQRY:
1037 lstcon_batch_op(lstcon_batch_t *bat, int transop,
1038 struct list_head *result_up)
1040 lstcon_rpc_trans_t *trans;
1043 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1044 &bat->bat_trans_list, transop,
1045 bat, lstcon_batrpc_condition, &trans);
1047 CERROR("Can't create transaction: %d\n", rc);
1051 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1053 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1055 lstcon_rpc_trans_destroy(trans);
1061 lstcon_batch_run(char *name, int timeout, struct list_head *result_up)
1063 lstcon_batch_t *bat;
1066 if (lstcon_batch_find(name, &bat) != 0) {
1067 CDEBUG(D_NET, "Can't find batch %s\n", name);
1071 bat->bat_arg = timeout;
1073 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1075 /* mark batch as running if it's started in any node */
1076 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1077 bat->bat_state = LST_BATCH_RUNNING;
1083 lstcon_batch_stop(char *name, int force, struct list_head *result_up)
1085 lstcon_batch_t *bat;
1088 if (lstcon_batch_find(name, &bat) != 0) {
1089 CDEBUG(D_NET, "Can't find batch %s\n", name);
1093 bat->bat_arg = force;
1095 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1097 /* mark batch as stopped if all RPCs finished */
1098 if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1099 bat->bat_state = LST_BATCH_IDLE;
1105 lstcon_batch_destroy(lstcon_batch_t *bat)
1107 lstcon_ndlink_t *ndl;
1108 lstcon_test_t *test;
1111 list_del(&bat->bat_link);
1113 while (!list_empty(&bat->bat_test_list)) {
1114 test = list_entry(bat->bat_test_list.next,
1115 lstcon_test_t, tes_link);
1116 LASSERT(list_empty(&test->tes_trans_list));
1118 list_del(&test->tes_link);
1120 lstcon_group_put(test->tes_src_grp);
1121 lstcon_group_put(test->tes_dst_grp);
1123 LIBCFS_FREE(test, offsetof(lstcon_test_t,
1124 tes_param[test->tes_paramlen]));
1127 LASSERT(list_empty(&bat->bat_trans_list));
1129 while (!list_empty(&bat->bat_cli_list)) {
1130 ndl = list_entry(bat->bat_cli_list.next,
1131 lstcon_ndlink_t, ndl_link);
1132 list_del_init(&ndl->ndl_link);
1134 lstcon_ndlink_release(ndl);
1137 while (!list_empty(&bat->bat_srv_list)) {
1138 ndl = list_entry(bat->bat_srv_list.next,
1139 lstcon_ndlink_t, ndl_link);
1140 list_del_init(&ndl->ndl_link);
1142 lstcon_ndlink_release(ndl);
1145 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1146 LASSERT(list_empty(&bat->bat_cli_hash[i]));
1147 LASSERT(list_empty(&bat->bat_srv_hash[i]));
1150 LIBCFS_FREE(bat->bat_cli_hash,
1151 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1152 LIBCFS_FREE(bat->bat_srv_hash,
1153 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1154 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
1158 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1160 lstcon_test_t *test;
1161 lstcon_batch_t *batch;
1162 lstcon_ndlink_t *ndl;
1163 struct list_head *hash;
1164 struct list_head *head;
1166 test = (lstcon_test_t *)arg;
1167 LASSERT(test != NULL);
1169 batch = test->tes_batch;
1170 LASSERT(batch != NULL);
1172 if (test->tes_oneside &&
1173 transop == LST_TRANS_TSBSRVADD)
1176 if (nd->nd_state != LST_NODE_ACTIVE)
1179 if (transop == LST_TRANS_TSBCLIADD) {
1180 hash = batch->bat_cli_hash;
1181 head = &batch->bat_cli_list;
1184 LASSERT (transop == LST_TRANS_TSBSRVADD);
1186 hash = batch->bat_srv_hash;
1187 head = &batch->bat_srv_list;
1190 LASSERT (nd->nd_id.nid != LNET_NID_ANY);
1192 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1195 if (list_empty(&ndl->ndl_link))
1196 list_add_tail(&ndl->ndl_link, head);
1202 lstcon_test_nodes_add(lstcon_test_t *test, struct list_head *result_up)
1204 lstcon_rpc_trans_t *trans;
1205 lstcon_group_t *grp;
1209 LASSERT (test->tes_src_grp != NULL);
1210 LASSERT (test->tes_dst_grp != NULL);
1212 transop = LST_TRANS_TSBSRVADD;
1213 grp = test->tes_dst_grp;
1215 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1216 &test->tes_trans_list, transop,
1217 test, lstcon_testrpc_condition, &trans);
1219 CERROR("Can't create transaction: %d\n", rc);
1223 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1225 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1226 lstcon_trans_stat()->trs_fwk_errno != 0) {
1227 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1229 lstcon_rpc_trans_destroy(trans);
1230 /* return if any error */
1231 CDEBUG(D_NET, "Failed to add test %s, "
1232 "RPC error %d, framework error %d\n",
1233 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1234 lstcon_trans_stat()->trs_rpc_errno,
1235 lstcon_trans_stat()->trs_fwk_errno);
1240 lstcon_rpc_trans_destroy(trans);
1242 if (transop == LST_TRANS_TSBCLIADD)
1245 transop = LST_TRANS_TSBCLIADD;
1246 grp = test->tes_src_grp;
1247 test->tes_cliidx = 0;
1249 /* requests to test clients */
1254 lstcon_verify_batch(const char *name, lstcon_batch_t **batch)
1258 rc = lstcon_batch_find(name, batch);
1260 CDEBUG(D_NET, "Can't find batch %s\n", name);
1264 if ((*batch)->bat_state != LST_BATCH_IDLE) {
1265 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1273 lstcon_verify_group(const char *name, lstcon_group_t **grp)
1276 lstcon_ndlink_t *ndl;
1278 rc = lstcon_group_find(name, grp);
1280 CDEBUG(D_NET, "can't find group %s\n", name);
1284 list_for_each_entry(ndl, &(*grp)->grp_ndl_list, ndl_link) {
1285 if (ndl->ndl_node->nd_state == LST_NODE_ACTIVE) {
1290 CDEBUG(D_NET, "Group %s has no ACTIVE nodes\n", name);
1296 lstcon_test_add(char *batch_name, int type, int loop,
1297 int concur, int dist, int span,
1298 char *src_name, char *dst_name,
1299 void *param, int paramlen, int *retp,
1300 struct list_head *result_up)
1302 lstcon_test_t *test = NULL;
1304 lstcon_group_t *src_grp = NULL;
1305 lstcon_group_t *dst_grp = NULL;
1306 lstcon_batch_t *batch = NULL;
1309 * verify that a batch of the given name exists, and the groups
1310 * that will be part of the batch exist and have at least one
1313 rc = lstcon_verify_batch(batch_name, &batch);
1317 rc = lstcon_verify_group(src_name, &src_grp);
1321 rc = lstcon_verify_group(dst_name, &dst_grp);
1325 if (dst_grp->grp_userland)
1328 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1330 CERROR("Can't allocate test descriptor\n");
1336 memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen]));
1337 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1338 test->tes_batch = batch;
1339 test->tes_type = type;
1340 test->tes_oneside = 0; /* TODO */
1341 test->tes_loop = loop;
1342 test->tes_concur = concur;
1343 test->tes_stop_onerr = 1; /* TODO */
1344 test->tes_span = span;
1345 test->tes_dist = dist;
1346 test->tes_cliidx = 0; /* just used for creating RPC */
1347 test->tes_src_grp = src_grp;
1348 test->tes_dst_grp = dst_grp;
1349 INIT_LIST_HEAD(&test->tes_trans_list);
1351 if (param != NULL) {
1352 test->tes_paramlen = paramlen;
1353 memcpy(&test->tes_param[0], param, paramlen);
1356 rc = lstcon_test_nodes_add(test, result_up);
1361 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1362 lstcon_trans_stat()->trs_fwk_errno != 0)
1363 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type,
1366 /* add to test list anyway, so user can check what's going on */
1367 list_add_tail(&test->tes_link, &batch->bat_test_list);
1370 test->tes_hdr.tsb_index = batch->bat_ntest;
1372 /* hold groups so nobody can change them */
1376 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1378 if (dst_grp != NULL)
1379 lstcon_group_put(dst_grp);
1381 if (src_grp != NULL)
1382 lstcon_group_put(src_grp);
1388 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1390 lstcon_test_t *test;
1392 list_for_each_entry(test, &batch->bat_test_list, tes_link) {
1393 if (idx == test->tes_hdr.tsb_index) {
1403 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1404 lstcon_rpc_ent_t *ent_up)
1406 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1408 LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1409 transop == LST_TRANS_TSBSRVQRY);
1411 /* positive errno, framework error code */
1412 if (copy_to_user(&ent_up->rpe_priv[0],
1413 &rep->bar_active, sizeof(rep->bar_active)))
1420 lstcon_test_batch_query(char *name, int testidx, int client,
1421 int timeout, struct list_head *result_up)
1423 lstcon_rpc_trans_t *trans;
1424 struct list_head *translist;
1425 struct list_head *ndlist;
1426 lstcon_tsb_hdr_t *hdr;
1427 lstcon_batch_t *batch;
1428 lstcon_test_t *test = NULL;
1432 rc = lstcon_batch_find(name, &batch);
1434 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1439 translist = &batch->bat_trans_list;
1440 ndlist = &batch->bat_cli_list;
1441 hdr = &batch->bat_hdr;
1444 /* query specified test only */
1445 rc = lstcon_test_find(batch, testidx, &test);
1447 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1451 translist = &test->tes_trans_list;
1452 ndlist = &test->tes_src_grp->grp_ndl_list;
1453 hdr = &test->tes_hdr;
1456 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1458 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1459 lstcon_batrpc_condition, &trans);
1461 CERROR("Can't create transaction: %d\n", rc);
1465 lstcon_rpc_trans_postwait(trans, timeout);
1467 if (testidx == 0 && /* query a batch, not a test */
1468 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1469 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1470 /* all RPCs finished, and no active test */
1471 batch->bat_state = LST_BATCH_IDLE;
1474 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1475 lstcon_tsbrpc_readent);
1476 lstcon_rpc_trans_destroy(trans);
1482 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1483 lstcon_rpc_ent_t *ent_up)
1485 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1486 sfw_counters_t *sfwk_stat;
1487 srpc_counters_t *srpc_stat;
1488 lnet_counters_t *lnet_stat;
1490 if (rep->str_status != 0)
1493 sfwk_stat = (sfw_counters_t *)&ent_up->rpe_payload[0];
1494 srpc_stat = (srpc_counters_t *)((char *)sfwk_stat + sizeof(*sfwk_stat));
1495 lnet_stat = (lnet_counters_t *)((char *)srpc_stat + sizeof(*srpc_stat));
1497 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1498 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1499 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1506 lstcon_ndlist_stat(struct list_head *ndlist,
1507 int timeout, struct list_head *result_up)
1509 struct list_head head;
1510 lstcon_rpc_trans_t *trans;
1513 INIT_LIST_HEAD(&head);
1515 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1516 LST_TRANS_STATQRY, NULL, NULL, &trans);
1518 CERROR("Can't create transaction: %d\n", rc);
1522 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1524 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1525 lstcon_statrpc_readent);
1526 lstcon_rpc_trans_destroy(trans);
1532 lstcon_group_stat(char *grp_name, int timeout, struct list_head *result_up)
1534 lstcon_group_t *grp;
1537 rc = lstcon_group_find(grp_name, &grp);
1539 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1543 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1545 lstcon_group_put(grp);
1551 lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
1552 int timeout, struct list_head *result_up)
1554 lstcon_ndlink_t *ndl;
1555 lstcon_group_t *tmp;
1556 lnet_process_id_t id;
1560 rc = lstcon_group_alloc(NULL, &tmp);
1562 CERROR("Out of memory\n");
1566 for (i = 0 ; i < count; i++) {
1567 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1572 /* add to tmp group */
1573 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1575 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1576 "Failed to find or create %s: %d\n",
1577 libcfs_id2str(id), rc);
1583 lstcon_group_put(tmp);
1587 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1589 lstcon_group_put(tmp);
1595 lstcon_debug_ndlist(struct list_head *ndlist,
1596 struct list_head *translist,
1597 int timeout, struct list_head *result_up)
1599 lstcon_rpc_trans_t *trans;
1602 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1603 NULL, lstcon_sesrpc_condition, &trans);
1605 CERROR("Can't create transaction: %d\n", rc);
1609 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1611 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1612 lstcon_sesrpc_readent);
1613 lstcon_rpc_trans_destroy(trans);
1619 lstcon_session_debug(int timeout, struct list_head *result_up)
1621 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1622 NULL, timeout, result_up);
1626 lstcon_batch_debug(int timeout, char *name,
1627 int client, struct list_head *result_up)
1629 lstcon_batch_t *bat;
1632 rc = lstcon_batch_find(name, &bat);
1636 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1638 NULL, timeout, result_up);
1644 lstcon_group_debug(int timeout, char *name,
1645 struct list_head *result_up)
1647 lstcon_group_t *grp;
1650 rc = lstcon_group_find(name, &grp);
1654 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1655 timeout, result_up);
1656 lstcon_group_put(grp);
1662 lstcon_nodes_debug(int timeout,
1663 int count, lnet_process_id_t *ids_up,
1664 struct list_head *result_up)
1666 lnet_process_id_t id;
1667 lstcon_ndlink_t *ndl;
1668 lstcon_group_t *grp;
1672 rc = lstcon_group_alloc(NULL, &grp);
1674 CDEBUG(D_NET, "Out of memory\n");
1678 for (i = 0; i < count; i++) {
1679 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1684 /* node is added to tmp group */
1685 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1687 CERROR("Can't create node link\n");
1693 lstcon_group_put(grp);
1697 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1698 timeout, result_up);
1700 lstcon_group_put(grp);
1706 lstcon_session_match(lst_sid_t sid)
1708 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1709 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1: 0;
1713 lstcon_new_session_id(lst_sid_t *sid)
1715 lnet_process_id_t id;
1717 LASSERT (console_session.ses_state == LST_SESSION_NONE);
1720 sid->ses_nid = id.nid;
1721 sid->ses_stamp = cfs_time_current();
1724 extern srpc_service_t lstcon_acceptor_service;
1727 lstcon_session_new(char *name, int key, unsigned feats,
1728 int timeout, int force, lst_sid_t *sid_up)
1733 if (console_session.ses_state != LST_SESSION_NONE) {
1734 /* session exists */
1736 CNETERR("Session %s already exists\n",
1737 console_session.ses_name);
1741 rc = lstcon_session_end();
1743 /* lstcon_session_end() only return local error */
1748 if ((feats & ~LST_FEATS_MASK) != 0) {
1749 CNETERR("Unknown session features %x\n",
1750 (feats & ~LST_FEATS_MASK));
1754 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1755 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
1757 lstcon_new_session_id(&console_session.ses_id);
1759 console_session.ses_key = key;
1760 console_session.ses_state = LST_SESSION_ACTIVE;
1761 console_session.ses_force = !!force;
1762 console_session.ses_features = feats;
1763 console_session.ses_feats_updated = 0;
1764 console_session.ses_timeout = (timeout <= 0) ?
1765 LST_CONSOLE_TIMEOUT : timeout;
1767 if (strlen(name) > sizeof(console_session.ses_name)-1)
1769 strlcpy(console_session.ses_name, name,
1770 sizeof(console_session.ses_name));
1772 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1776 rc = lstcon_rpc_pinger_start();
1778 lstcon_batch_t *bat = NULL;
1780 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1781 lstcon_batch_destroy(bat);
1786 if (copy_to_user(sid_up, &console_session.ses_id,
1787 sizeof(lst_sid_t)) == 0)
1790 lstcon_session_end();
1796 lstcon_session_info(lst_sid_t *sid_up, int *key_up, unsigned *featp,
1797 lstcon_ndlist_ent_t *ndinfo_up, char *name_up, int len)
1799 lstcon_ndlist_ent_t *entp;
1800 lstcon_ndlink_t *ndl;
1803 if (console_session.ses_state != LST_SESSION_ACTIVE)
1806 LIBCFS_ALLOC(entp, sizeof(*entp));
1810 memset(entp, 0, sizeof(*entp));
1812 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link)
1813 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1815 if (copy_to_user(sid_up, &console_session.ses_id,
1816 sizeof(lst_sid_t)) ||
1817 copy_to_user(key_up, &console_session.ses_key,
1819 copy_to_user(featp, &console_session.ses_features,
1821 copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1822 copy_to_user(name_up, console_session.ses_name, len))
1825 LIBCFS_FREE(entp, sizeof(*entp));
1831 lstcon_session_end()
1833 lstcon_rpc_trans_t *trans;
1834 lstcon_group_t *grp;
1835 lstcon_batch_t *bat;
1838 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1840 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1841 NULL, LST_TRANS_SESEND, NULL,
1842 lstcon_sesrpc_condition, &trans);
1844 CERROR("Can't create transaction: %d\n", rc);
1848 console_session.ses_shutdown = 1;
1850 lstcon_rpc_pinger_stop();
1852 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1854 lstcon_rpc_trans_destroy(trans);
1855 /* User can do nothing even rpc failed, so go on */
1857 /* waiting for orphan rpcs to die */
1858 lstcon_rpc_cleanup_wait();
1860 console_session.ses_id = LST_INVALID_SID;
1861 console_session.ses_state = LST_SESSION_NONE;
1862 console_session.ses_key = 0;
1863 console_session.ses_force = 0;
1864 console_session.ses_feats_updated = 0;
1866 /* destroy all batches */
1867 while (!list_empty(&console_session.ses_bat_list)) {
1868 bat = list_entry(console_session.ses_bat_list.next,
1869 lstcon_batch_t, bat_link);
1871 lstcon_batch_destroy(bat);
1874 /* destroy all groups */
1875 while (!list_empty(&console_session.ses_grp_list)) {
1876 grp = list_entry(console_session.ses_grp_list.next,
1877 lstcon_group_t, grp_link);
1878 LASSERT(grp->grp_ref == 1);
1880 lstcon_group_put(grp);
1883 /* all nodes should be released */
1884 LASSERT(list_empty(&console_session.ses_ndl_list));
1886 console_session.ses_shutdown = 0;
1887 console_session.ses_expired = 0;
1893 lstcon_session_feats_check(unsigned feats)
1897 if ((feats & ~LST_FEATS_MASK) != 0) {
1898 CERROR("Can't support these features: %x\n",
1899 (feats & ~LST_FEATS_MASK));
1903 spin_lock(&console_session.ses_rpc_lock);
1905 if (!console_session.ses_feats_updated) {
1906 console_session.ses_feats_updated = 1;
1907 console_session.ses_features = feats;
1910 if (console_session.ses_features != feats)
1913 spin_unlock(&console_session.ses_rpc_lock);
1916 CERROR("remote features %x do not match with "
1917 "session features %x of console\n",
1918 feats, console_session.ses_features);
1925 lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
1927 srpc_msg_t *rep = &rpc->srpc_replymsg;
1928 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1929 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1930 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1931 lstcon_group_t *grp = NULL;
1932 lstcon_ndlink_t *ndl;
1935 sfw_unpack_message(req);
1937 mutex_lock(&console_session.ses_mutex);
1939 jrep->join_sid = console_session.ses_id;
1941 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1942 jrep->join_status = ESRCH;
1946 if (lstcon_session_feats_check(req->msg_ses_feats) != 0) {
1947 jrep->join_status = EPROTO;
1951 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1952 !lstcon_session_match(jreq->join_sid)) {
1953 jrep->join_status = EBUSY;
1957 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1958 rc = lstcon_group_alloc(jreq->join_group, &grp);
1960 CERROR("Out of memory\n");
1964 list_add_tail(&grp->grp_link,
1965 &console_session.ses_grp_list);
1966 lstcon_group_addref(grp);
1969 if (grp->grp_ref > 2) {
1970 /* Group in using */
1971 jrep->join_status = EBUSY;
1975 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1977 jrep->join_status = EEXIST;
1981 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1983 CERROR("Out of memory\n");
1987 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1988 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1990 if (grp->grp_userland == 0)
1991 grp->grp_userland = 1;
1993 strlcpy(jrep->join_session, console_session.ses_name,
1994 sizeof(jrep->join_session));
1995 jrep->join_timeout = console_session.ses_timeout;
1996 jrep->join_status = 0;
1999 rep->msg_ses_feats = console_session.ses_features;
2001 lstcon_group_put(grp);
2003 mutex_unlock(&console_session.ses_mutex);
2008 srpc_service_t lstcon_acceptor_service;
2009 void lstcon_init_acceptor_service(void)
2011 /* initialize selftest console acceptor service table */
2012 lstcon_acceptor_service.sv_name = "join session";
2013 lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
2014 lstcon_acceptor_service.sv_id = SRPC_SERVICE_JOIN;
2015 lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX;
2018 extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
2020 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
2022 /* initialize console */
2024 lstcon_console_init(void)
2029 memset(&console_session, 0, sizeof(lstcon_session_t));
2031 console_session.ses_id = LST_INVALID_SID;
2032 console_session.ses_state = LST_SESSION_NONE;
2033 console_session.ses_timeout = 0;
2034 console_session.ses_force = 0;
2035 console_session.ses_expired = 0;
2036 console_session.ses_feats_updated = 0;
2037 console_session.ses_features = LST_FEATS_MASK;
2038 console_session.ses_laststamp = cfs_time_current_sec();
2040 mutex_init(&console_session.ses_mutex);
2042 INIT_LIST_HEAD(&console_session.ses_ndl_list);
2043 INIT_LIST_HEAD(&console_session.ses_grp_list);
2044 INIT_LIST_HEAD(&console_session.ses_bat_list);
2045 INIT_LIST_HEAD(&console_session.ses_trans_list);
2047 LIBCFS_ALLOC(console_session.ses_ndl_hash,
2048 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2049 if (console_session.ses_ndl_hash == NULL)
2052 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
2053 INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
2056 /* initialize acceptor service table */
2057 lstcon_init_acceptor_service();
2059 rc = srpc_add_service(&lstcon_acceptor_service);
2060 LASSERT(rc != -EBUSY);
2062 LIBCFS_FREE(console_session.ses_ndl_hash,
2063 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2067 rc = srpc_service_add_buffers(&lstcon_acceptor_service,
2068 lstcon_acceptor_service.sv_wi_total);
2074 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
2077 lstcon_rpc_module_init();
2082 srpc_shutdown_service(&lstcon_acceptor_service);
2083 srpc_remove_service(&lstcon_acceptor_service);
2085 LIBCFS_FREE(console_session.ses_ndl_hash,
2086 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2088 srpc_wait_service_shutdown(&lstcon_acceptor_service);
2094 lstcon_console_fini(void)
2098 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
2100 mutex_lock(&console_session.ses_mutex);
2102 srpc_shutdown_service(&lstcon_acceptor_service);
2103 srpc_remove_service(&lstcon_acceptor_service);
2105 if (console_session.ses_state != LST_SESSION_NONE)
2106 lstcon_session_end();
2108 lstcon_rpc_module_fini();
2110 mutex_unlock(&console_session.ses_mutex);
2112 LASSERT(list_empty(&console_session.ses_ndl_list));
2113 LASSERT(list_empty(&console_session.ses_grp_list));
2114 LASSERT(list_empty(&console_session.ses_bat_list));
2115 LASSERT(list_empty(&console_session.ses_trans_list));
2117 for (i = 0; i < LST_NODE_HASHSIZE; i++)
2118 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
2120 LIBCFS_FREE(console_session.ses_ndl_hash,
2121 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2123 srpc_wait_service_shutdown(&lstcon_acceptor_service);