Mention branches and keyring.
[releases.git] / btrfs / tree-log.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2008 Oracle.  All rights reserved.
4  */
5
6 #ifndef BTRFS_TREE_LOG_H
7 #define BTRFS_TREE_LOG_H
8
9 #include "ctree.h"
10 #include "transaction.h"
11
12 /* return value for btrfs_log_dentry_safe that means we don't need to log it at all */
13 #define BTRFS_NO_LOG_SYNC 256
14
15 /* We can't use the tree log for whatever reason, force a transaction commit */
16 #define BTRFS_LOG_FORCE_COMMIT                          (1)
17
18 struct btrfs_log_ctx {
19         int log_ret;
20         int log_transid;
21         bool log_new_dentries;
22         bool logging_new_name;
23         bool logging_new_delayed_dentries;
24         /* Indicate if the inode being logged was logged before. */
25         bool logged_before;
26         struct inode *inode;
27         struct list_head list;
28         /* Only used for fast fsyncs. */
29         struct list_head ordered_extents;
30         struct list_head conflict_inodes;
31         int num_conflict_inodes;
32         bool logging_conflict_inodes;
33 };
34
35 static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx,
36                                       struct inode *inode)
37 {
38         ctx->log_ret = 0;
39         ctx->log_transid = 0;
40         ctx->log_new_dentries = false;
41         ctx->logging_new_name = false;
42         ctx->logging_new_delayed_dentries = false;
43         ctx->logged_before = false;
44         ctx->inode = inode;
45         INIT_LIST_HEAD(&ctx->list);
46         INIT_LIST_HEAD(&ctx->ordered_extents);
47         INIT_LIST_HEAD(&ctx->conflict_inodes);
48         ctx->num_conflict_inodes = 0;
49         ctx->logging_conflict_inodes = false;
50 }
51
52 static inline void btrfs_release_log_ctx_extents(struct btrfs_log_ctx *ctx)
53 {
54         struct btrfs_ordered_extent *ordered;
55         struct btrfs_ordered_extent *tmp;
56
57         ASSERT(inode_is_locked(ctx->inode));
58
59         list_for_each_entry_safe(ordered, tmp, &ctx->ordered_extents, log_list) {
60                 list_del_init(&ordered->log_list);
61                 btrfs_put_ordered_extent(ordered);
62         }
63 }
64
65 static inline void btrfs_set_log_full_commit(struct btrfs_trans_handle *trans)
66 {
67         WRITE_ONCE(trans->fs_info->last_trans_log_full_commit, trans->transid);
68 }
69
70 static inline int btrfs_need_log_full_commit(struct btrfs_trans_handle *trans)
71 {
72         return READ_ONCE(trans->fs_info->last_trans_log_full_commit) ==
73                 trans->transid;
74 }
75
76 int btrfs_sync_log(struct btrfs_trans_handle *trans,
77                    struct btrfs_root *root, struct btrfs_log_ctx *ctx);
78 int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root);
79 int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans,
80                              struct btrfs_fs_info *fs_info);
81 int btrfs_recover_log_trees(struct btrfs_root *tree_root);
82 int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans,
83                           struct dentry *dentry,
84                           struct btrfs_log_ctx *ctx);
85 void btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans,
86                                   struct btrfs_root *root,
87                                   const struct fscrypt_str *name,
88                                   struct btrfs_inode *dir, u64 index);
89 void btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans,
90                                 struct btrfs_root *root,
91                                 const struct fscrypt_str *name,
92                                 struct btrfs_inode *inode, u64 dirid);
93 void btrfs_end_log_trans(struct btrfs_root *root);
94 void btrfs_pin_log_trans(struct btrfs_root *root);
95 void btrfs_record_unlink_dir(struct btrfs_trans_handle *trans,
96                              struct btrfs_inode *dir, struct btrfs_inode *inode,
97                              int for_rename);
98 void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans,
99                                    struct btrfs_inode *dir);
100 void btrfs_log_new_name(struct btrfs_trans_handle *trans,
101                         struct dentry *old_dentry, struct btrfs_inode *old_dir,
102                         u64 old_dir_index, struct dentry *parent);
103
104 #endif