Skip to contentSkip to conversation

fsck: add inline extent format support

RFC PATCH New Yongpeng Yang 1 participant 3 messages May 29

lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 1/3 fsck: add inline extent format support

From: Yongpeng Yang <[email protected]>

Add inline extent format recognition and handling to fsck.f2fs.

The inline extent format repurposes the inode's direct block address area (i_addr[]) to store compact extent entries, identified by dual magic numbers (0xF2F5EF00, 0xFFFFFFFD). This patch enables fsck to correctly parse, validate, and repair inodes using this format.

Changes:
- iextent.h/iextent.c: core extent operations including binary search lookup, insert with merge/split, truncate, and format conversion between inline extent and direct block formats
- node.h: update datablock_addr() to query inline extent first
- node.c: update set_data_blkaddr() to maintain inline extent format
- mount.c: handle inline extent in block address update path
- fsck.c: add sanity check for inline extent integrity
- dump.c: use datablock_addr() for consistent block address access

---
v2:
- Rename __is_extent_mergeable to __is_iextent_mergeable.
- Remove NULL_ADDR caching support from merge/split logic.
- Unify fofs range check to "fofs >= direct_blocks".
- Fix f2fs_iext_sanity_check overlap detection (use <= instead of <).
- Fix f2fs_iext_truncate_from_blkaddr write ordering to match kernel.
- Refactor datablock_addr/set_data_blkaddr to reduce #ifdef nesting.
- Code style fixes to comply with 80-column limit.

---
 fsck/dump.c    |   4 +-
 fsck/fsck.c    |  39 ++-
 fsck/iextent.c | 787 +++++++++++++++++++++++++++++++++++++++++++++++++
 fsck/iextent.h | 100 +++++++
 fsck/mount.c   |  67 ++++-
 fsck/node.c    |  31 ++
 fsck/node.h    |  16 +
 7 files changed, 1029 insertions(+), 15 deletions(-)
 create mode 100644 fsck/iextent.c
 create mode 100644 fsck/iextent.h
fsck/dump.c +2 -2
index c68dc6e..d7ecfa8 100644
@@ -547,8 +547,8 @@ static int dump_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
 
 	/* check data blocks in inode */
 	for (i = 0; i < addr_per_inode; i++, ofs++)
-		dump_data_blk(sbi, ofs * F2FS_BLKSIZE, le32_to_cpu(
-			node_blk->i.i_addr[get_extra_isize(node_blk) + i]), type);
+		dump_data_blk(sbi, ofs * F2FS_BLKSIZE,
+			datablock_addr(node_blk, i), type);
 
 	/* check node blocks in inode */
 	for (i = 0; i < 5; i++) {
fsck/fsck.c +32 -7
index 4fca4dd..cbc1cfe 100644
@@ -274,7 +274,7 @@ static int is_valid_summary(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
 
 		if (ofs + ofs_in_node >= DEF_ADDRS_PER_INODE)
 			goto out;
-		target_blk_addr = node_blk->i.i_addr[ofs + ofs_in_node];
+		target_blk_addr = datablock_addr(node_blk, ofs_in_node);
 	} else {
 		if (ofs_in_node >= DEF_ADDRS_PER_BLOCK)
 			goto out;
@@ -562,6 +562,14 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid,
 				p10);
 		}
 	}
+
+#ifdef HAVE_INLINE_EXTENT
+	if (IS_INODE(node_blk) &&
+			f2fs_iext_support_inline_extent(node_blk) &&
+			f2fs_iext_sanity_check(node_blk))
+		return -EINVAL;
+#endif
+
 	return 0;
 }
 
@@ -1211,7 +1219,7 @@ check_next:
 	}
 
 	for (idx = 0; idx < addrs; idx++, child.pgofs++) {
-		block_t blkaddr = le32_to_cpu(node_blk->i.i_addr[ofs + idx]);
+		block_t blkaddr = datablock_addr(node_blk, idx);
 
 		/* check extent info */
 		check_extent_info(&child, blkaddr, 0);
@@ -1247,14 +1255,20 @@ check_next:
 				&child, (i_blocks == *blk_cnt),
 				ftype, nid, idx, ni->version,
 				node_blk);
-		if (blkaddr != le32_to_cpu(node_blk->i.i_addr[ofs + idx]))
+		if (blkaddr != datablock_addr(node_blk, idx))
 			need_fix = 1;
 		if (!ret) {
 			*blk_cnt = *blk_cnt + 1;
 			if (cur_qtype != -1 && blkaddr != NEW_ADDR)
 				qf_last_blkofs[cur_qtype] = child.pgofs;
 		} else if (c.fix_on) {
-			node_blk->i.i_addr[ofs + idx] = NULL_ADDR;
+			struct dnode_of_data dn;
+
+			dn.inode_blk = node_blk;
+			dn.node_blk = node_blk;
+			dn.data_blkaddr = NULL_ADDR;
+			dn.ofs_in_node = idx;
+			set_data_blkaddr(&dn);
 			need_fix = 1;
 			FIX_MSG("[0x%x] i_addr[%d] = NULL_ADDR", nid, ofs + idx);
 		}
@@ -1498,6 +1512,18 @@ skip_dot_fix:
 	}
 
 	if (need_fix && f2fs_dev_is_writable()) {
+#ifdef HAVE_INLINE_EXTENT
+		/*
+		 * Truncate inline extent area to direct blocks boundary.
+		 * This removes any extent entries beyond ADDRS_PER_INODE,
+		 * ensuring inline extent doesn't reference indirect node
+		 * blocks.
+		 */
+		ASSERT(IS_INODE(node_blk));
+		if (f2fs_iext_support_inline_extent(node_blk))
+			f2fs_iext_truncate_from_blkaddr(node_blk,
+					ADDRS_PER_INODE(&node_blk->i));
+#endif
 		ret = update_block(sbi, node_blk, &ni->blk_addr, NULL);
 		ASSERT(ret >= 0);
 	}
@@ -3366,7 +3392,7 @@ static void fsck_disconnect_file(struct f2fs_sb_info *sbi, nid_t ino,
 	struct f2fs_node *node;
 	struct node_info ni;
 	nid_t nid;
-	int ofs, i, err;
+	int i, err;
 
 	node = calloc(F2FS_BLKSIZE, 1);
 	ASSERT(node);
@@ -3397,9 +3423,8 @@ static void fsck_disconnect_file(struct f2fs_sb_info *sbi, nid_t ino,
 	if (!(node->i.i_inline & (F2FS_INLINE_DATA | F2FS_INLINE_DENTRY))) {
 		u32 addrs = ADDRS_PER_INODE(&node->i);
 
-		ofs = get_extra_isize(node);
 		for (i = 0; i < addrs; i++) {
-			block_t addr = le32_to_cpu(node->i.i_addr[ofs + i]);
+			block_t addr = datablock_addr(node, i);
 			if (!addr)
 				continue;
 			release_block_cnt(sbi, dealloc);
fsck/iextent.c new file +787 -0

787 lines not on this page · raw message

fsck/iextent.h new file +100 -0

100 lines not on this page · raw message

fsck/mount.c +61 -6

117 lines not on this page · raw message

fsck/node.c +31 -0
index 8d4479c..356a81a 100644
@@ -100,6 +100,37 @@ void set_data_blkaddr(struct dnode_of_data *dn)
 	struct f2fs_node *node_blk = dn->node_blk;
 	unsigned int ofs_in_node = dn->ofs_in_node;
 
+#ifdef HAVE_INLINE_EXTENT
+	if (f2fs_iext_support_inline_extent(dn->inode_blk)) {
+		int ret = 0;
+		int direct_blocks = ADDRS_PER_INODE(&dn->inode_blk->i);
+		block_t fofs;
+
+		fofs = start_bidx_of_node(ofs_of_node(node_blk),
+					dn->node_blk) + ofs_in_node;
+
+		/* Truncate all blocks after direct_blocks position */
+		if (f2fs_iext_last_fofs(dn->inode_blk) >= direct_blocks) {
+			f2fs_iext_truncate_from_blkaddr(dn->inode_blk,
+					direct_blocks);
+			dn->idirty = 1;
+		}
+
+		if (fofs < direct_blocks) {
+			ret = f2fs_iext_update_data_blkaddr(dn->inode_blk, fofs,
+					dn->data_blkaddr);
+			if (!ret) {
+				dn->idirty = 1;
+				return;
+			}
+			DBG(1, "Converting from inline extent to direct blocks at fofs=%u\n",
+			    fofs);
+			f2fs_iext_convert_to_direct_blocks(dn->inode_blk);
+		}
+		/* For non-inode nodes or non-inline-extent format, fallback. */
+	}
+#endif
+
 	addr_array = blkaddr_in_node(node_blk);
 	addr_array[ofs_in_node] = cpu_to_le32(dn->data_blkaddr);
 	if (dn->node_blk != dn->inode_blk)
fsck/node.h +16 -0
index f3e2c46..023d636 100644
@@ -17,6 +17,9 @@
 #define _NODE_H_
 
 #include "fsck.h"
+#ifdef HAVE_INLINE_EXTENT
+#include "iextent.h"
+#endif
 
 static inline bool IS_INODE(struct f2fs_node *node)
 {
@@ -64,6 +67,19 @@ static inline block_t datablock_addr(struct f2fs_node *node_page,
 	__le32 *addr_array;
 
 	ASSERT(node_page);
+
+#ifdef HAVE_INLINE_EXTENT
+	if (IS_INODE(node_page) && f2fs_iext_support_inline_extent(node_page)) {
+		block_t blkaddr;
+
+		/* Query inline extent, node offset is equal to file's offset */
+		if (f2fs_iext_lookup_blkaddr(node_page, offset,
+					&blkaddr, NULL) == 0)
+			return blkaddr;
+		/* If not found in inline extent, it's unexpected. */
+		ASSERT(0);
+	}
+#endif
 	addr_array = blkaddr_in_node(node_page);
 	return le32_to_cpu(addr_array[offset]);
 }
Signature · 8 lines
2.43.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw

RFC PATCH v2 2/3 build: add inline extent build support

From: Yongpeng Yang <[email protected]>

Add build system configuration for inline extent feature:
- Add --disable-inline-extent configure option (enabled by default)
- Add iextent.c and iextent.h to fsck build sources
- Define HAVE_INLINE_EXTENT macro when feature is enabled

---
 configure.ac     | 10 ++++++++++
 fsck/Makefile.am |  4 ++--
 2 files changed, 12 insertions(+), 2 deletions(-)
configure.ac +10 -0
index 4d91605..0d140b4 100644
@@ -62,6 +62,16 @@ AC_ARG_WITH([lz4],
 	[],
 	[with_lz4=check])
 
+AC_ARG_ENABLE([inline-extent],
+	[AS_HELP_STRING([--disable-inline-extent],
+	  [Disable inline extent support (enabled by default)])],
+	[],
+	[enable_inline_extent=yes])
+
+AS_IF([test "x$enable_inline_extent" = "xyes"],
+	[AC_DEFINE([HAVE_INLINE_EXTENT], [1],
+		[Define if inline extent support is enabled])])
+
 # Checks for programs.
 AC_PROG_CC
 AM_PROG_AR
fsck/Makefile.am +2 -2
index f0d7f87..9694538 100644
@@ -4,12 +4,12 @@ AM_CPPFLAGS = ${libuuid_CFLAGS} -I$(top_srcdir)/include
 AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64
 sbin_PROGRAMS = fsck.f2fs
 noinst_HEADERS = common.h dict.h dqblk_v2.h f2fs.h fsck.h node.h quotaio.h \
-		quotaio_tree.h quotaio_v2.h xattr.h compress.h inject.h
+		quotaio_tree.h quotaio_v2.h xattr.h compress.h inject.h iextent.h
 include_HEADERS = $(top_srcdir)/include/quota.h
 fsck_f2fs_SOURCES = main.c fsck.c dump.c mount.c defrag.c resize.c \
 		node.c segment.c dir.c sload.c xattr.c compress.c \
 		dict.c mkquota.c quotaio.c quotaio_tree.c quotaio_v2.c \
-		inject.c
+		inject.c iextent.c
 fsck_f2fs_LDADD = ${libselinux_LIBS} ${libuuid_LIBS} \
 	${liblzo2_LIBS} ${liblz4_LIBS} ${libwinpthread_LIBS} \
 	$(top_builddir)/lib/libf2fs.la
Signature · 8 lines
2.43.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#2 lore raw

RFC PATCH v2 3/3 f2fs_io: add support to clear/set extent flags

In reply to Yongpeng Yang

From: Yongpeng Yang <[email protected]>

Add support to clear or set extent flags through ioctl for the inline extent feature. This allows users to enable or disable inline extent format on individual files via the f2fs_io tool.

---
 tools/f2fs_io/f2fs_io.c | 16 ++++++++++++++--
 tools/f2fs_io/f2fs_io.h |  3 +++
 2 files changed, 17 insertions(+), 2 deletions(-)
tools/f2fs_io/f2fs_io.c +14 -2
index 94e61b8..1a8c6a2 100644
@@ -317,6 +317,12 @@ static void do_getflags(int argc, char **argv, const struct cmd_desc *cmd)
 		printf("immutable");
 		exist = 1;
 	}
+	if (flag & FS_EXTENT_FL) {
+		if (exist)
+			printf(",");
+		printf("extent");
+		exist = 1;
+	}
 	if (!exist)
 		printf("none");
 	printf("\n");
@@ -332,7 +338,8 @@ static void do_getflags(int argc, char **argv, const struct cmd_desc *cmd)
 "  compression\n"						\
 "  nocompression\n"						\
 "  immutable\n"							\
-"  nocow\n"
+"  nocow\n"							\
+"  extent\n"
 
 static void do_setflags(int argc, char **argv, const struct cmd_desc *cmd)
 {
@@ -362,6 +369,8 @@ static void do_setflags(int argc, char **argv, const struct cmd_desc *cmd)
 		flag |= FS_IMMUTABLE_FL;
 	else if (!strcmp(argv[1], "nocow"))
 		flag |= FS_NOCOW_FL;
+	else if (!strcmp(argv[1], "extent"))
+		flag |= FS_EXTENT_FL;
 
 	ret = ioctl(fd, F2FS_IOC_SETFLAGS, &flag);
 	printf("set a flag on %s ret=%d, flags=%s\n", argv[2], ret, argv[1]);
@@ -378,7 +387,8 @@ static void do_setflags(int argc, char **argv, const struct cmd_desc *cmd)
 "  compression\n"						\
 "  nocompression\n"						\
 "  immutable\n"							\
-"  nocow\n"
+"  nocow\n"							\
+"  extent\n"
 
 static void do_clearflags(int argc, char **argv, const struct cmd_desc *cmd)
 {
@@ -406,6 +416,8 @@ static void do_clearflags(int argc, char **argv, const struct cmd_desc *cmd)
 		flag &= ~FS_IMMUTABLE_FL;
 	else if (!strcmp(argv[1], "nocow"))
 		flag &= ~FS_NOCOW_FL;
+	else if (!strcmp(argv[1], "extent"))
+		flag &= ~FS_EXTENT_FL;
 
 	ret = ioctl(fd, F2FS_IOC_SETFLAGS, &flag);
 	printf("clear a flag on %s ret=%d, flags=%s\n", argv[2], ret, argv[1]);
tools/f2fs_io/f2fs_io.h +3 -0
index 539964f..5e85dc7 100644
@@ -222,6 +222,9 @@ enum {
 #ifndef FS_NOCOW_FL
 #define FS_NOCOW_FL			0x00800000 /* Do not cow file */
 #endif
+#ifndef FS_EXTENT_FL
+#define FS_EXTENT_FL			0x00080000 /* Extent file */
+#endif
 #ifndef FS_NOCOMP_FL
 #define FS_NOCOMP_FL			0x00000400 /* Don't compress */
 #endif
Signature · 8 lines
2.43.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel