From patchwork Mon Dec 17 16:24:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 206909 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 1B9592C0093 for ; Tue, 18 Dec 2012 03:25:39 +1100 (EST) Received: from localhost ([::1]:44916 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkdVZ-0008SN-1C for incoming@patchwork.ozlabs.org; Mon, 17 Dec 2012 11:25:37 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52621) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkdV8-0008Eg-Gh for qemu-devel@nongnu.org; Mon, 17 Dec 2012 11:25:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TkdV3-00088g-Ja for qemu-devel@nongnu.org; Mon, 17 Dec 2012 11:25:10 -0500 Received: from mail-ia0-f173.google.com ([209.85.210.173]:47348) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkdV3-00087U-Bl for qemu-devel@nongnu.org; Mon, 17 Dec 2012 11:25:05 -0500 Received: by mail-ia0-f173.google.com with SMTP id w21so5709484iac.4 for ; Mon, 17 Dec 2012 08:25:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=0VAIHJYfou5eFV672h+uNSq9D2mV74//ns45whW8bxw=; b=mj+G3eSQU72/nU7JerMd9PKz9SciFK89iplUyvM6zUNcqUa5WbcA64C5RER3ODQ4Ob sN8Hv1XW1smg9M27FoHbKyTlvWcwEhnSJe/YuNKOALcEgwXmWHsrM9D7m4J4iCm4jJrv mDW1RDqjDSaURJ8jqBTXfufApwTNJg/k/3sa/pk0FYlnRMebP7URnj29VCPsH4DlynJH 64nAoW3SxBSc350xvMn+yCgNIqeWLl/zxktIguL+PCI60a33yts+7cQ//Hyk8N5PC+mx bxIB0O5nWzwLcpu6cUboWZAsIFqvwnveVcPYRNLQgxRt4ABjhTtGlhbhxtnGaMVFHfdb 9uUg== Received: by 10.50.216.133 with SMTP id oq5mr9653158igc.64.1355761504462; Mon, 17 Dec 2012 08:25:04 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-219-150.ip51.fastwebnet.it. [93.34.219.150]) by mx.google.com with ESMTPS id bh3sm5950327igc.0.2012.12.17.08.25.01 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 17 Dec 2012 08:25:03 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 17 Dec 2012 17:24:36 +0100 Message-Id: <1355761490-10073-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.0.2 In-Reply-To: <1355761490-10073-1-git-send-email-pbonzini@redhat.com> References: <1355761490-10073-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.210.173 Cc: aliguori@us.ibm.com, mst@redhat.com Subject: [Qemu-devel] [PATCH 01/15] qdev: do not reset a device until the parent has been initialized 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 a device creates a bus and more devices as part of its init callback, the child device could be reset while the parent is still only partly initialized. In this case, the right thing to do is to delay resetting the child. Do not do it at all in qdev_init, instead use qdev_reset_all to reset already-created devices when the state goes from CREATED to INITIALIZED. This happens when hotplugging a usb-storage device. Without this patch, initialization of a hotplugged usb-storage device would run in pre-order. Initialization of a coldplugged usb-storage device would run according to qdev_reset_all semantics (pre-order right now, post-order later in the series). This patch makes things consistent. Signed-off-by: Paolo Bonzini --- hw/qdev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index 599382c..2fdf4ac 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -176,8 +176,9 @@ int qdev_init(DeviceState *dev) dev->alias_required_for_version); } dev->state = DEV_STATE_INITIALIZED; - if (dev->hotplugged) { - device_reset(dev); + if (dev->hotplugged && + dev->parent_bus->parent->state == DEV_STATE_INITIALIZED) { + qdev_reset_all(dev); } return 0; }