Commit 6a19275a authored by J. Bruce Fields's avatar J. Bruce Fields Committed by Trond Myklebust

[PATCH] RPC: [PATCH] improve rpcauthauth_create error returns

 Currently we return -ENOMEM for every single failure to create a new auth.
 This is actually accurate for auth_null and auth_unix, but for auth_gss it's a
 bit confusing.

 Allow rpcauth_create (and the ->create methods) to return errors.  With this
 patch, the user may sometimes see an EINVAL instead.  Whee.
Signed-off-by: default avatarJ. Bruce Fields <bfields@citi.umich.edu>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 438b6fde
...@@ -160,11 +160,10 @@ nfs_clear_inode(struct inode *inode) ...@@ -160,11 +160,10 @@ nfs_clear_inode(struct inode *inode)
void void
nfs_umount_begin(struct super_block *sb) nfs_umount_begin(struct super_block *sb)
{ {
struct nfs_server *server = NFS_SB(sb); struct rpc_clnt *rpc = NFS_SB(sb)->client;
struct rpc_clnt *rpc;
/* -EIO all pending I/O */ /* -EIO all pending I/O */
if ((rpc = server->client) != NULL) if (!IS_ERR(rpc))
rpc_killall_tasks(rpc); rpc_killall_tasks(rpc);
} }
...@@ -450,11 +449,14 @@ nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data, int silent) ...@@ -450,11 +449,14 @@ nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data, int silent)
return PTR_ERR(server->client); return PTR_ERR(server->client);
/* RFC 2623, sec 2.3.2 */ /* RFC 2623, sec 2.3.2 */
if (authflavor != RPC_AUTH_UNIX) { if (authflavor != RPC_AUTH_UNIX) {
struct rpc_auth *auth;
server->client_sys = rpc_clone_client(server->client); server->client_sys = rpc_clone_client(server->client);
if (IS_ERR(server->client_sys)) if (IS_ERR(server->client_sys))
return PTR_ERR(server->client_sys); return PTR_ERR(server->client_sys);
if (!rpcauth_create(RPC_AUTH_UNIX, server->client_sys)) auth = rpcauth_create(RPC_AUTH_UNIX, server->client_sys);
return -ENOMEM; if (IS_ERR(auth))
return PTR_ERR(auth);
} else { } else {
atomic_inc(&server->client->cl_count); atomic_inc(&server->client->cl_count);
server->client_sys = server->client; server->client_sys = server->client;
...@@ -1450,6 +1452,7 @@ static struct super_block *nfs_get_sb(struct file_system_type *fs_type, ...@@ -1450,6 +1452,7 @@ static struct super_block *nfs_get_sb(struct file_system_type *fs_type,
memset(server, 0, sizeof(struct nfs_server)); memset(server, 0, sizeof(struct nfs_server));
/* Zero out the NFS state stuff */ /* Zero out the NFS state stuff */
init_nfsv4_state(server); init_nfsv4_state(server);
server->client = server->client_sys = ERR_PTR(-EINVAL);
root = &server->fh; root = &server->fh;
if (data->flags & NFS_MOUNT_VER3) if (data->flags & NFS_MOUNT_VER3)
...@@ -1506,9 +1509,9 @@ static void nfs_kill_super(struct super_block *s) ...@@ -1506,9 +1509,9 @@ static void nfs_kill_super(struct super_block *s)
kill_anon_super(s); kill_anon_super(s);
if (server->client != NULL && !IS_ERR(server->client)) if (!IS_ERR(server->client))
rpc_shutdown_client(server->client); rpc_shutdown_client(server->client);
if (server->client_sys != NULL && !IS_ERR(server->client_sys)) if (!IS_ERR(server->client_sys))
rpc_shutdown_client(server->client_sys); rpc_shutdown_client(server->client_sys);
if (!(server->flags & NFS_MOUNT_NONLM)) if (!(server->flags & NFS_MOUNT_NONLM))
...@@ -1650,7 +1653,7 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, ...@@ -1650,7 +1653,7 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data,
} }
down_write(&clp->cl_sem); down_write(&clp->cl_sem);
if (clp->cl_rpcclient == NULL) { if (IS_ERR(clp->cl_rpcclient)) {
xprt = xprt_create_proto(proto, &server->addr, &timeparms); xprt = xprt_create_proto(proto, &server->addr, &timeparms);
if (IS_ERR(xprt)) { if (IS_ERR(xprt)) {
up_write(&clp->cl_sem); up_write(&clp->cl_sem);
...@@ -1711,9 +1714,12 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, ...@@ -1711,9 +1714,12 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data,
} }
if (clnt->cl_auth->au_flavor != authflavour) { if (clnt->cl_auth->au_flavor != authflavour) {
if (rpcauth_create(authflavour, clnt) == NULL) { struct rpc_auth *auth;
auth = rpcauth_create(authflavour, clnt);
if (IS_ERR(auth)) {
dprintk("%s: couldn't create credcache!\n", __FUNCTION__); dprintk("%s: couldn't create credcache!\n", __FUNCTION__);
return -ENOMEM; return PTR_ERR(auth);
} }
} }
...@@ -1788,6 +1794,7 @@ static struct super_block *nfs4_get_sb(struct file_system_type *fs_type, ...@@ -1788,6 +1794,7 @@ static struct super_block *nfs4_get_sb(struct file_system_type *fs_type,
memset(server, 0, sizeof(struct nfs_server)); memset(server, 0, sizeof(struct nfs_server));
/* Zero out the NFS state stuff */ /* Zero out the NFS state stuff */
init_nfsv4_state(server); init_nfsv4_state(server);
server->client = server->client_sys = ERR_PTR(-EINVAL);
p = nfs_copy_user_string(NULL, &data->hostname, 256); p = nfs_copy_user_string(NULL, &data->hostname, 256);
if (IS_ERR(p)) if (IS_ERR(p))
......
...@@ -110,6 +110,7 @@ nfs4_alloc_client(struct in_addr *addr) ...@@ -110,6 +110,7 @@ nfs4_alloc_client(struct in_addr *addr)
INIT_LIST_HEAD(&clp->cl_superblocks); INIT_LIST_HEAD(&clp->cl_superblocks);
init_waitqueue_head(&clp->cl_waitq); init_waitqueue_head(&clp->cl_waitq);
rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS4 client"); rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS4 client");
clp->cl_rpcclient = ERR_PTR(-EINVAL);
clp->cl_boot_time = CURRENT_TIME; clp->cl_boot_time = CURRENT_TIME;
clp->cl_state = 1 << NFS4CLNT_OK; clp->cl_state = 1 << NFS4CLNT_OK;
return clp; return clp;
...@@ -131,7 +132,7 @@ nfs4_free_client(struct nfs4_client *clp) ...@@ -131,7 +132,7 @@ nfs4_free_client(struct nfs4_client *clp)
if (clp->cl_cred) if (clp->cl_cred)
put_rpccred(clp->cl_cred); put_rpccred(clp->cl_cred);
nfs_idmap_delete(clp); nfs_idmap_delete(clp);
if (clp->cl_rpcclient) if (!IS_ERR(clp->cl_rpcclient))
rpc_shutdown_client(clp->cl_rpcclient); rpc_shutdown_client(clp->cl_rpcclient);
kfree(clp); kfree(clp);
nfs_callback_down(); nfs_callback_down();
......
...@@ -66,10 +66,10 @@ rpcauth_create(rpc_authflavor_t pseudoflavor, struct rpc_clnt *clnt) ...@@ -66,10 +66,10 @@ rpcauth_create(rpc_authflavor_t pseudoflavor, struct rpc_clnt *clnt)
u32 flavor = pseudoflavor_to_flavor(pseudoflavor); u32 flavor = pseudoflavor_to_flavor(pseudoflavor);
if (flavor >= RPC_AUTH_MAXFLAVOR || !(ops = auth_flavors[flavor])) if (flavor >= RPC_AUTH_MAXFLAVOR || !(ops = auth_flavors[flavor]))
return NULL; return ERR_PTR(-EINVAL);
auth = ops->create(clnt, pseudoflavor); auth = ops->create(clnt, pseudoflavor);
if (!auth) if (IS_ERR(auth))
return NULL; return auth;
if (clnt->cl_auth) if (clnt->cl_auth)
rpcauth_destroy(clnt->cl_auth); rpcauth_destroy(clnt->cl_auth);
clnt->cl_auth = auth; clnt->cl_auth = auth;
......
...@@ -660,14 +660,16 @@ gss_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor) ...@@ -660,14 +660,16 @@ gss_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor)
{ {
struct gss_auth *gss_auth; struct gss_auth *gss_auth;
struct rpc_auth * auth; struct rpc_auth * auth;
int err = -ENOMEM; /* XXX? */
dprintk("RPC: creating GSS authenticator for client %p\n",clnt); dprintk("RPC: creating GSS authenticator for client %p\n",clnt);
if (!try_module_get(THIS_MODULE)) if (!try_module_get(THIS_MODULE))
return NULL; return ERR_PTR(err);
if (!(gss_auth = kmalloc(sizeof(*gss_auth), GFP_KERNEL))) if (!(gss_auth = kmalloc(sizeof(*gss_auth), GFP_KERNEL)))
goto out_dec; goto out_dec;
gss_auth->client = clnt; gss_auth->client = clnt;
err = -EINVAL;
gss_auth->mech = gss_mech_get_by_pseudoflavor(flavor); gss_auth->mech = gss_mech_get_by_pseudoflavor(flavor);
if (!gss_auth->mech) { if (!gss_auth->mech) {
printk(KERN_WARNING "%s: Pseudoflavor %d not found!", printk(KERN_WARNING "%s: Pseudoflavor %d not found!",
...@@ -686,15 +688,18 @@ gss_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor) ...@@ -686,15 +688,18 @@ gss_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor)
auth->au_flavor = flavor; auth->au_flavor = flavor;
atomic_set(&auth->au_count, 1); atomic_set(&auth->au_count, 1);
if (rpcauth_init_credcache(auth, GSS_CRED_EXPIRE) < 0) err = rpcauth_init_credcache(auth, GSS_CRED_EXPIRE);
if (err)
goto err_put_mech; goto err_put_mech;
snprintf(gss_auth->path, sizeof(gss_auth->path), "%s/%s", snprintf(gss_auth->path, sizeof(gss_auth->path), "%s/%s",
clnt->cl_pathname, clnt->cl_pathname,
gss_auth->mech->gm_name); gss_auth->mech->gm_name);
gss_auth->dentry = rpc_mkpipe(gss_auth->path, clnt, &gss_upcall_ops, RPC_PIPE_WAIT_FOR_OPEN); gss_auth->dentry = rpc_mkpipe(gss_auth->path, clnt, &gss_upcall_ops, RPC_PIPE_WAIT_FOR_OPEN);
if (IS_ERR(gss_auth->dentry)) if (IS_ERR(gss_auth->dentry)) {
err = PTR_ERR(gss_auth->dentry);
goto err_put_mech; goto err_put_mech;
}
return auth; return auth;
err_put_mech: err_put_mech:
...@@ -703,7 +708,7 @@ err_free: ...@@ -703,7 +708,7 @@ err_free:
kfree(gss_auth); kfree(gss_auth);
out_dec: out_dec:
module_put(THIS_MODULE); module_put(THIS_MODULE);
return NULL; return ERR_PTR(err);
} }
static void static void
......
...@@ -103,6 +103,7 @@ rpc_new_client(struct rpc_xprt *xprt, char *servname, ...@@ -103,6 +103,7 @@ rpc_new_client(struct rpc_xprt *xprt, char *servname,
{ {
struct rpc_version *version; struct rpc_version *version;
struct rpc_clnt *clnt = NULL; struct rpc_clnt *clnt = NULL;
struct rpc_auth *auth;
int err; int err;
int len; int len;
...@@ -157,10 +158,11 @@ rpc_new_client(struct rpc_xprt *xprt, char *servname, ...@@ -157,10 +158,11 @@ rpc_new_client(struct rpc_xprt *xprt, char *servname,
if (err < 0) if (err < 0)
goto out_no_path; goto out_no_path;
err = -ENOMEM; auth = rpcauth_create(flavor, clnt);
if (!rpcauth_create(flavor, clnt)) { if (IS_ERR(auth)) {
printk(KERN_INFO "RPC: Couldn't create auth handle (flavor %u)\n", printk(KERN_INFO "RPC: Couldn't create auth handle (flavor %u)\n",
flavor); flavor);
err = PTR_ERR(auth);
goto out_no_auth; goto out_no_auth;
} }
......
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