From patchwork Fri Apr 5 14:37:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 234178 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 DAAEE2C00C5 for ; Sat, 6 Apr 2013 02:40:04 +1100 (EST) Received: from localhost ([::1]:60962 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UO7sl-0000QX-9L for incoming@patchwork.ozlabs.org; Fri, 05 Apr 2013 10:44:47 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UO7sK-0000KH-Ed for qemu-devel@nongnu.org; Fri, 05 Apr 2013 10:44:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UO7sE-000680-3a for qemu-devel@nongnu.org; Fri, 05 Apr 2013 10:44:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7633) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UO7sD-00067o-R6 for qemu-devel@nongnu.org; Fri, 05 Apr 2013 10:44:14 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r35Ecu8W027456 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Apr 2013 10:38:56 -0400 Received: from thinkpad.mammed.com (vpn-238-59.phx2.redhat.com [10.3.238.59]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r35EbKxQ031798; Fri, 5 Apr 2013 10:38:52 -0400 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Fri, 5 Apr 2013 16:37:14 +0200 Message-Id: <1365172636-28628-23-git-send-email-imammedo@redhat.com> In-Reply-To: <1365172636-28628-1-git-send-email-imammedo@redhat.com> References: <1365172636-28628-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com, ehabkost@redhat.com, claudio.fontana@huawei.com, aderumier@odiso.com, lcapitulino@redhat.com, jfrei@linux.vnet.ibm.com, yang.z.zhang@intel.com, pbonzini@redhat.com, afaerber@suse.de, lig.fnst@cn.fujitsu.com, rth@twiddle.net Subject: [Qemu-devel] [PATCH 20/22] qdev: set device's parent before calling realize() down inheritance chain. 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 Currently device_set_realized() sets parent only after device was realized, But qdev_device_add() sets it before device is realized. Make behavior consistent and alter device_set_realized() to behave like qdev_device_add(). It will allow to set link<> properties in realize() method in classes inherited from DEVICE. Signed-off-by: Igor Mammedov Reviewed-by: Paolo Bonzini --- * Usage examples - conversion to CPU back-link property in APIC - pre-allocate link at board level, and populate them at realize time when CPUs are created. --- hw/qdev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index e2bb37d..b9bd6f5 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -671,10 +671,6 @@ static void device_set_realized(Object *obj, bool value, Error **err) Error *local_err = NULL; if (value && !dev->realized) { - if (dc->realize) { - dc->realize(dev, &local_err); - } - if (!obj->parent && local_err == NULL) { static int unattached_count; gchar *name = g_strdup_printf("device[%d]", unattached_count++); @@ -685,6 +681,10 @@ static void device_set_realized(Object *obj, bool value, Error **err) g_free(name); } + if (dc->realize) { + dc->realize(dev, &local_err); + } + if (qdev_get_vmsd(dev) && local_err == NULL) { vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev, dev->instance_id_alias,