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.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;
783 prq->png_size = param->png_size;
784 prq->png_flags = param->png_flags;
790 lstcon_bulkrpc_v0_prep(struct lst_test_bulk_param *param,
791 struct srpc_test_reqst *req)
793 struct test_bulk_req *brq = &req->tsr_u.bulk_v0;
795 brq->blk_opc = param->blk_opc;
796 brq->blk_npg = (param->blk_size + PAGE_SIZE - 1) /
798 brq->blk_flags = param->blk_flags;
804 lstcon_bulkrpc_v1_prep(struct lst_test_bulk_param *param, bool is_client,
805 struct srpc_test_reqst *req)
807 struct test_bulk_req_v1 *brq = &req->tsr_u.bulk_v1;
809 brq->blk_opc = param->blk_opc;
810 brq->blk_flags = param->blk_flags;
811 brq->blk_len = param->blk_size;
812 brq->blk_offset = is_client ? param->blk_cli_off : param->blk_srv_off;
818 lstcon_testrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
819 struct lstcon_test *test, struct lstcon_rpc **crpc)
821 struct lstcon_group *sgrp = test->tes_src_grp;
822 struct lstcon_group *dgrp = test->tes_dst_grp;
823 struct srpc_test_reqst *trq;
824 struct srpc_bulk *bulk;
830 if (transop == LST_TRANS_TSBCLIADD) {
831 npg = sfw_id_pages(test->tes_span);
832 nob = (feats & LST_FEAT_BULK_LEN) == 0 ?
834 sizeof(struct lnet_process_id_packed) * test->tes_span;
837 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc);
841 trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
843 if (transop == LST_TRANS_TSBSRVADD) {
844 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
845 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
846 int nmax = (ndist + nspan - 1) / nspan;
849 trq->tsr_loop = nmax * test->tes_dist * test->tes_concur;
852 bulk = &(*crpc)->crp_rpc->crpc_bulk;
854 for (i = 0; i < npg; i++) {
859 len = (feats & LST_FEAT_BULK_LEN) == 0 ?
860 PAGE_SIZE : min_t(int, nob, PAGE_SIZE);
863 bulk->bk_iovs[i].bv_offset = 0;
864 bulk->bk_iovs[i].bv_len = len;
865 bulk->bk_iovs[i].bv_page =
866 alloc_page(GFP_KERNEL);
868 if (bulk->bk_iovs[i].bv_page == NULL) {
869 lstcon_rpc_put(*crpc);
876 LASSERT (transop == LST_TRANS_TSBCLIADD);
878 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
882 npg, &bulk->bk_iovs[0]);
884 lstcon_rpc_put(*crpc);
888 trq->tsr_ndest = test->tes_span;
889 trq->tsr_loop = test->tes_loop;
892 trq->tsr_sid.ses_stamp = console_session.ses_id.ses_stamp;
893 trq->tsr_sid.ses_nid =
894 lnet_nid_to_nid4(&console_session.ses_id.ses_nid);
895 trq->tsr_bid = test->tes_hdr.tsb_id;
896 trq->tsr_concur = test->tes_concur;
897 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
898 trq->tsr_stop_onerr = !!test->tes_stop_onerr;
900 switch (test->tes_type) {
902 trq->tsr_service = SRPC_SERVICE_PING;
903 rc = lstcon_pingrpc_prep((struct lst_test_ping_param *)
904 &test->tes_param[0], trq);
908 trq->tsr_service = SRPC_SERVICE_BRW;
909 if ((feats & LST_FEAT_BULK_LEN) == 0) {
910 rc = lstcon_bulkrpc_v0_prep((struct lst_test_bulk_param *)
911 &test->tes_param[0], trq);
913 rc = lstcon_bulkrpc_v1_prep((struct lst_test_bulk_param *)
915 trq->tsr_is_client, trq);
928 lstcon_sesnew_stat_reply(struct lstcon_rpc_trans *trans,
929 struct lstcon_node *nd, struct srpc_msg *reply)
931 struct srpc_mksn_reply *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 spin_lock(&console_session.ses_rpc_lock);
951 if (!trans->tas_feats_updated) { /* recheck with lock */
952 trans->tas_feats_updated = 1;
953 trans->tas_features = reply->msg_ses_feats;
955 spin_unlock(&console_session.ses_rpc_lock);
958 if (reply->msg_ses_feats != trans->tas_features) {
959 CNETERR("Framework features %x from %s is different with "
960 "features on this transaction: %x\n",
961 reply->msg_ses_feats, libcfs_nid2str(nd->nd_id.nid),
962 trans->tas_features);
963 status = mksn_rep->mksn_status = EPROTO;
967 /* session timeout on remote node */
968 nd->nd_timeout = mksn_rep->mksn_timeout;
975 lstcon_rpc_stat_reply(struct lstcon_rpc_trans *trans, struct srpc_msg *msg,
976 struct lstcon_node *nd, struct lstcon_trans_stat *stat)
978 struct srpc_rmsn_reply *rmsn_rep;
979 struct srpc_debug_reply *dbg_rep;
980 struct srpc_batch_reply *bat_rep;
981 struct srpc_test_reply *test_rep;
982 struct srpc_stat_reply *stat_rep;
985 switch (trans->tas_opc) {
986 case LST_TRANS_SESNEW:
987 rc = lstcon_sesnew_stat_reply(trans, nd, msg);
989 lstcon_sesop_stat_success(stat, 1);
993 lstcon_sesop_stat_failure(stat, 1);
996 case LST_TRANS_SESEND:
997 rmsn_rep = &msg->msg_body.rmsn_reply;
998 /* ESRCH is not an error for end session */
999 if (rmsn_rep->rmsn_status == 0 ||
1000 rmsn_rep->rmsn_status == ESRCH) {
1001 lstcon_sesop_stat_success(stat, 1);
1005 lstcon_sesop_stat_failure(stat, 1);
1006 rc = rmsn_rep->rmsn_status;
1009 case LST_TRANS_SESQRY:
1010 case LST_TRANS_SESPING:
1011 dbg_rep = &msg->msg_body.dbg_reply;
1013 if (dbg_rep->dbg_status == ESRCH) {
1014 lstcon_sesqry_stat_unknown(stat, 1);
1018 if (lstcon_session_match(dbg_rep->dbg_sid))
1019 lstcon_sesqry_stat_active(stat, 1);
1021 lstcon_sesqry_stat_busy(stat, 1);
1024 case LST_TRANS_TSBRUN:
1025 case LST_TRANS_TSBSTOP:
1026 bat_rep = &msg->msg_body.bat_reply;
1028 if (bat_rep->bar_status == 0) {
1029 lstcon_tsbop_stat_success(stat, 1);
1033 if (bat_rep->bar_status == EPERM &&
1034 trans->tas_opc == LST_TRANS_TSBSTOP) {
1035 lstcon_tsbop_stat_success(stat, 1);
1039 lstcon_tsbop_stat_failure(stat, 1);
1040 rc = bat_rep->bar_status;
1043 case LST_TRANS_TSBCLIQRY:
1044 case LST_TRANS_TSBSRVQRY:
1045 bat_rep = &msg->msg_body.bat_reply;
1047 if (bat_rep->bar_active != 0)
1048 lstcon_tsbqry_stat_run(stat, 1);
1050 lstcon_tsbqry_stat_idle(stat, 1);
1052 if (bat_rep->bar_status == 0)
1055 lstcon_tsbqry_stat_failure(stat, 1);
1056 rc = bat_rep->bar_status;
1059 case LST_TRANS_TSBCLIADD:
1060 case LST_TRANS_TSBSRVADD:
1061 test_rep = &msg->msg_body.tes_reply;
1063 if (test_rep->tsr_status == 0) {
1064 lstcon_tsbop_stat_success(stat, 1);
1068 lstcon_tsbop_stat_failure(stat, 1);
1069 rc = test_rep->tsr_status;
1072 case LST_TRANS_STATQRY:
1073 stat_rep = &msg->msg_body.stat_reply;
1075 if (stat_rep->str_status == 0) {
1076 lstcon_statqry_stat_success(stat, 1);
1080 lstcon_statqry_stat_failure(stat, 1);
1081 rc = stat_rep->str_status;
1088 if (stat->trs_fwk_errno == 0)
1089 stat->trs_fwk_errno = rc;
1093 lstcon_rpc_trans_ndlist(struct list_head *ndlist,
1094 struct list_head *translist, int transop,
1095 void *arg, lstcon_rpc_cond_func_t condition,
1096 struct lstcon_rpc_trans **transpp)
1098 struct lstcon_rpc_trans *trans;
1099 struct lstcon_ndlink *ndl;
1100 struct lstcon_node *nd;
1101 struct lstcon_rpc *rpc;
1105 /* Creating session RPG for list of nodes */
1107 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1109 CERROR("Can't create transaction %d: %d\n", transop, rc);
1113 feats = trans->tas_features;
1114 list_for_each_entry(ndl, ndlist, ndl_link) {
1115 rc = condition == NULL ? 1 :
1116 condition(transop, ndl->ndl_node, arg);
1122 CDEBUG(D_NET, "Condition error while creating RPC "
1123 " for transaction %d: %d\n", transop, rc);
1130 case LST_TRANS_SESNEW:
1131 case LST_TRANS_SESEND:
1132 rc = lstcon_sesrpc_prep(nd, transop, feats, &rpc);
1134 case LST_TRANS_SESQRY:
1135 case LST_TRANS_SESPING:
1136 rc = lstcon_dbgrpc_prep(nd, feats, &rpc);
1138 case LST_TRANS_TSBCLIADD:
1139 case LST_TRANS_TSBSRVADD:
1140 rc = lstcon_testrpc_prep(nd, transop, feats,
1141 (struct lstcon_test *)arg,
1144 case LST_TRANS_TSBRUN:
1145 case LST_TRANS_TSBSTOP:
1146 case LST_TRANS_TSBCLIQRY:
1147 case LST_TRANS_TSBSRVQRY:
1148 rc = lstcon_batrpc_prep(nd, transop, feats,
1149 (struct lstcon_tsb_hdr *)arg,
1152 case LST_TRANS_STATQRY:
1153 rc = lstcon_statrpc_prep(nd, feats, &rpc);
1161 CERROR("Failed to create RPC for transaction %s: %d\n",
1162 lstcon_rpc_trans_name(transop), rc);
1166 lstcon_rpc_trans_addreq(trans, rpc);
1174 lstcon_rpc_trans_destroy(trans);
1180 lstcon_rpc_pinger(void *arg)
1182 struct stt_timer *ptimer = arg;
1183 struct lstcon_rpc_trans *trans;
1184 struct lstcon_rpc *crpc;
1185 struct srpc_msg *rep;
1186 struct srpc_debug_reqst *drq;
1187 struct lstcon_ndlink *ndl;
1188 struct lstcon_node *nd;
1193 /* RPC pinger is a special case of transaction,
1194 * it's called by timer at 8 seconds interval.
1196 mutex_lock(&console_session.ses_mutex);
1198 if (console_session.ses_shutdown || console_session.ses_expired) {
1199 mutex_unlock(&console_session.ses_mutex);
1203 if (!console_session.ses_expired &&
1204 ktime_get_real_seconds() - console_session.ses_laststamp >
1205 (time64_t)console_session.ses_timeout)
1206 console_session.ses_expired = 1;
1208 trans = console_session.ses_ping;
1210 LASSERT(trans != NULL);
1212 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link) {
1215 if (console_session.ses_expired) {
1216 /* idle console, end session on all nodes */
1217 if (nd->nd_state != LST_NODE_ACTIVE)
1220 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND,
1221 trans->tas_features, &crpc);
1223 CERROR("Out of memory\n");
1227 lstcon_rpc_trans_addreq(trans, crpc);
1228 lstcon_rpc_post(crpc);
1233 crpc = &nd->nd_ping;
1235 if (crpc->crp_rpc != NULL) {
1236 LASSERT(crpc->crp_trans == trans);
1237 LASSERT(!list_empty(&crpc->crp_link));
1239 spin_lock(&crpc->crp_rpc->crpc_lock);
1241 LASSERT(crpc->crp_posted);
1243 if (!crpc->crp_finished) {
1245 spin_unlock(&crpc->crp_rpc->crpc_lock);
1249 spin_unlock(&crpc->crp_rpc->crpc_lock);
1251 lstcon_rpc_get_reply(crpc, &rep);
1253 list_del_init(&crpc->crp_link);
1255 lstcon_rpc_put(crpc);
1258 if (nd->nd_state != LST_NODE_ACTIVE)
1261 intv = div_u64(ktime_ms_delta(ktime_get(), nd->nd_stamp),
1263 if (intv < nd->nd_timeout / 2)
1266 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
1267 trans->tas_features, 0, 0, 1, crpc);
1269 CERROR("Out of memory\n");
1273 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1275 drq->dbg_sid.ses_stamp = console_session.ses_id.ses_stamp;
1276 drq->dbg_sid.ses_nid =
1277 lnet_nid_to_nid4(&console_session.ses_id.ses_nid);
1280 lstcon_rpc_trans_addreq(trans, crpc);
1281 lstcon_rpc_post(crpc);
1286 if (console_session.ses_expired) {
1287 mutex_unlock(&console_session.ses_mutex);
1291 CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1293 ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1294 stt_add_timer(ptimer);
1296 mutex_unlock(&console_session.ses_mutex);
1300 lstcon_rpc_pinger_start(void)
1302 struct stt_timer *ptimer;
1305 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1306 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);
1308 rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1309 &console_session.ses_ping);
1311 CERROR("Failed to create console pinger\n");
1315 ptimer = &console_session.ses_ping_timer;
1316 ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1318 stt_add_timer(ptimer);
1324 lstcon_rpc_pinger_stop(void)
1326 LASSERT (console_session.ses_shutdown);
1328 stt_del_timer(&console_session.ses_ping_timer);
1330 lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1331 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1332 lstcon_rpc_trans_destroy(console_session.ses_ping);
1334 memset(lstcon_trans_stat(), 0, sizeof(struct lstcon_trans_stat));
1336 console_session.ses_ping = NULL;
1340 lstcon_rpc_cleanup_wait(void)
1342 struct lstcon_rpc_trans *trans;
1343 struct lstcon_rpc *crpc;
1344 struct list_head *pacer;
1347 /* Called with hold of global mutex */
1349 LASSERT(console_session.ses_shutdown);
1351 while (!list_empty(&console_session.ses_trans_list)) {
1352 list_for_each(pacer, &console_session.ses_trans_list) {
1353 trans = list_entry(pacer, struct lstcon_rpc_trans,
1356 CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1357 lstcon_rpc_trans_name(trans->tas_opc));
1359 wake_up(&trans->tas_waitq);
1362 mutex_unlock(&console_session.ses_mutex);
1364 CWARN("Session is shutting down, "
1365 "waiting for termination of transactions\n");
1366 schedule_timeout_uninterruptible(cfs_time_seconds(1));
1368 mutex_lock(&console_session.ses_mutex);
1371 spin_lock(&console_session.ses_rpc_lock);
1373 lst_wait_until((atomic_read(&console_session.ses_rpc_counter) == 0),
1374 console_session.ses_rpc_lock,
1375 "Network is not accessable or target is down, "
1376 "waiting for %d console RPCs to being recycled\n",
1377 atomic_read(&console_session.ses_rpc_counter));
1379 list_splice_init(&console_session.ses_rpc_freelist, &zlist);
1381 spin_unlock(&console_session.ses_rpc_lock);
1383 while (!list_empty(&zlist)) {
1384 crpc = list_entry(zlist.next, struct lstcon_rpc, crp_link);
1386 list_del(&crpc->crp_link);
1387 LIBCFS_FREE(crpc, sizeof(*crpc));
1392 lstcon_rpc_module_init(void)
1394 INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1395 console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1396 console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1398 console_session.ses_ping = NULL;
1400 spin_lock_init(&console_session.ses_rpc_lock);
1401 atomic_set(&console_session.ses_rpc_counter, 0);
1402 INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1408 lstcon_rpc_module_fini(void)
1410 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1411 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);