From fefc9cbca3288c4ca491968f9b7b5bf462059171 Mon Sep 17 00:00:00 2001 Message-Id: From: Fam Zheng Date: Tue, 2 Jul 2013 08:54:51 +0200 Subject: [PATCH 1/4] vmdk: remove wrong calculation of relative path RH-Author: Fam Zheng Message-id: <1372755291-23400-1-git-send-email-famz@redhat.com> Patchwork-id: 52289 O-Subject: [PATCH RHEL-6.5 qemu-kvm v2] vmdk: remove wrong calculation of relative path Bugzilla: 977767 RH-Acked-by: Kevin Wolf RH-Acked-by: Stefan Hajnoczi RH-Acked-by: Jeffrey Cody Bugzilla: 977774 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. Cc: qemu-stable@nongnu.org Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf (cherry picked from commit 8ed610a1c983dd2ed1eed8841036af55751d115f) Signed-off-by: Fam Zheng --- block/vmdk.c | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) Signed-off-by: Michal Novotny --- block/vmdk.c | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 308b82c..fa1fb0a 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1454,45 +1454,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; @@ -1592,7 +1553,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, 0, NULL); if (ret != 0) { @@ -1605,10 +1565,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 */ -- 1.7.11.7