qemu_tpm: do not delete parent directory for custom source

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@redhat.com>
Tested-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Marc-André Lureau 2024-12-11 14:37:14 +04:00 committed by Michal Privoznik
parent 958283a21f
commit 062a2c07cc

View File

@ -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;
ignore_value(virFileDeleteTree(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;
}
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));
}
}
}