Skip to content

Commit 8a172f7

Browse files
kdaveroxanan1996
authored andcommitted
btrfs: handle errors returned from unpin_extent_cache()
BugLink: https://bugs.launchpad.net/bugs/2060531 [ Upstream commit c03c89f821e51325d0e592cf625cf5e0a26fa3a7 ] We've had numerous attempts to let function unpin_extent_cache() return void as it only returns 0. There are still error cases to handle so do that, in addition to the verbose messages. The only caller btrfs_finish_one_ordered() will now abort the transaction, previously it let it continue which could lead to further problems. Signed-off-by: David Sterba <dsterba@suse.com> Stable-dep-of: 4dc1d69c2b10 ("btrfs: fix warning messages not printing interval at unpin_extent_range()") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
1 parent e986260 commit 8a172f7

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

fs/btrfs/extent_map.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ static void try_merge_map(struct extent_map_tree *tree, struct extent_map *em)
291291
* Called after an extent has been written to disk properly. Set the generation
292292
* to the generation that actually added the file item to the inode so we know
293293
* we need to sync this extent when we call fsync().
294+
*
295+
* Returns: 0 on success
296+
* -ENOENT when the extent is not found in the tree
297+
* -EUCLEAN if the found extent does not match the expected start
294298
*/
295299
int unpin_extent_cache(struct btrfs_inode *inode, u64 start, u64 len, u64 gen)
296300
{
@@ -308,14 +312,18 @@ int unpin_extent_cache(struct btrfs_inode *inode, u64 start, u64 len, u64 gen)
308312
"no extent map found for inode %llu (root %lld) when unpinning extent range [%llu, %llu), generation %llu",
309313
btrfs_ino(inode), btrfs_root_id(inode->root),
310314
start, len, gen);
315+
ret = -ENOENT;
311316
goto out;
312317
}
313318

314-
if (WARN_ON(em->start != start))
319+
if (WARN_ON(em->start != start)) {
315320
btrfs_warn(fs_info,
316321
"found extent map for inode %llu (root %lld) with unexpected start offset %llu when unpinning extent range [%llu, %llu), generation %llu",
317322
btrfs_ino(inode), btrfs_root_id(inode->root),
318323
em->start, start, len, gen);
324+
ret = -EUCLEAN;
325+
goto out;
326+
}
319327

320328
em->generation = gen;
321329
em->flags &= ~EXTENT_FLAG_PINNED;

fs/btrfs/inode.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3127,8 +3127,13 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
31273127
ordered_extent->disk_num_bytes);
31283128
}
31293129
}
3130-
unpin_extent_cache(inode, ordered_extent->file_offset,
3131-
ordered_extent->num_bytes, trans->transid);
3130+
if (ret < 0) {
3131+
btrfs_abort_transaction(trans, ret);
3132+
goto out;
3133+
}
3134+
3135+
ret = unpin_extent_cache(inode, ordered_extent->file_offset,
3136+
ordered_extent->num_bytes, trans->transid);
31323137
if (ret < 0) {
31333138
btrfs_abort_transaction(trans, ret);
31343139
goto out;

0 commit comments

Comments
 (0)