From patchwork Thu Jun 29 09:23:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9816293 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 288C96035F for ; Thu, 29 Jun 2017 09:30:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B4A5286E4 for ; Thu, 29 Jun 2017 09:30:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D549286EB; Thu, 29 Jun 2017 09:30:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7E5D6286E4 for ; Thu, 29 Jun 2017 09:30:06 +0000 (UTC) Received: from localhost ([::1]:37957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVm1-00025f-BL for patchwork-qemu-devel@patchwork.kernel.org; Thu, 29 Jun 2017 05:30:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVff-00052t-Ip for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQVfe-00077m-GE for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:23:31 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:35129) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQVfe-00077G-86; Thu, 29 Jun 2017 05:23:30 -0400 Received: by mail-pg0-x244.google.com with SMTP id f127so11229159pgc.2; Thu, 29 Jun 2017 02:23:30 -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=lrFjJhUO6c1M80+5jJLltXKK/AiSZfH9KtRxLROeXJ0=; b=IfGRtDhi9/Ga2QVPKX11etDyndeHSNUkEuaZA0BJqVfoDAdAb0AjDRIRkPNniOJHv9 jKaKpfWD7witsrldZiJb05vLkCXlui90Fw6D6aR/Y64lX5wlSNSYcZgW7FJZnRIYeH8a TWaeXgntlR4N4QIBRgEk/Fxs30L623h1ye59tcTzMS9qSHSPibTnFlldV8uGMwRK8ALK J3PG2vyvQt+9PjDSkuxxOaFBd/MJdM4bvpNJ7q+DyA8A0e8sy12HuvbcSOuDCO/ERLsO EtE2l9exUbx1PRJCzZZ+BV+zkZdP/SU2LSWp50acPd9qTSYFqExEKLyGli3qU1jdwEvs uT2A== 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=lrFjJhUO6c1M80+5jJLltXKK/AiSZfH9KtRxLROeXJ0=; b=W6fNb4c/Viy/Qsdx5EquskES12UoHM8lt8/t0fD/lx5pp3Cq2ZJNZs+XmMXBxahZr2 +M36BybpAPHH4XcXJdkD9rgfM1RrfcAfic/OpAwyLw9oa0/QprJXb4/WUWkJkz9CRM3G yl09qRvbYWawzj4uVkL9DJqC01j7TIZUbEOBGk6lRqBYG4bog0qZYsRMw0hH9elvl4pC 2gSkeIdUKn8FjAgy8g+7Vc8f0qiTh7yttEa6MjlziqKvijWJyC+PnRVCMnQ+nvdV4h1N TVhYCkyT1D1AjcUI2JmXDmZyAYDoOUXeY/TOodqw3+CqpsiejjGlTEYX169uVusS/9VR 9+vg== X-Gm-Message-State: AKS2vOxfHvZ8tI6lMlPvEol00Yw2pY4Q3/eClmMm8ZEhyDApee1k2fOx qPODwRarjDJxi7gQmWU= X-Received: by 10.84.225.18 with SMTP id t18mr16983148plj.273.1498728209286; Thu, 29 Jun 2017 02:23:29 -0700 (PDT) Received: from linux.local ([47.247.15.37]) by smtp.gmail.com with ESMTPSA id u9sm11031203pfg.127.2017.06.29.02.23.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jun 2017 02:23:28 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Thu, 29 Jun 2017 14:53:41 +0530 Message-Id: <1498728221-23979-9-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1498728221-23979-1-git-send-email-ashijeetacharya@gmail.com> References: <1498728221-23979-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:c05::244 Subject: [Qemu-devel] [PATCH v7 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 60b8adc..d41fde9 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1493,25 +1493,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; @@ -1536,31 +1527,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; } @@ -1603,9 +1572,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); @@ -1796,13 +1763,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) { @@ -2549,9 +2517,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 %"