[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 6/7] vmdk: Allocate multiple clusters at once
From: |
Ashijeet Acharya |
Subject: |
[Qemu-block] [PATCH v2 6/7] vmdk: Allocate multiple clusters at once |
Date: |
Sat, 25 Mar 2017 16:48:20 +0530 |
Get vmdk_pwritev() to make use of the new multiple cluster allocation
helper functions to allocate multiple clusters at once. Set the maximum
bytes allowed to get allocated at once to be not more than the extent
size boundary to handle writes at two separate extents appropriately.
Signed-off-by: Ashijeet Acharya <address@hidden>
---
block/vmdk.c | 37 +++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index 387e45b..3de8b8f 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1767,7 +1767,9 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t
offset,
int64_t offset_in_cluster, n_bytes;
uint64_t cluster_offset;
uint64_t bytes_done = 0;
+ uint64_t extent_size;
VmdkMetaData m_data;
+ uint32_t total_alloc_clusters = 0;
if (DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) > bs->total_sectors) {
error_report("Wrong offset: offset=0x%" PRIx64
@@ -1781,14 +1783,22 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t
offset,
if (!extent) {
return -EIO;
}
+ extent_size = extent->end_sector * BDRV_SECTOR_SIZE;
+
offset_in_cluster = vmdk_find_offset_in_cluster(extent, offset);
- n_bytes = MIN(bytes, extent->cluster_sectors * BDRV_SECTOR_SIZE
- - offset_in_cluster);
- ret = get_cluster_offset(bs, extent, &m_data, offset,
- !(extent->compressed || zeroed),
- &cluster_offset, offset_in_cluster,
- offset_in_cluster + n_bytes);
+ /* truncate n_bytes to first cluster because we need to perform COW */
+ if (offset_in_cluster > 0) {
+ n_bytes = MIN(bytes, extent->cluster_sectors * BDRV_SECTOR_SIZE
+ - offset_in_cluster);
+ } else {
+ n_bytes = MIN(bytes, extent_size - offset);
+ }
+
+ ret = vmdk_alloc_cluster_offset(bs, extent, &m_data, offset,
+ !(extent->compressed || zeroed),
+ &cluster_offset, n_bytes,
+ &total_alloc_clusters);
if (extent->compressed) {
if (ret == VMDK_OK) {
/* Refuse write to allocated cluster for streamOptimized */
@@ -1797,19 +1807,22 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t
offset,
return -EIO;
} else {
/* allocate */
- ret = get_cluster_offset(bs, extent, &m_data, offset,
- true, &cluster_offset, 0, 0);
+ ret = vmdk_alloc_cluster_offset(bs, extent, &m_data, offset,
+ true, &cluster_offset, n_bytes,
+ &total_alloc_clusters);
}
}
if (ret == VMDK_ERROR) {
return -EINVAL;
}
+
if (zeroed) {
/* Do zeroed write, buf is ignored */
- if (extent->has_zero_grain &&
- offset_in_cluster == 0 &&
- n_bytes >= extent->cluster_sectors * BDRV_SECTOR_SIZE) {
- n_bytes = extent->cluster_sectors * BDRV_SECTOR_SIZE;
+ if (extent->has_zero_grain && offset_in_cluster == 0 &&
+ n_bytes >= extent->cluster_sectors * BDRV_SECTOR_SIZE *
+ total_alloc_clusters) {
+ n_bytes = extent->cluster_sectors * BDRV_SECTOR_SIZE *
+ total_alloc_clusters;
if (!zero_dry_run) {
/* update L2 tables */
if (vmdk_L2update(extent, &m_data, VMDK_GTE_ZEROED)
--
2.6.2
- [Qemu-block] [PATCH v2 0/7] Optiomize VMDK I/O by allocating multiple clusters, Ashijeet Acharya, 2017/03/25
- [Qemu-block] [PATCH v2 1/7] vmdk: Refactor and introduce new helper functions, Ashijeet Acharya, 2017/03/25
- [Qemu-block] [PATCH v2 2/7] vmdk: Rename get_whole_cluster() to vmdk_perform_cow(), Ashijeet Acharya, 2017/03/25
- [Qemu-block] [PATCH v2 3/7] vmdk: Factor out metadata loading code out of get_cluster_offset(), Ashijeet Acharya, 2017/03/25
- [Qemu-block] [PATCH v2 4/7] vmdk: New functions to allocate multiple clusters and cluster offset, Ashijeet Acharya, 2017/03/25
- [Qemu-block] [PATCH v2 5/7] vmdk: Rename get_cluster_offset() to vmdk_get_cluster_offset(), Ashijeet Acharya, 2017/03/25
- [Qemu-block] [PATCH v2 6/7] vmdk: Allocate multiple clusters at once,
Ashijeet Acharya <=
- [Qemu-block] [PATCH v2 7/7] vmdk: Update metadata for multiple clusters, Ashijeet Acharya, 2017/03/25