Patchwork [RFC,8/9] hw/virtio-blk.c: Add virtio-blk device.

login
register
mail settings
Submitter Evgeny Voevodin
Date April 25, 2012, 5:54 a.m.
Message ID <1335333257-5128-9-git-send-email-e.voevodin@samsung.com>
Download mbox | patch
Permalink /patch/154807/
State New
Headers show

Comments

Evgeny Voevodin - April 25, 2012, 5:54 a.m.
Signed-off-by: Evgeny Voevodin <e.voevodin@samsung.com>
---
 hw/virtio-blk.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-blk.h |   11 +++++++++++
 2 files changed, 53 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 49990f8..b6c5ff5 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -15,6 +15,7 @@ 
 #include "qemu-error.h"
 #include "trace.h"
 #include "blockdev.h"
+#include "virtio-transport.h"
 #include "virtio-blk.h"
 #include "scsi-defs.h"
 #ifdef __linux__
@@ -628,3 +629,44 @@  void virtio_blk_exit(VirtIODevice *vdev)
     unregister_savevm(s->qdev, "virtio-blk", s);
     virtio_cleanup(vdev);
 }
+
+/******************** VirtIOBlk Device **********************/
+
+static int virtio_blkdev_init(DeviceState *dev)
+{
+    VirtIODevice *vdev;
+    VirtIOBlockState *proxy = VIRTIO_BLK_FROM_QDEV(dev);
+    vdev = virtio_blk_init(dev, &proxy->block, &proxy->block_serial);
+    if (!vdev) {
+        return -1;
+    }
+    return virtio_init_transport(dev, vdev);
+}
+
+static Property virtio_blkdev_properties[] = {
+    DEFINE_BLOCK_PROPERTIES(VirtIOBlockState, block),
+    DEFINE_PROP_STRING("serial", VirtIOBlockState, block_serial),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_blkdev_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    dc->init = virtio_blkdev_init;
+    dc->props = virtio_blkdev_properties;
+    dc->bus_info = &virtio_transport_bus_info;
+}
+
+static TypeInfo virtio_blkdev_info = {
+    .name = "virtio-blk",
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(VirtIOBlockState),
+    .class_init = virtio_blkdev_class_init,
+};
+
+static void virtio_blk_register_types(void)
+{
+    type_register_static(&virtio_blkdev_info);
+}
+
+type_init(virtio_blk_register_types)
diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h
index 244dce4..34ae7ce 100644
--- a/hw/virtio-blk.h
+++ b/hw/virtio-blk.h
@@ -14,6 +14,7 @@ 
 #ifndef _QEMU_VIRTIO_BLK_H
 #define _QEMU_VIRTIO_BLK_H
 
+#include "sysbus.h"
 #include "virtio.h"
 #include "block.h"
 
@@ -105,4 +106,14 @@  struct virtio_scsi_inhdr
 #define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
         DEFINE_VIRTIO_COMMON_FEATURES(_state, _field)
 #endif
+
+typedef struct {
+    DeviceState qdev;
+    /* virtio-blk */
+    BlockConf block;
+    char *block_serial;
+} VirtIOBlockState;
+
+#define VIRTIO_BLK_FROM_QDEV(dev) DO_UPCAST(VirtIOBlockState, qdev, dev)
+
 #endif