xapi-project/xen-api — pull request #1963 by johnelse (2014-09-26 13:27:36+00:00)
Title: CA-143836: Fix up snapshot_of links after reverting to snapshot

SXM uses the snapshot_of field to decide where to migrate snapshot disks, as they should be copied to the same SR as the disk of which they are a snapshot. Reverting a VM to a snapshot does not update snapshot VDIs to point to the new leaf VDIs, meaning SXM can no longer decide where snapshot disks should be migrated.

To fix this without explicitly setting VDI.snapshot_of (an SMAPI-owned field) in xapi, we introduce a new SMAPI call: VDI.revert. This takes a snapshot as an argument, and proceeds to:

Clone the snapshot
Update all snapshots in the tree to be snapshot_of this newly cloned VDI.
Destroy the original VDI from which the snapshot had been taken.

VM.revert then makes use of VDI.revert when reverting all of a VM's disks.

Tested by:

Manually creating a snapshot of a VM with 2 disks, reverting to the snapshot, then SXM'ing.
As above, but with a checkpoint.
Running quicktest.
Running a couple of snapshot/checkpoint rollback sequences.
Running a couple of SXM sequences (test cases which try to SXM a reverted VM are still failing, but I believe this is now due to a testcase bug).