From: Christoph Hellwig <hch@lst.de>
To: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: [PATCH 15/16] btrfs: refactor the zoned device handling in cow_file_range
Date: Tue, 23 May 2023 10:13:21 +0200 [thread overview]
Message-ID: <20230523081322.331337-16-hch@lst.de> (raw)
In-Reply-To: <20230523081322.331337-1-hch@lst.de>
Handling of the done_offset to cow_file_range is a bit confusing, as
it is not updated at all when the function succeeds, and the -EAGAIN
status is used bother for the case where we need to wait for a zone
finish and the one where the allocation was partially successful.
Change the calling convention so that done_offset is always updated,
and 0 is returned if some allocation was successful (partial allocation
can still only happen for zoned devices), and -EAGAIN is only returned
when the caller needs to wait for a zone finish.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/btrfs/inode.c | 53 ++++++++++++++++++++++++------------------------
1 file changed, 27 insertions(+), 26 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 786b88ac0fdd35..c94eb571ba4b48 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1403,7 +1403,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
unsigned clear_bits;
unsigned long page_ops;
bool extent_reserved = false;
- int ret = 0;
+ int ret;
if (btrfs_is_free_space_inode(inode)) {
ret = -EINVAL;
@@ -1462,7 +1462,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
* inline extent or a compressed extent.
*/
unlock_page(locked_page);
- goto out;
+ goto done;
} else if (ret < 0) {
goto out_unlock;
}
@@ -1491,6 +1491,23 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
ret = btrfs_reserve_extent(root, cur_alloc_size, cur_alloc_size,
min_alloc_size, 0, alloc_hint,
&ins, 1, 1);
+ if (ret == -EAGAIN) {
+ /*
+ * For zoned devices, let the caller retry after writing
+ * out the already allocated regions or waiting for a
+ * zone to finish if no allocation was possible at all.
+ *
+ * Else convert to -ENOSPC since the caller cannot
+ * retry.
+ */
+ if (btrfs_is_zoned(fs_info)) {
+ if (start == orig_start)
+ return -EAGAIN;
+ *done_offset = start - 1;
+ return 0;
+ }
+ ret = -ENOSPC;
+ }
if (ret < 0)
goto out_unlock;
cur_alloc_size = ins.offset;
@@ -1571,8 +1588,10 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
if (ret)
goto out_unlock;
}
-out:
- return ret;
+done:
+ if (done_offset)
+ *done_offset = end;
+ return 0;
out_drop_extent_cache:
btrfs_drop_extent_map_range(inode, start, start + ram_size - 1, false);
@@ -1580,21 +1599,6 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
btrfs_dec_block_group_reservations(fs_info, ins.objectid);
btrfs_free_reserved_extent(fs_info, ins.objectid, ins.offset, 1);
out_unlock:
- /*
- * If done_offset is non-NULL and ret == -EAGAIN, we expect the
- * caller to write out the successfully allocated region and retry.
- */
- if (done_offset && ret == -EAGAIN) {
- if (orig_start < start)
- *done_offset = start - 1;
- else
- *done_offset = start;
- return ret;
- } else if (ret == -EAGAIN) {
- /* Convert to -ENOSPC since the caller cannot retry. */
- ret = -ENOSPC;
- }
-
/*
* Now, we have three regions to clean up:
*
@@ -1826,23 +1830,20 @@ static noinline int run_delalloc_zoned(struct btrfs_inode *inode,
while (start <= end) {
ret = cow_file_range(inode, locked_page, start, end, page_started,
nr_written, 0, &done_offset);
- if (ret && ret != -EAGAIN)
- return ret;
-
if (*page_started) {
ASSERT(ret == 0);
return 0;
}
+ if (ret == -EAGAIN) {
+ ASSERT(btrfs_is_zoned(inode->root->fs_info));
- if (ret == 0)
- done_offset = end;
-
- if (done_offset == start) {
wait_on_bit_io(&inode->root->fs_info->flags,
BTRFS_FS_NEED_ZONE_FINISH,
TASK_UNINTERRUPTIBLE);
continue;
}
+ if (ret)
+ return ret;
extent_write_locked_range(&inode->vfs_inode, locked_page, start,
done_offset, wbc);
--
2.39.2
next prev parent reply other threads:[~2023-05-23 8:16 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-23 8:13 writeback fixlets and tidyups Christoph Hellwig
2023-05-23 8:13 ` [PATCH 01/16] btrfs: fix range_end calculation in extent_write_locked_range Christoph Hellwig
2023-05-29 17:13 ` David Sterba
2023-05-30 13:13 ` David Sterba
2023-05-30 14:23 ` Christoph Hellwig
2023-05-23 8:13 ` [PATCH 02/16] btrfs: factor out a btrfs_verify_page helper Christoph Hellwig
2023-05-23 9:23 ` Qu Wenruo
2023-05-23 11:38 ` Christoph Hellwig
2023-05-23 10:16 ` Anand Jain
2023-05-23 11:39 ` Christoph Hellwig
2023-05-23 11:47 ` Anand Jain
2023-05-23 11:54 ` Christoph Hellwig
2023-05-29 17:34 ` David Sterba
2023-05-23 8:13 ` [PATCH 03/16] btrfs: unify fsverify vs other read error handling in end_page_read Christoph Hellwig
2023-05-29 17:39 ` David Sterba
2023-05-23 8:13 ` [PATCH 04/16] btrfs: don't check PageError in btrfs_verify_page Christoph Hellwig
2023-05-23 8:13 ` [PATCH 05/16] btrfs: don't fail writeback when allocating the compression context fails Christoph Hellwig
2023-05-23 8:13 ` [PATCH 06/16] btrfs: rename cow_file_range_async to run_delalloc_compressed Christoph Hellwig
2023-05-23 10:23 ` Anand Jain
2023-05-23 8:13 ` [PATCH 07/16] btrfs: don't check PageError in __extent_writepage Christoph Hellwig
2023-05-23 8:13 ` [PATCH 08/16] btrfs: stop setting PageError in the data I/O path Christoph Hellwig
2023-05-29 17:52 ` David Sterba
2023-05-30 5:45 ` Christoph Hellwig
2023-05-30 6:08 ` Matthew Wilcox
2023-05-30 13:34 ` David Sterba
2023-05-30 14:26 ` Christoph Hellwig
2023-05-30 13:23 ` David Sterba
2023-05-30 14:24 ` Christoph Hellwig
2023-05-23 8:13 ` [PATCH 09/16] btrfs: remove PAGE_SET_ERROR Christoph Hellwig
2023-05-23 8:13 ` [PATCH 10/16] btrfs: remove non-standard extent handling in __extent_writepage_io Christoph Hellwig
2023-05-23 8:13 ` [PATCH 11/16] btrfs: move nr_to_write to __extent_writepage Christoph Hellwig
2023-05-23 10:30 ` Anand Jain
2023-05-23 8:13 ` [PATCH 12/16] btrfs: only call __extent_writepage_io from extent_write_locked_range Christoph Hellwig
2023-05-23 8:13 ` [PATCH 13/16] btrfs: don't treat zoned writeback as being from an async helper thread Christoph Hellwig
2023-05-23 8:13 ` [PATCH 14/16] btrfs: don't redirty the locked page for extent_write_locked_range Christoph Hellwig
2023-05-23 8:13 ` Christoph Hellwig [this message]
2023-05-23 8:13 ` [PATCH 16/16] btrfs: split page locking out of __process_pages_contig Christoph Hellwig
2023-05-23 23:27 ` kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2023-05-31 6:04 writeback fixlets and tidyups v2 Christoph Hellwig
2023-05-31 6:05 ` [PATCH 15/16] btrfs: refactor the zoned device handling in cow_file_range Christoph Hellwig
2023-06-06 14:20 ` Naohiro Aota
2023-06-07 7:27 ` 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=20230523081322.331337-16-hch@lst.de \
--to=hch@lst.de \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@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;
as well as URLs for NNTP newsgroup(s).