From 8f3a73bc57ea83e5b3930d14fc596ea51859987a Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Fri, 29 Jan 2016 20:49:10 +0100 Subject: block: Add blk_dev_has_tray() Pull out the check whether a block device has a tray from blk_dev_is_tray_open() into its own function so both attributes (whether there is a tray vs. whether that tray is open) can be queried independently. Cc: qemu-stable Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia Message-id: 1454096953-31773-2-git-send-email-mreitz@redhat.com --- block/block-backend.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'block/block-backend.c') diff --git a/block/block-backend.c b/block/block-backend.c index efd61464da..a4208f18c2 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -458,6 +458,14 @@ bool blk_dev_has_removable_media(BlockBackend *blk) return !blk->dev || (blk->dev_ops && blk->dev_ops->change_media_cb); } +/* + * Does @blk's attached device model have a tray? + */ +bool blk_dev_has_tray(BlockBackend *blk) +{ + return blk->dev_ops && blk->dev_ops->is_tray_open; +} + /* * Notify @blk's attached device model of a media eject request. * If @force is true, the medium is about to be yanked out forcefully. @@ -474,7 +482,7 @@ void blk_dev_eject_request(BlockBackend *blk, bool force) */ bool blk_dev_is_tray_open(BlockBackend *blk) { - if (blk->dev_ops && blk->dev_ops->is_tray_open) { + if (blk_dev_has_tray(blk)) { return blk->dev_ops->is_tray_open(blk->dev_opaque); } return false; -- cgit v1.2.3