Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 147087
b: refs/heads/master
c: 1d589bb
h: refs/heads/master
i:
  147085: eae3abc
  147083: 0a7def4
  147079: 28c46cf
  147071: 47ad9ae
v: v3
  • Loading branch information
john cooper authored and Jens Axboe committed Jun 9, 2009
1 parent 9a7b02a commit ba1c1a0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 77634f33d4078542cf1087995cced0ffdae25aa2
refs/heads/master: 1d589bb16b825b3a7b4edd34d997f1f1f953033d
37 changes: 34 additions & 3 deletions trunk/drivers/block/virtio_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,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 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 */
Expand Down Expand Up @@ -390,7 +421,7 @@ 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 = {
Expand Down
4 changes: 4 additions & 0 deletions trunk/include/linux/virtio_blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
#define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
#define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
#define VIRTIO_BLK_F_IDENTIFY 8 /* ATA IDENTIFY supported */

#define VIRTIO_BLK_ID_BYTES (sizeof(__u16[256])) /* IDENTIFY DATA */

struct virtio_blk_config
{
Expand All @@ -33,6 +36,7 @@ struct virtio_blk_config
} geometry;
/* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
__u32 blk_size;
__u8 identify[VIRTIO_BLK_ID_BYTES];
} __attribute__((packed));

/* These two define direction. */
Expand Down

0 comments on commit ba1c1a0

Please sign in to comment.