diff mbox series

[v2,2/4] btrfs: volumes: Add comment for find_free_dev_extent_start()

Message ID 20190719065144.15263-3-wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series Fix for btrfs/156 failure and misc enhancements relocated to relocation | expand

Commit Message

Qu Wenruo July 19, 2019, 6:51 a.m. UTC
Since commit 6df9a95e6339 ("Btrfs: make the chunk allocator completely tree lockless")
we search commit root of device tree to avoid deadlock.

This introduced a safety feature, find_free_dev_extent_start() won't
use dev extents which just get freed in current transaction.

This safety feature makes sure we won't allocate new block group using
just freed dev extents to break CoW.

However this feature also makes find_free_dev_extent_start() not
reliable reporting free device space.
Just add such comment to make later viewer careful about this behavior.

This behavior makes one caller, btrfs_can_relocate() unreliable
determining the device free space.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/volumes.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Johannes Thumshirn July 19, 2019, 9:47 a.m. UTC | #1
Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>

Btw: this comment block lacks a second '*' at the start to be valid kernel doc

-/*
+/**
  * find_free_dev_extent_start - find free space in the specified device
diff mbox series

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index b3fae492912d..41811522c4a3 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1546,6 +1546,12 @@  static bool contains_pending_extent(struct btrfs_device *device, u64 *start,
  * @len is used to store the size of the free space that we find.
  * But if we don't find suitable free space, it is used to store the size of
  * the max free space.
+ *
+ * NOTE: This function will search *commit* root of device tree, and does extra
+ * check to ensure dev extents are not double allocated.
+ * This makes the function safe to allocate dev extents but may not report
+ * correct usable device space, as device extent freed in current transaction
+ * is not reported as avaiable.
  */
 static int find_free_dev_extent_start(struct btrfs_device *device,
 				u64 num_bytes, u64 search_start, u64 *start,