2019-07-31 15:57:31 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2018-07-26 12:21:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017-2018 HUAWEI, Inc.
|
|
|
|
* http://www.huawei.com/
|
|
|
|
* 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 12:21:52 +00:00
|
|
|
#include <linux/seq_file.h>
|
2019-01-14 11:40:25 +00:00
|
|
|
#include "xattr.h"
|
2018-07-26 12:21:46 +00:00
|
|
|
|
2018-07-26 12:21:55 +00:00
|
|
|
#define CREATE_TRACE_POINTS
|
|
|
|
#include <trace/events/erofs.h>
|
|
|
|
|
2018-07-26 12:21:46 +00:00
|
|
|
static struct kmem_cache *erofs_inode_cachep __read_mostly;
|
|
|
|
|
|
|
|
static void init_once(void *ptr)
|
|
|
|
{
|
|
|
|
struct erofs_vnode *vi = ptr;
|
|
|
|
|
|
|
|
inode_init_once(&vi->vfs_inode);
|
|
|
|
}
|
|
|
|
|
2018-10-09 13:43:53 +00:00
|
|
|
static int __init erofs_init_inode_cache(void)
|
2018-07-26 12:21:46 +00:00
|
|
|
{
|
|
|
|
erofs_inode_cachep = kmem_cache_create("erofs_inode",
|
2019-03-18 23:58:41 +00:00
|
|
|
sizeof(struct erofs_vnode), 0,
|
|
|
|
SLAB_RECLAIM_ACCOUNT,
|
|
|
|
init_once);
|
2018-07-26 12:21:46 +00:00
|
|
|
|
2019-03-21 00:06:13 +00:00
|
|
|
return erofs_inode_cachep ? 0 : -ENOMEM;
|
2018-07-26 12:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void erofs_exit_inode_cache(void)
|
|
|
|
{
|
|
|
|
kmem_cache_destroy(erofs_inode_cachep);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct inode *alloc_inode(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct erofs_vnode *vi =
|
|
|
|
kmem_cache_alloc(erofs_inode_cachep, GFP_KERNEL);
|
|
|
|
|
2019-03-21 00:06:13 +00:00
|
|
|
if (!vi)
|
2018-07-26 12:21:46 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* zero out everything except vfs_inode */
|
|
|
|
memset(vi, 0, offsetof(struct erofs_vnode, vfs_inode));
|
|
|
|
return &vi->vfs_inode;
|
|
|
|
}
|
|
|
|
|
2019-04-10 18:59:08 +00:00
|
|
|
static void free_inode(struct inode *inode)
|
2018-07-26 12:21:46 +00:00
|
|
|
{
|
|
|
|
struct erofs_vnode *vi = EROFS_V(inode);
|
|
|
|
|
|
|
|
/* be careful RCU symlink path (see ext4_inode_info->i_data)! */
|
|
|
|
if (is_inode_fast_symlink(inode))
|
|
|
|
kfree(inode->i_link);
|
|
|
|
|
|
|
|
kfree(vi->xattr_shared_xattrs);
|
|
|
|
|
|
|
|
kmem_cache_free(erofs_inode_cachep, vi);
|
|
|
|
}
|
|
|
|
|
2019-06-13 08:35:41 +00:00
|
|
|
static bool check_layout_compatibility(struct super_block *sb,
|
|
|
|
struct erofs_super_block *layout)
|
|
|
|
{
|
|
|
|
const unsigned int requirements = le32_to_cpu(layout->requirements);
|
|
|
|
|
|
|
|
EROFS_SB(sb)->requirements = requirements;
|
|
|
|
|
|
|
|
/* check if current kernel meets all mandatory requirements */
|
|
|
|
if (requirements & (~EROFS_ALL_REQUIREMENTS)) {
|
|
|
|
errln("unidentified requirements %x, please upgrade kernel version",
|
|
|
|
requirements & ~EROFS_ALL_REQUIREMENTS);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-26 12:21:46 +00:00
|
|
|
static int superblock_read(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct erofs_sb_info *sbi;
|
|
|
|
struct buffer_head *bh;
|
|
|
|
struct erofs_super_block *layout;
|
2018-09-10 19:41:14 +00:00
|
|
|
unsigned int blkszbits;
|
2018-07-26 12:21:46 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
bh = sb_bread(sb, 0);
|
|
|
|
|
2019-03-21 00:06:13 +00:00
|
|
|
if (!bh) {
|
2018-07-26 12:21:46 +00:00
|
|
|
errln("cannot read erofs superblock");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
sbi = EROFS_SB(sb);
|
|
|
|
layout = (struct erofs_super_block *)((u8 *)bh->b_data
|
|
|
|
+ EROFS_SUPER_OFFSET);
|
|
|
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
if (le32_to_cpu(layout->magic) != EROFS_SUPER_MAGIC_V1) {
|
|
|
|
errln("cannot find valid erofs superblock");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
blkszbits = layout->blkszbits;
|
|
|
|
/* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */
|
|
|
|
if (unlikely(blkszbits != LOG_BLOCK_SIZE)) {
|
|
|
|
errln("blksize %u isn't supported on this platform",
|
2019-03-18 23:58:41 +00:00
|
|
|
1 << blkszbits);
|
2018-07-26 12:21:46 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-06-13 08:35:41 +00:00
|
|
|
if (!check_layout_compatibility(sb, layout))
|
|
|
|
goto out;
|
|
|
|
|
2018-07-26 12:21:46 +00:00
|
|
|
sbi->blocks = le32_to_cpu(layout->blocks);
|
|
|
|
sbi->meta_blkaddr = le32_to_cpu(layout->meta_blkaddr);
|
2018-07-26 12:21:52 +00:00
|
|
|
#ifdef CONFIG_EROFS_FS_XATTR
|
|
|
|
sbi->xattr_blkaddr = le32_to_cpu(layout->xattr_blkaddr);
|
|
|
|
#endif
|
2018-07-26 12:21:46 +00:00
|
|
|
sbi->islotbits = ffs(sizeof(struct erofs_inode_v1)) - 1;
|
|
|
|
sbi->root_nid = le16_to_cpu(layout->root_nid);
|
|
|
|
sbi->inos = le64_to_cpu(layout->inos);
|
|
|
|
|
|
|
|
sbi->build_time = le64_to_cpu(layout->build_time);
|
|
|
|
sbi->build_time_nsec = le32_to_cpu(layout->build_time_nsec);
|
|
|
|
|
|
|
|
memcpy(&sb->s_uuid, layout->uuid, sizeof(layout->uuid));
|
|
|
|
|
2019-08-18 10:28:24 +00:00
|
|
|
ret = strscpy(sbi->volume_name, layout->volume_name,
|
|
|
|
sizeof(layout->volume_name));
|
|
|
|
if (ret < 0) { /* -E2BIG */
|
|
|
|
errln("bad volume name without NIL terminator");
|
|
|
|
ret = -EFSCORRUPTED;
|
|
|
|
goto out;
|
|
|
|
}
|
2018-07-26 12:21:46 +00:00
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
brelse(bh);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-07-26 12:21:54 +00:00
|
|
|
#ifdef CONFIG_EROFS_FAULT_INJECTION
|
2019-03-25 03:40:09 +00:00
|
|
|
const char *erofs_fault_name[FAULT_MAX] = {
|
2018-07-26 12:21:54 +00:00
|
|
|
[FAULT_KMALLOC] = "kmalloc",
|
2019-03-25 03:40:09 +00:00
|
|
|
[FAULT_READ_IO] = "read IO error",
|
2018-07-26 12:21:54 +00:00
|
|
|
};
|
|
|
|
|
2018-09-19 14:53:46 +00:00
|
|
|
static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
|
|
|
|
unsigned int rate)
|
2018-07-26 12:21:54 +00:00
|
|
|
{
|
|
|
|
struct erofs_fault_info *ffi = &sbi->fault_info;
|
|
|
|
|
|
|
|
if (rate) {
|
|
|
|
atomic_set(&ffi->inject_ops, 0);
|
|
|
|
ffi->inject_rate = rate;
|
|
|
|
ffi->inject_type = (1 << FAULT_MAX) - 1;
|
|
|
|
} else {
|
|
|
|
memset(ffi, 0, sizeof(struct erofs_fault_info));
|
|
|
|
}
|
2018-09-19 14:53:44 +00:00
|
|
|
|
|
|
|
set_opt(sbi, FAULT_INJECTION);
|
2018-09-19 14:53:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
|
|
|
|
substring_t *args)
|
|
|
|
{
|
|
|
|
int rate = 0;
|
|
|
|
|
|
|
|
if (args->from && match_int(args, &rate))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
__erofs_build_fault_attr(sbi, rate);
|
2018-09-19 14:53:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-09-19 14:53:45 +00:00
|
|
|
|
|
|
|
static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
return sbi->fault_info.inject_rate;
|
|
|
|
}
|
2018-09-19 14:53:44 +00:00
|
|
|
#else
|
2018-09-19 14:53:46 +00:00
|
|
|
static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
|
|
|
|
unsigned int rate)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-19 14:53:44 +00:00
|
|
|
static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
|
|
|
|
substring_t *args)
|
|
|
|
{
|
|
|
|
infoln("fault_injection options not supported");
|
|
|
|
return 0;
|
2018-07-26 12:21:54 +00:00
|
|
|
}
|
2018-09-19 14:53:45 +00:00
|
|
|
|
|
|
|
static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-26 12:21:54 +00:00
|
|
|
#endif
|
|
|
|
|
2019-07-31 15:57:49 +00:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
|
|
|
static int erofs_build_cache_strategy(struct erofs_sb_info *sbi,
|
|
|
|
substring_t *args)
|
|
|
|
{
|
|
|
|
const char *cs = match_strdup(args);
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (!cs) {
|
|
|
|
errln("Not enough memory to store cache strategy");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(cs, "disabled")) {
|
|
|
|
sbi->cache_strategy = EROFS_ZIP_CACHE_DISABLED;
|
|
|
|
} else if (!strcmp(cs, "readahead")) {
|
|
|
|
sbi->cache_strategy = EROFS_ZIP_CACHE_READAHEAD;
|
|
|
|
} else if (!strcmp(cs, "readaround")) {
|
|
|
|
sbi->cache_strategy = EROFS_ZIP_CACHE_READAROUND;
|
|
|
|
} else {
|
|
|
|
errln("Unrecognized cache strategy \"%s\"", cs);
|
|
|
|
err = -EINVAL;
|
|
|
|
}
|
|
|
|
kfree(cs);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int erofs_build_cache_strategy(struct erofs_sb_info *sbi,
|
|
|
|
substring_t *args)
|
|
|
|
{
|
|
|
|
infoln("EROFS compression is disabled, so cache strategy is ignored");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* set up default EROFS parameters */
|
2018-07-26 12:21:46 +00:00
|
|
|
static void default_options(struct erofs_sb_info *sbi)
|
|
|
|
{
|
2018-09-19 16:06:56 +00:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
2019-07-31 15:57:49 +00:00
|
|
|
sbi->cache_strategy = EROFS_ZIP_CACHE_READAROUND;
|
2019-07-31 15:57:36 +00:00
|
|
|
sbi->max_sync_decompress_pages = 3;
|
2018-09-19 16:06:56 +00:00
|
|
|
#endif
|
2018-07-26 12:21:52 +00:00
|
|
|
#ifdef CONFIG_EROFS_FS_XATTR
|
|
|
|
set_opt(sbi, XATTR_USER);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EROFS_FS_POSIX_ACL
|
|
|
|
set_opt(sbi, POSIX_ACL);
|
|
|
|
#endif
|
2018-07-26 12:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
2018-07-26 12:21:52 +00:00
|
|
|
Opt_user_xattr,
|
|
|
|
Opt_nouser_xattr,
|
|
|
|
Opt_acl,
|
|
|
|
Opt_noacl,
|
2018-07-26 12:21:54 +00:00
|
|
|
Opt_fault_injection,
|
2019-07-31 15:57:49 +00:00
|
|
|
Opt_cache_strategy,
|
2018-07-26 12:21:46 +00:00
|
|
|
Opt_err
|
|
|
|
};
|
|
|
|
|
|
|
|
static match_table_t erofs_tokens = {
|
2018-07-26 12:21:52 +00:00
|
|
|
{Opt_user_xattr, "user_xattr"},
|
|
|
|
{Opt_nouser_xattr, "nouser_xattr"},
|
|
|
|
{Opt_acl, "acl"},
|
|
|
|
{Opt_noacl, "noacl"},
|
2018-07-26 12:21:54 +00:00
|
|
|
{Opt_fault_injection, "fault_injection=%u"},
|
2019-07-31 15:57:49 +00:00
|
|
|
{Opt_cache_strategy, "cache_strategy=%s"},
|
2018-07-26 12:21:46 +00:00
|
|
|
{Opt_err, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int parse_options(struct super_block *sb, char *options)
|
|
|
|
{
|
|
|
|
substring_t args[MAX_OPT_ARGS];
|
|
|
|
char *p;
|
2018-09-19 14:53:44 +00:00
|
|
|
int err;
|
2018-07-26 12:21:46 +00:00
|
|
|
|
|
|
|
if (!options)
|
|
|
|
return 0;
|
|
|
|
|
2019-03-22 02:38:16 +00:00
|
|
|
while ((p = strsep(&options, ","))) {
|
2018-07-26 12:21:46 +00:00
|
|
|
int token;
|
|
|
|
|
|
|
|
if (!*p)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
args[0].to = args[0].from = NULL;
|
|
|
|
token = match_token(p, erofs_tokens, args);
|
|
|
|
|
|
|
|
switch (token) {
|
2018-07-26 12:21:52 +00:00
|
|
|
#ifdef CONFIG_EROFS_FS_XATTR
|
|
|
|
case Opt_user_xattr:
|
|
|
|
set_opt(EROFS_SB(sb), XATTR_USER);
|
|
|
|
break;
|
|
|
|
case Opt_nouser_xattr:
|
|
|
|
clear_opt(EROFS_SB(sb), XATTR_USER);
|
|
|
|
break;
|
|
|
|
#else
|
|
|
|
case Opt_user_xattr:
|
|
|
|
infoln("user_xattr options not supported");
|
|
|
|
break;
|
|
|
|
case Opt_nouser_xattr:
|
|
|
|
infoln("nouser_xattr options not supported");
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EROFS_FS_POSIX_ACL
|
|
|
|
case Opt_acl:
|
|
|
|
set_opt(EROFS_SB(sb), POSIX_ACL);
|
|
|
|
break;
|
|
|
|
case Opt_noacl:
|
|
|
|
clear_opt(EROFS_SB(sb), POSIX_ACL);
|
|
|
|
break;
|
|
|
|
#else
|
|
|
|
case Opt_acl:
|
|
|
|
infoln("acl options not supported");
|
|
|
|
break;
|
|
|
|
case Opt_noacl:
|
|
|
|
infoln("noacl options not supported");
|
|
|
|
break;
|
|
|
|
#endif
|
2018-09-10 23:51:54 +00:00
|
|
|
case Opt_fault_injection:
|
2018-09-19 14:53:44 +00:00
|
|
|
err = erofs_build_fault_attr(EROFS_SB(sb), args);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2018-07-26 12:21:54 +00:00
|
|
|
break;
|
2019-07-31 15:57:49 +00:00
|
|
|
case Opt_cache_strategy:
|
|
|
|
err = erofs_build_cache_strategy(EROFS_SB(sb), args);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
break;
|
2018-07-26 12:21:46 +00:00
|
|
|
default:
|
2019-07-31 15:57:51 +00:00
|
|
|
errln("Unrecognized mount option \"%s\" or missing value", p);
|
2018-07-26 12:21:46 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-31 15:57:49 +00:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
2018-07-26 12:22:07 +00:00
|
|
|
static const struct address_space_operations managed_cache_aops;
|
|
|
|
|
|
|
|
static int managed_cache_releasepage(struct page *page, gfp_t gfp_mask)
|
|
|
|
{
|
|
|
|
int ret = 1; /* 0 - busy */
|
|
|
|
struct address_space *const mapping = page->mapping;
|
|
|
|
|
2018-12-05 13:23:13 +00:00
|
|
|
DBG_BUGON(!PageLocked(page));
|
|
|
|
DBG_BUGON(mapping->a_ops != &managed_cache_aops);
|
2018-07-26 12:22:07 +00:00
|
|
|
|
|
|
|
if (PagePrivate(page))
|
2018-07-29 05:34:58 +00:00
|
|
|
ret = erofs_try_to_free_cached_page(mapping, page);
|
2018-07-26 12:22:07 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void managed_cache_invalidatepage(struct page *page,
|
2019-03-18 23:58:41 +00:00
|
|
|
unsigned int offset,
|
|
|
|
unsigned int length)
|
2018-07-26 12:22:07 +00:00
|
|
|
{
|
|
|
|
const unsigned int stop = length + offset;
|
|
|
|
|
2018-12-05 13:23:13 +00:00
|
|
|
DBG_BUGON(!PageLocked(page));
|
2018-07-26 12:22:07 +00:00
|
|
|
|
2018-12-05 13:23:13 +00:00
|
|
|
/* Check for potential overflow in debug mode */
|
|
|
|
DBG_BUGON(stop > PAGE_SIZE || stop < length);
|
2018-07-26 12:22:07 +00:00
|
|
|
|
|
|
|
if (offset == 0 && stop == PAGE_SIZE)
|
|
|
|
while (!managed_cache_releasepage(page, GFP_NOFS))
|
|
|
|
cond_resched();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct address_space_operations managed_cache_aops = {
|
|
|
|
.releasepage = managed_cache_releasepage,
|
|
|
|
.invalidatepage = managed_cache_invalidatepage,
|
|
|
|
};
|
|
|
|
|
2019-07-31 15:57:41 +00:00
|
|
|
static int erofs_init_managed_cache(struct super_block *sb)
|
2018-07-26 12:22:07 +00:00
|
|
|
{
|
2019-07-31 15:57:41 +00:00
|
|
|
struct erofs_sb_info *const sbi = EROFS_SB(sb);
|
|
|
|
struct inode *const inode = new_inode(sb);
|
2018-07-26 12:22:07 +00:00
|
|
|
|
2019-03-21 00:06:13 +00:00
|
|
|
if (unlikely(!inode))
|
2019-07-31 15:57:41 +00:00
|
|
|
return -ENOMEM;
|
2018-07-26 12:22:07 +00: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 15:57:42 +00:00
|
|
|
GFP_NOFS | __GFP_HIGHMEM | __GFP_MOVABLE);
|
2019-07-31 15:57:41 +00:00
|
|
|
sbi->managed_cache = inode;
|
|
|
|
return 0;
|
2018-07-26 12:22:07 +00:00
|
|
|
}
|
2019-07-31 15:57:41 +00:00
|
|
|
#else
|
|
|
|
static int erofs_init_managed_cache(struct super_block *sb) { return 0; }
|
2018-07-26 12:22:07 +00:00
|
|
|
#endif
|
|
|
|
|
2019-07-31 15:57:40 +00:00
|
|
|
static int erofs_fill_super(struct super_block *sb, void *data, int silent)
|
2018-07-26 12:21:46 +00:00
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
struct erofs_sb_info *sbi;
|
2019-07-31 15:57:41 +00:00
|
|
|
int err;
|
2018-07-26 12:21:46 +00:00
|
|
|
|
2019-07-31 15:57:40 +00:00
|
|
|
infoln("fill_super, device -> %s", sb->s_id);
|
2018-07-26 12:21:46 +00:00
|
|
|
infoln("options -> %s", (char *)data);
|
|
|
|
|
2019-07-31 15:57:41 +00:00
|
|
|
sb->s_magic = EROFS_SUPER_MAGIC;
|
|
|
|
|
2018-07-26 12:21:46 +00:00
|
|
|
if (unlikely(!sb_set_blocksize(sb, EROFS_BLKSIZ))) {
|
|
|
|
errln("failed to set erofs blksize");
|
2019-07-31 15:57:41 +00:00
|
|
|
return -EINVAL;
|
2018-07-26 12:21:46 +00:00
|
|
|
}
|
|
|
|
|
2019-06-27 05:31:18 +00:00
|
|
|
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
|
2019-07-31 15:57:41 +00:00
|
|
|
if (unlikely(!sbi))
|
|
|
|
return -ENOMEM;
|
2018-07-26 12:21:46 +00:00
|
|
|
|
2019-07-31 15:57:41 +00:00
|
|
|
sb->s_fs_info = sbi;
|
2018-07-26 12:21:46 +00:00
|
|
|
err = superblock_read(sb);
|
|
|
|
if (err)
|
2019-07-31 15:57:41 +00:00
|
|
|
return err;
|
2018-07-26 12:21:46 +00:00
|
|
|
|
2018-09-06 09:01:47 +00:00
|
|
|
sb->s_flags |= SB_RDONLY | SB_NOATIME;
|
2018-07-26 12:21:46 +00:00
|
|
|
sb->s_maxbytes = MAX_LFS_FILESIZE;
|
|
|
|
sb->s_time_gran = 1;
|
|
|
|
|
|
|
|
sb->s_op = &erofs_sops;
|
|
|
|
|
2018-07-26 12:21:52 +00:00
|
|
|
#ifdef CONFIG_EROFS_FS_XATTR
|
|
|
|
sb->s_xattr = erofs_xattr_handlers;
|
|
|
|
#endif
|
2018-07-26 12:21:46 +00:00
|
|
|
/* set erofs default mount options */
|
|
|
|
default_options(sbi);
|
|
|
|
|
|
|
|
err = parse_options(sb, data);
|
2019-07-31 15:57:41 +00:00
|
|
|
if (unlikely(err))
|
|
|
|
return err;
|
2018-07-26 12:21:46 +00:00
|
|
|
|
|
|
|
if (!silent)
|
|
|
|
infoln("root inode @ nid %llu", ROOT_NID(sbi));
|
|
|
|
|
2019-01-29 08:35:20 +00:00
|
|
|
if (test_opt(sbi, POSIX_ACL))
|
|
|
|
sb->s_flags |= SB_POSIXACL;
|
|
|
|
else
|
|
|
|
sb->s_flags &= ~SB_POSIXACL;
|
|
|
|
|
2018-07-26 12:22:05 +00:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
|
|
|
INIT_RADIX_TREE(&sbi->workstn_tree, GFP_ATOMIC);
|
|
|
|
#endif
|
|
|
|
|
2018-07-26 12:21:46 +00:00
|
|
|
/* get the root inode */
|
|
|
|
inode = erofs_iget(sb, ROOT_NID(sbi), true);
|
2019-07-31 15:57:41 +00:00
|
|
|
if (IS_ERR(inode))
|
|
|
|
return PTR_ERR(inode);
|
2018-07-26 12:21:46 +00:00
|
|
|
|
2019-07-31 15:57:41 +00:00
|
|
|
if (unlikely(!S_ISDIR(inode->i_mode))) {
|
2018-07-26 12:21:46 +00:00
|
|
|
errln("rootino(nid %llu) is not a directory(i_mode %o)",
|
2019-03-18 23:58:41 +00:00
|
|
|
ROOT_NID(sbi), inode->i_mode);
|
2019-01-23 06:12:25 +00:00
|
|
|
iput(inode);
|
2019-07-31 15:57:41 +00:00
|
|
|
return -EINVAL;
|
2018-07-26 12:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sb->s_root = d_make_root(inode);
|
2019-07-31 15:57:41 +00:00
|
|
|
if (unlikely(!sb->s_root))
|
|
|
|
return -ENOMEM;
|
2018-07-26 12:21:46 +00:00
|
|
|
|
2019-07-31 15:57:39 +00:00
|
|
|
erofs_shrinker_register(sb);
|
2019-07-31 15:57:41 +00:00
|
|
|
/* sb->s_umount is already locked, SB_ACTIVE and SB_BORN are not set */
|
|
|
|
err = erofs_init_managed_cache(sb);
|
|
|
|
if (unlikely(err))
|
|
|
|
return err;
|
2018-07-26 12:22:03 +00:00
|
|
|
|
2018-07-26 12:21:46 +00:00
|
|
|
if (!silent)
|
2019-07-31 15:57:40 +00:00
|
|
|
infoln("mounted on %s with opts: %s.", sb->s_id, (char *)data);
|
2018-07-26 12:21:46 +00:00
|
|
|
return 0;
|
2019-07-31 15:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *erofs_mount(struct file_system_type *fs_type, int flags,
|
|
|
|
const char *dev_name, void *data)
|
|
|
|
{
|
|
|
|
return mount_bdev(fs_type, flags, dev_name, data, erofs_fill_super);
|
2018-07-26 12:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* could be triggered after deactivate_locked_super()
|
|
|
|
* is called, thus including umount and failed to initialize.
|
|
|
|
*/
|
2019-07-31 15:57:41 +00:00
|
|
|
static void erofs_kill_sb(struct super_block *sb)
|
2018-07-26 12:21:46 +00:00
|
|
|
{
|
2019-07-31 15:57:41 +00:00
|
|
|
struct erofs_sb_info *sbi;
|
|
|
|
|
|
|
|
WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC);
|
|
|
|
infoln("unmounting for %s", sb->s_id);
|
2018-07-26 12:21:46 +00:00
|
|
|
|
2019-07-31 15:57:41 +00:00
|
|
|
kill_block_super(sb);
|
|
|
|
|
|
|
|
sbi = EROFS_SB(sb);
|
2019-03-21 00:06:13 +00:00
|
|
|
if (!sbi)
|
2018-07-26 12:21:46 +00:00
|
|
|
return;
|
2019-07-31 15:57:41 +00:00
|
|
|
kfree(sbi);
|
|
|
|
sb->s_fs_info = NULL;
|
|
|
|
}
|
2018-07-26 12:21:46 +00:00
|
|
|
|
2019-07-31 15:57:41 +00: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 12:21:46 +00:00
|
|
|
|
2019-07-31 15:57:41 +00:00
|
|
|
DBG_BUGON(!sbi);
|
2018-07-26 12:21:46 +00:00
|
|
|
|
2019-07-31 15:57:39 +00:00
|
|
|
erofs_shrinker_unregister(sb);
|
2019-07-31 15:57:49 +00:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
2018-07-26 12:22:07 +00:00
|
|
|
iput(sbi->managed_cache);
|
2019-07-31 15:57:41 +00:00
|
|
|
sbi->managed_cache = NULL;
|
2018-07-26 12:22:07 +00:00
|
|
|
#endif
|
2018-07-26 12:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_system_type erofs_fs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "erofs",
|
|
|
|
.mount = erofs_mount,
|
2019-07-31 15:57:41 +00:00
|
|
|
.kill_sb = erofs_kill_sb,
|
2018-07-26 12:21:46 +00:00
|
|
|
.fs_flags = FS_REQUIRES_DEV,
|
|
|
|
};
|
|
|
|
MODULE_ALIAS_FS("erofs");
|
|
|
|
|
|
|
|
static int __init erofs_module_init(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
erofs_check_ondisk_layout_definitions();
|
|
|
|
infoln("initializing erofs " EROFS_VERSION);
|
|
|
|
|
|
|
|
err = erofs_init_inode_cache();
|
|
|
|
if (err)
|
|
|
|
goto icache_err;
|
|
|
|
|
2019-07-31 15:57:39 +00:00
|
|
|
err = erofs_init_shrinker();
|
2018-07-26 12:22:04 +00: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 12:22:06 +00:00
|
|
|
err = z_erofs_init_zip_subsystem();
|
|
|
|
if (err)
|
|
|
|
goto zip_err;
|
|
|
|
|
2018-07-26 12:21:46 +00:00
|
|
|
err = register_filesystem(&erofs_fs_type);
|
|
|
|
if (err)
|
|
|
|
goto fs_err;
|
|
|
|
|
|
|
|
infoln("successfully to initialize erofs");
|
|
|
|
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 12:22:06 +00:00
|
|
|
z_erofs_exit_zip_subsystem();
|
|
|
|
zip_err:
|
2019-07-31 15:57:39 +00:00
|
|
|
erofs_exit_shrinker();
|
2018-07-26 12:22:04 +00:00
|
|
|
shrinker_err:
|
2018-07-26 12:21:46 +00:00
|
|
|
erofs_exit_inode_cache();
|
|
|
|
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 12:22:06 +00:00
|
|
|
z_erofs_exit_zip_subsystem();
|
2019-07-31 15:57:39 +00:00
|
|
|
erofs_exit_shrinker();
|
2018-07-26 12:21:46 +00:00
|
|
|
erofs_exit_inode_cache();
|
|
|
|
infoln("successfully finalize erofs");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
buf->f_fsid.val[0] = (u32)id;
|
|
|
|
buf->f_fsid.val[1] = (u32)(id >> 32);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int erofs_show_options(struct seq_file *seq, struct dentry *root)
|
|
|
|
{
|
2018-07-26 12:21:52 +00:00
|
|
|
struct erofs_sb_info *sbi __maybe_unused = EROFS_SB(root->d_sb);
|
|
|
|
|
|
|
|
#ifdef CONFIG_EROFS_FS_XATTR
|
|
|
|
if (test_opt(sbi, XATTR_USER))
|
|
|
|
seq_puts(seq, ",user_xattr");
|
|
|
|
else
|
|
|
|
seq_puts(seq, ",nouser_xattr");
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_EROFS_FS_POSIX_ACL
|
|
|
|
if (test_opt(sbi, POSIX_ACL))
|
|
|
|
seq_puts(seq, ",acl");
|
|
|
|
else
|
|
|
|
seq_puts(seq, ",noacl");
|
2018-07-26 12:21:54 +00:00
|
|
|
#endif
|
|
|
|
if (test_opt(sbi, FAULT_INJECTION))
|
|
|
|
seq_printf(seq, ",fault_injection=%u",
|
2019-03-18 23:58:41 +00:00
|
|
|
erofs_get_fault_rate(sbi));
|
2019-07-31 15:57:49 +00:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
|
|
|
if (sbi->cache_strategy == EROFS_ZIP_CACHE_DISABLED) {
|
|
|
|
seq_puts(seq, ",cache_strategy=disabled");
|
|
|
|
} else if (sbi->cache_strategy == EROFS_ZIP_CACHE_READAHEAD) {
|
|
|
|
seq_puts(seq, ",cache_strategy=readahead");
|
|
|
|
} else if (sbi->cache_strategy == EROFS_ZIP_CACHE_READAROUND) {
|
|
|
|
seq_puts(seq, ",cache_strategy=readaround");
|
|
|
|
} else {
|
|
|
|
seq_puts(seq, ",cache_strategy=(unknown)");
|
|
|
|
DBG_BUGON(1);
|
|
|
|
}
|
|
|
|
#endif
|
2018-07-26 12:21:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int erofs_remount(struct super_block *sb, int *flags, char *data)
|
|
|
|
{
|
2018-09-19 14:53:46 +00:00
|
|
|
struct erofs_sb_info *sbi = EROFS_SB(sb);
|
|
|
|
unsigned int org_mnt_opt = sbi->mount_opt;
|
|
|
|
unsigned int org_inject_rate = erofs_get_fault_rate(sbi);
|
|
|
|
int err;
|
|
|
|
|
2018-12-05 13:23:13 +00:00
|
|
|
DBG_BUGON(!sb_rdonly(sb));
|
2018-09-19 14:53:46 +00:00
|
|
|
err = parse_options(sb, data);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
2018-07-26 12:21:46 +00:00
|
|
|
|
2019-01-29 08:35:20 +00:00
|
|
|
if (test_opt(sbi, POSIX_ACL))
|
|
|
|
sb->s_flags |= SB_POSIXACL;
|
|
|
|
else
|
|
|
|
sb->s_flags &= ~SB_POSIXACL;
|
|
|
|
|
2018-09-06 09:01:47 +00:00
|
|
|
*flags |= SB_RDONLY;
|
2018-07-26 12:21:46 +00:00
|
|
|
return 0;
|
2018-09-19 14:53:46 +00:00
|
|
|
out:
|
|
|
|
__erofs_build_fault_attr(sbi, org_inject_rate);
|
|
|
|
sbi->mount_opt = org_mnt_opt;
|
|
|
|
|
|
|
|
return err;
|
2018-07-26 12:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const struct super_operations erofs_sops = {
|
|
|
|
.put_super = erofs_put_super,
|
|
|
|
.alloc_inode = alloc_inode,
|
2019-04-10 18:59:08 +00:00
|
|
|
.free_inode = free_inode,
|
2018-07-26 12:21:46 +00:00
|
|
|
.statfs = erofs_statfs,
|
|
|
|
.show_options = erofs_show_options,
|
|
|
|
.remount_fs = erofs_remount,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_init(erofs_module_init);
|
|
|
|
module_exit(erofs_module_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Enhanced ROM File System");
|
2019-07-31 15:57:51 +00:00
|
|
|
MODULE_AUTHOR("Gao Xiang, Chao Yu, Miao Xie, CONSUMER BG, HUAWEI Inc.");
|
2018-07-26 12:21:46 +00:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|