Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bcachefs: kill INODE_LOCK, use lock_two_nondirectories()

In an ideal world, we'd have a common helper that could be used for
sorting a list of inodes into the correct lock order, and then the same
lock ordering could be used for any type of inode lock, not just
i_rwsem.

But the lock ordering rules for i_rwsem are a bit complicated, so -
abandon that dream for now and do it the more standard way.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>

+6 -9
+4 -2
fs/bcachefs/fs-io.c
··· 861 861 abs(pos_src - pos_dst) < len) 862 862 return -EINVAL; 863 863 864 - bch2_lock_inodes(INODE_LOCK|INODE_PAGECACHE_BLOCK, src, dst); 864 + lock_two_nondirectories(&src->v, &dst->v); 865 + bch2_lock_inodes(INODE_PAGECACHE_BLOCK, src, dst); 865 866 866 867 inode_dio_wait(&src->v); 867 868 inode_dio_wait(&dst->v); ··· 915 914 ret = bch2_flush_inode(c, dst); 916 915 err: 917 916 bch2_quota_reservation_put(c, dst, &quota_res); 918 - bch2_unlock_inodes(INODE_LOCK|INODE_PAGECACHE_BLOCK, src, dst); 917 + bch2_unlock_inodes(INODE_PAGECACHE_BLOCK, src, dst); 918 + unlock_two_nondirectories(&src->v, &dst->v); 919 919 920 920 return bch2_err_class(ret); 921 921 }
+2 -7
fs/bcachefs/fs.h
··· 77 77 } 78 78 79 79 enum bch_inode_lock_op { 80 - INODE_LOCK = (1U << 0), 81 - INODE_PAGECACHE_BLOCK = (1U << 1), 82 - INODE_UPDATE_LOCK = (1U << 2), 80 + INODE_PAGECACHE_BLOCK = (1U << 0), 81 + INODE_UPDATE_LOCK = (1U << 1), 83 82 }; 84 83 85 84 #define bch2_lock_inodes(_locks, ...) \ ··· 90 91 \ 91 92 for (i = 1; i < ARRAY_SIZE(a); i++) \ 92 93 if (a[i] != a[i - 1]) { \ 93 - if ((_locks) & INODE_LOCK) \ 94 - down_write_nested(&a[i]->v.i_rwsem, i); \ 95 94 if ((_locks) & INODE_PAGECACHE_BLOCK) \ 96 95 bch2_pagecache_block_get(a[i]);\ 97 96 if ((_locks) & INODE_UPDATE_LOCK) \ ··· 106 109 \ 107 110 for (i = 1; i < ARRAY_SIZE(a); i++) \ 108 111 if (a[i] != a[i - 1]) { \ 109 - if ((_locks) & INODE_LOCK) \ 110 - up_write(&a[i]->v.i_rwsem); \ 111 112 if ((_locks) & INODE_PAGECACHE_BLOCK) \ 112 113 bch2_pagecache_block_put(a[i]);\ 113 114 if ((_locks) & INODE_UPDATE_LOCK) \