Skip to content

Commit 9a5232e

Browse files
author
Kent Overstreet
committed
bcachefs: six locks: write locks can now be held recursively
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 <[email protected]>
1 parent 8f3aaa5 commit 9a5232e

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

fs/bcachefs/six.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -616,15 +616,22 @@ void six_unlock_ip(struct six_lock *lock, enum six_lock_type type, unsigned long
616616

617617
if (type != SIX_LOCK_write)
618618
six_release(&lock->dep_map, ip);
619-
else
620-
lock->seq++;
621619

622620
if (type == SIX_LOCK_intent &&
623621
lock->intent_lock_recurse) {
624622
--lock->intent_lock_recurse;
625623
return;
626624
}
627625

626+
if (type == SIX_LOCK_write &&
627+
lock->write_lock_recurse) {
628+
--lock->write_lock_recurse;
629+
return;
630+
}
631+
632+
if (type == SIX_LOCK_write)
633+
lock->seq++;
634+
628635
do_six_unlock_type(lock, type);
629636
}
630637
EXPORT_SYMBOL_GPL(six_unlock_ip);
@@ -735,13 +742,13 @@ void six_lock_increment(struct six_lock *lock, enum six_lock_type type)
735742
atomic_add(l[type].lock_val, &lock->state);
736743
}
737744
break;
745+
case SIX_LOCK_write:
746+
lock->write_lock_recurse++;
747+
fallthrough;
738748
case SIX_LOCK_intent:
739749
EBUG_ON(!(atomic_read(&lock->state) & SIX_LOCK_HELD_intent));
740750
lock->intent_lock_recurse++;
741751
break;
742-
case SIX_LOCK_write:
743-
BUG();
744-
break;
745752
}
746753
}
747754
EXPORT_SYMBOL_GPL(six_lock_increment);

fs/bcachefs/six.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ struct six_lock {
137137
atomic_t state;
138138
u32 seq;
139139
unsigned intent_lock_recurse;
140+
unsigned write_lock_recurse;
140141
struct task_struct *owner;
141142
unsigned __percpu *readers;
142143
raw_spinlock_t wait_lock;

0 commit comments

Comments
 (0)