From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53082) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6kUn-0003Qq-66 for qemu-devel@nongnu.org; Fri, 24 Jan 2014 12:24:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6kUh-0007y8-MW for qemu-devel@nongnu.org; Fri, 24 Jan 2014 12:24:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:5493) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6kUh-0007y3-CO for qemu-devel@nongnu.org; Fri, 24 Jan 2014 12:24:39 -0500 From: Kevin Wolf Date: Fri, 24 Jan 2014 18:21:37 +0100 Message-Id: <1390584136-24703-55-git-send-email-kwolf@redhat.com> In-Reply-To: <1390584136-24703-1-git-send-email-kwolf@redhat.com> References: <1390584136-24703-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 54/93] block: Allow the user to define "node-name" option both on command line and QMP. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Beno=C3=AEt Canet Signed-off-by: Benoit Canet Signed-off-by: Kevin Wolf --- block.c | 35 +++++++++++++++++++++++++++++++++++ qapi-schema.json | 2 ++ 2 files changed, 37 insertions(+) diff --git a/block.c b/block.c index 8562685..f043669 100644 --- a/block.c +++ b/block.c @@ -735,6 +735,33 @@ static int bdrv_open_flags(BlockDriverState *bs, int= flags) return open_flags; } =20 +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] =3D=3D '\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 * @@ -745,6 +772,7 @@ static int bdrv_open_common(BlockDriverState *bs, Blo= ckDriverState *file, { int ret, open_flags; const char *filename; + const char *node_name =3D NULL; Error *local_err =3D NULL; =20 assert(drv !=3D NULL); @@ -759,6 +787,13 @@ static int bdrv_open_common(BlockDriverState *bs, Bl= ockDriverState *file, =20 trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name); =20 + node_name =3D qdict_get_try_str(options, "node-name"); + ret =3D 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 * opened, so assign it to bs (while file becomes a closed BlockDriv= erState) * and return immediately. */ diff --git a/qapi-schema.json b/qapi-schema.json index a433869..26e370b 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4092,6 +4092,7 @@ # @id: #optional id by which the new block device can be referr= ed to. # This is a required option on the top level of blockdev-a= dd, and # 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) # @cache: #optional cache-related options # @aio: #optional AIO backend (default: threads) @@ -4107,6 +4108,7 @@ { 'type': 'BlockdevOptionsBase', 'data': { 'driver': 'str', '*id': 'str', + '*node-name': 'str', '*discard': 'BlockdevDiscardOptions', '*cache': 'BlockdevCacheOptions', '*aio': 'BlockdevAioOptions', --=20 1.8.1.4