]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - linux/six.c
Update bcachefs sources to 90a9c61e2b bcachefs: Switch bch2_btree_delete_range()...
[bcachefs-tools-debian] / linux / six.c
index 68295914f34249094be085cf01483447954d9134..5b2d92c6e91c382a5548fe5b88e84dbbe1a9a40c 100644 (file)
@@ -139,7 +139,7 @@ static __always_inline bool do_six_trylock_type(struct six_lock *lock,
                                                bool try)
 {
        const struct six_lock_vals l[] = LOCK_VALS;
-       union six_lock_state old = {0}, new;
+       union six_lock_state old, new;
        bool ret;
        u64 v;
 
@@ -757,3 +757,23 @@ void six_lock_pcpu_alloc(struct six_lock *lock)
 #endif
 }
 EXPORT_SYMBOL_GPL(six_lock_pcpu_alloc);
+
+/*
+ * Returns lock held counts, for both read and intent
+ */
+struct six_lock_count six_lock_counts(struct six_lock *lock)
+{
+       struct six_lock_count ret = { 0, lock->state.intent_lock };
+
+       if (!lock->readers)
+               ret.read += lock->state.read_lock;
+       else {
+               int cpu;
+
+               for_each_possible_cpu(cpu)
+                       ret.read += *per_cpu_ptr(lock->readers, cpu);
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(six_lock_counts);