aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2011-10-23 18:49:54 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2012-01-03 22:52:34 -0500
commit5ede7b1cfa8201418fb35e12f770e9e7c2559a4d (patch)
treec26d99fbbed708a6db116e57daca68f2b3c672ac
parent157e8bf8b4823bfcdefa6c1548002374b61f61df (diff)
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: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--fs/nfs/dir.c13
-rw-r--r--fs/nfs/inode.c40
-rw-r--r--include/linux/nfs_fs.h2
3 files changed, 22 insertions, 33 deletions
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index ac2899098147..23be134b3193 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -1368,18 +1368,7 @@ static fmode_t flags_to_mode(int flags)
1368 1368
1369static struct nfs_open_context *create_nfs_open_context(struct dentry *dentry, int open_flags) 1369static struct nfs_open_context *create_nfs_open_context(struct dentry *dentry, int open_flags)
1370{ 1370{
1371 struct nfs_open_context *ctx; 1371 return alloc_nfs_open_context(dentry, flags_to_mode(open_flags));
1372 struct rpc_cred *cred;
1373 fmode_t fmode = flags_to_mode(open_flags);
1374
1375 cred = rpc_lookup_cred();
1376 if (IS_ERR(cred))
1377 return ERR_CAST(cred);
1378 ctx = alloc_nfs_open_context(dentry, cred, fmode);
1379 put_rpccred(cred);
1380 if (ctx == NULL)
1381 return ERR_PTR(-ENOMEM);
1382 return ctx;
1383} 1372}
1384 1373
1385static int do_open(struct inode *inode, struct file *filp) 1374static int do_open(struct inode *inode, struct file *filp)
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 50a15fa8cf98..efb66db04f99 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -629,23 +629,28 @@ void nfs_close_context(struct nfs_open_context *ctx, int is_sync)
629 nfs_revalidate_inode(server, inode); 629 nfs_revalidate_inode(server, inode);
630} 630}
631 631
632struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, struct rpc_cred *cred, fmode_t f_mode) 632struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode)
633{ 633{
634 struct nfs_open_context *ctx; 634 struct nfs_open_context *ctx;
635 struct rpc_cred *cred = rpc_lookup_cred();
636 if (IS_ERR(cred))
637 return ERR_CAST(cred);
635 638
636 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); 639 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
637 if (ctx != NULL) { 640 if (!ctx) {
638 nfs_sb_active(dentry->d_sb); 641 put_rpccred(cred);
639 ctx->dentry = dget(dentry); 642 return ERR_PTR(-ENOMEM);
640 ctx->cred = get_rpccred(cred);
641 ctx->state = NULL;
642 ctx->mode = f_mode;
643 ctx->flags = 0;
644 ctx->error = 0;
645 nfs_init_lock_context(&ctx->lock_context);
646 ctx->lock_context.open_context = ctx;
647 INIT_LIST_HEAD(&ctx->list);
648 } 643 }
644 nfs_sb_active(dentry->d_sb);
645 ctx->dentry = dget(dentry);
646 ctx->cred = cred;
647 ctx->state = NULL;
648 ctx->mode = f_mode;
649 ctx->flags = 0;
650 ctx->error = 0;
651 nfs_init_lock_context(&ctx->lock_context);
652 ctx->lock_context.open_context = ctx;
653 INIT_LIST_HEAD(&ctx->list);
649 return ctx; 654 return ctx;
650} 655}
651 656
@@ -738,15 +743,10 @@ static void nfs_file_clear_open_context(struct file *filp)
738int nfs_open(struct inode *inode, struct file *filp) 743int nfs_open(struct inode *inode, struct file *filp)
739{ 744{
740 struct nfs_open_context *ctx; 745 struct nfs_open_context *ctx;
741 struct rpc_cred *cred;
742 746
743 cred = rpc_lookup_cred(); 747 ctx = alloc_nfs_open_context(filp->f_path.dentry, filp->f_mode);
744 if (IS_ERR(cred)) 748 if (IS_ERR(ctx))
745 return PTR_ERR(cred); 749 return PTR_ERR(ctx);
746 ctx = alloc_nfs_open_context(filp->f_path.dentry, cred, filp->f_mode);
747 put_rpccred(cred);
748 if (ctx == NULL)
749 return -ENOMEM;
750 nfs_file_set_open_context(filp, ctx); 750 nfs_file_set_open_context(filp, ctx);
751 put_nfs_open_context(ctx); 751 put_nfs_open_context(ctx);
752 nfs_fscache_set_inode_cookie(inode, filp); 752 nfs_fscache_set_inode_cookie(inode, filp);
diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h
index 92ecf5585fac..8c29950d2fa5 100644
--- a/include/linux/nfs_fs.h
+++ b/include/linux/nfs_fs.h
@@ -373,7 +373,7 @@ extern void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr);
373extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx); 373extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx);
374extern void put_nfs_open_context(struct nfs_open_context *ctx); 374extern void put_nfs_open_context(struct nfs_open_context *ctx);
375extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, fmode_t mode); 375extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, fmode_t mode);
376extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, struct rpc_cred *cred, fmode_t f_mode); 376extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode);
377extern void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx); 377extern void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx);
378extern struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx); 378extern struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx);
379extern void nfs_put_lock_context(struct nfs_lock_context *l_ctx); 379extern void nfs_put_lock_context(struct nfs_lock_context *l_ctx);