iotests/244: Add test cases for keep_data_file
Add various test cases around keep_data_file to the existing data_file test suite 244. Signed-off-by: Hanna Czenczek <hreitz@redhat.com> Message-ID: <20250530084448.192369-5-hreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> [kwolf: Added prealloc=full to the test] Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Hanna Czenczek committed
May 30, 2025 at 10:44 UTC
a844ad5da2d0d16bab819c6b50c9cba0012ed202
2 files changed
+132
tests/qemu-iotests/244
+71
@@ -384,6 +384,77 @@ $QEMU_IMG compare --image-opts \
384
"driver=raw,file.filename=$TEST_IMG.data" \
385
"file.filename=$TEST_IMG,backing.file.filename=$TEST_IMG.base"
386
387
+echo
388
+echo '=== keep_data_file tests ==='
389
+
390
+echo
391
+echo '--- Creating test data file ---'
392
+
393
+# Easiest way to create the raw data file without having to create and
394
+# access it manually
395
+_make_test_img -o "data_file=$TEST_IMG.data,data_file_raw=on" 1M
396
+# Values chosen by a fair random.org evaluation
397
+$QEMU_IO -c 'write -P 3 0 512k' -c 'write -P 96 512k 512k' "$TEST_IMG" |
398
+ _filter_qemu_io
399
+
400
+echo
401
+echo '--- Testing stand-alone option ---'
402
+
403
+# Cannot work, needs data file
404
+_make_test_img -o "keep_data_file=on" 1M
405
+
406
+# Invalid option value
407
+_make_test_img -o "keep_data_file=true" 1M
408
+
409
+# Should be the same as omitting
410
+_make_test_img -o "keep_data_file=off" 1M
411
+
412
+# No preallocation is OK when also specifying data_file_raw; otherwise, none of
413
+# the data file will be mapped, i.e. its contents will stay hidden, so
414
+# requesting its contents to be kept (but hidden) doesn't make much sense.
415
+#
416
+# Metadata preallocation is OK: It will not overwrite the data file's contents,
417
+# but ensure the contents are mapped and visible.
418
+#
419
+# Any data preallocation (like falloc) is not OK, as this would overwrite the
420
+# data file's contents despite keep_data_file requesting they should not be
421
+# overwritten.
422
+#
423
+# Note that all of these cases use the data file created above: This verifies
424
+# that when passing keep_data_file=on, the data file is always kept as-is (and
425
+# e.g. not deleted on error).
426
+for prealloc in off metadata falloc full; do
427
+ # Without metadata preallocation, the data_file_raw flag is required so that
428
+ # the data file's contents are visible.
429
+ for data_file_raw in off on; do
430
+ echo
431
+ echo "--- Testing prealloc=$prealloc data_file_raw=$data_file_raw ---"
432
+
433
+ # Remove previously existing qcow2 (metadata) file
434
+ _cleanup_test_img
435
+
436
+ opts="data_file=$TEST_IMG.data,keep_data_file=on"
437
+ opts+=",preallocation=$prealloc"
438
+ opts+=",data_file_raw=$data_file_raw"
439
+
440
+ _make_test_img -o "$opts" 1M
441
+ if [ -f "$TEST_IMG" ]; then
442
+ $QEMU_IO -c 'read -P 3 0 512k' -c 'read -P 96 512k 512k' "$TEST_IMG" |
443
+ _filter_qemu_io
444
+ fi
445
+ done
446
+done
447
+
448
+echo
449
+echo '--- Testing non-existent data file ---'
450
+
451
+# Maybe a matter of taste whether this should fail or create the file, but
452
+# failing is simpler (= will always skip create) and seems safer (users may
453
+# expect the file to exist, and the error will warn them when it does not).
454
+_make_test_img \
455
+ -o "data_file=$TEST_IMG.doesnotexist,keep_data_file=on,data_file_raw=on" \
456
+ 1M
457
+
458
# success, all done
459
echo "*** done"
460
rm -f $seq.full
tests/qemu-iotests/244.out
+61
@@ -197,4 +197,65 @@ wrote 1048576/1048576 bytes at offset 0
197
198
Comparing qcow2 image and raw data file:
199
Images are identical.
200
+
201
+=== keep_data_file tests ===
202
+
203
+--- Creating test data file ---
204
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 data_file=TEST_DIR/t.IMGFMT.data data_file_raw=on
205
+wrote 524288/524288 bytes at offset 0
206
+512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
207
+wrote 524288/524288 bytes at offset 524288
208
+512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
209
+
210
+--- Testing stand-alone option ---
211
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 keep_data_file=on
212
+qemu-img: TEST_DIR/t.IMGFMT: Must not use 'keep_data_file=on' without 'data_file'
213
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 keep_data_file=true
214
+qemu-img: TEST_DIR/t.IMGFMT: Invalid value 'true' for 'keep_data_file': Must be 'on' or 'off'
215
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 keep_data_file=off
216
+
217
+--- Testing prealloc=off data_file_raw=off ---
218
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 data_file=TEST_DIR/t.IMGFMT.data data_file_raw=off keep_data_file=on preallocation=off
219
+qemu-img: TEST_DIR/t.IMGFMT: 'keep_data_file=on' requires 'preallocation=metadata' or 'data_file_raw=on', or the file contents will not be visible
220
+
221
+--- Testing prealloc=off data_file_raw=on ---
222
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 data_file=TEST_DIR/t.IMGFMT.data data_file_raw=on keep_data_file=on preallocation=off
223
+read 524288/524288 bytes at offset 0
224
+512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
225
+read 524288/524288 bytes at offset 524288
226
+512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
227
+
228
+--- Testing prealloc=metadata data_file_raw=off ---
229
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 data_file=TEST_DIR/t.IMGFMT.data data_file_raw=off keep_data_file=on preallocation=metadata
230
+read 524288/524288 bytes at offset 0
231
+512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
232
+read 524288/524288 bytes at offset 524288
233
+512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
234
+
235
+--- Testing prealloc=metadata data_file_raw=on ---
236
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 data_file=TEST_DIR/t.IMGFMT.data data_file_raw=on keep_data_file=on preallocation=metadata
237
+read 524288/524288 bytes at offset 0
238
+512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
239
+read 524288/524288 bytes at offset 524288
240
+512 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
241
+
242
+--- Testing prealloc=falloc data_file_raw=off ---
243
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 data_file=TEST_DIR/t.IMGFMT.data data_file_raw=off keep_data_file=on preallocation=falloc
244
+qemu-img: TEST_DIR/t.IMGFMT: Preallocating more than only metadata would overwrite the external data file's content and is therefore incompatible with 'keep_data_file=on'
245
+
246
+--- Testing prealloc=falloc data_file_raw=on ---
247
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 data_file=TEST_DIR/t.IMGFMT.data data_file_raw=on keep_data_file=on preallocation=falloc
248
+qemu-img: TEST_DIR/t.IMGFMT: Preallocating more than only metadata would overwrite the external data file's content and is therefore incompatible with 'keep_data_file=on'
249
+
250
+--- Testing prealloc=full data_file_raw=off ---
251
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 data_file=TEST_DIR/t.IMGFMT.data data_file_raw=off keep_data_file=on preallocation=full
252
+qemu-img: TEST_DIR/t.IMGFMT: Preallocating more than only metadata would overwrite the external data file's content and is therefore incompatible with 'keep_data_file=on'
253
+
254
+--- Testing prealloc=full data_file_raw=on ---
255
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 data_file=TEST_DIR/t.IMGFMT.data data_file_raw=on keep_data_file=on preallocation=full
256
+qemu-img: TEST_DIR/t.IMGFMT: Preallocating more than only metadata would overwrite the external data file's content and is therefore incompatible with 'keep_data_file=on'
257
+
258
+--- Testing non-existent data file ---
259
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 data_file=TEST_DIR/t.IMGFMT.doesnotexist data_file_raw=on keep_data_file=on
260
+qemu-img: TEST_DIR/t.IMGFMT: Could not open 'TEST_DIR/t.IMGFMT.doesnotexist': No such file or directory
261
*** done