]> git.proxmox.com Git - mirror_qemu.git/commitdiff
block-backend: Refactor inactivate check
authorFam Zheng <famz@redhat.com>
Wed, 23 Aug 2017 13:42:39 +0000 (21:42 +0800)
committerEric Blake <eblake@redhat.com>
Wed, 23 Aug 2017 15:21:55 +0000 (10:21 -0500)
The logic will be fixed (extended), move it to a separate function.

Signed-off-by: Fam Zheng <famz@redhat.com>
Message-Id: <20170823134242.12080-2-famz@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
block/block-backend.c

index e9798e897d365eab74b5c368d63b4391ce9828fa..a3984d2becaf32990d0baf5105402260590f96bf 100644 (file)
@@ -192,6 +192,19 @@ static void blk_root_activate(BdrvChild *child, Error **errp)
     }
 }
 
+static bool blk_can_inactivate(BlockBackend *blk)
+{
+    /* 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]) {
+        return true;
+    }
+
+    return false;
+}
+
 static int blk_root_inactivate(BdrvChild *child)
 {
     BlockBackend *blk = child->opaque;
@@ -200,11 +213,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;
     }