mirror of https://gitee.com/openkylin/qemu.git
block: Split bdrv_new_root() off bdrv_new()
Creating an anonymous BDS can't fail. Make that obvious. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Benoît Canet <benoit.canet@nodalink.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
ec0de76874
commit
e4e9986b1c
28
block.c
28
block.c
|
@ -336,10 +336,11 @@ void bdrv_register(BlockDriver *bdrv)
|
|||
}
|
||||
|
||||
/* create a new block device (by default it is empty) */
|
||||
BlockDriverState *bdrv_new(const char *device_name, Error **errp)
|
||||
BlockDriverState *bdrv_new_root(const char *device_name, Error **errp)
|
||||
{
|
||||
BlockDriverState *bs;
|
||||
int i;
|
||||
|
||||
assert(*device_name);
|
||||
|
||||
if (*device_name && !id_wellformed(device_name)) {
|
||||
error_setg(errp, "Invalid device name");
|
||||
|
@ -358,12 +359,21 @@ BlockDriverState *bdrv_new(const char *device_name, Error **errp)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
bs = bdrv_new();
|
||||
|
||||
pstrcpy(bs->device_name, sizeof(bs->device_name), device_name);
|
||||
QTAILQ_INSERT_TAIL(&bdrv_states, bs, device_list);
|
||||
|
||||
return bs;
|
||||
}
|
||||
|
||||
BlockDriverState *bdrv_new(void)
|
||||
{
|
||||
BlockDriverState *bs;
|
||||
int i;
|
||||
|
||||
bs = g_new0(BlockDriverState, 1);
|
||||
QLIST_INIT(&bs->dirty_bitmaps);
|
||||
pstrcpy(bs->device_name, sizeof(bs->device_name), device_name);
|
||||
if (device_name[0] != '\0') {
|
||||
QTAILQ_INSERT_TAIL(&bdrv_states, bs, device_list);
|
||||
}
|
||||
for (i = 0; i < BLOCK_OP_TYPE_MAX; i++) {
|
||||
QLIST_INIT(&bs->op_blockers[i]);
|
||||
}
|
||||
|
@ -1224,7 +1234,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
|
|||
goto free_exit;
|
||||
}
|
||||
|
||||
backing_hd = bdrv_new("", errp);
|
||||
backing_hd = bdrv_new();
|
||||
|
||||
if (bs->backing_format[0] != '\0') {
|
||||
back_drv = bdrv_find_format(bs->backing_format);
|
||||
|
@ -1353,7 +1363,7 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
|
|||
qdict_put(snapshot_options, "file.filename",
|
||||
qstring_from_str(tmp_filename));
|
||||
|
||||
bs_snapshot = bdrv_new("", &error_abort);
|
||||
bs_snapshot = bdrv_new();
|
||||
|
||||
ret = bdrv_open(&bs_snapshot, NULL, NULL, snapshot_options,
|
||||
flags, bdrv_qcow2, &local_err);
|
||||
|
@ -1424,7 +1434,7 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
|
|||
if (*pbs) {
|
||||
bs = *pbs;
|
||||
} else {
|
||||
bs = bdrv_new("", &error_abort);
|
||||
bs = bdrv_new();
|
||||
}
|
||||
|
||||
/* NULL means an empty set of options */
|
||||
|
|
|
@ -1519,7 +1519,7 @@ static int iscsi_create(const char *filename, QemuOpts *opts, Error **errp)
|
|||
IscsiLun *iscsilun = NULL;
|
||||
QDict *bs_options;
|
||||
|
||||
bs = bdrv_new("", &error_abort);
|
||||
bs = bdrv_new();
|
||||
|
||||
/* Read out options */
|
||||
total_size = DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
|
||||
|
|
|
@ -2939,7 +2939,7 @@ static int enable_write_target(BDRVVVFATState *s, Error **errp)
|
|||
unlink(s->qcow_filename);
|
||||
#endif
|
||||
|
||||
bdrv_set_backing_hd(s->bs, bdrv_new("", &error_abort));
|
||||
bdrv_set_backing_hd(s->bs, bdrv_new());
|
||||
s->bs->backing_hd->drv = &vvfat_write_target;
|
||||
s->bs->backing_hd->opaque = g_new(void *, 1);
|
||||
*(void**)s->bs->backing_hd->opaque = s;
|
||||
|
|
|
@ -523,7 +523,7 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
|
|||
}
|
||||
|
||||
/* init */
|
||||
bs = bdrv_new(qemu_opts_id(opts), errp);
|
||||
bs = bdrv_new_root(qemu_opts_id(opts), errp);
|
||||
if (!bs) {
|
||||
goto early_err;
|
||||
}
|
||||
|
|
|
@ -858,7 +858,7 @@ static int blk_connect(struct XenDevice *xendev)
|
|||
|
||||
/* setup via xenbus -> create new block driver instance */
|
||||
xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
|
||||
blkdev->bs = bdrv_new(blkdev->dev, NULL);
|
||||
blkdev->bs = bdrv_new_root(blkdev->dev, NULL);
|
||||
if (!blkdev->bs) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -204,7 +204,8 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
|
|||
int bdrv_create(BlockDriver *drv, const char* filename,
|
||||
QemuOpts *opts, Error **errp);
|
||||
int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp);
|
||||
BlockDriverState *bdrv_new(const char *device_name, Error **errp);
|
||||
BlockDriverState *bdrv_new_root(const char *device_name, Error **errp);
|
||||
BlockDriverState *bdrv_new(void);
|
||||
void bdrv_make_anon(BlockDriverState *bs);
|
||||
void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
|
||||
void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top);
|
||||
|
|
|
@ -296,7 +296,7 @@ static BlockDriverState *bdrv_new_open(const char *id,
|
|||
Error *local_err = NULL;
|
||||
int ret;
|
||||
|
||||
bs = bdrv_new(id, &error_abort);
|
||||
bs = bdrv_new_root(id, &error_abort);
|
||||
|
||||
if (fmt) {
|
||||
drv = bdrv_find_format(fmt);
|
||||
|
@ -2423,7 +2423,7 @@ static int img_rebase(int argc, char **argv)
|
|||
if (!unsafe) {
|
||||
char backing_name[1024];
|
||||
|
||||
bs_old_backing = bdrv_new("old_backing", &error_abort);
|
||||
bs_old_backing = bdrv_new_root("old_backing", &error_abort);
|
||||
bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
|
||||
ret = bdrv_open(&bs_old_backing, backing_name, NULL, NULL, src_flags,
|
||||
old_backing_drv, &local_err);
|
||||
|
@ -2434,7 +2434,7 @@ static int img_rebase(int argc, char **argv)
|
|||
goto out;
|
||||
}
|
||||
if (out_baseimg[0]) {
|
||||
bs_new_backing = bdrv_new("new_backing", &error_abort);
|
||||
bs_new_backing = bdrv_new_root("new_backing", &error_abort);
|
||||
ret = bdrv_open(&bs_new_backing, out_baseimg, NULL, NULL, src_flags,
|
||||
new_backing_drv, &local_err);
|
||||
if (ret) {
|
||||
|
|
|
@ -58,7 +58,7 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
|
|||
return 1;
|
||||
}
|
||||
|
||||
qemuio_bs = bdrv_new("hda", &error_abort);
|
||||
qemuio_bs = bdrv_new_root("hda", &error_abort);
|
||||
|
||||
if (growable) {
|
||||
flags |= BDRV_O_PROTOCOL;
|
||||
|
|
|
@ -691,7 +691,7 @@ int main(int argc, char **argv)
|
|||
drv = NULL;
|
||||
}
|
||||
|
||||
bs = bdrv_new("hda", &error_abort);
|
||||
bs = bdrv_new_root("hda", &error_abort);
|
||||
|
||||
srcpath = argv[optind];
|
||||
ret = bdrv_open(&bs, srcpath, NULL, NULL, flags, drv, &local_err);
|
||||
|
|
Loading…
Reference in New Issue