]> git.baikalelectronics.ru Git - kernel.git/commit
xfs: redesign the reflink remap loop to fix blkres depletion crash
authorDarrick J. Wong <darrick.wong@oracle.com>
Fri, 11 Nov 2022 04:10:22 +0000 (09:40 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Nov 2022 16:42:03 +0000 (17:42 +0100)
commitbfa768ab545c230992119fc44e09d98939889605
tree1373fd93381dc79036345c03cec0ba8cdc80b9a2
parentf8f99418b75780c0e7b92dc4d1ca9f6fabb2e1f1
xfs: redesign the reflink remap loop to fix blkres depletion crash

commit a722e618f9d38b76043094d2d60cffb962076dac upstream.

The existing reflink remapping loop has some structural problems that
need addressing:

The biggest problem is that we create one transaction for each extent in
the source file without accounting for the number of mappings there are
for the same range in the destination file.  In other words, we don't
know the number of remap operations that will be necessary and we
therefore cannot guess the block reservation required.  On highly
fragmented filesystems (e.g. ones with active dedupe) we guess wrong,
run out of block reservation, and fail.

The second problem is that we don't actually use the bmap intents to
their full potential -- instead of calling bunmapi directly and having
to deal with its backwards operation, we could call the deferred ops
xfs_bmap_unmap_extent and xfs_refcount_decrease_extent instead.  This
makes the frontend loop much simpler.

Solve all of these problems by refactoring the remapping loops so that
we only perform one remapping operation per transaction, and each
operation only tries to remap a single extent from source to dest.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reported-by: Edwin Török <edwin@etorok.net>
Tested-by: Edwin Török <edwin@etorok.net>
Acked-by: Darrick J. Wong <djwong@kernel.org>
[backported to 5.4.y - Tested-by above does not refer to the backport]
Signed-off-by: Chandan Babu R <chandan.babu@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/xfs/libxfs/xfs_bmap.h
fs/xfs/xfs_reflink.c
fs/xfs/xfs_trace.h