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, 2012, Intel Corporation.
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 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 (cfs_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, 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 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 spin_unlock(&console_session.ses_rpc_lock);
135 LIBCFS_ALLOC(crpc, sizeof(*crpc));
140 rc = lstcon_rpc_init(nd, service, feats, bulk_npg, bulk_len, 0, crpc);
146 LIBCFS_FREE(crpc, sizeof(*crpc));
152 lstcon_rpc_put(lstcon_rpc_t *crpc)
154 srpc_bulk_t *bulk = &crpc->crp_rpc->crpc_bulk;
157 LASSERT (cfs_list_empty(&crpc->crp_link));
159 for (i = 0; i < bulk->bk_niov; i++) {
160 if (bulk->bk_iovs[i].kiov_page == NULL)
163 __free_page(bulk->bk_iovs[i].kiov_page);
166 srpc_client_rpc_decref(crpc->crp_rpc);
168 if (crpc->crp_embedded) {
169 /* embedded RPC, don't recycle it */
170 memset(crpc, 0, sizeof(*crpc));
171 crpc->crp_embedded = 1;
174 spin_lock(&console_session.ses_rpc_lock);
176 cfs_list_add(&crpc->crp_link,
177 &console_session.ses_rpc_freelist);
179 spin_unlock(&console_session.ses_rpc_lock);
182 /* RPC is not alive now */
183 cfs_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 cfs_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(cfs_list_t *translist,
240 int transop, lstcon_rpc_trans_t **transpp)
242 lstcon_rpc_trans_t *trans;
244 if (translist != NULL) {
245 cfs_list_for_each_entry_typed(trans, translist,
246 lstcon_rpc_trans_t, tas_link) {
247 /* Can't enqueue two private transaction on
249 if ((trans->tas_opc & transop) == LST_TRANS_PRIVATE)
254 /* create a trans group */
255 LIBCFS_ALLOC(trans, sizeof(*trans));
259 trans->tas_opc = transop;
261 if (translist == NULL)
262 CFS_INIT_LIST_HEAD(&trans->tas_olink);
264 cfs_list_add_tail(&trans->tas_olink, translist);
266 cfs_list_add_tail(&trans->tas_link, &console_session.ses_trans_list);
268 CFS_INIT_LIST_HEAD(&trans->tas_rpcs_list);
269 cfs_atomic_set(&trans->tas_remaining, 0);
270 cfs_waitq_init(&trans->tas_waitq);
272 spin_lock(&console_session.ses_rpc_lock);
273 trans->tas_features = console_session.ses_features;
274 spin_unlock(&console_session.ses_rpc_lock);
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 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 spin_unlock(&rpc->crpc_lock);
310 crpc->crp_stamp = cfs_time_current();
311 crpc->crp_status = error;
313 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 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 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, rep, crpc->crp_node, stat);
459 if (trans->tas_opc == LST_TRANS_SESNEW && stat->trs_fwk_errno == 0) {
460 stat->trs_fwk_errno =
461 lstcon_session_feats_check(trans->tas_features);
464 CDEBUG(D_NET, "transaction %s : success %d, failure %d, total %d, "
465 "RPC error(%d), Framework error(%d)\n",
466 lstcon_rpc_trans_name(trans->tas_opc),
467 lstcon_rpc_stat_success(stat, 0),
468 lstcon_rpc_stat_failure(stat, 0),
469 lstcon_rpc_stat_total(stat, 0),
470 stat->trs_rpc_errno, stat->trs_fwk_errno);
476 lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
478 lstcon_rpc_readent_func_t readent)
482 lstcon_rpc_ent_t *ent;
483 srpc_generic_reply_t *rep;
491 LASSERT (head_up != NULL);
495 cfs_list_for_each_entry_typed(crpc, &trans->tas_rpcs_list,
496 lstcon_rpc_t, crp_link) {
497 if (copy_from_user(&tmp, next,
501 if (tmp.next == head_up)
506 ent = cfs_list_entry(next, lstcon_rpc_ent_t, rpe_link);
508 LASSERT (crpc->crp_stamp != 0);
510 error = lstcon_rpc_get_reply(crpc, &msg);
514 dur = (cfs_duration_t)cfs_time_sub(crpc->crp_stamp,
515 (cfs_time_t)console_session.ses_id.ses_stamp);
516 cfs_duration_usec(dur, &tv);
518 if (copy_to_user(&ent->rpe_peer,
519 &nd->nd_id, sizeof(lnet_process_id_t)) ||
520 copy_to_user(&ent->rpe_stamp, &tv, sizeof(tv)) ||
521 copy_to_user(&ent->rpe_state,
522 &nd->nd_state, sizeof(nd->nd_state)) ||
523 copy_to_user(&ent->rpe_rpc_errno, &error,
531 rep = (srpc_generic_reply_t *)&msg->msg_body.reply;
533 if (copy_to_user(&ent->rpe_sid,
534 &rep->sid, sizeof(lst_sid_t)) ||
535 copy_to_user(&ent->rpe_fwk_errno,
536 &rep->status, sizeof(rep->status)))
542 error = readent(trans->tas_opc, msg, ent);
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 spin_lock(&rpc->crpc_lock);
565 /* free it if not posted or finished already */
566 if (!crpc->crp_posted || crpc->crp_finished) {
567 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 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 *)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 + PAGE_CACHE_SIZE - 1) /
804 brq->blk_flags = param->blk_flags;
810 lstcon_bulkrpc_v1_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
812 test_bulk_req_v1_t *brq = &req->tsr_u.bulk_v1;
814 brq->blk_opc = param->blk_opc;
815 brq->blk_flags = param->blk_flags;
816 brq->blk_len = param->blk_size;
817 brq->blk_offset = 0; /* reserved */
823 lstcon_testrpc_prep(lstcon_node_t *nd, int transop, unsigned feats,
824 lstcon_test_t *test, lstcon_rpc_t **crpc)
826 lstcon_group_t *sgrp = test->tes_src_grp;
827 lstcon_group_t *dgrp = test->tes_dst_grp;
828 srpc_test_reqst_t *trq;
835 if (transop == LST_TRANS_TSBCLIADD) {
836 npg = sfw_id_pages(test->tes_span);
837 nob = (feats & LST_FEAT_BULK_LEN) == 0 ?
838 npg * PAGE_CACHE_SIZE :
839 sizeof(lnet_process_id_packed_t) * test->tes_span;
842 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc);
846 trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
848 if (transop == LST_TRANS_TSBSRVADD) {
849 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
850 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
851 int nmax = (ndist + nspan - 1) / nspan;
854 trq->tsr_loop = nmax * test->tes_dist * test->tes_concur;
857 bulk = &(*crpc)->crp_rpc->crpc_bulk;
859 for (i = 0; i < npg; i++) {
864 len = (feats & LST_FEAT_BULK_LEN) == 0 ?
865 PAGE_CACHE_SIZE : min_t(int, nob, PAGE_CACHE_SIZE);
868 bulk->bk_iovs[i].kiov_offset = 0;
869 bulk->bk_iovs[i].kiov_len = len;
870 bulk->bk_iovs[i].kiov_page =
871 alloc_page(GFP_IOFS);
873 if (bulk->bk_iovs[i].kiov_page == NULL) {
874 lstcon_rpc_put(*crpc);
881 LASSERT (transop == LST_TRANS_TSBCLIADD);
883 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
887 npg, &bulk->bk_iovs[0]);
889 lstcon_rpc_put(*crpc);
893 trq->tsr_ndest = test->tes_span;
894 trq->tsr_loop = test->tes_loop;
897 trq->tsr_sid = console_session.ses_id;
898 trq->tsr_bid = test->tes_hdr.tsb_id;
899 trq->tsr_concur = test->tes_concur;
900 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
901 trq->tsr_stop_onerr = !!test->tes_stop_onerr;
903 switch (test->tes_type) {
905 trq->tsr_service = SRPC_SERVICE_PING;
906 rc = lstcon_pingrpc_prep((lst_test_ping_param_t *)
907 &test->tes_param[0], trq);
911 trq->tsr_service = SRPC_SERVICE_BRW;
912 if ((feats & LST_FEAT_BULK_LEN) == 0) {
913 rc = lstcon_bulkrpc_v0_prep((lst_test_bulk_param_t *)
914 &test->tes_param[0], trq);
916 rc = lstcon_bulkrpc_v1_prep((lst_test_bulk_param_t *)
917 &test->tes_param[0], trq);
930 lstcon_sesnew_stat_reply(lstcon_rpc_trans_t *trans,
931 lstcon_node_t *nd, srpc_msg_t *reply)
933 srpc_mksn_reply_t *mksn_rep = &reply->msg_body.mksn_reply;
934 int status = mksn_rep->mksn_status;
937 (reply->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
938 mksn_rep->mksn_status = EPROTO;
942 if (status == EPROTO) {
943 CNETERR("session protocol error from %s: %u\n",
944 libcfs_nid2str(nd->nd_id.nid),
945 reply->msg_ses_feats);
951 if (!trans->tas_feats_updated) {
952 spin_lock(&console_session.ses_rpc_lock);
953 if (!trans->tas_feats_updated) { /* recheck with lock */
954 trans->tas_feats_updated = 1;
955 trans->tas_features = reply->msg_ses_feats;
957 spin_unlock(&console_session.ses_rpc_lock);
960 if (reply->msg_ses_feats != trans->tas_features) {
961 CNETERR("Framework features %x from %s is different with "
962 "features on this transaction: %x\n",
963 reply->msg_ses_feats, libcfs_nid2str(nd->nd_id.nid),
964 trans->tas_features);
965 status = mksn_rep->mksn_status = EPROTO;
969 /* session timeout on remote node */
970 nd->nd_timeout = mksn_rep->mksn_timeout;
977 lstcon_rpc_stat_reply(lstcon_rpc_trans_t *trans, srpc_msg_t *msg,
978 lstcon_node_t *nd, lstcon_trans_stat_t *stat)
980 srpc_rmsn_reply_t *rmsn_rep;
981 srpc_debug_reply_t *dbg_rep;
982 srpc_batch_reply_t *bat_rep;
983 srpc_test_reply_t *test_rep;
984 srpc_stat_reply_t *stat_rep;
987 switch (trans->tas_opc) {
988 case LST_TRANS_SESNEW:
989 rc = lstcon_sesnew_stat_reply(trans, nd, msg);
991 lstcon_sesop_stat_success(stat, 1);
995 lstcon_sesop_stat_failure(stat, 1);
998 case LST_TRANS_SESEND:
999 rmsn_rep = &msg->msg_body.rmsn_reply;
1000 /* ESRCH is not an error for end session */
1001 if (rmsn_rep->rmsn_status == 0 ||
1002 rmsn_rep->rmsn_status == ESRCH) {
1003 lstcon_sesop_stat_success(stat, 1);
1007 lstcon_sesop_stat_failure(stat, 1);
1008 rc = rmsn_rep->rmsn_status;
1011 case LST_TRANS_SESQRY:
1012 case LST_TRANS_SESPING:
1013 dbg_rep = &msg->msg_body.dbg_reply;
1015 if (dbg_rep->dbg_status == ESRCH) {
1016 lstcon_sesqry_stat_unknown(stat, 1);
1020 if (lstcon_session_match(dbg_rep->dbg_sid))
1021 lstcon_sesqry_stat_active(stat, 1);
1023 lstcon_sesqry_stat_busy(stat, 1);
1026 case LST_TRANS_TSBRUN:
1027 case LST_TRANS_TSBSTOP:
1028 bat_rep = &msg->msg_body.bat_reply;
1030 if (bat_rep->bar_status == 0) {
1031 lstcon_tsbop_stat_success(stat, 1);
1035 if (bat_rep->bar_status == EPERM &&
1036 trans->tas_opc == LST_TRANS_TSBSTOP) {
1037 lstcon_tsbop_stat_success(stat, 1);
1041 lstcon_tsbop_stat_failure(stat, 1);
1042 rc = bat_rep->bar_status;
1045 case LST_TRANS_TSBCLIQRY:
1046 case LST_TRANS_TSBSRVQRY:
1047 bat_rep = &msg->msg_body.bat_reply;
1049 if (bat_rep->bar_active != 0)
1050 lstcon_tsbqry_stat_run(stat, 1);
1052 lstcon_tsbqry_stat_idle(stat, 1);
1054 if (bat_rep->bar_status == 0)
1057 lstcon_tsbqry_stat_failure(stat, 1);
1058 rc = bat_rep->bar_status;
1061 case LST_TRANS_TSBCLIADD:
1062 case LST_TRANS_TSBSRVADD:
1063 test_rep = &msg->msg_body.tes_reply;
1065 if (test_rep->tsr_status == 0) {
1066 lstcon_tsbop_stat_success(stat, 1);
1070 lstcon_tsbop_stat_failure(stat, 1);
1071 rc = test_rep->tsr_status;
1074 case LST_TRANS_STATQRY:
1075 stat_rep = &msg->msg_body.stat_reply;
1077 if (stat_rep->str_status == 0) {
1078 lstcon_statqry_stat_success(stat, 1);
1082 lstcon_statqry_stat_failure(stat, 1);
1083 rc = stat_rep->str_status;
1090 if (stat->trs_fwk_errno == 0)
1091 stat->trs_fwk_errno = rc;
1097 lstcon_rpc_trans_ndlist(cfs_list_t *ndlist,
1098 cfs_list_t *translist, int transop,
1099 void *arg, lstcon_rpc_cond_func_t condition,
1100 lstcon_rpc_trans_t **transpp)
1102 lstcon_rpc_trans_t *trans;
1103 lstcon_ndlink_t *ndl;
1109 /* Creating session RPG for list of nodes */
1111 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1113 CERROR("Can't create transaction %d: %d\n", transop, rc);
1117 feats = trans->tas_features;
1118 cfs_list_for_each_entry_typed(ndl, ndlist, lstcon_ndlink_t, ndl_link) {
1119 rc = condition == NULL ? 1 :
1120 condition(transop, ndl->ndl_node, arg);
1126 CDEBUG(D_NET, "Condition error while creating RPC "
1127 " for transaction %d: %d\n", transop, rc);
1134 case LST_TRANS_SESNEW:
1135 case LST_TRANS_SESEND:
1136 rc = lstcon_sesrpc_prep(nd, transop, feats, &rpc);
1138 case LST_TRANS_SESQRY:
1139 case LST_TRANS_SESPING:
1140 rc = lstcon_dbgrpc_prep(nd, feats, &rpc);
1142 case LST_TRANS_TSBCLIADD:
1143 case LST_TRANS_TSBSRVADD:
1144 rc = lstcon_testrpc_prep(nd, transop, feats,
1145 (lstcon_test_t *)arg, &rpc);
1147 case LST_TRANS_TSBRUN:
1148 case LST_TRANS_TSBSTOP:
1149 case LST_TRANS_TSBCLIQRY:
1150 case LST_TRANS_TSBSRVQRY:
1151 rc = lstcon_batrpc_prep(nd, transop, feats,
1152 (lstcon_tsb_hdr_t *)arg, &rpc);
1154 case LST_TRANS_STATQRY:
1155 rc = lstcon_statrpc_prep(nd, feats, &rpc);
1163 CERROR("Failed to create RPC for transaction %s: %d\n",
1164 lstcon_rpc_trans_name(transop), rc);
1168 lstcon_rpc_trans_addreq(trans, rpc);
1176 lstcon_rpc_trans_destroy(trans);
1182 lstcon_rpc_pinger(void *arg)
1184 stt_timer_t *ptimer = (stt_timer_t *)arg;
1185 lstcon_rpc_trans_t *trans;
1188 srpc_debug_reqst_t *drq;
1189 lstcon_ndlink_t *ndl;
1195 /* RPC pinger is a special case of transaction,
1196 * it's called by timer at 8 seconds interval.
1198 mutex_lock(&console_session.ses_mutex);
1200 if (console_session.ses_shutdown || console_session.ses_expired) {
1201 mutex_unlock(&console_session.ses_mutex);
1205 if (!console_session.ses_expired &&
1206 cfs_time_current_sec() - console_session.ses_laststamp >
1207 (time_t)console_session.ses_timeout)
1208 console_session.ses_expired = 1;
1210 trans = console_session.ses_ping;
1212 LASSERT (trans != NULL);
1214 cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_list,
1215 lstcon_ndlink_t, ndl_link) {
1218 if (console_session.ses_expired) {
1219 /* idle console, end session on all nodes */
1220 if (nd->nd_state != LST_NODE_ACTIVE)
1223 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND,
1224 trans->tas_features, &crpc);
1226 CERROR("Out of memory\n");
1230 lstcon_rpc_trans_addreq(trans, crpc);
1231 lstcon_rpc_post(crpc);
1236 crpc = &nd->nd_ping;
1238 if (crpc->crp_rpc != NULL) {
1239 LASSERT (crpc->crp_trans == trans);
1240 LASSERT (!cfs_list_empty(&crpc->crp_link));
1242 spin_lock(&crpc->crp_rpc->crpc_lock);
1244 LASSERT(crpc->crp_posted);
1246 if (!crpc->crp_finished) {
1248 spin_unlock(&crpc->crp_rpc->crpc_lock);
1252 spin_unlock(&crpc->crp_rpc->crpc_lock);
1254 lstcon_rpc_get_reply(crpc, &rep);
1256 cfs_list_del_init(&crpc->crp_link);
1258 lstcon_rpc_put(crpc);
1261 if (nd->nd_state != LST_NODE_ACTIVE)
1264 intv = cfs_duration_sec(cfs_time_sub(cfs_time_current(),
1266 if (intv < (time_t)nd->nd_timeout / 2)
1269 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
1270 trans->tas_features, 0, 0, 1, crpc);
1272 CERROR("Out of memory\n");
1276 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1278 drq->dbg_sid = console_session.ses_id;
1281 lstcon_rpc_trans_addreq(trans, crpc);
1282 lstcon_rpc_post(crpc);
1287 if (console_session.ses_expired) {
1288 mutex_unlock(&console_session.ses_mutex);
1292 CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1294 ptimer->stt_expires = (cfs_time_t)(cfs_time_current_sec() + LST_PING_INTERVAL);
1295 stt_add_timer(ptimer);
1297 mutex_unlock(&console_session.ses_mutex);
1301 lstcon_rpc_pinger_start(void)
1303 stt_timer_t *ptimer;
1306 LASSERT (cfs_list_empty(&console_session.ses_rpc_freelist));
1307 LASSERT (cfs_atomic_read(&console_session.ses_rpc_counter) == 0);
1309 rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1310 &console_session.ses_ping);
1312 CERROR("Failed to create console pinger\n");
1316 ptimer = &console_session.ses_ping_timer;
1317 ptimer->stt_expires = (cfs_time_t)(cfs_time_current_sec() + LST_PING_INTERVAL);
1319 stt_add_timer(ptimer);
1325 lstcon_rpc_pinger_stop(void)
1327 LASSERT (console_session.ses_shutdown);
1329 stt_del_timer(&console_session.ses_ping_timer);
1331 lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1332 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1333 lstcon_rpc_trans_destroy(console_session.ses_ping);
1335 memset(lstcon_trans_stat(), 0, sizeof(lstcon_trans_stat_t));
1337 console_session.ses_ping = NULL;
1341 lstcon_rpc_cleanup_wait(void)
1343 lstcon_rpc_trans_t *trans;
1348 /* Called with hold of global mutex */
1350 LASSERT (console_session.ses_shutdown);
1352 while (!cfs_list_empty(&console_session.ses_trans_list)) {
1353 cfs_list_for_each(pacer, &console_session.ses_trans_list) {
1354 trans = cfs_list_entry(pacer, lstcon_rpc_trans_t,
1357 CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1358 lstcon_rpc_trans_name(trans->tas_opc));
1360 cfs_waitq_signal(&trans->tas_waitq);
1363 mutex_unlock(&console_session.ses_mutex);
1365 CWARN("Session is shutting down, "
1366 "waiting for termination of transactions\n");
1367 cfs_pause(cfs_time_seconds(1));
1369 mutex_lock(&console_session.ses_mutex);
1372 spin_lock(&console_session.ses_rpc_lock);
1374 lst_wait_until((cfs_atomic_read(&console_session.ses_rpc_counter) == 0),
1375 console_session.ses_rpc_lock,
1376 "Network is not accessable or target is down, "
1377 "waiting for %d console RPCs to being recycled\n",
1378 cfs_atomic_read(&console_session.ses_rpc_counter));
1380 cfs_list_add(&zlist, &console_session.ses_rpc_freelist);
1381 cfs_list_del_init(&console_session.ses_rpc_freelist);
1383 spin_unlock(&console_session.ses_rpc_lock);
1385 while (!cfs_list_empty(&zlist)) {
1386 crpc = cfs_list_entry(zlist.next, lstcon_rpc_t, crp_link);
1388 cfs_list_del(&crpc->crp_link);
1389 LIBCFS_FREE(crpc, sizeof(lstcon_rpc_t));
1394 lstcon_rpc_module_init(void)
1396 CFS_INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1397 console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1398 console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1400 console_session.ses_ping = NULL;
1402 spin_lock_init(&console_session.ses_rpc_lock);
1403 cfs_atomic_set(&console_session.ses_rpc_counter, 0);
1404 CFS_INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1410 lstcon_rpc_module_fini(void)
1412 LASSERT (cfs_list_empty(&console_session.ses_rpc_freelist));
1413 LASSERT (cfs_atomic_read(&console_session.ses_rpc_counter) == 0);