1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * V9FS definitions.
4 *
5 * Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
6 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
7 */
8 #ifndef FS_9P_V9FS_H
9 #define FS_9P_V9FS_H
10
11 #include <linux/backing-dev.h>
12 #include <linux/netfs.h>
13 #include <linux/fs_parser.h>
14 #include <net/9p/client.h>
15 #include <net/9p/transport.h>
16
17 /**
18 * enum p9_session_flags - option flags for each 9P session
19 * @V9FS_PROTO_2000U: whether or not to use 9P2000.u extensions
20 * @V9FS_PROTO_2000L: whether or not to use 9P2000.l extensions
21 * @V9FS_ACCESS_SINGLE: only the mounting user can access the hierarchy
22 * @V9FS_ACCESS_USER: a new attach will be issued for every user (default)
23 * @V9FS_ACCESS_CLIENT: Just like user, but access check is performed on client.
24 * @V9FS_ACCESS_ANY: use a single attach for all users
25 * @V9FS_ACCESS_MASK: bit mask of different ACCESS options
26 * @V9FS_POSIX_ACL: POSIX ACLs are enforced
27 * @V9FS_NDENTRY_TIMEOUT_SET: Has negative dentry timeout retention time been
28 * overridden by negtimeout mount option
29 *
30 * Session flags reflect options selected by users at mount time
31 */
32 #define V9FS_ACCESS_ANY (V9FS_ACCESS_SINGLE | \
33 V9FS_ACCESS_USER | \
34 V9FS_ACCESS_CLIENT)
35 #define V9FS_ACCESS_MASK V9FS_ACCESS_ANY
36 #define V9FS_ACL_MASK V9FS_POSIX_ACL
37
38 enum p9_session_flags {
39 V9FS_PROTO_2000U = 0x01,
40 V9FS_PROTO_2000L = 0x02,
41 V9FS_ACCESS_SINGLE = 0x04,
42 V9FS_ACCESS_USER = 0x08,
43 V9FS_ACCESS_CLIENT = 0x10,
44 V9FS_POSIX_ACL = 0x20,
45 V9FS_NO_XATTR = 0x40,
46 V9FS_IGNORE_QV = 0x80, /* ignore qid.version for cache hints */
47 V9FS_DIRECT_IO = 0x100,
48 V9FS_SYNC = 0x200,
49 V9FS_NDENTRY_TIMEOUT_SET = 0x400,
50 };
51
52 /**
53 * enum p9_cache_shortcuts - human readable cache preferences
54 * @CACHE_SC_NONE: disable all caches
55 * @CACHE_SC_READAHEAD: only provide caching for readahead
56 * @CACHE_SC_MMAP: provide caching to enable mmap
57 * @CACHE_SC_LOOSE: non-coherent caching for files and meta data
58 * @CACHE_SC_FSCACHE: persistent non-coherent caching for files and meta-data
59 *
60 */
61
62 enum p9_cache_shortcuts {
63 CACHE_SC_NONE = 0b00000000,
64 CACHE_SC_READAHEAD = 0b00000001,
65 CACHE_SC_MMAP = 0b00000101,
66 CACHE_SC_LOOSE = 0b00001111,
67 CACHE_SC_FSCACHE = 0b10001111,
68 };
69
70 /**
71 * enum p9_cache_bits - possible values of ->cache
72 * @CACHE_NONE: caches disabled
73 * @CACHE_FILE: file caching (open to close)
74 * @CACHE_META: meta-data and directory caching
75 * @CACHE_WRITEBACK: write-back caching for files
76 * @CACHE_LOOSE: don't check cache consistency
77 * @CACHE_FSCACHE: local persistent caches
78 *
79 */
80
81 enum p9_cache_bits {
82 CACHE_NONE = 0b00000000,
83 CACHE_FILE = 0b00000001,
84 CACHE_META = 0b00000010,
85 CACHE_WRITEBACK = 0b00000100,
86 CACHE_LOOSE = 0b00001000,
87 CACHE_FSCACHE = 0b10000000,
88 };
89
90 /**
91 * struct v9fs_session_info - per-instance session information
92 * @flags: session options of type &p9_session_flags
93 * @nodev: set to 1 to disable device mapping
94 * @debug: debug level
95 * @afid: authentication handle
96 * @cache: cache mode of type &p9_cache_bits
97 * @ndentry_timeout: Negative dentry lookup cache retention time in ms
98 * @cachetag: the tag of the cache associated with this session
99 * @fscache: session cookie associated with FS-Cache
100 * @uname: string user name to mount hierarchy as
101 * @aname: mount specifier for remote hierarchy
102 * @maxdata: maximum data to be sent/recvd per protocol message
103 * @dfltuid: default numeric userid to mount hierarchy as
104 * @dfltgid: default numeric groupid to mount hierarchy as
105 * @uid: if %V9FS_ACCESS_SINGLE, the numeric uid which mounted the hierarchy
106 * @clnt: reference to 9P network client instantiated for this session
107 * @slist: reference to list of registered 9p sessions
108 * @ndentry_timeout_ms: Negative dentry caching retention time
109 *
110 * This structure holds state for each session instance established during
111 * a sys_mount() .
112 *
113 * Bugs: there seems to be a lot of state which could be condensed and/or
114 * removed.
115 */
116
117 struct v9fs_session_info {
118 /* options */
119 unsigned int flags;
120 unsigned char nodev;
121 unsigned short debug;
122 unsigned int afid;
123 unsigned int cache;
124 unsigned int ndentry_timeout_ms;
125 #ifdef CONFIG_9P_FSCACHE
126 char *cachetag;
127 struct fscache_volume *fscache;
128 #endif
129
130 char *uname; /* user name to mount as */
131 char *aname; /* name of remote hierarchy being mounted */
132 unsigned int maxdata; /* max data for client interface */
133 kuid_t dfltuid; /* default uid/muid for legacy support */
134 kgid_t dfltgid; /* default gid for legacy support */
135 kuid_t uid; /* if ACCESS_SINGLE, the uid that has access */
136 struct p9_client *clnt; /* 9p client */
137 struct list_head slist; /* list of sessions registered with v9fs */
138 struct rw_semaphore rename_sem;
139 long session_lock_timeout; /* retry interval for blocking locks */
140 struct rcu_head rcu; /* v9fs_vfs_get_link_dotl() reads ->cache in rcu pathwalk */
141 };
142
143 #define NDENTRY_TIMEOUT_NEVER (-1U)
144
145 /* cache_validity flags */
146 #define V9FS_INO_INVALID_ATTR 0x01
147
148 struct v9fs_inode {
149 struct netfs_inode netfs; /* Netfslib context and vfs inode */
150 struct p9_qid qid;
151 unsigned int cache_validity;
152 struct mutex v_mutex;
153 };
154
V9FS_I(const struct inode * inode)155 static inline struct v9fs_inode *V9FS_I(const struct inode *inode)
156 {
157 return container_of(inode, struct v9fs_inode, netfs.inode);
158 }
159
v9fs_inode_cookie(struct v9fs_inode * v9inode)160 static inline struct fscache_cookie *v9fs_inode_cookie(struct v9fs_inode *v9inode)
161 {
162 #ifdef CONFIG_9P_FSCACHE
163 return netfs_i_cookie(&v9inode->netfs);
164 #else
165 return NULL;
166 #endif
167 }
168
v9fs_session_cache(struct v9fs_session_info * v9ses)169 static inline struct fscache_volume *v9fs_session_cache(struct v9fs_session_info *v9ses)
170 {
171 #ifdef CONFIG_9P_FSCACHE
172 return v9ses->fscache;
173 #else
174 return NULL;
175 #endif
176 }
177
178 extern const struct fs_parameter_spec v9fs_param_spec[];
179
180 extern int v9fs_parse_param(struct fs_context *fc, struct fs_parameter *param);
181 extern int v9fs_show_options(struct seq_file *m, struct dentry *root);
182
183 struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
184 struct fs_context *fc);
185 extern void v9fs_session_close(struct v9fs_session_info *v9ses);
186 extern void v9fs_session_cancel(struct v9fs_session_info *v9ses);
187 extern void v9fs_session_begin_cancel(struct v9fs_session_info *v9ses);
188 extern struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
189 unsigned int flags);
190 extern int v9fs_vfs_unlink(struct inode *i, struct dentry *d);
191 extern int v9fs_vfs_rmdir(struct inode *i, struct dentry *d);
192 extern int v9fs_vfs_rename(const struct mnt_idmap *idmap,
193 struct inode *old_dir, struct dentry *old_dentry,
194 struct inode *new_dir, struct dentry *new_dentry,
195 unsigned int flags);
196 extern struct inode *v9fs_inode_from_fid(struct v9fs_session_info *v9ses,
197 struct p9_fid *fid,
198 struct super_block *sb, int new);
199 extern const struct inode_operations v9fs_dir_inode_operations_dotl;
200 extern const struct inode_operations v9fs_file_inode_operations_dotl;
201 extern const struct inode_operations v9fs_symlink_inode_operations_dotl;
202 extern const struct netfs_request_ops v9fs_req_ops;
203 extern struct inode *v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses,
204 struct p9_fid *fid,
205 struct super_block *sb, int new);
206
207 /* other default globals */
208 #define V9FS_PORT 564
209 #define V9FS_DEFUSER "nobody"
210 #define V9FS_DEFANAME ""
211 #define V9FS_DEFUID KUIDT_INIT(-2)
212 #define V9FS_DEFGID KGIDT_INIT(-2)
213
v9fs_inode2v9ses(struct inode * inode)214 static inline struct v9fs_session_info *v9fs_inode2v9ses(struct inode *inode)
215 {
216 return inode->i_sb->s_fs_info;
217 }
218
v9fs_dentry2v9ses(const struct dentry * dentry)219 static inline struct v9fs_session_info *v9fs_dentry2v9ses(const struct dentry *dentry)
220 {
221 return dentry->d_sb->s_fs_info;
222 }
223
v9fs_proto_dotu(struct v9fs_session_info * v9ses)224 static inline int v9fs_proto_dotu(struct v9fs_session_info *v9ses)
225 {
226 return v9ses->flags & V9FS_PROTO_2000U;
227 }
228
v9fs_proto_dotl(struct v9fs_session_info * v9ses)229 static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses)
230 {
231 return v9ses->flags & V9FS_PROTO_2000L;
232 }
233
234 /**
235 * v9fs_get_inode_from_fid - Helper routine to populate an inode by
236 * issuing a attribute request
237 * @v9ses: session information
238 * @fid: fid to issue attribute request for
239 * @sb: superblock on which to create inode
240 *
241 */
242 static inline struct inode *
v9fs_get_inode_from_fid(struct v9fs_session_info * v9ses,struct p9_fid * fid,struct super_block * sb)243 v9fs_get_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
244 struct super_block *sb)
245 {
246 if (v9fs_proto_dotl(v9ses))
247 return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 0);
248 else
249 return v9fs_inode_from_fid(v9ses, fid, sb, 0);
250 }
251
252 /**
253 * v9fs_get_new_inode_from_fid - Helper routine to populate an inode by
254 * issuing a attribute request
255 * @v9ses: session information
256 * @fid: fid to issue attribute request for
257 * @sb: superblock on which to create inode
258 *
259 */
260 static inline struct inode *
v9fs_get_new_inode_from_fid(struct v9fs_session_info * v9ses,struct p9_fid * fid,struct super_block * sb)261 v9fs_get_new_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
262 struct super_block *sb)
263 {
264 if (v9fs_proto_dotl(v9ses))
265 return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 1);
266 else
267 return v9fs_inode_from_fid(v9ses, fid, sb, 1);
268 }
269
270 #endif
271