From patchwork Wed Feb 16 02:30:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 83325 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B2CAAB70CE for ; Wed, 16 Feb 2011 13:32:50 +1100 (EST) Received: from localhost ([127.0.0.1]:49534 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PpXCA-0003Vz-Jc for incoming@patchwork.ozlabs.org; Tue, 15 Feb 2011 21:32:46 -0500 Received: from [140.186.70.92] (port=38680 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PpXBP-0003Vu-2M for qemu-devel@nongnu.org; Tue, 15 Feb 2011 21:31:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PpXBN-0005Dg-LM for qemu-devel@nongnu.org; Tue, 15 Feb 2011 21:31:58 -0500 Received: from [222.73.24.84] (port=55588 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PpXBN-0005DT-BK for qemu-devel@nongnu.org; Tue, 15 Feb 2011 21:31:57 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 58248170121 for ; Wed, 16 Feb 2011 10:31:55 +0800 (CST) Received: from mailserver.fnst.cn.fujitus.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id p1G2QGCx007653 for ; Wed, 16 Feb 2011 10:26:17 +0800 Received: from [10.167.225.226] ([10.167.225.226]) by mailserver.fnst.cn.fujitus.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2011021610310006-146416 ; Wed, 16 Feb 2011 10:31:00 +0800 Message-ID: <4D5B36B0.80804@cn.fujitsu.com> Date: Wed, 16 Feb 2011 10:30:08 +0800 From: Wen Congyang User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100413 Fedora/3.0.4-2.fc13 Thunderbird/3.0.4 MIME-Version: 1.0 To: qemu-devel X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-02-16 10:31:00, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-02-16 10:31:00, Serialize complete at 2011-02-16 10:31:00 X-detected-operating-system: by eggs.gnu.org: FreeBSD 6.x (1) X-Received-From: 222.73.24.84 Subject: [Qemu-devel] [PATCH] uninit drive if drive_init failed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org steps to reproduce this bug: 1. virsh attach-disk domain --source imagefile --target sdb --sourcetype file --driver qemu --subdriver qcow2 error: Failed to attach disk error: operation failed: adding scsi-disk,bus=scsi0.0,scsi-id=1,drive=drive-scsi0-0-1,id=scsi0-0-1 device failed: Property 'scsi-disk.drive' can't find value 'drive-scsi0-0-1' 2. virsh attach-disk domain --source imagefile --target sdb --sourcetype file --driver qemu --subdriver raw error: Failed to attach disk error: operation failed: adding scsi-disk,bus=scsi0.0,scsi-id=1,drive=drive-scsi0-0-1,id=scsi0-0-1 device failed: Property 'scsi-disk.drive' can't find value 'drive-scsi0-0-1' The format of disk image file is raw. If we run comand 2 only, we will attach the disk successfully. The reason of this bug is that: we do not remove dinfo from drives and dinfo->bdrv from bdrv_states if we open the disk image file failed. Signed-off-by: Wen Congyang --- blockdev.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/blockdev.c b/blockdev.c index 1333a4e..03cc000 100644 --- a/blockdev.c +++ b/blockdev.c @@ -527,7 +527,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) } else if (ro == 1) { if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY && type != IF_NONE) { error_report("readonly not supported by this bus type"); - return NULL; + goto cleanup; } } @@ -537,12 +537,19 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) if (ret < 0) { error_report("could not open disk image %s: %s", file, strerror(-ret)); - return NULL; + goto cleanup; } if (bdrv_key_required(dinfo->bdrv)) autostart = 0; return dinfo; + +cleanup: + bdrv_delete(dinfo->bdrv); + QTAILQ_REMOVE(&drives, dinfo, next); + qemu_free(dinfo->id); + qemu_free(dinfo); + return NULL; } void do_commit(Monitor *mon, const QDict *qdict)