* [RFC PATCH] btrfs: flush_space: treat return value of do_chunk_alloc properly
@ 2015-12-03 16:51 Alex Lyakas
2015-12-03 18:14 ` Liu Bo
2015-12-03 18:18 ` Josef Bacik
0 siblings, 2 replies; 6+ messages in thread
From: Alex Lyakas @ 2015-12-03 16:51 UTC (permalink / raw)
To: linux-btrfs
do_chunk_alloc returns 1 when it succeeds to allocate a new chunk.
But flush_space will not convert this to 0, and will also return 1.
As a result, reserve_metadata_bytes will think that flush_space failed,
and may potentially return this value "1" to the caller (depends how
reserve_metadata_bytes was called). The caller will also treat this as an error.
For example, btrfs_block_rsv_refill does:
int ret = -ENOSPC;
...
ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush);
if (!ret) {
block_rsv_add_bytes(block_rsv, num_bytes, 0);
return 0;
}
return ret;
So it will return -ENOSPC.
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 4b89680..1ba3f0d 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4727,7 +4727,7 @@ static int flush_space(struct btrfs_root *root,
btrfs_get_alloc_profile(root, 0),
CHUNK_ALLOC_NO_FORCE);
btrfs_end_transaction(trans, root);
- if (ret == -ENOSPC)
+ if (ret > 0 || ret == -ENOSPC)
ret = 0;
break;
case COMMIT_TRANS:
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [RFC PATCH] btrfs: flush_space: treat return value of do_chunk_alloc properly 2015-12-03 16:51 [RFC PATCH] btrfs: flush_space: treat return value of do_chunk_alloc properly Alex Lyakas @ 2015-12-03 18:14 ` Liu Bo 2015-12-06 10:19 ` Alex Lyakas 2015-12-03 18:18 ` Josef Bacik 1 sibling, 1 reply; 6+ messages in thread From: Liu Bo @ 2015-12-03 18:14 UTC (permalink / raw) To: Alex Lyakas; +Cc: linux-btrfs On Thu, Dec 03, 2015 at 06:51:03PM +0200, Alex Lyakas wrote: > do_chunk_alloc returns 1 when it succeeds to allocate a new chunk. > But flush_space will not convert this to 0, and will also return 1. > As a result, reserve_metadata_bytes will think that flush_space failed, > and may potentially return this value "1" to the caller (depends how > reserve_metadata_bytes was called). The caller will also treat this as an error. > For example, btrfs_block_rsv_refill does: > > int ret = -ENOSPC; > ... > ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush); > if (!ret) { > block_rsv_add_bytes(block_rsv, num_bytes, 0); > return 0; > } > > return ret; > > So it will return -ENOSPC. It will return 1 instead of -ENOSPC. The patch looks good, I noticed this before, but I didn't manage to trigger a error for this, did you catch a error like that? Thanks, -liubo > > diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c > index 4b89680..1ba3f0d 100644 > --- a/fs/btrfs/extent-tree.c > +++ b/fs/btrfs/extent-tree.c > @@ -4727,7 +4727,7 @@ static int flush_space(struct btrfs_root *root, > btrfs_get_alloc_profile(root, 0), > CHUNK_ALLOC_NO_FORCE); > btrfs_end_transaction(trans, root); > - if (ret == -ENOSPC) > + if (ret > 0 || ret == -ENOSPC) > ret = 0; > break; > case COMMIT_TRANS: > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH] btrfs: flush_space: treat return value of do_chunk_alloc properly 2015-12-03 18:14 ` Liu Bo @ 2015-12-06 10:19 ` Alex Lyakas 2015-12-06 10:32 ` Alex Lyakas 0 siblings, 1 reply; 6+ messages in thread From: Alex Lyakas @ 2015-12-06 10:19 UTC (permalink / raw) To: Liu Bo; +Cc: linux-btrfs Hi Liu, I was studying on how block reservation works, and making some modifications in reserve_metadata_bytes to understand better what it does. Then suddenly I saw this problem. I guess it depends on which value of "flush" parameter is passed to reserve_metadata_bytes. Alex. On Thu, Dec 3, 2015 at 8:14 PM, Liu Bo <bo.li.liu@oracle.com> wrote: > On Thu, Dec 03, 2015 at 06:51:03PM +0200, Alex Lyakas wrote: >> do_chunk_alloc returns 1 when it succeeds to allocate a new chunk. >> But flush_space will not convert this to 0, and will also return 1. >> As a result, reserve_metadata_bytes will think that flush_space failed, >> and may potentially return this value "1" to the caller (depends how >> reserve_metadata_bytes was called). The caller will also treat this as an error. >> For example, btrfs_block_rsv_refill does: >> >> int ret = -ENOSPC; >> ... >> ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush); >> if (!ret) { >> block_rsv_add_bytes(block_rsv, num_bytes, 0); >> return 0; >> } >> >> return ret; >> >> So it will return -ENOSPC. > > It will return 1 instead of -ENOSPC. > > The patch looks good, I noticed this before, but I didn't manage to trigger a error for this, did you catch a error like that? > > Thanks, > > -liubo > >> >> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c >> index 4b89680..1ba3f0d 100644 >> --- a/fs/btrfs/extent-tree.c >> +++ b/fs/btrfs/extent-tree.c >> @@ -4727,7 +4727,7 @@ static int flush_space(struct btrfs_root *root, >> btrfs_get_alloc_profile(root, 0), >> CHUNK_ALLOC_NO_FORCE); >> btrfs_end_transaction(trans, root); >> - if (ret == -ENOSPC) >> + if (ret > 0 || ret == -ENOSPC) >> ret = 0; >> break; >> case COMMIT_TRANS: >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH] btrfs: flush_space: treat return value of do_chunk_alloc properly 2015-12-06 10:19 ` Alex Lyakas @ 2015-12-06 10:32 ` Alex Lyakas 2015-12-06 18:59 ` Liu Bo 0 siblings, 1 reply; 6+ messages in thread From: Alex Lyakas @ 2015-12-06 10:32 UTC (permalink / raw) To: Liu Bo; +Cc: linux-btrfs do_chunk_alloc returns 1 when it succeeds to allocate a new chunk. But flush_space will not convert this to 0, and will also return 1. As a result, reserve_metadata_bytes will think that flush_space failed, and may potentially return this value "1" to the caller (depends how reserve_metadata_bytes was called). The caller will also treat this as an error. For example, btrfs_block_rsv_refill does: int ret = -ENOSPC; ... ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush); if (!ret) { block_rsv_add_bytes(block_rsv, num_bytes, 0); return 0; } return ret; So it will return -ENOSPC. Signed-off-by: Alex Lyakas <alex@zadarastorage.com> Reviewed-by: Josef Bacik <jbacik@fb.com> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 4b89680..1ba3f0d 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4727,7 +4727,7 @@ static int flush_space(struct btrfs_root *root, btrfs_get_alloc_profile(root, 0), CHUNK_ALLOC_NO_FORCE); btrfs_end_transaction(trans, root); - if (ret == -ENOSPC) + if (ret > 0 || ret == -ENOSPC) ret = 0; break; case COMMIT_TRANS: On Sun, Dec 6, 2015 at 12:19 PM, Alex Lyakas <alex@zadarastorage.com> wrote: > Hi Liu, > I was studying on how block reservation works, and making some > modifications in reserve_metadata_bytes to understand better what it > does. Then suddenly I saw this problem. I guess it depends on which > value of "flush" parameter is passed to reserve_metadata_bytes. > > Alex. > > > On Thu, Dec 3, 2015 at 8:14 PM, Liu Bo <bo.li.liu@oracle.com> wrote: >> On Thu, Dec 03, 2015 at 06:51:03PM +0200, Alex Lyakas wrote: >>> do_chunk_alloc returns 1 when it succeeds to allocate a new chunk. >>> But flush_space will not convert this to 0, and will also return 1. >>> As a result, reserve_metadata_bytes will think that flush_space failed, >>> and may potentially return this value "1" to the caller (depends how >>> reserve_metadata_bytes was called). The caller will also treat this as an error. >>> For example, btrfs_block_rsv_refill does: >>> >>> int ret = -ENOSPC; >>> ... >>> ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush); >>> if (!ret) { >>> block_rsv_add_bytes(block_rsv, num_bytes, 0); >>> return 0; >>> } >>> >>> return ret; >>> >>> So it will return -ENOSPC. >> >> It will return 1 instead of -ENOSPC. >> >> The patch looks good, I noticed this before, but I didn't manage to trigger a error for this, did you catch a error like that? >> >> Thanks, >> >> -liubo >> >>> >>> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c >>> index 4b89680..1ba3f0d 100644 >>> --- a/fs/btrfs/extent-tree.c >>> +++ b/fs/btrfs/extent-tree.c >>> @@ -4727,7 +4727,7 @@ static int flush_space(struct btrfs_root *root, >>> btrfs_get_alloc_profile(root, 0), >>> CHUNK_ALLOC_NO_FORCE); >>> btrfs_end_transaction(trans, root); >>> - if (ret == -ENOSPC) >>> + if (ret > 0 || ret == -ENOSPC) >>> ret = 0; >>> break; >>> case COMMIT_TRANS: >>> -- >>> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in >>> the body of a message to majordomo@vger.kernel.org >>> More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [RFC PATCH] btrfs: flush_space: treat return value of do_chunk_alloc properly 2015-12-06 10:32 ` Alex Lyakas @ 2015-12-06 18:59 ` Liu Bo 0 siblings, 0 replies; 6+ messages in thread From: Liu Bo @ 2015-12-06 18:59 UTC (permalink / raw) To: Alex Lyakas; +Cc: linux-btrfs On Sun, Dec 06, 2015 at 12:32:31PM +0200, Alex Lyakas wrote: > do_chunk_alloc returns 1 when it succeeds to allocate a new chunk. > But flush_space will not convert this to 0, and will also return 1. > As a result, reserve_metadata_bytes will think that flush_space failed, > and may potentially return this value "1" to the caller (depends how > reserve_metadata_bytes was called). The caller will also treat this as an error. > For example, btrfs_block_rsv_refill does: > > int ret = -ENOSPC; > ... > ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush); > if (!ret) { > block_rsv_add_bytes(block_rsv, num_bytes, 0); > return 0; > } > > return ret; > > So it will return -ENOSPC. Reviewed-by: Liu Bo <bo.li.liu@oracle.com> Thanks, -liubo > > Signed-off-by: Alex Lyakas <alex@zadarastorage.com> > Reviewed-by: Josef Bacik <jbacik@fb.com> > > diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c > index 4b89680..1ba3f0d 100644 > --- a/fs/btrfs/extent-tree.c > +++ b/fs/btrfs/extent-tree.c > @@ -4727,7 +4727,7 @@ static int flush_space(struct btrfs_root *root, > btrfs_get_alloc_profile(root, 0), > CHUNK_ALLOC_NO_FORCE); > btrfs_end_transaction(trans, root); > - if (ret == -ENOSPC) > + if (ret > 0 || ret == -ENOSPC) > ret = 0; > break; > case COMMIT_TRANS: > > On Sun, Dec 6, 2015 at 12:19 PM, Alex Lyakas <alex@zadarastorage.com> wrote: > > Hi Liu, > > I was studying on how block reservation works, and making some > > modifications in reserve_metadata_bytes to understand better what it > > does. Then suddenly I saw this problem. I guess it depends on which > > value of "flush" parameter is passed to reserve_metadata_bytes. > > > > Alex. > > > > > > On Thu, Dec 3, 2015 at 8:14 PM, Liu Bo <bo.li.liu@oracle.com> wrote: > >> On Thu, Dec 03, 2015 at 06:51:03PM +0200, Alex Lyakas wrote: > >>> do_chunk_alloc returns 1 when it succeeds to allocate a new chunk. > >>> But flush_space will not convert this to 0, and will also return 1. > >>> As a result, reserve_metadata_bytes will think that flush_space failed, > >>> and may potentially return this value "1" to the caller (depends how > >>> reserve_metadata_bytes was called). The caller will also treat this as an error. > >>> For example, btrfs_block_rsv_refill does: > >>> > >>> int ret = -ENOSPC; > >>> ... > >>> ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush); > >>> if (!ret) { > >>> block_rsv_add_bytes(block_rsv, num_bytes, 0); > >>> return 0; > >>> } > >>> > >>> return ret; > >>> > >>> So it will return -ENOSPC. > >> > >> It will return 1 instead of -ENOSPC. > >> > >> The patch looks good, I noticed this before, but I didn't manage to trigger a error for this, did you catch a error like that? > >> > >> Thanks, > >> > >> -liubo > >> > >>> > >>> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c > >>> index 4b89680..1ba3f0d 100644 > >>> --- a/fs/btrfs/extent-tree.c > >>> +++ b/fs/btrfs/extent-tree.c > >>> @@ -4727,7 +4727,7 @@ static int flush_space(struct btrfs_root *root, > >>> btrfs_get_alloc_profile(root, 0), > >>> CHUNK_ALLOC_NO_FORCE); > >>> btrfs_end_transaction(trans, root); > >>> - if (ret == -ENOSPC) > >>> + if (ret > 0 || ret == -ENOSPC) > >>> ret = 0; > >>> break; > >>> case COMMIT_TRANS: > >>> -- > >>> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > >>> the body of a message to majordomo@vger.kernel.org > >>> More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH] btrfs: flush_space: treat return value of do_chunk_alloc properly 2015-12-03 16:51 [RFC PATCH] btrfs: flush_space: treat return value of do_chunk_alloc properly Alex Lyakas 2015-12-03 18:14 ` Liu Bo @ 2015-12-03 18:18 ` Josef Bacik 1 sibling, 0 replies; 6+ messages in thread From: Josef Bacik @ 2015-12-03 18:18 UTC (permalink / raw) To: Alex Lyakas, linux-btrfs On 12/03/2015 11:51 AM, Alex Lyakas wrote: > do_chunk_alloc returns 1 when it succeeds to allocate a new chunk. > But flush_space will not convert this to 0, and will also return 1. > As a result, reserve_metadata_bytes will think that flush_space failed, > and may potentially return this value "1" to the caller (depends how > reserve_metadata_bytes was called). The caller will also treat this as an error. > For example, btrfs_block_rsv_refill does: > > int ret = -ENOSPC; > ... > ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush); > if (!ret) { > block_rsv_add_bytes(block_rsv, num_bytes, 0); > return 0; > } > > return ret; > > So it will return -ENOSPC. Huh nice catch. Can you add your signed off by, and you can add my Reviewed-by: Josef Bacik <jbacik@fb.com> Thanks, Josef ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-12-06 18:59 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-12-03 16:51 [RFC PATCH] btrfs: flush_space: treat return value of do_chunk_alloc properly Alex Lyakas 2015-12-03 18:14 ` Liu Bo 2015-12-06 10:19 ` Alex Lyakas 2015-12-06 10:32 ` Alex Lyakas 2015-12-06 18:59 ` Liu Bo 2015-12-03 18:18 ` Josef Bacik
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.