On Sat, May 4, 2019 at 12:32 AM Nir Soffer <nir...@gmail.com> wrote: > > > On Fri, May 3, 2019, 23:21 Eric Blake <ebl...@redhat.com> wrote: > >> ... >> >>> == creating image with preallocation off == >> >>> Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 >> preallocation=off >> >>> -size=1048576, blocks=0 >> >>> +size=1048576, blocks=2 >> >>> >> >>> == creating image with preallocation full == >> >>> Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 >> preallocation=full >> >>> -size=1048576, blocks=2048 >> >>> +size=1048576, blocks=2050 >> >> >> >> 2048/2050, so we DO have some indication of whether the file is sparse >> >> or fully allocated. >> > >> > Maybe we could check that the value after "blocks=" is a single digit in >> > the first case, and matches "blocks=20.." in the second case? >> >> I wonder if 'qemu-img map --output=json $TEST_IMG' might be any more >> reliable (at least for ignoring any extra block allocations associated >> with the file, if it is some journaling option or xattr or other reason >> why your files seem to occupy more disk sectors than just the size of >> the file would imply). >> > > I think it should work better and is more correct, testing actual > sparsness instead of underlying file system implementation. > > I can send a fix next week. >
I tested this change: $ git diff diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175 index d0ffc495c2..0e3faa50e4 100755 --- a/tests/qemu-iotests/175 +++ b/tests/qemu-iotests/175 @@ -43,17 +43,17 @@ _supported_os Linux size=1m echo echo "== creating image with default preallocation ==" _make_test_img $size | _filter_imgfmt -stat -c "size=%s, blocks=%b" $TEST_IMG +$QEMU_IMG map -f $IMGFMT --output json "$TEST_IMG" for mode in off full falloc; do echo echo "== creating image with preallocation $mode ==" IMGOPTS=preallocation=$mode _make_test_img $size | _filter_imgfmt - stat -c "size=%s, blocks=%b" $TEST_IMG + $QEMU_IMG map -f $IMGFMT --output json "$TEST_IMG" done # success, all done echo "*** done" rm -f $seq.full It almost works: $ ./check -raw 175 QEMU -- "/home/nsoffer/src/qemu/build/tests/qemu-iotests/../../x86_64-softmmu/qemu-system-x86_64" -nodefaults -machine accel=qtest QEMU_IMG -- "/home/nsoffer/src/qemu/build/tests/qemu-iotests/../../qemu-img" QEMU_IO -- "/home/nsoffer/src/qemu/build/tests/qemu-iotests/../../qemu-io" --cache writeback -f raw QEMU_NBD -- "/home/nsoffer/src/qemu/build/tests/qemu-iotests/../../qemu-nbd" IMGFMT -- raw IMGPROTO -- file PLATFORM -- Linux/x86_64 lean 5.0.11-100.fc28.x86_64 TEST_DIR -- /home/nsoffer/src/qemu/build/tests/qemu-iotests/scratch SOCKET_SCM_HELPER -- /home/nsoffer/src/qemu/build/tests/qemu-iotests/socket_scm_helper 175 - output mismatch (see 175.out.bad) --- /home/nsoffer/src/qemu/tests/qemu-iotests/175.out 2019-03-23 18:35:17.788177871 +0200 +++ /home/nsoffer/src/qemu/build/tests/qemu-iotests/175.out.bad 2019-05-11 00:06:09.515873624 +0300 @@ -2,17 +2,17 @@ == creating image with default preallocation == Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 -size=1048576, blocks=0 +[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": 0}] == creating image with preallocation off == Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=off -size=1048576, blocks=0 +[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": 0}] == creating image with preallocation full == Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=full -size=1048576, blocks=2048 +[{ "start": 0, "length": 1048576, "depth": 0, "zero": false, "data": true, "offset": 0}] == creating image with preallocation falloc == Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=falloc -size=1048576, blocks=2048 +[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": 0}] The "falloc" test looks exactly like "off", qemu-img map does not report the allocation status. Nir