block/vdi: Improved return values from vdi_open
vdi_open returned -1 in case of any error, but it should return an error code (negative value of errno or -EMEDIUMTYPE). Signed-off-by: Stefan Weil <sw@weilnetz.de> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
9f0470bb2d
commit
8937f8222c
17
block/vdi.c
17
block/vdi.c
@ -369,10 +369,12 @@ static int vdi_open(BlockDriverState *bs, int flags)
|
|||||||
BDRVVdiState *s = bs->opaque;
|
BDRVVdiState *s = bs->opaque;
|
||||||
VdiHeader header;
|
VdiHeader header;
|
||||||
size_t bmap_size;
|
size_t bmap_size;
|
||||||
|
int ret;
|
||||||
|
|
||||||
logout("\n");
|
logout("\n");
|
||||||
|
|
||||||
if (bdrv_read(bs->file, 0, (uint8_t *)&header, 1) < 0) {
|
ret = bdrv_read(bs->file, 0, (uint8_t *)&header, 1);
|
||||||
|
if (ret < 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,30 +395,38 @@ static int vdi_open(BlockDriverState *bs, int flags)
|
|||||||
if (header.version != VDI_VERSION_1_1) {
|
if (header.version != VDI_VERSION_1_1) {
|
||||||
logout("unsupported version %u.%u\n",
|
logout("unsupported version %u.%u\n",
|
||||||
header.version >> 16, header.version & 0xffff);
|
header.version >> 16, header.version & 0xffff);
|
||||||
|
ret = -ENOTSUP;
|
||||||
goto fail;
|
goto fail;
|
||||||
} else if (header.offset_bmap % SECTOR_SIZE != 0) {
|
} else if (header.offset_bmap % SECTOR_SIZE != 0) {
|
||||||
/* We only support block maps which start on a sector boundary. */
|
/* We only support block maps which start on a sector boundary. */
|
||||||
logout("unsupported block map offset 0x%x B\n", header.offset_bmap);
|
logout("unsupported block map offset 0x%x B\n", header.offset_bmap);
|
||||||
|
ret = -ENOTSUP;
|
||||||
goto fail;
|
goto fail;
|
||||||
} else if (header.offset_data % SECTOR_SIZE != 0) {
|
} else if (header.offset_data % SECTOR_SIZE != 0) {
|
||||||
/* We only support data blocks which start on a sector boundary. */
|
/* We only support data blocks which start on a sector boundary. */
|
||||||
logout("unsupported data offset 0x%x B\n", header.offset_data);
|
logout("unsupported data offset 0x%x B\n", header.offset_data);
|
||||||
|
ret = -ENOTSUP;
|
||||||
goto fail;
|
goto fail;
|
||||||
} else if (header.sector_size != SECTOR_SIZE) {
|
} else if (header.sector_size != SECTOR_SIZE) {
|
||||||
logout("unsupported sector size %u B\n", header.sector_size);
|
logout("unsupported sector size %u B\n", header.sector_size);
|
||||||
|
ret = -ENOTSUP;
|
||||||
goto fail;
|
goto fail;
|
||||||
} else if (header.block_size != 1 * MiB) {
|
} else if (header.block_size != 1 * MiB) {
|
||||||
logout("unsupported block size %u B\n", header.block_size);
|
logout("unsupported block size %u B\n", header.block_size);
|
||||||
|
ret = -ENOTSUP;
|
||||||
goto fail;
|
goto fail;
|
||||||
} else if (header.disk_size >
|
} else if (header.disk_size >
|
||||||
(uint64_t)header.blocks_in_image * header.block_size) {
|
(uint64_t)header.blocks_in_image * header.block_size) {
|
||||||
logout("unsupported disk size %" PRIu64 " B\n", header.disk_size);
|
logout("unsupported disk size %" PRIu64 " B\n", header.disk_size);
|
||||||
|
ret = -ENOTSUP;
|
||||||
goto fail;
|
goto fail;
|
||||||
} else if (!uuid_is_null(header.uuid_link)) {
|
} else if (!uuid_is_null(header.uuid_link)) {
|
||||||
logout("link uuid != 0, unsupported\n");
|
logout("link uuid != 0, unsupported\n");
|
||||||
|
ret = -ENOTSUP;
|
||||||
goto fail;
|
goto fail;
|
||||||
} else if (!uuid_is_null(header.uuid_parent)) {
|
} else if (!uuid_is_null(header.uuid_parent)) {
|
||||||
logout("parent uuid != 0, unsupported\n");
|
logout("parent uuid != 0, unsupported\n");
|
||||||
|
ret = -ENOTSUP;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,7 +442,8 @@ static int vdi_open(BlockDriverState *bs, int flags)
|
|||||||
if (bmap_size > 0) {
|
if (bmap_size > 0) {
|
||||||
s->bmap = g_malloc(bmap_size * SECTOR_SIZE);
|
s->bmap = g_malloc(bmap_size * SECTOR_SIZE);
|
||||||
}
|
}
|
||||||
if (bdrv_read(bs->file, s->bmap_sector, (uint8_t *)s->bmap, bmap_size) < 0) {
|
ret = bdrv_read(bs->file, s->bmap_sector, (uint8_t *)s->bmap, bmap_size);
|
||||||
|
if (ret < 0) {
|
||||||
goto fail_free_bmap;
|
goto fail_free_bmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,7 +459,7 @@ static int vdi_open(BlockDriverState *bs, int flags)
|
|||||||
g_free(s->bmap);
|
g_free(s->bmap);
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
return -1;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vdi_reopen_prepare(BDRVReopenState *state,
|
static int vdi_reopen_prepare(BDRVReopenState *state,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user