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) 2012, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
34 * Author: Isaac Huang <isaac@clusterfs.com>
36 * 2012-05-13: Liang Zhen <liang@whamcloud.com>
37 * - percpt data for service to improve smp performance
41 #define DEBUG_SUBSYSTEM S_LNET
53 static struct smoketest_rpc {
54 spinlock_t rpc_glock; /* global lock */
55 srpc_service_t *rpc_services[SRPC_SERVICE_MAX_ID + 1];
56 struct lnet_handle_eq rpc_lnet_eq; /* _the_ LNet event queue */
57 srpc_state_t rpc_state;
58 struct srpc_counters rpc_counters;
59 __u64 rpc_matchbits; /* matchbits counter */
63 srpc_serv_portal(int svc_id)
65 return svc_id < SRPC_FRAMEWORK_SERVICE_MAX_ID ?
66 SRPC_FRAMEWORK_REQUEST_PORTAL : SRPC_REQUEST_PORTAL;
70 int srpc_handle_rpc(swi_workitem_t *wi);
72 void srpc_get_counters(struct srpc_counters *cnt)
74 spin_lock(&srpc_data.rpc_glock);
75 *cnt = srpc_data.rpc_counters;
76 spin_unlock(&srpc_data.rpc_glock);
79 void srpc_set_counters(const struct srpc_counters *cnt)
81 spin_lock(&srpc_data.rpc_glock);
82 srpc_data.rpc_counters = *cnt;
83 spin_unlock(&srpc_data.rpc_glock);
87 srpc_add_bulk_page(srpc_bulk_t *bk, struct page *pg, int i, int off, int nob)
89 LASSERT(off < PAGE_SIZE);
90 LASSERT(nob > 0 && nob <= PAGE_SIZE);
92 bk->bk_iovs[i].kiov_offset = off;
93 bk->bk_iovs[i].kiov_page = pg;
94 bk->bk_iovs[i].kiov_len = nob;
99 srpc_free_bulk (srpc_bulk_t *bk)
104 LASSERT (bk != NULL);
106 for (i = 0; i < bk->bk_niov; i++) {
107 pg = bk->bk_iovs[i].kiov_page;
108 if (pg == NULL) break;
113 LIBCFS_FREE(bk, offsetof(srpc_bulk_t, bk_iovs[bk->bk_niov]));
118 srpc_alloc_bulk(int cpt, unsigned bulk_off, unsigned bulk_npg,
119 unsigned bulk_len, int sink)
124 LASSERT(bulk_npg > 0 && bulk_npg <= LNET_MAX_IOV);
126 LIBCFS_CPT_ALLOC(bk, lnet_cpt_table(), cpt,
127 offsetof(srpc_bulk_t, bk_iovs[bulk_npg]));
129 CERROR("Can't allocate descriptor for %d pages\n", bulk_npg);
133 memset(bk, 0, offsetof(srpc_bulk_t, bk_iovs[bulk_npg]));
135 bk->bk_len = bulk_len;
136 bk->bk_niov = bulk_npg;
138 for (i = 0; i < bulk_npg; i++) {
142 pg = cfs_page_cpt_alloc(lnet_cpt_table(), cpt, GFP_KERNEL);
144 CERROR("Can't allocate page %d of %d\n", i, bulk_npg);
149 nob = min_t(unsigned, bulk_off + bulk_len, PAGE_SIZE) -
152 srpc_add_bulk_page(bk, pg, i, bulk_off, nob);
165 spin_lock(&srpc_data.rpc_glock);
166 id = srpc_data.rpc_matchbits++;
167 spin_unlock(&srpc_data.rpc_glock);
172 srpc_init_server_rpc(struct srpc_server_rpc *rpc,
173 struct srpc_service_cd *scd,
174 struct srpc_buffer *buffer)
176 memset(rpc, 0, sizeof(*rpc));
177 swi_init_workitem(&rpc->srpc_wi, rpc, srpc_handle_rpc,
178 srpc_serv_is_framework(scd->scd_svc) ?
179 lst_sched_serial : lst_sched_test[scd->scd_cpt]);
181 rpc->srpc_ev.ev_fired = 1; /* no event expected now */
184 rpc->srpc_reqstbuf = buffer;
185 rpc->srpc_peer = buffer->buf_peer;
186 rpc->srpc_self = buffer->buf_self;
187 LNetInvalidateMDHandle(&rpc->srpc_replymdh);
191 srpc_service_fini(struct srpc_service *svc)
193 struct srpc_service_cd *scd;
194 struct srpc_server_rpc *rpc;
195 struct srpc_buffer *buf;
199 if (svc->sv_cpt_data == NULL)
202 cfs_percpt_for_each(scd, i, svc->sv_cpt_data) {
204 if (!list_empty(&scd->scd_buf_posted))
205 q = &scd->scd_buf_posted;
206 else if (!list_empty(&scd->scd_buf_blocked))
207 q = &scd->scd_buf_blocked;
211 while (!list_empty(q)) {
212 buf = list_entry(q->next,
215 list_del(&buf->buf_list);
216 LIBCFS_FREE(buf, sizeof(*buf));
220 LASSERT(list_empty(&scd->scd_rpc_active));
222 while (!list_empty(&scd->scd_rpc_free)) {
223 rpc = list_entry(scd->scd_rpc_free.next,
224 struct srpc_server_rpc,
226 list_del(&rpc->srpc_list);
227 LIBCFS_FREE(rpc, sizeof(*rpc));
231 cfs_percpt_free(svc->sv_cpt_data);
232 svc->sv_cpt_data = NULL;
236 srpc_service_nrpcs(struct srpc_service *svc)
238 int nrpcs = svc->sv_wi_total / svc->sv_ncpts;
240 return srpc_serv_is_framework(svc) ?
241 max(nrpcs, SFW_FRWK_WI_MIN) : max(nrpcs, SFW_TEST_WI_MIN);
244 int srpc_add_buffer(struct swi_workitem *wi);
247 srpc_service_init(struct srpc_service *svc)
249 struct srpc_service_cd *scd;
250 struct srpc_server_rpc *rpc;
255 svc->sv_shuttingdown = 0;
257 svc->sv_cpt_data = cfs_percpt_alloc(lnet_cpt_table(),
258 sizeof(struct srpc_service_cd));
259 if (svc->sv_cpt_data == NULL)
262 svc->sv_ncpts = srpc_serv_is_framework(svc) ?
263 1 : cfs_cpt_number(lnet_cpt_table());
264 nrpcs = srpc_service_nrpcs(svc);
266 cfs_percpt_for_each(scd, i, svc->sv_cpt_data) {
269 spin_lock_init(&scd->scd_lock);
270 INIT_LIST_HEAD(&scd->scd_rpc_free);
271 INIT_LIST_HEAD(&scd->scd_rpc_active);
272 INIT_LIST_HEAD(&scd->scd_buf_posted);
273 INIT_LIST_HEAD(&scd->scd_buf_blocked);
275 scd->scd_ev.ev_data = scd;
276 scd->scd_ev.ev_type = SRPC_REQUEST_RCVD;
278 /* NB: don't use lst_sched_serial for adding buffer,
279 * see details in srpc_service_add_buffers() */
280 swi_init_workitem(&scd->scd_buf_wi, scd,
281 srpc_add_buffer, lst_sched_test[i]);
283 if (i != 0 && srpc_serv_is_framework(svc)) {
284 /* NB: framework service only needs srpc_service_cd for
285 * one partition, but we allocate for all to make
286 * it easier to implement, it will waste a little
287 * memory but nobody should care about this */
291 for (j = 0; j < nrpcs; j++) {
292 LIBCFS_CPT_ALLOC(rpc, lnet_cpt_table(),
295 srpc_service_fini(svc);
298 list_add(&rpc->srpc_list, &scd->scd_rpc_free);
306 srpc_add_service(struct srpc_service *sv)
310 LASSERT(0 <= id && id <= SRPC_SERVICE_MAX_ID);
312 if (srpc_service_init(sv) != 0)
315 spin_lock(&srpc_data.rpc_glock);
317 LASSERT(srpc_data.rpc_state == SRPC_STATE_RUNNING);
319 if (srpc_data.rpc_services[id] != NULL) {
320 spin_unlock(&srpc_data.rpc_glock);
324 srpc_data.rpc_services[id] = sv;
325 spin_unlock(&srpc_data.rpc_glock);
327 CDEBUG(D_NET, "Adding service: id %d, name %s\n", id, sv->sv_name);
331 srpc_service_fini(sv);
336 srpc_remove_service (srpc_service_t *sv)
340 spin_lock(&srpc_data.rpc_glock);
342 if (srpc_data.rpc_services[id] != sv) {
343 spin_unlock(&srpc_data.rpc_glock);
347 srpc_data.rpc_services[id] = NULL;
348 spin_unlock(&srpc_data.rpc_glock);
353 srpc_post_passive_rdma(int portal, int local, __u64 matchbits, void *buf,
354 int len, int options, struct lnet_process_id peer,
355 struct lnet_handle_md *mdh, srpc_event_t *ev)
359 struct lnet_handle_me meh;
361 rc = LNetMEAttach(portal, peer, matchbits, 0, LNET_UNLINK,
362 local ? LNET_INS_LOCAL : LNET_INS_AFTER, &meh);
364 CERROR ("LNetMEAttach failed: %d\n", rc);
365 LASSERT (rc == -ENOMEM);
373 md.options = options;
374 md.eq_handle = srpc_data.rpc_lnet_eq;
376 rc = LNetMDAttach(meh, md, LNET_UNLINK, mdh);
378 CERROR ("LNetMDAttach failed: %d\n", rc);
379 LASSERT (rc == -ENOMEM);
381 rc = LNetMEUnlink(meh);
387 "Posted passive RDMA: peer %s, portal %d, matchbits %#llx\n",
388 libcfs_id2str(peer), portal, matchbits);
393 srpc_post_active_rdma(int portal, __u64 matchbits, void *buf, int len,
394 int options, struct lnet_process_id peer, lnet_nid_t self,
395 struct lnet_handle_md *mdh, srpc_event_t *ev)
403 md.eq_handle = srpc_data.rpc_lnet_eq;
404 md.threshold = ((options & LNET_MD_OP_GET) != 0) ? 2 : 1;
405 md.options = options & ~(LNET_MD_OP_PUT | LNET_MD_OP_GET);
407 rc = LNetMDBind(md, LNET_UNLINK, mdh);
409 CERROR ("LNetMDBind failed: %d\n", rc);
410 LASSERT (rc == -ENOMEM);
414 /* this is kind of an abuse of the LNET_MD_OP_{PUT,GET} options.
415 * they're only meaningful for MDs attached to an ME (i.e. passive
417 if ((options & LNET_MD_OP_PUT) != 0) {
418 rc = LNetPut(self, *mdh, LNET_NOACK_REQ, peer,
419 portal, matchbits, 0, 0);
421 LASSERT ((options & LNET_MD_OP_GET) != 0);
423 rc = LNetGet(self, *mdh, peer, portal, matchbits, 0);
427 CERROR ("LNet%s(%s, %d, %lld) failed: %d\n",
428 ((options & LNET_MD_OP_PUT) != 0) ? "Put" : "Get",
429 libcfs_id2str(peer), portal, matchbits, rc);
431 /* The forthcoming unlink event will complete this operation
432 * with failure, so fall through and return success here.
434 rc = LNetMDUnlink(*mdh);
438 "Posted active RDMA: peer %s, portal %u, matchbits %#llx\n",
439 libcfs_id2str(peer), portal, matchbits);
445 srpc_post_passive_rqtbuf(int service, int local, void *buf, int len,
446 struct lnet_handle_md *mdh, srpc_event_t *ev)
448 struct lnet_process_id any = {0};
450 any.nid = LNET_NID_ANY;
451 any.pid = LNET_PID_ANY;
453 return srpc_post_passive_rdma(srpc_serv_portal(service),
454 local, service, buf, len,
455 LNET_MD_OP_PUT, any, mdh, ev);
459 srpc_service_post_buffer(struct srpc_service_cd *scd, struct srpc_buffer *buf)
460 __must_hold(&scd->scd_lock)
462 struct srpc_service *sv = scd->scd_svc;
463 struct srpc_msg *msg = &buf->buf_msg;
466 LNetInvalidateMDHandle(&buf->buf_mdh);
467 list_add(&buf->buf_list, &scd->scd_buf_posted);
468 scd->scd_buf_nposted++;
469 spin_unlock(&scd->scd_lock);
471 rc = srpc_post_passive_rqtbuf(sv->sv_id,
472 !srpc_serv_is_framework(sv),
473 msg, sizeof(*msg), &buf->buf_mdh,
476 /* At this point, a RPC (new or delayed) may have arrived in
477 * msg and its event handler has been called. So we must add
478 * buf to scd_buf_posted _before_ dropping scd_lock */
480 spin_lock(&scd->scd_lock);
483 if (!sv->sv_shuttingdown)
486 spin_unlock(&scd->scd_lock);
487 /* srpc_shutdown_service might have tried to unlink me
488 * when my buf_mdh was still invalid */
489 LNetMDUnlink(buf->buf_mdh);
490 spin_lock(&scd->scd_lock);
494 scd->scd_buf_nposted--;
495 if (sv->sv_shuttingdown)
496 return rc; /* don't allow to change scd_buf_posted */
498 list_del(&buf->buf_list);
499 spin_unlock(&scd->scd_lock);
501 LIBCFS_FREE(buf, sizeof(*buf));
503 spin_lock(&scd->scd_lock);
508 srpc_add_buffer(struct swi_workitem *wi)
510 struct srpc_service_cd *scd = wi->swi_workitem.wi_data;
511 struct srpc_buffer *buf;
514 /* it's called by workitem scheduler threads, these threads
515 * should have been set CPT affinity, so buffers will be posted
516 * on CPT local list of Portal */
517 spin_lock(&scd->scd_lock);
519 while (scd->scd_buf_adjust > 0 &&
520 !scd->scd_svc->sv_shuttingdown) {
521 scd->scd_buf_adjust--; /* consume it */
522 scd->scd_buf_posting++;
524 spin_unlock(&scd->scd_lock);
526 LIBCFS_ALLOC(buf, sizeof(*buf));
528 CERROR("Failed to add new buf to service: %s\n",
529 scd->scd_svc->sv_name);
530 spin_lock(&scd->scd_lock);
535 spin_lock(&scd->scd_lock);
536 if (scd->scd_svc->sv_shuttingdown) {
537 spin_unlock(&scd->scd_lock);
538 LIBCFS_FREE(buf, sizeof(*buf));
540 spin_lock(&scd->scd_lock);
545 rc = srpc_service_post_buffer(scd, buf);
547 break; /* buf has been freed inside */
549 LASSERT(scd->scd_buf_posting > 0);
550 scd->scd_buf_posting--;
551 scd->scd_buf_total++;
552 scd->scd_buf_low = MAX(2, scd->scd_buf_total / 4);
556 scd->scd_buf_err_stamp = ktime_get_real_seconds();
557 scd->scd_buf_err = rc;
559 LASSERT(scd->scd_buf_posting > 0);
560 scd->scd_buf_posting--;
563 spin_unlock(&scd->scd_lock);
568 srpc_service_add_buffers(struct srpc_service *sv, int nbuffer)
570 struct srpc_service_cd *scd;
574 LASSERTF(nbuffer > 0, "nbuffer must be positive: %d\n", nbuffer);
576 cfs_percpt_for_each(scd, i, sv->sv_cpt_data) {
577 spin_lock(&scd->scd_lock);
579 scd->scd_buf_err = 0;
580 scd->scd_buf_err_stamp = 0;
581 scd->scd_buf_posting = 0;
582 scd->scd_buf_adjust = nbuffer;
583 /* start to post buffers */
584 swi_schedule_workitem(&scd->scd_buf_wi);
585 spin_unlock(&scd->scd_lock);
587 /* framework service only post buffer for one partition */
588 if (srpc_serv_is_framework(sv))
592 cfs_percpt_for_each(scd, i, sv->sv_cpt_data) {
593 spin_lock(&scd->scd_lock);
595 * NB: srpc_service_add_buffers() can be called inside
596 * thread context of lst_sched_serial, and we don't normally
597 * allow to sleep inside thread context of WI scheduler
598 * because it will block current scheduler thread from doing
599 * anything else, even worse, it could deadlock if it's
600 * waiting on result from another WI of the same scheduler.
601 * However, it's safe at here because scd_buf_wi is scheduled
602 * by thread in a different WI scheduler (lst_sched_test),
603 * so we don't have any risk of deadlock, though this could
604 * block all WIs pending on lst_sched_serial for a moment
605 * which is not good but not fatal.
607 lst_wait_until(scd->scd_buf_err != 0 ||
608 (scd->scd_buf_adjust == 0 &&
609 scd->scd_buf_posting == 0),
610 scd->scd_lock, "waiting for adding buffer\n");
612 if (scd->scd_buf_err != 0 && rc == 0)
613 rc = scd->scd_buf_err;
615 spin_unlock(&scd->scd_lock);
622 srpc_service_remove_buffers(struct srpc_service *sv, int nbuffer)
624 struct srpc_service_cd *scd;
628 LASSERT(!sv->sv_shuttingdown);
630 cfs_percpt_for_each(scd, i, sv->sv_cpt_data) {
631 spin_lock(&scd->scd_lock);
633 num = scd->scd_buf_total + scd->scd_buf_posting;
634 scd->scd_buf_adjust -= min(nbuffer, num);
636 spin_unlock(&scd->scd_lock);
640 /* returns 1 if sv has finished, otherwise 0 */
642 srpc_finish_service(struct srpc_service *sv)
644 struct srpc_service_cd *scd;
645 struct srpc_server_rpc *rpc;
648 LASSERT(sv->sv_shuttingdown); /* srpc_shutdown_service called */
650 cfs_percpt_for_each(scd, i, sv->sv_cpt_data) {
651 spin_lock(&scd->scd_lock);
652 if (!swi_deschedule_workitem(&scd->scd_buf_wi)) {
653 spin_unlock(&scd->scd_lock);
657 if (scd->scd_buf_nposted > 0) {
658 CDEBUG(D_NET, "waiting for %d posted buffers to "
659 "unlink\n", scd->scd_buf_nposted);
660 spin_unlock(&scd->scd_lock);
664 if (list_empty(&scd->scd_rpc_active)) {
665 spin_unlock(&scd->scd_lock);
669 rpc = list_entry(scd->scd_rpc_active.next,
670 struct srpc_server_rpc, srpc_list);
671 CNETERR("Active RPC %p on shutdown: sv %s, peer %s, "
672 "wi %s scheduled %d running %d, "
673 "ev fired %d type %d status %d lnet %d\n",
674 rpc, sv->sv_name, libcfs_id2str(rpc->srpc_peer),
675 swi_state2str(rpc->srpc_wi.swi_state),
676 rpc->srpc_wi.swi_workitem.wi_scheduled,
677 rpc->srpc_wi.swi_workitem.wi_running,
678 rpc->srpc_ev.ev_fired, rpc->srpc_ev.ev_type,
679 rpc->srpc_ev.ev_status, rpc->srpc_ev.ev_lnet);
680 spin_unlock(&scd->scd_lock);
684 /* no lock needed from now on */
685 srpc_service_fini(sv);
689 /* called with sv->sv_lock held */
691 srpc_service_recycle_buffer(struct srpc_service_cd *scd, srpc_buffer_t *buf)
692 __must_hold(&scd->scd_lock)
694 if (!scd->scd_svc->sv_shuttingdown && scd->scd_buf_adjust >= 0) {
695 if (srpc_service_post_buffer(scd, buf) != 0) {
696 CWARN("Failed to post %s buffer\n",
697 scd->scd_svc->sv_name);
702 /* service is shutting down, or we want to recycle some buffers */
703 scd->scd_buf_total--;
705 if (scd->scd_buf_adjust < 0) {
706 scd->scd_buf_adjust++;
707 if (scd->scd_buf_adjust < 0 &&
708 scd->scd_buf_total == 0 && scd->scd_buf_posting == 0) {
710 "Try to recyle %d buffers but nothing left\n",
711 scd->scd_buf_adjust);
712 scd->scd_buf_adjust = 0;
716 spin_unlock(&scd->scd_lock);
717 LIBCFS_FREE(buf, sizeof(*buf));
718 spin_lock(&scd->scd_lock);
722 srpc_abort_service(struct srpc_service *sv)
724 struct srpc_service_cd *scd;
725 struct srpc_server_rpc *rpc;
728 CDEBUG(D_NET, "Aborting service: id %d, name %s\n",
729 sv->sv_id, sv->sv_name);
731 cfs_percpt_for_each(scd, i, sv->sv_cpt_data) {
732 spin_lock(&scd->scd_lock);
734 /* schedule in-flight RPCs to notice the abort, NB:
735 * racing with incoming RPCs; complete fix should make test
736 * RPCs carry session ID in its headers */
737 list_for_each_entry(rpc, &scd->scd_rpc_active, srpc_list) {
738 rpc->srpc_aborted = 1;
739 swi_schedule_workitem(&rpc->srpc_wi);
742 spin_unlock(&scd->scd_lock);
747 srpc_shutdown_service(srpc_service_t *sv)
749 struct srpc_service_cd *scd;
750 struct srpc_server_rpc *rpc;
754 CDEBUG(D_NET, "Shutting down service: id %d, name %s\n",
755 sv->sv_id, sv->sv_name);
757 cfs_percpt_for_each(scd, i, sv->sv_cpt_data)
758 spin_lock(&scd->scd_lock);
760 sv->sv_shuttingdown = 1; /* i.e. no new active RPC */
762 cfs_percpt_for_each(scd, i, sv->sv_cpt_data)
763 spin_unlock(&scd->scd_lock);
765 cfs_percpt_for_each(scd, i, sv->sv_cpt_data) {
766 spin_lock(&scd->scd_lock);
768 /* schedule in-flight RPCs to notice the shutdown */
769 list_for_each_entry(rpc, &scd->scd_rpc_active, srpc_list)
770 swi_schedule_workitem(&rpc->srpc_wi);
772 spin_unlock(&scd->scd_lock);
774 /* OK to traverse scd_buf_posted without lock, since no one
775 * touches scd_buf_posted now */
776 list_for_each_entry(buf, &scd->scd_buf_posted, buf_list)
777 LNetMDUnlink(buf->buf_mdh);
782 srpc_send_request (srpc_client_rpc_t *rpc)
784 srpc_event_t *ev = &rpc->crpc_reqstev;
789 ev->ev_type = SRPC_REQUEST_SENT;
791 rc = srpc_post_active_rdma(srpc_serv_portal(rpc->crpc_service),
792 rpc->crpc_service, &rpc->crpc_reqstmsg,
793 sizeof(srpc_msg_t), LNET_MD_OP_PUT,
794 rpc->crpc_dest, LNET_NID_ANY,
795 &rpc->crpc_reqstmdh, ev);
797 LASSERT (rc == -ENOMEM);
798 ev->ev_fired = 1; /* no more event expected */
804 srpc_prepare_reply (srpc_client_rpc_t *rpc)
806 srpc_event_t *ev = &rpc->crpc_replyev;
807 __u64 *id = &rpc->crpc_reqstmsg.msg_body.reqst.rpyid;
812 ev->ev_type = SRPC_REPLY_RCVD;
814 *id = srpc_next_id();
816 rc = srpc_post_passive_rdma(SRPC_RDMA_PORTAL, 0, *id,
817 &rpc->crpc_replymsg, sizeof(srpc_msg_t),
818 LNET_MD_OP_PUT, rpc->crpc_dest,
819 &rpc->crpc_replymdh, ev);
821 LASSERT (rc == -ENOMEM);
822 ev->ev_fired = 1; /* no more event expected */
828 srpc_prepare_bulk (srpc_client_rpc_t *rpc)
830 srpc_bulk_t *bk = &rpc->crpc_bulk;
831 srpc_event_t *ev = &rpc->crpc_bulkev;
832 __u64 *id = &rpc->crpc_reqstmsg.msg_body.reqst.bulkid;
836 LASSERT (bk->bk_niov <= LNET_MAX_IOV);
838 if (bk->bk_niov == 0) return 0; /* nothing to do */
840 opt = bk->bk_sink ? LNET_MD_OP_PUT : LNET_MD_OP_GET;
845 ev->ev_type = SRPC_BULK_REQ_RCVD;
847 *id = srpc_next_id();
849 rc = srpc_post_passive_rdma(SRPC_RDMA_PORTAL, 0, *id,
850 &bk->bk_iovs[0], bk->bk_niov, opt,
851 rpc->crpc_dest, &bk->bk_mdh, ev);
853 LASSERT (rc == -ENOMEM);
854 ev->ev_fired = 1; /* no more event expected */
860 srpc_do_bulk (srpc_server_rpc_t *rpc)
862 srpc_event_t *ev = &rpc->srpc_ev;
863 srpc_bulk_t *bk = rpc->srpc_bulk;
864 __u64 id = rpc->srpc_reqstbuf->buf_msg.msg_body.reqst.bulkid;
868 LASSERT (bk != NULL);
870 opt = bk->bk_sink ? LNET_MD_OP_GET : LNET_MD_OP_PUT;
875 ev->ev_type = bk->bk_sink ? SRPC_BULK_GET_RPLD : SRPC_BULK_PUT_SENT;
877 rc = srpc_post_active_rdma(SRPC_RDMA_PORTAL, id,
878 &bk->bk_iovs[0], bk->bk_niov, opt,
879 rpc->srpc_peer, rpc->srpc_self,
882 ev->ev_fired = 1; /* no more event expected */
886 /* only called from srpc_handle_rpc */
888 srpc_server_rpc_done(srpc_server_rpc_t *rpc, int status)
890 struct srpc_service_cd *scd = rpc->srpc_scd;
891 struct srpc_service *sv = scd->scd_svc;
892 srpc_buffer_t *buffer;
894 LASSERT (status != 0 || rpc->srpc_wi.swi_state == SWI_STATE_DONE);
896 rpc->srpc_status = status;
898 CDEBUG_LIMIT (status == 0 ? D_NET : D_NETERROR,
899 "Server RPC %p done: service %s, peer %s, status %s:%d\n",
900 rpc, sv->sv_name, libcfs_id2str(rpc->srpc_peer),
901 swi_state2str(rpc->srpc_wi.swi_state), status);
904 spin_lock(&srpc_data.rpc_glock);
905 srpc_data.rpc_counters.rpcs_dropped++;
906 spin_unlock(&srpc_data.rpc_glock);
909 if (rpc->srpc_done != NULL)
910 (*rpc->srpc_done) (rpc);
911 LASSERT(rpc->srpc_bulk == NULL);
913 spin_lock(&scd->scd_lock);
915 if (rpc->srpc_reqstbuf != NULL) {
916 /* NB might drop sv_lock in srpc_service_recycle_buffer, but
917 * sv won't go away for scd_rpc_active must not be empty */
918 srpc_service_recycle_buffer(scd, rpc->srpc_reqstbuf);
919 rpc->srpc_reqstbuf = NULL;
922 list_del(&rpc->srpc_list); /* from scd->scd_rpc_active */
925 * No one can schedule me now since:
926 * - I'm not on scd_rpc_active.
927 * - all LNet events have been fired.
928 * Cancel pending schedules and prevent future schedule attempts:
930 LASSERT(rpc->srpc_ev.ev_fired);
931 swi_exit_workitem(&rpc->srpc_wi);
933 if (!sv->sv_shuttingdown && !list_empty(&scd->scd_buf_blocked)) {
934 buffer = list_entry(scd->scd_buf_blocked.next,
935 srpc_buffer_t, buf_list);
936 list_del(&buffer->buf_list);
938 srpc_init_server_rpc(rpc, scd, buffer);
939 list_add_tail(&rpc->srpc_list, &scd->scd_rpc_active);
940 swi_schedule_workitem(&rpc->srpc_wi);
942 list_add(&rpc->srpc_list, &scd->scd_rpc_free);
945 spin_unlock(&scd->scd_lock);
949 /* handles an incoming RPC */
951 srpc_handle_rpc(swi_workitem_t *wi)
953 struct srpc_server_rpc *rpc = wi->swi_workitem.wi_data;
954 struct srpc_service_cd *scd = rpc->srpc_scd;
955 struct srpc_service *sv = scd->scd_svc;
956 srpc_event_t *ev = &rpc->srpc_ev;
959 LASSERT(wi == &rpc->srpc_wi);
961 spin_lock(&scd->scd_lock);
963 if (sv->sv_shuttingdown || rpc->srpc_aborted) {
964 spin_unlock(&scd->scd_lock);
966 if (rpc->srpc_bulk != NULL)
967 LNetMDUnlink(rpc->srpc_bulk->bk_mdh);
968 LNetMDUnlink(rpc->srpc_replymdh);
970 if (ev->ev_fired) { /* no more event, OK to finish */
971 srpc_server_rpc_done(rpc, -ESHUTDOWN);
977 spin_unlock(&scd->scd_lock);
979 switch (wi->swi_state) {
982 case SWI_STATE_NEWBORN: {
984 srpc_generic_reply_t *reply;
986 msg = &rpc->srpc_reqstbuf->buf_msg;
987 reply = &rpc->srpc_replymsg.msg_body.reply;
989 if (msg->msg_magic == 0) {
990 /* moaned already in srpc_lnet_ev_handler */
991 srpc_server_rpc_done(rpc, EBADMSG);
995 srpc_unpack_msg_hdr(msg);
996 if (msg->msg_version != SRPC_MSG_VERSION) {
997 CWARN("Version mismatch: %u, %u expected, from %s\n",
998 msg->msg_version, SRPC_MSG_VERSION,
999 libcfs_id2str(rpc->srpc_peer));
1000 reply->status = EPROTO;
1001 /* drop through and send reply */
1004 rc = (*sv->sv_handler)(rpc);
1005 LASSERT(reply->status == 0 || !rpc->srpc_bulk);
1007 srpc_server_rpc_done(rpc, rc);
1012 wi->swi_state = SWI_STATE_BULK_STARTED;
1014 if (rpc->srpc_bulk != NULL) {
1015 rc = srpc_do_bulk(rpc);
1017 return 0; /* wait for bulk */
1019 LASSERT (ev->ev_fired);
1023 case SWI_STATE_BULK_STARTED:
1024 LASSERT (rpc->srpc_bulk == NULL || ev->ev_fired);
1026 if (rpc->srpc_bulk != NULL) {
1029 if (sv->sv_bulk_ready != NULL)
1030 rc = (*sv->sv_bulk_ready) (rpc, rc);
1033 srpc_server_rpc_done(rpc, rc);
1038 wi->swi_state = SWI_STATE_REPLY_SUBMITTED;
1039 rc = srpc_send_reply(rpc);
1041 return 0; /* wait for reply */
1042 srpc_server_rpc_done(rpc, rc);
1045 case SWI_STATE_REPLY_SUBMITTED:
1046 if (!ev->ev_fired) {
1047 CERROR("RPC %p: bulk %p, service %d\n",
1048 rpc, rpc->srpc_bulk, sv->sv_id);
1049 CERROR("Event: status %d, type %d, lnet %d\n",
1050 ev->ev_status, ev->ev_type, ev->ev_lnet);
1051 LASSERT (ev->ev_fired);
1054 wi->swi_state = SWI_STATE_DONE;
1055 srpc_server_rpc_done(rpc, ev->ev_status);
1063 srpc_client_rpc_expired (void *data)
1065 srpc_client_rpc_t *rpc = data;
1067 CWARN ("Client RPC expired: service %d, peer %s, timeout %d.\n",
1068 rpc->crpc_service, libcfs_id2str(rpc->crpc_dest),
1071 spin_lock(&rpc->crpc_lock);
1073 rpc->crpc_timeout = 0;
1074 srpc_abort_rpc(rpc, -ETIMEDOUT);
1076 spin_unlock(&rpc->crpc_lock);
1078 spin_lock(&srpc_data.rpc_glock);
1079 srpc_data.rpc_counters.rpcs_expired++;
1080 spin_unlock(&srpc_data.rpc_glock);
1084 srpc_add_client_rpc_timer(srpc_client_rpc_t *rpc)
1086 stt_timer_t *timer = &rpc->crpc_timer;
1088 if (rpc->crpc_timeout == 0)
1091 INIT_LIST_HEAD(&timer->stt_list);
1092 timer->stt_data = rpc;
1093 timer->stt_func = srpc_client_rpc_expired;
1094 timer->stt_expires = ktime_get_real_seconds() + rpc->crpc_timeout;
1095 stt_add_timer(timer);
1100 * Called with rpc->crpc_lock held.
1102 * Upon exit the RPC expiry timer is not queued and the handler is not
1103 * running on any CPU. */
1105 srpc_del_client_rpc_timer (srpc_client_rpc_t *rpc)
1107 /* timer not planted or already exploded */
1108 if (rpc->crpc_timeout == 0)
1111 /* timer successfully defused */
1112 if (stt_del_timer(&rpc->crpc_timer))
1115 /* timer detonated, wait for it to explode */
1116 while (rpc->crpc_timeout != 0) {
1117 spin_unlock(&rpc->crpc_lock);
1121 spin_lock(&rpc->crpc_lock);
1126 srpc_client_rpc_done (srpc_client_rpc_t *rpc, int status)
1128 swi_workitem_t *wi = &rpc->crpc_wi;
1130 LASSERT(status != 0 || wi->swi_state == SWI_STATE_DONE);
1132 spin_lock(&rpc->crpc_lock);
1134 rpc->crpc_closed = 1;
1135 if (rpc->crpc_status == 0)
1136 rpc->crpc_status = status;
1138 srpc_del_client_rpc_timer(rpc);
1140 CDEBUG_LIMIT ((status == 0) ? D_NET : D_NETERROR,
1141 "Client RPC done: service %d, peer %s, status %s:%d:%d\n",
1142 rpc->crpc_service, libcfs_id2str(rpc->crpc_dest),
1143 swi_state2str(wi->swi_state), rpc->crpc_aborted, status);
1146 * No one can schedule me now since:
1147 * - RPC timer has been defused.
1148 * - all LNet events have been fired.
1149 * - crpc_closed has been set, preventing srpc_abort_rpc from
1151 * Cancel pending schedules and prevent future schedule attempts:
1153 LASSERT (!srpc_event_pending(rpc));
1154 swi_exit_workitem(wi);
1156 spin_unlock(&rpc->crpc_lock);
1158 (*rpc->crpc_done)(rpc);
1162 /* sends an outgoing RPC */
1164 srpc_send_rpc (swi_workitem_t *wi)
1167 srpc_client_rpc_t *rpc;
1171 LASSERT(wi != NULL);
1173 rpc = wi->swi_workitem.wi_data;
1175 LASSERT (rpc != NULL);
1176 LASSERT (wi == &rpc->crpc_wi);
1178 reply = &rpc->crpc_replymsg;
1179 do_bulk = rpc->crpc_bulk.bk_niov > 0;
1181 spin_lock(&rpc->crpc_lock);
1183 if (rpc->crpc_aborted) {
1184 spin_unlock(&rpc->crpc_lock);
1188 spin_unlock(&rpc->crpc_lock);
1190 switch (wi->swi_state) {
1193 case SWI_STATE_NEWBORN:
1194 LASSERT (!srpc_event_pending(rpc));
1196 rc = srpc_prepare_reply(rpc);
1198 srpc_client_rpc_done(rpc, rc);
1202 rc = srpc_prepare_bulk(rpc);
1205 wi->swi_state = SWI_STATE_REQUEST_SUBMITTED;
1206 rc = srpc_send_request(rpc);
1209 case SWI_STATE_REQUEST_SUBMITTED:
1210 /* CAVEAT EMPTOR: rqtev, rpyev, and bulkev may come in any
1211 * order; however, they're processed in a strict order:
1212 * rqt, rpy, and bulk. */
1213 if (!rpc->crpc_reqstev.ev_fired) break;
1215 rc = rpc->crpc_reqstev.ev_status;
1218 wi->swi_state = SWI_STATE_REQUEST_SENT;
1219 /* perhaps more events, fall thru */
1220 case SWI_STATE_REQUEST_SENT: {
1221 srpc_msg_type_t type = srpc_service2reply(rpc->crpc_service);
1223 if (!rpc->crpc_replyev.ev_fired) break;
1225 rc = rpc->crpc_replyev.ev_status;
1228 srpc_unpack_msg_hdr(reply);
1229 if (reply->msg_type != type ||
1230 (reply->msg_magic != SRPC_MSG_MAGIC &&
1231 reply->msg_magic != __swab32(SRPC_MSG_MAGIC))) {
1232 CWARN ("Bad message from %s: type %u (%d expected),"
1233 " magic %u (%d expected).\n",
1234 libcfs_id2str(rpc->crpc_dest),
1235 reply->msg_type, type,
1236 reply->msg_magic, SRPC_MSG_MAGIC);
1241 if (do_bulk && reply->msg_body.reply.status != 0) {
1242 CWARN ("Remote error %d at %s, unlink bulk buffer in "
1243 "case peer didn't initiate bulk transfer\n",
1244 reply->msg_body.reply.status,
1245 libcfs_id2str(rpc->crpc_dest));
1246 LNetMDUnlink(rpc->crpc_bulk.bk_mdh);
1249 wi->swi_state = SWI_STATE_REPLY_RECEIVED;
1251 case SWI_STATE_REPLY_RECEIVED:
1252 if (do_bulk && !rpc->crpc_bulkev.ev_fired) break;
1254 rc = do_bulk ? rpc->crpc_bulkev.ev_status : 0;
1256 /* Bulk buffer was unlinked due to remote error. Clear error
1257 * since reply buffer still contains valid data.
1258 * NB rpc->crpc_done shouldn't look into bulk data in case of
1260 if (do_bulk && rpc->crpc_bulkev.ev_lnet == LNET_EVENT_UNLINK &&
1261 rpc->crpc_status == 0 && reply->msg_body.reply.status != 0)
1264 wi->swi_state = SWI_STATE_DONE;
1265 srpc_client_rpc_done(rpc, rc);
1270 spin_lock(&rpc->crpc_lock);
1271 srpc_abort_rpc(rpc, rc);
1272 spin_unlock(&rpc->crpc_lock);
1276 if (rpc->crpc_aborted) {
1277 LNetMDUnlink(rpc->crpc_reqstmdh);
1278 LNetMDUnlink(rpc->crpc_replymdh);
1279 LNetMDUnlink(rpc->crpc_bulk.bk_mdh);
1281 if (!srpc_event_pending(rpc)) {
1282 srpc_client_rpc_done(rpc, -EINTR);
1290 srpc_create_client_rpc(struct lnet_process_id peer, int service,
1291 int nbulkiov, int bulklen,
1292 void (*rpc_done)(srpc_client_rpc_t *),
1293 void (*rpc_fini)(srpc_client_rpc_t *), void *priv)
1295 srpc_client_rpc_t *rpc;
1297 LIBCFS_ALLOC(rpc, offsetof(srpc_client_rpc_t,
1298 crpc_bulk.bk_iovs[nbulkiov]));
1302 srpc_init_client_rpc(rpc, peer, service, nbulkiov,
1303 bulklen, rpc_done, rpc_fini, priv);
1307 /* called with rpc->crpc_lock held */
1309 srpc_abort_rpc (srpc_client_rpc_t *rpc, int why)
1313 if (rpc->crpc_aborted || /* already aborted */
1314 rpc->crpc_closed) /* callback imminent */
1318 "Aborting RPC: service %d, peer %s, state %s, why %d\n",
1319 rpc->crpc_service, libcfs_id2str(rpc->crpc_dest),
1320 swi_state2str(rpc->crpc_wi.swi_state), why);
1322 rpc->crpc_aborted = 1;
1323 rpc->crpc_status = why;
1324 swi_schedule_workitem(&rpc->crpc_wi);
1328 /* called with rpc->crpc_lock held */
1330 srpc_post_rpc (srpc_client_rpc_t *rpc)
1332 LASSERT (!rpc->crpc_aborted);
1333 LASSERT (srpc_data.rpc_state == SRPC_STATE_RUNNING);
1335 CDEBUG (D_NET, "Posting RPC: peer %s, service %d, timeout %d\n",
1336 libcfs_id2str(rpc->crpc_dest), rpc->crpc_service,
1339 srpc_add_client_rpc_timer(rpc);
1340 swi_schedule_workitem(&rpc->crpc_wi);
1346 srpc_send_reply(struct srpc_server_rpc *rpc)
1348 srpc_event_t *ev = &rpc->srpc_ev;
1349 struct srpc_msg *msg = &rpc->srpc_replymsg;
1350 struct srpc_buffer *buffer = rpc->srpc_reqstbuf;
1351 struct srpc_service_cd *scd = rpc->srpc_scd;
1352 struct srpc_service *sv = scd->scd_svc;
1356 LASSERT(buffer != NULL);
1357 rpyid = buffer->buf_msg.msg_body.reqst.rpyid;
1359 spin_lock(&scd->scd_lock);
1361 if (!sv->sv_shuttingdown && !srpc_serv_is_framework(sv)) {
1362 /* Repost buffer before replying since test client
1363 * might send me another RPC once it gets the reply */
1364 if (srpc_service_post_buffer(scd, buffer) != 0)
1365 CWARN("Failed to repost %s buffer\n", sv->sv_name);
1366 rpc->srpc_reqstbuf = NULL;
1369 spin_unlock(&scd->scd_lock);
1373 ev->ev_type = SRPC_REPLY_SENT;
1375 msg->msg_magic = SRPC_MSG_MAGIC;
1376 msg->msg_version = SRPC_MSG_VERSION;
1377 msg->msg_type = srpc_service2reply(sv->sv_id);
1379 rc = srpc_post_active_rdma(SRPC_RDMA_PORTAL, rpyid, msg,
1380 sizeof(*msg), LNET_MD_OP_PUT,
1381 rpc->srpc_peer, rpc->srpc_self,
1382 &rpc->srpc_replymdh, ev);
1384 ev->ev_fired = 1; /* no more event expected */
1388 /* when in kernel always called with LNET_LOCK() held, and in thread context */
1390 srpc_lnet_ev_handler(struct lnet_event *ev)
1392 struct srpc_service_cd *scd;
1393 srpc_event_t *rpcev = ev->md.user_ptr;
1394 srpc_client_rpc_t *crpc;
1395 srpc_server_rpc_t *srpc;
1396 srpc_buffer_t *buffer;
1399 srpc_msg_type_t type;
1401 LASSERT (!in_interrupt());
1403 if (ev->status != 0) {
1406 spin_lock(&srpc_data.rpc_glock);
1407 if (ev->status != -ECANCELED) /* cancellation is not error */
1408 srpc_data.rpc_counters.errors++;
1409 errors = srpc_data.rpc_counters.errors;
1410 spin_unlock(&srpc_data.rpc_glock);
1412 CNETERR("LNet event status %d type %d, RPC errors %u\n",
1413 ev->status, ev->type, errors);
1416 rpcev->ev_lnet = ev->type;
1418 switch (rpcev->ev_type) {
1420 CERROR("Unknown event: status %d, type %d, lnet %d\n",
1421 rpcev->ev_status, rpcev->ev_type, rpcev->ev_lnet);
1423 case SRPC_REQUEST_SENT:
1424 if (ev->status == 0 && ev->type != LNET_EVENT_UNLINK) {
1425 spin_lock(&srpc_data.rpc_glock);
1426 srpc_data.rpc_counters.rpcs_sent++;
1427 spin_unlock(&srpc_data.rpc_glock);
1429 case SRPC_REPLY_RCVD:
1430 case SRPC_BULK_REQ_RCVD:
1431 crpc = rpcev->ev_data;
1433 if (rpcev != &crpc->crpc_reqstev &&
1434 rpcev != &crpc->crpc_replyev &&
1435 rpcev != &crpc->crpc_bulkev) {
1436 CERROR("rpcev %p, crpc %p, reqstev %p, replyev %p, bulkev %p\n",
1437 rpcev, crpc, &crpc->crpc_reqstev,
1438 &crpc->crpc_replyev, &crpc->crpc_bulkev);
1439 CERROR("Bad event: status %d, type %d, lnet %d\n",
1440 rpcev->ev_status, rpcev->ev_type, rpcev->ev_lnet);
1444 spin_lock(&crpc->crpc_lock);
1446 LASSERT(rpcev->ev_fired == 0);
1447 rpcev->ev_fired = 1;
1448 rpcev->ev_status = (ev->type == LNET_EVENT_UNLINK) ?
1449 -EINTR : ev->status;
1450 swi_schedule_workitem(&crpc->crpc_wi);
1452 spin_unlock(&crpc->crpc_lock);
1455 case SRPC_REQUEST_RCVD:
1456 scd = rpcev->ev_data;
1459 LASSERT(rpcev == &scd->scd_ev);
1461 spin_lock(&scd->scd_lock);
1463 LASSERT (ev->unlinked);
1464 LASSERT (ev->type == LNET_EVENT_PUT ||
1465 ev->type == LNET_EVENT_UNLINK);
1466 LASSERT (ev->type != LNET_EVENT_UNLINK ||
1467 sv->sv_shuttingdown);
1469 buffer = container_of(ev->md.start, srpc_buffer_t, buf_msg);
1470 buffer->buf_peer = ev->source;
1471 buffer->buf_self = ev->target.nid;
1473 LASSERT(scd->scd_buf_nposted > 0);
1474 scd->scd_buf_nposted--;
1476 if (sv->sv_shuttingdown) {
1477 /* Leave buffer on scd->scd_buf_nposted since
1478 * srpc_finish_service needs to traverse it. */
1479 spin_unlock(&scd->scd_lock);
1483 if (scd->scd_buf_err_stamp != 0 &&
1484 scd->scd_buf_err_stamp < ktime_get_real_seconds()) {
1485 /* re-enable adding buffer */
1486 scd->scd_buf_err_stamp = 0;
1487 scd->scd_buf_err = 0;
1490 if (scd->scd_buf_err == 0 && /* adding buffer is enabled */
1491 scd->scd_buf_adjust == 0 &&
1492 scd->scd_buf_nposted < scd->scd_buf_low) {
1493 scd->scd_buf_adjust = MAX(scd->scd_buf_total / 2,
1495 swi_schedule_workitem(&scd->scd_buf_wi);
1498 list_del(&buffer->buf_list); /* from scd->scd_buf_posted */
1499 msg = &buffer->buf_msg;
1500 type = srpc_service2request(sv->sv_id);
1502 if (ev->status != 0 || ev->mlength != sizeof(*msg) ||
1503 (msg->msg_type != type &&
1504 msg->msg_type != __swab32(type)) ||
1505 (msg->msg_magic != SRPC_MSG_MAGIC &&
1506 msg->msg_magic != __swab32(SRPC_MSG_MAGIC))) {
1507 CERROR ("Dropping RPC (%s) from %s: "
1508 "status %d mlength %d type %u magic %u.\n",
1509 sv->sv_name, libcfs_id2str(ev->initiator),
1510 ev->status, ev->mlength,
1511 msg->msg_type, msg->msg_magic);
1513 /* NB can't call srpc_service_recycle_buffer here since
1514 * it may call LNetM[DE]Attach. The invalid magic tells
1515 * srpc_handle_rpc to drop this RPC */
1519 if (!list_empty(&scd->scd_rpc_free)) {
1520 srpc = list_entry(scd->scd_rpc_free.next,
1521 struct srpc_server_rpc,
1523 list_del(&srpc->srpc_list);
1525 srpc_init_server_rpc(srpc, scd, buffer);
1526 list_add_tail(&srpc->srpc_list,
1527 &scd->scd_rpc_active);
1528 swi_schedule_workitem(&srpc->srpc_wi);
1530 list_add_tail(&buffer->buf_list,
1531 &scd->scd_buf_blocked);
1534 spin_unlock(&scd->scd_lock);
1536 spin_lock(&srpc_data.rpc_glock);
1537 srpc_data.rpc_counters.rpcs_rcvd++;
1538 spin_unlock(&srpc_data.rpc_glock);
1541 case SRPC_BULK_GET_RPLD:
1542 LASSERT (ev->type == LNET_EVENT_SEND ||
1543 ev->type == LNET_EVENT_REPLY ||
1544 ev->type == LNET_EVENT_UNLINK);
1547 break; /* wait for final event */
1549 case SRPC_BULK_PUT_SENT:
1550 if (ev->status == 0 && ev->type != LNET_EVENT_UNLINK) {
1551 spin_lock(&srpc_data.rpc_glock);
1553 if (rpcev->ev_type == SRPC_BULK_GET_RPLD)
1554 srpc_data.rpc_counters.bulk_get += ev->mlength;
1556 srpc_data.rpc_counters.bulk_put += ev->mlength;
1558 spin_unlock(&srpc_data.rpc_glock);
1560 case SRPC_REPLY_SENT:
1561 srpc = rpcev->ev_data;
1562 scd = srpc->srpc_scd;
1564 LASSERT(rpcev == &srpc->srpc_ev);
1566 spin_lock(&scd->scd_lock);
1568 rpcev->ev_fired = 1;
1569 rpcev->ev_status = (ev->type == LNET_EVENT_UNLINK) ?
1570 -EINTR : ev->status;
1571 swi_schedule_workitem(&srpc->srpc_wi);
1573 spin_unlock(&scd->scd_lock);
1584 memset(&srpc_data, 0, sizeof(struct smoketest_rpc));
1585 spin_lock_init(&srpc_data.rpc_glock);
1587 /* 1 second pause to avoid timestamp reuse */
1588 set_current_state(TASK_UNINTERRUPTIBLE);
1589 schedule_timeout(cfs_time_seconds(1));
1590 srpc_data.rpc_matchbits = ((__u64) ktime_get_real_seconds()) << 48;
1592 srpc_data.rpc_state = SRPC_STATE_NONE;
1594 rc = LNetNIInit(LNET_PID_LUSTRE);
1596 CERROR ("LNetNIInit() has failed: %d\n", rc);
1600 srpc_data.rpc_state = SRPC_STATE_NI_INIT;
1602 LNetInvalidateEQHandle(&srpc_data.rpc_lnet_eq);
1603 rc = LNetEQAlloc(0, srpc_lnet_ev_handler, &srpc_data.rpc_lnet_eq);
1605 CERROR("LNetEQAlloc() has failed: %d\n", rc);
1609 rc = LNetSetLazyPortal(SRPC_FRAMEWORK_REQUEST_PORTAL);
1611 rc = LNetSetLazyPortal(SRPC_REQUEST_PORTAL);
1614 srpc_data.rpc_state = SRPC_STATE_EQ_INIT;
1622 srpc_data.rpc_state = SRPC_STATE_RUNNING;
1628 srpc_shutdown (void)
1634 state = srpc_data.rpc_state;
1635 srpc_data.rpc_state = SRPC_STATE_STOPPING;
1640 case SRPC_STATE_RUNNING:
1641 spin_lock(&srpc_data.rpc_glock);
1643 for (i = 0; i <= SRPC_SERVICE_MAX_ID; i++) {
1644 srpc_service_t *sv = srpc_data.rpc_services[i];
1646 LASSERTF (sv == NULL,
1647 "service not empty: id %d, name %s\n",
1651 spin_unlock(&srpc_data.rpc_glock);
1655 case SRPC_STATE_EQ_INIT:
1656 rc = LNetClearLazyPortal(SRPC_FRAMEWORK_REQUEST_PORTAL);
1657 rc = LNetClearLazyPortal(SRPC_REQUEST_PORTAL);
1659 rc = LNetEQFree(srpc_data.rpc_lnet_eq);
1660 LASSERT (rc == 0); /* the EQ should have no user by now */
1662 case SRPC_STATE_NI_INIT: