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