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 cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_hash[idx],
82 lstcon_ndlink_t, ndl_hlink) {
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 cfs_list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
114 cfs_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 (!cfs_list_empty(&ndl->ndl_link));
132 LASSERT (!cfs_list_empty(&ndl->ndl_hlink));
134 /* remove from session */
135 cfs_list_del(&ndl->ndl_link);
136 cfs_list_del(&ndl->ndl_hlink);
138 LIBCFS_FREE(nd, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
142 lstcon_ndlink_find(cfs_list_t *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 cfs_list_for_each_entry_typed(ndl, &hash[idx],
155 lstcon_ndlink_t, ndl_hlink) {
156 if (ndl->ndl_node->nd_id.nid != id.nid ||
157 ndl->ndl_node->nd_id.pid != id.pid)
167 /* find or create in session hash */
168 rc = lstcon_node_find(id, &nd, (create == 1) ? 1 : 0);
172 LIBCFS_ALLOC(ndl, sizeof(lstcon_ndlink_t));
181 CFS_INIT_LIST_HEAD(&ndl->ndl_link);
182 cfs_list_add_tail(&ndl->ndl_hlink, &hash[idx]);
188 lstcon_ndlink_release(lstcon_ndlink_t *ndl)
190 LASSERT (cfs_list_empty(&ndl->ndl_link));
191 LASSERT (!cfs_list_empty(&ndl->ndl_hlink));
193 cfs_list_del(&ndl->ndl_hlink); /* delete from hash */
194 lstcon_node_put(ndl->ndl_node);
196 LIBCFS_FREE(ndl, sizeof(*ndl));
200 lstcon_group_alloc(char *name, lstcon_group_t **grpp)
205 LIBCFS_ALLOC(grp, offsetof(lstcon_group_t,
206 grp_ndl_hash[LST_NODE_HASHSIZE]));
210 memset(grp, 0, offsetof(lstcon_group_t,
211 grp_ndl_hash[LST_NODE_HASHSIZE]));
215 if (strlen(name) > sizeof(grp->grp_name)-1) {
216 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
217 grp_ndl_hash[LST_NODE_HASHSIZE]));
220 strncpy(grp->grp_name, name, sizeof(grp->grp_name));
223 CFS_INIT_LIST_HEAD(&grp->grp_link);
224 CFS_INIT_LIST_HEAD(&grp->grp_ndl_list);
225 CFS_INIT_LIST_HEAD(&grp->grp_trans_list);
227 for (i = 0; i < LST_NODE_HASHSIZE; i++)
228 CFS_INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
236 lstcon_group_addref(lstcon_group_t *grp)
241 static void lstcon_group_ndlink_release(lstcon_group_t *, lstcon_ndlink_t *);
244 lstcon_group_drain(lstcon_group_t *grp, int keep)
246 lstcon_ndlink_t *ndl;
247 lstcon_ndlink_t *tmp;
249 cfs_list_for_each_entry_safe_typed(ndl, tmp, &grp->grp_ndl_list,
250 lstcon_ndlink_t, ndl_link) {
251 if ((ndl->ndl_node->nd_state & keep) == 0)
252 lstcon_group_ndlink_release(grp, ndl);
257 lstcon_group_decref(lstcon_group_t *grp)
261 if (--grp->grp_ref > 0)
264 if (!cfs_list_empty(&grp->grp_link))
265 cfs_list_del(&grp->grp_link);
267 lstcon_group_drain(grp, 0);
269 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
270 LASSERT (cfs_list_empty(&grp->grp_ndl_hash[i]));
273 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
274 grp_ndl_hash[LST_NODE_HASHSIZE]));
278 lstcon_group_find(const char *name, lstcon_group_t **grpp)
282 cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list,
283 lstcon_group_t, grp_link) {
284 if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
287 lstcon_group_addref(grp); /* +1 ref for caller */
296 lstcon_group_put(lstcon_group_t *grp)
298 lstcon_group_decref(grp);
302 lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id,
303 lstcon_ndlink_t **ndlpp, int create)
307 rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
311 if (!cfs_list_empty(&(*ndlpp)->ndl_link))
314 cfs_list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
321 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
323 cfs_list_del_init(&ndl->ndl_link);
324 lstcon_ndlink_release(ndl);
329 lstcon_group_ndlink_move(lstcon_group_t *old,
330 lstcon_group_t *new, lstcon_ndlink_t *ndl)
332 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
335 cfs_list_del(&ndl->ndl_hlink);
336 cfs_list_del(&ndl->ndl_link);
339 cfs_list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
340 cfs_list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
347 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
349 lstcon_ndlink_t *ndl;
351 while (!cfs_list_empty(&old->grp_ndl_list)) {
352 ndl = cfs_list_entry(old->grp_ndl_list.next,
353 lstcon_ndlink_t, ndl_link);
354 lstcon_group_ndlink_move(old, new, ndl);
359 lstcon_sesrpc_condition(int transop, lstcon_node_t *nd, void *arg)
361 lstcon_group_t *grp = (lstcon_group_t *)arg;
364 case LST_TRANS_SESNEW:
365 if (nd->nd_state == LST_NODE_ACTIVE)
369 case LST_TRANS_SESEND:
370 if (nd->nd_state != LST_NODE_ACTIVE)
373 if (grp != NULL && nd->nd_ref > 1)
377 case LST_TRANS_SESQRY:
388 lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
389 lstcon_rpc_ent_t *ent_up)
391 srpc_debug_reply_t *rep;
394 case LST_TRANS_SESNEW:
395 case LST_TRANS_SESEND:
398 case LST_TRANS_SESQRY:
399 rep = &msg->msg_body.dbg_reply;
401 if (copy_to_user(&ent_up->rpe_priv[0],
402 &rep->dbg_timeout, sizeof(int)) ||
403 copy_to_user(&ent_up->rpe_payload[0],
404 &rep->dbg_name, LST_NAME_SIZE))
417 lstcon_group_nodes_add(lstcon_group_t *grp,
418 int count, lnet_process_id_t *ids_up,
419 unsigned *featp, cfs_list_t *result_up)
421 lstcon_rpc_trans_t *trans;
422 lstcon_ndlink_t *ndl;
424 lnet_process_id_t id;
428 rc = lstcon_group_alloc(NULL, &tmp);
430 CERROR("Out of memory\n");
434 for (i = 0 ; i < count; i++) {
435 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
440 /* skip if it's in this group already */
441 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
445 /* add to tmp group */
446 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
448 CERROR("Can't create ndlink, out of memory\n");
454 lstcon_group_put(tmp);
458 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
459 &tmp->grp_trans_list, LST_TRANS_SESNEW,
460 tmp, lstcon_sesrpc_condition, &trans);
462 CERROR("Can't create transaction: %d\n", rc);
463 lstcon_group_put(tmp);
468 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
470 rc = lstcon_rpc_trans_interpreter(trans, result_up,
471 lstcon_sesrpc_readent);
472 *featp = trans->tas_features;
474 /* destroy all RPGs */
475 lstcon_rpc_trans_destroy(trans);
477 lstcon_group_move(tmp, grp);
478 lstcon_group_put(tmp);
484 lstcon_group_nodes_remove(lstcon_group_t *grp,
485 int count, lnet_process_id_t *ids_up,
486 cfs_list_t *result_up)
488 lstcon_rpc_trans_t *trans;
489 lstcon_ndlink_t *ndl;
491 lnet_process_id_t id;
495 /* End session and remove node from the group */
497 rc = lstcon_group_alloc(NULL, &tmp);
499 CERROR("Out of memory\n");
503 for (i = 0; i < count; i++) {
504 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
509 /* move node to tmp group */
510 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
511 lstcon_group_ndlink_move(grp, tmp, ndl);
514 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
515 &tmp->grp_trans_list, LST_TRANS_SESEND,
516 tmp, lstcon_sesrpc_condition, &trans);
518 CERROR("Can't create transaction: %d\n", rc);
522 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
524 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
526 lstcon_rpc_trans_destroy(trans);
527 /* release nodes anyway, because we can't rollback status */
528 lstcon_group_put(tmp);
532 lstcon_group_move(tmp, grp);
533 lstcon_group_put(tmp);
539 lstcon_group_add(char *name)
544 rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
546 /* find a group with same name */
547 lstcon_group_put(grp);
551 rc = lstcon_group_alloc(name, &grp);
553 CERROR("Can't allocate descriptor for group %s\n", name);
557 cfs_list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
563 lstcon_nodes_add(char *name, int count, lnet_process_id_t *ids_up,
564 unsigned *featp, cfs_list_t *result_up)
570 LASSERT (ids_up != NULL);
572 rc = lstcon_group_find(name, &grp);
574 CDEBUG(D_NET, "Can't find group %s\n", name);
578 if (grp->grp_ref > 2) {
579 /* referred by other threads or test */
580 CDEBUG(D_NET, "Group %s is busy\n", name);
581 lstcon_group_put(grp);
586 rc = lstcon_group_nodes_add(grp, count, ids_up, featp, result_up);
588 lstcon_group_put(grp);
594 lstcon_group_del(char *name)
596 lstcon_rpc_trans_t *trans;
600 rc = lstcon_group_find(name, &grp);
602 CDEBUG(D_NET, "Can't find group: %s\n", name);
606 if (grp->grp_ref > 2) {
607 /* referred by others threads or test */
608 CDEBUG(D_NET, "Group %s is busy\n", name);
609 lstcon_group_put(grp);
613 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
614 &grp->grp_trans_list, LST_TRANS_SESEND,
615 grp, lstcon_sesrpc_condition, &trans);
617 CERROR("Can't create transaction: %d\n", rc);
618 lstcon_group_put(grp);
622 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
624 lstcon_rpc_trans_destroy(trans);
626 lstcon_group_put(grp);
627 /* -ref for session, it's destroyed,
628 * status can't be rolled back, destroy group anway */
629 lstcon_group_put(grp);
635 lstcon_group_clean(char *name, int args)
637 lstcon_group_t *grp = NULL;
640 rc = lstcon_group_find(name, &grp);
642 CDEBUG(D_NET, "Can't find group %s\n", name);
646 if (grp->grp_ref > 2) {
647 /* referred by test */
648 CDEBUG(D_NET, "Group %s is busy\n", name);
649 lstcon_group_put(grp);
653 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
654 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
656 lstcon_group_drain(grp, args);
658 lstcon_group_put(grp);
659 /* release empty group */
660 if (cfs_list_empty(&grp->grp_ndl_list))
661 lstcon_group_put(grp);
667 lstcon_nodes_remove(char *name, int count,
668 lnet_process_id_t *ids_up, cfs_list_t *result_up)
670 lstcon_group_t *grp = NULL;
673 rc = lstcon_group_find(name, &grp);
675 CDEBUG(D_NET, "Can't find group: %s\n", name);
679 if (grp->grp_ref > 2) {
680 /* referred by test */
681 CDEBUG(D_NET, "Group %s is busy\n", name);
682 lstcon_group_put(grp);
686 rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
688 lstcon_group_put(grp);
689 /* release empty group */
690 if (cfs_list_empty(&grp->grp_ndl_list))
691 lstcon_group_put(grp);
697 lstcon_group_refresh(char *name, cfs_list_t *result_up)
699 lstcon_rpc_trans_t *trans;
703 rc = lstcon_group_find(name, &grp);
705 CDEBUG(D_NET, "Can't find group: %s\n", name);
709 if (grp->grp_ref > 2) {
710 /* referred by test */
711 CDEBUG(D_NET, "Group %s is busy\n", name);
712 lstcon_group_put(grp);
716 /* re-invite all inactive nodes int the group */
717 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
718 &grp->grp_trans_list, LST_TRANS_SESNEW,
719 grp, lstcon_sesrpc_condition, &trans);
721 /* local error, return */
722 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
723 lstcon_group_put(grp);
727 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
729 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
731 lstcon_rpc_trans_destroy(trans);
733 lstcon_group_put(grp);
739 lstcon_group_list(int index, int len, char *name_up)
743 LASSERT (index >= 0);
744 LASSERT (name_up != NULL);
746 cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list,
747 lstcon_group_t, grp_link) {
749 return copy_to_user(name_up, grp->grp_name, len) ?
758 lstcon_nodes_getent(cfs_list_t *head, int *index_p,
759 int *count_p, lstcon_node_ent_t *dents_up)
761 lstcon_ndlink_t *ndl;
766 LASSERT (index_p != NULL && count_p != NULL);
767 LASSERT (dents_up != NULL);
768 LASSERT (*index_p >= 0);
769 LASSERT (*count_p > 0);
771 cfs_list_for_each_entry_typed(ndl, head, lstcon_ndlink_t, ndl_link) {
772 if (index++ < *index_p)
775 if (count >= *count_p)
779 if (copy_to_user(&dents_up[count].nde_id,
780 &nd->nd_id, sizeof(nd->nd_id)) ||
781 copy_to_user(&dents_up[count].nde_state,
782 &nd->nd_state, sizeof(nd->nd_state)))
788 if (index <= *index_p)
798 lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p,
799 int *index_p, int *count_p, lstcon_node_ent_t *dents_up)
801 lstcon_ndlist_ent_t *gentp;
803 lstcon_ndlink_t *ndl;
806 rc = lstcon_group_find(name, &grp);
808 CDEBUG(D_NET, "Can't find group %s\n", name);
814 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
815 index_p, count_p, dents_up);
816 lstcon_group_put(grp);
821 /* non-verbose query */
822 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
824 CERROR("Can't allocate ndlist_ent\n");
825 lstcon_group_put(grp);
830 memset(gentp, 0, sizeof(lstcon_ndlist_ent_t));
832 cfs_list_for_each_entry_typed(ndl, &grp->grp_ndl_list,
833 lstcon_ndlink_t, ndl_link)
834 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
836 rc = copy_to_user(gents_p, gentp,
837 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT: 0;
839 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
841 lstcon_group_put(grp);
847 lstcon_batch_find(const char *name, lstcon_batch_t **batpp)
851 cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list,
852 lstcon_batch_t, bat_link) {
853 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
863 lstcon_batch_add(char *name)
869 rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
871 CDEBUG(D_NET, "Batch %s already exists\n", name);
875 LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
877 CERROR("Can't allocate descriptor for batch %s\n", name);
881 LIBCFS_ALLOC(bat->bat_cli_hash,
882 sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
883 if (bat->bat_cli_hash == NULL) {
884 CERROR("Can't allocate hash for batch %s\n", name);
885 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
890 LIBCFS_ALLOC(bat->bat_srv_hash,
891 sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
892 if (bat->bat_srv_hash == NULL) {
893 CERROR("Can't allocate hash for batch %s\n", name);
894 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
895 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
900 if (strlen(name) > sizeof(bat->bat_name)-1) {
901 LIBCFS_FREE(bat->bat_srv_hash, LST_NODE_HASHSIZE);
902 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
903 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
906 strncpy(bat->bat_name, name, sizeof(bat->bat_name));
907 bat->bat_hdr.tsb_index = 0;
908 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
911 bat->bat_state = LST_BATCH_IDLE;
913 CFS_INIT_LIST_HEAD(&bat->bat_cli_list);
914 CFS_INIT_LIST_HEAD(&bat->bat_srv_list);
915 CFS_INIT_LIST_HEAD(&bat->bat_test_list);
916 CFS_INIT_LIST_HEAD(&bat->bat_trans_list);
918 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
919 CFS_INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
920 CFS_INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
923 cfs_list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
929 lstcon_batch_list(int index, int len, char *name_up)
933 LASSERT (name_up != NULL);
934 LASSERT (index >= 0);
936 cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list,
937 lstcon_batch_t, bat_link) {
939 return copy_to_user(name_up, bat->bat_name, len) ?
948 lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
949 int testidx, int *index_p, int *ndent_p,
950 lstcon_node_ent_t *dents_up)
952 lstcon_test_batch_ent_t *entp;
955 lstcon_test_t *test = NULL;
957 lstcon_ndlink_t *ndl;
960 rc = lstcon_batch_find(name, &bat);
962 CDEBUG(D_NET, "Can't find batch %s\n", name);
967 /* query test, test index start from 1 */
968 cfs_list_for_each_entry_typed(test, &bat->bat_test_list,
969 lstcon_test_t, tes_link) {
975 CDEBUG(D_NET, "Can't find specified test in batch\n");
980 clilst = (test == NULL) ? &bat->bat_cli_list :
981 &test->tes_src_grp->grp_ndl_list;
982 srvlst = (test == NULL) ? &bat->bat_srv_list :
983 &test->tes_dst_grp->grp_ndl_list;
985 if (dents_up != NULL) {
986 rc = lstcon_nodes_getent((server ? srvlst: clilst),
987 index_p, ndent_p, dents_up);
991 /* non-verbose query */
992 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
996 memset(entp, 0, sizeof(lstcon_test_batch_ent_t));
999 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
1000 entp->u.tbe_batch.bae_state = bat->bat_state;
1004 entp->u.tbe_test.tse_type = test->tes_type;
1005 entp->u.tbe_test.tse_loop = test->tes_loop;
1006 entp->u.tbe_test.tse_concur = test->tes_concur;
1009 cfs_list_for_each_entry_typed(ndl, clilst, lstcon_ndlink_t, ndl_link)
1010 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
1012 cfs_list_for_each_entry_typed(ndl, srvlst, lstcon_ndlink_t, ndl_link)
1013 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
1015 rc = copy_to_user(ent_up, entp,
1016 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
1018 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
1024 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1027 case LST_TRANS_TSBRUN:
1028 if (nd->nd_state != LST_NODE_ACTIVE)
1032 case LST_TRANS_TSBSTOP:
1033 if (nd->nd_state != LST_NODE_ACTIVE)
1037 case LST_TRANS_TSBCLIQRY:
1038 case LST_TRANS_TSBSRVQRY:
1046 lstcon_batch_op(lstcon_batch_t *bat, int transop,
1047 cfs_list_t *result_up)
1049 lstcon_rpc_trans_t *trans;
1052 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
1053 &bat->bat_trans_list, transop,
1054 bat, lstcon_batrpc_condition, &trans);
1056 CERROR("Can't create transaction: %d\n", rc);
1060 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1062 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1064 lstcon_rpc_trans_destroy(trans);
1070 lstcon_batch_run(char *name, int timeout, cfs_list_t *result_up)
1072 lstcon_batch_t *bat;
1075 if (lstcon_batch_find(name, &bat) != 0) {
1076 CDEBUG(D_NET, "Can't find batch %s\n", name);
1080 bat->bat_arg = timeout;
1082 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1084 /* mark batch as running if it's started in any node */
1085 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1086 bat->bat_state = LST_BATCH_RUNNING;
1092 lstcon_batch_stop(char *name, int force, cfs_list_t *result_up)
1094 lstcon_batch_t *bat;
1097 if (lstcon_batch_find(name, &bat) != 0) {
1098 CDEBUG(D_NET, "Can't find batch %s\n", name);
1102 bat->bat_arg = force;
1104 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1106 /* mark batch as stopped if all RPCs finished */
1107 if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1108 bat->bat_state = LST_BATCH_IDLE;
1114 lstcon_batch_destroy(lstcon_batch_t *bat)
1116 lstcon_ndlink_t *ndl;
1117 lstcon_test_t *test;
1120 cfs_list_del(&bat->bat_link);
1122 while (!cfs_list_empty(&bat->bat_test_list)) {
1123 test = cfs_list_entry(bat->bat_test_list.next,
1124 lstcon_test_t, tes_link);
1125 LASSERT (cfs_list_empty(&test->tes_trans_list));
1127 cfs_list_del(&test->tes_link);
1129 lstcon_group_put(test->tes_src_grp);
1130 lstcon_group_put(test->tes_dst_grp);
1132 LIBCFS_FREE(test, offsetof(lstcon_test_t,
1133 tes_param[test->tes_paramlen]));
1136 LASSERT (cfs_list_empty(&bat->bat_trans_list));
1138 while (!cfs_list_empty(&bat->bat_cli_list)) {
1139 ndl = cfs_list_entry(bat->bat_cli_list.next,
1140 lstcon_ndlink_t, ndl_link);
1141 cfs_list_del_init(&ndl->ndl_link);
1143 lstcon_ndlink_release(ndl);
1146 while (!cfs_list_empty(&bat->bat_srv_list)) {
1147 ndl = cfs_list_entry(bat->bat_srv_list.next,
1148 lstcon_ndlink_t, ndl_link);
1149 cfs_list_del_init(&ndl->ndl_link);
1151 lstcon_ndlink_release(ndl);
1154 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1155 LASSERT (cfs_list_empty(&bat->bat_cli_hash[i]));
1156 LASSERT (cfs_list_empty(&bat->bat_srv_hash[i]));
1159 LIBCFS_FREE(bat->bat_cli_hash,
1160 sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
1161 LIBCFS_FREE(bat->bat_srv_hash,
1162 sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
1163 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
1167 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1169 lstcon_test_t *test;
1170 lstcon_batch_t *batch;
1171 lstcon_ndlink_t *ndl;
1175 test = (lstcon_test_t *)arg;
1176 LASSERT (test != NULL);
1178 batch = test->tes_batch;
1179 LASSERT (batch != NULL);
1181 if (test->tes_oneside &&
1182 transop == LST_TRANS_TSBSRVADD)
1185 if (nd->nd_state != LST_NODE_ACTIVE)
1188 if (transop == LST_TRANS_TSBCLIADD) {
1189 hash = batch->bat_cli_hash;
1190 head = &batch->bat_cli_list;
1193 LASSERT (transop == LST_TRANS_TSBSRVADD);
1195 hash = batch->bat_srv_hash;
1196 head = &batch->bat_srv_list;
1199 LASSERT (nd->nd_id.nid != LNET_NID_ANY);
1201 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1204 if (cfs_list_empty(&ndl->ndl_link))
1205 cfs_list_add_tail(&ndl->ndl_link, head);
1211 lstcon_test_nodes_add(lstcon_test_t *test, cfs_list_t *result_up)
1213 lstcon_rpc_trans_t *trans;
1214 lstcon_group_t *grp;
1218 LASSERT (test->tes_src_grp != NULL);
1219 LASSERT (test->tes_dst_grp != NULL);
1221 transop = LST_TRANS_TSBSRVADD;
1222 grp = test->tes_dst_grp;
1224 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1225 &test->tes_trans_list, transop,
1226 test, lstcon_testrpc_condition, &trans);
1228 CERROR("Can't create transaction: %d\n", rc);
1232 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1234 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1235 lstcon_trans_stat()->trs_fwk_errno != 0) {
1236 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1238 lstcon_rpc_trans_destroy(trans);
1239 /* return if any error */
1240 CDEBUG(D_NET, "Failed to add test %s, "
1241 "RPC error %d, framework error %d\n",
1242 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1243 lstcon_trans_stat()->trs_rpc_errno,
1244 lstcon_trans_stat()->trs_fwk_errno);
1249 lstcon_rpc_trans_destroy(trans);
1251 if (transop == LST_TRANS_TSBCLIADD)
1254 transop = LST_TRANS_TSBCLIADD;
1255 grp = test->tes_src_grp;
1256 test->tes_cliidx = 0;
1258 /* requests to test clients */
1263 lstcon_verify_batch(const char *name, lstcon_batch_t **batch)
1267 rc = lstcon_batch_find(name, batch);
1269 CDEBUG(D_NET, "Can't find batch %s\n", name);
1273 if ((*batch)->bat_state != LST_BATCH_IDLE) {
1274 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1282 lstcon_verify_group(const char *name, lstcon_group_t **grp)
1285 lstcon_ndlink_t *ndl;
1287 rc = lstcon_group_find(name, grp);
1289 CDEBUG(D_NET, "can't find group %s\n", name);
1293 cfs_list_for_each_entry_typed(ndl, &(*grp)->grp_ndl_list,
1294 lstcon_ndlink_t, ndl_link) {
1295 if (ndl->ndl_node->nd_state == LST_NODE_ACTIVE) {
1300 CDEBUG(D_NET, "Group %s has no ACTIVE nodes\n", name);
1306 lstcon_test_add(char *batch_name, int type, int loop,
1307 int concur, int dist, int span,
1308 char *src_name, char *dst_name,
1309 void *param, int paramlen, int *retp,
1310 cfs_list_t *result_up)
1312 lstcon_test_t *test = NULL;
1314 lstcon_group_t *src_grp = NULL;
1315 lstcon_group_t *dst_grp = NULL;
1316 lstcon_batch_t *batch = NULL;
1319 * verify that a batch of the given name exists, and the groups
1320 * that will be part of the batch exist and have at least one
1323 rc = lstcon_verify_batch(batch_name, &batch);
1327 rc = lstcon_verify_group(src_name, &src_grp);
1331 rc = lstcon_verify_group(dst_name, &dst_grp);
1335 if (dst_grp->grp_userland)
1338 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1340 CERROR("Can't allocate test descriptor\n");
1346 memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen]));
1347 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1348 test->tes_batch = batch;
1349 test->tes_type = type;
1350 test->tes_oneside = 0; /* TODO */
1351 test->tes_loop = loop;
1352 test->tes_concur = concur;
1353 test->tes_stop_onerr = 1; /* TODO */
1354 test->tes_span = span;
1355 test->tes_dist = dist;
1356 test->tes_cliidx = 0; /* just used for creating RPC */
1357 test->tes_src_grp = src_grp;
1358 test->tes_dst_grp = dst_grp;
1359 CFS_INIT_LIST_HEAD(&test->tes_trans_list);
1361 if (param != NULL) {
1362 test->tes_paramlen = paramlen;
1363 memcpy(&test->tes_param[0], param, paramlen);
1366 rc = lstcon_test_nodes_add(test, result_up);
1371 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1372 lstcon_trans_stat()->trs_fwk_errno != 0)
1373 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type,
1376 /* add to test list anyway, so user can check what's going on */
1377 cfs_list_add_tail(&test->tes_link, &batch->bat_test_list);
1380 test->tes_hdr.tsb_index = batch->bat_ntest;
1382 /* hold groups so nobody can change them */
1386 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1388 if (dst_grp != NULL)
1389 lstcon_group_put(dst_grp);
1391 if (src_grp != NULL)
1392 lstcon_group_put(src_grp);
1398 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1400 lstcon_test_t *test;
1402 cfs_list_for_each_entry_typed(test, &batch->bat_test_list,
1403 lstcon_test_t, tes_link) {
1404 if (idx == test->tes_hdr.tsb_index) {
1414 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1415 lstcon_rpc_ent_t *ent_up)
1417 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1419 LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1420 transop == LST_TRANS_TSBSRVQRY);
1422 /* positive errno, framework error code */
1423 if (copy_to_user(&ent_up->rpe_priv[0],
1424 &rep->bar_active, sizeof(rep->bar_active)))
1431 lstcon_test_batch_query(char *name, int testidx, int client,
1432 int timeout, cfs_list_t *result_up)
1434 lstcon_rpc_trans_t *trans;
1435 cfs_list_t *translist;
1437 lstcon_tsb_hdr_t *hdr;
1438 lstcon_batch_t *batch;
1439 lstcon_test_t *test = NULL;
1443 rc = lstcon_batch_find(name, &batch);
1445 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1450 translist = &batch->bat_trans_list;
1451 ndlist = &batch->bat_cli_list;
1452 hdr = &batch->bat_hdr;
1455 /* query specified test only */
1456 rc = lstcon_test_find(batch, testidx, &test);
1458 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1462 translist = &test->tes_trans_list;
1463 ndlist = &test->tes_src_grp->grp_ndl_list;
1464 hdr = &test->tes_hdr;
1467 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1469 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1470 lstcon_batrpc_condition, &trans);
1472 CERROR("Can't create transaction: %d\n", rc);
1476 lstcon_rpc_trans_postwait(trans, timeout);
1478 if (testidx == 0 && /* query a batch, not a test */
1479 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1480 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1481 /* all RPCs finished, and no active test */
1482 batch->bat_state = LST_BATCH_IDLE;
1485 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1486 lstcon_tsbrpc_readent);
1487 lstcon_rpc_trans_destroy(trans);
1493 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1494 lstcon_rpc_ent_t *ent_up)
1496 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1497 sfw_counters_t *sfwk_stat;
1498 srpc_counters_t *srpc_stat;
1499 lnet_counters_t *lnet_stat;
1501 if (rep->str_status != 0)
1504 sfwk_stat = (sfw_counters_t *)&ent_up->rpe_payload[0];
1505 srpc_stat = (srpc_counters_t *)((char *)sfwk_stat + sizeof(*sfwk_stat));
1506 lnet_stat = (lnet_counters_t *)((char *)srpc_stat + sizeof(*srpc_stat));
1508 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1509 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1510 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1517 lstcon_ndlist_stat(cfs_list_t *ndlist,
1518 int timeout, cfs_list_t *result_up)
1521 lstcon_rpc_trans_t *trans;
1524 CFS_INIT_LIST_HEAD(&head);
1526 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1527 LST_TRANS_STATQRY, NULL, NULL, &trans);
1529 CERROR("Can't create transaction: %d\n", rc);
1533 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1535 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1536 lstcon_statrpc_readent);
1537 lstcon_rpc_trans_destroy(trans);
1543 lstcon_group_stat(char *grp_name, int timeout, cfs_list_t *result_up)
1545 lstcon_group_t *grp;
1548 rc = lstcon_group_find(grp_name, &grp);
1550 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1554 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1556 lstcon_group_put(grp);
1562 lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
1563 int timeout, cfs_list_t *result_up)
1565 lstcon_ndlink_t *ndl;
1566 lstcon_group_t *tmp;
1567 lnet_process_id_t id;
1571 rc = lstcon_group_alloc(NULL, &tmp);
1573 CERROR("Out of memory\n");
1577 for (i = 0 ; i < count; i++) {
1578 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1583 /* add to tmp group */
1584 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1586 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1587 "Failed to find or create %s: %d\n",
1588 libcfs_id2str(id), rc);
1594 lstcon_group_put(tmp);
1598 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1600 lstcon_group_put(tmp);
1606 lstcon_debug_ndlist(cfs_list_t *ndlist,
1607 cfs_list_t *translist,
1608 int timeout, cfs_list_t *result_up)
1610 lstcon_rpc_trans_t *trans;
1613 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1614 NULL, lstcon_sesrpc_condition, &trans);
1616 CERROR("Can't create transaction: %d\n", rc);
1620 lstcon_rpc_trans_postwait(trans, LST_VALIDATE_TIMEOUT(timeout));
1622 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1623 lstcon_sesrpc_readent);
1624 lstcon_rpc_trans_destroy(trans);
1630 lstcon_session_debug(int timeout, cfs_list_t *result_up)
1632 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1633 NULL, timeout, result_up);
1637 lstcon_batch_debug(int timeout, char *name,
1638 int client, cfs_list_t *result_up)
1640 lstcon_batch_t *bat;
1643 rc = lstcon_batch_find(name, &bat);
1647 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1649 NULL, timeout, result_up);
1655 lstcon_group_debug(int timeout, char *name,
1656 cfs_list_t *result_up)
1658 lstcon_group_t *grp;
1661 rc = lstcon_group_find(name, &grp);
1665 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1666 timeout, result_up);
1667 lstcon_group_put(grp);
1673 lstcon_nodes_debug(int timeout,
1674 int count, lnet_process_id_t *ids_up,
1675 cfs_list_t *result_up)
1677 lnet_process_id_t id;
1678 lstcon_ndlink_t *ndl;
1679 lstcon_group_t *grp;
1683 rc = lstcon_group_alloc(NULL, &grp);
1685 CDEBUG(D_NET, "Out of memory\n");
1689 for (i = 0; i < count; i++) {
1690 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1695 /* node is added to tmp group */
1696 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1698 CERROR("Can't create node link\n");
1704 lstcon_group_put(grp);
1708 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1709 timeout, result_up);
1711 lstcon_group_put(grp);
1717 lstcon_session_match(lst_sid_t sid)
1719 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1720 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1: 0;
1724 lstcon_new_session_id(lst_sid_t *sid)
1726 lnet_process_id_t id;
1728 LASSERT (console_session.ses_state == LST_SESSION_NONE);
1731 sid->ses_nid = id.nid;
1732 sid->ses_stamp = cfs_time_current();
1735 extern srpc_service_t lstcon_acceptor_service;
1738 lstcon_session_new(char *name, int key, unsigned feats,
1739 int timeout, int force, lst_sid_t *sid_up)
1744 if (console_session.ses_state != LST_SESSION_NONE) {
1745 /* session exists */
1747 CNETERR("Session %s already exists\n",
1748 console_session.ses_name);
1752 rc = lstcon_session_end();
1754 /* lstcon_session_end() only return local error */
1759 if ((feats & ~LST_FEATS_MASK) != 0) {
1760 CNETERR("Unknown session features %x\n",
1761 (feats & ~LST_FEATS_MASK));
1765 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1766 LASSERT(cfs_list_empty(&console_session.ses_ndl_hash[i]));
1768 lstcon_new_session_id(&console_session.ses_id);
1770 console_session.ses_key = key;
1771 console_session.ses_state = LST_SESSION_ACTIVE;
1772 console_session.ses_force = !!force;
1773 console_session.ses_features = feats;
1774 console_session.ses_feats_updated = 0;
1775 console_session.ses_timeout = (timeout <= 0) ?
1776 LST_CONSOLE_TIMEOUT : timeout;
1778 if (strlen(name) > sizeof(console_session.ses_name)-1)
1780 strncpy(console_session.ses_name, name,
1781 sizeof(console_session.ses_name));
1783 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1787 rc = lstcon_rpc_pinger_start();
1789 lstcon_batch_t *bat = NULL;
1791 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1792 lstcon_batch_destroy(bat);
1797 if (copy_to_user(sid_up, &console_session.ses_id,
1798 sizeof(lst_sid_t)) == 0)
1801 lstcon_session_end();
1807 lstcon_session_info(lst_sid_t *sid_up, int *key_up, unsigned *featp,
1808 lstcon_ndlist_ent_t *ndinfo_up, char *name_up, int len)
1810 lstcon_ndlist_ent_t *entp;
1811 lstcon_ndlink_t *ndl;
1814 if (console_session.ses_state != LST_SESSION_ACTIVE)
1817 LIBCFS_ALLOC(entp, sizeof(*entp));
1821 memset(entp, 0, sizeof(*entp));
1823 cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_list,
1824 lstcon_ndlink_t, ndl_link)
1825 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1827 if (copy_to_user(sid_up, &console_session.ses_id,
1828 sizeof(lst_sid_t)) ||
1829 copy_to_user(key_up, &console_session.ses_key,
1831 copy_to_user(featp, &console_session.ses_features,
1833 copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1834 copy_to_user(name_up, console_session.ses_name, len))
1837 LIBCFS_FREE(entp, sizeof(*entp));
1843 lstcon_session_end()
1845 lstcon_rpc_trans_t *trans;
1846 lstcon_group_t *grp;
1847 lstcon_batch_t *bat;
1850 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1852 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1853 NULL, LST_TRANS_SESEND, NULL,
1854 lstcon_sesrpc_condition, &trans);
1856 CERROR("Can't create transaction: %d\n", rc);
1860 console_session.ses_shutdown = 1;
1862 lstcon_rpc_pinger_stop();
1864 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1866 lstcon_rpc_trans_destroy(trans);
1867 /* User can do nothing even rpc failed, so go on */
1869 /* waiting for orphan rpcs to die */
1870 lstcon_rpc_cleanup_wait();
1872 console_session.ses_id = LST_INVALID_SID;
1873 console_session.ses_state = LST_SESSION_NONE;
1874 console_session.ses_key = 0;
1875 console_session.ses_force = 0;
1876 console_session.ses_feats_updated = 0;
1878 /* destroy all batches */
1879 while (!cfs_list_empty(&console_session.ses_bat_list)) {
1880 bat = cfs_list_entry(console_session.ses_bat_list.next,
1881 lstcon_batch_t, bat_link);
1883 lstcon_batch_destroy(bat);
1886 /* destroy all groups */
1887 while (!cfs_list_empty(&console_session.ses_grp_list)) {
1888 grp = cfs_list_entry(console_session.ses_grp_list.next,
1889 lstcon_group_t, grp_link);
1890 LASSERT (grp->grp_ref == 1);
1892 lstcon_group_put(grp);
1895 /* all nodes should be released */
1896 LASSERT (cfs_list_empty(&console_session.ses_ndl_list));
1898 console_session.ses_shutdown = 0;
1899 console_session.ses_expired = 0;
1905 lstcon_session_feats_check(unsigned feats)
1909 if ((feats & ~LST_FEATS_MASK) != 0) {
1910 CERROR("Can't support these features: %x\n",
1911 (feats & ~LST_FEATS_MASK));
1915 spin_lock(&console_session.ses_rpc_lock);
1917 if (!console_session.ses_feats_updated) {
1918 console_session.ses_feats_updated = 1;
1919 console_session.ses_features = feats;
1922 if (console_session.ses_features != feats)
1925 spin_unlock(&console_session.ses_rpc_lock);
1928 CERROR("remote features %x do not match with "
1929 "session features %x of console\n",
1930 feats, console_session.ses_features);
1937 lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
1939 srpc_msg_t *rep = &rpc->srpc_replymsg;
1940 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1941 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1942 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1943 lstcon_group_t *grp = NULL;
1944 lstcon_ndlink_t *ndl;
1947 sfw_unpack_message(req);
1949 mutex_lock(&console_session.ses_mutex);
1951 jrep->join_sid = console_session.ses_id;
1953 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1954 jrep->join_status = ESRCH;
1958 if (lstcon_session_feats_check(req->msg_ses_feats) != 0) {
1959 jrep->join_status = EPROTO;
1963 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1964 !lstcon_session_match(jreq->join_sid)) {
1965 jrep->join_status = EBUSY;
1969 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1970 rc = lstcon_group_alloc(jreq->join_group, &grp);
1972 CERROR("Out of memory\n");
1976 cfs_list_add_tail(&grp->grp_link,
1977 &console_session.ses_grp_list);
1978 lstcon_group_addref(grp);
1981 if (grp->grp_ref > 2) {
1982 /* Group in using */
1983 jrep->join_status = EBUSY;
1987 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1989 jrep->join_status = EEXIST;
1993 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1995 CERROR("Out of memory\n");
1999 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
2000 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
2002 if (grp->grp_userland == 0)
2003 grp->grp_userland = 1;
2005 strcpy(jrep->join_session, console_session.ses_name);
2006 jrep->join_timeout = console_session.ses_timeout;
2007 jrep->join_status = 0;
2010 rep->msg_ses_feats = console_session.ses_features;
2012 lstcon_group_put(grp);
2014 mutex_unlock(&console_session.ses_mutex);
2019 srpc_service_t lstcon_acceptor_service;
2020 void lstcon_init_acceptor_service(void)
2022 /* initialize selftest console acceptor service table */
2023 lstcon_acceptor_service.sv_name = "join session";
2024 lstcon_acceptor_service.sv_handler = lstcon_acceptor_handle;
2025 lstcon_acceptor_service.sv_id = SRPC_SERVICE_JOIN;
2026 lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX;
2029 extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
2031 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
2033 /* initialize console */
2035 lstcon_console_init(void)
2040 memset(&console_session, 0, sizeof(lstcon_session_t));
2042 console_session.ses_id = LST_INVALID_SID;
2043 console_session.ses_state = LST_SESSION_NONE;
2044 console_session.ses_timeout = 0;
2045 console_session.ses_force = 0;
2046 console_session.ses_expired = 0;
2047 console_session.ses_feats_updated = 0;
2048 console_session.ses_features = LST_FEATS_MASK;
2049 console_session.ses_laststamp = cfs_time_current_sec();
2051 mutex_init(&console_session.ses_mutex);
2053 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_list);
2054 CFS_INIT_LIST_HEAD(&console_session.ses_grp_list);
2055 CFS_INIT_LIST_HEAD(&console_session.ses_bat_list);
2056 CFS_INIT_LIST_HEAD(&console_session.ses_trans_list);
2058 LIBCFS_ALLOC(console_session.ses_ndl_hash,
2059 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
2060 if (console_session.ses_ndl_hash == NULL)
2063 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
2064 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
2067 /* initialize acceptor service table */
2068 lstcon_init_acceptor_service();
2070 rc = srpc_add_service(&lstcon_acceptor_service);
2071 LASSERT (rc != -EBUSY);
2073 LIBCFS_FREE(console_session.ses_ndl_hash,
2074 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
2078 rc = srpc_service_add_buffers(&lstcon_acceptor_service,
2079 lstcon_acceptor_service.sv_wi_total);
2085 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
2088 lstcon_rpc_module_init();
2093 srpc_shutdown_service(&lstcon_acceptor_service);
2094 srpc_remove_service(&lstcon_acceptor_service);
2096 LIBCFS_FREE(console_session.ses_ndl_hash,
2097 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
2099 srpc_wait_service_shutdown(&lstcon_acceptor_service);
2105 lstcon_console_fini(void)
2109 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
2111 mutex_lock(&console_session.ses_mutex);
2113 srpc_shutdown_service(&lstcon_acceptor_service);
2114 srpc_remove_service(&lstcon_acceptor_service);
2116 if (console_session.ses_state != LST_SESSION_NONE)
2117 lstcon_session_end();
2119 lstcon_rpc_module_fini();
2121 mutex_unlock(&console_session.ses_mutex);
2123 LASSERT (cfs_list_empty(&console_session.ses_ndl_list));
2124 LASSERT (cfs_list_empty(&console_session.ses_grp_list));
2125 LASSERT (cfs_list_empty(&console_session.ses_bat_list));
2126 LASSERT (cfs_list_empty(&console_session.ses_trans_list));
2128 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
2129 LASSERT (cfs_list_empty(&console_session.ses_ndl_hash[i]));
2132 LIBCFS_FREE(console_session.ses_ndl_hash,
2133 sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
2135 srpc_wait_service_shutdown(&lstcon_acceptor_service);