Skip to content

Commit fa731fc

Browse files
committed
GFS2: Fix truncation of journaled data files
This patch fixes an issue relating to not having enough revokes available when truncating journaled data files. In order to ensure that we do no run out, the truncation is broken into separate pieces if it is large enough. Tested using fsx on a journaled data file. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent 9dbe961 commit fa731fc

1 file changed

Lines changed: 49 additions & 3 deletions

File tree

‎fs/gfs2/bmap.c‎

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,41 @@ static int gfs2_block_truncate_page(struct address_space *mapping, loff_t from)
991991
return err;
992992
}
993993

994+
/**
995+
* gfs2_journaled_truncate - Wrapper for truncate_pagecache for jdata files
996+
* @inode: The inode being truncated
997+
* @oldsize: The original (larger) size
998+
* @newsize: The new smaller size
999+
*
1000+
* With jdata files, we have to journal a revoke for each block which is
1001+
* truncated. As a result, we need to split this into separate transactions
1002+
* if the number of pages being truncated gets too large.
1003+
*/
1004+
1005+
#define GFS2_JTRUNC_REVOKES 8192
1006+
1007+
static int gfs2_journaled_truncate(struct inode *inode, u64 oldsize, u64 newsize)
1008+
{
1009+
struct gfs2_sbd *sdp = GFS2_SB(inode);
1010+
u64 max_chunk = GFS2_JTRUNC_REVOKES * sdp->sd_vfs->s_blocksize;
1011+
u64 chunk;
1012+
int error;
1013+
1014+
while (oldsize != newsize) {
1015+
chunk = oldsize - newsize;
1016+
if (chunk > max_chunk)
1017+
chunk = max_chunk;
1018+
truncate_pagecache(inode, oldsize, oldsize - chunk);
1019+
oldsize -= chunk;
1020+
gfs2_trans_end(sdp);
1021+
error = gfs2_trans_begin(sdp, RES_DINODE, GFS2_JTRUNC_REVOKES);
1022+
if (error)
1023+
return error;
1024+
}
1025+
1026+
return 0;
1027+
}
1028+
9941029
static int trunc_start(struct inode *inode, u64 oldsize, u64 newsize)
9951030
{
9961031
struct gfs2_inode *ip = GFS2_I(inode);
@@ -1000,8 +1035,10 @@ static int trunc_start(struct inode *inode, u64 oldsize, u64 newsize)
10001035
int journaled = gfs2_is_jdata(ip);
10011036
int error;
10021037

1003-
error = gfs2_trans_begin(sdp,
1004-
RES_DINODE + (journaled ? RES_JDATA : 0), 0);
1038+
if (journaled)
1039+
error = gfs2_trans_begin(sdp, RES_DINODE + RES_JDATA, GFS2_JTRUNC_REVOKES);
1040+
else
1041+
error = gfs2_trans_begin(sdp, RES_DINODE, 0);
10051042
if (error)
10061043
return error;
10071044

@@ -1026,7 +1063,16 @@ static int trunc_start(struct inode *inode, u64 oldsize, u64 newsize)
10261063
ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME;
10271064
gfs2_dinode_out(ip, dibh->b_data);
10281065

1029-
truncate_pagecache(inode, oldsize, newsize);
1066+
if (journaled)
1067+
error = gfs2_journaled_truncate(inode, oldsize, newsize);
1068+
else
1069+
truncate_pagecache(inode, oldsize, newsize);
1070+
1071+
if (error) {
1072+
brelse(dibh);
1073+
return error;
1074+
}
1075+
10301076
out_brelse:
10311077
brelse(dibh);
10321078
out:

0 commit comments

Comments
 (0)