|
|
357786 |
From c720832a9aa72b4b9a326ea95c46ed1e2cbd5cad Mon Sep 17 00:00:00 2001
|
|
|
357786 |
From: John Snow <jsnow@redhat.com>
|
|
|
357786 |
Date: Mon, 10 Sep 2018 18:17:51 +0200
|
|
|
357786 |
Subject: [PATCH 13/25] block/commit: refactor commit to use job callbacks
|
|
|
357786 |
|
|
|
357786 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
357786 |
Message-id: <20180910181803.11781-14-jsnow@redhat.com>
|
|
|
357786 |
Patchwork-id: 82092
|
|
|
357786 |
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 13/25] block/commit: refactor commit to use job callbacks
|
|
|
357786 |
Bugzilla: 1626061
|
|
|
357786 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
357786 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
|
|
|
357786 |
Use the component callbacks; prepare, abort, and clean.
|
|
|
357786 |
|
|
|
357786 |
NB: prepare is only called when the job has not yet failed;
|
|
|
357786 |
and abort can be called after prepare.
|
|
|
357786 |
|
|
|
357786 |
complete -> prepare -> abort -> clean
|
|
|
357786 |
complete -> abort -> clean
|
|
|
357786 |
|
|
|
357786 |
During refactor, a potential problem with bdrv_drop_intermediate
|
|
|
357786 |
was identified, the patched behavior is no worse than the pre-patch
|
|
|
357786 |
behavior, so leave a FIXME for now to be fixed in a future patch.
|
|
|
357786 |
|
|
|
357786 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
357786 |
Reviewed-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
Message-id: 20180906130225.5118-5-jsnow@redhat.com
|
|
|
357786 |
Reviewed-by: Jeff Cody <jcody@redhat.com>
|
|
|
357786 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
(cherry picked from commit 38ff0656c24ad88fb08af343ad610c9fc4741c58)
|
|
|
357786 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
357786 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
---
|
|
|
357786 |
block/commit.c | 92 ++++++++++++++++++++++++++++++++--------------------------
|
|
|
357786 |
1 file changed, 51 insertions(+), 41 deletions(-)
|
|
|
357786 |
|
|
|
357786 |
diff --git a/block/commit.c b/block/commit.c
|
|
|
357786 |
index c737664..b387765 100644
|
|
|
357786 |
--- a/block/commit.c
|
|
|
357786 |
+++ b/block/commit.c
|
|
|
357786 |
@@ -36,6 +36,7 @@ typedef struct CommitBlockJob {
|
|
|
357786 |
BlockDriverState *commit_top_bs;
|
|
|
357786 |
BlockBackend *top;
|
|
|
357786 |
BlockBackend *base;
|
|
|
357786 |
+ BlockDriverState *base_bs;
|
|
|
357786 |
BlockdevOnError on_error;
|
|
|
357786 |
int base_flags;
|
|
|
357786 |
char *backing_file_str;
|
|
|
357786 |
@@ -68,61 +69,67 @@ static int coroutine_fn commit_populate(BlockBackend *bs, BlockBackend *base,
|
|
|
357786 |
return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void commit_exit(Job *job)
|
|
|
357786 |
+static int commit_prepare(Job *job)
|
|
|
357786 |
{
|
|
|
357786 |
CommitBlockJob *s = container_of(job, CommitBlockJob, common.job);
|
|
|
357786 |
- BlockJob *bjob = &s->common;
|
|
|
357786 |
- BlockDriverState *top = blk_bs(s->top);
|
|
|
357786 |
- BlockDriverState *base = blk_bs(s->base);
|
|
|
357786 |
- BlockDriverState *commit_top_bs = s->commit_top_bs;
|
|
|
357786 |
- bool remove_commit_top_bs = false;
|
|
|
357786 |
-
|
|
|
357786 |
- /* Make sure commit_top_bs and top stay around until bdrv_replace_node() */
|
|
|
357786 |
- bdrv_ref(top);
|
|
|
357786 |
- bdrv_ref(commit_top_bs);
|
|
|
357786 |
|
|
|
357786 |
/* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE before
|
|
|
357786 |
* the normal backing chain can be restored. */
|
|
|
357786 |
blk_unref(s->base);
|
|
|
357786 |
+ s->base = NULL;
|
|
|
357786 |
+
|
|
|
357786 |
+ /* FIXME: bdrv_drop_intermediate treats total failures and partial failures
|
|
|
357786 |
+ * identically. Further work is needed to disambiguate these cases. */
|
|
|
357786 |
+ return bdrv_drop_intermediate(s->commit_top_bs, s->base_bs,
|
|
|
357786 |
+ s->backing_file_str);
|
|
|
357786 |
+}
|
|
|
357786 |
|
|
|
357786 |
- if (!job_is_cancelled(job) && job->ret == 0) {
|
|
|
357786 |
- /* success */
|
|
|
357786 |
- job->ret = bdrv_drop_intermediate(s->commit_top_bs, base,
|
|
|
357786 |
- s->backing_file_str);
|
|
|
357786 |
- } else {
|
|
|
357786 |
- /* XXX Can (or should) we somehow keep 'consistent read' blocked even
|
|
|
357786 |
- * after the failed/cancelled commit job is gone? If we already wrote
|
|
|
357786 |
- * something to base, the intermediate images aren't valid any more. */
|
|
|
357786 |
- remove_commit_top_bs = true;
|
|
|
357786 |
+static void commit_abort(Job *job)
|
|
|
357786 |
+{
|
|
|
357786 |
+ CommitBlockJob *s = container_of(job, CommitBlockJob, common.job);
|
|
|
357786 |
+ BlockDriverState *top_bs = blk_bs(s->top);
|
|
|
357786 |
+
|
|
|
357786 |
+ /* Make sure commit_top_bs and top stay around until bdrv_replace_node() */
|
|
|
357786 |
+ bdrv_ref(top_bs);
|
|
|
357786 |
+ bdrv_ref(s->commit_top_bs);
|
|
|
357786 |
+
|
|
|
357786 |
+ if (s->base) {
|
|
|
357786 |
+ blk_unref(s->base);
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
+ /* free the blockers on the intermediate nodes so that bdrv_replace_nodes
|
|
|
357786 |
+ * can succeed */
|
|
|
357786 |
+ block_job_remove_all_bdrv(&s->common);
|
|
|
357786 |
+
|
|
|
357786 |
+ /* If bdrv_drop_intermediate() failed (or was not invoked), remove the
|
|
|
357786 |
+ * commit filter driver from the backing chain now. Do this as the final
|
|
|
357786 |
+ * step so that the 'consistent read' permission can be granted.
|
|
|
357786 |
+ *
|
|
|
357786 |
+ * XXX Can (or should) we somehow keep 'consistent read' blocked even
|
|
|
357786 |
+ * after the failed/cancelled commit job is gone? If we already wrote
|
|
|
357786 |
+ * something to base, the intermediate images aren't valid any more. */
|
|
|
357786 |
+ bdrv_child_try_set_perm(s->commit_top_bs->backing, 0, BLK_PERM_ALL,
|
|
|
357786 |
+ &error_abort);
|
|
|
357786 |
+ bdrv_replace_node(s->commit_top_bs, backing_bs(s->commit_top_bs),
|
|
|
357786 |
+ &error_abort);
|
|
|
357786 |
+
|
|
|
357786 |
+ bdrv_unref(s->commit_top_bs);
|
|
|
357786 |
+ bdrv_unref(top_bs);
|
|
|
357786 |
+}
|
|
|
357786 |
+
|
|
|
357786 |
+static void commit_clean(Job *job)
|
|
|
357786 |
+{
|
|
|
357786 |
+ CommitBlockJob *s = container_of(job, CommitBlockJob, common.job);
|
|
|
357786 |
+
|
|
|
357786 |
/* restore base open flags here if appropriate (e.g., change the base back
|
|
|
357786 |
* to r/o). These reopens do not need to be atomic, since we won't abort
|
|
|
357786 |
* even on failure here */
|
|
|
357786 |
- if (s->base_flags != bdrv_get_flags(base)) {
|
|
|
357786 |
- bdrv_reopen(base, s->base_flags, NULL);
|
|
|
357786 |
+ if (s->base_flags != bdrv_get_flags(s->base_bs)) {
|
|
|
357786 |
+ bdrv_reopen(s->base_bs, s->base_flags, NULL);
|
|
|
357786 |
}
|
|
|
357786 |
+
|
|
|
357786 |
g_free(s->backing_file_str);
|
|
|
357786 |
blk_unref(s->top);
|
|
|
357786 |
-
|
|
|
357786 |
- /* If there is more than one reference to the job (e.g. if called from
|
|
|
357786 |
- * job_finish_sync()), job_completed() won't free it and therefore the
|
|
|
357786 |
- * blockers on the intermediate nodes remain. This would cause
|
|
|
357786 |
- * bdrv_set_backing_hd() to fail. */
|
|
|
357786 |
- block_job_remove_all_bdrv(bjob);
|
|
|
357786 |
-
|
|
|
357786 |
- /* If bdrv_drop_intermediate() didn't already do that, remove the commit
|
|
|
357786 |
- * filter driver from the backing chain. Do this as the final step so that
|
|
|
357786 |
- * the 'consistent read' permission can be granted. */
|
|
|
357786 |
- if (remove_commit_top_bs) {
|
|
|
357786 |
- bdrv_child_try_set_perm(commit_top_bs->backing, 0, BLK_PERM_ALL,
|
|
|
357786 |
- &error_abort);
|
|
|
357786 |
- bdrv_replace_node(commit_top_bs, backing_bs(commit_top_bs),
|
|
|
357786 |
- &error_abort);
|
|
|
357786 |
- }
|
|
|
357786 |
-
|
|
|
357786 |
- bdrv_unref(commit_top_bs);
|
|
|
357786 |
- bdrv_unref(top);
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static int coroutine_fn commit_run(Job *job, Error **errp)
|
|
|
357786 |
@@ -211,7 +218,9 @@ static const BlockJobDriver commit_job_driver = {
|
|
|
357786 |
.user_resume = block_job_user_resume,
|
|
|
357786 |
.drain = block_job_drain,
|
|
|
357786 |
.run = commit_run,
|
|
|
357786 |
- .exit = commit_exit,
|
|
|
357786 |
+ .prepare = commit_prepare,
|
|
|
357786 |
+ .abort = commit_abort,
|
|
|
357786 |
+ .clean = commit_clean
|
|
|
357786 |
},
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
@@ -350,6 +359,7 @@ void commit_start(const char *job_id, BlockDriverState *bs,
|
|
|
357786 |
if (ret < 0) {
|
|
|
357786 |
goto fail;
|
|
|
357786 |
}
|
|
|
357786 |
+ s->base_bs = base;
|
|
|
357786 |
|
|
|
357786 |
/* Required permissions are already taken with block_job_add_bdrv() */
|
|
|
357786 |
s->top = blk_new(0, BLK_PERM_ALL);
|
|
|
357786 |
--
|
|
|
357786 |
1.8.3.1
|
|
|
357786 |
|