From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com, mreitz@redhat.com,
qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/6] block: New BdrvChildRole.activate() for blk_resume_after_migration()
Date: Thu, 4 May 2017 18:52:37 +0200 [thread overview]
Message-ID: <1493916761-32319-3-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1493916761-32319-1-git-send-email-kwolf@redhat.com>
Instead of manually calling blk_resume_after_migration() in migration
code after doing bdrv_invalidate_cache_all(), integrate the BlockBackend
activation with cache invalidation into a single function. This is
achieved with a new callback in BdrvChildRole that is called by
bdrv_invalidate_cache_all().
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 12 +++++++++-
block/block-backend.c | 56 +++++++++++++++++++++++------------------------
include/block/block.h | 2 --
include/block/block_int.h | 5 +++++
migration/migration.c | 3 ---
migration/savevm.c | 3 ---
qmp.c | 6 -----
7 files changed, 44 insertions(+), 43 deletions(-)
diff --git a/block.c b/block.c
index 70ca7b4..3e7f124 100644
--- a/block.c
+++ b/block.c
@@ -3958,7 +3958,7 @@ void bdrv_init_with_whitelist(void)
void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
{
- BdrvChild *child;
+ BdrvChild *child, *parent;
Error *local_err = NULL;
int ret;
@@ -3994,6 +3994,16 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
error_setg_errno(errp, -ret, "Could not refresh total sector count");
return;
}
+
+ QLIST_FOREACH(parent, &bs->parents, next_parent) {
+ if (parent->role->activate) {
+ parent->role->activate(parent, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+ }
+ }
}
void bdrv_invalidate_cache_all(Error **errp)
diff --git a/block/block-backend.c b/block/block-backend.c
index f5bf13e..a7ce72b 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -130,6 +130,32 @@ static const char *blk_root_get_name(BdrvChild *child)
return blk_name(child->opaque);
}
+/*
+ * Notifies the user of the BlockBackend that migration has completed. qdev
+ * devices can tighten their permissions in response (specifically revoke
+ * shared write permissions that we needed for storage migration).
+ *
+ * If an error is returned, the VM cannot be allowed to be resumed.
+ */
+static void blk_root_activate(BdrvChild *child, Error **errp)
+{
+ BlockBackend *blk = child->opaque;
+ Error *local_err = NULL;
+
+ if (!blk->disable_perm) {
+ return;
+ }
+
+ blk->disable_perm = false;
+
+ blk_set_perm(blk, blk->perm, blk->shared_perm, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ blk->disable_perm = true;
+ return;
+ }
+}
+
static const BdrvChildRole child_root = {
.inherit_options = blk_root_inherit_options,
@@ -140,6 +166,8 @@ static const BdrvChildRole child_root = {
.drained_begin = blk_root_drained_begin,
.drained_end = blk_root_drained_end,
+
+ .activate = blk_root_activate,
};
/*
@@ -601,34 +629,6 @@ void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm)
*shared_perm = blk->shared_perm;
}
-/*
- * Notifies the user of all BlockBackends that migration has completed. qdev
- * devices can tighten their permissions in response (specifically revoke
- * shared write permissions that we needed for storage migration).
- *
- * If an error is returned, the VM cannot be allowed to be resumed.
- */
-void blk_resume_after_migration(Error **errp)
-{
- BlockBackend *blk;
- Error *local_err = NULL;
-
- for (blk = blk_all_next(NULL); blk; blk = blk_all_next(blk)) {
- if (!blk->disable_perm) {
- continue;
- }
-
- blk->disable_perm = false;
-
- blk_set_perm(blk, blk->perm, blk->shared_perm, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- blk->disable_perm = true;
- return;
- }
- }
-}
-
static int blk_do_attach_dev(BlockBackend *blk, void *dev)
{
if (blk->dev) {
diff --git a/include/block/block.h b/include/block/block.h
index 877fbb0..80d51d8 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -369,8 +369,6 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp);
void bdrv_invalidate_cache_all(Error **errp);
int bdrv_inactivate_all(void);
-void blk_resume_after_migration(Error **errp);
-
/* Ensure contents are flushed to disk. */
int bdrv_flush(BlockDriverState *bs);
int coroutine_fn bdrv_co_flush(BlockDriverState *bs);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 1b4d08e..5637925 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -473,6 +473,11 @@ struct BdrvChildRole {
void (*drained_begin)(BdrvChild *child);
void (*drained_end)(BdrvChild *child);
+ /* Notifies the parent that the child has been activated (e.g. when
+ * migration is completing) and it can start requesting permissions and
+ * doing I/O on it. */
+ void (*activate)(BdrvChild *child, Error **errp);
+
void (*attach)(BdrvChild *child);
void (*detach)(BdrvChild *child);
};
diff --git a/migration/migration.c b/migration/migration.c
index 7cb0af2..0d230f4 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -341,9 +341,6 @@ static void process_incoming_migration_bh(void *opaque)
/* Make sure all file formats flush their mutable metadata.
* If we get an error here, just don't restart the VM yet. */
bdrv_invalidate_cache_all(&local_err);
- if (!local_err) {
- blk_resume_after_migration(&local_err);
- }
if (local_err) {
error_report_err(local_err);
local_err = NULL;
diff --git a/migration/savevm.c b/migration/savevm.c
index 0004f43..5689615 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1619,9 +1619,6 @@ static void loadvm_postcopy_handle_run_bh(void *opaque)
/* Make sure all file formats flush their mutable metadata.
* If we get an error here, just don't restart the VM yet. */
bdrv_invalidate_cache_all(&local_err);
- if (!local_err) {
- blk_resume_after_migration(&local_err);
- }
if (local_err) {
error_report_err(local_err);
local_err = NULL;
diff --git a/qmp.c b/qmp.c
index 25b5050..f656940 100644
--- a/qmp.c
+++ b/qmp.c
@@ -207,12 +207,6 @@ void qmp_cont(Error **errp)
return;
}
- blk_resume_after_migration(&local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- return;
- }
-
if (runstate_check(RUN_STATE_INMIGRATE)) {
autostart = 1;
} else {
--
1.8.3.1
next prev parent reply other threads:[~2017-05-04 16:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-04 16:52 [Qemu-devel] [PATCH 0/6] block: Fix op blockers for inactive images Kevin Wolf
2017-05-04 16:52 ` [Qemu-devel] [PATCH 1/6] migration: Unify block node activation error handling Kevin Wolf
2017-05-04 17:12 ` Eric Blake
2017-05-04 16:52 ` Kevin Wolf [this message]
2017-05-04 17:19 ` [Qemu-devel] [PATCH 2/6] block: New BdrvChildRole.activate() for blk_resume_after_migration() Eric Blake
2017-05-04 16:52 ` [Qemu-devel] [PATCH 3/6] block: Drop permissions when migration completes Kevin Wolf
2017-05-04 17:21 ` Eric Blake
2017-05-04 16:52 ` [Qemu-devel] [PATCH 4/6] block: Inactivate parents before children Kevin Wolf
2017-05-04 17:23 ` Eric Blake
2017-05-04 16:52 ` [Qemu-devel] [PATCH 5/6] block: Fix write/resize permissions for inactive images Kevin Wolf
2017-05-04 17:42 ` Eric Blake
2017-08-18 10:06 ` Xie Changlong
2017-08-18 12:04 ` Fam Zheng
2017-05-04 16:52 ` [Qemu-devel] [PATCH 6/6] file-posix: Remove .bdrv_inactivate/invalidate_cache Kevin Wolf
2017-05-04 17:46 ` Eric Blake
2017-05-09 14:54 ` [Qemu-devel] [PATCH 0/6] block: Fix op blockers for inactive images Kevin Wolf
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=1493916761-32319-3-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=famz@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).