From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0Eae-0008RQ-CA for qemu-devel@nongnu.org; Wed, 03 Jun 2015 15:44:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z0Ead-0000Pn-FL for qemu-devel@nongnu.org; Wed, 03 Jun 2015 15:44:40 -0400 From: Max Reitz Date: Wed, 3 Jun 2015 21:43:46 +0200 Message-Id: <1433360659-1915-6-git-send-email-mreitz@redhat.com> In-Reply-To: <1433360659-1915-1-git-send-email-mreitz@redhat.com> References: <1433360659-1915-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v3 05/38] block: Add blk_is_available() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: Kevin Wolf , qemu-devel@nongnu.org, Markus Armbruster , Stefan Hajnoczi , Max Reitz , John Snow 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 --- 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 29baab2..d034c78 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -749,7 +749,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 189e72b..525b323 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -130,6 +130,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); -- 2.4.1