Blame view

fs/btrfs/ordered-data.h 6.97 KB
dc17ff8f1   Chris Mason   Btrfs: Add data=o...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  /*
   * Copyright (C) 2007 Oracle.  All rights reserved.
   *
   * 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 __BTRFS_ORDERED_DATA__
  #define __BTRFS_ORDERED_DATA__
eb84ae039   Chris Mason   Btrfs: Cleanup an...
21
  /* one of these per inode */
dc17ff8f1   Chris Mason   Btrfs: Add data=o...
22
  struct btrfs_ordered_inode_tree {
49958fd7d   Josef Bacik   Btrfs: change the...
23
  	spinlock_t lock;
dc17ff8f1   Chris Mason   Btrfs: Add data=o...
24
  	struct rb_root tree;
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
25
  	struct rb_node *last;
dc17ff8f1   Chris Mason   Btrfs: Add data=o...
26
  };
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
27
  struct btrfs_ordered_sum {
d20f7043f   Chris Mason   Btrfs: move data ...
28
29
  	/* bytenr is the start of this extent on disk */
  	u64 bytenr;
3edf7d33f   Chris Mason   Btrfs: Handle dat...
30
31
  	/*
  	 * this is the length in bytes covered by the sums array below.
3edf7d33f   Chris Mason   Btrfs: Handle dat...
32
  	 */
f51a4a182   Miao Xie   Btrfs: remove btr...
33
  	int len;
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
34
  	struct list_head list;
f51a4a182   Miao Xie   Btrfs: remove btr...
35
36
  	/* last field is a variable length array of csums */
  	u32 sums[];
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
37
  };
eb84ae039   Chris Mason   Btrfs: Cleanup an...
38
39
40
41
42
43
44
45
46
47
48
  /*
   * bits for the flags field:
   *
   * BTRFS_ORDERED_IO_DONE is set when all of the blocks are written.
   * It is used to make sure metadata is inserted into the tree only once
   * per extent.
   *
   * BTRFS_ORDERED_COMPLETE is set when the extent is removed from the
   * rbtree, just before waking any waiters.  It is used to indicate the
   * IO is done and any metadata is inserted into the tree.
   */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
49
  #define BTRFS_ORDERED_IO_DONE 0 /* set when all the pages are written */
eb84ae039   Chris Mason   Btrfs: Cleanup an...
50

e6dcd2dc9   Chris Mason   Btrfs: New data=o...
51
  #define BTRFS_ORDERED_COMPLETE 1 /* set when removed from the tree */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
52

7ea394f11   Yan Zheng   Btrfs: Fix nodata...
53
  #define BTRFS_ORDERED_NOCOW 2 /* set when we want to write in place */
261507a02   Li Zefan   btrfs: Allow to a...
54
  #define BTRFS_ORDERED_COMPRESSED 3 /* writing a zlib compressed extent */
c8b978188   Chris Mason   Btrfs: Add zlib c...
55

d899e0521   Yan Zheng   Btrfs: Add falloc...
56
  #define BTRFS_ORDERED_PREALLOC 4 /* set when writing to prealloced extent */
4b46fce23   Josef Bacik   Btrfs: add basic ...
57
  #define BTRFS_ORDERED_DIRECT 5 /* set when we're doing DIO with this extent */
5fd020435   Josef Bacik   Btrfs: finish ord...
58
  #define BTRFS_ORDERED_IOERR 6 /* We had an io error when writing this out */
48fc7f7e7   Adam Buchbinder   Fix misspellings ...
59
  #define BTRFS_ORDERED_UPDATED_ISIZE 7 /* indicates whether this ordered extent
5fd020435   Josef Bacik   Btrfs: finish ord...
60
61
  				       * has done its due diligence in updating
  				       * the isize. */
2ab28f322   Josef Bacik   Btrfs: wait on or...
62
63
  #define BTRFS_ORDERED_LOGGED_CSUM 8 /* We've logged the csums on this ordered
  				       ordered extent */
77cef2ec5   Josef Bacik   Btrfs: allow part...
64
  #define BTRFS_ORDERED_TRUNCATED 9 /* Set when we have to truncate an extent */
5fd020435   Josef Bacik   Btrfs: finish ord...
65

50d9aa99b   Josef Bacik   Btrfs: make sure ...
66
67
  #define BTRFS_ORDERED_LOGGED 10 /* Set when we've waited on this ordered extent
  				 * in the logging code. */
161c3549b   Josef Bacik   Btrfs: change how...
68
69
  #define BTRFS_ORDERED_PENDING 11 /* We are waiting for this ordered extent to
  				  * complete in the current transaction. */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
70
  struct btrfs_ordered_extent {
eb84ae039   Chris Mason   Btrfs: Cleanup an...
71
  	/* logical offset in the file */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
72
  	u64 file_offset;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
73
74
  
  	/* disk byte number */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
75
  	u64 start;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
76

c8b978188   Chris Mason   Btrfs: Add zlib c...
77
  	/* ram length of the extent in bytes */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
78
  	u64 len;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
79

c8b978188   Chris Mason   Btrfs: Add zlib c...
80
81
  	/* extent length on disk */
  	u64 disk_len;
8b62b72b2   Chris Mason   Btrfs: Use PagePr...
82
83
  	/* number of bytes that still need writing */
  	u64 bytes_left;
b9a8cc5be   Miao Xie   Btrfs: fix file e...
84
85
86
87
88
89
  	/*
  	 * the end of the ordered extent which is behind it but
  	 * didn't update disk_i_size. Please see the comment of
  	 * btrfs_ordered_update_i_size();
  	 */
  	u64 outstanding_isize;
77cef2ec5   Josef Bacik   Btrfs: allow part...
90
91
92
93
94
  	/*
  	 * If we get truncated we need to adjust the file extent we enter for
  	 * this ordered extent so that we do not expose stale data.
  	 */
  	u64 truncated_len;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
95
  	/* flags (described above) */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
96
  	unsigned long flags;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
97

261507a02   Li Zefan   btrfs: Allow to a...
98
99
  	/* compression algorithm */
  	int compress_type;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
100
  	/* reference count */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
101
  	atomic_t refs;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
102

3eaa28852   Chris Mason   Btrfs: Fix the de...
103
104
  	/* the inode we belong to */
  	struct inode *inode;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
105
  	/* list of checksums for insertion when the extent io is done */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
106
  	struct list_head list;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
107

2ab28f322   Josef Bacik   Btrfs: wait on or...
108
109
  	/* If we need to wait on this to be done */
  	struct list_head log_list;
50d9aa99b   Josef Bacik   Btrfs: make sure ...
110
111
  	/* If the transaction needs to wait on this ordered extent */
  	struct list_head trans_list;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
112
  	/* used to wait for the BTRFS_ORDERED_COMPLETE bit */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
113
  	wait_queue_head_t wait;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
114
115
  
  	/* our friendly rbtree entry */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
116
  	struct rb_node rb_node;
3eaa28852   Chris Mason   Btrfs: Fix the de...
117
118
119
  
  	/* a per root list of all the pending ordered extents */
  	struct list_head root_extent_list;
5fd020435   Josef Bacik   Btrfs: finish ord...
120

d458b0540   Qu Wenruo   btrfs: Cleanup th...
121
  	struct btrfs_work work;
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
122

9afab8820   Miao Xie   Btrfs: make order...
123
  	struct completion completion;
d458b0540   Qu Wenruo   btrfs: Cleanup th...
124
  	struct btrfs_work flush_work;
9afab8820   Miao Xie   Btrfs: make order...
125
126
  	struct list_head work_list;
  };
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
127

eb84ae039   Chris Mason   Btrfs: Cleanup an...
128
129
130
131
  /*
   * calculates the total size you need to allocate for an ordered sum
   * structure spanning 'bytes' in the file
   */
9ba4611a3   Chris Mason   Btrfs: Fix 32 bit...
132
133
  static inline int btrfs_ordered_sum_size(struct btrfs_root *root,
  					 unsigned long bytes)
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
134
  {
f51a4a182   Miao Xie   Btrfs: remove btr...
135
136
  	int num_sectors = (int)DIV_ROUND_UP(bytes, root->sectorsize);
  	return sizeof(struct btrfs_ordered_sum) + num_sectors * sizeof(u32);
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
137
  }
dc17ff8f1   Chris Mason   Btrfs: Add data=o...
138
139
140
  static inline void
  btrfs_ordered_inode_tree_init(struct btrfs_ordered_inode_tree *t)
  {
49958fd7d   Josef Bacik   Btrfs: change the...
141
  	spin_lock_init(&t->lock);
6bef4d317   Eric Paris   Btrfs: use RB_ROO...
142
  	t->tree = RB_ROOT;
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
143
  	t->last = NULL;
dc17ff8f1   Chris Mason   Btrfs: Add data=o...
144
  }
143bede52   Jeff Mahoney   btrfs: return voi...
145
146
  void btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry);
  void btrfs_remove_ordered_extent(struct inode *inode,
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
147
148
  				struct btrfs_ordered_extent *entry);
  int btrfs_dec_test_ordered_pending(struct inode *inode,
5a1a3df1f   Josef Bacik   Btrfs: cache orde...
149
  				   struct btrfs_ordered_extent **cached,
5fd020435   Josef Bacik   Btrfs: finish ord...
150
  				   u64 file_offset, u64 io_size, int uptodate);
163cf09c2   Chris Mason   Btrfs: deal with ...
151
152
  int btrfs_dec_test_first_ordered_pending(struct inode *inode,
  				   struct btrfs_ordered_extent **cached,
5fd020435   Josef Bacik   Btrfs: finish ord...
153
154
  				   u64 *file_offset, u64 io_size,
  				   int uptodate);
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
155
  int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
4b46fce23   Josef Bacik   Btrfs: add basic ...
156
157
158
  			     u64 start, u64 len, u64 disk_len, int type);
  int btrfs_add_ordered_extent_dio(struct inode *inode, u64 file_offset,
  				 u64 start, u64 len, u64 disk_len, int type);
261507a02   Li Zefan   btrfs: Allow to a...
159
160
161
  int btrfs_add_ordered_extent_compress(struct inode *inode, u64 file_offset,
  				      u64 start, u64 len, u64 disk_len,
  				      int type, int compress_type);
143bede52   Jeff Mahoney   btrfs: return voi...
162
163
164
  void btrfs_add_ordered_sum(struct inode *inode,
  			   struct btrfs_ordered_extent *entry,
  			   struct btrfs_ordered_sum *sum);
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
165
166
  struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct inode *inode,
  							 u64 file_offset);
eb84ae039   Chris Mason   Btrfs: Cleanup an...
167
168
  void btrfs_start_ordered_extent(struct inode *inode,
  				struct btrfs_ordered_extent *entry, int wait);
0ef8b7260   Josef Bacik   Btrfs: return an ...
169
  int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len);
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
170
171
  struct btrfs_ordered_extent *
  btrfs_lookup_first_ordered_extent(struct inode * inode, u64 file_offset);
4b46fce23   Josef Bacik   Btrfs: add basic ...
172
173
174
  struct btrfs_ordered_extent *btrfs_lookup_ordered_range(struct inode *inode,
  							u64 file_offset,
  							u64 len);
b659ef027   Filipe Manana   Btrfs: avoid sync...
175
176
177
  bool btrfs_have_ordered_extents_in_range(struct inode *inode,
  					 u64 file_offset,
  					 u64 len);
c21677545   Yan, Zheng   Btrfs: Fix disk_i...
178
  int btrfs_ordered_update_i_size(struct inode *inode, u64 offset,
dbe674a99   Chris Mason   Btrfs: Update on ...
179
  				struct btrfs_ordered_extent *ordered);
e4100d987   Miao Xie   Btrfs: improve th...
180
181
  int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr,
  			   u32 *sum, int len);
b02441999   Miao Xie   Btrfs: don't wait...
182
183
  int btrfs_wait_ordered_extents(struct btrfs_root *root, int nr);
  void btrfs_wait_ordered_roots(struct btrfs_fs_info *fs_info, int nr);
827463c49   Miao Xie   Btrfs: don't mix ...
184
  void btrfs_get_logged_extents(struct inode *inode,
0870295b2   Filipe Manana   Btrfs: collect on...
185
186
187
  			      struct list_head *logged_list,
  			      const loff_t start,
  			      const loff_t end);
827463c49   Miao Xie   Btrfs: don't mix ...
188
189
190
  void btrfs_put_logged_extents(struct list_head *logged_list);
  void btrfs_submit_logged_extents(struct list_head *logged_list,
  				 struct btrfs_root *log);
50d9aa99b   Josef Bacik   Btrfs: make sure ...
191
192
  void btrfs_wait_logged_extents(struct btrfs_trans_handle *trans,
  			       struct btrfs_root *log, u64 transid);
2ab28f322   Josef Bacik   Btrfs: wait on or...
193
  void btrfs_free_logged_extents(struct btrfs_root *log, u64 transid);
6352b91da   Miao Xie   Btrfs: use a slab...
194
195
  int __init ordered_data_init(void);
  void ordered_data_exit(void);
dc17ff8f1   Chris Mason   Btrfs: Add data=o...
196
  #endif