On Fri, Jan 31, 2020 at 03:31:08PM +0100, Peter Krempa wrote:
Allow deleting of checkpoints when snapshots were created along. The
code tracks and modifies the checkpoint list so that backups can still
be taken with such a backing chain. This unfortunately requires to
rename few bitmaps (by copying and deleting them) in some cases.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_checkpoint.c | 112 ++++++++++++++++++++++++++++---------
src/qemu/qemu_checkpoint.h | 5 +-
tests/qemublocktest.c | 34 +++++++----
3 files changed, 111 insertions(+), 40 deletions(-)
diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c
index e75cdd0458..087a740cf8 100644
--- a/src/qemu/qemu_checkpoint.c
+++ b/src/qemu/qemu_checkpoint.c
@@ -24,6 +24,7 @@
#include "qemu_capabilities.h"
#include "qemu_monitor.h"
#include "qemu_domain.h"
+#include "qemu_block.h"
#include "virerror.h"
#include "virlog.h"
@@ -150,39 +151,92 @@ qemuCheckpointFindActiveDiskInParent(virDomainObjPtr vm,
int
qemuCheckpointDiscardDiskBitmaps(virStorageSourcePtr src,
+ virHashTablePtr blockNamedNodeData,
const char *delbitmap,
const char *parentbitmap,
- bool chkcurrent,
- virJSONValuePtr actions)
+ virJSONValuePtr actions,
+ const char *diskdst)
{
- if (parentbitmap) {
- g_autoptr(virJSONValue) arr = NULL;
+ virStorageSourcePtr n = src;
- if (!(arr = virJSONValueNewArray()))
- return -1;
+ /* find the backing chain entry with bitmap named '@bitmap' */
@delbitmap
+ while (n) {
+ qemuBlockNamedNodeDataBitmapPtr tmp;
- if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(arr,
- src->nodeformat,
- delbitmap) < 0)
- return -1;
+ if ((tmp = qemuBlockNamedNodeDataGetBitmapByName(blockNamedNodeData,
+ n, delbitmap))) {
+ break;
+ }
+
+ n = n->backingStore;
+ }
+
+ if (!n) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("bitmap '%s' not found in backing chain of
'%s'"),
+ delbitmap, diskdst);
+ return -1;
+ }
- if (chkcurrent) {
- if (qemuMonitorTransactionBitmapEnable(actions,
- src->nodeformat,
- parentbitmap) < 0)
+ while (n) {
+ qemuBlockNamedNodeDataBitmapPtr srcbitmap;
+
+ if (!(srcbitmap = qemuBlockNamedNodeDataGetBitmapByName(blockNamedNodeData,
+ n, delbitmap)))
+ break;
+
+ /* For the actual checkpoint deletion we will merge any bitmap into the
+ * bitmap of the parent checkpoint (@mergebitmap) or for any image
@parentbitmap
+ * where the parent checkpoint bitmap is not present we must
rename
+ * the bitmap of the deleted checkpoint into the bitmap of the parent
+ * checkpoint as qemu can't currently take the allocation map and turn
+ * it into a bitmap and thus we wouldn't be able to do a backup. */
+ if (parentbitmap) {
+ qemuBlockNamedNodeDataBitmapPtr dstbitmap;
+ g_autoptr(virJSONValue) arr = NULL;
+
+ dstbitmap = qemuBlockNamedNodeDataGetBitmapByName(blockNamedNodeData,
+ n, parentbitmap);
+
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
Jano