Skip to content

Commit 5a29232

Browse files
committed
Merge tag 'for-5.19-rc6-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: "A more fixes that seem to me to be important enough to get merged before release: - in zoned mode, fix leak of a structure when reading zone info, this happens on normal path so this can be significant - in zoned mode, revert an optimization added in 5.19-rc1 to finish a zone when the capacity is full, but this is not reliable in all cases - try to avoid short reads for compressed data or inline files when it's a NOWAIT read, applications should handle that but there are two, qemu and mariadb, that are affected" * tag 'for-5.19-rc6-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: zoned: drop optimization of zone finish btrfs: zoned: fix a leaked bioc in read_zone_info btrfs: return -EAGAIN for NOWAIT dio reads/writes on compressed and inline extents
2 parents 23458ac + b3a3b02 commit 5a29232

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

fs/btrfs/inode.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7681,7 +7681,19 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
76817681
if (test_bit(EXTENT_FLAG_COMPRESSED, &em->flags) ||
76827682
em->block_start == EXTENT_MAP_INLINE) {
76837683
free_extent_map(em);
7684-
ret = -ENOTBLK;
7684+
/*
7685+
* If we are in a NOWAIT context, return -EAGAIN in order to
7686+
* fallback to buffered IO. This is not only because we can
7687+
* block with buffered IO (no support for NOWAIT semantics at
7688+
* the moment) but also to avoid returning short reads to user
7689+
* space - this happens if we were able to read some data from
7690+
* previous non-compressed extents and then when we fallback to
7691+
* buffered IO, at btrfs_file_read_iter() by calling
7692+
* filemap_read(), we fail to fault in pages for the read buffer,
7693+
* in which case filemap_read() returns a short read (the number
7694+
* of bytes previously read is > 0, so it does not return -EFAULT).
7695+
*/
7696+
ret = (flags & IOMAP_NOWAIT) ? -EAGAIN : -ENOTBLK;
76857697
goto unlock_err;
76867698
}
76877699

fs/btrfs/zoned.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,12 +1735,14 @@ static int read_zone_info(struct btrfs_fs_info *fs_info, u64 logical,
17351735
ret = btrfs_map_sblock(fs_info, BTRFS_MAP_GET_READ_MIRRORS, logical,
17361736
&mapped_length, &bioc);
17371737
if (ret || !bioc || mapped_length < PAGE_SIZE) {
1738-
btrfs_put_bioc(bioc);
1739-
return -EIO;
1738+
ret = -EIO;
1739+
goto out_put_bioc;
17401740
}
17411741

1742-
if (bioc->map_type & BTRFS_BLOCK_GROUP_RAID56_MASK)
1743-
return -EINVAL;
1742+
if (bioc->map_type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
1743+
ret = -EINVAL;
1744+
goto out_put_bioc;
1745+
}
17441746

17451747
nofs_flag = memalloc_nofs_save();
17461748
nmirrors = (int)bioc->num_stripes;
@@ -1759,7 +1761,8 @@ static int read_zone_info(struct btrfs_fs_info *fs_info, u64 logical,
17591761
break;
17601762
}
17611763
memalloc_nofs_restore(nofs_flag);
1762-
1764+
out_put_bioc:
1765+
btrfs_put_bioc(bioc);
17631766
return ret;
17641767
}
17651768

@@ -1885,7 +1888,6 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
18851888
{
18861889
struct btrfs_fs_info *fs_info = block_group->fs_info;
18871890
struct map_lookup *map;
1888-
bool need_zone_finish;
18891891
int ret = 0;
18901892
int i;
18911893

@@ -1942,12 +1944,6 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
19421944
}
19431945
}
19441946

1945-
/*
1946-
* The block group is not fully allocated, so not fully written yet. We
1947-
* need to send ZONE_FINISH command to free up an active zone.
1948-
*/
1949-
need_zone_finish = !btrfs_zoned_bg_is_full(block_group);
1950-
19511947
block_group->zone_is_active = 0;
19521948
block_group->alloc_offset = block_group->zone_capacity;
19531949
block_group->free_space_ctl->free_space = 0;
@@ -1963,15 +1959,13 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
19631959
if (device->zone_info->max_active_zones == 0)
19641960
continue;
19651961

1966-
if (need_zone_finish) {
1967-
ret = blkdev_zone_mgmt(device->bdev, REQ_OP_ZONE_FINISH,
1968-
physical >> SECTOR_SHIFT,
1969-
device->zone_info->zone_size >> SECTOR_SHIFT,
1970-
GFP_NOFS);
1962+
ret = blkdev_zone_mgmt(device->bdev, REQ_OP_ZONE_FINISH,
1963+
physical >> SECTOR_SHIFT,
1964+
device->zone_info->zone_size >> SECTOR_SHIFT,
1965+
GFP_NOFS);
19711966

1972-
if (ret)
1973-
return ret;
1974-
}
1967+
if (ret)
1968+
return ret;
19751969

19761970
btrfs_dev_clear_active_zone(device, physical);
19771971
}

0 commit comments

Comments
 (0)