Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: convert: prevent data chunks to go beyond device size
@ 2025-10-24 23:30 Qu Wenruo
  2025-10-30  4:16 ` Yuwei Han
  2025-10-31  2:47 ` David Sterba
  0 siblings, 2 replies; 5+ messages in thread
From: Qu Wenruo @ 2025-10-24 23:30 UTC (permalink / raw)
  To: linux-btrfs

[BUG]
There is a bug report that kernel is rejecting a converted btrfs that
has dev extents beyond device boundary.

The invovled device extent is at 999627694980, length is 30924800,
meanwhile the device is 999658557440.

The device is size not aligned to 64K, meanwhile the dev extent is
aligned to 64K.

[CAUSE]
For converted btrfs, the source fs has all its freedom to choose its
size, as long as it's aligned to the fs block size.

So when adding new converted data block groups we need to do extra
alignment, but in make_convert_data_block_groups() we are rounding up
the end, which can exceed the device size.

[FIX]
Instead of rounding up to stripe boundary, rounding it down to prevent
going beyond the device boundary.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 convert/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/convert/main.c b/convert/main.c
index e279e3d40c5f..5c40c08ddd72 100644
--- a/convert/main.c
+++ b/convert/main.c
@@ -948,8 +948,8 @@ static int make_convert_data_block_groups(struct btrfs_trans_handle *trans,
 			u64 cur_backup = cur;
 
 			len = min(max_chunk_size,
-				  round_up(cache->start + cache->size,
-					   BTRFS_STRIPE_LEN) - cur);
+				  round_down(cache->start + cache->size,
+					     BTRFS_STRIPE_LEN) - cur);
 			ret = btrfs_alloc_data_chunk(trans, fs_info, &cur_backup, len);
 			if (ret < 0)
 				break;
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-10-31  2:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-24 23:30 [PATCH] btrfs-progs: convert: prevent data chunks to go beyond device size Qu Wenruo
2025-10-30  4:16 ` Yuwei Han
2025-10-30 13:24   ` Filipe Manana
2025-10-30 20:32     ` Qu Wenruo
2025-10-31  2:47 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox