Skip to content

Commit 28b737f

Browse files
Liu Bomasoncl
authored andcommitted
Btrfs: clarify do_chunk_alloc()'s return value
Function start_transaction() can return ERR_PTR(1) when flush is BTRFS_RESERVE_FLUSH_LIMIT, so the call graph is start_transaction (return ERR_PTR(1)) -> btrfs_block_rsv_add (return 1) -> reserve_metadata_bytes (return 1) -> flush_space (return 1) -> do_chunk_alloc (return 1) With BTRFS_RESERVE_FLUSH_LIMIT, if flush_space is already on the flush_state of ALLOC_CHUNK and it successfully allocates a new chunk, then instead of trying to reserve space again, reserve_metadata_bytes returns 1 immediately. Eventually the callers who call start_transaction() usually just do the IS_ERR() check which ERR_PTR(1) can pass, then it'll get a panic when dereferencing a pointer which is ERR_PTR(1). The following patch fixes the above problem. "btrfs: flush_space: treat return value of do_chunk_alloc properly" https://patchwork.kernel.org/patch/7778651/ This add comments to clarify do_chunk_alloc()'s return value. Signed-off-by: Liu Bo <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent 9e7cc91 commit 28b737f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

fs/btrfs/extent-tree.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4457,6 +4457,15 @@ void check_system_chunk(struct btrfs_trans_handle *trans,
44574457
}
44584458
}
44594459

4460+
/*
4461+
* If force is CHUNK_ALLOC_FORCE:
4462+
* - return 1 if it successfully allocates a chunk,
4463+
* - return errors including -ENOSPC otherwise.
4464+
* If force is NOT CHUNK_ALLOC_FORCE:
4465+
* - return 0 if it doesn't need to allocate a new chunk,
4466+
* - return 1 if it successfully allocates a chunk,
4467+
* - return errors including -ENOSPC otherwise.
4468+
*/
44604469
static int do_chunk_alloc(struct btrfs_trans_handle *trans,
44614470
struct btrfs_root *extent_root, u64 flags, int force)
44624471
{

0 commit comments

Comments
 (0)