[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 29/36] block/backup: add backup_is_cluster_allocated
From: |
John Snow |
Subject: |
[Qemu-devel] [PULL 29/36] block/backup: add backup_is_cluster_allocated |
Date: |
Fri, 16 Aug 2019 19:13:11 -0400 |
Modify bdrv_is_unallocated_range to utilize the pnum return from
bdrv_is_allocated, and in the process change the semantics from
"is unallocated" to "is allocated."
Optionally returns a full number of clusters that share the same
allocation status.
This will be used to carefully toggle bits in the bitmap for sync=top
initialization in the following commits.
Signed-off-by: John Snow <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Message-id: address@hidden
Signed-off-by: John Snow <address@hidden>
---
block/backup.c | 62 +++++++++++++++++++++++++++++++++++---------------
1 file changed, 44 insertions(+), 18 deletions(-)
diff --git a/block/backup.c b/block/backup.c
index 305f9b3468b..f6bf32c9438 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -185,6 +185,48 @@ static int coroutine_fn
backup_cow_with_offload(BackupBlockJob *job,
return nbytes;
}
+/*
+ * Check if the cluster starting at offset is allocated or not.
+ * return via pnum the number of contiguous clusters sharing this allocation.
+ */
+static int backup_is_cluster_allocated(BackupBlockJob *s, int64_t offset,
+ int64_t *pnum)
+{
+ BlockDriverState *bs = blk_bs(s->common.blk);
+ int64_t count, total_count = 0;
+ int64_t bytes = s->len - offset;
+ int ret;
+
+ assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
+
+ while (true) {
+ ret = bdrv_is_allocated(bs, offset, bytes, &count);
+ if (ret < 0) {
+ return ret;
+ }
+
+ total_count += count;
+
+ if (ret || count == 0) {
+ /*
+ * ret: partial segment(s) are considered allocated.
+ * otherwise: unallocated tail is treated as an entire segment.
+ */
+ *pnum = DIV_ROUND_UP(total_count, s->cluster_size);
+ return ret;
+ }
+
+ /* Unallocated segment(s) with uncertain following segment(s) */
+ if (total_count >= s->cluster_size) {
+ *pnum = total_count / s->cluster_size;
+ return 0;
+ }
+
+ offset += count;
+ bytes -= count;
+ }
+}
+
static int coroutine_fn backup_do_cow(BackupBlockJob *job,
int64_t offset, uint64_t bytes,
bool *error_is_read,
@@ -398,34 +440,18 @@ static bool coroutine_fn yield_and_check(BackupBlockJob
*job)
return false;
}
-static bool bdrv_is_unallocated_range(BlockDriverState *bs,
- int64_t offset, int64_t bytes)
-{
- int64_t end = offset + bytes;
-
- while (offset < end && !bdrv_is_allocated(bs, offset, bytes, &bytes)) {
- if (bytes == 0) {
- return true;
- }
- offset += bytes;
- bytes = end - offset;
- }
-
- return offset >= end;
-}
-
static int coroutine_fn backup_loop(BackupBlockJob *job)
{
bool error_is_read;
int64_t offset;
BdrvDirtyBitmapIter *bdbi;
- BlockDriverState *bs = blk_bs(job->common.blk);
int ret = 0;
+ int64_t dummy;
bdbi = bdrv_dirty_iter_new(job->copy_bitmap);
while ((offset = bdrv_dirty_iter_next(bdbi)) != -1) {
if (job->sync_mode == MIRROR_SYNC_MODE_TOP &&
- bdrv_is_unallocated_range(bs, offset, job->cluster_size))
+ !backup_is_cluster_allocated(job, offset, &dummy))
{
bdrv_reset_dirty_bitmap(job->copy_bitmap, offset,
job->cluster_size);
--
2.21.0
- [Qemu-devel] [PULL 18/36] block/backup: loosen restriction on readonly bitmaps, (continued)
- [Qemu-devel] [PULL 18/36] block/backup: loosen restriction on readonly bitmaps, John Snow, 2019/08/16
- [Qemu-devel] [PULL 16/36] iotests: Add virtio-scsi device helper, John Snow, 2019/08/16
- [Qemu-devel] [PULL 12/36] block/backup: add 'always' bitmap sync policy, John Snow, 2019/08/16
- [Qemu-devel] [PULL 11/36] block/backup: upgrade copy_bitmap to BdrvDirtyBitmap, John Snow, 2019/08/16
- [Qemu-devel] [PULL 21/36] iotests: test bitmap moving inside 254, John Snow, 2019/08/16
- [Qemu-devel] [PULL 19/36] blockdev: reduce aio_context locked sections in bitmap add/remove, John Snow, 2019/08/16
- [Qemu-devel] [PULL 20/36] qapi: implement block-dirty-bitmap-remove transaction action, John Snow, 2019/08/16
- [Qemu-devel] [PULL 22/36] iotests/257: add Pattern class, John Snow, 2019/08/16
- [Qemu-devel] [PULL 25/36] block/backup: hoist bitmap check into QMP interface, John Snow, 2019/08/16
- [Qemu-devel] [PULL 23/36] iotests/257: add EmulatedBitmap class, John Snow, 2019/08/16
- [Qemu-devel] [PULL 29/36] block/backup: add backup_is_cluster_allocated,
John Snow <=
- [Qemu-devel] [PULL 28/36] block/backup: centralize copy_bitmap initialization, John Snow, 2019/08/16
- [Qemu-devel] [PULL 30/36] block/backup: teach TOP to never copy unallocated regions, John Snow, 2019/08/16
- [Qemu-devel] [PULL 27/36] block/backup: improve sync=bitmap work estimates, John Snow, 2019/08/16
- [Qemu-devel] [PULL 34/36] block/backup: deal with zero detection, John Snow, 2019/08/16
- [Qemu-devel] [PULL 35/36] block/backup: refactor write_flags, John Snow, 2019/08/16
- [Qemu-devel] [PULL 33/36] qapi: add dirty-bitmaps to query-named-block-nodes result, John Snow, 2019/08/16
- [Qemu-devel] [PULL 26/36] iotests/257: test API failures, John Snow, 2019/08/16
- [Qemu-devel] [PULL 31/36] block/backup: support bitmap sync modes for non-bitmap backups, John Snow, 2019/08/16
- [Qemu-devel] [PULL 36/36] tests/test-hbitmap: test next_zero and _next_dirty_area after truncate, John Snow, 2019/08/16
- [Qemu-devel] [PULL 24/36] iotests/257: Refactor backup helpers, John Snow, 2019/08/16