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