Skip to contentSkip to conversation

Add serial number support for virtio_blk, V2

PATCH In review john cooper 3 participants 6 messages May 13, 2009 – May 27, 2009 KVM

lore
Share & tools
lore
#0 lore raw

cover Add serial number support for virtio_blk, V2

[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

Signature · 1 line
[email protected]

/* 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);
}
#1 lore raw
Quoted 2 lines · john cooper

[Resend of earlier patch: 1/2 rebased to qemu-kvm, 2/2 minor tweak]

patch 1/2 seems to be missing.

Quoted 3 lines

Equivalent functionality currently exists for IDE
and SCSI, however it is not yet implemented for
virtio.

So why can't we re-use the existing interfaces instead of inventing a new one?

#2 lore raw
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · john cooper

[Resend of earlier patch: 1/2 rebased to qemu-kvm, 2/2 minor tweak]

patch 1/2 seems to be missing.

It is in the kvm and qemu-devel list archives:

http://www.spinics.net/lists/kvm/maillist.html
http://lists.gnu.org/archive/html/qemu-devel/2009-05/msg00661.html

Quoted 7 lines
Quoted 4 lines

Equivalent functionality currently exists for IDE
and SCSI, however it is not yet implemented for
virtio.

So why can't we re-use the existing interfaces instead of inventing a new one?

I'm unclear to what specifically you're referring -- the ioctl() used to retrieve the serial number in the guest?

-john

Signature · 1 line
[email protected]
#3 lore raw
Quoted 10 lines · john cooper
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · john cooper

[Resend of earlier patch: 1/2 rebased to qemu-kvm, 2/2 minor tweak]

patch 1/2 seems to be missing.

It is in the kvm and qemu-devel list archives:

http://www.spinics.net/lists/kvm/maillist.html
http://lists.gnu.org/archive/html/qemu-devel/2009-05/msg00661.html

Ah, it got posted as reply to the previous submission, not with this one.

Quoted 4 lines
Quoted 2 lines

So why can't we re-use the existing interfaces instead of inventing a new one?

I'm unclear to what specifically you're referring -- the ioctl() used to retrieve the serial number in the guest?

Well, there's not specific ioctl to get a serial number for scsi, but given that we now have SG_IO passthrough in virtio-blk it should be easy enough to provide inquiry data and the device identification VPD page by that way. Not sure how it's handled for ide, maybe that way is even easier.

#4 lore raw
Quoted 17 lines · Christoph Hellwig
Quoted 10 lines · john cooper
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · john cooper

[Resend of earlier patch: 1/2 rebased to qemu-kvm, 2/2 minor tweak]

patch 1/2 seems to be missing.

It is in the kvm and qemu-devel list archives:

http://www.spinics.net/lists/kvm/maillist.html
http://lists.gnu.org/archive/html/qemu-devel/2009-05/msg00661.html

Ah, it got posted as reply to the previous submission, not with this one.

Quoted 2 lines
Quoted 2 lines

So why can't we re-use the existing interfaces instead of inventing a new one?

Quoted 9 lines
Quoted 2 lines

I'm unclear to what specifically you're referring -- the ioctl() used to retrieve the serial number in the guest?

Well, there's not specific ioctl to get a serial number for scsi, but given that we now have SG_IO passthrough in virtio-blk it should be easy enough to provide inquiry data and the device identification VPD page by that way. Not sure how it's handled for ide, maybe that way is even easier.

IDE has "identify" command which return various info including 20 byte serial number.

--
Gleb.

#5 lore raw
In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig
Quoted 3 lines · john cooper
Quoted 2 lines · Christoph Hellwig

So why can't we re-use the existing interfaces instead of inventing a new one?

Quoted 8 lines
Quoted 2 lines

I'm unclear to what specifically you're referring -- the ioctl() used to retrieve the serial number in the guest?

Well, there's not specific ioctl to get a serial number for scsi, but given that we now have SG_IO passthrough in virtio-blk it should be easy enough to provide inquiry data and the device identification VPD page by that way. Not sure how it's handled for ide, maybe that way is even easier.

Yea, I'm hardly in enamored with the IDE/ATA diatribe. But in this case displacing the new ioctl with HDIO_GET_IDENTITY seemed the most straightforward means to provide access within an existing interface. Updated patch follows.

-john

Signature · 1 line
[email protected]