virtio: device configuration cleanup
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
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
@@ -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
@@ -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
@@ -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
PATCH 2/9 virtio-net: move NICConf into virtio_net_conf
In reply to Paolo BonziniThis 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH 3/9 virtio-serial: move property declarations to header file
In reply to Paolo BonziniInclude 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
@@ -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
@@ -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
@@ -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
PATCH 4/9 virtio-9p: remove PCI dependencies from hw/9pfs/
In reply to Paolo BonziniAlso 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Re: [Qemu-devel] [PATCH 4/9] virtio-9p: remove PCI dependencies from hw/9pfs/
Quoted 171 lines · Paolo Bonzini
Also move the
9p.hfile to9pfs/virtio-9p-device.h, for consistency with the corresponding .c file.Signed-off-by Paolo Bonzini <[email protected]>--- 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@@ -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@@ -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@@ -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@@ -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@@ -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
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
@@ -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
@@ -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
@@ -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
Re: [Qemu-devel] [PATCH 4/9] virtio-9p: remove PCI dependencies from hw/9pfs/
In reply to Paolo BonziniQuoted 5 lines · Paolo Bonzini
Also move the
9p.hfile to9pfs/virtio-9p-device.h, for consistency with the corresponding .c file.Signed-off-by Paolo Bonzini <[email protected]>---
...
Quoted 13 lines
hw/virtio-pci.c +5
-0@@ -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
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 intvirtio_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
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 intvirtio_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
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 intvirtio_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
PATCH 5/9 virtio-9p: move property declarations to header file
In reply to Paolo BonziniNo 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
@@ -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
@@ -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
PATCH 6/9 virtio-blk: define VirtIOBlkConf
In reply to Paolo BonziniIt 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
@@ -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
@@ -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
@@ -29,7 +29,7 @@ typedef struct VirtIOBlockvoid *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
@@ -97,6 +97,11 @@ struct virtio_scsi_inhdruint32_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
@@ -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
@@ -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
@@ -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
PATCH 7/9 virtio-blk: move property declarations to header file
In reply to Paolo BonziniInclude 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
@@ -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
@@ -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
@@ -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
PATCH 8/9 virtio-blk: move BlockConf into VirtIOBlkConf
In reply to Paolo BonziniThis 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
@@ -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
@@ -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
@@ -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
@@ -99,6 +99,7 @@ struct virtio_scsi_inhdrstruct 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
@@ -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
@@ -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
@@ -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
PATCH 9/9 virtio: move conf fields into an anonymous union
In reply to Paolo BonziniThe 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
@@ -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
@@ -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
@@ -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
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_PROPERTIESinclude 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 intovirtio_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 unionhw/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