From: john cooper <john.cooper@redhat.com>
To: KVM list <kvm@vger.kernel.org>, qemu-devel@nongnu.org
Cc: john.cooper@redhat.com
Subject: [PATCH 0/2] Add serial number support for virtio_blk, V2
Date: Wed, 13 May 2009 13:06:57 -0400 [thread overview]
Message-ID: <4A0AFE31.70908@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1008 bytes --]
[Resend of earlier patch: 1/2 rebased to qemu-kvm,
2/2 minor tweak]
This patch allows passing of a virtio_blk drive
serial number from qemu into a guest's virtio_blk
driver, and provides a means to access the serial
number from a guest's userspace.
Equivalent functionality currently exists for IDE
and SCSI, however it is not yet implemented for
virtio. Scenarios exist where guest code relies
on a unique drive serial number to correctly
identify the machine environment in which it
exists.
The following two patches implement the above:
qemu-vblk-serial-2.patch
which provides the qemu missing bits to interpret
a '-drive .. serial=XYZ ..' flag, and:
virtio_blk-serial-2.patch
which extracts this information and makes it
available to guest userspace via ioctl.
Attached to this patch header is a trivial example
program which retrieves the serial number from
guest userspace.
The above patches are relative to qemu-kvm.git and
2.6.29.3 respectively.
-john
--
john.cooper@redhat.com
[-- Attachment #2: virtio_get_sn.c --]
[-- Type: text/x-csrc, Size: 851 bytes --]
/* example: retrieve serial number from virtio block device
*/
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <linux/virtio_blk.h>
#define iswhite(c) (!('!' <= (c) && (c) <= '~'))
#ifndef VBLK_GET_SN
#define VBLK_GET_SN ((unsigned int)('V' << 24 | 'B' << 16 | 'L' << 8 | 'K'))
#endif
/* get virtblk drive serial#
*/
int main(int ac, char ***av)
{
int fd, nb, i;
unsigned char sn[30];
unsigned char *p;
sn[0] = sizeof (sn);
if ((fd = open("/dev/vda", O_RDONLY)) < 0)
perror("can't open device"), exit(1);
else if ((nb = ioctl(fd, VBLK_GET_SN, &sn)) < 0)
perror("can't ioctl device"), exit(1);
printf("returned %d bytes:\n", nb);
for (p = sn, i = nb; 0 <= --i; ++p)
printf("%02x%c", *p, i ? ' ' : '\t');
for (p = sn, i = nb; 0 <= --i; ++p)
printf("%c%s", iswhite(*p) ? '.' : *p, i ? "" : "\n");
return (0);
}
WARNING: multiple messages have this Message-ID (diff)
From: john cooper <john.cooper@redhat.com>
To: KVM list <kvm@vger.kernel.org>, qemu-devel@nongnu.org
Cc: john.cooper@redhat.com
Subject: [Qemu-devel] [PATCH 0/2] Add serial number support for virtio_blk, V2
Date: Wed, 13 May 2009 13:06:57 -0400 [thread overview]
Message-ID: <4A0AFE31.70908@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1008 bytes --]
[Resend of earlier patch: 1/2 rebased to qemu-kvm,
2/2 minor tweak]
This patch allows passing of a virtio_blk drive
serial number from qemu into a guest's virtio_blk
driver, and provides a means to access the serial
number from a guest's userspace.
Equivalent functionality currently exists for IDE
and SCSI, however it is not yet implemented for
virtio. Scenarios exist where guest code relies
on a unique drive serial number to correctly
identify the machine environment in which it
exists.
The following two patches implement the above:
qemu-vblk-serial-2.patch
which provides the qemu missing bits to interpret
a '-drive .. serial=XYZ ..' flag, and:
virtio_blk-serial-2.patch
which extracts this information and makes it
available to guest userspace via ioctl.
Attached to this patch header is a trivial example
program which retrieves the serial number from
guest userspace.
The above patches are relative to qemu-kvm.git and
2.6.29.3 respectively.
-john
--
john.cooper@redhat.com
[-- Attachment #2: virtio_get_sn.c --]
[-- Type: text/x-csrc, Size: 851 bytes --]
/* example: retrieve serial number from virtio block device
*/
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <linux/virtio_blk.h>
#define iswhite(c) (!('!' <= (c) && (c) <= '~'))
#ifndef VBLK_GET_SN
#define VBLK_GET_SN ((unsigned int)('V' << 24 | 'B' << 16 | 'L' << 8 | 'K'))
#endif
/* get virtblk drive serial#
*/
int main(int ac, char ***av)
{
int fd, nb, i;
unsigned char sn[30];
unsigned char *p;
sn[0] = sizeof (sn);
if ((fd = open("/dev/vda", O_RDONLY)) < 0)
perror("can't open device"), exit(1);
else if ((nb = ioctl(fd, VBLK_GET_SN, &sn)) < 0)
perror("can't ioctl device"), exit(1);
printf("returned %d bytes:\n", nb);
for (p = sn, i = nb; 0 <= --i; ++p)
printf("%02x%c", *p, i ? ' ' : '\t');
for (p = sn, i = nb; 0 <= --i; ++p)
printf("%c%s", iswhite(*p) ? '.' : *p, i ? "" : "\n");
return (0);
}
next reply other threads:[~2009-05-13 17:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-13 17:06 john cooper [this message]
2009-05-13 17:06 ` [Qemu-devel] [PATCH 0/2] Add serial number support for virtio_blk, V2 john cooper
2009-05-18 12:13 ` Christoph Hellwig
2009-05-18 12:13 ` [Qemu-devel] " Christoph Hellwig
2009-05-18 15:00 ` john cooper
2009-05-18 15:00 ` [Qemu-devel] " john cooper
2009-05-20 7:31 ` Christoph Hellwig
2009-05-20 7:31 ` [Qemu-devel] " Christoph Hellwig
2009-05-20 7:36 ` Gleb Natapov
2009-05-20 7:36 ` [Qemu-devel] " Gleb Natapov
2009-05-27 0:26 ` john cooper
2009-05-27 0:26 ` [Qemu-devel] " john cooper
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=4A0AFE31.70908@redhat.com \
--to=john.cooper@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.