From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52373) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLuu3-0003Vx-5k for qemu-devel@nongnu.org; Fri, 07 Mar 2014 08:33:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WLuty-0001jk-2P for qemu-devel@nongnu.org; Fri, 07 Mar 2014 08:33:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50248) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLutx-0001jb-PU for qemu-devel@nongnu.org; Fri, 07 Mar 2014 08:33:25 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s27DXOK5031359 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 7 Mar 2014 08:33:24 -0500 From: Kevin Wolf Date: Fri, 7 Mar 2014 14:32:55 +0100 Message-Id: <1394199187-9576-8-git-send-email-kwolf@redhat.com> In-Reply-To: <1394199187-9576-1-git-send-email-kwolf@redhat.com> References: <1394199187-9576-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 07/19] block: make bdrv_swap rebuild the bs graph node list field. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com From: Beno=C3=AEt Canet Moving only the node_name one field could lead to some inconsitencies whe= re a node_name was defined on a bs which was not registered in the graph node = list. bdrv_swap between a named node bs and a non named node bs would lead to t= his. bdrv_make_anon would then crash because it would try to remove the bs fro= m the graph node list while it is not in it. This patch remove named node bses from the graph node list before doing t= he swap then insert them back. Signed-off-by: Benoit Canet Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index f01b91c..7330a87 100644 --- a/block.c +++ b/block.c @@ -1847,11 +1847,6 @@ static void bdrv_move_feature_fields(BlockDriverSt= ate *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 entrie= s - */ - bs_dest->node_list =3D bs_src->node_list; } =20 /* @@ -1870,6 +1865,17 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriv= erState *bs_old) { BlockDriverState tmp; =20 + /* The code needs to swap the node_name but simply swapping node_lis= t won't + * work so first remove the nodes from the graph list, do the swap t= hen + * 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 enable= d */ assert(bs_new->device_name[0] =3D=3D '\0'); assert(QLIST_EMPTY(&bs_new->dirty_bitmaps)); @@ -1898,6 +1904,14 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriv= erState *bs_old) assert(bs_new->io_limits_enabled =3D=3D false); assert(!throttle_have_timer(&bs_new->throttle_state)); =20 + /* insert the nodes back into the graph node list if needed */ + 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); } --=20 1.8.1.4