2019-07-31 22:57:31 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2018-07-26 19:21:46 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017-2018 HUAWEI, Inc.
|
2020-07-13 20:09:44 +07:00
|
|
|
* https://www.huawei.com/
|
2018-07-26 19:21:46 +07:00
|
|
|
* Created by Gao Xiang <gaoxiang25@huawei.com>
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/buffer_head.h>
|
|
|
|
#include <linux/statfs.h>
|
|
|
|
#include <linux/parser.h>
|
2018-07-26 19:21:52 +07:00
|
|
|
#include <linux/seq_file.h>
|
2019-11-04 09:49:37 +07:00
|
|
|
#include <linux/crc32c.h>
|
2020-05-29 17:48:36 +07:00
|
|
|
#include <linux/fs_context.h>
|
|
|
|
#include <linux/fs_parser.h>
|
2019-01-14 18:40:25 +07:00
|
|
|
#include "xattr.h"
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2018-07-26 19:21:55 +07:00
|
|
|
#define CREATE_TRACE_POINTS
|
|
|
|
#include <trace/events/erofs.h>
|
|
|
|
|
2018-07-26 19:21:46 +07:00
|
|
|
static struct kmem_cache *erofs_inode_cachep __read_mostly;
|
|
|
|
|
2019-09-04 09:09:09 +07:00
|
|
|
void _erofs_err(struct super_block *sb, const char *function,
|
|
|
|
const char *fmt, ...)
|
|
|
|
{
|
|
|
|
struct va_format vaf;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
|
|
|
|
vaf.fmt = fmt;
|
|
|
|
vaf.va = &args;
|
|
|
|
|
|
|
|
pr_err("(device %s): %s: %pV", sb->s_id, function, &vaf);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _erofs_info(struct super_block *sb, const char *function,
|
|
|
|
const char *fmt, ...)
|
|
|
|
{
|
|
|
|
struct va_format vaf;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
|
|
|
|
vaf.fmt = fmt;
|
|
|
|
vaf.va = &args;
|
|
|
|
|
|
|
|
pr_info("(device %s): %pV", sb->s_id, &vaf);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2019-11-04 09:49:37 +07:00
|
|
|
static int erofs_superblock_csum_verify(struct super_block *sb, void *sbdata)
|
|
|
|
{
|
|
|
|
struct erofs_super_block *dsb;
|
|
|
|
u32 expected_crc, crc;
|
|
|
|
|
|
|
|
dsb = kmemdup(sbdata + EROFS_SUPER_OFFSET,
|
|
|
|
EROFS_BLKSIZ - EROFS_SUPER_OFFSET, GFP_KERNEL);
|
|
|
|
if (!dsb)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
expected_crc = le32_to_cpu(dsb->checksum);
|
|
|
|
dsb->checksum = 0;
|
|
|
|
/* to allow for x86 boot sectors and other oddities. */
|
|
|
|
crc = crc32c(~0, dsb, EROFS_BLKSIZ - EROFS_SUPER_OFFSET);
|
|
|
|
kfree(dsb);
|
|
|
|
|
|
|
|
if (crc != expected_crc) {
|
|
|
|
erofs_err(sb, "invalid checksum 0x%08x, 0x%08x expected",
|
|
|
|
crc, expected_crc);
|
|
|
|
return -EBADMSG;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-04 09:09:05 +07:00
|
|
|
static void erofs_inode_init_once(void *ptr)
|
2018-07-26 19:21:46 +07:00
|
|
|
{
|
2019-09-04 09:08:56 +07:00
|
|
|
struct erofs_inode *vi = ptr;
|
2018-07-26 19:21:46 +07:00
|
|
|
|
|
|
|
inode_init_once(&vi->vfs_inode);
|
|
|
|
}
|
|
|
|
|
2019-09-04 09:09:05 +07:00
|
|
|
static struct inode *erofs_alloc_inode(struct super_block *sb)
|
2018-07-26 19:21:46 +07:00
|
|
|
{
|
2019-09-04 09:08:56 +07:00
|
|
|
struct erofs_inode *vi =
|
2018-07-26 19:21:46 +07:00
|
|
|
kmem_cache_alloc(erofs_inode_cachep, GFP_KERNEL);
|
|
|
|
|
2019-03-21 07:06:13 +07:00
|
|
|
if (!vi)
|
2018-07-26 19:21:46 +07:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* zero out everything except vfs_inode */
|
2019-09-04 09:08:56 +07:00
|
|
|
memset(vi, 0, offsetof(struct erofs_inode, vfs_inode));
|
2018-07-26 19:21:46 +07:00
|
|
|
return &vi->vfs_inode;
|
|
|
|
}
|
|
|
|
|
2019-09-04 09:09:05 +07:00
|
|
|
static void erofs_free_inode(struct inode *inode)
|
2018-07-26 19:21:46 +07:00
|
|
|
{
|
2019-09-04 09:08:56 +07:00
|
|
|
struct erofs_inode *vi = EROFS_I(inode);
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2019-09-04 09:08:59 +07:00
|
|
|
/* be careful of RCU symlink path */
|
|
|
|
if (inode->i_op == &erofs_fast_symlink_iops)
|
2018-07-26 19:21:46 +07:00
|
|
|
kfree(inode->i_link);
|
|
|
|
kfree(vi->xattr_shared_xattrs);
|
|
|
|
|
|
|
|
kmem_cache_free(erofs_inode_cachep, vi);
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:35:41 +07:00
|
|
|
static bool check_layout_compatibility(struct super_block *sb,
|
2019-09-04 09:09:00 +07:00
|
|
|
struct erofs_super_block *dsb)
|
2019-06-13 15:35:41 +07:00
|
|
|
{
|
2019-09-04 09:09:00 +07:00
|
|
|
const unsigned int feature = le32_to_cpu(dsb->feature_incompat);
|
2019-06-13 15:35:41 +07:00
|
|
|
|
2019-09-04 09:08:53 +07:00
|
|
|
EROFS_SB(sb)->feature_incompat = feature;
|
2019-06-13 15:35:41 +07:00
|
|
|
|
|
|
|
/* check if current kernel meets all mandatory requirements */
|
2019-09-04 09:08:53 +07:00
|
|
|
if (feature & (~EROFS_ALL_FEATURE_INCOMPAT)) {
|
2019-09-04 09:09:09 +07:00
|
|
|
erofs_err(sb,
|
|
|
|
"unidentified incompatible feature %x, please upgrade kernel version",
|
|
|
|
feature & ~EROFS_ALL_FEATURE_INCOMPAT);
|
2019-06-13 15:35:41 +07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-04 09:09:05 +07:00
|
|
|
static int erofs_read_superblock(struct super_block *sb)
|
2018-07-26 19:21:46 +07:00
|
|
|
{
|
|
|
|
struct erofs_sb_info *sbi;
|
2019-09-04 09:09:10 +07:00
|
|
|
struct page *page;
|
2019-09-04 09:09:00 +07:00
|
|
|
struct erofs_super_block *dsb;
|
2018-09-11 02:41:14 +07:00
|
|
|
unsigned int blkszbits;
|
2019-09-04 09:09:10 +07:00
|
|
|
void *data;
|
2018-07-26 19:21:46 +07:00
|
|
|
int ret;
|
|
|
|
|
2019-09-04 09:09:10 +07:00
|
|
|
page = read_mapping_page(sb->s_bdev->bd_inode->i_mapping, 0, NULL);
|
2019-09-18 15:30:33 +07:00
|
|
|
if (IS_ERR(page)) {
|
2019-09-04 09:09:09 +07:00
|
|
|
erofs_err(sb, "cannot read erofs superblock");
|
2019-09-18 15:30:33 +07:00
|
|
|
return PTR_ERR(page);
|
2018-07-26 19:21:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
sbi = EROFS_SB(sb);
|
2019-09-04 09:09:10 +07:00
|
|
|
|
2019-11-04 09:49:37 +07:00
|
|
|
data = kmap(page);
|
2019-09-04 09:09:10 +07:00
|
|
|
dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET);
|
2018-07-26 19:21:46 +07:00
|
|
|
|
|
|
|
ret = -EINVAL;
|
2019-09-04 09:09:00 +07:00
|
|
|
if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) {
|
2019-09-04 09:09:09 +07:00
|
|
|
erofs_err(sb, "cannot find valid erofs superblock");
|
2018-07-26 19:21:46 +07:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-11-04 09:49:37 +07:00
|
|
|
sbi->feature_compat = le32_to_cpu(dsb->feature_compat);
|
|
|
|
if (sbi->feature_compat & EROFS_FEATURE_COMPAT_SB_CHKSUM) {
|
|
|
|
ret = erofs_superblock_csum_verify(sb, data);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2021-05-19 21:16:57 +07:00
|
|
|
ret = -EINVAL;
|
2019-09-04 09:09:00 +07:00
|
|
|
blkszbits = dsb->blkszbits;
|
2018-07-26 19:21:46 +07:00
|
|
|
/* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */
|
2019-08-29 23:38:27 +07:00
|
|
|
if (blkszbits != LOG_BLOCK_SIZE) {
|
2021-01-20 08:30:16 +07:00
|
|
|
erofs_err(sb, "blkszbits %u isn't supported on this platform",
|
|
|
|
blkszbits);
|
2018-07-26 19:21:46 +07:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-09-04 09:09:00 +07:00
|
|
|
if (!check_layout_compatibility(sb, dsb))
|
2019-06-13 15:35:41 +07:00
|
|
|
goto out;
|
|
|
|
|
2019-09-04 09:09:00 +07:00
|
|
|
sbi->blocks = le32_to_cpu(dsb->blocks);
|
|
|
|
sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr);
|
2018-07-26 19:21:52 +07:00
|
|
|
#ifdef CONFIG_EROFS_FS_XATTR
|
2019-09-04 09:09:00 +07:00
|
|
|
sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr);
|
2018-07-26 19:21:52 +07:00
|
|
|
#endif
|
2019-09-04 09:08:54 +07:00
|
|
|
sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact));
|
2019-09-04 09:09:00 +07:00
|
|
|
sbi->root_nid = le16_to_cpu(dsb->root_nid);
|
|
|
|
sbi->inos = le64_to_cpu(dsb->inos);
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2019-09-04 09:09:00 +07:00
|
|
|
sbi->build_time = le64_to_cpu(dsb->build_time);
|
|
|
|
sbi->build_time_nsec = le32_to_cpu(dsb->build_time_nsec);
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2019-09-04 09:09:00 +07:00
|
|
|
memcpy(&sb->s_uuid, dsb->uuid, sizeof(dsb->uuid));
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2019-09-04 09:09:00 +07:00
|
|
|
ret = strscpy(sbi->volume_name, dsb->volume_name,
|
|
|
|
sizeof(dsb->volume_name));
|
2019-08-18 17:28:24 +07:00
|
|
|
if (ret < 0) { /* -E2BIG */
|
2019-09-04 09:09:09 +07:00
|
|
|
erofs_err(sb, "bad volume name without NIL terminator");
|
2019-08-18 17:28:24 +07:00
|
|
|
ret = -EFSCORRUPTED;
|
|
|
|
goto out;
|
|
|
|
}
|
2018-07-26 19:21:46 +07:00
|
|
|
ret = 0;
|
|
|
|
out:
|
2019-11-04 09:49:37 +07:00
|
|
|
kunmap(page);
|
2019-09-04 09:09:10 +07:00
|
|
|
put_page(page);
|
2018-07-26 19:21:46 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:57:49 +07:00
|
|
|
/* set up default EROFS parameters */
|
2020-05-29 17:48:36 +07:00
|
|
|
static void erofs_default_options(struct erofs_fs_context *ctx)
|
2018-07-26 19:21:46 +07:00
|
|
|
{
|
2018-09-19 23:06:56 +07:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
2020-05-29 17:48:36 +07:00
|
|
|
ctx->cache_strategy = EROFS_ZIP_CACHE_READAROUND;
|
|
|
|
ctx->max_sync_decompress_pages = 3;
|
2018-09-19 23:06:56 +07:00
|
|
|
#endif
|
2018-07-26 19:21:52 +07:00
|
|
|
#ifdef CONFIG_EROFS_FS_XATTR
|
2020-05-29 17:48:36 +07:00
|
|
|
set_opt(ctx, XATTR_USER);
|
2018-07-26 19:21:52 +07:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EROFS_FS_POSIX_ACL
|
2020-05-29 17:48:36 +07:00
|
|
|
set_opt(ctx, POSIX_ACL);
|
2018-07-26 19:21:52 +07:00
|
|
|
#endif
|
2018-07-26 19:21:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
2018-07-26 19:21:52 +07:00
|
|
|
Opt_user_xattr,
|
|
|
|
Opt_acl,
|
2019-07-31 22:57:49 +07:00
|
|
|
Opt_cache_strategy,
|
2018-07-26 19:21:46 +07:00
|
|
|
Opt_err
|
|
|
|
};
|
|
|
|
|
2020-05-29 17:48:36 +07:00
|
|
|
static const struct constant_table erofs_param_cache_strategy[] = {
|
|
|
|
{"disabled", EROFS_ZIP_CACHE_DISABLED},
|
|
|
|
{"readahead", EROFS_ZIP_CACHE_READAHEAD},
|
|
|
|
{"readaround", EROFS_ZIP_CACHE_READAROUND},
|
|
|
|
{}
|
2018-07-26 19:21:46 +07:00
|
|
|
};
|
|
|
|
|
2020-05-29 17:48:36 +07:00
|
|
|
static const struct fs_parameter_spec erofs_fs_parameters[] = {
|
|
|
|
fsparam_flag_no("user_xattr", Opt_user_xattr),
|
|
|
|
fsparam_flag_no("acl", Opt_acl),
|
|
|
|
fsparam_enum("cache_strategy", Opt_cache_strategy,
|
|
|
|
erofs_param_cache_strategy),
|
|
|
|
{}
|
|
|
|
};
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2020-05-29 17:48:36 +07:00
|
|
|
static int erofs_fc_parse_param(struct fs_context *fc,
|
|
|
|
struct fs_parameter *param)
|
|
|
|
{
|
|
|
|
struct erofs_fs_context *ctx __maybe_unused = fc->fs_private;
|
|
|
|
struct fs_parse_result result;
|
|
|
|
int opt;
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2020-05-29 17:48:36 +07:00
|
|
|
opt = fs_parse(fc, erofs_fs_parameters, param, &result);
|
|
|
|
if (opt < 0)
|
|
|
|
return opt;
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2020-05-29 17:48:36 +07:00
|
|
|
switch (opt) {
|
|
|
|
case Opt_user_xattr:
|
2018-07-26 19:21:52 +07:00
|
|
|
#ifdef CONFIG_EROFS_FS_XATTR
|
2020-05-29 17:48:36 +07:00
|
|
|
if (result.boolean)
|
|
|
|
set_opt(ctx, XATTR_USER);
|
|
|
|
else
|
|
|
|
clear_opt(ctx, XATTR_USER);
|
2018-07-26 19:21:52 +07:00
|
|
|
#else
|
2020-05-29 17:48:36 +07:00
|
|
|
errorfc(fc, "{,no}user_xattr options not supported");
|
2018-07-26 19:21:52 +07:00
|
|
|
#endif
|
2020-05-29 17:48:36 +07:00
|
|
|
break;
|
|
|
|
case Opt_acl:
|
2018-07-26 19:21:52 +07:00
|
|
|
#ifdef CONFIG_EROFS_FS_POSIX_ACL
|
2020-05-29 17:48:36 +07:00
|
|
|
if (result.boolean)
|
|
|
|
set_opt(ctx, POSIX_ACL);
|
|
|
|
else
|
|
|
|
clear_opt(ctx, POSIX_ACL);
|
2018-07-26 19:21:52 +07:00
|
|
|
#else
|
2020-05-29 17:48:36 +07:00
|
|
|
errorfc(fc, "{,no}acl options not supported");
|
2018-07-26 19:21:52 +07:00
|
|
|
#endif
|
2020-05-29 17:48:36 +07:00
|
|
|
break;
|
|
|
|
case Opt_cache_strategy:
|
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
|
|
|
ctx->cache_strategy = result.uint_32;
|
|
|
|
#else
|
|
|
|
errorfc(fc, "compression not supported, cache_strategy ignored");
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENOPARAM;
|
2018-07-26 19:21:46 +07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:57:49 +07:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
2018-07-26 19:22:07 +07:00
|
|
|
static const struct address_space_operations managed_cache_aops;
|
|
|
|
|
2019-09-04 09:09:05 +07:00
|
|
|
static int erofs_managed_cache_releasepage(struct page *page, gfp_t gfp_mask)
|
2018-07-26 19:22:07 +07:00
|
|
|
{
|
|
|
|
int ret = 1; /* 0 - busy */
|
|
|
|
struct address_space *const mapping = page->mapping;
|
|
|
|
|
2018-12-05 20:23:13 +07:00
|
|
|
DBG_BUGON(!PageLocked(page));
|
|
|
|
DBG_BUGON(mapping->a_ops != &managed_cache_aops);
|
2018-07-26 19:22:07 +07:00
|
|
|
|
|
|
|
if (PagePrivate(page))
|
2018-07-29 12:34:58 +07:00
|
|
|
ret = erofs_try_to_free_cached_page(mapping, page);
|
2018-07-26 19:22:07 +07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-09-04 09:09:05 +07:00
|
|
|
static void erofs_managed_cache_invalidatepage(struct page *page,
|
|
|
|
unsigned int offset,
|
|
|
|
unsigned int length)
|
2018-07-26 19:22:07 +07:00
|
|
|
{
|
|
|
|
const unsigned int stop = length + offset;
|
|
|
|
|
2018-12-05 20:23:13 +07:00
|
|
|
DBG_BUGON(!PageLocked(page));
|
2018-07-26 19:22:07 +07:00
|
|
|
|
2018-12-05 20:23:13 +07:00
|
|
|
/* Check for potential overflow in debug mode */
|
|
|
|
DBG_BUGON(stop > PAGE_SIZE || stop < length);
|
2018-07-26 19:22:07 +07:00
|
|
|
|
|
|
|
if (offset == 0 && stop == PAGE_SIZE)
|
2019-09-04 09:09:05 +07:00
|
|
|
while (!erofs_managed_cache_releasepage(page, GFP_NOFS))
|
2018-07-26 19:22:07 +07:00
|
|
|
cond_resched();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct address_space_operations managed_cache_aops = {
|
2019-09-04 09:09:05 +07:00
|
|
|
.releasepage = erofs_managed_cache_releasepage,
|
|
|
|
.invalidatepage = erofs_managed_cache_invalidatepage,
|
2018-07-26 19:22:07 +07:00
|
|
|
};
|
|
|
|
|
2019-07-31 22:57:41 +07:00
|
|
|
static int erofs_init_managed_cache(struct super_block *sb)
|
2018-07-26 19:22:07 +07:00
|
|
|
{
|
2019-07-31 22:57:41 +07:00
|
|
|
struct erofs_sb_info *const sbi = EROFS_SB(sb);
|
|
|
|
struct inode *const inode = new_inode(sb);
|
2018-07-26 19:22:07 +07:00
|
|
|
|
2019-08-29 23:38:27 +07:00
|
|
|
if (!inode)
|
2019-07-31 22:57:41 +07:00
|
|
|
return -ENOMEM;
|
2018-07-26 19:22:07 +07:00
|
|
|
|
|
|
|
set_nlink(inode, 1);
|
|
|
|
inode->i_size = OFFSET_MAX;
|
|
|
|
|
|
|
|
inode->i_mapping->a_ops = &managed_cache_aops;
|
|
|
|
mapping_set_gfp_mask(inode->i_mapping,
|
2019-07-31 22:57:42 +07:00
|
|
|
GFP_NOFS | __GFP_HIGHMEM | __GFP_MOVABLE);
|
2019-07-31 22:57:41 +07:00
|
|
|
sbi->managed_cache = inode;
|
|
|
|
return 0;
|
2018-07-26 19:22:07 +07:00
|
|
|
}
|
2019-07-31 22:57:41 +07:00
|
|
|
#else
|
|
|
|
static int erofs_init_managed_cache(struct super_block *sb) { return 0; }
|
2018-07-26 19:22:07 +07:00
|
|
|
#endif
|
|
|
|
|
2020-05-29 17:48:36 +07:00
|
|
|
static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
|
2018-07-26 19:21:46 +07:00
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
struct erofs_sb_info *sbi;
|
2020-05-29 17:48:36 +07:00
|
|
|
struct erofs_fs_context *ctx = fc->fs_private;
|
2019-07-31 22:57:41 +07:00
|
|
|
int err;
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2019-07-31 22:57:41 +07:00
|
|
|
sb->s_magic = EROFS_SUPER_MAGIC;
|
|
|
|
|
2019-08-29 23:38:27 +07:00
|
|
|
if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) {
|
2019-09-04 09:09:09 +07:00
|
|
|
erofs_err(sb, "failed to set erofs blksize");
|
2019-07-31 22:57:41 +07:00
|
|
|
return -EINVAL;
|
2018-07-26 19:21:46 +07:00
|
|
|
}
|
|
|
|
|
2019-06-27 12:31:18 +07:00
|
|
|
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
|
2019-08-29 23:38:27 +07:00
|
|
|
if (!sbi)
|
2019-07-31 22:57:41 +07:00
|
|
|
return -ENOMEM;
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2019-07-31 22:57:41 +07:00
|
|
|
sb->s_fs_info = sbi;
|
2019-09-04 09:09:05 +07:00
|
|
|
err = erofs_read_superblock(sb);
|
2018-07-26 19:21:46 +07:00
|
|
|
if (err)
|
2019-07-31 22:57:41 +07:00
|
|
|
return err;
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2018-09-06 16:01:47 +07:00
|
|
|
sb->s_flags |= SB_RDONLY | SB_NOATIME;
|
2018-07-26 19:21:46 +07:00
|
|
|
sb->s_maxbytes = MAX_LFS_FILESIZE;
|
|
|
|
sb->s_time_gran = 1;
|
|
|
|
|
|
|
|
sb->s_op = &erofs_sops;
|
2018-07-26 19:21:52 +07:00
|
|
|
sb->s_xattr = erofs_xattr_handlers;
|
2020-05-26 16:03:43 +07:00
|
|
|
|
2020-05-29 17:48:36 +07:00
|
|
|
if (test_opt(ctx, POSIX_ACL))
|
2019-01-29 15:35:20 +07:00
|
|
|
sb->s_flags |= SB_POSIXACL;
|
|
|
|
else
|
|
|
|
sb->s_flags &= ~SB_POSIXACL;
|
|
|
|
|
2020-05-29 17:48:36 +07:00
|
|
|
sbi->ctx = *ctx;
|
|
|
|
|
2018-07-26 19:22:05 +07:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
2020-02-20 09:46:42 +07:00
|
|
|
xa_init(&sbi->managed_pslots);
|
2018-07-26 19:22:05 +07:00
|
|
|
#endif
|
|
|
|
|
2018-07-26 19:21:46 +07:00
|
|
|
/* get the root inode */
|
|
|
|
inode = erofs_iget(sb, ROOT_NID(sbi), true);
|
2019-07-31 22:57:41 +07:00
|
|
|
if (IS_ERR(inode))
|
|
|
|
return PTR_ERR(inode);
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2019-08-29 23:38:27 +07:00
|
|
|
if (!S_ISDIR(inode->i_mode)) {
|
2019-09-04 09:09:09 +07:00
|
|
|
erofs_err(sb, "rootino(nid %llu) is not a directory(i_mode %o)",
|
|
|
|
ROOT_NID(sbi), inode->i_mode);
|
2019-01-23 13:12:25 +07:00
|
|
|
iput(inode);
|
2019-07-31 22:57:41 +07:00
|
|
|
return -EINVAL;
|
2018-07-26 19:21:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
sb->s_root = d_make_root(inode);
|
2019-08-29 23:38:27 +07:00
|
|
|
if (!sb->s_root)
|
2019-07-31 22:57:41 +07:00
|
|
|
return -ENOMEM;
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2019-07-31 22:57:39 +07:00
|
|
|
erofs_shrinker_register(sb);
|
2019-07-31 22:57:41 +07:00
|
|
|
/* sb->s_umount is already locked, SB_ACTIVE and SB_BORN are not set */
|
|
|
|
err = erofs_init_managed_cache(sb);
|
2019-08-29 23:38:27 +07:00
|
|
|
if (err)
|
2019-07-31 22:57:41 +07:00
|
|
|
return err;
|
2018-07-26 19:22:03 +07:00
|
|
|
|
2020-05-29 17:48:36 +07:00
|
|
|
erofs_info(sb, "mounted with root inode @ nid %llu.", ROOT_NID(sbi));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int erofs_fc_get_tree(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
return get_tree_bdev(fc, erofs_fc_fill_super);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int erofs_fc_reconfigure(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
struct super_block *sb = fc->root->d_sb;
|
|
|
|
struct erofs_sb_info *sbi = EROFS_SB(sb);
|
|
|
|
struct erofs_fs_context *ctx = fc->fs_private;
|
|
|
|
|
|
|
|
DBG_BUGON(!sb_rdonly(sb));
|
|
|
|
|
|
|
|
if (test_opt(ctx, POSIX_ACL))
|
|
|
|
fc->sb_flags |= SB_POSIXACL;
|
|
|
|
else
|
|
|
|
fc->sb_flags &= ~SB_POSIXACL;
|
|
|
|
|
|
|
|
sbi->ctx = *ctx;
|
|
|
|
|
|
|
|
fc->sb_flags |= SB_RDONLY;
|
2018-07-26 19:21:46 +07:00
|
|
|
return 0;
|
2019-07-31 22:57:41 +07:00
|
|
|
}
|
|
|
|
|
2020-05-29 17:48:36 +07:00
|
|
|
static void erofs_fc_free(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
kfree(fc->fs_private);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct fs_context_operations erofs_context_ops = {
|
|
|
|
.parse_param = erofs_fc_parse_param,
|
|
|
|
.get_tree = erofs_fc_get_tree,
|
|
|
|
.reconfigure = erofs_fc_reconfigure,
|
|
|
|
.free = erofs_fc_free,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int erofs_init_fs_context(struct fs_context *fc)
|
2019-07-31 22:57:41 +07:00
|
|
|
{
|
2020-05-29 17:48:36 +07:00
|
|
|
fc->fs_private = kzalloc(sizeof(struct erofs_fs_context), GFP_KERNEL);
|
|
|
|
if (!fc->fs_private)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* set default mount options */
|
|
|
|
erofs_default_options(fc->fs_private);
|
|
|
|
|
|
|
|
fc->ops = &erofs_context_ops;
|
|
|
|
|
|
|
|
return 0;
|
2018-07-26 19:21:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* could be triggered after deactivate_locked_super()
|
|
|
|
* is called, thus including umount and failed to initialize.
|
|
|
|
*/
|
2019-07-31 22:57:41 +07:00
|
|
|
static void erofs_kill_sb(struct super_block *sb)
|
2018-07-26 19:21:46 +07:00
|
|
|
{
|
2019-07-31 22:57:41 +07:00
|
|
|
struct erofs_sb_info *sbi;
|
|
|
|
|
|
|
|
WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC);
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2019-07-31 22:57:41 +07:00
|
|
|
kill_block_super(sb);
|
|
|
|
|
|
|
|
sbi = EROFS_SB(sb);
|
2019-03-21 07:06:13 +07:00
|
|
|
if (!sbi)
|
2018-07-26 19:21:46 +07:00
|
|
|
return;
|
2019-07-31 22:57:41 +07:00
|
|
|
kfree(sbi);
|
|
|
|
sb->s_fs_info = NULL;
|
|
|
|
}
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2019-07-31 22:57:41 +07:00
|
|
|
/* called when ->s_root is non-NULL */
|
|
|
|
static void erofs_put_super(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct erofs_sb_info *const sbi = EROFS_SB(sb);
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2019-07-31 22:57:41 +07:00
|
|
|
DBG_BUGON(!sbi);
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2019-07-31 22:57:39 +07:00
|
|
|
erofs_shrinker_unregister(sb);
|
2019-07-31 22:57:49 +07:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
2018-07-26 19:22:07 +07:00
|
|
|
iput(sbi->managed_cache);
|
2019-07-31 22:57:41 +07:00
|
|
|
sbi->managed_cache = NULL;
|
2018-07-26 19:22:07 +07:00
|
|
|
#endif
|
2018-07-26 19:21:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_system_type erofs_fs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "erofs",
|
2020-05-29 17:48:36 +07:00
|
|
|
.init_fs_context = erofs_init_fs_context,
|
2019-07-31 22:57:41 +07:00
|
|
|
.kill_sb = erofs_kill_sb,
|
2018-07-26 19:21:46 +07:00
|
|
|
.fs_flags = FS_REQUIRES_DEV,
|
|
|
|
};
|
|
|
|
MODULE_ALIAS_FS("erofs");
|
|
|
|
|
|
|
|
static int __init erofs_module_init(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
erofs_check_ondisk_layout_definitions();
|
|
|
|
|
2019-09-04 09:08:55 +07:00
|
|
|
erofs_inode_cachep = kmem_cache_create("erofs_inode",
|
2019-09-04 09:08:56 +07:00
|
|
|
sizeof(struct erofs_inode), 0,
|
2019-09-04 09:08:55 +07:00
|
|
|
SLAB_RECLAIM_ACCOUNT,
|
2019-09-04 09:09:05 +07:00
|
|
|
erofs_inode_init_once);
|
2019-09-04 09:08:55 +07:00
|
|
|
if (!erofs_inode_cachep) {
|
|
|
|
err = -ENOMEM;
|
2018-07-26 19:21:46 +07:00
|
|
|
goto icache_err;
|
2019-09-04 09:08:55 +07:00
|
|
|
}
|
2018-07-26 19:21:46 +07:00
|
|
|
|
2019-07-31 22:57:39 +07:00
|
|
|
err = erofs_init_shrinker();
|
2018-07-26 19:22:04 +07:00
|
|
|
if (err)
|
|
|
|
goto shrinker_err;
|
|
|
|
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 19:22:06 +07:00
|
|
|
err = z_erofs_init_zip_subsystem();
|
|
|
|
if (err)
|
|
|
|
goto zip_err;
|
|
|
|
|
2018-07-26 19:21:46 +07:00
|
|
|
err = register_filesystem(&erofs_fs_type);
|
|
|
|
if (err)
|
|
|
|
goto fs_err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fs_err:
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 19:22:06 +07:00
|
|
|
z_erofs_exit_zip_subsystem();
|
|
|
|
zip_err:
|
2019-07-31 22:57:39 +07:00
|
|
|
erofs_exit_shrinker();
|
2018-07-26 19:22:04 +07:00
|
|
|
shrinker_err:
|
2019-09-04 09:08:55 +07:00
|
|
|
kmem_cache_destroy(erofs_inode_cachep);
|
2018-07-26 19:21:46 +07:00
|
|
|
icache_err:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit erofs_module_exit(void)
|
|
|
|
{
|
|
|
|
unregister_filesystem(&erofs_fs_type);
|
staging: erofs: introduce VLE decompression support
This patch introduces the basic in-place VLE decompression
implementation for the erofs file system.
Compared with fixed-sized input compression, it implements
what we call 'the variable-length extent compression' which
specifies the same output size for each compression block
to make the full use of IO bandwidth (which means almost
all data from block device can be directly used for decomp-
ression), improve the real (rather than just via data caching,
which costs more memory) random read and keep the relatively
lower compression ratios (it saves more storage space than
fixed-sized input compression which is also configured with
the same input block size), as illustrated below:
|--- variable-length extent ---|------ VLE ------|--- VLE ---|
/> clusterofs /> clusterofs /> clusterofs /> clusterofs
++---|-------++-----------++---------|-++-----------++-|---------++-|
...|| | || || | || || | || | ... original data
++---|-------++-----------++---------|-++-----------++-|---------++-|
++->cluster<-++->cluster<-++->cluster<-++->cluster<-++->cluster<-++
size size size size size
\ / / /
\ / / /
\ / / /
++-----------++-----------++-----------++
... || || || || ... compressed clusters
++-----------++-----------++-----------++
++->cluster<-++->cluster<-++->cluster<-++
size size size
The main point of 'in-place' refers to the decompression mode:
Instead of allocating independent compressed pages and data
structures, it reuses the allocated file cache pages at most
to store its compressed data and the corresponding pagevec in
a time-sharing approach by default, which will be useful for
low memory scenario.
In the end, unlike the other filesystems with (de)compression
support using a relatively large compression block size, which
reads and decompresses >= 128KB at once, and gains a more
good-looking random read (In fact it collects small random reads
into large sequential reads and caches all decompressed data
in memory, but it is unacceptable especially for embedded devices
with limited memory, and it is not the real random read), we
select a universal small-sized 4KB compressed cluster, which is
the smallest page size for most architectures, and all compressed
clusters can be read and decompressed independently, which ensures
random read number for all use cases.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-26 19:22:06 +07:00
|
|
|
z_erofs_exit_zip_subsystem();
|
2019-07-31 22:57:39 +07:00
|
|
|
erofs_exit_shrinker();
|
2019-09-04 09:08:55 +07:00
|
|
|
|
|
|
|
/* Ensure all RCU free inodes are safe before cache is destroyed. */
|
|
|
|
rcu_barrier();
|
|
|
|
kmem_cache_destroy(erofs_inode_cachep);
|
2018-07-26 19:21:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get filesystem statistics */
|
|
|
|
static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf)
|
|
|
|
{
|
|
|
|
struct super_block *sb = dentry->d_sb;
|
|
|
|
struct erofs_sb_info *sbi = EROFS_SB(sb);
|
|
|
|
u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
|
|
|
|
|
|
|
|
buf->f_type = sb->s_magic;
|
|
|
|
buf->f_bsize = EROFS_BLKSIZ;
|
|
|
|
buf->f_blocks = sbi->blocks;
|
|
|
|
buf->f_bfree = buf->f_bavail = 0;
|
|
|
|
|
|
|
|
buf->f_files = ULLONG_MAX;
|
|
|
|
buf->f_ffree = ULLONG_MAX - sbi->inos;
|
|
|
|
|
|
|
|
buf->f_namelen = EROFS_NAME_LEN;
|
|
|
|
|
2020-09-19 03:45:50 +07:00
|
|
|
buf->f_fsid = u64_to_fsid(id);
|
2018-07-26 19:21:46 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int erofs_show_options(struct seq_file *seq, struct dentry *root)
|
|
|
|
{
|
2018-07-26 19:21:52 +07:00
|
|
|
struct erofs_sb_info *sbi __maybe_unused = EROFS_SB(root->d_sb);
|
2020-05-29 17:48:36 +07:00
|
|
|
struct erofs_fs_context *ctx __maybe_unused = &sbi->ctx;
|
2018-07-26 19:21:52 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_EROFS_FS_XATTR
|
2020-05-29 17:48:36 +07:00
|
|
|
if (test_opt(ctx, XATTR_USER))
|
2018-07-26 19:21:52 +07:00
|
|
|
seq_puts(seq, ",user_xattr");
|
|
|
|
else
|
|
|
|
seq_puts(seq, ",nouser_xattr");
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EROFS_FS_POSIX_ACL
|
2020-05-29 17:48:36 +07:00
|
|
|
if (test_opt(ctx, POSIX_ACL))
|
2018-07-26 19:21:52 +07:00
|
|
|
seq_puts(seq, ",acl");
|
|
|
|
else
|
|
|
|
seq_puts(seq, ",noacl");
|
2018-07-26 19:21:54 +07:00
|
|
|
#endif
|
2019-07-31 22:57:49 +07:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
2020-05-29 17:48:36 +07:00
|
|
|
if (ctx->cache_strategy == EROFS_ZIP_CACHE_DISABLED)
|
2019-07-31 22:57:49 +07:00
|
|
|
seq_puts(seq, ",cache_strategy=disabled");
|
2020-05-29 17:48:36 +07:00
|
|
|
else if (ctx->cache_strategy == EROFS_ZIP_CACHE_READAHEAD)
|
2019-07-31 22:57:49 +07:00
|
|
|
seq_puts(seq, ",cache_strategy=readahead");
|
2020-05-29 17:48:36 +07:00
|
|
|
else if (ctx->cache_strategy == EROFS_ZIP_CACHE_READAROUND)
|
2019-07-31 22:57:49 +07:00
|
|
|
seq_puts(seq, ",cache_strategy=readaround");
|
|
|
|
#endif
|
2018-07-26 19:21:46 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct super_operations erofs_sops = {
|
|
|
|
.put_super = erofs_put_super,
|
2019-09-04 09:09:05 +07:00
|
|
|
.alloc_inode = erofs_alloc_inode,
|
|
|
|
.free_inode = erofs_free_inode,
|
2018-07-26 19:21:46 +07:00
|
|
|
.statfs = erofs_statfs,
|
|
|
|
.show_options = erofs_show_options,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_init(erofs_module_init);
|
|
|
|
module_exit(erofs_module_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Enhanced ROM File System");
|
2019-07-31 22:57:51 +07:00
|
|
|
MODULE_AUTHOR("Gao Xiang, Chao Yu, Miao Xie, CONSUMER BG, HUAWEI Inc.");
|
2018-07-26 19:21:46 +07:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|