Skip to content

Commit 0a27a04

Browse files
josefbacikkdave
authored andcommitted
btrfs: move lockdep class helpers to locking.c
These definitions exist in disk-io.c, which is not related to the locking. Move this over to locking.h/c where it makes more sense. Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 85f02d6 commit 0a27a04

File tree

4 files changed

+89
-92
lines changed

4 files changed

+89
-92
lines changed

fs/btrfs/disk-io.c

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -86,88 +86,6 @@ struct async_submit_bio {
8686
blk_status_t status;
8787
};
8888

89-
/*
90-
* Lockdep class keys for extent_buffer->lock's in this root. For a given
91-
* eb, the lockdep key is determined by the btrfs_root it belongs to and
92-
* the level the eb occupies in the tree.
93-
*
94-
* Different roots are used for different purposes and may nest inside each
95-
* other and they require separate keysets. As lockdep keys should be
96-
* static, assign keysets according to the purpose of the root as indicated
97-
* by btrfs_root->root_key.objectid. This ensures that all special purpose
98-
* roots have separate keysets.
99-
*
100-
* Lock-nesting across peer nodes is always done with the immediate parent
101-
* node locked thus preventing deadlock. As lockdep doesn't know this, use
102-
* subclass to avoid triggering lockdep warning in such cases.
103-
*
104-
* The key is set by the readpage_end_io_hook after the buffer has passed
105-
* csum validation but before the pages are unlocked. It is also set by
106-
* btrfs_init_new_buffer on freshly allocated blocks.
107-
*
108-
* We also add a check to make sure the highest level of the tree is the
109-
* same as our lockdep setup here. If BTRFS_MAX_LEVEL changes, this code
110-
* needs update as well.
111-
*/
112-
#ifdef CONFIG_DEBUG_LOCK_ALLOC
113-
# if BTRFS_MAX_LEVEL != 8
114-
# error
115-
# endif
116-
117-
#define DEFINE_LEVEL(stem, level) \
118-
.names[level] = "btrfs-" stem "-0" #level,
119-
120-
#define DEFINE_NAME(stem) \
121-
DEFINE_LEVEL(stem, 0) \
122-
DEFINE_LEVEL(stem, 1) \
123-
DEFINE_LEVEL(stem, 2) \
124-
DEFINE_LEVEL(stem, 3) \
125-
DEFINE_LEVEL(stem, 4) \
126-
DEFINE_LEVEL(stem, 5) \
127-
DEFINE_LEVEL(stem, 6) \
128-
DEFINE_LEVEL(stem, 7)
129-
130-
static struct btrfs_lockdep_keyset {
131-
u64 id; /* root objectid */
132-
/* Longest entry: btrfs-free-space-00 */
133-
char names[BTRFS_MAX_LEVEL][20];
134-
struct lock_class_key keys[BTRFS_MAX_LEVEL];
135-
} btrfs_lockdep_keysets[] = {
136-
{ .id = BTRFS_ROOT_TREE_OBJECTID, DEFINE_NAME("root") },
137-
{ .id = BTRFS_EXTENT_TREE_OBJECTID, DEFINE_NAME("extent") },
138-
{ .id = BTRFS_CHUNK_TREE_OBJECTID, DEFINE_NAME("chunk") },
139-
{ .id = BTRFS_DEV_TREE_OBJECTID, DEFINE_NAME("dev") },
140-
{ .id = BTRFS_CSUM_TREE_OBJECTID, DEFINE_NAME("csum") },
141-
{ .id = BTRFS_QUOTA_TREE_OBJECTID, DEFINE_NAME("quota") },
142-
{ .id = BTRFS_TREE_LOG_OBJECTID, DEFINE_NAME("log") },
143-
{ .id = BTRFS_TREE_RELOC_OBJECTID, DEFINE_NAME("treloc") },
144-
{ .id = BTRFS_DATA_RELOC_TREE_OBJECTID, DEFINE_NAME("dreloc") },
145-
{ .id = BTRFS_UUID_TREE_OBJECTID, DEFINE_NAME("uuid") },
146-
{ .id = BTRFS_FREE_SPACE_TREE_OBJECTID, DEFINE_NAME("free-space") },
147-
{ .id = 0, DEFINE_NAME("tree") },
148-
};
149-
150-
#undef DEFINE_LEVEL
151-
#undef DEFINE_NAME
152-
153-
void btrfs_set_buffer_lockdep_class(u64 objectid, struct extent_buffer *eb,
154-
int level)
155-
{
156-
struct btrfs_lockdep_keyset *ks;
157-
158-
BUG_ON(level >= ARRAY_SIZE(ks->keys));
159-
160-
/* find the matching keyset, id 0 is the default entry */
161-
for (ks = btrfs_lockdep_keysets; ks->id; ks++)
162-
if (ks->id == objectid)
163-
break;
164-
165-
lockdep_set_class_and_name(&eb->lock,
166-
&ks->keys[level], ks->names[level]);
167-
}
168-
169-
#endif
170-
17189
/*
17290
* Compute the csum of a btree block and store the result to provided buffer.
17391
*/

fs/btrfs/disk-io.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,4 @@ int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags);
137137
int btrfs_get_free_objectid(struct btrfs_root *root, u64 *objectid);
138138
int btrfs_init_root_free_objectid(struct btrfs_root *root);
139139

140-
#ifdef CONFIG_DEBUG_LOCK_ALLOC
141-
void btrfs_set_buffer_lockdep_class(u64 objectid,
142-
struct extent_buffer *eb, int level);
143-
#else
144-
static inline void btrfs_set_buffer_lockdep_class(u64 objectid,
145-
struct extent_buffer *eb, int level)
146-
{
147-
}
148-
#endif
149-
150140
#endif

fs/btrfs/locking.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,86 @@
1313
#include "extent_io.h"
1414
#include "locking.h"
1515

16+
/*
17+
* Lockdep class keys for extent_buffer->lock's in this root. For a given
18+
* eb, the lockdep key is determined by the btrfs_root it belongs to and
19+
* the level the eb occupies in the tree.
20+
*
21+
* Different roots are used for different purposes and may nest inside each
22+
* other and they require separate keysets. As lockdep keys should be
23+
* static, assign keysets according to the purpose of the root as indicated
24+
* by btrfs_root->root_key.objectid. This ensures that all special purpose
25+
* roots have separate keysets.
26+
*
27+
* Lock-nesting across peer nodes is always done with the immediate parent
28+
* node locked thus preventing deadlock. As lockdep doesn't know this, use
29+
* subclass to avoid triggering lockdep warning in such cases.
30+
*
31+
* The key is set by the readpage_end_io_hook after the buffer has passed
32+
* csum validation but before the pages are unlocked. It is also set by
33+
* btrfs_init_new_buffer on freshly allocated blocks.
34+
*
35+
* We also add a check to make sure the highest level of the tree is the
36+
* same as our lockdep setup here. If BTRFS_MAX_LEVEL changes, this code
37+
* needs update as well.
38+
*/
39+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
40+
#if BTRFS_MAX_LEVEL != 8
41+
#error
42+
#endif
43+
44+
#define DEFINE_LEVEL(stem, level) \
45+
.names[level] = "btrfs-" stem "-0" #level,
46+
47+
#define DEFINE_NAME(stem) \
48+
DEFINE_LEVEL(stem, 0) \
49+
DEFINE_LEVEL(stem, 1) \
50+
DEFINE_LEVEL(stem, 2) \
51+
DEFINE_LEVEL(stem, 3) \
52+
DEFINE_LEVEL(stem, 4) \
53+
DEFINE_LEVEL(stem, 5) \
54+
DEFINE_LEVEL(stem, 6) \
55+
DEFINE_LEVEL(stem, 7)
56+
57+
static struct btrfs_lockdep_keyset {
58+
u64 id; /* root objectid */
59+
/* Longest entry: btrfs-free-space-00 */
60+
char names[BTRFS_MAX_LEVEL][20];
61+
struct lock_class_key keys[BTRFS_MAX_LEVEL];
62+
} btrfs_lockdep_keysets[] = {
63+
{ .id = BTRFS_ROOT_TREE_OBJECTID, DEFINE_NAME("root") },
64+
{ .id = BTRFS_EXTENT_TREE_OBJECTID, DEFINE_NAME("extent") },
65+
{ .id = BTRFS_CHUNK_TREE_OBJECTID, DEFINE_NAME("chunk") },
66+
{ .id = BTRFS_DEV_TREE_OBJECTID, DEFINE_NAME("dev") },
67+
{ .id = BTRFS_CSUM_TREE_OBJECTID, DEFINE_NAME("csum") },
68+
{ .id = BTRFS_QUOTA_TREE_OBJECTID, DEFINE_NAME("quota") },
69+
{ .id = BTRFS_TREE_LOG_OBJECTID, DEFINE_NAME("log") },
70+
{ .id = BTRFS_TREE_RELOC_OBJECTID, DEFINE_NAME("treloc") },
71+
{ .id = BTRFS_DATA_RELOC_TREE_OBJECTID, DEFINE_NAME("dreloc") },
72+
{ .id = BTRFS_UUID_TREE_OBJECTID, DEFINE_NAME("uuid") },
73+
{ .id = BTRFS_FREE_SPACE_TREE_OBJECTID, DEFINE_NAME("free-space") },
74+
{ .id = 0, DEFINE_NAME("tree") },
75+
};
76+
77+
#undef DEFINE_LEVEL
78+
#undef DEFINE_NAME
79+
80+
void btrfs_set_buffer_lockdep_class(u64 objectid, struct extent_buffer *eb, int level)
81+
{
82+
struct btrfs_lockdep_keyset *ks;
83+
84+
BUG_ON(level >= ARRAY_SIZE(ks->keys));
85+
86+
/* Find the matching keyset, id 0 is the default entry */
87+
for (ks = btrfs_lockdep_keysets; ks->id; ks++)
88+
if (ks->id == objectid)
89+
break;
90+
91+
lockdep_set_class_and_name(&eb->lock, &ks->keys[level], ks->names[level]);
92+
}
93+
94+
#endif
95+
1696
/*
1797
* Extent buffer locking
1898
* =====================

fs/btrfs/locking.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,13 @@ void btrfs_drew_write_unlock(struct btrfs_drew_lock *lock);
131131
void btrfs_drew_read_lock(struct btrfs_drew_lock *lock);
132132
void btrfs_drew_read_unlock(struct btrfs_drew_lock *lock);
133133

134+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
135+
void btrfs_set_buffer_lockdep_class(u64 objectid, struct extent_buffer *eb, int level);
136+
#else
137+
static inline void btrfs_set_buffer_lockdep_class(u64 objectid,
138+
struct extent_buffer *eb, int level)
139+
{
140+
}
141+
#endif
142+
134143
#endif

0 commit comments

Comments
 (0)