diff mbox

[for-2.10,1/4] block-backend: Refactor inactivate check

Message ID 20170823134242.12080-2-famz@redhat.com
State New
Headers show

Commit Message

Fam Zheng Aug. 23, 2017, 1:42 p.m. UTC
The logic will be fixed (extended), move it to a separete function.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block/block-backend.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

Comments

Eric Blake Aug. 23, 2017, 2:33 p.m. UTC | #1
On 08/23/2017 08:42 AM, Fam Zheng wrote:
> The logic will be fixed (extended), move it to a separete function.

s/separete/separate/

[can fix on pull request]

> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  block/block-backend.c | 19 ++++++++++++++-----
>  1 file changed, 14 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/block/block-backend.c b/block/block-backend.c
index e9798e897d..a3984d2bec 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -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;
     }