Description of problem:
2 VMs can not boot at the same time with 'share-rw=on' for the same luks format image.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. create luks format disk and install guest
# qemu-img create -f luks --object secret,id=sec0,data=`printf %s "redhat" |base64`,format=base64 -o key-secret=sec0 system.luks 20G
2. boot guest with share-rw=on
-cpu host \
-rtc base=localtime,clock=host,driftfix=slew \
-M pc-i440fx-rhel7.5.0 \
-name rhel7.5 \
-smp 4,cores=2,threads=1,sockets=2 \
-m 4G \
-uuid c944829b-9aa0-46a2-b3d0-493c135da24d \
-boot menu=on \
-object iothread,id=iothread0 \
-object secret,id=sec0,data=`printf %s "redhat" |base64`,format=base64 \
-device virtio-scsi-pci,id=scsi0,addr=0x3,iothread=iothread0 \
-drive format=luks,key-secret=sec0,file=/home/system.luks,id=drive_sysdisk,if=none,werror=stop,rerror=stop \
-device scsi-hd,drive=drive_sysdisk,bootindex=0,share-rw=on \
-device virtio-net-pci,mac=fa:f7:f8:5f:fa:5b,id=idn0VnaA,vectors=4,netdev=id8xJhp7,bus=pci.0,addr=06 \
-netdev tap,id=id8xJhp7,vhost=on \
-monitor stdio \
-vnc :0 \
3. boot the guest with share-rw=on again.
after step 2, guest boot up normally.
after step 3, guest can not boot up.
qemu-kvm: -drive format=luks,key-secret=sec0,file=/home/system.luks,id=drive_sysdisk,if=none,werror=stop,rerror=stop: Failed to get "write" lock
Is another process using the image?
two guest can boot up at the same time.
Tested with luks format on RHEL7.5 also hit this issue.
Tested with raw format, works well.
luks is a format driver in QEMU. So it has the same restrictions as any other format like qcow2: share-rw DOES NOT allow two VMs to share it.
Re-opening, as there is no reason why sharing could not be made to work. LUKS is a format driver, but all the metadata in the LUKS header region is readonly, at least by default. So it is reasonable to expect to be able to have multiple writers, provided the driver beneath lucks supports it.
In the future, we will allow some live changes to the header regions, such as adding/removing key slots. In such a cases, we would need to require exclusive access during those operations, but that shouldn't block sharing during normal use.
Dan, does that mean if I use "locking=off" on the "driver beneath luks", it is guaranteed safe to write to the image from two VMs, and no corruption can happen with today's QEMU luks driver? Or is there additional work needed on the driver to handle concurrent writes?
Yes, /at this point in time/ it should be safe to use locking=off on the driver beneath luks.
This will change when we later provide the ability to update keyslots on the fly, but we can worry about that when we get there.
Addressed by below commit from QEMU 3.1:
Author: Fam Zheng <email@example.com>
Date: Tue Aug 14 15:25:51 2018 +0800
luks: Allow share-rw=on
Format drivers such as qcow2 don't allow sharing the same image between
two QEMU instances in order to prevent image corruptions, because of
metadata cache. LUKS driver don't modify metadata except for when
creating image, so it is safe to relax the permission. This makes
share-rw=on property work on virtual devices.
Suggested-by: Daniel P. Berrangé <firstname.lastname@example.org>
Signed-off-by: Fam Zheng <email@example.com>
Reviewed-by: Daniel P. Berrangé <firstname.lastname@example.org>
Signed-off-by: Kevin Wolf <email@example.com>
(In reply to Fam Zheng from comment #7)
> Addressed by below commit from QEMU 3.1:
> commit 497da8236ab2663a8108858ba7ea59aac21c5fe6
> Author: Fam Zheng <firstname.lastname@example.org>
> Date: Tue Aug 14 15:25:51 2018 +0800
> luks: Allow share-rw=on
> Format drivers such as qcow2 don't allow sharing the same image between
> two QEMU instances in order to prevent image corruptions, because of
> metadata cache. LUKS driver don't modify metadata except for when
> creating image, so it is safe to relax the permission. This makes
> share-rw=on property work on virtual devices.
> Suggested-by: Daniel P. Berrangé <email@example.com>
> Signed-off-by: Fam Zheng <firstname.lastname@example.org>
> Reviewed-by: Daniel P. Berrangé <email@example.com>
> Signed-off-by: Kevin Wolf <firstname.lastname@example.org>
Fix included in qemu-kvm-rhev-2.12.0-22.el7
According to steps mentioned in Description, tested on qemu-kvm-rhev-2.12.0-22.el7, not hit this issue. So set status to VERIFIED.
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.
For information on the advisory, and where to find the updated
files, follow the link below.
If the solution does not work for you, open a new bug report.