]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/nfsd/nfssvc.c
Pull style into test branch
[linux-2.6-omap-h63xx.git] / fs / nfsd / nfssvc.c
index 0029cb290f18c0fb746e6a3449a0375c28900c94..0aaccb03bf769a582ce6070d7e04ecfa261ae9f8 100644 (file)
@@ -198,9 +198,26 @@ int nfsd_create_serv(void)
                unlock_kernel();
                return 0;
        }
+       if (nfsd_max_blksize == 0) {
+               /* choose a suitable default */
+               struct sysinfo i;
+               si_meminfo(&i);
+               /* Aim for 1/4096 of memory per thread
+                * This gives 1MB on 4Gig machines
+                * But only uses 32K on 128M machines.
+                * Bottom out at 8K on 32M and smaller.
+                * Of course, this is only a default.
+                */
+               nfsd_max_blksize = NFSSVC_MAXBLKSIZE;
+               i.totalram <<= PAGE_SHIFT - 12;
+               while (nfsd_max_blksize > i.totalram &&
+                      nfsd_max_blksize >= 8*1024*2)
+                       nfsd_max_blksize /= 2;
+       }
 
        atomic_set(&nfsd_busy, 0);
-       nfsd_serv = svc_create_pooled(&nfsd_program, NFSD_BUFSIZE,
+       nfsd_serv = svc_create_pooled(&nfsd_program,
+                                     nfsd_max_blksize,
                                      nfsd_last_thread,
                                      nfsd, SIG_NOCLEAN, THIS_MODULE);
        if (nfsd_serv == NULL)
@@ -238,6 +255,80 @@ static int nfsd_init_socks(int port)
        return 0;
 }
 
+int nfsd_nrpools(void)
+{
+       if (nfsd_serv == NULL)
+               return 0;
+       else
+               return nfsd_serv->sv_nrpools;
+}
+
+int nfsd_get_nrthreads(int n, int *nthreads)
+{
+       int i = 0;
+
+       if (nfsd_serv != NULL) {
+               for (i = 0; i < nfsd_serv->sv_nrpools && i < n; i++)
+                       nthreads[i] = nfsd_serv->sv_pools[i].sp_nrthreads;
+       }
+
+       return 0;
+}
+
+int nfsd_set_nrthreads(int n, int *nthreads)
+{
+       int i = 0;
+       int tot = 0;
+       int err = 0;
+
+       if (nfsd_serv == NULL || n <= 0)
+               return 0;
+
+       if (n > nfsd_serv->sv_nrpools)
+               n = nfsd_serv->sv_nrpools;
+
+       /* enforce a global maximum number of threads */
+       tot = 0;
+       for (i = 0; i < n; i++) {
+               if (nthreads[i] > NFSD_MAXSERVS)
+                       nthreads[i] = NFSD_MAXSERVS;
+               tot += nthreads[i];
+       }
+       if (tot > NFSD_MAXSERVS) {
+               /* total too large: scale down requested numbers */
+               for (i = 0; i < n && tot > 0; i++) {
+                       int new = nthreads[i] * NFSD_MAXSERVS / tot;
+                       tot -= (nthreads[i] - new);
+                       nthreads[i] = new;
+               }
+               for (i = 0; i < n && tot > 0; i++) {
+                       nthreads[i]--;
+                       tot--;
+               }
+       }
+
+       /*
+        * There must always be a thread in pool 0; the admin
+        * can't shut down NFS completely using pool_threads.
+        */
+       if (nthreads[0] == 0)
+               nthreads[0] = 1;
+
+       /* apply the new numbers */
+       lock_kernel();
+       svc_get(nfsd_serv);
+       for (i = 0; i < n; i++) {
+               err = svc_set_num_threads(nfsd_serv, &nfsd_serv->sv_pools[i],
+                                         nthreads[i]);
+               if (err)
+                       break;
+       }
+       svc_destroy(nfsd_serv);
+       unlock_kernel();
+
+       return err;
+}
+
 int
 nfsd_svc(unsigned short port, int nrservs)
 {
@@ -400,12 +491,12 @@ out:
 }
 
 int
-nfsd_dispatch(struct svc_rqst *rqstp, u32 *statp)
+nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp)
 {
        struct svc_procedure    *proc;
        kxdrproc_t              xdr;
-       u32                     nfserr;
-       u32                     *nfserrp;
+       __be32                  nfserr;
+       __be32                  *nfserrp;
 
        dprintk("nfsd_dispatch: vers %d proc %d\n",
                                rqstp->rq_vers, rqstp->rq_proc);
@@ -424,7 +515,7 @@ nfsd_dispatch(struct svc_rqst *rqstp, u32 *statp)
 
        /* Decode arguments */
        xdr = proc->pc_decode;
-       if (xdr && !xdr(rqstp, (u32*)rqstp->rq_arg.head[0].iov_base,
+       if (xdr && !xdr(rqstp, (__be32*)rqstp->rq_arg.head[0].iov_base,
                        rqstp->rq_argp)) {
                dprintk("nfsd: failed to decode arguments!\n");
                nfsd_cache_update(rqstp, RC_NOCACHE, NULL);
@@ -437,7 +528,7 @@ nfsd_dispatch(struct svc_rqst *rqstp, u32 *statp)
         */
        nfserrp = rqstp->rq_res.head[0].iov_base
                + rqstp->rq_res.head[0].iov_len;
-       rqstp->rq_res.head[0].iov_len += sizeof(u32);
+       rqstp->rq_res.head[0].iov_len += sizeof(__be32);
 
        /* Now call the procedure handler, and encode NFS status. */
        nfserr = proc->pc_func(rqstp, rqstp->rq_argp, rqstp->rq_resp);