9p: remove duplicate client state
[safe/jmp/linux-2.6] / net / 9p / trans_virtio.c
index 0bab1f2..72493f0 100644 (file)
@@ -41,6 +41,7 @@
 #include <linux/file.h>
 #include <net/9p/9p.h>
 #include <linux/parser.h>
+#include <net/9p/client.h>
 #include <net/9p/transport.h>
 #include <linux/scatterlist.h>
 #include <linux/virtio.h>
 #define VIRTQUEUE_NUM  128
 
 /* a single mutex to manage channel initialization and attachment */
-static DECLARE_MUTEX(virtio_9p_lock);
+static DEFINE_MUTEX(virtio_9p_lock);
 /* global which tracks highest initialized channel */
 static int chan_index;
 
 #define P9_INIT_MAXTAG 16
 
-
 /**
  * enum p9_req_status_t - virtio request status
  * @REQ_STATUS_IDLE: request slot unused
@@ -197,11 +197,11 @@ static unsigned int rest_of_page(void *data)
  *
  */
 
-static void p9_virtio_close(struct p9_trans *trans)
+static void p9_virtio_close(struct p9_client *client)
 {
-       struct virtio_chan *chan = trans->priv;
+       struct virtio_chan *chan = client->trans;
        int count;
-       unsigned int flags;
+       unsigned long flags;
 
        spin_lock_irqsave(&chan->lock, flags);
        p9_idpool_destroy(chan->tagpool);
@@ -211,11 +211,11 @@ static void p9_virtio_close(struct p9_trans *trans)
        chan->max_tag = 0;
        spin_unlock_irqrestore(&chan->lock, flags);
 
-       down(&virtio_9p_lock);
+       mutex_lock(&virtio_9p_lock);
        chan->inuse = false;
-       up(&virtio_9p_lock);
+       mutex_unlock(&virtio_9p_lock);
 
-       kfree(trans);
+       client->trans = NULL;
 }
 
 /**
@@ -292,17 +292,17 @@ pack_sg_list(struct scatterlist *sg, int start, int limit, char *data,
  */
 
 static int
-p9_virtio_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc)
+p9_virtio_rpc(struct p9_client *c, struct p9_fcall *tc, struct p9_fcall **rc)
 {
        int in, out;
        int n, err, size;
-       struct virtio_chan *chan = t->priv;
+       struct virtio_chan *chan = c->trans;
        char *rdata;
        struct p9_req_t *req;
        unsigned long flags;
 
        if (*rc == NULL) {
-               *rc = kmalloc(sizeof(struct p9_fcall) + t->msize, GFP_KERNEL);
+               *rc = kmalloc(sizeof(struct p9_fcall) + c->msize, GFP_KERNEL);
                if (!*rc)
                        return -ENOMEM;
        }
@@ -325,7 +325,7 @@ p9_virtio_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc)
        P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio rpc tag %d\n", n);
 
        out = pack_sg_list(chan->sg, 0, VIRTQUEUE_NUM, tc->sdata, tc->size);
-       in = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM-out, rdata, t->msize);
+       in = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM-out, rdata, c->msize);
 
        req->status = REQ_STATUS_SENT;
 
@@ -341,7 +341,7 @@ p9_virtio_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc)
 
        size = le32_to_cpu(*(__le32 *) rdata);
 
-       err = p9_deserialize_fcall(rdata, size, *rc, t->extended);
+       err = p9_deserialize_fcall(rdata, size, *rc, c->dotu);
        if (err < 0) {
                P9_DPRINTK(P9_DEBUG_TRANS,
                        "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)
        if ((p9_debug_level&P9_DEBUG_FCALL) == P9_DEBUG_FCALL) {
                char buf[150];
 
-               p9_printfcall(buf, sizeof(buf), *rc, t->extended);
-               printk(KERN_NOTICE ">>> %p %s\n", t, buf);
+               p9_printfcall(buf, sizeof(buf), *rc, c->dotu);
+               printk(KERN_NOTICE ">>> %p %s\n", c, buf);
        }
 #endif
 
@@ -381,10 +381,10 @@ static int p9_virtio_probe(struct virtio_device *vdev)
        struct virtio_chan *chan;
        int index;
 
-       down(&virtio_9p_lock);
+       mutex_lock(&virtio_9p_lock);
        index = chan_index++;
        chan = &channels[index];
-       up(&virtio_9p_lock);
+       mutex_unlock(&virtio_9p_lock);
 
        if (chan_index > MAX_9P_CHAN) {
                printk(KERN_ERR "9p: virtio: Maximum channels exceeded\n");
@@ -413,19 +413,18 @@ static int p9_virtio_probe(struct virtio_device *vdev)
 out_free_vq:
        vdev->config->del_vq(chan->vq);
 fail:
-       down(&virtio_9p_lock);
+       mutex_lock(&virtio_9p_lock);
        chan_index--;
-       up(&virtio_9p_lock);
+       mutex_unlock(&virtio_9p_lock);
        return err;
 }
 
 
 /**
  * p9_virtio_create - allocate a new virtio channel
+ * @client: client instance invoking this transport
  * @devname: string identifying the channel to connect to (unused)
  * @args: args passed from sys_mount() for per-transport options (unused)
- * @msize: requested maximum packet size
- * @extended: 9p2000.u enabled flag
  *
  * This sets up a transport channel for 9p communication.  Right now
  * we only match the first available channel, but eventually we couldlook up
@@ -441,15 +440,13 @@ fail:
  *
  */
 
-static struct p9_trans *
-p9_virtio_create(const char *devname, char *args, int msize,
-                                                       unsigned char extended)
+static int
+p9_virtio_create(struct p9_client *client, const char *devname, char *args)
 {
-       struct p9_trans *trans;
        struct virtio_chan *chan = channels;
        int index = 0;
 
-       down(&virtio_9p_lock);
+       mutex_lock(&virtio_9p_lock);
        while (index < MAX_9P_CHAN) {
                if (chan->initialized && !chan->inuse) {
                        chan->inuse = true;
@@ -459,34 +456,25 @@ p9_virtio_create(const char *devname, char *args, int msize,
                        chan = &channels[index];
                }
        }
-       up(&virtio_9p_lock);
+       mutex_unlock(&virtio_9p_lock);
 
        if (index >= MAX_9P_CHAN) {
                printk(KERN_ERR "9p: no channels available\n");
-               return ERR_PTR(-ENODEV);
+               return -ENODEV;
        }
 
        chan->tagpool = p9_idpool_create();
        if (IS_ERR(chan->tagpool)) {
                printk(KERN_ERR "9p: couldn't allocate tagpool\n");
-               return ERR_PTR(-ENOMEM);
+               return -ENOMEM;
        }
        p9_idpool_get(chan->tagpool); /* reserve tag 0 */
        chan->max_tag = 0;
        chan->reqs = NULL;
 
-       trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL);
-       if (!trans) {
-               printk(KERN_ERR "9p: couldn't allocate transport\n");
-               return ERR_PTR(-ENOMEM);
-       }
-       trans->extended = extended;
-       trans->msize = msize;
-       trans->close = p9_virtio_close;
-       trans->rpc = p9_virtio_rpc;
-       trans->priv = chan;
+       client->trans = (void *)chan;
 
-       return trans;
+       return 0;
 }
 
 /**
@@ -526,8 +514,11 @@ static struct virtio_driver p9_virtio_drv = {
 static struct p9_trans_module p9_virtio_trans = {
        .name = "virtio",
        .create = p9_virtio_create,
+       .close = p9_virtio_close,
+       .rpc = p9_virtio_rpc,
        .maxsize = PAGE_SIZE*16,
        .def = 0,
+       .owner = THIS_MODULE,
 };
 
 /* The standard init function */
@@ -545,6 +536,7 @@ static int __init p9_virtio_init(void)
 static void __exit p9_virtio_cleanup(void)
 {
        unregister_virtio_driver(&p9_virtio_drv);
+       v9fs_unregister_trans(&p9_virtio_trans);
 }
 
 module_init(p9_virtio_init);