From patchwork Mon Jun 5 07:52:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 771123 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wh6hH3PDbz9s76 for ; Mon, 5 Jun 2017 18:01:03 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hnvMzFfi"; dkim-atps=neutral Received: from localhost ([::1]:60180 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHmwf-0002yN-7c for incoming@patchwork.ozlabs.org; Mon, 05 Jun 2017 04:01:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHmrJ-0006m6-Uy for qemu-devel@nongnu.org; Mon, 05 Jun 2017 03:55:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dHmrI-0003Qs-Nj for qemu-devel@nongnu.org; Mon, 05 Jun 2017 03:55:30 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:35808) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dHmrI-0003QI-Fp; Mon, 05 Jun 2017 03:55:28 -0400 Received: by mail-pf0-x244.google.com with SMTP id u26so19825336pfd.2; Mon, 05 Jun 2017 00:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=buLCrbEJPo+nPS5yIJ6nPrNl1oSB9HU8k6S2wXVDlAI=; b=hnvMzFfiLnm4+ZrPBA9CZXVm6oVWaX9Tf3O4TKt8fyGZ+XCGz8XANQYQhdw5VF+HiZ key+uuywlKGcS9KDoHdDHI464Ofu993T+NeZIA9dnmKRBBnaNcKeRQhBQIEo+sSyl4Z9 9fmS2zsvXImza6lSEsE3OhISqHQ4N4LBTBpN/lYrQVKuzv4dErvKWfmMnOPheJZ2/g0Y UryCJxt5oMk4penBr6u78oGn8l4HNIvW+ZhZGebOT05eVrMbENzW9pLQZmw765e7uv6+ CRVf3WbgfbHureB8t6/RME04iIfK/SD/k2jj8NwAQPsftWcmmdkAVmrvg6lh7McNlNJ3 Km8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=buLCrbEJPo+nPS5yIJ6nPrNl1oSB9HU8k6S2wXVDlAI=; b=gjZNYaD1cCqHm+e3WqegiKQbpQK6u3a6enjwIohVue+G/hduYyJkGUQtJ3NX/QvYwK AgBGsBEhK2xI9wx1wMPs/XUAdMU+Oqc3QYkXF95uJ8l77Chi6xJ4Q3UltPN5pnmyuYeK CFJk1e3lhUsG3VhfPU6ZQvAz5iTNwPtOfPfuzQ/IHGCoGhOfo/Iq9h67zRVmTCqWmMuK rNgZytpXf9aEuxacfVEYfN/Vb886aJ6cN2xz8AFf79jUG7dt3IyiI3+g+Y5mJzX/YG0w L6T5LImYby44VF9hWauxia1s32zS2wQ3LFM/IQGZ3Khfvq9rCClZL3q2YIxilFwKWJrw Qaxw== X-Gm-Message-State: AODbwcCxZyFF6erVbBOnPkW5WrRi80WLaiXFjcBPvIcMyizLal+JeQI4 3/6XGs0zOKn5AA== X-Received: by 10.99.121.4 with SMTP id u4mr19808919pgc.167.1496649327457; Mon, 05 Jun 2017 00:55:27 -0700 (PDT) Received: from linux.local ([47.247.14.139]) by smtp.gmail.com with ESMTPSA id j71sm11775537pge.63.2017.06.05.00.55.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Jun 2017 00:55:27 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Mon, 5 Jun 2017 13:22:52 +0530 Message-Id: <1496649172-26982-9-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1496649172-26982-1-git-send-email-ashijeetacharya@gmail.com> References: <1496649172-26982-1-git-send-email-ashijeetacharya@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::244 Subject: [Qemu-devel] [PATCH v6 8/8] vmdk: Make vmdk_get_cluster_offset() return cluster offset only X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, stefanha@gmail.com, qemu-devel@nongnu.org, mreitz@redhat.com, Ashijeet Acharya , jsnow@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" vmdk_alloc_clusters() introduced earlier now handles the task of allocating clusters and performing COW when needed. Thus we can change vmdk_get_cluster_offset() to stick to the sole purpose of returning cluster offset using sector number. Update the changes at all call sites. Signed-off-by: Ashijeet Acharya Reviewed-by: Fam Zheng --- block/vmdk.c | 56 ++++++++++++-------------------------------------------- 1 file changed, 12 insertions(+), 44 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 9fa2414..accf1c3 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1485,25 +1485,16 @@ static int vmdk_alloc_clusters(BlockDriverState *bs, * For flat extents, the start offset as parsed from the description file is * returned. * - * For sparse extents, look up in L1, L2 table. If allocate is true, return an - * offset for a new cluster and update L2 cache. If there is a backing file, - * COW is done before returning; otherwise, zeroes are written to the allocated - * cluster. Both COW and zero writing skips the sector range - * [@skip_start_sector, @skip_end_sector) passed in by caller, because caller - * has new data to write there. + * For sparse extents, look up the L1, L2 table. * * Returns: VMDK_OK if cluster exists and mapped in the image. - * VMDK_UNALLOC if cluster is not mapped and @allocate is false. - * VMDK_ERROR if failed. + * VMDK_UNALLOC if cluster is not mapped. + * VMDK_ERROR if failed */ static int vmdk_get_cluster_offset(BlockDriverState *bs, VmdkExtent *extent, - VmdkMetaData *m_data, uint64_t offset, - bool allocate, - uint64_t *cluster_offset, - uint64_t skip_start_bytes, - uint64_t skip_end_bytes) + uint64_t *cluster_offset) { int l1_index, l2_offset, l2_index; uint32_t *l2_table; @@ -1528,31 +1519,9 @@ static int vmdk_get_cluster_offset(BlockDriverState *bs, } if (!cluster_sector || zeroed) { - if (!allocate) { - return zeroed ? VMDK_ZEROED : VMDK_UNALLOC; - } - - cluster_sector = extent->next_cluster_sector; - extent->next_cluster_sector += extent->cluster_sectors; - - /* 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 - * or inappropriate VM shutdown. - */ - ret = vmdk_perform_cow(bs, extent, cluster_sector * BDRV_SECTOR_SIZE, - offset, skip_start_bytes, skip_end_bytes); - if (ret) { - return ret; - } - if (m_data) { - m_data->valid = 1; - m_data->l1_index = l1_index; - m_data->l2_index = l2_index; - m_data->l2_offset = l2_offset; - m_data->l2_cache_entry = &l2_table[l2_index]; - } + return zeroed ? VMDK_ZEROED : VMDK_UNALLOC; } + *cluster_offset = cluster_sector << BDRV_SECTOR_BITS; return VMDK_OK; } @@ -1595,9 +1564,7 @@ static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs, return 0; } qemu_co_mutex_lock(&s->lock); - ret = vmdk_get_cluster_offset(bs, extent, NULL, - sector_num * 512, false, &offset, - 0, 0); + ret = vmdk_get_cluster_offset(bs, extent, sector_num * 512, &offset); qemu_co_mutex_unlock(&s->lock); index_in_cluster = vmdk_find_index_in_cluster(extent, sector_num); @@ -1788,13 +1755,14 @@ vmdk_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, ret = -EIO; goto fail; } - ret = vmdk_get_cluster_offset(bs, extent, NULL, - offset, false, &cluster_offset, 0, 0); + offset_in_cluster = vmdk_find_offset_in_cluster(extent, offset); n_bytes = MIN(bytes, extent->cluster_sectors * BDRV_SECTOR_SIZE - offset_in_cluster); + ret = vmdk_get_cluster_offset(bs, extent, offset, &cluster_offset); + if (ret != VMDK_OK) { /* if not allocated, try to read from parent image, if exist */ if (bs->backing && ret != VMDK_ZEROED) { @@ -2541,9 +2509,9 @@ static int vmdk_check(BlockDriverState *bs, BdrvCheckResult *result, sector_num); break; } - ret = vmdk_get_cluster_offset(bs, extent, NULL, + ret = vmdk_get_cluster_offset(bs, extent, sector_num << BDRV_SECTOR_BITS, - false, &cluster_offset, 0, 0); + &cluster_offset); if (ret == VMDK_ERROR) { fprintf(stderr, "ERROR: could not get cluster_offset for sector %"