From patchwork Tue May 14 21:52:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 243837 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 764C22C00A8 for ; Wed, 15 May 2013 07:56:17 +1000 (EST) Received: from localhost ([::1]:54869 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcNCh-0006nX-Nk for incoming@patchwork.ozlabs.org; Tue, 14 May 2013 17:56:15 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48036) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcNC0-0006mD-Of for qemu-devel@nongnu.org; Tue, 14 May 2013 17:55:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UcNBz-0003ot-I3 for qemu-devel@nongnu.org; Tue, 14 May 2013 17:55:32 -0400 Received: from mail-ie0-x234.google.com ([2607:f8b0:4001:c03::234]:45358) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcNBz-0003om-CY; Tue, 14 May 2013 17:55:31 -0400 Received: by mail-ie0-f180.google.com with SMTP id ar20so2182581iec.39 for ; Tue, 14 May 2013 14:55:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:mime-version:content-type :content-transfer-encoding; bh=C/yKI08W9O14/gV1ylB8ay4zmjpQDFFtS/oW4t5CiJg=; b=IaufZKIVpVkWBX+3VV+P36qbXpVJkaPxhg6Or1i58baokpDsOA4uJ7VEtW/tN+4PQM bDoLnLPSqhl5u0IgFvuEX4E2hJg23oORj1bot14EdRu/Nhf5J9sK6yIfwJwKBWrJurf/ ZuZ9ebcZFXQwxthZGLnVfRNNFeIz2c+skvNGUjQh+2mqqCAI5r6QvXZDKd9Z9kyRaOx+ kmhc8JKzrZXnNGhdjO64I5zR0TBEI26R6f7YZd+wAGl3FPBIU8/pDJmZoTX8QEiItfBL nE925qHbmfcOIiHdO1+Ff20sJ5TQrvrmaLv98iNohGp67gkLZxsSG0Ng2l6HxcVf8caH TQXg== X-Received: by 10.50.118.37 with SMTP id kj5mr3548209igb.70.1368568530858; Tue, 14 May 2013 14:55:30 -0700 (PDT) Received: from localhost (cpe-72-177-121-217.austin.res.rr.com. [72.177.121.217]) by mx.google.com with ESMTPSA id b6sm203132igv.5.2013.05.14.14.55.29 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 14 May 2013 14:55:30 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 14 May 2013 16:52:59 -0500 Message-Id: <1368568392-2127-3-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1368568392-2127-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1368568392-2127-1-git-send-email-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c03::234 Cc: aliguori@us.ibm.com, qemu-stable@nongnu.org Subject: [Qemu-devel] [PATCH 02/15] qdev: Fix QOM unrealize behavior 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: Andreas Färber Since commit 249d41720b7dfbb5951b430b9eefdbee7464f515 (qdev: Prepare "realized" property) setting realized = true would register the device's VMStateDescription, but realized = false would not unregister it. Fix that. Moving the code from unparenting also revealed that we were calling DeviceClass::init through DeviceClass::realize as interim solution but DeviceClass::exit still at unparenting time with a realized check. Make this symmetrical by implementing DeviceClass::unrealize to call it, while we're setting realized = false in the unparenting path. The only other unrealize user is mac_nvram, which can safely override it. Thus, mark DeviceClass::exit as obsolete, new devices should implement DeviceClass::unrealize instead. Cc: qemu-stable@nongnu.org Signed-off-by: Andreas Färber Signed-off-by: Andreas Färber Message-id: 1366043650-9719-1-git-send-email-afaerber@suse.de Signed-off-by: Anthony Liguori (cherry picked from commit fe6c211781f80ef4fc246269cecbbc21981089f0) Signed-off-by: Michael Roth --- hw/qdev-core.h | 2 +- hw/qdev.c | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/hw/qdev-core.h b/hw/qdev-core.h index 2486f36..cc5bb2a 100644 --- a/hw/qdev-core.h +++ b/hw/qdev-core.h @@ -96,7 +96,7 @@ typedef struct DeviceClass { /* Private to qdev / bus. */ qdev_initfn init; /* TODO remove, once users are converted to realize */ qdev_event unplug; - qdev_event exit; + qdev_event exit; /* TODO remove, once users are converted to unrealize */ const char *bus_type; } DeviceClass; diff --git a/hw/qdev.c b/hw/qdev.c index 689cd54..1cbd910 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -180,6 +180,19 @@ static void device_realize(DeviceState *dev, Error **err) } } +static void device_unrealize(DeviceState *dev, Error **errp) +{ + DeviceClass *dc = DEVICE_GET_CLASS(dev); + + if (dc->exit) { + int rc = dc->exit(dev); + if (rc < 0) { + error_setg(errp, "Device exit failed."); + return; + } + } +} + void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, int required_for_version) { @@ -692,6 +705,9 @@ static void device_set_realized(Object *obj, bool value, Error **err) device_reset(dev); } } else if (!value && dev->realized) { + if (qdev_get_vmsd(dev)) { + vmstate_unregister(dev, qdev_get_vmsd(dev), dev); + } if (dc->unrealize) { dc->unrealize(dev, &local_err); } @@ -758,7 +774,6 @@ static void device_class_base_init(ObjectClass *class, void *data) static void device_unparent(Object *obj) { DeviceState *dev = DEVICE(obj); - DeviceClass *dc = DEVICE_GET_CLASS(dev); BusState *bus; while (dev->num_child_bus) { @@ -766,12 +781,7 @@ static void device_unparent(Object *obj) qbus_free(bus); } if (dev->realized) { - if (qdev_get_vmsd(dev)) { - vmstate_unregister(dev, qdev_get_vmsd(dev), dev); - } - if (dc->exit) { - dc->exit(dev); - } + object_property_set_bool(obj, false, "realized", NULL); } if (dev->parent_bus) { bus_remove_child(dev->parent_bus, dev); @@ -786,6 +796,7 @@ static void device_class_init(ObjectClass *class, void *data) class->unparent = device_unparent; dc->realize = device_realize; + dc->unrealize = device_unrealize; } void device_reset(DeviceState *dev)