diff options
author | Russell King <rmk@dyn-67.arm.linux.org.uk> | 2006-01-09 14:18:33 -0500 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2006-01-09 14:18:33 -0500 |
commit | 0a3a98f6dd4e8f4d928a09302c0d1c56f2192ac3 (patch) | |
tree | 92f55e374a84d06ce8213a4540454760fdecf137 /fs | |
parent | 8ef12c9f01afba47c2d33bb939085111ca0d0f7d (diff) | |
parent | 5367f2d67c7d0bf1faae90e6e7b4e2ac3c9b5e0f (diff) |
Merge Linus' tree.
Diffstat (limited to 'fs')
96 files changed, 2771 insertions, 1996 deletions
diff --git a/fs/9p/9p.c b/fs/9p/9p.c index e847f504a47c..1a6d08761f39 100644 --- a/fs/9p/9p.c +++ b/fs/9p/9p.c | |||
@@ -1,8 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * linux/fs/9p/9p.c | 2 | * linux/fs/9p/9p.c |
3 | * | 3 | * |
4 | * This file contains functions 9P2000 functions | 4 | * This file contains functions to perform synchronous 9P calls |
5 | * | 5 | * |
6 | * Copyright (C) 2004 by Latchesar Ionkov <lucho@ionkov.net> | ||
6 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> | 7 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> |
7 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> | 8 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> |
8 | * | 9 | * |
@@ -33,6 +34,7 @@ | |||
33 | #include "debug.h" | 34 | #include "debug.h" |
34 | #include "v9fs.h" | 35 | #include "v9fs.h" |
35 | #include "9p.h" | 36 | #include "9p.h" |
37 | #include "conv.h" | ||
36 | #include "mux.h" | 38 | #include "mux.h" |
37 | 39 | ||
38 | /** | 40 | /** |
@@ -46,16 +48,21 @@ | |||
46 | 48 | ||
47 | int | 49 | int |
48 | v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize, | 50 | v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize, |
49 | char *version, struct v9fs_fcall **fcall) | 51 | char *version, struct v9fs_fcall **rcp) |
50 | { | 52 | { |
51 | struct v9fs_fcall msg; | 53 | int ret; |
54 | struct v9fs_fcall *tc; | ||
52 | 55 | ||
53 | dprintk(DEBUG_9P, "msize: %d version: %s\n", msize, version); | 56 | dprintk(DEBUG_9P, "msize: %d version: %s\n", msize, version); |
54 | msg.id = TVERSION; | 57 | tc = v9fs_create_tversion(msize, version); |
55 | msg.params.tversion.msize = msize; | ||
56 | msg.params.tversion.version = version; | ||
57 | 58 | ||
58 | return v9fs_mux_rpc(v9ses, &msg, fcall); | 59 | if (!IS_ERR(tc)) { |
60 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); | ||
61 | kfree(tc); | ||
62 | } else | ||
63 | ret = PTR_ERR(tc); | ||
64 | |||
65 | return ret; | ||
59 | } | 66 | } |
60 | 67 | ||
61 | /** | 68 | /** |
@@ -71,19 +78,45 @@ v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize, | |||
71 | 78 | ||
72 | int | 79 | int |
73 | v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname, | 80 | v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname, |
74 | u32 fid, u32 afid, struct v9fs_fcall **fcall) | 81 | u32 fid, u32 afid, struct v9fs_fcall **rcp) |
75 | { | 82 | { |
76 | struct v9fs_fcall msg; | 83 | int ret; |
84 | struct v9fs_fcall* tc; | ||
77 | 85 | ||
78 | dprintk(DEBUG_9P, "uname '%s' aname '%s' fid %d afid %d\n", uname, | 86 | dprintk(DEBUG_9P, "uname '%s' aname '%s' fid %d afid %d\n", uname, |
79 | aname, fid, afid); | 87 | aname, fid, afid); |
80 | msg.id = TATTACH; | ||
81 | msg.params.tattach.fid = fid; | ||
82 | msg.params.tattach.afid = afid; | ||
83 | msg.params.tattach.uname = uname; | ||
84 | msg.params.tattach.aname = aname; | ||
85 | 88 | ||
86 | return v9fs_mux_rpc(v9ses, &msg, fcall); | 89 | tc = v9fs_create_tattach(fid, afid, uname, aname); |
90 | if (!IS_ERR(tc)) { | ||
91 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); | ||
92 | kfree(tc); | ||
93 | } else | ||
94 | ret = PTR_ERR(tc); | ||
95 | |||
96 | return ret; | ||
97 | } | ||
98 | |||
99 | static void v9fs_t_clunk_cb(void *a, struct v9fs_fcall *tc, | ||
100 | struct v9fs_fcall *rc, int err) | ||
101 | { | ||
102 | int fid; | ||
103 | struct v9fs_session_info *v9ses; | ||
104 | |||
105 | if (err) | ||
106 | return; | ||
107 | |||
108 | fid = tc->params.tclunk.fid; | ||
109 | kfree(tc); | ||
110 | |||
111 | if (!rc) | ||
112 | return; | ||
113 | |||
114 | dprintk(DEBUG_9P, "tcall id %d rcall id %d\n", tc->id, rc->id); | ||
115 | v9ses = a; | ||
116 | if (rc->id == RCLUNK) | ||
117 | v9fs_put_idpool(fid, &v9ses->fidpool); | ||
118 | |||
119 | kfree(rc); | ||
87 | } | 120 | } |
88 | 121 | ||
89 | /** | 122 | /** |
@@ -95,16 +128,25 @@ v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname, | |||
95 | */ | 128 | */ |
96 | 129 | ||
97 | int | 130 | int |
98 | v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid, | 131 | v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid) |
99 | struct v9fs_fcall **fcall) | ||
100 | { | 132 | { |
101 | struct v9fs_fcall msg; | 133 | int ret; |
134 | struct v9fs_fcall *tc, *rc; | ||
102 | 135 | ||
103 | dprintk(DEBUG_9P, "fid %d\n", fid); | 136 | dprintk(DEBUG_9P, "fid %d\n", fid); |
104 | msg.id = TCLUNK; | ||
105 | msg.params.tclunk.fid = fid; | ||
106 | 137 | ||
107 | return v9fs_mux_rpc(v9ses, &msg, fcall); | 138 | rc = NULL; |
139 | tc = v9fs_create_tclunk(fid); | ||
140 | if (!IS_ERR(tc)) | ||
141 | ret = v9fs_mux_rpc(v9ses->mux, tc, &rc); | ||
142 | else | ||
143 | ret = PTR_ERR(tc); | ||
144 | |||
145 | if (ret) | ||
146 | dprintk(DEBUG_ERROR, "failed fid %d err %d\n", fid, ret); | ||
147 | |||
148 | v9fs_t_clunk_cb(v9ses, tc, rc, ret); | ||
149 | return ret; | ||
108 | } | 150 | } |
109 | 151 | ||
110 | /** | 152 | /** |
@@ -114,14 +156,21 @@ v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid, | |||
114 | * | 156 | * |
115 | */ | 157 | */ |
116 | 158 | ||
117 | int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 tag) | 159 | int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag) |
118 | { | 160 | { |
119 | struct v9fs_fcall msg; | 161 | int ret; |
162 | struct v9fs_fcall *tc; | ||
163 | |||
164 | dprintk(DEBUG_9P, "oldtag %d\n", oldtag); | ||
165 | |||
166 | tc = v9fs_create_tflush(oldtag); | ||
167 | if (!IS_ERR(tc)) { | ||
168 | ret = v9fs_mux_rpc(v9ses->mux, tc, NULL); | ||
169 | kfree(tc); | ||
170 | } else | ||
171 | ret = PTR_ERR(tc); | ||
120 | 172 | ||
121 | dprintk(DEBUG_9P, "oldtag %d\n", tag); | 173 | return ret; |
122 | msg.id = TFLUSH; | ||
123 | msg.params.tflush.oldtag = tag; | ||
124 | return v9fs_mux_rpc(v9ses, &msg, NULL); | ||
125 | } | 174 | } |
126 | 175 | ||
127 | /** | 176 | /** |
@@ -133,17 +182,22 @@ int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 tag) | |||
133 | */ | 182 | */ |
134 | 183 | ||
135 | int | 184 | int |
136 | v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid, struct v9fs_fcall **fcall) | 185 | v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid, struct v9fs_fcall **rcp) |
137 | { | 186 | { |
138 | struct v9fs_fcall msg; | 187 | int ret; |
188 | struct v9fs_fcall *tc; | ||
139 | 189 | ||
140 | dprintk(DEBUG_9P, "fid %d\n", fid); | 190 | dprintk(DEBUG_9P, "fid %d\n", fid); |
141 | if (fcall) | ||
142 | *fcall = NULL; | ||
143 | 191 | ||
144 | msg.id = TSTAT; | 192 | ret = -ENOMEM; |
145 | msg.params.tstat.fid = fid; | 193 | tc = v9fs_create_tstat(fid); |
146 | return v9fs_mux_rpc(v9ses, &msg, fcall); | 194 | if (!IS_ERR(tc)) { |
195 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); | ||
196 | kfree(tc); | ||
197 | } else | ||
198 | ret = PTR_ERR(tc); | ||
199 | |||
200 | return ret; | ||
147 | } | 201 | } |
148 | 202 | ||
149 | /** | 203 | /** |
@@ -157,16 +211,21 @@ v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid, struct v9fs_fcall **fcall) | |||
157 | 211 | ||
158 | int | 212 | int |
159 | v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid, | 213 | v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid, |
160 | struct v9fs_stat *stat, struct v9fs_fcall **fcall) | 214 | struct v9fs_wstat *wstat, struct v9fs_fcall **rcp) |
161 | { | 215 | { |
162 | struct v9fs_fcall msg; | 216 | int ret; |
217 | struct v9fs_fcall *tc; | ||
218 | |||
219 | dprintk(DEBUG_9P, "fid %d\n", fid); | ||
163 | 220 | ||
164 | dprintk(DEBUG_9P, "fid %d length %d\n", fid, (int)stat->length); | 221 | tc = v9fs_create_twstat(fid, wstat, v9ses->extended); |
165 | msg.id = TWSTAT; | 222 | if (!IS_ERR(tc)) { |
166 | msg.params.twstat.fid = fid; | 223 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); |
167 | msg.params.twstat.stat = stat; | 224 | kfree(tc); |
225 | } else | ||
226 | ret = PTR_ERR(tc); | ||
168 | 227 | ||
169 | return v9fs_mux_rpc(v9ses, &msg, fcall); | 228 | return ret; |
170 | } | 229 | } |
171 | 230 | ||
172 | /** | 231 | /** |
@@ -183,23 +242,27 @@ v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid, | |||
183 | 242 | ||
184 | int | 243 | int |
185 | v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid, | 244 | v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid, |
186 | char *name, struct v9fs_fcall **fcall) | 245 | char *name, struct v9fs_fcall **rcp) |
187 | { | 246 | { |
188 | struct v9fs_fcall msg; | 247 | int ret; |
248 | struct v9fs_fcall *tc; | ||
249 | int nwname; | ||
189 | 250 | ||
190 | dprintk(DEBUG_9P, "fid %d newfid %d wname '%s'\n", fid, newfid, name); | 251 | dprintk(DEBUG_9P, "fid %d newfid %d wname '%s'\n", fid, newfid, name); |
191 | msg.id = TWALK; | 252 | |
192 | msg.params.twalk.fid = fid; | 253 | if (name) |
193 | msg.params.twalk.newfid = newfid; | 254 | nwname = 1; |
194 | 255 | else | |
195 | if (name) { | 256 | nwname = 0; |
196 | msg.params.twalk.nwname = 1; | 257 | |
197 | msg.params.twalk.wnames = &name; | 258 | tc = v9fs_create_twalk(fid, newfid, nwname, &name); |
198 | } else { | 259 | if (!IS_ERR(tc)) { |
199 | msg.params.twalk.nwname = 0; | 260 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); |
200 | } | 261 | kfree(tc); |
201 | 262 | } else | |
202 | return v9fs_mux_rpc(v9ses, &msg, fcall); | 263 | ret = PTR_ERR(tc); |
264 | |||
265 | return ret; | ||
203 | } | 266 | } |
204 | 267 | ||
205 | /** | 268 | /** |
@@ -214,19 +277,21 @@ v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid, | |||
214 | 277 | ||
215 | int | 278 | int |
216 | v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode, | 279 | v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode, |
217 | struct v9fs_fcall **fcall) | 280 | struct v9fs_fcall **rcp) |
218 | { | 281 | { |
219 | struct v9fs_fcall msg; | 282 | int ret; |
220 | long errorno = -1; | 283 | struct v9fs_fcall *tc; |
221 | 284 | ||
222 | dprintk(DEBUG_9P, "fid %d mode %d\n", fid, mode); | 285 | dprintk(DEBUG_9P, "fid %d mode %d\n", fid, mode); |
223 | msg.id = TOPEN; | ||
224 | msg.params.topen.fid = fid; | ||
225 | msg.params.topen.mode = mode; | ||
226 | 286 | ||
227 | errorno = v9fs_mux_rpc(v9ses, &msg, fcall); | 287 | tc = v9fs_create_topen(fid, mode); |
288 | if (!IS_ERR(tc)) { | ||
289 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); | ||
290 | kfree(tc); | ||
291 | } else | ||
292 | ret = PTR_ERR(tc); | ||
228 | 293 | ||
229 | return errorno; | 294 | return ret; |
230 | } | 295 | } |
231 | 296 | ||
232 | /** | 297 | /** |
@@ -239,14 +304,21 @@ v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode, | |||
239 | 304 | ||
240 | int | 305 | int |
241 | v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid, | 306 | v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid, |
242 | struct v9fs_fcall **fcall) | 307 | struct v9fs_fcall **rcp) |
243 | { | 308 | { |
244 | struct v9fs_fcall msg; | 309 | int ret; |
310 | struct v9fs_fcall *tc; | ||
245 | 311 | ||
246 | dprintk(DEBUG_9P, "fid %d\n", fid); | 312 | dprintk(DEBUG_9P, "fid %d\n", fid); |
247 | msg.id = TREMOVE; | 313 | |
248 | msg.params.tremove.fid = fid; | 314 | tc = v9fs_create_tremove(fid); |
249 | return v9fs_mux_rpc(v9ses, &msg, fcall); | 315 | if (!IS_ERR(tc)) { |
316 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); | ||
317 | kfree(tc); | ||
318 | } else | ||
319 | ret = PTR_ERR(tc); | ||
320 | |||
321 | return ret; | ||
250 | } | 322 | } |
251 | 323 | ||
252 | /** | 324 | /** |
@@ -262,20 +334,22 @@ v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid, | |||
262 | 334 | ||
263 | int | 335 | int |
264 | v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name, | 336 | v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name, |
265 | u32 perm, u8 mode, struct v9fs_fcall **fcall) | 337 | u32 perm, u8 mode, struct v9fs_fcall **rcp) |
266 | { | 338 | { |
267 | struct v9fs_fcall msg; | 339 | int ret; |
340 | struct v9fs_fcall *tc; | ||
268 | 341 | ||
269 | dprintk(DEBUG_9P, "fid %d name '%s' perm %x mode %d\n", | 342 | dprintk(DEBUG_9P, "fid %d name '%s' perm %x mode %d\n", |
270 | fid, name, perm, mode); | 343 | fid, name, perm, mode); |
271 | 344 | ||
272 | msg.id = TCREATE; | 345 | tc = v9fs_create_tcreate(fid, name, perm, mode); |
273 | msg.params.tcreate.fid = fid; | 346 | if (!IS_ERR(tc)) { |
274 | msg.params.tcreate.name = name; | 347 | ret = v9fs_mux_rpc(v9ses->mux, tc, rcp); |
275 | msg.params.tcreate.perm = perm; | 348 | kfree(tc); |
276 | msg.params.tcreate.mode = mode; | 349 | } else |
350 | ret = PTR_ERR(tc); | ||
277 | 351 | ||
278 | return v9fs_mux_rpc(v9ses, &msg, fcall); | 352 | return ret; |
279 | } | 353 | } |
280 | 354 | ||
281 | /** | 355 | /** |
@@ -290,31 +364,29 @@ v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name, | |||
290 | 364 | ||
291 | int | 365 | int |
292 | v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid, u64 offset, | 366 | v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid, u64 offset, |
293 | u32 count, struct v9fs_fcall **fcall) | 367 | u32 count, struct v9fs_fcall **rcp) |
294 | { | 368 | { |
295 | struct v9fs_fcall msg; | 369 | int ret; |
296 | struct v9fs_fcall *rc = NULL; | 370 | struct v9fs_fcall *tc, *rc; |
297 | long errorno = -1; | 371 | |
298 | 372 | dprintk(DEBUG_9P, "fid %d offset 0x%llux count 0x%x\n", fid, | |
299 | dprintk(DEBUG_9P, "fid %d offset 0x%lx count 0x%x\n", fid, | 373 | (long long unsigned) offset, count); |
300 | (long unsigned int)offset, count); | 374 | |
301 | msg.id = TREAD; | 375 | tc = v9fs_create_tread(fid, offset, count); |
302 | msg.params.tread.fid = fid; | 376 | if (!IS_ERR(tc)) { |
303 | msg.params.tread.offset = offset; | 377 | ret = v9fs_mux_rpc(v9ses->mux, tc, &rc); |
304 | msg.params.tread.count = count; | 378 | if (!ret) |
305 | errorno = v9fs_mux_rpc(v9ses, &msg, &rc); | 379 | ret = rc->params.rread.count; |
306 | 380 | if (rcp) | |
307 | if (!errorno) { | 381 | *rcp = rc; |
308 | errorno = rc->params.rread.count; | 382 | else |
309 | dump_data(rc->params.rread.data, rc->params.rread.count); | 383 | kfree(rc); |
310 | } | 384 | |
311 | 385 | kfree(tc); | |
312 | if (fcall) | 386 | } else |
313 | *fcall = rc; | 387 | ret = PTR_ERR(tc); |
314 | else | 388 | |
315 | kfree(rc); | 389 | return ret; |
316 | |||
317 | return errorno; | ||
318 | } | 390 | } |
319 | 391 | ||
320 | /** | 392 | /** |
@@ -328,32 +400,30 @@ v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid, u64 offset, | |||
328 | */ | 400 | */ |
329 | 401 | ||
330 | int | 402 | int |
331 | v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, | 403 | v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset, u32 count, |
332 | u64 offset, u32 count, void *data, struct v9fs_fcall **fcall) | 404 | const char __user *data, struct v9fs_fcall **rcp) |
333 | { | 405 | { |
334 | struct v9fs_fcall msg; | 406 | int ret; |
335 | struct v9fs_fcall *rc = NULL; | 407 | struct v9fs_fcall *tc, *rc; |
336 | long errorno = -1; | ||
337 | 408 | ||
338 | dprintk(DEBUG_9P, "fid %d offset 0x%llx count 0x%x\n", fid, | 409 | dprintk(DEBUG_9P, "fid %d offset 0x%llux count 0x%x\n", fid, |
339 | (unsigned long long)offset, count); | 410 | (long long unsigned) offset, count); |
340 | dump_data(data, count); | ||
341 | 411 | ||
342 | msg.id = TWRITE; | 412 | tc = v9fs_create_twrite(fid, offset, count, data); |
343 | msg.params.twrite.fid = fid; | 413 | if (!IS_ERR(tc)) { |
344 | msg.params.twrite.offset = offset; | 414 | ret = v9fs_mux_rpc(v9ses->mux, tc, &rc); |
345 | msg.params.twrite.count = count; | ||
346 | msg.params.twrite.data = data; | ||
347 | 415 | ||
348 | errorno = v9fs_mux_rpc(v9ses, &msg, &rc); | 416 | if (!ret) |
417 | ret = rc->params.rwrite.count; | ||
418 | if (rcp) | ||
419 | *rcp = rc; | ||
420 | else | ||
421 | kfree(rc); | ||
349 | 422 | ||
350 | if (!errorno) | 423 | kfree(tc); |
351 | errorno = rc->params.rwrite.count; | 424 | } else |
425 | ret = PTR_ERR(tc); | ||
352 | 426 | ||
353 | if (fcall) | 427 | return ret; |
354 | *fcall = rc; | ||
355 | else | ||
356 | kfree(rc); | ||
357 | |||
358 | return errorno; | ||
359 | } | 428 | } |
429 | |||
diff --git a/fs/9p/9p.h b/fs/9p/9p.h index f55424216be2..0cd374d94717 100644 --- a/fs/9p/9p.h +++ b/fs/9p/9p.h | |||
@@ -3,6 +3,7 @@ | |||
3 | * | 3 | * |
4 | * 9P protocol definitions. | 4 | * 9P protocol definitions. |
5 | * | 5 | * |
6 | * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net> | ||
6 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> | 7 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> |
7 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> | 8 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> |
8 | * | 9 | * |
@@ -100,9 +101,18 @@ enum { | |||
100 | V9FS_QTFILE = 0x00, | 101 | V9FS_QTFILE = 0x00, |
101 | }; | 102 | }; |
102 | 103 | ||
104 | #define V9FS_NOTAG (u16)(~0) | ||
105 | #define V9FS_NOFID (u32)(~0) | ||
106 | #define V9FS_MAXWELEM 16 | ||
107 | |||
103 | /* ample room for Twrite/Rread header (iounit) */ | 108 | /* ample room for Twrite/Rread header (iounit) */ |
104 | #define V9FS_IOHDRSZ 24 | 109 | #define V9FS_IOHDRSZ 24 |
105 | 110 | ||
111 | struct v9fs_str { | ||
112 | u16 len; | ||
113 | char *str; | ||
114 | }; | ||
115 | |||
106 | /* qids are the unique ID for a file (like an inode */ | 116 | /* qids are the unique ID for a file (like an inode */ |
107 | struct v9fs_qid { | 117 | struct v9fs_qid { |
108 | u8 type; | 118 | u8 type; |
@@ -120,6 +130,29 @@ struct v9fs_stat { | |||
120 | u32 atime; | 130 | u32 atime; |
121 | u32 mtime; | 131 | u32 mtime; |
122 | u64 length; | 132 | u64 length; |
133 | struct v9fs_str name; | ||
134 | struct v9fs_str uid; | ||
135 | struct v9fs_str gid; | ||
136 | struct v9fs_str muid; | ||
137 | struct v9fs_str extension; /* 9p2000.u extensions */ | ||
138 | u32 n_uid; /* 9p2000.u extensions */ | ||
139 | u32 n_gid; /* 9p2000.u extensions */ | ||
140 | u32 n_muid; /* 9p2000.u extensions */ | ||
141 | }; | ||
142 | |||
143 | /* file metadata (stat) structure used to create Twstat message | ||
144 | The is similar to v9fs_stat, but the strings don't point to | ||
145 | the same memory block and should be freed separately | ||
146 | */ | ||
147 | struct v9fs_wstat { | ||
148 | u16 size; | ||
149 | u16 type; | ||
150 | u32 dev; | ||
151 | struct v9fs_qid qid; | ||
152 | u32 mode; | ||
153 | u32 atime; | ||
154 | u32 mtime; | ||
155 | u64 length; | ||
123 | char *name; | 156 | char *name; |
124 | char *uid; | 157 | char *uid; |
125 | char *gid; | 158 | char *gid; |
@@ -128,25 +161,24 @@ struct v9fs_stat { | |||
128 | u32 n_uid; /* 9p2000.u extensions */ | 161 | u32 n_uid; /* 9p2000.u extensions */ |
129 | u32 n_gid; /* 9p2000.u extensions */ | 162 | u32 n_gid; /* 9p2000.u extensions */ |
130 | u32 n_muid; /* 9p2000.u extensions */ | 163 | u32 n_muid; /* 9p2000.u extensions */ |
131 | char data[0]; | ||
132 | }; | 164 | }; |
133 | 165 | ||
134 | /* Structures for Protocol Operations */ | 166 | /* Structures for Protocol Operations */ |
135 | 167 | ||
136 | struct Tversion { | 168 | struct Tversion { |
137 | u32 msize; | 169 | u32 msize; |
138 | char *version; | 170 | struct v9fs_str version; |
139 | }; | 171 | }; |
140 | 172 | ||
141 | struct Rversion { | 173 | struct Rversion { |
142 | u32 msize; | 174 | u32 msize; |
143 | char *version; | 175 | struct v9fs_str version; |
144 | }; | 176 | }; |
145 | 177 | ||
146 | struct Tauth { | 178 | struct Tauth { |
147 | u32 afid; | 179 | u32 afid; |
148 | char *uname; | 180 | struct v9fs_str uname; |
149 | char *aname; | 181 | struct v9fs_str aname; |
150 | }; | 182 | }; |
151 | 183 | ||
152 | struct Rauth { | 184 | struct Rauth { |
@@ -154,12 +186,12 @@ struct Rauth { | |||
154 | }; | 186 | }; |
155 | 187 | ||
156 | struct Rerror { | 188 | struct Rerror { |
157 | char *error; | 189 | struct v9fs_str error; |
158 | u32 errno; /* 9p2000.u extension */ | 190 | u32 errno; /* 9p2000.u extension */ |
159 | }; | 191 | }; |
160 | 192 | ||
161 | struct Tflush { | 193 | struct Tflush { |
162 | u32 oldtag; | 194 | u16 oldtag; |
163 | }; | 195 | }; |
164 | 196 | ||
165 | struct Rflush { | 197 | struct Rflush { |
@@ -168,8 +200,8 @@ struct Rflush { | |||
168 | struct Tattach { | 200 | struct Tattach { |
169 | u32 fid; | 201 | u32 fid; |
170 | u32 afid; | 202 | u32 afid; |
171 | char *uname; | 203 | struct v9fs_str uname; |
172 | char *aname; | 204 | struct v9fs_str aname; |
173 | }; | 205 | }; |
174 | 206 | ||
175 | struct Rattach { | 207 | struct Rattach { |
@@ -179,13 +211,13 @@ struct Rattach { | |||
179 | struct Twalk { | 211 | struct Twalk { |
180 | u32 fid; | 212 | u32 fid; |
181 | u32 newfid; | 213 | u32 newfid; |
182 | u32 nwname; | 214 | u16 nwname; |
183 | char **wnames; | 215 | struct v9fs_str wnames[16]; |
184 | }; | 216 | }; |
185 | 217 | ||
186 | struct Rwalk { | 218 | struct Rwalk { |
187 | u32 nwqid; | 219 | u16 nwqid; |
188 | struct v9fs_qid *wqids; | 220 | struct v9fs_qid wqids[16]; |
189 | }; | 221 | }; |
190 | 222 | ||
191 | struct Topen { | 223 | struct Topen { |
@@ -200,7 +232,7 @@ struct Ropen { | |||
200 | 232 | ||
201 | struct Tcreate { | 233 | struct Tcreate { |
202 | u32 fid; | 234 | u32 fid; |
203 | char *name; | 235 | struct v9fs_str name; |
204 | u32 perm; | 236 | u32 perm; |
205 | u8 mode; | 237 | u8 mode; |
206 | }; | 238 | }; |
@@ -251,12 +283,12 @@ struct Tstat { | |||
251 | }; | 283 | }; |
252 | 284 | ||
253 | struct Rstat { | 285 | struct Rstat { |
254 | struct v9fs_stat *stat; | 286 | struct v9fs_stat stat; |
255 | }; | 287 | }; |
256 | 288 | ||
257 | struct Twstat { | 289 | struct Twstat { |
258 | u32 fid; | 290 | u32 fid; |
259 | struct v9fs_stat *stat; | 291 | struct v9fs_stat stat; |
260 | }; | 292 | }; |
261 | 293 | ||
262 | struct Rwstat { | 294 | struct Rwstat { |
@@ -271,6 +303,7 @@ struct v9fs_fcall { | |||
271 | u32 size; | 303 | u32 size; |
272 | u8 id; | 304 | u8 id; |
273 | u16 tag; | 305 | u16 tag; |
306 | void *sdata; | ||
274 | 307 | ||
275 | union { | 308 | union { |
276 | struct Tversion tversion; | 309 | struct Tversion tversion; |
@@ -303,7 +336,9 @@ struct v9fs_fcall { | |||
303 | } params; | 336 | } params; |
304 | }; | 337 | }; |
305 | 338 | ||
306 | #define FCALL_ERROR(fcall) (fcall ? fcall->params.rerror.error : "") | 339 | #define PRINT_FCALL_ERROR(s, fcall) dprintk(DEBUG_ERROR, "%s: %.*s\n", s, \ |
340 | fcall?fcall->params.rerror.error.len:0, \ | ||
341 | fcall?fcall->params.rerror.error.str:""); | ||
307 | 342 | ||
308 | int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize, | 343 | int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize, |
309 | char *version, struct v9fs_fcall **rcall); | 344 | char *version, struct v9fs_fcall **rcall); |
@@ -311,8 +346,7 @@ int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize, | |||
311 | int v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname, | 346 | int v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname, |
312 | u32 fid, u32 afid, struct v9fs_fcall **rcall); | 347 | u32 fid, u32 afid, struct v9fs_fcall **rcall); |
313 | 348 | ||
314 | int v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid, | 349 | int v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid); |
315 | struct v9fs_fcall **rcall); | ||
316 | 350 | ||
317 | int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag); | 351 | int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag); |
318 | 352 | ||
@@ -320,7 +354,7 @@ int v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid, | |||
320 | struct v9fs_fcall **rcall); | 354 | struct v9fs_fcall **rcall); |
321 | 355 | ||
322 | int v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid, | 356 | int v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid, |
323 | struct v9fs_stat *stat, struct v9fs_fcall **rcall); | 357 | struct v9fs_wstat *wstat, struct v9fs_fcall **rcall); |
324 | 358 | ||
325 | int v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid, | 359 | int v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid, |
326 | char *name, struct v9fs_fcall **rcall); | 360 | char *name, struct v9fs_fcall **rcall); |
@@ -338,4 +372,5 @@ int v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid, | |||
338 | u64 offset, u32 count, struct v9fs_fcall **rcall); | 372 | u64 offset, u32 count, struct v9fs_fcall **rcall); |
339 | 373 | ||
340 | int v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset, | 374 | int v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset, |
341 | u32 count, void *data, struct v9fs_fcall **rcall); | 375 | u32 count, const char __user * data, |
376 | struct v9fs_fcall **rcall); | ||
diff --git a/fs/9p/Makefile b/fs/9p/Makefile index e4e4ffe5a7dc..3d023089707e 100644 --- a/fs/9p/Makefile +++ b/fs/9p/Makefile | |||
@@ -1,17 +1,17 @@ | |||
1 | obj-$(CONFIG_9P_FS) := 9p2000.o | 1 | obj-$(CONFIG_9P_FS) := 9p2000.o |
2 | 2 | ||
3 | 9p2000-objs := \ | 3 | 9p2000-objs := \ |
4 | trans_fd.o \ | ||
5 | trans_sock.o \ | ||
6 | mux.o \ | ||
7 | 9p.o \ | ||
8 | conv.o \ | ||
4 | vfs_super.o \ | 9 | vfs_super.o \ |
5 | vfs_inode.o \ | 10 | vfs_inode.o \ |
6 | vfs_file.o \ | 11 | vfs_file.o \ |
7 | vfs_dir.o \ | 12 | vfs_dir.o \ |
8 | vfs_dentry.o \ | 13 | vfs_dentry.o \ |
9 | error.o \ | 14 | error.o \ |
10 | mux.o \ | ||
11 | trans_fd.o \ | ||
12 | trans_sock.o \ | ||
13 | 9p.o \ | ||
14 | conv.o \ | ||
15 | v9fs.o \ | 15 | v9fs.o \ |
16 | fid.o | 16 | fid.o |
17 | 17 | ||
diff --git a/fs/9p/conv.c b/fs/9p/conv.c index 18121af99d3e..55ccfa10ee9e 100644 --- a/fs/9p/conv.c +++ b/fs/9p/conv.c | |||
@@ -30,7 +30,7 @@ | |||
30 | #include <linux/errno.h> | 30 | #include <linux/errno.h> |
31 | #include <linux/fs.h> | 31 | #include <linux/fs.h> |
32 | #include <linux/idr.h> | 32 | #include <linux/idr.h> |
33 | 33 | #include <asm/uaccess.h> | |
34 | #include "debug.h" | 34 | #include "debug.h" |
35 | #include "v9fs.h" | 35 | #include "v9fs.h" |
36 | #include "9p.h" | 36 | #include "9p.h" |
@@ -58,12 +58,15 @@ static inline int buf_check_overflow(struct cbuf *buf) | |||
58 | 58 | ||
59 | static inline int buf_check_size(struct cbuf *buf, int len) | 59 | static inline int buf_check_size(struct cbuf *buf, int len) |
60 | { | 60 | { |
61 | if (buf->p+len > buf->ep) { | 61 | if (buf->p + len > buf->ep) { |
62 | if (buf->p < buf->ep) { | 62 | if (buf->p < buf->ep) { |
63 | eprintk(KERN_ERR, "buffer overflow\n"); | 63 | eprintk(KERN_ERR, "buffer overflow: want %d has %d\n", |
64 | len, (int)(buf->ep - buf->p)); | ||
65 | dump_stack(); | ||
64 | buf->p = buf->ep + 1; | 66 | buf->p = buf->ep + 1; |
65 | return 0; | ||
66 | } | 67 | } |
68 | |||
69 | return 0; | ||
67 | } | 70 | } |
68 | 71 | ||
69 | return 1; | 72 | return 1; |
@@ -127,14 +130,6 @@ static inline void buf_put_string(struct cbuf *buf, const char *s) | |||
127 | buf_put_stringn(buf, s, strlen(s)); | 130 | buf_put_stringn(buf, s, strlen(s)); |
128 | } | 131 | } |
129 | 132 | ||
130 | static inline void buf_put_data(struct cbuf *buf, void *data, u32 datalen) | ||
131 | { | ||
132 | if (buf_check_size(buf, datalen)) { | ||
133 | memcpy(buf->p, data, datalen); | ||
134 | buf->p += datalen; | ||
135 | } | ||
136 | } | ||
137 | |||
138 | static inline u8 buf_get_int8(struct cbuf *buf) | 133 | static inline u8 buf_get_int8(struct cbuf *buf) |
139 | { | 134 | { |
140 | u8 ret = 0; | 135 | u8 ret = 0; |
@@ -183,86 +178,37 @@ static inline u64 buf_get_int64(struct cbuf *buf) | |||
183 | return ret; | 178 | return ret; |
184 | } | 179 | } |
185 | 180 | ||
186 | static inline int | 181 | static inline void buf_get_str(struct cbuf *buf, struct v9fs_str *vstr) |
187 | buf_get_string(struct cbuf *buf, char *data, unsigned int datalen) | ||
188 | { | ||
189 | u16 len = 0; | ||
190 | |||
191 | len = buf_get_int16(buf); | ||
192 | if (!buf_check_overflow(buf) && buf_check_size(buf, len) && len+1>datalen) { | ||
193 | memcpy(data, buf->p, len); | ||
194 | data[len] = 0; | ||
195 | buf->p += len; | ||
196 | len++; | ||
197 | } | ||
198 | |||
199 | return len; | ||
200 | } | ||
201 | |||
202 | static inline char *buf_get_stringb(struct cbuf *buf, struct cbuf *sbuf) | ||
203 | { | ||
204 | char *ret; | ||
205 | u16 len; | ||
206 | |||
207 | ret = NULL; | ||
208 | len = buf_get_int16(buf); | ||
209 | |||
210 | if (!buf_check_overflow(buf) && buf_check_size(buf, len) && | ||
211 | buf_check_size(sbuf, len+1)) { | ||
212 | |||
213 | memcpy(sbuf->p, buf->p, len); | ||
214 | sbuf->p[len] = 0; | ||
215 | ret = sbuf->p; | ||
216 | buf->p += len; | ||
217 | sbuf->p += len + 1; | ||
218 | } | ||
219 | |||
220 | return ret; | ||
221 | } | ||
222 | |||
223 | static inline int buf_get_data(struct cbuf *buf, void *data, int datalen) | ||
224 | { | 182 | { |
225 | int ret = 0; | 183 | vstr->len = buf_get_int16(buf); |
226 | 184 | if (!buf_check_overflow(buf) && buf_check_size(buf, vstr->len)) { | |
227 | if (buf_check_size(buf, datalen)) { | 185 | vstr->str = buf->p; |
228 | memcpy(data, buf->p, datalen); | 186 | buf->p += vstr->len; |
229 | buf->p += datalen; | 187 | } else { |
230 | ret = datalen; | 188 | vstr->len = 0; |
189 | vstr->str = NULL; | ||
231 | } | 190 | } |
232 | |||
233 | return ret; | ||
234 | } | 191 | } |
235 | 192 | ||
236 | static inline void *buf_get_datab(struct cbuf *buf, struct cbuf *dbuf, | 193 | static inline void buf_get_qid(struct cbuf *bufp, struct v9fs_qid *qid) |
237 | int datalen) | ||
238 | { | 194 | { |
239 | char *ret = NULL; | 195 | qid->type = buf_get_int8(bufp); |
240 | int n = 0; | 196 | qid->version = buf_get_int32(bufp); |
241 | 197 | qid->path = buf_get_int64(bufp); | |
242 | if (buf_check_size(dbuf, datalen)) { | ||
243 | n = buf_get_data(buf, dbuf->p, datalen); | ||
244 | if (n > 0) { | ||
245 | ret = dbuf->p; | ||
246 | dbuf->p += n; | ||
247 | } | ||
248 | } | ||
249 | |||
250 | return ret; | ||
251 | } | 198 | } |
252 | 199 | ||
253 | /** | 200 | /** |
254 | * v9fs_size_stat - calculate the size of a variable length stat struct | 201 | * v9fs_size_wstat - calculate the size of a variable length stat struct |
255 | * @v9ses: session information | ||
256 | * @stat: metadata (stat) structure | 202 | * @stat: metadata (stat) structure |
203 | * @extended: non-zero if 9P2000.u | ||
257 | * | 204 | * |
258 | */ | 205 | */ |
259 | 206 | ||
260 | static int v9fs_size_stat(struct v9fs_session_info *v9ses, | 207 | static int v9fs_size_wstat(struct v9fs_wstat *wstat, int extended) |
261 | struct v9fs_stat *stat) | ||
262 | { | 208 | { |
263 | int size = 0; | 209 | int size = 0; |
264 | 210 | ||
265 | if (stat == NULL) { | 211 | if (wstat == NULL) { |
266 | eprintk(KERN_ERR, "v9fs_size_stat: got a NULL stat pointer\n"); | 212 | eprintk(KERN_ERR, "v9fs_size_stat: got a NULL stat pointer\n"); |
267 | return 0; | 213 | return 0; |
268 | } | 214 | } |
@@ -279,82 +225,38 @@ static int v9fs_size_stat(struct v9fs_session_info *v9ses, | |||
279 | 8 + /* length[8] */ | 225 | 8 + /* length[8] */ |
280 | 8; /* minimum sum of string lengths */ | 226 | 8; /* minimum sum of string lengths */ |
281 | 227 | ||
282 | if (stat->name) | 228 | if (wstat->name) |
283 | size += strlen(stat->name); | 229 | size += strlen(wstat->name); |
284 | if (stat->uid) | 230 | if (wstat->uid) |
285 | size += strlen(stat->uid); | 231 | size += strlen(wstat->uid); |
286 | if (stat->gid) | 232 | if (wstat->gid) |
287 | size += strlen(stat->gid); | 233 | size += strlen(wstat->gid); |
288 | if (stat->muid) | 234 | if (wstat->muid) |
289 | size += strlen(stat->muid); | 235 | size += strlen(wstat->muid); |
290 | 236 | ||
291 | if (v9ses->extended) { | 237 | if (extended) { |
292 | size += 4 + /* n_uid[4] */ | 238 | size += 4 + /* n_uid[4] */ |
293 | 4 + /* n_gid[4] */ | 239 | 4 + /* n_gid[4] */ |
294 | 4 + /* n_muid[4] */ | 240 | 4 + /* n_muid[4] */ |
295 | 2; /* string length of extension[4] */ | 241 | 2; /* string length of extension[4] */ |
296 | if (stat->extension) | 242 | if (wstat->extension) |
297 | size += strlen(stat->extension); | 243 | size += strlen(wstat->extension); |
298 | } | 244 | } |
299 | 245 | ||
300 | return size; | 246 | return size; |
301 | } | 247 | } |
302 | 248 | ||
303 | /** | 249 | /** |
304 | * serialize_stat - safely format a stat structure for transmission | 250 | * buf_get_stat - safely decode a recieved metadata (stat) structure |
305 | * @v9ses: session info | ||
306 | * @stat: metadata (stat) structure | ||
307 | * @bufp: buffer to serialize structure into | ||
308 | * | ||
309 | */ | ||
310 | |||
311 | static int | ||
312 | serialize_stat(struct v9fs_session_info *v9ses, struct v9fs_stat *stat, | ||
313 | struct cbuf *bufp) | ||
314 | { | ||
315 | buf_put_int16(bufp, stat->size); | ||
316 | buf_put_int16(bufp, stat->type); | ||
317 | buf_put_int32(bufp, stat->dev); | ||
318 | buf_put_int8(bufp, stat->qid.type); | ||
319 | buf_put_int32(bufp, stat->qid.version); | ||
320 | buf_put_int64(bufp, stat->qid.path); | ||
321 | buf_put_int32(bufp, stat->mode); | ||
322 | buf_put_int32(bufp, stat->atime); | ||
323 | buf_put_int32(bufp, stat->mtime); | ||
324 | buf_put_int64(bufp, stat->length); | ||
325 | |||
326 | buf_put_string(bufp, stat->name); | ||
327 | buf_put_string(bufp, stat->uid); | ||
328 | buf_put_string(bufp, stat->gid); | ||
329 | buf_put_string(bufp, stat->muid); | ||
330 | |||
331 | if (v9ses->extended) { | ||
332 | buf_put_string(bufp, stat->extension); | ||
333 | buf_put_int32(bufp, stat->n_uid); | ||
334 | buf_put_int32(bufp, stat->n_gid); | ||
335 | buf_put_int32(bufp, stat->n_muid); | ||
336 | } | ||
337 | |||
338 | if (buf_check_overflow(bufp)) | ||
339 | return 0; | ||
340 | |||
341 | return stat->size; | ||
342 | } | ||
343 | |||
344 | /** | ||
345 | * deserialize_stat - safely decode a recieved metadata (stat) structure | ||
346 | * @v9ses: session info | ||
347 | * @bufp: buffer to deserialize | 251 | * @bufp: buffer to deserialize |
348 | * @stat: metadata (stat) structure | 252 | * @stat: metadata (stat) structure |
349 | * @dbufp: buffer to deserialize variable strings into | 253 | * @extended: non-zero if 9P2000.u |
350 | * | 254 | * |
351 | */ | 255 | */ |
352 | 256 | ||
353 | static inline int | 257 | static inline void |
354 | deserialize_stat(struct v9fs_session_info *v9ses, struct cbuf *bufp, | 258 | buf_get_stat(struct cbuf *bufp, struct v9fs_stat *stat, int extended) |
355 | struct v9fs_stat *stat, struct cbuf *dbufp) | ||
356 | { | 259 | { |
357 | |||
358 | stat->size = buf_get_int16(bufp); | 260 | stat->size = buf_get_int16(bufp); |
359 | stat->type = buf_get_int16(bufp); | 261 | stat->type = buf_get_int16(bufp); |
360 | stat->dev = buf_get_int32(bufp); | 262 | stat->dev = buf_get_int32(bufp); |
@@ -365,282 +267,82 @@ deserialize_stat(struct v9fs_session_info *v9ses, struct cbuf *bufp, | |||
365 | stat->atime = buf_get_int32(bufp); | 267 | stat->atime = buf_get_int32(bufp); |
366 | stat->mtime = buf_get_int32(bufp); | 268 | stat->mtime = buf_get_int32(bufp); |
367 | stat->length = buf_get_int64(bufp); | 269 | stat->length = buf_get_int64(bufp); |
368 | stat->name = buf_get_stringb(bufp, dbufp); | 270 | buf_get_str(bufp, &stat->name); |
369 | stat->uid = buf_get_stringb(bufp, dbufp); | 271 | buf_get_str(bufp, &stat->uid); |
370 | stat->gid = buf_get_stringb(bufp, dbufp); | 272 | buf_get_str(bufp, &stat->gid); |
371 | stat->muid = buf_get_stringb(bufp, dbufp); | 273 | buf_get_str(bufp, &stat->muid); |
372 | 274 | ||
373 | if (v9ses->extended) { | 275 | if (extended) { |
374 | stat->extension = buf_get_stringb(bufp, dbufp); | 276 | buf_get_str(bufp, &stat->extension); |
375 | stat->n_uid = buf_get_int32(bufp); | 277 | stat->n_uid = buf_get_int32(bufp); |
376 | stat->n_gid = buf_get_int32(bufp); | 278 | stat->n_gid = buf_get_int32(bufp); |
377 | stat->n_muid = buf_get_int32(bufp); | 279 | stat->n_muid = buf_get_int32(bufp); |
378 | } | 280 | } |
379 | |||
380 | if (buf_check_overflow(bufp) || buf_check_overflow(dbufp)) | ||
381 | return 0; | ||
382 | |||
383 | return stat->size + 2; | ||
384 | } | ||
385 | |||
386 | /** | ||
387 | * deserialize_statb - wrapper for decoding a received metadata structure | ||
388 | * @v9ses: session info | ||
389 | * @bufp: buffer to deserialize | ||
390 | * @dbufp: buffer to deserialize variable strings into | ||
391 | * | ||
392 | */ | ||
393 | |||
394 | static inline struct v9fs_stat *deserialize_statb(struct v9fs_session_info | ||
395 | *v9ses, struct cbuf *bufp, | ||
396 | struct cbuf *dbufp) | ||
397 | { | ||
398 | struct v9fs_stat *ret = buf_alloc(dbufp, sizeof(struct v9fs_stat)); | ||
399 | |||
400 | if (ret) { | ||
401 | int n = deserialize_stat(v9ses, bufp, ret, dbufp); | ||
402 | if (n <= 0) | ||
403 | return NULL; | ||
404 | } | ||
405 | |||
406 | return ret; | ||
407 | } | 281 | } |
408 | 282 | ||
409 | /** | 283 | /** |
410 | * v9fs_deserialize_stat - decode a received metadata structure | 284 | * v9fs_deserialize_stat - decode a received metadata structure |
411 | * @v9ses: session info | ||
412 | * @buf: buffer to deserialize | 285 | * @buf: buffer to deserialize |
413 | * @buflen: length of received buffer | 286 | * @buflen: length of received buffer |
414 | * @stat: metadata structure to decode into | 287 | * @stat: metadata structure to decode into |
415 | * @statlen: length of destination metadata structure | 288 | * @extended: non-zero if 9P2000.u |
416 | * | 289 | * |
290 | * Note: stat will point to the buf region. | ||
417 | */ | 291 | */ |
418 | 292 | ||
419 | int | 293 | int |
420 | v9fs_deserialize_stat(struct v9fs_session_info *v9ses, void *buf, | 294 | v9fs_deserialize_stat(void *buf, u32 buflen, struct v9fs_stat *stat, |
421 | u32 buflen, struct v9fs_stat *stat, u32 statlen) | 295 | int extended) |
422 | { | 296 | { |
423 | struct cbuf buffer; | 297 | struct cbuf buffer; |
424 | struct cbuf *bufp = &buffer; | 298 | struct cbuf *bufp = &buffer; |
425 | struct cbuf dbuffer; | 299 | unsigned char *p; |
426 | struct cbuf *dbufp = &dbuffer; | ||
427 | 300 | ||
428 | buf_init(bufp, buf, buflen); | 301 | buf_init(bufp, buf, buflen); |
429 | buf_init(dbufp, (char *)stat + sizeof(struct v9fs_stat), | 302 | p = bufp->p; |
430 | statlen - sizeof(struct v9fs_stat)); | 303 | buf_get_stat(bufp, stat, extended); |
431 | |||
432 | return deserialize_stat(v9ses, bufp, stat, dbufp); | ||
433 | } | ||
434 | |||
435 | static inline int | ||
436 | v9fs_size_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall) | ||
437 | { | ||
438 | int size = 4 + 1 + 2; /* size[4] msg[1] tag[2] */ | ||
439 | int i = 0; | ||
440 | |||
441 | switch (fcall->id) { | ||
442 | default: | ||
443 | eprintk(KERN_ERR, "bad msg type %d\n", fcall->id); | ||
444 | return 0; | ||
445 | case TVERSION: /* msize[4] version[s] */ | ||
446 | size += 4 + 2 + strlen(fcall->params.tversion.version); | ||
447 | break; | ||
448 | case TAUTH: /* afid[4] uname[s] aname[s] */ | ||
449 | size += 4 + 2 + strlen(fcall->params.tauth.uname) + | ||
450 | 2 + strlen(fcall->params.tauth.aname); | ||
451 | break; | ||
452 | case TFLUSH: /* oldtag[2] */ | ||
453 | size += 2; | ||
454 | break; | ||
455 | case TATTACH: /* fid[4] afid[4] uname[s] aname[s] */ | ||
456 | size += 4 + 4 + 2 + strlen(fcall->params.tattach.uname) + | ||
457 | 2 + strlen(fcall->params.tattach.aname); | ||
458 | break; | ||
459 | case TWALK: /* fid[4] newfid[4] nwname[2] nwname*(wname[s]) */ | ||
460 | size += 4 + 4 + 2; | ||
461 | /* now compute total for the array of names */ | ||
462 | for (i = 0; i < fcall->params.twalk.nwname; i++) | ||
463 | size += 2 + strlen(fcall->params.twalk.wnames[i]); | ||
464 | break; | ||
465 | case TOPEN: /* fid[4] mode[1] */ | ||
466 | size += 4 + 1; | ||
467 | break; | ||
468 | case TCREATE: /* fid[4] name[s] perm[4] mode[1] */ | ||
469 | size += 4 + 2 + strlen(fcall->params.tcreate.name) + 4 + 1; | ||
470 | break; | ||
471 | case TREAD: /* fid[4] offset[8] count[4] */ | ||
472 | size += 4 + 8 + 4; | ||
473 | break; | ||
474 | case TWRITE: /* fid[4] offset[8] count[4] data[count] */ | ||
475 | size += 4 + 8 + 4 + fcall->params.twrite.count; | ||
476 | break; | ||
477 | case TCLUNK: /* fid[4] */ | ||
478 | size += 4; | ||
479 | break; | ||
480 | case TREMOVE: /* fid[4] */ | ||
481 | size += 4; | ||
482 | break; | ||
483 | case TSTAT: /* fid[4] */ | ||
484 | size += 4; | ||
485 | break; | ||
486 | case TWSTAT: /* fid[4] stat[n] */ | ||
487 | fcall->params.twstat.stat->size = | ||
488 | v9fs_size_stat(v9ses, fcall->params.twstat.stat); | ||
489 | size += 4 + 2 + 2 + fcall->params.twstat.stat->size; | ||
490 | } | ||
491 | return size; | ||
492 | } | ||
493 | |||
494 | /* | ||
495 | * v9fs_serialize_fcall - marshall fcall struct into a packet | ||
496 | * @v9ses: session information | ||
497 | * @fcall: structure to convert | ||
498 | * @data: buffer to serialize fcall into | ||
499 | * @datalen: length of buffer to serialize fcall into | ||
500 | * | ||
501 | */ | ||
502 | |||
503 | int | ||
504 | v9fs_serialize_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall, | ||
505 | void *data, u32 datalen) | ||
506 | { | ||
507 | int i = 0; | ||
508 | struct v9fs_stat *stat = NULL; | ||
509 | struct cbuf buffer; | ||
510 | struct cbuf *bufp = &buffer; | ||
511 | |||
512 | buf_init(bufp, data, datalen); | ||
513 | |||
514 | if (!fcall) { | ||
515 | eprintk(KERN_ERR, "no fcall\n"); | ||
516 | return -EINVAL; | ||
517 | } | ||
518 | |||
519 | fcall->size = v9fs_size_fcall(v9ses, fcall); | ||
520 | |||
521 | buf_put_int32(bufp, fcall->size); | ||
522 | buf_put_int8(bufp, fcall->id); | ||
523 | buf_put_int16(bufp, fcall->tag); | ||
524 | |||
525 | dprintk(DEBUG_CONV, "size %d id %d tag %d\n", fcall->size, fcall->id, | ||
526 | fcall->tag); | ||
527 | |||
528 | /* now encode it */ | ||
529 | switch (fcall->id) { | ||
530 | default: | ||
531 | eprintk(KERN_ERR, "bad msg type: %d\n", fcall->id); | ||
532 | return -EPROTO; | ||
533 | case TVERSION: | ||
534 | buf_put_int32(bufp, fcall->params.tversion.msize); | ||
535 | buf_put_string(bufp, fcall->params.tversion.version); | ||
536 | break; | ||
537 | case TAUTH: | ||
538 | buf_put_int32(bufp, fcall->params.tauth.afid); | ||
539 | buf_put_string(bufp, fcall->params.tauth.uname); | ||
540 | buf_put_string(bufp, fcall->params.tauth.aname); | ||
541 | break; | ||
542 | case TFLUSH: | ||
543 | buf_put_int16(bufp, fcall->params.tflush.oldtag); | ||
544 | break; | ||
545 | case TATTACH: | ||
546 | buf_put_int32(bufp, fcall->params.tattach.fid); | ||
547 | buf_put_int32(bufp, fcall->params.tattach.afid); | ||
548 | buf_put_string(bufp, fcall->params.tattach.uname); | ||
549 | buf_put_string(bufp, fcall->params.tattach.aname); | ||
550 | break; | ||
551 | case TWALK: | ||
552 | buf_put_int32(bufp, fcall->params.twalk.fid); | ||
553 | buf_put_int32(bufp, fcall->params.twalk.newfid); | ||
554 | buf_put_int16(bufp, fcall->params.twalk.nwname); | ||
555 | for (i = 0; i < fcall->params.twalk.nwname; i++) | ||
556 | buf_put_string(bufp, fcall->params.twalk.wnames[i]); | ||
557 | break; | ||
558 | case TOPEN: | ||
559 | buf_put_int32(bufp, fcall->params.topen.fid); | ||
560 | buf_put_int8(bufp, fcall->params.topen.mode); | ||
561 | break; | ||
562 | case TCREATE: | ||
563 | buf_put_int32(bufp, fcall->params.tcreate.fid); | ||
564 | buf_put_string(bufp, fcall->params.tcreate.name); | ||
565 | buf_put_int32(bufp, fcall->params.tcreate.perm); | ||
566 | buf_put_int8(bufp, fcall->params.tcreate.mode); | ||
567 | break; | ||
568 | case TREAD: | ||
569 | buf_put_int32(bufp, fcall->params.tread.fid); | ||
570 | buf_put_int64(bufp, fcall->params.tread.offset); | ||
571 | buf_put_int32(bufp, fcall->params.tread.count); | ||
572 | break; | ||
573 | case TWRITE: | ||
574 | buf_put_int32(bufp, fcall->params.twrite.fid); | ||
575 | buf_put_int64(bufp, fcall->params.twrite.offset); | ||
576 | buf_put_int32(bufp, fcall->params.twrite.count); | ||
577 | buf_put_data(bufp, fcall->params.twrite.data, | ||
578 | fcall->params.twrite.count); | ||
579 | break; | ||
580 | case TCLUNK: | ||
581 | buf_put_int32(bufp, fcall->params.tclunk.fid); | ||
582 | break; | ||
583 | case TREMOVE: | ||
584 | buf_put_int32(bufp, fcall->params.tremove.fid); | ||
585 | break; | ||
586 | case TSTAT: | ||
587 | buf_put_int32(bufp, fcall->params.tstat.fid); | ||
588 | break; | ||
589 | case TWSTAT: | ||
590 | buf_put_int32(bufp, fcall->params.twstat.fid); | ||
591 | stat = fcall->params.twstat.stat; | ||
592 | |||
593 | buf_put_int16(bufp, stat->size + 2); | ||
594 | serialize_stat(v9ses, stat, bufp); | ||
595 | break; | ||
596 | } | ||
597 | 304 | ||
598 | if (buf_check_overflow(bufp)) | 305 | if (buf_check_overflow(bufp)) |
599 | return -EIO; | 306 | return 0; |
600 | 307 | else | |
601 | return fcall->size; | 308 | return bufp->p - p; |
602 | } | 309 | } |
603 | 310 | ||
604 | /** | 311 | /** |
605 | * deserialize_fcall - unmarshal a response | 312 | * deserialize_fcall - unmarshal a response |
606 | * @v9ses: session information | ||
607 | * @msgsize: size of rcall message | ||
608 | * @buf: recieved buffer | 313 | * @buf: recieved buffer |
609 | * @buflen: length of received buffer | 314 | * @buflen: length of received buffer |
610 | * @rcall: fcall structure to populate | 315 | * @rcall: fcall structure to populate |
611 | * @rcalllen: length of fcall structure to populate | 316 | * @rcalllen: length of fcall structure to populate |
317 | * @extended: non-zero if 9P2000.u | ||
612 | * | 318 | * |
613 | */ | 319 | */ |
614 | 320 | ||
615 | int | 321 | int |
616 | v9fs_deserialize_fcall(struct v9fs_session_info *v9ses, u32 msgsize, | 322 | v9fs_deserialize_fcall(void *buf, u32 buflen, struct v9fs_fcall *rcall, |
617 | void *buf, u32 buflen, struct v9fs_fcall *rcall, | 323 | int extended) |
618 | int rcalllen) | ||
619 | { | 324 | { |
620 | 325 | ||
621 | struct cbuf buffer; | 326 | struct cbuf buffer; |
622 | struct cbuf *bufp = &buffer; | 327 | struct cbuf *bufp = &buffer; |
623 | struct cbuf dbuffer; | ||
624 | struct cbuf *dbufp = &dbuffer; | ||
625 | int i = 0; | 328 | int i = 0; |
626 | 329 | ||
627 | buf_init(bufp, buf, buflen); | 330 | buf_init(bufp, buf, buflen); |
628 | buf_init(dbufp, (char *)rcall + sizeof(struct v9fs_fcall), | ||
629 | rcalllen - sizeof(struct v9fs_fcall)); | ||
630 | 331 | ||
631 | rcall->size = msgsize; | 332 | rcall->size = buf_get_int32(bufp); |
632 | rcall->id = buf_get_int8(bufp); | 333 | rcall->id = buf_get_int8(bufp); |
633 | rcall->tag = buf_get_int16(bufp); | 334 | rcall->tag = buf_get_int16(bufp); |
634 | 335 | ||
635 | dprintk(DEBUG_CONV, "size %d id %d tag %d\n", rcall->size, rcall->id, | 336 | dprintk(DEBUG_CONV, "size %d id %d tag %d\n", rcall->size, rcall->id, |
636 | rcall->tag); | 337 | rcall->tag); |
338 | |||
637 | switch (rcall->id) { | 339 | switch (rcall->id) { |
638 | default: | 340 | default: |
639 | eprintk(KERN_ERR, "unknown message type: %d\n", rcall->id); | 341 | eprintk(KERN_ERR, "unknown message type: %d\n", rcall->id); |
640 | return -EPROTO; | 342 | return -EPROTO; |
641 | case RVERSION: | 343 | case RVERSION: |
642 | rcall->params.rversion.msize = buf_get_int32(bufp); | 344 | rcall->params.rversion.msize = buf_get_int32(bufp); |
643 | rcall->params.rversion.version = buf_get_stringb(bufp, dbufp); | 345 | buf_get_str(bufp, &rcall->params.rversion.version); |
644 | break; | 346 | break; |
645 | case RFLUSH: | 347 | case RFLUSH: |
646 | break; | 348 | break; |
@@ -651,34 +353,27 @@ v9fs_deserialize_fcall(struct v9fs_session_info *v9ses, u32 msgsize, | |||
651 | break; | 353 | break; |
652 | case RWALK: | 354 | case RWALK: |
653 | rcall->params.rwalk.nwqid = buf_get_int16(bufp); | 355 | rcall->params.rwalk.nwqid = buf_get_int16(bufp); |
654 | rcall->params.rwalk.wqids = buf_alloc(dbufp, | 356 | if (rcall->params.rwalk.nwqid > V9FS_MAXWELEM) { |
655 | rcall->params.rwalk.nwqid * sizeof(struct v9fs_qid)); | 357 | eprintk(KERN_ERR, "Rwalk with more than %d qids: %d\n", |
656 | if (rcall->params.rwalk.wqids) | 358 | V9FS_MAXWELEM, rcall->params.rwalk.nwqid); |
657 | for (i = 0; i < rcall->params.rwalk.nwqid; i++) { | 359 | return -EPROTO; |
658 | rcall->params.rwalk.wqids[i].type = | 360 | } |
659 | buf_get_int8(bufp); | 361 | |
660 | rcall->params.rwalk.wqids[i].version = | 362 | for (i = 0; i < rcall->params.rwalk.nwqid; i++) |
661 | buf_get_int16(bufp); | 363 | buf_get_qid(bufp, &rcall->params.rwalk.wqids[i]); |
662 | rcall->params.rwalk.wqids[i].path = | ||
663 | buf_get_int64(bufp); | ||
664 | } | ||
665 | break; | 364 | break; |
666 | case ROPEN: | 365 | case ROPEN: |
667 | rcall->params.ropen.qid.type = buf_get_int8(bufp); | 366 | buf_get_qid(bufp, &rcall->params.ropen.qid); |
668 | rcall->params.ropen.qid.version = buf_get_int32(bufp); | ||
669 | rcall->params.ropen.qid.path = buf_get_int64(bufp); | ||
670 | rcall->params.ropen.iounit = buf_get_int32(bufp); | 367 | rcall->params.ropen.iounit = buf_get_int32(bufp); |
671 | break; | 368 | break; |
672 | case RCREATE: | 369 | case RCREATE: |
673 | rcall->params.rcreate.qid.type = buf_get_int8(bufp); | 370 | buf_get_qid(bufp, &rcall->params.rcreate.qid); |
674 | rcall->params.rcreate.qid.version = buf_get_int32(bufp); | ||
675 | rcall->params.rcreate.qid.path = buf_get_int64(bufp); | ||
676 | rcall->params.rcreate.iounit = buf_get_int32(bufp); | 371 | rcall->params.rcreate.iounit = buf_get_int32(bufp); |
677 | break; | 372 | break; |
678 | case RREAD: | 373 | case RREAD: |
679 | rcall->params.rread.count = buf_get_int32(bufp); | 374 | rcall->params.rread.count = buf_get_int32(bufp); |
680 | rcall->params.rread.data = buf_get_datab(bufp, dbufp, | 375 | rcall->params.rread.data = bufp->p; |
681 | rcall->params.rread.count); | 376 | buf_check_size(bufp, rcall->params.rread.count); |
682 | break; | 377 | break; |
683 | case RWRITE: | 378 | case RWRITE: |
684 | rcall->params.rwrite.count = buf_get_int32(bufp); | 379 | rcall->params.rwrite.count = buf_get_int32(bufp); |
@@ -689,20 +384,443 @@ v9fs_deserialize_fcall(struct v9fs_session_info *v9ses, u32 msgsize, | |||
689 | break; | 384 | break; |
690 | case RSTAT: | 385 | case RSTAT: |
691 | buf_get_int16(bufp); | 386 | buf_get_int16(bufp); |
692 | rcall->params.rstat.stat = | 387 | buf_get_stat(bufp, &rcall->params.rstat.stat, extended); |
693 | deserialize_statb(v9ses, bufp, dbufp); | ||
694 | break; | 388 | break; |
695 | case RWSTAT: | 389 | case RWSTAT: |
696 | break; | 390 | break; |
697 | case RERROR: | 391 | case RERROR: |
698 | rcall->params.rerror.error = buf_get_stringb(bufp, dbufp); | 392 | buf_get_str(bufp, &rcall->params.rerror.error); |
699 | if (v9ses->extended) | 393 | if (extended) |
700 | rcall->params.rerror.errno = buf_get_int16(bufp); | 394 | rcall->params.rerror.errno = buf_get_int16(bufp); |
701 | break; | 395 | break; |
702 | } | 396 | } |
703 | 397 | ||
704 | if (buf_check_overflow(bufp) || buf_check_overflow(dbufp)) | 398 | if (buf_check_overflow(bufp)) { |
399 | dprintk(DEBUG_ERROR, "buffer overflow\n"); | ||
705 | return -EIO; | 400 | return -EIO; |
401 | } | ||
402 | |||
403 | return bufp->p - bufp->sp; | ||
404 | } | ||
405 | |||
406 | static inline void v9fs_put_int8(struct cbuf *bufp, u8 val, u8 * p) | ||
407 | { | ||
408 | *p = val; | ||
409 | buf_put_int8(bufp, val); | ||
410 | } | ||
411 | |||
412 | static inline void v9fs_put_int16(struct cbuf *bufp, u16 val, u16 * p) | ||
413 | { | ||
414 | *p = val; | ||
415 | buf_put_int16(bufp, val); | ||
416 | } | ||
417 | |||
418 | static inline void v9fs_put_int32(struct cbuf *bufp, u32 val, u32 * p) | ||
419 | { | ||
420 | *p = val; | ||
421 | buf_put_int32(bufp, val); | ||
422 | } | ||
423 | |||
424 | static inline void v9fs_put_int64(struct cbuf *bufp, u64 val, u64 * p) | ||
425 | { | ||
426 | *p = val; | ||
427 | buf_put_int64(bufp, val); | ||
428 | } | ||
706 | 429 | ||
707 | return rcall->size; | 430 | static inline void |
431 | v9fs_put_str(struct cbuf *bufp, char *data, struct v9fs_str *str) | ||
432 | { | ||
433 | if (data) { | ||
434 | str->len = strlen(data); | ||
435 | str->str = bufp->p; | ||
436 | } else { | ||
437 | str->len = 0; | ||
438 | str->str = NULL; | ||
439 | } | ||
440 | |||
441 | buf_put_stringn(bufp, data, str->len); | ||
442 | } | ||
443 | |||
444 | static inline int | ||
445 | v9fs_put_user_data(struct cbuf *bufp, const char __user * data, int count, | ||
446 | unsigned char **pdata) | ||
447 | { | ||
448 | *pdata = buf_alloc(bufp, count); | ||
449 | return copy_from_user(*pdata, data, count); | ||
450 | } | ||
451 | |||
452 | static void | ||
453 | v9fs_put_wstat(struct cbuf *bufp, struct v9fs_wstat *wstat, | ||
454 | struct v9fs_stat *stat, int statsz, int extended) | ||
455 | { | ||
456 | v9fs_put_int16(bufp, statsz, &stat->size); | ||
457 | v9fs_put_int16(bufp, wstat->type, &stat->type); | ||
458 | v9fs_put_int32(bufp, wstat->dev, &stat->dev); | ||
459 | v9fs_put_int8(bufp, wstat->qid.type, &stat->qid.type); | ||
460 | v9fs_put_int32(bufp, wstat->qid.version, &stat->qid.version); | ||
461 | v9fs_put_int64(bufp, wstat->qid.path, &stat->qid.path); | ||
462 | v9fs_put_int32(bufp, wstat->mode, &stat->mode); | ||
463 | v9fs_put_int32(bufp, wstat->atime, &stat->atime); | ||
464 | v9fs_put_int32(bufp, wstat->mtime, &stat->mtime); | ||
465 | v9fs_put_int64(bufp, wstat->length, &stat->length); | ||
466 | |||
467 | v9fs_put_str(bufp, wstat->name, &stat->name); | ||
468 | v9fs_put_str(bufp, wstat->uid, &stat->uid); | ||
469 | v9fs_put_str(bufp, wstat->gid, &stat->gid); | ||
470 | v9fs_put_str(bufp, wstat->muid, &stat->muid); | ||
471 | |||
472 | if (extended) { | ||
473 | v9fs_put_str(bufp, wstat->extension, &stat->extension); | ||
474 | v9fs_put_int32(bufp, wstat->n_uid, &stat->n_uid); | ||
475 | v9fs_put_int32(bufp, wstat->n_gid, &stat->n_gid); | ||
476 | v9fs_put_int32(bufp, wstat->n_muid, &stat->n_muid); | ||
477 | } | ||
478 | } | ||
479 | |||
480 | static struct v9fs_fcall * | ||
481 | v9fs_create_common(struct cbuf *bufp, u32 size, u8 id) | ||
482 | { | ||
483 | struct v9fs_fcall *fc; | ||
484 | |||
485 | size += 4 + 1 + 2; /* size[4] id[1] tag[2] */ | ||
486 | fc = kmalloc(sizeof(struct v9fs_fcall) + size, GFP_KERNEL); | ||
487 | if (!fc) | ||
488 | return ERR_PTR(-ENOMEM); | ||
489 | |||
490 | fc->sdata = (char *)fc + sizeof(*fc); | ||
491 | |||
492 | buf_init(bufp, (char *)fc->sdata, size); | ||
493 | v9fs_put_int32(bufp, size, &fc->size); | ||
494 | v9fs_put_int8(bufp, id, &fc->id); | ||
495 | v9fs_put_int16(bufp, V9FS_NOTAG, &fc->tag); | ||
496 | |||
497 | return fc; | ||
498 | } | ||
499 | |||
500 | void v9fs_set_tag(struct v9fs_fcall *fc, u16 tag) | ||
501 | { | ||
502 | fc->tag = tag; | ||
503 | *(__le16 *) (fc->sdata + 5) = cpu_to_le16(tag); | ||
504 | } | ||
505 | |||
506 | struct v9fs_fcall *v9fs_create_tversion(u32 msize, char *version) | ||
507 | { | ||
508 | int size; | ||
509 | struct v9fs_fcall *fc; | ||
510 | struct cbuf buffer; | ||
511 | struct cbuf *bufp = &buffer; | ||
512 | |||
513 | size = 4 + 2 + strlen(version); /* msize[4] version[s] */ | ||
514 | fc = v9fs_create_common(bufp, size, TVERSION); | ||
515 | if (IS_ERR(fc)) | ||
516 | goto error; | ||
517 | |||
518 | v9fs_put_int32(bufp, msize, &fc->params.tversion.msize); | ||
519 | v9fs_put_str(bufp, version, &fc->params.tversion.version); | ||
520 | |||
521 | if (buf_check_overflow(bufp)) { | ||
522 | kfree(fc); | ||
523 | fc = ERR_PTR(-ENOMEM); | ||
524 | } | ||
525 | error: | ||
526 | return fc; | ||
527 | } | ||
528 | |||
529 | struct v9fs_fcall *v9fs_create_tauth(u32 afid, char *uname, char *aname) | ||
530 | { | ||
531 | int size; | ||
532 | struct v9fs_fcall *fc; | ||
533 | struct cbuf buffer; | ||
534 | struct cbuf *bufp = &buffer; | ||
535 | |||
536 | size = 4 + 2 + strlen(uname) + 2 + strlen(aname); /* afid[4] uname[s] aname[s] */ | ||
537 | fc = v9fs_create_common(bufp, size, TAUTH); | ||
538 | if (IS_ERR(fc)) | ||
539 | goto error; | ||
540 | |||
541 | v9fs_put_int32(bufp, afid, &fc->params.tauth.afid); | ||
542 | v9fs_put_str(bufp, uname, &fc->params.tauth.uname); | ||
543 | v9fs_put_str(bufp, aname, &fc->params.tauth.aname); | ||
544 | |||
545 | if (buf_check_overflow(bufp)) { | ||
546 | kfree(fc); | ||
547 | fc = ERR_PTR(-ENOMEM); | ||
548 | } | ||
549 | error: | ||
550 | return fc; | ||
551 | } | ||
552 | |||
553 | struct v9fs_fcall * | ||
554 | v9fs_create_tattach(u32 fid, u32 afid, char *uname, char *aname) | ||
555 | { | ||
556 | int size; | ||
557 | struct v9fs_fcall *fc; | ||
558 | struct cbuf buffer; | ||
559 | struct cbuf *bufp = &buffer; | ||
560 | |||
561 | size = 4 + 4 + 2 + strlen(uname) + 2 + strlen(aname); /* fid[4] afid[4] uname[s] aname[s] */ | ||
562 | fc = v9fs_create_common(bufp, size, TATTACH); | ||
563 | if (IS_ERR(fc)) | ||
564 | goto error; | ||
565 | |||
566 | v9fs_put_int32(bufp, fid, &fc->params.tattach.fid); | ||
567 | v9fs_put_int32(bufp, afid, &fc->params.tattach.afid); | ||
568 | v9fs_put_str(bufp, uname, &fc->params.tattach.uname); | ||
569 | v9fs_put_str(bufp, aname, &fc->params.tattach.aname); | ||
570 | |||
571 | error: | ||
572 | return fc; | ||
573 | } | ||
574 | |||
575 | struct v9fs_fcall *v9fs_create_tflush(u16 oldtag) | ||
576 | { | ||
577 | int size; | ||
578 | struct v9fs_fcall *fc; | ||
579 | struct cbuf buffer; | ||
580 | struct cbuf *bufp = &buffer; | ||
581 | |||
582 | size = 2; /* oldtag[2] */ | ||
583 | fc = v9fs_create_common(bufp, size, TFLUSH); | ||
584 | if (IS_ERR(fc)) | ||
585 | goto error; | ||
586 | |||
587 | v9fs_put_int16(bufp, oldtag, &fc->params.tflush.oldtag); | ||
588 | |||
589 | if (buf_check_overflow(bufp)) { | ||
590 | kfree(fc); | ||
591 | fc = ERR_PTR(-ENOMEM); | ||
592 | } | ||
593 | error: | ||
594 | return fc; | ||
595 | } | ||
596 | |||
597 | struct v9fs_fcall *v9fs_create_twalk(u32 fid, u32 newfid, u16 nwname, | ||
598 | char **wnames) | ||
599 | { | ||
600 | int i, size; | ||
601 | struct v9fs_fcall *fc; | ||
602 | struct cbuf buffer; | ||
603 | struct cbuf *bufp = &buffer; | ||
604 | |||
605 | if (nwname > V9FS_MAXWELEM) { | ||
606 | dprintk(DEBUG_ERROR, "nwname > %d\n", V9FS_MAXWELEM); | ||
607 | return NULL; | ||
608 | } | ||
609 | |||
610 | size = 4 + 4 + 2; /* fid[4] newfid[4] nwname[2] ... */ | ||
611 | for (i = 0; i < nwname; i++) { | ||
612 | size += 2 + strlen(wnames[i]); /* wname[s] */ | ||
613 | } | ||
614 | |||
615 | fc = v9fs_create_common(bufp, size, TWALK); | ||
616 | if (IS_ERR(fc)) | ||
617 | goto error; | ||
618 | |||
619 | v9fs_put_int32(bufp, fid, &fc->params.twalk.fid); | ||
620 | v9fs_put_int32(bufp, newfid, &fc->params.twalk.newfid); | ||
621 | v9fs_put_int16(bufp, nwname, &fc->params.twalk.nwname); | ||
622 | for (i = 0; i < nwname; i++) { | ||
623 | v9fs_put_str(bufp, wnames[i], &fc->params.twalk.wnames[i]); | ||
624 | } | ||
625 | |||
626 | if (buf_check_overflow(bufp)) { | ||
627 | kfree(fc); | ||
628 | fc = ERR_PTR(-ENOMEM); | ||
629 | } | ||
630 | error: | ||
631 | return fc; | ||
632 | } | ||
633 | |||
634 | struct v9fs_fcall *v9fs_create_topen(u32 fid, u8 mode) | ||
635 | { | ||
636 | int size; | ||
637 | struct v9fs_fcall *fc; | ||
638 | struct cbuf buffer; | ||
639 | struct cbuf *bufp = &buffer; | ||
640 | |||
641 | size = 4 + 1; /* fid[4] mode[1] */ | ||
642 | fc = v9fs_create_common(bufp, size, TOPEN); | ||
643 | if (IS_ERR(fc)) | ||
644 | goto error; | ||
645 | |||
646 | v9fs_put_int32(bufp, fid, &fc->params.topen.fid); | ||
647 | v9fs_put_int8(bufp, mode, &fc->params.topen.mode); | ||
648 | |||
649 | if (buf_check_overflow(bufp)) { | ||
650 | kfree(fc); | ||
651 | fc = ERR_PTR(-ENOMEM); | ||
652 | } | ||
653 | error: | ||
654 | return fc; | ||
655 | } | ||
656 | |||
657 | struct v9fs_fcall *v9fs_create_tcreate(u32 fid, char *name, u32 perm, u8 mode) | ||
658 | { | ||
659 | int size; | ||
660 | struct v9fs_fcall *fc; | ||
661 | struct cbuf buffer; | ||
662 | struct cbuf *bufp = &buffer; | ||
663 | |||
664 | size = 4 + 2 + strlen(name) + 4 + 1; /* fid[4] name[s] perm[4] mode[1] */ | ||
665 | fc = v9fs_create_common(bufp, size, TCREATE); | ||
666 | if (IS_ERR(fc)) | ||
667 | goto error; | ||
668 | |||
669 | v9fs_put_int32(bufp, fid, &fc->params.tcreate.fid); | ||
670 | v9fs_put_str(bufp, name, &fc->params.tcreate.name); | ||
671 | v9fs_put_int32(bufp, perm, &fc->params.tcreate.perm); | ||
672 | v9fs_put_int8(bufp, mode, &fc->params.tcreate.mode); | ||
673 | |||
674 | if (buf_check_overflow(bufp)) { | ||
675 | kfree(fc); | ||
676 | fc = ERR_PTR(-ENOMEM); | ||
677 | } | ||
678 | error: | ||
679 | return fc; | ||
680 | } | ||
681 | |||
682 | struct v9fs_fcall *v9fs_create_tread(u32 fid, u64 offset, u32 count) | ||
683 | { | ||
684 | int size; | ||
685 | struct v9fs_fcall *fc; | ||
686 | struct cbuf buffer; | ||
687 | struct cbuf *bufp = &buffer; | ||
688 | |||
689 | size = 4 + 8 + 4; /* fid[4] offset[8] count[4] */ | ||
690 | fc = v9fs_create_common(bufp, size, TREAD); | ||
691 | if (IS_ERR(fc)) | ||
692 | goto error; | ||
693 | |||
694 | v9fs_put_int32(bufp, fid, &fc->params.tread.fid); | ||
695 | v9fs_put_int64(bufp, offset, &fc->params.tread.offset); | ||
696 | v9fs_put_int32(bufp, count, &fc->params.tread.count); | ||
697 | |||
698 | if (buf_check_overflow(bufp)) { | ||
699 | kfree(fc); | ||
700 | fc = ERR_PTR(-ENOMEM); | ||
701 | } | ||
702 | error: | ||
703 | return fc; | ||
704 | } | ||
705 | |||
706 | struct v9fs_fcall *v9fs_create_twrite(u32 fid, u64 offset, u32 count, | ||
707 | const char __user * data) | ||
708 | { | ||
709 | int size, err; | ||
710 | struct v9fs_fcall *fc; | ||
711 | struct cbuf buffer; | ||
712 | struct cbuf *bufp = &buffer; | ||
713 | |||
714 | size = 4 + 8 + 4 + count; /* fid[4] offset[8] count[4] data[count] */ | ||
715 | fc = v9fs_create_common(bufp, size, TWRITE); | ||
716 | if (IS_ERR(fc)) | ||
717 | goto error; | ||
718 | |||
719 | v9fs_put_int32(bufp, fid, &fc->params.twrite.fid); | ||
720 | v9fs_put_int64(bufp, offset, &fc->params.twrite.offset); | ||
721 | v9fs_put_int32(bufp, count, &fc->params.twrite.count); | ||
722 | err = v9fs_put_user_data(bufp, data, count, &fc->params.twrite.data); | ||
723 | if (err) { | ||
724 | kfree(fc); | ||
725 | fc = ERR_PTR(err); | ||
726 | } | ||
727 | |||
728 | if (buf_check_overflow(bufp)) { | ||
729 | kfree(fc); | ||
730 | fc = ERR_PTR(-ENOMEM); | ||
731 | } | ||
732 | error: | ||
733 | return fc; | ||
734 | } | ||
735 | |||
736 | struct v9fs_fcall *v9fs_create_tclunk(u32 fid) | ||
737 | { | ||
738 | int size; | ||
739 | struct v9fs_fcall *fc; | ||
740 | struct cbuf buffer; | ||
741 | struct cbuf *bufp = &buffer; | ||
742 | |||
743 | size = 4; /* fid[4] */ | ||
744 | fc = v9fs_create_common(bufp, size, TCLUNK); | ||
745 | if (IS_ERR(fc)) | ||
746 | goto error; | ||
747 | |||
748 | v9fs_put_int32(bufp, fid, &fc->params.tclunk.fid); | ||
749 | |||
750 | if (buf_check_overflow(bufp)) { | ||
751 | kfree(fc); | ||
752 | fc = ERR_PTR(-ENOMEM); | ||
753 | } | ||
754 | error: | ||
755 | return fc; | ||
756 | } | ||
757 | |||
758 | struct v9fs_fcall *v9fs_create_tremove(u32 fid) | ||
759 | { | ||
760 | int size; | ||
761 | struct v9fs_fcall *fc; | ||
762 | struct cbuf buffer; | ||
763 | struct cbuf *bufp = &buffer; | ||
764 | |||
765 | size = 4; /* fid[4] */ | ||
766 | fc = v9fs_create_common(bufp, size, TREMOVE); | ||
767 | if (IS_ERR(fc)) | ||
768 | goto error; | ||
769 | |||
770 | v9fs_put_int32(bufp, fid, &fc->params.tremove.fid); | ||
771 | |||
772 | if (buf_check_overflow(bufp)) { | ||
773 | kfree(fc); | ||
774 | fc = ERR_PTR(-ENOMEM); | ||
775 | } | ||
776 | error: | ||
777 | return fc; | ||
778 | } | ||
779 | |||
780 | struct v9fs_fcall *v9fs_create_tstat(u32 fid) | ||
781 | { | ||
782 | int size; | ||
783 | struct v9fs_fcall *fc; | ||
784 | struct cbuf buffer; | ||
785 | struct cbuf *bufp = &buffer; | ||
786 | |||
787 | size = 4; /* fid[4] */ | ||
788 | fc = v9fs_create_common(bufp, size, TSTAT); | ||
789 | if (IS_ERR(fc)) | ||
790 | goto error; | ||
791 | |||
792 | v9fs_put_int32(bufp, fid, &fc->params.tstat.fid); | ||
793 | |||
794 | if (buf_check_overflow(bufp)) { | ||
795 | kfree(fc); | ||
796 | fc = ERR_PTR(-ENOMEM); | ||
797 | } | ||
798 | error: | ||
799 | return fc; | ||
800 | } | ||
801 | |||
802 | struct v9fs_fcall *v9fs_create_twstat(u32 fid, struct v9fs_wstat *wstat, | ||
803 | int extended) | ||
804 | { | ||
805 | int size, statsz; | ||
806 | struct v9fs_fcall *fc; | ||
807 | struct cbuf buffer; | ||
808 | struct cbuf *bufp = &buffer; | ||
809 | |||
810 | statsz = v9fs_size_wstat(wstat, extended); | ||
811 | size = 4 + 2 + 2 + statsz; /* fid[4] stat[n] */ | ||
812 | fc = v9fs_create_common(bufp, size, TWSTAT); | ||
813 | if (IS_ERR(fc)) | ||
814 | goto error; | ||
815 | |||
816 | v9fs_put_int32(bufp, fid, &fc->params.twstat.fid); | ||
817 | buf_put_int16(bufp, statsz + 2); | ||
818 | v9fs_put_wstat(bufp, wstat, &fc->params.twstat.stat, statsz, extended); | ||
819 | |||
820 | if (buf_check_overflow(bufp)) { | ||
821 | kfree(fc); | ||
822 | fc = ERR_PTR(-ENOMEM); | ||
823 | } | ||
824 | error: | ||
825 | return fc; | ||
708 | } | 826 | } |
diff --git a/fs/9p/conv.h b/fs/9p/conv.h index ee849613c61a..26a736e4a2e7 100644 --- a/fs/9p/conv.h +++ b/fs/9p/conv.h | |||
@@ -1,8 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * linux/fs/9p/conv.h | 2 | * linux/fs/9p/conv.h |
3 | * | 3 | * |
4 | * 9P protocol conversion definitions | 4 | * 9P protocol conversion definitions. |
5 | * | 5 | * |
6 | * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net> | ||
6 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> | 7 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> |
7 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> | 8 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> |
8 | * | 9 | * |
@@ -24,13 +25,27 @@ | |||
24 | * | 25 | * |
25 | */ | 26 | */ |
26 | 27 | ||
27 | int v9fs_deserialize_stat(struct v9fs_session_info *, void *buf, | 28 | int v9fs_deserialize_stat(void *buf, u32 buflen, struct v9fs_stat *stat, |
28 | u32 buflen, struct v9fs_stat *stat, u32 statlen); | 29 | int extended); |
29 | int v9fs_serialize_fcall(struct v9fs_session_info *, struct v9fs_fcall *tcall, | 30 | int v9fs_deserialize_fcall(void *buf, u32 buflen, struct v9fs_fcall *rcall, |
30 | void *buf, u32 buflen); | 31 | int extended); |
31 | int v9fs_deserialize_fcall(struct v9fs_session_info *, u32 msglen, | ||
32 | void *buf, u32 buflen, struct v9fs_fcall *rcall, | ||
33 | int rcalllen); | ||
34 | 32 | ||
35 | /* this one is actually in error.c right now */ | 33 | void v9fs_set_tag(struct v9fs_fcall *fc, u16 tag); |
36 | int v9fs_errstr2errno(char *errstr); | 34 | |
35 | struct v9fs_fcall *v9fs_create_tversion(u32 msize, char *version); | ||
36 | struct v9fs_fcall *v9fs_create_tauth(u32 afid, char *uname, char *aname); | ||
37 | struct v9fs_fcall *v9fs_create_tattach(u32 fid, u32 afid, char *uname, | ||
38 | char *aname); | ||
39 | struct v9fs_fcall *v9fs_create_tflush(u16 oldtag); | ||
40 | struct v9fs_fcall *v9fs_create_twalk(u32 fid, u32 newfid, u16 nwname, | ||
41 | char **wnames); | ||
42 | struct v9fs_fcall *v9fs_create_topen(u32 fid, u8 mode); | ||
43 | struct v9fs_fcall *v9fs_create_tcreate(u32 fid, char *name, u32 perm, u8 mode); | ||
44 | struct v9fs_fcall *v9fs_create_tread(u32 fid, u64 offset, u32 count); | ||
45 | struct v9fs_fcall *v9fs_create_twrite(u32 fid, u64 offset, u32 count, | ||
46 | const char __user *data); | ||
47 | struct v9fs_fcall *v9fs_create_tclunk(u32 fid); | ||
48 | struct v9fs_fcall *v9fs_create_tremove(u32 fid); | ||
49 | struct v9fs_fcall *v9fs_create_tstat(u32 fid); | ||
50 | struct v9fs_fcall *v9fs_create_twstat(u32 fid, struct v9fs_wstat *wstat, | ||
51 | int extended); | ||
diff --git a/fs/9p/debug.h b/fs/9p/debug.h index 4445f06919d9..fe551032788b 100644 --- a/fs/9p/debug.h +++ b/fs/9p/debug.h | |||
@@ -51,16 +51,23 @@ do { \ | |||
51 | #if DEBUG_DUMP_PKT | 51 | #if DEBUG_DUMP_PKT |
52 | static inline void dump_data(const unsigned char *data, unsigned int datalen) | 52 | static inline void dump_data(const unsigned char *data, unsigned int datalen) |
53 | { | 53 | { |
54 | int i, j; | 54 | int i, n; |
55 | int len = datalen; | 55 | char buf[5*8]; |
56 | 56 | ||
57 | printk(KERN_DEBUG "data "); | 57 | n = 0; |
58 | for (i = 0; i < len; i += 4) { | 58 | i = 0; |
59 | for (j = 0; (j < 4) && (i + j < len); j++) | 59 | while (i < datalen) { |
60 | printk(KERN_DEBUG "%02x", data[i + j]); | 60 | n += snprintf(buf+n, sizeof(buf)-n, "%02x", data[i++]); |
61 | printk(KERN_DEBUG " "); | 61 | if (i%4 == 0) |
62 | n += snprintf(buf+n, sizeof(buf)-n, " "); | ||
63 | |||
64 | if (i%16 == 0) { | ||
65 | dprintk(DEBUG_ERROR, "%s\n", buf); | ||
66 | n = 0; | ||
67 | } | ||
62 | } | 68 | } |
63 | printk(KERN_DEBUG "\n"); | 69 | |
70 | dprintk(DEBUG_ERROR, "%s\n", buf); | ||
64 | } | 71 | } |
65 | #else /* DEBUG_DUMP_PKT */ | 72 | #else /* DEBUG_DUMP_PKT */ |
66 | static inline void dump_data(const unsigned char *data, unsigned int datalen) | 73 | static inline void dump_data(const unsigned char *data, unsigned int datalen) |
diff --git a/fs/9p/error.c b/fs/9p/error.c index 834cb179e388..e4b6f8f38b6f 100644 --- a/fs/9p/error.c +++ b/fs/9p/error.c | |||
@@ -33,7 +33,6 @@ | |||
33 | 33 | ||
34 | #include <linux/list.h> | 34 | #include <linux/list.h> |
35 | #include <linux/jhash.h> | 35 | #include <linux/jhash.h> |
36 | #include <linux/string.h> | ||
37 | 36 | ||
38 | #include "debug.h" | 37 | #include "debug.h" |
39 | #include "error.h" | 38 | #include "error.h" |
@@ -55,7 +54,8 @@ int v9fs_error_init(void) | |||
55 | 54 | ||
56 | /* load initial error map into hash table */ | 55 | /* load initial error map into hash table */ |
57 | for (c = errmap; c->name != NULL; c++) { | 56 | for (c = errmap; c->name != NULL; c++) { |
58 | bucket = jhash(c->name, strlen(c->name), 0) % ERRHASHSZ; | 57 | c->namelen = strlen(c->name); |
58 | bucket = jhash(c->name, c->namelen, 0) % ERRHASHSZ; | ||
59 | INIT_HLIST_NODE(&c->list); | 59 | INIT_HLIST_NODE(&c->list); |
60 | hlist_add_head(&c->list, &hash_errmap[bucket]); | 60 | hlist_add_head(&c->list, &hash_errmap[bucket]); |
61 | } | 61 | } |
@@ -69,15 +69,15 @@ int v9fs_error_init(void) | |||
69 | * | 69 | * |
70 | */ | 70 | */ |
71 | 71 | ||
72 | int v9fs_errstr2errno(char *errstr) | 72 | int v9fs_errstr2errno(char *errstr, int len) |
73 | { | 73 | { |
74 | int errno = 0; | 74 | int errno = 0; |
75 | struct hlist_node *p = NULL; | 75 | struct hlist_node *p = NULL; |
76 | struct errormap *c = NULL; | 76 | struct errormap *c = NULL; |
77 | int bucket = jhash(errstr, strlen(errstr), 0) % ERRHASHSZ; | 77 | int bucket = jhash(errstr, len, 0) % ERRHASHSZ; |
78 | 78 | ||
79 | hlist_for_each_entry(c, p, &hash_errmap[bucket], list) { | 79 | hlist_for_each_entry(c, p, &hash_errmap[bucket], list) { |
80 | if (!strcmp(c->name, errstr)) { | 80 | if (c->namelen==len && !memcmp(c->name, errstr, len)) { |
81 | errno = c->val; | 81 | errno = c->val; |
82 | break; | 82 | break; |
83 | } | 83 | } |
diff --git a/fs/9p/error.h b/fs/9p/error.h index 78f89acf7c9a..a9794e85fe51 100644 --- a/fs/9p/error.h +++ b/fs/9p/error.h | |||
@@ -36,6 +36,7 @@ struct errormap { | |||
36 | char *name; | 36 | char *name; |
37 | int val; | 37 | int val; |
38 | 38 | ||
39 | int namelen; | ||
39 | struct hlist_node list; | 40 | struct hlist_node list; |
40 | }; | 41 | }; |
41 | 42 | ||
@@ -175,4 +176,3 @@ static struct errormap errmap[] = { | |||
175 | }; | 176 | }; |
176 | 177 | ||
177 | extern int v9fs_error_init(void); | 178 | extern int v9fs_error_init(void); |
178 | extern int v9fs_errstr2errno(char *errstr); | ||
diff --git a/fs/9p/fid.c b/fs/9p/fid.c index d95f8626d170..eda449778fa5 100644 --- a/fs/9p/fid.c +++ b/fs/9p/fid.c | |||
@@ -31,9 +31,6 @@ | |||
31 | #include "v9fs.h" | 31 | #include "v9fs.h" |
32 | #include "9p.h" | 32 | #include "9p.h" |
33 | #include "v9fs_vfs.h" | 33 | #include "v9fs_vfs.h" |
34 | #include "transport.h" | ||
35 | #include "mux.h" | ||
36 | #include "conv.h" | ||
37 | #include "fid.h" | 34 | #include "fid.h" |
38 | 35 | ||
39 | /** | 36 | /** |
@@ -164,7 +161,7 @@ static struct v9fs_fid *v9fs_fid_walk_up(struct dentry *dentry) | |||
164 | return v9fs_fid_create(dentry, v9ses, fidnum, 0); | 161 | return v9fs_fid_create(dentry, v9ses, fidnum, 0); |
165 | 162 | ||
166 | clunk_fid: | 163 | clunk_fid: |
167 | v9fs_t_clunk(v9ses, fidnum, NULL); | 164 | v9fs_t_clunk(v9ses, fidnum); |
168 | return ERR_PTR(err); | 165 | return ERR_PTR(err); |
169 | } | 166 | } |
170 | 167 | ||
diff --git a/fs/9p/mux.c b/fs/9p/mux.c index 8835b576f744..945cb368d451 100644 --- a/fs/9p/mux.c +++ b/fs/9p/mux.c | |||
@@ -4,7 +4,7 @@ | |||
4 | * Protocol Multiplexer | 4 | * Protocol Multiplexer |
5 | * | 5 | * |
6 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> | 6 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> |
7 | * Copyright (C) 2004 by Latchesar Ionkov <lucho@ionkov.net> | 7 | * Copyright (C) 2004-2005 by Latchesar Ionkov <lucho@ionkov.net> |
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by |
@@ -28,448 +28,943 @@ | |||
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/errno.h> | 29 | #include <linux/errno.h> |
30 | #include <linux/fs.h> | 30 | #include <linux/fs.h> |
31 | #include <linux/poll.h> | ||
31 | #include <linux/kthread.h> | 32 | #include <linux/kthread.h> |
32 | #include <linux/idr.h> | 33 | #include <linux/idr.h> |
33 | 34 | ||
34 | #include "debug.h" | 35 | #include "debug.h" |
35 | #include "v9fs.h" | 36 | #include "v9fs.h" |
36 | #include "9p.h" | 37 | #include "9p.h" |
37 | #include "transport.h" | ||
38 | #include "conv.h" | 38 | #include "conv.h" |
39 | #include "transport.h" | ||
39 | #include "mux.h" | 40 | #include "mux.h" |
40 | 41 | ||
42 | #define ERREQFLUSH 1 | ||
43 | #define SCHED_TIMEOUT 10 | ||
44 | #define MAXPOLLWADDR 2 | ||
45 | |||
46 | enum { | ||
47 | Rworksched = 1, /* read work scheduled or running */ | ||
48 | Rpending = 2, /* can read */ | ||
49 | Wworksched = 4, /* write work scheduled or running */ | ||
50 | Wpending = 8, /* can write */ | ||
51 | }; | ||
52 | |||
53 | struct v9fs_mux_poll_task; | ||
54 | |||
55 | struct v9fs_req { | ||
56 | int tag; | ||
57 | struct v9fs_fcall *tcall; | ||
58 | struct v9fs_fcall *rcall; | ||
59 | int err; | ||
60 | v9fs_mux_req_callback cb; | ||
61 | void *cba; | ||
62 | struct list_head req_list; | ||
63 | }; | ||
64 | |||
65 | struct v9fs_mux_data { | ||
66 | spinlock_t lock; | ||
67 | struct list_head mux_list; | ||
68 | struct v9fs_mux_poll_task *poll_task; | ||
69 | int msize; | ||
70 | unsigned char *extended; | ||
71 | struct v9fs_transport *trans; | ||
72 | struct v9fs_idpool tidpool; | ||
73 | int err; | ||
74 | wait_queue_head_t equeue; | ||
75 | struct list_head req_list; | ||
76 | struct list_head unsent_req_list; | ||
77 | struct v9fs_fcall *rcall; | ||
78 | int rpos; | ||
79 | char *rbuf; | ||
80 | int wpos; | ||
81 | int wsize; | ||
82 | char *wbuf; | ||
83 | wait_queue_t poll_wait[MAXPOLLWADDR]; | ||
84 | wait_queue_head_t *poll_waddr[MAXPOLLWADDR]; | ||
85 | poll_table pt; | ||
86 | struct work_struct rq; | ||
87 | struct work_struct wq; | ||
88 | unsigned long wsched; | ||
89 | }; | ||
90 | |||
91 | struct v9fs_mux_poll_task { | ||
92 | struct task_struct *task; | ||
93 | struct list_head mux_list; | ||
94 | int muxnum; | ||
95 | }; | ||
96 | |||
97 | struct v9fs_mux_rpc { | ||
98 | struct v9fs_mux_data *m; | ||
99 | struct v9fs_req *req; | ||
100 | int err; | ||
101 | struct v9fs_fcall *rcall; | ||
102 | wait_queue_head_t wqueue; | ||
103 | }; | ||
104 | |||
105 | static int v9fs_poll_proc(void *); | ||
106 | static void v9fs_read_work(void *); | ||
107 | static void v9fs_write_work(void *); | ||
108 | static void v9fs_pollwait(struct file *filp, wait_queue_head_t * wait_address, | ||
109 | poll_table * p); | ||
110 | static u16 v9fs_mux_get_tag(struct v9fs_mux_data *); | ||
111 | static void v9fs_mux_put_tag(struct v9fs_mux_data *, u16); | ||
112 | |||
113 | static DECLARE_MUTEX(v9fs_mux_task_lock); | ||
114 | static struct workqueue_struct *v9fs_mux_wq; | ||
115 | |||
116 | static int v9fs_mux_num; | ||
117 | static int v9fs_mux_poll_task_num; | ||
118 | static struct v9fs_mux_poll_task v9fs_mux_poll_tasks[100]; | ||
119 | |||
120 | int v9fs_mux_global_init(void) | ||
121 | { | ||
122 | int i; | ||
123 | |||
124 | for (i = 0; i < ARRAY_SIZE(v9fs_mux_poll_tasks); i++) | ||
125 | v9fs_mux_poll_tasks[i].task = NULL; | ||
126 | |||
127 | v9fs_mux_wq = create_workqueue("v9fs"); | ||
128 | if (!v9fs_mux_wq) | ||
129 | return -ENOMEM; | ||
130 | |||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | void v9fs_mux_global_exit(void) | ||
135 | { | ||
136 | destroy_workqueue(v9fs_mux_wq); | ||
137 | } | ||
138 | |||
41 | /** | 139 | /** |
42 | * dprintcond - print condition of session info | 140 | * v9fs_mux_calc_poll_procs - calculates the number of polling procs |
43 | * @v9ses: session info structure | 141 | * based on the number of mounted v9fs filesystems. |
44 | * @req: RPC request structure | ||
45 | * | 142 | * |
143 | * The current implementation returns sqrt of the number of mounts. | ||
46 | */ | 144 | */ |
145 | inline int v9fs_mux_calc_poll_procs(int muxnum) | ||
146 | { | ||
147 | int n; | ||
148 | |||
149 | if (v9fs_mux_poll_task_num) | ||
150 | n = muxnum / v9fs_mux_poll_task_num + | ||
151 | (muxnum % v9fs_mux_poll_task_num ? 1 : 0); | ||
152 | else | ||
153 | n = 1; | ||
154 | |||
155 | if (n > ARRAY_SIZE(v9fs_mux_poll_tasks)) | ||
156 | n = ARRAY_SIZE(v9fs_mux_poll_tasks); | ||
157 | |||
158 | return n; | ||
159 | } | ||
47 | 160 | ||
48 | static inline int | 161 | static int v9fs_mux_poll_start(struct v9fs_mux_data *m) |
49 | dprintcond(struct v9fs_session_info *v9ses, struct v9fs_rpcreq *req) | ||
50 | { | 162 | { |
51 | dprintk(DEBUG_MUX, "condition: %d, %p\n", v9ses->transport->status, | 163 | int i, n; |
52 | req->rcall); | 164 | struct v9fs_mux_poll_task *vpt, *vptlast; |
165 | struct task_struct *pproc; | ||
166 | |||
167 | dprintk(DEBUG_MUX, "mux %p muxnum %d procnum %d\n", m, v9fs_mux_num, | ||
168 | v9fs_mux_poll_task_num); | ||
169 | up(&v9fs_mux_task_lock); | ||
170 | |||
171 | n = v9fs_mux_calc_poll_procs(v9fs_mux_num + 1); | ||
172 | if (n > v9fs_mux_poll_task_num) { | ||
173 | for (i = 0; i < ARRAY_SIZE(v9fs_mux_poll_tasks); i++) { | ||
174 | if (v9fs_mux_poll_tasks[i].task == NULL) { | ||
175 | vpt = &v9fs_mux_poll_tasks[i]; | ||
176 | dprintk(DEBUG_MUX, "create proc %p\n", vpt); | ||
177 | pproc = kthread_create(v9fs_poll_proc, vpt, | ||
178 | "v9fs-poll"); | ||
179 | |||
180 | if (!IS_ERR(pproc)) { | ||
181 | vpt->task = pproc; | ||
182 | INIT_LIST_HEAD(&vpt->mux_list); | ||
183 | vpt->muxnum = 0; | ||
184 | v9fs_mux_poll_task_num++; | ||
185 | wake_up_process(vpt->task); | ||
186 | } | ||
187 | break; | ||
188 | } | ||
189 | } | ||
190 | |||
191 | if (i >= ARRAY_SIZE(v9fs_mux_poll_tasks)) | ||
192 | dprintk(DEBUG_ERROR, "warning: no free poll slots\n"); | ||
193 | } | ||
194 | |||
195 | n = (v9fs_mux_num + 1) / v9fs_mux_poll_task_num + | ||
196 | ((v9fs_mux_num + 1) % v9fs_mux_poll_task_num ? 1 : 0); | ||
197 | |||
198 | vptlast = NULL; | ||
199 | for (i = 0; i < ARRAY_SIZE(v9fs_mux_poll_tasks); i++) { | ||
200 | vpt = &v9fs_mux_poll_tasks[i]; | ||
201 | if (vpt->task != NULL) { | ||
202 | vptlast = vpt; | ||
203 | if (vpt->muxnum < n) { | ||
204 | dprintk(DEBUG_MUX, "put in proc %d\n", i); | ||
205 | list_add(&m->mux_list, &vpt->mux_list); | ||
206 | vpt->muxnum++; | ||
207 | m->poll_task = vpt; | ||
208 | memset(&m->poll_waddr, 0, sizeof(m->poll_waddr)); | ||
209 | init_poll_funcptr(&m->pt, v9fs_pollwait); | ||
210 | break; | ||
211 | } | ||
212 | } | ||
213 | } | ||
214 | |||
215 | if (i >= ARRAY_SIZE(v9fs_mux_poll_tasks)) { | ||
216 | if (vptlast == NULL) | ||
217 | return -ENOMEM; | ||
218 | |||
219 | dprintk(DEBUG_MUX, "put in proc %d\n", i); | ||
220 | list_add(&m->mux_list, &vptlast->mux_list); | ||
221 | vptlast->muxnum++; | ||
222 | m->poll_task = vptlast; | ||
223 | memset(&m->poll_waddr, 0, sizeof(m->poll_waddr)); | ||
224 | init_poll_funcptr(&m->pt, v9fs_pollwait); | ||
225 | } | ||
226 | |||
227 | v9fs_mux_num++; | ||
228 | down(&v9fs_mux_task_lock); | ||
229 | |||
53 | return 0; | 230 | return 0; |
54 | } | 231 | } |
55 | 232 | ||
233 | static void v9fs_mux_poll_stop(struct v9fs_mux_data *m) | ||
234 | { | ||
235 | int i; | ||
236 | struct v9fs_mux_poll_task *vpt; | ||
237 | |||
238 | up(&v9fs_mux_task_lock); | ||
239 | vpt = m->poll_task; | ||
240 | list_del(&m->mux_list); | ||
241 | for(i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) { | ||
242 | if (m->poll_waddr[i] != NULL) { | ||
243 | remove_wait_queue(m->poll_waddr[i], &m->poll_wait[i]); | ||
244 | m->poll_waddr[i] = NULL; | ||
245 | } | ||
246 | } | ||
247 | vpt->muxnum--; | ||
248 | if (!vpt->muxnum) { | ||
249 | dprintk(DEBUG_MUX, "destroy proc %p\n", vpt); | ||
250 | send_sig(SIGKILL, vpt->task, 1); | ||
251 | vpt->task = NULL; | ||
252 | v9fs_mux_poll_task_num--; | ||
253 | } | ||
254 | v9fs_mux_num--; | ||
255 | down(&v9fs_mux_task_lock); | ||
256 | } | ||
257 | |||
56 | /** | 258 | /** |
57 | * xread - force read of a certain number of bytes | 259 | * v9fs_mux_init - allocate and initialize the per-session mux data |
58 | * @v9ses: session info structure | 260 | * Creates the polling task if this is the first session. |
59 | * @ptr: pointer to buffer | ||
60 | * @sz: number of bytes to read | ||
61 | * | 261 | * |
62 | * Chuck Cranor CS-533 project1 | 262 | * @trans - transport structure |
263 | * @msize - maximum message size | ||
264 | * @extended - pointer to the extended flag | ||
63 | */ | 265 | */ |
64 | 266 | struct v9fs_mux_data *v9fs_mux_init(struct v9fs_transport *trans, int msize, | |
65 | static int xread(struct v9fs_session_info *v9ses, void *ptr, unsigned long sz) | 267 | unsigned char *extended) |
66 | { | 268 | { |
67 | int rd = 0; | 269 | int i, n; |
68 | int ret = 0; | 270 | struct v9fs_mux_data *m, *mtmp; |
69 | while (rd < sz) { | 271 | |
70 | ret = v9ses->transport->read(v9ses->transport, ptr, sz - rd); | 272 | dprintk(DEBUG_MUX, "transport %p msize %d\n", trans, msize); |
71 | if (ret <= 0) { | 273 | m = kmalloc(sizeof(struct v9fs_mux_data), GFP_KERNEL); |
72 | dprintk(DEBUG_ERROR, "xread errno %d\n", ret); | 274 | if (!m) |
73 | return ret; | 275 | return ERR_PTR(-ENOMEM); |
276 | |||
277 | spin_lock_init(&m->lock); | ||
278 | INIT_LIST_HEAD(&m->mux_list); | ||
279 | m->msize = msize; | ||
280 | m->extended = extended; | ||
281 | m->trans = trans; | ||
282 | idr_init(&m->tidpool.pool); | ||
283 | init_MUTEX(&m->tidpool.lock); | ||
284 | m->err = 0; | ||
285 | init_waitqueue_head(&m->equeue); | ||
286 | INIT_LIST_HEAD(&m->req_list); | ||
287 | INIT_LIST_HEAD(&m->unsent_req_list); | ||
288 | m->rcall = NULL; | ||
289 | m->rpos = 0; | ||
290 | m->rbuf = NULL; | ||
291 | m->wpos = m->wsize = 0; | ||
292 | m->wbuf = NULL; | ||
293 | INIT_WORK(&m->rq, v9fs_read_work, m); | ||
294 | INIT_WORK(&m->wq, v9fs_write_work, m); | ||
295 | m->wsched = 0; | ||
296 | memset(&m->poll_waddr, 0, sizeof(m->poll_waddr)); | ||
297 | m->poll_task = NULL; | ||
298 | n = v9fs_mux_poll_start(m); | ||
299 | if (n) | ||
300 | return ERR_PTR(n); | ||
301 | |||
302 | n = trans->poll(trans, &m->pt); | ||
303 | if (n & POLLIN) { | ||
304 | dprintk(DEBUG_MUX, "mux %p can read\n", m); | ||
305 | set_bit(Rpending, &m->wsched); | ||
306 | } | ||
307 | |||
308 | if (n & POLLOUT) { | ||
309 | dprintk(DEBUG_MUX, "mux %p can write\n", m); | ||
310 | set_bit(Wpending, &m->wsched); | ||
311 | } | ||
312 | |||
313 | for(i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) { | ||
314 | if (IS_ERR(m->poll_waddr[i])) { | ||
315 | v9fs_mux_poll_stop(m); | ||
316 | mtmp = (void *)m->poll_waddr; /* the error code */ | ||
317 | kfree(m); | ||
318 | m = mtmp; | ||
319 | break; | ||
74 | } | 320 | } |
75 | rd += ret; | ||
76 | ptr += ret; | ||
77 | } | 321 | } |
78 | return (rd); | 322 | |
323 | return m; | ||
79 | } | 324 | } |
80 | 325 | ||
81 | /** | 326 | /** |
82 | * read_message - read a full 9P2000 fcall packet | 327 | * v9fs_mux_destroy - cancels all pending requests and frees mux resources |
83 | * @v9ses: session info structure | ||
84 | * @rcall: fcall structure to read into | ||
85 | * @rcalllen: size of fcall buffer | ||
86 | * | ||
87 | */ | 328 | */ |
329 | void v9fs_mux_destroy(struct v9fs_mux_data *m) | ||
330 | { | ||
331 | dprintk(DEBUG_MUX, "mux %p prev %p next %p\n", m, | ||
332 | m->mux_list.prev, m->mux_list.next); | ||
333 | v9fs_mux_cancel(m, -ECONNRESET); | ||
334 | |||
335 | if (!list_empty(&m->req_list)) { | ||
336 | /* wait until all processes waiting on this session exit */ | ||
337 | dprintk(DEBUG_MUX, "mux %p waiting for empty request queue\n", | ||
338 | m); | ||
339 | wait_event_timeout(m->equeue, (list_empty(&m->req_list)), 5000); | ||
340 | dprintk(DEBUG_MUX, "mux %p request queue empty: %d\n", m, | ||
341 | list_empty(&m->req_list)); | ||
342 | } | ||
343 | |||
344 | v9fs_mux_poll_stop(m); | ||
345 | m->trans = NULL; | ||
346 | |||
347 | kfree(m); | ||
348 | } | ||
88 | 349 | ||
89 | static int | 350 | /** |
90 | read_message(struct v9fs_session_info *v9ses, | 351 | * v9fs_pollwait - called by files poll operation to add v9fs-poll task |
91 | struct v9fs_fcall *rcall, int rcalllen) | 352 | * to files wait queue |
353 | */ | ||
354 | static void | ||
355 | v9fs_pollwait(struct file *filp, wait_queue_head_t * wait_address, | ||
356 | poll_table * p) | ||
92 | { | 357 | { |
93 | unsigned char buf[4]; | 358 | int i; |
94 | void *data; | 359 | struct v9fs_mux_data *m; |
95 | int size = 0; | 360 | |
96 | int res = 0; | 361 | m = container_of(p, struct v9fs_mux_data, pt); |
97 | 362 | for(i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) | |
98 | res = xread(v9ses, buf, sizeof(buf)); | 363 | if (m->poll_waddr[i] == NULL) |
99 | if (res < 0) { | 364 | break; |
100 | dprintk(DEBUG_ERROR, | 365 | |
101 | "Reading of count field failed returned: %d\n", res); | 366 | if (i >= ARRAY_SIZE(m->poll_waddr)) { |
102 | return res; | 367 | dprintk(DEBUG_ERROR, "not enough wait_address slots\n"); |
368 | return; | ||
103 | } | 369 | } |
104 | 370 | ||
105 | if (res < 4) { | 371 | m->poll_waddr[i] = wait_address; |
106 | dprintk(DEBUG_ERROR, | 372 | |
107 | "Reading of count field failed returned: %d\n", res); | 373 | if (!wait_address) { |
108 | return -EIO; | 374 | dprintk(DEBUG_ERROR, "no wait_address\n"); |
375 | m->poll_waddr[i] = ERR_PTR(-EIO); | ||
376 | return; | ||
109 | } | 377 | } |
110 | 378 | ||
111 | size = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); | 379 | init_waitqueue_entry(&m->poll_wait[i], m->poll_task->task); |
112 | dprintk(DEBUG_MUX, "got a packet count: %d\n", size); | 380 | add_wait_queue(wait_address, &m->poll_wait[i]); |
381 | } | ||
382 | |||
383 | /** | ||
384 | * v9fs_poll_mux - polls a mux and schedules read or write works if necessary | ||
385 | */ | ||
386 | static inline void v9fs_poll_mux(struct v9fs_mux_data *m) | ||
387 | { | ||
388 | int n; | ||
113 | 389 | ||
114 | /* adjust for the four bytes of size */ | 390 | if (m->err < 0) |
115 | size -= 4; | 391 | return; |
116 | 392 | ||
117 | if (size > v9ses->maxdata) { | 393 | n = m->trans->poll(m->trans, NULL); |
118 | dprintk(DEBUG_ERROR, "packet too big: %d\n", size); | 394 | if (n < 0 || n & (POLLERR | POLLHUP | POLLNVAL)) { |
119 | return -E2BIG; | 395 | dprintk(DEBUG_MUX, "error mux %p err %d\n", m, n); |
396 | if (n >= 0) | ||
397 | n = -ECONNRESET; | ||
398 | v9fs_mux_cancel(m, n); | ||
120 | } | 399 | } |
121 | 400 | ||
122 | data = kmalloc(size, GFP_KERNEL); | 401 | if (n & POLLIN) { |
123 | if (!data) { | 402 | set_bit(Rpending, &m->wsched); |
124 | eprintk(KERN_WARNING, "out of memory\n"); | 403 | dprintk(DEBUG_MUX, "mux %p can read\n", m); |
125 | return -ENOMEM; | 404 | if (!test_and_set_bit(Rworksched, &m->wsched)) { |
405 | dprintk(DEBUG_MUX, "schedule read work mux %p\n", m); | ||
406 | queue_work(v9fs_mux_wq, &m->rq); | ||
407 | } | ||
126 | } | 408 | } |
127 | 409 | ||
128 | res = xread(v9ses, data, size); | 410 | if (n & POLLOUT) { |
129 | if (res < size) { | 411 | set_bit(Wpending, &m->wsched); |
130 | dprintk(DEBUG_ERROR, "Reading of fcall failed returned: %d\n", | 412 | dprintk(DEBUG_MUX, "mux %p can write\n", m); |
131 | res); | 413 | if ((m->wsize || !list_empty(&m->unsent_req_list)) |
132 | kfree(data); | 414 | && !test_and_set_bit(Wworksched, &m->wsched)) { |
133 | return res; | 415 | dprintk(DEBUG_MUX, "schedule write work mux %p\n", m); |
416 | queue_work(v9fs_mux_wq, &m->wq); | ||
417 | } | ||
134 | } | 418 | } |
419 | } | ||
420 | |||
421 | /** | ||
422 | * v9fs_poll_proc - polls all v9fs transports for new events and queues | ||
423 | * the appropriate work to the work queue | ||
424 | */ | ||
425 | static int v9fs_poll_proc(void *a) | ||
426 | { | ||
427 | struct v9fs_mux_data *m, *mtmp; | ||
428 | struct v9fs_mux_poll_task *vpt; | ||
135 | 429 | ||
136 | /* we now have an in-memory string that is the reply. | 430 | vpt = a; |
137 | * deserialize it. There is very little to go wrong at this point | 431 | dprintk(DEBUG_MUX, "start %p %p\n", current, vpt); |
138 | * save for v9fs_alloc errors. | 432 | allow_signal(SIGKILL); |
139 | */ | 433 | while (!kthread_should_stop()) { |
140 | res = v9fs_deserialize_fcall(v9ses, size, data, v9ses->maxdata, | 434 | set_current_state(TASK_INTERRUPTIBLE); |
141 | rcall, rcalllen); | 435 | if (signal_pending(current)) |
436 | break; | ||
142 | 437 | ||
143 | kfree(data); | 438 | list_for_each_entry_safe(m, mtmp, &vpt->mux_list, mux_list) { |
439 | v9fs_poll_mux(m); | ||
440 | } | ||
144 | 441 | ||
145 | if (res < 0) | 442 | dprintk(DEBUG_MUX, "sleeping...\n"); |
146 | return res; | 443 | schedule_timeout(SCHED_TIMEOUT * HZ); |
444 | } | ||
147 | 445 | ||
446 | __set_current_state(TASK_RUNNING); | ||
447 | dprintk(DEBUG_MUX, "finish\n"); | ||
148 | return 0; | 448 | return 0; |
149 | } | 449 | } |
150 | 450 | ||
151 | /** | 451 | /** |
152 | * v9fs_recv - receive an RPC response for a particular tag | 452 | * v9fs_write_work - called when a transport can send some data |
153 | * @v9ses: session info structure | ||
154 | * @req: RPC request structure | ||
155 | * | ||
156 | */ | 453 | */ |
157 | 454 | static void v9fs_write_work(void *a) | |
158 | static int v9fs_recv(struct v9fs_session_info *v9ses, struct v9fs_rpcreq *req) | ||
159 | { | 455 | { |
160 | int ret = 0; | 456 | int n, err; |
457 | struct v9fs_mux_data *m; | ||
458 | struct v9fs_req *req; | ||
161 | 459 | ||
162 | dprintk(DEBUG_MUX, "waiting for response: %d\n", req->tcall->tag); | 460 | m = a; |
163 | ret = wait_event_interruptible(v9ses->read_wait, | ||
164 | ((v9ses->transport->status != Connected) || | ||
165 | (req->rcall != 0) || (req->err < 0) || | ||
166 | dprintcond(v9ses, req))); | ||
167 | 461 | ||
168 | dprintk(DEBUG_MUX, "got it: rcall %p\n", req->rcall); | 462 | if (m->err < 0) { |
463 | clear_bit(Wworksched, &m->wsched); | ||
464 | return; | ||
465 | } | ||
169 | 466 | ||
170 | spin_lock(&v9ses->muxlock); | 467 | if (!m->wsize) { |
171 | list_del(&req->next); | 468 | if (list_empty(&m->unsent_req_list)) { |
172 | spin_unlock(&v9ses->muxlock); | 469 | clear_bit(Wworksched, &m->wsched); |
470 | return; | ||
471 | } | ||
173 | 472 | ||
174 | if (req->err < 0) | 473 | spin_lock(&m->lock); |
175 | return req->err; | 474 | req = |
475 | list_entry(m->unsent_req_list.next, struct v9fs_req, | ||
476 | req_list); | ||
477 | list_move_tail(&req->req_list, &m->req_list); | ||
478 | m->wbuf = req->tcall->sdata; | ||
479 | m->wsize = req->tcall->size; | ||
480 | m->wpos = 0; | ||
481 | dump_data(m->wbuf, m->wsize); | ||
482 | spin_unlock(&m->lock); | ||
483 | } | ||
176 | 484 | ||
177 | if (v9ses->transport->status == Disconnected) | 485 | dprintk(DEBUG_MUX, "mux %p pos %d size %d\n", m, m->wpos, m->wsize); |
178 | return -ECONNRESET; | 486 | clear_bit(Wpending, &m->wsched); |
487 | err = m->trans->write(m->trans, m->wbuf + m->wpos, m->wsize - m->wpos); | ||
488 | dprintk(DEBUG_MUX, "mux %p sent %d bytes\n", m, err); | ||
489 | if (err == -EAGAIN) { | ||
490 | clear_bit(Wworksched, &m->wsched); | ||
491 | return; | ||
492 | } | ||
179 | 493 | ||
180 | return ret; | 494 | if (err <= 0) |
181 | } | 495 | goto error; |
182 | 496 | ||
183 | /** | 497 | m->wpos += err; |
184 | * v9fs_send - send a 9P request | 498 | if (m->wpos == m->wsize) |
185 | * @v9ses: session info structure | 499 | m->wpos = m->wsize = 0; |
186 | * @req: RPC request to send | 500 | |
187 | * | 501 | if (m->wsize == 0 && !list_empty(&m->unsent_req_list)) { |
188 | */ | 502 | if (test_and_clear_bit(Wpending, &m->wsched)) |
503 | n = POLLOUT; | ||
504 | else | ||
505 | n = m->trans->poll(m->trans, NULL); | ||
506 | |||
507 | if (n & POLLOUT) { | ||
508 | dprintk(DEBUG_MUX, "schedule write work mux %p\n", m); | ||
509 | queue_work(v9fs_mux_wq, &m->wq); | ||
510 | } else | ||
511 | clear_bit(Wworksched, &m->wsched); | ||
512 | } else | ||
513 | clear_bit(Wworksched, &m->wsched); | ||
514 | |||
515 | return; | ||
189 | 516 | ||
190 | static int v9fs_send(struct v9fs_session_info *v9ses, struct v9fs_rpcreq *req) | 517 | error: |
518 | v9fs_mux_cancel(m, err); | ||
519 | clear_bit(Wworksched, &m->wsched); | ||
520 | } | ||
521 | |||
522 | static void process_request(struct v9fs_mux_data *m, struct v9fs_req *req) | ||
191 | { | 523 | { |
192 | int ret = -1; | 524 | int ecode, tag; |
193 | void *data = NULL; | 525 | struct v9fs_str *ename; |
194 | struct v9fs_fcall *tcall = req->tcall; | ||
195 | 526 | ||
196 | data = kmalloc(v9ses->maxdata + V9FS_IOHDRSZ, GFP_KERNEL); | 527 | tag = req->tag; |
197 | if (!data) | 528 | if (req->rcall->id == RERROR && !req->err) { |
198 | return -ENOMEM; | 529 | ecode = req->rcall->params.rerror.errno; |
530 | ename = &req->rcall->params.rerror.error; | ||
199 | 531 | ||
200 | tcall->size = 0; /* enforce size recalculation */ | 532 | dprintk(DEBUG_MUX, "Rerror %.*s\n", ename->len, ename->str); |
201 | ret = | ||
202 | v9fs_serialize_fcall(v9ses, tcall, data, | ||
203 | v9ses->maxdata + V9FS_IOHDRSZ); | ||
204 | if (ret < 0) | ||
205 | goto free_data; | ||
206 | 533 | ||
207 | spin_lock(&v9ses->muxlock); | 534 | if (*m->extended) |
208 | list_add(&req->next, &v9ses->mux_fcalls); | 535 | req->err = -ecode; |
209 | spin_unlock(&v9ses->muxlock); | ||
210 | 536 | ||
211 | dprintk(DEBUG_MUX, "sending message: tag %d size %d\n", tcall->tag, | 537 | if (!req->err) { |
212 | tcall->size); | 538 | req->err = v9fs_errstr2errno(ename->str, ename->len); |
213 | ret = v9ses->transport->write(v9ses->transport, data, tcall->size); | ||
214 | 539 | ||
215 | if (ret != tcall->size) { | 540 | if (!req->err) { /* string match failed */ |
216 | spin_lock(&v9ses->muxlock); | 541 | PRINT_FCALL_ERROR("unknown error", req->rcall); |
217 | list_del(&req->next); | 542 | } |
218 | kfree(req->rcall); | 543 | |
544 | if (!req->err) | ||
545 | req->err = -ESERVERFAULT; | ||
546 | } | ||
547 | } else if (req->tcall && req->rcall->id != req->tcall->id + 1) { | ||
548 | dprintk(DEBUG_ERROR, "fcall mismatch: expected %d, got %d\n", | ||
549 | req->tcall->id + 1, req->rcall->id); | ||
550 | if (!req->err) | ||
551 | req->err = -EIO; | ||
552 | } | ||
219 | 553 | ||
220 | spin_unlock(&v9ses->muxlock); | 554 | if (req->cb && req->err != ERREQFLUSH) { |
221 | if (ret >= 0) | 555 | dprintk(DEBUG_MUX, "calling callback tcall %p rcall %p\n", |
222 | ret = -EREMOTEIO; | 556 | req->tcall, req->rcall); |
557 | |||
558 | (*req->cb) (req->cba, req->tcall, req->rcall, req->err); | ||
559 | req->cb = NULL; | ||
223 | } else | 560 | } else |
224 | ret = 0; | 561 | kfree(req->rcall); |
225 | 562 | ||
226 | free_data: | 563 | v9fs_mux_put_tag(m, tag); |
227 | kfree(data); | 564 | |
228 | return ret; | 565 | wake_up(&m->equeue); |
566 | kfree(req); | ||
229 | } | 567 | } |
230 | 568 | ||
231 | /** | 569 | /** |
232 | * v9fs_mux_rpc - send a request, receive a response | 570 | * v9fs_read_work - called when there is some data to be read from a transport |
233 | * @v9ses: session info structure | ||
234 | * @tcall: fcall to send | ||
235 | * @rcall: buffer to place response into | ||
236 | * | ||
237 | */ | 571 | */ |
238 | 572 | static void v9fs_read_work(void *a) | |
239 | long | ||
240 | v9fs_mux_rpc(struct v9fs_session_info *v9ses, struct v9fs_fcall *tcall, | ||
241 | struct v9fs_fcall **rcall) | ||
242 | { | 573 | { |
243 | int tid = -1; | 574 | int n, err; |
244 | struct v9fs_fcall *fcall = NULL; | 575 | struct v9fs_mux_data *m; |
245 | struct v9fs_rpcreq req; | 576 | struct v9fs_req *req, *rptr, *rreq; |
246 | int ret = -1; | 577 | struct v9fs_fcall *rcall; |
247 | 578 | char *rbuf; | |
248 | if (!v9ses) | 579 | |
249 | return -EINVAL; | 580 | m = a; |
250 | 581 | ||
251 | if (!v9ses->transport || v9ses->transport->status != Connected) | 582 | if (m->err < 0) |
252 | return -EIO; | 583 | return; |
584 | |||
585 | rcall = NULL; | ||
586 | dprintk(DEBUG_MUX, "start mux %p pos %d\n", m, m->rpos); | ||
587 | |||
588 | if (!m->rcall) { | ||
589 | m->rcall = | ||
590 | kmalloc(sizeof(struct v9fs_fcall) + m->msize, GFP_KERNEL); | ||
591 | if (!m->rcall) { | ||
592 | err = -ENOMEM; | ||
593 | goto error; | ||
594 | } | ||
253 | 595 | ||
254 | if (rcall) | 596 | m->rbuf = (char *)m->rcall + sizeof(struct v9fs_fcall); |
255 | *rcall = NULL; | 597 | m->rpos = 0; |
598 | } | ||
256 | 599 | ||
257 | if (tcall->id != TVERSION) { | 600 | clear_bit(Rpending, &m->wsched); |
258 | tid = v9fs_get_idpool(&v9ses->tidpool); | 601 | err = m->trans->read(m->trans, m->rbuf + m->rpos, m->msize - m->rpos); |
259 | if (tid < 0) | 602 | dprintk(DEBUG_MUX, "mux %p got %d bytes\n", m, err); |
260 | return -ENOMEM; | 603 | if (err == -EAGAIN) { |
604 | clear_bit(Rworksched, &m->wsched); | ||
605 | return; | ||
261 | } | 606 | } |
262 | 607 | ||
263 | tcall->tag = tid; | 608 | if (err <= 0) |
609 | goto error; | ||
264 | 610 | ||
265 | req.tcall = tcall; | 611 | m->rpos += err; |
266 | req.err = 0; | 612 | while (m->rpos > 4) { |
267 | req.rcall = NULL; | 613 | n = le32_to_cpu(*(__le32 *) m->rbuf); |
614 | if (n >= m->msize) { | ||
615 | dprintk(DEBUG_ERROR, | ||
616 | "requested packet size too big: %d\n", n); | ||
617 | err = -EIO; | ||
618 | goto error; | ||
619 | } | ||
268 | 620 | ||
269 | ret = v9fs_send(v9ses, &req); | 621 | if (m->rpos < n) |
622 | break; | ||
270 | 623 | ||
271 | if (ret < 0) { | 624 | dump_data(m->rbuf, n); |
272 | if (tcall->id != TVERSION) | 625 | err = |
273 | v9fs_put_idpool(tid, &v9ses->tidpool); | 626 | v9fs_deserialize_fcall(m->rbuf, n, m->rcall, *m->extended); |
274 | dprintk(DEBUG_MUX, "error %d\n", ret); | 627 | if (err < 0) { |
275 | return ret; | 628 | goto error; |
276 | } | 629 | } |
630 | |||
631 | rcall = m->rcall; | ||
632 | rbuf = m->rbuf; | ||
633 | if (m->rpos > n) { | ||
634 | m->rcall = kmalloc(sizeof(struct v9fs_fcall) + m->msize, | ||
635 | GFP_KERNEL); | ||
636 | if (!m->rcall) { | ||
637 | err = -ENOMEM; | ||
638 | goto error; | ||
639 | } | ||
277 | 640 | ||
278 | ret = v9fs_recv(v9ses, &req); | 641 | m->rbuf = (char *)m->rcall + sizeof(struct v9fs_fcall); |
279 | 642 | memmove(m->rbuf, rbuf + n, m->rpos - n); | |
280 | fcall = req.rcall; | 643 | m->rpos -= n; |
281 | 644 | } else { | |
282 | dprintk(DEBUG_MUX, "received: tag=%x, ret=%d\n", tcall->tag, ret); | 645 | m->rcall = NULL; |
283 | if (ret == -ERESTARTSYS) { | 646 | m->rbuf = NULL; |
284 | if (v9ses->transport->status != Disconnected | 647 | m->rpos = 0; |
285 | && tcall->id != TFLUSH) { | ||
286 | unsigned long flags; | ||
287 | |||
288 | dprintk(DEBUG_MUX, "flushing the tag: %d\n", | ||
289 | tcall->tag); | ||
290 | clear_thread_flag(TIF_SIGPENDING); | ||
291 | v9fs_t_flush(v9ses, tcall->tag); | ||
292 | spin_lock_irqsave(¤t->sighand->siglock, flags); | ||
293 | recalc_sigpending(); | ||
294 | spin_unlock_irqrestore(¤t->sighand->siglock, | ||
295 | flags); | ||
296 | dprintk(DEBUG_MUX, "flushing done\n"); | ||
297 | } | 648 | } |
298 | 649 | ||
299 | goto release_req; | 650 | dprintk(DEBUG_MUX, "mux %p fcall id %d tag %d\n", m, rcall->id, |
300 | } else if (ret < 0) | 651 | rcall->tag); |
301 | goto release_req; | 652 | |
302 | 653 | req = NULL; | |
303 | if (!fcall) | 654 | spin_lock(&m->lock); |
304 | ret = -EIO; | 655 | list_for_each_entry_safe(rreq, rptr, &m->req_list, req_list) { |
305 | else { | 656 | if (rreq->tag == rcall->tag) { |
306 | if (fcall->id == RERROR) { | 657 | req = rreq; |
307 | ret = v9fs_errstr2errno(fcall->params.rerror.error); | 658 | req->rcall = rcall; |
308 | if (ret == 0) { /* string match failed */ | 659 | list_del(&req->req_list); |
309 | if (fcall->params.rerror.errno) | 660 | spin_unlock(&m->lock); |
310 | ret = -(fcall->params.rerror.errno); | 661 | process_request(m, req); |
311 | else | 662 | break; |
312 | ret = -ESERVERFAULT; | ||
313 | } | 663 | } |
314 | } else if (fcall->id != tcall->id + 1) { | 664 | |
315 | dprintk(DEBUG_ERROR, | 665 | } |
316 | "fcall mismatch: expected %d, got %d\n", | 666 | |
317 | tcall->id + 1, fcall->id); | 667 | if (!req) { |
318 | ret = -EIO; | 668 | spin_unlock(&m->lock); |
669 | if (err >= 0 && rcall->id != RFLUSH) | ||
670 | dprintk(DEBUG_ERROR, | ||
671 | "unexpected response mux %p id %d tag %d\n", | ||
672 | m, rcall->id, rcall->tag); | ||
673 | kfree(rcall); | ||
319 | } | 674 | } |
320 | } | 675 | } |
321 | 676 | ||
322 | release_req: | 677 | if (!list_empty(&m->req_list)) { |
323 | if (tcall->id != TVERSION) | 678 | if (test_and_clear_bit(Rpending, &m->wsched)) |
324 | v9fs_put_idpool(tid, &v9ses->tidpool); | 679 | n = POLLIN; |
325 | if (rcall) | 680 | else |
326 | *rcall = fcall; | 681 | n = m->trans->poll(m->trans, NULL); |
327 | else | 682 | |
328 | kfree(fcall); | 683 | if (n & POLLIN) { |
684 | dprintk(DEBUG_MUX, "schedule read work mux %p\n", m); | ||
685 | queue_work(v9fs_mux_wq, &m->rq); | ||
686 | } else | ||
687 | clear_bit(Rworksched, &m->wsched); | ||
688 | } else | ||
689 | clear_bit(Rworksched, &m->wsched); | ||
690 | |||
691 | return; | ||
329 | 692 | ||
330 | return ret; | 693 | error: |
694 | v9fs_mux_cancel(m, err); | ||
695 | clear_bit(Rworksched, &m->wsched); | ||
331 | } | 696 | } |
332 | 697 | ||
333 | /** | 698 | /** |
334 | * v9fs_mux_cancel_requests - cancels all pending requests | 699 | * v9fs_send_request - send 9P request |
700 | * The function can sleep until the request is scheduled for sending. | ||
701 | * The function can be interrupted. Return from the function is not | ||
702 | * a guarantee that the request is sent succesfully. Can return errors | ||
703 | * that can be retrieved by PTR_ERR macros. | ||
335 | * | 704 | * |
336 | * @v9ses: session info structure | 705 | * @m: mux data |
337 | * @err: error code to return to the requests | 706 | * @tc: request to be sent |
707 | * @cb: callback function to call when response is received | ||
708 | * @cba: parameter to pass to the callback function | ||
338 | */ | 709 | */ |
339 | void v9fs_mux_cancel_requests(struct v9fs_session_info *v9ses, int err) | 710 | static struct v9fs_req *v9fs_send_request(struct v9fs_mux_data *m, |
711 | struct v9fs_fcall *tc, | ||
712 | v9fs_mux_req_callback cb, void *cba) | ||
340 | { | 713 | { |
341 | struct v9fs_rpcreq *rptr; | 714 | int n; |
342 | struct v9fs_rpcreq *rreq; | 715 | struct v9fs_req *req; |
343 | 716 | ||
344 | dprintk(DEBUG_MUX, " %d\n", err); | 717 | dprintk(DEBUG_MUX, "mux %p task %p tcall %p id %d\n", m, current, |
345 | spin_lock(&v9ses->muxlock); | 718 | tc, tc->id); |
346 | list_for_each_entry_safe(rreq, rptr, &v9ses->mux_fcalls, next) { | 719 | if (m->err < 0) |
347 | rreq->err = err; | 720 | return ERR_PTR(m->err); |
348 | } | ||
349 | spin_unlock(&v9ses->muxlock); | ||
350 | wake_up_all(&v9ses->read_wait); | ||
351 | } | ||
352 | 721 | ||
353 | /** | 722 | req = kmalloc(sizeof(struct v9fs_req), GFP_KERNEL); |
354 | * v9fs_recvproc - kproc to handle demultiplexing responses | 723 | if (!req) |
355 | * @data: session info structure | 724 | return ERR_PTR(-ENOMEM); |
356 | * | ||
357 | */ | ||
358 | 725 | ||
359 | static int v9fs_recvproc(void *data) | 726 | if (tc->id == TVERSION) |
360 | { | 727 | n = V9FS_NOTAG; |
361 | struct v9fs_session_info *v9ses = (struct v9fs_session_info *)data; | 728 | else |
362 | struct v9fs_fcall *rcall = NULL; | 729 | n = v9fs_mux_get_tag(m); |
363 | struct v9fs_rpcreq *rptr; | ||
364 | struct v9fs_rpcreq *req; | ||
365 | struct v9fs_rpcreq *rreq; | ||
366 | int err = 0; | ||
367 | 730 | ||
368 | allow_signal(SIGKILL); | 731 | if (n < 0) |
369 | set_current_state(TASK_INTERRUPTIBLE); | 732 | return ERR_PTR(-ENOMEM); |
370 | complete(&v9ses->proccmpl); | ||
371 | while (!kthread_should_stop() && err >= 0) { | ||
372 | req = rptr = rreq = NULL; | ||
373 | |||
374 | rcall = kmalloc(v9ses->maxdata + V9FS_IOHDRSZ, GFP_KERNEL); | ||
375 | if (!rcall) { | ||
376 | eprintk(KERN_ERR, "no memory for buffers\n"); | ||
377 | break; | ||
378 | } | ||
379 | 733 | ||
380 | err = read_message(v9ses, rcall, v9ses->maxdata + V9FS_IOHDRSZ); | 734 | v9fs_set_tag(tc, n); |
381 | spin_lock(&v9ses->muxlock); | ||
382 | if (err < 0) { | ||
383 | list_for_each_entry_safe(rreq, rptr, &v9ses->mux_fcalls, next) { | ||
384 | rreq->err = err; | ||
385 | } | ||
386 | if(err != -ERESTARTSYS) | ||
387 | eprintk(KERN_ERR, | ||
388 | "Transport error while reading message %d\n", err); | ||
389 | } else { | ||
390 | list_for_each_entry_safe(rreq, rptr, &v9ses->mux_fcalls, next) { | ||
391 | if (rreq->tcall->tag == rcall->tag) { | ||
392 | req = rreq; | ||
393 | req->rcall = rcall; | ||
394 | break; | ||
395 | } | ||
396 | } | ||
397 | } | ||
398 | 735 | ||
399 | if (req && (req->tcall->id == TFLUSH)) { | 736 | req->tag = n; |
400 | struct v9fs_rpcreq *treq = NULL; | 737 | req->tcall = tc; |
401 | list_for_each_entry_safe(treq, rptr, &v9ses->mux_fcalls, next) { | 738 | req->rcall = NULL; |
402 | if (treq->tcall->tag == | 739 | req->err = 0; |
403 | req->tcall->params.tflush.oldtag) { | 740 | req->cb = cb; |
404 | list_del(&rptr->next); | 741 | req->cba = cba; |
405 | kfree(treq->rcall); | 742 | |
406 | break; | 743 | spin_lock(&m->lock); |
407 | } | 744 | list_add_tail(&req->req_list, &m->unsent_req_list); |
745 | spin_unlock(&m->lock); | ||
746 | |||
747 | if (test_and_clear_bit(Wpending, &m->wsched)) | ||
748 | n = POLLOUT; | ||
749 | else | ||
750 | n = m->trans->poll(m->trans, NULL); | ||
751 | |||
752 | if (n & POLLOUT && !test_and_set_bit(Wworksched, &m->wsched)) | ||
753 | queue_work(v9fs_mux_wq, &m->wq); | ||
754 | |||
755 | return req; | ||
756 | } | ||
757 | |||
758 | static inline void | ||
759 | v9fs_mux_flush_cb(void *a, struct v9fs_fcall *tc, struct v9fs_fcall *rc, | ||
760 | int err) | ||
761 | { | ||
762 | v9fs_mux_req_callback cb; | ||
763 | int tag; | ||
764 | struct v9fs_mux_data *m; | ||
765 | struct v9fs_req *req, *rptr; | ||
766 | |||
767 | m = a; | ||
768 | dprintk(DEBUG_MUX, "mux %p tc %p rc %p err %d oldtag %d\n", m, tc, | ||
769 | rc, err, tc->params.tflush.oldtag); | ||
770 | |||
771 | spin_lock(&m->lock); | ||
772 | cb = NULL; | ||
773 | tag = tc->params.tflush.oldtag; | ||
774 | list_for_each_entry_safe(req, rptr, &m->req_list, req_list) { | ||
775 | if (req->tag == tag) { | ||
776 | list_del(&req->req_list); | ||
777 | if (req->cb) { | ||
778 | cb = req->cb; | ||
779 | req->cb = NULL; | ||
780 | spin_unlock(&m->lock); | ||
781 | (*cb) (req->cba, req->tcall, req->rcall, | ||
782 | req->err); | ||
408 | } | 783 | } |
784 | kfree(req); | ||
785 | wake_up(&m->equeue); | ||
786 | break; | ||
409 | } | 787 | } |
788 | } | ||
410 | 789 | ||
411 | spin_unlock(&v9ses->muxlock); | 790 | if (!cb) |
791 | spin_unlock(&m->lock); | ||
412 | 792 | ||
413 | if (!req) { | 793 | v9fs_mux_put_tag(m, tag); |
414 | if (err >= 0) | 794 | kfree(tc); |
415 | dprintk(DEBUG_ERROR, | 795 | kfree(rc); |
416 | "unexpected response: id %d tag %d\n", | 796 | } |
417 | rcall->id, rcall->tag); | ||
418 | 797 | ||
419 | kfree(rcall); | 798 | static void |
420 | } | 799 | v9fs_mux_flush_request(struct v9fs_mux_data *m, struct v9fs_req *req) |
800 | { | ||
801 | struct v9fs_fcall *fc; | ||
421 | 802 | ||
422 | wake_up_all(&v9ses->read_wait); | 803 | dprintk(DEBUG_MUX, "mux %p req %p tag %d\n", m, req, req->tag); |
423 | set_current_state(TASK_INTERRUPTIBLE); | 804 | |
805 | fc = v9fs_create_tflush(req->tag); | ||
806 | v9fs_send_request(m, fc, v9fs_mux_flush_cb, m); | ||
807 | } | ||
808 | |||
809 | static void | ||
810 | v9fs_mux_rpc_cb(void *a, struct v9fs_fcall *tc, struct v9fs_fcall *rc, int err) | ||
811 | { | ||
812 | struct v9fs_mux_rpc *r; | ||
813 | |||
814 | if (err == ERREQFLUSH) { | ||
815 | dprintk(DEBUG_MUX, "err req flush\n"); | ||
816 | return; | ||
424 | } | 817 | } |
425 | 818 | ||
426 | v9ses->transport->close(v9ses->transport); | 819 | r = a; |
820 | dprintk(DEBUG_MUX, "mux %p req %p tc %p rc %p err %d\n", r->m, r->req, | ||
821 | tc, rc, err); | ||
822 | r->rcall = rc; | ||
823 | r->err = err; | ||
824 | wake_up(&r->wqueue); | ||
825 | } | ||
427 | 826 | ||
428 | /* Inform all pending processes about the failure */ | 827 | /** |
429 | wake_up_all(&v9ses->read_wait); | 828 | * v9fs_mux_rpc - sends 9P request and waits until a response is available. |
829 | * The function can be interrupted. | ||
830 | * @m: mux data | ||
831 | * @tc: request to be sent | ||
832 | * @rc: pointer where a pointer to the response is stored | ||
833 | */ | ||
834 | int | ||
835 | v9fs_mux_rpc(struct v9fs_mux_data *m, struct v9fs_fcall *tc, | ||
836 | struct v9fs_fcall **rc) | ||
837 | { | ||
838 | int err; | ||
839 | unsigned long flags; | ||
840 | struct v9fs_req *req; | ||
841 | struct v9fs_mux_rpc r; | ||
842 | |||
843 | r.err = 0; | ||
844 | r.rcall = NULL; | ||
845 | r.m = m; | ||
846 | init_waitqueue_head(&r.wqueue); | ||
847 | |||
848 | if (rc) | ||
849 | *rc = NULL; | ||
850 | |||
851 | req = v9fs_send_request(m, tc, v9fs_mux_rpc_cb, &r); | ||
852 | if (IS_ERR(req)) { | ||
853 | err = PTR_ERR(req); | ||
854 | dprintk(DEBUG_MUX, "error %d\n", err); | ||
855 | return PTR_ERR(req); | ||
856 | } | ||
430 | 857 | ||
431 | if (signal_pending(current)) | 858 | r.req = req; |
432 | complete(&v9ses->proccmpl); | 859 | dprintk(DEBUG_MUX, "mux %p tc %p tag %d rpc %p req %p\n", m, tc, |
860 | req->tag, &r, req); | ||
861 | err = wait_event_interruptible(r.wqueue, r.rcall != NULL || r.err < 0); | ||
862 | if (r.err < 0) | ||
863 | err = r.err; | ||
864 | |||
865 | if (err == -ERESTARTSYS && m->trans->status == Connected && m->err == 0) { | ||
866 | spin_lock(&m->lock); | ||
867 | req->tcall = NULL; | ||
868 | req->err = ERREQFLUSH; | ||
869 | spin_unlock(&m->lock); | ||
870 | |||
871 | clear_thread_flag(TIF_SIGPENDING); | ||
872 | v9fs_mux_flush_request(m, req); | ||
873 | spin_lock_irqsave(¤t->sighand->siglock, flags); | ||
874 | recalc_sigpending(); | ||
875 | spin_unlock_irqrestore(¤t->sighand->siglock, flags); | ||
876 | } | ||
433 | 877 | ||
434 | dprintk(DEBUG_MUX, "recvproc: end\n"); | 878 | if (!err) { |
435 | v9ses->recvproc = NULL; | 879 | if (r.rcall) |
880 | dprintk(DEBUG_MUX, "got response id %d tag %d\n", | ||
881 | r.rcall->id, r.rcall->tag); | ||
882 | |||
883 | if (rc) | ||
884 | *rc = r.rcall; | ||
885 | else | ||
886 | kfree(r.rcall); | ||
887 | } else { | ||
888 | kfree(r.rcall); | ||
889 | dprintk(DEBUG_MUX, "got error %d\n", err); | ||
890 | if (err > 0) | ||
891 | err = -EIO; | ||
892 | } | ||
436 | 893 | ||
437 | return err >= 0; | 894 | return err; |
438 | } | 895 | } |
439 | 896 | ||
440 | /** | 897 | /** |
441 | * v9fs_mux_init - initialize multiplexer (spawn kproc) | 898 | * v9fs_mux_rpcnb - sends 9P request without waiting for response. |
442 | * @v9ses: session info structure | 899 | * @m: mux data |
443 | * @dev_name: mount device information (to create unique kproc) | 900 | * @tc: request to be sent |
444 | * | 901 | * @cb: callback function to be called when response arrives |
902 | * @cba: value to pass to the callback function | ||
445 | */ | 903 | */ |
904 | int v9fs_mux_rpcnb(struct v9fs_mux_data *m, struct v9fs_fcall *tc, | ||
905 | v9fs_mux_req_callback cb, void *a) | ||
906 | { | ||
907 | int err; | ||
908 | struct v9fs_req *req; | ||
909 | |||
910 | req = v9fs_send_request(m, tc, cb, a); | ||
911 | if (IS_ERR(req)) { | ||
912 | err = PTR_ERR(req); | ||
913 | dprintk(DEBUG_MUX, "error %d\n", err); | ||
914 | return PTR_ERR(req); | ||
915 | } | ||
916 | |||
917 | dprintk(DEBUG_MUX, "mux %p tc %p tag %d\n", m, tc, req->tag); | ||
918 | return 0; | ||
919 | } | ||
446 | 920 | ||
447 | int v9fs_mux_init(struct v9fs_session_info *v9ses, const char *dev_name) | 921 | /** |
922 | * v9fs_mux_cancel - cancel all pending requests with error | ||
923 | * @m: mux data | ||
924 | * @err: error code | ||
925 | */ | ||
926 | void v9fs_mux_cancel(struct v9fs_mux_data *m, int err) | ||
448 | { | 927 | { |
449 | char procname[60]; | 928 | struct v9fs_req *req, *rtmp; |
450 | 929 | LIST_HEAD(cancel_list); | |
451 | strncpy(procname, dev_name, sizeof(procname)); | 930 | |
452 | procname[sizeof(procname) - 1] = 0; | 931 | dprintk(DEBUG_MUX, "mux %p err %d\n", m, err); |
453 | 932 | m->err = err; | |
454 | init_waitqueue_head(&v9ses->read_wait); | 933 | spin_lock(&m->lock); |
455 | init_completion(&v9ses->fcread); | 934 | list_for_each_entry_safe(req, rtmp, &m->req_list, req_list) { |
456 | init_completion(&v9ses->proccmpl); | 935 | list_move(&req->req_list, &cancel_list); |
457 | spin_lock_init(&v9ses->muxlock); | ||
458 | INIT_LIST_HEAD(&v9ses->mux_fcalls); | ||
459 | v9ses->recvproc = NULL; | ||
460 | v9ses->curfcall = NULL; | ||
461 | |||
462 | v9ses->recvproc = kthread_create(v9fs_recvproc, v9ses, | ||
463 | "v9fs_recvproc %s", procname); | ||
464 | |||
465 | if (IS_ERR(v9ses->recvproc)) { | ||
466 | eprintk(KERN_ERR, "cannot create receiving thread\n"); | ||
467 | v9fs_session_close(v9ses); | ||
468 | return -ECONNABORTED; | ||
469 | } | 936 | } |
937 | spin_unlock(&m->lock); | ||
470 | 938 | ||
471 | wake_up_process(v9ses->recvproc); | 939 | list_for_each_entry_safe(req, rtmp, &cancel_list, req_list) { |
472 | wait_for_completion(&v9ses->proccmpl); | 940 | list_del(&req->req_list); |
941 | if (!req->err) | ||
942 | req->err = err; | ||
473 | 943 | ||
474 | return 0; | 944 | if (req->cb) |
945 | (*req->cb) (req->cba, req->tcall, req->rcall, req->err); | ||
946 | else | ||
947 | kfree(req->rcall); | ||
948 | |||
949 | kfree(req); | ||
950 | } | ||
951 | |||
952 | wake_up(&m->equeue); | ||
953 | } | ||
954 | |||
955 | static u16 v9fs_mux_get_tag(struct v9fs_mux_data *m) | ||
956 | { | ||
957 | int tag; | ||
958 | |||
959 | tag = v9fs_get_idpool(&m->tidpool); | ||
960 | if (tag < 0) | ||
961 | return V9FS_NOTAG; | ||
962 | else | ||
963 | return (u16) tag; | ||
964 | } | ||
965 | |||
966 | static void v9fs_mux_put_tag(struct v9fs_mux_data *m, u16 tag) | ||
967 | { | ||
968 | if (tag != V9FS_NOTAG && v9fs_check_idpool(tag, &m->tidpool)) | ||
969 | v9fs_put_idpool(tag, &m->tidpool); | ||
475 | } | 970 | } |
diff --git a/fs/9p/mux.h b/fs/9p/mux.h index 4994cb10badf..9473b84f24b2 100644 --- a/fs/9p/mux.h +++ b/fs/9p/mux.h | |||
@@ -3,6 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Multiplexer Definitions | 4 | * Multiplexer Definitions |
5 | * | 5 | * |
6 | * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net> | ||
6 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> | 7 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> |
7 | * | 8 | * |
8 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
@@ -23,19 +24,35 @@ | |||
23 | * | 24 | * |
24 | */ | 25 | */ |
25 | 26 | ||
26 | /* structure to manage each RPC transaction */ | 27 | struct v9fs_mux_data; |
27 | 28 | ||
28 | struct v9fs_rpcreq { | 29 | /** |
29 | struct v9fs_fcall *tcall; | 30 | * v9fs_mux_req_callback - callback function that is called when the |
30 | struct v9fs_fcall *rcall; | 31 | * response of a request is received. The callback is called from |
31 | int err; /* error code if response failed */ | 32 | * a workqueue and shouldn't block. |
33 | * | ||
34 | * @a - the pointer that was specified when the request was send to be | ||
35 | * passed to the callback | ||
36 | * @tc - request call | ||
37 | * @rc - response call | ||
38 | * @err - error code (non-zero if error occured) | ||
39 | */ | ||
40 | typedef void (*v9fs_mux_req_callback)(void *a, struct v9fs_fcall *tc, | ||
41 | struct v9fs_fcall *rc, int err); | ||
42 | |||
43 | int v9fs_mux_global_init(void); | ||
44 | void v9fs_mux_global_exit(void); | ||
32 | 45 | ||
33 | /* XXX - could we put scatter/gather buffers here? */ | 46 | struct v9fs_mux_data *v9fs_mux_init(struct v9fs_transport *trans, int msize, |
47 | unsigned char *extended); | ||
48 | void v9fs_mux_destroy(struct v9fs_mux_data *); | ||
34 | 49 | ||
35 | struct list_head next; | 50 | int v9fs_mux_send(struct v9fs_mux_data *m, struct v9fs_fcall *tc); |
36 | }; | 51 | struct v9fs_fcall *v9fs_mux_recv(struct v9fs_mux_data *m); |
52 | int v9fs_mux_rpc(struct v9fs_mux_data *m, struct v9fs_fcall *tc, struct v9fs_fcall **rc); | ||
53 | int v9fs_mux_rpcnb(struct v9fs_mux_data *m, struct v9fs_fcall *tc, | ||
54 | v9fs_mux_req_callback cb, void *a); | ||
37 | 55 | ||
38 | int v9fs_mux_init(struct v9fs_session_info *v9ses, const char *dev_name); | 56 | void v9fs_mux_flush(struct v9fs_mux_data *m, int sendflush); |
39 | long v9fs_mux_rpc(struct v9fs_session_info *v9ses, | 57 | void v9fs_mux_cancel(struct v9fs_mux_data *m, int err); |
40 | struct v9fs_fcall *tcall, struct v9fs_fcall **rcall); | 58 | int v9fs_errstr2errno(char *errstr, int len); |
41 | void v9fs_mux_cancel_requests(struct v9fs_session_info *v9ses, int err); | ||
diff --git a/fs/9p/trans_fd.c b/fs/9p/trans_fd.c index 63b58ce98ff4..1a28ef97a3d1 100644 --- a/fs/9p/trans_fd.c +++ b/fs/9p/trans_fd.c | |||
@@ -3,6 +3,7 @@ | |||
3 | * | 3 | * |
4 | * File Descriptor Transport Layer | 4 | * File Descriptor Transport Layer |
5 | * | 5 | * |
6 | * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net> | ||
6 | * Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com> | 7 | * Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com> |
7 | * | 8 | * |
8 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
@@ -106,9 +107,6 @@ v9fs_fd_init(struct v9fs_session_info *v9ses, const char *addr, char *data) | |||
106 | return -ENOPROTOOPT; | 107 | return -ENOPROTOOPT; |
107 | } | 108 | } |
108 | 109 | ||
109 | sema_init(&trans->writelock, 1); | ||
110 | sema_init(&trans->readlock, 1); | ||
111 | |||
112 | ts = kmalloc(sizeof(struct v9fs_trans_fd), GFP_KERNEL); | 110 | ts = kmalloc(sizeof(struct v9fs_trans_fd), GFP_KERNEL); |
113 | 111 | ||
114 | if (!ts) | 112 | if (!ts) |
@@ -148,12 +146,12 @@ static void v9fs_fd_close(struct v9fs_transport *trans) | |||
148 | if (!trans) | 146 | if (!trans) |
149 | return; | 147 | return; |
150 | 148 | ||
151 | trans->status = Disconnected; | 149 | ts = xchg(&trans->priv, NULL); |
152 | ts = trans->priv; | ||
153 | 150 | ||
154 | if (!ts) | 151 | if (!ts) |
155 | return; | 152 | return; |
156 | 153 | ||
154 | trans->status = Disconnected; | ||
157 | if (ts->in_file) | 155 | if (ts->in_file) |
158 | fput(ts->in_file); | 156 | fput(ts->in_file); |
159 | 157 | ||
@@ -163,10 +161,55 @@ static void v9fs_fd_close(struct v9fs_transport *trans) | |||
163 | kfree(ts); | 161 | kfree(ts); |
164 | } | 162 | } |
165 | 163 | ||
164 | static unsigned int | ||
165 | v9fs_fd_poll(struct v9fs_transport *trans, struct poll_table_struct *pt) | ||
166 | { | ||
167 | int ret, n; | ||
168 | struct v9fs_trans_fd *ts; | ||
169 | mm_segment_t oldfs; | ||
170 | |||
171 | if (!trans) | ||
172 | return -EIO; | ||
173 | |||
174 | ts = trans->priv; | ||
175 | if (trans->status != Connected || !ts) | ||
176 | return -EIO; | ||
177 | |||
178 | oldfs = get_fs(); | ||
179 | set_fs(get_ds()); | ||
180 | |||
181 | if (!ts->in_file->f_op || !ts->in_file->f_op->poll) { | ||
182 | ret = -EIO; | ||
183 | goto end; | ||
184 | } | ||
185 | |||
186 | ret = ts->in_file->f_op->poll(ts->in_file, pt); | ||
187 | |||
188 | if (ts->out_file != ts->in_file) { | ||
189 | if (!ts->out_file->f_op || !ts->out_file->f_op->poll) { | ||
190 | ret = -EIO; | ||
191 | goto end; | ||
192 | } | ||
193 | |||
194 | n = ts->out_file->f_op->poll(ts->out_file, pt); | ||
195 | |||
196 | ret &= ~POLLOUT; | ||
197 | n &= ~POLLIN; | ||
198 | |||
199 | ret |= n; | ||
200 | } | ||
201 | |||
202 | end: | ||
203 | set_fs(oldfs); | ||
204 | return ret; | ||
205 | } | ||
206 | |||
207 | |||
166 | struct v9fs_transport v9fs_trans_fd = { | 208 | struct v9fs_transport v9fs_trans_fd = { |
167 | .init = v9fs_fd_init, | 209 | .init = v9fs_fd_init, |
168 | .write = v9fs_fd_send, | 210 | .write = v9fs_fd_send, |
169 | .read = v9fs_fd_recv, | 211 | .read = v9fs_fd_recv, |
170 | .close = v9fs_fd_close, | 212 | .close = v9fs_fd_close, |
213 | .poll = v9fs_fd_poll, | ||
171 | }; | 214 | }; |
172 | 215 | ||
diff --git a/fs/9p/trans_sock.c b/fs/9p/trans_sock.c index 6a9a75d40f73..44e830697acb 100644 --- a/fs/9p/trans_sock.c +++ b/fs/9p/trans_sock.c | |||
@@ -3,6 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Socket Transport Layer | 4 | * Socket Transport Layer |
5 | * | 5 | * |
6 | * Copyright (C) 2004-2005 by Latchesar Ionkov <lucho@ionkov.net> | ||
6 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> | 7 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> |
7 | * Copyright (C) 1997-2002 by Ron Minnich <rminnich@sarnoff.com> | 8 | * Copyright (C) 1997-2002 by Ron Minnich <rminnich@sarnoff.com> |
8 | * Copyright (C) 1995, 1996 by Olaf Kirch <okir@monad.swb.de> | 9 | * Copyright (C) 1995, 1996 by Olaf Kirch <okir@monad.swb.de> |
@@ -36,6 +37,7 @@ | |||
36 | #include <asm/uaccess.h> | 37 | #include <asm/uaccess.h> |
37 | #include <linux/inet.h> | 38 | #include <linux/inet.h> |
38 | #include <linux/idr.h> | 39 | #include <linux/idr.h> |
40 | #include <linux/file.h> | ||
39 | 41 | ||
40 | #include "debug.h" | 42 | #include "debug.h" |
41 | #include "v9fs.h" | 43 | #include "v9fs.h" |
@@ -45,6 +47,7 @@ | |||
45 | 47 | ||
46 | struct v9fs_trans_sock { | 48 | struct v9fs_trans_sock { |
47 | struct socket *s; | 49 | struct socket *s; |
50 | struct file *filp; | ||
48 | }; | 51 | }; |
49 | 52 | ||
50 | /** | 53 | /** |
@@ -57,41 +60,26 @@ struct v9fs_trans_sock { | |||
57 | 60 | ||
58 | static int v9fs_sock_recv(struct v9fs_transport *trans, void *v, int len) | 61 | static int v9fs_sock_recv(struct v9fs_transport *trans, void *v, int len) |
59 | { | 62 | { |
60 | struct msghdr msg; | 63 | int ret; |
61 | struct kvec iov; | 64 | struct v9fs_trans_sock *ts; |
62 | int result; | ||
63 | mm_segment_t oldfs; | ||
64 | struct v9fs_trans_sock *ts = trans ? trans->priv : NULL; | ||
65 | 65 | ||
66 | if (trans->status == Disconnected) | 66 | if (!trans || trans->status == Disconnected) { |
67 | dprintk(DEBUG_ERROR, "disconnected ...\n"); | ||
67 | return -EREMOTEIO; | 68 | return -EREMOTEIO; |
69 | } | ||
68 | 70 | ||
69 | result = -EINVAL; | 71 | ts = trans->priv; |
70 | |||
71 | oldfs = get_fs(); | ||
72 | set_fs(get_ds()); | ||
73 | |||
74 | iov.iov_base = v; | ||
75 | iov.iov_len = len; | ||
76 | msg.msg_name = NULL; | ||
77 | msg.msg_namelen = 0; | ||
78 | msg.msg_iovlen = 1; | ||
79 | msg.msg_control = NULL; | ||
80 | msg.msg_controllen = 0; | ||
81 | msg.msg_namelen = 0; | ||
82 | msg.msg_flags = MSG_NOSIGNAL; | ||
83 | 72 | ||
84 | result = kernel_recvmsg(ts->s, &msg, &iov, 1, len, 0); | 73 | if (!(ts->filp->f_flags & O_NONBLOCK)) |
74 | dprintk(DEBUG_ERROR, "blocking read ...\n"); | ||
85 | 75 | ||
86 | dprintk(DEBUG_TRANS, "socket state %d\n", ts->s->state); | 76 | ret = kernel_read(ts->filp, ts->filp->f_pos, v, len); |
87 | set_fs(oldfs); | 77 | if (ret <= 0) { |
88 | 78 | if (ret != -ERESTARTSYS && ret != -EAGAIN) | |
89 | if (result <= 0) { | ||
90 | if (result != -ERESTARTSYS) | ||
91 | trans->status = Disconnected; | 79 | trans->status = Disconnected; |
92 | } | 80 | } |
93 | 81 | ||
94 | return result; | 82 | return ret; |
95 | } | 83 | } |
96 | 84 | ||
97 | /** | 85 | /** |
@@ -104,40 +92,72 @@ static int v9fs_sock_recv(struct v9fs_transport *trans, void *v, int len) | |||
104 | 92 | ||
105 | static int v9fs_sock_send(struct v9fs_transport *trans, void *v, int len) | 93 | static int v9fs_sock_send(struct v9fs_transport *trans, void *v, int len) |
106 | { | 94 | { |
107 | struct kvec iov; | 95 | int ret; |
108 | struct msghdr msg; | ||
109 | int result = -1; | ||
110 | mm_segment_t oldfs; | 96 | mm_segment_t oldfs; |
111 | struct v9fs_trans_sock *ts = trans ? trans->priv : NULL; | 97 | struct v9fs_trans_sock *ts; |
112 | 98 | ||
113 | dprintk(DEBUG_TRANS, "Sending packet size %d (%x)\n", len, len); | 99 | if (!trans || trans->status == Disconnected) { |
114 | dump_data(v, len); | 100 | dprintk(DEBUG_ERROR, "disconnected ...\n"); |
101 | return -EREMOTEIO; | ||
102 | } | ||
103 | |||
104 | ts = trans->priv; | ||
105 | if (!ts) { | ||
106 | dprintk(DEBUG_ERROR, "no transport ...\n"); | ||
107 | return -EREMOTEIO; | ||
108 | } | ||
115 | 109 | ||
116 | down(&trans->writelock); | 110 | if (!(ts->filp->f_flags & O_NONBLOCK)) |
111 | dprintk(DEBUG_ERROR, "blocking write ...\n"); | ||
117 | 112 | ||
118 | oldfs = get_fs(); | 113 | oldfs = get_fs(); |
119 | set_fs(get_ds()); | 114 | set_fs(get_ds()); |
120 | iov.iov_base = v; | 115 | ret = vfs_write(ts->filp, (void __user *)v, len, &ts->filp->f_pos); |
121 | iov.iov_len = len; | ||
122 | msg.msg_name = NULL; | ||
123 | msg.msg_namelen = 0; | ||
124 | msg.msg_iovlen = 1; | ||
125 | msg.msg_control = NULL; | ||
126 | msg.msg_controllen = 0; | ||
127 | msg.msg_namelen = 0; | ||
128 | msg.msg_flags = MSG_NOSIGNAL; | ||
129 | result = kernel_sendmsg(ts->s, &msg, &iov, 1, len); | ||
130 | set_fs(oldfs); | 116 | set_fs(oldfs); |
131 | 117 | ||
132 | if (result < 0) { | 118 | if (ret < 0) { |
133 | if (result != -ERESTARTSYS) | 119 | if (ret != -ERESTARTSYS) |
134 | trans->status = Disconnected; | 120 | trans->status = Disconnected; |
135 | } | 121 | } |
136 | 122 | ||
137 | up(&trans->writelock); | 123 | return ret; |
138 | return result; | 124 | } |
125 | |||
126 | static unsigned int v9fs_sock_poll(struct v9fs_transport *trans, | ||
127 | struct poll_table_struct *pt) { | ||
128 | |||
129 | int ret; | ||
130 | struct v9fs_trans_sock *ts; | ||
131 | mm_segment_t oldfs; | ||
132 | |||
133 | if (!trans) { | ||
134 | dprintk(DEBUG_ERROR, "no transport\n"); | ||
135 | return -EIO; | ||
136 | } | ||
137 | |||
138 | ts = trans->priv; | ||
139 | if (trans->status != Connected || !ts) { | ||
140 | dprintk(DEBUG_ERROR, "transport disconnected: %d\n", trans->status); | ||
141 | return -EIO; | ||
142 | } | ||
143 | |||
144 | oldfs = get_fs(); | ||
145 | set_fs(get_ds()); | ||
146 | |||
147 | if (!ts->filp->f_op || !ts->filp->f_op->poll) { | ||
148 | dprintk(DEBUG_ERROR, "no poll operation\n"); | ||
149 | ret = -EIO; | ||
150 | goto end; | ||
151 | } | ||
152 | |||
153 | ret = ts->filp->f_op->poll(ts->filp, pt); | ||
154 | |||
155 | end: | ||
156 | set_fs(oldfs); | ||
157 | return ret; | ||
139 | } | 158 | } |
140 | 159 | ||
160 | |||
141 | /** | 161 | /** |
142 | * v9fs_tcp_init - initialize TCP socket | 162 | * v9fs_tcp_init - initialize TCP socket |
143 | * @v9ses: session information | 163 | * @v9ses: session information |
@@ -154,9 +174,9 @@ v9fs_tcp_init(struct v9fs_session_info *v9ses, const char *addr, char *data) | |||
154 | int rc = 0; | 174 | int rc = 0; |
155 | struct v9fs_trans_sock *ts = NULL; | 175 | struct v9fs_trans_sock *ts = NULL; |
156 | struct v9fs_transport *trans = v9ses->transport; | 176 | struct v9fs_transport *trans = v9ses->transport; |
177 | int fd; | ||
157 | 178 | ||
158 | sema_init(&trans->writelock, 1); | 179 | trans->status = Disconnected; |
159 | sema_init(&trans->readlock, 1); | ||
160 | 180 | ||
161 | ts = kmalloc(sizeof(struct v9fs_trans_sock), GFP_KERNEL); | 181 | ts = kmalloc(sizeof(struct v9fs_trans_sock), GFP_KERNEL); |
162 | 182 | ||
@@ -165,6 +185,7 @@ v9fs_tcp_init(struct v9fs_session_info *v9ses, const char *addr, char *data) | |||
165 | 185 | ||
166 | trans->priv = ts; | 186 | trans->priv = ts; |
167 | ts->s = NULL; | 187 | ts->s = NULL; |
188 | ts->filp = NULL; | ||
168 | 189 | ||
169 | if (!addr) | 190 | if (!addr) |
170 | return -EINVAL; | 191 | return -EINVAL; |
@@ -185,7 +206,18 @@ v9fs_tcp_init(struct v9fs_session_info *v9ses, const char *addr, char *data) | |||
185 | return rc; | 206 | return rc; |
186 | } | 207 | } |
187 | csocket->sk->sk_allocation = GFP_NOIO; | 208 | csocket->sk->sk_allocation = GFP_NOIO; |
209 | |||
210 | fd = sock_map_fd(csocket); | ||
211 | if (fd < 0) { | ||
212 | sock_release(csocket); | ||
213 | kfree(ts); | ||
214 | trans->priv = NULL; | ||
215 | return fd; | ||
216 | } | ||
217 | |||
188 | ts->s = csocket; | 218 | ts->s = csocket; |
219 | ts->filp = fget(fd); | ||
220 | ts->filp->f_flags |= O_NONBLOCK; | ||
189 | trans->status = Connected; | 221 | trans->status = Connected; |
190 | 222 | ||
191 | return 0; | 223 | return 0; |
@@ -203,7 +235,7 @@ static int | |||
203 | v9fs_unix_init(struct v9fs_session_info *v9ses, const char *dev_name, | 235 | v9fs_unix_init(struct v9fs_session_info *v9ses, const char *dev_name, |
204 | char *data) | 236 | char *data) |
205 | { | 237 | { |
206 | int rc; | 238 | int rc, fd; |
207 | struct socket *csocket; | 239 | struct socket *csocket; |
208 | struct sockaddr_un sun_server; | 240 | struct sockaddr_un sun_server; |
209 | struct v9fs_transport *trans; | 241 | struct v9fs_transport *trans; |
@@ -213,6 +245,8 @@ v9fs_unix_init(struct v9fs_session_info *v9ses, const char *dev_name, | |||
213 | csocket = NULL; | 245 | csocket = NULL; |
214 | trans = v9ses->transport; | 246 | trans = v9ses->transport; |
215 | 247 | ||
248 | trans->status = Disconnected; | ||
249 | |||
216 | if (strlen(dev_name) > UNIX_PATH_MAX) { | 250 | if (strlen(dev_name) > UNIX_PATH_MAX) { |
217 | eprintk(KERN_ERR, "v9fs_trans_unix: address too long: %s\n", | 251 | eprintk(KERN_ERR, "v9fs_trans_unix: address too long: %s\n", |
218 | dev_name); | 252 | dev_name); |
@@ -225,9 +259,7 @@ v9fs_unix_init(struct v9fs_session_info *v9ses, const char *dev_name, | |||
225 | 259 | ||
226 | trans->priv = ts; | 260 | trans->priv = ts; |
227 | ts->s = NULL; | 261 | ts->s = NULL; |
228 | 262 | ts->filp = NULL; | |
229 | sema_init(&trans->writelock, 1); | ||
230 | sema_init(&trans->readlock, 1); | ||
231 | 263 | ||
232 | sun_server.sun_family = PF_UNIX; | 264 | sun_server.sun_family = PF_UNIX; |
233 | strcpy(sun_server.sun_path, dev_name); | 265 | strcpy(sun_server.sun_path, dev_name); |
@@ -241,7 +273,18 @@ v9fs_unix_init(struct v9fs_session_info *v9ses, const char *dev_name, | |||
241 | return rc; | 273 | return rc; |
242 | } | 274 | } |
243 | csocket->sk->sk_allocation = GFP_NOIO; | 275 | csocket->sk->sk_allocation = GFP_NOIO; |
276 | |||
277 | fd = sock_map_fd(csocket); | ||
278 | if (fd < 0) { | ||
279 | sock_release(csocket); | ||
280 | kfree(ts); | ||
281 | trans->priv = NULL; | ||
282 | return fd; | ||
283 | } | ||
284 | |||
244 | ts->s = csocket; | 285 | ts->s = csocket; |
286 | ts->filp = fget(fd); | ||
287 | ts->filp->f_flags |= O_NONBLOCK; | ||
245 | trans->status = Connected; | 288 | trans->status = Connected; |
246 | 289 | ||
247 | return 0; | 290 | return 0; |
@@ -262,12 +305,11 @@ static void v9fs_sock_close(struct v9fs_transport *trans) | |||
262 | 305 | ||
263 | ts = trans->priv; | 306 | ts = trans->priv; |
264 | 307 | ||
265 | if ((ts) && (ts->s)) { | 308 | if ((ts) && (ts->filp)) { |
266 | dprintk(DEBUG_TRANS, "closing the socket %p\n", ts->s); | 309 | fput(ts->filp); |
267 | sock_release(ts->s); | 310 | ts->filp = NULL; |
268 | ts->s = NULL; | 311 | ts->s = NULL; |
269 | trans->status = Disconnected; | 312 | trans->status = Disconnected; |
270 | dprintk(DEBUG_TRANS, "socket closed\n"); | ||
271 | } | 313 | } |
272 | 314 | ||
273 | kfree(ts); | 315 | kfree(ts); |
@@ -280,6 +322,7 @@ struct v9fs_transport v9fs_trans_tcp = { | |||
280 | .write = v9fs_sock_send, | 322 | .write = v9fs_sock_send, |
281 | .read = v9fs_sock_recv, | 323 | .read = v9fs_sock_recv, |
282 | .close = v9fs_sock_close, | 324 | .close = v9fs_sock_close, |
325 | .poll = v9fs_sock_poll, | ||
283 | }; | 326 | }; |
284 | 327 | ||
285 | struct v9fs_transport v9fs_trans_unix = { | 328 | struct v9fs_transport v9fs_trans_unix = { |
@@ -287,4 +330,5 @@ struct v9fs_transport v9fs_trans_unix = { | |||
287 | .write = v9fs_sock_send, | 330 | .write = v9fs_sock_send, |
288 | .read = v9fs_sock_recv, | 331 | .read = v9fs_sock_recv, |
289 | .close = v9fs_sock_close, | 332 | .close = v9fs_sock_close, |
333 | .poll = v9fs_sock_poll, | ||
290 | }; | 334 | }; |
diff --git a/fs/9p/transport.h b/fs/9p/transport.h index 9e9cd418efd5..91fcdb94b361 100644 --- a/fs/9p/transport.h +++ b/fs/9p/transport.h | |||
@@ -3,6 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Transport Definition | 4 | * Transport Definition |
5 | * | 5 | * |
6 | * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net> | ||
6 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> | 7 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> |
7 | * | 8 | * |
8 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
@@ -31,14 +32,13 @@ enum v9fs_transport_status { | |||
31 | 32 | ||
32 | struct v9fs_transport { | 33 | struct v9fs_transport { |
33 | enum v9fs_transport_status status; | 34 | enum v9fs_transport_status status; |
34 | struct semaphore writelock; | ||
35 | struct semaphore readlock; | ||
36 | void *priv; | 35 | void *priv; |
37 | 36 | ||
38 | int (*init) (struct v9fs_session_info *, const char *, char *); | 37 | int (*init) (struct v9fs_session_info *, const char *, char *); |
39 | int (*write) (struct v9fs_transport *, void *, int); | 38 | int (*write) (struct v9fs_transport *, void *, int); |
40 | int (*read) (struct v9fs_transport *, void *, int); | 39 | int (*read) (struct v9fs_transport *, void *, int); |
41 | void (*close) (struct v9fs_transport *); | 40 | void (*close) (struct v9fs_transport *); |
41 | unsigned int (*poll)(struct v9fs_transport *, struct poll_table_struct *); | ||
42 | }; | 42 | }; |
43 | 43 | ||
44 | extern struct v9fs_transport v9fs_trans_tcp; | 44 | extern struct v9fs_transport v9fs_trans_tcp; |
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c index 418c3743fdee..5250c428fc1f 100644 --- a/fs/9p/v9fs.c +++ b/fs/9p/v9fs.c | |||
@@ -37,7 +37,6 @@ | |||
37 | #include "v9fs_vfs.h" | 37 | #include "v9fs_vfs.h" |
38 | #include "transport.h" | 38 | #include "transport.h" |
39 | #include "mux.h" | 39 | #include "mux.h" |
40 | #include "conv.h" | ||
41 | 40 | ||
42 | /* TODO: sysfs or debugfs interface */ | 41 | /* TODO: sysfs or debugfs interface */ |
43 | int v9fs_debug_level = 0; /* feature-rific global debug level */ | 42 | int v9fs_debug_level = 0; /* feature-rific global debug level */ |
@@ -213,7 +212,8 @@ retry: | |||
213 | return -1; | 212 | return -1; |
214 | } | 213 | } |
215 | 214 | ||
216 | error = idr_get_new(&p->pool, NULL, &i); | 215 | /* no need to store exactly p, we just need something non-null */ |
216 | error = idr_get_new(&p->pool, p, &i); | ||
217 | up(&p->lock); | 217 | up(&p->lock); |
218 | 218 | ||
219 | if (error == -EAGAIN) | 219 | if (error == -EAGAIN) |
@@ -243,6 +243,16 @@ void v9fs_put_idpool(int id, struct v9fs_idpool *p) | |||
243 | } | 243 | } |
244 | 244 | ||
245 | /** | 245 | /** |
246 | * v9fs_check_idpool - check if the specified id is available | ||
247 | * @id - id to check | ||
248 | * @p - pool | ||
249 | */ | ||
250 | int v9fs_check_idpool(int id, struct v9fs_idpool *p) | ||
251 | { | ||
252 | return idr_find(&p->pool, id) != NULL; | ||
253 | } | ||
254 | |||
255 | /** | ||
246 | * v9fs_session_init - initialize session | 256 | * v9fs_session_init - initialize session |
247 | * @v9ses: session information structure | 257 | * @v9ses: session information structure |
248 | * @dev_name: device being mounted | 258 | * @dev_name: device being mounted |
@@ -259,6 +269,7 @@ v9fs_session_init(struct v9fs_session_info *v9ses, | |||
259 | int n = 0; | 269 | int n = 0; |
260 | int newfid = -1; | 270 | int newfid = -1; |
261 | int retval = -EINVAL; | 271 | int retval = -EINVAL; |
272 | struct v9fs_str *version; | ||
262 | 273 | ||
263 | v9ses->name = __getname(); | 274 | v9ses->name = __getname(); |
264 | if (!v9ses->name) | 275 | if (!v9ses->name) |
@@ -281,9 +292,6 @@ v9fs_session_init(struct v9fs_session_info *v9ses, | |||
281 | /* id pools that are session-dependent: FIDs and TIDs */ | 292 | /* id pools that are session-dependent: FIDs and TIDs */ |
282 | idr_init(&v9ses->fidpool.pool); | 293 | idr_init(&v9ses->fidpool.pool); |
283 | init_MUTEX(&v9ses->fidpool.lock); | 294 | init_MUTEX(&v9ses->fidpool.lock); |
284 | idr_init(&v9ses->tidpool.pool); | ||
285 | init_MUTEX(&v9ses->tidpool.lock); | ||
286 | |||
287 | 295 | ||
288 | switch (v9ses->proto) { | 296 | switch (v9ses->proto) { |
289 | case PROTO_TCP: | 297 | case PROTO_TCP: |
@@ -320,7 +328,12 @@ v9fs_session_init(struct v9fs_session_info *v9ses, | |||
320 | v9ses->shutdown = 0; | 328 | v9ses->shutdown = 0; |
321 | v9ses->session_hung = 0; | 329 | v9ses->session_hung = 0; |
322 | 330 | ||
323 | if ((retval = v9fs_mux_init(v9ses, dev_name)) < 0) { | 331 | v9ses->mux = v9fs_mux_init(v9ses->transport, v9ses->maxdata + V9FS_IOHDRSZ, |
332 | &v9ses->extended); | ||
333 | |||
334 | if (IS_ERR(v9ses->mux)) { | ||
335 | retval = PTR_ERR(v9ses->mux); | ||
336 | v9ses->mux = NULL; | ||
324 | dprintk(DEBUG_ERROR, "problem initializing mux\n"); | 337 | dprintk(DEBUG_ERROR, "problem initializing mux\n"); |
325 | goto SessCleanUp; | 338 | goto SessCleanUp; |
326 | } | 339 | } |
@@ -339,13 +352,16 @@ v9fs_session_init(struct v9fs_session_info *v9ses, | |||
339 | goto FreeFcall; | 352 | goto FreeFcall; |
340 | } | 353 | } |
341 | 354 | ||
342 | /* Really should check for 9P1 and report error */ | 355 | version = &fcall->params.rversion.version; |
343 | if (!strcmp(fcall->params.rversion.version, "9P2000.u")) { | 356 | if (version->len==8 && !memcmp(version->str, "9P2000.u", 8)) { |
344 | dprintk(DEBUG_9P, "9P2000 UNIX extensions enabled\n"); | 357 | dprintk(DEBUG_9P, "9P2000 UNIX extensions enabled\n"); |
345 | v9ses->extended = 1; | 358 | v9ses->extended = 1; |
346 | } else { | 359 | } else if (version->len==6 && !memcmp(version->str, "9P2000", 6)) { |
347 | dprintk(DEBUG_9P, "9P2000 legacy mode enabled\n"); | 360 | dprintk(DEBUG_9P, "9P2000 legacy mode enabled\n"); |
348 | v9ses->extended = 0; | 361 | v9ses->extended = 0; |
362 | } else { | ||
363 | retval = -EREMOTEIO; | ||
364 | goto FreeFcall; | ||
349 | } | 365 | } |
350 | 366 | ||
351 | n = fcall->params.rversion.msize; | 367 | n = fcall->params.rversion.msize; |
@@ -381,7 +397,7 @@ v9fs_session_init(struct v9fs_session_info *v9ses, | |||
381 | } | 397 | } |
382 | 398 | ||
383 | if (v9ses->afid != ~0) { | 399 | if (v9ses->afid != ~0) { |
384 | if (v9fs_t_clunk(v9ses, v9ses->afid, NULL)) | 400 | if (v9fs_t_clunk(v9ses, v9ses->afid)) |
385 | dprintk(DEBUG_ERROR, "clunk failed\n"); | 401 | dprintk(DEBUG_ERROR, "clunk failed\n"); |
386 | } | 402 | } |
387 | 403 | ||
@@ -403,13 +419,16 @@ v9fs_session_init(struct v9fs_session_info *v9ses, | |||
403 | 419 | ||
404 | void v9fs_session_close(struct v9fs_session_info *v9ses) | 420 | void v9fs_session_close(struct v9fs_session_info *v9ses) |
405 | { | 421 | { |
406 | if (v9ses->recvproc) { | 422 | if (v9ses->mux) { |
407 | send_sig(SIGKILL, v9ses->recvproc, 1); | 423 | v9fs_mux_destroy(v9ses->mux); |
408 | wait_for_completion(&v9ses->proccmpl); | 424 | v9ses->mux = NULL; |
409 | } | 425 | } |
410 | 426 | ||
411 | if (v9ses->transport) | 427 | if (v9ses->transport) { |
412 | v9ses->transport->close(v9ses->transport); | 428 | v9ses->transport->close(v9ses->transport); |
429 | kfree(v9ses->transport); | ||
430 | v9ses->transport = NULL; | ||
431 | } | ||
413 | 432 | ||
414 | __putname(v9ses->name); | 433 | __putname(v9ses->name); |
415 | __putname(v9ses->remotename); | 434 | __putname(v9ses->remotename); |
@@ -420,8 +439,9 @@ void v9fs_session_close(struct v9fs_session_info *v9ses) | |||
420 | * and cancel all pending requests. | 439 | * and cancel all pending requests. |
421 | */ | 440 | */ |
422 | void v9fs_session_cancel(struct v9fs_session_info *v9ses) { | 441 | void v9fs_session_cancel(struct v9fs_session_info *v9ses) { |
442 | dprintk(DEBUG_ERROR, "cancel session %p\n", v9ses); | ||
423 | v9ses->transport->status = Disconnected; | 443 | v9ses->transport->status = Disconnected; |
424 | v9fs_mux_cancel_requests(v9ses, -EIO); | 444 | v9fs_mux_cancel(v9ses->mux, -EIO); |
425 | } | 445 | } |
426 | 446 | ||
427 | extern int v9fs_error_init(void); | 447 | extern int v9fs_error_init(void); |
@@ -433,11 +453,17 @@ extern int v9fs_error_init(void); | |||
433 | 453 | ||
434 | static int __init init_v9fs(void) | 454 | static int __init init_v9fs(void) |
435 | { | 455 | { |
456 | int ret; | ||
457 | |||
436 | v9fs_error_init(); | 458 | v9fs_error_init(); |
437 | 459 | ||
438 | printk(KERN_INFO "Installing v9fs 9P2000 file system support\n"); | 460 | printk(KERN_INFO "Installing v9fs 9P2000 file system support\n"); |
439 | 461 | ||
440 | return register_filesystem(&v9fs_fs_type); | 462 | ret = v9fs_mux_global_init(); |
463 | if (!ret) | ||
464 | ret = register_filesystem(&v9fs_fs_type); | ||
465 | |||
466 | return ret; | ||
441 | } | 467 | } |
442 | 468 | ||
443 | /** | 469 | /** |
@@ -447,6 +473,7 @@ static int __init init_v9fs(void) | |||
447 | 473 | ||
448 | static void __exit exit_v9fs(void) | 474 | static void __exit exit_v9fs(void) |
449 | { | 475 | { |
476 | v9fs_mux_global_exit(); | ||
450 | unregister_filesystem(&v9fs_fs_type); | 477 | unregister_filesystem(&v9fs_fs_type); |
451 | } | 478 | } |
452 | 479 | ||
diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h index 45dcef42bdd6..f337da7a0eec 100644 --- a/fs/9p/v9fs.h +++ b/fs/9p/v9fs.h | |||
@@ -57,24 +57,14 @@ struct v9fs_session_info { | |||
57 | 57 | ||
58 | /* book keeping */ | 58 | /* book keeping */ |
59 | struct v9fs_idpool fidpool; /* The FID pool for file descriptors */ | 59 | struct v9fs_idpool fidpool; /* The FID pool for file descriptors */ |
60 | struct v9fs_idpool tidpool; /* The TID pool for transactions ids */ | ||
61 | 60 | ||
62 | /* transport information */ | ||
63 | struct v9fs_transport *transport; | 61 | struct v9fs_transport *transport; |
62 | struct v9fs_mux_data *mux; | ||
64 | 63 | ||
65 | int inprogress; /* session in progress => true */ | 64 | int inprogress; /* session in progress => true */ |
66 | int shutdown; /* session shutting down. no more attaches. */ | 65 | int shutdown; /* session shutting down. no more attaches. */ |
67 | unsigned char session_hung; | 66 | unsigned char session_hung; |
68 | 67 | struct dentry *debugfs_dir; | |
69 | /* mux private data */ | ||
70 | struct v9fs_fcall *curfcall; | ||
71 | wait_queue_head_t read_wait; | ||
72 | struct completion fcread; | ||
73 | struct completion proccmpl; | ||
74 | struct task_struct *recvproc; | ||
75 | |||
76 | spinlock_t muxlock; | ||
77 | struct list_head mux_fcalls; | ||
78 | }; | 68 | }; |
79 | 69 | ||
80 | /* possible values of ->proto */ | 70 | /* possible values of ->proto */ |
@@ -84,11 +74,14 @@ enum { | |||
84 | PROTO_FD, | 74 | PROTO_FD, |
85 | }; | 75 | }; |
86 | 76 | ||
77 | extern struct dentry *v9fs_debugfs_root; | ||
78 | |||
87 | int v9fs_session_init(struct v9fs_session_info *, const char *, char *); | 79 | int v9fs_session_init(struct v9fs_session_info *, const char *, char *); |
88 | struct v9fs_session_info *v9fs_inode2v9ses(struct inode *); | 80 | struct v9fs_session_info *v9fs_inode2v9ses(struct inode *); |
89 | void v9fs_session_close(struct v9fs_session_info *v9ses); | 81 | void v9fs_session_close(struct v9fs_session_info *v9ses); |
90 | int v9fs_get_idpool(struct v9fs_idpool *p); | 82 | int v9fs_get_idpool(struct v9fs_idpool *p); |
91 | void v9fs_put_idpool(int id, struct v9fs_idpool *p); | 83 | void v9fs_put_idpool(int id, struct v9fs_idpool *p); |
84 | int v9fs_check_idpool(int id, struct v9fs_idpool *p); | ||
92 | void v9fs_session_cancel(struct v9fs_session_info *v9ses); | 85 | void v9fs_session_cancel(struct v9fs_session_info *v9ses); |
93 | 86 | ||
94 | #define V9FS_MAGIC 0x01021997 | 87 | #define V9FS_MAGIC 0x01021997 |
diff --git a/fs/9p/v9fs_vfs.h b/fs/9p/v9fs_vfs.h index 2f2cea7ee3e7..c78502ad00ed 100644 --- a/fs/9p/v9fs_vfs.h +++ b/fs/9p/v9fs_vfs.h | |||
@@ -45,9 +45,8 @@ extern struct dentry_operations v9fs_dentry_operations; | |||
45 | 45 | ||
46 | struct inode *v9fs_get_inode(struct super_block *sb, int mode); | 46 | struct inode *v9fs_get_inode(struct super_block *sb, int mode); |
47 | ino_t v9fs_qid2ino(struct v9fs_qid *qid); | 47 | ino_t v9fs_qid2ino(struct v9fs_qid *qid); |
48 | void v9fs_mistat2inode(struct v9fs_stat *, struct inode *, | 48 | void v9fs_stat2inode(struct v9fs_stat *, struct inode *, struct super_block *); |
49 | struct super_block *); | ||
50 | int v9fs_dir_release(struct inode *inode, struct file *filp); | 49 | int v9fs_dir_release(struct inode *inode, struct file *filp); |
51 | int v9fs_file_open(struct inode *inode, struct file *file); | 50 | int v9fs_file_open(struct inode *inode, struct file *file); |
52 | void v9fs_inode2mistat(struct inode *inode, struct v9fs_stat *mistat); | 51 | void v9fs_inode2stat(struct inode *inode, struct v9fs_stat *stat); |
53 | void v9fs_dentry_release(struct dentry *); | 52 | void v9fs_dentry_release(struct dentry *); |
diff --git a/fs/9p/vfs_dentry.c b/fs/9p/vfs_dentry.c index a6aa947de0f9..2dd806dac9f1 100644 --- a/fs/9p/vfs_dentry.c +++ b/fs/9p/vfs_dentry.c | |||
@@ -40,7 +40,6 @@ | |||
40 | #include "v9fs.h" | 40 | #include "v9fs.h" |
41 | #include "9p.h" | 41 | #include "9p.h" |
42 | #include "v9fs_vfs.h" | 42 | #include "v9fs_vfs.h" |
43 | #include "conv.h" | ||
44 | #include "fid.h" | 43 | #include "fid.h" |
45 | 44 | ||
46 | /** | 45 | /** |
@@ -95,24 +94,22 @@ static int v9fs_dentry_validate(struct dentry *dentry, struct nameidata *nd) | |||
95 | 94 | ||
96 | void v9fs_dentry_release(struct dentry *dentry) | 95 | void v9fs_dentry_release(struct dentry *dentry) |
97 | { | 96 | { |
97 | int err; | ||
98 | |||
98 | dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry); | 99 | dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry); |
99 | 100 | ||
100 | if (dentry->d_fsdata != NULL) { | 101 | if (dentry->d_fsdata != NULL) { |
101 | struct list_head *fid_list = dentry->d_fsdata; | 102 | struct list_head *fid_list = dentry->d_fsdata; |
102 | struct v9fs_fid *temp = NULL; | 103 | struct v9fs_fid *temp = NULL; |
103 | struct v9fs_fid *current_fid = NULL; | 104 | struct v9fs_fid *current_fid = NULL; |
104 | struct v9fs_fcall *fcall = NULL; | ||
105 | 105 | ||
106 | list_for_each_entry_safe(current_fid, temp, fid_list, list) { | 106 | list_for_each_entry_safe(current_fid, temp, fid_list, list) { |
107 | if (v9fs_t_clunk | 107 | err = v9fs_t_clunk(current_fid->v9ses, current_fid->fid); |
108 | (current_fid->v9ses, current_fid->fid, &fcall)) | ||
109 | dprintk(DEBUG_ERROR, "clunk failed: %s\n", | ||
110 | FCALL_ERROR(fcall)); | ||
111 | 108 | ||
112 | v9fs_put_idpool(current_fid->fid, | 109 | if (err < 0) |
113 | ¤t_fid->v9ses->fidpool); | 110 | dprintk(DEBUG_ERROR, "clunk failed: %d name %s\n", |
111 | err, dentry->d_iname); | ||
114 | 112 | ||
115 | kfree(fcall); | ||
116 | v9fs_fid_destroy(current_fid); | 113 | v9fs_fid_destroy(current_fid); |
117 | } | 114 | } |
118 | 115 | ||
diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c index 57a43b8feef5..ae6d032b9b59 100644 --- a/fs/9p/vfs_dir.c +++ b/fs/9p/vfs_dir.c | |||
@@ -37,8 +37,8 @@ | |||
37 | #include "debug.h" | 37 | #include "debug.h" |
38 | #include "v9fs.h" | 38 | #include "v9fs.h" |
39 | #include "9p.h" | 39 | #include "9p.h" |
40 | #include "v9fs_vfs.h" | ||
41 | #include "conv.h" | 40 | #include "conv.h" |
41 | #include "v9fs_vfs.h" | ||
42 | #include "fid.h" | 42 | #include "fid.h" |
43 | 43 | ||
44 | /** | 44 | /** |
@@ -74,20 +74,16 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
74 | struct inode *inode = filp->f_dentry->d_inode; | 74 | struct inode *inode = filp->f_dentry->d_inode; |
75 | struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); | 75 | struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); |
76 | struct v9fs_fid *file = filp->private_data; | 76 | struct v9fs_fid *file = filp->private_data; |
77 | unsigned int i, n; | 77 | unsigned int i, n, s; |
78 | int fid = -1; | 78 | int fid = -1; |
79 | int ret = 0; | 79 | int ret = 0; |
80 | struct v9fs_stat *mi = NULL; | 80 | struct v9fs_stat stat; |
81 | int over = 0; | 81 | int over = 0; |
82 | 82 | ||
83 | dprintk(DEBUG_VFS, "name %s\n", filp->f_dentry->d_name.name); | 83 | dprintk(DEBUG_VFS, "name %s\n", filp->f_dentry->d_name.name); |
84 | 84 | ||
85 | fid = file->fid; | 85 | fid = file->fid; |
86 | 86 | ||
87 | mi = kmalloc(v9ses->maxdata, GFP_KERNEL); | ||
88 | if (!mi) | ||
89 | return -ENOMEM; | ||
90 | |||
91 | if (file->rdir_fcall && (filp->f_pos != file->rdir_pos)) { | 87 | if (file->rdir_fcall && (filp->f_pos != file->rdir_pos)) { |
92 | kfree(file->rdir_fcall); | 88 | kfree(file->rdir_fcall); |
93 | file->rdir_fcall = NULL; | 89 | file->rdir_fcall = NULL; |
@@ -97,20 +93,20 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
97 | n = file->rdir_fcall->params.rread.count; | 93 | n = file->rdir_fcall->params.rread.count; |
98 | i = file->rdir_fpos; | 94 | i = file->rdir_fpos; |
99 | while (i < n) { | 95 | while (i < n) { |
100 | int s = v9fs_deserialize_stat(v9ses, | 96 | s = v9fs_deserialize_stat( |
101 | file->rdir_fcall->params.rread.data + i, | 97 | file->rdir_fcall->params.rread.data + i, |
102 | n - i, mi, v9ses->maxdata); | 98 | n - i, &stat, v9ses->extended); |
103 | 99 | ||
104 | if (s == 0) { | 100 | if (s == 0) { |
105 | dprintk(DEBUG_ERROR, | 101 | dprintk(DEBUG_ERROR, |
106 | "error while deserializing mistat\n"); | 102 | "error while deserializing stat\n"); |
107 | ret = -EIO; | 103 | ret = -EIO; |
108 | goto FreeStructs; | 104 | goto FreeStructs; |
109 | } | 105 | } |
110 | 106 | ||
111 | over = filldir(dirent, mi->name, strlen(mi->name), | 107 | over = filldir(dirent, stat.name.str, stat.name.len, |
112 | filp->f_pos, v9fs_qid2ino(&mi->qid), | 108 | filp->f_pos, v9fs_qid2ino(&stat.qid), |
113 | dt_type(mi)); | 109 | dt_type(&stat)); |
114 | 110 | ||
115 | if (over) { | 111 | if (over) { |
116 | file->rdir_fpos = i; | 112 | file->rdir_fpos = i; |
@@ -130,7 +126,7 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
130 | 126 | ||
131 | while (!over) { | 127 | while (!over) { |
132 | ret = v9fs_t_read(v9ses, fid, filp->f_pos, | 128 | ret = v9fs_t_read(v9ses, fid, filp->f_pos, |
133 | v9ses->maxdata-V9FS_IOHDRSZ, &fcall); | 129 | v9ses->maxdata-V9FS_IOHDRSZ, &fcall); |
134 | if (ret < 0) { | 130 | if (ret < 0) { |
135 | dprintk(DEBUG_ERROR, "error while reading: %d: %p\n", | 131 | dprintk(DEBUG_ERROR, "error while reading: %d: %p\n", |
136 | ret, fcall); | 132 | ret, fcall); |
@@ -141,19 +137,18 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
141 | n = ret; | 137 | n = ret; |
142 | i = 0; | 138 | i = 0; |
143 | while (i < n) { | 139 | while (i < n) { |
144 | int s = v9fs_deserialize_stat(v9ses, | 140 | s = v9fs_deserialize_stat(fcall->params.rread.data + i, |
145 | fcall->params.rread.data + i, n - i, mi, | 141 | n - i, &stat, v9ses->extended); |
146 | v9ses->maxdata); | ||
147 | 142 | ||
148 | if (s == 0) { | 143 | if (s == 0) { |
149 | dprintk(DEBUG_ERROR, | 144 | dprintk(DEBUG_ERROR, |
150 | "error while deserializing mistat\n"); | 145 | "error while deserializing stat\n"); |
151 | return -EIO; | 146 | return -EIO; |
152 | } | 147 | } |
153 | 148 | ||
154 | over = filldir(dirent, mi->name, strlen(mi->name), | 149 | over = filldir(dirent, stat.name.str, stat.name.len, |
155 | filp->f_pos, v9fs_qid2ino(&mi->qid), | 150 | filp->f_pos, v9fs_qid2ino(&stat.qid), |
156 | dt_type(mi)); | 151 | dt_type(&stat)); |
157 | 152 | ||
158 | if (over) { | 153 | if (over) { |
159 | file->rdir_fcall = fcall; | 154 | file->rdir_fcall = fcall; |
@@ -172,7 +167,6 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
172 | 167 | ||
173 | FreeStructs: | 168 | FreeStructs: |
174 | kfree(fcall); | 169 | kfree(fcall); |
175 | kfree(mi); | ||
176 | return ret; | 170 | return ret; |
177 | } | 171 | } |
178 | 172 | ||
@@ -193,18 +187,15 @@ int v9fs_dir_release(struct inode *inode, struct file *filp) | |||
193 | fid->fid); | 187 | fid->fid); |
194 | fidnum = fid->fid; | 188 | fidnum = fid->fid; |
195 | 189 | ||
196 | filemap_fdatawrite(inode->i_mapping); | 190 | filemap_write_and_wait(inode->i_mapping); |
197 | filemap_fdatawait(inode->i_mapping); | ||
198 | 191 | ||
199 | if (fidnum >= 0) { | 192 | if (fidnum >= 0) { |
200 | dprintk(DEBUG_VFS, "fidopen: %d v9f->fid: %d\n", fid->fidopen, | 193 | dprintk(DEBUG_VFS, "fidopen: %d v9f->fid: %d\n", fid->fidopen, |
201 | fid->fid); | 194 | fid->fid); |
202 | 195 | ||
203 | if (v9fs_t_clunk(v9ses, fidnum, NULL)) | 196 | if (v9fs_t_clunk(v9ses, fidnum)) |
204 | dprintk(DEBUG_ERROR, "clunk failed\n"); | 197 | dprintk(DEBUG_ERROR, "clunk failed\n"); |
205 | 198 | ||
206 | v9fs_put_idpool(fid->fid, &v9ses->fidpool); | ||
207 | |||
208 | kfree(fid->rdir_fcall); | 199 | kfree(fid->rdir_fcall); |
209 | kfree(fid); | 200 | kfree(fid); |
210 | 201 | ||
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index 89c849da8504..6852f0eb96ed 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/string.h> | 32 | #include <linux/string.h> |
33 | #include <linux/smp_lock.h> | 33 | #include <linux/smp_lock.h> |
34 | #include <linux/inet.h> | 34 | #include <linux/inet.h> |
35 | #include <linux/version.h> | ||
35 | #include <linux/list.h> | 36 | #include <linux/list.h> |
36 | #include <asm/uaccess.h> | 37 | #include <asm/uaccess.h> |
37 | #include <linux/idr.h> | 38 | #include <linux/idr.h> |
@@ -117,9 +118,7 @@ int v9fs_file_open(struct inode *inode, struct file *file) | |||
117 | 118 | ||
118 | result = v9fs_t_open(v9ses, newfid, open_mode, &fcall); | 119 | result = v9fs_t_open(v9ses, newfid, open_mode, &fcall); |
119 | if (result < 0) { | 120 | if (result < 0) { |
120 | dprintk(DEBUG_ERROR, | 121 | PRINT_FCALL_ERROR("open failed", fcall); |
121 | "open failed, open_mode 0x%x: %s\n", open_mode, | ||
122 | FCALL_ERROR(fcall)); | ||
123 | kfree(fcall); | 122 | kfree(fcall); |
124 | return result; | 123 | return result; |
125 | } | 124 | } |
@@ -165,8 +164,7 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl) | |||
165 | return -ENOLCK; | 164 | return -ENOLCK; |
166 | 165 | ||
167 | if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) { | 166 | if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) { |
168 | filemap_fdatawrite(inode->i_mapping); | 167 | filemap_write_and_wait(inode->i_mapping); |
169 | filemap_fdatawait(inode->i_mapping); | ||
170 | invalidate_inode_pages(&inode->i_data); | 168 | invalidate_inode_pages(&inode->i_data); |
171 | } | 169 | } |
172 | 170 | ||
@@ -257,7 +255,6 @@ v9fs_file_write(struct file *filp, const char __user * data, | |||
257 | int result = -EIO; | 255 | int result = -EIO; |
258 | int rsize = 0; | 256 | int rsize = 0; |
259 | int total = 0; | 257 | int total = 0; |
260 | char *buf; | ||
261 | 258 | ||
262 | dprintk(DEBUG_VFS, "data %p count %d offset %x\n", data, (int)count, | 259 | dprintk(DEBUG_VFS, "data %p count %d offset %x\n", data, (int)count, |
263 | (int)*offset); | 260 | (int)*offset); |
@@ -265,28 +262,14 @@ v9fs_file_write(struct file *filp, const char __user * data, | |||
265 | if (v9fid->iounit != 0 && rsize > v9fid->iounit) | 262 | if (v9fid->iounit != 0 && rsize > v9fid->iounit) |
266 | rsize = v9fid->iounit; | 263 | rsize = v9fid->iounit; |
267 | 264 | ||
268 | buf = kmalloc(v9ses->maxdata - V9FS_IOHDRSZ, GFP_KERNEL); | ||
269 | if (!buf) | ||
270 | return -ENOMEM; | ||
271 | |||
272 | do { | 265 | do { |
273 | if (count < rsize) | 266 | if (count < rsize) |
274 | rsize = count; | 267 | rsize = count; |
275 | 268 | ||
276 | result = copy_from_user(buf, data, rsize); | 269 | result = v9fs_t_write(v9ses, fid, *offset, rsize, data, &fcall); |
277 | if (result) { | ||
278 | dprintk(DEBUG_ERROR, "Problem copying from user\n"); | ||
279 | kfree(buf); | ||
280 | return -EFAULT; | ||
281 | } | ||
282 | |||
283 | dump_data(buf, rsize); | ||
284 | result = v9fs_t_write(v9ses, fid, *offset, rsize, buf, &fcall); | ||
285 | if (result < 0) { | 270 | if (result < 0) { |
286 | eprintk(KERN_ERR, "error while writing: %s(%d)\n", | 271 | PRINT_FCALL_ERROR("error while writing", fcall); |
287 | FCALL_ERROR(fcall), result); | ||
288 | kfree(fcall); | 272 | kfree(fcall); |
289 | kfree(buf); | ||
290 | return result; | 273 | return result; |
291 | } else | 274 | } else |
292 | *offset += result; | 275 | *offset += result; |
@@ -306,7 +289,6 @@ v9fs_file_write(struct file *filp, const char __user * data, | |||
306 | total += result; | 289 | total += result; |
307 | } while (count); | 290 | } while (count); |
308 | 291 | ||
309 | kfree(buf); | ||
310 | return total; | 292 | return total; |
311 | } | 293 | } |
312 | 294 | ||
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 0ea965c3bb7d..d933ef1fbd8a 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c | |||
@@ -40,7 +40,6 @@ | |||
40 | #include "v9fs.h" | 40 | #include "v9fs.h" |
41 | #include "9p.h" | 41 | #include "9p.h" |
42 | #include "v9fs_vfs.h" | 42 | #include "v9fs_vfs.h" |
43 | #include "conv.h" | ||
44 | #include "fid.h" | 43 | #include "fid.h" |
45 | 44 | ||
46 | static struct inode_operations v9fs_dir_inode_operations; | 45 | static struct inode_operations v9fs_dir_inode_operations; |
@@ -127,100 +126,32 @@ static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode) | |||
127 | } | 126 | } |
128 | 127 | ||
129 | /** | 128 | /** |
130 | * v9fs_blank_mistat - helper function to setup a 9P stat structure | 129 | * v9fs_blank_wstat - helper function to setup a 9P stat structure |
131 | * @v9ses: 9P session info (for determining extended mode) | 130 | * @v9ses: 9P session info (for determining extended mode) |
132 | * @mistat: structure to initialize | 131 | * @wstat: structure to initialize |
133 | * | 132 | * |
134 | */ | 133 | */ |
135 | 134 | ||
136 | static void | 135 | static void |
137 | v9fs_blank_mistat(struct v9fs_session_info *v9ses, struct v9fs_stat *mistat) | 136 | v9fs_blank_wstat(struct v9fs_wstat *wstat) |
138 | { | 137 | { |
139 | mistat->type = ~0; | 138 | wstat->type = ~0; |
140 | mistat->dev = ~0; | 139 | wstat->dev = ~0; |
141 | mistat->qid.type = ~0; | 140 | wstat->qid.type = ~0; |
142 | mistat->qid.version = ~0; | 141 | wstat->qid.version = ~0; |
143 | *((long long *)&mistat->qid.path) = ~0; | 142 | *((long long *)&wstat->qid.path) = ~0; |
144 | mistat->mode = ~0; | 143 | wstat->mode = ~0; |
145 | mistat->atime = ~0; | 144 | wstat->atime = ~0; |
146 | mistat->mtime = ~0; | 145 | wstat->mtime = ~0; |
147 | mistat->length = ~0; | 146 | wstat->length = ~0; |
148 | mistat->name = mistat->data; | 147 | wstat->name = NULL; |
149 | mistat->uid = mistat->data; | 148 | wstat->uid = NULL; |
150 | mistat->gid = mistat->data; | 149 | wstat->gid = NULL; |
151 | mistat->muid = mistat->data; | 150 | wstat->muid = NULL; |
152 | if (v9ses->extended) { | 151 | wstat->n_uid = ~0; |
153 | mistat->n_uid = ~0; | 152 | wstat->n_gid = ~0; |
154 | mistat->n_gid = ~0; | 153 | wstat->n_muid = ~0; |
155 | mistat->n_muid = ~0; | 154 | wstat->extension = NULL; |
156 | mistat->extension = mistat->data; | ||
157 | } | ||
158 | *mistat->data = 0; | ||
159 | } | ||
160 | |||
161 | /** | ||
162 | * v9fs_mistat2unix - convert mistat to unix stat | ||
163 | * @mistat: Plan 9 metadata (mistat) structure | ||
164 | * @buf: unix metadata (stat) structure to populate | ||
165 | * @sb: superblock | ||
166 | * | ||
167 | */ | ||
168 | |||
169 | static void | ||
170 | v9fs_mistat2unix(struct v9fs_stat *mistat, struct stat *buf, | ||
171 | struct super_block *sb) | ||
172 | { | ||
173 | struct v9fs_session_info *v9ses = sb ? sb->s_fs_info : NULL; | ||
174 | |||
175 | buf->st_nlink = 1; | ||
176 | |||
177 | buf->st_atime = mistat->atime; | ||
178 | buf->st_mtime = mistat->mtime; | ||
179 | buf->st_ctime = mistat->mtime; | ||
180 | |||
181 | buf->st_uid = (unsigned short)-1; | ||
182 | buf->st_gid = (unsigned short)-1; | ||
183 | |||
184 | if (v9ses && v9ses->extended) { | ||
185 | /* TODO: string to uid mapping via user-space daemon */ | ||
186 | if (mistat->n_uid != -1) | ||
187 | sscanf(mistat->uid, "%x", (unsigned int *)&buf->st_uid); | ||
188 | |||
189 | if (mistat->n_gid != -1) | ||
190 | sscanf(mistat->gid, "%x", (unsigned int *)&buf->st_gid); | ||
191 | } | ||
192 | |||
193 | if (buf->st_uid == (unsigned short)-1) | ||
194 | buf->st_uid = v9ses->uid; | ||
195 | if (buf->st_gid == (unsigned short)-1) | ||
196 | buf->st_gid = v9ses->gid; | ||
197 | |||
198 | buf->st_mode = p9mode2unixmode(v9ses, mistat->mode); | ||
199 | if ((S_ISBLK(buf->st_mode)) || (S_ISCHR(buf->st_mode))) { | ||
200 | char type = 0; | ||
201 | int major = -1; | ||
202 | int minor = -1; | ||
203 | sscanf(mistat->extension, "%c %u %u", &type, &major, &minor); | ||
204 | switch (type) { | ||
205 | case 'c': | ||
206 | buf->st_mode &= ~S_IFBLK; | ||
207 | buf->st_mode |= S_IFCHR; | ||
208 | break; | ||
209 | case 'b': | ||
210 | break; | ||
211 | default: | ||
212 | dprintk(DEBUG_ERROR, "Unknown special type %c (%s)\n", | ||
213 | type, mistat->extension); | ||
214 | }; | ||
215 | buf->st_rdev = MKDEV(major, minor); | ||
216 | } else | ||
217 | buf->st_rdev = 0; | ||
218 | |||
219 | buf->st_size = mistat->length; | ||
220 | |||
221 | buf->st_blksize = sb->s_blocksize; | ||
222 | buf->st_blocks = | ||
223 | (buf->st_size + buf->st_blksize - 1) >> sb->s_blocksize_bits; | ||
224 | } | 155 | } |
225 | 156 | ||
226 | /** | 157 | /** |
@@ -312,12 +243,12 @@ v9fs_create(struct inode *dir, | |||
312 | struct inode *file_inode = NULL; | 243 | struct inode *file_inode = NULL; |
313 | struct v9fs_fcall *fcall = NULL; | 244 | struct v9fs_fcall *fcall = NULL; |
314 | struct v9fs_qid qid; | 245 | struct v9fs_qid qid; |
315 | struct stat newstat; | ||
316 | int dirfidnum = -1; | 246 | int dirfidnum = -1; |
317 | long newfid = -1; | 247 | long newfid = -1; |
318 | int result = 0; | 248 | int result = 0; |
319 | unsigned int iounit = 0; | 249 | unsigned int iounit = 0; |
320 | int wfidno = -1; | 250 | int wfidno = -1; |
251 | int err; | ||
321 | 252 | ||
322 | perm = unixmode2p9mode(v9ses, perm); | 253 | perm = unixmode2p9mode(v9ses, perm); |
323 | 254 | ||
@@ -349,57 +280,64 @@ v9fs_create(struct inode *dir, | |||
349 | 280 | ||
350 | result = v9fs_t_walk(v9ses, dirfidnum, newfid, NULL, &fcall); | 281 | result = v9fs_t_walk(v9ses, dirfidnum, newfid, NULL, &fcall); |
351 | if (result < 0) { | 282 | if (result < 0) { |
352 | dprintk(DEBUG_ERROR, "clone error: %s\n", FCALL_ERROR(fcall)); | 283 | PRINT_FCALL_ERROR("clone error", fcall); |
353 | v9fs_put_idpool(newfid, &v9ses->fidpool); | 284 | v9fs_put_idpool(newfid, &v9ses->fidpool); |
354 | newfid = -1; | 285 | newfid = -1; |
355 | goto CleanUpFid; | 286 | goto CleanUpFid; |
356 | } | 287 | } |
357 | 288 | ||
358 | kfree(fcall); | 289 | kfree(fcall); |
290 | fcall = NULL; | ||
359 | 291 | ||
360 | result = v9fs_t_create(v9ses, newfid, (char *)file_dentry->d_name.name, | 292 | result = v9fs_t_create(v9ses, newfid, (char *)file_dentry->d_name.name, |
361 | perm, open_mode, &fcall); | 293 | perm, open_mode, &fcall); |
362 | if (result < 0) { | 294 | if (result < 0) { |
363 | dprintk(DEBUG_ERROR, "create fails: %s(%d)\n", | 295 | PRINT_FCALL_ERROR("create fails", fcall); |
364 | FCALL_ERROR(fcall), result); | ||
365 | |||
366 | goto CleanUpFid; | 296 | goto CleanUpFid; |
367 | } | 297 | } |
368 | 298 | ||
369 | iounit = fcall->params.rcreate.iounit; | 299 | iounit = fcall->params.rcreate.iounit; |
370 | qid = fcall->params.rcreate.qid; | 300 | qid = fcall->params.rcreate.qid; |
371 | kfree(fcall); | 301 | kfree(fcall); |
302 | fcall = NULL; | ||
372 | 303 | ||
373 | fid = v9fs_fid_create(file_dentry, v9ses, newfid, 1); | 304 | if (!(perm&V9FS_DMDIR)) { |
374 | dprintk(DEBUG_VFS, "fid %p %d\n", fid, fid->fidcreate); | 305 | fid = v9fs_fid_create(file_dentry, v9ses, newfid, 1); |
375 | if (!fid) { | 306 | dprintk(DEBUG_VFS, "fid %p %d\n", fid, fid->fidcreate); |
376 | result = -ENOMEM; | 307 | if (!fid) { |
377 | goto CleanUpFid; | 308 | result = -ENOMEM; |
378 | } | 309 | goto CleanUpFid; |
310 | } | ||
379 | 311 | ||
380 | fid->qid = qid; | 312 | fid->qid = qid; |
381 | fid->iounit = iounit; | 313 | fid->iounit = iounit; |
314 | } else { | ||
315 | err = v9fs_t_clunk(v9ses, newfid); | ||
316 | newfid = -1; | ||
317 | if (err < 0) | ||
318 | dprintk(DEBUG_ERROR, "clunk for mkdir failed: %d\n", err); | ||
319 | } | ||
382 | 320 | ||
383 | /* walk to the newly created file and put the fid in the dentry */ | 321 | /* walk to the newly created file and put the fid in the dentry */ |
384 | wfidno = v9fs_get_idpool(&v9ses->fidpool); | 322 | wfidno = v9fs_get_idpool(&v9ses->fidpool); |
385 | if (newfid < 0) { | 323 | if (wfidno < 0) { |
386 | eprintk(KERN_WARNING, "no free fids available\n"); | 324 | eprintk(KERN_WARNING, "no free fids available\n"); |
387 | return -ENOSPC; | 325 | return -ENOSPC; |
388 | } | 326 | } |
389 | 327 | ||
390 | result = v9fs_t_walk(v9ses, dirfidnum, wfidno, | 328 | result = v9fs_t_walk(v9ses, dirfidnum, wfidno, |
391 | (char *) file_dentry->d_name.name, NULL); | 329 | (char *) file_dentry->d_name.name, &fcall); |
392 | if (result < 0) { | 330 | if (result < 0) { |
393 | dprintk(DEBUG_ERROR, "clone error: %s\n", FCALL_ERROR(fcall)); | 331 | PRINT_FCALL_ERROR("clone error", fcall); |
394 | v9fs_put_idpool(wfidno, &v9ses->fidpool); | 332 | v9fs_put_idpool(wfidno, &v9ses->fidpool); |
395 | wfidno = -1; | 333 | wfidno = -1; |
396 | goto CleanUpFid; | 334 | goto CleanUpFid; |
397 | } | 335 | } |
336 | kfree(fcall); | ||
337 | fcall = NULL; | ||
398 | 338 | ||
399 | if (!v9fs_fid_create(file_dentry, v9ses, wfidno, 0)) { | 339 | if (!v9fs_fid_create(file_dentry, v9ses, wfidno, 0)) { |
400 | if (!v9fs_t_clunk(v9ses, newfid, &fcall)) { | 340 | v9fs_put_idpool(wfidno, &v9ses->fidpool); |
401 | v9fs_put_idpool(wfidno, &v9ses->fidpool); | ||
402 | } | ||
403 | 341 | ||
404 | goto CleanUpFid; | 342 | goto CleanUpFid; |
405 | } | 343 | } |
@@ -409,62 +347,43 @@ v9fs_create(struct inode *dir, | |||
409 | (perm & V9FS_DMDEVICE)) | 347 | (perm & V9FS_DMDEVICE)) |
410 | return 0; | 348 | return 0; |
411 | 349 | ||
412 | result = v9fs_t_stat(v9ses, newfid, &fcall); | 350 | result = v9fs_t_stat(v9ses, wfidno, &fcall); |
413 | if (result < 0) { | 351 | if (result < 0) { |
414 | dprintk(DEBUG_ERROR, "stat error: %s(%d)\n", FCALL_ERROR(fcall), | 352 | PRINT_FCALL_ERROR("stat error", fcall); |
415 | result); | ||
416 | goto CleanUpFid; | 353 | goto CleanUpFid; |
417 | } | 354 | } |
418 | 355 | ||
419 | v9fs_mistat2unix(fcall->params.rstat.stat, &newstat, sb); | ||
420 | 356 | ||
421 | file_inode = v9fs_get_inode(sb, newstat.st_mode); | 357 | file_inode = v9fs_get_inode(sb, |
358 | p9mode2unixmode(v9ses, fcall->params.rstat.stat.mode)); | ||
359 | |||
422 | if ((!file_inode) || IS_ERR(file_inode)) { | 360 | if ((!file_inode) || IS_ERR(file_inode)) { |
423 | dprintk(DEBUG_ERROR, "create inode failed\n"); | 361 | dprintk(DEBUG_ERROR, "create inode failed\n"); |
424 | result = -EBADF; | 362 | result = -EBADF; |
425 | goto CleanUpFid; | 363 | goto CleanUpFid; |
426 | } | 364 | } |
427 | 365 | ||
428 | v9fs_mistat2inode(fcall->params.rstat.stat, file_inode, sb); | 366 | v9fs_stat2inode(&fcall->params.rstat.stat, file_inode, sb); |
429 | kfree(fcall); | 367 | kfree(fcall); |
430 | fcall = NULL; | 368 | fcall = NULL; |
431 | file_dentry->d_op = &v9fs_dentry_operations; | 369 | file_dentry->d_op = &v9fs_dentry_operations; |
432 | d_instantiate(file_dentry, file_inode); | 370 | d_instantiate(file_dentry, file_inode); |
433 | 371 | ||
434 | if (perm & V9FS_DMDIR) { | ||
435 | if (!v9fs_t_clunk(v9ses, newfid, &fcall)) | ||
436 | v9fs_put_idpool(newfid, &v9ses->fidpool); | ||
437 | else | ||
438 | dprintk(DEBUG_ERROR, "clunk for mkdir failed: %s\n", | ||
439 | FCALL_ERROR(fcall)); | ||
440 | kfree(fcall); | ||
441 | fid->fidopen = 0; | ||
442 | fid->fidcreate = 0; | ||
443 | d_drop(file_dentry); | ||
444 | } | ||
445 | |||
446 | return 0; | 372 | return 0; |
447 | 373 | ||
448 | CleanUpFid: | 374 | CleanUpFid: |
449 | kfree(fcall); | 375 | kfree(fcall); |
376 | fcall = NULL; | ||
450 | 377 | ||
451 | if (newfid >= 0) { | 378 | if (newfid >= 0) { |
452 | if (!v9fs_t_clunk(v9ses, newfid, &fcall)) | 379 | err = v9fs_t_clunk(v9ses, newfid); |
453 | v9fs_put_idpool(newfid, &v9ses->fidpool); | 380 | if (err < 0) |
454 | else | 381 | dprintk(DEBUG_ERROR, "clunk failed: %d\n", err); |
455 | dprintk(DEBUG_ERROR, "clunk failed: %s\n", | ||
456 | FCALL_ERROR(fcall)); | ||
457 | |||
458 | kfree(fcall); | ||
459 | } | 382 | } |
460 | if (wfidno >= 0) { | 383 | if (wfidno >= 0) { |
461 | if (!v9fs_t_clunk(v9ses, wfidno, &fcall)) | 384 | err = v9fs_t_clunk(v9ses, wfidno); |
462 | v9fs_put_idpool(wfidno, &v9ses->fidpool); | 385 | if (err < 0) |
463 | else | 386 | dprintk(DEBUG_ERROR, "clunk failed: %d\n", err); |
464 | dprintk(DEBUG_ERROR, "clunk failed: %s\n", | ||
465 | FCALL_ERROR(fcall)); | ||
466 | |||
467 | kfree(fcall); | ||
468 | } | 387 | } |
469 | return result; | 388 | return result; |
470 | } | 389 | } |
@@ -509,10 +428,9 @@ static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir) | |||
509 | } | 428 | } |
510 | 429 | ||
511 | result = v9fs_t_remove(v9ses, fid, &fcall); | 430 | result = v9fs_t_remove(v9ses, fid, &fcall); |
512 | if (result < 0) | 431 | if (result < 0) { |
513 | dprintk(DEBUG_ERROR, "remove of file fails: %s(%d)\n", | 432 | PRINT_FCALL_ERROR("remove fails", fcall); |
514 | FCALL_ERROR(fcall), result); | 433 | } else { |
515 | else { | ||
516 | v9fs_put_idpool(fid, &v9ses->fidpool); | 434 | v9fs_put_idpool(fid, &v9ses->fidpool); |
517 | v9fs_fid_destroy(v9fid); | 435 | v9fs_fid_destroy(v9fid); |
518 | } | 436 | } |
@@ -567,7 +485,6 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, | |||
567 | struct v9fs_fid *fid; | 485 | struct v9fs_fid *fid; |
568 | struct inode *inode; | 486 | struct inode *inode; |
569 | struct v9fs_fcall *fcall = NULL; | 487 | struct v9fs_fcall *fcall = NULL; |
570 | struct stat newstat; | ||
571 | int dirfidnum = -1; | 488 | int dirfidnum = -1; |
572 | int newfid = -1; | 489 | int newfid = -1; |
573 | int result = 0; | 490 | int result = 0; |
@@ -620,8 +537,8 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, | |||
620 | goto FreeFcall; | 537 | goto FreeFcall; |
621 | } | 538 | } |
622 | 539 | ||
623 | v9fs_mistat2unix(fcall->params.rstat.stat, &newstat, sb); | 540 | inode = v9fs_get_inode(sb, p9mode2unixmode(v9ses, |
624 | inode = v9fs_get_inode(sb, newstat.st_mode); | 541 | fcall->params.rstat.stat.mode)); |
625 | 542 | ||
626 | if (IS_ERR(inode) && (PTR_ERR(inode) == -ENOSPC)) { | 543 | if (IS_ERR(inode) && (PTR_ERR(inode) == -ENOSPC)) { |
627 | eprintk(KERN_WARNING, "inode alloc failes, returns %ld\n", | 544 | eprintk(KERN_WARNING, "inode alloc failes, returns %ld\n", |
@@ -631,7 +548,7 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, | |||
631 | goto FreeFcall; | 548 | goto FreeFcall; |
632 | } | 549 | } |
633 | 550 | ||
634 | inode->i_ino = v9fs_qid2ino(&fcall->params.rstat.stat->qid); | 551 | inode->i_ino = v9fs_qid2ino(&fcall->params.rstat.stat.qid); |
635 | 552 | ||
636 | fid = v9fs_fid_create(dentry, v9ses, newfid, 0); | 553 | fid = v9fs_fid_create(dentry, v9ses, newfid, 0); |
637 | if (fid == NULL) { | 554 | if (fid == NULL) { |
@@ -640,10 +557,10 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, | |||
640 | goto FreeFcall; | 557 | goto FreeFcall; |
641 | } | 558 | } |
642 | 559 | ||
643 | fid->qid = fcall->params.rstat.stat->qid; | 560 | fid->qid = fcall->params.rstat.stat.qid; |
644 | 561 | ||
645 | dentry->d_op = &v9fs_dentry_operations; | 562 | dentry->d_op = &v9fs_dentry_operations; |
646 | v9fs_mistat2inode(fcall->params.rstat.stat, inode, inode->i_sb); | 563 | v9fs_stat2inode(&fcall->params.rstat.stat, inode, inode->i_sb); |
647 | 564 | ||
648 | d_add(dentry, inode); | 565 | d_add(dentry, inode); |
649 | kfree(fcall); | 566 | kfree(fcall); |
@@ -699,7 +616,7 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
699 | v9fs_fid_lookup(old_dentry->d_parent); | 616 | v9fs_fid_lookup(old_dentry->d_parent); |
700 | struct v9fs_fid *newdirfid = | 617 | struct v9fs_fid *newdirfid = |
701 | v9fs_fid_lookup(new_dentry->d_parent); | 618 | v9fs_fid_lookup(new_dentry->d_parent); |
702 | struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL); | 619 | struct v9fs_wstat wstat; |
703 | struct v9fs_fcall *fcall = NULL; | 620 | struct v9fs_fcall *fcall = NULL; |
704 | int fid = -1; | 621 | int fid = -1; |
705 | int olddirfidnum = -1; | 622 | int olddirfidnum = -1; |
@@ -708,9 +625,6 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
708 | 625 | ||
709 | dprintk(DEBUG_VFS, "\n"); | 626 | dprintk(DEBUG_VFS, "\n"); |
710 | 627 | ||
711 | if (!mistat) | ||
712 | return -ENOMEM; | ||
713 | |||
714 | if ((!oldfid) || (!olddirfid) || (!newdirfid)) { | 628 | if ((!oldfid) || (!olddirfid) || (!newdirfid)) { |
715 | dprintk(DEBUG_ERROR, "problem with arguments\n"); | 629 | dprintk(DEBUG_ERROR, "problem with arguments\n"); |
716 | return -EBADF; | 630 | return -EBADF; |
@@ -734,26 +648,15 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
734 | goto FreeFcallnBail; | 648 | goto FreeFcallnBail; |
735 | } | 649 | } |
736 | 650 | ||
737 | v9fs_blank_mistat(v9ses, mistat); | 651 | v9fs_blank_wstat(&wstat); |
652 | wstat.muid = v9ses->name; | ||
653 | wstat.name = (char *) new_dentry->d_name.name; | ||
738 | 654 | ||
739 | strcpy(mistat->data + 1, v9ses->name); | 655 | retval = v9fs_t_wstat(v9ses, fid, &wstat, &fcall); |
740 | mistat->name = mistat->data + 1 + strlen(v9ses->name); | ||
741 | |||
742 | if (new_dentry->d_name.len > | ||
743 | (v9ses->maxdata - strlen(v9ses->name) - sizeof(struct v9fs_stat))) { | ||
744 | dprintk(DEBUG_ERROR, "new name too long\n"); | ||
745 | goto FreeFcallnBail; | ||
746 | } | ||
747 | |||
748 | strcpy(mistat->name, new_dentry->d_name.name); | ||
749 | retval = v9fs_t_wstat(v9ses, fid, mistat, &fcall); | ||
750 | 656 | ||
751 | FreeFcallnBail: | 657 | FreeFcallnBail: |
752 | kfree(mistat); | ||
753 | |||
754 | if (retval < 0) | 658 | if (retval < 0) |
755 | dprintk(DEBUG_ERROR, "v9fs_t_wstat error: %s\n", | 659 | PRINT_FCALL_ERROR("wstat error", fcall); |
756 | FCALL_ERROR(fcall)); | ||
757 | 660 | ||
758 | kfree(fcall); | 661 | kfree(fcall); |
759 | return retval; | 662 | return retval; |
@@ -788,7 +691,7 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, | |||
788 | if (err < 0) | 691 | if (err < 0) |
789 | dprintk(DEBUG_ERROR, "stat error\n"); | 692 | dprintk(DEBUG_ERROR, "stat error\n"); |
790 | else { | 693 | else { |
791 | v9fs_mistat2inode(fcall->params.rstat.stat, dentry->d_inode, | 694 | v9fs_stat2inode(&fcall->params.rstat.stat, dentry->d_inode, |
792 | dentry->d_inode->i_sb); | 695 | dentry->d_inode->i_sb); |
793 | generic_fillattr(dentry->d_inode, stat); | 696 | generic_fillattr(dentry->d_inode, stat); |
794 | } | 697 | } |
@@ -809,57 +712,44 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) | |||
809 | struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode); | 712 | struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode); |
810 | struct v9fs_fid *fid = v9fs_fid_lookup(dentry); | 713 | struct v9fs_fid *fid = v9fs_fid_lookup(dentry); |
811 | struct v9fs_fcall *fcall = NULL; | 714 | struct v9fs_fcall *fcall = NULL; |
812 | struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL); | 715 | struct v9fs_wstat wstat; |
813 | int res = -EPERM; | 716 | int res = -EPERM; |
814 | 717 | ||
815 | dprintk(DEBUG_VFS, "\n"); | 718 | dprintk(DEBUG_VFS, "\n"); |
816 | 719 | ||
817 | if (!mistat) | ||
818 | return -ENOMEM; | ||
819 | |||
820 | if (!fid) { | 720 | if (!fid) { |
821 | dprintk(DEBUG_ERROR, | 721 | dprintk(DEBUG_ERROR, |
822 | "Couldn't find fid associated with dentry\n"); | 722 | "Couldn't find fid associated with dentry\n"); |
823 | return -EBADF; | 723 | return -EBADF; |
824 | } | 724 | } |
825 | 725 | ||
826 | v9fs_blank_mistat(v9ses, mistat); | 726 | v9fs_blank_wstat(&wstat); |
827 | if (iattr->ia_valid & ATTR_MODE) | 727 | if (iattr->ia_valid & ATTR_MODE) |
828 | mistat->mode = unixmode2p9mode(v9ses, iattr->ia_mode); | 728 | wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode); |
829 | 729 | ||
830 | if (iattr->ia_valid & ATTR_MTIME) | 730 | if (iattr->ia_valid & ATTR_MTIME) |
831 | mistat->mtime = iattr->ia_mtime.tv_sec; | 731 | wstat.mtime = iattr->ia_mtime.tv_sec; |
832 | 732 | ||
833 | if (iattr->ia_valid & ATTR_ATIME) | 733 | if (iattr->ia_valid & ATTR_ATIME) |
834 | mistat->atime = iattr->ia_atime.tv_sec; | 734 | wstat.atime = iattr->ia_atime.tv_sec; |
835 | 735 | ||
836 | if (iattr->ia_valid & ATTR_SIZE) | 736 | if (iattr->ia_valid & ATTR_SIZE) |
837 | mistat->length = iattr->ia_size; | 737 | wstat.length = iattr->ia_size; |
838 | 738 | ||
839 | if (v9ses->extended) { | 739 | if (v9ses->extended) { |
840 | char *ptr = mistat->data+1; | 740 | if (iattr->ia_valid & ATTR_UID) |
841 | 741 | wstat.n_uid = iattr->ia_uid; | |
842 | if (iattr->ia_valid & ATTR_UID) { | ||
843 | mistat->uid = ptr; | ||
844 | ptr += 1+sprintf(ptr, "%08x", iattr->ia_uid); | ||
845 | mistat->n_uid = iattr->ia_uid; | ||
846 | } | ||
847 | 742 | ||
848 | if (iattr->ia_valid & ATTR_GID) { | 743 | if (iattr->ia_valid & ATTR_GID) |
849 | mistat->gid = ptr; | 744 | wstat.n_gid = iattr->ia_gid; |
850 | ptr += 1+sprintf(ptr, "%08x", iattr->ia_gid); | ||
851 | mistat->n_gid = iattr->ia_gid; | ||
852 | } | ||
853 | } | 745 | } |
854 | 746 | ||
855 | res = v9fs_t_wstat(v9ses, fid->fid, mistat, &fcall); | 747 | res = v9fs_t_wstat(v9ses, fid->fid, &wstat, &fcall); |
856 | 748 | ||
857 | if (res < 0) | 749 | if (res < 0) |
858 | dprintk(DEBUG_ERROR, "wstat error: %s\n", FCALL_ERROR(fcall)); | 750 | PRINT_FCALL_ERROR("wstat error", fcall); |
859 | 751 | ||
860 | kfree(mistat); | ||
861 | kfree(fcall); | 752 | kfree(fcall); |
862 | |||
863 | if (res >= 0) | 753 | if (res >= 0) |
864 | res = inode_setattr(dentry->d_inode, iattr); | 754 | res = inode_setattr(dentry->d_inode, iattr); |
865 | 755 | ||
@@ -867,51 +757,47 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) | |||
867 | } | 757 | } |
868 | 758 | ||
869 | /** | 759 | /** |
870 | * v9fs_mistat2inode - populate an inode structure with mistat info | 760 | * v9fs_stat2inode - populate an inode structure with mistat info |
871 | * @mistat: Plan 9 metadata (mistat) structure | 761 | * @stat: Plan 9 metadata (mistat) structure |
872 | * @inode: inode to populate | 762 | * @inode: inode to populate |
873 | * @sb: superblock of filesystem | 763 | * @sb: superblock of filesystem |
874 | * | 764 | * |
875 | */ | 765 | */ |
876 | 766 | ||
877 | void | 767 | void |
878 | v9fs_mistat2inode(struct v9fs_stat *mistat, struct inode *inode, | 768 | v9fs_stat2inode(struct v9fs_stat *stat, struct inode *inode, |
879 | struct super_block *sb) | 769 | struct super_block *sb) |
880 | { | 770 | { |
771 | int n; | ||
772 | char ext[32]; | ||
881 | struct v9fs_session_info *v9ses = sb->s_fs_info; | 773 | struct v9fs_session_info *v9ses = sb->s_fs_info; |
882 | 774 | ||
883 | inode->i_nlink = 1; | 775 | inode->i_nlink = 1; |
884 | 776 | ||
885 | inode->i_atime.tv_sec = mistat->atime; | 777 | inode->i_atime.tv_sec = stat->atime; |
886 | inode->i_mtime.tv_sec = mistat->mtime; | 778 | inode->i_mtime.tv_sec = stat->mtime; |
887 | inode->i_ctime.tv_sec = mistat->mtime; | 779 | inode->i_ctime.tv_sec = stat->mtime; |
888 | 780 | ||
889 | inode->i_uid = -1; | 781 | inode->i_uid = v9ses->uid; |
890 | inode->i_gid = -1; | 782 | inode->i_gid = v9ses->gid; |
891 | 783 | ||
892 | if (v9ses->extended) { | 784 | if (v9ses->extended) { |
893 | /* TODO: string to uid mapping via user-space daemon */ | 785 | inode->i_uid = stat->n_uid; |
894 | inode->i_uid = mistat->n_uid; | 786 | inode->i_gid = stat->n_gid; |
895 | inode->i_gid = mistat->n_gid; | ||
896 | |||
897 | if (mistat->n_uid == -1) | ||
898 | sscanf(mistat->uid, "%x", &inode->i_uid); | ||
899 | |||
900 | if (mistat->n_gid == -1) | ||
901 | sscanf(mistat->gid, "%x", &inode->i_gid); | ||
902 | } | 787 | } |
903 | 788 | ||
904 | if (inode->i_uid == -1) | 789 | inode->i_mode = p9mode2unixmode(v9ses, stat->mode); |
905 | inode->i_uid = v9ses->uid; | ||
906 | if (inode->i_gid == -1) | ||
907 | inode->i_gid = v9ses->gid; | ||
908 | |||
909 | inode->i_mode = p9mode2unixmode(v9ses, mistat->mode); | ||
910 | if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) { | 790 | if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) { |
911 | char type = 0; | 791 | char type = 0; |
912 | int major = -1; | 792 | int major = -1; |
913 | int minor = -1; | 793 | int minor = -1; |
914 | sscanf(mistat->extension, "%c %u %u", &type, &major, &minor); | 794 | |
795 | n = stat->extension.len; | ||
796 | if (n > sizeof(ext)-1) | ||
797 | n = sizeof(ext)-1; | ||
798 | memmove(ext, stat->extension.str, n); | ||
799 | ext[n] = 0; | ||
800 | sscanf(ext, "%c %u %u", &type, &major, &minor); | ||
915 | switch (type) { | 801 | switch (type) { |
916 | case 'c': | 802 | case 'c': |
917 | inode->i_mode &= ~S_IFBLK; | 803 | inode->i_mode &= ~S_IFBLK; |
@@ -920,14 +806,14 @@ v9fs_mistat2inode(struct v9fs_stat *mistat, struct inode *inode, | |||
920 | case 'b': | 806 | case 'b': |
921 | break; | 807 | break; |
922 | default: | 808 | default: |
923 | dprintk(DEBUG_ERROR, "Unknown special type %c (%s)\n", | 809 | dprintk(DEBUG_ERROR, "Unknown special type %c (%.*s)\n", |
924 | type, mistat->extension); | 810 | type, stat->extension.len, stat->extension.str); |
925 | }; | 811 | }; |
926 | inode->i_rdev = MKDEV(major, minor); | 812 | inode->i_rdev = MKDEV(major, minor); |
927 | } else | 813 | } else |
928 | inode->i_rdev = 0; | 814 | inode->i_rdev = 0; |
929 | 815 | ||
930 | inode->i_size = mistat->length; | 816 | inode->i_size = stat->length; |
931 | 817 | ||
932 | inode->i_blksize = sb->s_blocksize; | 818 | inode->i_blksize = sb->s_blocksize; |
933 | inode->i_blocks = | 819 | inode->i_blocks = |
@@ -955,71 +841,6 @@ ino_t v9fs_qid2ino(struct v9fs_qid *qid) | |||
955 | } | 841 | } |
956 | 842 | ||
957 | /** | 843 | /** |
958 | * v9fs_vfs_symlink - helper function to create symlinks | ||
959 | * @dir: directory inode containing symlink | ||
960 | * @dentry: dentry for symlink | ||
961 | * @symname: symlink data | ||
962 | * | ||
963 | * See 9P2000.u RFC for more information | ||
964 | * | ||
965 | */ | ||
966 | |||
967 | static int | ||
968 | v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) | ||
969 | { | ||
970 | int retval = -EPERM; | ||
971 | struct v9fs_fid *newfid; | ||
972 | struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir); | ||
973 | struct v9fs_fcall *fcall = NULL; | ||
974 | struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL); | ||
975 | |||
976 | dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, | ||
977 | symname); | ||
978 | |||
979 | if (!mistat) | ||
980 | return -ENOMEM; | ||
981 | |||
982 | if (!v9ses->extended) { | ||
983 | dprintk(DEBUG_ERROR, "not extended\n"); | ||
984 | goto FreeFcall; | ||
985 | } | ||
986 | |||
987 | /* issue a create */ | ||
988 | retval = v9fs_create(dir, dentry, S_IFLNK, 0); | ||
989 | if (retval != 0) | ||
990 | goto FreeFcall; | ||
991 | |||
992 | newfid = v9fs_fid_lookup(dentry); | ||
993 | |||
994 | /* issue a twstat */ | ||
995 | v9fs_blank_mistat(v9ses, mistat); | ||
996 | strcpy(mistat->data + 1, symname); | ||
997 | mistat->extension = mistat->data + 1; | ||
998 | retval = v9fs_t_wstat(v9ses, newfid->fid, mistat, &fcall); | ||
999 | if (retval < 0) { | ||
1000 | dprintk(DEBUG_ERROR, "v9fs_t_wstat error: %s\n", | ||
1001 | FCALL_ERROR(fcall)); | ||
1002 | goto FreeFcall; | ||
1003 | } | ||
1004 | |||
1005 | kfree(fcall); | ||
1006 | |||
1007 | if (v9fs_t_clunk(v9ses, newfid->fid, &fcall)) { | ||
1008 | dprintk(DEBUG_ERROR, "clunk for symlink failed: %s\n", | ||
1009 | FCALL_ERROR(fcall)); | ||
1010 | goto FreeFcall; | ||
1011 | } | ||
1012 | |||
1013 | d_drop(dentry); /* FID - will this also clunk? */ | ||
1014 | |||
1015 | FreeFcall: | ||
1016 | kfree(mistat); | ||
1017 | kfree(fcall); | ||
1018 | |||
1019 | return retval; | ||
1020 | } | ||
1021 | |||
1022 | /** | ||
1023 | * v9fs_readlink - read a symlink's location (internal version) | 844 | * v9fs_readlink - read a symlink's location (internal version) |
1024 | * @dentry: dentry for symlink | 845 | * @dentry: dentry for symlink |
1025 | * @buffer: buffer to load symlink location into | 846 | * @buffer: buffer to load symlink location into |
@@ -1058,16 +879,17 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen) | |||
1058 | if (!fcall) | 879 | if (!fcall) |
1059 | return -EIO; | 880 | return -EIO; |
1060 | 881 | ||
1061 | if (!(fcall->params.rstat.stat->mode & V9FS_DMSYMLINK)) { | 882 | if (!(fcall->params.rstat.stat.mode & V9FS_DMSYMLINK)) { |
1062 | retval = -EINVAL; | 883 | retval = -EINVAL; |
1063 | goto FreeFcall; | 884 | goto FreeFcall; |
1064 | } | 885 | } |
1065 | 886 | ||
1066 | /* copy extension buffer into buffer */ | 887 | /* copy extension buffer into buffer */ |
1067 | if (strlen(fcall->params.rstat.stat->extension) < buflen) | 888 | if (fcall->params.rstat.stat.extension.len < buflen) |
1068 | buflen = strlen(fcall->params.rstat.stat->extension); | 889 | buflen = fcall->params.rstat.stat.extension.len; |
1069 | 890 | ||
1070 | memcpy(buffer, fcall->params.rstat.stat->extension, buflen + 1); | 891 | memcpy(buffer, fcall->params.rstat.stat.extension.str, buflen - 1); |
892 | buffer[buflen-1] = 0; | ||
1071 | 893 | ||
1072 | retval = buflen; | 894 | retval = buflen; |
1073 | 895 | ||
@@ -1157,6 +979,77 @@ static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void | |||
1157 | __putname(s); | 979 | __putname(s); |
1158 | } | 980 | } |
1159 | 981 | ||
982 | static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry, | ||
983 | int mode, const char *extension) | ||
984 | { | ||
985 | int err, retval; | ||
986 | struct v9fs_session_info *v9ses; | ||
987 | struct v9fs_fcall *fcall; | ||
988 | struct v9fs_fid *fid; | ||
989 | struct v9fs_wstat wstat; | ||
990 | |||
991 | v9ses = v9fs_inode2v9ses(dir); | ||
992 | retval = -EPERM; | ||
993 | fcall = NULL; | ||
994 | |||
995 | if (!v9ses->extended) { | ||
996 | dprintk(DEBUG_ERROR, "not extended\n"); | ||
997 | goto free_mem; | ||
998 | } | ||
999 | |||
1000 | /* issue a create */ | ||
1001 | retval = v9fs_create(dir, dentry, mode, 0); | ||
1002 | if (retval != 0) | ||
1003 | goto free_mem; | ||
1004 | |||
1005 | fid = v9fs_fid_get_created(dentry); | ||
1006 | if (!fid) { | ||
1007 | dprintk(DEBUG_ERROR, "couldn't resolve fid from dentry\n"); | ||
1008 | goto free_mem; | ||
1009 | } | ||
1010 | |||
1011 | /* issue a Twstat */ | ||
1012 | v9fs_blank_wstat(&wstat); | ||
1013 | wstat.muid = v9ses->name; | ||
1014 | wstat.extension = (char *) extension; | ||
1015 | retval = v9fs_t_wstat(v9ses, fid->fid, &wstat, &fcall); | ||
1016 | if (retval < 0) { | ||
1017 | PRINT_FCALL_ERROR("wstat error", fcall); | ||
1018 | goto free_mem; | ||
1019 | } | ||
1020 | |||
1021 | err = v9fs_t_clunk(v9ses, fid->fid); | ||
1022 | if (err < 0) { | ||
1023 | dprintk(DEBUG_ERROR, "clunk failed: %d\n", err); | ||
1024 | goto free_mem; | ||
1025 | } | ||
1026 | |||
1027 | d_drop(dentry); /* FID - will this also clunk? */ | ||
1028 | |||
1029 | free_mem: | ||
1030 | kfree(fcall); | ||
1031 | return retval; | ||
1032 | } | ||
1033 | |||
1034 | /** | ||
1035 | * v9fs_vfs_symlink - helper function to create symlinks | ||
1036 | * @dir: directory inode containing symlink | ||
1037 | * @dentry: dentry for symlink | ||
1038 | * @symname: symlink data | ||
1039 | * | ||
1040 | * See 9P2000.u RFC for more information | ||
1041 | * | ||
1042 | */ | ||
1043 | |||
1044 | static int | ||
1045 | v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) | ||
1046 | { | ||
1047 | dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, | ||
1048 | symname); | ||
1049 | |||
1050 | return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname); | ||
1051 | } | ||
1052 | |||
1160 | /** | 1053 | /** |
1161 | * v9fs_vfs_link - create a hardlink | 1054 | * v9fs_vfs_link - create a hardlink |
1162 | * @old_dentry: dentry for file to link to | 1055 | * @old_dentry: dentry for file to link to |
@@ -1173,64 +1066,24 @@ static int | |||
1173 | v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, | 1066 | v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, |
1174 | struct dentry *dentry) | 1067 | struct dentry *dentry) |
1175 | { | 1068 | { |
1176 | int retval = -EPERM; | 1069 | int retval; |
1177 | struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir); | 1070 | struct v9fs_fid *oldfid; |
1178 | struct v9fs_fcall *fcall = NULL; | 1071 | char *name; |
1179 | struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL); | ||
1180 | struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry); | ||
1181 | struct v9fs_fid *newfid = NULL; | ||
1182 | char *symname = __getname(); | ||
1183 | 1072 | ||
1184 | dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, | 1073 | dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, |
1185 | old_dentry->d_name.name); | 1074 | old_dentry->d_name.name); |
1186 | 1075 | ||
1187 | if (!v9ses->extended) { | 1076 | oldfid = v9fs_fid_lookup(old_dentry); |
1188 | dprintk(DEBUG_ERROR, "not extended\n"); | 1077 | if (!oldfid) { |
1189 | goto FreeMem; | 1078 | dprintk(DEBUG_ERROR, "can't find oldfid\n"); |
1190 | } | 1079 | return -EPERM; |
1191 | |||
1192 | /* get fid of old_dentry */ | ||
1193 | sprintf(symname, "hardlink(%d)\n", oldfid->fid); | ||
1194 | |||
1195 | /* issue a create */ | ||
1196 | retval = v9fs_create(dir, dentry, V9FS_DMLINK, 0); | ||
1197 | if (retval != 0) | ||
1198 | goto FreeMem; | ||
1199 | |||
1200 | newfid = v9fs_fid_lookup(dentry); | ||
1201 | if (!newfid) { | ||
1202 | dprintk(DEBUG_ERROR, "couldn't resolve fid from dentry\n"); | ||
1203 | goto FreeMem; | ||
1204 | } | ||
1205 | |||
1206 | /* issue a twstat */ | ||
1207 | v9fs_blank_mistat(v9ses, mistat); | ||
1208 | strcpy(mistat->data + 1, symname); | ||
1209 | mistat->extension = mistat->data + 1; | ||
1210 | retval = v9fs_t_wstat(v9ses, newfid->fid, mistat, &fcall); | ||
1211 | if (retval < 0) { | ||
1212 | dprintk(DEBUG_ERROR, "v9fs_t_wstat error: %s\n", | ||
1213 | FCALL_ERROR(fcall)); | ||
1214 | goto FreeMem; | ||
1215 | } | ||
1216 | |||
1217 | kfree(fcall); | ||
1218 | |||
1219 | if (v9fs_t_clunk(v9ses, newfid->fid, &fcall)) { | ||
1220 | dprintk(DEBUG_ERROR, "clunk for symlink failed: %s\n", | ||
1221 | FCALL_ERROR(fcall)); | ||
1222 | goto FreeMem; | ||
1223 | } | 1080 | } |
1224 | 1081 | ||
1225 | d_drop(dentry); /* FID - will this also clunk? */ | 1082 | name = __getname(); |
1226 | 1083 | sprintf(name, "hardlink(%d)\n", oldfid->fid); | |
1227 | kfree(fcall); | 1084 | retval = v9fs_vfs_mkspecial(dir, dentry, V9FS_DMLINK, name); |
1228 | fcall = NULL; | 1085 | __putname(name); |
1229 | 1086 | ||
1230 | FreeMem: | ||
1231 | kfree(mistat); | ||
1232 | kfree(fcall); | ||
1233 | __putname(symname); | ||
1234 | return retval; | 1087 | return retval; |
1235 | } | 1088 | } |
1236 | 1089 | ||
@@ -1246,82 +1099,30 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, | |||
1246 | static int | 1099 | static int |
1247 | v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) | 1100 | v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) |
1248 | { | 1101 | { |
1249 | int retval = -EPERM; | 1102 | int retval; |
1250 | struct v9fs_fid *newfid; | 1103 | char *name; |
1251 | struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir); | ||
1252 | struct v9fs_fcall *fcall = NULL; | ||
1253 | struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL); | ||
1254 | char *symname = __getname(); | ||
1255 | 1104 | ||
1256 | dprintk(DEBUG_VFS, " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino, | 1105 | dprintk(DEBUG_VFS, " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino, |
1257 | dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev)); | 1106 | dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev)); |
1258 | 1107 | ||
1259 | if (!mistat) | 1108 | if (!new_valid_dev(rdev)) |
1260 | return -ENOMEM; | 1109 | return -EINVAL; |
1261 | |||
1262 | if (!new_valid_dev(rdev)) { | ||
1263 | retval = -EINVAL; | ||
1264 | goto FreeMem; | ||
1265 | } | ||
1266 | |||
1267 | if (!v9ses->extended) { | ||
1268 | dprintk(DEBUG_ERROR, "not extended\n"); | ||
1269 | goto FreeMem; | ||
1270 | } | ||
1271 | |||
1272 | /* issue a create */ | ||
1273 | retval = v9fs_create(dir, dentry, mode, 0); | ||
1274 | |||
1275 | if (retval != 0) | ||
1276 | goto FreeMem; | ||
1277 | |||
1278 | newfid = v9fs_fid_lookup(dentry); | ||
1279 | if (!newfid) { | ||
1280 | dprintk(DEBUG_ERROR, "coudn't resove fid from dentry\n"); | ||
1281 | retval = -EINVAL; | ||
1282 | goto FreeMem; | ||
1283 | } | ||
1284 | 1110 | ||
1111 | name = __getname(); | ||
1285 | /* build extension */ | 1112 | /* build extension */ |
1286 | if (S_ISBLK(mode)) | 1113 | if (S_ISBLK(mode)) |
1287 | sprintf(symname, "b %u %u", MAJOR(rdev), MINOR(rdev)); | 1114 | sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev)); |
1288 | else if (S_ISCHR(mode)) | 1115 | else if (S_ISCHR(mode)) |
1289 | sprintf(symname, "c %u %u", MAJOR(rdev), MINOR(rdev)); | 1116 | sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev)); |
1290 | else if (S_ISFIFO(mode)) | 1117 | else if (S_ISFIFO(mode)) |
1291 | ; /* DO NOTHING */ | 1118 | *name = 0; |
1292 | else { | 1119 | else { |
1293 | retval = -EINVAL; | 1120 | __putname(name); |
1294 | goto FreeMem; | 1121 | return -EINVAL; |
1295 | } | ||
1296 | |||
1297 | if (!S_ISFIFO(mode)) { | ||
1298 | /* issue a twstat */ | ||
1299 | v9fs_blank_mistat(v9ses, mistat); | ||
1300 | strcpy(mistat->data + 1, symname); | ||
1301 | mistat->extension = mistat->data + 1; | ||
1302 | retval = v9fs_t_wstat(v9ses, newfid->fid, mistat, &fcall); | ||
1303 | if (retval < 0) { | ||
1304 | dprintk(DEBUG_ERROR, "v9fs_t_wstat error: %s\n", | ||
1305 | FCALL_ERROR(fcall)); | ||
1306 | goto FreeMem; | ||
1307 | } | ||
1308 | } | 1122 | } |
1309 | 1123 | ||
1310 | /* need to update dcache so we show up */ | 1124 | retval = v9fs_vfs_mkspecial(dir, dentry, mode, name); |
1311 | kfree(fcall); | 1125 | __putname(name); |
1312 | |||
1313 | if (v9fs_t_clunk(v9ses, newfid->fid, &fcall)) { | ||
1314 | dprintk(DEBUG_ERROR, "clunk for symlink failed: %s\n", | ||
1315 | FCALL_ERROR(fcall)); | ||
1316 | goto FreeMem; | ||
1317 | } | ||
1318 | |||
1319 | d_drop(dentry); /* FID - will this also clunk? */ | ||
1320 | |||
1321 | FreeMem: | ||
1322 | kfree(mistat); | ||
1323 | kfree(fcall); | ||
1324 | __putname(symname); | ||
1325 | 1126 | ||
1326 | return retval; | 1127 | return retval; |
1327 | } | 1128 | } |
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c index 82c5b0084079..ae0f06b3c11a 100644 --- a/fs/9p/vfs_super.c +++ b/fs/9p/vfs_super.c | |||
@@ -44,7 +44,6 @@ | |||
44 | #include "v9fs.h" | 44 | #include "v9fs.h" |
45 | #include "9p.h" | 45 | #include "9p.h" |
46 | #include "v9fs_vfs.h" | 46 | #include "v9fs_vfs.h" |
47 | #include "conv.h" | ||
48 | #include "fid.h" | 47 | #include "fid.h" |
49 | 48 | ||
50 | static void v9fs_clear_inode(struct inode *); | 49 | static void v9fs_clear_inode(struct inode *); |
@@ -123,12 +122,13 @@ static struct super_block *v9fs_get_sb(struct file_system_type | |||
123 | 122 | ||
124 | dprintk(DEBUG_VFS, " \n"); | 123 | dprintk(DEBUG_VFS, " \n"); |
125 | 124 | ||
126 | v9ses = kcalloc(1, sizeof(struct v9fs_session_info), GFP_KERNEL); | 125 | v9ses = kzalloc(sizeof(struct v9fs_session_info), GFP_KERNEL); |
127 | if (!v9ses) | 126 | if (!v9ses) |
128 | return ERR_PTR(-ENOMEM); | 127 | return ERR_PTR(-ENOMEM); |
129 | 128 | ||
130 | if ((newfid = v9fs_session_init(v9ses, dev_name, data)) < 0) { | 129 | if ((newfid = v9fs_session_init(v9ses, dev_name, data)) < 0) { |
131 | dprintk(DEBUG_ERROR, "problem initiating session\n"); | 130 | dprintk(DEBUG_ERROR, "problem initiating session\n"); |
131 | kfree(v9ses); | ||
132 | return ERR_PTR(newfid); | 132 | return ERR_PTR(newfid); |
133 | } | 133 | } |
134 | 134 | ||
@@ -157,7 +157,7 @@ static struct super_block *v9fs_get_sb(struct file_system_type | |||
157 | stat_result = v9fs_t_stat(v9ses, newfid, &fcall); | 157 | stat_result = v9fs_t_stat(v9ses, newfid, &fcall); |
158 | if (stat_result < 0) { | 158 | if (stat_result < 0) { |
159 | dprintk(DEBUG_ERROR, "stat error\n"); | 159 | dprintk(DEBUG_ERROR, "stat error\n"); |
160 | v9fs_t_clunk(v9ses, newfid, NULL); | 160 | v9fs_t_clunk(v9ses, newfid); |
161 | v9fs_put_idpool(newfid, &v9ses->fidpool); | 161 | v9fs_put_idpool(newfid, &v9ses->fidpool); |
162 | } else { | 162 | } else { |
163 | /* Setup the Root Inode */ | 163 | /* Setup the Root Inode */ |
@@ -167,10 +167,10 @@ static struct super_block *v9fs_get_sb(struct file_system_type | |||
167 | goto put_back_sb; | 167 | goto put_back_sb; |
168 | } | 168 | } |
169 | 169 | ||
170 | root_fid->qid = fcall->params.rstat.stat->qid; | 170 | root_fid->qid = fcall->params.rstat.stat.qid; |
171 | root->d_inode->i_ino = | 171 | root->d_inode->i_ino = |
172 | v9fs_qid2ino(&fcall->params.rstat.stat->qid); | 172 | v9fs_qid2ino(&fcall->params.rstat.stat.qid); |
173 | v9fs_mistat2inode(fcall->params.rstat.stat, root->d_inode, sb); | 173 | v9fs_stat2inode(&fcall->params.rstat.stat, root->d_inode, sb); |
174 | } | 174 | } |
175 | 175 | ||
176 | kfree(fcall); | 176 | kfree(fcall); |
diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt index 175b2e8177c1..f3d3d81eb7e9 100644 --- a/fs/Kconfig.binfmt +++ b/fs/Kconfig.binfmt | |||
@@ -1,6 +1,6 @@ | |||
1 | config BINFMT_ELF | 1 | config BINFMT_ELF |
2 | bool "Kernel support for ELF binaries" | 2 | bool "Kernel support for ELF binaries" |
3 | depends on MMU | 3 | depends on MMU && (BROKEN || !FRV) |
4 | default y | 4 | default y |
5 | ---help--- | 5 | ---help--- |
6 | ELF (Executable and Linkable Format) is a format for libraries and | 6 | ELF (Executable and Linkable Format) is a format for libraries and |
diff --git a/fs/Makefile b/fs/Makefile index 73676111ebbe..35e9aec608e4 100644 --- a/fs/Makefile +++ b/fs/Makefile | |||
@@ -10,7 +10,7 @@ obj-y := open.o read_write.o file_table.o buffer.o bio.o super.o \ | |||
10 | ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \ | 10 | ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \ |
11 | attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \ | 11 | attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \ |
12 | seq_file.o xattr.o libfs.o fs-writeback.o mpage.o direct-io.o \ | 12 | seq_file.o xattr.o libfs.o fs-writeback.o mpage.o direct-io.o \ |
13 | ioprio.o pnode.o | 13 | ioprio.o pnode.o drop_caches.o |
14 | 14 | ||
15 | obj-$(CONFIG_INOTIFY) += inotify.o | 15 | obj-$(CONFIG_INOTIFY) += inotify.o |
16 | obj-$(CONFIG_EPOLL) += eventpoll.o | 16 | obj-$(CONFIG_EPOLL) += eventpoll.o |
diff --git a/fs/afs/dir.c b/fs/afs/dir.c index 6682d6d7f294..5c61c24dab2a 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c | |||
@@ -137,7 +137,7 @@ static inline void afs_dir_check_page(struct inode *dir, struct page *page) | |||
137 | #endif | 137 | #endif |
138 | 138 | ||
139 | /* determine how many magic numbers there should be in this page */ | 139 | /* determine how many magic numbers there should be in this page */ |
140 | latter = dir->i_size - (page->index << PAGE_CACHE_SHIFT); | 140 | latter = dir->i_size - page_offset(page); |
141 | if (latter >= PAGE_SIZE) | 141 | if (latter >= PAGE_SIZE) |
142 | qty = PAGE_SIZE; | 142 | qty = PAGE_SIZE; |
143 | else | 143 | else |
diff --git a/fs/afs/volume.h b/fs/afs/volume.h index 1e691889c4c9..bfdcf19ba3f3 100644 --- a/fs/afs/volume.h +++ b/fs/afs/volume.h | |||
@@ -18,8 +18,6 @@ | |||
18 | #include "kafsasyncd.h" | 18 | #include "kafsasyncd.h" |
19 | #include "cache.h" | 19 | #include "cache.h" |
20 | 20 | ||
21 | #define __packed __attribute__((packed)) | ||
22 | |||
23 | typedef enum { | 21 | typedef enum { |
24 | AFS_VLUPD_SLEEP, /* sleeping waiting for update timer to fire */ | 22 | AFS_VLUPD_SLEEP, /* sleeping waiting for update timer to fire */ |
25 | AFS_VLUPD_PENDING, /* on pending queue */ | 23 | AFS_VLUPD_PENDING, /* on pending queue */ |
@@ -115,7 +113,7 @@ struct afs_volume | |||
115 | struct cachefs_cookie *cache; /* caching cookie */ | 113 | struct cachefs_cookie *cache; /* caching cookie */ |
116 | #endif | 114 | #endif |
117 | afs_volid_t vid; /* volume ID */ | 115 | afs_volid_t vid; /* volume ID */ |
118 | afs_voltype_t __packed type; /* type of volume */ | 116 | afs_voltype_t type; /* type of volume */ |
119 | char type_force; /* force volume type (suppress R/O -> R/W) */ | 117 | char type_force; /* force volume type (suppress R/O -> R/W) */ |
120 | unsigned short nservers; /* number of server slots filled */ | 118 | unsigned short nservers; /* number of server slots filled */ |
121 | unsigned short rjservers; /* number of servers discarded due to -ENOMEDIUM */ | 119 | unsigned short rjservers; /* number of servers discarded due to -ENOMEDIUM */ |
@@ -29,7 +29,6 @@ | |||
29 | #include <linux/highmem.h> | 29 | #include <linux/highmem.h> |
30 | #include <linux/workqueue.h> | 30 | #include <linux/workqueue.h> |
31 | #include <linux/security.h> | 31 | #include <linux/security.h> |
32 | #include <linux/rcuref.h> | ||
33 | 32 | ||
34 | #include <asm/kmap_types.h> | 33 | #include <asm/kmap_types.h> |
35 | #include <asm/uaccess.h> | 34 | #include <asm/uaccess.h> |
@@ -514,7 +513,7 @@ static int __aio_put_req(struct kioctx *ctx, struct kiocb *req) | |||
514 | /* Must be done under the lock to serialise against cancellation. | 513 | /* Must be done under the lock to serialise against cancellation. |
515 | * Call this aio_fput as it duplicates fput via the fput_work. | 514 | * Call this aio_fput as it duplicates fput via the fput_work. |
516 | */ | 515 | */ |
517 | if (unlikely(rcuref_dec_and_test(&req->ki_filp->f_count))) { | 516 | if (unlikely(atomic_dec_and_test(&req->ki_filp->f_count))) { |
518 | get_ioctx(ctx); | 517 | get_ioctx(ctx); |
519 | spin_lock(&fput_lock); | 518 | spin_lock(&fput_lock); |
520 | list_add(&req->ki_list, &fput_head); | 519 | list_add(&req->ki_list, &fput_head); |
@@ -67,20 +67,12 @@ EXPORT_SYMBOL(inode_change_ok); | |||
67 | int inode_setattr(struct inode * inode, struct iattr * attr) | 67 | int inode_setattr(struct inode * inode, struct iattr * attr) |
68 | { | 68 | { |
69 | unsigned int ia_valid = attr->ia_valid; | 69 | unsigned int ia_valid = attr->ia_valid; |
70 | int error = 0; | 70 | |
71 | 71 | if (ia_valid & ATTR_SIZE && | |
72 | if (ia_valid & ATTR_SIZE) { | 72 | attr->ia_size != i_size_read(inode)) { |
73 | if (attr->ia_size != i_size_read(inode)) { | 73 | int error = vmtruncate(inode, attr->ia_size); |
74 | error = vmtruncate(inode, attr->ia_size); | 74 | if (error) |
75 | if (error || (ia_valid == ATTR_SIZE)) | 75 | return error; |
76 | goto out; | ||
77 | } else { | ||
78 | /* | ||
79 | * We skipped the truncate but must still update | ||
80 | * timestamps | ||
81 | */ | ||
82 | ia_valid |= ATTR_MTIME|ATTR_CTIME; | ||
83 | } | ||
84 | } | 76 | } |
85 | 77 | ||
86 | if (ia_valid & ATTR_UID) | 78 | if (ia_valid & ATTR_UID) |
@@ -104,8 +96,8 @@ int inode_setattr(struct inode * inode, struct iattr * attr) | |||
104 | inode->i_mode = mode; | 96 | inode->i_mode = mode; |
105 | } | 97 | } |
106 | mark_inode_dirty(inode); | 98 | mark_inode_dirty(inode); |
107 | out: | 99 | |
108 | return error; | 100 | return 0; |
109 | } | 101 | } |
110 | EXPORT_SYMBOL(inode_setattr); | 102 | EXPORT_SYMBOL(inode_setattr); |
111 | 103 | ||
diff --git a/fs/autofs4/autofs_i.h b/fs/autofs4/autofs_i.h index fca83e28edcf..385bed09b0d8 100644 --- a/fs/autofs4/autofs_i.h +++ b/fs/autofs4/autofs_i.h | |||
@@ -209,7 +209,7 @@ static inline int simple_empty_nolock(struct dentry *dentry) | |||
209 | struct dentry *child; | 209 | struct dentry *child; |
210 | int ret = 0; | 210 | int ret = 0; |
211 | 211 | ||
212 | list_for_each_entry(child, &dentry->d_subdirs, d_child) | 212 | list_for_each_entry(child, &dentry->d_subdirs, d_u.d_child) |
213 | if (simple_positive(child)) | 213 | if (simple_positive(child)) |
214 | goto out; | 214 | goto out; |
215 | ret = 1; | 215 | ret = 1; |
diff --git a/fs/autofs4/expire.c b/fs/autofs4/expire.c index feb6ac427d05..dc39589df165 100644 --- a/fs/autofs4/expire.c +++ b/fs/autofs4/expire.c | |||
@@ -105,7 +105,7 @@ repeat: | |||
105 | next = this_parent->d_subdirs.next; | 105 | next = this_parent->d_subdirs.next; |
106 | resume: | 106 | resume: |
107 | while (next != &this_parent->d_subdirs) { | 107 | while (next != &this_parent->d_subdirs) { |
108 | struct dentry *dentry = list_entry(next, struct dentry, d_child); | 108 | struct dentry *dentry = list_entry(next, struct dentry, d_u.d_child); |
109 | 109 | ||
110 | /* Negative dentry - give up */ | 110 | /* Negative dentry - give up */ |
111 | if (!simple_positive(dentry)) { | 111 | if (!simple_positive(dentry)) { |
@@ -138,7 +138,7 @@ resume: | |||
138 | } | 138 | } |
139 | 139 | ||
140 | if (this_parent != top) { | 140 | if (this_parent != top) { |
141 | next = this_parent->d_child.next; | 141 | next = this_parent->d_u.d_child.next; |
142 | this_parent = this_parent->d_parent; | 142 | this_parent = this_parent->d_parent; |
143 | goto resume; | 143 | goto resume; |
144 | } | 144 | } |
@@ -163,7 +163,7 @@ repeat: | |||
163 | next = this_parent->d_subdirs.next; | 163 | next = this_parent->d_subdirs.next; |
164 | resume: | 164 | resume: |
165 | while (next != &this_parent->d_subdirs) { | 165 | while (next != &this_parent->d_subdirs) { |
166 | struct dentry *dentry = list_entry(next, struct dentry, d_child); | 166 | struct dentry *dentry = list_entry(next, struct dentry, d_u.d_child); |
167 | 167 | ||
168 | /* Negative dentry - give up */ | 168 | /* Negative dentry - give up */ |
169 | if (!simple_positive(dentry)) { | 169 | if (!simple_positive(dentry)) { |
@@ -199,7 +199,7 @@ cont: | |||
199 | } | 199 | } |
200 | 200 | ||
201 | if (this_parent != parent) { | 201 | if (this_parent != parent) { |
202 | next = this_parent->d_child.next; | 202 | next = this_parent->d_u.d_child.next; |
203 | this_parent = this_parent->d_parent; | 203 | this_parent = this_parent->d_parent; |
204 | goto resume; | 204 | goto resume; |
205 | } | 205 | } |
@@ -238,7 +238,7 @@ static struct dentry *autofs4_expire(struct super_block *sb, | |||
238 | /* On exit from the loop expire is set to a dgot dentry | 238 | /* On exit from the loop expire is set to a dgot dentry |
239 | * to expire or it's NULL */ | 239 | * to expire or it's NULL */ |
240 | while ( next != &root->d_subdirs ) { | 240 | while ( next != &root->d_subdirs ) { |
241 | struct dentry *dentry = list_entry(next, struct dentry, d_child); | 241 | struct dentry *dentry = list_entry(next, struct dentry, d_u.d_child); |
242 | 242 | ||
243 | /* Negative dentry - give up */ | 243 | /* Negative dentry - give up */ |
244 | if ( !simple_positive(dentry) ) { | 244 | if ( !simple_positive(dentry) ) { |
@@ -302,7 +302,7 @@ next: | |||
302 | expired, (int)expired->d_name.len, expired->d_name.name); | 302 | expired, (int)expired->d_name.len, expired->d_name.name); |
303 | spin_lock(&dcache_lock); | 303 | spin_lock(&dcache_lock); |
304 | list_del(&expired->d_parent->d_subdirs); | 304 | list_del(&expired->d_parent->d_subdirs); |
305 | list_add(&expired->d_parent->d_subdirs, &expired->d_child); | 305 | list_add(&expired->d_parent->d_subdirs, &expired->d_u.d_child); |
306 | spin_unlock(&dcache_lock); | 306 | spin_unlock(&dcache_lock); |
307 | return expired; | 307 | return expired; |
308 | } | 308 | } |
diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c index 818b37be5153..2d3082854a29 100644 --- a/fs/autofs4/inode.c +++ b/fs/autofs4/inode.c | |||
@@ -91,7 +91,7 @@ repeat: | |||
91 | next = this_parent->d_subdirs.next; | 91 | next = this_parent->d_subdirs.next; |
92 | resume: | 92 | resume: |
93 | while (next != &this_parent->d_subdirs) { | 93 | while (next != &this_parent->d_subdirs) { |
94 | struct dentry *dentry = list_entry(next, struct dentry, d_child); | 94 | struct dentry *dentry = list_entry(next, struct dentry, d_u.d_child); |
95 | 95 | ||
96 | /* Negative dentry - don`t care */ | 96 | /* Negative dentry - don`t care */ |
97 | if (!simple_positive(dentry)) { | 97 | if (!simple_positive(dentry)) { |
@@ -117,7 +117,7 @@ resume: | |||
117 | if (this_parent != sbi->root) { | 117 | if (this_parent != sbi->root) { |
118 | struct dentry *dentry = this_parent; | 118 | struct dentry *dentry = this_parent; |
119 | 119 | ||
120 | next = this_parent->d_child.next; | 120 | next = this_parent->d_u.d_child.next; |
121 | this_parent = this_parent->d_parent; | 121 | this_parent = this_parent->d_parent; |
122 | spin_unlock(&dcache_lock); | 122 | spin_unlock(&dcache_lock); |
123 | DPRINTK("parent dentry %p %.*s", | 123 | DPRINTK("parent dentry %p %.*s", |
diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c index 2a771ec66956..2241405ffc41 100644 --- a/fs/autofs4/root.c +++ b/fs/autofs4/root.c | |||
@@ -143,7 +143,8 @@ static int autofs4_dcache_readdir(struct file * filp, void * dirent, filldir_t f | |||
143 | } | 143 | } |
144 | 144 | ||
145 | while(1) { | 145 | while(1) { |
146 | struct dentry *de = list_entry(list, struct dentry, d_child); | 146 | struct dentry *de = list_entry(list, |
147 | struct dentry, d_u.d_child); | ||
147 | 148 | ||
148 | if (!d_unhashed(de) && de->d_inode) { | 149 | if (!d_unhashed(de) && de->d_inode) { |
149 | spin_unlock(&dcache_lock); | 150 | spin_unlock(&dcache_lock); |
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index f36f2210204f..80ca932ba0bd 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c | |||
@@ -58,7 +58,7 @@ extern int dump_fpu (struct pt_regs *, elf_fpregset_t *); | |||
58 | * If we don't support core dumping, then supply a NULL so we | 58 | * If we don't support core dumping, then supply a NULL so we |
59 | * don't even try. | 59 | * don't even try. |
60 | */ | 60 | */ |
61 | #ifdef USE_ELF_CORE_DUMP | 61 | #if defined(USE_ELF_CORE_DUMP) && defined(CONFIG_ELF_CORE) |
62 | static int elf_core_dump(long signr, struct pt_regs * regs, struct file * file); | 62 | static int elf_core_dump(long signr, struct pt_regs * regs, struct file * file); |
63 | #else | 63 | #else |
64 | #define elf_core_dump NULL | 64 | #define elf_core_dump NULL |
@@ -288,11 +288,17 @@ static unsigned long elf_map(struct file *filep, unsigned long addr, | |||
288 | struct elf_phdr *eppnt, int prot, int type) | 288 | struct elf_phdr *eppnt, int prot, int type) |
289 | { | 289 | { |
290 | unsigned long map_addr; | 290 | unsigned long map_addr; |
291 | unsigned long pageoffset = ELF_PAGEOFFSET(eppnt->p_vaddr); | ||
291 | 292 | ||
292 | down_write(¤t->mm->mmap_sem); | 293 | down_write(¤t->mm->mmap_sem); |
293 | map_addr = do_mmap(filep, ELF_PAGESTART(addr), | 294 | /* mmap() will return -EINVAL if given a zero size, but a |
294 | eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr), prot, type, | 295 | * segment with zero filesize is perfectly valid */ |
295 | eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr)); | 296 | if (eppnt->p_filesz + pageoffset) |
297 | map_addr = do_mmap(filep, ELF_PAGESTART(addr), | ||
298 | eppnt->p_filesz + pageoffset, prot, type, | ||
299 | eppnt->p_offset - pageoffset); | ||
300 | else | ||
301 | map_addr = ELF_PAGESTART(addr); | ||
296 | up_write(¤t->mm->mmap_sem); | 302 | up_write(¤t->mm->mmap_sem); |
297 | return(map_addr); | 303 | return(map_addr); |
298 | } | 304 | } |
@@ -1107,7 +1113,7 @@ out: | |||
1107 | * Note that some platforms still use traditional core dumps and not | 1113 | * Note that some platforms still use traditional core dumps and not |
1108 | * the ELF core dump. Each platform can select it as appropriate. | 1114 | * the ELF core dump. Each platform can select it as appropriate. |
1109 | */ | 1115 | */ |
1110 | #ifdef USE_ELF_CORE_DUMP | 1116 | #if defined(USE_ELF_CORE_DUMP) && defined(CONFIG_ELF_CORE) |
1111 | 1117 | ||
1112 | /* | 1118 | /* |
1113 | * ELF core dumper | 1119 | * ELF core dumper |
diff --git a/fs/buffer.c b/fs/buffer.c index 5287be18633b..55f0975a9b15 100644 --- a/fs/buffer.c +++ b/fs/buffer.c | |||
@@ -153,14 +153,8 @@ int sync_blockdev(struct block_device *bdev) | |||
153 | { | 153 | { |
154 | int ret = 0; | 154 | int ret = 0; |
155 | 155 | ||
156 | if (bdev) { | 156 | if (bdev) |
157 | int err; | 157 | ret = filemap_write_and_wait(bdev->bd_inode->i_mapping); |
158 | |||
159 | ret = filemap_fdatawrite(bdev->bd_inode->i_mapping); | ||
160 | err = filemap_fdatawait(bdev->bd_inode->i_mapping); | ||
161 | if (!ret) | ||
162 | ret = err; | ||
163 | } | ||
164 | return ret; | 158 | return ret; |
165 | } | 159 | } |
166 | EXPORT_SYMBOL(sync_blockdev); | 160 | EXPORT_SYMBOL(sync_blockdev); |
@@ -1768,7 +1762,7 @@ static int __block_write_full_page(struct inode *inode, struct page *page, | |||
1768 | * handle that here by just cleaning them. | 1762 | * handle that here by just cleaning them. |
1769 | */ | 1763 | */ |
1770 | 1764 | ||
1771 | block = page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits); | 1765 | block = (sector_t)page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits); |
1772 | head = page_buffers(page); | 1766 | head = page_buffers(page); |
1773 | bh = head; | 1767 | bh = head; |
1774 | 1768 | ||
@@ -2160,11 +2154,12 @@ int block_read_full_page(struct page *page, get_block_t *get_block) | |||
2160 | * truncates. Uses prepare/commit_write to allow the filesystem to | 2154 | * truncates. Uses prepare/commit_write to allow the filesystem to |
2161 | * deal with the hole. | 2155 | * deal with the hole. |
2162 | */ | 2156 | */ |
2163 | int generic_cont_expand(struct inode *inode, loff_t size) | 2157 | static int __generic_cont_expand(struct inode *inode, loff_t size, |
2158 | pgoff_t index, unsigned int offset) | ||
2164 | { | 2159 | { |
2165 | struct address_space *mapping = inode->i_mapping; | 2160 | struct address_space *mapping = inode->i_mapping; |
2166 | struct page *page; | 2161 | struct page *page; |
2167 | unsigned long index, offset, limit; | 2162 | unsigned long limit; |
2168 | int err; | 2163 | int err; |
2169 | 2164 | ||
2170 | err = -EFBIG; | 2165 | err = -EFBIG; |
@@ -2176,24 +2171,24 @@ int generic_cont_expand(struct inode *inode, loff_t size) | |||
2176 | if (size > inode->i_sb->s_maxbytes) | 2171 | if (size > inode->i_sb->s_maxbytes) |
2177 | goto out; | 2172 | goto out; |
2178 | 2173 | ||
2179 | offset = (size & (PAGE_CACHE_SIZE-1)); /* Within page */ | ||
2180 | |||
2181 | /* ugh. in prepare/commit_write, if from==to==start of block, we | ||
2182 | ** skip the prepare. make sure we never send an offset for the start | ||
2183 | ** of a block | ||
2184 | */ | ||
2185 | if ((offset & (inode->i_sb->s_blocksize - 1)) == 0) { | ||
2186 | offset++; | ||
2187 | } | ||
2188 | index = size >> PAGE_CACHE_SHIFT; | ||
2189 | err = -ENOMEM; | 2174 | err = -ENOMEM; |
2190 | page = grab_cache_page(mapping, index); | 2175 | page = grab_cache_page(mapping, index); |
2191 | if (!page) | 2176 | if (!page) |
2192 | goto out; | 2177 | goto out; |
2193 | err = mapping->a_ops->prepare_write(NULL, page, offset, offset); | 2178 | err = mapping->a_ops->prepare_write(NULL, page, offset, offset); |
2194 | if (!err) { | 2179 | if (err) { |
2195 | err = mapping->a_ops->commit_write(NULL, page, offset, offset); | 2180 | /* |
2181 | * ->prepare_write() may have instantiated a few blocks | ||
2182 | * outside i_size. Trim these off again. | ||
2183 | */ | ||
2184 | unlock_page(page); | ||
2185 | page_cache_release(page); | ||
2186 | vmtruncate(inode, inode->i_size); | ||
2187 | goto out; | ||
2196 | } | 2188 | } |
2189 | |||
2190 | err = mapping->a_ops->commit_write(NULL, page, offset, offset); | ||
2191 | |||
2197 | unlock_page(page); | 2192 | unlock_page(page); |
2198 | page_cache_release(page); | 2193 | page_cache_release(page); |
2199 | if (err > 0) | 2194 | if (err > 0) |
@@ -2202,6 +2197,36 @@ out: | |||
2202 | return err; | 2197 | return err; |
2203 | } | 2198 | } |
2204 | 2199 | ||
2200 | int generic_cont_expand(struct inode *inode, loff_t size) | ||
2201 | { | ||
2202 | pgoff_t index; | ||
2203 | unsigned int offset; | ||
2204 | |||
2205 | offset = (size & (PAGE_CACHE_SIZE - 1)); /* Within page */ | ||
2206 | |||
2207 | /* ugh. in prepare/commit_write, if from==to==start of block, we | ||
2208 | ** skip the prepare. make sure we never send an offset for the start | ||
2209 | ** of a block | ||
2210 | */ | ||
2211 | if ((offset & (inode->i_sb->s_blocksize - 1)) == 0) { | ||
2212 | /* caller must handle this extra byte. */ | ||
2213 | offset++; | ||
2214 | } | ||
2215 | index = size >> PAGE_CACHE_SHIFT; | ||
2216 | |||
2217 | return __generic_cont_expand(inode, size, index, offset); | ||
2218 | } | ||
2219 | |||
2220 | int generic_cont_expand_simple(struct inode *inode, loff_t size) | ||
2221 | { | ||
2222 | loff_t pos = size - 1; | ||
2223 | pgoff_t index = pos >> PAGE_CACHE_SHIFT; | ||
2224 | unsigned int offset = (pos & (PAGE_CACHE_SIZE - 1)) + 1; | ||
2225 | |||
2226 | /* prepare/commit_write can handle even if from==to==start of block. */ | ||
2227 | return __generic_cont_expand(inode, size, index, offset); | ||
2228 | } | ||
2229 | |||
2205 | /* | 2230 | /* |
2206 | * For moronic filesystems that do not allow holes in file. | 2231 | * For moronic filesystems that do not allow holes in file. |
2207 | * We may have to extend the file. | 2232 | * We may have to extend the file. |
@@ -2610,7 +2635,7 @@ int block_truncate_page(struct address_space *mapping, | |||
2610 | pgoff_t index = from >> PAGE_CACHE_SHIFT; | 2635 | pgoff_t index = from >> PAGE_CACHE_SHIFT; |
2611 | unsigned offset = from & (PAGE_CACHE_SIZE-1); | 2636 | unsigned offset = from & (PAGE_CACHE_SIZE-1); |
2612 | unsigned blocksize; | 2637 | unsigned blocksize; |
2613 | pgoff_t iblock; | 2638 | sector_t iblock; |
2614 | unsigned length, pos; | 2639 | unsigned length, pos; |
2615 | struct inode *inode = mapping->host; | 2640 | struct inode *inode = mapping->host; |
2616 | struct page *page; | 2641 | struct page *page; |
@@ -2626,7 +2651,7 @@ int block_truncate_page(struct address_space *mapping, | |||
2626 | return 0; | 2651 | return 0; |
2627 | 2652 | ||
2628 | length = blocksize - length; | 2653 | length = blocksize - length; |
2629 | iblock = index << (PAGE_CACHE_SHIFT - inode->i_blkbits); | 2654 | iblock = (sector_t)index << (PAGE_CACHE_SHIFT - inode->i_blkbits); |
2630 | 2655 | ||
2631 | page = grab_cache_page(mapping, index); | 2656 | page = grab_cache_page(mapping, index); |
2632 | err = -ENOMEM; | 2657 | err = -ENOMEM; |
@@ -3145,6 +3170,7 @@ EXPORT_SYMBOL(fsync_bdev); | |||
3145 | EXPORT_SYMBOL(generic_block_bmap); | 3170 | EXPORT_SYMBOL(generic_block_bmap); |
3146 | EXPORT_SYMBOL(generic_commit_write); | 3171 | EXPORT_SYMBOL(generic_commit_write); |
3147 | EXPORT_SYMBOL(generic_cont_expand); | 3172 | EXPORT_SYMBOL(generic_cont_expand); |
3173 | EXPORT_SYMBOL(generic_cont_expand_simple); | ||
3148 | EXPORT_SYMBOL(init_buffer); | 3174 | EXPORT_SYMBOL(init_buffer); |
3149 | EXPORT_SYMBOL(invalidate_bdev); | 3175 | EXPORT_SYMBOL(invalidate_bdev); |
3150 | EXPORT_SYMBOL(ll_rw_block); | 3176 | EXPORT_SYMBOL(ll_rw_block); |
diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 14a1c72ced92..5ade53d7bca8 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c | |||
@@ -127,8 +127,7 @@ static inline int cifs_open_inode_helper(struct inode *inode, struct file *file, | |||
127 | if (file->f_dentry->d_inode->i_mapping) { | 127 | if (file->f_dentry->d_inode->i_mapping) { |
128 | /* BB no need to lock inode until after invalidate | 128 | /* BB no need to lock inode until after invalidate |
129 | since namei code should already have it locked? */ | 129 | since namei code should already have it locked? */ |
130 | filemap_fdatawrite(file->f_dentry->d_inode->i_mapping); | 130 | filemap_write_and_wait(file->f_dentry->d_inode->i_mapping); |
131 | filemap_fdatawait(file->f_dentry->d_inode->i_mapping); | ||
132 | } | 131 | } |
133 | cFYI(1, ("invalidating remote inode since open detected it " | 132 | cFYI(1, ("invalidating remote inode since open detected it " |
134 | "changed")); | 133 | "changed")); |
@@ -419,8 +418,7 @@ static int cifs_reopen_file(struct inode *inode, struct file *file, | |||
419 | pCifsInode = CIFS_I(inode); | 418 | pCifsInode = CIFS_I(inode); |
420 | if (pCifsInode) { | 419 | if (pCifsInode) { |
421 | if (can_flush) { | 420 | if (can_flush) { |
422 | filemap_fdatawrite(inode->i_mapping); | 421 | filemap_write_and_wait(inode->i_mapping); |
423 | filemap_fdatawait(inode->i_mapping); | ||
424 | /* temporarily disable caching while we | 422 | /* temporarily disable caching while we |
425 | go to server to get inode info */ | 423 | go to server to get inode info */ |
426 | pCifsInode->clientCanCacheAll = FALSE; | 424 | pCifsInode->clientCanCacheAll = FALSE; |
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index 411c1f7f84da..9558f51bca55 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c | |||
@@ -1148,8 +1148,7 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs) | |||
1148 | /* BB check if we need to refresh inode from server now ? BB */ | 1148 | /* BB check if we need to refresh inode from server now ? BB */ |
1149 | 1149 | ||
1150 | /* need to flush data before changing file size on server */ | 1150 | /* need to flush data before changing file size on server */ |
1151 | filemap_fdatawrite(direntry->d_inode->i_mapping); | 1151 | filemap_write_and_wait(direntry->d_inode->i_mapping); |
1152 | filemap_fdatawait(direntry->d_inode->i_mapping); | ||
1153 | 1152 | ||
1154 | if (attrs->ia_valid & ATTR_SIZE) { | 1153 | if (attrs->ia_valid & ATTR_SIZE) { |
1155 | /* To avoid spurious oplock breaks from server, in the case of | 1154 | /* To avoid spurious oplock breaks from server, in the case of |
diff --git a/fs/coda/cache.c b/fs/coda/cache.c index 80072fd9b7fa..c607d923350a 100644 --- a/fs/coda/cache.c +++ b/fs/coda/cache.c | |||
@@ -93,7 +93,7 @@ static void coda_flag_children(struct dentry *parent, int flag) | |||
93 | spin_lock(&dcache_lock); | 93 | spin_lock(&dcache_lock); |
94 | list_for_each(child, &parent->d_subdirs) | 94 | list_for_each(child, &parent->d_subdirs) |
95 | { | 95 | { |
96 | de = list_entry(child, struct dentry, d_child); | 96 | de = list_entry(child, struct dentry, d_u.d_child); |
97 | /* don't know what to do with negative dentries */ | 97 | /* don't know what to do with negative dentries */ |
98 | if ( ! de->d_inode ) | 98 | if ( ! de->d_inode ) |
99 | continue; | 99 | continue; |
diff --git a/fs/compat.c b/fs/compat.c index 55ac0324aaf1..271b75d1597f 100644 --- a/fs/compat.c +++ b/fs/compat.c | |||
@@ -494,9 +494,21 @@ asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd, | |||
494 | ret = sys_fcntl(fd, cmd, (unsigned long)&f); | 494 | ret = sys_fcntl(fd, cmd, (unsigned long)&f); |
495 | set_fs(old_fs); | 495 | set_fs(old_fs); |
496 | if (cmd == F_GETLK && ret == 0) { | 496 | if (cmd == F_GETLK && ret == 0) { |
497 | if ((f.l_start >= COMPAT_OFF_T_MAX) || | 497 | /* GETLK was successfule and we need to return the data... |
498 | ((f.l_start + f.l_len) > COMPAT_OFF_T_MAX)) | 498 | * but it needs to fit in the compat structure. |
499 | * l_start shouldn't be too big, unless the original | ||
500 | * start + end is greater than COMPAT_OFF_T_MAX, in which | ||
501 | * case the app was asking for trouble, so we return | ||
502 | * -EOVERFLOW in that case. | ||
503 | * l_len could be too big, in which case we just truncate it, | ||
504 | * and only allow the app to see that part of the conflicting | ||
505 | * lock that might make sense to it anyway | ||
506 | */ | ||
507 | |||
508 | if (f.l_start > COMPAT_OFF_T_MAX) | ||
499 | ret = -EOVERFLOW; | 509 | ret = -EOVERFLOW; |
510 | if (f.l_len > COMPAT_OFF_T_MAX) | ||
511 | f.l_len = COMPAT_OFF_T_MAX; | ||
500 | if (ret == 0) | 512 | if (ret == 0) |
501 | ret = put_compat_flock(&f, compat_ptr(arg)); | 513 | ret = put_compat_flock(&f, compat_ptr(arg)); |
502 | } | 514 | } |
@@ -515,9 +527,11 @@ asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd, | |||
515 | (unsigned long)&f); | 527 | (unsigned long)&f); |
516 | set_fs(old_fs); | 528 | set_fs(old_fs); |
517 | if (cmd == F_GETLK64 && ret == 0) { | 529 | if (cmd == F_GETLK64 && ret == 0) { |
518 | if ((f.l_start >= COMPAT_LOFF_T_MAX) || | 530 | /* need to return lock information - see above for commentary */ |
519 | ((f.l_start + f.l_len) > COMPAT_LOFF_T_MAX)) | 531 | if (f.l_start > COMPAT_LOFF_T_MAX) |
520 | ret = -EOVERFLOW; | 532 | ret = -EOVERFLOW; |
533 | if (f.l_len > COMPAT_LOFF_T_MAX) | ||
534 | f.l_len = COMPAT_LOFF_T_MAX; | ||
521 | if (ret == 0) | 535 | if (ret == 0) |
522 | ret = put_compat_flock64(&f, compat_ptr(arg)); | 536 | ret = put_compat_flock64(&f, compat_ptr(arg)); |
523 | } | 537 | } |
diff --git a/fs/dcache.c b/fs/dcache.c index 17e439138681..1536f15c4d4c 100644 --- a/fs/dcache.c +++ b/fs/dcache.c | |||
@@ -71,7 +71,7 @@ struct dentry_stat_t dentry_stat = { | |||
71 | 71 | ||
72 | static void d_callback(struct rcu_head *head) | 72 | static void d_callback(struct rcu_head *head) |
73 | { | 73 | { |
74 | struct dentry * dentry = container_of(head, struct dentry, d_rcu); | 74 | struct dentry * dentry = container_of(head, struct dentry, d_u.d_rcu); |
75 | 75 | ||
76 | if (dname_external(dentry)) | 76 | if (dname_external(dentry)) |
77 | kfree(dentry->d_name.name); | 77 | kfree(dentry->d_name.name); |
@@ -86,7 +86,7 @@ static void d_free(struct dentry *dentry) | |||
86 | { | 86 | { |
87 | if (dentry->d_op && dentry->d_op->d_release) | 87 | if (dentry->d_op && dentry->d_op->d_release) |
88 | dentry->d_op->d_release(dentry); | 88 | dentry->d_op->d_release(dentry); |
89 | call_rcu(&dentry->d_rcu, d_callback); | 89 | call_rcu(&dentry->d_u.d_rcu, d_callback); |
90 | } | 90 | } |
91 | 91 | ||
92 | /* | 92 | /* |
@@ -193,7 +193,7 @@ kill_it: { | |||
193 | list_del(&dentry->d_lru); | 193 | list_del(&dentry->d_lru); |
194 | dentry_stat.nr_unused--; | 194 | dentry_stat.nr_unused--; |
195 | } | 195 | } |
196 | list_del(&dentry->d_child); | 196 | list_del(&dentry->d_u.d_child); |
197 | dentry_stat.nr_dentry--; /* For d_free, below */ | 197 | dentry_stat.nr_dentry--; /* For d_free, below */ |
198 | /*drops the locks, at that point nobody can reach this dentry */ | 198 | /*drops the locks, at that point nobody can reach this dentry */ |
199 | dentry_iput(dentry); | 199 | dentry_iput(dentry); |
@@ -367,7 +367,7 @@ static inline void prune_one_dentry(struct dentry * dentry) | |||
367 | struct dentry * parent; | 367 | struct dentry * parent; |
368 | 368 | ||
369 | __d_drop(dentry); | 369 | __d_drop(dentry); |
370 | list_del(&dentry->d_child); | 370 | list_del(&dentry->d_u.d_child); |
371 | dentry_stat.nr_dentry--; /* For d_free, below */ | 371 | dentry_stat.nr_dentry--; /* For d_free, below */ |
372 | dentry_iput(dentry); | 372 | dentry_iput(dentry); |
373 | parent = dentry->d_parent; | 373 | parent = dentry->d_parent; |
@@ -518,7 +518,7 @@ repeat: | |||
518 | resume: | 518 | resume: |
519 | while (next != &this_parent->d_subdirs) { | 519 | while (next != &this_parent->d_subdirs) { |
520 | struct list_head *tmp = next; | 520 | struct list_head *tmp = next; |
521 | struct dentry *dentry = list_entry(tmp, struct dentry, d_child); | 521 | struct dentry *dentry = list_entry(tmp, struct dentry, d_u.d_child); |
522 | next = tmp->next; | 522 | next = tmp->next; |
523 | /* Have we found a mount point ? */ | 523 | /* Have we found a mount point ? */ |
524 | if (d_mountpoint(dentry)) | 524 | if (d_mountpoint(dentry)) |
@@ -532,7 +532,7 @@ resume: | |||
532 | * All done at this level ... ascend and resume the search. | 532 | * All done at this level ... ascend and resume the search. |
533 | */ | 533 | */ |
534 | if (this_parent != parent) { | 534 | if (this_parent != parent) { |
535 | next = this_parent->d_child.next; | 535 | next = this_parent->d_u.d_child.next; |
536 | this_parent = this_parent->d_parent; | 536 | this_parent = this_parent->d_parent; |
537 | goto resume; | 537 | goto resume; |
538 | } | 538 | } |
@@ -569,7 +569,7 @@ repeat: | |||
569 | resume: | 569 | resume: |
570 | while (next != &this_parent->d_subdirs) { | 570 | while (next != &this_parent->d_subdirs) { |
571 | struct list_head *tmp = next; | 571 | struct list_head *tmp = next; |
572 | struct dentry *dentry = list_entry(tmp, struct dentry, d_child); | 572 | struct dentry *dentry = list_entry(tmp, struct dentry, d_u.d_child); |
573 | next = tmp->next; | 573 | next = tmp->next; |
574 | 574 | ||
575 | if (!list_empty(&dentry->d_lru)) { | 575 | if (!list_empty(&dentry->d_lru)) { |
@@ -610,7 +610,7 @@ dentry->d_parent->d_name.name, dentry->d_name.name, found); | |||
610 | * All done at this level ... ascend and resume the search. | 610 | * All done at this level ... ascend and resume the search. |
611 | */ | 611 | */ |
612 | if (this_parent != parent) { | 612 | if (this_parent != parent) { |
613 | next = this_parent->d_child.next; | 613 | next = this_parent->d_u.d_child.next; |
614 | this_parent = this_parent->d_parent; | 614 | this_parent = this_parent->d_parent; |
615 | #ifdef DCACHE_DEBUG | 615 | #ifdef DCACHE_DEBUG |
616 | printk(KERN_DEBUG "select_parent: ascending to %s/%s, found=%d\n", | 616 | printk(KERN_DEBUG "select_parent: ascending to %s/%s, found=%d\n", |
@@ -753,12 +753,12 @@ struct dentry *d_alloc(struct dentry * parent, const struct qstr *name) | |||
753 | dentry->d_parent = dget(parent); | 753 | dentry->d_parent = dget(parent); |
754 | dentry->d_sb = parent->d_sb; | 754 | dentry->d_sb = parent->d_sb; |
755 | } else { | 755 | } else { |
756 | INIT_LIST_HEAD(&dentry->d_child); | 756 | INIT_LIST_HEAD(&dentry->d_u.d_child); |
757 | } | 757 | } |
758 | 758 | ||
759 | spin_lock(&dcache_lock); | 759 | spin_lock(&dcache_lock); |
760 | if (parent) | 760 | if (parent) |
761 | list_add(&dentry->d_child, &parent->d_subdirs); | 761 | list_add(&dentry->d_u.d_child, &parent->d_subdirs); |
762 | dentry_stat.nr_dentry++; | 762 | dentry_stat.nr_dentry++; |
763 | spin_unlock(&dcache_lock); | 763 | spin_unlock(&dcache_lock); |
764 | 764 | ||
@@ -1310,8 +1310,8 @@ already_unhashed: | |||
1310 | /* Unhash the target: dput() will then get rid of it */ | 1310 | /* Unhash the target: dput() will then get rid of it */ |
1311 | __d_drop(target); | 1311 | __d_drop(target); |
1312 | 1312 | ||
1313 | list_del(&dentry->d_child); | 1313 | list_del(&dentry->d_u.d_child); |
1314 | list_del(&target->d_child); | 1314 | list_del(&target->d_u.d_child); |
1315 | 1315 | ||
1316 | /* Switch the names.. */ | 1316 | /* Switch the names.. */ |
1317 | switch_names(dentry, target); | 1317 | switch_names(dentry, target); |
@@ -1322,15 +1322,15 @@ already_unhashed: | |||
1322 | if (IS_ROOT(dentry)) { | 1322 | if (IS_ROOT(dentry)) { |
1323 | dentry->d_parent = target->d_parent; | 1323 | dentry->d_parent = target->d_parent; |
1324 | target->d_parent = target; | 1324 | target->d_parent = target; |
1325 | INIT_LIST_HEAD(&target->d_child); | 1325 | INIT_LIST_HEAD(&target->d_u.d_child); |
1326 | } else { | 1326 | } else { |
1327 | do_switch(dentry->d_parent, target->d_parent); | 1327 | do_switch(dentry->d_parent, target->d_parent); |
1328 | 1328 | ||
1329 | /* And add them back to the (new) parent lists */ | 1329 | /* And add them back to the (new) parent lists */ |
1330 | list_add(&target->d_child, &target->d_parent->d_subdirs); | 1330 | list_add(&target->d_u.d_child, &target->d_parent->d_subdirs); |
1331 | } | 1331 | } |
1332 | 1332 | ||
1333 | list_add(&dentry->d_child, &dentry->d_parent->d_subdirs); | 1333 | list_add(&dentry->d_u.d_child, &dentry->d_parent->d_subdirs); |
1334 | spin_unlock(&target->d_lock); | 1334 | spin_unlock(&target->d_lock); |
1335 | spin_unlock(&dentry->d_lock); | 1335 | spin_unlock(&dentry->d_lock); |
1336 | write_sequnlock(&rename_lock); | 1336 | write_sequnlock(&rename_lock); |
@@ -1568,7 +1568,7 @@ repeat: | |||
1568 | resume: | 1568 | resume: |
1569 | while (next != &this_parent->d_subdirs) { | 1569 | while (next != &this_parent->d_subdirs) { |
1570 | struct list_head *tmp = next; | 1570 | struct list_head *tmp = next; |
1571 | struct dentry *dentry = list_entry(tmp, struct dentry, d_child); | 1571 | struct dentry *dentry = list_entry(tmp, struct dentry, d_u.d_child); |
1572 | next = tmp->next; | 1572 | next = tmp->next; |
1573 | if (d_unhashed(dentry)||!dentry->d_inode) | 1573 | if (d_unhashed(dentry)||!dentry->d_inode) |
1574 | continue; | 1574 | continue; |
@@ -1579,7 +1579,7 @@ resume: | |||
1579 | atomic_dec(&dentry->d_count); | 1579 | atomic_dec(&dentry->d_count); |
1580 | } | 1580 | } |
1581 | if (this_parent != root) { | 1581 | if (this_parent != root) { |
1582 | next = this_parent->d_child.next; | 1582 | next = this_parent->d_u.d_child.next; |
1583 | atomic_dec(&this_parent->d_count); | 1583 | atomic_dec(&this_parent->d_count); |
1584 | this_parent = this_parent->d_parent; | 1584 | this_parent = this_parent->d_parent; |
1585 | goto resume; | 1585 | goto resume; |
diff --git a/fs/drop_caches.c b/fs/drop_caches.c new file mode 100644 index 000000000000..4e4762389bdc --- /dev/null +++ b/fs/drop_caches.c | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | * Implement the manual drop-all-pagecache function | ||
3 | */ | ||
4 | |||
5 | #include <linux/kernel.h> | ||
6 | #include <linux/mm.h> | ||
7 | #include <linux/fs.h> | ||
8 | #include <linux/writeback.h> | ||
9 | #include <linux/sysctl.h> | ||
10 | #include <linux/gfp.h> | ||
11 | |||
12 | /* A global variable is a bit ugly, but it keeps the code simple */ | ||
13 | int sysctl_drop_caches; | ||
14 | |||
15 | static void drop_pagecache_sb(struct super_block *sb) | ||
16 | { | ||
17 | struct inode *inode; | ||
18 | |||
19 | spin_lock(&inode_lock); | ||
20 | list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { | ||
21 | if (inode->i_state & (I_FREEING|I_WILL_FREE)) | ||
22 | continue; | ||
23 | invalidate_inode_pages(inode->i_mapping); | ||
24 | } | ||
25 | spin_unlock(&inode_lock); | ||
26 | } | ||
27 | |||
28 | void drop_pagecache(void) | ||
29 | { | ||
30 | struct super_block *sb; | ||
31 | |||
32 | spin_lock(&sb_lock); | ||
33 | restart: | ||
34 | list_for_each_entry(sb, &super_blocks, s_list) { | ||
35 | sb->s_count++; | ||
36 | spin_unlock(&sb_lock); | ||
37 | down_read(&sb->s_umount); | ||
38 | if (sb->s_root) | ||
39 | drop_pagecache_sb(sb); | ||
40 | up_read(&sb->s_umount); | ||
41 | spin_lock(&sb_lock); | ||
42 | if (__put_super_and_need_restart(sb)) | ||
43 | goto restart; | ||
44 | } | ||
45 | spin_unlock(&sb_lock); | ||
46 | } | ||
47 | |||
48 | void drop_slab(void) | ||
49 | { | ||
50 | int nr_objects; | ||
51 | |||
52 | do { | ||
53 | nr_objects = shrink_slab(1000, GFP_KERNEL, 1000); | ||
54 | } while (nr_objects > 10); | ||
55 | } | ||
56 | |||
57 | int drop_caches_sysctl_handler(ctl_table *table, int write, | ||
58 | struct file *file, void __user *buffer, size_t *length, loff_t *ppos) | ||
59 | { | ||
60 | proc_dointvec_minmax(table, write, file, buffer, length, ppos); | ||
61 | if (write) { | ||
62 | if (sysctl_drop_caches & 1) | ||
63 | drop_pagecache(); | ||
64 | if (sysctl_drop_caches & 2) | ||
65 | drop_slab(); | ||
66 | } | ||
67 | return 0; | ||
68 | } | ||
@@ -760,7 +760,7 @@ no_thread_group: | |||
760 | spin_lock(&oldsighand->siglock); | 760 | spin_lock(&oldsighand->siglock); |
761 | spin_lock(&newsighand->siglock); | 761 | spin_lock(&newsighand->siglock); |
762 | 762 | ||
763 | current->sighand = newsighand; | 763 | rcu_assign_pointer(current->sighand, newsighand); |
764 | recalc_sigpending(); | 764 | recalc_sigpending(); |
765 | 765 | ||
766 | spin_unlock(&newsighand->siglock); | 766 | spin_unlock(&newsighand->siglock); |
@@ -768,7 +768,7 @@ no_thread_group: | |||
768 | write_unlock_irq(&tasklist_lock); | 768 | write_unlock_irq(&tasklist_lock); |
769 | 769 | ||
770 | if (atomic_dec_and_test(&oldsighand->count)) | 770 | if (atomic_dec_and_test(&oldsighand->count)) |
771 | kmem_cache_free(sighand_cachep, oldsighand); | 771 | sighand_free(oldsighand); |
772 | } | 772 | } |
773 | 773 | ||
774 | BUG_ON(!thread_group_leader(current)); | 774 | BUG_ON(!thread_group_leader(current)); |
@@ -1462,6 +1462,7 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs) | |||
1462 | if (!(current->signal->flags & SIGNAL_GROUP_EXIT)) { | 1462 | if (!(current->signal->flags & SIGNAL_GROUP_EXIT)) { |
1463 | current->signal->flags = SIGNAL_GROUP_EXIT; | 1463 | current->signal->flags = SIGNAL_GROUP_EXIT; |
1464 | current->signal->group_exit_code = exit_code; | 1464 | current->signal->group_exit_code = exit_code; |
1465 | current->signal->group_stop_count = 0; | ||
1465 | retval = 0; | 1466 | retval = 0; |
1466 | } | 1467 | } |
1467 | spin_unlock_irq(¤t->sighand->siglock); | 1468 | spin_unlock_irq(¤t->sighand->siglock); |
@@ -1477,7 +1478,6 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs) | |||
1477 | * Clear any false indication of pending signals that might | 1478 | * Clear any false indication of pending signals that might |
1478 | * be seen by the filesystem code called to write the core file. | 1479 | * be seen by the filesystem code called to write the core file. |
1479 | */ | 1480 | */ |
1480 | current->signal->group_stop_count = 0; | ||
1481 | clear_thread_flag(TIF_SIGPENDING); | 1481 | clear_thread_flag(TIF_SIGPENDING); |
1482 | 1482 | ||
1483 | if (current->signal->rlim[RLIMIT_CORE].rlim_cur < binfmt->min_coredump) | 1483 | if (current->signal->rlim[RLIMIT_CORE].rlim_cur < binfmt->min_coredump) |
@@ -1505,7 +1505,7 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs) | |||
1505 | goto close_fail; | 1505 | goto close_fail; |
1506 | if (!file->f_op->write) | 1506 | if (!file->f_op->write) |
1507 | goto close_fail; | 1507 | goto close_fail; |
1508 | if (do_truncate(file->f_dentry, 0, file) != 0) | 1508 | if (do_truncate(file->f_dentry, 0, 0, file) != 0) |
1509 | goto close_fail; | 1509 | goto close_fail; |
1510 | 1510 | ||
1511 | retval = binfmt->core_dump(signr, regs, file); | 1511 | retval = binfmt->core_dump(signr, regs, file); |
diff --git a/fs/ext3/ialloc.c b/fs/ext3/ialloc.c index 9e4a24376210..69078079b19c 100644 --- a/fs/ext3/ialloc.c +++ b/fs/ext3/ialloc.c | |||
@@ -651,7 +651,7 @@ struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino) | |||
651 | /* Error cases - e2fsck has already cleaned up for us */ | 651 | /* Error cases - e2fsck has already cleaned up for us */ |
652 | if (ino > max_ino) { | 652 | if (ino > max_ino) { |
653 | ext3_warning(sb, __FUNCTION__, | 653 | ext3_warning(sb, __FUNCTION__, |
654 | "bad orphan ino %lu! e2fsck was run?\n", ino); | 654 | "bad orphan ino %lu! e2fsck was run?", ino); |
655 | goto out; | 655 | goto out; |
656 | } | 656 | } |
657 | 657 | ||
@@ -660,7 +660,7 @@ struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino) | |||
660 | bitmap_bh = read_inode_bitmap(sb, block_group); | 660 | bitmap_bh = read_inode_bitmap(sb, block_group); |
661 | if (!bitmap_bh) { | 661 | if (!bitmap_bh) { |
662 | ext3_warning(sb, __FUNCTION__, | 662 | ext3_warning(sb, __FUNCTION__, |
663 | "inode bitmap error for orphan %lu\n", ino); | 663 | "inode bitmap error for orphan %lu", ino); |
664 | goto out; | 664 | goto out; |
665 | } | 665 | } |
666 | 666 | ||
@@ -672,7 +672,7 @@ struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino) | |||
672 | !(inode = iget(sb, ino)) || is_bad_inode(inode) || | 672 | !(inode = iget(sb, ino)) || is_bad_inode(inode) || |
673 | NEXT_ORPHAN(inode) > max_ino) { | 673 | NEXT_ORPHAN(inode) > max_ino) { |
674 | ext3_warning(sb, __FUNCTION__, | 674 | ext3_warning(sb, __FUNCTION__, |
675 | "bad orphan inode %lu! e2fsck was run?\n", ino); | 675 | "bad orphan inode %lu! e2fsck was run?", ino); |
676 | printk(KERN_NOTICE "ext3_test_bit(bit=%d, block=%llu) = %d\n", | 676 | printk(KERN_NOTICE "ext3_test_bit(bit=%d, block=%llu) = %d\n", |
677 | bit, (unsigned long long)bitmap_bh->b_blocknr, | 677 | bit, (unsigned long long)bitmap_bh->b_blocknr, |
678 | ext3_test_bit(bit, bitmap_bh->b_data)); | 678 | ext3_test_bit(bit, bitmap_bh->b_data)); |
diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c index b3c690a3b54a..af193a304ee5 100644 --- a/fs/ext3/namei.c +++ b/fs/ext3/namei.c | |||
@@ -1476,7 +1476,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, | |||
1476 | if (levels && (dx_get_count(frames->entries) == | 1476 | if (levels && (dx_get_count(frames->entries) == |
1477 | dx_get_limit(frames->entries))) { | 1477 | dx_get_limit(frames->entries))) { |
1478 | ext3_warning(sb, __FUNCTION__, | 1478 | ext3_warning(sb, __FUNCTION__, |
1479 | "Directory index full!\n"); | 1479 | "Directory index full!"); |
1480 | err = -ENOSPC; | 1480 | err = -ENOSPC; |
1481 | goto cleanup; | 1481 | goto cleanup; |
1482 | } | 1482 | } |
diff --git a/fs/ext3/resize.c b/fs/ext3/resize.c index 6104ad310507..1041dab6de2f 100644 --- a/fs/ext3/resize.c +++ b/fs/ext3/resize.c | |||
@@ -31,7 +31,7 @@ static int verify_group_input(struct super_block *sb, | |||
31 | unsigned start = le32_to_cpu(es->s_blocks_count); | 31 | unsigned start = le32_to_cpu(es->s_blocks_count); |
32 | unsigned end = start + input->blocks_count; | 32 | unsigned end = start + input->blocks_count; |
33 | unsigned group = input->group; | 33 | unsigned group = input->group; |
34 | unsigned itend = input->inode_table + EXT3_SB(sb)->s_itb_per_group; | 34 | unsigned itend = input->inode_table + sbi->s_itb_per_group; |
35 | unsigned overhead = ext3_bg_has_super(sb, group) ? | 35 | unsigned overhead = ext3_bg_has_super(sb, group) ? |
36 | (1 + ext3_bg_num_gdb(sb, group) + | 36 | (1 + ext3_bg_num_gdb(sb, group) + |
37 | le16_to_cpu(es->s_reserved_gdt_blocks)) : 0; | 37 | le16_to_cpu(es->s_reserved_gdt_blocks)) : 0; |
@@ -340,7 +340,7 @@ static int verify_reserved_gdb(struct super_block *sb, | |||
340 | while ((grp = ext3_list_backups(sb, &three, &five, &seven)) < end) { | 340 | while ((grp = ext3_list_backups(sb, &three, &five, &seven)) < end) { |
341 | if (le32_to_cpu(*p++) != grp * EXT3_BLOCKS_PER_GROUP(sb) + blk){ | 341 | if (le32_to_cpu(*p++) != grp * EXT3_BLOCKS_PER_GROUP(sb) + blk){ |
342 | ext3_warning(sb, __FUNCTION__, | 342 | ext3_warning(sb, __FUNCTION__, |
343 | "reserved GDT %ld missing grp %d (%ld)\n", | 343 | "reserved GDT %ld missing grp %d (%ld)", |
344 | blk, grp, | 344 | blk, grp, |
345 | grp * EXT3_BLOCKS_PER_GROUP(sb) + blk); | 345 | grp * EXT3_BLOCKS_PER_GROUP(sb) + blk); |
346 | return -EINVAL; | 346 | return -EINVAL; |
@@ -393,7 +393,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, | |||
393 | if (EXT3_SB(sb)->s_sbh->b_blocknr != | 393 | if (EXT3_SB(sb)->s_sbh->b_blocknr != |
394 | le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block)) { | 394 | le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block)) { |
395 | ext3_warning(sb, __FUNCTION__, | 395 | ext3_warning(sb, __FUNCTION__, |
396 | "won't resize using backup superblock at %llu\n", | 396 | "won't resize using backup superblock at %llu", |
397 | (unsigned long long)EXT3_SB(sb)->s_sbh->b_blocknr); | 397 | (unsigned long long)EXT3_SB(sb)->s_sbh->b_blocknr); |
398 | return -EPERM; | 398 | return -EPERM; |
399 | } | 399 | } |
@@ -417,7 +417,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, | |||
417 | data = (__u32 *)dind->b_data; | 417 | data = (__u32 *)dind->b_data; |
418 | if (le32_to_cpu(data[gdb_num % EXT3_ADDR_PER_BLOCK(sb)]) != gdblock) { | 418 | if (le32_to_cpu(data[gdb_num % EXT3_ADDR_PER_BLOCK(sb)]) != gdblock) { |
419 | ext3_warning(sb, __FUNCTION__, | 419 | ext3_warning(sb, __FUNCTION__, |
420 | "new group %u GDT block %lu not reserved\n", | 420 | "new group %u GDT block %lu not reserved", |
421 | input->group, gdblock); | 421 | input->group, gdblock); |
422 | err = -EINVAL; | 422 | err = -EINVAL; |
423 | goto exit_dind; | 423 | goto exit_dind; |
@@ -540,7 +540,7 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode, | |||
540 | for (res = 0; res < reserved_gdb; res++, blk++) { | 540 | for (res = 0; res < reserved_gdb; res++, blk++) { |
541 | if (le32_to_cpu(*data) != blk) { | 541 | if (le32_to_cpu(*data) != blk) { |
542 | ext3_warning(sb, __FUNCTION__, | 542 | ext3_warning(sb, __FUNCTION__, |
543 | "reserved block %lu not at offset %ld\n", | 543 | "reserved block %lu not at offset %ld", |
544 | blk, (long)(data - (__u32 *)dind->b_data)); | 544 | blk, (long)(data - (__u32 *)dind->b_data)); |
545 | err = -EINVAL; | 545 | err = -EINVAL; |
546 | goto exit_bh; | 546 | goto exit_bh; |
@@ -683,7 +683,7 @@ exit_err: | |||
683 | if (err) { | 683 | if (err) { |
684 | ext3_warning(sb, __FUNCTION__, | 684 | ext3_warning(sb, __FUNCTION__, |
685 | "can't update backup for group %d (err %d), " | 685 | "can't update backup for group %d (err %d), " |
686 | "forcing fsck on next reboot\n", group, err); | 686 | "forcing fsck on next reboot", group, err); |
687 | sbi->s_mount_state &= ~EXT3_VALID_FS; | 687 | sbi->s_mount_state &= ~EXT3_VALID_FS; |
688 | sbi->s_es->s_state &= ~cpu_to_le16(EXT3_VALID_FS); | 688 | sbi->s_es->s_state &= ~cpu_to_le16(EXT3_VALID_FS); |
689 | mark_buffer_dirty(sbi->s_sbh); | 689 | mark_buffer_dirty(sbi->s_sbh); |
@@ -722,7 +722,7 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) | |||
722 | if (gdb_off == 0 && !EXT3_HAS_RO_COMPAT_FEATURE(sb, | 722 | if (gdb_off == 0 && !EXT3_HAS_RO_COMPAT_FEATURE(sb, |
723 | EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)) { | 723 | EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)) { |
724 | ext3_warning(sb, __FUNCTION__, | 724 | ext3_warning(sb, __FUNCTION__, |
725 | "Can't resize non-sparse filesystem further\n"); | 725 | "Can't resize non-sparse filesystem further"); |
726 | return -EPERM; | 726 | return -EPERM; |
727 | } | 727 | } |
728 | 728 | ||
@@ -730,13 +730,13 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) | |||
730 | if (!EXT3_HAS_COMPAT_FEATURE(sb, | 730 | if (!EXT3_HAS_COMPAT_FEATURE(sb, |
731 | EXT3_FEATURE_COMPAT_RESIZE_INODE)){ | 731 | EXT3_FEATURE_COMPAT_RESIZE_INODE)){ |
732 | ext3_warning(sb, __FUNCTION__, | 732 | ext3_warning(sb, __FUNCTION__, |
733 | "No reserved GDT blocks, can't resize\n"); | 733 | "No reserved GDT blocks, can't resize"); |
734 | return -EPERM; | 734 | return -EPERM; |
735 | } | 735 | } |
736 | inode = iget(sb, EXT3_RESIZE_INO); | 736 | inode = iget(sb, EXT3_RESIZE_INO); |
737 | if (!inode || is_bad_inode(inode)) { | 737 | if (!inode || is_bad_inode(inode)) { |
738 | ext3_warning(sb, __FUNCTION__, | 738 | ext3_warning(sb, __FUNCTION__, |
739 | "Error opening resize inode\n"); | 739 | "Error opening resize inode"); |
740 | iput(inode); | 740 | iput(inode); |
741 | return -ENOENT; | 741 | return -ENOENT; |
742 | } | 742 | } |
@@ -764,9 +764,9 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) | |||
764 | } | 764 | } |
765 | 765 | ||
766 | lock_super(sb); | 766 | lock_super(sb); |
767 | if (input->group != EXT3_SB(sb)->s_groups_count) { | 767 | if (input->group != sbi->s_groups_count) { |
768 | ext3_warning(sb, __FUNCTION__, | 768 | ext3_warning(sb, __FUNCTION__, |
769 | "multiple resizers run on filesystem!\n"); | 769 | "multiple resizers run on filesystem!"); |
770 | err = -EBUSY; | 770 | err = -EBUSY; |
771 | goto exit_journal; | 771 | goto exit_journal; |
772 | } | 772 | } |
@@ -799,7 +799,7 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) | |||
799 | * data. So we need to be careful to set all of the relevant | 799 | * data. So we need to be careful to set all of the relevant |
800 | * group descriptor data etc. *before* we enable the group. | 800 | * group descriptor data etc. *before* we enable the group. |
801 | * | 801 | * |
802 | * The key field here is EXT3_SB(sb)->s_groups_count: as long as | 802 | * The key field here is sbi->s_groups_count: as long as |
803 | * that retains its old value, nobody is going to access the new | 803 | * that retains its old value, nobody is going to access the new |
804 | * group. | 804 | * group. |
805 | * | 805 | * |
@@ -859,7 +859,7 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) | |||
859 | smp_wmb(); | 859 | smp_wmb(); |
860 | 860 | ||
861 | /* Update the global fs size fields */ | 861 | /* Update the global fs size fields */ |
862 | EXT3_SB(sb)->s_groups_count++; | 862 | sbi->s_groups_count++; |
863 | 863 | ||
864 | ext3_journal_dirty_metadata(handle, primary); | 864 | ext3_journal_dirty_metadata(handle, primary); |
865 | 865 | ||
@@ -874,7 +874,7 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) | |||
874 | percpu_counter_mod(&sbi->s_freeinodes_counter, | 874 | percpu_counter_mod(&sbi->s_freeinodes_counter, |
875 | EXT3_INODES_PER_GROUP(sb)); | 875 | EXT3_INODES_PER_GROUP(sb)); |
876 | 876 | ||
877 | ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); | 877 | ext3_journal_dirty_metadata(handle, sbi->s_sbh); |
878 | sb->s_dirt = 1; | 878 | sb->s_dirt = 1; |
879 | 879 | ||
880 | exit_journal: | 880 | exit_journal: |
@@ -937,7 +937,7 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es, | |||
937 | 937 | ||
938 | if (last == 0) { | 938 | if (last == 0) { |
939 | ext3_warning(sb, __FUNCTION__, | 939 | ext3_warning(sb, __FUNCTION__, |
940 | "need to use ext2online to resize further\n"); | 940 | "need to use ext2online to resize further"); |
941 | return -EPERM; | 941 | return -EPERM; |
942 | } | 942 | } |
943 | 943 | ||
@@ -973,7 +973,7 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es, | |||
973 | lock_super(sb); | 973 | lock_super(sb); |
974 | if (o_blocks_count != le32_to_cpu(es->s_blocks_count)) { | 974 | if (o_blocks_count != le32_to_cpu(es->s_blocks_count)) { |
975 | ext3_warning(sb, __FUNCTION__, | 975 | ext3_warning(sb, __FUNCTION__, |
976 | "multiple resizers run on filesystem!\n"); | 976 | "multiple resizers run on filesystem!"); |
977 | err = -EBUSY; | 977 | err = -EBUSY; |
978 | goto exit_put; | 978 | goto exit_put; |
979 | } | 979 | } |
diff --git a/fs/ext3/super.c b/fs/ext3/super.c index 4e6730622d90..7c45acf94589 100644 --- a/fs/ext3/super.c +++ b/fs/ext3/super.c | |||
@@ -43,7 +43,8 @@ | |||
43 | #include "acl.h" | 43 | #include "acl.h" |
44 | #include "namei.h" | 44 | #include "namei.h" |
45 | 45 | ||
46 | static int ext3_load_journal(struct super_block *, struct ext3_super_block *); | 46 | static int ext3_load_journal(struct super_block *, struct ext3_super_block *, |
47 | unsigned long journal_devnum); | ||
47 | static int ext3_create_journal(struct super_block *, struct ext3_super_block *, | 48 | static int ext3_create_journal(struct super_block *, struct ext3_super_block *, |
48 | int); | 49 | int); |
49 | static void ext3_commit_super (struct super_block * sb, | 50 | static void ext3_commit_super (struct super_block * sb, |
@@ -628,7 +629,7 @@ enum { | |||
628 | Opt_nouid32, Opt_nocheck, Opt_debug, Opt_oldalloc, Opt_orlov, | 629 | Opt_nouid32, Opt_nocheck, Opt_debug, Opt_oldalloc, Opt_orlov, |
629 | Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl, | 630 | Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl, |
630 | Opt_reservation, Opt_noreservation, Opt_noload, Opt_nobh, | 631 | Opt_reservation, Opt_noreservation, Opt_noload, Opt_nobh, |
631 | Opt_commit, Opt_journal_update, Opt_journal_inum, | 632 | Opt_commit, Opt_journal_update, Opt_journal_inum, Opt_journal_dev, |
632 | Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, | 633 | Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, |
633 | Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, | 634 | Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, |
634 | Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota, | 635 | Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota, |
@@ -666,6 +667,7 @@ static match_table_t tokens = { | |||
666 | {Opt_commit, "commit=%u"}, | 667 | {Opt_commit, "commit=%u"}, |
667 | {Opt_journal_update, "journal=update"}, | 668 | {Opt_journal_update, "journal=update"}, |
668 | {Opt_journal_inum, "journal=%u"}, | 669 | {Opt_journal_inum, "journal=%u"}, |
670 | {Opt_journal_dev, "journal_dev=%u"}, | ||
669 | {Opt_abort, "abort"}, | 671 | {Opt_abort, "abort"}, |
670 | {Opt_data_journal, "data=journal"}, | 672 | {Opt_data_journal, "data=journal"}, |
671 | {Opt_data_ordered, "data=ordered"}, | 673 | {Opt_data_ordered, "data=ordered"}, |
@@ -705,8 +707,9 @@ static unsigned long get_sb_block(void **data) | |||
705 | return sb_block; | 707 | return sb_block; |
706 | } | 708 | } |
707 | 709 | ||
708 | static int parse_options (char * options, struct super_block *sb, | 710 | static int parse_options (char *options, struct super_block *sb, |
709 | unsigned long * inum, unsigned long *n_blocks_count, int is_remount) | 711 | unsigned long *inum, unsigned long *journal_devnum, |
712 | unsigned long *n_blocks_count, int is_remount) | ||
710 | { | 713 | { |
711 | struct ext3_sb_info *sbi = EXT3_SB(sb); | 714 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
712 | char * p; | 715 | char * p; |
@@ -839,6 +842,16 @@ static int parse_options (char * options, struct super_block *sb, | |||
839 | return 0; | 842 | return 0; |
840 | *inum = option; | 843 | *inum = option; |
841 | break; | 844 | break; |
845 | case Opt_journal_dev: | ||
846 | if (is_remount) { | ||
847 | printk(KERN_ERR "EXT3-fs: cannot specify " | ||
848 | "journal on remount\n"); | ||
849 | return 0; | ||
850 | } | ||
851 | if (match_int(&args[0], &option)) | ||
852 | return 0; | ||
853 | *journal_devnum = option; | ||
854 | break; | ||
842 | case Opt_noload: | 855 | case Opt_noload: |
843 | set_opt (sbi->s_mount_opt, NOLOAD); | 856 | set_opt (sbi->s_mount_opt, NOLOAD); |
844 | break; | 857 | break; |
@@ -1331,6 +1344,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) | |||
1331 | unsigned long logic_sb_block; | 1344 | unsigned long logic_sb_block; |
1332 | unsigned long offset = 0; | 1345 | unsigned long offset = 0; |
1333 | unsigned long journal_inum = 0; | 1346 | unsigned long journal_inum = 0; |
1347 | unsigned long journal_devnum = 0; | ||
1334 | unsigned long def_mount_opts; | 1348 | unsigned long def_mount_opts; |
1335 | struct inode *root; | 1349 | struct inode *root; |
1336 | int blocksize; | 1350 | int blocksize; |
@@ -1411,7 +1425,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) | |||
1411 | 1425 | ||
1412 | set_opt(sbi->s_mount_opt, RESERVATION); | 1426 | set_opt(sbi->s_mount_opt, RESERVATION); |
1413 | 1427 | ||
1414 | if (!parse_options ((char *) data, sb, &journal_inum, NULL, 0)) | 1428 | if (!parse_options ((char *) data, sb, &journal_inum, &journal_devnum, |
1429 | NULL, 0)) | ||
1415 | goto failed_mount; | 1430 | goto failed_mount; |
1416 | 1431 | ||
1417 | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | | 1432 | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | |
@@ -1622,7 +1637,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) | |||
1622 | */ | 1637 | */ |
1623 | if (!test_opt(sb, NOLOAD) && | 1638 | if (!test_opt(sb, NOLOAD) && |
1624 | EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) { | 1639 | EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) { |
1625 | if (ext3_load_journal(sb, es)) | 1640 | if (ext3_load_journal(sb, es, journal_devnum)) |
1626 | goto failed_mount2; | 1641 | goto failed_mount2; |
1627 | } else if (journal_inum) { | 1642 | } else if (journal_inum) { |
1628 | if (ext3_create_journal(sb, es, journal_inum)) | 1643 | if (ext3_create_journal(sb, es, journal_inum)) |
@@ -1902,15 +1917,24 @@ out_bdev: | |||
1902 | return NULL; | 1917 | return NULL; |
1903 | } | 1918 | } |
1904 | 1919 | ||
1905 | static int ext3_load_journal(struct super_block * sb, | 1920 | static int ext3_load_journal(struct super_block *sb, |
1906 | struct ext3_super_block * es) | 1921 | struct ext3_super_block *es, |
1922 | unsigned long journal_devnum) | ||
1907 | { | 1923 | { |
1908 | journal_t *journal; | 1924 | journal_t *journal; |
1909 | int journal_inum = le32_to_cpu(es->s_journal_inum); | 1925 | int journal_inum = le32_to_cpu(es->s_journal_inum); |
1910 | dev_t journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev)); | 1926 | dev_t journal_dev; |
1911 | int err = 0; | 1927 | int err = 0; |
1912 | int really_read_only; | 1928 | int really_read_only; |
1913 | 1929 | ||
1930 | if (journal_devnum && | ||
1931 | journal_devnum != le32_to_cpu(es->s_journal_dev)) { | ||
1932 | printk(KERN_INFO "EXT3-fs: external journal device major/minor " | ||
1933 | "numbers have changed\n"); | ||
1934 | journal_dev = new_decode_dev(journal_devnum); | ||
1935 | } else | ||
1936 | journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev)); | ||
1937 | |||
1914 | really_read_only = bdev_read_only(sb->s_bdev); | 1938 | really_read_only = bdev_read_only(sb->s_bdev); |
1915 | 1939 | ||
1916 | /* | 1940 | /* |
@@ -1969,6 +1993,16 @@ static int ext3_load_journal(struct super_block * sb, | |||
1969 | 1993 | ||
1970 | EXT3_SB(sb)->s_journal = journal; | 1994 | EXT3_SB(sb)->s_journal = journal; |
1971 | ext3_clear_journal_err(sb, es); | 1995 | ext3_clear_journal_err(sb, es); |
1996 | |||
1997 | if (journal_devnum && | ||
1998 | journal_devnum != le32_to_cpu(es->s_journal_dev)) { | ||
1999 | es->s_journal_dev = cpu_to_le32(journal_devnum); | ||
2000 | sb->s_dirt = 1; | ||
2001 | |||
2002 | /* Make sure we flush the recovery flag to disk. */ | ||
2003 | ext3_commit_super(sb, es, 1); | ||
2004 | } | ||
2005 | |||
1972 | return 0; | 2006 | return 0; |
1973 | } | 2007 | } |
1974 | 2008 | ||
@@ -2197,7 +2231,7 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data) | |||
2197 | /* | 2231 | /* |
2198 | * Allow the "check" option to be passed as a remount option. | 2232 | * Allow the "check" option to be passed as a remount option. |
2199 | */ | 2233 | */ |
2200 | if (!parse_options(data, sb, NULL, &n_blocks_count, 1)) { | 2234 | if (!parse_options(data, sb, NULL, NULL, &n_blocks_count, 1)) { |
2201 | err = -EINVAL; | 2235 | err = -EINVAL; |
2202 | goto restore_opts; | 2236 | goto restore_opts; |
2203 | } | 2237 | } |
diff --git a/fs/fat/cache.c b/fs/fat/cache.c index 77c24fcf712a..1acc941245fb 100644 --- a/fs/fat/cache.c +++ b/fs/fat/cache.c | |||
@@ -295,7 +295,8 @@ static int fat_bmap_cluster(struct inode *inode, int cluster) | |||
295 | return dclus; | 295 | return dclus; |
296 | } | 296 | } |
297 | 297 | ||
298 | int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys) | 298 | int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys, |
299 | unsigned long *mapped_blocks) | ||
299 | { | 300 | { |
300 | struct super_block *sb = inode->i_sb; | 301 | struct super_block *sb = inode->i_sb; |
301 | struct msdos_sb_info *sbi = MSDOS_SB(sb); | 302 | struct msdos_sb_info *sbi = MSDOS_SB(sb); |
@@ -303,9 +304,12 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys) | |||
303 | int cluster, offset; | 304 | int cluster, offset; |
304 | 305 | ||
305 | *phys = 0; | 306 | *phys = 0; |
307 | *mapped_blocks = 0; | ||
306 | if ((sbi->fat_bits != 32) && (inode->i_ino == MSDOS_ROOT_INO)) { | 308 | if ((sbi->fat_bits != 32) && (inode->i_ino == MSDOS_ROOT_INO)) { |
307 | if (sector < (sbi->dir_entries >> sbi->dir_per_block_bits)) | 309 | if (sector < (sbi->dir_entries >> sbi->dir_per_block_bits)) { |
308 | *phys = sector + sbi->dir_start; | 310 | *phys = sector + sbi->dir_start; |
311 | *mapped_blocks = 1; | ||
312 | } | ||
309 | return 0; | 313 | return 0; |
310 | } | 314 | } |
311 | last_block = (MSDOS_I(inode)->mmu_private + (sb->s_blocksize - 1)) | 315 | last_block = (MSDOS_I(inode)->mmu_private + (sb->s_blocksize - 1)) |
@@ -318,7 +322,11 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys) | |||
318 | cluster = fat_bmap_cluster(inode, cluster); | 322 | cluster = fat_bmap_cluster(inode, cluster); |
319 | if (cluster < 0) | 323 | if (cluster < 0) |
320 | return cluster; | 324 | return cluster; |
321 | else if (cluster) | 325 | else if (cluster) { |
322 | *phys = fat_clus_to_blknr(sbi, cluster) + offset; | 326 | *phys = fat_clus_to_blknr(sbi, cluster) + offset; |
327 | *mapped_blocks = sbi->sec_per_clus - offset; | ||
328 | if (*mapped_blocks > last_block - sector) | ||
329 | *mapped_blocks = last_block - sector; | ||
330 | } | ||
323 | return 0; | 331 | return 0; |
324 | } | 332 | } |
diff --git a/fs/fat/dir.c b/fs/fat/dir.c index ba824964b9bb..eef1b81aa294 100644 --- a/fs/fat/dir.c +++ b/fs/fat/dir.c | |||
@@ -45,8 +45,8 @@ static inline void fat_dir_readahead(struct inode *dir, sector_t iblock, | |||
45 | if ((sbi->fat_bits != 32) && (dir->i_ino == MSDOS_ROOT_INO)) | 45 | if ((sbi->fat_bits != 32) && (dir->i_ino == MSDOS_ROOT_INO)) |
46 | return; | 46 | return; |
47 | 47 | ||
48 | bh = sb_getblk(sb, phys); | 48 | bh = sb_find_get_block(sb, phys); |
49 | if (bh && !buffer_uptodate(bh)) { | 49 | if (bh == NULL || !buffer_uptodate(bh)) { |
50 | for (sec = 0; sec < sbi->sec_per_clus; sec++) | 50 | for (sec = 0; sec < sbi->sec_per_clus; sec++) |
51 | sb_breadahead(sb, phys + sec); | 51 | sb_breadahead(sb, phys + sec); |
52 | } | 52 | } |
@@ -68,8 +68,8 @@ static int fat__get_entry(struct inode *dir, loff_t *pos, | |||
68 | { | 68 | { |
69 | struct super_block *sb = dir->i_sb; | 69 | struct super_block *sb = dir->i_sb; |
70 | sector_t phys, iblock; | 70 | sector_t phys, iblock; |
71 | int offset; | 71 | unsigned long mapped_blocks; |
72 | int err; | 72 | int err, offset; |
73 | 73 | ||
74 | next: | 74 | next: |
75 | if (*bh) | 75 | if (*bh) |
@@ -77,7 +77,7 @@ next: | |||
77 | 77 | ||
78 | *bh = NULL; | 78 | *bh = NULL; |
79 | iblock = *pos >> sb->s_blocksize_bits; | 79 | iblock = *pos >> sb->s_blocksize_bits; |
80 | err = fat_bmap(dir, iblock, &phys); | 80 | err = fat_bmap(dir, iblock, &phys, &mapped_blocks); |
81 | if (err || !phys) | 81 | if (err || !phys) |
82 | return -1; /* beyond EOF or error */ | 82 | return -1; /* beyond EOF or error */ |
83 | 83 | ||
@@ -418,7 +418,7 @@ EODir: | |||
418 | return err; | 418 | return err; |
419 | } | 419 | } |
420 | 420 | ||
421 | EXPORT_SYMBOL(fat_search_long); | 421 | EXPORT_SYMBOL_GPL(fat_search_long); |
422 | 422 | ||
423 | struct fat_ioctl_filldir_callback { | 423 | struct fat_ioctl_filldir_callback { |
424 | struct dirent __user *dirent; | 424 | struct dirent __user *dirent; |
@@ -780,7 +780,7 @@ int fat_get_dotdot_entry(struct inode *dir, struct buffer_head **bh, | |||
780 | return -ENOENT; | 780 | return -ENOENT; |
781 | } | 781 | } |
782 | 782 | ||
783 | EXPORT_SYMBOL(fat_get_dotdot_entry); | 783 | EXPORT_SYMBOL_GPL(fat_get_dotdot_entry); |
784 | 784 | ||
785 | /* See if directory is empty */ | 785 | /* See if directory is empty */ |
786 | int fat_dir_empty(struct inode *dir) | 786 | int fat_dir_empty(struct inode *dir) |
@@ -803,7 +803,7 @@ int fat_dir_empty(struct inode *dir) | |||
803 | return result; | 803 | return result; |
804 | } | 804 | } |
805 | 805 | ||
806 | EXPORT_SYMBOL(fat_dir_empty); | 806 | EXPORT_SYMBOL_GPL(fat_dir_empty); |
807 | 807 | ||
808 | /* | 808 | /* |
809 | * fat_subdirs counts the number of sub-directories of dir. It can be run | 809 | * fat_subdirs counts the number of sub-directories of dir. It can be run |
@@ -849,7 +849,7 @@ int fat_scan(struct inode *dir, const unsigned char *name, | |||
849 | return -ENOENT; | 849 | return -ENOENT; |
850 | } | 850 | } |
851 | 851 | ||
852 | EXPORT_SYMBOL(fat_scan); | 852 | EXPORT_SYMBOL_GPL(fat_scan); |
853 | 853 | ||
854 | static int __fat_remove_entries(struct inode *dir, loff_t pos, int nr_slots) | 854 | static int __fat_remove_entries(struct inode *dir, loff_t pos, int nr_slots) |
855 | { | 855 | { |
@@ -936,7 +936,7 @@ int fat_remove_entries(struct inode *dir, struct fat_slot_info *sinfo) | |||
936 | return 0; | 936 | return 0; |
937 | } | 937 | } |
938 | 938 | ||
939 | EXPORT_SYMBOL(fat_remove_entries); | 939 | EXPORT_SYMBOL_GPL(fat_remove_entries); |
940 | 940 | ||
941 | static int fat_zeroed_cluster(struct inode *dir, sector_t blknr, int nr_used, | 941 | static int fat_zeroed_cluster(struct inode *dir, sector_t blknr, int nr_used, |
942 | struct buffer_head **bhs, int nr_bhs) | 942 | struct buffer_head **bhs, int nr_bhs) |
@@ -1048,7 +1048,7 @@ error: | |||
1048 | return err; | 1048 | return err; |
1049 | } | 1049 | } |
1050 | 1050 | ||
1051 | EXPORT_SYMBOL(fat_alloc_new_dir); | 1051 | EXPORT_SYMBOL_GPL(fat_alloc_new_dir); |
1052 | 1052 | ||
1053 | static int fat_add_new_entries(struct inode *dir, void *slots, int nr_slots, | 1053 | static int fat_add_new_entries(struct inode *dir, void *slots, int nr_slots, |
1054 | int *nr_cluster, struct msdos_dir_entry **de, | 1054 | int *nr_cluster, struct msdos_dir_entry **de, |
@@ -1264,4 +1264,4 @@ error_remove: | |||
1264 | return err; | 1264 | return err; |
1265 | } | 1265 | } |
1266 | 1266 | ||
1267 | EXPORT_SYMBOL(fat_add_entries); | 1267 | EXPORT_SYMBOL_GPL(fat_add_entries); |
diff --git a/fs/fat/fatent.c b/fs/fat/fatent.c index 4164cd54c4d1..a1a9e0451217 100644 --- a/fs/fat/fatent.c +++ b/fs/fat/fatent.c | |||
@@ -476,6 +476,7 @@ int fat_alloc_clusters(struct inode *inode, int *cluster, int nr_cluster) | |||
476 | sbi->prev_free = entry; | 476 | sbi->prev_free = entry; |
477 | if (sbi->free_clusters != -1) | 477 | if (sbi->free_clusters != -1) |
478 | sbi->free_clusters--; | 478 | sbi->free_clusters--; |
479 | sb->s_dirt = 1; | ||
479 | 480 | ||
480 | cluster[idx_clus] = entry; | 481 | cluster[idx_clus] = entry; |
481 | idx_clus++; | 482 | idx_clus++; |
@@ -496,6 +497,7 @@ int fat_alloc_clusters(struct inode *inode, int *cluster, int nr_cluster) | |||
496 | 497 | ||
497 | /* Couldn't allocate the free entries */ | 498 | /* Couldn't allocate the free entries */ |
498 | sbi->free_clusters = 0; | 499 | sbi->free_clusters = 0; |
500 | sb->s_dirt = 1; | ||
499 | err = -ENOSPC; | 501 | err = -ENOSPC; |
500 | 502 | ||
501 | out: | 503 | out: |
@@ -509,7 +511,6 @@ out: | |||
509 | } | 511 | } |
510 | for (i = 0; i < nr_bhs; i++) | 512 | for (i = 0; i < nr_bhs; i++) |
511 | brelse(bhs[i]); | 513 | brelse(bhs[i]); |
512 | fat_clusters_flush(sb); | ||
513 | 514 | ||
514 | if (err && idx_clus) | 515 | if (err && idx_clus) |
515 | fat_free_clusters(inode, cluster[0]); | 516 | fat_free_clusters(inode, cluster[0]); |
@@ -542,8 +543,10 @@ int fat_free_clusters(struct inode *inode, int cluster) | |||
542 | } | 543 | } |
543 | 544 | ||
544 | ops->ent_put(&fatent, FAT_ENT_FREE); | 545 | ops->ent_put(&fatent, FAT_ENT_FREE); |
545 | if (sbi->free_clusters != -1) | 546 | if (sbi->free_clusters != -1) { |
546 | sbi->free_clusters++; | 547 | sbi->free_clusters++; |
548 | sb->s_dirt = 1; | ||
549 | } | ||
547 | 550 | ||
548 | if (nr_bhs + fatent.nr_bhs > MAX_BUF_PER_PAGE) { | 551 | if (nr_bhs + fatent.nr_bhs > MAX_BUF_PER_PAGE) { |
549 | if (sb->s_flags & MS_SYNCHRONOUS) { | 552 | if (sb->s_flags & MS_SYNCHRONOUS) { |
@@ -578,7 +581,7 @@ error: | |||
578 | return err; | 581 | return err; |
579 | } | 582 | } |
580 | 583 | ||
581 | EXPORT_SYMBOL(fat_free_clusters); | 584 | EXPORT_SYMBOL_GPL(fat_free_clusters); |
582 | 585 | ||
583 | int fat_count_free_clusters(struct super_block *sb) | 586 | int fat_count_free_clusters(struct super_block *sb) |
584 | { | 587 | { |
@@ -605,6 +608,7 @@ int fat_count_free_clusters(struct super_block *sb) | |||
605 | } while (fat_ent_next(sbi, &fatent)); | 608 | } while (fat_ent_next(sbi, &fatent)); |
606 | } | 609 | } |
607 | sbi->free_clusters = free; | 610 | sbi->free_clusters = free; |
611 | sb->s_dirt = 1; | ||
608 | fatent_brelse(&fatent); | 612 | fatent_brelse(&fatent); |
609 | out: | 613 | out: |
610 | unlock_fat(sbi); | 614 | unlock_fat(sbi); |
diff --git a/fs/fat/file.c b/fs/fat/file.c index 7134403d5be2..9b07c328a6fc 100644 --- a/fs/fat/file.c +++ b/fs/fat/file.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/msdos_fs.h> | 11 | #include <linux/msdos_fs.h> |
12 | #include <linux/smp_lock.h> | 12 | #include <linux/smp_lock.h> |
13 | #include <linux/buffer_head.h> | 13 | #include <linux/buffer_head.h> |
14 | #include <linux/writeback.h> | ||
14 | 15 | ||
15 | int fat_generic_ioctl(struct inode *inode, struct file *filp, | 16 | int fat_generic_ioctl(struct inode *inode, struct file *filp, |
16 | unsigned int cmd, unsigned long arg) | 17 | unsigned int cmd, unsigned long arg) |
@@ -124,6 +125,24 @@ struct file_operations fat_file_operations = { | |||
124 | .sendfile = generic_file_sendfile, | 125 | .sendfile = generic_file_sendfile, |
125 | }; | 126 | }; |
126 | 127 | ||
128 | static int fat_cont_expand(struct inode *inode, loff_t size) | ||
129 | { | ||
130 | struct address_space *mapping = inode->i_mapping; | ||
131 | loff_t start = inode->i_size, count = size - inode->i_size; | ||
132 | int err; | ||
133 | |||
134 | err = generic_cont_expand_simple(inode, size); | ||
135 | if (err) | ||
136 | goto out; | ||
137 | |||
138 | inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC; | ||
139 | mark_inode_dirty(inode); | ||
140 | if (IS_SYNC(inode)) | ||
141 | err = sync_page_range_nolock(inode, mapping, start, count); | ||
142 | out: | ||
143 | return err; | ||
144 | } | ||
145 | |||
127 | int fat_notify_change(struct dentry *dentry, struct iattr *attr) | 146 | int fat_notify_change(struct dentry *dentry, struct iattr *attr) |
128 | { | 147 | { |
129 | struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb); | 148 | struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb); |
@@ -132,11 +151,17 @@ int fat_notify_change(struct dentry *dentry, struct iattr *attr) | |||
132 | 151 | ||
133 | lock_kernel(); | 152 | lock_kernel(); |
134 | 153 | ||
135 | /* FAT cannot truncate to a longer file */ | 154 | /* |
155 | * Expand the file. Since inode_setattr() updates ->i_size | ||
156 | * before calling the ->truncate(), but FAT needs to fill the | ||
157 | * hole before it. | ||
158 | */ | ||
136 | if (attr->ia_valid & ATTR_SIZE) { | 159 | if (attr->ia_valid & ATTR_SIZE) { |
137 | if (attr->ia_size > inode->i_size) { | 160 | if (attr->ia_size > inode->i_size) { |
138 | error = -EPERM; | 161 | error = fat_cont_expand(inode, attr->ia_size); |
139 | goto out; | 162 | if (error || attr->ia_valid == ATTR_SIZE) |
163 | goto out; | ||
164 | attr->ia_valid &= ~ATTR_SIZE; | ||
140 | } | 165 | } |
141 | } | 166 | } |
142 | 167 | ||
@@ -173,7 +198,7 @@ out: | |||
173 | return error; | 198 | return error; |
174 | } | 199 | } |
175 | 200 | ||
176 | EXPORT_SYMBOL(fat_notify_change); | 201 | EXPORT_SYMBOL_GPL(fat_notify_change); |
177 | 202 | ||
178 | /* Free all clusters after the skip'th cluster. */ | 203 | /* Free all clusters after the skip'th cluster. */ |
179 | static int fat_free(struct inode *inode, int skip) | 204 | static int fat_free(struct inode *inode, int skip) |
diff --git a/fs/fat/inode.c b/fs/fat/inode.c index a0f9b9fe1307..e7f4aa7fc686 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c | |||
@@ -18,10 +18,12 @@ | |||
18 | #include <linux/seq_file.h> | 18 | #include <linux/seq_file.h> |
19 | #include <linux/msdos_fs.h> | 19 | #include <linux/msdos_fs.h> |
20 | #include <linux/pagemap.h> | 20 | #include <linux/pagemap.h> |
21 | #include <linux/mpage.h> | ||
21 | #include <linux/buffer_head.h> | 22 | #include <linux/buffer_head.h> |
22 | #include <linux/mount.h> | 23 | #include <linux/mount.h> |
23 | #include <linux/vfs.h> | 24 | #include <linux/vfs.h> |
24 | #include <linux/parser.h> | 25 | #include <linux/parser.h> |
26 | #include <linux/uio.h> | ||
25 | #include <asm/unaligned.h> | 27 | #include <asm/unaligned.h> |
26 | 28 | ||
27 | #ifndef CONFIG_FAT_DEFAULT_IOCHARSET | 29 | #ifndef CONFIG_FAT_DEFAULT_IOCHARSET |
@@ -48,51 +50,97 @@ static int fat_add_cluster(struct inode *inode) | |||
48 | return err; | 50 | return err; |
49 | } | 51 | } |
50 | 52 | ||
51 | static int fat_get_block(struct inode *inode, sector_t iblock, | 53 | static int __fat_get_blocks(struct inode *inode, sector_t iblock, |
52 | struct buffer_head *bh_result, int create) | 54 | unsigned long *max_blocks, |
55 | struct buffer_head *bh_result, int create) | ||
53 | { | 56 | { |
54 | struct super_block *sb = inode->i_sb; | 57 | struct super_block *sb = inode->i_sb; |
58 | struct msdos_sb_info *sbi = MSDOS_SB(sb); | ||
55 | sector_t phys; | 59 | sector_t phys; |
56 | int err; | 60 | unsigned long mapped_blocks; |
61 | int err, offset; | ||
57 | 62 | ||
58 | err = fat_bmap(inode, iblock, &phys); | 63 | err = fat_bmap(inode, iblock, &phys, &mapped_blocks); |
59 | if (err) | 64 | if (err) |
60 | return err; | 65 | return err; |
61 | if (phys) { | 66 | if (phys) { |
62 | map_bh(bh_result, sb, phys); | 67 | map_bh(bh_result, sb, phys); |
68 | *max_blocks = min(mapped_blocks, *max_blocks); | ||
63 | return 0; | 69 | return 0; |
64 | } | 70 | } |
65 | if (!create) | 71 | if (!create) |
66 | return 0; | 72 | return 0; |
73 | |||
67 | if (iblock != MSDOS_I(inode)->mmu_private >> sb->s_blocksize_bits) { | 74 | if (iblock != MSDOS_I(inode)->mmu_private >> sb->s_blocksize_bits) { |
68 | fat_fs_panic(sb, "corrupted file size (i_pos %lld, %lld)", | 75 | fat_fs_panic(sb, "corrupted file size (i_pos %lld, %lld)", |
69 | MSDOS_I(inode)->i_pos, MSDOS_I(inode)->mmu_private); | 76 | MSDOS_I(inode)->i_pos, MSDOS_I(inode)->mmu_private); |
70 | return -EIO; | 77 | return -EIO; |
71 | } | 78 | } |
72 | if (!((unsigned long)iblock & (MSDOS_SB(sb)->sec_per_clus - 1))) { | 79 | |
80 | offset = (unsigned long)iblock & (sbi->sec_per_clus - 1); | ||
81 | if (!offset) { | ||
82 | /* TODO: multiple cluster allocation would be desirable. */ | ||
73 | err = fat_add_cluster(inode); | 83 | err = fat_add_cluster(inode); |
74 | if (err) | 84 | if (err) |
75 | return err; | 85 | return err; |
76 | } | 86 | } |
77 | MSDOS_I(inode)->mmu_private += sb->s_blocksize; | 87 | /* available blocks on this cluster */ |
78 | err = fat_bmap(inode, iblock, &phys); | 88 | mapped_blocks = sbi->sec_per_clus - offset; |
89 | |||
90 | *max_blocks = min(mapped_blocks, *max_blocks); | ||
91 | MSDOS_I(inode)->mmu_private += *max_blocks << sb->s_blocksize_bits; | ||
92 | |||
93 | err = fat_bmap(inode, iblock, &phys, &mapped_blocks); | ||
79 | if (err) | 94 | if (err) |
80 | return err; | 95 | return err; |
81 | if (!phys) | 96 | BUG_ON(!phys); |
82 | BUG(); | 97 | BUG_ON(*max_blocks != mapped_blocks); |
83 | set_buffer_new(bh_result); | 98 | set_buffer_new(bh_result); |
84 | map_bh(bh_result, sb, phys); | 99 | map_bh(bh_result, sb, phys); |
85 | return 0; | 100 | return 0; |
86 | } | 101 | } |
87 | 102 | ||
103 | static int fat_get_blocks(struct inode *inode, sector_t iblock, | ||
104 | unsigned long max_blocks, | ||
105 | struct buffer_head *bh_result, int create) | ||
106 | { | ||
107 | struct super_block *sb = inode->i_sb; | ||
108 | int err; | ||
109 | |||
110 | err = __fat_get_blocks(inode, iblock, &max_blocks, bh_result, create); | ||
111 | if (err) | ||
112 | return err; | ||
113 | bh_result->b_size = max_blocks << sb->s_blocksize_bits; | ||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | static int fat_get_block(struct inode *inode, sector_t iblock, | ||
118 | struct buffer_head *bh_result, int create) | ||
119 | { | ||
120 | unsigned long max_blocks = 1; | ||
121 | return __fat_get_blocks(inode, iblock, &max_blocks, bh_result, create); | ||
122 | } | ||
123 | |||
88 | static int fat_writepage(struct page *page, struct writeback_control *wbc) | 124 | static int fat_writepage(struct page *page, struct writeback_control *wbc) |
89 | { | 125 | { |
90 | return block_write_full_page(page, fat_get_block, wbc); | 126 | return block_write_full_page(page, fat_get_block, wbc); |
91 | } | 127 | } |
92 | 128 | ||
129 | static int fat_writepages(struct address_space *mapping, | ||
130 | struct writeback_control *wbc) | ||
131 | { | ||
132 | return mpage_writepages(mapping, wbc, fat_get_block); | ||
133 | } | ||
134 | |||
93 | static int fat_readpage(struct file *file, struct page *page) | 135 | static int fat_readpage(struct file *file, struct page *page) |
94 | { | 136 | { |
95 | return block_read_full_page(page, fat_get_block); | 137 | return mpage_readpage(page, fat_get_block); |
138 | } | ||
139 | |||
140 | static int fat_readpages(struct file *file, struct address_space *mapping, | ||
141 | struct list_head *pages, unsigned nr_pages) | ||
142 | { | ||
143 | return mpage_readpages(mapping, pages, nr_pages, fat_get_block); | ||
96 | } | 144 | } |
97 | 145 | ||
98 | static int fat_prepare_write(struct file *file, struct page *page, | 146 | static int fat_prepare_write(struct file *file, struct page *page, |
@@ -115,6 +163,34 @@ static int fat_commit_write(struct file *file, struct page *page, | |||
115 | return err; | 163 | return err; |
116 | } | 164 | } |
117 | 165 | ||
166 | static ssize_t fat_direct_IO(int rw, struct kiocb *iocb, | ||
167 | const struct iovec *iov, | ||
168 | loff_t offset, unsigned long nr_segs) | ||
169 | { | ||
170 | struct file *file = iocb->ki_filp; | ||
171 | struct inode *inode = file->f_mapping->host; | ||
172 | |||
173 | if (rw == WRITE) { | ||
174 | /* | ||
175 | * FIXME: blockdev_direct_IO() doesn't use ->prepare_write(), | ||
176 | * so we need to update the ->mmu_private to block boundary. | ||
177 | * | ||
178 | * But we must fill the remaining area or hole by nul for | ||
179 | * updating ->mmu_private. | ||
180 | */ | ||
181 | loff_t size = offset + iov_length(iov, nr_segs); | ||
182 | if (MSDOS_I(inode)->mmu_private < size) | ||
183 | return -EINVAL; | ||
184 | } | ||
185 | |||
186 | /* | ||
187 | * FAT need to use the DIO_LOCKING for avoiding the race | ||
188 | * condition of fat_get_block() and ->truncate(). | ||
189 | */ | ||
190 | return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, | ||
191 | offset, nr_segs, fat_get_blocks, NULL); | ||
192 | } | ||
193 | |||
118 | static sector_t _fat_bmap(struct address_space *mapping, sector_t block) | 194 | static sector_t _fat_bmap(struct address_space *mapping, sector_t block) |
119 | { | 195 | { |
120 | return generic_block_bmap(mapping, block, fat_get_block); | 196 | return generic_block_bmap(mapping, block, fat_get_block); |
@@ -122,10 +198,13 @@ static sector_t _fat_bmap(struct address_space *mapping, sector_t block) | |||
122 | 198 | ||
123 | static struct address_space_operations fat_aops = { | 199 | static struct address_space_operations fat_aops = { |
124 | .readpage = fat_readpage, | 200 | .readpage = fat_readpage, |
201 | .readpages = fat_readpages, | ||
125 | .writepage = fat_writepage, | 202 | .writepage = fat_writepage, |
203 | .writepages = fat_writepages, | ||
126 | .sync_page = block_sync_page, | 204 | .sync_page = block_sync_page, |
127 | .prepare_write = fat_prepare_write, | 205 | .prepare_write = fat_prepare_write, |
128 | .commit_write = fat_commit_write, | 206 | .commit_write = fat_commit_write, |
207 | .direct_IO = fat_direct_IO, | ||
129 | .bmap = _fat_bmap | 208 | .bmap = _fat_bmap |
130 | }; | 209 | }; |
131 | 210 | ||
@@ -182,7 +261,7 @@ void fat_attach(struct inode *inode, loff_t i_pos) | |||
182 | spin_unlock(&sbi->inode_hash_lock); | 261 | spin_unlock(&sbi->inode_hash_lock); |
183 | } | 262 | } |
184 | 263 | ||
185 | EXPORT_SYMBOL(fat_attach); | 264 | EXPORT_SYMBOL_GPL(fat_attach); |
186 | 265 | ||
187 | void fat_detach(struct inode *inode) | 266 | void fat_detach(struct inode *inode) |
188 | { | 267 | { |
@@ -193,7 +272,7 @@ void fat_detach(struct inode *inode) | |||
193 | spin_unlock(&sbi->inode_hash_lock); | 272 | spin_unlock(&sbi->inode_hash_lock); |
194 | } | 273 | } |
195 | 274 | ||
196 | EXPORT_SYMBOL(fat_detach); | 275 | EXPORT_SYMBOL_GPL(fat_detach); |
197 | 276 | ||
198 | struct inode *fat_iget(struct super_block *sb, loff_t i_pos) | 277 | struct inode *fat_iget(struct super_block *sb, loff_t i_pos) |
199 | { | 278 | { |
@@ -347,7 +426,7 @@ out: | |||
347 | return inode; | 426 | return inode; |
348 | } | 427 | } |
349 | 428 | ||
350 | EXPORT_SYMBOL(fat_build_inode); | 429 | EXPORT_SYMBOL_GPL(fat_build_inode); |
351 | 430 | ||
352 | static void fat_delete_inode(struct inode *inode) | 431 | static void fat_delete_inode(struct inode *inode) |
353 | { | 432 | { |
@@ -374,12 +453,17 @@ static void fat_clear_inode(struct inode *inode) | |||
374 | unlock_kernel(); | 453 | unlock_kernel(); |
375 | } | 454 | } |
376 | 455 | ||
377 | static void fat_put_super(struct super_block *sb) | 456 | static void fat_write_super(struct super_block *sb) |
378 | { | 457 | { |
379 | struct msdos_sb_info *sbi = MSDOS_SB(sb); | 458 | sb->s_dirt = 0; |
380 | 459 | ||
381 | if (!(sb->s_flags & MS_RDONLY)) | 460 | if (!(sb->s_flags & MS_RDONLY)) |
382 | fat_clusters_flush(sb); | 461 | fat_clusters_flush(sb); |
462 | } | ||
463 | |||
464 | static void fat_put_super(struct super_block *sb) | ||
465 | { | ||
466 | struct msdos_sb_info *sbi = MSDOS_SB(sb); | ||
383 | 467 | ||
384 | if (sbi->nls_disk) { | 468 | if (sbi->nls_disk) { |
385 | unload_nls(sbi->nls_disk); | 469 | unload_nls(sbi->nls_disk); |
@@ -537,7 +621,7 @@ int fat_sync_inode(struct inode *inode) | |||
537 | return fat_write_inode(inode, 1); | 621 | return fat_write_inode(inode, 1); |
538 | } | 622 | } |
539 | 623 | ||
540 | EXPORT_SYMBOL(fat_sync_inode); | 624 | EXPORT_SYMBOL_GPL(fat_sync_inode); |
541 | 625 | ||
542 | static int fat_show_options(struct seq_file *m, struct vfsmount *mnt); | 626 | static int fat_show_options(struct seq_file *m, struct vfsmount *mnt); |
543 | static struct super_operations fat_sops = { | 627 | static struct super_operations fat_sops = { |
@@ -546,6 +630,7 @@ static struct super_operations fat_sops = { | |||
546 | .write_inode = fat_write_inode, | 630 | .write_inode = fat_write_inode, |
547 | .delete_inode = fat_delete_inode, | 631 | .delete_inode = fat_delete_inode, |
548 | .put_super = fat_put_super, | 632 | .put_super = fat_put_super, |
633 | .write_super = fat_write_super, | ||
549 | .statfs = fat_statfs, | 634 | .statfs = fat_statfs, |
550 | .clear_inode = fat_clear_inode, | 635 | .clear_inode = fat_clear_inode, |
551 | .remount_fs = fat_remount, | 636 | .remount_fs = fat_remount, |
@@ -1347,7 +1432,7 @@ out_fail: | |||
1347 | return error; | 1432 | return error; |
1348 | } | 1433 | } |
1349 | 1434 | ||
1350 | EXPORT_SYMBOL(fat_fill_super); | 1435 | EXPORT_SYMBOL_GPL(fat_fill_super); |
1351 | 1436 | ||
1352 | int __init fat_cache_init(void); | 1437 | int __init fat_cache_init(void); |
1353 | void fat_cache_destroy(void); | 1438 | void fat_cache_destroy(void); |
diff --git a/fs/fat/misc.c b/fs/fat/misc.c index 2a0df2122f5d..32fb0a3f1da4 100644 --- a/fs/fat/misc.c +++ b/fs/fat/misc.c | |||
@@ -33,7 +33,7 @@ void fat_fs_panic(struct super_block *s, const char *fmt, ...) | |||
33 | } | 33 | } |
34 | } | 34 | } |
35 | 35 | ||
36 | EXPORT_SYMBOL(fat_fs_panic); | 36 | EXPORT_SYMBOL_GPL(fat_fs_panic); |
37 | 37 | ||
38 | /* Flushes the number of free clusters on FAT32 */ | 38 | /* Flushes the number of free clusters on FAT32 */ |
39 | /* XXX: Need to write one per FSINFO block. Currently only writes 1 */ | 39 | /* XXX: Need to write one per FSINFO block. Currently only writes 1 */ |
@@ -67,8 +67,6 @@ void fat_clusters_flush(struct super_block *sb) | |||
67 | if (sbi->prev_free != -1) | 67 | if (sbi->prev_free != -1) |
68 | fsinfo->next_cluster = cpu_to_le32(sbi->prev_free); | 68 | fsinfo->next_cluster = cpu_to_le32(sbi->prev_free); |
69 | mark_buffer_dirty(bh); | 69 | mark_buffer_dirty(bh); |
70 | if (sb->s_flags & MS_SYNCHRONOUS) | ||
71 | sync_dirty_buffer(bh); | ||
72 | } | 70 | } |
73 | brelse(bh); | 71 | brelse(bh); |
74 | } | 72 | } |
@@ -194,7 +192,7 @@ void fat_date_unix2dos(int unix_date, __le16 *time, __le16 *date) | |||
194 | *date = cpu_to_le16(nl_day-day_n[month-1]+1+(month << 5)+(year << 9)); | 192 | *date = cpu_to_le16(nl_day-day_n[month-1]+1+(month << 5)+(year << 9)); |
195 | } | 193 | } |
196 | 194 | ||
197 | EXPORT_SYMBOL(fat_date_unix2dos); | 195 | EXPORT_SYMBOL_GPL(fat_date_unix2dos); |
198 | 196 | ||
199 | int fat_sync_bhs(struct buffer_head **bhs, int nr_bhs) | 197 | int fat_sync_bhs(struct buffer_head **bhs, int nr_bhs) |
200 | { | 198 | { |
@@ -222,4 +220,4 @@ int fat_sync_bhs(struct buffer_head **bhs, int nr_bhs) | |||
222 | return err; | 220 | return err; |
223 | } | 221 | } |
224 | 222 | ||
225 | EXPORT_SYMBOL(fat_sync_bhs); | 223 | EXPORT_SYMBOL_GPL(fat_sync_bhs); |
diff --git a/fs/fcntl.c b/fs/fcntl.c index 863b46e0d78a..9903bde475f2 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c | |||
@@ -457,11 +457,11 @@ static void send_sigio_to_task(struct task_struct *p, | |||
457 | else | 457 | else |
458 | si.si_band = band_table[reason - POLL_IN]; | 458 | si.si_band = band_table[reason - POLL_IN]; |
459 | si.si_fd = fd; | 459 | si.si_fd = fd; |
460 | if (!send_group_sig_info(fown->signum, &si, p)) | 460 | if (!group_send_sig_info(fown->signum, &si, p)) |
461 | break; | 461 | break; |
462 | /* fall-through: fall back on the old plain SIGIO signal */ | 462 | /* fall-through: fall back on the old plain SIGIO signal */ |
463 | case 0: | 463 | case 0: |
464 | send_group_sig_info(SIGIO, SEND_SIG_PRIV, p); | 464 | group_send_sig_info(SIGIO, SEND_SIG_PRIV, p); |
465 | } | 465 | } |
466 | } | 466 | } |
467 | 467 | ||
@@ -495,7 +495,7 @@ static void send_sigurg_to_task(struct task_struct *p, | |||
495 | struct fown_struct *fown) | 495 | struct fown_struct *fown) |
496 | { | 496 | { |
497 | if (sigio_perm(p, fown, SIGURG)) | 497 | if (sigio_perm(p, fown, SIGURG)) |
498 | send_group_sig_info(SIGURG, SEND_SIG_PRIV, p); | 498 | group_send_sig_info(SIGURG, SEND_SIG_PRIV, p); |
499 | } | 499 | } |
500 | 500 | ||
501 | int send_sigurg(struct fown_struct *fown) | 501 | int send_sigurg(struct fown_struct *fown) |
diff --git a/fs/file_table.c b/fs/file_table.c index c3a5e2fd663b..6142250104a6 100644 --- a/fs/file_table.c +++ b/fs/file_table.c | |||
@@ -117,7 +117,7 @@ EXPORT_SYMBOL(get_empty_filp); | |||
117 | 117 | ||
118 | void fastcall fput(struct file *file) | 118 | void fastcall fput(struct file *file) |
119 | { | 119 | { |
120 | if (rcuref_dec_and_test(&file->f_count)) | 120 | if (atomic_dec_and_test(&file->f_count)) |
121 | __fput(file); | 121 | __fput(file); |
122 | } | 122 | } |
123 | 123 | ||
@@ -166,7 +166,7 @@ struct file fastcall *fget(unsigned int fd) | |||
166 | rcu_read_lock(); | 166 | rcu_read_lock(); |
167 | file = fcheck_files(files, fd); | 167 | file = fcheck_files(files, fd); |
168 | if (file) { | 168 | if (file) { |
169 | if (!rcuref_inc_lf(&file->f_count)) { | 169 | if (!atomic_inc_not_zero(&file->f_count)) { |
170 | /* File object ref couldn't be taken */ | 170 | /* File object ref couldn't be taken */ |
171 | rcu_read_unlock(); | 171 | rcu_read_unlock(); |
172 | return NULL; | 172 | return NULL; |
@@ -198,7 +198,7 @@ struct file fastcall *fget_light(unsigned int fd, int *fput_needed) | |||
198 | rcu_read_lock(); | 198 | rcu_read_lock(); |
199 | file = fcheck_files(files, fd); | 199 | file = fcheck_files(files, fd); |
200 | if (file) { | 200 | if (file) { |
201 | if (rcuref_inc_lf(&file->f_count)) | 201 | if (atomic_inc_not_zero(&file->f_count)) |
202 | *fput_needed = 1; | 202 | *fput_needed = 1; |
203 | else | 203 | else |
204 | /* Didn't get the reference, someone's freed */ | 204 | /* Didn't get the reference, someone's freed */ |
@@ -213,7 +213,7 @@ struct file fastcall *fget_light(unsigned int fd, int *fput_needed) | |||
213 | 213 | ||
214 | void put_filp(struct file *file) | 214 | void put_filp(struct file *file) |
215 | { | 215 | { |
216 | if (rcuref_dec_and_test(&file->f_count)) { | 216 | if (atomic_dec_and_test(&file->f_count)) { |
217 | security_file_free(file); | 217 | security_file_free(file); |
218 | file_kill(file); | 218 | file_kill(file); |
219 | file_free(file); | 219 | file_free(file); |
diff --git a/fs/freevxfs/vxfs_immed.c b/fs/freevxfs/vxfs_immed.c index d0401dc68d41..6f5df1700e95 100644 --- a/fs/freevxfs/vxfs_immed.c +++ b/fs/freevxfs/vxfs_immed.c | |||
@@ -99,8 +99,8 @@ static int | |||
99 | vxfs_immed_readpage(struct file *fp, struct page *pp) | 99 | vxfs_immed_readpage(struct file *fp, struct page *pp) |
100 | { | 100 | { |
101 | struct vxfs_inode_info *vip = VXFS_INO(pp->mapping->host); | 101 | struct vxfs_inode_info *vip = VXFS_INO(pp->mapping->host); |
102 | u_int64_t offset = pp->index << PAGE_CACHE_SHIFT; | 102 | u_int64_t offset = (u_int64_t)pp->index << PAGE_CACHE_SHIFT; |
103 | caddr_t kaddr; | 103 | caddr_t kaddr; |
104 | 104 | ||
105 | kaddr = kmap(pp); | 105 | kaddr = kmap(pp); |
106 | memcpy(kaddr, vip->vii_immed.vi_immed + offset, PAGE_CACHE_SIZE); | 106 | memcpy(kaddr, vip->vii_immed.vi_immed + offset, PAGE_CACHE_SIZE); |
diff --git a/fs/inode.c b/fs/inode.c index d8d04bd72b59..fd568caf7f74 100644 --- a/fs/inode.c +++ b/fs/inode.c | |||
@@ -770,7 +770,7 @@ EXPORT_SYMBOL(igrab); | |||
770 | * | 770 | * |
771 | * Note, @test is called with the inode_lock held, so can't sleep. | 771 | * Note, @test is called with the inode_lock held, so can't sleep. |
772 | */ | 772 | */ |
773 | static inline struct inode *ifind(struct super_block *sb, | 773 | static struct inode *ifind(struct super_block *sb, |
774 | struct hlist_head *head, int (*test)(struct inode *, void *), | 774 | struct hlist_head *head, int (*test)(struct inode *, void *), |
775 | void *data, const int wait) | 775 | void *data, const int wait) |
776 | { | 776 | { |
@@ -804,7 +804,7 @@ static inline struct inode *ifind(struct super_block *sb, | |||
804 | * | 804 | * |
805 | * Otherwise NULL is returned. | 805 | * Otherwise NULL is returned. |
806 | */ | 806 | */ |
807 | static inline struct inode *ifind_fast(struct super_block *sb, | 807 | static struct inode *ifind_fast(struct super_block *sb, |
808 | struct hlist_head *head, unsigned long ino) | 808 | struct hlist_head *head, unsigned long ino) |
809 | { | 809 | { |
810 | struct inode *inode; | 810 | struct inode *inode; |
diff --git a/fs/jffs/inode-v23.c b/fs/jffs/inode-v23.c index 3dcc6d2162cb..2559ee10beda 100644 --- a/fs/jffs/inode-v23.c +++ b/fs/jffs/inode-v23.c | |||
@@ -757,7 +757,7 @@ jffs_do_readpage_nolock(struct file *file, struct page *page) | |||
757 | 757 | ||
758 | read_len = 0; | 758 | read_len = 0; |
759 | result = 0; | 759 | result = 0; |
760 | offset = page->index << PAGE_CACHE_SHIFT; | 760 | offset = page_offset(page); |
761 | 761 | ||
762 | kmap(page); | 762 | kmap(page); |
763 | buf = page_address(page); | 763 | buf = page_address(page); |
@@ -1545,7 +1545,7 @@ jffs_commit_write(struct file *filp, struct page *page, | |||
1545 | { | 1545 | { |
1546 | void *addr = page_address(page) + from; | 1546 | void *addr = page_address(page) + from; |
1547 | /* XXX: PAGE_CACHE_SHIFT or PAGE_SHIFT */ | 1547 | /* XXX: PAGE_CACHE_SHIFT or PAGE_SHIFT */ |
1548 | loff_t pos = (page->index<<PAGE_CACHE_SHIFT) + from; | 1548 | loff_t pos = page_offset(page) + from; |
1549 | 1549 | ||
1550 | return jffs_file_write(filp, addr, to-from, &pos); | 1550 | return jffs_file_write(filp, addr, to-from, &pos); |
1551 | } /* jffs_commit_write() */ | 1551 | } /* jffs_commit_write() */ |
diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c index 68000a50ceb6..2967b7393415 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c | |||
@@ -302,8 +302,7 @@ int dbSync(struct inode *ipbmap) | |||
302 | /* | 302 | /* |
303 | * write out dirty pages of bmap | 303 | * write out dirty pages of bmap |
304 | */ | 304 | */ |
305 | filemap_fdatawrite(ipbmap->i_mapping); | 305 | filemap_write_and_wait(ipbmap->i_mapping); |
306 | filemap_fdatawait(ipbmap->i_mapping); | ||
307 | 306 | ||
308 | diWriteSpecial(ipbmap, 0); | 307 | diWriteSpecial(ipbmap, 0); |
309 | 308 | ||
diff --git a/fs/jfs/jfs_imap.c b/fs/jfs/jfs_imap.c index 28201b194f53..31b4aa13dd4b 100644 --- a/fs/jfs/jfs_imap.c +++ b/fs/jfs/jfs_imap.c | |||
@@ -265,8 +265,7 @@ int diSync(struct inode *ipimap) | |||
265 | /* | 265 | /* |
266 | * write out dirty pages of imap | 266 | * write out dirty pages of imap |
267 | */ | 267 | */ |
268 | filemap_fdatawrite(ipimap->i_mapping); | 268 | filemap_write_and_wait(ipimap->i_mapping); |
269 | filemap_fdatawait(ipimap->i_mapping); | ||
270 | 269 | ||
271 | diWriteSpecial(ipimap, 0); | 270 | diWriteSpecial(ipimap, 0); |
272 | 271 | ||
@@ -565,8 +564,7 @@ void diFreeSpecial(struct inode *ip) | |||
565 | jfs_err("diFreeSpecial called with NULL ip!"); | 564 | jfs_err("diFreeSpecial called with NULL ip!"); |
566 | return; | 565 | return; |
567 | } | 566 | } |
568 | filemap_fdatawrite(ip->i_mapping); | 567 | filemap_write_and_wait(ip->i_mapping); |
569 | filemap_fdatawait(ip->i_mapping); | ||
570 | truncate_inode_pages(ip->i_mapping, 0); | 568 | truncate_inode_pages(ip->i_mapping, 0); |
571 | iput(ip); | 569 | iput(ip); |
572 | } | 570 | } |
diff --git a/fs/jfs/jfs_txnmgr.c b/fs/jfs/jfs_txnmgr.c index b660c93c92de..2ddb6b892bcf 100644 --- a/fs/jfs/jfs_txnmgr.c +++ b/fs/jfs/jfs_txnmgr.c | |||
@@ -1231,10 +1231,8 @@ int txCommit(tid_t tid, /* transaction identifier */ | |||
1231 | * when we don't need to worry about it at all. | 1231 | * when we don't need to worry about it at all. |
1232 | * | 1232 | * |
1233 | * if ((!S_ISDIR(ip->i_mode)) | 1233 | * if ((!S_ISDIR(ip->i_mode)) |
1234 | * && (tblk->flag & COMMIT_DELETE) == 0) { | 1234 | * && (tblk->flag & COMMIT_DELETE) == 0) |
1235 | * filemap_fdatawrite(ip->i_mapping); | 1235 | * filemap_write_and_wait(ip->i_mapping); |
1236 | * filemap_fdatawait(ip->i_mapping); | ||
1237 | * } | ||
1238 | */ | 1236 | */ |
1239 | 1237 | ||
1240 | /* | 1238 | /* |
diff --git a/fs/jfs/jfs_umount.c b/fs/jfs/jfs_umount.c index 5cf91785b541..21eaf7ac0fcb 100644 --- a/fs/jfs/jfs_umount.c +++ b/fs/jfs/jfs_umount.c | |||
@@ -108,8 +108,7 @@ int jfs_umount(struct super_block *sb) | |||
108 | * Make sure all metadata makes it to disk before we mark | 108 | * Make sure all metadata makes it to disk before we mark |
109 | * the superblock as clean | 109 | * the superblock as clean |
110 | */ | 110 | */ |
111 | filemap_fdatawrite(sbi->direct_inode->i_mapping); | 111 | filemap_write_and_wait(sbi->direct_inode->i_mapping); |
112 | filemap_fdatawait(sbi->direct_inode->i_mapping); | ||
113 | 112 | ||
114 | /* | 113 | /* |
115 | * ensure all file system file pages are propagated to their | 114 | * ensure all file system file pages are propagated to their |
@@ -161,8 +160,7 @@ int jfs_umount_rw(struct super_block *sb) | |||
161 | * mark the superblock clean before everything is flushed to | 160 | * mark the superblock clean before everything is flushed to |
162 | * disk. | 161 | * disk. |
163 | */ | 162 | */ |
164 | filemap_fdatawrite(sbi->direct_inode->i_mapping); | 163 | filemap_write_and_wait(sbi->direct_inode->i_mapping); |
165 | filemap_fdatawait(sbi->direct_inode->i_mapping); | ||
166 | 164 | ||
167 | updateSuper(sb, FM_CLEAN); | 165 | updateSuper(sb, FM_CLEAN); |
168 | 166 | ||
diff --git a/fs/jfs/resize.c b/fs/jfs/resize.c index c6dc254d3253..45180361871c 100644 --- a/fs/jfs/resize.c +++ b/fs/jfs/resize.c | |||
@@ -376,8 +376,7 @@ int jfs_extendfs(struct super_block *sb, s64 newLVSize, int newLogSize) | |||
376 | * by txCommit(); | 376 | * by txCommit(); |
377 | */ | 377 | */ |
378 | filemap_fdatawait(ipbmap->i_mapping); | 378 | filemap_fdatawait(ipbmap->i_mapping); |
379 | filemap_fdatawrite(ipbmap->i_mapping); | 379 | filemap_write_and_wait(ipbmap->i_mapping); |
380 | filemap_fdatawait(ipbmap->i_mapping); | ||
381 | diWriteSpecial(ipbmap, 0); | 380 | diWriteSpecial(ipbmap, 0); |
382 | 381 | ||
383 | newPage = nPages; /* first new page number */ | 382 | newPage = nPages; /* first new page number */ |
diff --git a/fs/jfs/super.c b/fs/jfs/super.c index 4226af3ea91b..8d31f1336431 100644 --- a/fs/jfs/super.c +++ b/fs/jfs/super.c | |||
@@ -502,8 +502,7 @@ out_no_rw: | |||
502 | jfs_err("jfs_umount failed with return code %d", rc); | 502 | jfs_err("jfs_umount failed with return code %d", rc); |
503 | } | 503 | } |
504 | out_mount_failed: | 504 | out_mount_failed: |
505 | filemap_fdatawrite(sbi->direct_inode->i_mapping); | 505 | filemap_write_and_wait(sbi->direct_inode->i_mapping); |
506 | filemap_fdatawait(sbi->direct_inode->i_mapping); | ||
507 | truncate_inode_pages(sbi->direct_inode->i_mapping, 0); | 506 | truncate_inode_pages(sbi->direct_inode->i_mapping, 0); |
508 | make_bad_inode(sbi->direct_inode); | 507 | make_bad_inode(sbi->direct_inode); |
509 | iput(sbi->direct_inode); | 508 | iput(sbi->direct_inode); |
diff --git a/fs/libfs.c b/fs/libfs.c index 58101dff2c66..9c50523382e7 100644 --- a/fs/libfs.c +++ b/fs/libfs.c | |||
@@ -93,16 +93,16 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int origin) | |||
93 | loff_t n = file->f_pos - 2; | 93 | loff_t n = file->f_pos - 2; |
94 | 94 | ||
95 | spin_lock(&dcache_lock); | 95 | spin_lock(&dcache_lock); |
96 | list_del(&cursor->d_child); | 96 | list_del(&cursor->d_u.d_child); |
97 | p = file->f_dentry->d_subdirs.next; | 97 | p = file->f_dentry->d_subdirs.next; |
98 | while (n && p != &file->f_dentry->d_subdirs) { | 98 | while (n && p != &file->f_dentry->d_subdirs) { |
99 | struct dentry *next; | 99 | struct dentry *next; |
100 | next = list_entry(p, struct dentry, d_child); | 100 | next = list_entry(p, struct dentry, d_u.d_child); |
101 | if (!d_unhashed(next) && next->d_inode) | 101 | if (!d_unhashed(next) && next->d_inode) |
102 | n--; | 102 | n--; |
103 | p = p->next; | 103 | p = p->next; |
104 | } | 104 | } |
105 | list_add_tail(&cursor->d_child, p); | 105 | list_add_tail(&cursor->d_u.d_child, p); |
106 | spin_unlock(&dcache_lock); | 106 | spin_unlock(&dcache_lock); |
107 | } | 107 | } |
108 | } | 108 | } |
@@ -126,7 +126,7 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir) | |||
126 | { | 126 | { |
127 | struct dentry *dentry = filp->f_dentry; | 127 | struct dentry *dentry = filp->f_dentry; |
128 | struct dentry *cursor = filp->private_data; | 128 | struct dentry *cursor = filp->private_data; |
129 | struct list_head *p, *q = &cursor->d_child; | 129 | struct list_head *p, *q = &cursor->d_u.d_child; |
130 | ino_t ino; | 130 | ino_t ino; |
131 | int i = filp->f_pos; | 131 | int i = filp->f_pos; |
132 | 132 | ||
@@ -153,7 +153,7 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir) | |||
153 | } | 153 | } |
154 | for (p=q->next; p != &dentry->d_subdirs; p=p->next) { | 154 | for (p=q->next; p != &dentry->d_subdirs; p=p->next) { |
155 | struct dentry *next; | 155 | struct dentry *next; |
156 | next = list_entry(p, struct dentry, d_child); | 156 | next = list_entry(p, struct dentry, d_u.d_child); |
157 | if (d_unhashed(next) || !next->d_inode) | 157 | if (d_unhashed(next) || !next->d_inode) |
158 | continue; | 158 | continue; |
159 | 159 | ||
@@ -261,7 +261,7 @@ int simple_empty(struct dentry *dentry) | |||
261 | int ret = 0; | 261 | int ret = 0; |
262 | 262 | ||
263 | spin_lock(&dcache_lock); | 263 | spin_lock(&dcache_lock); |
264 | list_for_each_entry(child, &dentry->d_subdirs, d_child) | 264 | list_for_each_entry(child, &dentry->d_subdirs, d_u.d_child) |
265 | if (simple_positive(child)) | 265 | if (simple_positive(child)) |
266 | goto out; | 266 | goto out; |
267 | ret = 1; | 267 | ret = 1; |
diff --git a/fs/locks.c b/fs/locks.c index fb32d6218e21..909eab8fb1d0 100644 --- a/fs/locks.c +++ b/fs/locks.c | |||
@@ -154,7 +154,7 @@ static struct file_lock *locks_alloc_lock(void) | |||
154 | } | 154 | } |
155 | 155 | ||
156 | /* Free a lock which is not in use. */ | 156 | /* Free a lock which is not in use. */ |
157 | static inline void locks_free_lock(struct file_lock *fl) | 157 | static void locks_free_lock(struct file_lock *fl) |
158 | { | 158 | { |
159 | if (fl == NULL) { | 159 | if (fl == NULL) { |
160 | BUG(); | 160 | BUG(); |
@@ -475,8 +475,7 @@ static inline int locks_overlap(struct file_lock *fl1, struct file_lock *fl2) | |||
475 | /* | 475 | /* |
476 | * Check whether two locks have the same owner. | 476 | * Check whether two locks have the same owner. |
477 | */ | 477 | */ |
478 | static inline int | 478 | static int posix_same_owner(struct file_lock *fl1, struct file_lock *fl2) |
479 | posix_same_owner(struct file_lock *fl1, struct file_lock *fl2) | ||
480 | { | 479 | { |
481 | if (fl1->fl_lmops && fl1->fl_lmops->fl_compare_owner) | 480 | if (fl1->fl_lmops && fl1->fl_lmops->fl_compare_owner) |
482 | return fl2->fl_lmops == fl1->fl_lmops && | 481 | return fl2->fl_lmops == fl1->fl_lmops && |
@@ -487,7 +486,7 @@ posix_same_owner(struct file_lock *fl1, struct file_lock *fl2) | |||
487 | /* Remove waiter from blocker's block list. | 486 | /* Remove waiter from blocker's block list. |
488 | * When blocker ends up pointing to itself then the list is empty. | 487 | * When blocker ends up pointing to itself then the list is empty. |
489 | */ | 488 | */ |
490 | static inline void __locks_delete_block(struct file_lock *waiter) | 489 | static void __locks_delete_block(struct file_lock *waiter) |
491 | { | 490 | { |
492 | list_del_init(&waiter->fl_block); | 491 | list_del_init(&waiter->fl_block); |
493 | list_del_init(&waiter->fl_link); | 492 | list_del_init(&waiter->fl_link); |
diff --git a/fs/mpage.c b/fs/mpage.c index f1d2d02bd4c8..e431cb3878d6 100644 --- a/fs/mpage.c +++ b/fs/mpage.c | |||
@@ -184,7 +184,7 @@ do_mpage_readpage(struct bio *bio, struct page *page, unsigned nr_pages, | |||
184 | if (page_has_buffers(page)) | 184 | if (page_has_buffers(page)) |
185 | goto confused; | 185 | goto confused; |
186 | 186 | ||
187 | block_in_file = page->index << (PAGE_CACHE_SHIFT - blkbits); | 187 | block_in_file = (sector_t)page->index << (PAGE_CACHE_SHIFT - blkbits); |
188 | last_block = (i_size_read(inode) + blocksize - 1) >> blkbits; | 188 | last_block = (i_size_read(inode) + blocksize - 1) >> blkbits; |
189 | 189 | ||
190 | bh.b_page = page; | 190 | bh.b_page = page; |
@@ -466,7 +466,7 @@ __mpage_writepage(struct bio *bio, struct page *page, get_block_t get_block, | |||
466 | * The page has no buffers: map it to disk | 466 | * The page has no buffers: map it to disk |
467 | */ | 467 | */ |
468 | BUG_ON(!PageUptodate(page)); | 468 | BUG_ON(!PageUptodate(page)); |
469 | block_in_file = page->index << (PAGE_CACHE_SHIFT - blkbits); | 469 | block_in_file = (sector_t)page->index << (PAGE_CACHE_SHIFT - blkbits); |
470 | last_block = (i_size - 1) >> blkbits; | 470 | last_block = (i_size - 1) >> blkbits; |
471 | map_bh.b_page = page; | 471 | map_bh.b_page = page; |
472 | for (page_block = 0; page_block < blocks_per_page; ) { | 472 | for (page_block = 0; page_block < blocks_per_page; ) { |
diff --git a/fs/namei.c b/fs/namei.c index 6dbbd42d8b95..300eae088d5f 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -1491,7 +1491,7 @@ int may_open(struct nameidata *nd, int acc_mode, int flag) | |||
1491 | if (!error) { | 1491 | if (!error) { |
1492 | DQUOT_INIT(inode); | 1492 | DQUOT_INIT(inode); |
1493 | 1493 | ||
1494 | error = do_truncate(dentry, 0, NULL); | 1494 | error = do_truncate(dentry, 0, ATTR_MTIME|ATTR_CTIME, NULL); |
1495 | } | 1495 | } |
1496 | put_write_access(inode); | 1496 | put_write_access(inode); |
1497 | if (error) | 1497 | if (error) |
diff --git a/fs/namespace.c b/fs/namespace.c index 2019899f2ab8..3e8fb61ad597 100644 --- a/fs/namespace.c +++ b/fs/namespace.c | |||
@@ -451,7 +451,7 @@ EXPORT_SYMBOL(may_umount); | |||
451 | void release_mounts(struct list_head *head) | 451 | void release_mounts(struct list_head *head) |
452 | { | 452 | { |
453 | struct vfsmount *mnt; | 453 | struct vfsmount *mnt; |
454 | while(!list_empty(head)) { | 454 | while (!list_empty(head)) { |
455 | mnt = list_entry(head->next, struct vfsmount, mnt_hash); | 455 | mnt = list_entry(head->next, struct vfsmount, mnt_hash); |
456 | list_del_init(&mnt->mnt_hash); | 456 | list_del_init(&mnt->mnt_hash); |
457 | if (mnt->mnt_parent != mnt) { | 457 | if (mnt->mnt_parent != mnt) { |
@@ -1526,6 +1526,10 @@ static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd) | |||
1526 | * pointed to by put_old must yield the same directory as new_root. No other | 1526 | * pointed to by put_old must yield the same directory as new_root. No other |
1527 | * file system may be mounted on put_old. After all, new_root is a mountpoint. | 1527 | * file system may be mounted on put_old. After all, new_root is a mountpoint. |
1528 | * | 1528 | * |
1529 | * Also, the current root cannot be on the 'rootfs' (initial ramfs) filesystem. | ||
1530 | * See Documentation/filesystems/ramfs-rootfs-initramfs.txt for alternatives | ||
1531 | * in this situation. | ||
1532 | * | ||
1529 | * Notes: | 1533 | * Notes: |
1530 | * - we don't move root/cwd if they are not at the root (reason: if something | 1534 | * - we don't move root/cwd if they are not at the root (reason: if something |
1531 | * cared enough to change them, it's probably wrong to force them elsewhere) | 1535 | * cared enough to change them, it's probably wrong to force them elsewhere) |
diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c index a9f7a8ab1d59..cfd76f431dc0 100644 --- a/fs/ncpfs/dir.c +++ b/fs/ncpfs/dir.c | |||
@@ -365,7 +365,7 @@ ncp_dget_fpos(struct dentry *dentry, struct dentry *parent, unsigned long fpos) | |||
365 | spin_lock(&dcache_lock); | 365 | spin_lock(&dcache_lock); |
366 | next = parent->d_subdirs.next; | 366 | next = parent->d_subdirs.next; |
367 | while (next != &parent->d_subdirs) { | 367 | while (next != &parent->d_subdirs) { |
368 | dent = list_entry(next, struct dentry, d_child); | 368 | dent = list_entry(next, struct dentry, d_u.d_child); |
369 | if ((unsigned long)dent->d_fsdata == fpos) { | 369 | if ((unsigned long)dent->d_fsdata == fpos) { |
370 | if (dent->d_inode) | 370 | if (dent->d_inode) |
371 | dget_locked(dent); | 371 | dget_locked(dent); |
diff --git a/fs/ncpfs/ncplib_kernel.h b/fs/ncpfs/ncplib_kernel.h index 9e4dc30c2435..799e5c2bec55 100644 --- a/fs/ncpfs/ncplib_kernel.h +++ b/fs/ncpfs/ncplib_kernel.h | |||
@@ -196,7 +196,7 @@ ncp_renew_dentries(struct dentry *parent) | |||
196 | spin_lock(&dcache_lock); | 196 | spin_lock(&dcache_lock); |
197 | next = parent->d_subdirs.next; | 197 | next = parent->d_subdirs.next; |
198 | while (next != &parent->d_subdirs) { | 198 | while (next != &parent->d_subdirs) { |
199 | dentry = list_entry(next, struct dentry, d_child); | 199 | dentry = list_entry(next, struct dentry, d_u.d_child); |
200 | 200 | ||
201 | if (dentry->d_fsdata == NULL) | 201 | if (dentry->d_fsdata == NULL) |
202 | ncp_age_dentry(server, dentry); | 202 | ncp_age_dentry(server, dentry); |
@@ -218,7 +218,7 @@ ncp_invalidate_dircache_entries(struct dentry *parent) | |||
218 | spin_lock(&dcache_lock); | 218 | spin_lock(&dcache_lock); |
219 | next = parent->d_subdirs.next; | 219 | next = parent->d_subdirs.next; |
220 | while (next != &parent->d_subdirs) { | 220 | while (next != &parent->d_subdirs) { |
221 | dentry = list_entry(next, struct dentry, d_child); | 221 | dentry = list_entry(next, struct dentry, d_u.d_child); |
222 | dentry->d_fsdata = NULL; | 222 | dentry->d_fsdata = NULL; |
223 | ncp_age_dentry(server, dentry); | 223 | ncp_age_dentry(server, dentry); |
224 | next = next->next; | 224 | next = next->next; |
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index e7bd0d92600f..3e4ba9cb7f80 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c | |||
@@ -644,10 +644,7 @@ int nfs_sync_mapping(struct address_space *mapping) | |||
644 | if (mapping->nrpages == 0) | 644 | if (mapping->nrpages == 0) |
645 | return 0; | 645 | return 0; |
646 | unmap_mapping_range(mapping, 0, 0, 0); | 646 | unmap_mapping_range(mapping, 0, 0, 0); |
647 | ret = filemap_fdatawrite(mapping); | 647 | ret = filemap_write_and_wait(mapping); |
648 | if (ret != 0) | ||
649 | goto out; | ||
650 | ret = filemap_fdatawait(mapping); | ||
651 | if (ret != 0) | 648 | if (ret != 0) |
652 | goto out; | 649 | goto out; |
653 | ret = nfs_wb_all(mapping->host); | 650 | ret = nfs_wb_all(mapping->host); |
@@ -864,8 +861,7 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
864 | nfs_begin_data_update(inode); | 861 | nfs_begin_data_update(inode); |
865 | /* Write all dirty data if we're changing file permissions or size */ | 862 | /* Write all dirty data if we're changing file permissions or size */ |
866 | if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE)) != 0) { | 863 | if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE)) != 0) { |
867 | if (filemap_fdatawrite(inode->i_mapping) == 0) | 864 | filemap_write_and_wait(inode->i_mapping); |
868 | filemap_fdatawait(inode->i_mapping); | ||
869 | nfs_wb_all(inode); | 865 | nfs_wb_all(inode); |
870 | } | 866 | } |
871 | /* | 867 | /* |
diff --git a/fs/nfs/nfsroot.c b/fs/nfs/nfsroot.c index 985cc53b8dd5..e897e00c2c9d 100644 --- a/fs/nfs/nfsroot.c +++ b/fs/nfs/nfsroot.c | |||
@@ -275,7 +275,9 @@ static int __init root_nfs_parse(char *name, char *buf) | |||
275 | case Opt_noacl: | 275 | case Opt_noacl: |
276 | nfs_data.flags |= NFS_MOUNT_NOACL; | 276 | nfs_data.flags |= NFS_MOUNT_NOACL; |
277 | break; | 277 | break; |
278 | default : | 278 | default: |
279 | printk(KERN_WARNING "Root-NFS: unknown " | ||
280 | "option: %s\n", p); | ||
279 | return 0; | 281 | return 0; |
280 | } | 282 | } |
281 | } | 283 | } |
diff --git a/fs/ocfs2/cluster/masklog.h b/fs/ocfs2/cluster/masklog.h index f5ef5ea61a05..e8c56a3d9c64 100644 --- a/fs/ocfs2/cluster/masklog.h +++ b/fs/ocfs2/cluster/masklog.h | |||
@@ -212,11 +212,10 @@ extern struct mlog_bits mlog_and_bits, mlog_not_bits; | |||
212 | mlog(ML_ENTRY, "ENTRY:\n"); \ | 212 | mlog(ML_ENTRY, "ENTRY:\n"); \ |
213 | } while (0) | 213 | } while (0) |
214 | 214 | ||
215 | /* We disable this for old compilers since they don't have support for | 215 | /* |
216 | * __builtin_types_compatible_p. | 216 | * We disable this for sparse. |
217 | */ | 217 | */ |
218 | #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) && \ | 218 | #if !defined(__CHECKER__) |
219 | !defined(__CHECKER__) | ||
220 | #define mlog_exit(st) do { \ | 219 | #define mlog_exit(st) do { \ |
221 | if (__builtin_types_compatible_p(typeof(st), unsigned long)) \ | 220 | if (__builtin_types_compatible_p(typeof(st), unsigned long)) \ |
222 | mlog(ML_EXIT, "EXIT: %lu\n", (unsigned long) (st)); \ | 221 | mlog(ML_EXIT, "EXIT: %lu\n", (unsigned long) (st)); \ |
@@ -194,7 +194,8 @@ out: | |||
194 | return error; | 194 | return error; |
195 | } | 195 | } |
196 | 196 | ||
197 | int do_truncate(struct dentry *dentry, loff_t length, struct file *filp) | 197 | int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs, |
198 | struct file *filp) | ||
198 | { | 199 | { |
199 | int err; | 200 | int err; |
200 | struct iattr newattrs; | 201 | struct iattr newattrs; |
@@ -204,7 +205,7 @@ int do_truncate(struct dentry *dentry, loff_t length, struct file *filp) | |||
204 | return -EINVAL; | 205 | return -EINVAL; |
205 | 206 | ||
206 | newattrs.ia_size = length; | 207 | newattrs.ia_size = length; |
207 | newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME; | 208 | newattrs.ia_valid = ATTR_SIZE | time_attrs; |
208 | if (filp) { | 209 | if (filp) { |
209 | newattrs.ia_file = filp; | 210 | newattrs.ia_file = filp; |
210 | newattrs.ia_valid |= ATTR_FILE; | 211 | newattrs.ia_valid |= ATTR_FILE; |
@@ -216,7 +217,7 @@ int do_truncate(struct dentry *dentry, loff_t length, struct file *filp) | |||
216 | return err; | 217 | return err; |
217 | } | 218 | } |
218 | 219 | ||
219 | static inline long do_sys_truncate(const char __user * path, loff_t length) | 220 | static long do_sys_truncate(const char __user * path, loff_t length) |
220 | { | 221 | { |
221 | struct nameidata nd; | 222 | struct nameidata nd; |
222 | struct inode * inode; | 223 | struct inode * inode; |
@@ -266,7 +267,7 @@ static inline long do_sys_truncate(const char __user * path, loff_t length) | |||
266 | error = locks_verify_truncate(inode, NULL, length); | 267 | error = locks_verify_truncate(inode, NULL, length); |
267 | if (!error) { | 268 | if (!error) { |
268 | DQUOT_INIT(inode); | 269 | DQUOT_INIT(inode); |
269 | error = do_truncate(nd.dentry, length, NULL); | 270 | error = do_truncate(nd.dentry, length, 0, NULL); |
270 | } | 271 | } |
271 | put_write_access(inode); | 272 | put_write_access(inode); |
272 | 273 | ||
@@ -282,7 +283,7 @@ asmlinkage long sys_truncate(const char __user * path, unsigned long length) | |||
282 | return do_sys_truncate(path, (long)length); | 283 | return do_sys_truncate(path, (long)length); |
283 | } | 284 | } |
284 | 285 | ||
285 | static inline long do_sys_ftruncate(unsigned int fd, loff_t length, int small) | 286 | static long do_sys_ftruncate(unsigned int fd, loff_t length, int small) |
286 | { | 287 | { |
287 | struct inode * inode; | 288 | struct inode * inode; |
288 | struct dentry *dentry; | 289 | struct dentry *dentry; |
@@ -318,7 +319,7 @@ static inline long do_sys_ftruncate(unsigned int fd, loff_t length, int small) | |||
318 | 319 | ||
319 | error = locks_verify_truncate(inode, file, length); | 320 | error = locks_verify_truncate(inode, file, length); |
320 | if (!error) | 321 | if (!error) |
321 | error = do_truncate(dentry, length, file); | 322 | error = do_truncate(dentry, length, 0, file); |
322 | out_putf: | 323 | out_putf: |
323 | fput(file); | 324 | fput(file); |
324 | out: | 325 | out: |
@@ -970,7 +971,7 @@ out: | |||
970 | 971 | ||
971 | EXPORT_SYMBOL(get_unused_fd); | 972 | EXPORT_SYMBOL(get_unused_fd); |
972 | 973 | ||
973 | static inline void __put_unused_fd(struct files_struct *files, unsigned int fd) | 974 | static void __put_unused_fd(struct files_struct *files, unsigned int fd) |
974 | { | 975 | { |
975 | struct fdtable *fdt = files_fdtable(files); | 976 | struct fdtable *fdt = files_fdtable(files); |
976 | __FD_CLR(fd, fdt->open_fds); | 977 | __FD_CLR(fd, fdt->open_fds); |
diff --git a/fs/pnode.c b/fs/pnode.c index aeeec8ba8dd2..f1871f773f64 100644 --- a/fs/pnode.c +++ b/fs/pnode.c | |||
@@ -103,7 +103,7 @@ static struct vfsmount *propagation_next(struct vfsmount *m, | |||
103 | struct vfsmount *next; | 103 | struct vfsmount *next; |
104 | struct vfsmount *master = m->mnt_master; | 104 | struct vfsmount *master = m->mnt_master; |
105 | 105 | ||
106 | if ( master == origin->mnt_master ) { | 106 | if (master == origin->mnt_master) { |
107 | next = next_peer(m); | 107 | next = next_peer(m); |
108 | return ((next == origin) ? NULL : next); | 108 | return ((next == origin) ? NULL : next); |
109 | } else if (m->mnt_slave.next != &master->mnt_slave_list) | 109 | } else if (m->mnt_slave.next != &master->mnt_slave_list) |
diff --git a/fs/proc/generic.c b/fs/proc/generic.c index 72b431d0a0a4..20e5c4509a43 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c | |||
@@ -21,6 +21,8 @@ | |||
21 | #include <linux/bitops.h> | 21 | #include <linux/bitops.h> |
22 | #include <asm/uaccess.h> | 22 | #include <asm/uaccess.h> |
23 | 23 | ||
24 | #include "internal.h" | ||
25 | |||
24 | static ssize_t proc_file_read(struct file *file, char __user *buf, | 26 | static ssize_t proc_file_read(struct file *file, char __user *buf, |
25 | size_t nbytes, loff_t *ppos); | 27 | size_t nbytes, loff_t *ppos); |
26 | static ssize_t proc_file_write(struct file *file, const char __user *buffer, | 28 | static ssize_t proc_file_write(struct file *file, const char __user *buffer, |
diff --git a/fs/proc/inode.c b/fs/proc/inode.c index e6a818a93f3d..6573f31f1fd9 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c | |||
@@ -19,7 +19,7 @@ | |||
19 | #include <asm/system.h> | 19 | #include <asm/system.h> |
20 | #include <asm/uaccess.h> | 20 | #include <asm/uaccess.h> |
21 | 21 | ||
22 | extern void free_proc_entry(struct proc_dir_entry *); | 22 | #include "internal.h" |
23 | 23 | ||
24 | static inline struct proc_dir_entry * de_get(struct proc_dir_entry *de) | 24 | static inline struct proc_dir_entry * de_get(struct proc_dir_entry *de) |
25 | { | 25 | { |
diff --git a/fs/proc/internal.h b/fs/proc/internal.h index 3e55198f9806..95a1cf32b838 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h | |||
@@ -37,6 +37,10 @@ extern int proc_tgid_stat(struct task_struct *, char *); | |||
37 | extern int proc_pid_status(struct task_struct *, char *); | 37 | extern int proc_pid_status(struct task_struct *, char *); |
38 | extern int proc_pid_statm(struct task_struct *, char *); | 38 | extern int proc_pid_statm(struct task_struct *, char *); |
39 | 39 | ||
40 | void free_proc_entry(struct proc_dir_entry *de); | ||
41 | |||
42 | int proc_init_inodecache(void); | ||
43 | |||
40 | static inline struct task_struct *proc_task(struct inode *inode) | 44 | static inline struct task_struct *proc_task(struct inode *inode) |
41 | { | 45 | { |
42 | return PROC_I(inode)->task; | 46 | return PROC_I(inode)->task; |
diff --git a/fs/proc/proc_misc.c b/fs/proc/proc_misc.c index 5b6b0b6038a7..63bf6c00fa0c 100644 --- a/fs/proc/proc_misc.c +++ b/fs/proc/proc_misc.c | |||
@@ -323,6 +323,7 @@ static struct file_operations proc_modules_operations = { | |||
323 | }; | 323 | }; |
324 | #endif | 324 | #endif |
325 | 325 | ||
326 | #ifdef CONFIG_SLAB | ||
326 | extern struct seq_operations slabinfo_op; | 327 | extern struct seq_operations slabinfo_op; |
327 | extern ssize_t slabinfo_write(struct file *, const char __user *, size_t, loff_t *); | 328 | extern ssize_t slabinfo_write(struct file *, const char __user *, size_t, loff_t *); |
328 | static int slabinfo_open(struct inode *inode, struct file *file) | 329 | static int slabinfo_open(struct inode *inode, struct file *file) |
@@ -336,6 +337,7 @@ static struct file_operations proc_slabinfo_operations = { | |||
336 | .llseek = seq_lseek, | 337 | .llseek = seq_lseek, |
337 | .release = seq_release, | 338 | .release = seq_release, |
338 | }; | 339 | }; |
340 | #endif | ||
339 | 341 | ||
340 | static int show_stat(struct seq_file *p, void *v) | 342 | static int show_stat(struct seq_file *p, void *v) |
341 | { | 343 | { |
@@ -600,7 +602,9 @@ void __init proc_misc_init(void) | |||
600 | create_seq_entry("partitions", 0, &proc_partitions_operations); | 602 | create_seq_entry("partitions", 0, &proc_partitions_operations); |
601 | create_seq_entry("stat", 0, &proc_stat_operations); | 603 | create_seq_entry("stat", 0, &proc_stat_operations); |
602 | create_seq_entry("interrupts", 0, &proc_interrupts_operations); | 604 | create_seq_entry("interrupts", 0, &proc_interrupts_operations); |
605 | #ifdef CONFIG_SLAB | ||
603 | create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations); | 606 | create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations); |
607 | #endif | ||
604 | create_seq_entry("buddyinfo",S_IRUGO, &fragmentation_file_operations); | 608 | create_seq_entry("buddyinfo",S_IRUGO, &fragmentation_file_operations); |
605 | create_seq_entry("vmstat",S_IRUGO, &proc_vmstat_file_operations); | 609 | create_seq_entry("vmstat",S_IRUGO, &proc_vmstat_file_operations); |
606 | create_seq_entry("zoneinfo",S_IRUGO, &proc_zoneinfo_file_operations); | 610 | create_seq_entry("zoneinfo",S_IRUGO, &proc_zoneinfo_file_operations); |
diff --git a/fs/proc/root.c b/fs/proc/root.c index aef148f099a2..68896283c8ae 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c | |||
@@ -18,6 +18,8 @@ | |||
18 | #include <linux/bitops.h> | 18 | #include <linux/bitops.h> |
19 | #include <linux/smp_lock.h> | 19 | #include <linux/smp_lock.h> |
20 | 20 | ||
21 | #include "internal.h" | ||
22 | |||
21 | struct proc_dir_entry *proc_net, *proc_net_stat, *proc_bus, *proc_root_fs, *proc_root_driver; | 23 | struct proc_dir_entry *proc_net, *proc_net_stat, *proc_bus, *proc_root_fs, *proc_root_driver; |
22 | 24 | ||
23 | #ifdef CONFIG_SYSCTL | 25 | #ifdef CONFIG_SYSCTL |
@@ -36,7 +38,6 @@ static struct file_system_type proc_fs_type = { | |||
36 | .kill_sb = kill_anon_super, | 38 | .kill_sb = kill_anon_super, |
37 | }; | 39 | }; |
38 | 40 | ||
39 | extern int __init proc_init_inodecache(void); | ||
40 | void __init proc_root_init(void) | 41 | void __init proc_root_init(void) |
41 | { | 42 | { |
42 | int err = proc_init_inodecache(); | 43 | int err = proc_init_inodecache(); |
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 50bd5a8f0446..0eaad41f4658 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c | |||
@@ -390,129 +390,12 @@ struct seq_operations proc_pid_smaps_op = { | |||
390 | }; | 390 | }; |
391 | 391 | ||
392 | #ifdef CONFIG_NUMA | 392 | #ifdef CONFIG_NUMA |
393 | 393 | extern int show_numa_map(struct seq_file *m, void *v); | |
394 | struct numa_maps { | ||
395 | unsigned long pages; | ||
396 | unsigned long anon; | ||
397 | unsigned long mapped; | ||
398 | unsigned long mapcount_max; | ||
399 | unsigned long node[MAX_NUMNODES]; | ||
400 | }; | ||
401 | |||
402 | /* | ||
403 | * Calculate numa node maps for a vma | ||
404 | */ | ||
405 | static struct numa_maps *get_numa_maps(struct vm_area_struct *vma) | ||
406 | { | ||
407 | int i; | ||
408 | struct page *page; | ||
409 | unsigned long vaddr; | ||
410 | struct numa_maps *md = kmalloc(sizeof(struct numa_maps), GFP_KERNEL); | ||
411 | |||
412 | if (!md) | ||
413 | return NULL; | ||
414 | md->pages = 0; | ||
415 | md->anon = 0; | ||
416 | md->mapped = 0; | ||
417 | md->mapcount_max = 0; | ||
418 | for_each_node(i) | ||
419 | md->node[i] =0; | ||
420 | |||
421 | for (vaddr = vma->vm_start; vaddr < vma->vm_end; vaddr += PAGE_SIZE) { | ||
422 | page = follow_page(vma, vaddr, 0); | ||
423 | if (page) { | ||
424 | int count = page_mapcount(page); | ||
425 | |||
426 | if (count) | ||
427 | md->mapped++; | ||
428 | if (count > md->mapcount_max) | ||
429 | md->mapcount_max = count; | ||
430 | md->pages++; | ||
431 | if (PageAnon(page)) | ||
432 | md->anon++; | ||
433 | md->node[page_to_nid(page)]++; | ||
434 | } | ||
435 | cond_resched(); | ||
436 | } | ||
437 | return md; | ||
438 | } | ||
439 | |||
440 | static int show_numa_map(struct seq_file *m, void *v) | ||
441 | { | ||
442 | struct task_struct *task = m->private; | ||
443 | struct vm_area_struct *vma = v; | ||
444 | struct mempolicy *pol; | ||
445 | struct numa_maps *md; | ||
446 | struct zone **z; | ||
447 | int n; | ||
448 | int first; | ||
449 | |||
450 | if (!vma->vm_mm) | ||
451 | return 0; | ||
452 | |||
453 | md = get_numa_maps(vma); | ||
454 | if (!md) | ||
455 | return 0; | ||
456 | |||
457 | seq_printf(m, "%08lx", vma->vm_start); | ||
458 | pol = get_vma_policy(task, vma, vma->vm_start); | ||
459 | /* Print policy */ | ||
460 | switch (pol->policy) { | ||
461 | case MPOL_PREFERRED: | ||
462 | seq_printf(m, " prefer=%d", pol->v.preferred_node); | ||
463 | break; | ||
464 | case MPOL_BIND: | ||
465 | seq_printf(m, " bind={"); | ||
466 | first = 1; | ||
467 | for (z = pol->v.zonelist->zones; *z; z++) { | ||
468 | |||
469 | if (!first) | ||
470 | seq_putc(m, ','); | ||
471 | else | ||
472 | first = 0; | ||
473 | seq_printf(m, "%d/%s", (*z)->zone_pgdat->node_id, | ||
474 | (*z)->name); | ||
475 | } | ||
476 | seq_putc(m, '}'); | ||
477 | break; | ||
478 | case MPOL_INTERLEAVE: | ||
479 | seq_printf(m, " interleave={"); | ||
480 | first = 1; | ||
481 | for_each_node(n) { | ||
482 | if (node_isset(n, pol->v.nodes)) { | ||
483 | if (!first) | ||
484 | seq_putc(m,','); | ||
485 | else | ||
486 | first = 0; | ||
487 | seq_printf(m, "%d",n); | ||
488 | } | ||
489 | } | ||
490 | seq_putc(m, '}'); | ||
491 | break; | ||
492 | default: | ||
493 | seq_printf(m," default"); | ||
494 | break; | ||
495 | } | ||
496 | seq_printf(m, " MaxRef=%lu Pages=%lu Mapped=%lu", | ||
497 | md->mapcount_max, md->pages, md->mapped); | ||
498 | if (md->anon) | ||
499 | seq_printf(m," Anon=%lu",md->anon); | ||
500 | |||
501 | for_each_online_node(n) { | ||
502 | if (md->node[n]) | ||
503 | seq_printf(m, " N%d=%lu", n, md->node[n]); | ||
504 | } | ||
505 | seq_putc(m, '\n'); | ||
506 | kfree(md); | ||
507 | if (m->count < m->size) /* vma is copied successfully */ | ||
508 | m->version = (vma != get_gate_vma(task)) ? vma->vm_start : 0; | ||
509 | return 0; | ||
510 | } | ||
511 | 394 | ||
512 | struct seq_operations proc_pid_numa_maps_op = { | 395 | struct seq_operations proc_pid_numa_maps_op = { |
513 | .start = m_start, | 396 | .start = m_start, |
514 | .next = m_next, | 397 | .next = m_next, |
515 | .stop = m_stop, | 398 | .stop = m_stop, |
516 | .show = show_numa_map | 399 | .show = show_numa_map |
517 | }; | 400 | }; |
518 | #endif | 401 | #endif |
diff --git a/fs/relayfs/buffers.c b/fs/relayfs/buffers.c index 84e21ffa5ca8..10187812771e 100644 --- a/fs/relayfs/buffers.c +++ b/fs/relayfs/buffers.c | |||
@@ -185,5 +185,6 @@ void relay_destroy_buf(struct rchan_buf *buf) | |||
185 | void relay_remove_buf(struct kref *kref) | 185 | void relay_remove_buf(struct kref *kref) |
186 | { | 186 | { |
187 | struct rchan_buf *buf = container_of(kref, struct rchan_buf, kref); | 187 | struct rchan_buf *buf = container_of(kref, struct rchan_buf, kref); |
188 | relayfs_remove(buf->dentry); | 188 | buf->chan->cb->remove_buf_file(buf->dentry); |
189 | relay_destroy_buf(buf); | ||
189 | } | 190 | } |
diff --git a/fs/relayfs/inode.c b/fs/relayfs/inode.c index 0f7f88d067ad..7b7f2cb5f0e1 100644 --- a/fs/relayfs/inode.c +++ b/fs/relayfs/inode.c | |||
@@ -26,31 +26,22 @@ | |||
26 | 26 | ||
27 | static struct vfsmount * relayfs_mount; | 27 | static struct vfsmount * relayfs_mount; |
28 | static int relayfs_mount_count; | 28 | static int relayfs_mount_count; |
29 | static kmem_cache_t * relayfs_inode_cachep; | ||
30 | 29 | ||
31 | static struct backing_dev_info relayfs_backing_dev_info = { | 30 | static struct backing_dev_info relayfs_backing_dev_info = { |
32 | .ra_pages = 0, /* No readahead */ | 31 | .ra_pages = 0, /* No readahead */ |
33 | .capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK, | 32 | .capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK, |
34 | }; | 33 | }; |
35 | 34 | ||
36 | static struct inode *relayfs_get_inode(struct super_block *sb, int mode, | 35 | static struct inode *relayfs_get_inode(struct super_block *sb, |
37 | struct rchan *chan) | 36 | int mode, |
37 | struct file_operations *fops, | ||
38 | void *data) | ||
38 | { | 39 | { |
39 | struct rchan_buf *buf = NULL; | ||
40 | struct inode *inode; | 40 | struct inode *inode; |
41 | 41 | ||
42 | if (S_ISREG(mode)) { | ||
43 | BUG_ON(!chan); | ||
44 | buf = relay_create_buf(chan); | ||
45 | if (!buf) | ||
46 | return NULL; | ||
47 | } | ||
48 | |||
49 | inode = new_inode(sb); | 42 | inode = new_inode(sb); |
50 | if (!inode) { | 43 | if (!inode) |
51 | relay_destroy_buf(buf); | ||
52 | return NULL; | 44 | return NULL; |
53 | } | ||
54 | 45 | ||
55 | inode->i_mode = mode; | 46 | inode->i_mode = mode; |
56 | inode->i_uid = 0; | 47 | inode->i_uid = 0; |
@@ -61,8 +52,9 @@ static struct inode *relayfs_get_inode(struct super_block *sb, int mode, | |||
61 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; | 52 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
62 | switch (mode & S_IFMT) { | 53 | switch (mode & S_IFMT) { |
63 | case S_IFREG: | 54 | case S_IFREG: |
64 | inode->i_fop = &relayfs_file_operations; | 55 | inode->i_fop = fops; |
65 | RELAYFS_I(inode)->buf = buf; | 56 | if (data) |
57 | inode->u.generic_ip = data; | ||
66 | break; | 58 | break; |
67 | case S_IFDIR: | 59 | case S_IFDIR: |
68 | inode->i_op = &simple_dir_inode_operations; | 60 | inode->i_op = &simple_dir_inode_operations; |
@@ -83,7 +75,8 @@ static struct inode *relayfs_get_inode(struct super_block *sb, int mode, | |||
83 | * @name: the name of the file to create | 75 | * @name: the name of the file to create |
84 | * @parent: parent directory | 76 | * @parent: parent directory |
85 | * @mode: mode | 77 | * @mode: mode |
86 | * @chan: relay channel associated with the file | 78 | * @fops: file operations to use for the file |
79 | * @data: user-associated data for this file | ||
87 | * | 80 | * |
88 | * Returns the new dentry, NULL on failure | 81 | * Returns the new dentry, NULL on failure |
89 | * | 82 | * |
@@ -92,7 +85,8 @@ static struct inode *relayfs_get_inode(struct super_block *sb, int mode, | |||
92 | static struct dentry *relayfs_create_entry(const char *name, | 85 | static struct dentry *relayfs_create_entry(const char *name, |
93 | struct dentry *parent, | 86 | struct dentry *parent, |
94 | int mode, | 87 | int mode, |
95 | struct rchan *chan) | 88 | struct file_operations *fops, |
89 | void *data) | ||
96 | { | 90 | { |
97 | struct dentry *d; | 91 | struct dentry *d; |
98 | struct inode *inode; | 92 | struct inode *inode; |
@@ -127,7 +121,7 @@ static struct dentry *relayfs_create_entry(const char *name, | |||
127 | goto release_mount; | 121 | goto release_mount; |
128 | } | 122 | } |
129 | 123 | ||
130 | inode = relayfs_get_inode(parent->d_inode->i_sb, mode, chan); | 124 | inode = relayfs_get_inode(parent->d_inode->i_sb, mode, fops, data); |
131 | if (!inode) { | 125 | if (!inode) { |
132 | d = NULL; | 126 | d = NULL; |
133 | goto release_mount; | 127 | goto release_mount; |
@@ -155,20 +149,26 @@ exit: | |||
155 | * @name: the name of the file to create | 149 | * @name: the name of the file to create |
156 | * @parent: parent directory | 150 | * @parent: parent directory |
157 | * @mode: mode, if not specied the default perms are used | 151 | * @mode: mode, if not specied the default perms are used |
158 | * @chan: channel associated with the file | 152 | * @fops: file operations to use for the file |
153 | * @data: user-associated data for this file | ||
159 | * | 154 | * |
160 | * Returns file dentry if successful, NULL otherwise. | 155 | * Returns file dentry if successful, NULL otherwise. |
161 | * | 156 | * |
162 | * The file will be created user r on behalf of current user. | 157 | * The file will be created user r on behalf of current user. |
163 | */ | 158 | */ |
164 | struct dentry *relayfs_create_file(const char *name, struct dentry *parent, | 159 | struct dentry *relayfs_create_file(const char *name, |
165 | int mode, struct rchan *chan) | 160 | struct dentry *parent, |
161 | int mode, | ||
162 | struct file_operations *fops, | ||
163 | void *data) | ||
166 | { | 164 | { |
165 | BUG_ON(!fops); | ||
166 | |||
167 | if (!mode) | 167 | if (!mode) |
168 | mode = S_IRUSR; | 168 | mode = S_IRUSR; |
169 | mode = (mode & S_IALLUGO) | S_IFREG; | 169 | mode = (mode & S_IALLUGO) | S_IFREG; |
170 | 170 | ||
171 | return relayfs_create_entry(name, parent, mode, chan); | 171 | return relayfs_create_entry(name, parent, mode, fops, data); |
172 | } | 172 | } |
173 | 173 | ||
174 | /** | 174 | /** |
@@ -183,7 +183,7 @@ struct dentry *relayfs_create_file(const char *name, struct dentry *parent, | |||
183 | struct dentry *relayfs_create_dir(const char *name, struct dentry *parent) | 183 | struct dentry *relayfs_create_dir(const char *name, struct dentry *parent) |
184 | { | 184 | { |
185 | int mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; | 185 | int mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; |
186 | return relayfs_create_entry(name, parent, mode, NULL); | 186 | return relayfs_create_entry(name, parent, mode, NULL, NULL); |
187 | } | 187 | } |
188 | 188 | ||
189 | /** | 189 | /** |
@@ -225,6 +225,17 @@ int relayfs_remove(struct dentry *dentry) | |||
225 | } | 225 | } |
226 | 226 | ||
227 | /** | 227 | /** |
228 | * relayfs_remove_file - remove a file from relay filesystem | ||
229 | * @dentry: directory dentry | ||
230 | * | ||
231 | * Returns 0 if successful, negative otherwise. | ||
232 | */ | ||
233 | int relayfs_remove_file(struct dentry *dentry) | ||
234 | { | ||
235 | return relayfs_remove(dentry); | ||
236 | } | ||
237 | |||
238 | /** | ||
228 | * relayfs_remove_dir - remove a directory in the relay filesystem | 239 | * relayfs_remove_dir - remove a directory in the relay filesystem |
229 | * @dentry: directory dentry | 240 | * @dentry: directory dentry |
230 | * | 241 | * |
@@ -236,45 +247,45 @@ int relayfs_remove_dir(struct dentry *dentry) | |||
236 | } | 247 | } |
237 | 248 | ||
238 | /** | 249 | /** |
239 | * relayfs_open - open file op for relayfs files | 250 | * relay_file_open - open file op for relay files |
240 | * @inode: the inode | 251 | * @inode: the inode |
241 | * @filp: the file | 252 | * @filp: the file |
242 | * | 253 | * |
243 | * Increments the channel buffer refcount. | 254 | * Increments the channel buffer refcount. |
244 | */ | 255 | */ |
245 | static int relayfs_open(struct inode *inode, struct file *filp) | 256 | static int relay_file_open(struct inode *inode, struct file *filp) |
246 | { | 257 | { |
247 | struct rchan_buf *buf = RELAYFS_I(inode)->buf; | 258 | struct rchan_buf *buf = inode->u.generic_ip; |
248 | kref_get(&buf->kref); | 259 | kref_get(&buf->kref); |
260 | filp->private_data = buf; | ||
249 | 261 | ||
250 | return 0; | 262 | return 0; |
251 | } | 263 | } |
252 | 264 | ||
253 | /** | 265 | /** |
254 | * relayfs_mmap - mmap file op for relayfs files | 266 | * relay_file_mmap - mmap file op for relay files |
255 | * @filp: the file | 267 | * @filp: the file |
256 | * @vma: the vma describing what to map | 268 | * @vma: the vma describing what to map |
257 | * | 269 | * |
258 | * Calls upon relay_mmap_buf to map the file into user space. | 270 | * Calls upon relay_mmap_buf to map the file into user space. |
259 | */ | 271 | */ |
260 | static int relayfs_mmap(struct file *filp, struct vm_area_struct *vma) | 272 | static int relay_file_mmap(struct file *filp, struct vm_area_struct *vma) |
261 | { | 273 | { |
262 | struct inode *inode = filp->f_dentry->d_inode; | 274 | struct rchan_buf *buf = filp->private_data; |
263 | return relay_mmap_buf(RELAYFS_I(inode)->buf, vma); | 275 | return relay_mmap_buf(buf, vma); |
264 | } | 276 | } |
265 | 277 | ||
266 | /** | 278 | /** |
267 | * relayfs_poll - poll file op for relayfs files | 279 | * relay_file_poll - poll file op for relay files |
268 | * @filp: the file | 280 | * @filp: the file |
269 | * @wait: poll table | 281 | * @wait: poll table |
270 | * | 282 | * |
271 | * Poll implemention. | 283 | * Poll implemention. |
272 | */ | 284 | */ |
273 | static unsigned int relayfs_poll(struct file *filp, poll_table *wait) | 285 | static unsigned int relay_file_poll(struct file *filp, poll_table *wait) |
274 | { | 286 | { |
275 | unsigned int mask = 0; | 287 | unsigned int mask = 0; |
276 | struct inode *inode = filp->f_dentry->d_inode; | 288 | struct rchan_buf *buf = filp->private_data; |
277 | struct rchan_buf *buf = RELAYFS_I(inode)->buf; | ||
278 | 289 | ||
279 | if (buf->finalized) | 290 | if (buf->finalized) |
280 | return POLLERR; | 291 | return POLLERR; |
@@ -289,27 +300,27 @@ static unsigned int relayfs_poll(struct file *filp, poll_table *wait) | |||
289 | } | 300 | } |
290 | 301 | ||
291 | /** | 302 | /** |
292 | * relayfs_release - release file op for relayfs files | 303 | * relay_file_release - release file op for relay files |
293 | * @inode: the inode | 304 | * @inode: the inode |
294 | * @filp: the file | 305 | * @filp: the file |
295 | * | 306 | * |
296 | * Decrements the channel refcount, as the filesystem is | 307 | * Decrements the channel refcount, as the filesystem is |
297 | * no longer using it. | 308 | * no longer using it. |
298 | */ | 309 | */ |
299 | static int relayfs_release(struct inode *inode, struct file *filp) | 310 | static int relay_file_release(struct inode *inode, struct file *filp) |
300 | { | 311 | { |
301 | struct rchan_buf *buf = RELAYFS_I(inode)->buf; | 312 | struct rchan_buf *buf = filp->private_data; |
302 | kref_put(&buf->kref, relay_remove_buf); | 313 | kref_put(&buf->kref, relay_remove_buf); |
303 | 314 | ||
304 | return 0; | 315 | return 0; |
305 | } | 316 | } |
306 | 317 | ||
307 | /** | 318 | /** |
308 | * relayfs_read_consume - update the consumed count for the buffer | 319 | * relay_file_read_consume - update the consumed count for the buffer |
309 | */ | 320 | */ |
310 | static void relayfs_read_consume(struct rchan_buf *buf, | 321 | static void relay_file_read_consume(struct rchan_buf *buf, |
311 | size_t read_pos, | 322 | size_t read_pos, |
312 | size_t bytes_consumed) | 323 | size_t bytes_consumed) |
313 | { | 324 | { |
314 | size_t subbuf_size = buf->chan->subbuf_size; | 325 | size_t subbuf_size = buf->chan->subbuf_size; |
315 | size_t n_subbufs = buf->chan->n_subbufs; | 326 | size_t n_subbufs = buf->chan->n_subbufs; |
@@ -332,9 +343,9 @@ static void relayfs_read_consume(struct rchan_buf *buf, | |||
332 | } | 343 | } |
333 | 344 | ||
334 | /** | 345 | /** |
335 | * relayfs_read_avail - boolean, are there unconsumed bytes available? | 346 | * relay_file_read_avail - boolean, are there unconsumed bytes available? |
336 | */ | 347 | */ |
337 | static int relayfs_read_avail(struct rchan_buf *buf, size_t read_pos) | 348 | static int relay_file_read_avail(struct rchan_buf *buf, size_t read_pos) |
338 | { | 349 | { |
339 | size_t bytes_produced, bytes_consumed, write_offset; | 350 | size_t bytes_produced, bytes_consumed, write_offset; |
340 | size_t subbuf_size = buf->chan->subbuf_size; | 351 | size_t subbuf_size = buf->chan->subbuf_size; |
@@ -365,16 +376,16 @@ static int relayfs_read_avail(struct rchan_buf *buf, size_t read_pos) | |||
365 | if (bytes_produced == bytes_consumed) | 376 | if (bytes_produced == bytes_consumed) |
366 | return 0; | 377 | return 0; |
367 | 378 | ||
368 | relayfs_read_consume(buf, read_pos, 0); | 379 | relay_file_read_consume(buf, read_pos, 0); |
369 | 380 | ||
370 | return 1; | 381 | return 1; |
371 | } | 382 | } |
372 | 383 | ||
373 | /** | 384 | /** |
374 | * relayfs_read_subbuf_avail - return bytes available in sub-buffer | 385 | * relay_file_read_subbuf_avail - return bytes available in sub-buffer |
375 | */ | 386 | */ |
376 | static size_t relayfs_read_subbuf_avail(size_t read_pos, | 387 | static size_t relay_file_read_subbuf_avail(size_t read_pos, |
377 | struct rchan_buf *buf) | 388 | struct rchan_buf *buf) |
378 | { | 389 | { |
379 | size_t padding, avail = 0; | 390 | size_t padding, avail = 0; |
380 | size_t read_subbuf, read_offset, write_subbuf, write_offset; | 391 | size_t read_subbuf, read_offset, write_subbuf, write_offset; |
@@ -396,14 +407,14 @@ static size_t relayfs_read_subbuf_avail(size_t read_pos, | |||
396 | } | 407 | } |
397 | 408 | ||
398 | /** | 409 | /** |
399 | * relayfs_read_start_pos - find the first available byte to read | 410 | * relay_file_read_start_pos - find the first available byte to read |
400 | * | 411 | * |
401 | * If the read_pos is in the middle of padding, return the | 412 | * If the read_pos is in the middle of padding, return the |
402 | * position of the first actually available byte, otherwise | 413 | * position of the first actually available byte, otherwise |
403 | * return the original value. | 414 | * return the original value. |
404 | */ | 415 | */ |
405 | static size_t relayfs_read_start_pos(size_t read_pos, | 416 | static size_t relay_file_read_start_pos(size_t read_pos, |
406 | struct rchan_buf *buf) | 417 | struct rchan_buf *buf) |
407 | { | 418 | { |
408 | size_t read_subbuf, padding, padding_start, padding_end; | 419 | size_t read_subbuf, padding, padding_start, padding_end; |
409 | size_t subbuf_size = buf->chan->subbuf_size; | 420 | size_t subbuf_size = buf->chan->subbuf_size; |
@@ -422,11 +433,11 @@ static size_t relayfs_read_start_pos(size_t read_pos, | |||
422 | } | 433 | } |
423 | 434 | ||
424 | /** | 435 | /** |
425 | * relayfs_read_end_pos - return the new read position | 436 | * relay_file_read_end_pos - return the new read position |
426 | */ | 437 | */ |
427 | static size_t relayfs_read_end_pos(struct rchan_buf *buf, | 438 | static size_t relay_file_read_end_pos(struct rchan_buf *buf, |
428 | size_t read_pos, | 439 | size_t read_pos, |
429 | size_t count) | 440 | size_t count) |
430 | { | 441 | { |
431 | size_t read_subbuf, padding, end_pos; | 442 | size_t read_subbuf, padding, end_pos; |
432 | size_t subbuf_size = buf->chan->subbuf_size; | 443 | size_t subbuf_size = buf->chan->subbuf_size; |
@@ -445,7 +456,7 @@ static size_t relayfs_read_end_pos(struct rchan_buf *buf, | |||
445 | } | 456 | } |
446 | 457 | ||
447 | /** | 458 | /** |
448 | * relayfs_read - read file op for relayfs files | 459 | * relay_file_read - read file op for relay files |
449 | * @filp: the file | 460 | * @filp: the file |
450 | * @buffer: the userspace buffer | 461 | * @buffer: the userspace buffer |
451 | * @count: number of bytes to read | 462 | * @count: number of bytes to read |
@@ -454,23 +465,23 @@ static size_t relayfs_read_end_pos(struct rchan_buf *buf, | |||
454 | * Reads count bytes or the number of bytes available in the | 465 | * Reads count bytes or the number of bytes available in the |
455 | * current sub-buffer being read, whichever is smaller. | 466 | * current sub-buffer being read, whichever is smaller. |
456 | */ | 467 | */ |
457 | static ssize_t relayfs_read(struct file *filp, | 468 | static ssize_t relay_file_read(struct file *filp, |
458 | char __user *buffer, | 469 | char __user *buffer, |
459 | size_t count, | 470 | size_t count, |
460 | loff_t *ppos) | 471 | loff_t *ppos) |
461 | { | 472 | { |
473 | struct rchan_buf *buf = filp->private_data; | ||
462 | struct inode *inode = filp->f_dentry->d_inode; | 474 | struct inode *inode = filp->f_dentry->d_inode; |
463 | struct rchan_buf *buf = RELAYFS_I(inode)->buf; | ||
464 | size_t read_start, avail; | 475 | size_t read_start, avail; |
465 | ssize_t ret = 0; | 476 | ssize_t ret = 0; |
466 | void *from; | 477 | void *from; |
467 | 478 | ||
468 | down(&inode->i_sem); | 479 | down(&inode->i_sem); |
469 | if(!relayfs_read_avail(buf, *ppos)) | 480 | if(!relay_file_read_avail(buf, *ppos)) |
470 | goto out; | 481 | goto out; |
471 | 482 | ||
472 | read_start = relayfs_read_start_pos(*ppos, buf); | 483 | read_start = relay_file_read_start_pos(*ppos, buf); |
473 | avail = relayfs_read_subbuf_avail(read_start, buf); | 484 | avail = relay_file_read_subbuf_avail(read_start, buf); |
474 | if (!avail) | 485 | if (!avail) |
475 | goto out; | 486 | goto out; |
476 | 487 | ||
@@ -480,58 +491,25 @@ static ssize_t relayfs_read(struct file *filp, | |||
480 | ret = -EFAULT; | 491 | ret = -EFAULT; |
481 | goto out; | 492 | goto out; |
482 | } | 493 | } |
483 | relayfs_read_consume(buf, read_start, count); | 494 | relay_file_read_consume(buf, read_start, count); |
484 | *ppos = relayfs_read_end_pos(buf, read_start, count); | 495 | *ppos = relay_file_read_end_pos(buf, read_start, count); |
485 | out: | 496 | out: |
486 | up(&inode->i_sem); | 497 | up(&inode->i_sem); |
487 | return ret; | 498 | return ret; |
488 | } | 499 | } |
489 | 500 | ||
490 | /** | 501 | struct file_operations relay_file_operations = { |
491 | * relayfs alloc_inode() implementation | 502 | .open = relay_file_open, |
492 | */ | 503 | .poll = relay_file_poll, |
493 | static struct inode *relayfs_alloc_inode(struct super_block *sb) | 504 | .mmap = relay_file_mmap, |
494 | { | 505 | .read = relay_file_read, |
495 | struct relayfs_inode_info *p = kmem_cache_alloc(relayfs_inode_cachep, SLAB_KERNEL); | ||
496 | if (!p) | ||
497 | return NULL; | ||
498 | p->buf = NULL; | ||
499 | |||
500 | return &p->vfs_inode; | ||
501 | } | ||
502 | |||
503 | /** | ||
504 | * relayfs destroy_inode() implementation | ||
505 | */ | ||
506 | static void relayfs_destroy_inode(struct inode *inode) | ||
507 | { | ||
508 | if (RELAYFS_I(inode)->buf) | ||
509 | relay_destroy_buf(RELAYFS_I(inode)->buf); | ||
510 | |||
511 | kmem_cache_free(relayfs_inode_cachep, RELAYFS_I(inode)); | ||
512 | } | ||
513 | |||
514 | static void init_once(void *p, kmem_cache_t *cachep, unsigned long flags) | ||
515 | { | ||
516 | struct relayfs_inode_info *i = p; | ||
517 | if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR) | ||
518 | inode_init_once(&i->vfs_inode); | ||
519 | } | ||
520 | |||
521 | struct file_operations relayfs_file_operations = { | ||
522 | .open = relayfs_open, | ||
523 | .poll = relayfs_poll, | ||
524 | .mmap = relayfs_mmap, | ||
525 | .read = relayfs_read, | ||
526 | .llseek = no_llseek, | 506 | .llseek = no_llseek, |
527 | .release = relayfs_release, | 507 | .release = relay_file_release, |
528 | }; | 508 | }; |
529 | 509 | ||
530 | static struct super_operations relayfs_ops = { | 510 | static struct super_operations relayfs_ops = { |
531 | .statfs = simple_statfs, | 511 | .statfs = simple_statfs, |
532 | .drop_inode = generic_delete_inode, | 512 | .drop_inode = generic_delete_inode, |
533 | .alloc_inode = relayfs_alloc_inode, | ||
534 | .destroy_inode = relayfs_destroy_inode, | ||
535 | }; | 513 | }; |
536 | 514 | ||
537 | static int relayfs_fill_super(struct super_block * sb, void * data, int silent) | 515 | static int relayfs_fill_super(struct super_block * sb, void * data, int silent) |
@@ -544,7 +522,7 @@ static int relayfs_fill_super(struct super_block * sb, void * data, int silent) | |||
544 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; | 522 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; |
545 | sb->s_magic = RELAYFS_MAGIC; | 523 | sb->s_magic = RELAYFS_MAGIC; |
546 | sb->s_op = &relayfs_ops; | 524 | sb->s_op = &relayfs_ops; |
547 | inode = relayfs_get_inode(sb, mode, NULL); | 525 | inode = relayfs_get_inode(sb, mode, NULL, NULL); |
548 | 526 | ||
549 | if (!inode) | 527 | if (!inode) |
550 | return -ENOMEM; | 528 | return -ENOMEM; |
@@ -575,33 +553,27 @@ static struct file_system_type relayfs_fs_type = { | |||
575 | 553 | ||
576 | static int __init init_relayfs_fs(void) | 554 | static int __init init_relayfs_fs(void) |
577 | { | 555 | { |
578 | int err; | 556 | return register_filesystem(&relayfs_fs_type); |
579 | |||
580 | relayfs_inode_cachep = kmem_cache_create("relayfs_inode_cache", | ||
581 | sizeof(struct relayfs_inode_info), 0, | ||
582 | 0, init_once, NULL); | ||
583 | if (!relayfs_inode_cachep) | ||
584 | return -ENOMEM; | ||
585 | |||
586 | err = register_filesystem(&relayfs_fs_type); | ||
587 | if (err) | ||
588 | kmem_cache_destroy(relayfs_inode_cachep); | ||
589 | |||
590 | return err; | ||
591 | } | 557 | } |
592 | 558 | ||
593 | static void __exit exit_relayfs_fs(void) | 559 | static void __exit exit_relayfs_fs(void) |
594 | { | 560 | { |
561 | |||
562 | |||
563 | |||
564 | |||
565 | |||
595 | unregister_filesystem(&relayfs_fs_type); | 566 | unregister_filesystem(&relayfs_fs_type); |
596 | kmem_cache_destroy(relayfs_inode_cachep); | ||
597 | } | 567 | } |
598 | 568 | ||
599 | module_init(init_relayfs_fs) | 569 | module_init(init_relayfs_fs) |
600 | module_exit(exit_relayfs_fs) | 570 | module_exit(exit_relayfs_fs) |
601 | 571 | ||
602 | EXPORT_SYMBOL_GPL(relayfs_file_operations); | 572 | EXPORT_SYMBOL_GPL(relay_file_operations); |
603 | EXPORT_SYMBOL_GPL(relayfs_create_dir); | 573 | EXPORT_SYMBOL_GPL(relayfs_create_dir); |
604 | EXPORT_SYMBOL_GPL(relayfs_remove_dir); | 574 | EXPORT_SYMBOL_GPL(relayfs_remove_dir); |
575 | EXPORT_SYMBOL_GPL(relayfs_create_file); | ||
576 | EXPORT_SYMBOL_GPL(relayfs_remove_file); | ||
605 | 577 | ||
606 | MODULE_AUTHOR("Tom Zanussi <zanussi@us.ibm.com> and Karim Yaghmour <karim@opersys.com>"); | 578 | MODULE_AUTHOR("Tom Zanussi <zanussi@us.ibm.com> and Karim Yaghmour <karim@opersys.com>"); |
607 | MODULE_DESCRIPTION("Relay Filesystem"); | 579 | MODULE_DESCRIPTION("Relay Filesystem"); |
diff --git a/fs/relayfs/relay.c b/fs/relayfs/relay.c index 2a6f7f12b7f9..abf3ceaace49 100644 --- a/fs/relayfs/relay.c +++ b/fs/relayfs/relay.c | |||
@@ -80,11 +80,34 @@ static void buf_unmapped_default_callback(struct rchan_buf *buf, | |||
80 | { | 80 | { |
81 | } | 81 | } |
82 | 82 | ||
83 | /* | ||
84 | * create_buf_file_create() default callback. Creates file to represent buf. | ||
85 | */ | ||
86 | static struct dentry *create_buf_file_default_callback(const char *filename, | ||
87 | struct dentry *parent, | ||
88 | int mode, | ||
89 | struct rchan_buf *buf, | ||
90 | int *is_global) | ||
91 | { | ||
92 | return relayfs_create_file(filename, parent, mode, | ||
93 | &relay_file_operations, buf); | ||
94 | } | ||
95 | |||
96 | /* | ||
97 | * remove_buf_file() default callback. Removes file representing relay buffer. | ||
98 | */ | ||
99 | static int remove_buf_file_default_callback(struct dentry *dentry) | ||
100 | { | ||
101 | return relayfs_remove(dentry); | ||
102 | } | ||
103 | |||
83 | /* relay channel default callbacks */ | 104 | /* relay channel default callbacks */ |
84 | static struct rchan_callbacks default_channel_callbacks = { | 105 | static struct rchan_callbacks default_channel_callbacks = { |
85 | .subbuf_start = subbuf_start_default_callback, | 106 | .subbuf_start = subbuf_start_default_callback, |
86 | .buf_mapped = buf_mapped_default_callback, | 107 | .buf_mapped = buf_mapped_default_callback, |
87 | .buf_unmapped = buf_unmapped_default_callback, | 108 | .buf_unmapped = buf_unmapped_default_callback, |
109 | .create_buf_file = create_buf_file_default_callback, | ||
110 | .remove_buf_file = remove_buf_file_default_callback, | ||
88 | }; | 111 | }; |
89 | 112 | ||
90 | /** | 113 | /** |
@@ -148,14 +171,16 @@ static inline void __relay_reset(struct rchan_buf *buf, unsigned int init) | |||
148 | void relay_reset(struct rchan *chan) | 171 | void relay_reset(struct rchan *chan) |
149 | { | 172 | { |
150 | unsigned int i; | 173 | unsigned int i; |
174 | struct rchan_buf *prev = NULL; | ||
151 | 175 | ||
152 | if (!chan) | 176 | if (!chan) |
153 | return; | 177 | return; |
154 | 178 | ||
155 | for (i = 0; i < NR_CPUS; i++) { | 179 | for (i = 0; i < NR_CPUS; i++) { |
156 | if (!chan->buf[i]) | 180 | if (!chan->buf[i] || chan->buf[i] == prev) |
157 | continue; | 181 | break; |
158 | __relay_reset(chan->buf[i], 0); | 182 | __relay_reset(chan->buf[i], 0); |
183 | prev = chan->buf[i]; | ||
159 | } | 184 | } |
160 | } | 185 | } |
161 | 186 | ||
@@ -166,17 +191,27 @@ void relay_reset(struct rchan *chan) | |||
166 | */ | 191 | */ |
167 | static struct rchan_buf *relay_open_buf(struct rchan *chan, | 192 | static struct rchan_buf *relay_open_buf(struct rchan *chan, |
168 | const char *filename, | 193 | const char *filename, |
169 | struct dentry *parent) | 194 | struct dentry *parent, |
195 | int *is_global) | ||
170 | { | 196 | { |
171 | struct rchan_buf *buf; | 197 | struct rchan_buf *buf; |
172 | struct dentry *dentry; | 198 | struct dentry *dentry; |
173 | 199 | ||
200 | if (*is_global) | ||
201 | return chan->buf[0]; | ||
202 | |||
203 | buf = relay_create_buf(chan); | ||
204 | if (!buf) | ||
205 | return NULL; | ||
206 | |||
174 | /* Create file in fs */ | 207 | /* Create file in fs */ |
175 | dentry = relayfs_create_file(filename, parent, S_IRUSR, chan); | 208 | dentry = chan->cb->create_buf_file(filename, parent, S_IRUSR, |
176 | if (!dentry) | 209 | buf, is_global); |
210 | if (!dentry) { | ||
211 | relay_destroy_buf(buf); | ||
177 | return NULL; | 212 | return NULL; |
213 | } | ||
178 | 214 | ||
179 | buf = RELAYFS_I(dentry->d_inode)->buf; | ||
180 | buf->dentry = dentry; | 215 | buf->dentry = dentry; |
181 | __relay_reset(buf, 1); | 216 | __relay_reset(buf, 1); |
182 | 217 | ||
@@ -214,6 +249,10 @@ static inline void setup_callbacks(struct rchan *chan, | |||
214 | cb->buf_mapped = buf_mapped_default_callback; | 249 | cb->buf_mapped = buf_mapped_default_callback; |
215 | if (!cb->buf_unmapped) | 250 | if (!cb->buf_unmapped) |
216 | cb->buf_unmapped = buf_unmapped_default_callback; | 251 | cb->buf_unmapped = buf_unmapped_default_callback; |
252 | if (!cb->create_buf_file) | ||
253 | cb->create_buf_file = create_buf_file_default_callback; | ||
254 | if (!cb->remove_buf_file) | ||
255 | cb->remove_buf_file = remove_buf_file_default_callback; | ||
217 | chan->cb = cb; | 256 | chan->cb = cb; |
218 | } | 257 | } |
219 | 258 | ||
@@ -241,6 +280,7 @@ struct rchan *relay_open(const char *base_filename, | |||
241 | unsigned int i; | 280 | unsigned int i; |
242 | struct rchan *chan; | 281 | struct rchan *chan; |
243 | char *tmpname; | 282 | char *tmpname; |
283 | int is_global = 0; | ||
244 | 284 | ||
245 | if (!base_filename) | 285 | if (!base_filename) |
246 | return NULL; | 286 | return NULL; |
@@ -265,7 +305,8 @@ struct rchan *relay_open(const char *base_filename, | |||
265 | 305 | ||
266 | for_each_online_cpu(i) { | 306 | for_each_online_cpu(i) { |
267 | sprintf(tmpname, "%s%d", base_filename, i); | 307 | sprintf(tmpname, "%s%d", base_filename, i); |
268 | chan->buf[i] = relay_open_buf(chan, tmpname, parent); | 308 | chan->buf[i] = relay_open_buf(chan, tmpname, parent, |
309 | &is_global); | ||
269 | chan->buf[i]->cpu = i; | 310 | chan->buf[i]->cpu = i; |
270 | if (!chan->buf[i]) | 311 | if (!chan->buf[i]) |
271 | goto free_bufs; | 312 | goto free_bufs; |
@@ -279,6 +320,8 @@ free_bufs: | |||
279 | if (!chan->buf[i]) | 320 | if (!chan->buf[i]) |
280 | break; | 321 | break; |
281 | relay_close_buf(chan->buf[i]); | 322 | relay_close_buf(chan->buf[i]); |
323 | if (is_global) | ||
324 | break; | ||
282 | } | 325 | } |
283 | kfree(tmpname); | 326 | kfree(tmpname); |
284 | 327 | ||
@@ -388,14 +431,16 @@ void relay_destroy_channel(struct kref *kref) | |||
388 | void relay_close(struct rchan *chan) | 431 | void relay_close(struct rchan *chan) |
389 | { | 432 | { |
390 | unsigned int i; | 433 | unsigned int i; |
434 | struct rchan_buf *prev = NULL; | ||
391 | 435 | ||
392 | if (!chan) | 436 | if (!chan) |
393 | return; | 437 | return; |
394 | 438 | ||
395 | for (i = 0; i < NR_CPUS; i++) { | 439 | for (i = 0; i < NR_CPUS; i++) { |
396 | if (!chan->buf[i]) | 440 | if (!chan->buf[i] || chan->buf[i] == prev) |
397 | continue; | 441 | break; |
398 | relay_close_buf(chan->buf[i]); | 442 | relay_close_buf(chan->buf[i]); |
443 | prev = chan->buf[i]; | ||
399 | } | 444 | } |
400 | 445 | ||
401 | if (chan->last_toobig) | 446 | if (chan->last_toobig) |
@@ -415,14 +460,16 @@ void relay_close(struct rchan *chan) | |||
415 | void relay_flush(struct rchan *chan) | 460 | void relay_flush(struct rchan *chan) |
416 | { | 461 | { |
417 | unsigned int i; | 462 | unsigned int i; |
463 | struct rchan_buf *prev = NULL; | ||
418 | 464 | ||
419 | if (!chan) | 465 | if (!chan) |
420 | return; | 466 | return; |
421 | 467 | ||
422 | for (i = 0; i < NR_CPUS; i++) { | 468 | for (i = 0; i < NR_CPUS; i++) { |
423 | if (!chan->buf[i]) | 469 | if (!chan->buf[i] || chan->buf[i] == prev) |
424 | continue; | 470 | break; |
425 | relay_switch_subbuf(chan->buf[i], 0); | 471 | relay_switch_subbuf(chan->buf[i], 0); |
472 | prev = chan->buf[i]; | ||
426 | } | 473 | } |
427 | } | 474 | } |
428 | 475 | ||
diff --git a/fs/relayfs/relay.h b/fs/relayfs/relay.h index 703503fa22b6..0993d3e5753b 100644 --- a/fs/relayfs/relay.h +++ b/fs/relayfs/relay.h | |||
@@ -1,10 +1,6 @@ | |||
1 | #ifndef _RELAY_H | 1 | #ifndef _RELAY_H |
2 | #define _RELAY_H | 2 | #define _RELAY_H |
3 | 3 | ||
4 | struct dentry *relayfs_create_file(const char *name, | ||
5 | struct dentry *parent, | ||
6 | int mode, | ||
7 | struct rchan *chan); | ||
8 | extern int relayfs_remove(struct dentry *dentry); | 4 | extern int relayfs_remove(struct dentry *dentry); |
9 | extern int relay_buf_empty(struct rchan_buf *buf); | 5 | extern int relay_buf_empty(struct rchan_buf *buf); |
10 | extern void relay_destroy_channel(struct kref *kref); | 6 | extern void relay_destroy_channel(struct kref *kref); |
diff --git a/fs/romfs/inode.c b/fs/romfs/inode.c index c74f382dabba..0a13859fd57b 100644 --- a/fs/romfs/inode.c +++ b/fs/romfs/inode.c | |||
@@ -418,7 +418,7 @@ static int | |||
418 | romfs_readpage(struct file *file, struct page * page) | 418 | romfs_readpage(struct file *file, struct page * page) |
419 | { | 419 | { |
420 | struct inode *inode = page->mapping->host; | 420 | struct inode *inode = page->mapping->host; |
421 | unsigned long offset, avail, readlen; | 421 | loff_t offset, avail, readlen; |
422 | void *buf; | 422 | void *buf; |
423 | int result = -EIO; | 423 | int result = -EIO; |
424 | 424 | ||
@@ -429,8 +429,8 @@ romfs_readpage(struct file *file, struct page * page) | |||
429 | goto err_out; | 429 | goto err_out; |
430 | 430 | ||
431 | /* 32 bit warning -- but not for us :) */ | 431 | /* 32 bit warning -- but not for us :) */ |
432 | offset = page->index << PAGE_CACHE_SHIFT; | 432 | offset = page_offset(page); |
433 | if (offset < inode->i_size) { | 433 | if (offset < i_size_read(inode)) { |
434 | avail = inode->i_size-offset; | 434 | avail = inode->i_size-offset; |
435 | readlen = min_t(unsigned long, avail, PAGE_SIZE); | 435 | readlen = min_t(unsigned long, avail, PAGE_SIZE); |
436 | if (romfs_copyfrom(inode, buf, ROMFS_I(inode)->i_dataoffset+offset, readlen) == readlen) { | 436 | if (romfs_copyfrom(inode, buf, ROMFS_I(inode)->i_dataoffset+offset, readlen) == readlen) { |
diff --git a/fs/smbfs/cache.c b/fs/smbfs/cache.c index f3e6b81288ab..74b86d9725a6 100644 --- a/fs/smbfs/cache.c +++ b/fs/smbfs/cache.c | |||
@@ -66,7 +66,7 @@ smb_invalidate_dircache_entries(struct dentry *parent) | |||
66 | spin_lock(&dcache_lock); | 66 | spin_lock(&dcache_lock); |
67 | next = parent->d_subdirs.next; | 67 | next = parent->d_subdirs.next; |
68 | while (next != &parent->d_subdirs) { | 68 | while (next != &parent->d_subdirs) { |
69 | dentry = list_entry(next, struct dentry, d_child); | 69 | dentry = list_entry(next, struct dentry, d_u.d_child); |
70 | dentry->d_fsdata = NULL; | 70 | dentry->d_fsdata = NULL; |
71 | smb_age_dentry(server, dentry); | 71 | smb_age_dentry(server, dentry); |
72 | next = next->next; | 72 | next = next->next; |
@@ -100,7 +100,7 @@ smb_dget_fpos(struct dentry *dentry, struct dentry *parent, unsigned long fpos) | |||
100 | spin_lock(&dcache_lock); | 100 | spin_lock(&dcache_lock); |
101 | next = parent->d_subdirs.next; | 101 | next = parent->d_subdirs.next; |
102 | while (next != &parent->d_subdirs) { | 102 | while (next != &parent->d_subdirs) { |
103 | dent = list_entry(next, struct dentry, d_child); | 103 | dent = list_entry(next, struct dentry, d_u.d_child); |
104 | if ((unsigned long)dent->d_fsdata == fpos) { | 104 | if ((unsigned long)dent->d_fsdata == fpos) { |
105 | if (dent->d_inode) | 105 | if (dent->d_inode) |
106 | dget_locked(dent); | 106 | dget_locked(dent); |
diff --git a/fs/smbfs/file.c b/fs/smbfs/file.c index b4fcfa8b55a1..7042e62726a4 100644 --- a/fs/smbfs/file.c +++ b/fs/smbfs/file.c | |||
@@ -209,8 +209,8 @@ smb_updatepage(struct file *file, struct page *page, unsigned long offset, | |||
209 | { | 209 | { |
210 | struct dentry *dentry = file->f_dentry; | 210 | struct dentry *dentry = file->f_dentry; |
211 | 211 | ||
212 | DEBUG1("(%s/%s %d@%ld)\n", DENTRY_PATH(dentry), | 212 | DEBUG1("(%s/%s %d@%lld)\n", DENTRY_PATH(dentry), count, |
213 | count, (page->index << PAGE_CACHE_SHIFT)+offset); | 213 | ((unsigned long long)page->index << PAGE_CACHE_SHIFT) + offset); |
214 | 214 | ||
215 | return smb_writepage_sync(dentry->d_inode, page, offset, count); | 215 | return smb_writepage_sync(dentry->d_inode, page, offset, count); |
216 | } | 216 | } |
@@ -374,8 +374,7 @@ smb_file_release(struct inode *inode, struct file * file) | |||
374 | /* We must flush any dirty pages now as we won't be able to | 374 | /* We must flush any dirty pages now as we won't be able to |
375 | write anything after close. mmap can trigger this. | 375 | write anything after close. mmap can trigger this. |
376 | "openers" should perhaps include mmap'ers ... */ | 376 | "openers" should perhaps include mmap'ers ... */ |
377 | filemap_fdatawrite(inode->i_mapping); | 377 | filemap_write_and_wait(inode->i_mapping); |
378 | filemap_fdatawait(inode->i_mapping); | ||
379 | smb_close(inode); | 378 | smb_close(inode); |
380 | } | 379 | } |
381 | unlock_kernel(); | 380 | unlock_kernel(); |
diff --git a/fs/smbfs/inode.c b/fs/smbfs/inode.c index 10b994428fef..6ec88bf59b2d 100644 --- a/fs/smbfs/inode.c +++ b/fs/smbfs/inode.c | |||
@@ -697,8 +697,7 @@ smb_notify_change(struct dentry *dentry, struct iattr *attr) | |||
697 | DENTRY_PATH(dentry), | 697 | DENTRY_PATH(dentry), |
698 | (long) inode->i_size, (long) attr->ia_size); | 698 | (long) inode->i_size, (long) attr->ia_size); |
699 | 699 | ||
700 | filemap_fdatawrite(inode->i_mapping); | 700 | filemap_write_and_wait(inode->i_mapping); |
701 | filemap_fdatawait(inode->i_mapping); | ||
702 | 701 | ||
703 | error = smb_open(dentry, O_WRONLY); | 702 | error = smb_open(dentry, O_WRONLY); |
704 | if (error) | 703 | if (error) |
diff --git a/fs/smbfs/proc.c b/fs/smbfs/proc.c index 38ab558835c4..d6baec0f24ad 100644 --- a/fs/smbfs/proc.c +++ b/fs/smbfs/proc.c | |||
@@ -3113,7 +3113,7 @@ smb_proc_setattr_unix(struct dentry *d, struct iattr *attr, | |||
3113 | LSET(data, 32, SMB_TIME_NO_CHANGE); | 3113 | LSET(data, 32, SMB_TIME_NO_CHANGE); |
3114 | LSET(data, 40, SMB_UID_NO_CHANGE); | 3114 | LSET(data, 40, SMB_UID_NO_CHANGE); |
3115 | LSET(data, 48, SMB_GID_NO_CHANGE); | 3115 | LSET(data, 48, SMB_GID_NO_CHANGE); |
3116 | LSET(data, 56, smb_filetype_from_mode(attr->ia_mode)); | 3116 | DSET(data, 56, smb_filetype_from_mode(attr->ia_mode)); |
3117 | LSET(data, 60, major); | 3117 | LSET(data, 60, major); |
3118 | LSET(data, 68, minor); | 3118 | LSET(data, 68, minor); |
3119 | LSET(data, 76, 0); | 3119 | LSET(data, 76, 0); |
diff --git a/fs/super.c b/fs/super.c index 5a347a4f673a..0a30e51692cf 100644 --- a/fs/super.c +++ b/fs/super.c | |||
@@ -700,8 +700,7 @@ struct super_block *get_sb_bdev(struct file_system_type *fs_type, | |||
700 | 700 | ||
701 | s->s_flags = flags; | 701 | s->s_flags = flags; |
702 | strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id)); | 702 | strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id)); |
703 | s->s_old_blocksize = block_size(bdev); | 703 | sb_set_blocksize(s, block_size(bdev)); |
704 | sb_set_blocksize(s, s->s_old_blocksize); | ||
705 | error = fill_super(s, data, flags & MS_VERBOSE ? 1 : 0); | 704 | error = fill_super(s, data, flags & MS_VERBOSE ? 1 : 0); |
706 | if (error) { | 705 | if (error) { |
707 | up_write(&s->s_umount); | 706 | up_write(&s->s_umount); |
diff --git a/fs/sysv/dir.c b/fs/sysv/dir.c index 69a085abad6f..cce8b05cba5a 100644 --- a/fs/sysv/dir.c +++ b/fs/sysv/dir.c | |||
@@ -103,7 +103,7 @@ static int sysv_readdir(struct file * filp, void * dirent, filldir_t filldir) | |||
103 | offset = (char *)de - kaddr; | 103 | offset = (char *)de - kaddr; |
104 | 104 | ||
105 | over = filldir(dirent, name, strnlen(name,SYSV_NAMELEN), | 105 | over = filldir(dirent, name, strnlen(name,SYSV_NAMELEN), |
106 | (n<<PAGE_CACHE_SHIFT) | offset, | 106 | ((loff_t)n<<PAGE_CACHE_SHIFT) | offset, |
107 | fs16_to_cpu(SYSV_SB(sb), de->inode), | 107 | fs16_to_cpu(SYSV_SB(sb), de->inode), |
108 | DT_UNKNOWN); | 108 | DT_UNKNOWN); |
109 | if (over) { | 109 | if (over) { |
@@ -115,7 +115,7 @@ static int sysv_readdir(struct file * filp, void * dirent, filldir_t filldir) | |||
115 | } | 115 | } |
116 | 116 | ||
117 | done: | 117 | done: |
118 | filp->f_pos = (n << PAGE_CACHE_SHIFT) | offset; | 118 | filp->f_pos = ((loff_t)n << PAGE_CACHE_SHIFT) | offset; |
119 | unlock_kernel(); | 119 | unlock_kernel(); |
120 | return 0; | 120 | return 0; |
121 | } | 121 | } |
diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c index 6598a5037ac8..4fae57d9d115 100644 --- a/fs/udf/balloc.c +++ b/fs/udf/balloc.c | |||
@@ -41,7 +41,7 @@ | |||
41 | #define uint(x) xuint(x) | 41 | #define uint(x) xuint(x) |
42 | #define xuint(x) __le ## x | 42 | #define xuint(x) __le ## x |
43 | 43 | ||
44 | extern inline int find_next_one_bit (void * addr, int size, int offset) | 44 | static inline int find_next_one_bit (void * addr, int size, int offset) |
45 | { | 45 | { |
46 | uintBPL_t * p = ((uintBPL_t *) addr) + (offset / BITS_PER_LONG); | 46 | uintBPL_t * p = ((uintBPL_t *) addr) + (offset / BITS_PER_LONG); |
47 | int result = offset & ~(BITS_PER_LONG-1); | 47 | int result = offset & ~(BITS_PER_LONG-1); |
diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 4014f17d382e..395e582ee542 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c | |||
@@ -1957,11 +1957,6 @@ int8_t inode_bmap(struct inode *inode, int block, kernel_lb_addr *bloc, uint32_t | |||
1957 | printk(KERN_ERR "udf: inode_bmap: block < 0\n"); | 1957 | printk(KERN_ERR "udf: inode_bmap: block < 0\n"); |
1958 | return -1; | 1958 | return -1; |
1959 | } | 1959 | } |
1960 | if (!inode) | ||
1961 | { | ||
1962 | printk(KERN_ERR "udf: inode_bmap: NULL inode\n"); | ||
1963 | return -1; | ||
1964 | } | ||
1965 | 1960 | ||
1966 | *extoffset = 0; | 1961 | *extoffset = 0; |
1967 | *elen = 0; | 1962 | *elen = 0; |
diff --git a/fs/ufs/super.c b/fs/ufs/super.c index 54828ebcf1ba..2ba11a9aa995 100644 --- a/fs/ufs/super.c +++ b/fs/ufs/super.c | |||
@@ -1296,8 +1296,10 @@ static ssize_t ufs_quota_write(struct super_block *sb, int type, | |||
1296 | blk++; | 1296 | blk++; |
1297 | } | 1297 | } |
1298 | out: | 1298 | out: |
1299 | if (len == towrite) | 1299 | if (len == towrite) { |
1300 | up(&inode->i_sem); | ||
1300 | return err; | 1301 | return err; |
1302 | } | ||
1301 | if (inode->i_size < off+len-towrite) | 1303 | if (inode->i_size < off+len-towrite) |
1302 | i_size_write(inode, off+len-towrite); | 1304 | i_size_write(inode, off+len-towrite); |
1303 | inode->i_version++; | 1305 | inode->i_version++; |
diff --git a/fs/xfs/linux-2.6/xfs_fs_subr.c b/fs/xfs/linux-2.6/xfs_fs_subr.c index f89340c61bf2..4fa4b1a5187e 100644 --- a/fs/xfs/linux-2.6/xfs_fs_subr.c +++ b/fs/xfs/linux-2.6/xfs_fs_subr.c | |||
@@ -79,8 +79,7 @@ fs_flushinval_pages( | |||
79 | struct inode *ip = LINVFS_GET_IP(vp); | 79 | struct inode *ip = LINVFS_GET_IP(vp); |
80 | 80 | ||
81 | if (VN_CACHED(vp)) { | 81 | if (VN_CACHED(vp)) { |
82 | filemap_fdatawrite(ip->i_mapping); | 82 | filemap_write_and_wait(ip->i_mapping); |
83 | filemap_fdatawait(ip->i_mapping); | ||
84 | 83 | ||
85 | truncate_inode_pages(ip->i_mapping, first); | 84 | truncate_inode_pages(ip->i_mapping, first); |
86 | } | 85 | } |
diff --git a/fs/xfs/xfs_log.h b/fs/xfs/xfs_log.h index 158829ca56f6..f40d4391fcfc 100644 --- a/fs/xfs/xfs_log.h +++ b/fs/xfs/xfs_log.h | |||
@@ -30,13 +30,7 @@ | |||
30 | * By comparing each compnent, we don't have to worry about extra | 30 | * By comparing each compnent, we don't have to worry about extra |
31 | * endian issues in treating two 32 bit numbers as one 64 bit number | 31 | * endian issues in treating two 32 bit numbers as one 64 bit number |
32 | */ | 32 | */ |
33 | static | 33 | static inline xfs_lsn_t _lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2) |
34 | #if defined(__GNUC__) && (__GNUC__ == 2) && ( (__GNUC_MINOR__ == 95) || (__GNUC_MINOR__ == 96)) | ||
35 | __attribute__((unused)) /* gcc 2.95, 2.96 miscompile this when inlined */ | ||
36 | #else | ||
37 | __inline__ | ||
38 | #endif | ||
39 | xfs_lsn_t _lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2) | ||
40 | { | 34 | { |
41 | if (CYCLE_LSN(lsn1) != CYCLE_LSN(lsn2)) | 35 | if (CYCLE_LSN(lsn1) != CYCLE_LSN(lsn2)) |
42 | return (CYCLE_LSN(lsn1)<CYCLE_LSN(lsn2))? -999 : 999; | 36 | return (CYCLE_LSN(lsn1)<CYCLE_LSN(lsn2))? -999 : 999; |