Skip to content

Commit

Permalink
BACKPORT: erofs: set block size to the on-disk block size
Browse files Browse the repository at this point in the history
Set the block size to that specified in on-disk superblock.

Also remove the hard constraint of PAGE_SIZE block size for the
uncompressed device backend.  This constraint is temporarily remained
for compressed device and fscache backend, as there is more work needed
to handle the condition where the block size is not equal to PAGE_SIZE.

It is worth noting that the on-disk block size is read prior to
erofs_superblock_csum_verify(), as the read block size is needed in the
latter.

Besides, later we are going to make erofs refer to tar data blobs (which
is 512-byte aligned) for OCI containers, where the block size is 512
bytes.  In this case, the 512-byte block size may not be adequate for a
directory to contain enough dirents.  To fix this, we are also going to
introduce directory block size independent on the block size.

Due to we have already supported block size smaller than PAGE_SIZE now,
disable all these images with such separated directory block size until
we supported this feature later.

Signed-off-by: Jingbo Xu <[email protected]>
Reviewed-by: Gao Xiang <[email protected]>
Reviewed-by: Yue Hu <[email protected]>
Reviewed-by: Chao Yu <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
[ Gao Xiang: update documentation. ]
Signed-off-by: Gao Xiang <[email protected]>
  • Loading branch information
lostjeffle authored and asuka-mio committed Apr 29, 2023
1 parent fb40a62 commit 71edbe8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
5 changes: 3 additions & 2 deletions fs/erofs/erofs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct erofs_super_block {
__le32 magic; /* file system magic number */
__le32 checksum; /* crc32c(super_block) */
__le32 feature_compat;
__u8 blkszbits; /* support block_size == PAGE_SIZE only */
__u8 blkszbits; /* filesystem block size in bit shift */
__u8 sb_extslots; /* superblock size = 128 + sb_extslots * 16 */

__le16 root_nid; /* nid of root directory */
Expand All @@ -81,7 +81,8 @@ struct erofs_super_block {
} __packed u1;
__le16 extra_devices; /* # of devices besides the primary device */
__le16 devt_slotoff; /* startoff = devt_slotoff * devt_slotsize */
__u8 reserved[6];
__u8 dirblkbits; /* directory block size in bit shift */
__u8 reserved[5];
__le64 packed_nid; /* nid of the special packed inode */
__u8 reserved2[24];
};
Expand Down
5 changes: 4 additions & 1 deletion fs/erofs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ static int erofs_fill_inode(struct inode *inode)
}

if (erofs_inode_is_data_compressed(vi->datalayout)) {
err = z_erofs_fill_inode(inode);
if (inode->i_sb->s_blocksize_bits == PAGE_SHIFT)
err = z_erofs_fill_inode(inode);
else
err = -EOPNOTSUPP;
goto out_unlock;
}
inode->i_mapping->a_ops = &erofs_raw_access_aops;
Expand Down
10 changes: 1 addition & 9 deletions fs/erofs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct erofs_sb_info {
u16 device_id_mask; /* valid bits of device id to be used */

unsigned char islotbits; /* inode slot unit size in bit shift */
unsigned char blkszbits;
unsigned char blkszbits; /* filesystem block size in bit shift */

u32 sb_size; /* total superblock size */
u32 build_time_nsec;
Expand Down Expand Up @@ -193,14 +193,6 @@ static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
VAL != EROFS_LOCKED_MAGIC);
}

/* we strictly follow PAGE_SIZE and no buffer head yet */
#define LOG_BLOCK_SIZE PAGE_SHIFT
#define EROFS_BLKSIZ (1 << LOG_BLOCK_SIZE)

#if (EROFS_BLKSIZ % 4096 || !EROFS_BLKSIZ)
#error erofs cannot be used in this platform
#endif

enum erofs_kmap_type {
EROFS_NO_KMAP, /* don't map the buffer */
EROFS_KMAP, /* use kmap_local_page() to map the buffer */
Expand Down
32 changes: 20 additions & 12 deletions fs/erofs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ static int erofs_read_superblock(struct super_block *sb)
struct erofs_sb_info *sbi;
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
struct erofs_super_block *dsb;
unsigned int blkszbits;
void *data;
int ret;

Expand All @@ -307,6 +306,16 @@ static int erofs_read_superblock(struct super_block *sb)
goto out;
}

sbi->blkszbits = dsb->blkszbits;
if (sbi->blkszbits < 9 || sbi->blkszbits > PAGE_SHIFT) {
erofs_err(sb, "blkszbits %u isn't supported", sbi->blkszbits);
goto out;
}
if (dsb->dirblkbits) {
erofs_err(sb, "dirblkbits %u isn't supported", dsb->dirblkbits);
goto out;
}

sbi->feature_compat = le32_to_cpu(dsb->feature_compat);
if (erofs_sb_has_sb_chksum(sbi)) {
ret = erofs_superblock_csum_verify(sb, data);
Expand All @@ -315,19 +324,11 @@ static int erofs_read_superblock(struct super_block *sb)
}

ret = -EINVAL;
blkszbits = dsb->blkszbits;
/* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */
if (blkszbits != LOG_BLOCK_SIZE) {
erofs_err(sb, "blkszbits %u isn't supported on this platform",
blkszbits);
goto out;
}

if (!check_layout_compatibility(sb, dsb))
goto out;

sbi->sb_size = 128 + dsb->sb_extslots * EROFS_SB_EXTSLOT_SIZE;
if (sbi->sb_size > EROFS_BLKSIZ) {
if (sbi->sb_size > PAGE_SIZE - EROFS_SUPER_OFFSET) {
erofs_err(sb, "invalid sb_extslots %u (more than a fs block)",
sbi->sb_size);
goto out;
Expand Down Expand Up @@ -651,8 +652,8 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent)

sb->s_magic = EROFS_SUPER_MAGIC;

if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) {
erofs_err(sb, "failed to set erofs blksize");
if (!sb_set_blocksize(sb, PAGE_SIZE)) {
erofs_err(sb, "failed to set initial blksize");
return -EINVAL;
}

Expand All @@ -671,6 +672,13 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent)
if (err)
return err;

if (sb->s_blocksize_bits != sbi->blkszbits) {
if (!sb_set_blocksize(sb, 1 << sbi->blkszbits)) {
erofs_err(sb, "failed to set erofs blksize");
return -EINVAL;
}
}

sb->s_flags |= SB_RDONLY | SB_NOATIME;
sb->s_maxbytes = MAX_LFS_FILESIZE;
sb->s_time_gran = 1;
Expand Down

0 comments on commit 71edbe8

Please sign in to comment.