diff options
author | Fam Zheng <famz@redhat.com> | 2017-08-23 21:42:39 +0800 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2017-08-23 10:21:55 -0500 |
commit | c16de8f59a2bcbe2dc037524cc648de896f581a4 (patch) | |
tree | 2089fa4f973580849ce51396695d61dd1bf5be66 | |
parent | 3da2bd8c4a80178fb115c70b858cecbfb1eb1067 (diff) | |
download | qemu-c16de8f59a2bcbe2dc037524cc648de896f581a4.zip qemu-c16de8f59a2bcbe2dc037524cc648de896f581a4.tar.gz qemu-c16de8f59a2bcbe2dc037524cc648de896f581a4.tar.bz2 |
block-backend: Refactor inactivate check
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>
-rw-r--r-- | block/block-backend.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/block/block-backend.c b/block/block-backend.c index e9798e8..a3984d2 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; } |