f2fs-tools: get rid of unneeded fields in on-disk inode
authorChao Yu <yuchao0@huawei.com>
Sun, 28 Apr 2019 09:17:37 +0000 (17:17 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 21 May 2019 00:29:50 +0000 (17:29 -0700)
As Jaegeuk reminded:

Once user updates f2fs-tools which support new fields in inode layout,
but do keep the kernel which can not support those fields, it will cause
old f2fs fail to mount new image due to root_inode's i_extra_isize value
sanity check.

So if f2fs-tools doesn't enable feature which will use new fields of
inode, we don't need to expand i_extra_isize to include them, let's just
let i_extra_isize point to the end of last valid extra field's position.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/dir.c
fsck/fsck.c
fsck/segment.c
include/f2fs_fs.h
lib/libf2fs.c
mkfs/f2fs_format.c

index 98a0b7a..d20c18c 100644 (file)
@@ -459,8 +459,7 @@ static void init_inode_block(struct f2fs_sb_info *sbi,
 
        if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
                node_blk->i.i_inline |= F2FS_EXTRA_ATTR;
-               node_blk->i.i_extra_isize =
-                               cpu_to_le16(F2FS_TOTAL_EXTRA_ATTR_SIZE);
+               node_blk->i.i_extra_isize = cpu_to_le16(calc_extra_isize());
        }
 
        node_blk->footer.ino = cpu_to_le32(de->ino);
index 23a32ab..07657b8 100644 (file)
@@ -733,12 +733,12 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
                        if (node_blk->i.i_extra_isize >
                                cpu_to_le16(F2FS_TOTAL_EXTRA_ATTR_SIZE)) {
                                FIX_MSG("ino[0x%x] recover i_extra_isize "
-                                       "from %u to %lu",
+                                       "from %u to %u",
                                        nid,
                                        le16_to_cpu(node_blk->i.i_extra_isize),
-                                       F2FS_TOTAL_EXTRA_ATTR_SIZE);
+                                       calc_extra_isize());
                                node_blk->i.i_extra_isize =
-                                       cpu_to_le16(F2FS_TOTAL_EXTRA_ATTR_SIZE);
+                                       cpu_to_le16(calc_extra_isize());
                                need_fix = 1;
                        }
                } else {
index 4ce623f..98c836e 100644 (file)
@@ -320,7 +320,7 @@ int f2fs_build_file(struct f2fs_sb_info *sbi, struct dentry *de)
                if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
                        node_blk->i.i_inline |= F2FS_EXTRA_ATTR;
                        node_blk->i.i_extra_isize =
-                               cpu_to_le16(F2FS_TOTAL_EXTRA_ATTR_SIZE);
+                                       cpu_to_le16(calc_extra_isize());
                }
                n = read(fd, buffer, BLOCK_SZ);
                ASSERT((unsigned long)n == de->size);
index f0d2bcf..9871f4a 100644 (file)
@@ -751,9 +751,10 @@ struct f2fs_extent {
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 #endif
 
+#define F2FS_EXTRA_ISIZE_OFFSET                                \
+       offsetof(struct f2fs_inode, i_extra_isize)
 #define F2FS_TOTAL_EXTRA_ATTR_SIZE                     \
-       (offsetof(struct f2fs_inode, i_extra_end) -     \
-       offsetof(struct f2fs_inode, i_extra_isize))     \
+       (offsetof(struct f2fs_inode, i_extra_end) - F2FS_EXTRA_ISIZE_OFFSET)
 
 #define        F2FS_DEF_PROJID         0       /* default project ID */
 
@@ -1156,6 +1157,7 @@ extern int f2fs_devs_are_umounted(void);
 extern int f2fs_dev_is_writable(void);
 extern int f2fs_dev_is_umounted(char *);
 extern int f2fs_get_device_info(void);
+extern unsigned int calc_extra_isize(void);
 extern int get_device_info(int);
 extern int f2fs_init_sparse_file(void);
 extern int f2fs_finalize_device(void);
index e0ce029..c9b0109 100644 (file)
@@ -1139,3 +1139,19 @@ int f2fs_get_device_info(void)
                                        (c.sector_size >> 9)) >> 11);
        return 0;
 }
+
+unsigned int calc_extra_isize(void)
+{
+       unsigned int size = offsetof(struct f2fs_inode, i_projid);
+
+       if (c.feature & cpu_to_le32(F2FS_FEATURE_FLEXIBLE_INLINE_XATTR))
+               size = offsetof(struct f2fs_inode, i_projid);
+       if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA))
+               size = offsetof(struct f2fs_inode, i_inode_checksum);
+       if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CHKSUM))
+               size = offsetof(struct f2fs_inode, i_crtime);
+       if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CRTIME))
+               size = offsetof(struct f2fs_inode, i_extra_end);
+
+       return size - F2FS_EXTRA_ISIZE_OFFSET;
+}
index a2685cb..dc6203e 100644 (file)
@@ -1113,8 +1113,7 @@ static int f2fs_write_root_inode(void)
 
        if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
                raw_node->i.i_inline = F2FS_EXTRA_ATTR;
-               raw_node->i.i_extra_isize =
-                               cpu_to_le16(F2FS_TOTAL_EXTRA_ATTR_SIZE);
+               raw_node->i.i_extra_isize = cpu_to_le16(calc_extra_isize());
        }
 
        if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA))
@@ -1270,8 +1269,7 @@ static int f2fs_write_qf_inode(int qtype)
 
        if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
                raw_node->i.i_inline = F2FS_EXTRA_ATTR;
-               raw_node->i.i_extra_isize =
-                               cpu_to_le16(F2FS_TOTAL_EXTRA_ATTR_SIZE);
+               raw_node->i.i_extra_isize = cpu_to_le16(calc_extra_isize());
        }
 
        if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA))
@@ -1473,8 +1471,7 @@ static int f2fs_write_lpf_inode(void)
 
        if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
                raw_node->i.i_inline = F2FS_EXTRA_ATTR;
-               raw_node->i.i_extra_isize =
-                       cpu_to_le16(F2FS_TOTAL_EXTRA_ATTR_SIZE);
+               raw_node->i.i_extra_isize = cpu_to_le16(calc_extra_isize());
        }
 
        if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA))