Christian,

In this case Juju (not charms) uses the following command in its code to
create a VM image based on a common cloud image:

 out, err := params.runCmd(
  "qemu-img",
  "create",
  "-b", backingPath,
  "-f", "qcow2",
  imgPath,
  fmt.Sprintf("%dG", params.RootDisk))


This is done when charms are requested to be deployed into a VM provisioned by 
a juju machine agent (--to kvm:<host-machine-id> syntax analogous to --to 
lxd:<host-machine-id>).

The reported problem specifically occurs when multiple machines are
provisioned on the same machine.

My understanding is:

1) that Redirect-on-Write type of snapshot is safe to do (even if multiple 
copies of qemu-img are using the same backing image at the same moment) because 
the backing image does not change in progress;
2) it is safe to run multiple VMs using different snapshots that use the same 
base image (because of the Redirect-on-Write behavior).
https://wiki.qemu.org/Documentation/CreateSnapshot

I initially thought that it might be a race between multiple parallel
`qemu-img create -b bfile -f qcow2 <targetimg>` invocations but the
errors are present in the libvirt domain log so it looks like I might be
wrong.


Given that each VM has its own snapshot based on the cloud image and its own 
ISO, I am not sure why the write lock is necessary:

-drive file=/var/lib/juju/kvm/guests/juju-5ad6c1-6-kvm-0.qcow
-drive file=/var/lib/juju/kvm/guests/juju-5ad6c1-6-kvm-0-ds.iso

Any thoughts about that?


I included `ls -il /var/lib/juju/kvm/guests/` output in comment #2 to
show if there were any hard links (none based on what I see in the first
column).


The patch for snapshots and backing images seems to be included in qemu/bionic 
already so the qemu-img -b (...) invocation shouldn't be a problem:

➜  qemu git:(ubuntu/bionic) grep -RiP ' Open backing image in force share mode' 
             
debian/patches/ubuntu/qemu-stable-2.11.1.patch:Subject: [PATCH 09/80] block: 
Open backing image in force share mode for size

https://lists.gnu.org/archive/html/qemu-devel/2017-12/msg02816.html
https://git.qemu.org/?p=qemu.git;a=commit;h=cc954f01e3c004aad081aa36736a17e842b80211

git --no-pager tag --contains=cc954f01e3c004aad081aa36736a17e842b80211 | grep 
-v rc
v2.12.0
v2.12.1
v3.0.0
v3.1.0

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1816170

Title:
  KVM instances fail at creation with: Failed to get shared "write" lock
  Is another process using the image?

To manage notifications about this bug go to:
https://bugs.launchpad.net/juju/+bug/1816170/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to