From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLKDB-0004wv-JE for qemu-devel@nongnu.org; Wed, 05 Mar 2014 17:22:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WLKD2-0006s8-Jw for qemu-devel@nongnu.org; Wed, 05 Mar 2014 17:22:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:9448) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLKD2-0006rz-BU for qemu-devel@nongnu.org; Wed, 05 Mar 2014 17:22:40 -0500 Message-ID: <5317A3A6.3040005@redhat.com> Date: Wed, 05 Mar 2014 23:22:30 +0100 From: Max Reitz MIME-Version: 1.0 References: <1393951330-25436-1-git-send-email-benoit.canet@irqsave.net> <1393951330-25436-2-git-send-email-benoit.canet@irqsave.net> In-Reply-To: <1393951330-25436-2-git-send-email-benoit.canet@irqsave.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [QEMU 2.0 Fix] block: make bdrv_swap rebuild the bs graph node list field. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?ISO-8859-1?Q?Beno=EEt_Canet?= , qemu-devel@nongnu.org Cc: kwolf@redhat.com, Benoit Canet , stefanha@redhat.com On 04.03.2014 17:42, Beno=EEt Canet wrote: > Moving only the node_name one field could lead to some inconsitencies w= here a > node_name was defined on a bs which was not registered in the graph nod= e list. > > bdrv_swap between a named node bs and a non named node bs would lead to= this. > > bdrv_make_anon would then crash because it would try to remove the bs f= rom the > graph node list while it is not in it. > > This patch remove named node bses from the graph node list before doing= the swap > then insert them back. > > Signed-off-by: Benoit Canet > --- > block.c | 24 +++++++++++++++++++----- > 1 file changed, 19 insertions(+), 5 deletions(-) > > diff --git a/block.c b/block.c > index 749835c..71349e5 100644 > --- a/block.c > +++ b/block.c > @@ -1846,11 +1846,6 @@ static void bdrv_move_feature_fields(BlockDriver= State *bs_dest, > pstrcpy(bs_dest->device_name, sizeof(bs_dest->device_name), > bs_src->device_name); > bs_dest->device_list =3D bs_src->device_list; > - > - /* keep the same entry in graph_bdrv_states > - * We do want to swap name but don't want to swap linked list entr= ies > - */ > - bs_dest->node_list =3D bs_src->node_list; > } > =20 > /* > @@ -1869,6 +1864,17 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDr= iverState *bs_old) > { > BlockDriverState tmp; > =20 > + /* The code need to swap the node_name but simply swapping node_li= st won't *needs > + * work so first remove the nodes from the graph list, do the swap= then > + * insert them back if needed. > + */ > + if (bs_new->node_name[0] !=3D '\0') { > + QTAILQ_REMOVE(&graph_bdrv_states, bs_new, node_list); > + } > + if (bs_old->node_name[0] !=3D '\0') { > + QTAILQ_REMOVE(&graph_bdrv_states, bs_old, node_list); > + } > + > /* bs_new must be anonymous and shouldn't have anything fancy ena= bled */ > assert(bs_new->device_name[0] =3D=3D '\0'); > assert(QLIST_EMPTY(&bs_new->dirty_bitmaps)); > @@ -1897,6 +1903,14 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDr= iverState *bs_old) > assert(bs_new->io_limits_enabled =3D=3D false); > assert(!throttle_have_timer(&bs_new->throttle_state)); > =20 > + /* insert back the nodes in the graph node list if needed */ The word order seems strange, I guess I'd put the "back" behind "nodes"=20 (and maybe "into" instead of "in"). > + if (bs_new->node_name[0] !=3D '\0') { > + QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs_new, node_list); > + } > + if (bs_old->node_name[0] !=3D '\0') { > + QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs_old, node_list); > + } > + > bdrv_rebind(bs_new); > bdrv_rebind(bs_old); > } Reviewed-by: Max Reitz