Skip to content

Commit 2e1473d

Browse files
committed
erofs: implement 48-bit block addressing for unencoded inodes
It adapts the on-disk changes from the previous commit. It also supports EROFS_NULL_ADDR (all 1's) for EROFS_INODE_FLAT_PLAIN inodes to indicate 0-filled inodes, as it's common for composefs use cases. As a result, EROFS_INODE_CHUNK_BASED is no longer needed. Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Acked-by: Chao Yu <chao@kernel.org> Link: https://lore.kernel.org/r/20250310095459.2620647-5-hsiangkao@linux.alibaba.com
1 parent 61ba89b commit 2e1473d

File tree

7 files changed

+53
-26
lines changed

7 files changed

+53
-26
lines changed

fs/erofs/data.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map)
7777
unsigned int unit, blksz = sb->s_blocksize;
7878
struct erofs_inode *vi = EROFS_I(inode);
7979
struct erofs_inode_chunk_index *idx;
80-
erofs_blk_t startblk;
80+
erofs_blk_t startblk, addrmask;
8181
bool tailpacking;
8282
erofs_off_t pos;
8383
u64 chunknr;
@@ -91,6 +91,8 @@ int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map)
9191

9292
if (vi->datalayout != EROFS_INODE_CHUNK_BASED) {
9393
tailpacking = (vi->datalayout == EROFS_INODE_FLAT_INLINE);
94+
if (!tailpacking && vi->startblk == EROFS_NULL_ADDR)
95+
goto out;
9496
pos = erofs_pos(sb, erofs_iblks(inode) - tailpacking);
9597

9698
map->m_flags = EROFS_MAP_MAPPED;
@@ -124,16 +126,19 @@ int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map)
124126
map->m_llen = min_t(erofs_off_t, 1UL << vi->chunkbits,
125127
round_up(inode->i_size - map->m_la, blksz));
126128
if (vi->chunkformat & EROFS_CHUNK_FORMAT_INDEXES) {
127-
startblk = le32_to_cpu(idx->startblk_lo);
128-
if (startblk != EROFS_NULL_ADDR) {
129+
addrmask = (vi->chunkformat & EROFS_CHUNK_FORMAT_48BIT) ?
130+
BIT_ULL(48) - 1 : BIT_ULL(32) - 1;
131+
startblk = (((u64)le16_to_cpu(idx->startblk_hi) << 32) |
132+
le32_to_cpu(idx->startblk_lo)) & addrmask;
133+
if ((startblk ^ EROFS_NULL_ADDR) & addrmask) {
129134
map->m_deviceid = le16_to_cpu(idx->device_id) &
130135
EROFS_SB(sb)->device_id_mask;
131136
map->m_pa = erofs_pos(sb, startblk);
132137
map->m_flags = EROFS_MAP_MAPPED;
133138
}
134139
} else {
135140
startblk = le32_to_cpu(*(__le32 *)idx);
136-
if (startblk != EROFS_NULL_ADDR) {
141+
if (startblk != (u32)EROFS_NULL_ADDR) {
137142
map->m_pa = erofs_pos(sb, startblk);
138143
map->m_flags = EROFS_MAP_MAPPED;
139144
}

fs/erofs/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx)
6060

6161
de = erofs_bread(&buf, dbstart, true);
6262
if (IS_ERR(de)) {
63-
erofs_err(sb, "fail to readdir of logical block %u of nid %llu",
63+
erofs_err(sb, "failed to readdir of logical block %llu of nid %llu",
6464
erofs_blknr(sb, dbstart), EROFS_I(dir)->nid);
6565
err = PTR_ERR(de);
6666
break;

fs/erofs/inode.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ static int erofs_read_inode(struct inode *inode)
3131
unsigned int ofs = erofs_blkoff(sb, erofs_iloc(inode));
3232
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
3333
struct erofs_sb_info *sbi = EROFS_SB(sb);
34+
erofs_blk_t addrmask = BIT_ULL(48) - 1;
3435
struct erofs_inode *vi = EROFS_I(inode);
3536
struct erofs_inode_extended *die, copied;
3637
struct erofs_inode_compact *dic;
37-
union erofs_inode_i_u iu;
3838
unsigned int ifmt;
3939
void *ptr;
4040
int err = 0;
@@ -71,6 +71,8 @@ static int erofs_read_inode(struct inode *inode)
7171
if (ofs + vi->inode_isize <= sb->s_blocksize) {
7272
ofs += vi->inode_isize;
7373
die = (struct erofs_inode_extended *)dic;
74+
copied.i_u = die->i_u;
75+
copied.i_nb = die->i_nb;
7476
} else {
7577
const unsigned int gotten = sb->s_blocksize - ofs;
7678

@@ -90,7 +92,6 @@ static int erofs_read_inode(struct inode *inode)
9092
vi->xattr_isize = erofs_xattr_ibody_size(die->i_xattr_icount);
9193

9294
inode->i_mode = le16_to_cpu(die->i_mode);
93-
iu = die->i_u;
9495
i_uid_write(inode, le32_to_cpu(die->i_uid));
9596
i_gid_write(inode, le32_to_cpu(die->i_gid));
9697
set_nlink(inode, le32_to_cpu(die->i_nlink));
@@ -105,11 +106,20 @@ static int erofs_read_inode(struct inode *inode)
105106
vi->xattr_isize = erofs_xattr_ibody_size(dic->i_xattr_icount);
106107

107108
inode->i_mode = le16_to_cpu(dic->i_mode);
108-
iu = dic->i_u;
109+
copied.i_u = dic->i_u;
109110
i_uid_write(inode, le16_to_cpu(dic->i_uid));
110111
i_gid_write(inode, le16_to_cpu(dic->i_gid));
111-
set_nlink(inode, le16_to_cpu(dic->i_nb.nlink));
112-
inode_set_mtime(inode, sbi->build_time, sbi->build_time_nsec);
112+
if (!S_ISDIR(inode->i_mode) &&
113+
((ifmt >> EROFS_I_NLINK_1_BIT) & 1)) {
114+
set_nlink(inode, 1);
115+
copied.i_nb = dic->i_nb;
116+
} else {
117+
set_nlink(inode, le16_to_cpu(dic->i_nb.nlink));
118+
copied.i_nb.startblk_hi = 0;
119+
addrmask = BIT_ULL(32) - 1;
120+
}
121+
inode_set_mtime(inode, sbi->epoch + le32_to_cpu(dic->i_mtime),
122+
sbi->fixed_nsec);
113123

114124
inode->i_size = le32_to_cpu(dic->i_size);
115125
break;
@@ -129,7 +139,12 @@ static int erofs_read_inode(struct inode *inode)
129139
case S_IFREG:
130140
case S_IFDIR:
131141
case S_IFLNK:
132-
vi->startblk = le32_to_cpu(iu.startblk_lo);
142+
vi->startblk = le32_to_cpu(copied.i_u.startblk_lo) |
143+
((u64)le16_to_cpu(copied.i_nb.startblk_hi) << 32);
144+
if (vi->datalayout == EROFS_INODE_FLAT_PLAIN &&
145+
!((vi->startblk ^ EROFS_NULL_ADDR) & addrmask))
146+
vi->startblk = EROFS_NULL_ADDR;
147+
133148
if(S_ISLNK(inode->i_mode)) {
134149
err = erofs_fill_symlink(inode, ptr, ofs);
135150
if (err)
@@ -138,7 +153,7 @@ static int erofs_read_inode(struct inode *inode)
138153
break;
139154
case S_IFCHR:
140155
case S_IFBLK:
141-
inode->i_rdev = new_decode_dev(le32_to_cpu(iu.rdev));
156+
inode->i_rdev = new_decode_dev(le32_to_cpu(copied.i_u.rdev));
142157
break;
143158
case S_IFIFO:
144159
case S_IFSOCK:
@@ -152,14 +167,14 @@ static int erofs_read_inode(struct inode *inode)
152167
}
153168

154169
if (erofs_inode_is_data_compressed(vi->datalayout))
155-
inode->i_blocks = le32_to_cpu(iu.blocks_lo) <<
170+
inode->i_blocks = le32_to_cpu(copied.i_u.blocks_lo) <<
156171
(sb->s_blocksize_bits - 9);
157172
else
158173
inode->i_blocks = round_up(inode->i_size, sb->s_blocksize) >> 9;
159174

160175
if (vi->datalayout == EROFS_INODE_CHUNK_BASED) {
161176
/* fill chunked inode summary info */
162-
vi->chunkformat = le16_to_cpu(iu.c.format);
177+
vi->chunkformat = le16_to_cpu(copied.i_u.c.format);
163178
if (vi->chunkformat & ~EROFS_CHUNK_FORMAT_ALL) {
164179
erofs_err(sb, "unsupported chunk format %x of nid %llu",
165180
vi->chunkformat, vi->nid);

fs/erofs/internal.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ __printf(2, 3) void _erofs_printk(struct super_block *sb, const char *fmt, ...);
3737

3838
typedef u64 erofs_nid_t;
3939
typedef u64 erofs_off_t;
40-
/* data type for filesystem-wide blocks number */
41-
typedef u32 erofs_blk_t;
40+
typedef u64 erofs_blk_t;
4241

4342
struct erofs_device_info {
4443
char *path;
@@ -143,8 +142,8 @@ struct erofs_sb_info {
143142
unsigned char blkszbits; /* filesystem block size in bit shift */
144143

145144
u32 sb_size; /* total superblock size */
146-
u32 build_time_nsec;
147-
u64 build_time;
145+
u32 fixed_nsec;
146+
s64 epoch;
148147

149148
/* what we really care is nid, rather than ino.. */
150149
erofs_nid_t root_nid;
@@ -205,8 +204,8 @@ struct erofs_buf {
205204
};
206205
#define __EROFS_BUF_INITIALIZER ((struct erofs_buf){ .page = NULL })
207206

208-
#define erofs_blknr(sb, addr) ((erofs_blk_t)((addr) >> (sb)->s_blocksize_bits))
209-
#define erofs_blkoff(sb, addr) ((addr) & ((sb)->s_blocksize - 1))
207+
#define erofs_blknr(sb, pos) ((erofs_blk_t)((pos) >> (sb)->s_blocksize_bits))
208+
#define erofs_blkoff(sb, pos) ((pos) & ((sb)->s_blocksize - 1))
210209
#define erofs_pos(sb, blk) ((erofs_off_t)(blk) << (sb)->s_blocksize_bits)
211210
#define erofs_iblks(i) (round_up((i)->i_size, i_blocksize(i)) >> (i)->i_blkbits)
212211

@@ -226,6 +225,7 @@ EROFS_FEATURE_FUNCS(ztailpacking, incompat, INCOMPAT_ZTAILPACKING)
226225
EROFS_FEATURE_FUNCS(fragments, incompat, INCOMPAT_FRAGMENTS)
227226
EROFS_FEATURE_FUNCS(dedupe, incompat, INCOMPAT_DEDUPE)
228227
EROFS_FEATURE_FUNCS(xattr_prefixes, incompat, INCOMPAT_XATTR_PREFIXES)
228+
EROFS_FEATURE_FUNCS(48bit, incompat, INCOMPAT_48BIT)
229229
EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM)
230230
EROFS_FEATURE_FUNCS(xattr_filter, compat, COMPAT_XATTR_FILTER)
231231

fs/erofs/super.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static int erofs_read_superblock(struct super_block *sb)
268268
goto out;
269269
}
270270

271-
sbi->blkszbits = dsb->blkszbits;
271+
sbi->blkszbits = dsb->blkszbits;
272272
if (sbi->blkszbits < 9 || sbi->blkszbits > PAGE_SHIFT) {
273273
erofs_err(sb, "blkszbits %u isn't supported", sbi->blkszbits);
274274
goto out;
@@ -308,13 +308,18 @@ static int erofs_read_superblock(struct super_block *sb)
308308
sbi->xattr_filter_reserved = dsb->xattr_filter_reserved;
309309
#endif
310310
sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact));
311-
sbi->root_nid = le16_to_cpu(dsb->rb.rootnid_2b);
311+
if (erofs_sb_has_48bit(sbi) && dsb->rootnid_8b) {
312+
sbi->root_nid = le64_to_cpu(dsb->rootnid_8b);
313+
sbi->dif0.blocks = (sbi->dif0.blocks << 32) |
314+
le16_to_cpu(dsb->rb.blocks_hi);
315+
} else {
316+
sbi->root_nid = le16_to_cpu(dsb->rb.rootnid_2b);
317+
}
312318
sbi->packed_nid = le64_to_cpu(dsb->packed_nid);
313319
sbi->inos = le64_to_cpu(dsb->inos);
314320

315-
sbi->build_time = le64_to_cpu(dsb->epoch);
316-
sbi->build_time_nsec = le32_to_cpu(dsb->fixed_nsec);
317-
321+
sbi->epoch = (s64)le64_to_cpu(dsb->epoch);
322+
sbi->fixed_nsec = le32_to_cpu(dsb->fixed_nsec);
318323
super_set_uuid(sb, (void *)dsb->uuid, sizeof(dsb->uuid));
319324

320325
/* parse on-disk compression configurations */

fs/erofs/sysfs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ EROFS_ATTR_FEATURE(sb_chksum);
8181
EROFS_ATTR_FEATURE(ztailpacking);
8282
EROFS_ATTR_FEATURE(fragments);
8383
EROFS_ATTR_FEATURE(dedupe);
84+
EROFS_ATTR_FEATURE(48bit);
8485

8586
static struct attribute *erofs_feat_attrs[] = {
8687
ATTR_LIST(zero_padding),
@@ -93,6 +94,7 @@ static struct attribute *erofs_feat_attrs[] = {
9394
ATTR_LIST(ztailpacking),
9495
ATTR_LIST(fragments),
9596
ATTR_LIST(dedupe),
97+
ATTR_LIST(48bit),
9698
NULL,
9799
};
98100
ATTRIBUTE_GROUPS(erofs_feat);

include/trace/events/erofs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ TRACE_EVENT(erofs_fill_inode,
7575
__entry->ofs = erofs_blkoff(inode->i_sb, erofs_iloc(inode));
7676
),
7777

78-
TP_printk("dev = (%d,%d), nid = %llu, blkaddr %u ofs %u",
78+
TP_printk("dev = (%d,%d), nid = %llu, blkaddr %llu ofs %u",
7979
show_dev_nid(__entry),
8080
__entry->blkaddr, __entry->ofs)
8181
);

0 commit comments

Comments
 (0)