From: Like Xu <like.xu@linux.intel.com> To: qemu-trivial@nongnu.org Cc: Igor Mammedov <imammedo@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Markus Armbruster <armbru@redhat.com>, Eduardo Habkost <ehabkost@redhat.com>, Thomas Huth <thuth@redhat.com>, qemu-devel@nongnu.org, like.xu@intel.com Subject: [Qemu-devel] [PATCH v3 2/2] core/qdev: refactor qdev_get_machine() with type assertion Date: Mon, 15 Apr 2019 15:59:45 +0800 [thread overview] Message-ID: <1555315185-16414-3-git-send-email-like.xu@linux.intel.com> (raw) In-Reply-To: <1555315185-16414-1-git-send-email-like.xu@linux.intel.com> To avoid the misuse of qdev_get_machine() if machine hasn't been created yet, this patch uses qdev_get_machine_uncheck() for obj-common (share with user-only mode) and adds type assertion to qdev_get_machine() in system-emulation mode. Suggested-by: Igor Mammedov <imammedo@redhat.com> Signed-off-by: Like Xu <like.xu@linux.intel.com> --- hw/core/qdev.c | 16 +++++++++++++--- include/hw/qdev-core.h | 1 + qom/cpu.c | 5 +++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index f9b6efe..8232216 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -223,7 +223,7 @@ HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev) { MachineState *machine; MachineClass *mc; - Object *m_obj = qdev_get_machine(); + Object *m_obj = qdev_get_machine_uncheck(); if (object_dynamic_cast(m_obj, TYPE_MACHINE)) { machine = MACHINE(m_obj); @@ -815,7 +815,7 @@ static void device_set_realized(Object *obj, bool value, Error **errp) if (!obj->parent) { gchar *name = g_strdup_printf("device[%d]", unattached_count++); - object_property_add_child(container_get(qdev_get_machine(), + object_property_add_child(container_get(qdev_get_machine_uncheck(), "/unattached"), name, obj, &error_abort); unattached_parent = true; @@ -1095,7 +1095,7 @@ void device_reset(DeviceState *dev) } } -Object *qdev_get_machine(void) +Object *qdev_get_machine_uncheck(void) { static Object *dev; @@ -1106,6 +1106,16 @@ Object *qdev_get_machine(void) return dev; } +Object *qdev_get_machine(void) +{ + static Object *dev; + + dev = qdev_get_machine_uncheck(); + assert(object_dynamic_cast(dev, TYPE_MACHINE) != NULL); + + return dev; +} + static const TypeInfo device_type_info = { .name = TYPE_DEVICE, .parent = TYPE_OBJECT, diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 33ed3b8..e7c6a5a 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -429,6 +429,7 @@ const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev); const char *qdev_fw_name(DeviceState *dev); +Object *qdev_get_machine_uncheck(void); Object *qdev_get_machine(void); /* FIXME: make this a link<> */ diff --git a/qom/cpu.c b/qom/cpu.c index a8d2958..bb877d5 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -325,9 +325,10 @@ static void cpu_common_parse_features(const char *typename, char *features, static void cpu_common_realizefn(DeviceState *dev, Error **errp) { CPUState *cpu = CPU(dev); - Object *machine = qdev_get_machine(); + Object *machine = qdev_get_machine_uncheck(); - /* qdev_get_machine() can return something that's not TYPE_MACHINE + /* + * qdev_get_machine_uncheck() can return something that's not TYPE_MACHINE * if this is one of the user-only emulators; in that case there's * no need to check the ignore_memory_transaction_failures board flag. */ -- 1.8.3.1
WARNING: multiple messages have this Message-ID (diff)
From: Like Xu <like.xu@linux.intel.com> To: qemu-trivial@nongnu.org Cc: Peter Maydell <peter.maydell@linaro.org>, Thomas Huth <thuth@redhat.com>, Eduardo Habkost <ehabkost@redhat.com>, like.xu@intel.com, qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>, Igor Mammedov <imammedo@redhat.com> Subject: [Qemu-devel] [PATCH v3 2/2] core/qdev: refactor qdev_get_machine() with type assertion Date: Mon, 15 Apr 2019 15:59:45 +0800 [thread overview] Message-ID: <1555315185-16414-3-git-send-email-like.xu@linux.intel.com> (raw) Message-ID: <20190415075945.pTB4Q0FV1WDTgSGpBNCM-CEvJClnj7iUDVS_DzB0dFY@z> (raw) In-Reply-To: <1555315185-16414-1-git-send-email-like.xu@linux.intel.com> To avoid the misuse of qdev_get_machine() if machine hasn't been created yet, this patch uses qdev_get_machine_uncheck() for obj-common (share with user-only mode) and adds type assertion to qdev_get_machine() in system-emulation mode. Suggested-by: Igor Mammedov <imammedo@redhat.com> Signed-off-by: Like Xu <like.xu@linux.intel.com> --- hw/core/qdev.c | 16 +++++++++++++--- include/hw/qdev-core.h | 1 + qom/cpu.c | 5 +++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index f9b6efe..8232216 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -223,7 +223,7 @@ HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev) { MachineState *machine; MachineClass *mc; - Object *m_obj = qdev_get_machine(); + Object *m_obj = qdev_get_machine_uncheck(); if (object_dynamic_cast(m_obj, TYPE_MACHINE)) { machine = MACHINE(m_obj); @@ -815,7 +815,7 @@ static void device_set_realized(Object *obj, bool value, Error **errp) if (!obj->parent) { gchar *name = g_strdup_printf("device[%d]", unattached_count++); - object_property_add_child(container_get(qdev_get_machine(), + object_property_add_child(container_get(qdev_get_machine_uncheck(), "/unattached"), name, obj, &error_abort); unattached_parent = true; @@ -1095,7 +1095,7 @@ void device_reset(DeviceState *dev) } } -Object *qdev_get_machine(void) +Object *qdev_get_machine_uncheck(void) { static Object *dev; @@ -1106,6 +1106,16 @@ Object *qdev_get_machine(void) return dev; } +Object *qdev_get_machine(void) +{ + static Object *dev; + + dev = qdev_get_machine_uncheck(); + assert(object_dynamic_cast(dev, TYPE_MACHINE) != NULL); + + return dev; +} + static const TypeInfo device_type_info = { .name = TYPE_DEVICE, .parent = TYPE_OBJECT, diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 33ed3b8..e7c6a5a 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -429,6 +429,7 @@ const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev); const char *qdev_fw_name(DeviceState *dev); +Object *qdev_get_machine_uncheck(void); Object *qdev_get_machine(void); /* FIXME: make this a link<> */ diff --git a/qom/cpu.c b/qom/cpu.c index a8d2958..bb877d5 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -325,9 +325,10 @@ static void cpu_common_parse_features(const char *typename, char *features, static void cpu_common_realizefn(DeviceState *dev, Error **errp) { CPUState *cpu = CPU(dev); - Object *machine = qdev_get_machine(); + Object *machine = qdev_get_machine_uncheck(); - /* qdev_get_machine() can return something that's not TYPE_MACHINE + /* + * qdev_get_machine_uncheck() can return something that's not TYPE_MACHINE * if this is one of the user-only emulators; in that case there's * no need to check the ignore_memory_transaction_failures board flag. */ -- 1.8.3.1
next prev parent reply other threads:[~2019-04-15 8:00 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-04-15 7:59 [Qemu-devel] [PATCH v3 0/2] vl.c: make current_machine as non-global variable Like Xu 2019-04-15 7:59 ` Like Xu 2019-04-15 7:59 ` [Qemu-devel] [PATCH v3 1/2] vl.c: refactor " Like Xu 2019-04-15 7:59 ` Like Xu 2019-04-16 21:16 ` Eduardo Habkost 2019-04-16 21:16 ` Eduardo Habkost 2019-04-17 5:26 ` Markus Armbruster 2019-04-17 5:26 ` Markus Armbruster 2019-04-17 17:05 ` Eduardo Habkost 2019-04-17 17:05 ` Eduardo Habkost 2019-04-15 7:59 ` Like Xu [this message] 2019-04-15 7:59 ` [Qemu-devel] [PATCH v3 2/2] core/qdev: refactor qdev_get_machine() with type assertion Like Xu 2019-04-16 21:20 ` Eduardo Habkost 2019-04-16 21:20 ` Eduardo Habkost 2019-04-17 5:14 ` Markus Armbruster 2019-04-17 5:14 ` Markus Armbruster 2019-04-17 17:10 ` Eduardo Habkost 2019-04-17 17:10 ` Eduardo Habkost 2019-04-23 7:59 ` Like Xu 2019-04-23 7:59 ` Like Xu 2019-04-24 17:21 ` Eduardo Habkost 2019-04-24 17:21 ` Eduardo Habkost 2019-04-25 3:12 ` Like Xu 2019-04-25 3:12 ` Like Xu 2019-04-25 17:48 ` Eduardo Habkost 2019-04-25 17:48 ` Eduardo Habkost 2019-05-06 11:17 ` Markus Armbruster 2019-05-06 11:15 ` Markus Armbruster
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=1555315185-16414-3-git-send-email-like.xu@linux.intel.com \ --to=like.xu@linux.intel.com \ --cc=armbru@redhat.com \ --cc=ehabkost@redhat.com \ --cc=imammedo@redhat.com \ --cc=like.xu@intel.com \ --cc=peter.maydell@linaro.org \ --cc=qemu-devel@nongnu.org \ --cc=qemu-trivial@nongnu.org \ --cc=thuth@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: linkBe 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).