aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ordered-data.h
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-07-17 12:53:50 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:04 -0400
commite6dcd2dc9c489108648e2ed543315dd134d50a9a (patch)
treecddf6f588b65e28c5feb8bff89b22d8ff70f8a50 /fs/btrfs/ordered-data.h
parent77a41afb7d0dd0f27b6f2f1a5bc701929c7034de (diff)
Btrfs: New data=ordered implementation
The old data=ordered code would force commit to wait until all the data extents from the transaction were fully on disk. This introduced large latencies into the commit and stalled new writers in the transaction for a long time. The new code changes the way data allocations and extents work: * When delayed allocation is filled, data extents are reserved, and the extent bit EXTENT_ORDERED is set on the entire range of the extent. A struct btrfs_ordered_extent is allocated an inserted into a per-inode rbtree to track the pending extents. * As each page is written EXTENT_ORDERED is cleared on the bytes corresponding to that page. * When all of the bytes corresponding to a single struct btrfs_ordered_extent are written, The previously reserved extent is inserted into the FS btree and into the extent allocation trees. The checksums for the file data are also updated. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ordered-data.h')
-rw-r--r--fs/btrfs/ordered-data.h71
1 files changed, 60 insertions, 11 deletions
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
index 4fa78736423e..33292c5fe90c 100644
--- a/fs/btrfs/ordered-data.h
+++ b/fs/btrfs/ordered-data.h
@@ -20,24 +20,73 @@
20#define __BTRFS_ORDERED_DATA__ 20#define __BTRFS_ORDERED_DATA__
21 21
22struct btrfs_ordered_inode_tree { 22struct btrfs_ordered_inode_tree {
23 rwlock_t lock; 23 struct mutex mutex;
24 struct rb_root tree; 24 struct rb_root tree;
25 struct rb_node *last;
25}; 26};
26 27
28struct btrfs_sector_sum {
29 u64 offset;
30 u32 sum;
31};
32
33struct btrfs_ordered_sum {
34 u64 file_offset;
35 u64 len;
36 struct list_head list;
37 struct btrfs_sector_sum sums;
38};
39
40/* bits for the flags field */
41#define BTRFS_ORDERED_IO_DONE 0 /* set when all the pages are written */
42#define BTRFS_ORDERED_COMPLETE 1 /* set when removed from the tree */
43#define BTRFS_ORDERED_START 2 /* set when tree setup */
44
45struct btrfs_ordered_extent {
46 u64 file_offset;
47 u64 start;
48 u64 len;
49 unsigned long flags;
50 atomic_t refs;
51 struct list_head list;
52 struct inode *inode;
53 wait_queue_head_t wait;
54 struct rb_node rb_node;
55};
56
57
58static inline int btrfs_ordered_sum_size(struct btrfs_root *root, u64 bytes)
59{
60 unsigned long num_sectors = (bytes + root->sectorsize - 1) /
61 root->sectorsize;
62 return sizeof(struct btrfs_ordered_sum) +
63 num_sectors * sizeof(struct btrfs_sector_sum);
64}
65
27static inline void 66static inline void
28btrfs_ordered_inode_tree_init(struct btrfs_ordered_inode_tree *t) 67btrfs_ordered_inode_tree_init(struct btrfs_ordered_inode_tree *t)
29{ 68{
30 rwlock_init(&t->lock); 69 mutex_init(&t->mutex);
31 t->tree.rb_node = NULL; 70 t->tree.rb_node = NULL;
71 t->last = NULL;
32} 72}
33 73
34int btrfs_add_ordered_inode(struct inode *inode); 74int btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry);
35int btrfs_find_del_first_ordered_inode(struct btrfs_ordered_inode_tree *tree, 75int btrfs_remove_ordered_extent(struct inode *inode,
36 u64 *root_objectid, u64 *objectid, 76 struct btrfs_ordered_extent *entry);
37 struct inode **inode); 77int btrfs_dec_test_ordered_pending(struct inode *inode,
38int btrfs_find_first_ordered_inode(struct btrfs_ordered_inode_tree *tree, 78 u64 file_offset, u64 io_size);
39 u64 *root_objectid, u64 *objectid, 79int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
40 struct inode **inode); 80 u64 start, u64 len);
41void btrfs_del_ordered_inode(struct inode *inode, int force); 81int btrfs_add_ordered_sum(struct inode *inode, struct btrfs_ordered_sum *sum);
42int btrfs_ordered_throttle(struct btrfs_root *root, struct inode *inode); 82struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct inode *inode,
83 u64 file_offset);
84void btrfs_wait_ordered_extent(struct inode *inode,
85 struct btrfs_ordered_extent *entry);
86void btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len);
87struct btrfs_ordered_extent *
88btrfs_lookup_first_ordered_extent(struct inode * inode, u64 file_offset);
89int btrfs_add_ordered_pending(struct inode *inode,
90 struct btrfs_ordered_extent *ordered,
91 u64 start, u64 len);
43#endif 92#endif