[WATCHDOG] ar7_wdt: convert to become a platform driver
[safe/jmp/linux-2.6] / drivers / block / virtio_blk.c
index 62275db..aa1a3d5 100644 (file)
@@ -50,7 +50,6 @@ static void blk_done(struct virtqueue *vq)
 
        spin_lock_irqsave(&vblk->lock, flags);
        while ((vbr = vblk->vq->vq_ops->get_buf(vblk->vq, &len)) != NULL) {
-               unsigned int nr_bytes;
                int error;
 
                switch (vbr->status) {
@@ -172,20 +171,51 @@ static void do_virtblk_request(struct request_queue *q)
                vblk->vq->vq_ops->kick(vblk->vq);
 }
 
+/* return ATA identify data
+ */
+static int virtblk_identify(struct gendisk *disk, void *argp)
+{
+       struct virtio_blk *vblk = disk->private_data;
+       void *opaque;
+       int err = -ENOMEM;
+
+       opaque = kmalloc(VIRTIO_BLK_ID_BYTES, GFP_KERNEL);
+       if (!opaque)
+               goto out;
+
+       err = virtio_config_buf(vblk->vdev, VIRTIO_BLK_F_IDENTIFY,
+               offsetof(struct virtio_blk_config, identify), opaque,
+               VIRTIO_BLK_ID_BYTES);
+
+       if (err)
+               goto out_kfree;
+
+       if (copy_to_user(argp, opaque, VIRTIO_BLK_ID_BYTES))
+               err = -EFAULT;
+
+out_kfree:
+       kfree(opaque);
+out:
+       return err;
+}
+
 static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
                         unsigned cmd, unsigned long data)
 {
        struct gendisk *disk = bdev->bd_disk;
        struct virtio_blk *vblk = disk->private_data;
+       void __user *argp = (void __user *)data;
+
+       if (cmd == HDIO_GET_IDENTITY)
+               return virtblk_identify(disk, argp);
 
        /*
         * Only allow the generic SCSI ioctls if the host can support it.
         */
        if (!virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_SCSI))
-               return -ENOIOCTLCMD;
+               return -ENOTTY;
 
-       return scsi_cmd_ioctl(disk->queue, disk, mode, cmd,
-                             (void __user *)data);
+       return scsi_cmd_ioctl(disk->queue, disk, mode, cmd, argp);
 }
 
 /* We provide getgeo only to please some old bootloader/partitioning tools */
@@ -224,7 +254,7 @@ static int index_to_minor(int index)
        return index << PART_BITS;
 }
 
-static int virtblk_probe(struct virtio_device *vdev)
+static int __devinit virtblk_probe(struct virtio_device *vdev)
 {
        struct virtio_blk *vblk;
        int err;
@@ -258,7 +288,7 @@ static int virtblk_probe(struct virtio_device *vdev)
        sg_init_table(vblk->sg, vblk->sg_elems);
 
        /* We expect one virtqueue, for output. */
-       vblk->vq = vdev->config->find_vq(vdev, 0, blk_done);
+       vblk->vq = virtio_find_single_vq(vdev, blk_done, "requests");
        if (IS_ERR(vblk->vq)) {
                err = PTR_ERR(vblk->vq);
                goto out_free_vblk;
@@ -330,6 +360,9 @@ static int virtblk_probe(struct virtio_device *vdev)
        blk_queue_max_phys_segments(vblk->disk->queue, vblk->sg_elems-2);
        blk_queue_max_hw_segments(vblk->disk->queue, vblk->sg_elems-2);
 
+       /* No need to bounce any requests */
+       blk_queue_bounce_limit(vblk->disk->queue, BLK_BOUNCE_ANY);
+
        /* No real sector limit. */
        blk_queue_max_sectors(vblk->disk->queue, -1U);
 
@@ -348,7 +381,7 @@ static int virtblk_probe(struct virtio_device *vdev)
                                offsetof(struct virtio_blk_config, blk_size),
                                &blk_size);
        if (!err)
-               blk_queue_hardsect_size(vblk->disk->queue, blk_size);
+               blk_queue_logical_block_size(vblk->disk->queue, blk_size);
 
        add_disk(vblk->disk);
        return 0;
@@ -358,14 +391,14 @@ out_put_disk:
 out_mempool:
        mempool_destroy(vblk->pool);
 out_free_vq:
-       vdev->config->del_vq(vblk->vq);
+       vdev->config->del_vqs(vdev);
 out_free_vblk:
        kfree(vblk);
 out:
        return err;
 }
 
-static void virtblk_remove(struct virtio_device *vdev)
+static void __devexit virtblk_remove(struct virtio_device *vdev)
 {
        struct virtio_blk *vblk = vdev->priv;
 
@@ -379,7 +412,7 @@ static void virtblk_remove(struct virtio_device *vdev)
        blk_cleanup_queue(vblk->disk->queue);
        put_disk(vblk->disk);
        mempool_destroy(vblk->pool);
-       vdev->config->del_vq(vblk->vq);
+       vdev->config->del_vqs(vdev);
        kfree(vblk);
 }
 
@@ -391,10 +424,15 @@ static struct virtio_device_id id_table[] = {
 static unsigned int features[] = {
        VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX,
        VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE,
-       VIRTIO_BLK_F_SCSI,
+       VIRTIO_BLK_F_SCSI, VIRTIO_BLK_F_IDENTIFY
 };
 
-static struct virtio_driver virtio_blk = {
+/*
+ * virtio_blk causes spurious section mismatch warning by
+ * simultaneously referring to a __devinit and a __devexit function.
+ * Use __refdata to avoid this warning.
+ */
+static struct virtio_driver __refdata virtio_blk = {
        .feature_table = features,
        .feature_table_size = ARRAY_SIZE(features),
        .driver.name =  KBUILD_MODNAME,