]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
fix various breakages in qemu Dump command
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 14 Dec 2009 10:27:41 +0000 (11:27 +0100)
committerDaniel Veillard <veillard@redhat.com>
Mon, 14 Dec 2009 10:27:41 +0000 (11:27 +0100)
1) qemuMigrateToCommand uses ">>" so we have to truncate the file
before starting the migration;

2) the command wasn't updated to chown the driver and set/restore
the security lavels;

3) the VM does not have to be resumed if migration fails;

4) the file is not removed when migration fails.

* src/qemu/qemu_driver.c (qemuDomainCoreDump): Truncate file before
  dumping, set/restore ownership and security labels for the file.

src/qemu/qemu_driver.c

index 5a61b8ca8c180f44721f4881cb4798b4ef063391..7e55c236f84885960f1ce188baae83b385109fde 100644 (file)
@@ -3801,7 +3801,7 @@ static int qemudDomainCoreDump(virDomainPtr dom,
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm;
     int resume = 0, paused = 0;
-    int ret = -1;
+    int ret = -1, fd = -1;
     const char *args[] = {
         "cat",
         NULL,
@@ -3828,6 +3828,33 @@ static int qemudDomainCoreDump(virDomainPtr dom,
         goto endjob;
     }
 
+    /* Create an empty file with appropriate ownership.  */
+    if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
+        qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+                         _("failed to create '%s'"), path);
+        goto endjob;
+    }
+
+    if (close(fd) < 0) {
+        virReportSystemError(dom->conn, errno,
+                             _("unable to save file %s"),
+                             path);
+        goto endjob;
+    }
+
+    if (driver->privileged &&
+        chown(path, driver->user, driver->group) < 0) {
+        virReportSystemError(NULL, errno,
+                             _("unable to set ownership of '%s' to user %d:%d"),
+                             path, driver->user, driver->group);
+        goto endjob;
+    }
+
+    if (driver->securityDriver &&
+        driver->securityDriver->domainSetSavedStateLabel &&
+        driver->securityDriver->domainSetSavedStateLabel(dom->conn, vm, path) == -1)
+        goto endjob;
+
     /* Migrate will always stop the VM, so once we support live dumping
        the resume condition will stay the same, independent of whether
        the stop command is issued.  */
@@ -3849,8 +3876,22 @@ static int qemudDomainCoreDump(virDomainPtr dom,
     qemuDomainObjEnterMonitor(vm);
     ret = qemuMonitorMigrateToCommand(priv->mon, 0, args, path);
     qemuDomainObjExitMonitor(vm);
-    paused = 1;
+    paused |= (ret == 0);
+
+    if (driver->privileged &&
+        chown(path, 0, 0) < 0) {
+        virReportSystemError(NULL, errno,
+                             _("unable to set ownership of '%s' to user %d:%d"),
+                             path, 0, 0);
+        goto endjob;
+    }
 
+    if (driver->securityDriver &&
+        driver->securityDriver->domainRestoreSavedStateLabel &&
+        driver->securityDriver->domainRestoreSavedStateLabel(dom->conn, path) == -1)
+        goto endjob;
+
+endjob:
     /* Since the monitor is always attached to a pty for libvirt, it
        will support synchronous operations so we always get here after
        the migration is complete.  */
@@ -3864,11 +3905,12 @@ static int qemudDomainCoreDump(virDomainPtr dom,
         qemuDomainObjExitMonitor(vm);
     }
 
-endjob:
     if (qemuDomainObjEndJob(vm) == 0)
         vm = NULL;
 
 cleanup:
+    if (ret != 0)
+        unlink(path);
     if (vm)
         virDomainObjUnlock(vm);
     return ret;