aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
Diffstat (limited to 'block')
-rw-r--r--block/block-backend.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/block/block-backend.c b/block/block-backend.c
index 6236b5b96d..fb91680f03 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -40,10 +40,20 @@ BlockBackend *blk_new(const char *name, Error **errp)
BlockBackend *blk;
assert(name && name[0]);
+ if (!id_wellformed(name)) {
+ error_setg(errp, "Invalid device name");
+ return NULL;
+ }
if (blk_by_name(name)) {
error_setg(errp, "Device with id '%s' already exists", name);
return NULL;
}
+ if (bdrv_find_node(name)) {
+ error_setg(errp,
+ "Device name '%s' conflicts with an existing node name",
+ name);
+ return NULL;
+ }
blk = g_new0(BlockBackend, 1);
blk->name = g_strdup(name);
@@ -66,12 +76,7 @@ BlockBackend *blk_new_with_bs(const char *name, Error **errp)
return NULL;
}
- bs = bdrv_new_root(name, errp);
- if (!bs) {
- blk_unref(blk);
- return NULL;
- }
-
+ bs = bdrv_new_root();
blk->bs = bs;
bs->blk = blk;
return blk;