Skip to content

Commit 87a201b

Browse files
committed
Merge tag 'erofs-for-6.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs
Pull erofs updates from Gao Xiang: "Nothing exciting lands for this cycle, since we're still busying in developing support for sub-page blocks and large-folios of compressed data for new scenarios on Android. In this cycle, MicroLZMA format is marked as stable, and there are minor cleanups around documentation and codebase. In addition, it also fixes incorrect lockref usage in erofs_insert_workgroup(). Summary: - Fix inode metadata space layout documentation - Avoid warning for MicroLZMA format anymore - Fix erofs_insert_workgroup() lockref usage - Some cleanups" * tag 'erofs-for-6.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs: erofs: fix erofs_insert_workgroup() lockref usage erofs: tidy up redundant includes erofs: get rid of ROOT_NID() erofs: simplify compression configuration parser erofs: don't warn MicroLZMA format anymore erofs: fix inode metadata space layout description in documentation
2 parents 57aff99 + 1a0ac8b commit 87a201b

File tree

11 files changed

+89
-136
lines changed

11 files changed

+89
-136
lines changed

Documentation/filesystems/erofs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ may not. All metadatas can be now observed in two different spaces (views):
199199
| |
200200
|__________________| 64 bytes
201201

202-
Xattrs, extents, data inline are followed by the corresponding inode with
202+
Xattrs, extents, data inline are placed after the corresponding inode with
203203
proper alignment, and they could be optional for different data mappings.
204204
_currently_ total 5 data layouts are supported:
205205

fs/erofs/Kconfig

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,10 @@ config EROFS_FS_ZIP_LZMA
9191
select XZ_DEC_MICROLZMA
9292
help
9393
Saying Y here includes support for reading EROFS file systems
94-
containing LZMA compressed data, specifically called microLZMA. it
95-
gives better compression ratios than the LZ4 algorithm, at the
94+
containing LZMA compressed data, specifically called microLZMA. It
95+
gives better compression ratios than the default LZ4 format, at the
9696
expense of more CPU overhead.
9797

98-
LZMA support is an experimental feature for now and so most file
99-
systems will be readable without selecting this option.
100-
10198
If unsure, say N.
10299

103100
config EROFS_FS_ZIP_DEFLATE

fs/erofs/compress.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ struct z_erofs_decompress_req {
2121
};
2222

2323
struct z_erofs_decompressor {
24+
int (*config)(struct super_block *sb, struct erofs_super_block *dsb,
25+
void *data, int size);
2426
int (*decompress)(struct z_erofs_decompress_req *rq,
2527
struct page **pagepool);
2628
char *name;
@@ -92,6 +94,10 @@ int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,
9294
extern const struct z_erofs_decompressor erofs_decompressors[];
9395

9496
/* prototypes for specific algorithms */
97+
int z_erofs_load_lzma_config(struct super_block *sb,
98+
struct erofs_super_block *dsb, void *data, int size);
99+
int z_erofs_load_deflate_config(struct super_block *sb,
100+
struct erofs_super_block *dsb, void *data, int size);
95101
int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,
96102
struct page **pagepool);
97103
int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,

fs/erofs/data.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
* Copyright (C) 2021, Alibaba Cloud
66
*/
77
#include "internal.h"
8-
#include <linux/prefetch.h>
98
#include <linux/sched/mm.h>
10-
#include <linux/dax.h>
119
#include <trace/events/erofs.h>
1210

1311
void erofs_unmap_metabuf(struct erofs_buf *buf)

fs/erofs/decompressor.c

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* https://www.huawei.com/
55
*/
66
#include "compress.h"
7-
#include <linux/module.h>
87
#include <linux/lz4.h>
98

109
#ifndef LZ4_DISTANCE_MAX /* history window size */
@@ -24,11 +23,11 @@ struct z_erofs_lz4_decompress_ctx {
2423
unsigned int oend;
2524
};
2625

27-
int z_erofs_load_lz4_config(struct super_block *sb,
28-
struct erofs_super_block *dsb,
29-
struct z_erofs_lz4_cfgs *lz4, int size)
26+
static int z_erofs_load_lz4_config(struct super_block *sb,
27+
struct erofs_super_block *dsb, void *data, int size)
3028
{
3129
struct erofs_sb_info *sbi = EROFS_SB(sb);
30+
struct z_erofs_lz4_cfgs *lz4 = data;
3231
u16 distance;
3332

3433
if (lz4) {
@@ -370,19 +369,75 @@ const struct z_erofs_decompressor erofs_decompressors[] = {
370369
.name = "interlaced"
371370
},
372371
[Z_EROFS_COMPRESSION_LZ4] = {
372+
.config = z_erofs_load_lz4_config,
373373
.decompress = z_erofs_lz4_decompress,
374374
.name = "lz4"
375375
},
376376
#ifdef CONFIG_EROFS_FS_ZIP_LZMA
377377
[Z_EROFS_COMPRESSION_LZMA] = {
378+
.config = z_erofs_load_lzma_config,
378379
.decompress = z_erofs_lzma_decompress,
379380
.name = "lzma"
380381
},
381382
#endif
382383
#ifdef CONFIG_EROFS_FS_ZIP_DEFLATE
383384
[Z_EROFS_COMPRESSION_DEFLATE] = {
385+
.config = z_erofs_load_deflate_config,
384386
.decompress = z_erofs_deflate_decompress,
385387
.name = "deflate"
386388
},
387389
#endif
388390
};
391+
392+
int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
393+
{
394+
struct erofs_sb_info *sbi = EROFS_SB(sb);
395+
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
396+
unsigned int algs, alg;
397+
erofs_off_t offset;
398+
int size, ret = 0;
399+
400+
if (!erofs_sb_has_compr_cfgs(sbi)) {
401+
sbi->available_compr_algs = Z_EROFS_COMPRESSION_LZ4;
402+
return z_erofs_load_lz4_config(sb, dsb, NULL, 0);
403+
}
404+
405+
sbi->available_compr_algs = le16_to_cpu(dsb->u1.available_compr_algs);
406+
if (sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS) {
407+
erofs_err(sb, "unidentified algorithms %x, please upgrade kernel",
408+
sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS);
409+
return -EOPNOTSUPP;
410+
}
411+
412+
erofs_init_metabuf(&buf, sb);
413+
offset = EROFS_SUPER_OFFSET + sbi->sb_size;
414+
alg = 0;
415+
for (algs = sbi->available_compr_algs; algs; algs >>= 1, ++alg) {
416+
void *data;
417+
418+
if (!(algs & 1))
419+
continue;
420+
421+
data = erofs_read_metadata(sb, &buf, &offset, &size);
422+
if (IS_ERR(data)) {
423+
ret = PTR_ERR(data);
424+
break;
425+
}
426+
427+
if (alg >= ARRAY_SIZE(erofs_decompressors) ||
428+
!erofs_decompressors[alg].config) {
429+
erofs_err(sb, "algorithm %d isn't enabled on this kernel",
430+
alg);
431+
ret = -EOPNOTSUPP;
432+
} else {
433+
ret = erofs_decompressors[alg].config(sb,
434+
dsb, data, size);
435+
}
436+
437+
kfree(data);
438+
if (ret)
439+
break;
440+
}
441+
erofs_put_metabuf(&buf);
442+
return ret;
443+
}

fs/erofs/decompressor_deflate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
2-
#include <linux/module.h>
32
#include <linux/zlib.h>
43
#include "compress.h"
54

@@ -77,9 +76,10 @@ int __init z_erofs_deflate_init(void)
7776
}
7877

7978
int z_erofs_load_deflate_config(struct super_block *sb,
80-
struct erofs_super_block *dsb,
81-
struct z_erofs_deflate_cfgs *dfl, int size)
79+
struct erofs_super_block *dsb, void *data, int size)
8280
{
81+
struct z_erofs_deflate_cfgs *dfl = data;
82+
8383
if (!dfl || size < sizeof(struct z_erofs_deflate_cfgs)) {
8484
erofs_err(sb, "invalid deflate cfgs, size=%u", size);
8585
return -EINVAL;

fs/erofs/decompressor_lzma.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22
#include <linux/xz.h>
3-
#include <linux/module.h>
43
#include "compress.h"
54

65
struct z_erofs_lzma {
@@ -72,10 +71,10 @@ int __init z_erofs_lzma_init(void)
7271
}
7372

7473
int z_erofs_load_lzma_config(struct super_block *sb,
75-
struct erofs_super_block *dsb,
76-
struct z_erofs_lzma_cfgs *lzma, int size)
74+
struct erofs_super_block *dsb, void *data, int size)
7775
{
7876
static DEFINE_MUTEX(lzma_resize_mutex);
77+
struct z_erofs_lzma_cfgs *lzma = data;
7978
unsigned int dict_size, i;
8079
struct z_erofs_lzma *strm, *head = NULL;
8180
int err;
@@ -96,8 +95,6 @@ int z_erofs_load_lzma_config(struct super_block *sb,
9695
return -EINVAL;
9796
}
9897

99-
erofs_info(sb, "EXPERIMENTAL MicroLZMA in use. Use at your own risk!");
100-
10198
/* in case 2 z_erofs_load_lzma_config() race to avoid deadlock */
10299
mutex_lock(&lzma_resize_mutex);
103100

fs/erofs/internal.h

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
#define __EROFS_INTERNAL_H
99

1010
#include <linux/fs.h>
11+
#include <linux/dax.h>
1112
#include <linux/dcache.h>
1213
#include <linux/mm.h>
14+
#include <linux/module.h>
1315
#include <linux/pagemap.h>
1416
#include <linux/bio.h>
1517
#include <linux/magic.h>
@@ -228,8 +230,6 @@ struct erofs_buf {
228230
};
229231
#define __EROFS_BUF_INITIALIZER ((struct erofs_buf){ .page = NULL })
230232

231-
#define ROOT_NID(sb) ((sb)->root_nid)
232-
233233
#define erofs_blknr(sb, addr) ((addr) >> (sb)->s_blocksize_bits)
234234
#define erofs_blkoff(sb, addr) ((addr) & ((sb)->s_blocksize - 1))
235235
#define erofs_pos(sb, blk) ((erofs_off_t)(blk) << (sb)->s_blocksize_bits)
@@ -469,9 +469,6 @@ int __init z_erofs_init_zip_subsystem(void);
469469
void z_erofs_exit_zip_subsystem(void);
470470
int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
471471
struct erofs_workgroup *egrp);
472-
int z_erofs_load_lz4_config(struct super_block *sb,
473-
struct erofs_super_block *dsb,
474-
struct z_erofs_lz4_cfgs *lz4, int len);
475472
int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map,
476473
int flags);
477474
void *erofs_get_pcpubuf(unsigned int requiredpages);
@@ -480,23 +477,14 @@ int erofs_pcpubuf_growsize(unsigned int nrpages);
480477
void __init erofs_pcpubuf_init(void);
481478
void erofs_pcpubuf_exit(void);
482479
int erofs_init_managed_cache(struct super_block *sb);
480+
int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb);
483481
#else
484482
static inline void erofs_shrinker_register(struct super_block *sb) {}
485483
static inline void erofs_shrinker_unregister(struct super_block *sb) {}
486484
static inline int erofs_init_shrinker(void) { return 0; }
487485
static inline void erofs_exit_shrinker(void) {}
488486
static inline int z_erofs_init_zip_subsystem(void) { return 0; }
489487
static inline void z_erofs_exit_zip_subsystem(void) {}
490-
static inline int z_erofs_load_lz4_config(struct super_block *sb,
491-
struct erofs_super_block *dsb,
492-
struct z_erofs_lz4_cfgs *lz4, int len)
493-
{
494-
if (lz4 || dsb->u1.lz4_max_distance) {
495-
erofs_err(sb, "lz4 algorithm isn't enabled");
496-
return -EINVAL;
497-
}
498-
return 0;
499-
}
500488
static inline void erofs_pcpubuf_init(void) {}
501489
static inline void erofs_pcpubuf_exit(void) {}
502490
static inline int erofs_init_managed_cache(struct super_block *sb) { return 0; }
@@ -505,41 +493,17 @@ static inline int erofs_init_managed_cache(struct super_block *sb) { return 0; }
505493
#ifdef CONFIG_EROFS_FS_ZIP_LZMA
506494
int __init z_erofs_lzma_init(void);
507495
void z_erofs_lzma_exit(void);
508-
int z_erofs_load_lzma_config(struct super_block *sb,
509-
struct erofs_super_block *dsb,
510-
struct z_erofs_lzma_cfgs *lzma, int size);
511496
#else
512497
static inline int z_erofs_lzma_init(void) { return 0; }
513498
static inline int z_erofs_lzma_exit(void) { return 0; }
514-
static inline int z_erofs_load_lzma_config(struct super_block *sb,
515-
struct erofs_super_block *dsb,
516-
struct z_erofs_lzma_cfgs *lzma, int size) {
517-
if (lzma) {
518-
erofs_err(sb, "lzma algorithm isn't enabled");
519-
return -EINVAL;
520-
}
521-
return 0;
522-
}
523499
#endif /* !CONFIG_EROFS_FS_ZIP_LZMA */
524500

525501
#ifdef CONFIG_EROFS_FS_ZIP_DEFLATE
526502
int __init z_erofs_deflate_init(void);
527503
void z_erofs_deflate_exit(void);
528-
int z_erofs_load_deflate_config(struct super_block *sb,
529-
struct erofs_super_block *dsb,
530-
struct z_erofs_deflate_cfgs *dfl, int size);
531504
#else
532505
static inline int z_erofs_deflate_init(void) { return 0; }
533506
static inline int z_erofs_deflate_exit(void) { return 0; }
534-
static inline int z_erofs_load_deflate_config(struct super_block *sb,
535-
struct erofs_super_block *dsb,
536-
struct z_erofs_deflate_cfgs *dfl, int size) {
537-
if (dfl) {
538-
erofs_err(sb, "deflate algorithm isn't enabled");
539-
return -EINVAL;
540-
}
541-
return 0;
542-
}
543507
#endif /* !CONFIG_EROFS_FS_ZIP_DEFLATE */
544508

545509
#ifdef CONFIG_EROFS_FS_ONDEMAND

0 commit comments

Comments
 (0)