virtio-9p refactoring.
v3 cover virtio-9p refactoring.
From: KONRAD Frederic <[email protected]>
This is the next part of virtio-refactoring.
Basically it creates virtio-9p-device backend which extends virtio-device. Then a virtio-9p-device can be connected on a virtio-bus. virtio-9p-pci is modified, extends virtio-pci and have a virtio-9p-device.
You can checkout my branch here:
git://project.greensocs.com/qemu-virtio.git virtio-9p-v3
Note that I applied Hans's patch to fix the recent 9p compilation issue:
(virtio-9p: Fix virtio-9p no longer building after hw-dirs branch merge).
I made basic tests (with linux guests) on:
* qemu-system-i386
Changes v2 -> v3:
* Renamed device "virtio-9p" => "virtio-9p-device".
* Rebased.
Thanks,
Fred
KONRAD Frederic (4):
virtio-9p: add the virtio-9p-device device.
virtio-9p-pci: switch to the new API.
virtio-9p: cleanup: init function.
virtio-9p: cleanup: QOM casts.
hw/9pfs/virtio-9p-device.c | 91 +++++++++++++++++++++++++++++----------------- hw/9pfs/virtio-9p.c | 2 +- hw/9pfs/virtio-9p.h | 11 +++++- hw/virtio/virtio-pci.c | 59 +++++++++++++++++------------- hw/virtio/virtio-pci.h | 23 ++++++++++-- 5 files changed, 122 insertions(+), 64 deletions(-)
Signature · 1 line
1.8.1.4
PATCH v3 1/4 virtio-9p: add the virtio-9p-device device.
From: KONRAD Frederic <[email protected]>
Create virtio-9p-device which extends virtio-device, so it can be connected on virtio-bus.
--- hw/9pfs/virtio-9p-device.c | 73 +++++++++++++++++++++++++++++++++++++++++----- hw/9pfs/virtio-9p.h | 9 ++++++ hw/virtio/virtio-pci.c | 3 +- hw/virtio/virtio-pci.h | 3 ++ 4 files changed, 79 insertions(+), 9 deletions(-)
hw/9pfs/virtio-9p-device.c +66 -7
@@ -46,19 +46,30 @@ static void virtio_9p_get_config(VirtIODevice *vdev, uint8_t *config)g_free (cfg); } -VirtIODevice *virtio_9p_init (DeviceState *dev,V9fsConf *conf) +static VirtIODevice *virtio_9p_common_init (DeviceState *dev,V9fsConf *conf, +V9fsState **ps) { -V9fsState *s; +V9fsState *s = *ps;int i, len;struct stat stat;FsDriverEntry *fse;V9fsPath path; - s = (V9fsState *)virtio_common_init ("virtio-9p" , -VIRTIO_ID_9P , -sizeof (struct virtio_9p_config )+ -MAX_TAG_LEN , -sizeof (V9fsState)); +/* +* We have two cases here: the old virtio-9p-pci device, and the +* refactored virtio-9p. +*/ + +if (s ==NULL ) { + s = (V9fsState *)virtio_common_init ("virtio-9p" , +VIRTIO_ID_9P , +sizeof (struct virtio_9p_config )+ +MAX_TAG_LEN , +sizeof (V9fsState)); + }else { +virtio_init (VIRTIO_DEVICE (s),"virtio-9p" ,VIRTIO_ID_9P , +sizeof (struct virtio_9p_config ) +MAX_TAG_LEN ); + }/* initialize pdu allocator */ QLIST_INIT (&s->free_list);QLIST_INIT (&s->active_list);
@@ -136,3 +147,51 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)return &s->vdev; } + +VirtIODevice *virtio_9p_init (DeviceState *dev,V9fsConf *conf) +{ +V9fsState *s =NULL ; +return virtio_9p_common_init (dev, conf, &s); +} + +/* virtio-9p device */ + +static int virtio_9p_device_init (VirtIODevice *vdev) +{ +DeviceState *qdev =DEVICE (vdev); +V9fsState *s =VIRTIO_9P (vdev); +V9fsConf *fsconf = &(s->fsconf); +if (virtio_9p_common_init (qdev, fsconf, &s) ==NULL ) { +return -1 ; + } +return 0 ; +} + +static Property virtio_9p_properties[] = { +DEFINE_VIRTIO_9P_PROPERTIES (V9fsState, fsconf), +DEFINE_PROP_END_OF_LIST (), +}; + +static void virtio_9p_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +VirtioDeviceClass *vdc =VIRTIO_DEVICE_CLASS (klass); + dc->props = virtio_9p_properties; + vdc->init = virtio_9p_device_init; + vdc->get_features = virtio_9p_get_features; + vdc->get_config = virtio_9p_get_config; +} + +static const TypeInfo virtio_device_info = { + .name =TYPE_VIRTIO_9P , + .parent =TYPE_VIRTIO_DEVICE , + .instance_size =sizeof (V9fsState), + .class_init = virtio_9p_class_init, +}; + +static void virtio_9p_register_types (void ) +{ +type_register_static (&virtio_device_info); +} + +type_init (virtio_9p_register_types)
hw/9pfs/virtio-9p.h +9 -0
@@ -225,6 +225,7 @@ typedef struct V9fsStateCoRwlock rename_lock;int32_t root_fid;Error *migration_blocker; +V9fsConf fsconf; } V9fsState; typedef struct V9fsStatState {
@@ -401,4 +402,12 @@ extern int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath, #define pdu_unmarshal(pdu, offset, fmt, args...) \ v9fs_unmarshal(pdu->elem.out_sg, pdu->elem.out_num, offset, 1, fmt, ##args) +#define TYPE_VIRTIO_9P "virtio-9p-device" +#define VIRTIO_9P (obj) \ + OBJECT_CHECK(V9fsState, (obj), TYPE_VIRTIO_9P) + +#define DEFINE_VIRTIO_9P_PROPERTIES (_state, _field) \ + DEFINE_PROP_STRING("mount_tag", _state, _field.tag), \ + DEFINE_PROP_STRING("fsdev", _state, _field.fsdev_id) +#endif
hw/virtio/virtio-pci.c +1 -2
@@ -1098,8 +1098,7 @@ static Property virtio_9p_properties[] = {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, fsconf), DEFINE_PROP_END_OF_LIST(), };
hw/virtio/virtio-pci.h +3 -0
@@ -23,7 +23,10 @@#include "hw/virtio/virtio-scsi.h" #include "hw/virtio/virtio-balloon.h" #include "hw/virtio/virtio-bus.h" +#ifdef CONFIG_VIRTFS #include "hw/virtio/virtio-9p.h" +#include "hw/9pfs/virtio-9p.h" +#endif /* CONFIG_VIRTFS */ typedef struct VirtIOPCIProxy VirtIOPCIProxy ;typedef struct VirtIOBlkPCI VirtIOBlkPCI ;
Signature · 1 line
1.8.1.4
PATCH v3 2/4 virtio-9p-pci: switch to the new API.
In reply to [email protected]From: KONRAD Frederic <[email protected]>
Here the virtio-9p-pci is modified for the new API. The device virtio-9p-pci extends virtio-pci. It creates and connects a virtio-9p-device during the init. The properties are not changed.
--- hw/virtio/virtio-pci.c | 58 ++++++++++++++++++++++++++++---------------------- hw/virtio/virtio-pci.h | 20 ++++++++++++++--- 2 files changed, 50 insertions(+), 28 deletions(-)
hw/virtio/virtio-pci.c +33 -25
@@ -1081,46 +1081,54 @@ static const TypeInfo virtio_rng_info = { };#ifdef CONFIG_VIRTFS -static int virtio_9p_init_pci (PCIDevice *pci_dev) +static int virtio_9p_init_pci (VirtIOPCIProxy *vpci_dev) { -VirtIOPCIProxy *proxy =DO_UPCAST (VirtIOPCIProxy, pci_dev, pci_dev); -VirtIODevice *vdev; +V9fsPCIState *dev =VIRTIO_9P_PCI (vpci_dev); +DeviceState *vdev =DEVICE (&dev->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; +qdev_set_parent_bus (vdev,BUS (&vpci_dev->bus)); +if (qdev_init (vdev) <0 ) { +return -1 ; + }return 0 ; } -static Property virtio_9p_properties[] = { -DEFINE_PROP_BIT ("ioeventfd" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT , true), +static Property virtio_9p_pci_properties[] = { +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_VIRTIO_9P_PROPERTIES (VirtIOPCIProxy, fsconf), +DEFINE_VIRTIO_9P_PROPERTIES (V9fsPCIState, vdev.fsconf),DEFINE_PROP_END_OF_LIST (), }; -static void virtio_9p_class_init (ObjectClass *klass,void *data) +static void virtio_9p_pci_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); -PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); +PCIDeviceClass *pcidev_k =PCI_DEVICE_CLASS (klass); +VirtioPCIClass *k =VIRTIO_PCI_CLASS (klass); k->init = virtio_9p_init_pci; - k->vendor_id =PCI_VENDOR_ID_REDHAT_QUMRANET ; - k->device_id =PCI_DEVICE_ID_VIRTIO_9P ; - k->revision =VIRTIO_PCI_ABI_VERSION ; - k->class_id =0x2 ; - dc->props = virtio_9p_properties; - dc->reset = virtio_pci_reset; + pcidev_k->vendor_id =PCI_VENDOR_ID_REDHAT_QUMRANET ; + pcidev_k->device_id =PCI_DEVICE_ID_VIRTIO_9P ; + pcidev_k->revision =VIRTIO_PCI_ABI_VERSION ; + pcidev_k->class_id =0x2 ; + dc->props = virtio_9p_pci_properties; } -static const TypeInfo virtio_9p_info = { - .name ="virtio-9p-pci" , - .parent =TYPE_PCI_DEVICE , - .instance_size =sizeof (VirtIOPCIProxy), - .class_init = virtio_9p_class_init, +static void virtio_9p_pci_instance_init (Object *obj) +{ +V9fsPCIState *dev =VIRTIO_9P_PCI (obj); +object_initialize (OBJECT (&dev->vdev),TYPE_VIRTIO_9P ); +object_property_add_child (obj,"virtio-backend" ,OBJECT (&dev->vdev),NULL ); +} + +static const TypeInfo virtio_9p_pci_info = { + .name =TYPE_VIRTIO_9P_PCI , + .parent =TYPE_VIRTIO_PCI , + .instance_size =sizeof (V9fsPCIState), + .instance_init = virtio_9p_pci_instance_init, + .class_init = virtio_9p_pci_class_init, };#endif
@@ -1501,7 +1509,7 @@ static void virtio_pci_register_types(void)type_register_static (&virtio_pci_bus_info);type_register_static (&virtio_pci_info);#ifdef CONFIG_VIRTFS -type_register_static (&virtio_9p_info); +type_register_static (&virtio_9p_pci_info);#endif type_register_static (&virtio_blk_pci_info);type_register_static (&virtio_scsi_pci_info);
hw/virtio/virtio-pci.h +17 -3
@@ -83,9 +83,6 @@ struct VirtIOPCIProxy {uint32_t nvectors;NICConf nic;uint32_t host_features; -#ifdef CONFIG_VIRTFS -V9fsConf fsconf; -#endif virtio_net_conf net;VirtIORNGConf rng;bool ioeventfd_disabled;
@@ -145,6 +142,23 @@ struct VirtIOSerialPCI {VirtIOSerial vdev; }; +/* +* virtio-9p-pci: This extends VirtioPCIProxy. +*/ + +#ifdef CONFIG_VIRTFS + +#define TYPE_VIRTIO_9P_PCI "virtio-9p-pci" +#define VIRTIO_9P_PCI (obj) \ + OBJECT_CHECK(V9fsPCIState, (obj), TYPE_VIRTIO_9P_PCI) + +typedef struct V9fsPCIState { +VirtIOPCIProxy parent_obj; +V9fsState vdev; +}V9fsPCIState ; + +#endif /* CONFIG_VIRTFS */ +void virtio_init_pci (VirtIOPCIProxy *proxy,VirtIODevice *vdev);void virtio_pci_bus_new (VirtioBusState *bus,VirtIOPCIProxy *dev);
Signature · 1 line
1.8.1.4
PATCH v3 3/4 virtio-9p: cleanup: init function.
In reply to [email protected]From: KONRAD Frederic <[email protected]>
This remove old init function as it is no longer needed.
--- hw/9pfs/virtio-9p-device.c | 75 ++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 52 deletions(-)
hw/9pfs/virtio-9p-device.c +23 -52
@@ -46,30 +46,17 @@ static void virtio_9p_get_config(VirtIODevice *vdev, uint8_t *config)g_free (cfg); } -static VirtIODevice *virtio_9p_common_init (DeviceState *dev,V9fsConf *conf, -V9fsState **ps) +static int virtio_9p_device_init (VirtIODevice *vdev) { -V9fsState *s = *ps; +V9fsState *s =VIRTIO_9P (vdev);int i, len;struct stat stat;FsDriverEntry *fse;V9fsPath path; -/* -* We have two cases here: the old virtio-9p-pci device, and the -* refactored virtio-9p. -*/ +virtio_init (VIRTIO_DEVICE (s),"virtio-9p" ,VIRTIO_ID_9P , +sizeof (struct virtio_9p_config ) +MAX_TAG_LEN ); -if (s ==NULL ) { - s = (V9fsState *)virtio_common_init ("virtio-9p" , -VIRTIO_ID_9P , -sizeof (struct virtio_9p_config )+ -MAX_TAG_LEN , -sizeof (V9fsState)); - }else { -virtio_init (VIRTIO_DEVICE (s),"virtio-9p" ,VIRTIO_ID_9P , -sizeof (struct virtio_9p_config ) +MAX_TAG_LEN ); - }/* initialize pdu allocator */ QLIST_INIT (&s->free_list);QLIST_INIT (&s->active_list);
@@ -77,35 +64,36 @@ static VirtIODevice *virtio_9p_common_init(DeviceState *dev, V9fsConf *conf,QLIST_INSERT_HEAD (&s->free_list, &s->pdus[i], next); } - s->vq =virtio_add_queue (&s->vdev,MAX_REQ , handle_9p_output); + s->vq =virtio_add_queue (vdev,MAX_REQ , handle_9p_output); - fse =get_fsdev_fsentry (conf->fsdev_id); + fse =get_fsdev_fsentry (s->fsconf.fsdev_id);if (!fse) {/* We don't have a fsdev identified by fsdev_id */ fprintf (stderr,"Virtio-9p device couldn't find fsdev with the " -"id = %s\n" , conf->fsdev_id ? conf->fsdev_id :"NULL" ); -exit (1 ); +"id = %s\n" , + s->fsconf.fsdev_id ? s->fsconf.fsdev_id :"NULL" ); +return -1 ; } -if (!conf->tag) { +if (!s->fsconf.tag) {/* we haven't specified a mount_tag */ fprintf (stderr,"fsdev with id %s needs mount_tag arguments\n" , - conf->fsdev_id); -exit (1 ); + s->fsconf.fsdev_id); +return -1 ; } s->ctx.export_flags = fse->export_flags; s->ctx.fs_root =g_strdup (fse->path); s->ctx.exops.get_st_gen =NULL ; - len =strlen (conf->tag); + len =strlen (s->fsconf.tag);if (len >MAX_TAG_LEN -1 ) {fprintf (stderr,"mount tag '%s' (%d bytes) is longer than " -"maximum (%d bytes)" , conf->tag, len,MAX_TAG_LEN -1 ); -exit (1 ); +"maximum (%d bytes)" , s->fsconf.tag, len,MAX_TAG_LEN -1 ); +return -1 ; } - s->tag =g_strdup (conf->tag); + s->tag =strdup (s->fsconf.tag); s->ctx.uid =-1 ; s->ops = fse->ops;
@@ -117,12 +105,12 @@ static VirtIODevice *virtio_9p_common_init(DeviceState *dev, V9fsConf *conf,if (s->ops->init (&s->ctx) <0 ) {fprintf (stderr,"Virtio-9p Failed to initialize fs-driver with id:%s" -" and export path:%s\n" , conf->fsdev_id, s->ctx.fs_root); -exit (1 ); +" and export path:%s\n" , s->fsconf.fsdev_id, s->ctx.fs_root); +return -1 ; }if (v9fs_init_worker_threads () <0 ) {fprintf (stderr,"worker thread initialization failed\n" ); -exit (1 ); +return -1 ; }/*
@@ -134,39 +122,22 @@ static VirtIODevice *virtio_9p_common_init(DeviceState *dev, V9fsConf *conf,if (s->ops->name_to_path (&s->ctx,NULL ,"/" , &path) <0 ) {fprintf (stderr,"error in converting name to path %s" ,strerror (errno)); -exit (1 ); +return -1 ; }if (s->ops->lstat (&s->ctx, &path, &stat)) {fprintf (stderr,"share path %s does not exist\n" , fse->path); -exit (1 ); +return -1 ; }else if (!S_ISDIR (stat.st_mode)) {fprintf (stderr,"share path %s is not a directory\n" , fse->path); -exit (1 ); +return -1 ; }v9fs_path_free (&path); -return &s->vdev; -} - -VirtIODevice *virtio_9p_init (DeviceState *dev,V9fsConf *conf) -{ -V9fsState *s =NULL ; -return virtio_9p_common_init (dev, conf, &s); +return 0 ; }/* virtio-9p device */ -static int virtio_9p_device_init (VirtIODevice *vdev) -{ -DeviceState *qdev =DEVICE (vdev); -V9fsState *s =VIRTIO_9P (vdev); -V9fsConf *fsconf = &(s->fsconf); -if (virtio_9p_common_init (qdev, fsconf, &s) ==NULL ) { -return -1 ; - } -return 0 ; -} -static Property virtio_9p_properties[] = {DEFINE_VIRTIO_9P_PROPERTIES (V9fsState, fsconf),DEFINE_PROP_END_OF_LIST (),
Signature · 1 line
1.8.1.4
PATCH v3 4/4 virtio-9p: cleanup: QOM casts.
In reply to [email protected]From: KONRAD Frederic <[email protected]>
As the virtio-9p-pci is switched to the new API, we can use QOM casts.
--- hw/9pfs/virtio-9p-device.c | 11 +++-------- hw/9pfs/virtio-9p.c | 2 +- hw/9pfs/virtio-9p.h | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-)
hw/9pfs/virtio-9p-device.c +3 -8
@@ -26,16 +26,11 @@ static uint32_t virtio_9p_get_features(VirtIODevice *vdev, uint32_t features)return features; } -static V9fsState *to_virtio_9p (VirtIODevice *vdev) -{ -return (V9fsState *)vdev; -} -static void virtio_9p_get_config (VirtIODevice *vdev,uint8_t *config) {int len;struct virtio_9p_config *cfg; -V9fsState *s =to_virtio_9p (vdev); +V9fsState *s =VIRTIO_9P (vdev); len =strlen (s->tag); cfg =g_malloc0 (sizeof (struct virtio_9p_config ) + len);
@@ -97,9 +92,9 @@ static int virtio_9p_device_init(VirtIODevice *vdev) s->ctx.uid =-1 ; s->ops = fse->ops; - s->vdev.get_features = virtio_9p_get_features; + vdev->get_features = virtio_9p_get_features; s->config_size =sizeof (struct virtio_9p_config ) + len; - s->vdev.get_config = virtio_9p_get_config; + vdev->get_config = virtio_9p_get_config; s->fid_list =NULL ;qemu_co_rwlock_init (&s->rename_lock);
hw/9pfs/virtio-9p.c +1 -1
@@ -631,7 +631,7 @@ static void complete_pdu(V9fsState *s, V9fsPDU *pdu, ssize_t len)virtqueue_push (s->vq, &pdu->elem, len);/* FIXME: we should batch these completions */ -virtio_notify (&s->vdev, s->vq); +virtio_notify (VIRTIO_DEVICE (s), s->vq);/* Now wakeup anybody waiting in flush for this request */ qemu_co_queue_next (&pdu->complete);
hw/9pfs/virtio-9p.h +1 -1
@@ -206,7 +206,7 @@ struct V9fsFidState typedef struct V9fsState { - VirtIODevice vdev; + VirtIODevice parent_obj; VirtQueue *vq; V9fsPDU pdus[MAX_REQ]; QLIST_HEAD(, V9fsPDU) free_list;
Signature · 1 line
1.8.1.4
Anthony Liguori
AppliedApplied. Thanks.
Regards,
Anthony Liguori