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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lnet/selftest/conctl.c
40 * Console framework rpcs
42 * Author: Liang Zhen <liangzhen@clusterfs.com>
47 #include <libcfs/libcfs.h>
48 #include <lnet/lib-lnet.h>
53 void lstcon_rpc_stat_reply(int, srpc_msg_t *,
54 lstcon_node_t *, lstcon_trans_stat_t *);
57 lstcon_rpc_done(srpc_client_rpc_t *rpc)
59 lstcon_rpc_t *crpc = (lstcon_rpc_t *)rpc->crpc_priv;
61 LASSERT (crpc != NULL && rpc == crpc->crp_rpc);
62 LASSERT (crpc->crp_posted && !crpc->crp_finished);
64 cfs_spin_lock(&rpc->crpc_lock);
66 if (crpc->crp_trans == NULL) {
67 /* Orphan RPC is not in any transaction,
68 * I'm just a poor body and nobody loves me */
69 cfs_spin_unlock(&rpc->crpc_lock);
76 /* not an orphan RPC */
77 crpc->crp_finished = 1;
79 if (crpc->crp_stamp == 0) {
81 LASSERT (crpc->crp_status == 0);
83 crpc->crp_stamp = cfs_time_current();
84 crpc->crp_status = rpc->crpc_status;
87 /* wakeup (transaction)thread if I'm the last RPC in the transaction */
88 if (cfs_atomic_dec_and_test(&crpc->crp_trans->tas_remaining))
89 cfs_waitq_signal(&crpc->crp_trans->tas_waitq);
91 cfs_spin_unlock(&rpc->crpc_lock);
95 lstcon_rpc_init(lstcon_node_t *nd, int service,
96 int npg, int cached, lstcon_rpc_t *crpc)
99 crpc->crp_rpc = sfw_create_rpc(nd->nd_id, service,
100 npg, npg * CFS_PAGE_SIZE,
101 lstcon_rpc_done, (void *)crpc);
102 if (crpc->crp_rpc == NULL)
105 crpc->crp_trans = NULL;
107 crpc->crp_posted = 0;
108 crpc->crp_finished = 0;
109 crpc->crp_unpacked = 0;
110 crpc->crp_status = 0;
112 crpc->crp_static = !cached;
113 CFS_INIT_LIST_HEAD(&crpc->crp_link);
115 cfs_atomic_inc(&console_session.ses_rpc_counter);
121 lstcon_rpc_prep(lstcon_node_t *nd, int service,
122 int npg, lstcon_rpc_t **crpcpp)
124 lstcon_rpc_t *crpc = NULL;
127 cfs_spin_lock(&console_session.ses_rpc_lock);
129 if (!cfs_list_empty(&console_session.ses_rpc_freelist)) {
130 crpc = cfs_list_entry(console_session.ses_rpc_freelist.next,
131 lstcon_rpc_t, crp_link);
132 cfs_list_del_init(&crpc->crp_link);
135 cfs_spin_unlock(&console_session.ses_rpc_lock);
138 LIBCFS_ALLOC(crpc, sizeof(*crpc));
143 rc = lstcon_rpc_init(nd, service, npg, 1, crpc);
149 LIBCFS_FREE(crpc, sizeof(*crpc));
155 lstcon_rpc_put(lstcon_rpc_t *crpc)
157 srpc_bulk_t *bulk = &crpc->crp_rpc->crpc_bulk;
160 LASSERT (cfs_list_empty(&crpc->crp_link));
162 for (i = 0; i < bulk->bk_niov; i++) {
163 if (bulk->bk_iovs[i].kiov_page == NULL)
166 cfs_free_page(bulk->bk_iovs[i].kiov_page);
169 srpc_client_rpc_decref(crpc->crp_rpc);
171 if (crpc->crp_static) {
172 /* Static RPC, not allocated */
173 memset(crpc, 0, sizeof(*crpc));
174 crpc->crp_static = 1;
177 cfs_spin_lock(&console_session.ses_rpc_lock);
179 cfs_list_add(&crpc->crp_link,
180 &console_session.ses_rpc_freelist);
182 cfs_spin_unlock(&console_session.ses_rpc_lock);
185 /* RPC is not alive now */
186 cfs_atomic_dec(&console_session.ses_rpc_counter);
190 lstcon_rpc_post(lstcon_rpc_t *crpc)
192 lstcon_rpc_trans_t *trans = crpc->crp_trans;
194 LASSERT (trans != NULL);
196 cfs_atomic_inc(&trans->tas_remaining);
197 crpc->crp_posted = 1;
199 sfw_post_rpc(crpc->crp_rpc);
203 lstcon_rpc_trans_name(int transop)
205 if (transop == LST_TRANS_SESNEW)
208 if (transop == LST_TRANS_SESEND)
211 if (transop == LST_TRANS_SESQRY)
214 if (transop == LST_TRANS_SESPING)
217 if (transop == LST_TRANS_TSBCLIADD)
220 if (transop == LST_TRANS_TSBSRVADD)
223 if (transop == LST_TRANS_TSBRUN)
226 if (transop == LST_TRANS_TSBSTOP)
229 if (transop == LST_TRANS_TSBCLIQRY)
232 if (transop == LST_TRANS_TSBSRVQRY)
235 if (transop == LST_TRANS_STATQRY)
242 lstcon_rpc_trans_prep(cfs_list_t *translist,
243 int transop, lstcon_rpc_trans_t **transpp)
245 lstcon_rpc_trans_t *trans;
247 if (translist != NULL) {
248 cfs_list_for_each_entry_typed(trans, translist,
249 lstcon_rpc_trans_t, tas_link) {
250 /* Can't enqueue two private transaction on
252 if ((trans->tas_opc & transop) == LST_TRANS_PRIVATE)
257 /* create a trans group */
258 LIBCFS_ALLOC(trans, sizeof(*trans));
262 trans->tas_opc = transop;
264 if (translist == NULL)
265 CFS_INIT_LIST_HEAD(&trans->tas_olink);
267 cfs_list_add_tail(&trans->tas_olink, translist);
269 cfs_list_add_tail(&trans->tas_link, &console_session.ses_trans_list);
271 CFS_INIT_LIST_HEAD(&trans->tas_rpcs_list);
272 cfs_atomic_set(&trans->tas_remaining, 0);
273 cfs_waitq_init(&trans->tas_waitq);
281 lstcon_rpc_trans_addreq(lstcon_rpc_trans_t *trans, lstcon_rpc_t *crpc)
283 cfs_list_add_tail(&crpc->crp_link, &trans->tas_rpcs_list);
284 crpc->crp_trans = trans;
288 lstcon_rpc_trans_abort(lstcon_rpc_trans_t *trans, int error)
290 srpc_client_rpc_t *rpc;
294 cfs_list_for_each_entry_typed (crpc, &trans->tas_rpcs_list,
295 lstcon_rpc_t, crp_link) {
298 cfs_spin_lock(&rpc->crpc_lock);
300 if (!crpc->crp_posted || /* not posted */
301 crpc->crp_stamp != 0) { /* rpc done or aborted already */
302 if (crpc->crp_stamp == 0) {
303 crpc->crp_stamp = cfs_time_current();
304 crpc->crp_status = -EINTR;
306 cfs_spin_unlock(&rpc->crpc_lock);
310 crpc->crp_stamp = cfs_time_current();
311 crpc->crp_status = error;
313 cfs_spin_unlock(&rpc->crpc_lock);
317 if (error != ETIMEDOUT)
321 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
324 nd->nd_stamp = crpc->crp_stamp;
325 nd->nd_state = LST_NODE_DOWN;
330 lstcon_rpc_trans_check(lstcon_rpc_trans_t *trans)
332 if (console_session.ses_shutdown &&
333 !cfs_list_empty(&trans->tas_olink)) /* Not an end session RPC */
336 return (cfs_atomic_read(&trans->tas_remaining) == 0) ? 1: 0;
340 lstcon_rpc_trans_postwait(lstcon_rpc_trans_t *trans, int timeout)
345 if (cfs_list_empty(&trans->tas_rpcs_list))
348 if (timeout < LST_TRANS_MIN_TIMEOUT)
349 timeout = LST_TRANS_MIN_TIMEOUT;
351 CDEBUG(D_NET, "Transaction %s started\n",
352 lstcon_rpc_trans_name(trans->tas_opc));
354 /* post all requests */
355 cfs_list_for_each_entry_typed (crpc, &trans->tas_rpcs_list,
356 lstcon_rpc_t, crp_link) {
357 LASSERT (!crpc->crp_posted);
359 lstcon_rpc_post(crpc);
362 cfs_mutex_unlock(&console_session.ses_mutex);
364 cfs_waitq_wait_event_interruptible_timeout(trans->tas_waitq,
365 lstcon_rpc_trans_check(trans),
366 cfs_time_seconds(timeout), rc);
368 rc = (rc > 0)? 0: ((rc < 0)? -EINTR: -ETIMEDOUT);
370 cfs_mutex_lock(&console_session.ses_mutex);
372 if (console_session.ses_shutdown)
375 if (rc != 0 || atomic_read(&trans->tas_remaining) != 0) {
376 /* treat short timeout as canceled */
377 if (rc == -ETIMEDOUT && timeout < LST_TRANS_MIN_TIMEOUT * 2)
380 lstcon_rpc_trans_abort(trans, rc);
383 CDEBUG(D_NET, "Transaction %s stopped: %d\n",
384 lstcon_rpc_trans_name(trans->tas_opc), rc);
386 lstcon_rpc_trans_stat(trans, lstcon_trans_stat());
392 lstcon_rpc_get_reply(lstcon_rpc_t *crpc, srpc_msg_t **msgpp)
394 lstcon_node_t *nd = crpc->crp_node;
395 srpc_client_rpc_t *rpc = crpc->crp_rpc;
396 srpc_generic_reply_t *rep;
398 LASSERT (nd != NULL && rpc != NULL);
399 LASSERT (crpc->crp_stamp != 0);
401 if (crpc->crp_status != 0) {
403 return crpc->crp_status;
406 *msgpp = &rpc->crpc_replymsg;
407 if (!crpc->crp_unpacked) {
408 sfw_unpack_message(*msgpp);
409 crpc->crp_unpacked = 1;
412 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
415 nd->nd_stamp = crpc->crp_stamp;
416 rep = &(*msgpp)->msg_body.reply;
418 if (rep->sid.ses_nid == LNET_NID_ANY)
419 nd->nd_state = LST_NODE_UNKNOWN;
420 else if (lstcon_session_match(rep->sid))
421 nd->nd_state = LST_NODE_ACTIVE;
423 nd->nd_state = LST_NODE_BUSY;
429 lstcon_rpc_trans_stat(lstcon_rpc_trans_t *trans, lstcon_trans_stat_t *stat)
435 LASSERT (stat != NULL);
437 memset(stat, 0, sizeof(*stat));
439 cfs_list_for_each_entry_typed(crpc, &trans->tas_rpcs_list,
440 lstcon_rpc_t, crp_link) {
441 lstcon_rpc_stat_total(stat, 1);
443 LASSERT (crpc->crp_stamp != 0);
445 error = lstcon_rpc_get_reply(crpc, &rep);
447 lstcon_rpc_stat_failure(stat, 1);
448 if (stat->trs_rpc_errno == 0)
449 stat->trs_rpc_errno = -error;
454 lstcon_rpc_stat_success(stat, 1);
456 lstcon_rpc_stat_reply(trans->tas_opc, rep,
457 crpc->crp_node, stat);
460 CDEBUG(D_NET, "transaction %s : success %d, failure %d, total %d, "
461 "RPC error(%d), Framework error(%d)\n",
462 lstcon_rpc_trans_name(trans->tas_opc),
463 lstcon_rpc_stat_success(stat, 0),
464 lstcon_rpc_stat_failure(stat, 0),
465 lstcon_rpc_stat_total(stat, 0),
466 stat->trs_rpc_errno, stat->trs_fwk_errno);
472 lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
474 lstcon_rpc_readent_func_t readent)
478 lstcon_rpc_ent_t *ent;
479 srpc_generic_reply_t *rep;
487 LASSERT (head_up != NULL);
491 cfs_list_for_each_entry_typed(crpc, &trans->tas_rpcs_list,
492 lstcon_rpc_t, crp_link) {
493 if (cfs_copy_from_user(&tmp, next,
497 if (tmp.next == head_up)
502 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_lock(&console_session.ses_mutex);
1118 if (console_session.ses_shutdown || console_session.ses_expired) {
1119 cfs_mutex_unlock(&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_unlock(&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_unlock(&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_unlock(&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_lock(&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);