+ 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.
+
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.
+
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.
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()
+
+ 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
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]+(name|creationTime)>";
+
+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