Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
delayed-inode.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Fujitsu. All rights reserved.
3  * Written by Miao Xie <[email protected]>
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>
28 #include <linux/atomic.h>
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 
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  */
45  atomic_t items; /* for delayed items */
46  int nodes; /* for delayed nodes */
48 };
49 
53  struct btrfs_root *root;
54  /* Used to add the node into the delayed root's node list. */
55  struct list_head n_list;
56  /*
57  * Used to add the node into the prepare list, the nodes in this list
58  * is waiting to be dealt with by the async worker.
59  */
60  struct list_head p_list;
61  struct rb_root ins_root;
62  struct rb_root del_root;
63  struct mutex mutex;
67  bool in_list;
69  int count;
70 };
71 
73  struct rb_node rb_node;
74  struct btrfs_key key;
75  struct list_head tree_list; /* used for batch insert/delete items */
76  struct list_head readdir_list; /* used for readdir items */
82  char data[0];
83 };
84 
85 static inline void btrfs_init_delayed_root(
86  struct btrfs_delayed_root *delayed_root)
87 {
88  atomic_set(&delayed_root->items, 0);
89  delayed_root->nodes = 0;
90  spin_lock_init(&delayed_root->lock);
91  init_waitqueue_head(&delayed_root->wait);
92  INIT_LIST_HEAD(&delayed_root->node_list);
93  INIT_LIST_HEAD(&delayed_root->prepare_list);
94 }
95 
97  struct btrfs_root *root, const char *name,
98  int name_len, struct inode *dir,
99  struct btrfs_disk_key *disk_key, u8 type,
100  u64 index);
101 
103  struct btrfs_root *root, struct inode *dir,
104  u64 index);
105 
107 
109  struct btrfs_root *root);
111  struct btrfs_root *root, int nr);
112 
114 
116  struct inode *inode);
117 /* Used for evicting the inode. */
120 
121 
123  struct btrfs_root *root, struct inode *inode);
124 int btrfs_fill_inode(struct inode *inode, u32 *rdev);
125 
126 /* Used for drop dead root */
128 
129 /* Used for clean the transaction */
131 
132 /* Used for readdir() */
133 void btrfs_get_delayed_items(struct inode *inode, struct list_head *ins_list,
134  struct list_head *del_list);
135 void btrfs_put_delayed_items(struct list_head *ins_list,
136  struct list_head *del_list);
137 int btrfs_should_delete_dir_index(struct list_head *del_list,
138  u64 index);
139 int btrfs_readdir_delayed_dir_index(struct file *filp, void *dirent,
140  filldir_t filldir,
141  struct list_head *ins_list);
142 
143 /* for init */
145 void btrfs_delayed_inode_exit(void);
146 
147 /* for debugging */
149 
150 #endif