summaryrefslogtreecommitdiff
path: root/libbcachefs/nocow_locking.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2022-12-19 14:47:35 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2022-12-19 14:47:35 -0500
commit71111771690f244d13650c73d52ff601ad914d95 (patch)
tree4877e26805b2c0666930c8ee417396a2c8e5b728 /libbcachefs/nocow_locking.h
parent3c0484687d00f3f2818d13c0c6f65123abcf4517 (diff)
Update bcachefs sources to 7958ebe324 bcachefs: Fix alloc_v4_backpointers()
Diffstat (limited to 'libbcachefs/nocow_locking.h')
-rw-r--r--libbcachefs/nocow_locking.h50
1 files changed, 17 insertions, 33 deletions
diff --git a/libbcachefs/nocow_locking.h b/libbcachefs/nocow_locking.h
index 2a7a9f44..45258cc3 100644
--- a/libbcachefs/nocow_locking.h
+++ b/libbcachefs/nocow_locking.h
@@ -2,54 +2,38 @@
#ifndef _BCACHEFS_NOCOW_LOCKING_H
#define _BCACHEFS_NOCOW_LOCKING_H
-#include "bcachefs_format.h"
-#include "two_state_shared_lock.h"
+#include "bcachefs.h"
+#include "alloc_background.h"
+#include "nocow_locking_types.h"
#include <linux/hash.h>
-#define BUCKET_NOCOW_LOCKS_BITS 10
-#define BUCKET_NOCOW_LOCKS (1U << BUCKET_NOCOW_LOCKS_BITS)
-
-struct bucket_nocow_lock_table {
- two_state_lock_t l[BUCKET_NOCOW_LOCKS];
-};
-
-#define BUCKET_NOCOW_LOCK_UPDATE (1 << 0)
-
-static inline two_state_lock_t *bucket_nocow_lock(struct bucket_nocow_lock_table *t,
- struct bpos bucket)
+static inline struct nocow_lock_bucket *bucket_nocow_lock(struct bucket_nocow_lock_table *t,
+ u64 dev_bucket)
{
- u64 dev_bucket = bucket.inode << 56 | bucket.offset;
unsigned h = hash_64(dev_bucket, BUCKET_NOCOW_LOCKS_BITS);
return t->l + (h & (BUCKET_NOCOW_LOCKS - 1));
}
-static inline bool bch2_bucket_nocow_is_locked(struct bucket_nocow_lock_table *t,
- struct bpos bucket)
-{
- two_state_lock_t *l = bucket_nocow_lock(t, bucket);
-
- return atomic_long_read(&l->v) != 0;
-}
-
-static inline void bch2_bucket_nocow_unlock(struct bucket_nocow_lock_table *t,
- struct bpos bucket, int flags)
-{
- two_state_lock_t *l = bucket_nocow_lock(t, bucket);
-
- bch2_two_state_unlock(l, flags & BUCKET_NOCOW_LOCK_UPDATE);
-}
+#define BUCKET_NOCOW_LOCK_UPDATE (1 << 0)
-void __bch2_bucket_nocow_lock(struct bucket_nocow_lock_table *, two_state_lock_t *, int);
+bool bch2_bucket_nocow_is_locked(struct bucket_nocow_lock_table *, struct bpos);
+void bch2_bucket_nocow_unlock(struct bucket_nocow_lock_table *, struct bpos, int);
+void __bch2_bucket_nocow_lock(struct bucket_nocow_lock_table *,
+ struct nocow_lock_bucket *, u64, int);
static inline void bch2_bucket_nocow_lock(struct bucket_nocow_lock_table *t,
struct bpos bucket, int flags)
{
- two_state_lock_t *l = bucket_nocow_lock(t, bucket);
+ u64 dev_bucket = bucket_to_u64(bucket);
+ struct nocow_lock_bucket *l = bucket_nocow_lock(t, dev_bucket);
- if (!bch2_two_state_trylock(l, flags & BUCKET_NOCOW_LOCK_UPDATE))
- __bch2_bucket_nocow_lock(t, l, flags);
+ __bch2_bucket_nocow_lock(t, l, dev_bucket, flags);
}
+void bch2_nocow_locks_to_text(struct printbuf *, struct bucket_nocow_lock_table *);
+
+int bch2_fs_nocow_locking_init(struct bch_fs *);
+
#endif /* _BCACHEFS_NOCOW_LOCKING_H */