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

SUNRPC: split SUNPRC PipeFS dentry and private pipe data creation

This patch is a final step towards to removing PipeFS inode references from
kernel code other than PipeFS itself. It makes all kernel SUNRPC PipeFS users
depends on pipe private data, which state depend on their specific operations,
etc.
This patch completes SUNRPC PipeFS preparations and allows to create pipe
private data and PipeFS dentries independently.
Next step will be making SUNPRC PipeFS dentries allocated by SUNRPC PipeFS
network namespace aware routines.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>

authored by

Stanislav Kinsbursky and committed by
Trond Myklebust
c239d83b 9beae467

+108 -59
+12 -4
fs/nfs/blocklayout/blocklayout.c
··· 46 46 MODULE_AUTHOR("Andy Adamson <andros@citi.umich.edu>"); 47 47 MODULE_DESCRIPTION("The NFSv4.1 pNFS Block layout driver"); 48 48 49 - struct dentry *bl_device_pipe; 49 + struct rpc_pipe *bl_device_pipe; 50 50 wait_queue_head_t bl_wq; 51 51 52 52 static void print_page(struct page *page) ··· 1051 1051 if (ret) 1052 1052 goto out_putrpc; 1053 1053 1054 - bl_device_pipe = rpc_mkpipe(path.dentry, "blocklayout", NULL, 1055 - &bl_upcall_ops, 0); 1054 + bl_device_pipe = rpc_mkpipe_data(&bl_upcall_ops, 0); 1056 1055 path_put(&path); 1057 1056 if (IS_ERR(bl_device_pipe)) { 1058 1057 ret = PTR_ERR(bl_device_pipe); 1059 1058 goto out_putrpc; 1060 1059 } 1060 + bl_device_pipe->dentry = rpc_mkpipe_dentry(path.dentry, "blocklayout", 1061 + NULL, bl_device_pipe); 1062 + if (IS_ERR(bl_device_pipe->dentry)) { 1063 + ret = PTR_ERR(bl_device_pipe->dentry); 1064 + goto out_destroy_pipe; 1065 + } 1061 1066 out: 1062 1067 return ret; 1063 1068 1069 + out_destroy_pipe: 1070 + rpc_destroy_pipe_data(bl_device_pipe); 1064 1071 out_putrpc: 1065 1072 rpc_put_mount(); 1066 1073 out_remove: ··· 1081 1074 __func__); 1082 1075 1083 1076 pnfs_unregister_layoutdriver(&blocklayout_type); 1084 - rpc_unlink(bl_device_pipe); 1077 + rpc_unlink(bl_device_pipe->dentry); 1078 + rpc_destroy_pipe_data(bl_device_pipe); 1085 1079 rpc_put_mount(); 1086 1080 } 1087 1081
+1 -1
fs/nfs/blocklayout/blocklayout.h
··· 161 161 u16 totallen; /* length of entire message, including hdr itself */ 162 162 }; 163 163 164 - extern struct dentry *bl_device_pipe; 164 + extern struct rpc_pipe *bl_device_pipe; 165 165 extern wait_queue_head_t bl_wq; 166 166 167 167 #define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */
+1 -1
fs/nfs/blocklayout/blocklayoutdev.c
··· 146 146 147 147 dprintk("%s CALLING USERSPACE DAEMON\n", __func__); 148 148 add_wait_queue(&bl_wq, &wq); 149 - rc = rpc_queue_upcall(RPC_I(bl_device_pipe->d_inode)->pipe, &msg); 149 + rc = rpc_queue_upcall(bl_device_pipe, &msg); 150 150 if (rc < 0) { 151 151 remove_wait_queue(&bl_wq, &wq); 152 152 rv = ERR_PTR(rc);
+1 -1
fs/nfs/blocklayout/blocklayoutdm.c
··· 66 66 msg.len = sizeof(bl_msg) + bl_msg.totallen; 67 67 68 68 add_wait_queue(&bl_wq, &wq); 69 - if (rpc_queue_upcall(RPC_I(bl_device_pipe->d_inode)->pipe, &msg) < 0) { 69 + if (rpc_queue_upcall(bl_device_pipe, &msg) < 0) { 70 70 remove_wait_queue(&bl_wq, &wq); 71 71 goto out; 72 72 }
+20 -8
fs/nfs/idmap.c
··· 410 410 }; 411 411 412 412 struct idmap { 413 - struct dentry *idmap_dentry; 413 + struct rpc_pipe *idmap_pipe; 414 414 wait_queue_head_t idmap_wq; 415 415 struct idmap_msg idmap_im; 416 416 struct mutex idmap_lock; /* Serializes upcalls */ ··· 435 435 nfs_idmap_new(struct nfs_client *clp) 436 436 { 437 437 struct idmap *idmap; 438 + struct rpc_pipe *pipe; 438 439 int error; 439 440 440 441 BUG_ON(clp->cl_idmap != NULL); ··· 444 443 if (idmap == NULL) 445 444 return -ENOMEM; 446 445 447 - idmap->idmap_dentry = rpc_mkpipe(clp->cl_rpcclient->cl_path.dentry, 448 - "idmap", idmap, &idmap_upcall_ops, 0); 449 - if (IS_ERR(idmap->idmap_dentry)) { 450 - error = PTR_ERR(idmap->idmap_dentry); 446 + pipe = rpc_mkpipe_data(&idmap_upcall_ops, 0); 447 + if (IS_ERR(pipe)) { 448 + error = PTR_ERR(pipe); 451 449 kfree(idmap); 452 450 return error; 453 451 } 454 452 453 + if (clp->cl_rpcclient->cl_path.dentry) 454 + pipe->dentry = rpc_mkpipe_dentry(clp->cl_rpcclient->cl_path.dentry, 455 + "idmap", idmap, pipe); 456 + if (IS_ERR(pipe->dentry)) { 457 + error = PTR_ERR(pipe->dentry); 458 + rpc_destroy_pipe_data(pipe); 459 + kfree(idmap); 460 + return error; 461 + } 462 + idmap->idmap_pipe = pipe; 455 463 mutex_init(&idmap->idmap_lock); 456 464 mutex_init(&idmap->idmap_im_lock); 457 465 init_waitqueue_head(&idmap->idmap_wq); ··· 478 468 479 469 if (!idmap) 480 470 return; 481 - rpc_unlink(idmap->idmap_dentry); 471 + if (idmap->idmap_pipe->dentry) 472 + rpc_unlink(idmap->idmap_pipe->dentry); 473 + rpc_destroy_pipe_data(idmap->idmap_pipe); 482 474 clp->cl_idmap = NULL; 483 475 kfree(idmap); 484 476 } ··· 601 589 msg.len = sizeof(*im); 602 590 603 591 add_wait_queue(&idmap->idmap_wq, &wq); 604 - if (rpc_queue_upcall(RPC_I(idmap->idmap_dentry->d_inode)->pipe, &msg) < 0) { 592 + if (rpc_queue_upcall(idmap->idmap_pipe, &msg) < 0) { 605 593 remove_wait_queue(&idmap->idmap_wq, &wq); 606 594 goto out; 607 595 } ··· 662 650 663 651 add_wait_queue(&idmap->idmap_wq, &wq); 664 652 665 - if (rpc_queue_upcall(RPC_I(idmap->idmap_dentry->d_inode)->pipe, &msg) < 0) { 653 + if (rpc_queue_upcall(idmap->idmap_pipe, &msg) < 0) { 666 654 remove_wait_queue(&idmap->idmap_wq, &wq); 667 655 goto out; 668 656 }
+5 -2
include/linux/sunrpc/rpc_pipe_fs.h
··· 34 34 struct delayed_work queue_timeout; 35 35 const struct rpc_pipe_ops *ops; 36 36 spinlock_t lock; 37 + struct dentry *dentry; 37 38 }; 38 39 39 40 struct rpc_inode { ··· 78 77 struct cache_detail *); 79 78 extern void rpc_remove_cache_dir(struct dentry *); 80 79 81 - extern struct dentry *rpc_mkpipe(struct dentry *, const char *, void *, 82 - const struct rpc_pipe_ops *, int flags); 80 + struct rpc_pipe *rpc_mkpipe_data(const struct rpc_pipe_ops *ops, int flags); 81 + void rpc_destroy_pipe_data(struct rpc_pipe *pipe); 82 + extern struct dentry *rpc_mkpipe_dentry(struct dentry *, const char *, void *, 83 + struct rpc_pipe *); 83 84 extern int rpc_unlink(struct dentry *); 84 85 extern struct vfsmount *rpc_get_mount(void); 85 86 extern void rpc_put_mount(void);
+36 -18
net/sunrpc/auth_gss/auth_gss.c
··· 81 81 * mechanism (for example, "krb5") and exists for 82 82 * backwards-compatibility with older gssd's. 83 83 */ 84 - struct dentry *dentry[2]; 84 + struct rpc_pipe *pipe[2]; 85 85 }; 86 86 87 87 /* pipe_version >= 0 if and only if someone has a pipe open. */ ··· 449 449 kfree(gss_msg); 450 450 return ERR_PTR(vers); 451 451 } 452 - gss_msg->pipe = RPC_I(gss_auth->dentry[vers]->d_inode)->pipe; 452 + gss_msg->pipe = gss_auth->pipe[vers]; 453 453 INIT_LIST_HEAD(&gss_msg->list); 454 454 rpc_init_wait_queue(&gss_msg->rpc_waitqueue, "RPCSEC_GSS upcall waitq"); 455 455 init_waitqueue_head(&gss_msg->waitqueue); ··· 799 799 * that we supported only the old pipe. So we instead create 800 800 * the new pipe first. 801 801 */ 802 - gss_auth->dentry[1] = rpc_mkpipe(clnt->cl_path.dentry, 803 - "gssd", 804 - clnt, &gss_upcall_ops_v1, 805 - RPC_PIPE_WAIT_FOR_OPEN); 806 - if (IS_ERR(gss_auth->dentry[1])) { 807 - err = PTR_ERR(gss_auth->dentry[1]); 802 + gss_auth->pipe[1] = rpc_mkpipe_data(&gss_upcall_ops_v1, 803 + RPC_PIPE_WAIT_FOR_OPEN); 804 + if (IS_ERR(gss_auth->pipe[1])) { 805 + err = PTR_ERR(gss_auth->pipe[1]); 808 806 goto err_put_mech; 809 807 } 810 808 811 - gss_auth->dentry[0] = rpc_mkpipe(clnt->cl_path.dentry, 812 - gss_auth->mech->gm_name, 813 - clnt, &gss_upcall_ops_v0, 814 - RPC_PIPE_WAIT_FOR_OPEN); 815 - if (IS_ERR(gss_auth->dentry[0])) { 816 - err = PTR_ERR(gss_auth->dentry[0]); 809 + gss_auth->pipe[0] = rpc_mkpipe_data(&gss_upcall_ops_v0, 810 + RPC_PIPE_WAIT_FOR_OPEN); 811 + if (IS_ERR(gss_auth->pipe[0])) { 812 + err = PTR_ERR(gss_auth->pipe[0]); 813 + goto err_destroy_pipe_1; 814 + } 815 + 816 + gss_auth->pipe[1]->dentry = rpc_mkpipe_dentry(clnt->cl_path.dentry, 817 + "gssd", 818 + clnt, gss_auth->pipe[1]); 819 + if (IS_ERR(gss_auth->pipe[1]->dentry)) { 820 + err = PTR_ERR(gss_auth->pipe[1]->dentry); 821 + goto err_destroy_pipe_0; 822 + } 823 + 824 + gss_auth->pipe[0]->dentry = rpc_mkpipe_dentry(clnt->cl_path.dentry, 825 + gss_auth->mech->gm_name, 826 + clnt, gss_auth->pipe[0]); 827 + if (IS_ERR(gss_auth->pipe[0]->dentry)) { 828 + err = PTR_ERR(gss_auth->pipe[0]->dentry); 817 829 goto err_unlink_pipe_1; 818 830 } 819 831 err = rpcauth_init_credcache(auth); ··· 834 822 835 823 return auth; 836 824 err_unlink_pipe_0: 837 - rpc_unlink(gss_auth->dentry[0]); 825 + rpc_unlink(gss_auth->pipe[0]->dentry); 838 826 err_unlink_pipe_1: 839 - rpc_unlink(gss_auth->dentry[1]); 827 + rpc_unlink(gss_auth->pipe[1]->dentry); 828 + err_destroy_pipe_0: 829 + rpc_destroy_pipe_data(gss_auth->pipe[0]); 830 + err_destroy_pipe_1: 831 + rpc_destroy_pipe_data(gss_auth->pipe[1]); 840 832 err_put_mech: 841 833 gss_mech_put(gss_auth->mech); 842 834 err_free: ··· 853 837 static void 854 838 gss_free(struct gss_auth *gss_auth) 855 839 { 856 - rpc_unlink(gss_auth->dentry[1]); 857 - rpc_unlink(gss_auth->dentry[0]); 840 + rpc_unlink(gss_auth->pipe[0]->dentry); 841 + rpc_unlink(gss_auth->pipe[1]->dentry); 842 + rpc_destroy_pipe_data(gss_auth->pipe[0]); 843 + rpc_destroy_pipe_data(gss_auth->pipe[1]); 858 844 gss_mech_put(gss_auth->mech); 859 845 860 846 kfree(gss_auth);
+32 -24
net/sunrpc/rpc_pipe.c
··· 206 206 rpc_i_callback(struct rcu_head *head) 207 207 { 208 208 struct inode *inode = container_of(head, struct inode, i_rcu); 209 - kfree(RPC_I(inode)->pipe); 210 209 kmem_cache_free(rpc_inode_cachep, RPC_I(inode)); 211 210 } 212 211 ··· 574 575 rpc_timeout_upcall_queue); 575 576 pipe->ops = NULL; 576 577 spin_lock_init(&pipe->lock); 577 - 578 + pipe->dentry = NULL; 578 579 } 579 580 580 - static int __rpc_mkpipe(struct inode *dir, struct dentry *dentry, 581 - umode_t mode, 582 - const struct file_operations *i_fop, 583 - void *private, 584 - const struct rpc_pipe_ops *ops, 585 - int flags) 581 + void rpc_destroy_pipe_data(struct rpc_pipe *pipe) 582 + { 583 + kfree(pipe); 584 + } 585 + EXPORT_SYMBOL_GPL(rpc_destroy_pipe_data); 586 + 587 + struct rpc_pipe *rpc_mkpipe_data(const struct rpc_pipe_ops *ops, int flags) 586 588 { 587 589 struct rpc_pipe *pipe; 588 - struct rpc_inode *rpci; 589 - int err; 590 590 591 591 pipe = kzalloc(sizeof(struct rpc_pipe), GFP_KERNEL); 592 592 if (!pipe) 593 - return -ENOMEM; 593 + return ERR_PTR(-ENOMEM); 594 594 init_pipe(pipe); 595 + pipe->ops = ops; 596 + pipe->flags = flags; 597 + return pipe; 598 + } 599 + EXPORT_SYMBOL_GPL(rpc_mkpipe_data); 600 + 601 + static int __rpc_mkpipe_dentry(struct inode *dir, struct dentry *dentry, 602 + umode_t mode, 603 + const struct file_operations *i_fop, 604 + void *private, 605 + struct rpc_pipe *pipe) 606 + { 607 + struct rpc_inode *rpci; 608 + int err; 609 + 595 610 err = __rpc_create_common(dir, dentry, S_IFIFO | mode, i_fop, private); 596 - if (err) { 597 - kfree(pipe); 611 + if (err) 598 612 return err; 599 - } 600 613 rpci = RPC_I(dentry->d_inode); 601 614 rpci->private = private; 602 615 rpci->pipe = pipe; 603 - rpci->pipe->flags = flags; 604 - rpci->pipe->ops = ops; 605 616 fsnotify_create(dir, dentry); 606 617 return 0; 607 618 } ··· 828 819 * The @private argument passed here will be available to all these methods 829 820 * from the file pointer, via RPC_I(file->f_dentry->d_inode)->private. 830 821 */ 831 - struct dentry *rpc_mkpipe(struct dentry *parent, const char *name, 832 - void *private, const struct rpc_pipe_ops *ops, 833 - int flags) 822 + struct dentry *rpc_mkpipe_dentry(struct dentry *parent, const char *name, 823 + void *private, struct rpc_pipe *pipe) 834 824 { 835 825 struct dentry *dentry; 836 826 struct inode *dir = parent->d_inode; ··· 837 829 struct qstr q; 838 830 int err; 839 831 840 - if (ops->upcall == NULL) 832 + if (pipe->ops->upcall == NULL) 841 833 umode &= ~S_IRUGO; 842 - if (ops->downcall == NULL) 834 + if (pipe->ops->downcall == NULL) 843 835 umode &= ~S_IWUGO; 844 836 845 837 q.name = name; ··· 850 842 dentry = __rpc_lookup_create_exclusive(parent, &q); 851 843 if (IS_ERR(dentry)) 852 844 goto out; 853 - err = __rpc_mkpipe(dir, dentry, umode, &rpc_pipe_fops, 854 - private, ops, flags); 845 + err = __rpc_mkpipe_dentry(dir, dentry, umode, &rpc_pipe_fops, 846 + private, pipe); 855 847 if (err) 856 848 goto out_err; 857 849 out: ··· 864 856 err); 865 857 goto out; 866 858 } 867 - EXPORT_SYMBOL_GPL(rpc_mkpipe); 859 + EXPORT_SYMBOL_GPL(rpc_mkpipe_dentry); 868 860 869 861 /** 870 862 * rpc_unlink - remove a pipe