2 * net/sunrpc/rpc_pipe.c
4 * Userland/kernel interface for rpcauth_gss.
5 * Code shamelessly plagiarized from fs/nfsd/nfsctl.c
8 * Copyright (c) 2002, Trond Myklebust <trond.myklebust@fys.uio.no>
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>
17 #include <linux/fsnotify.h>
18 #include <linux/kernel.h>
20 #include <asm/ioctls.h>
22 #include <linux/poll.h>
23 #include <linux/wait.h>
24 #include <linux/seq_file.h>
26 #include <linux/sunrpc/clnt.h>
27 #include <linux/workqueue.h>
28 #include <linux/sunrpc/rpc_pipe_fs.h>
29 #include <linux/sunrpc/cache.h>
30 #include <linux/smp_lock.h>
32 static struct vfsmount
*rpc_mount __read_mostly
;
33 static int rpc_mount_count
;
35 static struct file_system_type rpc_pipe_fs_type
;
38 static struct kmem_cache
*rpc_inode_cachep __read_mostly
;
40 #define RPC_UPCALL_TIMEOUT (30*HZ)
42 static void rpc_purge_list(struct rpc_inode
*rpci
, struct list_head
*head
,
43 void (*destroy_msg
)(struct rpc_pipe_msg
*), int err
)
45 struct rpc_pipe_msg
*msg
;
50 msg
= list_entry(head
->next
, struct rpc_pipe_msg
, list
);
54 } while (!list_empty(head
));
55 wake_up(&rpci
->waitq
);
59 rpc_timeout_upcall_queue(struct work_struct
*work
)
62 struct rpc_inode
*rpci
=
63 container_of(work
, struct rpc_inode
, queue_timeout
.work
);
64 struct inode
*inode
= &rpci
->vfs_inode
;
65 void (*destroy_msg
)(struct rpc_pipe_msg
*);
67 spin_lock(&inode
->i_lock
);
68 if (rpci
->ops
== NULL
) {
69 spin_unlock(&inode
->i_lock
);
72 destroy_msg
= rpci
->ops
->destroy_msg
;
73 if (rpci
->nreaders
== 0) {
74 list_splice_init(&rpci
->pipe
, &free_list
);
77 spin_unlock(&inode
->i_lock
);
78 rpc_purge_list(rpci
, &free_list
, destroy_msg
, -ETIMEDOUT
);
82 * rpc_queue_upcall - queue an upcall message to userspace
83 * @inode: inode of upcall pipe on which to queue given message
84 * @msg: message to queue
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.
92 rpc_queue_upcall(struct inode
*inode
, struct rpc_pipe_msg
*msg
)
94 struct rpc_inode
*rpci
= RPC_I(inode
);
97 spin_lock(&inode
->i_lock
);
98 if (rpci
->ops
== NULL
)
100 if (rpci
->nreaders
) {
101 list_add_tail(&msg
->list
, &rpci
->pipe
);
102 rpci
->pipelen
+= msg
->len
;
104 } else if (rpci
->flags
& RPC_PIPE_WAIT_FOR_OPEN
) {
105 if (list_empty(&rpci
->pipe
))
106 queue_delayed_work(rpciod_workqueue
,
107 &rpci
->queue_timeout
,
109 list_add_tail(&msg
->list
, &rpci
->pipe
);
110 rpci
->pipelen
+= msg
->len
;
114 spin_unlock(&inode
->i_lock
);
115 wake_up(&rpci
->waitq
);
118 EXPORT_SYMBOL_GPL(rpc_queue_upcall
);
121 rpc_inode_setowner(struct inode
*inode
, void *private)
123 RPC_I(inode
)->private = private;
127 rpc_close_pipes(struct inode
*inode
)
129 struct rpc_inode
*rpci
= RPC_I(inode
);
130 const struct rpc_pipe_ops
*ops
;
133 mutex_lock(&inode
->i_mutex
);
136 LIST_HEAD(free_list
);
137 spin_lock(&inode
->i_lock
);
138 need_release
= rpci
->nreaders
!= 0 || rpci
->nwriters
!= 0;
140 list_splice_init(&rpci
->in_upcall
, &free_list
);
141 list_splice_init(&rpci
->pipe
, &free_list
);
144 spin_unlock(&inode
->i_lock
);
145 rpc_purge_list(rpci
, &free_list
, ops
->destroy_msg
, -EPIPE
);
147 if (need_release
&& ops
->release_pipe
)
148 ops
->release_pipe(inode
);
149 cancel_delayed_work_sync(&rpci
->queue_timeout
);
151 rpc_inode_setowner(inode
, NULL
);
152 mutex_unlock(&inode
->i_mutex
);
155 static struct inode
*
156 rpc_alloc_inode(struct super_block
*sb
)
158 struct rpc_inode
*rpci
;
159 rpci
= (struct rpc_inode
*)kmem_cache_alloc(rpc_inode_cachep
, GFP_KERNEL
);
162 return &rpci
->vfs_inode
;
166 rpc_destroy_inode(struct inode
*inode
)
168 kmem_cache_free(rpc_inode_cachep
, RPC_I(inode
));
172 rpc_pipe_open(struct inode
*inode
, struct file
*filp
)
174 struct rpc_inode
*rpci
= RPC_I(inode
);
178 mutex_lock(&inode
->i_mutex
);
179 if (rpci
->ops
== NULL
)
181 first_open
= rpci
->nreaders
== 0 && rpci
->nwriters
== 0;
182 if (first_open
&& rpci
->ops
->open_pipe
) {
183 res
= rpci
->ops
->open_pipe(inode
);
187 if (filp
->f_mode
& FMODE_READ
)
189 if (filp
->f_mode
& FMODE_WRITE
)
193 mutex_unlock(&inode
->i_mutex
);
198 rpc_pipe_release(struct inode
*inode
, struct file
*filp
)
200 struct rpc_inode
*rpci
= RPC_I(inode
);
201 struct rpc_pipe_msg
*msg
;
204 mutex_lock(&inode
->i_mutex
);
205 if (rpci
->ops
== NULL
)
207 msg
= (struct rpc_pipe_msg
*)filp
->private_data
;
209 spin_lock(&inode
->i_lock
);
210 msg
->errno
= -EAGAIN
;
211 list_del(&msg
->list
);
212 spin_unlock(&inode
->i_lock
);
213 rpci
->ops
->destroy_msg(msg
);
215 if (filp
->f_mode
& FMODE_WRITE
)
217 if (filp
->f_mode
& FMODE_READ
) {
219 if (rpci
->nreaders
== 0) {
220 LIST_HEAD(free_list
);
221 spin_lock(&inode
->i_lock
);
222 list_splice_init(&rpci
->pipe
, &free_list
);
224 spin_unlock(&inode
->i_lock
);
225 rpc_purge_list(rpci
, &free_list
,
226 rpci
->ops
->destroy_msg
, -EAGAIN
);
229 last_close
= rpci
->nwriters
== 0 && rpci
->nreaders
== 0;
230 if (last_close
&& rpci
->ops
->release_pipe
)
231 rpci
->ops
->release_pipe(inode
);
233 mutex_unlock(&inode
->i_mutex
);
238 rpc_pipe_read(struct file
*filp
, char __user
*buf
, size_t len
, loff_t
*offset
)
240 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
241 struct rpc_inode
*rpci
= RPC_I(inode
);
242 struct rpc_pipe_msg
*msg
;
245 mutex_lock(&inode
->i_mutex
);
246 if (rpci
->ops
== NULL
) {
250 msg
= filp
->private_data
;
252 spin_lock(&inode
->i_lock
);
253 if (!list_empty(&rpci
->pipe
)) {
254 msg
= list_entry(rpci
->pipe
.next
,
257 list_move(&msg
->list
, &rpci
->in_upcall
);
258 rpci
->pipelen
-= msg
->len
;
259 filp
->private_data
= msg
;
262 spin_unlock(&inode
->i_lock
);
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
;
270 spin_lock(&inode
->i_lock
);
271 list_del(&msg
->list
);
272 spin_unlock(&inode
->i_lock
);
273 rpci
->ops
->destroy_msg(msg
);
276 mutex_unlock(&inode
->i_mutex
);
281 rpc_pipe_write(struct file
*filp
, const char __user
*buf
, size_t len
, loff_t
*offset
)
283 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
284 struct rpc_inode
*rpci
= RPC_I(inode
);
287 mutex_lock(&inode
->i_mutex
);
289 if (rpci
->ops
!= NULL
)
290 res
= rpci
->ops
->downcall(filp
, buf
, len
);
291 mutex_unlock(&inode
->i_mutex
);
296 rpc_pipe_poll(struct file
*filp
, struct poll_table_struct
*wait
)
298 struct rpc_inode
*rpci
;
299 unsigned int mask
= 0;
301 rpci
= RPC_I(filp
->f_path
.dentry
->d_inode
);
302 poll_wait(filp
, &rpci
->waitq
, wait
);
304 mask
= POLLOUT
| POLLWRNORM
;
305 if (rpci
->ops
== NULL
)
306 mask
|= POLLERR
| POLLHUP
;
307 if (filp
->private_data
|| !list_empty(&rpci
->pipe
))
308 mask
|= POLLIN
| POLLRDNORM
;
313 rpc_pipe_ioctl_unlocked(struct file
*filp
, unsigned int cmd
, unsigned long arg
)
315 struct rpc_inode
*rpci
= RPC_I(filp
->f_path
.dentry
->d_inode
);
320 if (rpci
->ops
== NULL
)
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
;
328 return put_user(len
, (int __user
*)arg
);
335 rpc_pipe_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
)
340 ret
= rpc_pipe_ioctl_unlocked(filp
, cmd
, arg
);
346 static const struct file_operations rpc_pipe_fops
= {
347 .owner
= THIS_MODULE
,
349 .read
= rpc_pipe_read
,
350 .write
= rpc_pipe_write
,
351 .poll
= rpc_pipe_poll
,
352 .unlocked_ioctl
= rpc_pipe_ioctl
,
353 .open
= rpc_pipe_open
,
354 .release
= rpc_pipe_release
,
358 rpc_show_info(struct seq_file
*m
, void *v
)
360 struct rpc_clnt
*clnt
= m
->private;
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
);
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
));
367 seq_printf(m
, "port: %s\n", rpc_peeraddr2str(clnt
, RPC_DISPLAY_PORT
));
372 rpc_info_open(struct inode
*inode
, struct file
*file
)
374 struct rpc_clnt
*clnt
;
375 int ret
= single_open(file
, rpc_show_info
, NULL
);
378 struct seq_file
*m
= file
->private_data
;
379 mutex_lock(&inode
->i_mutex
);
380 clnt
= RPC_I(inode
)->private;
382 kref_get(&clnt
->cl_kref
);
385 single_release(inode
, file
);
388 mutex_unlock(&inode
->i_mutex
);
394 rpc_info_release(struct inode
*inode
, struct file
*file
)
396 struct seq_file
*m
= file
->private_data
;
397 struct rpc_clnt
*clnt
= (struct rpc_clnt
*)m
->private;
400 rpc_release_client(clnt
);
401 return single_release(inode
, file
);
404 static const struct file_operations rpc_info_operations
= {
405 .owner
= THIS_MODULE
,
406 .open
= rpc_info_open
,
409 .release
= rpc_info_release
,
414 * Description of fs contents.
416 struct rpc_filelist
{
418 const struct file_operations
*i_fop
;
422 struct vfsmount
*rpc_get_mount(void)
426 err
= simple_pin_fs(&rpc_pipe_fs_type
, &rpc_mount
, &rpc_mount_count
);
431 EXPORT_SYMBOL_GPL(rpc_get_mount
);
433 void rpc_put_mount(void)
435 simple_release_fs(&rpc_mount
, &rpc_mount_count
);
437 EXPORT_SYMBOL_GPL(rpc_put_mount
);
439 static int rpc_delete_dentry(struct dentry
*dentry
)
444 static const struct dentry_operations rpc_dentry_operations
= {
445 .d_delete
= rpc_delete_dentry
,
448 static struct inode
*
449 rpc_get_inode(struct super_block
*sb
, umode_t mode
)
451 struct inode
*inode
= new_inode(sb
);
454 inode
->i_mode
= mode
;
455 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
456 switch(mode
& S_IFMT
) {
458 inode
->i_fop
= &simple_dir_operations
;
459 inode
->i_op
= &simple_dir_inode_operations
;
467 static int __rpc_create_common(struct inode
*dir
, struct dentry
*dentry
,
469 const struct file_operations
*i_fop
,
474 BUG_ON(!d_unhashed(dentry
));
475 inode
= rpc_get_inode(dir
->i_sb
, mode
);
478 inode
->i_ino
= iunique(dir
->i_sb
, 100);
480 inode
->i_fop
= i_fop
;
482 rpc_inode_setowner(inode
, private);
483 d_add(dentry
, inode
);
486 printk(KERN_WARNING
"%s: %s failed to allocate inode for dentry %s\n",
487 __FILE__
, __func__
, dentry
->d_name
.name
);
492 static int __rpc_create(struct inode
*dir
, struct dentry
*dentry
,
494 const struct file_operations
*i_fop
,
499 err
= __rpc_create_common(dir
, dentry
, S_IFREG
| mode
, i_fop
, private);
502 fsnotify_create(dir
, dentry
);
506 static int __rpc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
508 const struct file_operations
*i_fop
,
513 err
= __rpc_create_common(dir
, dentry
, S_IFDIR
| mode
, i_fop
, private);
517 fsnotify_mkdir(dir
, dentry
);
521 static int __rpc_mkpipe(struct inode
*dir
, struct dentry
*dentry
,
523 const struct file_operations
*i_fop
,
525 const struct rpc_pipe_ops
*ops
,
528 struct rpc_inode
*rpci
;
531 err
= __rpc_create_common(dir
, dentry
, S_IFIFO
| mode
, i_fop
, private);
534 rpci
= RPC_I(dentry
->d_inode
);
535 rpci
->nkern_readwriters
= 1;
536 rpci
->private = private;
539 fsnotify_create(dir
, dentry
);
543 static int __rpc_rmdir(struct inode
*dir
, struct dentry
*dentry
)
548 ret
= simple_rmdir(dir
, dentry
);
554 static int __rpc_unlink(struct inode
*dir
, struct dentry
*dentry
)
559 ret
= simple_unlink(dir
, dentry
);
565 static int __rpc_rmpipe(struct inode
*dir
, struct dentry
*dentry
)
567 struct inode
*inode
= dentry
->d_inode
;
568 struct rpc_inode
*rpci
= RPC_I(inode
);
570 rpci
->nkern_readwriters
--;
571 if (rpci
->nkern_readwriters
!= 0)
573 rpc_close_pipes(inode
);
574 return __rpc_unlink(dir
, dentry
);
577 static struct dentry
*__rpc_lookup_create(struct dentry
*parent
,
580 struct dentry
*dentry
;
582 dentry
= d_lookup(parent
, name
);
584 dentry
= d_alloc(parent
, name
);
586 dentry
= ERR_PTR(-ENOMEM
);
590 if (!dentry
->d_inode
)
591 dentry
->d_op
= &rpc_dentry_operations
;
596 static struct dentry
*__rpc_lookup_create_exclusive(struct dentry
*parent
,
599 struct dentry
*dentry
;
601 dentry
= __rpc_lookup_create(parent
, name
);
604 if (dentry
->d_inode
== NULL
)
607 return ERR_PTR(-EEXIST
);
611 * FIXME: This probably has races.
613 static void __rpc_depopulate(struct dentry
*parent
,
614 const struct rpc_filelist
*files
,
617 struct inode
*dir
= parent
->d_inode
;
618 struct dentry
*dentry
;
622 for (i
= start
; i
< eof
; i
++) {
623 name
.name
= files
[i
].name
;
624 name
.len
= strlen(files
[i
].name
);
625 name
.hash
= full_name_hash(name
.name
, name
.len
);
626 dentry
= d_lookup(parent
, &name
);
630 if (dentry
->d_inode
== NULL
)
632 switch (dentry
->d_inode
->i_mode
& S_IFMT
) {
636 __rpc_unlink(dir
, dentry
);
639 __rpc_rmdir(dir
, dentry
);
646 static void rpc_depopulate(struct dentry
*parent
,
647 const struct rpc_filelist
*files
,
650 struct inode
*dir
= parent
->d_inode
;
652 mutex_lock_nested(&dir
->i_mutex
, I_MUTEX_CHILD
);
653 __rpc_depopulate(parent
, files
, start
, eof
);
654 mutex_unlock(&dir
->i_mutex
);
657 static int rpc_populate(struct dentry
*parent
,
658 const struct rpc_filelist
*files
,
662 struct inode
*dir
= parent
->d_inode
;
663 struct dentry
*dentry
;
666 mutex_lock(&dir
->i_mutex
);
667 for (i
= start
; i
< eof
; i
++) {
670 q
.name
= files
[i
].name
;
671 q
.len
= strlen(files
[i
].name
);
672 q
.hash
= full_name_hash(q
.name
, q
.len
);
673 dentry
= __rpc_lookup_create_exclusive(parent
, &q
);
674 err
= PTR_ERR(dentry
);
677 switch (files
[i
].mode
& S_IFMT
) {
681 err
= __rpc_create(dir
, dentry
,
687 err
= __rpc_mkdir(dir
, dentry
,
695 mutex_unlock(&dir
->i_mutex
);
698 __rpc_depopulate(parent
, files
, start
, eof
);
699 mutex_unlock(&dir
->i_mutex
);
700 printk(KERN_WARNING
"%s: %s failed to populate directory %s\n",
701 __FILE__
, __func__
, parent
->d_name
.name
);
705 static struct dentry
*rpc_mkdir_populate(struct dentry
*parent
,
706 struct qstr
*name
, umode_t mode
, void *private,
707 int (*populate
)(struct dentry
*, void *), void *args_populate
)
709 struct dentry
*dentry
;
710 struct inode
*dir
= parent
->d_inode
;
713 mutex_lock_nested(&dir
->i_mutex
, I_MUTEX_PARENT
);
714 dentry
= __rpc_lookup_create_exclusive(parent
, name
);
717 error
= __rpc_mkdir(dir
, dentry
, mode
, NULL
, private);
720 if (populate
!= NULL
) {
721 error
= populate(dentry
, args_populate
);
726 mutex_unlock(&dir
->i_mutex
);
729 __rpc_rmdir(dir
, dentry
);
731 dentry
= ERR_PTR(error
);
735 static int rpc_rmdir_depopulate(struct dentry
*dentry
,
736 void (*depopulate
)(struct dentry
*))
738 struct dentry
*parent
;
742 parent
= dget_parent(dentry
);
743 dir
= parent
->d_inode
;
744 mutex_lock_nested(&dir
->i_mutex
, I_MUTEX_PARENT
);
745 if (depopulate
!= NULL
)
747 error
= __rpc_rmdir(dir
, dentry
);
748 mutex_unlock(&dir
->i_mutex
);
754 * rpc_mkpipe - make an rpc_pipefs file for kernel<->userspace communication
755 * @parent: dentry of directory to create new "pipe" in
756 * @name: name of pipe
757 * @private: private data to associate with the pipe, for the caller's use
758 * @ops: operations defining the behavior of the pipe: upcall, downcall,
759 * release_pipe, open_pipe, and destroy_msg.
760 * @flags: rpc_inode flags
762 * Data is made available for userspace to read by calls to
763 * rpc_queue_upcall(). The actual reads will result in calls to
764 * @ops->upcall, which will be called with the file pointer,
765 * message, and userspace buffer to copy to.
767 * Writes can come at any time, and do not necessarily have to be
768 * responses to upcalls. They will result in calls to @msg->downcall.
770 * The @private argument passed here will be available to all these methods
771 * from the file pointer, via RPC_I(file->f_dentry->d_inode)->private.
773 struct dentry
*rpc_mkpipe(struct dentry
*parent
, const char *name
,
774 void *private, const struct rpc_pipe_ops
*ops
,
777 struct dentry
*dentry
;
778 struct inode
*dir
= parent
->d_inode
;
779 umode_t umode
= S_IFIFO
| S_IRUSR
| S_IWUSR
;
783 if (ops
->upcall
== NULL
)
785 if (ops
->downcall
== NULL
)
789 q
.len
= strlen(name
);
790 q
.hash
= full_name_hash(q
.name
, q
.len
),
792 mutex_lock_nested(&dir
->i_mutex
, I_MUTEX_PARENT
);
793 dentry
= __rpc_lookup_create(parent
, &q
);
796 if (dentry
->d_inode
) {
797 struct rpc_inode
*rpci
= RPC_I(dentry
->d_inode
);
798 if (rpci
->private != private ||
800 rpci
->flags
!= flags
) {
805 rpci
->nkern_readwriters
++;
809 err
= __rpc_mkpipe(dir
, dentry
, umode
, &rpc_pipe_fops
,
810 private, ops
, flags
);
814 mutex_unlock(&dir
->i_mutex
);
817 dentry
= ERR_PTR(err
);
818 printk(KERN_WARNING
"%s: %s() failed to create pipe %s/%s (errno = %d)\n",
819 __FILE__
, __func__
, parent
->d_name
.name
, name
,
823 EXPORT_SYMBOL_GPL(rpc_mkpipe
);
826 * rpc_unlink - remove a pipe
827 * @dentry: dentry for the pipe, as returned from rpc_mkpipe
829 * After this call, lookups will no longer find the pipe, and any
830 * attempts to read or write using preexisting opens of the pipe will
834 rpc_unlink(struct dentry
*dentry
)
836 struct dentry
*parent
;
840 parent
= dget_parent(dentry
);
841 dir
= parent
->d_inode
;
842 mutex_lock_nested(&dir
->i_mutex
, I_MUTEX_PARENT
);
843 error
= __rpc_rmpipe(dir
, dentry
);
844 mutex_unlock(&dir
->i_mutex
);
848 EXPORT_SYMBOL_GPL(rpc_unlink
);
855 static const struct rpc_filelist authfiles
[] = {
858 .i_fop
= &rpc_info_operations
,
859 .mode
= S_IFREG
| S_IRUSR
,
863 static int rpc_clntdir_populate(struct dentry
*dentry
, void *private)
865 return rpc_populate(dentry
,
866 authfiles
, RPCAUTH_info
, RPCAUTH_EOF
,
870 static void rpc_clntdir_depopulate(struct dentry
*dentry
)
872 rpc_depopulate(dentry
, authfiles
, RPCAUTH_info
, RPCAUTH_EOF
);
876 * rpc_create_client_dir - Create a new rpc_client directory in rpc_pipefs
877 * @dentry: dentry from the rpc_pipefs root to the new directory
878 * @name: &struct qstr for the name
879 * @rpc_client: rpc client to associate with this directory
881 * This creates a directory at the given @path associated with
882 * @rpc_clnt, which will contain a file named "info" with some basic
883 * information about the client, together with any "pipes" that may
884 * later be created using rpc_mkpipe().
886 struct dentry
*rpc_create_client_dir(struct dentry
*dentry
,
888 struct rpc_clnt
*rpc_client
)
890 return rpc_mkdir_populate(dentry
, name
, S_IRUGO
| S_IXUGO
, NULL
,
891 rpc_clntdir_populate
, rpc_client
);
895 * rpc_remove_client_dir - Remove a directory created with rpc_create_client_dir()
896 * @dentry: directory to remove
898 int rpc_remove_client_dir(struct dentry
*dentry
)
900 return rpc_rmdir_depopulate(dentry
, rpc_clntdir_depopulate
);
903 static const struct rpc_filelist cache_pipefs_files
[3] = {
906 .i_fop
= &cache_file_operations_pipefs
,
907 .mode
= S_IFREG
|S_IRUSR
|S_IWUSR
,
911 .i_fop
= &content_file_operations_pipefs
,
912 .mode
= S_IFREG
|S_IRUSR
,
916 .i_fop
= &cache_flush_operations_pipefs
,
917 .mode
= S_IFREG
|S_IRUSR
|S_IWUSR
,
921 static int rpc_cachedir_populate(struct dentry
*dentry
, void *private)
923 return rpc_populate(dentry
,
924 cache_pipefs_files
, 0, 3,
928 static void rpc_cachedir_depopulate(struct dentry
*dentry
)
930 rpc_depopulate(dentry
, cache_pipefs_files
, 0, 3);
933 struct dentry
*rpc_create_cache_dir(struct dentry
*parent
, struct qstr
*name
,
934 mode_t umode
, struct cache_detail
*cd
)
936 return rpc_mkdir_populate(parent
, name
, umode
, NULL
,
937 rpc_cachedir_populate
, cd
);
940 void rpc_remove_cache_dir(struct dentry
*dentry
)
942 rpc_rmdir_depopulate(dentry
, rpc_cachedir_depopulate
);
946 * populate the filesystem
948 static const struct super_operations s_ops
= {
949 .alloc_inode
= rpc_alloc_inode
,
950 .destroy_inode
= rpc_destroy_inode
,
951 .statfs
= simple_statfs
,
954 #define RPCAUTH_GSSMAGIC 0x67596969
957 * We have a single directory with 1 node in it.
970 static const struct rpc_filelist files
[] = {
973 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
977 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
981 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
983 [RPCAUTH_portmap
] = {
985 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
989 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
991 [RPCAUTH_nfsd4_cb
] = {
993 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
997 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
1002 rpc_fill_super(struct super_block
*sb
, void *data
, int silent
)
1004 struct inode
*inode
;
1005 struct dentry
*root
;
1007 sb
->s_blocksize
= PAGE_CACHE_SIZE
;
1008 sb
->s_blocksize_bits
= PAGE_CACHE_SHIFT
;
1009 sb
->s_magic
= RPCAUTH_GSSMAGIC
;
1011 sb
->s_time_gran
= 1;
1013 inode
= rpc_get_inode(sb
, S_IFDIR
| 0755);
1016 sb
->s_root
= root
= d_alloc_root(inode
);
1021 if (rpc_populate(root
, files
, RPCAUTH_lockd
, RPCAUTH_RootEOF
, NULL
))
1027 rpc_get_sb(struct file_system_type
*fs_type
,
1028 int flags
, const char *dev_name
, void *data
, struct vfsmount
*mnt
)
1030 return get_sb_single(fs_type
, flags
, data
, rpc_fill_super
, mnt
);
1033 static struct file_system_type rpc_pipe_fs_type
= {
1034 .owner
= THIS_MODULE
,
1035 .name
= "rpc_pipefs",
1036 .get_sb
= rpc_get_sb
,
1037 .kill_sb
= kill_litter_super
,
1041 init_once(void *foo
)
1043 struct rpc_inode
*rpci
= (struct rpc_inode
*) foo
;
1045 inode_init_once(&rpci
->vfs_inode
);
1046 rpci
->private = NULL
;
1049 INIT_LIST_HEAD(&rpci
->in_upcall
);
1050 INIT_LIST_HEAD(&rpci
->in_downcall
);
1051 INIT_LIST_HEAD(&rpci
->pipe
);
1053 init_waitqueue_head(&rpci
->waitq
);
1054 INIT_DELAYED_WORK(&rpci
->queue_timeout
,
1055 rpc_timeout_upcall_queue
);
1059 int register_rpc_pipefs(void)
1063 rpc_inode_cachep
= kmem_cache_create("rpc_inode_cache",
1064 sizeof(struct rpc_inode
),
1065 0, (SLAB_HWCACHE_ALIGN
|SLAB_RECLAIM_ACCOUNT
|
1068 if (!rpc_inode_cachep
)
1070 err
= register_filesystem(&rpc_pipe_fs_type
);
1072 kmem_cache_destroy(rpc_inode_cachep
);
1079 void unregister_rpc_pipefs(void)
1081 kmem_cache_destroy(rpc_inode_cachep
);
1082 unregister_filesystem(&rpc_pipe_fs_type
);