mirror of
https://github.com/xemu-project/xemu.git
synced 2025-01-31 17:23:53 +00:00
block: Add errp to bdrv_new()
This patch adds an errp parameter to bdrv_new() and updates all its callers. The next patches will make use of this in order to check for duplicate IDs. Most of the callers know that their ID is fine, so they can simply assert that there is no error. Behaviour doesn't change with this patch yet as bdrv_new() doesn't actually assign errors to errp. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
5ff679b47d
commit
98522f63f4
6
block.c
6
block.c
@ -332,7 +332,7 @@ void bdrv_register(BlockDriver *bdrv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* create a new block device (by default it is empty) */
|
/* create a new block device (by default it is empty) */
|
||||||
BlockDriverState *bdrv_new(const char *device_name)
|
BlockDriverState *bdrv_new(const char *device_name, Error **errp)
|
||||||
{
|
{
|
||||||
BlockDriverState *bs;
|
BlockDriverState *bs;
|
||||||
|
|
||||||
@ -1220,7 +1220,7 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, Error **errp)
|
|||||||
qdict_put(snapshot_options, "file.filename",
|
qdict_put(snapshot_options, "file.filename",
|
||||||
qstring_from_str(tmp_filename));
|
qstring_from_str(tmp_filename));
|
||||||
|
|
||||||
bs_snapshot = bdrv_new("");
|
bs_snapshot = bdrv_new("", &error_abort);
|
||||||
bs_snapshot->is_temporary = 1;
|
bs_snapshot->is_temporary = 1;
|
||||||
|
|
||||||
ret = bdrv_open(&bs_snapshot, NULL, NULL, snapshot_options,
|
ret = bdrv_open(&bs_snapshot, NULL, NULL, snapshot_options,
|
||||||
@ -1287,7 +1287,7 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
|
|||||||
if (*pbs) {
|
if (*pbs) {
|
||||||
bs = *pbs;
|
bs = *pbs;
|
||||||
} else {
|
} else {
|
||||||
bs = bdrv_new("");
|
bs = bdrv_new("", &error_abort);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NULL means an empty set of options */
|
/* NULL means an empty set of options */
|
||||||
|
@ -1401,7 +1401,7 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options,
|
|||||||
IscsiLun *iscsilun = NULL;
|
IscsiLun *iscsilun = NULL;
|
||||||
QDict *bs_options;
|
QDict *bs_options;
|
||||||
|
|
||||||
bs = bdrv_new("");
|
bs = bdrv_new("", &error_abort);
|
||||||
|
|
||||||
/* Read out options */
|
/* Read out options */
|
||||||
while (options && options->name) {
|
while (options && options->name) {
|
||||||
|
@ -2947,7 +2947,7 @@ static int enable_write_target(BDRVVVFATState *s)
|
|||||||
unlink(s->qcow_filename);
|
unlink(s->qcow_filename);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
s->bs->backing_hd = bdrv_new("");
|
s->bs->backing_hd = bdrv_new("", &error_abort);
|
||||||
s->bs->backing_hd->drv = &vvfat_write_target;
|
s->bs->backing_hd->drv = &vvfat_write_target;
|
||||||
s->bs->backing_hd->opaque = g_malloc(sizeof(void*));
|
s->bs->backing_hd->opaque = g_malloc(sizeof(void*));
|
||||||
*(void**)s->bs->backing_hd->opaque = s;
|
*(void**)s->bs->backing_hd->opaque = s;
|
||||||
|
@ -461,7 +461,11 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
|
|||||||
/* init */
|
/* init */
|
||||||
dinfo = g_malloc0(sizeof(*dinfo));
|
dinfo = g_malloc0(sizeof(*dinfo));
|
||||||
dinfo->id = g_strdup(qemu_opts_id(opts));
|
dinfo->id = g_strdup(qemu_opts_id(opts));
|
||||||
dinfo->bdrv = bdrv_new(dinfo->id);
|
dinfo->bdrv = bdrv_new(dinfo->id, &error);
|
||||||
|
if (error) {
|
||||||
|
error_propagate(errp, error);
|
||||||
|
goto bdrv_new_err;
|
||||||
|
}
|
||||||
dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
|
dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
|
||||||
dinfo->bdrv->read_only = ro;
|
dinfo->bdrv->read_only = ro;
|
||||||
dinfo->refcount = 1;
|
dinfo->refcount = 1;
|
||||||
@ -523,8 +527,9 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
|
|||||||
|
|
||||||
err:
|
err:
|
||||||
bdrv_unref(dinfo->bdrv);
|
bdrv_unref(dinfo->bdrv);
|
||||||
g_free(dinfo->id);
|
|
||||||
QTAILQ_REMOVE(&drives, dinfo, next);
|
QTAILQ_REMOVE(&drives, dinfo, next);
|
||||||
|
bdrv_new_err:
|
||||||
|
g_free(dinfo->id);
|
||||||
g_free(dinfo);
|
g_free(dinfo);
|
||||||
early_err:
|
early_err:
|
||||||
QDECREF(bs_opts);
|
QDECREF(bs_opts);
|
||||||
|
@ -817,11 +817,14 @@ static int blk_connect(struct XenDevice *xendev)
|
|||||||
index = (blkdev->xendev.dev - 202 * 256) / 16;
|
index = (blkdev->xendev.dev - 202 * 256) / 16;
|
||||||
blkdev->dinfo = drive_get(IF_XEN, 0, index);
|
blkdev->dinfo = drive_get(IF_XEN, 0, index);
|
||||||
if (!blkdev->dinfo) {
|
if (!blkdev->dinfo) {
|
||||||
|
Error *local_err = NULL;
|
||||||
/* setup via xenbus -> create new block driver instance */
|
/* setup via xenbus -> create new block driver instance */
|
||||||
xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
|
xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
|
||||||
blkdev->bs = bdrv_new(blkdev->dev);
|
blkdev->bs = bdrv_new(blkdev->dev, &local_err);
|
||||||
|
if (local_err) {
|
||||||
|
blkdev->bs = NULL;
|
||||||
|
}
|
||||||
if (blkdev->bs) {
|
if (blkdev->bs) {
|
||||||
Error *local_err = NULL;
|
|
||||||
BlockDriver *drv = bdrv_find_whitelisted_format(blkdev->fileproto,
|
BlockDriver *drv = bdrv_find_whitelisted_format(blkdev->fileproto,
|
||||||
readonly);
|
readonly);
|
||||||
if (bdrv_open(&blkdev->bs, blkdev->filename, NULL, NULL, qflags,
|
if (bdrv_open(&blkdev->bs, blkdev->filename, NULL, NULL, qflags,
|
||||||
|
@ -180,7 +180,7 @@ int bdrv_create(BlockDriver *drv, const char* filename,
|
|||||||
QEMUOptionParameter *options, Error **errp);
|
QEMUOptionParameter *options, Error **errp);
|
||||||
int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
|
int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
|
||||||
Error **errp);
|
Error **errp);
|
||||||
BlockDriverState *bdrv_new(const char *device_name);
|
BlockDriverState *bdrv_new(const char *device_name, Error **errp);
|
||||||
void bdrv_make_anon(BlockDriverState *bs);
|
void bdrv_make_anon(BlockDriverState *bs);
|
||||||
void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
|
void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
|
||||||
void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top);
|
void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top);
|
||||||
|
@ -274,7 +274,7 @@ static BlockDriverState *bdrv_new_open(const char *filename,
|
|||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
bs = bdrv_new("image");
|
bs = bdrv_new("image", &error_abort);
|
||||||
|
|
||||||
if (fmt) {
|
if (fmt) {
|
||||||
drv = bdrv_find_format(fmt);
|
drv = bdrv_find_format(fmt);
|
||||||
@ -2344,7 +2344,7 @@ static int img_rebase(int argc, char **argv)
|
|||||||
} else {
|
} else {
|
||||||
char backing_name[1024];
|
char backing_name[1024];
|
||||||
|
|
||||||
bs_old_backing = bdrv_new("old_backing");
|
bs_old_backing = bdrv_new("old_backing", &error_abort);
|
||||||
bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
|
bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
|
||||||
ret = bdrv_open(&bs_old_backing, backing_name, NULL, NULL, BDRV_O_FLAGS,
|
ret = bdrv_open(&bs_old_backing, backing_name, NULL, NULL, BDRV_O_FLAGS,
|
||||||
old_backing_drv, &local_err);
|
old_backing_drv, &local_err);
|
||||||
@ -2355,7 +2355,7 @@ static int img_rebase(int argc, char **argv)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (out_baseimg[0]) {
|
if (out_baseimg[0]) {
|
||||||
bs_new_backing = bdrv_new("new_backing");
|
bs_new_backing = bdrv_new("new_backing", &error_abort);
|
||||||
ret = bdrv_open(&bs_new_backing, out_baseimg, NULL, NULL,
|
ret = bdrv_open(&bs_new_backing, out_baseimg, NULL, NULL,
|
||||||
BDRV_O_FLAGS, new_backing_drv, &local_err);
|
BDRV_O_FLAGS, new_backing_drv, &local_err);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
@ -67,7 +67,7 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qemuio_bs = bdrv_new("hda");
|
qemuio_bs = bdrv_new("hda", &error_abort);
|
||||||
|
|
||||||
if (bdrv_open(&qemuio_bs, name, NULL, opts, flags, NULL, &local_err)
|
if (bdrv_open(&qemuio_bs, name, NULL, opts, flags, NULL, &local_err)
|
||||||
< 0)
|
< 0)
|
||||||
|
@ -657,7 +657,8 @@ int main(int argc, char **argv)
|
|||||||
drv = NULL;
|
drv = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bs = bdrv_new("hda");
|
bs = bdrv_new("hda", &error_abort);
|
||||||
|
|
||||||
srcpath = argv[optind];
|
srcpath = argv[optind];
|
||||||
ret = bdrv_open(&bs, srcpath, NULL, NULL, flags, drv, &local_err);
|
ret = bdrv_open(&bs, srcpath, NULL, NULL, flags, drv, &local_err);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user