Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'for-6.0-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux

Pull btrfs fixes from David Sterba:
"A few short fixes and a lockdep warning fix (needs moving some code):

- tree-log replay fixes:
- fix error handling when looking up extent refs
- fix warning when setting inode number of links

- relocation fixes:
- reset block group read-only status when relocation fails
- unset control structure if transaction fails when starting
to process a block group
- add lockdep annotations to fix a warning during relocation
where blocks temporarily belong to another tree and can lead
to reversed dependencies

- tree-checker verifies that extent items don't overlap"

* tag 'for-6.0-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux:
btrfs: tree-checker: check for overlapping extent items
btrfs: fix warning during log replay when bumping inode link count
btrfs: fix lost error handling when looking up extended ref on log replay
btrfs: fix lockdep splat with reloc root extent buffers
btrfs: move lockdep class helpers to locking.c
btrfs: unset reloc control if transaction commit fails in prepare_to_relocate()
btrfs: reset RO counter on block group if we fail to relocate

+176 -101
+3 -1
fs/btrfs/block-group.c
··· 1640 1640 div64_u64(zone_unusable * 100, bg->length)); 1641 1641 trace_btrfs_reclaim_block_group(bg); 1642 1642 ret = btrfs_relocate_chunk(fs_info, bg->start); 1643 - if (ret) 1643 + if (ret) { 1644 + btrfs_dec_block_group_ro(bg); 1644 1645 btrfs_err(fs_info, "error relocating chunk %llu", 1645 1646 bg->start); 1647 + } 1646 1648 1647 1649 next: 1648 1650 btrfs_put_block_group(bg);
+3
fs/btrfs/ctree.c
··· 2075 2075 2076 2076 if (!p->skip_locking) { 2077 2077 level = btrfs_header_level(b); 2078 + 2079 + btrfs_maybe_reset_lockdep_class(root, b); 2080 + 2078 2081 if (level <= write_lock_level) { 2079 2082 btrfs_tree_lock(b); 2080 2083 p->locks[level] = BTRFS_WRITE_LOCK;
+2
fs/btrfs/ctree.h
··· 1173 1173 BTRFS_ROOT_ORPHAN_CLEANUP, 1174 1174 /* This root has a drop operation that was started previously. */ 1175 1175 BTRFS_ROOT_UNFINISHED_DROP, 1176 + /* This reloc root needs to have its buffers lockdep class reset. */ 1177 + BTRFS_ROOT_RESET_LOCKDEP_CLASS, 1176 1178 }; 1177 1179 1178 1180 static inline void btrfs_wake_unfinished_drop(struct btrfs_fs_info *fs_info)
-82
fs/btrfs/disk-io.c
··· 87 87 }; 88 88 89 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 - 171 - /* 172 90 * Compute the csum of a btree block and store the result to provided buffer. 173 91 */ 174 92 static void csum_tree_block(struct extent_buffer *buf, u8 *result)
-10
fs/btrfs/disk-io.h
··· 137 137 int btrfs_get_free_objectid(struct btrfs_root *root, u64 *objectid); 138 138 int btrfs_init_root_free_objectid(struct btrfs_root *root); 139 139 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 - 150 140 #endif
+17 -1
fs/btrfs/extent-tree.c
··· 4867 4867 { 4868 4868 struct btrfs_fs_info *fs_info = root->fs_info; 4869 4869 struct extent_buffer *buf; 4870 + u64 lockdep_owner = owner; 4870 4871 4871 4872 buf = btrfs_find_create_tree_block(fs_info, bytenr, owner, level); 4872 4873 if (IS_ERR(buf)) ··· 4887 4886 } 4888 4887 4889 4888 /* 4889 + * The reloc trees are just snapshots, so we need them to appear to be 4890 + * just like any other fs tree WRT lockdep. 4891 + * 4892 + * The exception however is in replace_path() in relocation, where we 4893 + * hold the lock on the original fs root and then search for the reloc 4894 + * root. At that point we need to make sure any reloc root buffers are 4895 + * set to the BTRFS_TREE_RELOC_OBJECTID lockdep class in order to make 4896 + * lockdep happy. 4897 + */ 4898 + if (lockdep_owner == BTRFS_TREE_RELOC_OBJECTID && 4899 + !test_bit(BTRFS_ROOT_RESET_LOCKDEP_CLASS, &root->state)) 4900 + lockdep_owner = BTRFS_FS_TREE_OBJECTID; 4901 + 4902 + /* 4890 4903 * This needs to stay, because we could allocate a freed block from an 4891 4904 * old tree into a new tree, so we need to make sure this new block is 4892 4905 * set to the appropriate level and owner. 4893 4906 */ 4894 - btrfs_set_buffer_lockdep_class(owner, buf, level); 4907 + btrfs_set_buffer_lockdep_class(lockdep_owner, buf, level); 4908 + 4895 4909 __btrfs_tree_lock(buf, nest); 4896 4910 btrfs_clean_tree_block(buf); 4897 4911 clear_bit(EXTENT_BUFFER_STALE, &buf->bflags);
+10 -1
fs/btrfs/extent_io.c
··· 6140 6140 struct extent_buffer *exists = NULL; 6141 6141 struct page *p; 6142 6142 struct address_space *mapping = fs_info->btree_inode->i_mapping; 6143 + u64 lockdep_owner = owner_root; 6143 6144 int uptodate = 1; 6144 6145 int ret; 6145 6146 ··· 6165 6164 eb = __alloc_extent_buffer(fs_info, start, len); 6166 6165 if (!eb) 6167 6166 return ERR_PTR(-ENOMEM); 6168 - btrfs_set_buffer_lockdep_class(owner_root, eb, level); 6167 + 6168 + /* 6169 + * The reloc trees are just snapshots, so we need them to appear to be 6170 + * just like any other fs tree WRT lockdep. 6171 + */ 6172 + if (lockdep_owner == BTRFS_TREE_RELOC_OBJECTID) 6173 + lockdep_owner = BTRFS_FS_TREE_OBJECTID; 6174 + 6175 + btrfs_set_buffer_lockdep_class(lockdep_owner, eb, level); 6169 6176 6170 6177 num_pages = num_extent_pages(eb); 6171 6178 for (i = 0; i < num_pages; i++, index++) {
+91
fs/btrfs/locking.c
··· 14 14 #include "locking.h" 15 15 16 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 + void btrfs_maybe_reset_lockdep_class(struct btrfs_root *root, struct extent_buffer *eb) 95 + { 96 + if (test_bit(BTRFS_ROOT_RESET_LOCKDEP_CLASS, &root->state)) 97 + btrfs_set_buffer_lockdep_class(root->root_key.objectid, 98 + eb, btrfs_header_level(eb)); 99 + } 100 + 101 + #endif 102 + 103 + /* 17 104 * Extent buffer locking 18 105 * ===================== 19 106 * ··· 251 164 252 165 while (1) { 253 166 eb = btrfs_root_node(root); 167 + 168 + btrfs_maybe_reset_lockdep_class(root, eb); 254 169 btrfs_tree_lock(eb); 255 170 if (eb == root->node) 256 171 break; ··· 274 185 275 186 while (1) { 276 187 eb = btrfs_root_node(root); 188 + 189 + btrfs_maybe_reset_lockdep_class(root, eb); 277 190 btrfs_tree_read_lock(eb); 278 191 if (eb == root->node) 279 192 break;
+14
fs/btrfs/locking.h
··· 131 131 void btrfs_drew_read_lock(struct btrfs_drew_lock *lock); 132 132 void btrfs_drew_read_unlock(struct btrfs_drew_lock *lock); 133 133 134 + #ifdef CONFIG_DEBUG_LOCK_ALLOC 135 + void btrfs_set_buffer_lockdep_class(u64 objectid, struct extent_buffer *eb, int level); 136 + void btrfs_maybe_reset_lockdep_class(struct btrfs_root *root, struct extent_buffer *eb); 137 + #else 138 + static inline void btrfs_set_buffer_lockdep_class(u64 objectid, 139 + struct extent_buffer *eb, int level) 140 + { 141 + } 142 + static inline void btrfs_maybe_reset_lockdep_class(struct btrfs_root *root, 143 + struct extent_buffer *eb) 144 + { 145 + } 146 + #endif 147 + 134 148 #endif
+8 -1
fs/btrfs/relocation.c
··· 1326 1326 btrfs_release_path(path); 1327 1327 1328 1328 path->lowest_level = level; 1329 + set_bit(BTRFS_ROOT_RESET_LOCKDEP_CLASS, &src->state); 1329 1330 ret = btrfs_search_slot(trans, src, &key, path, 0, 1); 1331 + clear_bit(BTRFS_ROOT_RESET_LOCKDEP_CLASS, &src->state); 1330 1332 path->lowest_level = 0; 1331 1333 if (ret) { 1332 1334 if (ret > 0) ··· 3575 3573 */ 3576 3574 return PTR_ERR(trans); 3577 3575 } 3578 - return btrfs_commit_transaction(trans); 3576 + 3577 + ret = btrfs_commit_transaction(trans); 3578 + if (ret) 3579 + unset_reloc_control(rc); 3580 + 3581 + return ret; 3579 3582 } 3580 3583 3581 3584 static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
+23 -2
fs/btrfs/tree-checker.c
··· 1233 1233 } 1234 1234 1235 1235 static int check_extent_item(struct extent_buffer *leaf, 1236 - struct btrfs_key *key, int slot) 1236 + struct btrfs_key *key, int slot, 1237 + struct btrfs_key *prev_key) 1237 1238 { 1238 1239 struct btrfs_fs_info *fs_info = leaf->fs_info; 1239 1240 struct btrfs_extent_item *ei; ··· 1454 1453 total_refs, inline_refs); 1455 1454 return -EUCLEAN; 1456 1455 } 1456 + 1457 + if ((prev_key->type == BTRFS_EXTENT_ITEM_KEY) || 1458 + (prev_key->type == BTRFS_METADATA_ITEM_KEY)) { 1459 + u64 prev_end = prev_key->objectid; 1460 + 1461 + if (prev_key->type == BTRFS_METADATA_ITEM_KEY) 1462 + prev_end += fs_info->nodesize; 1463 + else 1464 + prev_end += prev_key->offset; 1465 + 1466 + if (unlikely(prev_end > key->objectid)) { 1467 + extent_err(leaf, slot, 1468 + "previous extent [%llu %u %llu] overlaps current extent [%llu %u %llu]", 1469 + prev_key->objectid, prev_key->type, 1470 + prev_key->offset, key->objectid, key->type, 1471 + key->offset); 1472 + return -EUCLEAN; 1473 + } 1474 + } 1475 + 1457 1476 return 0; 1458 1477 } 1459 1478 ··· 1642 1621 break; 1643 1622 case BTRFS_EXTENT_ITEM_KEY: 1644 1623 case BTRFS_METADATA_ITEM_KEY: 1645 - ret = check_extent_item(leaf, key, slot); 1624 + ret = check_extent_item(leaf, key, slot, prev_key); 1646 1625 break; 1647 1626 case BTRFS_TREE_BLOCK_REF_KEY: 1648 1627 case BTRFS_SHARED_DATA_REF_KEY:
+5 -3
fs/btrfs/tree-log.c
··· 1146 1146 extref = btrfs_lookup_inode_extref(NULL, root, path, name, namelen, 1147 1147 inode_objectid, parent_objectid, 0, 1148 1148 0); 1149 - if (!IS_ERR_OR_NULL(extref)) { 1149 + if (IS_ERR(extref)) { 1150 + return PTR_ERR(extref); 1151 + } else if (extref) { 1150 1152 u32 item_size; 1151 1153 u32 cur_offset = 0; 1152 1154 unsigned long base; ··· 1459 1457 * on the inode will not free it. We will fixup the link count later. 1460 1458 */ 1461 1459 if (other_inode->i_nlink == 0) 1462 - inc_nlink(other_inode); 1460 + set_nlink(other_inode, 1); 1463 1461 add_link: 1464 1462 ret = btrfs_add_link(trans, BTRFS_I(dir), BTRFS_I(inode), 1465 1463 name, namelen, 0, ref_index); ··· 1602 1600 * free it. We will fixup the link count later. 1603 1601 */ 1604 1602 if (!ret && inode->i_nlink == 0) 1605 - inc_nlink(inode); 1603 + set_nlink(inode, 1); 1606 1604 } 1607 1605 if (ret < 0) 1608 1606 goto out;