From patchwork Mon Mar 2 10:08:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 445024 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 4194114009B for ; Mon, 2 Mar 2015 21:17:07 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=myhnpIzH; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: from localhost ([::1]:56011 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSNPN-0005aE-41 for incoming@patchwork.ozlabs.org; Mon, 02 Mar 2015 05:17:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33131) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSNHj-0001b2-Qc for qemu-devel@nongnu.org; Mon, 02 Mar 2015 05:09:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YSNHa-0007je-OI for qemu-devel@nongnu.org; Mon, 02 Mar 2015 05:09:11 -0500 Received: from mail-wi0-x22d.google.com ([2a00:1450:400c:c05::22d]:41107) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSNHa-0007jZ-Hj for qemu-devel@nongnu.org; Mon, 02 Mar 2015 05:09:02 -0500 Received: by widex7 with SMTP id ex7so13472284wid.0 for ; Mon, 02 Mar 2015 02:09:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=IB69G2jraVKyeyrzMBJdCbtjki5SqAGuqVJGtzqR2fE=; b=myhnpIzHW6RBJ7cvSqG/muPjTLZpeatWNcz5W9bT4XnV11HcEbP4s6XczWrfEEVisu SMD3elunRs1kNKXbXmbwOXbC1s62V8O51RRrq4mhkZzRILXgoDqzzogrECktifCVwLw0 u7+F09sYkefJ4lElKebbjpV4MfsH9xqvWnxbqJ+IQkYQgKBu2EbIiaPeyfQRZwiP9bYX R7N0kht6HWNDQ2P6r57e38fjLBr0A1bxcuGY4ldgAPd15AoiN46SH2p3UKGYN4+h7AE5 G9Gqp8aEFu8911clBhtc7D13HUdT/MHo/+yWaw+ZacxpO1NofvTM/sXH8Gxu1D1LLYeL CVQw== X-Received: by 10.180.73.171 with SMTP id m11mr33484861wiv.21.1425290941978; Mon, 02 Mar 2015 02:09:01 -0800 (PST) Received: from localhost.localdomain (net-37-116-207-136.cust.vodafonedsl.it. [37.116.207.136]) by mx.google.com with ESMTPSA id g10sm15364685wic.7.2015.03.02.02.09.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Mar 2015 02:09:01 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 2 Mar 2015 11:08:40 +0100 Message-Id: <1425290934-60872-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.3.0 In-Reply-To: <1425290934-60872-1-git-send-email-pbonzini@redhat.com> References: <1425290934-60872-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::22d Subject: [Qemu-devel] [PULL 01/15] scsi: give device a parent before setting properties 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 This mimics what is done in qdev_device_add, and lets the device be freed in case something goes wrong. Otherwise, object_unparent returns immediately without freeing the device, which is on the other hand left in the parent bus's list of children. scsi_bus_legacy_handle_cmdline then returns an error, and the HBA is destroyed as well with object_unparent. But the lingering device that was not removed in scsi_bus_legacy_add_drive cannot be removed now either, and bus_unparent gets stuck in an infinite loop trying to empty the list of children. The right fix of course would be to assert in bus_add_child that the device already has a bus, and remove the "safety net" that adds the drive to the QOM tree in device_set_realized. I am not yet sure whether that would entail changing all callers to qdev_create (as well as isa_create and usb_create and the corresponding _try_create versions). Reported-by: Markus Armbruster Tested-by: Markus Armbruster Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-bus.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index db39ae0..dca9576 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -221,11 +221,16 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockBackend *blk, const char *serial, Error **errp) { const char *driver; + char *name; DeviceState *dev; Error *err = NULL; driver = blk_is_sg(blk) ? "scsi-generic" : "scsi-disk"; dev = qdev_create(&bus->qbus, driver); + name = g_strdup_printf("legacy[%d]", unit); + object_property_add_child(OBJECT(bus), name, OBJECT(dev), NULL); + g_free(name); + qdev_prop_set_uint32(dev, "scsi-id", unit); if (bootindex >= 0) { object_property_set_int(OBJECT(dev), bootindex, "bootindex",