diff options
Diffstat (limited to 'fs/nilfs2/bmap.h')
-rw-r--r-- | fs/nilfs2/bmap.h | 135 |
1 files changed, 84 insertions, 51 deletions
diff --git a/fs/nilfs2/bmap.h b/fs/nilfs2/bmap.h index 4f2708abb1ba..b2890cdcef12 100644 --- a/fs/nilfs2/bmap.h +++ b/fs/nilfs2/bmap.h | |||
@@ -64,6 +64,8 @@ struct nilfs_bmap_stats { | |||
64 | */ | 64 | */ |
65 | struct nilfs_bmap_operations { | 65 | struct nilfs_bmap_operations { |
66 | int (*bop_lookup)(const struct nilfs_bmap *, __u64, int, __u64 *); | 66 | int (*bop_lookup)(const struct nilfs_bmap *, __u64, int, __u64 *); |
67 | int (*bop_lookup_contig)(const struct nilfs_bmap *, __u64, __u64 *, | ||
68 | unsigned); | ||
67 | int (*bop_insert)(struct nilfs_bmap *, __u64, __u64); | 69 | int (*bop_insert)(struct nilfs_bmap *, __u64, __u64); |
68 | int (*bop_delete)(struct nilfs_bmap *, __u64); | 70 | int (*bop_delete)(struct nilfs_bmap *, __u64); |
69 | void (*bop_clear)(struct nilfs_bmap *); | 71 | void (*bop_clear)(struct nilfs_bmap *); |
@@ -86,34 +88,6 @@ struct nilfs_bmap_operations { | |||
86 | }; | 88 | }; |
87 | 89 | ||
88 | 90 | ||
89 | /** | ||
90 | * struct nilfs_bmap_ptr_operations - bmap ptr operation table | ||
91 | */ | ||
92 | struct nilfs_bmap_ptr_operations { | ||
93 | int (*bpop_prepare_alloc_ptr)(struct nilfs_bmap *, | ||
94 | union nilfs_bmap_ptr_req *); | ||
95 | void (*bpop_commit_alloc_ptr)(struct nilfs_bmap *, | ||
96 | union nilfs_bmap_ptr_req *); | ||
97 | void (*bpop_abort_alloc_ptr)(struct nilfs_bmap *, | ||
98 | union nilfs_bmap_ptr_req *); | ||
99 | int (*bpop_prepare_start_ptr)(struct nilfs_bmap *, | ||
100 | union nilfs_bmap_ptr_req *); | ||
101 | void (*bpop_commit_start_ptr)(struct nilfs_bmap *, | ||
102 | union nilfs_bmap_ptr_req *, | ||
103 | sector_t); | ||
104 | void (*bpop_abort_start_ptr)(struct nilfs_bmap *, | ||
105 | union nilfs_bmap_ptr_req *); | ||
106 | int (*bpop_prepare_end_ptr)(struct nilfs_bmap *, | ||
107 | union nilfs_bmap_ptr_req *); | ||
108 | void (*bpop_commit_end_ptr)(struct nilfs_bmap *, | ||
109 | union nilfs_bmap_ptr_req *); | ||
110 | void (*bpop_abort_end_ptr)(struct nilfs_bmap *, | ||
111 | union nilfs_bmap_ptr_req *); | ||
112 | |||
113 | int (*bpop_translate)(const struct nilfs_bmap *, __u64, __u64 *); | ||
114 | }; | ||
115 | |||
116 | |||
117 | #define NILFS_BMAP_SIZE (NILFS_INODE_BMAP_SIZE * sizeof(__le64)) | 91 | #define NILFS_BMAP_SIZE (NILFS_INODE_BMAP_SIZE * sizeof(__le64)) |
118 | #define NILFS_BMAP_KEY_BIT (sizeof(unsigned long) * 8 /* CHAR_BIT */) | 92 | #define NILFS_BMAP_KEY_BIT (sizeof(unsigned long) * 8 /* CHAR_BIT */) |
119 | #define NILFS_BMAP_NEW_PTR_INIT \ | 93 | #define NILFS_BMAP_NEW_PTR_INIT \ |
@@ -131,11 +105,9 @@ static inline int nilfs_bmap_is_new_ptr(unsigned long ptr) | |||
131 | * @b_sem: semaphore | 105 | * @b_sem: semaphore |
132 | * @b_inode: owner of bmap | 106 | * @b_inode: owner of bmap |
133 | * @b_ops: bmap operation table | 107 | * @b_ops: bmap operation table |
134 | * @b_pops: bmap ptr operation table | ||
135 | * @b_low: low watermark of conversion | ||
136 | * @b_high: high watermark of conversion | ||
137 | * @b_last_allocated_key: last allocated key for data block | 108 | * @b_last_allocated_key: last allocated key for data block |
138 | * @b_last_allocated_ptr: last allocated ptr for data block | 109 | * @b_last_allocated_ptr: last allocated ptr for data block |
110 | * @b_ptr_type: pointer type | ||
139 | * @b_state: state | 111 | * @b_state: state |
140 | */ | 112 | */ |
141 | struct nilfs_bmap { | 113 | struct nilfs_bmap { |
@@ -146,14 +118,22 @@ struct nilfs_bmap { | |||
146 | struct rw_semaphore b_sem; | 118 | struct rw_semaphore b_sem; |
147 | struct inode *b_inode; | 119 | struct inode *b_inode; |
148 | const struct nilfs_bmap_operations *b_ops; | 120 | const struct nilfs_bmap_operations *b_ops; |
149 | const struct nilfs_bmap_ptr_operations *b_pops; | ||
150 | __u64 b_low; | ||
151 | __u64 b_high; | ||
152 | __u64 b_last_allocated_key; | 121 | __u64 b_last_allocated_key; |
153 | __u64 b_last_allocated_ptr; | 122 | __u64 b_last_allocated_ptr; |
123 | int b_ptr_type; | ||
154 | int b_state; | 124 | int b_state; |
155 | }; | 125 | }; |
156 | 126 | ||
127 | /* pointer type */ | ||
128 | #define NILFS_BMAP_PTR_P 0 /* physical block number (i.e. LBN) */ | ||
129 | #define NILFS_BMAP_PTR_VS 1 /* virtual block number (single | ||
130 | version) */ | ||
131 | #define NILFS_BMAP_PTR_VM 2 /* virtual block number (has multiple | ||
132 | versions) */ | ||
133 | #define NILFS_BMAP_PTR_U (-1) /* never perform pointer operations */ | ||
134 | |||
135 | #define NILFS_BMAP_USE_VBN(bmap) ((bmap)->b_ptr_type > 0) | ||
136 | |||
157 | /* state */ | 137 | /* state */ |
158 | #define NILFS_BMAP_DIRTY 0x00000001 | 138 | #define NILFS_BMAP_DIRTY 0x00000001 |
159 | 139 | ||
@@ -162,6 +142,7 @@ int nilfs_bmap_test_and_clear_dirty(struct nilfs_bmap *); | |||
162 | int nilfs_bmap_read(struct nilfs_bmap *, struct nilfs_inode *); | 142 | int nilfs_bmap_read(struct nilfs_bmap *, struct nilfs_inode *); |
163 | void nilfs_bmap_write(struct nilfs_bmap *, struct nilfs_inode *); | 143 | void nilfs_bmap_write(struct nilfs_bmap *, struct nilfs_inode *); |
164 | int nilfs_bmap_lookup(struct nilfs_bmap *, unsigned long, unsigned long *); | 144 | int nilfs_bmap_lookup(struct nilfs_bmap *, unsigned long, unsigned long *); |
145 | int nilfs_bmap_lookup_contig(struct nilfs_bmap *, __u64, __u64 *, unsigned); | ||
165 | int nilfs_bmap_insert(struct nilfs_bmap *, unsigned long, unsigned long); | 146 | int nilfs_bmap_insert(struct nilfs_bmap *, unsigned long, unsigned long); |
166 | int nilfs_bmap_delete(struct nilfs_bmap *, unsigned long); | 147 | int nilfs_bmap_delete(struct nilfs_bmap *, unsigned long); |
167 | int nilfs_bmap_last_key(struct nilfs_bmap *, unsigned long *); | 148 | int nilfs_bmap_last_key(struct nilfs_bmap *, unsigned long *); |
@@ -182,7 +163,67 @@ void nilfs_bmap_commit_gcdat(struct nilfs_bmap *, struct nilfs_bmap *); | |||
182 | /* | 163 | /* |
183 | * Internal use only | 164 | * Internal use only |
184 | */ | 165 | */ |
166 | struct inode *nilfs_bmap_get_dat(const struct nilfs_bmap *); | ||
167 | int nilfs_bmap_prepare_alloc_v(struct nilfs_bmap *, | ||
168 | union nilfs_bmap_ptr_req *); | ||
169 | void nilfs_bmap_commit_alloc_v(struct nilfs_bmap *, | ||
170 | union nilfs_bmap_ptr_req *); | ||
171 | void nilfs_bmap_abort_alloc_v(struct nilfs_bmap *, | ||
172 | union nilfs_bmap_ptr_req *); | ||
185 | 173 | ||
174 | static inline int nilfs_bmap_prepare_alloc_ptr(struct nilfs_bmap *bmap, | ||
175 | union nilfs_bmap_ptr_req *req) | ||
176 | { | ||
177 | if (NILFS_BMAP_USE_VBN(bmap)) | ||
178 | return nilfs_bmap_prepare_alloc_v(bmap, req); | ||
179 | /* ignore target ptr */ | ||
180 | req->bpr_ptr = bmap->b_last_allocated_ptr++; | ||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | static inline void nilfs_bmap_commit_alloc_ptr(struct nilfs_bmap *bmap, | ||
185 | union nilfs_bmap_ptr_req *req) | ||
186 | { | ||
187 | if (NILFS_BMAP_USE_VBN(bmap)) | ||
188 | nilfs_bmap_commit_alloc_v(bmap, req); | ||
189 | } | ||
190 | |||
191 | static inline void nilfs_bmap_abort_alloc_ptr(struct nilfs_bmap *bmap, | ||
192 | union nilfs_bmap_ptr_req *req) | ||
193 | { | ||
194 | if (NILFS_BMAP_USE_VBN(bmap)) | ||
195 | nilfs_bmap_abort_alloc_v(bmap, req); | ||
196 | else | ||
197 | bmap->b_last_allocated_ptr--; | ||
198 | } | ||
199 | |||
200 | int nilfs_bmap_prepare_end_v(struct nilfs_bmap *, union nilfs_bmap_ptr_req *); | ||
201 | void nilfs_bmap_commit_end_v(struct nilfs_bmap *, union nilfs_bmap_ptr_req *); | ||
202 | void nilfs_bmap_abort_end_v(struct nilfs_bmap *, union nilfs_bmap_ptr_req *); | ||
203 | |||
204 | static inline int nilfs_bmap_prepare_end_ptr(struct nilfs_bmap *bmap, | ||
205 | union nilfs_bmap_ptr_req *req) | ||
206 | { | ||
207 | return NILFS_BMAP_USE_VBN(bmap) ? | ||
208 | nilfs_bmap_prepare_end_v(bmap, req) : 0; | ||
209 | } | ||
210 | |||
211 | static inline void nilfs_bmap_commit_end_ptr(struct nilfs_bmap *bmap, | ||
212 | union nilfs_bmap_ptr_req *req) | ||
213 | { | ||
214 | if (NILFS_BMAP_USE_VBN(bmap)) | ||
215 | nilfs_bmap_commit_end_v(bmap, req); | ||
216 | } | ||
217 | |||
218 | static inline void nilfs_bmap_abort_end_ptr(struct nilfs_bmap *bmap, | ||
219 | union nilfs_bmap_ptr_req *req) | ||
220 | { | ||
221 | if (NILFS_BMAP_USE_VBN(bmap)) | ||
222 | nilfs_bmap_abort_end_v(bmap, req); | ||
223 | } | ||
224 | |||
225 | int nilfs_bmap_start_v(struct nilfs_bmap *, union nilfs_bmap_ptr_req *, | ||
226 | sector_t); | ||
186 | int nilfs_bmap_move_v(const struct nilfs_bmap *, __u64, sector_t); | 227 | int nilfs_bmap_move_v(const struct nilfs_bmap *, __u64, sector_t); |
187 | int nilfs_bmap_mark_dirty(const struct nilfs_bmap *, __u64); | 228 | int nilfs_bmap_mark_dirty(const struct nilfs_bmap *, __u64); |
188 | 229 | ||
@@ -193,28 +234,20 @@ __u64 nilfs_bmap_data_get_key(const struct nilfs_bmap *, | |||
193 | __u64 nilfs_bmap_find_target_seq(const struct nilfs_bmap *, __u64); | 234 | __u64 nilfs_bmap_find_target_seq(const struct nilfs_bmap *, __u64); |
194 | __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *); | 235 | __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *); |
195 | 236 | ||
196 | int nilfs_bmap_prepare_update(struct nilfs_bmap *, | 237 | int nilfs_bmap_prepare_update_v(struct nilfs_bmap *, |
197 | union nilfs_bmap_ptr_req *, | 238 | union nilfs_bmap_ptr_req *, |
198 | union nilfs_bmap_ptr_req *); | 239 | union nilfs_bmap_ptr_req *); |
199 | void nilfs_bmap_commit_update(struct nilfs_bmap *, | 240 | void nilfs_bmap_commit_update_v(struct nilfs_bmap *, |
200 | union nilfs_bmap_ptr_req *, | 241 | union nilfs_bmap_ptr_req *, |
201 | union nilfs_bmap_ptr_req *); | 242 | union nilfs_bmap_ptr_req *); |
202 | void nilfs_bmap_abort_update(struct nilfs_bmap *, | 243 | void nilfs_bmap_abort_update_v(struct nilfs_bmap *, |
203 | union nilfs_bmap_ptr_req *, | 244 | union nilfs_bmap_ptr_req *, |
204 | union nilfs_bmap_ptr_req *); | 245 | union nilfs_bmap_ptr_req *); |
205 | 246 | ||
206 | void nilfs_bmap_add_blocks(const struct nilfs_bmap *, int); | 247 | void nilfs_bmap_add_blocks(const struct nilfs_bmap *, int); |
207 | void nilfs_bmap_sub_blocks(const struct nilfs_bmap *, int); | 248 | void nilfs_bmap_sub_blocks(const struct nilfs_bmap *, int); |
208 | 249 | ||
209 | 250 | ||
210 | int nilfs_bmap_get_block(const struct nilfs_bmap *, __u64, | ||
211 | struct buffer_head **); | ||
212 | void nilfs_bmap_put_block(const struct nilfs_bmap *, struct buffer_head *); | ||
213 | int nilfs_bmap_get_new_block(const struct nilfs_bmap *, __u64, | ||
214 | struct buffer_head **); | ||
215 | void nilfs_bmap_delete_block(const struct nilfs_bmap *, struct buffer_head *); | ||
216 | |||
217 | |||
218 | /* Assume that bmap semaphore is locked. */ | 251 | /* Assume that bmap semaphore is locked. */ |
219 | static inline int nilfs_bmap_dirty(const struct nilfs_bmap *bmap) | 252 | static inline int nilfs_bmap_dirty(const struct nilfs_bmap *bmap) |
220 | { | 253 | { |