blkverify.rst 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. Block driver correctness testing with ``blkverify``
  2. ===================================================
  3. Introduction
  4. ------------
  5. This document describes how to use the ``blkverify`` protocol to test that a block
  6. driver is operating correctly.
  7. It is difficult to test and debug block drivers against real guests. Often
  8. processes inside the guest will crash because corrupt sectors were read as part
  9. of the executable. Other times obscure errors are raised by a program inside
  10. the guest. These issues are extremely hard to trace back to bugs in the block
  11. driver.
  12. ``blkverify`` solves this problem by catching data corruption inside QEMU the first
  13. time bad data is read and reporting the disk sector that is corrupted.
  14. How it works
  15. ------------
  16. The ``blkverify`` protocol has two child block devices, the "test" device and the
  17. "raw" device. Read/write operations are mirrored to both devices so their
  18. state should always be in sync.
  19. The "raw" device is a raw image, a flat file, that has identical starting
  20. contents to the "test" image. The idea is that the "raw" device will handle
  21. read/write operations correctly and not corrupt data. It can be used as a
  22. reference for comparison against the "test" device.
  23. After a mirrored read operation completes, ``blkverify`` will compare the data and
  24. raise an error if it is not identical. This makes it possible to catch the
  25. first instance where corrupt data is read.
  26. Example
  27. -------
  28. Imagine raw.img has 0xcd repeated throughout its first sector::
  29. $ ./qemu-io -c 'read -v 0 512' raw.img
  30. 00000000: cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd ................
  31. 00000010: cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd ................
  32. [...]
  33. 000001e0: cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd ................
  34. 000001f0: cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd ................
  35. read 512/512 bytes at offset 0
  36. 512.000000 bytes, 1 ops; 0.0000 sec (97.656 MiB/sec and 200000.0000 ops/sec)
  37. And test.img is corrupt, its first sector is zeroed when it shouldn't be::
  38. $ ./qemu-io -c 'read -v 0 512' test.img
  39. 00000000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  40. 00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  41. [...]
  42. 000001e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  43. 000001f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  44. read 512/512 bytes at offset 0
  45. 512.000000 bytes, 1 ops; 0.0000 sec (81.380 MiB/sec and 166666.6667 ops/sec)
  46. This error is caught by ``blkverify``::
  47. $ ./qemu-io -c 'read 0 512' blkverify:a.img:b.img
  48. blkverify: read sector_num=0 nb_sectors=4 contents mismatch in sector 0
  49. A more realistic scenario is verifying the installation of a guest OS::
  50. $ ./qemu-img create raw.img 16G
  51. $ ./qemu-img create -f qcow2 test.qcow2 16G
  52. $ ./qemu-system-x86_64 -cdrom debian.iso \
  53. -drive file=blkverify:raw.img:test.qcow2
  54. If the installation is aborted when ``blkverify`` detects corruption, use ``qemu-io``
  55. to explore the contents of the disk image at the sector in question.