1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#ifndef __DELAYED_TREE_OPERATION_H
21#define __DELAYED_TREE_OPERATION_H
22
23#include <linux/rbtree.h>
24#include <linux/spinlock.h>
25#include <linux/mutex.h>
26#include <linux/list.h>
27#include <linux/wait.h>
28#include <linux/atomic.h>
29#include <linux/refcount.h>
30#include "ctree.h"
31
32
33#define BTRFS_DELAYED_INSERTION_ITEM 1
34#define BTRFS_DELAYED_DELETION_ITEM 2
35
36struct btrfs_delayed_root {
37 spinlock_t lock;
38 struct list_head node_list;
39
40
41
42
43
44 struct list_head prepare_list;
45 atomic_t items;
46 atomic_t items_seq;
47 int nodes;
48 wait_queue_head_t wait;
49};
50
51#define BTRFS_DELAYED_NODE_IN_LIST 0
52#define BTRFS_DELAYED_NODE_INODE_DIRTY 1
53#define BTRFS_DELAYED_NODE_DEL_IREF 2
54
55struct btrfs_delayed_node {
56 u64 inode_id;
57 u64 bytes_reserved;
58 struct btrfs_root *root;
59
60 struct list_head n_list;
61
62
63
64
65 struct list_head p_list;
66 struct rb_root ins_root;
67 struct rb_root del_root;
68 struct mutex mutex;
69 struct btrfs_inode_item inode_item;
70 refcount_t refs;
71 u64 index_cnt;
72 unsigned long flags;
73 int count;
74};
75
76struct btrfs_delayed_item {
77 struct rb_node rb_node;
78 struct btrfs_key key;
79 struct list_head tree_list;
80 struct list_head readdir_list;
81 u64 bytes_reserved;
82 struct btrfs_delayed_node *delayed_node;
83 refcount_t refs;
84 int ins_or_del;
85 u32 data_len;
86 char data[0];
87};
88
89static inline void btrfs_init_delayed_root(
90 struct btrfs_delayed_root *delayed_root)
91{
92 atomic_set(&delayed_root->items, 0);
93 atomic_set(&delayed_root->items_seq, 0);
94 delayed_root->nodes = 0;
95 spin_lock_init(&delayed_root->lock);
96 init_waitqueue_head(&delayed_root->wait);
97 INIT_LIST_HEAD(&delayed_root->node_list);
98 INIT_LIST_HEAD(&delayed_root->prepare_list);
99}
100
101int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans,
102 struct btrfs_fs_info *fs_info,
103 const char *name, int name_len,
104 struct btrfs_inode *dir,
105 struct btrfs_disk_key *disk_key, u8 type,
106 u64 index);
107
108int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans,
109 struct btrfs_fs_info *fs_info,
110 struct btrfs_inode *dir, u64 index);
111
112int btrfs_inode_delayed_dir_index_count(struct btrfs_inode *inode);
113
114int btrfs_run_delayed_items(struct btrfs_trans_handle *trans,
115 struct btrfs_fs_info *fs_info);
116int btrfs_run_delayed_items_nr(struct btrfs_trans_handle *trans,
117 struct btrfs_fs_info *fs_info, int nr);
118
119void btrfs_balance_delayed_items(struct btrfs_fs_info *fs_info);
120
121int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans,
122 struct btrfs_inode *inode);
123
124void btrfs_remove_delayed_node(struct btrfs_inode *inode);
125void btrfs_kill_delayed_inode_items(struct btrfs_inode *inode);
126int btrfs_commit_inode_delayed_inode(struct btrfs_inode *inode);
127
128
129int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans,
130 struct btrfs_root *root, struct inode *inode);
131int btrfs_fill_inode(struct inode *inode, u32 *rdev);
132int btrfs_delayed_delete_inode_ref(struct btrfs_inode *inode);
133
134
135void btrfs_kill_all_delayed_nodes(struct btrfs_root *root);
136
137
138void btrfs_destroy_delayed_inodes(struct btrfs_fs_info *fs_info);
139
140
141bool btrfs_readdir_get_delayed_items(struct inode *inode,
142 struct list_head *ins_list,
143 struct list_head *del_list);
144void btrfs_readdir_put_delayed_items(struct inode *inode,
145 struct list_head *ins_list,
146 struct list_head *del_list);
147int btrfs_should_delete_dir_index(struct list_head *del_list,
148 u64 index);
149int btrfs_readdir_delayed_dir_index(struct dir_context *ctx,
150 struct list_head *ins_list);
151
152
153int __init btrfs_delayed_inode_init(void);
154void btrfs_delayed_inode_exit(void);
155
156
157void btrfs_assert_delayed_root_empty(struct btrfs_fs_info *fs_info);
158
159#endif
160