[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 30/58] block: Drop permissions when migration complet
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 30/58] block: Drop permissions when migration completes |
Date: |
Thu, 11 May 2017 16:32:33 +0200 |
With image locking, permissions affect other qemu processes as well. We
want to be sure that the destination can run, so let's drop permissions
on the source when migration completes.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
block.c | 12 +++++++++++-
block/block-backend.c | 25 +++++++++++++++++++++++++
include/block/block_int.h | 7 ++++---
3 files changed, 40 insertions(+), 4 deletions(-)
diff --git a/block.c b/block.c
index c8e6de2..444a52e 100644
--- a/block.c
+++ b/block.c
@@ -4019,7 +4019,7 @@ void bdrv_invalidate_cache_all(Error **errp)
static int bdrv_inactivate_recurse(BlockDriverState *bs,
bool setting_flag)
{
- BdrvChild *child;
+ BdrvChild *child, *parent;
int ret;
if (!setting_flag && bs->drv->bdrv_inactivate) {
@@ -4038,6 +4038,16 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
if (setting_flag) {
bs->open_flags |= BDRV_O_INACTIVE;
+
+ QLIST_FOREACH(parent, &bs->parents, next_parent) {
+ if (parent->role->inactivate) {
+ ret = parent->role->inactivate(parent);
+ if (ret < 0) {
+ bs->open_flags &= ~BDRV_O_INACTIVE;
+ return ret;
+ }
+ }
+ }
}
return 0;
}
diff --git a/block/block-backend.c b/block/block-backend.c
index a7ce72b..f3a6008 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -156,6 +156,30 @@ static void blk_root_activate(BdrvChild *child, Error
**errp)
}
}
+static int blk_root_inactivate(BdrvChild *child)
+{
+ BlockBackend *blk = child->opaque;
+
+ if (blk->disable_perm) {
+ return 0;
+ }
+
+ /* Only inactivate BlockBackends for guest devices (which are inactive at
+ * this point because the VM is stopped) and unattached monitor-owned
+ * BlockBackends. If there is still any other user like a block job, then
+ * we simply can't inactivate the image. */
+ if (!blk->dev && !blk->name[0]) {
+ return -EPERM;
+ }
+
+ blk->disable_perm = true;
+ if (blk->root) {
+ bdrv_child_try_set_perm(blk->root, 0, BLK_PERM_ALL, &error_abort);
+ }
+
+ return 0;
+}
+
static const BdrvChildRole child_root = {
.inherit_options = blk_root_inherit_options,
@@ -168,6 +192,7 @@ static const BdrvChildRole child_root = {
.drained_end = blk_root_drained_end,
.activate = blk_root_activate,
+ .inactivate = blk_root_inactivate,
};
/*
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 5637925..5750a44 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -473,10 +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. */
+ /* Notifies the parent that the child has been activated/inactivated (e.g.
+ * when migration is completing) and it can start/stop requesting
+ * permissions and doing I/O on it. */
void (*activate)(BdrvChild *child, Error **errp);
+ int (*inactivate)(BdrvChild *child);
void (*attach)(BdrvChild *child);
void (*detach)(BdrvChild *child);
--
1.8.3.1
- [Qemu-block] [PULL 20/58] osdep: Fall back to posix lock when OFD lock is unavailable, (continued)
- [Qemu-block] [PULL 20/58] osdep: Fall back to posix lock when OFD lock is unavailable, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 22/58] qemu-iotests: Add test case 153 for image locking, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 23/58] tests: Add POSIX image locking test case 182, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 24/58] qcow2: Fix preallocation size formula, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 21/58] file-posix: Add image locking to perm operations, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 25/58] qcow2: Reuse preallocated zero clusters, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 26/58] qcow2: Discard preallocated zero clusters, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 27/58] iotests: Extend test 066, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 28/58] migration: Unify block node activation error handling, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 29/58] block: New BdrvChildRole.activate() for blk_resume_after_migration(), Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 30/58] block: Drop permissions when migration completes,
Kevin Wolf <=
- [Qemu-block] [PULL 33/58] file-posix: Remove .bdrv_inactivate/invalidate_cache, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 32/58] block: Fix write/resize permissions for inactive images, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 36/58] blockdev: use drained_begin/end for qmp_block_resize, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 31/58] block: Inactivate parents before children, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 34/58] qemu-img: wait for convert coroutines to complete, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 35/58] nvme: Implement Write Zeroes, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 38/58] qemu-io: Switch 'alloc' command to byte-based length, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 40/58] blkdebug: Sanity check block layer guarantees, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 39/58] qemu-io: Switch 'map' output to byte-based reporting, Kevin Wolf, 2017/05/11
- [Qemu-block] [PULL 37/58] qemu-io: Improve alignment checks, Kevin Wolf, 2017/05/11