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. Thus, it shares the common
virDomainMoment base class created in the previous patches.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
include/libvirt/virterror.h | 6 +++++-
src/util/virerror.c | 12 ++++++++++-
include/libvirt/libvirt.h | 6 +++++-
src/datatypes.h | 42 ++++++++++++++++++++++++++++++++++++-
src/datatypes.c | 22 +++++++++++++++++++
src/libvirt_private.syms | 2 ++
6 files changed, 86 insertions(+), 4 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 = 66, /* Error from libssh connection transport */
VIR_FROM_RESCTRL = 67, /* Error from resource control */
VIR_FROM_FIREWALLD = 68, /* Error from firewalld */
+ VIR_FROM_DOMAIN_CHECKPOINT = 69,/* Error from domain checkpoint */
# ifdef VIR_ENUM_SENTINELS
VIR_ERR_DOMAIN_LAST
@@ -322,6 +323,9 @@ typedef enum {
VIR_ERR_DEVICE_MISSING = 99, /* fail to find the desired device */
VIR_ERR_INVALID_NWFILTER_BINDING = 100, /* invalid nwfilter binding */
VIR_ERR_NO_NWFILTER_BINDING = 101, /* no nwfilter binding */
+ VIR_ERR_INVALID_DOMAIN_CHECKPOINT = 102, /* invalid domain checkpoint */
+ VIR_ERR_NO_DOMAIN_CHECKPOINT = 103, /* domain checkpoint not found */
+ VIR_ERR_NO_DOMAIN_BACKUP = 104, /* domain backup job id not found */
# 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_NUMBER_LAST] = {
[VIR_ERR_NO_NWFILTER_BINDING] = {
N_("Network filter binding not found"),
N_("Network filter binding not found: %s") },
+ [VIR_ERR_INVALID_DOMAIN_CHECKPOINT] = {
+ N_("Invalid domain checkpoint"),
+ N_("Invalid domain checkpoint: %s") },
+ [VIR_ERR_NO_DOMAIN_CHECKPOINT] = {
+ N_("Domain checkpoint not found"),
+ N_("Domain checkpoint not found: %s") },
+ [VIR_ERR_NO_DOMAIN_BACKUP] = {
+ 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 <libvirt/libvirt-common.h>
# include <libvirt/libvirt-host.h>
# include <libvirt/libvirt-domain.h>
+/* FIXME: Temporary hack until later patch creates new
+ * libvirt-domain-checkpoint.h file */
+typedef struct _virDomainCheckpoint virDomainCheckpoint;
+typedef virDomainCheckpoint *virDomainCheckpointPtr;
# include <libvirt/libvirt-domain-snapshot.h>
# include <libvirt/libvirt-event.h>
# include <libvirt/libvirt-interface.h>
diff --git a/src/datatypes.h b/src/datatypes.h
index b675251500..03feb5b18f 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -32,6 +32,7 @@
extern virClassPtr virConnectClass;
extern virClassPtr virDomainClass;
extern virClassPtr virDomainMomentClass;
+extern virClassPtr virDomainCheckpointClass;
extern virClassPtr virDomainSnapshotClass;
extern virClassPtr virInterfaceClass;
extern virClassPtr virNetworkClass;
@@ -293,7 +294,23 @@ extern virClassPtr virAdmClientClass;
} \
} while (0)
-# define virCheckDomainSnapshotReturn(obj, retval) \
+
+# define virCheckDomainCheckpointReturn(obj, retval) \
+ do { \
+ virDomainCheckpointPtr _check = (obj); \
+ if (!virObjectIsClass(_check, virDomainCheckpointClass) || \
+ !virObjectIsClass(virChkDom(_check), virDomainClass) || \
+ !virObjectIsClass(virChkDom(_check)->conn, virConnectClass)) { \
+ virReportErrorHelper(VIR_FROM_DOMAIN_CHECKPOINT, \
+ VIR_ERR_INVALID_DOMAIN_CHECKPOINT, \
+ __FILE__, __FUNCTION__, __LINE__, \
+ __FUNCTION__); \
+ virDispatchError(NULL); \
+ return retval; \
+ } \
+ } while (0)
+
+# define virCheckDomainSnapshotReturn(obj, retval) \
do { \
virDomainSnapshotPtr _snap = (obj); \
if (!virObjectIsClass(_snap, virDomainSnapshotClass) || \
@@ -683,6 +700,27 @@ struct _virDomainMoment {
virDomainPtr domain;
};
+/*
+ * _virDomainCheckpoint
+ *
+ * Internal structure associated with a domain checkpoint
+ */
+struct _virDomainCheckpoint {
+ virDomainMoment parent;
+};
+
+static inline char *
+virChkName(virDomainCheckpointPtr checkpoint)
+{
+ return checkpoint->parent.name;
+}
+
+static inline virDomainPtr
+virChkDom(virDomainCheckpointPtr checkpoint)
+{
+ return checkpoint->parent.domain;
+}
+
/**
* _virDomainSnapshot
*
@@ -769,6 +807,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 f0cfbe11fc..ec22a7b38a 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -37,6 +37,7 @@ virClassPtr virConnectClass;
virClassPtr virConnectCloseCallbackDataClass;
virClassPtr virDomainClass;
virClassPtr virDomainMomentClass;
+virClassPtr virDomainCheckpointClass;
virClassPtr virDomainSnapshotClass;
virClassPtr virInterfaceClass;
virClassPtr virNetworkClass;
@@ -52,6 +53,7 @@ static void virConnectDispose(void *obj);
static void virConnectCloseCallbackDataDispose(void *obj);
static void virDomainDispose(void *obj);
static void virDomainMomentDispose(void *obj);
+#define virDomainCheckpointDispose NULL
#define virDomainSnapshotDispose NULL
static void virInterfaceDispose(void *obj);
static void virNetworkDispose(void *obj);
@@ -89,6 +91,7 @@ virDataTypesOnceInit(void)
DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData);
DECLARE_CLASS(virDomain);
DECLARE_CLASS(virDomainMoment);
+ DECLARE_CLASS_COMMON(virDomainCheckpoint, virDomainMomentClass);
DECLARE_CLASS_COMMON(virDomainSnapshot, virDomainMomentClass);
DECLARE_CLASS(virInterface);
DECLARE_CLASS(virNetwork);
@@ -961,6 +964,25 @@ virDomainMomentDispose(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)
+{
+ return (virDomainCheckpointPtr) virGetDomainMoment(domain, name,
+ virDomainCheckpointClass);
+}
+
+
/**
* virGetDomainSnapshot:
* @domain: the domain to snapshot
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 758ec9f102..96147c093a 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1243,10 +1243,12 @@ virConnectCloseCallbackDataClass;
virConnectCloseCallbackDataGetCallback;
virConnectCloseCallbackDataRegister;
virConnectCloseCallbackDataUnregister;
+virDomainCheckpointClass;
virDomainClass;
virDomainSnapshotClass;
virGetConnect;
virGetDomain;
+virGetDomainCheckpoint;
virGetDomainSnapshot;
virGetInterface;
virGetNetwork;
--
2.20.1