Blame view

fs/btrfs/delayed-inode.h 4.8 KB
16cdcec73   Miao Xie   btrfs: implement ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  /*
   * Copyright (C) 2011 Fujitsu.  All rights reserved.
   * Written by Miao Xie <miaox@cn.fujitsu.com>
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public
   * License v2 as published by the Free Software Foundation.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * General Public License for more details.
   *
   * You should have received a copy of the GNU General Public
   * License along with this program; if not, write to the
   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   * Boston, MA 021110-1307, USA.
   */
  
  #ifndef __DELAYED_TREE_OPERATION_H
  #define __DELAYED_TREE_OPERATION_H
  
  #include <linux/rbtree.h>
  #include <linux/spinlock.h>
  #include <linux/mutex.h>
  #include <linux/list.h>
  #include <linux/wait.h>
60063497a   Arun Sharma   atomic: use <linu...
28
  #include <linux/atomic.h>
16cdcec73   Miao Xie   btrfs: implement ...
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  
  #include "ctree.h"
  
  /* types of the delayed item */
  #define BTRFS_DELAYED_INSERTION_ITEM	1
  #define BTRFS_DELAYED_DELETION_ITEM	2
  
  struct btrfs_delayed_root {
  	spinlock_t lock;
  	struct list_head node_list;
  	/*
  	 * Used for delayed nodes which is waiting to be dealt with by the
  	 * worker. If the delayed node is inserted into the work queue, we
  	 * drop it from this list.
  	 */
  	struct list_head prepare_list;
  	atomic_t items;		/* for delayed items */
de3cb945d   Chris Mason   Btrfs: improve th...
46
  	atomic_t items_seq;	/* for delayed items */
16cdcec73   Miao Xie   btrfs: implement ...
47
48
49
  	int nodes;		/* for delayed nodes */
  	wait_queue_head_t wait;
  };
7cf35d91b   Miao Xie   Btrfs: use flags ...
50
51
  #define BTRFS_DELAYED_NODE_IN_LIST	0
  #define BTRFS_DELAYED_NODE_INODE_DIRTY	1
67de11769   Miao Xie   Btrfs: introduce ...
52
  #define BTRFS_DELAYED_NODE_DEL_IREF	2
7cf35d91b   Miao Xie   Btrfs: use flags ...
53

16cdcec73   Miao Xie   btrfs: implement ...
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  struct btrfs_delayed_node {
  	u64 inode_id;
  	u64 bytes_reserved;
  	struct btrfs_root *root;
  	/* Used to add the node into the delayed root's node list. */
  	struct list_head n_list;
  	/*
  	 * Used to add the node into the prepare list, the nodes in this list
  	 * is waiting to be dealt with by the async worker.
  	 */
  	struct list_head p_list;
  	struct rb_root ins_root;
  	struct rb_root del_root;
  	struct mutex mutex;
  	struct btrfs_inode_item inode_item;
  	atomic_t refs;
  	u64 index_cnt;
7cf35d91b   Miao Xie   Btrfs: use flags ...
71
  	unsigned long flags;
16cdcec73   Miao Xie   btrfs: implement ...
72
73
74
75
76
77
78
79
80
  	int count;
  };
  
  struct btrfs_delayed_item {
  	struct rb_node rb_node;
  	struct btrfs_key key;
  	struct list_head tree_list;	/* used for batch insert/delete items */
  	struct list_head readdir_list;	/* used for readdir items */
  	u64 bytes_reserved;
16cdcec73   Miao Xie   btrfs: implement ...
81
82
83
84
85
86
87
88
89
90
91
  	struct btrfs_delayed_node *delayed_node;
  	atomic_t refs;
  	int ins_or_del;
  	u32 data_len;
  	char data[0];
  };
  
  static inline void btrfs_init_delayed_root(
  				struct btrfs_delayed_root *delayed_root)
  {
  	atomic_set(&delayed_root->items, 0);
de3cb945d   Chris Mason   Btrfs: improve th...
92
  	atomic_set(&delayed_root->items_seq, 0);
16cdcec73   Miao Xie   btrfs: implement ...
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  	delayed_root->nodes = 0;
  	spin_lock_init(&delayed_root->lock);
  	init_waitqueue_head(&delayed_root->wait);
  	INIT_LIST_HEAD(&delayed_root->node_list);
  	INIT_LIST_HEAD(&delayed_root->prepare_list);
  }
  
  int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans,
  				   struct btrfs_root *root, const char *name,
  				   int name_len, struct inode *dir,
  				   struct btrfs_disk_key *disk_key, u8 type,
  				   u64 index);
  
  int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans,
  				   struct btrfs_root *root, struct inode *dir,
  				   u64 index);
  
  int btrfs_inode_delayed_dir_index_count(struct inode *inode);
  
  int btrfs_run_delayed_items(struct btrfs_trans_handle *trans,
  			    struct btrfs_root *root);
96c3f4331   Josef Bacik   Btrfs: flush dela...
114
115
  int btrfs_run_delayed_items_nr(struct btrfs_trans_handle *trans,
  			       struct btrfs_root *root, int nr);
16cdcec73   Miao Xie   btrfs: implement ...
116
117
118
119
120
121
122
123
  
  void btrfs_balance_delayed_items(struct btrfs_root *root);
  
  int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans,
  				     struct inode *inode);
  /* Used for evicting the inode. */
  void btrfs_remove_delayed_node(struct inode *inode);
  void btrfs_kill_delayed_inode_items(struct inode *inode);
0e8c36a9f   Miao Xie   Btrfs: fix lots o...
124
  int btrfs_commit_inode_delayed_inode(struct inode *inode);
16cdcec73   Miao Xie   btrfs: implement ...
125
126
127
128
  
  
  int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans,
  			       struct btrfs_root *root, struct inode *inode);
2f7e33d43   Miao Xie   btrfs: fix incons...
129
  int btrfs_fill_inode(struct inode *inode, u32 *rdev);
67de11769   Miao Xie   Btrfs: introduce ...
130
  int btrfs_delayed_delete_inode_ref(struct inode *inode);
16cdcec73   Miao Xie   btrfs: implement ...
131
132
133
  
  /* Used for drop dead root */
  void btrfs_kill_all_delayed_nodes(struct btrfs_root *root);
67cde3448   Miao Xie   Btrfs: destroy th...
134
135
  /* Used for clean the transaction */
  void btrfs_destroy_delayed_inodes(struct btrfs_root *root);
16cdcec73   Miao Xie   btrfs: implement ...
136
137
138
139
140
141
142
  /* Used for readdir() */
  void btrfs_get_delayed_items(struct inode *inode, struct list_head *ins_list,
  			     struct list_head *del_list);
  void btrfs_put_delayed_items(struct list_head *ins_list,
  			     struct list_head *del_list);
  int btrfs_should_delete_dir_index(struct list_head *del_list,
  				  u64 index);
9cdda8d31   Al Viro   [readdir] convert...
143
  int btrfs_readdir_delayed_dir_index(struct dir_context *ctx,
16cdcec73   Miao Xie   btrfs: implement ...
144
145
146
147
148
  				    struct list_head *ins_list);
  
  /* for init */
  int __init btrfs_delayed_inode_init(void);
  void btrfs_delayed_inode_exit(void);
e999376f0   Chris Mason   Btrfs: avoid dela...
149
150
151
  
  /* for debugging */
  void btrfs_assert_delayed_root_empty(struct btrfs_root *root);
16cdcec73   Miao Xie   btrfs: implement ...
152
  #endif