aboutsummaryrefslogtreecommitdiffstats
path: root/block/raw-posix.c
diff options
context:
space:
mode:
authorStefan Weil <weil@mail.berlios.de>2009-07-11 16:43:37 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-07-16 17:28:49 -0500
commit1e37d05904e300a0bfc8e3240e24ecc83d54c2e3 (patch)
treebf11091805bcb5432c303342614fbefd5685026f /block/raw-posix.c
parent09ac35ac311c8d7309b5ac2d67fbcf3e4d3fd860 (diff)
raw-posix: Handle errors in raw_create
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>
Diffstat (limited to 'block/raw-posix.c')
-rw-r--r--block/raw-posix.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/block/raw-posix.c b/block/raw-posix.c
index fa4f83e8f..389903e44 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)