Skip to content

Commit ca925f0

Browse files
conghuic23wenlingz
authored andcommitted
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 <conghui.chen@intel.com> Acked-by: Wang Yu <yu1.wang@intel.com>
1 parent 4642269 commit ca925f0

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

devicemodel/hw/block_if.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ blockif_process_discard(struct blockif_ctxt *bc, struct blockif_req *br)
313313
*/
314314
err = fallocate(bc->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
315315
arg[i][0], arg[i][1]);
316+
if (!err)
317+
err = fdatasync(bc->fd);
316318
}
317319
if (err) {
318320
WPRINTF(("Failed to discard offset=%ld nbytes=%ld err code: %d\n",

0 commit comments

Comments
 (0)