[libvirt] [PATCH 3/8] save: wire up trivial saveFlags implementations

Eric Blake eblake at redhat.com
Thu Jul 14 14:24:30 UTC 2011


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

* src/libxl/libxl_driver.c (libxlDomainSave): Move guts...
(libxlDomainSaveFlags): ...to new function.
* src/test/test_driver.c (testDomainSave, testDomainSaveFlags):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainSave, vboxDomainSaveFlags):
Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainSave)
(xenUnifiedDomainSaveFlags): Likewise.
* src/qemu/qemu_driver.c (qemudDomainSave): Rename and move guts.
(qemuDomainSave, qemuDomainSaveFlags): ...here.
(qemudDomainSaveFlag): Rename...
(qemuDomainSaveInternal): ...to this, and update callers.
---
 src/libxl/libxl_driver.c |   17 ++++++++++++++++-
 src/qemu/qemu_driver.c   |   31 ++++++++++++++++++++++++-------
 src/test/test_driver.c   |   20 ++++++++++++++++++--
 src/vbox/vbox_tmpl.c     |   19 ++++++++++++++++++-
 src/xen/xen_driver.c     |   17 ++++++++++++++++-
 5 files changed, 92 insertions(+), 12 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 2bc998d..a88d0dc 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,6 +1946,12 @@ cleanup:
 }

 static int
+libxlDomainSave(virDomainPtr dom, const char *to)
+{
+    return libxlDomainSaveFlags(dom, to, NULL, 0);
+}
+
+static int
 libxlDomainRestore(virConnectPtr conn, const char *from)
 {
     libxlDriverPrivatePtr driver = conn->privateData;
@@ -3822,6 +3836,7 @@ 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 */
     .domainCoreDump = libxlDomainCoreDump, /* 0.9.2 */
     .domainSetVcpus = libxlDomainSetVcpus, /* 0.9.0 */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f33abab..ceeef1c 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:
@@ -8578,7 +8594,8 @@ 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 */
     .domainCoreDump = qemudDomainCoreDump, /* 0.7.0 */
     .domainScreenshot = qemuDomainScreenshot, /* 0.9.2 */
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index eb800f5..665a344 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,6 +1828,13 @@ cleanup:
     return ret;
 }

+static int
+testDomainSave(virDomainPtr domain,
+               const char *path)
+{
+    return testDomainSaveFlags(domain, path, NULL, 0);
+}
+
 static int testDomainRestore(virConnectPtr conn,
                              const char *path)
 {
@@ -5543,6 +5558,7 @@ 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 */
     .domainCoreDump = testDomainCoreDump, /* 0.3.2 */
     .domainSetVcpus = testSetVcpus, /* 0.1.4 */
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 79423ee..c81d1a9 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1979,13 +1979,23 @@ cleanup:
     return ret;
 }

-static int vboxDomainSave(virDomainPtr dom, const char *path ATTRIBUTE_UNUSED) {
+static int
+vboxDomainSaveFlags(virDomainPtr dom, const char *path ATTRIBUTE_UNUSED,
+                    const char *dxml, unsigned int flags)
+{
     VBOX_OBJECT_CHECK(dom->conn, int, -1);
     IConsole *console    = NULL;
     vboxIID iid = VBOX_IID_INITIALIZER;
     IMachine *machine = NULL;
     nsresult rc;

+    virCheckFlags(0, -1);
+    if (dxml) {
+        vboxError(VIR_ERR_INVALID_ARG, "%s",
+                  _("xml modification unsupported"));
+        return -1;
+    }
+
     /* VirtualBox currently doesn't support saving to a file
      * at a location other then the machine folder and thus
      * setting path to ATTRIBUTE_UNUSED for now, will change
@@ -2040,6 +2050,12 @@ static int vboxDomainSave(virDomainPtr dom, const char *path ATTRIBUTE_UNUSED) {
 }

 static int
+vboxDomainSave(virDomainPtr dom, const char *path)
+{
+    return vboxDomainSaveFlags(dom, path, NULL, 0);
+}
+
+static int
 vboxDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
                         unsigned int flags)
 {
@@ -8781,6 +8797,7 @@ virDriver NAME(Driver) = {
     .domainGetInfo = vboxDomainGetInfo, /* 0.6.3 */
     .domainGetState = vboxDomainGetState, /* 0.9.2 */
     .domainSave = vboxDomainSave, /* 0.6.3 */
+    .domainSaveFlags = vboxDomainSaveFlags, /* 0.9.4 */
     .domainSetVcpus = vboxDomainSetVcpus, /* 0.7.1 */
     .domainSetVcpusFlags = vboxDomainSetVcpusFlags, /* 0.8.5 */
     .domainGetVcpusFlags = vboxDomainGetVcpusFlags, /* 0.8.5 */
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 83c28db..01c9c4a 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,6 +1074,12 @@ xenUnifiedDomainSave (virDomainPtr dom, const char *to)
 }

 static int
+xenUnifiedDomainSave(virDomainPtr dom, const char *to)
+{
+    return xenUnifiedDomainSaveFlags(dom, to, NULL, 0);
+}
+
+static int
 xenUnifiedDomainRestore (virConnectPtr conn, const char *from)
 {
     GET_PRIVATE(conn);
@@ -2200,6 +2214,7 @@ 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 */
     .domainCoreDump = xenUnifiedDomainCoreDump, /* 0.1.9 */
     .domainSetVcpus = xenUnifiedDomainSetVcpus, /* 0.1.4 */
-- 
1.7.4.4




More information about the libvir-list mailing list