Commit 617ccb46 authored by Paolo Bonzini's avatar Paolo Bonzini Committed by Stefan Hajnoczi
Browse files

block: do not use ->total_sectors in bdrv_co_is_allocated



This is more robust when the device has removable media.

Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
parent bdad13b9
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -3065,9 +3065,15 @@ static int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs,
                                             int64_t sector_num,
                                             int nb_sectors, int *pnum)
{
    int64_t length;
    int64_t n;

    if (sector_num >= bs->total_sectors) {
    length = bdrv_getlength(bs);
    if (length < 0) {
        return length;
    }

    if (sector_num >= (length >> BDRV_SECTOR_BITS)) {
        *pnum = 0;
        return 0;
    }