From patchwork Mon Oct 22 09:23:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pingfank@linux.vnet.ibm.com X-Patchwork-Id: 193194 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CB7B52C00FE for ; Tue, 23 Oct 2012 03:01:26 +1100 (EST) Received: from localhost ([::1]:34662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQJz8-0005tf-Fm for incoming@patchwork.ozlabs.org; Mon, 22 Oct 2012 11:32:10 -0400 Received: from eggs.gnu.org ([208.118.235.92]:54805) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQEFW-0002rn-SM for qemu-devel@nongnu.org; Mon, 22 Oct 2012 05:24:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TQEFB-0006fR-Nu for qemu-devel@nongnu.org; Mon, 22 Oct 2012 05:24:42 -0400 Received: from e28smtp09.in.ibm.com ([122.248.162.9]:53523) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQEFB-0006eX-11 for qemu-devel@nongnu.org; Mon, 22 Oct 2012 05:24:21 -0400 Received: from /spool/local by e28smtp09.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 22 Oct 2012 14:54:12 +0530 Received: from d28relay01.in.ibm.com (9.184.220.58) by e28smtp09.in.ibm.com (192.168.1.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 22 Oct 2012 14:54:10 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q9M9OAjJ37486682 for ; Mon, 22 Oct 2012 14:54:10 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q9MEs1aB027300 for ; Mon, 22 Oct 2012 14:54:02 GMT Received: from oc8440477808.cn.ibm.com (oc8440477808.cn.ibm.com [9.115.122.202]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q9MErrUd026674; Mon, 22 Oct 2012 14:53:59 GMT From: Liu Ping Fan To: qemu-devel@nongnu.org Date: Mon, 22 Oct 2012 17:23:46 +0800 Message-Id: <1350897839-29593-4-git-send-email-pingfank@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1350897839-29593-1-git-send-email-pingfank@linux.vnet.ibm.com> References: <1350897839-29593-1-git-send-email-pingfank@linux.vnet.ibm.com> x-cbid: 12102209-2674-0000-0000-0000066D8933 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 122.248.162.9 X-Mailman-Approved-At: Mon, 22 Oct 2012 11:31:25 -0400 Cc: Stefan Hajnoczi , Marcelo Tosatti , Avi Kivity , Anthony Liguori , Jan Kiszka , Paolo Bonzini Subject: [Qemu-devel] [patch v4 03/16] hotplug: introduce qdev_unplug_complete() to remove device from views 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 When device unplug has been ack by guest, we first remove it from memory to prevent incoming access from dispatcher. Then we isolate it from device composition tree Signed-off-by: Liu Ping Fan --- hw/qdev.c | 26 ++++++++++++++++++++++++++ hw/qdev.h | 3 ++- 2 files changed, 28 insertions(+), 1 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index b5a52ac..73df046 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -104,6 +104,14 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus) bus_add_child(bus, dev); } +static void qdev_unset_parent(DeviceState *dev) +{ + BusState *b = dev->parent_bus; + + object_unparent(OBJECT(dev)); + bus_remove_child(b, dev); +} + /* Create a new device. This only initializes the device state structure and allows properties to be set. qdev_init should be called to initialize the actual device emulation. */ @@ -193,6 +201,24 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, dev->alias_required_for_version = required_for_version; } +static int qdev_unmap(DeviceState *dev) +{ + DeviceClass *dc = DEVICE_GET_CLASS(dev); + if (dc->unmap) { + dc->unmap(dev); + } + return 0; +} + +void qdev_unplug_complete(DeviceState *dev, Error **errp) +{ + /* isolate from mem view */ + qdev_unmap(dev); + /* isolate from device tree */ + qdev_unset_parent(dev); + object_unref(OBJECT(dev)); +} + void qdev_unplug(DeviceState *dev, Error **errp) { DeviceClass *dc = DEVICE_GET_CLASS(dev); diff --git a/hw/qdev.h b/hw/qdev.h index d699194..aeae29e 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -47,7 +47,7 @@ typedef struct DeviceClass { /* callbacks */ void (*reset)(DeviceState *dev); - + void (*unmap)(DeviceState *dev); /* device state */ const VMStateDescription *vmsd; @@ -161,6 +161,7 @@ void qdev_init_nofail(DeviceState *dev); void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, int required_for_version); void qdev_unplug(DeviceState *dev, Error **errp); +void qdev_unplug_complete(DeviceState *dev, Error **errp); void qdev_free(DeviceState *dev); int qdev_simple_unplug_cb(DeviceState *dev); void qdev_machine_creation_done(void);