From: john cooper <john.cooper@third-harmonic.com>
To: kvm@vger.kernel.org, qemu-devel@nongnu.org
Cc: john.cooper@redhat.com
Subject: [PATCH 1/2] Add serial number support for virtio_blk
Date: Wed, 29 Apr 2009 11:47:54 -0400 [thread overview]
Message-ID: <49F876AA.2070600@third-harmonic.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 36 bytes --]
--
john.cooper@third-harmonic.com
[-- Attachment #2: qemu-vblk-serial.patch --]
[-- Type: text/x-patch, Size: 3483 bytes --]
hw/virtio-blk.c | 15 ++++++++++++++-
hw/virtio-blk.h | 3 +++
sysemu.h | 4 +++-
3 files changed, 20 insertions(+), 2 deletions(-)
=================================================================
--- a/qemu/hw/virtio-blk.h
+++ b/qemu/hw/virtio-blk.h
@@ -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_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. */
=================================================================
--- a/qemu/hw/virtio-blk.c
+++ b/qemu/hw/virtio-blk.c
@@ -22,6 +22,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)
@@ -238,6 +239,8 @@ static void virtio_blk_reset(VirtIODevic
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);
@@ -252,12 +255,17 @@ static void virtio_blk_update_config(Vir
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)
{
- 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, Block
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,
@@ -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);
=================================================================
--- a/qemu/sysemu.h
+++ b/qemu/sysemu.h
@@ -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;
WARNING: multiple messages have this Message-ID (diff)
From: john cooper <john.cooper@third-harmonic.com>
To: kvm@vger.kernel.org, qemu-devel@nongnu.org
Cc: john.cooper@redhat.com
Subject: [Qemu-devel] [PATCH 1/2] Add serial number support for virtio_blk
Date: Wed, 29 Apr 2009 11:47:54 -0400 [thread overview]
Message-ID: <49F876AA.2070600@third-harmonic.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 36 bytes --]
--
john.cooper@third-harmonic.com
[-- Attachment #2: qemu-vblk-serial.patch --]
[-- Type: text/x-patch, Size: 3483 bytes --]
hw/virtio-blk.c | 15 ++++++++++++++-
hw/virtio-blk.h | 3 +++
sysemu.h | 4 +++-
3 files changed, 20 insertions(+), 2 deletions(-)
=================================================================
--- a/qemu/hw/virtio-blk.h
+++ b/qemu/hw/virtio-blk.h
@@ -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_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. */
=================================================================
--- a/qemu/hw/virtio-blk.c
+++ b/qemu/hw/virtio-blk.c
@@ -22,6 +22,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)
@@ -238,6 +239,8 @@ static void virtio_blk_reset(VirtIODevic
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);
@@ -252,12 +255,17 @@ static void virtio_blk_update_config(Vir
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)
{
- 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, Block
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,
@@ -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);
=================================================================
--- a/qemu/sysemu.h
+++ b/qemu/sysemu.h
@@ -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;
next reply other threads:[~2009-04-29 15:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-29 15:47 john cooper [this message]
2009-04-29 15:47 ` [Qemu-devel] [PATCH 1/2] Add serial number support for virtio_blk john cooper
2009-05-01 13:59 ` Anthony Liguori
2009-05-01 13:59 ` [Qemu-devel] " Anthony Liguori
2009-05-13 17:07 ` [PATCH 1/2] Add serial number support for virtio_blk, V2 john cooper
2009-05-13 17:07 ` [Qemu-devel] " john cooper
-- strict thread matches above, loose matches on Subject: below --
2009-04-29 14:54 [PATCH 1/2] Add serial number support for virtio_blk john cooper
2009-04-29 15:22 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49F876AA.2070600@third-harmonic.com \
--to=john.cooper@third-harmonic.com \
--cc=john.cooper@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.