From: john cooper <john.cooper@redhat.com>
To: qemu-devel@nongnu.org
Cc: john.cooper@redhat.com, Rusty Russell <rusty@rustcorp.com.au>,
Ryan Harper <ryanh@us.ibm.com>,
Marc Haber <mh+qemu-devel@zugschlus.de>
Subject: [Qemu-devel] [PATCH 0/4] Add virtio disk identification support
Date: Fri, 02 Jul 2010 01:50:15 -0400 [thread overview]
Message-ID: <4C2D7E17.10105@redhat.com> (raw)
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 retrival of the id from guest userland.
Signed-off-by: john cooper<john.cooper@redhat.com>
---
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 0bf929a..bd6b896 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);
@@ -495,6 +502,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 we really intend to hard-limit
+ * the copy length to sizeof (s->sn) even in the case we're left without
+ * a trailing '\0'
+ */
+ strncpy(s->sn, drive_get_serial(s->bs), 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
--
john.cooper@redhat.com
next reply other threads:[~2010-07-02 6:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-02 5:50 john cooper [this message]
2010-07-02 6:39 ` [Qemu-devel] [PATCH 0/4] Add virtio disk identification support Markus Armbruster
2010-07-02 6:27 ` john cooper
-- strict thread matches above, loose matches on Subject: below --
2010-03-25 5:31 john cooper
2010-05-28 13:16 ` Ryan Harper
2010-06-02 1:46 ` Ryan Harper
2010-06-02 2:56 ` john cooper
2010-06-03 8:22 ` john cooper
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=4C2D7E17.10105@redhat.com \
--to=john.cooper@redhat.com \
--cc=mh+qemu-devel@zugschlus.de \
--cc=qemu-devel@nongnu.org \
--cc=rusty@rustcorp.com.au \
--cc=ryanh@us.ibm.com \
/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.