[PATCHv2 2/2] qemu: check unlink hint from virQEMUFileOpenAs()

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

 



Signed-off-by: Simon Rowe <simon.rowe@xxxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Changes from v1:
 * only unlink if virQEMUFileOpenAs() created the file

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 444e9e5cbc..6e83d7e068 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3201,6 +3201,7 @@ doCoreDump(virQEMUDriver *driver,
     int rc = -1;
     virFileWrapperFd *wrapperFd = NULL;
     int directFlag = 0;
+    bool needUnlink = false;
     unsigned int flags = VIR_FILE_WRAPPER_NON_BLOCKING;
     const char *memory_dump_format = NULL;
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
@@ -3224,12 +3225,9 @@ doCoreDump(virQEMUDriver *driver,
             goto cleanup;
         }
     }
-    /* Core dumps usually imply last-ditch analysis efforts are
-     * desired, so we intentionally do not unlink even if a file was
-     * created.  */
     if ((fd = virQEMUFileOpenAs(cfg->user, cfg->group, false, path,
                              O_CREAT | O_TRUNC | O_WRONLY | directFlag,
-                             NULL)) < 0)
+                             &needUnlink)) < 0)
         goto cleanup;
 
     if (!(wrapperFd = virFileWrapperFdNew(&fd, path, flags)))
@@ -3282,7 +3280,7 @@ doCoreDump(virQEMUDriver *driver,
     if (qemuDomainFileWrapperFDClose(vm, wrapperFd) < 0)
         ret = -1;
     virFileWrapperFdFree(wrapperFd);
-    if (ret != 0)
+    if (ret != 0 && needUnlink)
         unlink(path);
     return ret;
 }
-- 
2.22.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