Skip to content

Commit

Permalink
block: Add blk_is_available()
Browse files Browse the repository at this point in the history
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 <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
XanClic authored and kevmw committed Oct 23, 2015
1 parent e031f75 commit db0284f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion block/block-backend.c
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/sysemu/block-backend.h
Expand Up @@ -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);
Expand Down

0 comments on commit db0284f

Please sign in to comment.