]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: add lockdep annotations for pending_ordered wait event
authorIoannis Angelakopoulos <iangelak@fb.com>
Mon, 25 Jul 2022 22:11:54 +0000 (15:11 -0700)
committerDavid Sterba <dsterba@suse.com>
Mon, 26 Sep 2022 10:27:53 +0000 (12:27 +0200)
In contrast to the num_writers and num_extwriters wait events, the
condition for the pending ordered wait event is signaled in a different
context from the wait event itself. The condition signaling occurs in
btrfs_remove_ordered_extent() in fs/btrfs/ordered-data.c while the wait
event is implemented in btrfs_commit_transaction() in
fs/btrfs/transaction.c

Thus the thread signaling the condition has to acquire the lockdep map
as a reader at the start of btrfs_remove_ordered_extent() and release it
after it has signaled the condition. In this case some dependencies
might be left out due to the placement of the annotation, but it is
better than no annotation at all.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Ioannis Angelakopoulos <iangelak@fb.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/disk-io.c
fs/btrfs/ordered-data.c
fs/btrfs/transaction.c

index f8172e269f03788f0d3c9830c925adbb95dc1231..8bd9a6d5ade6111c9db83a6e25e3142a8485faf7 100644 (file)
@@ -1099,6 +1099,7 @@ struct btrfs_fs_info {
        struct lockdep_map btrfs_trans_num_writers_map;
        struct lockdep_map btrfs_trans_num_extwriters_map;
        struct lockdep_map btrfs_state_change_map[4];
+       struct lockdep_map btrfs_trans_pending_ordered_map;
 
 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
        spinlock_t ref_verify_lock;
index 68c6cb4e9283d0d3fdb4fd4bfefb5f9a73c9261d..393553fdfed65d334f768b95151a9d87d438a2e4 100644 (file)
@@ -2992,6 +2992,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
 
        btrfs_lockdep_init_map(fs_info, btrfs_trans_num_writers);
        btrfs_lockdep_init_map(fs_info, btrfs_trans_num_extwriters);
+       btrfs_lockdep_init_map(fs_info, btrfs_trans_pending_ordered);
        btrfs_state_lockdep_init_map(fs_info, btrfs_trans_commit_start,
                                     BTRFS_LOCKDEP_TRANS_COMMIT_START);
        btrfs_state_lockdep_init_map(fs_info, btrfs_trans_unblocked,
index 1952ac85222c0bb429fda21162f4d7827149ec12..2a4cb6db42d1c19aa06dd0adbdc98b702722a9d2 100644 (file)
@@ -525,6 +525,7 @@ void btrfs_remove_ordered_extent(struct btrfs_inode *btrfs_inode,
        struct rb_node *node;
        bool pending;
 
+       btrfs_lockdep_acquire(fs_info, btrfs_trans_pending_ordered);
        /* This is paired with btrfs_add_ordered_extent. */
        spin_lock(&btrfs_inode->lock);
        btrfs_mod_outstanding_extents(btrfs_inode, -1);
@@ -580,6 +581,8 @@ void btrfs_remove_ordered_extent(struct btrfs_inode *btrfs_inode,
                }
        }
 
+       btrfs_lockdep_release(fs_info, btrfs_trans_pending_ordered);
+
        spin_lock(&root->ordered_extent_lock);
        list_del_init(&entry->root_extent_list);
        root->nr_ordered_extents--;
index d3576f84020d5850be640f0463a17a98545e43f4..6e3b2cb6a04afa3fb9bf032f44bf7c8f6dfb5c55 100644 (file)
@@ -2310,6 +2310,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
         * transaction. Otherwise if this transaction commits before the ordered
         * extents complete we lose logged data after a power failure.
         */
+       btrfs_might_wait_for_event(fs_info, btrfs_trans_pending_ordered);
        wait_event(cur_trans->pending_wait,
                   atomic_read(&cur_trans->pending_ordered) == 0);