1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Author: Liang Zhen <liangzhen@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org
8 * Infrastructure of LST console
12 #include <libcfs/libcfs.h>
13 #include <lnet/lib-lnet.h>
17 #define LST_NODE_STATE_COUNTER(nd, p) \
19 if ((nd)->nd_state == LST_NODE_ACTIVE) \
20 (p)->nle_nactive ++; \
21 else if ((nd)->nd_state == LST_NODE_BUSY) \
23 else if ((nd)->nd_state == LST_NODE_DOWN) \
26 (p)->nle_nunknown ++; \
30 lstcon_session_t console_session;
33 lstcon_node_get(lstcon_node_t *nd)
35 LASSERT (nd->nd_ref >= 1);
41 lstcon_node_find(lnet_process_id_t id, lstcon_node_t **ndpp, int create)
44 unsigned int idx = LNET_NIDADDR(id.nid) % LST_GLOBAL_HASHSIZE;
46 LASSERT (id.nid != LNET_NID_ANY);
48 list_for_each_entry(ndl, &console_session.ses_ndl_hash[idx], ndl_hlink) {
49 if (ndl->ndl_node->nd_id.nid != id.nid ||
50 ndl->ndl_node->nd_id.pid != id.pid)
53 lstcon_node_get(ndl->ndl_node);
54 *ndpp = ndl->ndl_node;
61 LIBCFS_ALLOC(*ndpp, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
65 ndl = (lstcon_ndlink_t *)(*ndpp + 1);
67 ndl->ndl_node = *ndpp;
69 ndl->ndl_node->nd_ref = 1;
70 ndl->ndl_node->nd_id = id;
71 ndl->ndl_node->nd_stamp = cfs_time_current();
72 ndl->ndl_node->nd_state = LST_NODE_UNKNOWN;
73 ndl->ndl_node->nd_timeout = 0;
74 memset(&ndl->ndl_node->nd_ping, 0, sizeof(lstcon_rpc_t));
76 /* queued in global hash & list, no refcount is taken by
77 * global hash & list, if caller release his refcount,
78 * node will be released */
79 list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
80 list_add_tail(&ndl->ndl_link, &console_session.ses_ndl_list);
86 lstcon_node_put(lstcon_node_t *nd)
90 LASSERT (nd->nd_ref > 0);
95 ndl = (lstcon_ndlink_t *)(nd + 1);
97 LASSERT (!list_empty(&ndl->ndl_link));
98 LASSERT (!list_empty(&ndl->ndl_hlink));
100 /* remove from session */
101 list_del(&ndl->ndl_link);
102 list_del(&ndl->ndl_hlink);
104 LIBCFS_FREE(nd, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
108 lstcon_ndlink_find(struct list_head *hash,
109 lnet_process_id_t id, lstcon_ndlink_t **ndlpp, int create)
111 unsigned int idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
112 lstcon_ndlink_t *ndl;
116 if (id.nid == LNET_NID_ANY)
120 list_for_each_entry(ndl, &hash[idx], ndl_hlink) {
121 if (ndl->ndl_node->nd_id.nid != id.nid ||
122 ndl->ndl_node->nd_id.pid != id.pid)
132 /* find or create in session hash */
133 rc = lstcon_node_find(id, &nd, (create == 1) ? 1 : 0);
137 LIBCFS_ALLOC(ndl, sizeof(lstcon_ndlink_t));
146 CFS_INIT_LIST_HEAD(&ndl->ndl_link);
147 list_add_tail(&ndl->ndl_hlink, &hash[idx]);
153 lstcon_ndlink_release(lstcon_ndlink_t *ndl)
155 LASSERT (list_empty(&ndl->ndl_link));
156 LASSERT (!list_empty(&ndl->ndl_hlink));
158 list_del(&ndl->ndl_hlink); /* delete from hash */
159 lstcon_node_put(ndl->ndl_node);
161 LIBCFS_FREE(ndl, sizeof(*ndl));
165 lstcon_group_alloc(char *name, lstcon_group_t **grpp)
170 LIBCFS_ALLOC(grp, offsetof(lstcon_group_t,
171 grp_ndl_hash[LST_NODE_HASHSIZE]));
175 memset(grp, 0, offsetof(lstcon_group_t,
176 grp_ndl_hash[LST_NODE_HASHSIZE]));
180 strcpy(grp->grp_name, name);
182 CFS_INIT_LIST_HEAD(&grp->grp_link);
183 CFS_INIT_LIST_HEAD(&grp->grp_ndl_list);
184 CFS_INIT_LIST_HEAD(&grp->grp_trans_list);
186 for (i = 0; i < LST_NODE_HASHSIZE; i++)
187 CFS_INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
195 lstcon_group_addref(lstcon_group_t *grp)
200 static void lstcon_group_ndlink_release(lstcon_group_t *, lstcon_ndlink_t *);
203 lstcon_group_drain(lstcon_group_t *grp, int keep)
205 lstcon_ndlink_t *ndl;
206 lstcon_ndlink_t *tmp;
208 list_for_each_entry_safe(ndl, tmp, &grp->grp_ndl_list, ndl_link) {
209 if ((ndl->ndl_node->nd_state & keep) == 0)
210 lstcon_group_ndlink_release(grp, ndl);
215 lstcon_group_decref(lstcon_group_t *grp)
219 if (--grp->grp_ref > 0)
222 if (!list_empty(&grp->grp_link))
223 list_del(&grp->grp_link);
225 lstcon_group_drain(grp, 0);
227 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
228 LASSERT (list_empty(&grp->grp_ndl_hash[i]));
231 LIBCFS_FREE(grp, offsetof(lstcon_group_t,
232 grp_ndl_hash[LST_NODE_HASHSIZE]));
236 lstcon_group_find(char *name, lstcon_group_t **grpp)
240 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
241 if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
244 lstcon_group_addref(grp); /* +1 ref for caller */
253 lstcon_group_put(lstcon_group_t *grp)
255 lstcon_group_decref(grp);
259 lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id,
260 lstcon_ndlink_t **ndlpp, int create)
264 rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
268 if (!list_empty(&(*ndlpp)->ndl_link))
271 list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
278 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
280 list_del_init(&ndl->ndl_link);
281 lstcon_ndlink_release(ndl);
286 lstcon_group_ndlink_move(lstcon_group_t *old,
287 lstcon_group_t *new, lstcon_ndlink_t *ndl)
289 unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
292 list_del(&ndl->ndl_hlink);
293 list_del(&ndl->ndl_link);
296 list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
297 list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
304 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
306 lstcon_ndlink_t *ndl;
308 while (!list_empty(&old->grp_ndl_list)) {
309 ndl = list_entry(old->grp_ndl_list.next,
310 lstcon_ndlink_t, ndl_link);
311 lstcon_group_ndlink_move(old, new, ndl);
316 lstcon_sesrpc_condition(int transop, lstcon_node_t *nd, void *arg)
318 lstcon_group_t *grp = (lstcon_group_t *)arg;
321 case LST_TRANS_SESNEW:
322 if (nd->nd_state == LST_NODE_ACTIVE)
326 case LST_TRANS_SESEND:
327 if (nd->nd_state != LST_NODE_ACTIVE)
330 if (grp != NULL && nd->nd_ref > 1)
334 case LST_TRANS_SESQRY:
345 lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
346 lstcon_rpc_ent_t *ent_up)
348 srpc_debug_reply_t *rep;
351 case LST_TRANS_SESNEW:
352 case LST_TRANS_SESEND:
355 case LST_TRANS_SESQRY:
356 rep = &msg->msg_body.dbg_reply;
358 if (copy_to_user(&ent_up->rpe_priv[0],
359 &rep->dbg_timeout, sizeof(int)) ||
360 copy_to_user(&ent_up->rpe_payload[0],
361 &rep->dbg_name, LST_NAME_SIZE))
374 lstcon_group_nodes_add(lstcon_group_t *grp, int count,
375 lnet_process_id_t *ids_up, struct list_head *result_up)
377 lstcon_rpc_trans_t *trans;
378 lstcon_ndlink_t *ndl;
380 lnet_process_id_t id;
384 rc = lstcon_group_alloc(NULL, &tmp);
386 CERROR("Out of memory\n");
390 for (i = 0 ; i < count; i++) {
391 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
396 /* skip if it's in this group already */
397 rc = lstcon_group_ndlink_find(grp, id, &ndl, 0);
401 /* add to tmp group */
402 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 1);
404 CERROR("Can't create ndlink, out of memory\n");
410 lstcon_group_put(tmp);
414 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
415 &tmp->grp_trans_list, LST_TRANS_SESNEW,
416 tmp, lstcon_sesrpc_condition, &trans);
418 CERROR("Can't create transaction: %d\n", rc);
419 lstcon_group_put(tmp);
424 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
426 rc = lstcon_rpc_trans_interpreter(trans, result_up,
427 lstcon_sesrpc_readent);
428 /* destroy all RPGs */
429 lstcon_rpc_trans_destroy(trans);
431 lstcon_group_move(tmp, grp);
432 lstcon_group_put(tmp);
438 lstcon_group_nodes_remove(lstcon_group_t *grp,
439 int count, lnet_process_id_t *ids_up,
440 struct list_head *result_up)
442 lstcon_rpc_trans_t *trans;
443 lstcon_ndlink_t *ndl;
445 lnet_process_id_t id;
449 /* End session and remove node from the group */
451 rc = lstcon_group_alloc(NULL, &tmp);
453 CERROR("Out of memory\n");
457 for (i = 0; i < count; i++) {
458 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
463 /* move node to tmp group */
464 if (lstcon_group_ndlink_find(grp, id, &ndl, 0) == 0)
465 lstcon_group_ndlink_move(grp, tmp, ndl);
468 rc = lstcon_rpc_trans_ndlist(&tmp->grp_ndl_list,
469 &tmp->grp_trans_list, LST_TRANS_SESEND,
470 tmp, lstcon_sesrpc_condition, &trans);
472 CERROR("Can't create transaction: %d\n", rc);
476 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
478 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
480 lstcon_rpc_trans_destroy(trans);
481 /* release nodes anyway, because we can't rollback status */
482 lstcon_group_put(tmp);
486 lstcon_group_move(tmp, grp);
487 lstcon_group_put(tmp);
493 lstcon_group_add(char *name)
498 rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
500 /* find a group with same name */
501 lstcon_group_put(grp);
505 rc = lstcon_group_alloc(name, &grp);
507 CERROR("Can't allocate descriptor for group %s\n", name);
511 list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
517 lstcon_nodes_add(char *name, int count,
518 lnet_process_id_t *ids_up, struct list_head *result_up)
524 LASSERT (ids_up != NULL);
526 rc = lstcon_group_find(name, &grp);
528 CDEBUG(D_NET, "Can't find group %s\n", name);
532 if (grp->grp_ref > 2) {
533 /* referred by other threads or test */
534 CDEBUG(D_NET, "Group %s is busy\n", name);
535 lstcon_group_put(grp);
540 rc = lstcon_group_nodes_add(grp, count, ids_up, result_up);
542 lstcon_group_put(grp);
548 lstcon_group_del(char *name)
550 lstcon_rpc_trans_t *trans;
554 rc = lstcon_group_find(name, &grp);
556 CDEBUG(D_NET, "Can't find group: %s\n", name);
560 if (grp->grp_ref > 2) {
561 /* referred by others threads or test */
562 CDEBUG(D_NET, "Group %s is busy\n", name);
563 lstcon_group_put(grp);
567 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
568 &grp->grp_trans_list, LST_TRANS_SESEND,
569 grp, lstcon_sesrpc_condition, &trans);
571 CERROR("Can't create transaction: %d\n", rc);
572 lstcon_group_put(grp);
576 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
578 lstcon_rpc_trans_destroy(trans);
580 lstcon_group_put(grp);
581 /* -ref for session, it's destroyed,
582 * status can't be rolled back, destroy group anway */
583 lstcon_group_put(grp);
589 lstcon_group_clean(char *name, int args)
591 lstcon_group_t *grp = NULL;
594 rc = lstcon_group_find(name, &grp);
596 CDEBUG(D_NET, "Can't find group %s\n", name);
600 if (grp->grp_ref > 2) {
601 /* referred by test */
602 CDEBUG(D_NET, "Group %s is busy\n", name);
603 lstcon_group_put(grp);
607 args = (LST_NODE_ACTIVE | LST_NODE_BUSY |
608 LST_NODE_DOWN | LST_NODE_UNKNOWN) & ~args;
610 lstcon_group_drain(grp, args);
612 lstcon_group_put(grp);
613 /* release empty group */
614 if (list_empty(&grp->grp_ndl_list))
615 lstcon_group_put(grp);
621 lstcon_nodes_remove(char *name, int count,
622 lnet_process_id_t *ids_up, struct list_head *result_up)
624 lstcon_group_t *grp = NULL;
627 rc = lstcon_group_find(name, &grp);
629 CDEBUG(D_NET, "Can't find group: %s\n", name);
633 if (grp->grp_ref > 2) {
634 /* referred by test */
635 CDEBUG(D_NET, "Group %s is busy\n", name);
636 lstcon_group_put(grp);
640 rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
642 lstcon_group_put(grp);
643 /* release empty group */
644 if (list_empty(&grp->grp_ndl_list))
645 lstcon_group_put(grp);
651 lstcon_group_refresh(char *name, struct list_head *result_up)
653 lstcon_rpc_trans_t *trans;
657 rc = lstcon_group_find(name, &grp);
659 CDEBUG(D_NET, "Can't find group: %s\n", name);
663 if (grp->grp_ref > 2) {
664 /* referred by test */
665 CDEBUG(D_NET, "Group %s is busy\n", name);
666 lstcon_group_put(grp);
670 /* re-invite all inactive nodes int the group */
671 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
672 &grp->grp_trans_list, LST_TRANS_SESNEW,
673 grp, lstcon_sesrpc_condition, &trans);
675 /* local error, return */
676 CDEBUG(D_NET, "Can't create transaction: %d\n", rc);
677 lstcon_group_put(grp);
681 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
683 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
685 lstcon_rpc_trans_destroy(trans);
687 lstcon_group_put(grp);
693 lstcon_group_list(int index, int len, char *name_up)
697 LASSERT (index >= 0);
698 LASSERT (name_up != NULL);
700 list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
702 return copy_to_user(name_up, grp->grp_name, len) ?
711 lstcon_nodes_getent(struct list_head *head, int *index_p,
712 int *count_p, lstcon_node_ent_t *dents_up)
714 lstcon_ndlink_t *ndl;
719 LASSERT (index_p != NULL && count_p != NULL);
720 LASSERT (dents_up != NULL);
721 LASSERT (*index_p >= 0);
722 LASSERT (*count_p > 0);
724 list_for_each_entry(ndl, head, ndl_link) {
725 if (index++ < *index_p)
728 if (count >= *count_p)
732 if (copy_to_user(&dents_up[count].nde_id,
733 &nd->nd_id, sizeof(nd->nd_id)) ||
734 copy_to_user(&dents_up[count].nde_state,
735 &nd->nd_state, sizeof(nd->nd_state)))
741 if (index <= *index_p)
751 lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p,
752 int *index_p, int *count_p, lstcon_node_ent_t *dents_up)
754 lstcon_ndlist_ent_t *gentp;
756 lstcon_ndlink_t *ndl;
759 rc = lstcon_group_find(name, &grp);
761 CDEBUG(D_NET, "Can't find group %s\n", name);
767 rc = lstcon_nodes_getent(&grp->grp_ndl_list,
768 index_p, count_p, dents_up);
769 lstcon_group_put(grp);
774 /* non-verbose query */
775 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t));
777 CERROR("Can't allocate ndlist_ent\n");
778 lstcon_group_put(grp);
783 memset(gentp, 0, sizeof(lstcon_ndlist_ent_t));
785 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link)
786 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
788 rc = copy_to_user(gents_p, gentp,
789 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT: 0;
791 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
793 lstcon_group_put(grp);
799 lstcon_batch_find(char *name, lstcon_batch_t **batpp)
803 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
804 if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
814 lstcon_batch_add(char *name)
820 rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
822 CDEBUG(D_NET, "Batch %s already exists\n", name);
826 LIBCFS_ALLOC(bat, sizeof(lstcon_batch_t));
828 CERROR("Can't allocate descriptor for batch %s\n", name);
832 LIBCFS_ALLOC(bat->bat_cli_hash,
833 sizeof(struct list_head) * LST_NODE_HASHSIZE);
834 if (bat->bat_cli_hash == NULL) {
835 CERROR("Can't allocate hash for batch %s\n", name);
836 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
841 LIBCFS_ALLOC(bat->bat_srv_hash,
842 sizeof(struct list_head) * LST_NODE_HASHSIZE);
843 if (bat->bat_srv_hash == NULL) {
844 CERROR("Can't allocate hash for batch %s\n", name);
845 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
846 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
851 strcpy(bat->bat_name, name);
852 bat->bat_hdr.tsb_index = 0;
853 bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
856 bat->bat_state = LST_BATCH_IDLE;
858 CFS_INIT_LIST_HEAD(&bat->bat_cli_list);
859 CFS_INIT_LIST_HEAD(&bat->bat_srv_list);
860 CFS_INIT_LIST_HEAD(&bat->bat_test_list);
861 CFS_INIT_LIST_HEAD(&bat->bat_trans_list);
863 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
864 CFS_INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
865 CFS_INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
868 list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
874 lstcon_batch_list(int index, int len, char *name_up)
878 LASSERT (name_up != NULL);
879 LASSERT (index >= 0);
881 list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
883 return copy_to_user(name_up,bat->bat_name, len) ?
892 lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
893 int testidx, int *index_p, int *ndent_p,
894 lstcon_node_ent_t *dents_up)
896 lstcon_test_batch_ent_t *entp;
897 struct list_head *clilst;
898 struct list_head *srvlst;
899 lstcon_test_t *test = NULL;
901 lstcon_ndlink_t *ndl;
904 rc = lstcon_batch_find(name, &bat);
906 CDEBUG(D_NET, "Can't find batch %s\n", name);
911 /* query test, test index start from 1 */
912 list_for_each_entry(test, &bat->bat_test_list, tes_link) {
918 CDEBUG(D_NET, "Can't find specified test in batch\n");
923 clilst = (test == NULL) ? &bat->bat_cli_list :
924 &test->tes_src_grp->grp_ndl_list;
925 srvlst = (test == NULL) ? &bat->bat_srv_list :
926 &test->tes_dst_grp->grp_ndl_list;
928 if (dents_up != NULL) {
929 rc = lstcon_nodes_getent((server ? srvlst: clilst),
930 index_p, ndent_p, dents_up);
934 /* non-verbose query */
935 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t));
939 memset(entp, 0, sizeof(lstcon_test_batch_ent_t));
942 entp->u.tbe_batch.bae_ntest = bat->bat_ntest;
943 entp->u.tbe_batch.bae_state = bat->bat_state;
947 entp->u.tbe_test.tse_type = test->tes_type;
948 entp->u.tbe_test.tse_loop = test->tes_loop;
949 entp->u.tbe_test.tse_concur = test->tes_concur;
952 list_for_each_entry(ndl, clilst, ndl_link)
953 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
955 list_for_each_entry(ndl, srvlst, ndl_link)
956 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
958 rc = copy_to_user(ent_up, entp,
959 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
961 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
967 lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
970 case LST_TRANS_TSBRUN:
971 if (nd->nd_state != LST_NODE_ACTIVE)
975 case LST_TRANS_TSBSTOP:
976 if (nd->nd_state != LST_NODE_ACTIVE)
980 case LST_TRANS_TSBCLIQRY:
981 case LST_TRANS_TSBSRVQRY:
989 lstcon_batch_op(lstcon_batch_t *bat, int transop, struct list_head *result_up)
991 lstcon_rpc_trans_t *trans;
994 rc = lstcon_rpc_trans_ndlist(&bat->bat_cli_list,
995 &bat->bat_trans_list, transop,
996 bat, lstcon_batrpc_condition, &trans);
998 CERROR("Can't create transaction: %d\n", rc);
1002 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1004 rc = lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1006 lstcon_rpc_trans_destroy(trans);
1012 lstcon_batch_run(char *name, int timeout, struct list_head *result_up)
1014 lstcon_batch_t *bat;
1017 if (lstcon_batch_find(name, &bat) != 0) {
1018 CDEBUG(D_NET, "Can't find batch %s\n", name);
1022 bat->bat_arg = timeout;
1024 rc = lstcon_batch_op(bat, LST_TRANS_TSBRUN, result_up);
1026 /* mark batch as running if it's started in any node */
1027 if (lstcon_tsbop_stat_success(lstcon_trans_stat(), 0) != 0)
1028 bat->bat_state = LST_BATCH_RUNNING;
1034 lstcon_batch_stop(char *name, int force, struct list_head *result_up)
1036 lstcon_batch_t *bat;
1039 if (lstcon_batch_find(name, &bat) != 0) {
1040 CDEBUG(D_NET, "Can't find batch %s\n", name);
1044 bat->bat_arg = force;
1046 rc = lstcon_batch_op(bat, LST_TRANS_TSBSTOP, result_up);
1048 /* mark batch as stopped if all RPCs finished */
1049 if (lstcon_tsbop_stat_failure(lstcon_trans_stat(), 0) == 0)
1050 bat->bat_state = LST_BATCH_IDLE;
1056 lstcon_batch_destroy(lstcon_batch_t *bat)
1058 lstcon_ndlink_t *ndl;
1059 lstcon_test_t *test;
1062 list_del(&bat->bat_link);
1064 while (!list_empty(&bat->bat_test_list)) {
1065 test = list_entry(bat->bat_test_list.next,
1066 lstcon_test_t, tes_link);
1067 LASSERT (list_empty(&test->tes_trans_list));
1069 list_del(&test->tes_link);
1071 lstcon_group_put(test->tes_src_grp);
1072 lstcon_group_put(test->tes_dst_grp);
1074 LIBCFS_FREE(test, offsetof(lstcon_test_t,
1075 tes_param[test->tes_paramlen]));
1078 LASSERT (list_empty(&bat->bat_trans_list));
1080 while (!list_empty(&bat->bat_cli_list)) {
1081 ndl = list_entry(bat->bat_cli_list.next,
1082 lstcon_ndlink_t, ndl_link);
1083 list_del_init(&ndl->ndl_link);
1085 lstcon_ndlink_release(ndl);
1088 while (!list_empty(&bat->bat_srv_list)) {
1089 ndl = list_entry(bat->bat_srv_list.next,
1090 lstcon_ndlink_t, ndl_link);
1091 list_del_init(&ndl->ndl_link);
1093 lstcon_ndlink_release(ndl);
1096 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1097 LASSERT (list_empty(&bat->bat_cli_hash[i]));
1098 LASSERT (list_empty(&bat->bat_srv_hash[i]));
1101 LIBCFS_FREE(bat->bat_cli_hash,
1102 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1103 LIBCFS_FREE(bat->bat_srv_hash,
1104 sizeof(struct list_head) * LST_NODE_HASHSIZE);
1105 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
1109 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
1111 lstcon_test_t *test;
1112 lstcon_batch_t *batch;
1113 lstcon_ndlink_t *ndl;
1114 struct list_head *hash;
1115 struct list_head *head;
1117 test = (lstcon_test_t *)arg;
1118 LASSERT (test != NULL);
1120 batch = test->tes_batch;
1121 LASSERT (batch != NULL);
1123 if (test->tes_oneside &&
1124 transop == LST_TRANS_TSBSRVADD)
1127 if (nd->nd_state != LST_NODE_ACTIVE)
1130 if (transop == LST_TRANS_TSBCLIADD) {
1131 hash = batch->bat_cli_hash;
1132 head = &batch->bat_cli_list;
1135 LASSERT (transop == LST_TRANS_TSBSRVADD);
1137 hash = batch->bat_srv_hash;
1138 head = &batch->bat_srv_list;
1141 LASSERT (nd->nd_id.nid != LNET_NID_ANY);
1143 if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
1146 if (list_empty(&ndl->ndl_link))
1147 list_add_tail(&ndl->ndl_link, head);
1153 lstcon_test_nodes_add(lstcon_test_t *test, struct list_head *result_up)
1155 lstcon_rpc_trans_t *trans;
1156 lstcon_group_t *grp;
1160 LASSERT (test->tes_src_grp != NULL);
1161 LASSERT (test->tes_dst_grp != NULL);
1163 transop = LST_TRANS_TSBSRVADD;
1164 grp = test->tes_dst_grp;
1166 rc = lstcon_rpc_trans_ndlist(&grp->grp_ndl_list,
1167 &test->tes_trans_list, transop,
1168 test, lstcon_testrpc_condition, &trans);
1170 CERROR("Can't create transaction: %d\n", rc);
1174 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1176 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1177 lstcon_trans_stat()->trs_fwk_errno != 0) {
1178 lstcon_rpc_trans_interpreter(trans, result_up, NULL);
1180 lstcon_rpc_trans_destroy(trans);
1181 /* return if any error */
1182 CDEBUG(D_NET, "Failed to add test %s, "
1183 "RPC error %d, framework error %d\n",
1184 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1185 lstcon_trans_stat()->trs_rpc_errno,
1186 lstcon_trans_stat()->trs_fwk_errno);
1191 lstcon_rpc_trans_destroy(trans);
1193 if (transop == LST_TRANS_TSBCLIADD)
1196 transop = LST_TRANS_TSBCLIADD;
1197 grp = test->tes_src_grp;
1198 test->tes_cliidx = 0;
1200 /* requests to test clients */
1205 lstcon_test_add(char *name, int type, int loop, int concur,
1206 int dist, int span, char *src_name, char * dst_name,
1207 void *param, int paramlen, struct list_head *result_up)
1210 lstcon_group_t *src_grp = NULL;
1211 lstcon_group_t *dst_grp = NULL;
1212 lstcon_test_t *test = NULL;
1213 lstcon_batch_t *batch;
1216 rc = lstcon_batch_find(name, &batch);
1218 CDEBUG(D_NET, "Can't find batch %s\n", name);
1222 if (batch->bat_state != LST_BATCH_IDLE) {
1223 CDEBUG(D_NET, "Can't change running batch %s\n", name);
1227 rc = lstcon_group_find(src_name, &src_grp);
1229 CDEBUG(D_NET, "Can't find group %s\n", src_name);
1233 rc = lstcon_group_find(dst_name, &dst_grp);
1235 CDEBUG(D_NET, "Can't find group %s\n", dst_name);
1239 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1241 CERROR("Can't allocate test descriptor\n");
1247 memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen]));
1248 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1249 test->tes_batch = batch;
1250 test->tes_type = type;
1251 test->tes_oneside = 0; /* TODO */
1252 test->tes_loop = loop;
1253 test->tes_concur = concur;
1254 test->tes_stop_onerr = 1; /* TODO */
1255 test->tes_span = span;
1256 test->tes_dist = dist;
1257 test->tes_cliidx = 0; /* just used for creating RPC */
1258 test->tes_src_grp = src_grp;
1259 test->tes_dst_grp = dst_grp;
1260 CFS_INIT_LIST_HEAD(&test->tes_trans_list);
1262 if (param != NULL) {
1263 test->tes_paramlen = paramlen;
1264 memcpy(&test->tes_param[0], param, paramlen);
1267 rc = lstcon_test_nodes_add(test, result_up);
1272 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1273 lstcon_trans_stat()->trs_fwk_errno != 0)
1274 CDEBUG(D_NET, "Failed to add test %d to batch %s", type, name);
1276 /* add to test list anyway, so user can check what's going on */
1277 list_add_tail(&test->tes_link, &batch->bat_test_list);
1279 batch->bat_ntest ++;
1280 test->tes_hdr.tsb_index = batch->bat_ntest;
1282 /* hold groups so nobody can change them */
1286 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1288 if (dst_grp != NULL)
1289 lstcon_group_put(dst_grp);
1291 if (src_grp != NULL)
1292 lstcon_group_put(src_grp);
1298 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1300 lstcon_test_t *test;
1302 list_for_each_entry(test, &batch->bat_test_list, tes_link) {
1303 if (idx == test->tes_hdr.tsb_index) {
1313 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1314 lstcon_rpc_ent_t *ent_up)
1316 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1318 LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1319 transop == LST_TRANS_TSBSRVQRY);
1321 /* positive errno, framework error code */
1322 if (copy_to_user(&ent_up->rpe_priv[0],
1323 &rep->bar_active, sizeof(rep->bar_active)))
1330 lstcon_test_batch_query(char *name, int testidx, int client,
1331 int timeout, struct list_head *result_up)
1333 lstcon_rpc_trans_t *trans;
1334 struct list_head *translist;
1335 struct list_head *ndlist;
1336 lstcon_tsb_hdr_t *hdr;
1337 lstcon_batch_t *batch;
1338 lstcon_test_t *test = NULL;
1342 rc = lstcon_batch_find(name, &batch);
1344 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1349 translist = &batch->bat_trans_list;
1350 ndlist = &batch->bat_cli_list;
1351 hdr = &batch->bat_hdr;
1354 /* query specified test only */
1355 rc = lstcon_test_find(batch, testidx, &test);
1357 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1361 translist = &test->tes_trans_list;
1362 ndlist = &test->tes_src_grp->grp_ndl_list;
1363 hdr = &test->tes_hdr;
1366 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1368 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1369 lstcon_batrpc_condition, &trans);
1371 CERROR("Can't create transaction: %d\n", rc);
1375 lstcon_rpc_trans_postwait(trans, timeout);
1377 if (testidx == 0 && /* query a batch, not a test */
1378 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1379 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1380 /* all RPCs finished, and no active test */
1381 batch->bat_state = LST_BATCH_IDLE;
1384 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1385 lstcon_tsbrpc_readent);
1386 lstcon_rpc_trans_destroy(trans);
1392 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1393 lstcon_rpc_ent_t *ent_up)
1395 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1396 sfw_counters_t *sfwk_stat;
1397 srpc_counters_t *srpc_stat;
1398 lnet_counters_t *lnet_stat;
1400 if (rep->str_status != 0)
1403 sfwk_stat = (sfw_counters_t *)&ent_up->rpe_payload[0];
1404 srpc_stat = (srpc_counters_t *)((char *)sfwk_stat + sizeof(*sfwk_stat));
1405 lnet_stat = (lnet_counters_t *)((char *)srpc_stat + sizeof(*srpc_stat));
1407 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1408 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1409 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1416 lstcon_ndlist_stat(struct list_head *ndlist,
1417 int timeout, struct list_head *result_up)
1419 struct list_head head;
1420 lstcon_rpc_trans_t *trans;
1423 CFS_INIT_LIST_HEAD(&head);
1425 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1426 LST_TRANS_STATQRY, NULL, NULL, &trans);
1428 CERROR("Can't create transaction: %d\n", rc);
1432 timeout = (timeout > LST_TRANS_MIN_TIMEOUT) ? timeout :
1433 LST_TRANS_MIN_TIMEOUT;
1434 lstcon_rpc_trans_postwait(trans, timeout);
1436 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1437 lstcon_statrpc_readent);
1438 lstcon_rpc_trans_destroy(trans);
1444 lstcon_group_stat(char *grp_name, int timeout, struct list_head *result_up)
1446 lstcon_group_t *grp;
1449 rc = lstcon_group_find(grp_name, &grp);
1451 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1455 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1457 lstcon_group_put(grp);
1463 lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
1464 int timeout, struct list_head *result_up)
1466 lstcon_ndlink_t *ndl;
1467 lstcon_group_t *tmp;
1468 lnet_process_id_t id;
1472 rc = lstcon_group_alloc(NULL, &tmp);
1474 CERROR("Out of memory\n");
1478 for (i = 0 ; i < count; i++) {
1479 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1484 /* add to tmp group */
1485 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1487 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1488 "Failed to find or create %s: %d\n",
1489 libcfs_id2str(id), rc);
1495 lstcon_group_put(tmp);
1499 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1501 lstcon_group_put(tmp);
1507 lstcon_debug_ndlist(struct list_head *ndlist,
1508 struct list_head *translist,
1509 int timeout, struct list_head *result_up)
1511 lstcon_rpc_trans_t *trans;
1514 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1515 NULL, lstcon_sesrpc_condition, &trans);
1517 CERROR("Can't create transaction: %d\n", rc);
1521 timeout = (timeout > LST_TRANS_MIN_TIMEOUT) ? timeout :
1522 LST_TRANS_MIN_TIMEOUT;
1524 lstcon_rpc_trans_postwait(trans, timeout);
1526 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1527 lstcon_sesrpc_readent);
1528 lstcon_rpc_trans_destroy(trans);
1534 lstcon_session_debug(int timeout, struct list_head *result_up)
1536 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1537 NULL, timeout, result_up);
1541 lstcon_batch_debug(int timeout, char *name,
1542 int client, struct list_head *result_up)
1544 lstcon_batch_t *bat;
1547 rc = lstcon_batch_find(name, &bat);
1551 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1553 NULL, timeout, result_up);
1559 lstcon_group_debug(int timeout, char *name,
1560 struct list_head *result_up)
1562 lstcon_group_t *grp;
1565 rc = lstcon_group_find(name, &grp);
1569 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1570 timeout, result_up);
1571 lstcon_group_put(grp);
1577 lstcon_nodes_debug(int timeout,
1578 int count, lnet_process_id_t *ids_up,
1579 struct list_head *result_up)
1581 lnet_process_id_t id;
1582 lstcon_ndlink_t *ndl;
1583 lstcon_group_t *grp;
1587 rc = lstcon_group_alloc(NULL, &grp);
1589 CDEBUG(D_NET, "Out of memory\n");
1593 for (i = 0; i < count; i++) {
1594 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1599 /* node is added to tmp group */
1600 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1602 CERROR("Can't create node link\n");
1608 lstcon_group_put(grp);
1612 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1613 timeout, result_up);
1615 lstcon_group_put(grp);
1621 lstcon_session_match(lst_sid_t sid)
1623 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1624 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1: 0;
1628 lstcon_new_session_id(lst_sid_t *sid)
1630 lnet_process_id_t id;
1632 LASSERT (console_session.ses_state == LST_SESSION_NONE);
1635 sid->ses_nid = id.nid;
1636 sid->ses_stamp = cfs_time_current();
1639 extern srpc_service_t lstcon_acceptor_service;
1642 lstcon_session_new(char *name, int key,
1643 int timeout,int force, lst_sid_t *sid_up)
1648 if (console_session.ses_state != LST_SESSION_NONE) {
1649 /* session exists */
1651 CERROR("Session %s already exists\n",
1652 console_session.ses_name);
1656 rc = lstcon_session_end();
1658 /* lstcon_session_end() only return local error */
1663 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++) {
1664 LASSERT (list_empty(&console_session.ses_ndl_hash[i]));
1667 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1671 rc = lstcon_rpc_pinger_start();
1673 lstcon_batch_t *bat;
1675 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1676 lstcon_batch_destroy(bat);
1681 lstcon_new_session_id(&console_session.ses_id);
1683 console_session.ses_key = key;
1684 console_session.ses_state = LST_SESSION_ACTIVE;
1685 console_session.ses_force = !!force;
1686 console_session.ses_timeout = (timeout <= 0)? LST_CONSOLE_TIMEOUT:
1688 strcpy(console_session.ses_name, name);
1690 if (copy_to_user(sid_up, &console_session.ses_id,
1691 sizeof(lst_sid_t)) == 0)
1694 lstcon_session_end();
1700 lstcon_session_info(lst_sid_t *sid_up, int *key_up,
1701 lstcon_ndlist_ent_t *ndinfo_up, char *name_up, int len)
1703 lstcon_ndlist_ent_t *entp;
1704 lstcon_ndlink_t *ndl;
1707 if (console_session.ses_state != LST_SESSION_ACTIVE)
1710 LIBCFS_ALLOC(entp, sizeof(*entp));
1714 memset(entp, 0, sizeof(*entp));
1716 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link)
1717 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1719 if (copy_to_user(sid_up, &console_session.ses_id, sizeof(lst_sid_t)) ||
1720 copy_to_user(key_up, &console_session.ses_key, sizeof(int)) ||
1721 copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1722 copy_to_user(name_up, console_session.ses_name, len))
1725 LIBCFS_FREE(entp, sizeof(*entp));
1731 lstcon_session_end()
1733 lstcon_rpc_trans_t *trans;
1734 lstcon_group_t *grp;
1735 lstcon_batch_t *bat;
1738 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1740 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1741 NULL, LST_TRANS_SESEND, NULL,
1742 lstcon_sesrpc_condition, &trans);
1744 CERROR("Can't create transaction: %d\n", rc);
1748 console_session.ses_shutdown = 1;
1750 lstcon_rpc_pinger_stop();
1752 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1754 lstcon_rpc_trans_destroy(trans);
1755 /* User can do nothing even rpc failed, so go on */
1757 /* waiting for orphan rpcs to die */
1758 lstcon_rpc_cleanup_wait();
1760 console_session.ses_id = LST_INVALID_SID;
1761 console_session.ses_state = LST_SESSION_NONE;
1762 console_session.ses_key = 0;
1763 console_session.ses_force = 0;
1765 /* destroy all batches */
1766 while (!list_empty(&console_session.ses_bat_list)) {
1767 bat = list_entry(console_session.ses_bat_list.next,
1768 lstcon_batch_t, bat_link);
1770 lstcon_batch_destroy(bat);
1773 /* destroy all groups */
1774 while (!list_empty(&console_session.ses_grp_list)) {
1775 grp = list_entry(console_session.ses_grp_list.next,
1776 lstcon_group_t, grp_link);
1777 LASSERT (grp->grp_ref == 1);
1779 lstcon_group_put(grp);
1782 /* all nodes should be released */
1783 LASSERT (list_empty(&console_session.ses_ndl_list));
1785 console_session.ses_shutdown = 0;
1786 console_session.ses_expired = 0;
1792 lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
1794 srpc_msg_t *rep = &rpc->srpc_replymsg;
1795 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1796 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1797 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1798 lstcon_group_t *grp = NULL;
1799 lstcon_ndlink_t *ndl;
1802 sfw_unpack_message(req);
1804 mutex_down(&console_session.ses_mutex);
1806 jrep->join_sid = console_session.ses_id;
1808 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1809 jrep->join_status = ESRCH;
1813 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1814 !lstcon_session_match(jreq->join_sid)) {
1815 jrep->join_status = EBUSY;
1819 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1820 rc = lstcon_group_alloc(jreq->join_group, &grp);
1822 CERROR("Out of memory\n");
1826 list_add_tail(&grp->grp_link,
1827 &console_session.ses_grp_list);
1828 lstcon_group_addref(grp);
1831 if (grp->grp_ref > 2) {
1832 /* Group in using */
1833 jrep->join_status = EBUSY;
1837 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1839 jrep->join_status = EEXIST;
1843 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1845 CERROR("Out of memory\n");
1849 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1850 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1852 strcpy(jrep->join_session, console_session.ses_name);
1853 jrep->join_timeout = console_session.ses_timeout;
1854 jrep->join_status = 0;
1858 lstcon_group_put(grp);
1860 mutex_up(&console_session.ses_mutex);
1865 srpc_service_t lstcon_acceptor_service =
1867 .sv_name = "join session",
1868 .sv_handler = lstcon_acceptor_handle,
1869 .sv_bulk_ready = NULL,
1870 .sv_id = SRPC_SERVICE_JOIN,
1871 .sv_concur = SFW_SERVICE_CONCURRENCY,
1874 extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
1876 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
1878 /* initialize console */
1880 lstcon_console_init(void)
1886 memset(&console_session, 0, sizeof(lstcon_session_t));
1888 console_session.ses_id = LST_INVALID_SID;
1889 console_session.ses_state = LST_SESSION_NONE;
1890 console_session.ses_timeout = 0;
1891 console_session.ses_force = 0;
1892 console_session.ses_expired = 0;
1893 console_session.ses_laststamp = cfs_time_current_sec();
1895 init_mutex(&console_session.ses_mutex);
1897 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_list);
1898 CFS_INIT_LIST_HEAD(&console_session.ses_grp_list);
1899 CFS_INIT_LIST_HEAD(&console_session.ses_bat_list);
1900 CFS_INIT_LIST_HEAD(&console_session.ses_trans_list);
1902 LIBCFS_ALLOC(console_session.ses_ndl_hash,
1903 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1904 if (console_session.ses_ndl_hash == NULL)
1907 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1908 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
1910 rc = srpc_add_service(&lstcon_acceptor_service);
1911 LASSERT (rc != -EBUSY);
1913 LIBCFS_FREE(console_session.ses_ndl_hash,
1914 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1918 n = srpc_service_add_buffers(&lstcon_acceptor_service, SFW_POST_BUFFERS);
1919 if (n != SFW_POST_BUFFERS) {
1924 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
1927 lstcon_rpc_module_init();
1932 srpc_shutdown_service(&lstcon_acceptor_service);
1933 srpc_remove_service(&lstcon_acceptor_service);
1935 LIBCFS_FREE(console_session.ses_ndl_hash,
1936 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1938 srpc_wait_service_shutdown(&lstcon_acceptor_service);
1944 lstcon_console_fini(void)
1948 mutex_down(&console_session.ses_mutex);
1950 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
1952 srpc_shutdown_service(&lstcon_acceptor_service);
1953 srpc_remove_service(&lstcon_acceptor_service);
1955 if (console_session.ses_state != LST_SESSION_NONE)
1956 lstcon_session_end();
1958 lstcon_rpc_module_fini();
1960 mutex_up(&console_session.ses_mutex);
1962 LASSERT (list_empty(&console_session.ses_ndl_list));
1963 LASSERT (list_empty(&console_session.ses_grp_list));
1964 LASSERT (list_empty(&console_session.ses_bat_list));
1965 LASSERT (list_empty(&console_session.ses_trans_list));
1967 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1968 LASSERT (list_empty(&console_session.ses_ndl_hash[i]));
1971 LIBCFS_FREE(console_session.ses_ndl_hash,
1972 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1974 srpc_wait_service_shutdown(&lstcon_acceptor_service);