render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 9c5a70bc8c9332de2e769226efe81cb95b1ce2a4 Mon Sep 17 00:00:00 2001
Message-Id: <9c5a70bc8c9332de2e769226efe81cb95b1ce2a4@dist-git>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Fri, 2 Feb 2018 11:12:36 +0100
Subject: [PATCH] qemuDomainRemoveMemoryDevice: unlink() memory backing file

https://bugzilla.redhat.com/show_bug.cgi?id=1461214

Since fec8f9c49af we try to use predictable file names for
'memory-backend-file' objects. But that made us provide full path
to qemu when hot plugging the object while previously we provided
merely a directory. But this makes qemu behave differently. If
qemu sees a path terminated with a directory it calls mkstemp()
and unlinks the file immediately. But if it sees full path it
just calls open(path, O_CREAT ..); and never unlinks the file.
Therefore it's up to libvirt to unlink the file and not leave it
behind.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit 4d83a6722f5b9c10ee85d5a5ffee364ac0e7b8af)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_hotplug.c |  3 +++
 src/qemu/qemu_process.c | 26 ++++++++++++++++++++++++++
 src/qemu/qemu_process.h |  4 ++++
 3 files changed, 33 insertions(+)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index f1056627f2..831e014d9c 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -3803,6 +3803,9 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver,
     if (qemuDomainNamespaceTeardownMemory(driver, vm, mem) <  0)
         VIR_WARN("Unable to remove memory device from /dev");
 
+    if (qemuProcessDestroyMemoryBackingPath(driver, vm, mem) < 0)
+        VIR_WARN("Unable to destroy memory backing path");
+
     virDomainMemoryDefFree(mem);
 
     /* fix the balloon size */
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index caf967dac5..3853112924 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3491,6 +3491,32 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
 }
 
 
+int
+qemuProcessDestroyMemoryBackingPath(virQEMUDriverPtr driver,
+                                    virDomainObjPtr vm,
+                                    virDomainMemoryDefPtr mem)
+{
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    char *path = NULL;
+    int ret = -1;
+
+    if (qemuGetMemoryBackingPath(vm->def, cfg, mem->info.alias, &path) < 0)
+        goto cleanup;
+
+    if (unlink(path) < 0 &&
+        errno != ENOENT) {
+        virReportSystemError(errno, _("Unable to remove %s"), path);
+        goto cleanup;
+    }
+
+    ret = 0;
+ cleanup:
+    VIR_FREE(path);
+    virObjectUnref(cfg);
+    return ret;
+}
+
+
 static int
 qemuProcessVNCAllocatePorts(virQEMUDriverPtr driver,
                             virDomainGraphicsDefPtr graphics,
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index b383ff309b..8d210282f8 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -43,6 +43,10 @@ int qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
                                        virDomainMemoryDefPtr mem,
                                        bool build);
 
+int qemuProcessDestroyMemoryBackingPath(virQEMUDriverPtr driver,
+                                        virDomainObjPtr vm,
+                                        virDomainMemoryDefPtr mem);
+
 void qemuProcessAutostartAll(virQEMUDriverPtr driver);
 void qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr driver);
 
-- 
2.16.1