Skip to content
This repository was archived by the owner on Nov 21, 2022. It is now read-only.

Commit 81ca735

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: remove unneeded pointer conversion
There are redundant pointer conversion in following call stack: - at position a, inode was been converted to f2fs_file_info. - at position b, f2fs_file_info was been converted to inode again. - truncate_blocks(inode,..) - fi = F2FS_I(inode) ---a - ADDRS_PER_PAGE(node_page, fi) - addrs_per_inode(fi) - inode = &fi->vfs_inode ---b - f2fs_has_inline_xattr(inode) - fi = F2FS_I(inode) - is_inode_flag_set(fi,..) In order to avoid unneeded conversion, alter ADDRS_PER_PAGE and addrs_per_inode to acept parameter with type of inode pointer. Signed-off-by: Chao Yu <chao2.yu@samsung.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 5b8db7f commit 81ca735

File tree

8 files changed

+31
-36
lines changed

8 files changed

+31
-36
lines changed

fs/f2fs/data.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,6 @@ struct page *get_new_data_page(struct inode *inode,
497497
static int __allocate_data_block(struct dnode_of_data *dn)
498498
{
499499
struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
500-
struct f2fs_inode_info *fi = F2FS_I(dn->inode);
501500
struct f2fs_summary sum;
502501
struct node_info ni;
503502
int seg = CURSEG_WARM_DATA;
@@ -525,7 +524,7 @@ static int __allocate_data_block(struct dnode_of_data *dn)
525524
set_data_blkaddr(dn);
526525

527526
/* update i_size */
528-
fofs = start_bidx_of_node(ofs_of_node(dn->node_page), fi) +
527+
fofs = start_bidx_of_node(ofs_of_node(dn->node_page), dn->inode) +
529528
dn->ofs_in_node;
530529
if (i_size_read(dn->inode) < ((loff_t)(fofs + 1) << PAGE_CACHE_SHIFT))
531530
i_size_write(dn->inode,
@@ -592,7 +591,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
592591
goto unlock_out;
593592
}
594593

595-
end_offset = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode));
594+
end_offset = ADDRS_PER_PAGE(dn.node_page, inode);
596595

597596
next_block:
598597
blkaddr = datablock_addr(dn.node_page, dn.ofs_in_node);

fs/f2fs/extent_cache.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,6 @@ bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs,
673673

674674
void f2fs_update_extent_cache(struct dnode_of_data *dn)
675675
{
676-
struct f2fs_inode_info *fi = F2FS_I(dn->inode);
677676
pgoff_t fofs;
678677

679678
if (!f2fs_may_extent_tree(dn->inode))
@@ -682,8 +681,8 @@ void f2fs_update_extent_cache(struct dnode_of_data *dn)
682681
f2fs_bug_on(F2FS_I_SB(dn->inode), dn->data_blkaddr == NEW_ADDR);
683682

684683

685-
fofs = start_bidx_of_node(ofs_of_node(dn->node_page), fi) +
686-
dn->ofs_in_node;
684+
fofs = start_bidx_of_node(ofs_of_node(dn->node_page), dn->inode) +
685+
dn->ofs_in_node;
687686

688687
if (f2fs_update_extent_tree_range(dn->inode, fofs, dn->data_blkaddr, 1))
689688
sync_inode_page(dn);

fs/f2fs/f2fs.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,9 +1538,9 @@ static inline int f2fs_has_inline_xattr(struct inode *inode)
15381538
return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR);
15391539
}
15401540

1541-
static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi)
1541+
static inline unsigned int addrs_per_inode(struct inode *inode)
15421542
{
1543-
if (f2fs_has_inline_xattr(&fi->vfs_inode))
1543+
if (f2fs_has_inline_xattr(inode))
15441544
return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
15451545
return DEF_ADDRS_PER_INODE;
15461546
}
@@ -1694,10 +1694,10 @@ static inline void *f2fs_kvzalloc(size_t size, gfp_t flags)
16941694
(F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
16951695

16961696
/* get offset of first page in next direct node */
1697-
#define PGOFS_OF_NEXT_DNODE(pgofs, fi) \
1698-
((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \
1699-
(pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \
1700-
ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi))
1697+
#define PGOFS_OF_NEXT_DNODE(pgofs, inode) \
1698+
((pgofs < ADDRS_PER_INODE(inode)) ? ADDRS_PER_INODE(inode) : \
1699+
(pgofs - ADDRS_PER_INODE(inode) + ADDRS_PER_BLOCK) / \
1700+
ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(inode))
17011701

17021702
/*
17031703
* file.c
@@ -1916,7 +1916,7 @@ int f2fs_release_page(struct page *, gfp_t);
19161916
*/
19171917
int start_gc_thread(struct f2fs_sb_info *);
19181918
void stop_gc_thread(struct f2fs_sb_info *);
1919-
block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *);
1919+
block_t start_bidx_of_node(unsigned int, struct inode *);
19201920
int f2fs_gc(struct f2fs_sb_info *, bool);
19211921
void build_gc_manager(struct f2fs_sb_info *);
19221922

fs/f2fs/file.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,14 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence)
358358
} else if (err == -ENOENT) {
359359
/* direct node does not exists */
360360
if (whence == SEEK_DATA) {
361-
pgofs = PGOFS_OF_NEXT_DNODE(pgofs,
362-
F2FS_I(inode));
361+
pgofs = PGOFS_OF_NEXT_DNODE(pgofs, inode);
363362
continue;
364363
} else {
365364
goto found;
366365
}
367366
}
368367

369-
end_offset = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode));
368+
end_offset = ADDRS_PER_PAGE(dn.node_page, inode);
370369

371370
/* find data/hole in dnode block */
372371
for (; dn.ofs_in_node < end_offset;
@@ -480,7 +479,7 @@ int truncate_data_blocks_range(struct dnode_of_data *dn, int count)
480479
* we will invalidate all blkaddr in the whole range.
481480
*/
482481
fofs = start_bidx_of_node(ofs_of_node(dn->node_page),
483-
F2FS_I(dn->inode)) + ofs;
482+
dn->inode) + ofs;
484483
f2fs_update_extent_cache_range(dn, fofs, 0, len);
485484
dec_valid_block_count(sbi, dn->inode, nr_free);
486485
sync_inode_page(dn);
@@ -568,7 +567,7 @@ int truncate_blocks(struct inode *inode, u64 from, bool lock)
568567
goto out;
569568
}
570569

571-
count = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode));
570+
count = ADDRS_PER_PAGE(dn.node_page, inode);
572571

573572
count -= dn.ofs_in_node;
574573
f2fs_bug_on(sbi, count < 0);
@@ -768,7 +767,7 @@ int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end)
768767
return err;
769768
}
770769

771-
end_offset = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode));
770+
end_offset = ADDRS_PER_PAGE(dn.node_page, inode);
772771
count = min(end_offset - dn.ofs_in_node, pg_end - pg_start);
773772

774773
f2fs_bug_on(F2FS_I_SB(inode), count == 0 || count > end_offset);

fs/f2fs/gc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static void gc_node_segment(struct f2fs_sb_info *sbi,
486486
* as indirect or double indirect node blocks, are given, it must be a caller's
487487
* bug.
488488
*/
489-
block_t start_bidx_of_node(unsigned int node_ofs, struct f2fs_inode_info *fi)
489+
block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode)
490490
{
491491
unsigned int indirect_blks = 2 * NIDS_PER_BLOCK + 4;
492492
unsigned int bidx;
@@ -503,7 +503,7 @@ block_t start_bidx_of_node(unsigned int node_ofs, struct f2fs_inode_info *fi)
503503
int dec = (node_ofs - indirect_blks - 3) / (NIDS_PER_BLOCK + 1);
504504
bidx = node_ofs - 5 - dec;
505505
}
506-
return bidx * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi);
506+
return bidx * ADDRS_PER_BLOCK + ADDRS_PER_INODE(inode);
507507
}
508508

509509
static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
@@ -722,7 +722,7 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
722722
continue;
723723
}
724724

725-
start_bidx = start_bidx_of_node(nofs, F2FS_I(inode));
725+
start_bidx = start_bidx_of_node(nofs, inode);
726726
data_page = get_read_data_page(inode,
727727
start_bidx + ofs_in_node, READA, true);
728728
if (IS_ERR(data_page)) {
@@ -738,7 +738,7 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
738738
/* phase 3 */
739739
inode = find_gc_inode(gc_list, dni.ino);
740740
if (inode) {
741-
start_bidx = start_bidx_of_node(nofs, F2FS_I(inode))
741+
start_bidx = start_bidx_of_node(nofs, inode)
742742
+ ofs_in_node;
743743
if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
744744
move_encrypted_block(inode, start_bidx);

fs/f2fs/node.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,10 @@ void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni)
407407
* The maximum depth is four.
408408
* Offset[0] will have raw inode offset.
409409
*/
410-
static int get_node_path(struct f2fs_inode_info *fi, long block,
410+
static int get_node_path(struct inode *inode, long block,
411411
int offset[4], unsigned int noffset[4])
412412
{
413-
const long direct_index = ADDRS_PER_INODE(fi);
413+
const long direct_index = ADDRS_PER_INODE(inode);
414414
const long direct_blks = ADDRS_PER_BLOCK;
415415
const long dptrs_per_blk = NIDS_PER_BLOCK;
416416
const long indirect_blks = ADDRS_PER_BLOCK * NIDS_PER_BLOCK;
@@ -498,7 +498,7 @@ int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode)
498498
int level, i;
499499
int err = 0;
500500

501-
level = get_node_path(F2FS_I(dn->inode), index, offset, noffset);
501+
level = get_node_path(dn->inode, index, offset, noffset);
502502

503503
nids[0] = dn->inode->i_ino;
504504
npage[0] = dn->inode_page;
@@ -792,7 +792,7 @@ int truncate_inode_blocks(struct inode *inode, pgoff_t from)
792792

793793
trace_f2fs_truncate_inode_blocks_enter(inode, from);
794794

795-
level = get_node_path(F2FS_I(inode), from, offset, noffset);
795+
level = get_node_path(inode, from, offset, noffset);
796796
restart:
797797
page = get_node_page(sbi, inode->i_ino);
798798
if (IS_ERR(page)) {

fs/f2fs/recovery.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,7 @@ static int check_index_in_prev_nodes(struct f2fs_sb_info *sbi,
350350
inode = dn->inode;
351351
}
352352

353-
bidx = start_bidx_of_node(offset, F2FS_I(inode)) +
354-
le16_to_cpu(sum.ofs_in_node);
353+
bidx = start_bidx_of_node(offset, inode) + le16_to_cpu(sum.ofs_in_node);
355354

356355
/*
357356
* if inode page is locked, unlock temporarily, but its reference
@@ -386,10 +385,9 @@ static int check_index_in_prev_nodes(struct f2fs_sb_info *sbi,
386385
static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
387386
struct page *page, block_t blkaddr)
388387
{
389-
struct f2fs_inode_info *fi = F2FS_I(inode);
390-
unsigned int start, end;
391388
struct dnode_of_data dn;
392389
struct node_info ni;
390+
unsigned int start, end;
393391
int err = 0, recovered = 0;
394392

395393
/* step 1: recover xattr */
@@ -409,8 +407,8 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
409407
goto out;
410408

411409
/* step 3: recover data indices */
412-
start = start_bidx_of_node(ofs_of_node(page), fi);
413-
end = start + ADDRS_PER_PAGE(page, fi);
410+
start = start_bidx_of_node(ofs_of_node(page), inode);
411+
end = start + ADDRS_PER_PAGE(page, inode);
414412

415413
set_new_dnode(&dn, inode, NULL, NULL, 0);
416414

include/linux/f2fs_fs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ struct f2fs_extent {
170170
#define F2FS_INLINE_XATTR_ADDRS 50 /* 200 bytes for inline xattrs */
171171
#define DEF_ADDRS_PER_INODE 923 /* Address Pointers in an Inode */
172172
#define DEF_NIDS_PER_INODE 5 /* Node IDs in an Inode */
173-
#define ADDRS_PER_INODE(fi) addrs_per_inode(fi)
173+
#define ADDRS_PER_INODE(inode) addrs_per_inode(inode)
174174
#define ADDRS_PER_BLOCK 1018 /* Address Pointers in a Direct Block */
175175
#define NIDS_PER_BLOCK 1018 /* Node IDs in an Indirect Block */
176176

177-
#define ADDRS_PER_PAGE(page, fi) \
178-
(IS_INODE(page) ? ADDRS_PER_INODE(fi) : ADDRS_PER_BLOCK)
177+
#define ADDRS_PER_PAGE(page, inode) \
178+
(IS_INODE(page) ? ADDRS_PER_INODE(inode) : ADDRS_PER_BLOCK)
179179

180180
#define NODE_DIR1_BLOCK (DEF_ADDRS_PER_INODE + 1)
181181
#define NODE_DIR2_BLOCK (DEF_ADDRS_PER_INODE + 2)

0 commit comments

Comments
 (0)