diff mbox series

[1/2] When del child, next_child_index need to subtract 1. Otherwise, the index will get bigger and bigger.

Message ID 1589191231-18876-1-git-send-email-quweijie@huayun.com
State New
Headers show
Series [1/2] When del child, next_child_index need to subtract 1. Otherwise, the index will get bigger and bigger. | expand

Commit Message

quweijie@huayun.com May 11, 2020, 10 a.m. UTC
From: quweijie <quweijie@huayun.com>

Signed-off-by: quweijie <quweijie@huayun.com>
---
 block/quorum.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Alberto Garcia May 11, 2020, 10:10 a.m. UTC | #1
On Mon 11 May 2020 12:00:30 PM CEST, quweijie@huayun.com wrote:
> diff --git a/block/quorum.c b/block/quorum.c
> index 6d7a56b..a8272fe 100644
> --- a/block/quorum.c
> +++ b/block/quorum.c
> @@ -1096,6 +1096,7 @@ static void quorum_del_child(BlockDriverState *bs, BdrvChild *child,
>      memmove(&s->children[i], &s->children[i + 1],
>              (s->num_children - i - 1) * sizeof(BdrvChild *));
>      s->children = g_renew(BdrvChild *, s->children, --s->num_children);
> +    s->next_child_index--;
>      bdrv_unref_child(bs, child);

This is not correct, quorum_del_child() allows you to remove any child
from the Quorum device, so nothing guarantees you that
next_child_index-1 is free.

Berto
diff mbox series

Patch

diff --git a/block/quorum.c b/block/quorum.c
index 6d7a56b..a8272fe 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -1096,6 +1096,7 @@  static void quorum_del_child(BlockDriverState *bs, BdrvChild *child,
     memmove(&s->children[i], &s->children[i + 1],
             (s->num_children - i - 1) * sizeof(BdrvChild *));
     s->children = g_renew(BdrvChild *, s->children, --s->num_children);
+    s->next_child_index--;
     bdrv_unref_child(bs, child);
 
     bdrv_drained_end(bs);