Blame view

fs/btrfs/ordered-data.h 5.58 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
  };
eb84ae039   Chris Mason   Btrfs: Cleanup an...
27
28
29
30
31
32
  /*
   * these are used to collect checksums done just before bios submission.
   * They are attached via a list into the ordered extent, and
   * checksum items are inserted into the tree after all the blocks in
   * the ordered extent are on disk
   */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
33
  struct btrfs_sector_sum {
d20f7043f   Chris Mason   Btrfs: move data ...
34
35
  	/* bytenr on disk */
  	u64 bytenr;
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
36
37
38
39
  	u32 sum;
  };
  
  struct btrfs_ordered_sum {
d20f7043f   Chris Mason   Btrfs: move data ...
40
41
  	/* bytenr is the start of this extent on disk */
  	u64 bytenr;
3edf7d33f   Chris Mason   Btrfs: Handle dat...
42
43
  	/*
  	 * this is the length in bytes covered by the sums array below.
3edf7d33f   Chris Mason   Btrfs: Handle dat...
44
45
  	 */
  	unsigned long len;
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
46
  	struct list_head list;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
47
  	/* last field is a variable length array of btrfs_sector_sums */
ed98b56a6   Chris Mason   Btrfs: Take the c...
48
  	struct btrfs_sector_sum sums[];
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
49
  };
eb84ae039   Chris Mason   Btrfs: Cleanup an...
50
51
52
53
54
55
56
57
58
59
60
  /*
   * 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...
61
  #define BTRFS_ORDERED_IO_DONE 0 /* set when all the pages are written */
eb84ae039   Chris Mason   Btrfs: Cleanup an...
62

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

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

d899e0521   Yan Zheng   Btrfs: Add falloc...
68
  #define BTRFS_ORDERED_PREALLOC 4 /* set when writing to prealloced extent */
4b46fce23   Josef Bacik   Btrfs: add basic ...
69
  #define BTRFS_ORDERED_DIRECT 5 /* set when we're doing DIO with this extent */
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;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
84
  	/* flags (described above) */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
85
  	unsigned long flags;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
86

261507a02   Li Zefan   btrfs: Allow to a...
87
88
  	/* compression algorithm */
  	int compress_type;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
89
  	/* reference count */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
90
  	atomic_t refs;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
91

3eaa28852   Chris Mason   Btrfs: Fix the de...
92
93
  	/* the inode we belong to */
  	struct inode *inode;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
94
  	/* list of checksums for insertion when the extent io is done */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
95
  	struct list_head list;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
96
97
  
  	/* used to wait for the BTRFS_ORDERED_COMPLETE bit */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
98
  	wait_queue_head_t wait;
eb84ae039   Chris Mason   Btrfs: Cleanup an...
99
100
  
  	/* our friendly rbtree entry */
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
101
  	struct rb_node rb_node;
3eaa28852   Chris Mason   Btrfs: Fix the de...
102
103
104
  
  	/* a per root list of all the pending ordered extents */
  	struct list_head root_extent_list;
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
105
  };
eb84ae039   Chris Mason   Btrfs: Cleanup an...
106
107
108
109
  /*
   * 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...
110
111
  static inline int btrfs_ordered_sum_size(struct btrfs_root *root,
  					 unsigned long bytes)
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
112
113
114
  {
  	unsigned long num_sectors = (bytes + root->sectorsize - 1) /
  		root->sectorsize;
3edf7d33f   Chris Mason   Btrfs: Handle dat...
115
  	num_sectors++;
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
116
117
118
  	return sizeof(struct btrfs_ordered_sum) +
  		num_sectors * sizeof(struct btrfs_sector_sum);
  }
dc17ff8f1   Chris Mason   Btrfs: Add data=o...
119
120
121
  static inline void
  btrfs_ordered_inode_tree_init(struct btrfs_ordered_inode_tree *t)
  {
49958fd7d   Josef Bacik   Btrfs: change the...
122
  	spin_lock_init(&t->lock);
6bef4d317   Eric Paris   Btrfs: use RB_ROO...
123
  	t->tree = RB_ROOT;
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
124
  	t->last = NULL;
dc17ff8f1   Chris Mason   Btrfs: Add data=o...
125
  }
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
126
127
128
129
  int btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry);
  int btrfs_remove_ordered_extent(struct inode *inode,
  				struct btrfs_ordered_extent *entry);
  int btrfs_dec_test_ordered_pending(struct inode *inode,
5a1a3df1f   Josef Bacik   Btrfs: cache orde...
130
131
  				   struct btrfs_ordered_extent **cached,
  				   u64 file_offset, u64 io_size);
163cf09c2   Chris Mason   Btrfs: deal with ...
132
133
134
  int btrfs_dec_test_first_ordered_pending(struct inode *inode,
  				   struct btrfs_ordered_extent **cached,
  				   u64 *file_offset, u64 io_size);
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
135
  int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
4b46fce23   Josef Bacik   Btrfs: add basic ...
136
137
138
  			     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...
139
140
141
  int btrfs_add_ordered_extent_compress(struct inode *inode, u64 file_offset,
  				      u64 start, u64 len, u64 disk_len,
  				      int type, int compress_type);
3edf7d33f   Chris Mason   Btrfs: Handle dat...
142
143
144
  int btrfs_add_ordered_sum(struct inode *inode,
  			  struct btrfs_ordered_extent *entry,
  			  struct btrfs_ordered_sum *sum);
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
145
146
  struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct inode *inode,
  							 u64 file_offset);
eb84ae039   Chris Mason   Btrfs: Cleanup an...
147
148
  void btrfs_start_ordered_extent(struct inode *inode,
  				struct btrfs_ordered_extent *entry, int wait);
cb843a6f5   Chris Mason   Btrfs: O_DIRECT w...
149
  int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len);
e6dcd2dc9   Chris Mason   Btrfs: New data=o...
150
151
  struct btrfs_ordered_extent *
  btrfs_lookup_first_ordered_extent(struct inode * inode, u64 file_offset);
4b46fce23   Josef Bacik   Btrfs: add basic ...
152
153
154
  struct btrfs_ordered_extent *btrfs_lookup_ordered_range(struct inode *inode,
  							u64 file_offset,
  							u64 len);
c21677545   Yan, Zheng   Btrfs: Fix disk_i...
155
  int btrfs_ordered_update_i_size(struct inode *inode, u64 offset,
dbe674a99   Chris Mason   Btrfs: Update on ...
156
  				struct btrfs_ordered_extent *ordered);
d20f7043f   Chris Mason   Btrfs: move data ...
157
  int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr, u32 *sum);
5a3f23d51   Chris Mason   Btrfs: add extra ...
158
159
160
161
  int btrfs_run_ordered_operations(struct btrfs_root *root, int wait);
  int btrfs_add_ordered_operation(struct btrfs_trans_handle *trans,
  				struct btrfs_root *root,
  				struct inode *inode);
24bbcf044   Yan, Zheng   Btrfs: Add delaye...
162
163
  int btrfs_wait_ordered_extents(struct btrfs_root *root,
  			       int nocow_only, int delay_iput);
dc17ff8f1   Chris Mason   Btrfs: Add data=o...
164
  #endif