提交 9e5c98e8 编写于 作者: P Pavel Mores 提交者: Peter Krempa

qemu: block: use the delete flag to delete snapshot images if requested

When blockcommit finishes successfully, one of the
qemuBlockJobProcessEventCompletedCommit() and
qemuBlockJobProcessEventCompletedActiveCommit() event handlers is called.
This is where the delete flag (stored in qemuBlockJobCommitData since the
previous commit) can actually be used to delete the committed snapshot
images if requested.

We use virFileRemove() instead of a simple unlink() to cover the case where
the image to be removed is on an NFS volume.
Signed-off-by: NPavel Mores <pmores@redhat.com>
Reviewed-by: NPeter Krempa <pkrempa@redhat.com>
上级 cb03fd93
......@@ -1004,6 +1004,44 @@ qemuBlockJobProcessEventCompletedPull(virQEMUDriverPtr driver,
}
/**
* qemuBlockJobDeleteImages:
* @driver: qemu driver object
* @vm: domain object
* @disk: disk object that the chain to be deleted is associated with
* @top: top snapshot of the chain to be deleted
*
* Helper for removing snapshot images. Intended for callers like
* qemuBlockJobProcessEventCompletedCommit() and
* qemuBlockJobProcessEventCompletedActiveCommit() as it relies on adjustments
* these functions perform on the 'backingStore' chain to function correctly.
*
* TODO look into removing backing store for non-local snapshots too
*/
static void
qemuBlockJobDeleteImages(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainDiskDefPtr disk,
virStorageSourcePtr top)
{
virStorageSourcePtr p = top;
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
uid_t uid;
gid_t gid;
for (; p != NULL; p = p->backingStore) {
if (virStorageSourceGetActualType(p) == VIR_STORAGE_TYPE_FILE) {
qemuDomainGetImageIds(cfg, vm, p, disk->src, &uid, &gid);
if (virFileRemove(p->path, uid, gid) < 0) {
VIR_WARN("Unable to remove snapshot image file '%s' (%s)",
p->path, g_strerror(errno));
}
}
}
}
/**
* qemuBlockJobProcessEventCompletedCommit:
* @driver: qemu driver object
......@@ -1070,6 +1108,10 @@ qemuBlockJobProcessEventCompletedCommit(virQEMUDriverPtr driver,
job->data.commit.topparent->backingStore = job->data.commit.base;
qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, job->data.commit.top);
if (job->data.commit.deleteCommittedImages)
qemuBlockJobDeleteImages(driver, vm, job->disk, job->data.commit.top);
virObjectUnref(job->data.commit.top);
job->data.commit.top = NULL;
......@@ -1160,6 +1202,10 @@ qemuBlockJobProcessEventCompletedActiveCommit(virQEMUDriverPtr driver,
job->disk->src->readonly = job->data.commit.top->readonly;
qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, job->data.commit.top);
if (job->data.commit.deleteCommittedImages)
qemuBlockJobDeleteImages(driver, vm, job->disk, job->data.commit.top);
virObjectUnref(job->data.commit.top);
job->data.commit.top = NULL;
/* the mirror element does not serve functional purpose for the commit job */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册