Skip to content

Commit 5278b7a

Browse files
luca020400kdave
authored andcommitted
btrfs: always update fstrim_range on failure in FITRIM ioctl
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 <wqu@suse.com> Signed-off-by: Luca Stefani <luca.stefani.ge1@gmail.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent b9cf75b commit 5278b7a

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

fs/btrfs/extent-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6551,13 +6551,13 @@ int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range)
65516551
continue;
65526552

65536553
ret = btrfs_trim_free_extents(device, &group_trimmed);
6554+
6555+
trimmed += group_trimmed;
65546556
if (ret) {
65556557
dev_failed++;
65566558
dev_ret = ret;
65576559
break;
65586560
}
6559-
6560-
trimmed += group_trimmed;
65616561
}
65626562
mutex_unlock(&fs_devices->device_list_mutex);
65636563

fs/btrfs/ioctl.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,11 @@ static noinline int btrfs_ioctl_fitrim(struct btrfs_fs_info *fs_info,
543543

544544
range.minlen = max(range.minlen, minlen);
545545
ret = btrfs_trim_fs(fs_info, &range);
546-
if (ret < 0)
547-
return ret;
548546

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

552-
return 0;
550+
return ret;
553551
}
554552

555553
int __pure btrfs_is_empty_uuid(const u8 *uuid)

0 commit comments

Comments
 (0)