diff options
author | Kevin Wolf <kwolf@redhat.com> | 2016-09-20 13:38:41 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2016-09-23 13:36:10 +0200 |
commit | 6c1db528b0e1a68c342d49d032af1c707e9de87c (patch) | |
tree | 800f528f6b945d03cfc3eebeb1eb277ee11e168e | |
parent | 1c89e1fa2fb1414f4485a01924032ad9cdb9073d (diff) | |
download | qemu-6c1db528b0e1a68c342d49d032af1c707e9de87c.zip |
qdev-monitor: Factor out find_device_state()
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
-rw-r--r-- | qdev-monitor.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/qdev-monitor.c b/qdev-monitor.c index e19617fa8b..bc0213f5e3 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -801,7 +801,7 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp) object_unref(OBJECT(dev)); } -void qmp_device_del(const char *id, Error **errp) +static DeviceState *find_device_state(const char *id, Error **errp) { Object *obj; @@ -819,15 +819,23 @@ void qmp_device_del(const char *id, Error **errp) if (!obj) { error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, "Device '%s' not found", id); - return; + return NULL; } if (!object_dynamic_cast(obj, TYPE_DEVICE)) { error_setg(errp, "%s is not a hotpluggable device", id); - return; + return NULL; } - qdev_unplug(DEVICE(obj), errp); + return DEVICE(obj); +} + +void qmp_device_del(const char *id, Error **errp) +{ + DeviceState *dev = find_device_state(id, errp); + if (dev != NULL) { + qdev_unplug(dev, errp); + } } void qdev_machine_init(void) |