[v3,4/4] block/badblocks: fix the bug of reverse order

Message ID 20230621172052.1499919-5-linan666@huaweicloud.com
State New
Headers
Series block/badblocks: fix badblocks setting error |

Commit Message

Li Nan June 21, 2023, 5:20 p.m. UTC
  From: Li Nan <linan122@huawei.com>

Order of badblocks will be reversed if we set a large area at once. 'hi'
remains unchanged while adding continuous badblocks is wrong, the next
setting is greater than 'hi', it should be added to the next position.
Let 'hi' +1 each cycle.

  # echo 0 2048 > bad_blocks
  # cat bad_blocks
    1536 512
    1024 512
    512 512
    0 512

Fixes: 9e0e252a048b ("badblocks: Add core badblock management code")
Signed-off-by: Li Nan <linan122@huawei.com>
---
 block/badblocks.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Ashok Raj June 21, 2023, 2:15 p.m. UTC | #1
On Thu, Jun 22, 2023 at 01:20:52AM +0800, linan666@huaweicloud.com wrote:
> From: Li Nan <linan122@huawei.com>
> 
> Order of badblocks will be reversed if we set a large area at once. 'hi'
> remains unchanged while adding continuous badblocks is wrong, the next
> setting is greater than 'hi', it should be added to the next position.
> Let 'hi' +1 each cycle.

The commitlog needs more work. 
> 
>   # echo 0 2048 > bad_blocks
>   # cat bad_blocks
>     1536 512
>     1024 512
>     512 512
>     0 512

Is the above before or after this patch is applied?

> 
> Fixes: 9e0e252a048b ("badblocks: Add core badblock management code")
> Signed-off-by: Li Nan <linan122@huawei.com>
> ---
>  block/badblocks.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/block/badblocks.c b/block/badblocks.c
> index 2c2ef8284a3f..3b816690b940 100644
> --- a/block/badblocks.c
> +++ b/block/badblocks.c
> @@ -301,6 +301,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
>  			p[hi] = BB_MAKE(s, this_sectors, acknowledged);
>  			sectors -= this_sectors;
>  			s += this_sectors;
> +			hi++;
>  			changed = true;
>  		}
>  	}
> -- 
> 2.39.2
>
  
Li Nan June 25, 2023, 9:22 a.m. UTC | #2
在 2023/6/21 22:15, Ashok Raj 写道:
> On Thu, Jun 22, 2023 at 01:20:52AM +0800, linan666@huaweicloud.com wrote:
>> From: Li Nan <linan122@huawei.com>
>>
>> Order of badblocks will be reversed if we set a large area at once. 'hi'
>> remains unchanged while adding continuous badblocks is wrong, the next
>> setting is greater than 'hi', it should be added to the next position.
>> Let 'hi' +1 each cycle.
> 
> The commitlog needs more work.

OK, I will improve this.

>>
>>    # echo 0 2048 > bad_blocks
>>    # cat bad_blocks
>>      1536 512
>>      1024 512
>>      512 512
>>      0 512
> 
> Is the above before or after this patch is applied?

All badblocks are arranged from small to large. after patch:

# cat bad_blocks
   0 512
   512 512
   1024 512
   1536 512

I will show it in next version. Thanks for your suggestion.

> 
>>
>> Fixes: 9e0e252a048b ("badblocks: Add core badblock management code")
>> Signed-off-by: Li Nan <linan122@huawei.com>
>> ---
>>   block/badblocks.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/block/badblocks.c b/block/badblocks.c
>> index 2c2ef8284a3f..3b816690b940 100644
>> --- a/block/badblocks.c
>> +++ b/block/badblocks.c
>> @@ -301,6 +301,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
>>   			p[hi] = BB_MAKE(s, this_sectors, acknowledged);
>>   			sectors -= this_sectors;
>>   			s += this_sectors;
>> +			hi++;
>>   			changed = true;
>>   		}
>>   	}
>> -- 
>> 2.39.2
>>
> 
> .
  

Patch

diff --git a/block/badblocks.c b/block/badblocks.c
index 2c2ef8284a3f..3b816690b940 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -301,6 +301,7 @@  int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
 			p[hi] = BB_MAKE(s, this_sectors, acknowledged);
 			sectors -= this_sectors;
 			s += this_sectors;
+			hi++;
 			changed = true;
 		}
 	}