All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] quorum: Handle bdrv_getlength() failures in quorum_co_flush()
@ 2017-08-04 14:08 Alberto Garcia
  2017-08-04 15:44 ` [Qemu-devel] [PATCH for-2.10] " Eric Blake
  0 siblings, 1 reply; 5+ messages in thread
From: Alberto Garcia @ 2017-08-04 14:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-block, Markus Armbruster, Alberto Garcia

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.

Reported-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Alberto Garcia <berto@igalia.com>
---
 block/quorum.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/block/quorum.c b/block/quorum.c
index 55ba916655..d77991d680 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -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);
-- 
2.11.0

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

* Re: [Qemu-devel] [PATCH for-2.10] quorum: Handle bdrv_getlength() failures in quorum_co_flush()
  2017-08-04 14:08 [Qemu-devel] [PATCH] quorum: Handle bdrv_getlength() failures in quorum_co_flush() Alberto Garcia
@ 2017-08-04 15:44 ` Eric Blake
  2017-08-07  8:43   ` Alberto Garcia
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Blake @ 2017-08-04 15:44 UTC (permalink / raw)
  To: Alberto Garcia, qemu-devel; +Cc: Markus Armbruster, qemu-block

[-- Attachment #1: Type: text/plain, Size: 1430 bytes --]

On 08/04/2017 09:08 AM, Alberto Garcia wrote:
> 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.
> 
> Reported-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> ---
>  block/quorum.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/block/quorum.c b/block/quorum.c
> index 55ba916655..d77991d680 100644
> --- a/block/quorum.c
> +++ b/block/quorum.c
> @@ -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.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

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

* Re: [Qemu-devel] [PATCH for-2.10] quorum: Handle bdrv_getlength() failures in quorum_co_flush()
  2017-08-04 15:44 ` [Qemu-devel] [PATCH for-2.10] " Eric Blake
@ 2017-08-07  8:43   ` Alberto Garcia
  2017-08-07 11:29     ` Eric Blake
  0 siblings, 1 reply; 5+ messages in thread
From: Alberto Garcia @ 2017-08-07  8:43 UTC (permalink / raw)
  To: Eric Blake, qemu-devel; +Cc: Markus Armbruster, qemu-block

On Fri 04 Aug 2017 05:44:00 PM CEST, Eric Blake wrote:
>> --- a/block/quorum.c
>> +++ b/block/quorum.c
>> @@ -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.

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

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

* Re: [Qemu-devel] [PATCH for-2.10] quorum: Handle bdrv_getlength() failures in quorum_co_flush()
  2017-08-07  8:43   ` Alberto Garcia
@ 2017-08-07 11:29     ` Eric Blake
  2017-08-07 12:12       ` Alberto Garcia
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Blake @ 2017-08-07 11:29 UTC (permalink / raw)
  To: Alberto Garcia, qemu-devel; +Cc: Markus Armbruster, qemu-block

[-- Attachment #1: Type: text/plain, Size: 1278 bytes --]

On 08/07/2017 03:43 AM, Alberto Garcia wrote:
> On Fri 04 Aug 2017 05:44:00 PM CEST, Eric Blake wrote:
>>> --- a/block/quorum.c
>>> +++ b/block/quorum.c
>>> @@ -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.
> 
> 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?

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

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

* Re: [Qemu-devel] [PATCH for-2.10] quorum: Handle bdrv_getlength() failures in quorum_co_flush()
  2017-08-07 11:29     ` Eric Blake
@ 2017-08-07 12:12       ` Alberto Garcia
  0 siblings, 0 replies; 5+ messages in thread
From: Alberto Garcia @ 2017-08-07 12:12 UTC (permalink / raw)
  To: Eric Blake, qemu-devel; +Cc: Markus Armbruster, qemu-block

On Mon 07 Aug 2017 01:29:09 PM CEST, Eric Blake wrote:
> On 08/07/2017 03:43 AM, Alberto Garcia wrote:
>> On Fri 04 Aug 2017 05:44:00 PM CEST, Eric Blake wrote:
>>>> --- a/block/quorum.c
>>>> +++ b/block/quorum.c
>>>> @@ -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.
>> 
>> 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

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

end of thread, other threads:[~2017-08-07 12:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-04 14:08 [Qemu-devel] [PATCH] quorum: Handle bdrv_getlength() failures in quorum_co_flush() Alberto Garcia
2017-08-04 15:44 ` [Qemu-devel] [PATCH for-2.10] " Eric Blake
2017-08-07  8:43   ` Alberto Garcia
2017-08-07 11:29     ` Eric Blake
2017-08-07 12:12       ` Alberto Garcia

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.