Skip to content

Commit 7b00af2

Browse files
committed
erofs: use struct erofs_device_info for the primary device
Instead of just listing each one directly in `struct erofs_sb_info` except that we still use `sb->s_bdev` for the primary block device. Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e2de3c1 commit 7b00af2

File tree

4 files changed

+22
-31
lines changed

4 files changed

+22
-31
lines changed

fs/erofs/data.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb)
5656

5757
buf->file = NULL;
5858
if (erofs_is_fileio_mode(sbi)) {
59-
buf->file = sbi->fdev; /* some fs like FUSE needs it */
59+
buf->file = sbi->dif0.file; /* some fs like FUSE needs it */
6060
buf->mapping = buf->file->f_mapping;
6161
} else if (erofs_is_fscache_mode(sb))
62-
buf->mapping = sbi->s_fscache->inode->i_mapping;
62+
buf->mapping = sbi->dif0.fscache->inode->i_mapping;
6363
else
6464
buf->mapping = sb->s_bdev->bd_mapping;
6565
}
@@ -201,12 +201,8 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)
201201
erofs_off_t startoff, length;
202202
int id;
203203

204-
map->m_bdev = sb->s_bdev;
205-
map->m_daxdev = EROFS_SB(sb)->dax_dev;
206-
map->m_dax_part_off = EROFS_SB(sb)->dax_part_off;
207-
map->m_fscache = EROFS_SB(sb)->s_fscache;
208-
map->m_fp = EROFS_SB(sb)->fdev;
209-
204+
erofs_fill_from_devinfo(map, &EROFS_SB(sb)->dif0);
205+
map->m_bdev = sb->s_bdev; /* use s_bdev for the primary device */
210206
if (map->m_deviceid) {
211207
down_read(&devs->rwsem);
212208
dif = idr_find(&devs->tree, map->m_deviceid - 1);

fs/erofs/fscache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,22 +657,22 @@ int erofs_fscache_register_fs(struct super_block *sb)
657657
if (IS_ERR(fscache))
658658
return PTR_ERR(fscache);
659659

660-
sbi->s_fscache = fscache;
660+
sbi->dif0.fscache = fscache;
661661
return 0;
662662
}
663663

664664
void erofs_fscache_unregister_fs(struct super_block *sb)
665665
{
666666
struct erofs_sb_info *sbi = EROFS_SB(sb);
667667

668-
erofs_fscache_unregister_cookie(sbi->s_fscache);
668+
erofs_fscache_unregister_cookie(sbi->dif0.fscache);
669669

670670
if (sbi->domain)
671671
erofs_fscache_domain_put(sbi->domain);
672672
else
673673
fscache_relinquish_volume(sbi->volume, NULL, false);
674674

675-
sbi->s_fscache = NULL;
675+
sbi->dif0.fscache = NULL;
676676
sbi->volume = NULL;
677677
sbi->domain = NULL;
678678
}

fs/erofs/internal.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ struct erofs_xattr_prefix_item {
107107
};
108108

109109
struct erofs_sb_info {
110+
struct erofs_device_info dif0;
110111
struct erofs_mount_opts opt; /* options */
111112
#ifdef CONFIG_EROFS_FS_ZIP
112113
/* list for all registered superblocks, mainly for shrinker */
@@ -124,13 +125,9 @@ struct erofs_sb_info {
124125

125126
struct erofs_sb_lz4_info lz4;
126127
#endif /* CONFIG_EROFS_FS_ZIP */
127-
struct file *fdev;
128128
struct inode *packed_inode;
129129
struct erofs_dev_context *devs;
130-
struct dax_device *dax_dev;
131-
u64 dax_part_off;
132130
u64 total_blocks;
133-
u32 primarydevice_blocks;
134131

135132
u32 meta_blkaddr;
136133
#ifdef CONFIG_EROFS_FS_XATTR
@@ -166,7 +163,6 @@ struct erofs_sb_info {
166163

167164
/* fscache support */
168165
struct fscache_volume *volume;
169-
struct erofs_fscache *s_fscache;
170166
struct erofs_domain *domain;
171167
char *fsid;
172168
char *domain_id;
@@ -187,7 +183,7 @@ struct erofs_sb_info {
187183

188184
static inline bool erofs_is_fileio_mode(struct erofs_sb_info *sbi)
189185
{
190-
return IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) && sbi->fdev;
186+
return IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) && sbi->dif0.file;
191187
}
192188

193189
static inline bool erofs_is_fscache_mode(struct super_block *sb)

fs/erofs/super.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static int erofs_scan_devices(struct super_block *sb,
203203
struct erofs_device_info *dif;
204204
int id, err = 0;
205205

206-
sbi->total_blocks = sbi->primarydevice_blocks;
206+
sbi->total_blocks = sbi->dif0.blocks;
207207
if (!erofs_sb_has_device_table(sbi))
208208
ondisk_extradevs = 0;
209209
else
@@ -307,7 +307,7 @@ static int erofs_read_superblock(struct super_block *sb)
307307
sbi->sb_size);
308308
goto out;
309309
}
310-
sbi->primarydevice_blocks = le32_to_cpu(dsb->blocks);
310+
sbi->dif0.blocks = le32_to_cpu(dsb->blocks);
311311
sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr);
312312
#ifdef CONFIG_EROFS_FS_XATTR
313313
sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr);
@@ -602,9 +602,8 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
602602
return -EINVAL;
603603
}
604604

605-
sbi->dax_dev = fs_dax_get_by_bdev(sb->s_bdev,
606-
&sbi->dax_part_off,
607-
NULL, NULL);
605+
sbi->dif0.dax_dev = fs_dax_get_by_bdev(sb->s_bdev,
606+
&sbi->dif0.dax_part_off, NULL, NULL);
608607
}
609608

610609
err = erofs_read_superblock(sb);
@@ -627,7 +626,7 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
627626
}
628627

629628
if (test_opt(&sbi->opt, DAX_ALWAYS)) {
630-
if (!sbi->dax_dev) {
629+
if (!sbi->dif0.dax_dev) {
631630
errorfc(fc, "DAX unsupported by block device. Turning off DAX.");
632631
clear_opt(&sbi->opt, DAX_ALWAYS);
633632
} else if (sbi->blkszbits != PAGE_SHIFT) {
@@ -707,14 +706,13 @@ static int erofs_fc_get_tree(struct fs_context *fc)
707706

708707
if (!fc->source)
709708
return invalf(fc, "No source specified");
710-
711709
file = filp_open(fc->source, O_RDONLY | O_LARGEFILE, 0);
712710
if (IS_ERR(file))
713711
return PTR_ERR(file);
714-
sbi->fdev = file;
712+
sbi->dif0.file = file;
715713

716-
if (S_ISREG(file_inode(sbi->fdev)->i_mode) &&
717-
sbi->fdev->f_mapping->a_ops->read_folio)
714+
if (S_ISREG(file_inode(sbi->dif0.file)->i_mode) &&
715+
sbi->dif0.file->f_mapping->a_ops->read_folio)
718716
return get_tree_nodev(fc, erofs_fc_fill_super);
719717
}
720718
#endif
@@ -771,8 +769,8 @@ static void erofs_sb_free(struct erofs_sb_info *sbi)
771769
erofs_free_dev_context(sbi->devs);
772770
kfree(sbi->fsid);
773771
kfree(sbi->domain_id);
774-
if (sbi->fdev)
775-
fput(sbi->fdev);
772+
if (sbi->dif0.file)
773+
fput(sbi->dif0.file);
776774
kfree(sbi);
777775
}
778776

@@ -817,11 +815,12 @@ static void erofs_kill_sb(struct super_block *sb)
817815
{
818816
struct erofs_sb_info *sbi = EROFS_SB(sb);
819817

820-
if ((IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && sbi->fsid) || sbi->fdev)
818+
if ((IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && sbi->fsid) ||
819+
sbi->dif0.file)
821820
kill_anon_super(sb);
822821
else
823822
kill_block_super(sb);
824-
fs_put_dax(sbi->dax_dev, NULL);
823+
fs_put_dax(sbi->dif0.dax_dev, NULL);
825824
erofs_fscache_unregister_fs(sb);
826825
erofs_sb_free(sbi);
827826
sb->s_fs_info = NULL;

0 commit comments

Comments
 (0)