From: Anthony Liguori <aliguori@us.ibm.com>
To: fred.konrad@greensocs.com, qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, e.voevodin@samsung.com,
mark.burton@greensocs.com, agraf@suse.de, stefanha@redhat.com,
cornelia.huck@de.ibm.com, afaerber@suse.de
Subject: Re: [Qemu-devel] [RFC PATCH V8 09/15] virtio-blk-pci : Switch to new API.
Date: Wed, 02 Jan 2013 08:18:29 -0600 [thread overview]
Message-ID: <87a9srd5xm.fsf@codemonkey.ws> (raw)
In-Reply-To: <1355910821-21302-10-git-send-email-fred.konrad@greensocs.com>
fred.konrad@greensocs.com writes:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Here the virtio-blk-pci is modified for the new API. The device virtio-blk-pci
> extends virtio-pci. It creates and connects a virtio-blk during the init.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
> hw/virtio-pci.c | 106 +++++++++++++++++++++-----------------------------------
> hw/virtio-pci.h | 14 +++++++-
> 2 files changed, 53 insertions(+), 67 deletions(-)
>
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index 877bf38..e3a8276 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -734,26 +734,6 @@ void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
> proxy->host_features = vdev->get_features(vdev, proxy->host_features);
> }
>
> -static int virtio_blk_init_pci(PCIDevice *pci_dev)
> -{
> - VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
> - VirtIODevice *vdev;
> -
> - if (proxy->class_code != PCI_CLASS_STORAGE_SCSI &&
> - proxy->class_code != PCI_CLASS_STORAGE_OTHER)
> - proxy->class_code = PCI_CLASS_STORAGE_SCSI;
> -
> - vdev = virtio_blk_init(&pci_dev->qdev, &proxy->blk);
> - if (!vdev) {
> - return -1;
> - }
> - vdev->nvectors = proxy->nvectors;
> - virtio_init_pci(proxy, vdev);
> - /* make the actual value visible */
> - proxy->nvectors = vdev->nvectors;
> - return 0;
> -}
> -
> static void virtio_exit_pci(PCIDevice *pci_dev)
> {
> VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
> @@ -762,15 +742,6 @@ static void virtio_exit_pci(PCIDevice *pci_dev)
> msix_uninit_exclusive_bar(pci_dev);
> }
>
> -static void virtio_blk_exit_pci(PCIDevice *pci_dev)
> -{
> - VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
> -
> - virtio_pci_stop_ioeventfd(proxy);
> - virtio_blk_exit(proxy->vdev);
> - virtio_exit_pci(pci_dev);
> -}
> -
> static int virtio_serial_init_pci(PCIDevice *pci_dev)
> {
> VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
> @@ -888,42 +859,6 @@ static void virtio_rng_exit_pci(PCIDevice *pci_dev)
> virtio_exit_pci(pci_dev);
> }
>
> -static Property virtio_blk_properties[] = {
> - DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
> - DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, blk.conf),
> - DEFINE_BLOCK_CHS_PROPERTIES(VirtIOPCIProxy, blk.conf),
> - DEFINE_PROP_STRING("serial", VirtIOPCIProxy, blk.serial),
> -#ifdef __linux__
> - DEFINE_PROP_BIT("scsi", VirtIOPCIProxy, blk.scsi, 0, true),
> -#endif
> - 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_PROP_END_OF_LIST(),
> -};
> -
> -static void virtio_blk_class_init(ObjectClass *klass, void *data)
> -{
> - DeviceClass *dc = DEVICE_CLASS(klass);
> - PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
> -
> - k->init = virtio_blk_init_pci;
> - k->exit = virtio_blk_exit_pci;
> - k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
> - k->device_id = PCI_DEVICE_ID_VIRTIO_BLOCK;
> - k->revision = VIRTIO_PCI_ABI_VERSION;
> - k->class_id = PCI_CLASS_STORAGE_SCSI;
> - dc->reset = virtio_pci_reset;
> - dc->props = virtio_blk_properties;
> -}
> -
> -static TypeInfo virtio_blk_info = {
> - .name = "virtio-blk-pci",
> - .parent = TYPE_PCI_DEVICE,
> - .instance_size = sizeof(VirtIOPCIProxy),
> - .class_init = virtio_blk_class_init,
> -};
> -
> static Property virtio_net_properties[] = {
> DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
> DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
> @@ -1248,6 +1183,45 @@ static const TypeInfo virtio_pci_info = {
> .class_size = sizeof(VirtioPCIClass),
> };
>
> +/* virtio-blk-pci */
> +
> +static Property virtio_blk_pci_properties[] = {
> + DEFINE_PROP_HEX32("class", VirtIOBlkPCI, parent_obj.class_code, 0),
> + DEFINE_PROP_BIT("ioeventfd", VirtIOBlkPCI, parent_obj.flags,
> + VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
> + DEFINE_PROP_UINT32("vectors", VirtIOBlkPCI, parent_obj.nvectors, 2),
> + DEFINE_VIRTIO_BLK_FEATURES(VirtIOBlkPCI, parent_obj.host_features),
> + DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkPCI, blk),
> + DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static int virtio_blk_pci_init(VirtIOPCIProxy *vpci_dev)
> +{
> + DeviceState *vdev;
> + VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(vpci_dev);
> + vdev = qdev_create(BUS(vpci_dev->bus), "virtio-blk");
This is the wrong way to do this.
You should do object_initialize() and object_property_add_child() in an
initialization function for this type.
You can qdev_set_parent_bus() in the initialization function, but defer
the qdev_init() until here for the child.
Regards,
Anthony Liguori
> + virtio_blk_set_conf(vdev, &(dev->blk));
> + if (qdev_init(vdev) < 0) {
> + return -1;
> + }
> + return 0;
> +}
> +
> +static void virtio_blk_pci_class_init(ObjectClass *klass, void *data)
> +{
> + DeviceClass *dc = DEVICE_CLASS(klass);
> + VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
> + dc->props = virtio_blk_pci_properties;
> + k->init = virtio_blk_pci_init;
> +}
> +
> +static const TypeInfo virtio_blk_pci_info = {
> + .name = TYPE_VIRTIO_BLK_PCI,
> + .parent = TYPE_VIRTIO_PCI,
> + .instance_size = sizeof(VirtIOBlkPCI),
> + .class_init = virtio_blk_pci_class_init,
> +};
> +
> /* virtio-pci-bus */
>
> VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
> @@ -1287,7 +1261,6 @@ static const TypeInfo virtio_pci_bus_info = {
>
> static void virtio_pci_register_types(void)
> {
> - type_register_static(&virtio_blk_info);
> type_register_static(&virtio_net_info);
> type_register_static(&virtio_serial_info);
> type_register_static(&virtio_balloon_info);
> @@ -1295,6 +1268,7 @@ static void virtio_pci_register_types(void)
> type_register_static(&virtio_rng_info);
> type_register_static(&virtio_pci_bus_info);
> type_register_static(&virtio_pci_info);
> + type_register_static(&virtio_blk_pci_info);
> }
>
> type_init(virtio_pci_register_types)
> diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
> index e840cea..8a68d6e 100644
> --- a/hw/virtio-pci.h
> +++ b/hw/virtio-pci.h
> @@ -24,6 +24,7 @@
>
> /* VirtIOPCIProxy will be renammed VirtioPCIState at the end. */
> typedef struct VirtIOPCIProxy VirtIOPCIProxy;
> +typedef struct VirtIOBlkPCI VirtIOBlkPCI;
>
> /* virtio-pci-bus */
> #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
> @@ -69,7 +70,6 @@ struct VirtIOPCIProxy {
> uint32_t flags;
> uint32_t class_code;
> uint32_t nvectors;
> - VirtIOBlkConf blk;
> NICConf nic;
> uint32_t host_features;
> #ifdef CONFIG_LINUX
> @@ -87,6 +87,18 @@ struct VirtIOPCIProxy {
> /* Nothing more for the moment. */
> };
>
> +/*
> + * virtio-blk-pci : This extends VirtioPCIProxy.
> + */
> +#define TYPE_VIRTIO_BLK_PCI "virtio-blk-pci"
> +#define VIRTIO_BLK_PCI(obj) \
> + OBJECT_CHECK(VirtIOBlkPCI, (obj), TYPE_VIRTIO_BLK_PCI)
> +
> +struct VirtIOBlkPCI {
> + VirtIOPCIProxy parent_obj;
> + VirtIOBlkConf blk;
> +};
> +
> void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
> void virtio_pci_reset(DeviceState *d);
>
> --
> 1.7.11.7
next prev parent reply other threads:[~2013-01-02 14:18 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 01/15] qdev : add a maximum device allowed field for the bus fred.konrad
2013-01-02 14:08 ` Anthony Liguori
2013-01-02 14:16 ` Andreas Färber
2013-01-02 14:30 ` KONRAD Frédéric
2013-01-03 14:03 ` KONRAD Frédéric
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 02/15] virtio-bus : Introduce virtio-bus fred.konrad
2013-01-02 14:12 ` Anthony Liguori
2013-01-03 9:57 ` KONRAD Frédéric
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 03/15] virtio-pci-bus : Introduce virtio-pci-bus fred.konrad
2013-01-02 14:12 ` Anthony Liguori
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 04/15] virtio-pci : Refactor virtio-pci device fred.konrad
2012-12-19 19:53 ` Blue Swirl
2013-01-02 14:14 ` Anthony Liguori
2013-01-02 14:17 ` KONRAD Frédéric
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 05/15] virtio-device : Refactor virtio-device fred.konrad
2013-01-02 14:15 ` Anthony Liguori
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 06/15] virtio-s390-bus : Add virtio-s390-bus fred.konrad
2012-12-19 18:09 ` Cornelia Huck
2012-12-20 8:03 ` KONRAD Frédéric
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 07/15] virtio-s390-device : create a virtio-s390-bus during init fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 08/15] virtio-blk : Add the virtio-blk device fred.konrad
2012-12-19 20:00 ` Blue Swirl
2012-12-19 23:22 ` Peter Maydell
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 09/15] virtio-blk-pci : Switch to new API fred.konrad
2013-01-02 14:18 ` Anthony Liguori [this message]
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 10/15] virtio-blk-s390 : Switch to the " fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 11/15] virtio-blk : cleanup : use QOM cast fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 12/15] virtio-blk : cleanup : remove qdev field fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 13/15] virtio : Remove the function pointer fred.konrad
2012-12-19 19:50 ` Blue Swirl
2012-12-20 8:02 ` KONRAD Frédéric
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 14/15] virtio : Remove VirtIOBindings fred.konrad
2012-12-19 19:54 ` Blue Swirl
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 15/15] virtio : cleanup : init and exit function fred.konrad
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a9srd5xm.fsf@codemonkey.ws \
--to=aliguori@us.ibm.com \
--cc=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=cornelia.huck@de.ibm.com \
--cc=e.voevodin@samsung.com \
--cc=fred.konrad@greensocs.com \
--cc=mark.burton@greensocs.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).