[libvirt] [PATCH] Log an error when we fail to set the COW attribute

Ján Tomko jtomko at redhat.com
Thu Jul 17 10:22:57 UTC 2014


Coverity complains about the return value of ioctl not being checked.

Even though we carry on when this fails (just like qemu-img does),
we can log an error.
---
 src/storage/storage_backend.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 5e7aa3c..b8b89ca 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -464,9 +464,14 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED,
          * The FS_IOC_SETFLAGS ioctl return value will be ignored since any
          * failure of this operation should not block the left work.
          */
-        if (ioctl(fd, FS_IOC_GETFLAGS, &attr) == 0) {
+        if (ioctl(fd, FS_IOC_GETFLAGS, &attr) < 0) {
+            virReportSystemError(errno, "%s", _("Failed to get fs flags"));
+        } else {
             attr |= FS_NOCOW_FL;
-            ioctl(fd, FS_IOC_SETFLAGS, &attr);
+            if (ioctl(fd, FS_IOC_SETFLAGS, &attr) < 0) {
+                virReportSystemError(errno, "%s",
+                                     _("Failed to set NOCOW flag"));
+            }
         }
 #endif
     }
-- 
1.8.5.5




More information about the libvir-list mailing list