[4/8] btrfs: cleanup the target logic in __btrfs_block_rsv_release
diff mbox series

Message ID 20190619174724.1675-5-josef@toxicpanda.com
State New
Headers show
Series
  • btrfs: move the block_rsv code out of extent-tree.c
Related show

Commit Message

Josef Bacik June 19, 2019, 5:47 p.m. UTC
This works for all callers already, but if we wanted to use the helper
for the global_block_rsv it would end up trying to refill itself.  Fix
the logic to be able to be used no matter which block rsv is passed in
to this helper.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/extent-tree.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

Nikolay Borisov June 20, 2019, 8:23 a.m. UTC | #1
On 19.06.19 г. 20:47 ч., Josef Bacik wrote:
> This works for all callers already, but if we wanted to use the helper
> for the global_block_rsv it would end up trying to refill itself.  Fix
> the logic to be able to be used no matter which block rsv is passed in
> to this helper.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/btrfs/extent-tree.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index d6aff56337aa..6995edf887e1 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -4684,12 +4684,20 @@ u64 __btrfs_block_rsv_release(struct btrfs_fs_info *fs_info,
>  {
>  	struct btrfs_block_rsv *global_rsv = &fs_info->global_block_rsv;
>  	struct btrfs_block_rsv *delayed_rsv = &fs_info->delayed_refs_rsv;
> -	struct btrfs_block_rsv *target = delayed_rsv;
> +	struct btrfs_block_rsv *target = NULL;
>  
> -	if (target->full || target == block_rsv)
> +	/*
> +	 * If we are the delayed_rsv then push to the global rsv, otherwise dump
> +	 * into the delayed rsv if it is not full.
> +	 */
> +	if (block_rsv == delayed_rsv) {
>  		target = global_rsv;
> +	} else if (block_rsv != global_rsv) {
> +		if (!delayed_rsv->full)
> +			target = delayed_rsv;
> +	}

nit:

} else if (block_rsv != global_rsv && !delayed_rs->full) {

doesn't surpass the 80 character limit and IMO makes it a bit more
readable but it's minor.

Otherwise looks good.


>  
> -	if (block_rsv->space_info != target->space_info)
> +	if (target && block_rsv->space_info != target->space_info)
>  		target = NULL;
>  
>  	return block_rsv_release_bytes(fs_info, block_rsv, target, num_bytes,
>
David Sterba June 25, 2019, 6:25 p.m. UTC | #2
On Thu, Jun 20, 2019 at 11:23:36AM +0300, Nikolay Borisov wrote:
> 
> 
> On 19.06.19 г. 20:47 ч., Josef Bacik wrote:
> > This works for all callers already, but if we wanted to use the helper
> > for the global_block_rsv it would end up trying to refill itself.  Fix
> > the logic to be able to be used no matter which block rsv is passed in
> > to this helper.
> > 
> > Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> > ---
> >  fs/btrfs/extent-tree.c | 14 +++++++++++---
> >  1 file changed, 11 insertions(+), 3 deletions(-)
> > 
> > diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> > index d6aff56337aa..6995edf887e1 100644
> > --- a/fs/btrfs/extent-tree.c
> > +++ b/fs/btrfs/extent-tree.c
> > @@ -4684,12 +4684,20 @@ u64 __btrfs_block_rsv_release(struct btrfs_fs_info *fs_info,
> >  {
> >  	struct btrfs_block_rsv *global_rsv = &fs_info->global_block_rsv;
> >  	struct btrfs_block_rsv *delayed_rsv = &fs_info->delayed_refs_rsv;
> > -	struct btrfs_block_rsv *target = delayed_rsv;
> > +	struct btrfs_block_rsv *target = NULL;
> >  
> > -	if (target->full || target == block_rsv)
> > +	/*
> > +	 * If we are the delayed_rsv then push to the global rsv, otherwise dump
> > +	 * into the delayed rsv if it is not full.
> > +	 */
> > +	if (block_rsv == delayed_rsv) {
> >  		target = global_rsv;
> > +	} else if (block_rsv != global_rsv) {
> > +		if (!delayed_rsv->full)
> > +			target = delayed_rsv;
> > +	}
> 
> nit:
> 
> } else if (block_rsv != global_rsv && !delayed_rs->full) {
> 
> doesn't surpass the 80 character limit and IMO makes it a bit more
> readable but it's minor.

Agreed, updated.

Patch
diff mbox series

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index d6aff56337aa..6995edf887e1 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4684,12 +4684,20 @@  u64 __btrfs_block_rsv_release(struct btrfs_fs_info *fs_info,
 {
 	struct btrfs_block_rsv *global_rsv = &fs_info->global_block_rsv;
 	struct btrfs_block_rsv *delayed_rsv = &fs_info->delayed_refs_rsv;
-	struct btrfs_block_rsv *target = delayed_rsv;
+	struct btrfs_block_rsv *target = NULL;
 
-	if (target->full || target == block_rsv)
+	/*
+	 * If we are the delayed_rsv then push to the global rsv, otherwise dump
+	 * into the delayed rsv if it is not full.
+	 */
+	if (block_rsv == delayed_rsv) {
 		target = global_rsv;
+	} else if (block_rsv != global_rsv) {
+		if (!delayed_rsv->full)
+			target = delayed_rsv;
+	}
 
-	if (block_rsv->space_info != target->space_info)
+	if (target && block_rsv->space_info != target->space_info)
 		target = NULL;
 
 	return block_rsv_release_bytes(fs_info, block_rsv, target, num_bytes,