[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 17/21] qemu-img: rebase: Reduce reads on in-chain reb
From: |
Max Reitz |
Subject: |
[Qemu-block] [PULL 17/21] qemu-img: rebase: Reduce reads on in-chain rebase |
Date: |
Tue, 28 May 2019 21:28:43 +0200 |
From: Sam Eiderman <address@hidden>
In the following case:
(base) A <- B <- C (tip)
when running:
qemu-img rebase -b A C
QEMU would read all sectors not allocated in the file being rebased (C)
and compare them to the new base image (A), regardless of whether they
were changed or even allocated anywhere along the chain between the new
base and the top image (B). This causes many unneeded reads when
rebasing an image which represents a small diff of a large disk, as it
would read most of the disk's sectors.
Instead, use bdrv_is_allocated_above() to reduce the number of
unnecessary reads.
Reviewed-by: Karl Heubaum <address@hidden>
Signed-off-by: Sam Eiderman <address@hidden>
Signed-off-by: Eyal Moscovici <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
qemu-img.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/qemu-img.c b/qemu-img.c
index 9bd0bb1e47..2d96a491e2 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -3164,7 +3164,7 @@ static int img_rebase(int argc, char **argv)
BlockBackend *blk = NULL, *blk_old_backing = NULL, *blk_new_backing = NULL;
uint8_t *buf_old = NULL;
uint8_t *buf_new = NULL;
- BlockDriverState *bs = NULL;
+ BlockDriverState *bs = NULL, *prefix_chain_bs = NULL;
char *filename;
const char *fmt, *cache, *src_cache, *out_basefmt, *out_baseimg;
int c, flags, src_flags, ret;
@@ -3353,6 +3353,12 @@ static int img_rebase(int argc, char **argv)
goto out;
}
+ /*
+ * Find out whether we rebase an image on top of a previous image
+ * in its chain.
+ */
+ prefix_chain_bs = bdrv_find_backing_image(bs, out_real_path);
+
blk_new_backing = blk_new_open(out_real_path, NULL,
options, src_flags, &local_err);
g_free(out_real_path);
@@ -3437,6 +3443,23 @@ static int img_rebase(int argc, char **argv)
continue;
}
+ if (prefix_chain_bs) {
+ /*
+ * If cluster wasn't changed since prefix_chain, we don't need
+ * to take action
+ */
+ ret = bdrv_is_allocated_above(backing_bs(bs), prefix_chain_bs,
+ offset, n, &n);
+ if (ret < 0) {
+ error_report("error while reading image metadata: %s",
+ strerror(-ret));
+ goto out;
+ }
+ if (!ret) {
+ continue;
+ }
+ }
+
/*
* Read old and new backing file and take into consideration that
* backing files may be smaller than the COW image.
--
2.21.0
- [Qemu-block] [PULL 16/21] qemu-img: rebase: Reuse parent BlockDriverState, (continued)
- [Qemu-block] [PULL 16/21] qemu-img: rebase: Reuse parent BlockDriverState, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 07/21] qcow2: bdrv_co_pwritev: move encryption code out of the lock, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 06/21] qcow2: qcow2_co_preadv: improve locking, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 14/21] block: Use bdrv_unref_child() for all children in bdrv_close(), Max Reitz, 2019/05/28
- [Qemu-block] [PULL 10/21] block/backup: move to copy_bitmap with granularity, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 15/21] block: Make bdrv_root_attach_child() unref child_bs on failure, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 09/21] block/backup: simplify backup_incremental_init_copy_bitmap, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 08/21] qcow2: do encryption in threads, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 21/21] blockdev: loosen restrictions on drive-backup source node, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 18/21] qemu-img: rebase: Reuse in-chain BlockDriverState, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 17/21] qemu-img: rebase: Reduce reads on in-chain rebase,
Max Reitz <=
- [Qemu-block] [PULL 11/21] block/backup: refactor and tolerate unallocated cluster skipping, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 20/21] qcow2-bitmap: initialize bitmap directory alignment, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 12/21] block/backup: unify different modes code path, Max Reitz, 2019/05/28
- [Qemu-block] [PULL 19/21] qcow2: skip writing zero buffers to empty COW areas, Max Reitz, 2019/05/28
- Re: [Qemu-block] [PULL 00/21] Block patches, Peter Maydell, 2019/05/30