[libvirt RFCv7 07/40] libvirt: introduce virDomainSaveParams public API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



create an alternative to virDomainSaveFlags that is more
extendible via parameters.

Signed-off-by: Claudio Fontana <cfontana@xxxxxxx>
Reviewed-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 include/libvirt/libvirt-domain.h | 26 +++++++++++++++++
 src/driver-hypervisor.h          |  7 +++++
 src/libvirt-domain.c             | 48 ++++++++++++++++++++++++++++++++
 src/libvirt_public.syms          |  5 ++++
 4 files changed, 86 insertions(+)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 2edef9c4e1..52c86f3813 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1562,6 +1562,10 @@ int                     virDomainSaveFlags      (virDomainPtr domain,
                                                  const char *to,
                                                  const char *dxml,
                                                  unsigned int flags);
+int                     virDomainSaveParams     (virDomainPtr domain,
+                                                 virTypedParameterPtr params,
+                                                 int nparams,
+                                                 unsigned int flags);
 int                     virDomainRestore        (virConnectPtr conn,
                                                  const char *from);
 int                     virDomainRestoreFlags   (virConnectPtr conn,
@@ -1569,6 +1573,28 @@ int                     virDomainRestoreFlags   (virConnectPtr conn,
                                                  const char *dxml,
                                                  unsigned int flags);
 
+/**
+ * VIR_SAVE_PARAM_FILE:
+ *
+ * the parameter used to specify the savestate file to save to or restore from.
+ *
+ * Since: 8.4.0
+ */
+# define VIR_SAVE_PARAM_FILE                     "file"
+
+/**
+ * VIR_SAVE_PARAM_DXML:
+ *
+ * an optional parameter used to adjust guest xml on restore.
+ * If the hypervisor supports it, it can be used to alter
+ * host-specific portions of the domain XML that will be used when
+ * restoring an image.  For example, it is possible to alter the
+ * device while the domain is stopped.
+ *
+ * Since: 8.4.0
+ */
+# define VIR_SAVE_PARAM_DXML                     "dxml"
+
 /* See below for virDomainSaveImageXMLFlags */
 char *          virDomainSaveImageGetXMLDesc    (virConnectPtr conn,
                                                  const char *file,
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index 4423eb0885..434a7d7cc4 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -240,6 +240,12 @@ typedef int
                          const char *dxml,
                          unsigned int flags);
 
+typedef int
+(*virDrvDomainSaveParams)(virDomainPtr domain,
+                          virTypedParameterPtr params,
+                          int nparams,
+                          unsigned int flags);
+
 typedef int
 (*virDrvDomainRestore)(virConnectPtr conn,
                        const char *from);
@@ -1489,6 +1495,7 @@ struct _virHypervisorDriver {
     virDrvDomainGetControlInfo domainGetControlInfo;
     virDrvDomainSave domainSave;
     virDrvDomainSaveFlags domainSaveFlags;
+    virDrvDomainSaveParams domainSaveParams;
     virDrvDomainRestore domainRestore;
     virDrvDomainRestoreFlags domainRestoreFlags;
     virDrvDomainSaveImageGetXMLDesc domainSaveImageGetXMLDesc;
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 27993829a0..ca2fe5e99d 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -999,6 +999,54 @@ virDomainSaveFlags(virDomainPtr domain, const char *to,
     return -1;
 }
 
+/**
+ * virDomainSaveParams:
+ * @domain: a domain object
+ * @params: save parameters
+ * @nparams: number of save parameters
+ * @flags: bitwise-OR of virDomainSaveRestoreFlags
+ *
+ * This method extends virDomainSaveFlags by adding parameters.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ *
+ * Since: 8.4.0
+ */
+int
+virDomainSaveParams(virDomainPtr domain,
+                    virTypedParameterPtr params, int nparams,
+                    unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%d, flags=0x%x",
+                     params, nparams, flags);
+    VIR_TYPED_PARAMS_DEBUG(params, nparams);
+
+    virResetLastError();
+
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;
+
+    virCheckReadOnlyGoto(conn->flags, error);
+
+    VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_SAVE_RUNNING,
+                             VIR_DOMAIN_SAVE_PAUSED,
+                             error);
+
+    if (conn->driver->domainSaveParams) {
+        if (conn->driver->domainSaveParams(domain, params, nparams, flags) < 0)
+            goto error;
+        return 0;
+    }
+
+    virReportUnsupportedError();
+
+ error:
+    virDispatchError(domain->conn);
+    return -1;
+}
+
 
 /**
  * virDomainRestore:
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index f93692c427..32ffbbaf84 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -916,4 +916,9 @@ LIBVIRT_8.0.0 {
         virDomainSetLaunchSecurityState;
 } LIBVIRT_7.8.0;
 
+LIBVIRT_8.4.0 {
+    global:
+        virDomainSaveParams;
+} LIBVIRT_8.0.0;
+
 # .... define new API here using predicted next version number ....
-- 
2.35.3





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux