Skip to contentSkip to conversation

f2fs: using generic_file_llseek() instead of generic_file_llseek_size()

RFC PATCH In review Chengguang Xu 3 participants 4 messages Jan 10, 2021 – Jan 11, 2021 F2FS file system

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 f2fs: using generic_file_llseek() instead of generic_file_llseek_size()

generic_file_llseek_size() is used for filesystems that have a custom maximum size and a custom EOF position. so it's better to replace it using generic_file_llseek().

---
 fs/f2fs/file.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
fs/f2fs/file.c +1 -5
index f585545..2ca22ea 100644
@@ -480,15 +480,11 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence)
 
 static loff_t f2fs_llseek(struct file *file, loff_t offset, int whence)
 {
-	struct inode *inode = file->f_mapping->host;
-	loff_t maxbytes = inode->i_sb->s_maxbytes;
-
 	switch (whence) {
 	case SEEK_SET:
 	case SEEK_CUR:
 	case SEEK_END:
-		return generic_file_llseek_size(file, offset, whence,
-						maxbytes, i_size_read(inode));
+		return generic_file_llseek(file, offset, whence);
 	case SEEK_DATA:
 	case SEEK_HOLE:
 		if (offset < 0)
Signature · 8 lines
1.8.3.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw
Quoted 3 lines · Chengguang Xu

generic_file_llseek_size() is used for filesystems that have a custom maximum size and a custom EOF position. so it's better to replace it using generic_file_llseek().

F2FS inode may have different max size, e.g. compressed file have less blkaddr entries in all its direct-node blocks, result in being with less max filesize.

I guess we should consider that when checking boundary with s_maxbytes, so how about using below patch instead:

Subject: [PATCH] f2fs: fix to use per-inode maxbytes

---
 fs/f2fs/data.c  |  2 +-
 fs/f2fs/f2fs.h  |  2 +-
 fs/f2fs/file.c  |  9 ++++++---
 fs/f2fs/super.c | 12 ++++++++----
 4 files changed, 16 insertions(+), 9 deletions(-)
fs/f2fs/data.c +1 -1
index 3cc81e73b372..a534121729f2 100644
@@ -3791,7 +3791,7 @@ static sector_t f2fs_bmap(struct address_space *mapping, sector_t block)
 		filemap_write_and_wait(mapping);
 
 	/* Block number less than F2FS MAX BLOCKS */
-	if (unlikely(block >= F2FS_I_SB(inode)->max_file_blocks))
+	if (unlikely(block >= max_file_blocks(inode)))
 		goto out;
 
 	if (f2fs_compressed_file(inode)) {
fs/f2fs/f2fs.h +1 -1
index 63a8b0adeee6..9eea6f770a51 100644
@@ -1493,7 +1493,6 @@ struct f2fs_sb_info {
 	unsigned int total_sections;		/* total section count */
 	unsigned int total_node_count;		/* total node block count */
 	unsigned int total_valid_node_count;	/* valid node block count */
-	loff_t max_file_blocks;			/* max block index of file */
 	int dir_level;				/* directory level */
 	int readdir_ra;				/* readahead inode in readdir */
 	u64 max_io_bytes;			/* max io bytes to merge IOs */
@@ -3291,6 +3290,7 @@ int f2fs_inode_dirtied(struct inode *inode, bool sync);
 void f2fs_inode_synced(struct inode *inode);
 int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly);
 int f2fs_quota_sync(struct super_block *sb, int type);
+loff_t max_file_blocks(struct inode *inode);
 void f2fs_quota_off_umount(struct super_block *sb);
 int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover);
 int f2fs_sync_fs(struct super_block *sb, int sync);
fs/f2fs/file.c +6 -3
index 5e7a567b555b..567eba90bd93 100644
@@ -539,6 +539,9 @@ static loff_t f2fs_llseek(struct file *file, loff_t offset, int whence)
 	struct inode *inode = file->f_mapping->host;
 	loff_t maxbytes = inode->i_sb->s_maxbytes;
 
+	if (f2fs_compressed_file(inode))
+		maxbytes = max_file_blocks(inode) << F2FS_BLKSIZE_BITS;
+
 	switch (whence) {
 	case SEEK_SET:
 	case SEEK_CUR:
@@ -736,7 +739,7 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
 
 	free_from = (pgoff_t)F2FS_BLK_ALIGN(from);
 
-	if (free_from >= sbi->max_file_blocks)
+	if (free_from >= max_file_blocks(inode))
 		goto free_partial;
 
 	if (lock)
@@ -2890,7 +2893,7 @@ static int f2fs_ioc_defragment(struct file *filp, unsigned long arg)
 		return -EINVAL;
 
 	if (unlikely((range.start + range.len) >> PAGE_SHIFT >
-					sbi->max_file_blocks))
+					max_file_blocks(inode)))
 		return -EINVAL;
 
 	err = mnt_want_write_file(filp);
@@ -3458,7 +3461,7 @@ int f2fs_precache_extents(struct inode *inode)
 	map.m_next_extent = &m_next_extent;
 	map.m_seg_type = NO_CHECK_TYPE;
 	map.m_may_create = false;
-	end = F2FS_I_SB(inode)->max_file_blocks;
+	end = max_file_blocks(inode);
 
 	while (map.m_lblk < end) {
 		map.m_len = end - map.m_lblk;
fs/f2fs/super.c +8 -4
index f871aa718eaa..113c88af665e 100644
@@ -2786,10 +2786,10 @@ static const struct export_operations f2fs_export_ops = {
 	.get_parent = f2fs_get_parent,
 };
 
-static loff_t max_file_blocks(void)
+loff_t max_file_blocks(struct inode *inode)
 {
 	loff_t result = 0;
-	loff_t leaf_count = DEF_ADDRS_PER_BLOCK;
+	loff_t leaf_count;
 
 	/*
 	 * note: previously, result is equal to (DEF_ADDRS_PER_INODE -
@@ -2798,6 +2798,11 @@ static loff_t max_file_blocks(void)
 	 * result as zero.
 	 */
 
+	if (inode && f2fs_compressed_file(inode))
+		leaf_count = ADDRS_PER_BLOCK(inode);
+	else
+		leaf_count = DEF_ADDRS_PER_BLOCK;
+
 	/* two direct node blocks */
 	result += (leaf_count * 2);
 
@@ -3685,8 +3690,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
 	if (err)
 		goto free_options;
 
-	sbi->max_file_blocks = max_file_blocks();
-	sb->s_maxbytes = sbi->max_file_blocks <<
+	sb->s_maxbytes = max_file_blocks(NULL) <<
 				le32_to_cpu(raw_super->log_blocksize);
 	sb->s_max_links = F2FS_LINK_MAX;
 
Signature · 1 line
2.29.2
Quoted 18 lines
---
  fs/f2fs/file.c | 6 +-----
  1 file changed, 1 insertion(+), 5 deletions(-)
fs/f2fs/file.c +0 -3
index f585545..2ca22ea 100644
@@ -480,15 +480,11 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence)
 
  static loff_t f2fs_llseek(struct file *file, loff_t offset, int whence)
  {
-	struct inode *inode = file->f_mapping->host;
-	loff_t maxbytes = inode->i_sb->s_maxbytes;
-

fs/f2fs/file.c static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence) · line 490

Quoted 10 lines
fs/f2fs/file.c +1 -2
  	switch (whence) {
  	case SEEK_SET:
  	case SEEK_CUR:
  	case SEEK_END:
-		return generic_file_llseek_size(file, offset, whence,
-						maxbytes, i_size_read(inode));
+		return generic_file_llseek(file, offset, whence);
  	case SEEK_DATA:
  	case SEEK_HOLE:
  		if (offset < 0)

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#2 lore raw

---- 在 星期一, 2021-01-11 15:35:07 Chao Yu <[email protected]> 撰写 ----

Quoted 5 lines · Chengguang Xu
Quoted 3 lines

generic_file_llseek_size() is used for filesystems that have a custom maximum size and a custom EOF position. so it's better to replace it using generic_file_llseek().

Quoted 8 lines

F2FS inode may have different max size, e.g. compressed file have less blkaddr entries in all its direct-node blocks, result in being with less max filesize.

I guess we should consider that when checking boundary with s_maxbytes, so how about using below patch instead:

Subject: [PATCH] f2fs: fix to use per-inode maxbytes

Hi Chao,

Thanks for your review and suggestion. It looks a proper fix. Would you mind me sending revised patch follow your suggestion?

Thanks

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

maintainer
#3 lore raw
Quoted 13 lines · Chengguang Xu

---- 在 星期一, 2021-01-11 15:35:07 Chao Yu <[email protected]> 撰写 ----

Quoted 12 lines · Chengguang Xu
Quoted 3 lines

generic_file_llseek_size() is used for filesystems that have a custom maximum size and a custom EOF position. so it's better to replace it using generic_file_llseek().

F2FS inode may have different max size, e.g. compressed file have less blkaddr entries in all its direct-node blocks, result in being with less max filesize.

I guess we should consider that when checking boundary with s_maxbytes, so how about using below patch instead:

Quoted 6 lines
Quoted 1 line

Subject: [PATCH] f2fs: fix to use per-inode maxbytes

Hi Chao,

Thanks for your review and suggestion. It looks a proper fix. Would you mind me sending revised patch follow your suggestion?

Hi Chengguang,

It's fine to me.

Thanks,

Quoted 3 lines

Thanks

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel