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>
31 static struct vfsmount
*rpc_mnt __read_mostly
;
32 static int rpc_mount_count
;
34 static struct file_system_type rpc_pipe_fs_type
;
37 static struct kmem_cache
*rpc_inode_cachep __read_mostly
;
39 #define RPC_UPCALL_TIMEOUT (30*HZ)
41 static void rpc_purge_list(struct rpc_inode
*rpci
, struct list_head
*head
,
42 void (*destroy_msg
)(struct rpc_pipe_msg
*), int err
)
44 struct rpc_pipe_msg
*msg
;
49 msg
= list_entry(head
->next
, struct rpc_pipe_msg
, list
);
50 list_del_init(&msg
->list
);
53 } while (!list_empty(head
));
54 wake_up(&rpci
->waitq
);
58 rpc_timeout_upcall_queue(struct work_struct
*work
)
61 struct rpc_inode
*rpci
=
62 container_of(work
, struct rpc_inode
, queue_timeout
.work
);
63 struct inode
*inode
= &rpci
->vfs_inode
;
64 void (*destroy_msg
)(struct rpc_pipe_msg
*);
66 spin_lock(&inode
->i_lock
);
67 if (rpci
->ops
== NULL
) {
68 spin_unlock(&inode
->i_lock
);
71 destroy_msg
= rpci
->ops
->destroy_msg
;
72 if (rpci
->nreaders
== 0) {
73 list_splice_init(&rpci
->pipe
, &free_list
);
76 spin_unlock(&inode
->i_lock
);
77 rpc_purge_list(rpci
, &free_list
, destroy_msg
, -ETIMEDOUT
);
80 ssize_t
rpc_pipe_generic_upcall(struct file
*filp
, struct rpc_pipe_msg
*msg
,
81 char __user
*dst
, size_t buflen
)
83 char *data
= (char *)msg
->data
+ msg
->copied
;
84 size_t mlen
= min(msg
->len
- msg
->copied
, buflen
);
87 left
= copy_to_user(dst
, data
, mlen
);
98 EXPORT_SYMBOL_GPL(rpc_pipe_generic_upcall
);
101 * rpc_queue_upcall - queue an upcall message to userspace
102 * @inode: inode of upcall pipe on which to queue given message
103 * @msg: message to queue
105 * Call with an @inode created by rpc_mkpipe() to queue an upcall.
106 * A userspace process may then later read the upcall by performing a
107 * read on an open file for this inode. It is up to the caller to
108 * initialize the fields of @msg (other than @msg->list) appropriately.
111 rpc_queue_upcall(struct inode
*inode
, struct rpc_pipe_msg
*msg
)
113 struct rpc_inode
*rpci
= RPC_I(inode
);
116 spin_lock(&inode
->i_lock
);
117 if (rpci
->ops
== NULL
)
119 if (rpci
->nreaders
) {
120 list_add_tail(&msg
->list
, &rpci
->pipe
);
121 rpci
->pipelen
+= msg
->len
;
123 } else if (rpci
->flags
& RPC_PIPE_WAIT_FOR_OPEN
) {
124 if (list_empty(&rpci
->pipe
))
125 queue_delayed_work(rpciod_workqueue
,
126 &rpci
->queue_timeout
,
128 list_add_tail(&msg
->list
, &rpci
->pipe
);
129 rpci
->pipelen
+= msg
->len
;
133 spin_unlock(&inode
->i_lock
);
134 wake_up(&rpci
->waitq
);
137 EXPORT_SYMBOL_GPL(rpc_queue_upcall
);
140 rpc_inode_setowner(struct inode
*inode
, void *private)
142 RPC_I(inode
)->private = private;
146 rpc_close_pipes(struct inode
*inode
)
148 struct rpc_inode
*rpci
= RPC_I(inode
);
149 const struct rpc_pipe_ops
*ops
;
152 mutex_lock(&inode
->i_mutex
);
155 LIST_HEAD(free_list
);
156 spin_lock(&inode
->i_lock
);
157 need_release
= rpci
->nreaders
!= 0 || rpci
->nwriters
!= 0;
159 list_splice_init(&rpci
->in_upcall
, &free_list
);
160 list_splice_init(&rpci
->pipe
, &free_list
);
163 spin_unlock(&inode
->i_lock
);
164 rpc_purge_list(rpci
, &free_list
, ops
->destroy_msg
, -EPIPE
);
166 if (need_release
&& ops
->release_pipe
)
167 ops
->release_pipe(inode
);
168 cancel_delayed_work_sync(&rpci
->queue_timeout
);
170 rpc_inode_setowner(inode
, NULL
);
171 mutex_unlock(&inode
->i_mutex
);
174 static struct inode
*
175 rpc_alloc_inode(struct super_block
*sb
)
177 struct rpc_inode
*rpci
;
178 rpci
= (struct rpc_inode
*)kmem_cache_alloc(rpc_inode_cachep
, GFP_KERNEL
);
181 return &rpci
->vfs_inode
;
185 rpc_i_callback(struct rcu_head
*head
)
187 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
188 INIT_LIST_HEAD(&inode
->i_dentry
);
189 kmem_cache_free(rpc_inode_cachep
, RPC_I(inode
));
193 rpc_destroy_inode(struct inode
*inode
)
195 call_rcu(&inode
->i_rcu
, rpc_i_callback
);
199 rpc_pipe_open(struct inode
*inode
, struct file
*filp
)
201 struct rpc_inode
*rpci
= RPC_I(inode
);
205 mutex_lock(&inode
->i_mutex
);
206 if (rpci
->ops
== NULL
)
208 first_open
= rpci
->nreaders
== 0 && rpci
->nwriters
== 0;
209 if (first_open
&& rpci
->ops
->open_pipe
) {
210 res
= rpci
->ops
->open_pipe(inode
);
214 if (filp
->f_mode
& FMODE_READ
)
216 if (filp
->f_mode
& FMODE_WRITE
)
220 mutex_unlock(&inode
->i_mutex
);
225 rpc_pipe_release(struct inode
*inode
, struct file
*filp
)
227 struct rpc_inode
*rpci
= RPC_I(inode
);
228 struct rpc_pipe_msg
*msg
;
231 mutex_lock(&inode
->i_mutex
);
232 if (rpci
->ops
== NULL
)
234 msg
= filp
->private_data
;
236 spin_lock(&inode
->i_lock
);
237 msg
->errno
= -EAGAIN
;
238 list_del_init(&msg
->list
);
239 spin_unlock(&inode
->i_lock
);
240 rpci
->ops
->destroy_msg(msg
);
242 if (filp
->f_mode
& FMODE_WRITE
)
244 if (filp
->f_mode
& FMODE_READ
) {
246 if (rpci
->nreaders
== 0) {
247 LIST_HEAD(free_list
);
248 spin_lock(&inode
->i_lock
);
249 list_splice_init(&rpci
->pipe
, &free_list
);
251 spin_unlock(&inode
->i_lock
);
252 rpc_purge_list(rpci
, &free_list
,
253 rpci
->ops
->destroy_msg
, -EAGAIN
);
256 last_close
= rpci
->nwriters
== 0 && rpci
->nreaders
== 0;
257 if (last_close
&& rpci
->ops
->release_pipe
)
258 rpci
->ops
->release_pipe(inode
);
260 mutex_unlock(&inode
->i_mutex
);
265 rpc_pipe_read(struct file
*filp
, char __user
*buf
, size_t len
, loff_t
*offset
)
267 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
268 struct rpc_inode
*rpci
= RPC_I(inode
);
269 struct rpc_pipe_msg
*msg
;
272 mutex_lock(&inode
->i_mutex
);
273 if (rpci
->ops
== NULL
) {
277 msg
= filp
->private_data
;
279 spin_lock(&inode
->i_lock
);
280 if (!list_empty(&rpci
->pipe
)) {
281 msg
= list_entry(rpci
->pipe
.next
,
284 list_move(&msg
->list
, &rpci
->in_upcall
);
285 rpci
->pipelen
-= msg
->len
;
286 filp
->private_data
= msg
;
289 spin_unlock(&inode
->i_lock
);
293 /* NOTE: it is up to the callback to update msg->copied */
294 res
= rpci
->ops
->upcall(filp
, msg
, buf
, len
);
295 if (res
< 0 || msg
->len
== msg
->copied
) {
296 filp
->private_data
= NULL
;
297 spin_lock(&inode
->i_lock
);
298 list_del_init(&msg
->list
);
299 spin_unlock(&inode
->i_lock
);
300 rpci
->ops
->destroy_msg(msg
);
303 mutex_unlock(&inode
->i_mutex
);
308 rpc_pipe_write(struct file
*filp
, const char __user
*buf
, size_t len
, loff_t
*offset
)
310 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
311 struct rpc_inode
*rpci
= RPC_I(inode
);
314 mutex_lock(&inode
->i_mutex
);
316 if (rpci
->ops
!= NULL
)
317 res
= rpci
->ops
->downcall(filp
, buf
, len
);
318 mutex_unlock(&inode
->i_mutex
);
323 rpc_pipe_poll(struct file
*filp
, struct poll_table_struct
*wait
)
325 struct rpc_inode
*rpci
;
326 unsigned int mask
= 0;
328 rpci
= RPC_I(filp
->f_path
.dentry
->d_inode
);
329 poll_wait(filp
, &rpci
->waitq
, wait
);
331 mask
= POLLOUT
| POLLWRNORM
;
332 if (rpci
->ops
== NULL
)
333 mask
|= POLLERR
| POLLHUP
;
334 if (filp
->private_data
|| !list_empty(&rpci
->pipe
))
335 mask
|= POLLIN
| POLLRDNORM
;
340 rpc_pipe_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
)
342 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
343 struct rpc_inode
*rpci
= RPC_I(inode
);
348 spin_lock(&inode
->i_lock
);
349 if (rpci
->ops
== NULL
) {
350 spin_unlock(&inode
->i_lock
);
354 if (filp
->private_data
) {
355 struct rpc_pipe_msg
*msg
;
356 msg
= filp
->private_data
;
357 len
+= msg
->len
- msg
->copied
;
359 spin_unlock(&inode
->i_lock
);
360 return put_user(len
, (int __user
*)arg
);
366 static const struct file_operations rpc_pipe_fops
= {
367 .owner
= THIS_MODULE
,
369 .read
= rpc_pipe_read
,
370 .write
= rpc_pipe_write
,
371 .poll
= rpc_pipe_poll
,
372 .unlocked_ioctl
= rpc_pipe_ioctl
,
373 .open
= rpc_pipe_open
,
374 .release
= rpc_pipe_release
,
378 rpc_show_info(struct seq_file
*m
, void *v
)
380 struct rpc_clnt
*clnt
= m
->private;
382 seq_printf(m
, "RPC server: %s\n", clnt
->cl_server
);
383 seq_printf(m
, "service: %s (%d) version %d\n", clnt
->cl_protname
,
384 clnt
->cl_prog
, clnt
->cl_vers
);
385 seq_printf(m
, "address: %s\n", rpc_peeraddr2str(clnt
, RPC_DISPLAY_ADDR
));
386 seq_printf(m
, "protocol: %s\n", rpc_peeraddr2str(clnt
, RPC_DISPLAY_PROTO
));
387 seq_printf(m
, "port: %s\n", rpc_peeraddr2str(clnt
, RPC_DISPLAY_PORT
));
392 rpc_info_open(struct inode
*inode
, struct file
*file
)
394 struct rpc_clnt
*clnt
= NULL
;
395 int ret
= single_open(file
, rpc_show_info
, NULL
);
398 struct seq_file
*m
= file
->private_data
;
400 spin_lock(&file
->f_path
.dentry
->d_lock
);
401 if (!d_unhashed(file
->f_path
.dentry
))
402 clnt
= RPC_I(inode
)->private;
403 if (clnt
!= NULL
&& atomic_inc_not_zero(&clnt
->cl_count
)) {
404 spin_unlock(&file
->f_path
.dentry
->d_lock
);
407 spin_unlock(&file
->f_path
.dentry
->d_lock
);
408 single_release(inode
, file
);
416 rpc_info_release(struct inode
*inode
, struct file
*file
)
418 struct seq_file
*m
= file
->private_data
;
419 struct rpc_clnt
*clnt
= (struct rpc_clnt
*)m
->private;
422 rpc_release_client(clnt
);
423 return single_release(inode
, file
);
426 static const struct file_operations rpc_info_operations
= {
427 .owner
= THIS_MODULE
,
428 .open
= rpc_info_open
,
431 .release
= rpc_info_release
,
436 * Description of fs contents.
438 struct rpc_filelist
{
440 const struct file_operations
*i_fop
;
444 struct vfsmount
*rpc_get_mount(void)
448 err
= simple_pin_fs(&rpc_pipe_fs_type
, &rpc_mnt
, &rpc_mount_count
);
453 EXPORT_SYMBOL_GPL(rpc_get_mount
);
455 void rpc_put_mount(void)
457 simple_release_fs(&rpc_mnt
, &rpc_mount_count
);
459 EXPORT_SYMBOL_GPL(rpc_put_mount
);
461 static int rpc_delete_dentry(const struct dentry
*dentry
)
466 static const struct dentry_operations rpc_dentry_operations
= {
467 .d_delete
= rpc_delete_dentry
,
470 static struct inode
*
471 rpc_get_inode(struct super_block
*sb
, umode_t mode
)
473 struct inode
*inode
= new_inode(sb
);
476 inode
->i_ino
= get_next_ino();
477 inode
->i_mode
= mode
;
478 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
479 switch (mode
& S_IFMT
) {
481 inode
->i_fop
= &simple_dir_operations
;
482 inode
->i_op
= &simple_dir_inode_operations
;
490 static int __rpc_create_common(struct inode
*dir
, struct dentry
*dentry
,
492 const struct file_operations
*i_fop
,
498 inode
= rpc_get_inode(dir
->i_sb
, mode
);
501 inode
->i_ino
= iunique(dir
->i_sb
, 100);
503 inode
->i_fop
= i_fop
;
505 rpc_inode_setowner(inode
, private);
506 d_add(dentry
, inode
);
509 printk(KERN_WARNING
"%s: %s failed to allocate inode for dentry %s\n",
510 __FILE__
, __func__
, dentry
->d_name
.name
);
515 static int __rpc_create(struct inode
*dir
, struct dentry
*dentry
,
517 const struct file_operations
*i_fop
,
522 err
= __rpc_create_common(dir
, dentry
, S_IFREG
| mode
, i_fop
, private);
525 fsnotify_create(dir
, dentry
);
529 static int __rpc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
531 const struct file_operations
*i_fop
,
536 err
= __rpc_create_common(dir
, dentry
, S_IFDIR
| mode
, i_fop
, private);
540 fsnotify_mkdir(dir
, dentry
);
544 static int __rpc_mkpipe(struct inode
*dir
, struct dentry
*dentry
,
546 const struct file_operations
*i_fop
,
548 const struct rpc_pipe_ops
*ops
,
551 struct rpc_inode
*rpci
;
554 err
= __rpc_create_common(dir
, dentry
, S_IFIFO
| mode
, i_fop
, private);
557 rpci
= RPC_I(dentry
->d_inode
);
558 rpci
->nkern_readwriters
= 1;
559 rpci
->private = private;
562 fsnotify_create(dir
, dentry
);
566 static int __rpc_rmdir(struct inode
*dir
, struct dentry
*dentry
)
571 ret
= simple_rmdir(dir
, dentry
);
577 static int __rpc_unlink(struct inode
*dir
, struct dentry
*dentry
)
582 ret
= simple_unlink(dir
, dentry
);
588 static int __rpc_rmpipe(struct inode
*dir
, struct dentry
*dentry
)
590 struct inode
*inode
= dentry
->d_inode
;
591 struct rpc_inode
*rpci
= RPC_I(inode
);
593 rpci
->nkern_readwriters
--;
594 if (rpci
->nkern_readwriters
!= 0)
596 rpc_close_pipes(inode
);
597 return __rpc_unlink(dir
, dentry
);
600 static struct dentry
*__rpc_lookup_create(struct dentry
*parent
,
603 struct dentry
*dentry
;
605 dentry
= d_lookup(parent
, name
);
607 dentry
= d_alloc(parent
, name
);
609 dentry
= ERR_PTR(-ENOMEM
);
613 if (!dentry
->d_inode
)
614 d_set_d_op(dentry
, &rpc_dentry_operations
);
619 static struct dentry
*__rpc_lookup_create_exclusive(struct dentry
*parent
,
622 struct dentry
*dentry
;
624 dentry
= __rpc_lookup_create(parent
, name
);
627 if (dentry
->d_inode
== NULL
)
630 return ERR_PTR(-EEXIST
);
634 * FIXME: This probably has races.
636 static void __rpc_depopulate(struct dentry
*parent
,
637 const struct rpc_filelist
*files
,
640 struct inode
*dir
= parent
->d_inode
;
641 struct dentry
*dentry
;
645 for (i
= start
; i
< eof
; i
++) {
646 name
.name
= files
[i
].name
;
647 name
.len
= strlen(files
[i
].name
);
648 name
.hash
= full_name_hash(name
.name
, name
.len
);
649 dentry
= d_lookup(parent
, &name
);
653 if (dentry
->d_inode
== NULL
)
655 switch (dentry
->d_inode
->i_mode
& S_IFMT
) {
659 __rpc_unlink(dir
, dentry
);
662 __rpc_rmdir(dir
, dentry
);
669 static void rpc_depopulate(struct dentry
*parent
,
670 const struct rpc_filelist
*files
,
673 struct inode
*dir
= parent
->d_inode
;
675 mutex_lock_nested(&dir
->i_mutex
, I_MUTEX_CHILD
);
676 __rpc_depopulate(parent
, files
, start
, eof
);
677 mutex_unlock(&dir
->i_mutex
);
680 static int rpc_populate(struct dentry
*parent
,
681 const struct rpc_filelist
*files
,
685 struct inode
*dir
= parent
->d_inode
;
686 struct dentry
*dentry
;
689 mutex_lock(&dir
->i_mutex
);
690 for (i
= start
; i
< eof
; i
++) {
693 q
.name
= files
[i
].name
;
694 q
.len
= strlen(files
[i
].name
);
695 q
.hash
= full_name_hash(q
.name
, q
.len
);
696 dentry
= __rpc_lookup_create_exclusive(parent
, &q
);
697 err
= PTR_ERR(dentry
);
700 switch (files
[i
].mode
& S_IFMT
) {
704 err
= __rpc_create(dir
, dentry
,
710 err
= __rpc_mkdir(dir
, dentry
,
718 mutex_unlock(&dir
->i_mutex
);
721 __rpc_depopulate(parent
, files
, start
, eof
);
722 mutex_unlock(&dir
->i_mutex
);
723 printk(KERN_WARNING
"%s: %s failed to populate directory %s\n",
724 __FILE__
, __func__
, parent
->d_name
.name
);
728 static struct dentry
*rpc_mkdir_populate(struct dentry
*parent
,
729 struct qstr
*name
, umode_t mode
, void *private,
730 int (*populate
)(struct dentry
*, void *), void *args_populate
)
732 struct dentry
*dentry
;
733 struct inode
*dir
= parent
->d_inode
;
736 mutex_lock_nested(&dir
->i_mutex
, I_MUTEX_PARENT
);
737 dentry
= __rpc_lookup_create_exclusive(parent
, name
);
740 error
= __rpc_mkdir(dir
, dentry
, mode
, NULL
, private);
743 if (populate
!= NULL
) {
744 error
= populate(dentry
, args_populate
);
749 mutex_unlock(&dir
->i_mutex
);
752 __rpc_rmdir(dir
, dentry
);
754 dentry
= ERR_PTR(error
);
758 static int rpc_rmdir_depopulate(struct dentry
*dentry
,
759 void (*depopulate
)(struct dentry
*))
761 struct dentry
*parent
;
765 parent
= dget_parent(dentry
);
766 dir
= parent
->d_inode
;
767 mutex_lock_nested(&dir
->i_mutex
, I_MUTEX_PARENT
);
768 if (depopulate
!= NULL
)
770 error
= __rpc_rmdir(dir
, dentry
);
771 mutex_unlock(&dir
->i_mutex
);
777 * rpc_mkpipe - make an rpc_pipefs file for kernel<->userspace communication
778 * @parent: dentry of directory to create new "pipe" in
779 * @name: name of pipe
780 * @private: private data to associate with the pipe, for the caller's use
781 * @ops: operations defining the behavior of the pipe: upcall, downcall,
782 * release_pipe, open_pipe, and destroy_msg.
783 * @flags: rpc_inode flags
785 * Data is made available for userspace to read by calls to
786 * rpc_queue_upcall(). The actual reads will result in calls to
787 * @ops->upcall, which will be called with the file pointer,
788 * message, and userspace buffer to copy to.
790 * Writes can come at any time, and do not necessarily have to be
791 * responses to upcalls. They will result in calls to @msg->downcall.
793 * The @private argument passed here will be available to all these methods
794 * from the file pointer, via RPC_I(file->f_dentry->d_inode)->private.
796 struct dentry
*rpc_mkpipe(struct dentry
*parent
, const char *name
,
797 void *private, const struct rpc_pipe_ops
*ops
,
800 struct dentry
*dentry
;
801 struct inode
*dir
= parent
->d_inode
;
802 umode_t umode
= S_IFIFO
| S_IRUSR
| S_IWUSR
;
806 if (ops
->upcall
== NULL
)
808 if (ops
->downcall
== NULL
)
812 q
.len
= strlen(name
);
813 q
.hash
= full_name_hash(q
.name
, q
.len
),
815 mutex_lock_nested(&dir
->i_mutex
, I_MUTEX_PARENT
);
816 dentry
= __rpc_lookup_create(parent
, &q
);
819 if (dentry
->d_inode
) {
820 struct rpc_inode
*rpci
= RPC_I(dentry
->d_inode
);
821 if (rpci
->private != private ||
823 rpci
->flags
!= flags
) {
828 rpci
->nkern_readwriters
++;
832 err
= __rpc_mkpipe(dir
, dentry
, umode
, &rpc_pipe_fops
,
833 private, ops
, flags
);
837 mutex_unlock(&dir
->i_mutex
);
840 dentry
= ERR_PTR(err
);
841 printk(KERN_WARNING
"%s: %s() failed to create pipe %s/%s (errno = %d)\n",
842 __FILE__
, __func__
, parent
->d_name
.name
, name
,
846 EXPORT_SYMBOL_GPL(rpc_mkpipe
);
849 * rpc_unlink - remove a pipe
850 * @dentry: dentry for the pipe, as returned from rpc_mkpipe
852 * After this call, lookups will no longer find the pipe, and any
853 * attempts to read or write using preexisting opens of the pipe will
857 rpc_unlink(struct dentry
*dentry
)
859 struct dentry
*parent
;
863 parent
= dget_parent(dentry
);
864 dir
= parent
->d_inode
;
865 mutex_lock_nested(&dir
->i_mutex
, I_MUTEX_PARENT
);
866 error
= __rpc_rmpipe(dir
, dentry
);
867 mutex_unlock(&dir
->i_mutex
);
871 EXPORT_SYMBOL_GPL(rpc_unlink
);
878 static const struct rpc_filelist authfiles
[] = {
881 .i_fop
= &rpc_info_operations
,
882 .mode
= S_IFREG
| S_IRUSR
,
886 static int rpc_clntdir_populate(struct dentry
*dentry
, void *private)
888 return rpc_populate(dentry
,
889 authfiles
, RPCAUTH_info
, RPCAUTH_EOF
,
893 static void rpc_clntdir_depopulate(struct dentry
*dentry
)
895 rpc_depopulate(dentry
, authfiles
, RPCAUTH_info
, RPCAUTH_EOF
);
899 * rpc_create_client_dir - Create a new rpc_client directory in rpc_pipefs
900 * @dentry: dentry from the rpc_pipefs root to the new directory
901 * @name: &struct qstr for the name
902 * @rpc_client: rpc client to associate with this directory
904 * This creates a directory at the given @path associated with
905 * @rpc_clnt, which will contain a file named "info" with some basic
906 * information about the client, together with any "pipes" that may
907 * later be created using rpc_mkpipe().
909 struct dentry
*rpc_create_client_dir(struct dentry
*dentry
,
911 struct rpc_clnt
*rpc_client
)
913 return rpc_mkdir_populate(dentry
, name
, S_IRUGO
| S_IXUGO
, NULL
,
914 rpc_clntdir_populate
, rpc_client
);
918 * rpc_remove_client_dir - Remove a directory created with rpc_create_client_dir()
919 * @dentry: directory to remove
921 int rpc_remove_client_dir(struct dentry
*dentry
)
923 return rpc_rmdir_depopulate(dentry
, rpc_clntdir_depopulate
);
926 static const struct rpc_filelist cache_pipefs_files
[3] = {
929 .i_fop
= &cache_file_operations_pipefs
,
930 .mode
= S_IFREG
|S_IRUSR
|S_IWUSR
,
934 .i_fop
= &content_file_operations_pipefs
,
935 .mode
= S_IFREG
|S_IRUSR
,
939 .i_fop
= &cache_flush_operations_pipefs
,
940 .mode
= S_IFREG
|S_IRUSR
|S_IWUSR
,
944 static int rpc_cachedir_populate(struct dentry
*dentry
, void *private)
946 return rpc_populate(dentry
,
947 cache_pipefs_files
, 0, 3,
951 static void rpc_cachedir_depopulate(struct dentry
*dentry
)
953 rpc_depopulate(dentry
, cache_pipefs_files
, 0, 3);
956 struct dentry
*rpc_create_cache_dir(struct dentry
*parent
, struct qstr
*name
,
957 mode_t umode
, struct cache_detail
*cd
)
959 return rpc_mkdir_populate(parent
, name
, umode
, NULL
,
960 rpc_cachedir_populate
, cd
);
963 void rpc_remove_cache_dir(struct dentry
*dentry
)
965 rpc_rmdir_depopulate(dentry
, rpc_cachedir_depopulate
);
969 * populate the filesystem
971 static const struct super_operations s_ops
= {
972 .alloc_inode
= rpc_alloc_inode
,
973 .destroy_inode
= rpc_destroy_inode
,
974 .statfs
= simple_statfs
,
977 #define RPCAUTH_GSSMAGIC 0x67596969
980 * We have a single directory with 1 node in it.
993 static const struct rpc_filelist files
[] = {
996 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
1000 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
1004 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
1006 [RPCAUTH_portmap
] = {
1008 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
1012 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
1014 [RPCAUTH_nfsd4_cb
] = {
1016 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
1020 .mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
,
1025 rpc_fill_super(struct super_block
*sb
, void *data
, int silent
)
1027 struct inode
*inode
;
1028 struct dentry
*root
;
1030 sb
->s_blocksize
= PAGE_CACHE_SIZE
;
1031 sb
->s_blocksize_bits
= PAGE_CACHE_SHIFT
;
1032 sb
->s_magic
= RPCAUTH_GSSMAGIC
;
1034 sb
->s_time_gran
= 1;
1036 inode
= rpc_get_inode(sb
, S_IFDIR
| 0755);
1039 sb
->s_root
= root
= d_alloc_root(inode
);
1044 if (rpc_populate(root
, files
, RPCAUTH_lockd
, RPCAUTH_RootEOF
, NULL
))
1049 static struct dentry
*
1050 rpc_mount(struct file_system_type
*fs_type
,
1051 int flags
, const char *dev_name
, void *data
)
1053 return mount_single(fs_type
, flags
, data
, rpc_fill_super
);
1056 static struct file_system_type rpc_pipe_fs_type
= {
1057 .owner
= THIS_MODULE
,
1058 .name
= "rpc_pipefs",
1060 .kill_sb
= kill_litter_super
,
1064 init_once(void *foo
)
1066 struct rpc_inode
*rpci
= (struct rpc_inode
*) foo
;
1068 inode_init_once(&rpci
->vfs_inode
);
1069 rpci
->private = NULL
;
1072 INIT_LIST_HEAD(&rpci
->in_upcall
);
1073 INIT_LIST_HEAD(&rpci
->in_downcall
);
1074 INIT_LIST_HEAD(&rpci
->pipe
);
1076 init_waitqueue_head(&rpci
->waitq
);
1077 INIT_DELAYED_WORK(&rpci
->queue_timeout
,
1078 rpc_timeout_upcall_queue
);
1082 int register_rpc_pipefs(void)
1086 rpc_inode_cachep
= kmem_cache_create("rpc_inode_cache",
1087 sizeof(struct rpc_inode
),
1088 0, (SLAB_HWCACHE_ALIGN
|SLAB_RECLAIM_ACCOUNT
|
1091 if (!rpc_inode_cachep
)
1093 err
= register_filesystem(&rpc_pipe_fs_type
);
1095 kmem_cache_destroy(rpc_inode_cachep
);
1102 void unregister_rpc_pipefs(void)
1104 kmem_cache_destroy(rpc_inode_cachep
);
1105 unregister_filesystem(&rpc_pipe_fs_type
);
1108 /* Make 'mount -t rpc_pipefs ...' autoload this module. */
1109 MODULE_ALIAS("rpc_pipefs");