From patchwork Wed May 13 17:07:14 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john cooper X-Patchwork-Id: 23571 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n4DHG5mn028364 for ; Wed, 13 May 2009 17:16:05 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760516AbZEMRPq (ORCPT ); Wed, 13 May 2009 13:15:46 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1760465AbZEMRPp (ORCPT ); Wed, 13 May 2009 13:15:45 -0400 Received: from mx2.redhat.com ([66.187.237.31]:51678 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760397AbZEMRPo (ORCPT ); Wed, 13 May 2009 13:15:44 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n4DHFVoj024768; Wed, 13 May 2009 13:15:31 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n4DHFVdg022765; Wed, 13 May 2009 13:15:31 -0400 Received: from anvil.naka.net (sebastian-int.corp.redhat.com [172.16.52.221]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n4DHFNos006119; Wed, 13 May 2009 13:15:26 -0400 Message-ID: <4A0AFE42.903@redhat.com> Date: Wed, 13 May 2009 13:07:14 -0400 From: john cooper User-Agent: Thunderbird 2.0.0.9 (X11/20071115) MIME-Version: 1.0 To: kvm@vger.kernel.org, qemu-devel@nongnu.org CC: john cooper Subject: [PATCH 1/2] Add serial number support for virtio_blk, V2 References: <49F876AA.2070600@third-harmonic.com> In-Reply-To: <49F876AA.2070600@third-harmonic.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index dad4ef0..90825a8 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -25,6 +25,7 @@ typedef struct VirtIOBlock BlockDriverState *bs; VirtQueue *vq; void *rq; + char serial_str[BLOCK_SERIAL_STRLEN + 1]; } VirtIOBlock; static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev) @@ -285,6 +286,8 @@ static void virtio_blk_reset(VirtIODevice *vdev) qemu_aio_flush(); } +/* coalesce internal state, copy to pci i/o region 0 + */ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) { VirtIOBlock *s = to_virtio_blk(vdev); @@ -299,11 +302,13 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) stw_raw(&blkcfg.cylinders, cylinders); blkcfg.heads = heads; blkcfg.sectors = secs; + memcpy(&blkcfg.serial, s->serial_str, sizeof (blkcfg.serial)); memcpy(config, &blkcfg, sizeof(blkcfg)); } static uint32_t virtio_blk_get_features(VirtIODevice *vdev) { + VirtIOBlock *s = to_virtio_blk(vdev); uint32_t features = 0; features |= (1 << VIRTIO_BLK_F_SEG_MAX); @@ -311,6 +316,8 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev) #ifdef __linux__ features |= (1 << VIRTIO_BLK_F_SCSI); #endif + if (strcmp(s->serial_str, "0")) + features |= 1 << VIRTIO_BLK_F_SN; return features; } @@ -353,6 +360,7 @@ void *virtio_blk_init(PCIBus *bus, BlockDriverState *bs) VirtIOBlock *s; int cylinders, heads, secs; static int virtio_blk_id; + char *ps = drive_get_serial(bs); s = (VirtIOBlock *)virtio_init_pci(bus, "virtio-blk", PCI_VENDOR_ID_REDHAT_QUMRANET, @@ -369,6 +377,10 @@ void *virtio_blk_init(PCIBus *bus, BlockDriverState *bs) s->vdev.reset = virtio_blk_reset; s->bs = bs; s->rq = NULL; + if (strlen(ps)) + strncpy(s->serial_str, ps, sizeof (s->serial_str)); + else + snprintf(s->serial_str, sizeof (s->serial_str), "0"); bs->private = &s->vdev.pci_dev; bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs); bdrv_set_geometry_hint(s->bs, cylinders, heads, secs); diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h index 5ef6c36..3229394 100644 --- a/hw/virtio-blk.h +++ b/hw/virtio-blk.h @@ -31,6 +31,7 @@ #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_SCSI 7 /* Supports scsi command passthru */ +#define VIRTIO_BLK_F_SN 8 /* serial number supported */ struct virtio_blk_config { @@ -40,6 +41,8 @@ struct virtio_blk_config uint16_t cylinders; uint8_t heads; uint8_t sectors; + uint32_t _blk_size; /* structure pad, currently unused */ + uint8_t serial[BLOCK_SERIAL_STRLEN]; } __attribute__((packed)); /* These two define direction. */ diff --git a/sysemu.h b/sysemu.h index 1f45fd6..185b4e3 100644 --- a/sysemu.h +++ b/sysemu.h @@ -141,6 +141,8 @@ typedef enum { BLOCK_ERR_STOP_ANY } BlockInterfaceErrorAction; +#define BLOCK_SERIAL_STRLEN 20 + typedef struct DriveInfo { BlockDriverState *bdrv; BlockInterfaceType type; @@ -149,7 +151,7 @@ typedef struct DriveInfo { int used; int drive_opt_idx; BlockInterfaceErrorAction onerror; - char serial[21]; + char serial[BLOCK_SERIAL_STRLEN + 1]; } DriveInfo; #define MAX_IDE_DEVS 2