Skip to content

Commit

Permalink
block/vpc: optimize vpc_co_get_block_status
Browse files Browse the repository at this point in the history
*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: Peter Lieven <[email protected]>
Reviewed-by: Max Reitz <[email protected]>
Message-id: [email protected]
Signed-off-by: Max Reitz <[email protected]>
  • Loading branch information
plieven authored and XanClic committed Mar 16, 2015
1 parent d51a242 commit 2ec711d
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions block/vpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -626,20 +626,18 @@ 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;
}
return 0;
}

/*
Expand Down

0 comments on commit 2ec711d

Please sign in to comment.