Add serial number support for virtio_blk
PATCH 1/2 Add serial number support for virtio_blk
Signature · 2 lines
-- [email protected]
hw/virtio-blk.c | 15 ++++++++++++++- hw/virtio-blk.h | 3 +++ sysemu.h | 4 +++- 3 files changed, 20 insertions(+), 2 deletions(-)
=================================================================
qemu/hw/virtio-blk.h +3 -0
@@ -28,6 +28,7 @@#define VIRTIO_BLK_F_SIZE_MAX 1/* Indicates maximum segment size */ #define VIRTIO_BLK_F_SEG_MAX 2/* Indicates maximum # of segments */ #define VIRTIO_BLK_F_GEOMETRY 4/* Indicates support of legacy geometry */ +#define VIRTIO_BLK_F_SN 7/* serial number supported */ struct virtio_blk_config {
@@ -37,6 +38,8 @@ struct virtio_blk_configuint16_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. */
=================================================================
qemu/hw/virtio-blk.c +14 -1
@@ -22,6 +22,7 @@ typedef struct VirtIOBlockBlockDriverState *bs;VirtQueue *vq;void *rq; +char serial_str[BLOCK_SERIAL_STRLEN +1 ]; } VirtIOBlock;static VirtIOBlock *to_virtio_blk (VirtIODevice *vdev)
@@ -238,6 +239,8 @@ static void virtio_blk_reset(VirtIODevicqemu_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);
@@ -252,12 +255,17 @@ static void virtio_blk_update_config(Virstw_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) { -return (1 <<VIRTIO_BLK_F_SEG_MAX |1 <<VIRTIO_BLK_F_GEOMETRY ); +VirtIOBlock *s =to_virtio_blk (vdev); +char ser_set =strcmp (s->serial_str,"0" ); + +return (1 <<VIRTIO_BLK_F_SEG_MAX |1 <<VIRTIO_BLK_F_GEOMETRY | + (ser_set ?1 <<VIRTIO_BLK_F_SN :0 )); }static void virtio_blk_save (QEMUFile *f,void *opaque)
@@ -298,6 +306,7 @@ void *virtio_blk_init(PCIBus *bus, BlockVirtIOBlock *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,
@@ -314,6 +323,10 @@ void *virtio_blk_init(PCIBus *bus, Block 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->devfn = s->vdev.pci_dev.devfn;bdrv_guess_geometry (s->bs, &cylinders, &heads, &secs);bdrv_set_geometry_hint (s->bs, cylinders, heads, secs);
=================================================================
qemu/sysemu.h +3 -1
@@ -133,13 +133,15 @@ typedef enum { BLOCK_ERR_STOP_ANY } BlockInterfaceErrorAction; +#define BLOCK_SERIAL_STRLEN 20 +typedef struct DriveInfo {BlockDriverState *bdrv;BlockInterfaceType type;int bus;int unit;BlockInterfaceErrorAction onerror; -char serial[21 ]; +char serial[BLOCK_SERIAL_STRLEN +1 ];int used;int drive_opt_idx; }DriveInfo ;
Quoted 1 line · john cooper
Hi John,
Please submit this against qemu.git or at least qemu-kvm.git.
Signature · 3 lines
Regards, Anthony Liguori
PATCH 1/2 Add serial number support for virtio_blk, V2
In reply to john cooperSignature · 2 lines
-- [email protected]
hw/virtio-blk.c +12 -0
@@ -25,6 +25,7 @@ typedef struct VirtIOBlockBlockDriverState *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);
hw/virtio-blk.h +3 -0
@@ -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_configuint16_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. */
sysemu.h +3 -1
@@ -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