]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fix errno return in safezero()
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 14 Jun 2011 08:07:39 +0000 (09:07 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 17 Jun 2011 10:02:18 +0000 (11:02 +0100)
Most of the safezero() implementations return -1 on error,
setting errno. The safezero() impl using posix_fallocate()
though returned a positive errno value on error (due to
the unusual API contract of posix_fallocate() compared to
most syscall APIs).

* src/util/util.c: Ensure safezero() returns -1 and sets
  errno on error.
* src/storage/storage_backend.c: Change safezero != 0 to
  < 0 for detecting errors

src/storage/storage_backend.c
src/util/util.c

index 8d0ea9eee6e699f8ef37780165c8c92b51b0b4c0..a6e66e1c1e81133d7fb9c9e645eed25c439fc4ee 100644 (file)
@@ -331,7 +331,7 @@ createRawFile(int fd, virStorageVolDefPtr vol,
 
                 if (bytes > remain)
                     bytes = remain;
-                if (safezero(fd, 0, vol->allocation - remain, bytes) != 0) {
+                if (safezero(fd, 0, vol->allocation - remain, bytes) < 0) {
                     ret = -errno;
                     virReportSystemError(errno, _("cannot fill file '%s'"),
                                          vol->target.path);
@@ -340,7 +340,7 @@ createRawFile(int fd, virStorageVolDefPtr vol,
                 remain -= bytes;
             }
         } else { /* No progress bars to be shown */
-            if (safezero(fd, 0, 0, remain) != 0) {
+            if (safezero(fd, 0, 0, remain) < 0) {
                 ret = -errno;
                 virReportSystemError(errno, _("cannot fill file '%s'"),
                                      vol->target.path);
index df4dfacfed341a2e4e28efb897ae81fcc0c3d8c1..8f6d8872293419eda223a74ede9e2fece0f94340 100644 (file)
@@ -136,7 +136,11 @@ safewrite(int fd, const void *buf, size_t count)
 #ifdef HAVE_POSIX_FALLOCATE
 int safezero(int fd, int flags ATTRIBUTE_UNUSED, off_t offset, off_t len)
 {
-    return posix_fallocate(fd, offset, len);
+    int ret = posix_fallocate(fd, offset, len);
+    if (ret == 0)
+        return 0;
+    errno = ret;
+    return -1;
 }
 #else