Skip to contentSkip to conversation

erofs: handle 48-bit blocks_hi for compressed inodes

PATCH Superseded Zhan Xusheng 2 participants 4 messages Jun 22 EROFS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs: handle 48-bit blocks_hi for compressed inodes

Combine i_nb.blocks_hi with i_u.blocks_lo when computing inode->i_blocks for compressed inodes, mirroring the startblk_hi handling for unencoded inodes a few lines above. Also evaluate the shift in u64 to avoid truncation.

Fixes 2e1473d5195f ("erofs: implement 48-bit block addressing for unencoded inodes")
---
 fs/erofs/inode.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/erofs/inode.c +3 -2
index a188c570087a..cf2f00e13cae 100644
@@ -191,8 +191,9 @@ static int erofs_read_inode(struct inode *inode)
 		err = -EFSCORRUPTED;
 		goto err_out;
 	} else {
-		inode->i_blocks = le32_to_cpu(copied.i_u.blocks_lo) <<
-				(sb->s_blocksize_bits - 9);
+		inode->i_blocks = ((u64)le16_to_cpu(copied.i_nb.blocks_hi) << 32 |
+				   le32_to_cpu(copied.i_u.blocks_lo)) <<
+				  (sb->s_blocksize_bits - 9);
 	}
 
 	if (vi->datalayout == EROFS_INODE_CHUNK_BASED) {
Signature · 1 line
2.43.0
#1 lore raw

Hi Xusheng,

Quoted 6 lines · Zhan Xusheng

Combine i_nb.blocks_hi with i_u.blocks_lo when computing inode->i_blocks for compressed inodes, mirroring the startblk_hi handling for unencoded inodes a few lines above. Also evaluate the shift in u64 to avoid truncation.

Fixes 2e1473d5195f ("erofs: implement 48-bit block addressing for unencoded inodes")

It's not the right fix, it should be efb2aef569b3 since the pcluster layout only allows 32-bit addresssing for now.

Quoted 10 lines
---
  fs/erofs/inode.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
fs/erofs/inode.c +0 -0
index a188c570087a..cf2f00e13cae 100644

fs/erofs/inode.c static int erofs_read_inode(struct inode *inode) · line 196

Quoted 8 lines
fs/erofs/inode.c +3 -2
@@ -191,8 +191,9 @@ static int erofs_read_inode(struct inode *inode)
  		err = -EFSCORRUPTED;
  		goto err_out;
  	} else {
-		inode->i_blocks = le32_to_cpu(copied.i_u.blocks_lo) <<
-				(sb->s_blocksize_bits - 9);
+		inode->i_blocks = ((u64)le16_to_cpu(copied.i_nb.blocks_hi) << 32 |
+				   le32_to_cpu(copied.i_u.blocks_lo)) <<
+				  (sb->s_blocksize_bits - 9);

I hope it could be:

		inode->i_blocks = (le32_to_cpu(copied.i_u.blocks_lo) |
			((u64)le16_to_cpu(copied.i_nb.blocks_hi) << 32)) <<
				(sb->s_blocksize_bits - 9);

to explicitly use "()" and avoid overly long lines.

Thanks,
Gao Xiang

Quoted 3 lines
fs/erofs/inode.c +0 -0
  	}
 
  	if (vi->datalayout == EROFS_INODE_CHUNK_BASED) {
#2 lore raw

PATCH v2 1/1 erofs: handle 48-bit blocks_hi for compressed inodes

Combine i_nb.blocks_hi with i_u.blocks_lo when computing inode->i_blocks for compressed inodes, mirroring the startblk_hi handling for unencoded inodes a few lines above. Also evaluate the shift in u64 to avoid truncation.

Fixes efb2aef569b3 ("erofs: add encoded extent on-disk definition")

---
v2:
- Fix the Fixes: tag to efb2aef569b3 ("erofs: add encoded extent on-disk definition"), the commit that introduced blocks_hi for compressed inodes (Gao Xiang)
- Reorder to "blocks_lo | (blocks_hi << 32)" with explicit parentheses and shorter lines (Gao Xiang)

 fs/erofs/inode.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/erofs/inode.c +3 -2
index a188c570087a..dc0e3d6bb2b1 100644
@@ -191,8 +191,9 @@ static int erofs_read_inode(struct inode *inode)
 		err = -EFSCORRUPTED;
 		goto err_out;
 	} else {
-		inode->i_blocks = le32_to_cpu(copied.i_u.blocks_lo) <<
-				(sb->s_blocksize_bits - 9);
+		inode->i_blocks = (le32_to_cpu(copied.i_u.blocks_lo) |
+				   ((u64)le16_to_cpu(copied.i_nb.blocks_hi) << 32)) <<
+				  (sb->s_blocksize_bits - 9);
 	}
 
 	if (vi->datalayout == EROFS_INODE_CHUNK_BASED) {
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#3 lore raw
Quoted 23 lines · Zhan Xusheng

Combine i_nb.blocks_hi with i_u.blocks_lo when computing inode->i_blocks for compressed inodes, mirroring the startblk_hi handling for unencoded inodes a few lines above. Also evaluate the shift in u64 to avoid truncation.

Fixes efb2aef569b3 ("erofs: add encoded extent on-disk definition")

---
v2:
- Fix the Fixes: tag to efb2aef569b3 ("erofs: add encoded extent on-disk definition"), the commit that introduced blocks_hi for compressed inodes (Gao Xiang)
- Reorder to "blocks_lo | (blocks_hi << 32)" with explicit parentheses and shorter lines (Gao Xiang)

  fs/erofs/inode.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
fs/erofs/inode.c +0 -0
index a188c570087a..dc0e3d6bb2b1 100644

fs/erofs/inode.c static int erofs_read_inode(struct inode *inode) · line 195

Quoted 7 lines
fs/erofs/inode.c +2 -2
@@ -191,8 +191,9 @@ static int erofs_read_inode(struct inode *inode)
  		err = -EFSCORRUPTED;
  		goto err_out;
  	} else {
-		inode->i_blocks = le32_to_cpu(copied.i_u.blocks_lo) <<
-				(sb->s_blocksize_bits - 9);
+		inode->i_blocks = (le32_to_cpu(copied.i_u.blocks_lo) |
+				   ((u64)le16_to_cpu(copied.i_nb.blocks_hi) << 32)) <<

I will change this line to

			((u64)le16_to_cpu(copied.i_nb.blocks_hi) << 32)) <<

to avoid overly long lines (since such alignment is not strictly necessary but overly long lines should be avoided), otherwise it looks good to me,

Thanks,
Gao Xiang