aboutsummaryrefslogtreecommitdiffstats
path: root/net/9p/trans_virtio.c
diff options
context:
space:
mode:
authorEric Van Hensbergen <ericvh@ericvh-desktop.austin.ibm.com>2008-10-13 19:45:25 -0400
committerEric Van Hensbergen <ericvh@gmail.com>2008-10-17 12:04:41 -0400
commit8b81ef589ad1483dd977ef47fe00d4ce4d91a0ab (patch)
tree380a19ca0f55fefc60c4a45771f5273c80539c07 /net/9p/trans_virtio.c
parent992b3f1dbeec401e19a80bdb8c81e5df5381f4c5 (diff)
9p: consolidate transport structure
Right now there is a transport module structure which provides per-transport type functions and data and a transport structure which contains per-instance public data as well as function pointers to instance specific functions. This patch moves public transport visible instance data to the client structure (which in some cases had duplicate data) and consolidates the functions into the transport module structure. Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
Diffstat (limited to 'net/9p/trans_virtio.c')
-rw-r--r--net/9p/trans_virtio.c50
1 files changed, 20 insertions, 30 deletions
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index 94912e077a55..72493f04a76d 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -41,6 +41,7 @@
41#include <linux/file.h> 41#include <linux/file.h>
42#include <net/9p/9p.h> 42#include <net/9p/9p.h>
43#include <linux/parser.h> 43#include <linux/parser.h>
44#include <net/9p/client.h>
44#include <net/9p/transport.h> 45#include <net/9p/transport.h>
45#include <linux/scatterlist.h> 46#include <linux/scatterlist.h>
46#include <linux/virtio.h> 47#include <linux/virtio.h>
@@ -55,7 +56,6 @@ static int chan_index;
55 56
56#define P9_INIT_MAXTAG 16 57#define P9_INIT_MAXTAG 16
57 58
58
59/** 59/**
60 * enum p9_req_status_t - virtio request status 60 * enum p9_req_status_t - virtio request status
61 * @REQ_STATUS_IDLE: request slot unused 61 * @REQ_STATUS_IDLE: request slot unused
@@ -197,9 +197,9 @@ static unsigned int rest_of_page(void *data)
197 * 197 *
198 */ 198 */
199 199
200static void p9_virtio_close(struct p9_trans *trans) 200static void p9_virtio_close(struct p9_client *client)
201{ 201{
202 struct virtio_chan *chan = trans->priv; 202 struct virtio_chan *chan = client->trans;
203 int count; 203 int count;
204 unsigned long flags; 204 unsigned long flags;
205 205
@@ -215,7 +215,7 @@ static void p9_virtio_close(struct p9_trans *trans)
215 chan->inuse = false; 215 chan->inuse = false;
216 mutex_unlock(&virtio_9p_lock); 216 mutex_unlock(&virtio_9p_lock);
217 217
218 kfree(trans); 218 client->trans = NULL;
219} 219}
220 220
221/** 221/**
@@ -292,17 +292,17 @@ pack_sg_list(struct scatterlist *sg, int start, int limit, char *data,
292 */ 292 */
293 293
294static int 294static int
295p9_virtio_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc) 295p9_virtio_rpc(struct p9_client *c, struct p9_fcall *tc, struct p9_fcall **rc)
296{ 296{
297 int in, out; 297 int in, out;
298 int n, err, size; 298 int n, err, size;
299 struct virtio_chan *chan = t->priv; 299 struct virtio_chan *chan = c->trans;
300 char *rdata; 300 char *rdata;
301 struct p9_req_t *req; 301 struct p9_req_t *req;
302 unsigned long flags; 302 unsigned long flags;
303 303
304 if (*rc == NULL) { 304 if (*rc == NULL) {
305 *rc = kmalloc(sizeof(struct p9_fcall) + t->msize, GFP_KERNEL); 305 *rc = kmalloc(sizeof(struct p9_fcall) + c->msize, GFP_KERNEL);
306 if (!*rc) 306 if (!*rc)
307 return -ENOMEM; 307 return -ENOMEM;
308 } 308 }
@@ -325,7 +325,7 @@ p9_virtio_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc)
325 P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio rpc tag %d\n", n); 325 P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio rpc tag %d\n", n);
326 326
327 out = pack_sg_list(chan->sg, 0, VIRTQUEUE_NUM, tc->sdata, tc->size); 327 out = pack_sg_list(chan->sg, 0, VIRTQUEUE_NUM, tc->sdata, tc->size);
328 in = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM-out, rdata, t->msize); 328 in = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM-out, rdata, c->msize);
329 329
330 req->status = REQ_STATUS_SENT; 330 req->status = REQ_STATUS_SENT;
331 331
@@ -341,7 +341,7 @@ p9_virtio_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc)
341 341
342 size = le32_to_cpu(*(__le32 *) rdata); 342 size = le32_to_cpu(*(__le32 *) rdata);
343 343
344 err = p9_deserialize_fcall(rdata, size, *rc, t->extended); 344 err = p9_deserialize_fcall(rdata, size, *rc, c->dotu);
345 if (err < 0) { 345 if (err < 0) {
346 P9_DPRINTK(P9_DEBUG_TRANS, 346 P9_DPRINTK(P9_DEBUG_TRANS,
347 "9p debug: virtio rpc deserialize returned %d\n", err); 347 "9p debug: virtio rpc deserialize returned %d\n", err);
@@ -352,8 +352,8 @@ p9_virtio_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc)
352 if ((p9_debug_level&P9_DEBUG_FCALL) == P9_DEBUG_FCALL) { 352 if ((p9_debug_level&P9_DEBUG_FCALL) == P9_DEBUG_FCALL) {
353 char buf[150]; 353 char buf[150];
354 354
355 p9_printfcall(buf, sizeof(buf), *rc, t->extended); 355 p9_printfcall(buf, sizeof(buf), *rc, c->dotu);
356 printk(KERN_NOTICE ">>> %p %s\n", t, buf); 356 printk(KERN_NOTICE ">>> %p %s\n", c, buf);
357 } 357 }
358#endif 358#endif
359 359
@@ -422,10 +422,9 @@ fail:
422 422
423/** 423/**
424 * p9_virtio_create - allocate a new virtio channel 424 * p9_virtio_create - allocate a new virtio channel
425 * @client: client instance invoking this transport
425 * @devname: string identifying the channel to connect to (unused) 426 * @devname: string identifying the channel to connect to (unused)
426 * @args: args passed from sys_mount() for per-transport options (unused) 427 * @args: args passed from sys_mount() for per-transport options (unused)
427 * @msize: requested maximum packet size
428 * @extended: 9p2000.u enabled flag
429 * 428 *
430 * This sets up a transport channel for 9p communication. Right now 429 * This sets up a transport channel for 9p communication. Right now
431 * we only match the first available channel, but eventually we couldlook up 430 * we only match the first available channel, but eventually we couldlook up
@@ -441,11 +440,9 @@ fail:
441 * 440 *
442 */ 441 */
443 442
444static struct p9_trans * 443static int
445p9_virtio_create(const char *devname, char *args, int msize, 444p9_virtio_create(struct p9_client *client, const char *devname, char *args)
446 unsigned char extended)
447{ 445{
448 struct p9_trans *trans;
449 struct virtio_chan *chan = channels; 446 struct virtio_chan *chan = channels;
450 int index = 0; 447 int index = 0;
451 448
@@ -463,30 +460,21 @@ p9_virtio_create(const char *devname, char *args, int msize,
463 460
464 if (index >= MAX_9P_CHAN) { 461 if (index >= MAX_9P_CHAN) {
465 printk(KERN_ERR "9p: no channels available\n"); 462 printk(KERN_ERR "9p: no channels available\n");
466 return ERR_PTR(-ENODEV); 463 return -ENODEV;
467 } 464 }
468 465
469 chan->tagpool = p9_idpool_create(); 466 chan->tagpool = p9_idpool_create();
470 if (IS_ERR(chan->tagpool)) { 467 if (IS_ERR(chan->tagpool)) {
471 printk(KERN_ERR "9p: couldn't allocate tagpool\n"); 468 printk(KERN_ERR "9p: couldn't allocate tagpool\n");
472 return ERR_PTR(-ENOMEM); 469 return -ENOMEM;
473 } 470 }
474 p9_idpool_get(chan->tagpool); /* reserve tag 0 */ 471 p9_idpool_get(chan->tagpool); /* reserve tag 0 */
475 chan->max_tag = 0; 472 chan->max_tag = 0;
476 chan->reqs = NULL; 473 chan->reqs = NULL;
477 474
478 trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL); 475 client->trans = (void *)chan;
479 if (!trans) {
480 printk(KERN_ERR "9p: couldn't allocate transport\n");
481 return ERR_PTR(-ENOMEM);
482 }
483 trans->extended = extended;
484 trans->msize = msize;
485 trans->close = p9_virtio_close;
486 trans->rpc = p9_virtio_rpc;
487 trans->priv = chan;
488 476
489 return trans; 477 return 0;
490} 478}
491 479
492/** 480/**
@@ -526,6 +514,8 @@ static struct virtio_driver p9_virtio_drv = {
526static struct p9_trans_module p9_virtio_trans = { 514static struct p9_trans_module p9_virtio_trans = {
527 .name = "virtio", 515 .name = "virtio",
528 .create = p9_virtio_create, 516 .create = p9_virtio_create,
517 .close = p9_virtio_close,
518 .rpc = p9_virtio_rpc,
529 .maxsize = PAGE_SIZE*16, 519 .maxsize = PAGE_SIZE*16,
530 .def = 0, 520 .def = 0,
531 .owner = THIS_MODULE, 521 .owner = THIS_MODULE,