qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/4] Add virtio disk identification support
@ 2010-03-25  5:31 john cooper
  2010-05-28 13:16 ` Ryan Harper
  2010-06-02  1:46 ` Ryan Harper
  0 siblings, 2 replies; 8+ messages in thread
From: john cooper @ 2010-03-25  5:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: john.cooper, Rusty Russell, Marc Haber

This series adds the minimal support to qemu and virtio_blk
to support passing of a virtio_blk serial id string from qemu
through the guest driver and to the guest userland.

This is derived in part from a patch set posted by Rusty some
time ago, but has been minimized to remove support for prior
versions which attempted to provide the same functionality via
pci config/io space.  This version rather uses a virtio request
as proposed in Rusty's example.

Also removed is the packaging of the serial/id string within
the glorious bag of bits returned by the ATA_IDENTIFY command.
Here we transfer only the 20 bytes of serial/id string from
qemu to the guest userland.  In the proposed interface, this
is made available by an ioctl() into the virtio_blk driver
however other interfaces (eg: /sys) have also been proposed.
A code snippet is attached below as an example of ioctl usage.

The resulting code is quite minimal and I believe it addresses
all concerns raised in prior versions.

-john



#include <stdio.h>
#include <strings.h>
#include <sys/types.h>
#include <fcntl.h>
#include <linux/hdreg.h>

#define IOCTL_CMD	'VBID'

main()
{
	int fd, rv;
	char buf[512];

	bzero(buf, sizeof (buf));
	if ((fd = open("/dev/vda", O_RDONLY)) < 0)
		perror("open");
	else if (ioctl(fd, IOCTL_CMD, buf) < 0)
		perror("ioctl");
	else
		printf("[%s]\n", buf);
}

-- 
john.cooper@redhat.com

^ permalink raw reply	[flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH 0/4] Add virtio disk identification support
@ 2010-07-02  5:50 john cooper
  2010-07-02  6:39 ` Markus Armbruster
  0 siblings, 1 reply; 8+ messages in thread
From: john cooper @ 2010-07-02  5:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: john.cooper, Rusty Russell, Ryan Harper, Marc Haber

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-07-02  6:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-25  5:31 [Qemu-devel] [PATCH 0/4] Add virtio disk identification support 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
  -- strict thread matches above, loose matches on Subject: below --
2010-07-02  5:50 john cooper
2010-07-02  6:39 ` Markus Armbruster
2010-07-02  6:27   ` john cooper

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).