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, int *retp, 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 if (dst_grp->grp_userland)
1242 LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1244 CERROR("Can't allocate test descriptor\n");
1250 memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen]));
1251 test->tes_hdr.tsb_id = batch->bat_hdr.tsb_id;
1252 test->tes_batch = batch;
1253 test->tes_type = type;
1254 test->tes_oneside = 0; /* TODO */
1255 test->tes_loop = loop;
1256 test->tes_concur = concur;
1257 test->tes_stop_onerr = 1; /* TODO */
1258 test->tes_span = span;
1259 test->tes_dist = dist;
1260 test->tes_cliidx = 0; /* just used for creating RPC */
1261 test->tes_src_grp = src_grp;
1262 test->tes_dst_grp = dst_grp;
1263 CFS_INIT_LIST_HEAD(&test->tes_trans_list);
1265 if (param != NULL) {
1266 test->tes_paramlen = paramlen;
1267 memcpy(&test->tes_param[0], param, paramlen);
1270 rc = lstcon_test_nodes_add(test, result_up);
1275 if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
1276 lstcon_trans_stat()->trs_fwk_errno != 0)
1277 CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type, name);
1279 /* add to test list anyway, so user can check what's going on */
1280 list_add_tail(&test->tes_link, &batch->bat_test_list);
1282 batch->bat_ntest ++;
1283 test->tes_hdr.tsb_index = batch->bat_ntest;
1285 /* hold groups so nobody can change them */
1289 LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
1291 if (dst_grp != NULL)
1292 lstcon_group_put(dst_grp);
1294 if (src_grp != NULL)
1295 lstcon_group_put(src_grp);
1301 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
1303 lstcon_test_t *test;
1305 list_for_each_entry(test, &batch->bat_test_list, tes_link) {
1306 if (idx == test->tes_hdr.tsb_index) {
1316 lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
1317 lstcon_rpc_ent_t *ent_up)
1319 srpc_batch_reply_t *rep = &msg->msg_body.bat_reply;
1321 LASSERT (transop == LST_TRANS_TSBCLIQRY ||
1322 transop == LST_TRANS_TSBSRVQRY);
1324 /* positive errno, framework error code */
1325 if (copy_to_user(&ent_up->rpe_priv[0],
1326 &rep->bar_active, sizeof(rep->bar_active)))
1333 lstcon_test_batch_query(char *name, int testidx, int client,
1334 int timeout, struct list_head *result_up)
1336 lstcon_rpc_trans_t *trans;
1337 struct list_head *translist;
1338 struct list_head *ndlist;
1339 lstcon_tsb_hdr_t *hdr;
1340 lstcon_batch_t *batch;
1341 lstcon_test_t *test = NULL;
1345 rc = lstcon_batch_find(name, &batch);
1347 CDEBUG(D_NET, "Can't find batch: %s\n", name);
1352 translist = &batch->bat_trans_list;
1353 ndlist = &batch->bat_cli_list;
1354 hdr = &batch->bat_hdr;
1357 /* query specified test only */
1358 rc = lstcon_test_find(batch, testidx, &test);
1360 CDEBUG(D_NET, "Can't find test: %d\n", testidx);
1364 translist = &test->tes_trans_list;
1365 ndlist = &test->tes_src_grp->grp_ndl_list;
1366 hdr = &test->tes_hdr;
1369 transop = client ? LST_TRANS_TSBCLIQRY : LST_TRANS_TSBSRVQRY;
1371 rc = lstcon_rpc_trans_ndlist(ndlist, translist, transop, hdr,
1372 lstcon_batrpc_condition, &trans);
1374 CERROR("Can't create transaction: %d\n", rc);
1378 lstcon_rpc_trans_postwait(trans, timeout);
1380 if (testidx == 0 && /* query a batch, not a test */
1381 lstcon_rpc_stat_failure(lstcon_trans_stat(), 0) == 0 &&
1382 lstcon_tsbqry_stat_run(lstcon_trans_stat(), 0) == 0) {
1383 /* all RPCs finished, and no active test */
1384 batch->bat_state = LST_BATCH_IDLE;
1387 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1388 lstcon_tsbrpc_readent);
1389 lstcon_rpc_trans_destroy(trans);
1395 lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
1396 lstcon_rpc_ent_t *ent_up)
1398 srpc_stat_reply_t *rep = &msg->msg_body.stat_reply;
1399 sfw_counters_t *sfwk_stat;
1400 srpc_counters_t *srpc_stat;
1401 lnet_counters_t *lnet_stat;
1403 if (rep->str_status != 0)
1406 sfwk_stat = (sfw_counters_t *)&ent_up->rpe_payload[0];
1407 srpc_stat = (srpc_counters_t *)((char *)sfwk_stat + sizeof(*sfwk_stat));
1408 lnet_stat = (lnet_counters_t *)((char *)srpc_stat + sizeof(*srpc_stat));
1410 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
1411 copy_to_user(srpc_stat, &rep->str_rpc, sizeof(*srpc_stat)) ||
1412 copy_to_user(lnet_stat, &rep->str_lnet, sizeof(*lnet_stat)))
1419 lstcon_ndlist_stat(struct list_head *ndlist,
1420 int timeout, struct list_head *result_up)
1422 struct list_head head;
1423 lstcon_rpc_trans_t *trans;
1426 CFS_INIT_LIST_HEAD(&head);
1428 rc = lstcon_rpc_trans_ndlist(ndlist, &head,
1429 LST_TRANS_STATQRY, NULL, NULL, &trans);
1431 CERROR("Can't create transaction: %d\n", rc);
1435 timeout = (timeout > LST_TRANS_MIN_TIMEOUT) ? timeout :
1436 LST_TRANS_MIN_TIMEOUT;
1437 lstcon_rpc_trans_postwait(trans, timeout);
1439 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1440 lstcon_statrpc_readent);
1441 lstcon_rpc_trans_destroy(trans);
1447 lstcon_group_stat(char *grp_name, int timeout, struct list_head *result_up)
1449 lstcon_group_t *grp;
1452 rc = lstcon_group_find(grp_name, &grp);
1454 CDEBUG(D_NET, "Can't find group %s\n", grp_name);
1458 rc = lstcon_ndlist_stat(&grp->grp_ndl_list, timeout, result_up);
1460 lstcon_group_put(grp);
1466 lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
1467 int timeout, struct list_head *result_up)
1469 lstcon_ndlink_t *ndl;
1470 lstcon_group_t *tmp;
1471 lnet_process_id_t id;
1475 rc = lstcon_group_alloc(NULL, &tmp);
1477 CERROR("Out of memory\n");
1481 for (i = 0 ; i < count; i++) {
1482 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1487 /* add to tmp group */
1488 rc = lstcon_group_ndlink_find(tmp, id, &ndl, 2);
1490 CDEBUG((rc == -ENOMEM) ? D_ERROR : D_NET,
1491 "Failed to find or create %s: %d\n",
1492 libcfs_id2str(id), rc);
1498 lstcon_group_put(tmp);
1502 rc = lstcon_ndlist_stat(&tmp->grp_ndl_list, timeout, result_up);
1504 lstcon_group_put(tmp);
1510 lstcon_debug_ndlist(struct list_head *ndlist,
1511 struct list_head *translist,
1512 int timeout, struct list_head *result_up)
1514 lstcon_rpc_trans_t *trans;
1517 rc = lstcon_rpc_trans_ndlist(ndlist, translist, LST_TRANS_SESQRY,
1518 NULL, lstcon_sesrpc_condition, &trans);
1520 CERROR("Can't create transaction: %d\n", rc);
1524 timeout = (timeout > LST_TRANS_MIN_TIMEOUT) ? timeout :
1525 LST_TRANS_MIN_TIMEOUT;
1527 lstcon_rpc_trans_postwait(trans, timeout);
1529 rc = lstcon_rpc_trans_interpreter(trans, result_up,
1530 lstcon_sesrpc_readent);
1531 lstcon_rpc_trans_destroy(trans);
1537 lstcon_session_debug(int timeout, struct list_head *result_up)
1539 return lstcon_debug_ndlist(&console_session.ses_ndl_list,
1540 NULL, timeout, result_up);
1544 lstcon_batch_debug(int timeout, char *name,
1545 int client, struct list_head *result_up)
1547 lstcon_batch_t *bat;
1550 rc = lstcon_batch_find(name, &bat);
1554 rc = lstcon_debug_ndlist(client ? &bat->bat_cli_list :
1556 NULL, timeout, result_up);
1562 lstcon_group_debug(int timeout, char *name,
1563 struct list_head *result_up)
1565 lstcon_group_t *grp;
1568 rc = lstcon_group_find(name, &grp);
1572 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1573 timeout, result_up);
1574 lstcon_group_put(grp);
1580 lstcon_nodes_debug(int timeout,
1581 int count, lnet_process_id_t *ids_up,
1582 struct list_head *result_up)
1584 lnet_process_id_t id;
1585 lstcon_ndlink_t *ndl;
1586 lstcon_group_t *grp;
1590 rc = lstcon_group_alloc(NULL, &grp);
1592 CDEBUG(D_NET, "Out of memory\n");
1596 for (i = 0; i < count; i++) {
1597 if (copy_from_user(&id, &ids_up[i], sizeof(id))) {
1602 /* node is added to tmp group */
1603 rc = lstcon_group_ndlink_find(grp, id, &ndl, 1);
1605 CERROR("Can't create node link\n");
1611 lstcon_group_put(grp);
1615 rc = lstcon_debug_ndlist(&grp->grp_ndl_list, NULL,
1616 timeout, result_up);
1618 lstcon_group_put(grp);
1624 lstcon_session_match(lst_sid_t sid)
1626 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1627 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1: 0;
1631 lstcon_new_session_id(lst_sid_t *sid)
1633 lnet_process_id_t id;
1635 LASSERT (console_session.ses_state == LST_SESSION_NONE);
1638 sid->ses_nid = id.nid;
1639 sid->ses_stamp = cfs_time_current();
1642 extern srpc_service_t lstcon_acceptor_service;
1645 lstcon_session_new(char *name, int key,
1646 int timeout,int force, lst_sid_t *sid_up)
1651 if (console_session.ses_state != LST_SESSION_NONE) {
1652 /* session exists */
1654 CERROR("Session %s already exists\n",
1655 console_session.ses_name);
1659 rc = lstcon_session_end();
1661 /* lstcon_session_end() only return local error */
1666 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++) {
1667 LASSERT (list_empty(&console_session.ses_ndl_hash[i]));
1670 rc = lstcon_batch_add(LST_DEFAULT_BATCH);
1674 rc = lstcon_rpc_pinger_start();
1676 lstcon_batch_t *bat;
1678 lstcon_batch_find(LST_DEFAULT_BATCH, &bat);
1679 lstcon_batch_destroy(bat);
1684 lstcon_new_session_id(&console_session.ses_id);
1686 console_session.ses_key = key;
1687 console_session.ses_state = LST_SESSION_ACTIVE;
1688 console_session.ses_force = !!force;
1689 console_session.ses_timeout = (timeout <= 0)? LST_CONSOLE_TIMEOUT:
1691 strcpy(console_session.ses_name, name);
1693 if (copy_to_user(sid_up, &console_session.ses_id,
1694 sizeof(lst_sid_t)) == 0)
1697 lstcon_session_end();
1703 lstcon_session_info(lst_sid_t *sid_up, int *key_up,
1704 lstcon_ndlist_ent_t *ndinfo_up, char *name_up, int len)
1706 lstcon_ndlist_ent_t *entp;
1707 lstcon_ndlink_t *ndl;
1710 if (console_session.ses_state != LST_SESSION_ACTIVE)
1713 LIBCFS_ALLOC(entp, sizeof(*entp));
1717 memset(entp, 0, sizeof(*entp));
1719 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link)
1720 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1722 if (copy_to_user(sid_up, &console_session.ses_id, sizeof(lst_sid_t)) ||
1723 copy_to_user(key_up, &console_session.ses_key, sizeof(int)) ||
1724 copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
1725 copy_to_user(name_up, console_session.ses_name, len))
1728 LIBCFS_FREE(entp, sizeof(*entp));
1734 lstcon_session_end()
1736 lstcon_rpc_trans_t *trans;
1737 lstcon_group_t *grp;
1738 lstcon_batch_t *bat;
1741 LASSERT (console_session.ses_state == LST_SESSION_ACTIVE);
1743 rc = lstcon_rpc_trans_ndlist(&console_session.ses_ndl_list,
1744 NULL, LST_TRANS_SESEND, NULL,
1745 lstcon_sesrpc_condition, &trans);
1747 CERROR("Can't create transaction: %d\n", rc);
1751 console_session.ses_shutdown = 1;
1753 lstcon_rpc_pinger_stop();
1755 lstcon_rpc_trans_postwait(trans, LST_TRANS_TIMEOUT);
1757 lstcon_rpc_trans_destroy(trans);
1758 /* User can do nothing even rpc failed, so go on */
1760 /* waiting for orphan rpcs to die */
1761 lstcon_rpc_cleanup_wait();
1763 console_session.ses_id = LST_INVALID_SID;
1764 console_session.ses_state = LST_SESSION_NONE;
1765 console_session.ses_key = 0;
1766 console_session.ses_force = 0;
1768 /* destroy all batches */
1769 while (!list_empty(&console_session.ses_bat_list)) {
1770 bat = list_entry(console_session.ses_bat_list.next,
1771 lstcon_batch_t, bat_link);
1773 lstcon_batch_destroy(bat);
1776 /* destroy all groups */
1777 while (!list_empty(&console_session.ses_grp_list)) {
1778 grp = list_entry(console_session.ses_grp_list.next,
1779 lstcon_group_t, grp_link);
1780 LASSERT (grp->grp_ref == 1);
1782 lstcon_group_put(grp);
1785 /* all nodes should be released */
1786 LASSERT (list_empty(&console_session.ses_ndl_list));
1788 console_session.ses_shutdown = 0;
1789 console_session.ses_expired = 0;
1795 lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
1797 srpc_msg_t *rep = &rpc->srpc_replymsg;
1798 srpc_msg_t *req = &rpc->srpc_reqstbuf->buf_msg;
1799 srpc_join_reqst_t *jreq = &req->msg_body.join_reqst;
1800 srpc_join_reply_t *jrep = &rep->msg_body.join_reply;
1801 lstcon_group_t *grp = NULL;
1802 lstcon_ndlink_t *ndl;
1805 sfw_unpack_message(req);
1807 mutex_down(&console_session.ses_mutex);
1809 jrep->join_sid = console_session.ses_id;
1811 if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
1812 jrep->join_status = ESRCH;
1816 if (jreq->join_sid.ses_nid != LNET_NID_ANY &&
1817 !lstcon_session_match(jreq->join_sid)) {
1818 jrep->join_status = EBUSY;
1822 if (lstcon_group_find(jreq->join_group, &grp) != 0) {
1823 rc = lstcon_group_alloc(jreq->join_group, &grp);
1825 CERROR("Out of memory\n");
1829 list_add_tail(&grp->grp_link,
1830 &console_session.ses_grp_list);
1831 lstcon_group_addref(grp);
1834 if (grp->grp_ref > 2) {
1835 /* Group in using */
1836 jrep->join_status = EBUSY;
1840 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0);
1842 jrep->join_status = EEXIST;
1846 rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1);
1848 CERROR("Out of memory\n");
1852 ndl->ndl_node->nd_state = LST_NODE_ACTIVE;
1853 ndl->ndl_node->nd_timeout = console_session.ses_timeout;
1855 if (grp->grp_userland == 0)
1856 grp->grp_userland = 1;
1858 strcpy(jrep->join_session, console_session.ses_name);
1859 jrep->join_timeout = console_session.ses_timeout;
1860 jrep->join_status = 0;
1864 lstcon_group_put(grp);
1866 mutex_up(&console_session.ses_mutex);
1871 srpc_service_t lstcon_acceptor_service =
1873 .sv_name = "join session",
1874 .sv_handler = lstcon_acceptor_handle,
1875 .sv_bulk_ready = NULL,
1876 .sv_id = SRPC_SERVICE_JOIN,
1877 .sv_concur = SFW_SERVICE_CONCURRENCY,
1880 extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
1882 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
1884 /* initialize console */
1886 lstcon_console_init(void)
1892 memset(&console_session, 0, sizeof(lstcon_session_t));
1894 console_session.ses_id = LST_INVALID_SID;
1895 console_session.ses_state = LST_SESSION_NONE;
1896 console_session.ses_timeout = 0;
1897 console_session.ses_force = 0;
1898 console_session.ses_expired = 0;
1899 console_session.ses_laststamp = cfs_time_current_sec();
1901 init_mutex(&console_session.ses_mutex);
1903 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_list);
1904 CFS_INIT_LIST_HEAD(&console_session.ses_grp_list);
1905 CFS_INIT_LIST_HEAD(&console_session.ses_bat_list);
1906 CFS_INIT_LIST_HEAD(&console_session.ses_trans_list);
1908 LIBCFS_ALLOC(console_session.ses_ndl_hash,
1909 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1910 if (console_session.ses_ndl_hash == NULL)
1913 for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
1914 CFS_INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
1916 rc = srpc_add_service(&lstcon_acceptor_service);
1917 LASSERT (rc != -EBUSY);
1919 LIBCFS_FREE(console_session.ses_ndl_hash,
1920 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1924 n = srpc_service_add_buffers(&lstcon_acceptor_service, SFW_POST_BUFFERS);
1925 if (n != SFW_POST_BUFFERS) {
1930 rc = libcfs_register_ioctl(&lstcon_ioctl_handler);
1933 lstcon_rpc_module_init();
1938 srpc_shutdown_service(&lstcon_acceptor_service);
1939 srpc_remove_service(&lstcon_acceptor_service);
1941 LIBCFS_FREE(console_session.ses_ndl_hash,
1942 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1944 srpc_wait_service_shutdown(&lstcon_acceptor_service);
1950 lstcon_console_fini(void)
1954 mutex_down(&console_session.ses_mutex);
1956 libcfs_deregister_ioctl(&lstcon_ioctl_handler);
1958 srpc_shutdown_service(&lstcon_acceptor_service);
1959 srpc_remove_service(&lstcon_acceptor_service);
1961 if (console_session.ses_state != LST_SESSION_NONE)
1962 lstcon_session_end();
1964 lstcon_rpc_module_fini();
1966 mutex_up(&console_session.ses_mutex);
1968 LASSERT (list_empty(&console_session.ses_ndl_list));
1969 LASSERT (list_empty(&console_session.ses_grp_list));
1970 LASSERT (list_empty(&console_session.ses_bat_list));
1971 LASSERT (list_empty(&console_session.ses_trans_list));
1973 for (i = 0; i < LST_NODE_HASHSIZE; i++) {
1974 LASSERT (list_empty(&console_session.ses_ndl_hash[i]));
1977 LIBCFS_FREE(console_session.ses_ndl_hash,
1978 sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
1980 srpc_wait_service_shutdown(&lstcon_acceptor_service);