From 5bf83d85e5e0ee5d053f5e69b488736e7c7e2ae8 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Thu, 7 Oct 2010 20:31:29 -0300 Subject: [RHEL6 qemu-kvm PATCH 3/3] check for close() errors on qcow2_create() RH-Author: Eduardo Habkost Message-id: <1286483489-10946-1-git-send-email-ehabkost@redhat.com> Patchwork-id: 12457 O-Subject: [RHEL6 qemu-kvm PATCH] check for close() errors on qcow2_create() Bugzilla: 641127 RH-Acked-by: Zachary Amsden RH-Acked-by: Christoph Hellwig RH-Acked-by: Jes Sorensen 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. Bugzilla: 641127 Upstream status: submitted Signed-off-by: Eduardo Habkost --- block/qcow2.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) Signed-off-by: Eduardo Habkost --- block/qcow2.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 258de50..d7a05af 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -863,7 +863,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)); @@ -1033,7 +1033,10 @@ static int qcow_create2(const char *filename, int64_t total_size, exit: qemu_free(s->refcount_table); qemu_free(s->refcount_block); - close(fd); + + cret = close(fd); + if (ret == 0 && cret < 0) + ret = -errno; /* Preallocate metadata */ if (ret == 0 && prealloc) { -- 1.6.5.5