mirror of https://github.com/xemu-project/xemu.git
block: add flags to bdrv_*_write_zeroes
Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Peter Lieven <pl@kamp.de> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
6faac15fa8
commit
aa7bfbfff7
|
@ -780,7 +780,7 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & BLK_MIG_FLAG_ZERO_BLOCK) {
|
if (flags & BLK_MIG_FLAG_ZERO_BLOCK) {
|
||||||
ret = bdrv_write_zeroes(bs, addr, nr_sectors);
|
ret = bdrv_write_zeroes(bs, addr, nr_sectors, 0);
|
||||||
} else {
|
} else {
|
||||||
buf = g_malloc(BLOCK_SIZE);
|
buf = g_malloc(BLOCK_SIZE);
|
||||||
qemu_get_buffer(f, buf, BLOCK_SIZE);
|
qemu_get_buffer(f, buf, BLOCK_SIZE);
|
||||||
|
|
20
block.c
20
block.c
|
@ -79,7 +79,7 @@ static BlockDriverAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs,
|
||||||
bool is_write);
|
bool is_write);
|
||||||
static void coroutine_fn bdrv_co_do_rw(void *opaque);
|
static void coroutine_fn bdrv_co_do_rw(void *opaque);
|
||||||
static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
|
static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
|
||||||
int64_t sector_num, int nb_sectors);
|
int64_t sector_num, int nb_sectors, BdrvRequestFlags flags);
|
||||||
|
|
||||||
static QTAILQ_HEAD(, BlockDriverState) bdrv_states =
|
static QTAILQ_HEAD(, BlockDriverState) bdrv_states =
|
||||||
QTAILQ_HEAD_INITIALIZER(bdrv_states);
|
QTAILQ_HEAD_INITIALIZER(bdrv_states);
|
||||||
|
@ -2392,10 +2392,11 @@ int bdrv_writev(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov)
|
||||||
return bdrv_rwv_co(bs, sector_num, qiov, true, 0);
|
return bdrv_rwv_co(bs, sector_num, qiov, true, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
|
int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,
|
||||||
|
int nb_sectors, BdrvRequestFlags flags)
|
||||||
{
|
{
|
||||||
return bdrv_rw_co(bs, sector_num, NULL, nb_sectors, true,
|
return bdrv_rw_co(bs, sector_num, NULL, nb_sectors, true,
|
||||||
BDRV_REQ_ZERO_WRITE);
|
BDRV_REQ_ZERO_WRITE | flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
||||||
|
@ -2577,7 +2578,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BlockDriverState *bs,
|
||||||
if (drv->bdrv_co_write_zeroes &&
|
if (drv->bdrv_co_write_zeroes &&
|
||||||
buffer_is_zero(bounce_buffer, iov.iov_len)) {
|
buffer_is_zero(bounce_buffer, iov.iov_len)) {
|
||||||
ret = bdrv_co_do_write_zeroes(bs, cluster_sector_num,
|
ret = bdrv_co_do_write_zeroes(bs, cluster_sector_num,
|
||||||
cluster_nb_sectors);
|
cluster_nb_sectors, 0);
|
||||||
} else {
|
} else {
|
||||||
/* This does not change the data on the disk, it is not necessary
|
/* This does not change the data on the disk, it is not necessary
|
||||||
* to flush even in cache=writethrough mode.
|
* to flush even in cache=writethrough mode.
|
||||||
|
@ -2711,7 +2712,7 @@ int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
|
static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
|
||||||
int64_t sector_num, int nb_sectors)
|
int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
|
||||||
{
|
{
|
||||||
BlockDriver *drv = bs->drv;
|
BlockDriver *drv = bs->drv;
|
||||||
QEMUIOVector qiov;
|
QEMUIOVector qiov;
|
||||||
|
@ -2723,7 +2724,7 @@ static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs,
|
||||||
|
|
||||||
/* First try the efficient write zeroes operation */
|
/* First try the efficient write zeroes operation */
|
||||||
if (drv->bdrv_co_write_zeroes) {
|
if (drv->bdrv_co_write_zeroes) {
|
||||||
ret = drv->bdrv_co_write_zeroes(bs, sector_num, nb_sectors);
|
ret = drv->bdrv_co_write_zeroes(bs, sector_num, nb_sectors, flags);
|
||||||
if (ret != -ENOTSUP) {
|
if (ret != -ENOTSUP) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -2778,7 +2779,7 @@ static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs,
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
/* Do nothing, write notifier decided to fail this request */
|
/* Do nothing, write notifier decided to fail this request */
|
||||||
} else if (flags & BDRV_REQ_ZERO_WRITE) {
|
} else if (flags & BDRV_REQ_ZERO_WRITE) {
|
||||||
ret = bdrv_co_do_write_zeroes(bs, sector_num, nb_sectors);
|
ret = bdrv_co_do_write_zeroes(bs, sector_num, nb_sectors, flags);
|
||||||
} else {
|
} else {
|
||||||
ret = drv->bdrv_co_writev(bs, sector_num, nb_sectors, qiov);
|
ret = drv->bdrv_co_writev(bs, sector_num, nb_sectors, qiov);
|
||||||
}
|
}
|
||||||
|
@ -2812,12 +2813,13 @@ int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
|
||||||
}
|
}
|
||||||
|
|
||||||
int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs,
|
int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs,
|
||||||
int64_t sector_num, int nb_sectors)
|
int64_t sector_num, int nb_sectors,
|
||||||
|
BdrvRequestFlags flags)
|
||||||
{
|
{
|
||||||
trace_bdrv_co_write_zeroes(bs, sector_num, nb_sectors);
|
trace_bdrv_co_write_zeroes(bs, sector_num, nb_sectors);
|
||||||
|
|
||||||
return bdrv_co_do_writev(bs, sector_num, nb_sectors, NULL,
|
return bdrv_co_do_writev(bs, sector_num, nb_sectors, NULL,
|
||||||
BDRV_REQ_ZERO_WRITE);
|
BDRV_REQ_ZERO_WRITE | flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -138,7 +138,8 @@ static int coroutine_fn backup_do_cow(BlockDriverState *bs,
|
||||||
|
|
||||||
if (buffer_is_zero(iov.iov_base, iov.iov_len)) {
|
if (buffer_is_zero(iov.iov_base, iov.iov_len)) {
|
||||||
ret = bdrv_co_write_zeroes(job->target,
|
ret = bdrv_co_write_zeroes(job->target,
|
||||||
start * BACKUP_SECTORS_PER_CLUSTER, n);
|
start * BACKUP_SECTORS_PER_CLUSTER,
|
||||||
|
n, 0);
|
||||||
} else {
|
} else {
|
||||||
ret = bdrv_co_writev(job->target,
|
ret = bdrv_co_writev(job->target,
|
||||||
start * BACKUP_SECTORS_PER_CLUSTER, n,
|
start * BACKUP_SECTORS_PER_CLUSTER, n,
|
||||||
|
|
|
@ -1613,7 +1613,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = bdrv_write_zeroes(bs->file, offset / BDRV_SECTOR_SIZE,
|
ret = bdrv_write_zeroes(bs->file, offset / BDRV_SECTOR_SIZE,
|
||||||
s->cluster_sectors);
|
s->cluster_sectors, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (!preallocated) {
|
if (!preallocated) {
|
||||||
qcow2_free_clusters(bs, offset, s->cluster_size,
|
qcow2_free_clusters(bs, offset, s->cluster_size,
|
||||||
|
|
|
@ -1696,7 +1696,7 @@ static int qcow2_make_empty(BlockDriverState *bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
static coroutine_fn int qcow2_co_write_zeroes(BlockDriverState *bs,
|
static coroutine_fn int qcow2_co_write_zeroes(BlockDriverState *bs,
|
||||||
int64_t sector_num, int nb_sectors)
|
int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
BDRVQcowState *s = bs->opaque;
|
BDRVQcowState *s = bs->opaque;
|
||||||
|
|
|
@ -1397,7 +1397,8 @@ static void coroutine_fn qed_co_write_zeroes_cb(void *opaque, int ret)
|
||||||
|
|
||||||
static int coroutine_fn bdrv_qed_co_write_zeroes(BlockDriverState *bs,
|
static int coroutine_fn bdrv_qed_co_write_zeroes(BlockDriverState *bs,
|
||||||
int64_t sector_num,
|
int64_t sector_num,
|
||||||
int nb_sectors)
|
int nb_sectors,
|
||||||
|
BdrvRequestFlags flags)
|
||||||
{
|
{
|
||||||
BlockDriverAIOCB *blockacb;
|
BlockDriverAIOCB *blockacb;
|
||||||
BDRVQEDState *s = bs->opaque;
|
BDRVQEDState *s = bs->opaque;
|
||||||
|
|
|
@ -68,9 +68,10 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int coroutine_fn raw_co_write_zeroes(BlockDriverState *bs,
|
static int coroutine_fn raw_co_write_zeroes(BlockDriverState *bs,
|
||||||
int64_t sector_num, int nb_sectors)
|
int64_t sector_num, int nb_sectors,
|
||||||
|
BdrvRequestFlags flags)
|
||||||
{
|
{
|
||||||
return bdrv_co_write_zeroes(bs->file, sector_num, nb_sectors);
|
return bdrv_co_write_zeroes(bs->file, sector_num, nb_sectors, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int coroutine_fn raw_co_discard(BlockDriverState *bs,
|
static int coroutine_fn raw_co_discard(BlockDriverState *bs,
|
||||||
|
|
|
@ -1419,7 +1419,8 @@ static coroutine_fn int vmdk_co_write(BlockDriverState *bs, int64_t sector_num,
|
||||||
|
|
||||||
static int coroutine_fn vmdk_co_write_zeroes(BlockDriverState *bs,
|
static int coroutine_fn vmdk_co_write_zeroes(BlockDriverState *bs,
|
||||||
int64_t sector_num,
|
int64_t sector_num,
|
||||||
int nb_sectors)
|
int nb_sectors,
|
||||||
|
BdrvRequestFlags flags)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
BDRVVmdkState *s = bs->opaque;
|
BDRVVmdkState *s = bs->opaque;
|
||||||
|
|
|
@ -192,7 +192,7 @@ int bdrv_read_unthrottled(BlockDriverState *bs, int64_t sector_num,
|
||||||
int bdrv_write(BlockDriverState *bs, int64_t sector_num,
|
int bdrv_write(BlockDriverState *bs, int64_t sector_num,
|
||||||
const uint8_t *buf, int nb_sectors);
|
const uint8_t *buf, int nb_sectors);
|
||||||
int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,
|
int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,
|
||||||
int nb_sectors);
|
int nb_sectors, BdrvRequestFlags flags);
|
||||||
int bdrv_writev(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov);
|
int bdrv_writev(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov);
|
||||||
int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
||||||
void *buf, int count);
|
void *buf, int count);
|
||||||
|
@ -214,7 +214,7 @@ int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
|
||||||
* because it may allocate memory for the entire region.
|
* because it may allocate memory for the entire region.
|
||||||
*/
|
*/
|
||||||
int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
|
int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
|
||||||
int nb_sectors);
|
int nb_sectors, BdrvRequestFlags flags);
|
||||||
BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
|
BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
|
||||||
const char *backing_file);
|
const char *backing_file);
|
||||||
int bdrv_get_backing_file_depth(BlockDriverState *bs);
|
int bdrv_get_backing_file_depth(BlockDriverState *bs);
|
||||||
|
|
|
@ -130,7 +130,7 @@ struct BlockDriver {
|
||||||
* instead.
|
* instead.
|
||||||
*/
|
*/
|
||||||
int coroutine_fn (*bdrv_co_write_zeroes)(BlockDriverState *bs,
|
int coroutine_fn (*bdrv_co_write_zeroes)(BlockDriverState *bs,
|
||||||
int64_t sector_num, int nb_sectors);
|
int64_t sector_num, int nb_sectors, BdrvRequestFlags flags);
|
||||||
int coroutine_fn (*bdrv_co_discard)(BlockDriverState *bs,
|
int coroutine_fn (*bdrv_co_discard)(BlockDriverState *bs,
|
||||||
int64_t sector_num, int nb_sectors);
|
int64_t sector_num, int nb_sectors);
|
||||||
int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs,
|
int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs,
|
||||||
|
|
|
@ -442,7 +442,7 @@ static void coroutine_fn co_write_zeroes_entry(void *opaque)
|
||||||
CoWriteZeroes *data = opaque;
|
CoWriteZeroes *data = opaque;
|
||||||
|
|
||||||
data->ret = bdrv_co_write_zeroes(data->bs, data->offset / BDRV_SECTOR_SIZE,
|
data->ret = bdrv_co_write_zeroes(data->bs, data->offset / BDRV_SECTOR_SIZE,
|
||||||
data->count / BDRV_SECTOR_SIZE);
|
data->count / BDRV_SECTOR_SIZE, 0);
|
||||||
data->done = true;
|
data->done = true;
|
||||||
if (data->ret < 0) {
|
if (data->ret < 0) {
|
||||||
*data->total = data->ret;
|
*data->total = data->ret;
|
||||||
|
|
Loading…
Reference in New Issue