From: Fam Zheng <famz@redhat.com>
To: Ashijeet Acharya <ashijeetacharya@gmail.com>
Cc: kwolf@redhat.com, jsnow@redhat.com, mreitz@redhat.com,
stefanha@gmail.com, qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v6 8/8] vmdk: Make vmdk_get_cluster_offset() return cluster offset only
Date: Tue, 27 Jun 2017 16:15:33 +0800 [thread overview]
Message-ID: <20170627081533.GE14166@lemon.lan> (raw)
In-Reply-To: <1496649172-26982-9-git-send-email-ashijeetacharya@gmail.com>
On Mon, 06/05 13:22, Ashijeet Acharya wrote:
> 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 <ashijeetacharya@gmail.com>
> ---
> 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 %"
> --
> 2.6.2
>
Reviewed-by: Fam Zheng <famz@redhat.com>
prev parent reply other threads:[~2017-06-27 8:15 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-05 7:52 [Qemu-devel] [PATCH v6 0/8] Optimize VMDK I/O by allocating multiple clusters Ashijeet Acharya
2017-06-05 7:52 ` [Qemu-devel] [PATCH v6 1/8] vmdk: Move vmdk_find_offset_in_cluster() to the top Ashijeet Acharya
2017-06-05 7:52 ` [Qemu-devel] [PATCH v6 2/8] vmdk: Rename get_whole_cluster() to vmdk_perform_cow() Ashijeet Acharya
2017-06-05 7:52 ` [Qemu-devel] [PATCH v6 3/8] vmdk: Rename get_cluster_offset() to vmdk_get_cluster_offset() Ashijeet Acharya
2017-06-05 7:52 ` [Qemu-devel] [PATCH v6 4/8] vmdk: Factor out metadata loading code out of vmdk_get_cluster_offset() Ashijeet Acharya
2017-06-05 7:52 ` [Qemu-devel] [PATCH v6 5/8] vmdk: Set maximum bytes allocated in one cycle Ashijeet Acharya
2017-06-05 7:52 ` [Qemu-devel] [PATCH v6 6/8] vmdk: New functions to assist allocating multiple clusters Ashijeet Acharya
2017-06-27 8:02 ` Fam Zheng
2017-06-29 7:42 ` Ashijeet Acharya
2017-06-05 7:52 ` [Qemu-devel] [PATCH v6 7/8] vmdk: Update metadata for " Ashijeet Acharya
2017-06-27 8:04 ` Fam Zheng
2017-06-29 8:48 ` Ashijeet Acharya
2017-06-27 8:14 ` Fam Zheng
2017-06-05 7:52 ` [Qemu-devel] [PATCH v6 8/8] vmdk: Make vmdk_get_cluster_offset() return cluster offset only Ashijeet Acharya
2017-06-27 8:15 ` Fam Zheng [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170627081533.GE14166@lemon.lan \
--to=famz@redhat.com \
--cc=ashijeetacharya@gmail.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.