diff options
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r-- | fs/btrfs/disk-io.c | 103 |
1 files changed, 70 insertions, 33 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 97f22ff8326f..94ecac33cf2d 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -100,38 +100,83 @@ struct async_submit_bio { | |||
100 | struct btrfs_work work; | 100 | struct btrfs_work work; |
101 | }; | 101 | }; |
102 | 102 | ||
103 | /* These are used to set the lockdep class on the extent buffer locks. | 103 | /* |
104 | * The class is set by the readpage_end_io_hook after the buffer has | 104 | * Lockdep class keys for extent_buffer->lock's in this root. For a given |
105 | * passed csum validation but before the pages are unlocked. | 105 | * eb, the lockdep key is determined by the btrfs_root it belongs to and |
106 | * the level the eb occupies in the tree. | ||
107 | * | ||
108 | * Different roots are used for different purposes and may nest inside each | ||
109 | * other and they require separate keysets. As lockdep keys should be | ||
110 | * static, assign keysets according to the purpose of the root as indicated | ||
111 | * by btrfs_root->objectid. This ensures that all special purpose roots | ||
112 | * have separate keysets. | ||
106 | * | 113 | * |
107 | * The lockdep class is also set by btrfs_init_new_buffer on freshly | 114 | * Lock-nesting across peer nodes is always done with the immediate parent |
108 | * allocated blocks. | 115 | * node locked thus preventing deadlock. As lockdep doesn't know this, use |
116 | * subclass to avoid triggering lockdep warning in such cases. | ||
109 | * | 117 | * |
110 | * The class is based on the level in the tree block, which allows lockdep | 118 | * The key is set by the readpage_end_io_hook after the buffer has passed |
111 | * to know that lower nodes nest inside the locks of higher nodes. | 119 | * csum validation but before the pages are unlocked. It is also set by |
120 | * btrfs_init_new_buffer on freshly allocated blocks. | ||
112 | * | 121 | * |
113 | * We also add a check to make sure the highest level of the tree is | 122 | * We also add a check to make sure the highest level of the tree is the |
114 | * the same as our lockdep setup here. If BTRFS_MAX_LEVEL changes, this | 123 | * same as our lockdep setup here. If BTRFS_MAX_LEVEL changes, this code |
115 | * code needs update as well. | 124 | * needs update as well. |
116 | */ | 125 | */ |
117 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | 126 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
118 | # if BTRFS_MAX_LEVEL != 8 | 127 | # if BTRFS_MAX_LEVEL != 8 |
119 | # error | 128 | # error |
120 | # endif | 129 | # endif |
121 | static struct lock_class_key btrfs_eb_class[BTRFS_MAX_LEVEL + 1]; | 130 | |
122 | static const char *btrfs_eb_name[BTRFS_MAX_LEVEL + 1] = { | 131 | static struct btrfs_lockdep_keyset { |
123 | /* leaf */ | 132 | u64 id; /* root objectid */ |
124 | "btrfs-extent-00", | 133 | const char *name_stem; /* lock name stem */ |
125 | "btrfs-extent-01", | 134 | char names[BTRFS_MAX_LEVEL + 1][20]; |
126 | "btrfs-extent-02", | 135 | struct lock_class_key keys[BTRFS_MAX_LEVEL + 1]; |
127 | "btrfs-extent-03", | 136 | } btrfs_lockdep_keysets[] = { |
128 | "btrfs-extent-04", | 137 | { .id = BTRFS_ROOT_TREE_OBJECTID, .name_stem = "root" }, |
129 | "btrfs-extent-05", | 138 | { .id = BTRFS_EXTENT_TREE_OBJECTID, .name_stem = "extent" }, |
130 | "btrfs-extent-06", | 139 | { .id = BTRFS_CHUNK_TREE_OBJECTID, .name_stem = "chunk" }, |
131 | "btrfs-extent-07", | 140 | { .id = BTRFS_DEV_TREE_OBJECTID, .name_stem = "dev" }, |
132 | /* highest possible level */ | 141 | { .id = BTRFS_FS_TREE_OBJECTID, .name_stem = "fs" }, |
133 | "btrfs-extent-08", | 142 | { .id = BTRFS_CSUM_TREE_OBJECTID, .name_stem = "csum" }, |
143 | { .id = BTRFS_ORPHAN_OBJECTID, .name_stem = "orphan" }, | ||
144 | { .id = BTRFS_TREE_LOG_OBJECTID, .name_stem = "log" }, | ||
145 | { .id = BTRFS_TREE_RELOC_OBJECTID, .name_stem = "treloc" }, | ||
146 | { .id = BTRFS_DATA_RELOC_TREE_OBJECTID, .name_stem = "dreloc" }, | ||
147 | { .id = 0, .name_stem = "tree" }, | ||
134 | }; | 148 | }; |
149 | |||
150 | void __init btrfs_init_lockdep(void) | ||
151 | { | ||
152 | int i, j; | ||
153 | |||
154 | /* initialize lockdep class names */ | ||
155 | for (i = 0; i < ARRAY_SIZE(btrfs_lockdep_keysets); i++) { | ||
156 | struct btrfs_lockdep_keyset *ks = &btrfs_lockdep_keysets[i]; | ||
157 | |||
158 | for (j = 0; j < ARRAY_SIZE(ks->names); j++) | ||
159 | snprintf(ks->names[j], sizeof(ks->names[j]), | ||
160 | "btrfs-%s-%02d", ks->name_stem, j); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | void btrfs_set_buffer_lockdep_class(u64 objectid, struct extent_buffer *eb, | ||
165 | int level) | ||
166 | { | ||
167 | struct btrfs_lockdep_keyset *ks; | ||
168 | |||
169 | BUG_ON(level >= ARRAY_SIZE(ks->keys)); | ||
170 | |||
171 | /* find the matching keyset, id 0 is the default entry */ | ||
172 | for (ks = btrfs_lockdep_keysets; ks->id; ks++) | ||
173 | if (ks->id == objectid) | ||
174 | break; | ||
175 | |||
176 | lockdep_set_class_and_name(&eb->lock, | ||
177 | &ks->keys[level], ks->names[level]); | ||
178 | } | ||
179 | |||
135 | #endif | 180 | #endif |
136 | 181 | ||
137 | /* | 182 | /* |
@@ -491,15 +536,6 @@ static noinline int check_leaf(struct btrfs_root *root, | |||
491 | return 0; | 536 | return 0; |
492 | } | 537 | } |
493 | 538 | ||
494 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
495 | void btrfs_set_buffer_lockdep_class(struct extent_buffer *eb, int level) | ||
496 | { | ||
497 | lockdep_set_class_and_name(&eb->lock, | ||
498 | &btrfs_eb_class[level], | ||
499 | btrfs_eb_name[level]); | ||
500 | } | ||
501 | #endif | ||
502 | |||
503 | static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end, | 539 | static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end, |
504 | struct extent_state *state) | 540 | struct extent_state *state) |
505 | { | 541 | { |
@@ -550,7 +586,8 @@ static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end, | |||
550 | } | 586 | } |
551 | found_level = btrfs_header_level(eb); | 587 | found_level = btrfs_header_level(eb); |
552 | 588 | ||
553 | btrfs_set_buffer_lockdep_class(eb, found_level); | 589 | btrfs_set_buffer_lockdep_class(btrfs_header_owner(eb), |
590 | eb, found_level); | ||
554 | 591 | ||
555 | ret = csum_tree_block(root, eb, 1); | 592 | ret = csum_tree_block(root, eb, 1); |
556 | if (ret) { | 593 | if (ret) { |