gfs2: Never call gfs2_block_zero_range with an open transaction
authorBob Peterson <rpeterso@redhat.com>
Fri, 24 Jul 2020 17:06:31 +0000 (12:06 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Aug 2020 08:40:48 +0000 (10:40 +0200)
commit888d9b829c255e7bb0e1cb79cd6679f37dcb4473
tree255559927054f1a5cfdc31ad9c4f13647a7c59e4
parent18a640d3b57043a7efd31e79ca183ecf7faec3eb
gfs2: Never call gfs2_block_zero_range with an open transaction

[ Upstream commit 70499cdfeb3625c87eebe4f7a7ea06fa7447e5df ]

Before this patch, some functions started transactions then they called
gfs2_block_zero_range. However, gfs2_block_zero_range, like writes, can
start transactions, which results in a recursive transaction error.
For example:

do_shrink
   trunc_start
      gfs2_trans_begin <------------------------------------------------
         gfs2_block_zero_range
            iomap_zero_range(inode, from, length, NULL, &gfs2_iomap_ops);
               iomap_apply ... iomap_zero_range_actor
                  iomap_begin
                     gfs2_iomap_begin
                        gfs2_iomap_begin_write
                  actor (iomap_zero_range_actor)
     iomap_zero
iomap_write_begin
   gfs2_iomap_page_prepare
      gfs2_trans_begin <------------------------

This patch reorders the callers of gfs2_block_zero_range so that they
only start their transactions after the call. It also adds a BUG_ON to
ensure this doesn't happen again.

Fixes: 2257e468a63b ("gfs2: implement gfs2_block_zero_range using iomap_zero_range")
Cc: stable@vger.kernel.org # v5.5+
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/gfs2/bmap.c