From patchwork Fri May 29 04:15:27 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john cooper X-Patchwork-Id: 26860 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n4T4IDtJ032269 for ; Fri, 29 May 2009 04:18:14 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752021AbZE2ESJ (ORCPT ); Fri, 29 May 2009 00:18:09 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751611AbZE2ESI (ORCPT ); Fri, 29 May 2009 00:18:08 -0400 Received: from mx2.redhat.com ([66.187.237.31]:49105 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751281AbZE2ESG (ORCPT ); Fri, 29 May 2009 00:18:06 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n4T4I1sg007684; Fri, 29 May 2009 00:18:01 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n4T4I0Oh015828; Fri, 29 May 2009 00:18:01 -0400 Received: from anvil.naka.net (sebastian-int.corp.redhat.com [172.16.52.221]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n4T4HrEs026667; Fri, 29 May 2009 00:17:55 -0400 Message-ID: <4A1F615F.1090701@redhat.com> Date: Fri, 29 May 2009 00:15:27 -0400 From: john cooper User-Agent: Thunderbird 2.0.0.9 (X11/20071115) MIME-Version: 1.0 To: KVM list , qemu-devel@nongnu.org CC: john.cooper@redhat.com, Rusty Russell , Christoph Hellwig Subject: [PATCH 2/2] Add serial number support for virtio_blk, V4 X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org virtio_blk-serial-4.patch drivers/block/virtio_blk.c | 41 ++++++++++++++++++++++++++++++++++++++--- include/linux/virtio_blk.h | 7 +++++++ 2 files changed, 45 insertions(+), 3 deletions(-) ================================================================= --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -146,12 +146,46 @@ static void do_virtblk_request(struct re 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; + u16 *id; + int err = -ENOMEM; + + id = kmalloc(VIRTIO_BLK_ID_BYTES, GFP_KERNEL); + if (!id) + goto out; + + err = virtio_config_buf(vblk->vdev, VIRTIO_BLK_F_IDENTIFY, + offsetof(struct virtio_blk_config, identify), id, + VIRTIO_BLK_ID_BYTES); + + if (err) + goto out_kfree; + + if (copy_to_user(argp, id, VIRTIO_BLK_ID_BYTES)) + err = -EFAULT; + +out_kfree: + kfree(id); +out: + return err; +} + static int virtblk_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, unsigned long data) { - return scsi_cmd_ioctl(bdev->bd_disk->queue, - bdev->bd_disk, mode, cmd, - (void __user *)data); + struct gendisk *disk = bdev->bd_disk; + void __user *argp = (void __user *)data; + + switch (cmd) { + case HDIO_GET_IDENTITY: + return virtblk_identify(disk, argp); + default: + return scsi_cmd_ioctl(disk->queue, disk, mode, cmd, argp); + } } /* We provide getgeo only to please some old bootloader/partitioning tools */ @@ -356,6 +390,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_IDENTIFY }; static struct virtio_driver virtio_blk = { ================================================================= --- a/include/linux/virtio_blk.h +++ b/include/linux/virtio_blk.h @@ -15,7 +15,13 @@ #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */ #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_IDENTIFY 8 /* ATA IDENTIFY supported */ +#define VIRTIO_BLK_ID_LEN 256 +#define VIRTIO_BLK_ID_BYTES (VIRTIO_BLK_ID_LEN * sizeof (u16)) + +/* mapped into pci i/o region 0 + */ struct virtio_blk_config { /* The capacity (in 512-byte sectors). */ @@ -32,6 +38,7 @@ struct virtio_blk_config } geometry; /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ __u32 blk_size; + __u16 identify[VIRTIO_BLK_ID_LEN]; } __attribute__((packed)); /* These two define direction. */