From ca925f0dd4ba2b7ad8f8478b47d11e406aef193c Mon Sep 17 00:00:00 2001 From: Conghui Chen Date: Wed, 23 Jan 2019 18:05:51 +0000 Subject: [PATCH] dm: storage: change DISCARD to synchronous mode For virtio-blk, when the backend is a regular file, the discard and is implemented by fallocate(), but this function will not wait for the discard command handled by disk. So, add fdatasync to make sure the DISCARD is executed synchronously. Tracked-On: #2395 Signed-off-by: Conghui Chen Acked-by: Wang Yu --- devicemodel/hw/block_if.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/devicemodel/hw/block_if.c b/devicemodel/hw/block_if.c index 67a573e75..2a06b7ecf 100644 --- a/devicemodel/hw/block_if.c +++ b/devicemodel/hw/block_if.c @@ -313,6 +313,8 @@ blockif_process_discard(struct blockif_ctxt *bc, struct blockif_req *br) */ err = fallocate(bc->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, arg[i][0], arg[i][1]); + if (!err) + err = fdatasync(bc->fd); } if (err) { WPRINTF(("Failed to discard offset=%ld nbytes=%ld err code: %d\n",