public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] btrfs: handle bio_split() error
@ 2024-11-28  9:42 Johannes Thumshirn
  2024-11-28 14:50 ` David Sterba
  2024-11-29 16:34 ` David Sterba
  0 siblings, 2 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2024-11-28  9:42 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Johannes Thumshirn

From: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Commit bfebde92bd31 ("block: Rework bio_split() return value") changed
bio_split() so that it can return errors.

Add error handling for it in btrfs_split_bio() and ultimately
btrfs_submit_chunk().

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---

Changes to v3:
- decrement bio counter

Changes to v2:
- assign the split bbio to a new variable, so we can keep the old error
  paths and end the original bbio

Changes to v1:
- convert ERR_PTR to blk_status_t
- correctly fail already split bbios
---
 fs/btrfs/bio.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
index 1f216d07eff6..af3db0a7ae4d 100644
--- a/fs/btrfs/bio.c
+++ b/fs/btrfs/bio.c
@@ -81,6 +81,9 @@ static struct btrfs_bio *btrfs_split_bio(struct btrfs_fs_info *fs_info,
 
 	bio = bio_split(&orig_bbio->bio, map_length >> SECTOR_SHIFT, GFP_NOFS,
 			&btrfs_clone_bioset);
+	if (IS_ERR(bio))
+		return ERR_CAST(bio);
+
 	bbio = btrfs_bio(bio);
 	btrfs_bio_init(bbio, fs_info, NULL, orig_bbio);
 	bbio->inode = orig_bbio->inode;
@@ -678,7 +681,8 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
 				&bioc, &smap, &mirror_num);
 	if (error) {
 		ret = errno_to_blk_status(error);
-		goto fail;
+		btrfs_bio_counter_dec(fs_info);
+		goto end_bbio;
 	}
 
 	map_length = min(map_length, length);
@@ -686,7 +690,15 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
 		map_length = btrfs_append_map_length(bbio, map_length);
 
 	if (map_length < length) {
-		bbio = btrfs_split_bio(fs_info, bbio, map_length);
+		struct btrfs_bio *split;
+
+		split = btrfs_split_bio(fs_info, bbio, map_length);
+		if (IS_ERR(split)) {
+			ret = errno_to_blk_status(PTR_ERR(split));
+			btrfs_bio_counter_dec(fs_info);
+			goto end_bbio;
+		}
+		bbio = split;
 		bio = &bbio->bio;
 	}
 
@@ -760,6 +772,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
 
 		btrfs_bio_end_io(remaining, ret);
 	}
+end_bbio:
 	btrfs_bio_end_io(bbio, ret);
 	/* Do not submit another chunk */
 	return true;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v4] btrfs: handle bio_split() error
  2024-11-28  9:42 [PATCH v4] btrfs: handle bio_split() error Johannes Thumshirn
@ 2024-11-28 14:50 ` David Sterba
  2024-11-28 15:40   ` Johannes Thumshirn
  2024-11-29 16:34 ` David Sterba
  1 sibling, 1 reply; 5+ messages in thread
From: David Sterba @ 2024-11-28 14:50 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: linux-btrfs, Johannes Thumshirn

On Thu, Nov 28, 2024 at 10:42:01AM +0100, Johannes Thumshirn wrote:
> From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> 
> Commit bfebde92bd31 ("block: Rework bio_split() return value") changed
> bio_split() so that it can return errors.

Where is this commit or what are the merge plans?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4] btrfs: handle bio_split() error
  2024-11-28 14:50 ` David Sterba
@ 2024-11-28 15:40   ` Johannes Thumshirn
  2024-11-28 16:06     ` David Sterba
  0 siblings, 1 reply; 5+ messages in thread
From: Johannes Thumshirn @ 2024-11-28 15:40 UTC (permalink / raw)
  To: dsterba@suse.cz, Johannes Thumshirn; +Cc: linux-btrfs@vger.kernel.org

On 28.11.24 15:50, David Sterba wrote:
> On Thu, Nov 28, 2024 at 10:42:01AM +0100, Johannes Thumshirn wrote:
>> From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
>>
>> Commit bfebde92bd31 ("block: Rework bio_split() return value") changed
>> bio_split() so that it can return errors.
> 
> Where is this commit or what are the merge plans?
> 

It is 'e546fe1da9bd ("block: Rework bio_split() return value")' in 
Linus' tree,. I must have had it applied locally,  sorry for that.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4] btrfs: handle bio_split() error
  2024-11-28 15:40   ` Johannes Thumshirn
@ 2024-11-28 16:06     ` David Sterba
  0 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2024-11-28 16:06 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: Johannes Thumshirn, linux-btrfs@vger.kernel.org

On Thu, Nov 28, 2024 at 03:40:56PM +0000, Johannes Thumshirn wrote:
> On 28.11.24 15:50, David Sterba wrote:
> > On Thu, Nov 28, 2024 at 10:42:01AM +0100, Johannes Thumshirn wrote:
> >> From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> >>
> >> Commit bfebde92bd31 ("block: Rework bio_split() return value") changed
> >> bio_split() so that it can return errors.
> > 
> > Where is this commit or what are the merge plans?
> > 
> 
> It is 'e546fe1da9bd ("block: Rework bio_split() return value")' in 
> Linus' tree,. I must have had it applied locally,  sorry for that.

I see, so it was merged to 6.12-rc4, I thought there was some inter-git tree
dependency but we can merge it as usual.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4] btrfs: handle bio_split() error
  2024-11-28  9:42 [PATCH v4] btrfs: handle bio_split() error Johannes Thumshirn
  2024-11-28 14:50 ` David Sterba
@ 2024-11-29 16:34 ` David Sterba
  1 sibling, 0 replies; 5+ messages in thread
From: David Sterba @ 2024-11-29 16:34 UTC (permalink / raw)
  To: Johannes Thumshirn; +Cc: linux-btrfs, Johannes Thumshirn

On Thu, Nov 28, 2024 at 10:42:01AM +0100, Johannes Thumshirn wrote:
> From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> 
> Commit bfebde92bd31 ("block: Rework bio_split() return value") changed
> bio_split() so that it can return errors.
> 
> Add error handling for it in btrfs_split_bio() and ultimately
> btrfs_submit_chunk().
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
> 
> Changes to v3:
> - decrement bio counter

Is it possible to have some sanity checks for the bio counter? The
missing decrement could be hard to spot, but as it's a global counter
and possibly spanning unbounded time we'd have to add some checkpoints
like do per transaction accounting.

Otherwise,
Reviewed-by: David Sterba <dsterba@suse.com>

> Changes to v2:
> - assign the split bbio to a new variable, so we can keep the old error
>   paths and end the original bbio
> 
> Changes to v1:
> - convert ERR_PTR to blk_status_t
> - correctly fail already split bbios
> ---
>  fs/btrfs/bio.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
> index 1f216d07eff6..af3db0a7ae4d 100644
> --- a/fs/btrfs/bio.c
> +++ b/fs/btrfs/bio.c
> @@ -81,6 +81,9 @@ static struct btrfs_bio *btrfs_split_bio(struct btrfs_fs_info *fs_info,
>  
>  	bio = bio_split(&orig_bbio->bio, map_length >> SECTOR_SHIFT, GFP_NOFS,
>  			&btrfs_clone_bioset);
> +	if (IS_ERR(bio))
> +		return ERR_CAST(bio);

The cast is not strictly needed here as the pointer matches the return
type.

> +
>  	bbio = btrfs_bio(bio);
>  	btrfs_bio_init(bbio, fs_info, NULL, orig_bbio);
>  	bbio->inode = orig_bbio->inode;
> @@ -678,7 +681,8 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
>  				&bioc, &smap, &mirror_num);
>  	if (error) {
>  		ret = errno_to_blk_status(error);
> -		goto fail;
> +		btrfs_bio_counter_dec(fs_info);
> +		goto end_bbio;
>  	}
>  
>  	map_length = min(map_length, length);

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-11-29 16:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-28  9:42 [PATCH v4] btrfs: handle bio_split() error Johannes Thumshirn
2024-11-28 14:50 ` David Sterba
2024-11-28 15:40   ` Johannes Thumshirn
2024-11-28 16:06     ` David Sterba
2024-11-29 16:34 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox