From patchwork Wed Aug 27 08:08:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tang Chen X-Patchwork-Id: 383371 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4E30114009B for ; Wed, 27 Aug 2014 18:11:20 +1000 (EST) Received: from localhost ([::1]:58108 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMYK4-0006KB-Ka for incoming@patchwork.ozlabs.org; Wed, 27 Aug 2014 04:11:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMYHF-0001kv-U3 for qemu-devel@nongnu.org; Wed, 27 Aug 2014 04:08:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XMYHB-0002wI-7X for qemu-devel@nongnu.org; Wed, 27 Aug 2014 04:08:21 -0400 Received: from [59.151.112.132] (port=6472 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMYHA-0002p8-Pb for qemu-devel@nongnu.org; Wed, 27 Aug 2014 04:08:17 -0400 X-IronPort-AV: E=Sophos;i="5.04,409,1406563200"; d="scan'208";a="35133086" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Aug 2014 16:05:21 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s7R88DU4000443; Wed, 27 Aug 2014 16:08:13 +0800 Received: from tangchen.fnst.cn.fujitsu.com (10.167.226.71) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Wed, 27 Aug 2014 16:08:20 +0800 From: Tang Chen To: , , , Date: Wed, 27 Aug 2014 16:08:39 +0800 Message-ID: <1409126919-22233-9-git-send-email-tangchen@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1409126919-22233-1-git-send-email-tangchen@cn.fujitsu.com> References: <1409126919-22233-1-git-send-email-tangchen@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.71] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: hutao@cn.fujitsu.com, isimatu.yasuaki@jp.fujitsu.com, zhugh.fnst@cn.fujitsu.com, tangchen@cn.fujitsu.com Subject: [Qemu-devel] [RESEND PATCH v3 8/8] monitor: Add memory hot unplug support for device_del command. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 | 23 +++++++++++++++++++++++ qom/object.c | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) 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 fb9ee24..effd928 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,34 @@ 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 (!dev) { + dev = find_peripheral_device(id); + } + + if (!dev) { 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); }