| .. | .. |
|---|
| 1173 | 1173 | ret = __btrfs_commit_inode_delayed_items(trans, path, |
|---|
| 1174 | 1174 | curr_node); |
|---|
| 1175 | 1175 | if (ret) { |
|---|
| 1176 | | - btrfs_release_delayed_node(curr_node); |
|---|
| 1177 | | - curr_node = NULL; |
|---|
| 1178 | 1176 | btrfs_abort_transaction(trans, ret); |
|---|
| 1179 | 1177 | break; |
|---|
| 1180 | 1178 | } |
|---|
| 1181 | 1179 | |
|---|
| 1182 | 1180 | prev_node = curr_node; |
|---|
| 1183 | 1181 | curr_node = btrfs_next_delayed_node(curr_node); |
|---|
| 1182 | + /* |
|---|
| 1183 | + * See the comment below about releasing path before releasing |
|---|
| 1184 | + * node. If the commit of delayed items was successful the path |
|---|
| 1185 | + * should always be released, but in case of an error, it may |
|---|
| 1186 | + * point to locked extent buffers (a leaf at the very least). |
|---|
| 1187 | + */ |
|---|
| 1188 | + ASSERT(path->nodes[0] == NULL); |
|---|
| 1184 | 1189 | btrfs_release_delayed_node(prev_node); |
|---|
| 1185 | 1190 | } |
|---|
| 1186 | 1191 | |
|---|
| 1192 | + /* |
|---|
| 1193 | + * Release the path to avoid a potential deadlock and lockdep splat when |
|---|
| 1194 | + * releasing the delayed node, as that requires taking the delayed node's |
|---|
| 1195 | + * mutex. If another task starts running delayed items before we take |
|---|
| 1196 | + * the mutex, it will first lock the mutex and then it may try to lock |
|---|
| 1197 | + * the same btree path (leaf). |
|---|
| 1198 | + */ |
|---|
| 1199 | + btrfs_free_path(path); |
|---|
| 1200 | + |
|---|
| 1187 | 1201 | if (curr_node) |
|---|
| 1188 | 1202 | btrfs_release_delayed_node(curr_node); |
|---|
| 1189 | | - btrfs_free_path(path); |
|---|
| 1190 | 1203 | trans->block_rsv = block_rsv; |
|---|
| 1191 | 1204 | |
|---|
| 1192 | 1205 | return ret; |
|---|