From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54673) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zpfir-0007G2-Gg for qemu-devel@nongnu.org; Fri, 23 Oct 2015 13:01:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zpfiq-0006ce-K4 for qemu-devel@nongnu.org; Fri, 23 Oct 2015 13:01:45 -0400 From: Kevin Wolf Date: Fri, 23 Oct 2015 19:00:53 +0200 Message-Id: <1445619684-18216-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1445619684-18216-1-git-send-email-kwolf@redhat.com> References: <1445619684-18216-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 06/37] block: Add blk_is_available() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Max Reitz blk_is_available() returns true iff the BDS is inserted (which means blk_bs() is not NULL and bdrv_is_inserted() returns true) and if the tray of the guest device is closed. blk_is_inserted() is changed to return true only if blk_bs() is not NULL. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/block-backend.c | 7 ++++++- include/sysemu/block-backend.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/block/block-backend.c b/block/block-backend.c index 1db002c..74642dc 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -771,7 +771,12 @@ void blk_invalidate_cache(BlockBackend *blk, Error **errp) bool blk_is_inserted(BlockBackend *blk) { - return bdrv_is_inserted(blk->bs); + return blk->bs && bdrv_is_inserted(blk->bs); +} + +bool blk_is_available(BlockBackend *blk) +{ + return blk_is_inserted(blk) && !blk_dev_is_tray_open(blk); } void blk_lock_medium(BlockBackend *blk, bool locked) diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 8f2bf10..1e19d1b 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -131,6 +131,7 @@ int blk_enable_write_cache(BlockBackend *blk); void blk_set_enable_write_cache(BlockBackend *blk, bool wce); void blk_invalidate_cache(BlockBackend *blk, Error **errp); bool blk_is_inserted(BlockBackend *blk); +bool blk_is_available(BlockBackend *blk); void blk_lock_medium(BlockBackend *blk, bool locked); void blk_eject(BlockBackend *blk, bool eject_flag); int blk_get_flags(BlockBackend *blk); -- 1.8.3.1