bdrv: Use "Error" for opening images

Add an Error ** parameter to BlockDriver.bdrv_open and
BlockDriver.bdrv_file_open to allow more specific error messages.

Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
Max Reitz 2013-09-05 14:22:29 +02:00 committed by Kevin Wolf
parent 8023090be5
commit 015a1036a7
28 changed files with 67 additions and 37 deletions

View File

@ -761,7 +761,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
if (drv->bdrv_file_open) { if (drv->bdrv_file_open) {
assert(file == NULL); assert(file == NULL);
assert(drv->bdrv_parse_filename || filename != NULL); assert(drv->bdrv_parse_filename || filename != NULL);
ret = drv->bdrv_file_open(bs, options, open_flags); ret = drv->bdrv_file_open(bs, options, open_flags, NULL);
} else { } else {
if (file == NULL) { if (file == NULL) {
qerror_report(ERROR_CLASS_GENERIC_ERROR, "Can't use '%s' as a " qerror_report(ERROR_CLASS_GENERIC_ERROR, "Can't use '%s' as a "
@ -771,7 +771,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
goto free_and_fail; goto free_and_fail;
} }
bs->file = file; bs->file = file;
ret = drv->bdrv_open(bs, options, open_flags); ret = drv->bdrv_open(bs, options, open_flags, NULL);
} }
if (ret < 0) { if (ret < 0) {

View File

@ -350,7 +350,8 @@ static QemuOptsList runtime_opts = {
}, },
}; };
static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags) static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVBlkdebugState *s = bs->opaque; BDRVBlkdebugState *s = bs->opaque;
QemuOpts *opts; QemuOpts *opts;

View File

@ -116,7 +116,8 @@ static QemuOptsList runtime_opts = {
}, },
}; };
static int blkverify_open(BlockDriverState *bs, QDict *options, int flags) static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVBlkverifyState *s = bs->opaque; BDRVBlkverifyState *s = bs->opaque;
QemuOpts *opts; QemuOpts *opts;

View File

@ -108,7 +108,8 @@ static int bochs_probe(const uint8_t *buf, int buf_size, const char *filename)
return 0; return 0;
} }
static int bochs_open(BlockDriverState *bs, QDict *options, int flags) static int bochs_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVBochsState *s = bs->opaque; BDRVBochsState *s = bs->opaque;
int i; int i;

View File

@ -53,7 +53,8 @@ static int cloop_probe(const uint8_t *buf, int buf_size, const char *filename)
return 0; return 0;
} }
static int cloop_open(BlockDriverState *bs, QDict *options, int flags) static int cloop_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVCloopState *s = bs->opaque; BDRVCloopState *s = bs->opaque;
uint32_t offsets_size, max_compressed_block_size = 1, i; uint32_t offsets_size, max_compressed_block_size = 1, i;

View File

@ -58,7 +58,8 @@ static int cow_probe(const uint8_t *buf, int buf_size, const char *filename)
return 0; return 0;
} }
static int cow_open(BlockDriverState *bs, QDict *options, int flags) static int cow_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVCowState *s = bs->opaque; BDRVCowState *s = bs->opaque;
struct cow_header_v2 cow_header; struct cow_header_v2 cow_header;

View File

@ -395,7 +395,8 @@ static QemuOptsList runtime_opts = {
}, },
}; };
static int curl_open(BlockDriverState *bs, QDict *options, int flags) static int curl_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVCURLState *s = bs->opaque; BDRVCURLState *s = bs->opaque;
CURLState *state = NULL; CURLState *state = NULL;

View File

@ -92,7 +92,8 @@ static int read_uint32(BlockDriverState *bs, int64_t offset, uint32_t *result)
return 0; return 0;
} }
static int dmg_open(BlockDriverState *bs, QDict *options, int flags) static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVDMGState *s = bs->opaque; BDRVDMGState *s = bs->opaque;
uint64_t info_begin,info_end,last_in_offset,last_out_offset; uint64_t info_begin,info_end,last_in_offset,last_out_offset;

View File

@ -288,7 +288,7 @@ static QemuOptsList runtime_opts = {
}; };
static int qemu_gluster_open(BlockDriverState *bs, QDict *options, static int qemu_gluster_open(BlockDriverState *bs, QDict *options,
int bdrv_flags) int bdrv_flags, Error **errp)
{ {
BDRVGlusterState *s = bs->opaque; BDRVGlusterState *s = bs->opaque;
int open_flags = O_BINARY; int open_flags = O_BINARY;

View File

@ -1046,7 +1046,8 @@ static QemuOptsList runtime_opts = {
* We support iscsi url's on the form * We support iscsi url's on the form
* iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun> * iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
*/ */
static int iscsi_open(BlockDriverState *bs, QDict *options, int flags) static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
IscsiLun *iscsilun = bs->opaque; IscsiLun *iscsilun = bs->opaque;
struct iscsi_context *iscsi = NULL; struct iscsi_context *iscsi = NULL;
@ -1260,7 +1261,7 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options)
bs_options = qdict_new(); bs_options = qdict_new();
qdict_put(bs_options, "filename", qstring_from_str(filename)); qdict_put(bs_options, "filename", qstring_from_str(filename));
ret = iscsi_open(bs, bs_options, 0); ret = iscsi_open(bs, bs_options, 0, NULL);
QDECREF(bs_options); QDECREF(bs_options);
if (ret != 0) { if (ret != 0) {

View File

@ -453,7 +453,8 @@ static void nbd_teardown_connection(BlockDriverState *bs)
closesocket(s->sock); closesocket(s->sock);
} }
static int nbd_open(BlockDriverState *bs, QDict *options, int flags) static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVNBDState *s = bs->opaque; BDRVNBDState *s = bs->opaque;
int result; int result;

View File

@ -68,7 +68,8 @@ static int parallels_probe(const uint8_t *buf, int buf_size, const char *filenam
return 0; return 0;
} }
static int parallels_open(BlockDriverState *bs, QDict *options, int flags) static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVParallelsState *s = bs->opaque; BDRVParallelsState *s = bs->opaque;
int i; int i;

View File

@ -92,7 +92,8 @@ static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
return 0; return 0;
} }
static int qcow_open(BlockDriverState *bs, QDict *options, int flags) static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVQcowState *s = bs->opaque; BDRVQcowState *s = bs->opaque;
int len, i, shift, ret; int len, i, shift, ret;

View File

@ -350,7 +350,8 @@ static QemuOptsList qcow2_runtime_opts = {
}, },
}; };
static int qcow2_open(BlockDriverState *bs, QDict *options, int flags) static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVQcowState *s = bs->opaque; BDRVQcowState *s = bs->opaque;
int len, i, ret = 0; int len, i, ret = 0;
@ -1060,7 +1061,7 @@ static void qcow2_invalidate_cache(BlockDriverState *bs)
qbool_from_int(s->use_lazy_refcounts)); qbool_from_int(s->use_lazy_refcounts));
memset(s, 0, sizeof(BDRVQcowState)); memset(s, 0, sizeof(BDRVQcowState));
qcow2_open(bs, options, flags); qcow2_open(bs, options, flags, NULL);
QDECREF(options); QDECREF(options);

View File

@ -373,7 +373,8 @@ static void bdrv_qed_rebind(BlockDriverState *bs)
s->bs = bs; s->bs = bs;
} }
static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags) static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVQEDState *s = bs->opaque; BDRVQEDState *s = bs->opaque;
QEDHeader le_header; QEDHeader le_header;
@ -1547,7 +1548,7 @@ static void bdrv_qed_invalidate_cache(BlockDriverState *bs)
bdrv_qed_close(bs); bdrv_qed_close(bs);
memset(s, 0, sizeof(BDRVQEDState)); memset(s, 0, sizeof(BDRVQEDState));
bdrv_qed_open(bs, NULL, bs->open_flags); bdrv_qed_open(bs, NULL, bs->open_flags, NULL);
} }
static int bdrv_qed_check(BlockDriverState *bs, BdrvCheckResult *result, static int bdrv_qed_check(BlockDriverState *bs, BdrvCheckResult *result,

View File

@ -335,7 +335,8 @@ fail:
return ret; return ret;
} }
static int raw_open(BlockDriverState *bs, QDict *options, int flags) static int raw_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
@ -1331,7 +1332,8 @@ static int check_hdev_writable(BDRVRawState *s)
return 0; return 0;
} }
static int hdev_open(BlockDriverState *bs, QDict *options, int flags) static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
int ret; int ret;
@ -1565,7 +1567,8 @@ static BlockDriver bdrv_host_device = {
}; };
#ifdef __linux__ #ifdef __linux__
static int floppy_open(BlockDriverState *bs, QDict *options, int flags) static int floppy_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
int ret; int ret;
@ -1686,7 +1689,8 @@ static BlockDriver bdrv_host_floppy = {
.bdrv_eject = floppy_eject, .bdrv_eject = floppy_eject,
}; };
static int cdrom_open(BlockDriverState *bs, QDict *options, int flags) static int cdrom_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;

View File

@ -235,7 +235,8 @@ static QemuOptsList raw_runtime_opts = {
}, },
}; };
static int raw_open(BlockDriverState *bs, QDict *options, int flags) static int raw_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
int access_flags; int access_flags;
@ -532,7 +533,8 @@ static int hdev_probe_device(const char *filename)
return 0; return 0;
} }
static int hdev_open(BlockDriverState *bs, QDict *options, int flags) static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
int access_flags, create_flags; int access_flags, create_flags;

View File

@ -135,7 +135,8 @@ static int raw_create(const char *filename, QEMUOptionParameter *options)
return bdrv_create_file(filename, options); return bdrv_create_file(filename, options);
} }
static int raw_open(BlockDriverState *bs, QDict *options, int flags) static int raw_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
bs->sg = bs->file->sg; bs->sg = bs->file->sg;
return 0; return 0;

View File

@ -446,7 +446,8 @@ static QemuOptsList runtime_opts = {
}, },
}; };
static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags) static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVRBDState *s = bs->opaque; BDRVRBDState *s = bs->opaque;
char pool[RBD_MAX_POOL_NAME_SIZE]; char pool[RBD_MAX_POOL_NAME_SIZE];

View File

@ -1242,7 +1242,8 @@ static QemuOptsList runtime_opts = {
}, },
}; };
static int sd_open(BlockDriverState *bs, QDict *options, int flags) static int sd_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
int ret, fd; int ret, fd;
uint32_t vid = 0; uint32_t vid = 0;

View File

@ -170,7 +170,7 @@ int bdrv_snapshot_goto(BlockDriverState *bs,
if (bs->file) { if (bs->file) {
drv->bdrv_close(bs); drv->bdrv_close(bs);
ret = bdrv_snapshot_goto(bs->file, snapshot_id); ret = bdrv_snapshot_goto(bs->file, snapshot_id);
open_ret = drv->bdrv_open(bs, NULL, bs->open_flags); open_ret = drv->bdrv_open(bs, NULL, bs->open_flags, NULL);
if (open_ret < 0) { if (open_ret < 0) {
bdrv_unref(bs->file); bdrv_unref(bs->file);
bs->drv = NULL; bs->drv = NULL;

View File

@ -608,7 +608,8 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
return ret; return ret;
} }
static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags) static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags,
Error **errp)
{ {
BDRVSSHState *s = bs->opaque; BDRVSSHState *s = bs->opaque;
int ret; int ret;

View File

@ -364,7 +364,8 @@ static int vdi_probe(const uint8_t *buf, int buf_size, const char *filename)
return result; return result;
} }
static int vdi_open(BlockDriverState *bs, QDict *options, int flags) static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVVdiState *s = bs->opaque; BDRVVdiState *s = bs->opaque;
VdiHeader header; VdiHeader header;

View File

@ -715,7 +715,8 @@ exit:
} }
static int vhdx_open(BlockDriverState *bs, QDict *options, int flags) static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVVHDXState *s = bs->opaque; BDRVVHDXState *s = bs->opaque;
int ret = 0; int ret = 0;

View File

@ -806,7 +806,8 @@ exit:
return ret; return ret;
} }
static int vmdk_open(BlockDriverState *bs, QDict *options, int flags) static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
int ret; int ret;
BDRVVmdkState *s = bs->opaque; BDRVVmdkState *s = bs->opaque;

View File

@ -155,7 +155,8 @@ static int vpc_probe(const uint8_t *buf, int buf_size, const char *filename)
return 0; return 0;
} }
static int vpc_open(BlockDriverState *bs, QDict *options, int flags) static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVVPCState *s = bs->opaque; BDRVVPCState *s = bs->opaque;
int i; int i;

View File

@ -1065,7 +1065,8 @@ static void vvfat_parse_filename(const char *filename, QDict *options,
qdict_put(options, "rw", qbool_from_int(rw)); qdict_put(options, "rw", qbool_from_int(rw));
} }
static int vvfat_open(BlockDriverState *bs, QDict *options, int flags) static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{ {
BDRVVVFATState *s = bs->opaque; BDRVVVFATState *s = bs->opaque;
int cyls, heads, secs; int cyls, heads, secs;

View File

@ -80,8 +80,10 @@ struct BlockDriver {
void (*bdrv_reopen_commit)(BDRVReopenState *reopen_state); void (*bdrv_reopen_commit)(BDRVReopenState *reopen_state);
void (*bdrv_reopen_abort)(BDRVReopenState *reopen_state); void (*bdrv_reopen_abort)(BDRVReopenState *reopen_state);
int (*bdrv_open)(BlockDriverState *bs, QDict *options, int flags); int (*bdrv_open)(BlockDriverState *bs, QDict *options, int flags,
int (*bdrv_file_open)(BlockDriverState *bs, QDict *options, int flags); Error **errp);
int (*bdrv_file_open)(BlockDriverState *bs, QDict *options, int flags,
Error **errp);
int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num, int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
uint8_t *buf, int nb_sectors); uint8_t *buf, int nb_sectors);
int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num, int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num,