Skip to content

Commit 8f40f67

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh/v9fs
* 'for-linus' of ssh://master.kernel.org/pub/scm/linux/kernel/git/ericvh/v9fs: 9p: fix error path during early mount 9p: make cryptic unknown error from server less scary 9p: fix flags length in net 9p: Correct fidpool creation failure in p9_client_create 9p: use struct mutex instead of struct semaphore 9p: propagate parse_option changes to client and transports fs/9p/v9fs.c (v9fs_parse_options): Handle kstrdup and match_strdup failure. 9p: Documentation updates add match_strlcpy() us it to make v9fs make uname and remotename parsing more robust
2 parents 8978a31 + 887b3ec commit 8f40f67

File tree

23 files changed

+1014
-215
lines changed

23 files changed

+1014
-215
lines changed

fs/9p/fid.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@
2222

2323
#include <linux/list.h>
2424

25+
/**
26+
* struct v9fs_dentry - 9p private data stored in dentry d_fsdata
27+
* @lock: protects the fidlist
28+
* @fidlist: list of FIDs currently associated with this dentry
29+
*
30+
* This structure defines the 9p private data associated with
31+
* a particular dentry. In particular, this private data is used
32+
* to lookup which 9P FID handle should be used for a particular VFS
33+
* operation. FID handles are associated with dentries instead of
34+
* inodes in order to more closely map functionality to the Plan 9
35+
* expected behavior for FID reclaimation and tracking.
36+
*
37+
* See Also: Mapping FIDs to Linux VFS model in
38+
* Design and Implementation of the Linux 9P File System documentation
39+
*/
2540
struct v9fs_dentry {
2641
spinlock_t lock; /* protect fidlist */
2742
struct list_head fidlist;

fs/9p/v9fs.c

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,39 +71,46 @@ static match_table_t tokens = {
7171

7272
/**
7373
* v9fs_parse_options - parse mount options into session structure
74-
* @options: options string passed from mount
7574
* @v9ses: existing v9fs session information
7675
*
76+
* Return 0 upon success, -ERRNO upon failure.
7777
*/
7878

79-
static void v9fs_parse_options(struct v9fs_session_info *v9ses)
79+
static int v9fs_parse_options(struct v9fs_session_info *v9ses)
8080
{
8181
char *options;
8282
substring_t args[MAX_OPT_ARGS];
8383
char *p;
8484
int option = 0;
8585
char *s, *e;
86-
int ret;
86+
int ret = 0;
8787

8888
/* setup defaults */
8989
v9ses->afid = ~0;
9090
v9ses->debug = 0;
9191
v9ses->cache = 0;
9292

9393
if (!v9ses->options)
94-
return;
94+
return 0;
9595

9696
options = kstrdup(v9ses->options, GFP_KERNEL);
97+
if (!options) {
98+
P9_DPRINTK(P9_DEBUG_ERROR,
99+
"failed to allocate copy of option string\n");
100+
return -ENOMEM;
101+
}
102+
97103
while ((p = strsep(&options, ",")) != NULL) {
98104
int token;
99105
if (!*p)
100106
continue;
101107
token = match_token(p, tokens, args);
102108
if (token < Opt_uname) {
103-
ret = match_int(&args[0], &option);
104-
if (ret < 0) {
109+
int r = match_int(&args[0], &option);
110+
if (r < 0) {
105111
P9_DPRINTK(P9_DEBUG_ERROR,
106112
"integer field, but no integer?\n");
113+
ret = r;
107114
continue;
108115
}
109116
}
@@ -125,10 +132,10 @@ static void v9fs_parse_options(struct v9fs_session_info *v9ses)
125132
v9ses->afid = option;
126133
break;
127134
case Opt_uname:
128-
match_strcpy(v9ses->uname, &args[0]);
135+
match_strlcpy(v9ses->uname, &args[0], PATH_MAX);
129136
break;
130137
case Opt_remotename:
131-
match_strcpy(v9ses->aname, &args[0]);
138+
match_strlcpy(v9ses->aname, &args[0], PATH_MAX);
132139
break;
133140
case Opt_nodevmap:
134141
v9ses->nodev = 1;
@@ -139,6 +146,13 @@ static void v9fs_parse_options(struct v9fs_session_info *v9ses)
139146

140147
case Opt_access:
141148
s = match_strdup(&args[0]);
149+
if (!s) {
150+
P9_DPRINTK(P9_DEBUG_ERROR,
151+
"failed to allocate copy"
152+
" of option argument\n");
153+
ret = -ENOMEM;
154+
break;
155+
}
142156
v9ses->flags &= ~V9FS_ACCESS_MASK;
143157
if (strcmp(s, "user") == 0)
144158
v9ses->flags |= V9FS_ACCESS_USER;
@@ -158,6 +172,7 @@ static void v9fs_parse_options(struct v9fs_session_info *v9ses)
158172
}
159173
}
160174
kfree(options);
175+
return ret;
161176
}
162177

163178
/**
@@ -173,6 +188,7 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
173188
{
174189
int retval = -EINVAL;
175190
struct p9_fid *fid;
191+
int rc;
176192

177193
v9ses->uname = __getname();
178194
if (!v9ses->uname)
@@ -190,8 +206,21 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
190206
v9ses->uid = ~0;
191207
v9ses->dfltuid = V9FS_DEFUID;
192208
v9ses->dfltgid = V9FS_DEFGID;
193-
v9ses->options = kstrdup(data, GFP_KERNEL);
194-
v9fs_parse_options(v9ses);
209+
if (data) {
210+
v9ses->options = kstrdup(data, GFP_KERNEL);
211+
if (!v9ses->options) {
212+
P9_DPRINTK(P9_DEBUG_ERROR,
213+
"failed to allocate copy of option string\n");
214+
retval = -ENOMEM;
215+
goto error;
216+
}
217+
}
218+
219+
rc = v9fs_parse_options(v9ses);
220+
if (rc < 0) {
221+
retval = rc;
222+
goto error;
223+
}
195224

196225
v9ses->clnt = p9_client_create(dev_name, v9ses->options);
197226

@@ -233,7 +262,6 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
233262
return fid;
234263

235264
error:
236-
v9fs_session_close(v9ses);
237265
return ERR_PTR(retval);
238266
}
239267

@@ -256,9 +284,12 @@ void v9fs_session_close(struct v9fs_session_info *v9ses)
256284
}
257285

258286
/**
259-
* v9fs_session_cancel - mark transport as disconnected
260-
* and cancel all pending requests.
287+
* v9fs_session_cancel - terminate a session
288+
* @v9ses: session to terminate
289+
*
290+
* mark transport as disconnected and cancel all pending requests.
261291
*/
292+
262293
void v9fs_session_cancel(struct v9fs_session_info *v9ses) {
263294
P9_DPRINTK(P9_DEBUG_ERROR, "cancel session %p\n", v9ses);
264295
p9_client_disconnect(v9ses->clnt);

fs/9p/v9fs.h

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,69 @@
2121
*
2222
*/
2323

24-
/*
25-
* Session structure provides information for an opened session
26-
*
27-
*/
24+
/**
25+
* enum p9_session_flags - option flags for each 9P session
26+
* @V9FS_EXTENDED: whether or not to use 9P2000.u extensions
27+
* @V9FS_ACCESS_SINGLE: only the mounting user can access the hierarchy
28+
* @V9FS_ACCESS_USER: a new attach will be issued for every user (default)
29+
* @V9FS_ACCESS_ANY: use a single attach for all users
30+
* @V9FS_ACCESS_MASK: bit mask of different ACCESS options
31+
*
32+
* Session flags reflect options selected by users at mount time
33+
*/
34+
enum p9_session_flags {
35+
V9FS_EXTENDED = 0x01,
36+
V9FS_ACCESS_SINGLE = 0x02,
37+
V9FS_ACCESS_USER = 0x04,
38+
V9FS_ACCESS_ANY = 0x06,
39+
V9FS_ACCESS_MASK = 0x06,
40+
};
41+
42+
/* possible values of ->cache */
43+
/**
44+
* enum p9_cache_modes - user specified cache preferences
45+
* @CACHE_NONE: do not cache data, dentries, or directory contents (default)
46+
* @CACHE_LOOSE: cache data, dentries, and directory contents w/no consistency
47+
*
48+
* eventually support loose, tight, time, session, default always none
49+
*/
50+
51+
enum p9_cache_modes {
52+
CACHE_NONE,
53+
CACHE_LOOSE,
54+
};
55+
56+
/**
57+
* struct v9fs_session_info - per-instance session information
58+
* @flags: session options of type &p9_session_flags
59+
* @nodev: set to 1 to disable device mapping
60+
* @debug: debug level
61+
* @afid: authentication handle
62+
* @cache: cache mode of type &p9_cache_modes
63+
* @options: copy of options string given by user
64+
* @uname: string user name to mount hierarchy as
65+
* @aname: mount specifier for remote hierarchy
66+
* @maxdata: maximum data to be sent/recvd per protocol message
67+
* @dfltuid: default numeric userid to mount hierarchy as
68+
* @dfltgid: default numeric groupid to mount hierarchy as
69+
* @uid: if %V9FS_ACCESS_SINGLE, the numeric uid which mounted the hierarchy
70+
* @clnt: reference to 9P network client instantiated for this session
71+
* @debugfs_dir: reference to debugfs_dir which can be used for add'l debug
72+
*
73+
* This structure holds state for each session instance established during
74+
* a sys_mount() .
75+
*
76+
* Bugs: there seems to be a lot of state which could be condensed and/or
77+
* removed.
78+
*/
2879

2980
struct v9fs_session_info {
3081
/* options */
31-
unsigned char flags; /* session flags */
32-
unsigned char nodev; /* set to 1 if no disable device mapping */
33-
unsigned short debug; /* debug level */
34-
unsigned int afid; /* authentication fid */
35-
unsigned int cache; /* cache mode */
82+
unsigned char flags;
83+
unsigned char nodev;
84+
unsigned short debug;
85+
unsigned int afid;
86+
unsigned int cache;
3687

3788
char *options; /* copy of mount options */
3889
char *uname; /* user name to mount as */
@@ -45,22 +96,6 @@ struct v9fs_session_info {
4596
struct dentry *debugfs_dir;
4697
};
4798

48-
/* session flags */
49-
enum {
50-
V9FS_EXTENDED = 0x01, /* 9P2000.u */
51-
V9FS_ACCESS_MASK = 0x06, /* access mask */
52-
V9FS_ACCESS_SINGLE = 0x02, /* only one user can access the files */
53-
V9FS_ACCESS_USER = 0x04, /* attache per user */
54-
V9FS_ACCESS_ANY = 0x06, /* use the same attach for all users */
55-
};
56-
57-
/* possible values of ->cache */
58-
/* eventually support loose, tight, time, session, default always none */
59-
enum {
60-
CACHE_NONE, /* default */
61-
CACHE_LOOSE, /* no consistency */
62-
};
63-
6499
extern struct dentry *v9fs_debugfs_root;
65100

66101
struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *,

fs/9p/vfs_addr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
/**
4444
* v9fs_vfs_readpage - read an entire page in from 9P
4545
*
46-
* @file: file being read
46+
* @filp: file being read
4747
* @page: structure to page
4848
*
4949
*/

fs/9p/vfs_dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static inline int dt_type(struct p9_stat *mistat)
6060

6161
/**
6262
* v9fs_dir_readdir - read a directory
63-
* @filep: opened file structure
63+
* @filp: opened file structure
6464
* @dirent: directory structure ???
6565
* @filldir: function to populate directory structure ???
6666
*

fs/9p/vfs_file.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ int v9fs_file_open(struct inode *inode, struct file *file)
9090

9191
/**
9292
* v9fs_file_lock - lock a file (or directory)
93-
* @inode: inode to be opened
94-
* @file: file being opened
93+
* @filp: file to be locked
94+
* @cmd: lock command
95+
* @fl: file lock structure
9596
*
96-
* XXX - this looks like a local only lock, we should extend into 9P
97+
* Bugs: this looks like a local only lock, we should extend into 9P
9798
* by using open exclusive
9899
*/
99100

@@ -118,7 +119,7 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)
118119

119120
/**
120121
* v9fs_file_read - read from a file
121-
* @filep: file pointer to read
122+
* @filp: file pointer to read
122123
* @data: data buffer to read data into
123124
* @count: size of buffer
124125
* @offset: offset at which to read data
@@ -142,7 +143,7 @@ v9fs_file_read(struct file *filp, char __user * data, size_t count,
142143

143144
/**
144145
* v9fs_file_write - write to a file
145-
* @filep: file pointer to write
146+
* @filp: file pointer to write
146147
* @data: data buffer to write data from
147148
* @count: size of buffer
148149
* @offset: offset at which to write data

0 commit comments

Comments
 (0)