qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] Add serial number support for virtio_blk
@ 2009-04-29 15:47 john cooper
  0 siblings, 0 replies; only message in thread
From: john cooper @ 2009-04-29 15:47 UTC (permalink / raw)
  To: kvm, qemu-devel; +Cc: john.cooper

[-- Attachment #1: Type: text/plain, Size: 994 bytes --]

[Repost -- neglected to add qemu-devel in my
prior post.]

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.patch

which provides the qemu missing bits to interpret
a '-drive .. serial=XYZ ..' flag, and

     virtio_blk-serial.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 kvm-84 and
2.6.28 respectively.

-john


-- 
john.cooper@third-harmonic.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);
}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-04-29 16:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-29 15:47 [Qemu-devel] [PATCH 0/2] Add serial number support for virtio_blk john cooper

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).