From nobody Fri May 3 06:40:52 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 15519376975751001.6295013675924; Wed, 6 Mar 2019 21:48:17 -0800 (PST) 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 4C7DB30821B4; Thu, 7 Mar 2019 05:48:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6BE1B60139; Thu, 7 Mar 2019 05:48:14 +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 639AF181A12C; Thu, 7 Mar 2019 05:48:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275m6Hg003920 for ; Thu, 7 Mar 2019 00:48:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id B34F45D787; Thu, 7 Mar 2019 05:48:06 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id B38BB5D786; Thu, 7 Mar 2019 05:48:05 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:33 -0600 Message-Id: <20190307054752.19522-2-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 01/20] domain_conf: Expose virDomainStorageNetworkParseHost 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: , 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, 07 Mar 2019 05:48:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" An upcoming patch wants to reuse XML parsing of both unix and tcp network host descriptions in the context of setting up a backup NBD server. Make that easier by refactoring the existing parser. Signed-off-by: Eric Blake Reviewed-by: John Ferlan --- src/conf/domain_conf.h | 2 ++ src/conf/domain_conf.c | 43 ++++++++++++++++++++-------------------- src/libvirt_private.syms | 1 + 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 34c0b8cea1..da89e94083 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3265,6 +3265,8 @@ int virDomainDiskInsert(virDomainDefPtr def, ATTRIBUTE_RETURN_CHECK; void virDomainDiskInsertPreAlloced(virDomainDefPtr def, virDomainDiskDefPtr disk); +int virDomainStorageNetworkParseHost(xmlNodePtr hostnode, + virStorageNetHostDefPtr host); int virDomainDiskDefAssignAddress(virDomainXMLOptionPtr xmlopt, virDomainDiskDefPtr def, const virDomainDef *vmdef); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5e64d23a83..5d57c3cc1a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7460,23 +7460,21 @@ virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr nod= e, } -static int +int virDomainStorageNetworkParseHost(xmlNodePtr hostnode, - virStorageNetHostDefPtr *hosts, - size_t *nhosts) + virStorageNetHostDefPtr host) { int ret =3D -1; - virStorageNetHostDef host; VIR_AUTOFREE(char *) transport =3D NULL; VIR_AUTOFREE(char *) port =3D NULL; - memset(&host, 0, sizeof(host)); - host.transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; + memset(host, 0, sizeof(*host)); + host->transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; /* transport can be tcp (default), unix or rdma. */ if ((transport =3D virXMLPropString(hostnode, "transport"))) { - host.transport =3D virStorageNetHostTransportTypeFromString(transp= ort); - if (host.transport < 0) { + host->transport =3D virStorageNetHostTransportTypeFromString(trans= port); + if (host->transport < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown protocol transport type '%s'"), transport); @@ -7484,17 +7482,17 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnod= e, } } - host.socket =3D virXMLPropString(hostnode, "socket"); + host->socket =3D virXMLPropString(hostnode, "socket"); - if (host.transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_UNIX && - host.socket =3D=3D NULL) { + if (host->transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_UNIX && + host->socket =3D=3D NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing socket for unix transport")); goto cleanup; } - if (host.transport !=3D VIR_STORAGE_NET_HOST_TRANS_UNIX && - host.socket !=3D NULL) { + if (host->transport !=3D VIR_STORAGE_NET_HOST_TRANS_UNIX && + host->socket !=3D NULL) { virReportError(VIR_ERR_XML_ERROR, _("transport '%s' does not support " "socket attribute"), @@ -7502,26 +7500,24 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnod= e, goto cleanup; } - if (host.transport !=3D VIR_STORAGE_NET_HOST_TRANS_UNIX) { - if (!(host.name =3D virXMLPropString(hostnode, "name"))) { + if (host->transport !=3D VIR_STORAGE_NET_HOST_TRANS_UNIX) { + if (!(host->name =3D virXMLPropString(hostnode, "name"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing name for host")); goto cleanup; } if ((port =3D virXMLPropString(hostnode, "port"))) { - if (virStringParsePort(port, &host.port) < 0) + if (virStringParsePort(port, &host->port) < 0) goto cleanup; } } - if (VIR_APPEND_ELEMENT(*hosts, *nhosts, host) < 0) - goto cleanup; - ret =3D 0; cleanup: - virStorageNetHostDefClear(&host); + if (ret < 0) + virStorageNetHostDefClear(host); return ret; } @@ -7536,9 +7532,14 @@ virDomainStorageNetworkParseHosts(xmlNodePtr node, for (child =3D node->children; child; child =3D child->next) { if (child->type =3D=3D XML_ELEMENT_NODE && virXMLNodeNameEqual(child, "host")) { + virStorageNetHostDef host; - if (virDomainStorageNetworkParseHost(child, hosts, nhosts) < 0) + if (virDomainStorageNetworkParseHost(child, &host) < 0) return -1; + if (VIR_APPEND_ELEMENT(*hosts, *nhosts, host) < 0) { + virStorageNetHostDefClear(&host); + return -1; + } } } diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 47acb6a009..8632e6631d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -559,6 +559,7 @@ virDomainStateReasonFromString; virDomainStateReasonToString; virDomainStateTypeFromString; virDomainStateTypeToString; +virDomainStorageNetworkParseHost; virDomainStorageSourceFormat; virDomainStorageSourceParse; virDomainTaintTypeFromString; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937737313215.79866149397094; Wed, 6 Mar 2019 21:48:57 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AF0C687630; Thu, 7 Mar 2019 05:48:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7F3295D783; Thu, 7 Mar 2019 05:48:55 +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 3CAFC181A26C; Thu, 7 Mar 2019 05:48:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275m7BC003930 for ; Thu, 7 Mar 2019 00:48:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id D67725D788; Thu, 7 Mar 2019 05:48:07 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id D70975D786; Thu, 7 Mar 2019 05:48:06 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:34 -0600 Message-Id: <20190307054752.19522-3-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 02/20] qemu: clean up qemuDomainRemoveInactiveCommon 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: , 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 07 Mar 2019 05:48:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use VIR_AUTOFREE and saner formatting. No semantic change. Signed-off-by: Eric Blake Reviewed-by: John Ferlan --- src/qemu/qemu_domain.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 68298ad4e8..e243c07168 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8652,8 +8652,8 @@ static void qemuDomainRemoveInactiveCommon(virQEMUDriverPtr driver, virDomainObjPtr vm) { - char *snapDir; virQEMUDriverConfigPtr cfg; + VIR_AUTOFREE(char *) snapDir =3D NULL; cfg =3D virQEMUDriverGetConfig(driver); @@ -8661,15 +8661,12 @@ qemuDomainRemoveInactiveCommon(virQEMUDriverPtr dri= ver, if (qemuDomainSnapshotDiscardAllMetadata(driver, vm) < 0) { VIR_WARN("unable to remove all snapshots for domain %s", vm->def->name); - } - else if (virAsprintf(&snapDir, "%s/%s", cfg->snapshotDir, - vm->def->name) < 0) { + } else if (virAsprintf(&snapDir, "%s/%s", cfg->snapshotDir, + vm->def->name) < 0) { VIR_WARN("unable to remove snapshot directory %s/%s", cfg->snapshotDir, vm->def->name); - } else { - if (rmdir(snapDir) < 0 && errno !=3D ENOENT) - VIR_WARN("unable to remove snapshot directory %s", snapDir); - VIR_FREE(snapDir); + } else if (rmdir(snapDir) < 0 && errno !=3D ENOENT) { + VIR_WARN("unable to remove snapshot directory %s", snapDir); } qemuExtDevicesCleanupHost(driver, vm->def); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937697540432.39164068966375; Wed, 6 Mar 2019 21:48:17 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A305BDD0; Thu, 7 Mar 2019 05:48:15 +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 65CD31836C; Thu, 7 Mar 2019 05:48:14 +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 ED0F43FB12; Thu, 7 Mar 2019 05:48:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275m9vv003936 for ; Thu, 7 Mar 2019 00:48:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id 157D25D78C; Thu, 7 Mar 2019 05:48:09 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04F7F5D786; Thu, 7 Mar 2019 05:48:07 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:35 -0600 Message-Id: <20190307054752.19522-4-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 03/20] backup: Document nuances between different state capture APIs 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: , 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 07 Mar 2019 05:48:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Upcoming patches will add support for incremental backups via a new API; but first, we need a landing page that gives an overview of capturing various pieces of guest state, and which APIs are best suited to which tasks. Signed-off-by: Eric Blake Reviewed-by: John Ferlan --- v2: wording improvements based on review --- docs/docs.html.in | 5 + docs/domainstatecapture.html.in | 314 ++++++++++++++++++++++++++++++++ docs/formatsnapshot.html.in | 2 + 3 files changed, 321 insertions(+) create mode 100644 docs/domainstatecapture.html.in diff --git a/docs/docs.html.in b/docs/docs.html.in index d0ff844d0c..3afd13080a 100644 --- a/docs/docs.html.in +++ b/docs/docs.html.in @@ -121,6 +121,11 @@
Secure usage
Secure usage of the libvirt APIs
+ +
Domain state + capture
+
Comparison between different methods of capturing domain + state
diff --git a/docs/domainstatecapture.html.in b/docs/domainstatecapture.html= .in new file mode 100644 index 0000000000..f7f2fe0b98 --- /dev/null +++ b/docs/domainstatecapture.html.in @@ -0,0 +1,314 @@ + + + + + +

Domain state capture using Libvirt

+ +
    + +

    + In order to aid application developers to choose which + operations best suit their needs, this page compares the + different means for capturing state related to a domain managed + by libvirt. +

    + +

    + The information here is primarily geared towards capturing the + state of an active domain. Capturing the state of an inactive + domain essentially amounts to copying the contents of guest + disks, followed by a fresh boot with disks restored to that + state. Some of the topics presented below may relate to inactive + state collection, but it is not the primary focus of this page. +

    + +

    State capture trade-offs

    + +

    One of the features made possible with virtual machines is live + migration -- transferring all state related to the guest from + one host to another with minimal interruption to the guest's + activity. In this case, state includes domain memory (including + register and device contents), and domain storage (whether the + guest's view of the disks are backed by local storage on the + host, or by the hypervisor accessing shared storage over a + network). A clever observer will then note that if all state is + available for live migration, then there is nothing stopping a + user from saving some or all of that state at a given point of + time in order to be able to later rewind guest execution back to + the state it previously had. The astute reader will also realize + that state capture at any level requires that the data must be + stored and managed by some mechanism. This processing might fit + in a single file, or more likely require a chain of related + files, and may require synchronization with third-party tools + built around managing the amount of data resulting from + capturing the state of multiple guests that each use multiple + disks. +

    + +

    + There are several libvirt APIs associated with capturing the + state of a guest, which can later be used to rewind that guest + to the conditions it was in earlier. The following is a list of + trade-offs and differences between the various facets that + affect capturing domain state for active domains: +

    + +
    +
    Duration
    +
    Capturing state can be a lengthy process, so while the + captured state ideally represents an atomic point in time + correpsonding to something the guest was actually executing, + capturing state tends to focus on minimizing guest downtime + while performing the rest of the state capture in parallel + with guest execution. Some interfaces require up-front + preparation (the state captured is not complete until the API + ends, which may be some time after the command was first + started), while other interfaces track the state when the + command was first issued, regardless of the time spent in + capturing the rest of the state. Also, time spent in state + capture may be longer than the time required for live + migration, when state must be duplicated rather than shared. +
    + +
    Amount of state
    +
    For an online guest, there is a choice between capturing the + guest's memory (all that is needed during live migration when + the storage is already shared between source and destination), + the guest's disk state (all that is needed if there are no + pending guest I/O transactions that would be lost without the + corresponding memory state), or both together. Reverting to + partial state may still be viable, but typically, booting from + captured disk state without corresponding memory is comparable + to rebooting a machine that had power cut before I/O could be + flushed. Guests may need to use proper journaling methods to + avoid problems when booting from partial state. +
    + +
    Quiescing of data
    +
    Even if a guest has no pending I/O, capturing disk state may + catch the guest at a time when the contents of the disk are + inconsistent. Cooperating with the guest to perform data + quiescing is an optional step to ensure that captured disk + state is fully consistent without requiring additional memory + state, rather than just crash-consistent. But guest + cooperation may also have time constraints, where the guest + can rightfully panic if there is too much downtime while I/O + is frozen. +
    + +
    Quantity of files
    +
    When capturing state, some approaches store all state within + the same file (internal), while others expand a chain of + related files that must be used together (external), for more + files that a management application must track. +
    + +
    Impact to guest definition
    +
    Capturing state may require temporary changes to the guest + definition, such as associating new files into the domain + definition. While state capture should never impact the + running guest, a change to the domain's active XML may have + impact on other host operations being performed on the domain. +
    + +
    Third-party integration
    +
    When capturing state, there are tradeoffs to how much of the + process must be done directly by the hypervisor, and how much + can be off-loaded to third-party software. Since capturing + state is not instantaneous, it is essential that any + third-party integration see consistent data even if the + running guest continues to modify that data after the point in + time of the capture.
    + +
    Full vs. incremental
    +
    When periodically repeating the action of state capture, it + is useful to minimize the amount of state that must be + captured by exploiting the relation to a previous capture, + such as focusing only on the portions of the disk that the + guest has modified in the meantime. Some approaches are able + to take advantage of checkpoints to provide an incremental + backup, while others are only capable of a full backup even if + that means re-capturing unchanged portions of the disk.
    + +
    Local vs. remote
    +
    Domains that completely use remote storage may only need + some mechanism to keep track of guest memory state while using + external means to manage storage. Still, hypervisor and guest + cooperation to ensure points in time when no I/O is in flight + across the network can be important for properly capturing + disk state.
    + +
    Network latency
    +
    Whether it's domain storage or saving domain state into + remote storage, network latency has an impact on snapshot + data. Having dedicated network capacity, bandwidth, or quality + of service levels may play a role, as well as planning for how + much of the backup process needs to be local.
    +
    + +

    + An example of the various facets in action is migration of a + running guest. In order for the guest to be able to resume on + the destination at the same place it left off at the source, the + hypervisor has to get to a point where execution on the source + is stopped, the last remaining changes occurring since the + migration started are then transferred, and the guest is started + on the target. The management software thus must keep track of + the starting point and any changes since the starting + point. These last changes are often referred to as dirty page + tracking or dirty disk block bitmaps. At some point in time + during the migration, the management software must freeze the + source guest, transfer the dirty data, and then start the guest + on the target. This period of time must be minimal. To minimize + overall migration time, one is advised to use a dedicated + network connection with a high quality of service. Alternatively + saving the current state of the running guest can just be a + point in time type operation which doesn't require updating the + "last vestiges" of state prior to writing out the saved state + file. The state file is the point in time of whatever is current + and may contain incomplete data which if used to restart the + guest could cause confusion or problems because some operation + wasn't completed depending upon where in time the operation was + commenced. +

    + +

    State capture APIs

    +

    With those definitions, the following libvirt APIs related to + state capture have these properties:

    +
    +
    virDomainManagedSave
    +
    This API saves guest memory, with libvirt managing all of + the saved state, then stops the guest. While stopped, the + disks can be copied by a third party. However, since any + subsequent restart of the guest by libvirt API will restore + the memory state (which typically only works if the disk state + is unchanged in the meantime), and since it is not possible to + get at the memory state that libvirt is managing, this is not + viable as a means for rolling back to earlier saved states, + but is rather more suited to situations such as suspending a + guest prior to rebooting the host in order to resume the guest + when the host is back up. This API also has a drawback of + potentially long guest downtime, and therefore does not lend + itself well to live backups.
    + +
    virDomainSave
    +
    This API is similar to virDomainManagedSave(), but moves the + burden on managing the stored memory state to the user. As + such, the user can now couple saved state with copies of the + disks to perform a revert to an arbitrary earlier saved state. + However, changing who manages the memory state does not change + the drawback of potentially long guest downtime when capturing + state.
    + +
    virDomainSnapshotCreateXML()
    +
    This API wraps several approaches for capturing guest state, + with a general premise of creating a snapshot (where the + current guest resources are frozen in time and a new wrapper + layer is opened for tracking subsequent guest changes). It + can operate on both offline and running guests, can choose + whether to capture the state of memory, disk, or both when + used on a running guest, and can choose between internal and + external storage for captured state. However, it is geared + towards post-event captures (when capturing both memory and + disk state, the disk state is not captured until all memory + state has been collected first). Using QEMU as the + hypervisor, internal snapshots currently have lengthy downtime + that is incompatible with freezing guest I/O, but external + snapshots are quick. Since creating an external snapshot + changes which disk image resource is in use by the guest, this + API can be coupled with virDomainBlockCommit() to + restore things back to the guest using its original disk + image, where a third-party tool can read the backing file + prior to the live commit. See also + the XML details used with + this command.
    + +
    virDomainFSFreeze(), virDomainFSThaw()
    +
    This pair of APIs does not directly capture guest state, but + can be used to coordinate with a trusted live guest that state + capture is about to happen, and therefore guest I/O should be + quiesced so that the state capture is fully consistent, rather + than merely crash consistent. Some APIs are able to + automatically perform a freeze and thaw via a flags parameter, + rather than having to make separate calls to these + functions. Also, note that freezing guest I/O is only possible + with trusted guests running a guest agent, and that some + guests place maximum time limits on how long I/O can be + frozen.
    + +
    virDomainBlockCopy()
    +
    This API wraps approaches for capturing the disk state (but + not memory) of a running guest, but does not track + accompanying guest memory state, but can only operate on one + block device per job. To get a consistent copy of multiple + disks, multiple jobs just be run in parallel, then the domain + must be paused before ending all of the jobs. The capture is + consistent only at the end of the operation with a choice for + future guest changes to either pivot to the new file or to + resume to just using the original file. The resulting backup + file is thus the other file no longer in use by the + guest.
    + +
    virDomainCheckpointCreateXML()
    +
    This API does not actually capture guest state, rather it + makes it possible to track which portions of guest disks have + changed between a checkpoint and the current live execution of + the guest. However, while it is possible use this API to + create checkpoints in isolation, it is more typical to create + a checkpoint as a side-effect of starting a new incremental + backup with virDomainBackupBegin(), since a + second incremental backup is most useful when using the + checkpoint created during the first.
    + +
    virDomainBackupBegin(), virDomainBackupEnd()
    +
    This API wraps approaches for capturing the state of disks + of a running guest, but does not track accompanying guest + memory state. The capture is consistent to the start of the + operation, where the captured state is stored independently + from the disk image in use with the guest and where it can be + easily integrated with a third-party for capturing the disk + state. Since the backup operation is stored externally from + the guest resources, there is no need to commit data back in + at the completion of the operation. When coupled with + checkpoints, this can be used to capture incremental backups + instead of full.
    +
    + +

    Examples

    +

    The following two sequences both accomplish the task of + capturing the disk state of a running guest, then wrapping + things up so that the guest is still running with the same file + as its disk image as before the sequence of operations began. + The difference between the two sequences boils down to the + impact of an unexpected interruption made at any point in the + middle of the sequence: with such an interruption, the first + example leaves the guest tied to a temporary wrapper file rather + than the original disk, and requires manual clean up of the + domain definition; while the second example has no impact to the + domain definition.

    + +

    1. Backup via temporary snapshot +

    +virDomainFSFreeze()
    +virDomainSnapshotCreateXML(VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY)
    +virDomainFSThaw()
    +third-party copy the backing file to backup storage # most time spent here
    +virDomainBlockCommit(VIR_DOMAIN_BLOCK_COMMIT_ACTIVE) per disk
    +wait for commit ready event per disk
    +virDomainBlockJobAbort() per disk
    +      

    + +

    2. Direct backup +

    +virDomainFSFreeze()
    +virDomainBackupBegin()
    +virDomainFSThaw()
    +wait for push mode event, or pull data over NBD # most time spent here
    +virDomainBackeupEnd()
    +    

    + + + diff --git a/docs/formatsnapshot.html.in b/docs/formatsnapshot.html.in index c60b4fb7c9..9ee355198f 100644 --- a/docs/formatsnapshot.html.in +++ b/docs/formatsnapshot.html.in @@ -9,6 +9,8 @@

    Snapshot XML

    + Snapshots are one form + of domain state capture. There are several types of snapshots:

    --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937715987554.499210245586; Wed, 6 Mar 2019 21:48:35 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3BE33C05B1CB; Thu, 7 Mar 2019 05:48:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1594E19C68; Thu, 7 Mar 2019 05:48:34 +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 CFB69181A136; Thu, 7 Mar 2019 05:48:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275mAo5003947 for ; Thu, 7 Mar 2019 00:48:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3529D5D786; Thu, 7 Mar 2019 05:48:10 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 375295D783; Thu, 7 Mar 2019 05:48:09 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:36 -0600 Message-Id: <20190307054752.19522-5-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 04/20] backup: Introduce virDomainCheckpointPtr 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 07 Mar 2019 05:48:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Prepare for introducing a bunch of new public APIs related to backup checkpoints by first introducing a new internal type and errors associated with that type. Checkpoints are modeled heavily after virDomainSnapshotPtr (both represent a point in time of the guest), although a snapshot exists with the intent of rolling back to that state, while a checkpoint exists to make it possible to create an incremental backup at a later time. Signed-off-by: Eric Blake Reviewed-by: John Ferlan --- v5: minor review tweaks [John] --- include/libvirt/virterror.h | 6 +++- src/util/virerror.c | 12 ++++++- include/libvirt/libvirt.h | 6 +++- src/datatypes.h | 31 +++++++++++++++++- src/datatypes.c | 63 ++++++++++++++++++++++++++++++++++++- src/libvirt_private.syms | 2 ++ 6 files changed, 115 insertions(+), 5 deletions(-) diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 3c19ff5e2e..bccf3c731e 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -4,7 +4,7 @@ * Description: Provides the interfaces of the libvirt library to handle * errors raised while using the library. * - * Copyright (C) 2006-2016 Red Hat, Inc. + * Copyright (C) 2006-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -132,6 +132,7 @@ typedef enum { VIR_FROM_LIBSSH =3D 66, /* Error from libssh connection transpor= t */ VIR_FROM_RESCTRL =3D 67, /* Error from resource control */ VIR_FROM_FIREWALLD =3D 68, /* Error from firewalld */ + VIR_FROM_DOMAIN_CHECKPOINT =3D 69,/* Error from domain checkpoint */ # ifdef VIR_ENUM_SENTINELS VIR_ERR_DOMAIN_LAST @@ -322,6 +323,9 @@ typedef enum { VIR_ERR_DEVICE_MISSING =3D 99, /* fail to find the desired devi= ce */ VIR_ERR_INVALID_NWFILTER_BINDING =3D 100, /* invalid nwfilter binding= */ VIR_ERR_NO_NWFILTER_BINDING =3D 101, /* no nwfilter binding */ + VIR_ERR_INVALID_DOMAIN_CHECKPOINT =3D 102, /* invalid domain checkpoin= t */ + VIR_ERR_NO_DOMAIN_CHECKPOINT =3D 103, /* domain checkpoint not found */ + VIR_ERR_NO_DOMAIN_BACKUP =3D 104, /* domain backup job id not foun= d */ # ifdef VIR_ENUM_SENTINELS VIR_ERR_NUMBER_LAST diff --git a/src/util/virerror.c b/src/util/virerror.c index 91a513160f..05e535d859 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -1,7 +1,7 @@ /* * virerror.c: error handling and reporting code for libvirt * - * Copyright (C) 2006, 2008-2016 Red Hat, Inc. + * Copyright (C) 2006-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -139,6 +139,7 @@ VIR_ENUM_IMPL(virErrorDomain, VIR_ERR_DOMAIN_LAST, "Libssh transport layer", "Resource control", "FirewallD", + "Domain Checkpoint", ); @@ -1214,6 +1215,15 @@ const virErrorMsgTuple virErrorMsgStrings[VIR_ERR_NU= MBER_LAST] =3D { [VIR_ERR_NO_NWFILTER_BINDING] =3D { N_("Network filter binding not found"), N_("Network filter binding not found: %s") }, + [VIR_ERR_INVALID_DOMAIN_CHECKPOINT] =3D { + N_("Invalid domain checkpoint"), + N_("Invalid domain checkpoint: %s") }, + [VIR_ERR_NO_DOMAIN_CHECKPOINT] =3D { + N_("Domain checkpoint not found"), + N_("Domain checkpoint not found: %s") }, + [VIR_ERR_NO_DOMAIN_BACKUP] =3D { + N_("Domain backup job id not found"), + N_("Domain backup job id not found: %s") }, }; diff --git a/include/libvirt/libvirt.h b/include/libvirt/libvirt.h index 20e5d276a7..13de151cb6 100644 --- a/include/libvirt/libvirt.h +++ b/include/libvirt/libvirt.h @@ -4,7 +4,7 @@ * Description: Provides the interfaces of the libvirt library to handle * virtualized domains * - * Copyright (C) 2005-2006, 2010-2014 Red Hat, Inc. + * Copyright (C) 2005-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -34,6 +34,10 @@ extern "C" { # include # include # include +/* FIXME: Temporary hack until later patch creates new + * libvirt-domain-checkpoint.h file */ +typedef struct _virDomainCheckpoint virDomainCheckpoint; +typedef virDomainCheckpoint *virDomainCheckpointPtr; # include # include # include diff --git a/src/datatypes.h b/src/datatypes.h index 12015679f3..7c45a016c2 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -1,7 +1,7 @@ /* * datatypes.h: management of structs for public data types * - * Copyright (C) 2006-2015 Red Hat, Inc. + * Copyright (C) 2006-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -31,6 +31,7 @@ extern virClassPtr virConnectClass; extern virClassPtr virDomainClass; +extern virClassPtr virDomainCheckpointClass; extern virClassPtr virDomainSnapshotClass; extern virClassPtr virInterfaceClass; extern virClassPtr virNetworkClass; @@ -307,6 +308,21 @@ extern virClassPtr virAdmClientClass; } \ } while (0) +# define virCheckDomainCheckpointReturn(obj, retval) \ + do { \ + virDomainCheckpointPtr _check =3D (obj); \ + if (!virObjectIsClass(_check, virDomainCheckpointClass) || \ + !virObjectIsClass(_check->domain, virDomainClass) || \ + !virObjectIsClass(_check->domain->conn, virConnectClass)) { \ + virReportErrorHelper(VIR_FROM_DOMAIN_CHECKPOINT, \ + VIR_ERR_INVALID_DOMAIN_CHECKPOINT, \ + __FILE__, __FUNCTION__, __LINE__, \ + __FUNCTION__); \ + virDispatchError(NULL); \ + return retval; \ + } \ + } while (0) + /* Helper macros to implement VIR_DOMAIN_DEBUG using just C99. This * assumes you pass fewer than 15 arguments to VIR_DOMAIN_DEBUG, but @@ -668,6 +684,17 @@ struct _virStream { virFreeCallback ff; }; +/** + * _virDomainCheckpoint + * + * Internal structure associated with a domain checkpoint + */ +struct _virDomainCheckpoint { + virObject parent; + char *name; + virDomainPtr domain; +}; + /** * _virDomainSnapshot * @@ -744,6 +771,8 @@ virNWFilterPtr virGetNWFilter(virConnectPtr conn, virNWFilterBindingPtr virGetNWFilterBinding(virConnectPtr conn, const char *portdev, const char *filtername); +virDomainCheckpointPtr virGetDomainCheckpoint(virDomainPtr domain, + const char *name); virDomainSnapshotPtr virGetDomainSnapshot(virDomainPtr domain, const char *name); diff --git a/src/datatypes.c b/src/datatypes.c index 9b92d892d5..fec3b9821e 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -1,7 +1,7 @@ /* * datatypes.c: management of structs for public data types * - * Copyright (C) 2006-2015 Red Hat, Inc. + * Copyright (C) 2006-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -36,6 +36,7 @@ VIR_LOG_INIT("datatypes"); virClassPtr virConnectClass; virClassPtr virConnectCloseCallbackDataClass; virClassPtr virDomainClass; +virClassPtr virDomainCheckpointClass; virClassPtr virDomainSnapshotClass; virClassPtr virInterfaceClass; virClassPtr virNetworkClass; @@ -50,6 +51,7 @@ virClassPtr virStoragePoolClass; static void virConnectDispose(void *obj); static void virConnectCloseCallbackDataDispose(void *obj); static void virDomainDispose(void *obj); +static void virDomainCheckpointDispose(void *obj); static void virDomainSnapshotDispose(void *obj); static void virInterfaceDispose(void *obj); static void virNetworkDispose(void *obj); @@ -86,6 +88,7 @@ virDataTypesOnceInit(void) DECLARE_CLASS_LOCKABLE(virConnect); DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData); DECLARE_CLASS(virDomain); + DECLARE_CLASS(virDomainCheckpoint); DECLARE_CLASS(virDomainSnapshot); DECLARE_CLASS(virInterface); DECLARE_CLASS(virNetwork); @@ -957,6 +960,64 @@ virDomainSnapshotDispose(void *obj) } +/** + * virGetDomainCheckpoint: + * @domain: the domain to checkpoint + * @name: pointer to the domain checkpoint name + * + * Allocates a new domain checkpoint object. When the object is no longer = needed, + * virObjectUnref() must be called in order to not leak data. + * + * Returns a pointer to the domain checkpoint object, or NULL on error. + */ +virDomainCheckpointPtr +virGetDomainCheckpoint(virDomainPtr domain, + const char *name) +{ + virDomainCheckpointPtr ret =3D NULL; + + if (virDataTypesInitialize() < 0) + return NULL; + + virCheckDomainGoto(domain, error); + virCheckNonNullArgGoto(name, error); + + if (!(ret =3D virObjectNew(virDomainCheckpointClass))) + goto error; + if (VIR_STRDUP(ret->name, name) < 0) + goto error; + + ret->domain =3D virObjectRef(domain); + + return ret; + + error: + virObjectUnref(ret); + return NULL; +} + + +/** + * virDomainCheckpointDispose: + * @obj: the domain checkpoint to release + * + * Unconditionally release all memory associated with a checkpoint. + * The checkpoint object must not be used once this method returns. + * + * It will also unreference the associated connection object, + * which may also be released if its ref count hits zero. + */ +static void +virDomainCheckpointDispose(void *obj) +{ + virDomainCheckpointPtr checkpoint =3D obj; + VIR_DEBUG("release checkpoint %p %s", checkpoint, checkpoint->name); + + VIR_FREE(checkpoint->name); + virObjectUnref(checkpoint->domain); +} + + virAdmConnectPtr virAdmConnectNew(void) { diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8632e6631d..13ef94149b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1234,10 +1234,12 @@ virConnectCloseCallbackDataClass; virConnectCloseCallbackDataGetCallback; virConnectCloseCallbackDataRegister; virConnectCloseCallbackDataUnregister; +virDomainCheckpointClass; virDomainClass; virDomainSnapshotClass; virGetConnect; virGetDomain; +virGetDomainCheckpoint; virGetDomainSnapshot; virGetInterface; virGetNetwork; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937717079717.2764085180935; Wed, 6 Mar 2019 21:48:37 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E06CA796; Thu, 7 Mar 2019 05:48:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E826F1001E61; Thu, 7 Mar 2019 05:48:34 +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 A8336181A13B; Thu, 7 Mar 2019 05:48:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275mBGV003962 for ; Thu, 7 Mar 2019 00:48:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 70F1E5D78C; Thu, 7 Mar 2019 05:48:11 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57DB45D783; Thu, 7 Mar 2019 05:48:10 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:37 -0600 Message-Id: <20190307054752.19522-6-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 05/20] wip: backup: Document new XML for backups 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 07 Mar 2019 05:48:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" wip: Still need to incorporate v4 review comments... Prepare for new checkpoint and backup APIs by describing the XML that will represent a checkpoint and backup. The checkpoint XML is modeled heavily after virDomainSnapshotPtr, since both represent a point in time of the guest (however, a snapshot exists with the intent to roll back to that point, while a checkpoint exists to facilitate later incremental backups). Meanwhile, the backup XML has enough information to represent both push model (the hypervisor writes the backup file to a location of the user's choice) and the pull model (the hypervisor needs local temporary storage, and also creates an NBD server that the user can use to read the backup via a third-party client).. But while a snapshot exists with the intent of rolling back to that state, a checkpoint instead makes it possible to create an incremental backup at a later time. Add testsuite coverage for some minimal uses of both XML. Ultimately, I'd love for push model backups to target a network driver rather than just a local file or block device; but doing that got hairy (while uses as the description of a host or network resource, I picked as the description of a push model backup target [defaults to qcow2 but can also be raw or any other format], and as the description of a pull model backup scratch space [must be qcow2]). The ideal refactoring would be a way to parameterize RNG to accept ... so that the name of the subelement can be for domain, or or as needed for backups. Future patches may improve this area of code. Signed-off-by: Eric Blake --- docs/docs.html.in | 4 +- docs/domainstatecapture.html.in | 4 +- docs/format.html.in | 2 + docs/formatbackup.html.in | 123 ++++++++++++ docs/formatcheckpoint.html.in | 188 +++++++++++++++++++ docs/index.html.in | 4 +- docs/schemas/domainbackup.rng | 185 ++++++++++++++++++ docs/schemas/domaincheckpoint.rng | 94 ++++++++++ libvirt.spec.in | 2 + mingw-libvirt.spec.in | 4 + tests/Makefile.am | 6 +- tests/domainbackupxml2xmlin/backup-pull.xml | 9 + tests/domainbackupxml2xmlin/backup-push.xml | 9 + tests/domainbackupxml2xmlin/empty.xml | 1 + tests/domainbackupxml2xmlout/backup-pull.xml | 9 + tests/domainbackupxml2xmlout/backup-push.xml | 9 + tests/domainbackupxml2xmlout/empty.xml | 7 + tests/domaincheckpointxml2xmlin/empty.xml | 1 + tests/domaincheckpointxml2xmlin/sample.xml | 7 + tests/domaincheckpointxml2xmlout/empty.xml | 10 + tests/domaincheckpointxml2xmlout/sample.xml | 16 ++ tests/virschematest.c | 4 + 22 files changed, 693 insertions(+), 5 deletions(-) create mode 100644 docs/formatbackup.html.in create mode 100644 docs/formatcheckpoint.html.in create mode 100644 docs/schemas/domainbackup.rng create mode 100644 docs/schemas/domaincheckpoint.rng create mode 100644 tests/domainbackupxml2xmlin/backup-pull.xml create mode 100644 tests/domainbackupxml2xmlin/backup-push.xml create mode 100644 tests/domainbackupxml2xmlin/empty.xml create mode 100644 tests/domainbackupxml2xmlout/backup-pull.xml create mode 100644 tests/domainbackupxml2xmlout/backup-push.xml create mode 100644 tests/domainbackupxml2xmlout/empty.xml create mode 100644 tests/domaincheckpointxml2xmlin/empty.xml create mode 100644 tests/domaincheckpointxml2xmlin/sample.xml create mode 100644 tests/domaincheckpointxml2xmlout/empty.xml create mode 100644 tests/domaincheckpointxml2xmlout/sample.xml diff --git a/docs/docs.html.in b/docs/docs.html.in index 3afd13080a..057524521f 100644 --- a/docs/docs.html.in +++ b/docs/docs.html.in @@ -80,7 +80,9 @@ storage pool capabilities, node devices, secrets, - snapshots + snapshots, + checkpoints, + backup jobs
    URI format
    The URI formats used for connecting to libvirt
    diff --git a/docs/domainstatecapture.html.in b/docs/domainstatecapture.html= .in index f7f2fe0b98..9b890b4c0c 100644 --- a/docs/domainstatecapture.html.in +++ b/docs/domainstatecapture.html.in @@ -259,9 +259,9 @@ a checkpoint as a side-effect of starting a new incremental backup with virDomainBackupBegin(), since a second incremental backup is most useful when using the - checkpoint created during the first. + this command.
    virDomainBackupBegin(), virDomainBackupEnd()
    This API wraps approaches for capturing the state of disks diff --git a/docs/format.html.in b/docs/format.html.in index 640a9957ee..e287b430bc 100644 --- a/docs/format.html.in +++ b/docs/format.html.in @@ -25,6 +25,8 @@
  • Node devices
  • Secrets
  • Snapshots
  • +
  • Checkpoints
  • +
  • Backup jobs
  • Command line validation

    diff --git a/docs/formatbackup.html.in b/docs/formatbackup.html.in new file mode 100644 index 0000000000..b721f30de6 --- /dev/null +++ b/docs/formatbackup.html.in @@ -0,0 +1,123 @@ + + + + +

    Backup XML format

    + +
      + +

      Backup XML

      + +

      + Creating a backup, whether full or incremental, is done + via virDomainBackupBegin(), which takes an XML + description of the actions to perform, as well as an optional + second XML document describing a + checkpoint to create at the same point in time. See + also a comparison between + the various state capture APIs. +

      +

      + There are two general modes for backups: a push mode (where the + hypervisor writes out the data to the destination file, which + may be local or remote), and a pull mode (where the hypervisor + creates an NBD server that a third-party client can then read as + needed, and which requires the use of temporary storage, + typically local, until the backup is complete). +

      +

      + The instructions for beginning a backup job are provided as + attributes and elements of the + top-level domainbackup element. This element + includes an optional attribute mode which can be + either "push" or "pull" (default push). Where elements are + optional on creation, virDomainBackupGetXMLDesc() + can be used to see the actual values selected (for example, + learning which port the NBD server is using in the pull model, + or what file names libvirt generated when none were supplied). + The following child elements are supported: +

      +
      +
      incremental
      +
      Optional. If this element is present, it must name an + existing checkpoint of the domain, which will be used to make + this backup an incremental one (in the push model, only + changes since the checkpoint are written to the destination; + in the pull model, the NBD server uses the + NBD_OPT_SET_META_CONTEXT extension to advertise to the client + which portions of the export contain changes since the + checkpoint). If omitted, a full backup is performed. +
      +
      server
      +
      Present only for a pull mode backup. Contains the same + attributes as the protocol element of a disk + attached via NBD in the domain (such as transport, socket, + name, port, or tls), necessary to set up an NBD server that + exposes the content of each disk at the time the backup + started. +
      +
      disks
      +
      This is an optional listing of instructions for disks + participating in the backup (if omitted, all disks + participate, and libvirt attempts to generate filenames by + appending the current timestamp as a suffix). When provided on + input, disks omitted from the list do not participate in the + backup. On output, the list is present but contains only the + disks participating in the backup job. This element has a + list of disk sub-elements, describing anywhere + from one to all of the disks associated with the domain. +
      +
      disk
      +
      This sub-element describes the backup properties of + a specific disk. The attribute name is + mandatory, and must match either the <target + dev=3D'name'/> or an unambiguous <source + file=3D'name'/> of one of + the disk + devices specified for the domain at the time of the + checkpoint. The optional attribute type can + be file, block, + or network, similar to a disk declaration for + a domain, controls what additional sub-elements are needed + to describe the destination (such as protocol + for a network destination). In push mode backups, the + primary sub-element is target; in pull mode, + the primary sub-element is scratch; but + either way, the primary sub-element describes the file + name to be used during the backup operation, similar to + the source sub-element of a domain disk. In + push mode, an optional sub-element driver can + also be used, with an attribute type to + specify a destination format different from + qcow2. Additionally, if a push backup is not + incremental, target may contain an optional + attribute shallow=3D"on" so that the + destination file copies only the top-most source file in a + backing chain, rather than collapsing the entire chain + into the copy. +
      +
      +
      +
      + +

      Examples

      + +

      With an earlier checkpoint created created with the + name 1525889631, we can make a call + to virDomainBackupBegin() to perform an incremental + backup of just the data changed since that checkpoint, using the + following XML to start a pull model NBD export of the vda disk: +

      +
      +<domainbackup mode=3D"pull">
      +  <incremental>1525889631</incremental>
      +  <server transport=3D"unix" socket=3D"/path/to/server"/>
      +  <disks/>
      +    <disk name=3D'vda' type=3D'file'>
      +      <scratch file=3D'/path/to/file1.scratch'/>
      +    </disk>
      +  </disks/>
      +</domainbackup>
      +    
      + + diff --git a/docs/formatcheckpoint.html.in b/docs/formatcheckpoint.html.in new file mode 100644 index 0000000000..7a2354c78f --- /dev/null +++ b/docs/formatcheckpoint.html.in @@ -0,0 +1,188 @@ + + + + +

      Checkpoint XML format

      + +
        + +

        Checkpoint XML

        + +

        + One method of capturing domain disk backups is via the use of + incremental backups. Right now, incremental backups are only + supported for the qemu hypervisor when using qcow2 disks at the + active layer; if other disk formats are in use, capturing disk + backups requires different libvirt APIs + (see domain state capture + for a comparison between APIs). +

        +

        + Libvirt is able to facilitate incremental backups by tracking + disk checkpoints, which are points in time against which it is + easy to compute which portion of the disk has changed. Given a + full backup (a backup created from the creation of the disk to a + given point in time), coupled with the creation of a disk + checkpoint at that time, and an incremental backup (a backup + created from just the dirty portion of the disk between the + first checkpoint and the second backup operation), it is + possible to do an offline reconstruction of the state of the + disk at the time of the second backup without having to copy as + much data as a second full backup would require. Most disk + checkpoints are created in concert with a backup + via virDomainBackupBegin(); however, libvirt also + exposes enough support to create disk checkpoints independently + from a backup operation + via virDomainCheckpointCreateXML(). +

        +

        + Attributes of libvirt checkpoints are stored as child elements + of the domaincheckpoint element. At checkpoint + creation time, normally only + the name, description, + and disks elements are settable. The rest of the + fields are ignored on creation and will be filled in by libvirt + in for informational purposes + by virDomainCheckpointGetXMLDesc(). However, when + redefining a checkpoint, with + the VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE flag + of virDomainCheckpointCreateXML(), all of the XML + fields described here are relevant. +

        +

        + Checkpoints are maintained in a hierarchy. A domain can have a + current checkpoint, which is the most recent checkpoint compared to + the current state of the domain (although a domain might have + checkpoints without a current checkpoint, if checkpoints have been + deleted in the meantime). Creating or reverting to a checkpoint + sets that checkpoint as current, and the prior current checkpoint is + the parent of the new checkpoint. Branches in the hierarchy can + be formed by reverting to a checkpoint with a child, then creating + another checkpoint. +

        +

        + The top-level domaincheckpoint element may contain + the following elements: +

        +
        +
        name
        +
        The name for this checkpoint. If the name is specified when + initially creating the checkpoint, then the checkpoint will have + that particular name. If the name is omitted when initially + creating the checkpoint, then libvirt will make up a name for + the checkpoint, based on the time when it was created. +
        +
        description
        +
        A human-readable description of the checkpoint. If the + description is omitted when initially creating the checkpoint, + then this field will be empty. +
        +
        disks
        +
        On input, this is an optional listing of specific + instructions for disk checkpoints; it is needed when making a + checkpoint on only a subset of the disks associated with a + domain (in particular, since qemu checkpoints require qcow2 + disks, this element may be needed on input for excluding guest + disks that are not in qcow2 format); if the entire element was + omitted on input, then all disks participate in the + checkpoint, but if individual disks were omitted from the + element, they will not be part of the checkpoint. On output, + this is fully populated to show the state of each disk in the + checkpoint. This element has a list of disk + sub-elements, describing anywhere from one to all of the disks + associated with the domain. +
        +
        disk
        +
        This sub-element describes the checkpoint properties of + a specific disk. The attribute name is + mandatory, and must match either the <target + dev=3D'name'/> or an unambiguous <source + file=3D'name'/> of one of + the disk + devices specified for the domain at the time of the + checkpoint. The attribute checkpoint is + optional on input; possible values are no + when the disk does not participate in this checkpoint; + or bitmap if the disk will track all changes + since the creation of this checkpoint via a bitmap, in + which case another attribute bitmap will be + the name of the tracking bitmap (defaulting to the + checkpoint name). On output, an additional + attribute size may be present if + the VIR_DOMAIN_CHECKPOINT_XML_SIZE flag was + used to perform a dynamic query of the estimated size in + bytes of the changes made since the checkpoint was created. +
        +
        +
        +
        creationTime
        +
        The time this checkpoint was created. The time is specified + in seconds since the Epoch, UTC (i.e. Unix time). Readonly. +
        +
        parent
        +
        The parent of this checkpoint. If present, this element + contains exactly one child element, name. This specifies the + name of the parent checkpoint of this one, and is used to + represent trees of checkpoints. Readonly. +
        +
        domain
        +
        The inactive domain + configuration at the time the checkpoint was created. + Readonly. +
        +
        + +

        Examples

        + +

        Using this XML to create a checkpoint of just vda on a qemu + domain with two disks and a prior checkpoint:

        +
        +<domaincheckpoint>
        +  <description>Completion of updates after OS install</descriptio=
        n>
        +  <disks>
        +    <disk name=3D'vda' checkpoint=3D'bitmap'/>
        +    <disk name=3D'vdb' checkpoint=3D'no'/>
        +  </disks>
        +</domaincheckpoint>
        + +

        will result in XML similar to this from + virDomainCheckpointGetXMLDesc():

        +
        +<domaincheckpoint>
        +  <name>1525889631</name>
        +  <description>Completion of updates after OS install</descriptio=
        n>
        +  <creationTime>1525889631</creationTime>
        +  <parent>
        +    <name>1525111885</name>
        +  </parent>
        +  <disks>
        +    <disk name=3D'vda' checkpoint=3D'bitmap' bitmap=3D'1525889631'/>
        +    <disk name=3D'vdb' checkpoint=3D'no'/>
        +  </disks>
        +  <domain type=3D'qemu'>
        +    <name>fedora</name>
        +    <uuid>93a5c045-6457-2c09-e56c-927cdf34e178</uuid>
        +    <memory>1048576</memory>
        +    ...
        +    <devices>
        +      <disk type=3D'file' device=3D'disk'>
        +        <driver name=3D'qemu' type=3D'qcow2'/>
        +        <source file=3D'/path/to/file1'/>
        +        <target dev=3D'vda' bus=3D'virtio'/>
        +      </disk>
        +      <disk type=3D'file' device=3D'disk' snapshot=3D'external'>
        +        <driver name=3D'qemu' type=3D'raw'/>
        +        <source file=3D'/path/to/file2'/>
        +        <target dev=3D'vdb' bus=3D'virtio'/>
        +      </disk>
        +      ...
        +    </devices>
        +  </domain>
        +</domaincheckpoint>
        + +

        With that checkpoint created, the qcow2 image is now tracking + all changes that occur in the image since the checkpoint via + the persistent bitmap named 1525889631. +

        + + diff --git a/docs/index.html.in b/docs/index.html.in index f593445d06..167a58da58 100644 --- a/docs/index.html.in +++ b/docs/index.html.in @@ -69,7 +69,9 @@ storage pool capabilities, node devices, secrets, - snapshots
        + snapshots, + checkpoints, + backup jobs
        Wiki
        Read further community contributed content
        diff --git a/docs/schemas/domainbackup.rng b/docs/schemas/domainbackup.rng new file mode 100644 index 0000000000..edc68a37cf --- /dev/null +++ b/docs/schemas/domainbackup.rng @@ -0,0 +1,185 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + push + + + + + + + pull + + + + + + + + tcp + + + + + + + + + + + + + + + + + + unix + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + file + + + + + + + + + + + + + + + + disk + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + file + + + + + + + + + + + + + disk + + + + + + + + + + + + + + + + + diff --git a/docs/schemas/domaincheckpoint.rng b/docs/schemas/domaincheckpo= int.rng new file mode 100644 index 0000000000..d8dfda9f1c --- /dev/null +++ b/docs/schemas/domaincheckpoint.rng @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + no + + + + + bitmap + + + + + + + + + + + + + + + + + + diff --git a/libvirt.spec.in b/libvirt.spec.in index 82681eea42..b842bb2424 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -1809,7 +1809,9 @@ exit 0 %{_datadir}/libvirt/schemas/capability.rng %{_datadir}/libvirt/schemas/cputypes.rng %{_datadir}/libvirt/schemas/domain.rng +%{_datadir}/libvirt/schemas/domainbackup.rng %{_datadir}/libvirt/schemas/domaincaps.rng +%{_datadir}/libvirt/schemas/domaincheckpoint.rng %{_datadir}/libvirt/schemas/domaincommon.rng %{_datadir}/libvirt/schemas/domainsnapshot.rng %{_datadir}/libvirt/schemas/interface.rng diff --git a/mingw-libvirt.spec.in b/mingw-libvirt.spec.in index bea822fd73..f407526e1a 100644 --- a/mingw-libvirt.spec.in +++ b/mingw-libvirt.spec.in @@ -239,7 +239,9 @@ rm -rf $RPM_BUILD_ROOT%{mingw64_libexecdir}/libvirt-gue= sts.sh %{mingw32_datadir}/libvirt/schemas/capability.rng %{mingw32_datadir}/libvirt/schemas/cputypes.rng %{mingw32_datadir}/libvirt/schemas/domain.rng +%{mingw32_datadir}/libvirt/schemas/domainbackup.rng %{mingw32_datadir}/libvirt/schemas/domaincaps.rng +%{mingw32_datadir}/libvirt/schemas/domaincheckpoint.rng %{mingw32_datadir}/libvirt/schemas/domaincommon.rng %{mingw32_datadir}/libvirt/schemas/domainsnapshot.rng %{mingw32_datadir}/libvirt/schemas/interface.rng @@ -327,7 +329,9 @@ rm -rf $RPM_BUILD_ROOT%{mingw64_libexecdir}/libvirt-gue= sts.sh %{mingw64_datadir}/libvirt/schemas/capability.rng %{mingw64_datadir}/libvirt/schemas/cputypes.rng %{mingw64_datadir}/libvirt/schemas/domain.rng +%{mingw64_datadir}/libvirt/schemas/domainbackup.rng %{mingw64_datadir}/libvirt/schemas/domaincaps.rng +%{mingw64_datadir}/libvirt/schemas/domaincheckpoint.rng %{mingw64_datadir}/libvirt/schemas/domaincommon.rng %{mingw64_datadir}/libvirt/schemas/domainsnapshot.rng %{mingw64_datadir}/libvirt/schemas/interface.rng diff --git a/tests/Makefile.am b/tests/Makefile.am index 72f0420bab..98b99afcb1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in -## Copyright (C) 2005-2015 Red Hat, Inc. +## Copyright (C) 2005-2018 Red Hat, Inc. ## ## This library is free software; you can redistribute it and/or ## modify it under the terms of the GNU Lesser General Public @@ -92,7 +92,11 @@ EXTRA_DIST =3D \ capabilityschemadata \ commanddata \ cputestdata \ + domainbackupxml2xmlin \ + domainbackupxml2xmlout \ domaincapsschemadata \ + domaincheckpointxml2xmlin \ + domaincheckpointxml2xmlout \ domainconfdata \ domainschemadata \ domainsnapshotxml2xmlin \ diff --git a/tests/domainbackupxml2xmlin/backup-pull.xml b/tests/domainback= upxml2xmlin/backup-pull.xml new file mode 100644 index 0000000000..2ce5cd6711 --- /dev/null +++ b/tests/domainbackupxml2xmlin/backup-pull.xml @@ -0,0 +1,9 @@ + + 1525889631 + + + + + + + diff --git a/tests/domainbackupxml2xmlin/backup-push.xml b/tests/domainback= upxml2xmlin/backup-push.xml new file mode 100644 index 0000000000..1b7d3061fd --- /dev/null +++ b/tests/domainbackupxml2xmlin/backup-push.xml @@ -0,0 +1,9 @@ + + 1525889631 + + + + + + + diff --git a/tests/domainbackupxml2xmlin/empty.xml b/tests/domainbackupxml2= xmlin/empty.xml new file mode 100644 index 0000000000..7ed511f97b --- /dev/null +++ b/tests/domainbackupxml2xmlin/empty.xml @@ -0,0 +1 @@ + diff --git a/tests/domainbackupxml2xmlout/backup-pull.xml b/tests/domainbac= kupxml2xmlout/backup-pull.xml new file mode 100644 index 0000000000..2ce5cd6711 --- /dev/null +++ b/tests/domainbackupxml2xmlout/backup-pull.xml @@ -0,0 +1,9 @@ + + 1525889631 + + + + + + + diff --git a/tests/domainbackupxml2xmlout/backup-push.xml b/tests/domainbac= kupxml2xmlout/backup-push.xml new file mode 100644 index 0000000000..1b7d3061fd --- /dev/null +++ b/tests/domainbackupxml2xmlout/backup-push.xml @@ -0,0 +1,9 @@ + + 1525889631 + + + + + + + diff --git a/tests/domainbackupxml2xmlout/empty.xml b/tests/domainbackupxml= 2xmlout/empty.xml new file mode 100644 index 0000000000..13600fbb1c --- /dev/null +++ b/tests/domainbackupxml2xmlout/empty.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tests/domaincheckpointxml2xmlin/empty.xml b/tests/domaincheckp= ointxml2xmlin/empty.xml new file mode 100644 index 0000000000..dc36449142 --- /dev/null +++ b/tests/domaincheckpointxml2xmlin/empty.xml @@ -0,0 +1 @@ + diff --git a/tests/domaincheckpointxml2xmlin/sample.xml b/tests/domaincheck= pointxml2xmlin/sample.xml new file mode 100644 index 0000000000..70ed964e1e --- /dev/null +++ b/tests/domaincheckpointxml2xmlin/sample.xml @@ -0,0 +1,7 @@ + + Completion of updates after OS install + + + + + diff --git a/tests/domaincheckpointxml2xmlout/empty.xml b/tests/domaincheck= pointxml2xmlout/empty.xml new file mode 100644 index 0000000000..a26c7caab0 --- /dev/null +++ b/tests/domaincheckpointxml2xmlout/empty.xml @@ -0,0 +1,10 @@ + + 1525889631 + 1525889631 + + + + + 9d37b878-a7cc-9f9a-b78f-49b3abad25a8 + + diff --git a/tests/domaincheckpointxml2xmlout/sample.xml b/tests/domainchec= kpointxml2xmlout/sample.xml new file mode 100644 index 0000000000..559b29c8c1 --- /dev/null +++ b/tests/domaincheckpointxml2xmlout/sample.xml @@ -0,0 +1,16 @@ + + 1525889631 + Completion of updates after OS install + 1525889631 + + 1525111885 + + + + + + + fedora + 93a5c045-6457-2c09-e56c-927cdf34e178 + + diff --git a/tests/virschematest.c b/tests/virschematest.c index a89a26b918..ec672f7071 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -221,7 +221,11 @@ mymain(void) "lxcxml2xmloutdata", "bhyvexml2argvdata", "genericxml2xmli= ndata", "genericxml2xmloutdata", "xlconfigdata", "libxlxml2domconf= igdata", "qemuhotplugtestdomains"); + DO_TEST_DIR("domainbackup.rng", "domainbackupxml2xmlin", + "domainbackupxml2xmlout"); DO_TEST_DIR("domaincaps.rng", "domaincapsschemadata"); + DO_TEST_DIR("domaincheckpoint.rng", "domaincheckpointxml2xmlin", + "domaincheckpointxml2xmlout"); DO_TEST_DIR("domainsnapshot.rng", "domainsnapshotxml2xmlin", "domainsnapshotxml2xmlout"); DO_TEST_DIR("interface.rng", "interfaceschemadata"); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 155193774243359.54578007661053; Wed, 6 Mar 2019 21:49:02 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C9D387649; Thu, 7 Mar 2019 05:49:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6059D1001DCE; Thu, 7 Mar 2019 05:49:00 +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 15C68181A270; Thu, 7 Mar 2019 05:48:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275mCKI003972 for ; Thu, 7 Mar 2019 00:48:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id BE5735D788; Thu, 7 Mar 2019 05:48:12 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91EB35D786; Thu, 7 Mar 2019 05:48:11 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:38 -0600 Message-Id: <20190307054752.19522-7-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 06/20] backup: Introduce virDomainCheckpoint APIs 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 07 Mar 2019 05:49:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Introduce a bunch of new public APIs related to backup checkpoints. Checkpoints are modeled heavily after virDomainSnapshotPtr (both represent a point in time of the guest), although a snapshot exists with the intent of rolling back to that state, while a checkpoint exists to make it possible to create an incremental backup at a later time. The full list of new API: virDomainCheckpointCreateXML; virDomainCheckpointCurrent; virDomainCheckpointDelete; virDomainCheckpointFree; virDomainCheckpointGetConnect; virDomainCheckpointGetDomain; virDomainCheckpointGetParent; virDomainCheckpointGetXMLDesc; virDomainCheckpointHasMetadata; virDomainCheckpointIsCurrent; virDomainCheckpointListChildren; virDomainCheckpointLookupByName; virDomainCheckpointRef; virDomainHasCurrentCheckpoint; virDomainListCheckpoints; virDomainCheckpointGetName; Signed-off-by: Eric Blake --- include/libvirt/libvirt-domain-checkpoint.h | 161 +++++ include/libvirt/libvirt-domain.h | 7 + include/libvirt/libvirt.h | 5 +- src/driver-hypervisor.h | 60 +- docs/Makefile.am | 3 + docs/apibuild.py | 2 + docs/docs.html.in | 1 + libvirt.spec.in | 1 + mingw-libvirt.spec.in | 2 + po/POTFILES | 1 + src/Makefile.am | 2 + src/libvirt-domain-checkpoint.c | 741 ++++++++++++++++++++ src/libvirt-domain.c | 9 +- src/libvirt_public.syms | 16 + 14 files changed, 1005 insertions(+), 6 deletions(-) create mode 100644 include/libvirt/libvirt-domain-checkpoint.h create mode 100644 src/libvirt-domain-checkpoint.c diff --git a/include/libvirt/libvirt-domain-checkpoint.h b/include/libvirt/= libvirt-domain-checkpoint.h new file mode 100644 index 0000000000..49a0c7ba0b --- /dev/null +++ b/include/libvirt/libvirt-domain-checkpoint.h @@ -0,0 +1,161 @@ +/* + * libvirt-domain-checkpoint.h + * Summary: APIs for management of domain checkpoints + * Description: Provides APIs for the management of domain checkpoints + * + * Copyright (C) 2006-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#ifndef LIBVIRT_DOMAIN_CHECKPOINT_H +# define LIBVIRT_DOMAIN_CHECKPOINT_H + +# ifndef __VIR_LIBVIRT_H_INCLUDES__ +# error "Don't include this file directly, only use libvirt/libvirt.h" +# endif + +/** + * virDomainCheckpoint: + * + * A virDomainCheckpoint is a private structure representing a checkpoint = of + * a domain. A checkpoint is useful for tracking which portions of the + * domain disks have been altered since a point in time, but by itself does + * not allow reverting back to that point in time. + */ +typedef struct _virDomainCheckpoint virDomainCheckpoint; + +/** + * virDomainCheckpointPtr: + * + * A virDomainCheckpointPtr is pointer to a virDomainCheckpoint + * private structure, and is the type used to reference a domain + * checkpoint in the API. + */ +typedef virDomainCheckpoint *virDomainCheckpointPtr; + +const char *virDomainCheckpointGetName(virDomainCheckpointPtr checkpoint); +virDomainPtr virDomainCheckpointGetDomain(virDomainCheckpointPtr checkpoin= t); +virConnectPtr virDomainCheckpointGetConnect(virDomainCheckpointPtr checkpo= int); + +typedef enum { + VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE =3D (1 << 0), /* Restore or a= lter + metadata */ + VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT =3D (1 << 1), /* With redefin= e, make + checkpoint cur= rent */ + VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA =3D (1 << 2), /* Make checkpo= int without + remembering it= */ + VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE =3D (1 << 3), /* use guest ag= ent to + quiesce all mo= unted + file systems w= ithin + the domain */ + VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE_LIST =3D (1 << 4), /* parse mult= iple + checkpoints = in + one API call= */ +} virDomainCheckpointCreateFlags; + +/* Create a checkpoint using the current VM state. */ +virDomainCheckpointPtr virDomainCheckpointCreateXML(virDomainPtr domain, + const char *xmlDesc, + unsigned int flags); + +typedef enum { + VIR_DOMAIN_CHECKPOINT_XML_SECURE =3D (1 << 0), /* Include sensitive= data */ + VIR_DOMAIN_CHECKPOINT_XML_NO_DOMAIN =3D (1 << 1), /* Suppress + subelement */ + VIR_DOMAIN_CHECKPOINT_XML_SIZE =3D (1 << 2), /* Include dynamic + per- size */ +} virDomainCheckpointXMLFlags; + +/* Dump the XML of a checkpoint */ +char *virDomainCheckpointGetXMLDesc(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +/** + * virDomainCheckpointListFlags: + * + * Flags valid for virDomainListCheckpoints() and + * virDomainCheckpointListChildren(). Note that the interpretation of + * flag (1<<0) depends on which function it is passed to; but serves + * to toggle the per-call default of whether the listing is shallow or + * recursive. Remaining bits come in groups; if all bits from a group + * are 0, then that group is not used to filter results. */ +typedef enum { + VIR_DOMAIN_CHECKPOINT_LIST_ROOTS =3D (1 << 0), /* Filter by chec= kpoints + with no parents,= when + listing a domain= */ + VIR_DOMAIN_CHECKPOINT_LIST_DESCENDANTS =3D (1 << 0), /* List all desce= ndants, + not just childre= n, when + listing a checkp= oint */ + + VIR_DOMAIN_CHECKPOINT_LIST_LEAVES =3D (1 << 1), /* Filter by chec= kpoints + with no children= */ + VIR_DOMAIN_CHECKPOINT_LIST_NO_LEAVES =3D (1 << 2), /* Filter by chec= kpoints + that have childr= en */ + + VIR_DOMAIN_CHECKPOINT_LIST_METADATA =3D (1 << 3), /* Filter by chec= kpoints + which have metad= ata */ + VIR_DOMAIN_CHECKPOINT_LIST_NO_METADATA =3D (1 << 4), /* Filter by chec= kpoints + with no metadata= */ +} virDomainCheckpointListFlags; + +/* Get all checkpoint objects for this domain */ +int virDomainListCheckpoints(virDomainPtr domain, + virDomainCheckpointPtr **checkpoints, + unsigned int flags); + +/* Get all checkpoint object children for this checkpoint */ +int virDomainCheckpointListChildren(virDomainCheckpointPtr checkpoint, + virDomainCheckpointPtr **children, + unsigned int flags); + +/* Get a handle to a named checkpoint */ +virDomainCheckpointPtr virDomainCheckpointLookupByName(virDomainPtr domain, + const char *name, + unsigned int flags); + +/* Check whether a domain has a checkpoint which is currently used */ +int virDomainHasCurrentCheckpoint(virDomainPtr domain, unsigned int flags); + +/* Get a handle to the current checkpoint */ +virDomainCheckpointPtr virDomainCheckpointCurrent(virDomainPtr domain, + unsigned int flags); + +/* Get a handle to the parent checkpoint, if one exists */ +virDomainCheckpointPtr virDomainCheckpointGetParent(virDomainCheckpointPtr= checkpoint, + unsigned int flags); + +/* Determine if a checkpoint is the current checkpoint of its domain. */ +int virDomainCheckpointIsCurrent(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +/* Determine if checkpoint has metadata that would prevent domain deletion= . */ +int virDomainCheckpointHasMetadata(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +/* Delete a checkpoint */ +typedef enum { + VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN =3D (1 << 0), /* Also delet= e children */ + VIR_DOMAIN_CHECKPOINT_DELETE_METADATA_ONLY =3D (1 << 1), /* Delete jus= t metadata */ + VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY =3D (1 << 2), /* Delete jus= t children */ +} virDomainCheckpointDeleteFlags; + +int virDomainCheckpointDelete(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +int virDomainCheckpointRef(virDomainCheckpointPtr checkpoint); +int virDomainCheckpointFree(virDomainCheckpointPtr checkpoint); + +#endif /* LIBVIRT_DOMAIN_CHECKPOINT_H */ diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index a8ebb68388..7abfd03d91 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -1571,6 +1571,7 @@ typedef enum { VIR_DOMAIN_XML_UPDATE_CPU =3D (1 << 2), /* update guest CPU requirem= ents according to host CPU */ VIR_DOMAIN_XML_MIGRATABLE =3D (1 << 3), /* dump XML suitable for mig= ration */ VIR_DOMAIN_XML_SNAPSHOTS =3D (1 << 4), /* include all snapshots in = the dump */ + VIR_DOMAIN_XML_CHECKPOINTS =3D (1 << 5), /* include all checkpoints i= n the dump */ } virDomainXMLFlags; typedef enum { @@ -1775,6 +1776,9 @@ typedef enum { VIR_DOMAIN_UNDEFINE_NVRAM =3D (1 << 2), /* Also remove any nvram file */ VIR_DOMAIN_UNDEFINE_KEEP_NVRAM =3D (1 << 3), /* Keep nvram fil= e */ + VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA=3D (1 << 4),/* If last use of= domain, + then also remove= any + checkpoint metad= ata */ /* Future undefine control flags should come here. */ } virDomainUndefineFlagsValues; @@ -1813,6 +1817,9 @@ typedef enum { VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT =3D 1 << 12, VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT =3D 1 << 13, + + VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT =3D 1 << 14, + VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT =3D 1 << 15, } virConnectListAllDomainsFlags; int virConnectListAllDomains (virConnectPtr conn, diff --git a/include/libvirt/libvirt.h b/include/libvirt/libvirt.h index 13de151cb6..f93e3bfa85 100644 --- a/include/libvirt/libvirt.h +++ b/include/libvirt/libvirt.h @@ -34,10 +34,7 @@ extern "C" { # include # include # include -/* FIXME: Temporary hack until later patch creates new - * libvirt-domain-checkpoint.h file */ -typedef struct _virDomainCheckpoint virDomainCheckpoint; -typedef virDomainCheckpoint *virDomainCheckpointPtr; +# include # include # include # include diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 5315e33dde..14db8e49f3 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -1,7 +1,7 @@ /* * driver-hypervisor.h: entry points for hypervisor drivers * - * Copyright (C) 2006-2015 Red Hat, Inc. + * Copyright (C) 2006-2018 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -1328,6 +1328,53 @@ typedef int int *nparams, unsigned int flags); +typedef virDomainCheckpointPtr +(*virDrvDomainCheckpointCreateXML)(virDomainPtr domain, + const char *xmlDesc, + unsigned int flags); + +typedef char * +(*virDrvDomainCheckpointGetXMLDesc)(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +typedef int +(*virDrvDomainListCheckpoints)(virDomainPtr domain, + virDomainCheckpointPtr **checkpoints, + unsigned int flags); + +typedef int +(*virDrvDomainCheckpointListChildren)(virDomainCheckpointPtr checkpoint, + virDomainCheckpointPtr **children, + unsigned int flags); + +typedef virDomainCheckpointPtr +(*virDrvDomainCheckpointLookupByName)(virDomainPtr domain, + const char *name, + unsigned int flags); + +typedef int +(*virDrvDomainHasCurrentCheckpoint)(virDomainPtr domain, + unsigned int flags); + +typedef virDomainCheckpointPtr +(*virDrvDomainCheckpointGetParent)(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +typedef virDomainCheckpointPtr +(*virDrvDomainCheckpointCurrent)(virDomainPtr domain, + unsigned int flags); + +typedef int +(*virDrvDomainCheckpointIsCurrent)(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +typedef int +(*virDrvDomainCheckpointHasMetadata)(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +typedef int +(*virDrvDomainCheckpointDelete)(virDomainCheckpointPtr checkpoint, + unsigned int flags); typedef struct _virHypervisorDriver virHypervisorDriver; typedef virHypervisorDriver *virHypervisorDriverPtr; @@ -1580,6 +1627,17 @@ struct _virHypervisorDriver { virDrvConnectBaselineHypervisorCPU connectBaselineHypervisorCPU; virDrvNodeGetSEVInfo nodeGetSEVInfo; virDrvDomainGetLaunchSecurityInfo domainGetLaunchSecurityInfo; + virDrvDomainCheckpointCreateXML domainCheckpointCreateXML; + virDrvDomainCheckpointGetXMLDesc domainCheckpointGetXMLDesc; + virDrvDomainListCheckpoints domainListCheckpoints; + virDrvDomainCheckpointListChildren domainCheckpointListChildren; + virDrvDomainCheckpointLookupByName domainCheckpointLookupByName; + virDrvDomainHasCurrentCheckpoint domainHasCurrentCheckpoint; + virDrvDomainCheckpointGetParent domainCheckpointGetParent; + virDrvDomainCheckpointCurrent domainCheckpointCurrent; + virDrvDomainCheckpointIsCurrent domainCheckpointIsCurrent; + virDrvDomainCheckpointHasMetadata domainCheckpointHasMetadata; + virDrvDomainCheckpointDelete domainCheckpointDelete; }; diff --git a/docs/Makefile.am b/docs/Makefile.am index bd7bc1a431..88c1e83275 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -25,6 +25,7 @@ apihtml =3D \ apihtml_generated =3D \ html/libvirt-libvirt-common.html \ html/libvirt-libvirt-domain.html \ + html/libvirt-libvirt-domain-checkpoint.html \ html/libvirt-libvirt-domain-snapshot.html \ html/libvirt-libvirt-event.html \ html/libvirt-libvirt-host.html \ @@ -316,6 +317,7 @@ $(python_generated_files): $(APIBUILD_STAMP) $(APIBUILD_STAMP): $(srcdir)/apibuild.py \ $(top_srcdir)/include/libvirt/libvirt.h \ $(top_srcdir)/include/libvirt/libvirt-common.h.in \ + $(top_srcdir)/include/libvirt/libvirt-domain-checkpoint.h \ $(top_srcdir)/include/libvirt/libvirt-domain-snapshot.h \ $(top_srcdir)/include/libvirt/libvirt-domain.h \ $(top_srcdir)/include/libvirt/libvirt-event.h \ @@ -332,6 +334,7 @@ $(APIBUILD_STAMP): $(srcdir)/apibuild.py \ $(top_srcdir)/include/libvirt/libvirt-admin.h \ $(top_srcdir)/include/libvirt/virterror.h \ $(top_srcdir)/src/libvirt.c \ + $(top_srcdir)/src/libvirt-domain-checkpoint.c \ $(top_srcdir)/src/libvirt-domain-snapshot.c \ $(top_srcdir)/src/libvirt-domain.c \ $(top_srcdir)/src/libvirt-host.c \ diff --git a/docs/apibuild.py b/docs/apibuild.py index 9e04871220..dbdc1c95af 100755 --- a/docs/apibuild.py +++ b/docs/apibuild.py @@ -26,6 +26,7 @@ debugsym =3D None included_files =3D { "libvirt-common.h": "header with general libvirt API definitions", "libvirt-domain.h": "header with general libvirt API definitions", + "libvirt-domain-checkpoint.h": "header with general libvirt API definiti= ons", "libvirt-domain-snapshot.h": "header with general libvirt API definition= s", "libvirt-event.h": "header with general libvirt API definitions", "libvirt-host.h": "header with general libvirt API definitions", @@ -39,6 +40,7 @@ included_files =3D { "virterror.h": "header with error specific API definitions", "libvirt.c": "Main interfaces for the libvirt library", "libvirt-domain.c": "Domain interfaces for the libvirt library", + "libvirt-domain-checkpoint.c": "Domain checkpoint interfaces for the lib= virt library", "libvirt-domain-snapshot.c": "Domain snapshot interfaces for the libvirt= library", "libvirt-host.c": "Host interfaces for the libvirt library", "libvirt-interface.c": "Interface interfaces for the libvirt library", diff --git a/docs/docs.html.in b/docs/docs.html.in index 057524521f..47fb32c552 100644 --- a/docs/docs.html.in +++ b/docs/docs.html.in @@ -99,6 +99,7 @@
        Reference manual for the C public API, split in common, domain, + domain c= heckpoint, domain sna= pshot, error, event, diff --git a/libvirt.spec.in b/libvirt.spec.in index b842bb2424..c4eeacb56e 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -1870,6 +1870,7 @@ exit 0 %{_includedir}/libvirt/libvirt-admin.h %{_includedir}/libvirt/libvirt-common.h %{_includedir}/libvirt/libvirt-domain.h +%{_includedir}/libvirt/libvirt-domain-checkpoint.h %{_includedir}/libvirt/libvirt-domain-snapshot.h %{_includedir}/libvirt/libvirt-event.h %{_includedir}/libvirt/libvirt-host.h diff --git a/mingw-libvirt.spec.in b/mingw-libvirt.spec.in index f407526e1a..924725a5b6 100644 --- a/mingw-libvirt.spec.in +++ b/mingw-libvirt.spec.in @@ -272,6 +272,7 @@ rm -rf $RPM_BUILD_ROOT%{mingw64_libexecdir}/libvirt-gue= sts.sh %{mingw32_includedir}/libvirt/libvirt.h %{mingw32_includedir}/libvirt/libvirt-common.h %{mingw32_includedir}/libvirt/libvirt-domain.h +%{mingw32_includedir}/libvirt/libvirt-domain-checkpoint.h %{mingw32_includedir}/libvirt/libvirt-domain-snapshot.h %{mingw32_includedir}/libvirt/libvirt-event.h %{mingw32_includedir}/libvirt/libvirt-host.h @@ -362,6 +363,7 @@ rm -rf $RPM_BUILD_ROOT%{mingw64_libexecdir}/libvirt-gue= sts.sh %{mingw64_includedir}/libvirt/libvirt.h %{mingw64_includedir}/libvirt/libvirt-common.h %{mingw64_includedir}/libvirt/libvirt-domain.h +%{mingw64_includedir}/libvirt/libvirt-domain-checkpoint.h %{mingw64_includedir}/libvirt/libvirt-domain-snapshot.h %{mingw64_includedir}/libvirt/libvirt-event.h %{mingw64_includedir}/libvirt/libvirt-host.h diff --git a/po/POTFILES b/po/POTFILES index 9dd4ee7d99..88af551664 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -69,6 +69,7 @@ src/interface/interface_backend_netcf.c src/interface/interface_backend_udev.c src/internal.h src/libvirt-admin.c +src/libvirt-domain-checkpoint.c src/libvirt-domain-snapshot.c src/libvirt-domain.c src/libvirt-host.c diff --git a/src/Makefile.am b/src/Makefile.am index 8c8dfe3dcf..c871e12d8f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -176,6 +176,7 @@ DRIVER_SOURCES +=3D \ $(DATATYPES_SOURCES) \ libvirt.c libvirt_internal.h \ libvirt-domain.c \ + libvirt-domain-checkpoint.c \ libvirt-domain-snapshot.c \ libvirt-host.c \ libvirt-interface.c \ @@ -727,6 +728,7 @@ libvirt_setuid_rpc_client_la_SOURCES =3D \ datatypes.c \ libvirt.c \ libvirt-domain.c \ + libvirt-domain-checkpoint.c \ libvirt-domain-snapshot.c \ libvirt-host.c \ libvirt-interface.c \ diff --git a/src/libvirt-domain-checkpoint.c b/src/libvirt-domain-checkpoin= t.c new file mode 100644 index 0000000000..e3b38e627e --- /dev/null +++ b/src/libvirt-domain-checkpoint.c @@ -0,0 +1,741 @@ +/* + * libvirt-domain-checkpoint.c: entry points for virDomainCheckpointPtr AP= Is + * + * Copyright (C) 2006-2014, 2018 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "datatypes.h" +#include "virlog.h" + +VIR_LOG_INIT("libvirt.domain-checkpoint"); + +#define VIR_FROM_THIS VIR_FROM_DOMAIN_CHECKPOINT + +/** + * virDomainCheckpointGetName: + * @checkpoint: a checkpoint object + * + * Get the public name for that checkpoint + * + * Returns a pointer to the name or NULL, the string need not be deallocat= ed + * as its lifetime will be the same as the checkpoint object. + */ +const char * +virDomainCheckpointGetName(virDomainCheckpointPtr checkpoint) +{ + VIR_DEBUG("checkpoint=3D%p", checkpoint); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, NULL); + + return checkpoint->name; +} + + +/** + * virDomainCheckpointGetDomain: + * @checkpoint: a checkpoint object + * + * Provides the domain pointer associated with a checkpoint. The + * reference counter on the domain is not increased by this + * call. + * + * Returns the domain or NULL. + */ +virDomainPtr +virDomainCheckpointGetDomain(virDomainCheckpointPtr checkpoint) +{ + VIR_DEBUG("checkpoint=3D%p", checkpoint); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, NULL); + + return checkpoint->domain; +} + + +/** + * virDomainCheckpointGetConnect: + * @checkpoint: a checkpoint object + * + * Provides the connection pointer associated with a checkpoint. The + * reference counter on the connection is not increased by this + * call. + * + * Returns the connection or NULL. + */ +virConnectPtr +virDomainCheckpointGetConnect(virDomainCheckpointPtr checkpoint) +{ + VIR_DEBUG("checkpoint=3D%p", checkpoint); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, NULL); + + return checkpoint->domain->conn; +} + + +/** + * virDomainCheckpointCreateXML: + * @domain: a domain object + * @xmlDesc: description of the checkpoint to create + * @flags: bitwise-OR of supported virDomainCheckpointCreateFlags + * + * Create a new checkpoint using @xmlDesc, with a top-level + * element, on a running @domain. + * Typically, it is more common to create a new checkpoint as part of + * kicking off a backup job with virDomainBackupBegin(); however, it + * is also possible to start a checkpoint without a backup. + * + * See Checkpoint XM= L + * for more details on @xmlDesc. In particular, some hypervisors may requi= re + * particular disk formats, such as qcow2, in order to support this + * command; where @xmlDesc can be used to limit the checkpoint to a working + * subset of the domain's disks. + * + * If @flags includes VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE, then this + * is a request to reinstate checkpoint metadata that was previously + * discarded, rather than creating a new checkpoint. When redefining + * checkpoint metadata, the current checkpoint will not be altered + * unless the VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT flag is also + * present. It is an error to request the + * VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT flag without + * VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE. Alternatively, if @flags + * includes VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE_LIST (which requires + * VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE and is incompatible with + * VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT), and the domain has no + * existing checkpoint metadata, then @xmlDesc is parsed as a + * top-level element with an optional current=3D'name' + * attribute, and containing one or more children + * (as produced by virDomainGetXMLDesc() with the flag + * VIR_DOMAIN_XML_CHECKPOINTS), to do a bulk redefine of all + * checkpoints at once (it is unspecified which of the redefined + * checkpoints will be used as the return value on success). Not all + * hypervisors support these flags. + * + * If @flags includes VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA, then + * the domain's disk images are modified according to @xmlDesc, but + * then the just-created checkpoint has its metadata deleted. This + * flag is incompatible with VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE. + * + * Returns an (opaque) new virDomainCheckpointPtr on success, or NULL + * on failure. + */ +virDomainCheckpointPtr +virDomainCheckpointCreateXML(virDomainPtr domain, + const char *xmlDesc, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "xmlDesc=3D%s, flags=3D0x%x", xmlDesc, flags); + + virResetLastError(); + + virCheckDomainReturn(domain, NULL); + conn =3D domain->conn; + + virCheckNonNullArgGoto(xmlDesc, error); + virCheckReadOnlyGoto(conn->flags, error); + + VIR_REQUIRE_FLAG_GOTO(VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT, + VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE, + error); + VIR_REQUIRE_FLAG_GOTO(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE_LIST, + VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE, + error); + + VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE, + VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA, + error); + VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE_LIST, + VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT, + error); + + if (conn->driver->domainCheckpointCreateXML) { + virDomainCheckpointPtr ret; + ret =3D conn->driver->domainCheckpointCreateXML(domain, xmlDesc, f= lags); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return NULL; +} + + +/** + * virDomainCheckpointGetXMLDesc: + * @checkpoint: a domain checkpoint object + * @flags: bitwise-OR of supported virDomainCheckpointXMLFlags + * + * Provide an XML description of the domain checkpoint. + * + * No security-sensitive data will be included unless @flags contains + * VIR_DOMAIN_CHECKPOINT_XML_SECURE; this flag is rejected on read-only + * connections. + * + * Normally, the XML description includes an element giving a full + * description of the domain at the time the snapshot was created; to + * reduce parsing time, it will be suppressed when @flags contains + * VIR_DOMAIN_CHECKPOINT_XML_NO_DOMAIN. + * + * By default, the XML description contains only static information that + * does not change over time. However, when @flags contains + * VIR_DOMAIN_CHECKPOINT_XML_SIZE, each listing adds an additional + * attribute that shows an estimate of the current size in bytes that + * have been dirtied between the time the checkpoint was created and the + * current point in time. + * + * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of e= rror. + * the caller must free() the returned value. + */ +char * +virDomainCheckpointGetXMLDesc(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virConnectPtr conn; + VIR_DEBUG("checkpoint=3D%p, flags=3D0x%x", checkpoint, flags); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, NULL); + conn =3D checkpoint->domain->conn; + + if ((conn->flags & VIR_CONNECT_RO) && + (flags & VIR_DOMAIN_CHECKPOINT_XML_SECURE)) { + virReportError(VIR_ERR_OPERATION_DENIED, "%s", + _("virDomainCheckpointGetXMLDesc with secure flag")= ); + goto error; + } + + if (conn->driver->domainCheckpointGetXMLDesc) { + char *ret; + ret =3D conn->driver->domainCheckpointGetXMLDesc(checkpoint, flags= ); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return NULL; +} + + +/** + * virDomainListCheckpoints: + * @domain: a domain object + * @checkpoints: pointer to variable to store the array containing checkpo= int + * objects, or NULL if the list is not required (just returns + * number of checkpoints) + * @flags: bitwise-OR of supported virDomainCheckpoinListFlags + * + * Collect the list of domain checkpoints for the given domain, and alloca= te + * an array to store those objects. + * + * By default, this command covers all checkpoints; it is also possible to + * limit things to just checkpoints with no parents, when @flags includes + * VIR_DOMAIN_CHECKPOINT_LIST_ROOTS. Additional filters are provided in + * groups, where each group contains bits that describe mutually exclusive + * attributes of a checkpoint, and where all bits within a group describe + * all possible checkpoints. Some hypervisors might reject explicit bits + * from a group where the hypervisor cannot make a distinction. For a + * group supported by a given hypervisor, the behavior when no bits of a + * group are set is identical to the behavior when all bits in that group + * are set. When setting bits from more than one group, it is possible to + * select an impossible combination, in that case a hypervisor may return + * either 0 or an error. + * + * The first group of @flags is VIR_DOMAIN_CHECKPOINT_LIST_LEAVES and + * VIR_DOMAIN_CHECKPOINT_LIST_NO_LEAVES, to filter based on checkpoints th= at + * have no further children (a leaf checkpoint). + * + * The next group of @flags is VIR_DOMAIN_CHECKPOINT_LIST_METADATA and + * VIR_DOMAIN_CHECKPOINT_LIST_NO_METADATA, for filtering checkpoints based= on + * whether they have metadata that would prevent the removal of the last + * reference to a domain. + * + * Returns the number of domain checkpoints found or -1 and sets @checkpoi= nts + * to NULL in case of error. On success, the array stored into @checkpoin= ts + * is guaranteed to have an extra allocated element set to NULL but not + * included in the return count, to make iteration easier. The caller is + * responsible for calling virDomainCheckpointFree() on each array element, + * then calling free() on @checkpoints. + */ +int +virDomainListCheckpoints(virDomainPtr domain, + virDomainCheckpointPtr **checkpoints, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "checkpoints=3D%p, flags=3D0x%x", checkpoints= , flags); + + virResetLastError(); + + if (checkpoints) + *checkpoints =3D NULL; + + virCheckDomainReturn(domain, -1); + conn =3D domain->conn; + + if (conn->driver->domainListCheckpoints) { + int ret =3D conn->driver->domainListCheckpoints(domain, checkpoint= s, + flags); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + + +/** + * virDomainCheckpointListChildren: + * @checkpoint: a domain checkpoint object + * @children: pointer to variable to store the array containing checkpoint + * objects, or NULL if the list is not required (just returns + * number of checkpoints) + * @flags: bitwise-OR of supported virDomainCheckpointListFlags + * + * Collect the list of domain checkpoints that are children of the given + * checkpoint, and allocate an array to store those objects. + * + * By default, this command covers only direct children; it is also possib= le + * to expand things to cover all descendants, when @flags includes + * VIR_DOMAIN_CHECKPOINT_LIST_DESCENDANTS. Also, some filters are provide= d in + * groups, where each group contains bits that describe mutually exclusive + * attributes of a snapshot, and where all bits within a group describe + * all possible snapshots. Some hypervisors might reject explicit bits + * from a group where the hypervisor cannot make a distinction. For a + * group supported by a given hypervisor, the behavior when no bits of a + * group are set is identical to the behavior when all bits in that group + * are set. When setting bits from more than one group, it is possible to + * select an impossible combination, in that case a hypervisor may return + * either 0 or an error. + * + * The first group of @flags is VIR_DOMAIN_CHECKPOINT_LIST_LEAVES and + * VIR_DOMAIN_CHECKPOINT_LIST_NO_LEAVES, to filter based on checkpoints th= at + * have no further children (a leaf checkpoint). + * + * The next group of @flags is VIR_DOMAIN_CHECKPOINT_LIST_METADATA and + * VIR_DOMAIN_CHECKPOINT_LIST_NO_METADATA, for filtering checkpoints based= on + * whether they have metadata that would prevent the removal of the last + * reference to a domain. + * + * Returns the number of domain checkpoints found or -1 and sets @children= to + * NULL in case of error. On success, the array stored into @children is + * guaranteed to have an extra allocated element set to NULL but not inclu= ded + * in the return count, to make iteration easier. The caller is responsib= le + * for calling virDomainCheckpointFree() on each array element, then calli= ng + * free() on @children. + */ +int +virDomainCheckpointListChildren(virDomainCheckpointPtr checkpoint, + virDomainCheckpointPtr **children, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DEBUG("checkpoint=3D%p, children=3D%p, flags=3D0x%x", + checkpoint, children, flags); + + virResetLastError(); + + if (children) + *children =3D NULL; + + virCheckDomainCheckpointReturn(checkpoint, -1); + conn =3D checkpoint->domain->conn; + + if (conn->driver->domainCheckpointListChildren) { + int ret =3D conn->driver->domainCheckpointListChildren(checkpoint, + children, fla= gs); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + + +/** + * virDomainCheckpointLookupByName: + * @domain: a domain object + * @name: name for the domain checkpoint + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Try to lookup a domain checkpoint based on its name. + * + * Returns a domain checkpoint object or NULL in case of failure. If the + * domain checkpoint cannot be found, then the VIR_ERR_NO_DOMAIN_CHECKPOINT + * error is raised. + */ +virDomainCheckpointPtr +virDomainCheckpointLookupByName(virDomainPtr domain, + const char *name, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "name=3D%s, flags=3D0x%x", name, flags); + + virResetLastError(); + + virCheckDomainReturn(domain, NULL); + conn =3D domain->conn; + + virCheckNonNullArgGoto(name, error); + + if (conn->driver->domainCheckpointLookupByName) { + virDomainCheckpointPtr dom; + dom =3D conn->driver->domainCheckpointLookupByName(domain, name, f= lags); + if (!dom) + goto error; + return dom; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return NULL; +} + + +/** + * virDomainHasCurrentCheckpoint: + * @domain: pointer to the domain object + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Determine if the domain has a current checkpoint. + * + * Returns 1 if such checkpoint exists, 0 if it doesn't, -1 on error. + */ +int +virDomainHasCurrentCheckpoint(virDomainPtr domain, unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "flags=3D0x%x", flags); + + virResetLastError(); + + virCheckDomainReturn(domain, -1); + conn =3D domain->conn; + + if (conn->driver->domainHasCurrentCheckpoint) { + int ret =3D conn->driver->domainHasCurrentCheckpoint(domain, flags= ); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + + +/** + * virDomainCheckpointCurrent: + * @domain: a domain object + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Get the current checkpoint for a domain, if any. + * + * virDomainCheckpointFree should be used to free the resources after the + * checkpoint object is no longer needed. + * + * Returns a domain checkpoint object or NULL in case of failure. If the + * current domain checkpoint cannot be found, then the + * VIR_ERR_NO_DOMAIN_CHECKPOINT error is raised. + */ +virDomainCheckpointPtr +virDomainCheckpointCurrent(virDomainPtr domain, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "flags=3D0x%x", flags); + + virResetLastError(); + + virCheckDomainReturn(domain, NULL); + conn =3D domain->conn; + + if (conn->driver->domainCheckpointCurrent) { + virDomainCheckpointPtr snap; + snap =3D conn->driver->domainCheckpointCurrent(domain, flags); + if (!snap) + goto error; + return snap; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return NULL; +} + + +/** + * virDomainCheckpointGetParent: + * @checkpoint: a checkpoint object + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Get the parent checkpoint for @checkpoint, if any. + * + * virDomainCheckpointFree should be used to free the resources after the + * checkpoint object is no longer needed. + * + * Returns a domain checkpoint object or NULL in case of failure. If the + * given checkpoint is a root (no parent), then the VIR_ERR_NO_DOMAIN_CHEC= KPOINT + * error is raised. + */ +virDomainCheckpointPtr +virDomainCheckpointGetParent(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DEBUG("checkpoint=3D%p, flags=3D0x%x", checkpoint, flags); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, NULL); + conn =3D checkpoint->domain->conn; + + if (conn->driver->domainCheckpointGetParent) { + virDomainCheckpointPtr snap; + snap =3D conn->driver->domainCheckpointGetParent(checkpoint, flags= ); + if (!snap) + goto error; + return snap; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return NULL; +} + + +/** + * virDomainCheckpointIsCurrent: + * @checkpoint: a checkpoint object + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Determine if the given checkpoint is the domain's current checkpoint. = See + * also virDomainHasCurrentCheckpoint(). + * + * Returns 1 if current, 0 if not current, or -1 on error. + */ +int +virDomainCheckpointIsCurrent(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DEBUG("checkpoint=3D%p, flags=3D0x%x", checkpoint, flags); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, -1); + conn =3D checkpoint->domain->conn; + + if (conn->driver->domainCheckpointIsCurrent) { + int ret; + ret =3D conn->driver->domainCheckpointIsCurrent(checkpoint, flags); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + + +/** + * virDomainCheckpointHasMetadata: + * @checkpoint: a checkpoint object + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Determine if the given checkpoint is associated with libvirt metadata + * that would prevent the deletion of the domain. + * + * Returns 1 if the checkpoint has metadata, 0 if the checkpoint exists wi= thout + * help from libvirt, or -1 on error. + */ +int +virDomainCheckpointHasMetadata(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DEBUG("checkpoint=3D%p, flags=3D0x%x", checkpoint, flags); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, -1); + conn =3D checkpoint->domain->conn; + + if (conn->driver->domainCheckpointHasMetadata) { + int ret; + ret =3D conn->driver->domainCheckpointHasMetadata(checkpoint, flag= s); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + + +/** + * virDomainCheckpointDelete: + * @checkpoint: the checkpoint to remove + * @flags: not used yet, pass 0 + * @flags: bitwise-OR of supported virDomainCheckpointDeleteFlags + * + * Removes a checkpoint from the domain. + * + * When removing a checkpoint, the record of which portions of the + * disk were dirtied after the checkpoint will be merged into the + * record tracked by the parent checkpoint, if any. Likewise, if the + * checkpoint being deleted was the current checkpoint, the parent + * checkpoint becomes the new current checkpoint. + * + * If @flags includes VIR_DOMAIN_CHECKPOINT_DELETE_METADATA_ONLY, then + * any checkpoint metadata tracked by libvirt is removed while keeping + * the checkpoint contents intact; if a hypervisor does not require + * any libvirt metadata to track checkpoints, then this flag is + * silently ignored. + * + * Returns 0 on success, -1 on error. + */ +int +virDomainCheckpointDelete(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DEBUG("checkpoint=3D%p, flags=3D0x%x", checkpoint, flags); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, -1); + conn =3D checkpoint->domain->conn; + + virCheckReadOnlyGoto(conn->flags, error); + + VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN, + VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY, + error); + + if (conn->driver->domainCheckpointDelete) { + int ret =3D conn->driver->domainCheckpointDelete(checkpoint, flags= ); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + + +/** + * virDomainCheckpointRef: + * @checkpoint: the checkpoint to hold a reference on + * + * Increment the reference count on the checkpoint. For each + * additional call to this method, there shall be a corresponding + * call to virDomainCheckpointFree to release the reference count, once + * the caller no longer needs the reference to this object. + * + * This method is typically useful for applications where multiple + * threads are using a connection, and it is required that the + * connection and domain remain open until all threads have finished + * using the checkpoint. ie, each new thread using a checkpoint would + * increment the reference count. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virDomainCheckpointRef(virDomainCheckpointPtr checkpoint) +{ + VIR_DEBUG("checkpoint=3D%p, refs=3D%d", checkpoint, + checkpoint ? checkpoint->parent.u.s.refs : 0); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, -1); + + virObjectRef(checkpoint); + return 0; +} + + +/** + * virDomainCheckpointFree: + * @checkpoint: a domain checkpoint object + * + * Free the domain checkpoint object. The checkpoint itself is not modifi= ed. + * The data structure is freed and should not be used thereafter. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virDomainCheckpointFree(virDomainCheckpointPtr checkpoint) +{ + VIR_DEBUG("checkpoint=3D%p", checkpoint); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, -1); + + virObjectUnref(checkpoint); + return 0; +} diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index c886e0bdbe..10768bd279 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -2576,6 +2576,11 @@ virDomainGetControlInfo(virDomainPtr domain, * one of those snapshots is current. Note that some older servers * silently ignore this flag instead of diagnosing it as unsupported. * + * If @flags contains VIR_DOMAIN_XML_CHECKPOINTS, the XML will include + * an additional child element describing all checkpoints + * belonging to the domain, including an attribute current=3D'name' if + * one of those checkpoints is current. + * * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of e= rror. * the caller must free() the returned value. */ @@ -6450,7 +6455,9 @@ virConnectListDefinedDomains(virConnectPtr conn, char= **const names, * VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART, for filtering based on autostart; * VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT and * VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT, for filtering based on whether - * a domain has snapshots. + * a domain has snapshots; VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT and + * VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT, for filtering based on whether + * a domain has checkpoints. * * Example of usage: * diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index dbce3336d5..d026b33f53 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -817,6 +817,22 @@ LIBVIRT_4.10.0 { LIBVIRT_5.2.0 { global: virConnectGetStoragePoolCapabilities; + virDomainCheckpointCreateXML; + virDomainCheckpointCurrent; + virDomainCheckpointDelete; + virDomainCheckpointFree; + virDomainCheckpointGetConnect; + virDomainCheckpointGetDomain; + virDomainCheckpointGetName; + virDomainCheckpointGetParent; + virDomainCheckpointGetXMLDesc; + virDomainCheckpointHasMetadata; + virDomainCheckpointIsCurrent; + virDomainCheckpointListChildren; + virDomainCheckpointLookupByName; + virDomainCheckpointRef; + virDomainHasCurrentCheckpoint; + virDomainListCheckpoints; } LIBVIRT_4.10.0; # .... define new API here using predicted next version number .... --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937721171593.0759677844203; Wed, 6 Mar 2019 21:48:41 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51229307D874; Thu, 7 Mar 2019 05:48:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2A2D75C5FD; Thu, 7 Mar 2019 05:48:39 +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 D128A181A13C; Thu, 7 Mar 2019 05:48:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275mPJr003993 for ; Thu, 7 Mar 2019 00:48:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id 190085D788; Thu, 7 Mar 2019 05:48:25 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id B12075D783; Thu, 7 Mar 2019 05:48:12 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:39 -0600 Message-Id: <20190307054752.19522-8-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 07/20] backup: Introduce virDomainBackup APIs 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: , 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 07 Mar 2019 05:48:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Introduce a few more new public APIs related to incremental backups. This builds on the previous notion of a checkpoint (without an existing checkpoint, the new API is a full backup, differing only from virDomainCopy in the point of time chosen); and also allows creation of a new checkpoint at the same time as starting the backup (after all, an incremental backup is only useful if it covers the state since the previous backup). It also enhances event reporting for signaling when a push model backup completes (where the hypervisor creates the backup); note that the pull model does not have an event (starting the backup lets a third party access the data, and only the third party knows when it is finished). The full list of new API: virDomainBackupBegin; virDomainBackupEnd; virDomainBackupGetXMLDesc; Signed-off-by: Eric Blake --- include/libvirt/libvirt-domain.h | 41 +++++- src/driver-hypervisor.h | 14 ++ src/qemu/qemu_blockjob.h | 1 + examples/object-events/event-test.c | 3 + src/conf/domain_conf.c | 2 +- src/libvirt-domain.c | 208 ++++++++++++++++++++++++++++ src/libvirt_public.syms | 3 + tools/virsh-domain.c | 8 +- 8 files changed, 275 insertions(+), 5 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 7abfd03d91..3691aca338 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -3,7 +3,7 @@ * Summary: APIs for management of domains * Description: Provides APIs for the management of domains * - * Copyright (C) 2006-2015 Red Hat, Inc. + * Copyright (C) 2006-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -2422,6 +2422,9 @@ typedef enum { * exists as long as sync is active */ VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT =3D 4, + /* Backup (virDomainBackupBegin), job exists until virDomainBackupEnd = */ + VIR_DOMAIN_BLOCK_JOB_TYPE_BACKUP =3D 5, + # ifdef VIR_ENUM_SENTINELS VIR_DOMAIN_BLOCK_JOB_TYPE_LAST # endif @@ -3243,6 +3246,7 @@ typedef enum { VIR_DOMAIN_JOB_OPERATION_SNAPSHOT =3D 6, VIR_DOMAIN_JOB_OPERATION_SNAPSHOT_REVERT =3D 7, VIR_DOMAIN_JOB_OPERATION_DUMP =3D 8, + VIR_DOMAIN_JOB_OPERATION_BACKUP =3D 9, # ifdef VIR_ENUM_SENTINELS VIR_DOMAIN_JOB_OPERATION_LAST @@ -3258,6 +3262,14 @@ typedef enum { */ # define VIR_DOMAIN_JOB_OPERATION "operation" +/** + * VIR_DOMAIN_JOB_ID: + * + * virDomainGetJobStats field: the id of the job (so far, only for jobs + * started by virDomainBackupBegin()), as VIR_TYPED_PARAM_INT. + */ +# define VIR_DOMAIN_JOB_ID "id" + /** * VIR_DOMAIN_JOB_TIME_ELAPSED: * @@ -4082,7 +4094,8 @@ typedef void (*virConnectDomainEventMigrationIteratio= nCallback)(virConnectPtr co * @nparams: size of the params array * @opaque: application specific data * - * This callback occurs when a job (such as migration) running on the doma= in + * This callback occurs when a job (such as migration or push-model + * virDomainBackupBegin()) running on the domain * is completed. The params array will contain statistics of the just comp= leted * job as virDomainGetJobStats would return. The callback must not free @p= arams * (the array will be freed once the callback finishes). @@ -4878,4 +4891,28 @@ int virDomainGetLaunchSecurityInfo(virDomainPtr doma= in, int *nparams, unsigned int flags); +typedef enum { + VIR_DOMAIN_BACKUP_BEGIN_NO_METADATA =3D (1 << 0), /* Make checkpoint w= ithout + remembering it */ + VIR_DOMAIN_BACKUP_BEGIN_QUIESCE =3D (1 << 1), /* use guest agent to + quiesce all mounted + file systems within + the domain */ +} virDomainBackupBeginFlags; + +/* Begin an incremental backup job, possibly creating a checkpoint. */ +int virDomainBackupBegin(virDomainPtr domain, const char *diskXml, + const char *checkpointXml, unsigned int flags); + +/* Learn about an ongoing backup job. */ +char *virDomainBackupGetXMLDesc(virDomainPtr domain, int id, + unsigned int flags); + +typedef enum { + VIR_DOMAIN_BACKUP_END_ABORT =3D (1 << 0), /* Abandon a push model back= up */ +} virDomainBackupEndFlags; + +/* Complete (or abort) an incremental backup job. */ +int virDomainBackupEnd(virDomainPtr domain, int id, unsigned int flags); + #endif /* LIBVIRT_DOMAIN_H */ diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 14db8e49f3..4e65b8ad36 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -1376,6 +1376,17 @@ typedef int (*virDrvDomainCheckpointDelete)(virDomainCheckpointPtr checkpoint, unsigned int flags); +typedef int +(*virDrvDomainBackupBegin)(virDomainPtr domain, const char *diskXml, + const char *checkpointXml, unsigned int flags); + +typedef char * +(*virDrvDomainBackupGetXMLDesc)(virDomainPtr domain, int id, + unsigned int flags); + +typedef int +(*virDrvDomainBackupEnd)(virDomainPtr domain, int id, unsigned int flags); + typedef struct _virHypervisorDriver virHypervisorDriver; typedef virHypervisorDriver *virHypervisorDriverPtr; @@ -1638,6 +1649,9 @@ struct _virHypervisorDriver { virDrvDomainCheckpointIsCurrent domainCheckpointIsCurrent; virDrvDomainCheckpointHasMetadata domainCheckpointHasMetadata; virDrvDomainCheckpointDelete domainCheckpointDelete; + virDrvDomainBackupBegin domainBackupBegin; + virDrvDomainBackupGetXMLDesc domainBackupGetXMLDesc; + virDrvDomainBackupEnd domainBackupEnd; }; diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h index c7325c6daf..95f53dde16 100644 --- a/src/qemu/qemu_blockjob.h +++ b/src/qemu/qemu_blockjob.h @@ -55,6 +55,7 @@ typedef enum { QEMU_BLOCKJOB_TYPE_COPY =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COPY, QEMU_BLOCKJOB_TYPE_COMMIT =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT, QEMU_BLOCKJOB_TYPE_ACTIVE_COMMIT =3D VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_= COMMIT, + QEMU_BLOCKJOB_TYPE_BACKUP =3D VIR_DOMAIN_BLOCK_JOB_TYPE_BACKUP, /* Additional enum values local to qemu */ QEMU_BLOCKJOB_TYPE_INTERNAL, QEMU_BLOCKJOB_TYPE_LAST diff --git a/examples/object-events/event-test.c b/examples/object-events/e= vent-test.c index fcf4492470..98337ad185 100644 --- a/examples/object-events/event-test.c +++ b/examples/object-events/event-test.c @@ -891,6 +891,9 @@ blockJobTypeToStr(int type) case VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT: return "active layer block commit"; + + case VIR_DOMAIN_BLOCK_JOB_TYPE_BACKUP: + return "backup"; } return "unknown"; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5d57c3cc1a..c12ae57768 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1082,7 +1082,7 @@ VIR_ENUM_IMPL(virDomainHPTResizing, * XML (remaining types are not two-phase). */ VIR_ENUM_DECL(virDomainBlockJob); VIR_ENUM_IMPL(virDomainBlockJob, VIR_DOMAIN_BLOCK_JOB_TYPE_LAST, - "", "", "copy", "", "active-commit", + "", "", "copy", "", "active-commit", "", ); VIR_ENUM_IMPL(virDomainMemoryModel, diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 10768bd279..d83584c690 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -10352,6 +10352,12 @@ virDomainBlockRebase(virDomainPtr dom, const char = *disk, * over the destination format, the ability to copy to a destination that * is not a local file, and the possibility of additional tuning parameter= s. * + * The copy created by this API is not finalized until the job ends, + * and does not lend itself to incremental backups (beyond what + * VIR_DOMAIN_BLOCK_COPY_SHALLOW provides) nor to third-party control + * over the data being copied. For those features, use + * virDomainBackupBegin(). + * * Returns 0 if the operation has started, -1 on failure. */ int @@ -12372,3 +12378,205 @@ int virDomainGetLaunchSecurityInfo(virDomainPtr d= omain, virDispatchError(domain->conn); return -1; } + + +/** + * virDomainBackupBegin: + * @domain: a domain object + * @diskXml: description of storage to utilize and expose during + * the backup, or NULL + * @checkpointXml: description of a checkpoint to create, or NULL + * @flags: bitwise-OR of supported virDomainBackupBeginFlags + * + * Start a point-in-time backup job for the specified disks of a + * running domain. + * + * A backup job is mutually exclusive with domain migration + * (particularly when the job sets up an NBD export, since it is not + * possible to tell any NBD clients about a server migrating between + * hosts). For now, backup jobs are also mutually exclusive with any + * other block job on the same device, although this restriction may + * be lifted in a future release. Progress of the backup job can be + * tracked via virDomainGetJobStats(). The job remains active until a + * subsequent call to virDomainBackupEnd(), even if it no longer has + * anything to copy. + * + * This API differs from virDomainBlockCopy() in that it can grab the + * state of more than one disk in parallel, and the state is captured + * as of the start of the job, rather than the end. + * + * There are two fundamental backup approaches. The first, called a + * push model, instructs the hypervisor to copy the state of the guest + * disk to the designated storage destination (which may be on the + * local file system or a network device); in this mode, the + * hypervisor writes the content of the guest disk to the destination, + * then emits VIR_DOMAIN_EVENT_ID_JOB_COMPLETED when the backup is + * either complete or failed (the backup image is invalid if the job + * is ended prior to the event being emitted). The second, called a + * pull model, instructs the hypervisor to expose the state of the + * guest disk over an NBD export; a third-party client can then + * connect to this export, and read whichever portions of the disk it + * desires. In this mode, there is no event; libvirt has to be + * informed when the third-party NBD client is done and the backup + * resources can be released. + * + * The @diskXml parameter is optional but usually provided, and + * contains details about the backup, including which backup mode to + * use, whether the backup is incremental from a previous checkpoint, + * which disks participate in the backup, the destination for a push + * model backup, and the temporary storage and NBD server details for + * a pull model backup. If omitted, the backup attempts to default to + * a push mode full backup of all disks, where libvirt generates a + * filename for each disk by appending a suffix of a timestamp in + * seconds since the Epoch. virDomainBackupGetXMLDesc() can be called + * to learn actual values selected. For more information, see + * formatcheckpoint.html#BackupAttributes. + * + * The @checkpointXml parameter is optional; if non-NULL, then libvirt + * behaves as if virDomainCheckpointCreateXML() were called with + * @checkpointXml and the flag VIR_DOMAIN_BACKUP_BEGIN_NO_METADATA + * forwarded appropriately, atomically covering the same guest state + * that will be part of the backup. The creation of a new checkpoint + * allows for future incremental backups. Note that some hypervisors + * may require a particular disk format, such as qcow2, in order to + * take advantage of checkpoints, while allowing arbitrary formats + * if checkpoints are not involved. + * + * Returns a non-negative job id on success, or negative on failure. + * This operation returns quickly, such that a user can choose to + * start a backup job between virDomainFSFreeze() and + * virDomainFSThaw() in order to create the backup while guest I/O is + * quiesced. + */ +/* FIXME: Do we need a specific API for listing all current backup + * jobs (which, at the moment, is at most one job), or is it better to + * refactor other existing job APIs in libvirt-domain.c to have job-id + * counterparts along with a generic listing of all jobs (with flags + * for filtering to specific job types)? + */ +int +virDomainBackupBegin(virDomainPtr domain, const char *diskXml, + const char *checkpointXml, unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "diskXml=3D%s, checkpointXml=3D%s, flags=3D0x= %x", + NULLSTR(diskXml), NULLSTR(checkpointXml), flags); + + virResetLastError(); + + virCheckDomainReturn(domain, -1); + conn =3D domain->conn; + + virCheckReadOnlyGoto(conn->flags, error); + if (flags & VIR_DOMAIN_BACKUP_BEGIN_NO_METADATA) + virCheckNonNullArgGoto(checkpointXml, error); + + if (conn->driver->domainBackupBegin) { + int ret; + ret =3D conn->driver->domainBackupBegin(domain, diskXml, checkpoin= tXml, + flags); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + + +/** + * virDomainBackupGetXMLDesc: + * @domain: a domain object + * @id: the id of an active backup job previously started with + * virDomainBackupBegin() + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * In some cases, a user can start a backup job without supplying all + * details, and rely on libvirt to fill in the rest (for example, + * selecting the port used for an NBD export). This API can then be + * used to learn what default values were chosen. + * + * Returns a NUL-terminated UTF-8 encoded XML instance, or NULL in + * case of error. The caller must free() the returned value. + */ +char * +virDomainBackupGetXMLDesc(virDomainPtr domain, int id, unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "id=3D%d, flags=3D0x%x", id, flags); + + virResetLastError(); + + virCheckDomainReturn(domain, NULL); + conn =3D domain->conn; + + virCheckNonNegativeArgGoto(id, error); + + if (conn->driver->domainBackupGetXMLDesc) { + char *ret; + ret =3D conn->driver->domainBackupGetXMLDesc(domain, id, flags); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return NULL; +} + + +/** + * virDomainBackupEnd: + * @domain: a domain object + * @id: the id of an active backup job previously started with + * virDomainBackupBegin() + * @flags: bitwise-OR of supported virDomainBackupEndFlags + * + * Conclude a point-in-time backup job @id on the given domain. + * + * If the backup job uses the push model, but the event marking that + * all data has been copied has not yet been emitted, then the command + * fails unless @flags includes VIR_DOMAIN_BACKUP_END_ABORT. If the + * event has been issued, or if the backup uses the pull model, the + * flag has no effect. + * + * Returns 1 if the backup job completed successfully (the backup + * destination file in a push model is consistent), 0 if the job was + * aborted successfully (only when VIR_DOMAIN_BACKUP_END_ABORT is + * passed; the destination file is unusable), and -1 on failure. + */ +int +virDomainBackupEnd(virDomainPtr domain, int id, unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "id=3D%d, flags=3D0x%x", id, flags); + + virResetLastError(); + + virCheckDomainReturn(domain, -1); + conn =3D domain->conn; + + virCheckReadOnlyGoto(conn->flags, error); + virCheckNonNegativeArgGoto(id, error); + + if (conn->driver->domainBackupEnd) { + int ret; + ret =3D conn->driver->domainBackupEnd(domain, id, flags); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index d026b33f53..a7aeba8888 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -817,6 +817,9 @@ LIBVIRT_4.10.0 { LIBVIRT_5.2.0 { global: virConnectGetStoragePoolCapabilities; + virDomainBackupBegin; + virDomainBackupEnd; + virDomainBackupGetXMLDesc; virDomainCheckpointCreateXML; virDomainCheckpointCurrent; virDomainCheckpointDelete; diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index bdd6459cc6..ce4c6f1bad 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2561,7 +2561,9 @@ VIR_ENUM_IMPL(virshDomainBlockJob, N_("Block Pull"), N_("Block Copy"), N_("Block Commit"), - N_("Active Block Commit")); + N_("Active Block Commit"), + N_("Backup"), +); static const char * virshDomainBlockJobToString(int type) @@ -6064,7 +6066,9 @@ VIR_ENUM_IMPL(virshDomainJobOperation, N_("Outgoing migration"), N_("Snapshot"), N_("Snapshot revert"), - N_("Dump")); + N_("Dump"), + N_("Backup"), +); static const char * virshDomainJobOperationToString(int op) --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937720248879.3263965090875; Wed, 6 Mar 2019 21:48:40 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 556FAC04BD37; Thu, 7 Mar 2019 05:48:38 +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 272C619C68; Thu, 7 Mar 2019 05:48:38 +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 D66FA3FB10; Thu, 7 Mar 2019 05:48:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275mQTZ003998 for ; Thu, 7 Mar 2019 00:48:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3CC0B5D788; Thu, 7 Mar 2019 05:48:26 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CC735D783; Thu, 7 Mar 2019 05:48:25 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:40 -0600 Message-Id: <20190307054752.19522-9-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 08/20] backup: Add new domain:checkpoint access control 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 07 Mar 2019 05:48:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Creating a checkpoint does not modify guest-visible state, but does modify host resources. Rather than reuse existing domain:write, domain:block_write, or domain:snapshot access controls, it seems better to introduce a new access control specific to tasks related to checkpoints and incremental backups of guest disk state. Signed-off-by: Eric Blake --- src/access/viraccessperm.h | 8 +++++++- src/access/viraccessperm.c | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/access/viraccessperm.h b/src/access/viraccessperm.h index ce3865b359..509d3e327a 100644 --- a/src/access/viraccessperm.h +++ b/src/access/viraccessperm.h @@ -1,7 +1,7 @@ /* * viraccessperm.h: access control permissions * - * Copyright (C) 2012-2014 Red Hat, Inc. + * Copyright (C) 2012-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -186,6 +186,12 @@ typedef enum { */ VIR_ACCESS_PERM_DOMAIN_MIGRATE, /* Host migration */ + /** + * @desc: Checkpoint domain + * @message: Checkpointing domain requires authorization + */ + VIR_ACCESS_PERM_DOMAIN_CHECKPOINT, /* Checkpoint disks */ + /** * @desc: Snapshot domain * @message: Snapshotting domain requires authorization diff --git a/src/access/viraccessperm.c b/src/access/viraccessperm.c index 67f751ef9c..c1c40ac5bd 100644 --- a/src/access/viraccessperm.c +++ b/src/access/viraccessperm.c @@ -1,7 +1,7 @@ /* * viraccessperm.c: access control permissions * - * Copyright (C) 2012-2014 Red Hat, Inc. + * Copyright (C) 2012-2018 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -39,7 +39,8 @@ VIR_ENUM_IMPL(virAccessPermDomain, "getattr", "read", "write", "read_secure", "start", "stop", "reset", "save", "delete", - "migrate", "snapshot", "suspend", "hibernate", "core_dump", = "pm_control", + "migrate", "checkpoint", "snapshot", "suspend", "hibernate", + "core_dump", "pm_control", "init_control", "inject_nmi", "send_input", "send_signal", "fs_trim", "fs_freeze", "block_read", "block_write", "mem_read", --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937745999204.9436869471806; Wed, 6 Mar 2019 21:49:05 -0800 (PST) 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 3EA1358E51; Thu, 7 Mar 2019 05:49:04 +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 0FF0E60146; Thu, 7 Mar 2019 05:49:04 +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 C8CFA3FA4D; Thu, 7 Mar 2019 05:49:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275mRg1004008 for ; Thu, 7 Mar 2019 00:48:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 712CA5D787; Thu, 7 Mar 2019 05:48:27 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E8ED5D783; Thu, 7 Mar 2019 05:48:26 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:41 -0600 Message-Id: <20190307054752.19522-10-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 09/20] backup: Implement backup APIs for remote driver 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: , 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.39]); Thu, 07 Mar 2019 05:49:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The remote code generator had to be taught about the new virDomainCheckpointPtr type, at which point the remote driver code for backups can be generated. Signed-off-by: Eric Blake --- src/remote/remote_daemon_dispatch.c | 22 ++- src/remote/remote_driver.c | 33 +++- src/remote/remote_protocol.x | 239 +++++++++++++++++++++++++++- src/remote_protocol-structs | 129 +++++++++++++++ src/rpc/gendispatch.pl | 32 ++-- 5 files changed, 435 insertions(+), 20 deletions(-) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index df28259042..5433378539 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1,7 +1,7 @@ /* * remote_daemon_dispatch.c: handlers for RPC method calls * - * Copyright (C) 2007-2018 Red Hat, Inc. + * Copyright (C) 2007-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -89,6 +89,7 @@ static virStorageVolPtr get_nonnull_storage_vol(virConnec= tPtr conn, remote_nonnu static virSecretPtr get_nonnull_secret(virConnectPtr conn, remote_nonnull_= secret secret); static virNWFilterPtr get_nonnull_nwfilter(virConnectPtr conn, remote_nonn= ull_nwfilter nwfilter); static virNWFilterBindingPtr get_nonnull_nwfilter_binding(virConnectPtr co= nn, remote_nonnull_nwfilter_binding binding); +static virDomainCheckpointPtr get_nonnull_domain_checkpoint(virDomainPtr d= om, remote_nonnull_domain_checkpoint checkpoint); static virDomainSnapshotPtr get_nonnull_domain_snapshot(virDomainPtr dom, = remote_nonnull_domain_snapshot snapshot); static virNodeDevicePtr get_nonnull_node_device(virConnectPtr conn, remote= _nonnull_node_device dev); static int make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainPt= r dom_src) ATTRIBUTE_RETURN_CHECK; @@ -100,6 +101,7 @@ static int make_nonnull_node_device(remote_nonnull_node= _device *dev_dst, virNode static int make_nonnull_secret(remote_nonnull_secret *secret_dst, virSecre= tPtr secret_src) ATTRIBUTE_RETURN_CHECK; static int make_nonnull_nwfilter(remote_nonnull_nwfilter *net_dst, virNWFi= lterPtr nwfilter_src) ATTRIBUTE_RETURN_CHECK; static int make_nonnull_nwfilter_binding(remote_nonnull_nwfilter_binding *= binding_dst, virNWFilterBindingPtr binding_src) ATTRIBUTE_RETURN_CHECK; +static int make_nonnull_domain_checkpoint(remote_nonnull_domain_checkpoint= *checkpoint_dst, virDomainCheckpointPtr checkpoint_src) ATTRIBUTE_RETURN_C= HECK; static int make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *sn= apshot_dst, virDomainSnapshotPtr snapshot_src) ATTRIBUTE_RETURN_CHECK; static int @@ -7238,6 +7240,12 @@ get_nonnull_nwfilter_binding(virConnectPtr conn, rem= ote_nonnull_nwfilter_binding return virGetNWFilterBinding(conn, binding.portdev, binding.filtername= ); } +static virDomainCheckpointPtr +get_nonnull_domain_checkpoint(virDomainPtr dom, remote_nonnull_domain_chec= kpoint checkpoint) +{ + return virGetDomainCheckpoint(dom, checkpoint.name); +} + static virDomainSnapshotPtr get_nonnull_domain_snapshot(virDomainPtr dom, remote_nonnull_domain_snapsh= ot snapshot) { @@ -7348,6 +7356,18 @@ make_nonnull_nwfilter_binding(remote_nonnull_nwfilte= r_binding *binding_dst, virN return 0; } +static int +make_nonnull_domain_checkpoint(remote_nonnull_domain_checkpoint *checkpoin= t_dst, virDomainCheckpointPtr checkpoint_src) +{ + if (VIR_STRDUP_QUIET(checkpoint_dst->name, checkpoint_src->name) < 0) + return -1; + if (make_nonnull_domain(&checkpoint_dst->dom, checkpoint_src->domain) = < 0) { + VIR_FREE(checkpoint_dst->name); + return -1; + } + return 0; +} + static int make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *snapshot_dst,= virDomainSnapshotPtr snapshot_src) { diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index eabe7a3823..44428073d9 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -2,7 +2,7 @@ * remote_driver.c: driver to provide access to libvirtd running * on a remote machine * - * Copyright (C) 2007-2015 Red Hat, Inc. + * Copyright (C) 2007-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -145,6 +145,7 @@ static virStoragePoolPtr get_nonnull_storage_pool(virCo= nnectPtr conn, remote_non static virStorageVolPtr get_nonnull_storage_vol(virConnectPtr conn, remote= _nonnull_storage_vol vol); static virNodeDevicePtr get_nonnull_node_device(virConnectPtr conn, remote= _nonnull_node_device dev); static virSecretPtr get_nonnull_secret(virConnectPtr conn, remote_nonnull_= secret secret); +static virDomainCheckpointPtr get_nonnull_domain_checkpoint(virDomainPtr d= omain, remote_nonnull_domain_checkpoint checkpoint); static virDomainSnapshotPtr get_nonnull_domain_snapshot(virDomainPtr domai= n, remote_nonnull_domain_snapshot snapshot); static void make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainP= tr dom_src); static void make_nonnull_network(remote_nonnull_network *net_dst, virNetwo= rkPtr net_src); @@ -156,6 +157,7 @@ make_nonnull_node_device(remote_nonnull_node_device *de= v_dst, virNodeDevicePtr d static void make_nonnull_secret(remote_nonnull_secret *secret_dst, virSecr= etPtr secret_src); static void make_nonnull_nwfilter(remote_nonnull_nwfilter *nwfilter_dst, v= irNWFilterPtr nwfilter_src); static void make_nonnull_nwfilter_binding(remote_nonnull_nwfilter_binding = *binding_dst, virNWFilterBindingPtr binding_src); +static void make_nonnull_domain_checkpoint(remote_nonnull_domain_checkpoin= t *checkpoint_dst, virDomainCheckpointPtr checkpoint_src); static void make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *s= napshot_dst, virDomainSnapshotPtr snapshot_src); /*----------------------------------------------------------------------*/ @@ -8193,6 +8195,12 @@ get_nonnull_nwfilter_binding(virConnectPtr conn, rem= ote_nonnull_nwfilter_binding return virGetNWFilterBinding(conn, binding.portdev, binding.filtername= ); } +static virDomainCheckpointPtr +get_nonnull_domain_checkpoint(virDomainPtr domain, remote_nonnull_domain_c= heckpoint checkpoint) +{ + return virGetDomainCheckpoint(domain, checkpoint.name); +} + static virDomainSnapshotPtr get_nonnull_domain_snapshot(virDomainPtr domain, remote_nonnull_domain_sna= pshot snapshot) { @@ -8267,6 +8275,13 @@ make_nonnull_nwfilter_binding(remote_nonnull_nwfilte= r_binding *binding_dst, virN binding_dst->filtername =3D binding_src->filtername; } +static void +make_nonnull_domain_checkpoint(remote_nonnull_domain_checkpoint *checkpoin= t_dst, virDomainCheckpointPtr checkpoint_src) +{ + checkpoint_dst->name =3D checkpoint_src->name; + make_nonnull_domain(&checkpoint_dst->dom, checkpoint_src->domain); +} + static void make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *snapshot_dst,= virDomainSnapshotPtr snapshot_src) { @@ -8516,7 +8531,21 @@ static virHypervisorDriver hypervisor_driver =3D { .connectCompareHypervisorCPU =3D remoteConnectCompareHypervisorCPU, /*= 4.4.0 */ .connectBaselineHypervisorCPU =3D remoteConnectBaselineHypervisorCPU, = /* 4.4.0 */ .nodeGetSEVInfo =3D remoteNodeGetSEVInfo, /* 4.5.0 */ - .domainGetLaunchSecurityInfo =3D remoteDomainGetLaunchSecurityInfo /* = 4.5.0 */ + .domainGetLaunchSecurityInfo =3D remoteDomainGetLaunchSecurityInfo, /*= 4.5.0 */ + .domainCheckpointCreateXML =3D remoteDomainCheckpointCreateXML, /* 5.2= .0 */ + .domainCheckpointGetXMLDesc =3D remoteDomainCheckpointGetXMLDesc, /* 5= .2.0 */ + .domainListCheckpoints =3D remoteDomainListCheckpoints, /* 5.2.0 */ + .domainCheckpointListChildren =3D remoteDomainCheckpointListChildren, = /* 5.2.0 */ + .domainCheckpointLookupByName =3D remoteDomainCheckpointLookupByName, = /* 5.2.0 */ + .domainHasCurrentCheckpoint =3D remoteDomainHasCurrentCheckpoint, /* 5= .2.0 */ + .domainCheckpointGetParent =3D remoteDomainCheckpointGetParent, /* 5.2= .0 */ + .domainCheckpointCurrent =3D remoteDomainCheckpointCurrent, /* 5.2.0 */ + .domainCheckpointIsCurrent =3D remoteDomainCheckpointIsCurrent, /* 5.2= .0 */ + .domainCheckpointHasMetadata =3D remoteDomainCheckpointHasMetadata, /*= 5.2.0 */ + .domainCheckpointDelete =3D remoteDomainCheckpointDelete, /* 5.2.0 */ + .domainBackupBegin =3D remoteDomainBackupBegin, /* 5.2.0 */ + .domainBackupGetXMLDesc =3D remoteDomainBackupGetXMLDesc, /* 5.2.0 */ + .domainBackupEnd =3D remoteDomainBackupEnd, /* 5.2.0 */ }; static virNetworkDriver network_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 74be4b37d0..ca03460756 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -3,7 +3,7 @@ * remote_internal driver and libvirtd. This protocol is * internal and may change at any time. * - * Copyright (C) 2006-2015 Red Hat, Inc. + * Copyright (C) 2006-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -137,6 +137,9 @@ const REMOTE_AUTH_TYPE_LIST_MAX =3D 20; /* Upper limit on list of memory stats */ const REMOTE_DOMAIN_MEMORY_STATS_MAX =3D 1024; +/* Upper limit on lists of domain checkpoints. */ +const REMOTE_DOMAIN_CHECKPOINT_LIST_MAX =3D 16384; + /* Upper limit on lists of domain snapshots. */ const REMOTE_DOMAIN_SNAPSHOT_LIST_MAX =3D 16384; @@ -322,6 +325,12 @@ struct remote_nonnull_secret { remote_nonnull_string usageID; }; +/* A checkpoint which may not be NULL. */ +struct remote_nonnull_domain_checkpoint { + remote_nonnull_string name; + remote_nonnull_domain dom; +}; + /* A snapshot which may not be NULL. */ struct remote_nonnull_domain_snapshot { remote_nonnull_string name; @@ -3564,6 +3573,137 @@ struct remote_connect_list_all_nwfilter_bindings_re= t { /* insert@1 */ remote_nonnull_nwfilter_binding bindings; unsigned int ret; }; +struct remote_domain_checkpoint_create_xml_args { + remote_nonnull_domain dom; + remote_nonnull_string xml_desc; + unsigned int flags; +}; + +struct remote_domain_checkpoint_create_xml_ret { + remote_nonnull_domain_checkpoint checkpoint; +}; + +struct remote_domain_checkpoint_get_xml_desc_args { + remote_nonnull_domain_checkpoint checkpoint; + unsigned int flags; +}; + +struct remote_domain_checkpoint_get_xml_desc_ret { + remote_nonnull_string xml; +}; + +struct remote_domain_list_checkpoints_args { + remote_nonnull_domain dom; + int need_results; + unsigned int flags; +}; + +struct remote_domain_list_checkpoints_ret { /* insert@1 */ + remote_nonnull_domain_checkpoint checkpoints; + int ret; +}; + +struct remote_domain_checkpoint_list_children_args { + remote_nonnull_domain_checkpoint checkpoint; + int need_results; + unsigned int flags; +}; + +struct remote_domain_checkpoint_list_children_ret { /* insert@1 */ + remote_nonnull_domain_checkpoint checkpoints; + int ret; +}; + +struct remote_domain_checkpoint_lookup_by_name_args { + remote_nonnull_domain dom; + remote_nonnull_string name; + unsigned int flags; +}; + +struct remote_domain_checkpoint_lookup_by_name_ret { + remote_nonnull_domain_checkpoint checkpoint; +}; + +struct remote_domain_has_current_checkpoint_args { + remote_nonnull_domain dom; + unsigned int flags; +}; + +struct remote_domain_has_current_checkpoint_ret { + int result; +}; + +struct remote_domain_checkpoint_get_parent_args { + remote_nonnull_domain_checkpoint checkpoint; + unsigned int flags; +}; + +struct remote_domain_checkpoint_get_parent_ret { + remote_nonnull_domain_checkpoint parent; +}; + +struct remote_domain_checkpoint_current_args { + remote_nonnull_domain dom; + unsigned int flags; +}; + +struct remote_domain_checkpoint_current_ret { + remote_nonnull_domain_checkpoint checkpoint; +}; + +struct remote_domain_checkpoint_is_current_args { + remote_nonnull_domain_checkpoint checkpoint; + unsigned int flags; +}; + +struct remote_domain_checkpoint_is_current_ret { + int current; +}; + +struct remote_domain_checkpoint_has_metadata_args { + remote_nonnull_domain_checkpoint checkpoint; + unsigned int flags; +}; + +struct remote_domain_checkpoint_has_metadata_ret { + int metadata; +}; + +struct remote_domain_checkpoint_delete_args { + remote_nonnull_domain_checkpoint checkpoint; + unsigned int flags; +}; + +struct remote_domain_backup_begin_args { + remote_nonnull_domain dom; + remote_string disk_xml; + remote_string checkpoint_xml; + unsigned int flags; +}; + +struct remote_domain_backup_begin_ret { + int result; +}; + +struct remote_domain_backup_get_xml_desc_args { + remote_nonnull_domain dom; + int id; + unsigned int flags; +}; + +struct remote_domain_backup_get_xml_desc_ret { + remote_nonnull_string xml; +}; + +struct remote_domain_backup_end_args { + remote_nonnull_domain dom; + int id; + unsigned int flags; +}; + +struct remote_domain_backup_end_ret { + int retcode; +}; struct remote_connect_get_storage_pool_capabilities_args { unsigned int flags; @@ -6342,5 +6482,100 @@ enum remote_procedure { * @generate: both * @acl: connect:read */ - REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES =3D 403 + REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES =3D 403, + + /** + * @generate: both + * @acl: domain:checkpoint + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_CREATE_XML =3D 404, + + /** + * @generate: both + * @acl: domain:read + * @acl: domain:read_secure:VIR_DOMAIN_CHECKPOINT_XML_SECURE + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_GET_XML_DESC =3D 405, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_LIST_CHECKPOINTS =3D 406, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_LIST_CHILDREN =3D 407, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_LOOKUP_BY_NAME =3D 408, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_HAS_CURRENT_CHECKPOINT =3D 409, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_CURRENT =3D 410, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_GET_PARENT =3D 411, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_IS_CURRENT =3D 412, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_HAS_METADATA =3D 413, + + /** + * @generate: both + * @acl: domain:checkpoint + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_DELETE =3D 414, + + /** + * @generate: both + * @acl: domain:checkpoint + * @acl: domain:block_read + */ + REMOTE_PROC_DOMAIN_BACKUP_BEGIN =3D 415, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_BACKUP_GET_XML_DESC =3D 416, + + /** + * @generate: both + * @acl: domain:checkpoint + */ + REMOTE_PROC_DOMAIN_BACKUP_END =3D 417 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 768189c573..70f560c1b1 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -46,6 +46,10 @@ struct remote_nonnull_secret { int usageType; remote_nonnull_string usageID; }; +struct remote_nonnull_domain_checkpoint { + remote_nonnull_string name; + remote_nonnull_domain dom; +}; struct remote_nonnull_domain_snapshot { remote_nonnull_string name; remote_nonnull_domain dom; @@ -2981,6 +2985,117 @@ struct remote_connect_get_storage_pool_capabilities= _args { struct remote_connect_get_storage_pool_capabilities_ret { remote_nonnull_string capabilities; }; +struct remote_domain_checkpoint_create_xml_args { + remote_nonnull_domain dom; + remote_nonnull_string xml_desc; + u_int flags; +}; +struct remote_domain_checkpoint_create_xml_ret { + remote_nonnull_domain_checkpoint checkpoint; +}; +struct remote_domain_checkpoint_get_xml_desc_args { + remote_nonnull_domain_checkpoint checkpoint; + u_int flags; +}; +struct remote_domain_checkpoint_get_xml_desc_ret { + remote_nonnull_string xml; +}; +struct remote_domain_list_checkpoints_args { + remote_nonnull_domain dom; + int need_results; + u_int flags; +}; +struct remote_domain_list_checkpoints_ret { + struct { + u_int checkpoints_len; + remote_nonnull_domain_checkpoint * checkpoints_val; + } checkpoints; + int ret; +}; +struct remote_domain_checkpoint_list_children_args { + remote_nonnull_domain_checkpoint checkpoint; + int need_results; + u_int flags; +}; +struct remote_domain_checkpoint_list_children_ret { + struct { + u_int checkpoints_len; + remote_nonnull_domain_checkpoint * checkpoints_val; + } checkpoints; + int ret; +}; +struct remote_domain_checkpoint_lookup_by_name_args { + remote_nonnull_domain dom; + remote_nonnull_string name; + u_int flags; +}; +struct remote_domain_checkpoint_lookup_by_name_ret { + remote_nonnull_domain_checkpoint checkpoint; +}; +struct remote_domain_has_current_checkpoint_args { + remote_nonnull_domain dom; + u_int flags; +}; +struct remote_domain_has_current_checkpoint_ret { + int result; +}; +struct remote_domain_checkpoint_get_parent_args { + remote_nonnull_domain_checkpoint checkpoint; + u_int flags; +}; +struct remote_domain_checkpoint_get_parent_ret { + remote_nonnull_domain_checkpoint parent; +}; +struct remote_domain_checkpoint_current_args { + remote_nonnull_domain dom; + u_int flags; +}; +struct remote_domain_checkpoint_current_ret { + remote_nonnull_domain_checkpoint checkpoint; +}; +struct remote_domain_checkpoint_is_current_args { + remote_nonnull_domain_checkpoint checkpoint; + u_int flags; +}; +struct remote_domain_checkpoint_is_current_ret { + int current; +}; +struct remote_domain_checkpoint_has_metadata_args { + remote_nonnull_domain_checkpoint checkpoint; + u_int flags; +}; +struct remote_domain_checkpoint_has_metadata_ret { + int metadata; +}; +struct remote_domain_checkpoint_delete_args { + remote_nonnull_domain_checkpoint checkpoint; + u_int flags; +}; +struct remote_domain_backup_begin_args { + remote_nonnull_domain dom; + remote_string disk_xml; + remote_string checkpoint_xml; + u_int flags; +}; +struct remote_domain_backup_begin_ret { + int result; +}; +struct remote_domain_backup_get_xml_desc_args { + remote_nonnull_domain dom; + int id; + u_int flags; +}; +struct remote_domain_backup_get_xml_desc_ret { + remote_nonnull_string xml; +}; +struct remote_domain_backup_end_args { + remote_nonnull_domain dom; + int id; + u_int flags; +}; +struct remote_domain_backup_end_ret { + int retcode; +}; enum remote_procedure { REMOTE_PROC_CONNECT_OPEN =3D 1, REMOTE_PROC_CONNECT_CLOSE =3D 2, @@ -3385,4 +3500,18 @@ enum remote_procedure { REMOTE_PROC_CONNECT_LIST_ALL_NWFILTER_BINDINGS =3D 401, REMOTE_PROC_DOMAIN_SET_IOTHREAD_PARAMS =3D 402, REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES =3D 403, + REMOTE_PROC_DOMAIN_CHECKPOINT_CREATE_XML =3D 404, + REMOTE_PROC_DOMAIN_CHECKPOINT_GET_XML_DESC =3D 405, + REMOTE_PROC_DOMAIN_LIST_CHECKPOINTS =3D 406, + REMOTE_PROC_DOMAIN_CHECKPOINT_LIST_CHILDREN =3D 407, + REMOTE_PROC_DOMAIN_CHECKPOINT_LOOKUP_BY_NAME =3D 408, + REMOTE_PROC_DOMAIN_HAS_CURRENT_CHECKPOINT =3D 409, + REMOTE_PROC_DOMAIN_CHECKPOINT_CURRENT =3D 410, + REMOTE_PROC_DOMAIN_CHECKPOINT_GET_PARENT =3D 411, + REMOTE_PROC_DOMAIN_CHECKPOINT_IS_CURRENT =3D 412, + REMOTE_PROC_DOMAIN_CHECKPOINT_HAS_METADATA =3D 413, + REMOTE_PROC_DOMAIN_CHECKPOINT_DELETE =3D 414, + REMOTE_PROC_DOMAIN_BACKUP_BEGIN =3D 415, + REMOTE_PROC_DOMAIN_BACKUP_GET_XML_DESC =3D 416, + REMOTE_PROC_DOMAIN_BACKUP_END =3D 417, }; diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index ae3a42c4c1..1d20a7f277 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -1,6 +1,6 @@ #!/usr/bin/env perl # -# Copyright (C) 2010-2015 Red Hat, Inc. +# Copyright (C) 2010-2018 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -567,18 +567,20 @@ elsif ($mode eq "server") { push(@args_list, "$2"); push(@free_list, " virObjectUnref($2);"); - } elsif ($args_member =3D~ m/^remote_nonnull_domain_snapsh= ot (\S+);$/) { + } elsif ($args_member =3D~ m/^remote_nonnull_domain_(check= point|snapshot) (\S+);$/) { + my $type_name =3D name_to_TypeName($1); + push(@vars_list, "virDomainPtr dom =3D NULL"); - push(@vars_list, "virDomainSnapshotPtr snapshot =3D NU= LL"); + push(@vars_list, "virDomain${type_name}Ptr ${1} =3D NU= LL"); push(@getters_list, - " if (!(dom =3D get_nonnull_domain($conn, args= ->${1}.dom)))\n" . + " if (!(dom =3D get_nonnull_domain($conn, args= ->${2}.dom)))\n" . " goto cleanup;\n" . "\n" . - " if (!(snapshot =3D get_nonnull_domain_snapsh= ot(dom, args->${1})))\n" . + " if (!($1 =3D get_nonnull_domain_${1}(dom, ar= gs->$2)))\n" . " goto cleanup;\n"); - push(@args_list, "snapshot"); + push(@args_list, "$1"); push(@free_list, - " virObjectUnref(snapshot);\n" . + " virObjectUnref($1);\n" . " virObjectUnref(dom);"); } elsif ($args_member =3D~ m/^(?:(?:admin|remote)_string|r= emote_uuid) (\S+)<\S+>;/) { push(@args_list, $conn) if !@args_list; @@ -722,7 +724,7 @@ elsif ($mode eq "server") { if (!$modern_ret_as_list) { push(@ret_list, "ret->$3 =3D tmp.$3;"); } - } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|nwfilter_binding|node_device|interface|network|storage_vol|= storage_pool|domain_snapshot|domain|server|client) (\S+)<(\S+)>;/) { + } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|nwfilter_binding|node_device|interface|network|storage_vol|= storage_pool|domain_checkpoint|domain_snapshot|domain|server|client) (\S+)<= (\S+)>;/) { $modern_ret_struct_name =3D $1; $single_ret_list_error_msg_type =3D $1; $single_ret_list_name =3D $2; @@ -780,7 +782,7 @@ elsif ($mode eq "server") { $single_ret_var =3D $1; $single_ret_by_ref =3D 0; $single_ret_check =3D " =3D=3D NULL"; - } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|storage_pool|storage_vol|interface|node_device|secret|nwfilter|nwfilter_b= inding|domain_snapshot) (\S+);/) { + } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|storage_pool|storage_vol|interface|node_device|secret|nwfilter|nwfilter_b= inding|domain_checkpoint|domain_snapshot) (\S+);/) { my $type_name =3D name_to_TypeName($1); if ($call->{ProcName} eq "DomainCreateWithFlags") { @@ -1328,13 +1330,13 @@ elsif ($mode eq "client") { $priv_src =3D "dev->conn"; push(@args_list, "virNodeDevicePtr dev"); push(@setters_list, "args.name =3D dev->name;"); - } elsif ($args_member =3D~ m/^remote_nonnull_(domain|netwo= rk|storage_pool|storage_vol|interface|secret|nwfilter|nwfilter_binding|doma= in_snapshot) (\S+);/) { + } elsif ($args_member =3D~ m/^remote_nonnull_(domain|netwo= rk|storage_pool|storage_vol|interface|secret|nwfilter|nwfilter_binding|doma= in_checkpoint|domain_snapshot) (\S+);/) { my $name =3D $1; my $arg_name =3D $2; my $type_name =3D name_to_TypeName($name); if ($is_first_arg) { - if ($name eq "domain_snapshot") { + if ($name =3D~ m/^domain_.*/) { $priv_src =3D "$arg_name->domain->conn"; } else { $priv_src =3D "$arg_name->conn"; @@ -1521,7 +1523,7 @@ elsif ($mode eq "client") { } push(@ret_list, "memcpy(result->$3, ret.$3, sizeof= (result->$3));"); - } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|nwfilter_binding|node_device|interface|network|storage_vol|= storage_pool|domain_snapshot|domain|server|client) (\S+)<(\S+)>;/) { + } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|nwfilter_binding|node_device|interface|network|storage_vol|= storage_pool|domain_checkpoint|domain_snapshot|domain|server|client) (\S+)<= (\S+)>;/) { my $proc_name =3D name_to_TypeName($1); if ($structprefix eq "admin") { @@ -1574,7 +1576,7 @@ elsif ($mode eq "client") { push(@ret_list, "VIR_FREE(ret.$1);"); $single_ret_var =3D "char *rv =3D NULL"; $single_ret_type =3D "char *"; - } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|storage_pool|storage_vol|node_device|interface|secret|nwfilter|nwfilter_b= inding|domain_snapshot) (\S+);/) { + } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|storage_pool|storage_vol|node_device|interface|secret|nwfilter|nwfilter_b= inding|domain_checkpoint|domain_snapshot) (\S+);/) { my $name =3D $1; my $arg_name =3D $2; my $type_name =3D name_to_TypeName($name); @@ -1588,7 +1590,7 @@ elsif ($mode eq "client") { $single_ret_var =3D "int rv =3D -1"; $single_ret_type =3D "int"; } else { - if ($name eq "domain_snapshot") { + if ($name =3D~ m/^domain_.*/) { my $dom =3D "$priv_src"; $dom =3D~ s/->conn//; push(@ret_list, "rv =3D get_nonnull_$name($dom= , ret.$arg_name);"); @@ -1932,7 +1934,7 @@ elsif ($mode eq "client") { print " }\n"; print "\n"; } elsif ($modern_ret_as_list) { - if ($modern_ret_struct_name =3D~ m/domain_snapshot|client/) { + if ($modern_ret_struct_name =3D~ m/domain_checkpoint|domain_sn= apshot|client/) { $priv_src =3D~ s/->conn//; } print " if (result) {\n"; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937725291620.7979905720849; Wed, 6 Mar 2019 21:48:45 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 91FC266997; Thu, 7 Mar 2019 05:48:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6A1D119C67; Thu, 7 Mar 2019 05:48:43 +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 1C6D4181A264; Thu, 7 Mar 2019 05:48:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275mSVC004024 for ; Thu, 7 Mar 2019 00:48:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id CCE3F5D78D; Thu, 7 Mar 2019 05:48:28 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 942105D783; Thu, 7 Mar 2019 05:48:27 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:42 -0600 Message-Id: <20190307054752.19522-11-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 10/20] wip: backup: Parse and output checkpoint XML 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 07 Mar 2019 05:48:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Work in progress - the checkpoint code is not quite passing tests (part of that is figuring out the minimal XML that is still valid as a element, or just use --no-domain flag). Signed-off-by: Eric Blake --- src/conf/checkpoint_conf.h | 171 ++++ src/conf/domain_conf.h | 12 + src/conf/virdomainobjlist.h | 9 +- po/POTFILES | 1 + src/conf/Makefile.inc.am | 2 + src/conf/checkpoint_conf.c | 1240 +++++++++++++++++++++++++++ src/conf/domain_conf.c | 28 +- src/conf/virdomainobjlist.c | 12 +- src/libvirt_private.syms | 24 + tests/Makefile.am | 9 +- tests/domaincheckpointxml2xmltest.c | 233 +++++ 11 files changed, 1734 insertions(+), 7 deletions(-) create mode 100644 src/conf/checkpoint_conf.h create mode 100644 src/conf/checkpoint_conf.c create mode 100644 tests/domaincheckpointxml2xmltest.c diff --git a/src/conf/checkpoint_conf.h b/src/conf/checkpoint_conf.h new file mode 100644 index 0000000000..45ed8b0d29 --- /dev/null +++ b/src/conf/checkpoint_conf.h @@ -0,0 +1,171 @@ +/* + * checkpoint_conf.h: domain checkpoint XML processing + * + * Copyright (C) 2006-2019 Red Hat, Inc. + * Copyright (C) 2006-2008 Daniel P. Berrange + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#ifndef LIBVIRT_CHECKPOINT_CONF_H +# define LIBVIRT_CHECKPOINT_CONF_H + +# include "internal.h" +# include "domain_conf.h" + +/* Items related to checkpoint state */ + +typedef enum { + VIR_DOMAIN_CHECKPOINT_TYPE_DEFAULT =3D 0, + VIR_DOMAIN_CHECKPOINT_TYPE_NONE, + VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP, + + VIR_DOMAIN_CHECKPOINT_TYPE_LAST +} virDomainCheckpointType; + +/* Stores disk-checkpoint information */ +typedef struct _virDomainCheckpointDiskDef virDomainCheckpointDiskDef; +typedef virDomainCheckpointDiskDef *virDomainCheckpointDiskDefPtr; +struct _virDomainCheckpointDiskDef { + char *name; /* name matching the dom->disks that matches na= me */ + int type; /* virDomainCheckpointType */ + char *bitmap; /* bitmap name, if type is bitmap */ + unsigned long long size; /* current checkpoint size in bytes */ +}; + +/* Stores the complete checkpoint metadata */ +typedef struct _virDomainCheckpointDef virDomainCheckpointDef; +typedef virDomainCheckpointDef *virDomainCheckpointDefPtr; +struct _virDomainCheckpointDef { + /* Public XML. */ + char *name; + char *description; + char *parent; + long long creationTime; /* in seconds */ + + size_t ndisks; /* should not exceed dom->ndisks */ + virDomainCheckpointDiskDef *disks; + + virDomainDefPtr dom; + + /* Internal use. */ + bool current; /* At most one checkpoint in the list should have this s= et */ +}; + +struct _virDomainCheckpointObj { + virDomainCheckpointDefPtr def; /* non-NULL except for metaroot */ + + virDomainCheckpointObjPtr parent; /* non-NULL except for metaroot, bef= ore + virDomainCheckpointUpdateRelation= s, or + after virDomainCheckpointDropPare= nt */ + virDomainCheckpointObjPtr sibling; /* NULL if last child of parent */ + size_t nchildren; + virDomainCheckpointObjPtr first_child; /* NULL if no children */ +}; + +virDomainCheckpointObjListPtr virDomainCheckpointObjListNew(void); +void virDomainCheckpointObjListFree(virDomainCheckpointObjListPtr checkpoi= nts); + +typedef enum { + VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE =3D 1 << 0, + VIR_DOMAIN_CHECKPOINT_PARSE_DISKS =3D 1 << 1, + VIR_DOMAIN_CHECKPOINT_PARSE_INTERNAL =3D 1 << 2, +} virDomainCheckpointParseFlags; + +typedef enum { + VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE =3D 1 << 0, + VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN =3D 1 << 1, + VIR_DOMAIN_CHECKPOINT_FORMAT_SIZE =3D 1 << 2, + VIR_DOMAIN_CHECKPOINT_FORMAT_INTERNAL =3D 1 << 3, +} virDomainCheckpointFormatFlags; + +unsigned int virDomainCheckpointFormatConvertXMLFlags(unsigned int flags); + +virDomainCheckpointDefPtr virDomainCheckpointDefParseString(const char *xm= lStr, + virCapsPtr cap= s, + virDomainXMLOp= tionPtr xmlopt, + unsigned int f= lags); +virDomainCheckpointDefPtr virDomainCheckpointDefParseNode(xmlDocPtr xml, + xmlNodePtr root, + virCapsPtr caps, + virDomainXMLOpti= onPtr xmlopt, + unsigned int fla= gs); +int virDomainCheckpointObjListParse(const char *xmlStr, + const unsigned char *domain_uuid, + virDomainCheckpointObjListPtr checkpoi= nts, + virDomainCheckpointObjPtr *current_che= ck, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags); +void virDomainCheckpointDefFree(virDomainCheckpointDefPtr def); +char *virDomainCheckpointDefFormat(virDomainCheckpointDefPtr def, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags); +int virDomainCheckpointObjListFormat(virBufferPtr buf, + virDomainCheckpointObjListPtr checkpo= ints, + virDomainCheckpointObjPtr current_che= ck, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags); +int virDomainCheckpointAlignDisks(virDomainCheckpointDefPtr checkpoint); +virDomainCheckpointObjPtr virDomainCheckpointAssignDef(virDomainCheckpoint= ObjListPtr checkpoints, + virDomainCheckpoint= DefPtr def); + +virDomainCheckpointObjPtr virDomainCheckpointFindByName(virDomainCheckpoin= tObjListPtr checkpoints, + const char *name); +void virDomainCheckpointObjListRemove(virDomainCheckpointObjListPtr checkp= oints, + virDomainCheckpointObjPtr checkpoint= ); +int virDomainCheckpointForEach(virDomainCheckpointObjListPtr checkpoints, + virHashIterator iter, + void *data); +int virDomainCheckpointForEachChild(virDomainCheckpointObjPtr checkpoint, + virHashIterator iter, + void *data); +int virDomainCheckpointForEachDescendant(virDomainCheckpointObjPtr checkpo= int, + virHashIterator iter, + void *data); +int virDomainCheckpointUpdateRelations(virDomainCheckpointObjListPtr check= points); +void virDomainCheckpointDropParent(virDomainCheckpointObjPtr checkpoint); + +# define VIR_DOMAIN_CHECKPOINT_FILTERS_METADATA \ + (VIR_DOMAIN_CHECKPOINT_LIST_METADATA | \ + VIR_DOMAIN_CHECKPOINT_LIST_NO_METADATA) + +# define VIR_DOMAIN_CHECKPOINT_FILTERS_LEAVES \ + (VIR_DOMAIN_CHECKPOINT_LIST_LEAVES | \ + VIR_DOMAIN_CHECKPOINT_LIST_NO_LEAVES) + +# define VIR_DOMAIN_CHECKPOINT_FILTERS_ALL \ + (VIR_DOMAIN_CHECKPOINT_FILTERS_METADATA | \ + VIR_DOMAIN_CHECKPOINT_FILTERS_LEAVES) + +int virDomainListAllCheckpoints(virDomainCheckpointObjListPtr checkpoints, + virDomainCheckpointObjPtr from, + virDomainPtr dom, + virDomainCheckpointPtr **objs, + unsigned int flags); + +int virDomainCheckpointRedefinePrep(virDomainPtr domain, + virDomainObjPtr vm, + virDomainCheckpointDefPtr *def, + virDomainCheckpointObjPtr *checkpoint, + virDomainXMLOptionPtr xmlopt, + bool *update_current); + +VIR_ENUM_DECL(virDomainCheckpoint); + +#endif /* LIBVIRT_CHECKPOINT_CONF_H */ diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index da89e94083..c3d5f53bdd 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -119,6 +119,12 @@ typedef virDomainMemballoonDef *virDomainMemballoonDef= Ptr; typedef struct _virDomainNVRAMDef virDomainNVRAMDef; typedef virDomainNVRAMDef *virDomainNVRAMDefPtr; +typedef struct _virDomainCheckpointObj virDomainCheckpointObj; +typedef virDomainCheckpointObj *virDomainCheckpointObjPtr; + +typedef struct _virDomainCheckpointObjList virDomainCheckpointObjList; +typedef virDomainCheckpointObjList *virDomainCheckpointObjListPtr; + typedef struct _virDomainSnapshotObj virDomainSnapshotObj; typedef virDomainSnapshotObj *virDomainSnapshotObjPtr; @@ -2705,6 +2711,9 @@ struct _virDomainObj { bool hasManagedSave; + virDomainCheckpointObjListPtr checkpoints; + virDomainCheckpointObjPtr current_checkpoint; + void *privateData; void (*privateDataFreeFunc)(void *); @@ -3121,6 +3130,7 @@ typedef enum { VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT =3D 1 << 7, VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST =3D 1 << 8, VIR_DOMAIN_DEF_FORMAT_SNAPSHOTS =3D 1 << 9, + VIR_DOMAIN_DEF_FORMAT_CHECKPOINTS =3D 1 << 10, } virDomainDefFormatFlags; /* Use these flags to skip specific domain ABI consistency checks done @@ -3201,6 +3211,8 @@ typedef struct _virDomainDefFormatData { virCapsPtr caps; virDomainSnapshotObjListPtr snapshots; virDomainSnapshotObjPtr current_snapshot; + virDomainCheckpointObjListPtr checkpoints; + virDomainCheckpointObjPtr current_check; } virDomainDefFormatData; typedef struct _virDomainDefFormatData *virDomainDefFormatDataPtr; diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h index c1ffee76ad..32f3dcfcc2 100644 --- a/src/conf/virdomainobjlist.h +++ b/src/conf/virdomainobjlist.h @@ -1,7 +1,7 @@ /* * virdomainobjlist.h: domain objects list utilities * - * Copyright (C) 2006-2015 Red Hat, Inc. + * Copyright (C) 2006-2019 Red Hat, Inc. * Copyright (C) 2006-2008 Daniel P. Berrange * Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany. * @@ -121,13 +121,18 @@ int virDomainObjListForEach(virDomainObjListPtr doms, (VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT | \ VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT) +# define VIR_CONNECT_LIST_DOMAINS_FILTERS_CHECKPOINT \ + (VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT | \ + VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT) + # define VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL \ (VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE | \ VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT | \ VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE | \ VIR_CONNECT_LIST_DOMAINS_FILTERS_MANAGEDSAVE | \ VIR_CONNECT_LIST_DOMAINS_FILTERS_AUTOSTART | \ - VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT) + VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT | \ + VIR_CONNECT_LIST_DOMAINS_FILTERS_CHECKPOINT) int virDomainObjListCollect(virDomainObjListPtr doms, virConnectPtr conn, diff --git a/po/POTFILES b/po/POTFILES index 88af551664..57c55fb35f 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -15,6 +15,7 @@ src/bhyve/bhyve_monitor.c src/bhyve/bhyve_parse_command.c src/bhyve/bhyve_process.c src/conf/capabilities.c +src/conf/checkpoint_conf.c src/conf/cpu_conf.c src/conf/device_conf.c src/conf/domain_addr.c diff --git a/src/conf/Makefile.inc.am b/src/conf/Makefile.inc.am index fb2ec0e785..a058045a43 100644 --- a/src/conf/Makefile.inc.am +++ b/src/conf/Makefile.inc.am @@ -10,6 +10,8 @@ NETDEV_CONF_SOURCES =3D \ DOMAIN_CONF_SOURCES =3D \ conf/capabilities.c \ conf/capabilities.h \ + conf/checkpoint_conf.c \ + conf/checkpoint_conf.h \ conf/domain_addr.c \ conf/domain_addr.h \ conf/domain_capabilities.c \ diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c new file mode 100644 index 0000000000..e5e4c5e306 --- /dev/null +++ b/src/conf/checkpoint_conf.c @@ -0,0 +1,1240 @@ +/* + * checkpoint_conf.c: domain checkpoint XML processing + * + * Copyright (C) 2006-2019 Red Hat, Inc. + * Copyright (C) 2006-2008 Daniel P. Berrange + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include +#include +#include +#include + +#include "internal.h" +#include "virbitmap.h" +#include "virbuffer.h" +#include "count-one-bits.h" +#include "datatypes.h" +#include "domain_conf.h" +#include "virlog.h" +#include "viralloc.h" +#include "netdev_bandwidth_conf.h" +#include "netdev_vport_profile_conf.h" +#include "nwfilter_conf.h" +#include "secret_conf.h" +#include "checkpoint_conf.h" +#include "virstoragefile.h" +#include "viruuid.h" +#include "virfile.h" +#include "virerror.h" +#include "virxml.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_DOMAIN_CHECKPOINT + +VIR_LOG_INIT("conf.checkpoint_conf"); + +VIR_ENUM_IMPL(virDomainCheckpoint, VIR_DOMAIN_CHECKPOINT_TYPE_LAST, + "default", "no", "bitmap"); + +struct _virDomainCheckpointObjList { + /* name string -> virDomainCheckpointObj mapping + * for O(1), lockless lookup-by-name */ + virHashTable *objs; + + virDomainCheckpointObj metaroot; /* Special parent of all root checkpo= ints */ +}; + +/* Checkpoint Def functions */ +static void +virDomainCheckpointDiskDefClear(virDomainCheckpointDiskDefPtr disk) +{ + VIR_FREE(disk->name); + VIR_FREE(disk->bitmap); +} + +void virDomainCheckpointDefFree(virDomainCheckpointDefPtr def) +{ + size_t i; + + if (!def) + return; + + VIR_FREE(def->name); + VIR_FREE(def->description); + VIR_FREE(def->parent); + for (i =3D 0; i < def->ndisks; i++) + virDomainCheckpointDiskDefClear(&def->disks[i]); + VIR_FREE(def->disks); + virDomainDefFree(def->dom); + VIR_FREE(def); +} + +static int +virDomainCheckpointDiskDefParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virDomainCheckpointDiskDefPtr def) +{ + int ret =3D -1; + char *checkpoint =3D NULL; + char *bitmap =3D NULL; + xmlNodePtr saved =3D ctxt->node; + + ctxt->node =3D node; + + def->name =3D virXMLPropString(node, "name"); + if (!def->name) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing name from disk checkpoint element")); + goto cleanup; + } + + checkpoint =3D virXMLPropString(node, "checkpoint"); + if (checkpoint) { + def->type =3D virDomainCheckpointTypeFromString(checkpoint); + if (def->type <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown disk checkpoint setting '%s'"), + checkpoint); + goto cleanup; + } + } else { + def->type =3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP; + } + + bitmap =3D virXMLPropString(node, "bitmap"); + if (bitmap) { + if (def->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk checkpoint bitmap '%s' requires " + "type=3D'bitmap'"), + bitmap); + goto cleanup; + } + VIR_STEAL_PTR(def->bitmap, bitmap); + } + + ret =3D 0; + cleanup: + ctxt->node =3D saved; + + VIR_FREE(checkpoint); + VIR_FREE(bitmap); + if (ret < 0) + virDomainCheckpointDiskDefClear(def); + return ret; +} + +/* flags is bitwise-or of virDomainCheckpointParseFlags. + * If flags does not include VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE, then + * caps are ignored. + */ +static virDomainCheckpointDefPtr +virDomainCheckpointDefParse(xmlXPathContextPtr ctxt, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + virDomainCheckpointDefPtr def =3D NULL; + virDomainCheckpointDefPtr ret =3D NULL; + xmlNodePtr *nodes =3D NULL; + size_t i; + int n; + char *creation =3D NULL; + struct timeval tv; + int active; + char *tmp; + + if (VIR_ALLOC(def) < 0) + goto cleanup; + + gettimeofday(&tv, NULL); + + def->name =3D virXPathString("string(./name)", ctxt); + if (def->name =3D=3D NULL) { + if (flags & VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("a redefined checkpoint must have a name")); + goto cleanup; + } + if (virAsprintf(&def->name, "%lld", (long long)tv.tv_sec) < 0) + goto cleanup; + } + + def->description =3D virXPathString("string(./description)", ctxt); + + if (flags & VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE) { + if (virXPathLongLong("string(./creationTime)", ctxt, + &def->creationTime) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing creationTime from existing checkpoin= t")); + goto cleanup; + } + + def->parent =3D virXPathString("string(./parent/name)", ctxt); + + if ((tmp =3D virXPathString("string(./domain/@type)", ctxt))) { + int domainflags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE | + VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE; + xmlNodePtr domainNode =3D virXPathNode("./domain", ctxt); + + VIR_FREE(tmp); + if (!domainNode) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing domain in checkpoint")); + goto cleanup; + } + def->dom =3D virDomainDefParseNode(ctxt->node->doc, domainNode, + caps, xmlopt, NULL, domainfla= gs); + if (!def->dom) + goto cleanup; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing domain in checkpoint redefine")); + goto cleanup; + } + } else { + def->creationTime =3D tv.tv_sec; + } + + if ((n =3D virXPathNodeSet("./disks/*", ctxt, &nodes)) < 0) + goto cleanup; + if (flags & VIR_DOMAIN_CHECKPOINT_PARSE_DISKS) { + if (n && VIR_ALLOC_N(def->disks, n) < 0) + goto cleanup; + def->ndisks =3D n; + for (i =3D 0; i < def->ndisks; i++) { + if (virDomainCheckpointDiskDefParseXML(nodes[i], ctxt, + &def->disks[i]) < 0) + goto cleanup; + } + VIR_FREE(nodes); + } else if (n) { + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", + _("unable to handle disk requests in checkpoint")); + goto cleanup; + } + + if (flags & VIR_DOMAIN_CHECKPOINT_PARSE_INTERNAL) { + if (virXPathInt("string(./active)", ctxt, &active) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not find 'active' element")); + goto cleanup; + } + def->current =3D active !=3D 0; + } + + VIR_STEAL_PTR(ret, def); + + cleanup: + VIR_FREE(creation); + VIR_FREE(nodes); + virDomainCheckpointDefFree(def); + + return ret; +} + +virDomainCheckpointDefPtr +virDomainCheckpointDefParseNode(xmlDocPtr xml, + xmlNodePtr root, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + xmlXPathContextPtr ctxt =3D NULL; + virDomainCheckpointDefPtr def =3D NULL; + + if (!virXMLNodeNameEqual(root, "domaincheckpoint")) { + virReportError(VIR_ERR_XML_ERROR, "%s", _("domaincheckpoint")); + goto cleanup; + } + + ctxt =3D xmlXPathNewContext(xml); + if (ctxt =3D=3D NULL) { + virReportOOMError(); + goto cleanup; + } + + ctxt->node =3D root; + def =3D virDomainCheckpointDefParse(ctxt, caps, xmlopt, flags); + cleanup: + xmlXPathFreeContext(ctxt); + return def; +} + +virDomainCheckpointDefPtr +virDomainCheckpointDefParseString(const char *xmlStr, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + virDomainCheckpointDefPtr ret =3D NULL; + xmlDocPtr xml; + int keepBlanksDefault =3D xmlKeepBlanksDefault(0); + + if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_checkpoint)")))) { + xmlKeepBlanksDefault(keepBlanksDefault); + ret =3D virDomainCheckpointDefParseNode(xml, xmlDocGetRootElement(= xml), + caps, xmlopt, flags); + xmlFreeDoc(xml); + } + xmlKeepBlanksDefault(keepBlanksDefault); + + return ret; +} + +int +virDomainCheckpointObjListParse(const char *xmlStr, + const unsigned char *domain_uuid, + virDomainCheckpointObjListPtr checkpoints, + virDomainCheckpointObjPtr *current_check, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + int ret =3D -1; + xmlDocPtr xml; + xmlNodePtr root; + xmlXPathContextPtr ctxt =3D NULL; + char *current =3D NULL; + int n; + size_t i; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; + int keepBlanksDefault =3D xmlKeepBlanksDefault(0); + + if (!(flags & VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE) || + (flags & VIR_DOMAIN_CHECKPOINT_PARSE_INTERNAL)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("incorrect flags for bulk parse")); + return -1; + } + if (checkpoints->metaroot.nchildren || *current_check) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("bulk define of checkoints only possible with " + "no existing checkpoint")); + return -1; + } + + if (!(xml =3D virXMLParse(NULL, xmlStr, _("(domain_checkpoint)")))) + goto cleanup; + + root =3D xmlDocGetRootElement(xml); + if (!virXMLNodeNameEqual(root, "checkpoints")) { + virReportError(VIR_ERR_XML_ERROR, + _("unexpected root element <%s>, " + "expecting "), root->name); + goto cleanup; + } + ctxt =3D xmlXPathNewContext(xml); + if (ctxt =3D=3D NULL) { + virReportOOMError(); + goto cleanup; + } + ctxt->node =3D root; + current =3D virXMLPropString(root, "current"); + + if ((n =3D virXPathNodeSet("./domaincheckpoint", ctxt, &nodes)) < 0) + goto cleanup; + if (!n) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("expected at least one child")= ); + goto cleanup; + } + + for (i =3D 0; i < n; i++) { + virDomainCheckpointDefPtr def; + virDomainCheckpointObjPtr chk; + + def =3D virDomainCheckpointDefParseNode(xml, nodes[i], caps, xmlop= t, + flags); + if (!def) + goto cleanup; + if (!(chk =3D virDomainCheckpointAssignDef(checkpoints, def))) { + virDomainCheckpointDefFree(def); + goto cleanup; + } + /* Sanity checking, similar to virDomainCheckpointRedefinePrep */ + if (def->dom) { + if (memcmp(def->dom->uuid, domain_uuid, VIR_UUID_BUFLEN)) { + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + virUUIDFormat(domain_uuid, uuidstr); + virReportError(VIR_ERR_INVALID_ARG, + _("definition for checkpoint %s must use " + "uuid %s"), def->name, uuidstr); + goto cleanup; + } + if (virDomainCheckpointAlignDisks(def) < 0) + goto cleanup; + } + } + + if (virDomainCheckpointUpdateRelations(checkpoints) < 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _(" contains inconsistent parent-child= " + "relationships")); + goto cleanup; + } + + if (current) { + if (!(*current_check =3D virDomainCheckpointFindByName(checkpoints, + current))) { + virReportError(VIR_ERR_NO_DOMAIN_CHECKPOINT, + _("no checkpoint matching current=3D'%s'"), cur= rent); + goto cleanup; + } + (*current_check)->def->current =3D true; + } + + ret =3D 0; + cleanup: + if (ret < 0) { + /* There were no checkpoints before this call; so on error, just + * blindly delete anything created before the failure. */ + virHashRemoveAll(checkpoints->objs); + checkpoints->metaroot.nchildren =3D 0; + checkpoints->metaroot.first_child =3D NULL; + } + VIR_FREE(current); + xmlXPathFreeContext(ctxt); + xmlFreeDoc(xml); + xmlKeepBlanksDefault(keepBlanksDefault); + return ret; +} + + +/** + * virDomainCheckpointDefAssignBitmapNames: + * @def: checkpoint def object + * + * Generate default bitmap names for checkpoint targets. Returns 0 on + * success, -1 on error. + */ +static int +virDomainCheckpointDefAssignBitmapNames(virDomainCheckpointDefPtr def) +{ + size_t i; + + for (i =3D 0; i < def->ndisks; i++) { + virDomainCheckpointDiskDefPtr disk =3D &def->disks[i]; + + if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP || + disk->bitmap) + continue; + + if (VIR_STRDUP(disk->bitmap, def->name) < 0) + return -1; + } + + return 0; +} + + +static int +virDomainCheckpointCompareDiskIndex(const void *a, const void *b) +{ + const virDomainCheckpointDiskDef *diska =3D a; + const virDomainCheckpointDiskDef *diskb =3D b; + + /* Integer overflow shouldn't be a problem here. */ + return diska->idx - diskb->idx; +} + +/* Align def->disks to def->domain. Sort the list of def->disks, + * filling in any missing disks with appropriate default. Convert + * paths to disk targets for uniformity. Issue an error and return -1 + * if any def->disks[n]->name appears more than once or does not map + * to dom->disks. */ +int +virDomainCheckpointAlignDisks(virDomainCheckpointDefPtr def) +{ + int ret =3D -1; + virBitmapPtr map =3D NULL; + size_t i; + int ndisks; + int checkpoint_default =3D VIR_DOMAIN_CHECKPOINT_TYPE_NONE; + + if (!def->dom) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing domain in checkpoint")); + goto cleanup; + } + + if (def->ndisks > def->dom->ndisks) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("too many disk checkpoint requests for domain")); + goto cleanup; + } + + /* Unlikely to have a guest without disks but technically possible. */ + if (!def->dom->ndisks) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("domain must have at least one disk to perform " + "checkpoints")); + goto cleanup; + } + + /* If omitted, do bitmap on all disks; otherwise, do nothing + * for omitted disks */ + if (!def->ndisks) + checkpoint_default =3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP; + + if (!(map =3D virBitmapNew(def->dom->ndisks))) + goto cleanup; + + /* Double check requested disks. */ + for (i =3D 0; i < def->ndisks; i++) { + virDomainCheckpointDiskDefPtr disk =3D &def->disks[i]; + int idx =3D virDomainDiskIndexByName(def->dom, disk->name, false); + + if (idx < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("no disk named '%s'"), disk->name); + goto cleanup; + } + + if (virBitmapIsBitSet(map, idx)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk '%s' specified twice"), + disk->name); + goto cleanup; + } + ignore_value(virBitmapSetBit(map, idx)); + disk->idx =3D idx; + + if (STRNEQ(disk->name, def->dom->disks[idx]->dst)) { + VIR_FREE(disk->name); + if (VIR_STRDUP(disk->name, def->dom->disks[idx]->dst) < 0) + goto cleanup; + } + } + + /* Provide defaults for all remaining disks. */ + ndisks =3D def->ndisks; + if (VIR_EXPAND_N(def->disks, def->ndisks, + def->dom->ndisks - def->ndisks) < 0) + goto cleanup; + + for (i =3D 0; i < def->dom->ndisks; i++) { + virDomainCheckpointDiskDefPtr disk; + + if (virBitmapIsBitSet(map, i)) + continue; + disk =3D &def->disks[ndisks++]; + if (VIR_STRDUP(disk->name, def->dom->disks[i]->dst) < 0) + goto cleanup; + disk->idx =3D i; + + /* Don't checkpoint empty drives */ + if (virStorageSourceIsEmpty(def->dom->disks[i]->src)) + disk->type =3D VIR_DOMAIN_CHECKPOINT_TYPE_NONE; + else + disk->type =3D checkpoint_default; + } + + qsort(&def->disks[0], def->ndisks, sizeof(def->disks[0]), + virDomainCheckpointCompareDiskIndex); + + /* Generate default bitmap names for checkpoint */ + if (virDomainCheckpointDefAssignBitmapNames(def) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virBitmapFree(map); + return ret; +} + + +/* Converts public VIR_DOMAIN_CHECKPOINT_XML_* into + * VIR_DOMAIN_CHECKPOINT_FORMAT_* flags, and silently ignores any other + * flags. */ +unsigned int virDomainCheckpointFormatConvertXMLFlags(unsigned int flags) +{ + unsigned int formatFlags =3D 0; + + if (flags & VIR_DOMAIN_CHECKPOINT_XML_SECURE) + formatFlags |=3D VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE; + if (flags & VIR_DOMAIN_CHECKPOINT_XML_NO_DOMAIN) + formatFlags |=3D VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN; + if (flags & VIR_DOMAIN_CHECKPOINT_XML_SIZE) + formatFlags |=3D VIR_DOMAIN_CHECKPOINT_FORMAT_SIZE; + + return formatFlags; +} + + +static int +virDomainCheckpointDiskDefFormat(virBufferPtr buf, + virDomainCheckpointDiskDefPtr disk, + unsigned int flags) +{ + if (!disk->name) + return 0; + + virBufferEscapeString(buf, "name); + if (disk->type) + virBufferAsprintf(buf, " checkpoint=3D'%s'", + virDomainCheckpointTypeToString(disk->type)); + if (disk->bitmap) { + virBufferEscapeString(buf, " bitmap=3D'%s'", disk->bitmap); + if (flags & VIR_DOMAIN_CHECKPOINT_XML_SIZE) + virBufferAsprintf(buf, " size=3D'%llu'", disk->size); + } + virBufferAddLit(buf, "/>\n"); + return 0; +} + + +static int +virDomainCheckpointDefFormatInternal(virBufferPtr buf, + virDomainCheckpointDefPtr def, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + size_t i; + unsigned int domainflags =3D VIR_DOMAIN_DEF_FORMAT_INACTIVE; + virDomainDefFormatData data =3D { + .caps =3D caps, + }; + + if (flags & VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE) + domainflags |=3D VIR_DOMAIN_DEF_FORMAT_SECURE; + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + + virBufferEscapeString(buf, "%s\n", def->name); + if (def->description) + virBufferEscapeString(buf, "%s\n", + def->description); + + if (def->parent) { + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + virBufferEscapeString(buf, "%s\n", def->parent); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } + + virBufferAsprintf(buf, "%lld\n", + def->creationTime); + + if (def->ndisks) { + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + for (i =3D 0; i < def->ndisks; i++) { + if (virDomainCheckpointDiskDefFormat(buf, &def->disks[i], + flags) < 0) + goto error; + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } + + if (!(flags & VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN) && + virDomainDefFormatInternal(buf, def->dom, &data, domainflags, + xmlopt) < 0) + goto error; + + if (flags & VIR_DOMAIN_CHECKPOINT_FORMAT_INTERNAL) + virBufferAsprintf(buf, "%d\n", def->current); + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + if (virBufferCheckError(buf) < 0) + goto error; + + return 0; + + error: + virBufferFreeAndReset(buf); + return -1; +} + +char * +virDomainCheckpointDefFormat(virDomainCheckpointDefPtr def, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE | + VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN | + VIR_DOMAIN_CHECKPOINT_FORMAT_SIZE | + VIR_DOMAIN_CHECKPOINT_FORMAT_INTERNAL, NULL); + if (virDomainCheckpointDefFormatInternal(&buf, def, caps, xmlopt, + flags) < 0) + return NULL; + + return virBufferContentAndReset(&buf); +} + +struct virDomainCheckpointFormatData { + virBufferPtr buf; + virCapsPtr caps; + virDomainXMLOptionPtr xmlopt; + unsigned int flags; +}; + +static int +virDomainCheckpointFormatOne(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) +{ + virDomainCheckpointObjPtr chk =3D payload; + struct virDomainCheckpointFormatData *data =3D opaque; + + return virDomainCheckpointDefFormatInternal(data->buf, chk->def, data-= >caps, + data->xmlopt, data->flags); +} + + +int +virDomainCheckpointObjListFormat(virBufferPtr buf, + virDomainCheckpointObjListPtr checkpoints, + virDomainCheckpointObjPtr current_check, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + struct virDomainCheckpointFormatData data =3D { + .buf =3D buf, + .caps =3D caps, + .xmlopt =3D xmlopt, + .flags =3D flags, + }; + + virBufferAddLit(buf, "def->name); + virBufferAddLit(buf, ">\n"); + virBufferAdjustIndent(buf, 2); + if (virDomainCheckpointForEach(checkpoints, virDomainCheckpointFormatO= ne, + &data) < 0) { + virBufferFreeAndReset(buf); + return -1; + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + return 0; +} + + +/* Checkpoint Obj functions */ +static virDomainCheckpointObjPtr virDomainCheckpointObjNew(void) +{ + virDomainCheckpointObjPtr checkpoint; + + if (VIR_ALLOC(checkpoint) < 0) + return NULL; + + VIR_DEBUG("obj=3D%p", checkpoint); + + return checkpoint; +} + +static void virDomainCheckpointObjFree(virDomainCheckpointObjPtr checkpoin= t) +{ + if (!checkpoint) + return; + + VIR_DEBUG("obj=3D%p", checkpoint); + + virDomainCheckpointDefFree(checkpoint->def); + VIR_FREE(checkpoint); +} + +virDomainCheckpointObjPtr virDomainCheckpointAssignDef(virDomainCheckpoint= ObjListPtr checkpoints, + virDomainCheckpoint= DefPtr def) +{ + virDomainCheckpointObjPtr chk; + + if (virHashLookup(checkpoints->objs, def->name) !=3D NULL) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("domain checkpoint %s already exists"), + def->name); + return NULL; + } + + if (!(chk =3D virDomainCheckpointObjNew())) + return NULL; + chk->def =3D def; + + if (virHashAddEntry(checkpoints->objs, chk->def->name, chk) < 0) { + VIR_FREE(chk); + return NULL; + } + + return chk; +} + +/* Checkpoint Obj List functions */ +static void +virDomainCheckpointObjListDataFree(void *payload, + const void *name ATTRIBUTE_UNUSED) +{ + virDomainCheckpointObjPtr obj =3D payload; + + virDomainCheckpointObjFree(obj); +} + +virDomainCheckpointObjListPtr +virDomainCheckpointObjListNew(void) +{ + virDomainCheckpointObjListPtr checkpoints; + if (VIR_ALLOC(checkpoints) < 0) + return NULL; + checkpoints->objs =3D virHashCreate(50, virDomainCheckpointObjListData= Free); + if (!checkpoints->objs) { + VIR_FREE(checkpoints); + return NULL; + } + return checkpoints; +} + +void +virDomainCheckpointObjListFree(virDomainCheckpointObjListPtr checkpoints) +{ + if (!checkpoints) + return; + virHashFree(checkpoints->objs); + VIR_FREE(checkpoints); +} + +struct virDomainCheckpointNameData { + char **const names; + int maxnames; + unsigned int flags; + int count; + bool error; +}; + +static int +virDomainCheckpointObjListCopyNames(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) +{ + virDomainCheckpointObjPtr obj =3D payload; + struct virDomainCheckpointNameData *data =3D opaque; + + if (data->error) + return 0; + /* Caller already sanitized flags. Filtering on DESCENDANTS was + * done by choice of iteration in the caller. */ + if ((data->flags & VIR_DOMAIN_CHECKPOINT_LIST_LEAVES) && obj->nchildre= n) + return 0; + if ((data->flags & VIR_DOMAIN_CHECKPOINT_LIST_NO_LEAVES) && !obj->nchi= ldren) + return 0; + + if (data->names && data->count < data->maxnames && + VIR_STRDUP(data->names[data->count], obj->def->name) < 0) { + data->error =3D true; + return 0; + } + data->count++; + return 0; +} + +static int +virDomainCheckpointObjListGetNames(virDomainCheckpointObjListPtr checkpoin= ts, + virDomainCheckpointObjPtr from, + char **const names, int maxnames, + unsigned int flags) +{ + struct virDomainCheckpointNameData data =3D { names, maxnames, flags, = 0, + false }; + size_t i; + + if (!from) { + /* LIST_ROOTS and LIST_DESCENDANTS have the same bit value, + * but opposite semantics. Toggle here to get the correct + * traversal on the metaroot. */ + flags ^=3D VIR_DOMAIN_CHECKPOINT_LIST_ROOTS; + from =3D &checkpoints->metaroot; + } + + /* We handle LIST_ROOT/LIST_DESCENDANTS directly, mask that bit + * out to determine when we must use the filter callback. */ + data.flags &=3D ~VIR_DOMAIN_CHECKPOINT_LIST_DESCENDANTS; + + /* If this common code is being used, we assume that all checkpoints + * have metadata, and thus can handle METADATA up front as an + * all-or-none filter. XXX This might not always be true, if we + * add the ability to track qcow2 bitmaps without the + * use of metadata. */ + if ((data.flags & VIR_DOMAIN_CHECKPOINT_FILTERS_METADATA) =3D=3D + VIR_DOMAIN_CHECKPOINT_LIST_NO_METADATA) + return 0; + data.flags &=3D ~VIR_DOMAIN_CHECKPOINT_FILTERS_METADATA; + + /* For ease of coding the visitor, it is easier to zero each group + * where all of the bits are set. */ + if ((data.flags & VIR_DOMAIN_CHECKPOINT_FILTERS_LEAVES) =3D=3D + VIR_DOMAIN_CHECKPOINT_FILTERS_LEAVES) + data.flags &=3D ~VIR_DOMAIN_CHECKPOINT_FILTERS_LEAVES; + + if (flags & VIR_DOMAIN_CHECKPOINT_LIST_DESCENDANTS) { + if (from->def) + virDomainCheckpointForEachDescendant(from, + virDomainCheckpointObjLis= tCopyNames, + &data); + else if (names || data.flags) + virHashForEach(checkpoints->objs, + virDomainCheckpointObjListCopyNames, + &data); + else + data.count =3D virHashSize(checkpoints->objs); + } else if (names || data.flags) { + virDomainCheckpointForEachChild(from, + virDomainCheckpointObjListCopyName= s, + &data); + } else { + data.count =3D from->nchildren; + } + + if (data.error) { + for (i =3D 0; i < data.count; i++) + VIR_FREE(names[i]); + return -1; + } + + return data.count; +} + +static int +virDomainCheckpointObjListNum(virDomainCheckpointObjListPtr checkpoints, + virDomainCheckpointObjPtr from, + unsigned int flags) +{ + return virDomainCheckpointObjListGetNames(checkpoints, from, NULL, 0, + flags); +} + +virDomainCheckpointObjPtr +virDomainCheckpointFindByName(virDomainCheckpointObjListPtr checkpoints, + const char *name) +{ + return name ? virHashLookup(checkpoints->objs, name) : + &checkpoints->metaroot; +} + +void virDomainCheckpointObjListRemove(virDomainCheckpointObjListPtr checkp= oints, + virDomainCheckpointObjPtr checkpoint) +{ + virHashRemoveEntry(checkpoints->objs, checkpoint->def->name); +} + +int +virDomainCheckpointForEach(virDomainCheckpointObjListPtr checkpoints, + virHashIterator iter, + void *data) +{ + return virHashForEach(checkpoints->objs, iter, data); +} + +/* Run iter(data) on all direct children of checkpoint, while ignoring all + * other entries in checkpoints. Return the number of children + * visited. No particular ordering is guaranteed. */ +int +virDomainCheckpointForEachChild(virDomainCheckpointObjPtr checkpoint, + virHashIterator iter, + void *data) +{ + virDomainCheckpointObjPtr child =3D checkpoint->first_child; + + while (child) { + virDomainCheckpointObjPtr next =3D child->sibling; + (iter)(child, child->def->name, data); + child =3D next; + } + + return checkpoint->nchildren; +} + +struct checkpoint_act_on_descendant { + int number; + virHashIterator iter; + void *data; +}; + +static int +virDomainCheckpointActOnDescendant(void *payload, + const void *name, + void *data) +{ + virDomainCheckpointObjPtr obj =3D payload; + struct checkpoint_act_on_descendant *curr =3D data; + + curr->number +=3D 1 + virDomainCheckpointForEachDescendant(obj, + curr->iter, + curr->data); + (curr->iter)(payload, name, curr->data); + return 0; +} + +/* Run iter(data) on all descendants of checkpoint, while ignoring all + * other entries in checkpoints. Return the number of descendants + * visited. No particular ordering is guaranteed. */ +int +virDomainCheckpointForEachDescendant(virDomainCheckpointObjPtr checkpoint, + virHashIterator iter, + void *data) +{ + struct checkpoint_act_on_descendant act; + + act.number =3D 0; + act.iter =3D iter; + act.data =3D data; + virDomainCheckpointForEachChild(checkpoint, + virDomainCheckpointActOnDescendant, &a= ct); + + return act.number; +} + +/* Struct and callback function used as a hash table callback; each call + * inspects the pre-existing checkpoint->def->parent field, and adjusts + * the checkpoint->parent field as well as the parent's child fields to + * wire up the hierarchical relations for the given checkpoint. The error + * indicator gets set if a parent is missing or a requested parent would + * cause a circular parent chain. */ +struct checkpoint_set_relation { + virDomainCheckpointObjListPtr checkpoints; + int err; +}; +static int +virDomainCheckpointSetRelations(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *data) +{ + virDomainCheckpointObjPtr obj =3D payload; + struct checkpoint_set_relation *curr =3D data; + virDomainCheckpointObjPtr tmp; + + obj->parent =3D virDomainCheckpointFindByName(curr->checkpoints, + obj->def->parent); + if (!obj->parent) { + curr->err =3D -1; + obj->parent =3D &curr->checkpoints->metaroot; + VIR_WARN("checkpoint %s lacks parent", obj->def->name); + } else { + tmp =3D obj->parent; + while (tmp && tmp->def) { + if (tmp =3D=3D obj) { + curr->err =3D -1; + obj->parent =3D &curr->checkpoints->metaroot; + VIR_WARN("checkpoint %s in circular chain", obj->def->name= ); + break; + } + tmp =3D tmp->parent; + } + } + obj->parent->nchildren++; + obj->sibling =3D obj->parent->first_child; + obj->parent->first_child =3D obj; + return 0; +} + +/* Populate parent link and child count of all checkpoints, with all + * relations starting as 0/NULL. Return 0 on success, -1 if a parent + * is missing or if a circular relationship was requested. */ +int +virDomainCheckpointUpdateRelations(virDomainCheckpointObjListPtr checkpoin= ts) +{ + struct checkpoint_set_relation act =3D { checkpoints, 0 }; + + virHashForEach(checkpoints->objs, virDomainCheckpointSetRelations, &ac= t); + return act.err; +} + +/* Prepare to reparent or delete checkpoint, by removing it from its + * current listed parent. Note that when bulk removing all children + * of a parent, it is faster to just 0 the count rather than calling + * this function on each child. */ +void +virDomainCheckpointDropParent(virDomainCheckpointObjPtr checkpoint) +{ + virDomainCheckpointObjPtr prev =3D NULL; + virDomainCheckpointObjPtr curr =3D NULL; + + checkpoint->parent->nchildren--; + curr =3D checkpoint->parent->first_child; + while (curr !=3D checkpoint) { + if (!curr) { + VIR_WARN("inconsistent checkpoint relations"); + return; + } + prev =3D curr; + curr =3D curr->sibling; + } + if (prev) + prev->sibling =3D checkpoint->sibling; + else + checkpoint->parent->first_child =3D checkpoint->sibling; + checkpoint->parent =3D NULL; + checkpoint->sibling =3D NULL; +} + +int +virDomainListAllCheckpoints(virDomainCheckpointObjListPtr checkpoints, + virDomainCheckpointObjPtr from, + virDomainPtr dom, + virDomainCheckpointPtr **chks, + unsigned int flags) +{ + int count =3D virDomainCheckpointObjListNum(checkpoints, from, flags); + virDomainCheckpointPtr *list =3D NULL; + char **names; + int ret =3D -1; + size_t i; + + if (!chks || count < 0) + return count; + if (VIR_ALLOC_N(names, count) < 0 || + VIR_ALLOC_N(list, count + 1) < 0) + goto cleanup; + + if (virDomainCheckpointObjListGetNames(checkpoints, from, names, count, + flags) < 0) + goto cleanup; + for (i =3D 0; i < count; i++) + if ((list[i] =3D virGetDomainCheckpoint(dom, names[i])) =3D=3D NUL= L) + goto cleanup; + + ret =3D count; + *chks =3D list; + + cleanup: + for (i =3D 0; i < count; i++) + VIR_FREE(names[i]); + VIR_FREE(names); + if (ret < 0 && list) { + for (i =3D 0; i < count; i++) + virObjectUnref(list[i]); + VIR_FREE(list); + } + return ret; +} + + +int +virDomainCheckpointRedefinePrep(virDomainPtr domain, + virDomainObjPtr vm, + virDomainCheckpointDefPtr *defptr, + virDomainCheckpointObjPtr *chk, + virDomainXMLOptionPtr xmlopt, + bool *update_current) +{ + virDomainCheckpointDefPtr def =3D *defptr; + int ret =3D -1; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virDomainCheckpointObjPtr other; + + virUUIDFormat(domain->uuid, uuidstr); + + /* Prevent circular chains */ + if (def->parent) { + if (STREQ(def->name, def->parent)) { + virReportError(VIR_ERR_INVALID_ARG, + _("cannot set checkpoint %s as its own parent"), + def->name); + goto cleanup; + } + other =3D virDomainCheckpointFindByName(vm->checkpoints, def->pare= nt); + if (!other) { + virReportError(VIR_ERR_INVALID_ARG, + _("parent %s for checkpoint %s not found"), + def->parent, def->name); + goto cleanup; + } + while (other->def->parent) { + if (STREQ(other->def->parent, def->name)) { + virReportError(VIR_ERR_INVALID_ARG, + _("parent %s would create cycle to %s"), + other->def->name, def->name); + goto cleanup; + } + other =3D virDomainCheckpointFindByName(vm->checkpoints, + other->def->parent); + if (!other) { + VIR_WARN("checkpoints are inconsistent for %s", + vm->def->name); + break; + } + } + } + + if (def->dom && + memcmp(def->dom->uuid, domain->uuid, VIR_UUID_BUFLEN)) { + virReportError(VIR_ERR_INVALID_ARG, + _("definition for checkpoint %s must use uuid %s"), + def->name, uuidstr); + goto cleanup; + } + + other =3D virDomainCheckpointFindByName(vm->checkpoints, def->name); + if (other) { + if (other->def->dom) { + if (def->dom) { + if (!virDomainDefCheckABIStability(other->def->dom, + def->dom, xmlopt)) + goto cleanup; + } else { + /* Transfer the domain def */ + def->dom =3D other->def->dom; + other->def->dom =3D NULL; + } + } + + if (def->dom) { + if (virDomainCheckpointAlignDisks(def) < 0) { + /* revert stealing of the checkpoint domain definition */ + if (def->dom && !other->def->dom) { + other->def->dom =3D def->dom; + def->dom =3D NULL; + } + goto cleanup; + } + } + + if (other =3D=3D vm->current_checkpoint) { + *update_current =3D true; + vm->current_checkpoint =3D NULL; + } + + /* Drop and rebuild the parent relationship, but keep all + * child relations by reusing chk. */ + virDomainCheckpointDropParent(other); + virDomainCheckpointDefFree(other->def); + other->def =3D def; + *defptr =3D NULL; + *chk =3D other; + } else if (def->dom && virDomainCheckpointAlignDisks(def) < 0) { + goto cleanup; + } + + ret =3D 0; + cleanup: + return ret; +} diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c12ae57768..010ac2edb1 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -29,6 +29,7 @@ #include "configmake.h" #include "internal.h" #include "virerror.h" +#include "checkpoint_conf.h" #include "datatypes.h" #include "domain_addr.h" #include "domain_conf.h" @@ -3330,6 +3331,7 @@ static void virDomainObjDispose(void *obj) (dom->privateDataFreeFunc)(dom->privateData); virDomainSnapshotObjListFree(dom->snapshots); + virDomainCheckpointObjListFree(dom->checkpoints); } virDomainObjPtr @@ -3359,6 +3361,9 @@ virDomainObjNew(virDomainXMLOptionPtr xmlopt) if (!(domain->snapshots =3D virDomainSnapshotObjListNew())) goto error; + if (!(domain->checkpoints =3D virDomainCheckpointObjListNew())) + goto error; + virObjectLock(domain); virDomainObjSetState(domain, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_UNKNOWN); @@ -27920,7 +27925,8 @@ virDomainDefFormatInternal(virBufferPtr buf, VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET | VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES | VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST | - VIR_DOMAIN_DEF_FORMAT_SNAPSHOTS, + VIR_DOMAIN_DEF_FORMAT_SNAPSHOTS | + VIR_DOMAIN_DEF_FORMAT_CHECKPOINTS, -1); if (!(type =3D virDomainVirtTypeToString(def->virtType))) { @@ -28424,6 +28430,21 @@ virDomainDefFormatInternal(virBufferPtr buf, goto error; } + if (flags & VIR_DOMAIN_DEF_FORMAT_CHECKPOINTS) { + unsigned int snapflags =3D flags & VIR_DOMAIN_DEF_FORMAT_SECURE ? + VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE : 0; + + if (!(data && data->checkpoints)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("checkpoints requested but not provided")); + goto error; + } + if (virDomainCheckpointObjListFormat(buf, data->checkpoints, + data->current_check, caps, + xmlopt, snapflags) < 0) + goto error; + } + virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); @@ -28455,6 +28476,8 @@ unsigned int virDomainDefFormatConvertXMLFlags(unsi= gned int flags) formatFlags |=3D VIR_DOMAIN_DEF_FORMAT_MIGRATABLE; if (flags & VIR_DOMAIN_XML_SNAPSHOTS) formatFlags |=3D VIR_DOMAIN_DEF_FORMAT_SNAPSHOTS; + if (flags & VIR_DOMAIN_XML_CHECKPOINTS) + formatFlags |=3D VIR_DOMAIN_DEF_FORMAT_CHECKPOINTS; return formatFlags; } @@ -28481,7 +28504,8 @@ virDomainDefFormatFull(virDomainDefPtr def, virBuffer buf =3D VIR_BUFFER_INITIALIZER; virCheckFlags(VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS | - VIR_DOMAIN_DEF_FORMAT_SNAPSHOTS, NULL); + VIR_DOMAIN_DEF_FORMAT_SNAPSHOTS | + VIR_DOMAIN_DEF_FORMAT_CHECKPOINTS, NULL); if (virDomainDefFormatInternal(&buf, def, data, flags, NULL) < 0) return NULL; diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index 0e943d0a6c..73395e394d 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -1,7 +1,7 @@ /* * virdomainobjlist.c: domain objects list utilities * - * Copyright (C) 2006-2015 Red Hat, Inc. + * Copyright (C) 2006-2019 Red Hat, Inc. * Copyright (C) 2006-2008 Daniel P. Berrange * Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany. * @@ -25,6 +25,7 @@ #include "internal.h" #include "datatypes.h" #include "virdomainobjlist.h" +#include "checkpoint_conf.h" #include "snapshot_conf.h" #include "viralloc.h" #include "virfile.h" @@ -879,6 +880,15 @@ virDomainObjMatchFilter(virDomainObjPtr vm, return false; } + /* filter by checkpoint existence */ + if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_CHECKPOINT)) { + int nchk =3D virDomainListAllCheckpoints(vm->checkpoints, NULL, NU= LL, + NULL, 0); + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT) && nchk > 0)= || + (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT) && nchk <=3D = 0))) + return false; + } + return true; } #undef MATCH diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 13ef94149b..84e5d3dea2 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -69,6 +69,30 @@ virCapabilitiesSetHostCPU; virCapabilitiesSetNetPrefix; +# conf/checkpoint_conf.h +virDomainCheckpointAlignDisks; +virDomainCheckpointAssignDef; +virDomainCheckpointDefFormat; +virDomainCheckpointDefFree; +virDomainCheckpointDefParseString; +virDomainCheckpointDropParent; +virDomainCheckpointFindByName; +virDomainCheckpointForEach; +virDomainCheckpointForEachChild; +virDomainCheckpointForEachDescendant; +virDomainCheckpointFormatConvertXMLFlags; +virDomainCheckpointObjListFormat; +virDomainCheckpointObjListFree; +virDomainCheckpointObjListNew; +virDomainCheckpointObjListParse; +virDomainCheckpointObjListRemove; +virDomainCheckpointRedefinePrep; +virDomainCheckpointTypeFromString; +virDomainCheckpointTypeToString; +virDomainCheckpointUpdateRelations; +virDomainListAllCheckpoints; + + # conf/cpu_conf.h virCPUCacheModeTypeFromString; virCPUCacheModeTypeToString; diff --git a/tests/Makefile.am b/tests/Makefile.am index 98b99afcb1..a985a95eb3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -288,7 +288,7 @@ endif WITH_LIBXL if WITH_QEMU test_programs +=3D qemuxml2argvtest qemuxml2xmltest \ - qemuargv2xmltest domainsnapshotxml2xmltest \ + qemuargv2xmltest domaincheckpointxml2xmltest domainsnapshotxml2xmltest \ qemumonitorjsontest qemuhotplugtest \ qemuagenttest qemucapabilitiestest qemucaps2xmltest \ qemumemlocktest \ @@ -678,6 +678,11 @@ qemublocktest_LDADD =3D \ $(LDADDS) \ $(NULL) +domaincheckpointxml2xmltest_SOURCES =3D \ + domaincheckpointxml2xmltest.c testutilsqemu.c testutilsqemu.h \ + testutils.c testutils.h +domaincheckpointxml2xmltest_LDADD =3D $(qemu_LDADDS) $(LDADDS) + domainsnapshotxml2xmltest_SOURCES =3D \ domainsnapshotxml2xmltest.c testutilsqemu.c testutilsqemu.h \ testutils.c testutils.h @@ -706,7 +711,7 @@ qemusecuritytest_LDADD =3D $(qemu_LDADDS) $(LDADDS) else ! WITH_QEMU EXTRA_DIST +=3D qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \ - domainsnapshotxml2xmltest.c \ + domaincheckpointxml2xmltest.c domainsnapshotxml2xmltest.c \ testutilsqemu.c testutilsqemu.h \ testutilsqemuschema.c testutilsqemuschema.h \ qemumonitorjsontest.c qemuhotplugtest.c \ diff --git a/tests/domaincheckpointxml2xmltest.c b/tests/domaincheckpointxm= l2xmltest.c new file mode 100644 index 0000000000..0fff9fcbdf --- /dev/null +++ b/tests/domaincheckpointxml2xmltest.c @@ -0,0 +1,233 @@ +#include + +#include +#include +#include +#include + +#include +#include + +#include + +#include "testutils.h" + +#ifdef WITH_QEMU + +# include "internal.h" +# include "qemu/qemu_conf.h" +# include "qemu/qemu_domain.h" +# include "checkpoint_conf.h" +# include "testutilsqemu.h" +# include "virstring.h" + +# define VIR_FROM_THIS VIR_FROM_NONE + +static virQEMUDriver driver; + +/* This regex will skip the following XML constructs in test files + * that are dynamically generated and thus problematic to test: + * 1234352345 if the checkpoint has no name, + * 23523452345. + */ +static const char *testCheckpointXMLVariableLineRegexStr =3D + "<(name|creationTime)>[0-9]+"; + +regex_t *testCheckpointXMLVariableLineRegex =3D NULL; + +static char * +testFilterXML(char *xml) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + char **xmlLines =3D NULL; + char **xmlLine; + char *ret =3D NULL; + + if (!(xmlLines =3D virStringSplit(xml, "\n", 0))) { + VIR_FREE(xml); + goto cleanup; + } + VIR_FREE(xml); + + for (xmlLine =3D xmlLines; *xmlLine; xmlLine++) { + if (regexec(testCheckpointXMLVariableLineRegex, + *xmlLine, 0, NULL, 0) =3D=3D 0) + continue; + + virBufferStrcat(&buf, *xmlLine, "\n", NULL); + } + + if (virBufferCheckError(&buf) < 0) + goto cleanup; + + ret =3D virBufferContentAndReset(&buf); + + cleanup: + virBufferFreeAndReset(&buf); + virStringListFree(xmlLines); + return ret; +} + +static int +testCompareXMLToXMLFiles(const char *inxml, + const char *outxml, + bool internal, + bool redefine) +{ + char *inXmlData =3D NULL; + char *outXmlData =3D NULL; + char *actual =3D NULL; + int ret =3D -1; + virDomainCheckpointDefPtr def =3D NULL; + unsigned int parseflags =3D VIR_DOMAIN_CHECKPOINT_PARSE_DISKS; + unsigned int formatflags =3D VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE; + + if (internal) { + parseflags |=3D VIR_DOMAIN_CHECKPOINT_PARSE_INTERNAL; + formatflags |=3D VIR_DOMAIN_CHECKPOINT_FORMAT_INTERNAL; + } + + if (redefine) + parseflags |=3D VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE; + + if (virTestLoadFile(inxml, &inXmlData) < 0) + goto cleanup; + + if (virTestLoadFile(outxml, &outXmlData) < 0) + goto cleanup; + + if (!(def =3D virDomainCheckpointDefParseString(inXmlData, driver.caps, + driver.xmlopt, + parseflags))) + goto cleanup; + + /* Parsing XML does not populate the domain definition, so add a + * canned bare-bones fallback */ + if (!def->dom) { + // HACK + ret =3D 77; + goto cleanup; + const char *def_dom =3D "" + "" + " fedora" + " 93a5c045-6457-2c09-e56c-927cdf34e178" +/* arch=3D'x86_64' machine=3D'pc'*/ + " hvm" + ""; + int dom_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE; + if (!(def->dom =3D virDomainDefParseString(def_dom, driver.caps, + driver.xmlopt, NULL, + dom_flags))) + goto cleanup; + } + + if (!(actual =3D virDomainCheckpointDefFormat(def, driver.caps, + driver.xmlopt, + formatflags))) + goto cleanup; + + if (!redefine) { + if (!(actual =3D testFilterXML(actual))) + goto cleanup; + + if (!(outXmlData =3D testFilterXML(outXmlData))) + goto cleanup; + } + + if (STRNEQ(outXmlData, actual)) { + virTestDifferenceFull(stderr, outXmlData, outxml, actual, inxml); + goto cleanup; + } + + ret =3D 0; + + cleanup: + VIR_FREE(inXmlData); + VIR_FREE(outXmlData); + VIR_FREE(actual); + virDomainCheckpointDefFree(def); + return ret; +} + +struct testInfo { + const char *inxml; + const char *outxml; + bool internal; + bool redefine; +}; + + +static int +testCompareXMLToXMLHelper(const void *data) +{ + const struct testInfo *info =3D data; + + return testCompareXMLToXMLFiles(info->inxml, info->outxml, + info->internal, info->redefine); +} + + +static int +mymain(void) +{ + int ret =3D 0; + + if (qemuTestDriverInit(&driver) < 0) + return EXIT_FAILURE; + + if (VIR_ALLOC(testCheckpointXMLVariableLineRegex) < 0) + goto cleanup; + + if (regcomp(testCheckpointXMLVariableLineRegex, + testCheckpointXMLVariableLineRegexStr, + REG_EXTENDED | REG_NOSUB) !=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "failed to compile test regex"); + goto cleanup; + } + + +# define DO_TEST(prefix, name, inpath, outpath, internal, redefine) \ + do { \ + const struct testInfo info =3D {abs_srcdir "/" inpath "/" name ".x= ml", \ + abs_srcdir "/" outpath "/" name ".xm= l", \ + internal, redefine}; \ + if (virTestRun("CHECKPOINT XML-2-XML " prefix " " name, \ + testCompareXMLToXMLHelper, &info) < 0) \ + ret =3D -1; \ + } while (0) + +# define DO_TEST_INOUT(name, internal, redefine) \ + DO_TEST("in->out", name,\ + "domaincheckpointxml2xmlin",\ + "domaincheckpointxml2xmlout",\ + internal, redefine) + + /* Unset or set all envvars here that are copied in qemudBuildCommandL= ine + * using ADD_ENV_COPY, otherwise these tests may fail due to unexpected + * values for these envvars */ + setenv("PATH", "/bin", 1); + + DO_TEST_INOUT("empty", false, false); + DO_TEST_INOUT("sample", false, false); + + cleanup: + if (testCheckpointXMLVariableLineRegex) + regfree(testCheckpointXMLVariableLineRegex); + VIR_FREE(testCheckpointXMLVariableLineRegex); + qemuTestDriverFree(&driver); + + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIR_TEST_MAIN(mymain) + +#else + +int +main(void) +{ + return EXIT_AM_SKIP; +} + +#endif /* WITH_QEMU */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937749241872.2471049215922; Wed, 6 Mar 2019 21:49:09 -0800 (PST) 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 A452FC05D3E4; Thu, 7 Mar 2019 05:49:07 +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 7009960147; Thu, 7 Mar 2019 05:49:07 +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 304273F7D9; Thu, 7 Mar 2019 05:49:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275mUFw004035 for ; Thu, 7 Mar 2019 00:48:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id 023CE5D78D; Thu, 7 Mar 2019 05:48:30 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFC795D783; Thu, 7 Mar 2019 05:48:28 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:43 -0600 Message-Id: <20190307054752.19522-12-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 11/20] wip: backup: Parse and output backup XML 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: , 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.32]); Thu, 07 Mar 2019 05:49:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Accept XML describing a generic block job, and output it again as needed. At the moment, it has some qemu-specific hacks, such as storing internal XML for a node name, that might be cleaner once full-tree node-name support goes in. Still not done: decent tests Signed-off-by: Eric Blake --- src/conf/checkpoint_conf.h | 66 +++++ src/conf/domain_conf.h | 3 + src/conf/checkpoint_conf.c | 503 +++++++++++++++++++++++++++++++++++++ src/libvirt_private.syms | 8 +- 4 files changed, 579 insertions(+), 1 deletion(-) diff --git a/src/conf/checkpoint_conf.h b/src/conf/checkpoint_conf.h index 45ed8b0d29..2d18b7d0fb 100644 --- a/src/conf/checkpoint_conf.h +++ b/src/conf/checkpoint_conf.h @@ -168,4 +168,70 @@ int virDomainCheckpointRedefinePrep(virDomainPtr domai= n, VIR_ENUM_DECL(virDomainCheckpoint); +/* Items related to incremental backup state */ + +typedef enum { + VIR_DOMAIN_BACKUP_TYPE_DEFAULT =3D 0, + VIR_DOMAIN_BACKUP_TYPE_PUSH, + VIR_DOMAIN_BACKUP_TYPE_PULL, + + VIR_DOMAIN_BACKUP_TYPE_LAST +} virDomainBackupType; + +typedef enum { + VIR_DOMAIN_BACKUP_DISK_STATE_DEFAULT =3D 0, /* Initial */ + VIR_DOMAIN_BACKUP_DISK_STATE_CREATED, /* File created */ + VIR_DOMAIN_BACKUP_DISK_STATE_LABEL, /* Security labels applied */ + VIR_DOMAIN_BACKUP_DISK_STATE_READY, /* Handed to guest */ + VIR_DOMAIN_BACKUP_DISK_STATE_BITMAP, /* Associated temp bitmap created= */ + VIR_DOMAIN_BACKUP_DISK_STATE_EXPORT, /* NBD export created */ + VIR_DOMAIN_BACKUP_DISK_STATE_COMPLETE, /* Push job finished */ +} virDomainBackupDiskState; + +/* Stores disk-backup information */ +typedef struct _virDomainBackupDiskDef virDomainBackupDiskDef; +typedef virDomainBackupDiskDef *virDomainBackupDiskDefPtr; +struct _virDomainBackupDiskDef { + char *name; /* name matching the dom->disks that matches na= me */ + + /* details of target for push-mode, or of the scratch file for pull-mo= de */ + virStorageSourcePtr store; + int state; /* virDomainBackupDiskState, not stored in XML */ +}; + +/* Stores the complete backup metadata */ +typedef struct _virDomainBackupDef virDomainBackupDef; +typedef virDomainBackupDef *virDomainBackupDefPtr; +struct _virDomainBackupDef { + /* Public XML. */ + int type; /* virDomainBackupType */ + int id; + char *incremental; + virStorageNetHostDefPtr server; /* only when type =3D=3D PULL */ + + size_t ndisks; /* should not exceed dom->ndisks */ + virDomainBackupDiskDef *disks; +}; + +VIR_ENUM_DECL(virDomainBackup); + +typedef enum { + VIR_DOMAIN_BACKUP_PARSE_INTERNAL =3D 1 << 0, +} virDomainBackupParseFlags; + +virDomainBackupDefPtr virDomainBackupDefParseString(const char *xmlStr, + virDomainXMLOptionPtr = xmlopt, + unsigned int flags); +virDomainBackupDefPtr virDomainBackupDefParseNode(xmlDocPtr xml, + xmlNodePtr root, + virDomainXMLOptionPtr xm= lopt, + unsigned int flags); +void virDomainBackupDefFree(virDomainBackupDefPtr def); +int virDomainBackupDefFormat(virBufferPtr buf, + virDomainBackupDefPtr def, + bool internal); +int virDomainBackupAlignDisks(virDomainBackupDefPtr backup, + virDomainDefPtr dom, const char *suffix); + #endif /* LIBVIRT_CHECKPOINT_CONF_H */ diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c3d5f53bdd..ea98dd31d9 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -125,6 +125,9 @@ typedef virDomainCheckpointObj *virDomainCheckpointObjP= tr; typedef struct _virDomainCheckpointObjList virDomainCheckpointObjList; typedef virDomainCheckpointObjList *virDomainCheckpointObjListPtr; +typedef struct _virDomainBackupDef virDomainBackupDef; +typedef virDomainBackupDef *virDomainBackupDefPtr; + typedef struct _virDomainSnapshotObj virDomainSnapshotObj; typedef virDomainSnapshotObj *virDomainSnapshotObjPtr; diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index e5e4c5e306..61aeb7f0a1 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -1238,3 +1238,506 @@ virDomainCheckpointRedefinePrep(virDomainPtr domain, cleanup: return ret; } + +/* Backup Def functions */ + +VIR_ENUM_IMPL(virDomainBackup, VIR_DOMAIN_BACKUP_TYPE_LAST, + "default", "push", "pull"); + +static void +virDomainBackupDiskDefClear(virDomainBackupDiskDefPtr disk) +{ + VIR_FREE(disk->name); + virStorageSourceClear(disk->store); + disk->store =3D NULL; +} + +void +virDomainBackupDefFree(virDomainBackupDefPtr def) +{ + size_t i; + + if (!def) + return; + + VIR_FREE(def->incremental); + VIR_FREE(def->server); // FIXME which struct + for (i =3D 0; i < def->ndisks; i++) + virDomainBackupDiskDefClear(&def->disks[i]); + VIR_FREE(def->disks); + VIR_FREE(def); +} + +static int +virDomainBackupDiskDefParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virDomainBackupDiskDefPtr def, + bool push, bool internal, + virDomainXMLOptionPtr xmlopt) +{ + int ret =3D -1; + // char *backup =3D NULL; /* backup=3D"yes|no"? */ + char *type =3D NULL; + char *driver =3D NULL; + xmlNodePtr cur; + xmlNodePtr saved =3D ctxt->node; + + ctxt->node =3D node; + + if (VIR_ALLOC(def->store) < 0) + goto cleanup; + + def->name =3D virXMLPropString(node, "name"); + if (!def->name) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing name from disk backup element")); + goto cleanup; + } + + /* Needed? A way for users to list a disk and explicitly mark it + * as not participating, and then output shows all disks rather + * than just active disks */ +#if 0 + backup =3D virXMLPropString(node, "backup"); + if (backup) { + def->type =3D virDomainCheckpointTypeFromString(checkpoint); + if (def->type <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown disk checkpoint setting '%s'"), + checkpoint); + goto cleanup; + } + } +#endif + + if ((type =3D virXMLPropString(node, "type"))) { + if ((def->store->type =3D virStorageTypeFromString(type)) <=3D 0 || + def->store->type =3D=3D VIR_STORAGE_TYPE_VOLUME || + def->store->type =3D=3D VIR_STORAGE_TYPE_DIR) { + virReportError(VIR_ERR_XML_ERROR, + _("unknown disk backup type '%s'"), type); + goto cleanup; + } + } else { + def->store->type =3D VIR_STORAGE_TYPE_FILE; + } + + if ((cur =3D virXPathNode(push ? "./target" : "./scratch", ctxt)) && + virDomainDiskSourceParse(cur, ctxt, def->store, 0, xmlopt) < 0) + goto cleanup; + + if (internal) { + int detected; + if (virXPathInt("string(./node/@detected)", ctxt, &detected) < 0) + goto cleanup; + def->store->detected =3D detected; + def->store->nodeformat =3D virXPathString("string(./node)", ctxt); + } + + if ((driver =3D virXPathString("string(./driver/@type)", ctxt))) { + def->store->format =3D virStorageFileFormatTypeFromString(driver); + if (def->store->format <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown disk backup driver '%s'"), driver); + goto cleanup; + } else if (!push && def->store->format !=3D VIR_STORAGE_FILE_QCOW2= ) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("pull mode requires qcow2 driver, not '%s'"), + driver); + goto cleanup; + } + } + + /* validate that the passed path is absolute */ + if (virStorageSourceIsRelative(def->store)) { + virReportError(VIR_ERR_XML_ERROR, + _("disk backup image path '%s' must be absolute"), + def->store->path); + goto cleanup; + } + + ret =3D 0; + cleanup: + ctxt->node =3D saved; + + VIR_FREE(driver); +// VIR_FREE(backup); + VIR_FREE(type); + if (ret < 0) + virDomainBackupDiskDefClear(def); + return ret; +} + +static virDomainBackupDefPtr +virDomainBackupDefParse(xmlXPathContextPtr ctxt, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + virDomainBackupDefPtr def =3D NULL; + virDomainBackupDefPtr ret =3D NULL; + xmlNodePtr *nodes =3D NULL; + xmlNodePtr node =3D NULL; + char *mode =3D NULL; + bool push; + size_t i; + int n; + + if (VIR_ALLOC(def) < 0) + goto cleanup; + + mode =3D virXMLPropString(ctxt->node, "mode"); + if (mode) { + def->type =3D virDomainBackupTypeFromString(mode); + if (def->type <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown backup mode '%s'"), mode); + goto cleanup; + } + } else { + def->type =3D VIR_DOMAIN_BACKUP_TYPE_PUSH; + } + push =3D def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PUSH; + + if (flags & VIR_DOMAIN_BACKUP_PARSE_INTERNAL) { + char *tmp =3D virXMLPropString(ctxt->node, "id"); + if (tmp && virStrToLong_i(tmp, NULL, 10, &def->id) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("invalid 'id' value '%s'"), tmp); + VIR_FREE(tmp); + goto cleanup; + } + VIR_FREE(tmp); + } + + def->incremental =3D virXPathString("string(./incremental)", ctxt); + + node =3D virXPathNode("./server", ctxt); + if (node) { + if (def->type !=3D VIR_DOMAIN_BACKUP_TYPE_PULL) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("use of requires pull mode backup")); + goto cleanup; + } + if (VIR_ALLOC(def->server) < 0) + goto cleanup; + if (virDomainStorageNetworkParseHost(node, def->server) < 0) + goto cleanup; + if (def->server->transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_RDMA)= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("transport rdma is not supported for = ")); + goto cleanup; + } + } + + if ((n =3D virXPathNodeSet("./disks/*", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->disks, n) < 0) + goto cleanup; + def->ndisks =3D n; + for (i =3D 0; i < def->ndisks; i++) { + if (virDomainBackupDiskDefParseXML(nodes[i], ctxt, + &def->disks[i], push, + flags & VIR_DOMAIN_BACKUP_PARSE= _INTERNAL, + xmlopt) < 0) + goto cleanup; + } + VIR_FREE(nodes); + + VIR_STEAL_PTR(ret, def); + + cleanup: + VIR_FREE(mode); + VIR_FREE(nodes); + virDomainBackupDefFree(def); + + return ret; +} + +virDomainBackupDefPtr +virDomainBackupDefParseString(const char *xmlStr, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + virDomainBackupDefPtr ret =3D NULL; + xmlDocPtr xml; + int keepBlanksDefault =3D xmlKeepBlanksDefault(0); + + if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_backup)")))) { + xmlKeepBlanksDefault(keepBlanksDefault); + ret =3D virDomainBackupDefParseNode(xml, xmlDocGetRootElement(xml), + xmlopt, flags); + xmlFreeDoc(xml); + } + xmlKeepBlanksDefault(keepBlanksDefault); + + return ret; +} + +virDomainBackupDefPtr +virDomainBackupDefParseNode(xmlDocPtr xml, + xmlNodePtr root, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + xmlXPathContextPtr ctxt =3D NULL; + virDomainBackupDefPtr def =3D NULL; + + if (!virXMLNodeNameEqual(root, "domainbackup")) { + virReportError(VIR_ERR_XML_ERROR, "%s", _("domainbackup")); + goto cleanup; + } + + ctxt =3D xmlXPathNewContext(xml); + if (ctxt =3D=3D NULL) { + virReportOOMError(); + goto cleanup; + } + + ctxt->node =3D root; + def =3D virDomainBackupDefParse(ctxt, xmlopt, flags); + cleanup: + xmlXPathFreeContext(ctxt); + return def; +} + +static int +virDomainBackupDiskDefFormat(virBufferPtr buf, + virDomainBackupDiskDefPtr disk, + bool push, bool internal) +{ + int type =3D disk->store->type; + virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; + virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + int ret =3D -1; + + if (!disk->name) + return 0; + + virBufferEscapeString(buf, "name); + /* TODO: per-disk backup=3Doff? */ + + virBufferAsprintf(buf, " type=3D'%s'>\n", virStorageTypeToString(type)= ); + virBufferAdjustIndent(buf, 2); + + if (disk->store->format > 0) + virBufferEscapeString(buf, "\n", + virStorageFileFormatTypeToString(disk->store= ->format)); + /* TODO: should node names be part of storage file xml, rather + * than a one-off hack for qemu? */ + if (internal) { + virBufferEscapeString(buf, "store->detected ? "1" : "0"); + virBufferEscapeString(buf, ">%s\n", disk->store->nodeformat= ); + } + + virBufferSetChildIndent(&childBuf, buf); + if (virDomainStorageSourceFormat(&attrBuf, &childBuf, disk->store, 0, + false) < 0) + goto cleanup; + if (virXMLFormatElement(buf, push ? "target" : "scratch", + &attrBuf, &childBuf) < 0) + goto cleanup; + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + ret =3D 0; + + cleanup: + virBufferFreeAndReset(&attrBuf); + virBufferFreeAndReset(&childBuf); + return ret; +} + +int +virDomainBackupDefFormat(virBufferPtr buf, virDomainBackupDefPtr def, + bool internal) +{ + size_t i; + + virBufferAsprintf(buf, "type)); + if (def->id) + virBufferAsprintf(buf, " id=3D'%d'", def->id); + virBufferAddLit(buf, ">\n"); + virBufferAdjustIndent(buf, 2); + + virBufferEscapeString(buf, "%s\n", + def->incremental); + if (def->server) { + virBufferAsprintf(buf, "serv= er->transport)); + virBufferEscapeString(buf, " name=3D'%s'", def->server->name); + if (def->server->port) + virBufferAsprintf(buf, " port=3D'%u'", def->server->port); + virBufferEscapeString(buf, " socket=3D'%s'", def->server->socket); + virBufferAddLit(buf, "/>\n"); + } + + if (def->ndisks) { + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + for (i =3D 0; i < def->ndisks; i++) { + if (!def->disks[i].store) + continue; + if (virDomainBackupDiskDefFormat(buf, &def->disks[i], + def->type =3D=3D VIR_DOMAIN_B= ACKUP_TYPE_PUSH, + internal) < 0) + return -1; + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + return virBufferCheckError(buf); +} + + +static int +virDomainBackupCompareDiskIndex(const void *a, const void *b) +{ + const virDomainBackupDiskDef *diska =3D a; + const virDomainBackupDiskDef *diskb =3D b; + + /* Integer overflow shouldn't be a problem here. */ + return diska->idx - diskb->idx; +} + +static int +virDomainBackupDefAssignStore(virDomainBackupDiskDefPtr disk, + virStorageSourcePtr src, + const char *suffix) +{ + int ret =3D -1; + + if (virStorageSourceIsEmpty(src)) { + if (disk->store) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk '%s' has no media"), disk->name); + goto cleanup; + } + } else if (src->readonly && disk->store) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("backup of readonly disk '%s' makes no sense"), + disk->name); + goto cleanup; + } else if (!disk->store) { + if (virStorageSourceGetActualType(src) =3D=3D VIR_STORAGE_TYPE_FIL= E) { + if (VIR_ALLOC(disk->store) < 0) + goto cleanup; + disk->store->type =3D VIR_STORAGE_TYPE_FILE; + if (virAsprintf(&disk->store->path, "%s.%s", src->path, + suffix) < 0) + goto cleanup; + disk->store->detected =3D true; + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("refusing to generate file name for disk '%s'= "), + disk->name); + goto cleanup; + } + } + ret =3D 0; + cleanup: + return ret; +} + +/* Align def->disks to domain. Sort the list of def->disks, + * generating storage names using suffix as needed. Convert paths to + * disk targets for uniformity. Issue an error and return -1 if any + * def->disks[n]->name appears more than once or does not map to + * dom->disks. */ +int +virDomainBackupAlignDisks(virDomainBackupDefPtr def, virDomainDefPtr dom, + const char *suffix) +{ + int ret =3D -1; + virBitmapPtr map =3D NULL; + size_t i; + int ndisks; + bool alloc_all =3D false; + + if (def->ndisks > dom->ndisks) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("too many disk backup requests for domain")); + goto cleanup; + } + + /* Unlikely to have a guest without disks but technically possible. */ + if (!dom->ndisks) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("domain must have at least one disk to perform " + "backups")); + goto cleanup; + } + + if (!(map =3D virBitmapNew(dom->ndisks))) + goto cleanup; + + /* Double check requested disks. */ + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDefPtr disk =3D &def->disks[i]; + int idx =3D virDomainDiskIndexByName(dom, disk->name, false); + + if (idx < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("no disk named '%s'"), disk->name); + goto cleanup; + } + + if (virBitmapIsBitSet(map, idx)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk '%s' specified twice"), + disk->name); + goto cleanup; + } + ignore_value(virBitmapSetBit(map, idx)); + disk->idx =3D idx; + + if (STRNEQ(disk->name, dom->disks[idx]->dst)) { + VIR_FREE(disk->name); + if (VIR_STRDUP(disk->name, dom->disks[idx]->dst) < 0) + goto cleanup; + } + if (disk->store && !disk->store->path) { + virStorageSourceClear(disk->store); + disk->store =3D NULL; + } + if (virDomainBackupDefAssignStore(disk, dom->disks[i]->src, suffix= ) < 0) + goto cleanup; + } + + /* Provide fillers for all remaining disks, for easier iteration. */ + if (!def->ndisks) + alloc_all =3D true; + ndisks =3D def->ndisks; + if (VIR_EXPAND_N(def->disks, def->ndisks, + dom->ndisks - def->ndisks) < 0) + goto cleanup; + + for (i =3D 0; i < dom->ndisks; i++) { + virDomainBackupDiskDefPtr disk; + + if (virBitmapIsBitSet(map, i)) + continue; + disk =3D &def->disks[ndisks++]; + if (VIR_STRDUP(disk->name, dom->disks[i]->dst) < 0) + goto cleanup; + disk->idx =3D i; + if (alloc_all && + virDomainBackupDefAssignStore(disk, dom->disks[i]->src, suffix= ) < 0) + goto cleanup; + } + + qsort(&def->disks[0], def->ndisks, sizeof(def->disks[0]), + virDomainBackupCompareDiskIndex); + + ret =3D 0; + + cleanup: + virBitmapFree(map); + return ret; +} diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 84e5d3dea2..053fa8bc8b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -70,6 +70,13 @@ virCapabilitiesSetNetPrefix; # conf/checkpoint_conf.h +virDomainBackupAlignDisks; +virDomainBackupDefFormat; +virDomainBackupDefFree; +virDomainBackupDefParseNode; +virDomainBackupDefParseString; +virDomainBackupTypeFromString; +virDomainBackupTypeToString; virDomainCheckpointAlignDisks; virDomainCheckpointAssignDef; virDomainCheckpointDefFormat; @@ -92,7 +99,6 @@ virDomainCheckpointTypeToString; virDomainCheckpointUpdateRelations; virDomainListAllCheckpoints; - # conf/cpu_conf.h virCPUCacheModeTypeFromString; virCPUCacheModeTypeToString; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937753092125.25930215643564; Wed, 6 Mar 2019 21:49:13 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1806C307E042; Thu, 7 Mar 2019 05:49:11 +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 E1E7DA4F88; Thu, 7 Mar 2019 05:49:10 +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 9F7663F5CF; Thu, 7 Mar 2019 05:49:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275mVpW004046 for ; Thu, 7 Mar 2019 00:48:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6426F5D78C; Thu, 7 Mar 2019 05:48:31 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 246735D783; Thu, 7 Mar 2019 05:48:30 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:44 -0600 Message-Id: <20190307054752.19522-13-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 12/20] backup: Implement virsh support for checkpoints 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: , 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 07 Mar 2019 05:49:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Introduce a bunch of new virsh commands for managing checkpoints in isolation. More commands are needed for performing incremental backups, but these commands were easy to implement by modeling heavily after virsh-snapshot.c (no need for checkpoint-revert, and checkpoint-list was a lot easier since we don't have to cater to older libvirt API). Signed-off-by: Eric Blake --- tools/virsh-checkpoint.h | 29 + tools/virsh-completer.h | 4 + tools/virsh-util.h | 3 + tools/virsh.h | 1 + po/POTFILES | 1 + tools/Makefile.am | 3 +- tools/virsh-checkpoint.c | 1377 ++++++++++++++++++++++++++++++++++ tools/virsh-completer.c | 52 +- tools/virsh-domain-monitor.c | 25 +- tools/virsh-domain.c | 22 + tools/virsh-util.c | 11 + tools/virsh.c | 2 + tools/virsh.pod | 240 +++++- 13 files changed, 1757 insertions(+), 13 deletions(-) create mode 100644 tools/virsh-checkpoint.h create mode 100644 tools/virsh-checkpoint.c diff --git a/tools/virsh-checkpoint.h b/tools/virsh-checkpoint.h new file mode 100644 index 0000000000..707defa1c5 --- /dev/null +++ b/tools/virsh-checkpoint.h @@ -0,0 +1,29 @@ +/* + * virsh-checkpoint.h: Commands to manage domain checkpoints + * + * Copyright (C) 2005-2018 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ + +#ifndef LIBVIRT_VIRSH_CHECKPOINT_H +# define LIBVIRT_VIRSH_CHECKPOINT_H + +# include "virsh.h" + +extern const vshCmdDef checkpointCmds[]; + +#endif /* LIBVIRT_VIRSH_CHECKPOINT_H */ diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 2e2e1edafb..429e695a55 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -75,6 +75,10 @@ char ** virshSecretUUIDCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); +char ** virshCheckpointNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + char ** virshSnapshotNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); diff --git a/tools/virsh-util.h b/tools/virsh-util.h index fb2ed277af..f814558144 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -43,6 +43,9 @@ virshCommandOptDomain(vshControl *ctl, void virshDomainFree(virDomainPtr dom); +void +virshDomainCheckpointFree(virDomainCheckpointPtr chk); + void virshDomainSnapshotFree(virDomainSnapshotPtr snap); diff --git a/tools/virsh.h b/tools/virsh.h index 254ce3289e..da157d6caa 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -41,6 +41,7 @@ /* * Command group types */ +# define VIRSH_CMD_GRP_CHECKPOINT "Checkpoint" # define VIRSH_CMD_GRP_DOM_MANAGEMENT "Domain Management" # define VIRSH_CMD_GRP_DOM_MONITORING "Domain Monitoring" # define VIRSH_CMD_GRP_STORAGE_POOL "Storage Pool" diff --git a/po/POTFILES b/po/POTFILES index 57c55fb35f..70417cd01b 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -300,6 +300,7 @@ src/xenconfig/xen_xl.c src/xenconfig/xen_xm.c tests/virpolkittest.c tools/libvirt-guests.sh.in +tools/virsh-checkpoint.c tools/virsh-console.c tools/virsh-domain-monitor.c tools/virsh-domain.c diff --git a/tools/Makefile.am b/tools/Makefile.am index f2f84f7852..5a4facb3fb 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,4 +1,4 @@ -## Copyright (C) 2005-2016 Red Hat, Inc. +## Copyright (C) 2005-2018 Red Hat, Inc. ## Copyright (C) 2013 Yuto KAWAMURA(kawamuray) ## ## This library is free software; you can redistribute it and/or @@ -220,6 +220,7 @@ virt_login_shell_CFLAGS =3D \ virsh_SOURCES =3D \ virsh.c virsh.h \ + virsh-checkpoint.c virsh-checkpoint.h \ virsh-completer.c virsh-completer.h \ virsh-console.c virsh-console.h \ virsh-domain.c virsh-domain.h \ diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c new file mode 100644 index 0000000000..a85797653f --- /dev/null +++ b/tools/virsh-checkpoint.c @@ -0,0 +1,1377 @@ +/* + * virsh-checkpoint.c: Commands to manage domain checkpoints + * + * Copyright (C) 2005-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + * Daniel Veillard + * Karel Zak + * Daniel P. Berrange + * + */ + +#include +#include "virsh-checkpoint.h" + +#include + +#include +#include +#include +#include + +#include "internal.h" +#include "virbuffer.h" +#include "viralloc.h" +#include "virfile.h" +#include "virsh-util.h" +#include "virstring.h" +#include "virxml.h" +#include "conf/checkpoint_conf.h" + +/* Helper for checkpoint-create and checkpoint-create-as */ +static bool +virshCheckpointCreate(vshControl *ctl, + virDomainPtr dom, + const char *buffer, + unsigned int flags, + const char *from) +{ + bool ret =3D false; + virDomainCheckpointPtr checkpoint; + const char *name =3D NULL; + + checkpoint =3D virDomainCheckpointCreateXML(dom, buffer, flags); + + if (checkpoint =3D=3D NULL) + goto cleanup; + + if (flags & VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE_LIST) { + vshPrintExtra(ctl, "%s", + _("Domain checkpoint list imported successfully")); + ret =3D true; + goto cleanup; + } + + name =3D virDomainCheckpointGetName(checkpoint); + if (!name) { + vshError(ctl, "%s", _("Could not get snapshot name")); + goto cleanup; + } + + if (from) + vshPrintExtra(ctl, _("Domain checkpoint %s created from '%s'"), + name, from); + else + vshPrintExtra(ctl, _("Domain checkpoint %s created"), name); + + ret =3D true; + + cleanup: + virshDomainCheckpointFree(checkpoint); + return ret; +} + + +/* + * "checkpoint-create" command + */ +static const vshCmdInfo info_checkpoint_create[] =3D { + {.name =3D "help", + .data =3D N_("Create a checkpoint from XML") + }, + {.name =3D "desc", + .data =3D N_("Create a checkpoint from XML for use in " + "future incremental backups") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_create[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "xmlfile", + .type =3D VSH_OT_STRING, + .help =3D N_("domain checkpoint XML") + }, + {.name =3D "redefine", + .type =3D VSH_OT_BOOL, + .help =3D N_("redefine metadata for existing checkpoint") + }, + VIRSH_COMMON_OPT_CURRENT(N_("with redefine, set current checkpoint")), + {.name =3D "redefine-list", + .type =3D VSH_OT_BOOL, + .help =3D N_("bulk define a set of checkpoints, implies --redefine"), + }, + {.name =3D "no-metadata", + .type =3D VSH_OT_BOOL, + .help =3D N_("create checkpoint but create no metadata") + }, + {.name =3D "quiesce", + .type =3D VSH_OT_BOOL, + .help =3D N_("quiesce guest's file systems") + }, + {.name =3D NULL} +}; + +static bool +cmdCheckpointCreate(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + const char *from =3D NULL; + char *buffer =3D NULL; + unsigned int flags =3D 0; + + if (vshCommandOptBool(cmd, "redefine")) + flags |=3D VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE; + if (vshCommandOptBool(cmd, "current")) + flags |=3D VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT; + if (vshCommandOptBool(cmd, "no-metadata")) + flags |=3D VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA; + if (vshCommandOptBool(cmd, "quiesce")) + flags |=3D VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE; + if (vshCommandOptBool(cmd, "redefine-list")) + flags |=3D VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE | + VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE_LIST; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + goto cleanup; + + if (vshCommandOptStringReq(ctl, cmd, "xmlfile", &from) < 0) + goto cleanup; + if (!from) { + buffer =3D vshStrdup(ctl, ""); + } else { + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { + vshSaveLibvirtError(); + goto cleanup; + } + } + + ret =3D virshCheckpointCreate(ctl, dom, buffer, flags, from); + + cleanup: + VIR_FREE(buffer); + virshDomainFree(dom); + + return ret; +} + + +/* + * "checkpoint-create-as" command + */ +static int +virshParseCheckpointDiskspec(vshControl *ctl, + virBufferPtr buf, + const char *str) +{ + int ret =3D -1; + const char *name =3D NULL; + const char *checkpoint =3D NULL; + const char *bitmap =3D NULL; + char **array =3D NULL; + int narray; + size_t i; + + narray =3D vshStringToArray(str, &array); + if (narray <=3D 0) + goto cleanup; + + name =3D array[0]; + for (i =3D 1; i < narray; i++) { + if (!checkpoint && STRPREFIX(array[i], "checkpoint=3D")) + checkpoint =3D array[i] + strlen("checkpoint=3D"); + else if (!bitmap && STRPREFIX(array[i], "bitmap=3D")) + bitmap =3D array[i] + strlen("bitmap=3D"); + else + goto cleanup; + } + + virBufferEscapeString(buf, "\n"); + ret =3D 0; + cleanup: + if (ret < 0) + vshError(ctl, _("unable to parse diskspec: %s"), str); + virStringListFree(array); + return ret; +} + +static const vshCmdInfo info_checkpoint_create_as[] =3D { + {.name =3D "help", + .data =3D N_("Create a checkpoint from a set of args") + }, + {.name =3D "desc", + .data =3D N_("Create a checkpoint from arguments for use in " + "future incremental backups") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_create_as[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "name", + .type =3D VSH_OT_STRING, + .help =3D N_("name of checkpoint") + }, + {.name =3D "description", + .type =3D VSH_OT_STRING, + .help =3D N_("description of checkpoint") + }, + {.name =3D "print-xml", + .type =3D VSH_OT_BOOL, + .help =3D N_("print XML document rather than create") + }, + {.name =3D "no-metadata", + .type =3D VSH_OT_BOOL, + .help =3D N_("take checkpoint but create no metadata") + }, + {.name =3D "quiesce", + .type =3D VSH_OT_BOOL, + .help =3D N_("quiesce guest's file systems") + }, + {.name =3D "diskspec", + .type =3D VSH_OT_ARGV, + .help =3D N_("disk attributes: disk[,checkpoint=3Dtype][,bitmap=3Dnam= e]") + }, + {.name =3D NULL} +}; + + +static bool +cmdCheckpointCreateAs(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + char *buffer =3D NULL; + const char *name =3D NULL; + const char *desc =3D NULL; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + unsigned int flags =3D 0; + const vshCmdOpt *opt =3D NULL; + + if (vshCommandOptBool(cmd, "no-metadata")) { + if (vshCommandOptBool(cmd, "print-xml")) { + vshError(ctl, "%s", + _("--print-xml is incompatible with --no-metadata")); + return false; + } + flags |=3D VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA; + } + if (vshCommandOptBool(cmd, "quiesce")) + flags |=3D VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0 || + vshCommandOptStringReq(ctl, cmd, "description", &desc) < 0) + goto cleanup; + + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); + virBufferEscapeString(&buf, "%s\n", name); + virBufferEscapeString(&buf, "%s\n", desc); + + if (vshCommandOptBool(cmd, "diskspec")) { + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); + while ((opt =3D vshCommandOptArgv(ctl, cmd, opt))) { + if (virshParseCheckpointDiskspec(ctl, &buf, opt->data) < 0) + goto cleanup; + } + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); + } + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); + + if (virBufferError(&buf)) { + vshError(ctl, "%s", _("Out of memory")); + goto cleanup; + } + + buffer =3D virBufferContentAndReset(&buf); + + if (vshCommandOptBool(cmd, "print-xml")) { + vshPrint(ctl, "%s\n", buffer); + ret =3D true; + goto cleanup; + } + + ret =3D virshCheckpointCreate(ctl, dom, buffer, flags, NULL); + + cleanup: + virBufferFreeAndReset(&buf); + VIR_FREE(buffer); + virshDomainFree(dom); + + return ret; +} + + +/* Helper for resolving {--current | --ARG name} into a checkpoint + * belonging to DOM. If EXCLUSIVE, fail if both --current and arg are + * present. On success, populate *CHK and *NAME, before returning 0. + * On failure, return -1 after issuing an error message. */ +static int +virshLookupCheckpoint(vshControl *ctl, + const vshCmd *cmd, + const char *arg, + bool exclusive, + virDomainPtr dom, + virDomainCheckpointPtr *chk, + const char **name) +{ + bool current =3D vshCommandOptBool(cmd, "current"); + const char *chkname =3D NULL; + + if (vshCommandOptStringReq(ctl, cmd, arg, &chkname) < 0) + return -1; + + if (exclusive && current && chkname) { + vshError(ctl, _("--%s and --current are mutually exclusive"), arg); + return -1; + } + + if (chkname) { + *chk =3D virDomainCheckpointLookupByName(dom, chkname, 0); + } else if (current) { + *chk =3D virDomainCheckpointCurrent(dom, 0); + } else { + vshError(ctl, _("--%s or --current is required"), arg); + return -1; + } + if (!*chk) { + vshReportError(ctl); + return -1; + } + + *name =3D virDomainCheckpointGetName(*chk); + return 0; +} + + +/* + * "checkpoint-edit" command + */ +static const vshCmdInfo info_checkpoint_edit[] =3D { + {.name =3D "help", + .data =3D N_("edit XML for a checkpoint") + }, + {.name =3D "desc", + .data =3D N_("Edit the domain checkpoint XML for a named checkpoint") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_edit[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "checkpointname", + .type =3D VSH_OT_STRING, + .help =3D N_("checkpoint name"), + .completer =3D virshCheckpointNameCompleter, + }, + VIRSH_COMMON_OPT_CURRENT(N_("also set edited checkpoint as current")), + {.name =3D "rename", + .type =3D VSH_OT_BOOL, + .help =3D N_("allow renaming an existing checkpoint") + }, + {.name =3D "clone", + .type =3D VSH_OT_BOOL, + .help =3D N_("allow cloning to new name") + }, + {.name =3D NULL} +}; + +static bool +cmdCheckpointEdit(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + virDomainCheckpointPtr edited =3D NULL; + const char *name =3D NULL; + const char *edited_name; + bool ret =3D false; + unsigned int getxml_flags =3D VIR_DOMAIN_CHECKPOINT_XML_SECURE; + unsigned int define_flags =3D VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE; + bool rename_okay =3D vshCommandOptBool(cmd, "rename"); + bool clone_okay =3D vshCommandOptBool(cmd, "clone"); + + VSH_EXCLUSIVE_OPTIONS_EXPR("rename", rename_okay, "clone", clone_okay) + + if (vshCommandOptBool(cmd, "current") && + vshCommandOptBool(cmd, "checkpointname")) + define_flags |=3D VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (virshLookupCheckpoint(ctl, cmd, "checkpointname", false, dom, + &checkpoint, &name) < 0) + goto cleanup; + +#define EDIT_GET_XML \ + virDomainCheckpointGetXMLDesc(checkpoint, getxml_flags) +#define EDIT_NOT_CHANGED \ + do { \ + /* Depending on flags, we re-edit even if XML is unchanged. */ \ + if (!(define_flags & VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT)) { \ + vshPrintExtra(ctl, \ + _("Checkpoint %s XML configuration not changed.\= n"), \ + name); \ + ret =3D true; \ + goto edit_cleanup; \ + } \ + } while (0) +#define EDIT_DEFINE \ + edited =3D virDomainCheckpointCreateXML(dom, doc_edited, define_flags) +#include "virsh-edit.c" + + edited_name =3D virDomainCheckpointGetName(edited); + if (STREQ(name, edited_name)) { + vshPrintExtra(ctl, _("Checkpoint %s edited.\n"), name); + } else if (clone_okay) { + vshPrintExtra(ctl, _("Checkpoint %s cloned to %s.\n"), name, + edited_name); + } else { + unsigned int delete_flags; + + delete_flags =3D VIR_DOMAIN_CHECKPOINT_DELETE_METADATA_ONLY; + if (virDomainCheckpointDelete(rename_okay ? checkpoint : edited, + delete_flags) < 0) { + vshReportError(ctl); + vshError(ctl, _("Failed to clean up %s"), + rename_okay ? name : edited_name); + goto cleanup; + } + if (!rename_okay) { + vshError(ctl, _("Must use --rename or --clone to change %s to = %s"), + name, edited_name); + goto cleanup; + } + } + + ret =3D true; + + cleanup: + if (!ret && name) + vshError(ctl, _("Failed to update %s"), name); + virshDomainCheckpointFree(edited); + virshDomainCheckpointFree(checkpoint); + virshDomainFree(dom); + return ret; +} + + +/* + * "checkpoint-current" command + */ +static const vshCmdInfo info_checkpoint_current[] =3D { + {.name =3D "help", + .data =3D N_("Get or set the current checkpoint") + }, + {.name =3D "desc", + .data =3D N_("Get or set the current checkpoint") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_current[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "name", + .type =3D VSH_OT_BOOL, + .help =3D N_("list the name, rather than the full xml") + }, + {.name =3D "security-info", + .type =3D VSH_OT_BOOL, + .help =3D N_("include security sensitive information in XML dump") + }, + {.name =3D "no-domain", + .type =3D VSH_OT_BOOL, + .help =3D N_("exclude from XML") + }, + {.name =3D "size", + .type =3D VSH_OT_BOOL, + .help =3D N_("include backup size estimate in XML dump") + }, + {.name =3D "checkpointname", + .type =3D VSH_OT_STRING, + .help =3D N_("name of existing checkpoint to make current"), + .completer =3D virshCheckpointNameCompleter, + }, + {.name =3D NULL} +}; + +static bool +cmdCheckpointCurrent(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + int current; + virDomainCheckpointPtr checkpoint =3D NULL; + char *xml =3D NULL; + const char *checkpointname =3D NULL; + unsigned int flags =3D 0; + const char *domname; + + if (vshCommandOptBool(cmd, "security-info")) + flags |=3D VIR_DOMAIN_CHECKPOINT_XML_SECURE; + if (vshCommandOptBool(cmd, "no-domain")) + flags |=3D VIR_DOMAIN_CHECKPOINT_XML_NO_DOMAIN; + if (vshCommandOptBool(cmd, "size")) + flags |=3D VIR_DOMAIN_CHECKPOINT_XML_SIZE; + + VSH_EXCLUSIVE_OPTIONS("name", "checkpointname"); + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, &domname))) + return false; + + if (vshCommandOptStringReq(ctl, cmd, "checkpointname", &checkpointname= ) < 0) + goto cleanup; + + if (checkpointname) { + virDomainCheckpointPtr checkpoint2 =3D NULL; + flags =3D (VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE | + VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT); + + if (!(checkpoint =3D virDomainCheckpointLookupByName(dom, + checkpointname,= 0))) + goto cleanup; + + xml =3D virDomainCheckpointGetXMLDesc(checkpoint, + VIR_DOMAIN_CHECKPOINT_XML_SECU= RE); + if (!xml) + goto cleanup; + + if (!(checkpoint2 =3D virDomainCheckpointCreateXML(dom, xml, flags= ))) + goto cleanup; + + virshDomainCheckpointFree(checkpoint2); + vshPrintExtra(ctl, _("Checkpoint %s set as current"), checkpointna= me); + ret =3D true; + goto cleanup; + } + + if ((current =3D virDomainHasCurrentCheckpoint(dom, 0)) < 0) + goto cleanup; + + if (!current) { + vshError(ctl, _("domain '%s' has no current checkpoint"), domname); + goto cleanup; + } else { + if (!(checkpoint =3D virDomainCheckpointCurrent(dom, 0))) + goto cleanup; + + if (vshCommandOptBool(cmd, "name")) { + const char *name; + if (!(name =3D virDomainCheckpointGetName(checkpoint))) + goto cleanup; + + vshPrint(ctl, "%s", name); + } else { + if (!(xml =3D virDomainCheckpointGetXMLDesc(checkpoint, flags)= )) + goto cleanup; + + vshPrint(ctl, "%s", xml); + } + } + + ret =3D true; + + cleanup: + if (!ret) + vshReportError(ctl); + VIR_FREE(xml); + virshDomainCheckpointFree(checkpoint); + virshDomainFree(dom); + + return ret; +} + + +/* Helper function to get the name of a checkpoint's parent. Caller + * must free the result. Returns 0 on success (including when it was + * proven no parent exists), and -1 on failure with error reported + * (such as no checkpoint support or domain deleted in meantime). */ +static int +virshGetCheckpointParent(vshControl *ctl, + virDomainCheckpointPtr checkpoint, + char **parent_name) +{ + virDomainCheckpointPtr parent =3D NULL; + int ret =3D -1; + + *parent_name =3D NULL; + + parent =3D virDomainCheckpointGetParent(checkpoint, 0); + if (parent) { + /* API works, and virDomainCheckpointGetName will succeed */ + *parent_name =3D vshStrdup(ctl, virDomainCheckpointGetName(parent)= ); + ret =3D 0; + } else if (last_error->code =3D=3D VIR_ERR_NO_DOMAIN_CHECKPOINT) { + /* API works, and we found a root with no parent */ + ret =3D 0; + } + + if (ret < 0) { + vshReportError(ctl); + vshError(ctl, "%s", _("unable to determine if checkpoint has paren= t")); + } else { + vshResetLibvirtError(); + } + virshDomainCheckpointFree(parent); + return ret; +} + + +/* + * "checkpoint-info" command + */ +static const vshCmdInfo info_checkpoint_info[] =3D { + {.name =3D "help", + .data =3D N_("checkpoint information") + }, + {.name =3D "desc", + .data =3D N_("Returns basic information about a checkpoint.") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_info[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "checkpointname", + .type =3D VSH_OT_STRING, + .help =3D N_("checkpoint name"), + .completer =3D virshCheckpointNameCompleter, + }, + VIRSH_COMMON_OPT_CURRENT(N_("info on current checkpoint")), + {.name =3D NULL} +}; + + +static bool +cmdCheckpointInfo(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom; + virDomainCheckpointPtr checkpoint =3D NULL; + const char *name; + char *parent =3D NULL; + bool ret =3D false; + int count; + unsigned int flags; + int current; + int metadata; + + dom =3D virshCommandOptDomain(ctl, cmd, NULL); + if (dom =3D=3D NULL) + return false; + + if (virshLookupCheckpoint(ctl, cmd, "checkpointname", true, dom, + &checkpoint, &name) < 0) + goto cleanup; + + vshPrint(ctl, "%-15s %s\n", _("Name:"), name); + vshPrint(ctl, "%-15s %s\n", _("Domain:"), virDomainGetName(dom)); + + /* Determine if checkpoint is current. */ + current =3D virDomainCheckpointIsCurrent(checkpoint, 0); + if (current < 0) { + vshError(ctl, "%s", + _("unexpected problem querying checkpoint state")); + goto cleanup; + } + vshPrint(ctl, "%-15s %s\n", _("Current:"), + current > 0 ? _("yes") : _("no")); + + if (virshGetCheckpointParent(ctl, checkpoint, &parent) < 0) { + vshError(ctl, "%s", + _("unexpected problem querying checkpoint state")); + goto cleanup; + } + vshPrint(ctl, "%-15s %s\n", _("Parent:"), parent ? parent : "-"); + + /* Children, Descendants. */ + flags =3D 0; + count =3D virDomainCheckpointListChildren(checkpoint, NULL, flags); + if (count < 0) { + if (last_error->code =3D=3D VIR_ERR_NO_SUPPORT) { + vshResetLibvirtError(); + ret =3D true; + } + goto cleanup; + } + vshPrint(ctl, "%-15s %d\n", _("Children:"), count); + flags =3D VIR_DOMAIN_CHECKPOINT_LIST_DESCENDANTS; + count =3D virDomainCheckpointListChildren(checkpoint, NULL, flags); + if (count < 0) + goto cleanup; + vshPrint(ctl, "%-15s %d\n", _("Descendants:"), count); + + /* Metadata. */ + metadata =3D virDomainCheckpointHasMetadata(checkpoint, 0); + if (metadata >=3D 0) + vshPrint(ctl, "%-15s %s\n", _("Metadata:"), + metadata ? _("yes") : _("no")); + + ret =3D true; + + cleanup: + VIR_FREE(parent); + virshDomainCheckpointFree(checkpoint); + virshDomainFree(dom); + return ret; +} + + +/* Helpers for collecting a list of checkpoints. */ +struct virshChk { + virDomainCheckpointPtr chk; + char *parent; +}; +struct virshCheckpointList { + struct virshChk *chks; + int nchks; +}; +typedef struct virshCheckpointList *virshCheckpointListPtr; + +static void +virshCheckpointListFree(virshCheckpointListPtr chklist) +{ + size_t i; + + if (!chklist) + return; + if (chklist->chks) { + for (i =3D 0; i < chklist->nchks; i++) { + virshDomainCheckpointFree(chklist->chks[i].chk); + VIR_FREE(chklist->chks[i].parent); + } + VIR_FREE(chklist->chks); + } + VIR_FREE(chklist); +} + + +static int +virshChkSorter(const void *a, + const void *b) +{ + const struct virshChk *sa =3D a; + const struct virshChk *sb =3D b; + + if (sa->chk && !sb->chk) + return -1; + if (!sa->chk) + return sb->chk !=3D NULL; + + return vshStrcasecmp(virDomainCheckpointGetName(sa->chk), + virDomainCheckpointGetName(sb->chk)); +} + + +/* Compute a list of checkpoints from DOM. If FROM is provided, the + * list is limited to descendants of the given checkpoint. If FLAGS is + * given, the list is filtered. If TREE is specified, then all but + * FROM or the roots will also have parent information. */ +static virshCheckpointListPtr +virshCheckpointListCollect(vshControl *ctl, + virDomainPtr dom, + virDomainCheckpointPtr from, + unsigned int orig_flags, + bool tree) +{ + size_t i; + char **names =3D NULL; + int count =3D -1; + virDomainCheckpointPtr *chks; + virshCheckpointListPtr chklist =3D vshMalloc(ctl, sizeof(*chklist)); + virshCheckpointListPtr ret =3D NULL; + unsigned int flags =3D orig_flags; + + if (from) + count =3D virDomainCheckpointListChildren(from, &chks, flags); + else + count =3D virDomainListCheckpoints(dom, &chks, flags); + if (count < 0) { + vshError(ctl, "%s", + _("unexpected problem querying checkpoints")); + goto cleanup; + } + + /* When mixing --from and --tree, we also want a copy of from + * in the list, but with no parent for that one entry. */ + chklist->chks =3D vshCalloc(ctl, count + (tree && from), + sizeof(*chklist->chks)); + chklist->nchks =3D count; + for (i =3D 0; i < count; i++) + chklist->chks[i].chk =3D chks[i]; + VIR_FREE(chks); + if (tree) { + for (i =3D 0; i < count; i++) { + if (virshGetCheckpointParent(ctl, chklist->chks[i].chk, + &chklist->chks[i].parent) < 0) + goto cleanup; + } + if (from) { + chklist->chks[chklist->nchks++].chk =3D from; + virDomainCheckpointRef(from); + } + } + + qsort(chklist->chks, chklist->nchks, sizeof(*chklist->chks), + virshChkSorter); + + ret =3D chklist; + chklist =3D NULL; + + cleanup: + virshCheckpointListFree(chklist); + if (names && count > 0) + for (i =3D 0; i < count; i++) + VIR_FREE(names[i]); + VIR_FREE(names); + return ret; +} + + +static const char * +virshCheckpointListLookup(int id, + bool parent, + void *opaque) +{ + virshCheckpointListPtr chklist =3D opaque; + if (parent) + return chklist->chks[id].parent; + return virDomainCheckpointGetName(chklist->chks[id].chk); +} + + +/* + * "checkpoint-list" command + */ +static const vshCmdInfo info_checkpoint_list[] =3D { + {.name =3D "help", + .data =3D N_("List checkpoints for a domain") + }, + {.name =3D "desc", + .data =3D N_("Checkpoint List") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_list[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "parent", + .type =3D VSH_OT_BOOL, + .help =3D N_("add a column showing parent checkpoint") + }, + {.name =3D "roots", + .type =3D VSH_OT_BOOL, + .help =3D N_("list only checkpoints without parents") + }, + {.name =3D "leaves", + .type =3D VSH_OT_BOOL, + .help =3D N_("list only checkpoints without children") + }, + {.name =3D "no-leaves", + .type =3D VSH_OT_BOOL, + .help =3D N_("list only checkpoints that are not leaves (with childre= n)") + }, + {.name =3D "metadata", + .type =3D VSH_OT_BOOL, + .help =3D N_("list only checkpoints that have metadata that would pre= vent undefine") + }, + {.name =3D "no-metadata", + .type =3D VSH_OT_BOOL, + .help =3D N_("list only checkpoints that have no metadata managed by = libvirt") + }, + {.name =3D "tree", + .type =3D VSH_OT_BOOL, + .help =3D N_("list checkpoints in a tree") + }, + {.name =3D "from", + .type =3D VSH_OT_STRING, + .help =3D N_("limit list to children of given checkpoint"), + .completer =3D virshCheckpointNameCompleter, + }, + VIRSH_COMMON_OPT_CURRENT(N_("limit list to children of current checkpo= int")), + {.name =3D "descendants", + .type =3D VSH_OT_BOOL, + .help =3D N_("with --from, list all descendants") + }, + {.name =3D "name", + .type =3D VSH_OT_BOOL, + .help =3D N_("list checkpoint names only") + }, + + {.name =3D NULL} +}; + +static bool +cmdCheckpointList(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + unsigned int flags =3D 0; + size_t i; + xmlDocPtr xml =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + char *doc =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + long long creation_longlong; + time_t creation_time_t; + char timestr[100]; + struct tm time_info; + bool tree =3D vshCommandOptBool(cmd, "tree"); + bool name =3D vshCommandOptBool(cmd, "name"); + bool from =3D vshCommandOptBool(cmd, "from"); + bool parent =3D vshCommandOptBool(cmd, "parent"); + bool roots =3D vshCommandOptBool(cmd, "roots"); + bool current =3D vshCommandOptBool(cmd, "current"); + const char *from_chk =3D NULL; + char *parent_chk =3D NULL; + virDomainCheckpointPtr start =3D NULL; + virshCheckpointListPtr chklist =3D NULL; + + VSH_EXCLUSIVE_OPTIONS_VAR(tree, name); + VSH_EXCLUSIVE_OPTIONS_VAR(parent, roots); + VSH_EXCLUSIVE_OPTIONS_VAR(parent, tree); + VSH_EXCLUSIVE_OPTIONS_VAR(roots, tree); + VSH_EXCLUSIVE_OPTIONS_VAR(roots, from); + VSH_EXCLUSIVE_OPTIONS_VAR(roots, current); + +#define FILTER(option, flag) \ + do { \ + if (vshCommandOptBool(cmd, option)) { \ + if (tree) { \ + vshError(ctl, \ + _("--%s and --tree are mutually exclusive"), \ + option); \ + return false; \ + } \ + flags |=3D VIR_DOMAIN_CHECKPOINT_LIST_ ## flag; \ + } \ + } while (0) + + FILTER("leaves", LEAVES); + FILTER("no-leaves", NO_LEAVES); +#undef FILTER + + if (roots) + flags |=3D VIR_DOMAIN_CHECKPOINT_LIST_ROOTS; + + if (vshCommandOptBool(cmd, "metadata")) + flags |=3D VIR_DOMAIN_CHECKPOINT_LIST_METADATA; + + if (vshCommandOptBool(cmd, "no-metadata")) + flags |=3D VIR_DOMAIN_CHECKPOINT_LIST_NO_METADATA; + + if (vshCommandOptBool(cmd, "descendants")) { + if (!from && !current) { + vshError(ctl, "%s", + _("--descendants requires either --from or --current"= )); + return false; + } + flags |=3D VIR_DOMAIN_CHECKPOINT_LIST_DESCENDANTS; + } + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if ((from || current) && + virshLookupCheckpoint(ctl, cmd, "from", true, dom, &start, &from_c= hk) < 0) + goto cleanup; + + if (!(chklist =3D virshCheckpointListCollect(ctl, dom, start, flags, t= ree))) + goto cleanup; + + if (!tree && !name) { + if (parent) + vshPrintExtra(ctl, " %-20s %-25s %s", + _("Name"), _("Creation Time"), _("Parent")); + else + vshPrintExtra(ctl, " %-20s %-25s", + _("Name"), _("Creation Time")); + vshPrintExtra(ctl, "\n" + "------------------------------" + "--------------\n"); + } + + if (tree) { + for (i =3D 0; i < chklist->nchks; i++) { + if (!chklist->chks[i].parent && + vshTreePrint(ctl, virshCheckpointListLookup, chklist, + chklist->nchks, i) < 0) + goto cleanup; + } + ret =3D true; + goto cleanup; + } + + for (i =3D 0; i < chklist->nchks; i++) { + const char *chk_name; + + /* free up memory from previous iterations of the loop */ + VIR_FREE(parent_chk); + xmlXPathFreeContext(ctxt); + xmlFreeDoc(xml); + VIR_FREE(doc); + + checkpoint =3D chklist->chks[i].chk; + chk_name =3D virDomainCheckpointGetName(checkpoint); + assert(chk_name); + + if (name) { + /* just print the checkpoint name */ + vshPrint(ctl, "%s\n", chk_name); + continue; + } + + if (!(doc =3D virDomainCheckpointGetXMLDesc(checkpoint, 0))) + continue; + + if (!(xml =3D virXMLParseStringCtxt(doc, _("(domain_checkpoint)"),= &ctxt))) + continue; + + if (parent) + parent_chk =3D virXPathString("string(/domaincheckpoint/parent= /name)", + ctxt); + + if (virXPathLongLong("string(/domaincheckpoint/creationTime)", ctx= t, + &creation_longlong) < 0) + continue; + creation_time_t =3D creation_longlong; + if (creation_time_t !=3D creation_longlong) { + vshError(ctl, "%s", _("time_t overflow")); + continue; + } + localtime_r(&creation_time_t, &time_info); + strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S %z", + &time_info); + + if (parent) + vshPrint(ctl, " %-20s %-25s %s\n", + chk_name, timestr, parent_chk ?: "-"); + else + vshPrint(ctl, " %-20s %-25s\n", chk_name, timestr); + } + + ret =3D true; + + cleanup: + /* this frees up memory from the last iteration of the loop */ + virshCheckpointListFree(chklist); + VIR_FREE(parent_chk); + virshDomainCheckpointFree(start); + xmlXPathFreeContext(ctxt); + xmlFreeDoc(xml); + VIR_FREE(doc); + virshDomainFree(dom); + + return ret; +} + + +/* + * "checkpoint-dumpxml" command + */ +static const vshCmdInfo info_checkpoint_dumpxml[] =3D { + {.name =3D "help", + .data =3D N_("Dump XML for a domain checkpoint") + }, + {.name =3D "desc", + .data =3D N_("Checkpoint Dump XML") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_dumpxml[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "checkpointname", + .type =3D VSH_OT_DATA, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("checkpoint name"), + .completer =3D virshCheckpointNameCompleter, + }, + {.name =3D "security-info", + .type =3D VSH_OT_BOOL, + .help =3D N_("include security sensitive information in XML dump") + }, + {.name =3D "no-domain", + .type =3D VSH_OT_BOOL, + .help =3D N_("exclude from XML") + }, + {.name =3D "size", + .type =3D VSH_OT_BOOL, + .help =3D N_("include backup size estimate in XML dump") + }, + {.name =3D NULL} +}; + +static bool +cmdCheckpointDumpXML(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + const char *name =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + char *xml =3D NULL; + unsigned int flags =3D 0; + + if (vshCommandOptBool(cmd, "security-info")) + flags |=3D VIR_DOMAIN_CHECKPOINT_XML_SECURE; + if (vshCommandOptBool(cmd, "no-domain")) + flags |=3D VIR_DOMAIN_CHECKPOINT_XML_NO_DOMAIN; + if (vshCommandOptBool(cmd, "size")) + flags |=3D VIR_DOMAIN_CHECKPOINT_XML_SIZE; + + if (vshCommandOptStringReq(ctl, cmd, "checkpointname", &name) < 0) + return false; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (!(checkpoint =3D virDomainCheckpointLookupByName(dom, name, 0))) + goto cleanup; + + if (!(xml =3D virDomainCheckpointGetXMLDesc(checkpoint, flags))) + goto cleanup; + + vshPrint(ctl, "%s", xml); + ret =3D true; + + cleanup: + VIR_FREE(xml); + virshDomainCheckpointFree(checkpoint); + virshDomainFree(dom); + + return ret; +} + + +/* + * "checkpoint-parent" command + */ +static const vshCmdInfo info_checkpoint_parent[] =3D { + {.name =3D "help", + .data =3D N_("Get the name of the parent of a checkpoint") + }, + {.name =3D "desc", + .data =3D N_("Extract the checkpoint's parent, if any") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_parent[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "checkpointname", + .type =3D VSH_OT_STRING, + .help =3D N_("find parent of checkpoint name"), + .completer =3D virshCheckpointNameCompleter, + }, + VIRSH_COMMON_OPT_CURRENT(N_("find parent of current checkpoint")), + {.name =3D NULL} +}; + +static bool +cmdCheckpointParent(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + const char *name =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + char *parent =3D NULL; + + dom =3D virshCommandOptDomain(ctl, cmd, NULL); + if (dom =3D=3D NULL) + goto cleanup; + + if (virshLookupCheckpoint(ctl, cmd, "checkpointname", true, dom, + &checkpoint, &name) < 0) + goto cleanup; + + if (virshGetCheckpointParent(ctl, checkpoint, &parent) < 0) + goto cleanup; + if (!parent) { + vshError(ctl, _("checkpoint '%s' has no parent"), name); + goto cleanup; + } + + vshPrint(ctl, "%s", parent); + + ret =3D true; + + cleanup: + VIR_FREE(parent); + virshDomainCheckpointFree(checkpoint); + virshDomainFree(dom); + + return ret; +} + + +/* + * "checkpoint-delete" command + */ +static const vshCmdInfo info_checkpoint_delete[] =3D { + {.name =3D "help", + .data =3D N_("Delete a domain checkpoint") + }, + {.name =3D "desc", + .data =3D N_("Checkpoint Delete") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_delete[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "checkpointname", + .type =3D VSH_OT_STRING, + .help =3D N_("checkpoint name"), + .completer =3D virshCheckpointNameCompleter, + }, + VIRSH_COMMON_OPT_CURRENT(N_("delete current checkpoint")), + {.name =3D "children", + .type =3D VSH_OT_BOOL, + .help =3D N_("delete checkpoint and all children") + }, + {.name =3D "children-only", + .type =3D VSH_OT_BOOL, + .help =3D N_("delete children but not checkpoint") + }, + {.name =3D "metadata", + .type =3D VSH_OT_BOOL, + .help =3D N_("delete only libvirt metadata, leaving checkpoint conten= ts behind") + }, + {.name =3D NULL} +}; + +static bool +cmdCheckpointDelete(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + const char *name =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + unsigned int flags =3D 0; + + dom =3D virshCommandOptDomain(ctl, cmd, NULL); + if (dom =3D=3D NULL) + goto cleanup; + + if (virshLookupCheckpoint(ctl, cmd, "checkpointname", true, dom, + &checkpoint, &name) < 0) + goto cleanup; + + if (vshCommandOptBool(cmd, "children")) + flags |=3D VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN; + if (vshCommandOptBool(cmd, "children-only")) + flags |=3D VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY; + if (vshCommandOptBool(cmd, "metadata")) + flags |=3D VIR_DOMAIN_CHECKPOINT_DELETE_METADATA_ONLY; + + if (virDomainCheckpointDelete(checkpoint, flags) =3D=3D 0) { + if (flags & VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY) + vshPrintExtra(ctl, _("Domain checkpoint %s children deleted\n"= ), name); + else + vshPrintExtra(ctl, _("Domain checkpoint %s deleted\n"), name); + } else { + vshError(ctl, _("Failed to delete checkpoint %s"), name); + goto cleanup; + } + + ret =3D true; + + cleanup: + virshDomainCheckpointFree(checkpoint); + virshDomainFree(dom); + + return ret; +} + + +const vshCmdDef checkpointCmds[] =3D { + {.name =3D "checkpoint-create", + .handler =3D cmdCheckpointCreate, + .opts =3D opts_checkpoint_create, + .info =3D info_checkpoint_create, + .flags =3D 0 + }, + {.name =3D "checkpoint-create-as", + .handler =3D cmdCheckpointCreateAs, + .opts =3D opts_checkpoint_create_as, + .info =3D info_checkpoint_create_as, + .flags =3D 0 + }, + {.name =3D "checkpoint-current", + .handler =3D cmdCheckpointCurrent, + .opts =3D opts_checkpoint_current, + .info =3D info_checkpoint_current, + .flags =3D 0 + }, + {.name =3D "checkpoint-delete", + .handler =3D cmdCheckpointDelete, + .opts =3D opts_checkpoint_delete, + .info =3D info_checkpoint_delete, + .flags =3D 0 + }, + {.name =3D "checkpoint-dumpxml", + .handler =3D cmdCheckpointDumpXML, + .opts =3D opts_checkpoint_dumpxml, + .info =3D info_checkpoint_dumpxml, + .flags =3D 0 + }, + {.name =3D "checkpoint-edit", + .handler =3D cmdCheckpointEdit, + .opts =3D opts_checkpoint_edit, + .info =3D info_checkpoint_edit, + .flags =3D 0 + }, + {.name =3D "checkpoint-info", + .handler =3D cmdCheckpointInfo, + .opts =3D opts_checkpoint_info, + .info =3D info_checkpoint_info, + .flags =3D 0 + }, + {.name =3D "checkpoint-list", + .handler =3D cmdCheckpointList, + .opts =3D opts_checkpoint_list, + .info =3D info_checkpoint_list, + .flags =3D 0 + }, + {.name =3D "checkpoint-parent", + .handler =3D cmdCheckpointParent, + .opts =3D opts_checkpoint_parent, + .info =3D info_checkpoint_parent, + .flags =3D 0 + }, + {.name =3D NULL} +}; diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index c4adbb70d0..9c9836aadb 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -1,7 +1,7 @@ /* * virsh-completer.c: virsh completer callbacks * - * Copyright (C) 2017 Red Hat, Inc. + * Copyright (C) 2017-2018 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -623,6 +623,56 @@ virshSecretUUIDCompleter(vshControl *ctl, } +char ** +virshCheckpointNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virDomainPtr dom =3D NULL; + virDomainCheckpointPtr *checkpoints =3D NULL; + int ncheckpoints =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return NULL; + + if ((ncheckpoints =3D virDomainListCheckpoints(dom, &checkpoints, flag= s)) < 0) + goto error; + + if (VIR_ALLOC_N(ret, ncheckpoints + 1) < 0) + goto error; + + for (i =3D 0; i < ncheckpoints; i++) { + const char *name =3D virDomainCheckpointGetName(checkpoints[i]); + + if (VIR_STRDUP(ret[i], name) < 0) + goto error; + + virshDomainCheckpointFree(checkpoints[i]); + } + VIR_FREE(checkpoints); + virshDomainFree(dom); + + return ret; + + error: + for (; i < ncheckpoints; i++) + virshDomainCheckpointFree(checkpoints[i]); + VIR_FREE(checkpoints); + for (i =3D 0; i < ncheckpoints; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + virshDomainFree(dom); + return NULL; +} + char ** virshSnapshotNameCompleter(vshControl *ctl, const vshCmd *cmd, diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index ad739a9df5..505aa84929 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1,7 +1,7 @@ /* * virsh-domain-monitor.c: Commands to monitor domain status * - * Copyright (C) 2005, 2007-2016 Red Hat, Inc. + * Copyright (C) 2005-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -1614,6 +1614,7 @@ virshDomainListCollect(vshControl *ctl, unsigned int = flags) int autostart; int state; int nsnap; + int nchk; int mansave; virshControlPtr priv =3D ctl->privData; @@ -1781,6 +1782,17 @@ virshDomainListCollect(vshControl *ctl, unsigned int= flags) goto remove_entry; } + /* checkpoint filter */ + if (VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_CHECKPOINT)) { + if ((nchk =3D virDomainListCheckpoints(dom, NULL, 0)) < 0) { + vshError(ctl, "%s", _("Failed to get checkpoint count")); + goto cleanup; + } + if (!((VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT) && n= chk > 0) || + (VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT) && nc= hk =3D=3D 0))) + goto remove_entry; + } + /* the domain matched all filters, it may stay */ continue; @@ -1842,6 +1854,14 @@ static const vshCmdOptDef opts_list[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("list domains without a snapshot") }, + {.name =3D "with-checkpoint", + .type =3D VSH_OT_BOOL, + .help =3D N_("list domains with existing checkpoint") + }, + {.name =3D "without-checkpoint", + .type =3D VSH_OT_BOOL, + .help =3D N_("list domains without a checkpoint") + }, {.name =3D "state-running", .type =3D VSH_OT_BOOL, .help =3D N_("list domains in running state") @@ -1941,6 +1961,9 @@ cmdList(vshControl *ctl, const vshCmd *cmd) FILTER("with-snapshot", VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT); FILTER("without-snapshot", VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT); + FILTER("with-checkpoint", VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT); + FILTER("without-checkpoint", VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT); + FILTER("state-running", VIR_CONNECT_LIST_DOMAINS_RUNNING); FILTER("state-paused", VIR_CONNECT_LIST_DOMAINS_PAUSED); FILTER("state-shutoff", VIR_CONNECT_LIST_DOMAINS_SHUTOFF); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index ce4c6f1bad..23169f0569 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3630,6 +3630,10 @@ static const vshCmdOptDef opts_undefine[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("remove all domain snapshot metadata, if inactive") }, + {.name =3D "checkpoints-metadata", + .type =3D VSH_OT_BOOL, + .help =3D N_("remove all domain checkpoint metadata, if inactive") + }, {.name =3D "nvram", .type =3D VSH_OT_BOOL, .help =3D N_("remove nvram file, if inactive") @@ -3659,6 +3663,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) /* User-requested actions. */ bool managed_save =3D vshCommandOptBool(cmd, "managed-save"); bool snapshots_metadata =3D vshCommandOptBool(cmd, "snapshots-metadata= "); + bool checkpoints_metadata =3D vshCommandOptBool(cmd, "checkpoints-meta= data"); bool wipe_storage =3D vshCommandOptBool(cmd, "wipe-storage"); bool remove_all_storage =3D vshCommandOptBool(cmd, "remove-all-storage= "); bool delete_snapshots =3D vshCommandOptBool(cmd, "delete-snapshots"); @@ -3667,6 +3672,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) /* Positive if these items exist. */ int has_managed_save =3D 0; int has_snapshots_metadata =3D 0; + int has_checkpoints_metadata =3D 0; int has_snapshots =3D 0; /* True if undefine will not strand data, even on older servers. */ bool managed_save_safe =3D false; @@ -3713,6 +3719,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) flags |=3D VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA; snapshots_safe =3D true; } + if (checkpoints_metadata) + flags |=3D VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA; if (nvram) flags |=3D VIR_DOMAIN_UNDEFINE_NVRAM; if (keep_nvram) @@ -3761,7 +3769,12 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) managed_save_safe =3D snapshots_safe =3D true; } } + has_checkpoints_metadata + =3D virDomainListCheckpoints(dom, NULL, + VIR_DOMAIN_CHECKPOINT_LIST_METADATA= ); } + /* Clear flags which older servers might reject, if they would + * otherwise have no effect. */ if (!has_managed_save) { flags &=3D ~VIR_DOMAIN_UNDEFINE_MANAGED_SAVE; managed_save_safe =3D true; @@ -3772,6 +3785,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) flags &=3D ~VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA; snapshots_safe =3D true; } + if (has_checkpoints_metadata =3D=3D 0) + flags &=3D ~VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA; /* Stash domain description for later use */ if (vol_string || remove_all_storage) { @@ -10063,6 +10078,10 @@ static const vshCmdOptDef opts_dumpxml[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("include all domain snapshots in XML dump"), }, + {.name =3D "checkpoints", + .type =3D VSH_OT_BOOL, + .help =3D N_("include all domain checkpoints in XML dump"), + }, {.name =3D NULL} }; @@ -10078,6 +10097,7 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd) bool update =3D vshCommandOptBool(cmd, "update-cpu"); bool migratable =3D vshCommandOptBool(cmd, "migratable"); bool snapshots =3D vshCommandOptBool(cmd, "snapshots"); + bool checkpoints =3D vshCommandOptBool(cmd, "checkpoints"); if (inactive) flags |=3D VIR_DOMAIN_XML_INACTIVE; @@ -10089,6 +10109,8 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd) flags |=3D VIR_DOMAIN_XML_MIGRATABLE; if (snapshots) flags |=3D VIR_DOMAIN_XML_SNAPSHOTS; + if (checkpoints) + flags |=3D VIR_DOMAIN_XML_CHECKPOINTS; if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; diff --git a/tools/virsh-util.c b/tools/virsh-util.c index aa88397d61..933d1c825d 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -228,6 +228,17 @@ virshDomainFree(virDomainPtr dom) } +void +virshDomainCheckpointFree(virDomainCheckpointPtr chk) +{ + if (!chk) + return; + + vshSaveLibvirtHelperError(); + virDomainCheckpointFree(chk); /* sc_prohibit_obj_free_apis_in_virsh */ +} + + void virshDomainSnapshotFree(virDomainSnapshotPtr snap) { diff --git a/tools/virsh.c b/tools/virsh.c index b41304a888..0de41e33b8 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -50,6 +50,7 @@ #include "virstring.h" #include "virgettext.h" +#include "virsh-checkpoint.h" #include "virsh-console.h" #include "virsh-domain.h" #include "virsh-domain-monitor.h" @@ -832,6 +833,7 @@ static const vshCmdGrp cmdGroups[] =3D { {VIRSH_CMD_GRP_DOM_MANAGEMENT, "domain", domManagementCmds}, {VIRSH_CMD_GRP_DOM_MONITORING, "monitor", domMonitoringCmds}, {VIRSH_CMD_GRP_HOST_AND_HV, "host", hostAndHypervisorCmds}, + {VIRSH_CMD_GRP_CHECKPOINT, "checkpoint", checkpointCmds}, {VIRSH_CMD_GRP_IFACE, "interface", ifaceCmds}, {VIRSH_CMD_GRP_NWFILTER, "filter", nwfilterCmds}, {VIRSH_CMD_GRP_NETWORK, "network", networkCmds}, diff --git a/tools/virsh.pod b/tools/virsh.pod index 4d548e94ca..d70f2ecd0c 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -407,6 +407,7 @@ Inject NMI to the guest. [I<--with-managed-save>] [I<--without-managed-save>] [I<--autostart>] [I<--no-autostart>] [I<--with-snapshot>] [I<--without-snapshot>] + [I<--with-checkpoint>] [I<--without-checkpoint>] [I<--state-running>] [I<--state-paused>] [I<--state-shutoff>] [I<--state-other>] @@ -512,6 +513,11 @@ this feature disabled use I<--no-autostart>. Domains that have snapshot images can be listed using flag I<--with-snapsh= ot>, domains without a snapshot I<--without-snapshot>. +=3Ditem B + +Domains that have checkpoints can be listed using flag I<--with-checkpoint= >, +domains without a checkpoint I<--without-checkpoint>. + =3Dback When talking to older servers, this command is forced to use a series of A= PI @@ -805,7 +811,8 @@ can be restarted later. If I is transient, then the metadata of any snapshots will be lost once the guest stops running, but the snapshot contents still exist, and a new domain with the same name and UUID can restore the -snapshot metadata with B. +snapshot metadata with B. Similarly, the metadata of +any checkpoints will be lost, but can be restored with B. If I<--graceful> is specified, don't resort to extreme measures (e.g. SIGKILL) when the guest doesn't stop after a reasonable timeout; @@ -1566,7 +1573,7 @@ Convert a domain Id (or UUID) to domain name Rename a domain. This command changes current domain name to the new name specified in the second argument. -B: Domain must be inactive and without snapshots. +B: Domain must be inactive and without snapshots or checkpoints. =3Ditem B I [I<--reason>] @@ -1654,7 +1661,7 @@ is required in order to produce valid ELF file which = can be later processed by the crash utility. =3Ditem B I [I<--inactive>] [I<--security-info>] -[I<--update-cpu>] [I<--migratable>] [I<--snapshots>] +[I<--update-cpu>] [I<--migratable>] [I<--snapshots>] [I<--checkpoints>] Output the domain information as an XML dump to stdout, this format can be= used by the B command. Additional options affecting the XML dump may be @@ -1667,8 +1674,9 @@ migrations, i.e., compatible with older libvirt relea= ses and possibly amended with internal run-time options. This option may automatically enable other options (I<--update-cpu>, I<--security-info>, ...) as necessary. -Using I<--snapshots> will expand the output to also include information on -all domain snapshots, for servers that understand the flag. +Using I<--snapshots> or I<--checkpoints> will expand the output to also +include information on all domain snapshots or checkpoints respectively, +for servers that understand the flags. =3Ditem B I @@ -2804,10 +2812,11 @@ services must be shutdown in the domain. The exact behavior of a domain when it shuts down is set by the I parameter in the domain's XML definition. -If I is transient, then the metadata of any snapshots will -be lost once the guest stops running, but the snapshot contents still -exist, and a new domain with the same name and UUID can restore the -snapshot metadata with B. +If I is transient, then the metadata of any snapshots and +checkpoints will be lost once the guest stops running, but the underlying +contents still exist, and a new domain with the same name and UUID can +restore the snapshot metadata with B, and the checkpoint +metadata with B. By default the hypervisor will try to pick a suitable shutdown method. To specify an alternative method, the I<--mode> parameter @@ -2884,7 +2893,7 @@ Output the device used for the TTY console of the dom= ain. If the information is not available the processes will provide an exit code of 1. =3Ditem B I [I<--managed-save>] [I<--snapshots-metadata>] -[I<--nvram>] [I<--keep-nvram>] +[I<--checkpoints-metadata>] [I<--nvram>] [I<--keep-nvram>] [ {I<--storage> B | I<--remove-all-storage> [I<--delete-snapshots= >]} I<--wipe-storage>] @@ -2902,6 +2911,12 @@ domain. Without the flag, attempts to undefine an i= nactive domain with snapshot metadata will fail. If the domain is active, this flag is ignored. +The I<--checkpoints-metadata> flag guarantees that any checkpoints (see the +B command) are also cleaned up when undefining an inactive +domain. Without the flag, attempts to undefine an inactive domain with +checkpoint metadata will fail. If the domain is active, this flag is +ignored. + I<--nvram> and I<--keep-nvram> specify accordingly to delete or keep nvram (/domain/os/nvram/) file. If the domain has an nvram file and the flags are omitted, the undefine will fail. @@ -4854,6 +4869,211 @@ the data contents from that point in time. =3Dback +=3Dhead1 CHECKPOINT COMMANDS + +The following commands manipulate domain checkpoints. Checkpoints serve as +a point in time to identify which portions of a guest's disks have changed +after that time, making it possible to perform incremental and differential +backups. Checkpoints are identified with a unique name. See +L for documentation of the XML +format used to represent properties of checkpoints. + +=3Dover 4 + +=3Ditem B I [I] {[I<--redefine> +{[I<--current>] | [I<--redefine-list>]}] | [I<--no-metadata>] [I<--quiesce= >]} + +Create a checkpoint for domain I with the properties specified +in I describing a top-level element. If +I is completely omitted, then libvirt will create a +checkpoint with a name based on the current time. The new checkpoint +will become current, as listed by B. + +If I<--redefine> is specified, then all XML elements produced by +B are valid; this can be used to migrate +checkpoint hierarchy from one machine to another, to recreate +hierarchy for the case of a transient domain that goes away and is +later recreated with the same name and UUID, or to make slight +alterations in the checkpoint metadata (such as host-specific aspects +of the domain XML embedded in the checkpoint). When this flag is +supplied, the I argument is mandatory, and the domain's +current snapshot will not be altered unless the I<--current> flag is +also given. If I<--redefine-list> is specified, I<--redefine> is +implied, I<--current> is rejected, and the XML changes from being a +single to instead being a element +describing a list of checkpoints. List form only works if the domain +has no currently-defined checkpoint metadata, and can be obtained as a +subset of I output. + +If I<--no-metadata> is specified, then the checkpoint data is created, +but any metadata is immediately discarded (that is, libvirt does not +treat the checkpoint as current, and cannot use the checkpoint for an +incremental backup unless I<--redefine> is later used to teach libvirt +about the metadata again). + +If I<--quiesce> is specified, libvirt will try to use guest agent +to freeze and unfreeze domain's mounted file systems. However, +if domain has no guest agent, checkpoint creation will fail. + +Existence of checkpoint metadata will prevent attempts to B +a persistent domain. However, for transient domains, checkpoint +metadata is silently lost when the domain quits running (whether +by command such as B or by internal guest action). + +=3Ditem B I {[I<--print-xml>] +| [I<--no-metadata>]} [I] [I] [I<--quiesce>] +[I<--diskspec>] B]... + +Create a checkpoint for domain I with the given and +; if either value is omitted, libvirt will choose a +value. If I<--print-xml> is specified, then XML appropriate for +I is output, rather than actually creating a +checkpoint. + +The I<--diskspec> option can be used to control which guest disks particip= ate in the checkpoint. This option can occur +multiple times, according to the number of elements in the domain +xml. Each is in the +form B. A literal I<--diskspec> = must precede each B unless +all three of I, I, and I are also present. +For example, a diskspec of "vda,checkpoint=3Dbitmap,bitmap=3Dmap1" +results in the following XML: + + +If I<--quiesce> is specified, libvirt will try to use guest agent +to freeze and unfreeze domain's mounted file systems. However, +if domain has no guest agent, checkpoint creation will fail. + +If I<--no-metadata> is specified, then the checkpoint data is created, +but any metadata is immediately discarded (that is, libvirt does not +treat the checkpoint as current, and cannot use the checkpoint for an +incremental backup unless I<--redefine> is later used to teach libvirt +about the metadata again). + +=3Ditem B I {[I<--name>] | [I<--security-info>] +[I<--no-domain>] [I<--size>] | [I]} + +Without I, this will output the checkpoint XML for the +domain's current checkpoint (if any). If I<--name> is specified, +output just the current checkpoint name instead of the full xml. +Otherwise, using I<--security-info> will also include security +sensitive information in the XML, using I<--size> will add XML +indicating roughly how much guest data has changed since the +checkpoint was created, and using I<--no-domain> will omit the + element from the output for a more compact view. + +With I, this is a request to make the existing named +checkpoint become the current checkpoint. + +=3Ditem B I [I] [I<--current>] +{[I<--rename>] | [I<--clone>]} + +Edit the XML configuration file for I of a domain. If +both I and I<--current> are specified, also force the +edited checkpoint to become the current snapshot. If +I is omitted, then I<--current> must be supplied, to +edit the current checkpoint. + +This is equivalent to: + + virsh checkpoint-dumpxml dom name > checkpoint.xml + vi checkpoint.xml (or make changes with your other text editor) + virsh checkpoint-create dom checkpoint.xml --redefine [--current] + +except that it does some error checking. + +The editor used can be supplied by the C<$VISUAL> or C<$EDITOR> environment +variables, and defaults to C. + +If I<--rename> is specified, then the edits can change the checkpoint +name. If I<--clone> is specified, then changing the snapshot name +will create a clone of the checkpoint metadata. If neither is +specified, then the edits must not change the checkpoint name. Note +that changing a checkpoint name must be done with care, since some +drivers may require the original checkpoint name for actually +accessing changes since a point in time. + +=3Ditem B I {I | I<--current>} + +Output basic information about a named , or the current +checkpoint with I<--current>. + +=3Ditem B I [I<--metadata>] [I<--no-metadata>] +[{I<--parent> | I<--roots> | [{I<--tree> | I<--name>}]}] +[{[I<--from>] B | I<--current>} [I<--descendants>]] +[I<--leaves>] [I<--no-leaves>] + +List all of the available checkpoints for the given domain, defaulting +to show columns for the checkpoint name and creation time. + +If I<--parent> is specified, add a column to the output table giving +the name of the parent of each checkpoint. If I<--roots> is +specified, the list will be filtered to just checkpoints that have no +parents. If I<--tree> is specified, the output will be in a tree +format, listing just checkpoint names. These three options are +mutually exclusive. If I<--name> is specified only the checkpoint name +is printed. This option is mutually exclusive with I<--tree>. + +If I<--from> is provided, filter the list to checkpoints which are +children of the given B; or if I<--current> is provided, +start at the current checkpoint. When used in isolation or with +I<--parent>, the list is limited to direct children unless +I<--descendants> is also present. When used with I<--tree>, the use +of I<--descendants> is implied. This option is not compatible with +I<--roots>. Note that the starting point of I<--from> or I<--current> +is not included in the list unless the I<--tree> option is also +present. + +If I<--leaves> is specified, the list will be filtered to just +checkpoints that have no children. Likewise, if I<--no-leaves> is +specified, the list will be filtered to just checkpoints with +children. (Note that omitting both options does no filtering, while +providing both options will either produce the same list or error out +depending on whether the server recognizes the flags). Filtering +options are not compatible with I<--tree>. + +If I<--metadata> is specified, the list will be filtered to just +checkpoints that involve libvirt metadata, and thus would prevent +B of a persistent domain, or be lost on B of a +transient domain. Likewise, if I<--no-metadata> is specified, the +list will be filtered to just checkpoints that exist without the need +for libvirt metadata. + +=3Ditem B I I [I<--security-info>] +[I<--no-domain>] [I<--size>] + +Output the snapshot XML for the domain's checkpoint named +I. Using I<--security-info> will also include security +sensitive information, using I<--size> will add XML indicating roughly +how much guest data has changed since the checkpoint was created, and +using I<--no-domain> will omit the element from the output +for a more compact view. Use B to easily access +the XML of the current snapshot. To grab the XML for all checkpoints +at once, use B. + +=3Ditem B I {I | I<--current>} + +Output the name of the parent checkpoint, if any, for the given +I, or for the current checkpoint with I<--current>. + +=3Ditem B I {I | I<--current>} +[I<--metadata>] [{I<--children> | I<--children-only>}] + +Delete the checkpoint for the domain named I, or the +current checkpoint with I<--current>. The record of which portions of +the disk changed since the checkpoint are merged into the parent +checkpoint (if any). If I<--children> is passed, then delete this +checkpoint and any children of this checkpoint. If I<--children-only> +is passed, then delete any children of this checkpoint, but leave this +checkpoint intact. These two flags are mutually exclusive. + +If I<--metadata> is specified, then only delete the checkpoint +metadata maintained by libvirt, while leaving the checkpoint contents +intact for access by external tools; otherwise deleting a checkpoint +also removes the ability to perform an incremental backup from that +point in time. + +=3Dback + =3Dhead1 NWFILTER COMMANDS The following commands manipulate network filters. Network filters allow --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937724626261.49324598478063; Wed, 6 Mar 2019 21:48:44 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9334307D95F; Thu, 7 Mar 2019 05:48:42 +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 C2E21177F7; Thu, 7 Mar 2019 05:48:42 +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 8343D3FB15; Thu, 7 Mar 2019 05:48:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275meZL004065 for ; Thu, 7 Mar 2019 00:48:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 807395D78C; Thu, 7 Mar 2019 05:48:40 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 301D85D787; Thu, 7 Mar 2019 05:48:31 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:45 -0600 Message-Id: <20190307054752.19522-14-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 13/20] wip: backup: virsh support for backup 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: , 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 07 Mar 2019 05:48:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" --- tools/virsh-domain.c | 247 +++++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 32 ++++++ 2 files changed, 279 insertions(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 23169f0569..8a06168f6f 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -14034,6 +14034,235 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd) return ret; } + +/* + * "backup-begin" command + */ +static const vshCmdInfo info_backup_begin[] =3D { + {.name =3D "help", + .data =3D N_("Start a disk backup of a live domain") + }, + {.name =3D "desc", + .data =3D N_("Use XML to start a full or incremental disk backup of a= live " + "domain, optionally creating a checkpoint") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_backup_begin[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "xmlfile", + .type =3D VSH_OT_STRING, + .help =3D N_("domain backup XML"), + }, + {.name =3D "checkpointxml", + .type =3D VSH_OT_STRING, + .help =3D N_("domain checkpoint XML"), + }, + {.name =3D "no-metadata", + .type =3D VSH_OT_BOOL, + .help =3D N_("create checkpoint but don't track metadata"), + }, + {.name =3D "quiesce", + .type =3D VSH_OT_BOOL, + .help =3D N_("quiesce guest's file systems"), + }, + /* TODO: --wait/--verbose/--timeout flags for push model backups? */ + {.name =3D NULL} +}; + +static bool +cmdBackupBegin(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + const char *backup_from =3D NULL; + char *backup_buffer =3D NULL; + const char *check_from =3D NULL; + char *check_buffer =3D NULL; + unsigned int flags =3D 0; + int id; + + if (vshCommandOptBool(cmd, "no-metadata")) + flags |=3D VIR_DOMAIN_BACKUP_BEGIN_NO_METADATA; + if (vshCommandOptBool(cmd, "quiesce")) + flags |=3D VIR_DOMAIN_BACKUP_BEGIN_QUIESCE; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + goto cleanup; + + if (vshCommandOptStringReq(ctl, cmd, "xmlfile", &backup_from) < 0) + goto cleanup; + if (!backup_from) { + backup_buffer =3D vshStrdup(ctl, ""); + } else { + if (virFileReadAll(backup_from, VSH_MAX_XML_FILE, &backup_buffer) = < 0) { + vshSaveLibvirtError(); + goto cleanup; + } + } + + if (vshCommandOptStringReq(ctl, cmd, "checkpointxml", &check_from) < 0) + goto cleanup; + if (check_from) { + if (virFileReadAll(check_from, VSH_MAX_XML_FILE, &check_buffer) < = 0) { + vshSaveLibvirtError(); + goto cleanup; + } + } + + id =3D virDomainBackupBegin(dom, backup_buffer, check_buffer, flags); + + if (id < 0) + goto cleanup; + + vshPrint(ctl, _("Backup id %d started\n"), id); + if (backup_from) + vshPrintExtra(ctl, _("backup used description from '%s'\n"), + backup_from); + if (check_buffer) + vshPrintExtra(ctl, _("checkpoint created from '%s'\n"), check_from= ); + + ret =3D true; + + cleanup: + VIR_FREE(backup_buffer); + VIR_FREE(check_buffer); + virshDomainFree(dom); + + return ret; +} + +/* TODO: backup-begin-as? */ + +/* + * "backup-dumpxml" command + */ +static const vshCmdInfo info_backup_dumpxml[] =3D { + {.name =3D "help", + .data =3D N_("Dump XML for an ongoing domain block backup job") + }, + {.name =3D "desc", + .data =3D N_("Backup Dump XML") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_backup_dumpxml[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "id", + .type =3D VSH_OT_INT, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("backup job id"), + /* TODO: Add API for listing active jobs, then adding a completer? */ + }, + /* TODO - worth adding this flag? + {.name =3D "checkpoint", + .type =3D VSH_OT_BOOL, + .help =3D N_("if the backup created a checkpoint, also dump that XML") + }, + */ + {.name =3D NULL} +}; + +static bool +cmdBackupDumpXML(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + char *xml =3D NULL; + unsigned int flags =3D 0; + int id; + + if (vshCommandOptBool(cmd, "security-info")) + flags |=3D VIR_DOMAIN_XML_SECURE; + + if (vshCommandOptInt(ctl, cmd, "id", &id) < 0) + return false; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (!(xml =3D virDomainBackupGetXMLDesc(dom, id, flags))) + goto cleanup; + + vshPrint(ctl, "%s", xml); + ret =3D true; + + cleanup: + VIR_FREE(xml); + virshDomainFree(dom); + + return ret; +} + + +/* + * "backup-end" command + */ +static const vshCmdInfo info_backup_end[] =3D { + {.name =3D "help", + .data =3D N_("Conclude a disk backup of a live domain") + }, + {.name =3D "desc", + .data =3D N_("End a domain block backup job") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_backup_end[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "id", + .type =3D VSH_OT_INT, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("backup job id"), + /* TODO: Add API for listing active jobs, then adding a completer? */ + }, + {.name =3D "abort", + .type =3D VSH_OT_BOOL, + .help =3D N_("abandon a push model backup that has not yet completed") + }, + {.name =3D NULL} +}; + +static bool +cmdBackupEnd(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + unsigned int flags =3D 0; + int id; + int rc; + + if (vshCommandOptBool(cmd, "abort")) + flags |=3D VIR_DOMAIN_BACKUP_END_ABORT; + + if (vshCommandOptInt(ctl, cmd, "id", &id) < 0) + return false; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + goto cleanup; + + rc =3D virDomainBackupEnd(dom, id, flags); + + if (rc < 0) + goto cleanup; + if (rc =3D=3D 0) + vshPrint(ctl, _("Backup id %d aborted"), id); + else + vshPrint(ctl, _("Backup id %d completed"), id); + + ret =3D true; + + cleanup: + virshDomainFree(dom); + + return ret; +} + + const vshCmdDef domManagementCmds[] =3D { {.name =3D "attach-device", .handler =3D cmdAttachDevice, @@ -14059,6 +14288,24 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D info_autostart, .flags =3D 0 }, + {.name =3D "backup-begin", + .handler =3D cmdBackupBegin, + .opts =3D opts_backup_begin, + .info =3D info_backup_begin, + .flags =3D 0 + }, + {.name =3D "backup-dumpxml", + .handler =3D cmdBackupDumpXML, + .opts =3D opts_backup_dumpxml, + .info =3D info_backup_dumpxml, + .flags =3D 0 + }, + {.name =3D "backup-end", + .handler =3D cmdBackupEnd, + .opts =3D opts_backup_end, + .info =3D info_backup_end, + .flags =3D 0 + }, {.name =3D "blkdeviotune", .handler =3D cmdBlkdeviotune, .opts =3D opts_blkdeviotune, diff --git a/tools/virsh.pod b/tools/virsh.pod index d70f2ecd0c..2edcecec4e 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1344,6 +1344,38 @@ I specifies copying bandwidth limit in Mi= B/s. For further information on the I argument see the corresponding section for the B command. +=3Ditem B I [I] +[I [I<--no-metadata>]] [I<--quiesce>] + +Begin a new backup job, and output the resulting job id on success. If +I is omitted, this defaults to a full backup using a push +model to filenames generated by libvirt; supplying XML allows +fine-tuning such as requesting an incremental backup relative to an +earlier checkpoint, controlling which disks participate or which +filenames are involved, or requesting the use of a pull model backup. +The B command shows any resulting values assigned by +libvirt. For more information on backup XML, see: +L. + +This command returns as soon as possible, and the backup job runs in +the background; the progress of a push model backup can be checked +with B or by waiting for an event with B (the +progress of a pull model backup is under the control of whatever third +party connects to the NBD export). The job is ended with B. + +FIXME +I<--checkpointxml> +I<--no-metadata> +I<--quiesce> + +=3Ditem B I I + +FIXME + +=3Ditem B I I [I<--abort>] + +FIXME + =3Ditem B I I [[I<--config>] [I<--live>] | [I<--current>]] [[I] | [I] [I]] --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937729682527.30019937404; Wed, 6 Mar 2019 21:48:49 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A130307D966; Thu, 7 Mar 2019 05:48:48 +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 CC8C31B5BA; Thu, 7 Mar 2019 05: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 9163A3FAF5; Thu, 7 Mar 2019 05:48:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275mia5004076 for ; Thu, 7 Mar 2019 00:48:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6A04E5D78F; Thu, 7 Mar 2019 05:48:44 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2D7D5D783; Thu, 7 Mar 2019 05:48:40 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:46 -0600 Message-Id: <20190307054752.19522-15-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 14/20] backup: Add new qemu monitor interactions 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: , 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 07 Mar 2019 05:48:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Add some monitor commands to be used during backup/checkpoint operations: - another facet to query-block for learning bitmap size - new export and bitmap parameters to nbd-server-add - new block-dirty-bitmap-{add,enable,disable,merge} functions Also add two capabilities for testing that they are supported; using block-dirty-bitmap-merge as the generic witness of checkpoint support (since all of the functionalities were added in the same qemu 4.0 release), and the bitmap parameter to nbd-server-add for pull-mode backup support. Even though both capabilities are likely to be present or absent together (that is, it is unlikely to encounter a qemu that backports only one of the two), it still makes sense to keep two capabilities as the two uses are orthogonal (full backups don't require checkpoints, push mode backups don't require NBD bitmap support, and checkpoints can be used for more than just incremental backups). Signed-off-by: Eric Blake --- src/qemu/qemu_capabilities.h | 4 + src/qemu/qemu_monitor.h | 21 +- src/qemu/qemu_monitor_json.h | 19 +- src/qemu/qemu_capabilities.c | 6 + src/qemu/qemu_migration.c | 2 +- src/qemu/qemu_monitor.c | 65 +++++- src/qemu/qemu_monitor_json.c | 199 +++++++++++++++++- .../caps_4.0.0.riscv32.xml | 2 + .../caps_4.0.0.riscv64.xml | 2 + tests/qemumonitorjsontest.c | 2 +- 10 files changed, 314 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 1d677f6a06..144088ecec 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -506,6 +506,10 @@ typedef enum { /* virQEMUCapsFlags grouping marker for= syntax-check */ QEMU_CAPS_DEVICE_NVDIMM_UNARMED, /* -device nvdimm,unarmed=3D */ QEMU_CAPS_SCSI_DISK_DEVICE_ID, /* 'device_id' property of scsi disk */ QEMU_CAPS_VIRTIO_PCI_TRANSITIONAL, /* virtio *-pci-{non-}transitional = devices */ + QEMU_CAPS_BITMAP_MERGE, /* block-dirty-bitmap-merge */ + + /* 330 */ + QEMU_CAPS_NBD_BITMAP, /* nbd-server-add supports bitmap */ QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index fd7dcc9196..7eb0d067b9 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -25,6 +25,7 @@ # include "internal.h" # include "domain_conf.h" +# include "checkpoint_conf.h" # include "virbitmap.h" # include "virhash.h" # include "virjson.h" @@ -629,6 +630,9 @@ int qemuMonitorBlockStatsUpdateCapacity(qemuMonitorPtr = mon, int qemuMonitorBlockStatsUpdateCapacityBlockdev(qemuMonitorPtr mon, virHashTablePtr stats) ATTRIBUTE_NONNULL(2); +int qemuMonitorUpdateCheckpointSize(qemuMonitorPtr mon, + virDomainCheckpointDefPtr chk) + ATTRIBUTE_NONNULL(2); int qemuMonitorBlockResize(qemuMonitorPtr mon, const char *device, @@ -647,6 +651,19 @@ int qemuMonitorSetBalloon(qemuMonitorPtr mon, unsigned long long newmem); int qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, bool online); +int qemuMonitorAddBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap, bool persistent) + ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); +int qemuMonitorEnableBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap) + ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); +int qemuMonitorMergeBitmaps(qemuMonitorPtr mon, const char *node, + const char *dst, virJSONValuePtr *src) + ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4); +int qemuMonitorDeleteBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap) + ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); + /* XXX should we pass the virDomainDiskDefPtr instead * and hide dev_name details inside monitor. Reconsider @@ -1099,7 +1116,9 @@ int qemuMonitorNBDServerStart(qemuMonitorPtr mon, const char *tls_alias); int qemuMonitorNBDServerAdd(qemuMonitorPtr mon, const char *deviceID, - bool writable); + const char *export, + bool writable, + const char *bitmap); int qemuMonitorNBDServerStop(qemuMonitorPtr); int qemuMonitorGetTPMModels(qemuMonitorPtr mon, char ***tpmmodels); diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 62772228fe..076f7b6dde 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -98,6 +98,9 @@ int qemuMonitorJSONBlockResize(qemuMonitorPtr mon, const char *nodename, unsigned long long size); +int qemuMonitorJSONUpdateCheckpointSize(qemuMonitorPtr mon, + virDomainCheckpointDefPtr chk); + int qemuMonitorJSONSetVNCPassword(qemuMonitorPtr mon, const char *password); int qemuMonitorJSONSetPassword(qemuMonitorPtr mon, @@ -465,7 +468,9 @@ int qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon, const char *tls_alias); int qemuMonitorJSONNBDServerAdd(qemuMonitorPtr mon, const char *deviceID, - bool writable); + const char *export, + bool writable, + const char *bitmap); int qemuMonitorJSONNBDServerStop(qemuMonitorPtr mon); int qemuMonitorJSONGetTPMModels(qemuMonitorPtr mon, char ***tpmmodels) @@ -578,4 +583,16 @@ int qemuMonitorJSONGetPRManagerInfo(qemuMonitorPtr mon, virHashTablePtr info) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); +int qemuMonitorJSONAddBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap, bool persistent); + +int qemuMonitorJSONEnableBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap); + +int qemuMonitorJSONMergeBitmaps(qemuMonitorPtr mon, const char *node, + const char *dst, virJSONValuePtr *src); + +int qemuMonitorJSONDeleteBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap); + #endif /* LIBVIRT_QEMU_MONITOR_JSON_H */ diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index c9700193fd..e5b4daf6ee 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -523,6 +523,10 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "nvdimm.unarmed", "scsi-disk.device_id", "virtio-pci-non-transitional", + "bitmap-merge", + + /* 330 */ + "nbd-bitmap", ); @@ -978,6 +982,7 @@ struct virQEMUCapsStringFlags virQEMUCapsCommands[] =3D= { { "query-cpus-fast", QEMU_CAPS_QUERY_CPUS_FAST }, { "qom-list-properties", QEMU_CAPS_QOM_LIST_PROPERTIES }, { "blockdev-del", QEMU_CAPS_BLOCKDEV_DEL }, + { "block-dirty-bitmap-merge", QEMU_CAPS_BITMAP_MERGE }, }; struct virQEMUCapsStringFlags virQEMUCapsMigration[] =3D { @@ -1272,6 +1277,7 @@ static struct virQEMUCapsStringFlags virQEMUCapsQMPSc= hemaQueries[] =3D { { "block-commit/arg-type/*top", QEMU_CAPS_ACTIVE_COMMIT }, { "query-iothreads/ret-type/poll-max-ns", QEMU_CAPS_IOTHREAD_POLLING }, { "query-display-options/ret-type/+egl-headless/rendernode", QEMU_CAPS= _EGL_HEADLESS_RENDERNODE }, + { "nbd-server-add/arg-type/bitmap", QEMU_CAPS_NBD_BITMAP }, }; typedef struct _virQEMUCapsObjectTypeProps virQEMUCapsObjectTypeProps; diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 362b79e567..d1f6692835 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -417,7 +417,7 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr driver, goto exit_monitor; } - if (qemuMonitorNBDServerAdd(priv->mon, diskAlias, true) < 0) + if (qemuMonitorNBDServerAdd(priv->mon, diskAlias, NULL, true, NULL= ) < 0) goto exit_monitor; if (qemuDomainObjExitMonitor(driver, vm) < 0) goto cleanup; diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 8bd4d4d761..906ed50466 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2342,6 +2342,17 @@ qemuMonitorBlockStatsUpdateCapacityBlockdev(qemuMoni= torPtr mon, return qemuMonitorJSONBlockStatsUpdateCapacityBlockdev(mon, stats); } +/* Updates "chk" to fill in size of the associated bitmap */ +int qemuMonitorUpdateCheckpointSize(qemuMonitorPtr mon, + virDomainCheckpointDefPtr chk) +{ + VIR_DEBUG("chk=3D%p", chk); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONUpdateCheckpointSize(mon, chk); +} + int qemuMonitorBlockResize(qemuMonitorPtr mon, const char *device, @@ -3945,13 +3956,17 @@ qemuMonitorNBDServerStart(qemuMonitorPtr mon, int qemuMonitorNBDServerAdd(qemuMonitorPtr mon, const char *deviceID, - bool writable) + const char *export, + bool writable, + const char *bitmap) { - VIR_DEBUG("deviceID=3D%s", deviceID); + VIR_DEBUG("deviceID=3D%s, export=3D%s, bitmap=3D%s", deviceID, NULLSTR= (export), + NULLSTR(bitmap)); QEMU_CHECK_MONITOR(mon); - return qemuMonitorJSONNBDServerAdd(mon, deviceID, writable); + return qemuMonitorJSONNBDServerAdd(mon, deviceID, export, writable, + bitmap); } @@ -4478,3 +4493,47 @@ qemuMonitorGetPRManagerInfo(qemuMonitorPtr mon, virHashFree(info); return ret; } + +int +qemuMonitorAddBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap, bool persistent) +{ + VIR_DEBUG("node=3D%s bitmap=3D%s persistent=3D%d", node, bitmap, persi= stent); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONAddBitmap(mon, node, bitmap, persistent); +} + +int +qemuMonitorEnableBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap) +{ + VIR_DEBUG("node=3D%s bitmap=3D%s", node, bitmap); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONEnableBitmap(mon, node, bitmap); +} + +int +qemuMonitorMergeBitmaps(qemuMonitorPtr mon, const char *node, + const char *dst, virJSONValuePtr *src) +{ + VIR_DEBUG("node=3D%s dst=3D%s src=3D%p", node, dst, *src); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONMergeBitmaps(mon, node, dst, src); +} + +int +qemuMonitorDeleteBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap) +{ + VIR_DEBUG("node=3D%s bitmap=3D%s", node, bitmap); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONDeleteBitmap(mon, node, bitmap); +} diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index cf474eb6c8..09f37cc37b 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1011,6 +1011,8 @@ qemuMonitorJSONHandleBlockJobImpl(qemuMonitorPtr mon, type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT; else if (STREQ(type_str, "mirror")) type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COPY; + else if (STREQ(type_str, "backup")) + type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_BACKUP; switch ((virConnectDomainEventBlockJobStatus) event) { case VIR_DOMAIN_BLOCK_JOB_COMPLETED: @@ -2755,6 +2757,82 @@ int qemuMonitorJSONBlockResize(qemuMonitorPtr mon, return ret; } +int qemuMonitorJSONUpdateCheckpointSize(qemuMonitorPtr mon, + virDomainCheckpointDefPtr chk) +{ + int ret =3D -1; + size_t i, j; + virJSONValuePtr devices; + + if (!(devices =3D qemuMonitorJSONQueryBlock(mon))) + return -1; + + for (i =3D 0; i < virJSONValueArraySize(devices); i++) { + virJSONValuePtr dev =3D virJSONValueArrayGet(devices, i); + virJSONValuePtr inserted; + virJSONValuePtr bitmaps =3D NULL; + const char *node; + virDomainCheckpointDiskDefPtr disk; + + if (!(dev =3D qemuMonitorJSONGetBlockDev(devices, i))) + goto cleanup; + + if (!(inserted =3D virJSONValueObjectGetObject(dev, "inserted"))) + continue; + if (!(node =3D virJSONValueObjectGetString(inserted, "node-name"))= ) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("query-block device entry was not in expected= format")); + goto cleanup; + } + + for (j =3D 0; j < chk->ndisks; j++) { + disk =3D &chk->disks[j]; + if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) + continue; + if (STREQ(chk->dom->disks[disk->idx]->src->nodeformat, node)) + break; + } + if (j =3D=3D chk->ndisks) { + VIR_DEBUG("query-block did not find node %s", node); + continue; + } + if (!(bitmaps =3D virJSONValueObjectGetArray(dev, "dirty-bitmaps")= )) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("disk %s dirty bitmaps missing"), disk->name); + goto cleanup; + } + for (j =3D 0; j < virJSONValueArraySize(bitmaps); j++) { + virJSONValuePtr map =3D virJSONValueArrayGet(bitmaps, j); + const char *name; + + if (!(name =3D virJSONValueObjectGetString(map, "name"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("dirty bitmaps entry was not in expected form= at")); + goto cleanup; + } + if (STRNEQ(name, disk->bitmap)) + continue; + if (virJSONValueObjectGetNumberUlong(map, "count", &disk->size= ) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("invalid bitmap count")); + goto cleanup; + } + break; + } + if (j =3D=3D virJSONValueArraySize(bitmaps)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("disk %s dirty bitmap info missing"), disk->n= ame); + goto cleanup; + } + } + + ret =3D 0; + + cleanup: + virJSONValueFree(devices); + return ret; +} + int qemuMonitorJSONSetVNCPassword(qemuMonitorPtr mon, const char *password) { @@ -4738,6 +4816,8 @@ qemuMonitorJSONParseBlockJobInfo(virHashTablePtr bloc= kJobs, info->type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT; else if (STREQ(type, "mirror")) info->type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COPY; + else if (STREQ(type, "backup")) + info->type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_BACKUP; else info->type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN; @@ -6767,15 +6847,20 @@ qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon, int qemuMonitorJSONNBDServerAdd(qemuMonitorPtr mon, const char *deviceID, - bool writable) + const char *export, + bool writable, + const char *bitmap) { int ret =3D -1; virJSONValuePtr cmd; virJSONValuePtr reply =3D NULL; + /* Note: bitmap must be NULL if QEMU_CAPS_NBD_BITMAP is lacking */ if (!(cmd =3D qemuMonitorJSONMakeCommand("nbd-server-add", "s:device", deviceID, + "S:name", export, "b:writable", writable, + "S:bitmap", bitmap, NULL))) return ret; @@ -8484,3 +8569,115 @@ qemuMonitorJSONGetPRManagerInfo(qemuMonitorPtr mon, return ret; } + +int +qemuMonitorJSONAddBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap, bool persistent) +{ + int ret =3D -1; + virJSONValuePtr cmd; + virJSONValuePtr reply =3D NULL; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("block-dirty-bitmap-add", + "s:node", node, + "s:name", bitmap, + "b:persistent", persistent, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} + +int +qemuMonitorJSONEnableBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap) +{ + int ret =3D -1; + virJSONValuePtr cmd; + virJSONValuePtr reply =3D NULL; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("block-dirty-bitmap-enable", + "s:node", node, + "s:name", bitmap, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} + +int +qemuMonitorJSONMergeBitmaps(qemuMonitorPtr mon, const char *node, + const char *dst, virJSONValuePtr *src) +{ + int ret =3D -1; + virJSONValuePtr cmd; + virJSONValuePtr reply =3D NULL; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("block-dirty-bitmap-merge", + "s:node", node, + "s:target", dst, + "a:bitmaps", src, + NULL))) + goto cleanup; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virJSONValueFree(*src); + *src =3D NULL; + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} + +int +qemuMonitorJSONDeleteBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap) +{ + int ret =3D -1; + virJSONValuePtr cmd; + virJSONValuePtr reply =3D NULL; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("block-dirty-bitmap-remove", + "s:node", node, + "s:name", bitmap, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml b/tests/qemu= capabilitiesdata/caps_4.0.0.riscv32.xml index 396e3019a0..d7e51e5106 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml @@ -161,6 +161,8 @@ + + 3001050 0 0 diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml b/tests/qemu= capabilitiesdata/caps_4.0.0.riscv64.xml index addc6ae4d3..4a16a1981d 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml @@ -161,6 +161,8 @@ + + 3001050 0 0 diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 1a8a31717f..c5eac06cc1 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1354,7 +1354,7 @@ GEN_TEST_FUNC(qemuMonitorJSONDrivePivot, "vdb") GEN_TEST_FUNC(qemuMonitorJSONScreendump, "devicename", 1, "/foo/bar") GEN_TEST_FUNC(qemuMonitorJSONOpenGraphics, "spice", "spicefd", false) GEN_TEST_FUNC(qemuMonitorJSONNBDServerStart, "localhost", 12345, "test-ali= as") -GEN_TEST_FUNC(qemuMonitorJSONNBDServerAdd, "vda", true) +GEN_TEST_FUNC(qemuMonitorJSONNBDServerAdd, "vda", NULL, true, NULL) GEN_TEST_FUNC(qemuMonitorJSONDetachCharDev, "serial1") GEN_TEST_FUNC(qemuMonitorJSONBlockdevTrayOpen, "foodev", true) GEN_TEST_FUNC(qemuMonitorJSONBlockdevTrayClose, "foodev") --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937730001206.90701753364522; Wed, 6 Mar 2019 21:48:50 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 535E7318A60D; Thu, 7 Mar 2019 05:48:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 295581001E69; Thu, 7 Mar 2019 05:48:48 +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 D4D0E181A268; Thu, 7 Mar 2019 05:48:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275mjZt004086 for ; Thu, 7 Mar 2019 00:48:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id B412E5D791; Thu, 7 Mar 2019 05:48:45 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D2775D783; Thu, 7 Mar 2019 05:48:44 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:47 -0600 Message-Id: <20190307054752.19522-16-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 15/20] backup: qemu: Implement metadata tracking for checkpoint APIs 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 07 Mar 2019 05:48:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" A lot of this work heavily copies from the existing snapshot APIs. The interaction with qemu during create/delete still needs to be implemented, but this takes care of all the libvirt metadata (saving and restoring XML, and tracking the relations between multiple checkpoints). Signed-off-by: Eric Blake --- src/qemu/qemu_block.h | 3 + src/qemu/qemu_conf.h | 2 + src/qemu/qemu_domain.h | 28 +- src/qemu/qemu_block.c | 12 + src/qemu/qemu_conf.c | 5 + src/qemu/qemu_domain.c | 178 +++++++- src/qemu/qemu_driver.c | 955 ++++++++++++++++++++++++++++++++++++++++- 7 files changed, 1172 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index 9401ab4e12..fbcd019d5c 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -125,4 +125,7 @@ qemuBlockSnapshotAddLegacy(virJSONValuePtr actions, virStorageSourcePtr newsrc, bool reuse); +const char * +qemuBlockNodeLookup(virDomainObjPtr vm, const char *disk); + #endif /* LIBVIRT_QEMU_BLOCK_H */ diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 14c9d15a72..a94c229526 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -29,6 +29,7 @@ # include "capabilities.h" # include "network_conf.h" # include "domain_conf.h" +# include "checkpoint_conf.h" # include "snapshot_conf.h" # include "domain_event.h" # include "virthread.h" @@ -110,6 +111,7 @@ struct _virQEMUDriverConfig { char *cacheDir; char *saveDir; char *snapshotDir; + char *checkpointDir; char *channelTargetDir; char *nvramDir; char *swtpmStorageDir; diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 37c9813ec5..bcceaa5506 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1,7 +1,7 @@ /* * qemu_domain.h: QEMU domain private state * - * Copyright (C) 2006-2016 Red Hat, Inc. + * Copyright (C) 2006-2019 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -697,9 +697,10 @@ int qemuDomainSnapshotDiscard(virQEMUDriverPtr driver, bool update_current, bool metadata_only); -typedef struct _virQEMUSnapRemove virQEMUSnapRemove; -typedef virQEMUSnapRemove *virQEMUSnapRemovePtr; -struct _virQEMUSnapRemove { +/* Used for both snapshots and checkpoints */ +typedef struct _virQEMUDependentRemove virQEMUDependentRemove; +typedef virQEMUDependentRemove *virQEMUDependentRemovePtr; +struct _virQEMUDependentRemove { virQEMUDriverPtr driver; virDomainObjPtr vm; int err; @@ -714,6 +715,25 @@ int qemuDomainSnapshotDiscardAll(void *payload, int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver, virDomainObjPtr vm); +int qemuDomainCheckpointWriteMetadata(virDomainObjPtr vm, + virDomainCheckpointObjPtr checkpoint, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + const char *checkpointDir); + +int qemuDomainCheckpointDiscard(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainCheckpointObjPtr chk, + bool update_current, + bool metadata_only); + +int qemuDomainCheckpointDiscardAll(void *payload, + const void *name, + void *data); + +int qemuDomainCheckpointDiscardAllMetadata(virQEMUDriverPtr driver, + virDomainObjPtr vm); + void qemuDomainRemoveInactive(virQEMUDriverPtr driver, virDomainObjPtr vm); diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index cbf0aa4189..df04abeb07 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1767,3 +1767,15 @@ qemuBlockStorageGetCopyOnReadProps(virDomainDiskDefP= tr disk) return ret; } + +const char * +qemuBlockNodeLookup(virDomainObjPtr vm, const char *disk) +{ + size_t i; + + for (i =3D 0; i < vm->def->ndisks; i++) { + if (STREQ(vm->def->disks[i]->dst, disk)) + return vm->def->disks[i]->src->nodeformat; + } + return NULL; +} diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 42122dcd97..e58683f571 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -179,6 +179,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool priv= ileged) goto error; if (virAsprintf(&cfg->snapshotDir, "%s/snapshot", cfg->libDir) < 0) goto error; + if (virAsprintf(&cfg->checkpointDir, "%s/checkpoint", cfg->libDir)= < 0) + goto error; if (virAsprintf(&cfg->autoDumpPath, "%s/dump", cfg->libDir) < 0) goto error; if (virAsprintf(&cfg->channelTargetDir, @@ -242,6 +244,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool priv= ileged) goto error; if (virAsprintf(&cfg->snapshotDir, "%s/qemu/snapshot", cfg->config= BaseDir) < 0) goto error; + if (virAsprintf(&cfg->checkpointDir, "%s/qemu/checkpoint", cfg->co= nfigBaseDir) < 0) + goto error; if (virAsprintf(&cfg->autoDumpPath, "%s/qemu/dump", cfg->configBas= eDir) < 0) goto error; if (virAsprintf(&cfg->channelTargetDir, @@ -354,6 +358,7 @@ static void virQEMUDriverConfigDispose(void *obj) VIR_FREE(cfg->cacheDir); VIR_FREE(cfg->saveDir); VIR_FREE(cfg->snapshotDir); + VIR_FREE(cfg->checkpointDir); VIR_FREE(cfg->channelTargetDir); VIR_FREE(cfg->nvramDir); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e243c07168..f995721bb0 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1,7 +1,7 @@ /* * qemu_domain.c: QEMU domain private state * - * Copyright (C) 2006-2016 Red Hat, Inc. + * Copyright (C) 2006-2018 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -7728,9 +7728,10 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr driv= er, virQEMUCapsPtr qemuCaps =3D NULL; virDomainDefFormatData data =3D { 0 }; bool snapshots =3D flags & VIR_DOMAIN_XML_SNAPSHOTS; + bool checkpoints =3D flags & VIR_DOMAIN_XML_CHECKPOINTS; virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS | VIR_DOMAIN_XML_UPDATE_CPU | - VIR_DOMAIN_XML_SNAPSHOTS, -1); + VIR_DOMAIN_XML_SNAPSHOTS | VIR_DOMAIN_XML_CHECKPOINTS, -= 1); if (!(data.caps =3D virQEMUDriverGetCapabilities(driver, false))) goto cleanup; @@ -7906,6 +7907,15 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr driv= er, data.snapshots =3D vm->snapshots; data.current_snapshot =3D vm->current_snapshot; } + if (checkpoints) { + if (!vm) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("checkpoints XML requested but not provided")= ); + goto cleanup; + } + data.checkpoints =3D vm->checkpoints; + data.current_check =3D vm->current_checkpoint; + } ret =3D virDomainDefFormatInternal(buf, def, &data, virDomainDefFormatConvertXMLFlags(fla= gs), driver->xmlopt); @@ -8448,6 +8458,45 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm, return ret; } +int +qemuDomainCheckpointWriteMetadata(virDomainObjPtr vm, + virDomainCheckpointObjPtr checkpoint, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + const char *checkpointDir) +{ + char *newxml =3D NULL; + int ret =3D -1; + char *chkDir =3D NULL; + char *chkFile =3D NULL; + + newxml =3D virDomainCheckpointDefFormat( + checkpoint->def, caps, xmlopt, + virDomainDefFormatConvertXMLFlags(QEMU_DOMAIN_FORMAT_LIVE_FLAGS) | + VIR_DOMAIN_CHECKPOINT_FORMAT_INTERNAL); + if (newxml =3D=3D NULL) + return -1; + + if (virAsprintf(&chkDir, "%s/%s", checkpointDir, vm->def->name) < 0) + goto cleanup; + if (virFileMakePath(chkDir) < 0) { + virReportSystemError(errno, _("cannot create checkpoint directory = '%s'"), + chkDir); + goto cleanup; + } + + if (virAsprintf(&chkFile, "%s/%s.xml", chkDir, checkpoint->def->name) = < 0) + goto cleanup; + + ret =3D virXMLSaveFile(chkFile, NULL, "checkpoint-edit", newxml); + + cleanup: + VIR_FREE(chkFile); + VIR_FREE(chkDir); + VIR_FREE(newxml); + return ret; +} + /* The domain is expected to be locked and inactive. Return -1 on normal * failure, 1 if we skipped a disk due to try_all. */ static int @@ -8615,7 +8664,7 @@ int qemuDomainSnapshotDiscardAll(void *payload, void *data) { virDomainSnapshotObjPtr snap =3D payload; - virQEMUSnapRemovePtr curr =3D data; + virQEMUDependentRemovePtr curr =3D data; int err; if (snap->def->current) @@ -8631,7 +8680,7 @@ int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver, virDomainObjPtr vm) { - virQEMUSnapRemove rem; + virQEMUDependentRemove rem; rem.driver =3D driver; rem.vm =3D vm; @@ -8648,12 +8697,122 @@ qemuDomainSnapshotDiscardAllMetadata(virQEMUDriver= Ptr driver, } +/* Discard one checkpoint (or its metadata), without reparenting any child= ren. */ +int +qemuDomainCheckpointDiscard(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainCheckpointObjPtr chk, + bool update_parent, + bool metadata_only) +{ + char *chkFile =3D NULL; + int ret =3D -1; + virDomainCheckpointObjPtr parentchk =3D NULL; + virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); + + 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 (virAsprintf(&chkFile, "%s/%s/%s.xml", cfg->checkpointDir, + vm->def->name, chk->def->name) < 0) + 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'", + 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; + } + } + } + vm->current_checkpoint =3D parentchk; + } + + if (unlink(chkFile) < 0) + VIR_WARN("Failed to unlink %s", chkFile); + if (update_parent) + virDomainCheckpointDropParent(chk); + virDomainCheckpointObjListRemove(vm->checkpoints, chk); + + ret =3D 0; + + cleanup: + VIR_FREE(chkFile); + virObjectUnref(cfg); + return ret; +} + +/* Hash iterator callback to discard multiple checkpoints. */ +int qemuDomainCheckpointDiscardAll(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *data) +{ + virDomainCheckpointObjPtr chk =3D payload; + virQEMUDependentRemovePtr curr =3D data; + int err; + + if (chk->def->current) + curr->current =3D true; + err =3D qemuDomainCheckpointDiscard(curr->driver, curr->vm, chk, false, + curr->metadata_only); + if (err && !curr->err) + curr->err =3D err; + return 0; +} + + +int +qemuDomainCheckpointDiscardAllMetadata(virQEMUDriverPtr driver, + virDomainObjPtr vm) +{ + virQEMUDependentRemove rem; + + rem.driver =3D driver; + rem.vm =3D vm; + rem.metadata_only =3D true; + rem.err =3D 0; + virDomainCheckpointForEach(vm->checkpoints, qemuDomainCheckpointDiscar= dAll, + &rem); + if (rem.current) + vm->current_checkpoint =3D NULL; + if (virDomainCheckpointUpdateRelations(vm->checkpoints) < 0 && !rem.er= r) + rem.err =3D -1; + + return rem.err; +} + + static void qemuDomainRemoveInactiveCommon(virQEMUDriverPtr driver, virDomainObjPtr vm) { virQEMUDriverConfigPtr cfg; VIR_AUTOFREE(char *) snapDir =3D NULL; + VIR_AUTOFREE(char *) chkDir =3D NULL; cfg =3D virQEMUDriverGetConfig(driver); @@ -8668,6 +8827,17 @@ qemuDomainRemoveInactiveCommon(virQEMUDriverPtr driv= er, } else if (rmdir(snapDir) < 0 && errno !=3D ENOENT) { VIR_WARN("unable to remove snapshot directory %s", snapDir); } + /* Remove any checkpoint metadata prior to removing the domain */ + if (qemuDomainCheckpointDiscardAllMetadata(driver, vm) < 0) { + VIR_WARN("unable to remove all checkpoints for domain %s", + vm->def->name); + } else if (virAsprintf(&chkDir, "%s/%s", cfg->checkpointDir, + vm->def->name) < 0) { + VIR_WARN("unable to remove checkpoint directory %s/%s", + cfg->checkpointDir, vm->def->name); + } else if (rmdir(chkDir) < 0 && errno !=3D ENOENT) { + VIR_WARN("unable to remove snapshot directory %s", chkDir); + } qemuExtDevicesCleanupHost(driver, vm->def); virObjectUnref(cfg); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 55fcb3ba5a..76a62d2d76 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1,7 +1,7 @@ /* * qemu_driver.c: core driver methods for managing qemu guests * - * Copyright (C) 2006-2016 Red Hat, Inc. + * Copyright (C) 2006-2019 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -220,6 +220,40 @@ qemuSnapObjFromSnapshot(virDomainObjPtr vm, return qemuSnapObjFromName(vm, snapshot->name); } +/* Looks up the domain object from checkpoint and unlocks the + * driver. The returned domain object is locked and ref'd and the + * caller must call virDomainObjEndAPI() on it. */ +static virDomainObjPtr +qemuDomObjFromCheckpoint(virDomainCheckpointPtr checkpoint) +{ + return qemuDomObjFromDomain(checkpoint->domain); +} + + +/* Looks up checkpoint object from VM and name */ +static virDomainCheckpointObjPtr +qemuCheckObjFromName(virDomainObjPtr vm, + const char *name) +{ + virDomainCheckpointObjPtr chk =3D NULL; + chk =3D virDomainCheckpointFindByName(vm->checkpoints, name); + if (!chk) + virReportError(VIR_ERR_NO_DOMAIN_CHECKPOINT, + _("no domain checkpoint with matching name '%s'"), + name); + + return chk; +} + + +/* Looks up checkpoint object from VM and checkpointPtr */ +static virDomainCheckpointObjPtr +qemuCheckObjFromCheckpoint(virDomainObjPtr vm, + virDomainCheckpointPtr checkpoint) +{ + return qemuCheckObjFromName(vm, checkpoint->name); +} + static int qemuAutostartDomain(virDomainObjPtr vm, void *opaque) @@ -526,6 +560,127 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm, } +static int +qemuDomainCheckpointLoad(virDomainObjPtr vm, + void *data) +{ + char *baseDir =3D (char *)data; + char *chkDir =3D NULL; + DIR *dir =3D NULL; + struct dirent *entry; + char *xmlStr; + char *fullpath; + virDomainCheckpointDefPtr def =3D NULL; + virDomainCheckpointObjPtr chk =3D NULL; + virDomainCheckpointObjPtr current =3D NULL; + unsigned int flags =3D (VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE | + VIR_DOMAIN_CHECKPOINT_PARSE_DISKS | + VIR_DOMAIN_CHECKPOINT_PARSE_INTERNAL); + int ret =3D -1; + virCapsPtr caps =3D NULL; + int direrr; + + virObjectLock(vm); + if (virAsprintf(&chkDir, "%s/%s", baseDir, vm->def->name) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to allocate memory for " + "checkpoint directory for domain %s"), + vm->def->name); + goto cleanup; + } + + if (!(caps =3D virQEMUDriverGetCapabilities(qemu_driver, false))) + goto cleanup; + + VIR_INFO("Scanning for checkpoints for domain %s in %s", vm->def->name, + chkDir); + + if (virDirOpenIfExists(&dir, chkDir) <=3D 0) + goto cleanup; + + while ((direrr =3D virDirRead(dir, &entry, NULL)) > 0) { + /* NB: ignoring errors, so one malformed config doesn't + kill the whole process */ + VIR_INFO("Loading checkpoint file '%s'", entry->d_name); + + if (virAsprintf(&fullpath, "%s/%s", chkDir, entry->d_name) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Failed to allocate memory for path")); + continue; + } + + if (virFileReadAll(fullpath, 1024*1024*1, &xmlStr) < 0) { + /* Nothing we can do here, skip this one */ + virReportSystemError(errno, + _("Failed to read checkpoint file %s"), + fullpath); + VIR_FREE(fullpath); + continue; + } + + def =3D virDomainCheckpointDefParseString(xmlStr, caps, + qemu_driver->xmlopt, + flags); + if (!def || virDomainCheckpointAlignDisks(def) < 0) { + /* Nothing we can do here, skip this one */ + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to parse checkpoint XML from file '%s= '"), + fullpath); + VIR_FREE(fullpath); + VIR_FREE(xmlStr); + continue; + } + + chk =3D virDomainCheckpointAssignDef(vm->checkpoints, def); + if (chk =3D=3D NULL) { + virDomainCheckpointDefFree(def); + } else if (chk->def->current) { + current =3D chk; + if (!vm->current_checkpoint) + vm->current_checkpoint =3D chk; + } + + VIR_FREE(fullpath); + VIR_FREE(xmlStr); + } + if (direrr < 0) + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to fully read directory %s"), + chkDir); + + if (vm->current_checkpoint !=3D current) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Too many checkpoints claiming to be current for = domain %s"), + vm->def->name); + vm->current_checkpoint =3D NULL; + } + + if (virDomainCheckpointUpdateRelations(vm->checkpoints) < 0) + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Checkpoints have inconsistent relations for doma= in %s"), + vm->def->name); + + /* FIXME: qemu keeps internal track of bitmaps, which form the + * basis for checkpoints; it would be nice if we could update our + * internal state to reflect that information automatically. But + * qemu 3.0 did not have access to this via qemu-img for offline + * images (you have to use QMP commands on a running guest), and + * it also does not track relations which we find + * important in our metadata. + */ + + virResetLastError(); + + ret =3D 0; + cleanup: + VIR_DIR_CLOSE(dir); + VIR_FREE(chkDir); + virObjectUnref(caps); + virObjectUnlock(vm); + return ret; +} + + static int qemuDomainNetsRestart(virDomainObjPtr vm, void *data ATTRIBUTE_UNUSED) @@ -656,6 +811,11 @@ qemuStateInitialize(bool privileged, cfg->snapshotDir); goto error; } + if (virFileMakePath(cfg->checkpointDir) < 0) { + virReportSystemError(errno, _("Failed to create checkpoint dir %s"= ), + cfg->checkpointDir); + goto error; + } if (virFileMakePath(cfg->autoDumpPath) < 0) { virReportSystemError(errno, _("Failed to create dump dir %s"), cfg->autoDumpPath); @@ -763,6 +923,13 @@ qemuStateInitialize(bool privileged, (int)cfg->group); goto error; } + if (chown(cfg->checkpointDir, cfg->user, cfg->group) < 0) { + virReportSystemError(errno, + _("unable to set ownership of '%s' to %d:= %d"), + cfg->checkpointDir, (int)cfg->user, + (int)cfg->group); + goto error; + } if (chown(cfg->autoDumpPath, cfg->user, cfg->group) < 0) { virReportSystemError(errno, _("unable to set ownership of '%s' to %d:= %d"), @@ -901,6 +1068,10 @@ qemuStateInitialize(bool privileged, qemuDomainSnapshotLoad, cfg->snapshotDir); + virDomainObjListForEach(qemu_driver->domains, + qemuDomainCheckpointLoad, + cfg->checkpointDir); + virDomainObjListForEach(qemu_driver->domains, qemuDomainManagedSaveLoad, qemu_driver); @@ -7330,7 +7501,7 @@ static char char *ret =3D NULL; virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS | VIR_DOMAIN_XML_UPDATE_CPU | - VIR_DOMAIN_XML_SNAPSHOTS, NULL); + VIR_DOMAIN_XML_SNAPSHOTS | VIR_DOMAIN_XML_CHECKPOINTS, N= ULL); if (!(vm =3D qemuDomObjFromDomain(dom))) goto cleanup; @@ -7789,6 +7960,7 @@ qemuDomainUndefineFlags(virDomainPtr dom, if (qemuDomainSnapshotDiscardAllMetadata(driver, vm) < 0) goto endjob; } + /* TODO: Restrict deletion if checkpoints exist? */ name =3D qemuDomainManagedSavePath(driver, vm); if (name =3D=3D NULL) @@ -16887,7 +17059,7 @@ qemuDomainSnapshotDelete(virDomainSnapshotPtr snaps= hot, virDomainObjPtr vm =3D NULL; int ret =3D -1; virDomainSnapshotObjPtr snap =3D NULL; - virQEMUSnapRemove rem; + virQEMUDependentRemove rem; virQEMUSnapReparent rep; bool metadata_only =3D !!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_= ONLY); int external =3D 0; @@ -16991,6 +17163,755 @@ qemuDomainSnapshotDelete(virDomainSnapshotPtr sna= pshot, return ret; } + +/* Called prior to job lock */ +static virDomainCheckpointDefPtr +qemuDomainCheckpointDefParseString(virQEMUDriverPtr driver, virCapsPtr cap= s, + const char *xmlDesc, unsigned int flags) +{ + virDomainCheckpointDefPtr def =3D NULL; + virDomainCheckpointDefPtr ret =3D NULL; + unsigned int parse_flags =3D VIR_DOMAIN_CHECKPOINT_PARSE_DISKS; + + if (flags & VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE) + parse_flags |=3D VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE; + if (!(def =3D virDomainCheckpointDefParseString(xmlDesc, caps, driver-= >xmlopt, + parse_flags))) + goto cleanup; + + /* reject checkpoint names containing slashes or starting with dot as + * checkpoint definitions are saved in files named by the checkpoint n= ame */ + if (!(flags & VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA)) { + if (strchr(def->name, '/')) { + virReportError(VIR_ERR_XML_DETAIL, + _("invalid checkpoint name '%s': " + "name can't contain '/'"), + def->name); + goto cleanup; + } + + if (def->name[0] =3D=3D '.') { + virReportError(VIR_ERR_XML_DETAIL, + _("invalid checkpoint name '%s': " + "name can't start with '.'"), + def->name); + goto cleanup; + } + } + + VIR_STEAL_PTR(ret, def); + + cleanup: + virDomainCheckpointDefFree(def); + return ret; +} + + +/* Called inside job lock */ +static int +qemuDomainCheckpointPrepare(virQEMUDriverPtr driver, virCapsPtr caps, + virDomainObjPtr vm, + virDomainCheckpointDefPtr def) +{ + int ret =3D -1; + size_t i; + char *xml =3D NULL; + qemuDomainObjPrivatePtr priv =3D vm->privateData; + + /* Easiest way to clone inactive portion of vm->def is via + * conversion in and back out of xml. */ + if (!(xml =3D qemuDomainDefFormatLive(driver, vm->def, priv->origCPU, + true, true)) || + !(def->dom =3D virDomainDefParseString(xml, caps, driver->xmlopt, = NULL, + VIR_DOMAIN_DEF_PARSE_INACTIVE= | + VIR_DOMAIN_DEF_PARSE_SKIP_VAL= IDATE))) + goto cleanup; + + if (virDomainCheckpointAlignDisks(def) < 0 || + qemuBlockNodeNamesDetect(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) + goto cleanup; + + for (i =3D 0; i < def->ndisks; i++) { + virDomainCheckpointDiskDefPtr disk =3D &def->disks[i]; + + if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) + continue; + + if (vm->def->disks[i]->src->format > 0 && + vm->def->disks[i]->src->format !=3D VIR_STORAGE_FILE_QCOW2) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("checkpoint for disk %s unsupported " + "for storage type %s"), + disk->name, + virStorageFileFormatTypeToString( + vm->def->disks[i]->src->format)); + goto cleanup; + } + } + + ret =3D 0; + + cleanup: + VIR_FREE(xml); + return ret; +} + + + +/* Struct and hash-iterator callback used when bulk redefining checkpoints= */ +struct qemuDomainCheckpointBulk { + virDomainObjPtr vm; + virQEMUDriverPtr driver; + const char *checkpointDir; + unsigned int flags; +}; + +static int +qemuDomainCheckpointBulkRedefine(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) +{ + virDomainCheckpointObjPtr chk =3D payload; + struct qemuDomainCheckpointBulk *data =3D opaque; + + return qemuDomainCheckpointWriteMetadata(data->vm, chk, data->driver->= caps, + data->driver->xmlopt, + data->checkpointDir); +} + + +static virDomainCheckpointPtr +qemuDomainCheckpointCreateXML(virDomainPtr domain, + const char *xmlDesc, + unsigned int flags) +{ + virQEMUDriverPtr driver =3D domain->conn->privateData; + virDomainObjPtr vm =3D NULL; + char *xml =3D NULL; + virDomainCheckpointObjPtr chk =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + virDomainCheckpointDefPtr def =3D NULL; + bool update_current =3D true; + bool redefine =3D flags & VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE; + unsigned int parse_flags =3D VIR_DOMAIN_CHECKPOINT_PARSE_DISKS; + virDomainCheckpointObjPtr other =3D NULL; + virQEMUDriverConfigPtr cfg =3D NULL; + virCapsPtr caps =3D NULL; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE | + VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT | + VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA | + VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE_LIST, NULL); + /* TODO: VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE */ + + if (redefine) + parse_flags |=3D VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE; + if ((redefine && !(flags & VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT)) || + (flags & VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA)) + update_current =3D false; + + if (!(vm =3D qemuDomObjFromDomain(domain))) + goto cleanup; + + cfg =3D virQEMUDriverGetConfig(driver); + + if (virDomainCheckpointCreateXMLEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + if (!(caps =3D virQEMUDriverGetCapabilities(driver, false))) + goto cleanup; + + if (qemuProcessAutoDestroyActive(driver, vm)) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("domain is marked for auto destroy")); + goto cleanup; + } + + if (!virDomainObjIsActive(vm)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot create checkpoint for inactive domain")); + goto cleanup; + } + + if (flags & VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE_LIST) { + struct qemuDomainCheckpointBulk bulk =3D { + .vm =3D vm, + .driver =3D driver, + .checkpointDir =3D cfg->checkpointDir, + .flags =3D flags, + }; + + if (virDomainCheckpointObjListParse(xmlDesc, vm->def->uuid, + vm->checkpoints, + &vm->current_checkpoint, + caps, driver->xmlopt, + parse_flags) < 0) + goto cleanup; + /* Validate and save the checkpoints to disk. Since we don't get + * here unless there were no checkpoints beforehand, just delete + * everything if anything failed, ignoring further errors. */ + if (virDomainCheckpointForEach(vm->checkpoints, + qemuDomainCheckpointBulkRedefine, + &bulk) < 0) { + virErrorPtr orig_err =3D virSaveLastError(); + + qemuDomainCheckpointDiscardAllMetadata(driver, vm); + virSetError(orig_err); + virFreeError(orig_err); + goto cleanup; + } + /* Return is arbitrary, so use the first root */ + chk =3D virDomainCheckpointFindByName(vm->checkpoints, NULL); + checkpoint =3D virGetDomainCheckpoint(domain, + chk->first_child->def->name); + goto cleanup; + } + + if (!(def =3D qemuDomainCheckpointDefParseString(driver, caps, xmlDesc, + parse_flags))) + goto cleanup; + + /* We are going to modify the domain below. */ + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + goto cleanup; + + if (redefine) { + if (virDomainCheckpointRedefinePrep(domain, vm, &def, &chk, + driver->xmlopt, + &update_current) < 0) + goto endjob; + } else if (qemuDomainCheckpointPrepare(driver, caps, vm, def) < 0) { + goto endjob; + } + + if (!chk) { + if (!(chk =3D virDomainCheckpointAssignDef(vm->checkpoints, def))) + goto endjob; + + def =3D NULL; + } + + if (update_current) + chk->def->current =3D true; + if (vm->current_checkpoint) { + if (!redefine && + VIR_STRDUP(chk->def->parent, vm->current_checkpoint->def->name= ) < 0) + goto endjob; + if (update_current) { + vm->current_checkpoint->def->current =3D false; + if (qemuDomainCheckpointWriteMetadata(vm, vm->current_checkpoi= nt, + driver->caps, driver->xm= lopt, + cfg->checkpointDir) < 0) + goto endjob; + vm->current_checkpoint =3D NULL; + } + } + + /* actually do the checkpoint */ + if (redefine) { + /* XXX Should we validate that the redefined checkpoint even + * 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 we fail after this point, there's not a whole lot we can do; + * we've successfully created the checkpoint, so we have to go + * forward the best we can. + */ + checkpoint =3D virGetDomainCheckpoint(domain, chk->def->name); + + endjob: + if (checkpoint && !(flags & VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA))= { + if (qemuDomainCheckpointWriteMetadata(vm, chk, driver->caps, + driver->xmlopt, + cfg->checkpointDir) < 0) { + /* if writing of metadata fails, error out rather than trying + * to silently carry on without completing the checkpoint */ + virObjectUnref(checkpoint); + checkpoint =3D NULL; + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unable to save metadata for checkpoint %s"), + chk->def->name); + virDomainCheckpointObjListRemove(vm->checkpoints, chk); + } else { + if (update_current) + vm->current_checkpoint =3D chk; + other =3D virDomainCheckpointFindByName(vm->checkpoints, + chk->def->parent); + chk->parent =3D other; + other->nchildren++; + chk->sibling =3D other->first_child; + other->first_child =3D chk; + } + } else if (chk) { + virDomainCheckpointObjListRemove(vm->checkpoints, chk); + } + + qemuDomainObjEndJob(driver, vm); + + cleanup: + virDomainObjEndAPI(&vm); + virDomainCheckpointDefFree(def); + VIR_FREE(xml); + virObjectUnref(caps); + virObjectUnref(cfg); + return checkpoint; +} + + +static int +qemuDomainListCheckpoints(virDomainPtr domain, + virDomainCheckpointPtr **chks, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + int n =3D -1; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_LIST_ROOTS | + VIR_DOMAIN_CHECKPOINT_FILTERS_ALL, -1); + + if (!(vm =3D qemuDomObjFromDomain(domain))) + return -1; + + if (virDomainListCheckpointsEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + n =3D virDomainListAllCheckpoints(vm->checkpoints, NULL, domain, chks,= flags); + + cleanup: + virDomainObjEndAPI(&vm); + return n; +} + + +static int +qemuDomainCheckpointListChildren(virDomainCheckpointPtr checkpoint, + virDomainCheckpointPtr **chks, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + virDomainCheckpointObjPtr chk =3D NULL; + int n =3D -1; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_LIST_DESCENDANTS | + VIR_DOMAIN_CHECKPOINT_FILTERS_ALL, -1); + + if (!(vm =3D qemuDomObjFromCheckpoint(checkpoint))) + return -1; + + if (virDomainCheckpointListChildrenEnsureACL(checkpoint->domain->conn,= vm->def) < 0) + goto cleanup; + + if (!(chk =3D qemuCheckObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + + n =3D virDomainListAllCheckpoints(vm->checkpoints, chk, checkpoint->do= main, chks, flags); + + cleanup: + virDomainObjEndAPI(&vm); + return n; +} + + +static virDomainCheckpointPtr +qemuDomainCheckpointLookupByName(virDomainPtr domain, + const char *name, + unsigned int flags) +{ + virDomainObjPtr vm; + virDomainCheckpointObjPtr chk =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + + virCheckFlags(0, NULL); + + if (!(vm =3D qemuDomObjFromDomain(domain))) + return NULL; + + if (virDomainCheckpointLookupByNameEnsureACL(domain->conn, vm->def) < = 0) + goto cleanup; + + if (!(chk =3D qemuCheckObjFromName(vm, name))) + goto cleanup; + + checkpoint =3D virGetDomainCheckpoint(domain, chk->def->name); + + cleanup: + virDomainObjEndAPI(&vm); + return checkpoint; +} + + +static int +qemuDomainHasCurrentCheckpoint(virDomainPtr domain, + unsigned int flags) +{ + virDomainObjPtr vm; + int ret =3D -1; + + virCheckFlags(0, -1); + + if (!(vm =3D qemuDomObjFromDomain(domain))) + return -1; + + if (virDomainHasCurrentCheckpointEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + ret =3D (vm->current_checkpoint !=3D NULL); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + +static virDomainCheckpointPtr +qemuDomainCheckpointGetParent(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virDomainObjPtr vm; + virDomainCheckpointObjPtr chk =3D NULL; + virDomainCheckpointPtr parent =3D NULL; + + virCheckFlags(0, NULL); + + if (!(vm =3D qemuDomObjFromCheckpoint(checkpoint))) + return NULL; + + if (virDomainCheckpointGetParentEnsureACL(checkpoint->domain->conn, vm= ->def) < 0) + goto cleanup; + + if (!(chk =3D qemuCheckObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + + if (!chk->def->parent) { + virReportError(VIR_ERR_NO_DOMAIN_CHECKPOINT, + _("checkpoint '%s' does not have a parent"), + chk->def->name); + goto cleanup; + } + + parent =3D virGetDomainCheckpoint(checkpoint->domain, chk->def->parent= ); + + cleanup: + virDomainObjEndAPI(&vm); + return parent; +} + + +static virDomainCheckpointPtr +qemuDomainCheckpointCurrent(virDomainPtr domain, + unsigned int flags) +{ + virDomainObjPtr vm; + virDomainCheckpointPtr checkpoint =3D NULL; + + virCheckFlags(0, NULL); + + if (!(vm =3D qemuDomObjFromDomain(domain))) + return NULL; + + if (virDomainCheckpointCurrentEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + if (!vm->current_checkpoint) { + virReportError(VIR_ERR_NO_DOMAIN_CHECKPOINT, "%s", + _("the domain does not have a current checkpoint")); + goto cleanup; + } + + checkpoint =3D virGetDomainCheckpoint(domain, vm->current_checkpoint->= def->name); + + cleanup: + virDomainObjEndAPI(&vm); + return checkpoint; +} + + +static char * +qemuDomainCheckpointGetXMLDesc(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virQEMUDriverPtr driver =3D checkpoint->domain->conn->privateData; + virDomainObjPtr vm =3D NULL; + char *xml =3D NULL; + virDomainCheckpointObjPtr chk =3D NULL; + qemuDomainObjPrivatePtr priv; + int rc; + size_t i; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_XML_SECURE | + VIR_DOMAIN_CHECKPOINT_XML_NO_DOMAIN | + VIR_DOMAIN_CHECKPOINT_XML_SIZE, NULL); + + if (!(vm =3D qemuDomObjFromCheckpoint(checkpoint))) + return NULL; + + if (virDomainCheckpointGetXMLDescEnsureACL(checkpoint->domain->conn, v= m->def, flags) < 0) + goto cleanup; + + if (!(chk =3D qemuCheckObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + + if (flags & VIR_DOMAIN_CHECKPOINT_XML_SIZE) { + /* TODO: for non-current checkpoint, this requires a QMP sequence = per + disk, since the stat of one bitmap in isolation is too low, + and merely adding bitmap sizes may be too high: + block-dirty-bitmap-create tmp + for each bitmap from checkpoint to current: + add bitmap to src_list + block-dirty-bitmap-merge dst=3Dtmp src_list + query-block and read tmp size + block-dirty-bitmap-remove tmp + So for now, go with simpler query-blocks only for current. + */ + if (!vm->current_checkpoint || + STRNEQ(checkpoint->name, vm->current_checkpoint->def->name)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("cannot compute size for non-current checkpoi= nt '%s'"), + checkpoint->name); + goto cleanup; + } + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto endjob; + + if (qemuBlockNodeNamesDetect(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) + goto endjob; + + /* TODO: Shouldn't need to recompute node names. */ + 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; + VIR_FREE(chk->def->dom->disks[disk->idx]->src->nodeformat); + if (VIR_STRDUP(chk->def->dom->disks[disk->idx]->src->nodeforma= t, + qemuBlockNodeLookup(vm, disk->name)) < 0) + goto endjob; + } + + priv =3D vm->privateData; + qemuDomainObjEnterMonitor(driver, vm); + rc =3D qemuMonitorUpdateCheckpointSize(priv->mon, chk->def); + if (qemuDomainObjExitMonitor(driver, vm) < 0) + goto endjob; + if (rc < 0) + goto endjob; + } + + xml =3D virDomainCheckpointDefFormat(chk->def, driver->caps, driver->x= mlopt, + flags); + + endjob: + if (flags & VIR_DOMAIN_CHECKPOINT_XML_SIZE) + qemuDomainObjEndJob(driver, vm); + + cleanup: + virDomainObjEndAPI(&vm); + return xml; +} + + +static int +qemuDomainCheckpointIsCurrent(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + int ret =3D -1; + virDomainCheckpointObjPtr chk =3D NULL; + + virCheckFlags(0, -1); + + if (!(vm =3D qemuDomObjFromCheckpoint(checkpoint))) + return -1; + + if (virDomainCheckpointIsCurrentEnsureACL(checkpoint->domain->conn, vm= ->def) < 0) + goto cleanup; + + if (!(chk =3D qemuCheckObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + + ret =3D (vm->current_checkpoint && + STREQ(checkpoint->name, vm->current_checkpoint->def->name)); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + +static int +qemuDomainCheckpointHasMetadata(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + int ret =3D -1; + virDomainCheckpointObjPtr chk =3D NULL; + + virCheckFlags(0, -1); + + if (!(vm =3D qemuDomObjFromCheckpoint(checkpoint))) + return -1; + + if (virDomainCheckpointHasMetadataEnsureACL(checkpoint->domain->conn, = vm->def) < 0) + goto cleanup; + + if (!(chk =3D qemuCheckObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + + /* XXX Someday, we should recognize internal bitmaps in qcow2 + * images that are not tied to a libvirt checkpoint; if we ever do + * that, then we would have a reason to return 0 here. */ + ret =3D 1; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + +typedef struct _virQEMUCheckReparent virQEMUCheckReparent; +typedef virQEMUCheckReparent *virQEMUCheckReparentPtr; +struct _virQEMUCheckReparent { + virQEMUDriverConfigPtr cfg; + virDomainCheckpointObjPtr parent; + virDomainObjPtr vm; + virCapsPtr caps; + virDomainXMLOptionPtr xmlopt; + int err; + virDomainCheckpointObjPtr last; +}; + + +static int +qemuDomainCheckpointReparentChildren(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *data) +{ + virDomainCheckpointObjPtr chk =3D payload; + virQEMUCheckReparentPtr rep =3D data; + + if (rep->err < 0) + return 0; + + VIR_FREE(chk->def->parent); + chk->parent =3D rep->parent; + + if (rep->parent->def && + VIR_STRDUP(chk->def->parent, rep->parent->def->name) < 0) { + rep->err =3D -1; + return 0; + } + + if (!chk->sibling) + rep->last =3D chk; + + rep->err =3D qemuDomainCheckpointWriteMetadata(rep->vm, chk, + rep->caps, rep->xmlopt, + rep->cfg->checkpointDir); + return 0; +} + + +static int +qemuDomainCheckpointDelete(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virQEMUDriverPtr driver =3D checkpoint->domain->conn->privateData; + virDomainObjPtr vm =3D NULL; + int ret =3D -1; + virDomainCheckpointObjPtr chk =3D NULL; + virQEMUDependentRemove rem; + virQEMUCheckReparent rep; + bool metadata_only =3D !!(flags & VIR_DOMAIN_CHECKPOINT_DELETE_METADAT= A_ONLY); + virQEMUDriverConfigPtr cfg =3D NULL; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN | + VIR_DOMAIN_CHECKPOINT_DELETE_METADATA_ONLY | + VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY, -1); + + if (!(vm =3D qemuDomObjFromCheckpoint(checkpoint))) + return -1; + + cfg =3D virQEMUDriverGetConfig(driver); + + if (virDomainCheckpointDeleteEnsureACL(checkpoint->domain->conn, vm->d= ef) < 0) + goto cleanup; + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + goto cleanup; + + if (!(chk =3D qemuCheckObjFromCheckpoint(vm, checkpoint))) + goto endjob; + + if (flags & (VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN | + VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY)) { + rem.driver =3D driver; + rem.vm =3D vm; + rem.metadata_only =3D metadata_only; + rem.err =3D 0; + rem.current =3D false; + virDomainCheckpointForEachDescendant(chk, + qemuDomainCheckpointDiscardAl= l, + &rem); + if (rem.err < 0) + goto endjob; + if (rem.current) { + if (flags & VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY) { + chk->def->current =3D true; + if (qemuDomainCheckpointWriteMetadata(vm, chk, driver->cap= s, + driver->xmlopt, + cfg->checkpointDir) = < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to set checkpoint '%s' as cur= rent"), + chk->def->name); + chk->def->current =3D false; + goto endjob; + } + } + vm->current_checkpoint =3D chk; + } + } else if (chk->nchildren) { + rep.cfg =3D cfg; + rep.parent =3D chk->parent; + rep.vm =3D vm; + rep.err =3D 0; + rep.last =3D NULL; + rep.caps =3D driver->caps; + rep.xmlopt =3D driver->xmlopt; + virDomainCheckpointForEachChild(chk, + qemuDomainCheckpointReparentChildr= en, + &rep); + if (rep.err < 0) + goto endjob; + /* Can't modify siblings during ForEachChild, so do it now. */ + chk->parent->nchildren +=3D chk->nchildren; + rep.last->sibling =3D chk->parent->first_child; + chk->parent->first_child =3D chk->first_child; + } + + if (flags & VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY) { + chk->nchildren =3D 0; + chk->first_child =3D NULL; + ret =3D 0; + } else { + ret =3D qemuDomainCheckpointDiscard(driver, vm, chk, true, metadat= a_only); + } + + endjob: + qemuDomainObjEndJob(driver, vm); + + cleanup: + virDomainObjEndAPI(&vm); + virObjectUnref(cfg); + return ret; +} + static int qemuDomainQemuMonitorCommand(virDomainPtr domain, const char *c= md, char **result, unsigned int flags) { @@ -17101,6 +18022,16 @@ static virDomainPtr qemuDomainQemuAttach(virConnec= tPtr conn, goto cleanup; } + if (qemuProcessAttach(conn, driver, vm, pid, + pidfile, monConfig, monJSON) < 0) { + monConfig =3D NULL; + qemuDomainRemoveInactive(driver, vm); + qemuDomainObjEndJob(driver, vm); + goto cleanup; + } + + monConfig =3D NULL; + if (qemuProcessAttach(conn, driver, vm, pid, pidfile, monConfig, monJSON) < 0) { qemuDomainRemoveInactive(driver, vm); @@ -21908,6 +22839,12 @@ static int qemuDomainRename(virDomainPtr dom, goto endjob; } + if (virDomainListAllCheckpoints(vm->checkpoints, NULL, dom, NULL, flag= s) > 0) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("cannot rename domain with checkpoints")); + goto endjob; + } + if (virDomainObjListRename(driver->domains, vm, new_name, flags, qemuDomainRenameCallback, driver) < 0) goto endjob; @@ -22728,6 +23665,18 @@ static virHypervisorDriver qemuHypervisorDriver = =3D { .connectBaselineHypervisorCPU =3D qemuConnectBaselineHypervisorCPU, /*= 4.4.0 */ .nodeGetSEVInfo =3D qemuNodeGetSEVInfo, /* 4.5.0 */ .domainGetLaunchSecurityInfo =3D qemuDomainGetLaunchSecurityInfo, /* 4= .5.0 */ + .domainCheckpointCreateXML =3D qemuDomainCheckpointCreateXML, /* 5.2.0= */ + .domainCheckpointGetXMLDesc =3D qemuDomainCheckpointGetXMLDesc, /* 5.2= .0 */ + + .domainListCheckpoints =3D qemuDomainListCheckpoints, /* 5.2.0 */ + .domainCheckpointListChildren =3D qemuDomainCheckpointListChildren, /*= 5.2.0 */ + .domainCheckpointLookupByName =3D qemuDomainCheckpointLookupByName, /*= 5.2.0 */ + .domainHasCurrentCheckpoint =3D qemuDomainHasCurrentCheckpoint, /* 5.2= .0 */ + .domainCheckpointGetParent =3D qemuDomainCheckpointGetParent, /* 5.2.0= */ + .domainCheckpointCurrent =3D qemuDomainCheckpointCurrent, /* 5.2.0 */ + .domainCheckpointIsCurrent =3D qemuDomainCheckpointIsCurrent, /* 5.2.0= */ + .domainCheckpointHasMetadata =3D qemuDomainCheckpointHasMetadata, /* 5= .2.0 */ + .domainCheckpointDelete =3D qemuDomainCheckpointDelete, /* 5.2.0 */ }; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937756582774.7828355111369; Wed, 6 Mar 2019 21:49:16 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 948FB301E11B; Thu, 7 Mar 2019 05:49:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E1302CFB0; Thu, 7 Mar 2019 05:49:14 +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 246E7181A135; Thu, 7 Mar 2019 05:49:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275mkTm004094 for ; Thu, 7 Mar 2019 00:48:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id D72F35D791; Thu, 7 Mar 2019 05:48:46 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id D77585EDE2; Thu, 7 Mar 2019 05:48:45 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:48 -0600 Message-Id: <20190307054752.19522-17-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 16/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: , 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 07 Mar 2019 05:49:15 +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 | 106 +++++++++++++++++++++++++++++------------ src/qemu/qemu_driver.c | 84 +++++++++++++++++++++++++++++++- 2 files changed, 159 insertions(+), 31 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f995721bb0..2161e7b3b4 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1,7 +1,7 @@ /* * qemu_domain.c: QEMU domain private state * - * Copyright (C) 2006-2018 Red Hat, Inc. + * Copyright (C) 2006-2019 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -8709,44 +8709,89 @@ qemuDomainCheckpointDiscard(virQEMUDriverPtr driver, int ret =3D -1; virDomainCheckpointObjPtr parentchk =3D NULL; virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); + size_t i, j; + virJSONValuePtr arr =3D NULL; - 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; + + if (qemuBlockNodeNamesDetect(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) + goto cleanup; + qemuDomainObjEnterMonitor(driver, vm); + for (i =3D 0; i < chk->def->ndisks; i++) { + virDomainCheckpointDiskDef *disk =3D &chk->def->disks[i]; + const char *node; + + if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) + continue; + + node =3D qemuBlockNodeLookup(vm, disk->name); + if (parentchk) { + arr =3D virJSONValueNewArray(); + if (!arr || + virJSONValueArrayAppendString(arr, disk->bitmap) < 0) { + success =3D false; + break; + } + + for (j =3D 0; j < parentchk->def->ndisks; j++) { + virDomainCheckpointDiskDef *disk2; + + disk2 =3D &parentchk->def->disks[j]; + if (STRNEQ(disk->name, disk2->name)) + continue; + if (chk =3D=3D vm->current_checkpoint && + qemuMonitorEnableBitmap(priv->mon, node, + disk2->bitmap) < 0) { + success =3D false; + break; + } + if (qemuMonitorMergeBitmaps(priv->mon, node, + disk2->bitmap, &arr) < 0) { + success =3D false; + break; + } + } + } + if (qemuMonitorDeleteBitmap(priv->mon, 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; @@ -8763,6 +8808,7 @@ qemuDomainCheckpointDiscard(virQEMUDriverPtr driver, cleanup: VIR_FREE(chkFile); virObjectUnref(cfg); + virJSONValueFree(arr); return ret; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 76a62d2d76..07db03dca3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -48,6 +48,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" @@ -17256,6 +17257,51 @@ qemuDomainCheckpointPrepare(virQEMUDriverPtr drive= r, virCapsPtr caps, return ret; } +static int +qemuDomainCheckpointAddActions(virDomainObjPtr vm, + virJSONValuePtr actions, + virDomainCheckpointObjPtr old_current, + virDomainCheckpointDefPtr def) +{ + size_t i, j; + int ret =3D -1; + + for (i =3D 0; i < def->ndisks; i++) { + virDomainCheckpointDiskDef *disk =3D &def->disks[i]; + const char *node; + + if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) + continue; + node =3D qemuBlockNodeLookup(vm, disk->name); + if (qemuMonitorJSONTransactionAdd(actions, + "block-dirty-bitmap-add", + "s:node", 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->name, disk2->name)) + continue; + if (disk2->type =3D=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP && + qemuMonitorJSONTransactionAdd(actions, + "block-dirty-bitmap-disa= ble", + "s:node", node, + "s:name", disk2->bitmap, + NULL) < 0) + goto cleanup; + } + } + } + ret =3D 0; + + cleanup: + return ret; +} /* Struct and hash-iterator callback used when bulk redefining checkpoints= */ @@ -17297,6 +17343,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 | @@ -17313,11 +17362,18 @@ 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) goto cleanup; + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BITMAP_MERGE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("qemu binary lacks persistent bitmaps support")); + goto cleanup; + } + if (!(caps =3D virQEMUDriverGetCapabilities(driver, false))) goto cleanup; @@ -17394,6 +17450,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; @@ -17413,7 +17470,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(vm, 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; @@ -17452,6 +17516,7 @@ qemuDomainCheckpointCreateXML(virDomainPtr domain, qemuDomainObjEndJob(driver, vm); cleanup: + virJSONValueFree(actions); virDomainObjEndAPI(&vm); virDomainCheckpointDefFree(def); VIR_FREE(xml); @@ -17824,6 +17889,7 @@ qemuDomainCheckpointDelete(virDomainCheckpointPtr c= heckpoint, { virQEMUDriverPtr driver =3D checkpoint->domain->conn->privateData; virDomainObjPtr vm =3D NULL; + qemuDomainObjPrivatePtr priv; int ret =3D -1; virDomainCheckpointObjPtr chk =3D NULL; virQEMUDependentRemove rem; @@ -17846,6 +17912,22 @@ qemuDomainCheckpointDelete(virDomainCheckpointPtr = checkpoint, if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup; + priv =3D vm->privateData; + if (!metadata_only) { + /* Until qemu-img supports offline bitmap deletion, we are stuck + * with requiring a running guest */ + if (!virDomainObjIsActive(vm)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot delete checkpoint for inactive domain= ")); + goto endjob; + } + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BITMAP_MERGE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("qemu binary lacks persistent bitmaps support= ")); + goto endjob; + } + } + if (!(chk =3D qemuCheckObjFromCheckpoint(vm, checkpoint))) goto endjob; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937759891204.57498302259546; Wed, 6 Mar 2019 21:49:19 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 488CF3003079; Thu, 7 Mar 2019 05:49:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1DE1D611C2; Thu, 7 Mar 2019 05:49:18 +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 C99AA181A13E; Thu, 7 Mar 2019 05:49:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275mmer004102 for ; Thu, 7 Mar 2019 00:48:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0365B5D787; Thu, 7 Mar 2019 05:48:48 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04C965D78D; Thu, 7 Mar 2019 05:48:46 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:49 -0600 Message-Id: <20190307054752.19522-18-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 17/20] wip: backup: qemu: Implement framework for backup job APIs 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: , 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 07 Mar 2019 05:49:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Still needs to actually kick off the right QMP commands, but at least allows validation of backup XML, including the fact that a backup job can survive a libvirtd restart. Atomically creating a checkpoint alongside the backup still needs implementing. Signed-off-by: Eric Blake --- src/qemu/qemu_domain.h | 4 + src/qemu/qemu_domain.c | 31 ++++++- src/qemu/qemu_driver.c | 184 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 215 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index bcceaa5506..78bc059834 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -374,6 +374,10 @@ struct _qemuDomainObjPrivate { /* true if global -mem-prealloc appears on cmd line */ bool memPrealloc; + + /* Any currently running backup job. + * FIXME: allow jobs in parallel. For now, at most one job, always id = 1. */ + virDomainBackupDefPtr backup; }; # define QEMU_DOMAIN_PRIVATE(vm) \ diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 2161e7b3b4..aef8cdda73 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2311,13 +2311,25 @@ static int qemuDomainObjPrivateXMLFormatBlockjobs(virBufferPtr buf, virDomainObjPtr vm) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; bool bj =3D qemuDomainHasBlockjob(vm, false); + int ret =3D -1; virBufferAsprintf(&attrBuf, " active=3D'%s'", virTristateBoolTypeToString(virTristateBoolFromBool(= bj))); - return virXMLFormatElement(buf, "blockjobs", &attrBuf, NULL); + if (virXMLFormatElement(buf, "blockjobs", &attrBuf, NULL) < 0) + goto cleanup; + + /* TODO: merge other blockjobs and backups into uniform space? */ + if (priv->backup && virDomainBackupDefFormat(buf, priv->backup, true) = < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virBufferFreeAndReset(&attrBuf); + return ret; } @@ -2664,18 +2676,29 @@ qemuDomainObjPrivateXMLParseAutomaticPlacement(xmlX= PathContextPtr ctxt, static int -qemuDomainObjPrivateXMLParseBlockjobs(qemuDomainObjPrivatePtr priv, +qemuDomainObjPrivateXMLParseBlockjobs(virQEMUDriverPtr driver, + qemuDomainObjPrivatePtr priv, xmlXPathContextPtr ctxt) { + xmlNodePtr node; char *active; int tmp; + int ret =3D -1; if ((active =3D virXPathString("string(./blockjobs/@active)", ctxt)) && (tmp =3D virTristateBoolTypeFromString(active)) > 0) priv->reconnectBlockjobs =3D tmp; + if ((node =3D virXPathNode("./domainbackup", ctxt)) && + !(priv->backup =3D virDomainBackupDefParseNode(ctxt->doc, node, + driver->xmlopt, + VIR_DOMAIN_BACKUP_PAR= SE_INTERNAL))) + goto cleanup; + + ret =3D 0; + cleanup: VIR_FREE(active); - return 0; + return ret; } @@ -3051,7 +3074,7 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, qemuDomainObjPrivateXMLParsePR(ctxt, &priv->prDaemonRunning); - if (qemuDomainObjPrivateXMLParseBlockjobs(priv, ctxt) < 0) + if (qemuDomainObjPrivateXMLParseBlockjobs(driver, priv, ctxt) < 0) goto error; qemuDomainStorageIdReset(priv); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 07db03dca3..66db4a8f70 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17994,6 +17994,187 @@ qemuDomainCheckpointDelete(virDomainCheckpointPtr= checkpoint, return ret; } +static int qemuDomainBackupBegin(virDomainPtr domain, const char *diskXml, + const char *checkpointXml, unsigned int f= lags) +{ + virQEMUDriverPtr driver =3D domain->conn->privateData; + virDomainObjPtr vm =3D NULL; + virDomainBackupDefPtr def =3D NULL; + virQEMUDriverConfigPtr cfg =3D NULL; + virCapsPtr caps =3D NULL; + qemuDomainObjPrivatePtr priv; + int ret =3D -1; + struct timeval tv; + char *suffix =3D NULL; + + virCheckFlags(VIR_DOMAIN_BACKUP_BEGIN_NO_METADATA, -1); + /* TODO: VIR_DOMAIN_BACKUP_BEGIN_QUIESCE */ + + // FIXME: Support non-null checkpointXML for incremental - what + // code can be shared with CheckpointCreateXML, then add to transaction + // to create new checkpoint at same time as starting blockdev-backup + if (checkpointXml) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot create incremental backups yet")); + return -1; + } + // if (chk) VIR_STRDUP(suffix, chk->name); + gettimeofday(&tv, NULL); + if (virAsprintf(&suffix, "%lld", (long long)tv.tv_sec) < 0) + goto cleanup; + + if (!(vm =3D qemuDomObjFromDomain(domain))) + goto cleanup; + + cfg =3D virQEMUDriverGetConfig(driver); + + if (virDomainBackupBeginEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + if (!(caps =3D virQEMUDriverGetCapabilities(driver, false))) + goto cleanup; + + if (qemuProcessAutoDestroyActive(driver, vm)) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("domain is marked for auto destroy")); + goto cleanup; + } + + if (!virDomainObjIsActive(vm)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot perform disk backup for inactive domain")= ); + goto cleanup; + } + if (!(def =3D virDomainBackupDefParseString(diskXml, driver->xmlopt, 0= ))) + goto cleanup; + + /* We are going to modify the domain below. */ + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + goto cleanup; + + priv =3D vm->privateData; + if (priv->backup) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("another backup job is already running")); + goto endjob; + } + + if (virDomainBackupAlignDisks(def, vm->def, suffix) < 0) + goto endjob; + + /* actually start the checkpoint. 2x2 array of push/pull, full/incr, + plus additional tweak if checkpoint requested */ + /* TODO: issue QMP commands: + - pull: nbd-server-start with from user (or autogenerate s= erver) + - push/pull: blockdev-add per + - incr: bitmap-add of tmp, bitmap-merge per + - transaction, containing: + - push+full: blockdev-backup sync:full + - push+incr: blockdev-backup sync:incremental bitmap:tmp + - pull+full: blockdev-backup sync:none + - pull+incr: blockdev-backup sync:none, bitmap-disable of tmp + - if checkpoint: bitmap-disable of old, bitmap-add of new + - pull: nbd-server-add per , including bitmap for incr + */ + + VIR_STEAL_PTR(priv->backup, def); + ret =3D priv->backup->id =3D 1; /* Hard-coded job id for now */ + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, + driver->caps) < 0) + VIR_WARN("Unable to save status on vm %s after backup job", + vm->def->name); + + endjob: + qemuDomainObjEndJob(driver, vm); + + cleanup: + VIR_FREE(suffix); + virDomainObjEndAPI(&vm); + virDomainBackupDefFree(def); + virObjectUnref(caps); + virObjectUnref(cfg); + return ret; +} + +static char *qemuDomainBackupGetXMLDesc(virDomainPtr domain, int id, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + char *xml =3D NULL; + qemuDomainObjPrivatePtr priv; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + virCheckFlags(0, NULL); + + if (!(vm =3D qemuDomObjFromDomain(domain))) + return NULL; + + if (virDomainBackupGetXMLDescEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + /* TODO: Allow more than one hard-coded job id */ + priv =3D vm->privateData; + if (id !=3D 1 || !priv->backup) { + virReportError(VIR_ERR_NO_DOMAIN_CHECKPOINT, + _("no domain backup job with id '%d'"), id); + goto cleanup; + } + + if (virDomainBackupDefFormat(&buf, priv->backup, false) < 0) + goto cleanup; + xml =3D virBufferContentAndReset(&buf); + + cleanup: + virDomainObjEndAPI(&vm); + return xml; +} + +static int qemuDomainBackupEnd(virDomainPtr domain, int id, unsigned int f= lags) +{ + virQEMUDriverPtr driver =3D domain->conn->privateData; + virQEMUDriverConfigPtr cfg =3D NULL; + virDomainObjPtr vm =3D NULL; + int ret =3D -1; + virDomainBackupDefPtr backup =3D NULL; + qemuDomainObjPrivatePtr priv; + bool want_abort =3D flags & VIR_DOMAIN_BACKUP_END_ABORT; + + virCheckFlags(VIR_DOMAIN_BACKUP_END_ABORT, -1); + + if (!(vm =3D qemuDomObjFromDomain(domain))) + return -1; + + cfg =3D virQEMUDriverGetConfig(driver); + if (virDomainBackupEndEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + /* TODO: Allow more than one hard-coded job id */ + priv =3D vm->privateData; + if (id !=3D 1 || !priv->backup) { + virReportError(VIR_ERR_NO_DOMAIN_CHECKPOINT, + _("no domain backup job with id '%d'"), id); + goto cleanup; + } + + if (priv->backup->type !=3D VIR_DOMAIN_BACKUP_TYPE_PUSH) + want_abort =3D false; + + /* TODO: QMP commands to actually cancel the pending job, and on + * pull, also tear down the NBD server */ + VIR_STEAL_PTR(backup, priv->backup); + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, + driver->caps) < 0) + VIR_WARN("Unable to save status on vm %s after backup job", + vm->def->name); + + ret =3D want_abort ? 0 : 1; + + cleanup: + virDomainBackupDefFree(backup); + virDomainObjEndAPI(&vm); + return ret; +} + static int qemuDomainQemuMonitorCommand(virDomainPtr domain, const char *c= md, char **result, unsigned int flags) { @@ -23759,6 +23940,9 @@ static virHypervisorDriver qemuHypervisorDriver =3D= { .domainCheckpointIsCurrent =3D qemuDomainCheckpointIsCurrent, /* 5.2.0= */ .domainCheckpointHasMetadata =3D qemuDomainCheckpointHasMetadata, /* 5= .2.0 */ .domainCheckpointDelete =3D qemuDomainCheckpointDelete, /* 5.2.0 */ + .domainBackupBegin =3D qemuDomainBackupBegin, /* 5.2.0 */ + .domainBackupGetXMLDesc =3D qemuDomainBackupGetXMLDesc, /* 5.2.0 */ + .domainBackupEnd =3D qemuDomainBackupEnd, /* 5.2.0 */ }; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937733838582.8509000305395; Wed, 6 Mar 2019 21:48:53 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFA70300309D; Thu, 7 Mar 2019 05:48:51 +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 A38CB1001DCE; Thu, 7 Mar 2019 05:48:51 +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 601A93FA46; Thu, 7 Mar 2019 05:48:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275mn07004110 for ; Thu, 7 Mar 2019 00:48:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2C90F5D78F; Thu, 7 Mar 2019 05:48:49 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 25ABC5D787; Thu, 7 Mar 2019 05:48:48 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:50 -0600 Message-Id: <20190307054752.19522-19-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 18/20] backup: Wire up qemu full pull backup 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 07 Mar 2019 05:48:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Time to actually issue the QMP transactions that start and stop backup commands (for now, just pull mode, not push). Starting a job has to kick off several pre-req steps, then a transaction, and additionally spawn an NBD server for pull mode; ending a job as well as failing partway through beginning a job has to unwind the earlier steps. Implementing push mode, as well as incremental pull and checkpoint creation, is deferred to later patches. Signed-off-by: Eric Blake --- src/qemu/qemu_domain.c | 18 ++- src/qemu/qemu_driver.c | 288 ++++++++++++++++++++++++++++++++++++++-- src/qemu/qemu_process.c | 7 + 3 files changed, 299 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index aef8cdda73..a71cd0e52c 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2684,16 +2684,24 @@ qemuDomainObjPrivateXMLParseBlockjobs(virQEMUDriver= Ptr driver, char *active; int tmp; int ret =3D -1; + size_t i; if ((active =3D virXPathString("string(./blockjobs/@active)", ctxt)) && (tmp =3D virTristateBoolTypeFromString(active)) > 0) priv->reconnectBlockjobs =3D tmp; - if ((node =3D virXPathNode("./domainbackup", ctxt)) && - !(priv->backup =3D virDomainBackupDefParseNode(ctxt->doc, node, - driver->xmlopt, - VIR_DOMAIN_BACKUP_PAR= SE_INTERNAL))) - goto cleanup; + if ((node =3D virXPathNode("./domainbackup", ctxt))) { + if (!(priv->backup =3D virDomainBackupDefParseNode(ctxt->doc, node, + driver->xmlopt, + VIR_DOMAIN_BACKUP= _PARSE_INTERNAL))) + goto cleanup; + /* The backup job is only stored in XML if backupBegin + * succeeded at exporting the disk, so no need to store disk + * state when we can just force-reset it to a known-good + * value. */ + for (i =3D 0; i < priv->backup->ndisks; i++) + priv->backup->disks[i].state =3D VIR_DOMAIN_BACKUP_DISK_STATE_= EXPORT; + } ret =3D 0; cleanup: diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 66db4a8f70..76b72acbef 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17994,8 +17994,80 @@ qemuDomainCheckpointDelete(virDomainCheckpointPtr = checkpoint, return ret; } -static int qemuDomainBackupBegin(virDomainPtr domain, const char *diskXml, - const char *checkpointXml, unsigned int f= lags) +static int +qemuDomainBackupPrepare(virQEMUDriverPtr driver, virDomainObjPtr vm, + virDomainBackupDefPtr def) +{ + int ret =3D -1; + size_t i; + + if (qemuBlockNodeNamesDetect(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) + goto cleanup; + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDef *disk =3D &def->disks[i]; + virStorageSourcePtr src =3D vm->def->disks[disk->idx]->src; + + if (!disk->store) + continue; + if (virAsprintf(&disk->store->nodeformat, "tmp-%s", disk->name) < = 0) + goto cleanup; + if (!disk->store->format) + disk->store->format =3D VIR_STORAGE_FILE_QCOW2; + if (def->incremental) { + if (src->format !=3D VIR_STORAGE_FILE_QCOW2) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("incremental backup of %s requires qcow2"= ), + disk->name); + goto cleanup; + } + } + } + ret =3D 0; + cleanup: + return ret; +} + +/* Called while monitor lock is held. Best-effort cleanup. */ +static int +qemuDomainBackupDiskCleanup(virQEMUDriverPtr driver, virDomainObjPtr vm, + virDomainBackupDiskDef *disk, bool incremental) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + const char *node =3D vm->def->disks[disk->idx]->src->nodeformat; + int ret =3D 0; + + if (!disk->store) + return 0; + if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_EXPORT) { + /* No real need to use nbd-server-remove, since we will + * shortly be calling nbd-server-stop. */ + } + if (incremental && disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_BITMA= P && + qemuMonitorDeleteBitmap(priv->mon, node, disk->store->nodeformat) = < 0) { + VIR_WARN("Unable to remove temp bitmap for disk %s after backup", + disk->name); + ret =3D -1; + } + if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_READY && + qemuMonitorBlockdevDel(priv->mon, disk->store->nodeformat) < 0) { + VIR_WARN("Unable to remove temp disk %s after backup", + disk->name); + ret =3D -1; + } + if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_LABEL) + qemuDomainDiskChainElementRevoke(driver, vm, disk->store); + if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_CREATED && + disk->store->detected && unlink(disk->store->path) < 0) { + VIR_WARN("Unable to unlink temp disk %s after backup", + disk->store->path); + ret =3D -1; + } + return ret; +} + +static int +qemuDomainBackupBegin(virDomainPtr domain, const char *diskXml, + const char *checkpointXml, unsigned int flags) { virQEMUDriverPtr driver =3D domain->conn->privateData; virDomainObjPtr vm =3D NULL; @@ -18004,8 +18076,14 @@ static int qemuDomainBackupBegin(virDomainPtr doma= in, const char *diskXml, virCapsPtr caps =3D NULL; qemuDomainObjPrivatePtr priv; int ret =3D -1; + virJSONValuePtr json =3D NULL; + bool job_started =3D false; + bool nbd_running =3D false; + size_t i; struct timeval tv; char *suffix =3D NULL; + virCommandPtr cmd =3D NULL; + const char *qemuImgPath; virCheckFlags(VIR_DOMAIN_BACKUP_BEGIN_NO_METADATA, -1); /* TODO: VIR_DOMAIN_BACKUP_BEGIN_QUIESCE */ @@ -18026,6 +18104,7 @@ static int qemuDomainBackupBegin(virDomainPtr domai= n, const char *diskXml, if (!(vm =3D qemuDomObjFromDomain(domain))) goto cleanup; + priv =3D vm->privateData; cfg =3D virQEMUDriverGetConfig(driver); if (virDomainBackupBeginEnsureACL(domain->conn, vm->def) < 0) @@ -18048,25 +18127,122 @@ static int qemuDomainBackupBegin(virDomainPtr do= main, const char *diskXml, if (!(def =3D virDomainBackupDefParseString(diskXml, driver->xmlopt, 0= ))) goto cleanup; + if (def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PULL) { + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NBD_BITMAP)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("qemu binary lacks pull-mode backup support")= ); + goto cleanup; + } + if (!def->server || + def->server->transport !=3D VIR_STORAGE_NET_HOST_TRANS_TCP) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _(" must specify TCP server for n= ow")); + goto cleanup; + } + } else { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("push mode backups not supported yet")); + goto cleanup; + } + if (def->incremental) { + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BITMAP_MERGE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("qemu binary lacks persistent bitmaps support= ")); + goto cleanup; + } + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot create incremental backups yet")); + goto cleanup; + } + + if (!(qemuImgPath =3D qemuFindQemuImgBinary(driver))) + goto cleanup; + /* We are going to modify the domain below. */ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup; - priv =3D vm->privateData; if (priv->backup) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("another backup job is already running")); goto endjob; } - if (virDomainBackupAlignDisks(def, vm->def, suffix) < 0) + if (virDomainBackupAlignDisks(def, vm->def, suffix) < 0 || + qemuDomainBackupPrepare(driver, vm, def) < 0) goto endjob; /* actually start the checkpoint. 2x2 array of push/pull, full/incr, plus additional tweak if checkpoint requested */ - /* TODO: issue QMP commands: - - pull: nbd-server-start with from user (or autogenerate s= erver) - - push/pull: blockdev-add per + qemuDomainObjEnterMonitor(driver, vm); + /* - push/pull: blockdev-add per */ + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDef *disk =3D &def->disks[i]; + virJSONValuePtr file; + virStorageSourcePtr src =3D vm->def->disks[disk->idx]->src; + const char *node =3D src->nodeformat; + + if (!disk->store) + continue; + if (qemuDomainStorageFileInit(driver, vm, disk->store, src) < 0) + goto endmon; + if (disk->store->detected) { + if (virStorageFileCreate(disk->store) < 0) { + virReportSystemError(errno, + _("failed to create image file '%s'"), + NULLSTR(disk->store->path)); + goto endmon; + } + disk->state =3D VIR_DOMAIN_BACKUP_DISK_STATE_CREATED; + } + if (qemuDomainDiskChainElementPrepare(driver, vm, disk->store, fal= se, + true) < 0) + goto endmon; + disk->state =3D VIR_DOMAIN_BACKUP_DISK_STATE_LABEL; + if (disk->store->detected) { + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + /* Force initialization of scratch/target file to new qcow2 */ + if (!(cmd =3D virCommandNewArgList(qemuImgPath, + "create", + "-f", + virStorageFileFormatTypeToStr= ing(disk->store->format), + "-o", + NULL))) + goto endmon; + virBufferAsprintf(&buf, "backing_fmt=3D%s,backing_file=3D", + virStorageFileFormatTypeToString(src->format= )); + virQEMUBuildBufferEscapeComma(&buf, src->path); + virCommandAddArgBuffer(cmd, &buf); + + virQEMUBuildBufferEscapeComma(&buf, disk->store->path); + virCommandAddArgBuffer(cmd, &buf); + if (virCommandRun(cmd, NULL) < 0) + goto endmon; + virCommandFree(cmd); + cmd =3D NULL; + } + + if (virJSONValueObjectCreate(&file, + "s:driver", "file", + "s:filename", disk->store->path, + NULL) < 0) + goto endmon; + if (virJSONValueObjectCreate(&json, + "s:driver", virStorageFileFormatTypeT= oString(disk->store->format), + "s:node-name", disk->store->nodeforma= t, + "a:file", &file, + "s:backing", node, NULL) < 0) { + virJSONValueFree(file); + goto endmon; + } + if (qemuMonitorBlockdevAdd(priv->mon, json) < 0) + goto endmon; + json =3D NULL; + disk->state =3D VIR_DOMAIN_BACKUP_DISK_STATE_READY; + } + + /* TODO: - incr: bitmap-add of tmp, bitmap-merge per - transaction, containing: - push+full: blockdev-backup sync:full @@ -18074,8 +18250,77 @@ static int qemuDomainBackupBegin(virDomainPtr doma= in, const char *diskXml, - pull+full: blockdev-backup sync:none - pull+incr: blockdev-backup sync:none, bitmap-disable of tmp - if checkpoint: bitmap-disable of old, bitmap-add of new + */ + if (!(json =3D virJSONValueNewArray())) + goto endmon; + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDef *disk =3D &def->disks[i]; + virStorageSourcePtr src =3D vm->def->disks[disk->idx]->src; + + if (!disk->store) + continue; + if (qemuMonitorJSONTransactionAdd(json, + "blockdev-backup", + "s:device", src->nodeformat, + "s:target", disk->store->nodefor= mat, + "s:sync", "none", + "s:job-id", disk->name, + NULL) < 0) + goto endmon; + } + if (qemuMonitorTransaction(priv->mon, &json) < 0) + goto endmon; + job_started =3D true; + + /* + - pull: nbd-server-start with from user (or autogenerate s= erver) - pull: nbd-server-add per , including bitmap for incr */ + if (def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PULL) { + if (qemuMonitorNBDServerStart(priv->mon, def->server->name, + def->server->port, NULL) < 0) + goto endmon; + nbd_running =3D true; + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDef *disk =3D &def->disks[i]; + + if (!disk->store) + continue; + if (qemuMonitorNBDServerAdd(priv->mon, disk->store->nodeformat, + disk->name, false, + def->incremental ? disk->name : + NULL) < 0) + goto endmon; + disk->state =3D VIR_DOMAIN_BACKUP_DISK_STATE_EXPORT; + } + } + + ret =3D 0; + endmon: + /* Best effort cleanup if we fail partway through */ + if (ret < 0) { + virErrorPtr save_err =3D virSaveLastError(); + + if (nbd_running && + qemuMonitorNBDServerStop(priv->mon) < 0) + VIR_WARN("Unable to stop NBD server on vm %s after backup job", + vm->def->name); + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDef *disk =3D &def->disks[i]; + + if (job_started && + qemuMonitorBlockJobCancel(priv->mon, disk->name) < 0) + VIR_WARN("Unable to stop backup job %s on vm %s after fail= ure", + disk->store->nodeformat, vm->def->name); + qemuDomainBackupDiskCleanup(driver, vm, disk, !!def->increment= al); + } + virSetError(save_err); + virFreeError(save_err); + } + if (qemuDomainObjExitMonitor(driver, vm) < 0) + ret =3D -1; + if (ret < 0) + goto endjob; VIR_STEAL_PTR(priv->backup, def); ret =3D priv->backup->id =3D 1; /* Hard-coded job id for now */ @@ -18088,7 +18333,9 @@ static int qemuDomainBackupBegin(virDomainPtr domai= n, const char *diskXml, qemuDomainObjEndJob(driver, vm); cleanup: + virCommandFree(cmd); VIR_FREE(suffix); + virJSONValueFree(json); virDomainObjEndAPI(&vm); virDomainBackupDefFree(def); virObjectUnref(caps); @@ -18138,6 +18385,8 @@ static int qemuDomainBackupEnd(virDomainPtr domain,= int id, unsigned int flags) virDomainBackupDefPtr backup =3D NULL; qemuDomainObjPrivatePtr priv; bool want_abort =3D flags & VIR_DOMAIN_BACKUP_END_ABORT; + virDomainBackupDefPtr def; + size_t i; virCheckFlags(VIR_DOMAIN_BACKUP_END_ABORT, -1); @@ -18158,9 +18407,27 @@ static int qemuDomainBackupEnd(virDomainPtr domain= , int id, unsigned int flags) if (priv->backup->type !=3D VIR_DOMAIN_BACKUP_TYPE_PUSH) want_abort =3D false; + def =3D priv->backup; + + /* We are going to modify the domain below. */ + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + goto cleanup; + + qemuDomainObjEnterMonitor(driver, vm); + if (def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PULL) + ret =3D qemuMonitorNBDServerStop(priv->mon); + for (i =3D 0; i < def->ndisks; i++) { + if (qemuMonitorBlockJobCancel(priv->mon, + def->disks[i].name) < 0 || + qemuDomainBackupDiskCleanup(driver, vm, &def->disks[i], + !!def->incremental) < 0) + ret =3D -1; + } + if (qemuDomainObjExitMonitor(driver, vm) < 0 || ret < 0) { + ret =3D -1; + goto endjob; + } - /* TODO: QMP commands to actually cancel the pending job, and on - * pull, also tear down the NBD server */ VIR_STEAL_PTR(backup, priv->backup); if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) @@ -18169,6 +18436,9 @@ static int qemuDomainBackupEnd(virDomainPtr domain,= int id, unsigned int flags) ret =3D want_abort ? 0 : 1; + endjob: + qemuDomainObjEndJob(driver, vm); + cleanup: virDomainBackupDefFree(backup); virDomainObjEndAPI(&vm); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 68c670d3f2..63b6aada1f 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -929,6 +929,7 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE_= UNUSED, void *opaque) { virQEMUDriverPtr driver =3D opaque; + qemuDomainObjPrivatePtr priv; struct qemuProcessEvent *processEvent =3D NULL; virDomainDiskDefPtr disk; qemuBlockJobDataPtr job =3D NULL; @@ -939,6 +940,12 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE= _UNUSED, VIR_DEBUG("Block job for device %s (domain: %p,%s) type %d status %d", diskAlias, vm, vm->def->name, type, status); + priv =3D vm->privateData; + if (type =3D=3D VIR_DOMAIN_BLOCK_JOB_TYPE_BACKUP && priv->backup) { + /* Event for canceling a pull-mode backup is side-effect that + * should not be forwarded on to user */ + goto cleanup; + } if (!(disk =3D qemuProcessFindDomainDiskByAliasOrQOM(vm, diskAlias, NU= LL))) goto cleanup; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937763718407.2899991327464; Wed, 6 Mar 2019 21:49:23 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 075222DA986; Thu, 7 Mar 2019 05:49:22 +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 D77F460DB4; Thu, 7 Mar 2019 05:49:21 +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 9E6493D388; Thu, 7 Mar 2019 05:49:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275moDD004129 for ; Thu, 7 Mar 2019 00:48:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4AA4B5D78F; Thu, 7 Mar 2019 05:48:50 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BF1E5D783; Thu, 7 Mar 2019 05:48:49 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:51 -0600 Message-Id: <20190307054752.19522-20-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 19/20] wip: backup: qemu: Wire up qemu full push backup 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: , 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 07 Mar 2019 05:49:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" wip: still need to polish event code, cleanup properly on errors Update the code to support push backups; for now, the destination file still has to be local, although the XML could be extended into supporting remote destinations (where we will have to use the full power of blockdev-add). This also touches up the event handling to inform the user when the job is complete. Signed-off-by: Eric Blake --- src/qemu/qemu_driver.c | 81 +++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 76b72acbef..03506460a8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18030,14 +18030,13 @@ qemuDomainBackupPrepare(virQEMUDriverPtr driver, = virDomainObjPtr vm, /* Called while monitor lock is held. Best-effort cleanup. */ static int qemuDomainBackupDiskCleanup(virQEMUDriverPtr driver, virDomainObjPtr vm, - virDomainBackupDiskDef *disk, bool incremental) + virDomainBackupDiskDef *disk, bool push, + bool incremental, bool completed) { qemuDomainObjPrivatePtr priv =3D vm->privateData; const char *node =3D vm->def->disks[disk->idx]->src->nodeformat; int ret =3D 0; - if (!disk->store) - return 0; if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_EXPORT) { /* No real need to use nbd-server-remove, since we will * shortly be calling nbd-server-stop. */ @@ -18050,16 +18049,17 @@ qemuDomainBackupDiskCleanup(virQEMUDriverPtr driv= er, virDomainObjPtr vm, } if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_READY && qemuMonitorBlockdevDel(priv->mon, disk->store->nodeformat) < 0) { - VIR_WARN("Unable to remove temp disk %s after backup", - disk->name); + VIR_WARN("Unable to remove %s disk %s after backup", + push ? "target" : "scratch", disk->name); ret =3D -1; } if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_LABEL) qemuDomainDiskChainElementRevoke(driver, vm, disk->store); - if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_CREATED && + if ((!push || !completed) && + disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_CREATED && disk->store->detected && unlink(disk->store->path) < 0) { - VIR_WARN("Unable to unlink temp disk %s after backup", - disk->store->path); + VIR_WARN("Unable to unlink %s disk %s after backup", + push ? "failed target" : "scratch", disk->store->path); ret =3D -1; } return ret; @@ -18079,6 +18079,7 @@ qemuDomainBackupBegin(virDomainPtr domain, const ch= ar *diskXml, virJSONValuePtr json =3D NULL; bool job_started =3D false; bool nbd_running =3D false; + bool push; size_t i; struct timeval tv; char *suffix =3D NULL; @@ -18127,7 +18128,8 @@ qemuDomainBackupBegin(virDomainPtr domain, const ch= ar *diskXml, if (!(def =3D virDomainBackupDefParseString(diskXml, driver->xmlopt, 0= ))) goto cleanup; - if (def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PULL) { + push =3D def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PUSH; + if (!push) { if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NBD_BITMAP)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("qemu binary lacks pull-mode backup support")= ); @@ -18139,10 +18141,6 @@ qemuDomainBackupBegin(virDomainPtr domain, const c= har *diskXml, _(" must specify TCP server for n= ow")); goto cleanup; } - } else { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("push mode backups not supported yet")); - goto cleanup; } if (def->incremental) { if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BITMAP_MERGE)) { @@ -18223,6 +18221,7 @@ qemuDomainBackupBegin(virDomainPtr domain, const ch= ar *diskXml, cmd =3D NULL; } + /* FIXME: allow non-local files for push destinations */ if (virJSONValueObjectCreate(&file, "s:driver", "file", "s:filename", disk->store->path, @@ -18263,7 +18262,7 @@ qemuDomainBackupBegin(virDomainPtr domain, const ch= ar *diskXml, "blockdev-backup", "s:device", src->nodeformat, "s:target", disk->store->nodefor= mat, - "s:sync", "none", + "s:sync", push ? "full" : "none", "s:job-id", disk->name, NULL) < 0) goto endmon; @@ -18276,7 +18275,7 @@ qemuDomainBackupBegin(virDomainPtr domain, const ch= ar *diskXml, - pull: nbd-server-start with from user (or autogenerate s= erver) - pull: nbd-server-add per , including bitmap for incr */ - if (def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PULL) { + if (!push) { if (qemuMonitorNBDServerStart(priv->mon, def->server->name, def->server->port, NULL) < 0) goto endmon; @@ -18308,11 +18307,14 @@ qemuDomainBackupBegin(virDomainPtr domain, const = char *diskXml, for (i =3D 0; i < def->ndisks; i++) { virDomainBackupDiskDef *disk =3D &def->disks[i]; + if (!disk->store) + continue; if (job_started && qemuMonitorBlockJobCancel(priv->mon, disk->name) < 0) VIR_WARN("Unable to stop backup job %s on vm %s after fail= ure", disk->store->nodeformat, vm->def->name); - qemuDomainBackupDiskCleanup(driver, vm, disk, !!def->increment= al); + qemuDomainBackupDiskCleanup(driver, vm, disk, push, + !!def->incremental, false); } virSetError(save_err); virFreeError(save_err); @@ -18387,6 +18389,8 @@ static int qemuDomainBackupEnd(virDomainPtr domain,= int id, unsigned int flags) bool want_abort =3D flags & VIR_DOMAIN_BACKUP_END_ABORT; virDomainBackupDefPtr def; size_t i; + bool push =3D true; + bool completed =3D true; virCheckFlags(VIR_DOMAIN_BACKUP_END_ABORT, -1); @@ -18405,23 +18409,50 @@ static int qemuDomainBackupEnd(virDomainPtr domai= n, int id, unsigned int flags) goto cleanup; } - if (priv->backup->type !=3D VIR_DOMAIN_BACKUP_TYPE_PUSH) - want_abort =3D false; def =3D priv->backup; + if (def->type !=3D VIR_DOMAIN_BACKUP_TYPE_PUSH) { + want_abort =3D false; + push =3D false; + } /* We are going to modify the domain below. */ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup; qemuDomainObjEnterMonitor(driver, vm); - if (def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PULL) + if (push) { + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDef *disk =3D &def->disks[i]; + + if (!disk->store) + continue; + if (disk->state !=3D VIR_DOMAIN_BACKUP_DISK_STATE_COMPLETE) + completed =3D false; + } + } else { ret =3D qemuMonitorNBDServerStop(priv->mon); - for (i =3D 0; i < def->ndisks; i++) { - if (qemuMonitorBlockJobCancel(priv->mon, - def->disks[i].name) < 0 || - qemuDomainBackupDiskCleanup(driver, vm, &def->disks[i], - !!def->incremental) < 0) - ret =3D -1; + } + if (!completed && !want_abort) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("backup job id '%d' not complete yet"), id); + } else { + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDef *disk =3D &def->disks[i]; + + if (!disk->store) + continue; + if (!push || disk->state < VIR_DOMAIN_BACKUP_DISK_STATE_COMPLE= TE) { + if (qemuMonitorBlockJobCancel(priv->mon, + disk->name) < 0 && + !want_abort) { + ret =3D -1; + continue; + } + } + if (qemuDomainBackupDiskCleanup(driver, vm, disk, push, + !!def->incremental, completed)= < 0) + ret =3D -1; + } } if (qemuDomainObjExitMonitor(driver, vm) < 0 || ret < 0) { ret =3D -1; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:40:52 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 1551937747417309.1650973566798; Wed, 6 Mar 2019 21:49:07 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C2B8DC4ED3; Thu, 7 Mar 2019 05:49:05 +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 9ED9C60E3D; Thu, 7 Mar 2019 05:49:05 +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 633EC3FA50; Thu, 7 Mar 2019 05:49:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x275n4GK004217 for ; Thu, 7 Mar 2019 00:49:04 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4BD9D5EDE2; Thu, 7 Mar 2019 05:49:04 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C6865D787; Thu, 7 Mar 2019 05:48:50 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 23:47:52 -0600 Message-Id: <20190307054752.19522-21-eblake@redhat.com> In-Reply-To: <20190307054752.19522-1-eblake@redhat.com> References: <20190307054752.19522-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: amureini@redhat.com, derez@redhat.com, vsementsov@virtuozzo.com, zhanhouliang@outlook.com, bharadwaj.rayala@rubrik.com, ydary@redhat.com, nsoffer@redhat.com, jsnow@redhat.com, suman.swaroop@rubrik.com Subject: [libvirt] [PATCH v5 20/20] backup: implement qemu incremental pull backup 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: , 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 07 Mar 2019 05:49:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Complete wiring up incremental backup, by adding in support for creating a checkpoint at the same time as a backup (make the transaction have a few more steps) as well as exposing the dirty bitmap for a prior backup over NBD (requires creating a temporary bitmap, merging all appropriate bitmaps in, then exposing that bitmap over NBD). Signed-off-by: Eric Blake --- src/qemu/qemu_driver.c | 195 +++++++++++++++++++++++++++++++++++------ 1 file changed, 167 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 03506460a8..73c9db91b4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17238,6 +17238,24 @@ qemuDomainCheckpointPrepare(virQEMUDriverPtr drive= r, virCapsPtr caps, if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) continue; + /* We want to name temporary bitmap after disk name during + * incremental backup, which is not possible if that is a + * persistent bitmap name. We can also make life easier by + * enforcing bitmap names match checkpoint name, although this + * is not technically necessary. */ + if (STREQ(disk->name, disk->bitmap)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("checkpoint for disk %s must have distinct bi= tmap name"), + disk->name); + goto cleanup; + } + if (STRNEQ(disk->bitmap, def->name)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk %s bitmap should match checkpoint name = %s"), + disk->name, def->name); + goto cleanup; + } + if (vm->def->disks[i]->src->format > 0 && vm->def->disks[i]->src->format !=3D VIR_STORAGE_FILE_QCOW2) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -17996,19 +18014,42 @@ qemuDomainCheckpointDelete(virDomainCheckpointPtr= checkpoint, static int qemuDomainBackupPrepare(virQEMUDriverPtr driver, virDomainObjPtr vm, - virDomainBackupDefPtr def) + virDomainBackupDefPtr def, + virDomainCheckpointObjPtr chk) { int ret =3D -1; size_t i; + if (chk && def->ndisks !=3D chk->def->ndisks) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("inconsistency between backup and checkpoint disk= s")); + goto cleanup; + } if (qemuBlockNodeNamesDetect(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) goto cleanup; for (i =3D 0; i < def->ndisks; i++) { virDomainBackupDiskDef *disk =3D &def->disks[i]; virStorageSourcePtr src =3D vm->def->disks[disk->idx]->src; - if (!disk->store) + /* For now, insist that atomic checkpoint affect same disks as + * those being backed up. */ + if (!disk->store) { + if (chk && + chk->def->disks[i].type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_NO= NE) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("disk %s requested checkpoint without bac= kup"), + disk->name); + goto cleanup; + } continue; + } + if (chk && + chk->def->disks[i].type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP= ) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("disk %s requested backup without checkpoint"= ), + disk->name); + goto cleanup; + } if (virAsprintf(&disk->store->nodeformat, "tmp-%s", disk->name) < = 0) goto cleanup; if (!disk->store->format) @@ -18042,7 +18083,7 @@ qemuDomainBackupDiskCleanup(virQEMUDriverPtr driver= , virDomainObjPtr vm, * shortly be calling nbd-server-stop. */ } if (incremental && disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_BITMA= P && - qemuMonitorDeleteBitmap(priv->mon, node, disk->store->nodeformat) = < 0) { + qemuMonitorDeleteBitmap(priv->mon, node, disk->name) < 0) { VIR_WARN("Unable to remove temp bitmap for disk %s after backup", disk->name); ret =3D -1; @@ -18080,28 +18121,21 @@ qemuDomainBackupBegin(virDomainPtr domain, const = char *diskXml, bool job_started =3D false; bool nbd_running =3D false; bool push; + const char *mode; size_t i; struct timeval tv; char *suffix =3D NULL; virCommandPtr cmd =3D NULL; const char *qemuImgPath; + virDomainCheckpointDefPtr chkdef =3D NULL; + virDomainCheckpointObjPtr chk =3D NULL; + virDomainCheckpointObjPtr other =3D NULL; + virDomainCheckpointObjPtr parent =3D NULL; + virJSONValuePtr arr =3D NULL; virCheckFlags(VIR_DOMAIN_BACKUP_BEGIN_NO_METADATA, -1); /* TODO: VIR_DOMAIN_BACKUP_BEGIN_QUIESCE */ - // FIXME: Support non-null checkpointXML for incremental - what - // code can be shared with CheckpointCreateXML, then add to transaction - // to create new checkpoint at same time as starting blockdev-backup - if (checkpointXml) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("cannot create incremental backups yet")); - return -1; - } - // if (chk) VIR_STRDUP(suffix, chk->name); - gettimeofday(&tv, NULL); - if (virAsprintf(&suffix, "%lld", (long long)tv.tv_sec) < 0) - goto cleanup; - if (!(vm =3D qemuDomObjFromDomain(domain))) goto cleanup; @@ -18128,6 +18162,17 @@ qemuDomainBackupBegin(virDomainPtr domain, const c= har *diskXml, if (!(def =3D virDomainBackupDefParseString(diskXml, driver->xmlopt, 0= ))) goto cleanup; + if (checkpointXml) { + if (!(chkdef =3D qemuDomainCheckpointDefParseString(driver, caps, + checkpointXml, 0= )) || + VIR_STRDUP(suffix, chkdef->name) < 0) + goto cleanup; + } else { + gettimeofday(&tv, NULL); + if (virAsprintf(&suffix, "%lld", (long long)tv.tv_sec) < 0) + goto cleanup; + } + push =3D def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PUSH; if (!push) { if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NBD_BITMAP)) { @@ -18148,9 +18193,18 @@ qemuDomainBackupBegin(virDomainPtr domain, const c= har *diskXml, _("qemu binary lacks persistent bitmaps support= ")); goto cleanup; } - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("cannot create incremental backups yet")); - goto cleanup; + for (other =3D vm->current_checkpoint; other; + other =3D other->def->parent ? + virDomainCheckpointFindByName(vm->checkpoints, + other->def->parent) : NULL) + if (STREQ(other->def->name, def->incremental)) + break; + if (!other) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("could not locate checkpoint '%s' for increme= ntal backup"), + def->incremental); + goto cleanup; + } } if (!(qemuImgPath =3D qemuFindQemuImgBinary(driver))) @@ -18166,14 +18220,40 @@ qemuDomainBackupBegin(virDomainPtr domain, const = char *diskXml, goto endjob; } + if (chkdef) { + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BITMAP_MERGE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("qemu binary lacks persistent bitmaps support= ")); + goto endjob; + } + + if (qemuDomainCheckpointPrepare(driver, caps, vm, chkdef) < 0) + goto endjob; + if (!(chk =3D virDomainCheckpointAssignDef(vm->checkpoints, chkdef= ))) + goto endjob; + chkdef =3D NULL; + chk->def->current =3D true; + if (vm->current_checkpoint) { + parent =3D vm->current_checkpoint; + if (VIR_STRDUP(chk->def->parent, parent->def->name) < 0) + goto endjob; + if (qemuDomainCheckpointWriteMetadata(vm, parent, driver->caps, + driver->xmlopt, + cfg->checkpointDir) < 0) + goto endjob; + vm->current_checkpoint =3D NULL; + } + } + if (virDomainBackupAlignDisks(def, vm->def, suffix) < 0 || - qemuDomainBackupPrepare(driver, vm, def) < 0) + qemuDomainBackupPrepare(driver, vm, def, chk) < 0) goto endjob; /* actually start the checkpoint. 2x2 array of push/pull, full/incr, plus additional tweak if checkpoint requested */ qemuDomainObjEnterMonitor(driver, vm); - /* - push/pull: blockdev-add per */ + /* - push/pull: blockdev-add per + - incr: bitmap-add of tmp, bitmap-merge per */ for (i =3D 0; i < def->ndisks; i++) { virDomainBackupDiskDef *disk =3D &def->disks[i]; virJSONValuePtr file; @@ -18239,11 +18319,32 @@ qemuDomainBackupBegin(virDomainPtr domain, const = char *diskXml, goto endmon; json =3D NULL; disk->state =3D VIR_DOMAIN_BACKUP_DISK_STATE_READY; + + if (def->incremental) { + if (!(arr =3D virJSONValueNewArray())) + goto endmon; + if (qemuMonitorAddBitmap(priv->mon, node, disk->name, false) <= 0) { + virJSONValueFree(arr); + goto endmon; + } + disk->state =3D VIR_DOMAIN_BACKUP_DISK_STATE_BITMAP; + for (other =3D parent ? parent : vm->current_checkpoint; other; + other =3D other->def->parent ? + virDomainCheckpointFindByName(vm->checkpoints, + other->def->parent) : N= ULL) { + if (virJSONValueArrayAppendString(arr, other->def->name) <= 0) { + virJSONValueFree(arr); + goto endmon; + } + if (STREQ(other->def->name, def->incremental)) + break; + } + if (qemuMonitorMergeBitmaps(priv->mon, node, disk->name, &arr)= < 0) + goto endmon; + } } - /* TODO: - - incr: bitmap-add of tmp, bitmap-merge per - - transaction, containing: + /* - transaction, containing: - push+full: blockdev-backup sync:full - push+incr: blockdev-backup sync:incremental bitmap:tmp - pull+full: blockdev-backup sync:none @@ -18252,24 +18353,60 @@ qemuDomainBackupBegin(virDomainPtr domain, const = char *diskXml, */ if (!(json =3D virJSONValueNewArray())) goto endmon; + if (push) + mode =3D def->incremental ? "incremental" : "full"; + else + mode =3D "none"; for (i =3D 0; i < def->ndisks; i++) { virDomainBackupDiskDef *disk =3D &def->disks[i]; - virStorageSourcePtr src =3D vm->def->disks[disk->idx]->src; + const char *node; + const char *push_bitmap =3D NULL; if (!disk->store) continue; + node =3D qemuBlockNodeLookup(vm, disk->name); + if (push && def->incremental) + push_bitmap =3D disk->name; if (qemuMonitorJSONTransactionAdd(json, "blockdev-backup", - "s:device", src->nodeformat, + "s:device", node, "s:target", disk->store->nodefor= mat, - "s:sync", push ? "full" : "none", + "s:sync", mode, + "S:bitmap", push_bitmap, "s:job-id", disk->name, NULL) < 0) goto endmon; + if (def->incremental && !push && + qemuMonitorJSONTransactionAdd(json, + "block-dirty-bitmap-disable", + "s:node", node, + "s:name", disk->name, + NULL) < 0) + goto endmon; } + if (chk && qemuDomainCheckpointAddActions(vm, json, parent, chk->def) = < 0) + goto endmon; if (qemuMonitorTransaction(priv->mon, &json) < 0) goto endmon; job_started =3D true; + if (chk) { + if (qemuDomainCheckpointWriteMetadata(vm, chk, driver->caps, + driver->xmlopt, + cfg->checkpointDir) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unable to save metadata for checkpoint %s"), + chk->def->name); + virDomainCheckpointObjListRemove(vm->checkpoints, chk); + goto endmon; + } + vm->current_checkpoint =3D chk; + other =3D virDomainCheckpointFindByName(vm->checkpoints, + chk->def->parent); + chk->parent =3D other; + other->nchildren++; + chk->sibling =3D other->first_child; + other->first_child =3D chk; + } /* - pull: nbd-server-start with from user (or autogenerate s= erver) @@ -18312,7 +18449,7 @@ qemuDomainBackupBegin(virDomainPtr domain, const ch= ar *diskXml, if (job_started && qemuMonitorBlockJobCancel(priv->mon, disk->name) < 0) VIR_WARN("Unable to stop backup job %s on vm %s after fail= ure", - disk->store->nodeformat, vm->def->name); + disk->name, vm->def->name); qemuDomainBackupDiskCleanup(driver, vm, disk, push, !!def->incremental, false); } @@ -18335,6 +18472,8 @@ qemuDomainBackupBegin(virDomainPtr domain, const ch= ar *diskXml, qemuDomainObjEndJob(driver, vm); cleanup: + virJSONValueFree(arr); + virDomainCheckpointDefFree(chkdef); virCommandFree(cmd); VIR_FREE(suffix); virJSONValueFree(json); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list