1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/selftest/conctl.c
38 * Console framework rpcs
40 * Author: Liang Zhen <liangzhen@clusterfs.com>
45 #include <libcfs/libcfs.h>
46 #include <lnet/lib-lnet.h>
51 void lstcon_rpc_stat_reply(int, srpc_msg_t *,
52 lstcon_node_t *, lstcon_trans_stat_t *);
55 lstcon_rpc_done(srpc_client_rpc_t *rpc)
57 lstcon_rpc_t *crpc = (lstcon_rpc_t *)rpc->crpc_priv;
59 LASSERT (crpc != NULL && rpc == crpc->crp_rpc);
60 LASSERT (crpc->crp_posted && !crpc->crp_finished);
62 cfs_spin_lock(&rpc->crpc_lock);
64 if (crpc->crp_trans == NULL) {
65 /* Orphan RPC is not in any transaction,
66 * I'm just a poor body and nobody loves me */
67 cfs_spin_unlock(&rpc->crpc_lock);
74 /* not an orphan RPC */
75 crpc->crp_finished = 1;
77 if (crpc->crp_stamp == 0) {
79 LASSERT (crpc->crp_status == 0);
81 crpc->crp_stamp = cfs_time_current();
82 crpc->crp_status = rpc->crpc_status;
85 /* wakeup (transaction)thread if I'm the last RPC in the transaction */
86 if (cfs_atomic_dec_and_test(&crpc->crp_trans->tas_remaining))
87 cfs_waitq_signal(&crpc->crp_trans->tas_waitq);
89 cfs_spin_unlock(&rpc->crpc_lock);
93 lstcon_rpc_init(lstcon_node_t *nd, int service,
94 int npg, int cached, lstcon_rpc_t *crpc)
97 crpc->crp_rpc = sfw_create_rpc(nd->nd_id, service,
98 npg, npg * CFS_PAGE_SIZE,
99 lstcon_rpc_done, (void *)crpc);
100 if (crpc->crp_rpc == NULL)
103 crpc->crp_trans = NULL;
105 crpc->crp_posted = 0;
106 crpc->crp_finished = 0;
107 crpc->crp_unpacked = 0;
108 crpc->crp_status = 0;
110 crpc->crp_static = !cached;
111 CFS_INIT_LIST_HEAD(&crpc->crp_link);
113 cfs_atomic_inc(&console_session.ses_rpc_counter);
119 lstcon_rpc_prep(lstcon_node_t *nd, int service,
120 int npg, lstcon_rpc_t **crpcpp)
122 lstcon_rpc_t *crpc = NULL;
125 cfs_spin_lock(&console_session.ses_rpc_lock);
127 if (!cfs_list_empty(&console_session.ses_rpc_freelist)) {
128 crpc = cfs_list_entry(console_session.ses_rpc_freelist.next,
129 lstcon_rpc_t, crp_link);
130 cfs_list_del_init(&crpc->crp_link);
133 cfs_spin_unlock(&console_session.ses_rpc_lock);
136 LIBCFS_ALLOC(crpc, sizeof(*crpc));
141 rc = lstcon_rpc_init(nd, service, npg, 1, crpc);
147 LIBCFS_FREE(crpc, sizeof(*crpc));
153 lstcon_rpc_put(lstcon_rpc_t *crpc)
155 srpc_bulk_t *bulk = &crpc->crp_rpc->crpc_bulk;
158 LASSERT (cfs_list_empty(&crpc->crp_link));
160 for (i = 0; i < bulk->bk_niov; i++) {
161 if (bulk->bk_iovs[i].kiov_page == NULL)
164 cfs_free_page(bulk->bk_iovs[i].kiov_page);
167 srpc_client_rpc_decref(crpc->crp_rpc);
169 if (crpc->crp_static) {
170 /* Static RPC, not allocated */
171 memset(crpc, 0, sizeof(*crpc));
172 crpc->crp_static = 1;
175 cfs_spin_lock(&console_session.ses_rpc_lock);
177 cfs_list_add(&crpc->crp_link,
178 &console_session.ses_rpc_freelist);
180 cfs_spin_unlock(&console_session.ses_rpc_lock);
183 /* RPC is not alive now */
184 cfs_atomic_dec(&console_session.ses_rpc_counter);
188 lstcon_rpc_post(lstcon_rpc_t *crpc)
190 lstcon_rpc_trans_t *trans = crpc->crp_trans;
192 LASSERT (trans != NULL);
194 cfs_atomic_inc(&trans->tas_remaining);
195 crpc->crp_posted = 1;
197 sfw_post_rpc(crpc->crp_rpc);
201 lstcon_rpc_trans_name(int transop)
203 if (transop == LST_TRANS_SESNEW)
206 if (transop == LST_TRANS_SESEND)
209 if (transop == LST_TRANS_SESQRY)
212 if (transop == LST_TRANS_SESPING)
215 if (transop == LST_TRANS_TSBCLIADD)
218 if (transop == LST_TRANS_TSBSRVADD)
221 if (transop == LST_TRANS_TSBRUN)
224 if (transop == LST_TRANS_TSBSTOP)
227 if (transop == LST_TRANS_TSBCLIQRY)
230 if (transop == LST_TRANS_TSBSRVQRY)
233 if (transop == LST_TRANS_STATQRY)
240 lstcon_rpc_trans_prep(cfs_list_t *translist,
241 int transop, lstcon_rpc_trans_t **transpp)
243 lstcon_rpc_trans_t *trans;
245 if (translist != NULL) {
246 cfs_list_for_each_entry_typed(trans, translist,
247 lstcon_rpc_trans_t, tas_link) {
248 /* Can't enqueue two private transaction on
250 if ((trans->tas_opc & transop) == LST_TRANS_PRIVATE)
255 /* create a trans group */
256 LIBCFS_ALLOC(trans, sizeof(*trans));
260 trans->tas_opc = transop;
262 if (translist == NULL)
263 CFS_INIT_LIST_HEAD(&trans->tas_olink);
265 cfs_list_add_tail(&trans->tas_olink, translist);
267 cfs_list_add_tail(&trans->tas_link, &console_session.ses_trans_list);
269 CFS_INIT_LIST_HEAD(&trans->tas_rpcs_list);
270 cfs_atomic_set(&trans->tas_remaining, 0);
271 cfs_waitq_init(&trans->tas_waitq);
279 lstcon_rpc_trans_addreq(lstcon_rpc_trans_t *trans, lstcon_rpc_t *crpc)
281 cfs_list_add_tail(&crpc->crp_link, &trans->tas_rpcs_list);
282 crpc->crp_trans = trans;
286 lstcon_rpc_trans_abort(lstcon_rpc_trans_t *trans, int error)
288 srpc_client_rpc_t *rpc;
292 cfs_list_for_each_entry_typed (crpc, &trans->tas_rpcs_list,
293 lstcon_rpc_t, crp_link) {
296 cfs_spin_lock(&rpc->crpc_lock);
298 if (!crpc->crp_posted || crpc->crp_stamp != 0) {
299 /* rpc done or aborted already */
300 cfs_spin_unlock(&rpc->crpc_lock);
304 crpc->crp_stamp = cfs_time_current();
305 crpc->crp_status = error;
307 cfs_spin_unlock(&rpc->crpc_lock);
311 if (error != ETIMEDOUT)
315 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
318 nd->nd_stamp = crpc->crp_stamp;
319 nd->nd_state = LST_NODE_DOWN;
324 lstcon_rpc_trans_check(lstcon_rpc_trans_t *trans)
326 if (console_session.ses_shutdown &&
327 !cfs_list_empty(&trans->tas_olink)) /* Not an end session RPC */
330 return (cfs_atomic_read(&trans->tas_remaining) == 0) ? 1: 0;
334 lstcon_rpc_trans_postwait(lstcon_rpc_trans_t *trans, int timeout)
339 if (cfs_list_empty(&trans->tas_rpcs_list))
342 if (timeout < LST_TRANS_MIN_TIMEOUT)
343 timeout = LST_TRANS_MIN_TIMEOUT;
345 CDEBUG(D_NET, "Transaction %s started\n",
346 lstcon_rpc_trans_name(trans->tas_opc));
348 /* post all requests */
349 cfs_list_for_each_entry_typed (crpc, &trans->tas_rpcs_list,
350 lstcon_rpc_t, crp_link) {
351 LASSERT (!crpc->crp_posted);
353 lstcon_rpc_post(crpc);
356 cfs_mutex_up(&console_session.ses_mutex);
358 cfs_waitq_wait_event_interruptible_timeout(trans->tas_waitq,
359 lstcon_rpc_trans_check(trans),
360 cfs_time_seconds(timeout), rc);
362 rc = (rc > 0)? 0: ((rc < 0)? -EINTR: -ETIMEDOUT);
364 cfs_mutex_down(&console_session.ses_mutex);
366 if (console_session.ses_shutdown)
370 /* treat short timeout as canceled */
371 if (rc == -ETIMEDOUT && timeout < LST_TRANS_MIN_TIMEOUT * 2)
374 lstcon_rpc_trans_abort(trans, rc);
377 CDEBUG(D_NET, "Transaction %s stopped: %d\n",
378 lstcon_rpc_trans_name(trans->tas_opc), rc);
380 lstcon_rpc_trans_stat(trans, lstcon_trans_stat());
386 lstcon_rpc_get_reply(lstcon_rpc_t *crpc, srpc_msg_t **msgpp)
388 lstcon_node_t *nd = crpc->crp_node;
389 srpc_client_rpc_t *rpc = crpc->crp_rpc;
390 srpc_generic_reply_t *rep;
392 LASSERT (nd != NULL && rpc != NULL);
393 LASSERT (crpc->crp_stamp != 0);
395 if (crpc->crp_status != 0) {
397 return crpc->crp_status;
400 *msgpp = &rpc->crpc_replymsg;
401 if (!crpc->crp_unpacked) {
402 sfw_unpack_message(*msgpp);
403 crpc->crp_unpacked = 1;
406 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
409 nd->nd_stamp = crpc->crp_stamp;
410 rep = &(*msgpp)->msg_body.reply;
412 if (rep->sid.ses_nid == LNET_NID_ANY)
413 nd->nd_state = LST_NODE_UNKNOWN;
414 else if (lstcon_session_match(rep->sid))
415 nd->nd_state = LST_NODE_ACTIVE;
417 nd->nd_state = LST_NODE_BUSY;
423 lstcon_rpc_trans_stat(lstcon_rpc_trans_t *trans, lstcon_trans_stat_t *stat)
426 srpc_client_rpc_t *rpc;
430 LASSERT (stat != NULL);
432 memset(stat, 0, sizeof(*stat));
434 cfs_list_for_each_entry_typed(crpc, &trans->tas_rpcs_list,
435 lstcon_rpc_t, crp_link) {
436 lstcon_rpc_stat_total(stat, 1);
440 LASSERT (crpc->crp_stamp != 0);
442 error = lstcon_rpc_get_reply(crpc, &rep);
444 lstcon_rpc_stat_failure(stat, 1);
445 if (stat->trs_rpc_errno == 0)
446 stat->trs_rpc_errno = -error;
451 lstcon_rpc_stat_success(stat, 1);
453 lstcon_rpc_stat_reply(trans->tas_opc, rep,
454 crpc->crp_node, stat);
457 CDEBUG(D_NET, "transaction %s : success %d, failure %d, total %d, "
458 "RPC error(%d), Framework error(%d)\n",
459 lstcon_rpc_trans_name(trans->tas_opc),
460 lstcon_rpc_stat_success(stat, 0),
461 lstcon_rpc_stat_failure(stat, 0),
462 lstcon_rpc_stat_total(stat, 0),
463 stat->trs_rpc_errno, stat->trs_fwk_errno);
469 lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
471 lstcon_rpc_readent_func_t readent)
475 lstcon_rpc_ent_t *ent;
476 srpc_generic_reply_t *rep;
477 srpc_client_rpc_t *rpc;
485 LASSERT (head_up != NULL);
489 cfs_list_for_each_entry_typed(crpc, &trans->tas_rpcs_list,
490 lstcon_rpc_t, crp_link) {
491 if (cfs_copy_from_user(&tmp, next,
495 if (tmp.next == head_up)
500 ent = cfs_list_entry(next, lstcon_rpc_ent_t, rpe_link);
504 LASSERT (crpc->crp_stamp != 0);
506 error = lstcon_rpc_get_reply(crpc, &msg);
510 dur = (cfs_duration_t)cfs_time_sub(crpc->crp_stamp,
511 (cfs_time_t)console_session.ses_id.ses_stamp);
512 cfs_duration_usec(dur, &tv);
514 if (cfs_copy_to_user(&ent->rpe_peer,
515 &nd->nd_id, sizeof(lnet_process_id_t)) ||
516 cfs_copy_to_user(&ent->rpe_stamp, &tv, sizeof(tv)) ||
517 cfs_copy_to_user(&ent->rpe_state,
518 &nd->nd_state, sizeof(nd->nd_state)) ||
519 cfs_copy_to_user(&ent->rpe_rpc_errno, &error,
527 rep = (srpc_generic_reply_t *)&msg->msg_body.reply;
529 if (cfs_copy_to_user(&ent->rpe_sid,
530 &rep->sid, sizeof(lst_sid_t)) ||
531 cfs_copy_to_user(&ent->rpe_fwk_errno,
532 &rep->status, sizeof(rep->status)))
538 if ((error = readent(trans->tas_opc, msg, ent)) != 0)
546 lstcon_rpc_trans_destroy(lstcon_rpc_trans_t *trans)
548 srpc_client_rpc_t *rpc;
553 cfs_list_for_each_entry_safe_typed(crpc, tmp,
554 &trans->tas_rpcs_list,
555 lstcon_rpc_t, crp_link) {
558 cfs_spin_lock(&rpc->crpc_lock);
560 /* free it if not posted or finished already */
561 if (!crpc->crp_posted || crpc->crp_finished) {
562 cfs_spin_unlock(&rpc->crpc_lock);
564 cfs_list_del_init(&crpc->crp_link);
565 lstcon_rpc_put(crpc);
570 /* rpcs can be still not callbacked (even LNetMDUnlink is called)
571 * because huge timeout for inaccessible network, don't make
572 * user wait for them, just abandon them, they will be recycled
575 LASSERT (crpc->crp_status != 0);
577 crpc->crp_node = NULL;
578 crpc->crp_trans = NULL;
579 cfs_list_del_init(&crpc->crp_link);
582 cfs_spin_unlock(&rpc->crpc_lock);
584 cfs_atomic_dec(&trans->tas_remaining);
587 LASSERT (cfs_atomic_read(&trans->tas_remaining) == 0);
589 cfs_list_del(&trans->tas_link);
590 if (!cfs_list_empty(&trans->tas_olink))
591 cfs_list_del(&trans->tas_olink);
593 CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
594 lstcon_rpc_trans_name(trans->tas_opc), count);
596 LIBCFS_FREE(trans, sizeof(*trans));
602 lstcon_sesrpc_prep(lstcon_node_t *nd, int transop, lstcon_rpc_t **crpc)
604 srpc_mksn_reqst_t *msrq;
605 srpc_rmsn_reqst_t *rsrq;
609 case LST_TRANS_SESNEW:
610 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION, 0, crpc);
614 msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
615 msrq->mksn_sid = console_session.ses_id;
616 msrq->mksn_force = console_session.ses_force;
617 strncpy(msrq->mksn_name, console_session.ses_name,
618 strlen(console_session.ses_name));
621 case LST_TRANS_SESEND:
622 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION, 0, crpc);
626 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
627 rsrq->rmsn_sid = console_session.ses_id;
638 lstcon_dbgrpc_prep(lstcon_node_t *nd, lstcon_rpc_t **crpc)
640 srpc_debug_reqst_t *drq;
643 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, 0, crpc);
647 drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
649 drq->dbg_sid = console_session.ses_id;
656 lstcon_batrpc_prep(lstcon_node_t *nd, int transop,
657 lstcon_tsb_hdr_t *tsb, lstcon_rpc_t **crpc)
659 lstcon_batch_t *batch;
660 srpc_batch_reqst_t *brq;
663 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, 0, crpc);
667 brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
669 brq->bar_sid = console_session.ses_id;
670 brq->bar_bid = tsb->tsb_id;
671 brq->bar_testidx = tsb->tsb_index;
672 brq->bar_opc = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
673 (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP:
674 SRPC_BATCH_OPC_QUERY);
676 if (transop != LST_TRANS_TSBRUN &&
677 transop != LST_TRANS_TSBSTOP)
680 LASSERT (tsb->tsb_index == 0);
682 batch = (lstcon_batch_t *)tsb;
683 brq->bar_arg = batch->bat_arg;
689 lstcon_statrpc_prep(lstcon_node_t *nd, lstcon_rpc_t **crpc)
691 srpc_stat_reqst_t *srq;
694 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_QUERY_STAT, 0, crpc);
698 srq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.stat_reqst;
700 srq->str_sid = console_session.ses_id;
701 srq->str_type = 0; /* XXX remove it */
706 lnet_process_id_packed_t *
707 lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov)
709 lnet_process_id_packed_t *pid;
712 i = idx / SFW_ID_PER_PAGE;
716 pid = (lnet_process_id_packed_t *)cfs_page_address(kiov[i].kiov_page);
718 return &pid[idx % SFW_ID_PER_PAGE];
722 lstcon_dstnodes_prep(lstcon_group_t *grp, int idx,
723 int dist, int span, int nkiov, lnet_kiov_t *kiov)
725 lnet_process_id_packed_t *pid;
726 lstcon_ndlink_t *ndl;
734 LASSERT (grp->grp_nnode >= 1);
736 if (span > grp->grp_nnode)
739 start = ((idx / dist) * span) % grp->grp_nnode;
740 end = ((idx / dist) * span + span - 1) % grp->grp_nnode;
742 cfs_list_for_each_entry_typed(ndl, &grp->grp_ndl_list,
743 lstcon_ndlink_t, ndl_link) {
750 if (i > (end >= start ? end: grp->grp_nnode))
753 pid = lstcon_next_id((i - start), nkiov, kiov);
754 pid->nid = nd->nd_id.nid;
755 pid->pid = nd->nd_id.pid;
759 if (start <= end) /* done */
762 cfs_list_for_each_entry_typed(ndl, &grp->grp_ndl_list,
763 lstcon_ndlink_t, ndl_link) {
764 if (i > grp->grp_nnode + end)
768 pid = lstcon_next_id((i - start), nkiov, kiov);
769 pid->nid = nd->nd_id.nid;
770 pid->pid = nd->nd_id.pid;
778 lstcon_pingrpc_prep(lst_test_ping_param_t *param, srpc_test_reqst_t *req)
780 test_ping_req_t *prq = &req->tsr_u.ping;
782 prq->png_size = param->png_size;
783 prq->png_flags = param->png_flags;
789 lstcon_bulkrpc_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
791 test_bulk_req_t *brq = &req->tsr_u.bulk;
793 brq->blk_opc = param->blk_opc;
794 brq->blk_npg = (param->blk_size + CFS_PAGE_SIZE - 1) / CFS_PAGE_SIZE;
795 brq->blk_flags = param->blk_flags;
801 lstcon_testrpc_prep(lstcon_node_t *nd, int transop,
802 lstcon_test_t *test, lstcon_rpc_t **crpc)
804 lstcon_group_t *sgrp = test->tes_src_grp;
805 lstcon_group_t *dgrp = test->tes_dst_grp;
806 srpc_test_reqst_t *trq;
812 if (transop == LST_TRANS_TSBCLIADD)
813 n = sfw_id_pages(test->tes_span);
815 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, n, crpc);
819 trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
821 if (transop == LST_TRANS_TSBSRVADD) {
822 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
823 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
824 int nmax = (ndist + nspan - 1) / nspan;
827 trq->tsr_loop = nmax * test->tes_dist * test->tes_concur;
830 bulk = &(*crpc)->crp_rpc->crpc_bulk;
832 for (i = 0; i < n; i++) {
833 bulk->bk_iovs[i].kiov_offset = 0;
834 bulk->bk_iovs[i].kiov_len = CFS_PAGE_SIZE;
835 bulk->bk_iovs[i].kiov_page = cfs_alloc_page(CFS_ALLOC_STD);
837 if (bulk->bk_iovs[i].kiov_page != NULL)
840 lstcon_rpc_put(*crpc);
846 LASSERT (transop == LST_TRANS_TSBCLIADD);
848 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
849 test->tes_cliidx++, test->tes_dist,
850 test->tes_span, n, &bulk->bk_iovs[0]);
852 lstcon_rpc_put(*crpc);
856 trq->tsr_ndest = test->tes_span;
857 trq->tsr_loop = test->tes_loop;
860 trq->tsr_sid = console_session.ses_id;
861 trq->tsr_bid = test->tes_hdr.tsb_id;
862 trq->tsr_concur = test->tes_concur;
863 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
864 trq->tsr_stop_onerr = !!test->tes_stop_onerr;
866 switch (test->tes_type) {
868 trq->tsr_service = SRPC_SERVICE_PING;
869 rc = lstcon_pingrpc_prep((lst_test_ping_param_t *)&test->tes_param[0], trq);
872 trq->tsr_service = SRPC_SERVICE_BRW;
873 rc = lstcon_bulkrpc_prep((lst_test_bulk_param_t *)&test->tes_param[0], trq);
884 lstcon_rpc_stat_reply(int transop, srpc_msg_t *msg,
885 lstcon_node_t *nd, lstcon_trans_stat_t *stat)
887 srpc_mksn_reply_t *mksn_rep;
888 srpc_rmsn_reply_t *rmsn_rep;
889 srpc_debug_reply_t *dbg_rep;
890 srpc_batch_reply_t *bat_rep;
891 srpc_test_reply_t *test_rep;
892 srpc_stat_reply_t *stat_rep;
896 case LST_TRANS_SESNEW:
897 mksn_rep = &msg->msg_body.mksn_reply;
899 if (mksn_rep->mksn_status == 0) {
900 lstcon_sesop_stat_success(stat, 1);
901 /* session timeout on remote node */
902 nd->nd_timeout = mksn_rep->mksn_timeout;
906 LASSERT (mksn_rep->mksn_status == EBUSY ||
907 mksn_rep->mksn_status == EINVAL);
909 lstcon_sesop_stat_failure(stat, 1);
910 rc = mksn_rep->mksn_status;
913 case LST_TRANS_SESEND:
914 rmsn_rep = &msg->msg_body.rmsn_reply;
915 /* ESRCH is not an error for end session */
916 if (rmsn_rep->rmsn_status == 0 ||
917 rmsn_rep->rmsn_status == ESRCH) {
918 lstcon_sesop_stat_success(stat, 1);
922 LASSERT (rmsn_rep->rmsn_status == EBUSY ||
923 rmsn_rep->rmsn_status == EINVAL);
925 lstcon_sesop_stat_failure(stat, 1);
926 rc = rmsn_rep->rmsn_status;
929 case LST_TRANS_SESQRY:
930 case LST_TRANS_SESPING:
931 dbg_rep = &msg->msg_body.dbg_reply;
933 if (dbg_rep->dbg_status == ESRCH) {
934 lstcon_sesqry_stat_unknown(stat, 1);
938 LASSERT (dbg_rep->dbg_status == 0);
940 if (lstcon_session_match(dbg_rep->dbg_sid))
941 lstcon_sesqry_stat_active(stat, 1);
943 lstcon_sesqry_stat_busy(stat, 1);
946 case LST_TRANS_TSBRUN:
947 case LST_TRANS_TSBSTOP:
948 bat_rep = &msg->msg_body.bat_reply;
950 if (bat_rep->bar_status == 0) {
951 lstcon_tsbop_stat_success(stat, 1);
955 if (bat_rep->bar_status == EPERM &&
956 transop == LST_TRANS_TSBSTOP) {
957 lstcon_tsbop_stat_success(stat, 1);
961 lstcon_tsbop_stat_failure(stat, 1);
962 rc = bat_rep->bar_status;
965 case LST_TRANS_TSBCLIQRY:
966 case LST_TRANS_TSBSRVQRY:
967 bat_rep = &msg->msg_body.bat_reply;
969 if (bat_rep->bar_active != 0)
970 lstcon_tsbqry_stat_run(stat, 1);
972 lstcon_tsbqry_stat_idle(stat, 1);
974 if (bat_rep->bar_status == 0)
977 lstcon_tsbqry_stat_failure(stat, 1);
978 rc = bat_rep->bar_status;
981 case LST_TRANS_TSBCLIADD:
982 case LST_TRANS_TSBSRVADD:
983 test_rep = &msg->msg_body.tes_reply;
985 if (test_rep->tsr_status == 0) {
986 lstcon_tsbop_stat_success(stat, 1);
990 lstcon_tsbop_stat_failure(stat, 1);
991 rc = test_rep->tsr_status;
994 case LST_TRANS_STATQRY:
995 stat_rep = &msg->msg_body.stat_reply;
997 if (stat_rep->str_status == 0) {
998 lstcon_statqry_stat_success(stat, 1);
1002 lstcon_statqry_stat_failure(stat, 1);
1003 rc = stat_rep->str_status;
1010 if (stat->trs_fwk_errno == 0)
1011 stat->trs_fwk_errno = rc;
1017 lstcon_rpc_trans_ndlist(cfs_list_t *ndlist,
1018 cfs_list_t *translist, int transop,
1019 void *arg, lstcon_rpc_cond_func_t condition,
1020 lstcon_rpc_trans_t **transpp)
1022 lstcon_rpc_trans_t *trans;
1023 lstcon_ndlink_t *ndl;
1028 /* Creating session RPG for list of nodes */
1030 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1032 CERROR("Can't create transaction %d: %d\n", transop, rc);
1036 cfs_list_for_each_entry_typed(ndl, ndlist, lstcon_ndlink_t, ndl_link) {
1037 rc = condition == NULL ? 1 :
1038 condition(transop, ndl->ndl_node, arg);
1044 CDEBUG(D_NET, "Condition error while creating RPC "
1045 " for transaction %d: %d\n", transop, rc);
1052 case LST_TRANS_SESNEW:
1053 case LST_TRANS_SESEND:
1054 rc = lstcon_sesrpc_prep(nd, transop, &rpc);
1056 case LST_TRANS_SESQRY:
1057 case LST_TRANS_SESPING:
1058 rc = lstcon_dbgrpc_prep(nd, &rpc);
1060 case LST_TRANS_TSBCLIADD:
1061 case LST_TRANS_TSBSRVADD:
1062 rc = lstcon_testrpc_prep(nd, transop,
1063 (lstcon_test_t *)arg, &rpc);
1065 case LST_TRANS_TSBRUN:
1066 case LST_TRANS_TSBSTOP:
1067 case LST_TRANS_TSBCLIQRY:
1068 case LST_TRANS_TSBSRVQRY:
1069 rc = lstcon_batrpc_prep(nd, transop,
1070 (lstcon_tsb_hdr_t *)arg, &rpc);
1072 case LST_TRANS_STATQRY:
1073 rc = lstcon_statrpc_prep(nd, &rpc);
1081 CERROR("Failed to create RPC for transaction %s: %d\n",
1082 lstcon_rpc_trans_name(transop), rc);
1086 lstcon_rpc_trans_addreq(trans, rpc);
1094 lstcon_rpc_trans_destroy(trans);
1100 lstcon_rpc_pinger(void *arg)
1102 stt_timer_t *ptimer = (stt_timer_t *)arg;
1103 lstcon_rpc_trans_t *trans;
1106 srpc_debug_reqst_t *drq;
1107 lstcon_ndlink_t *ndl;
1113 /* RPC pinger is a special case of transaction,
1114 * it's called by timer at 8 seconds interval.
1116 cfs_mutex_down(&console_session.ses_mutex);
1118 if (console_session.ses_shutdown || console_session.ses_expired) {
1119 cfs_mutex_up(&console_session.ses_mutex);
1123 if (!console_session.ses_expired &&
1124 cfs_time_current_sec() - console_session.ses_laststamp >
1125 (time_t)console_session.ses_timeout)
1126 console_session.ses_expired = 1;
1128 trans = console_session.ses_ping;
1130 LASSERT (trans != NULL);
1132 cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_list,
1133 lstcon_ndlink_t, ndl_link) {
1136 if (console_session.ses_expired) {
1137 /* idle console, end session on all nodes */
1138 if (nd->nd_state != LST_NODE_ACTIVE)
1141 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND, &crpc);
1143 CERROR("Out of memory\n");
1147 lstcon_rpc_trans_addreq(trans, crpc);
1148 lstcon_rpc_post(crpc);
1153 crpc = &nd->nd_ping;
1155 if (crpc->crp_rpc != NULL) {
1156 LASSERT (crpc->crp_trans == trans);
1157 LASSERT (!cfs_list_empty(&crpc->crp_link));
1159 cfs_spin_lock(&crpc->crp_rpc->crpc_lock);
1161 LASSERT (crpc->crp_posted);
1163 if (!crpc->crp_finished) {
1165 cfs_spin_unlock(&crpc->crp_rpc->crpc_lock);
1169 cfs_spin_unlock(&crpc->crp_rpc->crpc_lock);
1171 lstcon_rpc_get_reply(crpc, &rep);
1173 cfs_list_del_init(&crpc->crp_link);
1175 lstcon_rpc_put(crpc);
1178 if (nd->nd_state != LST_NODE_ACTIVE)
1181 intv = cfs_duration_sec(cfs_time_sub(cfs_time_current(),
1183 if (intv < (time_t)nd->nd_timeout / 2)
1186 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG, 0, 0, crpc);
1188 CERROR("Out of memory\n");
1192 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1194 drq->dbg_sid = console_session.ses_id;
1197 lstcon_rpc_trans_addreq(trans, crpc);
1198 lstcon_rpc_post(crpc);
1203 if (console_session.ses_expired) {
1204 cfs_mutex_up(&console_session.ses_mutex);
1208 CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1210 ptimer->stt_expires = (cfs_time_t)(cfs_time_current_sec() + LST_PING_INTERVAL);
1211 stt_add_timer(ptimer);
1213 cfs_mutex_up(&console_session.ses_mutex);
1217 lstcon_rpc_pinger_start(void)
1219 stt_timer_t *ptimer;
1222 LASSERT (cfs_list_empty(&console_session.ses_rpc_freelist));
1223 LASSERT (cfs_atomic_read(&console_session.ses_rpc_counter) == 0);
1225 rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1226 &console_session.ses_ping);
1228 CERROR("Failed to create console pinger\n");
1232 ptimer = &console_session.ses_ping_timer;
1233 ptimer->stt_expires = (cfs_time_t)(cfs_time_current_sec() + LST_PING_INTERVAL);
1235 stt_add_timer(ptimer);
1241 lstcon_rpc_pinger_stop(void)
1243 LASSERT (console_session.ses_shutdown);
1245 stt_del_timer(&console_session.ses_ping_timer);
1247 lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1248 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1249 lstcon_rpc_trans_destroy(console_session.ses_ping);
1251 memset(lstcon_trans_stat(), 0, sizeof(lstcon_trans_stat_t));
1253 console_session.ses_ping = NULL;
1257 lstcon_rpc_cleanup_wait(void)
1259 lstcon_rpc_trans_t *trans;
1264 /* Called with hold of global mutex */
1266 LASSERT (console_session.ses_shutdown);
1268 while (!cfs_list_empty(&console_session.ses_trans_list)) {
1269 cfs_list_for_each(pacer, &console_session.ses_trans_list) {
1270 trans = cfs_list_entry(pacer, lstcon_rpc_trans_t,
1273 CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1274 lstcon_rpc_trans_name(trans->tas_opc));
1276 cfs_waitq_signal(&trans->tas_waitq);
1279 cfs_mutex_up(&console_session.ses_mutex);
1281 CWARN("Session is shutting down, "
1282 "waiting for termination of transactions\n");
1283 cfs_pause(cfs_time_seconds(1));
1285 cfs_mutex_down(&console_session.ses_mutex);
1288 cfs_spin_lock(&console_session.ses_rpc_lock);
1290 lst_wait_until((cfs_atomic_read(&console_session.ses_rpc_counter) == 0),
1291 console_session.ses_rpc_lock,
1292 "Network is not accessable or target is down, "
1293 "waiting for %d console RPCs to being recycled\n",
1294 cfs_atomic_read(&console_session.ses_rpc_counter));
1296 cfs_list_add(&zlist, &console_session.ses_rpc_freelist);
1297 cfs_list_del_init(&console_session.ses_rpc_freelist);
1299 cfs_spin_unlock(&console_session.ses_rpc_lock);
1301 while (!cfs_list_empty(&zlist)) {
1302 crpc = cfs_list_entry(zlist.next, lstcon_rpc_t, crp_link);
1304 cfs_list_del(&crpc->crp_link);
1305 LIBCFS_FREE(crpc, sizeof(lstcon_rpc_t));
1310 lstcon_rpc_module_init(void)
1312 CFS_INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1313 console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1314 console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1316 console_session.ses_ping = NULL;
1318 cfs_spin_lock_init(&console_session.ses_rpc_lock);
1319 cfs_atomic_set(&console_session.ses_rpc_counter, 0);
1320 CFS_INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1326 lstcon_rpc_module_fini(void)
1328 LASSERT (cfs_list_empty(&console_session.ses_rpc_freelist));
1329 LASSERT (cfs_atomic_read(&console_session.ses_rpc_counter) == 0);