Skip to contentSkip to conversation

f2fs: validate before set/clear free nat bitmap

PATCH RESEND Superseded LiFan 3 participants 4 messages Nov 11, 2017 – Nov 14, 2017 1 message not in the archive F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20171111082604epcas5p472a0e6a07db371cb050eb6a13d8f0676@epcas5p4.samsung.com

LiFan

author
#1 lore raw

PATCH RESEND 1/1 f2fs: validate before set/clear free nat bitmap

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")

---
 fs/f2fs/node.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
fs/f2fs/node.c +0 -0
@@ -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

maintainer
#2 lore raw

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

Quoted 48 lines · LiFan

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")

---
 fs/f2fs/node.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
fs/f2fs/node.c +10 -7
@@ -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

author
#3 lore raw

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.
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:[email protected]]
发送时间: 2017年11月14日 12:54
收件人: LiFan
抄送: 'Chao Yu'; 'Chao Yu'; [email protected]; [email protected]
主题: Re: [f2fs-dev] [PATCH RESEND] f2fs: validate before set/clear free nat bitmap

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

Quoted 6 lines · LiFan

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.

Quoted 39 lines
Fixes 586d1492f301 ("f2fs: skip scanning free nid bitmap of full NAT

blocks")

---
 fs/f2fs/node.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
fs/f2fs/node.c index d234c6e..b965a53 renamed from fs/f2fs/node.c +0 -0

100644

fs/f2fs/node.c +10 -7
@@ -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]--;
+	}
 }
 
Quoted 4 lines

static void scan_nat_page(struct f2fs_sb_info *sbi,
--
2.7.4

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#4 lore raw
Quoted 3 lines · LiFan

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,

Quoted 62 lines

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:[email protected]]
发送时间: 2017年11月14日 12:54
收件人: LiFan
抄送: 'Chao Yu'; 'Chao Yu'; [email protected]; [email protected]
主题: Re: [f2fs-dev] [PATCH RESEND] f2fs: validate before set/clear free nat bitmap

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

Quoted 6 lines · LiFan

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.

Quoted 39 lines
Fixes 586d1492f301 ("f2fs: skip scanning free nid bitmap of full NAT

blocks")

---
 fs/f2fs/node.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
fs/f2fs/node.c index d234c6e..b965a53 renamed from fs/f2fs/node.c +0 -0

100644

fs/f2fs/node.c +10 -7
@@ -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]--;
+	}
 }
 
Quoted 9 lines
Quoted 4 lines

static void scan_nat_page(struct f2fs_sb_info *sbi,
--
2.7.4

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel