From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vql0L-0001jV-OR for qemu-devel@nongnu.org; Wed, 11 Dec 2013 09:43:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vql0G-0003ec-NH for qemu-devel@nongnu.org; Wed, 11 Dec 2013 09:43:13 -0500 Received: from nodalink.pck.nerim.net ([62.212.105.220]:47826 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vql0G-0003eQ-6n for qemu-devel@nongnu.org; Wed, 11 Dec 2013 09:43:08 -0500 Date: Wed, 11 Dec 2013 15:42:56 +0100 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20131211144256.GB2947@irqsave.net> References: <1386263703-19292-1-git-send-email-benoit@irqsave.net> <1386263703-19292-3-git-send-email-benoit@irqsave.net> <20131209161526.GI3549@dhcp-200-207.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <20131209161526.GI3549@dhcp-200-207.str.redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH V4 2/7] block: Allow the user to define "node-name" option. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: famz@redhat.com, jcody@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, stefanha@redhat.com Le Monday 09 Dec 2013 =E0 17:15:26 (+0100), Kevin Wolf a =E9crit : > Am 05.12.2013 um 18:14 hat Beno=EEt Canet geschrieben: > > Signed-off-by: Benoit Canet > > --- > > block.c | 44 +++++++++++++++++++++++++++++++++++++++----- > > 1 file changed, 39 insertions(+), 5 deletions(-) > >=20 > > diff --git a/block.c b/block.c > > index 4f6b36a..61f5ba0 100644 > > --- a/block.c > > +++ b/block.c > > @@ -873,6 +873,7 @@ int bdrv_file_open(BlockDriverState **pbs, const = char *filename, > > const char *drvname; > > bool allow_protocol_prefix =3D false; > > Error *local_err =3D NULL; > > + const char *node_name =3D NULL; > > int ret; > > =20 > > /* NULL means an empty set of options */ > > @@ -880,7 +881,15 @@ int bdrv_file_open(BlockDriverState **pbs, const= char *filename, > > options =3D qdict_new(); > > } > > =20 > > - bs =3D bdrv_new("", ""); > > + node_name =3D 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 =3D bdrv_new("", node_name ? node_name : ""); > > + qdict_del(options, "node-name"); > > + > > bs->options =3D options; > > options =3D qdict_clone_shallow(options); > > =20 > > @@ -980,6 +989,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, = QDict *options, Error **errp) > > int back_flags, ret; > > BlockDriver *back_drv =3D NULL; > > Error *local_err =3D NULL; > > + const char *node_name =3D NULL; > > =20 > > if (bs->backing_hd !=3D NULL) { > > QDECREF(options); > > @@ -1002,7 +1012,14 @@ int bdrv_open_backing_file(BlockDriverState *b= s, QDict *options, Error **errp) > > sizeof(backing_filename)); > > } > > =20 > > - bs->backing_hd =3D bdrv_new("", ""); > > + node_name =3D 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 =3D bdrv_new("", node_name ? node_name : ""); > > + qdict_del(options, "node-name"); > > =20 > > if (bs->backing_format[0] !=3D '\0') { > > back_drv =3D bdrv_find_format(bs->backing_format); > > @@ -1046,6 +1063,7 @@ int bdrv_open(BlockDriverState *bs, const char = *filename, QDict *options, > > BlockDriverState *file =3D NULL; > > QDict *file_options =3D NULL; > > const char *drvname; > > + const char *node_name =3D NULL; > > Error *local_err =3D NULL; > > =20 > > /* NULL means an empty set of options */ > > @@ -1053,6 +1071,22 @@ int bdrv_open(BlockDriverState *bs, const char= *filename, QDict *options, > > options =3D qdict_new(); > > } > > =20 > > + node_name =3D 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; > > + } > > + > > + if (node_name) { > > + pstrcpy(bs->node_name, sizeof(bs->node_name), node_name); > > + if (node_name[0] !=3D '\0') { > > + QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list); > > + } > > + } > > + > > + qdict_del(options, "node-name"); >=20 > We duplicate some code all over the place. In general you seem to be > trying to let the caller of bdrv_new() already figure out what the node > name is by parsing the options QDict; here however, you do it after > bdrv_new(). >=20 > Can't we consolidate this and only ever set the node name in > bdrv_open_common(), so that the option is parsed only once, there is > only once place adding BDSes to the list, and there is only one place > checking for duplicates? Nice idea it will make the patches much smaller and cleaner. Best regards Beno=EEt >=20 > Kevin