All of lore.kernel.org
 help / color / mirror / Atom feed
From: "wangyanan (Y)" <wangyanan55@huawei.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>, qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>
Subject: Re: [PATCH 3/4] hw/core: Extract hotplug-related functions to qdev-hotplug.c
Date: Sun, 31 Oct 2021 19:24:41 +0800	[thread overview]
Message-ID: <5617d6fb-e83b-9ad8-7e70-157a39df44c3@huawei.com> (raw)
In-Reply-To: <20211028150521.1973821-4-philmd@redhat.com>

Hi Philippe,

On 2021/10/28 23:05, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>   hw/core/qdev-hotplug.c | 73 ++++++++++++++++++++++++++++++++++++++++++
>   hw/core/qdev.c         | 60 ----------------------------------
>   hw/core/meson.build    |  1 +
>   3 files changed, 74 insertions(+), 60 deletions(-)
>   create mode 100644 hw/core/qdev-hotplug.c
>
> diff --git a/hw/core/qdev-hotplug.c b/hw/core/qdev-hotplug.c
> new file mode 100644
> index 00000000000..d495d0e9c70
> --- /dev/null
> +++ b/hw/core/qdev-hotplug.c
> @@ -0,0 +1,73 @@
> +/*
> + * QDev Hotplug handlers
> + *
> + * Copyright (c) Red Hat
I find that this is a bit different from what we have in the
existing files after a git grep in QEMU, maybe better as:

Copyright (c) 2021 Red Hat, Inc.
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "hw/qdev-core.h"
> +#include "hw/boards.h"
> +
> +HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev)
> +{
> +    MachineState *machine;
> +    MachineClass *mc;
> +    Object *m_obj = qdev_get_machine();
> +
> +    if (object_dynamic_cast(m_obj, TYPE_MACHINE)) {
> +        machine = MACHINE(m_obj);
> +        mc = MACHINE_GET_CLASS(machine);
> +        if (mc->get_hotplug_handler) {
> +            return mc->get_hotplug_handler(machine, dev);
> +        }
> +    }
> +
> +    return NULL;
> +}
> +
> +bool qdev_hotplug_allowed(DeviceState *dev, Error **errp)
> +{
> +    MachineState *machine;
> +    MachineClass *mc;
> +    Object *m_obj = qdev_get_machine();
> +
> +    if (object_dynamic_cast(m_obj, TYPE_MACHINE)) {
> +        machine = MACHINE(m_obj);
> +        mc = MACHINE_GET_CLASS(machine);
> +        if (mc->hotplug_allowed) {
> +            return mc->hotplug_allowed(machine, dev, errp);
> +        }
> +    }
> +
> +    return true;
> +}
> +
> +HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev)
> +{
> +    if (dev->parent_bus) {
> +        return dev->parent_bus->hotplug_handler;
> +    }
> +    return NULL;
> +}
> +
> +HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev)
> +{
> +    HotplugHandler *hotplug_ctrl = qdev_get_machine_hotplug_handler(dev);
> +
> +    if (hotplug_ctrl == NULL && dev->parent_bus) {
> +        hotplug_ctrl = qdev_get_bus_hotplug_handler(dev);
> +    }
> +    return hotplug_ctrl;
> +}
> +
> +/* can be used as ->unplug() callback for the simple cases */
> +void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,
> +                                  DeviceState *dev, Error **errp)
> +{
> +    qdev_unrealize(dev);
> +}
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index 7f06403752d..cede76fce47 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -33,7 +33,6 @@
>   #include "qapi/visitor.h"
>   #include "qemu/error-report.h"
>   #include "qemu/option.h"
> -#include "hw/hotplug.h"
>   #include "hw/irq.h"
>   #include "hw/qdev-properties.h"
>   #include "hw/boards.h"
> @@ -238,58 +237,6 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
>       dev->alias_required_for_version = required_for_version;
>   }
>   
> -HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev)
> -{
> -    MachineState *machine;
> -    MachineClass *mc;
> -    Object *m_obj = qdev_get_machine();
> -
> -    if (object_dynamic_cast(m_obj, TYPE_MACHINE)) {
> -        machine = MACHINE(m_obj);
> -        mc = MACHINE_GET_CLASS(machine);
> -        if (mc->get_hotplug_handler) {
> -            return mc->get_hotplug_handler(machine, dev);
> -        }
> -    }
> -
> -    return NULL;
> -}
> -
> -bool qdev_hotplug_allowed(DeviceState *dev, Error **errp)
> -{
> -    MachineState *machine;
> -    MachineClass *mc;
> -    Object *m_obj = qdev_get_machine();
> -
> -    if (object_dynamic_cast(m_obj, TYPE_MACHINE)) {
> -        machine = MACHINE(m_obj);
> -        mc = MACHINE_GET_CLASS(machine);
> -        if (mc->hotplug_allowed) {
> -            return mc->hotplug_allowed(machine, dev, errp);
> -        }
> -    }
> -
> -    return true;
> -}
> -
> -HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev)
> -{
> -    if (dev->parent_bus) {
> -        return dev->parent_bus->hotplug_handler;
> -    }
> -    return NULL;
> -}
> -
> -HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev)
> -{
> -    HotplugHandler *hotplug_ctrl = qdev_get_machine_hotplug_handler(dev);
> -
> -    if (hotplug_ctrl == NULL && dev->parent_bus) {
> -        hotplug_ctrl = qdev_get_bus_hotplug_handler(dev);
> -    }
> -    return hotplug_ctrl;
> -}
> -
>   static int qdev_prereset(DeviceState *dev, void *opaque)
>   {
>       trace_qdev_reset_tree(dev, object_get_typename(OBJECT(dev)));
> @@ -371,13 +318,6 @@ static void device_reset_child_foreach(Object *obj, ResettableChildCallback cb,
>       }
>   }
>   
> -/* can be used as ->unplug() callback for the simple cases */
> -void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,
> -                                  DeviceState *dev, Error **errp)
> -{
> -    qdev_unrealize(dev);
> -}
> -
>   bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp)
>   {
>       assert(!dev->realized && !dev->parent_bus);
> diff --git a/hw/core/meson.build b/hw/core/meson.build
> index 4d04069f85f..85f2ad1374b 100644
> --- a/hw/core/meson.build
> +++ b/hw/core/meson.build
> @@ -11,6 +11,7 @@
>     'irq.c',
>     'clock.c',
>     'qdev-clock.c',
> +  'qdev-hotplug.c',
>   ))
>   
>   common_ss.add(files('cpu-common.c'))
Besides,
Reviewed-by: Yanan Wang <wangyanan55@huawei.com>

Thanks,
Yanan
.


  reply	other threads:[~2021-10-31 11:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-28 15:05 [PATCH 0/4] hw/core: Restrict qdev-hotplug to sysemu Philippe Mathieu-Daudé
2021-10-28 15:05 ` [PATCH 1/4] hw/core: Restrict sysemu specific files Philippe Mathieu-Daudé
2021-10-29 12:30   ` wangyanan (Y)
2021-10-28 15:05 ` [PATCH 2/4] hw/core: Declare meson source set Philippe Mathieu-Daudé
2021-10-29 12:51   ` wangyanan (Y)
2021-10-28 15:05 ` [PATCH 3/4] hw/core: Extract hotplug-related functions to qdev-hotplug.c Philippe Mathieu-Daudé
2021-10-31 11:24   ` wangyanan (Y) [this message]
2021-10-28 15:05 ` [PATCH 4/4] hw/core: Restrict hotplug to system emulation Philippe Mathieu-Daudé
2021-10-31 11:56   ` wangyanan (Y)
2021-10-29 17:09 ` [PATCH 0/4] hw/core: Restrict qdev-hotplug to sysemu Eduardo Habkost
2021-11-01 18:28 ` Philippe Mathieu-Daudé

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=5617d6fb-e83b-9ad8-7e70-157a39df44c3@huawei.com \
    --to=wangyanan55@huawei.com \
    --cc=berrange@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.