|
|
383d26 |
From f27835b1c21b80477e828ed82c5afd764e6f90ca Mon Sep 17 00:00:00 2001
|
|
|
383d26 |
From: John Snow <jsnow@redhat.com>
|
|
|
383d26 |
Date: Mon, 10 Sep 2018 18:17:53 +0200
|
|
|
383d26 |
Subject: [PATCH 15/25] block/mirror: conservative mirror_exit refactor
|
|
|
383d26 |
|
|
|
383d26 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
383d26 |
Message-id: <20180910181803.11781-16-jsnow@redhat.com>
|
|
|
383d26 |
Patchwork-id: 82105
|
|
|
383d26 |
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 15/25] block/mirror: conservative mirror_exit refactor
|
|
|
383d26 |
Bugzilla: 1626061
|
|
|
383d26 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
383d26 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
383d26 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
383d26 |
|
|
|
383d26 |
For purposes of minimum code movement, refactor the mirror_exit
|
|
|
383d26 |
callback to use the post-finalization callbacks in a trivial way.
|
|
|
383d26 |
|
|
|
383d26 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
383d26 |
Message-id: 20180906130225.5118-7-jsnow@redhat.com
|
|
|
383d26 |
Reviewed-by: Jeff Cody <jcody@redhat.com>
|
|
|
383d26 |
Reviewed-by: Max Reitz <mreitz@redhat.com>
|
|
|
383d26 |
[mreitz: Added comment for the mirror_exit() function]
|
|
|
383d26 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
383d26 |
(cherry picked from commit 9fd426955da4239af7690c92b387fff0502aca84)
|
|
|
383d26 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
383d26 |
|
|
|
383d26 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
383d26 |
|
|
|
383d26 |
Conflicts:
|
|
|
383d26 |
block/mirror.c: context conflict on job properties
|
|
|
383d26 |
---
|
|
|
383d26 |
block/mirror.c | 44 +++++++++++++++++++++++++++++++++-----------
|
|
|
383d26 |
1 file changed, 33 insertions(+), 11 deletions(-)
|
|
|
383d26 |
|
|
|
383d26 |
diff --git a/block/mirror.c b/block/mirror.c
|
|
|
383d26 |
index 1945000..313e6e9 100644
|
|
|
383d26 |
--- a/block/mirror.c
|
|
|
383d26 |
+++ b/block/mirror.c
|
|
|
383d26 |
@@ -71,6 +71,7 @@ typedef struct MirrorBlockJob {
|
|
|
383d26 |
int target_cluster_size;
|
|
|
383d26 |
int max_iov;
|
|
|
383d26 |
bool initial_zeroing_ongoing;
|
|
|
383d26 |
+ bool prepared;
|
|
|
383d26 |
} MirrorBlockJob;
|
|
|
383d26 |
|
|
|
383d26 |
typedef struct MirrorOp {
|
|
|
383d26 |
@@ -480,7 +481,12 @@ static void mirror_wait_for_all_io(MirrorBlockJob *s)
|
|
|
383d26 |
}
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
-static void mirror_exit(Job *job)
|
|
|
383d26 |
+/**
|
|
|
383d26 |
+ * mirror_exit_common: handle both abort() and prepare() cases.
|
|
|
383d26 |
+ * for .prepare, returns 0 on success and -errno on failure.
|
|
|
383d26 |
+ * for .abort cases, denoted by abort = true, MUST return 0.
|
|
|
383d26 |
+ */
|
|
|
383d26 |
+static int mirror_exit_common(Job *job)
|
|
|
383d26 |
{
|
|
|
383d26 |
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
|
|
|
383d26 |
BlockJob *bjob = &s->common;
|
|
|
383d26 |
@@ -489,7 +495,13 @@ static void mirror_exit(Job *job)
|
|
|
383d26 |
BlockDriverState *target_bs = blk_bs(s->target);
|
|
|
383d26 |
BlockDriverState *mirror_top_bs = s->mirror_top_bs;
|
|
|
383d26 |
Error *local_err = NULL;
|
|
|
383d26 |
- int ret = job->ret;
|
|
|
383d26 |
+ bool abort = job->ret < 0;
|
|
|
383d26 |
+ int ret = 0;
|
|
|
383d26 |
+
|
|
|
383d26 |
+ if (s->prepared) {
|
|
|
383d26 |
+ return 0;
|
|
|
383d26 |
+ }
|
|
|
383d26 |
+ s->prepared = true;
|
|
|
383d26 |
|
|
|
383d26 |
bdrv_release_dirty_bitmap(src, s->dirty_bitmap);
|
|
|
383d26 |
|
|
|
383d26 |
@@ -514,7 +526,7 @@ static void mirror_exit(Job *job)
|
|
|
383d26 |
* required before it could become a backing file of target_bs. */
|
|
|
383d26 |
bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL,
|
|
|
383d26 |
&error_abort);
|
|
|
383d26 |
- if (ret == 0 && s->backing_mode == MIRROR_SOURCE_BACKING_CHAIN) {
|
|
|
383d26 |
+ if (!abort && s->backing_mode == MIRROR_SOURCE_BACKING_CHAIN) {
|
|
|
383d26 |
BlockDriverState *backing = s->is_none_mode ? src : s->base;
|
|
|
383d26 |
if (backing_bs(target_bs) != backing) {
|
|
|
383d26 |
bdrv_set_backing_hd(target_bs, backing, &local_err);
|
|
|
383d26 |
@@ -530,11 +542,8 @@ static void mirror_exit(Job *job)
|
|
|
383d26 |
aio_context_acquire(replace_aio_context);
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
- if (s->should_complete && ret == 0) {
|
|
|
383d26 |
- BlockDriverState *to_replace = src;
|
|
|
383d26 |
- if (s->to_replace) {
|
|
|
383d26 |
- to_replace = s->to_replace;
|
|
|
383d26 |
- }
|
|
|
383d26 |
+ if (s->should_complete && !abort) {
|
|
|
383d26 |
+ BlockDriverState *to_replace = s->to_replace ?: src;
|
|
|
383d26 |
|
|
|
383d26 |
if (bdrv_get_flags(target_bs) != bdrv_get_flags(to_replace)) {
|
|
|
383d26 |
bdrv_reopen(target_bs, bdrv_get_flags(to_replace), NULL);
|
|
|
383d26 |
@@ -581,7 +590,18 @@ static void mirror_exit(Job *job)
|
|
|
383d26 |
bdrv_unref(mirror_top_bs);
|
|
|
383d26 |
bdrv_unref(src);
|
|
|
383d26 |
|
|
|
383d26 |
- job->ret = ret;
|
|
|
383d26 |
+ return ret;
|
|
|
383d26 |
+}
|
|
|
383d26 |
+
|
|
|
383d26 |
+static int mirror_prepare(Job *job)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ return mirror_exit_common(job);
|
|
|
383d26 |
+}
|
|
|
383d26 |
+
|
|
|
383d26 |
+static void mirror_abort(Job *job)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ int ret = mirror_exit_common(job);
|
|
|
383d26 |
+ assert(ret == 0);
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
static void mirror_throttle(MirrorBlockJob *s)
|
|
|
383d26 |
@@ -986,7 +1006,8 @@ static const BlockJobDriver mirror_job_driver = {
|
|
|
383d26 |
.user_resume = block_job_user_resume,
|
|
|
383d26 |
.drain = block_job_drain,
|
|
|
383d26 |
.run = mirror_run,
|
|
|
383d26 |
- .exit = mirror_exit,
|
|
|
383d26 |
+ .prepare = mirror_prepare,
|
|
|
383d26 |
+ .abort = mirror_abort,
|
|
|
383d26 |
.pause = mirror_pause,
|
|
|
383d26 |
.complete = mirror_complete,
|
|
|
383d26 |
},
|
|
|
383d26 |
@@ -1002,7 +1023,8 @@ static const BlockJobDriver commit_active_job_driver = {
|
|
|
383d26 |
.user_resume = block_job_user_resume,
|
|
|
383d26 |
.drain = block_job_drain,
|
|
|
383d26 |
.run = mirror_run,
|
|
|
383d26 |
- .exit = mirror_exit,
|
|
|
383d26 |
+ .prepare = mirror_prepare,
|
|
|
383d26 |
+ .abort = mirror_abort,
|
|
|
383d26 |
.pause = mirror_pause,
|
|
|
383d26 |
.complete = mirror_complete,
|
|
|
383d26 |
},
|
|
|
383d26 |
--
|
|
|
383d26 |
1.8.3.1
|
|
|
383d26 |
|