From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M971B-0004zC-O3 for qemu-devel@nongnu.org; Tue, 26 May 2009 20:29:17 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M9717-0004yb-V1 for qemu-devel@nongnu.org; Tue, 26 May 2009 20:29:17 -0400 Received: from [199.232.76.173] (port=43037 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M9717-0004yY-Op for qemu-devel@nongnu.org; Tue, 26 May 2009 20:29:13 -0400 Received: from mx2.redhat.com ([66.187.237.31]:58320) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M9717-0006GX-A0 for qemu-devel@nongnu.org; Tue, 26 May 2009 20:29:13 -0400 Message-ID: <4A1C88DE.6050608@redhat.com> Date: Tue, 26 May 2009 20:27:10 -0400 From: john cooper MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------000800060803030407000206" Subject: [Qemu-devel] [PATCH 2/2] Add serial number support for virtio_blk, V3 List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: KVM list , qemu-devel@nongnu.org Cc: john.cooper@redhat.com This is a multi-part message in MIME format. --------------000800060803030407000206 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit -- john.cooper@redhat.com --------------000800060803030407000206 Content-Type: text/x-patch; name="virtio_blk-serial-3.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="virtio_blk-serial-3.patch" drivers/block/virtio_blk.c | 32 +++++++++++++++++++++++++++++--- include/linux/virtio_blk.h | 6 ++++++ 2 files changed, 35 insertions(+), 3 deletions(-) ================================================================= --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -146,12 +146,37 @@ static void do_virtblk_request(struct re vblk->vq->vq_ops->kick(vblk->vq); } +/* return serial# in IDE identify data (all other fields are currently zero) + */ +static int virtblk_identity(struct block_device *bdev, void *buf) +{ + struct virtio_blk *vblk = bdev->bd_disk->private_data; + u16 *id; + int rv; + + if (!(id = kzalloc(ATA_ID_WORDS, GFP_KERNEL))) + rv = -ENOMEM; + else if ((rv = virtio_config_buf(vblk->vdev, VIRTIO_BLK_F_SN, + offsetof(struct virtio_blk_config, serial), &id[ATA_ID_SERNO], + ATA_ID_SERNO_LEN))) + ; + else if (copy_to_user(buf, id, ATA_ID_WORDS)) + rv = -EFAULT; + else + rv = 0; + if (id) + kfree(id); + return (rv); +} + 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); + if (cmd == HDIO_GET_IDENTITY) + return (virtblk_identity(bdev, (void __user *)data)); + else + return scsi_cmd_ioctl(bdev->bd_disk->queue, bdev->bd_disk, + mode, cmd, (void __user *)data); } /* We provide getgeo only to please some old bootloader/partitioning tools */ @@ -356,6 +381,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_SN }; static struct virtio_driver virtio_blk = { ================================================================= --- a/include/linux/virtio_blk.h +++ b/include/linux/virtio_blk.h @@ -15,7 +15,12 @@ #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_SN 8 /* serial number supported */ +#define BLOCK_SERIAL_STRLEN 20 + +/* mapped into pci i/o region 0 + */ struct virtio_blk_config { /* The capacity (in 512-byte sectors). */ @@ -32,6 +37,7 @@ struct virtio_blk_config } geometry; /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ __u32 blk_size; + __u8 serial[BLOCK_SERIAL_STRLEN]; } __attribute__((packed)); /* These two define direction. */ --------------000800060803030407000206--