Patch "gfs2: Fix filesystem block deallocation for short writes" has been added to the 4.19-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    gfs2: Fix filesystem block deallocation for short writes

to the 4.19-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     gfs2-fix-filesystem-block-deallocation-for-short-wri.patch
and it can be found in the queue-4.19 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 63232c61c5a8d0327b798af303311f023704eddf
Author: Andreas Gruenbacher <agruenba@xxxxxxxxxx>
Date:   Thu Apr 14 17:52:39 2022 +0200

    gfs2: Fix filesystem block deallocation for short writes
    
    [ Upstream commit d031a8866e709c9d1ee5537a321b6192b4d2dc5b ]
    
    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: 64bc06bb32ee ("gfs2: iomap buffered write support")
    Signed-off-by: Andreas Gruenbacher <agruenba@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 53ba5019ad06..150cec85c416 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -1168,13 +1168,12 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length,
 
 	if (length != written && (iomap->flags & IOMAP_F_NEW)) {
 		/* Deallocate blocks that were just allocated. */
-		loff_t blockmask = i_blocksize(inode) - 1;
-		loff_t end = (pos + length) & ~blockmask;
+		loff_t hstart = round_up(pos + written, i_blocksize(inode));
+		loff_t hend = iomap->offset + iomap->length;
 
-		pos = (pos + written + blockmask) & ~blockmask;
-		if (pos < end) {
-			truncate_pagecache_range(inode, pos, end - 1);
-			punch_hole(ip, pos, end - pos);
+		if (hstart < hend) {
+			truncate_pagecache_range(inode, hstart, hend - 1);
+			punch_hole(ip, hstart, hend - hstart);
 		}
 	}
 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux