erofs: introduce on-disk lz4 fs configurations
authorGao Xiang <hsiangkao@redhat.com>
Mon, 29 Mar 2021 01:23:07 +0000 (09:23 +0800)
committerGao Xiang <hsiangkao@redhat.com>
Mon, 29 Mar 2021 02:24:58 +0000 (10:24 +0800)
Introduce z_erofs_lz4_cfgs to store all lz4 configurations.
Currently it's only max_distance, but will be used for new
features later.

Link: https://lore.kernel.org/r/20210329012308.28743-4-hsiangkao@aol.com
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
fs/erofs/decompressor.c
fs/erofs/erofs_fs.h
fs/erofs/internal.h
fs/erofs/super.c

index 93411e9df9b67c2dd9f1c2f959e4dbcfe08da06a..97538ff24a19104e6a080ed43d10e73cb1858cb8 100644 (file)
@@ -29,9 +29,20 @@ struct z_erofs_decompressor {
 };
 
 int z_erofs_load_lz4_config(struct super_block *sb,
-                           struct erofs_super_block *dsb)
+                           struct erofs_super_block *dsb,
+                           struct z_erofs_lz4_cfgs *lz4, int size)
 {
-       u16 distance = le16_to_cpu(dsb->lz4_max_distance);
+       u16 distance;
+
+       if (lz4) {
+               if (size < sizeof(struct z_erofs_lz4_cfgs)) {
+                       erofs_err(sb, "invalid lz4 cfgs, size=%u", size);
+                       return -EINVAL;
+               }
+               distance = le16_to_cpu(lz4->max_distance);
+       } else {
+               distance = le16_to_cpu(dsb->lz4_max_distance);
+       }
 
        EROFS_SB(sb)->lz4.max_distance_pages = distance ?
                                        DIV_ROUND_UP(distance, PAGE_SIZE) + 1 :
index dc7cc79410dfd08c32017fe3c65f72b1644ba0fd..700597e9c810dcd249752bee1d8e4fea8ac1543c 100644 (file)
@@ -200,6 +200,12 @@ enum {
        Z_EROFS_COMPRESSION_MAX
 };
 
+/* 14 bytes (+ length field = 16 bytes) */
+struct z_erofs_lz4_cfgs {
+       __le16 max_distance;
+       u8 reserved[12];
+} __packed;
+
 /*
  * bit 0 : COMPACTED_2B indexes (0 - off; 1 - on)
  *  e.g. for 4k logical cluster size,      4B        if compacted 2B is off;
index 875b2ebf2af9d26d63d306b472860cf4f784accd..b02fc64fcece547c3be47a7622066fd5c7a253c6 100644 (file)
@@ -439,7 +439,8 @@ int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
 int erofs_try_to_free_cached_page(struct address_space *mapping,
                                  struct page *page);
 int z_erofs_load_lz4_config(struct super_block *sb,
-                           struct erofs_super_block *dsb);
+                           struct erofs_super_block *dsb,
+                           struct z_erofs_lz4_cfgs *lz4, int len);
 #else
 static inline void erofs_shrinker_register(struct super_block *sb) {}
 static inline void erofs_shrinker_unregister(struct super_block *sb) {}
@@ -448,9 +449,10 @@ static inline void erofs_exit_shrinker(void) {}
 static inline int z_erofs_init_zip_subsystem(void) { return 0; }
 static inline void z_erofs_exit_zip_subsystem(void) {}
 static inline int z_erofs_load_lz4_config(struct super_block *sb,
-                               struct erofs_super_block *dsb)
+                                 struct erofs_super_block *dsb,
+                                 struct z_erofs_lz4_cfgs *lz4, int len)
 {
-       if (dsb->lz4_max_distance) {
+       if (lz4 || dsb->lz4_max_distance) {
                erofs_err(sb, "lz4 algorithm isn't enabled");
                return -EINVAL;
        }
index 3212e4f73f8522a25d74ad8f11d41307b9e00838..1ca8da3f21254054b199c4b7ac961f452639a7e9 100644 (file)
@@ -189,7 +189,7 @@ static int erofs_read_superblock(struct super_block *sb)
        }
 
        /* parse on-disk compression configurations */
-       ret = z_erofs_load_lz4_config(sb, dsb);
+       ret = z_erofs_load_lz4_config(sb, dsb, NULL, 0);
 out:
        kunmap(page);
        put_page(page);