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