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/nsproxy.h>
34 static struct vfsmount
*rpc_mnt __read_mostly
;
35 static int rpc_mount_count
;
37 static struct file_system_type rpc_pipe_fs_type
;
40 static struct kmem_cache
*rpc_inode_cachep __read_mostly
;
42 #define RPC_UPCALL_TIMEOUT (30*HZ)
44 static void rpc_purge_list(struct rpc_inode
*rpci
, struct list_head
*head
,
45 void (*destroy_msg
)(struct rpc_pipe_msg
*), int err
)
47 struct rpc_pipe_msg
*msg
;
52 msg
= list_entry(head
->next
, struct rpc_pipe_msg
, list
);
53 list_del_init(&msg
->list
);
56 } while (!list_empty(head
));
57 wake_up(&rpci
->waitq
);
61 rpc_timeout_upcall_queue(struct work_struct
*work
)
64 struct rpc_inode
*rpci
=
65 container_of(work
, struct rpc_inode
, queue_timeout
.work
);
66 struct inode
*inode
= &rpci
->vfs_inode
;
67 void (*destroy_msg
)(struct rpc_pipe_msg
*);
69 spin_lock(&inode
->i_lock
);
70 if (rpci
->ops
== NULL
) {
71 spin_unlock(&inode
->i_lock
);
74 destroy_msg
= rpci
->ops
->destroy_msg
;
75 if (rpci
->nreaders
== 0) {
76 list_splice_init(&rpci
->pipe
, &free_list
);
79 spin_unlock(&inode
->i_lock
);
80 rpc_purge_list(rpci
, &free_list
, destroy_msg
, -ETIMEDOUT
);
83 ssize_t
rpc_pipe_generic_upcall(struct file
*filp
, struct rpc_pipe_msg
*msg
,
84 char __user
*dst
, size_t buflen
)
86 char *data
= (char *)msg
->data
+ msg
->copied
;
87 size_t mlen
= min(msg
->len
- msg
->copied
, buflen
);
90 left
= copy_to_user(dst
, data
, mlen
);
101 EXPORT_SYMBOL_GPL(rpc_pipe_generic_upcall
);
104 * rpc_queue_upcall - queue an upcall message to userspace
105 * @inode: inode of upcall pipe on which to queue given message
106 * @msg: message to queue
108 * Call with an @inode created by rpc_mkpipe() to queue an upcall.
109 * A userspace process may then later read the upcall by performing a
110 * read on an open file for this inode. It is up to the caller to
111 * initialize the fields of @msg (other than @msg->list) appropriately.
114 rpc_queue_upcall(struct inode
*inode
, struct rpc_pipe_msg
*msg
)
116 struct rpc_inode
*rpci
= RPC_I(inode
);
119 spin_lock(&inode
->i_lock
);
120 if (rpci
->ops
== NULL
)
122 if (rpci
->nreaders
) {
123 list_add_tail(&msg
->list
, &rpci
->pipe
);
124 rpci
->pipelen
+= msg
->len
;
126 } else if (rpci
->flags
& RPC_PIPE_WAIT_FOR_OPEN
) {
127 if (list_empty(&rpci
->pipe
))
128 queue_delayed_work(rpciod_workqueue
,
129 &rpci
->queue_timeout
,
131 list_add_tail(&msg
->list
, &rpci
->pipe
);
132 rpci
->pipelen
+= msg
->len
;
136 spin_unlock(&inode
->i_lock
);
137 wake_up(&rpci
->waitq
);
140 EXPORT_SYMBOL_GPL(rpc_queue_upcall
);
143 rpc_inode_setowner(struct inode
*inode
, void *private)
145 RPC_I(inode
)->private = private;
149 rpc_close_pipes(struct inode
*inode
)
151 struct rpc_inode
*rpci
= RPC_I(inode
);
152 const struct rpc_pipe_ops
*ops
;
155 mutex_lock(&inode
->i_mutex
);
158 LIST_HEAD(free_list
);
159 spin_lock(&inode
->i_lock
);
160 need_release
= rpci
->nreaders
!= 0 || rpci
->nwriters
!= 0;
162 list_splice_init(&rpci
->in_upcall
, &free_list
);
163 list_splice_init(&rpci
->pipe
, &free_list
);
166 spin_unlock(&inode
->i_lock
);
167 rpc_purge_list(rpci
, &free_list
, ops
->destroy_msg
, -EPIPE
);
169 if (need_release
&& ops
->release_pipe
)
170 ops
->release_pipe(inode
);
171 cancel_delayed_work_sync(&rpci
->queue_timeout
);
173 rpc_inode_setowner(inode
, NULL
);
174 mutex_unlock(&inode
->i_mutex
);
177 static struct inode
*
178 rpc_alloc_inode(struct super_block
*sb
)
180 struct rpc_inode
*rpci
;
181 rpci
= (struct rpc_inode
*)kmem_cache_alloc(rpc_inode_cachep
, GFP_KERNEL
);
184 return &rpci
->vfs_inode
;
188 rpc_i_callback(struct rcu_head
*head
)
190 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
191 kmem_cache_free(rpc_inode_cachep
, RPC_I(inode
));
195 rpc_destroy_inode(struct inode
*inode
)
197 call_rcu(&inode
->i_rcu
, rpc_i_callback
);
201 rpc_pipe_open(struct inode
*inode
, struct file
*filp
)
203 struct rpc_inode
*rpci
= RPC_I(inode
);
207 mutex_lock(&inode
->i_mutex
);
208 if (rpci
->ops
== NULL
)
210 first_open
= rpci
->nreaders
== 0 && rpci
->nwriters
== 0;
211 if (first_open
&& rpci
->ops
->open_pipe
) {
212 res
= rpci
->ops
->open_pipe(inode
);
216 if (filp
->f_mode
& FMODE_READ
)
218 if (filp
->f_mode
& FMODE_WRITE
)
222 mutex_unlock(&inode
->i_mutex
);
227 rpc_pipe_release(struct inode
*inode
, struct file
*filp
)
229 struct rpc_inode
*rpci
= RPC_I(inode
);
230 struct rpc_pipe_msg
*msg
;
233 mutex_lock(&inode
->i_mutex
);
234 if (rpci
->ops
== NULL
)
236 msg
= filp
->private_data
;
238 spin_lock(&inode
->i_lock
);
239 msg
->errno
= -EAGAIN
;
240 list_del_init(&msg
->list
);
241 spin_unlock(&inode
->i_lock
);
242 rpci
->ops
->destroy_msg(msg
);
244 if (filp
->f_mode
& FMODE_WRITE
)
246 if (filp
->f_mode
& FMODE_READ
) {
248 if (rpci
->nreaders
== 0) {
249 LIST_HEAD(free_list
);
250 spin_lock(&inode
->i_lock
);
251 list_splice_init(&rpci
->pipe
, &free_list
);
253 spin_unlock(&inode
->i_lock
);
254 rpc_purge_list(rpci
, &free_list
,
255 rpci
->ops
->destroy_msg
, -EAGAIN
);
258 last_close
= rpci
->nwriters
== 0 && rpci
->nreaders
== 0;
259 if (last_close
&& rpci
->ops
->release_pipe
)
260 rpci
->ops
->release_pipe(inode
);
262 mutex_unlock(&inode
->i_mutex
);
267 rpc_pipe_read(struct file
*filp
, char __user
*buf
, size_t len
, loff_t
*offset
)
269 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
270 struct rpc_inode
*rpci
= RPC_I(inode
);
271 struct rpc_pipe_msg
*msg
;
274 mutex_lock(&inode
->i_mutex
);
275 if (rpci
->ops
== NULL
) {
279 msg
= filp
->private_data
;
281 spin_lock(&inode
->i_lock
);
282 if (!list_empty(&rpci
->pipe
)) {
283 msg
= list_entry(rpci
->pipe
.next
,
286 list_move(&msg
->list
, &rpci
->in_upcall
);
287 rpci
->pipelen
-= msg
->len
;
288 filp
->private_data
= msg
;
291 spin_unlock(&inode
->i_lock
);
295 /* NOTE: it is up to the callback to update msg->copied */
296 res
= rpci
->ops
->upcall(filp
, msg
, buf
, len
);
297 if (res
< 0 || msg
->len
== msg
->copied
) {
298 filp
->private_data
= NULL
;
299 spin_lock(&inode
->i_lock
);
300 list_del_init(&msg
->list
);
301 spin_unlock(&inode
->i_lock
);
302 rpci
->ops
->destroy_msg(msg
);
305 mutex_unlock(&inode
->i_mutex
);
310 rpc_pipe_write(struct file
*filp
, const char __user
*buf
, size_t len
, loff_t
*offset
)
312 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
313 struct rpc_inode
*rpci
= RPC_I(inode
);
316 mutex_lock(&inode
->i_mutex
);
318 if (rpci
->ops
!= NULL
)
319 res
= rpci
->ops
->downcall(filp
, buf
, len
);
320 mutex_unlock(&inode
->i_mutex
);
325 rpc_pipe_poll(struct file
*filp
, struct poll_table_struct
*wait
)
327 struct rpc_inode
*rpci
;
328 unsigned int mask
= 0;
330 rpci
= RPC_I(filp
->f_path
.dentry
->d_inode
);
331 poll_wait(filp
, &rpci
->waitq
, wait
);
333 mask
= POLLOUT
| POLLWRNORM
;
334 if (rpci
->ops
== NULL
)
335 mask
|= POLLERR
| POLLHUP
;
336 if (filp
->private_data
|| !list_empty(&rpci
->pipe
))
337 mask
|= POLLIN
| POLLRDNORM
;
342 rpc_pipe_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
)
344 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
345 struct rpc_inode
*rpci
= RPC_I(inode
);
350 spin_lock(&inode
->i_lock
);
351 if (rpci
->ops
== NULL
) {
352 spin_unlock(&inode
->i_lock
);
356 if (filp
->private_data
) {
357 struct rpc_pipe_msg
*msg
;
358 msg
= filp
->private_data
;
359 len
+= msg
->len
- msg
->copied
;
361 spin_unlock(&inode
->i_lock
);
362 return put_user(len
, (int __user
*)arg
);
368 static const struct file_operations rpc_pipe_fops
= {
369 .owner
= THIS_MODULE
,
371 .read
= rpc_pipe_read
,
372 .write
= rpc_pipe_write
,
373 .poll
= rpc_pipe_poll
,
374 .unlocked_ioctl
= rpc_pipe_ioctl
,
375 .open
= rpc_pipe_open
,
376 .release
= rpc_pipe_release
,
380 rpc_show_info(struct seq_file
*m
, void *v
)
382 struct rpc_clnt
*clnt
= m
->private;
384 seq_printf(m
, "RPC server: %s\n", clnt
->cl_server
);
385 seq_printf(m
, "service: %s (%d) version %d\n", clnt
->cl_protname
,
386 clnt
->cl_prog
, clnt
->cl_vers
);
387 seq_printf(m
, "address: %s\n", rpc_peeraddr2str(clnt
, RPC_DISPLAY_ADDR
));
388 seq_printf(m
, "protocol: %s\n", rpc_peeraddr2str(clnt
, RPC_DISPLAY_PROTO
));
389 seq_printf(m
, "port: %s\n", rpc_peeraddr2str(clnt
, RPC_DISPLAY_PORT
));
394 rpc_info_open(struct inode
*inode
, struct file
*file
)
396 struct rpc_clnt
*clnt
= NULL
;
397 int ret
= single_open(file
, rpc_show_info
, NULL
);
400 struct seq_file
*m
= file
->private_data
;
402 spin_lock(&file
->f_path
.dentry
->d_lock
);
403 if (!d_unhashed(file
->f_path
.dentry
))
404 clnt
= RPC_I(inode
)->private;
405 if (clnt
!= NULL
&& atomic_inc_not_zero(&clnt
->cl_count
)) {
406 spin_unlock(&file
->f_path
.dentry
->d_lock
);
409 spin_unlock(&file
->f_path
.dentry
->d_lock
);
410 single_release(inode
, file
);
418 rpc_info_release(struct inode
*inode
, struct file
*file
)
420 struct seq_file
*m
= file
->private_data
;
421 struct rpc_clnt
*clnt
= (struct rpc_clnt
*)m
->private;
424 rpc_release_client(clnt
);
425 return single_release(inode
, file
);
428 static const struct file_operations rpc_info_operations
= {
429 .owner
= THIS_MODULE
,
430 .open
= rpc_info_open
,
433 .release
= rpc_info_release
,
438 * Description of fs contents.
440 struct rpc_filelist
{
442 const struct file_operations
*i_fop
;
446 struct vfsmount
*rpc_get_mount(void)
450 err
= simple_pin_fs(&rpc_pipe_fs_type
, &rpc_mnt
, &rpc_mount_count
);
455 EXPORT_SYMBOL_GPL(rpc_get_mount
);
457 void rpc_put_mount(void)
459 simple_release_fs(&rpc_mnt
, &rpc_mount_count
);
461 EXPORT_SYMBOL_GPL(rpc_put_mount
);
463 static int rpc_delete_dentry(const struct dentry
*dentry
)
468 static const struct dentry_operations rpc_dentry_operations
= {
469 .d_delete
= rpc_delete_dentry
,
472 static struct inode
*
473 rpc_get_inode(struct super_block
*sb
, umode_t mode
)
475 struct inode
*inode
= new_inode(sb
);
478 inode
->i_ino
= get_next_ino();
479 inode
->i_mode
= mode
;
480 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
481 switch (mode
& S_IFMT
) {
483 inode
->i_fop
= &simple_dir_operations
;
484 inode
->i_op
= &simple_dir_inode_operations
;
492 static int __rpc_create_common(struct inode
*dir
, struct dentry
*dentry
,
494 const struct file_operations
*i_fop
,
500 inode
= rpc_get_inode(dir
->i_sb
, mode
);
503 inode
->i_ino
= iunique(dir
->i_sb
, 100);
505 inode
->i_fop
= i_fop
;
507 rpc_inode_setowner(inode
, private);
508 d_add(dentry
, inode
);
511 printk(KERN_WARNING
"%s: %s failed to allocate inode for dentry %s\n",
512 __FILE__
, __func__
, dentry
->d_name
.name
);
517 static int __rpc_create(struct inode
*dir
, struct dentry
*dentry
,
519 const struct file_operations
*i_fop
,
524 err
= __rpc_create_common(dir
, dentry
, S_IFREG
| mode
, i_fop
, private);
527 fsnotify_create(dir
, dentry
);
531 static int __rpc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
533 const struct file_operations
*i_fop
,
538 err
= __rpc_create_common(dir
, dentry
, S_IFDIR
| mode
, i_fop
, private);
542 fsnotify_mkdir(dir
, dentry
);
546 static int __rpc_mkpipe(struct inode
*dir
, struct dentry
*dentry
,
548 const struct file_operations
*i_fop
,
550 const struct rpc_pipe_ops
*ops
,
553 struct rpc_inode
*rpci
;
556 err
= __rpc_create_common(dir
, dentry
, S_IFIFO
| mode
, i_fop
, private);
559 rpci
= RPC_I(dentry
->d_inode
);
560 rpci
->private = private;
563 fsnotify_create(dir
, dentry
);
567 static int __rpc_rmdir(struct inode
*dir
, struct dentry
*dentry
)
572 ret
= simple_rmdir(dir
, dentry
);
578 static int __rpc_unlink(struct inode
*dir
, struct dentry
*dentry
)
583 ret
= simple_unlink(dir
, dentry
);
589 static int __rpc_rmpipe(struct inode
*dir
, struct dentry
*dentry
)
591 struct inode
*inode
= dentry
->d_inode
;
593 rpc_close_pipes(inode
);
594 return __rpc_unlink(dir
, dentry
);
597 static struct dentry
*__rpc_lookup_create_exclusive(struct dentry
*parent
,
600 struct dentry
*dentry
;
602 dentry
= d_lookup(parent
, name
);
604 dentry
= d_alloc(parent
, name
);
606 return ERR_PTR(-ENOMEM
);
608 if (dentry
->d_inode
== NULL
) {
609 d_set_d_op(dentry
, &rpc_dentry_operations
);
613 return ERR_PTR(-EEXIST
);
617 * FIXME: This probably has races.
619 static void __rpc_depopulate(struct dentry
*parent
,
620 const struct rpc_filelist
*files
,
623 struct inode
*dir
= parent
->d_inode
;
624 struct dentry
*dentry
;
628 for (i
= start
; i
< eof
; i
++) {
629 name
.name
= files
[i
].name
;
630 name
.len
= strlen(files
[i
].name
);
631 name
.hash
= full_name_hash(name
.name
, name
.len
);
632 dentry
= d_lookup(parent
, &name
);
636 if (dentry
->d_inode
== NULL
)
638 switch (dentry
->d_inode
->i_mode
& S_IFMT
) {
642 __rpc_unlink(dir
, dentry
);
645 __rpc_rmdir(dir
, dentry
);
652 static void rpc_depopulate(struct dentry
*parent
,
653 const struct rpc_filelist
*files
,
656 struct inode
*dir
= parent
->d_inode
;
658 mutex_lock_nested(&dir
->i_mutex
, I_MUTEX_CHILD
);
659 __rpc_depopulate(parent
, files
, start
, eof
);
660 mutex_unlock(&dir
->i_mutex
);
663 static int rpc_populate(struct dentry
*parent
,
664 const struct rpc_filelist
*files
,
668 struct inode
*dir
= parent
->d_inode
;
669 struct dentry
*dentry
;
672 mutex_lock(&dir
->i_mutex
);
673 for (i
= start
; i
< eof
; i
++) {
676 q
.name
= files
[i
].name
;
677 q
.len
= strlen(files
[i
].name
);
678 q
.hash
= full_name_hash(q
.name
, q
.len
);
679 dentry
= __rpc_lookup_create_exclusive(parent
, &q
);
680 err
= PTR_ERR(dentry
);
683 switch (files
[i
].mode
& S_IFMT
) {
687 err
= __rpc_create(dir
, dentry
,
693 err
= __rpc_mkdir(dir
, dentry
,
701 mutex_unlock(&dir
->i_mutex
);
704 __rpc_depopulate(parent
, files
, start
, eof
);
705 mutex_unlock(&dir
->i_mutex
);
706 printk(KERN_WARNING
"%s: %s failed to populate directory %s\n",
707 __FILE__
, __func__
, parent
->d_name
.name
);
711 static struct dentry
*rpc_mkdir_populate(struct dentry
*parent
,
712 struct qstr
*name
, umode_t mode
, void *private,
713 int (*populate
)(struct dentry
*, void *), void *args_populate
)
715 struct dentry
*dentry
;
716 struct inode
*dir
= parent
->d_inode
;
719 mutex_lock_nested(&dir
->i_mutex
, I_MUTEX_PARENT
);
720 dentry
= __rpc_lookup_create_exclusive(parent
, name
);
723 error
= __rpc_mkdir(dir
, dentry
, mode
, NULL
, private);
726 if (populate
!= NULL
) {
727 error
= populate(dentry
, args_populate
);
732 mutex_unlock(&dir
->i_mutex
);
735 __rpc_rmdir(dir
, dentry
);
737 dentry
= ERR_PTR(error
);
741 static int rpc_rmdir_depopulate(struct dentry
*dentry
,
742 void (*depopulate
)(struct dentry
*))
744 struct dentry
*parent
;
748 parent
= dget_parent(dentry
);
749 dir
= parent
->d_inode
;
750 mutex_lock_nested(&dir
->i_mutex
, I_MUTEX_PARENT
);
751 if (depopulate
!= NULL
)
753 error
= __rpc_rmdir(dir
, dentry
);
754 mutex_unlock(&dir
->i_mutex
);
760 * rpc_mkpipe - make an rpc_pipefs file for kernel<->userspace communication
761 * @parent: dentry of directory to create new "pipe" in
762 * @name: name of pipe
763 * @private: private data to associate with the pipe, for the caller's use
764 * @ops: operations defining the behavior of the pipe: upcall, downcall,
765 * release_pipe, open_pipe, and destroy_msg.
766 * @flags: rpc_inode flags
768 * Data is made available for userspace to read by calls to
769 * rpc_queue_upcall(). The actual reads will result in calls to
770 * @ops->upcall, which will be called with the file pointer,
771 * message, and userspace buffer to copy to.
773 * Writes can come at any time, and do not necessarily have to be
774 * responses to upcalls. They will result in calls to @msg->downcall.
776 * The @private argument passed here will be available to all these methods
777 * from the file pointer, via RPC_I(file->f_dentry->d_inode)->private.
779 struct dentry
*rpc_mkpipe(struct dentry
*parent
, const char *name
,
780 void *private, const struct rpc_pipe_ops
*ops
,
783 struct dentry
*dentry
;
784 struct inode
*dir
= parent
->d_inode
;
785 umode_t umode
= S_IFIFO
| S_IRUSR
| S_IWUSR
;
789 if (ops
->upcall
== NULL
)
791 if (ops
->downcall
== NULL
)
795 q
.len
= strlen(name
);
796 q
.hash
= full_name_hash(q
.name
, q
.len
),
798 mutex_lock_nested(&dir
->i_mutex
, I_MUTEX_PARENT
);
799 dentry
= __rpc_lookup_create_exclusive(parent
, &q
);
802 err
= __rpc_mkpipe(dir
, dentry
, umode
, &rpc_pipe_fops
,
803 private, ops
, flags
);
807 mutex_unlock(&dir
->i_mutex
);
810 dentry
= ERR_PTR(err
);
811 printk(KERN_WARNING
"%s: %s() failed to create pipe %s/%s (errno = %d)\n",
812 __FILE__
, __func__
, parent
->d_name
.name
, name
,
816 EXPORT_SYMBOL_GPL(rpc_mkpipe
);
819 * rpc_unlink - remove a pipe
820 * @dentry: dentry for the pipe, as returned from rpc_mkpipe
822 * After this call, lookups will no longer find the pipe, and any
823 * attempts to read or write using preexisting opens of the pipe will
827 rpc_unlink(struct dentry
*dentry
)
829 struct dentry
*parent
;
833 parent
= dget_parent(dentry
);
834 dir
= parent
->d_inode
;
835 mutex_lock_nested(&dir
->i_mutex
, I_MUTEX_PARENT
);
836 error
= __rpc_rmpipe(dir
, dentry
);
837 mutex_unlock(&dir
->i_mutex
);
841 EXPORT_SYMBOL_GPL(rpc_unlink
);
848 static const struct rpc_filelist authfiles
[] = {
851 .i_fop
= &rpc_info_operations
,
852 .mode
= S_IFREG
| S_IRUSR
,
856 static int rpc_clntdir_populate(struct dentry
*dentry
, void *private)
858 return rpc_populate(dentry
,
859 authfiles
, RPCAUTH_info
, RPCAUTH_EOF
,
863 static void rpc_clntdir_depopulate(struct dentry
*dentry
)
865 rpc_depopulate(dentry
, authfiles
, RPCAUTH_info
, RPCAUTH_EOF
);
869 * rpc_create_client_dir - Create a new rpc_client directory in rpc_pipefs
870 * @dentry: dentry from the rpc_pipefs root to the new directory
871 * @name: &struct qstr for the name
872 * @rpc_client: rpc client to associate with this directory
874 * This creates a directory at the given @path associated with
875 * @rpc_clnt, which will contain a file named "info" with some basic
876 * information about the client, together with any "pipes" that may
877 * later be created using rpc_mkpipe().
879 struct dentry
*rpc_create_client_dir(struct dentry
*dentry
,
881 struct rpc_clnt
*rpc_client
)
883 return rpc_mkdir_populate(dentry
, name
, S_IRUGO
| S_IXUGO
, NULL
,
884 rpc_clntdir_populate
, rpc_client
);
888 * rpc_remove_client_dir - Remove a directory created with rpc_create_client_dir()
889 * @dentry: directory to remove
891 int rpc_remove_client_dir(struct dentry
*dentry
)
893 return rpc_rmdir_depopulate(dentry
, rpc_clntdir_depopulate
);
896 static const struct rpc_filelist cache_pipefs_files
[3] = {
899 .i_fop
= &cache_file_operations_pipefs
,
900 .mode
= S_IFREG
|S_IRUSR
|S_IWUSR
,
904 .i_fop
= &content_file_operations_pipefs
,
905 .mode
= S_IFREG
|S_IRUSR
,
909 .i_fop
= &cache_flush_operations_pipefs
,
910 .mode
= S_IFREG
|S_IRUSR
|S_IWUSR
,
914 static int rpc_cachedir_populate(struct dentry
*dentry
, void *private)
916 return rpc_populate(dentry
,
917 cache_pipefs_files
, 0, 3,
921 static void rpc_cachedir_depopulate(struct dentry
*dentry
)
923 rpc_depopulate(dentry
, cache_pipefs_files
, 0, 3);
926 struct dentry
*rpc_create_cache_dir(struct dentry
*parent
, struct qstr
*name
,
927 umode_t umode
, struct cache_detail
*cd
)
929 return rpc_mkdir_populate(parent
, name
, umode
, NULL
,
930 rpc_cachedir_populate
, cd
);
933 void rpc_remove_cache_dir(struct dentry
*dentry
)
935 rpc_rmdir_depopulate(dentry
, rpc_cachedir_depopulate
);
939 * populate the filesystem
941 static const struct super_operations s_ops
= {
942 .alloc_inode
= rpc_alloc_inode
,
943 .destroy_inode
= rpc_destroy_inode
,
944 .statfs
= simple_statfs
,
947 #define RPCAUTH_GSSMAGIC 0x67596969
950 * We have a single directory with 1 node in it.
963 static const struct rpc_filelist files
[] = {
966 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
970 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
974 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
976 [RPCAUTH_portmap
] = {
978 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
982 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
984 [RPCAUTH_nfsd4_cb
] = {
986 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
990 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
995 rpc_fill_super(struct super_block
*sb
, void *data
, int silent
)
999 struct net
*net
= data
;
1001 sb
->s_blocksize
= PAGE_CACHE_SIZE
;
1002 sb
->s_blocksize_bits
= PAGE_CACHE_SHIFT
;
1003 sb
->s_magic
= RPCAUTH_GSSMAGIC
;
1005 sb
->s_time_gran
= 1;
1007 inode
= rpc_get_inode(sb
, S_IFDIR
| 0755);
1010 sb
->s_root
= root
= d_alloc_root(inode
);
1015 if (rpc_populate(root
, files
, RPCAUTH_lockd
, RPCAUTH_RootEOF
, NULL
))
1017 sb
->s_fs_info
= get_net(net
);
1021 static struct dentry
*
1022 rpc_mount(struct file_system_type
*fs_type
,
1023 int flags
, const char *dev_name
, void *data
)
1025 return mount_ns(fs_type
, flags
, current
->nsproxy
->net_ns
, rpc_fill_super
);
1028 void rpc_kill_sb(struct super_block
*sb
)
1030 struct net
*net
= sb
->s_fs_info
;
1033 kill_litter_super(sb
);
1036 static struct file_system_type rpc_pipe_fs_type
= {
1037 .owner
= THIS_MODULE
,
1038 .name
= "rpc_pipefs",
1040 .kill_sb
= rpc_kill_sb
,
1044 init_once(void *foo
)
1046 struct rpc_inode
*rpci
= (struct rpc_inode
*) foo
;
1048 inode_init_once(&rpci
->vfs_inode
);
1049 rpci
->private = NULL
;
1052 INIT_LIST_HEAD(&rpci
->in_upcall
);
1053 INIT_LIST_HEAD(&rpci
->in_downcall
);
1054 INIT_LIST_HEAD(&rpci
->pipe
);
1056 init_waitqueue_head(&rpci
->waitq
);
1057 INIT_DELAYED_WORK(&rpci
->queue_timeout
,
1058 rpc_timeout_upcall_queue
);
1062 int register_rpc_pipefs(void)
1066 rpc_inode_cachep
= kmem_cache_create("rpc_inode_cache",
1067 sizeof(struct rpc_inode
),
1068 0, (SLAB_HWCACHE_ALIGN
|SLAB_RECLAIM_ACCOUNT
|
1071 if (!rpc_inode_cachep
)
1073 err
= register_filesystem(&rpc_pipe_fs_type
);
1075 kmem_cache_destroy(rpc_inode_cachep
);
1082 void unregister_rpc_pipefs(void)
1084 kmem_cache_destroy(rpc_inode_cachep
);
1085 unregister_filesystem(&rpc_pipe_fs_type
);
1088 /* Make 'mount -t rpc_pipefs ...' autoload this module. */
1089 MODULE_ALIAS("rpc_pipefs");