blob: b382809726d8d67f6db6092f7bc30248d2569f14 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Beerd51fe1b2005-09-02 08:59:25 +02006 * and fs/sysfs/inode.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * Copyright (c) 2002, Trond Myklebust <trond.myklebust@fys.uio.no>
9 *
10 */
11#include <linux/config.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/string.h>
15#include <linux/pagemap.h>
16#include <linux/mount.h>
17#include <linux/namei.h>
18#include <linux/dnotify.h>
19#include <linux/kernel.h>
20
21#include <asm/ioctls.h>
22#include <linux/fs.h>
23#include <linux/poll.h>
24#include <linux/wait.h>
25#include <linux/seq_file.h>
26
27#include <linux/sunrpc/clnt.h>
28#include <linux/workqueue.h>
29#include <linux/sunrpc/rpc_pipe_fs.h>
30
Eric Dumazetba899662005-08-26 12:05:31 -070031static struct vfsmount *rpc_mount __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032static int rpc_mount_count;
33
34static struct file_system_type rpc_pipe_fs_type;
35
36
Eric Dumazetba899662005-08-26 12:05:31 -070037static kmem_cache_t *rpc_inode_cachep __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39#define RPC_UPCALL_TIMEOUT (30*HZ)
40
41static void
42__rpc_purge_upcall(struct inode *inode, int err)
43{
44 struct rpc_inode *rpci = RPC_I(inode);
45 struct rpc_pipe_msg *msg;
46
47 while (!list_empty(&rpci->pipe)) {
48 msg = list_entry(rpci->pipe.next, struct rpc_pipe_msg, list);
49 list_del_init(&msg->list);
50 msg->errno = err;
51 rpci->ops->destroy_msg(msg);
52 }
53 while (!list_empty(&rpci->in_upcall)) {
54 msg = list_entry(rpci->pipe.next, struct rpc_pipe_msg, list);
55 list_del_init(&msg->list);
56 msg->errno = err;
57 rpci->ops->destroy_msg(msg);
58 }
59 rpci->pipelen = 0;
60 wake_up(&rpci->waitq);
61}
62
63static void
64rpc_timeout_upcall_queue(void *data)
65{
66 struct rpc_inode *rpci = (struct rpc_inode *)data;
67 struct inode *inode = &rpci->vfs_inode;
68
69 down(&inode->i_sem);
70 if (rpci->nreaders == 0 && !list_empty(&rpci->pipe))
71 __rpc_purge_upcall(inode, -ETIMEDOUT);
72 up(&inode->i_sem);
73}
74
75int
76rpc_queue_upcall(struct inode *inode, struct rpc_pipe_msg *msg)
77{
78 struct rpc_inode *rpci = RPC_I(inode);
79 int res = 0;
80
81 down(&inode->i_sem);
82 if (rpci->nreaders) {
83 list_add_tail(&msg->list, &rpci->pipe);
84 rpci->pipelen += msg->len;
85 } else if (rpci->flags & RPC_PIPE_WAIT_FOR_OPEN) {
86 if (list_empty(&rpci->pipe))
87 schedule_delayed_work(&rpci->queue_timeout,
88 RPC_UPCALL_TIMEOUT);
89 list_add_tail(&msg->list, &rpci->pipe);
90 rpci->pipelen += msg->len;
91 } else
92 res = -EPIPE;
93 up(&inode->i_sem);
94 wake_up(&rpci->waitq);
95 return res;
96}
97
98static void
99rpc_close_pipes(struct inode *inode)
100{
101 struct rpc_inode *rpci = RPC_I(inode);
102
103 cancel_delayed_work(&rpci->queue_timeout);
104 flush_scheduled_work();
105 down(&inode->i_sem);
106 if (rpci->ops != NULL) {
107 rpci->nreaders = 0;
108 __rpc_purge_upcall(inode, -EPIPE);
109 rpci->nwriters = 0;
110 if (rpci->ops->release_pipe)
111 rpci->ops->release_pipe(inode);
112 rpci->ops = NULL;
113 }
114 up(&inode->i_sem);
115}
116
117static inline void
118rpc_inode_setowner(struct inode *inode, void *private)
119{
120 RPC_I(inode)->private = private;
121}
122
123static struct inode *
124rpc_alloc_inode(struct super_block *sb)
125{
126 struct rpc_inode *rpci;
127 rpci = (struct rpc_inode *)kmem_cache_alloc(rpc_inode_cachep, SLAB_KERNEL);
128 if (!rpci)
129 return NULL;
130 return &rpci->vfs_inode;
131}
132
133static void
134rpc_destroy_inode(struct inode *inode)
135{
136 kmem_cache_free(rpc_inode_cachep, RPC_I(inode));
137}
138
139static int
140rpc_pipe_open(struct inode *inode, struct file *filp)
141{
142 struct rpc_inode *rpci = RPC_I(inode);
143 int res = -ENXIO;
144
145 down(&inode->i_sem);
146 if (rpci->ops != NULL) {
147 if (filp->f_mode & FMODE_READ)
148 rpci->nreaders ++;
149 if (filp->f_mode & FMODE_WRITE)
150 rpci->nwriters ++;
151 res = 0;
152 }
153 up(&inode->i_sem);
154 return res;
155}
156
157static int
158rpc_pipe_release(struct inode *inode, struct file *filp)
159{
160 struct rpc_inode *rpci = RPC_I(filp->f_dentry->d_inode);
161 struct rpc_pipe_msg *msg;
162
163 down(&inode->i_sem);
164 if (rpci->ops == NULL)
165 goto out;
166 msg = (struct rpc_pipe_msg *)filp->private_data;
167 if (msg != NULL) {
168 msg->errno = -EPIPE;
169 list_del_init(&msg->list);
170 rpci->ops->destroy_msg(msg);
171 }
172 if (filp->f_mode & FMODE_WRITE)
173 rpci->nwriters --;
174 if (filp->f_mode & FMODE_READ)
175 rpci->nreaders --;
176 if (!rpci->nreaders)
177 __rpc_purge_upcall(inode, -EPIPE);
178 if (rpci->ops->release_pipe)
179 rpci->ops->release_pipe(inode);
180out:
181 up(&inode->i_sem);
182 return 0;
183}
184
185static ssize_t
186rpc_pipe_read(struct file *filp, char __user *buf, size_t len, loff_t *offset)
187{
188 struct inode *inode = filp->f_dentry->d_inode;
189 struct rpc_inode *rpci = RPC_I(inode);
190 struct rpc_pipe_msg *msg;
191 int res = 0;
192
193 down(&inode->i_sem);
194 if (rpci->ops == NULL) {
195 res = -EPIPE;
196 goto out_unlock;
197 }
198 msg = filp->private_data;
199 if (msg == NULL) {
200 if (!list_empty(&rpci->pipe)) {
201 msg = list_entry(rpci->pipe.next,
202 struct rpc_pipe_msg,
203 list);
204 list_move(&msg->list, &rpci->in_upcall);
205 rpci->pipelen -= msg->len;
206 filp->private_data = msg;
207 msg->copied = 0;
208 }
209 if (msg == NULL)
210 goto out_unlock;
211 }
212 /* NOTE: it is up to the callback to update msg->copied */
213 res = rpci->ops->upcall(filp, msg, buf, len);
214 if (res < 0 || msg->len == msg->copied) {
215 filp->private_data = NULL;
216 list_del_init(&msg->list);
217 rpci->ops->destroy_msg(msg);
218 }
219out_unlock:
220 up(&inode->i_sem);
221 return res;
222}
223
224static ssize_t
225rpc_pipe_write(struct file *filp, const char __user *buf, size_t len, loff_t *offset)
226{
227 struct inode *inode = filp->f_dentry->d_inode;
228 struct rpc_inode *rpci = RPC_I(inode);
229 int res;
230
231 down(&inode->i_sem);
232 res = -EPIPE;
233 if (rpci->ops != NULL)
234 res = rpci->ops->downcall(filp, buf, len);
235 up(&inode->i_sem);
236 return res;
237}
238
239static unsigned int
240rpc_pipe_poll(struct file *filp, struct poll_table_struct *wait)
241{
242 struct rpc_inode *rpci;
243 unsigned int mask = 0;
244
245 rpci = RPC_I(filp->f_dentry->d_inode);
246 poll_wait(filp, &rpci->waitq, wait);
247
248 mask = POLLOUT | POLLWRNORM;
249 if (rpci->ops == NULL)
250 mask |= POLLERR | POLLHUP;
251 if (!list_empty(&rpci->pipe))
252 mask |= POLLIN | POLLRDNORM;
253 return mask;
254}
255
256static int
257rpc_pipe_ioctl(struct inode *ino, struct file *filp,
258 unsigned int cmd, unsigned long arg)
259{
260 struct rpc_inode *rpci = RPC_I(filp->f_dentry->d_inode);
261 int len;
262
263 switch (cmd) {
264 case FIONREAD:
265 if (rpci->ops == NULL)
266 return -EPIPE;
267 len = rpci->pipelen;
268 if (filp->private_data) {
269 struct rpc_pipe_msg *msg;
270 msg = (struct rpc_pipe_msg *)filp->private_data;
271 len += msg->len - msg->copied;
272 }
273 return put_user(len, (int __user *)arg);
274 default:
275 return -EINVAL;
276 }
277}
278
279static struct file_operations rpc_pipe_fops = {
280 .owner = THIS_MODULE,
281 .llseek = no_llseek,
282 .read = rpc_pipe_read,
283 .write = rpc_pipe_write,
284 .poll = rpc_pipe_poll,
285 .ioctl = rpc_pipe_ioctl,
286 .open = rpc_pipe_open,
287 .release = rpc_pipe_release,
288};
289
290static int
291rpc_show_info(struct seq_file *m, void *v)
292{
293 struct rpc_clnt *clnt = m->private;
294
295 seq_printf(m, "RPC server: %s\n", clnt->cl_server);
296 seq_printf(m, "service: %s (%d) version %d\n", clnt->cl_protname,
297 clnt->cl_prog, clnt->cl_vers);
298 seq_printf(m, "address: %u.%u.%u.%u\n",
299 NIPQUAD(clnt->cl_xprt->addr.sin_addr.s_addr));
300 seq_printf(m, "protocol: %s\n",
301 clnt->cl_xprt->prot == IPPROTO_UDP ? "udp" : "tcp");
302 return 0;
303}
304
305static int
306rpc_info_open(struct inode *inode, struct file *file)
307{
308 struct rpc_clnt *clnt;
309 int ret = single_open(file, rpc_show_info, NULL);
310
311 if (!ret) {
312 struct seq_file *m = file->private_data;
313 down(&inode->i_sem);
314 clnt = RPC_I(inode)->private;
315 if (clnt) {
316 atomic_inc(&clnt->cl_users);
317 m->private = clnt;
318 } else {
319 single_release(inode, file);
320 ret = -EINVAL;
321 }
322 up(&inode->i_sem);
323 }
324 return ret;
325}
326
327static int
328rpc_info_release(struct inode *inode, struct file *file)
329{
330 struct seq_file *m = file->private_data;
331 struct rpc_clnt *clnt = (struct rpc_clnt *)m->private;
332
333 if (clnt)
334 rpc_release_client(clnt);
335 return single_release(inode, file);
336}
337
338static struct file_operations rpc_info_operations = {
339 .owner = THIS_MODULE,
340 .open = rpc_info_open,
341 .read = seq_read,
342 .llseek = seq_lseek,
343 .release = rpc_info_release,
344};
345
346
347/*
348 * We have a single directory with 1 node in it.
349 */
350enum {
351 RPCAUTH_Root = 1,
352 RPCAUTH_lockd,
353 RPCAUTH_mount,
354 RPCAUTH_nfs,
355 RPCAUTH_portmap,
356 RPCAUTH_statd,
357 RPCAUTH_RootEOF
358};
359
360/*
361 * Description of fs contents.
362 */
363struct rpc_filelist {
364 char *name;
365 struct file_operations *i_fop;
366 int mode;
367};
368
369static struct rpc_filelist files[] = {
370 [RPCAUTH_lockd] = {
371 .name = "lockd",
372 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
373 },
374 [RPCAUTH_mount] = {
375 .name = "mount",
376 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
377 },
378 [RPCAUTH_nfs] = {
379 .name = "nfs",
380 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
381 },
382 [RPCAUTH_portmap] = {
383 .name = "portmap",
384 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
385 },
386 [RPCAUTH_statd] = {
387 .name = "statd",
388 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
389 },
390};
391
392enum {
393 RPCAUTH_info = 2,
394 RPCAUTH_EOF
395};
396
397static struct rpc_filelist authfiles[] = {
398 [RPCAUTH_info] = {
399 .name = "info",
400 .i_fop = &rpc_info_operations,
401 .mode = S_IFREG | S_IRUSR,
402 },
403};
404
405static int
406rpc_get_mount(void)
407{
408 return simple_pin_fs("rpc_pipefs", &rpc_mount, &rpc_mount_count);
409}
410
411static void
412rpc_put_mount(void)
413{
414 simple_release_fs(&rpc_mount, &rpc_mount_count);
415}
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417static struct inode *
418rpc_get_inode(struct super_block *sb, int mode)
419{
420 struct inode *inode = new_inode(sb);
421 if (!inode)
422 return NULL;
423 inode->i_mode = mode;
424 inode->i_uid = inode->i_gid = 0;
425 inode->i_blksize = PAGE_CACHE_SIZE;
426 inode->i_blocks = 0;
427 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
428 switch(mode & S_IFMT) {
429 case S_IFDIR:
430 inode->i_fop = &simple_dir_operations;
431 inode->i_op = &simple_dir_inode_operations;
432 inode->i_nlink++;
433 default:
434 break;
435 }
436 return inode;
437}
438
439/*
440 * FIXME: This probably has races.
441 */
442static void
443rpc_depopulate(struct dentry *parent)
444{
445 struct inode *dir = parent->d_inode;
446 struct list_head *pos, *next;
447 struct dentry *dentry, *dvec[10];
448 int n = 0;
449
450 down(&dir->i_sem);
451repeat:
452 spin_lock(&dcache_lock);
453 list_for_each_safe(pos, next, &parent->d_subdirs) {
454 dentry = list_entry(pos, struct dentry, d_child);
455 spin_lock(&dentry->d_lock);
456 if (!d_unhashed(dentry)) {
457 dget_locked(dentry);
458 __d_drop(dentry);
459 spin_unlock(&dentry->d_lock);
460 dvec[n++] = dentry;
461 if (n == ARRAY_SIZE(dvec))
462 break;
463 } else
464 spin_unlock(&dentry->d_lock);
465 }
466 spin_unlock(&dcache_lock);
467 if (n) {
468 do {
469 dentry = dvec[--n];
470 if (dentry->d_inode) {
471 rpc_close_pipes(dentry->d_inode);
472 rpc_inode_setowner(dentry->d_inode, NULL);
473 simple_unlink(dir, dentry);
474 }
475 dput(dentry);
476 } while (n);
477 goto repeat;
478 }
479 up(&dir->i_sem);
480}
481
482static int
483rpc_populate(struct dentry *parent,
484 struct rpc_filelist *files,
485 int start, int eof)
486{
487 struct inode *inode, *dir = parent->d_inode;
488 void *private = RPC_I(dir)->private;
489 struct dentry *dentry;
490 int mode, i;
491
492 down(&dir->i_sem);
493 for (i = start; i < eof; i++) {
494 dentry = d_alloc_name(parent, files[i].name);
495 if (!dentry)
496 goto out_bad;
497 mode = files[i].mode;
498 inode = rpc_get_inode(dir->i_sb, mode);
499 if (!inode) {
500 dput(dentry);
501 goto out_bad;
502 }
503 inode->i_ino = i;
504 if (files[i].i_fop)
505 inode->i_fop = files[i].i_fop;
506 if (private)
507 rpc_inode_setowner(inode, private);
508 if (S_ISDIR(mode))
509 dir->i_nlink++;
510 d_add(dentry, inode);
511 }
512 up(&dir->i_sem);
513 return 0;
514out_bad:
515 up(&dir->i_sem);
516 printk(KERN_WARNING "%s: %s failed to populate directory %s\n",
517 __FILE__, __FUNCTION__, parent->d_name.name);
518 return -ENOMEM;
519}
520
Christoph Hellwig278c9952005-07-24 23:53:01 +0100521struct dentry *
522rpc_mkdir(struct dentry *parent, char *name, struct rpc_clnt *rpc_client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523{
Christoph Hellwig278c9952005-07-24 23:53:01 +0100524 struct inode *dir;
525 struct dentry *dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 struct inode *inode;
Christoph Hellwig278c9952005-07-24 23:53:01 +0100527 int error;
528
529 if (!parent)
530 parent = rpc_mount->mnt_root;
531
532 dir = parent->d_inode;
533
534 error = rpc_get_mount();
535 if (error)
536 return ERR_PTR(error);
537
538 down(&dir->i_sem);
539 dentry = lookup_one_len(name, parent, strlen(name));
540 if (IS_ERR(dentry))
541 goto out_unlock;
542 if (dentry->d_inode) {
543 dentry = ERR_PTR(-EEXIST);
544 goto out_dput;
545 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547 inode = rpc_get_inode(dir->i_sb, S_IFDIR | S_IRUSR | S_IXUSR);
548 if (!inode)
Christoph Hellwig278c9952005-07-24 23:53:01 +0100549 goto out_dput;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 inode->i_ino = iunique(dir->i_sb, 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 dir->i_nlink++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 RPC_I(dentry->d_inode)->private = rpc_client;
Christoph Hellwig278c9952005-07-24 23:53:01 +0100553
554 d_instantiate(dentry, inode);
555 dget(dentry);
556 up(&dir->i_sem);
557
558 inode_dir_notify(dir, DN_CREATE);
559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 error = rpc_populate(dentry, authfiles,
561 RPCAUTH_info, RPCAUTH_EOF);
562 if (error)
Christoph Hellwig278c9952005-07-24 23:53:01 +0100563 goto out_depopulate;
564
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 return dentry;
Christoph Hellwig278c9952005-07-24 23:53:01 +0100566
567 out_depopulate:
568 rpc_rmdir(dentry);
569 out_dput:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 dput(dentry);
Christoph Hellwig278c9952005-07-24 23:53:01 +0100571 out_unlock:
572 up(&dir->i_sem);
573 rpc_put_mount();
574 return dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575}
576
Christoph Hellwig278c9952005-07-24 23:53:01 +0100577void
578rpc_rmdir(struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
Christoph Hellwig278c9952005-07-24 23:53:01 +0100580 struct dentry *parent = dentry->d_parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 rpc_depopulate(dentry);
Christoph Hellwig278c9952005-07-24 23:53:01 +0100583
584 down(&parent->d_inode->i_sem);
585 if (dentry->d_inode) {
586 rpc_close_pipes(dentry->d_inode);
587 rpc_inode_setowner(dentry->d_inode, NULL);
588 simple_rmdir(parent->d_inode, dentry);
589 }
590 up(&parent->d_inode->i_sem);
591
592 inode_dir_notify(parent->d_inode, DN_DELETE);
593 rpc_put_mount();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594}
595
596struct dentry *
Christoph Hellwig278c9952005-07-24 23:53:01 +0100597rpc_mkpipe(struct dentry *parent, char *name, void *private,
598 struct rpc_pipe_ops *ops, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
Christoph Hellwig278c9952005-07-24 23:53:01 +0100600 struct inode *dir = parent->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 struct dentry *dentry;
Christoph Hellwig278c9952005-07-24 23:53:01 +0100602 struct inode *inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 struct rpc_inode *rpci;
Christoph Hellwig278c9952005-07-24 23:53:01 +0100604 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Christoph Hellwig278c9952005-07-24 23:53:01 +0100606 error = rpc_get_mount();
607 if (error)
608 return ERR_PTR(error);
609
610 down(&parent->d_inode->i_sem);
611 dentry = lookup_one_len(name, parent, strlen(name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 if (IS_ERR(dentry))
Christoph Hellwig278c9952005-07-24 23:53:01 +0100613 goto out_unlock;
614 if (dentry->d_inode) {
615 dentry = ERR_PTR(-EEXIST);
616 goto out_dput;
617 }
618
619 inode = rpc_get_inode(parent->d_inode->i_sb,
620 S_IFSOCK | S_IRUSR | S_IWUSR);
621 if (!inode) {
622 dentry = ERR_PTR(-ENOMEM);
623 goto out_dput;
624 }
625
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 inode->i_ino = iunique(dir->i_sb, 100);
627 inode->i_fop = &rpc_pipe_fops;
Christoph Hellwig278c9952005-07-24 23:53:01 +0100628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 rpci = RPC_I(inode);
630 rpci->private = private;
631 rpci->flags = flags;
632 rpci->ops = ops;
Christoph Hellwig278c9952005-07-24 23:53:01 +0100633
634 d_instantiate(dentry, inode);
635 dget(dentry);
636 up(&parent->d_inode->i_sem);
637
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 inode_dir_notify(dir, DN_CREATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 return dentry;
Christoph Hellwig278c9952005-07-24 23:53:01 +0100640
641 out_dput:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 dput(dentry);
Christoph Hellwig278c9952005-07-24 23:53:01 +0100643 out_unlock:
644 up(&parent->d_inode->i_sem);
645 rpc_put_mount();
646 return dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647}
648
Christoph Hellwig278c9952005-07-24 23:53:01 +0100649void
650rpc_unlink(struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651{
Christoph Hellwig278c9952005-07-24 23:53:01 +0100652 struct dentry *parent = dentry->d_parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Christoph Hellwig278c9952005-07-24 23:53:01 +0100654 down(&parent->d_inode->i_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 if (dentry->d_inode) {
656 rpc_close_pipes(dentry->d_inode);
657 rpc_inode_setowner(dentry->d_inode, NULL);
Christoph Hellwig278c9952005-07-24 23:53:01 +0100658 simple_unlink(parent->d_inode, dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 }
Christoph Hellwig278c9952005-07-24 23:53:01 +0100660 up(&parent->d_inode->i_sem);
661
662 inode_dir_notify(parent->d_inode, DN_DELETE);
663 rpc_put_mount();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664}
665
666/*
667 * populate the filesystem
668 */
669static struct super_operations s_ops = {
670 .alloc_inode = rpc_alloc_inode,
671 .destroy_inode = rpc_destroy_inode,
672 .statfs = simple_statfs,
673};
674
675#define RPCAUTH_GSSMAGIC 0x67596969
676
677static int
678rpc_fill_super(struct super_block *sb, void *data, int silent)
679{
680 struct inode *inode;
681 struct dentry *root;
682
683 sb->s_blocksize = PAGE_CACHE_SIZE;
684 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
685 sb->s_magic = RPCAUTH_GSSMAGIC;
686 sb->s_op = &s_ops;
687 sb->s_time_gran = 1;
688
689 inode = rpc_get_inode(sb, S_IFDIR | 0755);
690 if (!inode)
691 return -ENOMEM;
692 root = d_alloc_root(inode);
693 if (!root) {
694 iput(inode);
695 return -ENOMEM;
696 }
697 if (rpc_populate(root, files, RPCAUTH_Root + 1, RPCAUTH_RootEOF))
698 goto out;
699 sb->s_root = root;
700 return 0;
701out:
702 d_genocide(root);
703 dput(root);
704 return -ENOMEM;
705}
706
707static struct super_block *
708rpc_get_sb(struct file_system_type *fs_type,
709 int flags, const char *dev_name, void *data)
710{
711 return get_sb_single(fs_type, flags, data, rpc_fill_super);
712}
713
714static struct file_system_type rpc_pipe_fs_type = {
715 .owner = THIS_MODULE,
716 .name = "rpc_pipefs",
717 .get_sb = rpc_get_sb,
718 .kill_sb = kill_litter_super,
719};
720
721static void
722init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
723{
724 struct rpc_inode *rpci = (struct rpc_inode *) foo;
725
726 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
727 SLAB_CTOR_CONSTRUCTOR) {
728 inode_init_once(&rpci->vfs_inode);
729 rpci->private = NULL;
730 rpci->nreaders = 0;
731 rpci->nwriters = 0;
732 INIT_LIST_HEAD(&rpci->in_upcall);
733 INIT_LIST_HEAD(&rpci->pipe);
734 rpci->pipelen = 0;
735 init_waitqueue_head(&rpci->waitq);
736 INIT_WORK(&rpci->queue_timeout, rpc_timeout_upcall_queue, rpci);
737 rpci->ops = NULL;
738 }
739}
740
741int register_rpc_pipefs(void)
742{
743 rpc_inode_cachep = kmem_cache_create("rpc_inode_cache",
744 sizeof(struct rpc_inode),
745 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
746 init_once, NULL);
747 if (!rpc_inode_cachep)
748 return -ENOMEM;
749 register_filesystem(&rpc_pipe_fs_type);
750 return 0;
751}
752
753void unregister_rpc_pipefs(void)
754{
755 if (kmem_cache_destroy(rpc_inode_cachep))
756 printk(KERN_WARNING "RPC: unable to free inode cache\n");
757 unregister_filesystem(&rpc_pipe_fs_type);
758}