[Qemu-devel] [PATCH] util/hbitmaps: recalculate count on merge

John Snow posted 1 patch 5 years, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20180926212814.3822-1-jsnow@redhat.com
Test docker-clang@ubuntu failed
Test checkpatch passed
util/hbitmap.c | 3 +++
1 file changed, 3 insertions(+)
[Qemu-devel] [PATCH] util/hbitmaps: recalculate count on merge
Posted by John Snow 5 years, 6 months ago
We have been neglecting to do so, which results in wrong counts
after merge. In the worst case, we may think the bitmap is empty
when it has had new writes merged into it.

Reported-by: Eric Blake <eblake@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
---
 util/hbitmap.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/util/hbitmap.c b/util/hbitmap.c
index d5aca5159f..28e9c523ab 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -759,6 +759,9 @@ bool hbitmap_merge(const HBitmap *a, const HBitmap *b, HBitmap *result)
         }
     }
 
+    /* Recompute the dirty count */
+    a->count = hb_count_between(a, 0, a->size - 1);
+
     return true;
 }
 
-- 
2.14.4


Re: [Qemu-devel] [PATCH] util/hbitmaps: recalculate count on merge
Posted by Vladimir Sementsov-Ogievskiy 5 years, 6 months ago
27.09.2018 00:28, John Snow wrote:
> We have been neglecting to do so, which results in wrong counts
> after merge. In the worst case, we may think the bitmap is empty
> when it has had new writes merged into it.
>
> Reported-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>   util/hbitmap.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/util/hbitmap.c b/util/hbitmap.c
> index d5aca5159f..28e9c523ab 100644
> --- a/util/hbitmap.c
> +++ b/util/hbitmap.c
> @@ -759,6 +759,9 @@ bool hbitmap_merge(const HBitmap *a, const HBitmap *b, HBitmap *result)
>           }
>       }
>   
> +    /* Recompute the dirty count */
> +    a->count = hb_count_between(a, 0, a->size - 1);

hmm, just looking at function header: shouldn't we update result->count 
instead? This code shouldn't compile (thanks to my const*)

> +
>       return true;
>   }
>   


-- 
Best regards,
Vladimir


Re: [Qemu-devel] [PATCH] util/hbitmaps: recalculate count on merge
Posted by Eric Blake 5 years, 6 months ago
On 9/27/18 2:31 AM, Vladimir Sementsov-Ogievskiy wrote:
> 27.09.2018 00:28, John Snow wrote:
>> We have been neglecting to do so, which results in wrong counts
>> after merge. In the worst case, we may think the bitmap is empty
>> when it has had new writes merged into it.
>>
>> Reported-by: Eric Blake <eblake@redhat.com>
>> Signed-off-by: John Snow <jsnow@redhat.com>
>> ---
>>   util/hbitmap.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/util/hbitmap.c b/util/hbitmap.c
>> index d5aca5159f..28e9c523ab 100644
>> --- a/util/hbitmap.c
>> +++ b/util/hbitmap.c
>> @@ -759,6 +759,9 @@ bool hbitmap_merge(const HBitmap *a, const HBitmap 
>> *b, HBitmap *result)
>>           }
>>       }
>> +    /* Recompute the dirty count */
>> +    a->count = hb_count_between(a, 0, a->size - 1);
> 
> hmm, just looking at function header: shouldn't we update result->count 
> instead? This code shouldn't compile (thanks to my const*)

Hmm. It looks like John and I posted essentially the same patch, but 
that John's version is based against his out-of-tree patch queue, which 
includes Vladimir's "dirty-bitmap: make it possible to restore bitmap 
after merge".

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

Re: [Qemu-devel] [PATCH] util/hbitmaps: recalculate count on merge
Posted by John Snow 5 years, 6 months ago

On 09/27/2018 10:09 AM, Eric Blake wrote:
> On 9/27/18 2:31 AM, Vladimir Sementsov-Ogievskiy wrote:
>> 27.09.2018 00:28, John Snow wrote:
>>> We have been neglecting to do so, which results in wrong counts
>>> after merge. In the worst case, we may think the bitmap is empty
>>> when it has had new writes merged into it.
>>>
>>> Reported-by: Eric Blake <eblake@redhat.com>
>>> Signed-off-by: John Snow <jsnow@redhat.com>
>>> ---
>>>   util/hbitmap.c | 3 +++
>>>   1 file changed, 3 insertions(+)
>>>
>>> diff --git a/util/hbitmap.c b/util/hbitmap.c
>>> index d5aca5159f..28e9c523ab 100644
>>> --- a/util/hbitmap.c
>>> +++ b/util/hbitmap.c
>>> @@ -759,6 +759,9 @@ bool hbitmap_merge(const HBitmap *a, const
>>> HBitmap *b, HBitmap *result)
>>>           }
>>>       }
>>> +    /* Recompute the dirty count */
>>> +    a->count = hb_count_between(a, 0, a->size - 1);
>>
>> hmm, just looking at function header: shouldn't we update
>> result->count instead? This code shouldn't compile (thanks to my const*)
> 
> Hmm. It looks like John and I posted essentially the same patch, but
> that John's version is based against his out-of-tree patch queue, which
> includes Vladimir's "dirty-bitmap: make it possible to restore bitmap
> after merge".
> 

Oh, I see, we each posted one. Whoops!

Yes, mine is based off of the transactionable merge series.

--js