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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lnet/selftest/conctl.c
33 * Console framework rpcs
35 * Author: Liang Zhen <liang@whamcloud.com>
39 #include <libcfs/libcfs.h>
40 #include <lnet/lib-lnet.h>
45 void lstcon_rpc_stat_reply(struct lstcon_rpc_trans *, struct srpc_msg *,
46 struct lstcon_node *, struct lstcon_trans_stat *);
49 lstcon_rpc_done(struct srpc_client_rpc *rpc)
51 struct lstcon_rpc *crpc = rpc->crpc_priv;
53 LASSERT(crpc != NULL && rpc == crpc->crp_rpc);
54 LASSERT(crpc->crp_posted && !crpc->crp_finished);
56 spin_lock(&rpc->crpc_lock);
58 if (crpc->crp_trans == NULL) {
59 /* Orphan RPC is not in any transaction,
60 * I'm just a poor body and nobody loves me */
61 spin_unlock(&rpc->crpc_lock);
68 /* not an orphan RPC */
69 crpc->crp_finished = 1;
71 if (crpc->crp_stamp_ns == 0) {
73 LASSERT(crpc->crp_status == 0);
75 crpc->crp_stamp_ns = ktime_get_ns();
76 crpc->crp_status = rpc->crpc_status;
79 /* wakeup (transaction)thread if I'm the last RPC in the transaction */
80 if (atomic_dec_and_test(&crpc->crp_trans->tas_remaining))
81 wake_up(&crpc->crp_trans->tas_waitq);
83 spin_unlock(&rpc->crpc_lock);
87 lstcon_rpc_init(struct lstcon_node *nd, int service, unsigned int feats,
88 int bulk_npg, int bulk_len, int embedded,
89 struct lstcon_rpc *crpc)
91 memset(crpc, 0, sizeof(*crpc));
93 crpc->crp_rpc = sfw_create_rpc(nd->nd_id, service,
94 feats, bulk_npg, bulk_len,
95 lstcon_rpc_done, (void *)crpc);
96 if (crpc->crp_rpc == NULL)
100 crpc->crp_embedded = embedded;
101 INIT_LIST_HEAD(&crpc->crp_link);
103 atomic_inc(&console_session.ses_rpc_counter);
109 lstcon_rpc_prep(struct lstcon_node *nd, int service, unsigned int feats,
110 int bulk_npg, int bulk_len, struct lstcon_rpc **crpcpp)
112 struct lstcon_rpc *crpc = NULL;
115 spin_lock(&console_session.ses_rpc_lock);
117 if (!list_empty(&console_session.ses_rpc_freelist)) {
118 crpc = list_entry(console_session.ses_rpc_freelist.next,
119 struct lstcon_rpc, crp_link);
120 list_del_init(&crpc->crp_link);
123 spin_unlock(&console_session.ses_rpc_lock);
126 LIBCFS_ALLOC(crpc, sizeof(*crpc));
131 rc = lstcon_rpc_init(nd, service, feats, bulk_npg, bulk_len, 0, crpc);
137 LIBCFS_FREE(crpc, sizeof(*crpc));
143 lstcon_rpc_put(struct lstcon_rpc *crpc)
145 struct srpc_bulk *bulk = &crpc->crp_rpc->crpc_bulk;
148 LASSERT(list_empty(&crpc->crp_link));
150 for (i = 0; i < bulk->bk_niov; i++) {
151 if (bulk->bk_iovs[i].bv_page == NULL)
154 __free_page(bulk->bk_iovs[i].bv_page);
157 srpc_client_rpc_decref(crpc->crp_rpc);
159 if (crpc->crp_embedded) {
160 /* embedded RPC, don't recycle it */
161 memset(crpc, 0, sizeof(*crpc));
162 crpc->crp_embedded = 1;
165 spin_lock(&console_session.ses_rpc_lock);
167 list_add(&crpc->crp_link,
168 &console_session.ses_rpc_freelist);
170 spin_unlock(&console_session.ses_rpc_lock);
173 /* RPC is not alive now */
174 atomic_dec(&console_session.ses_rpc_counter);
178 lstcon_rpc_post(struct lstcon_rpc *crpc)
180 struct lstcon_rpc_trans *trans = crpc->crp_trans;
182 LASSERT (trans != NULL);
184 atomic_inc(&trans->tas_remaining);
185 crpc->crp_posted = 1;
187 sfw_post_rpc(crpc->crp_rpc);
191 lstcon_rpc_trans_name(int transop)
193 if (transop == LST_TRANS_SESNEW)
196 if (transop == LST_TRANS_SESEND)
199 if (transop == LST_TRANS_SESQRY)
202 if (transop == LST_TRANS_SESPING)
205 if (transop == LST_TRANS_TSBCLIADD)
208 if (transop == LST_TRANS_TSBSRVADD)
211 if (transop == LST_TRANS_TSBRUN)
214 if (transop == LST_TRANS_TSBSTOP)
217 if (transop == LST_TRANS_TSBCLIQRY)
220 if (transop == LST_TRANS_TSBSRVQRY)
223 if (transop == LST_TRANS_STATQRY)
230 lstcon_rpc_trans_prep(struct list_head *translist, int transop,
231 struct lstcon_rpc_trans **transpp)
233 struct lstcon_rpc_trans *trans;
235 if (translist != NULL) {
236 list_for_each_entry(trans, translist, tas_link) {
237 /* Can't enqueue two private transaction on
239 if ((trans->tas_opc & transop) == LST_TRANS_PRIVATE)
244 /* create a trans group */
245 LIBCFS_ALLOC(trans, sizeof(*trans));
249 trans->tas_opc = transop;
251 if (translist == NULL)
252 INIT_LIST_HEAD(&trans->tas_olink);
254 list_add_tail(&trans->tas_olink, translist);
256 list_add_tail(&trans->tas_link, &console_session.ses_trans_list);
258 INIT_LIST_HEAD(&trans->tas_rpcs_list);
259 atomic_set(&trans->tas_remaining, 0);
260 init_waitqueue_head(&trans->tas_waitq);
262 spin_lock(&console_session.ses_rpc_lock);
263 trans->tas_features = console_session.ses_features;
264 spin_unlock(&console_session.ses_rpc_lock);
271 lstcon_rpc_trans_addreq(struct lstcon_rpc_trans *trans, struct lstcon_rpc *crpc)
273 list_add_tail(&crpc->crp_link, &trans->tas_rpcs_list);
274 crpc->crp_trans = trans;
278 lstcon_rpc_trans_abort(struct lstcon_rpc_trans *trans, int error)
280 struct srpc_client_rpc *rpc;
281 struct lstcon_rpc *crpc;
282 struct lstcon_node *nd;
284 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
287 spin_lock(&rpc->crpc_lock);
289 if (!crpc->crp_posted || /* not posted */
290 crpc->crp_stamp_ns != 0) { /* rpc done or aborted already */
291 if (crpc->crp_stamp_ns == 0) {
292 crpc->crp_stamp_ns = ktime_get_ns();
293 crpc->crp_status = -EINTR;
295 spin_unlock(&rpc->crpc_lock);
299 crpc->crp_stamp_ns = ktime_get_ns();
300 crpc->crp_status = error;
302 spin_unlock(&rpc->crpc_lock);
306 if (error != -ETIMEDOUT)
310 if (ktime_to_ns(nd->nd_stamp) > crpc->crp_stamp_ns)
313 nd->nd_stamp = ktime_set(0, crpc->crp_stamp_ns);
314 nd->nd_state = LST_NODE_DOWN;
319 lstcon_rpc_trans_check(struct lstcon_rpc_trans *trans)
321 if (console_session.ses_shutdown &&
322 !list_empty(&trans->tas_olink)) /* Not an end session RPC */
325 return (atomic_read(&trans->tas_remaining) == 0) ? 1: 0;
329 lstcon_rpc_trans_postwait(struct lstcon_rpc_trans *trans, int timeout)
331 struct lstcon_rpc *crpc;
334 if (list_empty(&trans->tas_rpcs_list))
337 if (timeout < LST_TRANS_MIN_TIMEOUT)
338 timeout = LST_TRANS_MIN_TIMEOUT;
340 CDEBUG(D_NET, "Transaction %s started\n",
341 lstcon_rpc_trans_name(trans->tas_opc));
343 /* post all requests */
344 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
345 LASSERT(!crpc->crp_posted);
347 lstcon_rpc_post(crpc);
350 mutex_unlock(&console_session.ses_mutex);
352 rc = wait_event_interruptible_timeout(trans->tas_waitq,
353 lstcon_rpc_trans_check(trans),
354 cfs_time_seconds(timeout));
356 rc = (rc > 0)? 0: ((rc < 0)? -EINTR: -ETIMEDOUT);
358 mutex_lock(&console_session.ses_mutex);
360 if (console_session.ses_shutdown)
363 if (rc != 0 || atomic_read(&trans->tas_remaining) != 0) {
364 /* treat short timeout as canceled */
365 if (rc == -ETIMEDOUT && timeout < LST_TRANS_MIN_TIMEOUT * 2)
368 lstcon_rpc_trans_abort(trans, rc);
371 CDEBUG(D_NET, "Transaction %s stopped: %d\n",
372 lstcon_rpc_trans_name(trans->tas_opc), rc);
374 lstcon_rpc_trans_stat(trans, lstcon_trans_stat());
380 lstcon_rpc_get_reply(struct lstcon_rpc *crpc, struct srpc_msg **msgpp)
382 struct lstcon_node *nd = crpc->crp_node;
383 struct srpc_client_rpc *rpc = crpc->crp_rpc;
384 struct srpc_generic_reply *rep;
386 LASSERT(nd != NULL && rpc != NULL);
387 LASSERT(crpc->crp_stamp_ns != 0);
389 if (crpc->crp_status != 0) {
391 return crpc->crp_status;
394 *msgpp = &rpc->crpc_replymsg;
395 if (!crpc->crp_unpacked) {
396 sfw_unpack_message(*msgpp);
397 crpc->crp_unpacked = 1;
400 if (ktime_to_ns(nd->nd_stamp) > crpc->crp_stamp_ns)
403 nd->nd_stamp = ktime_set(0, crpc->crp_stamp_ns);
404 rep = &(*msgpp)->msg_body.reply;
406 if (rep->sid.ses_nid == LNET_NID_ANY)
407 nd->nd_state = LST_NODE_UNKNOWN;
408 else if (lstcon_session_match(rep->sid))
409 nd->nd_state = LST_NODE_ACTIVE;
411 nd->nd_state = LST_NODE_BUSY;
417 lstcon_rpc_trans_stat(struct lstcon_rpc_trans *trans,
418 struct lstcon_trans_stat *stat)
420 struct lstcon_rpc *crpc;
421 struct srpc_msg *rep;
424 LASSERT(stat != NULL);
426 memset(stat, 0, sizeof(*stat));
428 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
429 lstcon_rpc_stat_total(stat, 1);
431 LASSERT(crpc->crp_stamp_ns != 0);
433 error = lstcon_rpc_get_reply(crpc, &rep);
435 lstcon_rpc_stat_failure(stat, 1);
436 if (stat->trs_rpc_errno == 0)
437 stat->trs_rpc_errno = -error;
442 lstcon_rpc_stat_success(stat, 1);
444 lstcon_rpc_stat_reply(trans, rep, crpc->crp_node, stat);
447 if (trans->tas_opc == LST_TRANS_SESNEW && stat->trs_fwk_errno == 0) {
448 stat->trs_fwk_errno =
449 lstcon_session_feats_check(trans->tas_features);
452 CDEBUG(D_NET, "transaction %s : success %d, failure %d, total %d, "
453 "RPC error(%d), Framework error(%d)\n",
454 lstcon_rpc_trans_name(trans->tas_opc),
455 lstcon_rpc_stat_success(stat, 0),
456 lstcon_rpc_stat_failure(stat, 0),
457 lstcon_rpc_stat_total(stat, 0),
458 stat->trs_rpc_errno, stat->trs_fwk_errno);
462 lstcon_rpc_trans_interpreter(struct lstcon_rpc_trans *trans,
463 struct list_head __user *head_up,
464 lstcon_rpc_readent_func_t readent)
466 struct list_head tmp;
467 struct list_head __user *next;
468 struct lstcon_rpc_ent *ent;
469 struct srpc_generic_reply *rep;
470 struct lstcon_rpc *crpc;
471 struct srpc_msg *msg;
472 struct lstcon_node *nd;
473 struct timespec64 ts;
477 LASSERT(head_up != NULL);
481 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
482 if (copy_from_user(&tmp, next,
483 sizeof(struct list_head)))
486 if (tmp.next == head_up)
491 ent = list_entry(next, struct lstcon_rpc_ent, rpe_link);
493 LASSERT(crpc->crp_stamp_ns != 0);
495 error = lstcon_rpc_get_reply(crpc, &msg);
499 dur = crpc->crp_stamp_ns -
500 console_session.ses_id.ses_stamp * NSEC_PER_MSEC;
501 ts = ns_to_timespec64(dur);
503 if (copy_to_user(&ent->rpe_peer,
504 &nd->nd_id, sizeof(struct lnet_process_id)) ||
505 copy_to_user(&ent->rpe_stamp, &ts, sizeof(ts)) ||
506 copy_to_user(&ent->rpe_state,
507 &nd->nd_state, sizeof(nd->nd_state)) ||
508 copy_to_user(&ent->rpe_rpc_errno, &error,
516 rep = (struct srpc_generic_reply *)&msg->msg_body.reply;
518 if (copy_to_user(&ent->rpe_sid,
519 &rep->sid, sizeof(rep->sid)) ||
520 copy_to_user(&ent->rpe_fwk_errno,
521 &rep->status, sizeof(rep->status)))
527 error = readent(trans->tas_opc, msg, ent);
536 lstcon_rpc_trans_destroy(struct lstcon_rpc_trans *trans)
538 struct srpc_client_rpc *rpc;
539 struct lstcon_rpc *crpc;
540 struct lstcon_rpc *tmp;
543 list_for_each_entry_safe(crpc, tmp, &trans->tas_rpcs_list, crp_link) {
546 spin_lock(&rpc->crpc_lock);
548 /* free it if not posted or finished already */
549 if (!crpc->crp_posted || crpc->crp_finished) {
550 spin_unlock(&rpc->crpc_lock);
552 list_del_init(&crpc->crp_link);
553 lstcon_rpc_put(crpc);
558 /* rpcs can be still not callbacked (even LNetMDUnlink is
559 * called) because huge timeout for inaccessible network,
560 * don't make user wait for them, just abandon them, they
561 * will be recycled in callback */
563 LASSERT(crpc->crp_status != 0);
565 crpc->crp_node = NULL;
566 crpc->crp_trans = NULL;
567 list_del_init(&crpc->crp_link);
570 spin_unlock(&rpc->crpc_lock);
572 atomic_dec(&trans->tas_remaining);
575 LASSERT(atomic_read(&trans->tas_remaining) == 0);
577 list_del(&trans->tas_link);
578 if (!list_empty(&trans->tas_olink))
579 list_del(&trans->tas_olink);
581 CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
582 lstcon_rpc_trans_name(trans->tas_opc), count);
584 LIBCFS_FREE(trans, sizeof(*trans));
588 lstcon_sesrpc_prep(struct lstcon_node *nd, int transop,
589 unsigned int feats, struct lstcon_rpc **crpc)
591 struct srpc_mksn_reqst *msrq;
592 struct srpc_rmsn_reqst *rsrq;
596 case LST_TRANS_SESNEW:
597 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION,
602 msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
603 msrq->mksn_sid = console_session.ses_id;
604 msrq->mksn_force = console_session.ses_force;
605 strlcpy(msrq->mksn_name, console_session.ses_name,
606 sizeof(msrq->mksn_name));
609 case LST_TRANS_SESEND:
610 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION,
615 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
616 rsrq->rmsn_sid = console_session.ses_id;
627 lstcon_dbgrpc_prep(struct lstcon_node *nd, unsigned int feats,
628 struct lstcon_rpc **crpc)
630 struct srpc_debug_reqst *drq;
633 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, feats, 0, 0, crpc);
637 drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
639 drq->dbg_sid = console_session.ses_id;
646 lstcon_batrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
647 struct lstcon_tsb_hdr *tsb, struct lstcon_rpc **crpc)
649 struct lstcon_batch *batch;
650 struct srpc_batch_reqst *brq;
653 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, feats, 0, 0, crpc);
657 brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
659 brq->bar_sid = console_session.ses_id;
660 brq->bar_bid = tsb->tsb_id;
661 brq->bar_testidx = tsb->tsb_index;
662 brq->bar_opc = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
663 (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP:
664 SRPC_BATCH_OPC_QUERY);
666 if (transop != LST_TRANS_TSBRUN &&
667 transop != LST_TRANS_TSBSTOP)
670 LASSERT (tsb->tsb_index == 0);
672 batch = (struct lstcon_batch *)tsb;
673 brq->bar_arg = batch->bat_arg;
679 lstcon_statrpc_prep(struct lstcon_node *nd, unsigned int feats,
680 struct lstcon_rpc **crpc)
682 struct srpc_stat_reqst *srq;
685 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_QUERY_STAT, feats, 0, 0, crpc);
689 srq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.stat_reqst;
691 srq->str_sid = console_session.ses_id;
692 srq->str_type = 0; /* XXX remove it */
697 static struct lnet_process_id_packed *
698 lstcon_next_id(int idx, int nkiov, struct bio_vec *kiov)
700 struct lnet_process_id_packed *pid;
703 i = idx / SFW_ID_PER_PAGE;
707 pid = (struct lnet_process_id_packed *)page_address(kiov[i].bv_page);
709 return &pid[idx % SFW_ID_PER_PAGE];
713 lstcon_dstnodes_prep(struct lstcon_group *grp, int idx,
714 int dist, int span, int nkiov, struct bio_vec *kiov)
716 struct lnet_process_id_packed *pid;
717 struct lstcon_ndlink *ndl;
718 struct lstcon_node *nd;
725 LASSERT (grp->grp_nnode >= 1);
727 if (span > grp->grp_nnode)
730 start = ((idx / dist) * span) % grp->grp_nnode;
731 end = ((idx / dist) * span + span - 1) % grp->grp_nnode;
733 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
740 if (i > (end >= start ? end : grp->grp_nnode))
743 pid = lstcon_next_id((i - start), nkiov, kiov);
744 pid->nid = nd->nd_id.nid;
745 pid->pid = nd->nd_id.pid;
749 if (start <= end) /* done */
752 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
753 if (i > grp->grp_nnode + end)
757 pid = lstcon_next_id((i - start), nkiov, kiov);
758 pid->nid = nd->nd_id.nid;
759 pid->pid = nd->nd_id.pid;
767 lstcon_pingrpc_prep(struct lst_test_ping_param *param,
768 struct srpc_test_reqst *req)
770 struct test_ping_req *prq = &req->tsr_u.ping;
772 prq->png_size = param->png_size;
773 prq->png_flags = param->png_flags;
779 lstcon_bulkrpc_v0_prep(struct lst_test_bulk_param *param,
780 struct srpc_test_reqst *req)
782 struct test_bulk_req *brq = &req->tsr_u.bulk_v0;
784 brq->blk_opc = param->blk_opc;
785 brq->blk_npg = (param->blk_size + PAGE_SIZE - 1) /
787 brq->blk_flags = param->blk_flags;
793 lstcon_bulkrpc_v1_prep(struct lst_test_bulk_param *param, bool is_client,
794 struct srpc_test_reqst *req)
796 struct test_bulk_req_v1 *brq = &req->tsr_u.bulk_v1;
798 brq->blk_opc = param->blk_opc;
799 brq->blk_flags = param->blk_flags;
800 brq->blk_len = param->blk_size;
801 brq->blk_offset = is_client ? param->blk_cli_off : param->blk_srv_off;
807 lstcon_testrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
808 struct lstcon_test *test, struct lstcon_rpc **crpc)
810 struct lstcon_group *sgrp = test->tes_src_grp;
811 struct lstcon_group *dgrp = test->tes_dst_grp;
812 struct srpc_test_reqst *trq;
813 struct srpc_bulk *bulk;
819 if (transop == LST_TRANS_TSBCLIADD) {
820 npg = sfw_id_pages(test->tes_span);
821 nob = (feats & LST_FEAT_BULK_LEN) == 0 ?
823 sizeof(struct lnet_process_id_packed) * test->tes_span;
826 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc);
830 trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
832 if (transop == LST_TRANS_TSBSRVADD) {
833 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
834 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
835 int nmax = (ndist + nspan - 1) / nspan;
838 trq->tsr_loop = nmax * test->tes_dist * test->tes_concur;
841 bulk = &(*crpc)->crp_rpc->crpc_bulk;
843 for (i = 0; i < npg; i++) {
848 len = (feats & LST_FEAT_BULK_LEN) == 0 ?
849 PAGE_SIZE : min_t(int, nob, PAGE_SIZE);
852 bulk->bk_iovs[i].bv_offset = 0;
853 bulk->bk_iovs[i].bv_len = len;
854 bulk->bk_iovs[i].bv_page =
855 alloc_page(GFP_KERNEL);
857 if (bulk->bk_iovs[i].bv_page == NULL) {
858 lstcon_rpc_put(*crpc);
865 LASSERT (transop == LST_TRANS_TSBCLIADD);
867 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
871 npg, &bulk->bk_iovs[0]);
873 lstcon_rpc_put(*crpc);
877 trq->tsr_ndest = test->tes_span;
878 trq->tsr_loop = test->tes_loop;
881 trq->tsr_sid = console_session.ses_id;
882 trq->tsr_bid = test->tes_hdr.tsb_id;
883 trq->tsr_concur = test->tes_concur;
884 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
885 trq->tsr_stop_onerr = !!test->tes_stop_onerr;
887 switch (test->tes_type) {
889 trq->tsr_service = SRPC_SERVICE_PING;
890 rc = lstcon_pingrpc_prep((struct lst_test_ping_param *)
891 &test->tes_param[0], trq);
895 trq->tsr_service = SRPC_SERVICE_BRW;
896 if ((feats & LST_FEAT_BULK_LEN) == 0) {
897 rc = lstcon_bulkrpc_v0_prep((struct lst_test_bulk_param *)
898 &test->tes_param[0], trq);
900 rc = lstcon_bulkrpc_v1_prep((struct lst_test_bulk_param *)
902 trq->tsr_is_client, trq);
915 lstcon_sesnew_stat_reply(struct lstcon_rpc_trans *trans,
916 struct lstcon_node *nd, struct srpc_msg *reply)
918 struct srpc_mksn_reply *mksn_rep = &reply->msg_body.mksn_reply;
919 int status = mksn_rep->mksn_status;
922 (reply->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
923 mksn_rep->mksn_status = EPROTO;
927 if (status == EPROTO) {
928 CNETERR("session protocol error from %s: %u\n",
929 libcfs_nid2str(nd->nd_id.nid),
930 reply->msg_ses_feats);
936 if (!trans->tas_feats_updated) {
937 spin_lock(&console_session.ses_rpc_lock);
938 if (!trans->tas_feats_updated) { /* recheck with lock */
939 trans->tas_feats_updated = 1;
940 trans->tas_features = reply->msg_ses_feats;
942 spin_unlock(&console_session.ses_rpc_lock);
945 if (reply->msg_ses_feats != trans->tas_features) {
946 CNETERR("Framework features %x from %s is different with "
947 "features on this transaction: %x\n",
948 reply->msg_ses_feats, libcfs_nid2str(nd->nd_id.nid),
949 trans->tas_features);
950 status = mksn_rep->mksn_status = EPROTO;
954 /* session timeout on remote node */
955 nd->nd_timeout = mksn_rep->mksn_timeout;
962 lstcon_rpc_stat_reply(struct lstcon_rpc_trans *trans, struct srpc_msg *msg,
963 struct lstcon_node *nd, struct lstcon_trans_stat *stat)
965 struct srpc_rmsn_reply *rmsn_rep;
966 struct srpc_debug_reply *dbg_rep;
967 struct srpc_batch_reply *bat_rep;
968 struct srpc_test_reply *test_rep;
969 struct srpc_stat_reply *stat_rep;
972 switch (trans->tas_opc) {
973 case LST_TRANS_SESNEW:
974 rc = lstcon_sesnew_stat_reply(trans, nd, msg);
976 lstcon_sesop_stat_success(stat, 1);
980 lstcon_sesop_stat_failure(stat, 1);
983 case LST_TRANS_SESEND:
984 rmsn_rep = &msg->msg_body.rmsn_reply;
985 /* ESRCH is not an error for end session */
986 if (rmsn_rep->rmsn_status == 0 ||
987 rmsn_rep->rmsn_status == ESRCH) {
988 lstcon_sesop_stat_success(stat, 1);
992 lstcon_sesop_stat_failure(stat, 1);
993 rc = rmsn_rep->rmsn_status;
996 case LST_TRANS_SESQRY:
997 case LST_TRANS_SESPING:
998 dbg_rep = &msg->msg_body.dbg_reply;
1000 if (dbg_rep->dbg_status == ESRCH) {
1001 lstcon_sesqry_stat_unknown(stat, 1);
1005 if (lstcon_session_match(dbg_rep->dbg_sid))
1006 lstcon_sesqry_stat_active(stat, 1);
1008 lstcon_sesqry_stat_busy(stat, 1);
1011 case LST_TRANS_TSBRUN:
1012 case LST_TRANS_TSBSTOP:
1013 bat_rep = &msg->msg_body.bat_reply;
1015 if (bat_rep->bar_status == 0) {
1016 lstcon_tsbop_stat_success(stat, 1);
1020 if (bat_rep->bar_status == EPERM &&
1021 trans->tas_opc == LST_TRANS_TSBSTOP) {
1022 lstcon_tsbop_stat_success(stat, 1);
1026 lstcon_tsbop_stat_failure(stat, 1);
1027 rc = bat_rep->bar_status;
1030 case LST_TRANS_TSBCLIQRY:
1031 case LST_TRANS_TSBSRVQRY:
1032 bat_rep = &msg->msg_body.bat_reply;
1034 if (bat_rep->bar_active != 0)
1035 lstcon_tsbqry_stat_run(stat, 1);
1037 lstcon_tsbqry_stat_idle(stat, 1);
1039 if (bat_rep->bar_status == 0)
1042 lstcon_tsbqry_stat_failure(stat, 1);
1043 rc = bat_rep->bar_status;
1046 case LST_TRANS_TSBCLIADD:
1047 case LST_TRANS_TSBSRVADD:
1048 test_rep = &msg->msg_body.tes_reply;
1050 if (test_rep->tsr_status == 0) {
1051 lstcon_tsbop_stat_success(stat, 1);
1055 lstcon_tsbop_stat_failure(stat, 1);
1056 rc = test_rep->tsr_status;
1059 case LST_TRANS_STATQRY:
1060 stat_rep = &msg->msg_body.stat_reply;
1062 if (stat_rep->str_status == 0) {
1063 lstcon_statqry_stat_success(stat, 1);
1067 lstcon_statqry_stat_failure(stat, 1);
1068 rc = stat_rep->str_status;
1075 if (stat->trs_fwk_errno == 0)
1076 stat->trs_fwk_errno = rc;
1080 lstcon_rpc_trans_ndlist(struct list_head *ndlist,
1081 struct list_head *translist, int transop,
1082 void *arg, lstcon_rpc_cond_func_t condition,
1083 struct lstcon_rpc_trans **transpp)
1085 struct lstcon_rpc_trans *trans;
1086 struct lstcon_ndlink *ndl;
1087 struct lstcon_node *nd;
1088 struct lstcon_rpc *rpc;
1092 /* Creating session RPG for list of nodes */
1094 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1096 CERROR("Can't create transaction %d: %d\n", transop, rc);
1100 feats = trans->tas_features;
1101 list_for_each_entry(ndl, ndlist, ndl_link) {
1102 rc = condition == NULL ? 1 :
1103 condition(transop, ndl->ndl_node, arg);
1109 CDEBUG(D_NET, "Condition error while creating RPC "
1110 " for transaction %d: %d\n", transop, rc);
1117 case LST_TRANS_SESNEW:
1118 case LST_TRANS_SESEND:
1119 rc = lstcon_sesrpc_prep(nd, transop, feats, &rpc);
1121 case LST_TRANS_SESQRY:
1122 case LST_TRANS_SESPING:
1123 rc = lstcon_dbgrpc_prep(nd, feats, &rpc);
1125 case LST_TRANS_TSBCLIADD:
1126 case LST_TRANS_TSBSRVADD:
1127 rc = lstcon_testrpc_prep(nd, transop, feats,
1128 (struct lstcon_test *)arg,
1131 case LST_TRANS_TSBRUN:
1132 case LST_TRANS_TSBSTOP:
1133 case LST_TRANS_TSBCLIQRY:
1134 case LST_TRANS_TSBSRVQRY:
1135 rc = lstcon_batrpc_prep(nd, transop, feats,
1136 (struct lstcon_tsb_hdr *)arg,
1139 case LST_TRANS_STATQRY:
1140 rc = lstcon_statrpc_prep(nd, feats, &rpc);
1148 CERROR("Failed to create RPC for transaction %s: %d\n",
1149 lstcon_rpc_trans_name(transop), rc);
1153 lstcon_rpc_trans_addreq(trans, rpc);
1161 lstcon_rpc_trans_destroy(trans);
1167 lstcon_rpc_pinger(void *arg)
1169 struct stt_timer *ptimer = arg;
1170 struct lstcon_rpc_trans *trans;
1171 struct lstcon_rpc *crpc;
1172 struct srpc_msg *rep;
1173 struct srpc_debug_reqst *drq;
1174 struct lstcon_ndlink *ndl;
1175 struct lstcon_node *nd;
1180 /* RPC pinger is a special case of transaction,
1181 * it's called by timer at 8 seconds interval.
1183 mutex_lock(&console_session.ses_mutex);
1185 if (console_session.ses_shutdown || console_session.ses_expired) {
1186 mutex_unlock(&console_session.ses_mutex);
1190 if (!console_session.ses_expired &&
1191 ktime_get_real_seconds() - console_session.ses_laststamp >
1192 (time64_t)console_session.ses_timeout)
1193 console_session.ses_expired = 1;
1195 trans = console_session.ses_ping;
1197 LASSERT(trans != NULL);
1199 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link) {
1202 if (console_session.ses_expired) {
1203 /* idle console, end session on all nodes */
1204 if (nd->nd_state != LST_NODE_ACTIVE)
1207 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND,
1208 trans->tas_features, &crpc);
1210 CERROR("Out of memory\n");
1214 lstcon_rpc_trans_addreq(trans, crpc);
1215 lstcon_rpc_post(crpc);
1220 crpc = &nd->nd_ping;
1222 if (crpc->crp_rpc != NULL) {
1223 LASSERT(crpc->crp_trans == trans);
1224 LASSERT(!list_empty(&crpc->crp_link));
1226 spin_lock(&crpc->crp_rpc->crpc_lock);
1228 LASSERT(crpc->crp_posted);
1230 if (!crpc->crp_finished) {
1232 spin_unlock(&crpc->crp_rpc->crpc_lock);
1236 spin_unlock(&crpc->crp_rpc->crpc_lock);
1238 lstcon_rpc_get_reply(crpc, &rep);
1240 list_del_init(&crpc->crp_link);
1242 lstcon_rpc_put(crpc);
1245 if (nd->nd_state != LST_NODE_ACTIVE)
1248 intv = div_u64(ktime_ms_delta(ktime_get(), nd->nd_stamp),
1250 if (intv < nd->nd_timeout / 2)
1253 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
1254 trans->tas_features, 0, 0, 1, crpc);
1256 CERROR("Out of memory\n");
1260 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1262 drq->dbg_sid = console_session.ses_id;
1265 lstcon_rpc_trans_addreq(trans, crpc);
1266 lstcon_rpc_post(crpc);
1271 if (console_session.ses_expired) {
1272 mutex_unlock(&console_session.ses_mutex);
1276 CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1278 ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1279 stt_add_timer(ptimer);
1281 mutex_unlock(&console_session.ses_mutex);
1285 lstcon_rpc_pinger_start(void)
1287 struct stt_timer *ptimer;
1290 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1291 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);
1293 rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1294 &console_session.ses_ping);
1296 CERROR("Failed to create console pinger\n");
1300 ptimer = &console_session.ses_ping_timer;
1301 ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1303 stt_add_timer(ptimer);
1309 lstcon_rpc_pinger_stop(void)
1311 LASSERT (console_session.ses_shutdown);
1313 stt_del_timer(&console_session.ses_ping_timer);
1315 lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1316 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1317 lstcon_rpc_trans_destroy(console_session.ses_ping);
1319 memset(lstcon_trans_stat(), 0, sizeof(struct lstcon_trans_stat));
1321 console_session.ses_ping = NULL;
1325 lstcon_rpc_cleanup_wait(void)
1327 struct lstcon_rpc_trans *trans;
1328 struct lstcon_rpc *crpc;
1329 struct list_head *pacer;
1332 /* Called with hold of global mutex */
1334 LASSERT(console_session.ses_shutdown);
1336 while (!list_empty(&console_session.ses_trans_list)) {
1337 list_for_each(pacer, &console_session.ses_trans_list) {
1338 trans = list_entry(pacer, struct lstcon_rpc_trans,
1341 CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1342 lstcon_rpc_trans_name(trans->tas_opc));
1344 wake_up(&trans->tas_waitq);
1347 mutex_unlock(&console_session.ses_mutex);
1349 CWARN("Session is shutting down, "
1350 "waiting for termination of transactions\n");
1351 schedule_timeout_uninterruptible(cfs_time_seconds(1));
1353 mutex_lock(&console_session.ses_mutex);
1356 spin_lock(&console_session.ses_rpc_lock);
1358 lst_wait_until((atomic_read(&console_session.ses_rpc_counter) == 0),
1359 console_session.ses_rpc_lock,
1360 "Network is not accessable or target is down, "
1361 "waiting for %d console RPCs to being recycled\n",
1362 atomic_read(&console_session.ses_rpc_counter));
1364 list_splice_init(&console_session.ses_rpc_freelist, &zlist);
1366 spin_unlock(&console_session.ses_rpc_lock);
1368 while (!list_empty(&zlist)) {
1369 crpc = list_entry(zlist.next, struct lstcon_rpc, crp_link);
1371 list_del(&crpc->crp_link);
1372 LIBCFS_FREE(crpc, sizeof(*crpc));
1377 lstcon_rpc_module_init(void)
1379 INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1380 console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1381 console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1383 console_session.ses_ping = NULL;
1385 spin_lock_init(&console_session.ses_rpc_lock);
1386 atomic_set(&console_session.ses_rpc_counter, 0);
1387 INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1393 lstcon_rpc_module_fini(void)
1395 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1396 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);