2 * Copyright (C) 2007 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
22 #if BTRFS_FLAT_INCLUDES
23 #include "kerncompat.h"
24 #include "extent-cache.h"
27 #include <btrfs/kerncompat.h>
28 #include <btrfs/extent-cache.h>
29 #include <btrfs/list.h>
30 #endif /* BTRFS_FLAT_INCLUDES */
32 #define EXTENT_DIRTY 1
33 #define EXTENT_WRITEBACK (1 << 1)
34 #define EXTENT_UPTODATE (1 << 2)
35 #define EXTENT_LOCKED (1 << 3)
36 #define EXTENT_NEW (1 << 4)
37 #define EXTENT_DELALLOC (1 << 5)
38 #define EXTENT_DEFRAG (1 << 6)
39 #define EXTENT_DEFRAG_DONE (1 << 7)
40 #define EXTENT_BUFFER_FILLED (1 << 8)
41 #define EXTENT_CSUM (1 << 9)
42 #define EXTENT_BAD_TRANSID (1 << 10)
43 #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
45 #define BLOCK_GROUP_DATA EXTENT_WRITEBACK
46 #define BLOCK_GROUP_METADATA EXTENT_UPTODATE
47 #define BLOCK_GROUP_SYSTEM EXTENT_NEW
49 #define BLOCK_GROUP_DIRTY EXTENT_DIRTY
53 struct extent_io_tree {
54 struct cache_tree state;
55 struct cache_tree cache;
61 struct cache_extent cache_node;
69 struct extent_buffer {
70 struct cache_extent cache_node;
74 struct extent_io_tree *tree;
76 struct list_head recow;
83 static inline void extent_buffer_get(struct extent_buffer *eb)
88 void extent_io_tree_init(struct extent_io_tree *tree);
89 void extent_io_tree_cleanup(struct extent_io_tree *tree);
90 int set_extent_bits(struct extent_io_tree *tree, u64 start,
91 u64 end, int bits, gfp_t mask);
92 int clear_extent_bits(struct extent_io_tree *tree, u64 start,
93 u64 end, int bits, gfp_t mask);
94 int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
95 u64 *start_ret, u64 *end_ret, int bits);
96 int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
97 int bits, int filled);
98 int set_extent_dirty(struct extent_io_tree *tree, u64 start,
100 int clear_extent_dirty(struct extent_io_tree *tree, u64 start,
101 u64 end, gfp_t mask);
102 int extent_buffer_uptodate(struct extent_buffer *eb);
103 int set_extent_buffer_uptodate(struct extent_buffer *eb);
104 int clear_extent_buffer_uptodate(struct extent_io_tree *tree,
105 struct extent_buffer *eb);
106 int set_state_private(struct extent_io_tree *tree, u64 start, u64 xprivate);
107 int get_state_private(struct extent_io_tree *tree, u64 start, u64 *xprivate);
108 struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
109 u64 bytenr, u32 blocksize);
110 struct extent_buffer *find_first_extent_buffer(struct extent_io_tree *tree,
112 struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
113 u64 bytenr, u32 blocksize);
114 void free_extent_buffer(struct extent_buffer *eb);
115 int read_extent_from_disk(struct extent_buffer *eb,
116 unsigned long offset, unsigned long len);
117 int write_extent_to_disk(struct extent_buffer *eb);
118 int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
119 unsigned long start, unsigned long len);
120 void read_extent_buffer(struct extent_buffer *eb, void *dst,
121 unsigned long start, unsigned long len);
122 void write_extent_buffer(struct extent_buffer *eb, const void *src,
123 unsigned long start, unsigned long len);
124 void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
125 unsigned long dst_offset, unsigned long src_offset,
127 void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
128 unsigned long src_offset, unsigned long len);
129 void memset_extent_buffer(struct extent_buffer *eb, char c,
130 unsigned long start, unsigned long len);
131 int set_extent_buffer_dirty(struct extent_buffer *eb);
132 int clear_extent_buffer_dirty(struct extent_buffer *eb);
133 int read_data_from_disk(struct btrfs_fs_info *info, void *buf, u64 offset,
134 u64 bytes, int mirror);
135 int write_data_to_disk(struct btrfs_fs_info *info, void *buf, u64 offset,
136 u64 bytes, int mirror);