From patchwork Tue Dec 10 06:42:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Wang X-Patchwork-Id: 299290 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 CC8CE2C0086 for ; Tue, 10 Dec 2013 17:54:00 +1100 (EST) Received: from localhost ([::1]:47538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqHCf-0004Vs-U5 for incoming@patchwork.ozlabs.org; Tue, 10 Dec 2013 01:53:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqHCI-0004Vh-DZ for qemu-devel@nongnu.org; Tue, 10 Dec 2013 01:53:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VqHC9-000715-F9 for qemu-devel@nongnu.org; Tue, 10 Dec 2013 01:53:34 -0500 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:46745) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqHC8-00070z-PL for qemu-devel@nongnu.org; Tue, 10 Dec 2013 01:53:25 -0500 Received: from /spool/local by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 10 Dec 2013 16:43:05 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 10 Dec 2013 16:43:04 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id EB27C3578050 for ; Tue, 10 Dec 2013 17:43:03 +1100 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id rBA6gpLv6291770 for ; Tue, 10 Dec 2013 17:42:51 +1100 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id rBA6h3RP023951 for ; Tue, 10 Dec 2013 17:43:03 +1100 Received: from localhost.localdomain ([9.110.190.188]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id rBA6h1JZ023902; Tue, 10 Dec 2013 17:43:02 +1100 From: Xu Wang To: qemu-devel@nongnu.org Date: Tue, 10 Dec 2013 01:42:54 -0500 Message-Id: <1386657774-9342-1-git-send-email-gesaint@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.1.4 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13121006-9264-0000-0000-00000517385D X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.146 Cc: kwolf@redhat.com, stefanha@gmail.com, Xu Wang Subject: [Qemu-devel] [PATCH] block: Fix relative backing file path checking 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 patch is made for Bug #1257334 (diffuse handling of image creation from another path). The cause of it is user could create image even though the backing file doesn't exist. Becase backing file checking in the bdrv_img_create() is from the user's current path instead of relative path to the image to be created. This patch makes qemu check backing file according to the relative path to the image to be created. Hence if relative backing file path doesn't exist, the backing file checking will fail now. Test case: Reproduce process (from bug page): 1. $mkdir a/ 2. $qemu-img create -f qcow2 a/blob.img 10G 3. $qemu-img create -f qcow2 -b a/blob.img a/ovl.img Here the actual backing file of ovl.img is a/a/blob.img. But the backing file checking will check from the user's current path and find a/blob.img successfully. But the path saved in the ovl.img is a/a/blob.img. Bug occurred. After patched: The step 3 above an error message will be thrown because backing file checking started after got the full path of backing file intead of relative path. Signed-off-by: Xu Wang --- block.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 13f001a..20d2b66 100644 --- a/block.c +++ b/block.c @@ -4790,18 +4790,31 @@ void bdrv_img_create(const char *filename, const char *fmt, uint64_t size; char buf[32]; int back_flags; + char backing_filename_full[PATH_MAX]; + /* check if relative backing file path could be accessed */ + if (backing_file->value.s[0] == '\0' || + path_has_protocol(backing_file->value.s)) { + pstrcpy(backing_filename_full, sizeof(backing_filename_full), + backing_file->value.s); + } else { + path_combine(backing_filename_full, + sizeof(backing_filename_full), + filename, backing_file->value.s); + } /* backing files always opened read-only */ back_flags = flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING); bs = bdrv_new(""); - ret = bdrv_open(bs, backing_file->value.s, NULL, back_flags, + ret = bdrv_open(bs, backing_filename_full, NULL, back_flags, backing_drv, &local_err); if (ret < 0) { - error_setg_errno(errp, -ret, "Could not open '%s': %s", + error_setg_errno(errp, -ret, "Backing file '%s'" + "(actual path is '%s') error: %s", backing_file->value.s, + backing_filename_full, error_get_pretty(local_err)); error_free(local_err); local_err = NULL;