[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [RFC PATCH 5/8] Snapshot QEMU driver.



2010/4/2 Chris Lalancette <clalance redhat com>:
> Signed-off-by: Chris Lalancette <clalance redhat com>
> ---
>  src/qemu/qemu_conf.c         |    9 +-
>  src/qemu/qemu_conf.h         |    4 +-
>  src/qemu/qemu_driver.c       |  757 ++++++++++++++++++++++++++++++++++++++++-
>  src/qemu/qemu_monitor.c      |   39 +++
>  src/qemu/qemu_monitor.h      |    4 +
>  src/qemu/qemu_monitor_json.c |   24 ++
>  src/qemu/qemu_monitor_json.h |    4 +
>  src/qemu/qemu_monitor_text.c |  126 +++++++
>  src/qemu/qemu_monitor_text.h |    4 +
>  tests/qemuxml2argvtest.c     |    2 +-
>  10 files changed, 951 insertions(+), 22 deletions(-)
>
> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index 5d0b211..1ebb29a 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c


> +
> +static int qemuDomainSnapshotWriteSnapshotMetadata(virDomainObjPtr vm,
> +                                                   virDomainSnapshotDefPtr def,
> +                                                   char *snapshotDir)
> +{
> +    int fd = -1;
> +    char *newxml = NULL;
> +    int ret = -1;
> +    char *snapDir = NULL;
> +    char *snapFile = NULL;
> +    int err;
> +    char uuidstr[VIR_UUID_STRING_BUFLEN];
> +
> +    virUUIDFormat(vm->def->uuid, uuidstr);
> +    newxml = virDomainSnapshotDefFormat(uuidstr, def);
> +    if (newxml == NULL) {
> +        virReportOOMError();
> +        return -1;
> +    }
> +
> +    if (virAsprintf(&snapDir, "%s/%s", snapshotDir, vm->def->name) < 0) {
> +        virReportOOMError();
> +        goto cleanup;
> +    }
> +    err = virFileMakePath(snapDir);
> +    if (err < 0) {
> +        virReportSystemError(err, _("cannot create snapshot directory '%s'"),
> +                             snapDir);
> +        goto cleanup;
> +    }
> +
> +    if (virAsprintf(&snapFile, "%s/%s.snap", snapDir, def->name) < 0) {

Maybe use .xml instead of .snap, because the file will contain XML.

> +        virReportOOMError();
> +        goto cleanup;
> +    }
> +    fd = open(snapFile, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);
> +    if (fd < 0) {
> +        qemuReportError(VIR_ERR_OPERATION_FAILED,
> +                        _("failed to create snapshot file '%s'"), snapFile);
> +        goto cleanup;
> +    }
> +    if (safewrite(fd, newxml, strlen(newxml)) != strlen(newxml)) {
> +        virReportSystemError(errno, _("Failed to write snapshot data to %s"),
> +                             snapFile);
> +        goto cleanup;
> +    }
> +
> +    ret = 0;
> +
> +cleanup:
> +    VIR_FREE(snapFile);
> +    VIR_FREE(snapDir);
> +    VIR_FREE(newxml);
> +    if (fd != -1)
> +        close(fd);
> +    return ret;
> +}
> +

ACK.

Matthias


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]