Commit f18cc978 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David Sterba

btrfs: fix dirty_metadata_bytes for redirtied buffers

dirty_metadata_bytes is decremented in both places that clear the dirty
bit in a buffer, but only incremented in btrfs_mark_buffer_dirty, which
means that a buffer that is redirtied using btrfs_redirty_list_add won't
be added to dirty_metadata_bytes, but it will be subtracted when written
out, leading an inconsistency in the counter.

Move the dirty_metadata_bytes from btrfs_mark_buffer_dirty into
set_extent_buffer_dirty to also account for the redirty case, and remove
the now unused set_extent_buffer_dirty return value.

Fixes: d3575156 ("btrfs: zoned: redirty released extent buffers")
CC: stable@vger.kernel.org # 5.15+
Reviewed-by: default avatarNaohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent bb5167e6
...@@ -4621,7 +4621,6 @@ void btrfs_mark_buffer_dirty(struct extent_buffer *buf) ...@@ -4621,7 +4621,6 @@ void btrfs_mark_buffer_dirty(struct extent_buffer *buf)
{ {
struct btrfs_fs_info *fs_info = buf->fs_info; struct btrfs_fs_info *fs_info = buf->fs_info;
u64 transid = btrfs_header_generation(buf); u64 transid = btrfs_header_generation(buf);
int was_dirty;
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
/* /*
...@@ -4636,11 +4635,7 @@ void btrfs_mark_buffer_dirty(struct extent_buffer *buf) ...@@ -4636,11 +4635,7 @@ void btrfs_mark_buffer_dirty(struct extent_buffer *buf)
if (transid != fs_info->generation) if (transid != fs_info->generation)
WARN(1, KERN_CRIT "btrfs transid mismatch buffer %llu, found %llu running %llu\n", WARN(1, KERN_CRIT "btrfs transid mismatch buffer %llu, found %llu running %llu\n",
buf->start, transid, fs_info->generation); buf->start, transid, fs_info->generation);
was_dirty = set_extent_buffer_dirty(buf); set_extent_buffer_dirty(buf);
if (!was_dirty)
percpu_counter_add_batch(&fs_info->dirty_metadata_bytes,
buf->len,
fs_info->dirty_metadata_batch);
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
/* /*
* btrfs_check_leaf() won't check item data if we don't have WRITTEN * btrfs_check_leaf() won't check item data if we don't have WRITTEN
......
...@@ -4148,7 +4148,7 @@ void btrfs_clear_buffer_dirty(struct btrfs_trans_handle *trans, ...@@ -4148,7 +4148,7 @@ void btrfs_clear_buffer_dirty(struct btrfs_trans_handle *trans,
WARN_ON(atomic_read(&eb->refs) == 0); WARN_ON(atomic_read(&eb->refs) == 0);
} }
bool set_extent_buffer_dirty(struct extent_buffer *eb) void set_extent_buffer_dirty(struct extent_buffer *eb)
{ {
int i; int i;
int num_pages; int num_pages;
...@@ -4183,13 +4183,14 @@ bool set_extent_buffer_dirty(struct extent_buffer *eb) ...@@ -4183,13 +4183,14 @@ bool set_extent_buffer_dirty(struct extent_buffer *eb)
eb->start, eb->len); eb->start, eb->len);
if (subpage) if (subpage)
unlock_page(eb->pages[0]); unlock_page(eb->pages[0]);
percpu_counter_add_batch(&eb->fs_info->dirty_metadata_bytes,
eb->len,
eb->fs_info->dirty_metadata_batch);
} }
#ifdef CONFIG_BTRFS_DEBUG #ifdef CONFIG_BTRFS_DEBUG
for (i = 0; i < num_pages; i++) for (i = 0; i < num_pages; i++)
ASSERT(PageDirty(eb->pages[i])); ASSERT(PageDirty(eb->pages[i]));
#endif #endif
return was_dirty;
} }
void clear_extent_buffer_uptodate(struct extent_buffer *eb) void clear_extent_buffer_uptodate(struct extent_buffer *eb)
......
...@@ -262,7 +262,7 @@ void extent_buffer_bitmap_set(const struct extent_buffer *eb, unsigned long star ...@@ -262,7 +262,7 @@ void extent_buffer_bitmap_set(const struct extent_buffer *eb, unsigned long star
void extent_buffer_bitmap_clear(const struct extent_buffer *eb, void extent_buffer_bitmap_clear(const struct extent_buffer *eb,
unsigned long start, unsigned long pos, unsigned long start, unsigned long pos,
unsigned long len); unsigned long len);
bool set_extent_buffer_dirty(struct extent_buffer *eb); void set_extent_buffer_dirty(struct extent_buffer *eb);
void set_extent_buffer_uptodate(struct extent_buffer *eb); void set_extent_buffer_uptodate(struct extent_buffer *eb);
void clear_extent_buffer_uptodate(struct extent_buffer *eb); void clear_extent_buffer_uptodate(struct extent_buffer *eb);
int extent_buffer_under_io(const struct extent_buffer *eb); int extent_buffer_under_io(const struct extent_buffer *eb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment