qemu 'aio=native' option can cause filesystem corruption when using sparse images on ext4

Updated -

Direct Asynchronous IO (AIO) that is not issued on filesystem block boundaries, and falls into a hole in a sparse file on ext4 or xfs filesystems, may corrupt file data if multiple I/O operations modify the same filesystem block. Specifically, if qemu-kvm is used with the aio=native IO mode over a sparse device image hosted on the ext4 or xfs filesystem, guest filesystem corruption will occur if partitions are not aligned with the host filesystem block size. Generally, do not use aio=native option along with cache=none for QEMU. Additionally, this issue can be avoided by using one of the following techniques:

  1. Align AIOs on filesystem block boundaries, or do not write to sparse files using AIO on xfs or ext4 filesystems.

  2. KVM: Use a non-sparse system image file or allocate the space by zeroing out the entire file.

  3. KVM: Create the image using an ext3 host filesystem instead of ext4.

  4. KVM: Invoke qemu-kvm with aio=threads (this is the default).

  5. KVM: Align all partitions within the guest image to the host's filesystem block boundary (default 4k).

This issue is documented in the RHEL 6 Technical Notes, and is represented by Red Hat Bugzilla # 615309.

Comments