-
Notifications
You must be signed in to change notification settings - Fork 488
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
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: |
dmacvicar
left a comment
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
|
ℹ️ ℹ️ ℹ️ ℹ️ ℹ️ ℹ️ This contribution is relevant to the legacy version of the provider, which is now in the v0.8 branch of this repository. Future development is based on a new provider, which is not compatible with this one, nor does share code. As the new provider solves many issues with the legacy, and to make development in my free time more enjoyable, I have decided to close all PRs for the legacy provider, and to ask to check if the contribution would apply to the new one. This also to encourage trying the new version. and check the documentation:
You are free to reopen the PR for v0.8, which is targetted now to the v0.8 branch. We may also start a discussion if we can assemble a team of maintainters for the legacy branch. My efforts will go into the new provider. I ask you to check the new provider and re-evaluate this contribution. 🙏 |
Description
Add key
base_volume_copyforlibvirt_volumeresource 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
backingStorexml 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
logicalstorage pools,backingStoreelement 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
qcow2images, 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
qcow2In 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-rawvolume 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_copyoption istruesizeoption is set and it's greater than the volume'sallocationand the base volume'scapacitydirqcow2There are many other format options. I think supporting the two most used formats,
rawandqcow2, is a great start.Other storage backends
Behavior for storage backends other than
dirandlogicalwas not tested.