^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * net/sunrpc/rpc_pipe.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Userland/kernel interface for rpcauth_gss.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Code shamelessly plagiarized from fs/nfsd/nfsctl.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * and fs/sysfs/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (c) 2002, Trond Myklebust <trond.myklebust@fys.uio.no>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/fs_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/fsnotify.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/utsname.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/ioctls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/sunrpc/clnt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/sunrpc/rpc_pipe_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/sunrpc/cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/nsproxy.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include "netns.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include "sunrpc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define RPCDBG_FACILITY RPCDBG_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define NET_NAME(net) ((net == &init_net) ? " (init_net)" : "")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static struct file_system_type rpc_pipe_fs_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static const struct rpc_pipe_ops gssd_dummy_pipe_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static struct kmem_cache *rpc_inode_cachep __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define RPC_UPCALL_TIMEOUT (30*HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static BLOCKING_NOTIFIER_HEAD(rpc_pipefs_notifier_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) int rpc_pipefs_notifier_register(struct notifier_block *nb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return blocking_notifier_chain_register(&rpc_pipefs_notifier_list, nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) EXPORT_SYMBOL_GPL(rpc_pipefs_notifier_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) void rpc_pipefs_notifier_unregister(struct notifier_block *nb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) blocking_notifier_chain_unregister(&rpc_pipefs_notifier_list, nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) EXPORT_SYMBOL_GPL(rpc_pipefs_notifier_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static void rpc_purge_list(wait_queue_head_t *waitq, struct list_head *head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) void (*destroy_msg)(struct rpc_pipe_msg *), int err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct rpc_pipe_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (list_empty(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) msg = list_entry(head->next, struct rpc_pipe_msg, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) list_del_init(&msg->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) msg->errno = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) destroy_msg(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) } while (!list_empty(head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (waitq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) wake_up(waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) rpc_timeout_upcall_queue(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) LIST_HEAD(free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct rpc_pipe *pipe =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) container_of(work, struct rpc_pipe, queue_timeout.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) void (*destroy_msg)(struct rpc_pipe_msg *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) spin_lock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) destroy_msg = pipe->ops->destroy_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (pipe->nreaders == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) list_splice_init(&pipe->pipe, &free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) pipe->pipelen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) dentry = dget(pipe->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) spin_unlock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) rpc_purge_list(dentry ? &RPC_I(d_inode(dentry))->waitq : NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) &free_list, destroy_msg, -ETIMEDOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) ssize_t rpc_pipe_generic_upcall(struct file *filp, struct rpc_pipe_msg *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) char __user *dst, size_t buflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) char *data = (char *)msg->data + msg->copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) size_t mlen = min(msg->len - msg->copied, buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned long left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) left = copy_to_user(dst, data, mlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (left == mlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) msg->errno = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) mlen -= left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) msg->copied += mlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) msg->errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return mlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) EXPORT_SYMBOL_GPL(rpc_pipe_generic_upcall);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * rpc_queue_upcall - queue an upcall message to userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * @pipe: upcall pipe on which to queue given message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * @msg: message to queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * Call with an @inode created by rpc_mkpipe() to queue an upcall.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * A userspace process may then later read the upcall by performing a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * read on an open file for this inode. It is up to the caller to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * initialize the fields of @msg (other than @msg->list) appropriately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) rpc_queue_upcall(struct rpc_pipe *pipe, struct rpc_pipe_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int res = -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) spin_lock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (pipe->nreaders) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) list_add_tail(&msg->list, &pipe->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) pipe->pipelen += msg->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) } else if (pipe->flags & RPC_PIPE_WAIT_FOR_OPEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (list_empty(&pipe->pipe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) queue_delayed_work(rpciod_workqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) &pipe->queue_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) RPC_UPCALL_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) list_add_tail(&msg->list, &pipe->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) pipe->pipelen += msg->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) dentry = dget(pipe->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) spin_unlock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) wake_up(&RPC_I(d_inode(dentry))->waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) EXPORT_SYMBOL_GPL(rpc_queue_upcall);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) rpc_inode_setowner(struct inode *inode, void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) RPC_I(inode)->private = private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) rpc_close_pipes(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct rpc_pipe *pipe = RPC_I(inode)->pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) int need_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) LIST_HEAD(free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) spin_lock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) need_release = pipe->nreaders != 0 || pipe->nwriters != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) pipe->nreaders = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) list_splice_init(&pipe->in_upcall, &free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) list_splice_init(&pipe->pipe, &free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) pipe->pipelen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) pipe->dentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) spin_unlock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) rpc_purge_list(&RPC_I(inode)->waitq, &free_list, pipe->ops->destroy_msg, -EPIPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) pipe->nwriters = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (need_release && pipe->ops->release_pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) pipe->ops->release_pipe(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) cancel_delayed_work_sync(&pipe->queue_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) rpc_inode_setowner(inode, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) RPC_I(inode)->pipe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static struct inode *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) rpc_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct rpc_inode *rpci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) rpci = kmem_cache_alloc(rpc_inode_cachep, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (!rpci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return &rpci->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) rpc_free_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) kmem_cache_free(rpc_inode_cachep, RPC_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) rpc_pipe_open(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct rpc_pipe *pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) int first_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) int res = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) pipe = RPC_I(inode)->pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (pipe == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) first_open = pipe->nreaders == 0 && pipe->nwriters == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (first_open && pipe->ops->open_pipe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) res = pipe->ops->open_pipe(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (filp->f_mode & FMODE_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) pipe->nreaders++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (filp->f_mode & FMODE_WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) pipe->nwriters++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) rpc_pipe_release(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct rpc_pipe *pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct rpc_pipe_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int last_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) pipe = RPC_I(inode)->pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (pipe == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) msg = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (msg != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) spin_lock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) msg->errno = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) list_del_init(&msg->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) spin_unlock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) pipe->ops->destroy_msg(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (filp->f_mode & FMODE_WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) pipe->nwriters --;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (filp->f_mode & FMODE_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) pipe->nreaders --;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (pipe->nreaders == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) LIST_HEAD(free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) spin_lock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) list_splice_init(&pipe->pipe, &free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) pipe->pipelen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) spin_unlock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) rpc_purge_list(&RPC_I(inode)->waitq, &free_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) pipe->ops->destroy_msg, -EAGAIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) last_close = pipe->nwriters == 0 && pipe->nreaders == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (last_close && pipe->ops->release_pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) pipe->ops->release_pipe(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) rpc_pipe_read(struct file *filp, char __user *buf, size_t len, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) struct inode *inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct rpc_pipe *pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct rpc_pipe_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) pipe = RPC_I(inode)->pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (pipe == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) res = -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) msg = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (msg == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) spin_lock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (!list_empty(&pipe->pipe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) msg = list_entry(pipe->pipe.next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct rpc_pipe_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) list_move(&msg->list, &pipe->in_upcall);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) pipe->pipelen -= msg->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) filp->private_data = msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) msg->copied = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) spin_unlock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (msg == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) /* NOTE: it is up to the callback to update msg->copied */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) res = pipe->ops->upcall(filp, msg, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (res < 0 || msg->len == msg->copied) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) filp->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) spin_lock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) list_del_init(&msg->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) spin_unlock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) pipe->ops->destroy_msg(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) rpc_pipe_write(struct file *filp, const char __user *buf, size_t len, loff_t *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct inode *inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) res = -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (RPC_I(inode)->pipe != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) res = RPC_I(inode)->pipe->ops->downcall(filp, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static __poll_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) rpc_pipe_poll(struct file *filp, struct poll_table_struct *wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct inode *inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) struct rpc_inode *rpci = RPC_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) __poll_t mask = EPOLLOUT | EPOLLWRNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) poll_wait(filp, &rpci->waitq, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) if (rpci->pipe == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) mask |= EPOLLERR | EPOLLHUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) else if (filp->private_data || !list_empty(&rpci->pipe->pipe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) mask |= EPOLLIN | EPOLLRDNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) return mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) rpc_pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) struct inode *inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) struct rpc_pipe *pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) case FIONREAD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) pipe = RPC_I(inode)->pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (pipe == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) spin_lock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) len = pipe->pipelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (filp->private_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) struct rpc_pipe_msg *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) msg = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) len += msg->len - msg->copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) spin_unlock(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return put_user(len, (int __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static const struct file_operations rpc_pipe_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) .llseek = no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) .read = rpc_pipe_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) .write = rpc_pipe_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) .poll = rpc_pipe_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) .unlocked_ioctl = rpc_pipe_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) .open = rpc_pipe_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) .release = rpc_pipe_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) rpc_show_info(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct rpc_clnt *clnt = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) seq_printf(m, "RPC server: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) rcu_dereference(clnt->cl_xprt)->servername);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) seq_printf(m, "service: %s (%d) version %d\n", clnt->cl_program->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) clnt->cl_prog, clnt->cl_vers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) seq_printf(m, "address: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_ADDR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) seq_printf(m, "protocol: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_PROTO));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) seq_printf(m, "port: %s\n", rpc_peeraddr2str(clnt, RPC_DISPLAY_PORT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) rpc_info_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) struct rpc_clnt *clnt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) int ret = single_open(file, rpc_show_info, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct seq_file *m = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) spin_lock(&file->f_path.dentry->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) if (!d_unhashed(file->f_path.dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) clnt = RPC_I(inode)->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (clnt != NULL && atomic_inc_not_zero(&clnt->cl_count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) spin_unlock(&file->f_path.dentry->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) m->private = clnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) spin_unlock(&file->f_path.dentry->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) single_release(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) rpc_info_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) struct seq_file *m = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct rpc_clnt *clnt = (struct rpc_clnt *)m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (clnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) rpc_release_client(clnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) return single_release(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) static const struct file_operations rpc_info_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) .open = rpc_info_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) .read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) .llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) .release = rpc_info_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * Description of fs contents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct rpc_filelist {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) const struct file_operations *i_fop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) umode_t mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static struct inode *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) rpc_get_inode(struct super_block *sb, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) struct inode *inode = new_inode(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) inode->i_ino = get_next_ino();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) inode->i_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) switch (mode & S_IFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) case S_IFDIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) inode->i_fop = &simple_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) inode->i_op = &simple_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) inc_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) static int __rpc_create_common(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) const struct file_operations *i_fop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) d_drop(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) inode = rpc_get_inode(dir->i_sb, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) inode->i_ino = iunique(dir->i_sb, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) if (i_fop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) inode->i_fop = i_fop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) rpc_inode_setowner(inode, private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) d_add(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) printk(KERN_WARNING "%s: %s failed to allocate inode for dentry %pd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) __FILE__, __func__, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) static int __rpc_create(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) const struct file_operations *i_fop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) err = __rpc_create_common(dir, dentry, S_IFREG | mode, i_fop, private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) fsnotify_create(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static int __rpc_mkdir(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) const struct file_operations *i_fop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) err = __rpc_create_common(dir, dentry, S_IFDIR | mode, i_fop, private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) inc_nlink(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) fsnotify_mkdir(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) init_pipe(struct rpc_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) pipe->nreaders = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) pipe->nwriters = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) INIT_LIST_HEAD(&pipe->in_upcall);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) INIT_LIST_HEAD(&pipe->in_downcall);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) INIT_LIST_HEAD(&pipe->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) pipe->pipelen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) INIT_DELAYED_WORK(&pipe->queue_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) rpc_timeout_upcall_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) pipe->ops = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) spin_lock_init(&pipe->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) pipe->dentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) void rpc_destroy_pipe_data(struct rpc_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) kfree(pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) EXPORT_SYMBOL_GPL(rpc_destroy_pipe_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) struct rpc_pipe *rpc_mkpipe_data(const struct rpc_pipe_ops *ops, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) struct rpc_pipe *pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) pipe = kzalloc(sizeof(struct rpc_pipe), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (!pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) init_pipe(pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) pipe->ops = ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) pipe->flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) return pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) EXPORT_SYMBOL_GPL(rpc_mkpipe_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) static int __rpc_mkpipe_dentry(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) const struct file_operations *i_fop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) void *private,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) struct rpc_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) struct rpc_inode *rpci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) err = __rpc_create_common(dir, dentry, S_IFIFO | mode, i_fop, private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) rpci = RPC_I(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) rpci->private = private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) rpci->pipe = pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) fsnotify_create(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) static int __rpc_rmdir(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) dget(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) ret = simple_rmdir(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) d_drop(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) fsnotify_rmdir(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) static int __rpc_unlink(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) dget(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) ret = simple_unlink(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) d_drop(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) fsnotify_unlink(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) static int __rpc_rmpipe(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) rpc_close_pipes(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) return __rpc_unlink(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) static struct dentry *__rpc_lookup_create_exclusive(struct dentry *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) struct qstr q = QSTR_INIT(name, strlen(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) struct dentry *dentry = d_hash_and_lookup(parent, &q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) if (!dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) dentry = d_alloc(parent, &q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (!dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) if (d_really_is_negative(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) return ERR_PTR(-EEXIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) * FIXME: This probably has races.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) static void __rpc_depopulate(struct dentry *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) const struct rpc_filelist *files,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) int start, int eof)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) struct inode *dir = d_inode(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) struct qstr name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) for (i = start; i < eof; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) name.name = files[i].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) name.len = strlen(files[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) dentry = d_hash_and_lookup(parent, &name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) if (dentry == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) if (d_really_is_negative(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) switch (d_inode(dentry)->i_mode & S_IFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) case S_IFREG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) __rpc_unlink(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) case S_IFDIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) __rpc_rmdir(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) static void rpc_depopulate(struct dentry *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) const struct rpc_filelist *files,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) int start, int eof)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) struct inode *dir = d_inode(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) inode_lock_nested(dir, I_MUTEX_CHILD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) __rpc_depopulate(parent, files, start, eof);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) inode_unlock(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) static int rpc_populate(struct dentry *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) const struct rpc_filelist *files,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) int start, int eof,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) struct inode *dir = d_inode(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) inode_lock(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) for (i = start; i < eof; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) dentry = __rpc_lookup_create_exclusive(parent, files[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) err = PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) if (IS_ERR(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) goto out_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) switch (files[i].mode & S_IFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) case S_IFREG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) err = __rpc_create(dir, dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) files[i].mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) files[i].i_fop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) case S_IFDIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) err = __rpc_mkdir(dir, dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) files[i].mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) goto out_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) inode_unlock(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) out_bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) __rpc_depopulate(parent, files, start, eof);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) inode_unlock(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) printk(KERN_WARNING "%s: %s failed to populate directory %pd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) __FILE__, __func__, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) static struct dentry *rpc_mkdir_populate(struct dentry *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) const char *name, umode_t mode, void *private,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) int (*populate)(struct dentry *, void *), void *args_populate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) struct inode *dir = d_inode(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) inode_lock_nested(dir, I_MUTEX_PARENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) dentry = __rpc_lookup_create_exclusive(parent, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) if (IS_ERR(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) error = __rpc_mkdir(dir, dentry, mode, NULL, private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (error != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) if (populate != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) error = populate(dentry, args_populate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) goto err_rmdir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) inode_unlock(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) err_rmdir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) __rpc_rmdir(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) dentry = ERR_PTR(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) static int rpc_rmdir_depopulate(struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) void (*depopulate)(struct dentry *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) struct dentry *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) struct inode *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) parent = dget_parent(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) dir = d_inode(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) inode_lock_nested(dir, I_MUTEX_PARENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) if (depopulate != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) depopulate(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) error = __rpc_rmdir(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) inode_unlock(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) dput(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) * rpc_mkpipe - make an rpc_pipefs file for kernel<->userspace communication
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) * @parent: dentry of directory to create new "pipe" in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) * @name: name of pipe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) * @private: private data to associate with the pipe, for the caller's use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) * @pipe: &rpc_pipe containing input parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) * Data is made available for userspace to read by calls to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) * rpc_queue_upcall(). The actual reads will result in calls to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) * @ops->upcall, which will be called with the file pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) * message, and userspace buffer to copy to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) * Writes can come at any time, and do not necessarily have to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) * responses to upcalls. They will result in calls to @msg->downcall.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) * The @private argument passed here will be available to all these methods
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) * from the file pointer, via RPC_I(file_inode(file))->private.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) struct dentry *rpc_mkpipe_dentry(struct dentry *parent, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) void *private, struct rpc_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) struct inode *dir = d_inode(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) umode_t umode = S_IFIFO | 0600;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) if (pipe->ops->upcall == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) umode &= ~0444;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) if (pipe->ops->downcall == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) umode &= ~0222;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) inode_lock_nested(dir, I_MUTEX_PARENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) dentry = __rpc_lookup_create_exclusive(parent, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) if (IS_ERR(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) err = __rpc_mkpipe_dentry(dir, dentry, umode, &rpc_pipe_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) private, pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) inode_unlock(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) dentry = ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) printk(KERN_WARNING "%s: %s() failed to create pipe %pd/%s (errno = %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) __FILE__, __func__, parent, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) EXPORT_SYMBOL_GPL(rpc_mkpipe_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) * rpc_unlink - remove a pipe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) * @dentry: dentry for the pipe, as returned from rpc_mkpipe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) * After this call, lookups will no longer find the pipe, and any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) * attempts to read or write using preexisting opens of the pipe will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) * return -EPIPE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) rpc_unlink(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) struct dentry *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) struct inode *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) parent = dget_parent(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) dir = d_inode(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) inode_lock_nested(dir, I_MUTEX_PARENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) error = __rpc_rmpipe(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) inode_unlock(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) dput(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) EXPORT_SYMBOL_GPL(rpc_unlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) * rpc_init_pipe_dir_head - initialise a struct rpc_pipe_dir_head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) * @pdh: pointer to struct rpc_pipe_dir_head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) void rpc_init_pipe_dir_head(struct rpc_pipe_dir_head *pdh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) INIT_LIST_HEAD(&pdh->pdh_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) pdh->pdh_dentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) EXPORT_SYMBOL_GPL(rpc_init_pipe_dir_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) * rpc_init_pipe_dir_object - initialise a struct rpc_pipe_dir_object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) * @pdo: pointer to struct rpc_pipe_dir_object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) * @pdo_ops: pointer to const struct rpc_pipe_dir_object_ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) * @pdo_data: pointer to caller-defined data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) void rpc_init_pipe_dir_object(struct rpc_pipe_dir_object *pdo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) const struct rpc_pipe_dir_object_ops *pdo_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) void *pdo_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) INIT_LIST_HEAD(&pdo->pdo_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) pdo->pdo_ops = pdo_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) pdo->pdo_data = pdo_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) EXPORT_SYMBOL_GPL(rpc_init_pipe_dir_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) rpc_add_pipe_dir_object_locked(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) struct rpc_pipe_dir_head *pdh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) struct rpc_pipe_dir_object *pdo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) if (pdh->pdh_dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) ret = pdo->pdo_ops->create(pdh->pdh_dentry, pdo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) list_add_tail(&pdo->pdo_head, &pdh->pdh_entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) rpc_remove_pipe_dir_object_locked(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) struct rpc_pipe_dir_head *pdh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) struct rpc_pipe_dir_object *pdo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) if (pdh->pdh_dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) pdo->pdo_ops->destroy(pdh->pdh_dentry, pdo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) list_del_init(&pdo->pdo_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) * rpc_add_pipe_dir_object - associate a rpc_pipe_dir_object to a directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) * @net: pointer to struct net
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) * @pdh: pointer to struct rpc_pipe_dir_head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) * @pdo: pointer to struct rpc_pipe_dir_object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) rpc_add_pipe_dir_object(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) struct rpc_pipe_dir_head *pdh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) struct rpc_pipe_dir_object *pdo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) if (list_empty(&pdo->pdo_head)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) mutex_lock(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) ret = rpc_add_pipe_dir_object_locked(net, pdh, pdo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) mutex_unlock(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) EXPORT_SYMBOL_GPL(rpc_add_pipe_dir_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) * rpc_remove_pipe_dir_object - remove a rpc_pipe_dir_object from a directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) * @net: pointer to struct net
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) * @pdh: pointer to struct rpc_pipe_dir_head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) * @pdo: pointer to struct rpc_pipe_dir_object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) rpc_remove_pipe_dir_object(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) struct rpc_pipe_dir_head *pdh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) struct rpc_pipe_dir_object *pdo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) if (!list_empty(&pdo->pdo_head)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) mutex_lock(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) rpc_remove_pipe_dir_object_locked(net, pdh, pdo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) mutex_unlock(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) EXPORT_SYMBOL_GPL(rpc_remove_pipe_dir_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) * rpc_find_or_alloc_pipe_dir_object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) * @net: pointer to struct net
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) * @pdh: pointer to struct rpc_pipe_dir_head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) * @match: match struct rpc_pipe_dir_object to data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) * @alloc: allocate a new struct rpc_pipe_dir_object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) * @data: user defined data for match() and alloc()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) struct rpc_pipe_dir_object *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) rpc_find_or_alloc_pipe_dir_object(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) struct rpc_pipe_dir_head *pdh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) int (*match)(struct rpc_pipe_dir_object *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) struct rpc_pipe_dir_object *(*alloc)(void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) struct rpc_pipe_dir_object *pdo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) mutex_lock(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) list_for_each_entry(pdo, &pdh->pdh_entries, pdo_head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) if (!match(pdo, data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) pdo = alloc(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) if (!pdo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) rpc_add_pipe_dir_object_locked(net, pdh, pdo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) mutex_unlock(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) return pdo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) EXPORT_SYMBOL_GPL(rpc_find_or_alloc_pipe_dir_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) rpc_create_pipe_dir_objects(struct rpc_pipe_dir_head *pdh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) struct rpc_pipe_dir_object *pdo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) struct dentry *dir = pdh->pdh_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) list_for_each_entry(pdo, &pdh->pdh_entries, pdo_head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) pdo->pdo_ops->create(dir, pdo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) rpc_destroy_pipe_dir_objects(struct rpc_pipe_dir_head *pdh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) struct rpc_pipe_dir_object *pdo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) struct dentry *dir = pdh->pdh_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) list_for_each_entry(pdo, &pdh->pdh_entries, pdo_head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) pdo->pdo_ops->destroy(dir, pdo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) RPCAUTH_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) RPCAUTH_EOF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) static const struct rpc_filelist authfiles[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) [RPCAUTH_info] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) .name = "info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) .i_fop = &rpc_info_operations,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) .mode = S_IFREG | 0400,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) static int rpc_clntdir_populate(struct dentry *dentry, void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) return rpc_populate(dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) authfiles, RPCAUTH_info, RPCAUTH_EOF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) static void rpc_clntdir_depopulate(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) rpc_depopulate(dentry, authfiles, RPCAUTH_info, RPCAUTH_EOF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) * rpc_create_client_dir - Create a new rpc_client directory in rpc_pipefs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) * @dentry: the parent of new directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) * @name: the name of new directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) * @rpc_client: rpc client to associate with this directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) * This creates a directory at the given @path associated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) * @rpc_clnt, which will contain a file named "info" with some basic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) * information about the client, together with any "pipes" that may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) * later be created using rpc_mkpipe().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) struct dentry *rpc_create_client_dir(struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) struct rpc_clnt *rpc_client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) struct dentry *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) ret = rpc_mkdir_populate(dentry, name, 0555, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) rpc_clntdir_populate, rpc_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) if (!IS_ERR(ret)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) rpc_client->cl_pipedir_objects.pdh_dentry = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) rpc_create_pipe_dir_objects(&rpc_client->cl_pipedir_objects);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) * rpc_remove_client_dir - Remove a directory created with rpc_create_client_dir()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) * @rpc_client: rpc_client for the pipe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) int rpc_remove_client_dir(struct rpc_clnt *rpc_client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) struct dentry *dentry = rpc_client->cl_pipedir_objects.pdh_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) if (dentry == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) rpc_destroy_pipe_dir_objects(&rpc_client->cl_pipedir_objects);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) rpc_client->cl_pipedir_objects.pdh_dentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) return rpc_rmdir_depopulate(dentry, rpc_clntdir_depopulate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) static const struct rpc_filelist cache_pipefs_files[3] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) [0] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) .name = "channel",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) .i_fop = &cache_file_operations_pipefs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) .mode = S_IFREG | 0600,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) [1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) .name = "content",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) .i_fop = &content_file_operations_pipefs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) .mode = S_IFREG | 0400,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) [2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) .name = "flush",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) .i_fop = &cache_flush_operations_pipefs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) .mode = S_IFREG | 0600,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) static int rpc_cachedir_populate(struct dentry *dentry, void *private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) return rpc_populate(dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) cache_pipefs_files, 0, 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) static void rpc_cachedir_depopulate(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) rpc_depopulate(dentry, cache_pipefs_files, 0, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) struct dentry *rpc_create_cache_dir(struct dentry *parent, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) umode_t umode, struct cache_detail *cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) return rpc_mkdir_populate(parent, name, umode, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) rpc_cachedir_populate, cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) void rpc_remove_cache_dir(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) rpc_rmdir_depopulate(dentry, rpc_cachedir_depopulate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) * populate the filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) static const struct super_operations s_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) .alloc_inode = rpc_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) .free_inode = rpc_free_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) .statfs = simple_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) #define RPCAUTH_GSSMAGIC 0x67596969
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) * We have a single directory with 1 node in it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) RPCAUTH_lockd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) RPCAUTH_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) RPCAUTH_nfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) RPCAUTH_portmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) RPCAUTH_statd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) RPCAUTH_nfsd4_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) RPCAUTH_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) RPCAUTH_nfsd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) RPCAUTH_gssd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) RPCAUTH_RootEOF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) static const struct rpc_filelist files[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) [RPCAUTH_lockd] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) .name = "lockd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) .mode = S_IFDIR | 0555,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) [RPCAUTH_mount] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) .name = "mount",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) .mode = S_IFDIR | 0555,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) [RPCAUTH_nfs] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) .name = "nfs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) .mode = S_IFDIR | 0555,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) [RPCAUTH_portmap] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) .name = "portmap",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) .mode = S_IFDIR | 0555,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) [RPCAUTH_statd] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) .name = "statd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) .mode = S_IFDIR | 0555,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) [RPCAUTH_nfsd4_cb] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) .name = "nfsd4_cb",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) .mode = S_IFDIR | 0555,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) [RPCAUTH_cache] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) .name = "cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) .mode = S_IFDIR | 0555,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) [RPCAUTH_nfsd] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) .name = "nfsd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) .mode = S_IFDIR | 0555,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) [RPCAUTH_gssd] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) .name = "gssd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) .mode = S_IFDIR | 0555,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) * This call can be used only in RPC pipefs mount notification hooks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) struct dentry *rpc_d_lookup_sb(const struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) const unsigned char *dir_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) struct qstr dir = QSTR_INIT(dir_name, strlen(dir_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) return d_hash_and_lookup(sb->s_root, &dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) EXPORT_SYMBOL_GPL(rpc_d_lookup_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) int rpc_pipefs_init_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) sn->gssd_dummy = rpc_mkpipe_data(&gssd_dummy_pipe_ops, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) if (IS_ERR(sn->gssd_dummy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) return PTR_ERR(sn->gssd_dummy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) mutex_init(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) sn->pipe_version = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) void rpc_pipefs_exit_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) rpc_destroy_pipe_data(sn->gssd_dummy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) * This call will be used for per network namespace operations calls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) * Note: Function will be returned with pipefs_sb_lock taken if superblock was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) * found. This lock have to be released by rpc_put_sb_net() when all operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) * will be completed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) struct super_block *rpc_get_sb_net(const struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) mutex_lock(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) if (sn->pipefs_sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) return sn->pipefs_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) mutex_unlock(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) EXPORT_SYMBOL_GPL(rpc_get_sb_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) void rpc_put_sb_net(const struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) WARN_ON(sn->pipefs_sb == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) mutex_unlock(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) EXPORT_SYMBOL_GPL(rpc_put_sb_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) static const struct rpc_filelist gssd_dummy_clnt_dir[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) [0] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) .name = "clntXX",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) .mode = S_IFDIR | 0555,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) dummy_downcall(struct file *filp, const char __user *src, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) static const struct rpc_pipe_ops gssd_dummy_pipe_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) .upcall = rpc_pipe_generic_upcall,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) .downcall = dummy_downcall,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) * Here we present a bogus "info" file to keep rpc.gssd happy. We don't expect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) * that it will ever use this info to handle an upcall, but rpc.gssd expects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) * that this file will be there and have a certain format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) rpc_dummy_info_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) seq_printf(m, "RPC server: %s\n", utsname()->nodename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) seq_printf(m, "service: foo (1) version 0\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) seq_printf(m, "address: 127.0.0.1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) seq_printf(m, "protocol: tcp\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) seq_printf(m, "port: 0\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) DEFINE_SHOW_ATTRIBUTE(rpc_dummy_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) static const struct rpc_filelist gssd_dummy_info_file[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) [0] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) .name = "info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) .i_fop = &rpc_dummy_info_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) .mode = S_IFREG | 0400,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) * rpc_gssd_dummy_populate - create a dummy gssd pipe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) * @root: root of the rpc_pipefs filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) * @pipe_data: pipe data created when netns is initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) * Create a dummy set of directories and a pipe that gssd can hold open to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) * indicate that it is up and running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) static struct dentry *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) rpc_gssd_dummy_populate(struct dentry *root, struct rpc_pipe *pipe_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) struct dentry *gssd_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) struct dentry *clnt_dentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) struct dentry *pipe_dentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) struct qstr q = QSTR_INIT(files[RPCAUTH_gssd].name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) strlen(files[RPCAUTH_gssd].name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) /* We should never get this far if "gssd" doesn't exist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) gssd_dentry = d_hash_and_lookup(root, &q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) if (!gssd_dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) ret = rpc_populate(gssd_dentry, gssd_dummy_clnt_dir, 0, 1, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) pipe_dentry = ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) q.name = gssd_dummy_clnt_dir[0].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) q.len = strlen(gssd_dummy_clnt_dir[0].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) clnt_dentry = d_hash_and_lookup(gssd_dentry, &q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) if (!clnt_dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) __rpc_depopulate(gssd_dentry, gssd_dummy_clnt_dir, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) pipe_dentry = ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) ret = rpc_populate(clnt_dentry, gssd_dummy_info_file, 0, 1, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) __rpc_depopulate(gssd_dentry, gssd_dummy_clnt_dir, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) pipe_dentry = ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) pipe_dentry = rpc_mkpipe_dentry(clnt_dentry, "gssd", NULL, pipe_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) if (IS_ERR(pipe_dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) __rpc_depopulate(clnt_dentry, gssd_dummy_info_file, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) __rpc_depopulate(gssd_dentry, gssd_dummy_clnt_dir, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) dput(clnt_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) dput(gssd_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) return pipe_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) rpc_gssd_dummy_depopulate(struct dentry *pipe_dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) struct dentry *clnt_dir = pipe_dentry->d_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) struct dentry *gssd_dir = clnt_dir->d_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) dget(pipe_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) __rpc_rmpipe(d_inode(clnt_dir), pipe_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) __rpc_depopulate(clnt_dir, gssd_dummy_info_file, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) __rpc_depopulate(gssd_dir, gssd_dummy_clnt_dir, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) dput(pipe_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) rpc_fill_super(struct super_block *sb, struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) struct dentry *root, *gssd_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) struct net *net = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) sb->s_blocksize = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) sb->s_blocksize_bits = PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) sb->s_magic = RPCAUTH_GSSMAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) sb->s_op = &s_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) sb->s_d_op = &simple_dentry_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) sb->s_time_gran = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) inode = rpc_get_inode(sb, S_IFDIR | 0555);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) sb->s_root = root = d_make_root(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) if (!root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) if (rpc_populate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) gssd_dentry = rpc_gssd_dummy_populate(root, sn->gssd_dummy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) if (IS_ERR(gssd_dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) __rpc_depopulate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) return PTR_ERR(gssd_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) dprintk("RPC: sending pipefs MOUNT notification for net %x%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) net->ns.inum, NET_NAME(net));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) mutex_lock(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) sn->pipefs_sb = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) err = blocking_notifier_call_chain(&rpc_pipefs_notifier_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) RPC_PIPEFS_MOUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) goto err_depopulate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) mutex_unlock(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) err_depopulate:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) rpc_gssd_dummy_depopulate(gssd_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) blocking_notifier_call_chain(&rpc_pipefs_notifier_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) RPC_PIPEFS_UMOUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) sn->pipefs_sb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) __rpc_depopulate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) mutex_unlock(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) gssd_running(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) struct rpc_pipe *pipe = sn->gssd_dummy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) return pipe->nreaders || pipe->nwriters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) EXPORT_SYMBOL_GPL(gssd_running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) static int rpc_fs_get_tree(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) return get_tree_keyed(fc, rpc_fill_super, get_net(fc->net_ns));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) static void rpc_fs_free_fc(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) if (fc->s_fs_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) put_net(fc->s_fs_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) static const struct fs_context_operations rpc_fs_context_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) .free = rpc_fs_free_fc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) .get_tree = rpc_fs_get_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) static int rpc_init_fs_context(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) put_user_ns(fc->user_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) fc->user_ns = get_user_ns(fc->net_ns->user_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) fc->ops = &rpc_fs_context_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) static void rpc_kill_sb(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) struct net *net = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) mutex_lock(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) if (sn->pipefs_sb != sb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) mutex_unlock(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) sn->pipefs_sb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) dprintk("RPC: sending pipefs UMOUNT notification for net %x%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) net->ns.inum, NET_NAME(net));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) blocking_notifier_call_chain(&rpc_pipefs_notifier_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) RPC_PIPEFS_UMOUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) mutex_unlock(&sn->pipefs_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) kill_litter_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) put_net(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) static struct file_system_type rpc_pipe_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) .name = "rpc_pipefs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) .init_fs_context = rpc_init_fs_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) .kill_sb = rpc_kill_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) MODULE_ALIAS_FS("rpc_pipefs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) MODULE_ALIAS("rpc_pipefs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) init_once(void *foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) struct rpc_inode *rpci = (struct rpc_inode *) foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) inode_init_once(&rpci->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) rpci->private = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) rpci->pipe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) init_waitqueue_head(&rpci->waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) int register_rpc_pipefs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) rpc_inode_cachep = kmem_cache_create("rpc_inode_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) sizeof(struct rpc_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) SLAB_MEM_SPREAD|SLAB_ACCOUNT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) if (!rpc_inode_cachep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) err = rpc_clients_notifier_register();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) goto err_notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) err = register_filesystem(&rpc_pipe_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) goto err_register;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) err_register:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) rpc_clients_notifier_unregister();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) err_notifier:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) kmem_cache_destroy(rpc_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) void unregister_rpc_pipefs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) rpc_clients_notifier_unregister();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) unregister_filesystem(&rpc_pipe_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) kmem_cache_destroy(rpc_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) }