Received: from eggs.gnu.org ([2001:4830:134:3::10]:54768) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJL2n-0000NX-Da for qemu-devel@nongnu.org; Mon, 18 Aug 2014 07:24:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XJL2i-00024N-Gf for qemu-devel@nongnu.org; Mon, 18 Aug 2014 07:24:09 -0400 Received: from [59.151.112.132] (port=51809 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJL2i-00020d-63 for qemu-devel@nongnu.org; Mon, 18 Aug 2014 07:24:04 -0400 From: Tang Chen Date: Mon, 18 Aug 2014 19:24:28 +0800 Message-ID: <1408361068-22955-9-git-send-email-tangchen@cn.fujitsu.com> In-Reply-To: <1408361068-22955-1-git-send-email-tangchen@cn.fujitsu.com> References: <1408361068-22955-1-git-send-email-tangchen@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v3 8/8] monitor: Add memory hot unplug support for device_del command. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, imammedo@redhat.com, vasilis.liaskovitis@profitbricks.com Cc: hutao@cn.fujitsu.com, isimatu.yasuaki@jp.fujitsu.com, zhugh.fnst@cn.fujitsu.com, tangchen@cn.fujitsu.com From: Hu Tao Implement find_peripheral_device() to find bus-less device, and call it in qmp_device_del() so that device_del command will be able to remove memory device. Signed-off-by: Hu Tao Signed-off-by: Tang Chen --- include/qom/object.h | 1 + qdev-monitor.c | 26 +++++++++++++++++++++++++- qom/object.c | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index 8a05a81..a352beb 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1300,5 +1300,6 @@ int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque), */ Object *container_get(Object *root, const char *path); +bool object_property_is_child(ObjectProperty *prop); #endif diff --git a/qdev-monitor.c b/qdev-monitor.c index 5fe5e75..f57b379 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -24,6 +24,7 @@ #include "qmp-commands.h" #include "sysemu/arch_init.h" #include "qemu/config-file.h" +#include "qom/object.h" /* * Aliases were a bad idea from the start. Let's keep them @@ -683,12 +684,35 @@ int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data) return 0; } +static DeviceState *find_peripheral_device(const char *id) +{ + Object *peripheral = qdev_get_peripheral(); + DeviceState *dev = NULL; + ObjectProperty *prop; + + QTAILQ_FOREACH(prop, &peripheral->properties, node) { + if (object_property_is_child(prop)) { + dev = DEVICE(prop->opaque); + if (!strcmp(dev->id, id)) { + return dev; + } + } + } + + return NULL; +} + void qmp_device_del(const char *id, Error **errp) { DeviceState *dev; dev = qdev_find_recursive(sysbus_get_default(), id); - if (NULL == dev) { + + if (dev == NULL) { + dev = find_peripheral_device(id); + } + + if (dev == NULL) { error_set(errp, QERR_DEVICE_NOT_FOUND, id); return; } diff --git a/qom/object.c b/qom/object.c index 0e8267b..1183e5d 100644 --- a/qom/object.c +++ b/qom/object.c @@ -351,7 +351,7 @@ void object_initialize(void *data, size_t size, const char *typename) object_initialize_with_type(data, size, type); } -static inline bool object_property_is_child(ObjectProperty *prop) +bool object_property_is_child(ObjectProperty *prop) { return strstart(prop->type, "child<", NULL); } -- 1.8.4.2