btrfs: move the lockdep helpers into locking.h
authorJosef Bacik <josef@toxicpanda.com>
Mon, 24 Oct 2022 18:46:53 +0000 (14:46 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 5 Dec 2022 17:00:44 +0000 (18:00 +0100)
These more naturally fit in with the locking related code, and they're
all defines so they can easily go anywhere, move them out of ctree.h
into locking.h

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/locking.h

index ace6f41612e5c85fe429005db09a32bd1bc5f378..970a22a04c9463d11f3090e9efedaf9e3a82cd36 100644 (file)
@@ -181,82 +181,6 @@ enum {
        BTRFS_ROOT_RESET_LOCKDEP_CLASS,
 };
 
-enum btrfs_lockdep_trans_states {
-       BTRFS_LOCKDEP_TRANS_COMMIT_START,
-       BTRFS_LOCKDEP_TRANS_UNBLOCKED,
-       BTRFS_LOCKDEP_TRANS_SUPER_COMMITTED,
-       BTRFS_LOCKDEP_TRANS_COMPLETED,
-};
-
-/*
- * Lockdep annotation for wait events.
- *
- * @owner:  The struct where the lockdep map is defined
- * @lock:   The lockdep map corresponding to a wait event
- *
- * This macro is used to annotate a wait event. In this case a thread acquires
- * the lockdep map as writer (exclusive lock) because it has to block until all
- * the threads that hold the lock as readers signal the condition for the wait
- * event and release their locks.
- */
-#define btrfs_might_wait_for_event(owner, lock)                                        \
-       do {                                                                    \
-               rwsem_acquire(&owner->lock##_map, 0, 0, _THIS_IP_);             \
-               rwsem_release(&owner->lock##_map, _THIS_IP_);                   \
-       } while (0)
-
-/*
- * Protection for the resource/condition of a wait event.
- *
- * @owner:  The struct where the lockdep map is defined
- * @lock:   The lockdep map corresponding to a wait event
- *
- * Many threads can modify the condition for the wait event at the same time
- * and signal the threads that block on the wait event. The threads that modify
- * the condition and do the signaling acquire the lock as readers (shared
- * lock).
- */
-#define btrfs_lockdep_acquire(owner, lock)                                     \
-       rwsem_acquire_read(&owner->lock##_map, 0, 0, _THIS_IP_)
-
-/*
- * Used after signaling the condition for a wait event to release the lockdep
- * map held by a reader thread.
- */
-#define btrfs_lockdep_release(owner, lock)                                     \
-       rwsem_release(&owner->lock##_map, _THIS_IP_)
-
-/*
- * Macros for the transaction states wait events, similar to the generic wait
- * event macros.
- */
-#define btrfs_might_wait_for_state(owner, i)                                   \
-       do {                                                                    \
-               rwsem_acquire(&owner->btrfs_state_change_map[i], 0, 0, _THIS_IP_); \
-               rwsem_release(&owner->btrfs_state_change_map[i], _THIS_IP_);    \
-       } while (0)
-
-#define btrfs_trans_state_lockdep_acquire(owner, i)                            \
-       rwsem_acquire_read(&owner->btrfs_state_change_map[i], 0, 0, _THIS_IP_)
-
-#define btrfs_trans_state_lockdep_release(owner, i)                            \
-       rwsem_release(&owner->btrfs_state_change_map[i], _THIS_IP_)
-
-/* Initialization of the lockdep map */
-#define btrfs_lockdep_init_map(owner, lock)                                    \
-       do {                                                                    \
-               static struct lock_class_key lock##_key;                        \
-               lockdep_init_map(&owner->lock##_map, #lock, &lock##_key, 0);    \
-       } while (0)
-
-/* Initialization of the transaction states lockdep maps. */
-#define btrfs_state_lockdep_init_map(owner, lock, state)                       \
-       do {                                                                    \
-               static struct lock_class_key lock##_key;                        \
-               lockdep_init_map(&owner->btrfs_state_change_map[state], #lock,  \
-                                &lock##_key, 0);                               \
-       } while (0)
-
 /*
  * Record swapped tree blocks of a subvolume tree for delayed subtree trace
  * code. For detail check comment in fs/btrfs/qgroup.c.
index 490c7a79e9959871c4c5e277fec02e955e87e824..11c2269b4b6f6504a3d722ee9dda4a6f94c8c45e 100644 (file)
@@ -78,6 +78,82 @@ enum btrfs_lock_nesting {
        BTRFS_NESTING_MAX,
 };
 
+enum btrfs_lockdep_trans_states {
+       BTRFS_LOCKDEP_TRANS_COMMIT_START,
+       BTRFS_LOCKDEP_TRANS_UNBLOCKED,
+       BTRFS_LOCKDEP_TRANS_SUPER_COMMITTED,
+       BTRFS_LOCKDEP_TRANS_COMPLETED,
+};
+
+/*
+ * Lockdep annotation for wait events.
+ *
+ * @owner:  The struct where the lockdep map is defined
+ * @lock:   The lockdep map corresponding to a wait event
+ *
+ * This macro is used to annotate a wait event. In this case a thread acquires
+ * the lockdep map as writer (exclusive lock) because it has to block until all
+ * the threads that hold the lock as readers signal the condition for the wait
+ * event and release their locks.
+ */
+#define btrfs_might_wait_for_event(owner, lock)                                        \
+       do {                                                                    \
+               rwsem_acquire(&owner->lock##_map, 0, 0, _THIS_IP_);             \
+               rwsem_release(&owner->lock##_map, _THIS_IP_);                   \
+       } while (0)
+
+/*
+ * Protection for the resource/condition of a wait event.
+ *
+ * @owner:  The struct where the lockdep map is defined
+ * @lock:   The lockdep map corresponding to a wait event
+ *
+ * Many threads can modify the condition for the wait event at the same time
+ * and signal the threads that block on the wait event. The threads that modify
+ * the condition and do the signaling acquire the lock as readers (shared
+ * lock).
+ */
+#define btrfs_lockdep_acquire(owner, lock)                                     \
+       rwsem_acquire_read(&owner->lock##_map, 0, 0, _THIS_IP_)
+
+/*
+ * Used after signaling the condition for a wait event to release the lockdep
+ * map held by a reader thread.
+ */
+#define btrfs_lockdep_release(owner, lock)                                     \
+       rwsem_release(&owner->lock##_map, _THIS_IP_)
+
+/*
+ * Macros for the transaction states wait events, similar to the generic wait
+ * event macros.
+ */
+#define btrfs_might_wait_for_state(owner, i)                                   \
+       do {                                                                    \
+               rwsem_acquire(&owner->btrfs_state_change_map[i], 0, 0, _THIS_IP_); \
+               rwsem_release(&owner->btrfs_state_change_map[i], _THIS_IP_);    \
+       } while (0)
+
+#define btrfs_trans_state_lockdep_acquire(owner, i)                            \
+       rwsem_acquire_read(&owner->btrfs_state_change_map[i], 0, 0, _THIS_IP_)
+
+#define btrfs_trans_state_lockdep_release(owner, i)                            \
+       rwsem_release(&owner->btrfs_state_change_map[i], _THIS_IP_)
+
+/* Initialization of the lockdep map */
+#define btrfs_lockdep_init_map(owner, lock)                                    \
+       do {                                                                    \
+               static struct lock_class_key lock##_key;                        \
+               lockdep_init_map(&owner->lock##_map, #lock, &lock##_key, 0);    \
+       } while (0)
+
+/* Initialization of the transaction states lockdep maps. */
+#define btrfs_state_lockdep_init_map(owner, lock, state)                       \
+       do {                                                                    \
+               static struct lock_class_key lock##_key;                        \
+               lockdep_init_map(&owner->btrfs_state_change_map[state], #lock,  \
+                                &lock##_key, 0);                               \
+       } while (0)
+
 static_assert(BTRFS_NESTING_MAX <= MAX_LOCKDEP_SUBCLASSES,
              "too many lock subclasses defined");