diff options
author | Jeff Cody <jcody@redhat.com> | 2015-10-12 19:36:50 -0400 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2015-10-16 15:34:30 +0200 |
commit | 15489c769b9a4b3bec5b5848af2960689d7b4bd8 (patch) | |
tree | 4402e78af2ba94bd42ffb4705073a5dd0e956bd6 /block.c | |
parent | a0f1913637e6cd711aa721233b75eb2ec84d017b (diff) | |
download | qemu-15489c769b9a4b3bec5b5848af2960689d7b4bd8.zip qemu-15489c769b9a4b3bec5b5848af2960689d7b4bd8.tar.gz qemu-15489c769b9a4b3bec5b5848af2960689d7b4bd8.tar.bz2 |
block: auto-generated node-names
If a node-name is not specified, automatically generate the node-name.
Generated node-names will use the "block" sub-system identifier.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -763,12 +763,15 @@ static void bdrv_assign_node_name(BlockDriverState *bs, const char *node_name, Error **errp) { - if (!node_name) { - return; - } + char *gen_node_name = NULL; - /* Check for empty string or invalid characters */ - if (!id_wellformed(node_name)) { + if (!node_name) { + node_name = gen_node_name = id_generate(ID_BLOCK); + } else if (!id_wellformed(node_name)) { + /* + * Check for empty string or invalid characters, but not if it is + * generated (generated names use characters not available to the user) + */ error_setg(errp, "Invalid node name"); return; } @@ -777,18 +780,20 @@ static void bdrv_assign_node_name(BlockDriverState *bs, if (blk_by_name(node_name)) { error_setg(errp, "node-name=%s is conflicting with a device id", node_name); - return; + goto out; } /* takes care of avoiding duplicates node names */ if (bdrv_find_node(node_name)) { error_setg(errp, "Duplicate node name"); - return; + goto out; } /* copy node name into the bs and insert it into the graph list */ pstrcpy(bs->node_name, sizeof(bs->node_name), node_name); QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list); +out: + g_free(gen_node_name); } static QemuOptsList bdrv_runtime_opts = { |