From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGC5r-0005wG-Fc for qemu-devel@nongnu.org; Tue, 27 Jan 2015 14:46:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGC5q-00024a-Ch for qemu-devel@nongnu.org; Tue, 27 Jan 2015 14:46:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48184) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGC5q-00024P-4Y for qemu-devel@nongnu.org; Tue, 27 Jan 2015 14:46: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 t0RJkXtH011148 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 27 Jan 2015 14:46:33 -0500 From: Max Reitz Date: Tue, 27 Jan 2015 14:45:39 -0500 Message-Id: <1422387983-32153-7-git-send-email-mreitz@redhat.com> In-Reply-To: <1422387983-32153-1-git-send-email-mreitz@redhat.com> References: <1422387983-32153-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH RESEND 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 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 --- 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