1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_SUNRPC_RPC_PIPE_FS_H
3 #define _LINUX_SUNRPC_RPC_PIPE_FS_H
4 
5 #ifdef __KERNEL__
6 
7 #include <linux/workqueue.h>
8 
9 struct rpc_pipe_dir_head {
10 	struct list_head pdh_entries;
11 	struct dentry *pdh_dentry;
12 };
13 
14 struct rpc_pipe_dir_object_ops;
15 struct rpc_pipe_dir_object {
16 	struct list_head pdo_head;
17 	const struct rpc_pipe_dir_object_ops *pdo_ops;
18 
19 	void *pdo_data;
20 };
21 
22 struct rpc_pipe_dir_object_ops {
23 	int (*create)(struct dentry *dir,
24 			struct rpc_pipe_dir_object *pdo);
25 	void (*destroy)(struct dentry *dir,
26 			struct rpc_pipe_dir_object *pdo);
27 };
28 
29 struct rpc_pipe_msg {
30 	struct list_head list;
31 	void *data;
32 	size_t len;
33 	size_t copied;
34 	int errno;
35 };
36 
37 struct rpc_pipe_ops {
38 	ssize_t (*upcall)(struct file *, struct rpc_pipe_msg *, char __user *, size_t);
39 	ssize_t (*downcall)(struct file *, const char __user *, size_t);
40 	void (*release_pipe)(struct inode *);
41 	int (*open_pipe)(struct inode *);
42 	void (*destroy_msg)(struct rpc_pipe_msg *);
43 };
44 
45 struct rpc_pipe {
46 	struct list_head pipe;
47 	struct list_head in_upcall;
48 	struct list_head in_downcall;
49 	int pipelen;
50 	int nreaders;
51 	int nwriters;
52 #define RPC_PIPE_WAIT_FOR_OPEN	1
53 	int flags;
54 	struct delayed_work queue_timeout;
55 	const struct rpc_pipe_ops *ops;
56 	spinlock_t lock;
57 	struct dentry *dentry;
58 };
59 
60 struct rpc_inode {
61 	struct inode vfs_inode;
62 	void *private;
63 	struct rpc_pipe *pipe;
64 	wait_queue_head_t waitq;
65 };
66 
67 static inline struct rpc_inode *
RPC_I(struct inode * inode)68 RPC_I(struct inode *inode)
69 {
70 	return container_of(inode, struct rpc_inode, vfs_inode);
71 }
72 
73 enum {
74 	SUNRPC_PIPEFS_NFS_PRIO,
75 	SUNRPC_PIPEFS_RPC_PRIO,
76 };
77 
78 extern int rpc_pipefs_notifier_register(struct notifier_block *);
79 extern void rpc_pipefs_notifier_unregister(struct notifier_block *);
80 
81 enum {
82 	RPC_PIPEFS_MOUNT,
83 	RPC_PIPEFS_UMOUNT,
84 };
85 
86 extern struct dentry *rpc_d_lookup_sb(const struct super_block *sb,
87 				      const unsigned char *dir_name);
88 extern int rpc_pipefs_init_net(struct net *net);
89 extern void rpc_pipefs_exit_net(struct net *net);
90 extern struct super_block *rpc_get_sb_net(const struct net *net);
91 extern void rpc_put_sb_net(const struct net *net);
92 
93 extern ssize_t rpc_pipe_generic_upcall(struct file *, struct rpc_pipe_msg *,
94 				       char __user *, size_t);
95 extern int rpc_queue_upcall(struct rpc_pipe *, struct rpc_pipe_msg *);
96 
97 /* returns true if the msg is in-flight, i.e., already eaten by the peer */
rpc_msg_is_inflight(const struct rpc_pipe_msg * msg)98 static inline bool rpc_msg_is_inflight(const struct rpc_pipe_msg *msg) {
99 	return (msg->copied != 0 && list_empty(&msg->list));
100 }
101 
102 struct rpc_clnt;
103 extern struct dentry *rpc_create_client_dir(struct dentry *, const char *, struct rpc_clnt *);
104 extern int rpc_remove_client_dir(struct rpc_clnt *);
105 
106 extern void rpc_init_pipe_dir_head(struct rpc_pipe_dir_head *pdh);
107 extern void rpc_init_pipe_dir_object(struct rpc_pipe_dir_object *pdo,
108 		const struct rpc_pipe_dir_object_ops *pdo_ops,
109 		void *pdo_data);
110 extern int rpc_add_pipe_dir_object(struct net *net,
111 		struct rpc_pipe_dir_head *pdh,
112 		struct rpc_pipe_dir_object *pdo);
113 extern void rpc_remove_pipe_dir_object(struct net *net,
114 		struct rpc_pipe_dir_head *pdh,
115 		struct rpc_pipe_dir_object *pdo);
116 extern struct rpc_pipe_dir_object *rpc_find_or_alloc_pipe_dir_object(
117 		struct net *net,
118 		struct rpc_pipe_dir_head *pdh,
119 		int (*match)(struct rpc_pipe_dir_object *, void *),
120 		struct rpc_pipe_dir_object *(*alloc)(void *),
121 		void *data);
122 
123 struct cache_detail;
124 extern struct dentry *rpc_create_cache_dir(struct dentry *,
125 					   const char *,
126 					   umode_t umode,
127 					   struct cache_detail *);
128 extern void rpc_remove_cache_dir(struct dentry *);
129 
130 struct rpc_pipe *rpc_mkpipe_data(const struct rpc_pipe_ops *ops, int flags);
131 void rpc_destroy_pipe_data(struct rpc_pipe *pipe);
132 extern struct dentry *rpc_mkpipe_dentry(struct dentry *, const char *, void *,
133 					struct rpc_pipe *);
134 extern int rpc_unlink(struct dentry *);
135 extern int register_rpc_pipefs(void);
136 extern void unregister_rpc_pipefs(void);
137 
138 extern bool gssd_running(struct net *net);
139 
140 #endif
141 #endif
142