[PATCH 4/6] parallels: Use highest_offset() helper in leak check

Alexander Ivanov posted 6 patches 3 years, 5 months ago
There is a newer version of this series
[PATCH 4/6] parallels: Use highest_offset() helper in leak check
Posted by Alexander Ivanov 3 years, 5 months ago
Deduplicate code by using highest_offset() helper.

Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 block/parallels.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/block/parallels.c b/block/parallels.c
index 339ce45634..688aa081e2 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -535,16 +535,9 @@ static int parallels_check_leak(BlockDriverState *bs,
                                 BdrvCheckMode fix)
 {
     BDRVParallelsState *s = bs->opaque;
-    int64_t off, high_off, count, cut_out;
-    uint32_t i;
+    int64_t high_off, count, cut_out;
 
-    high_off = 0;
-    for (i = 0; i < s->bat_size; i++) {
-        off = bat2sect(s, i) << BDRV_SECTOR_BITS;
-        if (off > high_off) {
-            high_off = off;
-        }
-    }
+    high_off = highest_offset(s);
 
     cut_out = parallels_handle_leak(bs, res, high_off, fix & BDRV_FIX_LEAKS);
     if (cut_out < 0) {
-- 
2.34.1
Re: [PATCH 4/6] parallels: Use highest_offset() helper in leak check
Posted by Denis V. Lunev 3 years, 5 months ago
On 9/2/22 10:52, Alexander Ivanov wrote:
> Deduplicate code by using highest_offset() helper.
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
>   block/parallels.c | 11 ++---------
>   1 file changed, 2 insertions(+), 9 deletions(-)
>
> diff --git a/block/parallels.c b/block/parallels.c
> index 339ce45634..688aa081e2 100644
> --- a/block/parallels.c
> +++ b/block/parallels.c
> @@ -535,16 +535,9 @@ static int parallels_check_leak(BlockDriverState *bs,
>                                   BdrvCheckMode fix)
>   {
>       BDRVParallelsState *s = bs->opaque;
> -    int64_t off, high_off, count, cut_out;
> -    uint32_t i;
> +    int64_t high_off, count, cut_out;
>   
> -    high_off = 0;
> -    for (i = 0; i < s->bat_size; i++) {
> -        off = bat2sect(s, i) << BDRV_SECTOR_BITS;
> -        if (off > high_off) {
> -            high_off = off;
> -        }
> -    }
> +    high_off = highest_offset(s);
>   
>       cut_out = parallels_handle_leak(bs, res, high_off, fix & BDRV_FIX_LEAKS);
>       if (cut_out < 0) {
Here I kinda disagree. This change and the introduction of the
helper should be done exactly in the same patch as in the other
case it is not possible to say whether this replacement is
correct or not.

Den