Commit ff7d9756 authored by Olga Kornievskaia's avatar Olga Kornievskaia Committed by J. Bruce Fields

nfsd: use static memory for callback program and stats

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: default avatarJ. Bruce Fields <bfields@citi.umich.edu>
parent 8774282c
...@@ -344,6 +344,21 @@ static struct rpc_version * nfs_cb_version[] = { ...@@ -344,6 +344,21 @@ static struct rpc_version * nfs_cb_version[] = {
&nfs_cb_version4, &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. /* Reference counting, callback cleanup, etc., all look racy as heck.
* And why is cb_set an atomic? */ * And why is cb_set an atomic? */
...@@ -358,13 +373,12 @@ static int do_probe_callback(void *data) ...@@ -358,13 +373,12 @@ static int do_probe_callback(void *data)
.to_maxval = (NFSD_LEASE_TIME/2) * HZ, .to_maxval = (NFSD_LEASE_TIME/2) * HZ,
.to_exponential = 1, .to_exponential = 1,
}; };
struct rpc_program * program = &cb->cb_program;
struct rpc_create_args args = { struct rpc_create_args args = {
.protocol = IPPROTO_TCP, .protocol = IPPROTO_TCP,
.address = (struct sockaddr *)&addr, .address = (struct sockaddr *)&addr,
.addrsize = sizeof(addr), .addrsize = sizeof(addr),
.timeout = &timeparms, .timeout = &timeparms,
.program = program, .program = &cb_program,
.version = nfs_cb_version[1]->number, .version = nfs_cb_version[1]->number,
.authflavor = RPC_AUTH_UNIX, /* XXX: need AUTH_GSS... */ .authflavor = RPC_AUTH_UNIX, /* XXX: need AUTH_GSS... */
.flags = (RPC_CLNT_CREATE_NOPING), .flags = (RPC_CLNT_CREATE_NOPING),
...@@ -382,16 +396,8 @@ static int do_probe_callback(void *data) ...@@ -382,16 +396,8 @@ static int do_probe_callback(void *data)
addr.sin_port = htons(cb->cb_port); addr.sin_port = htons(cb->cb_port);
addr.sin_addr.s_addr = htonl(cb->cb_addr); 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 */ /* Initialize rpc_stat */
memset(program->stats, 0, sizeof(cb->cb_stat)); memset(args.program->stats, 0, sizeof(struct rpc_stat));
program->stats->program = program;
/* Create RPC client */ /* Create RPC client */
client = rpc_create(&args); client = rpc_create(&args);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment