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) 2012, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 * Author: Isaac Huang <isaac@clusterfs.com>
40 * 2012-05-13: Liang Zhen <liang@whamcloud.com>
41 * - percpt data for service to improve smp performance
45 #define DEBUG_SUBSYSTEM S_LNET
57 static struct smoketest_rpc {
58 spinlock_t rpc_glock; /* global lock */
59 srpc_service_t *rpc_services[SRPC_SERVICE_MAX_ID + 1];
60 lnet_handle_eq_t rpc_lnet_eq; /* _the_ LNet event queue */
61 srpc_state_t rpc_state;
62 srpc_counters_t rpc_counters;
63 __u64 rpc_matchbits; /* matchbits counter */
67 srpc_serv_portal(int svc_id)
69 return svc_id < SRPC_FRAMEWORK_SERVICE_MAX_ID ?
70 SRPC_FRAMEWORK_REQUEST_PORTAL : SRPC_REQUEST_PORTAL;
74 int srpc_handle_rpc (swi_workitem_t *wi);
76 void srpc_get_counters (srpc_counters_t *cnt)
78 spin_lock(&srpc_data.rpc_glock);
79 *cnt = srpc_data.rpc_counters;
80 spin_unlock(&srpc_data.rpc_glock);
83 void srpc_set_counters (const srpc_counters_t *cnt)
85 spin_lock(&srpc_data.rpc_glock);
86 srpc_data.rpc_counters = *cnt;
87 spin_unlock(&srpc_data.rpc_glock);
91 srpc_add_bulk_page(srpc_bulk_t *bk, struct page *pg, int i, int nob)
93 nob = min(nob, (int)PAGE_CACHE_SIZE);
96 LASSERT(i >= 0 && i < bk->bk_niov);
98 bk->bk_iovs[i].kiov_offset = 0;
99 bk->bk_iovs[i].kiov_page = pg;
100 bk->bk_iovs[i].kiov_len = nob;
105 srpc_free_bulk (srpc_bulk_t *bk)
110 LASSERT (bk != NULL);
112 for (i = 0; i < bk->bk_niov; i++) {
113 pg = bk->bk_iovs[i].kiov_page;
114 if (pg == NULL) break;
119 LIBCFS_FREE(bk, offsetof(srpc_bulk_t, bk_iovs[bk->bk_niov]));
124 srpc_alloc_bulk(int cpt, unsigned bulk_npg, unsigned bulk_len, int sink)
129 LASSERT(bulk_npg > 0 && bulk_npg <= LNET_MAX_IOV);
131 LIBCFS_CPT_ALLOC(bk, lnet_cpt_table(), cpt,
132 offsetof(srpc_bulk_t, bk_iovs[bulk_npg]));
134 CERROR("Can't allocate descriptor for %d pages\n", bulk_npg);
138 memset(bk, 0, offsetof(srpc_bulk_t, bk_iovs[bulk_npg]));
140 bk->bk_len = bulk_len;
141 bk->bk_niov = bulk_npg;
143 for (i = 0; i < bulk_npg; i++) {
147 pg = cfs_page_cpt_alloc(lnet_cpt_table(), cpt, GFP_IOFS);
149 CERROR("Can't allocate page %d of %d\n", i, bulk_npg);
154 nob = srpc_add_bulk_page(bk, pg, i, bulk_len);
166 spin_lock(&srpc_data.rpc_glock);
167 id = srpc_data.rpc_matchbits++;
168 spin_unlock(&srpc_data.rpc_glock);
173 srpc_init_server_rpc(struct srpc_server_rpc *rpc,
174 struct srpc_service_cd *scd,
175 struct srpc_buffer *buffer)
177 memset(rpc, 0, sizeof(*rpc));
178 swi_init_workitem(&rpc->srpc_wi, rpc, srpc_handle_rpc,
179 srpc_serv_is_framework(scd->scd_svc) ?
180 lst_sched_serial : lst_sched_test[scd->scd_cpt]);
182 rpc->srpc_ev.ev_fired = 1; /* no event expected now */
185 rpc->srpc_reqstbuf = buffer;
186 rpc->srpc_peer = buffer->buf_peer;
187 rpc->srpc_self = buffer->buf_self;
188 LNetInvalidateHandle(&rpc->srpc_replymdh);
192 srpc_service_fini(struct srpc_service *svc)
194 struct srpc_service_cd *scd;
195 struct srpc_server_rpc *rpc;
196 struct srpc_buffer *buf;
200 if (svc->sv_cpt_data == NULL)
203 cfs_percpt_for_each(scd, i, svc->sv_cpt_data) {
205 if (!list_empty(&scd->scd_buf_posted))
206 q = &scd->scd_buf_posted;
207 else if (!list_empty(&scd->scd_buf_blocked))
208 q = &scd->scd_buf_blocked;
212 while (!list_empty(q)) {
213 buf = list_entry(q->next,
216 list_del(&buf->buf_list);
217 LIBCFS_FREE(buf, sizeof(*buf));
221 LASSERT(list_empty(&scd->scd_rpc_active));
223 while (!list_empty(&scd->scd_rpc_free)) {
224 rpc = list_entry(scd->scd_rpc_free.next,
225 struct srpc_server_rpc,
227 list_del(&rpc->srpc_list);
228 LIBCFS_FREE(rpc, sizeof(*rpc));
232 cfs_percpt_free(svc->sv_cpt_data);
233 svc->sv_cpt_data = NULL;
237 srpc_service_nrpcs(struct srpc_service *svc)
239 int nrpcs = svc->sv_wi_total / svc->sv_ncpts;
241 return srpc_serv_is_framework(svc) ?
242 max(nrpcs, SFW_FRWK_WI_MIN) : max(nrpcs, SFW_TEST_WI_MIN);
245 int srpc_add_buffer(struct swi_workitem *wi);
248 srpc_service_init(struct srpc_service *svc)
250 struct srpc_service_cd *scd;
251 struct srpc_server_rpc *rpc;
256 svc->sv_shuttingdown = 0;
258 svc->sv_cpt_data = cfs_percpt_alloc(lnet_cpt_table(),
259 sizeof(struct srpc_service_cd));
260 if (svc->sv_cpt_data == NULL)
263 svc->sv_ncpts = srpc_serv_is_framework(svc) ?
264 1 : cfs_cpt_number(lnet_cpt_table());
265 nrpcs = srpc_service_nrpcs(svc);
267 cfs_percpt_for_each(scd, i, svc->sv_cpt_data) {
270 spin_lock_init(&scd->scd_lock);
271 INIT_LIST_HEAD(&scd->scd_rpc_free);
272 INIT_LIST_HEAD(&scd->scd_rpc_active);
273 INIT_LIST_HEAD(&scd->scd_buf_posted);
274 INIT_LIST_HEAD(&scd->scd_buf_blocked);
276 scd->scd_ev.ev_data = scd;
277 scd->scd_ev.ev_type = SRPC_REQUEST_RCVD;
279 /* NB: don't use lst_sched_serial for adding buffer,
280 * see details in srpc_service_add_buffers() */
281 swi_init_workitem(&scd->scd_buf_wi, scd,
282 srpc_add_buffer, lst_sched_test[i]);
284 if (i != 0 && srpc_serv_is_framework(svc)) {
285 /* NB: framework service only needs srpc_service_cd for
286 * one partition, but we allocate for all to make
287 * it easier to implement, it will waste a little
288 * memory but nobody should care about this */
292 for (j = 0; j < nrpcs; j++) {
293 LIBCFS_CPT_ALLOC(rpc, lnet_cpt_table(),
296 srpc_service_fini(svc);
299 list_add(&rpc->srpc_list, &scd->scd_rpc_free);
307 srpc_add_service(struct srpc_service *sv)
311 LASSERT(0 <= id && id <= SRPC_SERVICE_MAX_ID);
313 if (srpc_service_init(sv) != 0)
316 spin_lock(&srpc_data.rpc_glock);
318 LASSERT(srpc_data.rpc_state == SRPC_STATE_RUNNING);
320 if (srpc_data.rpc_services[id] != NULL) {
321 spin_unlock(&srpc_data.rpc_glock);
325 srpc_data.rpc_services[id] = sv;
326 spin_unlock(&srpc_data.rpc_glock);
328 CDEBUG(D_NET, "Adding service: id %d, name %s\n", id, sv->sv_name);
332 srpc_service_fini(sv);
337 srpc_remove_service (srpc_service_t *sv)
341 spin_lock(&srpc_data.rpc_glock);
343 if (srpc_data.rpc_services[id] != sv) {
344 spin_unlock(&srpc_data.rpc_glock);
348 srpc_data.rpc_services[id] = NULL;
349 spin_unlock(&srpc_data.rpc_glock);
354 srpc_post_passive_rdma(int portal, int local, __u64 matchbits, void *buf,
355 int len, int options, lnet_process_id_t peer,
356 lnet_handle_md_t *mdh, srpc_event_t *ev)
360 lnet_handle_me_t meh;
362 rc = LNetMEAttach(portal, peer, matchbits, 0, LNET_UNLINK,
363 local ? LNET_INS_LOCAL : LNET_INS_AFTER, &meh);
365 CERROR ("LNetMEAttach failed: %d\n", rc);
366 LASSERT (rc == -ENOMEM);
374 md.options = options;
375 md.eq_handle = srpc_data.rpc_lnet_eq;
377 rc = LNetMDAttach(meh, md, LNET_UNLINK, mdh);
379 CERROR ("LNetMDAttach failed: %d\n", rc);
380 LASSERT (rc == -ENOMEM);
382 rc = LNetMEUnlink(meh);
388 "Posted passive RDMA: peer %s, portal %d, matchbits "LPX64"\n",
389 libcfs_id2str(peer), portal, matchbits);
394 srpc_post_active_rdma(int portal, __u64 matchbits, void *buf, int len,
395 int options, lnet_process_id_t peer, lnet_nid_t self,
396 lnet_handle_md_t *mdh, srpc_event_t *ev)
404 md.eq_handle = srpc_data.rpc_lnet_eq;
405 md.threshold = ((options & LNET_MD_OP_GET) != 0) ? 2 : 1;
406 md.options = options & ~(LNET_MD_OP_PUT | LNET_MD_OP_GET);
408 rc = LNetMDBind(md, LNET_UNLINK, mdh);
410 CERROR ("LNetMDBind failed: %d\n", rc);
411 LASSERT (rc == -ENOMEM);
415 /* this is kind of an abuse of the LNET_MD_OP_{PUT,GET} options.
416 * they're only meaningful for MDs attached to an ME (i.e. passive
418 if ((options & LNET_MD_OP_PUT) != 0) {
419 rc = LNetPut(self, *mdh, LNET_NOACK_REQ, peer,
420 portal, matchbits, 0, 0);
422 LASSERT ((options & LNET_MD_OP_GET) != 0);
424 rc = LNetGet(self, *mdh, peer, portal, matchbits, 0);
428 CERROR ("LNet%s(%s, %d, "LPD64") failed: %d\n",
429 ((options & LNET_MD_OP_PUT) != 0) ? "Put" : "Get",
430 libcfs_id2str(peer), portal, matchbits, rc);
432 /* The forthcoming unlink event will complete this operation
433 * with failure, so fall through and return success here.
435 rc = LNetMDUnlink(*mdh);
439 "Posted active RDMA: peer %s, portal %u, matchbits "LPX64"\n",
440 libcfs_id2str(peer), portal, matchbits);
446 srpc_post_active_rqtbuf(lnet_process_id_t peer, int service, void *buf,
447 int len, lnet_handle_md_t *mdh, srpc_event_t *ev)
449 return srpc_post_active_rdma(srpc_serv_portal(service), service,
450 buf, len, LNET_MD_OP_PUT, peer,
451 LNET_NID_ANY, mdh, ev);
455 srpc_post_passive_rqtbuf(int service, int local, void *buf, int len,
456 lnet_handle_md_t *mdh, srpc_event_t *ev)
458 lnet_process_id_t any = {0};
460 any.nid = LNET_NID_ANY;
461 any.pid = LNET_PID_ANY;
463 return srpc_post_passive_rdma(srpc_serv_portal(service),
464 local, service, buf, len,
465 LNET_MD_OP_PUT, any, mdh, ev);
469 srpc_service_post_buffer(struct srpc_service_cd *scd, struct srpc_buffer *buf)
470 __must_hold(&scd->scd_lock)
472 struct srpc_service *sv = scd->scd_svc;
473 struct srpc_msg *msg = &buf->buf_msg;
476 LNetInvalidateHandle(&buf->buf_mdh);
477 list_add(&buf->buf_list, &scd->scd_buf_posted);
478 scd->scd_buf_nposted++;
479 spin_unlock(&scd->scd_lock);
481 rc = srpc_post_passive_rqtbuf(sv->sv_id,
482 !srpc_serv_is_framework(sv),
483 msg, sizeof(*msg), &buf->buf_mdh,
486 /* At this point, a RPC (new or delayed) may have arrived in
487 * msg and its event handler has been called. So we must add
488 * buf to scd_buf_posted _before_ dropping scd_lock */
490 spin_lock(&scd->scd_lock);
493 if (!sv->sv_shuttingdown)
496 spin_unlock(&scd->scd_lock);
497 /* srpc_shutdown_service might have tried to unlink me
498 * when my buf_mdh was still invalid */
499 LNetMDUnlink(buf->buf_mdh);
500 spin_lock(&scd->scd_lock);
504 scd->scd_buf_nposted--;
505 if (sv->sv_shuttingdown)
506 return rc; /* don't allow to change scd_buf_posted */
508 list_del(&buf->buf_list);
509 spin_unlock(&scd->scd_lock);
511 LIBCFS_FREE(buf, sizeof(*buf));
513 spin_lock(&scd->scd_lock);
518 srpc_add_buffer(struct swi_workitem *wi)
520 struct srpc_service_cd *scd = wi->swi_workitem.wi_data;
521 struct srpc_buffer *buf;
524 /* it's called by workitem scheduler threads, these threads
525 * should have been set CPT affinity, so buffers will be posted
526 * on CPT local list of Portal */
527 spin_lock(&scd->scd_lock);
529 while (scd->scd_buf_adjust > 0 &&
530 !scd->scd_svc->sv_shuttingdown) {
531 scd->scd_buf_adjust--; /* consume it */
532 scd->scd_buf_posting++;
534 spin_unlock(&scd->scd_lock);
536 LIBCFS_ALLOC(buf, sizeof(*buf));
538 CERROR("Failed to add new buf to service: %s\n",
539 scd->scd_svc->sv_name);
540 spin_lock(&scd->scd_lock);
545 spin_lock(&scd->scd_lock);
546 if (scd->scd_svc->sv_shuttingdown) {
547 spin_unlock(&scd->scd_lock);
548 LIBCFS_FREE(buf, sizeof(*buf));
550 spin_lock(&scd->scd_lock);
555 rc = srpc_service_post_buffer(scd, buf);
557 break; /* buf has been freed inside */
559 LASSERT(scd->scd_buf_posting > 0);
560 scd->scd_buf_posting--;
561 scd->scd_buf_total++;
562 scd->scd_buf_low = MAX(2, scd->scd_buf_total / 4);
566 scd->scd_buf_err_stamp = cfs_time_current_sec();
567 scd->scd_buf_err = rc;
569 LASSERT(scd->scd_buf_posting > 0);
570 scd->scd_buf_posting--;
573 spin_unlock(&scd->scd_lock);
578 srpc_service_add_buffers(struct srpc_service *sv, int nbuffer)
580 struct srpc_service_cd *scd;
584 LASSERTF(nbuffer > 0, "nbuffer must be positive: %d\n", nbuffer);
586 cfs_percpt_for_each(scd, i, sv->sv_cpt_data) {
587 spin_lock(&scd->scd_lock);
589 scd->scd_buf_err = 0;
590 scd->scd_buf_err_stamp = 0;
591 scd->scd_buf_posting = 0;
592 scd->scd_buf_adjust = nbuffer;
593 /* start to post buffers */
594 swi_schedule_workitem(&scd->scd_buf_wi);
595 spin_unlock(&scd->scd_lock);
597 /* framework service only post buffer for one partition */
598 if (srpc_serv_is_framework(sv))
602 cfs_percpt_for_each(scd, i, sv->sv_cpt_data) {
603 spin_lock(&scd->scd_lock);
605 * NB: srpc_service_add_buffers() can be called inside
606 * thread context of lst_sched_serial, and we don't normally
607 * allow to sleep inside thread context of WI scheduler
608 * because it will block current scheduler thread from doing
609 * anything else, even worse, it could deadlock if it's
610 * waiting on result from another WI of the same scheduler.
611 * However, it's safe at here because scd_buf_wi is scheduled
612 * by thread in a different WI scheduler (lst_sched_test),
613 * so we don't have any risk of deadlock, though this could
614 * block all WIs pending on lst_sched_serial for a moment
615 * which is not good but not fatal.
617 lst_wait_until(scd->scd_buf_err != 0 ||
618 (scd->scd_buf_adjust == 0 &&
619 scd->scd_buf_posting == 0),
620 scd->scd_lock, "waiting for adding buffer\n");
622 if (scd->scd_buf_err != 0 && rc == 0)
623 rc = scd->scd_buf_err;
625 spin_unlock(&scd->scd_lock);
632 srpc_service_remove_buffers(struct srpc_service *sv, int nbuffer)
634 struct srpc_service_cd *scd;
638 LASSERT(!sv->sv_shuttingdown);
640 cfs_percpt_for_each(scd, i, sv->sv_cpt_data) {
641 spin_lock(&scd->scd_lock);
643 num = scd->scd_buf_total + scd->scd_buf_posting;
644 scd->scd_buf_adjust -= min(nbuffer, num);
646 spin_unlock(&scd->scd_lock);
650 /* returns 1 if sv has finished, otherwise 0 */
652 srpc_finish_service(struct srpc_service *sv)
654 struct srpc_service_cd *scd;
655 struct srpc_server_rpc *rpc;
658 LASSERT(sv->sv_shuttingdown); /* srpc_shutdown_service called */
660 cfs_percpt_for_each(scd, i, sv->sv_cpt_data) {
661 spin_lock(&scd->scd_lock);
662 if (!swi_deschedule_workitem(&scd->scd_buf_wi)) {
663 spin_unlock(&scd->scd_lock);
667 if (scd->scd_buf_nposted > 0) {
668 CDEBUG(D_NET, "waiting for %d posted buffers to "
669 "unlink\n", scd->scd_buf_nposted);
670 spin_unlock(&scd->scd_lock);
674 if (list_empty(&scd->scd_rpc_active)) {
675 spin_unlock(&scd->scd_lock);
679 rpc = list_entry(scd->scd_rpc_active.next,
680 struct srpc_server_rpc, srpc_list);
681 CNETERR("Active RPC %p on shutdown: sv %s, peer %s, "
682 "wi %s scheduled %d running %d, "
683 "ev fired %d type %d status %d lnet %d\n",
684 rpc, sv->sv_name, libcfs_id2str(rpc->srpc_peer),
685 swi_state2str(rpc->srpc_wi.swi_state),
686 rpc->srpc_wi.swi_workitem.wi_scheduled,
687 rpc->srpc_wi.swi_workitem.wi_running,
688 rpc->srpc_ev.ev_fired, rpc->srpc_ev.ev_type,
689 rpc->srpc_ev.ev_status, rpc->srpc_ev.ev_lnet);
690 spin_unlock(&scd->scd_lock);
694 /* no lock needed from now on */
695 srpc_service_fini(sv);
699 /* called with sv->sv_lock held */
701 srpc_service_recycle_buffer(struct srpc_service_cd *scd, srpc_buffer_t *buf)
702 __must_hold(&scd->scd_lock)
704 if (!scd->scd_svc->sv_shuttingdown && scd->scd_buf_adjust >= 0) {
705 if (srpc_service_post_buffer(scd, buf) != 0) {
706 CWARN("Failed to post %s buffer\n",
707 scd->scd_svc->sv_name);
712 /* service is shutting down, or we want to recycle some buffers */
713 scd->scd_buf_total--;
715 if (scd->scd_buf_adjust < 0) {
716 scd->scd_buf_adjust++;
717 if (scd->scd_buf_adjust < 0 &&
718 scd->scd_buf_total == 0 && scd->scd_buf_posting == 0) {
720 "Try to recyle %d buffers but nothing left\n",
721 scd->scd_buf_adjust);
722 scd->scd_buf_adjust = 0;
726 spin_unlock(&scd->scd_lock);
727 LIBCFS_FREE(buf, sizeof(*buf));
728 spin_lock(&scd->scd_lock);
732 srpc_abort_service(struct srpc_service *sv)
734 struct srpc_service_cd *scd;
735 struct srpc_server_rpc *rpc;
738 CDEBUG(D_NET, "Aborting service: id %d, name %s\n",
739 sv->sv_id, sv->sv_name);
741 cfs_percpt_for_each(scd, i, sv->sv_cpt_data) {
742 spin_lock(&scd->scd_lock);
744 /* schedule in-flight RPCs to notice the abort, NB:
745 * racing with incoming RPCs; complete fix should make test
746 * RPCs carry session ID in its headers */
747 list_for_each_entry(rpc, &scd->scd_rpc_active, srpc_list) {
748 rpc->srpc_aborted = 1;
749 swi_schedule_workitem(&rpc->srpc_wi);
752 spin_unlock(&scd->scd_lock);
757 srpc_shutdown_service(srpc_service_t *sv)
759 struct srpc_service_cd *scd;
760 struct srpc_server_rpc *rpc;
764 CDEBUG(D_NET, "Shutting down service: id %d, name %s\n",
765 sv->sv_id, sv->sv_name);
767 cfs_percpt_for_each(scd, i, sv->sv_cpt_data)
768 spin_lock(&scd->scd_lock);
770 sv->sv_shuttingdown = 1; /* i.e. no new active RPC */
772 cfs_percpt_for_each(scd, i, sv->sv_cpt_data)
773 spin_unlock(&scd->scd_lock);
775 cfs_percpt_for_each(scd, i, sv->sv_cpt_data) {
776 spin_lock(&scd->scd_lock);
778 /* schedule in-flight RPCs to notice the shutdown */
779 list_for_each_entry(rpc, &scd->scd_rpc_active, srpc_list)
780 swi_schedule_workitem(&rpc->srpc_wi);
782 spin_unlock(&scd->scd_lock);
784 /* OK to traverse scd_buf_posted without lock, since no one
785 * touches scd_buf_posted now */
786 list_for_each_entry(buf, &scd->scd_buf_posted, buf_list)
787 LNetMDUnlink(buf->buf_mdh);
792 srpc_send_request (srpc_client_rpc_t *rpc)
794 srpc_event_t *ev = &rpc->crpc_reqstev;
799 ev->ev_type = SRPC_REQUEST_SENT;
801 rc = srpc_post_active_rqtbuf(rpc->crpc_dest, rpc->crpc_service,
802 &rpc->crpc_reqstmsg, sizeof(srpc_msg_t),
803 &rpc->crpc_reqstmdh, ev);
805 LASSERT (rc == -ENOMEM);
806 ev->ev_fired = 1; /* no more event expected */
812 srpc_prepare_reply (srpc_client_rpc_t *rpc)
814 srpc_event_t *ev = &rpc->crpc_replyev;
815 __u64 *id = &rpc->crpc_reqstmsg.msg_body.reqst.rpyid;
820 ev->ev_type = SRPC_REPLY_RCVD;
822 *id = srpc_next_id();
824 rc = srpc_post_passive_rdma(SRPC_RDMA_PORTAL, 0, *id,
825 &rpc->crpc_replymsg, sizeof(srpc_msg_t),
826 LNET_MD_OP_PUT, rpc->crpc_dest,
827 &rpc->crpc_replymdh, ev);
829 LASSERT (rc == -ENOMEM);
830 ev->ev_fired = 1; /* no more event expected */
836 srpc_prepare_bulk (srpc_client_rpc_t *rpc)
838 srpc_bulk_t *bk = &rpc->crpc_bulk;
839 srpc_event_t *ev = &rpc->crpc_bulkev;
840 __u64 *id = &rpc->crpc_reqstmsg.msg_body.reqst.bulkid;
844 LASSERT (bk->bk_niov <= LNET_MAX_IOV);
846 if (bk->bk_niov == 0) return 0; /* nothing to do */
848 opt = bk->bk_sink ? LNET_MD_OP_PUT : LNET_MD_OP_GET;
853 ev->ev_type = SRPC_BULK_REQ_RCVD;
855 *id = srpc_next_id();
857 rc = srpc_post_passive_rdma(SRPC_RDMA_PORTAL, 0, *id,
858 &bk->bk_iovs[0], bk->bk_niov, opt,
859 rpc->crpc_dest, &bk->bk_mdh, ev);
861 LASSERT (rc == -ENOMEM);
862 ev->ev_fired = 1; /* no more event expected */
868 srpc_do_bulk (srpc_server_rpc_t *rpc)
870 srpc_event_t *ev = &rpc->srpc_ev;
871 srpc_bulk_t *bk = rpc->srpc_bulk;
872 __u64 id = rpc->srpc_reqstbuf->buf_msg.msg_body.reqst.bulkid;
876 LASSERT (bk != NULL);
878 opt = bk->bk_sink ? LNET_MD_OP_GET : LNET_MD_OP_PUT;
883 ev->ev_type = bk->bk_sink ? SRPC_BULK_GET_RPLD : SRPC_BULK_PUT_SENT;
885 rc = srpc_post_active_rdma(SRPC_RDMA_PORTAL, id,
886 &bk->bk_iovs[0], bk->bk_niov, opt,
887 rpc->srpc_peer, rpc->srpc_self,
890 ev->ev_fired = 1; /* no more event expected */
894 /* only called from srpc_handle_rpc */
896 srpc_server_rpc_done(srpc_server_rpc_t *rpc, int status)
898 struct srpc_service_cd *scd = rpc->srpc_scd;
899 struct srpc_service *sv = scd->scd_svc;
900 srpc_buffer_t *buffer;
902 LASSERT (status != 0 || rpc->srpc_wi.swi_state == SWI_STATE_DONE);
904 rpc->srpc_status = status;
906 CDEBUG_LIMIT (status == 0 ? D_NET : D_NETERROR,
907 "Server RPC %p done: service %s, peer %s, status %s:%d\n",
908 rpc, sv->sv_name, libcfs_id2str(rpc->srpc_peer),
909 swi_state2str(rpc->srpc_wi.swi_state), status);
912 spin_lock(&srpc_data.rpc_glock);
913 srpc_data.rpc_counters.rpcs_dropped++;
914 spin_unlock(&srpc_data.rpc_glock);
917 if (rpc->srpc_done != NULL)
918 (*rpc->srpc_done) (rpc);
919 LASSERT(rpc->srpc_bulk == NULL);
921 spin_lock(&scd->scd_lock);
923 if (rpc->srpc_reqstbuf != NULL) {
924 /* NB might drop sv_lock in srpc_service_recycle_buffer, but
925 * sv won't go away for scd_rpc_active must not be empty */
926 srpc_service_recycle_buffer(scd, rpc->srpc_reqstbuf);
927 rpc->srpc_reqstbuf = NULL;
930 list_del(&rpc->srpc_list); /* from scd->scd_rpc_active */
933 * No one can schedule me now since:
934 * - I'm not on scd_rpc_active.
935 * - all LNet events have been fired.
936 * Cancel pending schedules and prevent future schedule attempts:
938 LASSERT(rpc->srpc_ev.ev_fired);
939 swi_exit_workitem(&rpc->srpc_wi);
941 if (!sv->sv_shuttingdown && !list_empty(&scd->scd_buf_blocked)) {
942 buffer = list_entry(scd->scd_buf_blocked.next,
943 srpc_buffer_t, buf_list);
944 list_del(&buffer->buf_list);
946 srpc_init_server_rpc(rpc, scd, buffer);
947 list_add_tail(&rpc->srpc_list, &scd->scd_rpc_active);
948 swi_schedule_workitem(&rpc->srpc_wi);
950 list_add(&rpc->srpc_list, &scd->scd_rpc_free);
953 spin_unlock(&scd->scd_lock);
957 /* handles an incoming RPC */
959 srpc_handle_rpc(swi_workitem_t *wi)
961 struct srpc_server_rpc *rpc = wi->swi_workitem.wi_data;
962 struct srpc_service_cd *scd = rpc->srpc_scd;
963 struct srpc_service *sv = scd->scd_svc;
964 srpc_event_t *ev = &rpc->srpc_ev;
967 LASSERT(wi == &rpc->srpc_wi);
969 spin_lock(&scd->scd_lock);
971 if (sv->sv_shuttingdown || rpc->srpc_aborted) {
972 spin_unlock(&scd->scd_lock);
974 if (rpc->srpc_bulk != NULL)
975 LNetMDUnlink(rpc->srpc_bulk->bk_mdh);
976 LNetMDUnlink(rpc->srpc_replymdh);
978 if (ev->ev_fired) { /* no more event, OK to finish */
979 srpc_server_rpc_done(rpc, -ESHUTDOWN);
985 spin_unlock(&scd->scd_lock);
987 switch (wi->swi_state) {
990 case SWI_STATE_NEWBORN: {
992 srpc_generic_reply_t *reply;
994 msg = &rpc->srpc_reqstbuf->buf_msg;
995 reply = &rpc->srpc_replymsg.msg_body.reply;
997 if (msg->msg_magic == 0) {
998 /* moaned already in srpc_lnet_ev_handler */
999 srpc_server_rpc_done(rpc, EBADMSG);
1003 srpc_unpack_msg_hdr(msg);
1004 if (msg->msg_version != SRPC_MSG_VERSION) {
1005 CWARN("Version mismatch: %u, %u expected, from %s\n",
1006 msg->msg_version, SRPC_MSG_VERSION,
1007 libcfs_id2str(rpc->srpc_peer));
1008 reply->status = EPROTO;
1009 /* drop through and send reply */
1012 rc = (*sv->sv_handler)(rpc);
1013 LASSERT(reply->status == 0 || !rpc->srpc_bulk);
1015 srpc_server_rpc_done(rpc, rc);
1020 wi->swi_state = SWI_STATE_BULK_STARTED;
1022 if (rpc->srpc_bulk != NULL) {
1023 rc = srpc_do_bulk(rpc);
1025 return 0; /* wait for bulk */
1027 LASSERT (ev->ev_fired);
1031 case SWI_STATE_BULK_STARTED:
1032 LASSERT (rpc->srpc_bulk == NULL || ev->ev_fired);
1034 if (rpc->srpc_bulk != NULL) {
1037 if (sv->sv_bulk_ready != NULL)
1038 rc = (*sv->sv_bulk_ready) (rpc, rc);
1041 srpc_server_rpc_done(rpc, rc);
1046 wi->swi_state = SWI_STATE_REPLY_SUBMITTED;
1047 rc = srpc_send_reply(rpc);
1049 return 0; /* wait for reply */
1050 srpc_server_rpc_done(rpc, rc);
1053 case SWI_STATE_REPLY_SUBMITTED:
1054 if (!ev->ev_fired) {
1055 CERROR("RPC %p: bulk %p, service %d\n",
1056 rpc, rpc->srpc_bulk, sv->sv_id);
1057 CERROR("Event: status %d, type %d, lnet %d\n",
1058 ev->ev_status, ev->ev_type, ev->ev_lnet);
1059 LASSERT (ev->ev_fired);
1062 wi->swi_state = SWI_STATE_DONE;
1063 srpc_server_rpc_done(rpc, ev->ev_status);
1071 srpc_client_rpc_expired (void *data)
1073 srpc_client_rpc_t *rpc = data;
1075 CWARN ("Client RPC expired: service %d, peer %s, timeout %d.\n",
1076 rpc->crpc_service, libcfs_id2str(rpc->crpc_dest),
1079 spin_lock(&rpc->crpc_lock);
1081 rpc->crpc_timeout = 0;
1082 srpc_abort_rpc(rpc, -ETIMEDOUT);
1084 spin_unlock(&rpc->crpc_lock);
1086 spin_lock(&srpc_data.rpc_glock);
1087 srpc_data.rpc_counters.rpcs_expired++;
1088 spin_unlock(&srpc_data.rpc_glock);
1092 srpc_add_client_rpc_timer(srpc_client_rpc_t *rpc)
1094 stt_timer_t *timer = &rpc->crpc_timer;
1096 if (rpc->crpc_timeout == 0)
1099 INIT_LIST_HEAD(&timer->stt_list);
1100 timer->stt_data = rpc;
1101 timer->stt_func = srpc_client_rpc_expired;
1102 timer->stt_expires = cfs_time_add(rpc->crpc_timeout,
1103 cfs_time_current_sec());
1104 stt_add_timer(timer);
1109 * Called with rpc->crpc_lock held.
1111 * Upon exit the RPC expiry timer is not queued and the handler is not
1112 * running on any CPU. */
1114 srpc_del_client_rpc_timer (srpc_client_rpc_t *rpc)
1116 /* timer not planted or already exploded */
1117 if (rpc->crpc_timeout == 0)
1120 /* timer successfully defused */
1121 if (stt_del_timer(&rpc->crpc_timer))
1124 /* timer detonated, wait for it to explode */
1125 while (rpc->crpc_timeout != 0) {
1126 spin_unlock(&rpc->crpc_lock);
1130 spin_lock(&rpc->crpc_lock);
1135 srpc_client_rpc_done (srpc_client_rpc_t *rpc, int status)
1137 swi_workitem_t *wi = &rpc->crpc_wi;
1139 LASSERT(status != 0 || wi->swi_state == SWI_STATE_DONE);
1141 spin_lock(&rpc->crpc_lock);
1143 rpc->crpc_closed = 1;
1144 if (rpc->crpc_status == 0)
1145 rpc->crpc_status = status;
1147 srpc_del_client_rpc_timer(rpc);
1149 CDEBUG_LIMIT ((status == 0) ? D_NET : D_NETERROR,
1150 "Client RPC done: service %d, peer %s, status %s:%d:%d\n",
1151 rpc->crpc_service, libcfs_id2str(rpc->crpc_dest),
1152 swi_state2str(wi->swi_state), rpc->crpc_aborted, status);
1155 * No one can schedule me now since:
1156 * - RPC timer has been defused.
1157 * - all LNet events have been fired.
1158 * - crpc_closed has been set, preventing srpc_abort_rpc from
1160 * Cancel pending schedules and prevent future schedule attempts:
1162 LASSERT (!srpc_event_pending(rpc));
1163 swi_exit_workitem(wi);
1165 spin_unlock(&rpc->crpc_lock);
1167 (*rpc->crpc_done)(rpc);
1171 /* sends an outgoing RPC */
1173 srpc_send_rpc (swi_workitem_t *wi)
1176 srpc_client_rpc_t *rpc;
1180 LASSERT(wi != NULL);
1182 rpc = wi->swi_workitem.wi_data;
1184 LASSERT (rpc != NULL);
1185 LASSERT (wi == &rpc->crpc_wi);
1187 reply = &rpc->crpc_replymsg;
1188 do_bulk = rpc->crpc_bulk.bk_niov > 0;
1190 spin_lock(&rpc->crpc_lock);
1192 if (rpc->crpc_aborted) {
1193 spin_unlock(&rpc->crpc_lock);
1197 spin_unlock(&rpc->crpc_lock);
1199 switch (wi->swi_state) {
1202 case SWI_STATE_NEWBORN:
1203 LASSERT (!srpc_event_pending(rpc));
1205 rc = srpc_prepare_reply(rpc);
1207 srpc_client_rpc_done(rpc, rc);
1211 rc = srpc_prepare_bulk(rpc);
1214 wi->swi_state = SWI_STATE_REQUEST_SUBMITTED;
1215 rc = srpc_send_request(rpc);
1218 case SWI_STATE_REQUEST_SUBMITTED:
1219 /* CAVEAT EMPTOR: rqtev, rpyev, and bulkev may come in any
1220 * order; however, they're processed in a strict order:
1221 * rqt, rpy, and bulk. */
1222 if (!rpc->crpc_reqstev.ev_fired) break;
1224 rc = rpc->crpc_reqstev.ev_status;
1227 wi->swi_state = SWI_STATE_REQUEST_SENT;
1228 /* perhaps more events, fall thru */
1229 case SWI_STATE_REQUEST_SENT: {
1230 srpc_msg_type_t type = srpc_service2reply(rpc->crpc_service);
1232 if (!rpc->crpc_replyev.ev_fired) break;
1234 rc = rpc->crpc_replyev.ev_status;
1237 srpc_unpack_msg_hdr(reply);
1238 if (reply->msg_type != type ||
1239 (reply->msg_magic != SRPC_MSG_MAGIC &&
1240 reply->msg_magic != __swab32(SRPC_MSG_MAGIC))) {
1241 CWARN ("Bad message from %s: type %u (%d expected),"
1242 " magic %u (%d expected).\n",
1243 libcfs_id2str(rpc->crpc_dest),
1244 reply->msg_type, type,
1245 reply->msg_magic, SRPC_MSG_MAGIC);
1250 if (do_bulk && reply->msg_body.reply.status != 0) {
1251 CWARN ("Remote error %d at %s, unlink bulk buffer in "
1252 "case peer didn't initiate bulk transfer\n",
1253 reply->msg_body.reply.status,
1254 libcfs_id2str(rpc->crpc_dest));
1255 LNetMDUnlink(rpc->crpc_bulk.bk_mdh);
1258 wi->swi_state = SWI_STATE_REPLY_RECEIVED;
1260 case SWI_STATE_REPLY_RECEIVED:
1261 if (do_bulk && !rpc->crpc_bulkev.ev_fired) break;
1263 rc = do_bulk ? rpc->crpc_bulkev.ev_status : 0;
1265 /* Bulk buffer was unlinked due to remote error. Clear error
1266 * since reply buffer still contains valid data.
1267 * NB rpc->crpc_done shouldn't look into bulk data in case of
1269 if (do_bulk && rpc->crpc_bulkev.ev_lnet == LNET_EVENT_UNLINK &&
1270 rpc->crpc_status == 0 && reply->msg_body.reply.status != 0)
1273 wi->swi_state = SWI_STATE_DONE;
1274 srpc_client_rpc_done(rpc, rc);
1279 spin_lock(&rpc->crpc_lock);
1280 srpc_abort_rpc(rpc, rc);
1281 spin_unlock(&rpc->crpc_lock);
1285 if (rpc->crpc_aborted) {
1286 LNetMDUnlink(rpc->crpc_reqstmdh);
1287 LNetMDUnlink(rpc->crpc_replymdh);
1288 LNetMDUnlink(rpc->crpc_bulk.bk_mdh);
1290 if (!srpc_event_pending(rpc)) {
1291 srpc_client_rpc_done(rpc, -EINTR);
1299 srpc_create_client_rpc (lnet_process_id_t peer, int service,
1300 int nbulkiov, int bulklen,
1301 void (*rpc_done)(srpc_client_rpc_t *),
1302 void (*rpc_fini)(srpc_client_rpc_t *), void *priv)
1304 srpc_client_rpc_t *rpc;
1306 LIBCFS_ALLOC(rpc, offsetof(srpc_client_rpc_t,
1307 crpc_bulk.bk_iovs[nbulkiov]));
1311 srpc_init_client_rpc(rpc, peer, service, nbulkiov,
1312 bulklen, rpc_done, rpc_fini, priv);
1316 /* called with rpc->crpc_lock held */
1318 srpc_abort_rpc (srpc_client_rpc_t *rpc, int why)
1322 if (rpc->crpc_aborted || /* already aborted */
1323 rpc->crpc_closed) /* callback imminent */
1327 "Aborting RPC: service %d, peer %s, state %s, why %d\n",
1328 rpc->crpc_service, libcfs_id2str(rpc->crpc_dest),
1329 swi_state2str(rpc->crpc_wi.swi_state), why);
1331 rpc->crpc_aborted = 1;
1332 rpc->crpc_status = why;
1333 swi_schedule_workitem(&rpc->crpc_wi);
1337 /* called with rpc->crpc_lock held */
1339 srpc_post_rpc (srpc_client_rpc_t *rpc)
1341 LASSERT (!rpc->crpc_aborted);
1342 LASSERT (srpc_data.rpc_state == SRPC_STATE_RUNNING);
1344 CDEBUG (D_NET, "Posting RPC: peer %s, service %d, timeout %d\n",
1345 libcfs_id2str(rpc->crpc_dest), rpc->crpc_service,
1348 srpc_add_client_rpc_timer(rpc);
1349 swi_schedule_workitem(&rpc->crpc_wi);
1355 srpc_send_reply(struct srpc_server_rpc *rpc)
1357 srpc_event_t *ev = &rpc->srpc_ev;
1358 struct srpc_msg *msg = &rpc->srpc_replymsg;
1359 struct srpc_buffer *buffer = rpc->srpc_reqstbuf;
1360 struct srpc_service_cd *scd = rpc->srpc_scd;
1361 struct srpc_service *sv = scd->scd_svc;
1365 LASSERT(buffer != NULL);
1366 rpyid = buffer->buf_msg.msg_body.reqst.rpyid;
1368 spin_lock(&scd->scd_lock);
1370 if (!sv->sv_shuttingdown && !srpc_serv_is_framework(sv)) {
1371 /* Repost buffer before replying since test client
1372 * might send me another RPC once it gets the reply */
1373 if (srpc_service_post_buffer(scd, buffer) != 0)
1374 CWARN("Failed to repost %s buffer\n", sv->sv_name);
1375 rpc->srpc_reqstbuf = NULL;
1378 spin_unlock(&scd->scd_lock);
1382 ev->ev_type = SRPC_REPLY_SENT;
1384 msg->msg_magic = SRPC_MSG_MAGIC;
1385 msg->msg_version = SRPC_MSG_VERSION;
1386 msg->msg_type = srpc_service2reply(sv->sv_id);
1388 rc = srpc_post_active_rdma(SRPC_RDMA_PORTAL, rpyid, msg,
1389 sizeof(*msg), LNET_MD_OP_PUT,
1390 rpc->srpc_peer, rpc->srpc_self,
1391 &rpc->srpc_replymdh, ev);
1393 ev->ev_fired = 1; /* no more event expected */
1397 /* when in kernel always called with LNET_LOCK() held, and in thread context */
1399 srpc_lnet_ev_handler(lnet_event_t *ev)
1401 struct srpc_service_cd *scd;
1402 srpc_event_t *rpcev = ev->md.user_ptr;
1403 srpc_client_rpc_t *crpc;
1404 srpc_server_rpc_t *srpc;
1405 srpc_buffer_t *buffer;
1408 srpc_msg_type_t type;
1410 LASSERT (!in_interrupt());
1412 if (ev->status != 0) {
1415 spin_lock(&srpc_data.rpc_glock);
1416 if (ev->status != -ECANCELED) /* cancellation is not error */
1417 srpc_data.rpc_counters.errors++;
1418 errors = srpc_data.rpc_counters.errors;
1419 spin_unlock(&srpc_data.rpc_glock);
1421 CNETERR("LNet event status %d type %d, RPC errors %u\n",
1422 ev->status, ev->type, errors);
1425 rpcev->ev_lnet = ev->type;
1427 switch (rpcev->ev_type) {
1429 CERROR("Unknown event: status %d, type %d, lnet %d\n",
1430 rpcev->ev_status, rpcev->ev_type, rpcev->ev_lnet);
1432 case SRPC_REQUEST_SENT:
1433 if (ev->status == 0 && ev->type != LNET_EVENT_UNLINK) {
1434 spin_lock(&srpc_data.rpc_glock);
1435 srpc_data.rpc_counters.rpcs_sent++;
1436 spin_unlock(&srpc_data.rpc_glock);
1438 case SRPC_REPLY_RCVD:
1439 case SRPC_BULK_REQ_RCVD:
1440 crpc = rpcev->ev_data;
1442 if (rpcev != &crpc->crpc_reqstev &&
1443 rpcev != &crpc->crpc_replyev &&
1444 rpcev != &crpc->crpc_bulkev) {
1445 CERROR("rpcev %p, crpc %p, reqstev %p, replyev %p, bulkev %p\n",
1446 rpcev, crpc, &crpc->crpc_reqstev,
1447 &crpc->crpc_replyev, &crpc->crpc_bulkev);
1448 CERROR("Bad event: status %d, type %d, lnet %d\n",
1449 rpcev->ev_status, rpcev->ev_type, rpcev->ev_lnet);
1453 spin_lock(&crpc->crpc_lock);
1455 LASSERT(rpcev->ev_fired == 0);
1456 rpcev->ev_fired = 1;
1457 rpcev->ev_status = (ev->type == LNET_EVENT_UNLINK) ?
1458 -EINTR : ev->status;
1459 swi_schedule_workitem(&crpc->crpc_wi);
1461 spin_unlock(&crpc->crpc_lock);
1464 case SRPC_REQUEST_RCVD:
1465 scd = rpcev->ev_data;
1468 LASSERT(rpcev == &scd->scd_ev);
1470 spin_lock(&scd->scd_lock);
1472 LASSERT (ev->unlinked);
1473 LASSERT (ev->type == LNET_EVENT_PUT ||
1474 ev->type == LNET_EVENT_UNLINK);
1475 LASSERT (ev->type != LNET_EVENT_UNLINK ||
1476 sv->sv_shuttingdown);
1478 buffer = container_of(ev->md.start, srpc_buffer_t, buf_msg);
1479 buffer->buf_peer = ev->initiator;
1480 buffer->buf_self = ev->target.nid;
1482 LASSERT(scd->scd_buf_nposted > 0);
1483 scd->scd_buf_nposted--;
1485 if (sv->sv_shuttingdown) {
1486 /* Leave buffer on scd->scd_buf_nposted since
1487 * srpc_finish_service needs to traverse it. */
1488 spin_unlock(&scd->scd_lock);
1492 if (scd->scd_buf_err_stamp != 0 &&
1493 scd->scd_buf_err_stamp < cfs_time_current_sec()) {
1494 /* re-enable adding buffer */
1495 scd->scd_buf_err_stamp = 0;
1496 scd->scd_buf_err = 0;
1499 if (scd->scd_buf_err == 0 && /* adding buffer is enabled */
1500 scd->scd_buf_adjust == 0 &&
1501 scd->scd_buf_nposted < scd->scd_buf_low) {
1502 scd->scd_buf_adjust = MAX(scd->scd_buf_total / 2,
1504 swi_schedule_workitem(&scd->scd_buf_wi);
1507 list_del(&buffer->buf_list); /* from scd->scd_buf_posted */
1508 msg = &buffer->buf_msg;
1509 type = srpc_service2request(sv->sv_id);
1511 if (ev->status != 0 || ev->mlength != sizeof(*msg) ||
1512 (msg->msg_type != type &&
1513 msg->msg_type != __swab32(type)) ||
1514 (msg->msg_magic != SRPC_MSG_MAGIC &&
1515 msg->msg_magic != __swab32(SRPC_MSG_MAGIC))) {
1516 CERROR ("Dropping RPC (%s) from %s: "
1517 "status %d mlength %d type %u magic %u.\n",
1518 sv->sv_name, libcfs_id2str(ev->initiator),
1519 ev->status, ev->mlength,
1520 msg->msg_type, msg->msg_magic);
1522 /* NB can't call srpc_service_recycle_buffer here since
1523 * it may call LNetM[DE]Attach. The invalid magic tells
1524 * srpc_handle_rpc to drop this RPC */
1528 if (!list_empty(&scd->scd_rpc_free)) {
1529 srpc = list_entry(scd->scd_rpc_free.next,
1530 struct srpc_server_rpc,
1532 list_del(&srpc->srpc_list);
1534 srpc_init_server_rpc(srpc, scd, buffer);
1535 list_add_tail(&srpc->srpc_list,
1536 &scd->scd_rpc_active);
1537 swi_schedule_workitem(&srpc->srpc_wi);
1539 list_add_tail(&buffer->buf_list,
1540 &scd->scd_buf_blocked);
1543 spin_unlock(&scd->scd_lock);
1545 spin_lock(&srpc_data.rpc_glock);
1546 srpc_data.rpc_counters.rpcs_rcvd++;
1547 spin_unlock(&srpc_data.rpc_glock);
1550 case SRPC_BULK_GET_RPLD:
1551 LASSERT (ev->type == LNET_EVENT_SEND ||
1552 ev->type == LNET_EVENT_REPLY ||
1553 ev->type == LNET_EVENT_UNLINK);
1556 break; /* wait for final event */
1558 case SRPC_BULK_PUT_SENT:
1559 if (ev->status == 0 && ev->type != LNET_EVENT_UNLINK) {
1560 spin_lock(&srpc_data.rpc_glock);
1562 if (rpcev->ev_type == SRPC_BULK_GET_RPLD)
1563 srpc_data.rpc_counters.bulk_get += ev->mlength;
1565 srpc_data.rpc_counters.bulk_put += ev->mlength;
1567 spin_unlock(&srpc_data.rpc_glock);
1569 case SRPC_REPLY_SENT:
1570 srpc = rpcev->ev_data;
1571 scd = srpc->srpc_scd;
1573 LASSERT(rpcev == &srpc->srpc_ev);
1575 spin_lock(&scd->scd_lock);
1577 rpcev->ev_fired = 1;
1578 rpcev->ev_status = (ev->type == LNET_EVENT_UNLINK) ?
1579 -EINTR : ev->status;
1580 swi_schedule_workitem(&srpc->srpc_wi);
1582 spin_unlock(&scd->scd_lock);
1593 memset(&srpc_data, 0, sizeof(struct smoketest_rpc));
1594 spin_lock_init(&srpc_data.rpc_glock);
1596 /* 1 second pause to avoid timestamp reuse */
1597 set_current_state(TASK_UNINTERRUPTIBLE);
1598 schedule_timeout(cfs_time_seconds(1));
1599 srpc_data.rpc_matchbits = ((__u64) cfs_time_current_sec()) << 48;
1601 srpc_data.rpc_state = SRPC_STATE_NONE;
1603 rc = LNetNIInit(LNET_PID_LUSTRE);
1605 CERROR ("LNetNIInit() has failed: %d\n", rc);
1609 srpc_data.rpc_state = SRPC_STATE_NI_INIT;
1611 LNetInvalidateHandle(&srpc_data.rpc_lnet_eq);
1612 rc = LNetEQAlloc(0, srpc_lnet_ev_handler, &srpc_data.rpc_lnet_eq);
1614 CERROR("LNetEQAlloc() has failed: %d\n", rc);
1618 rc = LNetSetLazyPortal(SRPC_FRAMEWORK_REQUEST_PORTAL);
1620 rc = LNetSetLazyPortal(SRPC_REQUEST_PORTAL);
1623 srpc_data.rpc_state = SRPC_STATE_EQ_INIT;
1631 srpc_data.rpc_state = SRPC_STATE_RUNNING;
1637 srpc_shutdown (void)
1643 state = srpc_data.rpc_state;
1644 srpc_data.rpc_state = SRPC_STATE_STOPPING;
1649 case SRPC_STATE_RUNNING:
1650 spin_lock(&srpc_data.rpc_glock);
1652 for (i = 0; i <= SRPC_SERVICE_MAX_ID; i++) {
1653 srpc_service_t *sv = srpc_data.rpc_services[i];
1655 LASSERTF (sv == NULL,
1656 "service not empty: id %d, name %s\n",
1660 spin_unlock(&srpc_data.rpc_glock);
1664 case SRPC_STATE_EQ_INIT:
1665 rc = LNetClearLazyPortal(SRPC_FRAMEWORK_REQUEST_PORTAL);
1666 rc = LNetClearLazyPortal(SRPC_REQUEST_PORTAL);
1668 rc = LNetEQFree(srpc_data.rpc_lnet_eq);
1669 LASSERT (rc == 0); /* the EQ should have no user by now */
1671 case SRPC_STATE_NI_INIT: