mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 02:04:16 +03:00
qemu: Switch snapshot deletion to the new API functions
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.
This commit is contained in:
parent
a44b7b87bc
commit
8f4091d677
1
cfg.mk
1
cfg.mk
@ -764,6 +764,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" \
|
||||
|
@ -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
|
||||
|
||||
@ -12648,6 +12649,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",
|
||||
@ -12667,6 +12669,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;
|
||||
@ -12742,8 +12747,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);
|
||||
@ -12763,16 +12769,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. */
|
||||
@ -12790,6 +12800,7 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
|
||||
}
|
||||
|
||||
cleanup:
|
||||
virStorageFileFree(diskfile);
|
||||
VIR_FREE(source);
|
||||
VIR_FREE(persistSource);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user