Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

Al Viro 5ede7b1c 157e8bf8

+22 -33
+1 -12
fs/nfs/dir.c
··· 1368 1368 1369 1369 static struct nfs_open_context *create_nfs_open_context(struct dentry *dentry, int open_flags) 1370 1370 { 1371 - struct nfs_open_context *ctx; 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; 1371 + return alloc_nfs_open_context(dentry, flags_to_mode(open_flags)); 1383 1372 } 1384 1373 1385 1374 static int do_open(struct inode *inode, struct file *filp)
+20 -20
fs/nfs/inode.c
··· 629 629 nfs_revalidate_inode(server, inode); 630 630 } 631 631 632 - struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, struct rpc_cred *cred, fmode_t f_mode) 632 + struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode) 633 633 { 634 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 639 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); 637 - if (ctx != NULL) { 638 - nfs_sb_active(dentry->d_sb); 639 - ctx->dentry = dget(dentry); 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); 640 + if (!ctx) { 641 + put_rpccred(cred); 642 + return ERR_PTR(-ENOMEM); 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 654 return ctx; 650 655 } 651 656 ··· 743 738 int nfs_open(struct inode *inode, struct file *filp) 744 739 { 745 740 struct nfs_open_context *ctx; 746 - struct rpc_cred *cred; 747 741 748 - cred = rpc_lookup_cred(); 749 - if (IS_ERR(cred)) 750 - return PTR_ERR(cred); 751 - ctx = alloc_nfs_open_context(filp->f_path.dentry, cred, filp->f_mode); 752 - put_rpccred(cred); 753 - if (ctx == NULL) 754 - return -ENOMEM; 742 + ctx = alloc_nfs_open_context(filp->f_path.dentry, filp->f_mode); 743 + if (IS_ERR(ctx)) 744 + return PTR_ERR(ctx); 755 745 nfs_file_set_open_context(filp, ctx); 756 746 put_nfs_open_context(ctx); 757 747 nfs_fscache_set_inode_cookie(inode, filp);
+1 -1
include/linux/nfs_fs.h
··· 373 373 extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx); 374 374 extern void put_nfs_open_context(struct nfs_open_context *ctx); 375 375 extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, fmode_t mode); 376 - extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, struct rpc_cred *cred, fmode_t f_mode); 376 + extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode); 377 377 extern void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx); 378 378 extern struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx); 379 379 extern void nfs_put_lock_context(struct nfs_lock_context *l_ctx);