xref: /linux/fs/9p/v9fs.h (revision 95f41d87810083d8b3dedcce46a4e356cf4a9673)
11f327613SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
29e82cf6aSEric Van Hensbergen /*
39e82cf6aSEric Van Hensbergen  * V9FS definitions.
49e82cf6aSEric Van Hensbergen  *
58a0dc95fSEric Van Hensbergen  *  Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
69e82cf6aSEric Van Hensbergen  *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
79e82cf6aSEric Van Hensbergen  */
8e0459f57SAneesh Kumar K.V #ifndef FS_9P_V9FS_H
9e0459f57SAneesh Kumar K.V #define FS_9P_V9FS_H
10e0459f57SAneesh Kumar K.V 
110ed07ddbSJens Axboe #include <linux/backing-dev.h>
12bc899ee1SDavid Howells #include <linux/netfs.h>
139e82cf6aSEric Van Hensbergen 
14ee443996SEric Van Hensbergen /**
15ee443996SEric Van Hensbergen  * enum p9_session_flags - option flags for each 9P session
16dd6102fbSSripathi Kodi  * @V9FS_PROTO_2000U: whether or not to use 9P2000.u extensions
1745bc21edSSripathi Kodi  * @V9FS_PROTO_2000L: whether or not to use 9P2000.l extensions
18ee443996SEric Van Hensbergen  * @V9FS_ACCESS_SINGLE: only the mounting user can access the hierarchy
19ee443996SEric Van Hensbergen  * @V9FS_ACCESS_USER: a new attach will be issued for every user (default)
20e782ef71SVenkateswararao Jujjuri (JV)  * @V9FS_ACCESS_CLIENT: Just like user, but access check is performed on client.
21ee443996SEric Van Hensbergen  * @V9FS_ACCESS_ANY: use a single attach for all users
22ee443996SEric Van Hensbergen  * @V9FS_ACCESS_MASK: bit mask of different ACCESS options
23e782ef71SVenkateswararao Jujjuri (JV)  * @V9FS_POSIX_ACL: POSIX ACLs are enforced
249e82cf6aSEric Van Hensbergen  *
25ee443996SEric Van Hensbergen  * Session flags reflect options selected by users at mount time
26ee443996SEric Van Hensbergen  */
2776381a42SAneesh Kumar K.V #define	V9FS_ACCESS_ANY (V9FS_ACCESS_SINGLE | \
2876381a42SAneesh Kumar K.V 			 V9FS_ACCESS_USER |   \
2976381a42SAneesh Kumar K.V 			 V9FS_ACCESS_CLIENT)
3076381a42SAneesh Kumar K.V #define V9FS_ACCESS_MASK V9FS_ACCESS_ANY
31e782ef71SVenkateswararao Jujjuri (JV) #define V9FS_ACL_MASK V9FS_POSIX_ACL
3276381a42SAneesh Kumar K.V 
33ee443996SEric Van Hensbergen enum p9_session_flags {
34dd6102fbSSripathi Kodi 	V9FS_PROTO_2000U    = 0x01,
3545bc21edSSripathi Kodi 	V9FS_PROTO_2000L    = 0x02,
36dd6102fbSSripathi Kodi 	V9FS_ACCESS_SINGLE  = 0x04,
37dd6102fbSSripathi Kodi 	V9FS_ACCESS_USER    = 0x08,
38e782ef71SVenkateswararao Jujjuri (JV) 	V9FS_ACCESS_CLIENT  = 0x10,
398142db4fSEric Van Hensbergen 	V9FS_POSIX_ACL      = 0x20,
406deffc89SEric Van Hensbergen 	V9FS_NO_XATTR       = 0x40,
416deffc89SEric Van Hensbergen 	V9FS_IGNORE_QV      = 0x80, /* ignore qid.version for cache hints */
426deffc89SEric Van Hensbergen 	V9FS_DIRECT_IO      = 0x100,
436deffc89SEric Van Hensbergen 	V9FS_SYNC           = 0x200
44ee443996SEric Van Hensbergen };
45ee443996SEric Van Hensbergen 
46ee443996SEric Van Hensbergen /**
474eb31178SEric Van Hensbergen  * enum p9_cache_shortcuts - human readable cache preferences
484eb31178SEric Van Hensbergen  * @CACHE_SC_NONE: disable all caches
494eb31178SEric Van Hensbergen  * @CACHE_SC_READAHEAD: only provide caching for readahead
504eb31178SEric Van Hensbergen  * @CACHE_SC_MMAP: provide caching to enable mmap
514eb31178SEric Van Hensbergen  * @CACHE_SC_LOOSE: non-coherent caching for files and meta data
524eb31178SEric Van Hensbergen  * @CACHE_SC_FSCACHE: persistent non-coherent caching for files and meta-data
53ee443996SEric Van Hensbergen  *
54ee443996SEric Van Hensbergen  */
55ee443996SEric Van Hensbergen 
564eb31178SEric Van Hensbergen enum p9_cache_shortcuts {
574eb31178SEric Van Hensbergen 	CACHE_SC_NONE       = 0b00000000,
584eb31178SEric Van Hensbergen 	CACHE_SC_READAHEAD  = 0b00000001,
594eb31178SEric Van Hensbergen 	CACHE_SC_MMAP       = 0b00000101,
604eb31178SEric Van Hensbergen 	CACHE_SC_LOOSE      = 0b00001111,
614eb31178SEric Van Hensbergen 	CACHE_SC_FSCACHE    = 0b10001111,
624eb31178SEric Van Hensbergen };
634eb31178SEric Van Hensbergen 
644eb31178SEric Van Hensbergen /**
654eb31178SEric Van Hensbergen  * enum p9_cache_bits - possible values of ->cache
664eb31178SEric Van Hensbergen  * @CACHE_NONE: caches disabled
674eb31178SEric Van Hensbergen  * @CACHE_FILE: file caching (open to close)
684eb31178SEric Van Hensbergen  * @CACHE_META: meta-data and directory caching
694eb31178SEric Van Hensbergen  * @CACHE_WRITEBACK: write-back caching for files
704eb31178SEric Van Hensbergen  * @CACHE_LOOSE: don't check cache consistency
714eb31178SEric Van Hensbergen  * @CACHE_FSCACHE: local persistent caches
724eb31178SEric Van Hensbergen  *
734eb31178SEric Van Hensbergen  */
744eb31178SEric Van Hensbergen 
754eb31178SEric Van Hensbergen enum p9_cache_bits {
764eb31178SEric Van Hensbergen 	CACHE_NONE          = 0b00000000,
774eb31178SEric Van Hensbergen 	CACHE_FILE          = 0b00000001,
784eb31178SEric Van Hensbergen 	CACHE_META          = 0b00000010,
794eb31178SEric Van Hensbergen 	CACHE_WRITEBACK     = 0b00000100,
804eb31178SEric Van Hensbergen 	CACHE_LOOSE         = 0b00001000,
814eb31178SEric Van Hensbergen 	CACHE_FSCACHE       = 0b10000000,
82ee443996SEric Van Hensbergen };
83ee443996SEric Van Hensbergen 
84ee443996SEric Van Hensbergen /**
85ee443996SEric Van Hensbergen  * struct v9fs_session_info - per-instance session information
86ee443996SEric Van Hensbergen  * @flags: session options of type &p9_session_flags
87ee443996SEric Van Hensbergen  * @nodev: set to 1 to disable device mapping
88ee443996SEric Van Hensbergen  * @debug: debug level
89ee443996SEric Van Hensbergen  * @afid: authentication handle
904eb31178SEric Van Hensbergen  * @cache: cache mode of type &p9_cache_bits
9160e78d2cSAbhishek Kulkarni  * @cachetag: the tag of the cache associated with this session
9260e78d2cSAbhishek Kulkarni  * @fscache: session cookie associated with FS-Cache
93ee443996SEric Van Hensbergen  * @uname: string user name to mount hierarchy as
94ee443996SEric Van Hensbergen  * @aname: mount specifier for remote hierarchy
95ee443996SEric Van Hensbergen  * @maxdata: maximum data to be sent/recvd per protocol message
96ee443996SEric Van Hensbergen  * @dfltuid: default numeric userid to mount hierarchy as
97ee443996SEric Van Hensbergen  * @dfltgid: default numeric groupid to mount hierarchy as
98ee443996SEric Van Hensbergen  * @uid: if %V9FS_ACCESS_SINGLE, the numeric uid which mounted the hierarchy
99ee443996SEric Van Hensbergen  * @clnt: reference to 9P network client instantiated for this session
10060e78d2cSAbhishek Kulkarni  * @slist: reference to list of registered 9p sessions
101ee443996SEric Van Hensbergen  *
102ee443996SEric Van Hensbergen  * This structure holds state for each session instance established during
103ee443996SEric Van Hensbergen  * a sys_mount() .
104ee443996SEric Van Hensbergen  *
105ee443996SEric Van Hensbergen  * Bugs: there seems to be a lot of state which could be condensed and/or
106ee443996SEric Van Hensbergen  * removed.
1079e82cf6aSEric Van Hensbergen  */
1089e82cf6aSEric Van Hensbergen 
1099e82cf6aSEric Van Hensbergen struct v9fs_session_info {
1109e82cf6aSEric Van Hensbergen 	/* options */
111*95f41d87SChristophe JAILLET 	unsigned int flags;
112ee443996SEric Van Hensbergen 	unsigned char nodev;
113ee443996SEric Van Hensbergen 	unsigned short debug;
114ee443996SEric Van Hensbergen 	unsigned int afid;
115ee443996SEric Van Hensbergen 	unsigned int cache;
11660e78d2cSAbhishek Kulkarni #ifdef CONFIG_9P_FSCACHE
11760e78d2cSAbhishek Kulkarni 	char *cachetag;
11824e42e32SDavid Howells 	struct fscache_volume *fscache;
11960e78d2cSAbhishek Kulkarni #endif
1209e82cf6aSEric Van Hensbergen 
121ba17674fSLatchesar Ionkov 	char *uname;		/* user name to mount as */
122ba17674fSLatchesar Ionkov 	char *aname;		/* name of remote hierarchy being mounted */
1238a0dc95fSEric Van Hensbergen 	unsigned int maxdata;	/* max data for client interface */
12476ed23a5SEric W. Biederman 	kuid_t dfltuid;		/* default uid/muid for legacy support */
12576ed23a5SEric W. Biederman 	kgid_t dfltgid;		/* default gid for legacy support */
12676ed23a5SEric W. Biederman 	kuid_t uid;		/* if ACCESS_SINGLE, the uid that has access */
127bd238fb4SLatchesar Ionkov 	struct p9_client *clnt;	/* 9p client */
12860e78d2cSAbhishek Kulkarni 	struct list_head slist; /* list of sessions registered with v9fs */
129a534c8d1SAneesh Kumar K.V 	struct rw_semaphore rename_sem;
1305e172f75SDinu-Razvan Chis-Serban 	long session_lock_timeout; /* retry interval for blocking locks */
1319e82cf6aSEric Van Hensbergen };
1329e82cf6aSEric Van Hensbergen 
133b3cbea03SAneesh Kumar K.V /* cache_validity flags */
134b3cbea03SAneesh Kumar K.V #define V9FS_INO_INVALID_ATTR 0x01
135b3cbea03SAneesh Kumar K.V 
136a78ce05dSAneesh Kumar K.V struct v9fs_inode {
137874c8ca1SDavid Howells 	struct netfs_inode netfs; /* Netfslib context and vfs inode */
138fd2421f5SAneesh Kumar K.V 	struct p9_qid qid;
139b3cbea03SAneesh Kumar K.V 	unsigned int cache_validity;
1405a7e0a8cSAneesh Kumar K.V 	struct mutex v_mutex;
141a78ce05dSAneesh Kumar K.V };
142a78ce05dSAneesh Kumar K.V 
143a78ce05dSAneesh Kumar K.V static inline struct v9fs_inode *V9FS_I(const struct inode *inode)
144a78ce05dSAneesh Kumar K.V {
145874c8ca1SDavid Howells 	return container_of(inode, struct v9fs_inode, netfs.inode);
146a78ce05dSAneesh Kumar K.V }
147a78ce05dSAneesh Kumar K.V 
148eb497943SDavid Howells static inline struct fscache_cookie *v9fs_inode_cookie(struct v9fs_inode *v9inode)
149eb497943SDavid Howells {
150eb497943SDavid Howells #ifdef CONFIG_9P_FSCACHE
151e81fb419SLinus Torvalds 	return netfs_i_cookie(&v9inode->netfs);
152eb497943SDavid Howells #else
153eb497943SDavid Howells 	return NULL;
154eb497943SDavid Howells #endif
155eb497943SDavid Howells }
156eb497943SDavid Howells 
15724e42e32SDavid Howells static inline struct fscache_volume *v9fs_session_cache(struct v9fs_session_info *v9ses)
15824e42e32SDavid Howells {
15924e42e32SDavid Howells #ifdef CONFIG_9P_FSCACHE
16024e42e32SDavid Howells 	return v9ses->fscache;
16124e42e32SDavid Howells #else
16224e42e32SDavid Howells 	return NULL;
16324e42e32SDavid Howells #endif
16424e42e32SDavid Howells }
16524e42e32SDavid Howells 
16624e42e32SDavid Howells 
167c4fac910SDavid Howells extern int v9fs_show_options(struct seq_file *m, struct dentry *root);
168c4fac910SDavid Howells 
169772712c5SSohaib Mohamed struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
170772712c5SSohaib Mohamed 				 const char *dev_name, char *data);
17153c06f4eSAneesh Kumar K.V extern void v9fs_session_close(struct v9fs_session_info *v9ses);
17253c06f4eSAneesh Kumar K.V extern void v9fs_session_cancel(struct v9fs_session_info *v9ses);
17353c06f4eSAneesh Kumar K.V extern void v9fs_session_begin_cancel(struct v9fs_session_info *v9ses);
17453c06f4eSAneesh Kumar K.V extern struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
17500cd8dd3SAl Viro 				      unsigned int flags);
17653c06f4eSAneesh Kumar K.V extern int v9fs_vfs_unlink(struct inode *i, struct dentry *d);
17753c06f4eSAneesh Kumar K.V extern int v9fs_vfs_rmdir(struct inode *i, struct dentry *d);
178e18275aeSChristian Brauner extern int v9fs_vfs_rename(struct mnt_idmap *idmap,
179549c7297SChristian Brauner 			   struct inode *old_dir, struct dentry *old_dentry,
1801cd66c93SMiklos Szeredi 			   struct inode *new_dir, struct dentry *new_dentry,
1811cd66c93SMiklos Szeredi 			   unsigned int flags);
182a78ce05dSAneesh Kumar K.V extern struct inode *v9fs_inode_from_fid(struct v9fs_session_info *v9ses,
18353c06f4eSAneesh Kumar K.V 					 struct p9_fid *fid,
184ed80fcfaSAneesh Kumar K.V 					 struct super_block *sb, int new);
18553c06f4eSAneesh Kumar K.V extern const struct inode_operations v9fs_dir_inode_operations_dotl;
18653c06f4eSAneesh Kumar K.V extern const struct inode_operations v9fs_file_inode_operations_dotl;
18753c06f4eSAneesh Kumar K.V extern const struct inode_operations v9fs_symlink_inode_operations_dotl;
188bc899ee1SDavid Howells extern const struct netfs_request_ops v9fs_req_ops;
189a78ce05dSAneesh Kumar K.V extern struct inode *v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses,
19053c06f4eSAneesh Kumar K.V 					      struct p9_fid *fid,
191ed80fcfaSAneesh Kumar K.V 					      struct super_block *sb, int new);
1929e82cf6aSEric Van Hensbergen 
1939e82cf6aSEric Van Hensbergen /* other default globals */
1949e82cf6aSEric Van Hensbergen #define V9FS_PORT	564
1959e82cf6aSEric Van Hensbergen #define V9FS_DEFUSER	"nobody"
1969e82cf6aSEric Van Hensbergen #define V9FS_DEFANAME	""
19776ed23a5SEric W. Biederman #define V9FS_DEFUID	KUIDT_INIT(-2)
19876ed23a5SEric W. Biederman #define V9FS_DEFGID	KGIDT_INIT(-2)
1999e82cf6aSEric Van Hensbergen 
200bd238fb4SLatchesar Ionkov static inline struct v9fs_session_info *v9fs_inode2v9ses(struct inode *inode)
201bd238fb4SLatchesar Ionkov {
202772712c5SSohaib Mohamed 	return inode->i_sb->s_fs_info;
203bd238fb4SLatchesar Ionkov }
2042405669bSLatchesar Ionkov 
20542869c8aSAneesh Kumar K.V static inline struct v9fs_session_info *v9fs_dentry2v9ses(struct dentry *dentry)
20642869c8aSAneesh Kumar K.V {
20742869c8aSAneesh Kumar K.V 	return dentry->d_sb->s_fs_info;
20842869c8aSAneesh Kumar K.V }
20942869c8aSAneesh Kumar K.V 
210dd6102fbSSripathi Kodi static inline int v9fs_proto_dotu(struct v9fs_session_info *v9ses)
2112405669bSLatchesar Ionkov {
212dd6102fbSSripathi Kodi 	return v9ses->flags & V9FS_PROTO_2000U;
213dd6102fbSSripathi Kodi }
214dd6102fbSSripathi Kodi 
215dd6102fbSSripathi Kodi static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses)
216dd6102fbSSripathi Kodi {
21745bc21edSSripathi Kodi 	return v9ses->flags & V9FS_PROTO_2000L;
2182405669bSLatchesar Ionkov }
21953c06f4eSAneesh Kumar K.V 
22053c06f4eSAneesh Kumar K.V /**
221a78ce05dSAneesh Kumar K.V  * v9fs_get_inode_from_fid - Helper routine to populate an inode by
22253c06f4eSAneesh Kumar K.V  * issuing a attribute request
22353c06f4eSAneesh Kumar K.V  * @v9ses: session information
22453c06f4eSAneesh Kumar K.V  * @fid: fid to issue attribute request for
22553c06f4eSAneesh Kumar K.V  * @sb: superblock on which to create inode
22653c06f4eSAneesh Kumar K.V  *
22753c06f4eSAneesh Kumar K.V  */
22853c06f4eSAneesh Kumar K.V static inline struct inode *
229a78ce05dSAneesh Kumar K.V v9fs_get_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
23053c06f4eSAneesh Kumar K.V 			struct super_block *sb)
23153c06f4eSAneesh Kumar K.V {
23253c06f4eSAneesh Kumar K.V 	if (v9fs_proto_dotl(v9ses))
233ed80fcfaSAneesh Kumar K.V 		return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 0);
23453c06f4eSAneesh Kumar K.V 	else
235ed80fcfaSAneesh Kumar K.V 		return v9fs_inode_from_fid(v9ses, fid, sb, 0);
23653c06f4eSAneesh Kumar K.V }
237ed80fcfaSAneesh Kumar K.V 
238ed80fcfaSAneesh Kumar K.V /**
239ed80fcfaSAneesh Kumar K.V  * v9fs_get_new_inode_from_fid - Helper routine to populate an inode by
240ed80fcfaSAneesh Kumar K.V  * issuing a attribute request
241ed80fcfaSAneesh Kumar K.V  * @v9ses: session information
242ed80fcfaSAneesh Kumar K.V  * @fid: fid to issue attribute request for
243ed80fcfaSAneesh Kumar K.V  * @sb: superblock on which to create inode
244ed80fcfaSAneesh Kumar K.V  *
245ed80fcfaSAneesh Kumar K.V  */
246ed80fcfaSAneesh Kumar K.V static inline struct inode *
247ed80fcfaSAneesh Kumar K.V v9fs_get_new_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
248ed80fcfaSAneesh Kumar K.V 			    struct super_block *sb)
249ed80fcfaSAneesh Kumar K.V {
250ed80fcfaSAneesh Kumar K.V 	if (v9fs_proto_dotl(v9ses))
251ed80fcfaSAneesh Kumar K.V 		return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 1);
252ed80fcfaSAneesh Kumar K.V 	else
253ed80fcfaSAneesh Kumar K.V 		return v9fs_inode_from_fid(v9ses, fid, sb, 1);
254ed80fcfaSAneesh Kumar K.V }
255ed80fcfaSAneesh Kumar K.V 
256e0459f57SAneesh Kumar K.V #endif
257