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]));
208 memset(grp, 0, offsetof(lstcon_group_t,
209 grp_ndl_hash[LST_NODE_HASHSIZE]));
213 if (strlen(name) > sizeof(grp->grp_name)-1) {
214 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
215 grp_ndl_hash[LST_NODE_HASHSIZE]));
218 strncpy(grp->grp_name, name, sizeof(grp->grp_name));
221 INIT_LIST_HEAD(&grp->grp_link);
222 INIT_LIST_HEAD(&grp->grp_ndl_list);
223 INIT_LIST_HEAD(&grp->grp_trans_list);
225 for (i = 0; i < LST_NODE_HASHSIZE; i++)
226 INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
234 lstcon_group_addref(lstcon_group_t *grp)
239 static void lstcon_group_ndlink_release(lstcon_group_t *, lstcon_ndlink_t *);
242 lstcon_group_drain(lstcon_group_t *grp, int keep)
244 lstcon_ndlink_t *ndl;
245 lstcon_ndlink_t *tmp;
247 list_for_each_entry_safe(ndl, tmp, &grp->grp_ndl_list, ndl_link) {
248 if ((ndl->ndl_node->nd_state & keep) == 0)
249 lstcon_group_ndlink_release(grp, ndl);
254 lstcon_group_decref(lstcon_group_t *grp)
258 if (--grp->grp_ref > 0)
261 if (!list_empty(&grp->grp_link))
262 list_del(&grp->grp_link);
264 lstcon_group_drain(grp, 0);
266 for (i = 0; i < LST_NODE_HASHSIZE; i++)
267 LASSERT(list_empty(&grp->grp_ndl_hash[i]));
269 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
270 grp_ndl_hash[LST_NODE_HASHSIZE]));
274 lstcon_group_find(const char *name, lstcon_group_t **grpp)
278 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
279 if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
282 lstcon_group_addref(grp); /* +1 ref for caller */
291 lstcon_group_put(lstcon_group_t *grp)
293 lstcon_group_decref(grp);
297 lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id,
298 lstcon_ndlink_t **ndlpp, int create)
302 rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
306 if (!list_empty(&(*ndlpp)->ndl_link))
309 list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
316 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
318 list_del_init(&ndl->ndl_link);
319 lstcon_ndlink_release(ndl);
324 lstcon_group_ndlink_move(lstcon_group_t *old,
325 lstcon_group_t *new, lstcon_ndlink_t *ndl)
327 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
330 list_del(&ndl->ndl_hlink);
331 list_del(&ndl->ndl_link);
334 list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
335 list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
342 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
344 lstcon_ndlink_t *ndl;
346 while (!list_empty(&old->grp_ndl_list)) {
347 ndl = list_entry(old->grp_ndl_list.next,
348 lstcon_ndlink_t, ndl_link);
349 lstcon_group_ndlink_move(old, new, ndl);
354 lstcon_sesrpc_condition(int transop, lstcon_node_t *nd, void *arg)
356 lstcon_group_t *grp = (lstcon_group_t *)arg;
359 case LST_TRANS_SESNEW:
360 if (nd->nd_state == LST_NODE_ACTIVE)
364 case LST_TRANS_SESEND:
365 if (nd->nd_state != LST_NODE_ACTIVE)
368 if (grp != NULL && nd->nd_ref > 1)
372 case LST_TRANS_SESQRY:
383 lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
384 lstcon_rpc_ent_t __user *ent_up)
386 srpc_debug_reply_t *rep;
389 case LST_TRANS_SESNEW:
390 case LST_TRANS_SESEND:
393 case LST_TRANS_SESQRY:
394 rep = &msg->msg_body.dbg_reply;
396 if (copy_to_user(&ent_up->rpe_priv[0],
397 &rep->dbg_timeout, sizeof(int)) ||
398 copy_to_user(&ent_up->rpe_payload[0],
399 &rep->dbg_name, LST_NAME_SIZE))
412 lstcon_group_nodes_add(lstcon_group_t *grp,
413 int count, lnet_process_id_t __user *ids_up,
414 unsigned *featp, struct list_head __user *result_up)
416 lstcon_rpc_trans_t *trans;
417 lstcon_ndlink_t *ndl;
419 lnet_process_id_t id;
423 rc = lstcon_group_alloc(NULL, &tmp);
425 CERROR("Out of memory\n");
429 for (i = 0 ; i < count; i++) {
430 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
435 /* skip if it's in this group already */
436 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
440 /* add to tmp group */
441 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
443 CERROR("Can't create ndlink, out of memory\n");
449 lstcon_group_put(tmp);
453 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
454 &tmp->grp_trans_list, LST_TRANS_SESNEW,
455 tmp, lstcon_sesrpc_condition, &trans);
457 CERROR("Can't create transaction: %d\n", rc);
458 lstcon_group_put(tmp);
463 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
465 rc = lstcon_rpc_trans_interpreter(trans, result_up,
466 lstcon_sesrpc_readent);
467 *featp = trans->tas_features;
469 /* destroy all RPGs */
470 lstcon_rpc_trans_destroy(trans);
472 lstcon_group_move(tmp, grp);
473 lstcon_group_put(tmp);
479 lstcon_group_nodes_remove(lstcon_group_t *grp,
480 int count, lnet_process_id_t __user *ids_up,
481 struct list_head __user *result_up)
483 lstcon_rpc_trans_t *trans;
484 lstcon_ndlink_t *ndl;
486 lnet_process_id_t id;
490 /* End session and remove node from the group */
492 rc = lstcon_group_alloc(NULL, &tmp);
494 CERROR("Out of memory\n");
498 for (i = 0; i < count; i++) {
499 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
504 /* move node to tmp group */
505 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
506 lstcon_group_ndlink_move(grp, tmp, ndl);
509 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
510 &tmp->grp_trans_list, LST_TRANS_SESEND,
511 tmp, lstcon_sesrpc_condition, &trans);
513 CERROR("Can't create transaction: %d\n", rc);
517 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
519 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
521 lstcon_rpc_trans_destroy(trans);
522 /* release nodes anyway, because we can't rollback status */
523 lstcon_group_put(tmp);
527 lstcon_group_move(tmp, grp);
528 lstcon_group_put(tmp);
534 lstcon_group_add(char *name)
539 rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
541 /* find a group with same name */
542 lstcon_group_put(grp);
546 rc = lstcon_group_alloc(name, &grp);
548 CERROR("Can't allocate descriptor for group %s\n", name);
552 list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
558 lstcon_nodes_add(char *name, int count, lnet_process_id_t __user *ids_up,
559 unsigned *featp, struct list_head __user *result_up)
565 LASSERT (ids_up != NULL);
567 rc = lstcon_group_find(name, &grp);
569 CDEBUG(D_NET, "Can't find group %s\n", name);
573 if (grp->grp_ref > 2) {
574 /* referred by other threads or test */
575 CDEBUG(D_NET, "Group %s is busy\n", name);
576 lstcon_group_put(grp);
581 rc = lstcon_group_nodes_add(grp, count, ids_up, featp, result_up);
583 lstcon_group_put(grp);
589 lstcon_group_del(char *name)
591 lstcon_rpc_trans_t *trans;
595 rc = lstcon_group_find(name, &grp);
597 CDEBUG(D_NET, "Can't find group: %s\n", name);
601 if (grp->grp_ref > 2) {
602 /* referred by others threads or test */
603 CDEBUG(D_NET, "Group %s is busy\n", name);
604 lstcon_group_put(grp);
608 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
609 &grp->grp_trans_list, LST_TRANS_SESEND,
610 grp, lstcon_sesrpc_condition, &trans);
612 CERROR("Can't create transaction: %d\n", rc);
613 lstcon_group_put(grp);
617 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
619 lstcon_rpc_trans_destroy(trans);
621 lstcon_group_put(grp);
622 /* -ref for session, it's destroyed,
623 * status can't be rolled back, destroy group anway */
624 lstcon_group_put(grp);
630 lstcon_group_clean(char *name, int args)
632 lstcon_group_t *grp = NULL;
635 rc = lstcon_group_find(name, &grp);
637 CDEBUG(D_NET, "Can't find group %s\n", name);
641 if (grp->grp_ref > 2) {
642 /* referred by test */
643 CDEBUG(D_NET, "Group %s is busy\n", name);
644 lstcon_group_put(grp);
648 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
649 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
651 lstcon_group_drain(grp, args);
653 lstcon_group_put(grp);
654 /* release empty group */
655 if (list_empty(&grp->grp_ndl_list))
656 lstcon_group_put(grp);
662 lstcon_nodes_remove(char *name, int count,
663 lnet_process_id_t __user *ids_up,
664 struct list_head __user *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 __user *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 __user *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 __user *gents_p,
794 int *index_p, int *count_p,
795 lstcon_node_ent_t __user *dents_up)
797 lstcon_ndlist_ent_t *gentp;
799 lstcon_ndlink_t *ndl;
802 rc = lstcon_group_find(name, &grp);
804 CDEBUG(D_NET, "Can't find group %s\n", name);
808 if (dents_up != NULL) {
810 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
811 index_p, count_p, dents_up);
812 lstcon_group_put(grp);
817 /* non-verbose query */
818 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
820 CERROR("Can't allocate ndlist_ent\n");
821 lstcon_group_put(grp);
826 memset(gentp, 0, sizeof(lstcon_ndlist_ent_t));
828 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link)
829 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
831 rc = copy_to_user(gents_p, gentp,
832 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT : 0;
834 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
836 lstcon_group_put(grp);
842 lstcon_batch_find(const char *name, lstcon_batch_t **batpp)
846 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
847 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
857 lstcon_batch_add(char *name)
863 rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
865 CDEBUG(D_NET, "Batch %s already exists\n", name);
869 LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
871 CERROR("Can't allocate descriptor for batch %s\n", name);
875 LIBCFS_ALLOC(bat->bat_cli_hash,
876 sizeof(struct list_head) * LST_NODE_HASHSIZE);
877 if (bat->bat_cli_hash == NULL) {
878 CERROR("Can't allocate hash for batch %s\n", name);
879 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
884 LIBCFS_ALLOC(bat->bat_srv_hash,
885 sizeof(struct list_head) * LST_NODE_HASHSIZE);
886 if (bat->bat_srv_hash == NULL) {
887 CERROR("Can't allocate hash for batch %s\n", name);
888 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
889 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
894 if (strlen(name) > sizeof(bat->bat_name)-1) {
895 LIBCFS_FREE(bat->bat_srv_hash, LST_NODE_HASHSIZE);
896 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
897 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
900 strncpy(bat->bat_name, name, sizeof(bat->bat_name));
901 bat->bat_hdr.tsb_index = 0;
902 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
905 bat->bat_state = LST_BATCH_IDLE;
907 INIT_LIST_HEAD(&bat->bat_cli_list);
908 INIT_LIST_HEAD(&bat->bat_srv_list);
909 INIT_LIST_HEAD(&bat->bat_test_list);
910 INIT_LIST_HEAD(&bat->bat_trans_list);
912 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
913 INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
914 INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
917 list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
923 lstcon_batch_list(int index, int len, char __user *name_up)
927 LASSERT(name_up != NULL);
930 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
932 return copy_to_user(name_up, bat->bat_name, len) ?
941 lstcon_batch_info(char *name, lstcon_test_batch_ent_t __user *ent_up,
942 int server, int testidx, int *index_p, int *ndent_p,
943 lstcon_node_ent_t __user *dents_up)
945 lstcon_test_batch_ent_t *entp;
946 struct list_head *clilst;
947 struct list_head *srvlst;
948 lstcon_test_t *test = NULL;
950 lstcon_ndlink_t *ndl;
953 rc = lstcon_batch_find(name, &bat);
955 CDEBUG(D_NET, "Can't find batch %s\n", name);
960 /* query test, test index start from 1 */
961 list_for_each_entry(test, &bat->bat_test_list, tes_link) {
967 CDEBUG(D_NET, "Can't find specified test in batch\n");
972 clilst = (test == NULL) ? &bat->bat_cli_list :
973 &test->tes_src_grp->grp_ndl_list;
974 srvlst = (test == NULL) ? &bat->bat_srv_list :
975 &test->tes_dst_grp->grp_ndl_list;
977 if (dents_up != NULL) {
978 rc = lstcon_nodes_getent((server ? srvlst: clilst),
979 index_p, ndent_p, dents_up);
983 /* non-verbose query */
984 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
988 memset(entp, 0, sizeof(lstcon_test_batch_ent_t));
991 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
992 entp->u.tbe_batch.bae_state = bat->bat_state;
996 entp->u.tbe_test.tse_type = test->tes_type;
997 entp->u.tbe_test.tse_loop = test->tes_loop;
998 entp->u.tbe_test.tse_concur = test->tes_concur;
1001 list_for_each_entry(ndl, clilst, ndl_link)
1002 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
1004 list_for_each_entry(ndl, srvlst, ndl_link)
1005 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
1007 rc = copy_to_user(ent_up, entp,
1008 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
1010 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
1016 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1019 case LST_TRANS_TSBRUN:
1020 if (nd->nd_state != LST_NODE_ACTIVE)
1024 case LST_TRANS_TSBSTOP:
1025 if (nd->nd_state != LST_NODE_ACTIVE)
1029 case LST_TRANS_TSBCLIQRY:
1030 case LST_TRANS_TSBSRVQRY:
1038 lstcon_batch_op(lstcon_batch_t *bat, int transop,
1039 struct list_head __user *result_up)
1041 lstcon_rpc_trans_t *trans;
1044 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1045 &bat->bat_trans_list, transop,
1046 bat, lstcon_batrpc_condition, &trans);
1048 CERROR("Can't create transaction: %d\n", rc);
1052 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1054 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1056 lstcon_rpc_trans_destroy(trans);
1062 lstcon_batch_run(char *name, int timeout, struct list_head __user *result_up)
1064 lstcon_batch_t *bat;
1067 if (lstcon_batch_find(name, &bat) != 0) {
1068 CDEBUG(D_NET, "Can't find batch %s\n", name);
1072 bat->bat_arg = timeout;
1074 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1076 /* mark batch as running if it's started in any node */
1077 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1078 bat->bat_state = LST_BATCH_RUNNING;
1084 lstcon_batch_stop(char *name, int force, struct list_head __user *result_up)
1086 lstcon_batch_t *bat;
1089 if (lstcon_batch_find(name, &bat) != 0) {
1090 CDEBUG(D_NET, "Can't find batch %s\n", name);
1094 bat->bat_arg = force;
1096 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1098 /* mark batch as stopped if all RPCs finished */
1099 if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1100 bat->bat_state = LST_BATCH_IDLE;
1106 lstcon_batch_destroy(lstcon_batch_t *bat)
1108 lstcon_ndlink_t *ndl;
1109 lstcon_test_t *test;
1112 list_del(&bat->bat_link);
1114 while (!list_empty(&bat->bat_test_list)) {
1115 test = list_entry(bat->bat_test_list.next,
1116 lstcon_test_t, tes_link);
1117 LASSERT(list_empty(&test->tes_trans_list));
1119 list_del(&test->tes_link);
1121 lstcon_group_put(test->tes_src_grp);
1122 lstcon_group_put(test->tes_dst_grp);
1124 LIBCFS_FREE(test, offsetof(lstcon_test_t,
1125 tes_param[test->tes_paramlen]));
1128 LASSERT(list_empty(&bat->bat_trans_list));
1130 while (!list_empty(&bat->bat_cli_list)) {
1131 ndl = list_entry(bat->bat_cli_list.next,
1132 lstcon_ndlink_t, ndl_link);
1133 list_del_init(&ndl->ndl_link);
1135 lstcon_ndlink_release(ndl);
1138 while (!list_empty(&bat->bat_srv_list)) {
1139 ndl = list_entry(bat->bat_srv_list.next,
1140 lstcon_ndlink_t, ndl_link);
1141 list_del_init(&ndl->ndl_link);
1143 lstcon_ndlink_release(ndl);
1146 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1147 LASSERT(list_empty(&bat->bat_cli_hash[i]));
1148 LASSERT(list_empty(&bat->bat_srv_hash[i]));
1151 LIBCFS_FREE(bat->bat_cli_hash,
1152 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1153 LIBCFS_FREE(bat->bat_srv_hash,
1154 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1155 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
1159 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1161 lstcon_test_t *test;
1162 lstcon_batch_t *batch;
1163 lstcon_ndlink_t *ndl;
1164 struct list_head *hash;
1165 struct list_head *head;
1167 test = (lstcon_test_t *)arg;
1168 LASSERT(test != NULL);
1170 batch = test->tes_batch;
1171 LASSERT(batch != NULL);
1173 if (test->tes_oneside &&
1174 transop == LST_TRANS_TSBSRVADD)
1177 if (nd->nd_state != LST_NODE_ACTIVE)
1180 if (transop == LST_TRANS_TSBCLIADD) {
1181 hash = batch->bat_cli_hash;
1182 head = &batch->bat_cli_list;
1185 LASSERT (transop == LST_TRANS_TSBSRVADD);
1187 hash = batch->bat_srv_hash;
1188 head = &batch->bat_srv_list;
1191 LASSERT (nd->nd_id.nid != LNET_NID_ANY);
1193 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1196 if (list_empty(&ndl->ndl_link))
1197 list_add_tail(&ndl->ndl_link, head);
1203 lstcon_test_nodes_add(lstcon_test_t *test, struct list_head __user *result_up)
1205 lstcon_rpc_trans_t *trans;
1206 lstcon_group_t *grp;
1210 LASSERT (test->tes_src_grp != NULL);
1211 LASSERT (test->tes_dst_grp != NULL);
1213 transop = LST_TRANS_TSBSRVADD;
1214 grp = test->tes_dst_grp;
1216 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1217 &test->tes_trans_list, transop,
1218 test, lstcon_testrpc_condition, &trans);
1220 CERROR("Can't create transaction: %d\n", rc);
1224 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1226 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1227 lstcon_trans_stat()->trs_fwk_errno != 0) {
1228 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1230 lstcon_rpc_trans_destroy(trans);
1231 /* return if any error */
1232 CDEBUG(D_NET, "Failed to add test %s, "
1233 "RPC error %d, framework error %d\n",
1234 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1235 lstcon_trans_stat()->trs_rpc_errno,
1236 lstcon_trans_stat()->trs_fwk_errno);
1241 lstcon_rpc_trans_destroy(trans);
1243 if (transop == LST_TRANS_TSBCLIADD)
1246 transop = LST_TRANS_TSBCLIADD;
1247 grp = test->tes_src_grp;
1248 test->tes_cliidx = 0;
1250 /* requests to test clients */
1255 lstcon_verify_batch(const char *name, lstcon_batch_t **batch)
1259 rc = lstcon_batch_find(name, batch);
1261 CDEBUG(D_NET, "Can't find batch %s\n", name);
1265 if ((*batch)->bat_state != LST_BATCH_IDLE) {
1266 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1274 lstcon_verify_group(const char *name, lstcon_group_t **grp)
1277 lstcon_ndlink_t *ndl;
1279 rc = lstcon_group_find(name, grp);
1281 CDEBUG(D_NET, "can't find group %s\n", name);
1285 list_for_each_entry(ndl, &(*grp)->grp_ndl_list, ndl_link) {
1286 if (ndl->ndl_node->nd_state == LST_NODE_ACTIVE) {
1291 CDEBUG(D_NET, "Group %s has no ACTIVE nodes\n", name);
1297 lstcon_test_add(char *batch_name, int type, int loop,
1298 int concur, int dist, int span,
1299 char *src_name, char *dst_name,
1300 void *param, int paramlen, int *retp,
1301 struct list_head __user *result_up)
1303 lstcon_test_t *test = NULL;
1305 lstcon_group_t *src_grp = NULL;
1306 lstcon_group_t *dst_grp = NULL;
1307 lstcon_batch_t *batch = NULL;
1310 * verify that a batch of the given name exists, and the groups
1311 * that will be part of the batch exist and have at least one
1314 rc = lstcon_verify_batch(batch_name, &batch);
1318 rc = lstcon_verify_group(src_name, &src_grp);
1322 rc = lstcon_verify_group(dst_name, &dst_grp);
1326 if (dst_grp->grp_userland)
1329 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1331 CERROR("Can't allocate test descriptor\n");
1337 memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen]));
1338 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1339 test->tes_batch = batch;
1340 test->tes_type = type;
1341 test->tes_oneside = 0; /* TODO */
1342 test->tes_loop = loop;
1343 test->tes_concur = concur;
1344 test->tes_stop_onerr = 1; /* TODO */
1345 test->tes_span = span;
1346 test->tes_dist = dist;
1347 test->tes_cliidx = 0; /* just used for creating RPC */
1348 test->tes_src_grp = src_grp;
1349 test->tes_dst_grp = dst_grp;
1350 INIT_LIST_HEAD(&test->tes_trans_list);
1352 if (param != NULL) {
1353 test->tes_paramlen = paramlen;
1354 memcpy(&test->tes_param[0], param, paramlen);
1357 rc = lstcon_test_nodes_add(test, result_up);
1362 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1363 lstcon_trans_stat()->trs_fwk_errno != 0)
1364 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type,
1367 /* add to test list anyway, so user can check what's going on */
1368 list_add_tail(&test->tes_link, &batch->bat_test_list);
1371 test->tes_hdr.tsb_index = batch->bat_ntest;
1373 /* hold groups so nobody can change them */
1377 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1379 if (dst_grp != NULL)
1380 lstcon_group_put(dst_grp);
1382 if (src_grp != NULL)
1383 lstcon_group_put(src_grp);
1389 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1391 lstcon_test_t *test;
1393 list_for_each_entry(test, &batch->bat_test_list, tes_link) {
1394 if (idx == test->tes_hdr.tsb_index) {
1404 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1405 lstcon_rpc_ent_t __user *ent_up)
1407 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1409 LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1410 transop == LST_TRANS_TSBSRVQRY);
1412 /* positive errno, framework error code */
1413 if (copy_to_user(&ent_up->rpe_priv[0],
1414 &rep->bar_active, sizeof(rep->bar_active)))
1421 lstcon_test_batch_query(char *name, int testidx, int client,
1422 int timeout, struct list_head __user *result_up)
1424 lstcon_rpc_trans_t *trans;
1425 struct list_head *translist;
1426 struct list_head *ndlist;
1427 lstcon_tsb_hdr_t *hdr;
1428 lstcon_batch_t *batch;
1429 lstcon_test_t *test = NULL;
1433 rc = lstcon_batch_find(name, &batch);
1435 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1440 translist = &batch->bat_trans_list;
1441 ndlist = &batch->bat_cli_list;
1442 hdr = &batch->bat_hdr;
1445 /* query specified test only */
1446 rc = lstcon_test_find(batch, testidx, &test);
1448 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1452 translist = &test->tes_trans_list;
1453 ndlist = &test->tes_src_grp->grp_ndl_list;
1454 hdr = &test->tes_hdr;
1457 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1459 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1460 lstcon_batrpc_condition, &trans);
1462 CERROR("Can't create transaction: %d\n", rc);
1466 lstcon_rpc_trans_postwait(trans, timeout);
1468 if (testidx == 0 && /* query a batch, not a test */
1469 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1470 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1471 /* all RPCs finished, and no active test */
1472 batch->bat_state = LST_BATCH_IDLE;
1475 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1476 lstcon_tsbrpc_readent);
1477 lstcon_rpc_trans_destroy(trans);
1483 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1484 lstcon_rpc_ent_t __user *ent_up)
1486 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1487 sfw_counters_t __user *sfwk_stat;
1488 srpc_counters_t __user *srpc_stat;
1489 lnet_counters_t __user *lnet_stat;
1491 if (rep->str_status != 0)
1494 sfwk_stat = (sfw_counters_t __user *)&ent_up->rpe_payload[0];
1495 srpc_stat = (srpc_counters_t __user *)
1496 ((char __user *)sfwk_stat + sizeof(*sfwk_stat));
1497 lnet_stat = (lnet_counters_t __user *)
1498 ((char __user *)srpc_stat + sizeof(*srpc_stat));
1500 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1501 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1502 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1509 lstcon_ndlist_stat(struct list_head *ndlist,
1510 int timeout, struct list_head __user *result_up)
1512 struct list_head head;
1513 lstcon_rpc_trans_t *trans;
1516 INIT_LIST_HEAD(&head);
1518 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1519 LST_TRANS_STATQRY, NULL, NULL, &trans);
1521 CERROR("Can't create transaction: %d\n", rc);
1525 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1527 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1528 lstcon_statrpc_readent);
1529 lstcon_rpc_trans_destroy(trans);
1535 lstcon_group_stat(char *grp_name, int timeout,
1536 struct list_head __user *result_up)
1538 lstcon_group_t *grp;
1541 rc = lstcon_group_find(grp_name, &grp);
1543 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1547 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1549 lstcon_group_put(grp);
1555 lstcon_nodes_stat(int count, lnet_process_id_t __user *ids_up,
1556 int timeout, struct list_head __user *result_up)
1558 lstcon_ndlink_t *ndl;
1559 lstcon_group_t *tmp;
1560 lnet_process_id_t id;
1564 rc = lstcon_group_alloc(NULL, &tmp);
1566 CERROR("Out of memory\n");
1570 for (i = 0 ; i < count; i++) {
1571 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1576 /* add to tmp group */
1577 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1579 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1580 "Failed to find or create %s: %d\n",
1581 libcfs_id2str(id), rc);
1587 lstcon_group_put(tmp);
1591 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1593 lstcon_group_put(tmp);
1599 lstcon_debug_ndlist(struct list_head *ndlist,
1600 struct list_head *translist,
1601 int timeout, struct list_head __user *result_up)
1603 lstcon_rpc_trans_t *trans;
1606 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1607 NULL, lstcon_sesrpc_condition, &trans);
1609 CERROR("Can't create transaction: %d\n", rc);
1613 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1615 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1616 lstcon_sesrpc_readent);
1617 lstcon_rpc_trans_destroy(trans);
1623 lstcon_session_debug(int timeout, struct list_head __user *result_up)
1625 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1626 NULL, timeout, result_up);
1630 lstcon_batch_debug(int timeout, char *name,
1631 int client, struct list_head __user *result_up)
1633 lstcon_batch_t *bat;
1636 rc = lstcon_batch_find(name, &bat);
1640 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1642 NULL, timeout, result_up);
1648 lstcon_group_debug(int timeout, char *name,
1649 struct list_head __user *result_up)
1651 lstcon_group_t *grp;
1654 rc = lstcon_group_find(name, &grp);
1658 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1659 timeout, result_up);
1660 lstcon_group_put(grp);
1666 lstcon_nodes_debug(int timeout,
1667 int count, lnet_process_id_t __user *ids_up,
1668 struct list_head __user *result_up)
1670 lnet_process_id_t id;
1671 lstcon_ndlink_t *ndl;
1672 lstcon_group_t *grp;
1676 rc = lstcon_group_alloc(NULL, &grp);
1678 CDEBUG(D_NET, "Out of memory\n");
1682 for (i = 0; i < count; i++) {
1683 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1688 /* node is added to tmp group */
1689 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1691 CERROR("Can't create node link\n");
1697 lstcon_group_put(grp);
1701 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1702 timeout, result_up);
1704 lstcon_group_put(grp);
1710 lstcon_session_match(lst_sid_t sid)
1712 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1713 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1: 0;
1717 lstcon_new_session_id(lst_sid_t *sid)
1719 lnet_process_id_t id;
1721 LASSERT (console_session.ses_state == LST_SESSION_NONE);
1724 sid->ses_nid = id.nid;
1725 sid->ses_stamp = cfs_time_current();
1729 lstcon_session_new(char *name, int key, unsigned feats,
1730 int timeout, int force, lst_sid_t __user *sid_up)
1735 if (console_session.ses_state != LST_SESSION_NONE) {
1736 /* session exists */
1738 CNETERR("Session %s already exists\n",
1739 console_session.ses_name);
1743 rc = lstcon_session_end();
1745 /* lstcon_session_end() only return local error */
1750 if ((feats & ~LST_FEATS_MASK) != 0) {
1751 CNETERR("Unknown session features %x\n",
1752 (feats & ~LST_FEATS_MASK));
1756 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1757 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
1759 lstcon_new_session_id(&console_session.ses_id);
1761 console_session.ses_key = key;
1762 console_session.ses_state = LST_SESSION_ACTIVE;
1763 console_session.ses_force = !!force;
1764 console_session.ses_features = feats;
1765 console_session.ses_feats_updated = 0;
1766 console_session.ses_timeout = (timeout <= 0) ?
1767 LST_CONSOLE_TIMEOUT : timeout;
1769 if (strlen(name) > sizeof(console_session.ses_name)-1)
1771 strlcpy(console_session.ses_name, name,
1772 sizeof(console_session.ses_name));
1774 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1778 rc = lstcon_rpc_pinger_start();
1780 lstcon_batch_t *bat = NULL;
1782 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1783 lstcon_batch_destroy(bat);
1788 if (copy_to_user(sid_up, &console_session.ses_id,
1789 sizeof(lst_sid_t)) == 0)
1792 lstcon_session_end();
1798 lstcon_session_info(lst_sid_t __user *sid_up, int __user *key_up,
1799 unsigned __user *featp,
1800 lstcon_ndlist_ent_t __user *ndinfo_up,
1801 char __user *name_up, int len)
1803 lstcon_ndlist_ent_t *entp;
1804 lstcon_ndlink_t *ndl;
1807 if (console_session.ses_state != LST_SESSION_ACTIVE)
1810 LIBCFS_ALLOC(entp, sizeof(*entp));
1814 memset(entp, 0, sizeof(*entp));
1816 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link)
1817 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1819 if (copy_to_user(sid_up, &console_session.ses_id,
1820 sizeof(lst_sid_t)) ||
1821 copy_to_user(key_up, &console_session.ses_key,
1823 copy_to_user(featp, &console_session.ses_features,
1825 copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1826 copy_to_user(name_up, console_session.ses_name, len))
1829 LIBCFS_FREE(entp, sizeof(*entp));
1835 lstcon_session_end()
1837 lstcon_rpc_trans_t *trans;
1838 lstcon_group_t *grp;
1839 lstcon_batch_t *bat;
1842 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1844 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1845 NULL, LST_TRANS_SESEND, NULL,
1846 lstcon_sesrpc_condition, &trans);
1848 CERROR("Can't create transaction: %d\n", rc);
1852 console_session.ses_shutdown = 1;
1854 lstcon_rpc_pinger_stop();
1856 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1858 lstcon_rpc_trans_destroy(trans);
1859 /* User can do nothing even rpc failed, so go on */
1861 /* waiting for orphan rpcs to die */
1862 lstcon_rpc_cleanup_wait();
1864 console_session.ses_id = LST_INVALID_SID;
1865 console_session.ses_state = LST_SESSION_NONE;
1866 console_session.ses_key = 0;
1867 console_session.ses_force = 0;
1868 console_session.ses_feats_updated = 0;
1870 /* destroy all batches */
1871 while (!list_empty(&console_session.ses_bat_list)) {
1872 bat = list_entry(console_session.ses_bat_list.next,
1873 lstcon_batch_t, bat_link);
1875 lstcon_batch_destroy(bat);
1878 /* destroy all groups */
1879 while (!list_empty(&console_session.ses_grp_list)) {
1880 grp = list_entry(console_session.ses_grp_list.next,
1881 lstcon_group_t, grp_link);
1882 LASSERT(grp->grp_ref == 1);
1884 lstcon_group_put(grp);
1887 /* all nodes should be released */
1888 LASSERT(list_empty(&console_session.ses_ndl_list));
1890 console_session.ses_shutdown = 0;
1891 console_session.ses_expired = 0;
1897 lstcon_session_feats_check(unsigned feats)
1901 if ((feats & ~LST_FEATS_MASK) != 0) {
1902 CERROR("Can't support these features: %x\n",
1903 (feats & ~LST_FEATS_MASK));
1907 spin_lock(&console_session.ses_rpc_lock);
1909 if (!console_session.ses_feats_updated) {
1910 console_session.ses_feats_updated = 1;
1911 console_session.ses_features = feats;
1914 if (console_session.ses_features != feats)
1917 spin_unlock(&console_session.ses_rpc_lock);
1920 CERROR("remote features %x do not match with "
1921 "session features %x of console\n",
1922 feats, console_session.ses_features);
1929 lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
1931 srpc_msg_t *rep = &rpc->srpc_replymsg;
1932 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1933 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1934 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1935 lstcon_group_t *grp = NULL;
1936 lstcon_ndlink_t *ndl;
1939 sfw_unpack_message(req);
1941 mutex_lock(&console_session.ses_mutex);
1943 jrep->join_sid = console_session.ses_id;
1945 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1946 jrep->join_status = ESRCH;
1950 if (lstcon_session_feats_check(req->msg_ses_feats) != 0) {
1951 jrep->join_status = EPROTO;
1955 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1956 !lstcon_session_match(jreq->join_sid)) {
1957 jrep->join_status = EBUSY;
1961 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1962 rc = lstcon_group_alloc(jreq->join_group, &grp);
1964 CERROR("Out of memory\n");
1968 list_add_tail(&grp->grp_link,
1969 &console_session.ses_grp_list);
1970 lstcon_group_addref(grp);
1973 if (grp->grp_ref > 2) {
1974 /* Group in using */
1975 jrep->join_status = EBUSY;
1979 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1981 jrep->join_status = EEXIST;
1985 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1987 CERROR("Out of memory\n");
1991 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1992 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1994 if (grp->grp_userland == 0)
1995 grp->grp_userland = 1;
1997 strlcpy(jrep->join_session, console_session.ses_name,
1998 sizeof(jrep->join_session));
1999 jrep->join_timeout = console_session.ses_timeout;
2000 jrep->join_status = 0;
2003 rep->msg_ses_feats = console_session.ses_features;
2005 lstcon_group_put(grp);
2007 mutex_unlock(&console_session.ses_mutex);
2012 static srpc_service_t lstcon_acceptor_service;
2013 static void lstcon_init_acceptor_service(void)
2015 /* initialize selftest console acceptor service table */
2016 lstcon_acceptor_service.sv_name = "join session";
2017 lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
2018 lstcon_acceptor_service.sv_id = SRPC_SERVICE_JOIN;
2019 lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX;
2022 int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
2024 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
2026 /* initialize console */
2028 lstcon_console_init(void)
2033 memset(&console_session, 0, sizeof(lstcon_session_t));
2035 console_session.ses_id = LST_INVALID_SID;
2036 console_session.ses_state = LST_SESSION_NONE;
2037 console_session.ses_timeout = 0;
2038 console_session.ses_force = 0;
2039 console_session.ses_expired = 0;
2040 console_session.ses_feats_updated = 0;
2041 console_session.ses_features = LST_FEATS_MASK;
2042 console_session.ses_laststamp = cfs_time_current_sec();
2044 mutex_init(&console_session.ses_mutex);
2046 INIT_LIST_HEAD(&console_session.ses_ndl_list);
2047 INIT_LIST_HEAD(&console_session.ses_grp_list);
2048 INIT_LIST_HEAD(&console_session.ses_bat_list);
2049 INIT_LIST_HEAD(&console_session.ses_trans_list);
2051 LIBCFS_ALLOC(console_session.ses_ndl_hash,
2052 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2053 if (console_session.ses_ndl_hash == NULL)
2056 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
2057 INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
2060 /* initialize acceptor service table */
2061 lstcon_init_acceptor_service();
2063 rc = srpc_add_service(&lstcon_acceptor_service);
2064 LASSERT(rc != -EBUSY);
2066 LIBCFS_FREE(console_session.ses_ndl_hash,
2067 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2071 rc = srpc_service_add_buffers(&lstcon_acceptor_service,
2072 lstcon_acceptor_service.sv_wi_total);
2078 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
2081 lstcon_rpc_module_init();
2086 srpc_shutdown_service(&lstcon_acceptor_service);
2087 srpc_remove_service(&lstcon_acceptor_service);
2089 LIBCFS_FREE(console_session.ses_ndl_hash,
2090 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2092 srpc_wait_service_shutdown(&lstcon_acceptor_service);
2098 lstcon_console_fini(void)
2102 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
2104 mutex_lock(&console_session.ses_mutex);
2106 srpc_shutdown_service(&lstcon_acceptor_service);
2107 srpc_remove_service(&lstcon_acceptor_service);
2109 if (console_session.ses_state != LST_SESSION_NONE)
2110 lstcon_session_end();
2112 lstcon_rpc_module_fini();
2114 mutex_unlock(&console_session.ses_mutex);
2116 LASSERT(list_empty(&console_session.ses_ndl_list));
2117 LASSERT(list_empty(&console_session.ses_grp_list));
2118 LASSERT(list_empty(&console_session.ses_bat_list));
2119 LASSERT(list_empty(&console_session.ses_trans_list));
2121 for (i = 0; i < LST_NODE_HASHSIZE; i++)
2122 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
2124 LIBCFS_FREE(console_session.ses_ndl_hash,
2125 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2127 srpc_wait_service_shutdown(&lstcon_acceptor_service);