public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>,
	Chandan Babu R <chandanbabu@kernel.org>,
	Keith Busch <kbusch@kernel.org>
Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org,
	linux-xfs@vger.kernel.org
Subject: [PATCH 04/10] xfs: switch to using blk_next_discard_bio directly
Date: Thu,  7 Mar 2024 08:11:51 -0700	[thread overview]
Message-ID: <20240307151157.466013-5-hch@lst.de> (raw)
In-Reply-To: <20240307151157.466013-1-hch@lst.de>

This fixes fatal signals getting into the way and corrupting the bio
chain and removes the need to handle synchronous errors.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/xfs_discard.c | 47 ++++++++++++++------------------------------
 fs/xfs/xfs_discard.h |  2 +-
 2 files changed, 16 insertions(+), 33 deletions(-)

diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
index d5787991bb5b46..6396a4e14809a2 100644
--- a/fs/xfs/xfs_discard.c
+++ b/fs/xfs/xfs_discard.c
@@ -102,33 +102,26 @@ xfs_discard_endio(
  * list. We plug and chain the bios so that we only need a single completion
  * call to clear all the busy extents once the discards are complete.
  */
-int
+void
 xfs_discard_extents(
 	struct xfs_mount	*mp,
 	struct xfs_busy_extents	*extents)
 {
+	struct block_device	*bdev = mp->m_ddev_targp->bt_bdev;
 	struct xfs_extent_busy	*busyp;
 	struct bio		*bio = NULL;
 	struct blk_plug		plug;
-	int			error = 0;
 
 	blk_start_plug(&plug);
 	list_for_each_entry(busyp, &extents->extent_list, list) {
+		sector_t sector = XFS_AGB_TO_DADDR(mp, busyp->agno, busyp->bno);
+		sector_t nr_sects = XFS_FSB_TO_BB(mp, busyp->length);
+
 		trace_xfs_discard_extent(mp, busyp->agno, busyp->bno,
 					 busyp->length);
-
-		error = __blkdev_issue_discard(mp->m_ddev_targp->bt_bdev,
-				XFS_AGB_TO_DADDR(mp, busyp->agno, busyp->bno),
-				XFS_FSB_TO_BB(mp, busyp->length),
-				GFP_NOFS, &bio);
-		if (error && error != -EOPNOTSUPP) {
-			xfs_info(mp,
-	 "discard failed for extent [0x%llx,%u], error %d",
-				 (unsigned long long)busyp->bno,
-				 busyp->length,
-				 error);
-			break;
-		}
+		while (blk_next_discard_bio(bdev, &bio, &sector, &nr_sects,
+				GFP_NOFS))
+			;
 	}
 
 	if (bio) {
@@ -139,11 +132,8 @@ xfs_discard_extents(
 		xfs_discard_endio_work(&extents->endio_work);
 	}
 	blk_finish_plug(&plug);
-
-	return error;
 }
 
-
 static int
 xfs_trim_gather_extents(
 	struct xfs_perag	*pag,
@@ -306,16 +296,14 @@ xfs_trim_extents(
 		.ar_blockcount = pag->pagf_longest,
 		.ar_startblock = NULLAGBLOCK,
 	};
-	int			error = 0;
 
 	do {
 		struct xfs_busy_extents	*extents;
+		int			error;
 
 		extents = kzalloc(sizeof(*extents), GFP_KERNEL);
-		if (!extents) {
-			error = -ENOMEM;
-			break;
-		}
+		if (!extents)
+			return -ENOMEM;
 
 		extents->mount = pag->pag_mount;
 		extents->owner = extents;
@@ -325,7 +313,7 @@ xfs_trim_extents(
 				&tcur, extents, blocks_trimmed);
 		if (error) {
 			kfree(extents);
-			break;
+			return error;
 		}
 
 		/*
@@ -338,17 +326,12 @@ xfs_trim_extents(
 		 * list  after this function call, as it may have been freed by
 		 * the time control returns to us.
 		 */
-		error = xfs_discard_extents(pag->pag_mount, extents);
-		if (error)
-			break;
-
+		xfs_discard_extents(pag->pag_mount, extents);
 		if (xfs_trim_should_stop())
-			break;
-
+			return 0;
 	} while (tcur.ar_blockcount != 0);
 
-	return error;
-
+	return 0;
 }
 
 /*
diff --git a/fs/xfs/xfs_discard.h b/fs/xfs/xfs_discard.h
index 2b1a85223a56c6..8c5cc4af6a0787 100644
--- a/fs/xfs/xfs_discard.h
+++ b/fs/xfs/xfs_discard.h
@@ -6,7 +6,7 @@ struct fstrim_range;
 struct xfs_mount;
 struct xfs_busy_extents;
 
-int xfs_discard_extents(struct xfs_mount *mp, struct xfs_busy_extents *busy);
+void xfs_discard_extents(struct xfs_mount *mp, struct xfs_busy_extents *busy);
 int xfs_ioc_trim(struct xfs_mount *mp, struct fstrim_range __user *fstrim);
 
 #endif /* XFS_DISCARD_H */
-- 
2.39.2


  parent reply	other threads:[~2024-03-07 15:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07 15:11 RFC: untangle and fix __blkdev_issue_discard Christoph Hellwig
2024-03-07 15:11 ` [PATCH 01/10] block: remove the discard_granularity check in __blkdev_issue_discard Christoph Hellwig
2024-03-07 15:11 ` [PATCH 02/10] block: move discard checks into the ioctl handler Christoph Hellwig
2024-03-07 21:33   ` Dave Chinner
2024-03-08 15:22     ` Christoph Hellwig
2024-03-08 21:16       ` Dave Chinner
2024-03-07 15:11 ` [PATCH 03/10] block: add a blk_next_discard_bio helper Christoph Hellwig
2024-03-07 15:11 ` Christoph Hellwig [this message]
2024-03-07 15:11 ` [PATCH 05/10] f2fs: switch to using blk_next_discard_bio directly Christoph Hellwig
2024-03-07 15:11 ` [PATCH 06/10] ext4: " Christoph Hellwig
2024-03-07 16:13   ` Keith Busch
2024-03-08 15:21     ` Christoph Hellwig
2024-03-07 15:11 ` [PATCH 07/10] nvmet: " Christoph Hellwig
2024-03-07 15:11 ` [PATCH 08/10] md: " Christoph Hellwig
2024-03-07 15:11 ` [PATCH 09/10] dm-thin: " Christoph Hellwig
2024-03-07 15:11 ` [PATCH 10/10] block: remove __blkdev_issue_discard Christoph Hellwig
2024-03-07 21:05 ` RFC: untangle and fix __blkdev_issue_discard Keith Busch
2024-03-08 15:21   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240307151157.466013-5-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=chandanbabu@kernel.org \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox