4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, Whamcloud, Inc.
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 <liang@whamcloud.com>
45 #include <libcfs/libcfs.h>
46 #include <lnet/lib-lnet.h>
51 void lstcon_rpc_stat_reply(lstcon_rpc_trans_t *, 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, unsigned feats,
94 int bulk_npg, int bulk_len, int embedded, lstcon_rpc_t *crpc)
96 crpc->crp_rpc = sfw_create_rpc(nd->nd_id, service,
97 feats, bulk_npg, bulk_len,
98 lstcon_rpc_done, (void *)crpc);
99 if (crpc->crp_rpc == NULL)
102 crpc->crp_trans = NULL;
104 crpc->crp_posted = 0;
105 crpc->crp_finished = 0;
106 crpc->crp_unpacked = 0;
107 crpc->crp_status = 0;
109 crpc->crp_embedded = embedded;
110 CFS_INIT_LIST_HEAD(&crpc->crp_link);
112 cfs_atomic_inc(&console_session.ses_rpc_counter);
118 lstcon_rpc_prep(lstcon_node_t *nd, int service, unsigned feats,
119 int bulk_npg, int bulk_len, lstcon_rpc_t **crpcpp)
121 lstcon_rpc_t *crpc = NULL;
124 cfs_spin_lock(&console_session.ses_rpc_lock);
126 if (!cfs_list_empty(&console_session.ses_rpc_freelist)) {
127 crpc = cfs_list_entry(console_session.ses_rpc_freelist.next,
128 lstcon_rpc_t, crp_link);
129 cfs_list_del_init(&crpc->crp_link);
132 cfs_spin_unlock(&console_session.ses_rpc_lock);
135 LIBCFS_ALLOC(crpc, sizeof(*crpc));
140 rc = lstcon_rpc_init(nd, service, feats,
141 bulk_npg, bulk_len, 0, 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_embedded) {
170 /* embedded RPC, don't recycle it */
171 memset(crpc, 0, sizeof(*crpc));
172 crpc->crp_embedded = 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);
273 cfs_spin_lock(&console_session.ses_rpc_lock);
274 trans->tas_features = console_session.ses_features;
275 cfs_spin_unlock(&console_session.ses_rpc_lock);
282 lstcon_rpc_trans_addreq(lstcon_rpc_trans_t *trans, lstcon_rpc_t *crpc)
284 cfs_list_add_tail(&crpc->crp_link, &trans->tas_rpcs_list);
285 crpc->crp_trans = trans;
289 lstcon_rpc_trans_abort(lstcon_rpc_trans_t *trans, int error)
291 srpc_client_rpc_t *rpc;
295 cfs_list_for_each_entry_typed (crpc, &trans->tas_rpcs_list,
296 lstcon_rpc_t, crp_link) {
299 cfs_spin_lock(&rpc->crpc_lock);
301 if (!crpc->crp_posted || /* not posted */
302 crpc->crp_stamp != 0) { /* rpc done or aborted already */
303 if (crpc->crp_stamp == 0) {
304 crpc->crp_stamp = cfs_time_current();
305 crpc->crp_status = -EINTR;
307 cfs_spin_unlock(&rpc->crpc_lock);
311 crpc->crp_stamp = cfs_time_current();
312 crpc->crp_status = error;
314 cfs_spin_unlock(&rpc->crpc_lock);
318 if (error != ETIMEDOUT)
322 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
325 nd->nd_stamp = crpc->crp_stamp;
326 nd->nd_state = LST_NODE_DOWN;
331 lstcon_rpc_trans_check(lstcon_rpc_trans_t *trans)
333 if (console_session.ses_shutdown &&
334 !cfs_list_empty(&trans->tas_olink)) /* Not an end session RPC */
337 return (cfs_atomic_read(&trans->tas_remaining) == 0) ? 1: 0;
341 lstcon_rpc_trans_postwait(lstcon_rpc_trans_t *trans, int timeout)
346 if (cfs_list_empty(&trans->tas_rpcs_list))
349 if (timeout < LST_TRANS_MIN_TIMEOUT)
350 timeout = LST_TRANS_MIN_TIMEOUT;
352 CDEBUG(D_NET, "Transaction %s started\n",
353 lstcon_rpc_trans_name(trans->tas_opc));
355 /* post all requests */
356 cfs_list_for_each_entry_typed (crpc, &trans->tas_rpcs_list,
357 lstcon_rpc_t, crp_link) {
358 LASSERT (!crpc->crp_posted);
360 lstcon_rpc_post(crpc);
363 cfs_mutex_unlock(&console_session.ses_mutex);
365 cfs_waitq_wait_event_interruptible_timeout(trans->tas_waitq,
366 lstcon_rpc_trans_check(trans),
367 cfs_time_seconds(timeout), rc);
369 rc = (rc > 0)? 0: ((rc < 0)? -EINTR: -ETIMEDOUT);
371 cfs_mutex_lock(&console_session.ses_mutex);
373 if (console_session.ses_shutdown)
376 if (rc != 0 || atomic_read(&trans->tas_remaining) != 0) {
377 /* treat short timeout as canceled */
378 if (rc == -ETIMEDOUT && timeout < LST_TRANS_MIN_TIMEOUT * 2)
381 lstcon_rpc_trans_abort(trans, rc);
384 CDEBUG(D_NET, "Transaction %s stopped: %d\n",
385 lstcon_rpc_trans_name(trans->tas_opc), rc);
387 lstcon_rpc_trans_stat(trans, lstcon_trans_stat());
393 lstcon_rpc_get_reply(lstcon_rpc_t *crpc, srpc_msg_t **msgpp)
395 lstcon_node_t *nd = crpc->crp_node;
396 srpc_client_rpc_t *rpc = crpc->crp_rpc;
397 srpc_generic_reply_t *rep;
399 LASSERT (nd != NULL && rpc != NULL);
400 LASSERT (crpc->crp_stamp != 0);
402 if (crpc->crp_status != 0) {
404 return crpc->crp_status;
407 *msgpp = &rpc->crpc_replymsg;
408 if (!crpc->crp_unpacked) {
409 sfw_unpack_message(*msgpp);
410 crpc->crp_unpacked = 1;
413 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
416 nd->nd_stamp = crpc->crp_stamp;
417 rep = &(*msgpp)->msg_body.reply;
419 if (rep->sid.ses_nid == LNET_NID_ANY)
420 nd->nd_state = LST_NODE_UNKNOWN;
421 else if (lstcon_session_match(rep->sid))
422 nd->nd_state = LST_NODE_ACTIVE;
424 nd->nd_state = LST_NODE_BUSY;
430 lstcon_rpc_trans_stat(lstcon_rpc_trans_t *trans, lstcon_trans_stat_t *stat)
436 LASSERT (stat != NULL);
438 memset(stat, 0, sizeof(*stat));
440 cfs_list_for_each_entry_typed(crpc, &trans->tas_rpcs_list,
441 lstcon_rpc_t, crp_link) {
442 lstcon_rpc_stat_total(stat, 1);
444 LASSERT (crpc->crp_stamp != 0);
446 error = lstcon_rpc_get_reply(crpc, &rep);
448 lstcon_rpc_stat_failure(stat, 1);
449 if (stat->trs_rpc_errno == 0)
450 stat->trs_rpc_errno = -error;
455 lstcon_rpc_stat_success(stat, 1);
457 lstcon_rpc_stat_reply(trans, rep, crpc->crp_node, stat);
460 if (trans->tas_opc == LST_TRANS_SESNEW && stat->trs_fwk_errno == 0) {
461 stat->trs_fwk_errno =
462 lstcon_session_feats_check(trans->tas_features);
465 CDEBUG(D_NET, "transaction %s : success %d, failure %d, total %d, "
466 "RPC error(%d), Framework error(%d)\n",
467 lstcon_rpc_trans_name(trans->tas_opc),
468 lstcon_rpc_stat_success(stat, 0),
469 lstcon_rpc_stat_failure(stat, 0),
470 lstcon_rpc_stat_total(stat, 0),
471 stat->trs_rpc_errno, stat->trs_fwk_errno);
477 lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
479 lstcon_rpc_readent_func_t readent)
483 lstcon_rpc_ent_t *ent;
484 srpc_generic_reply_t *rep;
492 LASSERT (head_up != NULL);
496 cfs_list_for_each_entry_typed(crpc, &trans->tas_rpcs_list,
497 lstcon_rpc_t, crp_link) {
498 if (cfs_copy_from_user(&tmp, next,
502 if (tmp.next == head_up)
507 ent = cfs_list_entry(next, lstcon_rpc_ent_t, rpe_link);
509 LASSERT (crpc->crp_stamp != 0);
511 error = lstcon_rpc_get_reply(crpc, &msg);
515 dur = (cfs_duration_t)cfs_time_sub(crpc->crp_stamp,
516 (cfs_time_t)console_session.ses_id.ses_stamp);
517 cfs_duration_usec(dur, &tv);
519 if (cfs_copy_to_user(&ent->rpe_peer,
520 &nd->nd_id, sizeof(lnet_process_id_t)) ||
521 cfs_copy_to_user(&ent->rpe_stamp, &tv, sizeof(tv)) ||
522 cfs_copy_to_user(&ent->rpe_state,
523 &nd->nd_state, sizeof(nd->nd_state)) ||
524 cfs_copy_to_user(&ent->rpe_rpc_errno, &error,
532 rep = (srpc_generic_reply_t *)&msg->msg_body.reply;
534 if (cfs_copy_to_user(&ent->rpe_sid,
535 &rep->sid, sizeof(lst_sid_t)) ||
536 cfs_copy_to_user(&ent->rpe_fwk_errno,
537 &rep->status, sizeof(rep->status)))
543 if ((error = readent(trans->tas_opc, msg, ent)) != 0)
551 lstcon_rpc_trans_destroy(lstcon_rpc_trans_t *trans)
553 srpc_client_rpc_t *rpc;
558 cfs_list_for_each_entry_safe_typed(crpc, tmp,
559 &trans->tas_rpcs_list,
560 lstcon_rpc_t, crp_link) {
563 cfs_spin_lock(&rpc->crpc_lock);
565 /* free it if not posted or finished already */
566 if (!crpc->crp_posted || crpc->crp_finished) {
567 cfs_spin_unlock(&rpc->crpc_lock);
569 cfs_list_del_init(&crpc->crp_link);
570 lstcon_rpc_put(crpc);
575 /* rpcs can be still not callbacked (even LNetMDUnlink is called)
576 * because huge timeout for inaccessible network, don't make
577 * user wait for them, just abandon them, they will be recycled
580 LASSERT (crpc->crp_status != 0);
582 crpc->crp_node = NULL;
583 crpc->crp_trans = NULL;
584 cfs_list_del_init(&crpc->crp_link);
587 cfs_spin_unlock(&rpc->crpc_lock);
589 cfs_atomic_dec(&trans->tas_remaining);
592 LASSERT (cfs_atomic_read(&trans->tas_remaining) == 0);
594 cfs_list_del(&trans->tas_link);
595 if (!cfs_list_empty(&trans->tas_olink))
596 cfs_list_del(&trans->tas_olink);
598 CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
599 lstcon_rpc_trans_name(trans->tas_opc), count);
601 LIBCFS_FREE(trans, sizeof(*trans));
607 lstcon_sesrpc_prep(lstcon_node_t *nd, int transop,
608 unsigned feats, lstcon_rpc_t **crpc)
610 srpc_mksn_reqst_t *msrq;
611 srpc_rmsn_reqst_t *rsrq;
615 case LST_TRANS_SESNEW:
616 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION,
621 msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
622 msrq->mksn_sid = console_session.ses_id;
623 msrq->mksn_force = console_session.ses_force;
624 strncpy(msrq->mksn_name, console_session.ses_name,
625 strlen(console_session.ses_name));
628 case LST_TRANS_SESEND:
629 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION,
634 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
635 rsrq->rmsn_sid = console_session.ses_id;
646 lstcon_dbgrpc_prep(lstcon_node_t *nd, unsigned feats, lstcon_rpc_t **crpc)
648 srpc_debug_reqst_t *drq;
651 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, feats, 0, 0, crpc);
655 drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
657 drq->dbg_sid = console_session.ses_id;
664 lstcon_batrpc_prep(lstcon_node_t *nd, int transop, unsigned feats,
665 lstcon_tsb_hdr_t *tsb, lstcon_rpc_t **crpc)
667 lstcon_batch_t *batch;
668 srpc_batch_reqst_t *brq;
671 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, feats, 0, 0, crpc);
675 brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
677 brq->bar_sid = console_session.ses_id;
678 brq->bar_bid = tsb->tsb_id;
679 brq->bar_testidx = tsb->tsb_index;
680 brq->bar_opc = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
681 (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP:
682 SRPC_BATCH_OPC_QUERY);
684 if (transop != LST_TRANS_TSBRUN &&
685 transop != LST_TRANS_TSBSTOP)
688 LASSERT (tsb->tsb_index == 0);
690 batch = (lstcon_batch_t *)tsb;
691 brq->bar_arg = batch->bat_arg;
697 lstcon_statrpc_prep(lstcon_node_t *nd, unsigned feats, lstcon_rpc_t **crpc)
699 srpc_stat_reqst_t *srq;
702 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_QUERY_STAT, feats, 0, 0, crpc);
706 srq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.stat_reqst;
708 srq->str_sid = console_session.ses_id;
709 srq->str_type = 0; /* XXX remove it */
714 lnet_process_id_packed_t *
715 lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov)
717 lnet_process_id_packed_t *pid;
720 i = idx / SFW_ID_PER_PAGE;
724 pid = (lnet_process_id_packed_t *)cfs_page_address(kiov[i].kiov_page);
726 return &pid[idx % SFW_ID_PER_PAGE];
730 lstcon_dstnodes_prep(lstcon_group_t *grp, int idx,
731 int dist, int span, int nkiov, lnet_kiov_t *kiov)
733 lnet_process_id_packed_t *pid;
734 lstcon_ndlink_t *ndl;
742 LASSERT (grp->grp_nnode >= 1);
744 if (span > grp->grp_nnode)
747 start = ((idx / dist) * span) % grp->grp_nnode;
748 end = ((idx / dist) * span + span - 1) % grp->grp_nnode;
750 cfs_list_for_each_entry_typed(ndl, &grp->grp_ndl_list,
751 lstcon_ndlink_t, ndl_link) {
758 if (i > (end >= start ? end: grp->grp_nnode))
761 pid = lstcon_next_id((i - start), nkiov, kiov);
762 pid->nid = nd->nd_id.nid;
763 pid->pid = nd->nd_id.pid;
767 if (start <= end) /* done */
770 cfs_list_for_each_entry_typed(ndl, &grp->grp_ndl_list,
771 lstcon_ndlink_t, ndl_link) {
772 if (i > grp->grp_nnode + end)
776 pid = lstcon_next_id((i - start), nkiov, kiov);
777 pid->nid = nd->nd_id.nid;
778 pid->pid = nd->nd_id.pid;
786 lstcon_pingrpc_prep(lst_test_ping_param_t *param, srpc_test_reqst_t *req)
788 test_ping_req_t *prq = &req->tsr_u.ping;
790 prq->png_size = param->png_size;
791 prq->png_flags = param->png_flags;
797 lstcon_bulkrpc_v0_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
799 test_bulk_req_t *brq = &req->tsr_u.bulk_v0;
801 brq->blk_opc = param->blk_opc;
802 brq->blk_npg = (param->blk_size + CFS_PAGE_SIZE - 1) / CFS_PAGE_SIZE;
803 brq->blk_flags = param->blk_flags;
809 lstcon_bulkrpc_v1_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
811 test_bulk_req_v1_t *brq = &req->tsr_u.bulk_v1;
813 brq->blk_opc = param->blk_opc;
814 brq->blk_flags = param->blk_flags;
815 brq->blk_len = param->blk_size;
816 brq->blk_offset = 0; /* reserved */
822 lstcon_testrpc_prep(lstcon_node_t *nd, int transop, unsigned feats,
823 lstcon_test_t *test, lstcon_rpc_t **crpc)
825 lstcon_group_t *sgrp = test->tes_src_grp;
826 lstcon_group_t *dgrp = test->tes_dst_grp;
827 srpc_test_reqst_t *trq;
834 if (transop == LST_TRANS_TSBCLIADD) {
835 npg = sfw_id_pages(test->tes_span);
836 nob = (feats & LST_FEAT_BULK_LEN) == 0 ?
837 npg * CFS_PAGE_SIZE :
838 sizeof(lnet_process_id_packed_t) * test->tes_span;
841 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc);
845 trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
847 if (transop == LST_TRANS_TSBSRVADD) {
848 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
849 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
850 int nmax = (ndist + nspan - 1) / nspan;
853 trq->tsr_loop = nmax * test->tes_dist * test->tes_concur;
856 bulk = &(*crpc)->crp_rpc->crpc_bulk;
858 for (i = 0; i < npg; i++) {
863 len = (feats & LST_FEAT_BULK_LEN) == 0 ?
864 CFS_PAGE_SIZE : min_t(int, nob, CFS_PAGE_SIZE);
867 bulk->bk_iovs[i].kiov_offset = 0;
868 bulk->bk_iovs[i].kiov_len = len;
869 bulk->bk_iovs[i].kiov_page =
870 cfs_alloc_page(CFS_ALLOC_STD);
872 if (bulk->bk_iovs[i].kiov_page == NULL) {
873 lstcon_rpc_put(*crpc);
880 LASSERT (transop == LST_TRANS_TSBCLIADD);
882 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
886 npg, &bulk->bk_iovs[0]);
888 lstcon_rpc_put(*crpc);
892 trq->tsr_ndest = test->tes_span;
893 trq->tsr_loop = test->tes_loop;
896 trq->tsr_sid = console_session.ses_id;
897 trq->tsr_bid = test->tes_hdr.tsb_id;
898 trq->tsr_concur = test->tes_concur;
899 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
900 trq->tsr_stop_onerr = !!test->tes_stop_onerr;
902 switch (test->tes_type) {
904 trq->tsr_service = SRPC_SERVICE_PING;
905 rc = lstcon_pingrpc_prep((lst_test_ping_param_t *)
906 &test->tes_param[0], trq);
910 trq->tsr_service = SRPC_SERVICE_BRW;
911 if ((feats & LST_FEAT_BULK_LEN) == 0) {
912 rc = lstcon_bulkrpc_v0_prep((lst_test_bulk_param_t *)
913 &test->tes_param[0], trq);
915 rc = lstcon_bulkrpc_v1_prep((lst_test_bulk_param_t *)
916 &test->tes_param[0], trq);
929 lstcon_sesnew_stat_reply(lstcon_rpc_trans_t *trans,
930 lstcon_node_t *nd, srpc_msg_t *reply)
932 srpc_mksn_reply_t *mksn_rep = &reply->msg_body.mksn_reply;
933 int status = mksn_rep->mksn_status;
936 (reply->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
937 mksn_rep->mksn_status = EPROTO;
941 if (status == EPROTO) {
942 CNETERR("session protocol error from %s: %u\n",
943 libcfs_nid2str(nd->nd_id.nid),
944 reply->msg_ses_feats);
950 if (!trans->tas_feats_updated) {
951 trans->tas_feats_updated = 1;
952 trans->tas_features = reply->msg_ses_feats;
955 if (reply->msg_ses_feats != trans->tas_features) {
956 CNETERR("Framework features %x from %s is different with "
957 "features on this transaction: %x\n",
958 reply->msg_ses_feats, libcfs_nid2str(nd->nd_id.nid),
959 trans->tas_features);
960 status = mksn_rep->mksn_status = EPROTO;
964 /* session timeout on remote node */
965 nd->nd_timeout = mksn_rep->mksn_timeout;
972 lstcon_rpc_stat_reply(lstcon_rpc_trans_t *trans, srpc_msg_t *msg,
973 lstcon_node_t *nd, lstcon_trans_stat_t *stat)
975 srpc_rmsn_reply_t *rmsn_rep;
976 srpc_debug_reply_t *dbg_rep;
977 srpc_batch_reply_t *bat_rep;
978 srpc_test_reply_t *test_rep;
979 srpc_stat_reply_t *stat_rep;
982 switch (trans->tas_opc) {
983 case LST_TRANS_SESNEW:
984 rc = lstcon_sesnew_stat_reply(trans, nd, msg);
986 lstcon_sesop_stat_success(stat, 1);
990 lstcon_sesop_stat_failure(stat, 1);
993 case LST_TRANS_SESEND:
994 rmsn_rep = &msg->msg_body.rmsn_reply;
995 /* ESRCH is not an error for end session */
996 if (rmsn_rep->rmsn_status == 0 ||
997 rmsn_rep->rmsn_status == ESRCH) {
998 lstcon_sesop_stat_success(stat, 1);
1002 lstcon_sesop_stat_failure(stat, 1);
1003 rc = rmsn_rep->rmsn_status;
1006 case LST_TRANS_SESQRY:
1007 case LST_TRANS_SESPING:
1008 dbg_rep = &msg->msg_body.dbg_reply;
1010 if (dbg_rep->dbg_status == ESRCH) {
1011 lstcon_sesqry_stat_unknown(stat, 1);
1015 if (lstcon_session_match(dbg_rep->dbg_sid))
1016 lstcon_sesqry_stat_active(stat, 1);
1018 lstcon_sesqry_stat_busy(stat, 1);
1021 case LST_TRANS_TSBRUN:
1022 case LST_TRANS_TSBSTOP:
1023 bat_rep = &msg->msg_body.bat_reply;
1025 if (bat_rep->bar_status == 0) {
1026 lstcon_tsbop_stat_success(stat, 1);
1030 if (bat_rep->bar_status == EPERM &&
1031 trans->tas_opc == LST_TRANS_TSBSTOP) {
1032 lstcon_tsbop_stat_success(stat, 1);
1036 lstcon_tsbop_stat_failure(stat, 1);
1037 rc = bat_rep->bar_status;
1040 case LST_TRANS_TSBCLIQRY:
1041 case LST_TRANS_TSBSRVQRY:
1042 bat_rep = &msg->msg_body.bat_reply;
1044 if (bat_rep->bar_active != 0)
1045 lstcon_tsbqry_stat_run(stat, 1);
1047 lstcon_tsbqry_stat_idle(stat, 1);
1049 if (bat_rep->bar_status == 0)
1052 lstcon_tsbqry_stat_failure(stat, 1);
1053 rc = bat_rep->bar_status;
1056 case LST_TRANS_TSBCLIADD:
1057 case LST_TRANS_TSBSRVADD:
1058 test_rep = &msg->msg_body.tes_reply;
1060 if (test_rep->tsr_status == 0) {
1061 lstcon_tsbop_stat_success(stat, 1);
1065 lstcon_tsbop_stat_failure(stat, 1);
1066 rc = test_rep->tsr_status;
1069 case LST_TRANS_STATQRY:
1070 stat_rep = &msg->msg_body.stat_reply;
1072 if (stat_rep->str_status == 0) {
1073 lstcon_statqry_stat_success(stat, 1);
1077 lstcon_statqry_stat_failure(stat, 1);
1078 rc = stat_rep->str_status;
1085 if (stat->trs_fwk_errno == 0)
1086 stat->trs_fwk_errno = rc;
1092 lstcon_rpc_trans_ndlist(cfs_list_t *ndlist,
1093 cfs_list_t *translist, int transop,
1094 void *arg, lstcon_rpc_cond_func_t condition,
1095 lstcon_rpc_trans_t **transpp)
1097 lstcon_rpc_trans_t *trans;
1098 lstcon_ndlink_t *ndl;
1104 /* Creating session RPG for list of nodes */
1106 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1108 CERROR("Can't create transaction %d: %d\n", transop, rc);
1112 feats = trans->tas_features;
1113 cfs_list_for_each_entry_typed(ndl, ndlist, lstcon_ndlink_t, ndl_link) {
1114 rc = condition == NULL ? 1 :
1115 condition(transop, ndl->ndl_node, arg);
1121 CDEBUG(D_NET, "Condition error while creating RPC "
1122 " for transaction %d: %d\n", transop, rc);
1129 case LST_TRANS_SESNEW:
1130 case LST_TRANS_SESEND:
1131 rc = lstcon_sesrpc_prep(nd, transop, feats, &rpc);
1133 case LST_TRANS_SESQRY:
1134 case LST_TRANS_SESPING:
1135 rc = lstcon_dbgrpc_prep(nd, feats, &rpc);
1137 case LST_TRANS_TSBCLIADD:
1138 case LST_TRANS_TSBSRVADD:
1139 rc = lstcon_testrpc_prep(nd, transop, feats,
1140 (lstcon_test_t *)arg, &rpc);
1142 case LST_TRANS_TSBRUN:
1143 case LST_TRANS_TSBSTOP:
1144 case LST_TRANS_TSBCLIQRY:
1145 case LST_TRANS_TSBSRVQRY:
1146 rc = lstcon_batrpc_prep(nd, transop, feats,
1147 (lstcon_tsb_hdr_t *)arg, &rpc);
1149 case LST_TRANS_STATQRY:
1150 rc = lstcon_statrpc_prep(nd, feats, &rpc);
1158 CERROR("Failed to create RPC for transaction %s: %d\n",
1159 lstcon_rpc_trans_name(transop), rc);
1163 lstcon_rpc_trans_addreq(trans, rpc);
1171 lstcon_rpc_trans_destroy(trans);
1177 lstcon_rpc_pinger(void *arg)
1179 stt_timer_t *ptimer = (stt_timer_t *)arg;
1180 lstcon_rpc_trans_t *trans;
1183 srpc_debug_reqst_t *drq;
1184 lstcon_ndlink_t *ndl;
1190 /* RPC pinger is a special case of transaction,
1191 * it's called by timer at 8 seconds interval.
1193 cfs_mutex_lock(&console_session.ses_mutex);
1195 if (console_session.ses_shutdown || console_session.ses_expired) {
1196 cfs_mutex_unlock(&console_session.ses_mutex);
1200 if (!console_session.ses_expired &&
1201 cfs_time_current_sec() - console_session.ses_laststamp >
1202 (time_t)console_session.ses_timeout)
1203 console_session.ses_expired = 1;
1205 trans = console_session.ses_ping;
1207 LASSERT (trans != NULL);
1209 cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_list,
1210 lstcon_ndlink_t, ndl_link) {
1213 if (console_session.ses_expired) {
1214 /* idle console, end session on all nodes */
1215 if (nd->nd_state != LST_NODE_ACTIVE)
1218 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND,
1219 trans->tas_features, &crpc);
1221 CERROR("Out of memory\n");
1225 lstcon_rpc_trans_addreq(trans, crpc);
1226 lstcon_rpc_post(crpc);
1231 crpc = &nd->nd_ping;
1233 if (crpc->crp_rpc != NULL) {
1234 LASSERT (crpc->crp_trans == trans);
1235 LASSERT (!cfs_list_empty(&crpc->crp_link));
1237 cfs_spin_lock(&crpc->crp_rpc->crpc_lock);
1239 LASSERT (crpc->crp_posted);
1241 if (!crpc->crp_finished) {
1243 cfs_spin_unlock(&crpc->crp_rpc->crpc_lock);
1247 cfs_spin_unlock(&crpc->crp_rpc->crpc_lock);
1249 lstcon_rpc_get_reply(crpc, &rep);
1251 cfs_list_del_init(&crpc->crp_link);
1253 lstcon_rpc_put(crpc);
1256 if (nd->nd_state != LST_NODE_ACTIVE)
1259 intv = cfs_duration_sec(cfs_time_sub(cfs_time_current(),
1261 if (intv < (time_t)nd->nd_timeout / 2)
1264 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
1265 trans->tas_features, 0, 0, 1, crpc);
1267 CERROR("Out of memory\n");
1271 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1273 drq->dbg_sid = console_session.ses_id;
1276 lstcon_rpc_trans_addreq(trans, crpc);
1277 lstcon_rpc_post(crpc);
1282 if (console_session.ses_expired) {
1283 cfs_mutex_unlock(&console_session.ses_mutex);
1287 CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1289 ptimer->stt_expires = (cfs_time_t)(cfs_time_current_sec() + LST_PING_INTERVAL);
1290 stt_add_timer(ptimer);
1292 cfs_mutex_unlock(&console_session.ses_mutex);
1296 lstcon_rpc_pinger_start(void)
1298 stt_timer_t *ptimer;
1301 LASSERT (cfs_list_empty(&console_session.ses_rpc_freelist));
1302 LASSERT (cfs_atomic_read(&console_session.ses_rpc_counter) == 0);
1304 rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1305 &console_session.ses_ping);
1307 CERROR("Failed to create console pinger\n");
1311 ptimer = &console_session.ses_ping_timer;
1312 ptimer->stt_expires = (cfs_time_t)(cfs_time_current_sec() + LST_PING_INTERVAL);
1314 stt_add_timer(ptimer);
1320 lstcon_rpc_pinger_stop(void)
1322 LASSERT (console_session.ses_shutdown);
1324 stt_del_timer(&console_session.ses_ping_timer);
1326 lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1327 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1328 lstcon_rpc_trans_destroy(console_session.ses_ping);
1330 memset(lstcon_trans_stat(), 0, sizeof(lstcon_trans_stat_t));
1332 console_session.ses_ping = NULL;
1336 lstcon_rpc_cleanup_wait(void)
1338 lstcon_rpc_trans_t *trans;
1343 /* Called with hold of global mutex */
1345 LASSERT (console_session.ses_shutdown);
1347 while (!cfs_list_empty(&console_session.ses_trans_list)) {
1348 cfs_list_for_each(pacer, &console_session.ses_trans_list) {
1349 trans = cfs_list_entry(pacer, lstcon_rpc_trans_t,
1352 CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1353 lstcon_rpc_trans_name(trans->tas_opc));
1355 cfs_waitq_signal(&trans->tas_waitq);
1358 cfs_mutex_unlock(&console_session.ses_mutex);
1360 CWARN("Session is shutting down, "
1361 "waiting for termination of transactions\n");
1362 cfs_pause(cfs_time_seconds(1));
1364 cfs_mutex_lock(&console_session.ses_mutex);
1367 cfs_spin_lock(&console_session.ses_rpc_lock);
1369 lst_wait_until((cfs_atomic_read(&console_session.ses_rpc_counter) == 0),
1370 console_session.ses_rpc_lock,
1371 "Network is not accessable or target is down, "
1372 "waiting for %d console RPCs to being recycled\n",
1373 cfs_atomic_read(&console_session.ses_rpc_counter));
1375 cfs_list_add(&zlist, &console_session.ses_rpc_freelist);
1376 cfs_list_del_init(&console_session.ses_rpc_freelist);
1378 cfs_spin_unlock(&console_session.ses_rpc_lock);
1380 while (!cfs_list_empty(&zlist)) {
1381 crpc = cfs_list_entry(zlist.next, lstcon_rpc_t, crp_link);
1383 cfs_list_del(&crpc->crp_link);
1384 LIBCFS_FREE(crpc, sizeof(lstcon_rpc_t));
1389 lstcon_rpc_module_init(void)
1391 CFS_INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1392 console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1393 console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1395 console_session.ses_ping = NULL;
1397 cfs_spin_lock_init(&console_session.ses_rpc_lock);
1398 cfs_atomic_set(&console_session.ses_rpc_counter, 0);
1399 CFS_INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1405 lstcon_rpc_module_fini(void)
1407 LASSERT (cfs_list_empty(&console_session.ses_rpc_freelist));
1408 LASSERT (cfs_atomic_read(&console_session.ses_rpc_counter) == 0);