summaryrefslogtreecommitdiff
path: root/fs/bcachefs/fs.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2019-06-25 01:24:38 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:08:23 +0300
commit168f4c5fb375131bd0f5996b549c5e13cc2c2bb5 (patch)
treeb874959e361b914e3447e6fe3bf263a55145bea0 /fs/bcachefs/fs.h
parente812cf38c558f4d3a6bef8a077478a6632811f0b (diff)
downloadlinux-168f4c5fb375131bd0f5996b549c5e13cc2c2bb5.tar.xz
bcachefs: Improve bch2_lock_inodes()
Can now be used for the two different types of locks we have so far Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/fs.h')
-rw-r--r--fs/bcachefs/fs.h34
1 files changed, 26 insertions, 8 deletions
diff --git a/fs/bcachefs/fs.h b/fs/bcachefs/fs.h
index e72d6a58b322..de07f0f1dd51 100644
--- a/fs/bcachefs/fs.h
+++ b/fs/bcachefs/fs.h
@@ -57,24 +57,42 @@ static inline int ptrcmp(void *l, void *r)
return cmp_int(l, r);
}
-#define __bch2_lock_inodes(_lock, ...) \
+enum bch_inode_lock_op {
+ INODE_LOCK = (1U << 0),
+ INODE_UPDATE_LOCK = (1U << 1),
+};
+
+#define bch2_lock_inodes(_locks, ...) \
do { \
struct bch_inode_info *a[] = { NULL, __VA_ARGS__ }; \
unsigned i; \
\
- bubble_sort(&a[1], ARRAY_SIZE(a) - 1 , ptrcmp); \
+ bubble_sort(&a[1], ARRAY_SIZE(a) - 1, ptrcmp); \
\
- for (i = ARRAY_SIZE(a) - 1; a[i]; --i) \
+ for (i = 1; i < ARRAY_SIZE(a); i++) \
if (a[i] != a[i - 1]) { \
- if (_lock) \
+ if (_locks & INODE_LOCK) \
+ down_write_nested(&a[i]->v.i_rwsem, i); \
+ if (_locks & INODE_UPDATE_LOCK) \
mutex_lock_nested(&a[i]->ei_update_lock, i);\
- else \
- mutex_unlock(&a[i]->ei_update_lock); \
} \
} while (0)
-#define bch2_lock_inodes(...) __bch2_lock_inodes(true, __VA_ARGS__)
-#define bch2_unlock_inodes(...) __bch2_lock_inodes(false, __VA_ARGS__)
+#define bch2_unlock_inodes(_locks, ...) \
+do { \
+ struct bch_inode_info *a[] = { NULL, __VA_ARGS__ }; \
+ unsigned i; \
+ \
+ bubble_sort(&a[1], ARRAY_SIZE(a) - 1, ptrcmp); \
+ \
+ 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_UPDATE_LOCK) \
+ mutex_unlock(&a[i]->ei_update_lock); \
+ } \
+} while (0)
static inline struct bch_inode_info *file_bch_inode(struct file *file)
{