@@ -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)
@@ -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
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(-)