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.
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 || /* not posted */
296 crpc->crp_stamp != 0) { /* rpc done or aborted already */
297 if (crpc->crp_stamp == 0) {
298 crpc->crp_stamp = cfs_time_current();
299 crpc->crp_status = -EINTR;
301 spin_unlock(&rpc->crpc_lock);
305 crpc->crp_stamp = cfs_time_current();
306 crpc->crp_status = error;
308 spin_unlock(&rpc->crpc_lock);
312 if (error != ETIMEDOUT)
316 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
319 nd->nd_stamp = crpc->crp_stamp;
320 nd->nd_state = LST_NODE_DOWN;
325 lstcon_rpc_trans_check(lstcon_rpc_trans_t *trans)
327 if (console_session.ses_shutdown &&
328 !list_empty(&trans->tas_olink)) /* It's not an end session RPC */
331 return (atomic_read(&trans->tas_remaining) == 0) ? 1: 0;
335 lstcon_rpc_trans_postwait(lstcon_rpc_trans_t *trans, int timeout)
340 if (list_empty(&trans->tas_rpcs_list))
343 if (timeout < LST_TRANS_MIN_TIMEOUT)
344 timeout = LST_TRANS_MIN_TIMEOUT;
346 CDEBUG(D_NET, "Transaction %s started\n",
347 lstcon_rpc_trans_name(trans->tas_opc));
349 /* post all requests */
350 list_for_each_entry (crpc, &trans->tas_rpcs_list, crp_link) {
351 LASSERT (!crpc->crp_posted);
353 lstcon_rpc_post(crpc);
356 mutex_up(&console_session.ses_mutex);
358 rc = cfs_waitq_wait_event_interruptible_timeout(trans->tas_waitq,
359 lstcon_rpc_trans_check(trans),
362 rc = (rc > 0)? 0: ((rc < 0)? -EINTR: -ETIMEDOUT);
364 mutex_down(&console_session.ses_mutex);
366 if (console_session.ses_shutdown)
369 if (rc != 0 || atomic_read(&trans->tas_remaining) != 0) {
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 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
435 lstcon_rpc_stat_total(stat, 1);
439 LASSERT (crpc->crp_stamp != 0);
441 error = lstcon_rpc_get_reply(crpc, &rep);
443 lstcon_rpc_stat_failure(stat, 1);
444 if (stat->trs_rpc_errno == 0)
445 stat->trs_rpc_errno = -error;
450 lstcon_rpc_stat_success(stat, 1);
452 lstcon_rpc_stat_reply(trans->tas_opc, rep,
453 crpc->crp_node, stat);
456 CDEBUG(D_NET, "transaction %s : success %d, failure %d, total %d, "
457 "RPC error(%d), Framework error(%d)\n",
458 lstcon_rpc_trans_name(trans->tas_opc),
459 lstcon_rpc_stat_success(stat, 0),
460 lstcon_rpc_stat_failure(stat, 0),
461 lstcon_rpc_stat_total(stat, 0),
462 stat->trs_rpc_errno, stat->trs_fwk_errno);
468 lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
469 struct list_head *head_up,
470 lstcon_rpc_readent_func_t readent)
472 struct list_head tmp;
473 struct list_head *next;
474 lstcon_rpc_ent_t *ent;
475 srpc_generic_reply_t *rep;
476 srpc_client_rpc_t *rpc;
484 LASSERT (head_up != NULL);
488 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
489 if (copy_from_user(&tmp, next, sizeof(struct list_head)))
492 if (tmp.next == head_up)
497 ent = list_entry(next, lstcon_rpc_ent_t, rpe_link);
501 LASSERT (crpc->crp_stamp != 0);
503 error = lstcon_rpc_get_reply(crpc, &msg);
507 dur = cfs_time_sub(crpc->crp_stamp,
508 console_session.ses_id.ses_stamp);
509 cfs_duration_usec(dur, &tv);
511 if (copy_to_user(&ent->rpe_peer,
512 &nd->nd_id, sizeof(lnet_process_id_t)) ||
513 copy_to_user(&ent->rpe_stamp, &tv, sizeof(tv)) ||
514 copy_to_user(&ent->rpe_state,
515 &nd->nd_state, sizeof(nd->nd_state)) ||
516 copy_to_user(&ent->rpe_rpc_errno, &error, sizeof(error)))
523 rep = (srpc_generic_reply_t *)&msg->msg_body.reply;
525 if (copy_to_user(&ent->rpe_sid,
526 &rep->sid, sizeof(lst_sid_t)) ||
527 copy_to_user(&ent->rpe_fwk_errno,
528 &rep->status, sizeof(rep->status)))
534 if ((error = readent(trans->tas_opc, msg, ent)) != 0)
542 lstcon_rpc_trans_destroy(lstcon_rpc_trans_t *trans)
544 srpc_client_rpc_t *rpc;
549 list_for_each_entry_safe(crpc, tmp,
550 &trans->tas_rpcs_list, crp_link) {
553 spin_lock(&rpc->crpc_lock);
555 /* free it if not posted or finished already */
556 if (!crpc->crp_posted || crpc->crp_finished) {
557 spin_unlock(&rpc->crpc_lock);
559 list_del_init(&crpc->crp_link);
560 lstcon_rpc_put(crpc);
565 /* rpcs can be still not callbacked (even LNetMDUnlink is called)
566 * because huge timeout for inaccessible network, don't make
567 * user wait for them, just abandon them, they will be recycled
570 LASSERT (crpc->crp_status != 0);
572 crpc->crp_node = NULL;
573 crpc->crp_trans = NULL;
574 list_del_init(&crpc->crp_link);
577 spin_unlock(&rpc->crpc_lock);
579 atomic_dec(&trans->tas_remaining);
582 LASSERT (atomic_read(&trans->tas_remaining) == 0);
584 list_del(&trans->tas_link);
585 if (!list_empty(&trans->tas_olink))
586 list_del(&trans->tas_olink);
588 CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
589 lstcon_rpc_trans_name(trans->tas_opc), count);
591 LIBCFS_FREE(trans, sizeof(*trans));
597 lstcon_sesrpc_prep(lstcon_node_t *nd, int transop, lstcon_rpc_t **crpc)
599 srpc_mksn_reqst_t *msrq;
600 srpc_rmsn_reqst_t *rsrq;
604 case LST_TRANS_SESNEW:
605 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION, 0, crpc);
609 msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
610 msrq->mksn_sid = console_session.ses_id;
611 msrq->mksn_force = console_session.ses_force;
612 strncpy(msrq->mksn_name, console_session.ses_name,
613 strlen(console_session.ses_name));
616 case LST_TRANS_SESEND:
617 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION, 0, crpc);
621 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
622 rsrq->rmsn_sid = console_session.ses_id;
633 lstcon_dbgrpc_prep(lstcon_node_t *nd, lstcon_rpc_t **crpc)
635 srpc_debug_reqst_t *drq;
638 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, 0, crpc);
642 drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
644 drq->dbg_sid = console_session.ses_id;
651 lstcon_batrpc_prep(lstcon_node_t *nd, int transop,
652 lstcon_tsb_hdr_t *tsb, lstcon_rpc_t **crpc)
654 lstcon_batch_t *batch;
655 srpc_batch_reqst_t *brq;
658 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, 0, crpc);
662 brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
664 brq->bar_sid = console_session.ses_id;
665 brq->bar_bid = tsb->tsb_id;
666 brq->bar_testidx = tsb->tsb_index;
667 brq->bar_opc = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
668 (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP:
669 SRPC_BATCH_OPC_QUERY);
671 if (transop != LST_TRANS_TSBRUN &&
672 transop != LST_TRANS_TSBSTOP)
675 LASSERT (tsb->tsb_index == 0);
677 batch = (lstcon_batch_t *)tsb;
678 brq->bar_arg = batch->bat_arg;
684 lstcon_statrpc_prep(lstcon_node_t *nd, lstcon_rpc_t **crpc)
686 srpc_stat_reqst_t *srq;
689 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_QUERY_STAT, 0, crpc);
693 srq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.stat_reqst;
695 srq->str_sid = console_session.ses_id;
696 srq->str_type = 0; /* XXX remove it */
701 lnet_process_id_packed_t *
702 lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov)
704 lnet_process_id_packed_t *pid;
707 i = idx / SFW_ID_PER_PAGE;
711 pid = (lnet_process_id_packed_t *)cfs_page_address(kiov[i].kiov_page);
713 return &pid[idx % SFW_ID_PER_PAGE];
717 lstcon_dstnodes_prep(lstcon_group_t *grp, int idx,
718 int dist, int span, int nkiov, lnet_kiov_t *kiov)
720 lnet_process_id_packed_t *pid;
721 lstcon_ndlink_t *ndl;
729 LASSERT (grp->grp_nnode >= 1);
731 if (span > grp->grp_nnode)
734 start = ((idx / dist) * span) % grp->grp_nnode;
735 end = ((idx / dist) * span + span - 1) % grp->grp_nnode;
737 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
744 if (i > (end >= start ? end: grp->grp_nnode))
747 pid = lstcon_next_id((i - start), nkiov, kiov);
748 pid->nid = nd->nd_id.nid;
749 pid->pid = nd->nd_id.pid;
753 if (start <= end) /* done */
756 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
757 if (i > grp->grp_nnode + end)
761 pid = lstcon_next_id((i - start), nkiov, kiov);
762 pid->nid = nd->nd_id.nid;
763 pid->pid = nd->nd_id.pid;
771 lstcon_pingrpc_prep(lst_test_ping_param_t *param, srpc_test_reqst_t *req)
773 test_ping_req_t *prq = &req->tsr_u.ping;
775 prq->png_size = param->png_size;
776 prq->png_flags = param->png_flags;
782 lstcon_bulkrpc_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
784 test_bulk_req_t *brq = &req->tsr_u.bulk;
786 brq->blk_opc = param->blk_opc;
787 brq->blk_npg = (param->blk_size + CFS_PAGE_SIZE - 1) / CFS_PAGE_SIZE;
788 brq->blk_flags = param->blk_flags;
794 lstcon_testrpc_prep(lstcon_node_t *nd, int transop,
795 lstcon_test_t *test, lstcon_rpc_t **crpc)
797 lstcon_group_t *sgrp = test->tes_src_grp;
798 lstcon_group_t *dgrp = test->tes_dst_grp;
799 srpc_test_reqst_t *trq;
805 if (transop == LST_TRANS_TSBCLIADD)
806 n = sfw_id_pages(test->tes_span);
808 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, n, crpc);
812 trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
814 if (transop == LST_TRANS_TSBSRVADD) {
815 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
816 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
817 int nmax = (ndist + nspan - 1) / nspan;
820 trq->tsr_loop = nmax * test->tes_dist * test->tes_concur;
823 bulk = &(*crpc)->crp_rpc->crpc_bulk;
825 for (i = 0; i < n; i++) {
826 bulk->bk_iovs[i].kiov_offset = 0;
827 bulk->bk_iovs[i].kiov_len = CFS_PAGE_SIZE;
828 bulk->bk_iovs[i].kiov_page = cfs_alloc_page(CFS_ALLOC_STD);
830 if (bulk->bk_iovs[i].kiov_page != NULL)
833 lstcon_rpc_put(*crpc);
839 LASSERT (transop == LST_TRANS_TSBCLIADD);
841 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
842 test->tes_cliidx++, test->tes_dist,
843 test->tes_span, n, &bulk->bk_iovs[0]);
845 lstcon_rpc_put(*crpc);
849 trq->tsr_ndest = test->tes_span;
850 trq->tsr_loop = test->tes_loop;
853 trq->tsr_sid = console_session.ses_id;
854 trq->tsr_bid = test->tes_hdr.tsb_id;
855 trq->tsr_concur = test->tes_concur;
856 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
857 trq->tsr_stop_onerr = test->tes_stop_onerr;
859 switch (test->tes_type) {
861 trq->tsr_service = SRPC_SERVICE_PING;
862 rc = lstcon_pingrpc_prep((lst_test_ping_param_t *)&test->tes_param[0], trq);
865 trq->tsr_service = SRPC_SERVICE_BRW;
866 rc = lstcon_bulkrpc_prep((lst_test_bulk_param_t *)&test->tes_param[0], trq);
877 lstcon_rpc_stat_reply(int transop, srpc_msg_t *msg,
878 lstcon_node_t *nd, lstcon_trans_stat_t *stat)
880 srpc_mksn_reply_t *mksn_rep;
881 srpc_rmsn_reply_t *rmsn_rep;
882 srpc_debug_reply_t *dbg_rep;
883 srpc_batch_reply_t *bat_rep;
884 srpc_test_reply_t *test_rep;
885 srpc_stat_reply_t *stat_rep;
889 case LST_TRANS_SESNEW:
890 mksn_rep = &msg->msg_body.mksn_reply;
892 if (mksn_rep->mksn_status == 0) {
893 lstcon_sesop_stat_success(stat, 1);
894 /* session timeout on remote node */
895 nd->nd_timeout = mksn_rep->mksn_timeout;
899 LASSERT (mksn_rep->mksn_status == EBUSY ||
900 mksn_rep->mksn_status == EINVAL);
902 lstcon_sesop_stat_failure(stat, 1);
903 errno = mksn_rep->mksn_status;
906 case LST_TRANS_SESEND:
907 rmsn_rep = &msg->msg_body.rmsn_reply;
908 /* ESRCH is not an error for end session */
909 if (rmsn_rep->rmsn_status == 0 ||
910 rmsn_rep->rmsn_status == ESRCH) {
911 lstcon_sesop_stat_success(stat, 1);
915 LASSERT (rmsn_rep->rmsn_status == EBUSY ||
916 rmsn_rep->rmsn_status == EINVAL);
918 lstcon_sesop_stat_failure(stat, 1);
919 errno = rmsn_rep->rmsn_status;
922 case LST_TRANS_SESQRY:
923 case LST_TRANS_SESPING:
924 dbg_rep = &msg->msg_body.dbg_reply;
926 if (dbg_rep->dbg_status == ESRCH) {
927 lstcon_sesqry_stat_unknown(stat, 1);
931 LASSERT (dbg_rep->dbg_status == 0);
933 if (lstcon_session_match(dbg_rep->dbg_sid))
934 lstcon_sesqry_stat_active(stat, 1);
936 lstcon_sesqry_stat_busy(stat, 1);
939 case LST_TRANS_TSBRUN:
940 case LST_TRANS_TSBSTOP:
941 bat_rep = &msg->msg_body.bat_reply;
943 if (bat_rep->bar_status == 0) {
944 lstcon_tsbop_stat_success(stat, 1);
948 if (bat_rep->bar_status == EPERM &&
949 transop == LST_TRANS_TSBSTOP) {
950 lstcon_tsbop_stat_success(stat, 1);
954 lstcon_tsbop_stat_failure(stat, 1);
955 errno = bat_rep->bar_status;
958 case LST_TRANS_TSBCLIQRY:
959 case LST_TRANS_TSBSRVQRY:
960 bat_rep = &msg->msg_body.bat_reply;
962 if (bat_rep->bar_active != 0)
963 lstcon_tsbqry_stat_run(stat, 1);
965 lstcon_tsbqry_stat_idle(stat, 1);
967 if (bat_rep->bar_status == 0)
970 lstcon_tsbqry_stat_failure(stat, 1);
971 errno = bat_rep->bar_status;
974 case LST_TRANS_TSBCLIADD:
975 case LST_TRANS_TSBSRVADD:
976 test_rep = &msg->msg_body.tes_reply;
978 if (test_rep->tsr_status == 0) {
979 lstcon_tsbop_stat_success(stat, 1);
983 lstcon_tsbop_stat_failure(stat, 1);
984 errno = test_rep->tsr_status;
987 case LST_TRANS_STATQRY:
988 stat_rep = &msg->msg_body.stat_reply;
990 if (stat_rep->str_status == 0) {
991 lstcon_statqry_stat_success(stat, 1);
995 lstcon_statqry_stat_failure(stat, 1);
996 errno = stat_rep->str_status;
1003 if (stat->trs_fwk_errno == 0)
1004 stat->trs_fwk_errno = errno;
1010 lstcon_rpc_trans_ndlist(struct list_head *ndlist,
1011 struct list_head *translist, int transop,
1012 void *arg, lstcon_rpc_cond_func_t condition,
1013 lstcon_rpc_trans_t **transpp)
1015 lstcon_rpc_trans_t *trans;
1016 lstcon_ndlink_t *ndl;
1021 /* Creating session RPG for list of nodes */
1023 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1025 CERROR("Can't create transaction %d: %d\n", transop, rc);
1029 list_for_each_entry(ndl, ndlist, ndl_link) {
1030 rc = condition == NULL ? 1 :
1031 condition(transop, ndl->ndl_node, arg);
1037 CDEBUG(D_NET, "Condition error while creating RPC "
1038 " for transaction %d: %d\n", transop, rc);
1045 case LST_TRANS_SESNEW:
1046 case LST_TRANS_SESEND:
1047 rc = lstcon_sesrpc_prep(nd, transop, &rpc);
1049 case LST_TRANS_SESQRY:
1050 case LST_TRANS_SESPING:
1051 rc = lstcon_dbgrpc_prep(nd, &rpc);
1053 case LST_TRANS_TSBCLIADD:
1054 case LST_TRANS_TSBSRVADD:
1055 rc = lstcon_testrpc_prep(nd, transop,
1056 (lstcon_test_t *)arg, &rpc);
1058 case LST_TRANS_TSBRUN:
1059 case LST_TRANS_TSBSTOP:
1060 case LST_TRANS_TSBCLIQRY:
1061 case LST_TRANS_TSBSRVQRY:
1062 rc = lstcon_batrpc_prep(nd, transop,
1063 (lstcon_tsb_hdr_t *)arg, &rpc);
1065 case LST_TRANS_STATQRY:
1066 rc = lstcon_statrpc_prep(nd, &rpc);
1074 CERROR("Failed to create RPC for transaction %s: %d\n",
1075 lstcon_rpc_trans_name(transop), rc);
1079 lstcon_rpc_trans_addreq(trans, rpc);
1087 lstcon_rpc_trans_destroy(trans);
1093 lstcon_rpc_pinger(void *arg)
1095 stt_timer_t *ptimer = (stt_timer_t *)arg;
1096 lstcon_rpc_trans_t *trans;
1099 srpc_debug_reqst_t *drq;
1100 lstcon_ndlink_t *ndl;
1106 /* RPC pinger is a special case of transaction,
1107 * it's called by timer at 8 seconds interval.
1109 mutex_down(&console_session.ses_mutex);
1111 if (console_session.ses_shutdown || console_session.ses_expired) {
1112 mutex_up(&console_session.ses_mutex);
1116 if (!console_session.ses_expired &&
1117 cfs_time_current_sec() - console_session.ses_laststamp >
1118 console_session.ses_timeout)
1119 console_session.ses_expired = 1;
1121 trans = console_session.ses_ping;
1123 LASSERT (trans != NULL);
1125 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link) {
1128 if (console_session.ses_expired) {
1129 /* idle console, end session on all nodes */
1130 if (nd->nd_state != LST_NODE_ACTIVE)
1133 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND, &crpc);
1135 CERROR("Out of memory\n");
1139 lstcon_rpc_trans_addreq(trans, crpc);
1140 lstcon_rpc_post(crpc);
1145 crpc = &nd->nd_ping;
1147 if (crpc->crp_rpc != NULL) {
1148 LASSERT (crpc->crp_trans == trans);
1149 LASSERT (!list_empty(&crpc->crp_link));
1151 spin_lock(&crpc->crp_rpc->crpc_lock);
1153 LASSERT (crpc->crp_posted);
1155 if (!crpc->crp_finished) {
1157 spin_unlock(&crpc->crp_rpc->crpc_lock);
1161 spin_unlock(&crpc->crp_rpc->crpc_lock);
1163 lstcon_rpc_get_reply(crpc, &rep);
1165 list_del_init(&crpc->crp_link);
1167 lstcon_rpc_put(crpc);
1170 if (nd->nd_state != LST_NODE_ACTIVE)
1173 intv = cfs_duration_sec(cfs_time_sub(cfs_time_current(),
1175 if (intv < nd->nd_timeout / 2)
1178 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG, 0, 0, crpc);
1180 CERROR("Out of memory\n");
1184 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1186 drq->dbg_sid = console_session.ses_id;
1189 lstcon_rpc_trans_addreq(trans, crpc);
1190 lstcon_rpc_post(crpc);
1195 if (console_session.ses_expired) {
1196 mutex_up(&console_session.ses_mutex);
1200 CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1202 ptimer->stt_expires = cfs_time_current_sec() + LST_PING_INTERVAL;
1203 stt_add_timer(ptimer);
1205 mutex_up(&console_session.ses_mutex);
1209 lstcon_rpc_pinger_start(void)
1211 stt_timer_t *ptimer;
1214 LASSERT (list_empty(&console_session.ses_rpc_freelist));
1215 LASSERT (atomic_read(&console_session.ses_rpc_counter) == 0);
1217 rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1218 &console_session.ses_ping);
1220 CERROR("Failed to create console pinger\n");
1224 ptimer = &console_session.ses_ping_timer;
1225 ptimer->stt_expires = cfs_time_current_sec() + LST_PING_INTERVAL;
1227 stt_add_timer(ptimer);
1233 lstcon_rpc_pinger_stop(void)
1235 LASSERT (console_session.ses_shutdown);
1237 stt_del_timer(&console_session.ses_ping_timer);
1239 lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1240 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1241 lstcon_rpc_trans_destroy(console_session.ses_ping);
1243 memset(lstcon_trans_stat(), 0, sizeof(lstcon_trans_stat_t));
1245 console_session.ses_ping = NULL;
1249 lstcon_rpc_cleanup_wait(void)
1251 lstcon_rpc_trans_t *trans;
1253 struct list_head *pacer;
1254 struct list_head zlist;
1256 /* Called with hold of global mutex */
1258 LASSERT (console_session.ses_shutdown);
1260 while (!list_empty(&console_session.ses_trans_list)) {
1261 list_for_each(pacer, &console_session.ses_trans_list) {
1262 trans = list_entry(pacer, lstcon_rpc_trans_t, tas_link);
1264 CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1265 lstcon_rpc_trans_name(trans->tas_opc));
1267 cfs_waitq_signal(&trans->tas_waitq);
1270 mutex_up(&console_session.ses_mutex);
1272 CWARN("Session is shutting down, "
1273 "waiting for termination of transactions\n");
1274 cfs_pause(cfs_time_seconds(1));
1276 mutex_down(&console_session.ses_mutex);
1279 spin_lock(&console_session.ses_rpc_lock);
1281 lst_wait_until((atomic_read(&console_session.ses_rpc_counter) == 0),
1282 console_session.ses_rpc_lock,
1283 "Network is not accessable or target is down, "
1284 "waiting for %d console RPCs to being recycled\n",
1285 atomic_read(&console_session.ses_rpc_counter));
1287 list_add(&zlist, &console_session.ses_rpc_freelist);
1288 list_del_init(&console_session.ses_rpc_freelist);
1290 spin_unlock(&console_session.ses_rpc_lock);
1292 while (!list_empty(&zlist)) {
1293 crpc = list_entry(zlist.next, lstcon_rpc_t, crp_link);
1295 list_del(&crpc->crp_link);
1296 LIBCFS_FREE(crpc, sizeof(lstcon_rpc_t));
1301 lstcon_rpc_module_init(void)
1303 CFS_INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1304 console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1305 console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1307 console_session.ses_ping = NULL;
1309 spin_lock_init(&console_session.ses_rpc_lock);
1310 atomic_set(&console_session.ses_rpc_counter, 0);
1311 CFS_INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1317 lstcon_rpc_module_fini(void)
1319 LASSERT (list_empty(&console_session.ses_rpc_freelist));
1320 LASSERT (atomic_read(&console_session.ses_rpc_counter) == 0);