[PATCH v2 3/5] Add a new function doCoreDump

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

 



This patch prepares for the next patch.
---
 src/qemu/qemu_driver.c |  145 ++++++++++++++++++++++++++----------------------
 1 files changed, 78 insertions(+), 67 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b5b4e83..a894837 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -138,6 +138,7 @@ struct _qemuDomainObjPrivate {
 };
 
 static int getCompressionType(struct qemud_driver *driver);
+static int doCoreDump(struct qemud_driver *driver, virDomainObjPtr vm, const char *path, int compress);
 
 static int qemudShutdown(void);
 
@@ -6032,6 +6033,81 @@ cleanup:
     return ret;
 }
 
+static int doCoreDump(struct qemud_driver *driver, virDomainObjPtr vm, const char *path, int compress)
+{
+    int fd = -1;
+    int ret = -1;
+    qemuDomainObjPrivatePtr priv;
+
+    priv = vm->privateData;
+
+    if (!virDomainObjIsActive(vm)) {
+        qemuReportError(VIR_ERR_OPERATION_INVALID,
+                        "%s", _("domain is not running"));
+        goto endjob;
+    }
+
+    /* Create an empty file with appropriate ownership.  */
+    if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
+        qemuReportError(VIR_ERR_OPERATION_FAILED,
+                        _("failed to create '%s'"), path);
+        goto endjob;
+    }
+
+    if (VIR_CLOSE(fd) < 0) {
+        virReportSystemError(errno,
+                             _("unable to save file %s"),
+                             path);
+        goto endjob;
+    }
+
+    if (driver->securityDriver &&
+        driver->securityDriver->domainSetSavedStateLabel &&
+        driver->securityDriver->domainSetSavedStateLabel(driver->securityDriver,
+                                                         vm, path) == -1)
+        goto endjob;
+
+    qemuDomainObjEnterMonitorWithDriver(driver, vm);
+    if (compress == QEMUD_SAVE_FORMAT_RAW) {
+        const char *args[] = {
+            "cat",
+            NULL,
+        };
+        ret = qemuMonitorMigrateToFile(priv->mon,
+                                       QEMU_MONITOR_MIGRATE_BACKGROUND,
+                                       args, path, 0);
+    } else {
+        const char *prog = qemudSaveCompressionTypeToString(compress);
+        const char *args[] = {
+            prog,
+            "-c",
+            NULL,
+        };
+        ret = qemuMonitorMigrateToFile(priv->mon,
+                                       QEMU_MONITOR_MIGRATE_BACKGROUND,
+                                       args, path, 0);
+    }
+    qemuDomainObjExitMonitorWithDriver(driver, vm);
+    if (ret < 0)
+        goto endjob;
+
+    ret = qemuDomainWaitForMigrationComplete(driver, vm);
+
+    if (ret < 0)
+        goto endjob;
+
+    if (driver->securityDriver &&
+        driver->securityDriver->domainRestoreSavedStateLabel &&
+        driver->securityDriver->domainRestoreSavedStateLabel(driver->securityDriver,
+                                                             vm, path) == -1)
+        goto endjob;
+
+endjob:
+    if (ret != 0)
+        unlink(path);
+    return ret;
+}
+
 static int getCompressionType(struct qemud_driver *driver)
 {
     int compress;
@@ -6065,13 +6141,10 @@ static int qemudDomainCoreDump(virDomainPtr dom,
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm;
     int resume = 0, paused = 0;
-    int ret = -1, fd = -1;
+    int ret = -1;
     virDomainEventPtr event = NULL;
-    int compress;
     qemuDomainObjPrivatePtr priv;
 
-    compress = getCompressionType(driver);
-
     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
 
@@ -6084,35 +6157,6 @@ static int qemudDomainCoreDump(virDomainPtr dom,
     }
     priv = vm->privateData;
 
-    if (qemuDomainObjBeginJobWithDriver(driver, vm) < 0)
-        goto cleanup;
-
-    if (!virDomainObjIsActive(vm)) {
-        qemuReportError(VIR_ERR_OPERATION_INVALID,
-                        "%s", _("domain is not running"));
-        goto endjob;
-    }
-
-    /* Create an empty file with appropriate ownership.  */
-    if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
-        qemuReportError(VIR_ERR_OPERATION_FAILED,
-                        _("failed to create '%s'"), path);
-        goto endjob;
-    }
-
-    if (VIR_CLOSE(fd) < 0) {
-        virReportSystemError(errno,
-                             _("unable to save file %s"),
-                             path);
-        goto endjob;
-    }
-
-    if (driver->securityDriver &&
-        driver->securityDriver->domainSetSavedStateLabel &&
-        driver->securityDriver->domainSetSavedStateLabel(driver->securityDriver,
-                                                         vm, path) == -1)
-        goto endjob;
-
     /* Migrate will always stop the VM, so the resume condition is
        independent of whether the stop command is issued.  */
     resume = (vm->state == VIR_DOMAIN_RUNNING);
@@ -6136,43 +6180,12 @@ static int qemudDomainCoreDump(virDomainPtr dom,
         }
     }
 
-    qemuDomainObjEnterMonitorWithDriver(driver, vm);
-    if (compress == QEMUD_SAVE_FORMAT_RAW) {
-        const char *args[] = {
-            "cat",
-            NULL,
-        };
-        ret = qemuMonitorMigrateToFile(priv->mon,
-                                       QEMU_MONITOR_MIGRATE_BACKGROUND,
-                                       args, path, 0);
-    } else {
-        const char *prog = qemudSaveCompressionTypeToString(compress);
-        const char *args[] = {
-            prog,
-            "-c",
-            NULL,
-        };
-        ret = qemuMonitorMigrateToFile(priv->mon,
-                                       QEMU_MONITOR_MIGRATE_BACKGROUND,
-                                       args, path, 0);
-    }
-    qemuDomainObjExitMonitorWithDriver(driver, vm);
-    if (ret < 0)
-        goto endjob;
-
-    ret = qemuDomainWaitForMigrationComplete(driver, vm);
-
+    ret = doCoreDump(driver, vm, path, getCompressionType(driver));
     if (ret < 0)
         goto endjob;
 
     paused = 1;
 
-    if (driver->securityDriver &&
-        driver->securityDriver->domainRestoreSavedStateLabel &&
-        driver->securityDriver->domainRestoreSavedStateLabel(driver->securityDriver,
-                                                             vm, path) == -1)
-        goto endjob;
-
 endjob:
     if ((ret == 0) && (flags & VIR_DUMP_CRASH)) {
         qemudShutdownVMDaemon(driver, vm, 0);
@@ -6205,8 +6218,6 @@ endjob:
     }
 
 cleanup:
-    if (ret != 0)
-        unlink(path);
     if (vm)
         virDomainObjUnlock(vm);
     if (event)
-- 
1.7.3


-- 
Thanks,
Hu Tao

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