quorum: Handle bdrv_getlength() failures in quorum_co_flush()
PATCH 1/1 quorum: Handle bdrv_getlength() failures in quorum_co_flush()
A bdrv_getlength() call can fail and return a negative value. This is not being handled in quorum_co_flush(), which can result in a QUORUM_REPORT_BAD event with an arbitrary value on the 'sectors-count' field.
--- block/quorum.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/quorum.c +2 -1
@@ -785,8 +785,9 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs)for (i =0 ; i < s->num_children; i++) { result =bdrv_co_flush (s->children[i]->bs);if (result) { +int64_t length =bdrv_getlength (s->children[i]->bs);quorum_report_bad (QUORUM_OP_TYPE_FLUSH ,0 , -bdrv_getlength (s->children[i]->bs), + length >0 ? length :0 , s->children[i]->bs->node_name, result); result_value.l = result;quorum_count_vote (&error_votes, &result_value, i);
Signature · 1 line
2.11.0
Quoted 16 lines · Alberto Garcia
A
bdrv_getlength()call can fail and return a negative value. This is not being handled inquorum_co_flush(), which can result in aQUORUM_REPORT_BADevent with an arbitrary value on the 'sectors-count' field.Reported-by Markus Armbruster <[email protected]>Signed-off-by Alberto Garcia <[email protected]>--- block/quorum.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)block/quorum.c +0
-0
block/quorum.c static coroutine_fn int quorum_co_flush(BlockDriverState *bs) · line 790
Quoted 7 lines
block/quorum.c +2
-1@@ -785,8 +785,9 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs)for (i =0 ; i < s->num_children; i++) { result =bdrv_co_flush (s->children[i]->bs);if (result) { +int64_t length =bdrv_getlength (s->children[i]->bs); quorum_report_bad(QUORUM_OP_TYPE_FLUSH, 0, - bdrv_getlength(s->children[i]->bs), + length > 0 ? length : 0,
In the fallback case, is always picking 0 good enough? Then again, this is in the error path, so it is unlikely in practice, and I don't see any better way to handle it.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 6 lines · Eric Blake
Quoted 6 lines
block/quorum.c +0
-0@@ -785,8 +785,9 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs)for (i =0 ; i < s->num_children; i++) { result =bdrv_co_flush (s->children[i]->bs);if (result) {
Quoted 8 lines
block/quorum.c static coroutine_fn int quorum_co_flush(BlockDriverState *bs) · line 790
Quoted 4 lines
block/quorum.c +2
-1+int64_t length =bdrv_getlength (s->children[i]->bs); quorum_report_bad(QUORUM_OP_TYPE_FLUSH, 0, - bdrv_getlength(s->children[i]->bs), + length > 0 ? length : 0,In the fallback case, is always picking 0 good enough? Then again, this is in the error path, so it is unlikely in practice, and I don't see any better way to handle it.
I don't see any better way to handle it either, and I'm not sure that it matters much: this is a flush error event, the 'sectors-count' field doesn't even mean anything, but we have to put something there.
Berto
Quoted 16 lines · Alberto Garcia
Quoted 6 lines · Eric Blake
Quoted 6 lines
block/quorum.c +0
-0@@ -785,8 +785,9 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs)for (i =0 ; i < s->num_children; i++) { result =bdrv_co_flush (s->children[i]->bs);if (result) {Quoted 8 lines
block/quorum.c static coroutine_fn int quorum_co_flush(BlockDriverState *bs) · line 790
Quoted 4 lines
block/quorum.c +2
-1+int64_t length =bdrv_getlength (s->children[i]->bs); quorum_report_bad(QUORUM_OP_TYPE_FLUSH, 0, - bdrv_getlength(s->children[i]->bs), + length > 0 ? length : 0,In the fallback case, is always picking 0 good enough? Then again, this is in the error path, so it is unlikely in practice, and I don't see any better way to handle it.
Quoted 3 lines
I don't see any better way to handle it either, and I'm not sure that it matters much: this is a flush error event, the 'sectors-count' field doesn't even mean anything, but we have to put something there.
If that's the case, can we ALWAYS report 0, instead of usually the length and sometimes 0?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 17 lines · Eric Blake
Quoted 16 lines · Alberto Garcia
Quoted 14 lines · Eric Blake
block/quorum.c static coroutine_fn int quorum_co_flush(BlockDriverState *bs) · line 790
Quoted 10 lines
block/quorum.c +2
-1@@ -785,8 +785,9 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs)for (i =0 ; i < s->num_children; i++) { result =bdrv_co_flush (s->children[i]->bs);if (result) { +int64_t length =bdrv_getlength (s->children[i]->bs); quorum_report_bad(QUORUM_OP_TYPE_FLUSH, 0, - bdrv_getlength(s->children[i]->bs), + length > 0 ? length : 0,In the fallback case, is always picking 0 good enough? Then again, this is in the error path, so it is unlikely in practice, and I don't see any better way to handle it.
Quoted 6 lines
Quoted 3 lines
I don't see any better way to handle it either, and I'm not sure that it matters much: this is a flush error event, the 'sectors-count' field doesn't even mean anything, but we have to put something there.
If that's the case, can we ALWAYS report 0, instead of usually the length and sometimes 0?
That's actually not a bad idea, I'll send the patch now.
Berto