Skip to content

Commit 6fa425a

Browse files
committed
Merge tag 'for-5.2-rc4-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fix from David Sterba: "One regression fix to TRIM ioctl. The range cannot be used as its meaning can be confusing regarding physical and logical addresses. This confusion in code led to potential corruptions when the range overlapped data. The original patch made it to several stable kernels and was promptly reverted, the version for master branch is different due to additional changes but the change is effectively the same" * tag 'for-5.2-rc4-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: Always trim all unallocated space in btrfs_trim_free_extents
2 parents 01ccc3a + 8103d10 commit 6fa425a

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

fs/btrfs/extent-tree.c

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11137,13 +11137,11 @@ int btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info,
1113711137
* it while performing the free space search since we have already
1113811138
* held back allocations.
1113911139
*/
11140-
static int btrfs_trim_free_extents(struct btrfs_device *device,
11141-
struct fstrim_range *range, u64 *trimmed)
11140+
static int btrfs_trim_free_extents(struct btrfs_device *device, u64 *trimmed)
1114211141
{
11143-
u64 start, len = 0, end = 0;
11142+
u64 start = SZ_1M, len = 0, end = 0;
1114411143
int ret;
1114511144

11146-
start = max_t(u64, range->start, SZ_1M);
1114711145
*trimmed = 0;
1114811146

1114911147
/* Discard not supported = nothing to do. */
@@ -11186,22 +11184,6 @@ static int btrfs_trim_free_extents(struct btrfs_device *device,
1118611184
break;
1118711185
}
1118811186

11189-
/* Keep going until we satisfy minlen or reach end of space */
11190-
if (len < range->minlen) {
11191-
mutex_unlock(&fs_info->chunk_mutex);
11192-
start += len;
11193-
continue;
11194-
}
11195-
11196-
/* If we are out of the passed range break */
11197-
if (start > range->start + range->len - 1) {
11198-
mutex_unlock(&fs_info->chunk_mutex);
11199-
break;
11200-
}
11201-
11202-
start = max(range->start, start);
11203-
len = min(range->len, len);
11204-
1120511187
ret = btrfs_issue_discard(device->bdev, start, len,
1120611188
&bytes);
1120711189
if (!ret)
@@ -11216,10 +11198,6 @@ static int btrfs_trim_free_extents(struct btrfs_device *device,
1121611198
start += len;
1121711199
*trimmed += bytes;
1121811200

11219-
/* We've trimmed enough */
11220-
if (*trimmed >= range->len)
11221-
break;
11222-
1122311201
if (fatal_signal_pending(current)) {
1122411202
ret = -ERESTARTSYS;
1122511203
break;
@@ -11303,7 +11281,7 @@ int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range)
1130311281
mutex_lock(&fs_info->fs_devices->device_list_mutex);
1130411282
devices = &fs_info->fs_devices->devices;
1130511283
list_for_each_entry(device, devices, dev_list) {
11306-
ret = btrfs_trim_free_extents(device, range, &group_trimmed);
11284+
ret = btrfs_trim_free_extents(device, &group_trimmed);
1130711285
if (ret) {
1130811286
dev_failed++;
1130911287
dev_ret = ret;

0 commit comments

Comments
 (0)