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 5/6] btrfs: move locking and write pointer checking into write_one_eb
Date: Mon, 15 May 2023 21:22:55 +0200 [thread overview]
Message-ID: <20230515192256.29006-6-hch@lst.de> (raw)
In-Reply-To: <20230515192256.29006-1-hch@lst.de>
Currently only submit_eb_page contains handling for checking against the
write pointer on zoned devices. This is ok as there is no support for
block size < PAGE_SIZE with zoned devices at the moment, but prevents
us from easily adding new callers of write_one_eb without breaking zoned
device support.
Move the call tolock_extent_buffer_for_io as well as the write pointer
checking and related code into write_one_eb. To be able to do this,
write_one_eb now needs to set the eb_context pointer if the caller
passed in a non-NULL argument.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/btrfs/extent_io.c | 69 +++++++++++++++++++++-----------------------
1 file changed, 33 insertions(+), 36 deletions(-)
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 1205b3a3147e7d..c291fc728db047 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -1759,12 +1759,39 @@ static void prepare_eb_write(struct extent_buffer *eb)
}
}
-static noinline_for_stack void write_one_eb(struct extent_buffer *eb,
- struct writeback_control *wbc)
+static noinline_for_stack int write_one_eb(struct extent_buffer *eb,
+ struct writeback_control *wbc,
+ struct extent_buffer **eb_context)
{
struct btrfs_fs_info *fs_info = eb->fs_info;
+ struct btrfs_block_group *zoned_bg = NULL;
struct btrfs_bio *bbio;
+ if (!btrfs_check_meta_write_pointer(eb->fs_info, eb, &zoned_bg)) {
+ /*
+ * If for_sync, this hole will be filled with
+ * trasnsaction commit.
+ */
+ if (wbc->sync_mode == WB_SYNC_ALL && !wbc->for_sync)
+ return -EAGAIN;
+ return 0;
+ }
+
+ if (eb_context)
+ *eb_context = eb;
+
+ if (!lock_extent_buffer_for_io(eb, wbc)) {
+ btrfs_revert_meta_write_pointer(zoned_bg, eb);
+ return 0;
+ }
+
+ /*
+ * A non-NULL zoned_bg implies zoned mode and that we are writing the
+ * last possible block in the zone.
+ */
+ if (zoned_bg)
+ btrfs_schedule_zone_finish_bg(zoned_bg, eb);
+
prepare_eb_write(eb);
bbio = btrfs_bio_alloc(INLINE_EXTENT_BUFFER_PAGES,
@@ -1801,6 +1828,7 @@ static noinline_for_stack void write_one_eb(struct extent_buffer *eb,
}
}
btrfs_submit_bio(bbio, 0);
+ return 1;
}
/*
@@ -1868,11 +1896,8 @@ static int submit_eb_subpage(struct page *page, struct writeback_control *wbc)
*/
if (!eb)
continue;
-
- if (lock_extent_buffer_for_io(eb, wbc)) {
- write_one_eb(eb, wbc);
+ if (write_one_eb(eb, wbc, NULL) > 0)
submitted++;
- }
free_extent_buffer(eb);
}
return submitted;
@@ -1902,7 +1927,6 @@ static int submit_eb_page(struct page *page, struct writeback_control *wbc,
struct extent_buffer **eb_context)
{
struct address_space *mapping = page->mapping;
- struct btrfs_block_group *cache = NULL;
struct extent_buffer *eb;
int ret;
@@ -1937,36 +1961,9 @@ static int submit_eb_page(struct page *page, struct writeback_control *wbc,
spin_unlock(&mapping->private_lock);
if (!ret)
return 0;
-
- if (!btrfs_check_meta_write_pointer(eb->fs_info, eb, &cache)) {
- /*
- * If for_sync, this hole will be filled with
- * trasnsaction commit.
- */
- if (wbc->sync_mode == WB_SYNC_ALL && !wbc->for_sync)
- ret = -EAGAIN;
- else
- ret = 0;
- free_extent_buffer(eb);
- return ret;
- }
-
- *eb_context = eb;
-
- if (!lock_extent_buffer_for_io(eb, wbc)) {
- btrfs_revert_meta_write_pointer(cache, eb);
- free_extent_buffer(eb);
- return 0;
- }
- if (cache) {
- /*
- * Implies write in zoned mode. Mark the last eb in a block group.
- */
- btrfs_schedule_zone_finish_bg(cache, eb);
- }
- write_one_eb(eb, wbc);
+ ret = write_one_eb(eb, wbc, eb_context);
free_extent_buffer(eb);
- return 1;
+ return ret;
}
int btree_write_cache_pages(struct address_space *mapping,
--
2.39.2
next prev parent reply other threads:[~2023-05-15 19:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-15 19:22 simplify dirty buffer tracking Christoph Hellwig
2023-05-15 19:22 ` [PATCH 1/6] btrfs: use a linked list for tracking per-transaction/log dirty buffers Christoph Hellwig
2023-05-17 10:40 ` Filipe Manana
2023-05-17 12:21 ` Christoph Hellwig
2023-05-17 16:24 ` Filipe Manana
2023-05-17 16:37 ` Christoph Hellwig
2023-05-15 19:22 ` [PATCH 2/6] btrfs: remove convert_extent_bit Christoph Hellwig
2023-05-15 19:22 ` [PATCH 3/6] btrfs: directly wait for buffer writeback completion in btrfs_wait_buffers Christoph Hellwig
2023-05-15 19:22 ` [PATCH 4/6] btrfs: move dropping the bg reference out of submit_eb_page Christoph Hellwig
2023-05-15 19:22 ` Christoph Hellwig [this message]
2023-05-15 19:22 ` [PATCH 6/6] btrfs: bypass filemap_fdatawrite_range in btrfs_write_buffers 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=20230515192256.29006-6-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