1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2008 Oracle. All rights reserved.
6 #ifndef BTRFS_TREE_LOG_H
7 #define BTRFS_TREE_LOG_H
10 #include "transaction.h"
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
15 /* We can't use the tree log for whatever reason, force a transaction commit */
16 #define BTRFS_LOG_FORCE_COMMIT (1)
18 struct btrfs_log_ctx {
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. */
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;
35 static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx,
40 ctx->log_new_dentries = false;
41 ctx->logging_new_name = false;
42 ctx->logging_new_delayed_dentries = false;
43 ctx->logged_before = false;
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;
52 static inline void btrfs_release_log_ctx_extents(struct btrfs_log_ctx *ctx)
54 struct btrfs_ordered_extent *ordered;
55 struct btrfs_ordered_extent *tmp;
57 ASSERT(inode_is_locked(ctx->inode));
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);
65 static inline void btrfs_set_log_full_commit(struct btrfs_trans_handle *trans)
67 WRITE_ONCE(trans->fs_info->last_trans_log_full_commit, trans->transid);
70 static inline int btrfs_need_log_full_commit(struct btrfs_trans_handle *trans)
72 return READ_ONCE(trans->fs_info->last_trans_log_full_commit) ==
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 char *name, int name_len,
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 char *name, int name_len,
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,
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);