]> git.karo-electronics.de Git - linux-beck.git/commitdiff
nfsd: use static memory for callback program and stats
authorOlga Kornievskaia <aglo@citi.umich.edu>
Fri, 28 Mar 2008 20:04:56 +0000 (16:04 -0400)
committerJ. Bruce Fields <bfields@citi.umich.edu>
Wed, 23 Apr 2008 20:13:42 +0000 (16:13 -0400)
There's no need to dynamically allocate this memory, and doing so may
create the possibility of races on shutdown of the rpc client.  (We've
witnessed it only after adding rpcsec_gss support to the server, after
which the rpc code can send destroys calls that expect to still be able
to access the rpc_stats structure after it has been destroyed.)

Such races are in theory possible if the module containing this "static"
memory is removed very quickly after an rpc client is destroyed, but
we haven't seen that happen.

Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
fs/nfsd/nfs4callback.c

index aae2b29ae2c9e6d4b645f91bf68b50046030accc..562abf3380d032e96342589fa13232233698c130 100644 (file)
@@ -344,6 +344,21 @@ static struct rpc_version *        nfs_cb_version[] = {
        &nfs_cb_version4,
 };
 
+static struct rpc_program cb_program;
+
+static struct rpc_stat cb_stats = {
+               .program        = &cb_program
+};
+
+#define NFS4_CALLBACK 0x40000000
+static struct rpc_program cb_program = {
+               .name           = "nfs4_cb",
+               .number         = NFS4_CALLBACK,
+               .nrvers         = ARRAY_SIZE(nfs_cb_version),
+               .version        = nfs_cb_version,
+               .stats          = &cb_stats,
+};
+
 /* Reference counting, callback cleanup, etc., all look racy as heck.
  * And why is cb_set an atomic? */
 
@@ -358,13 +373,12 @@ static int do_probe_callback(void *data)
                .to_maxval      = (NFSD_LEASE_TIME/2) * HZ,
                .to_exponential = 1,
        };
-       struct rpc_program *    program = &cb->cb_program;
        struct rpc_create_args args = {
                .protocol       = IPPROTO_TCP,
                .address        = (struct sockaddr *)&addr,
                .addrsize       = sizeof(addr),
                .timeout        = &timeparms,
-               .program        = program,
+               .program        = &cb_program,
                .version        = nfs_cb_version[1]->number,
                .authflavor     = RPC_AUTH_UNIX, /* XXX: need AUTH_GSS... */
                .flags          = (RPC_CLNT_CREATE_NOPING),
@@ -382,16 +396,8 @@ static int do_probe_callback(void *data)
        addr.sin_port = htons(cb->cb_port);
        addr.sin_addr.s_addr = htonl(cb->cb_addr);
 
-       /* Initialize rpc_program */
-       program->name = "nfs4_cb";
-       program->number = cb->cb_prog;
-       program->nrvers = ARRAY_SIZE(nfs_cb_version);
-       program->version = nfs_cb_version;
-       program->stats = &cb->cb_stat;
-
        /* Initialize rpc_stat */
-       memset(program->stats, 0, sizeof(cb->cb_stat));
-       program->stats->program = program;
+       memset(args.program->stats, 0, sizeof(struct rpc_stat));
 
        /* Create RPC client */
        client = rpc_create(&args);