From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Fam Zheng <famz@redhat.com>, Kevin Wolf <kwolf@redhat.com>,
Max Reitz <mreitz@redhat.com>,
"open list:Block layer core" <qemu-block@nongnu.org>
Subject: [Qemu-devel] [PULL 5/7] block-backend: Defer shared_perm tightening migration completion
Date: Tue, 15 Aug 2017 10:09:05 -0500 [thread overview]
Message-ID: <20170815150907.21495-6-eblake@redhat.com> (raw)
In-Reply-To: <20170815150907.21495-1-eblake@redhat.com>
From: Fam Zheng <famz@redhat.com>
As in the case of nbd_export_new(), bdrv_invalidate_cache() can be
called when migration is still in progress. In this case we are not
ready to tighten the shared permissions fenced by blk->disable_perm.
Defer to a VM state change handler.
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-Id: <20170815130740.31229-4-famz@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
---
block/block-backend.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/block/block-backend.c b/block/block-backend.c
index 968438c149..e9798e897d 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -20,6 +20,7 @@
#include "qapi-event.h"
#include "qemu/id.h"
#include "trace.h"
+#include "migration/misc.h"
/* Number of coroutines to reserve per attached device model */
#define COROUTINE_POOL_RESERVATION 64
@@ -68,6 +69,7 @@ struct BlockBackend {
NotifierList remove_bs_notifiers, insert_bs_notifiers;
int quiesce_counter;
+ VMChangeStateEntry *vmsh;
};
typedef struct BlockBackendAIOCB {
@@ -129,6 +131,23 @@ static const char *blk_root_get_name(BdrvChild *child)
return blk_name(child->opaque);
}
+static void blk_vm_state_changed(void *opaque, int running, RunState state)
+{
+ Error *local_err = NULL;
+ BlockBackend *blk = opaque;
+
+ if (state == RUN_STATE_INMIGRATE) {
+ return;
+ }
+
+ qemu_del_vm_change_state_handler(blk->vmsh);
+ blk->vmsh = NULL;
+ blk_set_perm(blk, blk->perm, blk->shared_perm, &local_err);
+ if (local_err) {
+ error_report_err(local_err);
+ }
+}
+
/*
* Notifies the user of the BlockBackend that migration has completed. qdev
* devices can tighten their permissions in response (specifically revoke
@@ -147,6 +166,24 @@ static void blk_root_activate(BdrvChild *child, Error **errp)
blk->disable_perm = false;
+ blk_set_perm(blk, blk->perm, BLK_PERM_ALL, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ blk->disable_perm = true;
+ return;
+ }
+
+ if (runstate_check(RUN_STATE_INMIGRATE)) {
+ /* Activation can happen when migration process is still active, for
+ * example when nbd_server_add is called during non-shared storage
+ * migration. Defer the shared_perm update to migration completion. */
+ if (!blk->vmsh) {
+ blk->vmsh = qemu_add_vm_change_state_handler(blk_vm_state_changed,
+ blk);
+ }
+ return;
+ }
+
blk_set_perm(blk, blk->perm, blk->shared_perm, &local_err);
if (local_err) {
error_propagate(errp, local_err);
@@ -291,6 +328,10 @@ static void blk_delete(BlockBackend *blk)
if (blk->root) {
blk_remove_bs(blk);
}
+ if (blk->vmsh) {
+ qemu_del_vm_change_state_handler(blk->vmsh);
+ blk->vmsh = NULL;
+ }
assert(QLIST_EMPTY(&blk->remove_bs_notifiers.notifiers));
assert(QLIST_EMPTY(&blk->insert_bs_notifiers.notifiers));
QTAILQ_REMOVE(&block_backends, blk, link);
--
2.13.5
next prev parent reply other threads:[~2017-08-15 15:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-15 15:09 [Qemu-devel] [PULL for 2.10-rc3 0/7] NBD changes for 2.10-rc3 Eric Blake
2017-08-15 15:09 ` [Qemu-devel] [PULL 1/7] nbd: Fix trace message for disconnect Eric Blake
2017-08-15 15:09 ` [Qemu-devel] [PULL 2/7] qemu-iotests: step clock after each test iteration Eric Blake
2017-08-15 15:09 ` [Qemu-devel] [PULL 3/7] stubs: Add vm state change handler stubs Eric Blake
2017-08-15 15:09 ` [Qemu-devel] [PULL 4/7] nbd: Fix order of bdrv_set_perm and bdrv_invalidate_cache Eric Blake
2017-08-15 15:09 ` Eric Blake [this message]
2017-08-15 15:09 ` [Qemu-devel] [PULL 6/7] iotests: Add non-shared storage migration case 192 Eric Blake
2017-08-15 15:09 ` [Qemu-devel] [PULL 7/7] nbd-client: Fix regression when server sends garbage Eric Blake
2017-08-15 15:50 ` Vladimir Sementsov-Ogievskiy
2017-08-15 16:51 ` Eric Blake
2017-08-16 12:00 ` Vladimir Sementsov-Ogievskiy
2017-08-21 10:11 ` Vladimir Sementsov-Ogievskiy
2017-08-21 10:13 ` Vladimir Sementsov-Ogievskiy
2017-08-23 15:09 ` [Qemu-devel] " Vladimir Sementsov-Ogievskiy
2017-08-23 15:17 ` Eric Blake
2017-08-23 15:21 ` Vladimir Sementsov-Ogievskiy
2017-08-15 17:52 ` [Qemu-devel] [PULL for 2.10-rc3 0/7] NBD changes for 2.10-rc3 Peter Maydell
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=20170815150907.21495-6-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=famz@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).