mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-31 06:13:53 -06:00

When opening an image with discard=off, we punch hole in the image when writing zeroes, making the image sparse. This breaks users that want to ensure that writes cannot fail with ENOSPACE by using fully allocated images[1]. bdrv_co_pwrite_zeroes() correctly disables BDRV_REQ_MAY_UNMAP if we opened the child without discard=unmap or discard=on. But we don't go through this function when accessing the top node. Move the check down to bdrv_co_do_pwrite_zeroes() which seems to be used in all code paths. This change implements the documented behavior, punching holes only when opening the image with discard=on or discard=unmap. This may not be the best default but can improve it later. The test depends on a file system supporting discard, deallocating the entire file when punching hole with the length of the entire file. Tested with xfs, ext4, and tmpfs. [1] https://lists.nongnu.org/archive/html/qemu-discuss/2024-06/msg00003.html Signed-off-by: Nir Soffer <nsoffer@redhat.com> Message-id: 20240628202058.1964986-3-nsoffer@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
81 lines
2.5 KiB
Text
81 lines
2.5 KiB
Text
QA output created by write-zeroes-unmap
|
|
|
|
=== defaults - write zeros ===
|
|
|
|
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
|
|
QEMU X.Y.Z monitor - type 'help' for more information
|
|
(qemu) qemu-io none0 "write -z 0 1m"
|
|
wrote 1048576/1048576 bytes at offset 0
|
|
1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
|
(qemu) quit
|
|
1.0M TEST_DIR/t.raw
|
|
|
|
=== defaults - write zeros unmap ===
|
|
|
|
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
|
|
QEMU X.Y.Z monitor - type 'help' for more information
|
|
(qemu) qemu-io none0 "write -zu 0 1m"
|
|
wrote 1048576/1048576 bytes at offset 0
|
|
1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
|
(qemu) quit
|
|
1.0M TEST_DIR/t.raw
|
|
|
|
=== defaults - write actual zeros ===
|
|
|
|
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
|
|
QEMU X.Y.Z monitor - type 'help' for more information
|
|
(qemu) qemu-io none0 "write -P 0 0 1m"
|
|
wrote 1048576/1048576 bytes at offset 0
|
|
1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
|
(qemu) quit
|
|
1.0M TEST_DIR/t.raw
|
|
|
|
=== discard=off - write zeroes unmap ===
|
|
|
|
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
|
|
QEMU X.Y.Z monitor - type 'help' for more information
|
|
(qemu) qemu-io none0 "write -zu 0 1m"
|
|
wrote 1048576/1048576 bytes at offset 0
|
|
1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
|
(qemu) quit
|
|
1.0M TEST_DIR/t.raw
|
|
|
|
=== detect-zeroes=on - write actual zeros ===
|
|
|
|
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
|
|
QEMU X.Y.Z monitor - type 'help' for more information
|
|
(qemu) qemu-io none0 "write -P 0 0 1m"
|
|
wrote 1048576/1048576 bytes at offset 0
|
|
1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
|
(qemu) quit
|
|
1.0M TEST_DIR/t.raw
|
|
|
|
=== detect-zeroes=on,discard=on - write actual zeros ===
|
|
|
|
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
|
|
QEMU X.Y.Z monitor - type 'help' for more information
|
|
(qemu) qemu-io none0 "write -P 0 0 1m"
|
|
wrote 1048576/1048576 bytes at offset 0
|
|
1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
|
(qemu) quit
|
|
1.0M TEST_DIR/t.raw
|
|
|
|
=== discard=on - write zeroes ===
|
|
|
|
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
|
|
QEMU X.Y.Z monitor - type 'help' for more information
|
|
(qemu) qemu-io none0 "write -z 0 1m"
|
|
wrote 1048576/1048576 bytes at offset 0
|
|
1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
|
(qemu) quit
|
|
1.0M TEST_DIR/t.raw
|
|
|
|
=== discard=on - write zeroes unmap ===
|
|
|
|
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
|
|
QEMU X.Y.Z monitor - type 'help' for more information
|
|
(qemu) qemu-io none0 "write -zu 0 1m"
|
|
wrote 1048576/1048576 bytes at offset 0
|
|
1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
|
(qemu) quit
|
|
0 TEST_DIR/t.raw
|