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_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id,
292 lstcon_ndlink_t **ndlpp, int create)
296 rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
300 if (!list_empty(&(*ndlpp)->ndl_link))
303 list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
310 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
312 list_del_init(&ndl->ndl_link);
313 lstcon_ndlink_release(ndl);
318 lstcon_group_ndlink_move(lstcon_group_t *old,
319 lstcon_group_t *new, lstcon_ndlink_t *ndl)
321 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
324 list_del(&ndl->ndl_hlink);
325 list_del(&ndl->ndl_link);
328 list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
329 list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
336 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
338 lstcon_ndlink_t *ndl;
340 while (!list_empty(&old->grp_ndl_list)) {
341 ndl = list_entry(old->grp_ndl_list.next,
342 lstcon_ndlink_t, ndl_link);
343 lstcon_group_ndlink_move(old, new, ndl);
348 lstcon_sesrpc_condition(int transop, lstcon_node_t *nd, void *arg)
350 lstcon_group_t *grp = (lstcon_group_t *)arg;
353 case LST_TRANS_SESNEW:
354 if (nd->nd_state == LST_NODE_ACTIVE)
358 case LST_TRANS_SESEND:
359 if (nd->nd_state != LST_NODE_ACTIVE)
362 if (grp != NULL && nd->nd_ref > 1)
366 case LST_TRANS_SESQRY:
377 lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
378 lstcon_rpc_ent_t __user *ent_up)
380 srpc_debug_reply_t *rep;
383 case LST_TRANS_SESNEW:
384 case LST_TRANS_SESEND:
387 case LST_TRANS_SESQRY:
388 rep = &msg->msg_body.dbg_reply;
390 if (copy_to_user(&ent_up->rpe_priv[0],
391 &rep->dbg_timeout, sizeof(int)) ||
392 copy_to_user(&ent_up->rpe_payload[0],
393 &rep->dbg_name, LST_NAME_SIZE))
406 lstcon_group_nodes_add(lstcon_group_t *grp,
407 int count, lnet_process_id_t __user *ids_up,
408 unsigned *featp, struct list_head __user *result_up)
410 lstcon_rpc_trans_t *trans;
411 lstcon_ndlink_t *ndl;
413 lnet_process_id_t id;
417 rc = lstcon_group_alloc(NULL, &tmp);
419 CERROR("Out of memory\n");
423 for (i = 0 ; i < count; i++) {
424 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
429 /* skip if it's in this group already */
430 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
434 /* add to tmp group */
435 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
437 CERROR("Can't create ndlink, out of memory\n");
443 lstcon_group_decref(tmp);
447 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
448 &tmp->grp_trans_list, LST_TRANS_SESNEW,
449 tmp, lstcon_sesrpc_condition, &trans);
451 CERROR("Can't create transaction: %d\n", rc);
452 lstcon_group_decref(tmp);
457 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
459 rc = lstcon_rpc_trans_interpreter(trans, result_up,
460 lstcon_sesrpc_readent);
461 *featp = trans->tas_features;
463 /* destroy all RPGs */
464 lstcon_rpc_trans_destroy(trans);
466 lstcon_group_move(tmp, grp);
467 lstcon_group_decref(tmp);
473 lstcon_group_nodes_remove(lstcon_group_t *grp,
474 int count, lnet_process_id_t __user *ids_up,
475 struct list_head __user *result_up)
477 lstcon_rpc_trans_t *trans;
478 lstcon_ndlink_t *ndl;
480 lnet_process_id_t id;
484 /* End session and remove node from the group */
486 rc = lstcon_group_alloc(NULL, &tmp);
488 CERROR("Out of memory\n");
492 for (i = 0; i < count; i++) {
493 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
498 /* move node to tmp group */
499 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
500 lstcon_group_ndlink_move(grp, tmp, ndl);
503 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
504 &tmp->grp_trans_list, LST_TRANS_SESEND,
505 tmp, lstcon_sesrpc_condition, &trans);
507 CERROR("Can't create transaction: %d\n", rc);
511 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
513 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
515 lstcon_rpc_trans_destroy(trans);
516 /* release nodes anyway, because we can't rollback status */
517 lstcon_group_decref(tmp);
521 lstcon_group_move(tmp, grp);
522 lstcon_group_decref(tmp);
528 lstcon_group_add(char *name)
533 rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
535 /* find a group with same name */
536 lstcon_group_decref(grp);
540 rc = lstcon_group_alloc(name, &grp);
542 CERROR("Can't allocate descriptor for group %s\n", name);
546 list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
552 lstcon_nodes_add(char *name, int count, lnet_process_id_t __user *ids_up,
553 unsigned *featp, struct list_head __user *result_up)
559 LASSERT (ids_up != NULL);
561 rc = lstcon_group_find(name, &grp);
563 CDEBUG(D_NET, "Can't find group %s\n", name);
567 if (grp->grp_ref > 2) {
568 /* referred by other threads or test */
569 CDEBUG(D_NET, "Group %s is busy\n", name);
570 lstcon_group_decref(grp);
575 rc = lstcon_group_nodes_add(grp, count, ids_up, featp, result_up);
577 lstcon_group_decref(grp);
583 lstcon_group_del(char *name)
585 lstcon_rpc_trans_t *trans;
589 rc = lstcon_group_find(name, &grp);
591 CDEBUG(D_NET, "Can't find group: %s\n", name);
595 if (grp->grp_ref > 2) {
596 /* referred by others threads or test */
597 CDEBUG(D_NET, "Group %s is busy\n", name);
598 lstcon_group_decref(grp);
602 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
603 &grp->grp_trans_list, LST_TRANS_SESEND,
604 grp, lstcon_sesrpc_condition, &trans);
606 CERROR("Can't create transaction: %d\n", rc);
607 lstcon_group_decref(grp);
611 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
613 lstcon_rpc_trans_destroy(trans);
615 lstcon_group_decref(grp);
616 /* -ref for session, it's destroyed,
617 * status can't be rolled back, destroy group anway */
618 lstcon_group_decref(grp);
624 lstcon_group_clean(char *name, int args)
626 lstcon_group_t *grp = NULL;
629 rc = lstcon_group_find(name, &grp);
631 CDEBUG(D_NET, "Can't find group %s\n", name);
635 if (grp->grp_ref > 2) {
636 /* referred by test */
637 CDEBUG(D_NET, "Group %s is busy\n", name);
638 lstcon_group_decref(grp);
642 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
643 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
645 lstcon_group_drain(grp, args);
647 lstcon_group_decref(grp);
648 /* release empty group */
649 if (list_empty(&grp->grp_ndl_list))
650 lstcon_group_decref(grp);
656 lstcon_nodes_remove(char *name, int count,
657 lnet_process_id_t __user *ids_up,
658 struct list_head __user *result_up)
660 lstcon_group_t *grp = NULL;
663 rc = lstcon_group_find(name, &grp);
665 CDEBUG(D_NET, "Can't find group: %s\n", name);
669 if (grp->grp_ref > 2) {
670 /* referred by test */
671 CDEBUG(D_NET, "Group %s is busy\n", name);
672 lstcon_group_decref(grp);
676 rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
678 lstcon_group_decref(grp);
679 /* release empty group */
680 if (list_empty(&grp->grp_ndl_list))
681 lstcon_group_decref(grp);
687 lstcon_group_refresh(char *name, struct list_head __user *result_up)
689 lstcon_rpc_trans_t *trans;
693 rc = lstcon_group_find(name, &grp);
695 CDEBUG(D_NET, "Can't find group: %s\n", name);
699 if (grp->grp_ref > 2) {
700 /* referred by test */
701 CDEBUG(D_NET, "Group %s is busy\n", name);
702 lstcon_group_decref(grp);
706 /* re-invite all inactive nodes int the group */
707 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
708 &grp->grp_trans_list, LST_TRANS_SESNEW,
709 grp, lstcon_sesrpc_condition, &trans);
711 /* local error, return */
712 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
713 lstcon_group_decref(grp);
717 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
719 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
721 lstcon_rpc_trans_destroy(trans);
723 lstcon_group_decref(grp);
729 lstcon_group_list(int index, int len, char __user *name_up)
734 LASSERT(name_up != NULL);
736 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
738 return copy_to_user(name_up, grp->grp_name, len) ?
747 lstcon_nodes_getent(struct list_head *head, int *index_p,
748 int *count_p, lstcon_node_ent_t __user *dents_up)
750 lstcon_ndlink_t *ndl;
755 LASSERT(index_p != NULL && count_p != NULL);
756 LASSERT(dents_up != NULL);
757 LASSERT(*index_p >= 0);
758 LASSERT(*count_p > 0);
760 list_for_each_entry(ndl, head, ndl_link) {
761 if (index++ < *index_p)
764 if (count >= *count_p)
768 if (copy_to_user(&dents_up[count].nde_id,
769 &nd->nd_id, sizeof(nd->nd_id)) ||
770 copy_to_user(&dents_up[count].nde_state,
771 &nd->nd_state, sizeof(nd->nd_state)))
777 if (index <= *index_p)
787 lstcon_group_info(char *name, lstcon_ndlist_ent_t __user *gents_p,
788 int *index_p, int *count_p,
789 lstcon_node_ent_t __user *dents_up)
791 lstcon_ndlist_ent_t *gentp;
793 lstcon_ndlink_t *ndl;
796 rc = lstcon_group_find(name, &grp);
798 CDEBUG(D_NET, "Can't find group %s\n", name);
802 if (dents_up != NULL) {
804 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
805 index_p, count_p, dents_up);
806 lstcon_group_decref(grp);
811 /* non-verbose query */
812 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
814 CERROR("Can't allocate ndlist_ent\n");
815 lstcon_group_decref(grp);
820 memset(gentp, 0, sizeof(lstcon_ndlist_ent_t));
822 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link)
823 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
825 rc = copy_to_user(gents_p, gentp,
826 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT : 0;
828 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
830 lstcon_group_decref(grp);
836 lstcon_batch_find(const char *name, lstcon_batch_t **batpp)
840 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
841 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
851 lstcon_batch_add(char *name)
857 rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
859 CDEBUG(D_NET, "Batch %s already exists\n", name);
863 LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
865 CERROR("Can't allocate descriptor for batch %s\n", name);
869 LIBCFS_ALLOC(bat->bat_cli_hash,
870 sizeof(struct list_head) * LST_NODE_HASHSIZE);
871 if (bat->bat_cli_hash == NULL) {
872 CERROR("Can't allocate hash for batch %s\n", name);
873 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
878 LIBCFS_ALLOC(bat->bat_srv_hash,
879 sizeof(struct list_head) * LST_NODE_HASHSIZE);
880 if (bat->bat_srv_hash == NULL) {
881 CERROR("Can't allocate hash for batch %s\n", name);
882 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
883 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
888 if (strlen(name) > sizeof(bat->bat_name)-1) {
889 LIBCFS_FREE(bat->bat_srv_hash, LST_NODE_HASHSIZE);
890 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
891 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
894 strncpy(bat->bat_name, name, sizeof(bat->bat_name));
895 bat->bat_hdr.tsb_index = 0;
896 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
899 bat->bat_state = LST_BATCH_IDLE;
901 INIT_LIST_HEAD(&bat->bat_cli_list);
902 INIT_LIST_HEAD(&bat->bat_srv_list);
903 INIT_LIST_HEAD(&bat->bat_test_list);
904 INIT_LIST_HEAD(&bat->bat_trans_list);
906 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
907 INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
908 INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
911 list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
917 lstcon_batch_list(int index, int len, char __user *name_up)
921 LASSERT(name_up != NULL);
924 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
926 return copy_to_user(name_up, bat->bat_name, len) ?
935 lstcon_batch_info(char *name, lstcon_test_batch_ent_t __user *ent_up,
936 int server, int testidx, int *index_p, int *ndent_p,
937 lstcon_node_ent_t __user *dents_up)
939 lstcon_test_batch_ent_t *entp;
940 struct list_head *clilst;
941 struct list_head *srvlst;
942 lstcon_test_t *test = NULL;
944 lstcon_ndlink_t *ndl;
947 rc = lstcon_batch_find(name, &bat);
949 CDEBUG(D_NET, "Can't find batch %s\n", name);
954 /* query test, test index start from 1 */
955 list_for_each_entry(test, &bat->bat_test_list, tes_link) {
961 CDEBUG(D_NET, "Can't find specified test in batch\n");
966 clilst = (test == NULL) ? &bat->bat_cli_list :
967 &test->tes_src_grp->grp_ndl_list;
968 srvlst = (test == NULL) ? &bat->bat_srv_list :
969 &test->tes_dst_grp->grp_ndl_list;
971 if (dents_up != NULL) {
972 rc = lstcon_nodes_getent((server ? srvlst: clilst),
973 index_p, ndent_p, dents_up);
977 /* non-verbose query */
978 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
982 memset(entp, 0, sizeof(lstcon_test_batch_ent_t));
985 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
986 entp->u.tbe_batch.bae_state = bat->bat_state;
990 entp->u.tbe_test.tse_type = test->tes_type;
991 entp->u.tbe_test.tse_loop = test->tes_loop;
992 entp->u.tbe_test.tse_concur = test->tes_concur;
995 list_for_each_entry(ndl, clilst, ndl_link)
996 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
998 list_for_each_entry(ndl, srvlst, ndl_link)
999 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
1001 rc = copy_to_user(ent_up, entp,
1002 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
1004 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
1010 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1013 case LST_TRANS_TSBRUN:
1014 if (nd->nd_state != LST_NODE_ACTIVE)
1018 case LST_TRANS_TSBSTOP:
1019 if (nd->nd_state != LST_NODE_ACTIVE)
1023 case LST_TRANS_TSBCLIQRY:
1024 case LST_TRANS_TSBSRVQRY:
1032 lstcon_batch_op(lstcon_batch_t *bat, int transop,
1033 struct list_head __user *result_up)
1035 lstcon_rpc_trans_t *trans;
1038 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1039 &bat->bat_trans_list, transop,
1040 bat, lstcon_batrpc_condition, &trans);
1042 CERROR("Can't create transaction: %d\n", rc);
1046 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1048 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1050 lstcon_rpc_trans_destroy(trans);
1056 lstcon_batch_run(char *name, int timeout, struct list_head __user *result_up)
1058 lstcon_batch_t *bat;
1061 if (lstcon_batch_find(name, &bat) != 0) {
1062 CDEBUG(D_NET, "Can't find batch %s\n", name);
1066 bat->bat_arg = timeout;
1068 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1070 /* mark batch as running if it's started in any node */
1071 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1072 bat->bat_state = LST_BATCH_RUNNING;
1078 lstcon_batch_stop(char *name, int force, struct list_head __user *result_up)
1080 lstcon_batch_t *bat;
1083 if (lstcon_batch_find(name, &bat) != 0) {
1084 CDEBUG(D_NET, "Can't find batch %s\n", name);
1088 bat->bat_arg = force;
1090 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1092 /* mark batch as stopped if all RPCs finished */
1093 if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1094 bat->bat_state = LST_BATCH_IDLE;
1100 lstcon_batch_destroy(lstcon_batch_t *bat)
1102 lstcon_ndlink_t *ndl;
1103 lstcon_test_t *test;
1106 list_del(&bat->bat_link);
1108 while (!list_empty(&bat->bat_test_list)) {
1109 test = list_entry(bat->bat_test_list.next,
1110 lstcon_test_t, tes_link);
1111 LASSERT(list_empty(&test->tes_trans_list));
1113 list_del(&test->tes_link);
1115 lstcon_group_decref(test->tes_src_grp);
1116 lstcon_group_decref(test->tes_dst_grp);
1118 LIBCFS_FREE(test, offsetof(lstcon_test_t,
1119 tes_param[test->tes_paramlen]));
1122 LASSERT(list_empty(&bat->bat_trans_list));
1124 while (!list_empty(&bat->bat_cli_list)) {
1125 ndl = list_entry(bat->bat_cli_list.next,
1126 lstcon_ndlink_t, ndl_link);
1127 list_del_init(&ndl->ndl_link);
1129 lstcon_ndlink_release(ndl);
1132 while (!list_empty(&bat->bat_srv_list)) {
1133 ndl = list_entry(bat->bat_srv_list.next,
1134 lstcon_ndlink_t, ndl_link);
1135 list_del_init(&ndl->ndl_link);
1137 lstcon_ndlink_release(ndl);
1140 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1141 LASSERT(list_empty(&bat->bat_cli_hash[i]));
1142 LASSERT(list_empty(&bat->bat_srv_hash[i]));
1145 LIBCFS_FREE(bat->bat_cli_hash,
1146 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1147 LIBCFS_FREE(bat->bat_srv_hash,
1148 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1149 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
1153 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1155 lstcon_test_t *test;
1156 lstcon_batch_t *batch;
1157 lstcon_ndlink_t *ndl;
1158 struct list_head *hash;
1159 struct list_head *head;
1161 test = (lstcon_test_t *)arg;
1162 LASSERT(test != NULL);
1164 batch = test->tes_batch;
1165 LASSERT(batch != NULL);
1167 if (test->tes_oneside &&
1168 transop == LST_TRANS_TSBSRVADD)
1171 if (nd->nd_state != LST_NODE_ACTIVE)
1174 if (transop == LST_TRANS_TSBCLIADD) {
1175 hash = batch->bat_cli_hash;
1176 head = &batch->bat_cli_list;
1179 LASSERT (transop == LST_TRANS_TSBSRVADD);
1181 hash = batch->bat_srv_hash;
1182 head = &batch->bat_srv_list;
1185 LASSERT (nd->nd_id.nid != LNET_NID_ANY);
1187 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1190 if (list_empty(&ndl->ndl_link))
1191 list_add_tail(&ndl->ndl_link, head);
1197 lstcon_test_nodes_add(lstcon_test_t *test, struct list_head __user *result_up)
1199 lstcon_rpc_trans_t *trans;
1200 lstcon_group_t *grp;
1204 LASSERT (test->tes_src_grp != NULL);
1205 LASSERT (test->tes_dst_grp != NULL);
1207 transop = LST_TRANS_TSBSRVADD;
1208 grp = test->tes_dst_grp;
1210 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1211 &test->tes_trans_list, transop,
1212 test, lstcon_testrpc_condition, &trans);
1214 CERROR("Can't create transaction: %d\n", rc);
1218 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1220 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1221 lstcon_trans_stat()->trs_fwk_errno != 0) {
1222 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1224 lstcon_rpc_trans_destroy(trans);
1225 /* return if any error */
1226 CDEBUG(D_NET, "Failed to add test %s, "
1227 "RPC error %d, framework error %d\n",
1228 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1229 lstcon_trans_stat()->trs_rpc_errno,
1230 lstcon_trans_stat()->trs_fwk_errno);
1235 lstcon_rpc_trans_destroy(trans);
1237 if (transop == LST_TRANS_TSBCLIADD)
1240 transop = LST_TRANS_TSBCLIADD;
1241 grp = test->tes_src_grp;
1242 test->tes_cliidx = 0;
1244 /* requests to test clients */
1249 lstcon_verify_batch(const char *name, lstcon_batch_t **batch)
1253 rc = lstcon_batch_find(name, batch);
1255 CDEBUG(D_NET, "Can't find batch %s\n", name);
1259 if ((*batch)->bat_state != LST_BATCH_IDLE) {
1260 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1268 lstcon_verify_group(const char *name, lstcon_group_t **grp)
1271 lstcon_ndlink_t *ndl;
1273 rc = lstcon_group_find(name, grp);
1275 CDEBUG(D_NET, "can't find group %s\n", name);
1279 list_for_each_entry(ndl, &(*grp)->grp_ndl_list, ndl_link) {
1280 if (ndl->ndl_node->nd_state == LST_NODE_ACTIVE) {
1285 CDEBUG(D_NET, "Group %s has no ACTIVE nodes\n", name);
1291 lstcon_test_add(char *batch_name, int type, int loop,
1292 int concur, int dist, int span,
1293 char *src_name, char *dst_name,
1294 void *param, int paramlen, int *retp,
1295 struct list_head __user *result_up)
1297 lstcon_test_t *test = NULL;
1299 lstcon_group_t *src_grp = NULL;
1300 lstcon_group_t *dst_grp = NULL;
1301 lstcon_batch_t *batch = NULL;
1304 * verify that a batch of the given name exists, and the groups
1305 * that will be part of the batch exist and have at least one
1308 rc = lstcon_verify_batch(batch_name, &batch);
1312 rc = lstcon_verify_group(src_name, &src_grp);
1316 rc = lstcon_verify_group(dst_name, &dst_grp);
1320 if (dst_grp->grp_userland)
1323 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1325 CERROR("Can't allocate test descriptor\n");
1331 memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen]));
1332 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1333 test->tes_batch = batch;
1334 test->tes_type = type;
1335 test->tes_oneside = 0; /* TODO */
1336 test->tes_loop = loop;
1337 test->tes_concur = concur;
1338 test->tes_stop_onerr = 1; /* TODO */
1339 test->tes_span = span;
1340 test->tes_dist = dist;
1341 test->tes_cliidx = 0; /* just used for creating RPC */
1342 test->tes_src_grp = src_grp;
1343 test->tes_dst_grp = dst_grp;
1344 INIT_LIST_HEAD(&test->tes_trans_list);
1346 if (param != NULL) {
1347 test->tes_paramlen = paramlen;
1348 memcpy(&test->tes_param[0], param, paramlen);
1351 rc = lstcon_test_nodes_add(test, result_up);
1356 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1357 lstcon_trans_stat()->trs_fwk_errno != 0)
1358 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type,
1361 /* add to test list anyway, so user can check what's going on */
1362 list_add_tail(&test->tes_link, &batch->bat_test_list);
1365 test->tes_hdr.tsb_index = batch->bat_ntest;
1367 /* hold groups so nobody can change them */
1371 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1373 if (dst_grp != NULL)
1374 lstcon_group_decref(dst_grp);
1376 if (src_grp != NULL)
1377 lstcon_group_decref(src_grp);
1383 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1385 lstcon_test_t *test;
1387 list_for_each_entry(test, &batch->bat_test_list, tes_link) {
1388 if (idx == test->tes_hdr.tsb_index) {
1398 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1399 lstcon_rpc_ent_t __user *ent_up)
1401 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1403 LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1404 transop == LST_TRANS_TSBSRVQRY);
1406 /* positive errno, framework error code */
1407 if (copy_to_user(&ent_up->rpe_priv[0],
1408 &rep->bar_active, sizeof(rep->bar_active)))
1415 lstcon_test_batch_query(char *name, int testidx, int client,
1416 int timeout, struct list_head __user *result_up)
1418 lstcon_rpc_trans_t *trans;
1419 struct list_head *translist;
1420 struct list_head *ndlist;
1421 lstcon_tsb_hdr_t *hdr;
1422 lstcon_batch_t *batch;
1423 lstcon_test_t *test = NULL;
1427 rc = lstcon_batch_find(name, &batch);
1429 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1434 translist = &batch->bat_trans_list;
1435 ndlist = &batch->bat_cli_list;
1436 hdr = &batch->bat_hdr;
1439 /* query specified test only */
1440 rc = lstcon_test_find(batch, testidx, &test);
1442 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1446 translist = &test->tes_trans_list;
1447 ndlist = &test->tes_src_grp->grp_ndl_list;
1448 hdr = &test->tes_hdr;
1451 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1453 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1454 lstcon_batrpc_condition, &trans);
1456 CERROR("Can't create transaction: %d\n", rc);
1460 lstcon_rpc_trans_postwait(trans, timeout);
1462 if (testidx == 0 && /* query a batch, not a test */
1463 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1464 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1465 /* all RPCs finished, and no active test */
1466 batch->bat_state = LST_BATCH_IDLE;
1469 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1470 lstcon_tsbrpc_readent);
1471 lstcon_rpc_trans_destroy(trans);
1477 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1478 lstcon_rpc_ent_t __user *ent_up)
1480 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1481 sfw_counters_t __user *sfwk_stat;
1482 srpc_counters_t __user *srpc_stat;
1483 lnet_counters_t __user *lnet_stat;
1485 if (rep->str_status != 0)
1488 sfwk_stat = (sfw_counters_t __user *)&ent_up->rpe_payload[0];
1489 srpc_stat = (srpc_counters_t __user *)
1490 ((char __user *)sfwk_stat + sizeof(*sfwk_stat));
1491 lnet_stat = (lnet_counters_t __user *)
1492 ((char __user *)srpc_stat + sizeof(*srpc_stat));
1494 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1495 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1496 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1503 lstcon_ndlist_stat(struct list_head *ndlist,
1504 int timeout, struct list_head __user *result_up)
1506 struct list_head head;
1507 lstcon_rpc_trans_t *trans;
1510 INIT_LIST_HEAD(&head);
1512 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1513 LST_TRANS_STATQRY, NULL, NULL, &trans);
1515 CERROR("Can't create transaction: %d\n", rc);
1519 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1521 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1522 lstcon_statrpc_readent);
1523 lstcon_rpc_trans_destroy(trans);
1529 lstcon_group_stat(char *grp_name, int timeout,
1530 struct list_head __user *result_up)
1532 lstcon_group_t *grp;
1535 rc = lstcon_group_find(grp_name, &grp);
1537 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1541 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1543 lstcon_group_decref(grp);
1549 lstcon_nodes_stat(int count, lnet_process_id_t __user *ids_up,
1550 int timeout, struct list_head __user *result_up)
1552 lstcon_ndlink_t *ndl;
1553 lstcon_group_t *tmp;
1554 lnet_process_id_t id;
1558 rc = lstcon_group_alloc(NULL, &tmp);
1560 CERROR("Out of memory\n");
1564 for (i = 0 ; i < count; i++) {
1565 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1570 /* add to tmp group */
1571 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1573 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1574 "Failed to find or create %s: %d\n",
1575 libcfs_id2str(id), rc);
1581 lstcon_group_decref(tmp);
1585 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1587 lstcon_group_decref(tmp);
1593 lstcon_debug_ndlist(struct list_head *ndlist,
1594 struct list_head *translist,
1595 int timeout, struct list_head __user *result_up)
1597 lstcon_rpc_trans_t *trans;
1600 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1601 NULL, lstcon_sesrpc_condition, &trans);
1603 CERROR("Can't create transaction: %d\n", rc);
1607 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1609 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1610 lstcon_sesrpc_readent);
1611 lstcon_rpc_trans_destroy(trans);
1617 lstcon_session_debug(int timeout, struct list_head __user *result_up)
1619 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1620 NULL, timeout, result_up);
1624 lstcon_batch_debug(int timeout, char *name,
1625 int client, struct list_head __user *result_up)
1627 lstcon_batch_t *bat;
1630 rc = lstcon_batch_find(name, &bat);
1634 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1636 NULL, timeout, result_up);
1642 lstcon_group_debug(int timeout, char *name,
1643 struct list_head __user *result_up)
1645 lstcon_group_t *grp;
1648 rc = lstcon_group_find(name, &grp);
1652 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1653 timeout, result_up);
1654 lstcon_group_decref(grp);
1660 lstcon_nodes_debug(int timeout,
1661 int count, lnet_process_id_t __user *ids_up,
1662 struct list_head __user *result_up)
1664 lnet_process_id_t id;
1665 lstcon_ndlink_t *ndl;
1666 lstcon_group_t *grp;
1670 rc = lstcon_group_alloc(NULL, &grp);
1672 CDEBUG(D_NET, "Out of memory\n");
1676 for (i = 0; i < count; i++) {
1677 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1682 /* node is added to tmp group */
1683 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1685 CERROR("Can't create node link\n");
1691 lstcon_group_decref(grp);
1695 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1696 timeout, result_up);
1698 lstcon_group_decref(grp);
1704 lstcon_session_match(lst_sid_t sid)
1706 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1707 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1: 0;
1711 lstcon_new_session_id(lst_sid_t *sid)
1713 lnet_process_id_t id;
1715 LASSERT (console_session.ses_state == LST_SESSION_NONE);
1718 sid->ses_nid = id.nid;
1719 sid->ses_stamp = cfs_time_current();
1723 lstcon_session_new(char *name, int key, unsigned feats,
1724 int timeout, int force, lst_sid_t __user *sid_up)
1729 if (console_session.ses_state != LST_SESSION_NONE) {
1730 /* session exists */
1732 CNETERR("Session %s already exists\n",
1733 console_session.ses_name);
1737 rc = lstcon_session_end();
1739 /* lstcon_session_end() only return local error */
1744 if ((feats & ~LST_FEATS_MASK) != 0) {
1745 CNETERR("Unknown session features %x\n",
1746 (feats & ~LST_FEATS_MASK));
1750 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1751 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
1753 lstcon_new_session_id(&console_session.ses_id);
1755 console_session.ses_key = key;
1756 console_session.ses_state = LST_SESSION_ACTIVE;
1757 console_session.ses_force = !!force;
1758 console_session.ses_features = feats;
1759 console_session.ses_feats_updated = 0;
1760 console_session.ses_timeout = (timeout <= 0) ?
1761 LST_CONSOLE_TIMEOUT : timeout;
1763 if (strlen(name) > sizeof(console_session.ses_name)-1)
1765 strlcpy(console_session.ses_name, name,
1766 sizeof(console_session.ses_name));
1768 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1772 rc = lstcon_rpc_pinger_start();
1774 lstcon_batch_t *bat = NULL;
1776 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1777 lstcon_batch_destroy(bat);
1782 if (copy_to_user(sid_up, &console_session.ses_id,
1783 sizeof(lst_sid_t)) == 0)
1786 lstcon_session_end();
1792 lstcon_session_info(lst_sid_t __user *sid_up, int __user *key_up,
1793 unsigned __user *featp,
1794 lstcon_ndlist_ent_t __user *ndinfo_up,
1795 char __user *name_up, int len)
1797 lstcon_ndlist_ent_t *entp;
1798 lstcon_ndlink_t *ndl;
1801 if (console_session.ses_state != LST_SESSION_ACTIVE)
1804 LIBCFS_ALLOC(entp, sizeof(*entp));
1808 memset(entp, 0, sizeof(*entp));
1810 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link)
1811 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1813 if (copy_to_user(sid_up, &console_session.ses_id,
1814 sizeof(lst_sid_t)) ||
1815 copy_to_user(key_up, &console_session.ses_key,
1817 copy_to_user(featp, &console_session.ses_features,
1819 copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1820 copy_to_user(name_up, console_session.ses_name, len))
1823 LIBCFS_FREE(entp, sizeof(*entp));
1829 lstcon_session_end()
1831 lstcon_rpc_trans_t *trans;
1832 lstcon_group_t *grp;
1833 lstcon_batch_t *bat;
1836 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1838 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1839 NULL, LST_TRANS_SESEND, NULL,
1840 lstcon_sesrpc_condition, &trans);
1842 CERROR("Can't create transaction: %d\n", rc);
1846 console_session.ses_shutdown = 1;
1848 lstcon_rpc_pinger_stop();
1850 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1852 lstcon_rpc_trans_destroy(trans);
1853 /* User can do nothing even rpc failed, so go on */
1855 /* waiting for orphan rpcs to die */
1856 lstcon_rpc_cleanup_wait();
1858 console_session.ses_id = LST_INVALID_SID;
1859 console_session.ses_state = LST_SESSION_NONE;
1860 console_session.ses_key = 0;
1861 console_session.ses_force = 0;
1862 console_session.ses_feats_updated = 0;
1864 /* destroy all batches */
1865 while (!list_empty(&console_session.ses_bat_list)) {
1866 bat = list_entry(console_session.ses_bat_list.next,
1867 lstcon_batch_t, bat_link);
1869 lstcon_batch_destroy(bat);
1872 /* destroy all groups */
1873 while (!list_empty(&console_session.ses_grp_list)) {
1874 grp = list_entry(console_session.ses_grp_list.next,
1875 lstcon_group_t, grp_link);
1876 LASSERT(grp->grp_ref == 1);
1878 lstcon_group_decref(grp);
1881 /* all nodes should be released */
1882 LASSERT(list_empty(&console_session.ses_ndl_list));
1884 console_session.ses_shutdown = 0;
1885 console_session.ses_expired = 0;
1891 lstcon_session_feats_check(unsigned feats)
1895 if ((feats & ~LST_FEATS_MASK) != 0) {
1896 CERROR("Can't support these features: %x\n",
1897 (feats & ~LST_FEATS_MASK));
1901 spin_lock(&console_session.ses_rpc_lock);
1903 if (!console_session.ses_feats_updated) {
1904 console_session.ses_feats_updated = 1;
1905 console_session.ses_features = feats;
1908 if (console_session.ses_features != feats)
1911 spin_unlock(&console_session.ses_rpc_lock);
1914 CERROR("remote features %x do not match with "
1915 "session features %x of console\n",
1916 feats, console_session.ses_features);
1923 lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
1925 srpc_msg_t *rep = &rpc->srpc_replymsg;
1926 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1927 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1928 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1929 lstcon_group_t *grp = NULL;
1930 lstcon_ndlink_t *ndl;
1933 sfw_unpack_message(req);
1935 mutex_lock(&console_session.ses_mutex);
1937 jrep->join_sid = console_session.ses_id;
1939 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1940 jrep->join_status = ESRCH;
1944 if (lstcon_session_feats_check(req->msg_ses_feats) != 0) {
1945 jrep->join_status = EPROTO;
1949 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1950 !lstcon_session_match(jreq->join_sid)) {
1951 jrep->join_status = EBUSY;
1955 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1956 rc = lstcon_group_alloc(jreq->join_group, &grp);
1958 CERROR("Out of memory\n");
1962 list_add_tail(&grp->grp_link,
1963 &console_session.ses_grp_list);
1964 lstcon_group_addref(grp);
1967 if (grp->grp_ref > 2) {
1968 /* Group in using */
1969 jrep->join_status = EBUSY;
1973 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1975 jrep->join_status = EEXIST;
1979 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1981 CERROR("Out of memory\n");
1985 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1986 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1988 if (grp->grp_userland == 0)
1989 grp->grp_userland = 1;
1991 strlcpy(jrep->join_session, console_session.ses_name,
1992 sizeof(jrep->join_session));
1993 jrep->join_timeout = console_session.ses_timeout;
1994 jrep->join_status = 0;
1997 rep->msg_ses_feats = console_session.ses_features;
1999 lstcon_group_decref(grp);
2001 mutex_unlock(&console_session.ses_mutex);
2006 static srpc_service_t lstcon_acceptor_service;
2007 static void lstcon_init_acceptor_service(void)
2009 /* initialize selftest console acceptor service table */
2010 lstcon_acceptor_service.sv_name = "join session";
2011 lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
2012 lstcon_acceptor_service.sv_id = SRPC_SERVICE_JOIN;
2013 lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX;
2016 int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
2018 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
2020 /* initialize console */
2022 lstcon_console_init(void)
2027 memset(&console_session, 0, sizeof(lstcon_session_t));
2029 console_session.ses_id = LST_INVALID_SID;
2030 console_session.ses_state = LST_SESSION_NONE;
2031 console_session.ses_timeout = 0;
2032 console_session.ses_force = 0;
2033 console_session.ses_expired = 0;
2034 console_session.ses_feats_updated = 0;
2035 console_session.ses_features = LST_FEATS_MASK;
2036 console_session.ses_laststamp = cfs_time_current_sec();
2038 mutex_init(&console_session.ses_mutex);
2040 INIT_LIST_HEAD(&console_session.ses_ndl_list);
2041 INIT_LIST_HEAD(&console_session.ses_grp_list);
2042 INIT_LIST_HEAD(&console_session.ses_bat_list);
2043 INIT_LIST_HEAD(&console_session.ses_trans_list);
2045 LIBCFS_ALLOC(console_session.ses_ndl_hash,
2046 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2047 if (console_session.ses_ndl_hash == NULL)
2050 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
2051 INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
2054 /* initialize acceptor service table */
2055 lstcon_init_acceptor_service();
2057 rc = srpc_add_service(&lstcon_acceptor_service);
2058 LASSERT(rc != -EBUSY);
2060 LIBCFS_FREE(console_session.ses_ndl_hash,
2061 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2065 rc = srpc_service_add_buffers(&lstcon_acceptor_service,
2066 lstcon_acceptor_service.sv_wi_total);
2072 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
2075 lstcon_rpc_module_init();
2080 srpc_shutdown_service(&lstcon_acceptor_service);
2081 srpc_remove_service(&lstcon_acceptor_service);
2083 LIBCFS_FREE(console_session.ses_ndl_hash,
2084 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2086 srpc_wait_service_shutdown(&lstcon_acceptor_service);
2092 lstcon_console_fini(void)
2096 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
2098 mutex_lock(&console_session.ses_mutex);
2100 srpc_shutdown_service(&lstcon_acceptor_service);
2101 srpc_remove_service(&lstcon_acceptor_service);
2103 if (console_session.ses_state != LST_SESSION_NONE)
2104 lstcon_session_end();
2106 lstcon_rpc_module_fini();
2108 mutex_unlock(&console_session.ses_mutex);
2110 LASSERT(list_empty(&console_session.ses_ndl_list));
2111 LASSERT(list_empty(&console_session.ses_grp_list));
2112 LASSERT(list_empty(&console_session.ses_bat_list));
2113 LASSERT(list_empty(&console_session.ses_trans_list));
2115 for (i = 0; i < LST_NODE_HASHSIZE; i++)
2116 LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
2118 LIBCFS_FREE(console_session.ses_ndl_hash,
2119 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
2121 srpc_wait_service_shutdown(&lstcon_acceptor_service);