block: introduce BDRV_REQ_MAY_UNMAP request flag
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
aa7bfbfff7
commit
d32f35cbc5
@ -780,7 +780,8 @@ 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, 0);
|
ret = bdrv_write_zeroes(bs, addr, nr_sectors,
|
||||||
|
BDRV_REQ_MAY_UNMAP);
|
||||||
} 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);
|
||||||
|
4
block.c
4
block.c
@ -2818,6 +2818,10 @@ int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs,
|
|||||||
{
|
{
|
||||||
trace_bdrv_co_write_zeroes(bs, sector_num, nb_sectors);
|
trace_bdrv_co_write_zeroes(bs, sector_num, nb_sectors);
|
||||||
|
|
||||||
|
if (!(bs->open_flags & BDRV_O_UNMAP)) {
|
||||||
|
flags &= ~BDRV_REQ_MAY_UNMAP;
|
||||||
|
}
|
||||||
|
|
||||||
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 | flags);
|
BDRV_REQ_ZERO_WRITE | flags);
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ 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,
|
start * BACKUP_SECTORS_PER_CLUSTER,
|
||||||
n, 0);
|
n, BDRV_REQ_MAY_UNMAP);
|
||||||
} 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,
|
||||||
|
@ -65,6 +65,13 @@ typedef struct BlockDevOps {
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
BDRV_REQ_COPY_ON_READ = 0x1,
|
BDRV_REQ_COPY_ON_READ = 0x1,
|
||||||
BDRV_REQ_ZERO_WRITE = 0x2,
|
BDRV_REQ_ZERO_WRITE = 0x2,
|
||||||
|
/* The BDRV_REQ_MAY_UNMAP flag is used to indicate that the block driver
|
||||||
|
* is allowed to optimize a write zeroes request by unmapping (discarding)
|
||||||
|
* blocks if it is guaranteed that the result will read back as
|
||||||
|
* zeroes. The flag is only passed to the driver if the block device is
|
||||||
|
* opened with BDRV_O_UNMAP.
|
||||||
|
*/
|
||||||
|
BDRV_REQ_MAY_UNMAP = 0x4,
|
||||||
} BdrvRequestFlags;
|
} BdrvRequestFlags;
|
||||||
|
|
||||||
#define BDRV_O_RDWR 0x0002
|
#define BDRV_O_RDWR 0x0002
|
||||||
|
Loading…
Reference in New Issue
Block a user