blob: 5c3eee76850458d1ca17511b405a473267d9cdb6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/net/sunrpc/sched.c
3 *
4 * Scheduling for synchronous and asynchronous RPC requests.
5 *
6 * Copyright (C) 1996 Olaf Kirch, <okir@monad.swb.de>
7 *
8 * TCP NFS related read + write fixes
9 * (C) 1999 Dave Airlie, University of Limerick, Ireland <airlied@linux.ie>
10 */
11
12#include <linux/module.h>
13
14#include <linux/sched.h>
15#include <linux/interrupt.h>
16#include <linux/slab.h>
17#include <linux/mempool.h>
18#include <linux/smp.h>
19#include <linux/smp_lock.h>
20#include <linux/spinlock.h>
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -080021#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#include <linux/sunrpc/clnt.h>
24#include <linux/sunrpc/xprt.h>
25
26#ifdef RPC_DEBUG
27#define RPCDBG_FACILITY RPCDBG_SCHED
28#define RPC_TASK_MAGIC_ID 0xf00baa
29static int rpc_task_id;
30#endif
31
32/*
33 * RPC slabs and memory pools
34 */
35#define RPC_BUFFER_MAXSIZE (2048)
36#define RPC_BUFFER_POOLSIZE (8)
37#define RPC_TASK_POOLSIZE (8)
Eric Dumazetba899662005-08-26 12:05:31 -070038static kmem_cache_t *rpc_task_slabp __read_mostly;
39static kmem_cache_t *rpc_buffer_slabp __read_mostly;
40static mempool_t *rpc_task_mempool __read_mostly;
41static mempool_t *rpc_buffer_mempool __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43static void __rpc_default_timer(struct rpc_task *task);
44static void rpciod_killall(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045static void rpc_async_schedule(void *);
46
47/*
48 * RPC tasks that create another task (e.g. for contacting the portmapper)
49 * will wait on this queue for their child's completion
50 */
51static RPC_WAITQ(childq, "childq");
52
53/*
54 * RPC tasks sit here while waiting for conditions to improve.
55 */
56static RPC_WAITQ(delay_queue, "delayq");
57
58/*
59 * All RPC tasks are linked into this list
60 */
61static LIST_HEAD(all_tasks);
62
63/*
64 * rpciod-related stuff
65 */
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -080066static DEFINE_MUTEX(rpciod_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067static unsigned int rpciod_users;
Trond Myklebust24c5d9d2006-03-20 13:44:08 -050068struct workqueue_struct *rpciod_workqueue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/*
71 * Spinlock for other critical sections of code.
72 */
73static DEFINE_SPINLOCK(rpc_sched_lock);
74
75/*
76 * Disable the timer for a given RPC task. Should be called with
77 * queue->lock and bh_disabled in order to avoid races within
78 * rpc_run_timer().
79 */
80static inline void
81__rpc_disable_timer(struct rpc_task *task)
82{
83 dprintk("RPC: %4d disabling timer\n", task->tk_pid);
84 task->tk_timeout_fn = NULL;
85 task->tk_timeout = 0;
86}
87
88/*
89 * Run a timeout function.
90 * We use the callback in order to allow __rpc_wake_up_task()
91 * and friends to disable the timer synchronously on SMP systems
92 * without calling del_timer_sync(). The latter could cause a
93 * deadlock if called while we're holding spinlocks...
94 */
95static void rpc_run_timer(struct rpc_task *task)
96{
97 void (*callback)(struct rpc_task *);
98
99 callback = task->tk_timeout_fn;
100 task->tk_timeout_fn = NULL;
101 if (callback && RPC_IS_QUEUED(task)) {
102 dprintk("RPC: %4d running timer\n", task->tk_pid);
103 callback(task);
104 }
105 smp_mb__before_clear_bit();
106 clear_bit(RPC_TASK_HAS_TIMER, &task->tk_runstate);
107 smp_mb__after_clear_bit();
108}
109
110/*
111 * Set up a timer for the current task.
112 */
113static inline void
114__rpc_add_timer(struct rpc_task *task, rpc_action timer)
115{
116 if (!task->tk_timeout)
117 return;
118
119 dprintk("RPC: %4d setting alarm for %lu ms\n",
120 task->tk_pid, task->tk_timeout * 1000 / HZ);
121
122 if (timer)
123 task->tk_timeout_fn = timer;
124 else
125 task->tk_timeout_fn = __rpc_default_timer;
126 set_bit(RPC_TASK_HAS_TIMER, &task->tk_runstate);
127 mod_timer(&task->tk_timer, jiffies + task->tk_timeout);
128}
129
130/*
131 * Delete any timer for the current task. Because we use del_timer_sync(),
132 * this function should never be called while holding queue->lock.
133 */
134static void
135rpc_delete_timer(struct rpc_task *task)
136{
137 if (RPC_IS_QUEUED(task))
138 return;
139 if (test_and_clear_bit(RPC_TASK_HAS_TIMER, &task->tk_runstate)) {
140 del_singleshot_timer_sync(&task->tk_timer);
141 dprintk("RPC: %4d deleting timer\n", task->tk_pid);
142 }
143}
144
145/*
146 * Add new request to a priority queue.
147 */
148static void __rpc_add_wait_queue_priority(struct rpc_wait_queue *queue, struct rpc_task *task)
149{
150 struct list_head *q;
151 struct rpc_task *t;
152
153 INIT_LIST_HEAD(&task->u.tk_wait.links);
154 q = &queue->tasks[task->tk_priority];
155 if (unlikely(task->tk_priority > queue->maxpriority))
156 q = &queue->tasks[queue->maxpriority];
157 list_for_each_entry(t, q, u.tk_wait.list) {
158 if (t->tk_cookie == task->tk_cookie) {
159 list_add_tail(&task->u.tk_wait.list, &t->u.tk_wait.links);
160 return;
161 }
162 }
163 list_add_tail(&task->u.tk_wait.list, q);
164}
165
166/*
167 * Add new request to wait queue.
168 *
169 * Swapper tasks always get inserted at the head of the queue.
170 * This should avoid many nasty memory deadlocks and hopefully
171 * improve overall performance.
172 * Everyone else gets appended to the queue to ensure proper FIFO behavior.
173 */
174static void __rpc_add_wait_queue(struct rpc_wait_queue *queue, struct rpc_task *task)
175{
176 BUG_ON (RPC_IS_QUEUED(task));
177
178 if (RPC_IS_PRIORITY(queue))
179 __rpc_add_wait_queue_priority(queue, task);
180 else if (RPC_IS_SWAPPER(task))
181 list_add(&task->u.tk_wait.list, &queue->tasks[0]);
182 else
183 list_add_tail(&task->u.tk_wait.list, &queue->tasks[0]);
184 task->u.tk_wait.rpc_waitq = queue;
Chuck Levere19b63d2006-03-20 13:44:15 -0500185 queue->qlen++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 rpc_set_queued(task);
187
188 dprintk("RPC: %4d added to queue %p \"%s\"\n",
189 task->tk_pid, queue, rpc_qname(queue));
190}
191
192/*
193 * Remove request from a priority queue.
194 */
195static void __rpc_remove_wait_queue_priority(struct rpc_task *task)
196{
197 struct rpc_task *t;
198
199 if (!list_empty(&task->u.tk_wait.links)) {
200 t = list_entry(task->u.tk_wait.links.next, struct rpc_task, u.tk_wait.list);
201 list_move(&t->u.tk_wait.list, &task->u.tk_wait.list);
202 list_splice_init(&task->u.tk_wait.links, &t->u.tk_wait.links);
203 }
204 list_del(&task->u.tk_wait.list);
205}
206
207/*
208 * Remove request from queue.
209 * Note: must be called with spin lock held.
210 */
211static void __rpc_remove_wait_queue(struct rpc_task *task)
212{
213 struct rpc_wait_queue *queue;
214 queue = task->u.tk_wait.rpc_waitq;
215
216 if (RPC_IS_PRIORITY(queue))
217 __rpc_remove_wait_queue_priority(task);
218 else
219 list_del(&task->u.tk_wait.list);
Chuck Levere19b63d2006-03-20 13:44:15 -0500220 queue->qlen--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 dprintk("RPC: %4d removed from queue %p \"%s\"\n",
222 task->tk_pid, queue, rpc_qname(queue));
223}
224
225static inline void rpc_set_waitqueue_priority(struct rpc_wait_queue *queue, int priority)
226{
227 queue->priority = priority;
228 queue->count = 1 << (priority * 2);
229}
230
231static inline void rpc_set_waitqueue_cookie(struct rpc_wait_queue *queue, unsigned long cookie)
232{
233 queue->cookie = cookie;
234 queue->nr = RPC_BATCH_COUNT;
235}
236
237static inline void rpc_reset_waitqueue_priority(struct rpc_wait_queue *queue)
238{
239 rpc_set_waitqueue_priority(queue, queue->maxpriority);
240 rpc_set_waitqueue_cookie(queue, 0);
241}
242
243static void __rpc_init_priority_wait_queue(struct rpc_wait_queue *queue, const char *qname, int maxprio)
244{
245 int i;
246
247 spin_lock_init(&queue->lock);
248 for (i = 0; i < ARRAY_SIZE(queue->tasks); i++)
249 INIT_LIST_HEAD(&queue->tasks[i]);
250 queue->maxpriority = maxprio;
251 rpc_reset_waitqueue_priority(queue);
252#ifdef RPC_DEBUG
253 queue->name = qname;
254#endif
255}
256
257void rpc_init_priority_wait_queue(struct rpc_wait_queue *queue, const char *qname)
258{
259 __rpc_init_priority_wait_queue(queue, qname, RPC_PRIORITY_HIGH);
260}
261
262void rpc_init_wait_queue(struct rpc_wait_queue *queue, const char *qname)
263{
264 __rpc_init_priority_wait_queue(queue, qname, 0);
265}
266EXPORT_SYMBOL(rpc_init_wait_queue);
267
Trond Myklebust44c28872006-01-03 09:55:06 +0100268static int rpc_wait_bit_interruptible(void *word)
269{
270 if (signal_pending(current))
271 return -ERESTARTSYS;
272 schedule();
273 return 0;
274}
275
276/*
277 * Mark an RPC call as having completed by clearing the 'active' bit
278 */
279static inline void rpc_mark_complete_task(struct rpc_task *task)
280{
281 rpc_clear_active(task);
282 wake_up_bit(&task->tk_runstate, RPC_TASK_ACTIVE);
283}
284
285/*
286 * Allow callers to wait for completion of an RPC call
287 */
288int __rpc_wait_for_completion_task(struct rpc_task *task, int (*action)(void *))
289{
290 if (action == NULL)
291 action = rpc_wait_bit_interruptible;
292 return wait_on_bit(&task->tk_runstate, RPC_TASK_ACTIVE,
293 action, TASK_INTERRUPTIBLE);
294}
295EXPORT_SYMBOL(__rpc_wait_for_completion_task);
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297/*
298 * Make an RPC task runnable.
299 *
300 * Note: If the task is ASYNC, this must be called with
301 * the spinlock held to protect the wait queue operation.
302 */
303static void rpc_make_runnable(struct rpc_task *task)
304{
305 int do_ret;
306
307 BUG_ON(task->tk_timeout_fn);
308 do_ret = rpc_test_and_set_running(task);
309 rpc_clear_queued(task);
310 if (do_ret)
311 return;
312 if (RPC_IS_ASYNC(task)) {
313 int status;
314
315 INIT_WORK(&task->u.tk_work, rpc_async_schedule, (void *)task);
316 status = queue_work(task->tk_workqueue, &task->u.tk_work);
317 if (status < 0) {
318 printk(KERN_WARNING "RPC: failed to add task to queue: error: %d!\n", status);
319 task->tk_status = status;
320 return;
321 }
322 } else
Trond Myklebust96651ab2005-06-22 17:16:21 +0000323 wake_up_bit(&task->tk_runstate, RPC_TASK_QUEUED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324}
325
326/*
327 * Place a newly initialized task on the workqueue.
328 */
329static inline void
330rpc_schedule_run(struct rpc_task *task)
331{
Trond Myklebust44c28872006-01-03 09:55:06 +0100332 rpc_set_active(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 rpc_make_runnable(task);
334}
335
336/*
337 * Prepare for sleeping on a wait queue.
338 * By always appending tasks to the list we ensure FIFO behavior.
339 * NB: An RPC task will only receive interrupt-driven events as long
340 * as it's on a wait queue.
341 */
342static void __rpc_sleep_on(struct rpc_wait_queue *q, struct rpc_task *task,
343 rpc_action action, rpc_action timer)
344{
345 dprintk("RPC: %4d sleep_on(queue \"%s\" time %ld)\n", task->tk_pid,
346 rpc_qname(q), jiffies);
347
348 if (!RPC_IS_ASYNC(task) && !RPC_IS_ACTIVATED(task)) {
349 printk(KERN_ERR "RPC: Inactive synchronous task put to sleep!\n");
350 return;
351 }
352
353 /* Mark the task as being activated if so needed */
Trond Myklebust44c28872006-01-03 09:55:06 +0100354 rpc_set_active(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 __rpc_add_wait_queue(q, task);
357
358 BUG_ON(task->tk_callback != NULL);
359 task->tk_callback = action;
360 __rpc_add_timer(task, timer);
361}
362
363void rpc_sleep_on(struct rpc_wait_queue *q, struct rpc_task *task,
364 rpc_action action, rpc_action timer)
365{
366 /*
367 * Protect the queue operations.
368 */
369 spin_lock_bh(&q->lock);
370 __rpc_sleep_on(q, task, action, timer);
371 spin_unlock_bh(&q->lock);
372}
373
374/**
375 * __rpc_do_wake_up_task - wake up a single rpc_task
376 * @task: task to be woken up
377 *
378 * Caller must hold queue->lock, and have cleared the task queued flag.
379 */
380static void __rpc_do_wake_up_task(struct rpc_task *task)
381{
382 dprintk("RPC: %4d __rpc_wake_up_task (now %ld)\n", task->tk_pid, jiffies);
383
384#ifdef RPC_DEBUG
385 BUG_ON(task->tk_magic != RPC_TASK_MAGIC_ID);
386#endif
387 /* Has the task been executed yet? If not, we cannot wake it up! */
388 if (!RPC_IS_ACTIVATED(task)) {
389 printk(KERN_ERR "RPC: Inactive task (%p) being woken up!\n", task);
390 return;
391 }
392
393 __rpc_disable_timer(task);
394 __rpc_remove_wait_queue(task);
395
396 rpc_make_runnable(task);
397
398 dprintk("RPC: __rpc_wake_up_task done\n");
399}
400
401/*
402 * Wake up the specified task
403 */
404static void __rpc_wake_up_task(struct rpc_task *task)
405{
406 if (rpc_start_wakeup(task)) {
407 if (RPC_IS_QUEUED(task))
408 __rpc_do_wake_up_task(task);
409 rpc_finish_wakeup(task);
410 }
411}
412
413/*
414 * Default timeout handler if none specified by user
415 */
416static void
417__rpc_default_timer(struct rpc_task *task)
418{
419 dprintk("RPC: %d timeout (default timer)\n", task->tk_pid);
420 task->tk_status = -ETIMEDOUT;
421 rpc_wake_up_task(task);
422}
423
424/*
425 * Wake up the specified task
426 */
427void rpc_wake_up_task(struct rpc_task *task)
428{
429 if (rpc_start_wakeup(task)) {
430 if (RPC_IS_QUEUED(task)) {
431 struct rpc_wait_queue *queue = task->u.tk_wait.rpc_waitq;
432
433 spin_lock_bh(&queue->lock);
434 __rpc_do_wake_up_task(task);
435 spin_unlock_bh(&queue->lock);
436 }
437 rpc_finish_wakeup(task);
438 }
439}
440
441/*
442 * Wake up the next task on a priority queue.
443 */
444static struct rpc_task * __rpc_wake_up_next_priority(struct rpc_wait_queue *queue)
445{
446 struct list_head *q;
447 struct rpc_task *task;
448
449 /*
450 * Service a batch of tasks from a single cookie.
451 */
452 q = &queue->tasks[queue->priority];
453 if (!list_empty(q)) {
454 task = list_entry(q->next, struct rpc_task, u.tk_wait.list);
455 if (queue->cookie == task->tk_cookie) {
456 if (--queue->nr)
457 goto out;
458 list_move_tail(&task->u.tk_wait.list, q);
459 }
460 /*
461 * Check if we need to switch queues.
462 */
463 if (--queue->count)
464 goto new_cookie;
465 }
466
467 /*
468 * Service the next queue.
469 */
470 do {
471 if (q == &queue->tasks[0])
472 q = &queue->tasks[queue->maxpriority];
473 else
474 q = q - 1;
475 if (!list_empty(q)) {
476 task = list_entry(q->next, struct rpc_task, u.tk_wait.list);
477 goto new_queue;
478 }
479 } while (q != &queue->tasks[queue->priority]);
480
481 rpc_reset_waitqueue_priority(queue);
482 return NULL;
483
484new_queue:
485 rpc_set_waitqueue_priority(queue, (unsigned int)(q - &queue->tasks[0]));
486new_cookie:
487 rpc_set_waitqueue_cookie(queue, task->tk_cookie);
488out:
489 __rpc_wake_up_task(task);
490 return task;
491}
492
493/*
494 * Wake up the next task on the wait queue.
495 */
496struct rpc_task * rpc_wake_up_next(struct rpc_wait_queue *queue)
497{
498 struct rpc_task *task = NULL;
499
500 dprintk("RPC: wake_up_next(%p \"%s\")\n", queue, rpc_qname(queue));
501 spin_lock_bh(&queue->lock);
502 if (RPC_IS_PRIORITY(queue))
503 task = __rpc_wake_up_next_priority(queue);
504 else {
505 task_for_first(task, &queue->tasks[0])
506 __rpc_wake_up_task(task);
507 }
508 spin_unlock_bh(&queue->lock);
509
510 return task;
511}
512
513/**
514 * rpc_wake_up - wake up all rpc_tasks
515 * @queue: rpc_wait_queue on which the tasks are sleeping
516 *
517 * Grabs queue->lock
518 */
519void rpc_wake_up(struct rpc_wait_queue *queue)
520{
Trond Myklebuste6d83d52006-03-13 21:20:48 -0800521 struct rpc_task *task, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 struct list_head *head;
Trond Myklebuste6d83d52006-03-13 21:20:48 -0800523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 spin_lock_bh(&queue->lock);
525 head = &queue->tasks[queue->maxpriority];
526 for (;;) {
Trond Myklebuste6d83d52006-03-13 21:20:48 -0800527 list_for_each_entry_safe(task, next, head, u.tk_wait.list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 __rpc_wake_up_task(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 if (head == &queue->tasks[0])
530 break;
531 head--;
532 }
533 spin_unlock_bh(&queue->lock);
534}
535
536/**
537 * rpc_wake_up_status - wake up all rpc_tasks and set their status value.
538 * @queue: rpc_wait_queue on which the tasks are sleeping
539 * @status: status value to set
540 *
541 * Grabs queue->lock
542 */
543void rpc_wake_up_status(struct rpc_wait_queue *queue, int status)
544{
Trond Myklebuste6d83d52006-03-13 21:20:48 -0800545 struct rpc_task *task, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 struct list_head *head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 spin_lock_bh(&queue->lock);
549 head = &queue->tasks[queue->maxpriority];
550 for (;;) {
Trond Myklebuste6d83d52006-03-13 21:20:48 -0800551 list_for_each_entry_safe(task, next, head, u.tk_wait.list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 task->tk_status = status;
553 __rpc_wake_up_task(task);
554 }
555 if (head == &queue->tasks[0])
556 break;
557 head--;
558 }
559 spin_unlock_bh(&queue->lock);
560}
561
562/*
563 * Run a task at a later time
564 */
565static void __rpc_atrun(struct rpc_task *);
566void
567rpc_delay(struct rpc_task *task, unsigned long delay)
568{
569 task->tk_timeout = delay;
570 rpc_sleep_on(&delay_queue, task, NULL, __rpc_atrun);
571}
572
573static void
574__rpc_atrun(struct rpc_task *task)
575{
576 task->tk_status = 0;
577 rpc_wake_up_task(task);
578}
579
580/*
Trond Myklebust4ce70ad2006-01-03 09:55:05 +0100581 * Helper to call task->tk_ops->rpc_call_prepare
582 */
583static void rpc_prepare_task(struct rpc_task *task)
584{
585 task->tk_ops->rpc_call_prepare(task, task->tk_calldata);
586}
587
588/*
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100589 * Helper that calls task->tk_ops->rpc_call_done if it exists
Trond Myklebustd05fdb02005-06-22 17:16:19 +0000590 */
Trond Myklebustabbcf282006-01-03 09:55:03 +0100591void rpc_exit_task(struct rpc_task *task)
Trond Myklebustd05fdb02005-06-22 17:16:19 +0000592{
Trond Myklebustabbcf282006-01-03 09:55:03 +0100593 task->tk_action = NULL;
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100594 if (task->tk_ops->rpc_call_done != NULL) {
595 task->tk_ops->rpc_call_done(task, task->tk_calldata);
Trond Myklebustd05fdb02005-06-22 17:16:19 +0000596 if (task->tk_action != NULL) {
Trond Myklebustabbcf282006-01-03 09:55:03 +0100597 WARN_ON(RPC_ASSASSINATED(task));
598 /* Always release the RPC slot and buffer memory */
599 xprt_release(task);
Trond Myklebustd05fdb02005-06-22 17:16:19 +0000600 }
601 }
Trond Myklebustd05fdb02005-06-22 17:16:19 +0000602}
Trond Myklebustabbcf282006-01-03 09:55:03 +0100603EXPORT_SYMBOL(rpc_exit_task);
Trond Myklebustd05fdb02005-06-22 17:16:19 +0000604
605/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 * This is the RPC `scheduler' (or rather, the finite state machine).
607 */
608static int __rpc_execute(struct rpc_task *task)
609{
610 int status = 0;
611
612 dprintk("RPC: %4d rpc_execute flgs %x\n",
613 task->tk_pid, task->tk_flags);
614
615 BUG_ON(RPC_IS_QUEUED(task));
616
Trond Myklebustd05fdb02005-06-22 17:16:19 +0000617 for (;;) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 /*
619 * Garbage collection of pending timers...
620 */
621 rpc_delete_timer(task);
622
623 /*
624 * Execute any pending callback.
625 */
626 if (RPC_DO_CALLBACK(task)) {
627 /* Define a callback save pointer */
628 void (*save_callback)(struct rpc_task *);
629
630 /*
631 * If a callback exists, save it, reset it,
632 * call it.
633 * The save is needed to stop from resetting
634 * another callback set within the callback handler
635 * - Dave
636 */
637 save_callback=task->tk_callback;
638 task->tk_callback=NULL;
639 lock_kernel();
640 save_callback(task);
641 unlock_kernel();
642 }
643
644 /*
645 * Perform the next FSM step.
646 * tk_action may be NULL when the task has been killed
647 * by someone else.
648 */
649 if (!RPC_IS_QUEUED(task)) {
Trond Myklebustabbcf282006-01-03 09:55:03 +0100650 if (task->tk_action == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 break;
Trond Myklebustabbcf282006-01-03 09:55:03 +0100652 lock_kernel();
653 task->tk_action(task);
654 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 }
656
657 /*
658 * Lockless check for whether task is sleeping or not.
659 */
660 if (!RPC_IS_QUEUED(task))
661 continue;
662 rpc_clear_running(task);
663 if (RPC_IS_ASYNC(task)) {
664 /* Careful! we may have raced... */
665 if (RPC_IS_QUEUED(task))
666 return 0;
667 if (rpc_test_and_set_running(task))
668 return 0;
669 continue;
670 }
671
672 /* sync task: sleep here */
673 dprintk("RPC: %4d sync task going to sleep\n", task->tk_pid);
Trond Myklebust96651ab2005-06-22 17:16:21 +0000674 /* Note: Caller should be using rpc_clnt_sigmask() */
675 status = out_of_line_wait_on_bit(&task->tk_runstate,
676 RPC_TASK_QUEUED, rpc_wait_bit_interruptible,
677 TASK_INTERRUPTIBLE);
678 if (status == -ERESTARTSYS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 /*
680 * When a sync task receives a signal, it exits with
681 * -ERESTARTSYS. In order to catch any callbacks that
682 * clean up after sleeping on some queue, we don't
683 * break the loop here, but go around once more.
684 */
Trond Myklebust96651ab2005-06-22 17:16:21 +0000685 dprintk("RPC: %4d got signal\n", task->tk_pid);
686 task->tk_flags |= RPC_TASK_KILLED;
687 rpc_exit(task, -ERESTARTSYS);
688 rpc_wake_up_task(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
690 rpc_set_running(task);
691 dprintk("RPC: %4d sync task resuming\n", task->tk_pid);
692 }
693
Trond Myklebuste60859a2006-01-03 09:55:10 +0100694 dprintk("RPC: %4d, return %d, status %d\n", task->tk_pid, status, task->tk_status);
Trond Myklebust44c28872006-01-03 09:55:06 +0100695 /* Wake up anyone who is waiting for task completion */
696 rpc_mark_complete_task(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 /* Release all resources associated with the task */
698 rpc_release_task(task);
699 return status;
700}
701
702/*
703 * User-visible entry point to the scheduler.
704 *
705 * This may be called recursively if e.g. an async NFS task updates
706 * the attributes and finds that dirty pages must be flushed.
707 * NOTE: Upon exit of this function the task is guaranteed to be
708 * released. In particular note that tk_release() will have
709 * been called, so your task memory may have been freed.
710 */
711int
712rpc_execute(struct rpc_task *task)
713{
Trond Myklebust44c28872006-01-03 09:55:06 +0100714 rpc_set_active(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 rpc_set_running(task);
716 return __rpc_execute(task);
717}
718
719static void rpc_async_schedule(void *arg)
720{
721 __rpc_execute((struct rpc_task *)arg);
722}
723
Chuck Lever02107142006-01-03 09:55:49 +0100724/**
725 * rpc_malloc - allocate an RPC buffer
726 * @task: RPC task that will use this buffer
727 * @size: requested byte size
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 *
729 * We try to ensure that some NFS reads and writes can always proceed
730 * by using a mempool when allocating 'small' buffers.
731 * In order to avoid memory starvation triggering more writebacks of
732 * NFS requests, we use GFP_NOFS rather than GFP_KERNEL.
733 */
Chuck Lever02107142006-01-03 09:55:49 +0100734void * rpc_malloc(struct rpc_task *task, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735{
Chuck Lever02107142006-01-03 09:55:49 +0100736 struct rpc_rqst *req = task->tk_rqstp;
Al Virodd0fc662005-10-07 07:46:04 +0100737 gfp_t gfp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739 if (task->tk_flags & RPC_TASK_SWAPPER)
740 gfp = GFP_ATOMIC;
741 else
742 gfp = GFP_NOFS;
743
744 if (size > RPC_BUFFER_MAXSIZE) {
Chuck Lever02107142006-01-03 09:55:49 +0100745 req->rq_buffer = kmalloc(size, gfp);
746 if (req->rq_buffer)
747 req->rq_bufsize = size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 } else {
Chuck Lever02107142006-01-03 09:55:49 +0100749 req->rq_buffer = mempool_alloc(rpc_buffer_mempool, gfp);
750 if (req->rq_buffer)
751 req->rq_bufsize = RPC_BUFFER_MAXSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 }
Chuck Lever02107142006-01-03 09:55:49 +0100753 return req->rq_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754}
755
Chuck Lever02107142006-01-03 09:55:49 +0100756/**
757 * rpc_free - free buffer allocated via rpc_malloc
758 * @task: RPC task with a buffer to be freed
759 *
760 */
761void rpc_free(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762{
Chuck Lever02107142006-01-03 09:55:49 +0100763 struct rpc_rqst *req = task->tk_rqstp;
764
765 if (req->rq_buffer) {
766 if (req->rq_bufsize == RPC_BUFFER_MAXSIZE)
767 mempool_free(req->rq_buffer, rpc_buffer_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 else
Chuck Lever02107142006-01-03 09:55:49 +0100769 kfree(req->rq_buffer);
770 req->rq_buffer = NULL;
771 req->rq_bufsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 }
773}
774
775/*
776 * Creation and deletion of RPC task structures
777 */
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100778void rpc_init_task(struct rpc_task *task, struct rpc_clnt *clnt, int flags, const struct rpc_call_ops *tk_ops, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
780 memset(task, 0, sizeof(*task));
781 init_timer(&task->tk_timer);
782 task->tk_timer.data = (unsigned long) task;
783 task->tk_timer.function = (void (*)(unsigned long)) rpc_run_timer;
Trond Myklebust44c28872006-01-03 09:55:06 +0100784 atomic_set(&task->tk_count, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 task->tk_client = clnt;
786 task->tk_flags = flags;
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100787 task->tk_ops = tk_ops;
Trond Myklebust4ce70ad2006-01-03 09:55:05 +0100788 if (tk_ops->rpc_call_prepare != NULL)
789 task->tk_action = rpc_prepare_task;
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100790 task->tk_calldata = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
792 /* Initialize retry counters */
793 task->tk_garb_retry = 2;
794 task->tk_cred_retry = 2;
795
796 task->tk_priority = RPC_PRIORITY_NORMAL;
797 task->tk_cookie = (unsigned long)current;
798
799 /* Initialize workqueue for async tasks */
800 task->tk_workqueue = rpciod_workqueue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 if (clnt) {
803 atomic_inc(&clnt->cl_users);
804 if (clnt->cl_softrtry)
805 task->tk_flags |= RPC_TASK_SOFT;
806 if (!clnt->cl_intr)
807 task->tk_flags |= RPC_TASK_NOINTR;
808 }
809
810#ifdef RPC_DEBUG
811 task->tk_magic = RPC_TASK_MAGIC_ID;
812 task->tk_pid = rpc_task_id++;
813#endif
814 /* Add to global list of all tasks */
815 spin_lock(&rpc_sched_lock);
816 list_add_tail(&task->tk_task, &all_tasks);
817 spin_unlock(&rpc_sched_lock);
818
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100819 BUG_ON(task->tk_ops == NULL);
820
Chuck Leveref759a22006-03-20 13:44:17 -0500821 /* starting timestamp */
822 task->tk_start = jiffies;
823
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 dprintk("RPC: %4d new task procpid %d\n", task->tk_pid,
825 current->pid);
826}
827
828static struct rpc_task *
829rpc_alloc_task(void)
830{
831 return (struct rpc_task *)mempool_alloc(rpc_task_mempool, GFP_NOFS);
832}
833
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100834static void rpc_free_task(struct rpc_task *task)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835{
836 dprintk("RPC: %4d freeing task\n", task->tk_pid);
837 mempool_free(task, rpc_task_mempool);
838}
839
840/*
841 * Create a new task for the specified client. We have to
842 * clean up after an allocation failure, as the client may
843 * have specified "oneshot".
844 */
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100845struct rpc_task *rpc_new_task(struct rpc_clnt *clnt, int flags, const struct rpc_call_ops *tk_ops, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846{
847 struct rpc_task *task;
848
849 task = rpc_alloc_task();
850 if (!task)
851 goto cleanup;
852
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100853 rpc_init_task(task, clnt, flags, tk_ops, calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
855 dprintk("RPC: %4d allocated task\n", task->tk_pid);
856 task->tk_flags |= RPC_TASK_DYNAMIC;
857out:
858 return task;
859
860cleanup:
861 /* Check whether to release the client */
862 if (clnt) {
863 printk("rpc_new_task: failed, users=%d, oneshot=%d\n",
864 atomic_read(&clnt->cl_users), clnt->cl_oneshot);
865 atomic_inc(&clnt->cl_users); /* pretend we were used ... */
866 rpc_release_client(clnt);
867 }
868 goto out;
869}
870
871void rpc_release_task(struct rpc_task *task)
872{
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100873 const struct rpc_call_ops *tk_ops = task->tk_ops;
874 void *calldata = task->tk_calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
876#ifdef RPC_DEBUG
877 BUG_ON(task->tk_magic != RPC_TASK_MAGIC_ID);
878#endif
Trond Myklebust44c28872006-01-03 09:55:06 +0100879 if (!atomic_dec_and_test(&task->tk_count))
880 return;
881 dprintk("RPC: %4d release task\n", task->tk_pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883 /* Remove from global task list */
884 spin_lock(&rpc_sched_lock);
885 list_del(&task->tk_task);
886 spin_unlock(&rpc_sched_lock);
887
888 BUG_ON (RPC_IS_QUEUED(task));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890 /* Synchronously delete any running timer */
891 rpc_delete_timer(task);
892
893 /* Release resources */
894 if (task->tk_rqstp)
895 xprt_release(task);
896 if (task->tk_msg.rpc_cred)
897 rpcauth_unbindcred(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 if (task->tk_client) {
899 rpc_release_client(task->tk_client);
900 task->tk_client = NULL;
901 }
902
903#ifdef RPC_DEBUG
904 task->tk_magic = 0;
905#endif
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100906 if (task->tk_flags & RPC_TASK_DYNAMIC)
907 rpc_free_task(task);
908 if (tk_ops->rpc_release)
909 tk_ops->rpc_release(calldata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910}
911
912/**
Trond Myklebust44c28872006-01-03 09:55:06 +0100913 * rpc_run_task - Allocate a new RPC task, then run rpc_execute against it
Martin Waitz99acf042006-02-01 03:06:56 -0800914 * @clnt: pointer to RPC client
915 * @flags: RPC flags
916 * @ops: RPC call ops
917 * @data: user call data
Trond Myklebust44c28872006-01-03 09:55:06 +0100918 */
919struct rpc_task *rpc_run_task(struct rpc_clnt *clnt, int flags,
920 const struct rpc_call_ops *ops,
921 void *data)
922{
923 struct rpc_task *task;
924 task = rpc_new_task(clnt, flags, ops, data);
Trond Myklebust7a1218a2006-03-20 18:11:10 -0500925 if (task == NULL) {
926 if (ops->rpc_release != NULL)
927 ops->rpc_release(data);
Trond Myklebust44c28872006-01-03 09:55:06 +0100928 return ERR_PTR(-ENOMEM);
Trond Myklebust7a1218a2006-03-20 18:11:10 -0500929 }
Trond Myklebust44c28872006-01-03 09:55:06 +0100930 atomic_inc(&task->tk_count);
931 rpc_execute(task);
932 return task;
933}
934EXPORT_SYMBOL(rpc_run_task);
935
936/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 * rpc_find_parent - find the parent of a child task.
938 * @child: child task
Martin Waitz99acf042006-02-01 03:06:56 -0800939 * @parent: parent task
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 *
941 * Checks that the parent task is still sleeping on the
942 * queue 'childq'. If so returns a pointer to the parent.
943 * Upon failure returns NULL.
944 *
945 * Caller must hold childq.lock
946 */
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100947static inline struct rpc_task *rpc_find_parent(struct rpc_task *child, struct rpc_task *parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948{
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100949 struct rpc_task *task;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 struct list_head *le;
951
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 task_for_each(task, le, &childq.tasks[0])
953 if (task == parent)
954 return parent;
955
956 return NULL;
957}
958
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100959static void rpc_child_exit(struct rpc_task *child, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960{
961 struct rpc_task *parent;
962
963 spin_lock_bh(&childq.lock);
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100964 if ((parent = rpc_find_parent(child, calldata)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 parent->tk_status = child->tk_status;
966 __rpc_wake_up_task(parent);
967 }
968 spin_unlock_bh(&childq.lock);
969}
970
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100971static const struct rpc_call_ops rpc_child_ops = {
972 .rpc_call_done = rpc_child_exit,
973};
974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975/*
976 * Note: rpc_new_task releases the client after a failure.
977 */
978struct rpc_task *
979rpc_new_child(struct rpc_clnt *clnt, struct rpc_task *parent)
980{
981 struct rpc_task *task;
982
Trond Myklebust963d8fe2006-01-03 09:55:04 +0100983 task = rpc_new_task(clnt, RPC_TASK_ASYNC | RPC_TASK_CHILD, &rpc_child_ops, parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 if (!task)
985 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 return task;
987
988fail:
989 parent->tk_status = -ENOMEM;
990 return NULL;
991}
992
993void rpc_run_child(struct rpc_task *task, struct rpc_task *child, rpc_action func)
994{
995 spin_lock_bh(&childq.lock);
996 /* N.B. Is it possible for the child to have already finished? */
997 __rpc_sleep_on(&childq, task, func, NULL);
998 rpc_schedule_run(child);
999 spin_unlock_bh(&childq.lock);
1000}
1001
1002/*
1003 * Kill all tasks for the given client.
1004 * XXX: kill their descendants as well?
1005 */
1006void rpc_killall_tasks(struct rpc_clnt *clnt)
1007{
1008 struct rpc_task *rovr;
1009 struct list_head *le;
1010
1011 dprintk("RPC: killing all tasks for client %p\n", clnt);
1012
1013 /*
1014 * Spin lock all_tasks to prevent changes...
1015 */
1016 spin_lock(&rpc_sched_lock);
1017 alltask_for_each(rovr, le, &all_tasks) {
1018 if (! RPC_IS_ACTIVATED(rovr))
1019 continue;
1020 if (!clnt || rovr->tk_client == clnt) {
1021 rovr->tk_flags |= RPC_TASK_KILLED;
1022 rpc_exit(rovr, -EIO);
1023 rpc_wake_up_task(rovr);
1024 }
1025 }
1026 spin_unlock(&rpc_sched_lock);
1027}
1028
1029static DECLARE_MUTEX_LOCKED(rpciod_running);
1030
1031static void rpciod_killall(void)
1032{
1033 unsigned long flags;
1034
1035 while (!list_empty(&all_tasks)) {
1036 clear_thread_flag(TIF_SIGPENDING);
1037 rpc_killall_tasks(NULL);
1038 flush_workqueue(rpciod_workqueue);
1039 if (!list_empty(&all_tasks)) {
1040 dprintk("rpciod_killall: waiting for tasks to exit\n");
1041 yield();
1042 }
1043 }
1044
1045 spin_lock_irqsave(&current->sighand->siglock, flags);
1046 recalc_sigpending();
1047 spin_unlock_irqrestore(&current->sighand->siglock, flags);
1048}
1049
1050/*
1051 * Start up the rpciod process if it's not already running.
1052 */
1053int
1054rpciod_up(void)
1055{
1056 struct workqueue_struct *wq;
1057 int error = 0;
1058
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -08001059 mutex_lock(&rpciod_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 dprintk("rpciod_up: users %d\n", rpciod_users);
1061 rpciod_users++;
1062 if (rpciod_workqueue)
1063 goto out;
1064 /*
1065 * If there's no pid, we should be the first user.
1066 */
1067 if (rpciod_users > 1)
1068 printk(KERN_WARNING "rpciod_up: no workqueue, %d users??\n", rpciod_users);
1069 /*
1070 * Create the rpciod thread and wait for it to start.
1071 */
1072 error = -ENOMEM;
1073 wq = create_workqueue("rpciod");
1074 if (wq == NULL) {
1075 printk(KERN_WARNING "rpciod_up: create workqueue failed, error=%d\n", error);
1076 rpciod_users--;
1077 goto out;
1078 }
1079 rpciod_workqueue = wq;
1080 error = 0;
1081out:
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -08001082 mutex_unlock(&rpciod_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 return error;
1084}
1085
1086void
1087rpciod_down(void)
1088{
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -08001089 mutex_lock(&rpciod_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 dprintk("rpciod_down sema %d\n", rpciod_users);
1091 if (rpciod_users) {
1092 if (--rpciod_users)
1093 goto out;
1094 } else
1095 printk(KERN_WARNING "rpciod_down: no users??\n");
1096
1097 if (!rpciod_workqueue) {
1098 dprintk("rpciod_down: Nothing to do!\n");
1099 goto out;
1100 }
1101 rpciod_killall();
1102
1103 destroy_workqueue(rpciod_workqueue);
1104 rpciod_workqueue = NULL;
1105 out:
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -08001106 mutex_unlock(&rpciod_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107}
1108
1109#ifdef RPC_DEBUG
1110void rpc_show_tasks(void)
1111{
1112 struct list_head *le;
1113 struct rpc_task *t;
1114
1115 spin_lock(&rpc_sched_lock);
1116 if (list_empty(&all_tasks)) {
1117 spin_unlock(&rpc_sched_lock);
1118 return;
1119 }
1120 printk("-pid- proc flgs status -client- -prog- --rqstp- -timeout "
Trond Myklebust963d8fe2006-01-03 09:55:04 +01001121 "-rpcwait -action- ---ops--\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 alltask_for_each(t, le, &all_tasks) {
1123 const char *rpc_waitq = "none";
1124
1125 if (RPC_IS_QUEUED(t))
1126 rpc_waitq = rpc_qname(t->u.tk_wait.rpc_waitq);
1127
1128 printk("%05d %04d %04x %06d %8p %6d %8p %08ld %8s %8p %8p\n",
1129 t->tk_pid,
1130 (t->tk_msg.rpc_proc ? t->tk_msg.rpc_proc->p_proc : -1),
1131 t->tk_flags, t->tk_status,
1132 t->tk_client,
1133 (t->tk_client ? t->tk_client->cl_prog : 0),
1134 t->tk_rqstp, t->tk_timeout,
1135 rpc_waitq,
Trond Myklebust963d8fe2006-01-03 09:55:04 +01001136 t->tk_action, t->tk_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 }
1138 spin_unlock(&rpc_sched_lock);
1139}
1140#endif
1141
1142void
1143rpc_destroy_mempool(void)
1144{
1145 if (rpc_buffer_mempool)
1146 mempool_destroy(rpc_buffer_mempool);
1147 if (rpc_task_mempool)
1148 mempool_destroy(rpc_task_mempool);
1149 if (rpc_task_slabp && kmem_cache_destroy(rpc_task_slabp))
1150 printk(KERN_INFO "rpc_task: not all structures were freed\n");
1151 if (rpc_buffer_slabp && kmem_cache_destroy(rpc_buffer_slabp))
1152 printk(KERN_INFO "rpc_buffers: not all structures were freed\n");
1153}
1154
1155int
1156rpc_init_mempool(void)
1157{
1158 rpc_task_slabp = kmem_cache_create("rpc_tasks",
1159 sizeof(struct rpc_task),
1160 0, SLAB_HWCACHE_ALIGN,
1161 NULL, NULL);
1162 if (!rpc_task_slabp)
1163 goto err_nomem;
1164 rpc_buffer_slabp = kmem_cache_create("rpc_buffers",
1165 RPC_BUFFER_MAXSIZE,
1166 0, SLAB_HWCACHE_ALIGN,
1167 NULL, NULL);
1168 if (!rpc_buffer_slabp)
1169 goto err_nomem;
Matthew Dobson93d23412006-03-26 01:37:50 -08001170 rpc_task_mempool = mempool_create_slab_pool(RPC_TASK_POOLSIZE,
1171 rpc_task_slabp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 if (!rpc_task_mempool)
1173 goto err_nomem;
Matthew Dobson93d23412006-03-26 01:37:50 -08001174 rpc_buffer_mempool = mempool_create_slab_pool(RPC_BUFFER_POOLSIZE,
1175 rpc_buffer_slabp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 if (!rpc_buffer_mempool)
1177 goto err_nomem;
1178 return 0;
1179err_nomem:
1180 rpc_destroy_mempool();
1181 return -ENOMEM;
1182}