2017-12-18 04:00:59 +01:00
|
|
|
// SPDX-License-Identifier: LGPL-2.1
|
2009-06-18 01:24:03 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008,2009 NEC Software Tohoku, Ltd.
|
|
|
|
* Written by Takashi Sato <t-sato@yk.jp.nec.com>
|
|
|
|
* Akira Fujita <a-fujita@rs.jp.nec.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/quotaops.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 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2009-06-18 01:24:03 +02:00
|
|
|
#include "ext4_jbd2.h"
|
|
|
|
#include "ext4.h"
|
2012-11-28 19:03:30 +01:00
|
|
|
#include "ext4_extents.h"
|
2009-06-18 01:24:03 +02:00
|
|
|
|
2009-09-16 19:46:38 +02:00
|
|
|
/**
|
2019-06-19 22:30:03 +02:00
|
|
|
* get_ext_path() - Find an extent path for designated logical block number.
|
|
|
|
* @inode: inode to be searched
|
2009-09-16 19:46:38 +02:00
|
|
|
* @lblock: logical block number to find an extent path
|
2019-06-19 22:30:03 +02:00
|
|
|
* @ppath: pointer to an extent path pointer (for output)
|
2009-09-16 19:46:38 +02:00
|
|
|
*
|
2014-09-01 20:43:09 +02:00
|
|
|
* ext4_find_extent wrapper. Return 0 on success, or a negative error value
|
2009-09-16 19:46:38 +02:00
|
|
|
* on failure.
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
get_ext_path(struct inode *inode, ext4_lblk_t lblock,
|
2014-09-01 20:42:09 +02:00
|
|
|
struct ext4_ext_path **ppath)
|
2009-09-16 19:46:38 +02:00
|
|
|
{
|
2013-03-18 16:40:19 +01:00
|
|
|
struct ext4_ext_path *path;
|
2009-09-16 19:46:38 +02:00
|
|
|
|
2014-09-01 20:43:09 +02:00
|
|
|
path = ext4_find_extent(inode, lblock, ppath, EXT4_EX_NOCACHE);
|
2013-03-18 16:40:19 +01:00
|
|
|
if (IS_ERR(path))
|
2014-09-01 20:42:09 +02:00
|
|
|
return PTR_ERR(path);
|
|
|
|
if (path[ext_depth(inode)].p_ext == NULL) {
|
|
|
|
ext4_ext_drop_refs(path);
|
|
|
|
kfree(path);
|
|
|
|
*ppath = NULL;
|
|
|
|
return -ENODATA;
|
|
|
|
}
|
|
|
|
*ppath = path;
|
|
|
|
return 0;
|
2009-09-16 19:46:38 +02:00
|
|
|
}
|
2009-06-18 01:24:03 +02:00
|
|
|
|
|
|
|
/**
|
2019-06-19 22:30:03 +02:00
|
|
|
* ext4_double_down_write_data_sem() - write lock two inodes's i_data_sem
|
|
|
|
* @first: inode to be locked
|
|
|
|
* @second: inode to be locked
|
2009-06-18 01:24:03 +02:00
|
|
|
*
|
2012-09-26 18:32:19 +02:00
|
|
|
* Acquire write lock of i_data_sem of the two inodes
|
2009-06-18 01:24:03 +02:00
|
|
|
*/
|
2013-04-08 18:54:05 +02:00
|
|
|
void
|
|
|
|
ext4_double_down_write_data_sem(struct inode *first, struct inode *second)
|
2009-06-18 01:24:03 +02:00
|
|
|
{
|
2012-09-26 18:32:19 +02:00
|
|
|
if (first < second) {
|
|
|
|
down_write(&EXT4_I(first)->i_data_sem);
|
2016-04-01 07:31:28 +02:00
|
|
|
down_write_nested(&EXT4_I(second)->i_data_sem, I_DATA_SEM_OTHER);
|
2012-09-26 18:32:19 +02:00
|
|
|
} else {
|
|
|
|
down_write(&EXT4_I(second)->i_data_sem);
|
2016-04-01 07:31:28 +02:00
|
|
|
down_write_nested(&EXT4_I(first)->i_data_sem, I_DATA_SEM_OTHER);
|
2009-06-18 01:24:03 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-04-08 18:54:05 +02:00
|
|
|
* ext4_double_up_write_data_sem - Release two inodes' write lock of i_data_sem
|
2009-06-18 01:24:03 +02:00
|
|
|
*
|
|
|
|
* @orig_inode: original inode structure to be released its lock first
|
|
|
|
* @donor_inode: donor inode structure to be released its lock second
|
ext4: fix lock order problem in ext4_move_extents()
ext4_move_extents() checks the logical block contiguousness
of original file with ext4_find_extent() and mext_next_extent().
Therefore the extent which ext4_ext_path structure indicates
must not be changed between above functions.
But in current implementation, there is no i_data_sem protection
between ext4_ext_find_extent() and mext_next_extent(). So the extent
which ext4_ext_path structure indicates may be overwritten by
delalloc. As a result, ext4_move_extents() will exchange wrong blocks
between original and donor files. I change the place where
acquire/release i_data_sem to solve this problem.
Moreover, I changed move_extent_per_page() to start transaction first,
and then acquire i_data_sem. Without this change, there is a
possibility of the deadlock between mmap() and ext4_move_extents():
* NOTE: "A", "B" and "C" mean different processes
A-1: ext4_ext_move_extents() acquires i_data_sem of two inodes.
B: do_page_fault() starts the transaction (T),
and then tries to acquire i_data_sem.
But process "A" is already holding it, so it is kept waiting.
C: While "A" and "B" running, kjournald2 tries to commit transaction (T)
but it is under updating, so kjournald2 waits for it.
A-2: Call ext4_journal_start with holding i_data_sem,
but transaction (T) is locked.
Signed-off-by: Akira Fujita <a-fujita@rs.jp.nec.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-11-23 13:24:43 +01:00
|
|
|
* Release write lock of i_data_sem of two inodes (orig and donor).
|
2009-06-18 01:24:03 +02:00
|
|
|
*/
|
2013-04-08 18:54:05 +02:00
|
|
|
void
|
|
|
|
ext4_double_up_write_data_sem(struct inode *orig_inode,
|
|
|
|
struct inode *donor_inode)
|
2009-06-18 01:24:03 +02:00
|
|
|
{
|
|
|
|
up_write(&EXT4_I(orig_inode)->i_data_sem);
|
|
|
|
up_write(&EXT4_I(donor_inode)->i_data_sem);
|
|
|
|
}
|
|
|
|
|
2012-09-26 18:54:52 +02:00
|
|
|
/**
|
|
|
|
* mext_check_coverage - Check that all extents in range has the same type
|
|
|
|
*
|
|
|
|
* @inode: inode in question
|
|
|
|
* @from: block offset of inode
|
|
|
|
* @count: block count to be checked
|
2014-04-21 05:45:47 +02:00
|
|
|
* @unwritten: extents expected to be unwritten
|
2012-09-26 18:54:52 +02:00
|
|
|
* @err: pointer to save error value
|
|
|
|
*
|
|
|
|
* Return 1 if all extents in range has expected type, and zero otherwise.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
mext_check_coverage(struct inode *inode, ext4_lblk_t from, ext4_lblk_t count,
|
2014-04-21 05:45:47 +02:00
|
|
|
int unwritten, int *err)
|
2012-09-26 18:54:52 +02:00
|
|
|
{
|
|
|
|
struct ext4_ext_path *path = NULL;
|
|
|
|
struct ext4_extent *ext;
|
2013-03-18 16:40:19 +01:00
|
|
|
int ret = 0;
|
2012-09-26 18:54:52 +02:00
|
|
|
ext4_lblk_t last = from + count;
|
|
|
|
while (from < last) {
|
|
|
|
*err = get_ext_path(inode, from, &path);
|
|
|
|
if (*err)
|
2013-03-18 16:40:19 +01:00
|
|
|
goto out;
|
2012-09-26 18:54:52 +02:00
|
|
|
ext = path[ext_depth(inode)].p_ext;
|
2014-04-21 05:45:47 +02:00
|
|
|
if (unwritten != ext4_ext_is_unwritten(ext))
|
2013-03-18 16:40:19 +01:00
|
|
|
goto out;
|
2012-09-26 18:54:52 +02:00
|
|
|
from += ext4_ext_get_actual_len(ext);
|
|
|
|
ext4_ext_drop_refs(path);
|
|
|
|
}
|
2013-03-18 16:40:19 +01:00
|
|
|
ret = 1;
|
|
|
|
out:
|
2014-09-01 20:39:09 +02:00
|
|
|
ext4_ext_drop_refs(path);
|
|
|
|
kfree(path);
|
2013-03-18 16:40:19 +01:00
|
|
|
return ret;
|
2012-09-26 18:54:52 +02:00
|
|
|
}
|
|
|
|
|
2012-09-26 18:52:07 +02:00
|
|
|
/**
|
|
|
|
* mext_page_double_lock - Grab and lock pages on both @inode1 and @inode2
|
|
|
|
*
|
|
|
|
* @inode1: the inode structure
|
|
|
|
* @inode2: the inode structure
|
2014-10-12 01:56:34 +02:00
|
|
|
* @index1: page index
|
|
|
|
* @index2: page index
|
2012-09-26 18:52:07 +02:00
|
|
|
* @page: result page vector
|
|
|
|
*
|
|
|
|
* Grab two locked pages for inode's by inode order
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
mext_page_double_lock(struct inode *inode1, struct inode *inode2,
|
2014-08-31 05:52:19 +02:00
|
|
|
pgoff_t index1, pgoff_t index2, struct page *page[2])
|
2012-09-26 18:52:07 +02:00
|
|
|
{
|
|
|
|
struct address_space *mapping[2];
|
|
|
|
unsigned fl = AOP_FLAG_NOFS;
|
|
|
|
|
|
|
|
BUG_ON(!inode1 || !inode2);
|
|
|
|
if (inode1 < inode2) {
|
|
|
|
mapping[0] = inode1->i_mapping;
|
|
|
|
mapping[1] = inode2->i_mapping;
|
|
|
|
} else {
|
2018-07-29 22:11:59 +02:00
|
|
|
swap(index1, index2);
|
2012-09-26 18:52:07 +02:00
|
|
|
mapping[0] = inode2->i_mapping;
|
|
|
|
mapping[1] = inode1->i_mapping;
|
|
|
|
}
|
|
|
|
|
2014-08-31 05:52:19 +02:00
|
|
|
page[0] = grab_cache_page_write_begin(mapping[0], index1, fl);
|
2012-09-26 18:52:07 +02:00
|
|
|
if (!page[0])
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2014-08-31 05:52:19 +02:00
|
|
|
page[1] = grab_cache_page_write_begin(mapping[1], index2, fl);
|
2012-09-26 18:52:07 +02:00
|
|
|
if (!page[1]) {
|
|
|
|
unlock_page(page[0]);
|
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 14:29:47 +02:00
|
|
|
put_page(page[0]);
|
2012-09-26 18:52:07 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2013-04-12 05:24:58 +02:00
|
|
|
/*
|
|
|
|
* grab_cache_page_write_begin() may not wait on page's writeback if
|
|
|
|
* BDI not demand that. But it is reasonable to be very conservative
|
|
|
|
* here and explicitly wait on page's writeback
|
|
|
|
*/
|
|
|
|
wait_on_page_writeback(page[0]);
|
|
|
|
wait_on_page_writeback(page[1]);
|
2015-06-13 05:47:33 +02:00
|
|
|
if (inode1 > inode2)
|
|
|
|
swap(page[0], page[1]);
|
|
|
|
|
2012-09-26 18:52:07 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Force page buffers uptodate w/o dropping page's lock */
|
|
|
|
static int
|
|
|
|
mext_page_mkuptodate(struct page *page, unsigned from, unsigned to)
|
|
|
|
{
|
|
|
|
struct inode *inode = page->mapping->host;
|
|
|
|
sector_t block;
|
|
|
|
struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE];
|
|
|
|
unsigned int blocksize, block_start, block_end;
|
|
|
|
int i, err, nr = 0, partial = 0;
|
|
|
|
BUG_ON(!PageLocked(page));
|
|
|
|
BUG_ON(PageWriteback(page));
|
|
|
|
|
|
|
|
if (PageUptodate(page))
|
|
|
|
return 0;
|
|
|
|
|
2017-02-27 23:28:32 +01:00
|
|
|
blocksize = i_blocksize(inode);
|
2012-09-26 18:52:07 +02:00
|
|
|
if (!page_has_buffers(page))
|
|
|
|
create_empty_buffers(page, blocksize, 0);
|
|
|
|
|
|
|
|
head = page_buffers(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 14:29:47 +02:00
|
|
|
block = (sector_t)page->index << (PAGE_SHIFT - inode->i_blkbits);
|
2012-09-26 18:52:07 +02:00
|
|
|
for (bh = head, block_start = 0; bh != head || !block_start;
|
|
|
|
block++, block_start = block_end, bh = bh->b_this_page) {
|
|
|
|
block_end = block_start + blocksize;
|
|
|
|
if (block_end <= from || block_start >= to) {
|
|
|
|
if (!buffer_uptodate(bh))
|
|
|
|
partial = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (buffer_uptodate(bh))
|
|
|
|
continue;
|
|
|
|
if (!buffer_mapped(bh)) {
|
|
|
|
err = ext4_get_block(inode, block, bh, 0);
|
|
|
|
if (err) {
|
|
|
|
SetPageError(page);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (!buffer_mapped(bh)) {
|
|
|
|
zero_user(page, block_start, blocksize);
|
2014-02-18 02:46:40 +01:00
|
|
|
set_buffer_uptodate(bh);
|
2012-09-26 18:52:07 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BUG_ON(nr >= MAX_BUF_PER_PAGE);
|
|
|
|
arr[nr++] = bh;
|
|
|
|
}
|
|
|
|
/* No io required */
|
|
|
|
if (!nr)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (i = 0; i < nr; i++) {
|
|
|
|
bh = arr[i];
|
|
|
|
if (!bh_uptodate_or_lock(bh)) {
|
|
|
|
err = bh_submit_read(bh);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
if (!partial)
|
|
|
|
SetPageUptodate(page);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-18 01:24:03 +02:00
|
|
|
/**
|
|
|
|
* move_extent_per_page - Move extent data per page
|
|
|
|
*
|
|
|
|
* @o_filp: file structure of original file
|
|
|
|
* @donor_inode: donor inode
|
|
|
|
* @orig_page_offset: page index on original file
|
2014-10-12 01:56:34 +02:00
|
|
|
* @donor_page_offset: page index on donor file
|
2009-06-18 01:24:03 +02:00
|
|
|
* @data_offset_in_page: block index where data swapping starts
|
|
|
|
* @block_len_in_page: the number of blocks to be swapped
|
2014-04-21 05:45:47 +02:00
|
|
|
* @unwritten: orig extent is unwritten or not
|
2009-11-23 13:25:48 +01:00
|
|
|
* @err: pointer to save return value
|
2009-06-18 01:24:03 +02:00
|
|
|
*
|
|
|
|
* Save the data in original inode blocks and replace original inode extents
|
2014-10-12 01:56:34 +02:00
|
|
|
* with donor inode extents by calling ext4_swap_extents().
|
2009-11-23 13:25:48 +01:00
|
|
|
* Finally, write out the saved data in new original inode blocks. Return
|
|
|
|
* replaced block count.
|
2009-06-18 01:24:03 +02:00
|
|
|
*/
|
|
|
|
static int
|
2009-09-06 05:12:41 +02:00
|
|
|
move_extent_per_page(struct file *o_filp, struct inode *donor_inode,
|
2014-08-31 05:52:19 +02:00
|
|
|
pgoff_t orig_page_offset, pgoff_t donor_page_offset,
|
|
|
|
int data_offset_in_page,
|
|
|
|
int block_len_in_page, int unwritten, int *err)
|
2009-06-18 01:24:03 +02:00
|
|
|
{
|
2013-01-23 23:07:38 +01:00
|
|
|
struct inode *orig_inode = file_inode(o_filp);
|
2012-09-26 18:52:07 +02:00
|
|
|
struct page *pagep[2] = {NULL, NULL};
|
2009-06-18 01:24:03 +02:00
|
|
|
handle_t *handle;
|
2014-08-31 05:52:19 +02:00
|
|
|
ext4_lblk_t orig_blk_offset, donor_blk_offset;
|
2009-06-18 01:24:03 +02:00
|
|
|
unsigned long blocksize = orig_inode->i_sb->s_blocksize;
|
2009-11-23 13:25:48 +01:00
|
|
|
unsigned int tmp_data_size, data_size, replaced_size;
|
2016-02-12 07:20:43 +01:00
|
|
|
int i, err2, jblocks, retries = 0;
|
2009-11-23 13:25:48 +01:00
|
|
|
int replaced_count = 0;
|
2012-09-26 18:52:07 +02:00
|
|
|
int from = data_offset_in_page << orig_inode->i_blkbits;
|
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 14:29:47 +02:00
|
|
|
int blocks_per_page = PAGE_SIZE >> orig_inode->i_blkbits;
|
2014-11-05 17:52:38 +01:00
|
|
|
struct super_block *sb = orig_inode->i_sb;
|
2016-02-12 07:20:43 +01:00
|
|
|
struct buffer_head *bh = NULL;
|
2009-06-18 01:24:03 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* It needs twice the amount of ordinary journal buffers because
|
|
|
|
* inode and donor_inode may change each different metadata blocks.
|
|
|
|
*/
|
2012-09-26 18:52:07 +02:00
|
|
|
again:
|
|
|
|
*err = 0;
|
2009-06-18 01:24:03 +02:00
|
|
|
jblocks = ext4_writepage_trans_blocks(orig_inode) * 2;
|
2013-02-09 03:59:22 +01:00
|
|
|
handle = ext4_journal_start(orig_inode, EXT4_HT_MOVE_EXTENTS, jblocks);
|
2009-06-18 01:24:03 +02:00
|
|
|
if (IS_ERR(handle)) {
|
2009-11-23 13:25:48 +01:00
|
|
|
*err = PTR_ERR(handle);
|
|
|
|
return 0;
|
2009-06-18 01:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
orig_blk_offset = orig_page_offset * blocks_per_page +
|
|
|
|
data_offset_in_page;
|
|
|
|
|
2014-08-31 05:52:19 +02:00
|
|
|
donor_blk_offset = donor_page_offset * blocks_per_page +
|
|
|
|
data_offset_in_page;
|
|
|
|
|
2009-11-23 13:25:48 +01:00
|
|
|
/* Calculate data_size */
|
2009-06-18 01:24:03 +02:00
|
|
|
if ((orig_blk_offset + block_len_in_page - 1) ==
|
|
|
|
((orig_inode->i_size - 1) >> orig_inode->i_blkbits)) {
|
|
|
|
/* Replace the last block */
|
2009-11-23 13:25:48 +01:00
|
|
|
tmp_data_size = orig_inode->i_size & (blocksize - 1);
|
2009-06-18 01:24:03 +02:00
|
|
|
/*
|
2009-11-23 13:25:48 +01:00
|
|
|
* If data_size equal zero, it shows data_size is multiples of
|
2009-06-18 01:24:03 +02:00
|
|
|
* blocksize. So we set appropriate value.
|
|
|
|
*/
|
2009-11-23 13:25:48 +01:00
|
|
|
if (tmp_data_size == 0)
|
|
|
|
tmp_data_size = blocksize;
|
2009-06-18 01:24:03 +02:00
|
|
|
|
2009-11-23 13:25:48 +01:00
|
|
|
data_size = tmp_data_size +
|
2009-06-18 01:24:03 +02:00
|
|
|
((block_len_in_page - 1) << orig_inode->i_blkbits);
|
2009-11-23 13:25:48 +01:00
|
|
|
} else
|
|
|
|
data_size = block_len_in_page << orig_inode->i_blkbits;
|
|
|
|
|
|
|
|
replaced_size = data_size;
|
2009-06-18 01:24:03 +02:00
|
|
|
|
2012-09-26 18:52:07 +02:00
|
|
|
*err = mext_page_double_lock(orig_inode, donor_inode, orig_page_offset,
|
2014-08-31 05:52:19 +02:00
|
|
|
donor_page_offset, pagep);
|
2009-11-23 13:25:48 +01:00
|
|
|
if (unlikely(*err < 0))
|
2012-09-26 18:52:07 +02:00
|
|
|
goto stop_journal;
|
2012-09-26 18:54:52 +02:00
|
|
|
/*
|
2014-04-21 05:45:47 +02:00
|
|
|
* If orig extent was unwritten it can become initialized
|
2012-09-26 18:54:52 +02:00
|
|
|
* at any time after i_data_sem was dropped, in order to
|
|
|
|
* serialize with delalloc we have recheck extent while we
|
|
|
|
* hold page's lock, if it is still the case data copy is not
|
|
|
|
* necessary, just swap data blocks between orig and donor.
|
|
|
|
*/
|
2014-04-21 05:45:47 +02:00
|
|
|
if (unwritten) {
|
2013-04-08 18:54:05 +02:00
|
|
|
ext4_double_down_write_data_sem(orig_inode, donor_inode);
|
2012-09-26 18:54:52 +02:00
|
|
|
/* If any of extents in range became initialized we have to
|
|
|
|
* fallback to data copying */
|
2014-04-21 05:45:47 +02:00
|
|
|
unwritten = mext_check_coverage(orig_inode, orig_blk_offset,
|
|
|
|
block_len_in_page, 1, err);
|
2012-09-26 18:54:52 +02:00
|
|
|
if (*err)
|
|
|
|
goto drop_data_sem;
|
2009-06-18 01:24:03 +02:00
|
|
|
|
2014-08-31 05:52:19 +02:00
|
|
|
unwritten &= mext_check_coverage(donor_inode, donor_blk_offset,
|
2014-04-21 05:45:47 +02:00
|
|
|
block_len_in_page, 1, err);
|
2012-09-26 18:54:52 +02:00
|
|
|
if (*err)
|
|
|
|
goto drop_data_sem;
|
|
|
|
|
2014-04-21 05:45:47 +02:00
|
|
|
if (!unwritten) {
|
2013-04-08 18:54:05 +02:00
|
|
|
ext4_double_up_write_data_sem(orig_inode, donor_inode);
|
2012-09-26 18:54:52 +02:00
|
|
|
goto data_copy;
|
|
|
|
}
|
|
|
|
if ((page_has_private(pagep[0]) &&
|
|
|
|
!try_to_release_page(pagep[0], 0)) ||
|
|
|
|
(page_has_private(pagep[1]) &&
|
|
|
|
!try_to_release_page(pagep[1], 0))) {
|
|
|
|
*err = -EBUSY;
|
|
|
|
goto drop_data_sem;
|
|
|
|
}
|
2014-08-31 05:52:19 +02:00
|
|
|
replaced_count = ext4_swap_extents(handle, orig_inode,
|
|
|
|
donor_inode, orig_blk_offset,
|
|
|
|
donor_blk_offset,
|
|
|
|
block_len_in_page, 1, err);
|
2012-09-26 18:54:52 +02:00
|
|
|
drop_data_sem:
|
2013-04-08 18:54:05 +02:00
|
|
|
ext4_double_up_write_data_sem(orig_inode, donor_inode);
|
2012-09-26 18:54:52 +02:00
|
|
|
goto unlock_pages;
|
|
|
|
}
|
|
|
|
data_copy:
|
2012-09-26 18:52:07 +02:00
|
|
|
*err = mext_page_mkuptodate(pagep[0], from, from + replaced_size);
|
|
|
|
if (*err)
|
|
|
|
goto unlock_pages;
|
|
|
|
|
|
|
|
/* At this point all buffers in range are uptodate, old mapping layout
|
|
|
|
* is no longer required, try to drop it now. */
|
|
|
|
if ((page_has_private(pagep[0]) && !try_to_release_page(pagep[0], 0)) ||
|
|
|
|
(page_has_private(pagep[1]) && !try_to_release_page(pagep[1], 0))) {
|
|
|
|
*err = -EBUSY;
|
|
|
|
goto unlock_pages;
|
2009-06-18 01:24:03 +02:00
|
|
|
}
|
2014-07-28 04:32:27 +02:00
|
|
|
ext4_double_down_write_data_sem(orig_inode, donor_inode);
|
2014-08-31 05:52:19 +02:00
|
|
|
replaced_count = ext4_swap_extents(handle, orig_inode, donor_inode,
|
|
|
|
orig_blk_offset, donor_blk_offset,
|
|
|
|
block_len_in_page, 1, err);
|
2014-07-28 04:32:27 +02:00
|
|
|
ext4_double_up_write_data_sem(orig_inode, donor_inode);
|
2012-09-26 18:52:07 +02:00
|
|
|
if (*err) {
|
2009-11-23 13:25:48 +01:00
|
|
|
if (replaced_count) {
|
|
|
|
block_len_in_page = replaced_count;
|
|
|
|
replaced_size =
|
|
|
|
block_len_in_page << orig_inode->i_blkbits;
|
2009-11-24 16:31:56 +01:00
|
|
|
} else
|
2012-09-26 18:52:07 +02:00
|
|
|
goto unlock_pages;
|
2009-06-18 01:24:03 +02:00
|
|
|
}
|
2012-09-26 18:52:07 +02:00
|
|
|
/* Perform all necessary steps similar write_begin()/write_end()
|
|
|
|
* but keeping in mind that i_size will not change */
|
2016-02-12 07:20:43 +01:00
|
|
|
if (!page_has_buffers(pagep[0]))
|
|
|
|
create_empty_buffers(pagep[0], 1 << orig_inode->i_blkbits, 0);
|
|
|
|
bh = page_buffers(pagep[0]);
|
|
|
|
for (i = 0; i < data_offset_in_page; i++)
|
|
|
|
bh = bh->b_this_page;
|
|
|
|
for (i = 0; i < block_len_in_page; i++) {
|
|
|
|
*err = ext4_get_block(orig_inode, orig_blk_offset + i, bh, 0);
|
|
|
|
if (*err < 0)
|
|
|
|
break;
|
2016-02-22 00:38:44 +01:00
|
|
|
bh = bh->b_this_page;
|
2016-02-12 07:20:43 +01:00
|
|
|
}
|
2012-09-26 18:52:07 +02:00
|
|
|
if (!*err)
|
|
|
|
*err = block_commit_write(pagep[0], from, from + replaced_size);
|
2009-06-18 01:24:03 +02:00
|
|
|
|
2012-09-26 18:52:07 +02:00
|
|
|
if (unlikely(*err < 0))
|
|
|
|
goto repair_branches;
|
|
|
|
|
|
|
|
/* Even in case of data=writeback it is reasonable to pin
|
|
|
|
* inode to transaction, to prevent unexpected data loss */
|
2019-06-20 23:26:26 +02:00
|
|
|
*err = ext4_jbd2_inode_add_write(handle, orig_inode,
|
|
|
|
(loff_t)orig_page_offset << PAGE_SHIFT, replaced_size);
|
2012-09-26 18:52:07 +02:00
|
|
|
|
|
|
|
unlock_pages:
|
|
|
|
unlock_page(pagep[0]);
|
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 14:29:47 +02:00
|
|
|
put_page(pagep[0]);
|
2012-09-26 18:52:07 +02:00
|
|
|
unlock_page(pagep[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 14:29:47 +02:00
|
|
|
put_page(pagep[1]);
|
2012-09-26 18:52:07 +02:00
|
|
|
stop_journal:
|
2009-06-18 01:24:03 +02:00
|
|
|
ext4_journal_stop(handle);
|
2014-11-05 17:52:38 +01:00
|
|
|
if (*err == -ENOSPC &&
|
|
|
|
ext4_should_retry_alloc(sb, &retries))
|
|
|
|
goto again;
|
2012-09-26 18:52:07 +02:00
|
|
|
/* Buffer was busy because probably is pinned to journal transaction,
|
|
|
|
* force transaction commit may help to free it. */
|
2014-11-05 17:52:38 +01:00
|
|
|
if (*err == -EBUSY && retries++ < 4 && EXT4_SB(sb)->s_journal &&
|
|
|
|
jbd2_journal_force_commit_nested(EXT4_SB(sb)->s_journal))
|
2012-09-26 18:52:07 +02:00
|
|
|
goto again;
|
2009-11-23 13:25:48 +01:00
|
|
|
return replaced_count;
|
2012-09-26 18:52:07 +02:00
|
|
|
|
|
|
|
repair_branches:
|
|
|
|
/*
|
|
|
|
* This should never ever happen!
|
|
|
|
* Extents are swapped already, but we are not able to copy data.
|
|
|
|
* Try to swap extents to it's original places
|
|
|
|
*/
|
2013-04-08 18:54:05 +02:00
|
|
|
ext4_double_down_write_data_sem(orig_inode, donor_inode);
|
2014-08-31 05:52:19 +02:00
|
|
|
replaced_count = ext4_swap_extents(handle, donor_inode, orig_inode,
|
|
|
|
orig_blk_offset, donor_blk_offset,
|
|
|
|
block_len_in_page, 0, &err2);
|
2013-04-08 18:54:05 +02:00
|
|
|
ext4_double_up_write_data_sem(orig_inode, donor_inode);
|
2012-09-26 18:52:07 +02:00
|
|
|
if (replaced_count != block_len_in_page) {
|
|
|
|
EXT4_ERROR_INODE_BLOCK(orig_inode, (sector_t)(orig_blk_offset),
|
|
|
|
"Unable to copy data block,"
|
|
|
|
" data will be lost.");
|
|
|
|
*err = -EIO;
|
|
|
|
}
|
|
|
|
replaced_count = 0;
|
|
|
|
goto unlock_pages;
|
2009-06-18 01:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-03-04 06:39:24 +01:00
|
|
|
* mext_check_arguments - Check whether move extent can be done
|
2009-06-18 01:24:03 +02:00
|
|
|
*
|
|
|
|
* @orig_inode: original inode
|
|
|
|
* @donor_inode: donor inode
|
|
|
|
* @orig_start: logical start offset in block for orig
|
|
|
|
* @donor_start: logical start offset in block for donor
|
|
|
|
* @len: the number of blocks to be moved
|
|
|
|
*
|
|
|
|
* Check the arguments of ext4_move_extents() whether the files can be
|
|
|
|
* exchanged with each other.
|
|
|
|
* Return 0 on success, or a negative error value on failure.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
mext_check_arguments(struct inode *orig_inode,
|
2009-11-24 16:28:48 +01:00
|
|
|
struct inode *donor_inode, __u64 orig_start,
|
|
|
|
__u64 donor_start, __u64 *len)
|
2009-06-18 01:24:03 +02:00
|
|
|
{
|
2014-08-31 05:52:19 +02:00
|
|
|
__u64 orig_eof, donor_eof;
|
2009-09-16 20:28:22 +02:00
|
|
|
unsigned int blkbits = orig_inode->i_blkbits;
|
|
|
|
unsigned int blocksize = 1 << blkbits;
|
|
|
|
|
2014-08-31 05:52:19 +02:00
|
|
|
orig_eof = (i_size_read(orig_inode) + blocksize - 1) >> blkbits;
|
|
|
|
donor_eof = (i_size_read(donor_inode) + blocksize - 1) >> blkbits;
|
|
|
|
|
|
|
|
|
2009-12-07 05:38:31 +01:00
|
|
|
if (donor_inode->i_mode & (S_ISUID|S_ISGID)) {
|
|
|
|
ext4_debug("ext4 move extent: suid or sgid is set"
|
|
|
|
" to donor file [ino:orig %lu, donor %lu]\n",
|
|
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-06-03 04:04:39 +02:00
|
|
|
if (IS_IMMUTABLE(donor_inode) || IS_APPEND(donor_inode))
|
|
|
|
return -EPERM;
|
|
|
|
|
2009-06-18 01:24:03 +02:00
|
|
|
/* Ext4 move extent does not support swapfile */
|
|
|
|
if (IS_SWAPFILE(orig_inode) || IS_SWAPFILE(donor_inode)) {
|
|
|
|
ext4_debug("ext4 move extent: The argument files should "
|
|
|
|
"not be swapfile [ino:orig %lu, donor %lu]\n",
|
|
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
2014-08-31 05:52:19 +02:00
|
|
|
return -EBUSY;
|
2009-06-18 01:24:03 +02:00
|
|
|
}
|
|
|
|
|
2017-06-22 17:31:25 +02:00
|
|
|
if (ext4_is_quota_file(orig_inode) && ext4_is_quota_file(donor_inode)) {
|
2016-04-01 07:31:28 +02:00
|
|
|
ext4_debug("ext4 move extent: The argument files should "
|
|
|
|
"not be quota files [ino:orig %lu, donor %lu]\n",
|
|
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2009-06-18 01:24:03 +02:00
|
|
|
/* Ext4 move extent supports only extent based file */
|
2010-05-17 04:00:00 +02:00
|
|
|
if (!(ext4_test_inode_flag(orig_inode, EXT4_INODE_EXTENTS))) {
|
2009-06-18 01:24:03 +02:00
|
|
|
ext4_debug("ext4 move extent: orig file is not extents "
|
|
|
|
"based file [ino:orig %lu]\n", orig_inode->i_ino);
|
|
|
|
return -EOPNOTSUPP;
|
2010-05-17 04:00:00 +02:00
|
|
|
} else if (!(ext4_test_inode_flag(donor_inode, EXT4_INODE_EXTENTS))) {
|
2009-06-18 01:24:03 +02:00
|
|
|
ext4_debug("ext4 move extent: donor file is not extents "
|
|
|
|
"based file [ino:donor %lu]\n", donor_inode->i_ino);
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!orig_inode->i_size) || (!donor_inode->i_size)) {
|
|
|
|
ext4_debug("ext4 move extent: File size is 0 byte\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start offset should be same */
|
2014-08-31 05:52:19 +02:00
|
|
|
if ((orig_start & ~(PAGE_MASK >> orig_inode->i_blkbits)) !=
|
|
|
|
(donor_start & ~(PAGE_MASK >> orig_inode->i_blkbits))) {
|
2009-06-18 01:24:03 +02:00
|
|
|
ext4_debug("ext4 move extent: orig and donor's start "
|
2017-03-25 22:33:31 +01:00
|
|
|
"offsets are not aligned [ino:orig %lu, donor %lu]\n",
|
2009-06-18 01:24:03 +02:00
|
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-06-06 06:05:17 +02:00
|
|
|
if ((orig_start >= EXT_MAX_BLOCKS) ||
|
2014-08-31 05:52:19 +02:00
|
|
|
(donor_start >= EXT_MAX_BLOCKS) ||
|
2011-06-06 06:05:17 +02:00
|
|
|
(*len > EXT_MAX_BLOCKS) ||
|
2014-08-31 05:52:19 +02:00
|
|
|
(donor_start + *len >= EXT_MAX_BLOCKS) ||
|
2011-06-06 06:05:17 +02:00
|
|
|
(orig_start + *len >= EXT_MAX_BLOCKS)) {
|
2009-09-17 17:55:58 +02:00
|
|
|
ext4_debug("ext4 move extent: Can't handle over [%u] blocks "
|
2011-06-06 06:05:17 +02:00
|
|
|
"[ino:orig %lu, donor %lu]\n", EXT_MAX_BLOCKS,
|
2009-06-18 01:24:03 +02:00
|
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2018-10-02 07:34:44 +02:00
|
|
|
if (orig_eof <= orig_start)
|
|
|
|
*len = 0;
|
|
|
|
else if (orig_eof < orig_start + *len - 1)
|
2014-08-31 05:52:19 +02:00
|
|
|
*len = orig_eof - orig_start;
|
2018-10-02 07:34:44 +02:00
|
|
|
if (donor_eof <= donor_start)
|
|
|
|
*len = 0;
|
|
|
|
else if (donor_eof < donor_start + *len - 1)
|
2014-08-31 05:52:19 +02:00
|
|
|
*len = donor_eof - donor_start;
|
2009-06-18 01:24:03 +02:00
|
|
|
if (!*len) {
|
2009-11-23 13:24:50 +01:00
|
|
|
ext4_debug("ext4 move extent: len should not be 0 "
|
2009-06-18 01:24:03 +02:00
|
|
|
"[ino:orig %lu, donor %lu]\n", orig_inode->i_ino,
|
|
|
|
donor_inode->i_ino);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ext4_move_extents - Exchange the specified range of a file
|
|
|
|
*
|
|
|
|
* @o_filp: file structure of the original file
|
|
|
|
* @d_filp: file structure of the donor file
|
2014-10-12 01:56:34 +02:00
|
|
|
* @orig_blk: start offset in block for orig
|
|
|
|
* @donor_blk: start offset in block for donor
|
2009-06-18 01:24:03 +02:00
|
|
|
* @len: the number of blocks to be moved
|
|
|
|
* @moved_len: moved block length
|
|
|
|
*
|
|
|
|
* This function returns 0 and moved block length is set in moved_len
|
|
|
|
* if succeed, otherwise returns error value.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int
|
2014-08-31 05:52:19 +02:00
|
|
|
ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,
|
|
|
|
__u64 donor_blk, __u64 len, __u64 *moved_len)
|
2009-06-18 01:24:03 +02:00
|
|
|
{
|
2013-01-23 23:07:38 +01:00
|
|
|
struct inode *orig_inode = file_inode(o_filp);
|
|
|
|
struct inode *donor_inode = file_inode(d_filp);
|
2014-08-31 05:52:19 +02:00
|
|
|
struct ext4_ext_path *path = NULL;
|
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 14:29:47 +02:00
|
|
|
int blocks_per_page = PAGE_SIZE >> orig_inode->i_blkbits;
|
2014-08-31 05:52:19 +02:00
|
|
|
ext4_lblk_t o_end, o_start = orig_blk;
|
|
|
|
ext4_lblk_t d_start = donor_blk;
|
|
|
|
int ret;
|
2009-06-18 01:24:03 +02:00
|
|
|
|
2012-09-26 18:32:19 +02:00
|
|
|
if (orig_inode->i_sb != donor_inode->i_sb) {
|
|
|
|
ext4_debug("ext4 move extent: The argument files "
|
|
|
|
"should be in same FS [ino:orig %lu, donor %lu]\n",
|
|
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* orig and donor should be different inodes */
|
|
|
|
if (orig_inode == donor_inode) {
|
2009-09-28 21:58:29 +02:00
|
|
|
ext4_debug("ext4 move extent: The argument files should not "
|
2012-09-26 18:32:19 +02:00
|
|
|
"be same inode [ino:orig %lu, donor %lu]\n",
|
2009-09-28 21:58:29 +02:00
|
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-03-04 06:34:58 +01:00
|
|
|
/* Regular file check */
|
|
|
|
if (!S_ISREG(orig_inode->i_mode) || !S_ISREG(donor_inode->i_mode)) {
|
|
|
|
ext4_debug("ext4 move extent: The argument files should be "
|
|
|
|
"regular file [ino:orig %lu, donor %lu]\n",
|
|
|
|
orig_inode->i_ino, donor_inode->i_ino);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2015-06-22 03:38:03 +02:00
|
|
|
|
|
|
|
/* TODO: it's not obvious how to swap blocks for inodes with full
|
|
|
|
journaling enabled */
|
2012-09-26 18:32:54 +02:00
|
|
|
if (ext4_should_journal_data(orig_inode) ||
|
|
|
|
ext4_should_journal_data(donor_inode)) {
|
2015-06-22 03:38:03 +02:00
|
|
|
ext4_msg(orig_inode->i_sb, KERN_ERR,
|
|
|
|
"Online defrag not supported with data journaling");
|
|
|
|
return -EOPNOTSUPP;
|
2012-09-26 18:32:54 +02:00
|
|
|
}
|
2015-06-22 03:38:03 +02:00
|
|
|
|
2018-12-12 10:50:10 +01:00
|
|
|
if (IS_ENCRYPTED(orig_inode) || IS_ENCRYPTED(donor_inode)) {
|
2016-08-29 21:45:11 +02:00
|
|
|
ext4_msg(orig_inode->i_sb, KERN_ERR,
|
|
|
|
"Online defrag not supported for encrypted files");
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
ext4: fix lock order problem in ext4_move_extents()
ext4_move_extents() checks the logical block contiguousness
of original file with ext4_find_extent() and mext_next_extent().
Therefore the extent which ext4_ext_path structure indicates
must not be changed between above functions.
But in current implementation, there is no i_data_sem protection
between ext4_ext_find_extent() and mext_next_extent(). So the extent
which ext4_ext_path structure indicates may be overwritten by
delalloc. As a result, ext4_move_extents() will exchange wrong blocks
between original and donor files. I change the place where
acquire/release i_data_sem to solve this problem.
Moreover, I changed move_extent_per_page() to start transaction first,
and then acquire i_data_sem. Without this change, there is a
possibility of the deadlock between mmap() and ext4_move_extents():
* NOTE: "A", "B" and "C" mean different processes
A-1: ext4_ext_move_extents() acquires i_data_sem of two inodes.
B: do_page_fault() starts the transaction (T),
and then tries to acquire i_data_sem.
But process "A" is already holding it, so it is kept waiting.
C: While "A" and "B" running, kjournald2 tries to commit transaction (T)
but it is under updating, so kjournald2 waits for it.
A-2: Call ext4_journal_start with holding i_data_sem,
but transaction (T) is locked.
Signed-off-by: Akira Fujita <a-fujita@rs.jp.nec.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-11-23 13:24:43 +01:00
|
|
|
/* Protect orig and donor inodes against a truncate */
|
2012-04-18 21:16:33 +02:00
|
|
|
lock_two_nondirectories(orig_inode, donor_inode);
|
2009-06-18 01:24:03 +02:00
|
|
|
|
2012-09-29 06:41:21 +02:00
|
|
|
/* Wait for all existing dio workers */
|
|
|
|
inode_dio_wait(orig_inode);
|
|
|
|
inode_dio_wait(donor_inode);
|
|
|
|
|
ext4: fix lock order problem in ext4_move_extents()
ext4_move_extents() checks the logical block contiguousness
of original file with ext4_find_extent() and mext_next_extent().
Therefore the extent which ext4_ext_path structure indicates
must not be changed between above functions.
But in current implementation, there is no i_data_sem protection
between ext4_ext_find_extent() and mext_next_extent(). So the extent
which ext4_ext_path structure indicates may be overwritten by
delalloc. As a result, ext4_move_extents() will exchange wrong blocks
between original and donor files. I change the place where
acquire/release i_data_sem to solve this problem.
Moreover, I changed move_extent_per_page() to start transaction first,
and then acquire i_data_sem. Without this change, there is a
possibility of the deadlock between mmap() and ext4_move_extents():
* NOTE: "A", "B" and "C" mean different processes
A-1: ext4_ext_move_extents() acquires i_data_sem of two inodes.
B: do_page_fault() starts the transaction (T),
and then tries to acquire i_data_sem.
But process "A" is already holding it, so it is kept waiting.
C: While "A" and "B" running, kjournald2 tries to commit transaction (T)
but it is under updating, so kjournald2 waits for it.
A-2: Call ext4_journal_start with holding i_data_sem,
but transaction (T) is locked.
Signed-off-by: Akira Fujita <a-fujita@rs.jp.nec.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-11-23 13:24:43 +01:00
|
|
|
/* Protect extent tree against block allocations via delalloc */
|
2013-04-08 18:54:05 +02:00
|
|
|
ext4_double_down_write_data_sem(orig_inode, donor_inode);
|
2009-06-18 01:24:03 +02:00
|
|
|
/* Check the filesystem environment whether move_extent can be done */
|
2014-08-31 05:52:19 +02:00
|
|
|
ret = mext_check_arguments(orig_inode, donor_inode, orig_blk,
|
|
|
|
donor_blk, &len);
|
2012-09-26 18:32:19 +02:00
|
|
|
if (ret)
|
2009-09-16 20:25:07 +02:00
|
|
|
goto out;
|
2014-08-31 05:52:19 +02:00
|
|
|
o_end = o_start + len;
|
2009-06-18 01:24:03 +02:00
|
|
|
|
2014-08-31 05:52:19 +02:00
|
|
|
while (o_start < o_end) {
|
|
|
|
struct ext4_extent *ex;
|
|
|
|
ext4_lblk_t cur_blk, next_blk;
|
|
|
|
pgoff_t orig_page_index, donor_page_index;
|
|
|
|
int offset_in_page;
|
|
|
|
int unwritten, cur_len;
|
2009-06-18 01:24:03 +02:00
|
|
|
|
2014-08-31 05:52:19 +02:00
|
|
|
ret = get_ext_path(orig_inode, o_start, &path);
|
|
|
|
if (ret)
|
2009-06-18 01:24:03 +02:00
|
|
|
goto out;
|
2014-08-31 05:52:19 +02:00
|
|
|
ex = path[path->p_depth].p_ext;
|
|
|
|
next_blk = ext4_ext_next_allocated_block(path);
|
|
|
|
cur_blk = le32_to_cpu(ex->ee_block);
|
|
|
|
cur_len = ext4_ext_get_actual_len(ex);
|
|
|
|
/* Check hole before the start pos */
|
|
|
|
if (cur_blk + cur_len - 1 < o_start) {
|
|
|
|
if (next_blk == EXT_MAX_BLOCKS) {
|
|
|
|
o_start = o_end;
|
|
|
|
ret = -ENODATA;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
d_start += next_blk - o_start;
|
|
|
|
o_start = next_blk;
|
2014-09-01 20:42:09 +02:00
|
|
|
continue;
|
2014-08-31 05:52:19 +02:00
|
|
|
/* Check hole after the start pos */
|
|
|
|
} else if (cur_blk > o_start) {
|
|
|
|
/* Skip hole */
|
|
|
|
d_start += cur_blk - o_start;
|
|
|
|
o_start = cur_blk;
|
|
|
|
/* Extent inside requested range ?*/
|
|
|
|
if (cur_blk >= o_end)
|
|
|
|
goto out;
|
|
|
|
} else { /* in_range(o_start, o_blk, o_len) */
|
|
|
|
cur_len += cur_blk - o_start;
|
2009-06-18 01:24:03 +02:00
|
|
|
}
|
2014-08-31 05:52:19 +02:00
|
|
|
unwritten = ext4_ext_is_unwritten(ex);
|
|
|
|
if (o_end - o_start < cur_len)
|
|
|
|
cur_len = o_end - o_start;
|
|
|
|
|
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 14:29:47 +02:00
|
|
|
orig_page_index = o_start >> (PAGE_SHIFT -
|
2014-08-31 05:52:19 +02:00
|
|
|
orig_inode->i_blkbits);
|
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 14:29:47 +02:00
|
|
|
donor_page_index = d_start >> (PAGE_SHIFT -
|
2014-08-31 05:52:19 +02:00
|
|
|
donor_inode->i_blkbits);
|
|
|
|
offset_in_page = o_start % blocks_per_page;
|
|
|
|
if (cur_len > blocks_per_page- offset_in_page)
|
|
|
|
cur_len = blocks_per_page - offset_in_page;
|
ext4: fix lock order problem in ext4_move_extents()
ext4_move_extents() checks the logical block contiguousness
of original file with ext4_find_extent() and mext_next_extent().
Therefore the extent which ext4_ext_path structure indicates
must not be changed between above functions.
But in current implementation, there is no i_data_sem protection
between ext4_ext_find_extent() and mext_next_extent(). So the extent
which ext4_ext_path structure indicates may be overwritten by
delalloc. As a result, ext4_move_extents() will exchange wrong blocks
between original and donor files. I change the place where
acquire/release i_data_sem to solve this problem.
Moreover, I changed move_extent_per_page() to start transaction first,
and then acquire i_data_sem. Without this change, there is a
possibility of the deadlock between mmap() and ext4_move_extents():
* NOTE: "A", "B" and "C" mean different processes
A-1: ext4_ext_move_extents() acquires i_data_sem of two inodes.
B: do_page_fault() starts the transaction (T),
and then tries to acquire i_data_sem.
But process "A" is already holding it, so it is kept waiting.
C: While "A" and "B" running, kjournald2 tries to commit transaction (T)
but it is under updating, so kjournald2 waits for it.
A-2: Call ext4_journal_start with holding i_data_sem,
but transaction (T) is locked.
Signed-off-by: Akira Fujita <a-fujita@rs.jp.nec.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-11-23 13:24:43 +01:00
|
|
|
/*
|
|
|
|
* Up semaphore to avoid following problems:
|
|
|
|
* a. transaction deadlock among ext4_journal_start,
|
|
|
|
* ->write_begin via pagefault, and jbd2_journal_commit
|
|
|
|
* b. racing with ->readpage, ->write_begin, and ext4_get_block
|
|
|
|
* in move_extent_per_page
|
|
|
|
*/
|
2013-04-08 18:54:05 +02:00
|
|
|
ext4_double_up_write_data_sem(orig_inode, donor_inode);
|
2014-08-31 05:52:19 +02:00
|
|
|
/* Swap original branches with new branches */
|
|
|
|
move_extent_per_page(o_filp, donor_inode,
|
|
|
|
orig_page_index, donor_page_index,
|
|
|
|
offset_in_page, cur_len,
|
|
|
|
unwritten, &ret);
|
2013-04-08 18:54:05 +02:00
|
|
|
ext4_double_down_write_data_sem(orig_inode, donor_inode);
|
2012-09-26 18:32:19 +02:00
|
|
|
if (ret < 0)
|
ext4: fix lock order problem in ext4_move_extents()
ext4_move_extents() checks the logical block contiguousness
of original file with ext4_find_extent() and mext_next_extent().
Therefore the extent which ext4_ext_path structure indicates
must not be changed between above functions.
But in current implementation, there is no i_data_sem protection
between ext4_ext_find_extent() and mext_next_extent(). So the extent
which ext4_ext_path structure indicates may be overwritten by
delalloc. As a result, ext4_move_extents() will exchange wrong blocks
between original and donor files. I change the place where
acquire/release i_data_sem to solve this problem.
Moreover, I changed move_extent_per_page() to start transaction first,
and then acquire i_data_sem. Without this change, there is a
possibility of the deadlock between mmap() and ext4_move_extents():
* NOTE: "A", "B" and "C" mean different processes
A-1: ext4_ext_move_extents() acquires i_data_sem of two inodes.
B: do_page_fault() starts the transaction (T),
and then tries to acquire i_data_sem.
But process "A" is already holding it, so it is kept waiting.
C: While "A" and "B" running, kjournald2 tries to commit transaction (T)
but it is under updating, so kjournald2 waits for it.
A-2: Call ext4_journal_start with holding i_data_sem,
but transaction (T) is locked.
Signed-off-by: Akira Fujita <a-fujita@rs.jp.nec.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-11-23 13:24:43 +01:00
|
|
|
break;
|
2014-08-31 05:52:19 +02:00
|
|
|
o_start += cur_len;
|
|
|
|
d_start += cur_len;
|
2009-06-18 01:24:03 +02:00
|
|
|
}
|
2014-08-31 05:52:19 +02:00
|
|
|
*moved_len = o_start - orig_blk;
|
|
|
|
if (*moved_len > len)
|
|
|
|
*moved_len = len;
|
|
|
|
|
2009-06-18 01:24:03 +02:00
|
|
|
out:
|
2009-11-24 16:19:57 +01:00
|
|
|
if (*moved_len) {
|
|
|
|
ext4_discard_preallocations(orig_inode);
|
|
|
|
ext4_discard_preallocations(donor_inode);
|
|
|
|
}
|
|
|
|
|
2014-09-01 20:39:09 +02:00
|
|
|
ext4_ext_drop_refs(path);
|
|
|
|
kfree(path);
|
2013-04-08 18:54:05 +02:00
|
|
|
ext4_double_up_write_data_sem(orig_inode, donor_inode);
|
2012-04-18 21:16:33 +02:00
|
|
|
unlock_two_nondirectories(orig_inode, donor_inode);
|
2009-06-18 01:24:03 +02:00
|
|
|
|
2012-09-26 18:32:19 +02:00
|
|
|
return ret;
|
2009-06-18 01:24:03 +02:00
|
|
|
}
|