Skip to content

Commit c36ec00

Browse files
Sheng Yonghsiangkao
authored andcommitted
erofs: add 'fsoffset' mount option to specify filesystem offset
When attempting to use an archive file, such as APEX on android, as a file-backed mount source, it fails because EROFS image within the archive file does not start at offset 0. As a result, a loop or a dm device is still needed to attach the image file at an appropriate offset first. Similarly, if an EROFS image within a block device does not start at offset 0, it cannot be mounted directly either. To address this issue, this patch adds a new mount option `fsoffset=x' to accept a start offset for the primary device. The offset should be aligned to the block size. EROFS will add this offset before performing read requests. Signed-off-by: Sheng Yong <[email protected]> Signed-off-by: Wang Shuai <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Gao Xiang: minor update on documentation and the error message. ] Reviewed-by: Hongbo Li <[email protected]> Signed-off-by: Gao Xiang <[email protected]>
1 parent 12bf25d commit c36ec00

File tree

6 files changed

+25
-6
lines changed

6 files changed

+25
-6
lines changed

Documentation/filesystems/erofs.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ device=%s Specify a path to an extra device to be used together.
128128
fsid=%s Specify a filesystem image ID for Fscache back-end.
129129
domain_id=%s Specify a domain ID in fscache mode so that different images
130130
with the same blobs under a given domain ID can share storage.
131+
fsoffset=%llu Specify block-aligned filesystem offset for the primary device.
131132
=================== =========================================================
132133

133134
Sysfs Entries

fs/erofs/data.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void erofs_put_metabuf(struct erofs_buf *buf)
2727

2828
void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset, bool need_kmap)
2929
{
30-
pgoff_t index = offset >> PAGE_SHIFT;
30+
pgoff_t index = (buf->off + offset) >> PAGE_SHIFT;
3131
struct folio *folio = NULL;
3232

3333
if (buf->page) {
@@ -54,6 +54,7 @@ void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb)
5454
struct erofs_sb_info *sbi = EROFS_SB(sb);
5555

5656
buf->file = NULL;
57+
buf->off = sbi->dif0.fsoff;
5758
if (erofs_is_fileio_mode(sbi)) {
5859
buf->file = sbi->dif0.file; /* some fs like FUSE needs it */
5960
buf->mapping = buf->file->f_mapping;
@@ -299,7 +300,7 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
299300
iomap->private = buf.base;
300301
} else {
301302
iomap->type = IOMAP_MAPPED;
302-
iomap->addr = mdev.m_pa;
303+
iomap->addr = mdev.m_dif->fsoff + mdev.m_pa;
303304
if (flags & IOMAP_DAX)
304305
iomap->addr += mdev.m_dif->dax_part_off;
305306
}

fs/erofs/fileio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ static int erofs_fileio_scan_folio(struct erofs_fileio *io, struct folio *folio)
147147
if (err)
148148
break;
149149
io->rq = erofs_fileio_rq_alloc(&io->dev);
150-
io->rq->bio.bi_iter.bi_sector = io->dev.m_pa >> 9;
150+
io->rq->bio.bi_iter.bi_sector =
151+
(io->dev.m_dif->fsoff + io->dev.m_pa) >> 9;
151152
attached = 0;
152153
}
153154
if (!bio_add_folio(&io->rq->bio, folio, len, cur))

fs/erofs/internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct erofs_device_info {
4444
struct erofs_fscache *fscache;
4545
struct file *file;
4646
struct dax_device *dax_dev;
47-
u64 dax_part_off;
47+
u64 fsoff, dax_part_off;
4848

4949
erofs_blk_t blocks;
5050
erofs_blk_t uniaddr;
@@ -199,6 +199,7 @@ enum {
199199
struct erofs_buf {
200200
struct address_space *mapping;
201201
struct file *file;
202+
u64 off;
202203
struct page *page;
203204
void *base;
204205
};

fs/erofs/super.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ static void erofs_default_options(struct erofs_sb_info *sbi)
359359

360360
enum {
361361
Opt_user_xattr, Opt_acl, Opt_cache_strategy, Opt_dax, Opt_dax_enum,
362-
Opt_device, Opt_fsid, Opt_domain_id, Opt_directio,
362+
Opt_device, Opt_fsid, Opt_domain_id, Opt_directio, Opt_fsoffset,
363363
};
364364

365365
static const struct constant_table erofs_param_cache_strategy[] = {
@@ -386,6 +386,7 @@ static const struct fs_parameter_spec erofs_fs_parameters[] = {
386386
fsparam_string("fsid", Opt_fsid),
387387
fsparam_string("domain_id", Opt_domain_id),
388388
fsparam_flag_no("directio", Opt_directio),
389+
fsparam_u64("fsoffset", Opt_fsoffset),
389390
{}
390391
};
391392

@@ -509,6 +510,9 @@ static int erofs_fc_parse_param(struct fs_context *fc,
509510
errorfc(fc, "%s option not supported", erofs_fs_parameters[opt].name);
510511
#endif
511512
break;
513+
case Opt_fsoffset:
514+
sbi->dif0.fsoff = result.uint_64;
515+
break;
512516
}
513517
return 0;
514518
}
@@ -649,6 +653,14 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
649653
}
650654
}
651655

656+
if (sbi->dif0.fsoff) {
657+
if (sbi->dif0.fsoff & (sb->s_blocksize - 1))
658+
return invalfc(fc, "fsoffset %llu is not aligned to block size %lu",
659+
sbi->dif0.fsoff, sb->s_blocksize);
660+
if (erofs_is_fscache_mode(sb))
661+
return invalfc(fc, "cannot use fsoffset in fscache mode");
662+
}
663+
652664
if (test_opt(&sbi->opt, DAX_ALWAYS)) {
653665
if (!sbi->dif0.dax_dev) {
654666
errorfc(fc, "DAX unsupported by block device. Turning off DAX.");
@@ -978,6 +990,8 @@ static int erofs_show_options(struct seq_file *seq, struct dentry *root)
978990
if (sbi->domain_id)
979991
seq_printf(seq, ",domain_id=%s", sbi->domain_id);
980992
#endif
993+
if (sbi->dif0.fsoff)
994+
seq_printf(seq, ",fsoffset=%llu", sbi->dif0.fsoff);
981995
return 0;
982996
}
983997

fs/erofs/zdata.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,8 @@ static void z_erofs_submit_queue(struct z_erofs_frontend *f,
17371737
bio = bio_alloc(mdev.m_bdev, BIO_MAX_VECS,
17381738
REQ_OP_READ, GFP_NOIO);
17391739
bio->bi_end_io = z_erofs_endio;
1740-
bio->bi_iter.bi_sector = cur >> 9;
1740+
bio->bi_iter.bi_sector =
1741+
(mdev.m_dif->fsoff + cur) >> 9;
17411742
bio->bi_private = q[JQ_SUBMIT];
17421743
if (readahead)
17431744
bio->bi_opf |= REQ_RAHEAD;

0 commit comments

Comments
 (0)