Commit c16de8f5 authored by Fam Zheng's avatar Fam Zheng Committed by Eric Blake
Browse files

block-backend: Refactor inactivate check



The logic will be fixed (extended), move it to a separate function.

Signed-off-by: default avatarFam Zheng <famz@redhat.com>
Message-Id: <20170823134242.12080-2-famz@redhat.com>
Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: default avatarEric Blake <eblake@redhat.com>
parent 3da2bd8c
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -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;
    }