linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH RESEND] f2fs: validate before set/clear free nat bitmap
       [not found] <CGME20171111082604epcas5p472a0e6a07db371cb050eb6a13d8f0676@epcas5p4.samsung.com>
@ 2017-11-11  8:25 ` LiFan
  2017-11-14  4:54   ` Jaegeuk Kim
  0 siblings, 1 reply; 3+ messages in thread
From: LiFan @ 2017-11-11  8:25 UTC (permalink / raw)
  To: 'Chao Yu', 'Chao Yu', 'Jaegeuk Kim'
  Cc: linux-kernel, linux-f2fs-devel

In flush_nat_entries, all dirty nats will be flushed and if their new
address isn't 
NULL_ADDR, their bitmaps will be updated, the free_nid_count of the bitmaps 
will be increased regardless of whether the nats have already been occupied 
before. This could lead to wrong free_nid_count.
So this patch checks the status of the bits before actually set/clear them.

Fixes: 586d1492f301 ("f2fs: skip scanning free nid bitmap of full NAT
blocks")

Signed-off-by: Fan li <fanofcode.li@samsung.com>
---
 fs/f2fs/node.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index d234c6e..b965a53 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1906,15 +1906,18 @@ static void update_free_nid_bitmap(struct
f2fs_sb_info *sbi, nid_t nid,
 	if (!test_bit_le(nat_ofs, nm_i->nat_block_bitmap))
 		return;
 
-	if (set)
+	if (set) {
+		if (test_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]))
+			return;
 		__set_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
-	else
-		__clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
-
-	if (set)
 		nm_i->free_nid_count[nat_ofs]++;
-	else if (!build)
-		nm_i->free_nid_count[nat_ofs]--;
+	} else {
+		if (!test_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]))
+			return;
+		__clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
+		if (!build)
+			nm_i->free_nid_count[nat_ofs]--;
+	}
 }
 
 static void scan_nat_page(struct f2fs_sb_info *sbi,
--
2.7.4

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

* Re: [f2fs-dev] [PATCH RESEND] f2fs: validate before set/clear free nat bitmap
  2017-11-11  8:25 ` [f2fs-dev] [PATCH RESEND] f2fs: validate before set/clear free nat bitmap LiFan
@ 2017-11-14  4:54   ` Jaegeuk Kim
       [not found]     ` <000501d35d0d$e5d313d0$b1793b70$@samsung.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Jaegeuk Kim @ 2017-11-14  4:54 UTC (permalink / raw)
  To: LiFan
  Cc: 'Chao Yu', 'Chao Yu', linux-kernel, linux-f2fs-devel

Sorry, I can't merge this patch due to wrong format.

On 11/11, LiFan wrote:
> In flush_nat_entries, all dirty nats will be flushed and if their new
> address isn't 
> NULL_ADDR, their bitmaps will be updated, the free_nid_count of the bitmaps 
> will be increased regardless of whether the nats have already been occupied 
> before. This could lead to wrong free_nid_count.
> So this patch checks the status of the bits before actually set/clear them.
> 
> Fixes: 586d1492f301 ("f2fs: skip scanning free nid bitmap of full NAT
> blocks")
> 
> Signed-off-by: Fan li <fanofcode.li@samsung.com>
> ---
>  fs/f2fs/node.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index d234c6e..b965a53 100644
> --- a/fs/f2fs/node.c
> +++ b/fs/f2fs/node.c
> @@ -1906,15 +1906,18 @@ static void update_free_nid_bitmap(struct
> f2fs_sb_info *sbi, nid_t nid,
>  	if (!test_bit_le(nat_ofs, nm_i->nat_block_bitmap))
>  		return;
>  
> -	if (set)
> +	if (set) {
> +		if (test_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]))
> +			return;
>  		__set_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
> -	else
> -		__clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
> -
> -	if (set)
>  		nm_i->free_nid_count[nat_ofs]++;
> -	else if (!build)
> -		nm_i->free_nid_count[nat_ofs]--;
> +	} else {
> +		if (!test_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]))
> +			return;
> +		__clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
> +		if (!build)
> +			nm_i->free_nid_count[nat_ofs]--;
> +	}
>  }
>  
>  static void scan_nat_page(struct f2fs_sb_info *sbi,
> --
> 2.7.4
> 

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

* Re: 答复: [f2fs-dev] [PATCH RESEND] f2fs: validate before set/clear free nat bitmap
       [not found]     ` <000501d35d0d$e5d313d0$b1793b70$@samsung.com>
@ 2017-11-14  6:27       ` Chao Yu
  0 siblings, 0 replies; 3+ messages in thread
From: Chao Yu @ 2017-11-14  6:27 UTC (permalink / raw)
  To: LiFan, 'Jaegeuk Kim'
  Cc: 'Chao Yu', linux-kernel, linux-f2fs-devel

On 2017/11/14 13:59, LiFan wrote:
> Sorry, it seems my company mailbox single mail would cut the long line short
> automatically.
> It's fine in my outlook mail, so I overlooked.

Maybe 'git send-email' can be one of your options to save some work in your
email client? ;)

Thanks,

> I haven't find a way to solve that yet, please hold both of my new patch.
> I will fix it as soon as possible.
> 
> 
> -----邮件原件-----
> 发件人: Jaegeuk Kim [mailto:jaegeuk@kernel.org] 
> 发送时间: 2017年11月14日 12:54
> 收件人: LiFan
> 抄送: 'Chao Yu'; 'Chao Yu'; linux-kernel@vger.kernel.org;
> linux-f2fs-devel@lists.sourceforge.net
> 主题: Re: [f2fs-dev] [PATCH RESEND] f2fs: validate before set/clear free nat
> bitmap
> 
> Sorry, I can't merge this patch due to wrong format.
> 
> On 11/11, LiFan wrote:
>> In flush_nat_entries, all dirty nats will be flushed and if their new 
>> address isn't NULL_ADDR, their bitmaps will be updated, the 
>> free_nid_count of the bitmaps will be increased regardless of whether 
>> the nats have already been occupied before. This could lead to wrong 
>> free_nid_count.
>> So this patch checks the status of the bits before actually set/clear
> them.
>>
>> Fixes: 586d1492f301 ("f2fs: skip scanning free nid bitmap of full NAT
>> blocks")
>>
>> Signed-off-by: Fan li <fanofcode.li@samsung.com>
>> ---
>>  fs/f2fs/node.c | 17 ++++++++++-------
>>  1 file changed, 10 insertions(+), 7 deletions(-)
>>
>> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index d234c6e..b965a53 
>> 100644
>> --- a/fs/f2fs/node.c
>> +++ b/fs/f2fs/node.c
>> @@ -1906,15 +1906,18 @@ static void update_free_nid_bitmap(struct 
>> f2fs_sb_info *sbi, nid_t nid,
>>  	if (!test_bit_le(nat_ofs, nm_i->nat_block_bitmap))
>>  		return;
>>  
>> -	if (set)
>> +	if (set) {
>> +		if (test_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]))
>> +			return;
>>  		__set_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
>> -	else
>> -		__clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
>> -
>> -	if (set)
>>  		nm_i->free_nid_count[nat_ofs]++;
>> -	else if (!build)
>> -		nm_i->free_nid_count[nat_ofs]--;
>> +	} else {
>> +		if (!test_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]))
>> +			return;
>> +		__clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
>> +		if (!build)
>> +			nm_i->free_nid_count[nat_ofs]--;
>> +	}
>>  }
>>  
>>  static void scan_nat_page(struct f2fs_sb_info *sbi,
>> --
>> 2.7.4
>>
> 
> 
> 
> 
> 

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

end of thread, other threads:[~2017-11-14  6:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20171111082604epcas5p472a0e6a07db371cb050eb6a13d8f0676@epcas5p4.samsung.com>
2017-11-11  8:25 ` [f2fs-dev] [PATCH RESEND] f2fs: validate before set/clear free nat bitmap LiFan
2017-11-14  4:54   ` Jaegeuk Kim
     [not found]     ` <000501d35d0d$e5d313d0$b1793b70$@samsung.com>
2017-11-14  6:27       ` 答复: " Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).