Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux...
[safe/jmp/linux-2.6] / fs / nfsd / nfssvc.c
index 929af23..07e4f5d 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/smp_lock.h>
 #include <linux/freezer.h>
 #include <linux/fs_struct.h>
+#include <linux/kthread.h>
 
 #include <linux/sunrpc/types.h>
 #include <linux/sunrpc/stats.h>
 
 #define NFSDDBG_FACILITY       NFSDDBG_SVC
 
-/* these signals will be delivered to an nfsd thread 
- * when handling a request
- */
-#define ALLOWED_SIGS   (sigmask(SIGKILL))
-/* these signals will be delivered to an nfsd thread
- * when not handling a request. i.e. when waiting
- */
-#define SHUTDOWN_SIGS  (sigmask(SIGKILL) | sigmask(SIGHUP) | sigmask(SIGINT) | sigmask(SIGQUIT))
-/* if the last thread dies with SIGHUP, then the exports table is
- * left unchanged ( like 2.4-{0-9} ).  Any other signal will clear
- * the exports table (like 2.2).
- */
-#define        SIG_NOCLEAN     SIGHUP
-
 extern struct svc_program      nfsd_program;
-static void                    nfsd(struct svc_rqst *rqstp);
+static int                     nfsd(void *vrqstp);
 struct timeval                 nfssvc_boot;
 static atomic_t                        nfsd_busy;
 static unsigned long           nfsd_last_call;
@@ -169,13 +156,14 @@ int nfsd_vers(int vers, enum vers_op change)
 
 int nfsd_nrthreads(void)
 {
-       if (nfsd_serv == NULL)
-               return 0;
-       else
-               return nfsd_serv->sv_nrthreads;
+       int rv = 0;
+       mutex_lock(&nfsd_mutex);
+       if (nfsd_serv)
+               rv = nfsd_serv->sv_nrthreads;
+       mutex_unlock(&nfsd_mutex);
+       return rv;
 }
 
-static int killsig;    /* signal that was used to kill last nfsd */
 static void nfsd_last_thread(struct svc_serv *serv)
 {
        /* When last nfsd thread exits we need to do some clean-up */
@@ -186,11 +174,9 @@ static void nfsd_last_thread(struct svc_serv *serv)
        nfsd_racache_shutdown();
        nfs4_state_shutdown();
 
-       printk(KERN_WARNING "nfsd: last server has exited\n");
-       if (killsig != SIG_NOCLEAN) {
-               printk(KERN_WARNING "nfsd: unexporting all filesystems\n");
-               nfsd_export_flush();
-       }
+       printk(KERN_WARNING "nfsd: last server has exited, flushing export "
+                           "cache\n");
+       nfsd_export_flush();
 }
 
 void nfsd_reset_versions(void)
@@ -242,10 +228,9 @@ int nfsd_create_serv(void)
        }
 
        atomic_set(&nfsd_busy, 0);
-       nfsd_serv = svc_create_pooled(&nfsd_program,
-                                     nfsd_max_blksize,
-                                     nfsd_last_thread,
-                                     nfsd, SIG_NOCLEAN, THIS_MODULE);
+       nfsd_serv = svc_create_pooled(&nfsd_program, nfsd_max_blksize,
+                                     AF_INET,
+                                     nfsd_last_thread, nfsd, THIS_MODULE);
        if (nfsd_serv == NULL)
                err = -ENOMEM;
 
@@ -259,25 +244,24 @@ static int nfsd_init_socks(int port)
        if (!list_empty(&nfsd_serv->sv_permsocks))
                return 0;
 
-       error = lockd_up(IPPROTO_UDP);
-       if (error >= 0) {
-               error = svc_create_xprt(nfsd_serv, "udp", port,
+       error = svc_create_xprt(nfsd_serv, "udp", port,
                                        SVC_SOCK_DEFAULTS);
-               if (error < 0)
-                       lockd_down();
-       }
        if (error < 0)
                return error;
 
-       error = lockd_up(IPPROTO_TCP);
-       if (error >= 0) {
-               error = svc_create_xprt(nfsd_serv, "tcp", port,
+       error = lockd_up();
+       if (error < 0)
+               return error;
+
+       error = svc_create_xprt(nfsd_serv, "tcp", port,
                                        SVC_SOCK_DEFAULTS);
-               if (error < 0)
-                       lockd_down();
-       }
        if (error < 0)
                return error;
+
+       error = lockd_up();
+       if (error < 0)
+               return error;
+
        return 0;
 }
 
@@ -416,18 +400,17 @@ update_thread_usage(int busy_threads)
 /*
  * This is the NFS server kernel thread
  */
-static void
-nfsd(struct svc_rqst *rqstp)
+static int
+nfsd(void *vrqstp)
 {
+       struct svc_rqst *rqstp = (struct svc_rqst *) vrqstp;
        struct fs_struct *fsp;
-       int             err;
-       sigset_t shutdown_mask, allowed_mask;
+       int err, preverr = 0;
 
        /* Lock module and set up kernel thread */
        mutex_lock(&nfsd_mutex);
-       daemonize("nfsd");
 
-       /* After daemonize() this kernel thread shares current->fs
+       /* At this point, the thread shares current->fs
         * with the init process. We need to create files with a
         * umask of 0 instead of init's umask. */
        fsp = copy_fs_struct(current->fs);
@@ -439,17 +422,18 @@ nfsd(struct svc_rqst *rqstp)
        current->fs = fsp;
        current->fs->umask = 0;
 
-       siginitsetinv(&shutdown_mask, SHUTDOWN_SIGS);
-       siginitsetinv(&allowed_mask, ALLOWED_SIGS);
-
+       /*
+        * thread is spawned with all signals set to SIG_IGN, re-enable
+        * the ones that will bring down the thread
+        */
+       allow_signal(SIGKILL);
+       allow_signal(SIGHUP);
+       allow_signal(SIGINT);
+       allow_signal(SIGQUIT);
 
        nfsdstats.th_cnt++;
-
-       rqstp->rq_task = current;
-
        mutex_unlock(&nfsd_mutex);
 
-
        /*
         * We want less throttling in balance_dirty_pages() so that nfs to
         * localhost doesn't cause nfsd to lock up due to all the client's
@@ -462,26 +446,30 @@ nfsd(struct svc_rqst *rqstp)
         * The main request loop
         */
        for (;;) {
-               /* Block all but the shutdown signals */
-               sigprocmask(SIG_SETMASK, &shutdown_mask, NULL);
-
                /*
                 * Find a socket with data available and call its
                 * recvfrom routine.
                 */
                while ((err = svc_recv(rqstp, 60*60*HZ)) == -EAGAIN)
                        ;
-               if (err < 0)
+               if (err == -EINTR)
                        break;
+               else if (err < 0) {
+                       if (err != preverr) {
+                               printk(KERN_WARNING "%s: unexpected error "
+                                       "from svc_recv (%d)\n", __func__, -err);
+                               preverr = err;
+                       }
+                       schedule_timeout_uninterruptible(HZ);
+                       continue;
+               }
+
                update_thread_usage(atomic_read(&nfsd_busy));
                atomic_inc(&nfsd_busy);
 
                /* Lock the export hash tables for reading. */
                exp_readlock();
 
-               /* Process request with signals blocked.  */
-               sigprocmask(SIG_SETMASK, &allowed_mask, NULL);
-
                svc_process(rqstp);
 
                /* Unlock export hash tables */
@@ -490,22 +478,10 @@ nfsd(struct svc_rqst *rqstp)
                atomic_dec(&nfsd_busy);
        }
 
-       if (err != -EINTR) {
-               printk(KERN_WARNING "nfsd: terminating on error %d\n", -err);
-       } else {
-               unsigned int    signo;
-
-               for (signo = 1; signo <= _NSIG; signo++)
-                       if (sigismember(&current->pending.signal, signo) &&
-                           !sigismember(&current->blocked, signo))
-                               break;
-               killsig = signo;
-       }
        /* Clear signals before calling svc_exit_thread() */
        flush_signals(current);
 
        mutex_lock(&nfsd_mutex);
-
        nfsdstats.th_cnt --;
 
 out:
@@ -515,6 +491,7 @@ out:
        /* Release module */
        mutex_unlock(&nfsd_mutex);
        module_put_and_exit(0);
+       return 0;
 }
 
 static __be32 map_new_errors(u32 vers, __be32 nfserr)