From: John Snow <jsnow@redhat.com>
To: qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Jeff Cody <jcody@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Kevin Wolf <kwolf@redhat.com>,
jtc@redhat.com, Max Reitz <mreitz@redhat.com>,
Eric Blake <eblake@redhat.com>, John Snow <jsnow@redhat.com>
Subject: [Qemu-devel] [PATCH v4 04/15] block/commit: refactor commit to use job callbacks
Date: Tue, 4 Sep 2018 13:09:19 -0400 [thread overview]
Message-ID: <20180904170930.28619-5-jsnow@redhat.com> (raw)
In-Reply-To: <20180904170930.28619-1-jsnow@redhat.com>
Use the component callbacks; prepare, abort, and clean.
NB: prepare is only called when the job has not yet failed;
and abort can be called after prepare.
complete -> prepare -> abort -> clean
complete -> abort -> clean
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
block/commit.c | 90 ++++++++++++++++++++++++++++++++--------------------------
1 file changed, 49 insertions(+), 41 deletions(-)
diff --git a/block/commit.c b/block/commit.c
index b6e8969877..eb3941e545 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -36,6 +36,7 @@ typedef struct CommitBlockJob {
BlockDriverState *commit_top_bs;
BlockBackend *top;
BlockBackend *base;
+ BlockDriverState *base_bs;
BlockdevOnError on_error;
int base_flags;
char *backing_file_str;
@@ -68,61 +69,65 @@ static int coroutine_fn commit_populate(BlockBackend *bs, BlockBackend *base,
return 0;
}
-static void commit_exit(Job *job)
+static int commit_prepare(Job *job)
{
CommitBlockJob *s = container_of(job, CommitBlockJob, common.job);
- BlockJob *bjob = &s->common;
- BlockDriverState *top = blk_bs(s->top);
- BlockDriverState *base = blk_bs(s->base);
- BlockDriverState *commit_top_bs = s->commit_top_bs;
- bool remove_commit_top_bs = false;
-
- /* Make sure commit_top_bs and top stay around until bdrv_replace_node() */
- bdrv_ref(top);
- bdrv_ref(commit_top_bs);
/* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE before
* the normal backing chain can be restored. */
blk_unref(s->base);
+ s->base = NULL;
- if (!job_is_cancelled(job) && job->ret == 0) {
- /* success */
- job->ret = bdrv_drop_intermediate(s->commit_top_bs, base,
- s->backing_file_str);
- } else {
- /* XXX Can (or should) we somehow keep 'consistent read' blocked even
- * after the failed/cancelled commit job is gone? If we already wrote
- * something to base, the intermediate images aren't valid any more. */
- remove_commit_top_bs = true;
+ return bdrv_drop_intermediate(s->commit_top_bs, s->base_bs,
+ s->backing_file_str);
+}
+
+static void commit_abort(Job *job)
+{
+ CommitBlockJob *s = container_of(job, CommitBlockJob, common.job);
+ BlockDriverState *top_bs = blk_bs(s->top);
+
+ /* Make sure commit_top_bs and top stay around until bdrv_replace_node() */
+ bdrv_ref(top_bs);
+ bdrv_ref(s->commit_top_bs);
+
+ if (s->base) {
+ blk_unref(s->base);
}
+ /* free the blockers on the intermediate nodes so that bdrv_replace_nodes
+ * can succeed */
+ block_job_remove_all_bdrv(&s->common);
+
+ /* If bdrv_drop_intermediate() failed (or was not invoked), remove the
+ * commit filter driver from the backing chain now. Do this as the final
+ * step so that the 'consistent read' permission can be granted.
+ *
+ * XXX Can (or should) we somehow keep 'consistent read' blocked even
+ * after the failed/cancelled commit job is gone? If we already wrote
+ * something to base, the intermediate images aren't valid any more. */
+ bdrv_child_try_set_perm(s->commit_top_bs->backing, 0, BLK_PERM_ALL,
+ &error_abort);
+ bdrv_replace_node(s->commit_top_bs, backing_bs(s->commit_top_bs),
+ &error_abort);
+
+ bdrv_unref(s->commit_top_bs);
+ bdrv_unref(top_bs);
+}
+
+static void commit_clean(Job *job)
+{
+ CommitBlockJob *s = container_of(job, CommitBlockJob, common.job);
+
/* restore base open flags here if appropriate (e.g., change the base back
* to r/o). These reopens do not need to be atomic, since we won't abort
* even on failure here */
- if (s->base_flags != bdrv_get_flags(base)) {
- bdrv_reopen(base, s->base_flags, NULL);
+ if (s->base_flags != bdrv_get_flags(s->base_bs)) {
+ bdrv_reopen(s->base_bs, s->base_flags, NULL);
}
+
g_free(s->backing_file_str);
blk_unref(s->top);
-
- /* If there is more than one reference to the job (e.g. if called from
- * job_finish_sync()), job_completed() won't free it and therefore the
- * blockers on the intermediate nodes remain. This would cause
- * bdrv_set_backing_hd() to fail. */
- block_job_remove_all_bdrv(bjob);
-
- /* If bdrv_drop_intermediate() didn't already do that, remove the commit
- * filter driver from the backing chain. Do this as the final step so that
- * the 'consistent read' permission can be granted. */
- if (remove_commit_top_bs) {
- bdrv_child_try_set_perm(commit_top_bs->backing, 0, BLK_PERM_ALL,
- &error_abort);
- bdrv_replace_node(commit_top_bs, backing_bs(commit_top_bs),
- &error_abort);
- }
-
- bdrv_unref(commit_top_bs);
- bdrv_unref(top);
}
static int coroutine_fn commit_run(Job *job, Error **errp)
@@ -211,7 +216,9 @@ static const BlockJobDriver commit_job_driver = {
.user_resume = block_job_user_resume,
.drain = block_job_drain,
.run = commit_run,
- .exit = commit_exit,
+ .prepare = commit_prepare,
+ .abort = commit_abort,
+ .clean = commit_clean
},
};
@@ -345,6 +352,7 @@ void commit_start(const char *job_id, BlockDriverState *bs,
if (ret < 0) {
goto fail;
}
+ s->base_bs = base;
/* Required permissions are already taken with block_job_add_bdrv() */
s->top = blk_new(0, BLK_PERM_ALL);
--
2.14.4
next prev parent reply other threads:[~2018-09-04 17:09 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-04 17:09 [Qemu-devel] [PATCH v4 00/15] jobs: Job Exit Refactoring Pt 2 John Snow
2018-09-04 17:09 ` [Qemu-devel] [PATCH v4 01/15] block/commit: add block job creation flags John Snow
2018-09-04 17:09 ` [Qemu-devel] [PATCH v4 02/15] block/mirror: " John Snow
2018-09-04 17:09 ` [Qemu-devel] [PATCH v4 03/15] block/stream: " John Snow
2018-09-04 17:09 ` John Snow [this message]
2018-09-04 18:46 ` [Qemu-devel] [PATCH v4 04/15] block/commit: refactor commit to use job callbacks Jeff Cody
2018-09-04 20:32 ` John Snow
2018-09-05 10:27 ` Max Reitz
2018-09-05 10:49 ` Kevin Wolf
2018-09-05 11:37 ` Max Reitz
2018-09-05 11:53 ` Kevin Wolf
2018-09-05 12:25 ` Max Reitz
2018-09-05 19:05 ` John Snow
2018-09-04 17:09 ` [Qemu-devel] [PATCH v4 05/15] block/mirror: don't install backing chain on abort John Snow
2018-09-05 10:40 ` Max Reitz
2018-09-05 15:39 ` John Snow
2018-09-07 11:40 ` Max Reitz
2018-09-04 17:09 ` [Qemu-devel] [PATCH v4 06/15] block/mirror: conservative mirror_exit refactor John Snow
2018-09-05 10:43 ` Max Reitz
2018-09-05 13:09 ` John Snow
2018-09-05 15:50 ` Eric Blake
2018-09-04 17:09 ` [Qemu-devel] [PATCH v4 07/15] block/stream: refactor stream to use job callbacks John Snow
2018-09-04 17:09 ` [Qemu-devel] [PATCH v4 08/15] tests/blockjob: replace Blockjob with Job John Snow
2018-09-04 17:09 ` [Qemu-devel] [PATCH v4 09/15] tests/test-blockjob: remove exit callback John Snow
2018-09-04 17:09 ` [Qemu-devel] [PATCH v4 10/15] tests/test-blockjob-txn: move .exit to .clean John Snow
2018-09-05 10:45 ` Max Reitz
2018-09-04 17:09 ` [Qemu-devel] [PATCH v4 11/15] jobs: remove .exit callback John Snow
2018-09-04 17:09 ` [Qemu-devel] [PATCH v4 12/15] qapi/block-commit: expose new job properties John Snow
2018-09-04 17:09 ` [Qemu-devel] [PATCH v4 13/15] qapi/block-mirror: " John Snow
2018-09-04 17:09 ` [Qemu-devel] [PATCH v4 14/15] qapi/block-stream: " John Snow
2018-09-04 17:09 ` [Qemu-devel] [PATCH v4 15/15] block/backup: qapi documentation fixup John Snow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180904170930.28619-5-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=jcody@redhat.com \
--cc=jtc@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).