From patchwork Wed Nov 6 18:50:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 288986 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1F6A02C0086 for ; Thu, 7 Nov 2013 05:51:49 +1100 (EST) Received: from localhost ([::1]:35530 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ve8Ch-0006YD-46 for incoming@patchwork.ozlabs.org; Wed, 06 Nov 2013 13:51:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ve8By-00061g-O9 for qemu-devel@nongnu.org; Wed, 06 Nov 2013 13:51:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ve8Bp-0005EI-Hy for qemu-devel@nongnu.org; Wed, 06 Nov 2013 13:51:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38125) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ve8Bp-0005EB-8E for qemu-devel@nongnu.org; Wed, 06 Nov 2013 13:50:53 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rA6IopcE008099 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 6 Nov 2013 13:50:51 -0500 Received: from localhost (ovpn-116-77.ams2.redhat.com [10.36.116.77]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rA6IonxB010328 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Wed, 6 Nov 2013 13:50:50 -0500 From: Max Reitz To: qemu-devel@nongnu.org Date: Wed, 6 Nov 2013 19:50:44 +0100 Message-Id: <1383763845-30340-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1383763845-30340-1-git-send-email-mreitz@redhat.com> References: <1383763845-30340-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Fam Zheng , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , Wenchao Xia Subject: [Qemu-devel] [PATCH v3 1/2] block/drive-mirror: Check for NULL backing_hd 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 It should be possible to execute the QMP "drive-mirror" command in "none" sync mode and "absolute-paths" mode even for block devices lacking a backing file. "absolute-paths" does in fact not require a backing file to be present, as can be seen from the "top" sync mode code path. "top" basically states that the device should indeed have a backing file - however, the current code catches the case if it doesn't and then simply treats it as "full" sync mode, creating a target image without a backing file (in "absolute-paths" mode). Thus, "absolute-paths" does not imply the target file must indeed have a backing file. Therefore, the target file may be left unbacked in case of "none" sync mode as well, if the specified device is not backed either. Currently, qemu will crash trying to dereference the backing file pointer since it assumes that it will always be non-NULL in that case ("none" with "absolute-paths"). Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- blockdev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index b260477..1c426b0 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2026,7 +2026,9 @@ void qmp_drive_mirror(const char *device, const char *target, return; } - if (sync == MIRROR_SYNC_MODE_FULL && mode != NEW_IMAGE_MODE_EXISTING) { + if ((sync == MIRROR_SYNC_MODE_FULL || !source) + && mode != NEW_IMAGE_MODE_EXISTING) + { /* create new image w/o backing file */ assert(format && drv); bdrv_img_create(target, format,