public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Catherine Hoang <catherine.hoang@oracle.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH 6.6 CANDIDATE v2 09/21] xfs: handle nimaps=0 from xfs_bmapi_write in xfs_alloc_file_space
Date: Mon,  5 Feb 2024 14:19:59 -0800	[thread overview]
Message-ID: <20240205222011.95476-10-catherine.hoang@oracle.com> (raw)
In-Reply-To: <20240205222011.95476-1-catherine.hoang@oracle.com>

From: Christoph Hellwig <hch@lst.de>

commit 35dc55b9e80cb9ec4bcb969302000b002b2ed850 upstream.

If xfs_bmapi_write finds a delalloc extent at the requested range, it
tries to convert the entire delalloc extent to a real allocation.

But if the allocator cannot find a single free extent large enough to
cover the start block of the requested range, xfs_bmapi_write will
return 0 but leave *nimaps set to 0.

In that case we simply need to keep looping with the same startoffset_fsb
so that one of the following allocations will eventually reach the
requested range.

Note that this could affect any caller of xfs_bmapi_write that covers
an existing delayed allocation.  As far as I can tell we do not have
any other such caller, though - the regular writeback path uses
xfs_bmapi_convert_delalloc to convert delayed allocations to real ones,
and direct I/O invalidates the page cache first.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com>
---
 fs/xfs/xfs_bmap_util.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index fcefab687285..ad4aba5002c1 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -780,12 +780,10 @@ xfs_alloc_file_space(
 {
 	xfs_mount_t		*mp = ip->i_mount;
 	xfs_off_t		count;
-	xfs_filblks_t		allocated_fsb;
 	xfs_filblks_t		allocatesize_fsb;
 	xfs_extlen_t		extsz, temp;
 	xfs_fileoff_t		startoffset_fsb;
 	xfs_fileoff_t		endoffset_fsb;
-	int			nimaps;
 	int			rt;
 	xfs_trans_t		*tp;
 	xfs_bmbt_irec_t		imaps[1], *imapp;
@@ -808,7 +806,6 @@ xfs_alloc_file_space(
 
 	count = len;
 	imapp = &imaps[0];
-	nimaps = 1;
 	startoffset_fsb	= XFS_B_TO_FSBT(mp, offset);
 	endoffset_fsb = XFS_B_TO_FSB(mp, offset + count);
 	allocatesize_fsb = endoffset_fsb - startoffset_fsb;
@@ -819,6 +816,7 @@ xfs_alloc_file_space(
 	while (allocatesize_fsb && !error) {
 		xfs_fileoff_t	s, e;
 		unsigned int	dblocks, rblocks, resblks;
+		int		nimaps = 1;
 
 		/*
 		 * Determine space reservations for data/realtime.
@@ -884,15 +882,19 @@ xfs_alloc_file_space(
 		if (error)
 			break;
 
-		allocated_fsb = imapp->br_blockcount;
-
-		if (nimaps == 0) {
-			error = -ENOSPC;
-			break;
+		/*
+		 * If the allocator cannot find a single free extent large
+		 * enough to cover the start block of the requested range,
+		 * xfs_bmapi_write will return 0 but leave *nimaps set to 0.
+		 *
+		 * In that case we simply need to keep looping with the same
+		 * startoffset_fsb so that one of the following allocations
+		 * will eventually reach the requested range.
+		 */
+		if (nimaps) {
+			startoffset_fsb += imapp->br_blockcount;
+			allocatesize_fsb -= imapp->br_blockcount;
 		}
-
-		startoffset_fsb += allocated_fsb;
-		allocatesize_fsb -= allocated_fsb;
 	}
 
 	return error;
-- 
2.39.3


  parent reply	other threads:[~2024-02-05 22:20 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-05 22:19 [PATCH 6.6 CANDIDATE v2 00/21] xfs backports for 6.6.y (from v6.7) Catherine Hoang
2024-02-05 22:19 ` [PATCH 6.6 CANDIDATE v2 01/21] MAINTAINERS: add Catherine as xfs maintainer for 6.6.y Catherine Hoang
2024-02-05 22:19 ` [PATCH 6.6 CANDIDATE v2 02/21] xfs: bump max fsgeom struct version Catherine Hoang
2024-02-05 22:19 ` [PATCH 6.6 CANDIDATE v2 03/21] xfs: hoist freeing of rt data fork extent mappings Catherine Hoang
2024-02-05 22:19 ` [PATCH 6.6 CANDIDATE v2 04/21] xfs: prevent rt growfs when quota is enabled Catherine Hoang
2024-02-05 22:19 ` [PATCH 6.6 CANDIDATE v2 05/21] xfs: rt stubs should return negative errnos when rt disabled Catherine Hoang
2024-02-05 22:19 ` [PATCH 6.6 CANDIDATE v2 06/21] xfs: fix units conversion error in xfs_bmap_del_extent_delay Catherine Hoang
2024-02-05 22:19 ` [PATCH 6.6 CANDIDATE v2 07/21] xfs: make sure maxlen is still congruent with prod when rounding down Catherine Hoang
2024-02-05 22:19 ` [PATCH 6.6 CANDIDATE v2 08/21] xfs: introduce protection for drop nlink Catherine Hoang
2024-02-05 22:19 ` Catherine Hoang [this message]
2024-02-05 22:20 ` [PATCH 6.6 CANDIDATE v2 10/21] xfs: allow read IO and FICLONE to run concurrently Catherine Hoang
2024-02-05 22:20 ` [PATCH 6.6 CANDIDATE v2 11/21] xfs: factor out xfs_defer_pending_abort Catherine Hoang
2024-02-05 22:20 ` [PATCH 6.6 CANDIDATE v2 12/21] xfs: abort intent items when recovery intents fail Catherine Hoang
2024-02-05 22:20 ` [PATCH 6.6 CANDIDATE v2 13/21] xfs: only remap the written blocks in xfs_reflink_end_cow_extent Catherine Hoang
2024-02-05 22:20 ` [PATCH 6.6 CANDIDATE v2 14/21] xfs: up(ic_sema) if flushing data device fails Catherine Hoang
2024-02-05 22:20 ` [PATCH 6.6 CANDIDATE v2 15/21] xfs: fix internal error from AGFL exhaustion Catherine Hoang
2024-02-05 22:20 ` [PATCH 6.6 CANDIDATE v2 16/21] xfs: fix again select in kconfig XFS_ONLINE_SCRUB_STATS Catherine Hoang
2024-02-05 22:20 ` [PATCH 6.6 CANDIDATE v2 17/21] xfs: inode recovery does not validate the recovered inode Catherine Hoang
2024-02-05 22:20 ` [PATCH 6.6 CANDIDATE v2 18/21] xfs: clean up dqblk extraction Catherine Hoang
2024-02-05 22:20 ` [PATCH 6.6 CANDIDATE v2 19/21] xfs: dquot recovery does not validate the recovered dquot Catherine Hoang
2024-02-05 22:20 ` [PATCH 6.6 CANDIDATE v2 20/21] xfs: clean up FS_XFLAG_REALTIME handling in xfs_ioctl_setattr_xflags Catherine Hoang
2024-02-05 22:20 ` [PATCH 6.6 CANDIDATE v2 21/21] xfs: respect the stable writes flag on the RT device Catherine Hoang
2024-02-06  5:23 ` [PATCH 6.6 CANDIDATE v2 00/21] xfs backports for 6.6.y (from v6.7) Chandan Babu R

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=20240205222011.95476-10-catherine.hoang@oracle.com \
    --to=catherine.hoang@oracle.com \
    --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