Skip to content

Commit

Permalink
btrfs: always update fstrim_range on failure in FITRIM ioctl
Browse files Browse the repository at this point in the history
Even in case of failure we could've discarded some data and userspace
should be made aware of it, so copy fstrim_range to userspace
regardless.

Also make sure to update the trimmed bytes amount even if
btrfs_trim_free_extents fails.

Reviewed-by: Qu Wenruo <[email protected]>
Signed-off-by: Luca Stefani <[email protected]>
Reviewed-by: David Sterba <[email protected]>
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
luca020400 authored and kdave committed Sep 2, 2024
1 parent b9cf75b commit 5278b7a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -6551,13 +6551,13 @@ int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range)
continue;

ret = btrfs_trim_free_extents(device, &group_trimmed);

trimmed += group_trimmed;
if (ret) {
dev_failed++;
dev_ret = ret;
break;
}

trimmed += group_trimmed;
}
mutex_unlock(&fs_devices->device_list_mutex);

Expand Down
4 changes: 1 addition & 3 deletions fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,11 @@ static noinline int btrfs_ioctl_fitrim(struct btrfs_fs_info *fs_info,

range.minlen = max(range.minlen, minlen);
ret = btrfs_trim_fs(fs_info, &range);
if (ret < 0)
return ret;

if (copy_to_user(arg, &range, sizeof(range)))
return -EFAULT;

return 0;
return ret;
}

int __pure btrfs_is_empty_uuid(const u8 *uuid)
Expand Down

0 comments on commit 5278b7a

Please sign in to comment.