xapi-project/xen-api — pull request #1570 by zli (2013-11-28 15:59:35+00:00)
Title: SCTX-1316: Do not delete VDI from DB immediately if it's CSLG.

Minimal reproducing steps: on a CSLG SR, create a VDI, make a
snapshot. If you then delete the VDI before its snapshot, the
LUN of that VDI will be left behind on the array (even if the
deletion is reported as succeeded).

The root cause is, CSLG uses array's snapshot facility instead
of the standard VHD tree. There is no 3rd node as base copy,
the original VDI is the base copy. Therefore, the GC works
differently too. If you delete a CSLG VDI before its snapshot,
the VDI will be marked as unmanaged but won't be deleted. It's
until all its dependencies are gone, the VDI is then garbage
collected.

This used to work well, but then a change was introduced in XAPI
for SMAPI2. With this change, XAPI will always remove the a VDI's
DB entry immediately after the deleting action without waiting
for the SM backend to issue the DB forget.

In this case, when we ask CSLG to delete the VDI, the VDI is
merely marked as unmanaged and wait for GC to collect it until
all its dependencies are gone. But now, since the DB entry was
removed by XAPI immediately, the dependency link from the snapshot
to the VDI is immediaely cut off. So when we delete the snapshot
later on, GC has no way to figure out the relation between the
VDI and the snapshot because the link is gone from the DB.
Therefore, the VDI will not be collected automatically, and will
reside as an orphan LUN on the array forever.

Signed-off-by: Zheng Li