f2fs: prepare metadata layouts for runtime block sizes
v8 cover f2fs: prepare metadata layouts for runtime block sizes
F2FS currently describes several on-disk metadata layouts and filesystem geometry values with constants derived from PAGE_SIZE or a fixed 4KB block size. This series derives those values from the mounted filesystem's block size instead, as preparation for supporting filesystem blocks smaller than PAGE_SIZE.
The patches initialize sb_info early, describe the SIT, NAT, orphan, dentry, node, and xattr layouts dynamically, parameterize sector/byte/block conversion helpers, and derive node-tree geometry at runtime.
This series does not relax the block-size mount check or enable subpage I/O. It is intended to be a behavior-preserving refactoring for currently supported 4KB-block filesystems.
Changes since v7:
- address all review comments from Chao Yu and Daeho Jeong
- mark the sb_set_blocksize() failure as unlikely and remove unused helpers
- retain struct f2fs_orphan_block as a flexible-array wrapper
- separate the shared-header block-size geometry helper from the cached kernel-side inode geometry helper
- consolidate the inline-xattr size helpers and move F2FS_MAX_BLKSIZE to its first use
- retain the node-ID layout description without nesting comments
- restore shift-based block alignment instead of using 64-bit division
- move node-tree geometry before block-size macro parameterization so each intermediate patch builds without temporary PAGE_SIZE churn
- use a size_t format for the maximum inline-xattr size on 32-bit builds
- remove unrelated whitespace and other incidental changes
v7:
https://lore.kernel.org/linux-f2fs-devel/[email protected]/
Changes since v3:
- no code changes in v4 through v7; those versions addressed mail transport corruption before v7 was delivered intact through direct SMTP
Changes since v2:
- use DECLARE_FLEX_ARRAY() for flexible arrays that are alone in a struct or used in a union, fixing the reported m68k GCC build failures
- use F2FS_BLK_ALIGN() in f2fs_sec_trim_file() to avoid a runtime 64-bit division and an unresolved __divdi3 reference on 32-bit SH
- no other code changes
Changes since v1:
- rebase onto f2fs/dev at c966d29e01bb
- drop the unrelated free-NID underflow fix from this series
- split the preparatory changes into 11 focused patches
- initialize sb_info earlier and describe the xattr layout explicitly
- separate sector, byte/block, and block-size macro parameterization
- update commit messages and address checkpatch warnings
v2:
https://lore.kernel.org/linux-f2fs-devel/CAH=xXfHWW_J92z3YgvoLSx8+z6rekq=p2kiP15KE9=2+Ju2RjQ@mail.gmail.com/
v1:
https://lore.kernel.org/linux-f2fs-devel/CAH=xXfFVAwQ3r_NdUDtmXhtg6Lw8kDWoNTzGL5oy4mwHMsJLJw@mail.gmail.com/
Tested with:
- x86_64 W=1 F2FS build at every patch
- i386 allmodconfig W=1 F2FS builds at patch 07/11 and the series tip (no new warnings)
- arm64 16KB-page W=1 F2FS build at the series tip
- builds of all five F2FS subpage selftest binaries on the complete branch
- scripts/checkpatch.pl --strict (no errors or warnings)
Kelvin Zhang (11):
f2fs: initialize sb_info early in f2fs_fill_super
f2fs: describe SIT block layout dynamically
f2fs: describe NAT block layout dynamically
f2fs: describe orphan block layout dynamically
f2fs: describe dentry block layout dynamically
f2fs: describe {i,d,id}node block layout dynamically
f2fs: describe xattr block layout dynamically
f2fs: parameterize sector conversion macros
f2fs: parameterize byte and block conversion macros
f2fs: describe node tree geometry dynamically
f2fs: parameterize block size and mask macros
fs/f2fs/checkpoint.c | 63 ++++++++------- fs/f2fs/data.c | 85 +++++++++++--------- fs/f2fs/debug.c | 4 +- fs/f2fs/dir.c | 51 ++++++------ fs/f2fs/extent_cache.c | 9 ++- fs/f2fs/f2fs.h | 117 ++++++++++++++++++++------- fs/f2fs/file.c | 84 +++++++++++--------- fs/f2fs/gc.c | 27 ++++--- fs/f2fs/inline.c | 11 ++- fs/f2fs/inode.c | 25 +++--- fs/f2fs/node.c | 171 +++++++++++++++++++++------------------- fs/f2fs/node.h | 87 ++++++++++---------- fs/f2fs/recovery.c | 4 +- fs/f2fs/segment.c | 60 +++++++------- fs/f2fs/segment.h | 32 ++++---- fs/f2fs/shrinker.c | 2 +- fs/f2fs/super.c | 84 +++++++++++++------- fs/f2fs/sysfs.c | 10 +-- fs/f2fs/verity.c | 6 +- fs/f2fs/xattr.c | 10 ++- fs/f2fs/xattr.h | 11 +-- include/linux/f2fs_fs.h | 135 +++++++++++++++++-------------- 22 files changed, 628 insertions(+), 460 deletions(-)
base-commit: c966d29e01bbf829f8bb4a39a49811c56cdb49c3
Signature · 1 line
2.53.0
PATCH v8 1/11 f2fs: initialize sb_info early in f2fs_fill_super
Previously, init_sb_info() was invoked late in f2fs_fill_super(), after processing superblock error tracking, mount options, and sb->s_maxbytes.
However, read_raw_super_block() reads the superblock folio directly from the block device mapping using folio page offsets. This makes the initial static sb_set_blocksize(sb, F2FS_BLKSIZE) call redundant.
Move init_sb_info() to execute immediately after sbi->raw_super is attached, allowing the block device block size to be set dynamically via sb_set_blocksize(sb, sbi->blocksize).
This early initialization also prepares for upcoming patches that add dynamically computed filesystem geometry fields, such as sbi->addrs_per_block and sbi->nids_per_block, to init_sb_info(). These fields are required by earlier initialization steps, including mount option consistency checks and sb->s_maxbytes computation.
--- fs/f2fs/super.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fs/f2fs/super.c +8 -8
@@ -5125,12 +5125,6 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc) }mutex_init (&sbi->flush_lock); -/* set a block size */ -if (unlikely (!sb_set_blocksize (sb,F2FS_BLKSIZE ))) { -f2fs_err (sbi,"unable to set blocksize" ); - goto free_sbi; - } - err =read_raw_super_block (sbi, &raw_super, &valid_super_block, &recovery);if (err)
@@ -5138,6 +5132,14 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_fs_info = sbi; sbi->raw_super = raw_super; +init_sb_info (sbi); + +/* set a block size */ +if (unlikely (!sb_set_blocksize (sb, sbi->blocksize))) { +f2fs_err (sbi,"unable to set blocksize %u" , sbi->blocksize); + err = -EINVAL ; + goto free_sb_buf; + } sbi->max_atc_write_bio_size =UINT_MAX ;INIT_WORK (&sbi->s_error_work, f2fs_record_error_work);
@@ -5217,8 +5219,6 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)if (err) goto free_bio_info; -init_sb_info (sbi); - err =f2fs_init_iostat (sbi);if (err) goto free_bio_info;
Signature · 1 line
2.53.0
PATCH v8 2/11 f2fs: describe SIT block layout dynamically
In reply to Kelvin ZhangAn SIT block consists of an on-disk array of struct f2fs_sit_entry elements whose total capacity depends on the filesystem block size. The existing fixed SIT_ENTRY_PER_BLOCK macro hardcodes a 4KB block size.
Convert the entries array in struct f2fs_sit_block into a C flexible array member, and calculate sbi->sit_entries_per_block dynamically in init_sb_info().
Parameterize SIT indexing helpers (SIT_ENTRY_PER_BLOCK, SIT_BLOCK_OFFSET, SIT_BLK_CNT, and f2fs_start_segno) to take struct f2fs_sb_info *sbi, and update all call sites across segment management, checkpointing, and mount.
This is a layout-only change; valid 4KB filesystems retain identical runtime geometry and behavior.
--- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/f2fs.h | 3 +++ fs/f2fs/segment.c | 15 ++++++++------- fs/f2fs/segment.h | 22 +++++++++++++--------- fs/f2fs/super.c | 4 +++- include/linux/f2fs_fs.h | 9 ++++++--- 6 files changed, 34 insertions(+), 21 deletions(-)
fs/f2fs/checkpoint.c +1 -1
@@ -487,7 +487,7 @@ int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, goto out;/* get sit block addr */ fio.new_blkaddr =current_sit_addr (sbi, - blkno *SIT_ENTRY_PER_BLOCK ); + blkno *SIT_ENTRY_PER_BLOCK (sbi));break ;case META_SSA :case META_CP :
fs/f2fs/f2fs.h +3 -0
@@ -1863,6 +1863,7 @@ struct f2fs_sb_info {unsigned int log_sectors_per_block;/* log2 sectors per block */ unsigned int log_blocksize;/* log2 block size */ unsigned int blocksize;/* block size */ +unsigned int sit_entries_per_block;/* SIT entries in a block */ unsigned int root_ino_num;/* root inode number*/ unsigned int node_ino_num;/* node inode number*/ unsigned int meta_ino_num;/* meta inode number*/
@@ -2251,6 +2252,8 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const struct folio *folio)return F2FS_M_SB (folio->mapping); } +#define SIT_ENTRY_PER_BLOCK (sbi) ((sbi)->sit_entries_per_block) +static inline struct f2fs_super_block *F2FS_RAW_SUPER (struct f2fs_sb_info *sbi) {return (struct f2fs_super_block *)(sbi->raw_super);
fs/f2fs/segment.c +8 -7
@@ -4708,7 +4708,7 @@ static struct folio *get_next_sit_folio(struct f2fs_sb_info *sbi,seg_info_to_sit_folio (sbi, folio, start);folio_mark_dirty (folio); -set_to_next_sit (sit_i, start); +set_to_next_sit (sbi, sit_i, start);return folio; }
@@ -4747,10 +4747,11 @@ static void adjust_sit_entry_set(struct sit_entry_set *ses,list_move_tail (&ses->set_list, head); } -static void add_sit_entry (unsigned int segno,struct list_head *head) +static void add_sit_entry (struct f2fs_sb_info *sbi,unsigned int segno, +struct list_head *head) {struct sit_entry_set *ses; -unsigned int start_segno =START_SEGNO (segno); +unsigned int start_segno =f2fs_start_segno (sbi, segno);list_for_each_entry (ses, head, set_list) {if (ses->start_segno == start_segno) {
@@ -4775,7 +4776,7 @@ static void add_sits_in_set(struct f2fs_sb_info *sbi)unsigned int segno;for_each_set_bit (segno, bitmap,MAIN_SEGS (sbi)) -add_sit_entry (segno, set_list); +add_sit_entry (sbi, segno, set_list); }static void remove_sits_in_journal (struct f2fs_sb_info *sbi)
@@ -4793,7 +4794,7 @@ static void remove_sits_in_journal(struct f2fs_sb_info *sbi) dirtied =__mark_sit_entry_dirty (sbi, segno);if (!dirtied) -add_sit_entry (segno, &SM_I (sbi)->sit_entry_set); +add_sit_entry (sbi, segno, &SM_I (sbi)->sit_entry_set); }update_sits_in_cursum (journal, -i);up_write (&curseg->journal_rwsem);
@@ -4843,7 +4844,7 @@ void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)struct folio *folio =NULL ;struct f2fs_sit_block *raw_sit =NULL ;unsigned int start_segno = ses->start_segno; -unsigned int end =min (start_segno +SIT_ENTRY_PER_BLOCK , +unsigned int end =min (start_segno +SIT_ENTRY_PER_BLOCK (sbi), (unsigned long )MAIN_SEGS (sbi));unsigned int segno = start_segno;
@@ -5008,7 +5009,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi) sit_i->written_valid_blocks =0 ; sit_i->bitmap_size = sit_bitmap_size; sit_i->dirty_sentries =0 ; - sit_i->sents_per_block =SIT_ENTRY_PER_BLOCK ; + sit_i->sents_per_block =SIT_ENTRY_PER_BLOCK (sbi); sit_i->elapsed_time =le64_to_cpu (sbi->ckpt->elapsed_time); sit_i->mounted_time =ktime_get_boottime_seconds ();init_rwsem (&sit_i->sentry_lock);
fs/f2fs/segment.h +13 -9
@@ -102,12 +102,15 @@ static inline void sanity_check_seg_type(struct f2fs_sb_info *sbi,#define SIT_ENTRY_OFFSET (sit_i, segno) \ ((segno) % (sit_i)->sents_per_block) -#define SIT_BLOCK_OFFSET (segno) \ - ((segno) / SIT_ENTRY_PER_BLOCK) -#define START_SEGNO (segno) \ - (SIT_BLOCK_OFFSET(segno) * SIT_ENTRY_PER_BLOCK) +#define SIT_BLOCK_OFFSET (sbi, segno) \ + ((segno) / SIT_ENTRY_PER_BLOCK(sbi)) +static inline unsigned int +f2fs_start_segno (struct f2fs_sb_info *sbi,unsigned int segno) +{ +return SIT_BLOCK_OFFSET (sbi, segno) *SIT_ENTRY_PER_BLOCK (sbi); +}#define SIT_BLK_CNT (sbi) \ - DIV_ROUND_UP(MAIN_SEGS(sbi), SIT_ENTRY_PER_BLOCK) + DIV_ROUND_UP(MAIN_SEGS(sbi), SIT_ENTRY_PER_BLOCK(sbi))#define f2fs_bitmap_size (nr) \ (BITS_TO_LONGS(nr) * sizeof(unsigned long))
@@ -424,7 +427,7 @@ static inline void seg_info_to_sit_folio(struct f2fs_sb_info *sbi,struct f2fs_sit_block *raw_sit;struct seg_entry *se;struct f2fs_sit_entry *rs; -unsigned int end =min (start +SIT_ENTRY_PER_BLOCK , +unsigned int end =min (start +SIT_ENTRY_PER_BLOCK (sbi), (unsigned long )MAIN_SEGS (sbi));int i;
@@ -869,7 +872,7 @@ static inline pgoff_t current_sit_addr(struct f2fs_sb_info *sbi, unsigned int start) {struct sit_info *sit_i =SIT_I (sbi); -unsigned int offset =SIT_BLOCK_OFFSET (start); +unsigned int offset =SIT_BLOCK_OFFSET (sbi, start);block_t blk_addr = sit_i->sit_base_addr + offset;f2fs_bug_on (sbi, !valid_main_segno (sbi, start));
@@ -894,9 +897,10 @@ static inline pgoff_t next_sit_addr(struct f2fs_sb_info *sbi,return block_addr + sit_i->sit_base_addr; } -static inline void set_to_next_sit (struct sit_info *sit_i,unsigned int start) +static inline void set_to_next_sit (struct f2fs_sb_info *sbi, +struct sit_info *sit_i,unsigned int start) { -unsigned int block_off =SIT_BLOCK_OFFSET (start); +unsigned int block_off =SIT_BLOCK_OFFSET (sbi, start);f2fs_change_bit (block_off, sit_i->sit_bitmap); }
fs/f2fs/super.c +3 -1
@@ -4329,7 +4329,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)return 1 ; } - sit_blk_cnt =DIV_ROUND_UP (main_segs,SIT_ENTRY_PER_BLOCK ); + sit_blk_cnt =DIV_ROUND_UP (main_segs,SIT_ENTRY_PER_BLOCK (sbi));if (sit_bitmap_size *8 < sit_blk_cnt) {f2fs_err (sbi,"Wrong bitmap size: sit: %u, sit_blk_cnt:%u" , sit_bitmap_size, sit_blk_cnt);
@@ -4382,6 +4382,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi)le32_to_cpu (raw_super->log_sectors_per_block); sbi->log_blocksize =le32_to_cpu (raw_super->log_blocksize); sbi->blocksize =BIT (sbi->log_blocksize); + sbi->sit_entries_per_block = sbi->blocksize / +sizeof (struct f2fs_sit_entry ); sbi->log_blocks_per_seg =le32_to_cpu (raw_super->log_blocks_per_seg); sbi->blocks_per_seg =BIT (sbi->log_blocks_per_seg); sbi->segs_per_sec =le32_to_cpu (raw_super->segs_per_sec);
include/linux/f2fs_fs.h +6 -3
@@ -396,8 +396,6 @@ struct f2fs_nat_block {* Not allow to change this. */ #define SIT_VBLOCK_MAP_SIZE 64 -#define SIT_ENTRY_PER_BLOCK (F2FS_BLKSIZE / sizeof(struct f2fs_sit_entry)) -/* * F2FS uses 4 bytes to represent block address. As a result, supported size of * disk is 16 TB for a 4K page size and 64 TB for a 16K page size and it equals
@@ -424,8 +422,13 @@ struct f2fs_sit_entry {__le64 mtime;/* segment age for cleaning */ } __packed; +/* +* The on-disk SIT block is a filesystem-block-sized array of SIT entries. +* Its entry count depends on the filesystem block size, so it must be +* calculated by the caller rather than implied by this C structure. +*/ struct f2fs_sit_block { -struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK ]; + DECLARE_FLEX_ARRAY(struct f2fs_sit_entry, entries); } __packed;/*
Signature · 1 line
2.53.0
PATCH v8 3/11 f2fs: describe NAT block layout dynamically
In reply to Kelvin ZhangA NAT block is a filesystem-block-sized array of struct f2fs_nat_entry elements. The compile-time NAT_ENTRY_PER_BLOCK definition hardcodes the NAT capacity to a 4KB block size.
Replace the fixed array in struct f2fs_nat_block with a C flexible array member, and calculate sbi->nat_entries_per_block dynamically in init_sb_info().
Parameterize NAT geometry helpers (NAT_ENTRY_PER_BLOCK, NAT_BLOCK_OFFSET, f2fs_start_nid, NAT_BLK_CNT, and f2fs_nat_bitmap_size) with sbi. Update call sites across node management, checkpointing, GC, and sysfs.
This is a layout-only change without behavioral differences for 4KB blocks.
--- fs/f2fs/checkpoint.c | 4 +-- fs/f2fs/debug.c | 2 +- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/gc.c | 4 +-- fs/f2fs/node.c | 77 +++++++++++++++++++++-------------------- fs/f2fs/node.h | 20 +++++++---- fs/f2fs/segment.c | 4 +-- fs/f2fs/shrinker.c | 2 +- fs/f2fs/super.c | 4 ++- include/linux/f2fs_fs.h | 5 ++- 10 files changed, 69 insertions(+), 55 deletions(-)
fs/f2fs/checkpoint.c +2 -2
@@ -476,11 +476,11 @@ int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,switch (type) {case META_NAT :if (unlikely (blkno >= -NAT_BLOCK_OFFSET (NM_I (sbi)->max_nid))) +NAT_BLOCK_OFFSET (sbi,NM_I (sbi)->max_nid))) blkno =0 ;/* get nat block addr */ fio.new_blkaddr =current_nat_addr (sbi, - blkno *NAT_ENTRY_PER_BLOCK ); + blkno *NAT_ENTRY_PER_BLOCK (sbi));break ;case META_SIT :if (unlikely (blkno >=TOTAL_SEGS (sbi)))
fs/f2fs/debug.c +1 -1
@@ -345,7 +345,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi) si->base_mem +=__bitmap_size (sbi,NAT_BITMAP ); si->base_mem +=F2FS_BLK_TO_BYTES (NM_I (sbi)->nat_bits_blocks); si->base_mem +=NM_I (sbi)->nat_blocks * -f2fs_bitmap_size (NAT_ENTRY_PER_BLOCK ); +f2fs_bitmap_size (NAT_ENTRY_PER_BLOCK (sbi)); si->base_mem +=NM_I (sbi)->nat_blocks /8 ; si->base_mem +=NM_I (sbi)->nat_blocks *sizeof (unsigned short );
fs/f2fs/f2fs.h +2 -0
@@ -1863,6 +1863,7 @@ struct f2fs_sb_info {unsigned int log_sectors_per_block;/* log2 sectors per block */ unsigned int log_blocksize;/* log2 block size */ unsigned int blocksize;/* block size */ +unsigned int nat_entries_per_block;/* NAT entries in a block */ unsigned int sit_entries_per_block;/* SIT entries in a block */ unsigned int root_ino_num;/* root inode number*/ unsigned int node_ino_num;/* node inode number*/
@@ -2253,6 +2254,7 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const struct folio *folio) }#define SIT_ENTRY_PER_BLOCK (sbi) ((sbi)->sit_entries_per_block) +#define NAT_ENTRY_PER_BLOCK (sbi) ((sbi)->nat_entries_per_block)static inline struct f2fs_super_block *F2FS_RAW_SUPER (struct f2fs_sb_info *sbi) {
fs/f2fs/gc.c +2 -2
@@ -1066,7 +1066,7 @@ static int gc_node_segment(struct f2fs_sb_info *sbi,continue ;if (phase ==0 ) { -f2fs_ra_meta_pages (sbi,NAT_BLOCK_OFFSET (nid),1 , +f2fs_ra_meta_pages (sbi,NAT_BLOCK_OFFSET (sbi, nid),1 ,META_NAT , true);continue ; }
@@ -1614,7 +1614,7 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,continue ;if (phase ==0 ) { -f2fs_ra_meta_pages (sbi,NAT_BLOCK_OFFSET (nid),1 , +f2fs_ra_meta_pages (sbi,NAT_BLOCK_OFFSET (sbi, nid),1 ,META_NAT , true);continue ; }
fs/f2fs/node.c +40 -37
243 lines not on this page · raw message
fs/f2fs/node.h +14 -6
@@ -6,14 +6,21 @@* http://www.samsung.com/ */ /* start node id of a node block dedicated to the given node id */ -#define START_NID (nid) (((nid) / NAT_ENTRY_PER_BLOCK) * NAT_ENTRY_PER_BLOCK) +static inline nid_t f2fs_start_nid (struct f2fs_sb_info *sbi,nid_t nid) +{ +unsigned int entries =NAT_ENTRY_PER_BLOCK (sbi); + +return (nid / entries) * entries; +}/* node block offset on the NAT area dedicated to the given start node id */ -#define NAT_BLOCK_OFFSET (start_nid) ((start_nid) / NAT_ENTRY_PER_BLOCK) +#define NAT_BLOCK_OFFSET (sbi, start_nid) \ + ((start_nid) / NAT_ENTRY_PER_BLOCK(sbi))/* # of pages to perform synchronous readahead before building free nids */ #define FREE_NID_PAGES 8 -#define MAX_FREE_NIDS (NAT_ENTRY_PER_BLOCK * FREE_NID_PAGES) +#define MAX_FREE_NIDS (sbi) ((unsigned long)NAT_ENTRY_PER_BLOCK(sbi) * \ + FREE_NID_PAGES)/* size of free nid batch when shrinking */ #define SHRINK_NID_BATCH_SIZE 8
@@ -208,7 +215,7 @@ static inline pgoff_t current_nat_addr(struct f2fs_sb_info *sbi, nid_t start)* OLD = (segment_off * 512) * 2 + off_in_segment * NEW = 2 * (segment_off * 512 + off_in_segment) - off_in_segment */ - block_off =NAT_BLOCK_OFFSET (start); + block_off =NAT_BLOCK_OFFSET (sbi, start); block_addr = (pgoff_t)(nm_i->nat_blkaddr + (block_off << 1) -
@@ -230,9 +237,10 @@ static inline pgoff_t next_nat_addr(struct f2fs_sb_info *sbi,return block_addr + nm_i->nat_blkaddr; } -static inline void set_to_next_nat (struct f2fs_nm_info *nm_i,nid_t start_nid) +static inline void set_to_next_nat (struct f2fs_sb_info *sbi, +struct f2fs_nm_info *nm_i,nid_t start_nid) { -unsigned int block_off =NAT_BLOCK_OFFSET (start_nid); +unsigned int block_off =NAT_BLOCK_OFFSET (sbi, start_nid);f2fs_change_bit (block_off, nm_i->nat_bitmap);#ifdef CONFIG_F2FS_CHECK_FS
fs/f2fs/segment.c +2 -2
@@ -512,10 +512,10 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg)/* check the # of cached NAT entries */ if (!f2fs_available_free_memory (sbi,NAT_ENTRIES )) -f2fs_try_to_free_nats (sbi,NAT_ENTRY_PER_BLOCK ); +f2fs_try_to_free_nats (sbi,NAT_ENTRY_PER_BLOCK (sbi));if (!f2fs_available_free_memory (sbi,FREE_NIDS )) -f2fs_try_to_free_nids (sbi,MAX_FREE_NIDS ); +f2fs_try_to_free_nids (sbi,MAX_FREE_NIDS (sbi));else f2fs_build_free_nids (sbi, false, false);
fs/f2fs/shrinker.c +1 -1
@@ -23,7 +23,7 @@ static unsigned long __count_nat_entries(struct f2fs_sb_info *sbi)static unsigned long __count_free_nids (struct f2fs_sb_info *sbi) { -long count =NM_I (sbi)->nid_cnt[FREE_NID ] -MAX_FREE_NIDS ; +long count =NM_I (sbi)->nid_cnt[FREE_NID ] -MAX_FREE_NIDS (sbi);return count >0 ? count :0 ; }
fs/f2fs/super.c +3 -1
@@ -4382,6 +4382,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi)le32_to_cpu (raw_super->log_sectors_per_block); sbi->log_blocksize =le32_to_cpu (raw_super->log_blocksize); sbi->blocksize =BIT (sbi->log_blocksize); + sbi->nat_entries_per_block = sbi->blocksize / +sizeof (struct f2fs_nat_entry ); sbi->sit_entries_per_block = sbi->blocksize /sizeof (struct f2fs_sit_entry ); sbi->log_blocks_per_seg =le32_to_cpu (raw_super->log_blocks_per_seg);
@@ -4391,7 +4393,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sbi->total_sections =le32_to_cpu (raw_super->section_count); sbi->total_node_count =SEGS_TO_BLKS (sbi, ((le32_to_cpu (raw_super->segment_count_nat) /2 ) * -NAT_ENTRY_PER_BLOCK )); +NAT_ENTRY_PER_BLOCK (sbi))); sbi->allocate_section_hint =le32_to_cpu (raw_super->section_count); sbi->allocate_section_policy =ALLOCATE_FORWARD_NOHINT ;F2FS_ROOT_INO (sbi) =le32_to_cpu (raw_super->root_ino);
include/linux/f2fs_fs.h +2 -3
@@ -375,8 +375,6 @@ struct f2fs_node {/* * For NAT entries */ -#define NAT_ENTRY_PER_BLOCK (F2FS_BLKSIZE / sizeof(struct f2fs_nat_entry)) -struct f2fs_nat_entry {__u8 version;/* latest version of cached nat entry */ __le32 ino;/* inode number */
@@ -384,7 +382,8 @@ struct f2fs_nat_entry { } __packed;struct f2fs_nat_block { -struct f2fs_nat_entry entries[NAT_ENTRY_PER_BLOCK ]; +/* The entry count depends on the filesystem block size. */ + DECLARE_FLEX_ARRAY(struct f2fs_nat_entry, entries); } __packed;/*
Signature · 1 line
2.53.0
PATCH v8 4/11 f2fs: describe orphan block layout dynamically
In reply to Kelvin ZhangAn on-disk orphan block contains a variable-length array of 32-bit inode numbers followed by a fixed footer at the end of the block. A compile-time whole-block structure cannot represent the footer position when the block size varies at runtime.
Remove struct f2fs_orphan_block, introduce
struct f2fs_orphan_block_footer, and compute sbi->orphans_per_block dynamically in init_sb_info(). Add helpers to access the inode entry array and footer from a block buffer.
Update orphan inode recovery, checkpointing, and mount paths to use the parameterized helpers. This preserves the on-disk format while decoupling orphan handling from compile-time constants.
--- fs/f2fs/checkpoint.c | 32 ++++++++++++++++++-------------- fs/f2fs/f2fs.h | 12 ++++++++++++ fs/f2fs/super.c | 2 ++ include/linux/f2fs_fs.h | 20 ++++++++++++++------ 4 files changed, 46 insertions(+), 20 deletions(-)
fs/f2fs/checkpoint.c +18 -14
@@ -1042,6 +1042,7 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi)for (i =0 ; i < orphan_blocks; i++) {struct folio *folio;struct f2fs_orphan_block *orphan_blk; +struct f2fs_orphan_footer *footer;unsigned int entry_count; folio =f2fs_get_meta_folio (sbi, start_blk + i);
@@ -1051,8 +1052,9 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi) } orphan_blk =folio_address (folio); - entry_count =le32_to_cpu (orphan_blk->entry_count); -if (entry_count >F2FS_ORPHANS_PER_BLOCK ) { + footer =f2fs_orphan_footer (orphan_blk, sbi); + entry_count =le32_to_cpu (footer->entry_count); +if (entry_count >F2FS_ORPHANS_PER_BLOCK (sbi)) {f2fs_err (sbi,"invalid orphan inode entry count %u" , entry_count);set_sbi_flag (sbi,SBI_NEED_FSCK );
@@ -1085,6 +1087,7 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk) {struct list_head *head;struct f2fs_orphan_block *orphan_blk =NULL ; +struct f2fs_orphan_footer *footer =NULL ;unsigned int nentries =0 ;unsigned short index =1 ;unsigned short orphan_blocks;
@@ -1092,7 +1095,7 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)struct ino_entry *orphan =NULL ;struct inode_management *im = &sbi->im[ORPHAN_INO ]; - orphan_blocks =GET_ORPHAN_BLOCKS (im->ino_num); + orphan_blocks =GET_ORPHAN_BLOCKS (sbi, im->ino_num);/* * we don't need to do spin_lock(&im->ino_lock) here, since all the
@@ -1106,20 +1109,21 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)if (!folio) { folio =f2fs_grab_meta_folio (sbi, start_blk++); orphan_blk =folio_address (folio); -memset (orphan_blk,0 ,sizeof (*orphan_blk)); + footer =f2fs_orphan_footer (orphan_blk, sbi); +memset (orphan_blk,0 , sbi->blocksize); } orphan_blk->ino[nentries++] =cpu_to_le32 (orphan->ino); -if (nentries ==F2FS_ORPHANS_PER_BLOCK ) { +if (nentries ==F2FS_ORPHANS_PER_BLOCK (sbi)) {/* -* an orphan block is full of 1020 entries, +* an orphan block is full, * then we need to flush current orphan blocks * and bring another one in memory */ - orphan_blk->blk_addr =cpu_to_le16 (index); - orphan_blk->blk_count =cpu_to_le16 (orphan_blocks); - orphan_blk->entry_count =cpu_to_le32 (nentries); + footer->blk_addr =cpu_to_le16 (index); + footer->blk_count =cpu_to_le16 (orphan_blocks); + footer->entry_count =cpu_to_le32 (nentries);folio_mark_dirty (folio);f2fs_folio_put (folio, true); index++;
@@ -1129,9 +1133,9 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk) }if (folio) { - orphan_blk->blk_addr =cpu_to_le16 (index); - orphan_blk->blk_count =cpu_to_le16 (orphan_blocks); - orphan_blk->entry_count =cpu_to_le32 (nentries); + footer->blk_addr =cpu_to_le16 (index); + footer->blk_count =cpu_to_le16 (orphan_blocks); + footer->entry_count =cpu_to_le32 (nentries);folio_mark_dirty (folio);f2fs_folio_put (folio, true); }
@@ -1824,7 +1828,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)__clear_ckpt_flags (ckpt,CP_COMPACT_SUM_FLAG );spin_unlock_irqrestore (&sbi->cp_lock, flags); - orphan_blocks =GET_ORPHAN_BLOCKS (orphan_num); + orphan_blocks =GET_ORPHAN_BLOCKS (sbi, orphan_num); ckpt->cp_pack_start_sum =cpu_to_le32 (1 + cp_payload_blks + orphan_blocks);
@@ -2080,7 +2084,7 @@ void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi) sbi->max_orphans = (BLKS_PER_SEG (sbi) -F2FS_CP_PACKS -NR_CURSEG_PERSIST_TYPE -__cp_payload (sbi)) * -F2FS_ORPHANS_PER_BLOCK ; +F2FS_ORPHANS_PER_BLOCK (sbi); }int __init f2fs_create_checkpoint_caches (void )
fs/f2fs/f2fs.h +12 -0
@@ -1865,6 +1865,7 @@ struct f2fs_sb_info {unsigned int blocksize;/* block size */ unsigned int nat_entries_per_block;/* NAT entries in a block */ unsigned int sit_entries_per_block;/* SIT entries in a block */ +unsigned int orphans_per_block;/* orphan inodes in a block */ unsigned int root_ino_num;/* root inode number*/ unsigned int node_ino_num;/* node inode number*/ unsigned int meta_ino_num;/* meta inode number*/
@@ -2255,6 +2256,17 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const struct folio *folio)#define SIT_ENTRY_PER_BLOCK (sbi) ((sbi)->sit_entries_per_block)#define NAT_ENTRY_PER_BLOCK (sbi) ((sbi)->nat_entries_per_block) +#define F2FS_ORPHANS_PER_BLOCK (sbi) ((sbi)->orphans_per_block) +#define GET_ORPHAN_BLOCKS (sbi, n) DIV_ROUND_UP((n), \ + F2FS_ORPHANS_PER_BLOCK(sbi)) + +static inline struct f2fs_orphan_footer * +f2fs_orphan_footer (void *orphan_block,struct f2fs_sb_info *sbi) +{ +return (struct f2fs_orphan_footer *) + ((char *)orphan_block + sbi->blocksize - +sizeof (struct f2fs_orphan_footer )); +}static inline struct f2fs_super_block *F2FS_RAW_SUPER (struct f2fs_sb_info *sbi) {
fs/f2fs/super.c +2 -0
@@ -4386,6 +4386,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi)sizeof (struct f2fs_nat_entry ); sbi->sit_entries_per_block = sbi->blocksize /sizeof (struct f2fs_sit_entry ); + sbi->orphans_per_block = (sbi->blocksize - +sizeof (struct f2fs_orphan_footer )) /sizeof (__le32); sbi->log_blocks_per_seg =le32_to_cpu (raw_super->log_blocks_per_seg); sbi->blocks_per_seg =BIT (sbi->log_blocks_per_seg); sbi->segs_per_sec =le32_to_cpu (raw_super->segs_per_sec);
include/linux/f2fs_fs.h +14 -6
@@ -220,14 +220,22 @@ struct f2fs_checkpoint {/* * For orphan inode management +* +* The number of inode entries in an orphan block depends on the filesystem +* block size. Its exact on-disk layout is: +* +* 0 blocksize - 16 blocksize +* +--------------------------+--------------------------+ +* | ino[0] ... ino[n - 1] | struct f2fs_orphan_footer | +* +--------------------------+--------------------------+ +* +* n = (blocksize - sizeof(struct f2fs_orphan_footer)) / sizeof(__le32) */ -#define F2FS_ORPHANS_PER_BLOCK ((F2FS_BLKSIZE - 4 * sizeof(__le32)) / sizeof(__le32)) - -#define GET_ORPHAN_BLOCKS (n) (((n) + F2FS_ORPHANS_PER_BLOCK - 1) / \ - F2FS_ORPHANS_PER_BLOCK) -struct f2fs_orphan_block { -__le32 ino[F2FS_ORPHANS_PER_BLOCK ];/* inode numbers */ + DECLARE_FLEX_ARRAY(__le32, ino); +} __packed; + +struct f2fs_orphan_footer {__le32 reserved;/* reserved */ __le16 blk_addr;/* block index in current CP */ __le16 blk_count;/* Number of orphan inode blocks in CP */
Signature · 1 line
2.53.0
PATCH v8 5/11 f2fs: describe dentry block layout dynamically
In reply to Kelvin ZhangAn on-disk directory block contains a bitmap, reserved padding, an array of directory entries (struct f2fs_dir_entry), and matching filename slots. A fixed compile-time structure couples their offsets to 4KB blocks and relies on static reserved-space definitions.
Remove struct f2fs_dentry_block and compute region offsets (bitmap bytes, directory-entry count, and filename slots) dynamically from the filesystem block size. Access directory blocks through struct f2fs_dentry_ptr views initialized with the runtime geometry.
Update directory operations, inline dentry handling, and recovery paths to use the dynamic block layout. No functional change is introduced for 4KB blocks.
--- fs/f2fs/dir.c | 51 +++++++++++++++++++++-------------------- fs/f2fs/f2fs.h | 31 ++++++++++++++++--------- fs/f2fs/inline.c | 2 +- fs/f2fs/super.c | 6 +++++ include/linux/f2fs_fs.h | 31 ++++++++++++------------- 5 files changed, 68 insertions(+), 53 deletions(-)
fs/f2fs/dir.c +26 -25
@@ -195,7 +195,7 @@ static struct f2fs_dir_entry *find_in_block(struct inode *dir,int *max_slots, bool use_hash) { -struct f2fs_dentry_block *dentry_blk; + void *dentry_blk;struct f2fs_dentry_ptr d; dentry_blk =folio_address (dentry_folio);
@@ -518,7 +518,7 @@ static int make_empty_dir(struct inode *inode, struct inode *parent, struct folio *folio) { struct folio *dentry_folio; -struct f2fs_dentry_block *dentry_blk; +void *dentry_blk;struct f2fs_dentry_ptr d;if (f2fs_has_inline_dentry (inode))
@@ -530,7 +530,7 @@ static int make_empty_dir(struct inode *inode, dentry_blk =folio_address (dentry_folio); -make_dentry_ptr_block (NULL , &d, dentry_blk); +make_dentry_ptr_block (inode, &d, dentry_blk);f2fs_do_make_empty_dir (inode, parent, &d);folio_mark_dirty (dentry_folio);
@@ -690,7 +690,7 @@ int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname,unsigned long bidx, block;unsigned int nbucket, nblock;struct folio *dentry_folio =NULL ; -struct f2fs_dentry_block *dentry_blk =NULL ; +void *dentry_blk =NULL ;struct f2fs_dentry_ptr d;struct folio *folio =NULL ;int slots, err =0 ;
@@ -727,9 +727,9 @@ int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname,return PTR_ERR (dentry_folio); dentry_blk =folio_address (dentry_folio); - bit_pos =f2fs_room_for_filename (&dentry_blk->dentry_bitmap, - slots,NR_DENTRY_IN_BLOCK ); -if (bit_pos <NR_DENTRY_IN_BLOCK ) +make_dentry_ptr_block (dir, &d, dentry_blk); + bit_pos =f2fs_room_for_filename (d.bitmap, slots, d.max); +if (bit_pos < d.max) goto add_dentry;f2fs_folio_put (dentry_folio, true);
@@ -750,7 +750,6 @@ int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname, } } -make_dentry_ptr_block (NULL , &d, dentry_blk);f2fs_update_dentry (ino, mode, &d, &fname->disk_name, fname->hash, bit_pos);
@@ -887,7 +886,8 @@ void f2fs_drop_nlink(struct inode *dir, struct inode *inode)void f2fs_delete_entry (struct f2fs_dir_entry *dentry,struct folio *folio,struct inode *dir,struct inode *inode) { -struct f2fs_dentry_block *dentry_blk; +void *dentry_blk; +struct f2fs_dentry_ptr d;unsigned int bit_pos;int slots =GET_DENTRY_SLOTS (le16_to_cpu (dentry->name_len));pgoff_t index = folio->index;
@@ -905,18 +905,17 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct folio *folio,f2fs_folio_wait_writeback (folio,DATA , true, true); dentry_blk =folio_address (folio); - bit_pos = dentry - dentry_blk->dentry; +make_dentry_ptr_block (dir, &d, dentry_blk); + bit_pos = dentry - d.dentry;for (i =0 ; i < slots; i++) -__clear_bit_le (bit_pos + i, &dentry_blk->dentry_bitmap); +__clear_bit_le (bit_pos + i, d.bitmap);/* Let's check and deallocate this dentry page */ - bit_pos =find_next_bit_le (&dentry_blk->dentry_bitmap, -NR_DENTRY_IN_BLOCK , -0 ); + bit_pos =find_next_bit_le (d.bitmap, d.max,0 );folio_mark_dirty (folio); -if (bit_pos ==NR_DENTRY_IN_BLOCK && - !f2fs_truncate_hole (dir, index, index +1 )) { +if (bit_pos == d.max && + !f2fs_truncate_hole (dir, index, index +1 )) {f2fs_clear_page_cache_dirty_tag (folio);folio_clear_dirty_for_io (folio);folio_clear_uptodate (folio);
@@ -938,7 +937,8 @@ bool f2fs_empty_dir(struct inode *dir) {unsigned long bidx =0 ;unsigned int bit_pos; -struct f2fs_dentry_block *dentry_blk; +void *dentry_blk; +struct f2fs_dentry_ptr d;unsigned long nblock =dir_blocks (dir);if (f2fs_has_inline_dentry (dir))
@@ -959,17 +959,16 @@ bool f2fs_empty_dir(struct inode *dir) } dentry_blk =folio_address (dentry_folio); +make_dentry_ptr_block (dir, &d, dentry_blk);if (bidx ==0 ) bit_pos =2 ;else bit_pos =0 ; - bit_pos =find_next_bit_le (&dentry_blk->dentry_bitmap, -NR_DENTRY_IN_BLOCK , - bit_pos); + bit_pos =find_next_bit_le (d.bitmap, d.max, bit_pos);f2fs_folio_put (dentry_folio, false); -if (bit_pos <NR_DENTRY_IN_BLOCK ) +if (bit_pos < d.max)return false; bidx++;
@@ -1066,10 +1065,12 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx) {struct inode *inode =file_inode (file);unsigned long npages =dir_blocks (inode); -struct f2fs_dentry_block *dentry_blk =NULL ; +void *dentry_blk =NULL ;struct file_ra_state *ra = &file->f_ra;loff_t start_pos = ctx->pos; -unsigned int n = ((unsigned long )ctx->pos /NR_DENTRY_IN_BLOCK ); +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); +unsigned int entries = sbi->dentries_per_block; +unsigned int n = (unsigned long )ctx->pos / entries;struct f2fs_dentry_ptr d;struct fscrypt_str fstr =FSTR_INIT (NULL ,0 );int err =0 ;
@@ -1089,7 +1090,7 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx) goto out_free; } -for (; n < npages; ctx->pos = n *NR_DENTRY_IN_BLOCK ) { +for (; n < npages; ctx->pos = n * entries) {struct folio *dentry_folio;pgoff_t next_pgofs;
@@ -1122,7 +1123,7 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)make_dentry_ptr_block (inode, &d, dentry_blk); err =f2fs_fill_dentries (ctx, &d, - n *NR_DENTRY_IN_BLOCK , &fstr); + n * entries, &fstr);f2fs_folio_put (dentry_folio, false);if (err)break ;
fs/f2fs/f2fs.h +20 -11
@@ -669,17 +669,6 @@ struct f2fs_dentry_ptr {int nr_bitmap; }; -static inline void make_dentry_ptr_block (struct inode *inode, -struct f2fs_dentry_ptr *d,struct f2fs_dentry_block *t) -{ - d->inode = inode; - d->max =NR_DENTRY_IN_BLOCK ; - d->nr_bitmap =SIZE_OF_DENTRY_BITMAP ; - d->bitmap = t->dentry_bitmap; - d->dentry = t->dentry; - d->filename = t->filename; -} -static inline void make_dentry_ptr_inline (struct inode *inode,struct f2fs_dentry_ptr *d,void *t) {
@@ -1866,6 +1855,9 @@ struct f2fs_sb_info {unsigned int nat_entries_per_block;/* NAT entries in a block */ unsigned int sit_entries_per_block;/* SIT entries in a block */ unsigned int orphans_per_block;/* orphan inodes in a block */ +unsigned int dentries_per_block;/* dentries in a block */ +unsigned int dentry_bitmap_size;/* dentry bitmap size in bytes */ +unsigned int dentry_reserved_size;/* dentry reserved bytes */ unsigned int root_ino_num;/* root inode number*/ unsigned int node_ino_num;/* node inode number*/ unsigned int meta_ino_num;/* meta inode number*/
@@ -2268,6 +2260,23 @@ f2fs_orphan_footer(void *orphan_block, struct f2fs_sb_info *sbi) sizeof(struct f2fs_orphan_footer)); } +static inline void make_dentry_ptr_block (struct inode *inode, +struct f2fs_dentry_ptr *d,void *t) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); +unsigned int entries = sbi->dentries_per_block; +unsigned int bitmap_size = sbi->dentry_bitmap_size; +unsigned int reserved_size = sbi->dentry_reserved_size; + + d->inode = inode; + d->max = entries; + d->nr_bitmap = bitmap_size; + d->bitmap = t; + d->dentry = t + bitmap_size + reserved_size; + d->filename = t + bitmap_size + reserved_size + +SIZE_OF_DIR_ENTRY * entries; +} +static inline struct f2fs_super_block *F2FS_RAW_SUPER (struct f2fs_sb_info *sbi) {return (struct f2fs_super_block *)(sbi->raw_super);
fs/f2fs/inline.c +1 -1
@@ -415,7 +415,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio, {struct folio *folio;struct dnode_of_data dn; -struct f2fs_dentry_block *dentry_blk; +void *dentry_blk;struct f2fs_dentry_ptr src, dst;int err;
fs/f2fs/super.c +6 -0
@@ -4388,6 +4388,12 @@ static void init_sb_info(struct f2fs_sb_info *sbi)sizeof (struct f2fs_sit_entry ); sbi->orphans_per_block = (sbi->blocksize -sizeof (struct f2fs_orphan_footer )) /sizeof (__le32); + sbi->dentries_per_block = (BITS_PER_BYTE * sbi->blocksize) / + ((SIZE_OF_DIR_ENTRY +F2FS_SLOT_LEN ) *BITS_PER_BYTE +1 ); + sbi->dentry_bitmap_size =DIV_ROUND_UP (sbi->dentries_per_block, +BITS_PER_BYTE ); + sbi->dentry_reserved_size = sbi->blocksize - sbi->dentry_bitmap_size - + (SIZE_OF_DIR_ENTRY +F2FS_SLOT_LEN ) * sbi->dentries_per_block; sbi->log_blocks_per_seg =le32_to_cpu (raw_super->log_blocks_per_seg); sbi->blocks_per_seg =BIT (sbi->log_blocks_per_seg); sbi->segs_per_sec =le32_to_cpu (raw_super->segs_per_sec);
include/linux/f2fs_fs.h +15 -16
@@ -605,15 +605,7 @@ typedef __le32 f2fs_hash_t;* dentry, when converting inline dentry we should handle this carefully. */ -/* the number of dentry in a block */ -#define NR_DENTRY_IN_BLOCK ((BITS_PER_BYTE * F2FS_BLKSIZE) / \ - ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * BITS_PER_BYTE + 1))#define SIZE_OF_DIR_ENTRY 11/* by byte */ -#define SIZE_OF_DENTRY_BITMAP ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \ - BITS_PER_BYTE) -#define SIZE_OF_RESERVED (F2FS_BLKSIZE - ((SIZE_OF_DIR_ENTRY + \ - F2FS_SLOT_LEN) * \ - NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP))#define MIN_INLINE_DENTRY_SIZE 40/* just include '.' and '..' entries */ /* One directory entry slot representing F2FS_SLOT_LEN-sized file name */
@@ -624,14 +616,21 @@ struct f2fs_dir_entry {__u8 file_type;/* file type */ } __packed; -/* Block-sized directory entry block */ -struct f2fs_dentry_block { -/* validity bitmap for directory entries in each block */ -__u8 dentry_bitmap[SIZE_OF_DENTRY_BITMAP ]; -__u8 reserved[SIZE_OF_RESERVED ]; -struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK ]; -__u8 filename[NR_DENTRY_IN_BLOCK ][F2FS_SLOT_LEN ]; -} __packed; +/* +* A dentry block is laid out as follows, where the number of entries and all +* offsets are determined by the filesystem block size at runtime: +* +* 0 blocksize +* +--------+----------+-------------------+-----------------------+ +* | bitmap | reserved | dir_entry[entries]| filename[entries][8] | +* +--------+----------+-------------------+-----------------------+ +* +* entries = (BITS_PER_BYTE * blocksize) / +* ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * BITS_PER_BYTE + 1) +* bitmap_size = DIV_ROUND_UP(entries, BITS_PER_BYTE) +* reserved_size = blocksize - bitmap_size - +* (SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * entries +*/ #define F2FS_DEF_PROJID 0/* default project ID */
Signature · 1 line
2.53.0
PATCH v8 6/11 f2fs: describe {i,d,id}node block layout dynamically
In reply to Kelvin ZhangAn inode block ends with five i_nid entries followed by a node footer. Data block address pointers (i_addr[]) precede them. Similarly, direct and indirect node blocks contain data addresses or node IDs followed by a node footer at the end of the block.
Describe struct f2fs_inode, struct direct_node, and
struct indirect_node using flexible array members. Compute the locations of i_nid and node footers dynamically from the filesystem block size. Introduce F2FS_INODE_NIDS() and F2FS_NODE_FOOTER() helpers to access these tail fields.
Compute sbi->addrs_per_inode, sbi->addrs_per_block, and sbi->nids_per_block in init_sb_info(), and update node management, file mapping, and recovery paths accordingly.
--- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 42 ++++++++++++++++++++++++-------- fs/f2fs/gc.c | 2 +- fs/f2fs/inline.c | 3 +-- fs/f2fs/inode.c | 5 ++-- fs/f2fs/node.c | 4 +--- fs/f2fs/node.h | 53 +++++++++++++++++++---------------------- fs/f2fs/super.c | 4 ++++ fs/f2fs/xattr.h | 2 +- include/linux/f2fs_fs.h | 44 +++++++++++++++++++++------------- 10 files changed, 95 insertions(+), 66 deletions(-)
fs/f2fs/data.c +1 -1
@@ -2027,7 +2027,7 @@ static int f2fs_xattr_fiemap(struct inode *inode, phys =F2FS_BLK_TO_BYTES (ni.blk_addr); offset = offsetof(struct f2fs_inode , i_addr) + -sizeof (__le32) * (DEF_ADDRS_PER_INODE - +sizeof (__le32) * (DEF_ADDRS_PER_INODE (sbi) -get_inline_xattr_addrs (inode)); phys += offset;
fs/f2fs/f2fs.h +32 -10
112 lines not on this page · raw message
fs/f2fs/gc.c +1 -1
@@ -1176,7 +1176,7 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,if (IS_INODE (node_folio)) { base =offset_in_addr (F2FS_INODE (node_folio)); - max_addrs =DEF_ADDRS_PER_INODE ; + max_addrs =DEF_ADDRS_PER_INODE (sbi); }else { base =0 ; max_addrs =DEF_ADDRS_PER_BLOCK ;
fs/f2fs/inline.c +1 -2
@@ -36,14 +36,13 @@ bool f2fs_may_inline_data(struct inode *inode)static bool inode_has_blocks (struct inode *inode,struct folio *ifolio) { -struct f2fs_inode *ri =F2FS_INODE (ifolio);int i;if (F2FS_HAS_BLOCKS (inode))return true;for (i =0 ; i <DEF_NIDS_PER_INODE ; i++) { -if (ri->i_nid[i]) +if (F2FS_INODE_NIDS (ifolio)[i])return true; }return false;
fs/f2fs/inode.c +2 -3
@@ -150,9 +150,8 @@ bool f2fs_enable_inode_chksum(struct f2fs_sb_info *sbi, struct folio *folio)static __u32 f2fs_inode_chksum (struct f2fs_sb_info *sbi,struct folio *folio) { -struct f2fs_node *node =F2FS_NODE (folio); -struct f2fs_inode *ri = &node->i; -__le32 ino = node->footer.ino; +struct f2fs_inode *ri =F2FS_INODE (folio); +__le32 ino =F2FS_NODE_FOOTER (folio)->ino;__le32 gen = ri->i_generation;__u32 chksum, chksum_seed;__u32 dummy_cs =0 ;
fs/f2fs/node.c +1 -3
@@ -3001,7 +3001,6 @@ int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct folio *folio)int f2fs_restore_node_summary (struct f2fs_sb_info *sbi,unsigned int segno,struct f2fs_summary_block *sum) { -struct f2fs_node *rn;struct f2fs_summary *sum_entry;block_t addr;int i, idx, last_offset, nrpages;
@@ -3023,8 +3022,7 @@ int f2fs_restore_node_summary(struct f2fs_sb_info *sbi,if (IS_ERR (folio))return PTR_ERR (folio); - rn =F2FS_NODE (folio); - sum_entry->nid = rn->footer.nid; + sum_entry->nid =F2FS_NODE_FOOTER (folio)->nid; sum_entry->version =0 ; sum_entry->ofs_in_node =0 ; sum_entry++;
fs/f2fs/node.h +24 -29
139 lines not on this page · raw message
fs/f2fs/super.c +4 -0
@@ -4384,6 +4384,10 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sbi->blocksize =BIT (sbi->log_blocksize); sbi->nat_entries_per_block = sbi->blocksize /sizeof (struct f2fs_nat_entry ); + sbi->addrs_per_inode =F2FS_DEF_ADDRS_PER_INODE (sbi->blocksize); + sbi->addrs_per_block = (sbi->blocksize - +sizeof (struct node_footer )) /sizeof (__le32); + sbi->nids_per_block = sbi->addrs_per_block; sbi->sit_entries_per_block = sbi->blocksize /sizeof (struct f2fs_sit_entry ); sbi->orphans_per_block = (sbi->blocksize -
fs/f2fs/xattr.h +1 -1
@@ -85,7 +85,7 @@ struct f2fs_xattr_entry {#define MIN_INLINE_XATTR_SIZE (sizeof(struct f2fs_xattr_header) / sizeof(__le32))#define MAX_INLINE_XATTR_SIZE \ - (DEF_ADDRS_PER_INODE - \ + (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) - \ F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \ DEF_INLINE_RESERVED_SIZE - \ MIN_INLINE_DENTRY_SIZE / sizeof(__le32))
include/linux/f2fs_fs.h +28 -16
75 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v8 7/11 f2fs: describe xattr block layout dynamically
In reply to Kelvin ZhangThe usable capacity of dedicated on-disk extended attribute blocks and inline xattr regions scales with the filesystem block size.
Parameterize VALID_XATTR_BLOCK_SIZE and MAX_INLINE_XATTR_SIZE to calculate usable xattr limits dynamically from sbi->blocksize rather than hardcoding PAGE_SIZE or DEF_ADDRS_PER_INODE.
Update mount option consistency validation for inline_xattr_size to evaluate allowed boundaries dynamically against the runtime block size.
--- fs/f2fs/inode.c | 7 ++++--- fs/f2fs/node.c | 2 +- fs/f2fs/super.c | 17 +++++++++++++++-- fs/f2fs/xattr.c | 8 +++++--- fs/f2fs/xattr.h | 11 ++++++----- include/linux/f2fs_fs.h | 3 +++ 6 files changed, 34 insertions(+), 14 deletions(-)
fs/f2fs/inode.c +4 -3
@@ -337,12 +337,13 @@ static bool sanity_check_inode(struct inode *inode, struct folio *node_folio) }if (f2fs_sb_has_flexible_inline_xattr (sbi) && - (fi->i_inline_xattr_size >MAX_INLINE_XATTR_SIZE || + (fi->i_inline_xattr_size >MAX_INLINE_XATTR_SIZE (i_blocksize (inode)) || (f2fs_has_inline_xattr (inode) && fi->i_inline_xattr_size <MIN_INLINE_XATTR_SIZE ))) { -f2fs_warn (sbi,"%s: inode (ino=%llx) has corrupted i_inline_xattr_size: %d, min: %zu, max: %lu" , +f2fs_warn (sbi,"%s: inode (ino=%llx) has corrupted i_inline_xattr_size: %d, min: %zu, max: %zu" , __func__, inode->i_ino, fi->i_inline_xattr_size, -MIN_INLINE_XATTR_SIZE ,MAX_INLINE_XATTR_SIZE ); +MIN_INLINE_XATTR_SIZE , + (size_t )MAX_INLINE_XATTR_SIZE (i_blocksize (inode)));return false; }
fs/f2fs/node.c +1 -1
@@ -2919,7 +2919,7 @@ int f2fs_recover_xattr_data(struct inode *inode, struct folio *folio)/* 3: update and set xattr node page dirty */ if (folio) {memcpy (F2FS_NODE (xfolio),F2FS_NODE (folio), -VALID_XATTR_BLOCK_SIZE ); +VALID_XATTR_BLOCK_SIZE (inode));folio_mark_dirty (xfolio); }f2fs_folio_put (xfolio, true);
fs/f2fs/super.c +15 -2
@@ -855,9 +855,11 @@ static int f2fs_parse_param(struct fs_context *fc, struct fs_parameter *param)break ;case Opt_inline_xattr_size:if (result.int_32 <MIN_INLINE_XATTR_SIZE || - result.int_32 >MAX_INLINE_XATTR_SIZE ) { + result.int_32 > +MAX_INLINE_XATTR_SIZE (F2FS_MAX_BLKSIZE )) {f2fs_err (NULL ,"inline xattr size is out of range: %u ~ %u" , - (u32 )MIN_INLINE_XATTR_SIZE , (u32 )MAX_INLINE_XATTR_SIZE ); + (u32 )MIN_INLINE_XATTR_SIZE , + (u32 )MAX_INLINE_XATTR_SIZE (F2FS_MAX_BLKSIZE ));return -EINVAL ; }ctx_set_opt (ctx,F2FS_MOUNT_INLINE_XATTR_SIZE );
@@ -1596,6 +1598,8 @@ static int f2fs_check_opt_consistency(struct fs_context *fc, }if (ctx_test_opt (ctx,F2FS_MOUNT_INLINE_XATTR_SIZE )) { +int min_size, max_size; +if (!f2fs_sb_has_extra_attr (sbi) || !f2fs_sb_has_flexible_inline_xattr (sbi)) {f2fs_err (sbi,"extra_attr or flexible_inline_xattr feature is off" );
@@ -1605,6 +1609,15 @@ static int f2fs_check_opt_consistency(struct fs_context *fc,f2fs_err (sbi,"inline_xattr_size option should be set with inline_xattr option" );return -EINVAL ; } + min_size =MIN_INLINE_XATTR_SIZE ; + max_size =MAX_INLINE_XATTR_SIZE (sbi->blocksize); + +if (F2FS_OPTION (sbi).inline_xattr_size < min_size || +F2FS_OPTION (sbi).inline_xattr_size > max_size) { +f2fs_err (sbi,"inline xattr size is out of range: %d ~ %d" , + min_size, max_size); +return -EINVAL ; + } } if (ctx_test_opt(ctx, F2FS_MOUNT_ATGC) &&
fs/f2fs/xattr.c +5 -3
@@ -310,7 +310,8 @@ static int read_xattr_block(struct inode *inode, void *txattr_addr)return PTR_ERR (xfolio); xattr_addr =folio_address (xfolio); -memcpy (txattr_addr + inline_size, xattr_addr,VALID_XATTR_BLOCK_SIZE ); +memcpy (txattr_addr + inline_size, xattr_addr, +VALID_XATTR_BLOCK_SIZE (inode));f2fs_folio_put (xfolio, true);return 0 ;
@@ -393,7 +394,7 @@ static int read_all_xattrs(struct inode *inode, struct folio *ifolio, {struct f2fs_xattr_header *header;nid_t xnid =F2FS_I (inode)->i_xattr_nid; -unsigned int size =VALID_XATTR_BLOCK_SIZE ; +unsigned int size =VALID_XATTR_BLOCK_SIZE (inode);unsigned int inline_size =inline_xattr_size (inode);void *txattr_addr;int err;
@@ -502,7 +503,8 @@ static inline int write_all_xattrs(struct inode *inode, __u32 hsize,if (inline_size)memcpy (inline_addr, txattr_addr, inline_size); -memcpy (xattr_addr, txattr_addr + inline_size,VALID_XATTR_BLOCK_SIZE ); +memcpy (xattr_addr, txattr_addr + inline_size, +VALID_XATTR_BLOCK_SIZE (inode));if (inline_size)folio_mark_dirty (ifolio ? ifolio : in_folio);
fs/f2fs/xattr.h +6 -5
@@ -71,21 +71,22 @@ struct f2fs_xattr_entry {for (entry =XATTR_FIRST_ENTRY (addr);\ !IS_XATTR_LAST_ENTRY (entry);\ entry = XATTR_NEXT_ENTRY(entry)) -#define VALID_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer)) +#define VALID_XATTR_BLOCK_SIZE (i) (i_blocksize(i) - \ + sizeof(struct node_footer))#define XATTR_PADDING_SIZE (sizeof(__u32))#define XATTR_SIZE (i) ((F2FS_I(i)->i_xattr_nid ? \ - VALID_XATTR_BLOCK_SIZE : 0) + \ + VALID_XATTR_BLOCK_SIZE(i) : 0) + \ (inline_xattr_size(i)))#define MIN_OFFSET (i) XATTR_ALIGN(inline_xattr_size(i) + \ - VALID_XATTR_BLOCK_SIZE) + VALID_XATTR_BLOCK_SIZE(i))#define MAX_VALUE_LEN (i) (MIN_OFFSET(i) - \ sizeof(struct f2fs_xattr_header) - \ sizeof(struct f2fs_xattr_entry))#define MIN_INLINE_XATTR_SIZE (sizeof(struct f2fs_xattr_header) / sizeof(__le32)) -#define MAX_INLINE_XATTR_SIZE \ - (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) - \ +#define MAX_INLINE_XATTR_SIZE (blocksize) \ + (F2FS_DEF_ADDRS_PER_INODE(blocksize) - \ F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \ DEF_INLINE_RESERVED_SIZE - \ MIN_INLINE_DENTRY_SIZE / sizeof(__le32))
include/linux/f2fs_fs.h +3 -0
@@ -15,7 +15,10 @@#define F2FS_MIN_LOG_SECTOR_SIZE 9/* 9 bits for 512 bytes */ #define F2FS_MAX_LOG_SECTOR_SIZE PAGE_SHIFT/* Max is Block Size */ #define F2FS_LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9)/* log number for sector/blk */ +#define F2FS_MIN_LOG_BLOCKSIZE 12 +#define F2FS_MIN_BLKSIZE 4096UL#define F2FS_BLKSIZE PAGE_SIZE/* support only block == page */ +#define F2FS_MAX_BLKSIZE PAGE_SIZE#define F2FS_BLKSIZE_BITS PAGE_SHIFT/* bits for F2FS_BLKSIZE */ #define F2FS_MAX_EXTENSION 64/* # of extension entries */ #define F2FS_EXTENSION_LEN 8/* max size of extension */
Signature · 1 line
2.53.0
PATCH v8 8/11 f2fs: parameterize sector conversion macros
In reply to Kelvin ZhangSector-to-block and block-to-sector conversion helpers previously assumed a fixed sector count per block derived from 4KB pages.
Parameterize F2FS_LOG_SECTORS_PER_BLOCK, SECTOR_FROM_BLOCK, and SECTOR_TO_BLOCK with struct f2fs_sb_info *sbi, using sbi->log_sectors_per_block.
Update all call sites across metadata I/O, data mapping, discard operations, and zoned block device reporting.
--- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 5 +++-- fs/f2fs/file.c | 4 ++-- fs/f2fs/inode.c | 11 +++++++---- fs/f2fs/segment.c | 14 +++++++------- fs/f2fs/segment.h | 8 ++++---- fs/f2fs/super.c | 10 +++++----- include/linux/f2fs_fs.h | 2 +- 8 files changed, 30 insertions(+), 26 deletions(-)
fs/f2fs/data.c +1 -1
@@ -466,7 +466,7 @@ struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, }if (sector) - *sector =SECTOR_FROM_BLOCK (blk_addr); + *sector =SECTOR_FROM_BLOCK (sbi, blk_addr);return bdev; }
fs/f2fs/f2fs.h +3 -2
@@ -2610,7 +2610,8 @@ static inline int F2FS_HAS_BLOCKS(struct inode *inode) {block_t xattr_block =F2FS_I (inode)->i_xattr_nid ?1 :0 ; -return (inode->i_blocks >>F2FS_LOG_SECTORS_PER_BLOCK ) > xattr_block; +return (inode->i_blocks >> +F2FS_LOG_SECTORS_PER_BLOCK (F2FS_I_SB (inode))) > xattr_block; }static inline bool f2fs_has_xattr_block (unsigned int ofs)
@@ -2816,7 +2817,7 @@ static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, struct inode *inode, block_t count) { -blkcnt_t sectors = count <<F2FS_LOG_SECTORS_PER_BLOCK ; +blkcnt_t sectors = count <<F2FS_LOG_SECTORS_PER_BLOCK (sbi);spin_lock (&sbi->stat_lock);if (unlikely (sbi->total_valid_block_count < count)) {
fs/f2fs/file.c +2 -2
@@ -4510,8 +4510,8 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)static int f2fs_secure_erase (struct block_device *bdev,struct inode *inode,pgoff_t off,block_t block,block_t len,u32 flags) { -sector_t sector =SECTOR_FROM_BLOCK (block); -sector_t nr_sects =SECTOR_FROM_BLOCK (len); +sector_t sector =SECTOR_FROM_BLOCK (F2FS_I_SB (inode), block); +sector_t nr_sects =SECTOR_FROM_BLOCK (F2FS_I_SB (inode), len);int ret =0 ;if (flags &F2FS_TRIM_FILE_DISCARD ) {
fs/f2fs/inode.c +7 -4
@@ -221,11 +221,11 @@ static bool sanity_check_compress_inode(struct inode *inode,return false; }if (le64_to_cpu (ri->i_compr_blocks) > -SECTOR_TO_BLOCK (inode->i_blocks)) { +SECTOR_TO_BLOCK (sbi, inode->i_blocks)) {f2fs_warn (sbi,"%s: inode (ino=%llx) has inconsistent i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix" , __func__, inode->i_ino,le64_to_cpu (ri->i_compr_blocks), -SECTOR_TO_BLOCK (inode->i_blocks)); +SECTOR_TO_BLOCK (sbi, inode->i_blocks));return false; } if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE ||
@@ -447,7 +447,8 @@ static int do_read_inode(struct inode *inode)i_gid_write (inode,le32_to_cpu (ri->i_gid));set_nlink (inode,le32_to_cpu (ri->i_links)); inode->i_size =le64_to_cpu (ri->i_size); - inode->i_blocks =SECTOR_FROM_BLOCK (le64_to_cpu (ri->i_blocks) -1 ); + inode->i_blocks =SECTOR_FROM_BLOCK (sbi, +le64_to_cpu (ri->i_blocks) -1 );inode_set_atime (inode,le64_to_cpu (ri->i_atime),le32_to_cpu (ri->i_atime_nsec));
@@ -696,6 +697,7 @@ struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino)void f2fs_update_inode (struct inode *inode,struct folio *node_folio) { +struct f2fs_sb_info *sbi =F2FS_I_SB (inode);struct f2fs_inode_info *fi =F2FS_I (inode);struct f2fs_inode *ri;struct extent_tree *et = fi->extent_tree[EX_READ ];
@@ -712,7 +714,8 @@ void f2fs_update_inode(struct inode *inode, struct folio *node_folio) ri->i_uid =cpu_to_le32 (i_uid_read (inode)); ri->i_gid =cpu_to_le32 (i_gid_read (inode)); ri->i_links =cpu_to_le32 (inode->i_nlink); - ri->i_blocks =cpu_to_le64 (SECTOR_TO_BLOCK (READ_ONCE (inode->i_blocks)) +1 ); + ri->i_blocks =cpu_to_le64 (SECTOR_TO_BLOCK (sbi, +READ_ONCE (inode->i_blocks)) +1 );if (!f2fs_is_atomic_file (inode) ||is_inode_flag_set (inode,FI_ATOMIC_COMMITTED ))
fs/f2fs/segment.c +7 -7
@@ -1310,7 +1310,7 @@ static void __submit_zone_reset_cmd(struct f2fs_sb_info *sbi,/* sanity check on discard range */ __check_sit_bitmap (sbi, dc->di.lstart, dc->di.lstart + dc->di.len); - bio->bi_iter.bi_sector =SECTOR_FROM_BLOCK (dc->di.start); + bio->bi_iter.bi_sector =SECTOR_FROM_BLOCK (sbi, dc->di.start); bio->bi_private = dc; bio->bi_end_io = f2fs_submit_discard_endio;submit_bio (bio);
@@ -1327,7 +1327,7 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi, {struct block_device *bdev = dc->bdev;unsigned int max_discard_blocks = -SECTOR_TO_BLOCK (bdev_max_discard_sectors (bdev)); +SECTOR_TO_BLOCK (sbi,bdev_max_discard_sectors (bdev));struct discard_cmd_control *dcc =SM_I (sbi)->dcc_info;struct list_head *wait_list = (dpolicy->type ==DPOLICY_FSTRIM ) ? &(dcc->fstrim_list) : &(dcc->wait_list);
@@ -1389,8 +1389,8 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi, dc->di.len += len; -__blkdev_issue_discard (bdev,SECTOR_FROM_BLOCK (start), -SECTOR_FROM_BLOCK (len),GFP_NOFS , &bio); +__blkdev_issue_discard (bdev,SECTOR_FROM_BLOCK (sbi, start), +SECTOR_FROM_BLOCK (sbi, len),GFP_NOFS , &bio);f2fs_bug_on (sbi, !bio);/*
@@ -1518,7 +1518,7 @@ static void __update_discard_tree_range(struct f2fs_sb_info *sbi,struct discard_info di = {0 };struct rb_node **insert_p =NULL , *insert_parent =NULL ;unsigned int max_discard_blocks = -SECTOR_TO_BLOCK (bdev_max_discard_sectors (bdev)); +SECTOR_TO_BLOCK (sbi,bdev_max_discard_sectors (bdev));block_t end = lstart + len; dc = __lookup_discard_cmd_ret(&dcc->root, lstart,
@@ -2041,8 +2041,8 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,/* For sequential zones, reset the zone write pointer */ if (f2fs_blkz_is_seq (sbi, devi, blkstart)) { - sector =SECTOR_FROM_BLOCK (blkstart); - nr_sects =SECTOR_FROM_BLOCK (blklen); + sector =SECTOR_FROM_BLOCK (sbi, blkstart); + nr_sects =SECTOR_FROM_BLOCK (sbi, blklen);div64_u64_rem (sector,bdev_zone_sectors (bdev), &remainder);if (remainder || nr_sects !=bdev_zone_sectors (bdev)) {
fs/f2fs/segment.h +4 -4
@@ -114,10 +114,10 @@ f2fs_start_segno(struct f2fs_sb_info *sbi, unsigned int segno)#define f2fs_bitmap_size (nr) \ (BITS_TO_LONGS(nr) * sizeof(unsigned long)) -#define SECTOR_FROM_BLOCK (blk_addr) \ - (((sector_t)blk_addr) << F2FS_LOG_SECTORS_PER_BLOCK) -#define SECTOR_TO_BLOCK (sectors) \ - ((sectors) >> F2FS_LOG_SECTORS_PER_BLOCK) +#define SECTOR_FROM_BLOCK (sbi, blk_addr) \ + (((sector_t)blk_addr) << F2FS_LOG_SECTORS_PER_BLOCK(sbi)) +#define SECTOR_TO_BLOCK (sbi, sectors) \ + ((sectors) >> F2FS_LOG_SECTORS_PER_BLOCK(sbi))/* * In the victim_sel_policy->alloc_mode, there are three block allocation modes.
fs/f2fs/super.c +5 -5
@@ -3944,7 +3944,7 @@ static int __f2fs_commit_super(struct f2fs_sb_info *sbi, struct folio *folio, bio =bio_alloc (sbi->sb->s_bdev,1 , opf,GFP_NOFS );/* it doesn't need to set crypto context for superblock update */ - bio->bi_iter.bi_sector =SECTOR_FROM_BLOCK (folio->index); + bio->bi_iter.bi_sector =SECTOR_FROM_BLOCK (sbi, folio->index);if (!bio_add_folio (bio, folio,folio_size (folio),0 ))f2fs_bug_on (sbi,1 );
@@ -4519,7 +4519,7 @@ static int f2fs_report_zone_cb(struct blk_zone *zone, unsigned int idx, {struct f2fs_report_zones_args *rz_args = data;block_t unusable_blocks = (zone->len - zone->capacity) >> -F2FS_LOG_SECTORS_PER_BLOCK ; +F2FS_LOG_SECTORS_PER_BLOCK (rz_args->sbi);if (zone->type ==BLK_ZONE_TYPE_CONVENTIONAL )return 0 ;
@@ -4562,10 +4562,10 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) zone_sectors =bdev_zone_sectors (bdev);if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != -SECTOR_TO_BLOCK (zone_sectors)) +SECTOR_TO_BLOCK (sbi, zone_sectors))return -EINVAL ; - sbi->blocks_per_blkz =SECTOR_TO_BLOCK (zone_sectors); -FDEV (devi).nr_blkz =div_u64 (SECTOR_TO_BLOCK (nr_sectors), + sbi->blocks_per_blkz =SECTOR_TO_BLOCK (sbi, zone_sectors); +FDEV (devi).nr_blkz =div_u64 (SECTOR_TO_BLOCK (sbi, nr_sectors), sbi->blocks_per_blkz);if (nr_sectors & (zone_sectors -1 ))FDEV (devi).nr_blkz++;
include/linux/f2fs_fs.h +1 -1
@@ -14,7 +14,7 @@#define F2FS_SUPER_OFFSET 1024/* byte-size offset */ #define F2FS_MIN_LOG_SECTOR_SIZE 9/* 9 bits for 512 bytes */ #define F2FS_MAX_LOG_SECTOR_SIZE PAGE_SHIFT/* Max is Block Size */ -#define F2FS_LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9)/* log number for sector/blk */ +#define F2FS_LOG_SECTORS_PER_BLOCK (sbi) ((sbi)->log_blocksize - 9)/* log number for sector/blk */ #define F2FS_MIN_LOG_BLOCKSIZE 12#define F2FS_MIN_BLKSIZE 4096UL#define F2FS_BLKSIZE PAGE_SIZE/* support only block == page */
Signature · 1 line
2.53.0
PATCH v8 9/11 f2fs: parameterize byte and block conversion macros
In reply to Kelvin ZhangByte-to-block and block-to-byte conversion helpers previously relied on global PAGE_SIZE, PAGE_SHIFT, or F2FS_BLKSIZE_BITS.
Parameterize F2FS_BYTES_TO_BLK, F2FS_BLK_TO_BYTES, F2FS_BLK_END_BYTES, F2FS_BLK_ALIGN, and max_file_blocks with struct f2fs_sb_info *sbi using sbi->log_blocksize.
Update all call sites across data mapping, file operations, fiemap queries, fsverity checks, NAT bitmap allocations, and truncate paths.
--- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/data.c | 58 +++++++++++++++++++++++------------------ fs/f2fs/debug.c | 2 +- fs/f2fs/f2fs.h | 7 ++--- fs/f2fs/file.c | 54 +++++++++++++++++++++----------------- fs/f2fs/node.c | 7 ++--- fs/f2fs/recovery.c | 4 +-- fs/f2fs/segment.c | 9 ++++--- fs/f2fs/super.c | 9 ++++--- fs/f2fs/verity.c | 6 +++-- include/linux/f2fs_fs.h | 13 ++++++--- 11 files changed, 97 insertions(+), 74 deletions(-)
fs/f2fs/checkpoint.c +1 -1
@@ -1866,7 +1866,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) blk = start_blk +BLKS_PER_SEG (sbi) - nm_i->nat_bits_blocks;for (i =0 ; i < nm_i->nat_bits_blocks; i++)f2fs_update_meta_page (sbi, nm_i->nat_bits + -F2FS_BLK_TO_BYTES (i), blk + i); +F2FS_BLK_TO_BYTES (sbi, i), blk + i); }/* write out checkpoint buffer at block 0 */
fs/f2fs/data.c +32 -26
185 lines not on this page · raw message
fs/f2fs/debug.c +1 -1
@@ -343,7 +343,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi)/* build nm */ si->base_mem +=sizeof (struct f2fs_nm_info ); si->base_mem +=__bitmap_size (sbi,NAT_BITMAP ); - si->base_mem +=F2FS_BLK_TO_BYTES (NM_I (sbi)->nat_bits_blocks); + si->base_mem +=F2FS_BLK_TO_BYTES (sbi,NM_I (sbi)->nat_bits_blocks); si->base_mem +=NM_I (sbi)->nat_blocks *f2fs_bitmap_size (NAT_ENTRY_PER_BLOCK (sbi)); si->base_mem +=NM_I (sbi)->nat_blocks /8 ;
fs/f2fs/f2fs.h +4 -3
@@ -4022,7 +4022,7 @@ void f2fs_inode_synced(struct inode *inode);int f2fs_dquot_initialize (struct inode *inode);int f2fs_enable_quota_files (struct f2fs_sb_info *sbi,bool rdonly);int f2fs_do_quota_sync (struct super_block *sb,int type); -loff_t max_file_blocks (struct inode *inode); +loff_t max_file_blocks (struct f2fs_sb_info *sbi,struct inode *inode);void f2fs_quota_off_umount (struct super_block *sb);void f2fs_save_errors (struct f2fs_sb_info *sbi,unsigned char flag);void f2fs_handle_error (struct f2fs_sb_info *sbi,unsigned char error);
@@ -5269,8 +5269,9 @@ static inline void f2fs_truncate_meta_inode_pages(struct f2fs_sb_info *sbi, NULL, 0, DATA);truncate_inode_pages_range (META_MAPPING (sbi), -F2FS_BLK_TO_BYTES ((loff_t )blkaddr), -F2FS_BLK_END_BYTES ((loff_t)(blkaddr + cnt -1 ))); +F2FS_BLK_TO_BYTES (sbi, (loff_t )blkaddr), +F2FS_BLK_END_BYTES (sbi, + (loff_t)(blkaddr + cnt -1 ))); } static inline void f2fs_invalidate_internal_cache(struct f2fs_sb_info *sbi,
fs/f2fs/file.c +30 -24
160 lines not on this page · raw message
fs/f2fs/node.c +4 -3
@@ -3294,9 +3294,10 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)if (!enabled_nat_bits (sbi,NULL ))return 0 ; - nm_i->nat_bits_blocks =F2FS_BLK_ALIGN ((nat_bits_bytes <<1 ) +8 ); + nm_i->nat_bits_blocks =F2FS_BLK_ALIGN (sbi, + (nat_bits_bytes <<1 ) +8 ); nm_i->nat_bits =f2fs_kvzalloc (sbi, -F2FS_BLK_TO_BYTES (nm_i->nat_bits_blocks),GFP_KERNEL ); +F2FS_BLK_TO_BYTES (sbi, nm_i->nat_bits_blocks),GFP_KERNEL );if (!nm_i->nat_bits)return -ENOMEM ;
@@ -3309,7 +3310,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)if (IS_ERR (folio))return PTR_ERR (folio); -memcpy (nm_i->nat_bits +F2FS_BLK_TO_BYTES (i), +memcpy (nm_i->nat_bits +F2FS_BLK_TO_BYTES (sbi, i),folio_address (folio),F2FS_BLKSIZE );f2fs_folio_put (folio, true); }
fs/f2fs/recovery.c +2 -2
@@ -734,9 +734,9 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, }if (!file_keep_isize (inode) && - (i_size_read (inode) <= ((loff_t )index <<PAGE_SHIFT ))) + (i_size_read (inode) <=F2FS_BLK_TO_BYTES (sbi, index)))f2fs_i_size_write (inode, - (loff_t)(index +1 ) <<PAGE_SHIFT ); +F2FS_BLK_TO_BYTES (sbi, index +1 ));/* * dest is reserved block, invalidate src block
fs/f2fs/segment.c +5 -4
@@ -3592,8 +3592,8 @@ static unsigned int __issue_discard_cmd_range(struct f2fs_sb_info *sbi,int f2fs_trim_fs (struct f2fs_sb_info *sbi,struct fstrim_range *range) { -__u64 start =F2FS_BYTES_TO_BLK (range->start); -__u64 end = start +F2FS_BYTES_TO_BLK (range->len) -1 ; +__u64 start =F2FS_BYTES_TO_BLK (sbi, range->start); +__u64 end = start +F2FS_BYTES_TO_BLK (sbi, range->len) -1 ;unsigned int start_segno, end_segno;block_t start_block, end_block;struct cp_control cpc;
@@ -3624,7 +3624,8 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) } cpc.reason =CP_DISCARD ; - cpc.trim_minlen =max_t (__u64,1 ,F2FS_BYTES_TO_BLK (range->minlen)); + cpc.trim_minlen =max_t (__u64,1 , +F2FS_BYTES_TO_BLK (sbi, range->minlen)); cpc.trim_start = start_segno; cpc.trim_end = end_segno;
@@ -3658,7 +3659,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) start_block, end_block); out:if (!err) - range->len =F2FS_BLK_TO_BYTES (trimmed); + range->len =F2FS_BLK_TO_BYTES (sbi, trimmed);return err; }
fs/f2fs/super.c +5 -4
@@ -3884,7 +3884,7 @@ static const struct export_operations f2fs_export_ops = { .get_parent = f2fs_get_parent, }; -loff_t max_file_blocks (struct inode *inode) +loff_t max_file_blocks (struct f2fs_sb_info *sbi,struct inode *inode) {loff_t result =0 ;loff_t leaf_count;
@@ -3918,7 +3918,8 @@ loff_t max_file_blocks(struct inode *inode)* fit within U32_MAX + 1 data units. */ - result =umin (result,F2FS_BYTES_TO_BLK (((loff_t )U32_MAX +1 ) *4096 )); + result =umin (result,F2FS_BYTES_TO_BLK (sbi, + ((loff_t )U32_MAX +1 ) *4096 ));return result; }
@@ -4370,7 +4371,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) nat_blocks = nat_segs << log_blocks_per_seg; nat_bits_bytes = nat_blocks /BITS_PER_BYTE ; - nat_bits_blocks =F2FS_BLK_ALIGN ((nat_bits_bytes <<1 ) +8 ); + nat_bits_blocks =F2FS_BLK_ALIGN (sbi, (nat_bits_bytes <<1 ) +8 );if (__is_set_ckpt_flags (ckpt,CP_NAT_BITS_FLAG ) && (cp_payload +F2FS_CP_PACKS +NR_CURSEG_PERSIST_TYPE + nat_bits_blocks >= blocks_per_seg)) {
@@ -5192,7 +5193,7 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)if (err) goto free_options; - sb->s_maxbytes =max_file_blocks (NULL ) << + sb->s_maxbytes =max_file_blocks (sbi,NULL ) <<le32_to_cpu (raw_super->log_blocksize); sb->s_max_links =F2FS_LINK_MAX ;
fs/f2fs/verity.c +4 -2
@@ -75,7 +75,8 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count,struct address_space *mapping = inode->i_mapping;const struct address_space_operations *aops = mapping->a_ops; -if (pos + count >F2FS_BLK_TO_BYTES (max_file_blocks (inode))) +if (pos + count >F2FS_BLK_TO_BYTES (F2FS_I_SB (inode), +max_file_blocks (F2FS_I_SB (inode), inode)))return -EFBIG ;while (count) {
@@ -239,7 +240,8 @@ static int f2fs_get_verity_descriptor(struct inode *inode, void *buf,/* Get the descriptor */ if (pos + size < pos || - pos + size >F2FS_BLK_TO_BYTES (max_file_blocks (inode)) || + pos + size >F2FS_BLK_TO_BYTES (F2FS_I_SB (inode), +max_file_blocks (F2FS_I_SB (inode), inode)) || pos <f2fs_verity_metadata_pos (inode) || size >INT_MAX ) {f2fs_warn (F2FS_I_SB (inode),"invalid verity xattr" ); f2fs_handle_error(F2FS_I_SB(inode),
include/linux/f2fs_fs.h +9 -4
@@ -28,10 +28,15 @@#define COMPRESS_ADDR ((block_t)-2)/* used as compressed data flag */ #define F2FS_BLKSIZE_MASK (F2FS_BLKSIZE - 1) -#define F2FS_BYTES_TO_BLK (bytes) ((unsigned long long)(bytes) >> F2FS_BLKSIZE_BITS) -#define F2FS_BLK_TO_BYTES (blk) ((unsigned long long)(blk) << F2FS_BLKSIZE_BITS) -#define F2FS_BLK_END_BYTES (blk) (F2FS_BLK_TO_BYTES(blk + 1) - 1) -#define F2FS_BLK_ALIGN (x) (F2FS_BYTES_TO_BLK((x) + F2FS_BLKSIZE - 1)) +#define F2FS_BYTES_TO_BLK (sbi, bytes) \ + ((unsigned long long)(bytes) >> (sbi)->log_blocksize) +#define F2FS_BLK_TO_BYTES (sbi, blk) \ + ((unsigned long long)(blk) << (sbi)->log_blocksize) +#define F2FS_BLK_END_BYTES (sbi, blk) \ + (F2FS_BLK_TO_BYTES(sbi, (blk) + 1) - 1) +#define F2FS_BLK_ALIGN (sbi, bytes) \ + F2FS_BYTES_TO_BLK(sbi, (unsigned long long)(bytes) + \ + (sbi)->blocksize - 1)/* 0, 1(node nid), 2(meta nid) are reserved node id */ #define F2FS_RESERVED_NODE_NUM 3
Signature · 1 line
2.53.0
PATCH v8 10/11 f2fs: describe node tree geometry dynamically
In reply to Kelvin ZhangThe file indexing tree boundaries separating direct, indirect, and double-indirect node blocks depend on the number of data block addresses and node IDs contained in each node block.
Parameterize index boundary macros (NODE_DIR1_BLOCK, NODE_DIR2_BLOCK, NODE_IND1_BLOCK, NODE_IND2_BLOCK, and NODE_DIND_BLOCK) and address capacity helpers (DEF_ADDRS_PER_BLOCK, NIDS_PER_BLOCK, cur_addrs_per_inode, addrs_per_page, and addrs_per_folio) with struct f2fs_sb_info *sbi.
Update file mapping, block allocation, truncate, garbage collection, and recovery paths to compute indexing tree offsets from the runtime geometry.
--- fs/f2fs/f2fs.h | 11 +++++- fs/f2fs/gc.c | 10 +++--- fs/f2fs/node.c | 74 +++++++++++++++++++++-------------------- fs/f2fs/node.h | 18 ++++++---- fs/f2fs/super.c | 8 ++--- include/linux/f2fs_fs.h | 10 ------ 6 files changed, 69 insertions(+), 62 deletions(-)
fs/f2fs/f2fs.h +10 -1
@@ -2253,10 +2253,18 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const struct folio *folio)#define SIT_ENTRY_PER_BLOCK (sbi) ((sbi)->sit_entries_per_block)#define NAT_ENTRY_PER_BLOCK (sbi) ((sbi)->nat_entries_per_block)#define DEF_ADDRS_PER_INODE (sbi) ((sbi)->addrs_per_inode) +#define DEF_ADDRS_PER_BLOCK (sbi) ((sbi)->addrs_per_block) +#define NIDS_PER_BLOCK (sbi) ((sbi)->nids_per_block)#define F2FS_ORPHANS_PER_BLOCK (sbi) ((sbi)->orphans_per_block)#define GET_ORPHAN_BLOCKS (sbi, n) DIV_ROUND_UP((n), \ F2FS_ORPHANS_PER_BLOCK(sbi)) +#define NODE_DIR1_BLOCK (sbi) (DEF_ADDRS_PER_INODE(sbi) + 1) +#define NODE_DIR2_BLOCK (sbi) (DEF_ADDRS_PER_INODE(sbi) + 2) +#define NODE_IND1_BLOCK (sbi) (DEF_ADDRS_PER_INODE(sbi) + 3) +#define NODE_IND2_BLOCK (sbi) (DEF_ADDRS_PER_INODE(sbi) + 4) +#define NODE_DIND_BLOCK (sbi) (DEF_ADDRS_PER_INODE(sbi) + 5) +static inline struct f2fs_orphan_footer *f2fs_orphan_footer (void *orphan_block,struct f2fs_sb_info *sbi) {
@@ -3645,7 +3653,8 @@ static inline unsigned int addrs_per_page(struct inode *inode, bool is_inode) {unsigned int addrs = is_inode ? (cur_addrs_per_inode (inode) - -get_inline_xattr_addrs (inode)) :DEF_ADDRS_PER_BLOCK ; +get_inline_xattr_addrs (inode)) : +DEF_ADDRS_PER_BLOCK (F2FS_I_SB (inode));if (f2fs_compressed_file (inode))return ALIGN_DOWN (addrs,F2FS_I (inode)->i_cluster_size);
fs/f2fs/gc.c +6 -4
@@ -1123,7 +1123,8 @@ static int gc_node_segment(struct f2fs_sb_info *sbi,*/ block_t f2fs_start_bidx_of_node (unsigned int node_ofs,struct inode *inode) { -unsigned int indirect_blks =2 *NIDS_PER_BLOCK +4 ; +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); +unsigned int indirect_blks =2 *NIDS_PER_BLOCK (sbi) +4 ;unsigned int bidx;if (node_ofs ==0 )
@@ -1132,11 +1133,12 @@ block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode)if (node_ofs <=2 ) { bidx = node_ofs -1 ; }else if (node_ofs <= indirect_blks) { -int dec = (node_ofs -4 ) / (NIDS_PER_BLOCK +1 ); +int dec = (node_ofs -4 ) / (NIDS_PER_BLOCK (sbi) +1 ); bidx = node_ofs -2 - dec; }else { -int dec = (node_ofs - indirect_blks -3 ) / (NIDS_PER_BLOCK +1 ); +int dec = (node_ofs - indirect_blks -3 ) / + (NIDS_PER_BLOCK (sbi) +1 ); bidx = node_ofs -5 - dec; }
@@ -1179,7 +1181,7 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, max_addrs =DEF_ADDRS_PER_INODE (sbi); }else { base =0 ; - max_addrs =DEF_ADDRS_PER_BLOCK ; + max_addrs =DEF_ADDRS_PER_BLOCK (sbi); }if (base + ofs_in_node >= max_addrs) {
fs/f2fs/node.c +38 -36
197 lines not on this page · raw message
fs/f2fs/node.h +11 -7
@@ -352,17 +352,18 @@ static inline bool is_recoverable_dnode(const struct folio *folio)*/ static inline bool IS_DNODE (const struct folio *node_folio) { +struct f2fs_sb_info *sbi =F2FS_F_SB (node_folio);unsigned int ofs =ofs_of_node (node_folio);if (f2fs_has_xattr_block (ofs))return true; -if (ofs ==3 || ofs ==4 +NIDS_PER_BLOCK || - ofs ==5 +2 *NIDS_PER_BLOCK ) +if (ofs ==3 || ofs ==4 +NIDS_PER_BLOCK (sbi) || + ofs ==5 +2 *NIDS_PER_BLOCK (sbi))return false; -if (ofs >=6 +2 *NIDS_PER_BLOCK ) { - ofs -=6 +2 *NIDS_PER_BLOCK ; -if (!((long int )ofs % (NIDS_PER_BLOCK +1 ))) +if (ofs >=6 +2 *NIDS_PER_BLOCK (sbi)) { + ofs -=6 +2 *NIDS_PER_BLOCK (sbi); +if (!((long )ofs % (NIDS_PER_BLOCK (sbi) +1 )))return false; }return true;
@@ -370,13 +371,15 @@ static inline bool IS_DNODE(const struct folio *node_folio)static inline int set_nid (struct folio *folio,int off,nid_t nid,bool i) { +struct f2fs_sb_info *sbi =F2FS_F_SB (folio);struct f2fs_node *rn =F2FS_NODE (folio);__le32 *inode_nids =F2FS_INODE_NIDS (folio);f2fs_folio_wait_writeback (folio,NODE , true, true);if (i) - inode_nids[off -NODE_DIR1_BLOCK ] =cpu_to_le32 (nid); + inode_nids[off -NODE_DIR1_BLOCK (sbi)] = +cpu_to_le32 (nid);else rn->in.nid[off] =cpu_to_le32 (nid);return folio_mark_dirty (folio);
@@ -386,9 +389,10 @@ static inline nid_t get_nid(const struct folio *folio, int off, bool i) {struct f2fs_node *rn =F2FS_NODE (folio);const __le32 *inode_nids =F2FS_INODE_NIDS (folio); +int nid_index = off -NODE_DIR1_BLOCK (F2FS_F_SB (folio));if (i) -return le32_to_cpu (inode_nids[off -NODE_DIR1_BLOCK ]); +return le32_to_cpu (inode_nids[nid_index]);return le32_to_cpu (rn->in.nid[off]); }
fs/f2fs/super.c +4 -4
@@ -3890,7 +3890,7 @@ loff_t max_file_blocks(struct f2fs_sb_info *sbi, struct inode *inode)loff_t leaf_count;/* -* note: previously, result is equal to (DEF_ADDRS_PER_INODE - +* note: previously, result is equal to (DEF_ADDRS_PER_INODE(sbi) - * DEFAULT_INLINE_XATTR_ADDRS), but now f2fs try to reserve more * space in inode.i_addr, it will be more safe to reassign * result as zero.
@@ -3899,17 +3899,17 @@ loff_t max_file_blocks(struct f2fs_sb_info *sbi, struct inode *inode)if (inode &&f2fs_compressed_file (inode)) leaf_count =ADDRS_PER_BLOCK (inode);else - leaf_count =DEF_ADDRS_PER_BLOCK ; + leaf_count =DEF_ADDRS_PER_BLOCK (sbi);/* two direct node blocks */ result += (leaf_count *2 );/* two indirect node blocks */ - leaf_count *=NIDS_PER_BLOCK ; + leaf_count *=NIDS_PER_BLOCK (sbi); result += (leaf_count *2 );/* one double indirect node block */ - leaf_count *=NIDS_PER_BLOCK ; + leaf_count *=NIDS_PER_BLOCK (sbi); result += leaf_count;/*
include/linux/f2fs_fs.h +0 -10
@@ -282,19 +282,9 @@ struct node_footer {#define DEF_NIDS_PER_INODE 5/* Node IDs in an Inode */ #define ADDRS_PER_INODE (inode) addrs_per_page(inode, true)/* Address Pointers in a Direct Block */ -#define DEF_ADDRS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) / sizeof(__le32))#define ADDRS_PER_BLOCK (inode) addrs_per_page(inode, false) -/* Node IDs in an Indirect Block */ -#define NIDS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) / sizeof(__le32)) -#define ADDRS_PER_PAGE (folio, inode) (addrs_per_page(inode, IS_INODE(folio))) -#define NODE_DIR1_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 1) -#define NODE_DIR2_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 2) -#define NODE_IND1_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 3) -#define NODE_IND2_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 4) -#define NODE_DIND_BLOCK (F2FS_DEF_ADDRS_PER_INODE(F2FS_BLKSIZE) + 5) -#define F2FS_INLINE_XATTR 0x01/* file inline xattr flag */ #define F2FS_INLINE_DATA 0x02/* file inline data flag */ #define F2FS_INLINE_DENTRY 0x04/* file inline dentry flag */
Signature · 1 line
2.53.0
PATCH v8 11/11 f2fs: parameterize block size and mask macros
In reply to Kelvin ZhangBlock size constants, shift counts, masks, and page-to-block ratios were globally defined assuming a fixed 4KB block size.
Parameterize F2FS_BLKSIZE, F2FS_BLKSIZE_BITS, F2FS_BLKSIZE_MASK, F2FS_BLKS_PER_PAGE, and CP_CHKSUM_OFFSET with struct f2fs_sb_info *sbi to reference sbi->blocksize, sbi->log_blocksize, and runtime masks.
Update call sites across metadata operations, data I/O, file operations, garbage collection, inline data, and sysfs information.
--- fs/f2fs/checkpoint.c | 23 ++++++++++++----------- fs/f2fs/data.c | 25 ++++++++++++++----------- fs/f2fs/extent_cache.c | 9 +++++---- fs/f2fs/f2fs.h | 8 +++++--- fs/f2fs/file.c | 30 +++++++++++++++++------------- fs/f2fs/gc.c | 11 ++++++----- fs/f2fs/inline.c | 6 +++--- fs/f2fs/inode.c | 2 +- fs/f2fs/node.c | 7 ++++--- fs/f2fs/node.h | 2 +- fs/f2fs/segment.c | 18 +++++++++++------- fs/f2fs/segment.h | 2 +- fs/f2fs/super.c | 6 +++--- fs/f2fs/sysfs.c | 10 +++++----- fs/f2fs/xattr.c | 2 +- include/linux/f2fs_fs.h | 16 ++++++++-------- 16 files changed, 97 insertions(+), 80 deletions(-)
fs/f2fs/checkpoint.c +12 -11
@@ -288,7 +288,7 @@ static struct folio *__get_meta_folio(struct f2fs_sb_info *sbi, pgoff_t index,return ERR_PTR (err); } -f2fs_update_iostat (sbi,NULL ,FS_META_READ_IO ,F2FS_BLKSIZE ); +f2fs_update_iostat (sbi,NULL ,FS_META_READ_IO ,F2FS_BLKSIZE (sbi));folio_lock (folio);if (unlikely (!is_meta_folio (folio))) {
@@ -513,7 +513,7 @@ int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,if (!err)f2fs_update_iostat (sbi,NULL ,FS_META_READ_IO , -F2FS_BLKSIZE ); +F2FS_BLKSIZE (sbi)); } out:blk_finish_plug (&plug);
@@ -1141,16 +1141,17 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk) } } -static __u32 f2fs_checkpoint_chksum (struct f2fs_checkpoint *ckpt) +static __u32 f2fs_checkpoint_chksum (struct f2fs_sb_info *sbi, +struct f2fs_checkpoint *ckpt) {unsigned int chksum_ofs =le32_to_cpu (ckpt->checksum_offset);__u32 chksum; chksum =f2fs_crc32 (ckpt, chksum_ofs); -if (chksum_ofs <CP_CHKSUM_OFFSET ) { +if (chksum_ofs <CP_CHKSUM_OFFSET (sbi)) { chksum_ofs +=sizeof (chksum); chksum =f2fs_chksum (chksum, (__u8 *)ckpt + chksum_ofs, -F2FS_BLKSIZE - chksum_ofs); +F2FS_BLKSIZE (sbi) - chksum_ofs); }return chksum; }
@@ -1170,13 +1171,13 @@ static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr, crc_offset =le32_to_cpu ((*cp_block)->checksum_offset);if (crc_offset <CP_MIN_CHKSUM_OFFSET || - crc_offset >CP_CHKSUM_OFFSET ) { + crc_offset >CP_CHKSUM_OFFSET (sbi)) {f2fs_folio_put (*cp_folio, true);f2fs_warn (sbi,"invalid crc_offset: %zu" , crc_offset);return -EINVAL ; } - crc =f2fs_checkpoint_chksum (*cp_block); + crc =f2fs_checkpoint_chksum (sbi, *cp_block);if (crc !=cur_cp_crc (*cp_block)) {f2fs_folio_put (*cp_folio, true);f2fs_warn (sbi,"invalid crc value" );
@@ -1713,7 +1714,7 @@ static void commit_checkpoint(struct f2fs_sb_info *sbi,*/ struct folio *folio =f2fs_grab_meta_folio (sbi, blk_addr); -memcpy (folio_address (folio), src,PAGE_SIZE ); +memcpy (folio_address (folio), src,F2FS_BLKSIZE (sbi));folio_mark_dirty (folio);if (unlikely (!folio_clear_dirty_for_io (folio)))
@@ -1848,7 +1849,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)get_sit_bitmap (sbi,__bitmap_ptr (sbi,SIT_BITMAP ));get_nat_bitmap (sbi,__bitmap_ptr (sbi,NAT_BITMAP )); - crc32 =f2fs_checkpoint_chksum (ckpt); + crc32 =f2fs_checkpoint_chksum (sbi, ckpt); *((__le32 *)((unsigned char *)ckpt +le32_to_cpu (ckpt->checksum_offset))) =cpu_to_le32 (crc32);
@@ -1873,8 +1874,8 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)f2fs_update_meta_page (sbi, ckpt, start_blk++);for (i =1 ; i <1 + cp_payload_blks; i++) -f2fs_update_meta_page (sbi, (char *)ckpt + i *F2FS_BLKSIZE , - start_blk++); +f2fs_update_meta_page (sbi, (char *)ckpt + + i *F2FS_BLKSIZE (sbi), start_blk++);if (orphan_num) {write_orphan_inodes (sbi, start_blk);
fs/f2fs/data.c +14 -11
@@ -1227,7 +1227,7 @@ static void f2fs_submit_page_read(struct inode *inode, struct fsverity_info *vi,f2fs_bug_on (sbi,1 );inc_page_count (sbi,F2FS_RD_DATA ); -f2fs_update_iostat (sbi,NULL ,FS_DATA_READ_IO ,F2FS_BLKSIZE ); +f2fs_update_iostat (sbi,NULL ,FS_DATA_READ_IO ,F2FS_BLKSIZE (sbi));f2fs_submit_read_bio (sbi, bio,DATA ); }
@@ -2210,7 +2210,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, count_in_cluster += map.m_len;if (count_in_cluster == cluster_size) { compr_cluster = false; - size +=F2FS_BLKSIZE ; + size +=F2FS_BLKSIZE (sbi); } }else if (map.m_flags &F2FS_MAP_DELALLOC ) { flags =FIEMAP_EXTENT_UNWRITTEN ;
@@ -2255,7 +2255,7 @@ static int f2fs_read_single_page(struct inode *inode, struct fsverity_info *vi, struct readahead_control *rac) {struct bio *bio = *bio_ret; -const unsigned int blocksize =F2FS_BLKSIZE ; +const unsigned int blocksize =F2FS_BLKSIZE (F2FS_I_SB (inode));sector_t block_in_file;sector_t last_block;sector_t last_block_in_file;
@@ -2344,7 +2344,7 @@ static int f2fs_read_single_page(struct inode *inode, struct fsverity_info *vi,inc_page_count (F2FS_I_SB (inode),F2FS_RD_DATA );f2fs_update_iostat (F2FS_I_SB (inode),NULL ,FS_DATA_READ_IO , -F2FS_BLKSIZE ); +F2FS_BLKSIZE (F2FS_I_SB (inode))); *last_block_in_bio = block_nr; out: *bio_ret = bio;
@@ -2362,7 +2362,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,struct bio *bio = *bio_ret;unsigned int start_idx = cc->cluster_idx << cc->log_cluster_size;sector_t last_block_in_file; -const unsigned int blocksize =F2FS_BLKSIZE ; +const unsigned int blocksize =F2FS_BLKSIZE (sbi);struct decompress_io_ctx *dic =NULL ;struct extent_info ei = {};bool from_dnode = true;
@@ -2495,7 +2495,8 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,refcount_inc (&dic->refcnt);inc_page_count (sbi,F2FS_RD_DATA ); -f2fs_update_iostat (sbi, inode,FS_DATA_READ_IO ,F2FS_BLKSIZE ); +f2fs_update_iostat (sbi, inode,FS_DATA_READ_IO , +F2FS_BLKSIZE (sbi)); *last_block_in_bio = blkaddr; }
@@ -2669,14 +2670,14 @@ static int f2fs_read_data_large_folio(struct inode *inode,*/ f2fs_wait_on_block_writeback (inode, block_nr); -if (!bio_add_folio (bio, folio,F2FS_BLKSIZE , - offset <<PAGE_SHIFT )) +if (!bio_add_folio (bio, folio,F2FS_BLKSIZE (F2FS_I_SB (inode)), + offset <<PAGE_SHIFT )) goto submit_and_realloc; folio_in_bio = true;inc_page_count (F2FS_I_SB (inode),F2FS_RD_DATA );f2fs_update_iostat (F2FS_I_SB (inode),NULL ,FS_DATA_READ_IO , -F2FS_BLKSIZE ); +F2FS_BLKSIZE (F2FS_I_SB (inode))); last_block_in_bio = block_nr; }trace_f2fs_read_folio (folio,DATA );
@@ -4230,6 +4231,7 @@ static sector_t f2fs_bmap_compress(struct inode *inode, sector_t block)static sector_t f2fs_bmap (struct address_space *mapping,sector_t block) {struct inode *inode = mapping->host; +struct f2fs_sb_info *sbi =F2FS_I_SB (inode);sector_t blknr =0 ;if (f2fs_has_inline_data (inode))
@@ -4240,7 +4242,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 >=max_file_blocks (F2FS_I_SB (inode), inode))) +if (unlikely (block >=max_file_blocks (sbi, inode))) goto out;if (f2fs_compressed_file (inode)) {
@@ -4442,7 +4444,8 @@ static int check_swap_activate(struct swap_info_struct *sis, out:if (not_aligned)f2fs_warn (sbi,"Swapfile (%u) is not align to section: 1) creat(), 2) ioctl(F2FS_IOC_SET_PIN_FILE), 3) fallocate(%lu * N)" , - not_aligned, blks_per_sec *F2FS_BLKSIZE ); + not_aligned, + (unsigned long )blks_per_sec *F2FS_BLKSIZE (sbi));return ret; }
fs/f2fs/extent_cache.c +5 -4
@@ -904,11 +904,12 @@ static int __get_new_block_age(struct inode *inode, struct extent_info *ei,struct extent_info tei = *ei;/* only fofs and len are valid */ /* -* When I/O is not aligned to a PAGE_SIZE, update will happen to the last -* file block even in seq write. So don't record age for newly last file -* block here. +* When I/O is not aligned to the filesystem block size, update will +* happen to the last file block even in seq write. Do not record the age +* of the new last file block here. */ -if ((f_size >>PAGE_SHIFT ) == ei->fofs && f_size & (PAGE_SIZE -1 ) && +if ((f_size >> sbi->log_blocksize) == ei->fofs && + f_size &F2FS_BLKSIZE_MASK (sbi) && blkaddr ==NEW_ADDR )return -EINVAL ;
fs/f2fs/f2fs.h +5 -3
@@ -2258,6 +2258,7 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const struct folio *folio)#define F2FS_ORPHANS_PER_BLOCK (sbi) ((sbi)->orphans_per_block)#define GET_ORPHAN_BLOCKS (sbi, n) DIV_ROUND_UP((n), \ F2FS_ORPHANS_PER_BLOCK(sbi)) +#define CP_CHKSUM_OFFSET (sbi) (F2FS_BLKSIZE(sbi) - sizeof(__le32))#define NODE_DIR1_BLOCK (sbi) (DEF_ADDRS_PER_INODE(sbi) + 1)#define NODE_DIR2_BLOCK (sbi) (DEF_ADDRS_PER_INODE(sbi) + 2)
@@ -2312,7 +2313,7 @@ static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)static inline struct node_footer *F2FS_NODE_FOOTER (const struct folio *folio) { -return folio_address (folio) +F2FS_BLKSIZE - +return folio_address (folio) +F2FS_BLKSIZE (F2FS_F_SB (folio)) -sizeof (struct node_footer ); }
@@ -2328,7 +2329,8 @@ static inline struct f2fs_inode *F2FS_INODE(const struct folio *folio)static inline __le32 *F2FS_INODE_NIDS (const struct folio *folio) { -return folio_address (folio) +F2FS_BLKSIZE -sizeof (struct node_footer ) - +return folio_address (folio) +F2FS_BLKSIZE (F2FS_F_SB (folio)) - +sizeof (struct node_footer ) -SIZE_OF_I_NID ; }
@@ -2977,7 +2979,7 @@ static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)if (flag ==NAT_BITMAP )return tmp_ptr;else -return (unsigned char *)ckpt +F2FS_BLKSIZE ; +return (unsigned char *)ckpt +F2FS_BLKSIZE (sbi); }else { offset = (flag ==NAT_BITMAP ) ?le32_to_cpu (ckpt->sit_ver_bitmap_bytesize) :0 ;
fs/f2fs/file.c +17 -13
@@ -110,7 +110,8 @@ static vm_fault_t f2fs_filemap_fault(struct vm_fault *vmf) ret =filemap_fault (vmf);if (ret &VM_FAULT_LOCKED )f2fs_update_iostat (F2FS_I_SB (inode), inode, -APP_MAPPED_READ_IO ,F2FS_BLKSIZE ); +APP_MAPPED_READ_IO , +F2FS_BLKSIZE (F2FS_I_SB (inode)));trace_f2fs_filemap_fault (inode, vmf->pgoff, flags, ret);
@@ -233,7 +234,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) }folio_mark_dirty (folio); -f2fs_update_iostat (sbi, inode,APP_MAPPED_IO ,F2FS_BLKSIZE ); +f2fs_update_iostat (sbi, inode,APP_MAPPED_IO ,F2FS_BLKSIZE (sbi));f2fs_update_time (sbi,REQ_TIME ); out_sem:
@@ -974,7 +975,7 @@ int f2fs_truncate(struct inode *inode)trace_f2fs_truncate (inode); -if (time_to_inject (sbi,FAULT_TRUNCATE )) +if (time_to_inject (F2FS_I_SB (inode),FAULT_TRUNCATE ))return -EIO ; err =f2fs_dquot_initialize (inode);
@@ -1675,7 +1676,8 @@ static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len)return -EINVAL ;/* collapse range should be aligned to block size of f2fs. */ -if (offset & (F2FS_BLKSIZE -1 ) || len & (F2FS_BLKSIZE -1 )) +if (offset &F2FS_BLKSIZE_MASK (F2FS_I_SB (inode)) || + len &F2FS_BLKSIZE_MASK (F2FS_I_SB (inode)))return -EINVAL ; ret =f2fs_convert_inline_inode (inode);
@@ -1890,7 +1892,8 @@ static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len)return -EINVAL ;/* insert range should be aligned to block size of f2fs. */ -if (offset & (F2FS_BLKSIZE -1 ) || len & (F2FS_BLKSIZE -1 )) +if (offset &F2FS_BLKSIZE_MASK (F2FS_I_SB (inode)) || + len &F2FS_BLKSIZE_MASK (F2FS_I_SB (inode)))return -EINVAL ; ret =f2fs_convert_inline_inode (inode);
@@ -3193,7 +3196,8 @@ static int f2fs_ioc_defragment(struct file *filp, unsigned long arg)return -EFAULT ;/* verify alignment of offset & size */ -if (range.start & (F2FS_BLKSIZE -1 ) || range.len & (F2FS_BLKSIZE -1 )) +if (range.start &F2FS_BLKSIZE_MASK (sbi) || + range.len &F2FS_BLKSIZE_MASK (sbi))return -EINVAL ; if (unlikely(F2FS_BYTES_TO_BLK(sbi, range.start + range.len) >
@@ -3279,7 +3283,7 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,if (src == dst && pos_out > pos_in && pos_out < pos_in + len) goto out_unlock;if (pos_in + len == src->i_size) - len =ALIGN (src->i_size,F2FS_BLKSIZE ) - pos_in; + len =ALIGN (src->i_size,F2FS_BLKSIZE (sbi)) - pos_in;if (len ==0 ) { ret =0 ; goto out_unlock;
@@ -3297,9 +3301,9 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, }/* verify the end result is block aligned */ -if (!IS_ALIGNED (pos_in,F2FS_BLKSIZE ) || - !IS_ALIGNED (pos_in + len,F2FS_BLKSIZE ) || - !IS_ALIGNED (pos_out,F2FS_BLKSIZE )) +if (!IS_ALIGNED (pos_in,F2FS_BLKSIZE (sbi)) || + !IS_ALIGNED (pos_in + len,F2FS_BLKSIZE (sbi)) || + !IS_ALIGNED (pos_out,F2FS_BLKSIZE (sbi))) goto out_unlock; ret =f2fs_convert_inline_inode (src);
@@ -4593,14 +4597,14 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) to_end = true; } -if (!IS_ALIGNED (range.start,F2FS_BLKSIZE ) || - (!to_end && !IS_ALIGNED (end_addr,F2FS_BLKSIZE ))) { +if (!IS_ALIGNED (range.start,F2FS_BLKSIZE (sbi)) || + (!to_end && !IS_ALIGNED (end_addr,F2FS_BLKSIZE (sbi)))) { ret = -EINVAL ; goto err; } index =F2FS_BYTES_TO_BLK (sbi, range.start); - pg_end =DIV_ROUND_UP (end_addr,F2FS_BLKSIZE ); + pg_end =F2FS_BLK_ALIGN (sbi, end_addr); ret =f2fs_convert_inline_inode (inode);if (ret)
fs/f2fs/gc.c +6 -5
@@ -1305,8 +1305,8 @@ static int ra_data_block(struct inode *inode, pgoff_t index)f2fs_put_page (fio.encrypted_page, false);f2fs_folio_put (folio, true); -f2fs_update_iostat (sbi, inode,FS_DATA_READ_IO ,F2FS_BLKSIZE ); -f2fs_update_iostat (sbi,NULL ,FS_GDATA_READ_IO ,F2FS_BLKSIZE ); +f2fs_update_iostat (sbi, inode,FS_DATA_READ_IO ,F2FS_BLKSIZE (sbi)); +f2fs_update_iostat (sbi,NULL ,FS_GDATA_READ_IO ,F2FS_BLKSIZE (sbi));if (atomic_inode)iput (atomic_inode);
@@ -1426,9 +1426,9 @@ static int move_data_block(struct inode *inode, block_t bidx, }f2fs_update_iostat (fio.sbi, inode,FS_DATA_READ_IO , -F2FS_BLKSIZE ); +F2FS_BLKSIZE (fio.sbi));f2fs_update_iostat (fio.sbi,NULL ,FS_GDATA_READ_IO , -F2FS_BLKSIZE ); +F2FS_BLKSIZE (fio.sbi));folio_lock (mfolio); if (unlikely(!is_meta_folio(mfolio) ||
@@ -1479,7 +1479,8 @@ static int move_data_block(struct inode *inode, block_t bidx, fio.new_blkaddr = newaddr;f2fs_submit_page_write (&fio); -f2fs_update_iostat (fio.sbi,NULL ,FS_GC_DATA_IO ,F2FS_BLKSIZE ); +f2fs_update_iostat (fio.sbi,NULL ,FS_GC_DATA_IO , +F2FS_BLKSIZE (fio.sbi));f2fs_update_data_blkaddr (&dn, newaddr);set_inode_flag (inode,FI_APPEND_WRITE );
fs/f2fs/inline.c +3 -3
@@ -448,7 +448,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,* Start by zeroing the full block, to ensure that all unused space is * zeroed and no uninitialized memory is leaked to disk. */ -memset (dentry_blk,0 ,F2FS_BLKSIZE ); +memset (dentry_blk,0 ,F2FS_BLKSIZE (F2FS_I_SB (dir)));make_dentry_ptr_inline (dir, &src, inline_dentry);make_dentry_ptr_block (dir, &dst, dentry_blk);
@@ -477,8 +477,8 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,F2FS_I (dir)->i_inline_xattr_size =0 ;f2fs_i_depth_write (dir,1 ); -if (i_size_read (dir) <PAGE_SIZE ) -f2fs_i_size_write (dir,PAGE_SIZE ); +if (i_size_read (dir) <F2FS_BLKSIZE (F2FS_I_SB (dir))) +f2fs_i_size_write (dir,F2FS_BLKSIZE (F2FS_I_SB (dir))); out:f2fs_folio_put (folio, true);return err;
fs/f2fs/inode.c +1 -1
@@ -165,7 +165,7 @@ static __u32 f2fs_inode_chksum(struct f2fs_sb_info *sbi, struct folio *folio) chksum =f2fs_chksum (chksum, (__u8 *)&dummy_cs, cs_size); offset += cs_size; chksum =f2fs_chksum (chksum, (__u8 *)ri + offset, -F2FS_BLKSIZE - offset); +F2FS_BLKSIZE (sbi) - offset);return chksum; }
fs/f2fs/node.c +4 -3
@@ -165,7 +165,7 @@ static struct folio *get_next_nat_folio(struct f2fs_sb_info *sbi, nid_t nid) src_addr =folio_address (src_folio); dst_addr =folio_address (dst_folio); -memcpy (dst_addr, src_addr,PAGE_SIZE ); +memcpy (dst_addr, src_addr,F2FS_BLKSIZE (sbi));folio_mark_dirty (dst_folio);f2fs_folio_put (src_folio, true);
@@ -1500,7 +1500,8 @@ static int read_node_folio(struct folio *folio, blk_opf_t op_flags) err =f2fs_submit_page_bio (&fio);if (!err) -f2fs_update_iostat (sbi,NULL ,FS_NODE_READ_IO ,F2FS_BLKSIZE ); +f2fs_update_iostat (sbi,NULL ,FS_NODE_READ_IO , +F2FS_BLKSIZE (sbi));return err; }
@@ -3313,7 +3314,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)return PTR_ERR (folio);memcpy (nm_i->nat_bits +F2FS_BLK_TO_BYTES (sbi, i), -folio_address (folio),F2FS_BLKSIZE ); +folio_address (folio),F2FS_BLKSIZE (sbi));f2fs_folio_put (folio, true); }
fs/f2fs/node.h +1 -1
@@ -282,7 +282,7 @@ static inline void fill_node_footer(const struct folio *folio, nid_t nid,unsigned int old_flag =0 ;if (reset) -memset (rn,0 ,F2FS_BLKSIZE ); +memset (rn,0 ,F2FS_BLKSIZE (F2FS_F_SB (folio)));else old_flag =le32_to_cpu (footer->flag);
fs/f2fs/segment.c +11 -7
@@ -1316,7 +1316,8 @@ static void __submit_zone_reset_cmd(struct f2fs_sb_info *sbi,submit_bio (bio);atomic_inc (&dcc->issued_discard); - f2fs_update_iostat(sbi, NULL, FS_ZONE_RESET_IO, dc->di.len * F2FS_BLKSIZE); +f2fs_update_iostat (sbi,NULL ,FS_ZONE_RESET_IO , + dc->di.len * F2FS_BLKSIZE(sbi)); }#endif
@@ -1419,7 +1420,8 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,atomic_inc (&dcc->issued_discard); -f2fs_update_iostat (sbi,NULL ,FS_DISCARD_IO , len *F2FS_BLKSIZE ); +f2fs_update_iostat (sbi,NULL ,FS_DISCARD_IO , + len *F2FS_BLKSIZE (sbi)); lstart += len; start += len;
@@ -2797,7 +2799,7 @@ void f2fs_update_meta_page(struct f2fs_sb_info *sbi,if (IS_ERR (folio))return ; -memcpy (folio_address (folio), src,PAGE_SIZE ); +memcpy (folio_address (folio), src,F2FS_BLKSIZE (sbi));folio_mark_dirty (folio);f2fs_folio_put (folio, true); }
@@ -4152,7 +4154,7 @@ void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi, struct folio *folio,f2fs_submit_page_write (&fio);stat_inc_meta_count (sbi, folio->index); -f2fs_update_iostat (sbi,NULL , io_type,F2FS_BLKSIZE ); +f2fs_update_iostat (sbi,NULL , io_type,F2FS_BLKSIZE (sbi)); }void f2fs_do_write_node_page (unsigned int nid,struct f2fs_io_info *fio)
@@ -4162,7 +4164,8 @@ void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio)set_summary (&sum, nid,0 ,0 );do_write_page (&sum, fio); -f2fs_update_iostat (fio->sbi,NULL , fio->io_type,F2FS_BLKSIZE ); +f2fs_update_iostat (fio->sbi,NULL , fio->io_type, +F2FS_BLKSIZE (fio->sbi)); } void f2fs_outplace_write_data(struct dnode_of_data *dn,
@@ -4178,7 +4181,8 @@ void f2fs_outplace_write_data(struct dnode_of_data *dn,do_write_page (&sum, fio);f2fs_update_data_blkaddr (dn, fio->new_blkaddr); -f2fs_update_iostat (sbi, dn->inode, fio->io_type,F2FS_BLKSIZE ); +f2fs_update_iostat (sbi, dn->inode, fio->io_type, +F2FS_BLKSIZE (sbi)); }int f2fs_inplace_write_data (struct f2fs_io_info *fio)
@@ -4220,7 +4224,7 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio)f2fs_update_device_state (fio->sbi, fio->ino, fio->new_blkaddr,1 );f2fs_update_iostat (fio->sbi,fio_inode (fio), - fio->io_type,F2FS_BLKSIZE ); + fio->io_type,F2FS_BLKSIZE (fio->sbi)); }return err;
fs/f2fs/segment.h +1 -1
@@ -432,7 +432,7 @@ static inline void seg_info_to_sit_folio(struct f2fs_sb_info *sbi,int i; raw_sit =folio_address (folio); -memset (raw_sit,0 ,PAGE_SIZE ); +memset (raw_sit,0 ,F2FS_BLKSIZE (sbi));for (i =0 ; i < end - start; i++) { rs = &raw_sit->entries[i]; se =get_seg_entry (sbi, start + i);
fs/f2fs/super.c +3 -3
@@ -1610,7 +1610,7 @@ static int f2fs_check_opt_consistency(struct fs_context *fc,return -EINVAL ; } min_size =MIN_INLINE_XATTR_SIZE ; - max_size =MAX_INLINE_XATTR_SIZE (sbi->blocksize); + max_size =MAX_INLINE_XATTR_SIZE (F2FS_BLKSIZE (sbi));if (F2FS_OPTION (sbi).inline_xattr_size < min_size ||F2FS_OPTION (sbi).inline_xattr_size > max_size) {
@@ -4079,10 +4079,10 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi, }/* only support block_size equals to PAGE_SIZE */ -if (le32_to_cpu (raw_super->log_blocksize) !=F2FS_BLKSIZE_BITS ) { +if (le32_to_cpu (raw_super->log_blocksize) !=PAGE_SHIFT ) {f2fs_info (sbi,"Invalid log_blocksize (%u), supports only %u" ,le32_to_cpu (raw_super->log_blocksize), -F2FS_BLKSIZE_BITS ); +PAGE_SHIFT );return -EFSCORRUPTED ; }
fs/f2fs/sysfs.c +5 -5
@@ -1871,8 +1871,8 @@ static int __maybe_unused disk_map_seq_show(struct seq_file *seq,struct f2fs_sb_info *sbi =F2FS_SB (sb);int i; -seq_printf (seq,"Address Layout : %5luB Block address (# of Segments)\n" , -F2FS_BLKSIZE ); +seq_printf (seq,"Address Layout : %5uB Block address (# of Segments)\n" , +F2FS_BLKSIZE (sbi));seq_printf (seq," SB : %12s\n" ,"0/1024B" );seq_printf (seq," seg0_blkaddr : 0x%010x\n" ,SEG0_BLKADDR (sbi)); seq_printf(seq, " Checkpoint : 0x%010x (%10d)\n",
@@ -1889,13 +1889,13 @@ static int __maybe_unused disk_map_seq_show(struct seq_file *seq,seq_printf (seq," Main : 0x%010x (%10d)\n" ,SM_I (sbi)->main_blkaddr,le32_to_cpu (F2FS_RAW_SUPER (sbi)->segment_count_main)); -seq_printf (seq," Block size : %12lu KB\n" ,F2FS_BLKSIZE >>10 ); +seq_printf (seq," Block size : %12u KB\n" ,F2FS_BLKSIZE (sbi) >>10 );seq_printf (seq," Segment size : %12d MB\n" , - (BLKS_PER_SEG (sbi) << (F2FS_BLKSIZE_BITS -10 )) >>10 ); + (BLKS_PER_SEG (sbi) << (F2FS_BLKSIZE_BITS (sbi) -10 )) >>10 );seq_printf (seq," Segs/Sections : %12d\n" ,SEGS_PER_SEC (sbi));seq_printf (seq," Section size : %12d MB\n" , - (BLKS_PER_SEC (sbi) << (F2FS_BLKSIZE_BITS -10 )) >>10 ); + (BLKS_PER_SEC (sbi) << (F2FS_BLKSIZE_BITS (sbi) -10 )) >>10 );seq_printf (seq," # of Sections : %12d\n" ,le32_to_cpu (F2FS_RAW_SUPER (sbi)->section_count));
fs/f2fs/xattr.c +1 -1
@@ -850,4 +850,4 @@ int __init f2fs_init_xattr_cache(void)void f2fs_destroy_xattr_cache (void ) {kmem_cache_destroy (inline_xattr_slab); -} +}
include/linux/f2fs_fs.h +8 -8
@@ -14,12 +14,9 @@#define F2FS_SUPER_OFFSET 1024/* byte-size offset */ #define F2FS_MIN_LOG_SECTOR_SIZE 9/* 9 bits for 512 bytes */ #define F2FS_MAX_LOG_SECTOR_SIZE PAGE_SHIFT/* Max is Block Size */ -#define F2FS_LOG_SECTORS_PER_BLOCK (sbi) ((sbi)->log_blocksize - 9)/* log number for sector/blk */ #define F2FS_MIN_LOG_BLOCKSIZE 12#define F2FS_MIN_BLKSIZE 4096UL -#define F2FS_BLKSIZE PAGE_SIZE/* support only block == page */ #define F2FS_MAX_BLKSIZE PAGE_SIZE -#define F2FS_BLKSIZE_BITS PAGE_SHIFT/* bits for F2FS_BLKSIZE */ #define F2FS_MAX_EXTENSION 64/* # of extension entries */ #define F2FS_EXTENSION_LEN 8/* max size of extension */
@@ -27,16 +24,20 @@#define NEW_ADDR ((block_t)-1)/* used as block_t addresses */ #define COMPRESS_ADDR ((block_t)-2)/* used as compressed data flag */ -#define F2FS_BLKSIZE_MASK (F2FS_BLKSIZE - 1) +#define F2FS_BLKSIZE (sbi) ((sbi)->blocksize) +#define F2FS_BLKSIZE_BITS (sbi) ((sbi)->log_blocksize) +#define F2FS_BLKSIZE_MASK (sbi) (F2FS_BLKSIZE(sbi) - 1) +#define F2FS_LOG_SECTORS_PER_BLOCK (sbi) (F2FS_BLKSIZE_BITS(sbi) - 9) +#define F2FS_BLKS_PER_PAGE (sbi) (PAGE_SIZE / F2FS_BLKSIZE(sbi))#define F2FS_BYTES_TO_BLK (sbi, bytes) \ - ((unsigned long long)(bytes) >> (sbi)->log_blocksize) + ((unsigned long long)(bytes) >> F2FS_BLKSIZE_BITS(sbi))#define F2FS_BLK_TO_BYTES (sbi, blk) \ - ((unsigned long long)(blk) << (sbi)->log_blocksize) + ((unsigned long long)(blk) << F2FS_BLKSIZE_BITS(sbi))#define F2FS_BLK_END_BYTES (sbi, blk) \ (F2FS_BLK_TO_BYTES(sbi, (blk) + 1) - 1)#define F2FS_BLK_ALIGN (sbi, bytes) \ F2FS_BYTES_TO_BLK(sbi, (unsigned long long)(bytes) + \ - (sbi)->blocksize - 1) + F2FS_BLKSIZE(sbi) - 1)/* 0, 1(node nid), 2(meta nid) are reserved node id */ #define F2FS_RESERVED_NODE_NUM 3
@@ -222,7 +223,6 @@ struct f2fs_checkpoint {unsigned char sit_nat_version_bitmap[]; } __packed; -#define CP_CHKSUM_OFFSET (F2FS_BLKSIZE - sizeof(__le32))/* default chksum offset in checkpoint */ #define CP_MIN_CHKSUM_OFFSET \ (offsetof(struct f2fs_checkpoint, sit_nat_version_bitmap))
Signature · 1 line
2.53.0