From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFm8Y-0005PJ-IM for qemu-devel@nongnu.org; Mon, 26 Jan 2015 11:03:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YFm8U-00055F-GR for qemu-devel@nongnu.org; Mon, 26 Jan 2015 11:03:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45771) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFm8U-00054y-7Z for qemu-devel@nongnu.org; Mon, 26 Jan 2015 11:03:34 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0QG3WXE031587 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 26 Jan 2015 11:03:33 -0500 From: Max Reitz Date: Mon, 26 Jan 2015 11:02:40 -0500 Message-Id: <1422288204-29271-7-git-send-email-mreitz@redhat.com> In-Reply-To: <1422288204-29271-1-git-send-email-mreitz@redhat.com> References: <1422288204-29271-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH 06/50] block: Add blk_is_available() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , Jeff Cody , Markus Armbruster , Max Reitz , Stefan Hajnoczi , john@redhat.com 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 --- 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 4c40747..4a2428e 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -738,7 +738,12 @@ void blk_invalidate_cache(BlockBackend *blk, Error **errp) int 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 f39bb5c..f91f3c7 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -127,6 +127,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); int 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.1.0