From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MPdnk-0006Xz-QC for qemu-devel@nongnu.org; Sat, 11 Jul 2009 10:43:44 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MPdng-0006PM-8C for qemu-devel@nongnu.org; Sat, 11 Jul 2009 10:43:44 -0400 Received: from [199.232.76.173] (port=39552 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MPdng-0006Oz-4B for qemu-devel@nongnu.org; Sat, 11 Jul 2009 10:43:40 -0400 Received: from moutng.kundenserver.de ([212.227.17.8]:53377) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MPdnf-0000xJ-IG for qemu-devel@nongnu.org; Sat, 11 Jul 2009 10:43:39 -0400 From: Stefan Weil Date: Sat, 11 Jul 2009 16:43:37 +0200 Message-Id: <1247323417-17395-1-git-send-email-weil@mail.berlios.de> Subject: [Qemu-devel] [PATCH] raw-posix: Handle errors in raw_create List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU Developers 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 --- block/raw-posix.c | 17 ++++++++++++----- 1 files changed, 12 insertions(+), 5 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index fa4f83e..389903e 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -852,6 +852,7 @@ again: static int raw_create(const char *filename, QEMUOptionParameter *options) { int fd; + int result = 0; int64_t total_size = 0; /* Read out options */ @@ -864,11 +865,17 @@ static int raw_create(const char *filename, QEMUOptionParameter *options) 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.5.6.5