[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 11/19] mirror: Resize active commit base in mirror_ru
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 11/19] mirror: Resize active commit base in mirror_run() |
Date: |
Fri, 24 Feb 2017 19:17:02 +0100 |
This is more consistent with the commit block job, and it moves the code
to a place where we already have the necessary BlockBackends to resize
the base image when bdrv_truncate() is changed to require a BdrvChild.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block/mirror.c | 50 ++++++++++++++++++++++----------------------------
1 file changed, 22 insertions(+), 28 deletions(-)
diff --git a/block/mirror.c b/block/mirror.c
index ca8547b..3d50857 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -662,7 +662,28 @@ static void coroutine_fn mirror_run(void *opaque)
if (s->bdev_length < 0) {
ret = s->bdev_length;
goto immediate_exit;
- } else if (s->bdev_length == 0) {
+ }
+
+ /* Active commit must resize the base image if its size differs from the
+ * active layer. */
+ if (s->base == blk_bs(s->target)) {
+ int64_t base_length;
+
+ base_length = blk_getlength(s->target);
+ if (base_length < 0) {
+ ret = base_length;
+ goto immediate_exit;
+ }
+
+ if (s->bdev_length > base_length) {
+ ret = blk_truncate(s->target, s->bdev_length);
+ if (ret < 0) {
+ goto immediate_exit;
+ }
+ }
+ }
+
+ if (s->bdev_length == 0) {
/* Report BLOCK_JOB_READY and wait for complete. */
block_job_event_ready(&s->common);
s->synced = true;
@@ -1063,9 +1084,7 @@ void commit_active_start(const char *job_id,
BlockDriverState *bs,
BlockCompletionFunc *cb, void *opaque, Error **errp,
bool auto_complete)
{
- int64_t length, base_length;
int orig_base_flags;
- int ret;
Error *local_err = NULL;
orig_base_flags = bdrv_get_flags(base);
@@ -1074,31 +1093,6 @@ void commit_active_start(const char *job_id,
BlockDriverState *bs,
return;
}
- length = bdrv_getlength(bs);
- if (length < 0) {
- error_setg_errno(errp, -length,
- "Unable to determine length of %s", bs->filename);
- goto error_restore_flags;
- }
-
- base_length = bdrv_getlength(base);
- if (base_length < 0) {
- error_setg_errno(errp, -base_length,
- "Unable to determine length of %s", base->filename);
- goto error_restore_flags;
- }
-
- if (length > base_length) {
- ret = bdrv_truncate(base, length);
- if (ret < 0) {
- error_setg_errno(errp, -ret,
- "Top image %s is larger than base image %s, and "
- "resize of base image failed",
- bs->filename, base->filename);
- goto error_restore_flags;
- }
- }
-
mirror_start_job(job_id, bs, creation_flags, base, NULL, speed, 0, 0,
MIRROR_LEAVE_BACKING_CHAIN,
on_error, on_error, true, cb, opaque, &local_err,
--
1.8.3.1
- [Qemu-block] [PULL 01/19] qemu-iotests: Test 137 only supports 'file' protocol, (continued)
- [Qemu-block] [PULL 01/19] qemu-iotests: Test 137 only supports 'file' protocol, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 02/19] qemu-iotests: add ability to exclude certain protocols from tests, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 03/19] qemu-iotests: redirect nbd server stdout to /dev/null, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 04/19] qemu-img: Do not truncate before preallocation, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 05/19] qemu-img: Add tests for raw image preallocation, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 06/19] qemu-img: Truncate before full preallocation, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 07/19] qemu-img: Improve documentation for PREALLOC_MODE_FALLOC, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 08/19] iotests: Fix another race in 030, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 10/19] qcow2: Use BB for resizing in qcow2_amend_options(), Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 09/19] blockdev: Use BlockBackend to resize in qmp_block_resize(), Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 11/19] mirror: Resize active commit base in mirror_run(),
Kevin Wolf <=
- [Qemu-block] [PULL 13/19] block: Attach bs->file only during .bdrv_open(), Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 12/19] block: Pass BdrvChild to bdrv_truncate(), Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 16/19] block: Factor out bdrv_open_driver(), Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 17/19] block: Add bdrv_new_open_driver(), Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 18/19] vvfat: Use opened node as backing file, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 14/19] block: Factor out bdrv_open_child_bs(), Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 15/19] block: Use BlockBackend for image probing, Kevin Wolf, 2017/02/24
- [Qemu-block] [PULL 19/19] tests: Use opened block node for block job tests, Kevin Wolf, 2017/02/24
- Re: [Qemu-block] [Qemu-devel] [PULL 00/19] Block layer patches, no-reply, 2017/02/24
- Re: [Qemu-block] [Qemu-devel] [PULL 00/19] Block layer patches, Peter Maydell, 2017/02/26