Merge branches 'acpi-ec', 'acpi-video', 'acpi-button' and 'acpi-thermal'
[linux-2.6-block.git] / fs / btrfs / delayed-inode.h
CommitLineData
16cdcec7
MX
1/*
2 * Copyright (C) 2011 Fujitsu. All rights reserved.
3 * Written by Miao Xie <miaox@cn.fujitsu.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License v2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 021110-1307, USA.
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>
60063497 28#include <linux/atomic.h>
16cdcec7
MX
29
30#include "ctree.h"
31
32/* types of the delayed item */
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 * Used for delayed nodes which is waiting to be dealt with by the
41 * worker. If the delayed node is inserted into the work queue, we
42 * drop it from this list.
43 */
44 struct list_head prepare_list;
45 atomic_t items; /* for delayed items */
de3cb945 46 atomic_t items_seq; /* for delayed items */
16cdcec7
MX
47 int nodes; /* for delayed nodes */
48 wait_queue_head_t wait;
49};
50
7cf35d91
MX
51#define BTRFS_DELAYED_NODE_IN_LIST 0
52#define BTRFS_DELAYED_NODE_INODE_DIRTY 1
67de1176 53#define BTRFS_DELAYED_NODE_DEL_IREF 2
7cf35d91 54
16cdcec7
MX
55struct btrfs_delayed_node {
56 u64 inode_id;
57 u64 bytes_reserved;
58 struct btrfs_root *root;
59 /* Used to add the node into the delayed root's node list. */
60 struct list_head n_list;
61 /*
62 * Used to add the node into the prepare list, the nodes in this list
63 * is waiting to be dealt with by the async worker.
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 atomic_t refs;
71 u64 index_cnt;
7cf35d91 72 unsigned long flags;
16cdcec7
MX
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; /* used for batch insert/delete items */
80 struct list_head readdir_list; /* used for readdir items */
81 u64 bytes_reserved;
16cdcec7
MX
82 struct btrfs_delayed_node *delayed_node;
83 atomic_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);
de3cb945 93 atomic_set(&delayed_root->items_seq, 0);
16cdcec7
MX
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_root *root, const char *name,
103 int name_len, struct inode *dir,
104 struct btrfs_disk_key *disk_key, u8 type,
105 u64 index);
106
107int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans,
108 struct btrfs_root *root, struct inode *dir,
109 u64 index);
110
111int btrfs_inode_delayed_dir_index_count(struct inode *inode);
112
113int btrfs_run_delayed_items(struct btrfs_trans_handle *trans,
114 struct btrfs_root *root);
96c3f433
JB
115int btrfs_run_delayed_items_nr(struct btrfs_trans_handle *trans,
116 struct btrfs_root *root, int nr);
16cdcec7
MX
117
118void btrfs_balance_delayed_items(struct btrfs_root *root);
119
120int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans,
121 struct inode *inode);
122/* Used for evicting the inode. */
123void btrfs_remove_delayed_node(struct inode *inode);
124void btrfs_kill_delayed_inode_items(struct inode *inode);
0e8c36a9 125int btrfs_commit_inode_delayed_inode(struct inode *inode);
16cdcec7
MX
126
127
128int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans,
129 struct btrfs_root *root, struct inode *inode);
2f7e33d4 130int btrfs_fill_inode(struct inode *inode, u32 *rdev);
67de1176 131int btrfs_delayed_delete_inode_ref(struct inode *inode);
16cdcec7
MX
132
133/* Used for drop dead root */
134void btrfs_kill_all_delayed_nodes(struct btrfs_root *root);
135
67cde344
MX
136/* Used for clean the transaction */
137void btrfs_destroy_delayed_inodes(struct btrfs_root *root);
138
16cdcec7 139/* Used for readdir() */
02dbfc99
OS
140bool btrfs_readdir_get_delayed_items(struct inode *inode,
141 struct list_head *ins_list,
142 struct list_head *del_list);
143void btrfs_readdir_put_delayed_items(struct inode *inode,
144 struct list_head *ins_list,
145 struct list_head *del_list);
16cdcec7
MX
146int btrfs_should_delete_dir_index(struct list_head *del_list,
147 u64 index);
9cdda8d3 148int btrfs_readdir_delayed_dir_index(struct dir_context *ctx,
bc4ef759 149 struct list_head *ins_list, bool *emitted);
16cdcec7
MX
150
151/* for init */
152int __init btrfs_delayed_inode_init(void);
153void btrfs_delayed_inode_exit(void);
e999376f
CM
154
155/* for debugging */
156void btrfs_assert_delayed_root_empty(struct btrfs_root *root);
157
16cdcec7 158#endif