diff --git a/block.c b/block.c index f3b93c942b..fc2edd33ae 100644 --- a/block.c +++ b/block.c @@ -336,6 +336,17 @@ BlockDriverState *bdrv_new(const char *device_name, Error **errp) { BlockDriverState *bs; + if (bdrv_find(device_name)) { + error_setg(errp, "Device with id '%s' already exists", + device_name); + return NULL; + } + if (bdrv_find_node(device_name)) { + error_setg(errp, "Device with node-name '%s' already exists", + device_name); + return NULL; + } + bs = g_malloc0(sizeof(BlockDriverState)); QLIST_INIT(&bs->dirty_bitmaps); pstrcpy(bs->device_name, sizeof(bs->device_name), device_name); diff --git a/blockdev.c b/blockdev.c index 3a11a62019..09826f10cf 100644 --- a/blockdev.c +++ b/blockdev.c @@ -452,12 +452,6 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts, } } - if (bdrv_find_node(qemu_opts_id(opts))) { - error_setg(errp, "device id=%s is conflicting with a node-name", - qemu_opts_id(opts)); - goto early_err; - } - /* init */ dinfo = g_malloc0(sizeof(*dinfo)); dinfo->id = g_strdup(qemu_opts_id(opts)); diff --git a/tests/qemu-iotests/087 b/tests/qemu-iotests/087 index a38bb702b3..37d82fcdcd 100755 --- a/tests/qemu-iotests/087 +++ b/tests/qemu-iotests/087 @@ -72,6 +72,39 @@ run_qemu <