Merge tag 'topic/drm-ci-2023-08-31-1' of git://anongit.freedesktop.org/drm/drm
[linux-block.git] / fs / btrfs / tree-log.h
CommitLineData
9888c340 1/* SPDX-License-Identifier: GPL-2.0 */
e02119d5
CM
2/*
3 * Copyright (C) 2008 Oracle. All rights reserved.
e02119d5
CM
4 */
5
9888c340
DS
6#ifndef BTRFS_TREE_LOG_H
7#define BTRFS_TREE_LOG_H
e02119d5 8
9b569ea0 9#include "messages.h"
995946dd
MX
10#include "ctree.h"
11#include "transaction.h"
12
257c62e1
CM
13/* return value for btrfs_log_dentry_safe that means we don't need to log it at all */
14#define BTRFS_NO_LOG_SYNC 256
15
5cce1780
FM
16/*
17 * We can't use the tree log for whatever reason, force a transaction commit.
18 * We use a negative value because there are functions through the logging code
19 * that need to return an error (< 0 value), false (0) or true (1). Any negative
20 * value will do, as it will cause the log to be marked for a full sync.
21 */
22#define BTRFS_LOG_FORCE_COMMIT (-(MAX_ERRNO + 1))
f31f09f6 23
8b050d35
MX
24struct btrfs_log_ctx {
25 int log_ret;
d1433deb 26 int log_transid;
2f2ff0ee 27 bool log_new_dentries;
75b463d2 28 bool logging_new_name;
30b80f3c 29 bool logging_new_delayed_dentries;
0f8ce498
FM
30 /* Indicate if the inode being logged was logged before. */
31 bool logged_before;
28a23593 32 struct inode *inode;
8b050d35 33 struct list_head list;
48778179
FM
34 /* Only used for fast fsyncs. */
35 struct list_head ordered_extents;
e09d94c9
FM
36 struct list_head conflict_inodes;
37 int num_conflict_inodes;
38 bool logging_conflict_inodes;
8b050d35
MX
39};
40
28a23593
FM
41static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx,
42 struct inode *inode)
8b050d35
MX
43{
44 ctx->log_ret = 0;
d1433deb 45 ctx->log_transid = 0;
2f2ff0ee 46 ctx->log_new_dentries = false;
75b463d2 47 ctx->logging_new_name = false;
30b80f3c 48 ctx->logging_new_delayed_dentries = false;
0f8ce498 49 ctx->logged_before = false;
28a23593 50 ctx->inode = inode;
8b050d35 51 INIT_LIST_HEAD(&ctx->list);
48778179 52 INIT_LIST_HEAD(&ctx->ordered_extents);
e09d94c9
FM
53 INIT_LIST_HEAD(&ctx->conflict_inodes);
54 ctx->num_conflict_inodes = 0;
55 ctx->logging_conflict_inodes = false;
48778179
FM
56}
57
58static inline void btrfs_release_log_ctx_extents(struct btrfs_log_ctx *ctx)
59{
60 struct btrfs_ordered_extent *ordered;
61 struct btrfs_ordered_extent *tmp;
62
63 ASSERT(inode_is_locked(ctx->inode));
64
65 list_for_each_entry_safe(ordered, tmp, &ctx->ordered_extents, log_list) {
66 list_del_init(&ordered->log_list);
67 btrfs_put_ordered_extent(ordered);
68 }
8b050d35
MX
69}
70
90787766 71static inline void btrfs_set_log_full_commit(struct btrfs_trans_handle *trans)
995946dd 72{
90787766 73 WRITE_ONCE(trans->fs_info->last_trans_log_full_commit, trans->transid);
995946dd
MX
74}
75
4884b8e8 76static inline int btrfs_need_log_full_commit(struct btrfs_trans_handle *trans)
995946dd 77{
4884b8e8 78 return READ_ONCE(trans->fs_info->last_trans_log_full_commit) ==
995946dd
MX
79 trans->transid;
80}
81
e02119d5 82int btrfs_sync_log(struct btrfs_trans_handle *trans,
8b050d35 83 struct btrfs_root *root, struct btrfs_log_ctx *ctx);
e02119d5 84int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root);
4a500fd1
YZ
85int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans,
86 struct btrfs_fs_info *fs_info);
e02119d5
CM
87int btrfs_recover_log_trees(struct btrfs_root *tree_root);
88int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans,
e5b84f7a 89 struct dentry *dentry,
8b050d35 90 struct btrfs_log_ctx *ctx);
9a35fc95
JB
91void btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans,
92 struct btrfs_root *root,
6db75318 93 const struct fscrypt_str *name,
9a35fc95
JB
94 struct btrfs_inode *dir, u64 index);
95void btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans,
96 struct btrfs_root *root,
6db75318 97 const struct fscrypt_str *name,
9a35fc95 98 struct btrfs_inode *inode, u64 dirid);
143bede5 99void btrfs_end_log_trans(struct btrfs_root *root);
45128b08 100void btrfs_pin_log_trans(struct btrfs_root *root);
12fcfd22 101void btrfs_record_unlink_dir(struct btrfs_trans_handle *trans,
4176bdbf 102 struct btrfs_inode *dir, struct btrfs_inode *inode,
59fcf388 103 bool for_rename);
1ec9a1ae 104void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans,
43663557 105 struct btrfs_inode *dir);
75b463d2 106void btrfs_log_new_name(struct btrfs_trans_handle *trans,
d5f5bd54 107 struct dentry *old_dentry, struct btrfs_inode *old_dir,
88d2beec 108 u64 old_dir_index, struct dentry *parent);
9888c340 109
e02119d5 110#endif