From: Josef Bacik <josef@toxicpanda.com>
Date: Fri, 9 Oct 2020 09:28:21 -0400
Subject: btrfs: introduce a FORCE_COMMIT_TRANS flush operation
Git-commit: f00c42dd4cc8b856e68638e6a88b51f88b8e849e
Patch-mainline: v5.12-rc1
References: bsc#1202528
Solely 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.
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
[ add comment ]
Signed-off-by: David Sterba <dsterba@suse.com>
Acked-by: Nikolay Borisov <nborisov@suse.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(-)
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2593,6 +2593,7 @@ enum btrfs_flush_state {
ALLOC_CHUNK_FORCE = 8,
RUN_DELAYED_IPUTS = 9,
COMMIT_TRANS = 10,
+ FORCE_COMMIT_TRANS = 11,
};
void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans,
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -619,6 +619,14 @@ static int flush_space(struct btrfs_fs_i
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;
--- a/include/trace/events/btrfs.h
+++ b/include/trace/events/btrfs.h
@@ -1042,7 +1042,8 @@ TRACE_EVENT(btrfs_trigger_flush,
{ ALLOC_CHUNK, "ALLOC_CHUNK"}, \
{ ALLOC_CHUNK_FORCE, "ALLOC_CHUNK_FORCE"}, \
{ RUN_DELAYED_IPUTS, "RUN_DELAYED_IPUTS"}, \
- { COMMIT_TRANS, "COMMIT_TRANS"})
+ { COMMIT_TRANS, "COMMIT_TRANS"}, \
+ { FORCE_COMMIT_TRANS, "FORCE_COMMIT_TRANS"})
TRACE_EVENT(btrfs_flush_space,