From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54152) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xecvo-0001SK-5V for qemu-devel@nongnu.org; Thu, 16 Oct 2014 00:45:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xecvj-0002NM-Hl for qemu-devel@nongnu.org; Thu, 16 Oct 2014 00:44:56 -0400 Received: from [59.151.112.132] (port=39116 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xecvj-0002MW-1i for qemu-devel@nongnu.org; Thu, 16 Oct 2014 00:44:51 -0400 From: Tang Chen Date: Thu, 16 Oct 2014 12:44:26 +0800 Message-ID: <1413434666-22732-13-git-send-email-tangchen@cn.fujitsu.com> In-Reply-To: <1413434666-22732-1-git-send-email-tangchen@cn.fujitsu.com> References: <1413434666-22732-1-git-send-email-tangchen@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v4 12/12] 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, mst@redhat.com, pbonzini@redhat.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 --- qdev-monitor.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/qdev-monitor.c b/qdev-monitor.c index 5ec6606..63dabd6 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -51,6 +51,13 @@ static const QDevAlias qdev_alias_table[] = { { } }; +/* Used as the type of parameter opaque in object_child_foreach(). */ +typedef struct QPeripheralDev +{ + const char *id; + DeviceState *dev; +} QPeripheralDev; + static const char *qdev_class_get_alias(DeviceClass *dc) { const char *typename = object_class_get_name(OBJECT_CLASS(dc)); @@ -683,12 +690,51 @@ int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data) return 0; } +static int query_peripheral_device(Object *obj, void *opaque) +{ + QPeripheralDev *pdev = (QPeripheralDev *)opaque; + DeviceState *dev = (DeviceState *)obj; + + if (!strcmp(pdev->id, dev->id)) { + pdev->dev = dev; + return 1; + } + + return 0; +} + +static DeviceState *find_peripheral_device(const char *id) +{ + Object *peripheral = NULL; + QPeripheralDev pdev = { + .id = id, + .dev = NULL + }; + + peripheral = qdev_get_peripheral(); + if (!peripheral) + return NULL; + + /* + * No need to check return value of object_child_foreach() because when + * query_peripheral_device() returns, pdev->dev is the device we are + * looking for, or NULL. + */ + object_child_foreach(peripheral, query_peripheral_device, &pdev); + + return pdev.dev; +} + void qmp_device_del(const char *id, Error **errp) { DeviceState *dev; dev = qdev_find_recursive(sysbus_get_default(), id); if (!dev) { + dev = find_peripheral_device(id); + } + + if (!dev) { error_set(errp, QERR_DEVICE_NOT_FOUND, id); return; } -- 1.8.4.2