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 * Console framework rpcs
12 #include <libcfs/libcfs.h>
13 #include <lnet/lib-lnet.h>
18 void lstcon_rpc_stat_reply(int, srpc_msg_t *,
19 lstcon_node_t *, lstcon_trans_stat_t *);
22 lstcon_rpc_done(srpc_client_rpc_t *rpc)
24 lstcon_rpc_t *crpc = (lstcon_rpc_t *)rpc->crpc_priv;
26 LASSERT (crpc != NULL && rpc == crpc->crp_rpc);
27 LASSERT (crpc->crp_posted && !crpc->crp_finished);
29 spin_lock(&rpc->crpc_lock);
31 if (crpc->crp_trans == NULL) {
32 /* Orphan RPC is not in any transaction,
33 * I'm just a poor body and nobody loves me */
34 spin_unlock(&rpc->crpc_lock);
41 /* not an orphan RPC */
42 crpc->crp_finished = 1;
44 if (crpc->crp_stamp == 0) {
46 LASSERT (crpc->crp_status == 0);
48 crpc->crp_stamp = cfs_time_current();
49 crpc->crp_status = rpc->crpc_status;
52 /* wakeup (transaction)thread if I'm the last RPC in the transaction */
53 if (atomic_dec_and_test(&crpc->crp_trans->tas_remaining))
54 cfs_waitq_signal(&crpc->crp_trans->tas_waitq);
56 spin_unlock(&rpc->crpc_lock);
60 lstcon_rpc_init(lstcon_node_t *nd, int service,
61 int npg, int cached, lstcon_rpc_t *crpc)
64 crpc->crp_rpc = sfw_create_rpc(nd->nd_id, service,
65 npg, npg * CFS_PAGE_SIZE,
66 lstcon_rpc_done, (void *)crpc);
67 if (crpc->crp_rpc == NULL)
70 crpc->crp_trans = NULL;
73 crpc->crp_finished = 0;
74 crpc->crp_unpacked = 0;
77 crpc->crp_static = !cached;
78 CFS_INIT_LIST_HEAD(&crpc->crp_link);
80 atomic_inc(&console_session.ses_rpc_counter);
86 lstcon_rpc_prep(lstcon_node_t *nd, int service,
87 int npg, lstcon_rpc_t **crpcpp)
89 lstcon_rpc_t *crpc = NULL;
92 spin_lock(&console_session.ses_rpc_lock);
94 if (!list_empty(&console_session.ses_rpc_freelist)) {
95 crpc = list_entry(console_session.ses_rpc_freelist.next,
96 lstcon_rpc_t, crp_link);
97 list_del_init(&crpc->crp_link);
100 spin_unlock(&console_session.ses_rpc_lock);
103 LIBCFS_ALLOC(crpc, sizeof(*crpc));
108 rc = lstcon_rpc_init(nd, service, npg, 1, crpc);
114 LIBCFS_FREE(crpc, sizeof(*crpc));
120 lstcon_rpc_put(lstcon_rpc_t *crpc)
122 srpc_bulk_t *bulk = &crpc->crp_rpc->crpc_bulk;
125 LASSERT (list_empty(&crpc->crp_link));
127 for (i = 0; i < bulk->bk_niov; i++) {
128 if (bulk->bk_iovs[i].kiov_page == NULL)
131 cfs_free_page(bulk->bk_iovs[i].kiov_page);
134 srpc_client_rpc_decref(crpc->crp_rpc);
136 if (crpc->crp_static) {
137 /* Static RPC, not allocated */
138 memset(crpc, 0, sizeof(*crpc));
139 crpc->crp_static = 1;
142 spin_lock(&console_session.ses_rpc_lock);
144 list_add(&crpc->crp_link, &console_session.ses_rpc_freelist);
146 spin_unlock(&console_session.ses_rpc_lock);
149 /* RPC is not alive now */
150 atomic_dec(&console_session.ses_rpc_counter);
154 lstcon_rpc_post(lstcon_rpc_t *crpc)
156 lstcon_rpc_trans_t *trans = crpc->crp_trans;
158 LASSERT (trans != NULL);
160 atomic_inc(&trans->tas_remaining);
161 crpc->crp_posted = 1;
163 sfw_post_rpc(crpc->crp_rpc);
167 lstcon_rpc_trans_name(int transop)
169 if (transop == LST_TRANS_SESNEW)
172 if (transop == LST_TRANS_SESEND)
175 if (transop == LST_TRANS_SESQRY)
178 if (transop == LST_TRANS_SESPING)
181 if (transop == LST_TRANS_TSBCLIADD)
184 if (transop == LST_TRANS_TSBSRVADD)
187 if (transop == LST_TRANS_TSBRUN)
190 if (transop == LST_TRANS_TSBSTOP)
193 if (transop == LST_TRANS_TSBCLIQRY)
196 if (transop == LST_TRANS_TSBSRVQRY)
199 if (transop == LST_TRANS_STATQRY)
206 lstcon_rpc_trans_prep(struct list_head *translist,
207 int transop, lstcon_rpc_trans_t **transpp)
209 lstcon_rpc_trans_t *trans;
211 if (translist != NULL) {
212 list_for_each_entry(trans, translist, tas_link) {
213 /* Can't enqueue two private transaction on
215 if ((trans->tas_opc & transop) == LST_TRANS_PRIVATE)
220 /* create a trans group */
221 LIBCFS_ALLOC(trans, sizeof(*trans));
225 trans->tas_opc = transop;
227 if (translist == NULL)
228 CFS_INIT_LIST_HEAD(&trans->tas_olink);
230 list_add_tail(&trans->tas_olink, translist);
232 list_add_tail(&trans->tas_link, &console_session.ses_trans_list);
234 CFS_INIT_LIST_HEAD(&trans->tas_rpcs_list);
235 atomic_set(&trans->tas_remaining, 0);
236 cfs_waitq_init(&trans->tas_waitq);
244 lstcon_rpc_trans_addreq(lstcon_rpc_trans_t *trans, lstcon_rpc_t *crpc)
246 list_add_tail(&crpc->crp_link, &trans->tas_rpcs_list);
247 crpc->crp_trans = trans;
251 lstcon_rpc_trans_abort(lstcon_rpc_trans_t *trans, int error)
253 srpc_client_rpc_t *rpc;
257 list_for_each_entry (crpc, &trans->tas_rpcs_list, crp_link) {
260 spin_lock(&rpc->crpc_lock);
262 if (!crpc->crp_posted || crpc->crp_stamp != 0) {
263 /* rpc done or aborted already */
264 spin_unlock(&rpc->crpc_lock);
268 crpc->crp_stamp = cfs_time_current();
269 crpc->crp_status = error;
271 spin_unlock(&rpc->crpc_lock);
275 if (error != ETIMEDOUT)
279 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
282 nd->nd_stamp = crpc->crp_stamp;
283 nd->nd_state = LST_NODE_DOWN;
288 lstcon_rpc_trans_check(lstcon_rpc_trans_t *trans)
290 if (console_session.ses_shutdown &&
291 !list_empty(&trans->tas_olink)) /* It's not an end session RPC */
294 return (atomic_read(&trans->tas_remaining) == 0) ? 1: 0;
298 lstcon_rpc_trans_postwait(lstcon_rpc_trans_t *trans, int timeout)
303 if (list_empty(&trans->tas_rpcs_list))
306 if (timeout < LST_TRANS_MIN_TIMEOUT)
307 timeout = LST_TRANS_MIN_TIMEOUT;
309 CDEBUG(D_NET, "Transaction %s started\n",
310 lstcon_rpc_trans_name(trans->tas_opc));
312 /* post all requests */
313 list_for_each_entry (crpc, &trans->tas_rpcs_list, crp_link) {
314 LASSERT (!crpc->crp_posted);
316 lstcon_rpc_post(crpc);
319 mutex_up(&console_session.ses_mutex);
321 rc = cfs_waitq_wait_event_interruptible_timeout(trans->tas_waitq,
322 lstcon_rpc_trans_check(trans),
325 rc = (rc > 0)? 0: ((rc < 0)? -EINTR: -ETIMEDOUT);
327 mutex_down(&console_session.ses_mutex);
329 if (console_session.ses_shutdown)
333 /* treat short timeout as canceled */
334 if (rc == -ETIMEDOUT && timeout < LST_TRANS_MIN_TIMEOUT * 2)
337 lstcon_rpc_trans_abort(trans, rc);
340 CDEBUG(D_NET, "Transaction %s stopped: %d\n",
341 lstcon_rpc_trans_name(trans->tas_opc), rc);
343 lstcon_rpc_trans_stat(trans, lstcon_trans_stat());
349 lstcon_rpc_get_reply(lstcon_rpc_t *crpc, srpc_msg_t **msgpp)
351 lstcon_node_t *nd = crpc->crp_node;
352 srpc_client_rpc_t *rpc = crpc->crp_rpc;
353 srpc_generic_reply_t *rep;
355 LASSERT (nd != NULL && rpc != NULL);
356 LASSERT (crpc->crp_stamp != 0);
358 if (crpc->crp_status != 0) {
360 return crpc->crp_status;
363 *msgpp = &rpc->crpc_replymsg;
364 if (!crpc->crp_unpacked) {
365 sfw_unpack_message(*msgpp);
366 crpc->crp_unpacked = 1;
369 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
372 nd->nd_stamp = crpc->crp_stamp;
373 rep = &(*msgpp)->msg_body.reply;
375 if (rep->sid.ses_nid == LNET_NID_ANY)
376 nd->nd_state = LST_NODE_UNKNOWN;
377 else if (lstcon_session_match(rep->sid))
378 nd->nd_state = LST_NODE_ACTIVE;
380 nd->nd_state = LST_NODE_BUSY;
386 lstcon_rpc_trans_stat(lstcon_rpc_trans_t *trans, lstcon_trans_stat_t *stat)
389 srpc_client_rpc_t *rpc;
393 LASSERT (stat != NULL);
395 memset(stat, 0, sizeof(*stat));
397 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
398 lstcon_rpc_stat_total(stat, 1);
402 LASSERT (crpc->crp_stamp != 0);
404 error = lstcon_rpc_get_reply(crpc, &rep);
406 lstcon_rpc_stat_failure(stat, 1);
407 if (stat->trs_rpc_errno == 0)
408 stat->trs_rpc_errno = -error;
413 lstcon_rpc_stat_success(stat, 1);
415 lstcon_rpc_stat_reply(trans->tas_opc, rep,
416 crpc->crp_node, stat);
419 CDEBUG(D_NET, "transaction %s : success %d, failure %d, total %d, "
420 "RPC error(%d), Framework error(%d)\n",
421 lstcon_rpc_trans_name(trans->tas_opc),
422 lstcon_rpc_stat_success(stat, 0),
423 lstcon_rpc_stat_failure(stat, 0),
424 lstcon_rpc_stat_total(stat, 0),
425 stat->trs_rpc_errno, stat->trs_fwk_errno);
431 lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
432 struct list_head *head_up,
433 lstcon_rpc_readent_func_t readent)
435 struct list_head tmp;
436 struct list_head *next;
437 lstcon_rpc_ent_t *ent;
438 srpc_generic_reply_t *rep;
439 srpc_client_rpc_t *rpc;
447 LASSERT (head_up != NULL);
451 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
452 if (copy_from_user(&tmp, next, sizeof(struct list_head)))
455 if (tmp.next == head_up)
460 ent = list_entry(next, lstcon_rpc_ent_t, rpe_link);
464 LASSERT (crpc->crp_stamp != 0);
466 error = lstcon_rpc_get_reply(crpc, &msg);
470 dur = cfs_time_sub(crpc->crp_stamp,
471 console_session.ses_id.ses_stamp);
472 cfs_duration_usec(dur, &tv);
474 if (copy_to_user(&ent->rpe_peer,
475 &nd->nd_id, sizeof(lnet_process_id_t)) ||
476 copy_to_user(&ent->rpe_stamp, &tv, sizeof(tv)) ||
477 copy_to_user(&ent->rpe_state,
478 &nd->nd_state, sizeof(nd->nd_state)) ||
479 copy_to_user(&ent->rpe_rpc_errno, &error, sizeof(error)))
486 rep = (srpc_generic_reply_t *)&msg->msg_body.reply;
488 if (copy_to_user(&ent->rpe_sid,
489 &rep->sid, sizeof(lst_sid_t)) ||
490 copy_to_user(&ent->rpe_fwk_errno,
491 &rep->status, sizeof(rep->status)))
497 if ((error = readent(trans->tas_opc, msg, ent)) != 0)
505 lstcon_rpc_trans_destroy(lstcon_rpc_trans_t *trans)
507 srpc_client_rpc_t *rpc;
512 list_for_each_entry_safe(crpc, tmp,
513 &trans->tas_rpcs_list, crp_link) {
516 spin_lock(&rpc->crpc_lock);
518 /* free it if not posted or finished already */
519 if (!crpc->crp_posted || crpc->crp_finished) {
520 spin_unlock(&rpc->crpc_lock);
522 list_del_init(&crpc->crp_link);
523 lstcon_rpc_put(crpc);
528 /* rpcs can be still not callbacked (even LNetMDUnlink is called)
529 * because huge timeout for inaccessible network, don't make
530 * user wait for them, just abandon them, they will be recycled
533 LASSERT (crpc->crp_status != 0);
535 crpc->crp_node = NULL;
536 crpc->crp_trans = NULL;
537 list_del_init(&crpc->crp_link);
540 spin_unlock(&rpc->crpc_lock);
542 atomic_dec(&trans->tas_remaining);
545 LASSERT (atomic_read(&trans->tas_remaining) == 0);
547 list_del(&trans->tas_link);
548 if (!list_empty(&trans->tas_olink))
549 list_del(&trans->tas_olink);
551 CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
552 lstcon_rpc_trans_name(trans->tas_opc), count);
554 LIBCFS_FREE(trans, sizeof(*trans));
560 lstcon_sesrpc_prep(lstcon_node_t *nd, int transop, lstcon_rpc_t **crpc)
562 srpc_mksn_reqst_t *msrq;
563 srpc_rmsn_reqst_t *rsrq;
567 case LST_TRANS_SESNEW:
568 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION, 0, crpc);
572 msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
573 msrq->mksn_sid = console_session.ses_id;
574 msrq->mksn_force = console_session.ses_force;
575 strncpy(msrq->mksn_name, console_session.ses_name,
576 strlen(console_session.ses_name));
579 case LST_TRANS_SESEND:
580 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION, 0, crpc);
584 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
585 rsrq->rmsn_sid = console_session.ses_id;
596 lstcon_dbgrpc_prep(lstcon_node_t *nd, lstcon_rpc_t **crpc)
598 srpc_debug_reqst_t *drq;
601 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, 0, crpc);
605 drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
607 drq->dbg_sid = console_session.ses_id;
614 lstcon_batrpc_prep(lstcon_node_t *nd, int transop,
615 lstcon_tsb_hdr_t *tsb, lstcon_rpc_t **crpc)
617 lstcon_batch_t *batch;
618 srpc_batch_reqst_t *brq;
621 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, 0, crpc);
625 brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
627 brq->bar_sid = console_session.ses_id;
628 brq->bar_bid = tsb->tsb_id;
629 brq->bar_testidx = tsb->tsb_index;
630 brq->bar_opc = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
631 (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP:
632 SRPC_BATCH_OPC_QUERY);
634 if (transop != LST_TRANS_TSBRUN &&
635 transop != LST_TRANS_TSBSTOP)
638 LASSERT (tsb->tsb_index == 0);
640 batch = (lstcon_batch_t *)tsb;
641 brq->bar_arg = batch->bat_arg;
647 lstcon_statrpc_prep(lstcon_node_t *nd, lstcon_rpc_t **crpc)
649 srpc_stat_reqst_t *srq;
652 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_QUERY_STAT, 0, crpc);
656 srq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.stat_reqst;
658 srq->str_sid = console_session.ses_id;
659 srq->str_type = 0; /* XXX remove it */
665 lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov)
667 lnet_process_id_t *pid;
670 i = idx / (CFS_PAGE_SIZE / sizeof(lnet_process_id_t));
674 pid = (lnet_process_id_t *)cfs_page_address(kiov[i].kiov_page);
676 return &pid[idx % (CFS_PAGE_SIZE / sizeof(lnet_process_id_t))];
680 lstcon_dstnodes_prep(lstcon_group_t *grp, int idx,
681 int dist, int span, int nkiov, lnet_kiov_t *kiov)
683 lnet_process_id_t *pid;
684 lstcon_ndlink_t *ndl;
692 LASSERT (grp->grp_nnode >= 1);
694 if (span > grp->grp_nnode)
697 start = ((idx / dist) * span) % grp->grp_nnode;
698 end = ((idx / dist) * span + span - 1) % grp->grp_nnode;
700 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
707 if (i > (end >= start ? end: grp->grp_nnode))
710 pid = lstcon_next_id((i - start), nkiov, kiov);
715 if (start <= end) /* done */
718 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
719 if (i > grp->grp_nnode + end)
723 pid = lstcon_next_id((i - start), nkiov, kiov);
732 lstcon_pingrpc_prep(lst_test_ping_param_t *param, srpc_test_reqst_t *req)
734 test_ping_req_t *prq = &req->tsr_u.ping;
736 prq->png_size = param->png_size;
737 prq->png_flags = param->png_flags;
743 lstcon_bulkrpc_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
745 test_bulk_req_t *brq = &req->tsr_u.bulk;
747 brq->blk_opc = param->blk_opc;
748 brq->blk_npg = (param->blk_size + CFS_PAGE_SIZE - 1) / CFS_PAGE_SIZE;
749 brq->blk_flags = param->blk_flags;
755 lstcon_testrpc_prep(lstcon_node_t *nd, int transop,
756 lstcon_test_t *test, lstcon_rpc_t **crpc)
758 lstcon_group_t *sgrp = test->tes_src_grp;
759 lstcon_group_t *dgrp = test->tes_dst_grp;
760 srpc_test_reqst_t *trq;
766 if (transop == LST_TRANS_TSBCLIADD)
767 n = sfw_id_pages(test->tes_span);
769 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, n, crpc);
773 trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
775 if (transop == LST_TRANS_TSBSRVADD) {
776 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
777 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
778 int nmax = (ndist + nspan - 1) / nspan;
781 trq->tsr_loop = nmax * test->tes_dist * test->tes_concur;
784 bulk = &(*crpc)->crp_rpc->crpc_bulk;
786 for (i = 0; i < n; i++) {
787 bulk->bk_iovs[i].kiov_offset = 0;
788 bulk->bk_iovs[i].kiov_len = CFS_PAGE_SIZE;
789 bulk->bk_iovs[i].kiov_page = cfs_alloc_page(CFS_ALLOC_STD);
791 if (bulk->bk_iovs[i].kiov_page != NULL)
794 lstcon_rpc_put(*crpc);
800 LASSERT (transop == LST_TRANS_TSBCLIADD);
802 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
803 test->tes_cliidx++, test->tes_dist,
804 test->tes_span, n, &bulk->bk_iovs[0]);
806 lstcon_rpc_put(*crpc);
810 trq->tsr_ndest = test->tes_span;
811 trq->tsr_loop = test->tes_loop;
814 trq->tsr_sid = console_session.ses_id;
815 trq->tsr_bid = test->tes_hdr.tsb_id;
816 trq->tsr_concur = test->tes_concur;
817 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
818 trq->tsr_stop_onerr = test->tes_stop_onerr;
820 switch (test->tes_type) {
822 trq->tsr_service = SRPC_SERVICE_PING;
823 rc = lstcon_pingrpc_prep((lst_test_ping_param_t *)&test->tes_param[0], trq);
826 trq->tsr_service = SRPC_SERVICE_BRW;
827 rc = lstcon_bulkrpc_prep((lst_test_bulk_param_t *)&test->tes_param[0], trq);
838 lstcon_rpc_stat_reply(int transop, srpc_msg_t *msg,
839 lstcon_node_t *nd, lstcon_trans_stat_t *stat)
841 srpc_mksn_reply_t *mksn_rep;
842 srpc_rmsn_reply_t *rmsn_rep;
843 srpc_debug_reply_t *dbg_rep;
844 srpc_batch_reply_t *bat_rep;
845 srpc_test_reply_t *test_rep;
846 srpc_stat_reply_t *stat_rep;
850 case LST_TRANS_SESNEW:
851 mksn_rep = &msg->msg_body.mksn_reply;
853 if (mksn_rep->mksn_status == 0) {
854 lstcon_sesop_stat_success(stat, 1);
855 /* session timeout on remote node */
856 nd->nd_timeout = mksn_rep->mksn_timeout;
860 LASSERT (mksn_rep->mksn_status == EBUSY ||
861 mksn_rep->mksn_status == EINVAL);
863 lstcon_sesop_stat_failure(stat, 1);
864 errno = mksn_rep->mksn_status;
867 case LST_TRANS_SESEND:
868 rmsn_rep = &msg->msg_body.rmsn_reply;
869 /* ESRCH is not an error for end session */
870 if (rmsn_rep->rmsn_status == 0 ||
871 rmsn_rep->rmsn_status == ESRCH) {
872 lstcon_sesop_stat_success(stat, 1);
876 LASSERT (rmsn_rep->rmsn_status == EBUSY ||
877 rmsn_rep->rmsn_status == EINVAL);
879 lstcon_sesop_stat_failure(stat, 1);
880 errno = rmsn_rep->rmsn_status;
883 case LST_TRANS_SESQRY:
884 case LST_TRANS_SESPING:
885 dbg_rep = &msg->msg_body.dbg_reply;
887 if (dbg_rep->dbg_status == ESRCH) {
888 lstcon_sesqry_stat_unknown(stat, 1);
892 LASSERT (dbg_rep->dbg_status == 0);
894 if (lstcon_session_match(dbg_rep->dbg_sid))
895 lstcon_sesqry_stat_active(stat, 1);
897 lstcon_sesqry_stat_busy(stat, 1);
900 case LST_TRANS_TSBRUN:
901 case LST_TRANS_TSBSTOP:
902 bat_rep = &msg->msg_body.bat_reply;
904 if (bat_rep->bar_status == 0) {
905 lstcon_tsbop_stat_success(stat, 1);
909 if (bat_rep->bar_status == EPERM &&
910 transop == LST_TRANS_TSBSTOP) {
911 lstcon_tsbop_stat_success(stat, 1);
915 lstcon_tsbop_stat_failure(stat, 1);
916 errno = bat_rep->bar_status;
919 case LST_TRANS_TSBCLIQRY:
920 case LST_TRANS_TSBSRVQRY:
921 bat_rep = &msg->msg_body.bat_reply;
923 if (bat_rep->bar_active != 0)
924 lstcon_tsbqry_stat_run(stat, 1);
926 lstcon_tsbqry_stat_idle(stat, 1);
928 if (bat_rep->bar_status == 0)
931 lstcon_tsbqry_stat_failure(stat, 1);
932 errno = bat_rep->bar_status;
935 case LST_TRANS_TSBCLIADD:
936 case LST_TRANS_TSBSRVADD:
937 test_rep = &msg->msg_body.tes_reply;
939 if (test_rep->tsr_status == 0) {
940 lstcon_tsbop_stat_success(stat, 1);
944 lstcon_tsbop_stat_failure(stat, 1);
945 errno = test_rep->tsr_status;
948 case LST_TRANS_STATQRY:
949 stat_rep = &msg->msg_body.stat_reply;
951 if (stat_rep->str_status == 0) {
952 lstcon_statqry_stat_success(stat, 1);
956 lstcon_statqry_stat_failure(stat, 1);
957 errno = stat_rep->str_status;
964 if (stat->trs_fwk_errno == 0)
965 stat->trs_fwk_errno = errno;
971 lstcon_rpc_trans_ndlist(struct list_head *ndlist,
972 struct list_head *translist, int transop,
973 void *arg, lstcon_rpc_cond_func_t condition,
974 lstcon_rpc_trans_t **transpp)
976 lstcon_rpc_trans_t *trans;
977 lstcon_ndlink_t *ndl;
982 /* Creating session RPG for list of nodes */
984 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
986 CERROR("Can't create transaction %d: %d\n", transop, rc);
990 list_for_each_entry(ndl, ndlist, ndl_link) {
991 rc = condition == NULL ? 1 :
992 condition(transop, ndl->ndl_node, arg);
998 CDEBUG(D_NET, "Condition error while creating RPC "
999 " for transaction %d: %d\n", transop, rc);
1006 case LST_TRANS_SESNEW:
1007 case LST_TRANS_SESEND:
1008 rc = lstcon_sesrpc_prep(nd, transop, &rpc);
1010 case LST_TRANS_SESQRY:
1011 case LST_TRANS_SESPING:
1012 rc = lstcon_dbgrpc_prep(nd, &rpc);
1014 case LST_TRANS_TSBCLIADD:
1015 case LST_TRANS_TSBSRVADD:
1016 rc = lstcon_testrpc_prep(nd, transop,
1017 (lstcon_test_t *)arg, &rpc);
1019 case LST_TRANS_TSBRUN:
1020 case LST_TRANS_TSBSTOP:
1021 case LST_TRANS_TSBCLIQRY:
1022 case LST_TRANS_TSBSRVQRY:
1023 rc = lstcon_batrpc_prep(nd, transop,
1024 (lstcon_tsb_hdr_t *)arg, &rpc);
1026 case LST_TRANS_STATQRY:
1027 rc = lstcon_statrpc_prep(nd, &rpc);
1035 CERROR("Failed to create RPC for transaction %s: %d\n",
1036 lstcon_rpc_trans_name(transop), rc);
1040 lstcon_rpc_trans_addreq(trans, rpc);
1048 lstcon_rpc_trans_destroy(trans);
1054 lstcon_rpc_pinger(void *arg)
1056 stt_timer_t *ptimer = (stt_timer_t *)arg;
1057 lstcon_rpc_trans_t *trans;
1060 srpc_debug_reqst_t *drq;
1061 lstcon_ndlink_t *ndl;
1067 /* RPC pinger is a special case of transaction,
1068 * it's called by timer at 8 seconds interval.
1070 mutex_down(&console_session.ses_mutex);
1072 if (console_session.ses_shutdown || console_session.ses_expired) {
1073 mutex_up(&console_session.ses_mutex);
1077 if (!console_session.ses_expired &&
1078 cfs_time_current_sec() - console_session.ses_laststamp >
1079 console_session.ses_timeout)
1080 console_session.ses_expired = 1;
1082 trans = console_session.ses_ping;
1084 LASSERT (trans != NULL);
1086 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link) {
1089 if (console_session.ses_expired) {
1090 /* idle console, end session on all nodes */
1091 if (nd->nd_state != LST_NODE_ACTIVE)
1094 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND, &crpc);
1096 CERROR("Out of memory\n");
1100 lstcon_rpc_trans_addreq(trans, crpc);
1101 lstcon_rpc_post(crpc);
1106 crpc = &nd->nd_ping;
1108 if (crpc->crp_rpc != NULL) {
1109 LASSERT (crpc->crp_trans == trans);
1110 LASSERT (!list_empty(&crpc->crp_link));
1112 spin_lock(&crpc->crp_rpc->crpc_lock);
1114 LASSERT (crpc->crp_posted);
1116 if (!crpc->crp_finished) {
1118 spin_unlock(&crpc->crp_rpc->crpc_lock);
1122 spin_unlock(&crpc->crp_rpc->crpc_lock);
1124 lstcon_rpc_get_reply(crpc, &rep);
1126 list_del_init(&crpc->crp_link);
1128 lstcon_rpc_put(crpc);
1131 if (nd->nd_state != LST_NODE_ACTIVE)
1134 intv = cfs_duration_sec(cfs_time_sub(cfs_time_current(),
1136 if (intv < nd->nd_timeout / 2)
1139 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG, 0, 0, crpc);
1141 CERROR("Out of memory\n");
1145 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1147 drq->dbg_sid = console_session.ses_id;
1150 lstcon_rpc_trans_addreq(trans, crpc);
1151 lstcon_rpc_post(crpc);
1156 if (console_session.ses_expired) {
1157 mutex_up(&console_session.ses_mutex);
1161 CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1163 ptimer->stt_expires = cfs_time_current_sec() + LST_PING_INTERVAL;
1164 stt_add_timer(ptimer);
1166 mutex_up(&console_session.ses_mutex);
1170 lstcon_rpc_pinger_start(void)
1172 stt_timer_t *ptimer;
1175 LASSERT (list_empty(&console_session.ses_rpc_freelist));
1176 LASSERT (atomic_read(&console_session.ses_rpc_counter) == 0);
1178 rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1179 &console_session.ses_ping);
1181 CERROR("Failed to create console pinger\n");
1185 ptimer = &console_session.ses_ping_timer;
1186 ptimer->stt_expires = cfs_time_current_sec() + LST_PING_INTERVAL;
1188 stt_add_timer(ptimer);
1194 lstcon_rpc_pinger_stop(void)
1196 LASSERT (console_session.ses_shutdown);
1198 stt_del_timer(&console_session.ses_ping_timer);
1200 lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1201 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1202 lstcon_rpc_trans_destroy(console_session.ses_ping);
1204 memset(lstcon_trans_stat(), 0, sizeof(lstcon_trans_stat_t));
1206 console_session.ses_ping = NULL;
1210 lstcon_rpc_cleanup_wait(void)
1212 lstcon_rpc_trans_t *trans;
1214 struct list_head *pacer;
1215 struct list_head zlist;
1217 /* Called with hold of global mutex */
1219 LASSERT (console_session.ses_shutdown);
1221 while (!list_empty(&console_session.ses_trans_list)) {
1222 list_for_each(pacer, &console_session.ses_trans_list) {
1223 trans = list_entry(pacer, lstcon_rpc_trans_t, tas_link);
1225 CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1226 lstcon_rpc_trans_name(trans->tas_opc));
1228 cfs_waitq_signal(&trans->tas_waitq);
1231 mutex_up(&console_session.ses_mutex);
1233 CWARN("Session is shutting down, "
1234 "waiting for termination of transactions\n");
1235 cfs_pause(cfs_time_seconds(1));
1237 mutex_down(&console_session.ses_mutex);
1240 spin_lock(&console_session.ses_rpc_lock);
1242 lst_wait_until((atomic_read(&console_session.ses_rpc_counter) == 0),
1243 console_session.ses_rpc_lock,
1244 "Network is not accessable or target is down, "
1245 "waiting for %d console RPCs to being recycled\n",
1246 atomic_read(&console_session.ses_rpc_counter));
1248 list_add(&zlist, &console_session.ses_rpc_freelist);
1249 list_del_init(&console_session.ses_rpc_freelist);
1251 spin_unlock(&console_session.ses_rpc_lock);
1253 while (!list_empty(&zlist)) {
1254 crpc = list_entry(zlist.next, lstcon_rpc_t, crp_link);
1256 list_del(&crpc->crp_link);
1257 LIBCFS_FREE(crpc, sizeof(lstcon_rpc_t));
1262 lstcon_rpc_module_init(void)
1264 CFS_INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1265 console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1266 console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1268 console_session.ses_ping = NULL;
1270 spin_lock_init(&console_session.ses_rpc_lock);
1271 atomic_set(&console_session.ses_rpc_counter, 0);
1272 CFS_INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1278 lstcon_rpc_module_fini(void)
1280 LASSERT (list_empty(&console_session.ses_rpc_freelist));
1281 LASSERT (atomic_read(&console_session.ses_rpc_counter) == 0);