Commit 1e37d05904e300a0bfc8e3240e24ecc83d54c2e3
Committed by
Anthony Liguori
1 parent
09ac35ac
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>
Showing
1 changed file
with
12 additions
and
5 deletions
block/raw-posix.c
... | ... | @@ -852,6 +852,7 @@ again: |
852 | 852 | static int raw_create(const char *filename, QEMUOptionParameter *options) |
853 | 853 | { |
854 | 854 | int fd; |
855 | + int result = 0; | |
855 | 856 | int64_t total_size = 0; |
856 | 857 | |
857 | 858 | /* Read out options */ |
... | ... | @@ -864,11 +865,17 @@ static int raw_create(const char *filename, QEMUOptionParameter *options) |
864 | 865 | |
865 | 866 | fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, |
866 | 867 | 0644); |
867 | - if (fd < 0) | |
868 | - return -EIO; | |
869 | - ftruncate(fd, total_size * 512); | |
870 | - close(fd); | |
871 | - return 0; | |
868 | + if (fd < 0) { | |
869 | + result = -errno; | |
870 | + } else { | |
871 | + if (ftruncate(fd, total_size * 512) != 0) { | |
872 | + result = -errno; | |
873 | + } | |
874 | + if (close(fd) != 0) { | |
875 | + result = -errno; | |
876 | + } | |
877 | + } | |
878 | + return result; | |
872 | 879 | } |
873 | 880 | |
874 | 881 | static void raw_flush(BlockDriverState *bs) | ... | ... |