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/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lnet/selftest/conctl.c
34 * Console framework rpcs
36 * Author: Liang Zhen <liang@whamcloud.com>
40 #include <libcfs/libcfs.h>
41 #include <lnet/lib-lnet.h>
46 void lstcon_rpc_stat_reply(struct lstcon_rpc_trans *, struct srpc_msg *,
47 struct lstcon_node *, struct lstcon_trans_stat *);
50 lstcon_rpc_done(struct srpc_client_rpc *rpc)
52 struct lstcon_rpc *crpc = rpc->crpc_priv;
54 LASSERT(crpc != NULL && rpc == crpc->crp_rpc);
55 LASSERT(crpc->crp_posted && !crpc->crp_finished);
57 spin_lock(&rpc->crpc_lock);
59 if (crpc->crp_trans == NULL) {
60 /* Orphan RPC is not in any transaction,
61 * I'm just a poor body and nobody loves me */
62 spin_unlock(&rpc->crpc_lock);
69 /* not an orphan RPC */
70 crpc->crp_finished = 1;
72 if (crpc->crp_stamp_ns == 0) {
74 LASSERT(crpc->crp_status == 0);
76 crpc->crp_stamp_ns = ktime_get_ns();
77 crpc->crp_status = rpc->crpc_status;
80 /* wakeup (transaction)thread if I'm the last RPC in the transaction */
81 if (atomic_dec_and_test(&crpc->crp_trans->tas_remaining))
82 wake_up(&crpc->crp_trans->tas_waitq);
84 spin_unlock(&rpc->crpc_lock);
88 lstcon_rpc_init(struct lstcon_node *nd, int service, unsigned int feats,
89 int bulk_npg, int bulk_len, int embedded,
90 struct lstcon_rpc *crpc)
92 memset(crpc, 0, sizeof(*crpc));
94 crpc->crp_rpc = sfw_create_rpc(nd->nd_id, service,
95 feats, bulk_npg, bulk_len,
96 lstcon_rpc_done, (void *)crpc);
97 if (crpc->crp_rpc == NULL)
101 crpc->crp_embedded = embedded;
102 INIT_LIST_HEAD(&crpc->crp_link);
104 atomic_inc(&console_session.ses_rpc_counter);
110 lstcon_rpc_prep(struct lstcon_node *nd, int service, unsigned int feats,
111 int bulk_npg, int bulk_len, struct lstcon_rpc **crpcpp)
113 struct lstcon_rpc *crpc = NULL;
116 spin_lock(&console_session.ses_rpc_lock);
118 if (!list_empty(&console_session.ses_rpc_freelist)) {
119 crpc = list_entry(console_session.ses_rpc_freelist.next,
120 struct lstcon_rpc, crp_link);
121 list_del_init(&crpc->crp_link);
124 spin_unlock(&console_session.ses_rpc_lock);
127 LIBCFS_ALLOC(crpc, sizeof(*crpc));
132 rc = lstcon_rpc_init(nd, service, feats, bulk_npg, bulk_len, 0, crpc);
138 LIBCFS_FREE(crpc, sizeof(*crpc));
144 lstcon_rpc_put(struct lstcon_rpc *crpc)
146 struct srpc_bulk *bulk = &crpc->crp_rpc->crpc_bulk;
149 LASSERT(list_empty(&crpc->crp_link));
151 for (i = 0; i < bulk->bk_niov; i++) {
152 if (bulk->bk_iovs[i].bv_page == NULL)
155 __free_page(bulk->bk_iovs[i].bv_page);
158 srpc_client_rpc_decref(crpc->crp_rpc);
160 if (crpc->crp_embedded) {
161 /* embedded RPC, don't recycle it */
162 memset(crpc, 0, sizeof(*crpc));
163 crpc->crp_embedded = 1;
166 spin_lock(&console_session.ses_rpc_lock);
168 list_add(&crpc->crp_link,
169 &console_session.ses_rpc_freelist);
171 spin_unlock(&console_session.ses_rpc_lock);
174 /* RPC is not alive now */
175 atomic_dec(&console_session.ses_rpc_counter);
179 lstcon_rpc_post(struct lstcon_rpc *crpc)
181 struct lstcon_rpc_trans *trans = crpc->crp_trans;
183 LASSERT (trans != NULL);
185 atomic_inc(&trans->tas_remaining);
186 crpc->crp_posted = 1;
188 sfw_post_rpc(crpc->crp_rpc);
192 lstcon_rpc_trans_name(int transop)
194 if (transop == LST_TRANS_SESNEW)
197 if (transop == LST_TRANS_SESEND)
200 if (transop == LST_TRANS_SESQRY)
203 if (transop == LST_TRANS_SESPING)
206 if (transop == LST_TRANS_TSBCLIADD)
209 if (transop == LST_TRANS_TSBSRVADD)
212 if (transop == LST_TRANS_TSBRUN)
215 if (transop == LST_TRANS_TSBSTOP)
218 if (transop == LST_TRANS_TSBCLIQRY)
221 if (transop == LST_TRANS_TSBSRVQRY)
224 if (transop == LST_TRANS_STATQRY)
231 lstcon_rpc_trans_prep(struct list_head *translist, int transop,
232 struct lstcon_rpc_trans **transpp)
234 struct lstcon_rpc_trans *trans;
236 if (translist != NULL) {
237 list_for_each_entry(trans, translist, tas_link) {
238 /* Can't enqueue two private transaction on
240 if ((trans->tas_opc & transop) == LST_TRANS_PRIVATE)
245 /* create a trans group */
246 LIBCFS_ALLOC(trans, sizeof(*trans));
250 trans->tas_opc = transop;
252 if (translist == NULL)
253 INIT_LIST_HEAD(&trans->tas_olink);
255 list_add_tail(&trans->tas_olink, translist);
257 list_add_tail(&trans->tas_link, &console_session.ses_trans_list);
259 INIT_LIST_HEAD(&trans->tas_rpcs_list);
260 atomic_set(&trans->tas_remaining, 0);
261 init_waitqueue_head(&trans->tas_waitq);
263 spin_lock(&console_session.ses_rpc_lock);
264 trans->tas_features = console_session.ses_features;
265 spin_unlock(&console_session.ses_rpc_lock);
272 lstcon_rpc_trans_addreq(struct lstcon_rpc_trans *trans, struct lstcon_rpc *crpc)
274 list_add_tail(&crpc->crp_link, &trans->tas_rpcs_list);
275 crpc->crp_trans = trans;
279 lstcon_rpc_trans_abort(struct lstcon_rpc_trans *trans, int error)
281 struct srpc_client_rpc *rpc;
282 struct lstcon_rpc *crpc;
283 struct lstcon_node *nd;
285 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
288 spin_lock(&rpc->crpc_lock);
290 if (!crpc->crp_posted || /* not posted */
291 crpc->crp_stamp_ns != 0) { /* rpc done or aborted already */
292 if (crpc->crp_stamp_ns == 0) {
293 crpc->crp_stamp_ns = ktime_get_ns();
294 crpc->crp_status = -EINTR;
296 spin_unlock(&rpc->crpc_lock);
300 crpc->crp_stamp_ns = ktime_get_ns();
301 crpc->crp_status = error;
303 spin_unlock(&rpc->crpc_lock);
307 if (error != -ETIMEDOUT)
311 if (ktime_to_ns(nd->nd_stamp) > crpc->crp_stamp_ns)
314 nd->nd_stamp = ktime_set(0, crpc->crp_stamp_ns);
315 nd->nd_state = LST_NODE_DOWN;
320 lstcon_rpc_trans_check(struct lstcon_rpc_trans *trans)
322 if (console_session.ses_shutdown &&
323 !list_empty(&trans->tas_olink)) /* Not an end session RPC */
326 return (atomic_read(&trans->tas_remaining) == 0) ? 1: 0;
330 lstcon_rpc_trans_postwait(struct lstcon_rpc_trans *trans, int timeout)
332 struct lstcon_rpc *crpc;
335 if (list_empty(&trans->tas_rpcs_list))
338 if (timeout < LST_TRANS_MIN_TIMEOUT)
339 timeout = LST_TRANS_MIN_TIMEOUT;
341 CDEBUG(D_NET, "Transaction %s started\n",
342 lstcon_rpc_trans_name(trans->tas_opc));
344 /* post all requests */
345 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
346 LASSERT(!crpc->crp_posted);
348 lstcon_rpc_post(crpc);
351 mutex_unlock(&console_session.ses_mutex);
353 rc = wait_event_interruptible_timeout(trans->tas_waitq,
354 lstcon_rpc_trans_check(trans),
355 cfs_time_seconds(timeout));
357 rc = (rc > 0)? 0: ((rc < 0)? -EINTR: -ETIMEDOUT);
359 mutex_lock(&console_session.ses_mutex);
361 if (console_session.ses_shutdown)
364 if (rc != 0 || atomic_read(&trans->tas_remaining) != 0) {
365 /* treat short timeout as canceled */
366 if (rc == -ETIMEDOUT && timeout < LST_TRANS_MIN_TIMEOUT * 2)
369 lstcon_rpc_trans_abort(trans, rc);
372 CDEBUG(D_NET, "Transaction %s stopped: %d\n",
373 lstcon_rpc_trans_name(trans->tas_opc), rc);
375 lstcon_rpc_trans_stat(trans, lstcon_trans_stat());
381 lstcon_rpc_get_reply(struct lstcon_rpc *crpc, struct srpc_msg **msgpp)
383 struct lstcon_node *nd = crpc->crp_node;
384 struct srpc_client_rpc *rpc = crpc->crp_rpc;
385 struct srpc_generic_reply *rep;
387 LASSERT(nd != NULL && rpc != NULL);
388 LASSERT(crpc->crp_stamp_ns != 0);
390 if (crpc->crp_status != 0) {
392 return crpc->crp_status;
395 *msgpp = &rpc->crpc_replymsg;
396 if (!crpc->crp_unpacked) {
397 sfw_unpack_message(*msgpp);
398 crpc->crp_unpacked = 1;
401 if (ktime_to_ns(nd->nd_stamp) > crpc->crp_stamp_ns)
404 nd->nd_stamp = ktime_set(0, crpc->crp_stamp_ns);
405 rep = &(*msgpp)->msg_body.reply;
407 if (rep->sid.ses_nid == LNET_NID_ANY)
408 nd->nd_state = LST_NODE_UNKNOWN;
409 else if (lstcon_session_match(rep->sid))
410 nd->nd_state = LST_NODE_ACTIVE;
412 nd->nd_state = LST_NODE_BUSY;
418 lstcon_rpc_trans_stat(struct lstcon_rpc_trans *trans,
419 struct lstcon_trans_stat *stat)
421 struct lstcon_rpc *crpc;
422 struct srpc_msg *rep;
425 LASSERT(stat != NULL);
427 memset(stat, 0, sizeof(*stat));
429 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
430 lstcon_rpc_stat_total(stat, 1);
432 LASSERT(crpc->crp_stamp_ns != 0);
434 error = lstcon_rpc_get_reply(crpc, &rep);
436 lstcon_rpc_stat_failure(stat, 1);
437 if (stat->trs_rpc_errno == 0)
438 stat->trs_rpc_errno = -error;
443 lstcon_rpc_stat_success(stat, 1);
445 lstcon_rpc_stat_reply(trans, rep, crpc->crp_node, stat);
448 if (trans->tas_opc == LST_TRANS_SESNEW && stat->trs_fwk_errno == 0) {
449 stat->trs_fwk_errno =
450 lstcon_session_feats_check(trans->tas_features);
453 CDEBUG(D_NET, "transaction %s : success %d, failure %d, total %d, "
454 "RPC error(%d), Framework error(%d)\n",
455 lstcon_rpc_trans_name(trans->tas_opc),
456 lstcon_rpc_stat_success(stat, 0),
457 lstcon_rpc_stat_failure(stat, 0),
458 lstcon_rpc_stat_total(stat, 0),
459 stat->trs_rpc_errno, stat->trs_fwk_errno);
463 lstcon_rpc_trans_interpreter(struct lstcon_rpc_trans *trans,
464 struct list_head __user *head_up,
465 lstcon_rpc_readent_func_t readent)
467 struct list_head tmp;
468 struct list_head __user *next;
469 struct lstcon_rpc_ent *ent;
470 struct srpc_generic_reply *rep;
471 struct lstcon_rpc *crpc;
472 struct srpc_msg *msg;
473 struct lstcon_node *nd;
478 LASSERT(head_up != NULL);
482 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
483 if (copy_from_user(&tmp, next,
484 sizeof(struct list_head)))
487 if (tmp.next == head_up)
492 ent = list_entry(next, struct lstcon_rpc_ent, rpe_link);
494 LASSERT(crpc->crp_stamp_ns != 0);
496 error = lstcon_rpc_get_reply(crpc, &msg);
500 dur = crpc->crp_stamp_ns -
501 console_session.ses_id.ses_stamp * NSEC_PER_MSEC;
502 tv = ns_to_timeval(dur);
504 if (copy_to_user(&ent->rpe_peer,
505 &nd->nd_id, sizeof(struct lnet_process_id)) ||
506 copy_to_user(&ent->rpe_stamp, &tv, sizeof(tv)) ||
507 copy_to_user(&ent->rpe_state,
508 &nd->nd_state, sizeof(nd->nd_state)) ||
509 copy_to_user(&ent->rpe_rpc_errno, &error,
517 rep = (struct srpc_generic_reply *)&msg->msg_body.reply;
519 if (copy_to_user(&ent->rpe_sid,
520 &rep->sid, sizeof(rep->sid)) ||
521 copy_to_user(&ent->rpe_fwk_errno,
522 &rep->status, sizeof(rep->status)))
528 error = readent(trans->tas_opc, msg, ent);
537 lstcon_rpc_trans_destroy(struct lstcon_rpc_trans *trans)
539 struct srpc_client_rpc *rpc;
540 struct lstcon_rpc *crpc;
541 struct lstcon_rpc *tmp;
544 list_for_each_entry_safe(crpc, tmp, &trans->tas_rpcs_list, crp_link) {
547 spin_lock(&rpc->crpc_lock);
549 /* free it if not posted or finished already */
550 if (!crpc->crp_posted || crpc->crp_finished) {
551 spin_unlock(&rpc->crpc_lock);
553 list_del_init(&crpc->crp_link);
554 lstcon_rpc_put(crpc);
559 /* rpcs can be still not callbacked (even LNetMDUnlink is
560 * called) because huge timeout for inaccessible network,
561 * don't make user wait for them, just abandon them, they
562 * will be recycled in callback */
564 LASSERT(crpc->crp_status != 0);
566 crpc->crp_node = NULL;
567 crpc->crp_trans = NULL;
568 list_del_init(&crpc->crp_link);
571 spin_unlock(&rpc->crpc_lock);
573 atomic_dec(&trans->tas_remaining);
576 LASSERT(atomic_read(&trans->tas_remaining) == 0);
578 list_del(&trans->tas_link);
579 if (!list_empty(&trans->tas_olink))
580 list_del(&trans->tas_olink);
582 CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
583 lstcon_rpc_trans_name(trans->tas_opc), count);
585 LIBCFS_FREE(trans, sizeof(*trans));
589 lstcon_sesrpc_prep(struct lstcon_node *nd, int transop,
590 unsigned int feats, struct lstcon_rpc **crpc)
592 struct srpc_mksn_reqst *msrq;
593 struct srpc_rmsn_reqst *rsrq;
597 case LST_TRANS_SESNEW:
598 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION,
603 msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
604 msrq->mksn_sid = console_session.ses_id;
605 msrq->mksn_force = console_session.ses_force;
606 strlcpy(msrq->mksn_name, console_session.ses_name,
607 sizeof(msrq->mksn_name));
610 case LST_TRANS_SESEND:
611 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION,
616 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
617 rsrq->rmsn_sid = console_session.ses_id;
628 lstcon_dbgrpc_prep(struct lstcon_node *nd, unsigned int feats,
629 struct lstcon_rpc **crpc)
631 struct srpc_debug_reqst *drq;
634 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, feats, 0, 0, crpc);
638 drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
640 drq->dbg_sid = console_session.ses_id;
647 lstcon_batrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
648 struct lstcon_tsb_hdr *tsb, struct lstcon_rpc **crpc)
650 struct lstcon_batch *batch;
651 struct srpc_batch_reqst *brq;
654 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, feats, 0, 0, crpc);
658 brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
660 brq->bar_sid = console_session.ses_id;
661 brq->bar_bid = tsb->tsb_id;
662 brq->bar_testidx = tsb->tsb_index;
663 brq->bar_opc = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
664 (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP:
665 SRPC_BATCH_OPC_QUERY);
667 if (transop != LST_TRANS_TSBRUN &&
668 transop != LST_TRANS_TSBSTOP)
671 LASSERT (tsb->tsb_index == 0);
673 batch = (struct lstcon_batch *)tsb;
674 brq->bar_arg = batch->bat_arg;
680 lstcon_statrpc_prep(struct lstcon_node *nd, unsigned int feats,
681 struct lstcon_rpc **crpc)
683 struct srpc_stat_reqst *srq;
686 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_QUERY_STAT, feats, 0, 0, crpc);
690 srq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.stat_reqst;
692 srq->str_sid = console_session.ses_id;
693 srq->str_type = 0; /* XXX remove it */
698 static struct lnet_process_id_packed *
699 lstcon_next_id(int idx, int nkiov, struct bio_vec *kiov)
701 struct lnet_process_id_packed *pid;
704 i = idx / SFW_ID_PER_PAGE;
708 pid = (struct lnet_process_id_packed *)page_address(kiov[i].bv_page);
710 return &pid[idx % SFW_ID_PER_PAGE];
714 lstcon_dstnodes_prep(struct lstcon_group *grp, int idx,
715 int dist, int span, int nkiov, struct bio_vec *kiov)
717 struct lnet_process_id_packed *pid;
718 struct lstcon_ndlink *ndl;
719 struct lstcon_node *nd;
726 LASSERT (grp->grp_nnode >= 1);
728 if (span > grp->grp_nnode)
731 start = ((idx / dist) * span) % grp->grp_nnode;
732 end = ((idx / dist) * span + span - 1) % grp->grp_nnode;
734 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
741 if (i > (end >= start ? end : grp->grp_nnode))
744 pid = lstcon_next_id((i - start), nkiov, kiov);
745 pid->nid = nd->nd_id.nid;
746 pid->pid = nd->nd_id.pid;
750 if (start <= end) /* done */
753 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
754 if (i > grp->grp_nnode + end)
758 pid = lstcon_next_id((i - start), nkiov, kiov);
759 pid->nid = nd->nd_id.nid;
760 pid->pid = nd->nd_id.pid;
768 lstcon_pingrpc_prep(struct lst_test_ping_param *param,
769 struct srpc_test_reqst *req)
771 struct test_ping_req *prq = &req->tsr_u.ping;
773 prq->png_size = param->png_size;
774 prq->png_flags = param->png_flags;
780 lstcon_bulkrpc_v0_prep(struct lst_test_bulk_param *param,
781 struct srpc_test_reqst *req)
783 struct test_bulk_req *brq = &req->tsr_u.bulk_v0;
785 brq->blk_opc = param->blk_opc;
786 brq->blk_npg = (param->blk_size + PAGE_SIZE - 1) /
788 brq->blk_flags = param->blk_flags;
794 lstcon_bulkrpc_v1_prep(struct lst_test_bulk_param *param, bool is_client,
795 struct srpc_test_reqst *req)
797 struct test_bulk_req_v1 *brq = &req->tsr_u.bulk_v1;
799 brq->blk_opc = param->blk_opc;
800 brq->blk_flags = param->blk_flags;
801 brq->blk_len = param->blk_size;
802 brq->blk_offset = is_client ? param->blk_cli_off : param->blk_srv_off;
808 lstcon_testrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
809 struct lstcon_test *test, struct lstcon_rpc **crpc)
811 struct lstcon_group *sgrp = test->tes_src_grp;
812 struct lstcon_group *dgrp = test->tes_dst_grp;
813 struct srpc_test_reqst *trq;
814 struct srpc_bulk *bulk;
820 if (transop == LST_TRANS_TSBCLIADD) {
821 npg = sfw_id_pages(test->tes_span);
822 nob = (feats & LST_FEAT_BULK_LEN) == 0 ?
824 sizeof(struct lnet_process_id_packed) * test->tes_span;
827 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc);
831 trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
833 if (transop == LST_TRANS_TSBSRVADD) {
834 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / test->tes_dist;
835 int nspan = (dgrp->grp_nnode + test->tes_span - 1) / test->tes_span;
836 int nmax = (ndist + nspan - 1) / nspan;
839 trq->tsr_loop = nmax * test->tes_dist * test->tes_concur;
842 bulk = &(*crpc)->crp_rpc->crpc_bulk;
844 for (i = 0; i < npg; i++) {
849 len = (feats & LST_FEAT_BULK_LEN) == 0 ?
850 PAGE_SIZE : min_t(int, nob, PAGE_SIZE);
853 bulk->bk_iovs[i].bv_offset = 0;
854 bulk->bk_iovs[i].bv_len = len;
855 bulk->bk_iovs[i].bv_page =
856 alloc_page(GFP_KERNEL);
858 if (bulk->bk_iovs[i].bv_page == NULL) {
859 lstcon_rpc_put(*crpc);
866 LASSERT (transop == LST_TRANS_TSBCLIADD);
868 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
872 npg, &bulk->bk_iovs[0]);
874 lstcon_rpc_put(*crpc);
878 trq->tsr_ndest = test->tes_span;
879 trq->tsr_loop = test->tes_loop;
882 trq->tsr_sid = console_session.ses_id;
883 trq->tsr_bid = test->tes_hdr.tsb_id;
884 trq->tsr_concur = test->tes_concur;
885 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
886 trq->tsr_stop_onerr = !!test->tes_stop_onerr;
888 switch (test->tes_type) {
890 trq->tsr_service = SRPC_SERVICE_PING;
891 rc = lstcon_pingrpc_prep((struct lst_test_ping_param *)
892 &test->tes_param[0], trq);
896 trq->tsr_service = SRPC_SERVICE_BRW;
897 if ((feats & LST_FEAT_BULK_LEN) == 0) {
898 rc = lstcon_bulkrpc_v0_prep((struct lst_test_bulk_param *)
899 &test->tes_param[0], trq);
901 rc = lstcon_bulkrpc_v1_prep((struct lst_test_bulk_param *)
903 trq->tsr_is_client, trq);
916 lstcon_sesnew_stat_reply(struct lstcon_rpc_trans *trans,
917 struct lstcon_node *nd, struct srpc_msg *reply)
919 struct srpc_mksn_reply *mksn_rep = &reply->msg_body.mksn_reply;
920 int status = mksn_rep->mksn_status;
923 (reply->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
924 mksn_rep->mksn_status = EPROTO;
928 if (status == EPROTO) {
929 CNETERR("session protocol error from %s: %u\n",
930 libcfs_nid2str(nd->nd_id.nid),
931 reply->msg_ses_feats);
937 if (!trans->tas_feats_updated) {
938 spin_lock(&console_session.ses_rpc_lock);
939 if (!trans->tas_feats_updated) { /* recheck with lock */
940 trans->tas_feats_updated = 1;
941 trans->tas_features = reply->msg_ses_feats;
943 spin_unlock(&console_session.ses_rpc_lock);
946 if (reply->msg_ses_feats != trans->tas_features) {
947 CNETERR("Framework features %x from %s is different with "
948 "features on this transaction: %x\n",
949 reply->msg_ses_feats, libcfs_nid2str(nd->nd_id.nid),
950 trans->tas_features);
951 status = mksn_rep->mksn_status = EPROTO;
955 /* session timeout on remote node */
956 nd->nd_timeout = mksn_rep->mksn_timeout;
963 lstcon_rpc_stat_reply(struct lstcon_rpc_trans *trans, struct srpc_msg *msg,
964 struct lstcon_node *nd, struct lstcon_trans_stat *stat)
966 struct srpc_rmsn_reply *rmsn_rep;
967 struct srpc_debug_reply *dbg_rep;
968 struct srpc_batch_reply *bat_rep;
969 struct srpc_test_reply *test_rep;
970 struct srpc_stat_reply *stat_rep;
973 switch (trans->tas_opc) {
974 case LST_TRANS_SESNEW:
975 rc = lstcon_sesnew_stat_reply(trans, nd, msg);
977 lstcon_sesop_stat_success(stat, 1);
981 lstcon_sesop_stat_failure(stat, 1);
984 case LST_TRANS_SESEND:
985 rmsn_rep = &msg->msg_body.rmsn_reply;
986 /* ESRCH is not an error for end session */
987 if (rmsn_rep->rmsn_status == 0 ||
988 rmsn_rep->rmsn_status == ESRCH) {
989 lstcon_sesop_stat_success(stat, 1);
993 lstcon_sesop_stat_failure(stat, 1);
994 rc = rmsn_rep->rmsn_status;
997 case LST_TRANS_SESQRY:
998 case LST_TRANS_SESPING:
999 dbg_rep = &msg->msg_body.dbg_reply;
1001 if (dbg_rep->dbg_status == ESRCH) {
1002 lstcon_sesqry_stat_unknown(stat, 1);
1006 if (lstcon_session_match(dbg_rep->dbg_sid))
1007 lstcon_sesqry_stat_active(stat, 1);
1009 lstcon_sesqry_stat_busy(stat, 1);
1012 case LST_TRANS_TSBRUN:
1013 case LST_TRANS_TSBSTOP:
1014 bat_rep = &msg->msg_body.bat_reply;
1016 if (bat_rep->bar_status == 0) {
1017 lstcon_tsbop_stat_success(stat, 1);
1021 if (bat_rep->bar_status == EPERM &&
1022 trans->tas_opc == LST_TRANS_TSBSTOP) {
1023 lstcon_tsbop_stat_success(stat, 1);
1027 lstcon_tsbop_stat_failure(stat, 1);
1028 rc = bat_rep->bar_status;
1031 case LST_TRANS_TSBCLIQRY:
1032 case LST_TRANS_TSBSRVQRY:
1033 bat_rep = &msg->msg_body.bat_reply;
1035 if (bat_rep->bar_active != 0)
1036 lstcon_tsbqry_stat_run(stat, 1);
1038 lstcon_tsbqry_stat_idle(stat, 1);
1040 if (bat_rep->bar_status == 0)
1043 lstcon_tsbqry_stat_failure(stat, 1);
1044 rc = bat_rep->bar_status;
1047 case LST_TRANS_TSBCLIADD:
1048 case LST_TRANS_TSBSRVADD:
1049 test_rep = &msg->msg_body.tes_reply;
1051 if (test_rep->tsr_status == 0) {
1052 lstcon_tsbop_stat_success(stat, 1);
1056 lstcon_tsbop_stat_failure(stat, 1);
1057 rc = test_rep->tsr_status;
1060 case LST_TRANS_STATQRY:
1061 stat_rep = &msg->msg_body.stat_reply;
1063 if (stat_rep->str_status == 0) {
1064 lstcon_statqry_stat_success(stat, 1);
1068 lstcon_statqry_stat_failure(stat, 1);
1069 rc = stat_rep->str_status;
1076 if (stat->trs_fwk_errno == 0)
1077 stat->trs_fwk_errno = rc;
1081 lstcon_rpc_trans_ndlist(struct list_head *ndlist,
1082 struct list_head *translist, int transop,
1083 void *arg, lstcon_rpc_cond_func_t condition,
1084 struct lstcon_rpc_trans **transpp)
1086 struct lstcon_rpc_trans *trans;
1087 struct lstcon_ndlink *ndl;
1088 struct lstcon_node *nd;
1089 struct lstcon_rpc *rpc;
1093 /* Creating session RPG for list of nodes */
1095 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1097 CERROR("Can't create transaction %d: %d\n", transop, rc);
1101 feats = trans->tas_features;
1102 list_for_each_entry(ndl, ndlist, ndl_link) {
1103 rc = condition == NULL ? 1 :
1104 condition(transop, ndl->ndl_node, arg);
1110 CDEBUG(D_NET, "Condition error while creating RPC "
1111 " for transaction %d: %d\n", transop, rc);
1118 case LST_TRANS_SESNEW:
1119 case LST_TRANS_SESEND:
1120 rc = lstcon_sesrpc_prep(nd, transop, feats, &rpc);
1122 case LST_TRANS_SESQRY:
1123 case LST_TRANS_SESPING:
1124 rc = lstcon_dbgrpc_prep(nd, feats, &rpc);
1126 case LST_TRANS_TSBCLIADD:
1127 case LST_TRANS_TSBSRVADD:
1128 rc = lstcon_testrpc_prep(nd, transop, feats,
1129 (struct lstcon_test *)arg,
1132 case LST_TRANS_TSBRUN:
1133 case LST_TRANS_TSBSTOP:
1134 case LST_TRANS_TSBCLIQRY:
1135 case LST_TRANS_TSBSRVQRY:
1136 rc = lstcon_batrpc_prep(nd, transop, feats,
1137 (struct lstcon_tsb_hdr *)arg,
1140 case LST_TRANS_STATQRY:
1141 rc = lstcon_statrpc_prep(nd, feats, &rpc);
1149 CERROR("Failed to create RPC for transaction %s: %d\n",
1150 lstcon_rpc_trans_name(transop), rc);
1154 lstcon_rpc_trans_addreq(trans, rpc);
1162 lstcon_rpc_trans_destroy(trans);
1168 lstcon_rpc_pinger(void *arg)
1170 struct stt_timer *ptimer = arg;
1171 struct lstcon_rpc_trans *trans;
1172 struct lstcon_rpc *crpc;
1173 struct srpc_msg *rep;
1174 struct srpc_debug_reqst *drq;
1175 struct lstcon_ndlink *ndl;
1176 struct lstcon_node *nd;
1181 /* RPC pinger is a special case of transaction,
1182 * it's called by timer at 8 seconds interval.
1184 mutex_lock(&console_session.ses_mutex);
1186 if (console_session.ses_shutdown || console_session.ses_expired) {
1187 mutex_unlock(&console_session.ses_mutex);
1191 if (!console_session.ses_expired &&
1192 ktime_get_real_seconds() - console_session.ses_laststamp >
1193 (time64_t)console_session.ses_timeout)
1194 console_session.ses_expired = 1;
1196 trans = console_session.ses_ping;
1198 LASSERT(trans != NULL);
1200 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link) {
1203 if (console_session.ses_expired) {
1204 /* idle console, end session on all nodes */
1205 if (nd->nd_state != LST_NODE_ACTIVE)
1208 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND,
1209 trans->tas_features, &crpc);
1211 CERROR("Out of memory\n");
1215 lstcon_rpc_trans_addreq(trans, crpc);
1216 lstcon_rpc_post(crpc);
1221 crpc = &nd->nd_ping;
1223 if (crpc->crp_rpc != NULL) {
1224 LASSERT(crpc->crp_trans == trans);
1225 LASSERT(!list_empty(&crpc->crp_link));
1227 spin_lock(&crpc->crp_rpc->crpc_lock);
1229 LASSERT(crpc->crp_posted);
1231 if (!crpc->crp_finished) {
1233 spin_unlock(&crpc->crp_rpc->crpc_lock);
1237 spin_unlock(&crpc->crp_rpc->crpc_lock);
1239 lstcon_rpc_get_reply(crpc, &rep);
1241 list_del_init(&crpc->crp_link);
1243 lstcon_rpc_put(crpc);
1246 if (nd->nd_state != LST_NODE_ACTIVE)
1249 intv = div_u64(ktime_ms_delta(ktime_get(), nd->nd_stamp),
1251 if (intv < nd->nd_timeout / 2)
1254 rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
1255 trans->tas_features, 0, 0, 1, crpc);
1257 CERROR("Out of memory\n");
1261 drq = &crpc->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
1263 drq->dbg_sid = console_session.ses_id;
1266 lstcon_rpc_trans_addreq(trans, crpc);
1267 lstcon_rpc_post(crpc);
1272 if (console_session.ses_expired) {
1273 mutex_unlock(&console_session.ses_mutex);
1277 CDEBUG(D_NET, "Ping %d nodes in session\n", count);
1279 ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1280 stt_add_timer(ptimer);
1282 mutex_unlock(&console_session.ses_mutex);
1286 lstcon_rpc_pinger_start(void)
1288 struct stt_timer *ptimer;
1291 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1292 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);
1294 rc = lstcon_rpc_trans_prep(NULL, LST_TRANS_SESPING,
1295 &console_session.ses_ping);
1297 CERROR("Failed to create console pinger\n");
1301 ptimer = &console_session.ses_ping_timer;
1302 ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
1304 stt_add_timer(ptimer);
1310 lstcon_rpc_pinger_stop(void)
1312 LASSERT (console_session.ses_shutdown);
1314 stt_del_timer(&console_session.ses_ping_timer);
1316 lstcon_rpc_trans_abort(console_session.ses_ping, -ESHUTDOWN);
1317 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1318 lstcon_rpc_trans_destroy(console_session.ses_ping);
1320 memset(lstcon_trans_stat(), 0, sizeof(struct lstcon_trans_stat));
1322 console_session.ses_ping = NULL;
1326 lstcon_rpc_cleanup_wait(void)
1328 struct lstcon_rpc_trans *trans;
1329 struct lstcon_rpc *crpc;
1330 struct list_head *pacer;
1333 /* Called with hold of global mutex */
1335 LASSERT(console_session.ses_shutdown);
1337 while (!list_empty(&console_session.ses_trans_list)) {
1338 list_for_each(pacer, &console_session.ses_trans_list) {
1339 trans = list_entry(pacer, struct lstcon_rpc_trans,
1342 CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
1343 lstcon_rpc_trans_name(trans->tas_opc));
1345 wake_up(&trans->tas_waitq);
1348 mutex_unlock(&console_session.ses_mutex);
1350 CWARN("Session is shutting down, "
1351 "waiting for termination of transactions\n");
1352 schedule_timeout_uninterruptible(cfs_time_seconds(1));
1354 mutex_lock(&console_session.ses_mutex);
1357 spin_lock(&console_session.ses_rpc_lock);
1359 lst_wait_until((atomic_read(&console_session.ses_rpc_counter) == 0),
1360 console_session.ses_rpc_lock,
1361 "Network is not accessable or target is down, "
1362 "waiting for %d console RPCs to being recycled\n",
1363 atomic_read(&console_session.ses_rpc_counter));
1365 list_splice_init(&console_session.ses_rpc_freelist, &zlist);
1367 spin_unlock(&console_session.ses_rpc_lock);
1369 while (!list_empty(&zlist)) {
1370 crpc = list_entry(zlist.next, struct lstcon_rpc, crp_link);
1372 list_del(&crpc->crp_link);
1373 LIBCFS_FREE(crpc, sizeof(*crpc));
1378 lstcon_rpc_module_init(void)
1380 INIT_LIST_HEAD(&console_session.ses_ping_timer.stt_list);
1381 console_session.ses_ping_timer.stt_func = lstcon_rpc_pinger;
1382 console_session.ses_ping_timer.stt_data = &console_session.ses_ping_timer;
1384 console_session.ses_ping = NULL;
1386 spin_lock_init(&console_session.ses_rpc_lock);
1387 atomic_set(&console_session.ses_rpc_counter, 0);
1388 INIT_LIST_HEAD(&console_session.ses_rpc_freelist);
1394 lstcon_rpc_module_fini(void)
1396 LASSERT(list_empty(&console_session.ses_rpc_freelist));
1397 LASSERT(atomic_read(&console_session.ses_rpc_counter) == 0);