提交 6913c0c2 编写于 作者: B Benoît Canet 提交者: Kevin Wolf

block: Allow the user to define "node-name" option both on command line and QMP.

Signed-off-by: NBenoit Canet <benoit@irqsave.net>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 dc364f4c
...@@ -735,6 +735,33 @@ static int bdrv_open_flags(BlockDriverState *bs, int flags) ...@@ -735,6 +735,33 @@ static int bdrv_open_flags(BlockDriverState *bs, int flags)
return open_flags; return open_flags;
} }
static int bdrv_assign_node_name(BlockDriverState *bs,
const char *node_name,
Error **errp)
{
if (!node_name) {
return 0;
}
/* empty string node name is invalid */
if (node_name[0] == '\0') {
error_setg(errp, "Empty node name");
return -EINVAL;
}
/* takes care of avoiding duplicates node names */
if (bdrv_find_node(node_name)) {
error_setg(errp, "Duplicate node name");
return -EINVAL;
}
/* 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);
return 0;
}
/* /*
* Common part for opening disk images and files * Common part for opening disk images and files
* *
...@@ -745,6 +772,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file, ...@@ -745,6 +772,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
{ {
int ret, open_flags; int ret, open_flags;
const char *filename; const char *filename;
const char *node_name = NULL;
Error *local_err = NULL; Error *local_err = NULL;
assert(drv != NULL); assert(drv != NULL);
...@@ -759,6 +787,13 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file, ...@@ -759,6 +787,13 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name); trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name);
node_name = qdict_get_try_str(options, "node-name");
ret = bdrv_assign_node_name(bs, node_name, errp);
if (ret < 0) {
return ret;
}
qdict_del(options, "node-name");
/* bdrv_open() with directly using a protocol as drv. This layer is already /* bdrv_open() with directly using a protocol as drv. This layer is already
* opened, so assign it to bs (while file becomes a closed BlockDriverState) * opened, so assign it to bs (while file becomes a closed BlockDriverState)
* and return immediately. */ * and return immediately. */
......
...@@ -4092,6 +4092,7 @@ ...@@ -4092,6 +4092,7 @@
# @id: #optional id by which the new block device can be referred to. # @id: #optional id by which the new block device can be referred to.
# This is a required option on the top level of blockdev-add, and # This is a required option on the top level of blockdev-add, and
# currently not allowed on any other level. # currently not allowed on any other level.
# @node-name: #optional the name of a block driver state node (Since 2.0)
# @discard: #optional discard-related options (default: ignore) # @discard: #optional discard-related options (default: ignore)
# @cache: #optional cache-related options # @cache: #optional cache-related options
# @aio: #optional AIO backend (default: threads) # @aio: #optional AIO backend (default: threads)
...@@ -4107,6 +4108,7 @@ ...@@ -4107,6 +4108,7 @@
{ 'type': 'BlockdevOptionsBase', { 'type': 'BlockdevOptionsBase',
'data': { 'driver': 'str', 'data': { 'driver': 'str',
'*id': 'str', '*id': 'str',
'*node-name': 'str',
'*discard': 'BlockdevDiscardOptions', '*discard': 'BlockdevDiscardOptions',
'*cache': 'BlockdevCacheOptions', '*cache': 'BlockdevCacheOptions',
'*aio': 'BlockdevAioOptions', '*aio': 'BlockdevAioOptions',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册