[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 37/40] monitor: Tidy up find_device_state()
From: |
Paolo Bonzini |
Subject: |
[PULL 37/40] monitor: Tidy up find_device_state() |
Date: |
Wed, 13 Oct 2021 11:07:25 +0200 |
From: Markus Armbruster <armbru@redhat.com>
Commit 6287d827d4 "monitor: allow device_del to accept QOM paths"
extended find_device_state() to accept QOM paths in addition to qdev
IDs. This added a checked conversion to TYPE_DEVICE at the end, which
duplicates the check done for the qdev ID case earlier, except it sets
a *different* error: GenericError "ID is not a hotpluggable device"
when passed a QOM path, and DeviceNotFound "Device 'ID' not found"
when passed a qdev ID. Fortunately, the latter won't happen as long
as we add only devices to /machine/peripheral/.
Earlier, commit b6cc36abb2 "qdev: device_del: Search for to be
unplugged device in 'peripheral' container" rewrote the lookup by qdev
ID to use QOM instead of qdev_find_recursive(), so it can handle
buss-less devices. It does so by constructing an absolute QOM path.
Works, but object_resolve_path_component() is easier. Switching to it
also gets rid of the unclean duplication described above.
While there, avoid converting to TYPE_DEVICE twice, first to check
whether it's possible, and then for real.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20210916111707.84999-1-armbru@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
softmmu/qdev-monitor.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index 0705f00846..3df99ce9fc 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -836,16 +836,12 @@ void qmp_device_add(QDict *qdict, QObject **ret_data,
Error **errp)
static DeviceState *find_device_state(const char *id, Error **errp)
{
Object *obj;
+ DeviceState *dev;
if (id[0] == '/') {
obj = object_resolve_path(id, NULL);
} else {
- char *root_path = object_get_canonical_path(qdev_get_peripheral());
- char *path = g_strdup_printf("%s/%s", root_path, id);
-
- g_free(root_path);
- obj = object_resolve_path_type(path, TYPE_DEVICE, NULL);
- g_free(path);
+ obj = object_resolve_path_component(qdev_get_peripheral(), id);
}
if (!obj) {
@@ -854,12 +850,13 @@ static DeviceState *find_device_state(const char *id,
Error **errp)
return NULL;
}
- if (!object_dynamic_cast(obj, TYPE_DEVICE)) {
+ dev = (DeviceState *)object_dynamic_cast(obj, TYPE_DEVICE);
+ if (!dev) {
error_setg(errp, "%s is not a hotpluggable device", id);
return NULL;
}
- return DEVICE(obj);
+ return dev;
}
void qdev_unplug(DeviceState *dev, Error **errp)
--
2.31.1
- [PULL 13/40] target/i386/sev_i386.h: Remove unused headers, (continued)
- [PULL 13/40] target/i386/sev_i386.h: Remove unused headers, Paolo Bonzini, 2021/10/13
- [PULL 18/40] target/i386/sev: Restrict SEV to system emulation, Paolo Bonzini, 2021/10/13
- [PULL 16/40] target/i386/sev: sev_get_attestation_report use g_autofree, Paolo Bonzini, 2021/10/13
- [PULL 24/40] target/i386/sev: Move qmp_query_sev_capabilities() to sev.c, Paolo Bonzini, 2021/10/13
- [PULL 27/40] monitor: Reduce hmp_info_sev() declaration, Paolo Bonzini, 2021/10/13
- [PULL 23/40] target/i386/sev: Move qmp_sev_inject_launch_secret() to sev.c, Paolo Bonzini, 2021/10/13
- [PULL 39/40] target/i386/sev: Use local variable for kvm_sev_launch_measure, Paolo Bonzini, 2021/10/13
- [PULL 34/40] hw/i386/sgx: Move qmp_query_sgx_capabilities() to hw/i386/sgx.c, Paolo Bonzini, 2021/10/13
- [PULL 35/40] hw/i386/sgx: Move qmp_query_sgx() and hmp_info_sgx() to hw/i386/sgx.c, Paolo Bonzini, 2021/10/13
- [PULL 31/40] hvf: Determine slot count from struct layout, Paolo Bonzini, 2021/10/13
- [PULL 37/40] monitor: Tidy up find_device_state(),
Paolo Bonzini <=
- Re: [PULL 37/40] monitor: Tidy up find_device_state(), Markus Armbruster, 2021/10/18
- Re: [PULL 37/40] monitor: Tidy up find_device_state(), Markus Armbruster, 2021/10/19
[PULL 32/40] MAINTAINERS: Cover SGX documentation file with X86/KVM section, Paolo Bonzini, 2021/10/13
[PULL 36/40] Revert "hw/misc: applesmc: use host osk as default on macs", Paolo Bonzini, 2021/10/13
[PULL 38/40] target/i386/sev: Use local variable for kvm_sev_launch_start, Paolo Bonzini, 2021/10/13
[PULL 33/40] hw/i386/sgx: Have sgx_epc_get_section() return a boolean, Paolo Bonzini, 2021/10/13