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