f2fs: inject fault to kzalloc
PATCH 1/7 f2fs: inject fault to kzalloc
This patch introduces f2fs_kzalloc based on f2fs_kmalloc in order to support error injection for kzalloc().
--- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/debug.c | 2 +- fs/f2fs/f2fs.h | 6 ++++++ fs/f2fs/namei.c | 2 +- fs/f2fs/node.c | 7 ++++--- fs/f2fs/segment.c | 30 ++++++++++++++++-------------- fs/f2fs/xattr.c | 8 ++++---- 7 files changed, 33 insertions(+), 24 deletions(-)
fs/f2fs/checkpoint.c +1 -1
@@ -796,7 +796,7 @@ int get_valid_checkpoint(struct f2fs_sb_info *sbi)block_t cp_blk_no;int i; - sbi->ckpt =kzalloc (cp_blks * blk_size,GFP_KERNEL ); + sbi->ckpt =f2fs_kzalloc (sbi, cp_blks * blk_size,GFP_KERNEL );if (!sbi->ckpt)return -ENOMEM ;/*
fs/f2fs/debug.c +1 -1
@@ -439,7 +439,7 @@ int f2fs_build_stats(struct f2fs_sb_info *sbi)struct f2fs_super_block *raw_super =F2FS_RAW_SUPER (sbi);struct f2fs_stat_info *si; - si =kzalloc (sizeof (struct f2fs_stat_info ),GFP_KERNEL ); + si =f2fs_kzalloc (sbi,sizeof (struct f2fs_stat_info ),GFP_KERNEL );if (!si)return -ENOMEM ;
fs/f2fs/f2fs.h +6 -0
@@ -2425,6 +2425,12 @@ static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,return kmalloc (size, flags); } +static inline void *f2fs_kzalloc (struct f2fs_sb_info *sbi, +size_t size,gfp_t flags) +{ +return f2fs_kmalloc (sbi, size, flags | __GFP_ZERO); +} +static inline int get_extra_isize (struct inode *inode) {return F2FS_I (inode)->i_extra_isize /sizeof (__le32);
fs/f2fs/namei.c +1 -1
@@ -544,7 +544,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,struct qstr istr =QSTR_INIT (symname, len);struct fscrypt_str ostr; - sd =kzalloc (disk_link.len,GFP_NOFS ); + sd =f2fs_kzalloc (sbi, disk_link.len,GFP_NOFS );if (!sd) { err = -ENOMEM ; goto err_out;
fs/f2fs/node.c +4 -3
@@ -2600,8 +2600,8 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi) nm_i->nat_bits_blocks =F2FS_BYTES_TO_BLK ((nat_bits_bytes <<1 ) +8 +F2FS_BLKSIZE -1 ); - nm_i->nat_bits =kzalloc (nm_i->nat_bits_blocks <<F2FS_BLKSIZE_BITS , -GFP_KERNEL ); + nm_i->nat_bits =f2fs_kzalloc (sbi, + nm_i->nat_bits_blocks <<F2FS_BLKSIZE_BITS ,GFP_KERNEL );if (!nm_i->nat_bits)return -ENOMEM ;
@@ -2747,7 +2747,8 @@ int build_node_manager(struct f2fs_sb_info *sbi) {int err; - sbi->nm_info =kzalloc (sizeof (struct f2fs_nm_info ),GFP_KERNEL ); + sbi->nm_info =f2fs_kzalloc (sbi,sizeof (struct f2fs_nm_info ), +GFP_KERNEL );if (!sbi->nm_info)return -ENOMEM ;
fs/f2fs/segment.c +16 -14
@@ -657,7 +657,7 @@ int create_flush_cmd_control(struct f2fs_sb_info *sbi) goto init_thread; } - fcc =kzalloc (sizeof (struct flush_cmd_control ),GFP_KERNEL ); + fcc =f2fs_kzalloc (sbi,sizeof (struct flush_cmd_control ),GFP_KERNEL );if (!fcc)return -ENOMEM ;atomic_set (&fcc->issued_flush,0 );
@@ -1737,7 +1737,7 @@ static int create_discard_cmd_control(struct f2fs_sb_info *sbi) goto init_thread; } - dcc =kzalloc (sizeof (struct discard_cmd_control ),GFP_KERNEL ); + dcc =f2fs_kzalloc (sbi,sizeof (struct discard_cmd_control ),GFP_KERNEL );if (!dcc)return -ENOMEM ;
@@ -3379,7 +3379,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)unsigned int bitmap_size;/* allocate memory for SIT information */ - sit_i =kzalloc (sizeof (struct sit_info ),GFP_KERNEL ); + sit_i =f2fs_kzalloc (sbi,sizeof (struct sit_info ),GFP_KERNEL );if (!sit_i)return -ENOMEM ;
@@ -3397,29 +3397,30 @@ static int build_sit_info(struct f2fs_sb_info *sbi)for (start =0 ; start <MAIN_SEGS (sbi); start++) { sit_i->sentries[start].cur_valid_map - =kzalloc (SIT_VBLOCK_MAP_SIZE ,GFP_KERNEL ); + =f2fs_kzalloc (sbi,SIT_VBLOCK_MAP_SIZE ,GFP_KERNEL ); sit_i->sentries[start].ckpt_valid_map - =kzalloc (SIT_VBLOCK_MAP_SIZE ,GFP_KERNEL ); + =f2fs_kzalloc (sbi,SIT_VBLOCK_MAP_SIZE ,GFP_KERNEL );if (!sit_i->sentries[start].cur_valid_map || !sit_i->sentries[start].ckpt_valid_map)return -ENOMEM ;#ifdef CONFIG_F2FS_CHECK_FS sit_i->sentries[start].cur_valid_map_mir - =kzalloc (SIT_VBLOCK_MAP_SIZE ,GFP_KERNEL ); + =f2fs_kzalloc (sbi,SIT_VBLOCK_MAP_SIZE ,GFP_KERNEL );if (!sit_i->sentries[start].cur_valid_map_mir)return -ENOMEM ;#endif if (f2fs_discard_en (sbi)) { sit_i->sentries[start].discard_map - =kzalloc (SIT_VBLOCK_MAP_SIZE ,GFP_KERNEL ); + =f2fs_kzalloc (sbi,SIT_VBLOCK_MAP_SIZE , +GFP_KERNEL );if (!sit_i->sentries[start].discard_map)return -ENOMEM ; } } - sit_i->tmp_map =kzalloc (SIT_VBLOCK_MAP_SIZE ,GFP_KERNEL ); + sit_i->tmp_map =f2fs_kzalloc (sbi,SIT_VBLOCK_MAP_SIZE ,GFP_KERNEL );if (!sit_i->tmp_map)return -ENOMEM ;
@@ -3468,7 +3469,7 @@ static int build_free_segmap(struct f2fs_sb_info *sbi)unsigned int bitmap_size, sec_bitmap_size;/* allocate memory for free segmap information */ - free_i =kzalloc (sizeof (struct free_segmap_info ),GFP_KERNEL ); + free_i =f2fs_kzalloc (sbi,sizeof (struct free_segmap_info ),GFP_KERNEL );if (!free_i)return -ENOMEM ;
@@ -3509,12 +3510,12 @@ static int build_curseg(struct f2fs_sb_info *sbi)for (i =0 ; i <NR_CURSEG_TYPE ; i++) {mutex_init (&array[i].curseg_mutex); - array[i].sum_blk =kzalloc (PAGE_SIZE ,GFP_KERNEL ); + array[i].sum_blk =f2fs_kzalloc (sbi,PAGE_SIZE ,GFP_KERNEL );if (!array[i].sum_blk)return -ENOMEM ;init_rwsem (&array[i].journal_rwsem); - array[i].journal =kzalloc (sizeof (struct f2fs_journal ), -GFP_KERNEL ); + array[i].journal =f2fs_kzalloc (sbi, +sizeof (struct f2fs_journal ),GFP_KERNEL );if (!array[i].journal)return -ENOMEM ; array[i].segno =NULL_SEGNO ;
@@ -3672,7 +3673,8 @@ static int build_dirty_segmap(struct f2fs_sb_info *sbi)unsigned int bitmap_size, i;/* allocate memory for dirty segments list information */ - dirty_i =kzalloc (sizeof (struct dirty_seglist_info ),GFP_KERNEL ); + dirty_i =f2fs_kzalloc (sbi,sizeof (struct dirty_seglist_info ), +GFP_KERNEL );if (!dirty_i)return -ENOMEM ;
@@ -3726,7 +3728,7 @@ int build_segment_manager(struct f2fs_sb_info *sbi)struct f2fs_sm_info *sm_info;int err; - sm_info =kzalloc (sizeof (struct f2fs_sm_info ),GFP_KERNEL ); + sm_info =f2fs_kzalloc (sbi,sizeof (struct f2fs_sm_info ),GFP_KERNEL );if (!sm_info)return -ENOMEM ;
fs/f2fs/xattr.c +4 -4
@@ -298,8 +298,8 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,if (!size && !inline_size)return -ENODATA ; - txattr_addr =kzalloc (inline_size + size +XATTR_PADDING_SIZE , -GFP_F2FS_ZERO ); + txattr_addr =f2fs_kzalloc (F2FS_I_SB (inode), + inline_size + size +XATTR_PADDING_SIZE ,GFP_NOFS );if (!txattr_addr)return -ENOMEM ;
@@ -351,8 +351,8 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage,void *txattr_addr;int err; - txattr_addr =kzalloc (inline_size + size +XATTR_PADDING_SIZE , -GFP_F2FS_ZERO ); + txattr_addr =f2fs_kzalloc (F2FS_I_SB (inode), + inline_size + size +XATTR_PADDING_SIZE ,GFP_NOFS );if (!txattr_addr)return -ENOMEM ;
Signature · 6 lines
2.15.0.55.gc2ece9dc4de6 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 2/7 f2fs: inject fault to kvmalloc
This patch supports to inject fault into kvmalloc/kvzalloc.
--- fs/f2fs/f2fs.h | 19 +++++++++++++++++++ fs/f2fs/file.c | 6 ++++-- fs/f2fs/node.c | 6 +++--- fs/f2fs/segment.c | 16 +++++++++------- fs/f2fs/super.c | 1 + 5 files changed, 36 insertions(+), 12 deletions(-)
fs/f2fs/f2fs.h +19 -0
@@ -45,6 +45,7 @@#ifdef CONFIG_F2FS_FAULT_INJECTION enum {FAULT_KMALLOC , +FAULT_KVMALLOC ,FAULT_PAGE_ALLOC ,FAULT_PAGE_GET , FAULT_ALLOC_BIO,
@@ -2431,6 +2432,24 @@ static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi,return f2fs_kmalloc (sbi, size, flags | __GFP_ZERO); } +static inline void *f2fs_kvmalloc (struct f2fs_sb_info *sbi, +size_t size,gfp_t flags) +{ +#ifdef CONFIG_F2FS_FAULT_INJECTION +if (time_to_inject (sbi,FAULT_KVMALLOC )) { +f2fs_show_injection_info (FAULT_KVMALLOC ); +return NULL ; + } +#endif +return kvmalloc (size, flags); +} + +static inline void *f2fs_kvzalloc (struct f2fs_sb_info *sbi, +size_t size,gfp_t flags) +{ +return f2fs_kvmalloc (sbi, size, flags | __GFP_ZERO); +} +static inline int get_extra_isize (struct inode *inode) {return F2FS_I (inode)->i_extra_isize /sizeof (__le32);
fs/f2fs/file.c +4 -2
@@ -1113,11 +1113,13 @@ static int __exchange_data_block(struct inode *src_inode,while (len) { olen =min ((pgoff_t )4 *ADDRS_PER_BLOCK , len); - src_blkaddr =kvzalloc (sizeof (block_t) * olen,GFP_KERNEL ); + src_blkaddr =f2fs_kvzalloc (F2FS_I_SB (src_inode), +sizeof (block_t) * olen,GFP_KERNEL );if (!src_blkaddr)return -ENOMEM ; - do_replace =kvzalloc (sizeof (int ) * olen,GFP_KERNEL ); + do_replace =f2fs_kvzalloc (F2FS_I_SB (src_inode), +sizeof (int ) * olen,GFP_KERNEL );if (!do_replace) {kvfree (src_blkaddr);return -ENOMEM ;
fs/f2fs/node.c +3 -3
@@ -2726,17 +2726,17 @@ static int init_free_nid_cache(struct f2fs_sb_info *sbi) {struct f2fs_nm_info *nm_i =NM_I (sbi); - nm_i->free_nid_bitmap =kvzalloc (nm_i->nat_blocks * + nm_i->free_nid_bitmap =f2fs_kvzalloc (sbi, nm_i->nat_blocks *NAT_ENTRY_BITMAP_SIZE ,GFP_KERNEL );if (!nm_i->free_nid_bitmap)return -ENOMEM ; - nm_i->nat_block_bitmap =kvzalloc (nm_i->nat_blocks /8 , + nm_i->nat_block_bitmap =f2fs_kvzalloc (sbi, nm_i->nat_blocks /8 ,GFP_KERNEL );if (!nm_i->nat_block_bitmap)return -ENOMEM ; - nm_i->free_nid_count =kvzalloc (nm_i->nat_blocks * + nm_i->free_nid_count =f2fs_kvzalloc (sbi, nm_i->nat_blocks *sizeof (unsigned short ),GFP_KERNEL );if (!nm_i->free_nid_count)return -ENOMEM ;
fs/f2fs/segment.c +9 -7
@@ -3385,13 +3385,14 @@ static int build_sit_info(struct f2fs_sb_info *sbi)SM_I (sbi)->sit_info = sit_i; - sit_i->sentries =kvzalloc (MAIN_SEGS (sbi) * + sit_i->sentries =f2fs_kvzalloc (sbi,MAIN_SEGS (sbi) *sizeof (struct seg_entry ),GFP_KERNEL );if (!sit_i->sentries)return -ENOMEM ; bitmap_size =f2fs_bitmap_size (MAIN_SEGS (sbi)); - sit_i->dirty_sentries_bitmap =kvzalloc (bitmap_size,GFP_KERNEL ); + sit_i->dirty_sentries_bitmap =f2fs_kvzalloc (sbi, bitmap_size, +GFP_KERNEL );if (!sit_i->dirty_sentries_bitmap)return -ENOMEM ;
@@ -3425,7 +3426,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)return -ENOMEM ;if (sbi->segs_per_sec >1 ) { - sit_i->sec_entries =kvzalloc (MAIN_SECS (sbi) * + sit_i->sec_entries =f2fs_kvzalloc (sbi,MAIN_SECS (sbi) *sizeof (struct sec_entry ),GFP_KERNEL );if (!sit_i->sec_entries)return -ENOMEM ;
@@ -3476,12 +3477,12 @@ static int build_free_segmap(struct f2fs_sb_info *sbi)SM_I (sbi)->free_info = free_i; bitmap_size =f2fs_bitmap_size (MAIN_SEGS (sbi)); - free_i->free_segmap =kvmalloc (bitmap_size,GFP_KERNEL ); + free_i->free_segmap =f2fs_kvmalloc (sbi, bitmap_size,GFP_KERNEL );if (!free_i->free_segmap)return -ENOMEM ; sec_bitmap_size =f2fs_bitmap_size (MAIN_SECS (sbi)); - free_i->free_secmap =kvmalloc (sec_bitmap_size,GFP_KERNEL ); + free_i->free_secmap =f2fs_kvmalloc (sbi, sec_bitmap_size,GFP_KERNEL );if (!free_i->free_secmap)return -ENOMEM ;
@@ -3661,7 +3662,7 @@ static int init_victim_secmap(struct f2fs_sb_info *sbi)struct dirty_seglist_info *dirty_i =DIRTY_I (sbi);unsigned int bitmap_size =f2fs_bitmap_size (MAIN_SECS (sbi)); - dirty_i->victim_secmap =kvzalloc (bitmap_size,GFP_KERNEL ); + dirty_i->victim_secmap =f2fs_kvzalloc (sbi, bitmap_size,GFP_KERNEL );if (!dirty_i->victim_secmap)return -ENOMEM ;return 0 ;
@@ -3684,7 +3685,8 @@ static int build_dirty_segmap(struct f2fs_sb_info *sbi) bitmap_size =f2fs_bitmap_size (MAIN_SEGS (sbi));for (i =0 ; i <NR_DIRTY_TYPE ; i++) { - dirty_i->dirty_segmap[i] =kvzalloc (bitmap_size,GFP_KERNEL ); + dirty_i->dirty_segmap[i] =f2fs_kvzalloc (sbi, bitmap_size, +GFP_KERNEL );if (!dirty_i->dirty_segmap[i])return -ENOMEM ; }
fs/f2fs/super.c +1 -0
@@ -43,6 +43,7 @@ static struct kmem_cache *f2fs_inode_cachep;char *fault_name[FAULT_MAX ] = { [FAULT_KMALLOC ] ="kmalloc" , + [FAULT_KVMALLOC ] ="kvmalloc" , [FAULT_PAGE_ALLOC ] ="page alloc" , [FAULT_PAGE_GET ] ="page get" , [FAULT_ALLOC_BIO ] ="alloc bio" ,
Signature · 6 lines
2.15.0.55.gc2ece9dc4de6 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 3/7 f2fs: spread f2fs_k{m,z}alloc
In reply to Chao YuUse f2fs_k{m,z}alloc as much as possible to increase fault injection points.
--- fs/f2fs/segment.c | 2 +- fs/f2fs/super.c | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-)
fs/f2fs/segment.c +1 -1
@@ -3503,7 +3503,7 @@ static int build_curseg(struct f2fs_sb_info *sbi)struct curseg_info *array;int i; - array =kcalloc (NR_CURSEG_TYPE ,sizeof (*array),GFP_KERNEL ); + array =f2fs_kzalloc (sbi,sizeof (*array) *NR_CURSEG_TYPE ,GFP_KERNEL );if (!array)return -ENOMEM ;
fs/f2fs/super.c +9 -7
@@ -2155,14 +2155,15 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)if (nr_sectors & (bdev_zone_sectors (bdev) -1 ))FDEV (devi).nr_blkz++; -FDEV (devi).blkz_type =kmalloc (FDEV (devi).nr_blkz,GFP_KERNEL ); +FDEV (devi).blkz_type =f2fs_kmalloc (sbi,FDEV (devi).nr_blkz, +GFP_KERNEL );if (!FDEV (devi).blkz_type)return -ENOMEM ;#define F2FS_REPORT_NR_ZONES 4096 - zones =kcalloc (F2FS_REPORT_NR_ZONES ,sizeof (struct blk_zone ), -GFP_KERNEL ); + zones =f2fs_kzalloc (sbi,sizeof (struct blk_zone ) * +F2FS_REPORT_NR_ZONES ,GFP_KERNEL );if (!zones)return -ENOMEM ;
@@ -2302,8 +2303,8 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)* Initialize multiple devices information, or single * zoned block device information. */ - sbi->devs =kcalloc (max_devices,sizeof (struct f2fs_dev_info ), -GFP_KERNEL ); + sbi->devs =f2fs_kzalloc (sbi,sizeof (struct f2fs_dev_info ) * + max_devices,GFP_KERNEL );if (!sbi->devs)return -ENOMEM ;
@@ -2507,8 +2508,9 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)int n = (i ==META ) ?1 :NR_TEMP_TYPE ;int j; - sbi->write_io[i] =kmalloc (n *sizeof (struct f2fs_bio_info ), -GFP_KERNEL ); + sbi->write_io[i] =f2fs_kmalloc (sbi, + n *sizeof (struct f2fs_bio_info ), +GFP_KERNEL );if (!sbi->write_io[i]) { err = -ENOMEM ; goto free_options;
Signature · 6 lines
2.15.0.55.gc2ece9dc4de6 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 4/7 f2fs: fix error handling in fill_super
In reply to Chao YuIn fill_super, if we fail to call f2fs_build_stats(), it needs to detach from global f2fs shrink list, otherwise once system starts to shrink slab cache, we will encounter below panic:
BUG: unable to handle kernel paging request at 00007d35 Oops: 0002 [#1] PREEMPT SMP EIP: __lock_acquire+0x70/0x12c0 Call Trace: lock_acquire+0xae/0x220 mutex_trylock+0xc5/0xf0 f2fs_shrink_count+0x32/0xb0 [f2fs] shrink_slab+0xf1/0x5b0 drop_slab_node+0x35/0x60 drop_slab+0xf/0x20 drop_caches_sysctl_handler+0x79/0xc0 proc_sys_call_handler+0xa4/0xc0 proc_sys_write+0x1f/0x30 __vfs_write+0x24/0x150 SyS_write+0x44/0x90 do_fast_syscall_32+0xa1/0x1ca entry_SYSENTER_32+0x4c/0x7b
In addition, this patch relocates f2fs_join_shrinker in fill_super to avoid unneeded error handling of it.
--- fs/f2fs/super.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
fs/f2fs/super.c +7 -9
@@ -2620,18 +2620,16 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) goto free_nm; } -f2fs_join_shrinker (sbi); - err =f2fs_build_stats (sbi);if (err) - goto free_nm; + goto free_node_inode;/* read root inode and dentry */ root =f2fs_iget (sb,F2FS_ROOT_INO (sbi));if (IS_ERR (root)) {f2fs_msg (sb,KERN_ERR ,"Failed to read root inode" ); err =PTR_ERR (root); - goto free_node_inode; + goto free_stats; }if (!S_ISDIR (root->i_mode) || !root->i_blocks || !root->i_size) {iput (root);
@@ -2727,6 +2725,8 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) sbi->valid_super_block ? 1 : 2, err); } +f2fs_join_shrinker (sbi); +f2fs_msg (sbi->sb,KERN_NOTICE ,"Mounted with checkpoint version = %llx" ,cur_cp_version (F2FS_CKPT (sbi)));f2fs_update_time (sbi,CP_TIME );
@@ -2753,14 +2753,12 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) free_root_inode:dput (sb->s_root); sb->s_root =NULL ; +free_stats: +f2fs_destroy_stats (sbi); free_node_inode: -truncate_inode_pages_final (NODE_MAPPING (sbi)); -mutex_lock (&sbi->umount_mutex);release_ino_entry (sbi, true); -f2fs_leave_shrinker (sbi); +truncate_inode_pages_final (NODE_MAPPING (sbi));iput (sbi->node_inode); -mutex_unlock (&sbi->umount_mutex); -f2fs_destroy_stats (sbi); free_nm:destroy_node_manager (sbi); free_sm:
Signature · 6 lines
2.15.0.55.gc2ece9dc4de6 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 5/7 f2fs: clean up hash codes
In reply to Chao Yuf2fs_chksum and f2fs_crc32 use the same 'crc32' crypto engine, also their implementation are almost the same, except with different shash description context.
Introduce __f2fs_crc32 to wrap the common codes, and reuse it in f2fs_chksum and f2fs_crc32.
--- fs/f2fs/f2fs.h | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-)
fs/f2fs/f2fs.h +19 -27
@@ -1258,33 +1258,7 @@ static inline bool is_idle(struct f2fs_sb_info *sbi)/* * Inline functions */ -static inline u32 f2fs_crc32 (struct f2fs_sb_info *sbi,const void *address, -unsigned int length) -{ -SHASH_DESC_ON_STACK (shash, sbi->s_chksum_driver); -u32 *ctx = (u32 *)shash_desc_ctx (shash); -u32 retval; -int err; - - shash->tfm = sbi->s_chksum_driver; - shash->flags =0 ; - *ctx =F2FS_SUPER_MAGIC ; - - err =crypto_shash_update (shash, address, length); -BUG_ON (err); - - retval = *ctx; -barrier_data (ctx); -return retval; -} - -static inline bool f2fs_crc_valid (struct f2fs_sb_info *sbi,__u32 blk_crc, -void *buf,size_t buf_size) -{ -return f2fs_crc32 (sbi, buf, buf_size) == blk_crc; -} - -static inline u32 f2fs_chksum (struct f2fs_sb_info *sbi,u32 crc, +static inline u32 __f2fs_crc32 (struct f2fs_sb_info *sbi,u32 crc,const void *address,unsigned int length) {struct {
@@ -1305,6 +1279,24 @@ static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc,return *(u32 *)desc.ctx; } +static inline u32 f2fs_crc32 (struct f2fs_sb_info *sbi,const void *address, +unsigned int length) +{ +return __f2fs_crc32 (sbi,F2FS_SUPER_MAGIC , address, length); +} + +static inline bool f2fs_crc_valid (struct f2fs_sb_info *sbi,__u32 blk_crc, +void *buf,size_t buf_size) +{ +return f2fs_crc32 (sbi, buf, buf_size) == blk_crc; +} + +static inline u32 f2fs_chksum (struct f2fs_sb_info *sbi,u32 crc, +const void *address,unsigned int length) +{ +return __f2fs_crc32 (sbi, crc, address, length); +} +static inline struct f2fs_inode_info *F2FS_I (struct inode *inode) { return container_of(inode, struct f2fs_inode_info, vfs_inode);
Signature · 6 lines
2.15.0.55.gc2ece9dc4de6 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 6/7 f2fs: clean up f2fs_map_blocks
In reply to Chao Yuf2fs_map_blocks():
if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR) {
if (create) {
...
} else {
...
if (flag == F2FS_GET_BLOCK_FIEMAP &&
blkaddr == NULL_ADDR) {
...
}
if (flag != F2FS_GET_BLOCK_FIEMAP ||
blkaddr != NEW_ADDR)
goto sync_out;
}It means we can break the loop in cases of:
a) flag != F2FS_GET_BLOCK_FIEMAP or
b) flag == F2FS_GET_BLOCK_FIEMAP && blkaddr == NULL_ADDR
Condition b) is the same as previous one, so merge operations of them for readability.
--- fs/f2fs/data.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/data.c +2 -2
@@ -988,9 +988,9 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, blkaddr == NULL_ADDR) {if (map->m_next_pgofs) *map->m_next_pgofs = pgofs +1 ; + goto sync_out; } -if (flag !=F2FS_GET_BLOCK_FIEMAP || - blkaddr !=NEW_ADDR ) +if (flag !=F2FS_GET_BLOCK_FIEMAP ) goto sync_out; } }
Signature · 6 lines
2.15.0.55.gc2ece9dc4de6 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 7/7 f2fs: don't return value in truncate_data_blocks_range
In reply to Chao YuThere is no caller cares about return value of truncate_data_blocks_range, remove it.
--- fs/f2fs/f2fs.h | 2 +- fs/f2fs/file.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-)
fs/f2fs/f2fs.h +1 -1
@@ -2503,7 +2503,7 @@ int f2fs_getattr(const struct path *path, struct kstat *stat, u32 request_mask, unsigned int flags);int f2fs_setattr (struct dentry *dentry,struct iattr *attr);int truncate_hole (struct inode *inode,pgoff_t pg_start,pgoff_t pg_end); -int truncate_data_blocks_range (struct dnode_of_data *dn,int count); +void truncate_data_blocks_range (struct dnode_of_data *dn,int count);long f2fs_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);long f2fs_compat_ioctl (struct file *file,unsigned int cmd,unsigned long arg);
fs/f2fs/file.c +1 -2
@@ -490,7 +490,7 @@ static int f2fs_file_open(struct inode *inode, struct file *filp)return dquot_file_open (inode, filp); } -int truncate_data_blocks_range (struct dnode_of_data *dn,int count) +void truncate_data_blocks_range (struct dnode_of_data *dn,int count) {struct f2fs_sb_info *sbi =F2FS_I_SB (dn->inode);struct f2fs_node *raw_node;
@@ -533,7 +533,6 @@ int truncate_data_blocks_range(struct dnode_of_data *dn, int count)f2fs_update_time (sbi,REQ_TIME );trace_f2fs_truncate_data_blocks_range (dn->inode, dn->nid, dn->ofs_in_node, nr_free); -return nr_free; }void truncate_data_blocks (struct dnode_of_data *dn)
Signature · 6 lines
2.15.0.55.gc2ece9dc4de6 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot