block: do not abuse EMEDIUMTYPE
Returning "Wrong medium type" for an image that does not have a valid header is a bit weird. Improve the error by mentioning what format was trying to open it. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
89ac8480a8
commit
76abe4071d
|
@ -129,7 +129,8 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
strcmp(bochs.subtype, GROWING_TYPE) ||
|
strcmp(bochs.subtype, GROWING_TYPE) ||
|
||||||
((le32_to_cpu(bochs.version) != HEADER_VERSION) &&
|
((le32_to_cpu(bochs.version) != HEADER_VERSION) &&
|
||||||
(le32_to_cpu(bochs.version) != HEADER_V1))) {
|
(le32_to_cpu(bochs.version) != HEADER_V1))) {
|
||||||
return -EMEDIUMTYPE;
|
error_setg(errp, "Image not in Bochs format");
|
||||||
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (le32_to_cpu(bochs.version) == HEADER_V1) {
|
if (le32_to_cpu(bochs.version) == HEADER_V1) {
|
||||||
|
|
|
@ -74,7 +74,8 @@ static int cow_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (be32_to_cpu(cow_header.magic) != COW_MAGIC) {
|
if (be32_to_cpu(cow_header.magic) != COW_MAGIC) {
|
||||||
ret = -EMEDIUMTYPE;
|
error_setg(errp, "Image not in COW format");
|
||||||
|
ret = -EINVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,8 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
|
|
||||||
if (memcmp(ph.magic, HEADER_MAGIC, 16) ||
|
if (memcmp(ph.magic, HEADER_MAGIC, 16) ||
|
||||||
(le32_to_cpu(ph.version) != HEADER_VERSION)) {
|
(le32_to_cpu(ph.version) != HEADER_VERSION)) {
|
||||||
ret = -EMEDIUMTYPE;
|
error_setg(errp, "Image not in Parallels format");
|
||||||
|
ret = -EINVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,8 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
be64_to_cpus(&header.l1_table_offset);
|
be64_to_cpus(&header.l1_table_offset);
|
||||||
|
|
||||||
if (header.magic != QCOW_MAGIC) {
|
if (header.magic != QCOW_MAGIC) {
|
||||||
ret = -EMEDIUMTYPE;
|
error_setg(errp, "Image not in qcow format");
|
||||||
|
ret = -EINVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (header.version != QCOW_VERSION) {
|
if (header.version != QCOW_VERSION) {
|
||||||
|
|
|
@ -449,7 +449,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
|
|
||||||
if (header.magic != QCOW_MAGIC) {
|
if (header.magic != QCOW_MAGIC) {
|
||||||
error_setg(errp, "Image is not in qcow2 format");
|
error_setg(errp, "Image is not in qcow2 format");
|
||||||
ret = -EMEDIUMTYPE;
|
ret = -EINVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (header.version < 2 || header.version > 3) {
|
if (header.version < 2 || header.version > 3) {
|
||||||
|
|
|
@ -391,7 +391,8 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
qed_header_le_to_cpu(&le_header, &s->header);
|
qed_header_le_to_cpu(&le_header, &s->header);
|
||||||
|
|
||||||
if (s->header.magic != QED_MAGIC) {
|
if (s->header.magic != QED_MAGIC) {
|
||||||
return -EMEDIUMTYPE;
|
error_setg(errp, "Image not in QED format");
|
||||||
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
if (s->header.features & ~QED_FEATURE_MASK) {
|
if (s->header.features & ~QED_FEATURE_MASK) {
|
||||||
/* image uses unsupported feature bits */
|
/* image uses unsupported feature bits */
|
||||||
|
|
|
@ -395,8 +395,8 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (header.signature != VDI_SIGNATURE) {
|
if (header.signature != VDI_SIGNATURE) {
|
||||||
logout("bad vdi signature %08x\n", header.signature);
|
error_setg(errp, "Image not in VDI format (bad signature %08x)", header.signature);
|
||||||
ret = -EMEDIUMTYPE;
|
ret = -EINVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
} else if (header.version != VDI_VERSION_1_1) {
|
} else if (header.version != VDI_VERSION_1_1) {
|
||||||
logout("unsupported version %u.%u\n",
|
logout("unsupported version %u.%u\n",
|
||||||
|
|
|
@ -748,7 +748,8 @@ static int vmdk_open_sparse(BlockDriverState *bs,
|
||||||
return vmdk_open_vmdk4(bs, file, flags, errp);
|
return vmdk_open_vmdk4(bs, file, flags, errp);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -EMEDIUMTYPE;
|
error_setg(errp, "Image not in VMDK format");
|
||||||
|
return -EINVAL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -862,7 +863,8 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf,
|
||||||
BDRVVmdkState *s = bs->opaque;
|
BDRVVmdkState *s = bs->opaque;
|
||||||
|
|
||||||
if (vmdk_parse_description(buf, "createType", ct, sizeof(ct))) {
|
if (vmdk_parse_description(buf, "createType", ct, sizeof(ct))) {
|
||||||
ret = -EMEDIUMTYPE;
|
error_setg(errp, "invalid VMDK image descriptor");
|
||||||
|
ret = -EINVAL;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (strcmp(ct, "monolithicFlat") &&
|
if (strcmp(ct, "monolithicFlat") &&
|
||||||
|
|
|
@ -190,7 +190,8 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (strncmp(footer->creator, "conectix", 8)) {
|
if (strncmp(footer->creator, "conectix", 8)) {
|
||||||
ret = -EMEDIUMTYPE;
|
error_setg(errp, "invalid VPC image");
|
||||||
|
ret = -EINVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
disk_type = VHD_FIXED;
|
disk_type = VHD_FIXED;
|
||||||
|
|
Loading…
Reference in New Issue