]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/block/virtio_blk.c
[TCP]: Uninline tcp_set_state
[linux-2.6-omap-h63xx.git] / drivers / block / virtio_blk.c
index a901eee64ba52b620946050722bef5a82d0e7305..924ddd8bccd2b8fdd32e06a7db1c3e05918ebc12 100644 (file)
@@ -4,7 +4,9 @@
 #include <linux/hdreg.h>
 #include <linux/virtio.h>
 #include <linux/virtio_blk.h>
-#include <linux/virtio_blk.h>
+#include <linux/scatterlist.h>
+
+#define VIRTIO_MAX_SG  (3+MAX_PHYS_SEGMENTS)
 
 static unsigned char virtblk_index = 'a';
 struct virtio_blk
@@ -23,7 +25,7 @@ struct virtio_blk
        mempool_t *pool;
 
        /* Scatterlist: can be too big for stack. */
-       struct scatterlist sg[3+MAX_PHYS_SEGMENTS];
+       struct scatterlist sg[VIRTIO_MAX_SG];
 };
 
 struct virtblk_req
@@ -94,8 +96,8 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
        if (blk_barrier_rq(vbr->req))
                vbr->out_hdr.type |= VIRTIO_BLK_T_BARRIER;
 
-       /* We have to zero this, otherwise blk_rq_map_sg gets upset. */
-       memset(vblk->sg, 0, sizeof(vblk->sg));
+       /* This init could be done at vblk creation time */
+       sg_init_table(vblk->sg, VIRTIO_MAX_SG);
        sg_set_buf(&vblk->sg[0], &vbr->out_hdr, sizeof(vbr->out_hdr));
        num = blk_rq_map_sg(q, vbr->req, vblk->sg+1);
        sg_set_buf(&vblk->sg[num+1], &vbr->in_hdr, sizeof(vbr->in_hdr));
@@ -221,7 +223,7 @@ static int virtblk_probe(struct virtio_device *vdev)
        err = virtio_config_val(vdev, VIRTIO_CONFIG_BLK_F_CAPACITY, &cap);
        if (err) {
                dev_err(&vdev->dev, "Bad/missing capacity in config\n");
-               goto out_put_disk;
+               goto out_cleanup_queue;
        }
 
        /* If capacity is too big, truncate with warning. */
@@ -237,7 +239,7 @@ static int virtblk_probe(struct virtio_device *vdev)
                blk_queue_max_segment_size(vblk->disk->queue, v);
        else if (err != -ENOENT) {
                dev_err(&vdev->dev, "Bad SIZE_MAX in config\n");
-               goto out_put_disk;
+               goto out_cleanup_queue;
        }
 
        err = virtio_config_val(vdev, VIRTIO_CONFIG_BLK_F_SEG_MAX, &v);
@@ -245,12 +247,14 @@ static int virtblk_probe(struct virtio_device *vdev)
                blk_queue_max_hw_segments(vblk->disk->queue, v);
        else if (err != -ENOENT) {
                dev_err(&vdev->dev, "Bad SEG_MAX in config\n");
-               goto out_put_disk;
+               goto out_cleanup_queue;
        }
 
        add_disk(vblk->disk);
        return 0;
 
+out_cleanup_queue:
+       blk_cleanup_queue(vblk->disk->queue);
 out_put_disk:
        put_disk(vblk->disk);
 out_unregister_blkdev:
@@ -275,6 +279,8 @@ static void virtblk_remove(struct virtio_device *vdev)
        put_disk(vblk->disk);
        unregister_blkdev(major, "virtblk");
        mempool_destroy(vblk->pool);
+       /* There should be nothing in the queue now, so no need to shutdown */
+       vdev->config->del_vq(vblk->vq);
        kfree(vblk);
 }