[PATCH 0/2] qemu: Random fixes

I've been migrating some machines recently and on dst didn't have VSOCK enabled in the kernel which led to 1/2. Then I've also noticed weird looking error messaged around TPM which led to 2/2. Michal Prívozník (2): qemu: Report system error on failed open() qemu_tpm: Don't report uninitialized variable in error message src/qemu/qemu_domain.c | 8 ++++---- src/qemu/qemu_process.c | 4 ++-- src/qemu/qemu_tpm.c | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) -- 2.49.1

From: Michal Privoznik <mprivozn@redhat.com> With a help from coccinelle three places were identified that call virReportError() after failed open() (in qemuDomainWriteMasterKeyFile(), qemuDomainMasterKeyReadFile() and qemuProcessOpenVhostVsock()). The open() syscall does set errno on failure so switch them to virReportSystemError() which may shed more light into the reasons for failure. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_domain.c | 8 ++++---- src/qemu/qemu_process.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 4420940745..963dbd3973 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -515,8 +515,8 @@ qemuDomainWriteMasterKeyFile(virQEMUDriver *driver, return -1; if ((fd = open(path, O_WRONLY|O_TRUNC|O_CREAT, 0600)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to open domain master key file for write")); + virReportSystemError(errno, "%s", + _("failed to open domain master key file for write")); return -1; } @@ -580,8 +580,8 @@ qemuDomainMasterKeyReadFile(qemuDomainObjPrivate *priv) } if ((fd = open(path, O_RDONLY)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to open domain master key file for read")); + virReportSystemError(errno, "%s", + _("failed to open domain master key file for read")); goto error; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 82cab3f76e..a2872602e8 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7137,8 +7137,8 @@ qemuProcessOpenVhostVsock(virDomainVsockDef *vsock) int fd; if ((fd = open(vsock_path, O_RDWR)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - "%s", _("unable to open vhost-vsock device")); + virReportSystemError(errno, "%s", + _("unable to open vhost-vsock device")); return -1; } -- 2.49.1

From: Michal Privoznik <mprivozn@redhat.com> Inside to qemu_tpm.c there are three functions that use the same pattern (qemuTPMEmulatorRunSetup(), qemuTPMEmulatorReconfigure() and qemuTPMEmulatorUpdateProfileName()): int exitstatus; ... if (virCommandRun(cmd, &exitstatus) < 0 || exitstatus != 0) { virReportError(..., exitstatus); return -1; } Problem with this pattern is that if virCommandRun() fails then exitstatus is left untouched and a garbage value is then passed to virReportError(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_tpm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index b2f76e6b8b..5ff08fccad 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -439,7 +439,7 @@ qemuTPMEmulatorRunSetup(const virDomainTPMEmulatorDef *emulator, bool incomingMigration) { g_autoptr(virCommand) cmd = NULL; - int exitstatus; + int exitstatus = -1; char uuid[VIR_UUID_STRING_BUFLEN]; g_autofree char *vmid = NULL; g_autofree char *swtpm_setup = virTPMGetSwtpmSetup(); @@ -547,7 +547,7 @@ qemuTPMEmulatorReconfigure(const virDomainTPMEmulatorDef *emulator, const unsigned char *secretuuid) { g_autoptr(virCommand) cmd = NULL; - int exitstatus; + int exitstatus = -1; g_autofree char *activePcrBanksStr = NULL; g_autofree char *swtpm_setup = virTPMGetSwtpmSetup(); g_autofree char *tpm_state = qemuTPMGetSwtpmSetupStateArg(emulator->source_type, @@ -670,7 +670,7 @@ qemuTPMEmulatorUpdateProfileName(virDomainTPMEmulatorDef *emulator, g_autofree char *swtpm = NULL; virJSONValue *active_profile; const char *profile_name; - int exitstatus; + int exitstatus = -1; if (emulator->version != VIR_DOMAIN_TPM_VERSION_2_0 || !virTPMSwtpmCapsGet(VIR_TPM_SWTPM_FEATURE_CMDARG_PRINT_INFO)) -- 2.49.1

On a Thursday in 2025, Michal Privoznik via Devel wrote:
I've been migrating some machines recently and on dst didn't have VSOCK enabled in the kernel which led to 1/2. Then I've also noticed weird looking error messaged around TPM which led to 2/2.
Michal Prívozník (2): qemu: Report system error on failed open() qemu_tpm: Don't report uninitialized variable in error message
src/qemu/qemu_domain.c | 8 ++++---- src/qemu/qemu_process.c | 4 ++-- src/qemu/qemu_tpm.c | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Michal Privoznik