Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net/sunrpc/rpc_pipe.c |
| 3 | * |
| 4 | * Userland/kernel interface for rpcauth_gss. |
| 5 | * Code shamelessly plagiarized from fs/nfsd/nfsctl.c |
Rolf Eike Beer | d51fe1b | 2005-09-02 08:59:25 +0200 | [diff] [blame] | 6 | * and fs/sysfs/inode.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * Copyright (c) 2002, Trond Myklebust <trond.myklebust@fys.uio.no> |
| 9 | * |
| 10 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/string.h> |
| 14 | #include <linux/pagemap.h> |
| 15 | #include <linux/mount.h> |
| 16 | #include <linux/namei.h> |
Trond Myklebust | 50e437d | 2007-06-07 22:44:34 -0400 | [diff] [blame] | 17 | #include <linux/fsnotify.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/kernel.h> |
| 19 | |
| 20 | #include <asm/ioctls.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/poll.h> |
| 22 | #include <linux/wait.h> |
| 23 | #include <linux/seq_file.h> |
| 24 | |
| 25 | #include <linux/sunrpc/clnt.h> |
| 26 | #include <linux/workqueue.h> |
| 27 | #include <linux/sunrpc/rpc_pipe_fs.h> |
Trond Myklebust | 8854e82 | 2009-08-09 15:14:30 -0400 | [diff] [blame] | 28 | #include <linux/sunrpc/cache.h> |
Stanislav Kinsbursky | 021c68d | 2011-12-26 15:39:04 +0300 | [diff] [blame] | 29 | #include <linux/nsproxy.h> |
Stanislav Kinsbursky | 2d00131 | 2011-12-26 15:39:13 +0300 | [diff] [blame] | 30 | #include <linux/notifier.h> |
Stanislav Kinsbursky | 021c68d | 2011-12-26 15:39:04 +0300 | [diff] [blame] | 31 | |
| 32 | #include "netns.h" |
Stanislav Kinsbursky | 2d00131 | 2011-12-26 15:39:13 +0300 | [diff] [blame] | 33 | #include "sunrpc.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Stanislav Kinsbursky | efc46bf | 2011-12-26 15:39:47 +0300 | [diff] [blame] | 35 | #define RPCDBG_FACILITY RPCDBG_DEBUG |
| 36 | |
| 37 | #define NET_NAME(net) ((net == &init_net) ? " (init_net)" : "") |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | static struct file_system_type rpc_pipe_fs_type; |
| 40 | |
| 41 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 42 | static struct kmem_cache *rpc_inode_cachep __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | #define RPC_UPCALL_TIMEOUT (30*HZ) |
| 45 | |
Stanislav Kinsbursky | 2d00131 | 2011-12-26 15:39:13 +0300 | [diff] [blame] | 46 | static BLOCKING_NOTIFIER_HEAD(rpc_pipefs_notifier_list); |
| 47 | |
| 48 | int rpc_pipefs_notifier_register(struct notifier_block *nb) |
| 49 | { |
| 50 | return blocking_notifier_chain_cond_register(&rpc_pipefs_notifier_list, nb); |
| 51 | } |
| 52 | EXPORT_SYMBOL_GPL(rpc_pipefs_notifier_register); |
| 53 | |
| 54 | void rpc_pipefs_notifier_unregister(struct notifier_block *nb) |
| 55 | { |
| 56 | blocking_notifier_chain_unregister(&rpc_pipefs_notifier_list, nb); |
| 57 | } |
| 58 | EXPORT_SYMBOL_GPL(rpc_pipefs_notifier_unregister); |
| 59 | |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 60 | static void rpc_purge_list(wait_queue_head_t *waitq, struct list_head *head, |
Trond Myklebust | 9842ef3 | 2006-02-01 12:18:44 -0500 | [diff] [blame] | 61 | void (*destroy_msg)(struct rpc_pipe_msg *), int err) |
Trond Myklebust | b3eb67a | 2005-11-25 17:10:11 -0500 | [diff] [blame] | 62 | { |
| 63 | struct rpc_pipe_msg *msg; |
Trond Myklebust | b3eb67a | 2005-11-25 17:10:11 -0500 | [diff] [blame] | 64 | |
Trond Myklebust | 9842ef3 | 2006-02-01 12:18:44 -0500 | [diff] [blame] | 65 | if (list_empty(head)) |
| 66 | return; |
| 67 | do { |
Trond Myklebust | b3eb67a | 2005-11-25 17:10:11 -0500 | [diff] [blame] | 68 | msg = list_entry(head->next, struct rpc_pipe_msg, list); |
Trond Myklebust | 5a67657 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 69 | list_del_init(&msg->list); |
Trond Myklebust | b3eb67a | 2005-11-25 17:10:11 -0500 | [diff] [blame] | 70 | msg->errno = err; |
| 71 | destroy_msg(msg); |
Trond Myklebust | 9842ef3 | 2006-02-01 12:18:44 -0500 | [diff] [blame] | 72 | } while (!list_empty(head)); |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 73 | wake_up(waitq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static void |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 77 | rpc_timeout_upcall_queue(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
Trond Myklebust | 9842ef3 | 2006-02-01 12:18:44 -0500 | [diff] [blame] | 79 | LIST_HEAD(free_list); |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 80 | struct rpc_pipe *pipe = |
| 81 | container_of(work, struct rpc_pipe, queue_timeout.work); |
Trond Myklebust | 9842ef3 | 2006-02-01 12:18:44 -0500 | [diff] [blame] | 82 | void (*destroy_msg)(struct rpc_pipe_msg *); |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 83 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 85 | spin_lock(&pipe->lock); |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 86 | destroy_msg = pipe->ops->destroy_msg; |
| 87 | if (pipe->nreaders == 0) { |
| 88 | list_splice_init(&pipe->pipe, &free_list); |
| 89 | pipe->pipelen = 0; |
Trond Myklebust | 9842ef3 | 2006-02-01 12:18:44 -0500 | [diff] [blame] | 90 | } |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 91 | dentry = dget(pipe->dentry); |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 92 | spin_unlock(&pipe->lock); |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 93 | if (dentry) { |
| 94 | rpc_purge_list(&RPC_I(dentry->d_inode)->waitq, |
| 95 | &free_list, destroy_msg, -ETIMEDOUT); |
| 96 | dput(dentry); |
| 97 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Peng Tao | c122515 | 2011-09-22 21:50:10 -0400 | [diff] [blame] | 100 | ssize_t rpc_pipe_generic_upcall(struct file *filp, struct rpc_pipe_msg *msg, |
| 101 | char __user *dst, size_t buflen) |
| 102 | { |
| 103 | char *data = (char *)msg->data + msg->copied; |
| 104 | size_t mlen = min(msg->len - msg->copied, buflen); |
| 105 | unsigned long left; |
| 106 | |
| 107 | left = copy_to_user(dst, data, mlen); |
| 108 | if (left == mlen) { |
| 109 | msg->errno = -EFAULT; |
| 110 | return -EFAULT; |
| 111 | } |
| 112 | |
| 113 | mlen -= left; |
| 114 | msg->copied += mlen; |
| 115 | msg->errno = 0; |
| 116 | return mlen; |
| 117 | } |
| 118 | EXPORT_SYMBOL_GPL(rpc_pipe_generic_upcall); |
| 119 | |
J. Bruce Fields | 93a44a7 | 2007-11-06 13:06:03 -0500 | [diff] [blame] | 120 | /** |
Ben Hutchings | 1a5778a | 2010-02-14 22:35:47 -0800 | [diff] [blame] | 121 | * rpc_queue_upcall - queue an upcall message to userspace |
J. Bruce Fields | 93a44a7 | 2007-11-06 13:06:03 -0500 | [diff] [blame] | 122 | * @inode: inode of upcall pipe on which to queue given message |
| 123 | * @msg: message to queue |
| 124 | * |
| 125 | * Call with an @inode created by rpc_mkpipe() to queue an upcall. |
| 126 | * A userspace process may then later read the upcall by performing a |
| 127 | * read on an open file for this inode. It is up to the caller to |
| 128 | * initialize the fields of @msg (other than @msg->list) appropriately. |
| 129 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | int |
Stanislav Kinsbursky | d706ed1 | 2011-12-26 15:43:49 +0300 | [diff] [blame] | 131 | rpc_queue_upcall(struct rpc_pipe *pipe, struct rpc_pipe_msg *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { |
Trond Myklebust | 6070fe6 | 2005-10-27 22:12:46 -0400 | [diff] [blame] | 133 | int res = -EPIPE; |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 134 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 136 | spin_lock(&pipe->lock); |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 137 | if (pipe->nreaders) { |
| 138 | list_add_tail(&msg->list, &pipe->pipe); |
| 139 | pipe->pipelen += msg->len; |
Trond Myklebust | 6070fe6 | 2005-10-27 22:12:46 -0400 | [diff] [blame] | 140 | res = 0; |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 141 | } else if (pipe->flags & RPC_PIPE_WAIT_FOR_OPEN) { |
| 142 | if (list_empty(&pipe->pipe)) |
Trond Myklebust | 24c5d9d | 2006-03-20 13:44:08 -0500 | [diff] [blame] | 143 | queue_delayed_work(rpciod_workqueue, |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 144 | &pipe->queue_timeout, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | RPC_UPCALL_TIMEOUT); |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 146 | list_add_tail(&msg->list, &pipe->pipe); |
| 147 | pipe->pipelen += msg->len; |
Trond Myklebust | 6070fe6 | 2005-10-27 22:12:46 -0400 | [diff] [blame] | 148 | res = 0; |
| 149 | } |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 150 | dentry = dget(pipe->dentry); |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 151 | spin_unlock(&pipe->lock); |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 152 | if (dentry) { |
| 153 | wake_up(&RPC_I(dentry->d_inode)->waitq); |
| 154 | dput(dentry); |
| 155 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | return res; |
| 157 | } |
Trond Myklebust | 468039e | 2008-12-23 15:21:31 -0500 | [diff] [blame] | 158 | EXPORT_SYMBOL_GPL(rpc_queue_upcall); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Trond Myklebust | 6070fe6 | 2005-10-27 22:12:46 -0400 | [diff] [blame] | 160 | static inline void |
| 161 | rpc_inode_setowner(struct inode *inode, void *private) |
| 162 | { |
| 163 | RPC_I(inode)->private = private; |
| 164 | } |
| 165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | static void |
| 167 | rpc_close_pipes(struct inode *inode) |
| 168 | { |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 169 | struct rpc_pipe *pipe = RPC_I(inode)->pipe; |
\"J. Bruce Fields\ | e712804 | 2008-12-23 16:09:47 -0500 | [diff] [blame] | 170 | int need_release; |
Stanislav Kinsbursky | ad6b134 | 2012-01-10 16:12:38 +0400 | [diff] [blame] | 171 | LIST_HEAD(free_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 173 | mutex_lock(&inode->i_mutex); |
Stanislav Kinsbursky | ad6b134 | 2012-01-10 16:12:38 +0400 | [diff] [blame] | 174 | spin_lock(&pipe->lock); |
| 175 | need_release = pipe->nreaders != 0 || pipe->nwriters != 0; |
| 176 | pipe->nreaders = 0; |
| 177 | list_splice_init(&pipe->in_upcall, &free_list); |
| 178 | list_splice_init(&pipe->pipe, &free_list); |
| 179 | pipe->pipelen = 0; |
| 180 | pipe->dentry = NULL; |
| 181 | spin_unlock(&pipe->lock); |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 182 | rpc_purge_list(&RPC_I(inode)->waitq, &free_list, pipe->ops->destroy_msg, -EPIPE); |
Stanislav Kinsbursky | ad6b134 | 2012-01-10 16:12:38 +0400 | [diff] [blame] | 183 | pipe->nwriters = 0; |
| 184 | if (need_release && pipe->ops->release_pipe) |
| 185 | pipe->ops->release_pipe(inode); |
| 186 | cancel_delayed_work_sync(&pipe->queue_timeout); |
Trond Myklebust | 6070fe6 | 2005-10-27 22:12:46 -0400 | [diff] [blame] | 187 | rpc_inode_setowner(inode, NULL); |
Stanislav Kinsbursky | 2c9030e | 2012-02-27 22:05:45 +0400 | [diff] [blame] | 188 | RPC_I(inode)->pipe = NULL; |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 189 | mutex_unlock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | static struct inode * |
| 193 | rpc_alloc_inode(struct super_block *sb) |
| 194 | { |
| 195 | struct rpc_inode *rpci; |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 196 | rpci = (struct rpc_inode *)kmem_cache_alloc(rpc_inode_cachep, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | if (!rpci) |
| 198 | return NULL; |
| 199 | return &rpci->vfs_inode; |
| 200 | } |
| 201 | |
| 202 | static void |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 203 | rpc_i_callback(struct rcu_head *head) |
| 204 | { |
| 205 | struct inode *inode = container_of(head, struct inode, i_rcu); |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 206 | kmem_cache_free(rpc_inode_cachep, RPC_I(inode)); |
| 207 | } |
| 208 | |
| 209 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | rpc_destroy_inode(struct inode *inode) |
| 211 | { |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 212 | call_rcu(&inode->i_rcu, rpc_i_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static int |
| 216 | rpc_pipe_open(struct inode *inode, struct file *filp) |
| 217 | { |
Stanislav Kinsbursky | 2c9030e | 2012-02-27 22:05:45 +0400 | [diff] [blame] | 218 | struct rpc_pipe *pipe; |
\"J. Bruce Fields\ | c381060 | 2008-12-23 16:08:32 -0500 | [diff] [blame] | 219 | int first_open; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | int res = -ENXIO; |
| 221 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 222 | mutex_lock(&inode->i_mutex); |
Stanislav Kinsbursky | 2c9030e | 2012-02-27 22:05:45 +0400 | [diff] [blame] | 223 | pipe = RPC_I(inode)->pipe; |
| 224 | if (pipe == NULL) |
\"J. Bruce Fields\ | c381060 | 2008-12-23 16:08:32 -0500 | [diff] [blame] | 225 | goto out; |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 226 | first_open = pipe->nreaders == 0 && pipe->nwriters == 0; |
| 227 | if (first_open && pipe->ops->open_pipe) { |
| 228 | res = pipe->ops->open_pipe(inode); |
\"J. Bruce Fields\ | c381060 | 2008-12-23 16:08:32 -0500 | [diff] [blame] | 229 | if (res) |
| 230 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
\"J. Bruce Fields\ | c381060 | 2008-12-23 16:08:32 -0500 | [diff] [blame] | 232 | if (filp->f_mode & FMODE_READ) |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 233 | pipe->nreaders++; |
\"J. Bruce Fields\ | c381060 | 2008-12-23 16:08:32 -0500 | [diff] [blame] | 234 | if (filp->f_mode & FMODE_WRITE) |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 235 | pipe->nwriters++; |
\"J. Bruce Fields\ | c381060 | 2008-12-23 16:08:32 -0500 | [diff] [blame] | 236 | res = 0; |
| 237 | out: |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 238 | mutex_unlock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | return res; |
| 240 | } |
| 241 | |
| 242 | static int |
| 243 | rpc_pipe_release(struct inode *inode, struct file *filp) |
| 244 | { |
Stanislav Kinsbursky | 2c9030e | 2012-02-27 22:05:45 +0400 | [diff] [blame] | 245 | struct rpc_pipe *pipe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | struct rpc_pipe_msg *msg; |
\"J. Bruce Fields\ | e712804 | 2008-12-23 16:09:47 -0500 | [diff] [blame] | 247 | int last_close; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 249 | mutex_lock(&inode->i_mutex); |
Stanislav Kinsbursky | 2c9030e | 2012-02-27 22:05:45 +0400 | [diff] [blame] | 250 | pipe = RPC_I(inode)->pipe; |
| 251 | if (pipe == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | goto out; |
Joe Perches | 655b5bb | 2010-09-04 18:52:53 -0700 | [diff] [blame] | 253 | msg = filp->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | if (msg != NULL) { |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 255 | spin_lock(&pipe->lock); |
Trond Myklebust | 48e4918 | 2005-12-19 17:11:22 -0500 | [diff] [blame] | 256 | msg->errno = -EAGAIN; |
Trond Myklebust | 5a67657 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 257 | list_del_init(&msg->list); |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 258 | spin_unlock(&pipe->lock); |
| 259 | pipe->ops->destroy_msg(msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | if (filp->f_mode & FMODE_WRITE) |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 262 | pipe->nwriters --; |
Trond Myklebust | 9842ef3 | 2006-02-01 12:18:44 -0500 | [diff] [blame] | 263 | if (filp->f_mode & FMODE_READ) { |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 264 | pipe->nreaders --; |
| 265 | if (pipe->nreaders == 0) { |
Trond Myklebust | 9842ef3 | 2006-02-01 12:18:44 -0500 | [diff] [blame] | 266 | LIST_HEAD(free_list); |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 267 | spin_lock(&pipe->lock); |
| 268 | list_splice_init(&pipe->pipe, &free_list); |
| 269 | pipe->pipelen = 0; |
| 270 | spin_unlock(&pipe->lock); |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 271 | rpc_purge_list(&RPC_I(inode)->waitq, &free_list, |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 272 | pipe->ops->destroy_msg, -EAGAIN); |
Trond Myklebust | 9842ef3 | 2006-02-01 12:18:44 -0500 | [diff] [blame] | 273 | } |
| 274 | } |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 275 | last_close = pipe->nwriters == 0 && pipe->nreaders == 0; |
| 276 | if (last_close && pipe->ops->release_pipe) |
| 277 | pipe->ops->release_pipe(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | out: |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 279 | mutex_unlock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | static ssize_t |
| 284 | rpc_pipe_read(struct file *filp, char __user *buf, size_t len, loff_t *offset) |
| 285 | { |
Josef Sipek | 303b46b | 2006-12-08 02:37:42 -0800 | [diff] [blame] | 286 | struct inode *inode = filp->f_path.dentry->d_inode; |
Stanislav Kinsbursky | 2c9030e | 2012-02-27 22:05:45 +0400 | [diff] [blame] | 287 | struct rpc_pipe *pipe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | struct rpc_pipe_msg *msg; |
| 289 | int res = 0; |
| 290 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 291 | mutex_lock(&inode->i_mutex); |
Stanislav Kinsbursky | 2c9030e | 2012-02-27 22:05:45 +0400 | [diff] [blame] | 292 | pipe = RPC_I(inode)->pipe; |
| 293 | if (pipe == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | res = -EPIPE; |
| 295 | goto out_unlock; |
| 296 | } |
| 297 | msg = filp->private_data; |
| 298 | if (msg == NULL) { |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 299 | spin_lock(&pipe->lock); |
| 300 | if (!list_empty(&pipe->pipe)) { |
| 301 | msg = list_entry(pipe->pipe.next, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | struct rpc_pipe_msg, |
| 303 | list); |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 304 | list_move(&msg->list, &pipe->in_upcall); |
| 305 | pipe->pipelen -= msg->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | filp->private_data = msg; |
| 307 | msg->copied = 0; |
| 308 | } |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 309 | spin_unlock(&pipe->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | if (msg == NULL) |
| 311 | goto out_unlock; |
| 312 | } |
| 313 | /* NOTE: it is up to the callback to update msg->copied */ |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 314 | res = pipe->ops->upcall(filp, msg, buf, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | if (res < 0 || msg->len == msg->copied) { |
| 316 | filp->private_data = NULL; |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 317 | spin_lock(&pipe->lock); |
Trond Myklebust | 5a67657 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 318 | list_del_init(&msg->list); |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 319 | spin_unlock(&pipe->lock); |
| 320 | pipe->ops->destroy_msg(msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
| 322 | out_unlock: |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 323 | mutex_unlock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | return res; |
| 325 | } |
| 326 | |
| 327 | static ssize_t |
| 328 | rpc_pipe_write(struct file *filp, const char __user *buf, size_t len, loff_t *offset) |
| 329 | { |
Josef Sipek | 303b46b | 2006-12-08 02:37:42 -0800 | [diff] [blame] | 330 | struct inode *inode = filp->f_path.dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | int res; |
| 332 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 333 | mutex_lock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | res = -EPIPE; |
Stanislav Kinsbursky | 2c9030e | 2012-02-27 22:05:45 +0400 | [diff] [blame] | 335 | if (RPC_I(inode)->pipe != NULL) |
| 336 | res = RPC_I(inode)->pipe->ops->downcall(filp, buf, len); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 337 | mutex_unlock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | return res; |
| 339 | } |
| 340 | |
| 341 | static unsigned int |
| 342 | rpc_pipe_poll(struct file *filp, struct poll_table_struct *wait) |
| 343 | { |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 344 | struct inode *inode = filp->f_path.dentry->d_inode; |
| 345 | struct rpc_inode *rpci = RPC_I(inode); |
| 346 | unsigned int mask = POLLOUT | POLLWRNORM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 348 | poll_wait(filp, &rpci->waitq, wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 350 | mutex_lock(&inode->i_mutex); |
| 351 | if (rpci->pipe == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | mask |= POLLERR | POLLHUP; |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 353 | else if (filp->private_data || !list_empty(&rpci->pipe->pipe)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | mask |= POLLIN | POLLRDNORM; |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 355 | mutex_unlock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | return mask; |
| 357 | } |
| 358 | |
Arnd Bergmann | a6f8dbc | 2010-10-04 21:18:23 +0200 | [diff] [blame] | 359 | static long |
| 360 | rpc_pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | { |
Arnd Bergmann | a6f8dbc | 2010-10-04 21:18:23 +0200 | [diff] [blame] | 362 | struct inode *inode = filp->f_path.dentry->d_inode; |
Stanislav Kinsbursky | 2c9030e | 2012-02-27 22:05:45 +0400 | [diff] [blame] | 363 | struct rpc_pipe *pipe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | int len; |
| 365 | |
| 366 | switch (cmd) { |
| 367 | case FIONREAD: |
Stanislav Kinsbursky | 2c9030e | 2012-02-27 22:05:45 +0400 | [diff] [blame] | 368 | mutex_lock(&inode->i_mutex); |
| 369 | pipe = RPC_I(inode)->pipe; |
| 370 | if (pipe == NULL) { |
| 371 | mutex_unlock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | return -EPIPE; |
Arnd Bergmann | a6f8dbc | 2010-10-04 21:18:23 +0200 | [diff] [blame] | 373 | } |
Stanislav Kinsbursky | 2c9030e | 2012-02-27 22:05:45 +0400 | [diff] [blame] | 374 | spin_lock(&pipe->lock); |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 375 | len = pipe->pipelen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | if (filp->private_data) { |
| 377 | struct rpc_pipe_msg *msg; |
Joe Perches | 655b5bb | 2010-09-04 18:52:53 -0700 | [diff] [blame] | 378 | msg = filp->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | len += msg->len - msg->copied; |
| 380 | } |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 381 | spin_unlock(&pipe->lock); |
Stanislav Kinsbursky | 2c9030e | 2012-02-27 22:05:45 +0400 | [diff] [blame] | 382 | mutex_unlock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | return put_user(len, (int __user *)arg); |
| 384 | default: |
| 385 | return -EINVAL; |
| 386 | } |
| 387 | } |
| 388 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 389 | static const struct file_operations rpc_pipe_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | .owner = THIS_MODULE, |
| 391 | .llseek = no_llseek, |
| 392 | .read = rpc_pipe_read, |
| 393 | .write = rpc_pipe_write, |
| 394 | .poll = rpc_pipe_poll, |
Frederic Weisbecker | 674b604 | 2010-05-19 15:08:17 +0200 | [diff] [blame] | 395 | .unlocked_ioctl = rpc_pipe_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | .open = rpc_pipe_open, |
| 397 | .release = rpc_pipe_release, |
| 398 | }; |
| 399 | |
| 400 | static int |
| 401 | rpc_show_info(struct seq_file *m, void *v) |
| 402 | { |
| 403 | struct rpc_clnt *clnt = m->private; |
| 404 | |
| 405 | seq_printf(m, "RPC server: %s\n", clnt->cl_server); |
| 406 | seq_printf(m, "service: %s (%d) version %d\n", clnt->cl_protname, |
| 407 | clnt->cl_prog, clnt->cl_vers); |
Chuck Lever | e7f7865 | 2006-08-22 20:06:19 -0400 | [diff] [blame] | 408 | seq_printf(m, "address: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_ADDR)); |
| 409 | seq_printf(m, "protocol: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_PROTO)); |
J. Bruce Fields | bf19aac | 2007-09-26 14:38:09 -0400 | [diff] [blame] | 410 | seq_printf(m, "port: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_PORT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | static int |
| 415 | rpc_info_open(struct inode *inode, struct file *file) |
| 416 | { |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 417 | struct rpc_clnt *clnt = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | int ret = single_open(file, rpc_show_info, NULL); |
| 419 | |
| 420 | if (!ret) { |
| 421 | struct seq_file *m = file->private_data; |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 422 | |
| 423 | spin_lock(&file->f_path.dentry->d_lock); |
| 424 | if (!d_unhashed(file->f_path.dentry)) |
| 425 | clnt = RPC_I(inode)->private; |
| 426 | if (clnt != NULL && atomic_inc_not_zero(&clnt->cl_count)) { |
| 427 | spin_unlock(&file->f_path.dentry->d_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | m->private = clnt; |
| 429 | } else { |
Trond Myklebust | 006abe8 | 2010-09-12 19:55:25 -0400 | [diff] [blame] | 430 | spin_unlock(&file->f_path.dentry->d_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | single_release(inode, file); |
| 432 | ret = -EINVAL; |
| 433 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | return ret; |
| 436 | } |
| 437 | |
| 438 | static int |
| 439 | rpc_info_release(struct inode *inode, struct file *file) |
| 440 | { |
| 441 | struct seq_file *m = file->private_data; |
| 442 | struct rpc_clnt *clnt = (struct rpc_clnt *)m->private; |
| 443 | |
| 444 | if (clnt) |
| 445 | rpc_release_client(clnt); |
| 446 | return single_release(inode, file); |
| 447 | } |
| 448 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 449 | static const struct file_operations rpc_info_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | .owner = THIS_MODULE, |
| 451 | .open = rpc_info_open, |
| 452 | .read = seq_read, |
| 453 | .llseek = seq_lseek, |
| 454 | .release = rpc_info_release, |
| 455 | }; |
| 456 | |
| 457 | |
| 458 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | * Description of fs contents. |
| 460 | */ |
| 461 | struct rpc_filelist { |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 462 | const char *name; |
Arjan van de Ven | 99ac48f | 2006-03-28 01:56:41 -0800 | [diff] [blame] | 463 | const struct file_operations *i_fop; |
Trond Myklebust | 7364af6 | 2009-08-09 15:14:16 -0400 | [diff] [blame] | 464 | umode_t mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | }; |
| 466 | |
Nick Piggin | fe15ce4 | 2011-01-07 17:49:23 +1100 | [diff] [blame] | 467 | static int rpc_delete_dentry(const struct dentry *dentry) |
Trond Myklebust | 62e1761 | 2007-06-08 14:14:46 -0400 | [diff] [blame] | 468 | { |
| 469 | return 1; |
| 470 | } |
| 471 | |
Al Viro | 3ba13d1 | 2009-02-20 06:02:22 +0000 | [diff] [blame] | 472 | static const struct dentry_operations rpc_dentry_operations = { |
Trond Myklebust | 62e1761 | 2007-06-08 14:14:46 -0400 | [diff] [blame] | 473 | .d_delete = rpc_delete_dentry, |
| 474 | }; |
| 475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | static struct inode * |
Trond Myklebust | 7364af6 | 2009-08-09 15:14:16 -0400 | [diff] [blame] | 477 | rpc_get_inode(struct super_block *sb, umode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | { |
| 479 | struct inode *inode = new_inode(sb); |
| 480 | if (!inode) |
| 481 | return NULL; |
Christoph Hellwig | 85fe402 | 2010-10-23 11:19:54 -0400 | [diff] [blame] | 482 | inode->i_ino = get_next_ino(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | inode->i_mode = mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
Joe Perches | 89f0e4f | 2011-07-01 09:43:12 +0000 | [diff] [blame] | 485 | switch (mode & S_IFMT) { |
| 486 | case S_IFDIR: |
| 487 | inode->i_fop = &simple_dir_operations; |
| 488 | inode->i_op = &simple_dir_inode_operations; |
| 489 | inc_nlink(inode); |
| 490 | default: |
| 491 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | } |
| 493 | return inode; |
| 494 | } |
| 495 | |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 496 | static int __rpc_create_common(struct inode *dir, struct dentry *dentry, |
| 497 | umode_t mode, |
| 498 | const struct file_operations *i_fop, |
| 499 | void *private) |
| 500 | { |
| 501 | struct inode *inode; |
| 502 | |
Trond Myklebust | beb0f0a | 2010-12-20 21:19:26 +0000 | [diff] [blame] | 503 | d_drop(dentry); |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 504 | inode = rpc_get_inode(dir->i_sb, mode); |
| 505 | if (!inode) |
| 506 | goto out_err; |
| 507 | inode->i_ino = iunique(dir->i_sb, 100); |
| 508 | if (i_fop) |
| 509 | inode->i_fop = i_fop; |
| 510 | if (private) |
| 511 | rpc_inode_setowner(inode, private); |
| 512 | d_add(dentry, inode); |
| 513 | return 0; |
| 514 | out_err: |
| 515 | printk(KERN_WARNING "%s: %s failed to allocate inode for dentry %s\n", |
| 516 | __FILE__, __func__, dentry->d_name.name); |
| 517 | dput(dentry); |
| 518 | return -ENOMEM; |
| 519 | } |
| 520 | |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 521 | static int __rpc_create(struct inode *dir, struct dentry *dentry, |
| 522 | umode_t mode, |
| 523 | const struct file_operations *i_fop, |
| 524 | void *private) |
| 525 | { |
| 526 | int err; |
| 527 | |
| 528 | err = __rpc_create_common(dir, dentry, S_IFREG | mode, i_fop, private); |
| 529 | if (err) |
| 530 | return err; |
| 531 | fsnotify_create(dir, dentry); |
| 532 | return 0; |
| 533 | } |
| 534 | |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 535 | static int __rpc_mkdir(struct inode *dir, struct dentry *dentry, |
| 536 | umode_t mode, |
| 537 | const struct file_operations *i_fop, |
| 538 | void *private) |
| 539 | { |
| 540 | int err; |
| 541 | |
| 542 | err = __rpc_create_common(dir, dentry, S_IFDIR | mode, i_fop, private); |
| 543 | if (err) |
| 544 | return err; |
| 545 | inc_nlink(dir); |
| 546 | fsnotify_mkdir(dir, dentry); |
| 547 | return 0; |
| 548 | } |
| 549 | |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 550 | static void |
| 551 | init_pipe(struct rpc_pipe *pipe) |
| 552 | { |
| 553 | pipe->nreaders = 0; |
| 554 | pipe->nwriters = 0; |
| 555 | INIT_LIST_HEAD(&pipe->in_upcall); |
| 556 | INIT_LIST_HEAD(&pipe->in_downcall); |
| 557 | INIT_LIST_HEAD(&pipe->pipe); |
| 558 | pipe->pipelen = 0; |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 559 | INIT_DELAYED_WORK(&pipe->queue_timeout, |
| 560 | rpc_timeout_upcall_queue); |
| 561 | pipe->ops = NULL; |
| 562 | spin_lock_init(&pipe->lock); |
Stanislav Kinsbursky | c239d83 | 2011-12-26 15:44:06 +0300 | [diff] [blame] | 563 | pipe->dentry = NULL; |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 564 | } |
| 565 | |
Stanislav Kinsbursky | c239d83 | 2011-12-26 15:44:06 +0300 | [diff] [blame] | 566 | void rpc_destroy_pipe_data(struct rpc_pipe *pipe) |
| 567 | { |
| 568 | kfree(pipe); |
| 569 | } |
| 570 | EXPORT_SYMBOL_GPL(rpc_destroy_pipe_data); |
| 571 | |
| 572 | struct rpc_pipe *rpc_mkpipe_data(const struct rpc_pipe_ops *ops, int flags) |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 573 | { |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 574 | struct rpc_pipe *pipe; |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 575 | |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 576 | pipe = kzalloc(sizeof(struct rpc_pipe), GFP_KERNEL); |
| 577 | if (!pipe) |
Stanislav Kinsbursky | c239d83 | 2011-12-26 15:44:06 +0300 | [diff] [blame] | 578 | return ERR_PTR(-ENOMEM); |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 579 | init_pipe(pipe); |
Stanislav Kinsbursky | c239d83 | 2011-12-26 15:44:06 +0300 | [diff] [blame] | 580 | pipe->ops = ops; |
| 581 | pipe->flags = flags; |
| 582 | return pipe; |
| 583 | } |
| 584 | EXPORT_SYMBOL_GPL(rpc_mkpipe_data); |
| 585 | |
| 586 | static int __rpc_mkpipe_dentry(struct inode *dir, struct dentry *dentry, |
| 587 | umode_t mode, |
| 588 | const struct file_operations *i_fop, |
| 589 | void *private, |
| 590 | struct rpc_pipe *pipe) |
| 591 | { |
| 592 | struct rpc_inode *rpci; |
| 593 | int err; |
| 594 | |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 595 | err = __rpc_create_common(dir, dentry, S_IFIFO | mode, i_fop, private); |
Stanislav Kinsbursky | c239d83 | 2011-12-26 15:44:06 +0300 | [diff] [blame] | 596 | if (err) |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 597 | return err; |
| 598 | rpci = RPC_I(dentry->d_inode); |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 599 | rpci->private = private; |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 600 | rpci->pipe = pipe; |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 601 | fsnotify_create(dir, dentry); |
| 602 | return 0; |
| 603 | } |
| 604 | |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 605 | static int __rpc_rmdir(struct inode *dir, struct dentry *dentry) |
| 606 | { |
| 607 | int ret; |
| 608 | |
| 609 | dget(dentry); |
| 610 | ret = simple_rmdir(dir, dentry); |
| 611 | d_delete(dentry); |
| 612 | dput(dentry); |
| 613 | return ret; |
| 614 | } |
| 615 | |
Stanislav Kinsbursky | eee17325 | 2012-01-10 16:13:19 +0400 | [diff] [blame] | 616 | int rpc_rmdir(struct dentry *dentry) |
| 617 | { |
| 618 | struct dentry *parent; |
| 619 | struct inode *dir; |
| 620 | int error; |
| 621 | |
| 622 | parent = dget_parent(dentry); |
| 623 | dir = parent->d_inode; |
| 624 | mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); |
| 625 | error = __rpc_rmdir(dir, dentry); |
| 626 | mutex_unlock(&dir->i_mutex); |
| 627 | dput(parent); |
| 628 | return error; |
| 629 | } |
| 630 | EXPORT_SYMBOL_GPL(rpc_rmdir); |
| 631 | |
Trond Myklebust | 810d90b | 2009-08-09 15:14:18 -0400 | [diff] [blame] | 632 | static int __rpc_unlink(struct inode *dir, struct dentry *dentry) |
| 633 | { |
| 634 | int ret; |
| 635 | |
| 636 | dget(dentry); |
| 637 | ret = simple_unlink(dir, dentry); |
| 638 | d_delete(dentry); |
| 639 | dput(dentry); |
| 640 | return ret; |
| 641 | } |
| 642 | |
| 643 | static int __rpc_rmpipe(struct inode *dir, struct dentry *dentry) |
| 644 | { |
| 645 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 810d90b | 2009-08-09 15:14:18 -0400 | [diff] [blame] | 646 | |
Trond Myklebust | 810d90b | 2009-08-09 15:14:18 -0400 | [diff] [blame] | 647 | rpc_close_pipes(inode); |
| 648 | return __rpc_unlink(dir, dentry); |
| 649 | } |
| 650 | |
Trond Myklebust | cfeaa4a | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 651 | static struct dentry *__rpc_lookup_create_exclusive(struct dentry *parent, |
| 652 | struct qstr *name) |
| 653 | { |
| 654 | struct dentry *dentry; |
| 655 | |
Stanislav Kinsbursky | 5bff038 | 2011-11-08 15:09:19 +0300 | [diff] [blame] | 656 | dentry = d_lookup(parent, name); |
| 657 | if (!dentry) { |
| 658 | dentry = d_alloc(parent, name); |
| 659 | if (!dentry) |
| 660 | return ERR_PTR(-ENOMEM); |
| 661 | } |
| 662 | if (dentry->d_inode == NULL) { |
| 663 | d_set_d_op(dentry, &rpc_dentry_operations); |
Dan Carpenter | f1f0abe1 | 2010-03-21 12:10:34 -0400 | [diff] [blame] | 664 | return dentry; |
Stanislav Kinsbursky | 5bff038 | 2011-11-08 15:09:19 +0300 | [diff] [blame] | 665 | } |
Trond Myklebust | cfeaa4a | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 666 | dput(dentry); |
| 667 | return ERR_PTR(-EEXIST); |
| 668 | } |
| 669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | /* |
| 671 | * FIXME: This probably has races. |
| 672 | */ |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 673 | static void __rpc_depopulate(struct dentry *parent, |
| 674 | const struct rpc_filelist *files, |
| 675 | int start, int eof) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | { |
| 677 | struct inode *dir = parent->d_inode; |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 678 | struct dentry *dentry; |
| 679 | struct qstr name; |
| 680 | int i; |
| 681 | |
| 682 | for (i = start; i < eof; i++) { |
| 683 | name.name = files[i].name; |
| 684 | name.len = strlen(files[i].name); |
| 685 | name.hash = full_name_hash(name.name, name.len); |
| 686 | dentry = d_lookup(parent, &name); |
| 687 | |
| 688 | if (dentry == NULL) |
| 689 | continue; |
| 690 | if (dentry->d_inode == NULL) |
| 691 | goto next; |
| 692 | switch (dentry->d_inode->i_mode & S_IFMT) { |
| 693 | default: |
| 694 | BUG(); |
| 695 | case S_IFREG: |
| 696 | __rpc_unlink(dir, dentry); |
| 697 | break; |
| 698 | case S_IFDIR: |
| 699 | __rpc_rmdir(dir, dentry); |
| 700 | } |
| 701 | next: |
| 702 | dput(dentry); |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | static void rpc_depopulate(struct dentry *parent, |
| 707 | const struct rpc_filelist *files, |
| 708 | int start, int eof) |
| 709 | { |
| 710 | struct inode *dir = parent->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | |
Arjan van de Ven | c6573c2 | 2006-07-03 00:25:16 -0700 | [diff] [blame] | 712 | mutex_lock_nested(&dir->i_mutex, I_MUTEX_CHILD); |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 713 | __rpc_depopulate(parent, files, start, eof); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 714 | mutex_unlock(&dir->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 717 | static int rpc_populate(struct dentry *parent, |
| 718 | const struct rpc_filelist *files, |
| 719 | int start, int eof, |
| 720 | void *private) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | { |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 722 | struct inode *dir = parent->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | struct dentry *dentry; |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 724 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 726 | mutex_lock(&dir->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | for (i = start; i < eof; i++) { |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 728 | struct qstr q; |
| 729 | |
| 730 | q.name = files[i].name; |
| 731 | q.len = strlen(files[i].name); |
| 732 | q.hash = full_name_hash(q.name, q.len); |
| 733 | dentry = __rpc_lookup_create_exclusive(parent, &q); |
| 734 | err = PTR_ERR(dentry); |
| 735 | if (IS_ERR(dentry)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | goto out_bad; |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 737 | switch (files[i].mode & S_IFMT) { |
| 738 | default: |
| 739 | BUG(); |
| 740 | case S_IFREG: |
| 741 | err = __rpc_create(dir, dentry, |
| 742 | files[i].mode, |
| 743 | files[i].i_fop, |
| 744 | private); |
| 745 | break; |
| 746 | case S_IFDIR: |
| 747 | err = __rpc_mkdir(dir, dentry, |
| 748 | files[i].mode, |
| 749 | NULL, |
| 750 | private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 752 | if (err != 0) |
| 753 | goto out_bad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | } |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 755 | mutex_unlock(&dir->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | return 0; |
| 757 | out_bad: |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 758 | __rpc_depopulate(parent, files, start, eof); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 759 | mutex_unlock(&dir->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | printk(KERN_WARNING "%s: %s failed to populate directory %s\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 761 | __FILE__, __func__, parent->d_name.name); |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 762 | return err; |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 763 | } |
Christoph Hellwig | 278c995 | 2005-07-24 23:53:01 +0100 | [diff] [blame] | 764 | |
Trond Myklebust | e57aed7 | 2009-08-09 15:14:26 -0400 | [diff] [blame] | 765 | static struct dentry *rpc_mkdir_populate(struct dentry *parent, |
| 766 | struct qstr *name, umode_t mode, void *private, |
| 767 | int (*populate)(struct dentry *, void *), void *args_populate) |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 768 | { |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 769 | struct dentry *dentry; |
Trond Myklebust | 7d59d1e | 2009-08-09 15:14:23 -0400 | [diff] [blame] | 770 | struct inode *dir = parent->d_inode; |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 771 | int error; |
| 772 | |
Trond Myklebust | 7d59d1e | 2009-08-09 15:14:23 -0400 | [diff] [blame] | 773 | mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); |
| 774 | dentry = __rpc_lookup_create_exclusive(parent, name); |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 775 | if (IS_ERR(dentry)) |
Trond Myklebust | 7d59d1e | 2009-08-09 15:14:23 -0400 | [diff] [blame] | 776 | goto out; |
| 777 | error = __rpc_mkdir(dir, dentry, mode, NULL, private); |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 778 | if (error != 0) |
| 779 | goto out_err; |
Trond Myklebust | e57aed7 | 2009-08-09 15:14:26 -0400 | [diff] [blame] | 780 | if (populate != NULL) { |
| 781 | error = populate(dentry, args_populate); |
| 782 | if (error) |
| 783 | goto err_rmdir; |
| 784 | } |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 785 | out: |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 786 | mutex_unlock(&dir->i_mutex); |
Trond Myklebust | 5c3e985 | 2006-07-29 17:37:40 -0400 | [diff] [blame] | 787 | return dentry; |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 788 | err_rmdir: |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 789 | __rpc_rmdir(dir, dentry); |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 790 | out_err: |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 791 | dentry = ERR_PTR(error); |
| 792 | goto out; |
| 793 | } |
| 794 | |
Trond Myklebust | e57aed7 | 2009-08-09 15:14:26 -0400 | [diff] [blame] | 795 | static int rpc_rmdir_depopulate(struct dentry *dentry, |
| 796 | void (*depopulate)(struct dentry *)) |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 797 | { |
Trond Myklebust | dff02cc | 2006-07-31 14:17:18 -0700 | [diff] [blame] | 798 | struct dentry *parent; |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 799 | struct inode *dir; |
| 800 | int error; |
| 801 | |
Trond Myklebust | dff02cc | 2006-07-31 14:17:18 -0700 | [diff] [blame] | 802 | parent = dget_parent(dentry); |
| 803 | dir = parent->d_inode; |
Arjan van de Ven | c6573c2 | 2006-07-03 00:25:16 -0700 | [diff] [blame] | 804 | mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); |
Trond Myklebust | e57aed7 | 2009-08-09 15:14:26 -0400 | [diff] [blame] | 805 | if (depopulate != NULL) |
| 806 | depopulate(dentry); |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 807 | error = __rpc_rmdir(dir, dentry); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 808 | mutex_unlock(&dir->i_mutex); |
Trond Myklebust | dff02cc | 2006-07-31 14:17:18 -0700 | [diff] [blame] | 809 | dput(parent); |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 810 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | } |
| 812 | |
J. Bruce Fields | 93a44a7 | 2007-11-06 13:06:03 -0500 | [diff] [blame] | 813 | /** |
| 814 | * rpc_mkpipe - make an rpc_pipefs file for kernel<->userspace communication |
| 815 | * @parent: dentry of directory to create new "pipe" in |
| 816 | * @name: name of pipe |
| 817 | * @private: private data to associate with the pipe, for the caller's use |
| 818 | * @ops: operations defining the behavior of the pipe: upcall, downcall, |
\"J. Bruce Fields\ | c381060 | 2008-12-23 16:08:32 -0500 | [diff] [blame] | 819 | * release_pipe, open_pipe, and destroy_msg. |
Stanislav Kinsbursky | d0fe13b | 2011-12-26 15:43:41 +0300 | [diff] [blame] | 820 | * @flags: rpc_pipe flags |
J. Bruce Fields | 93a44a7 | 2007-11-06 13:06:03 -0500 | [diff] [blame] | 821 | * |
| 822 | * Data is made available for userspace to read by calls to |
| 823 | * rpc_queue_upcall(). The actual reads will result in calls to |
| 824 | * @ops->upcall, which will be called with the file pointer, |
| 825 | * message, and userspace buffer to copy to. |
| 826 | * |
| 827 | * Writes can come at any time, and do not necessarily have to be |
| 828 | * responses to upcalls. They will result in calls to @msg->downcall. |
| 829 | * |
| 830 | * The @private argument passed here will be available to all these methods |
| 831 | * from the file pointer, via RPC_I(file->f_dentry->d_inode)->private. |
| 832 | */ |
Stanislav Kinsbursky | c239d83 | 2011-12-26 15:44:06 +0300 | [diff] [blame] | 833 | struct dentry *rpc_mkpipe_dentry(struct dentry *parent, const char *name, |
| 834 | void *private, struct rpc_pipe *pipe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | struct dentry *dentry; |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 837 | struct inode *dir = parent->d_inode; |
Trond Myklebust | 7364af6 | 2009-08-09 15:14:16 -0400 | [diff] [blame] | 838 | umode_t umode = S_IFIFO | S_IRUSR | S_IWUSR; |
Trond Myklebust | cfeaa4a | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 839 | struct qstr q; |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 840 | int err; |
Trond Myklebust | 7364af6 | 2009-08-09 15:14:16 -0400 | [diff] [blame] | 841 | |
Stanislav Kinsbursky | c239d83 | 2011-12-26 15:44:06 +0300 | [diff] [blame] | 842 | if (pipe->ops->upcall == NULL) |
Trond Myklebust | 7364af6 | 2009-08-09 15:14:16 -0400 | [diff] [blame] | 843 | umode &= ~S_IRUGO; |
Stanislav Kinsbursky | c239d83 | 2011-12-26 15:44:06 +0300 | [diff] [blame] | 844 | if (pipe->ops->downcall == NULL) |
Trond Myklebust | 7364af6 | 2009-08-09 15:14:16 -0400 | [diff] [blame] | 845 | umode &= ~S_IWUGO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
Trond Myklebust | cfeaa4a | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 847 | q.name = name; |
| 848 | q.len = strlen(name); |
| 849 | q.hash = full_name_hash(q.name, q.len), |
| 850 | |
| 851 | mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); |
Stanislav Kinsbursky | 5bff038 | 2011-11-08 15:09:19 +0300 | [diff] [blame] | 852 | dentry = __rpc_lookup_create_exclusive(parent, &q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | if (IS_ERR(dentry)) |
Trond Myklebust | cfeaa4a | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 854 | goto out; |
Stanislav Kinsbursky | c239d83 | 2011-12-26 15:44:06 +0300 | [diff] [blame] | 855 | err = __rpc_mkpipe_dentry(dir, dentry, umode, &rpc_pipe_fops, |
| 856 | private, pipe); |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 857 | if (err) |
| 858 | goto out_err; |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 859 | out: |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 860 | mutex_unlock(&dir->i_mutex); |
Trond Myklebust | 5c3e985 | 2006-07-29 17:37:40 -0400 | [diff] [blame] | 861 | return dentry; |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 862 | out_err: |
| 863 | dentry = ERR_PTR(err); |
Trond Myklebust | 158998b | 2006-08-24 01:03:17 -0400 | [diff] [blame] | 864 | printk(KERN_WARNING "%s: %s() failed to create pipe %s/%s (errno = %d)\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 865 | __FILE__, __func__, parent->d_name.name, name, |
Trond Myklebust | 7589806 | 2009-08-09 15:14:17 -0400 | [diff] [blame] | 866 | err); |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 867 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | } |
Stanislav Kinsbursky | c239d83 | 2011-12-26 15:44:06 +0300 | [diff] [blame] | 869 | EXPORT_SYMBOL_GPL(rpc_mkpipe_dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | |
J. Bruce Fields | 93a44a7 | 2007-11-06 13:06:03 -0500 | [diff] [blame] | 871 | /** |
| 872 | * rpc_unlink - remove a pipe |
| 873 | * @dentry: dentry for the pipe, as returned from rpc_mkpipe |
| 874 | * |
| 875 | * After this call, lookups will no longer find the pipe, and any |
| 876 | * attempts to read or write using preexisting opens of the pipe will |
| 877 | * return -EPIPE. |
| 878 | */ |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 879 | int |
Trond Myklebust | 5d67476 | 2006-07-31 14:11:48 -0700 | [diff] [blame] | 880 | rpc_unlink(struct dentry *dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | { |
Trond Myklebust | 5d67476 | 2006-07-31 14:11:48 -0700 | [diff] [blame] | 882 | struct dentry *parent; |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 883 | struct inode *dir; |
Trond Myklebust | 5d67476 | 2006-07-31 14:11:48 -0700 | [diff] [blame] | 884 | int error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | |
Trond Myklebust | 5d67476 | 2006-07-31 14:11:48 -0700 | [diff] [blame] | 886 | parent = dget_parent(dentry); |
| 887 | dir = parent->d_inode; |
Arjan van de Ven | c6573c2 | 2006-07-03 00:25:16 -0700 | [diff] [blame] | 888 | mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT); |
Trond Myklebust | 810d90b | 2009-08-09 15:14:18 -0400 | [diff] [blame] | 889 | error = __rpc_rmpipe(dir, dentry); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 890 | mutex_unlock(&dir->i_mutex); |
Trond Myklebust | 5d67476 | 2006-07-31 14:11:48 -0700 | [diff] [blame] | 891 | dput(parent); |
Trond Myklebust | f134585 | 2005-09-23 11:08:25 -0400 | [diff] [blame] | 892 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | } |
Trond Myklebust | 468039e | 2008-12-23 15:21:31 -0500 | [diff] [blame] | 894 | EXPORT_SYMBOL_GPL(rpc_unlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
Trond Myklebust | e57aed7 | 2009-08-09 15:14:26 -0400 | [diff] [blame] | 896 | enum { |
| 897 | RPCAUTH_info, |
| 898 | RPCAUTH_EOF |
| 899 | }; |
| 900 | |
| 901 | static const struct rpc_filelist authfiles[] = { |
| 902 | [RPCAUTH_info] = { |
| 903 | .name = "info", |
| 904 | .i_fop = &rpc_info_operations, |
| 905 | .mode = S_IFREG | S_IRUSR, |
| 906 | }, |
| 907 | }; |
| 908 | |
| 909 | static int rpc_clntdir_populate(struct dentry *dentry, void *private) |
| 910 | { |
| 911 | return rpc_populate(dentry, |
| 912 | authfiles, RPCAUTH_info, RPCAUTH_EOF, |
| 913 | private); |
| 914 | } |
| 915 | |
| 916 | static void rpc_clntdir_depopulate(struct dentry *dentry) |
| 917 | { |
| 918 | rpc_depopulate(dentry, authfiles, RPCAUTH_info, RPCAUTH_EOF); |
| 919 | } |
| 920 | |
Trond Myklebust | 7d59d1e | 2009-08-09 15:14:23 -0400 | [diff] [blame] | 921 | /** |
| 922 | * rpc_create_client_dir - Create a new rpc_client directory in rpc_pipefs |
Randy Dunlap | 4111d4f | 2009-09-23 14:36:38 -0400 | [diff] [blame] | 923 | * @dentry: dentry from the rpc_pipefs root to the new directory |
| 924 | * @name: &struct qstr for the name |
Trond Myklebust | 7d59d1e | 2009-08-09 15:14:23 -0400 | [diff] [blame] | 925 | * @rpc_client: rpc client to associate with this directory |
| 926 | * |
| 927 | * This creates a directory at the given @path associated with |
| 928 | * @rpc_clnt, which will contain a file named "info" with some basic |
| 929 | * information about the client, together with any "pipes" that may |
| 930 | * later be created using rpc_mkpipe(). |
| 931 | */ |
Trond Myklebust | 23ac658 | 2009-08-09 15:14:25 -0400 | [diff] [blame] | 932 | struct dentry *rpc_create_client_dir(struct dentry *dentry, |
Trond Myklebust | e57aed7 | 2009-08-09 15:14:26 -0400 | [diff] [blame] | 933 | struct qstr *name, |
| 934 | struct rpc_clnt *rpc_client) |
Trond Myklebust | 7d59d1e | 2009-08-09 15:14:23 -0400 | [diff] [blame] | 935 | { |
Trond Myklebust | e57aed7 | 2009-08-09 15:14:26 -0400 | [diff] [blame] | 936 | return rpc_mkdir_populate(dentry, name, S_IRUGO | S_IXUGO, NULL, |
| 937 | rpc_clntdir_populate, rpc_client); |
| 938 | } |
| 939 | |
| 940 | /** |
| 941 | * rpc_remove_client_dir - Remove a directory created with rpc_create_client_dir() |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 942 | * @clnt: rpc client |
Trond Myklebust | e57aed7 | 2009-08-09 15:14:26 -0400 | [diff] [blame] | 943 | */ |
| 944 | int rpc_remove_client_dir(struct dentry *dentry) |
| 945 | { |
| 946 | return rpc_rmdir_depopulate(dentry, rpc_clntdir_depopulate); |
Trond Myklebust | 7d59d1e | 2009-08-09 15:14:23 -0400 | [diff] [blame] | 947 | } |
| 948 | |
Trond Myklebust | 8854e82 | 2009-08-09 15:14:30 -0400 | [diff] [blame] | 949 | static const struct rpc_filelist cache_pipefs_files[3] = { |
| 950 | [0] = { |
| 951 | .name = "channel", |
| 952 | .i_fop = &cache_file_operations_pipefs, |
Trond Myklebust | 96c61cb | 2009-08-19 18:12:21 -0400 | [diff] [blame] | 953 | .mode = S_IFREG|S_IRUSR|S_IWUSR, |
Trond Myklebust | 8854e82 | 2009-08-09 15:14:30 -0400 | [diff] [blame] | 954 | }, |
| 955 | [1] = { |
| 956 | .name = "content", |
| 957 | .i_fop = &content_file_operations_pipefs, |
| 958 | .mode = S_IFREG|S_IRUSR, |
| 959 | }, |
| 960 | [2] = { |
| 961 | .name = "flush", |
| 962 | .i_fop = &cache_flush_operations_pipefs, |
| 963 | .mode = S_IFREG|S_IRUSR|S_IWUSR, |
| 964 | }, |
| 965 | }; |
| 966 | |
| 967 | static int rpc_cachedir_populate(struct dentry *dentry, void *private) |
| 968 | { |
| 969 | return rpc_populate(dentry, |
| 970 | cache_pipefs_files, 0, 3, |
| 971 | private); |
| 972 | } |
| 973 | |
| 974 | static void rpc_cachedir_depopulate(struct dentry *dentry) |
| 975 | { |
| 976 | rpc_depopulate(dentry, cache_pipefs_files, 0, 3); |
| 977 | } |
| 978 | |
| 979 | struct dentry *rpc_create_cache_dir(struct dentry *parent, struct qstr *name, |
Al Viro | 64f1426 | 2011-07-25 00:35:13 -0400 | [diff] [blame] | 980 | umode_t umode, struct cache_detail *cd) |
Trond Myklebust | 8854e82 | 2009-08-09 15:14:30 -0400 | [diff] [blame] | 981 | { |
| 982 | return rpc_mkdir_populate(parent, name, umode, NULL, |
| 983 | rpc_cachedir_populate, cd); |
| 984 | } |
| 985 | |
| 986 | void rpc_remove_cache_dir(struct dentry *dentry) |
| 987 | { |
| 988 | rpc_rmdir_depopulate(dentry, rpc_cachedir_depopulate); |
| 989 | } |
| 990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | /* |
| 992 | * populate the filesystem |
| 993 | */ |
Alexey Dobriyan | b87221d | 2009-09-21 17:01:09 -0700 | [diff] [blame] | 994 | static const struct super_operations s_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | .alloc_inode = rpc_alloc_inode, |
| 996 | .destroy_inode = rpc_destroy_inode, |
| 997 | .statfs = simple_statfs, |
| 998 | }; |
| 999 | |
| 1000 | #define RPCAUTH_GSSMAGIC 0x67596969 |
| 1001 | |
Trond Myklebust | bb15674 | 2009-08-09 15:14:21 -0400 | [diff] [blame] | 1002 | /* |
| 1003 | * We have a single directory with 1 node in it. |
| 1004 | */ |
| 1005 | enum { |
| 1006 | RPCAUTH_lockd, |
| 1007 | RPCAUTH_mount, |
| 1008 | RPCAUTH_nfs, |
| 1009 | RPCAUTH_portmap, |
| 1010 | RPCAUTH_statd, |
| 1011 | RPCAUTH_nfsd4_cb, |
Trond Myklebust | e571cbf | 2009-08-19 18:12:27 -0400 | [diff] [blame] | 1012 | RPCAUTH_cache, |
Trond Myklebust | bb15674 | 2009-08-09 15:14:21 -0400 | [diff] [blame] | 1013 | RPCAUTH_RootEOF |
| 1014 | }; |
| 1015 | |
| 1016 | static const struct rpc_filelist files[] = { |
| 1017 | [RPCAUTH_lockd] = { |
| 1018 | .name = "lockd", |
| 1019 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, |
| 1020 | }, |
| 1021 | [RPCAUTH_mount] = { |
| 1022 | .name = "mount", |
| 1023 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, |
| 1024 | }, |
| 1025 | [RPCAUTH_nfs] = { |
| 1026 | .name = "nfs", |
| 1027 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, |
| 1028 | }, |
| 1029 | [RPCAUTH_portmap] = { |
| 1030 | .name = "portmap", |
| 1031 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, |
| 1032 | }, |
| 1033 | [RPCAUTH_statd] = { |
| 1034 | .name = "statd", |
| 1035 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, |
| 1036 | }, |
| 1037 | [RPCAUTH_nfsd4_cb] = { |
| 1038 | .name = "nfsd4_cb", |
| 1039 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, |
| 1040 | }, |
Trond Myklebust | e571cbf | 2009-08-19 18:12:27 -0400 | [diff] [blame] | 1041 | [RPCAUTH_cache] = { |
| 1042 | .name = "cache", |
| 1043 | .mode = S_IFDIR | S_IRUGO | S_IXUGO, |
| 1044 | }, |
Trond Myklebust | bb15674 | 2009-08-09 15:14:21 -0400 | [diff] [blame] | 1045 | }; |
| 1046 | |
Stanislav Kinsbursky | 432eb1a | 2011-12-26 15:39:22 +0300 | [diff] [blame] | 1047 | /* |
| 1048 | * This call can be used only in RPC pipefs mount notification hooks. |
| 1049 | */ |
| 1050 | struct dentry *rpc_d_lookup_sb(const struct super_block *sb, |
| 1051 | const unsigned char *dir_name) |
| 1052 | { |
| 1053 | struct qstr dir = { |
| 1054 | .name = dir_name, |
| 1055 | .len = strlen(dir_name), |
| 1056 | .hash = full_name_hash(dir_name, strlen(dir_name)), |
| 1057 | }; |
| 1058 | |
| 1059 | return d_lookup(sb->s_root, &dir); |
| 1060 | } |
| 1061 | EXPORT_SYMBOL_GPL(rpc_d_lookup_sb); |
| 1062 | |
Stanislav Kinsbursky | c21a588 | 2011-12-26 15:39:39 +0300 | [diff] [blame] | 1063 | void rpc_pipefs_init_net(struct net *net) |
| 1064 | { |
| 1065 | struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); |
| 1066 | |
| 1067 | mutex_init(&sn->pipefs_sb_lock); |
| 1068 | } |
| 1069 | |
| 1070 | /* |
| 1071 | * This call will be used for per network namespace operations calls. |
| 1072 | * Note: Function will be returned with pipefs_sb_lock taken if superblock was |
| 1073 | * found. This lock have to be released by rpc_put_sb_net() when all operations |
| 1074 | * will be completed. |
| 1075 | */ |
| 1076 | struct super_block *rpc_get_sb_net(const struct net *net) |
| 1077 | { |
| 1078 | struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); |
| 1079 | |
| 1080 | mutex_lock(&sn->pipefs_sb_lock); |
| 1081 | if (sn->pipefs_sb) |
| 1082 | return sn->pipefs_sb; |
| 1083 | mutex_unlock(&sn->pipefs_sb_lock); |
| 1084 | return NULL; |
| 1085 | } |
| 1086 | EXPORT_SYMBOL_GPL(rpc_get_sb_net); |
| 1087 | |
| 1088 | void rpc_put_sb_net(const struct net *net) |
| 1089 | { |
| 1090 | struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); |
| 1091 | |
| 1092 | BUG_ON(sn->pipefs_sb == NULL); |
| 1093 | mutex_unlock(&sn->pipefs_sb_lock); |
| 1094 | } |
| 1095 | EXPORT_SYMBOL_GPL(rpc_put_sb_net); |
| 1096 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | static int |
| 1098 | rpc_fill_super(struct super_block *sb, void *data, int silent) |
| 1099 | { |
| 1100 | struct inode *inode; |
| 1101 | struct dentry *root; |
Stanislav Kinsbursky | 38b0da7 | 2011-12-26 15:38:56 +0300 | [diff] [blame] | 1102 | struct net *net = data; |
Stanislav Kinsbursky | 90c4e82 | 2011-12-26 15:39:30 +0300 | [diff] [blame] | 1103 | struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); |
Stanislav Kinsbursky | 2d00131 | 2011-12-26 15:39:13 +0300 | [diff] [blame] | 1104 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | |
| 1106 | sb->s_blocksize = PAGE_CACHE_SIZE; |
| 1107 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; |
| 1108 | sb->s_magic = RPCAUTH_GSSMAGIC; |
| 1109 | sb->s_op = &s_ops; |
| 1110 | sb->s_time_gran = 1; |
| 1111 | |
| 1112 | inode = rpc_get_inode(sb, S_IFDIR | 0755); |
| 1113 | if (!inode) |
| 1114 | return -ENOMEM; |
Al Viro | fc7bed8 | 2010-01-25 18:30:38 -0500 | [diff] [blame] | 1115 | sb->s_root = root = d_alloc_root(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | if (!root) { |
| 1117 | iput(inode); |
| 1118 | return -ENOMEM; |
| 1119 | } |
Trond Myklebust | ac6fece | 2009-08-09 15:14:20 -0400 | [diff] [blame] | 1120 | if (rpc_populate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF, NULL)) |
Al Viro | fc7bed8 | 2010-01-25 18:30:38 -0500 | [diff] [blame] | 1121 | return -ENOMEM; |
Stanislav Kinsbursky | efc46bf | 2011-12-26 15:39:47 +0300 | [diff] [blame] | 1122 | dprintk("RPC: sending pipefs MOUNT notification for net %p%s\n", net, |
| 1123 | NET_NAME(net)); |
Stanislav Kinsbursky | 2d00131 | 2011-12-26 15:39:13 +0300 | [diff] [blame] | 1124 | err = blocking_notifier_call_chain(&rpc_pipefs_notifier_list, |
| 1125 | RPC_PIPEFS_MOUNT, |
| 1126 | sb); |
| 1127 | if (err) |
| 1128 | goto err_depopulate; |
Stanislav Kinsbursky | 021c68d | 2011-12-26 15:39:04 +0300 | [diff] [blame] | 1129 | sb->s_fs_info = get_net(net); |
Stanislav Kinsbursky | 90c4e82 | 2011-12-26 15:39:30 +0300 | [diff] [blame] | 1130 | sn->pipefs_sb = sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | return 0; |
Stanislav Kinsbursky | 2d00131 | 2011-12-26 15:39:13 +0300 | [diff] [blame] | 1132 | |
| 1133 | err_depopulate: |
| 1134 | blocking_notifier_call_chain(&rpc_pipefs_notifier_list, |
| 1135 | RPC_PIPEFS_UMOUNT, |
| 1136 | sb); |
| 1137 | __rpc_depopulate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF); |
| 1138 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 1141 | static struct dentry * |
| 1142 | rpc_mount(struct file_system_type *fs_type, |
| 1143 | int flags, const char *dev_name, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | { |
Stanislav Kinsbursky | 38b0da7 | 2011-12-26 15:38:56 +0300 | [diff] [blame] | 1145 | return mount_ns(fs_type, flags, current->nsproxy->net_ns, rpc_fill_super); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
Stanislav Kinsbursky | 021c68d | 2011-12-26 15:39:04 +0300 | [diff] [blame] | 1148 | void rpc_kill_sb(struct super_block *sb) |
| 1149 | { |
| 1150 | struct net *net = sb->s_fs_info; |
Stanislav Kinsbursky | 90c4e82 | 2011-12-26 15:39:30 +0300 | [diff] [blame] | 1151 | struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); |
Stanislav Kinsbursky | 021c68d | 2011-12-26 15:39:04 +0300 | [diff] [blame] | 1152 | |
Stanislav Kinsbursky | c21a588 | 2011-12-26 15:39:39 +0300 | [diff] [blame] | 1153 | mutex_lock(&sn->pipefs_sb_lock); |
Stanislav Kinsbursky | 90c4e82 | 2011-12-26 15:39:30 +0300 | [diff] [blame] | 1154 | sn->pipefs_sb = NULL; |
Stanislav Kinsbursky | c21a588 | 2011-12-26 15:39:39 +0300 | [diff] [blame] | 1155 | mutex_unlock(&sn->pipefs_sb_lock); |
Stanislav Kinsbursky | 021c68d | 2011-12-26 15:39:04 +0300 | [diff] [blame] | 1156 | put_net(net); |
Stanislav Kinsbursky | efc46bf | 2011-12-26 15:39:47 +0300 | [diff] [blame] | 1157 | dprintk("RPC: sending pipefs UMOUNT notification for net %p%s\n", net, |
| 1158 | NET_NAME(net)); |
Stanislav Kinsbursky | 2d00131 | 2011-12-26 15:39:13 +0300 | [diff] [blame] | 1159 | blocking_notifier_call_chain(&rpc_pipefs_notifier_list, |
| 1160 | RPC_PIPEFS_UMOUNT, |
| 1161 | sb); |
Stanislav Kinsbursky | 021c68d | 2011-12-26 15:39:04 +0300 | [diff] [blame] | 1162 | kill_litter_super(sb); |
| 1163 | } |
| 1164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | static struct file_system_type rpc_pipe_fs_type = { |
| 1166 | .owner = THIS_MODULE, |
| 1167 | .name = "rpc_pipefs", |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 1168 | .mount = rpc_mount, |
Stanislav Kinsbursky | 021c68d | 2011-12-26 15:39:04 +0300 | [diff] [blame] | 1169 | .kill_sb = rpc_kill_sb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | }; |
| 1171 | |
| 1172 | static void |
Alexey Dobriyan | 51cc506 | 2008-07-25 19:45:34 -0700 | [diff] [blame] | 1173 | init_once(void *foo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | { |
| 1175 | struct rpc_inode *rpci = (struct rpc_inode *) foo; |
| 1176 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 1177 | inode_init_once(&rpci->vfs_inode); |
| 1178 | rpci->private = NULL; |
Stanislav Kinsbursky | ba9e097 | 2011-12-26 15:43:32 +0300 | [diff] [blame] | 1179 | rpci->pipe = NULL; |
Stanislav Kinsbursky | 591ad7f | 2012-02-27 22:05:54 +0400 | [diff] [blame^] | 1180 | init_waitqueue_head(&rpci->waitq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | int register_rpc_pipefs(void) |
| 1184 | { |
Akinobu Mita | 5bd5f58 | 2007-05-09 02:34:51 -0700 | [diff] [blame] | 1185 | int err; |
| 1186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | rpc_inode_cachep = kmem_cache_create("rpc_inode_cache", |
Paul Jackson | fffb60f | 2006-03-24 03:16:06 -0800 | [diff] [blame] | 1188 | sizeof(struct rpc_inode), |
| 1189 | 0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT| |
| 1190 | SLAB_MEM_SPREAD), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1191 | init_once); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | if (!rpc_inode_cachep) |
| 1193 | return -ENOMEM; |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 1194 | err = rpc_clients_notifier_register(); |
| 1195 | if (err) |
| 1196 | goto err_notifier; |
Akinobu Mita | 5bd5f58 | 2007-05-09 02:34:51 -0700 | [diff] [blame] | 1197 | err = register_filesystem(&rpc_pipe_fs_type); |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 1198 | if (err) |
| 1199 | goto err_register; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | return 0; |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 1201 | |
| 1202 | err_register: |
| 1203 | rpc_clients_notifier_unregister(); |
| 1204 | err_notifier: |
| 1205 | kmem_cache_destroy(rpc_inode_cachep); |
| 1206 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | void unregister_rpc_pipefs(void) |
| 1210 | { |
Stanislav Kinsbursky | 80df9d2 | 2012-01-11 19:18:17 +0400 | [diff] [blame] | 1211 | rpc_clients_notifier_unregister(); |
Alexey Dobriyan | 1a1d92c | 2006-09-27 01:49:40 -0700 | [diff] [blame] | 1212 | kmem_cache_destroy(rpc_inode_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | unregister_filesystem(&rpc_pipe_fs_type); |
| 1214 | } |
Michal Schmidt | dcbf8c3 | 2011-07-02 00:47:12 +0200 | [diff] [blame] | 1215 | |
| 1216 | /* Make 'mount -t rpc_pipefs ...' autoload this module. */ |
| 1217 | MODULE_ALIAS("rpc_pipefs"); |