[PATCH 1/2] qemu: Report system error on failed open()

Michal Privoznik via Devel posted 2 patches 1 month, 3 weeks ago
[PATCH 1/2] qemu: Report system error on failed open()
Posted by Michal Privoznik via Devel 1 month, 3 weeks ago
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