[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC V2 2/3] block: Allow the user to define "node-name" op
From: |
Benoît Canet |
Subject: |
[Qemu-devel] [RFC V2 2/3] block: Allow the user to define "node-name" option. |
Date: |
Tue, 12 Nov 2013 15:39:17 +0100 |
Signed-off-by: Benoit Canet <address@hidden>
---
block.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/block.c b/block.c
index c397ee9..6690e3d 100644
--- a/block.c
+++ b/block.c
@@ -872,6 +872,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char
*filename,
const char *drvname;
bool allow_protocol_prefix = false;
Error *local_err = NULL;
+ const char *node_name = NULL;
int ret;
/* NULL means an empty set of options */
@@ -879,7 +880,14 @@ int bdrv_file_open(BlockDriverState **pbs, const char
*filename,
options = qdict_new();
}
- bs = bdrv_new("", "");
+ node_name = qdict_get_try_str(options, "node-name");
+ if (node_name && bdrv_find_node(node_name)) {
+ error_setg(errp, "Duplicate node name");
+ return -EINVAL;
+ }
+ bs = bdrv_new("", node_name ? node_name : "");
+ qdict_del(options, "node-name");
+
bs->options = options;
options = qdict_clone_shallow(options);
@@ -979,6 +987,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict
*options, Error **errp)
int back_flags, ret;
BlockDriver *back_drv = NULL;
Error *local_err = NULL;
+ const char *node_name = NULL;
if (bs->backing_hd != NULL) {
QDECREF(options);
@@ -1001,7 +1010,14 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict
*options, Error **errp)
sizeof(backing_filename));
}
- bs->backing_hd = bdrv_new("", "");
+ node_name = qdict_get_try_str(options, "node-name");
+ if (node_name && bdrv_find_node(node_name)) {
+ error_setg(errp, "Duplicate node name");
+ QDECREF(options);
+ return -EINVAL;
+ }
+ bs->backing_hd = bdrv_new("", node_name ? node_name : "");
+ qdict_del(options, "node-name");
if (bs->backing_format[0] != '\0') {
back_drv = bdrv_find_format(bs->backing_format);
--
1.8.3.2