Skip to content

Commit

Permalink
btrfs: introduce a FORCE_COMMIT_TRANS flush operation
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Josef Bacik authored and David Sterba committed Feb 8, 2021
1 parent 5deb17e commit f00c42d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -2740,6 +2740,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,
Expand Down
14 changes: 14 additions & 0 deletions fs/btrfs/space-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@
* be freed, plus any delayed work we may not have gotten rid of in the case
* of metadata.
*
* FORCE_COMMIT_TRANS
* For use by the preemptive flusher. We use this to bypass the ticketing
* checks in may_commit_transaction, as we have more information about the
* overall state of the system and may want to commit the transaction ahead
* of actual ENOSPC conditions.
*
* OVERCOMMIT
*
* Because we hold so many reservations for metadata we will allow you to
Expand Down Expand Up @@ -735,6 +741,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;
Expand Down
3 changes: 2 additions & 1 deletion include/trace/events/btrfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f00c42d

Please sign in to comment.