qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Damien Hedde" <damien.hedde@greensocs.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Alistair Francis" <alistair.francis@wdc.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [PULL 08/10] machine: add device_type_is_dynamic_sysbus function
Date: Mon,  1 Nov 2021 19:42:57 +0100	[thread overview]
Message-ID: <20211101184259.2859090-9-philmd@redhat.com> (raw)
In-Reply-To: <20211101184259.2859090-1-philmd@redhat.com>

From: Damien Hedde <damien.hedde@greensocs.com>

Right now the allowance check for adding a sysbus device using
-device cli option (or device_add qmp command) is done well after
the device has been created. It is done during the machine init done
notifier: machine_init_notify() in hw/core/machine.c

This new function will allow us to do the check at the right time and
issue an error if it fails.

Also make device_is_dynamic_sysbus() use the new function.

Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Message-Id: <20211029142258.484907-2-damien.hedde@greensocs.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 include/hw/boards.h | 15 +++++++++++++++
 hw/core/machine.c   | 13 ++++++++++---
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/include/hw/boards.h b/include/hw/boards.h
index e36fc7d8615..602993bd5ab 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -52,6 +52,21 @@ void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp);
  */
 void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type);
 
+/**
+ * device_type_is_dynamic_sysbus: Check if type is an allowed sysbus device
+ * type for the machine class.
+ * @mc: Machine class
+ * @type: type to check (should be a subtype of TYPE_SYS_BUS_DEVICE)
+ *
+ * Returns: true if @type is a type in the machine's list of
+ * dynamically pluggable sysbus devices; otherwise false.
+ *
+ * Check if the QOM type @type is in the list of allowed sysbus device
+ * types (see machine_class_allowed_dynamic_sysbus_dev()).
+ * Note that if @type has a parent type in the list, it is allowed too.
+ */
+bool device_type_is_dynamic_sysbus(MachineClass *mc, const char *type);
+
 /**
  * device_is_dynamic_sysbus: test whether device is a dynamic sysbus device
  * @mc: Machine class
diff --git a/hw/core/machine.c b/hw/core/machine.c
index dc15f5f9e5c..7c4004ac5a0 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -548,18 +548,25 @@ void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type)
 
 bool device_is_dynamic_sysbus(MachineClass *mc, DeviceState *dev)
 {
-    bool allowed = false;
-    strList *wl;
     Object *obj = OBJECT(dev);
 
     if (!object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE)) {
         return false;
     }
 
+    return device_type_is_dynamic_sysbus(mc, object_get_typename(obj));
+}
+
+bool device_type_is_dynamic_sysbus(MachineClass *mc, const char *type)
+{
+    bool allowed = false;
+    strList *wl;
+    ObjectClass *klass = object_class_by_name(type);
+
     for (wl = mc->allowed_dynamic_sysbus_devices;
          !allowed && wl;
          wl = wl->next) {
-        allowed |= !!object_dynamic_cast(obj, wl->value);
+        allowed |= !!object_class_dynamic_cast(klass, wl->value);
     }
 
     return allowed;
-- 
2.31.1



  parent reply	other threads:[~2021-11-01 20:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-01 18:42 [PULL 00/10] Machine-next patches for 2021-11-01 Philippe Mathieu-Daudé
2021-11-01 18:42 ` [PULL 01/10] machine: Move gpio code to hw/core/gpio.c Philippe Mathieu-Daudé
2021-11-01 18:42 ` [PULL 02/10] hw/core: Restrict sysemu specific files Philippe Mathieu-Daudé
2021-11-01 18:42 ` [PULL 03/10] hw/core: Declare meson source set Philippe Mathieu-Daudé
2021-11-01 18:42 ` [PULL 04/10] hw/core: Extract hotplug-related functions to qdev-hotplug.c Philippe Mathieu-Daudé
2021-11-01 18:42 ` [PULL 05/10] hw/core: Restrict hotplug to system emulation Philippe Mathieu-Daudé
2021-11-01 18:42 ` [PULL 06/10] hw/core/machine: Split out the smp parsing code Philippe Mathieu-Daudé
2021-11-01 18:42 ` [PULL 07/10] tests/unit: Add an unit test for smp parsing Philippe Mathieu-Daudé
2021-11-01 18:42 ` Philippe Mathieu-Daudé [this message]
2021-11-01 18:42 ` [PULL 09/10] qdev-monitor: Check sysbus device type before creating it Philippe Mathieu-Daudé
2021-11-01 18:42 ` [PULL 10/10] machine: remove the done notifier for dynamic sysbus device type check Philippe Mathieu-Daudé
2021-11-02 11:24 ` [PULL 00/10] Machine-next patches for 2021-11-01 Richard Henderson

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=20211101184259.2859090-9-philmd@redhat.com \
    --to=philmd@redhat.com \
    --cc=alistair.francis@wdc.com \
    --cc=berrange@redhat.com \
    --cc=damien.hedde@greensocs.com \
    --cc=ehabkost@redhat.com \
    --cc=pbonzini@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 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).