Skip to contentSkip to conversation

f2fs: limit b_size of mapped bh in f2fs_map_bh

PATCH Superseded Chao Yu 2 participants 3 messages Mar 23, 2015 – Mar 24, 2015 F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/4 f2fs: limit b_size of mapped bh in f2fs_map_bh

Map bh over max size which caller defined is not needed, limit it in f2fs_map_bh.

---
 fs/f2fs/data.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/f2fs/data.c +4 -3
index f0a18a0..a99bc7f 100644
@@ -255,15 +255,16 @@ static void f2fs_map_bh(struct super_block *sb, pgoff_t pgofs,
 			struct extent_info *ei, struct buffer_head *bh_result)
 {
 	unsigned int blkbits = sb->s_blocksize_bits;
+	unsigned int maxblocks = bh_result->b_size >> blkbits;
 	size_t count;
 
 	clear_buffer_new(bh_result);
 	map_bh(bh_result, sb, ei->blk + pgofs - ei->fofs);
 	count = ei->fofs + ei->len - pgofs;
-	if (count < (UINT_MAX >> blkbits))
-		bh_result->b_size = (count << blkbits);
+	if (count > maxblocks)
+		bh_result->b_size = maxblocks << blkbits;
 	else
-		bh_result->b_size = UINT_MAX;
+		bh_result->b_size = count << blkbits;
 }
 
 static bool lookup_extent_info(struct inode *inode, pgoff_t pgofs,
Signature · 1 line
2.3.3
maintainer
#1 lore raw

Hi Chao,

Quoted 19 lines · Chao Yu

Map bh over max size which caller defined is not needed, limit it in f2fs_map_bh.

---
 fs/f2fs/data.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/f2fs/data.c +1 -0
index f0a18a0..a99bc7f 100644
@@ -255,15 +255,16 @@ static void f2fs_map_bh(struct super_block *sb, pgoff_t pgofs,
 			struct extent_info *ei, struct buffer_head *bh_result)
 {
 	unsigned int blkbits = sb->s_blocksize_bits;
+	unsigned int maxblocks = bh_result->b_size >> blkbits;
 	size_t count;
 

fs/f2fs/data.c static void f2fs_map_bh(struct super_block *sb, pgoff_t pgofs, · line 267

Quoted 10 lines
fs/f2fs/data.c +3 -3
 	clear_buffer_new(bh_result);
 	map_bh(bh_result, sb, ei->blk + pgofs - ei->fofs);
 	count = ei->fofs + ei->len - pgofs;
-	if (count < (UINT_MAX >> blkbits))
-		bh_result->b_size = (count << blkbits);
+	if (count > maxblocks)
+		bh_result->b_size = maxblocks << blkbits;
 	else
-		bh_result->b_size = UINT_MAX;
+		bh_result->b_size = count << blkbits;

How about using min()?

Thanks,

Quoted 5 lines
fs/f2fs/data.c +0 -0
 }
 
 static bool lookup_extent_info(struct inode *inode, pgoff_t pgofs,
Signature · 1 line
2.3.3
author
#2 lore raw

Hi Jaegeuk,

Quoted 29 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Tuesday, March 24, 2015 12:42 PM
To: Chao Yu
Cc: Changman Lee; [email protected]; [email protected]
Subject: Re: [PATCH 1/4] f2fs: limit b_size of mapped bh in f2fs_map_bh

Hi Chao,

Quoted 19 lines · Chao Yu

Map bh over max size which caller defined is not needed, limit it in f2fs_map_bh.

---
 fs/f2fs/data.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/f2fs/data.c +1 -0
index f0a18a0..a99bc7f 100644
@@ -255,15 +255,16 @@ static void f2fs_map_bh(struct super_block *sb, pgoff_t pgofs,
 			struct extent_info *ei, struct buffer_head *bh_result)
 {
 	unsigned int blkbits = sb->s_blocksize_bits;
+	unsigned int maxblocks = bh_result->b_size >> blkbits;
 	size_t count;
 
Quoted 12 lines

fs/f2fs/data.c static void f2fs_map_bh(struct super_block *sb, pgoff_t pgofs, · line 267

Quoted 10 lines
fs/f2fs/data.c +3 -3
 	clear_buffer_new(bh_result);
 	map_bh(bh_result, sb, ei->blk + pgofs - ei->fofs);
 	count = ei->fofs + ei->len - pgofs;
-	if (count < (UINT_MAX >> blkbits))
-		bh_result->b_size = (count << blkbits);
+	if (count > maxblocks)
+		bh_result->b_size = maxblocks << blkbits;
 	else
-		bh_result->b_size = UINT_MAX;
+		bh_result->b_size = count << blkbits;

How about using min()?

Better, I will do it. :)

Thanks,

Quoted 8 lines

Thanks,

Quoted 5 lines
fs/f2fs/data.c +0 -1
 }
 
 static bool lookup_extent_info(struct inode *inode, pgoff_t pgofs,
--

2.3.3