Richard W.M. Jones
2014-Jun-28 10:39 UTC
[Libguestfs] IRC question: Does using two handles to write cause disk corruption?
>From IRC yesterday:19:38 < sr_> i wanted to ask you , if i launch 2 handle writing to the same disk images, does this cause disk corruption ? The short answer is: yes, in many cases. - - - - The longer answer is a bit more nuanced ... In the physical world you can wire up two computers to a single SCSI disk which would look like this (although more often done using FC/iSCSI): +---------------+ +---------------+ | host A | | host B | | | | | +----------+----+ +----+----------+ | | | +----------+ | +----+ SCSI +----+ | | +----------+ If both hosts write to the same filesystem on the SCSI LUN then with a regular filesystem like ext4 you would get instant, massive disk corruption. However there are other filesystems which can handle this like Clustered LVM / GFS2. If the two hosts are writing to different LUNs, then everything is fine. - - - - In terms of virtual machines: +---------------+ +---------------+ | qemu A | | qemu B | | | | | +----------+----+ +----+----------+ | | | +----------+ | +----+ raw +----+ | file | +----------+ If the libguestfs handles / virtual machines are talking to different filesystems, *and the disk format is raw*, then it should work. Of course any attempt to modify the partition table or other shared parts of the disk image will cause corruption, because the qemu processes won't see all changes made by each other. If you are using the non-default libvirt backend it will probably prevent you from doing this. Use the 'direct' backend instead. It is *not* possible, in the libguestfs API, to set up CLVM or use GFS2 in shared mode. - - - - This setup will definitely cause disk corruption: +---------------+ +---------------+ | qemu A | | qemu B | | | | | +----------+----+ +----+----------+ | | | +----------+ | +----+ qcow2 +----+ | file | +----------+ This is because qemu assumes it has exclusive access to the qcow2 metadata, and if two processes try to modify it at the same time they will corrupt each other. - - - - A corollary is whether you can open two or more libguestfs handles to the same appliance, ie: +---------------+ +---------------+ | libguestfs --------- qemu | | program --------- | +---------------+ +-----+---------+ | | +---+-----+ | qcow2 | | file | +---------+ This lets you exploit more parallelism in qemu. You cannot do this at the moment, but we intend to add this capability in libguestfs 1.28 if time permits. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html