]> err.no Git - linux-2.6/blobdiff - net/sunrpc/sched.c
[IPV6]: Fix kernel panic while send SCTP data with IP fragments
[linux-2.6] / net / sunrpc / sched.c
index d95fe4e40eb468de464cd198d9abc7ef785b9533..954d7ec86c7e201be80f0e19c41f3597125059e8 100644 (file)
@@ -39,7 +39,6 @@ static mempool_t      *rpc_task_mempool __read_mostly;
 static mempool_t       *rpc_buffer_mempool __read_mostly;
 
 static void                    __rpc_default_timer(struct rpc_task *task);
-static void                    rpciod_killall(void);
 static void                    rpc_async_schedule(struct work_struct *);
 static void                     rpc_release_task(struct rpc_task *task);
 
@@ -48,24 +47,11 @@ static void                  rpc_release_task(struct rpc_task *task);
  */
 static RPC_WAITQ(delay_queue, "delayq");
 
-/*
- * All RPC clients are linked into this list
- */
-static LIST_HEAD(all_clients);
-static DECLARE_WAIT_QUEUE_HEAD(client_kill_wait);
-
 /*
  * rpciod-related stuff
  */
-static DEFINE_MUTEX(rpciod_mutex);
-static unsigned int            rpciod_users;
 struct workqueue_struct *rpciod_workqueue;
 
-/*
- * Spinlock for other critical sections of code.
- */
-static DEFINE_SPINLOCK(rpc_sched_lock);
-
 /*
  * Disable the timer for a given RPC task. Should be called with
  * queue->lock and bh_disabled in order to avoid races within
@@ -945,29 +931,6 @@ static void rpc_release_task(struct rpc_task *task)
        rpc_put_task(task);
 }
 
-/**
- * rpc_run_task - Allocate a new RPC task, then run rpc_execute against it
- * @clnt: pointer to RPC client
- * @flags: RPC flags
- * @ops: RPC call ops
- * @data: user call data
- */
-struct rpc_task *rpc_run_task(struct rpc_clnt *clnt, int flags,
-                                       const struct rpc_call_ops *ops,
-                                       void *data)
-{
-       struct rpc_task *task;
-       task = rpc_new_task(clnt, flags, ops, data);
-       if (task == NULL) {
-               rpc_release_calldata(ops, data);
-               return ERR_PTR(-ENOMEM);
-       }
-       atomic_inc(&task->tk_count);
-       rpc_execute(task);
-       return task;
-}
-EXPORT_SYMBOL(rpc_run_task);
-
 /*
  * Kill all tasks for the given client.
  * XXX: kill their descendants as well?
@@ -996,148 +959,49 @@ void rpc_killall_tasks(struct rpc_clnt *clnt)
        spin_unlock(&clnt->cl_lock);
 }
 
-static void rpciod_killall(void)
+int rpciod_up(void)
 {
-       struct rpc_clnt *clnt;
-       unsigned long flags;
-
-       for(;;) {
-               clear_thread_flag(TIF_SIGPENDING);
-
-               spin_lock(&rpc_sched_lock);
-               list_for_each_entry(clnt, &all_clients, cl_clients)
-                       rpc_killall_tasks(clnt);
-               spin_unlock(&rpc_sched_lock);
-               flush_workqueue(rpciod_workqueue);
-               if (!list_empty(&all_clients))
-                       break;
-               dprintk("RPC:       rpciod_killall: waiting for tasks "
-                                       "to exit\n");
-               wait_event_timeout(client_kill_wait,
-                               list_empty(&all_clients), 1*HZ);
-       }
-
-       spin_lock_irqsave(&current->sighand->siglock, flags);
-       recalc_sigpending();
-       spin_unlock_irqrestore(&current->sighand->siglock, flags);
+       return try_module_get(THIS_MODULE) ? 0 : -EINVAL;
 }
 
-void rpc_register_client(struct rpc_clnt *clnt)
+void rpciod_down(void)
 {
-       spin_lock(&rpc_sched_lock);
-       list_add(&clnt->cl_clients, &all_clients);
-       spin_unlock(&rpc_sched_lock);
-}
-
-void rpc_unregister_client(struct rpc_clnt *clnt)
-{
-       spin_lock(&rpc_sched_lock);
-       list_del(&clnt->cl_clients);
-       if (list_empty(&all_clients))
-               wake_up(&client_kill_wait);
-       spin_unlock(&rpc_sched_lock);
+       module_put(THIS_MODULE);
 }
 
 /*
- * Start up the rpciod process if it's not already running.
+ * Start up the rpciod workqueue.
  */
-int
-rpciod_up(void)
+static int rpciod_start(void)
 {
        struct workqueue_struct *wq;
-       int error = 0;
 
-       mutex_lock(&rpciod_mutex);
-       dprintk("RPC:       rpciod_up: users %u\n", rpciod_users);
-       rpciod_users++;
-       if (rpciod_workqueue)
-               goto out;
-       /*
-        * If there's no pid, we should be the first user.
-        */
-       if (rpciod_users > 1)
-               printk(KERN_WARNING "rpciod_up: no workqueue, %u users??\n", rpciod_users);
        /*
         * Create the rpciod thread and wait for it to start.
         */
-       error = -ENOMEM;
+       dprintk("RPC:       creating workqueue rpciod\n");
        wq = create_workqueue("rpciod");
-       if (wq == NULL) {
-               printk(KERN_WARNING "rpciod_up: create workqueue failed, error=%d\n", error);
-               rpciod_users--;
-               goto out;
-       }
        rpciod_workqueue = wq;
-       error = 0;
-out:
-       mutex_unlock(&rpciod_mutex);
-       return error;
+       return rpciod_workqueue != NULL;
 }
 
-void
-rpciod_down(void)
+static void rpciod_stop(void)
 {
-       mutex_lock(&rpciod_mutex);
-       dprintk("RPC:       rpciod_down sema %u\n", rpciod_users);
-       if (rpciod_users) {
-               if (--rpciod_users)
-                       goto out;
-       } else
-               printk(KERN_WARNING "rpciod_down: no users??\n");
+       struct workqueue_struct *wq = NULL;
 
-       if (!rpciod_workqueue) {
-               dprintk("RPC:       rpciod_down: Nothing to do!\n");
-               goto out;
-       }
-       rpciod_killall();
+       if (rpciod_workqueue == NULL)
+               return;
+       dprintk("RPC:       destroying workqueue rpciod\n");
 
-       destroy_workqueue(rpciod_workqueue);
+       wq = rpciod_workqueue;
        rpciod_workqueue = NULL;
- out:
-       mutex_unlock(&rpciod_mutex);
+       destroy_workqueue(wq);
 }
 
-#ifdef RPC_DEBUG
-void rpc_show_tasks(void)
-{
-       struct rpc_clnt *clnt;
-       struct rpc_task *t;
-
-       spin_lock(&rpc_sched_lock);
-       if (list_empty(&all_clients))
-               goto out;
-       printk("-pid- proc flgs status -client- -prog- --rqstp- -timeout "
-               "-rpcwait -action- ---ops--\n");
-       list_for_each_entry(clnt, &all_clients, cl_clients) {
-               if (list_empty(&clnt->cl_tasks))
-                       continue;
-               spin_lock(&clnt->cl_lock);
-               list_for_each_entry(t, &clnt->cl_tasks, tk_task) {
-                       const char *rpc_waitq = "none";
-
-                       if (RPC_IS_QUEUED(t))
-                               rpc_waitq = rpc_qname(t->u.tk_wait.rpc_waitq);
-
-                       printk("%5u %04d %04x %6d %8p %6d %8p %8ld %8s %8p %8p\n",
-                               t->tk_pid,
-                               (t->tk_msg.rpc_proc ? t->tk_msg.rpc_proc->p_proc : -1),
-                               t->tk_flags, t->tk_status,
-                               t->tk_client,
-                               (t->tk_client ? t->tk_client->cl_prog : 0),
-                               t->tk_rqstp, t->tk_timeout,
-                               rpc_waitq,
-                               t->tk_action, t->tk_ops);
-               }
-               spin_unlock(&clnt->cl_lock);
-       }
-out:
-       spin_unlock(&rpc_sched_lock);
-}
-#endif
-
 void
 rpc_destroy_mempool(void)
 {
+       rpciod_stop();
        if (rpc_buffer_mempool)
                mempool_destroy(rpc_buffer_mempool);
        if (rpc_task_mempool)
@@ -1154,13 +1018,13 @@ rpc_init_mempool(void)
        rpc_task_slabp = kmem_cache_create("rpc_tasks",
                                             sizeof(struct rpc_task),
                                             0, SLAB_HWCACHE_ALIGN,
-                                            NULL, NULL);
+                                            NULL);
        if (!rpc_task_slabp)
                goto err_nomem;
        rpc_buffer_slabp = kmem_cache_create("rpc_buffers",
                                             RPC_BUFFER_MAXSIZE,
                                             0, SLAB_HWCACHE_ALIGN,
-                                            NULL, NULL);
+                                            NULL);
        if (!rpc_buffer_slabp)
                goto err_nomem;
        rpc_task_mempool = mempool_create_slab_pool(RPC_TASK_POOLSIZE,
@@ -1171,6 +1035,8 @@ rpc_init_mempool(void)
                                                      rpc_buffer_slabp);
        if (!rpc_buffer_mempool)
                goto err_nomem;
+       if (!rpciod_start())
+               goto err_nomem;
        return 0;
 err_nomem:
        rpc_destroy_mempool();