hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/fs/btrfs/delayed-inode.c
....@@ -1173,20 +1173,33 @@
11731173 ret = __btrfs_commit_inode_delayed_items(trans, path,
11741174 curr_node);
11751175 if (ret) {
1176
- btrfs_release_delayed_node(curr_node);
1177
- curr_node = NULL;
11781176 btrfs_abort_transaction(trans, ret);
11791177 break;
11801178 }
11811179
11821180 prev_node = curr_node;
11831181 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);
11841189 btrfs_release_delayed_node(prev_node);
11851190 }
11861191
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
+
11871201 if (curr_node)
11881202 btrfs_release_delayed_node(curr_node);
1189
- btrfs_free_path(path);
11901203 trans->block_rsv = block_rsv;
11911204
11921205 return ret;