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 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 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 (atomic_dec_and_test(&crpc->crp_trans->tas_remaining))
87 cfs_waitq_signal(&crpc->crp_trans->tas_waitq);
89 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 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 spin_lock(&console_session.ses_rpc_lock);
127 if (!list_empty(&console_session.ses_rpc_freelist)) {
128 crpc = list_entry(console_session.ses_rpc_freelist.next,
129 lstcon_rpc_t, crp_link);
130 list_del_init(&crpc->crp_link);
133 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 (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 spin_lock(&console_session.ses_rpc_lock);
177 list_add(&crpc->crp_link, &console_session.ses_rpc_freelist);
179 spin_unlock(&console_session.ses_rpc_lock);
182 /* RPC is not alive now */
183 atomic_dec(&console_session.ses_rpc_counter);
187 lstcon_rpc_post(lstcon_rpc_t *crpc)
189 lstcon_rpc_trans_t *trans = crpc->crp_trans;
191 LASSERT (trans != NULL);
193 atomic_inc(&trans->tas_remaining);
194 crpc->crp_posted = 1;
196 sfw_post_rpc(crpc->crp_rpc);
200 lstcon_rpc_trans_name(int transop)
202 if (transop == LST_TRANS_SESNEW)
205 if (transop == LST_TRANS_SESEND)
208 if (transop == LST_TRANS_SESQRY)
211 if (transop == LST_TRANS_SESPING)
214 if (transop == LST_TRANS_TSBCLIADD)
217 if (transop == LST_TRANS_TSBSRVADD)
220 if (transop == LST_TRANS_TSBRUN)
223 if (transop == LST_TRANS_TSBSTOP)
226 if (transop == LST_TRANS_TSBCLIQRY)
229 if (transop == LST_TRANS_TSBSRVQRY)
232 if (transop == LST_TRANS_STATQRY)
239 lstcon_rpc_trans_prep(struct list_head *translist,
240 int transop, lstcon_rpc_trans_t **transpp)
242 lstcon_rpc_trans_t *trans;
244 if (translist != NULL) {
245 list_for_each_entry(trans, translist, tas_link) {
246 /* Can't enqueue two private transaction on
248 if ((trans->tas_opc & transop) == LST_TRANS_PRIVATE)
253 /* create a trans group */
254 LIBCFS_ALLOC(trans, sizeof(*trans));
258 trans->tas_opc = transop;
260 if (translist == NULL)
261 CFS_INIT_LIST_HEAD(&trans->tas_olink);
263 list_add_tail(&trans->tas_olink, translist);
265 list_add_tail(&trans->tas_link, &console_session.ses_trans_list);
267 CFS_INIT_LIST_HEAD(&trans->tas_rpcs_list);
268 atomic_set(&trans->tas_remaining, 0);
269 cfs_waitq_init(&trans->tas_waitq);
277 lstcon_rpc_trans_addreq(lstcon_rpc_trans_t *trans, lstcon_rpc_t *crpc)
279 list_add_tail(&crpc->crp_link, &trans->tas_rpcs_list);
280 crpc->crp_trans = trans;
284 lstcon_rpc_trans_abort(lstcon_rpc_trans_t *trans, int error)
286 srpc_client_rpc_t *rpc;
290 list_for_each_entry (crpc, &trans->tas_rpcs_list, crp_link) {
293 spin_lock(&rpc->crpc_lock);
295 if (!crpc->crp_posted || crpc->crp_stamp != 0) {
296 /* rpc done or aborted already */
297 spin_unlock(&rpc->crpc_lock);
301 crpc->crp_stamp = cfs_time_current();
302 crpc->crp_status = error;
304 spin_unlock(&rpc->crpc_lock);
308 if (error != ETIMEDOUT)
312 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
315 nd->nd_stamp = crpc->crp_stamp;
316 nd->nd_state = LST_NODE_DOWN;
321 lstcon_rpc_trans_check(lstcon_rpc_trans_t *trans)
323 if (console_session.ses_shutdown &&
324 !list_empty(&trans->tas_olink)) /* It's not an end session RPC */
327 return (atomic_read(&trans->tas_remaining) == 0) ? 1: 0;
331 lstcon_rpc_trans_postwait(lstcon_rpc_trans_t *trans, int timeout)
336 if (list_empty(&trans->tas_rpcs_list))
339 if (timeout < LST_TRANS_MIN_TIMEOUT)
340 timeout = LST_TRANS_MIN_TIMEOUT;
342 CDEBUG(D_NET, "Transaction %s started\n",
343 lstcon_rpc_trans_name(trans->tas_opc));
345 /* post all requests */
346 list_for_each_entry (crpc, &trans->tas_rpcs_list, crp_link) {
347 LASSERT (!crpc->crp_posted);
349 lstcon_rpc_post(crpc);
352 mutex_up(&console_session.ses_mutex);
354 rc = cfs_waitq_wait_event_interruptible_timeout(trans->tas_waitq,
355 lstcon_rpc_trans_check(trans),
358 rc = (rc > 0)? 0: ((rc < 0)? -EINTR: -ETIMEDOUT);
360 mutex_down(&console_session.ses_mutex);
362 if (console_session.ses_shutdown)
366 /* treat short timeout as canceled */
367 if (rc == -ETIMEDOUT && timeout < LST_TRANS_MIN_TIMEOUT * 2)
370 lstcon_rpc_trans_abort(trans, rc);
373 CDEBUG(D_NET, "Transaction %s stopped: %d\n",
374 lstcon_rpc_trans_name(trans->tas_opc), rc);
376 lstcon_rpc_trans_stat(trans, lstcon_trans_stat());
382 lstcon_rpc_get_reply(lstcon_rpc_t *crpc, srpc_msg_t **msgpp)
384 lstcon_node_t *nd = crpc->crp_node;
385 srpc_client_rpc_t *rpc = crpc->crp_rpc;
386 srpc_generic_reply_t *rep;
388 LASSERT (nd != NULL && rpc != NULL);
389 LASSERT (crpc->crp_stamp != 0);
391 if (crpc->crp_status != 0) {
393 return crpc->crp_status;
396 *msgpp = &rpc->crpc_replymsg;
397 if (!crpc->crp_unpacked) {
398 sfw_unpack_message(*msgpp);
399 crpc->crp_unpacked = 1;
402 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
405 nd->nd_stamp = crpc->crp_stamp;
406 rep = &(*msgpp)->msg_body.reply;
408 if (rep->sid.ses_nid == LNET_NID_ANY)
409 nd->nd_state = LST_NODE_UNKNOWN;
410 else if (lstcon_session_match(rep->sid))
411 nd->nd_state = LST_NODE_ACTIVE;
413 nd->nd_state = LST_NODE_BUSY;
419 lstcon_rpc_trans_stat(lstcon_rpc_trans_t *trans, lstcon_trans_stat_t *stat)
422 srpc_client_rpc_t *rpc;
426 LASSERT (stat != NULL);
428 memset(stat, 0, sizeof(*stat));
430 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
431 lstcon_rpc_stat_total(stat, 1);
435 LASSERT (crpc->crp_stamp != 0);
437 error = lstcon_rpc_get_reply(crpc, &rep);
439 lstcon_rpc_stat_failure(stat, 1);
440 if (stat->trs_rpc_errno == 0)
441 stat->trs_rpc_errno = -error;
446 lstcon_rpc_stat_success(stat, 1);
448 lstcon_rpc_stat_reply(trans->tas_opc, rep,
449 crpc->crp_node, stat);
452 CDEBUG(D_NET, "transaction %s : success %d, failure %d, total %d, "
453 "RPC error(%d), Framework error(%d)\n",
454 lstcon_rpc_trans_name(trans->tas_opc),
455 lstcon_rpc_stat_success(stat, 0),
456 lstcon_rpc_stat_failure(stat, 0),
457 lstcon_rpc_stat_total(stat, 0),
458 stat->trs_rpc_errno, stat->trs_fwk_errno);
464 lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
465 struct list_head *head_up,
466 lstcon_rpc_readent_func_t readent)
468 struct list_head tmp;
469 struct list_head *next;
470 lstcon_rpc_ent_t *ent;
471 srpc_generic_reply_t *rep;
472 srpc_client_rpc_t *rpc;
480 LASSERT (head_up != NULL);
484 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
485 if (copy_from_user(&tmp, next, sizeof(struct list_head)))
488 if (tmp.next == head_up)
493 ent = list_entry(next, lstcon_rpc_ent_t, rpe_link);
497 LASSERT (crpc->crp_stamp != 0);
499 error = lstcon_rpc_get_reply(crpc, &msg);
503 dur = cfs_time_sub(crpc->crp_stamp,
504 console_session.ses_id.ses_stamp);
505 cfs_duration_usec(dur, &tv);
507 if (copy_to_user(&ent->rpe_peer,
508 &nd->nd_id, sizeof(lnet_process_id_t)) ||
509 copy_to_user(&ent->rpe_stamp, &tv, sizeof(tv)) ||
510 copy_to_user(&ent->rpe_state,
511 &nd->nd_state, sizeof(nd->nd_state)) ||
512 copy_to_user(&ent->rpe_rpc_errno, &error, sizeof(error)))
519 rep = (srpc_generic_reply_t *)&msg->msg_body.reply;
521 if (copy_to_user(&ent->rpe_sid,
522 &rep->sid, sizeof(lst_sid_t)) ||
523 copy_to_user(&ent->rpe_fwk_errno,
524 &rep->status, sizeof(rep->status)))
530 if ((error = readent(trans->tas_opc, msg, ent)) != 0)
538 lstcon_rpc_trans_destroy(lstcon_rpc_trans_t *trans)
540 srpc_client_rpc_t *rpc;
545 list_for_each_entry_safe(crpc, tmp,
546 &trans->tas_rpcs_list, crp_link) {
549 spin_lock(&rpc->crpc_lock);
551 /* free it if not posted or finished already */
552 if (!crpc->crp_posted || crpc->crp_finished) {
553 spin_unlock(&rpc->crpc_lock);
555 list_del_init(&crpc->crp_link);
556 lstcon_rpc_put(crpc);
561 /* rpcs can be still not callbacked (even LNetMDUnlink is called)
562 * because huge timeout for inaccessible network, don't make
563 * user wait for them, just abandon them, they will be recycled
566 LASSERT (crpc->crp_status != 0);
568 crpc->crp_node = NULL;
569 crpc->crp_trans = NULL;
570 list_del_init(&crpc->crp_link);
573 spin_unlock(&rpc->crpc_lock);
575 atomic_dec(&trans->tas_remaining);
578 LASSERT (atomic_read(&trans->tas_remaining) == 0);
580 list_del(&trans->tas_link);
581 if (!list_empty(&trans->tas_olink))
582 list_del(&trans->tas_olink);
584 CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
585 lstcon_rpc_trans_name(trans->tas_opc), count);
587 LIBCFS_FREE(trans, sizeof(*trans));
593 lstcon_sesrpc_prep(lstcon_node_t *nd, int transop, lstcon_rpc_t **crpc)
595 srpc_mksn_reqst_t *msrq;
596 srpc_rmsn_reqst_t *rsrq;
600 case LST_TRANS_SESNEW:
601 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION, 0, crpc);
605 msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
606 msrq->mksn_sid = console_session.ses_id;
607 msrq->mksn_force = console_session.ses_force;
608 strncpy(msrq->mksn_name, console_session.ses_name,
609 strlen(console_session.ses_name));
612 case LST_TRANS_SESEND:
613 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION, 0, crpc);
617 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
618 rsrq->rmsn_sid = console_session.ses_id;
629 lstcon_dbgrpc_prep(lstcon_node_t *nd, lstcon_rpc_t **crpc)
631 srpc_debug_reqst_t *drq;
634 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, 0, crpc);
638 drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
640 drq->dbg_sid = console_session.ses_id;
647 lstcon_batrpc_prep(lstcon_node_t *nd, int transop,
648 lstcon_tsb_hdr_t *tsb, lstcon_rpc_t **crpc)
650 lstcon_batch_t *batch;
651 srpc_batch_reqst_t *brq;
654 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, 0, crpc);
658 brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
660 brq->bar_sid = console_session.ses_id;
661 brq->bar_bid = tsb->tsb_id;
662 brq->bar_testidx = tsb->tsb_index;
663 brq->bar_opc = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
664 (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP:
665 SRPC_BATCH_OPC_QUERY);
667 if (transop != LST_TRANS_TSBRUN &&
668 transop != LST_TRANS_TSBSTOP)
671 LASSERT (tsb->tsb_index == 0);
673 batch = (lstcon_batch_t *)tsb;
674 brq->bar_arg = batch->bat_arg;
680 lstcon_statrpc_prep(lstcon_node_t *nd, lstcon_rpc_t **crpc)
682 srpc_stat_reqst_t *srq;
685 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_QUERY_STAT, 0, crpc);
689 srq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.stat_reqst;
691 srq->str_sid = console_session.ses_id;
692 srq->str_type = 0; /* XXX remove it */
698 lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov)
700 lnet_process_id_t *pid;
703 i = idx / (CFS_PAGE_SIZE / sizeof(lnet_process_id_t));
707 pid = (lnet_process_id_t *)cfs_page_address(kiov[i].kiov_page);
709 return &pid[idx % (CFS_PAGE_SIZE / sizeof(lnet_process_id_t))];
713 lstcon_dstnodes_prep(lstcon_group_t *grp, int idx,
714 int dist, int span, int nkiov, lnet_kiov_t *kiov)
716 lnet_process_id_t *pid;
717 lstcon_ndlink_t *ndl;
725 LASSERT (grp->grp_nnode >= 1);
727 if (span > grp->grp_nnode)
730 start = ((idx / dist) * span) % grp->grp_nnode;
731 end = ((idx / dist) * span + span - 1) % grp->grp_nnode;
733 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
740 if (i > (end >= start ? end: grp->grp_nnode))
743 pid = lstcon_next_id((i - start), nkiov, kiov);
748 if (start <= end) /* done */
751 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
752 if (i > grp->grp_nnode + end)
756 pid = lstcon_next_id((i - start), nkiov, kiov);
765 lstcon_pingrpc_prep(lst_test_ping_param_t *param, srpc_test_reqst_t *req)
767 test_ping_req_t *prq = &req->tsr_u.ping;
769 prq->png_size = param->png_size;
770 prq->png_flags = param->png_flags;
776 lstcon_bulkrpc_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
778 test_bulk_req_t *brq = &req->tsr_u.bulk;
780 brq->blk_opc = param->blk_opc;
781 brq->blk_npg = (param->blk_size + CFS_PAGE_SIZE - 1) / CFS_PAGE_SIZE;
782 brq->blk_flags = param->blk_flags;
788 lstcon_testrpc_prep(lstcon_node_t *nd, int transop,
789 lstcon_test_t *test, lstcon_rpc_t **crpc)
791 lstcon_group_t *sgrp = test->tes_src_grp;
792 lstcon_group_t *dgrp = test->tes_dst_grp;
793 srpc_test_reqst_t *trq;
799 if (transop == LST_TRANS_TSBCLIADD)
800 n = sfw_id_pages(test->tes_span);
802 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, n, crpc);
806 trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
808 if (transop == LST_TRANS_TSBSRVADD) {
809 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
810 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
811 int nmax = (ndist + nspan - 1) / nspan;
814 trq->tsr_loop = nmax * test->tes_dist * test->tes_concur;
817 bulk = &(*crpc)->crp_rpc->crpc_bulk;
819 for (i = 0; i < n; i++) {
820 bulk->bk_iovs[i].kiov_offset = 0;
821 bulk->bk_iovs[i].kiov_len = CFS_PAGE_SIZE;
822 bulk->bk_iovs[i].kiov_page = cfs_alloc_page(CFS_ALLOC_STD);
824 if (bulk->bk_iovs[i].kiov_page != NULL)
827 lstcon_rpc_put(*crpc);
833 LASSERT (transop == LST_TRANS_TSBCLIADD);
835 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
836 test->tes_cliidx++, test->tes_dist,
837 test->tes_span, n, &bulk->bk_iovs[0]);
839 lstcon_rpc_put(*crpc);
843 trq->tsr_ndest = test->tes_span;
844 trq->tsr_loop = test->tes_loop;
847 trq->tsr_sid = console_session.ses_id;
848 trq->tsr_bid = test->tes_hdr.tsb_id;
849 trq->tsr_concur = test->tes_concur;
850 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
851 trq->tsr_stop_onerr = test->tes_stop_onerr;
853 switch (test->tes_type) {
855 trq->tsr_service = SRPC_SERVICE_PING;
856 rc = lstcon_pingrpc_prep((lst_test_ping_param_t *)&test->tes_param[0], trq);
859 trq->tsr_service = SRPC_SERVICE_BRW;
860 rc = lstcon_bulkrpc_prep((lst_test_bulk_param_t *)&test->tes_param[0], trq);
871 lstcon_rpc_stat_reply(int transop, srpc_msg_t *msg,
872 lstcon_node_t *nd, lstcon_trans_stat_t *stat)
874 srpc_mksn_reply_t *mksn_rep;
875 srpc_rmsn_reply_t *rmsn_rep;
876 srpc_debug_reply_t *dbg_rep;
877 srpc_batch_reply_t *bat_rep;
878 srpc_test_reply_t *test_rep;
879 srpc_stat_reply_t *stat_rep;
883 case LST_TRANS_SESNEW:
884 mksn_rep = &msg->msg_body.mksn_reply;
886 if (mksn_rep->mksn_status == 0) {
887 lstcon_sesop_stat_success(stat, 1);
888 /* session timeout on remote node */
889 nd->nd_timeout = mksn_rep->mksn_timeout;
893 LASSERT (mksn_rep->mksn_status == EBUSY ||
894 mksn_rep->mksn_status == EINVAL);
896 lstcon_sesop_stat_failure(stat, 1);
897 errno = mksn_rep->mksn_status;
900 case LST_TRANS_SESEND:
901 rmsn_rep = &msg->msg_body.rmsn_reply;
902 /* ESRCH is not an error for end session */
903 if (rmsn_rep->rmsn_status == 0 ||
904 rmsn_rep->rmsn_status == ESRCH) {
905 lstcon_sesop_stat_success(stat, 1);
909 LASSERT (rmsn_rep->rmsn_status == EBUSY ||
910 rmsn_rep->rmsn_status == EINVAL);
912 lstcon_sesop_stat_failure(stat, 1);
913 errno = rmsn_rep->rmsn_status;
916 case LST_TRANS_SESQRY:
917 case LST_TRANS_SESPING:
918 dbg_rep = &msg->msg_body.dbg_reply;
920 if (dbg_rep->dbg_status == ESRCH) {
921 lstcon_sesqry_stat_unknown(stat, 1);
925 LASSERT (dbg_rep->dbg_status == 0);
927 if (lstcon_session_match(dbg_rep->dbg_sid))
928 lstcon_sesqry_stat_active(stat, 1);
930 lstcon_sesqry_stat_busy(stat, 1);
933 case LST_TRANS_TSBRUN:
934 case LST_TRANS_TSBSTOP:
935 bat_rep = &msg->msg_body.bat_reply;
937 if (bat_rep->bar_status == 0) {
938 lstcon_tsbop_stat_success(stat, 1);
942 if (bat_rep->bar_status == EPERM &&
943 transop == LST_TRANS_TSBSTOP) {
944 lstcon_tsbop_stat_success(stat, 1);
948 lstcon_tsbop_stat_failure(stat, 1);
949 errno = bat_rep->bar_status;
952 case LST_TRANS_TSBCLIQRY:
953 case LST_TRANS_TSBSRVQRY:
954 bat_rep = &msg->msg_body.bat_reply;
956 if (bat_rep->bar_active != 0)
957 lstcon_tsbqry_stat_run(stat, 1);
959 lstcon_tsbqry_stat_idle(stat, 1);
961 if (bat_rep->bar_status == 0)
964 lstcon_tsbqry_stat_failure(stat, 1);
965 errno = bat_rep->bar_status;
968 case LST_TRANS_TSBCLIADD:
969 case LST_TRANS_TSBSRVADD:
970 test_rep = &msg->msg_body.tes_reply;
972 if (test_rep->tsr_status == 0) {
973 lstcon_tsbop_stat_success(stat, 1);
977 lstcon_tsbop_stat_failure(stat, 1);
978 errno = test_rep->tsr_status;
981 case LST_TRANS_STATQRY:
982 stat_rep = &msg->msg_body.stat_reply;
984 if (stat_rep->str_status == 0) {
985 lstcon_statqry_stat_success(stat, 1);
989 lstcon_statqry_stat_failure(stat, 1);
990 errno = stat_rep->str_status;
997 if (stat->trs_fwk_errno == 0)
998 stat->trs_fwk_errno = errno;
1004 lstcon_rpc_trans_ndlist(struct list_head *ndlist,
1005 struct list_head *translist, int transop,
1006 void *arg, lstcon_rpc_cond_func_t condition,
1007 lstcon_rpc_trans_t **transpp)
1009 lstcon_rpc_trans_t *trans;
1010 lstcon_ndlink_t *ndl;
1015 /* Creating session RPG for list of nodes */
1017 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1019 CERROR("Can't create transaction %d: %d\n", transop, rc);
1023 list_for_each_entry(ndl, ndlist, ndl_link) {
1024 rc = condition == NULL ? 1 :
1025 condition(transop, ndl->ndl_node, arg);
1031 CDEBUG(D_NET, "Condition error while creating RPC "
1032 " for transaction %d: %d\n", transop, rc);
1039 case LST_TRANS_SESNEW:
1040 case LST_TRANS_SESEND:
1041 rc = lstcon_sesrpc_prep(nd, transop, &rpc);
1043 case LST_TRANS_SESQRY:
1044 case LST_TRANS_SESPING:
1045 rc = lstcon_dbgrpc_prep(nd, &rpc);
1047 case LST_TRANS_TSBCLIADD:
1048 case LST_TRANS_TSBSRVADD:
1049 rc = lstcon_testrpc_prep(nd, transop,
1050 (lstcon_test_t *)arg, &rpc);
1052 case LST_TRANS_TSBRUN:
1053 case LST_TRANS_TSBSTOP:
1054 case LST_TRANS_TSBCLIQRY:
1055 case LST_TRANS_TSBSRVQRY:
1056 rc = lstcon_batrpc_prep(nd, transop,
1057 (lstcon_tsb_hdr_t *)arg, &rpc);
1059 case LST_TRANS_STATQRY:
1060 rc = lstcon_statrpc_prep(nd, &rpc);
1068 CERROR("Failed to create RPC for transaction %s: %d\n",
1069 lstcon_rpc_trans_name(transop), rc);
1073 lstcon_rpc_trans_addreq(trans, rpc);
1081 lstcon_rpc_trans_destroy(trans);
1087 lstcon_rpc_pinger(void *arg)
1089 stt_timer_t *ptimer = (stt_timer_t *)arg;
1090 lstcon_rpc_trans_t *trans;
1093 srpc_debug_reqst_t *drq;
1094 lstcon_ndlink_t *ndl;
1100 /* RPC pinger is a special case of transaction,
1101 * it's called by timer at 8 seconds interval.
1103 mutex_down(&console_session.ses_mutex);
1105 if (console_session.ses_shutdown || console_session.ses_expired) {
1106 mutex_up(&console_session.ses_mutex);
1110 if (!console_session.ses_expired &&
1111 cfs_time_current_sec() - console_session.ses_laststamp >
1112 console_session.ses_timeout)
1113 console_session.ses_expired = 1;
1115 trans = console_session.ses_ping;
1117 LASSERT (trans != NULL);
1119 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link) {
1122 if (console_session.ses_expired) {
1123 /* idle console, end session on all nodes */
1124 if (nd->nd_state != LST_NODE_ACTIVE)
1127 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND, &crpc);
1129 CERROR("Out of memory\n");
1133 lstcon_rpc_trans_addreq(trans, crpc);
1134 lstcon_rpc_post(crpc);
1139 crpc = &nd->nd_ping;
1141 if (crpc->crp_rpc != NULL) {
1142 LASSERT (crpc->crp_trans == trans);
1143 LASSERT (!list_empty(&crpc->crp_link));
1145 spin_lock(&crpc->crp_rpc->crpc_lock);
1147 LASSERT (crpc->crp_posted);
1149 if (!crpc->crp_finished) {
1151 spin_unlock(&crpc->crp_rpc->crpc_lock);
1155 spin_unlock(&crpc->crp_rpc->crpc_lock);
1157 lstcon_rpc_get_reply(crpc, &rep);
1159 list_del_init(&crpc->crp_link);
1161 lstcon_rpc_put(crpc);
1164 if (nd->nd_state != LST_NODE_ACTIVE)
1167 intv = cfs_duration_sec(cfs_time_sub(cfs_time_current(),
1169 if (intv < nd->nd_timeout / 2)
1172 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG, 0, 0, crpc);
1174 CERROR("Out of memory\n");
1178 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1180 drq->dbg_sid = console_session.ses_id;
1183 lstcon_rpc_trans_addreq(trans, crpc);
1184 lstcon_rpc_post(crpc);
1189 if (console_session.ses_expired) {
1190 mutex_up(&console_session.ses_mutex);
1194 CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1196 ptimer->stt_expires = cfs_time_current_sec() + LST_PING_INTERVAL;
1197 stt_add_timer(ptimer);
1199 mutex_up(&console_session.ses_mutex);
1203 lstcon_rpc_pinger_start(void)
1205 stt_timer_t *ptimer;
1208 LASSERT (list_empty(&console_session.ses_rpc_freelist));
1209 LASSERT (atomic_read(&console_session.ses_rpc_counter) == 0);
1211 rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1212 &console_session.ses_ping);
1214 CERROR("Failed to create console pinger\n");
1218 ptimer = &console_session.ses_ping_timer;
1219 ptimer->stt_expires = cfs_time_current_sec() + LST_PING_INTERVAL;
1221 stt_add_timer(ptimer);
1227 lstcon_rpc_pinger_stop(void)
1229 LASSERT (console_session.ses_shutdown);
1231 stt_del_timer(&console_session.ses_ping_timer);
1233 lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1234 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1235 lstcon_rpc_trans_destroy(console_session.ses_ping);
1237 memset(lstcon_trans_stat(), 0, sizeof(lstcon_trans_stat_t));
1239 console_session.ses_ping = NULL;
1243 lstcon_rpc_cleanup_wait(void)
1245 lstcon_rpc_trans_t *trans;
1247 struct list_head *pacer;
1248 struct list_head zlist;
1250 /* Called with hold of global mutex */
1252 LASSERT (console_session.ses_shutdown);
1254 while (!list_empty(&console_session.ses_trans_list)) {
1255 list_for_each(pacer, &console_session.ses_trans_list) {
1256 trans = list_entry(pacer, lstcon_rpc_trans_t, tas_link);
1258 CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1259 lstcon_rpc_trans_name(trans->tas_opc));
1261 cfs_waitq_signal(&trans->tas_waitq);
1264 mutex_up(&console_session.ses_mutex);
1266 CWARN("Session is shutting down, "
1267 "waiting for termination of transactions\n");
1268 cfs_pause(cfs_time_seconds(1));
1270 mutex_down(&console_session.ses_mutex);
1273 spin_lock(&console_session.ses_rpc_lock);
1275 lst_wait_until((atomic_read(&console_session.ses_rpc_counter) == 0),
1276 console_session.ses_rpc_lock,
1277 "Network is not accessable or target is down, "
1278 "waiting for %d console RPCs to being recycled\n",
1279 atomic_read(&console_session.ses_rpc_counter));
1281 list_add(&zlist, &console_session.ses_rpc_freelist);
1282 list_del_init(&console_session.ses_rpc_freelist);
1284 spin_unlock(&console_session.ses_rpc_lock);
1286 while (!list_empty(&zlist)) {
1287 crpc = list_entry(zlist.next, lstcon_rpc_t, crp_link);
1289 list_del(&crpc->crp_link);
1290 LIBCFS_FREE(crpc, sizeof(lstcon_rpc_t));
1295 lstcon_rpc_module_init(void)
1297 CFS_INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1298 console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1299 console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1301 console_session.ses_ping = NULL;
1303 spin_lock_init(&console_session.ses_rpc_lock);
1304 atomic_set(&console_session.ses_rpc_counter, 0);
1305 CFS_INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1311 lstcon_rpc_module_fini(void)
1313 LASSERT (list_empty(&console_session.ses_rpc_freelist));
1314 LASSERT (atomic_read(&console_session.ses_rpc_counter) == 0);