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 cfs_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 (cfs_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 (cfs_copy_to_user(&ent->rpe_peer,
519 &nd->nd_id, sizeof(lnet_process_id_t)) ||
520 cfs_copy_to_user(&ent->rpe_stamp, &tv, sizeof(tv)) ||
521 cfs_copy_to_user(&ent->rpe_state,
522 &nd->nd_state, sizeof(nd->nd_state)) ||
523 cfs_copy_to_user(&ent->rpe_rpc_errno, &error,
531 rep = (srpc_generic_reply_t *)&msg->msg_body.reply;
533 if (cfs_copy_to_user(&ent->rpe_sid,
534 &rep->sid, sizeof(lst_sid_t)) ||
535 cfs_copy_to_user(&ent->rpe_fwk_errno,
536 &rep->status, sizeof(rep->status)))
542 if ((error = readent(trans->tas_opc, msg, ent)) != 0)
550 lstcon_rpc_trans_destroy(lstcon_rpc_trans_t *trans)
552 srpc_client_rpc_t *rpc;
557 cfs_list_for_each_entry_safe_typed(crpc, tmp,
558 &trans->tas_rpcs_list,
559 lstcon_rpc_t, crp_link) {
562 spin_lock(&rpc->crpc_lock);
564 /* free it if not posted or finished already */
565 if (!crpc->crp_posted || crpc->crp_finished) {
566 spin_unlock(&rpc->crpc_lock);
568 cfs_list_del_init(&crpc->crp_link);
569 lstcon_rpc_put(crpc);
574 /* rpcs can be still not callbacked (even LNetMDUnlink is called)
575 * because huge timeout for inaccessible network, don't make
576 * user wait for them, just abandon them, they will be recycled
579 LASSERT (crpc->crp_status != 0);
581 crpc->crp_node = NULL;
582 crpc->crp_trans = NULL;
583 cfs_list_del_init(&crpc->crp_link);
586 spin_unlock(&rpc->crpc_lock);
588 cfs_atomic_dec(&trans->tas_remaining);
591 LASSERT (cfs_atomic_read(&trans->tas_remaining) == 0);
593 cfs_list_del(&trans->tas_link);
594 if (!cfs_list_empty(&trans->tas_olink))
595 cfs_list_del(&trans->tas_olink);
597 CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
598 lstcon_rpc_trans_name(trans->tas_opc), count);
600 LIBCFS_FREE(trans, sizeof(*trans));
606 lstcon_sesrpc_prep(lstcon_node_t *nd, int transop,
607 unsigned feats, lstcon_rpc_t **crpc)
609 srpc_mksn_reqst_t *msrq;
610 srpc_rmsn_reqst_t *rsrq;
614 case LST_TRANS_SESNEW:
615 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION,
620 msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
621 msrq->mksn_sid = console_session.ses_id;
622 msrq->mksn_force = console_session.ses_force;
623 strncpy(msrq->mksn_name, console_session.ses_name,
624 strlen(console_session.ses_name));
627 case LST_TRANS_SESEND:
628 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION,
633 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
634 rsrq->rmsn_sid = console_session.ses_id;
645 lstcon_dbgrpc_prep(lstcon_node_t *nd, unsigned feats, lstcon_rpc_t **crpc)
647 srpc_debug_reqst_t *drq;
650 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, feats, 0, 0, crpc);
654 drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
656 drq->dbg_sid = console_session.ses_id;
663 lstcon_batrpc_prep(lstcon_node_t *nd, int transop, unsigned feats,
664 lstcon_tsb_hdr_t *tsb, lstcon_rpc_t **crpc)
666 lstcon_batch_t *batch;
667 srpc_batch_reqst_t *brq;
670 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, feats, 0, 0, crpc);
674 brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
676 brq->bar_sid = console_session.ses_id;
677 brq->bar_bid = tsb->tsb_id;
678 brq->bar_testidx = tsb->tsb_index;
679 brq->bar_opc = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
680 (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP:
681 SRPC_BATCH_OPC_QUERY);
683 if (transop != LST_TRANS_TSBRUN &&
684 transop != LST_TRANS_TSBSTOP)
687 LASSERT (tsb->tsb_index == 0);
689 batch = (lstcon_batch_t *)tsb;
690 brq->bar_arg = batch->bat_arg;
696 lstcon_statrpc_prep(lstcon_node_t *nd, unsigned feats, lstcon_rpc_t **crpc)
698 srpc_stat_reqst_t *srq;
701 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_QUERY_STAT, feats, 0, 0, crpc);
705 srq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.stat_reqst;
707 srq->str_sid = console_session.ses_id;
708 srq->str_type = 0; /* XXX remove it */
713 lnet_process_id_packed_t *
714 lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov)
716 lnet_process_id_packed_t *pid;
719 i = idx / SFW_ID_PER_PAGE;
723 pid = (lnet_process_id_packed_t *)cfs_page_address(kiov[i].kiov_page);
725 return &pid[idx % SFW_ID_PER_PAGE];
729 lstcon_dstnodes_prep(lstcon_group_t *grp, int idx,
730 int dist, int span, int nkiov, lnet_kiov_t *kiov)
732 lnet_process_id_packed_t *pid;
733 lstcon_ndlink_t *ndl;
741 LASSERT (grp->grp_nnode >= 1);
743 if (span > grp->grp_nnode)
746 start = ((idx / dist) * span) % grp->grp_nnode;
747 end = ((idx / dist) * span + span - 1) % grp->grp_nnode;
749 cfs_list_for_each_entry_typed(ndl, &grp->grp_ndl_list,
750 lstcon_ndlink_t, ndl_link) {
757 if (i > (end >= start ? end: grp->grp_nnode))
760 pid = lstcon_next_id((i - start), nkiov, kiov);
761 pid->nid = nd->nd_id.nid;
762 pid->pid = nd->nd_id.pid;
766 if (start <= end) /* done */
769 cfs_list_for_each_entry_typed(ndl, &grp->grp_ndl_list,
770 lstcon_ndlink_t, ndl_link) {
771 if (i > grp->grp_nnode + end)
775 pid = lstcon_next_id((i - start), nkiov, kiov);
776 pid->nid = nd->nd_id.nid;
777 pid->pid = nd->nd_id.pid;
785 lstcon_pingrpc_prep(lst_test_ping_param_t *param, srpc_test_reqst_t *req)
787 test_ping_req_t *prq = &req->tsr_u.ping;
789 prq->png_size = param->png_size;
790 prq->png_flags = param->png_flags;
796 lstcon_bulkrpc_v0_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
798 test_bulk_req_t *brq = &req->tsr_u.bulk_v0;
800 brq->blk_opc = param->blk_opc;
801 brq->blk_npg = (param->blk_size + CFS_PAGE_SIZE - 1) / CFS_PAGE_SIZE;
802 brq->blk_flags = param->blk_flags;
808 lstcon_bulkrpc_v1_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
810 test_bulk_req_v1_t *brq = &req->tsr_u.bulk_v1;
812 brq->blk_opc = param->blk_opc;
813 brq->blk_flags = param->blk_flags;
814 brq->blk_len = param->blk_size;
815 brq->blk_offset = 0; /* reserved */
821 lstcon_testrpc_prep(lstcon_node_t *nd, int transop, unsigned feats,
822 lstcon_test_t *test, lstcon_rpc_t **crpc)
824 lstcon_group_t *sgrp = test->tes_src_grp;
825 lstcon_group_t *dgrp = test->tes_dst_grp;
826 srpc_test_reqst_t *trq;
833 if (transop == LST_TRANS_TSBCLIADD) {
834 npg = sfw_id_pages(test->tes_span);
835 nob = (feats & LST_FEAT_BULK_LEN) == 0 ?
836 npg * CFS_PAGE_SIZE :
837 sizeof(lnet_process_id_packed_t) * test->tes_span;
840 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc);
844 trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
846 if (transop == LST_TRANS_TSBSRVADD) {
847 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
848 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
849 int nmax = (ndist + nspan - 1) / nspan;
852 trq->tsr_loop = nmax * test->tes_dist * test->tes_concur;
855 bulk = &(*crpc)->crp_rpc->crpc_bulk;
857 for (i = 0; i < npg; i++) {
862 len = (feats & LST_FEAT_BULK_LEN) == 0 ?
863 CFS_PAGE_SIZE : min_t(int, nob, CFS_PAGE_SIZE);
866 bulk->bk_iovs[i].kiov_offset = 0;
867 bulk->bk_iovs[i].kiov_len = len;
868 bulk->bk_iovs[i].kiov_page =
869 cfs_alloc_page(CFS_ALLOC_STD);
871 if (bulk->bk_iovs[i].kiov_page == NULL) {
872 lstcon_rpc_put(*crpc);
879 LASSERT (transop == LST_TRANS_TSBCLIADD);
881 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
885 npg, &bulk->bk_iovs[0]);
887 lstcon_rpc_put(*crpc);
891 trq->tsr_ndest = test->tes_span;
892 trq->tsr_loop = test->tes_loop;
895 trq->tsr_sid = console_session.ses_id;
896 trq->tsr_bid = test->tes_hdr.tsb_id;
897 trq->tsr_concur = test->tes_concur;
898 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
899 trq->tsr_stop_onerr = !!test->tes_stop_onerr;
901 switch (test->tes_type) {
903 trq->tsr_service = SRPC_SERVICE_PING;
904 rc = lstcon_pingrpc_prep((lst_test_ping_param_t *)
905 &test->tes_param[0], trq);
909 trq->tsr_service = SRPC_SERVICE_BRW;
910 if ((feats & LST_FEAT_BULK_LEN) == 0) {
911 rc = lstcon_bulkrpc_v0_prep((lst_test_bulk_param_t *)
912 &test->tes_param[0], trq);
914 rc = lstcon_bulkrpc_v1_prep((lst_test_bulk_param_t *)
915 &test->tes_param[0], trq);
928 lstcon_sesnew_stat_reply(lstcon_rpc_trans_t *trans,
929 lstcon_node_t *nd, srpc_msg_t *reply)
931 srpc_mksn_reply_t *mksn_rep = &reply->msg_body.mksn_reply;
932 int status = mksn_rep->mksn_status;
935 (reply->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
936 mksn_rep->mksn_status = EPROTO;
940 if (status == EPROTO) {
941 CNETERR("session protocol error from %s: %u\n",
942 libcfs_nid2str(nd->nd_id.nid),
943 reply->msg_ses_feats);
949 if (!trans->tas_feats_updated) {
950 trans->tas_feats_updated = 1;
951 trans->tas_features = reply->msg_ses_feats;
954 if (reply->msg_ses_feats != trans->tas_features) {
955 CNETERR("Framework features %x from %s is different with "
956 "features on this transaction: %x\n",
957 reply->msg_ses_feats, libcfs_nid2str(nd->nd_id.nid),
958 trans->tas_features);
959 status = mksn_rep->mksn_status = EPROTO;
963 /* session timeout on remote node */
964 nd->nd_timeout = mksn_rep->mksn_timeout;
971 lstcon_rpc_stat_reply(lstcon_rpc_trans_t *trans, srpc_msg_t *msg,
972 lstcon_node_t *nd, lstcon_trans_stat_t *stat)
974 srpc_rmsn_reply_t *rmsn_rep;
975 srpc_debug_reply_t *dbg_rep;
976 srpc_batch_reply_t *bat_rep;
977 srpc_test_reply_t *test_rep;
978 srpc_stat_reply_t *stat_rep;
981 switch (trans->tas_opc) {
982 case LST_TRANS_SESNEW:
983 rc = lstcon_sesnew_stat_reply(trans, nd, msg);
985 lstcon_sesop_stat_success(stat, 1);
989 lstcon_sesop_stat_failure(stat, 1);
992 case LST_TRANS_SESEND:
993 rmsn_rep = &msg->msg_body.rmsn_reply;
994 /* ESRCH is not an error for end session */
995 if (rmsn_rep->rmsn_status == 0 ||
996 rmsn_rep->rmsn_status == ESRCH) {
997 lstcon_sesop_stat_success(stat, 1);
1001 lstcon_sesop_stat_failure(stat, 1);
1002 rc = rmsn_rep->rmsn_status;
1005 case LST_TRANS_SESQRY:
1006 case LST_TRANS_SESPING:
1007 dbg_rep = &msg->msg_body.dbg_reply;
1009 if (dbg_rep->dbg_status == ESRCH) {
1010 lstcon_sesqry_stat_unknown(stat, 1);
1014 if (lstcon_session_match(dbg_rep->dbg_sid))
1015 lstcon_sesqry_stat_active(stat, 1);
1017 lstcon_sesqry_stat_busy(stat, 1);
1020 case LST_TRANS_TSBRUN:
1021 case LST_TRANS_TSBSTOP:
1022 bat_rep = &msg->msg_body.bat_reply;
1024 if (bat_rep->bar_status == 0) {
1025 lstcon_tsbop_stat_success(stat, 1);
1029 if (bat_rep->bar_status == EPERM &&
1030 trans->tas_opc == LST_TRANS_TSBSTOP) {
1031 lstcon_tsbop_stat_success(stat, 1);
1035 lstcon_tsbop_stat_failure(stat, 1);
1036 rc = bat_rep->bar_status;
1039 case LST_TRANS_TSBCLIQRY:
1040 case LST_TRANS_TSBSRVQRY:
1041 bat_rep = &msg->msg_body.bat_reply;
1043 if (bat_rep->bar_active != 0)
1044 lstcon_tsbqry_stat_run(stat, 1);
1046 lstcon_tsbqry_stat_idle(stat, 1);
1048 if (bat_rep->bar_status == 0)
1051 lstcon_tsbqry_stat_failure(stat, 1);
1052 rc = bat_rep->bar_status;
1055 case LST_TRANS_TSBCLIADD:
1056 case LST_TRANS_TSBSRVADD:
1057 test_rep = &msg->msg_body.tes_reply;
1059 if (test_rep->tsr_status == 0) {
1060 lstcon_tsbop_stat_success(stat, 1);
1064 lstcon_tsbop_stat_failure(stat, 1);
1065 rc = test_rep->tsr_status;
1068 case LST_TRANS_STATQRY:
1069 stat_rep = &msg->msg_body.stat_reply;
1071 if (stat_rep->str_status == 0) {
1072 lstcon_statqry_stat_success(stat, 1);
1076 lstcon_statqry_stat_failure(stat, 1);
1077 rc = stat_rep->str_status;
1084 if (stat->trs_fwk_errno == 0)
1085 stat->trs_fwk_errno = rc;
1091 lstcon_rpc_trans_ndlist(cfs_list_t *ndlist,
1092 cfs_list_t *translist, int transop,
1093 void *arg, lstcon_rpc_cond_func_t condition,
1094 lstcon_rpc_trans_t **transpp)
1096 lstcon_rpc_trans_t *trans;
1097 lstcon_ndlink_t *ndl;
1103 /* Creating session RPG for list of nodes */
1105 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1107 CERROR("Can't create transaction %d: %d\n", transop, rc);
1111 feats = trans->tas_features;
1112 cfs_list_for_each_entry_typed(ndl, ndlist, lstcon_ndlink_t, ndl_link) {
1113 rc = condition == NULL ? 1 :
1114 condition(transop, ndl->ndl_node, arg);
1120 CDEBUG(D_NET, "Condition error while creating RPC "
1121 " for transaction %d: %d\n", transop, rc);
1128 case LST_TRANS_SESNEW:
1129 case LST_TRANS_SESEND:
1130 rc = lstcon_sesrpc_prep(nd, transop, feats, &rpc);
1132 case LST_TRANS_SESQRY:
1133 case LST_TRANS_SESPING:
1134 rc = lstcon_dbgrpc_prep(nd, feats, &rpc);
1136 case LST_TRANS_TSBCLIADD:
1137 case LST_TRANS_TSBSRVADD:
1138 rc = lstcon_testrpc_prep(nd, transop, feats,
1139 (lstcon_test_t *)arg, &rpc);
1141 case LST_TRANS_TSBRUN:
1142 case LST_TRANS_TSBSTOP:
1143 case LST_TRANS_TSBCLIQRY:
1144 case LST_TRANS_TSBSRVQRY:
1145 rc = lstcon_batrpc_prep(nd, transop, feats,
1146 (lstcon_tsb_hdr_t *)arg, &rpc);
1148 case LST_TRANS_STATQRY:
1149 rc = lstcon_statrpc_prep(nd, feats, &rpc);
1157 CERROR("Failed to create RPC for transaction %s: %d\n",
1158 lstcon_rpc_trans_name(transop), rc);
1162 lstcon_rpc_trans_addreq(trans, rpc);
1170 lstcon_rpc_trans_destroy(trans);
1176 lstcon_rpc_pinger(void *arg)
1178 stt_timer_t *ptimer = (stt_timer_t *)arg;
1179 lstcon_rpc_trans_t *trans;
1182 srpc_debug_reqst_t *drq;
1183 lstcon_ndlink_t *ndl;
1189 /* RPC pinger is a special case of transaction,
1190 * it's called by timer at 8 seconds interval.
1192 mutex_lock(&console_session.ses_mutex);
1194 if (console_session.ses_shutdown || console_session.ses_expired) {
1195 mutex_unlock(&console_session.ses_mutex);
1199 if (!console_session.ses_expired &&
1200 cfs_time_current_sec() - console_session.ses_laststamp >
1201 (time_t)console_session.ses_timeout)
1202 console_session.ses_expired = 1;
1204 trans = console_session.ses_ping;
1206 LASSERT (trans != NULL);
1208 cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_list,
1209 lstcon_ndlink_t, ndl_link) {
1212 if (console_session.ses_expired) {
1213 /* idle console, end session on all nodes */
1214 if (nd->nd_state != LST_NODE_ACTIVE)
1217 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND,
1218 trans->tas_features, &crpc);
1220 CERROR("Out of memory\n");
1224 lstcon_rpc_trans_addreq(trans, crpc);
1225 lstcon_rpc_post(crpc);
1230 crpc = &nd->nd_ping;
1232 if (crpc->crp_rpc != NULL) {
1233 LASSERT (crpc->crp_trans == trans);
1234 LASSERT (!cfs_list_empty(&crpc->crp_link));
1236 spin_lock(&crpc->crp_rpc->crpc_lock);
1238 LASSERT(crpc->crp_posted);
1240 if (!crpc->crp_finished) {
1242 spin_unlock(&crpc->crp_rpc->crpc_lock);
1246 spin_unlock(&crpc->crp_rpc->crpc_lock);
1248 lstcon_rpc_get_reply(crpc, &rep);
1250 cfs_list_del_init(&crpc->crp_link);
1252 lstcon_rpc_put(crpc);
1255 if (nd->nd_state != LST_NODE_ACTIVE)
1258 intv = cfs_duration_sec(cfs_time_sub(cfs_time_current(),
1260 if (intv < (time_t)nd->nd_timeout / 2)
1263 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
1264 trans->tas_features, 0, 0, 1, crpc);
1266 CERROR("Out of memory\n");
1270 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1272 drq->dbg_sid = console_session.ses_id;
1275 lstcon_rpc_trans_addreq(trans, crpc);
1276 lstcon_rpc_post(crpc);
1281 if (console_session.ses_expired) {
1282 mutex_unlock(&console_session.ses_mutex);
1286 CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1288 ptimer->stt_expires = (cfs_time_t)(cfs_time_current_sec() + LST_PING_INTERVAL);
1289 stt_add_timer(ptimer);
1291 mutex_unlock(&console_session.ses_mutex);
1295 lstcon_rpc_pinger_start(void)
1297 stt_timer_t *ptimer;
1300 LASSERT (cfs_list_empty(&console_session.ses_rpc_freelist));
1301 LASSERT (cfs_atomic_read(&console_session.ses_rpc_counter) == 0);
1303 rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1304 &console_session.ses_ping);
1306 CERROR("Failed to create console pinger\n");
1310 ptimer = &console_session.ses_ping_timer;
1311 ptimer->stt_expires = (cfs_time_t)(cfs_time_current_sec() + LST_PING_INTERVAL);
1313 stt_add_timer(ptimer);
1319 lstcon_rpc_pinger_stop(void)
1321 LASSERT (console_session.ses_shutdown);
1323 stt_del_timer(&console_session.ses_ping_timer);
1325 lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1326 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1327 lstcon_rpc_trans_destroy(console_session.ses_ping);
1329 memset(lstcon_trans_stat(), 0, sizeof(lstcon_trans_stat_t));
1331 console_session.ses_ping = NULL;
1335 lstcon_rpc_cleanup_wait(void)
1337 lstcon_rpc_trans_t *trans;
1342 /* Called with hold of global mutex */
1344 LASSERT (console_session.ses_shutdown);
1346 while (!cfs_list_empty(&console_session.ses_trans_list)) {
1347 cfs_list_for_each(pacer, &console_session.ses_trans_list) {
1348 trans = cfs_list_entry(pacer, lstcon_rpc_trans_t,
1351 CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1352 lstcon_rpc_trans_name(trans->tas_opc));
1354 cfs_waitq_signal(&trans->tas_waitq);
1357 mutex_unlock(&console_session.ses_mutex);
1359 CWARN("Session is shutting down, "
1360 "waiting for termination of transactions\n");
1361 cfs_pause(cfs_time_seconds(1));
1363 mutex_lock(&console_session.ses_mutex);
1366 spin_lock(&console_session.ses_rpc_lock);
1368 lst_wait_until((cfs_atomic_read(&console_session.ses_rpc_counter) == 0),
1369 console_session.ses_rpc_lock,
1370 "Network is not accessable or target is down, "
1371 "waiting for %d console RPCs to being recycled\n",
1372 cfs_atomic_read(&console_session.ses_rpc_counter));
1374 cfs_list_add(&zlist, &console_session.ses_rpc_freelist);
1375 cfs_list_del_init(&console_session.ses_rpc_freelist);
1377 spin_unlock(&console_session.ses_rpc_lock);
1379 while (!cfs_list_empty(&zlist)) {
1380 crpc = cfs_list_entry(zlist.next, lstcon_rpc_t, crp_link);
1382 cfs_list_del(&crpc->crp_link);
1383 LIBCFS_FREE(crpc, sizeof(lstcon_rpc_t));
1388 lstcon_rpc_module_init(void)
1390 CFS_INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1391 console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1392 console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1394 console_session.ses_ping = NULL;
1396 spin_lock_init(&console_session.ses_rpc_lock);
1397 cfs_atomic_set(&console_session.ses_rpc_counter, 0);
1398 CFS_INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1404 lstcon_rpc_module_fini(void)
1406 LASSERT (cfs_list_empty(&console_session.ses_rpc_freelist));
1407 LASSERT (cfs_atomic_read(&console_session.ses_rpc_counter) == 0);