c1c534
From 9c5a70bc8c9332de2e769226efe81cb95b1ce2a4 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <9c5a70bc8c9332de2e769226efe81cb95b1ce2a4@dist-git>
c1c534
From: Michal Privoznik <mprivozn@redhat.com>
c1c534
Date: Fri, 2 Feb 2018 11:12:36 +0100
c1c534
Subject: [PATCH] qemuDomainRemoveMemoryDevice: unlink() memory backing file
c1c534
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1461214
c1c534
c1c534
Since fec8f9c49af we try to use predictable file names for
c1c534
'memory-backend-file' objects. But that made us provide full path
c1c534
to qemu when hot plugging the object while previously we provided
c1c534
merely a directory. But this makes qemu behave differently. If
c1c534
qemu sees a path terminated with a directory it calls mkstemp()
c1c534
and unlinks the file immediately. But if it sees full path it
c1c534
just calls open(path, O_CREAT ..); and never unlinks the file.
c1c534
Therefore it's up to libvirt to unlink the file and not leave it
c1c534
behind.
c1c534
c1c534
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
c1c534
(cherry picked from commit 4d83a6722f5b9c10ee85d5a5ffee364ac0e7b8af)
c1c534
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
c1c534
---
c1c534
 src/qemu/qemu_hotplug.c |  3 +++
c1c534
 src/qemu/qemu_process.c | 26 ++++++++++++++++++++++++++
c1c534
 src/qemu/qemu_process.h |  4 ++++
c1c534
 3 files changed, 33 insertions(+)
c1c534
c1c534
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
c1c534
index f1056627f2..831e014d9c 100644
c1c534
--- a/src/qemu/qemu_hotplug.c
c1c534
+++ b/src/qemu/qemu_hotplug.c
c1c534
@@ -3803,6 +3803,9 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver,
c1c534
     if (qemuDomainNamespaceTeardownMemory(driver, vm, mem) <  0)
c1c534
         VIR_WARN("Unable to remove memory device from /dev");
c1c534
 
c1c534
+    if (qemuProcessDestroyMemoryBackingPath(driver, vm, mem) < 0)
c1c534
+        VIR_WARN("Unable to destroy memory backing path");
c1c534
+
c1c534
     virDomainMemoryDefFree(mem);
c1c534
 
c1c534
     /* fix the balloon size */
c1c534
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
c1c534
index caf967dac5..3853112924 100644
c1c534
--- a/src/qemu/qemu_process.c
c1c534
+++ b/src/qemu/qemu_process.c
c1c534
@@ -3491,6 +3491,32 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
c1c534
 }
c1c534
 
c1c534
 
c1c534
+int
c1c534
+qemuProcessDestroyMemoryBackingPath(virQEMUDriverPtr driver,
c1c534
+                                    virDomainObjPtr vm,
c1c534
+                                    virDomainMemoryDefPtr mem)
c1c534
+{
c1c534
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
c1c534
+    char *path = NULL;
c1c534
+    int ret = -1;
c1c534
+
c1c534
+    if (qemuGetMemoryBackingPath(vm->def, cfg, mem->info.alias, &path) < 0)
c1c534
+        goto cleanup;
c1c534
+
c1c534
+    if (unlink(path) < 0 &&
c1c534
+        errno != ENOENT) {
c1c534
+        virReportSystemError(errno, _("Unable to remove %s"), path);
c1c534
+        goto cleanup;
c1c534
+    }
c1c534
+
c1c534
+    ret = 0;
c1c534
+ cleanup:
c1c534
+    VIR_FREE(path);
c1c534
+    virObjectUnref(cfg);
c1c534
+    return ret;
c1c534
+}
c1c534
+
c1c534
+
c1c534
 static int
c1c534
 qemuProcessVNCAllocatePorts(virQEMUDriverPtr driver,
c1c534
                             virDomainGraphicsDefPtr graphics,
c1c534
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
c1c534
index b383ff309b..8d210282f8 100644
c1c534
--- a/src/qemu/qemu_process.h
c1c534
+++ b/src/qemu/qemu_process.h
c1c534
@@ -43,6 +43,10 @@ int qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
c1c534
                                        virDomainMemoryDefPtr mem,
c1c534
                                        bool build);
c1c534
 
c1c534
+int qemuProcessDestroyMemoryBackingPath(virQEMUDriverPtr driver,
c1c534
+                                        virDomainObjPtr vm,
c1c534
+                                        virDomainMemoryDefPtr mem);
c1c534
+
c1c534
 void qemuProcessAutostartAll(virQEMUDriverPtr driver);
c1c534
 void qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr driver);
c1c534
 
c1c534
-- 
c1c534
2.16.1
c1c534