Skip to content

Commit d031a88

Browse files
author
Andreas Gruenbacher
committed
gfs2: Fix filesystem block deallocation for short writes
When a write cannot be carried out in full, gfs2_iomap_end() releases blocks that have been allocated for this write but haven't been used. To compute the end of the allocation, gfs2_iomap_end() incorrectly rounded the end of the attempted write down to the next block boundary to arrive at the end of the allocation. It would have to round up, but the end of the allocation is also available as iomap->offset + iomap->length, so just use that instead. In addition, use round_up() for computing the start of the unused range. Fixes: 64bc06b ("gfs2: iomap buffered write support") Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent 4a2316a commit d031a88

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

fs/gfs2/bmap.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,13 +1153,12 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length,
11531153

11541154
if (length != written && (iomap->flags & IOMAP_F_NEW)) {
11551155
/* Deallocate blocks that were just allocated. */
1156-
loff_t blockmask = i_blocksize(inode) - 1;
1157-
loff_t end = (pos + length) & ~blockmask;
1156+
loff_t hstart = round_up(pos + written, i_blocksize(inode));
1157+
loff_t hend = iomap->offset + iomap->length;
11581158

1159-
pos = (pos + written + blockmask) & ~blockmask;
1160-
if (pos < end) {
1161-
truncate_pagecache_range(inode, pos, end - 1);
1162-
punch_hole(ip, pos, end - pos);
1159+
if (hstart < hend) {
1160+
truncate_pagecache_range(inode, hstart, hend - 1);
1161+
punch_hole(ip, hstart, hend - hstart);
11631162
}
11641163
}
11651164

0 commit comments

Comments
 (0)