From patchwork Wed Jun 26 09:24:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 254651 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 0D99E2C0091 for ; Wed, 26 Jun 2013 19:25:17 +1000 (EST) Received: from localhost ([::1]:34690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UrlyV-0004wd-3N for incoming@patchwork.ozlabs.org; Wed, 26 Jun 2013 05:25:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Urly1-0004nS-3w for qemu-devel@nongnu.org; Wed, 26 Jun 2013 05:24:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Urlxy-00063L-Dw for qemu-devel@nongnu.org; Wed, 26 Jun 2013 05:24:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1583) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Urlxy-000639-5L for qemu-devel@nongnu.org; Wed, 26 Jun 2013 05:24:42 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5Q9Of4s022297 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 26 Jun 2013 05:24:41 -0400 Received: from t430s.nay.redhat.com ([10.66.7.14]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r5Q9Oc3m027388; Wed, 26 Jun 2013 05:24:39 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 26 Jun 2013 17:24:32 +0800 Message-Id: <1372238672-2614-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, Fam Zheng , stefanha@redhat.com Subject: [Qemu-devel] [PATCH] vmdk: remove wrong calculation of relative path 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 creating image with backing file, the driver tries to calculate the relative path from created image file to backing file, but the path computation is incorrect. e.g.: $ qemu-img create -f vmdk -b vmdk-data-disk.vmdk vmdk-data-snapshot1 Formatting 'vmdk-data-snapshot1', fmt=vmdk size=10737418240 backing_file='vmdk-data-disk.vmdk' compat6=off zeroed_grain=off $ qemu-img info vmdk-data-snapshot1 image: vmdk-data-snapshot1 file format: vmdk virtual size: 10G (10737418240 bytes) disk size: 12K -> backing file: disk.vmdk The common part in file names, "vmdk-data-", is incorrectly forgotten by relative_path(). As the VMDK specification has no restriction on parentNameHint to be relative path, we simply remove this by using the backing_file option. Signed-off-by: Fam Zheng --- block/vmdk.c | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 975e1d4..a28fb5e 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1487,45 +1487,6 @@ static int filename_decompose(const char *filename, char *path, char *prefix, return VMDK_OK; } -static int relative_path(char *dest, int dest_size, - const char *base, const char *target) -{ - int i = 0; - int n = 0; - const char *p, *q; -#ifdef _WIN32 - const char *sep = "\\"; -#else - const char *sep = "/"; -#endif - - if (!(dest && base && target)) { - return VMDK_ERROR; - } - if (path_is_absolute(target)) { - pstrcpy(dest, dest_size, target); - return VMDK_OK; - } - while (base[i] == target[i]) { - i++; - } - p = &base[i]; - q = &target[i]; - while (*p) { - if (*p == *sep) { - n++; - } - p++; - } - dest[0] = '\0'; - for (; n; n--) { - pstrcat(dest, dest_size, ".."); - pstrcat(dest, dest_size, sep); - } - pstrcat(dest, dest_size, q); - return VMDK_OK; -} - static int vmdk_create(const char *filename, QEMUOptionParameter *options) { int fd, idx = 0; @@ -1625,7 +1586,6 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options) return -ENOTSUP; } if (backing_file) { - char parent_filename[PATH_MAX]; BlockDriverState *bs = bdrv_new(""); ret = bdrv_open(bs, backing_file, NULL, 0, NULL); if (ret != 0) { @@ -1638,10 +1598,8 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options) } parent_cid = vmdk_read_cid(bs, 0); bdrv_delete(bs); - relative_path(parent_filename, sizeof(parent_filename), - filename, backing_file); snprintf(parent_desc_line, sizeof(parent_desc_line), - "parentFileNameHint=\"%s\"", parent_filename); + "parentFileNameHint=\"%s\"", backing_file); } /* Create extents */