diff mbox series

[v3,04/12] btrfs: introduce a FORCE_COMMIT_TRANS flush operation

Message ID 58ae7655908a28c446139452ea8f5210d590acb4.1602249928.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series Improve preemptive ENOSPC flushing | expand

Commit Message

Josef Bacik Oct. 9, 2020, 1:28 p.m. UTC
Sole-y for preemptive flushing, we want to be able to force the
transaction commit without any of the ambiguity of
may_commit_transaction().  This is because may_commit_transaction()
checks tickets and such, and in preemptive flushing we already know
it'll be helpful, so use this to keep the code nice and clean and
straightforward.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.h             | 1 +
 fs/btrfs/space-info.c        | 8 ++++++++
 include/trace/events/btrfs.h | 3 ++-
 3 files changed, 11 insertions(+), 1 deletion(-)

Comments

Nikolay Borisov Oct. 12, 2020, 1:50 p.m. UTC | #1
On 9.10.20 г. 16:28 ч., Josef Bacik wrote:
> Sole-y for preemptive flushing, we want to be able to force the
> transaction commit without any of the ambiguity of
> may_commit_transaction().  This is because may_commit_transaction()
> checks tickets and such, and in preemptive flushing we already know
> it'll be helpful, so use this to keep the code nice and clean and
> straightforward.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
David Sterba Oct. 29, 2020, 5:03 p.m. UTC | #2
On Fri, Oct 09, 2020 at 09:28:21AM -0400, Josef Bacik wrote:
> Sole-y for preemptive flushing, we want to be able to force the
> transaction commit without any of the ambiguity of
> may_commit_transaction().  This is because may_commit_transaction()
> checks tickets and such, and in preemptive flushing we already know
> it'll be helpful, so use this to keep the code nice and clean and
> straightforward.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/btrfs/ctree.h             | 1 +
>  fs/btrfs/space-info.c        | 8 ++++++++
>  include/trace/events/btrfs.h | 3 ++-
>  3 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index e817b3b3483d..84c5db91dc44 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -2654,6 +2654,7 @@ enum btrfs_flush_state {
>  	ALLOC_CHUNK_FORCE	=	8,
>  	RUN_DELAYED_IPUTS	=	9,
>  	COMMIT_TRANS		=	10,
> +	FORCE_COMMIT_TRANS	=	11,

This new state is not documented in space-info.c (before
btrfs_space_info_used).
David Sterba Jan. 26, 2021, 6:41 p.m. UTC | #3
On Thu, Oct 29, 2020 at 06:03:30PM +0100, David Sterba wrote:
> On Fri, Oct 09, 2020 at 09:28:21AM -0400, Josef Bacik wrote:
> > Sole-y for preemptive flushing, we want to be able to force the
> > transaction commit without any of the ambiguity of
> > may_commit_transaction().  This is because may_commit_transaction()
> > checks tickets and such, and in preemptive flushing we already know
> > it'll be helpful, so use this to keep the code nice and clean and
> > straightforward.
> > 
> > Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> > ---
> >  fs/btrfs/ctree.h             | 1 +
> >  fs/btrfs/space-info.c        | 8 ++++++++
> >  include/trace/events/btrfs.h | 3 ++-
> >  3 files changed, 11 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> > index e817b3b3483d..84c5db91dc44 100644
> > --- a/fs/btrfs/ctree.h
> > +++ b/fs/btrfs/ctree.h
> > @@ -2654,6 +2654,7 @@ enum btrfs_flush_state {
> >  	ALLOC_CHUNK_FORCE	=	8,
> >  	RUN_DELAYED_IPUTS	=	9,
> >  	COMMIT_TRANS		=	10,
> > +	FORCE_COMMIT_TRANS	=	11,
> 
> This new state is not documented in space-info.c (before
> btrfs_space_info_used).

I've used to changelog and turned it to the comment.
diff mbox series

Patch

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index e817b3b3483d..84c5db91dc44 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2654,6 +2654,7 @@  enum btrfs_flush_state {
 	ALLOC_CHUNK_FORCE	=	8,
 	RUN_DELAYED_IPUTS	=	9,
 	COMMIT_TRANS		=	10,
+	FORCE_COMMIT_TRANS	=	11,
 };
 
 int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
index 540960365787..cfcc3a5247f6 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -732,6 +732,14 @@  static void flush_space(struct btrfs_fs_info *fs_info,
 	case COMMIT_TRANS:
 		ret = may_commit_transaction(fs_info, space_info);
 		break;
+	case FORCE_COMMIT_TRANS:
+		trans = btrfs_join_transaction(root);
+		if (IS_ERR(trans)) {
+			ret = PTR_ERR(trans);
+			break;
+		}
+		ret = btrfs_commit_transaction(trans);
+		break;
 	default:
 		ret = -ENOSPC;
 		break;
diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
index eb348656839f..0a3d35d952c4 100644
--- a/include/trace/events/btrfs.h
+++ b/include/trace/events/btrfs.h
@@ -99,7 +99,8 @@  struct btrfs_space_info;
 	EM( ALLOC_CHUNK,		"ALLOC_CHUNK")			\
 	EM( ALLOC_CHUNK_FORCE,		"ALLOC_CHUNK_FORCE")		\
 	EM( RUN_DELAYED_IPUTS,		"RUN_DELAYED_IPUTS")		\
-	EMe(COMMIT_TRANS,		"COMMIT_TRANS")
+	EM(COMMIT_TRANS,		"COMMIT_TRANS")			\
+	EMe(FORCE_COMMIT_TRANS,		"FORCE_COMMIT_TRANS")
 
 /*
  * First define the enums in the above macros to be exported to userspace via