aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/9p/9p.c68
-rw-r--r--fs/9p/9p.h9
-rw-r--r--fs/9p/conv.c86
-rw-r--r--fs/9p/conv.h13
-rw-r--r--fs/9p/fid.c2
-rw-r--r--fs/9p/mux.c1122
-rw-r--r--fs/9p/mux.h40
-rw-r--r--fs/9p/trans_fd.c49
-rw-r--r--fs/9p/trans_sock.c161
-rw-r--r--fs/9p/transport.h4
-rw-r--r--fs/9p/v9fs.c41
-rw-r--r--fs/9p/v9fs.h17
-rw-r--r--fs/9p/vfs_dentry.c13
-rw-r--r--fs/9p/vfs_dir.c17
-rw-r--r--fs/9p/vfs_inode.c89
-rw-r--r--fs/9p/vfs_super.c3
16 files changed, 1172 insertions, 562 deletions
diff --git a/fs/9p/9p.c b/fs/9p/9p.c
index e847f504a47c..a3a1ac610723 100644
--- a/fs/9p/9p.c
+++ b/fs/9p/9p.c
@@ -52,10 +52,11 @@ v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
52 52
53 dprintk(DEBUG_9P, "msize: %d version: %s\n", msize, version); 53 dprintk(DEBUG_9P, "msize: %d version: %s\n", msize, version);
54 msg.id = TVERSION; 54 msg.id = TVERSION;
55 msg.tag = ~0;
55 msg.params.tversion.msize = msize; 56 msg.params.tversion.msize = msize;
56 msg.params.tversion.version = version; 57 msg.params.tversion.version = version;
57 58
58 return v9fs_mux_rpc(v9ses, &msg, fcall); 59 return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
59} 60}
60 61
61/** 62/**
@@ -83,7 +84,30 @@ v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
83 msg.params.tattach.uname = uname; 84 msg.params.tattach.uname = uname;
84 msg.params.tattach.aname = aname; 85 msg.params.tattach.aname = aname;
85 86
86 return v9fs_mux_rpc(v9ses, &msg, fcall); 87 return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
88}
89
90static void v9fs_t_clunk_cb(void *a, struct v9fs_fcall *tc,
91 struct v9fs_fcall *rc, int err)
92{
93 int fid;
94 struct v9fs_session_info *v9ses;
95
96 if (err)
97 return;
98
99 fid = tc->params.tclunk.fid;
100 kfree(tc);
101
102 if (!rc)
103 return;
104
105 dprintk(DEBUG_9P, "tcall id %d rcall id %d\n", tc->id, rc->id);
106 v9ses = a;
107 if (rc->id == RCLUNK)
108 v9fs_put_idpool(fid, &v9ses->fidpool);
109
110 kfree(rc);
87} 111}
88 112
89/** 113/**
@@ -93,18 +117,24 @@ v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
93 * @fcall: pointer to response fcall pointer 117 * @fcall: pointer to response fcall pointer
94 * 118 *
95 */ 119 */
96
97int 120int
98v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid, 121v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid)
99 struct v9fs_fcall **fcall)
100{ 122{
101 struct v9fs_fcall msg; 123 int err;
124 struct v9fs_fcall *tc, *rc;
125
126 tc = kmalloc(sizeof(struct v9fs_fcall), GFP_KERNEL);
102 127
103 dprintk(DEBUG_9P, "fid %d\n", fid); 128 dprintk(DEBUG_9P, "fid %d\n", fid);
104 msg.id = TCLUNK; 129 tc->id = TCLUNK;
105 msg.params.tclunk.fid = fid; 130 tc->params.tclunk.fid = fid;
106 131
107 return v9fs_mux_rpc(v9ses, &msg, fcall); 132 err = v9fs_mux_rpc(v9ses->mux, tc, &rc);
133 if (err >= 0) {
134 v9fs_t_clunk_cb(v9ses, tc, rc, 0);
135 }
136
137 return err;
108} 138}
109 139
110/** 140/**
@@ -121,7 +151,7 @@ int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 tag)
121 dprintk(DEBUG_9P, "oldtag %d\n", tag); 151 dprintk(DEBUG_9P, "oldtag %d\n", tag);
122 msg.id = TFLUSH; 152 msg.id = TFLUSH;
123 msg.params.tflush.oldtag = tag; 153 msg.params.tflush.oldtag = tag;
124 return v9fs_mux_rpc(v9ses, &msg, NULL); 154 return v9fs_mux_rpc(v9ses->mux, &msg, NULL);
125} 155}
126 156
127/** 157/**
@@ -143,7 +173,7 @@ v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid, struct v9fs_fcall **fcall)
143 173
144 msg.id = TSTAT; 174 msg.id = TSTAT;
145 msg.params.tstat.fid = fid; 175 msg.params.tstat.fid = fid;
146 return v9fs_mux_rpc(v9ses, &msg, fcall); 176 return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
147} 177}
148 178
149/** 179/**
@@ -166,7 +196,7 @@ v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,
166 msg.params.twstat.fid = fid; 196 msg.params.twstat.fid = fid;
167 msg.params.twstat.stat = stat; 197 msg.params.twstat.stat = stat;
168 198
169 return v9fs_mux_rpc(v9ses, &msg, fcall); 199 return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
170} 200}
171 201
172/** 202/**
@@ -199,7 +229,7 @@ v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
199 msg.params.twalk.nwname = 0; 229 msg.params.twalk.nwname = 0;
200 } 230 }
201 231
202 return v9fs_mux_rpc(v9ses, &msg, fcall); 232 return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
203} 233}
204 234
205/** 235/**
@@ -217,14 +247,14 @@ v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,
217 struct v9fs_fcall **fcall) 247 struct v9fs_fcall **fcall)
218{ 248{
219 struct v9fs_fcall msg; 249 struct v9fs_fcall msg;
220 long errorno = -1; 250 int errorno = -1;
221 251
222 dprintk(DEBUG_9P, "fid %d mode %d\n", fid, mode); 252 dprintk(DEBUG_9P, "fid %d mode %d\n", fid, mode);
223 msg.id = TOPEN; 253 msg.id = TOPEN;
224 msg.params.topen.fid = fid; 254 msg.params.topen.fid = fid;
225 msg.params.topen.mode = mode; 255 msg.params.topen.mode = mode;
226 256
227 errorno = v9fs_mux_rpc(v9ses, &msg, fcall); 257 errorno = v9fs_mux_rpc(v9ses->mux, &msg, fcall);
228 258
229 return errorno; 259 return errorno;
230} 260}
@@ -246,7 +276,7 @@ v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,
246 dprintk(DEBUG_9P, "fid %d\n", fid); 276 dprintk(DEBUG_9P, "fid %d\n", fid);
247 msg.id = TREMOVE; 277 msg.id = TREMOVE;
248 msg.params.tremove.fid = fid; 278 msg.params.tremove.fid = fid;
249 return v9fs_mux_rpc(v9ses, &msg, fcall); 279 return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
250} 280}
251 281
252/** 282/**
@@ -275,7 +305,7 @@ v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name,
275 msg.params.tcreate.perm = perm; 305 msg.params.tcreate.perm = perm;
276 msg.params.tcreate.mode = mode; 306 msg.params.tcreate.mode = mode;
277 307
278 return v9fs_mux_rpc(v9ses, &msg, fcall); 308 return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
279} 309}
280 310
281/** 311/**
@@ -302,7 +332,7 @@ v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
302 msg.params.tread.fid = fid; 332 msg.params.tread.fid = fid;
303 msg.params.tread.offset = offset; 333 msg.params.tread.offset = offset;
304 msg.params.tread.count = count; 334 msg.params.tread.count = count;
305 errorno = v9fs_mux_rpc(v9ses, &msg, &rc); 335 errorno = v9fs_mux_rpc(v9ses->mux, &msg, &rc);
306 336
307 if (!errorno) { 337 if (!errorno) {
308 errorno = rc->params.rread.count; 338 errorno = rc->params.rread.count;
@@ -345,7 +375,7 @@ v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid,
345 msg.params.twrite.count = count; 375 msg.params.twrite.count = count;
346 msg.params.twrite.data = data; 376 msg.params.twrite.data = data;
347 377
348 errorno = v9fs_mux_rpc(v9ses, &msg, &rc); 378 errorno = v9fs_mux_rpc(v9ses->mux, &msg, &rc);
349 379
350 if (!errorno) 380 if (!errorno)
351 errorno = rc->params.rwrite.count; 381 errorno = rc->params.rwrite.count;
diff --git a/fs/9p/9p.h b/fs/9p/9p.h
index f55424216be2..6355392786e2 100644
--- a/fs/9p/9p.h
+++ b/fs/9p/9p.h
@@ -100,6 +100,9 @@ enum {
100 V9FS_QTFILE = 0x00, 100 V9FS_QTFILE = 0x00,
101}; 101};
102 102
103#define V9FS_NOTAG (u16)(~0)
104#define V9FS_NOFID (u32)(~0)
105
103/* ample room for Twrite/Rread header (iounit) */ 106/* ample room for Twrite/Rread header (iounit) */
104#define V9FS_IOHDRSZ 24 107#define V9FS_IOHDRSZ 24
105 108
@@ -303,6 +306,9 @@ struct v9fs_fcall {
303 } params; 306 } params;
304}; 307};
305 308
309#define V9FS_FCALLHDRSZ (sizeof(struct v9fs_fcall) + \
310 sizeof(struct v9fs_stat) + 16*sizeof(struct v9fs_qid) + 16)
311
306#define FCALL_ERROR(fcall) (fcall ? fcall->params.rerror.error : "") 312#define FCALL_ERROR(fcall) (fcall ? fcall->params.rerror.error : "")
307 313
308int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize, 314int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
@@ -311,8 +317,7 @@ int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
311int v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname, 317int v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
312 u32 fid, u32 afid, struct v9fs_fcall **rcall); 318 u32 fid, u32 afid, struct v9fs_fcall **rcall);
313 319
314int v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid, 320int v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid);
315 struct v9fs_fcall **rcall);
316 321
317int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag); 322int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag);
318 323
diff --git a/fs/9p/conv.c b/fs/9p/conv.c
index 18121af99d3e..1b9b15dfeaf0 100644
--- a/fs/9p/conv.c
+++ b/fs/9p/conv.c
@@ -208,7 +208,7 @@ static inline char *buf_get_stringb(struct cbuf *buf, struct cbuf *sbuf)
208 len = buf_get_int16(buf); 208 len = buf_get_int16(buf);
209 209
210 if (!buf_check_overflow(buf) && buf_check_size(buf, len) && 210 if (!buf_check_overflow(buf) && buf_check_size(buf, len) &&
211 buf_check_size(sbuf, len+1)) { 211 buf_check_size(sbuf, len + 1)) {
212 212
213 memcpy(sbuf->p, buf->p, len); 213 memcpy(sbuf->p, buf->p, len);
214 sbuf->p[len] = 0; 214 sbuf->p[len] = 0;
@@ -252,13 +252,12 @@ static inline void *buf_get_datab(struct cbuf *buf, struct cbuf *dbuf,
252 252
253/** 253/**
254 * v9fs_size_stat - calculate the size of a variable length stat struct 254 * v9fs_size_stat - calculate the size of a variable length stat struct
255 * @v9ses: session information
256 * @stat: metadata (stat) structure 255 * @stat: metadata (stat) structure
256 * @extended: non-zero if 9P2000.u
257 * 257 *
258 */ 258 */
259 259
260static int v9fs_size_stat(struct v9fs_session_info *v9ses, 260static int v9fs_size_stat(struct v9fs_stat *stat, int extended)
261 struct v9fs_stat *stat)
262{ 261{
263 int size = 0; 262 int size = 0;
264 263
@@ -288,7 +287,7 @@ static int v9fs_size_stat(struct v9fs_session_info *v9ses,
288 if (stat->muid) 287 if (stat->muid)
289 size += strlen(stat->muid); 288 size += strlen(stat->muid);
290 289
291 if (v9ses->extended) { 290 if (extended) {
292 size += 4 + /* n_uid[4] */ 291 size += 4 + /* n_uid[4] */
293 4 + /* n_gid[4] */ 292 4 + /* n_gid[4] */
294 4 + /* n_muid[4] */ 293 4 + /* n_muid[4] */
@@ -302,15 +301,14 @@ static int v9fs_size_stat(struct v9fs_session_info *v9ses,
302 301
303/** 302/**
304 * serialize_stat - safely format a stat structure for transmission 303 * serialize_stat - safely format a stat structure for transmission
305 * @v9ses: session info
306 * @stat: metadata (stat) structure 304 * @stat: metadata (stat) structure
307 * @bufp: buffer to serialize structure into 305 * @bufp: buffer to serialize structure into
306 * @extended: non-zero if 9P2000.u
308 * 307 *
309 */ 308 */
310 309
311static int 310static int
312serialize_stat(struct v9fs_session_info *v9ses, struct v9fs_stat *stat, 311serialize_stat(struct v9fs_stat *stat, struct cbuf *bufp, int extended)
313 struct cbuf *bufp)
314{ 312{
315 buf_put_int16(bufp, stat->size); 313 buf_put_int16(bufp, stat->size);
316 buf_put_int16(bufp, stat->type); 314 buf_put_int16(bufp, stat->type);
@@ -328,7 +326,7 @@ serialize_stat(struct v9fs_session_info *v9ses, struct v9fs_stat *stat,
328 buf_put_string(bufp, stat->gid); 326 buf_put_string(bufp, stat->gid);
329 buf_put_string(bufp, stat->muid); 327 buf_put_string(bufp, stat->muid);
330 328
331 if (v9ses->extended) { 329 if (extended) {
332 buf_put_string(bufp, stat->extension); 330 buf_put_string(bufp, stat->extension);
333 buf_put_int32(bufp, stat->n_uid); 331 buf_put_int32(bufp, stat->n_uid);
334 buf_put_int32(bufp, stat->n_gid); 332 buf_put_int32(bufp, stat->n_gid);
@@ -343,16 +341,16 @@ serialize_stat(struct v9fs_session_info *v9ses, struct v9fs_stat *stat,
343 341
344/** 342/**
345 * deserialize_stat - safely decode a recieved metadata (stat) structure 343 * deserialize_stat - safely decode a recieved metadata (stat) structure
346 * @v9ses: session info
347 * @bufp: buffer to deserialize 344 * @bufp: buffer to deserialize
348 * @stat: metadata (stat) structure 345 * @stat: metadata (stat) structure
349 * @dbufp: buffer to deserialize variable strings into 346 * @dbufp: buffer to deserialize variable strings into
347 * @extended: non-zero if 9P2000.u
350 * 348 *
351 */ 349 */
352 350
353static inline int 351static inline int
354deserialize_stat(struct v9fs_session_info *v9ses, struct cbuf *bufp, 352deserialize_stat(struct cbuf *bufp, struct v9fs_stat *stat,
355 struct v9fs_stat *stat, struct cbuf *dbufp) 353 struct cbuf *dbufp, int extended)
356{ 354{
357 355
358 stat->size = buf_get_int16(bufp); 356 stat->size = buf_get_int16(bufp);
@@ -370,7 +368,7 @@ deserialize_stat(struct v9fs_session_info *v9ses, struct cbuf *bufp,
370 stat->gid = buf_get_stringb(bufp, dbufp); 368 stat->gid = buf_get_stringb(bufp, dbufp);
371 stat->muid = buf_get_stringb(bufp, dbufp); 369 stat->muid = buf_get_stringb(bufp, dbufp);
372 370
373 if (v9ses->extended) { 371 if (extended) {
374 stat->extension = buf_get_stringb(bufp, dbufp); 372 stat->extension = buf_get_stringb(bufp, dbufp);
375 stat->n_uid = buf_get_int32(bufp); 373 stat->n_uid = buf_get_int32(bufp);
376 stat->n_gid = buf_get_int32(bufp); 374 stat->n_gid = buf_get_int32(bufp);
@@ -385,20 +383,20 @@ deserialize_stat(struct v9fs_session_info *v9ses, struct cbuf *bufp,
385 383
386/** 384/**
387 * deserialize_statb - wrapper for decoding a received metadata structure 385 * deserialize_statb - wrapper for decoding a received metadata structure
388 * @v9ses: session info
389 * @bufp: buffer to deserialize 386 * @bufp: buffer to deserialize
390 * @dbufp: buffer to deserialize variable strings into 387 * @dbufp: buffer to deserialize variable strings into
388 * @extended: non-zero if 9P2000.u
391 * 389 *
392 */ 390 */
393 391
394static inline struct v9fs_stat *deserialize_statb(struct v9fs_session_info 392static inline struct v9fs_stat *deserialize_statb(struct cbuf *bufp,
395 *v9ses, struct cbuf *bufp, 393 struct cbuf *dbufp,
396 struct cbuf *dbufp) 394 int extended)
397{ 395{
398 struct v9fs_stat *ret = buf_alloc(dbufp, sizeof(struct v9fs_stat)); 396 struct v9fs_stat *ret = buf_alloc(dbufp, sizeof(struct v9fs_stat));
399 397
400 if (ret) { 398 if (ret) {
401 int n = deserialize_stat(v9ses, bufp, ret, dbufp); 399 int n = deserialize_stat(bufp, ret, dbufp, extended);
402 if (n <= 0) 400 if (n <= 0)
403 return NULL; 401 return NULL;
404 } 402 }
@@ -408,17 +406,16 @@ static inline struct v9fs_stat *deserialize_statb(struct v9fs_session_info
408 406
409/** 407/**
410 * v9fs_deserialize_stat - decode a received metadata structure 408 * v9fs_deserialize_stat - decode a received metadata structure
411 * @v9ses: session info
412 * @buf: buffer to deserialize 409 * @buf: buffer to deserialize
413 * @buflen: length of received buffer 410 * @buflen: length of received buffer
414 * @stat: metadata structure to decode into 411 * @stat: metadata structure to decode into
415 * @statlen: length of destination metadata structure 412 * @statlen: length of destination metadata structure
413 * @extended: non-zero if 9P2000.u
416 * 414 *
417 */ 415 */
418 416
419int 417int v9fs_deserialize_stat(void *buf, u32 buflen, struct v9fs_stat *stat,
420v9fs_deserialize_stat(struct v9fs_session_info *v9ses, void *buf, 418 u32 statlen, int extended)
421 u32 buflen, struct v9fs_stat *stat, u32 statlen)
422{ 419{
423 struct cbuf buffer; 420 struct cbuf buffer;
424 struct cbuf *bufp = &buffer; 421 struct cbuf *bufp = &buffer;
@@ -429,11 +426,10 @@ v9fs_deserialize_stat(struct v9fs_session_info *v9ses, void *buf,
429 buf_init(dbufp, (char *)stat + sizeof(struct v9fs_stat), 426 buf_init(dbufp, (char *)stat + sizeof(struct v9fs_stat),
430 statlen - sizeof(struct v9fs_stat)); 427 statlen - sizeof(struct v9fs_stat));
431 428
432 return deserialize_stat(v9ses, bufp, stat, dbufp); 429 return deserialize_stat(bufp, stat, dbufp, extended);
433} 430}
434 431
435static inline int 432static inline int v9fs_size_fcall(struct v9fs_fcall *fcall, int extended)
436v9fs_size_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall)
437{ 433{
438 int size = 4 + 1 + 2; /* size[4] msg[1] tag[2] */ 434 int size = 4 + 1 + 2; /* size[4] msg[1] tag[2] */
439 int i = 0; 435 int i = 0;
@@ -485,7 +481,7 @@ v9fs_size_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall)
485 break; 481 break;
486 case TWSTAT: /* fid[4] stat[n] */ 482 case TWSTAT: /* fid[4] stat[n] */
487 fcall->params.twstat.stat->size = 483 fcall->params.twstat.stat->size =
488 v9fs_size_stat(v9ses, fcall->params.twstat.stat); 484 v9fs_size_stat(fcall->params.twstat.stat, extended);
489 size += 4 + 2 + 2 + fcall->params.twstat.stat->size; 485 size += 4 + 2 + 2 + fcall->params.twstat.stat->size;
490 } 486 }
491 return size; 487 return size;
@@ -493,16 +489,16 @@ v9fs_size_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall)
493 489
494/* 490/*
495 * v9fs_serialize_fcall - marshall fcall struct into a packet 491 * v9fs_serialize_fcall - marshall fcall struct into a packet
496 * @v9ses: session information
497 * @fcall: structure to convert 492 * @fcall: structure to convert
498 * @data: buffer to serialize fcall into 493 * @data: buffer to serialize fcall into
499 * @datalen: length of buffer to serialize fcall into 494 * @datalen: length of buffer to serialize fcall into
495 * @extended: non-zero if 9P2000.u
500 * 496 *
501 */ 497 */
502 498
503int 499int
504v9fs_serialize_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall, 500v9fs_serialize_fcall(struct v9fs_fcall *fcall, void *data, u32 datalen,
505 void *data, u32 datalen) 501 int extended)
506{ 502{
507 int i = 0; 503 int i = 0;
508 struct v9fs_stat *stat = NULL; 504 struct v9fs_stat *stat = NULL;
@@ -516,7 +512,7 @@ v9fs_serialize_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall,
516 return -EINVAL; 512 return -EINVAL;
517 } 513 }
518 514
519 fcall->size = v9fs_size_fcall(v9ses, fcall); 515 fcall->size = v9fs_size_fcall(fcall, extended);
520 516
521 buf_put_int32(bufp, fcall->size); 517 buf_put_int32(bufp, fcall->size);
522 buf_put_int8(bufp, fcall->id); 518 buf_put_int8(bufp, fcall->id);
@@ -591,31 +587,31 @@ v9fs_serialize_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall,
591 stat = fcall->params.twstat.stat; 587 stat = fcall->params.twstat.stat;
592 588
593 buf_put_int16(bufp, stat->size + 2); 589 buf_put_int16(bufp, stat->size + 2);
594 serialize_stat(v9ses, stat, bufp); 590 serialize_stat(stat, bufp, extended);
595 break; 591 break;
596 } 592 }
597 593
598 if (buf_check_overflow(bufp)) 594 if (buf_check_overflow(bufp)) {
595 dprintk(DEBUG_ERROR, "buffer overflow\n");
599 return -EIO; 596 return -EIO;
597 }
600 598
601 return fcall->size; 599 return fcall->size;
602} 600}
603 601
604/** 602/**
605 * deserialize_fcall - unmarshal a response 603 * deserialize_fcall - unmarshal a response
606 * @v9ses: session information
607 * @msgsize: size of rcall message
608 * @buf: recieved buffer 604 * @buf: recieved buffer
609 * @buflen: length of received buffer 605 * @buflen: length of received buffer
610 * @rcall: fcall structure to populate 606 * @rcall: fcall structure to populate
611 * @rcalllen: length of fcall structure to populate 607 * @rcalllen: length of fcall structure to populate
608 * @extended: non-zero if 9P2000.u
612 * 609 *
613 */ 610 */
614 611
615int 612int
616v9fs_deserialize_fcall(struct v9fs_session_info *v9ses, u32 msgsize, 613v9fs_deserialize_fcall(void *buf, u32 buflen, struct v9fs_fcall *rcall,
617 void *buf, u32 buflen, struct v9fs_fcall *rcall, 614 int rcalllen, int extended)
618 int rcalllen)
619{ 615{
620 616
621 struct cbuf buffer; 617 struct cbuf buffer;
@@ -628,7 +624,7 @@ v9fs_deserialize_fcall(struct v9fs_session_info *v9ses, u32 msgsize,
628 buf_init(dbufp, (char *)rcall + sizeof(struct v9fs_fcall), 624 buf_init(dbufp, (char *)rcall + sizeof(struct v9fs_fcall),
629 rcalllen - sizeof(struct v9fs_fcall)); 625 rcalllen - sizeof(struct v9fs_fcall));
630 626
631 rcall->size = msgsize; 627 rcall->size = buf_get_int32(bufp);
632 rcall->id = buf_get_int8(bufp); 628 rcall->id = buf_get_int8(bufp);
633 rcall->tag = buf_get_int16(bufp); 629 rcall->tag = buf_get_int16(bufp);
634 630
@@ -651,6 +647,12 @@ v9fs_deserialize_fcall(struct v9fs_session_info *v9ses, u32 msgsize,
651 break; 647 break;
652 case RWALK: 648 case RWALK:
653 rcall->params.rwalk.nwqid = buf_get_int16(bufp); 649 rcall->params.rwalk.nwqid = buf_get_int16(bufp);
650 if (rcall->params.rwalk.nwqid > 16) {
651 eprintk(KERN_ERR, "Rwalk with more than 16 qids: %d\n",
652 rcall->params.rwalk.nwqid);
653 return -EPROTO;
654 }
655
654 rcall->params.rwalk.wqids = buf_alloc(dbufp, 656 rcall->params.rwalk.wqids = buf_alloc(dbufp,
655 rcall->params.rwalk.nwqid * sizeof(struct v9fs_qid)); 657 rcall->params.rwalk.nwqid * sizeof(struct v9fs_qid));
656 if (rcall->params.rwalk.wqids) 658 if (rcall->params.rwalk.wqids)
@@ -690,19 +692,21 @@ v9fs_deserialize_fcall(struct v9fs_session_info *v9ses, u32 msgsize,
690 case RSTAT: 692 case RSTAT:
691 buf_get_int16(bufp); 693 buf_get_int16(bufp);
692 rcall->params.rstat.stat = 694 rcall->params.rstat.stat =
693 deserialize_statb(v9ses, bufp, dbufp); 695 deserialize_statb(bufp, dbufp, extended);
694 break; 696 break;
695 case RWSTAT: 697 case RWSTAT:
696 break; 698 break;
697 case RERROR: 699 case RERROR:
698 rcall->params.rerror.error = buf_get_stringb(bufp, dbufp); 700 rcall->params.rerror.error = buf_get_stringb(bufp, dbufp);
699 if (v9ses->extended) 701 if (extended)
700 rcall->params.rerror.errno = buf_get_int16(bufp); 702 rcall->params.rerror.errno = buf_get_int16(bufp);
701 break; 703 break;
702 } 704 }
703 705
704 if (buf_check_overflow(bufp) || buf_check_overflow(dbufp)) 706 if (buf_check_overflow(bufp) || buf_check_overflow(dbufp)) {
707 dprintk(DEBUG_ERROR, "buffer overflow\n");
705 return -EIO; 708 return -EIO;
709 }
706 710
707 return rcall->size; 711 return rcall->size;
708} 712}
diff --git a/fs/9p/conv.h b/fs/9p/conv.h
index ee849613c61a..d5e33e17a685 100644
--- a/fs/9p/conv.h
+++ b/fs/9p/conv.h
@@ -24,13 +24,12 @@
24 * 24 *
25 */ 25 */
26 26
27int v9fs_deserialize_stat(struct v9fs_session_info *, void *buf, 27int v9fs_deserialize_stat(void *buf, u32 buflen, struct v9fs_stat *stat,
28 u32 buflen, struct v9fs_stat *stat, u32 statlen); 28 u32 statlen, int extended);
29int v9fs_serialize_fcall(struct v9fs_session_info *, struct v9fs_fcall *tcall, 29int v9fs_serialize_fcall(struct v9fs_fcall *tcall, void *buf, u32 buflen,
30 void *buf, u32 buflen); 30 int extended);
31int v9fs_deserialize_fcall(struct v9fs_session_info *, u32 msglen, 31int v9fs_deserialize_fcall(void *buf, u32 buflen, struct v9fs_fcall *rcall,
32 void *buf, u32 buflen, struct v9fs_fcall *rcall, 32 int rcalllen, int extended);
33 int rcalllen);
34 33
35/* this one is actually in error.c right now */ 34/* this one is actually in error.c right now */
36int v9fs_errstr2errno(char *errstr); 35int v9fs_errstr2errno(char *errstr);
diff --git a/fs/9p/fid.c b/fs/9p/fid.c
index d95f8626d170..60ef8aba757a 100644
--- a/fs/9p/fid.c
+++ b/fs/9p/fid.c
@@ -164,7 +164,7 @@ static struct v9fs_fid *v9fs_fid_walk_up(struct dentry *dentry)
164 return v9fs_fid_create(dentry, v9ses, fidnum, 0); 164 return v9fs_fid_create(dentry, v9ses, fidnum, 0);
165 165
166clunk_fid: 166clunk_fid:
167 v9fs_t_clunk(v9ses, fidnum, NULL); 167 v9fs_t_clunk(v9ses, fidnum);
168 return ERR_PTR(err); 168 return ERR_PTR(err);
169} 169}
170 170
diff --git a/fs/9p/mux.c b/fs/9p/mux.c
index 8835b576f744..62b6ad0767e1 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,6 +28,7 @@
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
@@ -38,438 +39,903 @@
38#include "conv.h" 39#include "conv.h"
39#include "mux.h" 40#include "mux.h"
40 41
41/** 42#define ERREQFLUSH 1
42 * dprintcond - print condition of session info 43#define SCHED_TIMEOUT 10
43 * @v9ses: session info structure 44#define MAXPOLLWADDR 2
44 * @req: RPC request structure 45
45 * 46enum {
46 */ 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
53struct v9fs_mux_poll_task;
54
55struct 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
65struct 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 int rpos;
78 char *rbuf;
79 int wpos;
80 int wsize;
81 char *wbuf;
82 wait_queue_t poll_wait[MAXPOLLWADDR];
83 wait_queue_head_t *poll_waddr[MAXPOLLWADDR];
84 poll_table pt;
85 struct work_struct rq;
86 struct work_struct wq;
87 unsigned long wsched;
88};
89
90struct v9fs_mux_poll_task {
91 struct task_struct *task;
92 struct list_head mux_list;
93 int muxnum;
94};
95
96struct v9fs_mux_rpc {
97 struct v9fs_mux_data *m;
98 struct v9fs_req *req;
99 int err;
100 struct v9fs_fcall *rcall;
101 wait_queue_head_t wqueue;
102};
103
104static int v9fs_poll_proc(void *);
105static void v9fs_read_work(void *);
106static void v9fs_write_work(void *);
107static void v9fs_pollwait(struct file *filp, wait_queue_head_t * wait_address,
108 poll_table * p);
109
110static DECLARE_MUTEX(v9fs_mux_task_lock);
111static struct workqueue_struct *v9fs_mux_wq;
112
113static int v9fs_mux_num;
114static int v9fs_mux_poll_task_num;
115static struct v9fs_mux_poll_task v9fs_mux_poll_tasks[100];
116
117void v9fs_mux_global_init(void)
118{
119 int i;
120
121 for (i = 0; i < ARRAY_SIZE(v9fs_mux_poll_tasks); i++)
122 v9fs_mux_poll_tasks[i].task = NULL;
123
124 v9fs_mux_wq = create_workqueue("v9fs");
125}
47 126
48static inline int 127void v9fs_mux_global_exit(void)
49dprintcond(struct v9fs_session_info *v9ses, struct v9fs_rpcreq *req)
50{ 128{
51 dprintk(DEBUG_MUX, "condition: %d, %p\n", v9ses->transport->status, 129 destroy_workqueue(v9fs_mux_wq);
52 req->rcall);
53 return 0;
54} 130}
55 131
56/** 132/**
57 * xread - force read of a certain number of bytes 133 * v9fs_mux_calc_poll_procs - calculates the number of polling procs
58 * @v9ses: session info structure 134 * based on the number of mounted v9fs filesystems.
59 * @ptr: pointer to buffer
60 * @sz: number of bytes to read
61 * 135 *
62 * Chuck Cranor CS-533 project1 136 * The current implementation returns sqrt of the number of mounts.
63 */ 137 */
138inline int v9fs_mux_calc_poll_procs(int muxnum)
139{
140 int n;
141
142 if (v9fs_mux_poll_task_num)
143 n = muxnum / v9fs_mux_poll_task_num +
144 (muxnum % v9fs_mux_poll_task_num ? 1 : 0);
145 else
146 n = 1;
147
148 if (n > ARRAY_SIZE(v9fs_mux_poll_tasks))
149 n = ARRAY_SIZE(v9fs_mux_poll_tasks);
64 150
65static int xread(struct v9fs_session_info *v9ses, void *ptr, unsigned long sz) 151 return n;
152}
153
154static void v9fs_mux_poll_start(struct v9fs_mux_data *m)
66{ 155{
67 int rd = 0; 156 int i, n;
68 int ret = 0; 157 struct v9fs_mux_poll_task *vpt, *vptlast;
69 while (rd < sz) { 158
70 ret = v9ses->transport->read(v9ses->transport, ptr, sz - rd); 159 dprintk(DEBUG_MUX, "mux %p muxnum %d procnum %d\n", m, v9fs_mux_num,
71 if (ret <= 0) { 160 v9fs_mux_poll_task_num);
72 dprintk(DEBUG_ERROR, "xread errno %d\n", ret); 161 up(&v9fs_mux_task_lock);
73 return ret; 162
163 n = v9fs_mux_calc_poll_procs(v9fs_mux_num + 1);
164 if (n > v9fs_mux_poll_task_num) {
165 for (i = 0; i < ARRAY_SIZE(v9fs_mux_poll_tasks); i++) {
166 if (v9fs_mux_poll_tasks[i].task == NULL) {
167 vpt = &v9fs_mux_poll_tasks[i];
168 dprintk(DEBUG_MUX, "create proc %p\n", vpt);
169 vpt->task = kthread_create(v9fs_poll_proc,
170 vpt, "v9fs-poll");
171 INIT_LIST_HEAD(&vpt->mux_list);
172 vpt->muxnum = 0;
173 v9fs_mux_poll_task_num++;
174 wake_up_process(vpt->task);
175 break;
176 }
74 } 177 }
75 rd += ret;
76 ptr += ret;
77 }
78 return (rd);
79}
80 178
81/** 179 if (i >= ARRAY_SIZE(v9fs_mux_poll_tasks))
82 * read_message - read a full 9P2000 fcall packet 180 dprintk(DEBUG_ERROR, "warning: no free poll slots\n");
83 * @v9ses: session info structure 181 }
84 * @rcall: fcall structure to read into
85 * @rcalllen: size of fcall buffer
86 *
87 */
88 182
89static int 183 n = (v9fs_mux_num + 1) / v9fs_mux_poll_task_num +
90read_message(struct v9fs_session_info *v9ses, 184 ((v9fs_mux_num + 1) % v9fs_mux_poll_task_num ? 1 : 0);
91 struct v9fs_fcall *rcall, int rcalllen) 185
92{ 186 vptlast = NULL;
93 unsigned char buf[4]; 187 for (i = 0; i < ARRAY_SIZE(v9fs_mux_poll_tasks); i++) {
94 void *data; 188 vpt = &v9fs_mux_poll_tasks[i];
95 int size = 0; 189 if (vpt->task != NULL) {
96 int res = 0; 190 vptlast = vpt;
97 191 if (vpt->muxnum < n) {
98 res = xread(v9ses, buf, sizeof(buf)); 192 dprintk(DEBUG_MUX, "put in proc %d\n", i);
99 if (res < 0) { 193 list_add(&m->mux_list, &vpt->mux_list);
100 dprintk(DEBUG_ERROR, 194 vpt->muxnum++;
101 "Reading of count field failed returned: %d\n", res); 195 m->poll_task = vpt;
102 return res; 196 memset(&m->poll_waddr, 0, sizeof(m->poll_waddr));
197 init_poll_funcptr(&m->pt, v9fs_pollwait);
198 break;
199 }
200 }
103 } 201 }
104 202
105 if (res < 4) { 203 if (i >= ARRAY_SIZE(v9fs_mux_poll_tasks)) {
106 dprintk(DEBUG_ERROR, 204 dprintk(DEBUG_MUX, "put in proc %d\n", i);
107 "Reading of count field failed returned: %d\n", res); 205 list_add(&m->mux_list, &vptlast->mux_list);
108 return -EIO; 206 vptlast->muxnum++;
207 m->poll_task = vpt;
208 memset(&m->poll_waddr, 0, sizeof(m->poll_waddr));
209 init_poll_funcptr(&m->pt, v9fs_pollwait);
109 } 210 }
110 211
111 size = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); 212 v9fs_mux_num++;
112 dprintk(DEBUG_MUX, "got a packet count: %d\n", size); 213 down(&v9fs_mux_task_lock);
214}
113 215
114 /* adjust for the four bytes of size */ 216static void v9fs_mux_poll_stop(struct v9fs_mux_data *m)
115 size -= 4; 217{
218 int i;
219 struct v9fs_mux_poll_task *vpt;
220
221 up(&v9fs_mux_task_lock);
222 vpt = m->poll_task;
223 list_del(&m->mux_list);
224 for(i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) {
225 if (m->poll_waddr[i] != NULL) {
226 remove_wait_queue(m->poll_waddr[i], &m->poll_wait[i]);
227 m->poll_waddr[i] = NULL;
228 }
229 }
230 vpt->muxnum--;
231 if (!vpt->muxnum) {
232 dprintk(DEBUG_MUX, "destroy proc %p\n", vpt);
233 send_sig(SIGKILL, vpt->task, 1);
234 vpt->task = NULL;
235 v9fs_mux_poll_task_num--;
236 }
237 v9fs_mux_num--;
238 down(&v9fs_mux_task_lock);
239}
116 240
117 if (size > v9ses->maxdata) { 241/**
118 dprintk(DEBUG_ERROR, "packet too big: %d\n", size); 242 * v9fs_mux_init - allocate and initialize the per-session mux data
119 return -E2BIG; 243 * Creates the polling task if this is the first session.
244 *
245 * @trans - transport structure
246 * @msize - maximum message size
247 * @extended - pointer to the extended flag
248 */
249struct v9fs_mux_data *v9fs_mux_init(struct v9fs_transport *trans, int msize,
250 unsigned char *extended)
251{
252 int i, n;
253 struct v9fs_mux_data *m, *mtmp;
254
255 dprintk(DEBUG_MUX, "transport %p msize %d\n", trans, msize);
256 m = kmalloc(sizeof(struct v9fs_mux_data) + 2 * msize, GFP_KERNEL);
257 if (!m)
258 return ERR_PTR(-ENOMEM);
259
260 spin_lock_init(&m->lock);
261 INIT_LIST_HEAD(&m->mux_list);
262 m->msize = msize;
263 m->extended = extended;
264 m->trans = trans;
265 idr_init(&m->tidpool.pool);
266 init_MUTEX(&m->tidpool.lock);
267 m->err = 0;
268 init_waitqueue_head(&m->equeue);
269 INIT_LIST_HEAD(&m->req_list);
270 INIT_LIST_HEAD(&m->unsent_req_list);
271 m->rpos = 0;
272 m->rbuf = (char *)m + sizeof(struct v9fs_mux_data);
273 m->wpos = m->wsize = 0;
274 m->wbuf = m->rbuf + msize;
275 INIT_WORK(&m->rq, v9fs_read_work, m);
276 INIT_WORK(&m->wq, v9fs_write_work, m);
277 m->wsched = 0;
278 memset(&m->poll_waddr, 0, sizeof(m->poll_waddr));
279 v9fs_mux_poll_start(m);
280
281 n = trans->poll(trans, &m->pt);
282 if (n & POLLIN) {
283 dprintk(DEBUG_MUX, "mux %p can read\n", m);
284 set_bit(Rpending, &m->wsched);
120 } 285 }
121 286
122 data = kmalloc(size, GFP_KERNEL); 287 if (n & POLLOUT) {
123 if (!data) { 288 dprintk(DEBUG_MUX, "mux %p can write\n", m);
124 eprintk(KERN_WARNING, "out of memory\n"); 289 set_bit(Wpending, &m->wsched);
125 return -ENOMEM;
126 } 290 }
127 291
128 res = xread(v9ses, data, size); 292 for(i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) {
129 if (res < size) { 293 if (IS_ERR(m->poll_waddr[i])) {
130 dprintk(DEBUG_ERROR, "Reading of fcall failed returned: %d\n", 294 v9fs_mux_poll_stop(m);
131 res); 295 mtmp = (void *)m->poll_waddr; /* the error code */
132 kfree(data); 296 kfree(m);
133 return res; 297 m = mtmp;
298 break;
299 }
134 } 300 }
135 301
136 /* we now have an in-memory string that is the reply. 302 return m;
137 * deserialize it. There is very little to go wrong at this point 303}
138 * save for v9fs_alloc errors.
139 */
140 res = v9fs_deserialize_fcall(v9ses, size, data, v9ses->maxdata,
141 rcall, rcalllen);
142 304
143 kfree(data); 305/**
306 * v9fs_mux_destroy - cancels all pending requests and frees mux resources
307 */
308void v9fs_mux_destroy(struct v9fs_mux_data *m)
309{
310 dprintk(DEBUG_MUX, "mux %p prev %p next %p\n", m,
311 m->mux_list.prev, m->mux_list.next);
312 v9fs_mux_cancel(m, -ECONNRESET);
313
314 if (!list_empty(&m->req_list)) {
315 /* wait until all processes waiting on this session exit */
316 dprintk(DEBUG_MUX, "mux %p waiting for empty request queue\n",
317 m);
318 wait_event_timeout(m->equeue, (list_empty(&m->req_list)), 5000);
319 dprintk(DEBUG_MUX, "mux %p request queue empty: %d\n", m,
320 list_empty(&m->req_list));
321 }
144 322
145 if (res < 0) 323 v9fs_mux_poll_stop(m);
146 return res; 324 m->trans = NULL;
147 325
148 return 0; 326 kfree(m);
149} 327}
150 328
151/** 329/**
152 * v9fs_recv - receive an RPC response for a particular tag 330 * v9fs_pollwait - called by files poll operation to add v9fs-poll task
153 * @v9ses: session info structure 331 * to files wait queue
154 * @req: RPC request structure
155 *
156 */ 332 */
157 333static void
158static int v9fs_recv(struct v9fs_session_info *v9ses, struct v9fs_rpcreq *req) 334v9fs_pollwait(struct file *filp, wait_queue_head_t * wait_address,
335 poll_table * p)
159{ 336{
160 int ret = 0; 337 int i;
161 338 struct v9fs_mux_data *m;
162 dprintk(DEBUG_MUX, "waiting for response: %d\n", req->tcall->tag);
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 339
168 dprintk(DEBUG_MUX, "got it: rcall %p\n", req->rcall); 340 m = container_of(p, struct v9fs_mux_data, pt);
341 for(i = 0; i < ARRAY_SIZE(m->poll_waddr); i++)
342 if (m->poll_waddr[i] == NULL)
343 break;
169 344
170 spin_lock(&v9ses->muxlock); 345 if (i >= ARRAY_SIZE(m->poll_waddr)) {
171 list_del(&req->next); 346 dprintk(DEBUG_ERROR, "not enough wait_address slots\n");
172 spin_unlock(&v9ses->muxlock); 347 return;
348 }
173 349
174 if (req->err < 0) 350 m->poll_waddr[i] = wait_address;
175 return req->err;
176 351
177 if (v9ses->transport->status == Disconnected) 352 if (!wait_address) {
178 return -ECONNRESET; 353 dprintk(DEBUG_ERROR, "no wait_address\n");
354 m->poll_waddr[i] = ERR_PTR(-EIO);
355 return;
356 }
179 357
180 return ret; 358 init_waitqueue_entry(&m->poll_wait[i], m->poll_task->task);
359 add_wait_queue(wait_address, &m->poll_wait[i]);
181} 360}
182 361
183/** 362/**
184 * v9fs_send - send a 9P request 363 * v9fs_poll_mux - polls a mux and schedules read or write works if necessary
185 * @v9ses: session info structure
186 * @req: RPC request to send
187 *
188 */ 364 */
189 365static inline void v9fs_poll_mux(struct v9fs_mux_data *m)
190static int v9fs_send(struct v9fs_session_info *v9ses, struct v9fs_rpcreq *req)
191{ 366{
192 int ret = -1; 367 int n;
193 void *data = NULL;
194 struct v9fs_fcall *tcall = req->tcall;
195
196 data = kmalloc(v9ses->maxdata + V9FS_IOHDRSZ, GFP_KERNEL);
197 if (!data)
198 return -ENOMEM;
199
200 tcall->size = 0; /* enforce size recalculation */
201 ret =
202 v9fs_serialize_fcall(v9ses, tcall, data,
203 v9ses->maxdata + V9FS_IOHDRSZ);
204 if (ret < 0)
205 goto free_data;
206
207 spin_lock(&v9ses->muxlock);
208 list_add(&req->next, &v9ses->mux_fcalls);
209 spin_unlock(&v9ses->muxlock);
210
211 dprintk(DEBUG_MUX, "sending message: tag %d size %d\n", tcall->tag,
212 tcall->size);
213 ret = v9ses->transport->write(v9ses->transport, data, tcall->size);
214
215 if (ret != tcall->size) {
216 spin_lock(&v9ses->muxlock);
217 list_del(&req->next);
218 kfree(req->rcall);
219 368
220 spin_unlock(&v9ses->muxlock); 369 if (m->err < 0)
221 if (ret >= 0) 370 return;
222 ret = -EREMOTEIO; 371
223 } else 372 n = m->trans->poll(m->trans, NULL);
224 ret = 0; 373 if (n < 0 || n & (POLLERR | POLLHUP | POLLNVAL)) {
374 dprintk(DEBUG_MUX, "error mux %p err %d\n", m, n);
375 if (n >= 0)
376 n = -ECONNRESET;
377 v9fs_mux_cancel(m, n);
378 }
379
380 if (n & POLLIN) {
381 set_bit(Rpending, &m->wsched);
382 dprintk(DEBUG_MUX, "mux %p can read\n", m);
383 if (!test_and_set_bit(Rworksched, &m->wsched)) {
384 dprintk(DEBUG_MUX, "schedule read work mux %p\n", m);
385 queue_work(v9fs_mux_wq, &m->rq);
386 }
387 }
225 388
226 free_data: 389 if (n & POLLOUT) {
227 kfree(data); 390 set_bit(Wpending, &m->wsched);
228 return ret; 391 dprintk(DEBUG_MUX, "mux %p can write\n", m);
392 if ((m->wsize || !list_empty(&m->unsent_req_list))
393 && !test_and_set_bit(Wworksched, &m->wsched)) {
394 dprintk(DEBUG_MUX, "schedule write work mux %p\n", m);
395 queue_work(v9fs_mux_wq, &m->wq);
396 }
397 }
229} 398}
230 399
231/** 400/**
232 * v9fs_mux_rpc - send a request, receive a response 401 * v9fs_poll_proc - polls all v9fs transports for new events and queues
233 * @v9ses: session info structure 402 * the appropriate work to the work queue
234 * @tcall: fcall to send
235 * @rcall: buffer to place response into
236 *
237 */ 403 */
238 404static int v9fs_poll_proc(void *a)
239long
240v9fs_mux_rpc(struct v9fs_session_info *v9ses, struct v9fs_fcall *tcall,
241 struct v9fs_fcall **rcall)
242{ 405{
243 int tid = -1; 406 struct v9fs_mux_data *m, *mtmp;
244 struct v9fs_fcall *fcall = NULL; 407 struct v9fs_mux_poll_task *vpt;
245 struct v9fs_rpcreq req;
246 int ret = -1;
247 408
248 if (!v9ses) 409 vpt = a;
249 return -EINVAL; 410 dprintk(DEBUG_MUX, "start %p %p\n", current, vpt);
411 allow_signal(SIGKILL);
412 while (!kthread_should_stop()) {
413 set_current_state(TASK_INTERRUPTIBLE);
414 if (signal_pending(current))
415 break;
250 416
251 if (!v9ses->transport || v9ses->transport->status != Connected) 417 list_for_each_entry_safe(m, mtmp, &vpt->mux_list, mux_list) {
252 return -EIO; 418 v9fs_poll_mux(m);
419 }
420
421 dprintk(DEBUG_MUX, "sleeping...\n");
422 schedule_timeout(SCHED_TIMEOUT * HZ);
423 }
253 424
254 if (rcall) 425 __set_current_state(TASK_RUNNING);
255 *rcall = NULL; 426 dprintk(DEBUG_MUX, "finish\n");
427 return 0;
428}
256 429
257 if (tcall->id != TVERSION) { 430static inline int v9fs_write_req(struct v9fs_mux_data *m, struct v9fs_req *req)
258 tid = v9fs_get_idpool(&v9ses->tidpool); 431{
259 if (tid < 0) 432 int n;
260 return -ENOMEM; 433
434 list_move_tail(&req->req_list, &m->req_list);
435 n = v9fs_serialize_fcall(req->tcall, m->wbuf, m->msize, *m->extended);
436 if (n < 0) {
437 req->err = n;
438 list_del(&req->req_list);
439 if (req->cb) {
440 spin_unlock(&m->lock);
441 (*req->cb) (req->cba, req->tcall, req->rcall, req->err);
442 req->cb = NULL;
443 spin_lock(&m->lock);
444 } else
445 kfree(req->rcall);
446
447 kfree(req);
261 } 448 }
262 449
263 tcall->tag = tid; 450 return n;
451}
264 452
265 req.tcall = tcall; 453/**
266 req.err = 0; 454 * v9fs_write_work - called when a transport can send some data
267 req.rcall = NULL; 455 */
456static void v9fs_write_work(void *a)
457{
458 int n, err;
459 struct v9fs_mux_data *m;
460 struct v9fs_req *req, *rtmp;
268 461
269 ret = v9fs_send(v9ses, &req); 462 m = a;
270 463
271 if (ret < 0) { 464 if (m->err < 0) {
272 if (tcall->id != TVERSION) 465 clear_bit(Wworksched, &m->wsched);
273 v9fs_put_idpool(tid, &v9ses->tidpool); 466 return;
274 dprintk(DEBUG_MUX, "error %d\n", ret);
275 return ret;
276 } 467 }
277 468
278 ret = v9fs_recv(v9ses, &req); 469 if (!m->wsize) {
279 470 if (list_empty(&m->unsent_req_list)) {
280 fcall = req.rcall; 471 clear_bit(Wworksched, &m->wsched);
281 472 return;
282 dprintk(DEBUG_MUX, "received: tag=%x, ret=%d\n", tcall->tag, ret);
283 if (ret == -ERESTARTSYS) {
284 if (v9ses->transport->status != Disconnected
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(&current->sighand->siglock, flags);
293 recalc_sigpending();
294 spin_unlock_irqrestore(&current->sighand->siglock,
295 flags);
296 dprintk(DEBUG_MUX, "flushing done\n");
297 } 473 }
298 474
299 goto release_req; 475 err = 0;
300 } else if (ret < 0) 476 spin_lock(&m->lock);
301 goto release_req; 477 list_for_each_entry_safe(req, rtmp, &m->unsent_req_list,
302 478 req_list) {
303 if (!fcall) 479 err = v9fs_write_req(m, req);
304 ret = -EIO; 480 if (err > 0)
305 else { 481 break;
306 if (fcall->id == RERROR) {
307 ret = v9fs_errstr2errno(fcall->params.rerror.error);
308 if (ret == 0) { /* string match failed */
309 if (fcall->params.rerror.errno)
310 ret = -(fcall->params.rerror.errno);
311 else
312 ret = -ESERVERFAULT;
313 }
314 } else if (fcall->id != tcall->id + 1) {
315 dprintk(DEBUG_ERROR,
316 "fcall mismatch: expected %d, got %d\n",
317 tcall->id + 1, fcall->id);
318 ret = -EIO;
319 } 482 }
483
484 m->wsize = err;
485 m->wpos = 0;
486 spin_unlock(&m->lock);
320 } 487 }
321 488
322 release_req: 489 dprintk(DEBUG_MUX, "mux %p pos %d size %d\n", m, m->wpos, m->wsize);
323 if (tcall->id != TVERSION) 490 clear_bit(Wpending, &m->wsched);
324 v9fs_put_idpool(tid, &v9ses->tidpool); 491 err = m->trans->write(m->trans, m->wbuf + m->wpos, m->wsize - m->wpos);
325 if (rcall) 492 dprintk(DEBUG_MUX, "mux %p sent %d bytes\n", m, err);
326 *rcall = fcall; 493 if (err == -EAGAIN) {
327 else 494 clear_bit(Wworksched, &m->wsched);
328 kfree(fcall); 495 return;
496 }
497
498 if (err <= 0)
499 goto error;
500
501 m->wpos += err;
502 if (m->wpos == m->wsize)
503 m->wpos = m->wsize = 0;
504
505 if (m->wsize == 0 && !list_empty(&m->unsent_req_list)) {
506 if (test_and_clear_bit(Wpending, &m->wsched))
507 n = POLLOUT;
508 else
509 n = m->trans->poll(m->trans, NULL);
510
511 if (n & POLLOUT) {
512 dprintk(DEBUG_MUX, "schedule write work mux %p\n", m);
513 queue_work(v9fs_mux_wq, &m->wq);
514 } else
515 clear_bit(Wworksched, &m->wsched);
516 } else
517 clear_bit(Wworksched, &m->wsched);
329 518
330 return ret; 519 return;
520
521 error:
522 v9fs_mux_cancel(m, err);
523 clear_bit(Wworksched, &m->wsched);
331} 524}
332 525
333/** 526static void process_request(struct v9fs_mux_data *m, struct v9fs_req *req)
334 * v9fs_mux_cancel_requests - cancels all pending requests
335 *
336 * @v9ses: session info structure
337 * @err: error code to return to the requests
338 */
339void v9fs_mux_cancel_requests(struct v9fs_session_info *v9ses, int err)
340{ 527{
341 struct v9fs_rpcreq *rptr; 528 int ecode, tag;
342 struct v9fs_rpcreq *rreq; 529 char *ename;
530
531 tag = req->tag;
532 if (req->rcall->id == RERROR && !req->err) {
533 ecode = req->rcall->params.rerror.errno;
534 ename = req->rcall->params.rerror.error;
343 535
344 dprintk(DEBUG_MUX, " %d\n", err); 536 dprintk(DEBUG_MUX, "Rerror %s\n", ename);
345 spin_lock(&v9ses->muxlock); 537
346 list_for_each_entry_safe(rreq, rptr, &v9ses->mux_fcalls, next) { 538 if (*m->extended)
347 rreq->err = err; 539 req->err = -ecode;
540
541 if (!req->err) {
542 req->err = v9fs_errstr2errno(ename);
543
544 if (!req->err) { /* string match failed */
545 dprintk(DEBUG_ERROR, "unknown error: %s\n",
546 ename);
547 }
548
549 if (!req->err)
550 req->err = -ESERVERFAULT;
551 }
552 } else if (req->tcall && req->rcall->id != req->tcall->id + 1) {
553 dprintk(DEBUG_ERROR, "fcall mismatch: expected %d, got %d\n",
554 req->tcall->id + 1, req->rcall->id);
555 if (!req->err)
556 req->err = -EIO;
348 } 557 }
349 spin_unlock(&v9ses->muxlock); 558
350 wake_up_all(&v9ses->read_wait); 559 if (req->cb && req->err != ERREQFLUSH) {
560 dprintk(DEBUG_MUX, "calling callback tcall %p rcall %p\n",
561 req->tcall, req->rcall);
562
563 (*req->cb) (req->cba, req->tcall, req->rcall, req->err);
564 req->cb = NULL;
565 } else
566 kfree(req->rcall);
567
568 if (tag != V9FS_NOTAG)
569 v9fs_put_idpool(tag, &m->tidpool);
570
571 wake_up(&m->equeue);
572 kfree(req);
351} 573}
352 574
353/** 575/**
354 * v9fs_recvproc - kproc to handle demultiplexing responses 576 * v9fs_read_work - called when there is some data to be read from a transport
355 * @data: session info structure
356 *
357 */ 577 */
358 578static void v9fs_read_work(void *a)
359static int v9fs_recvproc(void *data)
360{ 579{
361 struct v9fs_session_info *v9ses = (struct v9fs_session_info *)data; 580 int n, err, rcallen;
362 struct v9fs_fcall *rcall = NULL; 581 struct v9fs_mux_data *m;
363 struct v9fs_rpcreq *rptr; 582 struct v9fs_req *req, *rptr, *rreq;
364 struct v9fs_rpcreq *req; 583 struct v9fs_fcall *rcall;
365 struct v9fs_rpcreq *rreq; 584
366 int err = 0; 585 m = a;
586
587 if (m->err < 0)
588 return;
589
590 rcall = NULL;
591 dprintk(DEBUG_MUX, "start mux %p pos %d\n", m, m->rpos);
592 clear_bit(Rpending, &m->wsched);
593 err = m->trans->read(m->trans, m->rbuf + m->rpos, m->msize - m->rpos);
594 dprintk(DEBUG_MUX, "mux %p got %d bytes\n", m, err);
595 if (err == -EAGAIN) {
596 clear_bit(Rworksched, &m->wsched);
597 return;
598 }
367 599
368 allow_signal(SIGKILL); 600 if (err <= 0)
369 set_current_state(TASK_INTERRUPTIBLE); 601 goto error;
370 complete(&v9ses->proccmpl);
371 while (!kthread_should_stop() && err >= 0) {
372 req = rptr = rreq = NULL;
373 602
374 rcall = kmalloc(v9ses->maxdata + V9FS_IOHDRSZ, GFP_KERNEL); 603 m->rpos += err;
375 if (!rcall) { 604 while (m->rpos > 4) {
376 eprintk(KERN_ERR, "no memory for buffers\n"); 605 n = le32_to_cpu(*(__le32 *) m->rbuf);
606 if (n >= m->msize) {
607 dprintk(DEBUG_ERROR,
608 "requested packet size too big: %d\n", n);
609 err = -EIO;
610 goto error;
611 }
612
613 if (m->rpos < n)
377 break; 614 break;
615
616 rcallen = n + V9FS_FCALLHDRSZ;
617 rcall = kmalloc(rcallen, GFP_KERNEL);
618 if (!rcall) {
619 err = -ENOMEM;
620 goto error;
378 } 621 }
379 622
380 err = read_message(v9ses, rcall, v9ses->maxdata + V9FS_IOHDRSZ); 623 dump_data(m->rbuf, n);
381 spin_lock(&v9ses->muxlock); 624 err = v9fs_deserialize_fcall(m->rbuf, n, rcall, rcallen,
625 *m->extended);
382 if (err < 0) { 626 if (err < 0) {
383 list_for_each_entry_safe(rreq, rptr, &v9ses->mux_fcalls, next) { 627 kfree(rcall);
384 rreq->err = err; 628 goto error;
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 } 629 }
398 630
399 if (req && (req->tcall->id == TFLUSH)) { 631 dprintk(DEBUG_MUX, "mux %p fcall id %d tag %d\n", m, rcall->id,
400 struct v9fs_rpcreq *treq = NULL; 632 rcall->tag);
401 list_for_each_entry_safe(treq, rptr, &v9ses->mux_fcalls, next) { 633
402 if (treq->tcall->tag == 634 req = NULL;
403 req->tcall->params.tflush.oldtag) { 635 spin_lock(&m->lock);
404 list_del(&rptr->next); 636 list_for_each_entry_safe(rreq, rptr, &m->req_list, req_list) {
405 kfree(treq->rcall); 637 if (rreq->tag == rcall->tag) {
406 break; 638 req = rreq;
407 } 639 req->rcall = rcall;
640 list_del(&req->req_list);
641 spin_unlock(&m->lock);
642 process_request(m, req);
643 break;
408 } 644 }
409 } 645 }
410 646
411 spin_unlock(&v9ses->muxlock);
412
413 if (!req) { 647 if (!req) {
414 if (err >= 0) 648 spin_unlock(&m->lock);
649 if (err >= 0 && rcall->id != RFLUSH)
415 dprintk(DEBUG_ERROR, 650 dprintk(DEBUG_ERROR,
416 "unexpected response: id %d tag %d\n", 651 "unexpected response mux %p id %d tag %d\n",
417 rcall->id, rcall->tag); 652 m, rcall->id, rcall->tag);
418
419 kfree(rcall); 653 kfree(rcall);
420 } 654 }
421 655
422 wake_up_all(&v9ses->read_wait); 656 if (m->rpos > n)
423 set_current_state(TASK_INTERRUPTIBLE); 657 memmove(m->rbuf, m->rbuf + n, m->rpos - n);
658 m->rpos -= n;
424 } 659 }
425 660
426 v9ses->transport->close(v9ses->transport); 661 if (!list_empty(&m->req_list)) {
427 662 if (test_and_clear_bit(Rpending, &m->wsched))
428 /* Inform all pending processes about the failure */ 663 n = POLLIN;
429 wake_up_all(&v9ses->read_wait); 664 else
430 665 n = m->trans->poll(m->trans, NULL);
431 if (signal_pending(current)) 666
432 complete(&v9ses->proccmpl); 667 if (n & POLLIN) {
668 dprintk(DEBUG_MUX, "schedule read work mux %p\n", m);
669 queue_work(v9fs_mux_wq, &m->rq);
670 } else
671 clear_bit(Rworksched, &m->wsched);
672 } else
673 clear_bit(Rworksched, &m->wsched);
433 674
434 dprintk(DEBUG_MUX, "recvproc: end\n"); 675 return;
435 v9ses->recvproc = NULL;
436 676
437 return err >= 0; 677 error:
678 v9fs_mux_cancel(m, err);
679 clear_bit(Rworksched, &m->wsched);
438} 680}
439 681
440/** 682/**
441 * v9fs_mux_init - initialize multiplexer (spawn kproc) 683 * v9fs_send_request - send 9P request
442 * @v9ses: session info structure 684 * The function can sleep until the request is scheduled for sending.
443 * @dev_name: mount device information (to create unique kproc) 685 * The function can be interrupted. Return from the function is not
686 * a guarantee that the request is sent succesfully. Can return errors
687 * that can be retrieved by PTR_ERR macros.
444 * 688 *
689 * @m: mux data
690 * @tc: request to be sent
691 * @cb: callback function to call when response is received
692 * @cba: parameter to pass to the callback function
445 */ 693 */
694static struct v9fs_req *v9fs_send_request(struct v9fs_mux_data *m,
695 struct v9fs_fcall *tc,
696 v9fs_mux_req_callback cb, void *cba)
697{
698 int n;
699 struct v9fs_req *req;
700
701 dprintk(DEBUG_MUX, "mux %p task %p tcall %p id %d\n", m, current,
702 tc, tc->id);
703 if (m->err < 0)
704 return ERR_PTR(m->err);
705
706 req = kmalloc(sizeof(struct v9fs_req), GFP_KERNEL);
707 if (!req)
708 return ERR_PTR(-ENOMEM);
446 709
447int v9fs_mux_init(struct v9fs_session_info *v9ses, const char *dev_name) 710 if (tc->id == TVERSION)
711 n = V9FS_NOTAG;
712 else
713 n = v9fs_get_idpool(&m->tidpool);
714
715 if (n < 0)
716 return ERR_PTR(-ENOMEM);
717
718 tc->tag = n;
719 req->tag = n;
720 req->tcall = tc;
721 req->rcall = NULL;
722 req->err = 0;
723 req->cb = cb;
724 req->cba = cba;
725
726 spin_lock(&m->lock);
727 list_add_tail(&req->req_list, &m->unsent_req_list);
728 spin_unlock(&m->lock);
729
730 if (test_and_clear_bit(Wpending, &m->wsched))
731 n = POLLOUT;
732 else
733 n = m->trans->poll(m->trans, NULL);
734
735 if (n & POLLOUT && !test_and_set_bit(Wworksched, &m->wsched))
736 queue_work(v9fs_mux_wq, &m->wq);
737
738 return req;
739}
740
741static inline void
742v9fs_mux_flush_cb(void *a, struct v9fs_fcall *tc, struct v9fs_fcall *rc,
743 int err)
448{ 744{
449 char procname[60]; 745 v9fs_mux_req_callback cb;
450 746 int tag;
451 strncpy(procname, dev_name, sizeof(procname)); 747 struct v9fs_mux_data *m;
452 procname[sizeof(procname) - 1] = 0; 748 struct v9fs_req *req, *rptr;
453 749
454 init_waitqueue_head(&v9ses->read_wait); 750 m = a;
455 init_completion(&v9ses->fcread); 751 dprintk(DEBUG_MUX, "mux %p tc %p rc %p err %d oldtag %d\n", m, tc,
456 init_completion(&v9ses->proccmpl); 752 rc, err, tc->params.tflush.oldtag);
457 spin_lock_init(&v9ses->muxlock); 753
458 INIT_LIST_HEAD(&v9ses->mux_fcalls); 754 spin_lock(&m->lock);
459 v9ses->recvproc = NULL; 755 cb = NULL;
460 v9ses->curfcall = NULL; 756 tag = tc->params.tflush.oldtag;
461 757 list_for_each_entry_safe(req, rptr, &m->req_list, req_list) {
462 v9ses->recvproc = kthread_create(v9fs_recvproc, v9ses, 758 if (req->tag == tag) {
463 "v9fs_recvproc %s", procname); 759 list_del(&req->req_list);
464 760 if (req->cb) {
465 if (IS_ERR(v9ses->recvproc)) { 761 cb = req->cb;
466 eprintk(KERN_ERR, "cannot create receiving thread\n"); 762 req->cb = NULL;
467 v9fs_session_close(v9ses); 763 spin_unlock(&m->lock);
468 return -ECONNABORTED; 764 (*cb) (req->cba, req->tcall, req->rcall,
765 req->err);
766 }
767 kfree(req);
768 wake_up(&m->equeue);
769 break;
770 }
771 }
772
773 if (!cb)
774 spin_unlock(&m->lock);
775
776 if (v9fs_check_idpool(tag, &m->tidpool))
777 v9fs_put_idpool(tag, &m->tidpool);
778
779 kfree(tc);
780 kfree(rc);
781}
782
783static void
784v9fs_mux_flush_request(struct v9fs_mux_data *m, struct v9fs_req *req)
785{
786 struct v9fs_fcall *fc;
787
788 dprintk(DEBUG_MUX, "mux %p req %p tag %d\n", m, req, req->tag);
789
790 fc = kmalloc(sizeof(struct v9fs_fcall), GFP_KERNEL);
791 fc->id = TFLUSH;
792 fc->params.tflush.oldtag = req->tag;
793
794 v9fs_send_request(m, fc, v9fs_mux_flush_cb, m);
795}
796
797static void
798v9fs_mux_rpc_cb(void *a, struct v9fs_fcall *tc, struct v9fs_fcall *rc, int err)
799{
800 struct v9fs_mux_rpc *r;
801
802 if (err == ERREQFLUSH) {
803 dprintk(DEBUG_MUX, "err req flush\n");
804 return;
805 }
806
807 r = a;
808 dprintk(DEBUG_MUX, "mux %p req %p tc %p rc %p err %d\n", r->m, r->req,
809 tc, rc, err);
810 r->rcall = rc;
811 r->err = err;
812 wake_up(&r->wqueue);
813}
814
815/**
816 * v9fs_mux_rpc - sends 9P request and waits until a response is available.
817 * The function can be interrupted.
818 * @m: mux data
819 * @tc: request to be sent
820 * @rc: pointer where a pointer to the response is stored
821 */
822int
823v9fs_mux_rpc(struct v9fs_mux_data *m, struct v9fs_fcall *tc,
824 struct v9fs_fcall **rc)
825{
826 int err;
827 unsigned long flags;
828 struct v9fs_req *req;
829 struct v9fs_mux_rpc r;
830
831 r.err = 0;
832 r.rcall = NULL;
833 r.m = m;
834 init_waitqueue_head(&r.wqueue);
835
836 if (rc)
837 *rc = NULL;
838
839 req = v9fs_send_request(m, tc, v9fs_mux_rpc_cb, &r);
840 if (IS_ERR(req)) {
841 err = PTR_ERR(req);
842 dprintk(DEBUG_MUX, "error %d\n", err);
843 return PTR_ERR(req);
844 }
845
846 r.req = req;
847 dprintk(DEBUG_MUX, "mux %p tc %p tag %d rpc %p req %p\n", m, tc,
848 req->tag, &r, req);
849 err = wait_event_interruptible(r.wqueue, r.rcall != NULL || r.err < 0);
850 if (r.err < 0)
851 err = r.err;
852
853 if (err == -ERESTARTSYS && m->trans->status == Connected && m->err == 0) {
854 spin_lock(&m->lock);
855 req->tcall = NULL;
856 req->err = ERREQFLUSH;
857 spin_unlock(&m->lock);
858
859 clear_thread_flag(TIF_SIGPENDING);
860 v9fs_mux_flush_request(m, req);
861 spin_lock_irqsave(&current->sighand->siglock, flags);
862 recalc_sigpending();
863 spin_unlock_irqrestore(&current->sighand->siglock, flags);
469 } 864 }
470 865
471 wake_up_process(v9ses->recvproc); 866 if (!err) {
472 wait_for_completion(&v9ses->proccmpl); 867 if (r.rcall)
868 dprintk(DEBUG_MUX, "got response id %d tag %d\n",
869 r.rcall->id, r.rcall->tag);
870
871 if (rc)
872 *rc = r.rcall;
873 else
874 kfree(r.rcall);
875 } else {
876 kfree(r.rcall);
877 dprintk(DEBUG_MUX, "got error %d\n", err);
878 if (err > 0)
879 err = -EIO;
880 }
881
882 return err;
883}
884
885/**
886 * v9fs_mux_rpcnb - sends 9P request without waiting for response.
887 * @m: mux data
888 * @tc: request to be sent
889 * @cb: callback function to be called when response arrives
890 * @cba: value to pass to the callback function
891 */
892int v9fs_mux_rpcnb(struct v9fs_mux_data *m, struct v9fs_fcall *tc,
893 v9fs_mux_req_callback cb, void *a)
894{
895 int err;
896 struct v9fs_req *req;
897
898 req = v9fs_send_request(m, tc, cb, a);
899 if (IS_ERR(req)) {
900 err = PTR_ERR(req);
901 dprintk(DEBUG_MUX, "error %d\n", err);
902 return PTR_ERR(req);
903 }
473 904
905 dprintk(DEBUG_MUX, "mux %p tc %p tag %d\n", m, tc, req->tag);
474 return 0; 906 return 0;
475} 907}
908
909/**
910 * v9fs_mux_cancel - cancel all pending requests with error
911 * @m: mux data
912 * @err: error code
913 */
914void v9fs_mux_cancel(struct v9fs_mux_data *m, int err)
915{
916 struct v9fs_req *req, *rtmp;
917 LIST_HEAD(cancel_list);
918
919 dprintk(DEBUG_MUX, "mux %p err %d\n", m, err);
920 m->err = err;
921 spin_lock(&m->lock);
922 list_for_each_entry_safe(req, rtmp, &m->req_list, req_list) {
923 list_move(&req->req_list, &cancel_list);
924 }
925 spin_unlock(&m->lock);
926
927 list_for_each_entry_safe(req, rtmp, &cancel_list, req_list) {
928 list_del(&req->req_list);
929 if (!req->err)
930 req->err = err;
931
932 if (req->cb)
933 (*req->cb) (req->cba, req->tcall, req->rcall, req->err);
934 else
935 kfree(req->rcall);
936
937 kfree(req);
938 }
939
940 wake_up(&m->equeue);
941}
diff --git a/fs/9p/mux.h b/fs/9p/mux.h
index 4994cb10badf..02b13b14b05b 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,34 @@
23 * 24 *
24 */ 25 */
25 26
26/* structure to manage each RPC transaction */ 27struct v9fs_mux_data;
27 28
28struct 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 */
40typedef void (*v9fs_mux_req_callback)(void *a, struct v9fs_fcall *tc,
41 struct v9fs_fcall *rc, int err);
42
43void v9fs_mux_global_init(void);
44void v9fs_mux_global_exit(void);
32 45
33 /* XXX - could we put scatter/gather buffers here? */ 46struct v9fs_mux_data *v9fs_mux_init(struct v9fs_transport *trans, int msize,
47 unsigned char *extended);
48void v9fs_mux_destroy(struct v9fs_mux_data *);
34 49
35 struct list_head next; 50int v9fs_mux_send(struct v9fs_mux_data *m, struct v9fs_fcall *tc);
36}; 51struct v9fs_fcall *v9fs_mux_recv(struct v9fs_mux_data *m);
52int v9fs_mux_rpc(struct v9fs_mux_data *m, struct v9fs_fcall *tc, struct v9fs_fcall **rc);
53int v9fs_mux_rpcnb(struct v9fs_mux_data *m, struct v9fs_fcall *tc,
54 v9fs_mux_req_callback cb, void *a);
37 55
38int v9fs_mux_init(struct v9fs_session_info *v9ses, const char *dev_name); 56void v9fs_mux_flush(struct v9fs_mux_data *m, int sendflush);
39long v9fs_mux_rpc(struct v9fs_session_info *v9ses, 57void v9fs_mux_cancel(struct v9fs_mux_data *m, int err);
40 struct v9fs_fcall *tcall, struct v9fs_fcall **rcall);
41void 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 b7ffb9859588..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)
@@ -163,10 +161,55 @@ static void v9fs_fd_close(struct v9fs_transport *trans)
163 kfree(ts); 161 kfree(ts);
164} 162}
165 163
164static unsigned int
165v9fs_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
202end:
203 set_fs(oldfs);
204 return ret;
205}
206
207
166struct v9fs_transport v9fs_trans_fd = { 208struct 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..9ef404c75c8f 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
46struct v9fs_trans_sock { 48struct 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
58static int v9fs_sock_recv(struct v9fs_transport *trans, void *v, int len) 61static 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
84 result = kernel_recvmsg(ts->s, &msg, &iov, 1, len, 0);
85 72
86 dprintk(DEBUG_TRANS, "socket state %d\n", ts->s->state); 73 if (!(ts->filp->f_flags & O_NONBLOCK))
87 set_fs(oldfs); 74 dprintk(DEBUG_ERROR, "blocking read ...\n");
88 75
89 if (result <= 0) { 76 ret = kernel_read(ts->filp, ts->filp->f_pos, v, len);
90 if (result != -ERESTARTSYS) 77 if (ret <= 0) {
78 if (ret != -ERESTARTSYS && ret != -EAGAIN)
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,73 @@ static int v9fs_sock_recv(struct v9fs_transport *trans, void *v, int len)
104 92
105static int v9fs_sock_send(struct v9fs_transport *trans, void *v, int len) 93static 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
113 dump_data(v, len);
118 oldfs = get_fs(); 114 oldfs = get_fs();
119 set_fs(get_ds()); 115 set_fs(get_ds());
120 iov.iov_base = v; 116 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); 117 set_fs(oldfs);
131 118
132 if (result < 0) { 119 if (ret < 0) {
133 if (result != -ERESTARTSYS) 120 if (ret != -ERESTARTSYS)
134 trans->status = Disconnected; 121 trans->status = Disconnected;
135 } 122 }
136 123
137 up(&trans->writelock); 124 return ret;
138 return result; 125}
126
127static unsigned int v9fs_sock_poll(struct v9fs_transport *trans,
128 struct poll_table_struct *pt) {
129
130 int ret;
131 struct v9fs_trans_sock *ts;
132 mm_segment_t oldfs;
133
134 if (!trans) {
135 dprintk(DEBUG_ERROR, "no transport\n");
136 return -EIO;
137 }
138
139 ts = trans->priv;
140 if (trans->status != Connected || !ts) {
141 dprintk(DEBUG_ERROR, "transport disconnected: %d\n", trans->status);
142 return -EIO;
143 }
144
145 oldfs = get_fs();
146 set_fs(get_ds());
147
148 if (!ts->filp->f_op || !ts->filp->f_op->poll) {
149 dprintk(DEBUG_ERROR, "no poll operation\n");
150 ret = -EIO;
151 goto end;
152 }
153
154 ret = ts->filp->f_op->poll(ts->filp, pt);
155
156end:
157 set_fs(oldfs);
158 return ret;
139} 159}
140 160
161
141/** 162/**
142 * v9fs_tcp_init - initialize TCP socket 163 * v9fs_tcp_init - initialize TCP socket
143 * @v9ses: session information 164 * @v9ses: session information
@@ -154,9 +175,9 @@ v9fs_tcp_init(struct v9fs_session_info *v9ses, const char *addr, char *data)
154 int rc = 0; 175 int rc = 0;
155 struct v9fs_trans_sock *ts = NULL; 176 struct v9fs_trans_sock *ts = NULL;
156 struct v9fs_transport *trans = v9ses->transport; 177 struct v9fs_transport *trans = v9ses->transport;
178 int fd;
157 179
158 sema_init(&trans->writelock, 1); 180 trans->status = Disconnected;
159 sema_init(&trans->readlock, 1);
160 181
161 ts = kmalloc(sizeof(struct v9fs_trans_sock), GFP_KERNEL); 182 ts = kmalloc(sizeof(struct v9fs_trans_sock), GFP_KERNEL);
162 183
@@ -165,6 +186,7 @@ v9fs_tcp_init(struct v9fs_session_info *v9ses, const char *addr, char *data)
165 186
166 trans->priv = ts; 187 trans->priv = ts;
167 ts->s = NULL; 188 ts->s = NULL;
189 ts->filp = NULL;
168 190
169 if (!addr) 191 if (!addr)
170 return -EINVAL; 192 return -EINVAL;
@@ -185,7 +207,18 @@ v9fs_tcp_init(struct v9fs_session_info *v9ses, const char *addr, char *data)
185 return rc; 207 return rc;
186 } 208 }
187 csocket->sk->sk_allocation = GFP_NOIO; 209 csocket->sk->sk_allocation = GFP_NOIO;
210
211 fd = sock_map_fd(csocket);
212 if (fd < 0) {
213 sock_release(csocket);
214 kfree(ts);
215 trans->priv = NULL;
216 return fd;
217 }
218
188 ts->s = csocket; 219 ts->s = csocket;
220 ts->filp = fget(fd);
221 ts->filp->f_flags |= O_NONBLOCK;
189 trans->status = Connected; 222 trans->status = Connected;
190 223
191 return 0; 224 return 0;
@@ -203,7 +236,7 @@ static int
203v9fs_unix_init(struct v9fs_session_info *v9ses, const char *dev_name, 236v9fs_unix_init(struct v9fs_session_info *v9ses, const char *dev_name,
204 char *data) 237 char *data)
205{ 238{
206 int rc; 239 int rc, fd;
207 struct socket *csocket; 240 struct socket *csocket;
208 struct sockaddr_un sun_server; 241 struct sockaddr_un sun_server;
209 struct v9fs_transport *trans; 242 struct v9fs_transport *trans;
@@ -213,6 +246,8 @@ v9fs_unix_init(struct v9fs_session_info *v9ses, const char *dev_name,
213 csocket = NULL; 246 csocket = NULL;
214 trans = v9ses->transport; 247 trans = v9ses->transport;
215 248
249 trans->status = Disconnected;
250
216 if (strlen(dev_name) > UNIX_PATH_MAX) { 251 if (strlen(dev_name) > UNIX_PATH_MAX) {
217 eprintk(KERN_ERR, "v9fs_trans_unix: address too long: %s\n", 252 eprintk(KERN_ERR, "v9fs_trans_unix: address too long: %s\n",
218 dev_name); 253 dev_name);
@@ -225,9 +260,7 @@ v9fs_unix_init(struct v9fs_session_info *v9ses, const char *dev_name,
225 260
226 trans->priv = ts; 261 trans->priv = ts;
227 ts->s = NULL; 262 ts->s = NULL;
228 263 ts->filp = NULL;
229 sema_init(&trans->writelock, 1);
230 sema_init(&trans->readlock, 1);
231 264
232 sun_server.sun_family = PF_UNIX; 265 sun_server.sun_family = PF_UNIX;
233 strcpy(sun_server.sun_path, dev_name); 266 strcpy(sun_server.sun_path, dev_name);
@@ -241,7 +274,18 @@ v9fs_unix_init(struct v9fs_session_info *v9ses, const char *dev_name,
241 return rc; 274 return rc;
242 } 275 }
243 csocket->sk->sk_allocation = GFP_NOIO; 276 csocket->sk->sk_allocation = GFP_NOIO;
277
278 fd = sock_map_fd(csocket);
279 if (fd < 0) {
280 sock_release(csocket);
281 kfree(ts);
282 trans->priv = NULL;
283 return fd;
284 }
285
244 ts->s = csocket; 286 ts->s = csocket;
287 ts->filp = fget(fd);
288 ts->filp->f_flags |= O_NONBLOCK;
245 trans->status = Connected; 289 trans->status = Connected;
246 290
247 return 0; 291 return 0;
@@ -262,12 +306,11 @@ static void v9fs_sock_close(struct v9fs_transport *trans)
262 306
263 ts = trans->priv; 307 ts = trans->priv;
264 308
265 if ((ts) && (ts->s)) { 309 if ((ts) && (ts->filp)) {
266 dprintk(DEBUG_TRANS, "closing the socket %p\n", ts->s); 310 fput(ts->filp);
267 sock_release(ts->s); 311 ts->filp = NULL;
268 ts->s = NULL; 312 ts->s = NULL;
269 trans->status = Disconnected; 313 trans->status = Disconnected;
270 dprintk(DEBUG_TRANS, "socket closed\n");
271 } 314 }
272 315
273 kfree(ts); 316 kfree(ts);
@@ -280,6 +323,7 @@ struct v9fs_transport v9fs_trans_tcp = {
280 .write = v9fs_sock_send, 323 .write = v9fs_sock_send,
281 .read = v9fs_sock_recv, 324 .read = v9fs_sock_recv,
282 .close = v9fs_sock_close, 325 .close = v9fs_sock_close,
326 .poll = v9fs_sock_poll,
283}; 327};
284 328
285struct v9fs_transport v9fs_trans_unix = { 329struct v9fs_transport v9fs_trans_unix = {
@@ -287,4 +331,5 @@ struct v9fs_transport v9fs_trans_unix = {
287 .write = v9fs_sock_send, 331 .write = v9fs_sock_send,
288 .read = v9fs_sock_recv, 332 .read = v9fs_sock_recv,
289 .close = v9fs_sock_close, 333 .close = v9fs_sock_close,
334 .poll = v9fs_sock_poll,
290}; 335};
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
32struct v9fs_transport { 33struct 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
44extern struct v9fs_transport v9fs_trans_tcp; 44extern struct v9fs_transport v9fs_trans_tcp;
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index 418c3743fdee..5e0f79355fdf 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -213,7 +213,8 @@ retry:
213 return -1; 213 return -1;
214 } 214 }
215 215
216 error = idr_get_new(&p->pool, NULL, &i); 216 /* no need to store exactly p, we just need something non-null */
217 error = idr_get_new(&p->pool, p, &i);
217 up(&p->lock); 218 up(&p->lock);
218 219
219 if (error == -EAGAIN) 220 if (error == -EAGAIN)
@@ -243,6 +244,16 @@ void v9fs_put_idpool(int id, struct v9fs_idpool *p)
243} 244}
244 245
245/** 246/**
247 * v9fs_check_idpool - check if the specified id is available
248 * @id - id to check
249 * @p - pool
250 */
251int v9fs_check_idpool(int id, struct v9fs_idpool *p)
252{
253 return idr_find(&p->pool, id) != NULL;
254}
255
256/**
246 * v9fs_session_init - initialize session 257 * v9fs_session_init - initialize session
247 * @v9ses: session information structure 258 * @v9ses: session information structure
248 * @dev_name: device being mounted 259 * @dev_name: device being mounted
@@ -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 }
@@ -381,7 +394,7 @@ v9fs_session_init(struct v9fs_session_info *v9ses,
381 } 394 }
382 395
383 if (v9ses->afid != ~0) { 396 if (v9ses->afid != ~0) {
384 if (v9fs_t_clunk(v9ses, v9ses->afid, NULL)) 397 if (v9fs_t_clunk(v9ses, v9ses->afid))
385 dprintk(DEBUG_ERROR, "clunk failed\n"); 398 dprintk(DEBUG_ERROR, "clunk failed\n");
386 } 399 }
387 400
@@ -403,13 +416,16 @@ v9fs_session_init(struct v9fs_session_info *v9ses,
403 416
404void v9fs_session_close(struct v9fs_session_info *v9ses) 417void v9fs_session_close(struct v9fs_session_info *v9ses)
405{ 418{
406 if (v9ses->recvproc) { 419 if (v9ses->mux) {
407 send_sig(SIGKILL, v9ses->recvproc, 1); 420 v9fs_mux_destroy(v9ses->mux);
408 wait_for_completion(&v9ses->proccmpl); 421 v9ses->mux = NULL;
409 } 422 }
410 423
411 if (v9ses->transport) 424 if (v9ses->transport) {
412 v9ses->transport->close(v9ses->transport); 425 v9ses->transport->close(v9ses->transport);
426 kfree(v9ses->transport);
427 v9ses->transport = NULL;
428 }
413 429
414 __putname(v9ses->name); 430 __putname(v9ses->name);
415 __putname(v9ses->remotename); 431 __putname(v9ses->remotename);
@@ -420,8 +436,9 @@ void v9fs_session_close(struct v9fs_session_info *v9ses)
420 * and cancel all pending requests. 436 * and cancel all pending requests.
421 */ 437 */
422void v9fs_session_cancel(struct v9fs_session_info *v9ses) { 438void v9fs_session_cancel(struct v9fs_session_info *v9ses) {
439 dprintk(DEBUG_ERROR, "cancel session %p\n", v9ses);
423 v9ses->transport->status = Disconnected; 440 v9ses->transport->status = Disconnected;
424 v9fs_mux_cancel_requests(v9ses, -EIO); 441 v9fs_mux_cancel(v9ses->mux, -EIO);
425} 442}
426 443
427extern int v9fs_error_init(void); 444extern int v9fs_error_init(void);
@@ -437,6 +454,7 @@ static int __init init_v9fs(void)
437 454
438 printk(KERN_INFO "Installing v9fs 9P2000 file system support\n"); 455 printk(KERN_INFO "Installing v9fs 9P2000 file system support\n");
439 456
457 v9fs_mux_global_init();
440 return register_filesystem(&v9fs_fs_type); 458 return register_filesystem(&v9fs_fs_type);
441} 459}
442 460
@@ -447,6 +465,7 @@ static int __init init_v9fs(void)
447 465
448static void __exit exit_v9fs(void) 466static void __exit exit_v9fs(void)
449{ 467{
468 v9fs_mux_global_exit();
450 unregister_filesystem(&v9fs_fs_type); 469 unregister_filesystem(&v9fs_fs_type);
451} 470}
452 471
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
77extern struct dentry *v9fs_debugfs_root;
78
87int v9fs_session_init(struct v9fs_session_info *, const char *, char *); 79int v9fs_session_init(struct v9fs_session_info *, const char *, char *);
88struct v9fs_session_info *v9fs_inode2v9ses(struct inode *); 80struct v9fs_session_info *v9fs_inode2v9ses(struct inode *);
89void v9fs_session_close(struct v9fs_session_info *v9ses); 81void v9fs_session_close(struct v9fs_session_info *v9ses);
90int v9fs_get_idpool(struct v9fs_idpool *p); 82int v9fs_get_idpool(struct v9fs_idpool *p);
91void v9fs_put_idpool(int id, struct v9fs_idpool *p); 83void v9fs_put_idpool(int id, struct v9fs_idpool *p);
84int v9fs_check_idpool(int id, struct v9fs_idpool *p);
92void v9fs_session_cancel(struct v9fs_session_info *v9ses); 85void 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/vfs_dentry.c b/fs/9p/vfs_dentry.c
index a6aa947de0f9..4887df767394 100644
--- a/fs/9p/vfs_dentry.c
+++ b/fs/9p/vfs_dentry.c
@@ -95,24 +95,21 @@ static int v9fs_dentry_validate(struct dentry *dentry, struct nameidata *nd)
95 95
96void v9fs_dentry_release(struct dentry *dentry) 96void v9fs_dentry_release(struct dentry *dentry)
97{ 97{
98 int err;
99
98 dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry); 100 dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
99 101
100 if (dentry->d_fsdata != NULL) { 102 if (dentry->d_fsdata != NULL) {
101 struct list_head *fid_list = dentry->d_fsdata; 103 struct list_head *fid_list = dentry->d_fsdata;
102 struct v9fs_fid *temp = NULL; 104 struct v9fs_fid *temp = NULL;
103 struct v9fs_fid *current_fid = NULL; 105 struct v9fs_fid *current_fid = NULL;
104 struct v9fs_fcall *fcall = NULL;
105 106
106 list_for_each_entry_safe(current_fid, temp, fid_list, list) { 107 list_for_each_entry_safe(current_fid, temp, fid_list, list) {
107 if (v9fs_t_clunk 108 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 109
112 v9fs_put_idpool(current_fid->fid, 110 if (err < 0)
113 &current_fid->v9ses->fidpool); 111 dprintk(DEBUG_ERROR, "clunk failed: %d\n", err);
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 17089d1905ff..3893dd307ddb 100644
--- a/fs/9p/vfs_dir.c
+++ b/fs/9p/vfs_dir.c
@@ -74,7 +74,7 @@ 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 *mi = NULL;
@@ -97,9 +97,9 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
97 n = file->rdir_fcall->params.rread.count; 97 n = file->rdir_fcall->params.rread.count;
98 i = file->rdir_fpos; 98 i = file->rdir_fpos;
99 while (i < n) { 99 while (i < n) {
100 int s = v9fs_deserialize_stat(v9ses, 100 s = v9fs_deserialize_stat(
101 file->rdir_fcall->params.rread.data + i, 101 file->rdir_fcall->params.rread.data + i,
102 n - i, mi, v9ses->maxdata); 102 n - i, mi, v9ses->maxdata, v9ses->extended);
103 103
104 if (s == 0) { 104 if (s == 0) {
105 dprintk(DEBUG_ERROR, 105 dprintk(DEBUG_ERROR,
@@ -141,9 +141,8 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
141 n = ret; 141 n = ret;
142 i = 0; 142 i = 0;
143 while (i < n) { 143 while (i < n) {
144 int s = v9fs_deserialize_stat(v9ses, 144 s = v9fs_deserialize_stat(fcall->params.rread.data + i,
145 fcall->params.rread.data + i, n - i, mi, 145 n - i, mi, v9ses->maxdata, v9ses->extended);
146 v9ses->maxdata);
147 146
148 if (s == 0) { 147 if (s == 0) {
149 dprintk(DEBUG_ERROR, 148 dprintk(DEBUG_ERROR,
@@ -199,11 +198,9 @@ int v9fs_dir_release(struct inode *inode, struct file *filp)
199 dprintk(DEBUG_VFS, "fidopen: %d v9f->fid: %d\n", fid->fidopen, 198 dprintk(DEBUG_VFS, "fidopen: %d v9f->fid: %d\n", fid->fidopen,
200 fid->fid); 199 fid->fid);
201 200
202 if (v9fs_t_clunk(v9ses, fidnum, NULL)) 201 if (v9fs_t_clunk(v9ses, fidnum))
203 dprintk(DEBUG_ERROR, "clunk failed\n"); 202 dprintk(DEBUG_ERROR, "clunk failed\n");
204 203
205 v9fs_put_idpool(fid->fid, &v9ses->fidpool);
206
207 kfree(fid->rdir_fcall); 204 kfree(fid->rdir_fcall);
208 kfree(fid); 205 kfree(fid);
209 206
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 0ea965c3bb7d..466002a1fe32 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -318,6 +318,7 @@ v9fs_create(struct inode *dir,
318 int result = 0; 318 int result = 0;
319 unsigned int iounit = 0; 319 unsigned int iounit = 0;
320 int wfidno = -1; 320 int wfidno = -1;
321 int err;
321 322
322 perm = unixmode2p9mode(v9ses, perm); 323 perm = unixmode2p9mode(v9ses, perm);
323 324
@@ -356,6 +357,7 @@ v9fs_create(struct inode *dir,
356 } 357 }
357 358
358 kfree(fcall); 359 kfree(fcall);
360 fcall = NULL;
359 361
360 result = v9fs_t_create(v9ses, newfid, (char *)file_dentry->d_name.name, 362 result = v9fs_t_create(v9ses, newfid, (char *)file_dentry->d_name.name,
361 perm, open_mode, &fcall); 363 perm, open_mode, &fcall);
@@ -369,16 +371,23 @@ v9fs_create(struct inode *dir,
369 iounit = fcall->params.rcreate.iounit; 371 iounit = fcall->params.rcreate.iounit;
370 qid = fcall->params.rcreate.qid; 372 qid = fcall->params.rcreate.qid;
371 kfree(fcall); 373 kfree(fcall);
374 fcall = NULL;
372 375
373 fid = v9fs_fid_create(file_dentry, v9ses, newfid, 1); 376 if (!(perm&V9FS_DMDIR)) {
374 dprintk(DEBUG_VFS, "fid %p %d\n", fid, fid->fidcreate); 377 fid = v9fs_fid_create(file_dentry, v9ses, newfid, 1);
375 if (!fid) { 378 dprintk(DEBUG_VFS, "fid %p %d\n", fid, fid->fidcreate);
376 result = -ENOMEM; 379 if (!fid) {
377 goto CleanUpFid; 380 result = -ENOMEM;
378 } 381 goto CleanUpFid;
382 }
379 383
380 fid->qid = qid; 384 fid->qid = qid;
381 fid->iounit = iounit; 385 fid->iounit = iounit;
386 } else {
387 err = v9fs_t_clunk(v9ses, newfid);
388 if (err < 0)
389 dprintk(DEBUG_ERROR, "clunk for mkdir failed: %d\n", err);
390 }
382 391
383 /* walk to the newly created file and put the fid in the dentry */ 392 /* walk to the newly created file and put the fid in the dentry */
384 wfidno = v9fs_get_idpool(&v9ses->fidpool); 393 wfidno = v9fs_get_idpool(&v9ses->fidpool);
@@ -388,18 +397,19 @@ v9fs_create(struct inode *dir,
388 } 397 }
389 398
390 result = v9fs_t_walk(v9ses, dirfidnum, wfidno, 399 result = v9fs_t_walk(v9ses, dirfidnum, wfidno,
391 (char *) file_dentry->d_name.name, NULL); 400 (char *) file_dentry->d_name.name, &fcall);
392 if (result < 0) { 401 if (result < 0) {
393 dprintk(DEBUG_ERROR, "clone error: %s\n", FCALL_ERROR(fcall)); 402 dprintk(DEBUG_ERROR, "clone error: %s\n", FCALL_ERROR(fcall));
394 v9fs_put_idpool(wfidno, &v9ses->fidpool); 403 v9fs_put_idpool(wfidno, &v9ses->fidpool);
395 wfidno = -1; 404 wfidno = -1;
396 goto CleanUpFid; 405 goto CleanUpFid;
397 } 406 }
407 kfree(fcall);
408 fcall = NULL;
398 409
399 if (!v9fs_fid_create(file_dentry, v9ses, wfidno, 0)) { 410 if (!v9fs_fid_create(file_dentry, v9ses, wfidno, 0)) {
400 if (!v9fs_t_clunk(v9ses, newfid, &fcall)) { 411 v9fs_t_clunk(v9ses, newfid);
401 v9fs_put_idpool(wfidno, &v9ses->fidpool); 412 v9fs_put_idpool(wfidno, &v9ses->fidpool);
402 }
403 413
404 goto CleanUpFid; 414 goto CleanUpFid;
405 } 415 }
@@ -431,40 +441,21 @@ v9fs_create(struct inode *dir,
431 file_dentry->d_op = &v9fs_dentry_operations; 441 file_dentry->d_op = &v9fs_dentry_operations;
432 d_instantiate(file_dentry, file_inode); 442 d_instantiate(file_dentry, file_inode);
433 443
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; 444 return 0;
447 445
448 CleanUpFid: 446 CleanUpFid:
449 kfree(fcall); 447 kfree(fcall);
448 fcall = NULL;
450 449
451 if (newfid >= 0) { 450 if (newfid >= 0) {
452 if (!v9fs_t_clunk(v9ses, newfid, &fcall)) 451 err = v9fs_t_clunk(v9ses, newfid);
453 v9fs_put_idpool(newfid, &v9ses->fidpool); 452 if (err < 0)
454 else 453 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 } 454 }
460 if (wfidno >= 0) { 455 if (wfidno >= 0) {
461 if (!v9fs_t_clunk(v9ses, wfidno, &fcall)) 456 err = v9fs_t_clunk(v9ses, wfidno);
462 v9fs_put_idpool(wfidno, &v9ses->fidpool); 457 if (err < 0)
463 else 458 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 } 459 }
469 return result; 460 return result;
470} 461}
@@ -972,6 +963,7 @@ v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
972 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir); 963 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
973 struct v9fs_fcall *fcall = NULL; 964 struct v9fs_fcall *fcall = NULL;
974 struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL); 965 struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL);
966 int err;
975 967
976 dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, 968 dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
977 symname); 969 symname);
@@ -1004,9 +996,9 @@ v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
1004 996
1005 kfree(fcall); 997 kfree(fcall);
1006 998
1007 if (v9fs_t_clunk(v9ses, newfid->fid, &fcall)) { 999 err = v9fs_t_clunk(v9ses, newfid->fid);
1008 dprintk(DEBUG_ERROR, "clunk for symlink failed: %s\n", 1000 if (err < 0) {
1009 FCALL_ERROR(fcall)); 1001 dprintk(DEBUG_ERROR, "clunk for symlink failed: %d\n", err);
1010 goto FreeFcall; 1002 goto FreeFcall;
1011 } 1003 }
1012 1004
@@ -1180,6 +1172,7 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1180 struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry); 1172 struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry);
1181 struct v9fs_fid *newfid = NULL; 1173 struct v9fs_fid *newfid = NULL;
1182 char *symname = __getname(); 1174 char *symname = __getname();
1175 int err;
1183 1176
1184 dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, 1177 dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
1185 old_dentry->d_name.name); 1178 old_dentry->d_name.name);
@@ -1216,9 +1209,10 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1216 1209
1217 kfree(fcall); 1210 kfree(fcall);
1218 1211
1219 if (v9fs_t_clunk(v9ses, newfid->fid, &fcall)) { 1212 err = v9fs_t_clunk(v9ses, newfid->fid);
1220 dprintk(DEBUG_ERROR, "clunk for symlink failed: %s\n", 1213
1221 FCALL_ERROR(fcall)); 1214 if (err < 0) {
1215 dprintk(DEBUG_ERROR, "clunk for symlink failed: %d\n", err);
1222 goto FreeMem; 1216 goto FreeMem;
1223 } 1217 }
1224 1218
@@ -1252,6 +1246,7 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1252 struct v9fs_fcall *fcall = NULL; 1246 struct v9fs_fcall *fcall = NULL;
1253 struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL); 1247 struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL);
1254 char *symname = __getname(); 1248 char *symname = __getname();
1249 int err;
1255 1250
1256 dprintk(DEBUG_VFS, " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino, 1251 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)); 1252 dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev));
@@ -1310,9 +1305,9 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1310 /* need to update dcache so we show up */ 1305 /* need to update dcache so we show up */
1311 kfree(fcall); 1306 kfree(fcall);
1312 1307
1313 if (v9fs_t_clunk(v9ses, newfid->fid, &fcall)) { 1308 err = v9fs_t_clunk(v9ses, newfid->fid);
1314 dprintk(DEBUG_ERROR, "clunk for symlink failed: %s\n", 1309 if (err < 0) {
1315 FCALL_ERROR(fcall)); 1310 dprintk(DEBUG_ERROR, "clunk for symlink failed: %d\n", err);
1316 goto FreeMem; 1311 goto FreeMem;
1317 } 1312 }
1318 1313
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c
index 82c5b0084079..83b6edd0988a 100644
--- a/fs/9p/vfs_super.c
+++ b/fs/9p/vfs_super.c
@@ -129,6 +129,7 @@ static struct super_block *v9fs_get_sb(struct file_system_type
129 129
130 if ((newfid = v9fs_session_init(v9ses, dev_name, data)) < 0) { 130 if ((newfid = v9fs_session_init(v9ses, dev_name, data)) < 0) {
131 dprintk(DEBUG_ERROR, "problem initiating session\n"); 131 dprintk(DEBUG_ERROR, "problem initiating session\n");
132 kfree(v9ses);
132 return ERR_PTR(newfid); 133 return ERR_PTR(newfid);
133 } 134 }
134 135
@@ -157,7 +158,7 @@ static struct super_block *v9fs_get_sb(struct file_system_type
157 stat_result = v9fs_t_stat(v9ses, newfid, &fcall); 158 stat_result = v9fs_t_stat(v9ses, newfid, &fcall);
158 if (stat_result < 0) { 159 if (stat_result < 0) {
159 dprintk(DEBUG_ERROR, "stat error\n"); 160 dprintk(DEBUG_ERROR, "stat error\n");
160 v9fs_t_clunk(v9ses, newfid, NULL); 161 v9fs_t_clunk(v9ses, newfid);
161 v9fs_put_idpool(newfid, &v9ses->fidpool); 162 v9fs_put_idpool(newfid, &v9ses->fidpool);
162 } else { 163 } else {
163 /* Setup the Root Inode */ 164 /* Setup the Root Inode */