2019-05-29 23:57:50 +00:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* This file is part of UBIFS.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2006-2008 Nokia Corporation.
|
|
|
|
|
*
|
|
|
|
|
* Authors: Artem Bityutskiy (Битюцкий Артём)
|
|
|
|
|
* Adrian Hunter
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This file implements UBIFS initialization and VFS superblock operations. Some
|
|
|
|
|
* initialization stuff which is rather large and complex is placed at
|
|
|
|
|
* corresponding subsystems, but most of it is here.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
|
#include <linux/kthread.h>
|
2024-10-02 16:58:34 +00:00
|
|
|
|
#include <linux/fs_context.h>
|
|
|
|
|
#include <linux/fs_parser.h>
|
2008-07-14 16:08:37 +00:00
|
|
|
|
#include <linux/seq_file.h>
|
2008-12-18 12:06:51 +00:00
|
|
|
|
#include <linux/math64.h>
|
2008-12-28 06:04:17 +00:00
|
|
|
|
#include <linux/writeback.h>
|
2008-07-14 16:08:37 +00:00
|
|
|
|
#include "ubifs.h"
|
|
|
|
|
|
2020-07-07 10:31:59 +00:00
|
|
|
|
static int ubifs_default_version_set(const char *val, const struct kernel_param *kp)
|
|
|
|
|
{
|
|
|
|
|
int n = 0, ret;
|
|
|
|
|
|
|
|
|
|
ret = kstrtoint(val, 10, &n);
|
|
|
|
|
if (ret != 0 || n < 4 || n > UBIFS_FORMAT_VERSION)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
return param_set_int(val, kp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct kernel_param_ops ubifs_default_version_ops = {
|
|
|
|
|
.set = ubifs_default_version_set,
|
|
|
|
|
.get = param_get_int,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int ubifs_default_version = UBIFS_FORMAT_VERSION;
|
|
|
|
|
module_param_cb(default_version, &ubifs_default_version_ops, &ubifs_default_version, 0600);
|
|
|
|
|
|
2008-11-18 16:09:49 +00:00
|
|
|
|
/*
|
|
|
|
|
* Maximum amount of memory we may 'kmalloc()' without worrying that we are
|
|
|
|
|
* allocating too much.
|
|
|
|
|
*/
|
|
|
|
|
#define UBIFS_KMALLOC_OK (128*1024)
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/* Slab cache for UBIFS inodes */
|
2017-05-16 22:20:26 +00:00
|
|
|
|
static struct kmem_cache *ubifs_inode_slab;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
/* UBIFS TNC shrinker description */
|
2023-09-11 09:44:13 +00:00
|
|
|
|
static struct shrinker *ubifs_shrinker_info;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* validate_inode - validate inode.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
* @inode: the inode to validate
|
|
|
|
|
*
|
|
|
|
|
* This is a helper function for 'ubifs_iget()' which validates various fields
|
|
|
|
|
* of a newly built inode to make sure they contain sane values and prevent
|
|
|
|
|
* possible vulnerabilities. Returns zero if the inode is all right and
|
|
|
|
|
* a non-zero error code if not.
|
|
|
|
|
*/
|
|
|
|
|
static int validate_inode(struct ubifs_info *c, const struct inode *inode)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
const struct ubifs_inode *ui = ubifs_inode(inode);
|
|
|
|
|
|
|
|
|
|
if (inode->i_size > c->max_inode_sz) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "inode is too large (%lld)",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
(long long)inode->i_size);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-11 02:42:52 +00:00
|
|
|
|
if (ui->compr_type >= UBIFS_COMPR_TYPES_CNT) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "unknown compression type %d", ui->compr_type);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ui->xattr_names + ui->xattr_cnt > XATTR_LIST_MAX)
|
|
|
|
|
return 3;
|
|
|
|
|
|
|
|
|
|
if (ui->data_len < 0 || ui->data_len > UBIFS_MAX_INO_DATA)
|
|
|
|
|
return 4;
|
|
|
|
|
|
2011-05-26 06:43:34 +00:00
|
|
|
|
if (ui->xattr && !S_ISREG(inode->i_mode))
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return 5;
|
|
|
|
|
|
2018-07-12 11:01:57 +00:00
|
|
|
|
if (!ubifs_compr_present(c, ui->compr_type)) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_warn(c, "inode %lu uses '%s' compression, but it was not compiled in",
|
2018-07-12 11:01:57 +00:00
|
|
|
|
inode->i_ino, ubifs_compr_name(c, ui->compr_type));
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-25 14:38:29 +00:00
|
|
|
|
err = dbg_check_dir(c, inode);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct inode *ubifs_iget(struct super_block *sb, unsigned long inum)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
union ubifs_key key;
|
|
|
|
|
struct ubifs_ino_node *ino;
|
|
|
|
|
struct ubifs_info *c = sb->s_fs_info;
|
|
|
|
|
struct inode *inode;
|
|
|
|
|
struct ubifs_inode *ui;
|
|
|
|
|
|
|
|
|
|
dbg_gen("inode %lu", inum);
|
|
|
|
|
|
|
|
|
|
inode = iget_locked(sb, inum);
|
|
|
|
|
if (!inode)
|
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
if (!(inode->i_state & I_NEW))
|
|
|
|
|
return inode;
|
|
|
|
|
ui = ubifs_inode(inode);
|
|
|
|
|
|
|
|
|
|
ino = kmalloc(UBIFS_MAX_INO_NODE_SZ, GFP_NOFS);
|
|
|
|
|
if (!ino) {
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ino_key_init(c, &key, inode->i_ino);
|
|
|
|
|
|
|
|
|
|
err = ubifs_tnc_lookup(c, &key, ino);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_ino;
|
|
|
|
|
|
2015-11-07 04:46:11 +00:00
|
|
|
|
inode->i_flags |= S_NOCMTIME;
|
2019-03-26 07:52:32 +00:00
|
|
|
|
|
|
|
|
|
if (!IS_ENABLED(CONFIG_UBIFS_ATIME_SUPPORT))
|
|
|
|
|
inode->i_flags |= S_NOATIME;
|
|
|
|
|
|
2011-10-28 12:13:29 +00:00
|
|
|
|
set_nlink(inode, le32_to_cpu(ino->nlink));
|
2012-02-07 23:50:56 +00:00
|
|
|
|
i_uid_write(inode, le32_to_cpu(ino->uid));
|
|
|
|
|
i_gid_write(inode, le32_to_cpu(ino->gid));
|
2023-10-04 18:52:58 +00:00
|
|
|
|
inode_set_atime(inode, (int64_t)le64_to_cpu(ino->atime_sec),
|
|
|
|
|
le32_to_cpu(ino->atime_nsec));
|
|
|
|
|
inode_set_mtime(inode, (int64_t)le64_to_cpu(ino->mtime_sec),
|
|
|
|
|
le32_to_cpu(ino->mtime_nsec));
|
2023-07-05 19:01:43 +00:00
|
|
|
|
inode_set_ctime(inode, (int64_t)le64_to_cpu(ino->ctime_sec),
|
|
|
|
|
le32_to_cpu(ino->ctime_nsec));
|
2008-07-14 16:08:37 +00:00
|
|
|
|
inode->i_mode = le32_to_cpu(ino->mode);
|
|
|
|
|
inode->i_size = le64_to_cpu(ino->size);
|
|
|
|
|
|
|
|
|
|
ui->data_len = le32_to_cpu(ino->data_len);
|
|
|
|
|
ui->flags = le32_to_cpu(ino->flags);
|
|
|
|
|
ui->compr_type = le16_to_cpu(ino->compr_type);
|
|
|
|
|
ui->creat_sqnum = le64_to_cpu(ino->creat_sqnum);
|
|
|
|
|
ui->xattr_cnt = le32_to_cpu(ino->xattr_cnt);
|
|
|
|
|
ui->xattr_size = le32_to_cpu(ino->xattr_size);
|
|
|
|
|
ui->xattr_names = le32_to_cpu(ino->xattr_names);
|
|
|
|
|
ui->synced_i_size = ui->ui_size = inode->i_size;
|
|
|
|
|
|
|
|
|
|
ui->xattr = (ui->flags & UBIFS_XATTR_FL) ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
err = validate_inode(c, inode);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_invalid;
|
|
|
|
|
|
|
|
|
|
switch (inode->i_mode & S_IFMT) {
|
|
|
|
|
case S_IFREG:
|
|
|
|
|
inode->i_mapping->a_ops = &ubifs_file_address_operations;
|
|
|
|
|
inode->i_op = &ubifs_file_inode_operations;
|
|
|
|
|
inode->i_fop = &ubifs_file_operations;
|
|
|
|
|
if (ui->xattr) {
|
|
|
|
|
ui->data = kmalloc(ui->data_len + 1, GFP_NOFS);
|
|
|
|
|
if (!ui->data) {
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
goto out_ino;
|
|
|
|
|
}
|
|
|
|
|
memcpy(ui->data, ino->data, ui->data_len);
|
|
|
|
|
((char *)ui->data)[ui->data_len] = '\0';
|
|
|
|
|
} else if (ui->data_len != 0) {
|
|
|
|
|
err = 10;
|
|
|
|
|
goto out_invalid;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case S_IFDIR:
|
|
|
|
|
inode->i_op = &ubifs_dir_inode_operations;
|
|
|
|
|
inode->i_fop = &ubifs_dir_operations;
|
|
|
|
|
if (ui->data_len != 0) {
|
|
|
|
|
err = 11;
|
|
|
|
|
goto out_invalid;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case S_IFLNK:
|
|
|
|
|
inode->i_op = &ubifs_symlink_inode_operations;
|
|
|
|
|
if (ui->data_len <= 0 || ui->data_len > UBIFS_MAX_INO_DATA) {
|
|
|
|
|
err = 12;
|
|
|
|
|
goto out_invalid;
|
|
|
|
|
}
|
|
|
|
|
ui->data = kmalloc(ui->data_len + 1, GFP_NOFS);
|
|
|
|
|
if (!ui->data) {
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
goto out_ino;
|
|
|
|
|
}
|
|
|
|
|
memcpy(ui->data, ino->data, ui->data_len);
|
|
|
|
|
((char *)ui->data)[ui->data_len] = '\0';
|
|
|
|
|
break;
|
|
|
|
|
case S_IFBLK:
|
|
|
|
|
case S_IFCHR:
|
|
|
|
|
{
|
|
|
|
|
dev_t rdev;
|
|
|
|
|
union ubifs_dev_desc *dev;
|
|
|
|
|
|
|
|
|
|
ui->data = kmalloc(sizeof(union ubifs_dev_desc), GFP_NOFS);
|
|
|
|
|
if (!ui->data) {
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
goto out_ino;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dev = (union ubifs_dev_desc *)ino->data;
|
|
|
|
|
if (ui->data_len == sizeof(dev->new))
|
|
|
|
|
rdev = new_decode_dev(le32_to_cpu(dev->new));
|
|
|
|
|
else if (ui->data_len == sizeof(dev->huge))
|
|
|
|
|
rdev = huge_decode_dev(le64_to_cpu(dev->huge));
|
|
|
|
|
else {
|
|
|
|
|
err = 13;
|
|
|
|
|
goto out_invalid;
|
|
|
|
|
}
|
|
|
|
|
memcpy(ui->data, ino->data, ui->data_len);
|
|
|
|
|
inode->i_op = &ubifs_file_inode_operations;
|
|
|
|
|
init_special_inode(inode, inode->i_mode, rdev);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case S_IFSOCK:
|
|
|
|
|
case S_IFIFO:
|
|
|
|
|
inode->i_op = &ubifs_file_inode_operations;
|
|
|
|
|
init_special_inode(inode, inode->i_mode, 0);
|
|
|
|
|
if (ui->data_len != 0) {
|
|
|
|
|
err = 14;
|
|
|
|
|
goto out_invalid;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
err = 15;
|
|
|
|
|
goto out_invalid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kfree(ino);
|
|
|
|
|
ubifs_set_inode_flags(inode);
|
|
|
|
|
unlock_new_inode(inode);
|
|
|
|
|
return inode;
|
|
|
|
|
|
|
|
|
|
out_invalid:
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "inode %lu validation failed, error %d", inode->i_ino, err);
|
2020-06-16 07:11:44 +00:00
|
|
|
|
ubifs_dump_node(c, ino, UBIFS_MAX_INO_NODE_SZ);
|
2012-05-16 16:15:56 +00:00
|
|
|
|
ubifs_dump_inode(c, inode);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = -EINVAL;
|
|
|
|
|
out_ino:
|
|
|
|
|
kfree(ino);
|
|
|
|
|
out:
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "failed to read inode %lu, error %d", inode->i_ino, err);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
iget_failed(inode);
|
|
|
|
|
return ERR_PTR(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct inode *ubifs_alloc_inode(struct super_block *sb)
|
|
|
|
|
{
|
|
|
|
|
struct ubifs_inode *ui;
|
|
|
|
|
|
2022-03-22 21:41:03 +00:00
|
|
|
|
ui = alloc_inode_sb(sb, ubifs_inode_slab, GFP_NOFS);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (!ui)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
memset((void *)ui + sizeof(struct inode), 0,
|
|
|
|
|
sizeof(struct ubifs_inode) - sizeof(struct inode));
|
|
|
|
|
mutex_init(&ui->ui_mutex);
|
2021-05-31 12:52:09 +00:00
|
|
|
|
init_rwsem(&ui->xattr_sem);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
spin_lock_init(&ui->ui_lock);
|
|
|
|
|
return &ui->vfs_inode;
|
|
|
|
|
};
|
|
|
|
|
|
2019-04-16 02:23:44 +00:00
|
|
|
|
static void ubifs_free_inode(struct inode *inode)
|
2011-01-07 06:49:49 +00:00
|
|
|
|
{
|
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
2019-04-10 20:21:15 +00:00
|
|
|
|
|
2019-03-26 01:40:38 +00:00
|
|
|
|
kfree(ui->data);
|
2019-04-10 20:21:15 +00:00
|
|
|
|
fscrypt_free_inode(inode);
|
|
|
|
|
|
2011-01-07 06:49:49 +00:00
|
|
|
|
kmem_cache_free(ubifs_inode_slab, ui);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* Note, Linux write-back code calls this without 'i_mutex'.
|
|
|
|
|
*/
|
2010-03-05 08:21:37 +00:00
|
|
|
|
static int ubifs_write_inode(struct inode *inode, struct writeback_control *wbc)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
2008-07-22 08:52:52 +00:00
|
|
|
|
int err = 0;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
|
|
|
|
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_assert(c, !ui->xattr);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (is_bad_inode(inode))
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
mutex_lock(&ui->ui_mutex);
|
|
|
|
|
/*
|
|
|
|
|
* Due to races between write-back forced by budgeting
|
2012-07-25 15:12:14 +00:00
|
|
|
|
* (see 'sync_some_inodes()') and background write-back, the inode may
|
2008-07-14 16:08:37 +00:00
|
|
|
|
* have already been synchronized, do not do this again. This might
|
|
|
|
|
* also happen if it was synchronized in an VFS operation, e.g.
|
|
|
|
|
* 'ubifs_link()'.
|
|
|
|
|
*/
|
|
|
|
|
if (!ui->dirty) {
|
|
|
|
|
mutex_unlock(&ui->ui_mutex);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-22 08:52:52 +00:00
|
|
|
|
/*
|
|
|
|
|
* As an optimization, do not write orphan inodes to the media just
|
|
|
|
|
* because this is not needed.
|
|
|
|
|
*/
|
|
|
|
|
dbg_gen("inode %lu, mode %#x, nlink %u",
|
|
|
|
|
inode->i_ino, (int)inode->i_mode, inode->i_nlink);
|
|
|
|
|
if (inode->i_nlink) {
|
2008-07-22 09:06:13 +00:00
|
|
|
|
err = ubifs_jnl_write_inode(c, inode);
|
2008-07-22 08:52:52 +00:00
|
|
|
|
if (err)
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "can't write inode %lu, error %d",
|
2008-07-22 08:52:52 +00:00
|
|
|
|
inode->i_ino, err);
|
2009-08-27 13:34:19 +00:00
|
|
|
|
else
|
|
|
|
|
err = dbg_check_inode_size(c, inode, ui->ui_size);
|
2008-07-22 08:52:52 +00:00
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
ui->dirty = 0;
|
|
|
|
|
mutex_unlock(&ui->ui_mutex);
|
|
|
|
|
ubifs_release_dirty_inode_budget(c, ui);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 02:35:49 +00:00
|
|
|
|
static int ubifs_drop_inode(struct inode *inode)
|
|
|
|
|
{
|
|
|
|
|
int drop = generic_drop_inode(inode);
|
|
|
|
|
|
|
|
|
|
if (!drop)
|
|
|
|
|
drop = fscrypt_drop_inode(inode);
|
|
|
|
|
|
|
|
|
|
return drop;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-07 04:34:05 +00:00
|
|
|
|
static void ubifs_evict_inode(struct inode *inode)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
2008-07-21 07:59:53 +00:00
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2008-07-21 07:59:53 +00:00
|
|
|
|
if (ui->xattr)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* Extended attribute inode deletions are fully handled in
|
|
|
|
|
* 'ubifs_removexattr()'. These inodes are special and have
|
|
|
|
|
* limited usage, so there is nothing to do here.
|
|
|
|
|
*/
|
|
|
|
|
goto out;
|
|
|
|
|
|
2008-07-18 15:54:29 +00:00
|
|
|
|
dbg_gen("inode %lu, mode %#x", inode->i_ino, (int)inode->i_mode);
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_assert(c, !atomic_read(&inode->i_count));
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2014-04-03 21:47:49 +00:00
|
|
|
|
truncate_inode_pages_final(&inode->i_data);
|
2010-06-07 04:34:05 +00:00
|
|
|
|
|
|
|
|
|
if (inode->i_nlink)
|
|
|
|
|
goto done;
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (is_bad_inode(inode))
|
|
|
|
|
goto out;
|
|
|
|
|
|
2008-07-21 07:59:53 +00:00
|
|
|
|
ui->ui_size = inode->i_size = 0;
|
2008-07-22 10:06:20 +00:00
|
|
|
|
err = ubifs_jnl_delete_inode(c, inode);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (err)
|
|
|
|
|
/*
|
|
|
|
|
* Worst case we have a lost orphan inode wasting space, so a
|
2008-08-13 11:13:26 +00:00
|
|
|
|
* simple error message is OK here.
|
2008-07-14 16:08:37 +00:00
|
|
|
|
*/
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "can't delete inode %lu, error %d",
|
2008-07-22 10:06:20 +00:00
|
|
|
|
inode->i_ino, err);
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
out:
|
2008-07-21 07:59:53 +00:00
|
|
|
|
if (ui->dirty)
|
|
|
|
|
ubifs_release_dirty_inode_budget(c, ui);
|
2009-04-08 12:07:57 +00:00
|
|
|
|
else {
|
|
|
|
|
/* We've deleted something - clean the "no space" flags */
|
2011-03-29 15:04:05 +00:00
|
|
|
|
c->bi.nospace = c->bi.nospace_rp = 0;
|
2009-04-08 12:07:57 +00:00
|
|
|
|
smp_wmb();
|
|
|
|
|
}
|
2010-06-07 04:34:05 +00:00
|
|
|
|
done:
|
2012-05-03 12:48:02 +00:00
|
|
|
|
clear_inode(inode);
|
2018-01-12 04:30:13 +00:00
|
|
|
|
fscrypt_put_encryption_info(inode);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-27 10:53:02 +00:00
|
|
|
|
static void ubifs_dirty_inode(struct inode *inode, int flags)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
2018-07-12 11:01:57 +00:00
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
|
|
|
|
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_assert(c, mutex_is_locked(&ui->ui_mutex));
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (!ui->dirty) {
|
|
|
|
|
ui->dirty = 1;
|
|
|
|
|
dbg_gen("inode %lu", inode->i_ino);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int ubifs_statfs(struct dentry *dentry, struct kstatfs *buf)
|
|
|
|
|
{
|
|
|
|
|
struct ubifs_info *c = dentry->d_sb->s_fs_info;
|
|
|
|
|
unsigned long long free;
|
2008-09-03 11:16:42 +00:00
|
|
|
|
__le32 *uuid = (__le32 *)c->uuid;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
UBIFS: improve statfs reporting even more
Since free space we report in statfs is file size which should
fit to the FS - change the way we calculate free space and use
leb_overhead instead of dark_wm in calculations.
Results of "freespace" test (120MiB volume, 16KiB LEB size,
512 bytes page size). Before the change:
freespace: Test 1: fill the space we have 3 times
freespace: was free: 85204992 bytes 81.3 MiB, wrote: 96489472 bytes 92.0 MiB, delta: 11284480 bytes 10.8 MiB, wrote 13.2% more than predicted
freespace: was free: 83554304 bytes 79.7 MiB, wrote: 96489472 bytes 92.0 MiB, delta: 12935168 bytes 12.3 MiB, wrote 15.5% more than predicted
freespace: was free: 83554304 bytes 79.7 MiB, wrote: 96493568 bytes 92.0 MiB, delta: 12939264 bytes 12.3 MiB, wrote 15.5% more than predicted
freespace: Test 1 finished
freespace: Test 2: gradually lessen amount of free space and fill the FS
freespace: do 10 steps, lessen free space by 7596218 bytes 7.2 MiB each time
freespace: was free: 78675968 bytes 75.0 MiB, wrote: 88903680 bytes 84.8 MiB, delta: 10227712 bytes 9.8 MiB, wrote 13.0% more than predicted
freespace: was free: 72015872 bytes 68.7 MiB, wrote: 81514496 bytes 77.7 MiB, delta: 9498624 bytes 9.1 MiB, wrote 13.2% more than predicted
freespace: was free: 63938560 bytes 61.0 MiB, wrote: 72589312 bytes 69.2 MiB, delta: 8650752 bytes 8.2 MiB, wrote 13.5% more than predicted
freespace: was free: 56127488 bytes 53.5 MiB, wrote: 63762432 bytes 60.8 MiB, delta: 7634944 bytes 7.3 MiB, wrote 13.6% more than predicted
freespace: was free: 48336896 bytes 46.1 MiB, wrote: 54935552 bytes 52.4 MiB, delta: 6598656 bytes 6.3 MiB, wrote 13.7% more than predicted
freespace: was free: 40587264 bytes 38.7 MiB, wrote: 46157824 bytes 44.0 MiB, delta: 5570560 bytes 5.3 MiB, wrote 13.7% more than predicted
freespace: was free: 32841728 bytes 31.3 MiB, wrote: 37384192 bytes 35.7 MiB, delta: 4542464 bytes 4.3 MiB, wrote 13.8% more than predicted
freespace: was free: 25100288 bytes 23.9 MiB, wrote: 28618752 bytes 27.3 MiB, delta: 3518464 bytes 3.4 MiB, wrote 14.0% more than predicted
freespace: was free: 17342464 bytes 16.5 MiB, wrote: 19841024 bytes 18.9 MiB, delta: 2498560 bytes 2.4 MiB, wrote 14.4% more than predicted
freespace: was free: 9605120 bytes 9.2 MiB, wrote: 11063296 bytes 10.6 MiB, delta: 1458176 bytes 1.4 MiB, wrote 15.2% more than predicted
freespace: Test 2 finished
freespace: Test 3: gradually lessen amount of free space by trashing and fill the FS
freespace: do 10 steps, lessen free space by 7606272 bytes 7.3 MiB each time
freespace: trashing: was free: 83668992 bytes 79.8 MiB, need free: 7606272 bytes 7.3 MiB, files created: 248297, delete 225724 (90.9% of them)
freespace: was free: 70803456 bytes 67.5 MiB, wrote: 82485248 bytes 78.7 MiB, delta: 11681792 bytes 11.1 MiB, wrote 16.5% more than predicted
freespace: trashing: was free: 81080320 bytes 77.3 MiB, need free: 15212544 bytes 14.5 MiB, files created: 248711, delete 202047 (81.2% of them)
freespace: was free: 59867136 bytes 57.1 MiB, wrote: 71897088 bytes 68.6 MiB, delta: 12029952 bytes 11.5 MiB, wrote 20.1% more than predicted
freespace: trashing: was free: 82243584 bytes 78.4 MiB, need free: 22818816 bytes 21.8 MiB, files created: 248866, delete 179817 (72.3% of them)
freespace: was free: 50905088 bytes 48.5 MiB, wrote: 63168512 bytes 60.2 MiB, delta: 12263424 bytes 11.7 MiB, wrote 24.1% more than predicted
freespace: trashing: was free: 83402752 bytes 79.5 MiB, need free: 30425088 bytes 29.0 MiB, files created: 248920, delete 158114 (63.5% of them)
freespace: was free: 42651648 bytes 40.7 MiB, wrote: 55406592 bytes 52.8 MiB, delta: 12754944 bytes 12.2 MiB, wrote 29.9% more than predicted
freespace: trashing: was free: 84402176 bytes 80.5 MiB, need free: 38031360 bytes 36.3 MiB, files created: 248709, delete 136641 (54.9% of them)
freespace: was free: 35233792 bytes 33.6 MiB, wrote: 48250880 bytes 46.0 MiB, delta: 13017088 bytes 12.4 MiB, wrote 36.9% more than predicted
freespace: trashing: was free: 82530304 bytes 78.7 MiB, need free: 45637632 bytes 43.5 MiB, files created: 248778, delete 111208 (44.7% of them)
freespace: was free: 27287552 bytes 26.0 MiB, wrote: 40267776 bytes 38.4 MiB, delta: 12980224 bytes 12.4 MiB, wrote 47.6% more than predicted
freespace: trashing: was free: 85114880 bytes 81.2 MiB, need free: 53243904 bytes 50.8 MiB, files created: 248508, delete 93052 (37.4% of them)
freespace: was free: 22437888 bytes 21.4 MiB, wrote: 35328000 bytes 33.7 MiB, delta: 12890112 bytes 12.3 MiB, wrote 57.4% more than predicted
freespace: trashing: was free: 84103168 bytes 80.2 MiB, need free: 60850176 bytes 58.0 MiB, files created: 248637, delete 68743 (27.6% of them)
freespace: was free: 15536128 bytes 14.8 MiB, wrote: 28319744 bytes 27.0 MiB, delta: 12783616 bytes 12.2 MiB, wrote 82.3% more than predicted
freespace: trashing: was free: 84357120 bytes 80.4 MiB, need free: 68456448 bytes 65.3 MiB, files created: 248567, delete 46852 (18.8% of them)
freespace: was free: 9015296 bytes 8.6 MiB, wrote: 22044672 bytes 21.0 MiB, delta: 13029376 bytes 12.4 MiB, wrote 144.5% more than predicted
freespace: trashing: was free: 84942848 bytes 81.0 MiB, need free: 76062720 bytes 72.5 MiB, files created: 248636, delete 25993 (10.5% of them)
freespace: was free: 6086656 bytes 5.8 MiB, wrote: 8331264 bytes 7.9 MiB, delta: 2244608 bytes 2.1 MiB, wrote 36.9% more than predicted
freespace: Test 3 finished
freespace: finished successfully
After the change:
freespace: Test 1: fill the space we have 3 times
freespace: was free: 94048256 bytes 89.7 MiB, wrote: 96489472 bytes 92.0 MiB, delta: 2441216 bytes 2.3 MiB, wrote 2.6% more than predicted
freespace: was free: 92246016 bytes 88.0 MiB, wrote: 96493568 bytes 92.0 MiB, delta: 4247552 bytes 4.1 MiB, wrote 4.6% more than predicted
freespace: was free: 92254208 bytes 88.0 MiB, wrote: 96489472 bytes 92.0 MiB, delta: 4235264 bytes 4.0 MiB, wrote 4.6% more than predicted
freespace: Test 1 finished
freespace: Test 2: gradually lessen amount of free space and fill the FS
freespace: do 10 steps, lessen free space by 8386001 bytes 8.0 MiB each time
freespace: was free: 86605824 bytes 82.6 MiB, wrote: 88252416 bytes 84.2 MiB, delta: 1646592 bytes 1.6 MiB, wrote 1.9% more than predicted
freespace: was free: 78667776 bytes 75.0 MiB, wrote: 80715776 bytes 77.0 MiB, delta: 2048000 bytes 2.0 MiB, wrote 2.6% more than predicted
freespace: was free: 69615616 bytes 66.4 MiB, wrote: 71630848 bytes 68.3 MiB, delta: 2015232 bytes 1.9 MiB, wrote 2.9% more than predicted
freespace: was free: 61018112 bytes 58.2 MiB, wrote: 62783488 bytes 59.9 MiB, delta: 1765376 bytes 1.7 MiB, wrote 2.9% more than predicted
freespace: was free: 52424704 bytes 50.0 MiB, wrote: 53968896 bytes 51.5 MiB, delta: 1544192 bytes 1.5 MiB, wrote 2.9% more than predicted
freespace: was free: 43880448 bytes 41.8 MiB, wrote: 45199360 bytes 43.1 MiB, delta: 1318912 bytes 1.3 MiB, wrote 3.0% more than predicted
freespace: was free: 35332096 bytes 33.7 MiB, wrote: 36425728 bytes 34.7 MiB, delta: 1093632 bytes 1.0 MiB, wrote 3.1% more than predicted
freespace: was free: 26771456 bytes 25.5 MiB, wrote: 27643904 bytes 26.4 MiB, delta: 872448 bytes 852.0 KiB, wrote 3.3% more than predicted
freespace: was free: 18231296 bytes 17.4 MiB, wrote: 18878464 bytes 18.0 MiB, delta: 647168 bytes 632.0 KiB, wrote 3.5% more than predicted
freespace: was free: 9674752 bytes 9.2 MiB, wrote: 10088448 bytes 9.6 MiB, delta: 413696 bytes 404.0 KiB, wrote 4.3% more than predicted
freespace: Test 2 finished
freespace: Test 3: gradually lessen amount of free space by trashing and fill the FS
freespace: do 10 steps, lessen free space by 8397544 bytes 8.0 MiB each time
freespace: trashing: was free: 92372992 bytes 88.1 MiB, need free: 8397552 bytes 8.0 MiB, files created: 248296, delete 225723 (90.9% of them)
freespace: was free: 71909376 bytes 68.6 MiB, wrote: 82472960 bytes 78.7 MiB, delta: 10563584 bytes 10.1 MiB, wrote 14.7% more than predicted
freespace: trashing: was free: 88989696 bytes 84.9 MiB, need free: 16795096 bytes 16.0 MiB, files created: 248794, delete 201838 (81.1% of them)
freespace: was free: 60354560 bytes 57.6 MiB, wrote: 71782400 bytes 68.5 MiB, delta: 11427840 bytes 10.9 MiB, wrote 18.9% more than predicted
freespace: trashing: was free: 90304512 bytes 86.1 MiB, need free: 25192640 bytes 24.0 MiB, files created: 248733, delete 179342 (72.1% of them)
freespace: was free: 51187712 bytes 48.8 MiB, wrote: 62943232 bytes 60.0 MiB, delta: 11755520 bytes 11.2 MiB, wrote 23.0% more than predicted
freespace: trashing: was free: 91209728 bytes 87.0 MiB, need free: 33590184 bytes 32.0 MiB, files created: 248779, delete 157160 (63.2% of them)
freespace: was free: 42704896 bytes 40.7 MiB, wrote: 55050240 bytes 52.5 MiB, delta: 12345344 bytes 11.8 MiB, wrote 28.9% more than predicted
freespace: trashing: was free: 92700672 bytes 88.4 MiB, need free: 41987728 bytes 40.0 MiB, files created: 248848, delete 136135 (54.7% of them)
freespace: was free: 35250176 bytes 33.6 MiB, wrote: 48115712 bytes 45.9 MiB, delta: 12865536 bytes 12.3 MiB, wrote 36.5% more than predicted
freespace: trashing: was free: 93986816 bytes 89.6 MiB, need free: 50385272 bytes 48.1 MiB, files created: 248723, delete 115385 (46.4% of them)
freespace: was free: 29995008 bytes 28.6 MiB, wrote: 41582592 bytes 39.7 MiB, delta: 11587584 bytes 11.1 MiB, wrote 38.6% more than predicted
freespace: trashing: was free: 91881472 bytes 87.6 MiB, need free: 58782816 bytes 56.1 MiB, files created: 248645, delete 89569 (36.0% of them)
freespace: was free: 22511616 bytes 21.5 MiB, wrote: 34705408 bytes 33.1 MiB, delta: 12193792 bytes 11.6 MiB, wrote 54.2% more than predicted
freespace: trashing: was free: 91774976 bytes 87.5 MiB, need free: 67180360 bytes 64.1 MiB, files created: 248580, delete 66616 (26.8% of them)
freespace: was free: 16908288 bytes 16.1 MiB, wrote: 26898432 bytes 25.7 MiB, delta: 9990144 bytes 9.5 MiB, wrote 59.1% more than predicted
freespace: trashing: was free: 92450816 bytes 88.2 MiB, need free: 75577904 bytes 72.1 MiB, files created: 248654, delete 45381 (18.3% of them)
freespace: was free: 10170368 bytes 9.7 MiB, wrote: 19111936 bytes 18.2 MiB, delta: 8941568 bytes 8.5 MiB, wrote 87.9% more than predicted
freespace: trashing: was free: 93282304 bytes 89.0 MiB, need free: 83975448 bytes 80.1 MiB, files created: 248513, delete 24794 (10.0% of them)
freespace: was free: 3911680 bytes 3.7 MiB, wrote: 7872512 bytes 7.5 MiB, delta: 3960832 bytes 3.8 MiB, wrote 101.3% more than predicted
freespace: Test 3 finished
freespace: finished successfully
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2008-08-25 15:58:19 +00:00
|
|
|
|
free = ubifs_get_free_space(c);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
dbg_gen("free space %lld bytes (%lld blocks)",
|
|
|
|
|
free, free >> UBIFS_BLOCK_SHIFT);
|
|
|
|
|
|
|
|
|
|
buf->f_type = UBIFS_SUPER_MAGIC;
|
|
|
|
|
buf->f_bsize = UBIFS_BLOCK_SIZE;
|
|
|
|
|
buf->f_blocks = c->block_cnt;
|
|
|
|
|
buf->f_bfree = free >> UBIFS_BLOCK_SHIFT;
|
|
|
|
|
if (free > c->report_rp_size)
|
|
|
|
|
buf->f_bavail = (free - c->report_rp_size) >> UBIFS_BLOCK_SHIFT;
|
|
|
|
|
else
|
|
|
|
|
buf->f_bavail = 0;
|
|
|
|
|
buf->f_files = 0;
|
|
|
|
|
buf->f_ffree = 0;
|
|
|
|
|
buf->f_namelen = UBIFS_MAX_NLEN;
|
2008-09-03 11:16:42 +00:00
|
|
|
|
buf->f_fsid.val[0] = le32_to_cpu(uuid[0]) ^ le32_to_cpu(uuid[2]);
|
|
|
|
|
buf->f_fsid.val[1] = le32_to_cpu(uuid[1]) ^ le32_to_cpu(uuid[3]);
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_assert(c, buf->f_bfree <= c->block_cnt);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-09 02:32:45 +00:00
|
|
|
|
static int ubifs_show_options(struct seq_file *s, struct dentry *root)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
2011-12-09 02:32:45 +00:00
|
|
|
|
struct ubifs_info *c = root->d_sb->s_fs_info;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
if (c->mount_opts.unmount_mode == 2)
|
2014-07-15 19:26:35 +00:00
|
|
|
|
seq_puts(s, ",fast_unmount");
|
2008-07-14 16:08:37 +00:00
|
|
|
|
else if (c->mount_opts.unmount_mode == 1)
|
2014-07-15 19:26:35 +00:00
|
|
|
|
seq_puts(s, ",norm_unmount");
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2008-09-02 13:29:46 +00:00
|
|
|
|
if (c->mount_opts.bulk_read == 2)
|
2014-07-15 19:26:35 +00:00
|
|
|
|
seq_puts(s, ",bulk_read");
|
2008-09-02 13:29:46 +00:00
|
|
|
|
else if (c->mount_opts.bulk_read == 1)
|
2014-07-15 19:26:35 +00:00
|
|
|
|
seq_puts(s, ",no_bulk_read");
|
2008-09-02 13:29:46 +00:00
|
|
|
|
|
2008-09-04 13:26:00 +00:00
|
|
|
|
if (c->mount_opts.chk_data_crc == 2)
|
2014-07-15 19:26:35 +00:00
|
|
|
|
seq_puts(s, ",chk_data_crc");
|
2008-09-04 13:26:00 +00:00
|
|
|
|
else if (c->mount_opts.chk_data_crc == 1)
|
2014-07-15 19:26:35 +00:00
|
|
|
|
seq_puts(s, ",no_chk_data_crc");
|
2008-09-04 13:26:00 +00:00
|
|
|
|
|
2008-11-01 12:57:49 +00:00
|
|
|
|
if (c->mount_opts.override_compr) {
|
2009-03-18 11:29:39 +00:00
|
|
|
|
seq_printf(s, ",compr=%s",
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_compr_name(c, c->mount_opts.compr_type));
|
2008-11-01 12:57:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 11:01:59 +00:00
|
|
|
|
seq_printf(s, ",assert=%s", ubifs_assert_action_name(c));
|
ubifs: allow userspace to map mounts to volumes
There currently appears to be no way for userspace to find out the
underlying volume number for a mounted ubifs file system, since ubifs
uses anonymous block devices. The volume name is present in
/proc/mounts but UBI volumes can be renamed after the volume has been
mounted.
To remedy this, show the UBI number and UBI volume number as part of the
options visible under /proc/mounts.
Also, accept and ignore the ubi= vol= options if they are used mounting
(patch from Richard Weinberger).
# mount -t ubifs ubi:baz x
# mount
ubi:baz on /root/x type ubifs (rw,relatime,ubi=0,vol=2)
# ubirename /dev/ubi0 baz bazz
# mount
ubi:baz on /root/x type ubifs (rw,relatime,ubi=0,vol=2)
# ubinfo -d 0 -n 2
Volume ID: 2 (on ubi0)
Type: dynamic
Alignment: 1
Size: 67 LEBs (1063424 bytes, 1.0 MiB)
State: OK
Name: bazz
Character device major/minor: 254:3
Signed-off-by: Rabin Vincent <rabinv@axis.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2017-05-31 09:40:27 +00:00
|
|
|
|
seq_printf(s, ",ubi=%d,vol=%d", c->vi.ubi_num, c->vi.vol_id);
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int ubifs_sync_fs(struct super_block *sb, int wait)
|
|
|
|
|
{
|
2008-12-28 06:16:32 +00:00
|
|
|
|
int i, err;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
struct ubifs_info *c = sb->s_fs_info;
|
2008-12-28 06:04:17 +00:00
|
|
|
|
|
2009-01-06 22:40:23 +00:00
|
|
|
|
/*
|
2009-01-09 19:02:37 +00:00
|
|
|
|
* Zero @wait is just an advisory thing to help the file system shove
|
|
|
|
|
* lots of data into the queues, and there will be the second
|
2009-01-06 22:40:23 +00:00
|
|
|
|
* '->sync_fs()' call, with non-zero @wait.
|
|
|
|
|
*/
|
2009-01-09 19:02:37 +00:00
|
|
|
|
if (!wait)
|
|
|
|
|
return 0;
|
2009-01-06 22:40:23 +00:00
|
|
|
|
|
2009-01-29 09:17:24 +00:00
|
|
|
|
/*
|
|
|
|
|
* Synchronize write buffers, because 'ubifs_run_commit()' does not
|
|
|
|
|
* do this if it waits for an already running commit.
|
|
|
|
|
*/
|
|
|
|
|
for (i = 0; i < c->jhead_cnt; i++) {
|
|
|
|
|
err = ubifs_wbuf_sync(&c->jheads[i].wbuf);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-20 14:56:19 +00:00
|
|
|
|
/*
|
|
|
|
|
* Strictly speaking, it is not necessary to commit the journal here,
|
|
|
|
|
* synchronizing write-buffers would be enough. But committing makes
|
|
|
|
|
* UBIFS free space predictions much more accurate, so we want to let
|
|
|
|
|
* the user be able to get more accurate results of 'statfs()' after
|
|
|
|
|
* they synchronize the file system.
|
|
|
|
|
*/
|
2008-12-28 06:16:32 +00:00
|
|
|
|
err = ubifs_run_commit(c);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
2008-09-09 09:31:37 +00:00
|
|
|
|
|
2008-12-28 06:18:43 +00:00
|
|
|
|
return ubi_sync(c->vi.ubi_num);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* init_constants_early - initialize UBIFS constants.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* This function initialize UBIFS constants which do not need the superblock to
|
|
|
|
|
* be read. It also checks that the UBI volume satisfies basic UBIFS
|
|
|
|
|
* requirements. Returns zero in case of success and a negative error code in
|
|
|
|
|
* case of failure.
|
|
|
|
|
*/
|
|
|
|
|
static int init_constants_early(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
if (c->vi.corrupted) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_warn(c, "UBI volume is corrupted - read-only mode");
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->ro_media = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c->di.ro_mode) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_msg(c, "read-only UBI device");
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->ro_media = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c->vi.vol_type == UBI_STATIC_VOLUME) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_msg(c, "static UBI volume - read-only mode");
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->ro_media = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c->leb_cnt = c->vi.size;
|
|
|
|
|
c->leb_size = c->vi.usable_leb_size;
|
2011-02-14 13:17:55 +00:00
|
|
|
|
c->leb_start = c->di.leb_start;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->half_leb_size = c->leb_size / 2;
|
|
|
|
|
c->min_io_size = c->di.min_io_size;
|
|
|
|
|
c->min_io_shift = fls(c->min_io_size) - 1;
|
2011-01-30 16:58:32 +00:00
|
|
|
|
c->max_write_size = c->di.max_write_size;
|
|
|
|
|
c->max_write_shift = fls(c->max_write_size) - 1;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
if (c->leb_size < UBIFS_MIN_LEB_SZ) {
|
2016-07-18 22:26:55 +00:00
|
|
|
|
ubifs_errc(c, "too small LEBs (%d bytes), min. is %d bytes",
|
|
|
|
|
c->leb_size, UBIFS_MIN_LEB_SZ);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c->leb_cnt < UBIFS_MIN_LEB_CNT) {
|
2016-07-18 22:26:55 +00:00
|
|
|
|
ubifs_errc(c, "too few LEBs (%d), min. is %d",
|
|
|
|
|
c->leb_cnt, UBIFS_MIN_LEB_CNT);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_power_of_2(c->min_io_size)) {
|
2016-07-18 22:26:55 +00:00
|
|
|
|
ubifs_errc(c, "bad min. I/O size %d", c->min_io_size);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-30 16:58:32 +00:00
|
|
|
|
/*
|
|
|
|
|
* Maximum write size has to be greater or equivalent to min. I/O
|
|
|
|
|
* size, and be multiple of min. I/O size.
|
|
|
|
|
*/
|
|
|
|
|
if (c->max_write_size < c->min_io_size ||
|
|
|
|
|
c->max_write_size % c->min_io_size ||
|
|
|
|
|
!is_power_of_2(c->max_write_size)) {
|
2016-07-18 22:26:55 +00:00
|
|
|
|
ubifs_errc(c, "bad write buffer size %d for %d min. I/O unit",
|
|
|
|
|
c->max_write_size, c->min_io_size);
|
2011-01-30 16:58:32 +00:00
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* UBIFS aligns all node to 8-byte boundary, so to make function in
|
|
|
|
|
* io.c simpler, assume minimum I/O unit size to be 8 bytes if it is
|
|
|
|
|
* less than 8.
|
|
|
|
|
*/
|
|
|
|
|
if (c->min_io_size < 8) {
|
|
|
|
|
c->min_io_size = 8;
|
|
|
|
|
c->min_io_shift = 3;
|
2011-01-30 16:58:32 +00:00
|
|
|
|
if (c->max_write_size < c->min_io_size) {
|
|
|
|
|
c->max_write_size = c->min_io_size;
|
|
|
|
|
c->max_write_shift = c->min_io_shift;
|
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c->ref_node_alsz = ALIGN(UBIFS_REF_NODE_SZ, c->min_io_size);
|
|
|
|
|
c->mst_node_alsz = ALIGN(UBIFS_MST_NODE_SZ, c->min_io_size);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Initialize node length ranges which are mostly needed for node
|
|
|
|
|
* length validation.
|
|
|
|
|
*/
|
|
|
|
|
c->ranges[UBIFS_PAD_NODE].len = UBIFS_PAD_NODE_SZ;
|
|
|
|
|
c->ranges[UBIFS_SB_NODE].len = UBIFS_SB_NODE_SZ;
|
|
|
|
|
c->ranges[UBIFS_MST_NODE].len = UBIFS_MST_NODE_SZ;
|
|
|
|
|
c->ranges[UBIFS_REF_NODE].len = UBIFS_REF_NODE_SZ;
|
|
|
|
|
c->ranges[UBIFS_TRUN_NODE].len = UBIFS_TRUN_NODE_SZ;
|
|
|
|
|
c->ranges[UBIFS_CS_NODE].len = UBIFS_CS_NODE_SZ;
|
2018-09-07 12:36:45 +00:00
|
|
|
|
c->ranges[UBIFS_AUTH_NODE].min_len = UBIFS_AUTH_NODE_SZ;
|
|
|
|
|
c->ranges[UBIFS_AUTH_NODE].max_len = UBIFS_AUTH_NODE_SZ +
|
|
|
|
|
UBIFS_MAX_HMAC_LEN;
|
2019-05-14 08:33:22 +00:00
|
|
|
|
c->ranges[UBIFS_SIG_NODE].min_len = UBIFS_SIG_NODE_SZ;
|
|
|
|
|
c->ranges[UBIFS_SIG_NODE].max_len = c->leb_size - UBIFS_SB_NODE_SZ;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
c->ranges[UBIFS_INO_NODE].min_len = UBIFS_INO_NODE_SZ;
|
|
|
|
|
c->ranges[UBIFS_INO_NODE].max_len = UBIFS_MAX_INO_NODE_SZ;
|
|
|
|
|
c->ranges[UBIFS_ORPH_NODE].min_len =
|
|
|
|
|
UBIFS_ORPH_NODE_SZ + sizeof(__le64);
|
|
|
|
|
c->ranges[UBIFS_ORPH_NODE].max_len = c->leb_size;
|
|
|
|
|
c->ranges[UBIFS_DENT_NODE].min_len = UBIFS_DENT_NODE_SZ;
|
|
|
|
|
c->ranges[UBIFS_DENT_NODE].max_len = UBIFS_MAX_DENT_NODE_SZ;
|
|
|
|
|
c->ranges[UBIFS_XENT_NODE].min_len = UBIFS_XENT_NODE_SZ;
|
|
|
|
|
c->ranges[UBIFS_XENT_NODE].max_len = UBIFS_MAX_XENT_NODE_SZ;
|
|
|
|
|
c->ranges[UBIFS_DATA_NODE].min_len = UBIFS_DATA_NODE_SZ;
|
|
|
|
|
c->ranges[UBIFS_DATA_NODE].max_len = UBIFS_MAX_DATA_NODE_SZ;
|
|
|
|
|
/*
|
|
|
|
|
* Minimum indexing node size is amended later when superblock is
|
|
|
|
|
* read and the key length is known.
|
|
|
|
|
*/
|
|
|
|
|
c->ranges[UBIFS_IDX_NODE].min_len = UBIFS_IDX_NODE_SZ + UBIFS_BRANCH_SZ;
|
|
|
|
|
/*
|
|
|
|
|
* Maximum indexing node size is amended later when superblock is
|
|
|
|
|
* read and the fanout is known.
|
|
|
|
|
*/
|
|
|
|
|
c->ranges[UBIFS_IDX_NODE].max_len = INT_MAX;
|
|
|
|
|
|
|
|
|
|
/*
|
2009-01-19 17:57:27 +00:00
|
|
|
|
* Initialize dead and dark LEB space watermarks. See gc.c for comments
|
|
|
|
|
* about these values.
|
2008-07-14 16:08:37 +00:00
|
|
|
|
*/
|
|
|
|
|
c->dead_wm = ALIGN(MIN_WRITE_SZ, c->min_io_size);
|
|
|
|
|
c->dark_wm = ALIGN(UBIFS_MAX_NODE_SZ, c->min_io_size);
|
|
|
|
|
|
2008-08-22 15:23:22 +00:00
|
|
|
|
/*
|
|
|
|
|
* Calculate how many bytes would be wasted at the end of LEB if it was
|
|
|
|
|
* fully filled with data nodes of maximum size. This is used in
|
|
|
|
|
* calculations when reporting free space.
|
|
|
|
|
*/
|
|
|
|
|
c->leb_overhead = c->leb_size % UBIFS_MAX_DATA_NODE_SZ;
|
2008-11-18 16:09:49 +00:00
|
|
|
|
|
2008-09-02 13:29:46 +00:00
|
|
|
|
/* Buffer size for bulk-reads */
|
2008-11-18 18:20:05 +00:00
|
|
|
|
c->max_bu_buf_len = UBIFS_MAX_BULK_READ * UBIFS_MAX_DATA_NODE_SZ;
|
|
|
|
|
if (c->max_bu_buf_len > c->leb_size)
|
|
|
|
|
c->max_bu_buf_len = c->leb_size;
|
2019-08-13 21:55:48 +00:00
|
|
|
|
|
|
|
|
|
/* Log is ready, preserve one LEB for commits. */
|
|
|
|
|
c->min_log_bytes = c->leb_size;
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* bud_wbuf_callback - bud LEB write-buffer synchronization call-back.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
* @lnum: LEB the write-buffer was synchronized to
|
|
|
|
|
* @free: how many free bytes left in this LEB
|
|
|
|
|
* @pad: how many bytes were padded
|
|
|
|
|
*
|
|
|
|
|
* This is a callback function which is called by the I/O unit when the
|
|
|
|
|
* write-buffer is synchronized. We need this to correctly maintain space
|
|
|
|
|
* accounting in bud logical eraseblocks. This function returns zero in case of
|
|
|
|
|
* success and a negative error code in case of failure.
|
|
|
|
|
*
|
|
|
|
|
* This function actually belongs to the journal, but we keep it here because
|
|
|
|
|
* we want to keep it static.
|
|
|
|
|
*/
|
|
|
|
|
static int bud_wbuf_callback(struct ubifs_info *c, int lnum, int free, int pad)
|
|
|
|
|
{
|
|
|
|
|
return ubifs_update_one_lp(c, lnum, free, pad, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2008-12-27 17:18:00 +00:00
|
|
|
|
* init_constants_sb - initialize UBIFS constants.
|
2008-07-14 16:08:37 +00:00
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* This is a helper function which initializes various UBIFS constants after
|
|
|
|
|
* the superblock has been read. It also checks various UBIFS parameters and
|
|
|
|
|
* makes sure they are all right. Returns zero in case of success and a
|
|
|
|
|
* negative error code in case of failure.
|
|
|
|
|
*/
|
2008-12-27 17:18:00 +00:00
|
|
|
|
static int init_constants_sb(struct ubifs_info *c)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
|
|
|
|
int tmp, err;
|
2008-12-18 12:06:51 +00:00
|
|
|
|
long long tmp64;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
c->main_bytes = (long long)c->main_lebs * c->leb_size;
|
|
|
|
|
c->max_znode_sz = sizeof(struct ubifs_znode) +
|
|
|
|
|
c->fanout * sizeof(struct ubifs_zbranch);
|
|
|
|
|
|
|
|
|
|
tmp = ubifs_idx_node_sz(c, 1);
|
|
|
|
|
c->ranges[UBIFS_IDX_NODE].min_len = tmp;
|
|
|
|
|
c->min_idx_node_sz = ALIGN(tmp, 8);
|
|
|
|
|
|
|
|
|
|
tmp = ubifs_idx_node_sz(c, c->fanout);
|
|
|
|
|
c->ranges[UBIFS_IDX_NODE].max_len = tmp;
|
|
|
|
|
c->max_idx_node_sz = ALIGN(tmp, 8);
|
|
|
|
|
|
|
|
|
|
/* Make sure LEB size is large enough to fit full commit */
|
|
|
|
|
tmp = UBIFS_CS_NODE_SZ + UBIFS_REF_NODE_SZ * c->jhead_cnt;
|
|
|
|
|
tmp = ALIGN(tmp, c->min_io_size);
|
|
|
|
|
if (tmp > c->leb_size) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "too small LEB size %d, at least %d needed",
|
2012-05-16 17:11:23 +00:00
|
|
|
|
c->leb_size, tmp);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Make sure that the log is large enough to fit reference nodes for
|
|
|
|
|
* all buds plus one reserved LEB.
|
|
|
|
|
*/
|
2008-12-18 12:06:51 +00:00
|
|
|
|
tmp64 = c->max_bud_bytes + c->leb_size - 1;
|
|
|
|
|
c->max_bud_cnt = div_u64(tmp64, c->leb_size);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
tmp = (c->ref_node_alsz * c->max_bud_cnt + c->leb_size - 1);
|
|
|
|
|
tmp /= c->leb_size;
|
|
|
|
|
tmp += 1;
|
|
|
|
|
if (c->log_lebs < tmp) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "too small log %d LEBs, required min. %d LEBs",
|
2012-05-16 17:11:23 +00:00
|
|
|
|
c->log_lebs, tmp);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* When budgeting we assume worst-case scenarios when the pages are not
|
|
|
|
|
* be compressed and direntries are of the maximum size.
|
|
|
|
|
*
|
|
|
|
|
* Note, data, which may be stored in inodes is budgeted separately, so
|
2011-03-29 15:04:05 +00:00
|
|
|
|
* it is not included into 'c->bi.inode_budget'.
|
2008-07-14 16:08:37 +00:00
|
|
|
|
*/
|
2011-03-29 15:04:05 +00:00
|
|
|
|
c->bi.page_budget = UBIFS_MAX_DATA_NODE_SZ * UBIFS_BLOCKS_PER_PAGE;
|
|
|
|
|
c->bi.inode_budget = UBIFS_INO_NODE_SZ;
|
|
|
|
|
c->bi.dent_budget = UBIFS_MAX_DENT_NODE_SZ;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* When the amount of flash space used by buds becomes
|
|
|
|
|
* 'c->max_bud_bytes', UBIFS just blocks all writers and starts commit.
|
|
|
|
|
* The writers are unblocked when the commit is finished. To avoid
|
|
|
|
|
* writers to be blocked UBIFS initiates background commit in advance,
|
|
|
|
|
* when number of bud bytes becomes above the limit defined below.
|
|
|
|
|
*/
|
|
|
|
|
c->bg_bud_bytes = (c->max_bud_bytes * 13) >> 4;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Ensure minimum journal size. All the bytes in the journal heads are
|
|
|
|
|
* considered to be used, when calculating the current journal usage.
|
|
|
|
|
* Consequently, if the journal is too small, UBIFS will treat it as
|
|
|
|
|
* always full.
|
|
|
|
|
*/
|
2008-12-18 12:06:51 +00:00
|
|
|
|
tmp64 = (long long)(c->jhead_cnt + 1) * c->leb_size + 1;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (c->bg_bud_bytes < tmp64)
|
|
|
|
|
c->bg_bud_bytes = tmp64;
|
|
|
|
|
if (c->max_bud_bytes < tmp64 + c->leb_size)
|
|
|
|
|
c->max_bud_bytes = tmp64 + c->leb_size;
|
|
|
|
|
|
|
|
|
|
err = ubifs_calc_lpt_geom(c);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
2009-03-16 07:56:57 +00:00
|
|
|
|
/* Initialize effective LEB size used in budgeting calculations */
|
|
|
|
|
c->idx_leb_size = c->leb_size - c->max_idx_node_sz;
|
2008-12-27 17:18:00 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* init_constants_master - initialize UBIFS constants.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* This is a helper function which initializes various UBIFS constants after
|
|
|
|
|
* the master node has been read. It also checks various UBIFS parameters and
|
|
|
|
|
* makes sure they are all right.
|
|
|
|
|
*/
|
|
|
|
|
static void init_constants_master(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
long long tmp64;
|
|
|
|
|
|
2011-03-29 15:04:05 +00:00
|
|
|
|
c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c);
|
2009-03-16 07:56:57 +00:00
|
|
|
|
c->report_rp_size = ubifs_reported_space(c, c->rp_size);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Calculate total amount of FS blocks. This number is not used
|
|
|
|
|
* internally because it does not make much sense for UBIFS, but it is
|
|
|
|
|
* necessary to report something for the 'statfs()' call.
|
|
|
|
|
*
|
UBIFS: improve statfs reporting even more
Since free space we report in statfs is file size which should
fit to the FS - change the way we calculate free space and use
leb_overhead instead of dark_wm in calculations.
Results of "freespace" test (120MiB volume, 16KiB LEB size,
512 bytes page size). Before the change:
freespace: Test 1: fill the space we have 3 times
freespace: was free: 85204992 bytes 81.3 MiB, wrote: 96489472 bytes 92.0 MiB, delta: 11284480 bytes 10.8 MiB, wrote 13.2% more than predicted
freespace: was free: 83554304 bytes 79.7 MiB, wrote: 96489472 bytes 92.0 MiB, delta: 12935168 bytes 12.3 MiB, wrote 15.5% more than predicted
freespace: was free: 83554304 bytes 79.7 MiB, wrote: 96493568 bytes 92.0 MiB, delta: 12939264 bytes 12.3 MiB, wrote 15.5% more than predicted
freespace: Test 1 finished
freespace: Test 2: gradually lessen amount of free space and fill the FS
freespace: do 10 steps, lessen free space by 7596218 bytes 7.2 MiB each time
freespace: was free: 78675968 bytes 75.0 MiB, wrote: 88903680 bytes 84.8 MiB, delta: 10227712 bytes 9.8 MiB, wrote 13.0% more than predicted
freespace: was free: 72015872 bytes 68.7 MiB, wrote: 81514496 bytes 77.7 MiB, delta: 9498624 bytes 9.1 MiB, wrote 13.2% more than predicted
freespace: was free: 63938560 bytes 61.0 MiB, wrote: 72589312 bytes 69.2 MiB, delta: 8650752 bytes 8.2 MiB, wrote 13.5% more than predicted
freespace: was free: 56127488 bytes 53.5 MiB, wrote: 63762432 bytes 60.8 MiB, delta: 7634944 bytes 7.3 MiB, wrote 13.6% more than predicted
freespace: was free: 48336896 bytes 46.1 MiB, wrote: 54935552 bytes 52.4 MiB, delta: 6598656 bytes 6.3 MiB, wrote 13.7% more than predicted
freespace: was free: 40587264 bytes 38.7 MiB, wrote: 46157824 bytes 44.0 MiB, delta: 5570560 bytes 5.3 MiB, wrote 13.7% more than predicted
freespace: was free: 32841728 bytes 31.3 MiB, wrote: 37384192 bytes 35.7 MiB, delta: 4542464 bytes 4.3 MiB, wrote 13.8% more than predicted
freespace: was free: 25100288 bytes 23.9 MiB, wrote: 28618752 bytes 27.3 MiB, delta: 3518464 bytes 3.4 MiB, wrote 14.0% more than predicted
freespace: was free: 17342464 bytes 16.5 MiB, wrote: 19841024 bytes 18.9 MiB, delta: 2498560 bytes 2.4 MiB, wrote 14.4% more than predicted
freespace: was free: 9605120 bytes 9.2 MiB, wrote: 11063296 bytes 10.6 MiB, delta: 1458176 bytes 1.4 MiB, wrote 15.2% more than predicted
freespace: Test 2 finished
freespace: Test 3: gradually lessen amount of free space by trashing and fill the FS
freespace: do 10 steps, lessen free space by 7606272 bytes 7.3 MiB each time
freespace: trashing: was free: 83668992 bytes 79.8 MiB, need free: 7606272 bytes 7.3 MiB, files created: 248297, delete 225724 (90.9% of them)
freespace: was free: 70803456 bytes 67.5 MiB, wrote: 82485248 bytes 78.7 MiB, delta: 11681792 bytes 11.1 MiB, wrote 16.5% more than predicted
freespace: trashing: was free: 81080320 bytes 77.3 MiB, need free: 15212544 bytes 14.5 MiB, files created: 248711, delete 202047 (81.2% of them)
freespace: was free: 59867136 bytes 57.1 MiB, wrote: 71897088 bytes 68.6 MiB, delta: 12029952 bytes 11.5 MiB, wrote 20.1% more than predicted
freespace: trashing: was free: 82243584 bytes 78.4 MiB, need free: 22818816 bytes 21.8 MiB, files created: 248866, delete 179817 (72.3% of them)
freespace: was free: 50905088 bytes 48.5 MiB, wrote: 63168512 bytes 60.2 MiB, delta: 12263424 bytes 11.7 MiB, wrote 24.1% more than predicted
freespace: trashing: was free: 83402752 bytes 79.5 MiB, need free: 30425088 bytes 29.0 MiB, files created: 248920, delete 158114 (63.5% of them)
freespace: was free: 42651648 bytes 40.7 MiB, wrote: 55406592 bytes 52.8 MiB, delta: 12754944 bytes 12.2 MiB, wrote 29.9% more than predicted
freespace: trashing: was free: 84402176 bytes 80.5 MiB, need free: 38031360 bytes 36.3 MiB, files created: 248709, delete 136641 (54.9% of them)
freespace: was free: 35233792 bytes 33.6 MiB, wrote: 48250880 bytes 46.0 MiB, delta: 13017088 bytes 12.4 MiB, wrote 36.9% more than predicted
freespace: trashing: was free: 82530304 bytes 78.7 MiB, need free: 45637632 bytes 43.5 MiB, files created: 248778, delete 111208 (44.7% of them)
freespace: was free: 27287552 bytes 26.0 MiB, wrote: 40267776 bytes 38.4 MiB, delta: 12980224 bytes 12.4 MiB, wrote 47.6% more than predicted
freespace: trashing: was free: 85114880 bytes 81.2 MiB, need free: 53243904 bytes 50.8 MiB, files created: 248508, delete 93052 (37.4% of them)
freespace: was free: 22437888 bytes 21.4 MiB, wrote: 35328000 bytes 33.7 MiB, delta: 12890112 bytes 12.3 MiB, wrote 57.4% more than predicted
freespace: trashing: was free: 84103168 bytes 80.2 MiB, need free: 60850176 bytes 58.0 MiB, files created: 248637, delete 68743 (27.6% of them)
freespace: was free: 15536128 bytes 14.8 MiB, wrote: 28319744 bytes 27.0 MiB, delta: 12783616 bytes 12.2 MiB, wrote 82.3% more than predicted
freespace: trashing: was free: 84357120 bytes 80.4 MiB, need free: 68456448 bytes 65.3 MiB, files created: 248567, delete 46852 (18.8% of them)
freespace: was free: 9015296 bytes 8.6 MiB, wrote: 22044672 bytes 21.0 MiB, delta: 13029376 bytes 12.4 MiB, wrote 144.5% more than predicted
freespace: trashing: was free: 84942848 bytes 81.0 MiB, need free: 76062720 bytes 72.5 MiB, files created: 248636, delete 25993 (10.5% of them)
freespace: was free: 6086656 bytes 5.8 MiB, wrote: 8331264 bytes 7.9 MiB, delta: 2244608 bytes 2.1 MiB, wrote 36.9% more than predicted
freespace: Test 3 finished
freespace: finished successfully
After the change:
freespace: Test 1: fill the space we have 3 times
freespace: was free: 94048256 bytes 89.7 MiB, wrote: 96489472 bytes 92.0 MiB, delta: 2441216 bytes 2.3 MiB, wrote 2.6% more than predicted
freespace: was free: 92246016 bytes 88.0 MiB, wrote: 96493568 bytes 92.0 MiB, delta: 4247552 bytes 4.1 MiB, wrote 4.6% more than predicted
freespace: was free: 92254208 bytes 88.0 MiB, wrote: 96489472 bytes 92.0 MiB, delta: 4235264 bytes 4.0 MiB, wrote 4.6% more than predicted
freespace: Test 1 finished
freespace: Test 2: gradually lessen amount of free space and fill the FS
freespace: do 10 steps, lessen free space by 8386001 bytes 8.0 MiB each time
freespace: was free: 86605824 bytes 82.6 MiB, wrote: 88252416 bytes 84.2 MiB, delta: 1646592 bytes 1.6 MiB, wrote 1.9% more than predicted
freespace: was free: 78667776 bytes 75.0 MiB, wrote: 80715776 bytes 77.0 MiB, delta: 2048000 bytes 2.0 MiB, wrote 2.6% more than predicted
freespace: was free: 69615616 bytes 66.4 MiB, wrote: 71630848 bytes 68.3 MiB, delta: 2015232 bytes 1.9 MiB, wrote 2.9% more than predicted
freespace: was free: 61018112 bytes 58.2 MiB, wrote: 62783488 bytes 59.9 MiB, delta: 1765376 bytes 1.7 MiB, wrote 2.9% more than predicted
freespace: was free: 52424704 bytes 50.0 MiB, wrote: 53968896 bytes 51.5 MiB, delta: 1544192 bytes 1.5 MiB, wrote 2.9% more than predicted
freespace: was free: 43880448 bytes 41.8 MiB, wrote: 45199360 bytes 43.1 MiB, delta: 1318912 bytes 1.3 MiB, wrote 3.0% more than predicted
freespace: was free: 35332096 bytes 33.7 MiB, wrote: 36425728 bytes 34.7 MiB, delta: 1093632 bytes 1.0 MiB, wrote 3.1% more than predicted
freespace: was free: 26771456 bytes 25.5 MiB, wrote: 27643904 bytes 26.4 MiB, delta: 872448 bytes 852.0 KiB, wrote 3.3% more than predicted
freespace: was free: 18231296 bytes 17.4 MiB, wrote: 18878464 bytes 18.0 MiB, delta: 647168 bytes 632.0 KiB, wrote 3.5% more than predicted
freespace: was free: 9674752 bytes 9.2 MiB, wrote: 10088448 bytes 9.6 MiB, delta: 413696 bytes 404.0 KiB, wrote 4.3% more than predicted
freespace: Test 2 finished
freespace: Test 3: gradually lessen amount of free space by trashing and fill the FS
freespace: do 10 steps, lessen free space by 8397544 bytes 8.0 MiB each time
freespace: trashing: was free: 92372992 bytes 88.1 MiB, need free: 8397552 bytes 8.0 MiB, files created: 248296, delete 225723 (90.9% of them)
freespace: was free: 71909376 bytes 68.6 MiB, wrote: 82472960 bytes 78.7 MiB, delta: 10563584 bytes 10.1 MiB, wrote 14.7% more than predicted
freespace: trashing: was free: 88989696 bytes 84.9 MiB, need free: 16795096 bytes 16.0 MiB, files created: 248794, delete 201838 (81.1% of them)
freespace: was free: 60354560 bytes 57.6 MiB, wrote: 71782400 bytes 68.5 MiB, delta: 11427840 bytes 10.9 MiB, wrote 18.9% more than predicted
freespace: trashing: was free: 90304512 bytes 86.1 MiB, need free: 25192640 bytes 24.0 MiB, files created: 248733, delete 179342 (72.1% of them)
freespace: was free: 51187712 bytes 48.8 MiB, wrote: 62943232 bytes 60.0 MiB, delta: 11755520 bytes 11.2 MiB, wrote 23.0% more than predicted
freespace: trashing: was free: 91209728 bytes 87.0 MiB, need free: 33590184 bytes 32.0 MiB, files created: 248779, delete 157160 (63.2% of them)
freespace: was free: 42704896 bytes 40.7 MiB, wrote: 55050240 bytes 52.5 MiB, delta: 12345344 bytes 11.8 MiB, wrote 28.9% more than predicted
freespace: trashing: was free: 92700672 bytes 88.4 MiB, need free: 41987728 bytes 40.0 MiB, files created: 248848, delete 136135 (54.7% of them)
freespace: was free: 35250176 bytes 33.6 MiB, wrote: 48115712 bytes 45.9 MiB, delta: 12865536 bytes 12.3 MiB, wrote 36.5% more than predicted
freespace: trashing: was free: 93986816 bytes 89.6 MiB, need free: 50385272 bytes 48.1 MiB, files created: 248723, delete 115385 (46.4% of them)
freespace: was free: 29995008 bytes 28.6 MiB, wrote: 41582592 bytes 39.7 MiB, delta: 11587584 bytes 11.1 MiB, wrote 38.6% more than predicted
freespace: trashing: was free: 91881472 bytes 87.6 MiB, need free: 58782816 bytes 56.1 MiB, files created: 248645, delete 89569 (36.0% of them)
freespace: was free: 22511616 bytes 21.5 MiB, wrote: 34705408 bytes 33.1 MiB, delta: 12193792 bytes 11.6 MiB, wrote 54.2% more than predicted
freespace: trashing: was free: 91774976 bytes 87.5 MiB, need free: 67180360 bytes 64.1 MiB, files created: 248580, delete 66616 (26.8% of them)
freespace: was free: 16908288 bytes 16.1 MiB, wrote: 26898432 bytes 25.7 MiB, delta: 9990144 bytes 9.5 MiB, wrote 59.1% more than predicted
freespace: trashing: was free: 92450816 bytes 88.2 MiB, need free: 75577904 bytes 72.1 MiB, files created: 248654, delete 45381 (18.3% of them)
freespace: was free: 10170368 bytes 9.7 MiB, wrote: 19111936 bytes 18.2 MiB, delta: 8941568 bytes 8.5 MiB, wrote 87.9% more than predicted
freespace: trashing: was free: 93282304 bytes 89.0 MiB, need free: 83975448 bytes 80.1 MiB, files created: 248513, delete 24794 (10.0% of them)
freespace: was free: 3911680 bytes 3.7 MiB, wrote: 7872512 bytes 7.5 MiB, delta: 3960832 bytes 3.8 MiB, wrote 101.3% more than predicted
freespace: Test 3 finished
freespace: finished successfully
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2008-08-25 15:58:19 +00:00
|
|
|
|
* Subtract the LEB reserved for GC, the LEB which is reserved for
|
2008-12-19 17:26:29 +00:00
|
|
|
|
* deletions, minimum LEBs for the index, and assume only one journal
|
|
|
|
|
* head is available.
|
2008-07-14 16:08:37 +00:00
|
|
|
|
*/
|
2008-12-19 17:26:29 +00:00
|
|
|
|
tmp64 = c->main_lebs - 1 - 1 - MIN_INDEX_LEBS - c->jhead_cnt + 1;
|
2008-12-18 12:06:51 +00:00
|
|
|
|
tmp64 *= (long long)c->leb_size - c->leb_overhead;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
tmp64 = ubifs_reported_space(c, tmp64);
|
|
|
|
|
c->block_cnt = tmp64 >> UBIFS_BLOCK_SHIFT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* take_gc_lnum - reserve GC LEB.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
2009-01-23 16:23:03 +00:00
|
|
|
|
* This function ensures that the LEB reserved for garbage collection is marked
|
|
|
|
|
* as "taken" in lprops. We also have to set free space to LEB size and dirty
|
|
|
|
|
* space to zero, because lprops may contain out-of-date information if the
|
|
|
|
|
* file-system was un-mounted before it has been committed. This function
|
|
|
|
|
* returns zero in case of success and a negative error code in case of
|
|
|
|
|
* failure.
|
2008-07-14 16:08:37 +00:00
|
|
|
|
*/
|
|
|
|
|
static int take_gc_lnum(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if (c->gc_lnum == -1) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "no LEB for GC");
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* And we have to tell lprops that this LEB is taken */
|
|
|
|
|
err = ubifs_change_one_lp(c, c->gc_lnum, c->leb_size, 0,
|
|
|
|
|
LPROPS_TAKEN, 0, 0);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* alloc_wbufs - allocate write-buffers.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* This helper function allocates and initializes UBIFS write-buffers. Returns
|
|
|
|
|
* zero in case of success and %-ENOMEM in case of failure.
|
|
|
|
|
*/
|
|
|
|
|
static int alloc_wbufs(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
int i, err;
|
|
|
|
|
|
2014-06-23 16:41:23 +00:00
|
|
|
|
c->jheads = kcalloc(c->jhead_cnt, sizeof(struct ubifs_jhead),
|
|
|
|
|
GFP_KERNEL);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (!c->jheads)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
/* Initialize journal heads */
|
|
|
|
|
for (i = 0; i < c->jhead_cnt; i++) {
|
|
|
|
|
INIT_LIST_HEAD(&c->jheads[i].buds_list);
|
|
|
|
|
err = ubifs_wbuf_init(c, &c->jheads[i].wbuf);
|
|
|
|
|
if (err)
|
2022-10-22 11:52:11 +00:00
|
|
|
|
goto out_wbuf;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
c->jheads[i].wbuf.sync_callback = &bud_wbuf_callback;
|
|
|
|
|
c->jheads[i].wbuf.jhead = i;
|
2011-05-26 05:26:05 +00:00
|
|
|
|
c->jheads[i].grouped = 1;
|
ubifs: Add authentication nodes to journal
Nodes that are written to flash can only be authenticated through the
index after the next commit. When a journal replay is necessary the
nodes are not yet referenced by the index and thus can't be
authenticated.
This patch overcomes this situation by creating a hash over all nodes
beginning from the commit start node over the reference node(s) and
the buds themselves. From
time to time we insert authentication nodes. Authentication nodes
contain a HMAC from the current hash state, so that they can be
used to authenticate a journal replay up to the point where the
authentication node is. The hash is continued afterwards
so that theoretically we would only have to check the HMAC of
the last authentication node we find.
Overall we get this picture:
,,,,,,,,
,......,...........................................
,. CS , hash1.----. hash2.----.
,. | , . |hmac . |hmac
,. v , . v . v
,.REF#0,-> bud -> bud -> bud.-> auth -> bud -> bud.-> auth ...
,..|...,...........................................
, | ,
, | ,,,,,,,,,,,,,,,
. | hash3,----.
, | , |hmac
, v , v
, REF#1 -> bud -> bud,-> auth ...
,,,|,,,,,,,,,,,,,,,,,,
v
REF#2 -> ...
|
V
...
Note how hash3 covers CS, REF#0 and REF#1 so that it is not possible to
exchange or skip any reference nodes. Unlike the picture suggests the
auth nodes themselves are not hashed.
With this it is possible for an offline attacker to cut each journal
head or to drop the last reference node(s), but not to skip any journal
heads or to reorder any operations.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Richard Weinberger <richard@nod.at>
2018-09-07 12:36:36 +00:00
|
|
|
|
c->jheads[i].log_hash = ubifs_hash_get_desc(c);
|
2020-11-15 08:23:43 +00:00
|
|
|
|
if (IS_ERR(c->jheads[i].log_hash)) {
|
|
|
|
|
err = PTR_ERR(c->jheads[i].log_hash);
|
2022-10-22 11:52:11 +00:00
|
|
|
|
goto out_log_hash;
|
2020-11-15 08:23:43 +00:00
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2012-05-14 16:49:35 +00:00
|
|
|
|
* Garbage Collector head does not need to be synchronized by timer.
|
|
|
|
|
* Also GC head nodes are not grouped.
|
2008-07-14 16:08:37 +00:00
|
|
|
|
*/
|
2009-06-23 09:30:43 +00:00
|
|
|
|
c->jheads[GCHD].wbuf.no_timer = 1;
|
2011-05-26 05:26:05 +00:00
|
|
|
|
c->jheads[GCHD].grouped = 0;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
ubifs: Add authentication nodes to journal
Nodes that are written to flash can only be authenticated through the
index after the next commit. When a journal replay is necessary the
nodes are not yet referenced by the index and thus can't be
authenticated.
This patch overcomes this situation by creating a hash over all nodes
beginning from the commit start node over the reference node(s) and
the buds themselves. From
time to time we insert authentication nodes. Authentication nodes
contain a HMAC from the current hash state, so that they can be
used to authenticate a journal replay up to the point where the
authentication node is. The hash is continued afterwards
so that theoretically we would only have to check the HMAC of
the last authentication node we find.
Overall we get this picture:
,,,,,,,,
,......,...........................................
,. CS , hash1.----. hash2.----.
,. | , . |hmac . |hmac
,. v , . v . v
,.REF#0,-> bud -> bud -> bud.-> auth -> bud -> bud.-> auth ...
,..|...,...........................................
, | ,
, | ,,,,,,,,,,,,,,,
. | hash3,----.
, | , |hmac
, v , v
, REF#1 -> bud -> bud,-> auth ...
,,,|,,,,,,,,,,,,,,,,,,
v
REF#2 -> ...
|
V
...
Note how hash3 covers CS, REF#0 and REF#1 so that it is not possible to
exchange or skip any reference nodes. Unlike the picture suggests the
auth nodes themselves are not hashed.
With this it is possible for an offline attacker to cut each journal
head or to drop the last reference node(s), but not to skip any journal
heads or to reorder any operations.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Richard Weinberger <richard@nod.at>
2018-09-07 12:36:36 +00:00
|
|
|
|
|
2022-10-22 11:52:11 +00:00
|
|
|
|
out_log_hash:
|
|
|
|
|
kfree(c->jheads[i].wbuf.buf);
|
|
|
|
|
kfree(c->jheads[i].wbuf.inodes);
|
|
|
|
|
|
|
|
|
|
out_wbuf:
|
|
|
|
|
while (i--) {
|
|
|
|
|
kfree(c->jheads[i].wbuf.buf);
|
|
|
|
|
kfree(c->jheads[i].wbuf.inodes);
|
ubifs: Add authentication nodes to journal
Nodes that are written to flash can only be authenticated through the
index after the next commit. When a journal replay is necessary the
nodes are not yet referenced by the index and thus can't be
authenticated.
This patch overcomes this situation by creating a hash over all nodes
beginning from the commit start node over the reference node(s) and
the buds themselves. From
time to time we insert authentication nodes. Authentication nodes
contain a HMAC from the current hash state, so that they can be
used to authenticate a journal replay up to the point where the
authentication node is. The hash is continued afterwards
so that theoretically we would only have to check the HMAC of
the last authentication node we find.
Overall we get this picture:
,,,,,,,,
,......,...........................................
,. CS , hash1.----. hash2.----.
,. | , . |hmac . |hmac
,. v , . v . v
,.REF#0,-> bud -> bud -> bud.-> auth -> bud -> bud.-> auth ...
,..|...,...........................................
, | ,
, | ,,,,,,,,,,,,,,,
. | hash3,----.
, | , |hmac
, v , v
, REF#1 -> bud -> bud,-> auth ...
,,,|,,,,,,,,,,,,,,,,,,
v
REF#2 -> ...
|
V
...
Note how hash3 covers CS, REF#0 and REF#1 so that it is not possible to
exchange or skip any reference nodes. Unlike the picture suggests the
auth nodes themselves are not hashed.
With this it is possible for an offline attacker to cut each journal
head or to drop the last reference node(s), but not to skip any journal
heads or to reorder any operations.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Richard Weinberger <richard@nod.at>
2018-09-07 12:36:36 +00:00
|
|
|
|
kfree(c->jheads[i].log_hash);
|
2022-10-22 11:52:11 +00:00
|
|
|
|
}
|
|
|
|
|
kfree(c->jheads);
|
|
|
|
|
c->jheads = NULL;
|
ubifs: Add authentication nodes to journal
Nodes that are written to flash can only be authenticated through the
index after the next commit. When a journal replay is necessary the
nodes are not yet referenced by the index and thus can't be
authenticated.
This patch overcomes this situation by creating a hash over all nodes
beginning from the commit start node over the reference node(s) and
the buds themselves. From
time to time we insert authentication nodes. Authentication nodes
contain a HMAC from the current hash state, so that they can be
used to authenticate a journal replay up to the point where the
authentication node is. The hash is continued afterwards
so that theoretically we would only have to check the HMAC of
the last authentication node we find.
Overall we get this picture:
,,,,,,,,
,......,...........................................
,. CS , hash1.----. hash2.----.
,. | , . |hmac . |hmac
,. v , . v . v
,.REF#0,-> bud -> bud -> bud.-> auth -> bud -> bud.-> auth ...
,..|...,...........................................
, | ,
, | ,,,,,,,,,,,,,,,
. | hash3,----.
, | , |hmac
, v , v
, REF#1 -> bud -> bud,-> auth ...
,,,|,,,,,,,,,,,,,,,,,,
v
REF#2 -> ...
|
V
...
Note how hash3 covers CS, REF#0 and REF#1 so that it is not possible to
exchange or skip any reference nodes. Unlike the picture suggests the
auth nodes themselves are not hashed.
With this it is possible for an offline attacker to cut each journal
head or to drop the last reference node(s), but not to skip any journal
heads or to reorder any operations.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Richard Weinberger <richard@nod.at>
2018-09-07 12:36:36 +00:00
|
|
|
|
|
|
|
|
|
return err;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* free_wbufs - free write-buffers.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*/
|
|
|
|
|
static void free_wbufs(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (c->jheads) {
|
|
|
|
|
for (i = 0; i < c->jhead_cnt; i++) {
|
|
|
|
|
kfree(c->jheads[i].wbuf.buf);
|
|
|
|
|
kfree(c->jheads[i].wbuf.inodes);
|
ubifs: Add authentication nodes to journal
Nodes that are written to flash can only be authenticated through the
index after the next commit. When a journal replay is necessary the
nodes are not yet referenced by the index and thus can't be
authenticated.
This patch overcomes this situation by creating a hash over all nodes
beginning from the commit start node over the reference node(s) and
the buds themselves. From
time to time we insert authentication nodes. Authentication nodes
contain a HMAC from the current hash state, so that they can be
used to authenticate a journal replay up to the point where the
authentication node is. The hash is continued afterwards
so that theoretically we would only have to check the HMAC of
the last authentication node we find.
Overall we get this picture:
,,,,,,,,
,......,...........................................
,. CS , hash1.----. hash2.----.
,. | , . |hmac . |hmac
,. v , . v . v
,.REF#0,-> bud -> bud -> bud.-> auth -> bud -> bud.-> auth ...
,..|...,...........................................
, | ,
, | ,,,,,,,,,,,,,,,
. | hash3,----.
, | , |hmac
, v , v
, REF#1 -> bud -> bud,-> auth ...
,,,|,,,,,,,,,,,,,,,,,,
v
REF#2 -> ...
|
V
...
Note how hash3 covers CS, REF#0 and REF#1 so that it is not possible to
exchange or skip any reference nodes. Unlike the picture suggests the
auth nodes themselves are not hashed.
With this it is possible for an offline attacker to cut each journal
head or to drop the last reference node(s), but not to skip any journal
heads or to reorder any operations.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Richard Weinberger <richard@nod.at>
2018-09-07 12:36:36 +00:00
|
|
|
|
kfree(c->jheads[i].log_hash);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
kfree(c->jheads);
|
|
|
|
|
c->jheads = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* free_orphans - free orphans.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*/
|
|
|
|
|
static void free_orphans(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
struct ubifs_orphan *orph;
|
|
|
|
|
|
|
|
|
|
while (c->orph_dnext) {
|
|
|
|
|
orph = c->orph_dnext;
|
|
|
|
|
c->orph_dnext = orph->dnext;
|
|
|
|
|
list_del(&orph->list);
|
|
|
|
|
kfree(orph);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (!list_empty(&c->orph_list)) {
|
|
|
|
|
orph = list_entry(c->orph_list.next, struct ubifs_orphan, list);
|
|
|
|
|
list_del(&orph->list);
|
|
|
|
|
kfree(orph);
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "orphan list not empty at unmount");
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vfree(c->orph_buf);
|
|
|
|
|
c->orph_buf = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* free_buds - free per-bud objects.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*/
|
|
|
|
|
static void free_buds(struct ubifs_info *c)
|
|
|
|
|
{
|
2014-01-23 23:56:08 +00:00
|
|
|
|
struct ubifs_bud *bud, *n;
|
|
|
|
|
|
2023-07-18 12:41:45 +00:00
|
|
|
|
rbtree_postorder_for_each_entry_safe(bud, n, &c->buds, rb) {
|
|
|
|
|
kfree(bud->log_hash);
|
2014-01-23 23:56:08 +00:00
|
|
|
|
kfree(bud);
|
2023-07-18 12:41:45 +00:00
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* check_volume_empty - check if the UBI volume is empty.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* This function checks if the UBIFS volume is empty by looking if its LEBs are
|
|
|
|
|
* mapped or not. The result of checking is stored in the @c->empty variable.
|
|
|
|
|
* Returns zero in case of success and a negative error code in case of
|
|
|
|
|
* failure.
|
|
|
|
|
*/
|
|
|
|
|
static int check_volume_empty(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
int lnum, err;
|
|
|
|
|
|
|
|
|
|
c->empty = 1;
|
|
|
|
|
for (lnum = 0; lnum < c->leb_cnt; lnum++) {
|
2011-06-03 11:22:05 +00:00
|
|
|
|
err = ubifs_is_mapped(c, lnum);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (unlikely(err < 0))
|
|
|
|
|
return err;
|
|
|
|
|
if (err == 1) {
|
|
|
|
|
c->empty = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cond_resched();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* UBIFS mount options.
|
|
|
|
|
*
|
|
|
|
|
* Opt_fast_unmount: do not run a journal commit before un-mounting
|
|
|
|
|
* Opt_norm_unmount: run a journal commit before un-mounting
|
2008-09-02 13:29:46 +00:00
|
|
|
|
* Opt_bulk_read: enable bulk-reads
|
|
|
|
|
* Opt_no_bulk_read: disable bulk-reads
|
2008-09-04 13:26:00 +00:00
|
|
|
|
* Opt_chk_data_crc: check CRCs when reading data nodes
|
|
|
|
|
* Opt_no_chk_data_crc: do not check CRCs when reading data nodes
|
2008-11-01 12:57:49 +00:00
|
|
|
|
* Opt_override_compr: override default compressor
|
2018-07-12 11:01:59 +00:00
|
|
|
|
* Opt_assert: set ubifs_assert() action
|
2018-09-07 12:36:45 +00:00
|
|
|
|
* Opt_auth_key: The key name used for authentication
|
|
|
|
|
* Opt_auth_hash_name: The hash type used for authentication
|
2008-07-14 16:08:37 +00:00
|
|
|
|
* Opt_err: just end of array marker
|
|
|
|
|
*/
|
|
|
|
|
enum {
|
|
|
|
|
Opt_fast_unmount,
|
|
|
|
|
Opt_norm_unmount,
|
2008-09-02 13:29:46 +00:00
|
|
|
|
Opt_bulk_read,
|
|
|
|
|
Opt_no_bulk_read,
|
2008-09-04 13:26:00 +00:00
|
|
|
|
Opt_chk_data_crc,
|
|
|
|
|
Opt_no_chk_data_crc,
|
2008-11-01 12:57:49 +00:00
|
|
|
|
Opt_override_compr,
|
2018-07-12 11:01:59 +00:00
|
|
|
|
Opt_assert,
|
2018-09-07 12:36:45 +00:00
|
|
|
|
Opt_auth_key,
|
|
|
|
|
Opt_auth_hash_name,
|
ubifs: allow userspace to map mounts to volumes
There currently appears to be no way for userspace to find out the
underlying volume number for a mounted ubifs file system, since ubifs
uses anonymous block devices. The volume name is present in
/proc/mounts but UBI volumes can be renamed after the volume has been
mounted.
To remedy this, show the UBI number and UBI volume number as part of the
options visible under /proc/mounts.
Also, accept and ignore the ubi= vol= options if they are used mounting
(patch from Richard Weinberger).
# mount -t ubifs ubi:baz x
# mount
ubi:baz on /root/x type ubifs (rw,relatime,ubi=0,vol=2)
# ubirename /dev/ubi0 baz bazz
# mount
ubi:baz on /root/x type ubifs (rw,relatime,ubi=0,vol=2)
# ubinfo -d 0 -n 2
Volume ID: 2 (on ubi0)
Type: dynamic
Alignment: 1
Size: 67 LEBs (1063424 bytes, 1.0 MiB)
State: OK
Name: bazz
Character device major/minor: 254:3
Signed-off-by: Rabin Vincent <rabinv@axis.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2017-05-31 09:40:27 +00:00
|
|
|
|
Opt_ignore,
|
2008-07-14 16:08:37 +00:00
|
|
|
|
};
|
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
static const struct constant_table ubifs_param_compr[] = {
|
|
|
|
|
{ "none", UBIFS_COMPR_NONE },
|
|
|
|
|
{ "lzo", UBIFS_COMPR_LZO },
|
|
|
|
|
{ "zlib", UBIFS_COMPR_ZLIB },
|
|
|
|
|
{ "zstd", UBIFS_COMPR_ZSTD },
|
|
|
|
|
{}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
};
|
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
static const struct constant_table ubifs_param_assert[] = {
|
|
|
|
|
{ "report", ASSACT_REPORT },
|
|
|
|
|
{ "read-only", ASSACT_RO },
|
|
|
|
|
{ "panic", ASSACT_PANIC },
|
|
|
|
|
{}
|
|
|
|
|
};
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
static const struct fs_parameter_spec ubifs_fs_param_spec[] = {
|
|
|
|
|
fsparam_flag ("fast_unmount", Opt_fast_unmount),
|
|
|
|
|
fsparam_flag ("norm_unmount", Opt_norm_unmount),
|
|
|
|
|
fsparam_flag ("bulk_read", Opt_bulk_read),
|
|
|
|
|
fsparam_flag ("no_bulk_read", Opt_no_bulk_read),
|
|
|
|
|
fsparam_flag ("chk_data_crc", Opt_chk_data_crc),
|
|
|
|
|
fsparam_flag ("no_chk_data_crc", Opt_no_chk_data_crc),
|
|
|
|
|
fsparam_enum ("compr", Opt_override_compr, ubifs_param_compr),
|
|
|
|
|
fsparam_enum ("assert", Opt_assert, ubifs_param_assert),
|
|
|
|
|
fsparam_string ("auth_key", Opt_auth_key),
|
|
|
|
|
fsparam_string ("auth_hash_name", Opt_auth_hash_name),
|
|
|
|
|
fsparam_string ("ubi", Opt_ignore),
|
|
|
|
|
fsparam_string ("vol", Opt_ignore),
|
|
|
|
|
{}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ubifs_fs_context {
|
|
|
|
|
struct ubifs_mount_opts mount_opts;
|
|
|
|
|
char *auth_key_name;
|
|
|
|
|
char *auth_hash_name;
|
|
|
|
|
unsigned int no_chk_data_crc:1;
|
|
|
|
|
unsigned int bulk_read:1;
|
|
|
|
|
unsigned int default_compr:2;
|
|
|
|
|
unsigned int assert_action:2;
|
|
|
|
|
};
|
2009-05-29 09:34:52 +00:00
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/**
|
2024-10-02 16:58:34 +00:00
|
|
|
|
* ubifs_parse_param - parse a parameter.
|
|
|
|
|
* @fc: the filesystem context
|
|
|
|
|
* @param: the parameter to parse
|
2008-07-14 16:08:37 +00:00
|
|
|
|
*
|
|
|
|
|
* This function parses UBIFS mount options and returns zero in case success
|
|
|
|
|
* and a negative error code in case of failure.
|
|
|
|
|
*/
|
2024-10-02 16:58:34 +00:00
|
|
|
|
static int ubifs_parse_param(struct fs_context *fc, struct fs_parameter *param)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
2024-10-02 16:58:34 +00:00
|
|
|
|
struct ubifs_fs_context *ctx = fc->fs_private;
|
|
|
|
|
struct fs_parse_result result;
|
|
|
|
|
bool is_remount = (fc->purpose & FS_CONTEXT_FOR_RECONFIGURE);
|
|
|
|
|
int opt;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
opt = fs_parse(fc, ubifs_fs_param_spec, param, &result);
|
|
|
|
|
if (opt < 0)
|
|
|
|
|
return opt;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
switch (opt) {
|
2009-01-29 14:34:30 +00:00
|
|
|
|
/*
|
|
|
|
|
* %Opt_fast_unmount and %Opt_norm_unmount options are ignored.
|
2009-06-23 17:30:32 +00:00
|
|
|
|
* We accept them in order to be backward-compatible. But this
|
2009-01-29 14:34:30 +00:00
|
|
|
|
* should be removed at some point.
|
|
|
|
|
*/
|
2024-10-02 16:58:34 +00:00
|
|
|
|
case Opt_fast_unmount:
|
|
|
|
|
ctx->mount_opts.unmount_mode = 2;
|
|
|
|
|
break;
|
|
|
|
|
case Opt_norm_unmount:
|
|
|
|
|
ctx->mount_opts.unmount_mode = 1;
|
|
|
|
|
break;
|
|
|
|
|
case Opt_bulk_read:
|
|
|
|
|
ctx->mount_opts.bulk_read = 2;
|
|
|
|
|
ctx->bulk_read = 1;
|
|
|
|
|
break;
|
|
|
|
|
case Opt_no_bulk_read:
|
|
|
|
|
ctx->mount_opts.bulk_read = 1;
|
|
|
|
|
ctx->bulk_read = 0;
|
|
|
|
|
break;
|
|
|
|
|
case Opt_chk_data_crc:
|
|
|
|
|
ctx->mount_opts.chk_data_crc = 2;
|
|
|
|
|
ctx->no_chk_data_crc = 0;
|
|
|
|
|
break;
|
|
|
|
|
case Opt_no_chk_data_crc:
|
|
|
|
|
ctx->mount_opts.chk_data_crc = 1;
|
|
|
|
|
ctx->no_chk_data_crc = 1;
|
|
|
|
|
break;
|
|
|
|
|
case Opt_override_compr:
|
|
|
|
|
ctx->mount_opts.compr_type = result.uint_32;
|
|
|
|
|
ctx->mount_opts.override_compr = 1;
|
|
|
|
|
ctx->default_compr = ctx->mount_opts.compr_type;
|
|
|
|
|
break;
|
|
|
|
|
case Opt_assert:
|
|
|
|
|
ctx->assert_action = result.uint_32;
|
|
|
|
|
break;
|
|
|
|
|
case Opt_auth_key:
|
|
|
|
|
if (!is_remount) {
|
|
|
|
|
kfree(ctx->auth_key_name);
|
|
|
|
|
ctx->auth_key_name = param->string;
|
|
|
|
|
param->string = NULL;
|
2009-05-29 09:34:52 +00:00
|
|
|
|
}
|
2024-10-02 16:58:34 +00:00
|
|
|
|
break;
|
|
|
|
|
case Opt_auth_hash_name:
|
|
|
|
|
if (!is_remount) {
|
|
|
|
|
kfree(ctx->auth_hash_name);
|
|
|
|
|
ctx->auth_hash_name = param->string;
|
|
|
|
|
param->string = NULL;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
2024-10-02 16:58:34 +00:00
|
|
|
|
break;
|
|
|
|
|
case Opt_ignore:
|
|
|
|
|
break;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-29 12:45:29 +00:00
|
|
|
|
/*
|
|
|
|
|
* ubifs_release_options - release mount parameters which have been dumped.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*/
|
|
|
|
|
static void ubifs_release_options(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
kfree(c->auth_key_name);
|
|
|
|
|
c->auth_key_name = NULL;
|
|
|
|
|
kfree(c->auth_hash_name);
|
|
|
|
|
c->auth_hash_name = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* destroy_journal - destroy journal data structures.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* This function destroys journal data structures including those that may have
|
|
|
|
|
* been created by recovery functions.
|
|
|
|
|
*/
|
|
|
|
|
static void destroy_journal(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
while (!list_empty(&c->unclean_leb_list)) {
|
|
|
|
|
struct ubifs_unclean_leb *ucleb;
|
|
|
|
|
|
|
|
|
|
ucleb = list_entry(c->unclean_leb_list.next,
|
|
|
|
|
struct ubifs_unclean_leb, list);
|
|
|
|
|
list_del(&ucleb->list);
|
|
|
|
|
kfree(ucleb);
|
|
|
|
|
}
|
|
|
|
|
while (!list_empty(&c->old_buds)) {
|
|
|
|
|
struct ubifs_bud *bud;
|
|
|
|
|
|
|
|
|
|
bud = list_entry(c->old_buds.next, struct ubifs_bud, list);
|
|
|
|
|
list_del(&bud->list);
|
2023-07-18 12:41:45 +00:00
|
|
|
|
kfree(bud->log_hash);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
kfree(bud);
|
|
|
|
|
}
|
|
|
|
|
ubifs_destroy_idx_gc(c);
|
|
|
|
|
ubifs_destroy_size_tree(c);
|
|
|
|
|
ubifs_tnc_close(c);
|
|
|
|
|
free_buds(c);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-19 09:53:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* bu_init - initialize bulk-read information.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*/
|
|
|
|
|
static void bu_init(struct ubifs_info *c)
|
|
|
|
|
{
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_assert(c, c->bulk_read == 1);
|
2008-11-19 09:53:15 +00:00
|
|
|
|
|
|
|
|
|
if (c->bu.buf)
|
|
|
|
|
return; /* Already initialized */
|
|
|
|
|
|
|
|
|
|
again:
|
|
|
|
|
c->bu.buf = kmalloc(c->max_bu_buf_len, GFP_KERNEL | __GFP_NOWARN);
|
|
|
|
|
if (!c->bu.buf) {
|
|
|
|
|
if (c->max_bu_buf_len > UBIFS_KMALLOC_OK) {
|
|
|
|
|
c->max_bu_buf_len = UBIFS_KMALLOC_OK;
|
|
|
|
|
goto again;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Just disable bulk-read */
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_warn(c, "cannot allocate %d bytes of memory for bulk-read, disabling it",
|
2012-08-27 10:34:09 +00:00
|
|
|
|
c->max_bu_buf_len);
|
2008-11-19 09:53:15 +00:00
|
|
|
|
c->mount_opts.bulk_read = 1;
|
|
|
|
|
c->bulk_read = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-30 14:23:34 +00:00
|
|
|
|
/**
|
|
|
|
|
* check_free_space - check if there is enough free space to mount.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* This function makes sure UBIFS has enough free space to be mounted in
|
|
|
|
|
* read/write mode. UBIFS must always have some free space to allow deletions.
|
|
|
|
|
*/
|
|
|
|
|
static int check_free_space(struct ubifs_info *c)
|
|
|
|
|
{
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_assert(c, c->dark_wm > 0);
|
2008-12-30 14:23:34 +00:00
|
|
|
|
if (c->lst.total_free + c->lst.total_dirty < c->dark_wm) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "insufficient free space to mount in R/W mode");
|
2012-05-16 16:15:56 +00:00
|
|
|
|
ubifs_dump_budg(c, &c->bi);
|
|
|
|
|
ubifs_dump_lprops(c);
|
2009-01-29 14:22:54 +00:00
|
|
|
|
return -ENOSPC;
|
2008-12-30 14:23:34 +00:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* mount_ubifs - mount UBIFS file-system.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* This function mounts UBIFS file system. Returns zero in case of success and
|
|
|
|
|
* a negative error code in case of failure.
|
|
|
|
|
*/
|
|
|
|
|
static int mount_ubifs(struct ubifs_info *c)
|
|
|
|
|
{
|
2010-09-19 15:34:26 +00:00
|
|
|
|
int err;
|
2012-08-27 13:56:58 +00:00
|
|
|
|
long long x, y;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
size_t sz;
|
|
|
|
|
|
2017-07-17 07:45:34 +00:00
|
|
|
|
c->ro_mount = !!sb_rdonly(c->vfs_sb);
|
2017-11-27 21:05:09 +00:00
|
|
|
|
/* Suppress error messages while probing if SB_SILENT is set */
|
|
|
|
|
c->probing = !!(c->vfs_sb->s_flags & SB_SILENT);
|
2014-06-02 13:51:10 +00:00
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = init_constants_early(c);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
2008-10-17 10:31:39 +00:00
|
|
|
|
err = ubifs_debugging_init(c);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2021-10-10 04:22:39 +00:00
|
|
|
|
err = ubifs_sysfs_register(c);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_debugging;
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = check_volume_empty(c);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_free;
|
|
|
|
|
|
2010-09-19 15:34:26 +00:00
|
|
|
|
if (c->empty && (c->ro_mount || c->ro_media)) {
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* This UBI volume is empty, and read-only, or the file system
|
|
|
|
|
* is mounted read-only - we cannot format it.
|
|
|
|
|
*/
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "can't format empty UBI volume: read-only %s",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->ro_media ? "UBI volume" : "mount");
|
|
|
|
|
err = -EROFS;
|
|
|
|
|
goto out_free;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-19 15:34:26 +00:00
|
|
|
|
if (c->ro_media && !c->ro_mount) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "cannot mount read-write - read-only media");
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = -EROFS;
|
|
|
|
|
goto out_free;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The requirement for the buffer is that it should fit indexing B-tree
|
|
|
|
|
* height amount of integers. We assume the height if the TNC tree will
|
|
|
|
|
* never exceed 64.
|
|
|
|
|
*/
|
|
|
|
|
err = -ENOMEM;
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 20:55:00 +00:00
|
|
|
|
c->bottom_up_buf = kmalloc_array(BOTTOM_UP_HEIGHT, sizeof(int),
|
|
|
|
|
GFP_KERNEL);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (!c->bottom_up_buf)
|
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
|
|
c->sbuf = vmalloc(c->leb_size);
|
|
|
|
|
if (!c->sbuf)
|
|
|
|
|
goto out_free;
|
|
|
|
|
|
2010-09-19 15:34:26 +00:00
|
|
|
|
if (!c->ro_mount) {
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->ileb_buf = vmalloc(c->leb_size);
|
|
|
|
|
if (!c->ileb_buf)
|
|
|
|
|
goto out_free;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-19 09:53:15 +00:00
|
|
|
|
if (c->bulk_read == 1)
|
|
|
|
|
bu_init(c);
|
|
|
|
|
|
2011-03-04 22:55:02 +00:00
|
|
|
|
if (!c->ro_mount) {
|
2016-09-29 20:20:19 +00:00
|
|
|
|
c->write_reserve_buf = kmalloc(COMPRESSED_DATA_NODE_BUF_SZ + \
|
|
|
|
|
UBIFS_CIPHER_BLOCK_SIZE,
|
2011-03-04 22:55:02 +00:00
|
|
|
|
GFP_KERNEL);
|
|
|
|
|
if (!c->write_reserve_buf)
|
|
|
|
|
goto out_free;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-17 20:27:56 +00:00
|
|
|
|
c->mounting = 1;
|
2008-09-04 13:26:00 +00:00
|
|
|
|
|
2018-09-07 12:36:45 +00:00
|
|
|
|
if (c->auth_key_name) {
|
|
|
|
|
if (IS_ENABLED(CONFIG_UBIFS_FS_AUTHENTICATION)) {
|
|
|
|
|
err = ubifs_init_authentication(c);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_free;
|
|
|
|
|
} else {
|
|
|
|
|
ubifs_err(c, "auth_key_name, but UBIFS is built without"
|
|
|
|
|
" authentication support");
|
|
|
|
|
err = -EINVAL;
|
|
|
|
|
goto out_free;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = ubifs_read_superblock(c);
|
|
|
|
|
if (err)
|
2020-09-29 12:45:31 +00:00
|
|
|
|
goto out_auth;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2014-06-02 13:51:10 +00:00
|
|
|
|
c->probing = 0;
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
2008-11-01 12:57:49 +00:00
|
|
|
|
* Make sure the compressor which is set as default in the superblock
|
2008-12-30 14:23:34 +00:00
|
|
|
|
* or overridden by mount options is actually compiled in.
|
2008-07-14 16:08:37 +00:00
|
|
|
|
*/
|
2018-07-12 11:01:57 +00:00
|
|
|
|
if (!ubifs_compr_present(c, c->default_compr)) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "'compressor \"%s\" is not compiled in",
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_compr_name(c, c->default_compr));
|
2009-05-25 06:49:10 +00:00
|
|
|
|
err = -ENOTSUPP;
|
2020-09-29 12:45:31 +00:00
|
|
|
|
goto out_auth;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-12-27 17:18:00 +00:00
|
|
|
|
err = init_constants_sb(c);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (err)
|
2020-09-29 12:45:31 +00:00
|
|
|
|
goto out_auth;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2018-08-06 02:49:06 +00:00
|
|
|
|
sz = ALIGN(c->max_idx_node_sz, c->min_io_size) * 2;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->cbuf = kmalloc(sz, GFP_NOFS);
|
|
|
|
|
if (!c->cbuf) {
|
|
|
|
|
err = -ENOMEM;
|
2020-09-29 12:45:31 +00:00
|
|
|
|
goto out_auth;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
UBIFS: do not free write-buffers when in R/O mode
Currently UBIFS has a small optimization - it frees write-buffers when it is
re-mounted from R/W mode to R/O mode. Of course, when it is mounted R/O, it
does not allocate write-buffers as well.
This optimization is nice but it leads to subtle problems and complications
in recovery, which I can reproduce using the integck test. The symptoms are
that after a power cut the file-system cannot be mounted if we first mount
it R/O, and then re-mount R/W - 'ubifs_rcvry_gc_commit()' prints:
UBIFS error (pid 34456): could not find an empty LEB
Analysis of the problem.
When mounting R/W, the reply process sets journal heads to buds [1], but
when mounting R/O - it does not do this, because the write-buffers are not
allocated. So 'ubifs_rcvry_gc_commit()' works completely differently for the
same file-system but for the following 2 cases:
1. mounting R/W after a power cut and recover
2. mounting R/O after a power cut, re-mounting R/W and run deferred recovery
In the former case, we have journal heads seeked to the a bud, in the latter
case, they are non-seeked (wbuf->lnum == -1). So in the latter case we do not
try to recover the GC LEB by garbage-collecting to the GC head, but we just
try to find an empty LEB, and there may be no empty LEBs, so we just fail.
On the other hand, in the former case (mount R/W), we are able to make a GC LEB
(@c->gc_lnum) by garbage-collecting.
Thus, let's remove this small nice optimization and always allocate
write-buffers. This should not make too big difference - we have only 3
of them, each of max. write unit size, which is usually 2KiB. So this is
about 6KiB of RAM for the typical case, and only when mounted R/O.
[1]: Note, currently the replay process is setting (seeking) the journal heads
to _some_ buds, not necessarily to the buds which had been the journal heads
before the power cut happened. This will be fixed separately.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Cc: stable@kernel.org
2011-04-25 15:17:09 +00:00
|
|
|
|
err = alloc_wbufs(c);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_cbuf;
|
|
|
|
|
|
2008-09-09 09:17:29 +00:00
|
|
|
|
sprintf(c->bgt_name, BGT_NAME_PATTERN, c->vi.ubi_num, c->vi.vol_id);
|
2010-09-19 15:34:26 +00:00
|
|
|
|
if (!c->ro_mount) {
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/* Create background thread */
|
2021-10-21 08:43:43 +00:00
|
|
|
|
c->bgt = kthread_run(ubifs_bg_thread, c, "%s", c->bgt_name);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (IS_ERR(c->bgt)) {
|
|
|
|
|
err = PTR_ERR(c->bgt);
|
|
|
|
|
c->bgt = NULL;
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "cannot spawn \"%s\", error %d",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->bgt_name, err);
|
|
|
|
|
goto out_wbufs;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = ubifs_read_master(c);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_master;
|
|
|
|
|
|
2011-05-30 18:56:16 +00:00
|
|
|
|
init_constants_master(c);
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if ((c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY)) != 0) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_msg(c, "recovery needed");
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->need_recovery = 1;
|
2011-05-30 18:56:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c->need_recovery && !c->ro_mount) {
|
|
|
|
|
err = ubifs_recover_inl_heads(c, c->sbuf);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_master;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = ubifs_lpt_init(c, 1, !c->ro_mount);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_master;
|
|
|
|
|
|
2011-05-30 18:56:16 +00:00
|
|
|
|
if (!c->ro_mount && c->space_fixup) {
|
|
|
|
|
err = ubifs_fixup_free_space(c);
|
|
|
|
|
if (err)
|
2012-05-18 11:32:37 +00:00
|
|
|
|
goto out_lpt;
|
2011-05-30 18:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-04 10:46:16 +00:00
|
|
|
|
if (!c->ro_mount && !c->need_recovery) {
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* Set the "dirty" flag so that if we reboot uncleanly we
|
|
|
|
|
* will notice this immediately on the next mount.
|
|
|
|
|
*/
|
|
|
|
|
c->mst_node->flags |= cpu_to_le32(UBIFS_MST_DIRTY);
|
|
|
|
|
err = ubifs_write_master(c);
|
|
|
|
|
if (err)
|
2011-05-30 18:56:15 +00:00
|
|
|
|
goto out_lpt;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 08:33:22 +00:00
|
|
|
|
/*
|
|
|
|
|
* Handle offline signed images: Now that the master node is
|
|
|
|
|
* written and its validation no longer depends on the hash
|
|
|
|
|
* in the superblock, we can update the offline signed
|
|
|
|
|
* superblock with a HMAC version,
|
|
|
|
|
*/
|
|
|
|
|
if (ubifs_authenticated(c) && ubifs_hmac_zero(c, c->sup_node->hmac)) {
|
|
|
|
|
err = ubifs_hmac_wkm(c, c->sup_node->hmac_wkm);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_lpt;
|
|
|
|
|
c->superblock_need_write = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!c->ro_mount && c->superblock_need_write) {
|
|
|
|
|
err = ubifs_write_sb_node(c, c->sup_node);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_lpt;
|
|
|
|
|
c->superblock_need_write = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-29 15:04:05 +00:00
|
|
|
|
err = dbg_check_idx_size(c, c->bi.old_idx_sz);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out_lpt;
|
|
|
|
|
|
|
|
|
|
err = ubifs_replay_journal(c);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_journal;
|
|
|
|
|
|
2009-06-28 15:31:58 +00:00
|
|
|
|
/* Calculate 'min_idx_lebs' after journal replay */
|
2011-03-29 15:04:05 +00:00
|
|
|
|
c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c);
|
2009-06-28 15:31:58 +00:00
|
|
|
|
|
2010-09-19 15:34:26 +00:00
|
|
|
|
err = ubifs_mount_orphans(c, c->need_recovery, c->ro_mount);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out_orphans;
|
|
|
|
|
|
2010-09-19 15:34:26 +00:00
|
|
|
|
if (!c->ro_mount) {
|
2008-07-14 16:08:37 +00:00
|
|
|
|
int lnum;
|
|
|
|
|
|
2008-12-30 14:23:34 +00:00
|
|
|
|
err = check_free_space(c);
|
|
|
|
|
if (err)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
goto out_orphans;
|
|
|
|
|
|
|
|
|
|
/* Check for enough log space */
|
|
|
|
|
lnum = c->lhead_lnum + 1;
|
|
|
|
|
if (lnum >= UBIFS_LOG_LNUM + c->log_lebs)
|
|
|
|
|
lnum = UBIFS_LOG_LNUM;
|
|
|
|
|
if (lnum == c->ltail_lnum) {
|
|
|
|
|
err = ubifs_consolidate_log(c);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_orphans;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c->need_recovery) {
|
2018-09-07 12:36:44 +00:00
|
|
|
|
if (!ubifs_authenticated(c)) {
|
|
|
|
|
err = ubifs_recover_size(c, true);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_orphans;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = ubifs_rcvry_gc_commit(c);
|
2010-05-23 11:16:13 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out_orphans;
|
2018-09-07 12:36:44 +00:00
|
|
|
|
|
|
|
|
|
if (ubifs_authenticated(c)) {
|
|
|
|
|
err = ubifs_recover_size(c, false);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_orphans;
|
|
|
|
|
}
|
2009-01-23 16:23:03 +00:00
|
|
|
|
} else {
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = take_gc_lnum(c);
|
2009-01-23 16:23:03 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out_orphans;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* GC LEB may contain garbage if there was an unclean
|
|
|
|
|
* reboot, and it should be un-mapped.
|
|
|
|
|
*/
|
|
|
|
|
err = ubifs_leb_unmap(c, c->gc_lnum);
|
|
|
|
|
if (err)
|
2010-08-02 09:36:06 +00:00
|
|
|
|
goto out_orphans;
|
2009-01-23 16:23:03 +00:00
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
err = dbg_check_lprops(c);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_orphans;
|
|
|
|
|
} else if (c->need_recovery) {
|
2018-09-07 12:36:44 +00:00
|
|
|
|
err = ubifs_recover_size(c, false);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out_orphans;
|
2009-01-23 16:23:03 +00:00
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* Even if we mount read-only, we have to set space in GC LEB
|
|
|
|
|
* to proper value because this affects UBIFS free space
|
|
|
|
|
* reporting. We do not want to have a situation when
|
|
|
|
|
* re-mounting from R/O to R/W changes amount of free space.
|
|
|
|
|
*/
|
|
|
|
|
err = take_gc_lnum(c);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_orphans;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spin_lock(&ubifs_infos_lock);
|
|
|
|
|
list_add_tail(&c->infos_list, &ubifs_infos);
|
|
|
|
|
spin_unlock(&ubifs_infos_lock);
|
|
|
|
|
|
|
|
|
|
if (c->need_recovery) {
|
2010-09-19 15:34:26 +00:00
|
|
|
|
if (c->ro_mount)
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_msg(c, "recovery deferred");
|
2008-07-14 16:08:37 +00:00
|
|
|
|
else {
|
|
|
|
|
c->need_recovery = 0;
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_msg(c, "recovery completed");
|
2009-03-15 15:20:22 +00:00
|
|
|
|
/*
|
|
|
|
|
* GC LEB has to be empty and taken at this point. But
|
|
|
|
|
* the journal head LEBs may also be accounted as
|
|
|
|
|
* "empty taken" if they are empty.
|
|
|
|
|
*/
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_assert(c, c->lst.taken_empty_lebs > 0);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
2009-01-26 14:12:20 +00:00
|
|
|
|
} else
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_assert(c, c->lst.taken_empty_lebs > 0);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2009-01-26 14:12:20 +00:00
|
|
|
|
err = dbg_check_filesystem(c);
|
2008-10-23 08:49:28 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out_infos;
|
|
|
|
|
|
2019-06-12 15:21:20 +00:00
|
|
|
|
dbg_debugfs_init_fs(c);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2011-01-17 20:27:56 +00:00
|
|
|
|
c->mounting = 0;
|
2008-09-04 13:26:00 +00:00
|
|
|
|
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_msg(c, "UBIFS: mounted UBI device %d, volume %d, name \"%s\"%s",
|
2012-08-27 13:56:58 +00:00
|
|
|
|
c->vi.ubi_num, c->vi.vol_id, c->vi.name,
|
2013-04-02 10:24:37 +00:00
|
|
|
|
c->ro_mount ? ", R/O mode" : "");
|
2008-07-14 16:08:37 +00:00
|
|
|
|
x = (long long)c->main_lebs * c->leb_size;
|
2012-08-27 13:56:58 +00:00
|
|
|
|
y = (long long)c->log_lebs * c->leb_size + c->max_bud_bytes;
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_msg(c, "LEB size: %d bytes (%d KiB), min./max. I/O unit sizes: %d bytes/%d bytes",
|
2012-08-27 13:56:58 +00:00
|
|
|
|
c->leb_size, c->leb_size >> 10, c->min_io_size,
|
|
|
|
|
c->max_write_size);
|
2021-03-03 09:05:19 +00:00
|
|
|
|
ubifs_msg(c, "FS size: %lld bytes (%lld MiB, %d LEBs), max %d LEBs, journal size %lld bytes (%lld MiB, %d LEBs)",
|
|
|
|
|
x, x >> 20, c->main_lebs, c->max_leb_cnt,
|
2012-08-27 13:56:58 +00:00
|
|
|
|
y, y >> 20, c->log_lebs + c->max_bud_cnt);
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_msg(c, "reserved for root: %llu bytes (%llu KiB)",
|
2012-08-27 13:56:58 +00:00
|
|
|
|
c->report_rp_size, c->report_rp_size >> 10);
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_msg(c, "media format: w%d/r%d (latest is w%d/r%d), UUID %pUB%s",
|
2009-03-26 10:51:21 +00:00
|
|
|
|
c->fmt_version, c->ro_compat_version,
|
2012-08-27 13:56:58 +00:00
|
|
|
|
UBIFS_FORMAT_VERSION, UBIFS_RO_COMPAT_VERSION, c->uuid,
|
|
|
|
|
c->big_lpt ? ", big LPT model" : ", small LPT model");
|
|
|
|
|
|
2018-07-12 11:01:57 +00:00
|
|
|
|
dbg_gen("default compressor: %s", ubifs_compr_name(c, c->default_compr));
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("data journal heads: %d",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->jhead_cnt - NONDATA_JHEADS_CNT);
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("log LEBs: %d (%d - %d)",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->log_lebs, UBIFS_LOG_LNUM, c->log_last);
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("LPT area LEBs: %d (%d - %d)",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->lpt_lebs, c->lpt_first, c->lpt_last);
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("orphan area LEBs: %d (%d - %d)",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->orph_lebs, c->orph_first, c->orph_last);
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("main area LEBs: %d (%d - %d)",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->main_lebs, c->main_first, c->leb_cnt - 1);
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("index LEBs: %d", c->lst.idx_lebs);
|
2020-12-08 13:58:11 +00:00
|
|
|
|
dbg_gen("total index bytes: %llu (%llu KiB, %llu MiB)",
|
2011-03-29 15:04:05 +00:00
|
|
|
|
c->bi.old_idx_sz, c->bi.old_idx_sz >> 10,
|
|
|
|
|
c->bi.old_idx_sz >> 20);
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("key hash type: %d", c->key_hash_type);
|
|
|
|
|
dbg_gen("tree fanout: %d", c->fanout);
|
|
|
|
|
dbg_gen("reserved GC LEB: %d", c->gc_lnum);
|
|
|
|
|
dbg_gen("max. znode size %d", c->max_znode_sz);
|
|
|
|
|
dbg_gen("max. index node size %d", c->max_idx_node_sz);
|
|
|
|
|
dbg_gen("node sizes: data %zu, inode %zu, dentry %zu",
|
2008-12-30 16:37:45 +00:00
|
|
|
|
UBIFS_DATA_NODE_SZ, UBIFS_INO_NODE_SZ, UBIFS_DENT_NODE_SZ);
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("node sizes: trun %zu, sb %zu, master %zu",
|
2008-12-30 16:37:45 +00:00
|
|
|
|
UBIFS_TRUN_NODE_SZ, UBIFS_SB_NODE_SZ, UBIFS_MST_NODE_SZ);
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("node sizes: ref %zu, cmt. start %zu, orph %zu",
|
2008-12-30 16:37:45 +00:00
|
|
|
|
UBIFS_REF_NODE_SZ, UBIFS_CS_NODE_SZ, UBIFS_ORPH_NODE_SZ);
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("max. node sizes: data %zu, inode %zu dentry %zu, idx %d",
|
2011-03-25 13:27:40 +00:00
|
|
|
|
UBIFS_MAX_DATA_NODE_SZ, UBIFS_MAX_INO_NODE_SZ,
|
2011-03-08 12:26:47 +00:00
|
|
|
|
UBIFS_MAX_DENT_NODE_SZ, ubifs_idx_node_sz(c, c->fanout));
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("dead watermark: %d", c->dead_wm);
|
|
|
|
|
dbg_gen("dark watermark: %d", c->dark_wm);
|
|
|
|
|
dbg_gen("LEB overhead: %d", c->leb_overhead);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
x = (long long)c->main_lebs * c->dark_wm;
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("max. dark space: %lld (%lld KiB, %lld MiB)",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
x, x >> 10, x >> 20);
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("maximum bud bytes: %lld (%lld KiB, %lld MiB)",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->max_bud_bytes, c->max_bud_bytes >> 10,
|
|
|
|
|
c->max_bud_bytes >> 20);
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("BG commit bud bytes: %lld (%lld KiB, %lld MiB)",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->bg_bud_bytes, c->bg_bud_bytes >> 10,
|
|
|
|
|
c->bg_bud_bytes >> 20);
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("current bud bytes %lld (%lld KiB, %lld MiB)",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->bud_bytes, c->bud_bytes >> 10, c->bud_bytes >> 20);
|
2012-08-27 13:56:58 +00:00
|
|
|
|
dbg_gen("max. seq. number: %llu", c->max_sqnum);
|
|
|
|
|
dbg_gen("commit number: %llu", c->cmt_no);
|
2019-04-04 22:34:38 +00:00
|
|
|
|
dbg_gen("max. xattrs per inode: %d", ubifs_xattr_max_cnt(c));
|
|
|
|
|
dbg_gen("max orphans: %d", c->max_orphans);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
out_infos:
|
|
|
|
|
spin_lock(&ubifs_infos_lock);
|
|
|
|
|
list_del(&c->infos_list);
|
|
|
|
|
spin_unlock(&ubifs_infos_lock);
|
|
|
|
|
out_orphans:
|
|
|
|
|
free_orphans(c);
|
|
|
|
|
out_journal:
|
|
|
|
|
destroy_journal(c);
|
|
|
|
|
out_lpt:
|
|
|
|
|
ubifs_lpt_free(c, 0);
|
|
|
|
|
out_master:
|
|
|
|
|
kfree(c->mst_node);
|
|
|
|
|
kfree(c->rcvrd_mst_node);
|
|
|
|
|
if (c->bgt)
|
|
|
|
|
kthread_stop(c->bgt);
|
|
|
|
|
out_wbufs:
|
|
|
|
|
free_wbufs(c);
|
|
|
|
|
out_cbuf:
|
|
|
|
|
kfree(c->cbuf);
|
2020-09-29 12:45:31 +00:00
|
|
|
|
out_auth:
|
|
|
|
|
ubifs_exit_authentication(c);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
out_free:
|
2011-03-04 22:55:02 +00:00
|
|
|
|
kfree(c->write_reserve_buf);
|
2008-11-19 09:53:15 +00:00
|
|
|
|
kfree(c->bu.buf);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
vfree(c->ileb_buf);
|
|
|
|
|
vfree(c->sbuf);
|
|
|
|
|
kfree(c->bottom_up_buf);
|
2020-01-14 05:43:11 +00:00
|
|
|
|
kfree(c->sup_node);
|
2021-10-10 04:22:39 +00:00
|
|
|
|
ubifs_sysfs_unregister(c);
|
|
|
|
|
out_debugging:
|
2008-10-17 10:31:39 +00:00
|
|
|
|
ubifs_debugging_exit(c);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ubifs_umount - un-mount UBIFS file-system.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* Note, this function is called to free allocated resourced when un-mounting,
|
|
|
|
|
* as well as free resources when an error occurred while we were half way
|
|
|
|
|
* through mounting (error path cleanup function). So it has to make sure the
|
|
|
|
|
* resource was actually allocated before freeing it.
|
|
|
|
|
*/
|
|
|
|
|
static void ubifs_umount(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
dbg_gen("un-mounting UBI device %d, volume %d", c->vi.ubi_num,
|
|
|
|
|
c->vi.vol_id);
|
|
|
|
|
|
2008-10-23 08:49:28 +00:00
|
|
|
|
dbg_debugfs_exit_fs(c);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
spin_lock(&ubifs_infos_lock);
|
|
|
|
|
list_del(&c->infos_list);
|
|
|
|
|
spin_unlock(&ubifs_infos_lock);
|
|
|
|
|
|
|
|
|
|
if (c->bgt)
|
|
|
|
|
kthread_stop(c->bgt);
|
|
|
|
|
|
|
|
|
|
destroy_journal(c);
|
|
|
|
|
free_wbufs(c);
|
|
|
|
|
free_orphans(c);
|
|
|
|
|
ubifs_lpt_free(c, 0);
|
2018-09-07 12:36:45 +00:00
|
|
|
|
ubifs_exit_authentication(c);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2020-09-29 12:45:29 +00:00
|
|
|
|
ubifs_release_options(c);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
kfree(c->cbuf);
|
|
|
|
|
kfree(c->rcvrd_mst_node);
|
|
|
|
|
kfree(c->mst_node);
|
2011-03-04 22:55:02 +00:00
|
|
|
|
kfree(c->write_reserve_buf);
|
2008-11-19 09:53:15 +00:00
|
|
|
|
kfree(c->bu.buf);
|
|
|
|
|
vfree(c->ileb_buf);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
vfree(c->sbuf);
|
|
|
|
|
kfree(c->bottom_up_buf);
|
2020-01-14 05:43:11 +00:00
|
|
|
|
kfree(c->sup_node);
|
2008-10-17 10:31:39 +00:00
|
|
|
|
ubifs_debugging_exit(c);
|
2021-10-10 04:22:39 +00:00
|
|
|
|
ubifs_sysfs_unregister(c);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ubifs_remount_rw - re-mount in read-write mode.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* UBIFS avoids allocating many unnecessary resources when mounted in read-only
|
|
|
|
|
* mode. This function allocates the needed resources and re-mounts UBIFS in
|
|
|
|
|
* read-write mode.
|
|
|
|
|
*/
|
|
|
|
|
static int ubifs_remount_rw(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
int err, lnum;
|
|
|
|
|
|
2009-03-26 10:51:21 +00:00
|
|
|
|
if (c->rw_incompat) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "the file-system is not R/W-compatible");
|
|
|
|
|
ubifs_msg(c, "on-flash format version is w%d/r%d, but software only supports up to version w%d/r%d",
|
2012-08-27 10:34:09 +00:00
|
|
|
|
c->fmt_version, c->ro_compat_version,
|
|
|
|
|
UBIFS_FORMAT_VERSION, UBIFS_RO_COMPAT_VERSION);
|
2009-03-26 10:51:21 +00:00
|
|
|
|
return -EROFS;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
mutex_lock(&c->umount_mutex);
|
2009-01-23 12:54:59 +00:00
|
|
|
|
dbg_save_space_info(c);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->remounting_rw = 1;
|
2011-03-29 06:45:21 +00:00
|
|
|
|
c->ro_mount = 0;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2013-03-14 08:49:23 +00:00
|
|
|
|
if (c->space_fixup) {
|
|
|
|
|
err = ubifs_fixup_free_space(c);
|
|
|
|
|
if (err)
|
2014-04-07 10:39:06 +00:00
|
|
|
|
goto out;
|
2013-03-14 08:49:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-12-30 14:23:34 +00:00
|
|
|
|
err = check_free_space(c);
|
|
|
|
|
if (err)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
if (c->need_recovery) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_msg(c, "completing deferred recovery");
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = ubifs_write_rcvrd_mst_node(c);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
2018-09-07 12:36:44 +00:00
|
|
|
|
if (!ubifs_authenticated(c)) {
|
|
|
|
|
err = ubifs_recover_size(c, true);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = ubifs_clean_lebs(c, c->sbuf);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
err = ubifs_recover_inl_heads(c, c->sbuf);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
2009-01-26 08:55:40 +00:00
|
|
|
|
} else {
|
|
|
|
|
/* A readonly mount is not allowed to have orphans */
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_assert(c, c->tot_orphans == 0);
|
2009-01-26 08:55:40 +00:00
|
|
|
|
err = ubifs_clear_orphans(c);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY))) {
|
|
|
|
|
c->mst_node->flags |= cpu_to_le32(UBIFS_MST_DIRTY);
|
|
|
|
|
err = ubifs_write_master(c);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 08:33:22 +00:00
|
|
|
|
if (c->superblock_need_write) {
|
|
|
|
|
struct ubifs_sb_node *sup = c->sup_node;
|
|
|
|
|
|
|
|
|
|
err = ubifs_write_sb_node(c, sup);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
c->superblock_need_write = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->ileb_buf = vmalloc(c->leb_size);
|
|
|
|
|
if (!c->ileb_buf) {
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-29 20:20:19 +00:00
|
|
|
|
c->write_reserve_buf = kmalloc(COMPRESSED_DATA_NODE_BUF_SZ + \
|
|
|
|
|
UBIFS_CIPHER_BLOCK_SIZE, GFP_KERNEL);
|
2013-06-07 02:17:22 +00:00
|
|
|
|
if (!c->write_reserve_buf) {
|
|
|
|
|
err = -ENOMEM;
|
2011-03-04 22:55:02 +00:00
|
|
|
|
goto out;
|
2013-06-07 02:17:22 +00:00
|
|
|
|
}
|
2011-03-04 22:55:02 +00:00
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = ubifs_lpt_init(c, 0, 1);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
/* Create background thread */
|
2021-10-21 08:43:43 +00:00
|
|
|
|
c->bgt = kthread_run(ubifs_bg_thread, c, "%s", c->bgt_name);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (IS_ERR(c->bgt)) {
|
|
|
|
|
err = PTR_ERR(c->bgt);
|
|
|
|
|
c->bgt = NULL;
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "cannot spawn \"%s\", error %d",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->bgt_name, err);
|
2008-09-04 13:26:00 +00:00
|
|
|
|
goto out;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c->orph_buf = vmalloc(c->leb_size);
|
2008-09-04 13:26:00 +00:00
|
|
|
|
if (!c->orph_buf) {
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
/* Check for enough log space */
|
|
|
|
|
lnum = c->lhead_lnum + 1;
|
|
|
|
|
if (lnum >= UBIFS_LOG_LNUM + c->log_lebs)
|
|
|
|
|
lnum = UBIFS_LOG_LNUM;
|
|
|
|
|
if (lnum == c->ltail_lnum) {
|
|
|
|
|
err = ubifs_consolidate_log(c);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-07 12:36:44 +00:00
|
|
|
|
if (c->need_recovery) {
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = ubifs_rcvry_gc_commit(c);
|
2018-09-07 12:36:44 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
if (ubifs_authenticated(c)) {
|
|
|
|
|
err = ubifs_recover_size(c, false);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2009-01-23 16:23:03 +00:00
|
|
|
|
err = ubifs_leb_unmap(c, c->gc_lnum);
|
2018-09-07 12:36:44 +00:00
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
|
2011-04-20 15:02:45 +00:00
|
|
|
|
dbg_gen("re-mounted read-write");
|
|
|
|
|
c->remounting_rw = 0;
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (c->need_recovery) {
|
|
|
|
|
c->need_recovery = 0;
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_msg(c, "deferred recovery completed");
|
2011-04-20 15:02:45 +00:00
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* Do not run the debugging space check if the were doing
|
|
|
|
|
* recovery, because when we saved the information we had the
|
|
|
|
|
* file-system in a state where the TNC and lprops has been
|
|
|
|
|
* modified in memory, but all the I/O operations (including a
|
|
|
|
|
* commit) were deferred. So the file-system was in
|
|
|
|
|
* "non-committed" state. Now the file-system is in committed
|
|
|
|
|
* state, and of course the amount of free space will change
|
|
|
|
|
* because, for example, the old index size was imprecise.
|
|
|
|
|
*/
|
|
|
|
|
err = dbg_check_space_info(c);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
2011-05-06 22:58:23 +00:00
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
mutex_unlock(&c->umount_mutex);
|
2009-01-23 12:54:59 +00:00
|
|
|
|
return err;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
out:
|
2011-03-29 06:45:21 +00:00
|
|
|
|
c->ro_mount = 1;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
vfree(c->orph_buf);
|
|
|
|
|
c->orph_buf = NULL;
|
|
|
|
|
if (c->bgt) {
|
|
|
|
|
kthread_stop(c->bgt);
|
|
|
|
|
c->bgt = NULL;
|
|
|
|
|
}
|
2011-03-04 22:55:02 +00:00
|
|
|
|
kfree(c->write_reserve_buf);
|
|
|
|
|
c->write_reserve_buf = NULL;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
vfree(c->ileb_buf);
|
|
|
|
|
c->ileb_buf = NULL;
|
|
|
|
|
ubifs_lpt_free(c, 1);
|
|
|
|
|
c->remounting_rw = 0;
|
|
|
|
|
mutex_unlock(&c->umount_mutex);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ubifs_remount_ro - re-mount in read-only mode.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
2009-01-23 12:54:59 +00:00
|
|
|
|
* We assume VFS has stopped writing. Possibly the background thread could be
|
|
|
|
|
* running a commit, however kthread_stop will wait in that case.
|
2008-07-14 16:08:37 +00:00
|
|
|
|
*/
|
|
|
|
|
static void ubifs_remount_ro(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
int i, err;
|
|
|
|
|
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_assert(c, !c->need_recovery);
|
|
|
|
|
ubifs_assert(c, !c->ro_mount);
|
2009-01-23 12:17:36 +00:00
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
mutex_lock(&c->umount_mutex);
|
|
|
|
|
if (c->bgt) {
|
|
|
|
|
kthread_stop(c->bgt);
|
|
|
|
|
c->bgt = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-23 12:54:59 +00:00
|
|
|
|
dbg_save_space_info(c);
|
|
|
|
|
|
2018-01-17 18:12:42 +00:00
|
|
|
|
for (i = 0; i < c->jhead_cnt; i++) {
|
|
|
|
|
err = ubifs_wbuf_sync(&c->jheads[i].wbuf);
|
|
|
|
|
if (err)
|
|
|
|
|
ubifs_ro_mode(c, err);
|
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2009-01-23 12:17:36 +00:00
|
|
|
|
c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY);
|
|
|
|
|
c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS);
|
|
|
|
|
c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum);
|
|
|
|
|
err = ubifs_write_master(c);
|
|
|
|
|
if (err)
|
|
|
|
|
ubifs_ro_mode(c, err);
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
vfree(c->orph_buf);
|
|
|
|
|
c->orph_buf = NULL;
|
2011-03-04 22:55:02 +00:00
|
|
|
|
kfree(c->write_reserve_buf);
|
|
|
|
|
c->write_reserve_buf = NULL;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
vfree(c->ileb_buf);
|
|
|
|
|
c->ileb_buf = NULL;
|
|
|
|
|
ubifs_lpt_free(c, 1);
|
2010-09-19 15:34:26 +00:00
|
|
|
|
c->ro_mount = 1;
|
2009-01-23 12:54:59 +00:00
|
|
|
|
err = dbg_check_space_info(c);
|
|
|
|
|
if (err)
|
|
|
|
|
ubifs_ro_mode(c, err);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
mutex_unlock(&c->umount_mutex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ubifs_put_super(struct super_block *sb)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
struct ubifs_info *c = sb->s_fs_info;
|
|
|
|
|
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_msg(c, "un-mount UBI device %d", c->vi.ubi_num);
|
push BKL down into ->put_super
Move BKL into ->put_super from the only caller. A couple of
filesystems had trivial enough ->put_super (only kfree and NULLing of
s_fs_info + stuff in there) to not get any locking: coda, cramfs, efs,
hugetlbfs, omfs, qnx4, shmem, all others got the full treatment. Most
of them probably don't need it, but I'd rather sort that out individually.
Preferably after all the other BKL pushdowns in that area.
[AV: original used to move lock_super() down as well; these changes are
removed since we don't do lock_super() at all in generic_shutdown_super()
now]
[AV: fuse, btrfs and xfs are known to need no damn BKL, exempt]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2009-05-05 13:40:36 +00:00
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* The following asserts are only valid if there has not been a failure
|
|
|
|
|
* of the media. For example, there will be dirty inodes if we failed
|
|
|
|
|
* to write them back because of I/O errors.
|
|
|
|
|
*/
|
2011-04-21 07:39:54 +00:00
|
|
|
|
if (!c->ro_error) {
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_assert(c, c->bi.idx_growth == 0);
|
|
|
|
|
ubifs_assert(c, c->bi.dd_growth == 0);
|
|
|
|
|
ubifs_assert(c, c->bi.data_growth == 0);
|
2011-04-21 07:39:54 +00:00
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The 'c->umount_lock' prevents races between UBIFS memory shrinker
|
|
|
|
|
* and file system un-mount. Namely, it prevents the shrinker from
|
|
|
|
|
* picking this superblock for shrinking - it will be just skipped if
|
|
|
|
|
* the mutex is locked.
|
|
|
|
|
*/
|
|
|
|
|
mutex_lock(&c->umount_mutex);
|
2010-09-19 15:34:26 +00:00
|
|
|
|
if (!c->ro_mount) {
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* First of all kill the background thread to make sure it does
|
|
|
|
|
* not interfere with un-mounting and freeing resources.
|
|
|
|
|
*/
|
|
|
|
|
if (c->bgt) {
|
|
|
|
|
kthread_stop(c->bgt);
|
|
|
|
|
c->bgt = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
UBIFS: introduce new flag for RO due to errors
The R/O state may have various reasons:
1. The UBI volume is R/O
2. The FS is mounted R/O
3. The FS switched to R/O mode because of an error
However, in UBIFS we have only one variable which represents cases
1 and 3 - 'c->ro_media'. Indeed, we set this to 1 if we switch to
R/O mode due to an error, and then we test it in many places to
make sure that we stop writing as soon as the error happens.
But this is very unclean. One consequence of this, for example, is
that in 'ubifs_remount_fs()' we use 'c->ro_media' to check whether
we are in R/O mode because on an error, and we print a message
in this case. However, if we are in R/O mode because the media
is R/O, our message is bogus.
This patch introduces new flag - 'c->ro_error' which is set when
we switch to R/O mode because of an error. It also changes all
"if (c->ro_media)" checks to "if (c->ro_error)" checks, because
this is what the checks actually mean. We do not need to check
for 'c->ro_media' because if the UBI volume is in R/O mode, we
do not allow R/W mounting, and now writes can happen. This is
guaranteed by VFS. But it is good to double-check this, so this
patch also adds many "ubifs_assert(!c->ro_media)" checks.
In the 'ubifs_remount_fs()' function this patch makes a bit more
changes - it fixes the error messages as well.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-09-17 13:44:28 +00:00
|
|
|
|
* On fatal errors c->ro_error is set to 1, in which case we do
|
2008-07-14 16:08:37 +00:00
|
|
|
|
* not write the master node.
|
|
|
|
|
*/
|
UBIFS: introduce new flag for RO due to errors
The R/O state may have various reasons:
1. The UBI volume is R/O
2. The FS is mounted R/O
3. The FS switched to R/O mode because of an error
However, in UBIFS we have only one variable which represents cases
1 and 3 - 'c->ro_media'. Indeed, we set this to 1 if we switch to
R/O mode due to an error, and then we test it in many places to
make sure that we stop writing as soon as the error happens.
But this is very unclean. One consequence of this, for example, is
that in 'ubifs_remount_fs()' we use 'c->ro_media' to check whether
we are in R/O mode because on an error, and we print a message
in this case. However, if we are in R/O mode because the media
is R/O, our message is bogus.
This patch introduces new flag - 'c->ro_error' which is set when
we switch to R/O mode because of an error. It also changes all
"if (c->ro_media)" checks to "if (c->ro_error)" checks, because
this is what the checks actually mean. We do not need to check
for 'c->ro_media' because if the UBI volume is in R/O mode, we
do not allow R/W mounting, and now writes can happen. This is
guaranteed by VFS. But it is good to double-check this, so this
patch also adds many "ubifs_assert(!c->ro_media)" checks.
In the 'ubifs_remount_fs()' function this patch makes a bit more
changes - it fixes the error messages as well.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-09-17 13:44:28 +00:00
|
|
|
|
if (!c->ro_error) {
|
2010-09-19 15:34:26 +00:00
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
/* Synchronize write-buffers */
|
2018-01-17 18:12:42 +00:00
|
|
|
|
for (i = 0; i < c->jhead_cnt; i++) {
|
|
|
|
|
err = ubifs_wbuf_sync(&c->jheads[i].wbuf);
|
|
|
|
|
if (err)
|
|
|
|
|
ubifs_ro_mode(c, err);
|
|
|
|
|
}
|
2010-09-19 15:34:26 +00:00
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* We are being cleanly unmounted which means the
|
|
|
|
|
* orphans were killed - indicate this in the master
|
|
|
|
|
* node. Also save the reserved GC LEB number.
|
|
|
|
|
*/
|
|
|
|
|
c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY);
|
|
|
|
|
c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS);
|
|
|
|
|
c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum);
|
|
|
|
|
err = ubifs_write_master(c);
|
|
|
|
|
if (err)
|
|
|
|
|
/*
|
|
|
|
|
* Recovery will attempt to fix the master area
|
|
|
|
|
* next mount, so we just print a message and
|
|
|
|
|
* continue to unmount normally.
|
|
|
|
|
*/
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "failed to write master node, error %d",
|
2012-08-27 10:34:09 +00:00
|
|
|
|
err);
|
2010-10-18 05:32:35 +00:00
|
|
|
|
} else {
|
|
|
|
|
for (i = 0; i < c->jhead_cnt; i++)
|
|
|
|
|
/* Make sure write-buffer timers are canceled */
|
|
|
|
|
hrtimer_cancel(&c->jheads[i].wbuf.timer);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ubifs_umount(c);
|
|
|
|
|
ubi_close_volume(c->ubi);
|
|
|
|
|
mutex_unlock(&c->umount_mutex);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
static int ubifs_reconfigure(struct fs_context *fc)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
2024-10-02 16:58:34 +00:00
|
|
|
|
struct ubifs_fs_context *ctx = fc->fs_private;
|
|
|
|
|
struct super_block *sb = fc->root->d_sb;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
int err;
|
|
|
|
|
struct ubifs_info *c = sb->s_fs_info;
|
|
|
|
|
|
2014-03-13 14:14:33 +00:00
|
|
|
|
sync_filesystem(sb);
|
2024-10-02 16:58:34 +00:00
|
|
|
|
dbg_gen("old flags %#lx, new flags %#x", sb->s_flags, fc->sb_flags);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
/*
|
|
|
|
|
* Apply the mount option changes.
|
|
|
|
|
* auth_key_name and auth_hash_name are ignored on remount.
|
|
|
|
|
*/
|
|
|
|
|
c->mount_opts = ctx->mount_opts;
|
|
|
|
|
c->bulk_read = ctx->bulk_read;
|
|
|
|
|
c->no_chk_data_crc = ctx->no_chk_data_crc;
|
|
|
|
|
c->default_compr = ctx->default_compr;
|
|
|
|
|
c->assert_action = ctx->assert_action;
|
2008-11-19 09:53:15 +00:00
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
if (c->ro_mount && !(fc->sb_flags & SB_RDONLY)) {
|
UBIFS: introduce new flag for RO due to errors
The R/O state may have various reasons:
1. The UBI volume is R/O
2. The FS is mounted R/O
3. The FS switched to R/O mode because of an error
However, in UBIFS we have only one variable which represents cases
1 and 3 - 'c->ro_media'. Indeed, we set this to 1 if we switch to
R/O mode due to an error, and then we test it in many places to
make sure that we stop writing as soon as the error happens.
But this is very unclean. One consequence of this, for example, is
that in 'ubifs_remount_fs()' we use 'c->ro_media' to check whether
we are in R/O mode because on an error, and we print a message
in this case. However, if we are in R/O mode because the media
is R/O, our message is bogus.
This patch introduces new flag - 'c->ro_error' which is set when
we switch to R/O mode because of an error. It also changes all
"if (c->ro_media)" checks to "if (c->ro_error)" checks, because
this is what the checks actually mean. We do not need to check
for 'c->ro_media' because if the UBI volume is in R/O mode, we
do not allow R/W mounting, and now writes can happen. This is
guaranteed by VFS. But it is good to double-check this, so this
patch also adds many "ubifs_assert(!c->ro_media)" checks.
In the 'ubifs_remount_fs()' function this patch makes a bit more
changes - it fixes the error messages as well.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-09-17 13:44:28 +00:00
|
|
|
|
if (c->ro_error) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_msg(c, "cannot re-mount R/W due to prior errors");
|
UBIFS: introduce new flag for RO due to errors
The R/O state may have various reasons:
1. The UBI volume is R/O
2. The FS is mounted R/O
3. The FS switched to R/O mode because of an error
However, in UBIFS we have only one variable which represents cases
1 and 3 - 'c->ro_media'. Indeed, we set this to 1 if we switch to
R/O mode due to an error, and then we test it in many places to
make sure that we stop writing as soon as the error happens.
But this is very unclean. One consequence of this, for example, is
that in 'ubifs_remount_fs()' we use 'c->ro_media' to check whether
we are in R/O mode because on an error, and we print a message
in this case. However, if we are in R/O mode because the media
is R/O, our message is bogus.
This patch introduces new flag - 'c->ro_error' which is set when
we switch to R/O mode because of an error. It also changes all
"if (c->ro_media)" checks to "if (c->ro_error)" checks, because
this is what the checks actually mean. We do not need to check
for 'c->ro_media' because if the UBI volume is in R/O mode, we
do not allow R/W mounting, and now writes can happen. This is
guaranteed by VFS. But it is good to double-check this, so this
patch also adds many "ubifs_assert(!c->ro_media)" checks.
In the 'ubifs_remount_fs()' function this patch makes a bit more
changes - it fixes the error messages as well.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-09-17 13:44:28 +00:00
|
|
|
|
return -EROFS;
|
|
|
|
|
}
|
2009-01-23 12:17:36 +00:00
|
|
|
|
if (c->ro_media) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_msg(c, "cannot re-mount R/W - UBI volume is R/O");
|
2009-01-29 14:22:54 +00:00
|
|
|
|
return -EROFS;
|
2009-01-23 12:17:36 +00:00
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = ubifs_remount_rw(c);
|
2009-07-19 10:51:04 +00:00
|
|
|
|
if (err)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return err;
|
2024-10-02 16:58:34 +00:00
|
|
|
|
} else if (!c->ro_mount && (fc->sb_flags & SB_RDONLY)) {
|
UBIFS: introduce new flag for RO due to errors
The R/O state may have various reasons:
1. The UBI volume is R/O
2. The FS is mounted R/O
3. The FS switched to R/O mode because of an error
However, in UBIFS we have only one variable which represents cases
1 and 3 - 'c->ro_media'. Indeed, we set this to 1 if we switch to
R/O mode due to an error, and then we test it in many places to
make sure that we stop writing as soon as the error happens.
But this is very unclean. One consequence of this, for example, is
that in 'ubifs_remount_fs()' we use 'c->ro_media' to check whether
we are in R/O mode because on an error, and we print a message
in this case. However, if we are in R/O mode because the media
is R/O, our message is bogus.
This patch introduces new flag - 'c->ro_error' which is set when
we switch to R/O mode because of an error. It also changes all
"if (c->ro_media)" checks to "if (c->ro_error)" checks, because
this is what the checks actually mean. We do not need to check
for 'c->ro_media' because if the UBI volume is in R/O mode, we
do not allow R/W mounting, and now writes can happen. This is
guaranteed by VFS. But it is good to double-check this, so this
patch also adds many "ubifs_assert(!c->ro_media)" checks.
In the 'ubifs_remount_fs()' function this patch makes a bit more
changes - it fixes the error messages as well.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2010-09-17 13:44:28 +00:00
|
|
|
|
if (c->ro_error) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
ubifs_msg(c, "cannot re-mount R/O due to prior errors");
|
2009-01-29 14:22:54 +00:00
|
|
|
|
return -EROFS;
|
2009-01-29 10:59:33 +00:00
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
ubifs_remount_ro(c);
|
2009-01-29 10:59:33 +00:00
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2008-11-19 09:53:15 +00:00
|
|
|
|
if (c->bulk_read == 1)
|
|
|
|
|
bu_init(c);
|
|
|
|
|
else {
|
|
|
|
|
dbg_gen("disable bulk-read");
|
2017-06-12 01:46:31 +00:00
|
|
|
|
mutex_lock(&c->bu_mutex);
|
2008-11-19 09:53:15 +00:00
|
|
|
|
kfree(c->bu.buf);
|
|
|
|
|
c->bu.buf = NULL;
|
2017-06-12 01:46:31 +00:00
|
|
|
|
mutex_unlock(&c->bu_mutex);
|
2008-11-19 09:53:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 12:51:38 +00:00
|
|
|
|
if (!c->need_recovery)
|
|
|
|
|
ubifs_assert(c, c->lst.taken_empty_lebs > 0);
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-15 15:43:23 +00:00
|
|
|
|
const struct super_operations ubifs_super_operations = {
|
2008-07-14 16:08:37 +00:00
|
|
|
|
.alloc_inode = ubifs_alloc_inode,
|
2019-04-16 02:23:44 +00:00
|
|
|
|
.free_inode = ubifs_free_inode,
|
2008-07-14 16:08:37 +00:00
|
|
|
|
.put_super = ubifs_put_super,
|
|
|
|
|
.write_inode = ubifs_write_inode,
|
2019-08-05 02:35:49 +00:00
|
|
|
|
.drop_inode = ubifs_drop_inode,
|
2010-06-07 04:34:05 +00:00
|
|
|
|
.evict_inode = ubifs_evict_inode,
|
2008-07-14 16:08:37 +00:00
|
|
|
|
.statfs = ubifs_statfs,
|
|
|
|
|
.dirty_inode = ubifs_dirty_inode,
|
|
|
|
|
.show_options = ubifs_show_options,
|
|
|
|
|
.sync_fs = ubifs_sync_fs,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* open_ubi - parse UBI device name string and open the UBI device.
|
2024-10-02 16:58:34 +00:00
|
|
|
|
* @fc: The filesystem context
|
2008-07-14 16:08:37 +00:00
|
|
|
|
* @mode: UBI volume open mode
|
|
|
|
|
*
|
2009-09-28 19:10:12 +00:00
|
|
|
|
* The primary method of mounting UBIFS is by specifying the UBI volume
|
2021-06-04 01:45:56 +00:00
|
|
|
|
* character device node path. However, UBIFS may also be mounted without any
|
2009-09-28 19:10:12 +00:00
|
|
|
|
* character device node using one of the following methods:
|
|
|
|
|
*
|
|
|
|
|
* o ubiX_Y - mount UBI device number X, volume Y;
|
|
|
|
|
* o ubiY - mount UBI device number 0, volume Y;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
* o ubiX:NAME - mount UBI device X, volume with name NAME;
|
|
|
|
|
* o ubi:NAME - mount UBI device 0, volume with name NAME.
|
|
|
|
|
*
|
|
|
|
|
* Alternative '!' separator may be used instead of ':' (because some shells
|
|
|
|
|
* like busybox may interpret ':' as an NFS host name separator). This function
|
2009-09-28 19:10:12 +00:00
|
|
|
|
* returns UBI volume description object in case of success and a negative
|
|
|
|
|
* error code in case of failure.
|
2008-07-14 16:08:37 +00:00
|
|
|
|
*/
|
2024-10-02 16:58:34 +00:00
|
|
|
|
static struct ubi_volume_desc *open_ubi(struct fs_context *fc, int mode)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
2009-09-28 19:10:12 +00:00
|
|
|
|
struct ubi_volume_desc *ubi;
|
2024-10-02 16:58:34 +00:00
|
|
|
|
const char *name = fc->source;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
int dev, vol;
|
|
|
|
|
char *endptr;
|
|
|
|
|
|
2009-09-28 19:10:12 +00:00
|
|
|
|
/* First, try to open using the device node path method */
|
|
|
|
|
ubi = ubi_open_volume_path(name, mode);
|
|
|
|
|
if (!IS_ERR(ubi))
|
|
|
|
|
return ubi;
|
|
|
|
|
|
|
|
|
|
/* Try the "nodev" method */
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (name[0] != 'u' || name[1] != 'b' || name[2] != 'i')
|
2024-10-02 16:58:34 +00:00
|
|
|
|
goto invalid_source;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
/* ubi:NAME method */
|
|
|
|
|
if ((name[3] == ':' || name[3] == '!') && name[4] != '\0')
|
|
|
|
|
return ubi_open_volume_nm(0, name + 4, mode);
|
|
|
|
|
|
|
|
|
|
if (!isdigit(name[3]))
|
2024-10-02 16:58:34 +00:00
|
|
|
|
goto invalid_source;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
dev = simple_strtoul(name + 3, &endptr, 0);
|
|
|
|
|
|
|
|
|
|
/* ubiY method */
|
|
|
|
|
if (*endptr == '\0')
|
|
|
|
|
return ubi_open_volume(0, dev, mode);
|
|
|
|
|
|
|
|
|
|
/* ubiX_Y method */
|
|
|
|
|
if (*endptr == '_' && isdigit(endptr[1])) {
|
|
|
|
|
vol = simple_strtoul(endptr + 1, &endptr, 0);
|
|
|
|
|
if (*endptr != '\0')
|
2024-10-02 16:58:34 +00:00
|
|
|
|
goto invalid_source;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return ubi_open_volume(dev, vol, mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ubiX:NAME method */
|
|
|
|
|
if ((*endptr == ':' || *endptr == '!') && endptr[1] != '\0')
|
|
|
|
|
return ubi_open_volume_nm(dev, ++endptr, mode);
|
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
invalid_source:
|
|
|
|
|
return ERR_PTR(invalf(fc, "Invalid source name"));
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-12 14:07:03 +00:00
|
|
|
|
static struct ubifs_info *alloc_ubifs_info(struct ubi_volume_desc *ubi)
|
|
|
|
|
{
|
|
|
|
|
struct ubifs_info *c;
|
|
|
|
|
|
|
|
|
|
c = kzalloc(sizeof(struct ubifs_info), GFP_KERNEL);
|
|
|
|
|
if (c) {
|
|
|
|
|
spin_lock_init(&c->cnt_lock);
|
|
|
|
|
spin_lock_init(&c->cs_lock);
|
|
|
|
|
spin_lock_init(&c->buds_lock);
|
|
|
|
|
spin_lock_init(&c->space_lock);
|
|
|
|
|
spin_lock_init(&c->orphan_lock);
|
|
|
|
|
init_rwsem(&c->commit_sem);
|
|
|
|
|
mutex_init(&c->lp_mutex);
|
|
|
|
|
mutex_init(&c->tnc_mutex);
|
|
|
|
|
mutex_init(&c->log_mutex);
|
|
|
|
|
mutex_init(&c->umount_mutex);
|
|
|
|
|
mutex_init(&c->bu_mutex);
|
|
|
|
|
mutex_init(&c->write_reserve_mutex);
|
|
|
|
|
init_waitqueue_head(&c->cmt_wq);
|
ubifs: Queue up space reservation tasks if retrying many times
Recently we catched ENOSPC returned by make_reservation() while doing
fsstress on UBIFS, we got following information when it occurred (See
details in Link):
UBIFS error (ubi0:0 pid 3640152): make_reservation [ubifs]: cannot
reserve 112 bytes in jhead 2, error -28
CPU: 2 PID: 3640152 Comm: kworker/u16:2 Tainted: G B W
Hardware name: Hisilicon PhosphorHi1230 EMU (DT)
Workqueue: writeback wb_workfn (flush-ubifs_0_0)
Call trace:
dump_stack+0x114/0x198
make_reservation+0x564/0x610 [ubifs]
ubifs_jnl_write_data+0x328/0x48c [ubifs]
do_writepage+0x2a8/0x3e4 [ubifs]
ubifs_writepage+0x16c/0x374 [ubifs]
generic_writepages+0xb4/0x114
do_writepages+0xcc/0x11c
writeback_sb_inodes+0x2d0/0x564
wb_writeback+0x20c/0x2b4
wb_workfn+0x404/0x510
process_one_work+0x304/0x4ac
worker_thread+0x31c/0x4e4
kthread+0x23c/0x290
Budgeting info: data budget sum 17576, total budget sum 17768
budg_data_growth 4144, budg_dd_growth 13432, budg_idx_growth 192
min_idx_lebs 13, old_idx_sz 988640, uncommitted_idx 0
page_budget 4144, inode_budget 160, dent_budget 312
nospace 0, nospace_rp 0
dark_wm 8192, dead_wm 4096, max_idx_node_sz 192
freeable_cnt 0, calc_idx_sz 988640, idx_gc_cnt 0
dirty_pg_cnt 4, dirty_zn_cnt 0, clean_zn_cnt 4811
gc_lnum 21, ihead_lnum 14
jhead 0 (GC) LEB 16
jhead 1 (base) LEB 34
jhead 2 (data) LEB 23
bud LEB 16
bud LEB 23
bud LEB 34
old bud LEB 33
old bud LEB 31
old bud LEB 15
commit state 4
Budgeting predictions:
available: 33832, outstanding 17576, free 15356
(pid 3640152) start dumping LEB properties
(pid 3640152) Lprops statistics: empty_lebs 3, idx_lebs 11
taken_empty_lebs 1, total_free 1253376, total_dirty 2445736
total_used 3438712, total_dark 65536, total_dead 17248
LEB 15 free 0 dirty 248000 used 5952 (taken)
LEB 16 free 110592 dirty 896 used 142464 (taken, jhead 0 (GC))
LEB 21 free 253952 dirty 0 used 0 (taken, GC LEB)
LEB 23 free 0 dirty 248104 used 5848 (taken, jhead 2 (data))
LEB 29 free 253952 dirty 0 used 0 (empty)
LEB 33 free 0 dirty 253952 used 0 (taken)
LEB 34 free 217088 dirty 36544 used 320 (taken, jhead 1 (base))
LEB 37 free 253952 dirty 0 used 0 (empty)
OTHERS: index lebs, zero-available non-index lebs
According to the budget algorithm, there are 5 LEBs reserved for budget:
three journal heads(16,23,34), 1 GC LEB(21) and 1 deletion LEB(can be
used in make_reservation()). There are 2 empty LEBs used for index nodes,
which is calculated as min_idx_lebs - idx_lebs = 2. In theory, LEB 15
and 33 should be reclaimed as free state after committing, but it is now
in taken state. After looking the realization of reserve_space(), there's
a possible situation:
LEB 15: free 2000 dirty 248000 used 3952 (jhead 2)
LEB 23: free 2000 dirty 248104 used 3848 (bud, taken)
LEB 33: free 2000 dirty 251952 used 0 (bud, taken)
wb_workfn wb_workfn_2
do_writepage // write 3000 bytes
ubifs_jnl_write_data
make_reservation
reserve_space
ubifs_garbage_collect
ubifs_find_dirty_leb // ret ENOSPC, dirty LEBs are taken
nospc_retries++ // 1
ubifs_run_commit
do_commit
LEB 15: free 2000 dirty 248000 used 3952 (jhead 2)
LEB 23: free 2000 dirty 248104 used 3848 (dirty)
LEB 33: free 2000 dirty 251952 used 0 (dirty)
do_writepage // write 2000 bytes for 3 times
ubifs_jnl_write_data
// grabs 15\23\33
LEB 15: free 0 dirty 248000 used 5952 (bud, taken)
LEB 23: free 0 dirty 248104 used 5848 (jhead 2)
LEB 33: free 0 dirty 253952 used 0 (bud, taken)
reserve_space
ubifs_garbage_collect
ubifs_find_dirty_leb // ret ENOSPC, dirty LEBs are taken
if (nospc_retries++ < 2) // false
ubifs_ro_mode !
Fetch a reproducer in Link.
The dirty LEBs could be grabbed by other threads, which fails finding dirty
LEBs of GC in current thread, so make_reservation() could try many times to
invoke GC&&committing, but current realization limits the times of retrying
as 'nospc_retries'(twice).
Fix it by adding a wait queue, start queuing up space reservation tasks
when someone task has retried gc + commit for many times. Then there is
only one task making space reservation at any time, and it can always make
success under the premise of correct budgeting.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=218164
Fixes: 1e51764a3c2a ("UBIFS: add new flash file system")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2024-01-22 06:31:03 +00:00
|
|
|
|
init_waitqueue_head(&c->reserve_space_wq);
|
|
|
|
|
atomic_set(&c->need_wait_space, 0);
|
2011-06-12 14:07:03 +00:00
|
|
|
|
c->buds = RB_ROOT;
|
|
|
|
|
c->old_idx = RB_ROOT;
|
|
|
|
|
c->size_tree = RB_ROOT;
|
|
|
|
|
c->orph_tree = RB_ROOT;
|
|
|
|
|
INIT_LIST_HEAD(&c->infos_list);
|
|
|
|
|
INIT_LIST_HEAD(&c->idx_gc);
|
|
|
|
|
INIT_LIST_HEAD(&c->replay_list);
|
|
|
|
|
INIT_LIST_HEAD(&c->replay_buds);
|
|
|
|
|
INIT_LIST_HEAD(&c->uncat_list);
|
|
|
|
|
INIT_LIST_HEAD(&c->empty_list);
|
|
|
|
|
INIT_LIST_HEAD(&c->freeable_list);
|
|
|
|
|
INIT_LIST_HEAD(&c->frdi_idx_list);
|
|
|
|
|
INIT_LIST_HEAD(&c->unclean_leb_list);
|
|
|
|
|
INIT_LIST_HEAD(&c->old_buds);
|
|
|
|
|
INIT_LIST_HEAD(&c->orph_list);
|
|
|
|
|
INIT_LIST_HEAD(&c->orph_new);
|
|
|
|
|
c->no_chk_data_crc = 1;
|
2018-07-12 11:02:00 +00:00
|
|
|
|
c->assert_action = ASSACT_RO;
|
2011-06-12 14:07:03 +00:00
|
|
|
|
|
|
|
|
|
c->highest_inum = UBIFS_FIRST_INO;
|
|
|
|
|
c->lhead_lnum = c->ltail_lnum = UBIFS_LOG_LNUM;
|
|
|
|
|
|
|
|
|
|
ubi_get_volume_info(ubi, &c->vi);
|
|
|
|
|
ubi_get_device_info(c->vi.ubi_num, &c->di);
|
|
|
|
|
}
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
static int ubifs_fill_super(struct super_block *sb, struct fs_context *fc)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
2011-06-12 14:24:33 +00:00
|
|
|
|
struct ubifs_info *c = sb->s_fs_info;
|
2024-10-02 16:58:34 +00:00
|
|
|
|
struct ubifs_fs_context *ctx = fc->fs_private;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
struct inode *root;
|
|
|
|
|
int err;
|
|
|
|
|
|
2009-05-29 09:34:52 +00:00
|
|
|
|
c->vfs_sb = sb;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/* Re-open the UBI device in read-write mode */
|
|
|
|
|
c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READWRITE);
|
|
|
|
|
if (IS_ERR(c->ubi)) {
|
|
|
|
|
err = PTR_ERR(c->ubi);
|
2011-06-12 14:24:33 +00:00
|
|
|
|
goto out;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
/* Copy in parsed mount options */
|
|
|
|
|
c->mount_opts = ctx->mount_opts;
|
|
|
|
|
c->auth_key_name = ctx->auth_key_name;
|
|
|
|
|
c->auth_hash_name = ctx->auth_hash_name;
|
|
|
|
|
c->no_chk_data_crc = ctx->no_chk_data_crc;
|
|
|
|
|
c->bulk_read = ctx->bulk_read;
|
|
|
|
|
c->default_compr = ctx->default_compr;
|
|
|
|
|
c->assert_action = ctx->assert_action;
|
|
|
|
|
|
|
|
|
|
/* ubifs_info owns auth strings now */
|
|
|
|
|
ctx->auth_key_name = NULL;
|
|
|
|
|
ctx->auth_hash_name = NULL;
|
2017-04-12 10:24:46 +00:00
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
2008-08-13 11:13:26 +00:00
|
|
|
|
* UBIFS provides 'backing_dev_info' in order to disable read-ahead. For
|
2022-04-29 15:12:16 +00:00
|
|
|
|
* UBIFS, I/O is not deferred, it is done immediately in read_folio,
|
2008-07-14 16:08:37 +00:00
|
|
|
|
* which means the user would have to wait not just for their own I/O
|
2008-08-13 11:13:26 +00:00
|
|
|
|
* but the read-ahead I/O as well i.e. completely pointless.
|
2008-07-14 16:08:37 +00:00
|
|
|
|
*
|
2017-04-12 10:24:46 +00:00
|
|
|
|
* Read-ahead will be disabled because @sb->s_bdi->ra_pages is 0. Also
|
|
|
|
|
* @sb->s_bdi->capabilities are initialized to 0 so there won't be any
|
|
|
|
|
* writeback happening.
|
2008-07-14 16:08:37 +00:00
|
|
|
|
*/
|
2017-04-12 10:24:46 +00:00
|
|
|
|
err = super_setup_bdi_name(sb, "ubifs_%d_%d", c->vi.ubi_num,
|
|
|
|
|
c->vi.vol_id);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out_close;
|
2020-09-24 06:51:32 +00:00
|
|
|
|
sb->s_bdi->ra_pages = 0;
|
|
|
|
|
sb->s_bdi->io_pages = 0;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
sb->s_fs_info = c;
|
|
|
|
|
sb->s_magic = UBIFS_SUPER_MAGIC;
|
|
|
|
|
sb->s_blocksize = UBIFS_BLOCK_SIZE;
|
|
|
|
|
sb->s_blocksize_bits = UBIFS_BLOCK_SHIFT;
|
|
|
|
|
sb->s_maxbytes = c->max_inode_sz = key_max_inode_size(c);
|
|
|
|
|
if (c->max_inode_sz > MAX_LFS_FILESIZE)
|
|
|
|
|
sb->s_maxbytes = c->max_inode_sz = MAX_LFS_FILESIZE;
|
|
|
|
|
sb->s_op = &ubifs_super_operations;
|
2016-04-22 17:14:00 +00:00
|
|
|
|
sb->s_xattr = ubifs_xattr_handlers;
|
2019-03-26 07:52:31 +00:00
|
|
|
|
fscrypt_set_ops(sb, &ubifs_crypt_operations);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
mutex_lock(&c->umount_mutex);
|
|
|
|
|
err = mount_ubifs(c);
|
|
|
|
|
if (err) {
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_assert(c, err < 0);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
goto out_unlock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Read the root inode */
|
|
|
|
|
root = ubifs_iget(sb, UBIFS_ROOT_INO);
|
|
|
|
|
if (IS_ERR(root)) {
|
|
|
|
|
err = PTR_ERR(root);
|
|
|
|
|
goto out_umount;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-21 17:14:11 +00:00
|
|
|
|
generic_set_sb_d_ops(sb);
|
2012-01-09 03:15:13 +00:00
|
|
|
|
sb->s_root = d_make_root(root);
|
2013-06-07 02:17:22 +00:00
|
|
|
|
if (!sb->s_root) {
|
|
|
|
|
err = -ENOMEM;
|
2012-01-09 03:15:13 +00:00
|
|
|
|
goto out_umount;
|
2013-06-07 02:17:22 +00:00
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2024-02-07 02:56:15 +00:00
|
|
|
|
super_set_uuid(sb, c->uuid, sizeof(c->uuid));
|
2021-02-16 07:23:34 +00:00
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
mutex_unlock(&c->umount_mutex);
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
out_umount:
|
|
|
|
|
ubifs_umount(c);
|
|
|
|
|
out_unlock:
|
|
|
|
|
mutex_unlock(&c->umount_mutex);
|
|
|
|
|
out_close:
|
2020-09-29 12:45:29 +00:00
|
|
|
|
ubifs_release_options(c);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
ubi_close_volume(c->ubi);
|
2011-06-12 14:24:33 +00:00
|
|
|
|
out:
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
static int sb_test(struct super_block *sb, struct fs_context *fc)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
2024-10-02 16:58:34 +00:00
|
|
|
|
struct ubifs_info *c1 = fc->s_fs_info;
|
2009-05-25 16:23:04 +00:00
|
|
|
|
struct ubifs_info *c = sb->s_fs_info;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2011-06-12 14:24:33 +00:00
|
|
|
|
return c->vi.cdev == c1->vi.cdev;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
static int ubifs_get_tree(struct fs_context *fc)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
|
|
|
|
struct ubi_volume_desc *ubi;
|
2011-06-12 14:24:33 +00:00
|
|
|
|
struct ubifs_info *c;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
struct super_block *sb;
|
|
|
|
|
int err;
|
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
if (!fc->source || !*fc->source)
|
|
|
|
|
return invalf(fc, "No source specified");
|
|
|
|
|
|
|
|
|
|
dbg_gen("name %s, flags %#x", fc->source, fc->sb_flags);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Get UBI device number and volume ID. Mount it read-only so far
|
|
|
|
|
* because this might be a new mount point, and UBI allows only one
|
|
|
|
|
* read-write user at a time.
|
|
|
|
|
*/
|
2024-10-02 16:58:34 +00:00
|
|
|
|
ubi = open_ubi(fc, UBI_READONLY);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (IS_ERR(ubi)) {
|
2024-10-02 16:58:34 +00:00
|
|
|
|
err = PTR_ERR(ubi);
|
|
|
|
|
if (!(fc->sb_flags & SB_SILENT))
|
2016-06-18 15:53:45 +00:00
|
|
|
|
pr_err("UBIFS error (pid: %d): cannot open \"%s\", error %d",
|
2024-10-02 16:58:34 +00:00
|
|
|
|
current->pid, fc->source, err);
|
|
|
|
|
return err;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-12 14:24:33 +00:00
|
|
|
|
c = alloc_ubifs_info(ubi);
|
|
|
|
|
if (!c) {
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
goto out_close;
|
|
|
|
|
}
|
2024-10-02 16:58:34 +00:00
|
|
|
|
fc->s_fs_info = c;
|
2011-06-12 14:24:33 +00:00
|
|
|
|
|
|
|
|
|
dbg_gen("opened ubi%d_%d", c->vi.ubi_num, c->vi.vol_id);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
sb = sget_fc(fc, sb_test, set_anon_super_fc);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (IS_ERR(sb)) {
|
|
|
|
|
err = PTR_ERR(sb);
|
2011-06-12 14:24:33 +00:00
|
|
|
|
kfree(c);
|
2011-06-20 07:10:24 +00:00
|
|
|
|
goto out_close;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sb->s_root) {
|
2010-09-19 15:34:26 +00:00
|
|
|
|
struct ubifs_info *c1 = sb->s_fs_info;
|
2011-06-12 14:24:33 +00:00
|
|
|
|
kfree(c);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/* A new mount point for already mounted UBIFS */
|
|
|
|
|
dbg_gen("this ubi volume is already mounted");
|
2024-10-02 16:58:34 +00:00
|
|
|
|
if (!!(fc->sb_flags & SB_RDONLY) != c1->ro_mount) {
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = -EBUSY;
|
|
|
|
|
goto out_deact;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-10-02 16:58:34 +00:00
|
|
|
|
err = ubifs_fill_super(sb, fc);
|
2019-10-24 08:25:35 +00:00
|
|
|
|
if (err)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
goto out_deact;
|
|
|
|
|
/* We do not support atime */
|
2017-11-27 21:05:09 +00:00
|
|
|
|
sb->s_flags |= SB_ACTIVE;
|
2019-03-26 07:52:32 +00:00
|
|
|
|
if (IS_ENABLED(CONFIG_UBIFS_ATIME_SUPPORT))
|
|
|
|
|
ubifs_msg(c, "full atime support is enabled.");
|
|
|
|
|
else
|
|
|
|
|
sb->s_flags |= SB_NOATIME;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 'fill_super()' opens ubi again so we must close it here */
|
|
|
|
|
ubi_close_volume(ubi);
|
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
fc->root = dget(sb->s_root);
|
|
|
|
|
return 0;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
out_deact:
|
2009-05-06 05:34:22 +00:00
|
|
|
|
deactivate_locked_super(sb);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
out_close:
|
|
|
|
|
ubi_close_volume(ubi);
|
2024-10-02 16:58:34 +00:00
|
|
|
|
return err;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-12 14:24:33 +00:00
|
|
|
|
static void kill_ubifs_super(struct super_block *s)
|
|
|
|
|
{
|
|
|
|
|
struct ubifs_info *c = s->s_fs_info;
|
|
|
|
|
kill_anon_super(s);
|
|
|
|
|
kfree(c);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-02 16:58:34 +00:00
|
|
|
|
static void ubifs_free_fc(struct fs_context *fc)
|
|
|
|
|
{
|
|
|
|
|
struct ubifs_fs_context *ctx = fc->fs_private;
|
|
|
|
|
|
|
|
|
|
if (ctx) {
|
|
|
|
|
kfree(ctx->auth_key_name);
|
|
|
|
|
kfree(ctx->auth_hash_name);
|
|
|
|
|
kfree(ctx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct fs_context_operations ubifs_context_ops = {
|
|
|
|
|
.free = ubifs_free_fc,
|
|
|
|
|
.parse_param = ubifs_parse_param,
|
|
|
|
|
.get_tree = ubifs_get_tree,
|
|
|
|
|
.reconfigure = ubifs_reconfigure,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int ubifs_init_fs_context(struct fs_context *fc)
|
|
|
|
|
{
|
|
|
|
|
struct ubifs_fs_context *ctx;
|
|
|
|
|
|
|
|
|
|
ctx = kzalloc(sizeof(struct ubifs_fs_context), GFP_KERNEL);
|
|
|
|
|
if (!ctx)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
if (fc->purpose != FS_CONTEXT_FOR_RECONFIGURE) {
|
|
|
|
|
/* Iniitialize for first mount */
|
|
|
|
|
ctx->no_chk_data_crc = 1;
|
|
|
|
|
ctx->assert_action = ASSACT_RO;
|
|
|
|
|
} else {
|
|
|
|
|
struct ubifs_info *c = fc->root->d_sb->s_fs_info;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Preserve existing options across remounts.
|
|
|
|
|
* auth_key_name and auth_hash_name are not remountable.
|
|
|
|
|
*/
|
|
|
|
|
ctx->mount_opts = c->mount_opts;
|
|
|
|
|
ctx->bulk_read = c->bulk_read;
|
|
|
|
|
ctx->no_chk_data_crc = c->no_chk_data_crc;
|
|
|
|
|
ctx->default_compr = c->default_compr;
|
|
|
|
|
ctx->assert_action = c->assert_action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fc->ops = &ubifs_context_ops;
|
|
|
|
|
fc->fs_private = ctx;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
static struct file_system_type ubifs_fs_type = {
|
|
|
|
|
.name = "ubifs",
|
|
|
|
|
.owner = THIS_MODULE,
|
2024-10-02 16:58:34 +00:00
|
|
|
|
.init_fs_context = ubifs_init_fs_context,
|
|
|
|
|
.parameters = ubifs_fs_param_spec,
|
2011-06-12 14:24:33 +00:00
|
|
|
|
.kill_sb = kill_ubifs_super,
|
2008-07-14 16:08:37 +00:00
|
|
|
|
};
|
2013-03-03 03:39:14 +00:00
|
|
|
|
MODULE_ALIAS_FS("ubifs");
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Inode slab cache constructor.
|
|
|
|
|
*/
|
2008-07-26 02:45:34 +00:00
|
|
|
|
static void inode_slab_ctor(void *obj)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
|
|
|
|
struct ubifs_inode *ui = obj;
|
|
|
|
|
inode_init_once(&ui->vfs_inode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int __init ubifs_init(void)
|
|
|
|
|
{
|
2023-09-11 09:44:13 +00:00
|
|
|
|
int err = -ENOMEM;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
BUILD_BUG_ON(sizeof(struct ubifs_ch) != 24);
|
|
|
|
|
|
|
|
|
|
/* Make sure node sizes are 8-byte aligned */
|
|
|
|
|
BUILD_BUG_ON(UBIFS_CH_SZ & 7);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_INO_NODE_SZ & 7);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_DENT_NODE_SZ & 7);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_XENT_NODE_SZ & 7);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_DATA_NODE_SZ & 7);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_TRUN_NODE_SZ & 7);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_SB_NODE_SZ & 7);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_MST_NODE_SZ & 7);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_REF_NODE_SZ & 7);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_CS_NODE_SZ & 7);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_ORPH_NODE_SZ & 7);
|
|
|
|
|
|
|
|
|
|
BUILD_BUG_ON(UBIFS_MAX_DENT_NODE_SZ & 7);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_MAX_XENT_NODE_SZ & 7);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_MAX_DATA_NODE_SZ & 7);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_MAX_INO_NODE_SZ & 7);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_MAX_NODE_SZ & 7);
|
|
|
|
|
BUILD_BUG_ON(MIN_WRITE_SZ & 7);
|
|
|
|
|
|
|
|
|
|
/* Check min. node size */
|
|
|
|
|
BUILD_BUG_ON(UBIFS_INO_NODE_SZ < MIN_WRITE_SZ);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_DENT_NODE_SZ < MIN_WRITE_SZ);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_XENT_NODE_SZ < MIN_WRITE_SZ);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_TRUN_NODE_SZ < MIN_WRITE_SZ);
|
|
|
|
|
|
|
|
|
|
BUILD_BUG_ON(UBIFS_MAX_DENT_NODE_SZ > UBIFS_MAX_NODE_SZ);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_MAX_XENT_NODE_SZ > UBIFS_MAX_NODE_SZ);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_MAX_DATA_NODE_SZ > UBIFS_MAX_NODE_SZ);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_MAX_INO_NODE_SZ > UBIFS_MAX_NODE_SZ);
|
|
|
|
|
|
|
|
|
|
/* Defined node sizes */
|
|
|
|
|
BUILD_BUG_ON(UBIFS_SB_NODE_SZ != 4096);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_MST_NODE_SZ != 512);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_INO_NODE_SZ != 160);
|
|
|
|
|
BUILD_BUG_ON(UBIFS_REF_NODE_SZ != 64);
|
|
|
|
|
|
2008-11-01 12:20:50 +00:00
|
|
|
|
/*
|
|
|
|
|
* We use 2 bit wide bit-fields to store compression type, which should
|
|
|
|
|
* be amended if more compressors are added. The bit-fields are:
|
2008-11-01 12:57:49 +00:00
|
|
|
|
* @compr_type in 'struct ubifs_inode', @default_compr in
|
|
|
|
|
* 'struct ubifs_info' and @compr_type in 'struct ubifs_mount_opts'.
|
2008-11-01 12:20:50 +00:00
|
|
|
|
*/
|
|
|
|
|
BUILD_BUG_ON(UBIFS_COMPR_TYPES_CNT > 4);
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
2016-04-01 12:29:48 +00:00
|
|
|
|
* We require that PAGE_SIZE is greater-than-or-equal-to
|
2008-07-14 16:08:37 +00:00
|
|
|
|
* UBIFS_BLOCK_SIZE. It is assumed that both are powers of 2.
|
|
|
|
|
*/
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 12:29:47 +00:00
|
|
|
|
if (PAGE_SIZE < UBIFS_BLOCK_SIZE) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
pr_err("UBIFS error (pid %d): VFS page cache size is %u bytes, but UBIFS requires at least 4096 bytes",
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 12:29:47 +00:00
|
|
|
|
current->pid, (unsigned int)PAGE_SIZE);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ubifs_inode_slab = kmem_cache_create("ubifs_inode_slab",
|
|
|
|
|
sizeof(struct ubifs_inode), 0,
|
2024-03-13 03:32:19 +00:00
|
|
|
|
SLAB_RECLAIM_ACCOUNT | SLAB_ACCOUNT,
|
|
|
|
|
&inode_slab_ctor);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (!ubifs_inode_slab)
|
2011-12-13 04:58:21 +00:00
|
|
|
|
return -ENOMEM;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2023-09-11 09:44:13 +00:00
|
|
|
|
ubifs_shrinker_info = shrinker_alloc(0, "ubifs-slab");
|
|
|
|
|
if (!ubifs_shrinker_info)
|
2015-05-18 08:43:02 +00:00
|
|
|
|
goto out_slab;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2023-09-11 09:44:13 +00:00
|
|
|
|
ubifs_shrinker_info->count_objects = ubifs_shrink_count;
|
|
|
|
|
ubifs_shrinker_info->scan_objects = ubifs_shrink_scan;
|
|
|
|
|
|
|
|
|
|
shrinker_register(ubifs_shrinker_info);
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = ubifs_compressors_init();
|
2008-10-23 08:49:28 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out_shrinker;
|
|
|
|
|
|
2019-06-12 15:21:20 +00:00
|
|
|
|
dbg_debugfs_init();
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2021-10-10 04:22:39 +00:00
|
|
|
|
err = ubifs_sysfs_init();
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_dbg;
|
|
|
|
|
|
2011-12-13 04:58:21 +00:00
|
|
|
|
err = register_filesystem(&ubifs_fs_type);
|
|
|
|
|
if (err) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
pr_err("UBIFS error (pid %d): cannot register file system, error %d",
|
|
|
|
|
current->pid, err);
|
2021-10-10 04:22:39 +00:00
|
|
|
|
goto out_sysfs;
|
2011-12-13 04:58:21 +00:00
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
2021-10-10 04:22:39 +00:00
|
|
|
|
out_sysfs:
|
|
|
|
|
ubifs_sysfs_exit();
|
2011-12-13 04:58:21 +00:00
|
|
|
|
out_dbg:
|
|
|
|
|
dbg_debugfs_exit();
|
2008-10-23 08:49:28 +00:00
|
|
|
|
ubifs_compressors_exit();
|
|
|
|
|
out_shrinker:
|
2023-09-11 09:44:13 +00:00
|
|
|
|
shrinker_free(ubifs_shrinker_info);
|
2015-05-18 08:43:02 +00:00
|
|
|
|
out_slab:
|
2008-07-14 16:08:37 +00:00
|
|
|
|
kmem_cache_destroy(ubifs_inode_slab);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
/* late_initcall to let compressors initialize first */
|
|
|
|
|
late_initcall(ubifs_init);
|
|
|
|
|
|
|
|
|
|
static void __exit ubifs_exit(void)
|
|
|
|
|
{
|
2018-10-13 08:18:41 +00:00
|
|
|
|
WARN_ON(!list_empty(&ubifs_infos));
|
|
|
|
|
WARN_ON(atomic_long_read(&ubifs_clean_zn_cnt) != 0);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2008-10-23 08:49:28 +00:00
|
|
|
|
dbg_debugfs_exit();
|
2021-10-10 04:22:39 +00:00
|
|
|
|
ubifs_sysfs_exit();
|
2008-07-14 16:08:37 +00:00
|
|
|
|
ubifs_compressors_exit();
|
2023-09-11 09:44:13 +00:00
|
|
|
|
shrinker_free(ubifs_shrinker_info);
|
2012-09-26 01:33:07 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Make sure all delayed rcu free inodes are flushed before we
|
|
|
|
|
* destroy cache.
|
|
|
|
|
*/
|
|
|
|
|
rcu_barrier();
|
2008-07-14 16:08:37 +00:00
|
|
|
|
kmem_cache_destroy(ubifs_inode_slab);
|
|
|
|
|
unregister_filesystem(&ubifs_fs_type);
|
|
|
|
|
}
|
|
|
|
|
module_exit(ubifs_exit);
|
|
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
MODULE_VERSION(__stringify(UBIFS_VERSION));
|
|
|
|
|
MODULE_AUTHOR("Artem Bityutskiy, Adrian Hunter");
|
|
|
|
|
MODULE_DESCRIPTION("UBIFS - UBI File System");
|