Commit 6731212836059c7ac3575e21c499380e795516a9
Committed by
Greg Kroah-Hartman
1 parent
78418b8673
Exists in
smarct4x-processor-sdk-04.01.00.06
and in
1 other branch
Btrfs: fix lockdep warning about log_mutex
[ Upstream commit 781feef7e6befafd4d9787d1f7ada1f9ccd504e4 ] While checking INODE_REF/INODE_EXTREF for a corner case, we may acquire a different inode's log_mutex with holding the current inode's log_mutex, and lockdep has complained this with a possilble deadlock warning. Fix this by using mutex_lock_nested() when processing the other inode's log_mutex. Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Liu Bo <bo.li.liu@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Showing 1 changed file with 10 additions and 3 deletions Side-by-side Diff
fs/btrfs/tree-log.c
... | ... | @@ -37,6 +37,7 @@ |
37 | 37 | */ |
38 | 38 | #define LOG_INODE_ALL 0 |
39 | 39 | #define LOG_INODE_EXISTS 1 |
40 | +#define LOG_OTHER_INODE 2 | |
40 | 41 | |
41 | 42 | /* |
42 | 43 | * directory trouble cases |
... | ... | @@ -4623,7 +4624,7 @@ |
4623 | 4624 | if (S_ISDIR(inode->i_mode) || |
4624 | 4625 | (!test_bit(BTRFS_INODE_NEEDS_FULL_SYNC, |
4625 | 4626 | &BTRFS_I(inode)->runtime_flags) && |
4626 | - inode_only == LOG_INODE_EXISTS)) | |
4627 | + inode_only >= LOG_INODE_EXISTS)) | |
4627 | 4628 | max_key.type = BTRFS_XATTR_ITEM_KEY; |
4628 | 4629 | else |
4629 | 4630 | max_key.type = (u8)-1; |
... | ... | @@ -4647,7 +4648,13 @@ |
4647 | 4648 | return ret; |
4648 | 4649 | } |
4649 | 4650 | |
4650 | - mutex_lock(&BTRFS_I(inode)->log_mutex); | |
4651 | + if (inode_only == LOG_OTHER_INODE) { | |
4652 | + inode_only = LOG_INODE_EXISTS; | |
4653 | + mutex_lock_nested(&BTRFS_I(inode)->log_mutex, | |
4654 | + SINGLE_DEPTH_NESTING); | |
4655 | + } else { | |
4656 | + mutex_lock(&BTRFS_I(inode)->log_mutex); | |
4657 | + } | |
4651 | 4658 | |
4652 | 4659 | /* |
4653 | 4660 | * a brute force approach to making sure we get the most uptodate |
... | ... | @@ -4799,7 +4806,7 @@ |
4799 | 4806 | * unpin it. |
4800 | 4807 | */ |
4801 | 4808 | err = btrfs_log_inode(trans, root, other_inode, |
4802 | - LOG_INODE_EXISTS, | |
4809 | + LOG_OTHER_INODE, | |
4803 | 4810 | 0, LLONG_MAX, ctx); |
4804 | 4811 | iput(other_inode); |
4805 | 4812 | if (err) |