nfsd: don't take nfsd_mutex twice when setting number of threads.
authorNeilBrown <neilb@suse.de>
Tue, 16 Jun 2009 01:03:07 +0000 (11:03 +1000)
committerJ. Bruce Fields <bfields@citi.umich.edu>
Thu, 18 Jun 2009 16:40:31 +0000 (09:40 -0700)
Currently when we write a number to 'threads' in nfsdfs,
we take the nfsd_mutex, update the number of threads, then take the
mutex again to read the number of threads.

Mostly this isn't a big deal.  However if we are write '0', and
portmap happens to be dead, then we can get unpredictable behaviour.
If the nfsd threads all got killed quickly and the last thread is
waiting for portmap to respond, then the second time we take the mutex
we will block waiting for the last thread.
However if the nfsd threads didn't die quite that fast, then there
will be no contention when we try to take the mutex again.

Unpredictability isn't fun, and waiting for the last thread to exit is
pointless, so avoid taking the lock twice.
To achieve this, get nfsd_svc return a non-negative number of active
threads when not returning a negative error.

Signed-off-by: NeilBrown <neilb@suse.de>
fs/nfsd/nfsctl.c
fs/nfsd/nfssvc.c

index 877e713a0fd6886c4f0f43262c66414eacc59029..1250fb978ac1451b8d00f87bfe5183eb12d9f26f 100644 (file)
@@ -207,10 +207,14 @@ static struct file_operations pool_stats_operations = {
 static ssize_t write_svc(struct file *file, char *buf, size_t size)
 {
        struct nfsctl_svc *data;
+       int err;
        if (size < sizeof(*data))
                return -EINVAL;
        data = (struct nfsctl_svc*) buf;
-       return nfsd_svc(data->svc_port, data->svc_nthreads);
+       err = nfsd_svc(data->svc_port, data->svc_nthreads);
+       if (err < 0)
+               return err;
+       return 0;
 }
 
 /**
@@ -692,12 +696,12 @@ static ssize_t write_threads(struct file *file, char *buf, size_t size)
                if (newthreads < 0)
                        return -EINVAL;
                rv = nfsd_svc(NFS_PORT, newthreads);
-               if (rv)
+               if (rv < 0)
                        return rv;
-       }
+       } else
+               rv = nfsd_nrthreads();
 
-       return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n",
-                                                       nfsd_nrthreads());
+       return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv);
 }
 
 /**
index cbba4a935786db386ecf0b60e3a001b6f15ebf03..209eaa0885d10d5e2bdc98ac8327358b793fbaa6 100644 (file)
@@ -413,6 +413,12 @@ nfsd_svc(unsigned short port, int nrservs)
                goto failure;
 
        error = svc_set_num_threads(nfsd_serv, NULL, nrservs);
+       if (error == 0)
+               /* We are holding a reference to nfsd_serv which
+                * we don't want to count in the return value,
+                * so subtract 1
+                */
+               error = nfsd_serv->sv_nrthreads - 1;
  failure:
        svc_destroy(nfsd_serv);         /* Release server */
  out: