qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [QEMU 2.0 FIX V2] Fix bdrv_swap behavior regarding the node graph
@ 2014-03-05 22:48 Benoît Canet
  2014-03-05 22:48 ` [Qemu-devel] [QEMU 2.0 FIX V2] block: make bdrv_swap rebuild the bs graph node list field Benoît Canet
  0 siblings, 1 reply; 4+ messages in thread
From: Benoît Canet @ 2014-03-05 22:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Benoît Canet, stefanha, mreitz

This bug was discovered while working on the quorum file replacement.

The patch switch to a more sane behavior discussed with Kevin.

Best regards

Benoît

Benoît Canet (1):
  block: make bdrv_swap rebuild the bs graph node list field.

 block.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

-- 
1.8.3.2

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] [QEMU 2.0 FIX V2] block: make bdrv_swap rebuild the bs graph node list field.
  2014-03-05 22:48 [Qemu-devel] [QEMU 2.0 FIX V2] Fix bdrv_swap behavior regarding the node graph Benoît Canet
@ 2014-03-05 22:48 ` Benoît Canet
  2014-03-06 10:33   ` Kevin Wolf
  2014-03-06 10:45   ` Kevin Wolf
  0 siblings, 2 replies; 4+ messages in thread
From: Benoît Canet @ 2014-03-05 22:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, Benoît Canet, Benoit Canet, stefanha, mreitz

Moving only the node_name one field could lead to some inconsitencies where 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 this.

bdrv_make_anon would then crash because it would try to remove the bs from 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 <benoit@irqsave.net>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
 block.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/block.c b/block.c
index 0f4e5b9..495eb1b 100644
--- a/block.c
+++ b/block.c
@@ -1846,11 +1846,6 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest,
     pstrcpy(bs_dest->device_name, sizeof(bs_dest->device_name),
             bs_src->device_name);
     bs_dest->device_list = 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 entries
-     */
-    bs_dest->node_list   = bs_src->node_list;
 }
 
 /*
@@ -1869,6 +1864,17 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
 {
     BlockDriverState tmp;
 
+    /* The code needs to swap the node_name but simply swapping node_list won't
+     * 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] != '\0') {
+        QTAILQ_REMOVE(&graph_bdrv_states, bs_new, node_list);
+    }
+    if (bs_old->node_name[0] != '\0') {
+        QTAILQ_REMOVE(&graph_bdrv_states, bs_old, node_list);
+    }
+
     /* bs_new must be anonymous and shouldn't have anything fancy enabled */
     assert(bs_new->device_name[0] == '\0');
     assert(QLIST_EMPTY(&bs_new->dirty_bitmaps));
@@ -1897,6 +1903,14 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
     assert(bs_new->io_limits_enabled == false);
     assert(!throttle_have_timer(&bs_new->throttle_state));
 
+    /* insert the nodes back into the graph node list if needed */
+    if (bs_new->node_name[0] != '\0') {
+        QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs_new, node_list);
+    }
+    if (bs_old->node_name[0] != '\0') {
+        QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs_old, node_list);
+    }
+
     bdrv_rebind(bs_new);
     bdrv_rebind(bs_old);
 }
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [QEMU 2.0 FIX V2] block: make bdrv_swap rebuild the bs graph node list field.
  2014-03-05 22:48 ` [Qemu-devel] [QEMU 2.0 FIX V2] block: make bdrv_swap rebuild the bs graph node list field Benoît Canet
@ 2014-03-06 10:33   ` Kevin Wolf
  2014-03-06 10:45   ` Kevin Wolf
  1 sibling, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2014-03-06 10:33 UTC (permalink / raw)
  To: Benoît Canet; +Cc: Benoit Canet, qemu-devel, stefanha, mreitz

Am 05.03.2014 um 23:48 hat Benoît Canet geschrieben:
> Moving only the node_name one field could lead to some inconsitencies where 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 this.
> 
> bdrv_make_anon would then crash because it would try to remove the bs from 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 <benoit@irqsave.net>
> Reviewed-by: Max Reitz <mreitz@redhat.com>

Thanks, applied to the block branch.

Kevin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [QEMU 2.0 FIX V2] block: make bdrv_swap rebuild the bs graph node list field.
  2014-03-05 22:48 ` [Qemu-devel] [QEMU 2.0 FIX V2] block: make bdrv_swap rebuild the bs graph node list field Benoît Canet
  2014-03-06 10:33   ` Kevin Wolf
@ 2014-03-06 10:45   ` Kevin Wolf
  1 sibling, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2014-03-06 10:45 UTC (permalink / raw)
  To: Benoît Canet; +Cc: Benoit Canet, qemu-devel, stefanha, mreitz

Am 05.03.2014 um 23:48 hat Benoît Canet geschrieben:
> Moving only the node_name one field could lead to some inconsitencies where 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 this.
> 
> bdrv_make_anon would then crash because it would try to remove the bs from 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 <benoit@irqsave.net>
> Reviewed-by: Max Reitz <mreitz@redhat.com>

By the way, can you please just use the PATCH keyword in the subject
line like everyone else? Some people are relying on this to filter their
mail. If you like to express your intention to get it merged in time for
2.0, the traditional format is [PATCH for-2.0].

Kevin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-03-06 10:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-05 22:48 [Qemu-devel] [QEMU 2.0 FIX V2] Fix bdrv_swap behavior regarding the node graph Benoît Canet
2014-03-05 22:48 ` [Qemu-devel] [QEMU 2.0 FIX V2] block: make bdrv_swap rebuild the bs graph node list field Benoît Canet
2014-03-06 10:33   ` Kevin Wolf
2014-03-06 10:45   ` Kevin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).