btrfs: zoned: fix parallel compressed writes
authorJohannes Thumshirn <johannes.thumshirn@wdc.com>
Tue, 18 May 2021 15:40:28 +0000 (00:40 +0900)
committerDavid Sterba <dsterba@suse.com>
Thu, 20 May 2021 13:51:07 +0000 (15:51 +0200)
commit764c7c9a464b68f7c6a5a9ec0b923176a05e8e8f
tree40fb1fea29573fe90c6473331d4285d275f36c14
parente380adfc213a13677993c0e35cb48f5a8e61ebb0
btrfs: zoned: fix parallel compressed writes

When multiple processes write data to the same block group on a
compressed zoned filesystem, the underlying device could report I/O
errors and data corruption is possible.

This happens because on a zoned file system, compressed data writes
where sent to the device via a REQ_OP_WRITE instead of a
REQ_OP_ZONE_APPEND operation. But with REQ_OP_WRITE and parallel
submission it cannot be guaranteed that the data is always submitted
aligned to the underlying zone's write pointer.

The change to using REQ_OP_ZONE_APPEND instead of REQ_OP_WRITE on a
zoned filesystem is non intrusive on a regular file system or when
submitting to a conventional zone on a zoned filesystem, as it is
guarded by btrfs_use_zone_append.

Reported-by: David Sterba <dsterba@suse.com>
Fixes: 9d294a685fbc ("btrfs: zoned: enable to mount ZONED incompat flag")
CC: stable@vger.kernel.org # 5.12.x: e380adfc213a13: btrfs: zoned: pass start block to btrfs_use_zone_append
CC: stable@vger.kernel.org # 5.12.x
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/compression.c