Skip to contentSkip to conversation

virtio: device configuration cleanup

PATCH Superseded Paolo Bonzini 3 participants 16 messages Nov 24, 2011 – Jan 1, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover virtio: device configuration cleanup

This series cleans up device configuration in virtio:

1) all properties (features and not) are moved to a single macro DEFINE_VIRTIO_XYZ_PROPERTIES. This makes the definitions uniform across all three virtio backends.

2) all configuration is moved to a single struct, which embeds the NICConf/BlockConf for respectively virtio-nic/virtio-blk. This lets the DEFINE_VIRTIO_XYZ_PROPERTIES include these pieces as well.

3) virtio-9p had some knowledge of PCI, but there should be no reason why s390 or mmio backends cannot use it. These bits are removed and moved back to virtio-pci.[ch].

Tested x86_64, compiled arm+s390x.

Paolo Bonzini (9):
virtio-net: move property declarations to header file
virtio-net: move NICConf into virtio_net_conf
virtio-serial: move property declarations to header file
virtio-9p: remove PCI dependencies from hw/9pfs/
virtio-9p: move property declarations to header file
virtio-blk: define VirtIOBlkConf
virtio-blk: move property declarations to header file
virtio-blk: move BlockConf into VirtIOBlkConf
virtio: move conf fields into an anonymous union

 hw/9pfs/virtio-9p-device.c           |   35 +---------------------
 hw/{9p.h => 9pfs/virtio-9p-device.h} |    9 ++++-
 hw/9pfs/virtio-9p.c                  |    1 -
 hw/s390-virtio-bus.c                 |   18 +++--------
 hw/s390-virtio-bus.h                 |   11 ++++---
 hw/syborg_virtio.c                   |   15 +++------
 hw/virtio-blk.c                      |   28 ++++++++--------
 hw/virtio-blk.h                      |   12 +++++++
 hw/virtio-net.c                      |   13 ++++----
 hw/virtio-net.h                      |   43 +++++++++++++++------------
 hw/virtio-pci.c                      |   55 +++++++++++++++++++++++----------
 hw/virtio-pci.h                      |   14 +++++----
 hw/virtio-serial.h                   |    5 +++
 hw/virtio.h                          |    9 ++---
 14 files changed, 135 insertions(+), 133 deletions(-)
 rename hw/{9p.h => 9pfs/virtio-9p-device.h} (50%)
Signature · 1 line
1.7.7.1
#1 lore raw

PATCH 1/9 virtio-net: move property declarations to header file

Include also other properties than features. NIC properties are tackled in the next patch.

There is one semantic change: this adds the virtio-net and common feature bits to s390.

---
 hw/s390-virtio-bus.c |    6 +-----
 hw/syborg_virtio.c   |    7 +------
 hw/virtio-net.h      |   41 ++++++++++++++++++++++-------------------
 hw/virtio-pci.c      |    7 +------
 4 files changed, 25 insertions(+), 36 deletions(-)
hw/s390-virtio-bus.c +1 -5
index c4b9a99..0326cfc 100644
@@ -337,11 +337,7 @@ static VirtIOS390DeviceInfo s390_virtio_net = {
     .qdev.size = sizeof(VirtIOS390Device),
     .qdev.props = (Property[]) {
         DEFINE_NIC_PROPERTIES(VirtIOS390Device, nic),
-        DEFINE_PROP_UINT32("x-txtimer", VirtIOS390Device,
-                           net.txtimer, TX_TIMER_INTERVAL),
-        DEFINE_PROP_INT32("x-txburst", VirtIOS390Device,
-                          net.txburst, TX_BURST),
-        DEFINE_PROP_STRING("tx", VirtIOS390Device, net.tx),
+        DEFINE_VIRTIO_NET_PROPERTIES(VirtIOS390Device, host_features, net),
         DEFINE_PROP_END_OF_LIST(),
     },
 };
hw/syborg_virtio.c +1 -6
index 6de952c..98fd47b 100644
@@ -295,12 +295,7 @@ static SysBusDeviceInfo syborg_virtio_net_info = {
     .qdev.size  = sizeof(SyborgVirtIOProxy),
     .qdev.props = (Property[]) {
         DEFINE_NIC_PROPERTIES(SyborgVirtIOProxy, nic),
-        DEFINE_VIRTIO_NET_FEATURES(SyborgVirtIOProxy, host_features),
-        DEFINE_PROP_UINT32("x-txtimer", SyborgVirtIOProxy,
-                           net.txtimer, TX_TIMER_INTERVAL),
-        DEFINE_PROP_INT32("x-txburst", SyborgVirtIOProxy,
-                          net.txburst, TX_BURST),
-        DEFINE_PROP_STRING("tx", SyborgVirtIOProxy, net.tx),
+        DEFINE_VIRTIO_NET_PROPERTIES(SyborgVirtIOProxy, host_features, net),
         DEFINE_PROP_END_OF_LIST(),
     }
 };
hw/virtio-net.h +22 -19

45 lines not on this page · raw message

hw/virtio-pci.c +1 -6
index 64c6a94..a909e5f 100644
@@ -816,13 +816,8 @@ static PCIDeviceInfo virtio_info[] = {
             DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
                             VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
             DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
-            DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features),
+            DEFINE_VIRTIO_NET_PROPERTIES(VirtIOPCIProxy, host_features, net),
             DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic),
-            DEFINE_PROP_UINT32("x-txtimer", VirtIOPCIProxy,
-                               net.txtimer, TX_TIMER_INTERVAL),
-            DEFINE_PROP_INT32("x-txburst", VirtIOPCIProxy,
-                              net.txburst, TX_BURST),
-            DEFINE_PROP_STRING("tx", VirtIOPCIProxy, net.tx),
             DEFINE_PROP_END_OF_LIST(),
         },
         .qdev.reset = virtio_pci_reset,
Signature · 1 line
1.7.7.1
#2 lore raw

PATCH 2/9 virtio-net: move NICConf into virtio_net_conf

In reply to Paolo Bonzini

This part pushes the NIC properties down into virtio_net_conf and DEFINE_VIRTIO_NET_PROPERTIES. No semantic change.

---
 hw/s390-virtio-bus.c |    3 +--
 hw/s390-virtio-bus.h |    1 -
 hw/syborg_virtio.c   |    4 +---
 hw/virtio-net.c      |   13 ++++++-------
 hw/virtio-net.h      |    2 ++
 hw/virtio-pci.c      |    3 +--
 hw/virtio-pci.h      |    1 -
 hw/virtio.h          |    3 +--
 8 files changed, 12 insertions(+), 18 deletions(-)
hw/s390-virtio-bus.c +1 -2
index 0326cfc..80b11e5 100644
@@ -116,7 +116,7 @@ static int s390_virtio_net_init(VirtIOS390Device *dev)
 {
     VirtIODevice *vdev;
 
-    vdev = virtio_net_init((DeviceState *)dev, &dev->nic, &dev->net);
+    vdev = virtio_net_init((DeviceState *)dev, &dev->net);
     if (!vdev) {
         return -1;
     }
@@ -336,7 +336,6 @@ static VirtIOS390DeviceInfo s390_virtio_net = {
     .qdev.alias = "virtio-net",
     .qdev.size = sizeof(VirtIOS390Device),
     .qdev.props = (Property[]) {
-        DEFINE_NIC_PROPERTIES(VirtIOS390Device, nic),
         DEFINE_VIRTIO_NET_PROPERTIES(VirtIOS390Device, host_features, net),
         DEFINE_PROP_END_OF_LIST(),
     },
hw/s390-virtio-bus.h +0 -1
index f1bece7..b10c78b 100644
@@ -43,7 +43,6 @@ typedef struct VirtIOS390Device {
     VirtIODevice *vdev;
     BlockConf block;
     char *block_serial;
-    NICConf nic;
     uint32_t host_features;
     virtio_serial_conf serial;
     virtio_net_conf net;
hw/syborg_virtio.c +1 -3
index 98fd47b..a1dc5ff 100644
@@ -65,7 +65,6 @@ typedef struct {
     qemu_irq irq;
     uint32_t int_enable;
     uint32_t id;
-    NICConf nic;
     uint32_t host_features;
     virtio_net_conf net;
 } SyborgVirtIOProxy;
@@ -285,7 +284,7 @@ static int syborg_virtio_net_init(SysBusDevice *dev)
     VirtIODevice *vdev;
     SyborgVirtIOProxy *proxy = FROM_SYSBUS(SyborgVirtIOProxy, dev);
 
-    vdev = virtio_net_init(&dev->qdev, &proxy->nic, &proxy->net);
+    vdev = virtio_net_init(&dev->qdev, &proxy->net);
     return syborg_virtio_init(proxy, vdev);
 }
 
@@ -294,7 +293,6 @@ static SysBusDeviceInfo syborg_virtio_net_info = {
     .qdev.name  = "syborg,virtio-net",
     .qdev.size  = sizeof(SyborgVirtIOProxy),
     .qdev.props = (Property[]) {
-        DEFINE_NIC_PROPERTIES(SyborgVirtIOProxy, nic),
         DEFINE_VIRTIO_NET_PROPERTIES(SyborgVirtIOProxy, host_features, net),
         DEFINE_PROP_END_OF_LIST(),
     }
hw/virtio-net.c +6 -7
index 8c2f460..163b6c0 100644
@@ -992,8 +992,7 @@ static NetClientInfo net_virtio_info = {
     .link_status_changed = virtio_net_set_link_status,
 };
 
-VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
-                              virtio_net_conf *net)
+VirtIODevice *virtio_net_init(DeviceState *dev, virtio_net_conf *net)
 {
     VirtIONet *n;
 
@@ -1026,13 +1025,13 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
         n->tx_bh = qemu_bh_new(virtio_net_tx_bh, n);
     }
     n->ctrl_vq = virtio_add_queue(&n->vdev, 64, virtio_net_handle_ctrl);
-    qemu_macaddr_default_if_unset(&conf->macaddr);
-    memcpy(&n->mac[0], &conf->macaddr, sizeof(n->mac));
+    qemu_macaddr_default_if_unset(&net->nic.macaddr);
+    memcpy(&n->mac[0], &net->nic.macaddr, sizeof(n->mac));
     n->status = VIRTIO_NET_S_LINK_UP;
 
-    n->nic = qemu_new_nic(&net_virtio_info, conf, dev->info->name, dev->id, n);
+    n->nic = qemu_new_nic(&net_virtio_info, &net->nic, dev->info->name, dev->id, n);
 
-    qemu_format_nic_info_str(&n->nic->nc, conf->macaddr.a);
+    qemu_format_nic_info_str(&n->nic->nc, net->nic.macaddr.a);
 
     n->tx_waiting = 0;
     n->tx_burst = net->txburst;
@@ -1047,7 +1046,7 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
     register_savevm(dev, "virtio-net", -1, VIRTIO_NET_VM_VERSION,
                     virtio_net_save, virtio_net_load, n);
 
-    add_boot_device_path(conf->bootindex, dev, "/ethernet-phy@0");
+    add_boot_device_path(net->nic.bootindex, dev, "/ethernet-phy@0");
 
     return &n->vdev;
 }
hw/virtio-net.h +2 -0
index f6faea9..ee55a85 100644
@@ -58,6 +58,7 @@
 
 typedef struct virtio_net_conf
 {
+    NICConf nic;
     uint32_t txtimer;
     int32_t txburst;
     char *tx;
@@ -168,6 +169,7 @@ struct virtio_net_ctrl_mac {
  #define VIRTIO_NET_CTRL_VLAN_DEL             1
 
 #define DEFINE_VIRTIO_NET_PROPERTIES(_state, _features_field, _conf_field) \
+        DEFINE_NIC_PROPERTIES(_state, _conf_field.nic), \
         DEFINE_VIRTIO_COMMON_FEATURES(_state, _features_field), \
         DEFINE_PROP_BIT("csum", _state, _features_field, VIRTIO_NET_F_CSUM, true), \
         DEFINE_PROP_BIT("guest_csum", _state, _features_field, VIRTIO_NET_F_GUEST_CSUM, true), \
hw/virtio-pci.c +1 -2
index a909e5f..b93477b 100644
@@ -738,7 +738,7 @@ static int virtio_net_init_pci(PCIDevice *pci_dev)
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
     VirtIODevice *vdev;
 
-    vdev = virtio_net_init(&pci_dev->qdev, &proxy->nic, &proxy->net);
+    vdev = virtio_net_init(&pci_dev->qdev, &proxy->net);
 
     vdev->nvectors = proxy->nvectors;
     virtio_init_pci(proxy, vdev);
@@ -817,7 +817,6 @@ static PCIDeviceInfo virtio_info[] = {
                             VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
             DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
             DEFINE_VIRTIO_NET_PROPERTIES(VirtIOPCIProxy, host_features, net),
-            DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic),
             DEFINE_PROP_END_OF_LIST(),
         },
         .qdev.reset = virtio_pci_reset,
hw/virtio-pci.h +0 -1
index f8404de..4126705 100644
@@ -33,7 +33,6 @@ typedef struct {
     uint32_t nvectors;
     BlockConf block;
     char *block_serial;
-    NICConf nic;
     uint32_t host_features;
 #ifdef CONFIG_LINUX
     V9fsConf fsconf;
hw/virtio.h +1 -2
index 25f5564..7303b6c 100644
@@ -194,8 +194,7 @@ void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
 VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
                               char **serial);
 struct virtio_net_conf;
-VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
-                              struct virtio_net_conf *net);
+VirtIODevice *virtio_net_init(DeviceState *dev, struct virtio_net_conf *net);
 typedef struct virtio_serial_conf virtio_serial_conf;
 VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *serial);
 VirtIODevice *virtio_balloon_init(DeviceState *dev);
Signature · 1 line
1.7.7.1
#3 lore raw

PATCH 3/9 virtio-serial: move property declarations to header file

In reply to Paolo Bonzini

Include also other properties than features. This adds the common virtio features to s390.

---
 hw/s390-virtio-bus.c |    3 +--
 hw/virtio-pci.c      |    4 +---
 hw/virtio-serial.h   |    5 +++++
 3 files changed, 7 insertions(+), 5 deletions(-)
hw/s390-virtio-bus.c +1 -2
index 80b11e5..282688a 100644
@@ -359,8 +359,7 @@ static VirtIOS390DeviceInfo s390_virtio_serial = {
     .qdev.alias = "virtio-serial",
     .qdev.size = sizeof(VirtIOS390Device),
     .qdev.props = (Property[]) {
-        DEFINE_PROP_UINT32("max_ports", VirtIOS390Device,
-                           serial.max_virtserial_ports, 31),
+        DEFINE_VIRTIO_SERIAL_PROPERTIES(VirtIOS390Device, host_features, serial),
         DEFINE_PROP_END_OF_LIST(),
     },
 };
hw/virtio-pci.c +1 -3
index b93477b..d5cdc04 100644
@@ -836,9 +836,7 @@ static PCIDeviceInfo virtio_info[] = {
             DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
                                DEV_NVECTORS_UNSPECIFIED),
             DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
-            DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-            DEFINE_PROP_UINT32("max_ports", VirtIOPCIProxy,
-                               serial.max_virtserial_ports, 31),
+            DEFINE_VIRTIO_SERIAL_PROPERTIES(VirtIOPCIProxy, host_features, serial),
             DEFINE_PROP_END_OF_LIST(),
         },
         .qdev.reset = virtio_pci_reset,
hw/virtio-serial.h +5 -0
index ab13803..2e1a428 100644
@@ -204,4 +204,9 @@ size_t virtio_serial_guest_ready(VirtIOSerialPort *port);
  */
 void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle);
 
+#define DEFINE_VIRTIO_SERIAL_PROPERTIES(_state, _feature_field, _conf_field) \
+        DEFINE_VIRTIO_COMMON_FEATURES(_state, _feature_field), \
+        DEFINE_PROP_UINT32("max_ports", _state, \
+                           _conf_field.max_virtserial_ports, 31)
+
 #endif
Signature · 1 line
1.7.7.1
#4 lore raw

PATCH 4/9 virtio-9p: remove PCI dependencies from hw/9pfs/

In reply to Paolo Bonzini

Also move the 9p.h file to 9pfs/virtio-9p-device.h, for consistency with the corresponding .c file.

---
 hw/9pfs/virtio-9p-device.c           |   35 +---------------------------------
 hw/{9p.h => 9pfs/virtio-9p-device.h} |    4 +-
 hw/9pfs/virtio-9p.c                  |    1 -
 hw/virtio-pci.c                      |   35 ++++++++++++++++++++++++++++++++++
 hw/virtio-pci.h                      |    1 +
 hw/virtio.h                          |    2 +-
 6 files changed, 40 insertions(+), 38 deletions(-)
 rename hw/{9p.h => 9pfs/virtio-9p-device.h} (85%)
hw/9pfs/virtio-9p-device.c +1 -34
index bba4c54..509faa8 100644
@@ -14,9 +14,9 @@
 #include "hw/virtio.h"
 #include "hw/pc.h"
 #include "qemu_socket.h"
-#include "hw/virtio-pci.h"
 #include "virtio-9p.h"
 #include "fsdev/qemu-fsdev.h"
+#include "virtio-9p-device.h"
 #include "virtio-9p-xattr.h"
 #include "virtio-9p-coth.h"
 
@@ -147,41 +147,8 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
     return &s->vdev;
 }
 
-static int virtio_9p_init_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-    VirtIODevice *vdev;
-
-    vdev = virtio_9p_init(&pci_dev->qdev, &proxy->fsconf);
-    vdev->nvectors = proxy->nvectors;
-    virtio_init_pci(proxy, vdev);
-    /* make the actual value visible */
-    proxy->nvectors = vdev->nvectors;
-    return 0;
-}
-
-static PCIDeviceInfo virtio_9p_info = {
-    .qdev.name = "virtio-9p-pci",
-    .qdev.size = sizeof(VirtIOPCIProxy),
-    .init      = virtio_9p_init_pci,
-    .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
-    .device_id = 0x1009,
-    .revision  = VIRTIO_PCI_ABI_VERSION,
-    .class_id  = 0x2,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
-                        VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
-        DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
-        DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-        DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag),
-        DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy, fsconf.fsdev_id),
-        DEFINE_PROP_END_OF_LIST(),
-    }
-};
-
 static void virtio_9p_register_devices(void)
 {
-    pci_qdev_register(&virtio_9p_info);
     virtio_9p_set_fd_limit();
 }
 
hw/9pfs/virtio-9p-device.h renamed from hw/9p.h +2 -2
similarity index 85%
rename from hw/9p.h
rename to hw/9pfs/virtio-9p-device.h
index d9951d6..65789db 100644
@@ -11,8 +11,8 @@
  *
  */
 
-#ifndef QEMU_9P_H
-#define QEMU_9P_H
+#ifndef QEMU_VIRTIO_9P_DEVICE_H
+#define QEMU_VIRTIO_9P_DEVICE_H
 
 typedef struct V9fsConf
 {
hw/9pfs/virtio-9p.c +0 -1
index 1b2fc5d..7b786e5 100644
@@ -17,7 +17,6 @@
 #include "hw/virtio.h"
 #include "hw/pc.h"
 #include "qemu_socket.h"
-#include "hw/virtio-pci.h"
 #include "virtio-9p.h"
 #include "fsdev/qemu-fsdev.h"
 #include "virtio-9p-xattr.h"
hw/virtio-pci.c +35 -0
index d5cdc04..78c1790 100644
@@ -779,6 +779,21 @@ static int virtio_balloon_exit_pci(PCIDevice *pci_dev)
     return virtio_exit_pci(pci_dev);
 }
 
+#ifdef CONFIG_LINUX
+static int virtio_9p_init_pci(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+    VirtIODevice *vdev;
+
+    vdev = virtio_9p_init(&pci_dev->qdev, &proxy->fsconf);
+    vdev->nvectors = proxy->nvectors;
+    virtio_init_pci(proxy, vdev);
+    /* make the actual value visible */
+    proxy->nvectors = vdev->nvectors;
+    return 0;
+}
+#endif
+
 static PCIDeviceInfo virtio_info[] = {
     {
         .qdev.name = "virtio-blk-pci",
@@ -855,6 +870,26 @@ static PCIDeviceInfo virtio_info[] = {
             DEFINE_PROP_END_OF_LIST(),
         },
         .qdev.reset = virtio_pci_reset,
+#ifdef CONFIG_LINUX
+    }, {
+        .qdev.name = "virtio-9p-pci",
+        .qdev.size = sizeof(VirtIOPCIProxy),
+        .init      = virtio_9p_init_pci,
+        .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
+        .device_id = 0x1009,
+        .revision  = VIRTIO_PCI_ABI_VERSION,
+        .class_id  = 0x2,
+        .qdev.props = (Property[]) {
+            DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
+                            VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+            DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
+            DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+            DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag),
+            DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy, fsconf.fsdev_id),
+            DEFINE_PROP_END_OF_LIST(),
+        },
+        .qdev.reset = virtio_pci_reset,
+#endif
     },{
         /* end of list */
     }
hw/virtio-pci.h +1 -0
index 4126705..7654c84 100644
@@ -17,6 +17,7 @@
 
 #include "virtio-net.h"
 #include "virtio-serial.h"
+#include "9pfs/virtio-9p-device.h"
 
 /* Performance improves when virtqueue kick processing is decoupled from the
  * vcpu thread using ioeventfd for some devices. */
hw/virtio.h +1 -1
index 7303b6c..9ed8dfc 100644
@@ -21,7 +21,7 @@
 #include "block.h"
 #include "event_notifier.h"
 #ifdef CONFIG_LINUX
-#include "9p.h"
+#include "9pfs/virtio-9p-device.h"
 #endif
 
 /* from Linux's linux/virtio_config.h */
Signature · 1 line
1.7.7.1
#5 lore raw

Re: [Qemu-devel] [PATCH 4/9] virtio-9p: remove PCI dependencies from hw/9pfs/

Quoted 171 lines · Paolo Bonzini

Also move the 9p.h file to 9pfs/virtio-9p-device.h, for consistency with the corresponding .c file.

---
 hw/9pfs/virtio-9p-device.c           |   35 +---------------------------------
 hw/{9p.h => 9pfs/virtio-9p-device.h} |    4 +-
 hw/9pfs/virtio-9p.c                  |    1 -
 hw/virtio-pci.c                      |   35 ++++++++++++++++++++++++++++++++++
 hw/virtio-pci.h                      |    1 +
 hw/virtio.h                          |    2 +-
 6 files changed, 40 insertions(+), 38 deletions(-)
 rename hw/{9p.h => 9pfs/virtio-9p-device.h} (85%)
hw/9pfs/virtio-9p-device.c +1 -34
index bba4c54..509faa8 100644
@@ -14,9 +14,9 @@
 #include "hw/virtio.h"
 #include "hw/pc.h"
 #include "qemu_socket.h"
-#include "hw/virtio-pci.h"
 #include "virtio-9p.h"
 #include "fsdev/qemu-fsdev.h"
+#include "virtio-9p-device.h"
 #include "virtio-9p-xattr.h"
 #include "virtio-9p-coth.h"
 
@@ -147,41 +147,8 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
     return &s->vdev;
 }
 
-static int virtio_9p_init_pci(PCIDevice *pci_dev)
-{
-    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-    VirtIODevice *vdev;
-
-    vdev = virtio_9p_init(&pci_dev->qdev, &proxy->fsconf);
-    vdev->nvectors = proxy->nvectors;
-    virtio_init_pci(proxy, vdev);
-    /* make the actual value visible */
-    proxy->nvectors = vdev->nvectors;
-    return 0;
-}
-
-static PCIDeviceInfo virtio_9p_info = {
-    .qdev.name = "virtio-9p-pci",
-    .qdev.size = sizeof(VirtIOPCIProxy),
-    .init      = virtio_9p_init_pci,
-    .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
-    .device_id = 0x1009,
-    .revision  = VIRTIO_PCI_ABI_VERSION,
-    .class_id  = 0x2,
-    .qdev.props = (Property[]) {
-        DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
-                        VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
-        DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
-        DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-        DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag),
-        DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy, fsconf.fsdev_id),
-        DEFINE_PROP_END_OF_LIST(),
-    }
-};
-
 static void virtio_9p_register_devices(void)
 {
-    pci_qdev_register(&virtio_9p_info);
     virtio_9p_set_fd_limit();
 }
 
hw/9pfs/virtio-9p-device.h renamed from hw/9p.h +2 -2
similarity index 85%
rename from hw/9p.h
rename to hw/9pfs/virtio-9p-device.h
index d9951d6..65789db 100644
@@ -11,8 +11,8 @@
  *
  */
 
-#ifndef QEMU_9P_H
-#define QEMU_9P_H
+#ifndef QEMU_VIRTIO_9P_DEVICE_H
+#define QEMU_VIRTIO_9P_DEVICE_H
 
 typedef struct V9fsConf
 {
hw/9pfs/virtio-9p.c +0 -1
index 1b2fc5d..7b786e5 100644
@@ -17,7 +17,6 @@
 #include "hw/virtio.h"
 #include "hw/pc.h"
 #include "qemu_socket.h"
-#include "hw/virtio-pci.h"
 #include "virtio-9p.h"
 #include "fsdev/qemu-fsdev.h"
 #include "virtio-9p-xattr.h"
hw/virtio-pci.c +35 -0
index d5cdc04..78c1790 100644
@@ -779,6 +779,21 @@ static int virtio_balloon_exit_pci(PCIDevice *pci_dev)
     return virtio_exit_pci(pci_dev);
 }
 
+#ifdef CONFIG_LINUX
+static int virtio_9p_init_pci(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+    VirtIODevice *vdev;
+
+    vdev = virtio_9p_init(&pci_dev->qdev, &proxy->fsconf);
+    vdev->nvectors = proxy->nvectors;
+    virtio_init_pci(proxy, vdev);
+    /* make the actual value visible */
+    proxy->nvectors = vdev->nvectors;
+    return 0;
+}
+#endif
+
 static PCIDeviceInfo virtio_info[] = {
     {
         .qdev.name = "virtio-blk-pci",
@@ -855,6 +870,26 @@ static PCIDeviceInfo virtio_info[] = {
             DEFINE_PROP_END_OF_LIST(),
         },
         .qdev.reset = virtio_pci_reset,
+#ifdef CONFIG_LINUX
+    }, {
+        .qdev.name = "virtio-9p-pci",
+        .qdev.size = sizeof(VirtIOPCIProxy),
+        .init      = virtio_9p_init_pci,
+        .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
+        .device_id = 0x1009,
+        .revision  = VIRTIO_PCI_ABI_VERSION,
+        .class_id  = 0x2,
+        .qdev.props = (Property[]) {
+            DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
+                            VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+            DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
+            DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+            DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag),
+            DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy, fsconf.fsdev_id),
+            DEFINE_PROP_END_OF_LIST(),
+        },
+        .qdev.reset = virtio_pci_reset,
+#endif
     },{
         /* end of list */
     }
hw/virtio-pci.h +1 -0
index 4126705..7654c84 100644
@@ -17,6 +17,7 @@
 
 #include "virtio-net.h"
 #include "virtio-serial.h"
+#include "9pfs/virtio-9p-device.h"
 
 /* Performance improves when virtqueue kick processing is decoupled from the
  * vcpu thread using ioeventfd for some devices. */
hw/virtio.h +0 -0
index 7303b6c..9ed8dfc 100644

hw/virtio.h line 27

Quoted 8 lines
hw/virtio.h +1 -1
@@ -21,7 +21,7 @@
 #include "block.h"
 #include "event_notifier.h"
 #ifdef CONFIG_LINUX
-#include "9p.h"
+#include "9pfs/virtio-9p-device.h"
 #endif
 
 /* from Linux's linux/virtio_config.h */

That adds few #ifdef to virtio-pci.c. Is that ok ? I actually moved that code from virtio-pci.c as a part of 9fe1ebebd0c427fd9b3d1ffffa77a9969d873d93 . Regarding PCI dependency, I was thinking it would be better for 9p to explicitly state that dependency. When virtio can support other than pci devices, we would list then using #ifdef in virtio-9p-device.c That way all 9p device related details can be found at one place. That is one of the reason i did 9fe1ebebd0c427fd9b3d1ffffa77a9969d873d93

Part of the above patch would still be needed if we don't want to apply the full patch above. I have inlined it below.

commit 2cb7289031b2646d6a107610967e90d2320791fa

Author: Aneesh Kumar K.V <[email protected]>
Date:   Mon Nov 28 12:23:49 2011 +0530

hw/9pfs: Add qdev.reset callback for virtio-9p-pci device

Add the device reset callback

hw/9pfs/virtio-9p-device.c +2 -1
index bba4c54..57dc77c 100644
@@ -176,7 +176,8 @@ static PCIDeviceInfo virtio_9p_info = {
         DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag),
         DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy, fsconf.fsdev_id),
         DEFINE_PROP_END_OF_LIST(),
-    }
+    },
+    .qdev.reset = virtio_pci_reset,
 };
 
 static void virtio_9p_register_devices(void)
hw/virtio-pci.c +1 -1
index ca5923c..07f5861 100644
@@ -266,7 +266,7 @@ static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy)
     proxy->ioeventfd_started = false;
 }
 
-static void virtio_pci_reset(DeviceState *d)
+void virtio_pci_reset(DeviceState *d)
 {
     VirtIOPCIProxy *proxy = container_of(d, VirtIOPCIProxy, pci_dev.qdev);
     virtio_pci_stop_ioeventfd(proxy);
hw/virtio-pci.h +1 -0
index f8404de..344c22b 100644
@@ -45,6 +45,7 @@ typedef struct {
 } VirtIOPCIProxy;
 
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
+void virtio_pci_reset(DeviceState *d);
 
 /* Virtio ABI version, if we increment this, we break the guest driver. */
 #define VIRTIO_PCI_ABI_VERSION          0
#6 lore raw

Re: [Qemu-devel] [PATCH 4/9] virtio-9p: remove PCI dependencies from hw/9pfs/

In reply to Paolo Bonzini
Quoted 5 lines · Paolo Bonzini

Also move the 9p.h file to 9pfs/virtio-9p-device.h, for consistency with the corresponding .c file.

---

...

Quoted 13 lines
hw/virtio-pci.c +5 -0
index d5cdc04..78c1790 100644
@@ -779,6 +779,21 @@ static int virtio_balloon_exit_pci(PCIDevice *pci_dev)
     return virtio_exit_pci(pci_dev);
 }
 
+#ifdef CONFIG_LINUX
+static int virtio_9p_init_pci(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+    VirtIODevice *vdev;

hw/virtio-pci.c static int virtio_balloon_exit_pci(PCIDevice *pci_dev) · line 796

Quoted 10 lines
hw/virtio-pci.c +10 -0
+
+    vdev = virtio_9p_init(&pci_dev->qdev, &proxy->fsconf);
+    vdev->nvectors = proxy->nvectors;
+    virtio_init_pci(proxy, vdev);
+    /* make the actual value visible */
+    proxy->nvectors = vdev->nvectors;
+    return 0;
+}
+#endif
+

This ifdef looks wrong to me - is there no way 9p can thinkably work on non-linux hosts? If yes, we should have a separate config entry for 9p, configure script can make it
conditional on linux host.

Signature · 1 line
MST
#7 lore raw

Re: [Qemu-devel] [PATCH 4/9] virtio-9p: remove PCI dependencies from hw/9pfs/

Quoted 15 lines · Michael S. Tsirkin
Quoted 7 lines
Quoted 7 lines

+#ifdef CONFIG_LINUX
+static int virtio_9p_init_pci(PCIDevice *pci_dev) +{
+ VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+ VirtIODevice *vdev;
+
+ vdev = virtio_9p_init(&pci_dev->qdev,&proxy->fsconf);

Quoted 8 lines
Quoted 8 lines
 +    vdev->nvectors = proxy->nvectors;
 +    virtio_init_pci(proxy, vdev);
 +    /* make the actual value visible */
 +    proxy->nvectors = vdev->nvectors;
 +    return 0;

+}
+#endif
+

Quoted 4 lines

This ifdef looks wrong to me - is there no way 9p can thinkably work on non-linux hosts? If yes, we should have a separate config entry for 9p, configure script can make it
conditional on linux host.

I think it was true in the beginning, but more recent versions should only depend on CONFIG_POSIX. I will set up FreeBSD and come back.

Paolo

#8 lore raw

Re: [Qemu-devel] [PATCH 4/9] virtio-9p: remove PCI dependencies from hw/9pfs/

Quoted 21 lines · Paolo Bonzini
Quoted 15 lines · Michael S. Tsirkin
Quoted 7 lines
Quoted 7 lines

+#ifdef CONFIG_LINUX
+static int virtio_9p_init_pci(PCIDevice *pci_dev) +{
+ VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+ VirtIODevice *vdev;
+
+ vdev = virtio_9p_init(&pci_dev->qdev,&proxy->fsconf);

Quoted 8 lines
Quoted 8 lines
 +    vdev->nvectors = proxy->nvectors;
 +    virtio_init_pci(proxy, vdev);
 +    /* make the actual value visible */
 +    proxy->nvectors = vdev->nvectors;
 +    return 0;

+}
+#endif
+

Quoted 4 lines

This ifdef looks wrong to me - is there no way 9p can thinkably work on non-linux hosts? If yes, we should have a separate config entry for 9p, configure script can make it
conditional on linux host.

Quoted 5 lines

I think it was true in the beginning, but more recent versions should only depend on CONFIG_POSIX. I will set up FreeBSD and come back.

Paolo

It might be easier to add CONFIG_VIRTIO_9P. That won't hurt in any case.

Signature · 1 line
MST
#9 lore raw

Re: [Qemu-devel] [PATCH 4/9] virtio-9p: remove PCI dependencies from hw/9pfs/

Quoted 22 lines · Michael S. Tsirkin
Quoted 21 lines · Paolo Bonzini
Quoted 19 lines · Michael S. Tsirkin
Quoted 7 lines
Quoted 7 lines

+#ifdef CONFIG_LINUX
+static int virtio_9p_init_pci(PCIDevice *pci_dev) +{
+ VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+ VirtIODevice *vdev;
+
+ vdev = virtio_9p_init(&pci_dev->qdev,&proxy->fsconf);

Quoted 8 lines
Quoted 8 lines
  +    vdev->nvectors = proxy->nvectors;
  +    virtio_init_pci(proxy, vdev);
  +    /* make the actual value visible */
  +    proxy->nvectors = vdev->nvectors;
  +    return 0;

+}
+#endif
+

This ifdef looks wrong to me - is there no way 9p can thinkably work on non-linux hosts? If yes, we should have a separate config entry for 9p, configure script can make it
conditional on linux host.

Quoted 7 lines
Quoted 5 lines

I think it was true in the beginning, but more recent versions should only depend on CONFIG_POSIX. I will set up FreeBSD and come back.

Paolo

It might be easier to add CONFIG_VIRTIO_9P. That won't hurt in any case.

Actually CONFIG_VIRTFS exists already (Linux dependencies are mostly statfs and d_off in struct dirent, plus extended attributes which are checked separately).

Will resend.

Paolo

#10 lore raw

PATCH 5/9 virtio-9p: move property declarations to header file

In reply to Paolo Bonzini

No s390 change here, since s390 does not (yet?) support virtio-9p.

---
 hw/9pfs/virtio-9p-device.h |    5 +++++
 hw/virtio-pci.c            |    4 +---
 2 files changed, 6 insertions(+), 3 deletions(-)
hw/9pfs/virtio-9p-device.h +5 -0
index 65789db..7f2a4eb 100644
@@ -21,4 +21,9 @@ typedef struct V9fsConf
     char *fsdev_id;
 } V9fsConf;
 
+#define DEFINE_VIRTIO_9P_PROPERTIES(_state, _features_field, _conf_field) \
+    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, _features_field), \
+    DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, _conf_field.tag), \
+    DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy, _conf_field.fsdev_id)
+
 #endif
hw/virtio-pci.c +1 -3
index 78c1790..f522156 100644
@@ -883,9 +883,7 @@ static PCIDeviceInfo virtio_info[] = {
             DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
                             VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
             DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
-            DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-            DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag),
-            DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy, fsconf.fsdev_id),
+            DEFINE_VIRTIO_9P_PROPERTIES(VirtIOPCIProxy, host_features, fsconf),
             DEFINE_PROP_END_OF_LIST(),
         },
         .qdev.reset = virtio_pci_reset,
Signature · 1 line
1.7.7.1
#11 lore raw

PATCH 6/9 virtio-blk: define VirtIOBlkConf

In reply to Paolo Bonzini

It has only one field for now, but this will change soon...

---
 hw/s390-virtio-bus.c |    4 ++--
 hw/s390-virtio-bus.h |    3 ++-
 hw/virtio-blk.c      |   13 ++++++-------
 hw/virtio-blk.h      |    5 +++++
 hw/virtio-pci.c      |    4 ++--
 hw/virtio-pci.h      |    3 ++-
 hw/virtio.h          |    3 ++-
 7 files changed, 21 insertions(+), 14 deletions(-)
hw/s390-virtio-bus.c +2 -2
index 282688a..cf7cfef 100644
@@ -129,7 +129,7 @@ static int s390_virtio_blk_init(VirtIOS390Device *dev)
     VirtIODevice *vdev;
 
     vdev = virtio_blk_init((DeviceState *)dev, &dev->block,
-                           &dev->block_serial);
+                           &dev->blk);
     if (!vdev) {
         return -1;
     }
@@ -348,7 +348,7 @@ static VirtIOS390DeviceInfo s390_virtio_blk = {
     .qdev.size = sizeof(VirtIOS390Device),
     .qdev.props = (Property[]) {
         DEFINE_BLOCK_PROPERTIES(VirtIOS390Device, block),
-        DEFINE_PROP_STRING("serial", VirtIOS390Device, block_serial),
+        DEFINE_PROP_STRING("serial", VirtIOS390Device, blk.serial),
         DEFINE_PROP_END_OF_LIST(),
     },
 };
hw/s390-virtio-bus.h +2 -1
index b10c78b..1f47e4d 100644
@@ -17,6 +17,7 @@
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "virtio-blk.h"
 #include "virtio-net.h"
 #include "virtio-serial.h"
 
@@ -42,7 +43,7 @@ typedef struct VirtIOS390Device {
     uint8_t feat_len;
     VirtIODevice *vdev;
     BlockConf block;
-    char *block_serial;
+    VirtIOBlkConf blk;
     uint32_t host_features;
     virtio_serial_conf serial;
     virtio_net_conf net;
hw/virtio-blk.c +6 -7
index 19e89e7..e34140e 100644
@@ -29,7 +29,7 @@ typedef struct VirtIOBlock
     void *rq;
     QEMUBH *bh;
     BlockConf *conf;
-    char *serial;
+    VirtIOBlkConf *blk;
     unsigned short sector_mask;
     DeviceState *qdev;
 } VirtIOBlock;
@@ -397,7 +397,7 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
          * terminated by '\0' only when shorter than buffer.
          */
         strncpy(req->elem.in_sg[0].iov_base,
-                s->serial ? s->serial : "",
+                s->blk->serial ? s->blk->serial : "",
                 MIN(req->elem.in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES));
         virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
         g_free(req);
@@ -570,8 +570,7 @@ static const BlockDevOps virtio_block_ops = {
     .resize_cb = virtio_blk_resize,
 };
 
-VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
-                              char **serial)
+VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf, VirtIOBlkConf *blk)
 {
     VirtIOBlock *s;
     int cylinders, heads, secs;
@@ -587,11 +586,11 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
         return NULL;
     }
 
-    if (!*serial) {
+    if (!blk->serial) {
         /* try to fall back to value set with legacy -drive serial=... */
         dinfo = drive_get_by_blockdev(conf->bs);
         if (*dinfo->serial) {
-            *serial = strdup(dinfo->serial);
+            blk->serial = strdup(dinfo->serial);
         }
     }
 
@@ -604,7 +603,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
     s->vdev.reset = virtio_blk_reset;
     s->bs = conf->bs;
     s->conf = conf;
-    s->serial = *serial;
+    s->blk = blk;
     s->rq = NULL;
     s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
     bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
hw/virtio-blk.h +5 -0
index 244dce4..5f150f8 100644
@@ -97,6 +97,11 @@ struct virtio_scsi_inhdr
     uint32_t residual;
 };
 
+struct VirtIOBlkConf
+{
+    char *serial;
+};
+
 #ifdef __linux__
 #define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
         DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \
hw/virtio-pci.c +2 -2
index f522156..bd111d0 100644
@@ -670,7 +670,7 @@ static int virtio_blk_init_pci(PCIDevice *pci_dev)
         proxy->class_code = PCI_CLASS_STORAGE_SCSI;
 
     vdev = virtio_blk_init(&pci_dev->qdev, &proxy->block,
-                           &proxy->block_serial);
+                           &proxy->blk);
     if (!vdev) {
         return -1;
     }
@@ -808,7 +808,7 @@ static PCIDeviceInfo virtio_info[] = {
         .qdev.props = (Property[]) {
             DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
             DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, block),
-            DEFINE_PROP_STRING("serial", VirtIOPCIProxy, block_serial),
+            DEFINE_PROP_STRING("serial", VirtIOPCIProxy, blk.serial),
             DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
                             VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
             DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
hw/virtio-pci.h +2 -1
index 7654c84..195e852 100644
@@ -15,6 +15,7 @@
 #ifndef QEMU_VIRTIO_PCI_H
 #define QEMU_VIRTIO_PCI_H
 
+#include "virtio-blk.h"
 #include "virtio-net.h"
 #include "virtio-serial.h"
 #include "9pfs/virtio-9p-device.h"
@@ -33,7 +34,7 @@ typedef struct {
     uint32_t class_code;
     uint32_t nvectors;
     BlockConf block;
-    char *block_serial;
+    VirtIOBlkConf blk;
     uint32_t host_features;
 #ifdef CONFIG_LINUX
     V9fsConf fsconf;
hw/virtio.h +2 -1
index 9ed8dfc..da2941e 100644
@@ -191,8 +191,9 @@ void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
                         void *opaque);
 
 /* Base devices.  */
+typedef struct VirtIOBlkConf VirtIOBlkConf;
 VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
-                              char **serial);
+                              VirtIOBlkConf *blk);
 struct virtio_net_conf;
 VirtIODevice *virtio_net_init(DeviceState *dev, struct virtio_net_conf *net);
 typedef struct virtio_serial_conf virtio_serial_conf;
Signature · 1 line
1.7.7.1
#12 lore raw

PATCH 7/9 virtio-blk: move property declarations to header file

In reply to Paolo Bonzini

Include also other properties than features. This adds the common virtio features to s390.

---
 hw/s390-virtio-bus.c |    2 +-
 hw/virtio-blk.h      |    5 +++++
 hw/virtio-pci.c      |    3 +--
 3 files changed, 7 insertions(+), 3 deletions(-)
hw/s390-virtio-bus.c +1 -1
index cf7cfef..71720b9 100644
@@ -348,7 +348,7 @@ static VirtIOS390DeviceInfo s390_virtio_blk = {
     .qdev.size = sizeof(VirtIOS390Device),
     .qdev.props = (Property[]) {
         DEFINE_BLOCK_PROPERTIES(VirtIOS390Device, block),
-        DEFINE_PROP_STRING("serial", VirtIOS390Device, blk.serial),
+        DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOS390Device, host_features, blk),
         DEFINE_PROP_END_OF_LIST(),
     },
 };
hw/virtio-blk.h +5 -0
index 5f150f8..dd26ae7 100644
@@ -110,4 +110,9 @@ struct VirtIOBlkConf
 #define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
         DEFINE_VIRTIO_COMMON_FEATURES(_state, _field)
 #endif
+
+#define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _features_field, _conf_field) \
+        DEFINE_VIRTIO_BLK_FEATURES(_state, _features_field), \
+        DEFINE_PROP_STRING("serial", _state, _conf_field.serial)
+
 #endif
hw/virtio-pci.c +1 -2
index bd111d0..d64058e 100644
@@ -808,11 +808,10 @@ static PCIDeviceInfo virtio_info[] = {
         .qdev.props = (Property[]) {
             DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
             DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, block),
-            DEFINE_PROP_STRING("serial", VirtIOPCIProxy, blk.serial),
             DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
                             VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
             DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
-            DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
+            DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOPCIProxy, host_features, blk),
             DEFINE_PROP_END_OF_LIST(),
         },
         .qdev.reset = virtio_pci_reset,
Signature · 1 line
1.7.7.1
#13 lore raw

PATCH 8/9 virtio-blk: move BlockConf into VirtIOBlkConf

In reply to Paolo Bonzini

This part pushes the block device properties down into VirtIOBlkConf and DEFINE_VIRTIO_BLK_PROPERTIES. No semantic change.

---
 hw/s390-virtio-bus.c |    4 +---
 hw/s390-virtio-bus.h |    1 -
 hw/virtio-blk.c      |   17 +++++++++--------
 hw/virtio-blk.h      |    2 ++
 hw/virtio-pci.c      |    5 +----
 hw/virtio-pci.h      |    1 -
 hw/virtio.h          |    3 +--
 7 files changed, 14 insertions(+), 19 deletions(-)
hw/s390-virtio-bus.c +1 -3
index 71720b9..a3810f2 100644
@@ -128,8 +128,7 @@ static int s390_virtio_blk_init(VirtIOS390Device *dev)
 {
     VirtIODevice *vdev;
 
-    vdev = virtio_blk_init((DeviceState *)dev, &dev->block,
-                           &dev->blk);
+    vdev = virtio_blk_init((DeviceState *)dev, &dev->blk);
     if (!vdev) {
         return -1;
     }
@@ -347,7 +346,6 @@ static VirtIOS390DeviceInfo s390_virtio_blk = {
     .qdev.alias = "virtio-blk",
     .qdev.size = sizeof(VirtIOS390Device),
     .qdev.props = (Property[]) {
-        DEFINE_BLOCK_PROPERTIES(VirtIOS390Device, block),
         DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOS390Device, host_features, blk),
         DEFINE_PROP_END_OF_LIST(),
     },
hw/s390-virtio-bus.h +0 -1
index 1f47e4d..414fd22 100644
@@ -42,7 +42,6 @@ typedef struct VirtIOS390Device {
     ram_addr_t feat_offs;
     uint8_t feat_len;
     VirtIODevice *vdev;
-    BlockConf block;
     VirtIOBlkConf blk;
     uint32_t host_features;
     virtio_serial_conf serial;
hw/virtio-blk.c +9 -8
index e34140e..7713fd1 100644
@@ -570,25 +570,25 @@ static const BlockDevOps virtio_block_ops = {
     .resize_cb = virtio_blk_resize,
 };
 
-VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf, VirtIOBlkConf *blk)
+VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
 {
     VirtIOBlock *s;
     int cylinders, heads, secs;
     static int virtio_blk_id;
     DriveInfo *dinfo;
 
-    if (!conf->bs) {
+    if (!blk->conf.bs) {
         error_report("virtio-blk-pci: drive property not set");
         return NULL;
     }
-    if (!bdrv_is_inserted(conf->bs)) {
+    if (!bdrv_is_inserted(blk->conf.bs)) {
         error_report("Device needs media, but drive is empty");
         return NULL;
     }
 
     if (!blk->serial) {
         /* try to fall back to value set with legacy -drive serial=... */
-        dinfo = drive_get_by_blockdev(conf->bs);
+        dinfo = drive_get_by_blockdev(blk->conf.bs);
         if (*dinfo->serial) {
             blk->serial = strdup(dinfo->serial);
         }
@@ -601,8 +601,8 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf, VirtIOBlkConf *
     s->vdev.get_config = virtio_blk_update_config;
     s->vdev.get_features = virtio_blk_get_features;
     s->vdev.reset = virtio_blk_reset;
-    s->bs = conf->bs;
-    s->conf = conf;
+    s->bs = blk->conf.bs;
+    s->conf = &blk->conf;
     s->blk = blk;
     s->rq = NULL;
     s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
@@ -615,10 +615,10 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf, VirtIOBlkConf *
     register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
                     virtio_blk_save, virtio_blk_load, s);
     bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
-    bdrv_set_buffer_alignment(s->bs, conf->logical_block_size);
+    bdrv_set_buffer_alignment(s->bs, s->conf->logical_block_size);
 
     bdrv_iostatus_enable(s->bs);
-    add_boot_device_path(conf->bootindex, dev, "/disk@0,0");
+    add_boot_device_path(s->conf->bootindex, dev, "/disk@0,0");
 
     return &s->vdev;
 }
@@ -627,5 +627,6 @@ void virtio_blk_exit(VirtIODevice *vdev)
 {
     VirtIOBlock *s = to_virtio_blk(vdev);
     unregister_savevm(s->qdev, "virtio-blk", s);
+    blockdev_mark_auto_del(s->bs);
     virtio_cleanup(vdev);
 }
hw/virtio-blk.h +2 -0
index dd26ae7..518e1cc 100644
@@ -99,6 +99,7 @@ struct virtio_scsi_inhdr
 
 struct VirtIOBlkConf
 {
+    BlockConf conf;
     char *serial;
 };
 
@@ -113,6 +114,7 @@ struct VirtIOBlkConf
 
 #define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _features_field, _conf_field) \
         DEFINE_VIRTIO_BLK_FEATURES(_state, _features_field), \
+        DEFINE_BLOCK_PROPERTIES(_state, _conf_field.conf), \
         DEFINE_PROP_STRING("serial", _state, _conf_field.serial)
 
 #endif
hw/virtio-pci.c +1 -4
index d64058e..0048dc1 100644
@@ -669,8 +669,7 @@ static int virtio_blk_init_pci(PCIDevice *pci_dev)
         proxy->class_code != PCI_CLASS_STORAGE_OTHER)
         proxy->class_code = PCI_CLASS_STORAGE_SCSI;
 
-    vdev = virtio_blk_init(&pci_dev->qdev, &proxy->block,
-                           &proxy->blk);
+    vdev = virtio_blk_init(&pci_dev->qdev, &proxy->blk);
     if (!vdev) {
         return -1;
     }
@@ -698,7 +697,6 @@ static int virtio_blk_exit_pci(PCIDevice *pci_dev)
 
     virtio_pci_stop_ioeventfd(proxy);
     virtio_blk_exit(proxy->vdev);
-    blockdev_mark_auto_del(proxy->block.bs);
     return virtio_exit_pci(pci_dev);
 }
 
@@ -807,7 +805,6 @@ static PCIDeviceInfo virtio_info[] = {
         .class_id  = PCI_CLASS_STORAGE_SCSI,
         .qdev.props = (Property[]) {
             DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
-            DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, block),
             DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
                             VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
             DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
hw/virtio-pci.h +0 -1
index 195e852..63d83ae 100644
@@ -33,7 +33,6 @@ typedef struct {
     uint32_t flags;
     uint32_t class_code;
     uint32_t nvectors;
-    BlockConf block;
     VirtIOBlkConf blk;
     uint32_t host_features;
 #ifdef CONFIG_LINUX
hw/virtio.h +1 -2
index da2941e..94963fe 100644
@@ -192,8 +192,7 @@ void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
 
 /* Base devices.  */
 typedef struct VirtIOBlkConf VirtIOBlkConf;
-VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
-                              VirtIOBlkConf *blk);
+VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk);
 struct virtio_net_conf;
 VirtIODevice *virtio_net_init(DeviceState *dev, struct virtio_net_conf *net);
 typedef struct virtio_serial_conf virtio_serial_conf;
Signature · 1 line
1.7.7.1
#14 lore raw

PATCH 9/9 virtio: move conf fields into an anonymous union

In reply to Paolo Bonzini

The devices should not need to share any space from the conf fields

---
 hw/s390-virtio-bus.h |    8 +++++---
 hw/syborg_virtio.c   |    4 +++-
 hw/virtio-pci.h      |   10 ++++++----
 3 files changed, 14 insertions(+), 8 deletions(-)
hw/s390-virtio-bus.h +5 -3
index 414fd22..b9f711d 100644
@@ -42,10 +42,12 @@ typedef struct VirtIOS390Device {
     ram_addr_t feat_offs;
     uint8_t feat_len;
     VirtIODevice *vdev;
-    VirtIOBlkConf blk;
     uint32_t host_features;
-    virtio_serial_conf serial;
-    virtio_net_conf net;
+    union {
+        VirtIOBlkConf blk;
+        virtio_serial_conf serial;
+        virtio_net_conf net;
+    };
 } VirtIOS390Device;
 
 typedef struct VirtIOS390Bus {
hw/syborg_virtio.c +3 -1
index a1dc5ff..0971a85 100644
@@ -66,7 +66,9 @@ typedef struct {
     uint32_t int_enable;
     uint32_t id;
     uint32_t host_features;
-    virtio_net_conf net;
+    union {
+        virtio_net_conf net;
+    };
 } SyborgVirtIOProxy;
 
 static uint32_t syborg_virtio_readl(void *opaque, target_phys_addr_t offset)
hw/virtio-pci.h +6 -4
index 63d83ae..e05af31 100644
@@ -33,13 +33,15 @@ typedef struct {
     uint32_t flags;
     uint32_t class_code;
     uint32_t nvectors;
-    VirtIOBlkConf blk;
     uint32_t host_features;
+    union {
+        VirtIOBlkConf blk;
 #ifdef CONFIG_LINUX
-    V9fsConf fsconf;
+        V9fsConf fsconf;
 #endif
-    virtio_serial_conf serial;
-    virtio_net_conf net;
+        virtio_serial_conf serial;
+        virtio_net_conf net;
+    };
     bool ioeventfd_disabled;
     bool ioeventfd_started;
 } VirtIOPCIProxy;
Signature · 1 line
1.7.7.1
#15 lore raw
In reply to Paolo Bonzini
Quoted 11 lines · Paolo Bonzini

This series cleans up device configuration in virtio:

1) all properties (features and not) are moved to a single macro DEFINE_VIRTIO_XYZ_PROPERTIES. This makes the definitions uniform across all three virtio backends.

2) all configuration is moved to a single struct, which embeds the NICConf/BlockConf for respectively virtio-nic/virtio-blk. This lets the DEFINE_VIRTIO_XYZ_PROPERTIES include these pieces as well.

Quoted 5 lines

3) virtio-9p had some knowledge of PCI, but there should be no reason why s390 or mmio backends cannot use it. These bits are removed and moved back to virtio-pci.[ch].

Tested x86_64, compiled arm+s390x.

Looks good except the 9p part, commented on that.

Quoted 30 lines

Paolo Bonzini (9):
virtio-net: move property declarations to header file
virtio-net: move NICConf into virtio_net_conf
virtio-serial: move property declarations to header file
virtio-9p: remove PCI dependencies from hw/9pfs/
virtio-9p: move property declarations to header file
virtio-blk: define VirtIOBlkConf
virtio-blk: move property declarations to header file
virtio-blk: move BlockConf into VirtIOBlkConf
virtio: move conf fields into an anonymous union

 hw/9pfs/virtio-9p-device.c           |   35 +---------------------
 hw/{9p.h => 9pfs/virtio-9p-device.h} |    9 ++++-
 hw/9pfs/virtio-9p.c                  |    1 -
 hw/s390-virtio-bus.c                 |   18 +++--------
 hw/s390-virtio-bus.h                 |   11 ++++---
 hw/syborg_virtio.c                   |   15 +++------
 hw/virtio-blk.c                      |   28 ++++++++--------
 hw/virtio-blk.h                      |   12 +++++++
 hw/virtio-net.c                      |   13 ++++----
 hw/virtio-net.h                      |   43 +++++++++++++++------------
 hw/virtio-pci.c                      |   55 +++++++++++++++++++++++----------
 hw/virtio-pci.h                      |   14 +++++----
 hw/virtio-serial.h                   |    5 +++
 hw/virtio.h                          |    9 ++---
 14 files changed, 135 insertions(+), 133 deletions(-)
 rename hw/{9p.h => 9pfs/virtio-9p-device.h} (50%)
Signature · 1 line
1.7.7.1