xapi-project/xen-api — pull request #1568 by djs55 (2013-11-28 12:01:54+00:00)
Title: VDI.copy: enhancements for CloudStack

Here's v1 of a modified VDI.copy for early feedback. The design is from @zli, and it works like this:
* a new optional argument "base" requests a copy of only the differences between "base" and the source VDI
* a new optional argument "into" requests to write the blocks to a pre-created VDI, rather than a fresh one

To create a full-size copy use either
* VDI.copy vdi = sr =
* VDI.copy vdi = into =

To copy deltas (e.g. between two snapshots)
* VDI.copy vdi = base = sr =
* VDI.copy vdi = base = into =

To consolidate the deltas back into a full-size copy (aka "close" or "commit" a snapshot)
* VDI.copy vdi = into =

Now that we have an 'into' argument it will make cleaning up VDIs after failed copies easier for CS, because it can 'tag' them with something like 'owned by CS'.

Note the 'delta' VDIs look like regular VDIs, but they only contain block differences. The only sensible thing to do is to copy them back into a consolidated VDI. It's up to the user to use them properly, with great power comes great responsibility.

The following errors are likely to occur in practice:
* VDI_READ_ONLY: the 'into' VDI can't be written to
* VDI_TOO_SMALL: the 'into' VDI is too small to hold the deltas
* VDI_NOT_SPARSE: it makes no sense to copy deltas into a medium where there is no concept of sparseness, since the deltas cannot be copied out

I've tested this by:
* installing ubuntu, taking a snapshot
* writing some changes to the root disk
* making a full copy of the snapshot
* making a copy of the differences between the snapshot and the current VDI
* consolidating the differences back into the full copy of the snapshot
* verifying md5sum

We probably should add some simple test to quickest to cover this.