diff mbox series

btrfs: fix extent map logging bit not cleared for split maps after dropping range

Message ID 252e68aaa353859c8041305443a988866350cb3c.1677502380.git.fdmanana@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: fix extent map logging bit not cleared for split maps after dropping range | expand

Commit Message

Filipe Manana Feb. 27, 2023, 12:53 p.m. UTC
From: Filipe Manana <fdmanana@suse.com>

At btrfs_drop_extent_map_range() we are clearing the EXTENT_FLAG_LOGGING
bit on a 'flags' variable that was not initialized. This makes static
checkers complain about it, so initialize the 'flags' variable before
clearing the bit.

In practice this has no consequences, because EXTENT_FLAG_LOGGING should
not be set when btrfs_drop_extent_map_range() is called, as an fsync locks
the inode in exclusive mode, locks the inode's mmap semaphore in exclusive
mode too and it always flushes all delalloc.

Also add a comment about why we clear EXTENT_FLAG_LOGGING on a copy of the
flags of the split extent map.

Reported-by: Dan Carpenter <error27@gmail.com>
Link: https://lore.kernel.org/linux-btrfs/Y%2FyipSVozUDEZKow@kili/
Fixes: db21370bffbc ("btrfs: drop extent map range more efficiently")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/extent_map.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

David Sterba Feb. 27, 2023, 6:43 p.m. UTC | #1
On Mon, Feb 27, 2023 at 12:53:56PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> At btrfs_drop_extent_map_range() we are clearing the EXTENT_FLAG_LOGGING
> bit on a 'flags' variable that was not initialized. This makes static
> checkers complain about it, so initialize the 'flags' variable before
> clearing the bit.
> 
> In practice this has no consequences, because EXTENT_FLAG_LOGGING should
> not be set when btrfs_drop_extent_map_range() is called, as an fsync locks
> the inode in exclusive mode, locks the inode's mmap semaphore in exclusive
> mode too and it always flushes all delalloc.
> 
> Also add a comment about why we clear EXTENT_FLAG_LOGGING on a copy of the
> flags of the split extent map.
> 
> Reported-by: Dan Carpenter <error27@gmail.com>
> Link: https://lore.kernel.org/linux-btrfs/Y%2FyipSVozUDEZKow@kili/
> Fixes: db21370bffbc ("btrfs: drop extent map range more efficiently")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Added to misc-next, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
index be94030e1dfb..138afa955370 100644
--- a/fs/btrfs/extent_map.c
+++ b/fs/btrfs/extent_map.c
@@ -763,7 +763,13 @@  void btrfs_drop_extent_map_range(struct btrfs_inode *inode, u64 start, u64 end,
 			goto next;
 		}
 
+		flags = em->flags;
 		clear_bit(EXTENT_FLAG_PINNED, &em->flags);
+		/*
+		 * In case we split the extent map, we want to preserve the
+		 * EXTENT_FLAG_LOGGING flag on our extent map, but we don't want
+		 * it on the new extent maps.
+		 */
 		clear_bit(EXTENT_FLAG_LOGGING, &flags);
 		modified = !list_empty(&em->list);
 
@@ -774,7 +780,6 @@  void btrfs_drop_extent_map_range(struct btrfs_inode *inode, u64 start, u64 end,
 		if (em->start >= start && em_end <= end)
 			goto remove_em;
 
-		flags = em->flags;
 		gen = em->generation;
 		compressed = test_bit(EXTENT_FLAG_COMPRESSED, &em->flags);