From: john cooper <john.cooper@redhat.com>
To: kvm@vger.kernel.org, qemu-devel@nongnu.org
Cc: john cooper <john.cooper@third-harmonic.com>
Subject: [Qemu-devel] [PATCH 2/2] Add serial number support for virtio_blk, V2
Date: Wed, 13 May 2009 13:07:28 -0400 [thread overview]
Message-ID: <4A0AFE50.4040708@redhat.com> (raw)
In-Reply-To: <49F876B2.5000005@third-harmonic.com>
[-- Attachment #1: Type: text/plain, Size: 29 bytes --]
--
john.cooper@redhat.com
[-- Attachment #2: virtio_blk-serial-2.patch --]
[-- Type: text/x-patch, Size: 2927 bytes --]
drivers/block/virtio_blk.c | 35 ++++++++++++++++++++++++++++++++---
include/linux/virtio_blk.h | 10 ++++++++++
2 files changed, 42 insertions(+), 3 deletions(-)
=================================================================
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -146,12 +146,40 @@ static void do_virtblk_request(struct re
vblk->vq->vq_ops->kick(vblk->vq);
}
+/* user passes the address of a char[] for serial# return, and has set char[0]
+ * to the array size. copy serial# to this char[] and return number of
+ * characters copied excluding any trailing '\0' pad chars in buffer.
+ */
+static int get_virtblk_sn(struct block_device *bdev, void *buf)
+{
+ struct virtio_blk *vblk = bdev->bd_disk->private_data;
+ unsigned char serial[BLOCK_SERIAL_STRLEN];
+ unsigned char snlen;
+ int rv;
+
+ if (copy_from_user(&snlen, buf, sizeof (snlen)))
+ rv = -EFAULT;
+ else if ((rv = virtio_config_val(vblk->vdev, VIRTIO_BLK_F_SN,
+ offsetof(struct virtio_blk_config, serial), &serial)))
+ ;
+ else if (copy_to_user(buf, serial,
+ snlen = min(snlen, (unsigned char)sizeof (serial))))
+ rv = -EFAULT;
+ else
+ for (rv = 0; rv < snlen; ++rv)
+ if (!serial[rv])
+ break;
+ 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 == VBLK_GET_SN)
+ return (get_virtblk_sn(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 +384,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,16 @@
#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 */
+/* ioctl cmd to retrieve serial#
+*/
+#define VBLK_GET_SN ((unsigned int)('V' << 24 | 'B' << 16 | 'L' << 8 | 'K'))
+
+#define BLOCK_SERIAL_STRLEN 20
+
+/* mapped into pci i/o region 0
+ */
struct virtio_blk_config
{
/* The capacity (in 512-byte sectors). */
@@ -32,6 +41,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. */
prev parent reply other threads:[~2009-05-13 17:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-29 15:48 [Qemu-devel] [PATCH 2/2] Add serial number support for virtio_blk john cooper
2009-05-13 17:07 ` john cooper [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A0AFE50.4040708@redhat.com \
--to=john.cooper@redhat.com \
--cc=john.cooper@third-harmonic.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).