4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/selftest/conctl.c
38 * Console framework rpcs
40 * Author: Liang Zhen <liang@whamcloud.com>
43 #include "../../include/linux/libcfs/libcfs.h"
44 #include "../../include/linux/lnet/lib-lnet.h"
49 void lstcon_rpc_stat_reply(lstcon_rpc_trans_t *, srpc_msg_t *,
50 lstcon_node_t *, lstcon_trans_stat_t *);
53 lstcon_rpc_done(srpc_client_rpc_t *rpc)
55 lstcon_rpc_t *crpc = (lstcon_rpc_t *)rpc->crpc_priv;
57 LASSERT(crpc != NULL && rpc == crpc->crp_rpc);
58 LASSERT(crpc->crp_posted && !crpc->crp_finished);
60 spin_lock(&rpc->crpc_lock);
62 if (crpc->crp_trans == NULL) {
63 /* Orphan RPC is not in any transaction,
64 * I'm just a poor body and nobody loves me */
65 spin_unlock(&rpc->crpc_lock);
72 /* not an orphan RPC */
73 crpc->crp_finished = 1;
75 if (crpc->crp_stamp == 0) {
77 LASSERT(crpc->crp_status == 0);
79 crpc->crp_stamp = cfs_time_current();
80 crpc->crp_status = rpc->crpc_status;
83 /* wakeup (transaction)thread if I'm the last RPC in the transaction */
84 if (atomic_dec_and_test(&crpc->crp_trans->tas_remaining))
85 wake_up(&crpc->crp_trans->tas_waitq);
87 spin_unlock(&rpc->crpc_lock);
91 lstcon_rpc_init(lstcon_node_t *nd, int service, unsigned feats,
92 int bulk_npg, int bulk_len, int embedded, lstcon_rpc_t *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)
100 crpc->crp_trans = NULL;
102 crpc->crp_posted = 0;
103 crpc->crp_finished = 0;
104 crpc->crp_unpacked = 0;
105 crpc->crp_status = 0;
107 crpc->crp_embedded = embedded;
108 INIT_LIST_HEAD(&crpc->crp_link);
110 atomic_inc(&console_session.ses_rpc_counter);
116 lstcon_rpc_prep(lstcon_node_t *nd, int service, unsigned feats,
117 int bulk_npg, int bulk_len, lstcon_rpc_t **crpcpp)
119 lstcon_rpc_t *crpc = NULL;
122 spin_lock(&console_session.ses_rpc_lock);
124 if (!list_empty(&console_session.ses_rpc_freelist)) {
125 crpc = list_entry(console_session.ses_rpc_freelist.next,
126 lstcon_rpc_t, crp_link);
127 list_del_init(&crpc->crp_link);
130 spin_unlock(&console_session.ses_rpc_lock);
133 LIBCFS_ALLOC(crpc, sizeof(*crpc));
138 rc = lstcon_rpc_init(nd, service, feats, bulk_npg, bulk_len, 0, crpc);
144 LIBCFS_FREE(crpc, sizeof(*crpc));
150 lstcon_rpc_put(lstcon_rpc_t *crpc)
152 srpc_bulk_t *bulk = &crpc->crp_rpc->crpc_bulk;
155 LASSERT(list_empty(&crpc->crp_link));
157 for (i = 0; i < bulk->bk_niov; i++) {
158 if (bulk->bk_iovs[i].kiov_page == NULL)
161 __free_page(bulk->bk_iovs[i].kiov_page);
164 srpc_client_rpc_decref(crpc->crp_rpc);
166 if (crpc->crp_embedded) {
167 /* embedded RPC, don't recycle it */
168 memset(crpc, 0, sizeof(*crpc));
169 crpc->crp_embedded = 1;
172 spin_lock(&console_session.ses_rpc_lock);
174 list_add(&crpc->crp_link,
175 &console_session.ses_rpc_freelist);
177 spin_unlock(&console_session.ses_rpc_lock);
180 /* RPC is not alive now */
181 atomic_dec(&console_session.ses_rpc_counter);
185 lstcon_rpc_post(lstcon_rpc_t *crpc)
187 lstcon_rpc_trans_t *trans = crpc->crp_trans;
189 LASSERT(trans != NULL);
191 atomic_inc(&trans->tas_remaining);
192 crpc->crp_posted = 1;
194 sfw_post_rpc(crpc->crp_rpc);
198 lstcon_rpc_trans_name(int transop)
200 if (transop == LST_TRANS_SESNEW)
203 if (transop == LST_TRANS_SESEND)
206 if (transop == LST_TRANS_SESQRY)
209 if (transop == LST_TRANS_SESPING)
212 if (transop == LST_TRANS_TSBCLIADD)
215 if (transop == LST_TRANS_TSBSRVADD)
218 if (transop == LST_TRANS_TSBRUN)
221 if (transop == LST_TRANS_TSBSTOP)
224 if (transop == LST_TRANS_TSBCLIQRY)
227 if (transop == LST_TRANS_TSBSRVQRY)
230 if (transop == LST_TRANS_STATQRY)
237 lstcon_rpc_trans_prep(struct list_head *translist,
238 int transop, lstcon_rpc_trans_t **transpp)
240 lstcon_rpc_trans_t *trans;
242 if (translist != NULL) {
243 list_for_each_entry(trans, translist, tas_link) {
244 /* Can't enqueue two private transaction on
246 if ((trans->tas_opc & transop) == LST_TRANS_PRIVATE)
251 /* create a trans group */
252 LIBCFS_ALLOC(trans, sizeof(*trans));
256 trans->tas_opc = transop;
258 if (translist == NULL)
259 INIT_LIST_HEAD(&trans->tas_olink);
261 list_add_tail(&trans->tas_olink, translist);
263 list_add_tail(&trans->tas_link, &console_session.ses_trans_list);
265 INIT_LIST_HEAD(&trans->tas_rpcs_list);
266 atomic_set(&trans->tas_remaining, 0);
267 init_waitqueue_head(&trans->tas_waitq);
269 spin_lock(&console_session.ses_rpc_lock);
270 trans->tas_features = console_session.ses_features;
271 spin_unlock(&console_session.ses_rpc_lock);
278 lstcon_rpc_trans_addreq(lstcon_rpc_trans_t *trans, lstcon_rpc_t *crpc)
280 list_add_tail(&crpc->crp_link, &trans->tas_rpcs_list);
281 crpc->crp_trans = trans;
285 lstcon_rpc_trans_abort(lstcon_rpc_trans_t *trans, int error)
287 srpc_client_rpc_t *rpc;
291 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
294 spin_lock(&rpc->crpc_lock);
296 if (!crpc->crp_posted || /* not posted */
297 crpc->crp_stamp != 0) { /* rpc done or aborted already */
298 if (crpc->crp_stamp == 0) {
299 crpc->crp_stamp = cfs_time_current();
300 crpc->crp_status = -EINTR;
302 spin_unlock(&rpc->crpc_lock);
306 crpc->crp_stamp = cfs_time_current();
307 crpc->crp_status = error;
309 spin_unlock(&rpc->crpc_lock);
313 if (error != ETIMEDOUT)
317 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
320 nd->nd_stamp = crpc->crp_stamp;
321 nd->nd_state = LST_NODE_DOWN;
326 lstcon_rpc_trans_check(lstcon_rpc_trans_t *trans)
328 if (console_session.ses_shutdown &&
329 !list_empty(&trans->tas_olink)) /* Not an end session RPC */
332 return (atomic_read(&trans->tas_remaining) == 0) ? 1 : 0;
336 lstcon_rpc_trans_postwait(lstcon_rpc_trans_t *trans, int timeout)
341 if (list_empty(&trans->tas_rpcs_list))
344 if (timeout < LST_TRANS_MIN_TIMEOUT)
345 timeout = LST_TRANS_MIN_TIMEOUT;
347 CDEBUG(D_NET, "Transaction %s started\n",
348 lstcon_rpc_trans_name(trans->tas_opc));
350 /* post all requests */
351 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
352 LASSERT(!crpc->crp_posted);
354 lstcon_rpc_post(crpc);
357 mutex_unlock(&console_session.ses_mutex);
359 rc = wait_event_interruptible_timeout(trans->tas_waitq,
360 lstcon_rpc_trans_check(trans),
361 cfs_time_seconds(timeout));
362 rc = (rc > 0) ? 0 : ((rc < 0) ? -EINTR : -ETIMEDOUT);
364 mutex_lock(&console_session.ses_mutex);
366 if (console_session.ses_shutdown)
369 if (rc != 0 || atomic_read(&trans->tas_remaining) != 0) {
370 /* treat short timeout as canceled */
371 if (rc == -ETIMEDOUT && timeout < LST_TRANS_MIN_TIMEOUT * 2)
374 lstcon_rpc_trans_abort(trans, rc);
377 CDEBUG(D_NET, "Transaction %s stopped: %d\n",
378 lstcon_rpc_trans_name(trans->tas_opc), rc);
380 lstcon_rpc_trans_stat(trans, lstcon_trans_stat());
386 lstcon_rpc_get_reply(lstcon_rpc_t *crpc, srpc_msg_t **msgpp)
388 lstcon_node_t *nd = crpc->crp_node;
389 srpc_client_rpc_t *rpc = crpc->crp_rpc;
390 srpc_generic_reply_t *rep;
392 LASSERT(nd != NULL && rpc != NULL);
393 LASSERT(crpc->crp_stamp != 0);
395 if (crpc->crp_status != 0) {
397 return crpc->crp_status;
400 *msgpp = &rpc->crpc_replymsg;
401 if (!crpc->crp_unpacked) {
402 sfw_unpack_message(*msgpp);
403 crpc->crp_unpacked = 1;
406 if (cfs_time_after(nd->nd_stamp, crpc->crp_stamp))
409 nd->nd_stamp = crpc->crp_stamp;
410 rep = &(*msgpp)->msg_body.reply;
412 if (rep->sid.ses_nid == LNET_NID_ANY)
413 nd->nd_state = LST_NODE_UNKNOWN;
414 else if (lstcon_session_match(rep->sid))
415 nd->nd_state = LST_NODE_ACTIVE;
417 nd->nd_state = LST_NODE_BUSY;
423 lstcon_rpc_trans_stat(lstcon_rpc_trans_t *trans, lstcon_trans_stat_t *stat)
429 LASSERT(stat != NULL);
431 memset(stat, 0, sizeof(*stat));
433 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
434 lstcon_rpc_stat_total(stat, 1);
436 LASSERT(crpc->crp_stamp != 0);
438 error = lstcon_rpc_get_reply(crpc, &rep);
440 lstcon_rpc_stat_failure(stat, 1);
441 if (stat->trs_rpc_errno == 0)
442 stat->trs_rpc_errno = -error;
447 lstcon_rpc_stat_success(stat, 1);
449 lstcon_rpc_stat_reply(trans, rep, crpc->crp_node, stat);
452 if (trans->tas_opc == LST_TRANS_SESNEW && stat->trs_fwk_errno == 0) {
453 stat->trs_fwk_errno =
454 lstcon_session_feats_check(trans->tas_features);
457 CDEBUG(D_NET, "transaction %s : success %d, failure %d, total %d, RPC error(%d), Framework error(%d)\n",
458 lstcon_rpc_trans_name(trans->tas_opc),
459 lstcon_rpc_stat_success(stat, 0),
460 lstcon_rpc_stat_failure(stat, 0),
461 lstcon_rpc_stat_total(stat, 0),
462 stat->trs_rpc_errno, stat->trs_fwk_errno);
468 lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
469 struct list_head *head_up,
470 lstcon_rpc_readent_func_t readent)
472 struct list_head tmp;
473 struct list_head *next;
474 lstcon_rpc_ent_t *ent;
475 srpc_generic_reply_t *rep;
483 LASSERT(head_up != NULL);
487 list_for_each_entry(crpc, &trans->tas_rpcs_list, crp_link) {
488 if (copy_from_user(&tmp, next,
489 sizeof(struct list_head)))
492 if (tmp.next == head_up)
497 ent = list_entry(next, lstcon_rpc_ent_t, rpe_link);
499 LASSERT(crpc->crp_stamp != 0);
501 error = lstcon_rpc_get_reply(crpc, &msg);
505 dur = (long)cfs_time_sub(crpc->crp_stamp,
506 (unsigned long)console_session.ses_id.ses_stamp);
507 jiffies_to_timeval(dur, &tv);
509 if (copy_to_user(&ent->rpe_peer,
510 &nd->nd_id, sizeof(lnet_process_id_t)) ||
511 copy_to_user(&ent->rpe_stamp, &tv, sizeof(tv)) ||
512 copy_to_user(&ent->rpe_state,
513 &nd->nd_state, sizeof(nd->nd_state)) ||
514 copy_to_user(&ent->rpe_rpc_errno, &error,
522 rep = (srpc_generic_reply_t *)&msg->msg_body.reply;
524 if (copy_to_user(&ent->rpe_sid,
525 &rep->sid, sizeof(lst_sid_t)) ||
526 copy_to_user(&ent->rpe_fwk_errno,
527 &rep->status, sizeof(rep->status)))
533 error = readent(trans->tas_opc, msg, ent);
543 lstcon_rpc_trans_destroy(lstcon_rpc_trans_t *trans)
545 srpc_client_rpc_t *rpc;
550 list_for_each_entry_safe(crpc, tmp, &trans->tas_rpcs_list,
554 spin_lock(&rpc->crpc_lock);
556 /* free it if not posted or finished already */
557 if (!crpc->crp_posted || crpc->crp_finished) {
558 spin_unlock(&rpc->crpc_lock);
560 list_del_init(&crpc->crp_link);
561 lstcon_rpc_put(crpc);
566 /* rpcs can be still not callbacked (even LNetMDUnlink is called)
567 * because huge timeout for inaccessible network, don't make
568 * user wait for them, just abandon them, they will be recycled
571 LASSERT(crpc->crp_status != 0);
573 crpc->crp_node = NULL;
574 crpc->crp_trans = NULL;
575 list_del_init(&crpc->crp_link);
578 spin_unlock(&rpc->crpc_lock);
580 atomic_dec(&trans->tas_remaining);
583 LASSERT(atomic_read(&trans->tas_remaining) == 0);
585 list_del(&trans->tas_link);
586 if (!list_empty(&trans->tas_olink))
587 list_del(&trans->tas_olink);
589 CDEBUG(D_NET, "Transaction %s destroyed with %d pending RPCs\n",
590 lstcon_rpc_trans_name(trans->tas_opc), count);
592 LIBCFS_FREE(trans, sizeof(*trans));
598 lstcon_sesrpc_prep(lstcon_node_t *nd, int transop,
599 unsigned feats, lstcon_rpc_t **crpc)
601 srpc_mksn_reqst_t *msrq;
602 srpc_rmsn_reqst_t *rsrq;
606 case LST_TRANS_SESNEW:
607 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION,
612 msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
613 msrq->mksn_sid = console_session.ses_id;
614 msrq->mksn_force = console_session.ses_force;
615 strncpy(msrq->mksn_name, console_session.ses_name,
616 strlen(console_session.ses_name));
619 case LST_TRANS_SESEND:
620 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION,
625 rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst;
626 rsrq->rmsn_sid = console_session.ses_id;
637 lstcon_dbgrpc_prep(lstcon_node_t *nd, unsigned feats, lstcon_rpc_t **crpc)
639 srpc_debug_reqst_t *drq;
642 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_DEBUG, feats, 0, 0, crpc);
646 drq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.dbg_reqst;
648 drq->dbg_sid = console_session.ses_id;
655 lstcon_batrpc_prep(lstcon_node_t *nd, int transop, unsigned feats,
656 lstcon_tsb_hdr_t *tsb, lstcon_rpc_t **crpc)
658 lstcon_batch_t *batch;
659 srpc_batch_reqst_t *brq;
662 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_BATCH, feats, 0, 0, crpc);
666 brq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.bat_reqst;
668 brq->bar_sid = console_session.ses_id;
669 brq->bar_bid = tsb->tsb_id;
670 brq->bar_testidx = tsb->tsb_index;
671 brq->bar_opc = transop == LST_TRANS_TSBRUN ? SRPC_BATCH_OPC_RUN :
672 (transop == LST_TRANS_TSBSTOP ? SRPC_BATCH_OPC_STOP :
673 SRPC_BATCH_OPC_QUERY);
675 if (transop != LST_TRANS_TSBRUN &&
676 transop != LST_TRANS_TSBSTOP)
679 LASSERT(tsb->tsb_index == 0);
681 batch = (lstcon_batch_t *)tsb;
682 brq->bar_arg = batch->bat_arg;
688 lstcon_statrpc_prep(lstcon_node_t *nd, unsigned feats, lstcon_rpc_t **crpc)
690 srpc_stat_reqst_t *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;
699 srq->str_sid = console_session.ses_id;
700 srq->str_type = 0; /* XXX remove it */
705 static lnet_process_id_packed_t *
706 lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov)
708 lnet_process_id_packed_t *pid;
711 i = idx / SFW_ID_PER_PAGE;
715 pid = (lnet_process_id_packed_t *)page_address(kiov[i].kiov_page);
717 return &pid[idx % SFW_ID_PER_PAGE];
721 lstcon_dstnodes_prep(lstcon_group_t *grp, int idx,
722 int dist, int span, int nkiov, lnet_kiov_t *kiov)
724 lnet_process_id_packed_t *pid;
725 lstcon_ndlink_t *ndl;
733 LASSERT(grp->grp_nnode >= 1);
735 if (span > grp->grp_nnode)
738 start = ((idx / dist) * span) % grp->grp_nnode;
739 end = ((idx / dist) * span + span - 1) % grp->grp_nnode;
741 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
748 if (i > (end >= start ? end : grp->grp_nnode))
751 pid = lstcon_next_id((i - start), nkiov, kiov);
752 pid->nid = nd->nd_id.nid;
753 pid->pid = nd->nd_id.pid;
757 if (start <= end) /* done */
760 list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link) {
761 if (i > grp->grp_nnode + end)
765 pid = lstcon_next_id((i - start), nkiov, kiov);
766 pid->nid = nd->nd_id.nid;
767 pid->pid = nd->nd_id.pid;
775 lstcon_pingrpc_prep(lst_test_ping_param_t *param, srpc_test_reqst_t *req)
777 test_ping_req_t *prq = &req->tsr_u.ping;
779 prq->png_size = param->png_size;
780 prq->png_flags = param->png_flags;
786 lstcon_bulkrpc_v0_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
788 test_bulk_req_t *brq = &req->tsr_u.bulk_v0;
790 brq->blk_opc = param->blk_opc;
791 brq->blk_npg = (param->blk_size + PAGE_CACHE_SIZE - 1) /
793 brq->blk_flags = param->blk_flags;
799 lstcon_bulkrpc_v1_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
801 test_bulk_req_v1_t *brq = &req->tsr_u.bulk_v1;
803 brq->blk_opc = param->blk_opc;
804 brq->blk_flags = param->blk_flags;
805 brq->blk_len = param->blk_size;
806 brq->blk_offset = 0; /* reserved */
812 lstcon_testrpc_prep(lstcon_node_t *nd, int transop, unsigned feats,
813 lstcon_test_t *test, lstcon_rpc_t **crpc)
815 lstcon_group_t *sgrp = test->tes_src_grp;
816 lstcon_group_t *dgrp = test->tes_dst_grp;
817 srpc_test_reqst_t *trq;
824 if (transop == LST_TRANS_TSBCLIADD) {
825 npg = sfw_id_pages(test->tes_span);
826 nob = (feats & LST_FEAT_BULK_LEN) == 0 ?
827 npg * PAGE_CACHE_SIZE :
828 sizeof(lnet_process_id_packed_t) * test->tes_span;
831 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc);
835 trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst;
837 if (transop == LST_TRANS_TSBSRVADD) {
838 int ndist = (sgrp->grp_nnode + test->tes_dist - 1) /
840 int nspan = (dgrp->grp_nnode + test->tes_span - 1) /
842 int nmax = (ndist + nspan - 1) / nspan;
845 trq->tsr_loop = nmax * test->tes_dist * test->tes_concur;
848 bulk = &(*crpc)->crp_rpc->crpc_bulk;
850 for (i = 0; i < npg; i++) {
855 len = (feats & LST_FEAT_BULK_LEN) == 0 ?
857 min_t(int, nob, PAGE_CACHE_SIZE);
860 bulk->bk_iovs[i].kiov_offset = 0;
861 bulk->bk_iovs[i].kiov_len = len;
862 bulk->bk_iovs[i].kiov_page =
863 alloc_page(GFP_KERNEL);
865 if (bulk->bk_iovs[i].kiov_page == NULL) {
866 lstcon_rpc_put(*crpc);
873 LASSERT(transop == LST_TRANS_TSBCLIADD);
875 rc = lstcon_dstnodes_prep(test->tes_dst_grp,
879 npg, &bulk->bk_iovs[0]);
881 lstcon_rpc_put(*crpc);
885 trq->tsr_ndest = test->tes_span;
886 trq->tsr_loop = test->tes_loop;
889 trq->tsr_sid = console_session.ses_id;
890 trq->tsr_bid = test->tes_hdr.tsb_id;
891 trq->tsr_concur = test->tes_concur;
892 trq->tsr_is_client = (transop == LST_TRANS_TSBCLIADD) ? 1 : 0;
893 trq->tsr_stop_onerr = !!test->tes_stop_onerr;
895 switch (test->tes_type) {
897 trq->tsr_service = SRPC_SERVICE_PING;
898 rc = lstcon_pingrpc_prep((lst_test_ping_param_t *)
899 &test->tes_param[0], trq);
903 trq->tsr_service = SRPC_SERVICE_BRW;
904 if ((feats & LST_FEAT_BULK_LEN) == 0) {
905 rc = lstcon_bulkrpc_v0_prep((lst_test_bulk_param_t *)
906 &test->tes_param[0], trq);
908 rc = lstcon_bulkrpc_v1_prep((lst_test_bulk_param_t *)
909 &test->tes_param[0], trq);
922 lstcon_sesnew_stat_reply(lstcon_rpc_trans_t *trans,
923 lstcon_node_t *nd, srpc_msg_t *reply)
925 srpc_mksn_reply_t *mksn_rep = &reply->msg_body.mksn_reply;
926 int status = mksn_rep->mksn_status;
929 (reply->msg_ses_feats & ~LST_FEATS_MASK) != 0) {
930 mksn_rep->mksn_status = EPROTO;
934 if (status == EPROTO) {
935 CNETERR("session protocol error from %s: %u\n",
936 libcfs_nid2str(nd->nd_id.nid),
937 reply->msg_ses_feats);
943 if (!trans->tas_feats_updated) {
944 trans->tas_feats_updated = 1;
945 trans->tas_features = reply->msg_ses_feats;
948 if (reply->msg_ses_feats != trans->tas_features) {
949 CNETERR("Framework features %x from %s is different with features on this transaction: %x\n",
950 reply->msg_ses_feats, libcfs_nid2str(nd->nd_id.nid),
951 trans->tas_features);
952 status = mksn_rep->mksn_status = EPROTO;
956 /* session timeout on remote node */
957 nd->nd_timeout = mksn_rep->mksn_timeout;
964 lstcon_rpc_stat_reply(lstcon_rpc_trans_t *trans, srpc_msg_t *msg,
965 lstcon_node_t *nd, lstcon_trans_stat_t *stat)
967 srpc_rmsn_reply_t *rmsn_rep;
968 srpc_debug_reply_t *dbg_rep;
969 srpc_batch_reply_t *bat_rep;
970 srpc_test_reply_t *test_rep;
971 srpc_stat_reply_t *stat_rep;
974 switch (trans->tas_opc) {
975 case LST_TRANS_SESNEW:
976 rc = lstcon_sesnew_stat_reply(trans, nd, msg);
978 lstcon_sesop_stat_success(stat, 1);
982 lstcon_sesop_stat_failure(stat, 1);
985 case LST_TRANS_SESEND:
986 rmsn_rep = &msg->msg_body.rmsn_reply;
987 /* ESRCH is not an error for end session */
988 if (rmsn_rep->rmsn_status == 0 ||
989 rmsn_rep->rmsn_status == ESRCH) {
990 lstcon_sesop_stat_success(stat, 1);
994 lstcon_sesop_stat_failure(stat, 1);
995 rc = rmsn_rep->rmsn_status;
998 case LST_TRANS_SESQRY:
999 case LST_TRANS_SESPING:
1000 dbg_rep = &msg->msg_body.dbg_reply;
1002 if (dbg_rep->dbg_status == ESRCH) {
1003 lstcon_sesqry_stat_unknown(stat, 1);
1007 if (lstcon_session_match(dbg_rep->dbg_sid))
1008 lstcon_sesqry_stat_active(stat, 1);
1010 lstcon_sesqry_stat_busy(stat, 1);
1013 case LST_TRANS_TSBRUN:
1014 case LST_TRANS_TSBSTOP:
1015 bat_rep = &msg->msg_body.bat_reply;
1017 if (bat_rep->bar_status == 0) {
1018 lstcon_tsbop_stat_success(stat, 1);
1022 if (bat_rep->bar_status == EPERM &&
1023 trans->tas_opc == LST_TRANS_TSBSTOP) {
1024 lstcon_tsbop_stat_success(stat, 1);
1028 lstcon_tsbop_stat_failure(stat, 1);
1029 rc = bat_rep->bar_status;
1032 case LST_TRANS_TSBCLIQRY:
1033 case LST_TRANS_TSBSRVQRY:
1034 bat_rep = &msg->msg_body.bat_reply;
1036 if (bat_rep->bar_active != 0)
1037 lstcon_tsbqry_stat_run(stat, 1);
1039 lstcon_tsbqry_stat_idle(stat, 1);
1041 if (bat_rep->bar_status == 0)
1044 lstcon_tsbqry_stat_failure(stat, 1);
1045 rc = bat_rep->bar_status;
1048 case LST_TRANS_TSBCLIADD:
1049 case LST_TRANS_TSBSRVADD:
1050 test_rep = &msg->msg_body.tes_reply;
1052 if (test_rep->tsr_status == 0) {
1053 lstcon_tsbop_stat_success(stat, 1);
1057 lstcon_tsbop_stat_failure(stat, 1);
1058 rc = test_rep->tsr_status;
1061 case LST_TRANS_STATQRY:
1062 stat_rep = &msg->msg_body.stat_reply;
1064 if (stat_rep->str_status == 0) {
1065 lstcon_statqry_stat_success(stat, 1);
1069 lstcon_statqry_stat_failure(stat, 1);
1070 rc = stat_rep->str_status;
1077 if (stat->trs_fwk_errno == 0)
1078 stat->trs_fwk_errno = rc;
1084 lstcon_rpc_trans_ndlist(struct list_head *ndlist,
1085 struct list_head *translist, int transop,
1086 void *arg, lstcon_rpc_cond_func_t condition,
1087 lstcon_rpc_trans_t **transpp)
1089 lstcon_rpc_trans_t *trans;
1090 lstcon_ndlink_t *ndl;
1096 /* Creating session RPG for list of nodes */
1098 rc = lstcon_rpc_trans_prep(translist, transop, &trans);
1100 CERROR("Can't create transaction %d: %d\n", transop, rc);
1104 feats = trans->tas_features;
1105 list_for_each_entry(ndl, ndlist, ndl_link) {
1106 rc = condition == NULL ? 1 :
1107 condition(transop, ndl->ndl_node, arg);
1113 CDEBUG(D_NET, "Condition error while creating RPC for transaction %d: %d\n",
1121 case LST_TRANS_SESNEW:
1122 case LST_TRANS_SESEND:
1123 rc = lstcon_sesrpc_prep(nd, transop, feats, &rpc);
1125 case LST_TRANS_SESQRY:
1126 case LST_TRANS_SESPING:
1127 rc = lstcon_dbgrpc_prep(nd, feats, &rpc);
1129 case LST_TRANS_TSBCLIADD:
1130 case LST_TRANS_TSBSRVADD:
1131 rc = lstcon_testrpc_prep(nd, transop, feats,
1132 (lstcon_test_t *)arg, &rpc);
1134 case LST_TRANS_TSBRUN:
1135 case LST_TRANS_TSBSTOP:
1136 case LST_TRANS_TSBCLIQRY:
1137 case LST_TRANS_TSBSRVQRY:
1138 rc = lstcon_batrpc_prep(nd, transop, feats,
1139 (lstcon_tsb_hdr_t *)arg, &rpc);
1141 case LST_TRANS_STATQRY:
1142 rc = lstcon_statrpc_prep(nd, feats, &rpc);
1150 CERROR("Failed to create RPC for transaction %s: %d\n",
1151 lstcon_rpc_trans_name(transop), rc);
1155 lstcon_rpc_trans_addreq(trans, rpc);
1163 lstcon_rpc_trans_destroy(trans);
1169 lstcon_rpc_pinger(void *arg)
1171 stt_timer_t *ptimer = (stt_timer_t *)arg;
1172 lstcon_rpc_trans_t *trans;
1175 srpc_debug_reqst_t *drq;
1176 lstcon_ndlink_t *ndl;
1182 /* RPC pinger is a special case of transaction,
1183 * it's called by timer at 8 seconds interval.
1185 mutex_lock(&console_session.ses_mutex);
1187 if (console_session.ses_shutdown || console_session.ses_expired) {
1188 mutex_unlock(&console_session.ses_mutex);
1192 if (!console_session.ses_expired &&
1193 ktime_get_real_seconds() - console_session.ses_laststamp >
1194 (time64_t)console_session.ses_timeout)
1195 console_session.ses_expired = 1;
1197 trans = console_session.ses_ping;
1199 LASSERT(trans != NULL);
1201 list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link) {
1204 if (console_session.ses_expired) {
1205 /* idle console, end session on all nodes */
1206 if (nd->nd_state != LST_NODE_ACTIVE)
1209 rc = lstcon_sesrpc_prep(nd, LST_TRANS_SESEND,
1210 trans->tas_features, &crpc);
1212 CERROR("Out of memory\n");
1216 lstcon_rpc_trans_addreq(trans, crpc);
1217 lstcon_rpc_post(crpc);
1222 crpc = &nd->nd_ping;
1224 if (crpc->crp_rpc != NULL) {
1225 LASSERT(crpc->crp_trans == trans);
1226 LASSERT(!list_empty(&crpc->crp_link));
1228 spin_lock(&crpc->crp_rpc->crpc_lock);
1230 LASSERT(crpc->crp_posted);
1232 if (!crpc->crp_finished) {
1234 spin_unlock(&crpc->crp_rpc->crpc_lock);
1238 spin_unlock(&crpc->crp_rpc->crpc_lock);
1240 lstcon_rpc_get_reply(crpc, &rep);
1242 list_del_init(&crpc->crp_link);
1244 lstcon_rpc_put(crpc);
1247 if (nd->nd_state != LST_NODE_ACTIVE)
1250 intv = (jiffies - nd->nd_stamp) / HZ;
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 stt_timer_t *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(lstcon_trans_stat_t));
1322 console_session.ses_ping = NULL;
1326 lstcon_rpc_cleanup_wait(void)
1328 lstcon_rpc_trans_t *trans;
1330 struct list_head *pacer;
1331 struct list_head zlist;
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, lstcon_rpc_trans_t,
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, waiting for termination of transactions\n");
1351 set_current_state(TASK_UNINTERRUPTIBLE);
1352 schedule_timeout(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 accessible or target is down, waiting for %d console RPCs to being recycled\n",
1362 atomic_read(&console_session.ses_rpc_counter));
1364 list_add(&zlist, &console_session.ses_rpc_freelist);
1365 list_del_init(&console_session.ses_rpc_freelist);
1367 spin_unlock(&console_session.ses_rpc_lock);
1369 while (!list_empty(&zlist)) {
1370 crpc = list_entry(zlist.next, lstcon_rpc_t, crp_link);
1372 list_del(&crpc->crp_link);
1373 LIBCFS_FREE(crpc, sizeof(lstcon_rpc_t));
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);