Commit 2ec711dc authored by Peter Lieven's avatar Peter Lieven Committed by Max Reitz
Browse files

block/vpc: optimize vpc_co_get_block_status



*pnum can't be greater than s->block_size / BDRV_SECTOR_SIZE for allocated
sectors since there is always a bitmap in between.

Signed-off-by: default avatarPeter Lieven <pl@kamp.de>
Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
Message-id: 1425379316-19639-2-git-send-email-pl@kamp.de
Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
parent d51a2427
Loading
Loading
Loading
Loading
+8 −10
Original line number Diff line number Diff line
@@ -602,7 +602,7 @@ static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs,
{
    BDRVVPCState *s = bs->opaque;
    VHDFooter *footer = (VHDFooter*) s->footer_buf;
    int64_t start, offset, next;
    int64_t start, offset;
    bool allocated;
    int n;

@@ -626,21 +626,19 @@ static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs,
        *pnum += n;
        sector_num += n;
        nb_sectors -= n;
        next = start + (*pnum * BDRV_SECTOR_SIZE);

        /* *pnum can't be greater than one block for allocated
         * sectors since there is always a bitmap in between. */
        if (allocated) {
            return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
        }
        if (nb_sectors == 0) {
            break;
        }

        offset = get_sector_offset(bs, sector_num, 0);
    } while ((allocated && offset == next) || (!allocated && offset == -1));
    } while (offset == -1);

    if (allocated) {
        return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
    } else {
    return 0;
}
}

/*
 * Calculates the number of cylinders, heads and sectors per cylinder