From: lu zhipeng <luzhip...@cestc.cn> we can unmap(discard) blocks for block devices of supporting discard zeros or regular file.
Signed-off-by: lu zhipeng <luzhip...@cestc.cn> --- block/file-posix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/file-posix.c b/block/file-posix.c index 48cd096624..c35dbc0d88 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -799,7 +799,8 @@ static int raw_open_common(BlockDriverState *bs, QDict *options, #endif s->needs_alignment = raw_needs_alignment(bs); - bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK; + bs->supported_zero_flags = s->discard_zeroes ? + BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK : 0; if (S_ISREG(st.st_mode)) { /* When extending regular files, we get zeros from the OS */ bs->supported_truncate_flags = BDRV_REQ_ZERO_WRITE; -- 2.31.1