gfs2: Fix length of holes reported at end-of-file
authorAndreas Gruenbacher <agruenba@redhat.com>
Fri, 5 Nov 2021 23:18:56 +0000 (00:18 +0100)
committerAndreas Gruenbacher <agruenba@redhat.com>
Sat, 6 Nov 2021 09:25:45 +0000 (10:25 +0100)
Fix the length of holes reported at the end of a file: the length is
relative to the beginning of the extent, not the seek position which is
rounded down to the filesystem block size.

This bug went unnoticed for some time, but is now caught by the
following assertion in iomap_iter_done():

  WARN_ON_ONCE(iter->iomap.offset + iter->iomap.length <= iter->pos)

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
fs/gfs2/bmap.c

index 7235d539e96950574d3655e6f3b1b61ef64f5984..d67108489148eef281128c6841c52135abf74050 100644 (file)
@@ -940,7 +940,7 @@ do_alloc:
                else if (height == ip->i_height)
                        ret = gfs2_hole_size(inode, lblock, len, mp, iomap);
                else
-                       iomap->length = size - pos;
+                       iomap->length = size - iomap->offset;
        } else if (flags & IOMAP_WRITE) {
                u64 alloc_size;