From patchwork Fri Apr 16 19:59:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 50352 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 DABB0B7C8E for ; Sat, 17 Apr 2010 06:06:28 +1000 (EST) Received: from localhost ([127.0.0.1]:41999 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O2rmY-00063R-MH for incoming@patchwork.ozlabs.org; Fri, 16 Apr 2010 16:04:54 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O2rlm-0005ye-BI for qemu-devel@nongnu.org; Fri, 16 Apr 2010 16:04:06 -0400 Received: from [140.186.70.92] (port=57552 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O2rli-0005dz-Nm for qemu-devel@nongnu.org; Fri, 16 Apr 2010 16:04:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O2rio-0003xF-Gx for qemu-devel@nongnu.org; Fri, 16 Apr 2010 16:01:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36184) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O2rio-0003xB-90 for qemu-devel@nongnu.org; Fri, 16 Apr 2010 16:01:02 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3GK0xMf006649 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 16 Apr 2010 16:01:00 -0400 Received: from localhost.localdomain (vpn2-9-31.ams2.redhat.com [10.36.9.31]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3GK0TqE003532; Fri, 16 Apr 2010 16:00:49 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 16 Apr 2010 21:59:57 +0200 Message-Id: <1271447998-24718-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1271447998-24718-1-git-send-email-kwolf@redhat.com> References: <1271447998-24718-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com, stefanha@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 2/3] vmdk: Clean up backing file handling 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 VMDK is doing interesting things when it needs to open a backing file. This patch changes that part to look more like in other drivers. The nice side effect is that the file name isn't needed any more in the open function. Signed-off-by: Kevin Wolf --- block/vmdk.c | 50 +++++++++----------------------------------------- 1 files changed, 9 insertions(+), 41 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index ae34121..781518a 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -76,7 +76,6 @@ typedef struct BDRVVmdkState { unsigned int cluster_sectors; uint32_t parent_cid; - int is_parent; } BDRVVmdkState; typedef struct VmdkMetaData { @@ -344,13 +343,11 @@ static void vmdk_parent_close(BlockDriverState *bs) bdrv_close(bs->backing_hd); } -static int parent_open = 0; -static int vmdk_parent_open(BlockDriverState *bs, const char * filename) +static int vmdk_parent_open(BlockDriverState *bs) { BDRVVmdkState *s = bs->opaque; char *p_name; char desc[DESC_SIZE]; - char parent_img_name[1024]; /* the descriptor offset = 0x200 */ if (bdrv_pread(s->hd, 0x200, desc, DESC_SIZE) != DESC_SIZE) @@ -358,7 +355,6 @@ static int vmdk_parent_open(BlockDriverState *bs, const char * filename) if ((p_name = strstr(desc,"parentFileNameHint")) != NULL) { char *end_name; - struct stat file_buf; p_name += sizeof("parentFileNameHint") + 1; if ((end_name = strchr(p_name,'\"')) == NULL) @@ -367,24 +363,6 @@ static int vmdk_parent_open(BlockDriverState *bs, const char * filename) return -1; pstrcpy(bs->backing_file, end_name - p_name + 1, p_name); - if (stat(bs->backing_file, &file_buf) != 0) { - path_combine(parent_img_name, sizeof(parent_img_name), - filename, bs->backing_file); - } else { - pstrcpy(parent_img_name, sizeof(parent_img_name), - bs->backing_file); - } - - bs->backing_hd = bdrv_new(""); - if (!bs->backing_hd) { - failure: - bdrv_close(s->hd); - return -1; - } - parent_open = 1; - if (bdrv_open(bs->backing_hd, parent_img_name, 0, NULL) < 0) - goto failure; - parent_open = 0; } return 0; @@ -396,11 +374,6 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags) uint32_t magic; int l1_size, i, ret; - if (parent_open) { - /* Parent must be opened as RO, no RDWR. */ - flags = 0; - } - ret = bdrv_file_open(&s->hd, filename, flags); if (ret < 0) return ret; @@ -436,13 +409,8 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags) s->l1_table_offset = le64_to_cpu(header.rgd_offset) << 9; s->l1_backup_table_offset = le64_to_cpu(header.gd_offset) << 9; - if (parent_open) - s->is_parent = 1; - else - s->is_parent = 0; - // try to open parent images, if exist - if (vmdk_parent_open(bs, filename) != 0) + if (vmdk_parent_open(bs) != 0) goto fail; // write the CID once after the image creation s->parent_cid = vmdk_read_cid(bs,1); @@ -583,15 +551,15 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, VmdkMetaData *m_data, if (!cluster_offset) { if (!allocate) return 0; + // Avoid the L2 tables update for the images that have snapshots. - if (!s->is_parent) { - cluster_offset = bdrv_getlength(s->hd); - bdrv_truncate(s->hd, cluster_offset + (s->cluster_sectors << 9)); + cluster_offset = bdrv_getlength(s->hd); + bdrv_truncate(s->hd, cluster_offset + (s->cluster_sectors << 9)); + + cluster_offset >>= 9; + tmp = cpu_to_le32(cluster_offset); + l2_table[l2_index] = tmp; - cluster_offset >>= 9; - tmp = cpu_to_le32(cluster_offset); - l2_table[l2_index] = tmp; - } /* First of all we write grain itself, to avoid race condition * that may to corrupt the image. * This problem may occur because of insufficient space on host disk