From cce655aa7a7d4afdc5c6161f3bbc9b7d986759ad Mon Sep 17 00:00:00 2001 From: Rong Tao Date: Mon, 10 Nov 2025 09:53:42 +0800 Subject: [PATCH] block: Try to handle busy underlying device on discard Merge linux patch [1] and pick part of [2] to truncate_bdev_range() function to fix -EBUSY on multipath disk's discard/zeroout handle. See also linux commit d44c9780ed40 ("block: Try to handle busy underlying device on discard") and linux commit 37c3fc9abb25 ("block: simplify the block device claiming interface"). [1] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/fs/block_dev.c?h=v5.10.180&id=d44c9780ed40db88626c9354868eab72159c7a7f [2] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/fs/block_dev.c?h=v5.10.180&id=37c3fc9abb25cd767ad5b048358336ac89488c16 Ached-by: Ge Changzhong Signed-off-by: Li Xiang Signed-off-by: Rong Tao Cc: Gao Yan --- fs/block_dev.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index 3babe569eecf..90595c03dc4f 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1268,10 +1268,21 @@ int truncate_bdev_range(struct block_device *bdev, fmode_t mode, err = bd_prepare_to_claim(bdev, claimed_bdev, truncate_bdev_range); if (err) - return err; + goto invalidate; } truncate_inode_pages_range(bdev->bd_inode->i_mapping, lstart, lend); + if (!(mode & FMODE_EXCL)) + bd_abort_claiming(bdev, claimed_bdev, truncate_bdev_range); return 0; + +invalidate: + /* + * Someone else has handle exclusively open. Try invalidating instead. + * The 'end' argument is inclusive so the rounding is safe. + */ + return invalidate_inode_pages2_range(bdev->bd_inode->i_mapping, + lstart >> PAGE_SHIFT, + lend >> PAGE_SHIFT); } EXPORT_SYMBOL(truncate_bdev_range); -- Gitee