Skip to content

Commit f4d0ec0

Browse files
committed
Merge tag 'erofs-for-7.0-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs
Pull erofs fixes from Gao Xiang: - Do not share the page cache if the real @aops differs - Fix the incomplete condition for interlaced plain extents - Get rid of more unnecessary #ifdefs * tag 'erofs-for-7.0-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs: erofs: fix interlaced plain identification for encoded extents erofs: remove more unnecessary #ifdefs erofs: allow sharing page cache with the same aops only
2 parents d9d32e5 + 4a2d046 commit f4d0ec0

5 files changed

Lines changed: 63 additions & 68 deletions

File tree

fs/erofs/inode.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ static int erofs_read_inode(struct inode *inode)
222222

223223
static int erofs_fill_inode(struct inode *inode)
224224
{
225+
const struct address_space_operations *aops;
225226
int err;
226227

227228
trace_erofs_fill_inode(inode);
@@ -254,7 +255,11 @@ static int erofs_fill_inode(struct inode *inode)
254255
}
255256

256257
mapping_set_large_folios(inode->i_mapping);
257-
return erofs_inode_set_aops(inode, inode, false);
258+
aops = erofs_get_aops(inode, false);
259+
if (IS_ERR(aops))
260+
return PTR_ERR(aops);
261+
inode->i_mapping->a_ops = aops;
262+
return 0;
258263
}
259264

260265
/*

fs/erofs/internal.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -471,26 +471,24 @@ static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count)
471471
return NULL;
472472
}
473473

474-
static inline int erofs_inode_set_aops(struct inode *inode,
475-
struct inode *realinode, bool no_fscache)
474+
static inline const struct address_space_operations *
475+
erofs_get_aops(struct inode *realinode, bool no_fscache)
476476
{
477477
if (erofs_inode_is_data_compressed(EROFS_I(realinode)->datalayout)) {
478478
if (!IS_ENABLED(CONFIG_EROFS_FS_ZIP))
479-
return -EOPNOTSUPP;
479+
return ERR_PTR(-EOPNOTSUPP);
480480
DO_ONCE_LITE_IF(realinode->i_blkbits != PAGE_SHIFT,
481481
erofs_info, realinode->i_sb,
482482
"EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!");
483-
inode->i_mapping->a_ops = &z_erofs_aops;
484-
return 0;
483+
return &z_erofs_aops;
485484
}
486-
inode->i_mapping->a_ops = &erofs_aops;
487485
if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && !no_fscache &&
488486
erofs_is_fscache_mode(realinode->i_sb))
489-
inode->i_mapping->a_ops = &erofs_fscache_access_aops;
487+
return &erofs_fscache_access_aops;
490488
if (IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) &&
491489
erofs_is_fileio_mode(EROFS_SB(realinode->i_sb)))
492-
inode->i_mapping->a_ops = &erofs_fileio_aops;
493-
return 0;
490+
return &erofs_fileio_aops;
491+
return &erofs_aops;
494492
}
495493

496494
int erofs_register_sysfs(struct super_block *sb);

fs/erofs/ishare.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ bool erofs_ishare_fill_inode(struct inode *inode)
4040
{
4141
struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
4242
struct erofs_inode *vi = EROFS_I(inode);
43+
const struct address_space_operations *aops;
4344
struct erofs_inode_fingerprint fp;
4445
struct inode *sharedinode;
4546
unsigned long hash;
4647

48+
aops = erofs_get_aops(inode, true);
49+
if (IS_ERR(aops))
50+
return false;
4751
if (erofs_xattr_fill_inode_fingerprint(&fp, inode, sbi->domain_id))
4852
return false;
4953
hash = xxh32(fp.opaque, fp.size, 0);
@@ -56,15 +60,15 @@ bool erofs_ishare_fill_inode(struct inode *inode)
5660
}
5761

5862
if (inode_state_read_once(sharedinode) & I_NEW) {
59-
if (erofs_inode_set_aops(sharedinode, inode, true)) {
60-
iget_failed(sharedinode);
61-
kfree(fp.opaque);
62-
return false;
63-
}
63+
sharedinode->i_mapping->a_ops = aops;
6464
sharedinode->i_size = vi->vfs_inode.i_size;
6565
unlock_new_inode(sharedinode);
6666
} else {
6767
kfree(fp.opaque);
68+
if (aops != sharedinode->i_mapping->a_ops) {
69+
iput(sharedinode);
70+
return false;
71+
}
6872
if (sharedinode->i_size != vi->vfs_inode.i_size) {
6973
_erofs_printk(inode->i_sb, KERN_WARNING
7074
"size(%lld:%lld) not matches for the same fingerprint\n",

fs/erofs/super.c

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -424,26 +424,23 @@ static const struct fs_parameter_spec erofs_fs_parameters[] = {
424424

425425
static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode)
426426
{
427-
#ifdef CONFIG_FS_DAX
428-
struct erofs_sb_info *sbi = fc->s_fs_info;
429-
430-
switch (mode) {
431-
case EROFS_MOUNT_DAX_ALWAYS:
432-
set_opt(&sbi->opt, DAX_ALWAYS);
433-
clear_opt(&sbi->opt, DAX_NEVER);
434-
return true;
435-
case EROFS_MOUNT_DAX_NEVER:
436-
set_opt(&sbi->opt, DAX_NEVER);
437-
clear_opt(&sbi->opt, DAX_ALWAYS);
438-
return true;
439-
default:
427+
if (IS_ENABLED(CONFIG_FS_DAX)) {
428+
struct erofs_sb_info *sbi = fc->s_fs_info;
429+
430+
if (mode == EROFS_MOUNT_DAX_ALWAYS) {
431+
set_opt(&sbi->opt, DAX_ALWAYS);
432+
clear_opt(&sbi->opt, DAX_NEVER);
433+
return true;
434+
} else if (mode == EROFS_MOUNT_DAX_NEVER) {
435+
set_opt(&sbi->opt, DAX_NEVER);
436+
clear_opt(&sbi->opt, DAX_ALWAYS);
437+
return true;
438+
}
440439
DBG_BUGON(1);
441440
return false;
442441
}
443-
#else
444442
errorfc(fc, "dax options not supported");
445443
return false;
446-
#endif
447444
}
448445

449446
static int erofs_fc_parse_param(struct fs_context *fc,
@@ -460,31 +457,26 @@ static int erofs_fc_parse_param(struct fs_context *fc,
460457

461458
switch (opt) {
462459
case Opt_user_xattr:
463-
#ifdef CONFIG_EROFS_FS_XATTR
464-
if (result.boolean)
460+
if (!IS_ENABLED(CONFIG_EROFS_FS_XATTR))
461+
errorfc(fc, "{,no}user_xattr options not supported");
462+
else if (result.boolean)
465463
set_opt(&sbi->opt, XATTR_USER);
466464
else
467465
clear_opt(&sbi->opt, XATTR_USER);
468-
#else
469-
errorfc(fc, "{,no}user_xattr options not supported");
470-
#endif
471466
break;
472467
case Opt_acl:
473-
#ifdef CONFIG_EROFS_FS_POSIX_ACL
474-
if (result.boolean)
468+
if (!IS_ENABLED(CONFIG_EROFS_FS_POSIX_ACL))
469+
errorfc(fc, "{,no}acl options not supported");
470+
else if (result.boolean)
475471
set_opt(&sbi->opt, POSIX_ACL);
476472
else
477473
clear_opt(&sbi->opt, POSIX_ACL);
478-
#else
479-
errorfc(fc, "{,no}acl options not supported");
480-
#endif
481474
break;
482475
case Opt_cache_strategy:
483-
#ifdef CONFIG_EROFS_FS_ZIP
484-
sbi->opt.cache_strategy = result.uint_32;
485-
#else
486-
errorfc(fc, "compression not supported, cache_strategy ignored");
487-
#endif
476+
if (!IS_ENABLED(CONFIG_EROFS_FS_ZIP))
477+
errorfc(fc, "compression not supported, cache_strategy ignored");
478+
else
479+
sbi->opt.cache_strategy = result.uint_32;
488480
break;
489481
case Opt_dax:
490482
if (!erofs_fc_set_dax_mode(fc, EROFS_MOUNT_DAX_ALWAYS))
@@ -533,24 +525,21 @@ static int erofs_fc_parse_param(struct fs_context *fc,
533525
break;
534526
#endif
535527
case Opt_directio:
536-
#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE
537-
if (result.boolean)
528+
if (!IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE))
529+
errorfc(fc, "%s option not supported", erofs_fs_parameters[opt].name);
530+
else if (result.boolean)
538531
set_opt(&sbi->opt, DIRECT_IO);
539532
else
540533
clear_opt(&sbi->opt, DIRECT_IO);
541-
#else
542-
errorfc(fc, "%s option not supported", erofs_fs_parameters[opt].name);
543-
#endif
544534
break;
545535
case Opt_fsoffset:
546536
sbi->dif0.fsoff = result.uint_64;
547537
break;
548538
case Opt_inode_share:
549-
#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE
550-
set_opt(&sbi->opt, INODE_SHARE);
551-
#else
552-
errorfc(fc, "%s option not supported", erofs_fs_parameters[opt].name);
553-
#endif
539+
if (!IS_ENABLED(CONFIG_EROFS_FS_PAGE_CACHE_SHARE))
540+
errorfc(fc, "%s option not supported", erofs_fs_parameters[opt].name);
541+
else
542+
set_opt(&sbi->opt, INODE_SHARE);
554543
break;
555544
}
556545
return 0;
@@ -809,8 +798,7 @@ static int erofs_fc_get_tree(struct fs_context *fc)
809798
ret = get_tree_bdev_flags(fc, erofs_fc_fill_super,
810799
IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) ?
811800
GET_TREE_BDEV_QUIET_LOOKUP : 0);
812-
#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE
813-
if (ret == -ENOTBLK) {
801+
if (IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) && ret == -ENOTBLK) {
814802
struct file *file;
815803

816804
if (!fc->source)
@@ -824,7 +812,6 @@ static int erofs_fc_get_tree(struct fs_context *fc)
824812
sbi->dif0.file->f_mapping->a_ops->read_folio)
825813
return get_tree_nodev(fc, erofs_fc_fill_super);
826814
}
827-
#endif
828815
return ret;
829816
}
830817

@@ -1108,12 +1095,12 @@ static int erofs_show_options(struct seq_file *seq, struct dentry *root)
11081095
seq_puts(seq, ",dax=never");
11091096
if (erofs_is_fileio_mode(sbi) && test_opt(opt, DIRECT_IO))
11101097
seq_puts(seq, ",directio");
1111-
#ifdef CONFIG_EROFS_FS_ONDEMAND
1112-
if (sbi->fsid)
1113-
seq_printf(seq, ",fsid=%s", sbi->fsid);
1114-
if (sbi->domain_id)
1115-
seq_printf(seq, ",domain_id=%s", sbi->domain_id);
1116-
#endif
1098+
if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND)) {
1099+
if (sbi->fsid)
1100+
seq_printf(seq, ",fsid=%s", sbi->fsid);
1101+
if (sbi->domain_id)
1102+
seq_printf(seq, ",domain_id=%s", sbi->domain_id);
1103+
}
11171104
if (sbi->dif0.fsoff)
11181105
seq_printf(seq, ",fsoffset=%llu", sbi->dif0.fsoff);
11191106
if (test_opt(opt, INODE_SHARE))

fs/erofs/zmap.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ static int z_erofs_map_blocks_ext(struct inode *inode,
513513
unsigned int recsz = z_erofs_extent_recsize(vi->z_advise);
514514
erofs_off_t pos = round_up(Z_EROFS_MAP_HEADER_END(erofs_iloc(inode) +
515515
vi->inode_isize + vi->xattr_isize), recsz);
516+
unsigned int bmask = sb->s_blocksize - 1;
516517
bool in_mbox = erofs_inode_in_metabox(inode);
517518
erofs_off_t lend = inode->i_size;
518519
erofs_off_t l, r, mid, pa, la, lstart;
@@ -596,17 +597,17 @@ static int z_erofs_map_blocks_ext(struct inode *inode,
596597
map->m_flags |= EROFS_MAP_MAPPED |
597598
EROFS_MAP_FULL_MAPPED | EROFS_MAP_ENCODED;
598599
fmt = map->m_plen >> Z_EROFS_EXTENT_PLEN_FMT_BIT;
600+
if (map->m_plen & Z_EROFS_EXTENT_PLEN_PARTIAL)
601+
map->m_flags |= EROFS_MAP_PARTIAL_REF;
602+
map->m_plen &= Z_EROFS_EXTENT_PLEN_MASK;
599603
if (fmt)
600604
map->m_algorithmformat = fmt - 1;
601-
else if (interlaced && !erofs_blkoff(sb, map->m_pa))
605+
else if (interlaced && !((map->m_pa | map->m_plen) & bmask))
602606
map->m_algorithmformat =
603607
Z_EROFS_COMPRESSION_INTERLACED;
604608
else
605609
map->m_algorithmformat =
606610
Z_EROFS_COMPRESSION_SHIFTED;
607-
if (map->m_plen & Z_EROFS_EXTENT_PLEN_PARTIAL)
608-
map->m_flags |= EROFS_MAP_PARTIAL_REF;
609-
map->m_plen &= Z_EROFS_EXTENT_PLEN_MASK;
610611
}
611612
}
612613
map->m_llen = lend - map->m_la;

0 commit comments

Comments
 (0)