2019-05-30 07:57:50 +08:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2008-07-15 00:08:37 +08:00
|
|
|
|
/*
|
|
|
|
|
* This file is part of UBIFS.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2006-2008 Nokia Corporation.
|
|
|
|
|
*
|
|
|
|
|
* Authors: Artem Bityutskiy (Битюцкий Артём)
|
|
|
|
|
* Adrian Hunter
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
2009-09-01 22:06:43 +08:00
|
|
|
|
* This file implements VFS file and inode operations for regular files, device
|
2008-07-15 00:08:37 +08:00
|
|
|
|
* nodes and symlinks as well as address space operations.
|
|
|
|
|
*
|
2009-09-01 22:06:43 +08:00
|
|
|
|
* UBIFS uses 2 page flags: @PG_private and @PG_checked. @PG_private is set if
|
|
|
|
|
* the page is dirty and is used for optimization purposes - dirty pages are
|
|
|
|
|
* not budgeted so the flag shows that 'ubifs_write_end()' should not release
|
|
|
|
|
* the budget for this page. The @PG_checked flag is set if full budgeting is
|
|
|
|
|
* required for the page e.g., when it corresponds to a file hole or it is
|
|
|
|
|
* beyond the file size. The budgeting is done in 'ubifs_write_begin()', because
|
|
|
|
|
* it is OK to fail in this function, and the budget is released in
|
|
|
|
|
* 'ubifs_write_end()'. So the @PG_private and @PG_checked flags carry
|
|
|
|
|
* information about how the page was budgeted, to make it possible to release
|
|
|
|
|
* the budget properly.
|
2008-07-15 00:08:37 +08:00
|
|
|
|
*
|
2009-09-01 22:06:43 +08:00
|
|
|
|
* A thing to keep in mind: inode @i_mutex is locked in most VFS operations we
|
|
|
|
|
* implement. However, this is not true for 'ubifs_writepage()', which may be
|
2012-07-25 23:12:14 +08:00
|
|
|
|
* called with @i_mutex unlocked. For example, when flusher thread is doing
|
|
|
|
|
* background write-back, it calls 'ubifs_writepage()' with unlocked @i_mutex.
|
|
|
|
|
* At "normal" work-paths the @i_mutex is locked in 'ubifs_writepage()', e.g.
|
|
|
|
|
* in the "sys_write -> alloc_pages -> direct reclaim path". So, in
|
|
|
|
|
* 'ubifs_writepage()' we are only guaranteed that the page is locked.
|
2008-07-15 00:08:37 +08:00
|
|
|
|
*
|
2022-04-29 23:12:16 +08:00
|
|
|
|
* Similarly, @i_mutex is not always locked in 'ubifs_read_folio()', e.g., the
|
2009-09-01 22:06:43 +08:00
|
|
|
|
* read-ahead path does not lock it ("sys_read -> generic_file_aio_read ->
|
2022-04-29 23:12:16 +08:00
|
|
|
|
* ondemand_readahead -> read_folio"). In case of readahead, @I_SYNC flag is not
|
2009-09-01 22:06:43 +08:00
|
|
|
|
* set as well. However, UBIFS disables readahead.
|
2008-07-15 00:08:37 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ubifs.h"
|
|
|
|
|
#include <linux/mount.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
|
#include <linux/slab.h>
|
2016-06-17 05:26:15 +08:00
|
|
|
|
#include <linux/migrate.h>
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
|
|
|
|
static int read_block(struct inode *inode, void *addr, unsigned int block,
|
|
|
|
|
struct ubifs_data_node *dn)
|
|
|
|
|
{
|
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
|
|
|
|
int err, len, out_len;
|
|
|
|
|
union ubifs_key key;
|
|
|
|
|
unsigned int dlen;
|
|
|
|
|
|
|
|
|
|
data_key_init(c, &key, inode->i_ino, block);
|
|
|
|
|
err = ubifs_tnc_lookup(c, &key, dn);
|
|
|
|
|
if (err) {
|
|
|
|
|
if (err == -ENOENT)
|
|
|
|
|
/* Not found, so it must be a hole */
|
|
|
|
|
memset(addr, 0, UBIFS_BLOCK_SIZE);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 19:01:57 +08:00
|
|
|
|
ubifs_assert(c, le64_to_cpu(dn->ch.sqnum) >
|
2008-12-28 17:34:26 +08:00
|
|
|
|
ubifs_inode(inode)->creat_sqnum);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
len = le32_to_cpu(dn->size);
|
|
|
|
|
if (len <= 0 || len > UBIFS_BLOCK_SIZE)
|
|
|
|
|
goto dump;
|
|
|
|
|
|
|
|
|
|
dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ;
|
2016-09-30 04:20:19 +08:00
|
|
|
|
|
2019-12-10 05:27:21 +08:00
|
|
|
|
if (IS_ENCRYPTED(inode)) {
|
2016-09-30 04:20:19 +08:00
|
|
|
|
err = ubifs_decrypt(inode, dn, &dlen, block);
|
|
|
|
|
if (err)
|
|
|
|
|
goto dump;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-15 00:08:37 +08:00
|
|
|
|
out_len = 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 18:39:42 +08:00
|
|
|
|
err = ubifs_decompress(c, &dn->data, dlen, addr, &out_len,
|
2008-07-15 00:08:37 +08:00
|
|
|
|
le16_to_cpu(dn->compr_type));
|
|
|
|
|
if (err || len != out_len)
|
|
|
|
|
goto dump;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Data length can be less than a full block, even for blocks that are
|
|
|
|
|
* not the last in the file (e.g., as a result of making a hole and
|
|
|
|
|
* appending data). Ensure that the remainder is zeroed out.
|
|
|
|
|
*/
|
|
|
|
|
if (len < UBIFS_BLOCK_SIZE)
|
|
|
|
|
memset(addr + len, 0, UBIFS_BLOCK_SIZE - len);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
dump:
|
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 18:39:42 +08:00
|
|
|
|
ubifs_err(c, "bad data node (block %u, inode %lu)",
|
2008-07-15 00:08:37 +08:00
|
|
|
|
block, inode->i_ino);
|
2020-06-16 15:11:44 +08:00
|
|
|
|
ubifs_dump_node(c, dn, UBIFS_MAX_DATA_NODE_SZ);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int do_readpage(struct page *page)
|
|
|
|
|
{
|
|
|
|
|
void *addr;
|
|
|
|
|
int err = 0, i;
|
|
|
|
|
unsigned int block, beyond;
|
|
|
|
|
struct ubifs_data_node *dn;
|
|
|
|
|
struct inode *inode = page->mapping->host;
|
2018-07-12 19:01:57 +08:00
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
loff_t i_size = i_size_read(inode);
|
|
|
|
|
|
|
|
|
|
dbg_gen("ino %lu, pg %lu, i_size %lld, flags %#lx",
|
|
|
|
|
inode->i_ino, page->index, i_size, page->flags);
|
2018-07-12 19:01:57 +08:00
|
|
|
|
ubifs_assert(c, !PageChecked(page));
|
|
|
|
|
ubifs_assert(c, !PagePrivate(page));
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
|
|
|
|
addr = kmap(page);
|
|
|
|
|
|
|
|
|
|
block = page->index << UBIFS_BLOCKS_PER_PAGE_SHIFT;
|
|
|
|
|
beyond = (i_size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT;
|
|
|
|
|
if (block >= beyond) {
|
|
|
|
|
/* Reading beyond inode */
|
|
|
|
|
SetPageChecked(page);
|
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 20:29:47 +08:00
|
|
|
|
memset(addr, 0, PAGE_SIZE);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dn = kmalloc(UBIFS_MAX_DATA_NODE_SZ, GFP_NOFS);
|
|
|
|
|
if (!dn) {
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
while (1) {
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if (block >= beyond) {
|
|
|
|
|
/* Reading beyond inode */
|
|
|
|
|
err = -ENOENT;
|
|
|
|
|
memset(addr, 0, UBIFS_BLOCK_SIZE);
|
|
|
|
|
} else {
|
|
|
|
|
ret = read_block(inode, addr, block, dn);
|
|
|
|
|
if (ret) {
|
|
|
|
|
err = ret;
|
|
|
|
|
if (err != -ENOENT)
|
|
|
|
|
break;
|
2008-09-05 21:17:42 +08:00
|
|
|
|
} else if (block + 1 == beyond) {
|
|
|
|
|
int dlen = le32_to_cpu(dn->size);
|
|
|
|
|
int ilen = i_size & (UBIFS_BLOCK_SIZE - 1);
|
|
|
|
|
|
|
|
|
|
if (ilen && ilen < dlen)
|
|
|
|
|
memset(addr + ilen, 0, dlen - ilen);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (++i >= UBIFS_BLOCKS_PER_PAGE)
|
|
|
|
|
break;
|
|
|
|
|
block += 1;
|
|
|
|
|
addr += UBIFS_BLOCK_SIZE;
|
|
|
|
|
}
|
|
|
|
|
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 18:39:42 +08:00
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
if (err == -ENOENT) {
|
|
|
|
|
/* Not found, so it must be a hole */
|
|
|
|
|
SetPageChecked(page);
|
|
|
|
|
dbg_gen("hole");
|
|
|
|
|
goto out_free;
|
|
|
|
|
}
|
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 18:39:42 +08:00
|
|
|
|
ubifs_err(c, "cannot read page %lu of inode %lu, error %d",
|
2008-07-15 00:08:37 +08:00
|
|
|
|
page->index, inode->i_ino, err);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
|
kfree(dn);
|
|
|
|
|
out:
|
|
|
|
|
SetPageUptodate(page);
|
|
|
|
|
ClearPageError(page);
|
|
|
|
|
flush_dcache_page(page);
|
|
|
|
|
kunmap(page);
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
kfree(dn);
|
|
|
|
|
ClearPageUptodate(page);
|
|
|
|
|
SetPageError(page);
|
|
|
|
|
flush_dcache_page(page);
|
|
|
|
|
kunmap(page);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* release_new_page_budget - release budget of a new page.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* This is a helper function which releases budget corresponding to the budget
|
|
|
|
|
* of one new page of data.
|
|
|
|
|
*/
|
|
|
|
|
static void release_new_page_budget(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
struct ubifs_budget_req req = { .recalculate = 1, .new_page = 1 };
|
|
|
|
|
|
|
|
|
|
ubifs_release_budget(c, &req);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* release_existing_page_budget - release budget of an existing page.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* This is a helper function which releases budget corresponding to the budget
|
2020-08-05 10:49:35 +08:00
|
|
|
|
* of changing one page of data which already exists on the flash media.
|
2008-07-15 00:08:37 +08:00
|
|
|
|
*/
|
|
|
|
|
static void release_existing_page_budget(struct ubifs_info *c)
|
|
|
|
|
{
|
2011-03-29 23:04:05 +08:00
|
|
|
|
struct ubifs_budget_req req = { .dd_growth = c->bi.page_budget};
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
|
|
|
|
ubifs_release_budget(c, &req);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int write_begin_slow(struct address_space *mapping,
|
2022-02-23 03:31:43 +08:00
|
|
|
|
loff_t pos, unsigned len, struct page **pagep)
|
2008-07-15 00:08:37 +08:00
|
|
|
|
{
|
|
|
|
|
struct inode *inode = mapping->host;
|
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
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 20:29:47 +08:00
|
|
|
|
pgoff_t index = pos >> PAGE_SHIFT;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
struct ubifs_budget_req req = { .new_page = 1 };
|
treewide: Remove uninitialized_var() usage
Using uninitialized_var() is dangerous as it papers over real bugs[1]
(or can in the future), and suppresses unrelated compiler warnings
(e.g. "unused variable"). If the compiler thinks it is uninitialized,
either simply initialize the variable or make compiler changes.
In preparation for removing[2] the[3] macro[4], remove all remaining
needless uses with the following script:
git grep '\buninitialized_var\b' | cut -d: -f1 | sort -u | \
xargs perl -pi -e \
's/\buninitialized_var\(([^\)]+)\)/\1/g;
s:\s*/\* (GCC be quiet|to make compiler happy) \*/$::g;'
drivers/video/fbdev/riva/riva_hw.c was manually tweaked to avoid
pathological white-space.
No outstanding warnings were found building allmodconfig with GCC 9.3.0
for x86_64, i386, arm64, arm, powerpc, powerpc64le, s390x, mips, sparc64,
alpha, and m68k.
[1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/
[2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/
[3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/
[4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/
Reviewed-by: Leon Romanovsky <leonro@mellanox.com> # drivers/infiniband and mlx4/mlx5
Acked-by: Jason Gunthorpe <jgg@mellanox.com> # IB
Acked-by: Kalle Valo <kvalo@codeaurora.org> # wireless drivers
Reviewed-by: Chao Yu <yuchao0@huawei.com> # erofs
Signed-off-by: Kees Cook <keescook@chromium.org>
2020-06-04 04:09:38 +08:00
|
|
|
|
int err, appending = !!(pos + len > inode->i_size);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
struct page *page;
|
|
|
|
|
|
|
|
|
|
dbg_gen("ino %lu, pos %llu, len %u, i_size %lld",
|
|
|
|
|
inode->i_ino, pos, len, inode->i_size);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* At the slow path we have to budget before locking the page, because
|
|
|
|
|
* budgeting may force write-back, which would wait on locked pages and
|
|
|
|
|
* deadlock if we had the page locked. At this point we do not know
|
|
|
|
|
* anything about the page, so assume that this is a new page which is
|
|
|
|
|
* written to a hole. This corresponds to largest budget. Later the
|
|
|
|
|
* budget will be amended if this is not true.
|
|
|
|
|
*/
|
|
|
|
|
if (appending)
|
|
|
|
|
/* We are appending data, budget for inode change */
|
|
|
|
|
req.dirtied_ino = 1;
|
|
|
|
|
|
|
|
|
|
err = ubifs_budget_space(c, &req);
|
|
|
|
|
if (unlikely(err))
|
|
|
|
|
return err;
|
|
|
|
|
|
2022-02-23 00:25:12 +08:00
|
|
|
|
page = grab_cache_page_write_begin(mapping, index);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
if (unlikely(!page)) {
|
|
|
|
|
ubifs_release_budget(c, &req);
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!PageUptodate(page)) {
|
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 20:29:47 +08:00
|
|
|
|
if (!(pos & ~PAGE_MASK) && len == PAGE_SIZE)
|
2008-07-15 00:08:37 +08:00
|
|
|
|
SetPageChecked(page);
|
|
|
|
|
else {
|
|
|
|
|
err = do_readpage(page);
|
|
|
|
|
if (err) {
|
|
|
|
|
unlock_page(page);
|
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 20:29:47 +08:00
|
|
|
|
put_page(page);
|
2014-10-20 22:52:31 +08:00
|
|
|
|
ubifs_release_budget(c, &req);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetPageUptodate(page);
|
|
|
|
|
ClearPageError(page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (PagePrivate(page))
|
|
|
|
|
/*
|
|
|
|
|
* The page is dirty, which means it was budgeted twice:
|
|
|
|
|
* o first time the budget was allocated by the task which
|
|
|
|
|
* made the page dirty and set the PG_private flag;
|
|
|
|
|
* o and then we budgeted for it for the second time at the
|
|
|
|
|
* very beginning of this function.
|
|
|
|
|
*
|
|
|
|
|
* So what we have to do is to release the page budget we
|
|
|
|
|
* allocated.
|
|
|
|
|
*/
|
|
|
|
|
release_new_page_budget(c);
|
|
|
|
|
else if (!PageChecked(page))
|
|
|
|
|
/*
|
|
|
|
|
* We are changing a page which already exists on the media.
|
|
|
|
|
* This means that changing the page does not make the amount
|
|
|
|
|
* of indexing information larger, and this part of the budget
|
|
|
|
|
* which we have already acquired may be released.
|
|
|
|
|
*/
|
|
|
|
|
ubifs_convert_page_budget(c);
|
|
|
|
|
|
|
|
|
|
if (appending) {
|
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 'ubifs_write_end()' is optimized from the fast-path part of
|
|
|
|
|
* 'ubifs_write_begin()' and expects the @ui_mutex to be locked
|
|
|
|
|
* if data is appended.
|
|
|
|
|
*/
|
|
|
|
|
mutex_lock(&ui->ui_mutex);
|
|
|
|
|
if (ui->dirty)
|
|
|
|
|
/*
|
|
|
|
|
* The inode is dirty already, so we may free the
|
|
|
|
|
* budget we allocated.
|
|
|
|
|
*/
|
|
|
|
|
ubifs_release_dirty_inode_budget(c, ui);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*pagep = page;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* allocate_budget - allocate budget for 'ubifs_write_begin()'.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
* @page: page to allocate budget for
|
|
|
|
|
* @ui: UBIFS inode object the page belongs to
|
|
|
|
|
* @appending: non-zero if the page is appended
|
|
|
|
|
*
|
|
|
|
|
* This is a helper function for 'ubifs_write_begin()' which allocates budget
|
|
|
|
|
* for the operation. The budget is allocated differently depending on whether
|
|
|
|
|
* this is appending, whether the page is dirty or not, and so on. This
|
|
|
|
|
* function leaves the @ui->ui_mutex locked in case of appending. Returns zero
|
|
|
|
|
* in case of success and %-ENOSPC in case of failure.
|
|
|
|
|
*/
|
|
|
|
|
static int allocate_budget(struct ubifs_info *c, struct page *page,
|
|
|
|
|
struct ubifs_inode *ui, int appending)
|
|
|
|
|
{
|
|
|
|
|
struct ubifs_budget_req req = { .fast = 1 };
|
|
|
|
|
|
|
|
|
|
if (PagePrivate(page)) {
|
|
|
|
|
if (!appending)
|
|
|
|
|
/*
|
|
|
|
|
* The page is dirty and we are not appending, which
|
|
|
|
|
* means no budget is needed at all.
|
|
|
|
|
*/
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
mutex_lock(&ui->ui_mutex);
|
|
|
|
|
if (ui->dirty)
|
|
|
|
|
/*
|
|
|
|
|
* The page is dirty and we are appending, so the inode
|
|
|
|
|
* has to be marked as dirty. However, it is already
|
|
|
|
|
* dirty, so we do not need any budget. We may return,
|
|
|
|
|
* but @ui->ui_mutex hast to be left locked because we
|
|
|
|
|
* should prevent write-back from flushing the inode
|
|
|
|
|
* and freeing the budget. The lock will be released in
|
|
|
|
|
* 'ubifs_write_end()'.
|
|
|
|
|
*/
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The page is dirty, we are appending, the inode is clean, so
|
|
|
|
|
* we need to budget the inode change.
|
|
|
|
|
*/
|
|
|
|
|
req.dirtied_ino = 1;
|
|
|
|
|
} else {
|
|
|
|
|
if (PageChecked(page))
|
|
|
|
|
/*
|
|
|
|
|
* The page corresponds to a hole and does not
|
|
|
|
|
* exist on the media. So changing it makes
|
|
|
|
|
* make the amount of indexing information
|
|
|
|
|
* larger, and we have to budget for a new
|
|
|
|
|
* page.
|
|
|
|
|
*/
|
|
|
|
|
req.new_page = 1;
|
|
|
|
|
else
|
|
|
|
|
/*
|
|
|
|
|
* Not a hole, the change will not add any new
|
|
|
|
|
* indexing information, budget for page
|
|
|
|
|
* change.
|
|
|
|
|
*/
|
|
|
|
|
req.dirtied_page = 1;
|
|
|
|
|
|
|
|
|
|
if (appending) {
|
|
|
|
|
mutex_lock(&ui->ui_mutex);
|
|
|
|
|
if (!ui->dirty)
|
|
|
|
|
/*
|
|
|
|
|
* The inode is clean but we will have to mark
|
|
|
|
|
* it as dirty because we are appending. This
|
|
|
|
|
* needs a budget.
|
|
|
|
|
*/
|
|
|
|
|
req.dirtied_ino = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ubifs_budget_space(c, &req);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function is called when a page of data is going to be written. Since
|
|
|
|
|
* the page of data will not necessarily go to the flash straight away, UBIFS
|
|
|
|
|
* has to reserve space on the media for it, which is done by means of
|
|
|
|
|
* budgeting.
|
|
|
|
|
*
|
|
|
|
|
* This is the hot-path of the file-system and we are trying to optimize it as
|
|
|
|
|
* much as possible. For this reasons it is split on 2 parts - slow and fast.
|
|
|
|
|
*
|
|
|
|
|
* There many budgeting cases:
|
|
|
|
|
* o a new page is appended - we have to budget for a new page and for
|
|
|
|
|
* changing the inode; however, if the inode is already dirty, there is
|
|
|
|
|
* no need to budget for it;
|
|
|
|
|
* o an existing clean page is changed - we have budget for it; if the page
|
|
|
|
|
* does not exist on the media (a hole), we have to budget for a new
|
|
|
|
|
* page; otherwise, we may budget for changing an existing page; the
|
|
|
|
|
* difference between these cases is that changing an existing page does
|
|
|
|
|
* not introduce anything new to the FS indexing information, so it does
|
|
|
|
|
* not grow, and smaller budget is acquired in this case;
|
|
|
|
|
* o an existing dirty page is changed - no need to budget at all, because
|
|
|
|
|
* the page budget has been acquired by earlier, when the page has been
|
|
|
|
|
* marked dirty.
|
|
|
|
|
*
|
|
|
|
|
* UBIFS budgeting sub-system may force write-back if it thinks there is no
|
|
|
|
|
* space to reserve. This imposes some locking restrictions and makes it
|
|
|
|
|
* impossible to take into account the above cases, and makes it impossible to
|
|
|
|
|
* optimize budgeting.
|
|
|
|
|
*
|
|
|
|
|
* The solution for this is that the fast path of 'ubifs_write_begin()' assumes
|
|
|
|
|
* there is a plenty of flash space and the budget will be acquired quickly,
|
|
|
|
|
* without forcing write-back. The slow path does not make this assumption.
|
|
|
|
|
*/
|
|
|
|
|
static int ubifs_write_begin(struct file *file, struct address_space *mapping,
|
2022-02-23 03:31:43 +08:00
|
|
|
|
loff_t pos, unsigned len,
|
2008-07-15 00:08:37 +08:00
|
|
|
|
struct page **pagep, void **fsdata)
|
|
|
|
|
{
|
|
|
|
|
struct inode *inode = mapping->host;
|
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
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 20:29:47 +08:00
|
|
|
|
pgoff_t index = pos >> PAGE_SHIFT;
|
treewide: Remove uninitialized_var() usage
Using uninitialized_var() is dangerous as it papers over real bugs[1]
(or can in the future), and suppresses unrelated compiler warnings
(e.g. "unused variable"). If the compiler thinks it is uninitialized,
either simply initialize the variable or make compiler changes.
In preparation for removing[2] the[3] macro[4], remove all remaining
needless uses with the following script:
git grep '\buninitialized_var\b' | cut -d: -f1 | sort -u | \
xargs perl -pi -e \
's/\buninitialized_var\(([^\)]+)\)/\1/g;
s:\s*/\* (GCC be quiet|to make compiler happy) \*/$::g;'
drivers/video/fbdev/riva/riva_hw.c was manually tweaked to avoid
pathological white-space.
No outstanding warnings were found building allmodconfig with GCC 9.3.0
for x86_64, i386, arm64, arm, powerpc, powerpc64le, s390x, mips, sparc64,
alpha, and m68k.
[1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/
[2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/
[3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/
[4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/
Reviewed-by: Leon Romanovsky <leonro@mellanox.com> # drivers/infiniband and mlx4/mlx5
Acked-by: Jason Gunthorpe <jgg@mellanox.com> # IB
Acked-by: Kalle Valo <kvalo@codeaurora.org> # wireless drivers
Reviewed-by: Chao Yu <yuchao0@huawei.com> # erofs
Signed-off-by: Kees Cook <keescook@chromium.org>
2020-06-04 04:09:38 +08:00
|
|
|
|
int err, appending = !!(pos + len > inode->i_size);
|
2009-02-23 18:47:25 +08:00
|
|
|
|
int skipped_read = 0;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
struct page *page;
|
|
|
|
|
|
2018-07-12 19:01:57 +08:00
|
|
|
|
ubifs_assert(c, ubifs_inode(inode)->ui_size == inode->i_size);
|
|
|
|
|
ubifs_assert(c, !c->ro_media && !c->ro_mount);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
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 21:44:28 +08:00
|
|
|
|
if (unlikely(c->ro_error))
|
2008-07-15 00:08:37 +08:00
|
|
|
|
return -EROFS;
|
|
|
|
|
|
|
|
|
|
/* Try out the fast-path part first */
|
2022-02-23 00:25:12 +08:00
|
|
|
|
page = grab_cache_page_write_begin(mapping, index);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
if (unlikely(!page))
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
if (!PageUptodate(page)) {
|
|
|
|
|
/* The page is not loaded from the flash */
|
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 20:29:47 +08:00
|
|
|
|
if (!(pos & ~PAGE_MASK) && len == PAGE_SIZE) {
|
2008-07-15 00:08:37 +08:00
|
|
|
|
/*
|
|
|
|
|
* We change whole page so no need to load it. But we
|
UBIFS: fix assertion warning and refine comments
This patch fixes the following UBIFS assertion warning:
UBIFS assert failed in do_readpage at 115 (pid 199)
[<b00321b8>] (unwind_backtrace+0x0/0xdc) from [<af025118>]
(do_readpage+0x108/0x594 [ubifs])
[<af025118>] (do_readpage+0x108/0x594 [ubifs]) from [<af025764>]
(ubifs_write_end+0x1c0/0x2e8 [ubifs])
[<af025764>] (ubifs_write_end+0x1c0/0x2e8 [ubifs]) from
[<b00a0164>] (generic_file_buffered_write+0x18c/0x270)
[<b00a0164>] (generic_file_buffered_write+0x18c/0x270) from
[<b00a08d4>] (__generic_file_aio_write+0x478/0x4c0)
[<b00a08d4>] (__generic_file_aio_write+0x478/0x4c0) from
[<b00a0984>] (generic_file_aio_write+0x68/0xc8)
[<b00a0984>] (generic_file_aio_write+0x68/0xc8) from
[<af024a78>] (ubifs_aio_write+0x178/0x1d8 [ubifs])
[<af024a78>] (ubifs_aio_write+0x178/0x1d8 [ubifs]) from
[<b00d104c>] (do_sync_write+0xb0/0x100)
[<b00d104c>] (do_sync_write+0xb0/0x100) from [<b00d1abc>]
(vfs_write+0xac/0x154)
[<b00d1abc>] (vfs_write+0xac/0x154) from [<b00d1c10>]
(sys_write+0x3c/0x68)
[<b00d1c10>] (sys_write+0x3c/0x68) from [<b002d9a0>]
(ret_fast_syscall+0x0/0x2c)
The 'PG_checked' flag is used to indicate that the page does not
supposedly exist on the media (e.g., a hole or a page beyond the
inode size), so it requires slightly bigger budget, because we have
to account the indexing size increase. And this flag basically
tells that the budget for this page has to be "new page budget".
The "new page budget" is slightly bigger than the "existing page
budget".
The 'do_readpage()' function has the following assertion which
sometimes is hit: 'ubifs_assert(!PageChecked(page))'. Obviously,
the meaning of this assertion is: "I should not be asked to read
a page which does not exist on the media".
However, in 'ubifs_write_begin()' we have a small "trick". Notice,
that VFS may write pages which were not read yet, so the page data
were not loaded from the media to the page cache yet. If VFS tells
that it is going to change only some part of the page, we obviously
have to load it from the media. However, if VFS tells that it is
going to change whole page, we do not read it from the media for
optimization purposes.
However, since we do not read it, we do not know if it exists on
the media or not (a hole, etc). So we set the 'PG_checked' flag
to this page to force bigger budget, just in case.
So 'ubifs_write_begin()' sets 'PG_checked'. Then we are in
'ubifs_write_end()'. And VFS tells us: "hey, for some reasons I
changed my mind and did not change whole page". Frankly, I do not
know why this happens, but I hit this somehow on an ARM platform.
And this is extremely rare.
So in this case UBIFS does the following:
1. Cancels allocated budget.
2. Loads the page from the media by calling 'do_readpage()'.
3. Asks VFS to repeat the whole write operation from the very
beginning (call '->write_begin() again, etc).
And the assertion warning is hit at the step 2 - remember we have
the 'PG_checked' set for this page, and 'do_readpage()' does not
like this. So this patch fixes the problem by adding step 1.5 and
cleaning the 'PG_checked' before calling 'do_readpage()'.
All in all, this patch does not fix any functionality issue, but it
silences UBIFS false positive warning which may happen in very very
rare cases.
And while on it, this patch also improves a commentary which explains
the reasons of setting the 'PG_checked' flag for the page. The old
commentary was a bit difficult to understand.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2011-03-23 16:32:58 +08:00
|
|
|
|
* do not know whether this page exists on the media or
|
|
|
|
|
* not, so we assume the latter because it requires
|
|
|
|
|
* larger budget. The assumption is that it is better
|
|
|
|
|
* to budget a bit more than to read the page from the
|
|
|
|
|
* media. Thus, we are setting the @PG_checked flag
|
|
|
|
|
* here.
|
2008-07-15 00:08:37 +08:00
|
|
|
|
*/
|
|
|
|
|
SetPageChecked(page);
|
2009-02-23 18:47:25 +08:00
|
|
|
|
skipped_read = 1;
|
|
|
|
|
} else {
|
2008-07-15 00:08:37 +08:00
|
|
|
|
err = do_readpage(page);
|
|
|
|
|
if (err) {
|
|
|
|
|
unlock_page(page);
|
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 20:29:47 +08:00
|
|
|
|
put_page(page);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetPageUptodate(page);
|
|
|
|
|
ClearPageError(page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = allocate_budget(c, page, ui, appending);
|
|
|
|
|
if (unlikely(err)) {
|
2018-07-12 19:01:57 +08:00
|
|
|
|
ubifs_assert(c, err == -ENOSPC);
|
2009-02-23 18:47:25 +08:00
|
|
|
|
/*
|
|
|
|
|
* If we skipped reading the page because we were going to
|
|
|
|
|
* write all of it, then it is not up to date.
|
|
|
|
|
*/
|
|
|
|
|
if (skipped_read) {
|
|
|
|
|
ClearPageChecked(page);
|
|
|
|
|
ClearPageUptodate(page);
|
|
|
|
|
}
|
2008-07-15 00:08:37 +08:00
|
|
|
|
/*
|
|
|
|
|
* Budgeting failed which means it would have to force
|
|
|
|
|
* write-back but didn't, because we set the @fast flag in the
|
|
|
|
|
* request. Write-back cannot be done now, while we have the
|
|
|
|
|
* page locked, because it would deadlock. Unlock and free
|
|
|
|
|
* everything and fall-back to slow-path.
|
|
|
|
|
*/
|
|
|
|
|
if (appending) {
|
2018-07-12 19:01:57 +08:00
|
|
|
|
ubifs_assert(c, mutex_is_locked(&ui->ui_mutex));
|
2008-07-15 00:08:37 +08:00
|
|
|
|
mutex_unlock(&ui->ui_mutex);
|
|
|
|
|
}
|
|
|
|
|
unlock_page(page);
|
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 20:29:47 +08:00
|
|
|
|
put_page(page);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
2022-02-23 03:31:43 +08:00
|
|
|
|
return write_begin_slow(mapping, pos, len, pagep);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2009-09-01 22:06:43 +08:00
|
|
|
|
* Whee, we acquired budgeting quickly - without involving
|
|
|
|
|
* garbage-collection, committing or forcing write-back. We return
|
2008-07-15 00:08:37 +08:00
|
|
|
|
* with @ui->ui_mutex locked if we are appending pages, and unlocked
|
|
|
|
|
* otherwise. This is an optimization (slightly hacky though).
|
|
|
|
|
*/
|
|
|
|
|
*pagep = page;
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* cancel_budget - cancel budget.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
* @page: page to cancel budget for
|
|
|
|
|
* @ui: UBIFS inode object the page belongs to
|
|
|
|
|
* @appending: non-zero if the page is appended
|
|
|
|
|
*
|
|
|
|
|
* This is a helper function for a page write operation. It unlocks the
|
|
|
|
|
* @ui->ui_mutex in case of appending.
|
|
|
|
|
*/
|
|
|
|
|
static void cancel_budget(struct ubifs_info *c, struct page *page,
|
|
|
|
|
struct ubifs_inode *ui, int appending)
|
|
|
|
|
{
|
|
|
|
|
if (appending) {
|
|
|
|
|
if (!ui->dirty)
|
|
|
|
|
ubifs_release_dirty_inode_budget(c, ui);
|
|
|
|
|
mutex_unlock(&ui->ui_mutex);
|
|
|
|
|
}
|
|
|
|
|
if (!PagePrivate(page)) {
|
|
|
|
|
if (PageChecked(page))
|
|
|
|
|
release_new_page_budget(c);
|
|
|
|
|
else
|
|
|
|
|
release_existing_page_budget(c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int ubifs_write_end(struct file *file, struct address_space *mapping,
|
|
|
|
|
loff_t pos, unsigned len, unsigned copied,
|
|
|
|
|
struct page *page, void *fsdata)
|
|
|
|
|
{
|
|
|
|
|
struct inode *inode = mapping->host;
|
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
|
|
|
|
loff_t end_pos = pos + len;
|
|
|
|
|
int appending = !!(end_pos > inode->i_size);
|
|
|
|
|
|
|
|
|
|
dbg_gen("ino %lu, pos %llu, pg %lu, len %u, copied %d, i_size %lld",
|
|
|
|
|
inode->i_ino, pos, page->index, len, copied, inode->i_size);
|
|
|
|
|
|
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 20:29:47 +08:00
|
|
|
|
if (unlikely(copied < len && len == PAGE_SIZE)) {
|
2008-07-15 00:08:37 +08:00
|
|
|
|
/*
|
|
|
|
|
* VFS copied less data to the page that it intended and
|
|
|
|
|
* declared in its '->write_begin()' call via the @len
|
|
|
|
|
* argument. If the page was not up-to-date, and @len was
|
2016-04-01 20:29:48 +08:00
|
|
|
|
* @PAGE_SIZE, the 'ubifs_write_begin()' function did
|
2008-07-15 00:08:37 +08:00
|
|
|
|
* not load it from the media (for optimization reasons). This
|
|
|
|
|
* means that part of the page contains garbage. So read the
|
|
|
|
|
* page now.
|
|
|
|
|
*/
|
|
|
|
|
dbg_gen("copied %d instead of %d, read page and repeat",
|
|
|
|
|
copied, len);
|
|
|
|
|
cancel_budget(c, page, ui, appending);
|
UBIFS: fix assertion warning and refine comments
This patch fixes the following UBIFS assertion warning:
UBIFS assert failed in do_readpage at 115 (pid 199)
[<b00321b8>] (unwind_backtrace+0x0/0xdc) from [<af025118>]
(do_readpage+0x108/0x594 [ubifs])
[<af025118>] (do_readpage+0x108/0x594 [ubifs]) from [<af025764>]
(ubifs_write_end+0x1c0/0x2e8 [ubifs])
[<af025764>] (ubifs_write_end+0x1c0/0x2e8 [ubifs]) from
[<b00a0164>] (generic_file_buffered_write+0x18c/0x270)
[<b00a0164>] (generic_file_buffered_write+0x18c/0x270) from
[<b00a08d4>] (__generic_file_aio_write+0x478/0x4c0)
[<b00a08d4>] (__generic_file_aio_write+0x478/0x4c0) from
[<b00a0984>] (generic_file_aio_write+0x68/0xc8)
[<b00a0984>] (generic_file_aio_write+0x68/0xc8) from
[<af024a78>] (ubifs_aio_write+0x178/0x1d8 [ubifs])
[<af024a78>] (ubifs_aio_write+0x178/0x1d8 [ubifs]) from
[<b00d104c>] (do_sync_write+0xb0/0x100)
[<b00d104c>] (do_sync_write+0xb0/0x100) from [<b00d1abc>]
(vfs_write+0xac/0x154)
[<b00d1abc>] (vfs_write+0xac/0x154) from [<b00d1c10>]
(sys_write+0x3c/0x68)
[<b00d1c10>] (sys_write+0x3c/0x68) from [<b002d9a0>]
(ret_fast_syscall+0x0/0x2c)
The 'PG_checked' flag is used to indicate that the page does not
supposedly exist on the media (e.g., a hole or a page beyond the
inode size), so it requires slightly bigger budget, because we have
to account the indexing size increase. And this flag basically
tells that the budget for this page has to be "new page budget".
The "new page budget" is slightly bigger than the "existing page
budget".
The 'do_readpage()' function has the following assertion which
sometimes is hit: 'ubifs_assert(!PageChecked(page))'. Obviously,
the meaning of this assertion is: "I should not be asked to read
a page which does not exist on the media".
However, in 'ubifs_write_begin()' we have a small "trick". Notice,
that VFS may write pages which were not read yet, so the page data
were not loaded from the media to the page cache yet. If VFS tells
that it is going to change only some part of the page, we obviously
have to load it from the media. However, if VFS tells that it is
going to change whole page, we do not read it from the media for
optimization purposes.
However, since we do not read it, we do not know if it exists on
the media or not (a hole, etc). So we set the 'PG_checked' flag
to this page to force bigger budget, just in case.
So 'ubifs_write_begin()' sets 'PG_checked'. Then we are in
'ubifs_write_end()'. And VFS tells us: "hey, for some reasons I
changed my mind and did not change whole page". Frankly, I do not
know why this happens, but I hit this somehow on an ARM platform.
And this is extremely rare.
So in this case UBIFS does the following:
1. Cancels allocated budget.
2. Loads the page from the media by calling 'do_readpage()'.
3. Asks VFS to repeat the whole write operation from the very
beginning (call '->write_begin() again, etc).
And the assertion warning is hit at the step 2 - remember we have
the 'PG_checked' set for this page, and 'do_readpage()' does not
like this. So this patch fixes the problem by adding step 1.5 and
cleaning the 'PG_checked' before calling 'do_readpage()'.
All in all, this patch does not fix any functionality issue, but it
silences UBIFS false positive warning which may happen in very very
rare cases.
And while on it, this patch also improves a commentary which explains
the reasons of setting the 'PG_checked' flag for the page. The old
commentary was a bit difficult to understand.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2011-03-23 16:32:58 +08:00
|
|
|
|
ClearPageChecked(page);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Return 0 to force VFS to repeat the whole operation, or the
|
2009-09-01 22:06:43 +08:00
|
|
|
|
* error code if 'do_readpage()' fails.
|
2008-07-15 00:08:37 +08:00
|
|
|
|
*/
|
|
|
|
|
copied = do_readpage(page);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!PagePrivate(page)) {
|
ubifs: Fix to add refcount once page is set private
MM defined the rule [1] very clearly that once page was set with PG_private
flag, we should increment the refcount in that page, also main flows like
pageout(), migrate_page() will assume there is one additional page
reference count if page_has_private() returns true. Otherwise, we may
get a BUG in page migration:
page:0000000080d05b9d refcount:-1 mapcount:0 mapping:000000005f4d82a8
index:0xe2 pfn:0x14c12
aops:ubifs_file_address_operations [ubifs] ino:8f1 dentry name:"f30e"
flags: 0x1fffff80002405(locked|uptodate|owner_priv_1|private|node=0|
zone=1|lastcpupid=0x1fffff)
page dumped because: VM_BUG_ON_PAGE(page_count(page) != 0)
------------[ cut here ]------------
kernel BUG at include/linux/page_ref.h:184!
invalid opcode: 0000 [#1] SMP
CPU: 3 PID: 38 Comm: kcompactd0 Not tainted 5.15.0-rc5
RIP: 0010:migrate_page_move_mapping+0xac3/0xe70
Call Trace:
ubifs_migrate_page+0x22/0xc0 [ubifs]
move_to_new_page+0xb4/0x600
migrate_pages+0x1523/0x1cc0
compact_zone+0x8c5/0x14b0
kcompactd+0x2bc/0x560
kthread+0x18c/0x1e0
ret_from_fork+0x1f/0x30
Before the time, we should make clean a concept, what does refcount means
in page gotten from grab_cache_page_write_begin(). There are 2 situations:
Situation 1: refcount is 3, page is created by __page_cache_alloc.
TYPE_A - the write process is using this page
TYPE_B - page is assigned to one certain mapping by calling
__add_to_page_cache_locked()
TYPE_C - page is added into pagevec list corresponding current cpu by
calling lru_cache_add()
Situation 2: refcount is 2, page is gotten from the mapping's tree
TYPE_B - page has been assigned to one certain mapping
TYPE_A - the write process is using this page (by calling
page_cache_get_speculative())
Filesystem releases one refcount by calling put_page() in xxx_write_end(),
the released refcount corresponds to TYPE_A (write task is using it). If
there are any processes using a page, page migration process will skip the
page by judging whether expected_page_refs() equals to page refcount.
The BUG is caused by following process:
PA(cpu 0) kcompactd(cpu 1)
compact_zone
ubifs_write_begin
page_a = grab_cache_page_write_begin
add_to_page_cache_lru
lru_cache_add
pagevec_add // put page into cpu 0's pagevec
(refcnf = 3, for page creation process)
ubifs_write_end
SetPagePrivate(page_a) // doesn't increase page count !
unlock_page(page_a)
put_page(page_a) // refcnt = 2
[...]
PB(cpu 0)
filemap_read
filemap_get_pages
add_to_page_cache_lru
lru_cache_add
__pagevec_lru_add // traverse all pages in cpu 0's pagevec
__pagevec_lru_add_fn
SetPageLRU(page_a)
isolate_migratepages
isolate_migratepages_block
get_page_unless_zero(page_a)
// refcnt = 3
list_add(page_a, from_list)
migrate_pages(from_list)
__unmap_and_move
move_to_new_page
ubifs_migrate_page(page_a)
migrate_page_move_mapping
expected_page_refs get 3
(migration[1] + mapping[1] + private[1])
release_pages
put_page_testzero(page_a) // refcnt = 3
page_ref_freeze // refcnt = 0
page_ref_dec_and_test(0 - 1 = -1)
page_ref_unfreeze
VM_BUG_ON_PAGE(-1 != 0, page)
UBIFS doesn't increase the page refcount after setting private flag, which
leads to page migration task believes the page is not used by any other
processes, so the page is migrated. This causes concurrent accessing on
page refcount between put_page() called by other process(eg. read process
calls lru_cache_add) and page_ref_unfreeze() called by migration task.
Actually zhangjun has tried to fix this problem [2] by recalculating page
refcnt in ubifs_migrate_page(). It's better to follow MM rules [1], because
just like Kirill suggested in [2], we need to check all users of
page_has_private() helper. Like f2fs does in [3], fix it by adding/deleting
refcount when setting/clearing private for a page. BTW, according to [4],
we set 'page->private' as 1 because ubifs just simply SetPagePrivate().
And, [5] provided a common helper to set/clear page private, ubifs can
use this helper following the example of iomap, afs, btrfs, etc.
Jump [6] to find a reproducer.
[1] https://lore.kernel.org/lkml/2b19b3c4-2bc4-15fa-15cc-27a13e5c7af1@aol.com
[2] https://www.spinics.net/lists/linux-mtd/msg04018.html
[3] http://lkml.iu.edu/hypermail/linux/kernel/1903.0/03313.html
[4] https://lore.kernel.org/linux-f2fs-devel/20210422154705.GO3596236@casper.infradead.org
[5] https://lore.kernel.org/all/20200517214718.468-1-guoqing.jiang@cloud.ionos.com
[6] https://bugzilla.kernel.org/show_bug.cgi?id=214961
Fixes: 1e51764a3c2ac0 ("UBIFS: add new flash file system")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-12-27 11:22:41 +08:00
|
|
|
|
attach_page_private(page, (void *)1);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
atomic_long_inc(&c->dirty_pg_cnt);
|
|
|
|
|
__set_page_dirty_nobuffers(page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (appending) {
|
|
|
|
|
i_size_write(inode, end_pos);
|
|
|
|
|
ui->ui_size = end_pos;
|
|
|
|
|
/*
|
|
|
|
|
* Note, we do not set @I_DIRTY_PAGES (which means that the
|
|
|
|
|
* inode has dirty pages), this has been done in
|
|
|
|
|
* '__set_page_dirty_nobuffers()'.
|
|
|
|
|
*/
|
|
|
|
|
__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
|
2018-07-12 19:01:57 +08:00
|
|
|
|
ubifs_assert(c, mutex_is_locked(&ui->ui_mutex));
|
2008-07-15 00:08:37 +08:00
|
|
|
|
mutex_unlock(&ui->ui_mutex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
unlock_page(page);
|
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 20:29:47 +08:00
|
|
|
|
put_page(page);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
return copied;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-02 21:29:46 +08:00
|
|
|
|
/**
|
|
|
|
|
* populate_page - copy data nodes into a page for bulk-read.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
* @page: page
|
|
|
|
|
* @bu: bulk-read information
|
|
|
|
|
* @n: next zbranch slot
|
|
|
|
|
*
|
|
|
|
|
* This function returns %0 on success and a negative error code on failure.
|
|
|
|
|
*/
|
|
|
|
|
static int populate_page(struct ubifs_info *c, struct page *page,
|
|
|
|
|
struct bu_info *bu, int *n)
|
|
|
|
|
{
|
2008-09-12 15:34:51 +08:00
|
|
|
|
int i = 0, nn = *n, offs = bu->zbranch[0].offs, hole = 0, read = 0;
|
2008-09-02 21:29:46 +08:00
|
|
|
|
struct inode *inode = page->mapping->host;
|
|
|
|
|
loff_t i_size = i_size_read(inode);
|
|
|
|
|
unsigned int page_block;
|
|
|
|
|
void *addr, *zaddr;
|
|
|
|
|
pgoff_t end_index;
|
|
|
|
|
|
|
|
|
|
dbg_gen("ino %lu, pg %lu, i_size %lld, flags %#lx",
|
|
|
|
|
inode->i_ino, page->index, i_size, page->flags);
|
|
|
|
|
|
|
|
|
|
addr = zaddr = kmap(page);
|
|
|
|
|
|
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 20:29:47 +08:00
|
|
|
|
end_index = (i_size - 1) >> PAGE_SHIFT;
|
2008-09-02 21:29:46 +08:00
|
|
|
|
if (!i_size || page->index > end_index) {
|
2008-09-12 15:34:51 +08:00
|
|
|
|
hole = 1;
|
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 20:29:47 +08:00
|
|
|
|
memset(addr, 0, PAGE_SIZE);
|
2008-09-02 21:29:46 +08:00
|
|
|
|
goto out_hole;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
page_block = page->index << UBIFS_BLOCKS_PER_PAGE_SHIFT;
|
|
|
|
|
while (1) {
|
|
|
|
|
int err, len, out_len, dlen;
|
|
|
|
|
|
2008-09-12 15:34:51 +08:00
|
|
|
|
if (nn >= bu->cnt) {
|
|
|
|
|
hole = 1;
|
2008-09-02 21:29:46 +08:00
|
|
|
|
memset(addr, 0, UBIFS_BLOCK_SIZE);
|
2008-09-12 15:34:51 +08:00
|
|
|
|
} else if (key_block(c, &bu->zbranch[nn].key) == page_block) {
|
2008-09-02 21:29:46 +08:00
|
|
|
|
struct ubifs_data_node *dn;
|
|
|
|
|
|
|
|
|
|
dn = bu->buf + (bu->zbranch[nn].offs - offs);
|
|
|
|
|
|
2018-07-12 19:01:57 +08:00
|
|
|
|
ubifs_assert(c, le64_to_cpu(dn->ch.sqnum) >
|
2008-09-02 21:29:46 +08:00
|
|
|
|
ubifs_inode(inode)->creat_sqnum);
|
|
|
|
|
|
|
|
|
|
len = le32_to_cpu(dn->size);
|
|
|
|
|
if (len <= 0 || len > UBIFS_BLOCK_SIZE)
|
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
|
|
dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ;
|
|
|
|
|
out_len = UBIFS_BLOCK_SIZE;
|
2016-09-30 04:20:19 +08:00
|
|
|
|
|
2019-12-10 05:27:21 +08:00
|
|
|
|
if (IS_ENCRYPTED(inode)) {
|
2016-09-30 04:20:19 +08:00
|
|
|
|
err = ubifs_decrypt(inode, dn, &dlen, page_block);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_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 18:39:42 +08:00
|
|
|
|
err = ubifs_decompress(c, &dn->data, dlen, addr, &out_len,
|
2008-09-02 21:29:46 +08:00
|
|
|
|
le16_to_cpu(dn->compr_type));
|
|
|
|
|
if (err || len != out_len)
|
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
|
|
if (len < UBIFS_BLOCK_SIZE)
|
|
|
|
|
memset(addr + len, 0, UBIFS_BLOCK_SIZE - len);
|
|
|
|
|
|
|
|
|
|
nn += 1;
|
|
|
|
|
read = (i << UBIFS_BLOCK_SHIFT) + len;
|
2008-09-12 15:34:51 +08:00
|
|
|
|
} else if (key_block(c, &bu->zbranch[nn].key) < page_block) {
|
|
|
|
|
nn += 1;
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
hole = 1;
|
|
|
|
|
memset(addr, 0, UBIFS_BLOCK_SIZE);
|
2008-09-02 21:29:46 +08:00
|
|
|
|
}
|
|
|
|
|
if (++i >= UBIFS_BLOCKS_PER_PAGE)
|
|
|
|
|
break;
|
|
|
|
|
addr += UBIFS_BLOCK_SIZE;
|
|
|
|
|
page_block += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (end_index == page->index) {
|
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 20:29:47 +08:00
|
|
|
|
int len = i_size & (PAGE_SIZE - 1);
|
2008-09-02 21:29:46 +08:00
|
|
|
|
|
2008-09-05 21:17:42 +08:00
|
|
|
|
if (len && len < read)
|
2008-09-02 21:29:46 +08:00
|
|
|
|
memset(zaddr + len, 0, read - len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out_hole:
|
|
|
|
|
if (hole) {
|
|
|
|
|
SetPageChecked(page);
|
|
|
|
|
dbg_gen("hole");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetPageUptodate(page);
|
|
|
|
|
ClearPageError(page);
|
|
|
|
|
flush_dcache_page(page);
|
|
|
|
|
kunmap(page);
|
|
|
|
|
*n = nn;
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
|
ClearPageUptodate(page);
|
|
|
|
|
SetPageError(page);
|
|
|
|
|
flush_dcache_page(page);
|
|
|
|
|
kunmap(page);
|
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 18:39:42 +08:00
|
|
|
|
ubifs_err(c, "bad data node (block %u, inode %lu)",
|
2008-09-02 21:29:46 +08:00
|
|
|
|
page_block, inode->i_ino);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ubifs_do_bulk_read - do bulk-read.
|
|
|
|
|
* @c: UBIFS file-system description object
|
2008-11-19 02:20:05 +08:00
|
|
|
|
* @bu: bulk-read information
|
|
|
|
|
* @page1: first page to read
|
2008-09-02 21:29:46 +08:00
|
|
|
|
*
|
|
|
|
|
* This function returns %1 if the bulk-read is done, otherwise %0 is returned.
|
|
|
|
|
*/
|
2008-11-19 02:20:05 +08:00
|
|
|
|
static int ubifs_do_bulk_read(struct ubifs_info *c, struct bu_info *bu,
|
|
|
|
|
struct page *page1)
|
2008-09-02 21:29:46 +08:00
|
|
|
|
{
|
|
|
|
|
pgoff_t offset = page1->index, end_index;
|
|
|
|
|
struct address_space *mapping = page1->mapping;
|
|
|
|
|
struct inode *inode = mapping->host;
|
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
|
|
|
|
int err, page_idx, page_cnt, ret = 0, n = 0;
|
2008-11-19 02:20:05 +08:00
|
|
|
|
int allocate = bu->buf ? 0 : 1;
|
2008-09-02 21:29:46 +08:00
|
|
|
|
loff_t isize;
|
2017-06-14 08:31:49 +08:00
|
|
|
|
gfp_t ra_gfp_mask = readahead_gfp_mask(mapping) & ~__GFP_FS;
|
2008-09-02 21:29:46 +08:00
|
|
|
|
|
|
|
|
|
err = ubifs_tnc_get_bu_keys(c, bu);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_warn;
|
|
|
|
|
|
|
|
|
|
if (bu->eof) {
|
|
|
|
|
/* Turn off bulk-read at the end of the file */
|
|
|
|
|
ui->read_in_a_row = 1;
|
|
|
|
|
ui->bulk_read = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
page_cnt = bu->blk_cnt >> UBIFS_BLOCKS_PER_PAGE_SHIFT;
|
|
|
|
|
if (!page_cnt) {
|
|
|
|
|
/*
|
|
|
|
|
* This happens when there are multiple blocks per page and the
|
|
|
|
|
* blocks for the first page we are looking for, are not
|
|
|
|
|
* together. If all the pages were like this, bulk-read would
|
|
|
|
|
* reduce performance, so we turn it off for a while.
|
|
|
|
|
*/
|
2008-11-19 02:20:05 +08:00
|
|
|
|
goto out_bu_off;
|
2008-09-02 21:29:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bu->cnt) {
|
2008-11-19 02:20:05 +08:00
|
|
|
|
if (allocate) {
|
|
|
|
|
/*
|
|
|
|
|
* Allocate bulk-read buffer depending on how many data
|
|
|
|
|
* nodes we are going to read.
|
|
|
|
|
*/
|
|
|
|
|
bu->buf_len = bu->zbranch[bu->cnt - 1].offs +
|
|
|
|
|
bu->zbranch[bu->cnt - 1].len -
|
|
|
|
|
bu->zbranch[0].offs;
|
2018-07-12 19:01:57 +08:00
|
|
|
|
ubifs_assert(c, bu->buf_len > 0);
|
|
|
|
|
ubifs_assert(c, bu->buf_len <= c->leb_size);
|
2008-11-19 02:20:05 +08:00
|
|
|
|
bu->buf = kmalloc(bu->buf_len, GFP_NOFS | __GFP_NOWARN);
|
|
|
|
|
if (!bu->buf)
|
|
|
|
|
goto out_bu_off;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-02 21:29:46 +08:00
|
|
|
|
err = ubifs_tnc_bulk_read(c, bu);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_warn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = populate_page(c, page1, bu, &n);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_warn;
|
|
|
|
|
|
|
|
|
|
unlock_page(page1);
|
|
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
|
|
isize = i_size_read(inode);
|
|
|
|
|
if (isize == 0)
|
|
|
|
|
goto out_free;
|
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 20:29:47 +08:00
|
|
|
|
end_index = ((isize - 1) >> PAGE_SHIFT);
|
2008-09-02 21:29:46 +08:00
|
|
|
|
|
|
|
|
|
for (page_idx = 1; page_idx < page_cnt; page_idx++) {
|
|
|
|
|
pgoff_t page_offset = offset + page_idx;
|
|
|
|
|
struct page *page;
|
|
|
|
|
|
|
|
|
|
if (page_offset > end_index)
|
|
|
|
|
break;
|
2020-01-11 17:50:36 +08:00
|
|
|
|
page = pagecache_get_page(mapping, page_offset,
|
|
|
|
|
FGP_LOCK|FGP_ACCESSED|FGP_CREAT|FGP_NOWAIT,
|
|
|
|
|
ra_gfp_mask);
|
2008-09-02 21:29:46 +08:00
|
|
|
|
if (!page)
|
|
|
|
|
break;
|
|
|
|
|
if (!PageUptodate(page))
|
|
|
|
|
err = populate_page(c, page, bu, &n);
|
|
|
|
|
unlock_page(page);
|
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 20:29:47 +08:00
|
|
|
|
put_page(page);
|
2008-09-02 21:29:46 +08:00
|
|
|
|
if (err)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui->last_page_read = offset + page_idx - 1;
|
|
|
|
|
|
|
|
|
|
out_free:
|
2008-11-19 02:20:05 +08:00
|
|
|
|
if (allocate)
|
|
|
|
|
kfree(bu->buf);
|
2008-09-02 21:29:46 +08:00
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
out_warn:
|
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 18:39:42 +08:00
|
|
|
|
ubifs_warn(c, "ignoring error %d and skipping bulk-read", err);
|
2008-09-02 21:29:46 +08:00
|
|
|
|
goto out_free;
|
2008-11-19 02:20:05 +08:00
|
|
|
|
|
|
|
|
|
out_bu_off:
|
|
|
|
|
ui->read_in_a_row = ui->bulk_read = 0;
|
|
|
|
|
goto out_free;
|
2008-09-02 21:29:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ubifs_bulk_read - determine whether to bulk-read and, if so, do it.
|
|
|
|
|
* @page: page from which to start bulk-read.
|
|
|
|
|
*
|
|
|
|
|
* Some flash media are capable of reading sequentially at faster rates. UBIFS
|
|
|
|
|
* bulk-read facility is designed to take advantage of that, by reading in one
|
|
|
|
|
* go consecutive data nodes that are also located consecutively in the same
|
|
|
|
|
* LEB. This function returns %1 if a bulk-read is done and %0 otherwise.
|
|
|
|
|
*/
|
|
|
|
|
static int ubifs_bulk_read(struct page *page)
|
|
|
|
|
{
|
|
|
|
|
struct inode *inode = page->mapping->host;
|
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
|
|
|
|
pgoff_t index = page->index, last_page_read = ui->last_page_read;
|
2008-11-19 02:20:05 +08:00
|
|
|
|
struct bu_info *bu;
|
2008-11-19 17:53:15 +08:00
|
|
|
|
int err = 0, allocated = 0;
|
2008-09-02 21:29:46 +08:00
|
|
|
|
|
|
|
|
|
ui->last_page_read = index;
|
|
|
|
|
if (!c->bulk_read)
|
|
|
|
|
return 0;
|
2008-11-19 02:20:05 +08:00
|
|
|
|
|
2008-09-02 21:29:46 +08:00
|
|
|
|
/*
|
2008-11-19 17:53:15 +08:00
|
|
|
|
* Bulk-read is protected by @ui->ui_mutex, but it is an optimization,
|
|
|
|
|
* so don't bother if we cannot lock the mutex.
|
2008-09-02 21:29:46 +08:00
|
|
|
|
*/
|
|
|
|
|
if (!mutex_trylock(&ui->ui_mutex))
|
|
|
|
|
return 0;
|
2008-11-19 02:20:05 +08:00
|
|
|
|
|
2008-09-02 21:29:46 +08:00
|
|
|
|
if (index != last_page_read + 1) {
|
|
|
|
|
/* Turn off bulk-read if we stop reading sequentially */
|
|
|
|
|
ui->read_in_a_row = 1;
|
|
|
|
|
if (ui->bulk_read)
|
|
|
|
|
ui->bulk_read = 0;
|
|
|
|
|
goto out_unlock;
|
|
|
|
|
}
|
2008-11-19 02:20:05 +08:00
|
|
|
|
|
2008-09-02 21:29:46 +08:00
|
|
|
|
if (!ui->bulk_read) {
|
|
|
|
|
ui->read_in_a_row += 1;
|
|
|
|
|
if (ui->read_in_a_row < 3)
|
|
|
|
|
goto out_unlock;
|
|
|
|
|
/* Three reads in a row, so switch on bulk-read */
|
|
|
|
|
ui->bulk_read = 1;
|
|
|
|
|
}
|
2008-11-19 02:20:05 +08:00
|
|
|
|
|
2008-11-19 17:53:15 +08:00
|
|
|
|
/*
|
|
|
|
|
* If possible, try to use pre-allocated bulk-read information, which
|
|
|
|
|
* is protected by @c->bu_mutex.
|
|
|
|
|
*/
|
|
|
|
|
if (mutex_trylock(&c->bu_mutex))
|
|
|
|
|
bu = &c->bu;
|
|
|
|
|
else {
|
|
|
|
|
bu = kmalloc(sizeof(struct bu_info), GFP_NOFS | __GFP_NOWARN);
|
|
|
|
|
if (!bu)
|
|
|
|
|
goto out_unlock;
|
|
|
|
|
|
|
|
|
|
bu->buf = NULL;
|
|
|
|
|
allocated = 1;
|
|
|
|
|
}
|
2008-11-19 02:20:05 +08:00
|
|
|
|
|
|
|
|
|
bu->buf_len = c->max_bu_buf_len;
|
|
|
|
|
data_key_init(c, &bu->key, inode->i_ino,
|
|
|
|
|
page->index << UBIFS_BLOCKS_PER_PAGE_SHIFT);
|
|
|
|
|
err = ubifs_do_bulk_read(c, bu, page);
|
2008-11-19 17:53:15 +08:00
|
|
|
|
|
|
|
|
|
if (!allocated)
|
|
|
|
|
mutex_unlock(&c->bu_mutex);
|
|
|
|
|
else
|
|
|
|
|
kfree(bu);
|
2008-11-19 02:20:05 +08:00
|
|
|
|
|
2008-09-02 21:29:46 +08:00
|
|
|
|
out_unlock:
|
|
|
|
|
mutex_unlock(&ui->ui_mutex);
|
2008-11-19 02:20:05 +08:00
|
|
|
|
return err;
|
2008-09-02 21:29:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-29 23:12:16 +08:00
|
|
|
|
static int ubifs_read_folio(struct file *file, struct folio *folio)
|
2008-07-15 00:08:37 +08:00
|
|
|
|
{
|
2022-04-29 23:12:16 +08:00
|
|
|
|
struct page *page = &folio->page;
|
|
|
|
|
|
2008-09-02 21:29:46 +08:00
|
|
|
|
if (ubifs_bulk_read(page))
|
|
|
|
|
return 0;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
do_readpage(page);
|
2022-04-29 23:12:16 +08:00
|
|
|
|
folio_unlock(folio);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int do_writepage(struct page *page, int len)
|
|
|
|
|
{
|
|
|
|
|
int err = 0, i, blen;
|
|
|
|
|
unsigned int block;
|
|
|
|
|
void *addr;
|
|
|
|
|
union ubifs_key key;
|
|
|
|
|
struct inode *inode = page->mapping->host;
|
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
|
|
|
|
|
|
|
|
|
#ifdef UBIFS_DEBUG
|
2014-05-14 04:27:58 +08:00
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
spin_lock(&ui->ui_lock);
|
2018-07-12 19:01:57 +08:00
|
|
|
|
ubifs_assert(c, page->index <= ui->synced_i_size >> PAGE_SHIFT);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
spin_unlock(&ui->ui_lock);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Update radix tree tags */
|
|
|
|
|
set_page_writeback(page);
|
|
|
|
|
|
|
|
|
|
addr = kmap(page);
|
|
|
|
|
block = page->index << UBIFS_BLOCKS_PER_PAGE_SHIFT;
|
|
|
|
|
i = 0;
|
|
|
|
|
while (len) {
|
|
|
|
|
blen = min_t(int, len, UBIFS_BLOCK_SIZE);
|
|
|
|
|
data_key_init(c, &key, inode->i_ino, block);
|
|
|
|
|
err = ubifs_jnl_write_data(c, inode, &key, addr, blen);
|
|
|
|
|
if (err)
|
|
|
|
|
break;
|
|
|
|
|
if (++i >= UBIFS_BLOCKS_PER_PAGE)
|
|
|
|
|
break;
|
|
|
|
|
block += 1;
|
|
|
|
|
addr += blen;
|
|
|
|
|
len -= blen;
|
|
|
|
|
}
|
|
|
|
|
if (err) {
|
|
|
|
|
SetPageError(page);
|
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 18:39:42 +08:00
|
|
|
|
ubifs_err(c, "cannot write page %lu of inode %lu, error %d",
|
2008-07-15 00:08:37 +08:00
|
|
|
|
page->index, inode->i_ino, err);
|
|
|
|
|
ubifs_ro_mode(c, err);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 19:01:57 +08:00
|
|
|
|
ubifs_assert(c, PagePrivate(page));
|
2008-07-15 00:08:37 +08:00
|
|
|
|
if (PageChecked(page))
|
|
|
|
|
release_new_page_budget(c);
|
|
|
|
|
else
|
|
|
|
|
release_existing_page_budget(c);
|
|
|
|
|
|
|
|
|
|
atomic_long_dec(&c->dirty_pg_cnt);
|
ubifs: Fix to add refcount once page is set private
MM defined the rule [1] very clearly that once page was set with PG_private
flag, we should increment the refcount in that page, also main flows like
pageout(), migrate_page() will assume there is one additional page
reference count if page_has_private() returns true. Otherwise, we may
get a BUG in page migration:
page:0000000080d05b9d refcount:-1 mapcount:0 mapping:000000005f4d82a8
index:0xe2 pfn:0x14c12
aops:ubifs_file_address_operations [ubifs] ino:8f1 dentry name:"f30e"
flags: 0x1fffff80002405(locked|uptodate|owner_priv_1|private|node=0|
zone=1|lastcpupid=0x1fffff)
page dumped because: VM_BUG_ON_PAGE(page_count(page) != 0)
------------[ cut here ]------------
kernel BUG at include/linux/page_ref.h:184!
invalid opcode: 0000 [#1] SMP
CPU: 3 PID: 38 Comm: kcompactd0 Not tainted 5.15.0-rc5
RIP: 0010:migrate_page_move_mapping+0xac3/0xe70
Call Trace:
ubifs_migrate_page+0x22/0xc0 [ubifs]
move_to_new_page+0xb4/0x600
migrate_pages+0x1523/0x1cc0
compact_zone+0x8c5/0x14b0
kcompactd+0x2bc/0x560
kthread+0x18c/0x1e0
ret_from_fork+0x1f/0x30
Before the time, we should make clean a concept, what does refcount means
in page gotten from grab_cache_page_write_begin(). There are 2 situations:
Situation 1: refcount is 3, page is created by __page_cache_alloc.
TYPE_A - the write process is using this page
TYPE_B - page is assigned to one certain mapping by calling
__add_to_page_cache_locked()
TYPE_C - page is added into pagevec list corresponding current cpu by
calling lru_cache_add()
Situation 2: refcount is 2, page is gotten from the mapping's tree
TYPE_B - page has been assigned to one certain mapping
TYPE_A - the write process is using this page (by calling
page_cache_get_speculative())
Filesystem releases one refcount by calling put_page() in xxx_write_end(),
the released refcount corresponds to TYPE_A (write task is using it). If
there are any processes using a page, page migration process will skip the
page by judging whether expected_page_refs() equals to page refcount.
The BUG is caused by following process:
PA(cpu 0) kcompactd(cpu 1)
compact_zone
ubifs_write_begin
page_a = grab_cache_page_write_begin
add_to_page_cache_lru
lru_cache_add
pagevec_add // put page into cpu 0's pagevec
(refcnf = 3, for page creation process)
ubifs_write_end
SetPagePrivate(page_a) // doesn't increase page count !
unlock_page(page_a)
put_page(page_a) // refcnt = 2
[...]
PB(cpu 0)
filemap_read
filemap_get_pages
add_to_page_cache_lru
lru_cache_add
__pagevec_lru_add // traverse all pages in cpu 0's pagevec
__pagevec_lru_add_fn
SetPageLRU(page_a)
isolate_migratepages
isolate_migratepages_block
get_page_unless_zero(page_a)
// refcnt = 3
list_add(page_a, from_list)
migrate_pages(from_list)
__unmap_and_move
move_to_new_page
ubifs_migrate_page(page_a)
migrate_page_move_mapping
expected_page_refs get 3
(migration[1] + mapping[1] + private[1])
release_pages
put_page_testzero(page_a) // refcnt = 3
page_ref_freeze // refcnt = 0
page_ref_dec_and_test(0 - 1 = -1)
page_ref_unfreeze
VM_BUG_ON_PAGE(-1 != 0, page)
UBIFS doesn't increase the page refcount after setting private flag, which
leads to page migration task believes the page is not used by any other
processes, so the page is migrated. This causes concurrent accessing on
page refcount between put_page() called by other process(eg. read process
calls lru_cache_add) and page_ref_unfreeze() called by migration task.
Actually zhangjun has tried to fix this problem [2] by recalculating page
refcnt in ubifs_migrate_page(). It's better to follow MM rules [1], because
just like Kirill suggested in [2], we need to check all users of
page_has_private() helper. Like f2fs does in [3], fix it by adding/deleting
refcount when setting/clearing private for a page. BTW, according to [4],
we set 'page->private' as 1 because ubifs just simply SetPagePrivate().
And, [5] provided a common helper to set/clear page private, ubifs can
use this helper following the example of iomap, afs, btrfs, etc.
Jump [6] to find a reproducer.
[1] https://lore.kernel.org/lkml/2b19b3c4-2bc4-15fa-15cc-27a13e5c7af1@aol.com
[2] https://www.spinics.net/lists/linux-mtd/msg04018.html
[3] http://lkml.iu.edu/hypermail/linux/kernel/1903.0/03313.html
[4] https://lore.kernel.org/linux-f2fs-devel/20210422154705.GO3596236@casper.infradead.org
[5] https://lore.kernel.org/all/20200517214718.468-1-guoqing.jiang@cloud.ionos.com
[6] https://bugzilla.kernel.org/show_bug.cgi?id=214961
Fixes: 1e51764a3c2ac0 ("UBIFS: add new flash file system")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-12-27 11:22:41 +08:00
|
|
|
|
detach_page_private(page);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
ClearPageChecked(page);
|
|
|
|
|
|
|
|
|
|
kunmap(page);
|
|
|
|
|
unlock_page(page);
|
|
|
|
|
end_page_writeback(page);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* When writing-back dirty inodes, VFS first writes-back pages belonging to the
|
|
|
|
|
* inode, then the inode itself. For UBIFS this may cause a problem. Consider a
|
|
|
|
|
* situation when a we have an inode with size 0, then a megabyte of data is
|
|
|
|
|
* appended to the inode, then write-back starts and flushes some amount of the
|
|
|
|
|
* dirty pages, the journal becomes full, commit happens and finishes, and then
|
|
|
|
|
* an unclean reboot happens. When the file system is mounted next time, the
|
|
|
|
|
* inode size would still be 0, but there would be many pages which are beyond
|
|
|
|
|
* the inode size, they would be indexed and consume flash space. Because the
|
|
|
|
|
* journal has been committed, the replay would not be able to detect this
|
|
|
|
|
* situation and correct the inode size. This means UBIFS would have to scan
|
|
|
|
|
* whole index and correct all inode sizes, which is long an unacceptable.
|
|
|
|
|
*
|
|
|
|
|
* To prevent situations like this, UBIFS writes pages back only if they are
|
2009-03-21 01:11:12 +08:00
|
|
|
|
* within the last synchronized inode size, i.e. the size which has been
|
2008-07-15 00:08:37 +08:00
|
|
|
|
* written to the flash media last time. Otherwise, UBIFS forces inode
|
|
|
|
|
* write-back, thus making sure the on-flash inode contains current inode size,
|
|
|
|
|
* and then keeps writing pages back.
|
|
|
|
|
*
|
|
|
|
|
* Some locking issues explanation. 'ubifs_writepage()' first is called with
|
|
|
|
|
* the page locked, and it locks @ui_mutex. However, write-back does take inode
|
|
|
|
|
* @i_mutex, which means other VFS operations may be run on this inode at the
|
|
|
|
|
* same time. And the problematic one is truncation to smaller size, from where
|
2011-03-25 21:27:40 +08:00
|
|
|
|
* we have to call 'truncate_setsize()', which first changes @inode->i_size,
|
|
|
|
|
* then drops the truncated pages. And while dropping the pages, it takes the
|
|
|
|
|
* page lock. This means that 'do_truncation()' cannot call 'truncate_setsize()'
|
|
|
|
|
* with @ui_mutex locked, because it would deadlock with 'ubifs_writepage()'.
|
|
|
|
|
* This means that @inode->i_size is changed while @ui_mutex is unlocked.
|
2008-07-15 00:08:37 +08:00
|
|
|
|
*
|
2010-06-04 17:30:04 +08:00
|
|
|
|
* XXX(truncate): with the new truncate sequence this is not true anymore,
|
|
|
|
|
* and the calls to truncate_setsize can be move around freely. They should
|
|
|
|
|
* be moved to the very end of the truncate sequence.
|
2010-05-26 23:05:34 +08:00
|
|
|
|
*
|
2008-07-15 00:08:37 +08:00
|
|
|
|
* But in 'ubifs_writepage()' we have to guarantee that we do not write beyond
|
|
|
|
|
* inode size. How do we do this if @inode->i_size may became smaller while we
|
|
|
|
|
* are in the middle of 'ubifs_writepage()'? The UBIFS solution is the
|
|
|
|
|
* @ui->ui_isize "shadow" field which UBIFS uses instead of @inode->i_size
|
|
|
|
|
* internally and updates it under @ui_mutex.
|
|
|
|
|
*
|
|
|
|
|
* Q: why we do not worry that if we race with truncation, we may end up with a
|
|
|
|
|
* situation when the inode is truncated while we are in the middle of
|
|
|
|
|
* 'do_writepage()', so we do write beyond inode size?
|
|
|
|
|
* A: If we are in the middle of 'do_writepage()', truncation would be locked
|
|
|
|
|
* on the page lock and it would not write the truncated inode node to the
|
|
|
|
|
* journal before we have finished.
|
|
|
|
|
*/
|
|
|
|
|
static int ubifs_writepage(struct page *page, struct writeback_control *wbc)
|
|
|
|
|
{
|
|
|
|
|
struct inode *inode = page->mapping->host;
|
2018-07-12 19:01:57 +08:00
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
|
|
|
|
loff_t i_size = i_size_read(inode), synced_i_size;
|
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 20:29:47 +08:00
|
|
|
|
pgoff_t end_index = i_size >> PAGE_SHIFT;
|
|
|
|
|
int err, len = i_size & (PAGE_SIZE - 1);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
void *kaddr;
|
|
|
|
|
|
|
|
|
|
dbg_gen("ino %lu, pg %lu, pg flags %#lx",
|
|
|
|
|
inode->i_ino, page->index, page->flags);
|
2018-07-12 19:01:57 +08:00
|
|
|
|
ubifs_assert(c, PagePrivate(page));
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
|
|
|
|
/* Is the page fully outside @i_size? (truncate in progress) */
|
|
|
|
|
if (page->index > end_index || (page->index == end_index && !len)) {
|
|
|
|
|
err = 0;
|
|
|
|
|
goto out_unlock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spin_lock(&ui->ui_lock);
|
|
|
|
|
synced_i_size = ui->synced_i_size;
|
|
|
|
|
spin_unlock(&ui->ui_lock);
|
|
|
|
|
|
|
|
|
|
/* Is the page fully inside @i_size? */
|
|
|
|
|
if (page->index < end_index) {
|
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 20:29:47 +08:00
|
|
|
|
if (page->index >= synced_i_size >> PAGE_SHIFT) {
|
2010-03-05 16:21:37 +08:00
|
|
|
|
err = inode->i_sb->s_op->write_inode(inode, NULL);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
if (err)
|
|
|
|
|
goto out_unlock;
|
|
|
|
|
/*
|
|
|
|
|
* The inode has been written, but the write-buffer has
|
|
|
|
|
* not been synchronized, so in case of an unclean
|
|
|
|
|
* reboot we may end up with some pages beyond inode
|
|
|
|
|
* size, but they would be in the journal (because
|
|
|
|
|
* commit flushes write buffers) and recovery would deal
|
|
|
|
|
* with this.
|
|
|
|
|
*/
|
|
|
|
|
}
|
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 20:29:47 +08:00
|
|
|
|
return do_writepage(page, PAGE_SIZE);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The page straddles @i_size. It must be zeroed out on each and every
|
|
|
|
|
* writepage invocation because it may be mmapped. "A file is mapped
|
|
|
|
|
* in multiples of the page size. For a file that is not a multiple of
|
|
|
|
|
* the page size, the remaining memory is zeroed when mapped, and
|
|
|
|
|
* writes to that region are not written out to the file."
|
|
|
|
|
*/
|
2011-11-25 23:14:36 +08:00
|
|
|
|
kaddr = kmap_atomic(page);
|
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 20:29:47 +08:00
|
|
|
|
memset(kaddr + len, 0, PAGE_SIZE - len);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
flush_dcache_page(page);
|
2011-11-25 23:14:36 +08:00
|
|
|
|
kunmap_atomic(kaddr);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
|
|
|
|
if (i_size > synced_i_size) {
|
2010-03-05 16:21:37 +08:00
|
|
|
|
err = inode->i_sb->s_op->write_inode(inode, NULL);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
if (err)
|
|
|
|
|
goto out_unlock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return do_writepage(page, len);
|
|
|
|
|
|
|
|
|
|
out_unlock:
|
|
|
|
|
unlock_page(page);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* do_attr_changes - change inode attributes.
|
|
|
|
|
* @inode: inode to change attributes for
|
|
|
|
|
* @attr: describes attributes to change
|
|
|
|
|
*/
|
|
|
|
|
static void do_attr_changes(struct inode *inode, const struct iattr *attr)
|
|
|
|
|
{
|
|
|
|
|
if (attr->ia_valid & ATTR_UID)
|
|
|
|
|
inode->i_uid = attr->ia_uid;
|
|
|
|
|
if (attr->ia_valid & ATTR_GID)
|
|
|
|
|
inode->i_gid = attr->ia_gid;
|
2019-11-25 03:31:45 +08:00
|
|
|
|
if (attr->ia_valid & ATTR_ATIME)
|
|
|
|
|
inode->i_atime = attr->ia_atime;
|
|
|
|
|
if (attr->ia_valid & ATTR_MTIME)
|
|
|
|
|
inode->i_mtime = attr->ia_mtime;
|
|
|
|
|
if (attr->ia_valid & ATTR_CTIME)
|
|
|
|
|
inode->i_ctime = attr->ia_ctime;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
if (attr->ia_valid & ATTR_MODE) {
|
|
|
|
|
umode_t mode = attr->ia_mode;
|
|
|
|
|
|
|
|
|
|
if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
|
|
|
|
|
mode &= ~S_ISGID;
|
|
|
|
|
inode->i_mode = mode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* do_truncation - truncate an inode.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
* @inode: inode to truncate
|
|
|
|
|
* @attr: inode attribute changes description
|
|
|
|
|
*
|
|
|
|
|
* This function implements VFS '->setattr()' call when the inode is truncated
|
|
|
|
|
* to a smaller size. Returns zero in case of success and a negative error code
|
|
|
|
|
* in case of failure.
|
|
|
|
|
*/
|
|
|
|
|
static int do_truncation(struct ubifs_info *c, struct inode *inode,
|
|
|
|
|
const struct iattr *attr)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
struct ubifs_budget_req req;
|
|
|
|
|
loff_t old_size = inode->i_size, new_size = attr->ia_size;
|
2008-08-20 22:16:34 +08:00
|
|
|
|
int offset = new_size & (UBIFS_BLOCK_SIZE - 1), budgeted = 1;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
|
|
|
|
|
|
|
|
|
dbg_gen("ino %lu, size %lld -> %lld", inode->i_ino, old_size, new_size);
|
|
|
|
|
memset(&req, 0, sizeof(struct ubifs_budget_req));
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If this is truncation to a smaller size, and we do not truncate on a
|
|
|
|
|
* block boundary, budget for changing one data block, because the last
|
|
|
|
|
* block will be re-written.
|
|
|
|
|
*/
|
|
|
|
|
if (new_size & (UBIFS_BLOCK_SIZE - 1))
|
|
|
|
|
req.dirtied_page = 1;
|
|
|
|
|
|
|
|
|
|
req.dirtied_ino = 1;
|
|
|
|
|
/* A funny way to budget for truncation node */
|
|
|
|
|
req.dirtied_ino_d = UBIFS_TRUN_NODE_SZ;
|
|
|
|
|
err = ubifs_budget_space(c, &req);
|
2008-08-20 22:16:34 +08:00
|
|
|
|
if (err) {
|
|
|
|
|
/*
|
|
|
|
|
* Treat truncations to zero as deletion and always allow them,
|
|
|
|
|
* just like we do for '->unlink()'.
|
|
|
|
|
*/
|
|
|
|
|
if (new_size || err != -ENOSPC)
|
|
|
|
|
return err;
|
|
|
|
|
budgeted = 0;
|
|
|
|
|
}
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
2010-06-04 17:30:04 +08:00
|
|
|
|
truncate_setsize(inode, new_size);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
|
|
|
|
if (offset) {
|
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 20:29:47 +08:00
|
|
|
|
pgoff_t index = new_size >> PAGE_SHIFT;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
struct page *page;
|
|
|
|
|
|
|
|
|
|
page = find_lock_page(inode->i_mapping, index);
|
|
|
|
|
if (page) {
|
|
|
|
|
if (PageDirty(page)) {
|
|
|
|
|
/*
|
|
|
|
|
* 'ubifs_jnl_truncate()' will try to truncate
|
|
|
|
|
* the last data node, but it contains
|
|
|
|
|
* out-of-date data because the page is dirty.
|
|
|
|
|
* Write the page now, so that
|
|
|
|
|
* 'ubifs_jnl_truncate()' will see an already
|
|
|
|
|
* truncated (and up to date) data node.
|
|
|
|
|
*/
|
2018-07-12 19:01:57 +08:00
|
|
|
|
ubifs_assert(c, PagePrivate(page));
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
|
|
|
|
clear_page_dirty_for_io(page);
|
|
|
|
|
if (UBIFS_BLOCKS_PER_PAGE_SHIFT)
|
|
|
|
|
offset = new_size &
|
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 20:29:47 +08:00
|
|
|
|
(PAGE_SIZE - 1);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
err = do_writepage(page, offset);
|
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 20:29:47 +08:00
|
|
|
|
put_page(page);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
if (err)
|
|
|
|
|
goto out_budg;
|
|
|
|
|
/*
|
|
|
|
|
* We could now tell 'ubifs_jnl_truncate()' not
|
|
|
|
|
* to read the last block.
|
|
|
|
|
*/
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* We could 'kmap()' the page and pass the data
|
|
|
|
|
* to 'ubifs_jnl_truncate()' to save it from
|
|
|
|
|
* having to read it.
|
|
|
|
|
*/
|
|
|
|
|
unlock_page(page);
|
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 20:29:47 +08:00
|
|
|
|
put_page(page);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mutex_lock(&ui->ui_mutex);
|
|
|
|
|
ui->ui_size = inode->i_size;
|
|
|
|
|
/* Truncation changes inode [mc]time */
|
2017-05-09 06:59:25 +08:00
|
|
|
|
inode->i_mtime = inode->i_ctime = current_time(inode);
|
2009-09-01 22:06:43 +08:00
|
|
|
|
/* Other attributes may be changed at the same time as well */
|
2008-07-15 00:08:37 +08:00
|
|
|
|
do_attr_changes(inode, attr);
|
|
|
|
|
err = ubifs_jnl_truncate(c, inode, old_size, new_size);
|
|
|
|
|
mutex_unlock(&ui->ui_mutex);
|
2009-09-01 22:06:43 +08:00
|
|
|
|
|
2008-07-15 00:08:37 +08:00
|
|
|
|
out_budg:
|
2008-08-20 22:16:34 +08:00
|
|
|
|
if (budgeted)
|
|
|
|
|
ubifs_release_budget(c, &req);
|
|
|
|
|
else {
|
2011-03-29 23:04:05 +08:00
|
|
|
|
c->bi.nospace = c->bi.nospace_rp = 0;
|
2008-08-20 22:16:34 +08:00
|
|
|
|
smp_wmb();
|
|
|
|
|
}
|
2008-07-15 00:08:37 +08:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* do_setattr - change inode attributes.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
* @inode: inode to change attributes for
|
|
|
|
|
* @attr: inode attribute changes description
|
|
|
|
|
*
|
|
|
|
|
* This function implements VFS '->setattr()' call for all cases except
|
|
|
|
|
* truncations to smaller size. Returns zero in case of success and a negative
|
|
|
|
|
* error code in case of failure.
|
|
|
|
|
*/
|
|
|
|
|
static int do_setattr(struct ubifs_info *c, struct inode *inode,
|
|
|
|
|
const struct iattr *attr)
|
|
|
|
|
{
|
|
|
|
|
int err, release;
|
|
|
|
|
loff_t new_size = attr->ia_size;
|
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
|
|
|
|
struct ubifs_budget_req req = { .dirtied_ino = 1,
|
2008-07-24 19:52:45 +08:00
|
|
|
|
.dirtied_ino_d = ALIGN(ui->data_len, 8) };
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
|
|
|
|
err = ubifs_budget_space(c, &req);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
if (attr->ia_valid & ATTR_SIZE) {
|
|
|
|
|
dbg_gen("size %lld -> %lld", inode->i_size, new_size);
|
2010-06-04 17:30:04 +08:00
|
|
|
|
truncate_setsize(inode, new_size);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mutex_lock(&ui->ui_mutex);
|
|
|
|
|
if (attr->ia_valid & ATTR_SIZE) {
|
|
|
|
|
/* Truncation changes inode [mc]time */
|
2017-05-09 06:59:25 +08:00
|
|
|
|
inode->i_mtime = inode->i_ctime = current_time(inode);
|
2010-06-04 17:30:04 +08:00
|
|
|
|
/* 'truncate_setsize()' changed @i_size, update @ui_size */
|
2008-07-15 00:08:37 +08:00
|
|
|
|
ui->ui_size = inode->i_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do_attr_changes(inode, attr);
|
|
|
|
|
|
|
|
|
|
release = ui->dirty;
|
|
|
|
|
if (attr->ia_valid & ATTR_SIZE)
|
|
|
|
|
/*
|
|
|
|
|
* Inode length changed, so we have to make sure
|
|
|
|
|
* @I_DIRTY_DATASYNC is set.
|
|
|
|
|
*/
|
2018-02-21 23:54:48 +08:00
|
|
|
|
__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
else
|
|
|
|
|
mark_inode_dirty_sync(inode);
|
|
|
|
|
mutex_unlock(&ui->ui_mutex);
|
|
|
|
|
|
|
|
|
|
if (release)
|
|
|
|
|
ubifs_release_budget(c, &req);
|
|
|
|
|
if (IS_SYNC(inode))
|
2010-03-05 16:21:37 +08:00
|
|
|
|
err = inode->i_sb->s_op->write_inode(inode, NULL);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-21 21:19:43 +08:00
|
|
|
|
int ubifs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
|
|
|
|
|
struct iattr *attr)
|
2008-07-15 00:08:37 +08:00
|
|
|
|
{
|
|
|
|
|
int err;
|
2015-03-18 06:25:59 +08:00
|
|
|
|
struct inode *inode = d_inode(dentry);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
|
|
|
|
|
2008-07-18 23:54:29 +08:00
|
|
|
|
dbg_gen("ino %lu, mode %#x, ia_valid %#x",
|
|
|
|
|
inode->i_ino, inode->i_mode, attr->ia_valid);
|
2021-01-21 21:19:26 +08:00
|
|
|
|
err = setattr_prepare(&init_user_ns, dentry, attr);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
2011-05-31 23:14:38 +08:00
|
|
|
|
err = dbg_check_synced_i_size(c, inode);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
2017-11-30 04:43:17 +08:00
|
|
|
|
err = fscrypt_prepare_setattr(dentry, attr);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
2017-06-14 07:47:55 +08:00
|
|
|
|
|
2008-07-15 00:08:37 +08:00
|
|
|
|
if ((attr->ia_valid & ATTR_SIZE) && attr->ia_size < inode->i_size)
|
|
|
|
|
/* Truncation to a smaller size */
|
|
|
|
|
err = do_truncation(c, inode, attr);
|
|
|
|
|
else
|
|
|
|
|
err = do_setattr(c, inode, attr);
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 04:21:50 +08:00
|
|
|
|
static void ubifs_invalidate_folio(struct folio *folio, size_t offset,
|
|
|
|
|
size_t length)
|
2008-07-15 00:08:37 +08:00
|
|
|
|
{
|
2022-02-10 04:21:50 +08:00
|
|
|
|
struct inode *inode = folio->mapping->host;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
|
|
|
|
|
2022-02-10 04:21:50 +08:00
|
|
|
|
ubifs_assert(c, folio_test_private(folio));
|
|
|
|
|
if (offset || length < folio_size(folio))
|
|
|
|
|
/* Partial folio remains dirty */
|
2008-07-15 00:08:37 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2022-02-10 04:21:50 +08:00
|
|
|
|
if (folio_test_checked(folio))
|
2008-07-15 00:08:37 +08:00
|
|
|
|
release_new_page_budget(c);
|
|
|
|
|
else
|
|
|
|
|
release_existing_page_budget(c);
|
|
|
|
|
|
|
|
|
|
atomic_long_dec(&c->dirty_pg_cnt);
|
2022-04-01 07:09:41 +08:00
|
|
|
|
folio_detach_private(folio);
|
2022-02-10 04:21:50 +08:00
|
|
|
|
folio_clear_checked(folio);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-07-17 08:44:56 +08:00
|
|
|
|
int ubifs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
|
2008-07-15 00:08:37 +08:00
|
|
|
|
{
|
2010-05-26 23:53:25 +08:00
|
|
|
|
struct inode *inode = file->f_mapping->host;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
dbg_gen("syncing inode %lu", inode->i_ino);
|
|
|
|
|
|
2011-04-21 20:11:33 +08:00
|
|
|
|
if (c->ro_mount)
|
|
|
|
|
/*
|
|
|
|
|
* For some really strange reasons VFS does not filter out
|
|
|
|
|
* 'fsync()' for R/O mounted file-systems as per 2.6.39.
|
|
|
|
|
*/
|
2011-04-13 15:31:52 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
2017-07-08 03:20:52 +08:00
|
|
|
|
err = file_write_and_wait_range(file, start, end);
|
2011-07-17 08:44:56 +08:00
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
2016-01-23 04:40:57 +08:00
|
|
|
|
inode_lock(inode);
|
2011-07-17 08:44:56 +08:00
|
|
|
|
|
|
|
|
|
/* Synchronize the inode unless this is a 'datasync()' call. */
|
2008-07-15 00:08:37 +08:00
|
|
|
|
if (!datasync || (inode->i_state & I_DIRTY_DATASYNC)) {
|
2010-03-05 16:21:37 +08:00
|
|
|
|
err = inode->i_sb->s_op->write_inode(inode, NULL);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
if (err)
|
2011-07-17 08:44:56 +08:00
|
|
|
|
goto out;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Nodes related to this inode may still sit in a write-buffer. Flush
|
|
|
|
|
* them.
|
|
|
|
|
*/
|
|
|
|
|
err = ubifs_sync_wbufs_by_inode(c, inode);
|
2011-07-17 08:44:56 +08:00
|
|
|
|
out:
|
2016-01-23 04:40:57 +08:00
|
|
|
|
inode_unlock(inode);
|
2011-07-17 08:44:56 +08:00
|
|
|
|
return err;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* mctime_update_needed - check if mtime or ctime update is needed.
|
|
|
|
|
* @inode: the inode to do the check for
|
|
|
|
|
* @now: current time
|
|
|
|
|
*
|
|
|
|
|
* This helper function checks if the inode mtime/ctime should be updated or
|
|
|
|
|
* not. If current values of the time-stamps are within the UBIFS inode time
|
|
|
|
|
* granularity, they are not updated. This is an optimization.
|
|
|
|
|
*/
|
|
|
|
|
static inline int mctime_update_needed(const struct inode *inode,
|
2018-07-13 22:31:55 +08:00
|
|
|
|
const struct timespec64 *now)
|
2008-07-15 00:08:37 +08:00
|
|
|
|
{
|
2018-07-13 22:31:55 +08:00
|
|
|
|
if (!timespec64_equal(&inode->i_mtime, now) ||
|
|
|
|
|
!timespec64_equal(&inode->i_ctime, now))
|
2008-07-15 00:08:37 +08:00
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-07 12:46:11 +08:00
|
|
|
|
/**
|
|
|
|
|
* ubifs_update_time - update time of inode.
|
|
|
|
|
* @inode: inode to update
|
|
|
|
|
*
|
|
|
|
|
* This function updates time of the inode.
|
|
|
|
|
*/
|
vfs: change inode times to use struct timespec64
struct timespec is not y2038 safe. Transition vfs to use
y2038 safe struct timespec64 instead.
The change was made with the help of the following cocinelle
script. This catches about 80% of the changes.
All the header file and logic changes are included in the
first 5 rules. The rest are trivial substitutions.
I avoid changing any of the function signatures or any other
filesystem specific data structures to keep the patch simple
for review.
The script can be a little shorter by combining different cases.
But, this version was sufficient for my usecase.
virtual patch
@ depends on patch @
identifier now;
@@
- struct timespec
+ struct timespec64
current_time ( ... )
{
- struct timespec now = current_kernel_time();
+ struct timespec64 now = current_kernel_time64();
...
- return timespec_trunc(
+ return timespec64_trunc(
... );
}
@ depends on patch @
identifier xtime;
@@
struct \( iattr \| inode \| kstat \) {
...
- struct timespec xtime;
+ struct timespec64 xtime;
...
}
@ depends on patch @
identifier t;
@@
struct inode_operations {
...
int (*update_time) (...,
- struct timespec t,
+ struct timespec64 t,
...);
...
}
@ depends on patch @
identifier t;
identifier fn_update_time =~ "update_time$";
@@
fn_update_time (...,
- struct timespec *t,
+ struct timespec64 *t,
...) { ... }
@ depends on patch @
identifier t;
@@
lease_get_mtime( ... ,
- struct timespec *t
+ struct timespec64 *t
) { ... }
@te depends on patch forall@
identifier ts;
local idexpression struct inode *inode_node;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn_update_time =~ "update_time$";
identifier fn;
expression e, E3;
local idexpression struct inode *node1;
local idexpression struct inode *node2;
local idexpression struct iattr *attr1;
local idexpression struct iattr *attr2;
local idexpression struct iattr attr;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
@@
(
(
- struct timespec ts;
+ struct timespec64 ts;
|
- struct timespec ts = current_time(inode_node);
+ struct timespec64 ts = current_time(inode_node);
)
<+... when != ts
(
- timespec_equal(&inode_node->i_xtime, &ts)
+ timespec64_equal(&inode_node->i_xtime, &ts)
|
- timespec_equal(&ts, &inode_node->i_xtime)
+ timespec64_equal(&ts, &inode_node->i_xtime)
|
- timespec_compare(&inode_node->i_xtime, &ts)
+ timespec64_compare(&inode_node->i_xtime, &ts)
|
- timespec_compare(&ts, &inode_node->i_xtime)
+ timespec64_compare(&ts, &inode_node->i_xtime)
|
ts = current_time(e)
|
fn_update_time(..., &ts,...)
|
inode_node->i_xtime = ts
|
node1->i_xtime = ts
|
ts = inode_node->i_xtime
|
<+... attr1->ia_xtime ...+> = ts
|
ts = attr1->ia_xtime
|
ts.tv_sec
|
ts.tv_nsec
|
btrfs_set_stack_timespec_sec(..., ts.tv_sec)
|
btrfs_set_stack_timespec_nsec(..., ts.tv_nsec)
|
- ts = timespec64_to_timespec(
+ ts =
...
-)
|
- ts = ktime_to_timespec(
+ ts = ktime_to_timespec64(
...)
|
- ts = E3
+ ts = timespec_to_timespec64(E3)
|
- ktime_get_real_ts(&ts)
+ ktime_get_real_ts64(&ts)
|
fn(...,
- ts
+ timespec64_to_timespec(ts)
,...)
)
...+>
(
<... when != ts
- return ts;
+ return timespec64_to_timespec(ts);
...>
)
|
- timespec_equal(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_equal(&node1->i_xtime2, &node2->i_xtime2)
|
- timespec_equal(&node1->i_xtime1, &attr2->ia_xtime2)
+ timespec64_equal(&node1->i_xtime2, &attr2->ia_xtime2)
|
- timespec_compare(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_compare(&node1->i_xtime1, &node2->i_xtime2)
|
node1->i_xtime1 =
- timespec_trunc(attr1->ia_xtime1,
+ timespec64_trunc(attr1->ia_xtime1,
...)
|
- attr1->ia_xtime1 = timespec_trunc(attr2->ia_xtime2,
+ attr1->ia_xtime1 = timespec64_trunc(attr2->ia_xtime2,
...)
|
- ktime_get_real_ts(&attr1->ia_xtime1)
+ ktime_get_real_ts64(&attr1->ia_xtime1)
|
- ktime_get_real_ts(&attr.ia_xtime1)
+ ktime_get_real_ts64(&attr.ia_xtime1)
)
@ depends on patch @
struct inode *node;
struct iattr *attr;
identifier fn;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
expression e;
@@
(
- fn(node->i_xtime);
+ fn(timespec64_to_timespec(node->i_xtime));
|
fn(...,
- node->i_xtime);
+ timespec64_to_timespec(node->i_xtime));
|
- e = fn(attr->ia_xtime);
+ e = fn(timespec64_to_timespec(attr->ia_xtime));
)
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
fn (...,
- &attr->ia_xtime,
+ &ts,
...);
)
...+>
}
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
struct kstat *stat;
identifier ia_xtime =~ "^ia_[acm]time$";
identifier i_xtime =~ "^i_[acm]time$";
identifier xtime =~ "^[acm]time$";
identifier fn, ret;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(stat->xtime);
ret = fn (...,
- &stat->xtime);
+ &ts);
)
...+>
}
@ depends on patch @
struct inode *node;
struct inode *node2;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier i_xtime3 =~ "^i_[acm]time$";
struct iattr *attrp;
struct iattr *attrp2;
struct iattr attr ;
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
struct kstat *stat;
struct kstat stat1;
struct timespec64 ts;
identifier xtime =~ "^[acmb]time$";
expression e;
@@
(
( node->i_xtime2 \| attrp->ia_xtime2 \| attr.ia_xtime2 \) = node->i_xtime1 ;
|
node->i_xtime2 = \( node2->i_xtime1 \| timespec64_trunc(...) \);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
stat->xtime = node2->i_xtime1;
|
stat1.xtime = node2->i_xtime1;
|
( node->i_xtime2 \| attrp->ia_xtime2 \) = attrp->ia_xtime1 ;
|
( attrp->ia_xtime1 \| attr.ia_xtime1 \) = attrp2->ia_xtime2;
|
- e = node->i_xtime1;
+ e = timespec64_to_timespec( node->i_xtime1 );
|
- e = attrp->ia_xtime1;
+ e = timespec64_to_timespec( attrp->ia_xtime1 );
|
node->i_xtime1 = current_time(...);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
- node->i_xtime1 = e;
+ node->i_xtime1 = timespec_to_timespec64(e);
)
Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: <anton@tuxera.com>
Cc: <balbi@kernel.org>
Cc: <bfields@fieldses.org>
Cc: <darrick.wong@oracle.com>
Cc: <dhowells@redhat.com>
Cc: <dsterba@suse.com>
Cc: <dwmw2@infradead.org>
Cc: <hch@lst.de>
Cc: <hirofumi@mail.parknet.co.jp>
Cc: <hubcap@omnibond.com>
Cc: <jack@suse.com>
Cc: <jaegeuk@kernel.org>
Cc: <jaharkes@cs.cmu.edu>
Cc: <jslaby@suse.com>
Cc: <keescook@chromium.org>
Cc: <mark@fasheh.com>
Cc: <miklos@szeredi.hu>
Cc: <nico@linaro.org>
Cc: <reiserfs-devel@vger.kernel.org>
Cc: <richard@nod.at>
Cc: <sage@redhat.com>
Cc: <sfrench@samba.org>
Cc: <swhiteho@redhat.com>
Cc: <tj@kernel.org>
Cc: <trond.myklebust@primarydata.com>
Cc: <tytso@mit.edu>
Cc: <viro@zeniv.linux.org.uk>
2018-05-09 10:36:02 +08:00
|
|
|
|
int ubifs_update_time(struct inode *inode, struct timespec64 *time,
|
2015-11-07 12:46:11 +08:00
|
|
|
|
int flags)
|
|
|
|
|
{
|
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
|
|
|
|
struct ubifs_budget_req req = { .dirtied_ino = 1,
|
|
|
|
|
.dirtied_ino_d = ALIGN(ui->data_len, 8) };
|
|
|
|
|
int err, release;
|
|
|
|
|
|
2019-03-26 15:52:32 +08:00
|
|
|
|
if (!IS_ENABLED(CONFIG_UBIFS_ATIME_SUPPORT))
|
|
|
|
|
return generic_update_time(inode, time, flags);
|
|
|
|
|
|
2015-11-07 12:46:11 +08:00
|
|
|
|
err = ubifs_budget_space(c, &req);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
mutex_lock(&ui->ui_mutex);
|
|
|
|
|
if (flags & S_ATIME)
|
|
|
|
|
inode->i_atime = *time;
|
|
|
|
|
if (flags & S_CTIME)
|
|
|
|
|
inode->i_ctime = *time;
|
|
|
|
|
if (flags & S_MTIME)
|
|
|
|
|
inode->i_mtime = *time;
|
|
|
|
|
|
|
|
|
|
release = ui->dirty;
|
2020-04-09 19:33:05 +08:00
|
|
|
|
__mark_inode_dirty(inode, I_DIRTY_SYNC);
|
2015-11-07 12:46:11 +08:00
|
|
|
|
mutex_unlock(&ui->ui_mutex);
|
|
|
|
|
if (release)
|
|
|
|
|
ubifs_release_budget(c, &req);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-15 00:08:37 +08:00
|
|
|
|
/**
|
2016-10-02 04:53:11 +08:00
|
|
|
|
* update_mctime - update mtime and ctime of an inode.
|
2008-07-15 00:08:37 +08:00
|
|
|
|
* @inode: inode to update
|
|
|
|
|
*
|
|
|
|
|
* This function updates mtime and ctime of the inode if it is not equivalent to
|
|
|
|
|
* current time. Returns zero in case of success and a negative error code in
|
|
|
|
|
* case of failure.
|
|
|
|
|
*/
|
2014-04-04 02:00:23 +08:00
|
|
|
|
static int update_mctime(struct inode *inode)
|
2008-07-15 00:08:37 +08:00
|
|
|
|
{
|
2018-07-13 22:31:55 +08:00
|
|
|
|
struct timespec64 now = current_time(inode);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
2014-04-04 02:00:23 +08:00
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
|
|
|
|
if (mctime_update_needed(inode, &now)) {
|
|
|
|
|
int err, release;
|
|
|
|
|
struct ubifs_budget_req req = { .dirtied_ino = 1,
|
2008-07-24 19:52:45 +08:00
|
|
|
|
.dirtied_ino_d = ALIGN(ui->data_len, 8) };
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
|
|
|
|
err = ubifs_budget_space(c, &req);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
mutex_lock(&ui->ui_mutex);
|
2017-05-09 06:59:25 +08:00
|
|
|
|
inode->i_mtime = inode->i_ctime = current_time(inode);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
release = ui->dirty;
|
|
|
|
|
mark_inode_dirty_sync(inode);
|
|
|
|
|
mutex_unlock(&ui->ui_mutex);
|
|
|
|
|
if (release)
|
|
|
|
|
ubifs_release_budget(c, &req);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-04 02:00:23 +08:00
|
|
|
|
static ssize_t ubifs_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
2008-07-15 00:08:37 +08:00
|
|
|
|
{
|
2014-04-04 02:00:23 +08:00
|
|
|
|
int err = update_mctime(file_inode(iocb->ki_filp));
|
2008-07-15 00:08:37 +08:00
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
2014-04-04 02:00:23 +08:00
|
|
|
|
return generic_file_write_iter(iocb, from);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 04:22:09 +08:00
|
|
|
|
static bool ubifs_dirty_folio(struct address_space *mapping,
|
|
|
|
|
struct folio *folio)
|
2008-07-15 00:08:37 +08:00
|
|
|
|
{
|
2022-02-10 04:22:09 +08:00
|
|
|
|
bool ret;
|
|
|
|
|
struct ubifs_info *c = mapping->host->i_sb->s_fs_info;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
2022-02-10 04:22:09 +08:00
|
|
|
|
ret = filemap_dirty_folio(mapping, folio);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
/*
|
|
|
|
|
* An attempt to dirty a page without budgeting for it - should not
|
|
|
|
|
* happen.
|
|
|
|
|
*/
|
2022-02-10 04:22:09 +08:00
|
|
|
|
ubifs_assert(c, ret == false);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-01 12:10:21 +08:00
|
|
|
|
static bool ubifs_release_folio(struct folio *folio, gfp_t unused_gfp_flags)
|
2008-07-15 00:08:37 +08:00
|
|
|
|
{
|
2022-05-01 12:10:21 +08:00
|
|
|
|
struct inode *inode = folio->mapping->host;
|
2018-07-12 19:01:57 +08:00
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
|
|
|
|
|
2008-07-15 00:08:37 +08:00
|
|
|
|
/*
|
|
|
|
|
* An attempt to release a dirty page without budgeting for it - should
|
|
|
|
|
* not happen.
|
|
|
|
|
*/
|
2022-05-01 12:10:21 +08:00
|
|
|
|
if (folio_test_writeback(folio))
|
|
|
|
|
return false;
|
|
|
|
|
ubifs_assert(c, folio_test_private(folio));
|
2018-07-12 19:01:57 +08:00
|
|
|
|
ubifs_assert(c, 0);
|
2022-05-01 12:10:21 +08:00
|
|
|
|
folio_detach_private(folio);
|
|
|
|
|
folio_clear_checked(folio);
|
|
|
|
|
return true;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2011-03-25 21:27:40 +08:00
|
|
|
|
* mmap()d file has taken write protection fault and is being made writable.
|
|
|
|
|
* UBIFS must ensure page is budgeted for.
|
2008-07-15 00:08:37 +08:00
|
|
|
|
*/
|
2018-04-15 04:18:59 +08:00
|
|
|
|
static vm_fault_t ubifs_vm_page_mkwrite(struct vm_fault *vmf)
|
2008-07-15 00:08:37 +08:00
|
|
|
|
{
|
2009-04-01 06:23:21 +08:00
|
|
|
|
struct page *page = vmf->page;
|
2017-02-25 06:56:41 +08:00
|
|
|
|
struct inode *inode = file_inode(vmf->vma->vm_file);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
struct ubifs_info *c = inode->i_sb->s_fs_info;
|
2018-07-13 22:31:55 +08:00
|
|
|
|
struct timespec64 now = current_time(inode);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
struct ubifs_budget_req req = { .new_page = 1 };
|
|
|
|
|
int err, update_time;
|
|
|
|
|
|
|
|
|
|
dbg_gen("ino %lu, pg %lu, i_size %lld", inode->i_ino, page->index,
|
|
|
|
|
i_size_read(inode));
|
2018-07-12 19:01:57 +08:00
|
|
|
|
ubifs_assert(c, !c->ro_media && !c->ro_mount);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
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 21:44:28 +08:00
|
|
|
|
if (unlikely(c->ro_error))
|
2009-04-01 06:23:21 +08:00
|
|
|
|
return VM_FAULT_SIGBUS; /* -EROFS */
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We have not locked @page so far so we may budget for changing the
|
|
|
|
|
* page. Note, we cannot do this after we locked the page, because
|
|
|
|
|
* budgeting may cause write-back which would cause deadlock.
|
|
|
|
|
*
|
|
|
|
|
* At the moment we do not know whether the page is dirty or not, so we
|
|
|
|
|
* assume that it is not and budget for a new page. We could look at
|
|
|
|
|
* the @PG_private flag and figure this out, but we may race with write
|
|
|
|
|
* back and the page state may change by the time we lock it, so this
|
|
|
|
|
* would need additional care. We do not bother with this at the
|
|
|
|
|
* moment, although it might be good idea to do. Instead, we allocate
|
|
|
|
|
* budget for a new page and amend it later on if the page was in fact
|
|
|
|
|
* dirty.
|
|
|
|
|
*
|
|
|
|
|
* The budgeting-related logic of this function is similar to what we
|
|
|
|
|
* do in 'ubifs_write_begin()' and 'ubifs_write_end()'. Glance there
|
|
|
|
|
* for more comments.
|
|
|
|
|
*/
|
|
|
|
|
update_time = mctime_update_needed(inode, &now);
|
|
|
|
|
if (update_time)
|
|
|
|
|
/*
|
|
|
|
|
* We have to change inode time stamp which requires extra
|
|
|
|
|
* budgeting.
|
|
|
|
|
*/
|
|
|
|
|
req.dirtied_ino = 1;
|
|
|
|
|
|
|
|
|
|
err = ubifs_budget_space(c, &req);
|
|
|
|
|
if (unlikely(err)) {
|
|
|
|
|
if (err == -ENOSPC)
|
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 18:39:42 +08:00
|
|
|
|
ubifs_warn(c, "out of space for mmapped file (inode number %lu)",
|
2012-08-27 18:34:09 +08:00
|
|
|
|
inode->i_ino);
|
2009-04-01 06:23:21 +08:00
|
|
|
|
return VM_FAULT_SIGBUS;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lock_page(page);
|
|
|
|
|
if (unlikely(page->mapping != inode->i_mapping ||
|
|
|
|
|
page_offset(page) > i_size_read(inode))) {
|
|
|
|
|
/* Page got truncated out from underneath us */
|
2018-04-15 04:18:59 +08:00
|
|
|
|
goto sigbus;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (PagePrivate(page))
|
|
|
|
|
release_new_page_budget(c);
|
|
|
|
|
else {
|
|
|
|
|
if (!PageChecked(page))
|
|
|
|
|
ubifs_convert_page_budget(c);
|
ubifs: Fix to add refcount once page is set private
MM defined the rule [1] very clearly that once page was set with PG_private
flag, we should increment the refcount in that page, also main flows like
pageout(), migrate_page() will assume there is one additional page
reference count if page_has_private() returns true. Otherwise, we may
get a BUG in page migration:
page:0000000080d05b9d refcount:-1 mapcount:0 mapping:000000005f4d82a8
index:0xe2 pfn:0x14c12
aops:ubifs_file_address_operations [ubifs] ino:8f1 dentry name:"f30e"
flags: 0x1fffff80002405(locked|uptodate|owner_priv_1|private|node=0|
zone=1|lastcpupid=0x1fffff)
page dumped because: VM_BUG_ON_PAGE(page_count(page) != 0)
------------[ cut here ]------------
kernel BUG at include/linux/page_ref.h:184!
invalid opcode: 0000 [#1] SMP
CPU: 3 PID: 38 Comm: kcompactd0 Not tainted 5.15.0-rc5
RIP: 0010:migrate_page_move_mapping+0xac3/0xe70
Call Trace:
ubifs_migrate_page+0x22/0xc0 [ubifs]
move_to_new_page+0xb4/0x600
migrate_pages+0x1523/0x1cc0
compact_zone+0x8c5/0x14b0
kcompactd+0x2bc/0x560
kthread+0x18c/0x1e0
ret_from_fork+0x1f/0x30
Before the time, we should make clean a concept, what does refcount means
in page gotten from grab_cache_page_write_begin(). There are 2 situations:
Situation 1: refcount is 3, page is created by __page_cache_alloc.
TYPE_A - the write process is using this page
TYPE_B - page is assigned to one certain mapping by calling
__add_to_page_cache_locked()
TYPE_C - page is added into pagevec list corresponding current cpu by
calling lru_cache_add()
Situation 2: refcount is 2, page is gotten from the mapping's tree
TYPE_B - page has been assigned to one certain mapping
TYPE_A - the write process is using this page (by calling
page_cache_get_speculative())
Filesystem releases one refcount by calling put_page() in xxx_write_end(),
the released refcount corresponds to TYPE_A (write task is using it). If
there are any processes using a page, page migration process will skip the
page by judging whether expected_page_refs() equals to page refcount.
The BUG is caused by following process:
PA(cpu 0) kcompactd(cpu 1)
compact_zone
ubifs_write_begin
page_a = grab_cache_page_write_begin
add_to_page_cache_lru
lru_cache_add
pagevec_add // put page into cpu 0's pagevec
(refcnf = 3, for page creation process)
ubifs_write_end
SetPagePrivate(page_a) // doesn't increase page count !
unlock_page(page_a)
put_page(page_a) // refcnt = 2
[...]
PB(cpu 0)
filemap_read
filemap_get_pages
add_to_page_cache_lru
lru_cache_add
__pagevec_lru_add // traverse all pages in cpu 0's pagevec
__pagevec_lru_add_fn
SetPageLRU(page_a)
isolate_migratepages
isolate_migratepages_block
get_page_unless_zero(page_a)
// refcnt = 3
list_add(page_a, from_list)
migrate_pages(from_list)
__unmap_and_move
move_to_new_page
ubifs_migrate_page(page_a)
migrate_page_move_mapping
expected_page_refs get 3
(migration[1] + mapping[1] + private[1])
release_pages
put_page_testzero(page_a) // refcnt = 3
page_ref_freeze // refcnt = 0
page_ref_dec_and_test(0 - 1 = -1)
page_ref_unfreeze
VM_BUG_ON_PAGE(-1 != 0, page)
UBIFS doesn't increase the page refcount after setting private flag, which
leads to page migration task believes the page is not used by any other
processes, so the page is migrated. This causes concurrent accessing on
page refcount between put_page() called by other process(eg. read process
calls lru_cache_add) and page_ref_unfreeze() called by migration task.
Actually zhangjun has tried to fix this problem [2] by recalculating page
refcnt in ubifs_migrate_page(). It's better to follow MM rules [1], because
just like Kirill suggested in [2], we need to check all users of
page_has_private() helper. Like f2fs does in [3], fix it by adding/deleting
refcount when setting/clearing private for a page. BTW, according to [4],
we set 'page->private' as 1 because ubifs just simply SetPagePrivate().
And, [5] provided a common helper to set/clear page private, ubifs can
use this helper following the example of iomap, afs, btrfs, etc.
Jump [6] to find a reproducer.
[1] https://lore.kernel.org/lkml/2b19b3c4-2bc4-15fa-15cc-27a13e5c7af1@aol.com
[2] https://www.spinics.net/lists/linux-mtd/msg04018.html
[3] http://lkml.iu.edu/hypermail/linux/kernel/1903.0/03313.html
[4] https://lore.kernel.org/linux-f2fs-devel/20210422154705.GO3596236@casper.infradead.org
[5] https://lore.kernel.org/all/20200517214718.468-1-guoqing.jiang@cloud.ionos.com
[6] https://bugzilla.kernel.org/show_bug.cgi?id=214961
Fixes: 1e51764a3c2ac0 ("UBIFS: add new flash file system")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-12-27 11:22:41 +08:00
|
|
|
|
attach_page_private(page, (void *)1);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
atomic_long_inc(&c->dirty_pg_cnt);
|
|
|
|
|
__set_page_dirty_nobuffers(page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (update_time) {
|
|
|
|
|
int release;
|
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
|
|
|
|
|
|
|
|
|
mutex_lock(&ui->ui_mutex);
|
2017-05-09 06:59:25 +08:00
|
|
|
|
inode->i_mtime = inode->i_ctime = current_time(inode);
|
2008-07-15 00:08:37 +08:00
|
|
|
|
release = ui->dirty;
|
|
|
|
|
mark_inode_dirty_sync(inode);
|
|
|
|
|
mutex_unlock(&ui->ui_mutex);
|
|
|
|
|
if (release)
|
|
|
|
|
ubifs_release_dirty_inode_budget(c, ui);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-22 08:42:59 +08:00
|
|
|
|
wait_for_stable_page(page);
|
2014-04-30 14:06:06 +08:00
|
|
|
|
return VM_FAULT_LOCKED;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
|
2018-04-15 04:18:59 +08:00
|
|
|
|
sigbus:
|
2008-07-15 00:08:37 +08:00
|
|
|
|
unlock_page(page);
|
|
|
|
|
ubifs_release_budget(c, &req);
|
2018-04-15 04:18:59 +08:00
|
|
|
|
return VM_FAULT_SIGBUS;
|
2008-07-15 00:08:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-28 02:29:37 +08:00
|
|
|
|
static const struct vm_operations_struct ubifs_file_vm_ops = {
|
2008-07-15 00:08:37 +08:00
|
|
|
|
.fault = filemap_fault,
|
2014-04-08 06:37:19 +08:00
|
|
|
|
.map_pages = filemap_map_pages,
|
2008-07-15 00:08:37 +08:00
|
|
|
|
.page_mkwrite = ubifs_vm_page_mkwrite,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int ubifs_file_mmap(struct file *file, struct vm_area_struct *vma)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
err = generic_file_mmap(file, vma);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
vma->vm_ops = &ubifs_file_vm_ops;
|
2019-03-26 15:52:32 +08:00
|
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_UBIFS_ATIME_SUPPORT))
|
|
|
|
|
file_accessed(file);
|
|
|
|
|
|
2008-07-15 00:08:37 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-08 19:24:26 +08:00
|
|
|
|
static const char *ubifs_get_link(struct dentry *dentry,
|
|
|
|
|
struct inode *inode,
|
|
|
|
|
struct delayed_call *done)
|
|
|
|
|
{
|
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
|
|
|
|
|
2018-01-12 12:27:00 +08:00
|
|
|
|
if (!IS_ENCRYPTED(inode))
|
2016-10-08 19:24:26 +08:00
|
|
|
|
return ui->data;
|
|
|
|
|
|
|
|
|
|
if (!dentry)
|
|
|
|
|
return ERR_PTR(-ECHILD);
|
|
|
|
|
|
2018-01-12 12:27:00 +08:00
|
|
|
|
return fscrypt_get_symlink(inode, ui->data, ui->data_len, done);
|
2016-10-08 19:24:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-02 14:53:49 +08:00
|
|
|
|
static int ubifs_symlink_getattr(struct user_namespace *mnt_userns,
|
|
|
|
|
const struct path *path, struct kstat *stat,
|
|
|
|
|
u32 request_mask, unsigned int query_flags)
|
|
|
|
|
{
|
|
|
|
|
ubifs_getattr(mnt_userns, path, stat, request_mask, query_flags);
|
|
|
|
|
|
|
|
|
|
if (IS_ENCRYPTED(d_inode(path->dentry)))
|
|
|
|
|
return fscrypt_symlink_getattr(path, stat);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-15 23:43:23 +08:00
|
|
|
|
const struct address_space_operations ubifs_file_address_operations = {
|
2022-04-29 23:12:16 +08:00
|
|
|
|
.read_folio = ubifs_read_folio,
|
2008-07-15 00:08:37 +08:00
|
|
|
|
.writepage = ubifs_writepage,
|
|
|
|
|
.write_begin = ubifs_write_begin,
|
|
|
|
|
.write_end = ubifs_write_end,
|
2022-02-10 04:21:50 +08:00
|
|
|
|
.invalidate_folio = ubifs_invalidate_folio,
|
2022-02-10 04:22:09 +08:00
|
|
|
|
.dirty_folio = ubifs_dirty_folio,
|
2022-06-06 22:47:21 +08:00
|
|
|
|
.migrate_folio = filemap_migrate_folio,
|
|
|
|
|
.release_folio = ubifs_release_folio,
|
2008-07-15 00:08:37 +08:00
|
|
|
|
};
|
|
|
|
|
|
2009-01-15 23:43:23 +08:00
|
|
|
|
const struct inode_operations ubifs_file_inode_operations = {
|
2008-07-15 00:08:37 +08:00
|
|
|
|
.setattr = ubifs_setattr,
|
|
|
|
|
.getattr = ubifs_getattr,
|
|
|
|
|
.listxattr = ubifs_listxattr,
|
2015-11-07 12:46:11 +08:00
|
|
|
|
.update_time = ubifs_update_time,
|
2021-04-07 20:36:44 +08:00
|
|
|
|
.fileattr_get = ubifs_fileattr_get,
|
|
|
|
|
.fileattr_set = ubifs_fileattr_set,
|
2008-07-15 00:08:37 +08:00
|
|
|
|
};
|
|
|
|
|
|
2009-01-15 23:43:23 +08:00
|
|
|
|
const struct inode_operations ubifs_symlink_inode_operations = {
|
2016-10-08 19:24:26 +08:00
|
|
|
|
.get_link = ubifs_get_link,
|
2008-07-15 00:08:37 +08:00
|
|
|
|
.setattr = ubifs_setattr,
|
2021-07-02 14:53:49 +08:00
|
|
|
|
.getattr = ubifs_symlink_getattr,
|
2014-11-01 02:50:29 +08:00
|
|
|
|
.listxattr = ubifs_listxattr,
|
2015-11-07 12:46:11 +08:00
|
|
|
|
.update_time = ubifs_update_time,
|
2008-07-15 00:08:37 +08:00
|
|
|
|
};
|
|
|
|
|
|
2009-01-15 23:43:23 +08:00
|
|
|
|
const struct file_operations ubifs_file_operations = {
|
2008-07-15 00:08:37 +08:00
|
|
|
|
.llseek = generic_file_llseek,
|
2014-04-03 02:33:16 +08:00
|
|
|
|
.read_iter = generic_file_read_iter,
|
2014-04-04 02:00:23 +08:00
|
|
|
|
.write_iter = ubifs_write_iter,
|
2008-07-15 00:08:37 +08:00
|
|
|
|
.mmap = ubifs_file_mmap,
|
|
|
|
|
.fsync = ubifs_fsync,
|
|
|
|
|
.unlocked_ioctl = ubifs_ioctl,
|
|
|
|
|
.splice_read = generic_file_splice_read,
|
2014-04-05 16:27:08 +08:00
|
|
|
|
.splice_write = iter_file_splice_write,
|
2017-11-30 04:43:13 +08:00
|
|
|
|
.open = fscrypt_file_open,
|
2008-07-15 00:08:37 +08:00
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
|
.compat_ioctl = ubifs_compat_ioctl,
|
|
|
|
|
#endif
|
|
|
|
|
};
|