Commit 873e3851 authored by Jeff Layton's avatar Jeff Layton Committed by Trond Myklebust

nfs: make nfs4_init_uniform_client_string use a dynamically allocated buffer

Change the uniform client string generator to dynamically allocate the
NFSv4 client name string buffer. With this patch, we can eliminate the
buffers that are embedded within the "args" structs and simply use the
name string that is hanging off the client.

This uniform string case is a little simpler than the nonuniform since
we don't need to deal with RCU, but we do have two different cases,
depending on whether there is a uniquifier or not.
Signed-off-by: default avatarJeff Layton <jeff.layton@primarydata.com>
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@primarydata.com>
parent a3192688
...@@ -5007,28 +5007,78 @@ nfs4_init_nonuniform_client_string(struct nfs_client *clp) ...@@ -5007,28 +5007,78 @@ nfs4_init_nonuniform_client_string(struct nfs_client *clp)
return 0; return 0;
} }
static unsigned int static int
nfs4_init_uniform_client_string(struct nfs_client *clp, nfs4_init_uniquifier_client_string(struct nfs_client *clp)
char *buf, size_t len)
{ {
const char *nodename = clp->cl_rpcclient->cl_nodename; int result;
unsigned int result; size_t len;
char *str;
len = 10 + 10 + 1 + 10 + 1 +
strlen(nfs4_client_id_uniquifier) + 1 +
strlen(clp->cl_rpcclient->cl_nodename) + 1;
if (len > NFS4_OPAQUE_LIMIT + 1)
return -EINVAL;
/*
* Since this string is allocated at mount time, and held until the
* nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying
* about a memory-reclaim deadlock.
*/
str = kmalloc(len, GFP_KERNEL);
if (!str)
return -ENOMEM;
result = scnprintf(str, len, "Linux NFSv%u.%u %s/%s",
clp->rpc_ops->version, clp->cl_minorversion,
nfs4_client_id_uniquifier,
clp->cl_rpcclient->cl_nodename);
if (result >= len) {
kfree(str);
return -EINVAL;
}
clp->cl_owner_id = str;
return 0;
}
static int
nfs4_init_uniform_client_string(struct nfs_client *clp)
{
int result;
size_t len;
char *str;
if (clp->cl_owner_id != NULL) if (clp->cl_owner_id != NULL)
return strlcpy(buf, clp->cl_owner_id, len); return 0;
if (nfs4_client_id_uniquifier[0] != '\0') if (nfs4_client_id_uniquifier[0] != '\0')
result = scnprintf(buf, len, "Linux NFSv%u.%u %s/%s", return nfs4_init_uniquifier_client_string(clp);
clp->rpc_ops->version,
clp->cl_minorversion, len = 10 + 10 + 1 + 10 + 1 +
nfs4_client_id_uniquifier, strlen(clp->cl_rpcclient->cl_nodename) + 1;
nodename);
else if (len > NFS4_OPAQUE_LIMIT + 1)
result = scnprintf(buf, len, "Linux NFSv%u.%u %s", return -EINVAL;
clp->rpc_ops->version, clp->cl_minorversion,
nodename); /*
clp->cl_owner_id = kstrdup(buf, GFP_KERNEL); * Since this string is allocated at mount time, and held until the
return result; * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying
* about a memory-reclaim deadlock.
*/
str = kmalloc(len, GFP_KERNEL);
if (!str)
return -ENOMEM;
result = scnprintf(str, len, "Linux NFSv%u.%u %s",
clp->rpc_ops->version, clp->cl_minorversion,
clp->cl_rpcclient->cl_nodename);
if (result >= len) {
kfree(str);
return -EINVAL;
}
clp->cl_owner_id = str;
return 0;
} }
/* /*
...@@ -5095,20 +5145,14 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, ...@@ -5095,20 +5145,14 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
/* nfs_client_id4 */ /* nfs_client_id4 */
nfs4_init_boot_verifier(clp, &sc_verifier); nfs4_init_boot_verifier(clp, &sc_verifier);
if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) {
setclientid.sc_name_len = if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags))
nfs4_init_uniform_client_string(clp, status = nfs4_init_uniform_client_string(clp);
setclientid.sc_name, else
sizeof(setclientid.sc_name));
if (!clp->cl_owner_id) {
status = -ENOMEM;
goto out;
}
} else {
status = nfs4_init_nonuniform_client_string(clp); status = nfs4_init_nonuniform_client_string(clp);
if (status)
goto out; if (status)
} goto out;
/* cb_client4 */ /* cb_client4 */
setclientid.sc_netid_len = setclientid.sc_netid_len =
...@@ -6882,12 +6926,10 @@ static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, ...@@ -6882,12 +6926,10 @@ static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred,
}; };
nfs4_init_boot_verifier(clp, &verifier); nfs4_init_boot_verifier(clp, &verifier);
args.id_len = nfs4_init_uniform_client_string(clp, args.id,
sizeof(args.id)); status = nfs4_init_uniform_client_string(clp);
if (!clp->cl_owner_id) { if (status)
status = -ENOMEM;
goto out; goto out;
}
dprintk("NFS call exchange_id auth=%s, '%s'\n", dprintk("NFS call exchange_id auth=%s, '%s'\n",
clp->cl_rpcclient->cl_auth->au_ops->au_name, clp->cl_rpcclient->cl_auth->au_ops->au_name,
......
...@@ -984,11 +984,8 @@ struct nfs4_readlink_res { ...@@ -984,11 +984,8 @@ struct nfs4_readlink_res {
struct nfs4_sequence_res seq_res; struct nfs4_sequence_res seq_res;
}; };
#define NFS4_SETCLIENTID_NAMELEN (127)
struct nfs4_setclientid { struct nfs4_setclientid {
const nfs4_verifier * sc_verifier; const nfs4_verifier * sc_verifier;
unsigned int sc_name_len;
char sc_name[NFS4_SETCLIENTID_NAMELEN + 1];
u32 sc_prog; u32 sc_prog;
unsigned int sc_netid_len; unsigned int sc_netid_len;
char sc_netid[RPCBIND_MAXNETIDLEN + 1]; char sc_netid[RPCBIND_MAXNETIDLEN + 1];
...@@ -1142,12 +1139,9 @@ struct nfs41_state_protection { ...@@ -1142,12 +1139,9 @@ struct nfs41_state_protection {
struct nfs4_op_map allow; struct nfs4_op_map allow;
}; };
#define NFS4_EXCHANGE_ID_LEN (127)
struct nfs41_exchange_id_args { struct nfs41_exchange_id_args {
struct nfs_client *client; struct nfs_client *client;
nfs4_verifier *verifier; nfs4_verifier *verifier;
unsigned int id_len;
char id[NFS4_EXCHANGE_ID_LEN];
u32 flags; u32 flags;
struct nfs41_state_protection state_protect; struct nfs41_state_protection state_protect;
}; };
......
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