[libvirt] [PATCH 5/5] snapshot: Support reparenting external disk snapshots when deleting

Peter Krempa pkrempa at redhat.com
Wed Nov 7 16:01:03 UTC 2018


On Sun, Oct 21, 2018 at 19:38:52 +0300, Povilas Kanapickas wrote:
> Signed-off-by: Povilas Kanapickas <povilas at radix.lt>
> ---
>  src/qemu/qemu_driver.c | 89 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 89 insertions(+)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 227ec1c6d9..a3ffc19122 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c

[....]

> @@ -16617,6 +16618,88 @@ qemuDomainSnapshotReparentChildrenMetadata(virDomainSnapshotObjPtr snap,
>                                             rep->cfg->snapshotDir);
>  }
>  
> +static int
> +qemuDomainSnapshotReparentDiskExternal(virQEMUDriverPtr driver,
> +                                       virDomainSnapshotObjPtr parent_snap,
> +                                       virDomainSnapshotDiskDefPtr disk)
> +{
> +    const char* qemu_img_path = NULL;
> +    virCommandPtr cmd = NULL;
> +    int i;
> +    int ret = -1;
> +    const char* parent_disk_path = NULL;
> +
> +    // Find the path to the disk we should use as the base when reparenting
> +    // FIXME: what if there's no parent snapshot? i.e. we need to reparent on
> +    // "empty" disk?
> +    for (i = 0; i < parent_snap->def->dom->ndisks; ++i) {
> +        if (STREQ(parent_snap->def->dom->disks[i]->dst, disk->name)) {
> +            parent_disk_path = parent_snap->def->dom->disks[i]->src->path;
> +            break;
> +        }
> +    }
> +
> +    if (parent_disk_path == NULL) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("Could not find disk to reparent '%s' to"),
> +                       disk->src->path);
> +        goto cleanup;
> +    }
> +
> +    if (!(qemu_img_path = qemuFindQemuImgBinary(driver))) {
> +        goto cleanup;
> +    }
> +
> +    if (!(cmd = virCommandNewArgList(qemu_img_path,
> +                                     "rebase", "-b", parent_disk_path,
> +                                     disk->src->path,
> +                                     NULL))) {

Okay, this solves the problems that I've mentioned previously. There
still might be problems with matching which images actually get deleted
if the definition changed.

Also note that it needs to support network disks.

This code also should be added together with the deletion code as they
are tightly related.

> +        goto cleanup;
> +    }
> +
> +    if (virCommandRun(cmd, NULL) < 0)
> +        goto cleanup;
> +
> +    ret = 0;
> +cleanup:
> +    virCommandFree(cmd);
> +    return ret;
> +}
> +
> +static int
> +qemuDomainSnapshotReparentDisks(virDomainSnapshotObjPtr snap,
> +                                virQEMUSnapReparentPtr rep)
> +{
> +    int i;
> +    virDomainSnapshotDiskDefPtr snap_disk;
> +
> +    if (!snap->def->dom) {
> +        VIR_WARN("Any external disk snapshots in a snapshot created with "
> +                 "pre-0.9.5 libvirt will not be correctly reparented.");
> +        // In snapshots created with pre-0.9.5 libvirt we don't have information
> +        // needed to correctly reparent external disk snapshots but we also
> +        // don't even know whether external disk snapshots were used so that
> +        // we could report this as an error. We can only emit a warning in that
> +        // case.

As said earlier, this should not happen with external snapshots.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20181107/a496651b/attachment-0001.sig>


More information about the libvir-list mailing list