[PATCH v2 3/3] qemu_tpm: do not delete parent directory for custom source

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

 



From: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>

When the vTPM source path is specified, such as:
   <source type=".." path="/my/tpm"/>

Do not delete the parent directory, but only the given file/dir.

Fixes: commit f1304cc566 ("qemu_tpm: handle file/block storage source")

Signed-off-by: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>
---
 src/qemu/qemu_tpm.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
index 942ee64263..3e97518c06 100644
--- a/src/qemu/qemu_tpm.c
+++ b/src/qemu/qemu_tpm.c
@@ -214,9 +214,31 @@ qemuTPMEmulatorCreateStorage(virDomainTPMDef *tpm,
 static void
 qemuTPMEmulatorDeleteStorage(virDomainTPMDef *tpm)
 {
-    g_autofree char *path = g_path_get_dirname(tpm->data.emulator.source_path);
+    const char *source_path = tpm->data.emulator.source_path;
+
+    switch (tpm->data.emulator.source_type) {
+    case VIR_DOMAIN_TPM_SOURCE_TYPE_FILE: {
+        if (unlink(source_path) && errno != ENOENT)
+            virReportSystemError(errno,
+                                 _("Cannot delete file '%1$s'"),
+                                 source_path);
+        break;
+    }
+
+    case VIR_DOMAIN_TPM_SOURCE_TYPE_DIR: {
+        ignore_value(virFileDeleteTree(source_path));
+        break;
+    }
 
-    ignore_value(virFileDeleteTree(path));
+    case VIR_DOMAIN_TPM_SOURCE_TYPE_DEFAULT:
+    case VIR_DOMAIN_TPM_SOURCE_TYPE_LAST:
+    default: {
+        g_autofree char *vm_uuid_dir = g_path_get_dirname(source_path);
+
+        ignore_value(virFileDeleteTree(vm_uuid_dir));
+    }
+
+    }
 }
 
 
-- 
2.47.0




[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