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