From patchwork Wed Mar 5 17:45:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 14003095 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 411CE2500CF for ; Wed, 5 Mar 2025 17:45:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741196757; cv=none; b=oVLGpymUOaqj03qHu0T6ynGeOngGe2rapVdfv0ZkHsa9HxPiY0P3OZF8l28kLrPwtpDjlNbJqox3lceBPNm4H79DjFqqaHDDBrsJSXS2Dd3ZnSOHsauQmIn54++xMoUuH85yjsbY40px/+iDEJcvcXEyOTcO2VIPjed5gEOZChs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741196757; c=relaxed/simple; bh=aodlA1CuClmpgOwW88QPNv4Z4Lx/b5Qm+uq1Sc0PweQ=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MOKAct3aN/zrlTbqelXZmXx1rsDQx99rW1cgM/HOFKOciif4TY+PYeJIAlGoiBzs4IQWUt+1RVkKtbaZQkY3QkY4YRz6iYM4MVSR177zFPobZ5wXqkVVZu18UmsJd1cm7GUXFFM0zyGe7Gy9otscN5fJtJFkVSsG4BqhSIJQrQo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Yzgipmvm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Yzgipmvm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2528AC4CEE0 for ; Wed, 5 Mar 2025 17:45:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741196756; bh=aodlA1CuClmpgOwW88QPNv4Z4Lx/b5Qm+uq1Sc0PweQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Yzgipmvmyrfdw3LR62qsE1fT3Nz3rAHLrV7ksZ54ylVpf4ghz1IRSZzJVyKxPHNX9 6SXKYtl11scJfYsP7IkmjIGpCHfH9Qjy6tatWZh4Grr+1znabL3N4k66gChr45x9ba SB1FehXtH+9jhZ928DvHRGtALofMbrpBx1JxXXZGE7hskqjkEMD10MD1oRxYW+vCbU dmVDTSfu5rxxHdrOGfZz4cbWWHY1V6KCvjF/AbdRHD/KuXoXbL/MSGnssfQaWiN2IL DDBc7XZlOzb5EwT9uKOJB2pHu4k0Vfy+U2M+uFCwV6INWOTVR5iIFWg96VbrmsqDSw e6Mr7por4KvTA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/4] btrfs: fix non-empty delayed iputs list on unmount due to endio workers Date: Wed, 5 Mar 2025 17:45:47 +0000 Message-Id: <6421b94741d35f6ca2fa2e85afcf5a7eb39d38a5.1741196484.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana At close_ctree() after we have ran delayed iputs either through explicitly calling btrfs_run_delayed_iputs() or later during the call to btrfs_commit_super() or btrfs_error_commit_super(), we assert that the delayed iputs list is empty. Sometimes this assertion may fail because delayed iputs may have been added to the list after we last ran delayed iputs, and this happens due to workers in the endio_workers workqueue still running. These workers can do a final put on an ordered extent attached to a data bio, which results in adding a delayed iput. This is done at btrfs_bio_end_io() and its helper __btrfs_bio_end_io(). Fix this by flushing the endio_workers workqueue before running delayed iputs at close_ctree(). David reported this when running generic/648. Reported-by: David Sterba Fixes: ec63b84d4611 ("btrfs: add an ordered_extent pointer to struct btrfs_bio") Signed-off-by: Filipe Manana --- fs/btrfs/disk-io.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index d96ea974ef73..df8e075e69a3 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4340,6 +4340,16 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info) */ btrfs_flush_workqueue(fs_info->delalloc_workers); + /* + * We can also have ordered extents getting their last reference dropped + * from the endio_workers workqueue because for data bios we keep a + * reference on an ordered extent which gets dropped when running + * btrfs_bio_end_io() in that workqueue, and that final drop results in + * adding a delayed iput for the inode. + */ + if (fs_info->endio_workers) + flush_workqueue(fs_info->endio_workers); + /* * After we parked the cleaner kthread, ordered extents may have * completed and created new delayed iputs. If one of the async reclaim From patchwork Wed Mar 5 17:45:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 14003096 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37686250C0D for ; Wed, 5 Mar 2025 17:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741196758; cv=none; b=ZvXBkM4HAnoD8am/jHvvijxkiDMJUDvmdKgfqpvCcvuxlqocCK+aFE+lDhs9FKbOifCLJFtgrxRn9JwJQI28fb64bn1l7/12qnWJdH9elpN6s7dtLeyxwgo38FQ95ShlgNYxA0gnYKeKilCsZM3QMSIAp/BV1BLrbVTq59eiW64= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741196758; c=relaxed/simple; bh=2UyXHbsP9U4V63YhVQ8jwT7pZp3V8BmgdW6TRlynpCg=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fvXeuaCv7mpM53eEJjBLFGEGZeE7XoLXB+wNGG+am5/ihJZqqjXHsJvDtPuof1haRf5ZlZSp1IFQPvKnrI+LwD+pVLwI3Gvjwx7FxxuMGXw/EQCU4Kt8Om2jQj3ouJzWf2x3BhoLy1haNGPf7Xr1d6QvIWwVWSaP5yYj7+ekBSY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MWw7hWaA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MWw7hWaA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28970C4CED1 for ; Wed, 5 Mar 2025 17:45:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741196757; bh=2UyXHbsP9U4V63YhVQ8jwT7pZp3V8BmgdW6TRlynpCg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MWw7hWaAh19U9iEasW40snB2XemXlh97gjo6UuIAdd1CHeASlvk+5jWmKy3iz2BhV FJRhgk1CECtI9y600wKC1beSe4O2u+UdfnysPTPD965PFD+gnWkM2tETGbSYKP3Vn+ ZxtQXIgiuVGA2/moVzFtp58Va0w+1mJLa6ylp5Ky6ycFEymrvnty5kbNiOhELFb8/e cL3oyJI4Zt2DkIYsYUL3JxPMJu920fmBGH5kEdOAJHDM8IdKICQR9RAbD/qWGCiDHG ggpu1ndXTjdlgfMvGplztccb65b4Zy40sdeucc7s7seYHaenEg2Ai0WgHzuRPiq6Hk ECS4fF9FhFX+g== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/4] btrfs: fix non-empty delayed iputs list on unmount due to compressed write workers Date: Wed, 5 Mar 2025 17:45:48 +0000 Message-Id: <3111c41408f2cb11096b9fe002a08fd09b8fb89c.1741196484.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana At close_ctree() after we have ran delayed iputs either through explicitly calling btrfs_run_delayed_iputs() or later during the call to btrfs_commit_super() or btrfs_error_commit_super(), we assert that the delayed iputs list is empty. When we have compressed writes this assertion may fail because delayed iputs may have been added to the list after we last ran delayed iputs. This happens like this: 1) We have a compressed write bio executing; 2) We enter close_ctree() and flush the fs_info->endio_write_workers queue which is the queue used for running ordered extent completion; 3) The compressed write bio finishes and enters btrfs_finish_compressed_write_work(), where it calls btrfs_finish_ordered_extent() which in turn calls btrfs_queue_ordered_fn(), which queues a work item in the fs_info->endio_write_workers queue that we have flushed before; 4) At close_ctree() we proceed, run all existing delayed iputs and call btrfs_commit_super() (which also runs delayed iputs), but before we run the following assertion below: ASSERT(list_empty(&fs_info->delayed_iputs)) A delayed iput is added by the step below... 5) The ordered extent completion job queued in step 3 runs and results in creating a delayed iput when dropping the last reference of the ordered extent (a call to btrfs_put_ordered_extent() made from btrfs_finish_one_ordered()); 6) At this point the delayed iputs list is not empty, so the assertion at close_ctree() fails. Fix this by flushing the fs_info->compressed_write_workers queue at close_ctree() before flushing the fs_info->endio_write_workers queue, respecting the queue dependency as the later is responsible for the execution of ordered extent completion. Signed-off-by: Filipe Manana --- fs/btrfs/disk-io.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index df8e075e69a3..95277c05fefa 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4350,6 +4350,19 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info) if (fs_info->endio_workers) flush_workqueue(fs_info->endio_workers); + /* + * When finishing a compressed write bio we schedule a work queue item + * to finish an ordered extent - btrfs_finish_compressed_write_work() + * calls btrfs_finish_ordered_extent() which in turns does a call to + * btrfs_queue_ordered_fn(), and that queues the ordered extent + * completion either in the endio_write_workers work queue or in the + * fs_info->endio_freespace_worker work queue. We flush those queues + * below, so before we flush them we must flush this queue for the + * workers of compressed writes. + */ + if (fs_info->compressed_write_workers) + flush_workqueue(fs_info->compressed_write_workers); + /* * After we parked the cleaner kthread, ordered extents may have * completed and created new delayed iputs. If one of the async reclaim From patchwork Wed Mar 5 17:45:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 14003097 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D25FF2512D9 for ; Wed, 5 Mar 2025 17:45:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741196758; cv=none; b=CoJA1/8flUjUZFSZgPTtHgNLc/3cdh//GQuB4XEhAWfaDVQenXeBZtmU+ZYqTtk1+LCzke2PVqHvG8F0k3gExucJ29ptiHLiTAUnnU3VWLNm1PUPnc45rhZ6e0VjBsiw1Pkbzv5OJjS4Va1OGVnr8n/21WSyd2FJSn9o59UvSiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741196758; c=relaxed/simple; bh=MgWOsgZqI5T8K169gZV9TDzeg88d/7NeM/BpQfmy4nw=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rtBtpGL7G0AKLjvWe+Kn3ZyWFhCQk3Xk7YGt75qai1TQnvDxRdD+LY9c4zaukuBbrCUdhHr34eEprimFfOQgssI2lCPSkqv7w9U2sd8f0fUxBnSgpwMh0DviowUpC/qRkWDJ9QE0aWGTE/DgsNf83BaqmBDxDQBdXUng1HVGUdk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YDYVQYa0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YDYVQYa0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2FD43C4CEED for ; Wed, 5 Mar 2025 17:45:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741196758; bh=MgWOsgZqI5T8K169gZV9TDzeg88d/7NeM/BpQfmy4nw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YDYVQYa0fU8Pzl2786MpxXdfkMwiJBqgfEZ36DZSUY/ECAVFY5OqHn0ER+NyIvoHU SA4RS9/DnseAYp7k+cYpvfMfTrO2l9kNIoXcqJZ3dUG8N2+Juc4bInMzKuUmR2BwT6 sPowIHw8EYnbmHSnw45AWEyYcd99eJ+6Pb1vdTWHBvEECPv4yyQBhlpLgryaBgo7ld 4HXcd0m+BZap5Wbx/wIVrZc4wrC149qLDaI+Ny59BEVKLqPArjsfrAToGt5VsSJ/HS E30mDxVV3T25ejoYizBgkp1GKN1AmM/cL0Shsl/rAJ2PFdSQMWxn2bIo9aQozE/w0e HmxIm+rqhGhBg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/4] btrfs: move __btrfs_bio_end_io() code into its single caller Date: Wed, 5 Mar 2025 17:45:49 +0000 Message-Id: <427e1cc1519d2117c9cdedba51929e958340cdac.1741196484.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The __btrfs_bio_end_io() helper is trivial and has a single caller, so there's no point in having a dedicated helper function. Further the double underscore prefix in the name is discouraged. So get rid of it and move its code into the caller (btrfs_bio_end_io()). Signed-off-by: Filipe Manana --- fs/btrfs/bio.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 2f32ee215c3f..07bbb0da2812 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -105,18 +105,6 @@ static void btrfs_cleanup_bio(struct btrfs_bio *bbio) bio_put(&bbio->bio); } -static void __btrfs_bio_end_io(struct btrfs_bio *bbio) -{ - if (bbio_has_ordered_extent(bbio)) { - struct btrfs_ordered_extent *ordered = bbio->ordered; - - bbio->end_io(bbio); - btrfs_put_ordered_extent(ordered); - } else { - bbio->end_io(bbio); - } -} - void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status) { bbio->bio.bi_status = status; @@ -138,7 +126,15 @@ void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status) /* Load split bio's error which might be set above. */ if (status == BLK_STS_OK) bbio->bio.bi_status = READ_ONCE(bbio->status); - __btrfs_bio_end_io(bbio); + + if (bbio_has_ordered_extent(bbio)) { + struct btrfs_ordered_extent *ordered = bbio->ordered; + + bbio->end_io(bbio); + btrfs_put_ordered_extent(ordered); + } else { + bbio->end_io(bbio); + } } } From patchwork Wed Mar 5 17:45:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 14003098 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DA832512D9 for ; Wed, 5 Mar 2025 17:45:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741196760; cv=none; b=er1qneHdNZwkWGTI3Tk9qTJwtPrzLTSRyBCTiWkd9+QLEIBdmfwg2TF/77qPWDIucc3qg3wkOmVtXtFjalR3HmsMH+rKMbhcNnZnaOsUEPgjUyXRV43F81cSn6TzyDBCRcyqOd5p83vqlWb+z/IA82NTI+gLUFQN72MII3ynqro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741196760; c=relaxed/simple; bh=UWVLiD4f7nvJaf4OdEkWZ/tDZYdLBqAGx4ZsEmp01co=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kfumyld/SZpvv8KER4yJFnxwR0PalIZTSwnvegTZxXnrcMFFHgpidqmbjv9GPRXaeuchyUrOoJBUVMJvEh6vJph6JAI1eDvScupjjfqeZlzHovHIU0wpXkkOrUNLpOddBKRLAbyqRzV8OSJVxq9Bv7LwXB07yHp74TFwLBy+V74= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gAgA6LWM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gAgA6LWM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31AB5C4CEE2 for ; Wed, 5 Mar 2025 17:45:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741196759; bh=UWVLiD4f7nvJaf4OdEkWZ/tDZYdLBqAGx4ZsEmp01co=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gAgA6LWMxkeBeBuLkO/6rum5gpdCquoSl86bD2Xj+iYwobOJRUxwurwgSrHLAbakj 5lvPstVy7Thm4TudCek7ykU4HHfPzEBUBHnwcXrIxwfWJSjeaphdeH68BgzeoBYjMu Lr+oVvdbp06/9uatkVrpdkJVhJB7gghQLrdfwTzmUB6Jt+KF1BwueNT0cl6iCW51Z6 qsCjvVgg5VTVTyadY7YAd281r4WTRM04rGTpGhuEj881j9B/K9qJaIFxhqejroQagW WmskwZh+jdtK0zXcd5WwCeBBoQ0CzPzS3+T4SuBorQ9Ee557QsOt886guJimy/4OUl SWcntKedVRMEQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 4/4] btrfs: move btrfs_cleanup_bio() code into its single caller Date: Wed, 5 Mar 2025 17:45:50 +0000 Message-Id: <6b96e8cc67e95a3d1bac6f0974e2b5ee3824dd43.1741196484.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The btrfs_cleanup_bio() helper is trivial and has a single caller, there's no point in having a dedicated helper function. So get rid of it and move its code into the caller (btrfs_bio_end_io()). Signed-off-by: Filipe Manana --- fs/btrfs/bio.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 07bbb0da2812..e9840954bf4a 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -97,21 +97,17 @@ static struct btrfs_bio *btrfs_split_bio(struct btrfs_fs_info *fs_info, return bbio; } -/* Free a bio that was never submitted to the underlying device. */ -static void btrfs_cleanup_bio(struct btrfs_bio *bbio) -{ - if (bbio_has_ordered_extent(bbio)) - btrfs_put_ordered_extent(bbio->ordered); - bio_put(&bbio->bio); -} - void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status) { bbio->bio.bi_status = status; if (bbio->bio.bi_pool == &btrfs_clone_bioset) { struct btrfs_bio *orig_bbio = bbio->private; - btrfs_cleanup_bio(bbio); + /* Free bio that was never submitted to the underlying device. */ + if (bbio_has_ordered_extent(bbio)) + btrfs_put_ordered_extent(bbio->ordered); + bio_put(&bbio->bio); + bbio = orig_bbio; }