From mboxrd@z Thu Jan 1 00:00:00 1970 From: john cooper Subject: [PATCH 0/2] Add serial number support for virtio_blk Date: Wed, 29 Apr 2009 10:53:54 -0400 Message-ID: <49F86A02.2060504@third-harmonic.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080707070901030304090503" Cc: john cooper , john.cooper@redhat.com To: kvm@vger.kernel.org Return-path: Received: from dpc691978010.direcpc.com ([69.19.78.10]:43720 "EHLO anvil.third-harmonic.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753070AbZD2PA4 (ORCPT ); Wed, 29 Apr 2009 11:00:56 -0400 Sender: kvm-owner@vger.kernel.org List-ID: This is a multi-part message in MIME format. --------------080707070901030304090503 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 make 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 --------------080707070901030304090503 Content-Type: text/x-csrc; name="virtio_get_sn.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="virtio_get_sn.c" /* example: retrieve serial number from virtio block device */ #include #include #include #include #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); } --------------080707070901030304090503--