From 52badc03dfe80a80996d6dfb98ba18d65333f346 Mon Sep 17 00:00:00 2001
Message-Id: <52badc03dfe80a80996d6dfb98ba18d65333f346@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 26 Feb 2014 14:55:28 +0100
Subject: [PATCH] qemu: Switch snapshot deletion to the new API functions
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
Use the new storage driver APIs to delete snapshot backing files in case
of failure instead of directly relying on "unlink". This will help us in
the future when we will be adding network based storage without local
representation in the host.
(cherry picked from commit 8f4091d6771069324e60c8708881b76de8a8ab8a)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
cfg.mk | 1 +
src/qemu/qemu_driver.c | 17 ++++++++++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index f2cd411..cfbdc30 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -749,6 +749,7 @@ sc_prohibit_cross_inclusion:
cpu/ | locking/ | network/ | rpc/ | security/) \
safe="($$dir|util|conf)";; \
xenapi/ | xenxs/ ) safe="($$dir|util|conf|xen)";; \
+ qemu/ ) safe="($$dir|util|conf|cpu|network|locking|rpc|security|storage)";; \
*) safe="($$dir|util|conf|cpu|network|locking|rpc|security)";; \
esac; \
in_vc_files="^src/$$dir" \
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a1145a2..a91b06d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -94,6 +94,7 @@
#include "virstring.h"
#include "viraccessapicheck.h"
#include "viraccessapicheckqemu.h"
+#include "storage/storage_driver.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -12521,6 +12522,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
int ret = -1;
int fd = -1;
bool need_unlink = false;
+ virStorageFilePtr snapfile = NULL;
if (snap->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -12540,6 +12542,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
virStorageFileFreeMetadata(disk->backingChain);
disk->backingChain = NULL;
+ if (!(snapfile = virStorageFileInitFromSnapshotDef(snap)))
+ goto cleanup;
+
switch (snap->type) {
case VIR_DOMAIN_DISK_TYPE_BLOCK:
reuse = true;
@@ -12615,8 +12620,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
}
cleanup:
- if (need_unlink && unlink(source))
+ if (need_unlink && virStorageFileUnlink(snapfile))
VIR_WARN("unable to unlink just-created %s", source);
+ virStorageFileFree(snapfile);
VIR_FREE(device);
VIR_FREE(source);
VIR_FREE(persistSource);
@@ -12636,16 +12642,20 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
{
char *source = NULL;
char *persistSource = NULL;
+ virStorageFilePtr diskfile = NULL;
struct stat st;
+ diskfile = virStorageFileInitFromDiskDef(disk);
+
if (VIR_STRDUP(source, origdisk->src) < 0 ||
(persistDisk && VIR_STRDUP(persistSource, source) < 0))
goto cleanup;
qemuDomainPrepareDiskChainElement(driver, vm, disk, disk->src,
VIR_DISK_CHAIN_NO_ACCESS);
- if (need_unlink && stat(disk->src, &st) == 0 &&
- S_ISREG(st.st_mode) && unlink(disk->src) < 0)
+ if (need_unlink && diskfile &&
+ virStorageFileStat(diskfile, &st) == 0 && S_ISREG(st.st_mode) &&
+ virStorageFileUnlink(diskfile) < 0)
VIR_WARN("Unable to remove just-created %s", disk->src);
/* Update vm in place to match changes. */
@@ -12663,6 +12673,7 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
}
cleanup:
+ virStorageFileFree(diskfile);
VIR_FREE(source);
VIR_FREE(persistSource);
}
--
1.9.0