-
Notifications
You must be signed in to change notification settings - Fork 484
add possibility to choose whether snapshot base volume or copy #675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
add possibility to choose whether snapshot base volume or copy #675
Conversation
ccfee61
to
52df264
Compare
thx for PR. I will check this soon. stay tuned. 🌞 |
Just tested this pull request, works great! Here is my working main.tf:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
Something I don't get to understand from this feature is why virStorageVolCreateXMLFrom
takes the backing store to copy as an extra parameter, when there is a <backingStore>
element already present in the definition. Can you enlighten me?
Why doesn't virStorageVolCreateXMLFrom
simply copy the backing store mentioned in the definition? why does it need a second argument?
Super useful feature for us! 🎉 |
@dmacvicar seems like this is just how This feature is really useful and should be considered. A common use case is where you don't want or need a backing store for the resulting instance, just a standalone volume. |
This adds a new key base_volume_copy to the volume resource to choose whether to invoke StorageVolCreateXML (default) or StorageVolCreateXMLFrom Adapted from original PR dmacvicar#675
e0a579c
to
5240165
Compare
@dmacvicar I've rebased this PR onto main and refactored it a bit. I also decided to add a resize step after volume creation if
|
5240165
to
94e0dbb
Compare
@dmacvicar we are using this patch for a long time for VMs on LVM storage. Could you merge it to mainstream? |
94e0dbb
to
dfdadba
Compare
If base_volume_copy option is set to false (default), a volume is created using StorageVolCreateXML(). Otherwise, StorageVolCreateXMLFrom() is used and the resulting volume doesn't have any association with the original.
dfdadba
to
851fc64
Compare
Description
Add key
base_volume_copy
forlibvirt_volume
resource which controlswhether to invoke StorageVolCreateXML (defualt) or StorageVolCreateXMLFrom.
Motivation
Currently workflow of creating libvirt volumes from base volumes works good for qcow2 images. New volumes are created with
backingStore
xml element in definition which associates them with base qcow2 copy-on-write image and allows them to grow in size without any limitations.However for
logical
storage pools,backingStore
element instructs libvirt to create lvm snapshot which has the following implications:So workflow of creating libvirt volumes from base volumes for logical storage pool is not very useful:
it's impossible to create volume of arbitrary size from base volume.
To address this problem, this PR adds possibility to invoke StorageVolCreateXMLFrom which creates new ordinary logical volume of any size and just copies the base volume to it.
For
qcow2
images, this option can be useful as well. The resulting volume will be created without any association with its backing volume—neither in its XML definition nor in the underlying storage backend.For example, if a VM is expected to have a long lifetime with major OS upgrades, there is no sense in keeping a dangling CoW base volume that contains only dirty blocks.
Notes
Workaround for
qcow2
In some cases, StorageVolCreateXMLFrom() ignores the requested capacity and creates a volume with the same capacity as the original.
To test this behaviour, create 6 XML definitions: 2 for base volumes with a capacity of 10 MiB, and 4 for copy volumes with a capacity of 20 MiB:
Only the
test-copy-raw-from-raw
volume has the requested capacity of 20 MiB. This is because libvirt handles this case differently and copies images directly.In other cases, libvirt calls
qemu-img convert
, which retains the original volume capacity.To improve this behavior, I've added a resize step after volume creation. The resize is performed only if:
base_volume_copy
option istrue
size
option is set and it's greater than the volume'sallocation
and the base volume'scapacity
dir
qcow2
There are many other format options. I think supporting the two most used formats,
raw
andqcow2
, is a great start.Other storage backends
Behavior for storage backends other than
dir
andlogical
was not tested.