|
|
9ae3a8 |
From 57c326f0b2220c9bbe1968f3cc251ae2f99db8ae Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Date: Wed, 6 Nov 2013 16:53:40 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 83/87] vmdk: convert error code to use errp
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1383756824-6921-18-git-send-email-mreitz@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 55572
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 17/21] vmdk: convert error code to use errp
|
|
|
9ae3a8 |
Bugzilla: 980771
|
|
|
9ae3a8 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
From: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
BZ: 980771
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Convert "fprintf(stderr,..." and standardize error messages:
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Remove a few local_error's and use errp.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Remove "VMDK:" or "Vmdk:" prefixes in error message and fix to upper
|
|
|
9ae3a8 |
case.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 4823970bcb882cd5b7e9c9a21fa6573190035050)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Conflicts:
|
|
|
9ae3a8 |
block/vmdk.c
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Conflicts because the series "Implement reference count for
|
|
|
9ae3a8 |
BlockDriverState" has not yet been backported which "replaces"
|
|
|
9ae3a8 |
bdrv_delete by bdrv_unref.
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/vmdk.c | 116 ++++++++++++++++++++++++---------------------
|
|
|
9ae3a8 |
tests/qemu-iotests/059.out | 6 +--
|
|
|
9ae3a8 |
2 files changed, 63 insertions(+), 59 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/vmdk.c | 116 +++++++++++++++++++++++---------------------
|
|
|
9ae3a8 |
tests/qemu-iotests/059.out | 6 +--
|
|
|
9ae3a8 |
2 files changed, 63 insertions(+), 59 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/vmdk.c b/block/vmdk.c
|
|
|
9ae3a8 |
index bd1dd62..96f9415 100644
|
|
|
9ae3a8 |
--- a/block/vmdk.c
|
|
|
9ae3a8 |
+++ b/block/vmdk.c
|
|
|
9ae3a8 |
@@ -331,8 +331,7 @@ static int vmdk_reopen_prepare(BDRVReopenState *state,
|
|
|
9ae3a8 |
assert(state->bs != NULL);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (queue == NULL) {
|
|
|
9ae3a8 |
- error_set(errp, ERROR_CLASS_GENERIC_ERROR,
|
|
|
9ae3a8 |
- "No reopen queue for VMDK extents");
|
|
|
9ae3a8 |
+ error_setg(errp, "No reopen queue for VMDK extents");
|
|
|
9ae3a8 |
goto exit;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -391,22 +390,23 @@ static int vmdk_add_extent(BlockDriverState *bs,
|
|
|
9ae3a8 |
int64_t l1_offset, int64_t l1_backup_offset,
|
|
|
9ae3a8 |
uint32_t l1_size,
|
|
|
9ae3a8 |
int l2_size, uint64_t cluster_sectors,
|
|
|
9ae3a8 |
- VmdkExtent **new_extent)
|
|
|
9ae3a8 |
+ VmdkExtent **new_extent,
|
|
|
9ae3a8 |
+ Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
VmdkExtent *extent;
|
|
|
9ae3a8 |
BDRVVmdkState *s = bs->opaque;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (cluster_sectors > 0x200000) {
|
|
|
9ae3a8 |
/* 0x200000 * 512Bytes = 1GB for one cluster is unrealistic */
|
|
|
9ae3a8 |
- error_report("invalid granularity, image may be corrupt");
|
|
|
9ae3a8 |
- return -EINVAL;
|
|
|
9ae3a8 |
+ error_setg(errp, "Invalid granularity, image may be corrupt");
|
|
|
9ae3a8 |
+ return -EFBIG;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
if (l1_size > 512 * 1024 * 1024) {
|
|
|
9ae3a8 |
/* Although with big capacity and small l1_entry_sectors, we can get a
|
|
|
9ae3a8 |
* big l1_size, we don't want unbounded value to allocate the table.
|
|
|
9ae3a8 |
* Limit it to 512M, which is 16PB for default cluster and L2 table
|
|
|
9ae3a8 |
* size */
|
|
|
9ae3a8 |
- error_report("L1 size too big");
|
|
|
9ae3a8 |
+ error_setg(errp, "L1 size too big");
|
|
|
9ae3a8 |
return -EFBIG;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -438,7 +438,8 @@ static int vmdk_add_extent(BlockDriverState *bs,
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent)
|
|
|
9ae3a8 |
+static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent,
|
|
|
9ae3a8 |
+ Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
int l1_size, i;
|
|
|
9ae3a8 |
@@ -447,10 +448,13 @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent)
|
|
|
9ae3a8 |
l1_size = extent->l1_size * sizeof(uint32_t);
|
|
|
9ae3a8 |
extent->l1_table = g_malloc(l1_size);
|
|
|
9ae3a8 |
ret = bdrv_pread(extent->file,
|
|
|
9ae3a8 |
- extent->l1_table_offset,
|
|
|
9ae3a8 |
- extent->l1_table,
|
|
|
9ae3a8 |
- l1_size);
|
|
|
9ae3a8 |
+ extent->l1_table_offset,
|
|
|
9ae3a8 |
+ extent->l1_table,
|
|
|
9ae3a8 |
+ l1_size);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret,
|
|
|
9ae3a8 |
+ "Could not read l1 table from extent '%s'",
|
|
|
9ae3a8 |
+ extent->file->filename);
|
|
|
9ae3a8 |
goto fail_l1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
for (i = 0; i < extent->l1_size; i++) {
|
|
|
9ae3a8 |
@@ -460,10 +464,13 @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent)
|
|
|
9ae3a8 |
if (extent->l1_backup_table_offset) {
|
|
|
9ae3a8 |
extent->l1_backup_table = g_malloc(l1_size);
|
|
|
9ae3a8 |
ret = bdrv_pread(extent->file,
|
|
|
9ae3a8 |
- extent->l1_backup_table_offset,
|
|
|
9ae3a8 |
- extent->l1_backup_table,
|
|
|
9ae3a8 |
- l1_size);
|
|
|
9ae3a8 |
+ extent->l1_backup_table_offset,
|
|
|
9ae3a8 |
+ extent->l1_backup_table,
|
|
|
9ae3a8 |
+ l1_size);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret,
|
|
|
9ae3a8 |
+ "Could not read l1 backup table from extent '%s'",
|
|
|
9ae3a8 |
+ extent->file->filename);
|
|
|
9ae3a8 |
goto fail_l1b;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
for (i = 0; i < extent->l1_size; i++) {
|
|
|
9ae3a8 |
@@ -483,7 +490,7 @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static int vmdk_open_vmfs_sparse(BlockDriverState *bs,
|
|
|
9ae3a8 |
BlockDriverState *file,
|
|
|
9ae3a8 |
- int flags)
|
|
|
9ae3a8 |
+ int flags, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
uint32_t magic;
|
|
|
9ae3a8 |
@@ -492,6 +499,9 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header));
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret,
|
|
|
9ae3a8 |
+ "Could not read header from file '%s'",
|
|
|
9ae3a8 |
+ file->filename);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
ret = vmdk_add_extent(bs, file, false,
|
|
|
9ae3a8 |
@@ -501,11 +511,12 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,
|
|
|
9ae3a8 |
le32_to_cpu(header.l1dir_size),
|
|
|
9ae3a8 |
4096,
|
|
|
9ae3a8 |
le32_to_cpu(header.granularity),
|
|
|
9ae3a8 |
- &extent);
|
|
|
9ae3a8 |
+ &extent,
|
|
|
9ae3a8 |
+ errp);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- ret = vmdk_init_tables(bs, extent);
|
|
|
9ae3a8 |
+ ret = vmdk_init_tables(bs, extent, errp);
|
|
|
9ae3a8 |
if (ret) {
|
|
|
9ae3a8 |
/* free extent allocated by vmdk_add_extent */
|
|
|
9ae3a8 |
vmdk_free_last_extent(bs);
|
|
|
9ae3a8 |
@@ -514,11 +525,11 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static int vmdk_open_desc_file(BlockDriverState *bs, int flags,
|
|
|
9ae3a8 |
- uint64_t desc_offset);
|
|
|
9ae3a8 |
+ uint64_t desc_offset, Error **errp);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static int vmdk_open_vmdk4(BlockDriverState *bs,
|
|
|
9ae3a8 |
BlockDriverState *file,
|
|
|
9ae3a8 |
- int flags)
|
|
|
9ae3a8 |
+ int flags, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
uint32_t magic;
|
|
|
9ae3a8 |
@@ -529,12 +540,14 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header));
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret,
|
|
|
9ae3a8 |
+ "Could not read header from file '%s'",
|
|
|
9ae3a8 |
+ file->filename);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
if (header.capacity == 0) {
|
|
|
9ae3a8 |
uint64_t desc_offset = le64_to_cpu(header.desc_offset);
|
|
|
9ae3a8 |
if (desc_offset) {
|
|
|
9ae3a8 |
- return vmdk_open_desc_file(bs, flags, desc_offset << 9);
|
|
|
9ae3a8 |
+ return vmdk_open_desc_file(bs, flags, desc_offset << 9, errp);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -616,7 +629,8 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
|
|
|
9ae3a8 |
l1_size,
|
|
|
9ae3a8 |
le32_to_cpu(header.num_gtes_per_gt),
|
|
|
9ae3a8 |
le64_to_cpu(header.granularity),
|
|
|
9ae3a8 |
- &extent);
|
|
|
9ae3a8 |
+ &extent,
|
|
|
9ae3a8 |
+ errp);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -625,7 +639,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
|
|
|
9ae3a8 |
extent->has_marker = le32_to_cpu(header.flags) & VMDK4_FLAG_MARKER;
|
|
|
9ae3a8 |
extent->version = le32_to_cpu(header.version);
|
|
|
9ae3a8 |
extent->has_zero_grain = le32_to_cpu(header.flags) & VMDK4_FLAG_ZERO_GRAIN;
|
|
|
9ae3a8 |
- ret = vmdk_init_tables(bs, extent);
|
|
|
9ae3a8 |
+ ret = vmdk_init_tables(bs, extent, errp);
|
|
|
9ae3a8 |
if (ret) {
|
|
|
9ae3a8 |
/* free extent allocated by vmdk_add_extent */
|
|
|
9ae3a8 |
vmdk_free_last_extent(bs);
|
|
|
9ae3a8 |
@@ -663,7 +677,7 @@ static int vmdk_parse_description(const char *desc, const char *opt_name,
|
|
|
9ae3a8 |
/* Open an extent file and append to bs array */
|
|
|
9ae3a8 |
static int vmdk_open_sparse(BlockDriverState *bs,
|
|
|
9ae3a8 |
BlockDriverState *file,
|
|
|
9ae3a8 |
- int flags)
|
|
|
9ae3a8 |
+ int flags, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
uint32_t magic;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -674,10 +688,10 @@ static int vmdk_open_sparse(BlockDriverState *bs,
|
|
|
9ae3a8 |
magic = be32_to_cpu(magic);
|
|
|
9ae3a8 |
switch (magic) {
|
|
|
9ae3a8 |
case VMDK3_MAGIC:
|
|
|
9ae3a8 |
- return vmdk_open_vmfs_sparse(bs, file, flags);
|
|
|
9ae3a8 |
+ return vmdk_open_vmfs_sparse(bs, file, flags, errp);
|
|
|
9ae3a8 |
break;
|
|
|
9ae3a8 |
case VMDK4_MAGIC:
|
|
|
9ae3a8 |
- return vmdk_open_vmdk4(bs, file, flags);
|
|
|
9ae3a8 |
+ return vmdk_open_vmdk4(bs, file, flags, errp);
|
|
|
9ae3a8 |
break;
|
|
|
9ae3a8 |
default:
|
|
|
9ae3a8 |
return -EMEDIUMTYPE;
|
|
|
9ae3a8 |
@@ -686,7 +700,7 @@ static int vmdk_open_sparse(BlockDriverState *bs,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
|
|
|
9ae3a8 |
- const char *desc_file_path)
|
|
|
9ae3a8 |
+ const char *desc_file_path, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
char access[11];
|
|
|
9ae3a8 |
@@ -697,7 +711,6 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
|
|
|
9ae3a8 |
int64_t flat_offset;
|
|
|
9ae3a8 |
char extent_path[PATH_MAX];
|
|
|
9ae3a8 |
BlockDriverState *extent_file;
|
|
|
9ae3a8 |
- Error *local_err = NULL;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
while (*p) {
|
|
|
9ae3a8 |
/* parse extent line:
|
|
|
9ae3a8 |
@@ -712,9 +725,11 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
|
|
|
9ae3a8 |
goto next_line;
|
|
|
9ae3a8 |
} else if (!strcmp(type, "FLAT")) {
|
|
|
9ae3a8 |
if (ret != 5 || flat_offset < 0) {
|
|
|
9ae3a8 |
+ error_setg(errp, "Invalid extent lines: \n%s", p);
|
|
|
9ae3a8 |
return -EINVAL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
} else if (ret != 4) {
|
|
|
9ae3a8 |
+ error_setg(errp, "Invalid extent lines: \n%s", p);
|
|
|
9ae3a8 |
return -EINVAL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -728,10 +743,8 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
|
|
|
9ae3a8 |
path_combine(extent_path, sizeof(extent_path),
|
|
|
9ae3a8 |
desc_file_path, fname);
|
|
|
9ae3a8 |
ret = bdrv_file_open(&extent_file, extent_path, NULL, bs->open_flags,
|
|
|
9ae3a8 |
- &local_err);
|
|
|
9ae3a8 |
+ errp);
|
|
|
9ae3a8 |
if (ret) {
|
|
|
9ae3a8 |
- qerror_report_err(local_err);
|
|
|
9ae3a8 |
- error_free(local_err);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -741,21 +754,20 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
|
|
|
9ae3a8 |
VmdkExtent *extent;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret = vmdk_add_extent(bs, extent_file, true, sectors,
|
|
|
9ae3a8 |
- 0, 0, 0, 0, 0, &extent);
|
|
|
9ae3a8 |
+ 0, 0, 0, 0, 0, &extent, errp);
|
|
|
9ae3a8 |
if (ret < 0) {
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
extent->flat_start_offset = flat_offset << 9;
|
|
|
9ae3a8 |
} else if (!strcmp(type, "SPARSE") || !strcmp(type, "VMFSSPARSE")) {
|
|
|
9ae3a8 |
/* SPARSE extent and VMFSSPARSE extent are both "COWD" sparse file*/
|
|
|
9ae3a8 |
- ret = vmdk_open_sparse(bs, extent_file, bs->open_flags);
|
|
|
9ae3a8 |
+ ret = vmdk_open_sparse(bs, extent_file, bs->open_flags, errp);
|
|
|
9ae3a8 |
if (ret) {
|
|
|
9ae3a8 |
bdrv_delete(extent_file);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
- fprintf(stderr,
|
|
|
9ae3a8 |
- "VMDK: Not supported extent type \"%s\""".\n", type);
|
|
|
9ae3a8 |
+ error_setg(errp, "Unsupported extent type '%s'", type);
|
|
|
9ae3a8 |
return -ENOTSUP;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
next_line:
|
|
|
9ae3a8 |
@@ -769,7 +781,7 @@ next_line:
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static int vmdk_open_desc_file(BlockDriverState *bs, int flags,
|
|
|
9ae3a8 |
- uint64_t desc_offset)
|
|
|
9ae3a8 |
+ uint64_t desc_offset, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
char *buf = NULL;
|
|
|
9ae3a8 |
@@ -798,13 +810,12 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags,
|
|
|
9ae3a8 |
strcmp(ct, "vmfsSparse") &&
|
|
|
9ae3a8 |
strcmp(ct, "twoGbMaxExtentSparse") &&
|
|
|
9ae3a8 |
strcmp(ct, "twoGbMaxExtentFlat")) {
|
|
|
9ae3a8 |
- fprintf(stderr,
|
|
|
9ae3a8 |
- "VMDK: Not supported image type \"%s\""".\n", ct);
|
|
|
9ae3a8 |
+ error_setg(errp, "Unsupported image type '%s'", ct);
|
|
|
9ae3a8 |
ret = -ENOTSUP;
|
|
|
9ae3a8 |
goto exit;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
s->desc_offset = 0;
|
|
|
9ae3a8 |
- ret = vmdk_parse_extents(buf, bs, bs->file->filename);
|
|
|
9ae3a8 |
+ ret = vmdk_parse_extents(buf, bs, bs->file->filename, errp);
|
|
|
9ae3a8 |
exit:
|
|
|
9ae3a8 |
g_free(buf);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
@@ -816,10 +827,10 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
BDRVVmdkState *s = bs->opaque;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (vmdk_open_sparse(bs, bs->file, flags) == 0) {
|
|
|
9ae3a8 |
+ if (vmdk_open_sparse(bs, bs->file, flags, errp) == 0) {
|
|
|
9ae3a8 |
s->desc_offset = 0x200;
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
- ret = vmdk_open_desc_file(bs, flags, 0);
|
|
|
9ae3a8 |
+ ret = vmdk_open_desc_file(bs, flags, 0, errp);
|
|
|
9ae3a8 |
if (ret) {
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -1286,8 +1297,7 @@ static int vmdk_write(BlockDriverState *bs, int64_t sector_num,
|
|
|
9ae3a8 |
VmdkMetaData m_data;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (sector_num > bs->total_sectors) {
|
|
|
9ae3a8 |
- fprintf(stderr,
|
|
|
9ae3a8 |
- "(VMDK) Wrong offset: sector_num=0x%" PRIx64
|
|
|
9ae3a8 |
+ error_report("Wrong offset: sector_num=0x%" PRIx64
|
|
|
9ae3a8 |
" total_sectors=0x%" PRIx64 "\n",
|
|
|
9ae3a8 |
sector_num, bs->total_sectors);
|
|
|
9ae3a8 |
return -EIO;
|
|
|
9ae3a8 |
@@ -1307,9 +1317,8 @@ static int vmdk_write(BlockDriverState *bs, int64_t sector_num,
|
|
|
9ae3a8 |
if (extent->compressed) {
|
|
|
9ae3a8 |
if (ret == VMDK_OK) {
|
|
|
9ae3a8 |
/* Refuse write to allocated cluster for streamOptimized */
|
|
|
9ae3a8 |
- fprintf(stderr,
|
|
|
9ae3a8 |
- "VMDK: can't write to allocated cluster"
|
|
|
9ae3a8 |
- " for streamOptimized\n");
|
|
|
9ae3a8 |
+ error_report("Could not write to allocated cluster"
|
|
|
9ae3a8 |
+ " for streamOptimized");
|
|
|
9ae3a8 |
return -EIO;
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
/* allocate */
|
|
|
9ae3a8 |
@@ -1517,12 +1526,12 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static int filename_decompose(const char *filename, char *path, char *prefix,
|
|
|
9ae3a8 |
- char *postfix, size_t buf_len)
|
|
|
9ae3a8 |
+ char *postfix, size_t buf_len, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
const char *p, *q;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (filename == NULL || !strlen(filename)) {
|
|
|
9ae3a8 |
- fprintf(stderr, "Vmdk: no filename provided.\n");
|
|
|
9ae3a8 |
+ error_setg(errp, "No filename provided");
|
|
|
9ae3a8 |
return VMDK_ERROR;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
p = strrchr(filename, '/');
|
|
|
9ae3a8 |
@@ -1595,9 +1604,8 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
"ddb.geometry.heads = \"%d\"\n"
|
|
|
9ae3a8 |
"ddb.geometry.sectors = \"63\"\n"
|
|
|
9ae3a8 |
"ddb.adapterType = \"%s\"\n";
|
|
|
9ae3a8 |
- Error *local_err = NULL;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (filename_decompose(filename, path, prefix, postfix, PATH_MAX)) {
|
|
|
9ae3a8 |
+ if (filename_decompose(filename, path, prefix, postfix, PATH_MAX, errp)) {
|
|
|
9ae3a8 |
return -EINVAL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
/* Read out options */
|
|
|
9ae3a8 |
@@ -1623,7 +1631,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
strcmp(adapter_type, "buslogic") &&
|
|
|
9ae3a8 |
strcmp(adapter_type, "lsilogic") &&
|
|
|
9ae3a8 |
strcmp(adapter_type, "legacyESX")) {
|
|
|
9ae3a8 |
- fprintf(stderr, "VMDK: Unknown adapter type: '%s'.\n", adapter_type);
|
|
|
9ae3a8 |
+ error_setg(errp, "Unknown adapter type: '%s'", adapter_type);
|
|
|
9ae3a8 |
return -EINVAL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
if (strcmp(adapter_type, "ide") != 0) {
|
|
|
9ae3a8 |
@@ -1639,7 +1647,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
strcmp(fmt, "twoGbMaxExtentSparse") &&
|
|
|
9ae3a8 |
strcmp(fmt, "twoGbMaxExtentFlat") &&
|
|
|
9ae3a8 |
strcmp(fmt, "streamOptimized")) {
|
|
|
9ae3a8 |
- fprintf(stderr, "VMDK: Unknown subformat: %s\n", fmt);
|
|
|
9ae3a8 |
+ error_setg(errp, "Unknown subformat: '%s'", fmt);
|
|
|
9ae3a8 |
return -EINVAL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
split = !(strcmp(fmt, "twoGbMaxExtentFlat") &&
|
|
|
9ae3a8 |
@@ -1653,15 +1661,13 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
desc_extent_line = "RW %lld SPARSE \"%s\"\n";
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
if (flat && backing_file) {
|
|
|
9ae3a8 |
- /* not supporting backing file for flat image */
|
|
|
9ae3a8 |
+ error_setg(errp, "Flat image can't have backing file");
|
|
|
9ae3a8 |
return -ENOTSUP;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
if (backing_file) {
|
|
|
9ae3a8 |
BlockDriverState *bs = bdrv_new("");
|
|
|
9ae3a8 |
- ret = bdrv_open(bs, backing_file, NULL, 0, NULL, &local_err);
|
|
|
9ae3a8 |
+ ret = bdrv_open(bs, backing_file, NULL, 0, NULL, errp);
|
|
|
9ae3a8 |
if (ret != 0) {
|
|
|
9ae3a8 |
- qerror_report_err(local_err);
|
|
|
9ae3a8 |
- error_free(local_err);
|
|
|
9ae3a8 |
bdrv_delete(bs);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
|
|
|
9ae3a8 |
index 9159dbe..dc4f024 100644
|
|
|
9ae3a8 |
--- a/tests/qemu-iotests/059.out
|
|
|
9ae3a8 |
+++ b/tests/qemu-iotests/059.out
|
|
|
9ae3a8 |
@@ -2,8 +2,7 @@ QA output created by 059
|
|
|
9ae3a8 |
=== Testing invalid granularity ===
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
|
|
|
9ae3a8 |
-invalid granularity, image may be corrupt
|
|
|
9ae3a8 |
-qemu-io: can't open device TEST_DIR/t.vmdk: Could not open 'TEST_DIR/t.vmdk': Wrong medium type
|
|
|
9ae3a8 |
+qemu-io: can't open device TEST_DIR/t.vmdk: Invalid granularity, image may be corrupt
|
|
|
9ae3a8 |
no file open, try 'help open'
|
|
|
9ae3a8 |
=== Testing too big L2 table size ===
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -14,8 +13,7 @@ no file open, try 'help open'
|
|
|
9ae3a8 |
=== Testing too big L1 table size ===
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
|
|
|
9ae3a8 |
-L1 size too big
|
|
|
9ae3a8 |
-qemu-io: can't open device TEST_DIR/t.vmdk: Could not open 'TEST_DIR/t.vmdk': Wrong medium type
|
|
|
9ae3a8 |
+qemu-io: can't open device TEST_DIR/t.vmdk: L1 size too big
|
|
|
9ae3a8 |
no file open, try 'help open'
|
|
|
9ae3a8 |
=== Testing monolithicFlat creation and opening ===
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|