]> www.infradead.org Git - linux.git/commitdiff
bcachefs: six locks: write locks can now be held recursively
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Dec 2024 07:33:53 +0000 (02:33 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 10 Jan 2025 04:38:41 +0000 (23:38 -0500)
This is needed for the interior update locking rework, where we'll be
holding node write locks for the duration of the update - which is
needed for synchronizing with online check_allocations.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/six.c
fs/bcachefs/six.h

index 617d07e53b20ccaba8552dc7c1b2faeaeff39aa4..537bf049618fa78b879330591e9275452e7a1e8f 100644 (file)
@@ -616,8 +616,6 @@ void six_unlock_ip(struct six_lock *lock, enum six_lock_type type, unsigned long
 
        if (type != SIX_LOCK_write)
                six_release(&lock->dep_map, ip);
-       else
-               lock->seq++;
 
        if (type == SIX_LOCK_intent &&
            lock->intent_lock_recurse) {
@@ -625,6 +623,15 @@ void six_unlock_ip(struct six_lock *lock, enum six_lock_type type, unsigned long
                return;
        }
 
+       if (type == SIX_LOCK_write &&
+           lock->write_lock_recurse) {
+               --lock->write_lock_recurse;
+               return;
+       }
+
+       if (type == SIX_LOCK_write)
+               lock->seq++;
+
        do_six_unlock_type(lock, type);
 }
 EXPORT_SYMBOL_GPL(six_unlock_ip);
@@ -735,13 +742,13 @@ void six_lock_increment(struct six_lock *lock, enum six_lock_type type)
                        atomic_add(l[type].lock_val, &lock->state);
                }
                break;
+       case SIX_LOCK_write:
+               lock->write_lock_recurse++;
+               fallthrough;
        case SIX_LOCK_intent:
                EBUG_ON(!(atomic_read(&lock->state) & SIX_LOCK_HELD_intent));
                lock->intent_lock_recurse++;
                break;
-       case SIX_LOCK_write:
-               BUG();
-               break;
        }
 }
 EXPORT_SYMBOL_GPL(six_lock_increment);
index 68d46fd7f3912a8101ecee24e8aab9722dbf07c1..c142e06b7a3a7c3ee73f1205a0a0408f3393e297 100644 (file)
@@ -137,6 +137,7 @@ struct six_lock {
        atomic_t                state;
        u32                     seq;
        unsigned                intent_lock_recurse;
+       unsigned                write_lock_recurse;
        struct task_struct      *owner;
        unsigned __percpu       *readers;
        raw_spinlock_t          wait_lock;