mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 03:40:35 +09:00
gfs2: Improve mmap write vs. punch_hole consistency
[ Upstream commit 39c3a948ec ]
When punching a hole in a file, use filemap_write_and_wait_range to
write back any dirty pages in the range of the hole. As a side effect,
if the hole isn't page aligned, this marks unaligned pages at the
beginning and the end of the hole read-only. This is required when the
block size is smaller than the page size: when those pages are written
to again after the hole punching, we must make sure that page_mkwrite is
called for those pages so that the page will be fully allocated and any
blocks turned into holes from the hole punching will be reallocated.
(If a page is writably mapped, page_mkwrite won't be called.)
Fixes xfstest generic/567.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
e42c75ef34
commit
18a640d3b5
@@ -2442,8 +2442,16 @@ int __gfs2_punch_hole(struct file *file, loff_t offset, loff_t length)
|
||||
struct inode *inode = file_inode(file);
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_sbd *sdp = GFS2_SB(inode);
|
||||
unsigned int blocksize = i_blocksize(inode);
|
||||
loff_t start, end;
|
||||
int error;
|
||||
|
||||
start = round_down(offset, blocksize);
|
||||
end = round_up(offset + length, blocksize) - 1;
|
||||
error = filemap_write_and_wait_range(inode->i_mapping, start, end);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
if (gfs2_is_jdata(ip))
|
||||
error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_JDATA,
|
||||
GFS2_JTRUNC_REVOKES);
|
||||
@@ -2457,9 +2465,8 @@ int __gfs2_punch_hole(struct file *file, loff_t offset, loff_t length)
|
||||
if (error)
|
||||
goto out;
|
||||
} else {
|
||||
unsigned int start_off, end_len, blocksize;
|
||||
unsigned int start_off, end_len;
|
||||
|
||||
blocksize = i_blocksize(inode);
|
||||
start_off = offset & (blocksize - 1);
|
||||
end_len = (offset + length) & (blocksize - 1);
|
||||
if (start_off) {
|
||||
|
||||
Reference in New Issue
Block a user