xref: /openbmc/linux/fs/btrfs/tree-log.h (revision 53f9cd5c)
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 	/* Indicate if the inode being logged was logged before. */
24 	bool logged_before;
25 	/* Tracks the last logged dir item/index key offset. */
26 	u64 last_dir_item_offset;
27 	struct inode *inode;
28 	struct list_head list;
29 	/* Only used for fast fsyncs. */
30 	struct list_head ordered_extents;
31 };
32 
33 static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx,
34 				      struct inode *inode)
35 {
36 	ctx->log_ret = 0;
37 	ctx->log_transid = 0;
38 	ctx->log_new_dentries = false;
39 	ctx->logging_new_name = false;
40 	ctx->logged_before = false;
41 	ctx->inode = inode;
42 	INIT_LIST_HEAD(&ctx->list);
43 	INIT_LIST_HEAD(&ctx->ordered_extents);
44 }
45 
46 static inline void btrfs_release_log_ctx_extents(struct btrfs_log_ctx *ctx)
47 {
48 	struct btrfs_ordered_extent *ordered;
49 	struct btrfs_ordered_extent *tmp;
50 
51 	ASSERT(inode_is_locked(ctx->inode));
52 
53 	list_for_each_entry_safe(ordered, tmp, &ctx->ordered_extents, log_list) {
54 		list_del_init(&ordered->log_list);
55 		btrfs_put_ordered_extent(ordered);
56 	}
57 }
58 
59 static inline void btrfs_set_log_full_commit(struct btrfs_trans_handle *trans)
60 {
61 	WRITE_ONCE(trans->fs_info->last_trans_log_full_commit, trans->transid);
62 }
63 
64 static inline int btrfs_need_log_full_commit(struct btrfs_trans_handle *trans)
65 {
66 	return READ_ONCE(trans->fs_info->last_trans_log_full_commit) ==
67 		trans->transid;
68 }
69 
70 int btrfs_sync_log(struct btrfs_trans_handle *trans,
71 		   struct btrfs_root *root, struct btrfs_log_ctx *ctx);
72 int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root);
73 int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans,
74 			     struct btrfs_fs_info *fs_info);
75 int btrfs_recover_log_trees(struct btrfs_root *tree_root);
76 int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans,
77 			  struct dentry *dentry,
78 			  struct btrfs_log_ctx *ctx);
79 void btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans,
80 				  struct btrfs_root *root,
81 				  const char *name, int name_len,
82 				  struct btrfs_inode *dir, u64 index);
83 void btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans,
84 				struct btrfs_root *root,
85 				const char *name, int name_len,
86 				struct btrfs_inode *inode, u64 dirid);
87 void btrfs_end_log_trans(struct btrfs_root *root);
88 void btrfs_pin_log_trans(struct btrfs_root *root);
89 void btrfs_record_unlink_dir(struct btrfs_trans_handle *trans,
90 			     struct btrfs_inode *dir, struct btrfs_inode *inode,
91 			     int for_rename);
92 void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans,
93 				   struct btrfs_inode *dir);
94 void btrfs_log_new_name(struct btrfs_trans_handle *trans,
95 			struct dentry *old_dentry, struct btrfs_inode *old_dir,
96 			u64 old_dir_index, struct dentry *parent);
97 
98 #endif
99