From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 03/17] Add virtio disk identification support
Date: Tue, 6 Jul 2010 17:33:12 +0200 [thread overview]
Message-ID: <1278430406-18667-4-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1278430406-18667-1-git-send-email-kwolf@redhat.com>
From: john cooper <john.cooper@redhat.com>
This patch adds the final missing bits for support of
passing a serial/id string to a virtio-blk guest driver.
The guest-side component already exists in the virtio
driver, and has recently been reworked by Ryan to export
a /sys interface for retrieval of the id from guest userland.
Signed-off-by: john cooper <john.cooper@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/virtio-blk.c | 14 ++++++++++++++
hw/virtio-blk.h | 3 +++
2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index f0b3ba5..0bd57b5 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -26,6 +26,7 @@ typedef struct VirtIOBlock
QEMUBH *bh;
BlockConf *conf;
unsigned short sector_mask;
+ char sn[BLOCK_SERIAL_STRLEN];
} VirtIOBlock;
static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
@@ -324,6 +325,12 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
virtio_blk_handle_flush(req, mrb);
} else if (req->out->type & VIRTIO_BLK_T_SCSI_CMD) {
virtio_blk_handle_scsi(req);
+ } else if (req->out->type & VIRTIO_BLK_T_GET_ID) {
+ VirtIOBlock *s = req->dev;
+
+ memcpy(req->elem.in_sg[0].iov_base, s->sn,
+ MIN(req->elem.in_sg[0].iov_len, sizeof(s->sn)));
+ virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
} else if (req->out->type & VIRTIO_BLK_T_OUT) {
qemu_iovec_init_external(&req->qiov, &req->elem.out_sg[1],
req->elem.out_num - 1);
@@ -481,6 +488,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf)
VirtIOBlock *s;
int cylinders, heads, secs;
static int virtio_blk_id;
+ DriveInfo *dinfo;
s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
sizeof(struct virtio_blk_config),
@@ -495,6 +503,12 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf)
s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
+ /* NB: per existing s/n string convention the string is terminated
+ * by '\0' only when less than sizeof (s->sn)
+ */
+ dinfo = drive_get_by_blockdev(s->bs);
+ strncpy(s->sn, dinfo->serial, sizeof (s->sn));
+
s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output);
qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h
index 7a7ece3..fff46da 100644
--- a/hw/virtio-blk.h
+++ b/hw/virtio-blk.h
@@ -59,6 +59,9 @@ struct virtio_blk_config
/* Flush the volatile write cache */
#define VIRTIO_BLK_T_FLUSH 4
+/* return the device ID string */
+#define VIRTIO_BLK_T_GET_ID 8
+
/* Barrier before this op. */
#define VIRTIO_BLK_T_BARRIER 0x80000000
--
1.6.6.1
next prev parent reply other threads:[~2010-07-06 15:33 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-06 15:33 [Qemu-devel] [PULL 00/17] Block patches Kevin Wolf
2010-07-06 15:33 ` [Qemu-devel] [PATCH 01/17] qemu-img check: Distinguish different kinds of errors Kevin Wolf
2010-07-06 15:33 ` [Qemu-devel] [PATCH 02/17] qcow2/vdi: Change check to distinguish error cases Kevin Wolf
2010-07-06 15:33 ` Kevin Wolf [this message]
2010-07-06 15:33 ` [Qemu-devel] [PATCH 04/17] blockdev: Clean up how readonly persists across virtual media change Kevin Wolf
2010-07-06 15:33 ` [Qemu-devel] [PATCH 05/17] block migration: Fix test for read-only drive Kevin Wolf
2010-07-06 15:33 ` [Qemu-devel] [PATCH 06/17] raw-posix: Fix test for host CD-ROM Kevin Wolf
2010-07-06 15:33 ` [Qemu-devel] [PATCH 07/17] fdc: Reject unimplemented error actions Kevin Wolf
2010-07-06 15:33 ` [Qemu-devel] [PATCH 08/17] qdev: Don't hw_error() in qdev_init_nofail() Kevin Wolf
2010-07-06 15:33 ` [Qemu-devel] [PATCH 09/17] scsi: Reject unimplemented error actions Kevin Wolf
2010-07-06 15:33 ` [Qemu-devel] [PATCH 10/17] error: New qemu_opts_loc_restore() Kevin Wolf
2010-07-06 15:33 ` [Qemu-devel] [PATCH 11/17] scsi: Error locations for -drive if=scsi device initialization Kevin Wolf
2010-07-06 15:33 ` [Qemu-devel] [PATCH 12/17] ide: Improve error messages Kevin Wolf
2010-07-06 15:33 ` [Qemu-devel] [PATCH 13/17] ide: Replace IDEState members is_cdrom, is_cf by drive_kind Kevin Wolf
2010-07-06 15:33 ` [Qemu-devel] [PATCH 14/17] ide: Make ide_init_drive() return success Kevin Wolf
2010-07-06 15:33 ` [Qemu-devel] [PATCH 15/17] ide: Reject readonly drives unless CD-ROM Kevin Wolf
2010-07-06 15:33 ` [Qemu-devel] [PATCH 16/17] ide: Reject invalid CHS geometry Kevin Wolf
2010-07-06 15:33 ` [Qemu-devel] [PATCH 17/17] block: add sheepdog driver for distributed storage support Kevin Wolf
2010-07-06 19:07 ` [Qemu-devel] [PULL 00/17] Block patches 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=1278430406-18667-4-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=anthony@codemonkey.ws \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).