Blame view
fs/btrfs/ordered-data.h
6.97 KB
dc17ff8f1
|
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
|
21 |
/* one of these per inode */ |
dc17ff8f1
|
22 |
struct btrfs_ordered_inode_tree { |
49958fd7d
|
23 |
spinlock_t lock; |
dc17ff8f1
|
24 |
struct rb_root tree; |
e6dcd2dc9
|
25 |
struct rb_node *last; |
dc17ff8f1
|
26 |
}; |
e6dcd2dc9
|
27 |
struct btrfs_ordered_sum { |
d20f7043f
|
28 29 |
/* bytenr is the start of this extent on disk */ u64 bytenr; |
3edf7d33f
|
30 31 |
/* * this is the length in bytes covered by the sums array below. |
3edf7d33f
|
32 |
*/ |
f51a4a182
|
33 |
int len; |
e6dcd2dc9
|
34 |
struct list_head list; |
f51a4a182
|
35 36 |
/* last field is a variable length array of csums */ u32 sums[]; |
e6dcd2dc9
|
37 |
}; |
eb84ae039
|
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
|
49 |
#define BTRFS_ORDERED_IO_DONE 0 /* set when all the pages are written */ |
eb84ae039
|
50 |
|
e6dcd2dc9
|
51 |
#define BTRFS_ORDERED_COMPLETE 1 /* set when removed from the tree */ |
e6dcd2dc9
|
52 |
|
7ea394f11
|
53 |
#define BTRFS_ORDERED_NOCOW 2 /* set when we want to write in place */ |
261507a02
|
54 |
#define BTRFS_ORDERED_COMPRESSED 3 /* writing a zlib compressed extent */ |
c8b978188
|
55 |
|
d899e0521
|
56 |
#define BTRFS_ORDERED_PREALLOC 4 /* set when writing to prealloced extent */ |
4b46fce23
|
57 |
#define BTRFS_ORDERED_DIRECT 5 /* set when we're doing DIO with this extent */ |
5fd020435
|
58 |
#define BTRFS_ORDERED_IOERR 6 /* We had an io error when writing this out */ |
48fc7f7e7
|
59 |
#define BTRFS_ORDERED_UPDATED_ISIZE 7 /* indicates whether this ordered extent |
5fd020435
|
60 61 |
* has done its due diligence in updating * the isize. */ |
2ab28f322
|
62 63 |
#define BTRFS_ORDERED_LOGGED_CSUM 8 /* We've logged the csums on this ordered ordered extent */ |
77cef2ec5
|
64 |
#define BTRFS_ORDERED_TRUNCATED 9 /* Set when we have to truncate an extent */ |
5fd020435
|
65 |
|
50d9aa99b
|
66 67 |
#define BTRFS_ORDERED_LOGGED 10 /* Set when we've waited on this ordered extent * in the logging code. */ |
161c3549b
|
68 69 |
#define BTRFS_ORDERED_PENDING 11 /* We are waiting for this ordered extent to * complete in the current transaction. */ |
e6dcd2dc9
|
70 |
struct btrfs_ordered_extent { |
eb84ae039
|
71 |
/* logical offset in the file */ |
e6dcd2dc9
|
72 |
u64 file_offset; |
eb84ae039
|
73 74 |
/* disk byte number */ |
e6dcd2dc9
|
75 |
u64 start; |
eb84ae039
|
76 |
|
c8b978188
|
77 |
/* ram length of the extent in bytes */ |
e6dcd2dc9
|
78 |
u64 len; |
eb84ae039
|
79 |
|
c8b978188
|
80 81 |
/* extent length on disk */ u64 disk_len; |
8b62b72b2
|
82 83 |
/* number of bytes that still need writing */ u64 bytes_left; |
b9a8cc5be
|
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
|
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
|
95 |
/* flags (described above) */ |
e6dcd2dc9
|
96 |
unsigned long flags; |
eb84ae039
|
97 |
|
261507a02
|
98 99 |
/* compression algorithm */ int compress_type; |
eb84ae039
|
100 |
/* reference count */ |
e6dcd2dc9
|
101 |
atomic_t refs; |
eb84ae039
|
102 |
|
3eaa28852
|
103 104 |
/* the inode we belong to */ struct inode *inode; |
eb84ae039
|
105 |
/* list of checksums for insertion when the extent io is done */ |
e6dcd2dc9
|
106 |
struct list_head list; |
eb84ae039
|
107 |
|
2ab28f322
|
108 109 |
/* If we need to wait on this to be done */ struct list_head log_list; |
50d9aa99b
|
110 111 |
/* If the transaction needs to wait on this ordered extent */ struct list_head trans_list; |
eb84ae039
|
112 |
/* used to wait for the BTRFS_ORDERED_COMPLETE bit */ |
e6dcd2dc9
|
113 |
wait_queue_head_t wait; |
eb84ae039
|
114 115 |
/* our friendly rbtree entry */ |
e6dcd2dc9
|
116 |
struct rb_node rb_node; |
3eaa28852
|
117 118 119 |
/* a per root list of all the pending ordered extents */ struct list_head root_extent_list; |
5fd020435
|
120 |
|
d458b0540
|
121 |
struct btrfs_work work; |
e6dcd2dc9
|
122 |
|
9afab8820
|
123 |
struct completion completion; |
d458b0540
|
124 |
struct btrfs_work flush_work; |
9afab8820
|
125 126 |
struct list_head work_list; }; |
e6dcd2dc9
|
127 |
|
eb84ae039
|
128 129 130 131 |
/* * calculates the total size you need to allocate for an ordered sum * structure spanning 'bytes' in the file */ |
9ba4611a3
|
132 133 |
static inline int btrfs_ordered_sum_size(struct btrfs_root *root, unsigned long bytes) |
e6dcd2dc9
|
134 |
{ |
f51a4a182
|
135 136 |
int num_sectors = (int)DIV_ROUND_UP(bytes, root->sectorsize); return sizeof(struct btrfs_ordered_sum) + num_sectors * sizeof(u32); |
e6dcd2dc9
|
137 |
} |
dc17ff8f1
|
138 139 140 |
static inline void btrfs_ordered_inode_tree_init(struct btrfs_ordered_inode_tree *t) { |
49958fd7d
|
141 |
spin_lock_init(&t->lock); |
6bef4d317
|
142 |
t->tree = RB_ROOT; |
e6dcd2dc9
|
143 |
t->last = NULL; |
dc17ff8f1
|
144 |
} |
143bede52
|
145 146 |
void btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry); void btrfs_remove_ordered_extent(struct inode *inode, |
e6dcd2dc9
|
147 148 |
struct btrfs_ordered_extent *entry); int btrfs_dec_test_ordered_pending(struct inode *inode, |
5a1a3df1f
|
149 |
struct btrfs_ordered_extent **cached, |
5fd020435
|
150 |
u64 file_offset, u64 io_size, int uptodate); |
163cf09c2
|
151 152 |
int btrfs_dec_test_first_ordered_pending(struct inode *inode, struct btrfs_ordered_extent **cached, |
5fd020435
|
153 154 |
u64 *file_offset, u64 io_size, int uptodate); |
e6dcd2dc9
|
155 |
int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, |
4b46fce23
|
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
|
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
|
162 163 164 |
void btrfs_add_ordered_sum(struct inode *inode, struct btrfs_ordered_extent *entry, struct btrfs_ordered_sum *sum); |
e6dcd2dc9
|
165 166 |
struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct inode *inode, u64 file_offset); |
eb84ae039
|
167 168 |
void btrfs_start_ordered_extent(struct inode *inode, struct btrfs_ordered_extent *entry, int wait); |
0ef8b7260
|
169 |
int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len); |
e6dcd2dc9
|
170 171 |
struct btrfs_ordered_extent * btrfs_lookup_first_ordered_extent(struct inode * inode, u64 file_offset); |
4b46fce23
|
172 173 174 |
struct btrfs_ordered_extent *btrfs_lookup_ordered_range(struct inode *inode, u64 file_offset, u64 len); |
b659ef027
|
175 176 177 |
bool btrfs_have_ordered_extents_in_range(struct inode *inode, u64 file_offset, u64 len); |
c21677545
|
178 |
int btrfs_ordered_update_i_size(struct inode *inode, u64 offset, |
dbe674a99
|
179 |
struct btrfs_ordered_extent *ordered); |
e4100d987
|
180 181 |
int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr, u32 *sum, int len); |
b02441999
|
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
|
184 |
void btrfs_get_logged_extents(struct inode *inode, |
0870295b2
|
185 186 187 |
struct list_head *logged_list, const loff_t start, const loff_t end); |
827463c49
|
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
|
191 192 |
void btrfs_wait_logged_extents(struct btrfs_trans_handle *trans, struct btrfs_root *log, u64 transid); |
2ab28f322
|
193 |
void btrfs_free_logged_extents(struct btrfs_root *log, u64 transid); |
6352b91da
|
194 195 |
int __init ordered_data_init(void); void ordered_data_exit(void); |
dc17ff8f1
|
196 |
#endif |