bcachefs: Add an assert to bch2_bucket_nocow_unlock()
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 26 Jan 2023 18:36:30 +0000 (13:36 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:52 +0000 (17:09 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/nocow_locking.c

index 53e5bc9fd5854545518b24b7a8b813ef47f6b4f5..396357cd8f2fe715c278bfe486799e6fe039e335 100644 (file)
@@ -18,6 +18,8 @@ bool bch2_bucket_nocow_is_locked(struct bucket_nocow_lock_table *t, struct bpos
        return false;
 }
 
+#define sign(v)                (v < 0 ? -1 : v > 0 ? 1 : 0)
+
 void bch2_bucket_nocow_unlock(struct bucket_nocow_lock_table *t, struct bpos bucket, int flags)
 {
        u64 dev_bucket = bucket_to_u64(bucket);
@@ -27,6 +29,8 @@ void bch2_bucket_nocow_unlock(struct bucket_nocow_lock_table *t, struct bpos buc
 
        for (i = 0; i < ARRAY_SIZE(l->b); i++)
                if (l->b[i] == dev_bucket) {
+                       BUG_ON(sign(atomic_read(&l->l[i])) != lock_val);
+
                        if (!atomic_sub_return(lock_val, &l->l[i]))
                                closure_wake_up(&l->wait);
                        return;