Patchwork Re: [PATCH 2/2] check for close() errors on qcow2_create()

login
register
mail settings
Submitter Eduardo Habkost
Date Oct. 8, 2010, 5:39 p.m.
Message ID <20101008173908.GQ24658@blackpad.lan.raisama.net>
Download mbox | patch
Permalink /patch/67254/
State New
Headers show

Comments

Eduardo Habkost - Oct. 8, 2010, 5:39 p.m.
On Fri, Oct 08, 2010 at 12:14:07PM +0200, Kevin Wolf wrote:
> Am 07.10.2010 22:25, schrieb Eduardo Habkost:
> > Errors when closing the file we just created should not be ignored. I/O errors
> > may happen and "qemu-img create" should fail in those cases.
> > 
> > If we are already exiting due to an error, we will still return the original
> > error number, though.
[...]
> >  exit_close:
> > -    close(fd);
> > +    cret = close(fd);
> > +    if (ret == 0 && cret < 0)
> > +        ret = -errno;
> 
> Braces are missing here.

Updated patch below.

I won't resubmit the series as a new thread, as it depends on deciding
what to do about the qcow2_create() rewrite.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 block/qcow2.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

Patch

diff --git a/block/qcow2.c b/block/qcow2.c
index c5fb28e..e2e9a95 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -882,7 +882,7 @@  static int qcow_create2(const char *filename, int64_t total_size,
     uint64_t old_ref_clusters;
     QCowCreateState s1, *s = &s1;
     QCowExtension ext_bf = {0, 0};
-    int ret;
+    int ret, cret;
 
     memset(s, 0, sizeof(*s));
 
@@ -1055,7 +1055,10 @@  exit:
     qemu_free(s->refcount_block);
 
 exit_close:
-    close(fd);
+    cret = close(fd);
+    if (ret == 0 && cret < 0) {
+        ret = -errno;
+    }
 
     /* Preallocate metadata */
     if (ret == 0 && prealloc) {