diff options
author | Andreas Gruenbacher <agruenba@redhat.com> | 2017-12-13 14:10:38 -0500 |
---|---|---|
committer | Bob Peterson <rpeterso@redhat.com> | 2018-01-17 08:35:53 -0500 |
commit | bdba0d5ec13ed48420a4f85a69317c963c0de67e (patch) | |
tree | 9f5957b3801873d32fa1b581f9dca6b6bfc76c21 | |
parent | cb7f0903efacb7d25b844b9d321b43f228c7a37a (diff) |
Turn gfs2_block_truncate_page into gfs2_block_zero_range
Turn gfs2_block_truncate_page into a function that zeroes a range within
a block rather than only the end of a block. This will be used for
cleaning the end of the first partial block and the start of the last
partial block when punching a hole in a file.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
-rw-r--r-- | fs/gfs2/bmap.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 1c964def34fd..c4a297e87512 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c | |||
@@ -904,17 +904,18 @@ int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsi | |||
904 | } | 904 | } |
905 | 905 | ||
906 | /** | 906 | /** |
907 | * gfs2_block_truncate_page - Deal with zeroing out data for truncate | 907 | * gfs2_block_zero_range - Deal with zeroing out data |
908 | * | 908 | * |
909 | * This is partly borrowed from ext3. | 909 | * This is partly borrowed from ext3. |
910 | */ | 910 | */ |
911 | static int gfs2_block_truncate_page(struct address_space *mapping, loff_t from) | 911 | static int gfs2_block_zero_range(struct inode *inode, loff_t from, |
912 | unsigned int length) | ||
912 | { | 913 | { |
913 | struct inode *inode = mapping->host; | 914 | struct address_space *mapping = inode->i_mapping; |
914 | struct gfs2_inode *ip = GFS2_I(inode); | 915 | struct gfs2_inode *ip = GFS2_I(inode); |
915 | unsigned long index = from >> PAGE_SHIFT; | 916 | unsigned long index = from >> PAGE_SHIFT; |
916 | unsigned offset = from & (PAGE_SIZE-1); | 917 | unsigned offset = from & (PAGE_SIZE-1); |
917 | unsigned blocksize, iblock, length, pos; | 918 | unsigned blocksize, iblock, pos; |
918 | struct buffer_head *bh; | 919 | struct buffer_head *bh; |
919 | struct page *page; | 920 | struct page *page; |
920 | int err; | 921 | int err; |
@@ -924,7 +925,6 @@ static int gfs2_block_truncate_page(struct address_space *mapping, loff_t from) | |||
924 | return 0; | 925 | return 0; |
925 | 926 | ||
926 | blocksize = inode->i_sb->s_blocksize; | 927 | blocksize = inode->i_sb->s_blocksize; |
927 | length = blocksize - (offset & (blocksize - 1)); | ||
928 | iblock = index << (PAGE_SHIFT - inode->i_sb->s_blocksize_bits); | 928 | iblock = index << (PAGE_SHIFT - inode->i_sb->s_blocksize_bits); |
929 | 929 | ||
930 | if (!page_has_buffers(page)) | 930 | if (!page_has_buffers(page)) |
@@ -1025,7 +1025,6 @@ static int trunc_start(struct inode *inode, u64 newsize) | |||
1025 | { | 1025 | { |
1026 | struct gfs2_inode *ip = GFS2_I(inode); | 1026 | struct gfs2_inode *ip = GFS2_I(inode); |
1027 | struct gfs2_sbd *sdp = GFS2_SB(inode); | 1027 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
1028 | struct address_space *mapping = inode->i_mapping; | ||
1029 | struct buffer_head *dibh = NULL; | 1028 | struct buffer_head *dibh = NULL; |
1030 | int journaled = gfs2_is_jdata(ip); | 1029 | int journaled = gfs2_is_jdata(ip); |
1031 | u64 oldsize = inode->i_size; | 1030 | u64 oldsize = inode->i_size; |
@@ -1047,8 +1046,11 @@ static int trunc_start(struct inode *inode, u64 newsize) | |||
1047 | if (gfs2_is_stuffed(ip)) { | 1046 | if (gfs2_is_stuffed(ip)) { |
1048 | gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode) + newsize); | 1047 | gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode) + newsize); |
1049 | } else { | 1048 | } else { |
1050 | if (newsize & (u64)(sdp->sd_sb.sb_bsize - 1)) { | 1049 | unsigned int blocksize = i_blocksize(inode); |
1051 | error = gfs2_block_truncate_page(mapping, newsize); | 1050 | unsigned int offs = newsize & (blocksize - 1); |
1051 | if (offs) { | ||
1052 | error = gfs2_block_zero_range(inode, newsize, | ||
1053 | blocksize - offs); | ||
1052 | if (error) | 1054 | if (error) |
1053 | goto out; | 1055 | goto out; |
1054 | } | 1056 | } |