More lockdep annotations
David Sterba
maintainercover More lockdep annotations
Lockdep annotations are better than comments about necessary locks.
David Sterba (5):
btrfs: tests: add locks around add_extent_mapping
btrfs: assert extent map tree lock in add_extent_mapping
btrfs: assert tree mod log lock in __tree_mod_log_insert
btrfs: assert delayed ref lock in btrfs_find_delayed_ref_head
btrfs: assert bio list lock in merge_rbio
fs/btrfs/ctree.c | 4 ++-- fs/btrfs/delayed-ref.c | 7 ++++--- fs/btrfs/extent_map.c | 2 ++ fs/btrfs/raid56.c | 4 ++-- fs/btrfs/tests/extent-map-tests.c | 22 ++++++++++++++++++++++ 5 files changed, 32 insertions(+), 7 deletions(-)
Signature · 1 line
2.21.0
David Sterba
maintainerPATCH 1/5 btrfs: tests: add locks around add_extent_mapping
There are no concerns about locking during the selftests so the locks are not necessary, but following patches will add lockdep assertions to add_extent_mapping so this is needed in tests too.
--- fs/btrfs/tests/extent-map-tests.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
fs/btrfs/tests/extent-map-tests.c +22 -0
@@ -66,7 +66,9 @@ static int test_case_1(struct btrfs_fs_info *fs_info, em->len =SZ_16K ; em->block_start =0 ; em->block_len =SZ_16K ; +write_lock (&em_tree->lock); ret =add_extent_mapping (em_tree, em,0 ); +write_unlock (&em_tree->lock);if (ret <0 ) {test_err ("cannot add extent range [0, 16K)" ); goto out;
@@ -85,7 +87,9 @@ static int test_case_1(struct btrfs_fs_info *fs_info, em->len =SZ_4K ; em->block_start =SZ_32K ;/* avoid merging */ em->block_len =SZ_4K ; +write_lock (&em_tree->lock); ret =add_extent_mapping (em_tree, em,0 ); +write_unlock (&em_tree->lock);if (ret <0 ) {test_err ("cannot add extent range [16K, 20K)" ); goto out;
@@ -104,7 +108,9 @@ static int test_case_1(struct btrfs_fs_info *fs_info, em->len = len; em->block_start = start; em->block_len = len; +write_lock (&em_tree->lock); ret =btrfs_add_extent_mapping (fs_info, em_tree, &em, em->start, em->len); +write_unlock (&em_tree->lock);if (ret) {test_err ("case1 [%llu %llu]: ret %d" , start, start + len, ret); goto out;
@@ -148,7 +154,9 @@ static int test_case_2(struct btrfs_fs_info *fs_info, em->len =SZ_1K ; em->block_start =EXTENT_MAP_INLINE ; em->block_len = (u64)-1 ; +write_lock (&em_tree->lock); ret =add_extent_mapping (em_tree, em,0 ); +write_unlock (&em_tree->lock);if (ret <0 ) {test_err ("cannot add extent range [0, 1K)" ); goto out;
@@ -167,7 +175,9 @@ static int test_case_2(struct btrfs_fs_info *fs_info, em->len =SZ_4K ; em->block_start =SZ_4K ; em->block_len =SZ_4K ; +write_lock (&em_tree->lock); ret =add_extent_mapping (em_tree, em,0 ); +write_unlock (&em_tree->lock);if (ret <0 ) {test_err ("cannot add extent range [4K, 8K)" ); goto out;
@@ -186,7 +196,9 @@ static int test_case_2(struct btrfs_fs_info *fs_info, em->len =SZ_1K ; em->block_start =EXTENT_MAP_INLINE ; em->block_len = (u64)-1 ; +write_lock (&em_tree->lock); ret =btrfs_add_extent_mapping (fs_info, em_tree, &em, em->start, em->len); +write_unlock (&em_tree->lock);if (ret) {test_err ("case2 [0 1K]: ret %d" , ret); goto out;
@@ -225,7 +237,9 @@ static int __test_case_3(struct btrfs_fs_info *fs_info, em->len =SZ_4K ; em->block_start =SZ_4K ; em->block_len =SZ_4K ; +write_lock (&em_tree->lock); ret =add_extent_mapping (em_tree, em,0 ); +write_unlock (&em_tree->lock);if (ret <0 ) {test_err ("cannot add extent range [4K, 8K)" ); goto out;
@@ -244,7 +258,9 @@ static int __test_case_3(struct btrfs_fs_info *fs_info, em->len =SZ_16K ; em->block_start =0 ; em->block_len =SZ_16K ; +write_lock (&em_tree->lock); ret =btrfs_add_extent_mapping (fs_info, em_tree, &em, start, len); +write_unlock (&em_tree->lock);if (ret) {test_err ("case3 [0x%llx 0x%llx): ret %d" , start, start + len, ret);
@@ -320,7 +336,9 @@ static int __test_case_4(struct btrfs_fs_info *fs_info, em->len =SZ_8K ; em->block_start =0 ; em->block_len =SZ_8K ; +write_lock (&em_tree->lock); ret =add_extent_mapping (em_tree, em,0 ); +write_unlock (&em_tree->lock);if (ret <0 ) {test_err ("cannot add extent range [0, 8K)" ); goto out;
@@ -339,7 +357,9 @@ static int __test_case_4(struct btrfs_fs_info *fs_info, em->len =24 *SZ_1K ; em->block_start =SZ_16K ;/* avoid merging */ em->block_len =24 *SZ_1K ; +write_lock (&em_tree->lock); ret =add_extent_mapping (em_tree, em,0 ); +write_unlock (&em_tree->lock);if (ret <0 ) {test_err ("cannot add extent range [8K, 32K)" ); goto out;
@@ -357,7 +377,9 @@ static int __test_case_4(struct btrfs_fs_info *fs_info, em->len =SZ_32K ; em->block_start =0 ; em->block_len =SZ_32K ; +write_lock (&em_tree->lock); ret =btrfs_add_extent_mapping (fs_info, em_tree, &em, start, len); +write_unlock (&em_tree->lock);if (ret) {test_err ("case4 [0x%llx 0x%llx): ret %d" , start, len, ret);
Signature · 1 line
2.21.0
David Sterba
maintainerPATCH 2/5 btrfs: assert extent map tree lock in add_extent_mapping
In reply to David SterbaAs add_extent_mapping is called from several functions, let's add the lock annotation. The tree is going to be modified so it must be the exclusive lock.
--- fs/btrfs/extent_map.c | 2 ++ 1 file changed, 2 insertions(+)
fs/btrfs/extent_map.c +2 -0
@@ -384,6 +384,8 @@ int add_extent_mapping(struct extent_map_tree *tree, {int ret =0 ; +lockdep_assert_held_exclusive (&tree->lock); + ret =tree_insert (&tree->map, em);if (ret) goto out;
Signature · 1 line
2.21.0
David Sterba
maintainerPATCH 3/5 btrfs: assert tree mod log lock in __tree_mod_log_insert
In reply to David SterbaThe tree is going to be modified so it must be the exclusive lock.
--- fs/btrfs/ctree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/ctree.c +2 -2
@@ -376,8 +376,6 @@ void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,* The 'start address' is the logical address of the *new* root node * for root replace operations, or the logical address of the affected * block for all other operations. -* -* Note: must be called with write lock for fs_info::tree_mod_log_lock. */ static noinline int__tree_mod_log_insert (struct btrfs_fs_info *fs_info,struct tree_mod_elem *tm)
@@ -387,6 +385,8 @@ __tree_mod_log_insert(struct btrfs_fs_info *fs_info, struct tree_mod_elem *tm)struct rb_node *parent =NULL ;struct tree_mod_elem *cur; +lockdep_assert_held_exclusive (&fs_info->tree_mod_log_lock); + tm->seq =btrfs_inc_tree_mod_seq (fs_info); tm_root = &fs_info->tree_mod_log;
Signature · 1 line
2.21.0
David Sterba
maintainerPATCH 4/5 btrfs: assert delayed ref lock in btrfs_find_delayed_ref_head
In reply to David SterbaTurn the comment about required lock into an assertion.
--- fs/btrfs/delayed-ref.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/btrfs/delayed-ref.c +4 -3
@@ -957,13 +957,14 @@ int btrfs_add_delayed_extent_op(struct btrfs_trans_handle *trans, }/* -* this does a simple search for the head node for a given extent. -* It must be called with the delayed ref spinlock held, and it returns -* the head node if any where found, or NULL if not. +* This does a simple search for the head node for a given extent. Returns the +* head node if found, or NULL if not. */ struct btrfs_delayed_ref_head *btrfs_find_delayed_ref_head (struct btrfs_delayed_ref_root *delayed_refs,u64 bytenr) { +lockdep_assert_held (&delayed_refs->lock); +return find_ref_head (delayed_refs, bytenr, false); }
Signature · 1 line
2.21.0
David Sterba
maintainerPATCH 5/5 btrfs: assert bio list lock in merge_rbio
In reply to David SterbaTurn the comment about required lock into an assertion.
--- fs/btrfs/raid56.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/raid56.c +2 -2
@@ -310,12 +310,12 @@ static void steal_rbio(struct btrfs_raid_bio *src, struct btrfs_raid_bio *dest)* merging means we take the bio_list from the victim and * splice it into the destination. The victim should * be discarded afterwards. -* -* must be called with dest->rbio_list_lock held */ static void merge_rbio (struct btrfs_raid_bio *dest,struct btrfs_raid_bio *victim) { +lockdep_assert_held (&dest->bio_list_lock); +bio_list_merge (&dest->bio_list, &victim->bio_list); dest->bio_list_bytes += victim->bio_list_bytes; dest->generic_bio_cnt += victim->generic_bio_cnt;
Signature · 1 line
2.21.0
Quoted 9 lines · David Sterba
Lockdep annotations are better than comments about necessary locks.
David Sterba (5):
btrfs: tests: add locks aroundadd_extent_mapping
btrfs: assert extent map tree lock inadd_extent_mapping
btrfs: assert tree mod log lock in__tree_mod_log_insert
btrfs: assert delayed ref lock inbtrfs_find_delayed_ref_head
btrfs: assert bio list lock inmerge_rbio
Quoted 7 lines
fs/btrfs/ctree.c | 4 ++-- fs/btrfs/delayed-ref.c | 7 ++++--- fs/btrfs/extent_map.c | 2 ++ fs/btrfs/raid56.c | 4 ++-- fs/btrfs/tests/extent-map-tests.c | 22 ++++++++++++++++++++++ 5 files changed, 32 insertions(+), 7 deletions(-)
For the whole series :
Quoted 21 lines · Nikolay Borisov
Quoted 9 lines · David Sterba
Lockdep annotations are better than comments about necessary locks.
David Sterba (5):
btrfs: tests: add locks aroundadd_extent_mapping
btrfs: assert extent map tree lock inadd_extent_mapping
btrfs: assert tree mod log lock in__tree_mod_log_insert
btrfs: assert delayed ref lock inbtrfs_find_delayed_ref_head
btrfs: assert bio list lock inmerge_rbioQuoted 7 lines
fs/btrfs/ctree.c | 4 ++-- fs/btrfs/delayed-ref.c | 7 ++++--- fs/btrfs/extent_map.c | 2 ++ fs/btrfs/raid56.c | 4 ++-- fs/btrfs/tests/extent-map-tests.c | 22 ++++++++++++++++++++++ 5 files changed, 32 insertions(+), 7 deletions(-)
Quoted 3 lines
For the whole series :
Reviewed-by Nikolay Borisov <[email protected]>
Thanks, series moved to misc-next.