f2fs-tools: adapt to inline extent format
v3 cover f2fs-tools: adapt to inline extent format
From: Yongpeng Yang <[email protected]>
This is the f2fs-tools companion series for the kernel patchset "f2fs: introduce inline extent mapping for inode data blocks" (v3).
Changes since v2:
- The kernel inline extent feature has been redesigned. The inline extent area is now placed after struct f2fs_inode->i_extra_end, inside the i_extra_isize region, instead of repurposing the direct block address area (i_addr[]) with dual magic numbers.
- As a consequence, f2fs-tools no longer needs to understand or convert the inline extent on-disk format. The bulk of v2 (the 787-line fsck/iextent.c core with lookup/insert/merge/split/convert logic, the datablock_addr()/set_data_blkaddr() rework, and the build plumbing) is dropped entirely.
- Dropped [RFC PATCH v2 2/3] "build: add inline extent build support":
no new source files are added, so no build changes are needed.
- Dropped [RFC PATCH v2 3/3] "f2fs_io: add support to clear/set extent flags": the per-file ioctl flag no longer exists in the kernel side.
v2: https://lore.kernel.org/all/[email protected]/
What remains is a small adaptation to the new on-disk inode layout:
Patch 1: Adapt to the inode layout change -- split i_compr_blocks into
__le32 i_compr_blocks + __le32 i_inline_ext_capacity, add the struct f2fs_iext_header definition, and keep the inline extent consistent with the largest extent cache by invalidating it whenever i_ext is dropped or truncated in fsck.
Patch 2: dump.f2fs -- print the inline extent capacity and all extent
entries for inodes that reserve an inline extent area.
Yongpeng Yang (2):
fsck.f2fs: adapt to inline extent inode layout dump.f2fs: dump inline extent mapping information
fsck/fsck.c | 9 ++++++--- fsck/inject.c | 6 +++--- fsck/mount.c | 20 +++++++++++++++++++- fsck/segment.c | 2 +- include/f2fs_fs.h | 22 +++++++++++++++++++++- 5 files changed, 50 insertions(+), 9 deletions(-)
Signature · 8 lines
2.43.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
RFC PATCH v3 1/2 fsck.f2fs: adapt to inline extent inode layout
From: Yongpeng Yang <[email protected]>
The kernel inline extent feature has been designed to place the inline extent area after struct f2fs_inode->i_extra_end, inside the i_extra_isize region. f2fs-tools only needs to track the inode layout change and keep the inline extent consistent with the largest cached extent.
Adapt to the new on-disk inode layout:
- Split struct f2fs_inode->i_compr_blocks (was __le64) into __le32 i_compr_blocks + __le32 i_inline_ext_capacity, matching the kernel change. i_inline_ext_capacity records the number of inline extent entries reserved in the inode.
- Add struct f2fs_iext_header, the header of the inline extent area located right after i_extra_end[].
- Update all i_compr_blocks accesses (fsck.c, inject.c, mount.c, segment.c) to use le32 helpers.
Keep the inline extent consistent with the largest extent:
- Add f2fs_invalidate_inline_extent(), which resets the inline extent entry count to 0.
- The inline extent shares its lifetime with the largest extent cache:
whenever i_ext is dropped or truncated (in fsck_chk_inode_blk() and update_data_blkaddr()), invalidate the inline extent as well so a stale mapping is never left behind.
--- fsck/fsck.c | 9 ++++++--- fsck/inject.c | 6 +++--- fsck/mount.c | 3 ++- fsck/segment.c | 2 +- include/f2fs_fs.h | 22 +++++++++++++++++++++- 5 files changed, 33 insertions(+), 9 deletions(-)
fsck/fsck.c +6 -3
@@ -919,7 +919,7 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,u32 i_flags =le32_to_cpu (node_blk->i.i_flags);bool compressed = i_flags &F2FS_COMPR_FL ;bool compr_rel = node_blk->i.i_inline &F2FS_COMPRESS_RELEASED ; -u64 i_compr_blocks =le64_to_cpu (node_blk->i.i_compr_blocks); +u64 i_compr_blocks =le32_to_cpu (node_blk->i.i_compr_blocks);nid_t i_xattr_nid =le32_to_cpu (node_blk->i.i_xattr_nid);int ofs;char *en;
@@ -1204,6 +1204,7 @@ check_next: qf_last_blkofs[cur_qtype] = child.pgofs; }else if (c.fix_on) { node_blk->i.i_ext.len =cpu_to_le32 (idx); +f2fs_invalidate_inline_extent (&node_blk->i); need_fix =1 ;break ; }
@@ -1332,7 +1333,7 @@ check:if (compressed && i_compr_blocks != cbc->cnt) {if (c.fix_on) { - node_blk->i.i_compr_blocks =cpu_to_le64 (cbc->cnt); + node_blk->i.i_compr_blocks =cpu_to_le32 (cbc->cnt); need_fix =1 ;FIX_MSG ("[0x%x] i_compr_blocks=0x%08" PRIx64" -> 0x%x" , nid, i_compr_blocks, cbc->cnt);
@@ -1476,8 +1477,10 @@ skip_dot_fix: }/* drop extent information to avoid potential wrong access */ -if (need_fix &&f2fs_dev_is_writable () && !is_aliasing) +if (need_fix &&f2fs_dev_is_writable () && !is_aliasing) { node_blk->i.i_ext.len =0 ; +f2fs_invalidate_inline_extent (&node_blk->i); + }if ((c.feature &F2FS_FEATURE_INODE_CHKSUM ) &&f2fs_has_extra_isize (&node_blk->i)) {
fsck/inject.c +3 -3
@@ -1088,9 +1088,9 @@ static int inject_inode(struct f2fs_sb_info *sbi, struct f2fs_node *node, inode->i_inode_checksum =cpu_to_le32 ((u32 )opt->val); }else if (!strcmp (opt->mb,"i_compr_blocks" )) {MSG (0 ,"Info: inject inode i_compr_blocks of nid %u: " -"%" PRIu64" -> %" PRIu64"\n" , opt->nid, -le64_to_cpu (inode->i_compr_blocks), (u64 )opt->val); - inode->i_compr_blocks =cpu_to_le64 ((u64 )opt->val); +"%u -> %u\n" , opt->nid, +le32_to_cpu (inode->i_compr_blocks), (u32 )opt->val); + inode->i_compr_blocks =cpu_to_le32 ((u32 )opt->val); }else if (!strcmp (opt->mb,"i_addr" )) {/* do not care if it is inline data */ if (opt->idx >=DEF_ADDRS_PER_INODE ) {
fsck/mount.c +2 -1
@@ -344,7 +344,7 @@ void print_inode_info(struct f2fs_sb_info *sbi,DISP_u32 (inode, i_crtime_nsec); }if (c.feature &F2FS_FEATURE_COMPRESSION ) { -DISP_u64 (inode, i_compr_blocks); +DISP_u32 (inode, i_compr_blocks);DISP_u8 (inode, i_compress_algorithm);DISP_u8 (inode, i_log_cluster_size);DISP_u16 (inode, i_compress_flag);
@@ -2574,6 +2574,7 @@ void update_data_blkaddr(struct f2fs_sb_info *sbi, nid_t nid, endaddr = startaddr +le32_to_cpu (node_blk->i.i_ext.len);if (oldaddr >= startaddr && oldaddr < endaddr) { node_blk->i.i_ext.len =0 ; +f2fs_invalidate_inline_extent (&node_blk->i);/* update inode block */ if (node_blk_alloced)
fsck/segment.c +1 -1
@@ -725,7 +725,7 @@ int f2fs_build_file(struct f2fs_sb_info *sbi, struct dentry *de)/* update inode meta */ node_blk->i.i_size =cpu_to_le64 (off);if (!c.compress.readonly) { - node_blk->i.i_compr_blocks =cpu_to_le64 (cblocks); + node_blk->i.i_compr_blocks =cpu_to_le32 (cblocks); node_blk->i.i_blocks +=cpu_to_le64 (cblocks); }ASSERT (update_inode (sbi, node_blk, &ni.blk_addr) >=0 );
include/f2fs_fs.h +21 -1
@@ -929,6 +929,15 @@ struct f2fs_extent {static_assert (sizeof (struct f2fs_extent ) ==12 ,"" ); +/* +* f2fs_iext_header: header for inline extent area in i_extra_attr region. +* Placed right after i_extra_end[0], before the extent array. +*/ +struct f2fs_iext_header { +__le32 cnt;/* current # of valid extents */ +struct f2fs_extent exts[]; +} __attribute__((packed)); +#define F2FS_NAME_LEN 255/* max output length of pretty_print_filename() including null terminator */
@@ -1079,7 +1088,8 @@ struct f2fs_inode {__le32 i_inode_checksum;/* inode meta checksum */ __le64 i_crtime;/* creation time */ __le32 i_crtime_nsec;/* creation time in nano scale */ -__le64 i_compr_blocks;/* # of compressed blocks */ +__le32 i_compr_blocks;/* # of compressed blocks */ +__le32 i_inline_ext_capacity;/* # of inline extent entries */ __u8 i_compress_algorithm;/* compress algorithm */ __u8 i_log_cluster_size;/* log of cluster size */ __le16 i_compress_flag;/* compress flag */
@@ -1730,6 +1740,16 @@ static inline bool f2fs_has_extra_isize(struct f2fs_inode *inode)return (inode->i_inline &F2FS_EXTRA_ATTR ); } +static inline void f2fs_invalidate_inline_extent (struct f2fs_inode *inode) +{ +if (f2fs_has_extra_isize (inode) && +le32_to_cpu (inode->i_inline_ext_capacity) >0 ) { +struct f2fs_iext_header *eh = + (struct f2fs_iext_header *)inode->i_extra_end; + eh->cnt =0 ; + } +} +static inline int __get_extra_isize (struct f2fs_inode *inode) {if (f2fs_has_extra_isize (inode))
Signature · 8 lines
2.43.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
RFC PATCH v3 2/2 dump.f2fs: dump inline extent mapping information
In reply to Yongpeng YangFrom: Yongpeng Yang <[email protected]>
When extra attributes are enabled and an inode reserves an inline extent area (i_inline_ext_capacity > 0), print the capacity, the valid extent count, and the content of every extent entry (fofs, blkaddr, len) in print_inode_info().
The inline extent area lives right after struct f2fs_inode->i_extra_end, so it can be read directly without any format-specific decoding.
Example output:
i_inline_ext_capacity [0x 100 : 256]
inline_ext (cnt/cap) [3 / 256]
inline_ext[0]: fofs:3ac blkaddr:12f400 len:64
inline_ext[1]: fofs:410 blkaddr:12f480 len:20
inline_ext[2]: fofs:500 blkaddr:130000 len:c--- fsck/mount.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
fsck/mount.c +17 -0
@@ -349,6 +349,23 @@ void print_inode_info(struct f2fs_sb_info *sbi,DISP_u8 (inode, i_log_cluster_size);DISP_u16 (inode, i_compress_flag); } +if (le32_to_cpu (inode->i_inline_ext_capacity) >0 ) { +struct f2fs_iext_header *eh = + (struct f2fs_iext_header *)inode->i_extra_end; +u32 cnt =le32_to_cpu (eh->cnt); +u32 cap =le32_to_cpu (inode->i_inline_ext_capacity); +u32 j; + +DISP_u32 (inode, i_inline_ext_capacity); +printf ("%-30s\t\t[%u / %u]\n" , +"inline_ext (cnt/cap)" , cnt, cap); +for (j =0 ; j < cnt && j < cap; j++) { +printf (" inline_ext[%u]: fofs:%x blkaddr:%x len:%x\n" , + j,le32_to_cpu (eh->exts[j].fofs), +le32_to_cpu (eh->exts[j].blk_addr), +le32_to_cpu (eh->exts[j].len)); + } + } } addrs =ADDRS_PER_INODE (inode);
Signature · 8 lines
2.43.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel