bcachefs: kill INODE_LOCK, use lock_two_nondirectories()
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 16 Nov 2023 20:46:50 +0000 (15:46 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 1 Jan 2024 16:47:36 +0000 (11:47 -0500)
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>
fs/bcachefs/fs-io.c
fs/bcachefs/fs.h

index b0e8144ec5500cd37a2d35f71f399c1ebe424d53..31f40e587a4f3ca76d5aa73eb3de53ac5214f548 100644 (file)
@@ -861,7 +861,8 @@ loff_t bch2_remap_file_range(struct file *file_src, loff_t pos_src,
            abs(pos_src - pos_dst) < len)
                return -EINVAL;
 
-       bch2_lock_inodes(INODE_LOCK|INODE_PAGECACHE_BLOCK, src, dst);
+       lock_two_nondirectories(&src->v, &dst->v);
+       bch2_lock_inodes(INODE_PAGECACHE_BLOCK, src, dst);
 
        inode_dio_wait(&src->v);
        inode_dio_wait(&dst->v);
@@ -914,7 +915,8 @@ loff_t bch2_remap_file_range(struct file *file_src, loff_t pos_src,
                ret = bch2_flush_inode(c, dst);
 err:
        bch2_quota_reservation_put(c, dst, &quota_res);
-       bch2_unlock_inodes(INODE_LOCK|INODE_PAGECACHE_BLOCK, src, dst);
+       bch2_unlock_inodes(INODE_PAGECACHE_BLOCK, src, dst);
+       unlock_two_nondirectories(&src->v, &dst->v);
 
        return bch2_err_class(ret);
 }
index 5edf1d4b9e6bdfa9a992bf895727228c79de4267..c3af7225ff693ec9c5af06502e22f3fbc8354fd5 100644 (file)
@@ -77,9 +77,8 @@ static inline int ptrcmp(void *l, void *r)
 }
 
 enum bch_inode_lock_op {
-       INODE_LOCK              = (1U << 0),
-       INODE_PAGECACHE_BLOCK   = (1U << 1),
-       INODE_UPDATE_LOCK       = (1U << 2),
+       INODE_PAGECACHE_BLOCK   = (1U << 0),
+       INODE_UPDATE_LOCK       = (1U << 1),
 };
 
 #define bch2_lock_inodes(_locks, ...)                                  \
@@ -91,8 +90,6 @@ do {                                                                  \
                                                                        \
        for (i = 1; i < ARRAY_SIZE(a); i++)                             \
                if (a[i] != a[i - 1]) {                                 \
-                       if ((_locks) & INODE_LOCK)                      \
-                               down_write_nested(&a[i]->v.i_rwsem, i); \
                        if ((_locks) & INODE_PAGECACHE_BLOCK)           \
                                bch2_pagecache_block_get(a[i]);\
                        if ((_locks) & INODE_UPDATE_LOCK)                       \
@@ -109,8 +106,6 @@ do {                                                                        \
                                                                        \
        for (i = 1; i < ARRAY_SIZE(a); i++)                             \
                if (a[i] != a[i - 1]) {                                 \
-                       if ((_locks) & INODE_LOCK)                      \
-                               up_write(&a[i]->v.i_rwsem);             \
                        if ((_locks) & INODE_PAGECACHE_BLOCK)           \
                                bch2_pagecache_block_put(a[i]);\
                        if ((_locks) & INODE_UPDATE_LOCK)                       \