summaryrefslogtreecommitdiff
path: root/block/block-backend.c
diff options
context:
space:
mode:
Diffstat (limited to 'block/block-backend.c')
-rw-r--r--block/block-backend.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/block/block-backend.c b/block/block-backend.c
index e9798e897d..1031742401 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -70,6 +70,7 @@ struct BlockBackend {
int quiesce_counter;
VMChangeStateEntry *vmsh;
+ bool force_allow_inactivate;
};
typedef struct BlockBackendAIOCB {
@@ -192,6 +193,30 @@ static void blk_root_activate(BdrvChild *child, Error **errp)
}
}
+void blk_set_force_allow_inactivate(BlockBackend *blk)
+{
+ blk->force_allow_inactivate = true;
+}
+
+static bool blk_can_inactivate(BlockBackend *blk)
+{
+ /* If it is a guest device, inactivate is ok. */
+ if (blk->dev || blk_name(blk)[0]) {
+ return true;
+ }
+
+ /* Inactivating means no more writes to the image can be done,
+ * even if those writes would be changes invisible to the
+ * guest. For block job BBs that satisfy this, we can just allow
+ * it. This is the case for mirror job source, which is required
+ * by libvirt non-shared block migration. */
+ if (!(blk->perm & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED))) {
+ return true;
+ }
+
+ return blk->force_allow_inactivate;
+}
+
static int blk_root_inactivate(BdrvChild *child)
{
BlockBackend *blk = child->opaque;
@@ -200,11 +225,7 @@ static int blk_root_inactivate(BdrvChild *child)
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(blk)[0]) {
+ if (!blk_can_inactivate(blk)) {
return -EPERM;
}