Virtio back-end devices can be plugged into both transports:
VIRTIO_PCI and VIRTIO_MMIO. In order to choose the desired
transport we have a property "transport" in every back-end
state struct. By specifying -device virtio-blk-pci user chooses
VIRTIO_PCI transport and "transport" property is set automatically.
But in order to provide full control to user we need to have
"transport" property available to be set through command line:

-device virtio-pci,id=virtio-pci.0
-device virtio-blk,transport=virtio-pci.0,...

Signed-off-by: Evgeny Voevodin <e.voevo...@samsung.com>
---
 hw/qdev-properties.c |   29 +++++++++++++++++++++++++++++
 hw/qdev.h            |    3 +++
 2 files changed, 32 insertions(+)

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 8aca0d4..4226a02 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -2,6 +2,7 @@
 #include "qdev.h"
 #include "qerror.h"
 #include "blockdev.h"
+#include "virtio-transport.h"
 #include "hw/block-common.h"
 #include "net/hub.h"
 
@@ -526,6 +527,34 @@ PropertyInfo qdev_prop_drive = {
     .release = release_drive,
 };
 
+/* --- virtio transport --- */
+
+static int parse_transport(DeviceState *dev, const char *str, void **ptr)
+{
+    VirtIOTransportLink *trl;
+
+    trl = virtio_find_transport(str);
+
+    if (trl == NULL) {
+        return -ENOENT;
+    }
+
+    *ptr = trl;
+
+    return 0;
+}
+
+static void set_transport(Object *obj, Visitor *v, void *opaque,
+                      const char *name, Error **errp)
+{
+    set_pointer(obj, v, opaque, parse_transport, name, errp);
+}
+
+PropertyInfo qdev_prop_transport = {
+    .name  = "transport",
+    .set   = set_transport,
+};
+
 /* --- character device --- */
 
 static int parse_chr(DeviceState *dev, const char *str, void **ptr)
diff --git a/hw/qdev.h b/hw/qdev.h
index d699194..bd6aa6e 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -233,6 +233,7 @@ extern PropertyInfo qdev_prop_macaddr;
 extern PropertyInfo qdev_prop_losttickpolicy;
 extern PropertyInfo qdev_prop_bios_chs_trans;
 extern PropertyInfo qdev_prop_drive;
+extern PropertyInfo qdev_prop_transport;
 extern PropertyInfo qdev_prop_netdev;
 extern PropertyInfo qdev_prop_vlan;
 extern PropertyInfo qdev_prop_pci_devfn;
@@ -294,6 +295,8 @@ extern PropertyInfo qdev_prop_pci_host_devaddr;
     DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, NetClientState*)
 #define DEFINE_PROP_DRIVE(_n, _s, _f) \
     DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *)
+#define DEFINE_PROP_TRANSPORT(_n, _s, _f) \
+    DEFINE_PROP(_n, _s, _f, qdev_prop_transport, VirtIOTransportLink *)
 #define DEFINE_PROP_MACADDR(_n, _s, _f)         \
     DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
 #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
-- 
1.7.9.5


Reply via email to