From 48398d9b96fa334e8c0e626d99cf2df8f4a5c664 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Thu, 23 Oct 2014 10:10:11 +0200 Subject: [PATCH 08/19] block: Catch duplicate IDs in bdrv_new() Message-id: <1414059011-15516-9-git-send-email-kwolf@redhat.com> Patchwork-id: 61840 O-Subject: [RHEL-7.1 qemu-kvm PATCH v2 8/8] block: Catch duplicate IDs in bdrv_new() Bugzilla: 1088176 RH-Acked-by: Jeffrey Cody RH-Acked-by: Markus Armbruster RH-Acked-by: Max Reitz Since commit f298d071, block devices added with blockdev-add don't have a QemuOpts around in dinfo->opts. Consequently, we can't rely any more on QemuOpts catching duplicate IDs for block devices. This patch adds a new check for duplicate IDs to bdrv_new(), and moves the existing check that the ID isn't already taken for a node-name there as well. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake (cherry picked from commit f2d953ec31eeeb3029ca915a55938c538a14efa8) In RHEL 7, node names don't exist yet, so only check the ID. Signed-off-by: Kevin Wolf Signed-off-by: Miroslav Rezanina --- block.c | 6 ++++++ tests/qemu-iotests/087 | 33 +++++++++++++++++++++++++++++++++ tests/qemu-iotests/087.out | 13 +++++++++++++ 3 files changed, 52 insertions(+) diff --git a/block.c b/block.c index eb0810e..d7b6376 100644 --- a/block.c +++ b/block.c @@ -304,6 +304,12 @@ 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; + } + bs = g_malloc0(sizeof(BlockDriverState)); pstrcpy(bs->device_name, sizeof(bs->device_name), device_name); if (device_name[0] != '\0') { diff --git a/tests/qemu-iotests/087 b/tests/qemu-iotests/087 index 53b6c43..f2fb3f4 100755 --- a/tests/qemu-iotests/087 +++ b/tests/qemu-iotests/087 @@ -73,6 +73,39 @@ run_qemu <