1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define DEBUG_SUBSYSTEM S_RPC
25 #include <liblustre.h>
26 #include <linux/kp30.h>
28 #include <linux/obd_support.h>
29 #include <linux/obd_class.h>
30 #include <linux/lustre_net.h>
31 #include <portals/types.h>
32 #include "ptlrpc_internal.h"
34 static LIST_HEAD (ptlrpc_all_services);
35 static spinlock_t ptlrpc_all_services_lock = SPIN_LOCK_UNLOCKED;
38 ptlrpc_free_server_req (struct ptlrpc_request *req)
40 /* The last request to be received into a request buffer uses space
41 * in the request buffer descriptor, otherwise requests are
42 * allocated dynamically in the incoming reply event handler */
43 if (req == &req->rq_rqbd->rqbd_req)
46 OBD_FREE(req, sizeof(*req));
50 ptlrpc_alloc_request_buffer (int size)
54 if (size > SVC_BUF_VMALLOC_THRESHOLD)
55 OBD_VMALLOC(ptr, size);
63 ptlrpc_free_request_buffer (char *ptr, int size)
65 if (size > SVC_BUF_VMALLOC_THRESHOLD)
71 struct ptlrpc_request_buffer_desc *
72 ptlrpc_alloc_rqbd (struct ptlrpc_srv_ni *srv_ni)
74 struct ptlrpc_service *svc = srv_ni->sni_service;
76 struct ptlrpc_request_buffer_desc *rqbd;
78 OBD_ALLOC(rqbd, sizeof (*rqbd));
82 rqbd->rqbd_srv_ni = srv_ni;
83 rqbd->rqbd_refcount = 0;
84 rqbd->rqbd_cbid.cbid_fn = request_in_callback;
85 rqbd->rqbd_cbid.cbid_arg = rqbd;
86 rqbd->rqbd_buffer = ptlrpc_alloc_request_buffer(svc->srv_buf_size);
88 if (rqbd->rqbd_buffer == NULL) {
89 OBD_FREE(rqbd, sizeof (*rqbd));
93 spin_lock_irqsave (&svc->srv_lock, flags);
94 list_add(&rqbd->rqbd_list, &srv_ni->sni_rqbds);
96 spin_unlock_irqrestore (&svc->srv_lock, flags);
102 ptlrpc_free_rqbd (struct ptlrpc_request_buffer_desc *rqbd)
104 struct ptlrpc_srv_ni *sni = rqbd->rqbd_srv_ni;
105 struct ptlrpc_service *svc = sni->sni_service;
108 LASSERT (rqbd->rqbd_refcount == 0);
110 spin_lock_irqsave(&svc->srv_lock, flags);
111 list_del(&rqbd->rqbd_list);
113 spin_unlock_irqrestore(&svc->srv_lock, flags);
115 ptlrpc_free_request_buffer (rqbd->rqbd_buffer, svc->srv_buf_size);
116 OBD_FREE (rqbd, sizeof (*rqbd));
120 ptlrpc_save_lock (struct ptlrpc_request *req,
121 struct lustre_handle *lock, int mode)
123 struct ptlrpc_reply_state *rs = req->rq_reply_state;
126 LASSERT (rs != NULL);
127 LASSERT (rs->rs_nlocks < RS_MAX_LOCKS);
129 idx = rs->rs_nlocks++;
130 rs->rs_locks[idx] = *lock;
131 rs->rs_modes[idx] = mode;
132 rs->rs_difficult = 1;
136 ptlrpc_schedule_difficult_reply (struct ptlrpc_reply_state *rs)
138 struct ptlrpc_service *svc = rs->rs_srv_ni->sni_service;
141 LASSERT (spin_is_locked (&svc->srv_lock));
143 LASSERT (rs->rs_difficult);
144 rs->rs_scheduled_ever = 1; /* flag any notification attempt */
146 if (rs->rs_scheduled) /* being set up or already notified */
149 rs->rs_scheduled = 1;
150 list_del (&rs->rs_list);
151 list_add (&rs->rs_list, &svc->srv_reply_queue);
152 wake_up (&svc->srv_waitq);
156 ptlrpc_commit_replies (struct obd_device *obd)
158 struct list_head *tmp;
159 struct list_head *nxt;
162 /* Find any replies that have been committed and get their service
163 * to attend to complete them. */
165 /* CAVEAT EMPTOR: spinlock ordering!!! */
166 spin_lock_irqsave (&obd->obd_uncommitted_replies_lock, flags);
168 list_for_each_safe (tmp, nxt, &obd->obd_uncommitted_replies) {
169 struct ptlrpc_reply_state *rs =
170 list_entry (tmp, struct ptlrpc_reply_state, rs_obd_list);
172 LASSERT (rs->rs_difficult);
174 if (rs->rs_transno <= obd->obd_last_committed) {
175 struct ptlrpc_service *svc = rs->rs_srv_ni->sni_service;
177 spin_lock (&svc->srv_lock);
178 list_del_init (&rs->rs_obd_list);
179 ptlrpc_schedule_difficult_reply (rs);
180 spin_unlock (&svc->srv_lock);
184 spin_unlock_irqrestore (&obd->obd_uncommitted_replies_lock, flags);
188 timeval_sub(struct timeval *large, struct timeval *small)
190 return (large->tv_sec - small->tv_sec) * 1000000 +
191 (large->tv_usec - small->tv_usec);
194 struct ptlrpc_service *
195 ptlrpc_init_svc(int nbufs, int bufsize, int max_req_size,
196 int req_portal, int rep_portal,
197 svc_handler_t handler, char *name,
198 struct proc_dir_entry *proc_entry)
203 struct ptlrpc_service *service;
204 struct ptlrpc_srv_ni *srv_ni;
205 struct ptlrpc_request_buffer_desc *rqbd;
208 LASSERT (ptlrpc_ninterfaces > 0);
210 LASSERT (bufsize >= max_req_size);
212 ssize = offsetof (struct ptlrpc_service,
213 srv_interfaces[ptlrpc_ninterfaces]);
214 OBD_ALLOC(service, ssize);
218 service->srv_name = name;
219 spin_lock_init(&service->srv_lock);
220 INIT_LIST_HEAD(&service->srv_threads);
221 init_waitqueue_head(&service->srv_waitq);
223 service->srv_max_req_size = max_req_size;
224 service->srv_buf_size = bufsize;
225 service->srv_rep_portal = rep_portal;
226 service->srv_req_portal = req_portal;
227 service->srv_handler = handler;
229 INIT_LIST_HEAD(&service->srv_request_queue);
230 INIT_LIST_HEAD(&service->srv_reply_queue);
232 /* First initialise enough for early teardown */
233 for (i = 0; i < ptlrpc_ninterfaces; i++) {
234 srv_ni = &service->srv_interfaces[i];
236 srv_ni->sni_service = service;
237 srv_ni->sni_ni = &ptlrpc_interfaces[i];
238 INIT_LIST_HEAD(&srv_ni->sni_rqbds);
239 INIT_LIST_HEAD(&srv_ni->sni_active_replies);
242 spin_lock (&ptlrpc_all_services_lock);
243 list_add (&service->srv_list, &ptlrpc_all_services);
244 spin_unlock (&ptlrpc_all_services_lock);
246 /* Now allocate the request buffers, assuming all interfaces require
247 * the same number. */
248 for (i = 0; i < ptlrpc_ninterfaces; i++) {
249 srv_ni = &service->srv_interfaces[i];
250 CDEBUG (D_NET, "%s: initialising interface %s\n", name,
251 srv_ni->sni_ni->pni_name);
253 for (j = 0; j < nbufs; j++) {
254 rqbd = ptlrpc_alloc_rqbd (srv_ni);
257 CERROR ("%s.%d: Can't allocate request %d "
258 "on %s\n", name, i, j,
259 srv_ni->sni_ni->pni_name);
262 ptlrpc_register_rqbd (rqbd);
266 if (proc_entry != NULL)
267 ptlrpc_lprocfs_register_service(proc_entry, service);
269 CDEBUG(D_NET, "%s: Started on %d interfaces, listening on portal %d\n",
270 service->srv_name, ptlrpc_ninterfaces, service->srv_req_portal);
274 ptlrpc_unregister_service(service);
279 ptlrpc_server_handle_request (struct ptlrpc_service *svc)
281 struct ptlrpc_request *request;
283 struct timeval work_start;
284 struct timeval work_end;
290 spin_lock_irqsave (&svc->srv_lock, flags);
291 if (list_empty (&svc->srv_request_queue) ||
292 (svc->srv_n_difficult_replies != 0 &&
293 svc->srv_n_active_reqs >= (svc->srv_nthreads - 1))) {
294 /* If all the other threads are handling requests, I must
295 * remain free to handle any 'difficult' reply that might
297 spin_unlock_irqrestore (&svc->srv_lock, flags);
301 request = list_entry (svc->srv_request_queue.next,
302 struct ptlrpc_request, rq_list);
303 list_del_init (&request->rq_list);
304 svc->srv_n_queued_reqs--;
305 svc->srv_n_active_reqs++;
307 spin_unlock_irqrestore (&svc->srv_lock, flags);
309 do_gettimeofday(&work_start);
310 timediff = timeval_sub(&work_start, &request->rq_arrival_time);
311 if (svc->srv_stats != NULL) {
312 lprocfs_counter_add(svc->srv_stats, PTLRPC_REQWAIT_CNTR,
314 lprocfs_counter_add(svc->srv_stats, PTLRPC_REQQDEPTH_CNTR,
315 svc->srv_n_queued_reqs);
316 lprocfs_counter_add(svc->srv_stats, PTLRPC_REQACTIVE_CNTR,
317 svc->srv_n_active_reqs);
321 /* Clear request swab mask; this is a new request */
322 request->rq_req_swab_mask = 0;
324 rc = lustre_unpack_msg (request->rq_reqmsg, request->rq_reqlen);
326 CERROR ("error unpacking request: ptl %d from "LPX64
327 " xid "LPU64"\n", svc->srv_req_portal,
328 request->rq_peer.peer_nid, request->rq_xid);
333 if (request->rq_reqmsg->type != PTL_RPC_MSG_REQUEST) {
334 CERROR("wrong packet type received (type=%u) from "
335 LPX64"\n", request->rq_reqmsg->type,
336 request->rq_peer.peer_nid);
340 CDEBUG(D_NET, "got req "LPD64"\n", request->rq_xid);
342 /* Discard requests queued for longer than my timeout. If the
343 * client's timeout is similar to mine, she'll be timing out this
344 * REQ anyway (bug 1502) */
345 if (timediff / 1000000 > (long)obd_timeout) {
346 CERROR("Dropping timed-out request from "LPX64
347 ": %ld seconds old\n",
348 request->rq_peer.peer_nid, timediff / 1000000);
352 request->rq_export = class_conn2export(&request->rq_reqmsg->handle);
354 if (request->rq_export) {
355 if (request->rq_reqmsg->conn_cnt <
356 request->rq_export->exp_conn_cnt) {
357 DEBUG_REQ(D_ERROR, request,
358 "DROPPING req from old connection %d < %d",
359 request->rq_reqmsg->conn_cnt,
360 request->rq_export->exp_conn_cnt);
364 request->rq_export->exp_last_request_time =
365 LTIME_S(CURRENT_TIME);
368 CDEBUG(D_RPCTRACE, "Handling RPC pname:cluuid+ref:pid:xid:ni:nid:opc "
369 "%s:%s+%d:%d:"LPU64":%s:"LPX64":%d\n", current->comm,
370 (request->rq_export ?
371 (char *)request->rq_export->exp_client_uuid.uuid : "0"),
372 (request->rq_export ?
373 atomic_read(&request->rq_export->exp_refcount) : -99),
374 request->rq_reqmsg->status, request->rq_xid,
375 request->rq_peer.peer_ni->pni_name,
376 request->rq_peer.peer_nid,
377 request->rq_reqmsg->opc);
379 rc = svc->srv_handler(request);
380 CDEBUG(D_RPCTRACE, "Handled RPC pname:cluuid+ref:pid:xid:ni:nid:opc "
381 "%s:%s+%d:%d:"LPU64":%s:"LPX64":%d\n", current->comm,
382 (request->rq_export ?
383 (char *)request->rq_export->exp_client_uuid.uuid : "0"),
384 (request->rq_export ?
385 atomic_read(&request->rq_export->exp_refcount) : -99),
386 request->rq_reqmsg->status, request->rq_xid,
387 request->rq_peer.peer_ni->pni_name,
388 request->rq_peer.peer_nid,
389 request->rq_reqmsg->opc);
392 if (request->rq_export != NULL)
393 class_export_put(request->rq_export);
396 do_gettimeofday(&work_end);
398 timediff = timeval_sub(&work_end, &work_start);
400 CDEBUG((timediff / 1000000 > (long)obd_timeout) ? D_ERROR : D_HA,
401 "request "LPU64" opc %u from NID "LPX64" processed in %ldus "
402 "(%ldus total)\n", request->rq_xid, request->rq_reqmsg->opc,
403 request->rq_peer.peer_nid,
404 timediff, timeval_sub(&work_end, &request->rq_arrival_time));
406 if (svc->srv_stats != NULL) {
407 int opc = opcode_offset(request->rq_reqmsg->opc);
409 LASSERT(opc < LUSTRE_MAX_OPCODES);
410 lprocfs_counter_add(svc->srv_stats,
411 opc + PTLRPC_LAST_CNTR,
416 spin_lock_irqsave(&svc->srv_lock, flags);
417 svc->srv_n_active_reqs--;
418 refcount = --(request->rq_rqbd->rqbd_refcount);
419 spin_unlock_irqrestore(&svc->srv_lock, flags);
422 /* rqbd now idle: repost */
423 ptlrpc_register_rqbd(request->rq_rqbd);
426 ptlrpc_free_server_req(request);
432 ptlrpc_server_handle_reply (struct ptlrpc_service *svc)
434 struct ptlrpc_reply_state *rs;
436 struct obd_export *exp;
437 struct obd_device *obd;
442 spin_lock_irqsave (&svc->srv_lock, flags);
443 if (list_empty (&svc->srv_reply_queue)) {
444 spin_unlock_irqrestore (&svc->srv_lock, flags);
448 rs = list_entry (svc->srv_reply_queue.next,
449 struct ptlrpc_reply_state, rs_list);
454 LASSERT (rs->rs_difficult);
455 LASSERT (rs->rs_scheduled);
457 list_del_init (&rs->rs_list);
459 /* Disengage from notifiers carefully (lock ordering!) */
460 spin_unlock(&svc->srv_lock);
462 spin_lock (&obd->obd_uncommitted_replies_lock);
463 /* Noop if removed already */
464 list_del_init (&rs->rs_obd_list);
465 spin_unlock (&obd->obd_uncommitted_replies_lock);
467 spin_lock (&exp->exp_lock);
468 /* Noop if removed already */
469 list_del_init (&rs->rs_exp_list);
470 spin_unlock (&exp->exp_lock);
472 spin_lock(&svc->srv_lock);
474 been_handled = rs->rs_handled;
477 nlocks = rs->rs_nlocks; /* atomic "steal", but */
478 rs->rs_nlocks = 0; /* locks still on rs_locks! */
480 if (nlocks == 0 && !been_handled) {
481 /* If we see this, we should already have seen the warning
482 * in mds_steal_ack_locks() */
483 CWARN("All locks stolen from rs %p x"LPD64".t"LPD64
486 rs->rs_xid, rs->rs_transno,
487 rs->rs_msg.opc, exp->exp_connection->c_peer.peer_nid);
490 if ((!been_handled && rs->rs_on_net) ||
492 spin_unlock_irqrestore(&svc->srv_lock, flags);
494 if (!been_handled && rs->rs_on_net) {
495 PtlMDUnlink(rs->rs_md_h);
496 /* Ignore return code; we're racing with
501 ldlm_lock_decref(&rs->rs_locks[nlocks],
502 rs->rs_modes[nlocks]);
504 spin_lock_irqsave(&svc->srv_lock, flags);
507 rs->rs_scheduled = 0;
509 if (!rs->rs_on_net) {
511 svc->srv_n_difficult_replies--;
512 spin_unlock_irqrestore(&svc->srv_lock, flags);
514 class_export_put (exp);
515 rs->rs_export = NULL;
516 lustre_free_reply_state (rs);
517 atomic_dec (&svc->srv_outstanding_replies);
521 /* still on the net; callback will schedule */
522 spin_unlock_irqrestore (&svc->srv_lock, flags);
527 /* FIXME make use of timeout later */
529 liblustre_check_services (void *arg)
531 int did_something = 0;
532 struct list_head *tmp, *nxt;
535 /* I'm relying on being single threaded, not to have to lock
536 * ptlrpc_all_services etc */
537 list_for_each_safe (tmp, nxt, &ptlrpc_all_services) {
538 struct ptlrpc_service *svc =
539 list_entry (tmp, struct ptlrpc_service, srv_list);
541 if (svc->srv_nthreads != 0) /* I've recursed */
544 /* service threads can block for bulk, so this limits us
545 * (arbitrarily) to recursing 1 stack frame per service.
546 * Note that the problem with recursion is that we have to
547 * unwind completely before our caller can resume. */
551 while (ptlrpc_server_handle_reply (svc))
554 while (ptlrpc_server_handle_request (svc))
560 RETURN(did_something);
563 #else /* __KERNEL__ */
565 /* Don't use daemonize, it removes fs struct from new thread (bug 418) */
566 void ptlrpc_daemonize(void)
569 lustre_daemonize_helper();
574 static int ptlrpc_main(void *arg)
576 struct ptlrpc_svc_data *data = (struct ptlrpc_svc_data *)arg;
577 struct ptlrpc_service *svc = data->svc;
578 struct ptlrpc_thread *thread = data->thread;
585 SIGNAL_MASK_LOCK(current, flags);
586 sigfillset(¤t->blocked);
588 SIGNAL_MASK_UNLOCK(current, flags);
590 THREAD_NAME(current->comm, "%s", data->name);
593 /* Record that the thread is running */
594 thread->t_flags = SVC_RUNNING;
595 wake_up(&thread->t_ctl_waitq);
597 spin_lock_irqsave(&svc->srv_lock, flags);
599 spin_unlock_irqrestore(&svc->srv_lock, flags);
601 /* XXX maintain a list of all managed devices: insert here */
603 while ((thread->t_flags & SVC_STOPPING) == 0 ||
604 svc->srv_n_difficult_replies != 0) {
605 /* Don't exit while there are replies to be handled */
606 struct l_wait_info lwi = { 0 };
608 l_wait_event_exclusive (svc->srv_waitq,
609 (thread->t_flags & SVC_STOPPING) != 0 ||
610 !list_empty (&svc->srv_reply_queue) ||
611 (!list_empty (&svc->srv_request_queue) &&
612 (svc->srv_n_difficult_replies == 0 ||
613 svc->srv_n_active_reqs <
614 (svc->srv_nthreads - 1))),
617 if (!list_empty (&svc->srv_reply_queue))
618 ptlrpc_server_handle_reply (svc);
620 /* only handle requests if there are no difficult replies
621 * outstanding, or I'm not the last thread handling
623 if (!list_empty (&svc->srv_request_queue) &&
624 (svc->srv_n_difficult_replies == 0 ||
625 svc->srv_n_active_reqs < (svc->srv_nthreads - 1)))
626 ptlrpc_server_handle_request (svc);
629 spin_lock_irqsave(&svc->srv_lock, flags);
631 svc->srv_nthreads--; /* must know immediately */
632 thread->t_flags = SVC_STOPPED;
633 wake_up(&thread->t_ctl_waitq);
635 spin_unlock_irqrestore(&svc->srv_lock, flags);
637 CDEBUG(D_NET, "service thread exiting, process %d\n", current->pid);
641 static void ptlrpc_stop_thread(struct ptlrpc_service *svc,
642 struct ptlrpc_thread *thread)
644 struct l_wait_info lwi = { 0 };
647 spin_lock_irqsave(&svc->srv_lock, flags);
648 thread->t_flags = SVC_STOPPING;
649 spin_unlock_irqrestore(&svc->srv_lock, flags);
651 wake_up_all(&svc->srv_waitq);
652 l_wait_event(thread->t_ctl_waitq, (thread->t_flags & SVC_STOPPED),
655 spin_lock_irqsave(&svc->srv_lock, flags);
656 list_del(&thread->t_link);
657 spin_unlock_irqrestore(&svc->srv_lock, flags);
659 OBD_FREE(thread, sizeof(*thread));
662 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc)
665 struct ptlrpc_thread *thread;
667 spin_lock_irqsave(&svc->srv_lock, flags);
668 while (!list_empty(&svc->srv_threads)) {
669 thread = list_entry(svc->srv_threads.next,
670 struct ptlrpc_thread, t_link);
672 spin_unlock_irqrestore(&svc->srv_lock, flags);
673 ptlrpc_stop_thread(svc, thread);
674 spin_lock_irqsave(&svc->srv_lock, flags);
677 spin_unlock_irqrestore(&svc->srv_lock, flags);
680 int ptlrpc_start_n_threads(struct obd_device *dev, struct ptlrpc_service *svc,
681 int num_threads, char *base_name)
686 for (i = 0; i < num_threads; i++) {
688 sprintf(name, "%s_%02d", base_name, i);
689 rc = ptlrpc_start_thread(dev, svc, name);
691 CERROR("cannot start %s thread #%d: rc %d\n", base_name,
693 ptlrpc_stop_all_threads(svc);
699 int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc,
702 struct l_wait_info lwi = { 0 };
703 struct ptlrpc_svc_data d;
704 struct ptlrpc_thread *thread;
709 OBD_ALLOC(thread, sizeof(*thread));
712 init_waitqueue_head(&thread->t_ctl_waitq);
719 spin_lock_irqsave(&svc->srv_lock, flags);
720 list_add(&thread->t_link, &svc->srv_threads);
721 spin_unlock_irqrestore(&svc->srv_lock, flags);
723 /* CLONE_VM and CLONE_FILES just avoid a needless copy, because we
724 * just drop the VM and FILES in ptlrpc_daemonize() right away.
726 rc = kernel_thread(ptlrpc_main, &d, CLONE_VM | CLONE_FILES);
728 CERROR("cannot start thread: %d\n", rc);
729 OBD_FREE(thread, sizeof(*thread));
732 l_wait_event(thread->t_ctl_waitq, thread->t_flags & SVC_RUNNING, &lwi);
738 int ptlrpc_unregister_service(struct ptlrpc_service *service)
743 struct ptlrpc_srv_ni *srv_ni;
744 struct l_wait_info lwi;
745 struct list_head *tmp;
747 LASSERT(list_empty(&service->srv_threads));
749 spin_lock (&ptlrpc_all_services_lock);
750 list_del_init (&service->srv_list);
751 spin_unlock (&ptlrpc_all_services_lock);
753 for (i = 0; i < ptlrpc_ninterfaces; i++) {
754 srv_ni = &service->srv_interfaces[i];
755 CDEBUG(D_NET, "%s: tearing down interface %s\n",
756 service->srv_name, srv_ni->sni_ni->pni_name);
758 /* Unlink all the request buffers. This forces a 'final'
759 * event with its 'unlink' flag set for each rqbd */
760 list_for_each(tmp, &srv_ni->sni_rqbds) {
761 struct ptlrpc_request_buffer_desc *rqbd =
762 list_entry(tmp, struct ptlrpc_request_buffer_desc,
765 rc = PtlMDUnlink(rqbd->rqbd_md_h);
766 LASSERT (rc == PTL_OK || rc == PTL_INV_MD);
769 /* Wait for the network to release any buffers it's
770 * currently filling */
772 spin_lock_irqsave(&service->srv_lock, flags);
773 rc = srv_ni->sni_nrqbd_receiving;
774 spin_unlock_irqrestore(&service->srv_lock, flags);
779 /* Network access will complete in finite time but
780 * the HUGE timeout lets us CWARN for visibility of
782 lwi = LWI_TIMEOUT(300 * HZ, NULL, NULL);
783 rc = l_wait_event(service->srv_waitq,
784 srv_ni->sni_nrqbd_receiving == 0,
786 if (rc == -ETIMEDOUT)
787 CWARN("Waiting for request buffers on "
788 "service %s on interface %s ",
789 service->srv_name, srv_ni->sni_ni->pni_name);
792 /* schedule all outstanding replies to terminate them */
793 spin_lock_irqsave(&service->srv_lock, flags);
794 while (!list_empty(&srv_ni->sni_active_replies)) {
795 struct ptlrpc_reply_state *rs =
796 list_entry(srv_ni->sni_active_replies.next,
797 struct ptlrpc_reply_state,
799 ptlrpc_schedule_difficult_reply(rs);
801 spin_unlock_irqrestore(&service->srv_lock, flags);
804 /* purge the request queue. NB No new replies (rqbds all unlinked)
805 * and no service threads, so I'm the only thread noodling the
806 * request queue now */
807 while (!list_empty(&service->srv_request_queue)) {
808 struct ptlrpc_request *req =
809 list_entry(service->srv_request_queue.next,
810 struct ptlrpc_request,
813 list_del(&req->rq_list);
814 service->srv_n_queued_reqs--;
815 req->rq_rqbd->rqbd_refcount--;
817 ptlrpc_free_server_req(req);
819 LASSERT(service->srv_n_queued_reqs == 0);
821 /* Now free all the request buffers since nothing references them
823 for (i = 0; i < ptlrpc_ninterfaces; i++) {
824 srv_ni = &service->srv_interfaces[i];
826 while (!list_empty(&srv_ni->sni_rqbds)) {
827 struct ptlrpc_request_buffer_desc *rqbd =
828 list_entry(srv_ni->sni_rqbds.next,
829 struct ptlrpc_request_buffer_desc,
832 ptlrpc_free_rqbd(rqbd);
836 /* wait for all outstanding replies to complete (they were
837 * scheduled having been flagged to abort above) */
838 while (atomic_read(&service->srv_outstanding_replies) != 0) {
839 struct l_wait_info lwi = LWI_TIMEOUT(10 * HZ, NULL, NULL);
841 rc = l_wait_event(service->srv_waitq,
842 !list_empty(&service->srv_reply_queue), &lwi);
843 LASSERT(rc == 0 || rc == -ETIMEDOUT);
846 ptlrpc_server_handle_reply(service);
849 CWARN("Unexpectedly long timeout %p\n", service);
852 ptlrpc_lprocfs_unregister_service(service);
855 offsetof(struct ptlrpc_service,
856 srv_interfaces[ptlrpc_ninterfaces]));