From 55bfda3a0e077b822f57e8ed901f0cee848bc471 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Mon, 8 Jun 2020 15:01:35 +0100 Subject: [PATCH 07/17] file-posix: Support BDRV_REQ_ZERO_WRITE for truncate RH-Author: Kevin Wolf Message-id: <20200608150140.38218-7-kwolf@redhat.com> Patchwork-id: 97452 O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 06/11] file-posix: Support BDRV_REQ_ZERO_WRITE for truncate Bugzilla: 1780574 RH-Acked-by: Sergio Lopez Pascual RH-Acked-by: Eric Blake RH-Acked-by: Max Reitz For regular files, we always get BDRV_REQ_ZERO_WRITE behaviour from the OS, so we can advertise the flag and just ignore it. Signed-off-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia Reviewed-by: Max Reitz Message-Id: <20200424125448.63318-7-kwolf@redhat.com> Signed-off-by: Kevin Wolf (cherry picked from commit 2f0c6e7a650de133eccd94e9bb6cf7b2070f07f1) Signed-off-by: Kevin Wolf Signed-off-by: Danilo C. L. de Paula --- block/file-posix.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 7551e8d..adafbfa 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -674,6 +674,10 @@ static int raw_open_common(BlockDriverState *bs, QDict *options, #endif bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK; + if (S_ISREG(st.st_mode)) { + /* When extending regular files, we get zeros from the OS */ + bs->supported_truncate_flags = BDRV_REQ_ZERO_WRITE; + } ret = 0; fail: if (filename && (bdrv_flags & BDRV_O_TEMPORARY)) { -- 1.8.3.1