Skip to contentSkip to conversation

erofs: avoid using generic_block_bmap

PATCH Superseded Huang Jianan 3 participants 5 messages Dec 9, 2020 EROFS file system

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 erofs: avoid using generic_block_bmap

iblock indicates the number of i_blkbits-sized blocks rather than sectors.

In addition, considering buffer_head limits mapped size to 32-bits, should avoid using generic_block_bmap.

Fixes 9da681e017a3 ("staging: erofs: support bmap")
---
 fs/erofs/data.c | 30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)
fs/erofs/data.c +10 -20
index 347be146884c..d6ea0a216b57 100644
@@ -312,36 +312,26 @@ static void erofs_raw_access_readahead(struct readahead_control *rac)
 		submit_bio(bio);
 }
 
-static int erofs_get_block(struct inode *inode, sector_t iblock,
-			   struct buffer_head *bh, int create)
-{
-	struct erofs_map_blocks map = {
-		.m_la = iblock << 9,
-	};
-	int err;
-
-	err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
-	if (err)
-		return err;
-
-	if (map.m_flags & EROFS_MAP_MAPPED)
-		bh->b_blocknr = erofs_blknr(map.m_pa);
-
-	return err;
-}
-
 static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
 {
 	struct inode *inode = mapping->host;
+	struct erofs_map_blocks map = {
+		.m_la = blknr_to_addr(block),
+	};
+	sector_t blknr = 0;
 
 	if (EROFS_I(inode)->datalayout == EROFS_INODE_FLAT_INLINE) {
 		erofs_blk_t blks = i_size_read(inode) >> LOG_BLOCK_SIZE;
 
 		if (block >> LOG_SECTORS_PER_BLOCK >= blks)
-			return 0;
+			goto out;
 	}
 
-	return generic_block_bmap(mapping, block, erofs_get_block);
+	if (!erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW))
+		blknr = erofs_blknr(map.m_pa);
+
+out:
+	return blknr;
 }
 
 /* for uncompressed (aligned) files and raw access for other files */
Signature · 1 line
2.25.1
#1 lore raw
Quoted 10 lines · Huang Jianan

iblock indicates the number of i_blkbits-sized blocks rather than sectors.

In addition, considering buffer_head limits mapped size to 32-bits, should avoid using generic_block_bmap.

Fixes 9da681e017a3 ("staging: erofs: support bmap")

---

Looks good to me in general, yet see my v3 reply as below:
https://lore.kernel.org/r/[email protected]/

Thanks,
Gao Xiang

Quoted 57 lines
 fs/erofs/data.c | 30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)
fs/erofs/data.c +10 -20
index 347be146884c..d6ea0a216b57 100644
@@ -312,36 +312,26 @@ static void erofs_raw_access_readahead(struct readahead_control *rac)
 		submit_bio(bio);
 }
 
-static int erofs_get_block(struct inode *inode, sector_t iblock,
-			   struct buffer_head *bh, int create)
-{
-	struct erofs_map_blocks map = {
-		.m_la = iblock << 9,
-	};
-	int err;
-
-	err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
-	if (err)
-		return err;
-
-	if (map.m_flags & EROFS_MAP_MAPPED)
-		bh->b_blocknr = erofs_blknr(map.m_pa);
-
-	return err;
-}
-
 static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
 {
 	struct inode *inode = mapping->host;
+	struct erofs_map_blocks map = {
+		.m_la = blknr_to_addr(block),
+	};
+	sector_t blknr = 0;
 
 	if (EROFS_I(inode)->datalayout == EROFS_INODE_FLAT_INLINE) {
 		erofs_blk_t blks = i_size_read(inode) >> LOG_BLOCK_SIZE;
 
 		if (block >> LOG_SECTORS_PER_BLOCK >= blks)
-			return 0;
+			goto out;
 	}
 
-	return generic_block_bmap(mapping, block, erofs_get_block);
+	if (!erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW))
+		blknr = erofs_blknr(map.m_pa);
+
+out:
+	return blknr;
 }
 
 /* for uncompressed (aligned) files and raw access for other files */
Signature · 1 line
2.25.1
Reviewed-by on v4 1/1
#2 lore raw
In reply to Huang Jianan
Quoted 36 lines · Huang Jianan

iblock indicates the number of i_blkbits-sized blocks rather than sectors.

In addition, considering buffer_head limits mapped size to 32-bits, should avoid using generic_block_bmap.

Fixes 9da681e017a3 ("staging: erofs: support bmap")
---
  fs/erofs/data.c | 30 ++++++++++--------------------
  1 file changed, 10 insertions(+), 20 deletions(-)
fs/erofs/data.c +0 -15
index 347be146884c..d6ea0a216b57 100644
@@ -312,36 +312,26 @@ static void erofs_raw_access_readahead(struct readahead_control *rac)
  		submit_bio(bio);
  }
 
-static int erofs_get_block(struct inode *inode, sector_t iblock,
-			   struct buffer_head *bh, int create)
-{
-	struct erofs_map_blocks map = {
-		.m_la = iblock << 9,
-	};
-	int err;
-
-	err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
-	if (err)
-		return err;
-
-	if (map.m_flags & EROFS_MAP_MAPPED)
-		bh->b_blocknr = erofs_blknr(map.m_pa);
-

fs/erofs/data.c static void erofs_raw_access_readahead(struct readahead_control *rac) · line 321

Quoted 10 lines
fs/erofs/data.c +4 -3
-	return err;
-}
-
  static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
  {
  	struct inode *inode = mapping->host;
+	struct erofs_map_blocks map = {
+		.m_la = blknr_to_addr(block),
+	};
+	sector_t blknr = 0;

It could be removed?

fs/erofs/data.c static void erofs_raw_access_readahead(struct readahead_control *rac) · line 341

Quoted 6 lines
fs/erofs/data.c +0 -1
  	if (EROFS_I(inode)->datalayout == EROFS_INODE_FLAT_INLINE) {
  		erofs_blk_t blks = i_size_read(inode) >> LOG_BLOCK_SIZE;
 
  		if (block >> LOG_SECTORS_PER_BLOCK >= blks)
-			return 0;

return 0;

fs/erofs/data.c static void erofs_raw_access_readahead(struct readahead_control *rac) · line 331

Quoted 6 lines
fs/erofs/data.c +3 -1
+			goto out;
  	}
 
-	return generic_block_bmap(mapping, block, erofs_get_block);
+	if (!erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW))
+		blknr = erofs_blknr(map.m_pa);

return erofs_blknr(map.m_pa);

fs/erofs/data.c static void erofs_raw_access_readahead(struct readahead_control *rac) · line 334

Quoted 3 lines
fs/erofs/data.c +3 -0
+
+out:
+	return blknr;

return 0;

Anyway, LGTM.

Thanks,

Quoted 4 lines
fs/erofs/data.c +0 -0
  }
 
  /* for uncompressed (aligned) files and raw access for other files */
 
#3 lore raw

Hi Jianan,

Quoted 10 lines · Chao Yu
Quoted 9 lines · Huang Jianan

iblock indicates the number of i_blkbits-sized blocks rather than sectors.

In addition, considering buffer_head limits mapped size to 32-bits, should avoid using generic_block_bmap.

Fixes 9da681e017a3 ("staging: erofs: support bmap")

Could you send out an updated version? I might get a point to freeze dev branch since it needs some time on linux-next....

Thanks,
Gao Xiang

Quoted 70 lines
Quoted 26 lines
---
  fs/erofs/data.c | 30 ++++++++++--------------------
  1 file changed, 10 insertions(+), 20 deletions(-)
fs/erofs/data.c +0 -15
index 347be146884c..d6ea0a216b57 100644
@@ -312,36 +312,26 @@ static void erofs_raw_access_readahead(struct readahead_control *rac)
  		submit_bio(bio);
  }
-static int erofs_get_block(struct inode *inode, sector_t iblock,
-			   struct buffer_head *bh, int create)
-{
-	struct erofs_map_blocks map = {
-		.m_la = iblock << 9,
-	};
-	int err;
-
-	err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
-	if (err)
-		return err;
-
-	if (map.m_flags & EROFS_MAP_MAPPED)
-		bh->b_blocknr = erofs_blknr(map.m_pa);
-

fs/erofs/data.c static void erofs_raw_access_readahead(struct readahead_control *rac) · line 320

Quoted 10 lines
fs/erofs/data.c +4 -3
-	return err;
-}
-
  static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
  {
  	struct inode *inode = mapping->host;
+	struct erofs_map_blocks map = {
+		.m_la = blknr_to_addr(block),
+	};
+	sector_t blknr = 0;

It could be removed?

fs/erofs/data.c static void erofs_raw_access_readahead(struct readahead_control *rac) · line 341

Quoted 4 lines
fs/erofs/data.c +0 -1
  	if (EROFS_I(inode)->datalayout == EROFS_INODE_FLAT_INLINE) {
  		erofs_blk_t blks = i_size_read(inode) >> LOG_BLOCK_SIZE;
  		if (block >> LOG_SECTORS_PER_BLOCK >= blks)
-			return 0;

return 0;

fs/erofs/data.c static void erofs_raw_access_readahead(struct readahead_control *rac) · line 331

Quoted 5 lines
fs/erofs/data.c +3 -1
+			goto out;
  	}
-	return generic_block_bmap(mapping, block, erofs_get_block);
+	if (!erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW))
+		blknr = erofs_blknr(map.m_pa);

return erofs_blknr(map.m_pa);

fs/erofs/data.c static void erofs_raw_access_readahead(struct readahead_control *rac) · line 334

Quoted 3 lines
fs/erofs/data.c +3 -0
+
+out:
+	return blknr;

return 0;

Anyway, LGTM.

Thanks,

Quoted 3 lines
fs/erofs/data.c +0 -0
  }
  /* for uncompressed (aligned) files and raw access for other files */
 
#4 lore raw

Thanks for review, i will update it soon.

Quoted 84 lines · Gao Xiang

Hi Jianan,

Quoted 10 lines · Chao Yu
Quoted 9 lines · Huang Jianan

iblock indicates the number of i_blkbits-sized blocks rather than sectors.

In addition, considering buffer_head limits mapped size to 32-bits, should avoid using generic_block_bmap.

Fixes 9da681e017a3 ("staging: erofs: support bmap")

Could you send out an updated version? I might get a point to freeze dev branch since it needs some time on linux-next....

Thanks,
Gao Xiang

Quoted 65 lines
Quoted 26 lines
---
   fs/erofs/data.c | 30 ++++++++++--------------------
   1 file changed, 10 insertions(+), 20 deletions(-)
fs/erofs/data.c +0 -15
index 347be146884c..d6ea0a216b57 100644
@@ -312,36 +312,26 @@ static void erofs_raw_access_readahead(struct readahead_control *rac)
   		submit_bio(bio);
   }
-static int erofs_get_block(struct inode *inode, sector_t iblock,
-			   struct buffer_head *bh, int create)
-{
-	struct erofs_map_blocks map = {
-		.m_la = iblock << 9,
-	};
-	int err;
-
-	err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
-	if (err)
-		return err;
-
-	if (map.m_flags & EROFS_MAP_MAPPED)
-		bh->b_blocknr = erofs_blknr(map.m_pa);
-

fs/erofs/data.c static void erofs_raw_access_readahead(struct readahead_control *rac) · line 320

Quoted 10 lines
fs/erofs/data.c +4 -3
-	return err;
-}
-
   static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
   {
   	struct inode *inode = mapping->host;
+	struct erofs_map_blocks map = {
+		.m_la = blknr_to_addr(block),
+	};
+	sector_t blknr = 0;

It could be removed?

fs/erofs/data.c static void erofs_raw_access_readahead(struct readahead_control *rac) · line 341

Quoted 4 lines
fs/erofs/data.c +0 -1
   	if (EROFS_I(inode)->datalayout == EROFS_INODE_FLAT_INLINE) {
   		erofs_blk_t blks = i_size_read(inode) >> LOG_BLOCK_SIZE;
   		if (block >> LOG_SECTORS_PER_BLOCK >= blks)
-			return 0;

return 0;

fs/erofs/data.c static void erofs_raw_access_readahead(struct readahead_control *rac) · line 331

Quoted 5 lines
fs/erofs/data.c +3 -1
+			goto out;
   	}
-	return generic_block_bmap(mapping, block, erofs_get_block);
+	if (!erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW))
+		blknr = erofs_blknr(map.m_pa);

return erofs_blknr(map.m_pa);

fs/erofs/data.c static void erofs_raw_access_readahead(struct readahead_control *rac) · line 334

Quoted 3 lines
fs/erofs/data.c +3 -0
+
+out:
+	return blknr;

return 0;

Anyway, LGTM.

Thanks,

Quoted 3 lines
fs/erofs/data.c +0 -0
   }
   /* for uncompressed (aligned) files and raw access for other files */