Message ID | 20190612100542.1848-1-fdmanana@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Btrfs: fix race between block group removal and block group allocation | expand |
On Wed, Jun 12, 2019 at 11:05:42AM +0100, fdmanana@kernel.org wrote: > From: Filipe Manana <fdmanana@suse.com> > Fixes: 04216820fe83d5 ("Btrfs: fix race between fs trimming and block group remove/allocation") > Signed-off-by: Filipe Manana <fdmanana@suse.com> > --- > > NOTE: this applies only to a 5.2 kernel, although the problem exists in previous > kernels starting from 3.19, due to recent changes in the 5.2 merge window > that removed the fs_info->pending_chunks, a slightly different version of > this patch is needed, one which locks and unlocks the chunk mutex inside > the moved block. Thanks, I'll add it to misc-5.2, the type of the fix qualifies for a late rc, so I'll send it by the end of the week. > Such patch version can be found here: > > https://www.dropbox.com/s/1sv0hd2xbsn9jrt/Btrfs-fix-race-between-block-group-removal-and-block.patch?dl=0 I'd prefer to get patches instead of links to dropbox. You can send more patches in a series or as a reply to one of them and put the expected target version to the subject to eg. like [PATCH for 5.2] or [PATCH for <= 5.1] and put the note like the above with further details. Thanks.
On Wed, Jun 12, 2019 at 2:22 PM David Sterba <dsterba@suse.cz> wrote: > > On Wed, Jun 12, 2019 at 11:05:42AM +0100, fdmanana@kernel.org wrote: > > From: Filipe Manana <fdmanana@suse.com> > > > Fixes: 04216820fe83d5 ("Btrfs: fix race between fs trimming and block group remove/allocation") > > Signed-off-by: Filipe Manana <fdmanana@suse.com> > > --- > > > > NOTE: this applies only to a 5.2 kernel, although the problem exists in previous > > kernels starting from 3.19, due to recent changes in the 5.2 merge window > > that removed the fs_info->pending_chunks, a slightly different version of > > this patch is needed, one which locks and unlocks the chunk mutex inside > > the moved block. > > Thanks, I'll add it to misc-5.2, the type of the fix qualifies for a > late rc, so I'll send it by the end of the week. > > > > Such patch version can be found here: > > > > https://www.dropbox.com/s/1sv0hd2xbsn9jrt/Btrfs-fix-race-between-block-group-removal-and-block.patch?dl=0 > > I'd prefer to get patches instead of links to dropbox. You can send more > patches in a series or as a reply to one of them and put the expected > target version to the subject to eg. like [PATCH for 5.2] or [PATCH for > <= 5.1] and put the note like the above with further details. Thanks. It was just a note, I meant to send a proper patch once I got mail from the stable guys mentioning that the patch fails to apply. Thanks.
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 1aee51a9f3bf..3a26a4ab9cb8 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -10831,17 +10831,6 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, remove_em = (atomic_read(&block_group->trimming) == 0); spin_unlock(&block_group->lock); - if (remove_em) { - struct extent_map_tree *em_tree; - - em_tree = &fs_info->mapping_tree.map_tree; - write_lock(&em_tree->lock); - remove_extent_mapping(em_tree, em); - write_unlock(&em_tree->lock); - /* once for the tree */ - free_extent_map(em); - } - mutex_unlock(&fs_info->chunk_mutex); ret = remove_block_group_free_space(trans, block_group); @@ -10858,6 +10847,19 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, goto out; ret = btrfs_del_item(trans, root, path); + if (ret) + goto out; + + if (remove_em) { + struct extent_map_tree *em_tree; + + em_tree = &fs_info->mapping_tree.map_tree; + write_lock(&em_tree->lock); + remove_extent_mapping(em_tree, em); + write_unlock(&em_tree->lock); + /* once for the tree */ + free_extent_map(em); + } out: if (remove_rsv) btrfs_delayed_refs_rsv_release(fs_info, 1);