]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
erofs: add erofs_inode_set_aops helper to set the aops
authorHongbo Li <lihongbo22@huawei.com>
Fri, 23 Jan 2026 07:52:39 +0000 (07:52 +0000)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 23 Jan 2026 12:01:39 +0000 (20:01 +0800)
Add erofs_inode_set_aops helper to set the inode->i_mapping->a_ops
and use IS_ENABLED to make it cleaner.

Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
fs/erofs/inode.c
fs/erofs/internal.h

index bce98c845a186f3709553c1338ca8f1398a00c79..202cbbb4eadaa4faed84f257fbc5519e18c70cdf 100644 (file)
@@ -203,7 +203,6 @@ err_out:
 
 static int erofs_fill_inode(struct inode *inode)
 {
-       struct erofs_inode *vi = EROFS_I(inode);
        int err;
 
        trace_erofs_fill_inode(inode);
@@ -235,28 +234,7 @@ static int erofs_fill_inode(struct inode *inode)
        }
 
        mapping_set_large_folios(inode->i_mapping);
-       if (erofs_inode_is_data_compressed(vi->datalayout)) {
-#ifdef CONFIG_EROFS_FS_ZIP
-               DO_ONCE_LITE_IF(inode->i_blkbits != PAGE_SHIFT,
-                         erofs_info, inode->i_sb,
-                         "EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!");
-               inode->i_mapping->a_ops = &z_erofs_aops;
-#else
-               err = -EOPNOTSUPP;
-#endif
-       } else {
-               inode->i_mapping->a_ops = &erofs_aops;
-#ifdef CONFIG_EROFS_FS_ONDEMAND
-               if (erofs_is_fscache_mode(inode->i_sb))
-                       inode->i_mapping->a_ops = &erofs_fscache_access_aops;
-#endif
-#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE
-               if (erofs_is_fileio_mode(EROFS_SB(inode->i_sb)))
-                       inode->i_mapping->a_ops = &erofs_fileio_aops;
-#endif
-       }
-
-       return err;
+       return erofs_inode_set_aops(inode, inode, false);
 }
 
 /*
index ae4ade00b5787d71cb974ed07486f637e15355d6..aea28c2fe27437b1a1b950cc98df525885f92acb 100644 (file)
@@ -452,6 +452,28 @@ static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count)
        return NULL;
 }
 
+static inline int erofs_inode_set_aops(struct inode *inode,
+                                      struct inode *realinode, bool no_fscache)
+{
+       if (erofs_inode_is_data_compressed(EROFS_I(realinode)->datalayout)) {
+               if (!IS_ENABLED(CONFIG_EROFS_FS_ZIP))
+                       return -EOPNOTSUPP;
+               DO_ONCE_LITE_IF(realinode->i_blkbits != PAGE_SHIFT,
+                         erofs_info, realinode->i_sb,
+                         "EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!");
+               inode->i_mapping->a_ops = &z_erofs_aops;
+               return 0;
+       }
+       inode->i_mapping->a_ops = &erofs_aops;
+       if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && !no_fscache &&
+           erofs_is_fscache_mode(realinode->i_sb))
+               inode->i_mapping->a_ops = &erofs_fscache_access_aops;
+       if (IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) &&
+           erofs_is_fileio_mode(EROFS_SB(realinode->i_sb)))
+               inode->i_mapping->a_ops = &erofs_fileio_aops;
+       return 0;
+}
+
 int erofs_register_sysfs(struct super_block *sb);
 void erofs_unregister_sysfs(struct super_block *sb);
 int __init erofs_init_sysfs(void);