Skip to content

Commit

Permalink
f2fs: introduce max_file_blocks in sbi
Browse files Browse the repository at this point in the history
Introduce max_file_blocks in sbi to store max block index of file in f2fs,
it could be used to avoid unneeded calculation of max block index in
runtime.

Signed-off-by: Chao Yu <[email protected]>
[Jaegeuk Kim: fix overflow of sbi->max_file_blocks]
Signed-off-by: Jaegeuk Kim <[email protected]>
  • Loading branch information
chaseyu authored and Jaegeuk Kim committed Jan 4, 2016
1 parent 3a9e643 commit e0afc4d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fs/f2fs/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ static int get_data_block_bmap(struct inode *inode, sector_t iblock,
struct buffer_head *bh_result, int create)
{
/* Block number less than F2FS MAX BLOCKS */
if (unlikely(iblock >= max_file_size(0)))
if (unlikely(iblock >= F2FS_I_SB(inode)->max_file_blocks))
return -EFBIG;

return __get_data_block(inode, iblock, bh_result, create,
Expand Down
2 changes: 1 addition & 1 deletion fs/f2fs/f2fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ struct f2fs_sb_info {
unsigned int total_node_count; /* total node block count */
unsigned int total_valid_node_count; /* valid node block count */
unsigned int total_valid_inode_count; /* valid inode count */
loff_t max_file_blocks; /* max block index of file */
int active_logs; /* # of active logs */
int dir_level; /* directory level */

Expand Down Expand Up @@ -1727,7 +1728,6 @@ static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
* super.c
*/
int f2fs_commit_super(struct f2fs_sb_info *, bool);
loff_t max_file_size(unsigned bits);
int f2fs_sync_fs(struct super_block *, int);
extern __printf(3, 4)
void f2fs_msg(struct super_block *, const char *, const char *, ...);
Expand Down
7 changes: 4 additions & 3 deletions fs/f2fs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ static const struct export_operations f2fs_export_ops = {
.get_parent = f2fs_get_parent,
};

loff_t max_file_size(unsigned bits)
static loff_t max_file_blocks(void)
{
loff_t result = (DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS);
loff_t leaf_count = ADDRS_PER_BLOCK;
Expand All @@ -923,7 +923,6 @@ loff_t max_file_size(unsigned bits)
leaf_count *= NIDS_PER_BLOCK;
result += leaf_count;

result <<= bits;
return result;
}

Expand Down Expand Up @@ -1278,7 +1277,9 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
if (err)
goto free_options;

sb->s_maxbytes = max_file_size(le32_to_cpu(raw_super->log_blocksize));
sbi->max_file_blocks = max_file_blocks();
sb->s_maxbytes = sbi->max_file_blocks <<
le32_to_cpu(raw_super->log_blocksize);
sb->s_max_links = F2FS_LINK_MAX;
get_random_bytes(&sbi->s_next_generation, sizeof(u32));

Expand Down

0 comments on commit e0afc4d

Please sign in to comment.