xref: /linux/fs/9p/v9fs.h (revision fb89b45cdfdc8bdab93986f1bc1474e313295c31)
19e82cf6aSEric Van Hensbergen /*
29e82cf6aSEric Van Hensbergen  * V9FS definitions.
39e82cf6aSEric Van Hensbergen  *
48a0dc95fSEric Van Hensbergen  *  Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
59e82cf6aSEric Van Hensbergen  *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
69e82cf6aSEric Van Hensbergen  *
79e82cf6aSEric Van Hensbergen  *  This program is free software; you can redistribute it and/or modify
842e8c509SEric Van Hensbergen  *  it under the terms of the GNU General Public License version 2
942e8c509SEric Van Hensbergen  *  as published by the Free Software Foundation.
109e82cf6aSEric Van Hensbergen  *
119e82cf6aSEric Van Hensbergen  *  This program is distributed in the hope that it will be useful,
129e82cf6aSEric Van Hensbergen  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
139e82cf6aSEric Van Hensbergen  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
149e82cf6aSEric Van Hensbergen  *  GNU General Public License for more details.
159e82cf6aSEric Van Hensbergen  *
169e82cf6aSEric Van Hensbergen  *  You should have received a copy of the GNU General Public License
179e82cf6aSEric Van Hensbergen  *  along with this program; if not, write to:
189e82cf6aSEric Van Hensbergen  *  Free Software Foundation
199e82cf6aSEric Van Hensbergen  *  51 Franklin Street, Fifth Floor
209e82cf6aSEric Van Hensbergen  *  Boston, MA  02111-1301  USA
219e82cf6aSEric Van Hensbergen  *
229e82cf6aSEric Van Hensbergen  */
23e0459f57SAneesh Kumar K.V #ifndef FS_9P_V9FS_H
24e0459f57SAneesh Kumar K.V #define FS_9P_V9FS_H
25e0459f57SAneesh Kumar K.V 
260ed07ddbSJens Axboe #include <linux/backing-dev.h>
279e82cf6aSEric Van Hensbergen 
28ee443996SEric Van Hensbergen /**
29ee443996SEric Van Hensbergen  * enum p9_session_flags - option flags for each 9P session
30dd6102fbSSripathi Kodi  * @V9FS_PROTO_2000U: whether or not to use 9P2000.u extensions
3145bc21edSSripathi Kodi  * @V9FS_PROTO_2000L: whether or not to use 9P2000.l extensions
32ee443996SEric Van Hensbergen  * @V9FS_ACCESS_SINGLE: only the mounting user can access the hierarchy
33ee443996SEric Van Hensbergen  * @V9FS_ACCESS_USER: a new attach will be issued for every user (default)
34e782ef71SVenkateswararao Jujjuri (JV)  * @V9FS_ACCESS_CLIENT: Just like user, but access check is performed on client.
35ee443996SEric Van Hensbergen  * @V9FS_ACCESS_ANY: use a single attach for all users
36ee443996SEric Van Hensbergen  * @V9FS_ACCESS_MASK: bit mask of different ACCESS options
37e782ef71SVenkateswararao Jujjuri (JV)  * @V9FS_POSIX_ACL: POSIX ACLs are enforced
389e82cf6aSEric Van Hensbergen  *
39ee443996SEric Van Hensbergen  * Session flags reflect options selected by users at mount time
40ee443996SEric Van Hensbergen  */
4176381a42SAneesh Kumar K.V #define	V9FS_ACCESS_ANY (V9FS_ACCESS_SINGLE | \
4276381a42SAneesh Kumar K.V 			 V9FS_ACCESS_USER |   \
4376381a42SAneesh Kumar K.V 			 V9FS_ACCESS_CLIENT)
4476381a42SAneesh Kumar K.V #define V9FS_ACCESS_MASK V9FS_ACCESS_ANY
45e782ef71SVenkateswararao Jujjuri (JV) #define V9FS_ACL_MASK V9FS_POSIX_ACL
4676381a42SAneesh Kumar K.V 
47ee443996SEric Van Hensbergen enum p9_session_flags {
48dd6102fbSSripathi Kodi 	V9FS_PROTO_2000U	= 0x01,
4945bc21edSSripathi Kodi 	V9FS_PROTO_2000L	= 0x02,
50dd6102fbSSripathi Kodi 	V9FS_ACCESS_SINGLE	= 0x04,
51dd6102fbSSripathi Kodi 	V9FS_ACCESS_USER	= 0x08,
52e782ef71SVenkateswararao Jujjuri (JV) 	V9FS_ACCESS_CLIENT	= 0x10,
53e782ef71SVenkateswararao Jujjuri (JV) 	V9FS_POSIX_ACL		= 0x20
54ee443996SEric Van Hensbergen };
55ee443996SEric Van Hensbergen 
56ee443996SEric Van Hensbergen /* possible values of ->cache */
57ee443996SEric Van Hensbergen /**
58ee443996SEric Van Hensbergen  * enum p9_cache_modes - user specified cache preferences
59ee443996SEric Van Hensbergen  * @CACHE_NONE: do not cache data, dentries, or directory contents (default)
60ee443996SEric Van Hensbergen  * @CACHE_LOOSE: cache data, dentries, and directory contents w/no consistency
61ee443996SEric Van Hensbergen  *
62ee443996SEric Van Hensbergen  * eventually support loose, tight, time, session, default always none
63ee443996SEric Van Hensbergen  */
64ee443996SEric Van Hensbergen 
65ee443996SEric Van Hensbergen enum p9_cache_modes {
66ee443996SEric Van Hensbergen 	CACHE_NONE,
67*fb89b45cSDominique Martinet 	CACHE_MMAP,
68ee443996SEric Van Hensbergen 	CACHE_LOOSE,
6960e78d2cSAbhishek Kulkarni 	CACHE_FSCACHE,
70ee443996SEric Van Hensbergen };
71ee443996SEric Van Hensbergen 
72ee443996SEric Van Hensbergen /**
73ee443996SEric Van Hensbergen  * struct v9fs_session_info - per-instance session information
74ee443996SEric Van Hensbergen  * @flags: session options of type &p9_session_flags
75ee443996SEric Van Hensbergen  * @nodev: set to 1 to disable device mapping
76ee443996SEric Van Hensbergen  * @debug: debug level
77ee443996SEric Van Hensbergen  * @afid: authentication handle
78ee443996SEric Van Hensbergen  * @cache: cache mode of type &p9_cache_modes
7960e78d2cSAbhishek Kulkarni  * @cachetag: the tag of the cache associated with this session
8060e78d2cSAbhishek Kulkarni  * @fscache: session cookie associated with FS-Cache
81ee443996SEric Van Hensbergen  * @options: copy of options string given by user
82ee443996SEric Van Hensbergen  * @uname: string user name to mount hierarchy as
83ee443996SEric Van Hensbergen  * @aname: mount specifier for remote hierarchy
84ee443996SEric Van Hensbergen  * @maxdata: maximum data to be sent/recvd per protocol message
85ee443996SEric Van Hensbergen  * @dfltuid: default numeric userid to mount hierarchy as
86ee443996SEric Van Hensbergen  * @dfltgid: default numeric groupid to mount hierarchy as
87ee443996SEric Van Hensbergen  * @uid: if %V9FS_ACCESS_SINGLE, the numeric uid which mounted the hierarchy
88ee443996SEric Van Hensbergen  * @clnt: reference to 9P network client instantiated for this session
8960e78d2cSAbhishek Kulkarni  * @slist: reference to list of registered 9p sessions
90ee443996SEric Van Hensbergen  *
91ee443996SEric Van Hensbergen  * This structure holds state for each session instance established during
92ee443996SEric Van Hensbergen  * a sys_mount() .
93ee443996SEric Van Hensbergen  *
94ee443996SEric Van Hensbergen  * Bugs: there seems to be a lot of state which could be condensed and/or
95ee443996SEric Van Hensbergen  * removed.
969e82cf6aSEric Van Hensbergen  */
979e82cf6aSEric Van Hensbergen 
989e82cf6aSEric Van Hensbergen struct v9fs_session_info {
999e82cf6aSEric Van Hensbergen 	/* options */
100ee443996SEric Van Hensbergen 	unsigned char flags;
101ee443996SEric Van Hensbergen 	unsigned char nodev;
102ee443996SEric Van Hensbergen 	unsigned short debug;
103ee443996SEric Van Hensbergen 	unsigned int afid;
104ee443996SEric Van Hensbergen 	unsigned int cache;
10560e78d2cSAbhishek Kulkarni #ifdef CONFIG_9P_FSCACHE
10660e78d2cSAbhishek Kulkarni 	char *cachetag;
10760e78d2cSAbhishek Kulkarni 	struct fscache_cookie *fscache;
10860e78d2cSAbhishek Kulkarni #endif
1099e82cf6aSEric Van Hensbergen 
110ba17674fSLatchesar Ionkov 	char *uname;		/* user name to mount as */
111ba17674fSLatchesar Ionkov 	char *aname;		/* name of remote hierarchy being mounted */
1128a0dc95fSEric Van Hensbergen 	unsigned int maxdata;	/* max data for client interface */
11376ed23a5SEric W. Biederman 	kuid_t dfltuid;		/* default uid/muid for legacy support */
11476ed23a5SEric W. Biederman 	kgid_t dfltgid;		/* default gid for legacy support */
11576ed23a5SEric W. Biederman 	kuid_t uid;		/* if ACCESS_SINGLE, the uid that has access */
116bd238fb4SLatchesar Ionkov 	struct p9_client *clnt;	/* 9p client */
11760e78d2cSAbhishek Kulkarni 	struct list_head slist; /* list of sessions registered with v9fs */
1180ed07ddbSJens Axboe 	struct backing_dev_info bdi;
119a534c8d1SAneesh Kumar K.V 	struct rw_semaphore rename_sem;
1209e82cf6aSEric Van Hensbergen };
1219e82cf6aSEric Van Hensbergen 
122b3cbea03SAneesh Kumar K.V /* cache_validity flags */
123b3cbea03SAneesh Kumar K.V #define V9FS_INO_INVALID_ATTR 0x01
124b3cbea03SAneesh Kumar K.V 
125a78ce05dSAneesh Kumar K.V struct v9fs_inode {
126a78ce05dSAneesh Kumar K.V #ifdef CONFIG_9P_FSCACHE
127a78ce05dSAneesh Kumar K.V 	spinlock_t fscache_lock;
128a78ce05dSAneesh Kumar K.V 	struct fscache_cookie *fscache;
129a78ce05dSAneesh Kumar K.V #endif
130fd2421f5SAneesh Kumar K.V 	struct p9_qid qid;
131b3cbea03SAneesh Kumar K.V 	unsigned int cache_validity;
1326b39f6d2SAneesh Kumar K.V 	struct p9_fid *writeback_fid;
1335a7e0a8cSAneesh Kumar K.V 	struct mutex v_mutex;
134a78ce05dSAneesh Kumar K.V 	struct inode vfs_inode;
135a78ce05dSAneesh Kumar K.V };
136a78ce05dSAneesh Kumar K.V 
137a78ce05dSAneesh Kumar K.V static inline struct v9fs_inode *V9FS_I(const struct inode *inode)
138a78ce05dSAneesh Kumar K.V {
139a78ce05dSAneesh Kumar K.V 	return container_of(inode, struct v9fs_inode, vfs_inode);
140a78ce05dSAneesh Kumar K.V }
141a78ce05dSAneesh Kumar K.V 
142bd238fb4SLatchesar Ionkov struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *,
143bd238fb4SLatchesar Ionkov 									char *);
14453c06f4eSAneesh Kumar K.V extern void v9fs_session_close(struct v9fs_session_info *v9ses);
14553c06f4eSAneesh Kumar K.V extern void v9fs_session_cancel(struct v9fs_session_info *v9ses);
14653c06f4eSAneesh Kumar K.V extern void v9fs_session_begin_cancel(struct v9fs_session_info *v9ses);
14753c06f4eSAneesh Kumar K.V extern struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
14800cd8dd3SAl Viro 			unsigned int flags);
14953c06f4eSAneesh Kumar K.V extern int v9fs_vfs_unlink(struct inode *i, struct dentry *d);
15053c06f4eSAneesh Kumar K.V extern int v9fs_vfs_rmdir(struct inode *i, struct dentry *d);
15153c06f4eSAneesh Kumar K.V extern int v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
15253c06f4eSAneesh Kumar K.V 			struct inode *new_dir, struct dentry *new_dentry);
15353c06f4eSAneesh Kumar K.V extern void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd,
15453c06f4eSAneesh Kumar K.V 			void *p);
155a78ce05dSAneesh Kumar K.V extern struct inode *v9fs_inode_from_fid(struct v9fs_session_info *v9ses,
15653c06f4eSAneesh Kumar K.V 					 struct p9_fid *fid,
157ed80fcfaSAneesh Kumar K.V 					 struct super_block *sb, int new);
15853c06f4eSAneesh Kumar K.V extern const struct inode_operations v9fs_dir_inode_operations_dotl;
15953c06f4eSAneesh Kumar K.V extern const struct inode_operations v9fs_file_inode_operations_dotl;
16053c06f4eSAneesh Kumar K.V extern const struct inode_operations v9fs_symlink_inode_operations_dotl;
161a78ce05dSAneesh Kumar K.V extern struct inode *v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses,
16253c06f4eSAneesh Kumar K.V 					      struct p9_fid *fid,
163ed80fcfaSAneesh Kumar K.V 					      struct super_block *sb, int new);
1649e82cf6aSEric Van Hensbergen 
1659e82cf6aSEric Van Hensbergen /* other default globals */
1669e82cf6aSEric Van Hensbergen #define V9FS_PORT	564
1679e82cf6aSEric Van Hensbergen #define V9FS_DEFUSER	"nobody"
1689e82cf6aSEric Van Hensbergen #define V9FS_DEFANAME	""
16976ed23a5SEric W. Biederman #define V9FS_DEFUID	KUIDT_INIT(-2)
17076ed23a5SEric W. Biederman #define V9FS_DEFGID	KGIDT_INIT(-2)
1719e82cf6aSEric Van Hensbergen 
172bd238fb4SLatchesar Ionkov static inline struct v9fs_session_info *v9fs_inode2v9ses(struct inode *inode)
173bd238fb4SLatchesar Ionkov {
174bd238fb4SLatchesar Ionkov 	return (inode->i_sb->s_fs_info);
175bd238fb4SLatchesar Ionkov }
1762405669bSLatchesar Ionkov 
17742869c8aSAneesh Kumar K.V static inline struct v9fs_session_info *v9fs_dentry2v9ses(struct dentry *dentry)
17842869c8aSAneesh Kumar K.V {
17942869c8aSAneesh Kumar K.V 	return dentry->d_sb->s_fs_info;
18042869c8aSAneesh Kumar K.V }
18142869c8aSAneesh Kumar K.V 
182dd6102fbSSripathi Kodi static inline int v9fs_proto_dotu(struct v9fs_session_info *v9ses)
1832405669bSLatchesar Ionkov {
184dd6102fbSSripathi Kodi 	return v9ses->flags & V9FS_PROTO_2000U;
185dd6102fbSSripathi Kodi }
186dd6102fbSSripathi Kodi 
187dd6102fbSSripathi Kodi static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses)
188dd6102fbSSripathi Kodi {
18945bc21edSSripathi Kodi 	return v9ses->flags & V9FS_PROTO_2000L;
1902405669bSLatchesar Ionkov }
19153c06f4eSAneesh Kumar K.V 
19253c06f4eSAneesh Kumar K.V /**
193a78ce05dSAneesh Kumar K.V  * v9fs_get_inode_from_fid - Helper routine to populate an inode by
19453c06f4eSAneesh Kumar K.V  * issuing a attribute request
19553c06f4eSAneesh Kumar K.V  * @v9ses: session information
19653c06f4eSAneesh Kumar K.V  * @fid: fid to issue attribute request for
19753c06f4eSAneesh Kumar K.V  * @sb: superblock on which to create inode
19853c06f4eSAneesh Kumar K.V  *
19953c06f4eSAneesh Kumar K.V  */
20053c06f4eSAneesh Kumar K.V static inline struct inode *
201a78ce05dSAneesh Kumar K.V v9fs_get_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
20253c06f4eSAneesh Kumar K.V 			struct super_block *sb)
20353c06f4eSAneesh Kumar K.V {
20453c06f4eSAneesh Kumar K.V 	if (v9fs_proto_dotl(v9ses))
205ed80fcfaSAneesh Kumar K.V 		return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 0);
20653c06f4eSAneesh Kumar K.V 	else
207ed80fcfaSAneesh Kumar K.V 		return v9fs_inode_from_fid(v9ses, fid, sb, 0);
20853c06f4eSAneesh Kumar K.V }
209ed80fcfaSAneesh Kumar K.V 
210ed80fcfaSAneesh Kumar K.V /**
211ed80fcfaSAneesh Kumar K.V  * v9fs_get_new_inode_from_fid - Helper routine to populate an inode by
212ed80fcfaSAneesh Kumar K.V  * issuing a attribute request
213ed80fcfaSAneesh Kumar K.V  * @v9ses: session information
214ed80fcfaSAneesh Kumar K.V  * @fid: fid to issue attribute request for
215ed80fcfaSAneesh Kumar K.V  * @sb: superblock on which to create inode
216ed80fcfaSAneesh Kumar K.V  *
217ed80fcfaSAneesh Kumar K.V  */
218ed80fcfaSAneesh Kumar K.V static inline struct inode *
219ed80fcfaSAneesh Kumar K.V v9fs_get_new_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
220ed80fcfaSAneesh Kumar K.V 			    struct super_block *sb)
221ed80fcfaSAneesh Kumar K.V {
222ed80fcfaSAneesh Kumar K.V 	if (v9fs_proto_dotl(v9ses))
223ed80fcfaSAneesh Kumar K.V 		return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 1);
224ed80fcfaSAneesh Kumar K.V 	else
225ed80fcfaSAneesh Kumar K.V 		return v9fs_inode_from_fid(v9ses, fid, sb, 1);
226ed80fcfaSAneesh Kumar K.V }
227ed80fcfaSAneesh Kumar K.V 
228e0459f57SAneesh Kumar K.V #endif
229