[PATCHv2 07/16] save: wire up trivial save/restore flags implementations

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

 



For all hypervisors that support save and restore, the new API
now performs the same functions as the old.

VBox is excluded from this list, because its existing domainsave
is broken (there is no corresponding domainrestore, and there
is no control over the filename used in the save).  A later
patch should change vbox to use its implementation for
managedsave, and teach start to use managedsave results.

* src/libxl/libxl_driver.c (libxlDomainSave): Move guts...
(libxlDomainSaveFlags): ...to new function.
(libxlDomainRestore): Move guts...
(libxlDomainRestoreFlags): ...to new function.
* src/test/test_driver.c (testDomainSave, testDomainSaveFlags)
(testDomainRestore, testDomainRestoreFlags): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSave)
(xenUnifiedDomainSaveFlags, xenUnifiedDomainRestore)
(xenUnifiedDomainRestoreFlags): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSave, qemudDomainRestore):
Rename and move guts.
(qemuDomainSave, qemuDomainSaveFlags, qemuDomainRestore)
(qemuDomainRestoreFlags): ...here.
(qemudDomainSaveFlag): Rename...
(qemuDomainSaveInternal): ...to this, and update callers.
---

v2: merge 3 and 13 of v1, drop vbox support

 src/libxl/libxl_driver.c |   34 ++++++++++++++++++++++++++++-
 src/qemu/qemu_driver.c   |   52 ++++++++++++++++++++++++++++++++++++++--------
 src/test/test_driver.c   |   42 +++++++++++++++++++++++++++++++++---
 src/xen/xen_driver.c     |   34 ++++++++++++++++++++++++++++-
 4 files changed, 145 insertions(+), 17 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 381d90b..e84fa36 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -1906,12 +1906,20 @@ cleanup:
 }

 static int
-libxlDomainSave(virDomainPtr dom, const char *to)
+libxlDomainSaveFlags(virDomainPtr dom, const char *to, const char *dxml,
+                     unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
     virDomainObjPtr vm;
     int ret = -1;

+    virCheckFlags(0, -1);
+    if (dxml) {
+        libxlError(VIR_ERR_INVALID_ARG, "%s",
+                   _("xml modification unsupported"));
+        return -1;
+    }
+
     libxlDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);

@@ -1938,7 +1946,14 @@ cleanup:
 }

 static int
-libxlDomainRestore(virConnectPtr conn, const char *from)
+libxlDomainSave(virDomainPtr dom, const char *to)
+{
+    return libxlDomainSaveFlags(dom, to, NULL, 0);
+}
+
+static int
+libxlDomainRestoreFlags(virConnectPtr conn, const char *from,
+                        const char *dxml, unsigned int flags)
 {
     libxlDriverPrivatePtr driver = conn->privateData;
     virDomainObjPtr vm = NULL;
@@ -1947,6 +1962,13 @@ libxlDomainRestore(virConnectPtr conn, const char *from)
     int fd = -1;
     int ret = -1;

+    virCheckFlags(0, -1);
+    if (dxml) {
+        libxlError(VIR_ERR_INVALID_ARG, "%s",
+                   _("xml modification unsupported"));
+        return -1;
+    }
+
     libxlDriverLock(driver);

     fd = libxlSaveImageOpen(driver, from, &def, &hdr);
@@ -1978,6 +2000,12 @@ cleanup:
 }

 static int
+libxlDomainRestore(virConnectPtr conn, const char *from)
+{
+    return libxlDomainRestoreFlags(conn, from, NULL, 0);
+}
+
+static int
 libxlDomainCoreDump(virDomainPtr dom, const char *to, unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
@@ -3850,7 +3878,9 @@ static virDriver libxlDriver = {
     .domainGetInfo = libxlDomainGetInfo, /* 0.9.0 */
     .domainGetState = libxlDomainGetState, /* 0.9.2 */
     .domainSave = libxlDomainSave, /* 0.9.2 */
+    .domainSaveFlags = libxlDomainSaveFlags, /* 0.9.4 */
     .domainRestore = libxlDomainRestore, /* 0.9.2 */
+    .domainRestoreFlags = libxlDomainRestoreFlags, /* 0.9.4 */
     .domainCoreDump = libxlDomainCoreDump, /* 0.9.2 */
     .domainSetVcpus = libxlDomainSetVcpus, /* 0.9.0 */
     .domainSetVcpusFlags = libxlDomainSetVcpusFlags, /* 0.9.0 */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 20eca30..95f30c3 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2107,9 +2107,10 @@ qemuCompressProgramName(int compress)
  * shutdown). So 'vm' must not be referenced by the caller after
  * this returns (whether returning success or failure).
  */
-static int qemudDomainSaveFlag(struct qemud_driver *driver, virDomainPtr dom,
-                               virDomainObjPtr vm, const char *path,
-                               int compressed)
+static int
+qemuDomainSaveInternal(struct qemud_driver *driver, virDomainPtr dom,
+                       virDomainObjPtr vm, const char *path,
+                       int compressed)
 {
     char *xml = NULL;
     struct qemud_save_header header;
@@ -2351,13 +2352,22 @@ static bool qemudCompressProgramAvailable(enum qemud_save_formats compress)
     return true;
 }

-static int qemudDomainSave(virDomainPtr dom, const char *path)
+static int
+qemuDomainSaveFlags(virDomainPtr dom, const char *path, const char *dxml,
+                    unsigned int flags)
 {
     struct qemud_driver *driver = dom->conn->privateData;
     int compressed;
     int ret = -1;
     virDomainObjPtr vm = NULL;

+    virCheckFlags(0, -1);
+    if (dxml) {
+        qemuReportError(VIR_ERR_INVALID_ARG, "%s",
+                        _("xml modification unsupported"));
+        return -1;
+    }
+
     qemuDriverLock(driver);

     if (driver->saveImageFormat == NULL)
@@ -2393,7 +2403,7 @@ static int qemudDomainSave(virDomainPtr dom, const char *path)
         goto cleanup;
     }

-    ret = qemudDomainSaveFlag(driver, dom, vm, path, compressed);
+    ret = qemuDomainSaveInternal(driver, dom, vm, path, compressed);
     vm = NULL;

 cleanup:
@@ -2404,6 +2414,12 @@ cleanup:
     return ret;
 }

+static int
+qemuDomainSave(virDomainPtr dom, const char *path)
+{
+    return qemuDomainSaveFlags(dom, path, NULL, 0);
+}
+
 static char *
 qemuDomainManagedSavePath(struct qemud_driver *driver, virDomainObjPtr vm) {
     char *ret;
@@ -2450,7 +2466,7 @@ qemuDomainManagedSave(virDomainPtr dom, unsigned int flags)
     VIR_INFO("Saving state to %s", name);

     compressed = QEMUD_SAVE_FORMAT_RAW;
-    ret = qemudDomainSaveFlag(driver, dom, vm, name, compressed);
+    ret = qemuDomainSaveInternal(driver, dom, vm, name, compressed);
     vm = NULL;

 cleanup:
@@ -3752,8 +3768,10 @@ out:
 }

 static int
-qemuDomainRestore(virConnectPtr conn,
-                  const char *path)
+qemuDomainRestoreFlags(virConnectPtr conn,
+                       const char *path,
+                       const char *dxml,
+                       unsigned int flags)
 {
     struct qemud_driver *driver = conn->privateData;
     virDomainDefPtr def = NULL;
@@ -3762,6 +3780,13 @@ qemuDomainRestore(virConnectPtr conn,
     int ret = -1;
     struct qemud_save_header header;

+    virCheckFlags(0, -1);
+    if (dxml) {
+        qemuReportError(VIR_ERR_INVALID_ARG, "%s",
+                        _("xml modification unsupported"));
+        return -1;
+    }
+
     qemuDriverLock(driver);

     fd = qemuDomainSaveImageOpen(driver, path, &def, &header);
@@ -3801,6 +3826,13 @@ cleanup:
 }

 static int
+qemuDomainRestore(virConnectPtr conn,
+                  const char *path)
+{
+    return qemuDomainRestoreFlags(conn, path, NULL, 0);
+}
+
+static int
 qemuDomainObjRestore(virConnectPtr conn,
                      struct qemud_driver *driver,
                      virDomainObjPtr vm,
@@ -8563,8 +8595,10 @@ static virDriver qemuDriver = {
     .domainGetInfo = qemudDomainGetInfo, /* 0.2.0 */
     .domainGetState = qemuDomainGetState, /* 0.9.2 */
     .domainGetControlInfo = qemuDomainGetControlInfo, /* 0.9.3 */
-    .domainSave = qemudDomainSave, /* 0.2.0 */
+    .domainSave = qemuDomainSave, /* 0.2.0 */
+    .domainSaveFlags = qemuDomainSaveFlags, /* 0.9.4 */
     .domainRestore = qemuDomainRestore, /* 0.2.0 */
+    .domainRestoreFlags = qemuDomainRestoreFlags, /* 0.9.4 */
     .domainCoreDump = qemudDomainCoreDump, /* 0.7.0 */
     .domainScreenshot = qemuDomainScreenshot, /* 0.9.2 */
     .domainSetVcpus = qemuDomainSetVcpus, /* 0.4.4 */
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 0e3bf53..534270d 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1726,8 +1726,9 @@ cleanup:

 #define TEST_SAVE_MAGIC "TestGuestMagic"

-static int testDomainSave(virDomainPtr domain,
-                          const char *path)
+static int
+testDomainSaveFlags(virDomainPtr domain, const char *path,
+                    const char *dxml, unsigned int flags)
 {
     testConnPtr privconn = domain->conn->privateData;
     char *xml = NULL;
@@ -1737,6 +1738,13 @@ static int testDomainSave(virDomainPtr domain,
     virDomainEventPtr event = NULL;
     int ret = -1;

+    virCheckFlags(0, -1);
+    if (dxml) {
+        testError(VIR_ERR_INVALID_ARG, "%s",
+                  _("xml modification unsupported"));
+        return -1;
+    }
+
     testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
@@ -1820,8 +1828,18 @@ cleanup:
     return ret;
 }

-static int testDomainRestore(virConnectPtr conn,
-                             const char *path)
+static int
+testDomainSave(virDomainPtr domain,
+               const char *path)
+{
+    return testDomainSaveFlags(domain, path, NULL, 0);
+}
+
+static int
+testDomainRestoreFlags(virConnectPtr conn,
+                       const char *path,
+                       const char *dxml,
+                       unsigned int flags)
 {
     testConnPtr privconn = conn->privateData;
     char *xml = NULL;
@@ -1833,6 +1851,13 @@ static int testDomainRestore(virConnectPtr conn,
     virDomainEventPtr event = NULL;
     int ret = -1;

+    virCheckFlags(0, -1);
+    if (dxml) {
+        testError(VIR_ERR_INVALID_ARG, "%s",
+                  _("xml modification unsupported"));
+        return -1;
+    }
+
     if ((fd = open(path, O_RDONLY)) < 0) {
         virReportSystemError(errno,
                              _("cannot read domain image '%s'"),
@@ -1909,6 +1934,13 @@ cleanup:
     return ret;
 }

+static int
+testDomainRestore(virConnectPtr conn,
+                  const char *path)
+{
+    return testDomainRestoreFlags(conn, path, NULL, 0);
+}
+
 static int testDomainCoreDump(virDomainPtr domain,
                               const char *to,
                               unsigned int flags)
@@ -5550,7 +5582,9 @@ static virDriver testDriver = {
     .domainGetInfo = testGetDomainInfo, /* 0.1.1 */
     .domainGetState = testDomainGetState, /* 0.9.2 */
     .domainSave = testDomainSave, /* 0.3.2 */
+    .domainSaveFlags = testDomainSaveFlags, /* 0.9.4 */
     .domainRestore = testDomainRestore, /* 0.3.2 */
+    .domainRestoreFlags = testDomainRestoreFlags, /* 0.9.4 */
     .domainCoreDump = testDomainCoreDump, /* 0.3.2 */
     .domainSetVcpus = testSetVcpus, /* 0.1.4 */
     .domainSetVcpusFlags = testDomainSetVcpusFlags, /* 0.8.5 */
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 7e3ef77..cf34132 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -1051,11 +1051,19 @@ xenUnifiedDomainGetState(virDomainPtr dom,
 }

 static int
-xenUnifiedDomainSave (virDomainPtr dom, const char *to)
+xenUnifiedDomainSaveFlags(virDomainPtr dom, const char *to, const char *dxml,
+                          unsigned int flags)
 {
     GET_PRIVATE(dom->conn);
     int i;

+    virCheckFlags(0, -1);
+    if (dxml) {
+        xenUnifiedError(VIR_ERR_INVALID_ARG, "%s",
+                        _("xml modification unsupported"));
+        return -1;
+    }
+
     for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
         if (priv->opened[i] &&
             drivers[i]->domainSave &&
@@ -1066,11 +1074,25 @@ xenUnifiedDomainSave (virDomainPtr dom, const char *to)
 }

 static int
-xenUnifiedDomainRestore (virConnectPtr conn, const char *from)
+xenUnifiedDomainSave(virDomainPtr dom, const char *to)
+{
+    return xenUnifiedDomainSaveFlags(dom, to, NULL, 0);
+}
+
+static int
+xenUnifiedDomainRestoreFlags(virConnectPtr conn, const char *from,
+                             const char *dxml, unsigned int flags)
 {
     GET_PRIVATE(conn);
     int i;

+    virCheckFlags(0, -1);
+    if (dxml) {
+        xenUnifiedError(VIR_ERR_INVALID_ARG, "%s",
+                        _("xml modification unsupported"));
+        return -1;
+    }
+
     for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
         if (priv->opened[i] &&
             drivers[i]->domainRestore &&
@@ -1081,6 +1103,12 @@ xenUnifiedDomainRestore (virConnectPtr conn, const char *from)
 }

 static int
+xenUnifiedDomainRestore (virConnectPtr conn, const char *from)
+{
+    return xenUnifiedDomainRestoreFlags(conn, from, NULL, 0);
+}
+
+static int
 xenUnifiedDomainCoreDump (virDomainPtr dom, const char *to, unsigned int flags)
 {
     GET_PRIVATE(dom->conn);
@@ -2212,7 +2240,9 @@ static virDriver xenUnifiedDriver = {
     .domainGetInfo = xenUnifiedDomainGetInfo, /* 0.0.3 */
     .domainGetState = xenUnifiedDomainGetState, /* 0.9.2 */
     .domainSave = xenUnifiedDomainSave, /* 0.0.3 */
+    .domainSaveFlags = xenUnifiedDomainSaveFlags, /* 0.9.4 */
     .domainRestore = xenUnifiedDomainRestore, /* 0.0.3 */
+    .domainRestoreFlags = xenUnifiedDomainRestoreFlags, /* 0.9.4 */
     .domainCoreDump = xenUnifiedDomainCoreDump, /* 0.1.9 */
     .domainSetVcpus = xenUnifiedDomainSetVcpus, /* 0.1.4 */
     .domainSetVcpusFlags = xenUnifiedDomainSetVcpusFlags, /* 0.8.5 */
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[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]