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_first_entry(&console_session.ses_rpc_freelist,
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.ses_stamp = console_session.ses_id.ses_stamp;
604 msrq->mksn_sid.ses_nid =
605 lnet_nid_to_nid4(&console_session.ses_id.ses_nid);
606 msrq->mksn_force = console_session.ses_force;
607 strlcpy(msrq->mksn_name, console_session.ses_name,
608 sizeof(msrq->mksn_name));
611 case LST_TRANS_SESEND:
612 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION,
617 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
618 rsrq->rmsn_sid.ses_stamp = console_session.ses_id.ses_stamp;
619 rsrq->rmsn_sid.ses_nid =
620 lnet_nid_to_nid4(&console_session.ses_id.ses_nid);
631 lstcon_dbgrpc_prep(struct lstcon_node *nd, unsigned int feats,
632 struct lstcon_rpc **crpc)
634 struct srpc_debug_reqst *drq;
637 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, feats, 0, 0, crpc);
641 drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
643 drq->dbg_sid.ses_stamp = console_session.ses_id.ses_stamp;
644 drq->dbg_sid.ses_nid =
645 lnet_nid_to_nid4(&console_session.ses_id.ses_nid);
652 lstcon_batrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
653 struct lstcon_tsb_hdr *tsb, struct lstcon_rpc **crpc)
655 struct lstcon_batch *batch;
656 struct srpc_batch_reqst *brq;
659 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, feats, 0, 0, crpc);
663 brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
665 brq->bar_sid.ses_stamp = console_session.ses_id.ses_stamp;
666 brq->bar_sid.ses_nid =
667 lnet_nid_to_nid4(&console_session.ses_id.ses_nid);
668 brq->bar_bid = tsb->tsb_id;
669 brq->bar_testidx = tsb->tsb_index;
670 brq->bar_opc = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
671 (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP:
672 SRPC_BATCH_OPC_QUERY);
674 if (transop != LST_TRANS_TSBRUN &&
675 transop != LST_TRANS_TSBSTOP)
678 LASSERT (tsb->tsb_index == 0);
680 batch = (struct lstcon_batch *)tsb;
681 brq->bar_arg = batch->bat_arg;
687 lstcon_statrpc_prep(struct lstcon_node *nd, unsigned int feats,
688 struct lstcon_rpc **crpc)
690 struct srpc_stat_reqst *srq;
693 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_QUERY_STAT, feats, 0, 0, crpc);
697 srq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.stat_reqst;
700 srq->str_sid.ses_stamp = console_session.ses_id.ses_stamp;
701 srq->str_sid.ses_nid =
702 lnet_nid_to_nid4(&console_session.ses_id.ses_nid);
703 srq->str_type = 0; /* XXX remove it */
708 static struct lnet_process_id_packed *
709 lstcon_next_id(int idx, int nkiov, struct bio_vec *kiov)
711 struct lnet_process_id_packed *pid;
714 i = idx / SFW_ID_PER_PAGE;
718 pid = (struct lnet_process_id_packed *)page_address(kiov[i].bv_page);
720 return &pid[idx % SFW_ID_PER_PAGE];
724 lstcon_dstnodes_prep(struct lstcon_group *grp, int idx,
725 int dist, int span, int nkiov, struct bio_vec *kiov)
727 struct lnet_process_id_packed *pid;
728 struct lstcon_ndlink *ndl;
729 struct lstcon_node *nd;
736 LASSERT (grp->grp_nnode >= 1);
738 if (span > grp->grp_nnode)
741 start = ((idx / dist) * span) % grp->grp_nnode;
742 end = ((idx / dist) * span + span - 1) % grp->grp_nnode;
744 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
751 if (i > (end >= start ? end : grp->grp_nnode))
754 pid = lstcon_next_id((i - start), nkiov, kiov);
755 pid->nid = nd->nd_id.nid;
756 pid->pid = nd->nd_id.pid;
760 if (start <= end) /* done */
763 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
764 if (i > grp->grp_nnode + end)
768 pid = lstcon_next_id((i - start), nkiov, kiov);
769 pid->nid = nd->nd_id.nid;
770 pid->pid = nd->nd_id.pid;
778 lstcon_pingrpc_prep(struct lst_test_ping_param *param,
779 struct srpc_test_reqst *req)
781 struct test_ping_req *prq = &req->tsr_u.ping;
784 prq->png_size = param->png_size;
785 prq->png_flags = param->png_flags;
795 lstcon_bulkrpc_v0_prep(struct lst_test_bulk_param *param,
796 struct srpc_test_reqst *req)
798 struct test_bulk_req *brq = &req->tsr_u.bulk_v0;
800 brq->blk_opc = param->blk_opc;
801 brq->blk_npg = (param->blk_size + PAGE_SIZE - 1) /
803 brq->blk_flags = param->blk_flags;
809 lstcon_bulkrpc_v1_prep(struct lst_test_bulk_param *param, bool is_client,
810 struct srpc_test_reqst *req)
812 struct test_bulk_req_v1 *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 = is_client ? param->blk_cli_off : param->blk_srv_off;
823 lstcon_testrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
824 struct lstcon_test *test, struct lstcon_rpc **crpc)
826 struct lstcon_group *sgrp = test->tes_src_grp;
827 struct lstcon_group *dgrp = test->tes_dst_grp;
828 struct srpc_test_reqst *trq;
829 struct srpc_bulk *bulk;
835 if (transop == LST_TRANS_TSBCLIADD) {
836 npg = sfw_id_pages(test->tes_span);
837 nob = (feats & LST_FEAT_BULK_LEN) == 0 ?
839 sizeof(struct lnet_process_id_packed) * 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_SIZE : min_t(int, nob, PAGE_SIZE);
868 bulk->bk_iovs[i].bv_offset = 0;
869 bulk->bk_iovs[i].bv_len = len;
870 bulk->bk_iovs[i].bv_page =
871 alloc_page(GFP_KERNEL);
873 if (bulk->bk_iovs[i].bv_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.ses_stamp = console_session.ses_id.ses_stamp;
898 trq->tsr_sid.ses_nid =
899 lnet_nid_to_nid4(&console_session.ses_id.ses_nid);
900 trq->tsr_bid = test->tes_hdr.tsb_id;
901 trq->tsr_concur = test->tes_concur;
902 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
903 trq->tsr_stop_onerr = !!test->tes_stop_onerr;
905 switch (test->tes_type) {
906 case LST_TEST_PING: {
907 struct lst_test_ping_param *data = NULL;
909 trq->tsr_service = SRPC_SERVICE_PING;
910 if (test->tes_paramlen)
911 data = ((struct lst_test_ping_param *)
912 &test->tes_param[0]);
914 rc = lstcon_pingrpc_prep(data, trq);
918 trq->tsr_service = SRPC_SERVICE_BRW;
919 if ((feats & LST_FEAT_BULK_LEN) == 0) {
920 rc = lstcon_bulkrpc_v0_prep((struct lst_test_bulk_param *)
921 &test->tes_param[0], trq);
923 rc = lstcon_bulkrpc_v1_prep((struct lst_test_bulk_param *)
925 trq->tsr_is_client, trq);
938 lstcon_sesnew_stat_reply(struct lstcon_rpc_trans *trans,
939 struct lstcon_node *nd, struct srpc_msg *reply)
941 struct srpc_mksn_reply *mksn_rep = &reply->msg_body.mksn_reply;
942 int status = mksn_rep->mksn_status;
945 (reply->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
946 mksn_rep->mksn_status = EPROTO;
950 if (status == EPROTO) {
951 CNETERR("session protocol error from %s: %u\n",
952 libcfs_nid2str(nd->nd_id.nid),
953 reply->msg_ses_feats);
959 if (!trans->tas_feats_updated) {
960 spin_lock(&console_session.ses_rpc_lock);
961 if (!trans->tas_feats_updated) { /* recheck with lock */
962 trans->tas_feats_updated = 1;
963 trans->tas_features = reply->msg_ses_feats;
965 spin_unlock(&console_session.ses_rpc_lock);
968 if (reply->msg_ses_feats != trans->tas_features) {
969 CNETERR("Framework features %x from %s is different with "
970 "features on this transaction: %x\n",
971 reply->msg_ses_feats, libcfs_nid2str(nd->nd_id.nid),
972 trans->tas_features);
973 status = mksn_rep->mksn_status = EPROTO;
977 /* session timeout on remote node */
978 nd->nd_timeout = mksn_rep->mksn_timeout;
985 lstcon_rpc_stat_reply(struct lstcon_rpc_trans *trans, struct srpc_msg *msg,
986 struct lstcon_node *nd, struct lstcon_trans_stat *stat)
988 struct srpc_rmsn_reply *rmsn_rep;
989 struct srpc_debug_reply *dbg_rep;
990 struct srpc_batch_reply *bat_rep;
991 struct srpc_test_reply *test_rep;
992 struct srpc_stat_reply *stat_rep;
995 switch (trans->tas_opc) {
996 case LST_TRANS_SESNEW:
997 rc = lstcon_sesnew_stat_reply(trans, nd, msg);
999 lstcon_sesop_stat_success(stat, 1);
1003 lstcon_sesop_stat_failure(stat, 1);
1006 case LST_TRANS_SESEND:
1007 rmsn_rep = &msg->msg_body.rmsn_reply;
1008 /* ESRCH is not an error for end session */
1009 if (rmsn_rep->rmsn_status == 0 ||
1010 rmsn_rep->rmsn_status == ESRCH) {
1011 lstcon_sesop_stat_success(stat, 1);
1015 lstcon_sesop_stat_failure(stat, 1);
1016 rc = rmsn_rep->rmsn_status;
1019 case LST_TRANS_SESQRY:
1020 case LST_TRANS_SESPING:
1021 dbg_rep = &msg->msg_body.dbg_reply;
1023 if (dbg_rep->dbg_status == ESRCH) {
1024 lstcon_sesqry_stat_unknown(stat, 1);
1028 if (lstcon_session_match(dbg_rep->dbg_sid))
1029 lstcon_sesqry_stat_active(stat, 1);
1031 lstcon_sesqry_stat_busy(stat, 1);
1034 case LST_TRANS_TSBRUN:
1035 case LST_TRANS_TSBSTOP:
1036 bat_rep = &msg->msg_body.bat_reply;
1038 if (bat_rep->bar_status == 0) {
1039 lstcon_tsbop_stat_success(stat, 1);
1043 if (bat_rep->bar_status == EPERM &&
1044 trans->tas_opc == LST_TRANS_TSBSTOP) {
1045 lstcon_tsbop_stat_success(stat, 1);
1049 lstcon_tsbop_stat_failure(stat, 1);
1050 rc = bat_rep->bar_status;
1053 case LST_TRANS_TSBCLIQRY:
1054 case LST_TRANS_TSBSRVQRY:
1055 bat_rep = &msg->msg_body.bat_reply;
1057 if (bat_rep->bar_active != 0)
1058 lstcon_tsbqry_stat_run(stat, 1);
1060 lstcon_tsbqry_stat_idle(stat, 1);
1062 if (bat_rep->bar_status == 0)
1065 lstcon_tsbqry_stat_failure(stat, 1);
1066 rc = bat_rep->bar_status;
1069 case LST_TRANS_TSBCLIADD:
1070 case LST_TRANS_TSBSRVADD:
1071 test_rep = &msg->msg_body.tes_reply;
1073 if (test_rep->tsr_status == 0) {
1074 lstcon_tsbop_stat_success(stat, 1);
1078 lstcon_tsbop_stat_failure(stat, 1);
1079 rc = test_rep->tsr_status;
1082 case LST_TRANS_STATQRY:
1083 stat_rep = &msg->msg_body.stat_reply;
1085 if (stat_rep->str_status == 0) {
1086 lstcon_statqry_stat_success(stat, 1);
1090 lstcon_statqry_stat_failure(stat, 1);
1091 rc = stat_rep->str_status;
1098 if (stat->trs_fwk_errno == 0)
1099 stat->trs_fwk_errno = rc;
1103 lstcon_rpc_trans_ndlist(struct list_head *ndlist,
1104 struct list_head *translist, int transop,
1105 void *arg, lstcon_rpc_cond_func_t condition,
1106 struct lstcon_rpc_trans **transpp)
1108 struct lstcon_rpc_trans *trans;
1109 struct lstcon_ndlink *ndl;
1110 struct lstcon_node *nd;
1111 struct lstcon_rpc *rpc;
1115 /* Creating session RPG for list of nodes */
1117 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1119 CERROR("Can't create transaction %d: %d\n", transop, rc);
1123 feats = trans->tas_features;
1124 list_for_each_entry(ndl, ndlist, ndl_link) {
1125 rc = condition == NULL ? 1 :
1126 condition(transop, ndl->ndl_node, arg);
1132 CDEBUG(D_NET, "Condition error while creating RPC "
1133 " for transaction %d: %d\n", transop, rc);
1140 case LST_TRANS_SESNEW:
1141 case LST_TRANS_SESEND:
1142 rc = lstcon_sesrpc_prep(nd, transop, feats, &rpc);
1144 case LST_TRANS_SESQRY:
1145 case LST_TRANS_SESPING:
1146 rc = lstcon_dbgrpc_prep(nd, feats, &rpc);
1148 case LST_TRANS_TSBCLIADD:
1149 case LST_TRANS_TSBSRVADD:
1150 rc = lstcon_testrpc_prep(nd, transop, feats,
1151 (struct lstcon_test *)arg,
1154 case LST_TRANS_TSBRUN:
1155 case LST_TRANS_TSBSTOP:
1156 case LST_TRANS_TSBCLIQRY:
1157 case LST_TRANS_TSBSRVQRY:
1158 rc = lstcon_batrpc_prep(nd, transop, feats,
1159 (struct lstcon_tsb_hdr *)arg,
1162 case LST_TRANS_STATQRY:
1163 rc = lstcon_statrpc_prep(nd, feats, &rpc);
1171 CERROR("Failed to create RPC for transaction %s: %d\n",
1172 lstcon_rpc_trans_name(transop), rc);
1176 lstcon_rpc_trans_addreq(trans, rpc);
1184 lstcon_rpc_trans_destroy(trans);
1190 lstcon_rpc_pinger(void *arg)
1192 struct stt_timer *ptimer = arg;
1193 struct lstcon_rpc_trans *trans;
1194 struct lstcon_rpc *crpc;
1195 struct srpc_msg *rep;
1196 struct srpc_debug_reqst *drq;
1197 struct lstcon_ndlink *ndl;
1198 struct lstcon_node *nd;
1203 /* RPC pinger is a special case of transaction,
1204 * it's called by timer at 8 seconds interval.
1206 mutex_lock(&console_session.ses_mutex);
1208 if (console_session.ses_shutdown || console_session.ses_expired) {
1209 mutex_unlock(&console_session.ses_mutex);
1213 if (!console_session.ses_expired &&
1214 ktime_get_real_seconds() - console_session.ses_laststamp >
1215 (time64_t)console_session.ses_timeout)
1216 console_session.ses_expired = 1;
1218 trans = console_session.ses_ping;
1220 LASSERT(trans != NULL);
1222 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link) {
1225 if (console_session.ses_expired) {
1226 /* idle console, end session on all nodes */
1227 if (nd->nd_state != LST_NODE_ACTIVE)
1230 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND,
1231 trans->tas_features, &crpc);
1233 CERROR("Out of memory\n");
1237 lstcon_rpc_trans_addreq(trans, crpc);
1238 lstcon_rpc_post(crpc);
1243 crpc = &nd->nd_ping;
1245 if (crpc->crp_rpc != NULL) {
1246 LASSERT(crpc->crp_trans == trans);
1247 LASSERT(!list_empty(&crpc->crp_link));
1249 spin_lock(&crpc->crp_rpc->crpc_lock);
1251 LASSERT(crpc->crp_posted);
1253 if (!crpc->crp_finished) {
1255 spin_unlock(&crpc->crp_rpc->crpc_lock);
1259 spin_unlock(&crpc->crp_rpc->crpc_lock);
1261 lstcon_rpc_get_reply(crpc, &rep);
1263 list_del_init(&crpc->crp_link);
1265 lstcon_rpc_put(crpc);
1268 if (nd->nd_state != LST_NODE_ACTIVE)
1271 intv = div_u64(ktime_ms_delta(ktime_get(), nd->nd_stamp),
1273 if (intv < nd->nd_timeout / 2)
1276 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
1277 trans->tas_features, 0, 0, 1, crpc);
1279 CERROR("Out of memory\n");
1283 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1285 drq->dbg_sid.ses_stamp = console_session.ses_id.ses_stamp;
1286 drq->dbg_sid.ses_nid =
1287 lnet_nid_to_nid4(&console_session.ses_id.ses_nid);
1290 lstcon_rpc_trans_addreq(trans, crpc);
1291 lstcon_rpc_post(crpc);
1296 if (console_session.ses_expired) {
1297 mutex_unlock(&console_session.ses_mutex);
1301 CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1303 ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1304 stt_add_timer(ptimer);
1306 mutex_unlock(&console_session.ses_mutex);
1310 lstcon_rpc_pinger_start(void)
1312 struct stt_timer *ptimer;
1315 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1316 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);
1318 rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1319 &console_session.ses_ping);
1321 CERROR("Failed to create console pinger\n");
1325 ptimer = &console_session.ses_ping_timer;
1326 ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1328 stt_add_timer(ptimer);
1334 lstcon_rpc_pinger_stop(void)
1336 LASSERT (console_session.ses_shutdown);
1338 stt_del_timer(&console_session.ses_ping_timer);
1340 lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1341 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1342 lstcon_rpc_trans_destroy(console_session.ses_ping);
1344 memset(lstcon_trans_stat(), 0, sizeof(struct lstcon_trans_stat));
1346 console_session.ses_ping = NULL;
1350 lstcon_rpc_cleanup_wait(void)
1352 struct lstcon_rpc_trans *trans;
1353 struct lstcon_rpc *crpc;
1354 struct list_head *pacer;
1357 /* Called with hold of global mutex */
1359 LASSERT(console_session.ses_shutdown);
1361 while (!list_empty(&console_session.ses_trans_list)) {
1362 list_for_each(pacer, &console_session.ses_trans_list) {
1363 trans = list_entry(pacer, struct lstcon_rpc_trans,
1366 CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1367 lstcon_rpc_trans_name(trans->tas_opc));
1369 wake_up(&trans->tas_waitq);
1372 mutex_unlock(&console_session.ses_mutex);
1374 CWARN("Session is shutting down, "
1375 "waiting for termination of transactions\n");
1376 schedule_timeout_uninterruptible(cfs_time_seconds(1));
1378 mutex_lock(&console_session.ses_mutex);
1381 spin_lock(&console_session.ses_rpc_lock);
1383 lst_wait_until((atomic_read(&console_session.ses_rpc_counter) == 0),
1384 console_session.ses_rpc_lock,
1385 "Network is not accessable or target is down, "
1386 "waiting for %d console RPCs to being recycled\n",
1387 atomic_read(&console_session.ses_rpc_counter));
1389 list_splice_init(&console_session.ses_rpc_freelist, &zlist);
1391 spin_unlock(&console_session.ses_rpc_lock);
1393 while (!list_empty(&zlist)) {
1394 crpc = list_first_entry(&zlist, struct lstcon_rpc, crp_link);
1396 list_del(&crpc->crp_link);
1397 LIBCFS_FREE(crpc, sizeof(*crpc));
1402 lstcon_rpc_module_init(void)
1404 INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1405 console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1406 console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1408 console_session.ses_ping = NULL;
1410 spin_lock_init(&console_session.ses_rpc_lock);
1411 atomic_set(&console_session.ses_rpc_counter, 0);
1412 INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1418 lstcon_rpc_module_fini(void)
1420 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1421 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);