diff mbox

[RFC,v2,04/12] hw/qdev-properties.c: Add "transport" property.

Message ID 1347876042-22609-5-git-send-email-e.voevodin@samsung.com
State New
Headers show

Commit Message

Evgeny Voevodin Sept. 17, 2012, 10 a.m. UTC
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.voevodin@samsung.com>
---
 hw/qdev-properties.c |   29 +++++++++++++++++++++++++++++
 hw/qdev.h            |    3 +++
 2 files changed, 32 insertions(+)

Comments

Paolo Bonzini Sept. 17, 2012, 12:42 p.m. UTC | #1
Il 17/09/2012 12:00, Evgeny Voevodin ha scritto:
> 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,...

What's the difference between this and "bus"? i.e.

  -device virtio-pci,id=virtio-pci-0
  -device virtio-blk,bus=virtio-pci-0.0,...

Paolo
Evgeny Voevodin Sept. 18, 2012, 4:48 a.m. UTC | #2
On 09/17/2012 04:42 PM, Paolo Bonzini wrote:
> Il 17/09/2012 12:00, Evgeny Voevodin ha scritto:
>> 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,...
> What's the difference between this and "bus"? i.e.
>
>    -device virtio-pci,id=virtio-pci-0
>    -device virtio-blk,bus=virtio-pci-0.0,...
>
> Paolo
>

The difference is that with "transport" I used a linked list like, say, 
bdrv_states in block.c.
It's much simpler then use buses. Also I was planning to use a <link>.
In this approach buses are used only to reflect hierarchy of devices in 
emulator manager.
And yes, cover letter contains quite misleading information because 
attach to transport
is based on a list of links, not on buses. Sorry, I forgot that when 
wrote the cover.
diff mbox

Patch

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