Skip to content

CloningVolumeSource doesn't support clones between pools #67

Description

@richt-volx

I tried cloning a volume between 2 libvirt storage pools as follows:

volume {
    name  = "my-new-root-volume"
    bus   = "virtio"
    pool  = "default"
    alias = "artifact"
    source {
      type   = "cloning"
      pool   = "my-library-pool"
      volume = "noble-server-cloudimg-amd64.img"
    }
  }

Running that gives with -debug gives the following relevant log entries:

==> test_build.libvirt.cloud_image: Preparing volumes...
    test_build.libvirt.cloud_image: Preparing volume 
...
==> test_build.libvirt.cloud_image: Pausing after run of step 'stepPrepareVolumes'. Press enter to continue. 
==> test_build.libvirt.cloud_image: Sending the domain definition to libvirt
==> test_build.libvirt.cloud_image: Pausing after run of step 'stepDefineDomain'. Press enter to continue. 
==> test_build.libvirt.cloud_image: Starting the Libvirt domain
==> test_build.libvirt.cloud_image: DomainCreate.RPC: Storage volume not found: no storage vol with matching name 'my-new-root-volume'

Checking with virsh shows that 'my-new-root-volume' has been created in 'my-library-pool', not in 'default'.

The issue here is in the call to StorageVolCreateXMLFrom in PreparationContext.CloneVolumeFrom preparation_context.go

	ref, err := pctx.Driver.StorageVolCreateXMLFrom(sourcePool, volumeXML, sourceVol, 0)

This is actually passing the sourcePool twice - once as the Pool parameter, and again as sourceVol.Pool. If we alter the call to CloneVolumeFrom to pass in the target pool as the 'Pool' parameter libvirt does the right thing and creates the cloned volume in the specified target pool ('default' in this case).

I have a branch with the updates to get cross-pool clones working, let me know if it would be helpful to tidy it up and open a PR for it.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions