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>
31 #include <linux/notifier.h>
36 #define RPCDBG_FACILITY RPCDBG_DEBUG
38 #define NET_NAME(net) ((net == &init_net) ? " (init_net)" : "")
40 static struct vfsmount *rpc_mnt __read_mostly;
41 static int rpc_mount_count;
43 static struct file_system_type rpc_pipe_fs_type;
46 static struct kmem_cache *rpc_inode_cachep __read_mostly;
48 #define RPC_UPCALL_TIMEOUT (30*HZ)
50 static BLOCKING_NOTIFIER_HEAD(rpc_pipefs_notifier_list);
52 int rpc_pipefs_notifier_register(struct notifier_block *nb)
54 return blocking_notifier_chain_cond_register(&rpc_pipefs_notifier_list, nb);
56 EXPORT_SYMBOL_GPL(rpc_pipefs_notifier_register);
58 void rpc_pipefs_notifier_unregister(struct notifier_block *nb)
60 blocking_notifier_chain_unregister(&rpc_pipefs_notifier_list, nb);
62 EXPORT_SYMBOL_GPL(rpc_pipefs_notifier_unregister);
64 static void rpc_purge_list(struct rpc_inode *rpci, struct list_head *head,
65 void (*destroy_msg)(struct rpc_pipe_msg *), int err)
67 struct rpc_pipe_msg *msg;
72 msg = list_entry(head->next, struct rpc_pipe_msg, list);
73 list_del_init(&msg->list);
76 } while (!list_empty(head));
77 wake_up(&rpci->waitq);
81 rpc_timeout_upcall_queue(struct work_struct *work)
84 struct rpc_inode *rpci =
85 container_of(work, struct rpc_inode, queue_timeout.work);
86 void (*destroy_msg)(struct rpc_pipe_msg *);
88 spin_lock(&rpci->lock);
89 if (rpci->ops == NULL) {
90 spin_unlock(&rpci->lock);
93 destroy_msg = rpci->ops->destroy_msg;
94 if (rpci->nreaders == 0) {
95 list_splice_init(&rpci->pipe, &free_list);
98 spin_unlock(&rpci->lock);
99 rpc_purge_list(rpci, &free_list, destroy_msg, -ETIMEDOUT);
102 ssize_t rpc_pipe_generic_upcall(struct file *filp, struct rpc_pipe_msg *msg,
103 char __user *dst, size_t buflen)
105 char *data = (char *)msg->data + msg->copied;
106 size_t mlen = min(msg->len - msg->copied, buflen);
109 left = copy_to_user(dst, data, mlen);
111 msg->errno = -EFAULT;
120 EXPORT_SYMBOL_GPL(rpc_pipe_generic_upcall);
123 * rpc_queue_upcall - queue an upcall message to userspace
124 * @inode: inode of upcall pipe on which to queue given message
125 * @msg: message to queue
127 * Call with an @inode created by rpc_mkpipe() to queue an upcall.
128 * A userspace process may then later read the upcall by performing a
129 * read on an open file for this inode. It is up to the caller to
130 * initialize the fields of @msg (other than @msg->list) appropriately.
133 rpc_queue_upcall(struct inode *inode, struct rpc_pipe_msg *msg)
135 struct rpc_inode *rpci = RPC_I(inode);
138 spin_lock(&rpci->lock);
139 if (rpci->ops == NULL)
141 if (rpci->nreaders) {
142 list_add_tail(&msg->list, &rpci->pipe);
143 rpci->pipelen += msg->len;
145 } else if (rpci->flags & RPC_PIPE_WAIT_FOR_OPEN) {
146 if (list_empty(&rpci->pipe))
147 queue_delayed_work(rpciod_workqueue,
148 &rpci->queue_timeout,
150 list_add_tail(&msg->list, &rpci->pipe);
151 rpci->pipelen += msg->len;
155 spin_unlock(&rpci->lock);
156 wake_up(&rpci->waitq);
159 EXPORT_SYMBOL_GPL(rpc_queue_upcall);
162 rpc_inode_setowner(struct inode *inode, void *private)
164 RPC_I(inode)->private = private;
168 rpc_close_pipes(struct inode *inode)
170 struct rpc_inode *rpci = RPC_I(inode);
171 const struct rpc_pipe_ops *ops;
174 mutex_lock(&inode->i_mutex);
177 LIST_HEAD(free_list);
178 spin_lock(&rpci->lock);
179 need_release = rpci->nreaders != 0 || rpci->nwriters != 0;
181 list_splice_init(&rpci->in_upcall, &free_list);
182 list_splice_init(&rpci->pipe, &free_list);
185 spin_unlock(&rpci->lock);
186 rpc_purge_list(rpci, &free_list, ops->destroy_msg, -EPIPE);
188 if (need_release && ops->release_pipe)
189 ops->release_pipe(inode);
190 cancel_delayed_work_sync(&rpci->queue_timeout);
192 rpc_inode_setowner(inode, NULL);
193 mutex_unlock(&inode->i_mutex);
196 static struct inode *
197 rpc_alloc_inode(struct super_block *sb)
199 struct rpc_inode *rpci;
200 rpci = (struct rpc_inode *)kmem_cache_alloc(rpc_inode_cachep, GFP_KERNEL);
203 return &rpci->vfs_inode;
207 rpc_i_callback(struct rcu_head *head)
209 struct inode *inode = container_of(head, struct inode, i_rcu);
210 kmem_cache_free(rpc_inode_cachep, RPC_I(inode));
214 rpc_destroy_inode(struct inode *inode)
216 call_rcu(&inode->i_rcu, rpc_i_callback);
220 rpc_pipe_open(struct inode *inode, struct file *filp)
222 struct rpc_inode *rpci = RPC_I(inode);
226 mutex_lock(&inode->i_mutex);
227 if (rpci->ops == NULL)
229 first_open = rpci->nreaders == 0 && rpci->nwriters == 0;
230 if (first_open && rpci->ops->open_pipe) {
231 res = rpci->ops->open_pipe(inode);
235 if (filp->f_mode & FMODE_READ)
237 if (filp->f_mode & FMODE_WRITE)
241 mutex_unlock(&inode->i_mutex);
246 rpc_pipe_release(struct inode *inode, struct file *filp)
248 struct rpc_inode *rpci = RPC_I(inode);
249 struct rpc_pipe_msg *msg;
252 mutex_lock(&inode->i_mutex);
253 if (rpci->ops == NULL)
255 msg = filp->private_data;
257 spin_lock(&rpci->lock);
258 msg->errno = -EAGAIN;
259 list_del_init(&msg->list);
260 spin_unlock(&rpci->lock);
261 rpci->ops->destroy_msg(msg);
263 if (filp->f_mode & FMODE_WRITE)
265 if (filp->f_mode & FMODE_READ) {
267 if (rpci->nreaders == 0) {
268 LIST_HEAD(free_list);
269 spin_lock(&rpci->lock);
270 list_splice_init(&rpci->pipe, &free_list);
272 spin_unlock(&rpci->lock);
273 rpc_purge_list(rpci, &free_list,
274 rpci->ops->destroy_msg, -EAGAIN);
277 last_close = rpci->nwriters == 0 && rpci->nreaders == 0;
278 if (last_close && rpci->ops->release_pipe)
279 rpci->ops->release_pipe(inode);
281 mutex_unlock(&inode->i_mutex);
286 rpc_pipe_read(struct file *filp, char __user *buf, size_t len, loff_t *offset)
288 struct inode *inode = filp->f_path.dentry->d_inode;
289 struct rpc_inode *rpci = RPC_I(inode);
290 struct rpc_pipe_msg *msg;
293 mutex_lock(&inode->i_mutex);
294 if (rpci->ops == NULL) {
298 msg = filp->private_data;
300 spin_lock(&rpci->lock);
301 if (!list_empty(&rpci->pipe)) {
302 msg = list_entry(rpci->pipe.next,
305 list_move(&msg->list, &rpci->in_upcall);
306 rpci->pipelen -= msg->len;
307 filp->private_data = msg;
310 spin_unlock(&rpci->lock);
314 /* NOTE: it is up to the callback to update msg->copied */
315 res = rpci->ops->upcall(filp, msg, buf, len);
316 if (res < 0 || msg->len == msg->copied) {
317 filp->private_data = NULL;
318 spin_lock(&rpci->lock);
319 list_del_init(&msg->list);
320 spin_unlock(&rpci->lock);
321 rpci->ops->destroy_msg(msg);
324 mutex_unlock(&inode->i_mutex);
329 rpc_pipe_write(struct file *filp, const char __user *buf, size_t len, loff_t *offset)
331 struct inode *inode = filp->f_path.dentry->d_inode;
332 struct rpc_inode *rpci = RPC_I(inode);
335 mutex_lock(&inode->i_mutex);
337 if (rpci->ops != NULL)
338 res = rpci->ops->downcall(filp, buf, len);
339 mutex_unlock(&inode->i_mutex);
344 rpc_pipe_poll(struct file *filp, struct poll_table_struct *wait)
346 struct rpc_inode *rpci;
347 unsigned int mask = 0;
349 rpci = RPC_I(filp->f_path.dentry->d_inode);
350 poll_wait(filp, &rpci->waitq, wait);
352 mask = POLLOUT | POLLWRNORM;
353 if (rpci->ops == NULL)
354 mask |= POLLERR | POLLHUP;
355 if (filp->private_data || !list_empty(&rpci->pipe))
356 mask |= POLLIN | POLLRDNORM;
361 rpc_pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
363 struct inode *inode = filp->f_path.dentry->d_inode;
364 struct rpc_inode *rpci = RPC_I(inode);
369 spin_lock(&rpci->lock);
370 if (rpci->ops == NULL) {
371 spin_unlock(&rpci->lock);
375 if (filp->private_data) {
376 struct rpc_pipe_msg *msg;
377 msg = filp->private_data;
378 len += msg->len - msg->copied;
380 spin_unlock(&rpci->lock);
381 return put_user(len, (int __user *)arg);
387 static const struct file_operations rpc_pipe_fops = {
388 .owner = THIS_MODULE,
390 .read = rpc_pipe_read,
391 .write = rpc_pipe_write,
392 .poll = rpc_pipe_poll,
393 .unlocked_ioctl = rpc_pipe_ioctl,
394 .open = rpc_pipe_open,
395 .release = rpc_pipe_release,
399 rpc_show_info(struct seq_file *m, void *v)
401 struct rpc_clnt *clnt = m->private;
403 seq_printf(m, "RPC server: %s\n", clnt->cl_server);
404 seq_printf(m, "service: %s (%d) version %d\n", clnt->cl_protname,
405 clnt->cl_prog, clnt->cl_vers);
406 seq_printf(m, "address: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_ADDR));
407 seq_printf(m, "protocol: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_PROTO));
408 seq_printf(m, "port: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_PORT));
413 rpc_info_open(struct inode *inode, struct file *file)
415 struct rpc_clnt *clnt = NULL;
416 int ret = single_open(file, rpc_show_info, NULL);
419 struct seq_file *m = file->private_data;
421 spin_lock(&file->f_path.dentry->d_lock);
422 if (!d_unhashed(file->f_path.dentry))
423 clnt = RPC_I(inode)->private;
424 if (clnt != NULL && atomic_inc_not_zero(&clnt->cl_count)) {
425 spin_unlock(&file->f_path.dentry->d_lock);
428 spin_unlock(&file->f_path.dentry->d_lock);
429 single_release(inode, file);
437 rpc_info_release(struct inode *inode, struct file *file)
439 struct seq_file *m = file->private_data;
440 struct rpc_clnt *clnt = (struct rpc_clnt *)m->private;
443 rpc_release_client(clnt);
444 return single_release(inode, file);
447 static const struct file_operations rpc_info_operations = {
448 .owner = THIS_MODULE,
449 .open = rpc_info_open,
452 .release = rpc_info_release,
457 * Description of fs contents.
459 struct rpc_filelist {
461 const struct file_operations *i_fop;
465 struct vfsmount *rpc_get_mount(void)
469 err = simple_pin_fs(&rpc_pipe_fs_type, &rpc_mnt, &rpc_mount_count);
474 EXPORT_SYMBOL_GPL(rpc_get_mount);
476 void rpc_put_mount(void)
478 simple_release_fs(&rpc_mnt, &rpc_mount_count);
480 EXPORT_SYMBOL_GPL(rpc_put_mount);
482 static int rpc_delete_dentry(const struct dentry *dentry)
487 static const struct dentry_operations rpc_dentry_operations = {
488 .d_delete = rpc_delete_dentry,
491 static struct inode *
492 rpc_get_inode(struct super_block *sb, umode_t mode)
494 struct inode *inode = new_inode(sb);
497 inode->i_ino = get_next_ino();
498 inode->i_mode = mode;
499 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
500 switch (mode & S_IFMT) {
502 inode->i_fop = &simple_dir_operations;
503 inode->i_op = &simple_dir_inode_operations;
511 static int __rpc_create_common(struct inode *dir, struct dentry *dentry,
513 const struct file_operations *i_fop,
519 inode = rpc_get_inode(dir->i_sb, mode);
522 inode->i_ino = iunique(dir->i_sb, 100);
524 inode->i_fop = i_fop;
526 rpc_inode_setowner(inode, private);
527 d_add(dentry, inode);
530 printk(KERN_WARNING "%s: %s failed to allocate inode for dentry %s\n",
531 __FILE__, __func__, dentry->d_name.name);
536 static int __rpc_create(struct inode *dir, struct dentry *dentry,
538 const struct file_operations *i_fop,
543 err = __rpc_create_common(dir, dentry, S_IFREG | mode, i_fop, private);
546 fsnotify_create(dir, dentry);
550 static int __rpc_mkdir(struct inode *dir, struct dentry *dentry,
552 const struct file_operations *i_fop,
557 err = __rpc_create_common(dir, dentry, S_IFDIR | mode, i_fop, private);
561 fsnotify_mkdir(dir, dentry);
565 static int __rpc_mkpipe(struct inode *dir, struct dentry *dentry,
567 const struct file_operations *i_fop,
569 const struct rpc_pipe_ops *ops,
572 struct rpc_inode *rpci;
575 err = __rpc_create_common(dir, dentry, S_IFIFO | mode, i_fop, private);
578 rpci = RPC_I(dentry->d_inode);
579 rpci->private = private;
582 fsnotify_create(dir, dentry);
586 static int __rpc_rmdir(struct inode *dir, struct dentry *dentry)
591 ret = simple_rmdir(dir, dentry);
597 static int __rpc_unlink(struct inode *dir, struct dentry *dentry)
602 ret = simple_unlink(dir, dentry);
608 static int __rpc_rmpipe(struct inode *dir, struct dentry *dentry)
610 struct inode *inode = dentry->d_inode;
612 rpc_close_pipes(inode);
613 return __rpc_unlink(dir, dentry);
616 static struct dentry *__rpc_lookup_create_exclusive(struct dentry *parent,
619 struct dentry *dentry;
621 dentry = d_lookup(parent, name);
623 dentry = d_alloc(parent, name);
625 return ERR_PTR(-ENOMEM);
627 if (dentry->d_inode == NULL) {
628 d_set_d_op(dentry, &rpc_dentry_operations);
632 return ERR_PTR(-EEXIST);
636 * FIXME: This probably has races.
638 static void __rpc_depopulate(struct dentry *parent,
639 const struct rpc_filelist *files,
642 struct inode *dir = parent->d_inode;
643 struct dentry *dentry;
647 for (i = start; i < eof; i++) {
648 name.name = files[i].name;
649 name.len = strlen(files[i].name);
650 name.hash = full_name_hash(name.name, name.len);
651 dentry = d_lookup(parent, &name);
655 if (dentry->d_inode == NULL)
657 switch (dentry->d_inode->i_mode & S_IFMT) {
661 __rpc_unlink(dir, dentry);
664 __rpc_rmdir(dir, dentry);
671 static void rpc_depopulate(struct dentry *parent,
672 const struct rpc_filelist *files,
675 struct inode *dir = parent->d_inode;
677 mutex_lock_nested(&dir->i_mutex, I_MUTEX_CHILD);
678 __rpc_depopulate(parent, files, start, eof);
679 mutex_unlock(&dir->i_mutex);
682 static int rpc_populate(struct dentry *parent,
683 const struct rpc_filelist *files,
687 struct inode *dir = parent->d_inode;
688 struct dentry *dentry;
691 mutex_lock(&dir->i_mutex);
692 for (i = start; i < eof; i++) {
695 q.name = files[i].name;
696 q.len = strlen(files[i].name);
697 q.hash = full_name_hash(q.name, q.len);
698 dentry = __rpc_lookup_create_exclusive(parent, &q);
699 err = PTR_ERR(dentry);
702 switch (files[i].mode & S_IFMT) {
706 err = __rpc_create(dir, dentry,
712 err = __rpc_mkdir(dir, dentry,
720 mutex_unlock(&dir->i_mutex);
723 __rpc_depopulate(parent, files, start, eof);
724 mutex_unlock(&dir->i_mutex);
725 printk(KERN_WARNING "%s: %s failed to populate directory %s\n",
726 __FILE__, __func__, parent->d_name.name);
730 static struct dentry *rpc_mkdir_populate(struct dentry *parent,
731 struct qstr *name, umode_t mode, void *private,
732 int (*populate)(struct dentry *, void *), void *args_populate)
734 struct dentry *dentry;
735 struct inode *dir = parent->d_inode;
738 mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT);
739 dentry = __rpc_lookup_create_exclusive(parent, name);
742 error = __rpc_mkdir(dir, dentry, mode, NULL, private);
745 if (populate != NULL) {
746 error = populate(dentry, args_populate);
751 mutex_unlock(&dir->i_mutex);
754 __rpc_rmdir(dir, dentry);
756 dentry = ERR_PTR(error);
760 static int rpc_rmdir_depopulate(struct dentry *dentry,
761 void (*depopulate)(struct dentry *))
763 struct dentry *parent;
767 parent = dget_parent(dentry);
768 dir = parent->d_inode;
769 mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT);
770 if (depopulate != NULL)
772 error = __rpc_rmdir(dir, dentry);
773 mutex_unlock(&dir->i_mutex);
779 * rpc_mkpipe - make an rpc_pipefs file for kernel<->userspace communication
780 * @parent: dentry of directory to create new "pipe" in
781 * @name: name of pipe
782 * @private: private data to associate with the pipe, for the caller's use
783 * @ops: operations defining the behavior of the pipe: upcall, downcall,
784 * release_pipe, open_pipe, and destroy_msg.
785 * @flags: rpc_inode flags
787 * Data is made available for userspace to read by calls to
788 * rpc_queue_upcall(). The actual reads will result in calls to
789 * @ops->upcall, which will be called with the file pointer,
790 * message, and userspace buffer to copy to.
792 * Writes can come at any time, and do not necessarily have to be
793 * responses to upcalls. They will result in calls to @msg->downcall.
795 * The @private argument passed here will be available to all these methods
796 * from the file pointer, via RPC_I(file->f_dentry->d_inode)->private.
798 struct dentry *rpc_mkpipe(struct dentry *parent, const char *name,
799 void *private, const struct rpc_pipe_ops *ops,
802 struct dentry *dentry;
803 struct inode *dir = parent->d_inode;
804 umode_t umode = S_IFIFO | S_IRUSR | S_IWUSR;
808 if (ops->upcall == NULL)
810 if (ops->downcall == NULL)
814 q.len = strlen(name);
815 q.hash = full_name_hash(q.name, q.len),
817 mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT);
818 dentry = __rpc_lookup_create_exclusive(parent, &q);
821 err = __rpc_mkpipe(dir, dentry, umode, &rpc_pipe_fops,
822 private, ops, flags);
826 mutex_unlock(&dir->i_mutex);
829 dentry = ERR_PTR(err);
830 printk(KERN_WARNING "%s: %s() failed to create pipe %s/%s (errno = %d)\n",
831 __FILE__, __func__, parent->d_name.name, name,
835 EXPORT_SYMBOL_GPL(rpc_mkpipe);
838 * rpc_unlink - remove a pipe
839 * @dentry: dentry for the pipe, as returned from rpc_mkpipe
841 * After this call, lookups will no longer find the pipe, and any
842 * attempts to read or write using preexisting opens of the pipe will
846 rpc_unlink(struct dentry *dentry)
848 struct dentry *parent;
852 parent = dget_parent(dentry);
853 dir = parent->d_inode;
854 mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT);
855 error = __rpc_rmpipe(dir, dentry);
856 mutex_unlock(&dir->i_mutex);
860 EXPORT_SYMBOL_GPL(rpc_unlink);
867 static const struct rpc_filelist authfiles[] = {
870 .i_fop = &rpc_info_operations,
871 .mode = S_IFREG | S_IRUSR,
875 static int rpc_clntdir_populate(struct dentry *dentry, void *private)
877 return rpc_populate(dentry,
878 authfiles, RPCAUTH_info, RPCAUTH_EOF,
882 static void rpc_clntdir_depopulate(struct dentry *dentry)
884 rpc_depopulate(dentry, authfiles, RPCAUTH_info, RPCAUTH_EOF);
888 * rpc_create_client_dir - Create a new rpc_client directory in rpc_pipefs
889 * @dentry: dentry from the rpc_pipefs root to the new directory
890 * @name: &struct qstr for the name
891 * @rpc_client: rpc client to associate with this directory
893 * This creates a directory at the given @path associated with
894 * @rpc_clnt, which will contain a file named "info" with some basic
895 * information about the client, together with any "pipes" that may
896 * later be created using rpc_mkpipe().
898 struct dentry *rpc_create_client_dir(struct dentry *dentry,
900 struct rpc_clnt *rpc_client)
902 return rpc_mkdir_populate(dentry, name, S_IRUGO | S_IXUGO, NULL,
903 rpc_clntdir_populate, rpc_client);
907 * rpc_remove_client_dir - Remove a directory created with rpc_create_client_dir()
908 * @dentry: directory to remove
910 int rpc_remove_client_dir(struct dentry *dentry)
912 return rpc_rmdir_depopulate(dentry, rpc_clntdir_depopulate);
915 static const struct rpc_filelist cache_pipefs_files[3] = {
918 .i_fop = &cache_file_operations_pipefs,
919 .mode = S_IFREG|S_IRUSR|S_IWUSR,
923 .i_fop = &content_file_operations_pipefs,
924 .mode = S_IFREG|S_IRUSR,
928 .i_fop = &cache_flush_operations_pipefs,
929 .mode = S_IFREG|S_IRUSR|S_IWUSR,
933 static int rpc_cachedir_populate(struct dentry *dentry, void *private)
935 return rpc_populate(dentry,
936 cache_pipefs_files, 0, 3,
940 static void rpc_cachedir_depopulate(struct dentry *dentry)
942 rpc_depopulate(dentry, cache_pipefs_files, 0, 3);
945 struct dentry *rpc_create_cache_dir(struct dentry *parent, struct qstr *name,
946 umode_t umode, struct cache_detail *cd)
948 return rpc_mkdir_populate(parent, name, umode, NULL,
949 rpc_cachedir_populate, cd);
952 void rpc_remove_cache_dir(struct dentry *dentry)
954 rpc_rmdir_depopulate(dentry, rpc_cachedir_depopulate);
958 * populate the filesystem
960 static const struct super_operations s_ops = {
961 .alloc_inode = rpc_alloc_inode,
962 .destroy_inode = rpc_destroy_inode,
963 .statfs = simple_statfs,
966 #define RPCAUTH_GSSMAGIC 0x67596969
969 * We have a single directory with 1 node in it.
982 static const struct rpc_filelist files[] = {
985 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
989 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
993 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
995 [RPCAUTH_portmap] = {
997 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
1001 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
1003 [RPCAUTH_nfsd4_cb] = {
1005 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
1009 .mode = S_IFDIR | S_IRUGO | S_IXUGO,
1014 * This call can be used only in RPC pipefs mount notification hooks.
1016 struct dentry *rpc_d_lookup_sb(const struct super_block *sb,
1017 const unsigned char *dir_name)
1021 .len = strlen(dir_name),
1022 .hash = full_name_hash(dir_name, strlen(dir_name)),
1025 return d_lookup(sb->s_root, &dir);
1027 EXPORT_SYMBOL_GPL(rpc_d_lookup_sb);
1029 void rpc_pipefs_init_net(struct net *net)
1031 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
1033 mutex_init(&sn->pipefs_sb_lock);
1037 * This call will be used for per network namespace operations calls.
1038 * Note: Function will be returned with pipefs_sb_lock taken if superblock was
1039 * found. This lock have to be released by rpc_put_sb_net() when all operations
1040 * will be completed.
1042 struct super_block *rpc_get_sb_net(const struct net *net)
1044 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
1046 mutex_lock(&sn->pipefs_sb_lock);
1048 return sn->pipefs_sb;
1049 mutex_unlock(&sn->pipefs_sb_lock);
1052 EXPORT_SYMBOL_GPL(rpc_get_sb_net);
1054 void rpc_put_sb_net(const struct net *net)
1056 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
1058 BUG_ON(sn->pipefs_sb == NULL);
1059 mutex_unlock(&sn->pipefs_sb_lock);
1061 EXPORT_SYMBOL_GPL(rpc_put_sb_net);
1064 rpc_fill_super(struct super_block *sb, void *data, int silent)
1066 struct inode *inode;
1067 struct dentry *root;
1068 struct net *net = data;
1069 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
1072 sb->s_blocksize = PAGE_CACHE_SIZE;
1073 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1074 sb->s_magic = RPCAUTH_GSSMAGIC;
1076 sb->s_time_gran = 1;
1078 inode = rpc_get_inode(sb, S_IFDIR | 0755);
1081 sb->s_root = root = d_alloc_root(inode);
1086 if (rpc_populate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF, NULL))
1088 dprintk("RPC: sending pipefs MOUNT notification for net %p%s\n", net,
1090 err = blocking_notifier_call_chain(&rpc_pipefs_notifier_list,
1094 goto err_depopulate;
1095 sb->s_fs_info = get_net(net);
1100 blocking_notifier_call_chain(&rpc_pipefs_notifier_list,
1103 __rpc_depopulate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF);
1107 static struct dentry *
1108 rpc_mount(struct file_system_type *fs_type,
1109 int flags, const char *dev_name, void *data)
1111 return mount_ns(fs_type, flags, current->nsproxy->net_ns, rpc_fill_super);
1114 void rpc_kill_sb(struct super_block *sb)
1116 struct net *net = sb->s_fs_info;
1117 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
1119 mutex_lock(&sn->pipefs_sb_lock);
1120 sn->pipefs_sb = NULL;
1121 mutex_unlock(&sn->pipefs_sb_lock);
1123 dprintk("RPC: sending pipefs UMOUNT notification for net %p%s\n", net,
1125 blocking_notifier_call_chain(&rpc_pipefs_notifier_list,
1128 kill_litter_super(sb);
1131 static struct file_system_type rpc_pipe_fs_type = {
1132 .owner = THIS_MODULE,
1133 .name = "rpc_pipefs",
1135 .kill_sb = rpc_kill_sb,
1139 init_once(void *foo)
1141 struct rpc_inode *rpci = (struct rpc_inode *) foo;
1143 inode_init_once(&rpci->vfs_inode);
1144 rpci->private = NULL;
1147 INIT_LIST_HEAD(&rpci->in_upcall);
1148 INIT_LIST_HEAD(&rpci->in_downcall);
1149 INIT_LIST_HEAD(&rpci->pipe);
1151 init_waitqueue_head(&rpci->waitq);
1152 INIT_DELAYED_WORK(&rpci->queue_timeout,
1153 rpc_timeout_upcall_queue);
1155 spin_lock_init(&rpci->lock);
1158 int register_rpc_pipefs(void)
1162 rpc_inode_cachep = kmem_cache_create("rpc_inode_cache",
1163 sizeof(struct rpc_inode),
1164 0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
1167 if (!rpc_inode_cachep)
1169 err = register_filesystem(&rpc_pipe_fs_type);
1171 kmem_cache_destroy(rpc_inode_cachep);
1178 void unregister_rpc_pipefs(void)
1180 kmem_cache_destroy(rpc_inode_cachep);
1181 unregister_filesystem(&rpc_pipe_fs_type);
1184 /* Make 'mount -t rpc_pipefs ...' autoload this module. */
1185 MODULE_ALIAS("rpc_pipefs");