Message ID | 1422288204-29271-7-git-send-email-mreitz@redhat.com |
---|---|
State | New |
Headers | show |
On 01/26/2015 09:02 AM, Max Reitz wrote: > 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> > --- > block/block-backend.c | 7 ++++++- > include/sysemu/block-backend.h | 1 + > 2 files changed, 7 insertions(+), 1 deletion(-) > > +++ 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); Should we change blk_is_inserted to return bool? > +bool blk_is_available(BlockBackend *blk); Looks reasonable. Reviewed-by: Eric Blake <eblake@redhat.com>
On 2015-01-27 at 14:15, Eric Blake wrote: > On 01/26/2015 09:02 AM, Max Reitz wrote: >> 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> >> --- >> block/block-backend.c | 7 ++++++- >> include/sysemu/block-backend.h | 1 + >> 2 files changed, 7 insertions(+), 1 deletion(-) >> >> +++ 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); > Should we change blk_is_inserted to return bool? Seems like a good opportunity to. Will do. >> +bool blk_is_available(BlockBackend *blk); > Looks reasonable. > Reviewed-by: Eric Blake <eblake@redhat.com> Thank you for tackling this series! Max
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);
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> --- block/block-backend.c | 7 ++++++- include/sysemu/block-backend.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-)