OSDN Git Service

gfs2: Fix rounding error in gfs2_iomap_page_prepare
authorAndreas Gruenbacher <agruenba@redhat.com>
Sat, 8 Jun 2019 12:09:02 +0000 (13:09 +0100)
committerAndreas Gruenbacher <agruenba@redhat.com>
Fri, 14 Jun 2019 16:49:07 +0000 (18:49 +0200)
The pos and len arguments to the iomap page_prepare callback are not
block aligned, so we need to take that into account when computing the
number of blocks.

Fixes: d0a22a4b03b8 ("gfs2: Fix iomap write page reclaim deadlock")
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
fs/gfs2/bmap.c

index f42718d..8bae753 100644 (file)
@@ -994,9 +994,12 @@ static void gfs2_write_unlock(struct inode *inode)
 static int gfs2_iomap_page_prepare(struct inode *inode, loff_t pos,
                                   unsigned len, struct iomap *iomap)
 {
+       unsigned int blockmask = i_blocksize(inode) - 1;
        struct gfs2_sbd *sdp = GFS2_SB(inode);
+       unsigned int blocks;
 
-       return gfs2_trans_begin(sdp, RES_DINODE + (len >> inode->i_blkbits), 0);
+       blocks = ((pos & blockmask) + len + blockmask) >> inode->i_blkbits;
+       return gfs2_trans_begin(sdp, RES_DINODE + blocks, 0);
 }
 
 static void gfs2_iomap_page_done(struct inode *inode, loff_t pos,