aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/net/9p/transport.h2
-rw-r--r--net/9p/client.c34
-rw-r--r--net/9p/trans_virtio.c344
3 files changed, 228 insertions, 152 deletions
diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
index adbcafe99177..f9f362e934c9 100644
--- a/include/net/9p/transport.h
+++ b/include/net/9p/transport.h
@@ -40,7 +40,7 @@ struct p9_trans {
40 void (*close) (struct p9_trans *); 40 void (*close) (struct p9_trans *);
41 unsigned int (*poll)(struct p9_trans *, struct poll_table_struct *); 41 unsigned int (*poll)(struct p9_trans *, struct poll_table_struct *);
42 int (*rpc) (struct p9_trans *t, struct p9_fcall *tc, 42 int (*rpc) (struct p9_trans *t, struct p9_fcall *tc,
43 struct p9_fcall **rc); 43 struct p9_fcall **rc, int msize, int dotu);
44}; 44};
45 45
46struct p9_trans_module { 46struct p9_trans_module {
diff --git a/net/9p/client.c b/net/9p/client.c
index b0d08c2375d0..433b30713ef6 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -51,7 +51,7 @@ p9_client_rpc(struct p9_client *c, struct p9_fcall *tc,
51 struct p9_fcall **rc) 51 struct p9_fcall **rc)
52{ 52{
53 if (c->trans->rpc) 53 if (c->trans->rpc)
54 return c->trans->rpc(c->trans, tc, rc); 54 return c->trans->rpc(c->trans, tc, rc, c->msize, c->dotu);
55 else 55 else
56 return p9_conn_rpc(c->conn, tc, rc); 56 return p9_conn_rpc(c->conn, tc, rc);
57} 57}
@@ -99,7 +99,7 @@ struct p9_client *p9_client_create(struct p9_trans *trans, int msize,
99 goto error; 99 goto error;
100 } 100 }
101 101
102 err = p9_client_rpc(clnt->conn, tc, &rc); 102 err = p9_client_rpc(clnt, tc, &rc);
103 if (err) 103 if (err)
104 goto error; 104 goto error;
105 105
@@ -191,7 +191,7 @@ struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid,
191 goto error; 191 goto error;
192 } 192 }
193 193
194 err = p9_client_rpc(clnt->conn, tc, &rc); 194 err = p9_client_rpc(clnt, tc, &rc);
195 if (err) 195 if (err)
196 goto error; 196 goto error;
197 197
@@ -236,7 +236,7 @@ struct p9_fid *p9_client_auth(struct p9_client *clnt, char *uname,
236 goto error; 236 goto error;
237 } 237 }
238 238
239 err = p9_client_rpc(clnt->conn, tc, &rc); 239 err = p9_client_rpc(clnt, tc, &rc);
240 if (err) 240 if (err)
241 goto error; 241 goto error;
242 242
@@ -287,7 +287,7 @@ struct p9_fid *p9_client_walk(struct p9_fid *oldfid, int nwname, char **wnames,
287 goto error; 287 goto error;
288 } 288 }
289 289
290 err = p9_client_rpc(clnt->conn, tc, &rc); 290 err = p9_client_rpc(clnt, tc, &rc);
291 if (err) { 291 if (err) {
292 if (rc && rc->id == P9_RWALK) 292 if (rc && rc->id == P9_RWALK)
293 goto clunk_fid; 293 goto clunk_fid;
@@ -322,7 +322,7 @@ clunk_fid:
322 goto error; 322 goto error;
323 } 323 }
324 324
325 p9_client_rpc(clnt->conn, tc, &rc); 325 p9_client_rpc(clnt, tc, &rc);
326 326
327error: 327error:
328 kfree(tc); 328 kfree(tc);
@@ -356,7 +356,7 @@ int p9_client_open(struct p9_fid *fid, int mode)
356 goto done; 356 goto done;
357 } 357 }
358 358
359 err = p9_client_rpc(clnt->conn, tc, &rc); 359 err = p9_client_rpc(clnt, tc, &rc);
360 if (err) 360 if (err)
361 goto done; 361 goto done;
362 362
@@ -395,7 +395,7 @@ int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode,
395 goto done; 395 goto done;
396 } 396 }
397 397
398 err = p9_client_rpc(clnt->conn, tc, &rc); 398 err = p9_client_rpc(clnt, tc, &rc);
399 if (err) 399 if (err)
400 goto done; 400 goto done;
401 401
@@ -428,7 +428,7 @@ int p9_client_clunk(struct p9_fid *fid)
428 goto done; 428 goto done;
429 } 429 }
430 430
431 err = p9_client_rpc(clnt->conn, tc, &rc); 431 err = p9_client_rpc(clnt, tc, &rc);
432 if (err) 432 if (err)
433 goto done; 433 goto done;
434 434
@@ -460,7 +460,7 @@ int p9_client_remove(struct p9_fid *fid)
460 goto done; 460 goto done;
461 } 461 }
462 462
463 err = p9_client_rpc(clnt->conn, tc, &rc); 463 err = p9_client_rpc(clnt, tc, &rc);
464 if (err) 464 if (err)
465 goto done; 465 goto done;
466 466
@@ -502,7 +502,7 @@ int p9_client_read(struct p9_fid *fid, char *data, u64 offset, u32 count)
502 goto error; 502 goto error;
503 } 503 }
504 504
505 err = p9_client_rpc(clnt->conn, tc, &rc); 505 err = p9_client_rpc(clnt, tc, &rc);
506 if (err) 506 if (err)
507 goto error; 507 goto error;
508 508
@@ -559,7 +559,7 @@ int p9_client_write(struct p9_fid *fid, char *data, u64 offset, u32 count)
559 goto error; 559 goto error;
560 } 560 }
561 561
562 err = p9_client_rpc(clnt->conn, tc, &rc); 562 err = p9_client_rpc(clnt, tc, &rc);
563 if (err) 563 if (err)
564 goto error; 564 goto error;
565 565
@@ -613,7 +613,7 @@ p9_client_uread(struct p9_fid *fid, char __user *data, u64 offset, u32 count)
613 goto error; 613 goto error;
614 } 614 }
615 615
616 err = p9_client_rpc(clnt->conn, tc, &rc); 616 err = p9_client_rpc(clnt, tc, &rc);
617 if (err) 617 if (err)
618 goto error; 618 goto error;
619 619
@@ -677,7 +677,7 @@ p9_client_uwrite(struct p9_fid *fid, const char __user *data, u64 offset,
677 goto error; 677 goto error;
678 } 678 }
679 679
680 err = p9_client_rpc(clnt->conn, tc, &rc); 680 err = p9_client_rpc(clnt, tc, &rc);
681 if (err) 681 if (err)
682 goto error; 682 goto error;
683 683
@@ -748,7 +748,7 @@ struct p9_stat *p9_client_stat(struct p9_fid *fid)
748 goto error; 748 goto error;
749 } 749 }
750 750
751 err = p9_client_rpc(clnt->conn, tc, &rc); 751 err = p9_client_rpc(clnt, tc, &rc);
752 if (err) 752 if (err)
753 goto error; 753 goto error;
754 754
@@ -790,7 +790,7 @@ int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst)
790 goto done; 790 goto done;
791 } 791 }
792 792
793 err = p9_client_rpc(clnt->conn, tc, &rc); 793 err = p9_client_rpc(clnt, tc, &rc);
794 794
795done: 795done:
796 kfree(tc); 796 kfree(tc);
@@ -847,7 +847,7 @@ struct p9_stat *p9_client_dirread(struct p9_fid *fid, u64 offset)
847 goto error; 847 goto error;
848 } 848 }
849 849
850 err = p9_client_rpc(clnt->conn, tc, &rc); 850 err = p9_client_rpc(clnt, tc, &rc);
851 if (err) 851 if (err)
852 goto error; 852 goto error;
853 853
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index 42eea5fe2628..0f590227943b 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -1,17 +1,8 @@
1/* 1/*
2 * The Guest 9p transport driver 2 * The Guest 9p transport driver
3 * 3 *
4 * This is a trivial pipe-based transport driver based on the lguest console 4 * This is a block based transport driver based on the lguest block driver
5 * code: we use lguest's DMA mechanism to send bytes out, and register a 5 * code.
6 * DMA buffer to receive bytes in. It is assumed to be present and available
7 * from the very beginning of boot.
8 *
9 * This may be have been done by just instaniating another HVC console,
10 * but HVC's blocksize of 16 bytes is annoying and painful to performance.
11 *
12 * A more efficient transport could be built based on the virtio block driver
13 * but it requires some changes in the 9p transport model (which are in
14 * progress)
15 * 6 *
16 */ 7 */
17/* 8/*
@@ -55,11 +46,25 @@
55#include <linux/virtio.h> 46#include <linux/virtio.h>
56#include <linux/virtio_9p.h> 47#include <linux/virtio_9p.h>
57 48
49#define VIRTQUEUE_NUM 128
50
58/* a single mutex to manage channel initialization and attachment */ 51/* a single mutex to manage channel initialization and attachment */
59static DECLARE_MUTEX(virtio_9p_lock); 52static DECLARE_MUTEX(virtio_9p_lock);
60/* global which tracks highest initialized channel */ 53/* global which tracks highest initialized channel */
61static int chan_index; 54static int chan_index;
62 55
56#define P9_INIT_MAXTAG 16
57
58#define REQ_STATUS_IDLE 0
59#define REQ_STATUS_SENT 1
60#define REQ_STATUS_RCVD 2
61#define REQ_STATUS_FLSH 3
62
63struct p9_req_t {
64 int status;
65 wait_queue_head_t *wq;
66};
67
63/* We keep all per-channel information in a structure. 68/* We keep all per-channel information in a structure.
64 * This structure is allocated within the devices dev->mem space. 69 * This structure is allocated within the devices dev->mem space.
65 * A pointer to the structure will get put in the transport private. 70 * A pointer to the structure will get put in the transport private.
@@ -68,16 +73,57 @@ static struct virtio_chan {
68 bool initialized; /* channel is initialized */ 73 bool initialized; /* channel is initialized */
69 bool inuse; /* channel is in use */ 74 bool inuse; /* channel is in use */
70 75
71 struct virtqueue *in_vq, *out_vq; 76 spinlock_t lock;
77
72 struct virtio_device *vdev; 78 struct virtio_device *vdev;
79 struct virtqueue *vq;
73 80
74 /* This is our input buffer, and how much data is left in it. */ 81 struct p9_idpool *tagpool;
75 unsigned int in_len; 82 struct p9_req_t *reqs;
76 char *in, *inbuf; 83 int max_tag;
77 84
78 wait_queue_head_t wq; /* waitq for buffer */ 85 /* Scatterlist: can be too big for stack. */
86 struct scatterlist sg[VIRTQUEUE_NUM];
79} channels[MAX_9P_CHAN]; 87} channels[MAX_9P_CHAN];
80 88
89/* Lookup requests by tag */
90static struct p9_req_t *p9_lookup_tag(struct virtio_chan *c, u16 tag)
91{
92 /* This looks up the original request by tag so we know which
93 * buffer to read the data into */
94 tag++;
95
96 while (tag >= c->max_tag) {
97 int old_max = c->max_tag;
98 int count;
99
100 if (c->max_tag)
101 c->max_tag *= 2;
102 else
103 c->max_tag = P9_INIT_MAXTAG;
104
105 c->reqs = krealloc(c->reqs, sizeof(struct p9_req_t)*c->max_tag,
106 GFP_ATOMIC);
107 if (!c->reqs) {
108 printk(KERN_ERR "Couldn't grow tag array\n");
109 BUG();
110 }
111 for (count = old_max; count < c->max_tag; count++) {
112 c->reqs[count].status = REQ_STATUS_IDLE;
113 c->reqs[count].wq = kmalloc(sizeof(wait_queue_t),
114 GFP_ATOMIC);
115 if (!c->reqs[count].wq) {
116 printk(KERN_ERR "Couldn't grow tag array\n");
117 BUG();
118 }
119 init_waitqueue_head(c->reqs[count].wq);
120 }
121 }
122
123 return &c->reqs[tag];
124}
125
126
81/* How many bytes left in this page. */ 127/* How many bytes left in this page. */
82static unsigned int rest_of_page(void *data) 128static unsigned int rest_of_page(void *data)
83{ 129{
@@ -86,128 +132,163 @@ static unsigned int rest_of_page(void *data)
86 132
87static int p9_virtio_write(struct p9_trans *trans, void *buf, int count) 133static int p9_virtio_write(struct p9_trans *trans, void *buf, int count)
88{ 134{
89 struct virtio_chan *chan = (struct virtio_chan *) trans->priv; 135 /* Only use the rpc mechanism for now */
90 struct virtqueue *out_vq = chan->out_vq; 136 return count;
91 struct scatterlist sg[1]; 137}
92 unsigned int len;
93 138
94 P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio write (%d)\n", count); 139static int p9_virtio_read(struct p9_trans *trans, void *buf, int count)
140{
141 /* Only use the rpc mechanism for now */
142 return 0;
143}
95 144
96 /* keep it simple - make sure we don't overflow a page */ 145/* The poll function is used by 9p transports to determine if there
97 if (rest_of_page(buf) < count) 146 * is there is activity available on a particular channel. In our case
98 count = rest_of_page(buf); 147 * we use it to wait for a callback from the input routines.
148 */
149static unsigned int
150p9_virtio_poll(struct p9_trans *trans, struct poll_table_struct *pt)
151{
152 /* Only use the rpc mechanism for now */
153 return 0;
154}
99 155
100 sg_init_one(sg, buf, count); 156static void p9_virtio_close(struct p9_trans *trans)
157{
158 struct virtio_chan *chan = trans->priv;
159 int count;
160 unsigned int flags;
101 161
102 /* add_buf wants a token to identify this buffer: we hand it any 162 spin_lock_irqsave(&chan->lock, flags);
103 * non-NULL pointer, since there's only ever one buffer. */ 163 p9_idpool_destroy(chan->tagpool);
104 if (out_vq->vq_ops->add_buf(out_vq, sg, 1, 0, (void *)1) == 0) { 164 for (count = 0; count < chan->max_tag; count++)
105 /* Tell Host to go! */ 165 kfree(chan->reqs[count].wq);
106 out_vq->vq_ops->kick(out_vq); 166 kfree(chan->reqs);
107 /* Chill out until it's done with the buffer. */ 167 chan->max_tag = 0;
108 while (!out_vq->vq_ops->get_buf(out_vq, &len)) 168 spin_unlock_irqrestore(&chan->lock, flags);
109 cpu_relax();
110 }
111 169
112 P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio wrote (%d)\n", count); 170 down(&virtio_9p_lock);
171 chan->inuse = false;
172 up(&virtio_9p_lock);
113 173
114 /* We're expected to return the amount of data we wrote: all of it. */ 174 kfree(trans);
115 return count;
116} 175}
117 176
118/* Create a scatter-gather list representing our input buffer and put it in the 177static void req_done(struct virtqueue *vq)
119 * queue. */
120static void add_inbuf(struct virtio_chan *chan)
121{ 178{
122 struct scatterlist sg[1]; 179 struct virtio_chan *chan = vq->vdev->priv;
180 struct p9_fcall *rc;
181 unsigned int len;
182 unsigned long flags;
183 struct p9_req_t *req;
184
185 spin_lock_irqsave(&chan->lock, flags);
186 while ((rc = chan->vq->vq_ops->get_buf(chan->vq, &len)) != NULL) {
187 req = p9_lookup_tag(chan, rc->tag);
188 req->status = REQ_STATUS_RCVD;
189 wake_up(req->wq);
190 }
191 /* In case queue is stopped waiting for more buffers. */
192 spin_unlock_irqrestore(&chan->lock, flags);
193}
123 194
124 sg_init_one(sg, chan->inbuf, PAGE_SIZE); 195static int
196pack_sg_list(struct scatterlist *sg, int start, int limit, char *data,
197 int count)
198{
199 int s;
200 int index = start;
201
202 while (count) {
203 s = rest_of_page(data);
204 if (s > count)
205 s = count;
206 sg_set_buf(&sg[index++], data, s);
207 count -= s;
208 data += s;
209 if (index > limit)
210 BUG();
211 }
125 212
126 /* We should always be able to add one buffer to an empty queue. */ 213 return index-start;
127 if (chan->in_vq->vq_ops->add_buf(chan->in_vq, sg, 0, 1, chan->inbuf))
128 BUG();
129 chan->in_vq->vq_ops->kick(chan->in_vq);
130} 214}
131 215
132static int p9_virtio_read(struct p9_trans *trans, void *buf, int count) 216static int
217p9_virtio_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc,
218 int msize, int dotu)
133{ 219{
134 struct virtio_chan *chan = (struct virtio_chan *) trans->priv; 220 int in, out;
135 struct virtqueue *in_vq = chan->in_vq; 221 int n, err, size;
136 222 struct virtio_chan *chan = t->priv;
137 P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio read (%d)\n", count); 223 char *rdata;
224 struct p9_req_t *req;
225 unsigned long flags;
226
227 if (*rc == NULL) {
228 *rc = kmalloc(sizeof(struct p9_fcall) + msize, GFP_KERNEL);
229 if (!*rc)
230 return -ENOMEM;
231 }
138 232
139 /* If we don't have an input queue yet, we can't get input. */ 233 rdata = (char *)*rc+sizeof(struct p9_fcall);
140 BUG_ON(!in_vq);
141 234
142 /* No buffer? Try to get one. */ 235 spin_lock_irqsave(&chan->lock, flags);
143 if (!chan->in_len) { 236 n = P9_NOTAG;
144 chan->in = in_vq->vq_ops->get_buf(in_vq, &chan->in_len); 237 if (tc->id != P9_TVERSION) {
145 if (!chan->in) 238 n = p9_idpool_get(chan->tagpool);
146 return 0; 239 if (n < 0)
240 return -ENOMEM;
147 } 241 }
148 242
149 /* You want more than we have to give? Well, try wanting less! */ 243 req = p9_lookup_tag(chan, n);
150 if (chan->in_len < count) 244 spin_unlock_irqrestore(&chan->lock, flags);
151 count = chan->in_len;
152 245
153 /* Copy across to their buffer and increment offset. */ 246 p9_set_tag(tc, n);
154 memcpy(buf, chan->in, count);
155 chan->in += count;
156 chan->in_len -= count;
157 247
158 /* Finished? Re-register buffer so Host will use it again. */ 248 P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio rpc tag %d\n", n);
159 if (chan->in_len == 0)
160 add_inbuf(chan);
161 249
162 P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio finished read (%d)\n", 250 out = pack_sg_list(chan->sg, 0, VIRTQUEUE_NUM, tc->sdata, tc->size);
163 count); 251 in = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM-out, rdata, msize);
164 252
165 return count; 253 req->status = REQ_STATUS_SENT;
166}
167 254
168/* The poll function is used by 9p transports to determine if there 255 if (chan->vq->vq_ops->add_buf(chan->vq, chan->sg, out, in, tc)) {
169 * is there is activity available on a particular channel. In our case 256 P9_DPRINTK(P9_DEBUG_TRANS,
170 * we use it to wait for a callback from the input routines. 257 "9p debug: virtio rpc add_buf returned failure");
171 */ 258 return -EIO;
172static unsigned int 259 }
173p9_virtio_poll(struct p9_trans *trans, struct poll_table_struct *pt)
174{
175 struct virtio_chan *chan = (struct virtio_chan *)trans->priv;
176 struct virtqueue *in_vq = chan->in_vq;
177 int ret = POLLOUT; /* we can always handle more output */
178 260
179 poll_wait(NULL, &chan->wq, pt); 261 chan->vq->vq_ops->kick(chan->vq);
180 262
181 /* No buffer? Try to get one. */ 263 wait_event(*req->wq, req->status == REQ_STATUS_RCVD);
182 if (!chan->in_len)
183 chan->in = in_vq->vq_ops->get_buf(in_vq, &chan->in_len);
184 264
185 if (chan->in_len) 265 size = le32_to_cpu(*(__le32 *) rdata);
186 ret |= POLLIN;
187 266
188 return ret; 267 err = p9_deserialize_fcall(rdata, size, *rc, dotu);
189} 268 if (err < 0) {
269 P9_DPRINTK(P9_DEBUG_TRANS,
270 "9p debug: virtio rpc deserialize returned %d\n", err);
271 return err;
272 }
190 273
191static void p9_virtio_close(struct p9_trans *trans) 274#ifdef CONFIG_NET_9P_DEBUG
192{ 275 if ((p9_debug_level&P9_DEBUG_FCALL) == P9_DEBUG_FCALL) {
193 struct virtio_chan *chan = trans->priv; 276 char buf[150];
194 277
195 down(&virtio_9p_lock); 278 p9_printfcall(buf, sizeof(buf), *rc, dotu);
196 chan->inuse = false; 279 printk(KERN_NOTICE ">>> %p %s\n", t, buf);
197 up(&virtio_9p_lock); 280 }
281#endif
198 282
199 kfree(trans); 283 if (n != P9_NOTAG && p9_idpool_check(n, chan->tagpool))
200} 284 p9_idpool_put(n, chan->tagpool);
201 285
202static void p9_virtio_intr(struct virtqueue *q) 286 req->status = REQ_STATUS_IDLE;
203{
204 struct virtio_chan *chan = q->vdev->priv;
205 287
206 P9_DPRINTK(P9_DEBUG_TRANS, "9p poll_wakeup: %p\n", &chan->wq); 288 return 0;
207 wake_up_interruptible(&chan->wq);
208} 289}
209 290
210static int p9_virtio_probe(struct virtio_device *dev) 291static int p9_virtio_probe(struct virtio_device *vdev)
211{ 292{
212 int err; 293 int err;
213 struct virtio_chan *chan; 294 struct virtio_chan *chan;
@@ -221,44 +302,29 @@ static int p9_virtio_probe(struct virtio_device *dev)
221 if (chan_index > MAX_9P_CHAN) { 302 if (chan_index > MAX_9P_CHAN) {
222 printk(KERN_ERR "9p: virtio: Maximum channels exceeded\n"); 303 printk(KERN_ERR "9p: virtio: Maximum channels exceeded\n");
223 BUG(); 304 BUG();
224 }
225
226 chan->vdev = dev;
227
228 /* This is the scratch page we use to receive console input */
229 chan->inbuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
230 if (!chan->inbuf) {
231 err = -ENOMEM; 305 err = -ENOMEM;
232 goto fail; 306 goto fail;
233 } 307 }
234 308
235 /* Find the input queue. */ 309 chan->vdev = vdev;
236 dev->priv = chan;
237 chan->in_vq = dev->config->find_vq(dev, 0, p9_virtio_intr);
238 if (IS_ERR(chan->in_vq)) {
239 err = PTR_ERR(chan->in_vq);
240 goto free;
241 }
242 310
243 chan->out_vq = dev->config->find_vq(dev, 1, NULL); 311 /* We expect one virtqueue, for requests. */
244 if (IS_ERR(chan->out_vq)) { 312 chan->vq = vdev->config->find_vq(vdev, 0, req_done);
245 err = PTR_ERR(chan->out_vq); 313 if (IS_ERR(chan->vq)) {
246 goto free_in_vq; 314 err = PTR_ERR(chan->vq);
315 goto out_free_vq;
247 } 316 }
317 chan->vq->vdev->priv = chan;
318 spin_lock_init(&chan->lock);
248 319
249 init_waitqueue_head(&chan->wq); 320 sg_init_table(chan->sg, VIRTQUEUE_NUM);
250 321
251 /* Register the input buffer the first time. */
252 add_inbuf(chan);
253 chan->inuse = false; 322 chan->inuse = false;
254 chan->initialized = true; 323 chan->initialized = true;
255
256 return 0; 324 return 0;
257 325
258free_in_vq: 326out_free_vq:
259 dev->config->del_vq(chan->in_vq); 327 vdev->config->del_vq(chan->vq);
260free:
261 kfree(chan->inbuf);
262fail: 328fail:
263 down(&virtio_9p_lock); 329 down(&virtio_9p_lock);
264 chan_index--; 330 chan_index--;
@@ -274,8 +340,8 @@ fail:
274static struct p9_trans *p9_virtio_create(const char *devname, char *args) 340static struct p9_trans *p9_virtio_create(const char *devname, char *args)
275{ 341{
276 struct p9_trans *trans; 342 struct p9_trans *trans;
277 int index = 0;
278 struct virtio_chan *chan = channels; 343 struct virtio_chan *chan = channels;
344 int index = 0;
279 345
280 down(&virtio_9p_lock); 346 down(&virtio_9p_lock);
281 while (index < MAX_9P_CHAN) { 347 while (index < MAX_9P_CHAN) {
@@ -290,9 +356,18 @@ static struct p9_trans *p9_virtio_create(const char *devname, char *args)
290 up(&virtio_9p_lock); 356 up(&virtio_9p_lock);
291 357
292 if (index >= MAX_9P_CHAN) { 358 if (index >= MAX_9P_CHAN) {
293 printk(KERN_ERR "9p: virtio: couldn't find a free channel\n"); 359 printk(KERN_ERR "9p: no channels available\n");
294 return NULL; 360 return ERR_PTR(-ENODEV);
361 }
362
363 chan->tagpool = p9_idpool_create();
364 if (IS_ERR(chan->tagpool)) {
365 printk(KERN_ERR "9p: couldn't allocate tagpool\n");
366 return ERR_PTR(-ENOMEM);
295 } 367 }
368 p9_idpool_get(chan->tagpool); /* reserve tag 0 */
369 chan->max_tag = 0;
370 chan->reqs = NULL;
296 371
297 trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL); 372 trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL);
298 if (!trans) { 373 if (!trans) {
@@ -304,6 +379,7 @@ static struct p9_trans *p9_virtio_create(const char *devname, char *args)
304 trans->read = p9_virtio_read; 379 trans->read = p9_virtio_read;
305 trans->close = p9_virtio_close; 380 trans->close = p9_virtio_close;
306 trans->poll = p9_virtio_poll; 381 trans->poll = p9_virtio_poll;
382 trans->rpc = p9_virtio_rpc;
307 trans->priv = chan; 383 trans->priv = chan;
308 384
309 return trans; 385 return trans;
@@ -327,7 +403,7 @@ static struct virtio_driver p9_virtio_drv = {
327static struct p9_trans_module p9_virtio_trans = { 403static struct p9_trans_module p9_virtio_trans = {
328 .name = "virtio", 404 .name = "virtio",
329 .create = p9_virtio_create, 405 .create = p9_virtio_create,
330 .maxsize = PAGE_SIZE, 406 .maxsize = PAGE_SIZE*16,
331 .def = 0, 407 .def = 0,
332}; 408};
333 409