btrfs: zoned: fix linked list corruption after log root tree allocation failure
authorFilipe Manana <fdmanana@suse.com>
Thu, 11 Mar 2021 15:13:30 +0000 (15:13 +0000)
committerDavid Sterba <dsterba@suse.com>
Mon, 15 Mar 2021 15:57:19 +0000 (16:57 +0100)
commite3d3b4157610164b0ec43d968b0dfedfe7c68992
treead175deedb026e3125dcdcd6aba170900921e843
parenta3ee79bd8fe17812d2305ccc4bf81bfeab395576
btrfs: zoned: fix linked list corruption after log root tree allocation failure

When using a zoned filesystem, while syncing the log, if we fail to
allocate the root node for the log root tree, we are not removing the
log context we allocated on stack from the list of log contexts of the
log root tree. This means after the return from btrfs_sync_log() we get
a corrupted linked list.

Fix this by allocating the node before adding our stack allocated context
to the list of log contexts of the log root tree.

Fixes: 3ddebf27fcd3a9 ("btrfs: zoned: reorder log node allocation on zoned filesystem")
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/tree-log.c