Commit 5ede7b1c authored by Al Viro's avatar Al Viro

pull manipulations of rpc_cred inside alloc_nfs_open_context()

No need to duplicate them in both callers; make it return
ERR_PTR(-ENOMEM) on allocation failure instead of NULL and
it'll be able to report rpc_lookup_cred() failures just
fine.  Callers are much happier that way...
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 157e8bf8
...@@ -1368,18 +1368,7 @@ static fmode_t flags_to_mode(int flags) ...@@ -1368,18 +1368,7 @@ static fmode_t flags_to_mode(int flags)
static struct nfs_open_context *create_nfs_open_context(struct dentry *dentry, int open_flags) static struct nfs_open_context *create_nfs_open_context(struct dentry *dentry, int open_flags)
{ {
struct nfs_open_context *ctx; return alloc_nfs_open_context(dentry, flags_to_mode(open_flags));
struct rpc_cred *cred;
fmode_t fmode = flags_to_mode(open_flags);
cred = rpc_lookup_cred();
if (IS_ERR(cred))
return ERR_CAST(cred);
ctx = alloc_nfs_open_context(dentry, cred, fmode);
put_rpccred(cred);
if (ctx == NULL)
return ERR_PTR(-ENOMEM);
return ctx;
} }
static int do_open(struct inode *inode, struct file *filp) static int do_open(struct inode *inode, struct file *filp)
......
...@@ -629,23 +629,28 @@ void nfs_close_context(struct nfs_open_context *ctx, int is_sync) ...@@ -629,23 +629,28 @@ void nfs_close_context(struct nfs_open_context *ctx, int is_sync)
nfs_revalidate_inode(server, inode); nfs_revalidate_inode(server, inode);
} }
struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, struct rpc_cred *cred, fmode_t f_mode) struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode)
{ {
struct nfs_open_context *ctx; struct nfs_open_context *ctx;
struct rpc_cred *cred = rpc_lookup_cred();
if (IS_ERR(cred))
return ERR_CAST(cred);
ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
if (ctx != NULL) { if (!ctx) {
nfs_sb_active(dentry->d_sb); put_rpccred(cred);
ctx->dentry = dget(dentry); return ERR_PTR(-ENOMEM);
ctx->cred = get_rpccred(cred);
ctx->state = NULL;
ctx->mode = f_mode;
ctx->flags = 0;
ctx->error = 0;
nfs_init_lock_context(&ctx->lock_context);
ctx->lock_context.open_context = ctx;
INIT_LIST_HEAD(&ctx->list);
} }
nfs_sb_active(dentry->d_sb);
ctx->dentry = dget(dentry);
ctx->cred = cred;
ctx->state = NULL;
ctx->mode = f_mode;
ctx->flags = 0;
ctx->error = 0;
nfs_init_lock_context(&ctx->lock_context);
ctx->lock_context.open_context = ctx;
INIT_LIST_HEAD(&ctx->list);
return ctx; return ctx;
} }
...@@ -738,15 +743,10 @@ static void nfs_file_clear_open_context(struct file *filp) ...@@ -738,15 +743,10 @@ static void nfs_file_clear_open_context(struct file *filp)
int nfs_open(struct inode *inode, struct file *filp) int nfs_open(struct inode *inode, struct file *filp)
{ {
struct nfs_open_context *ctx; struct nfs_open_context *ctx;
struct rpc_cred *cred;
cred = rpc_lookup_cred(); ctx = alloc_nfs_open_context(filp->f_path.dentry, filp->f_mode);
if (IS_ERR(cred)) if (IS_ERR(ctx))
return PTR_ERR(cred); return PTR_ERR(ctx);
ctx = alloc_nfs_open_context(filp->f_path.dentry, cred, filp->f_mode);
put_rpccred(cred);
if (ctx == NULL)
return -ENOMEM;
nfs_file_set_open_context(filp, ctx); nfs_file_set_open_context(filp, ctx);
put_nfs_open_context(ctx); put_nfs_open_context(ctx);
nfs_fscache_set_inode_cookie(inode, filp); nfs_fscache_set_inode_cookie(inode, filp);
......
...@@ -373,7 +373,7 @@ extern void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr); ...@@ -373,7 +373,7 @@ extern void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr);
extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx); extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx);
extern void put_nfs_open_context(struct nfs_open_context *ctx); extern void put_nfs_open_context(struct nfs_open_context *ctx);
extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, fmode_t mode); extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, fmode_t mode);
extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, struct rpc_cred *cred, fmode_t f_mode); extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode);
extern void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx); extern void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx);
extern struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx); extern struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx);
extern void nfs_put_lock_context(struct nfs_lock_context *l_ctx); extern void nfs_put_lock_context(struct nfs_lock_context *l_ctx);
......
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