This is a note to let you know that I've just added the patch titled btrfs: zoned: only allow one process to add pages to a relocation inode to the 5.15-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: btrfs-zoned-only-allow-one-process-to-add-pages-to-a-relocation-inode.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From foo@baz Fri Nov 19 01:33:42 PM CET 2021 From: Johannes Thumshirn <johannes.thumshirn@xxxxxxx> Date: Thu, 18 Nov 2021 17:58:15 +0900 Subject: btrfs: zoned: only allow one process to add pages to a relocation inode To: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Cc: linux-btrfs@xxxxxxxxxxxxxxx, stable@xxxxxxxxxxxxxxx, Naohiro Aota <naohiro.aota@xxxxxxx>, David Sterba <dsterba@xxxxxxxx>, Johannes Thumshirn <johannes.thumshirn@xxxxxxx> Message-ID: <c2c15d9992727dc6473d3dedb3d863874a3d3222.1637225333.git.johannes.thumshirn@xxxxxxx> From: Johannes Thumshirn <johannes.thumshirn@xxxxxxx> commit 35156d852762b58855f513b4f8bb7f32d69dc9c5 upstream Don't allow more than one process to add pages to a relocation inode on a zoned filesystem, otherwise we cannot guarantee the sequential write rule once we're filling preallocated extents on a zoned filesystem. Signed-off-by: Johannes Thumshirn <johannes.thumshirn@xxxxxxx> Reviewed-by: David Sterba <dsterba@xxxxxxxx> Signed-off-by: David Sterba <dsterba@xxxxxxxx> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@xxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/btrfs/extent_io.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -5120,6 +5120,9 @@ int extent_write_locked_range(struct ino int extent_writepages(struct address_space *mapping, struct writeback_control *wbc) { + struct inode *inode = mapping->host; + const bool data_reloc = btrfs_is_data_reloc_root(BTRFS_I(inode)->root); + const bool zoned = btrfs_is_zoned(BTRFS_I(inode)->root->fs_info); int ret = 0; struct extent_page_data epd = { .bio_ctrl = { 0 }, @@ -5127,7 +5130,15 @@ int extent_writepages(struct address_spa .sync_io = wbc->sync_mode == WB_SYNC_ALL, }; + /* + * Allow only a single thread to do the reloc work in zoned mode to + * protect the write pointer updates. + */ + if (data_reloc && zoned) + btrfs_inode_lock(inode, 0); ret = extent_write_cache_pages(mapping, wbc, &epd); + if (data_reloc && zoned) + btrfs_inode_unlock(inode, 0); ASSERT(ret <= 0); if (ret < 0) { end_write_bio(&epd, ret); Patches currently in stable-queue which might be from johannes.thumshirn@xxxxxxx are queue-5.15/btrfs-zoned-add-a-dedicated-data-relocation-block-group.patch queue-5.15/btrfs-check-for-relocation-inodes-on-zoned-btrfs-in-should_nocow.patch queue-5.15/btrfs-zoned-use-regular-writes-for-relocation.patch queue-5.15/btrfs-introduce-btrfs_is_data_reloc_root.patch queue-5.15/btrfs-zoned-allow-preallocation-for-relocation-inodes.patch queue-5.15/btrfs-zoned-only-allow-one-process-to-add-pages-to-a-relocation-inode.patch