From nobody Mon Sep 16 19:22:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1540496929682804.969660546601; Thu, 25 Oct 2018 12:48:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D0A530026A4; Thu, 25 Oct 2018 19:48:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 43D99906B; Thu, 25 Oct 2018 19:48:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EBFD04BB74; Thu, 25 Oct 2018 19:48:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9PJLHlk027785 for ; Thu, 25 Oct 2018 15:21:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2662860F80; Thu, 25 Oct 2018 19:21:17 +0000 (UTC) Received: from red.redhat.com (ovpn-122-116.rdu2.redhat.com [10.10.122.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A0B86714C; Thu, 25 Oct 2018 19:21:15 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Thu, 25 Oct 2018 20:20:18 +0100 Message-Id: <20181025192021.350438-18-eblake@redhat.com> In-Reply-To: <20181025192021.350438-1-eblake@redhat.com> References: <20181025192021.350438-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com Subject: [libvirt] [PATCH v3 17/20] wip: backup: Wire up qemu checkpoint commands over QMP X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 25 Oct 2018 19:48:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Time to actually issue the QMP transactions that create and delete persistent checkpoints. For create, we only need one transaction: inside, we visit all disks affected by the checkpoint, and create a new enabled bitmap, as well as disabling the bitmap of the parent checkpoint (if any). For deletion, we need multiple calls: if the checkpoint to be deleted is active, we must enable the parent; then we must merge the existing checkpoint into the parent, and finally we can delete the checkpoint. Signed-off-by: Eric Blake --- src/qemu/qemu_domain.c | 93 +++++++++++++++++++++++++++++------------- src/qemu/qemu_driver.c | 58 +++++++++++++++++++++++++- 2 files changed, 121 insertions(+), 30 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index fec59d06b5..15722956bc 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8399,44 +8399,79 @@ qemuDomainCheckpointDiscard(virQEMUDriverPtr driver, int ret =3D -1; virDomainCheckpointObjPtr parentchk =3D NULL; virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); + int i, j; - if (!metadata_only) { - if (!virDomainObjIsActive(vm)) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("cannot remove checkpoint from inactive domai= n")); - goto cleanup; - } else { - /* TODO: Implement QMP sequence to merge bitmaps */ - // qemuDomainObjPrivatePtr priv; - // priv =3D vm->privateData; - // qemuDomainObjEnterMonitor(driver, vm); - // /* we continue on even in the face of error */ - // qemuMonitorDeleteCheckpoint(priv->mon, chk->def->name); - // ignore_value(qemuDomainObjExitMonitor(driver, vm)); - } + if (!metadata_only && !virDomainObjIsActive(vm)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot remove checkpoint from inactive domain")); + goto cleanup; } if (virAsprintf(&chkFile, "%s/%s/%s.xml", cfg->checkpointDir, vm->def->name, chk->def->name) < 0) goto cleanup; + if (chk->def->parent) { + parentchk =3D virDomainCheckpointFindByName(vm->checkpoints, + chk->def->parent); + if (!parentchk) { + VIR_WARN("missing parent checkpoint matching name '%s'", + chk->def->parent); + } + } + + if (!metadata_only) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; + bool success =3D true; + + qemuDomainObjEnterMonitor(driver, vm); + for (i =3D 0; i < chk->def->ndisks; i++) { + virDomainCheckpointDiskDef *disk =3D &chk->def->disks[i]; + + if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) + continue; + + if (parentchk) { + for (j =3D 0; j < parentchk->def->ndisks; j++) { + virDomainCheckpointDiskDef *disk2; + + disk2 =3D &parentchk->def->disks[j]; + if (STRNEQ(disk->node, disk2->node)) + continue; + if (chk =3D=3D vm->current_checkpoint && + qemuMonitorEnableBitmap(priv->mon, disk->node, + disk2->bitmap) < 0) { + success =3D false; + break; + } + if (qemuMonitorMergeBitmaps(priv->mon, disk->node, + disk2->bitmap, + disk->bitmap) < 0) { + success =3D false; + break; + } + } + } + if (qemuMonitorDeleteBitmap(priv->mon, disk->node, + disk->bitmap) < 0) { + success =3D false; + break; + } + } + if (qemuDomainObjExitMonitor(driver, vm) < 0 || !success) + goto cleanup; + } + if (chk =3D=3D vm->current_checkpoint) { - if (update_parent && chk->def->parent) { - parentchk =3D virDomainCheckpointFindByName(vm->checkpoints, - chk->def->parent); - if (!parentchk) { - VIR_WARN("missing parent checkpoint matching name '%s'", + if (update_parent && parentchk) { + parentchk->def->current =3D true; + if (qemuDomainCheckpointWriteMetadata(vm, parentchk, driver->c= aps, + driver->xmlopt, + cfg->checkpointDir) < 0)= { + VIR_WARN("failed to set parent checkpoint '%s' as current", chk->def->parent); - } else { - parentchk->def->current =3D true; - if (qemuDomainCheckpointWriteMetadata(vm, parentchk, drive= r->caps, - driver->xmlopt, - cfg->checkpointDir) = < 0) { - VIR_WARN("failed to set parent checkpoint '%s' as curr= ent", - chk->def->parent); - parentchk->def->current =3D false; - parentchk =3D NULL; - } + parentchk->def->current =3D false; + parentchk =3D NULL; } } vm->current_checkpoint =3D parentchk; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2c5295d14a..236cbeb683 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -50,6 +50,7 @@ #include "qemu_hostdev.h" #include "qemu_hotplug.h" #include "qemu_monitor.h" +#include "qemu_monitor_json.h" #include "qemu_process.h" #include "qemu_migration.h" #include "qemu_migration_params.h" @@ -16815,6 +16816,48 @@ qemuDomainCheckpointPrepare(virQEMUDriverPtr drive= r, virCapsPtr caps, return ret; } +static int +qemuDomainCheckpointAddActions(virJSONValuePtr actions, + virDomainCheckpointObjPtr old_current, + virDomainCheckpointDefPtr def) +{ + int i, j; + int ret =3D -1; + + for (i =3D 0; i < def->ndisks; i++) { + virDomainCheckpointDiskDef *disk =3D &def->disks[i]; + + if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) + continue; + if (qemuMonitorJSONTransactionAdd(actions, + "block-dirty-bitmap-add", + "s:node", disk->node, + "s:name", disk->bitmap, + "b:persistent", true, + NULL) < 0) + goto cleanup; + if (old_current) { + for (j =3D 0; j < old_current->def->ndisks; j++) { + virDomainCheckpointDiskDef *disk2; + + disk2 =3D &old_current->def->disks[j]; + if (STRNEQ(disk->node, disk2->node)) + continue; + if (disk2->type =3D=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP && + qemuMonitorJSONTransactionAdd(actions, + "x-block-dirty-bitmap-di= sable", + "s:node", disk->node, + "s:name", disk2->bitmap, + NULL) < 0) + goto cleanup; + } + } + } + ret =3D 0; + + cleanup: + return ret; +} static virDomainCheckpointPtr qemuDomainCheckpointCreateXML(virDomainPtr domain, @@ -16832,6 +16875,9 @@ qemuDomainCheckpointCreateXML(virDomainPtr domain, virDomainCheckpointObjPtr other =3D NULL; virQEMUDriverConfigPtr cfg =3D NULL; virCapsPtr caps =3D NULL; + qemuDomainObjPrivatePtr priv; + virJSONValuePtr actions =3D NULL; + int ret; virCheckFlags(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE | VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT | @@ -16845,6 +16891,7 @@ qemuDomainCheckpointCreateXML(virDomainPtr domain, if (!(vm =3D qemuDomObjFromDomain(domain))) goto cleanup; + priv =3D vm->privateData; cfg =3D virQEMUDriverGetConfig(driver); if (virDomainCheckpointCreateXMLEnsureACL(domain->conn, vm->def) < 0) @@ -16891,6 +16938,7 @@ qemuDomainCheckpointCreateXML(virDomainPtr domain, if (update_current) chk->def->current =3D true; if (vm->current_checkpoint) { + other =3D vm->current_checkpoint; if (!redefine && VIR_STRDUP(chk->def->parent, vm->current_checkpoint->def->name= ) < 0) goto endjob; @@ -16910,7 +16958,14 @@ qemuDomainCheckpointCreateXML(virDomainPtr domain, * makes sense, such as checking that qemu-img recognizes the * checkpoint bitmap name in at least one of the domain's disks? = */ } else { - /* TODO: issue QMP transaction command */ + if (!(actions =3D virJSONValueNewArray())) + goto endjob; + if (qemuDomainCheckpointAddActions(actions, other, chk->def) < 0) + goto endjob; + qemuDomainObjEnterMonitor(driver, vm); + ret =3D qemuMonitorTransaction(priv->mon, &actions); + if (qemuDomainObjExitMonitor(driver, vm) < 0 || ret < 0) + goto endjob; } /* If we fail after this point, there's not a whole lot we can do; @@ -16949,6 +17004,7 @@ qemuDomainCheckpointCreateXML(virDomainPtr domain, qemuDomainObjEndJob(driver, vm); cleanup: + virJSONValueFree(actions); virDomainObjEndAPI(&vm); virDomainCheckpointDefFree(def); VIR_FREE(xml); --=20 2.17.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list