From nobody Tue Feb 10 04:03:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492838337640872.568366007463; Fri, 21 Apr 2017 22:18:57 -0700 (PDT) Received: from localhost ([::1]:34232 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1nRg-0005WV-2H for importer@patchew.org; Sat, 22 Apr 2017 01:18:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1nMh-0000ST-UD for qemu-devel@nongnu.org; Sat, 22 Apr 2017 01:13:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1nMc-0000Xh-UC for qemu-devel@nongnu.org; Sat, 22 Apr 2017 01:13:47 -0400 Received: from mail-io0-x242.google.com ([2607:f8b0:4001:c06::242]:34889) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d1nMc-0000XU-P1; Sat, 22 Apr 2017 01:13:42 -0400 Received: by mail-io0-x242.google.com with SMTP id d203so36061060iof.2; Fri, 21 Apr 2017 22:13:42 -0700 (PDT) Received: from linux.local ([27.251.197.196]) by smtp.gmail.com with ESMTPSA id d82sm18780120pfl.124.2017.04.21.22.13.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 21 Apr 2017 22:13:41 -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=+71yeWSPxYplIGKA4GSGY3FguCe55S1tbJHvU344ARs=; b=MC19xNRImYETdUaNE2qXJyOM3XR89TZBqqjxwRxgNK5CXvVbko/1WAm5EXQyqmPz2e KRHzMT728TxxKhBW4vXPQjyXIYH9hEyp2U+wihC9EX9iuR82njY+ZcWtoKTJaItXyEwF 4VeDJJEXUSgRaKaoYwLJdBne/FSM6jPgBb8YOhlOIneiF9aufX/tnA2lYAkHpGlQUWKp FqdqrMAiZf1gEHeM9OPqean2JoQkHC6mswdymsliVBA/MSmRS4puvaZ5cWmCeUnHJCwA 7Mf6J9wJGVivwGIkC/VjtEGDHh1PhRP6w3XUN83MwEk9QCDWtzgw/g0lLG0sshG1CDcj +4mA== 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=+71yeWSPxYplIGKA4GSGY3FguCe55S1tbJHvU344ARs=; b=qJHyjDCG5J2LKjcnYjtwD6g3wNhodiI4CjfJ43YIUmbBOcf7HScVZwIL7OHQcmKq2K 8BsryiPkOAoEtgr84sXrakethshANbRVbSEOhoQWP2NRgsH6TreOXCdtOequSMcWAUR5 WUzJozj+Q04+NvQ1Fmp+v/jGKE33/X3Lveb/n/dfui0oZ003hJwGXppiSn50eFNRzwYx ZEXEHaxTc4rowHdcMlpNXO7FSLwZeIrdjhqAyQVrcE4yqoACxNmheuOEEPIaxV4MTxoZ ujTFhIjy0vid6cOzbeGIL9TOPyxyaU7LNDMwyUb2HvDkx0G/Q58+GXXhLGIFEeotmB4R 6sTg== X-Gm-Message-State: AN3rC/4ikedfaphXzQQik47b8dr0lEURLdVojVAbW/KCmDJbdsPkNc4A bDBww8sFL0NpeA== X-Received: by 10.98.192.129 with SMTP id g1mr15233028pfk.254.1492838022231; Fri, 21 Apr 2017 22:13:42 -0700 (PDT) From: Ashijeet Acharya To: famz@redhat.com Date: Sat, 22 Apr 2017 10:43:41 +0530 Message-Id: <1492838021-10538-9-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1492838021-10538-1-git-send-email-ashijeetacharya@gmail.com> References: <1492838021-10538-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:4001:c06::242 Subject: [Qemu-devel] [PATCH v4 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- block/vmdk.c | 56 ++++++++++++-------------------------------------------- 1 file changed, 12 insertions(+), 44 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index e52c373..be08bde 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1486,25 +1486,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, retur= n an - * offset for a new cluster and update L2 cache. If there is a backing fil= e, - * COW is done before returning; otherwise, zeroes are written to the allo= cated - * cluster. Both COW and zero writing skips the sector range - * [@skip_start_sector, @skip_end_sector) passed in by caller, because cal= ler - * 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; @@ -1529,31 +1520,9 @@ static int vmdk_get_cluster_offset(BlockDriverState = *bs, } =20 if (!cluster_sector || zeroed) { - if (!allocate) { - return zeroed ? VMDK_ZEROED : VMDK_UNALLOC; - } - - cluster_sector =3D extent->next_cluster_sector; - extent->next_cluster_sector +=3D 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 di= sk - * or inappropriate VM shutdown. - */ - ret =3D 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 =3D 1; - m_data->l1_index =3D l1_index; - m_data->l2_index =3D l2_index; - m_data->l2_offset =3D l2_offset; - m_data->l2_cache_entry =3D &l2_table[l2_index]; - } + return zeroed ? VMDK_ZEROED : VMDK_UNALLOC; } + *cluster_offset =3D cluster_sector << BDRV_SECTOR_BITS; return VMDK_OK; } @@ -1596,9 +1565,7 @@ static int64_t coroutine_fn vmdk_co_get_block_status(= BlockDriverState *bs, return 0; } qemu_co_mutex_lock(&s->lock); - ret =3D vmdk_get_cluster_offset(bs, extent, NULL, - sector_num * 512, false, &offset, - 0, 0); + ret =3D vmdk_get_cluster_offset(bs, extent, sector_num * 512, &offset); qemu_co_mutex_unlock(&s->lock); =20 index_in_cluster =3D vmdk_find_index_in_cluster(extent, sector_num); @@ -1789,13 +1756,14 @@ vmdk_co_preadv(BlockDriverState *bs, uint64_t offse= t, uint64_t bytes, ret =3D -EIO; goto fail; } - ret =3D vmdk_get_cluster_offset(bs, extent, NULL, - offset, false, &cluster_offset, 0, 0= ); + offset_in_cluster =3D vmdk_find_offset_in_cluster(extent, offset); =20 n_bytes =3D MIN(bytes, extent->cluster_sectors * BDRV_SECTOR_SIZE - offset_in_cluster); =20 + ret =3D vmdk_get_cluster_offset(bs, extent, offset, &cluster_offse= t); + if (ret !=3D VMDK_OK) { /* if not allocated, try to read from parent image, if exist */ if (bs->backing && ret !=3D VMDK_ZEROED) { @@ -2542,9 +2510,9 @@ static int vmdk_check(BlockDriverState *bs, BdrvCheck= Result *result, sector_num); break; } - ret =3D vmdk_get_cluster_offset(bs, extent, NULL, + ret =3D vmdk_get_cluster_offset(bs, extent, sector_num << BDRV_SECTOR_BITS, - false, &cluster_offset, 0, 0); + &cluster_offset); if (ret =3D=3D VMDK_ERROR) { fprintf(stderr, "ERROR: could not get cluster_offset for sector %" --=20 2.6.2