diff options
author | Max Reitz <mreitz@redhat.com> | 2017-03-28 22:51:26 +0200 |
---|---|---|
committer | Max Reitz <mreitz@redhat.com> | 2017-04-28 16:02:02 +0200 |
commit | 55b9392b98e500399f2da1edc1d110bbfd40fb05 (patch) | |
tree | 8a248a50f5ce79664be0e3bb7d8cd7675220a3e4 /block/vhdx.c | |
parent | 2b4c0a20fbcfdba838d412d07739b2f4b6f7cd9a (diff) | |
download | qemu-55b9392b98e500399f2da1edc1d110bbfd40fb05.zip qemu-55b9392b98e500399f2da1edc1d110bbfd40fb05.tar.gz qemu-55b9392b98e500399f2da1edc1d110bbfd40fb05.tar.bz2 |
block/vhdx: Make vhdx_create() always set errp
This patch makes vhdx_create() always set errp in case of an error. It
also adds errp parameters to vhdx_create_bat() and
vhdx_create_new_region_table() so we can pass on the error object
generated by blk_truncate() as of a future commit.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-id: 20170328205129.15138-2-mreitz@redhat.com
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'block/vhdx.c')
-rw-r--r-- | block/vhdx.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/block/vhdx.c b/block/vhdx.c index 052a753..d25bcd9 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1586,7 +1586,7 @@ exit: static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s, uint64_t image_size, VHDXImageType type, bool use_zero_blocks, uint64_t file_offset, - uint32_t length) + uint32_t length, Error **errp) { int ret = 0; uint64_t data_file_offset; @@ -1609,14 +1609,19 @@ static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s, * is the furthest thing we have written yet */ ret = blk_truncate(blk, data_file_offset); if (ret < 0) { + error_setg_errno(errp, -ret, + "Failed to resize the underlying file"); goto exit; } } else if (type == VHDX_TYPE_FIXED) { ret = blk_truncate(blk, data_file_offset + image_size); if (ret < 0) { + error_setg_errno(errp, -ret, + "Failed to resize the underlying file"); goto exit; } } else { + error_setg(errp, "Unsupported image type"); ret = -ENOTSUP; goto exit; } @@ -1627,6 +1632,7 @@ static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s, /* for a fixed file, the default BAT entry is not zero */ s->bat = g_try_malloc0(length); if (length && s->bat == NULL) { + error_setg(errp, "Failed to allocate memory for the BAT"); ret = -ENOMEM; goto exit; } @@ -1646,6 +1652,7 @@ static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s, } ret = blk_pwrite(blk, file_offset, s->bat, length, 0); if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to write the BAT"); goto exit; } } @@ -1671,7 +1678,8 @@ static int vhdx_create_new_region_table(BlockBackend *blk, uint32_t log_size, bool use_zero_blocks, VHDXImageType type, - uint64_t *metadata_offset) + uint64_t *metadata_offset, + Error **errp) { int ret = 0; uint32_t offset = 0; @@ -1740,7 +1748,7 @@ static int vhdx_create_new_region_table(BlockBackend *blk, /* The region table gives us the data we need to create the BAT, * so do that now */ ret = vhdx_create_bat(blk, s, image_size, type, use_zero_blocks, - bat_file_offset, bat_length); + bat_file_offset, bat_length, errp); if (ret < 0) { goto exit; } @@ -1749,12 +1757,14 @@ static int vhdx_create_new_region_table(BlockBackend *blk, ret = blk_pwrite(blk, VHDX_REGION_TABLE_OFFSET, buffer, VHDX_HEADER_BLOCK_SIZE, 0); if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to write first region table"); goto exit; } ret = blk_pwrite(blk, VHDX_REGION_TABLE2_OFFSET, buffer, VHDX_HEADER_BLOCK_SIZE, 0); if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to write second region table"); goto exit; } @@ -1825,6 +1835,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) ret = -ENOTSUP; goto exit; } else { + error_setg(errp, "Invalid subformat '%s'", type); ret = -EINVAL; goto exit; } @@ -1879,12 +1890,14 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET, &signature, sizeof(signature), 0); if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to write file signature"); goto delete_and_exit; } if (creator) { ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET + sizeof(signature), creator, creator_items * sizeof(gunichar2), 0); if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to write creator field"); goto delete_and_exit; } } @@ -1893,13 +1906,14 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) /* Creates (B),(C) */ ret = vhdx_create_new_headers(blk, image_size, log_size); if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to write image headers"); goto delete_and_exit; } /* Creates (D),(E),(G) explicitly. (F) created as by-product */ ret = vhdx_create_new_region_table(blk, image_size, block_size, 512, log_size, use_zero_blocks, image_type, - &metadata_offset); + &metadata_offset, errp); if (ret < 0) { goto delete_and_exit; } @@ -1908,6 +1922,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) ret = vhdx_create_new_metadata(blk, image_size, block_size, 512, metadata_offset, image_type); if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to initialize metadata"); goto delete_and_exit; } |