From d4aecf6259512c97dcc08c6378ef472ba4ba40e5 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost <ehabkost@redhat.com> Date: Fri, 25 Sep 2009 13:40:39 -0300 Subject: [PATCH 2/2] raw-posix: Handle errors in raw_create RH-Author: Kevin Wolf <kwolf@redhat.com> Message-id: <1253625902-10709-3-git-send-email-kwolf@redhat.com> Patchwork-id: 3505 O-Subject: [PATCH 2/2] raw-posix: Handle errors in raw_create Bugzilla: 511072 RH-Acked-by: Juan Quintela <quintela@redhat.com> RH-Acked-by: Markus Armbruster <armbru@redhat.com> RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com> From: Stefan Weil <weil@mail.berlios.de> Bugzilla: 511072 Upstream commit: 1e37d05904e300a0bfc8e3240e24ecc83d54c2e3 In qemu-iotests, some large images are created using qemu-img. Without checks for errors, qemu-img will just create an empty image, and later read / write tests will fail. With the patch, failures during image creation are detected and reported. Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com> --- qemu/block-raw-posix.c | 17 ++++++++++++----- 1 files changed, 12 insertions(+), 5 deletions(-) Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- qemu/block-raw-posix.c | 17 ++++++++++++----- 1 files changed, 12 insertions(+), 5 deletions(-) diff --git a/qemu/block-raw-posix.c b/qemu/block-raw-posix.c index 4ec0618..a5850f4 100644 --- a/qemu/block-raw-posix.c +++ b/qemu/block-raw-posix.c @@ -790,17 +790,24 @@ static int raw_create(const char *filename, int64_t total_size, const char *backing_file, int flags) { int fd; + int result = 0; if (flags || backing_file) return -ENOTSUP; fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); - if (fd < 0) - return -EIO; - ftruncate(fd, total_size * 512); - close(fd); - return 0; + if (fd < 0) { + result = -errno; + } else { + if (ftruncate(fd, total_size * 512) != 0) { + result = -errno; + } + if (close(fd) != 0) { + result = -errno; + } + } + return result; } static void raw_flush(BlockDriverState *bs) -- 1.6.3.rc4.29.g8146