diff mbox series

btrfs-progs: properly exclude leaves for lowmem

Message ID 845796bfab85f02919d64908b63f3f7201a2abb3.1609882807.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: properly exclude leaves for lowmem | expand

Commit Message

Josef Bacik Jan. 5, 2021, 9:40 p.m. UTC
The lowmem mode excludes all referenced blocks from the allocator in
order to avoid accidentally overwriting blocks while fixing the file
system.  However for leaves it wouldn't exclude anything, it would just
pin them down, which gets cleaned up on transaction commit.  We're safe
for the first modification, but subsequent modifications could blow up
in our face.  Fix this by properly excluding leaves as well as all of
the nodes.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 check/mode-common.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Su Yue Jan. 6, 2021, 1:42 a.m. UTC | #1
On Wed 06 Jan 2021 at 05:40, Josef Bacik <josef@toxicpanda.com> 
wrote:

> The lowmem mode excludes all referenced blocks from the 
> allocator in
> order to avoid accidentally overwriting blocks while fixing the 
> file
> system.  However for leaves it wouldn't exclude anything, it 
> would just
> pin them down, which gets cleaned up on transaction commit. 
> We're safe
> for the first modification, but subsequent modifications could 
> blow up
> in our face.  Fix this by properly excluding leaves as well as 
> all of
> the nodes.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
>

LGTM.
Reviewed-by: Su Yue <l@damenly.su>
> ---
>  check/mode-common.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/check/mode-common.c b/check/mode-common.c
> index a6489191..ef77b060 100644
> --- a/check/mode-common.c
> +++ b/check/mode-common.c
> @@ -667,8 +667,12 @@ static int traverse_tree_blocks(struct 
> extent_buffer *eb, int tree_root, int pin
>
>  			/* If we aren't the tree root don't read the block */
>  			if (level == 1 && !tree_root) {
> -				btrfs_pin_extent(gfs_info, bytenr,
> -						 gfs_info->nodesize);
>
> +				if (pin)
> +					btrfs_pin_extent(gfs_info, bytenr,
> +							 gfs_info->nodesize);
> +				else
> +					set_extent_dirty(tree, bytenr,
> +							 gfs_info->nodesize);
>  				continue;
>  			}
David Sterba Jan. 6, 2021, 4:17 p.m. UTC | #2
On Tue, Jan 05, 2021 at 04:40:18PM -0500, Josef Bacik wrote:
> The lowmem mode excludes all referenced blocks from the allocator in
> order to avoid accidentally overwriting blocks while fixing the file
> system.  However for leaves it wouldn't exclude anything, it would just
> pin them down, which gets cleaned up on transaction commit.  We're safe
> for the first modification, but subsequent modifications could blow up
> in our face.  Fix this by properly excluding leaves as well as all of
> the nodes.

This sounds like a test case can be easily written.
diff mbox series

Patch

diff --git a/check/mode-common.c b/check/mode-common.c
index a6489191..ef77b060 100644
--- a/check/mode-common.c
+++ b/check/mode-common.c
@@ -667,8 +667,12 @@  static int traverse_tree_blocks(struct extent_buffer *eb, int tree_root, int pin
 
 			/* If we aren't the tree root don't read the block */
 			if (level == 1 && !tree_root) {
-				btrfs_pin_extent(gfs_info, bytenr,
-						 gfs_info->nodesize);
+				if (pin)
+					btrfs_pin_extent(gfs_info, bytenr,
+							 gfs_info->nodesize);
+				else
+					set_extent_dirty(tree, bytenr,
+							 gfs_info->nodesize);
 				continue;
 			}