mirror of https://github.com/xemu-project/xemu.git
block: Use BdrvChild to discard
Other I/O functions are already using a BdrvChild pointer in the API, so make discard do the same. It makes it possible to initiate the same permission checks before doing I/O, and much easier to share the helper functions for this, which will be added and used by write, truncate and copy range paths. Signed-off-by: Fam Zheng <famz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
ecc983a507
commit
0b9fd3f467
|
@ -625,7 +625,7 @@ static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs,
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bdrv_co_pdiscard(bs->file->bs, offset, bytes);
|
return bdrv_co_pdiscard(bs->file, offset, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int coroutine_fn blkdebug_co_block_status(BlockDriverState *bs,
|
static int coroutine_fn blkdebug_co_block_status(BlockDriverState *bs,
|
||||||
|
|
|
@ -486,7 +486,7 @@ static int coroutine_fn blk_log_writes_co_do_file_flush(BlkLogWritesFileReq *fr)
|
||||||
static int coroutine_fn
|
static int coroutine_fn
|
||||||
blk_log_writes_co_do_file_pdiscard(BlkLogWritesFileReq *fr)
|
blk_log_writes_co_do_file_pdiscard(BlkLogWritesFileReq *fr)
|
||||||
{
|
{
|
||||||
return bdrv_co_pdiscard(fr->bs->file->bs, fr->offset, fr->bytes);
|
return bdrv_co_pdiscard(fr->bs->file, fr->offset, fr->bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int coroutine_fn
|
static int coroutine_fn
|
||||||
|
|
|
@ -113,7 +113,7 @@ static int coroutine_fn blkreplay_co_pdiscard(BlockDriverState *bs,
|
||||||
int64_t offset, int bytes)
|
int64_t offset, int bytes)
|
||||||
{
|
{
|
||||||
uint64_t reqid = blkreplay_next_id();
|
uint64_t reqid = blkreplay_next_id();
|
||||||
int ret = bdrv_co_pdiscard(bs->file->bs, offset, bytes);
|
int ret = bdrv_co_pdiscard(bs->file, offset, bytes);
|
||||||
block_request_create(reqid, bs, qemu_coroutine_self());
|
block_request_create(reqid, bs, qemu_coroutine_self());
|
||||||
qemu_coroutine_yield();
|
qemu_coroutine_yield();
|
||||||
|
|
||||||
|
|
|
@ -1560,7 +1560,7 @@ int blk_co_pdiscard(BlockBackend *blk, int64_t offset, int bytes)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bdrv_co_pdiscard(blk_bs(blk), offset, bytes);
|
return bdrv_co_pdiscard(blk->root, offset, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
int blk_co_flush(BlockBackend *blk)
|
int blk_co_flush(BlockBackend *blk)
|
||||||
|
|
|
@ -116,7 +116,7 @@ static int coroutine_fn cor_co_pwrite_zeroes(BlockDriverState *bs,
|
||||||
static int coroutine_fn cor_co_pdiscard(BlockDriverState *bs,
|
static int coroutine_fn cor_co_pdiscard(BlockDriverState *bs,
|
||||||
int64_t offset, int bytes)
|
int64_t offset, int bytes)
|
||||||
{
|
{
|
||||||
return bdrv_co_pdiscard(bs->file->bs, offset, bytes);
|
return bdrv_co_pdiscard(bs->file, offset, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
18
block/io.c
18
block/io.c
|
@ -2633,7 +2633,7 @@ int bdrv_flush(BlockDriverState *bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct DiscardCo {
|
typedef struct DiscardCo {
|
||||||
BlockDriverState *bs;
|
BdrvChild *child;
|
||||||
int64_t offset;
|
int64_t offset;
|
||||||
int bytes;
|
int bytes;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -2642,17 +2642,17 @@ static void coroutine_fn bdrv_pdiscard_co_entry(void *opaque)
|
||||||
{
|
{
|
||||||
DiscardCo *rwco = opaque;
|
DiscardCo *rwco = opaque;
|
||||||
|
|
||||||
rwco->ret = bdrv_co_pdiscard(rwco->bs, rwco->offset, rwco->bytes);
|
rwco->ret = bdrv_co_pdiscard(rwco->child, rwco->offset, rwco->bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset,
|
int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int bytes)
|
||||||
int bytes)
|
|
||||||
{
|
{
|
||||||
BdrvTrackedRequest req;
|
BdrvTrackedRequest req;
|
||||||
int max_pdiscard, ret;
|
int max_pdiscard, ret;
|
||||||
int head, tail, align;
|
int head, tail, align;
|
||||||
|
BlockDriverState *bs = child->bs;
|
||||||
|
|
||||||
if (!bs->drv) {
|
if (!bs || !bs->drv) {
|
||||||
return -ENOMEDIUM;
|
return -ENOMEDIUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2763,11 +2763,11 @@ out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
|
int bdrv_pdiscard(BdrvChild *child, int64_t offset, int bytes)
|
||||||
{
|
{
|
||||||
Coroutine *co;
|
Coroutine *co;
|
||||||
DiscardCo rwco = {
|
DiscardCo rwco = {
|
||||||
.bs = bs,
|
.child = child,
|
||||||
.offset = offset,
|
.offset = offset,
|
||||||
.bytes = bytes,
|
.bytes = bytes,
|
||||||
.ret = NOT_DONE,
|
.ret = NOT_DONE,
|
||||||
|
@ -2778,8 +2778,8 @@ int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
|
||||||
bdrv_pdiscard_co_entry(&rwco);
|
bdrv_pdiscard_co_entry(&rwco);
|
||||||
} else {
|
} else {
|
||||||
co = qemu_coroutine_create(bdrv_pdiscard_co_entry, &rwco);
|
co = qemu_coroutine_create(bdrv_pdiscard_co_entry, &rwco);
|
||||||
bdrv_coroutine_enter(bs, co);
|
bdrv_coroutine_enter(child->bs, co);
|
||||||
BDRV_POLL_WHILE(bs, rwco.ret == NOT_DONE);
|
BDRV_POLL_WHILE(child->bs, rwco.ret == NOT_DONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rwco.ret;
|
return rwco.ret;
|
||||||
|
|
|
@ -1333,7 +1333,7 @@ static int coroutine_fn bdrv_mirror_top_do_write(BlockDriverState *bs,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MIRROR_METHOD_DISCARD:
|
case MIRROR_METHOD_DISCARD:
|
||||||
ret = bdrv_co_pdiscard(bs->backing->bs, offset, bytes);
|
ret = bdrv_co_pdiscard(bs->backing, offset, bytes);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -734,7 +734,7 @@ void qcow2_process_discards(BlockDriverState *bs, int ret)
|
||||||
|
|
||||||
/* Discard is optional, ignore the return value */
|
/* Discard is optional, ignore the return value */
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
bdrv_pdiscard(bs->file->bs, d->offset, d->bytes);
|
bdrv_pdiscard(bs->file, d->offset, d->bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(d);
|
g_free(d);
|
||||||
|
|
|
@ -297,7 +297,7 @@ static int coroutine_fn raw_co_pdiscard(BlockDriverState *bs,
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
return bdrv_co_pdiscard(bs->file->bs, offset, bytes);
|
return bdrv_co_pdiscard(bs->file, offset, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t raw_getlength(BlockDriverState *bs)
|
static int64_t raw_getlength(BlockDriverState *bs)
|
||||||
|
|
|
@ -149,7 +149,7 @@ static int coroutine_fn throttle_co_pdiscard(BlockDriverState *bs,
|
||||||
ThrottleGroupMember *tgm = bs->opaque;
|
ThrottleGroupMember *tgm = bs->opaque;
|
||||||
throttle_group_co_io_limits_intercept(tgm, bytes, true);
|
throttle_group_co_io_limits_intercept(tgm, bytes, true);
|
||||||
|
|
||||||
return bdrv_co_pdiscard(bs->file->bs, offset, bytes);
|
return bdrv_co_pdiscard(bs->file, offset, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int throttle_co_flush(BlockDriverState *bs)
|
static int throttle_co_flush(BlockDriverState *bs)
|
||||||
|
|
|
@ -418,8 +418,8 @@ AioWait *bdrv_get_aio_wait(BlockDriverState *bs);
|
||||||
bdrv_get_aio_context(bs_), \
|
bdrv_get_aio_context(bs_), \
|
||||||
cond); })
|
cond); })
|
||||||
|
|
||||||
int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int bytes);
|
int bdrv_pdiscard(BdrvChild *child, int64_t offset, int bytes);
|
||||||
int bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes);
|
int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int bytes);
|
||||||
int bdrv_has_zero_init_1(BlockDriverState *bs);
|
int bdrv_has_zero_init_1(BlockDriverState *bs);
|
||||||
int bdrv_has_zero_init(BlockDriverState *bs);
|
int bdrv_has_zero_init(BlockDriverState *bs);
|
||||||
bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs);
|
bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs);
|
||||||
|
|
Loading…
Reference in New Issue