Skip to contentSkip to conversation

btrfs: Add macros for multilevel wait event annotations with lockdep

PATCH New Ioannis Angelakopoulos 1 participant 2 messages Aug 12, 2022 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover btrfs: Add macros for multilevel wait event annotations with lockdep

Hello,

with this patch series we add two new macros, which can be used for multilevel (nested) wait event annotations with lockdep.

The new macros added in fs/btrfs/ctree.h are:
1) btrfs_might_wait_for_event_nested()
2) btrfs_lockdep_acquire_nested()

Ioannis Angelakopoulos (1):
btrfs: Macros for multilevel annotations of wait events with lockdep

 fs/btrfs/ctree.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/1 btrfs: Macros for multilevel annotations of wait events with lockdep

The new macros are similar to the generic lockdep annotation macros used to annotate wait events in btrfs in fs/btrfs/ctree.h. However, the new macros take as a parameter the subclass of the lockdep map, which can be used for a multilevel annotation of a wait event.

The new macros introduced are:
1) btrfs_might_wait_for_event_nested()
2) btrfs_lockdep_acquire_nested()

---
 fs/btrfs/ctree.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
fs/btrfs/ctree.h +17 -0
index 51c480439263..44837545eef8 100644
@@ -1211,6 +1211,16 @@ enum btrfs_lockdep_trans_states {
 		rwsem_release(&owner->lock##_map, _THIS_IP_);			\
 	} while (0)
 
+/*
+ * Same as the btrfs_wait_for_event() macro but used for multilevel lockdep
+ * annotations.
+ */
+#define btrfs_might_wait_for_event_nested(owner, lock, subclass)		\
+	do {									\
+		rwsem_acquire(&owner->lock##_map, subclass, 0, _THIS_IP_);	\
+		rwsem_release(&owner->lock##_map, _THIS_IP_);			\
+	} while (0)
+
 /*
  * Protection for the resource/condition of a wait event.
  *
@@ -1225,6 +1235,13 @@ enum btrfs_lockdep_trans_states {
 #define btrfs_lockdep_acquire(owner, lock)					\
 	rwsem_acquire_read(&owner->lock##_map, 0, 0, _THIS_IP_)
 
+/*
+ * Same as the btrfs_lockdep_acquire() macro but used for multilevel lockdep
+ * annotations.
+ */
+#define btrfs_lockdep_acquire_nested(owner, lock, subclass)			\
+	rwsem_acquire_read(&owner->lock##_map, subclass, 0, _THIS_IP_)
+
 /*
  * Used after signaling the condition for a wait event to release the lockdep
  * map held by a reader thread.
Signature · 1 line
2.30.2