mirror of https://gitee.com/openkylin/qemu.git
block: Switch bdrv_co_get_block_status_above() to byte-based
We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert another internal type (no semantic change), and rename it to match the corresponding public function rename. Signed-off-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
7ddb99b9dc
commit
5b648c67e3
60
block/io.c
60
block/io.c
|
@ -1976,33 +1976,26 @@ early_out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t coroutine_fn bdrv_co_get_block_status_above(BlockDriverState *bs,
|
static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs,
|
||||||
BlockDriverState *base,
|
BlockDriverState *base,
|
||||||
bool want_zero,
|
bool want_zero,
|
||||||
int64_t sector_num,
|
int64_t offset,
|
||||||
int nb_sectors,
|
int64_t bytes,
|
||||||
int *pnum,
|
int64_t *pnum,
|
||||||
|
int64_t *map,
|
||||||
BlockDriverState **file)
|
BlockDriverState **file)
|
||||||
{
|
{
|
||||||
BlockDriverState *p;
|
BlockDriverState *p;
|
||||||
int64_t ret = 0;
|
int ret = 0;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
int64_t map = 0;
|
|
||||||
|
|
||||||
assert(bs != base);
|
assert(bs != base);
|
||||||
for (p = bs; p != base; p = backing_bs(p)) {
|
for (p = bs; p != base; p = backing_bs(p)) {
|
||||||
int64_t count;
|
ret = bdrv_co_block_status(p, want_zero, offset, bytes, pnum, map,
|
||||||
|
file);
|
||||||
ret = bdrv_co_block_status(p, want_zero,
|
|
||||||
sector_num * BDRV_SECTOR_SIZE,
|
|
||||||
nb_sectors * BDRV_SECTOR_SIZE, &count,
|
|
||||||
&map, file);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
assert(QEMU_IS_ALIGNED(count | map, BDRV_SECTOR_SIZE));
|
|
||||||
ret |= map;
|
|
||||||
*pnum = count >> BDRV_SECTOR_BITS;
|
|
||||||
if (ret & BDRV_BLOCK_ZERO && ret & BDRV_BLOCK_EOF && !first) {
|
if (ret & BDRV_BLOCK_ZERO && ret & BDRV_BLOCK_EOF && !first) {
|
||||||
/*
|
/*
|
||||||
* Reading beyond the end of the file continues to read
|
* Reading beyond the end of the file continues to read
|
||||||
|
@ -2010,47 +2003,35 @@ static int64_t coroutine_fn bdrv_co_get_block_status_above(BlockDriverState *bs,
|
||||||
* unallocated length we learned from an earlier
|
* unallocated length we learned from an earlier
|
||||||
* iteration.
|
* iteration.
|
||||||
*/
|
*/
|
||||||
*pnum = nb_sectors;
|
*pnum = bytes;
|
||||||
}
|
}
|
||||||
if (ret & (BDRV_BLOCK_ZERO | BDRV_BLOCK_DATA)) {
|
if (ret & (BDRV_BLOCK_ZERO | BDRV_BLOCK_DATA)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* [sector_num, pnum] unallocated on this layer, which could be only
|
/* [offset, pnum] unallocated on this layer, which could be only
|
||||||
* the first part of [sector_num, nb_sectors]. */
|
* the first part of [offset, bytes]. */
|
||||||
nb_sectors = MIN(nb_sectors, *pnum);
|
bytes = MIN(bytes, *pnum);
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Coroutine wrapper for bdrv_get_block_status_above() */
|
/* Coroutine wrapper for bdrv_get_block_status_above() */
|
||||||
static void coroutine_fn bdrv_get_block_status_above_co_entry(void *opaque)
|
static void coroutine_fn bdrv_block_status_above_co_entry(void *opaque)
|
||||||
{
|
{
|
||||||
BdrvCoBlockStatusData *data = opaque;
|
BdrvCoBlockStatusData *data = opaque;
|
||||||
int n = 0;
|
|
||||||
int64_t ret;
|
|
||||||
|
|
||||||
ret = bdrv_co_get_block_status_above(data->bs, data->base,
|
data->ret = bdrv_co_block_status_above(data->bs, data->base,
|
||||||
data->want_zero,
|
data->want_zero,
|
||||||
data->offset >> BDRV_SECTOR_BITS,
|
data->offset, data->bytes,
|
||||||
data->bytes >> BDRV_SECTOR_BITS,
|
data->pnum, data->map, data->file);
|
||||||
&n,
|
|
||||||
data->file);
|
|
||||||
if (ret < 0) {
|
|
||||||
assert(INT_MIN <= ret);
|
|
||||||
data->ret = ret;
|
|
||||||
} else {
|
|
||||||
*data->pnum = n * BDRV_SECTOR_SIZE;
|
|
||||||
*data->map = ret & BDRV_BLOCK_OFFSET_MASK;
|
|
||||||
data->ret = ret & ~BDRV_BLOCK_OFFSET_MASK;
|
|
||||||
}
|
|
||||||
data->done = true;
|
data->done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Synchronous wrapper around bdrv_co_get_block_status_above().
|
* Synchronous wrapper around bdrv_co_block_status_above().
|
||||||
*
|
*
|
||||||
* See bdrv_co_get_block_status_above() for details.
|
* See bdrv_co_block_status_above() for details.
|
||||||
*/
|
*/
|
||||||
static int bdrv_common_block_status_above(BlockDriverState *bs,
|
static int bdrv_common_block_status_above(BlockDriverState *bs,
|
||||||
BlockDriverState *base,
|
BlockDriverState *base,
|
||||||
|
@ -2074,10 +2055,9 @@ static int bdrv_common_block_status_above(BlockDriverState *bs,
|
||||||
|
|
||||||
if (qemu_in_coroutine()) {
|
if (qemu_in_coroutine()) {
|
||||||
/* Fast-path if already in coroutine context */
|
/* Fast-path if already in coroutine context */
|
||||||
bdrv_get_block_status_above_co_entry(&data);
|
bdrv_block_status_above_co_entry(&data);
|
||||||
} else {
|
} else {
|
||||||
co = qemu_coroutine_create(bdrv_get_block_status_above_co_entry,
|
co = qemu_coroutine_create(bdrv_block_status_above_co_entry, &data);
|
||||||
&data);
|
|
||||||
bdrv_coroutine_enter(bs, co);
|
bdrv_coroutine_enter(bs, co);
|
||||||
BDRV_POLL_WHILE(bs, !data.done);
|
BDRV_POLL_WHILE(bs, !data.done);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue