mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-04 01:24:12 +08:00
gfs2: implement gfs2_block_zero_range using iomap_zero_range
iomap handles all the nitty-gritty details of zeroing a file range for us, so use the proper helper. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Reviewed-by: Bob Peterson <rpeterso@redhat.com>
This commit is contained in:
parent
72d36d0529
commit
2257e468a6
@ -1348,76 +1348,10 @@ int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsi
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* gfs2_block_zero_range - Deal with zeroing out data
|
||||
*
|
||||
* This is partly borrowed from ext3.
|
||||
*/
|
||||
static int gfs2_block_zero_range(struct inode *inode, loff_t from,
|
||||
unsigned int length)
|
||||
{
|
||||
struct address_space *mapping = inode->i_mapping;
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
unsigned long index = from >> PAGE_SHIFT;
|
||||
unsigned offset = from & (PAGE_SIZE-1);
|
||||
unsigned blocksize, iblock, pos;
|
||||
struct buffer_head *bh;
|
||||
struct page *page;
|
||||
int err;
|
||||
|
||||
page = find_or_create_page(mapping, index, GFP_NOFS);
|
||||
if (!page)
|
||||
return 0;
|
||||
|
||||
blocksize = inode->i_sb->s_blocksize;
|
||||
iblock = index << (PAGE_SHIFT - inode->i_sb->s_blocksize_bits);
|
||||
|
||||
if (!page_has_buffers(page))
|
||||
create_empty_buffers(page, blocksize, 0);
|
||||
|
||||
/* Find the buffer that contains "offset" */
|
||||
bh = page_buffers(page);
|
||||
pos = blocksize;
|
||||
while (offset >= pos) {
|
||||
bh = bh->b_this_page;
|
||||
iblock++;
|
||||
pos += blocksize;
|
||||
}
|
||||
|
||||
err = 0;
|
||||
|
||||
if (!buffer_mapped(bh)) {
|
||||
gfs2_block_map(inode, iblock, bh, 0);
|
||||
/* unmapped? It's a hole - nothing to do */
|
||||
if (!buffer_mapped(bh))
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
/* Ok, it's mapped. Make sure it's up-to-date */
|
||||
if (PageUptodate(page))
|
||||
set_buffer_uptodate(bh);
|
||||
|
||||
if (!buffer_uptodate(bh)) {
|
||||
err = -EIO;
|
||||
ll_rw_block(REQ_OP_READ, 0, 1, &bh);
|
||||
wait_on_buffer(bh);
|
||||
/* Uhhuh. Read error. Complain and punt. */
|
||||
if (!buffer_uptodate(bh))
|
||||
goto unlock;
|
||||
err = 0;
|
||||
}
|
||||
|
||||
if (gfs2_is_jdata(ip))
|
||||
gfs2_trans_add_data(ip->i_gl, bh);
|
||||
else
|
||||
gfs2_ordered_add_inode(ip);
|
||||
|
||||
zero_user(page, offset, length);
|
||||
mark_buffer_dirty(bh);
|
||||
unlock:
|
||||
unlock_page(page);
|
||||
put_page(page);
|
||||
return err;
|
||||
return iomap_zero_range(inode, from, length, NULL, &gfs2_iomap_ops);
|
||||
}
|
||||
|
||||
#define GFS2_JTRUNC_REVOKES 8192
|
||||
|
Loading…
Reference in New Issue
Block a user