23 #include <linux/errno.h>
39 return le64_to_cpu(*(nilfs_direct_dptrs(direct) + key));
42 static inline void nilfs_direct_set_ptr(
struct nilfs_bmap *direct,
48 static int nilfs_direct_lookup(
const struct nilfs_bmap *direct,
55 ptr = nilfs_direct_get_ptr(direct, key);
63 static int nilfs_direct_lookup_contig(
const struct nilfs_bmap *direct,
74 ptr = nilfs_direct_get_ptr(direct, key);
87 for (cnt = 1; cnt < maxblocks &&
88 (ptr2 = nilfs_direct_get_ptr(direct, key + cnt)) !=
97 if (ptr2 != ptr + cnt)
122 struct buffer_head *bh;
131 req.bpr_ptr = nilfs_direct_find_target_v(bmap, key);
134 ret = nilfs_bmap_prepare_alloc_ptr(bmap, &
req, dat);
137 bh = (
struct buffer_head *)((
unsigned long)
ptr);
138 set_buffer_nilfs_volatile(bh);
140 nilfs_bmap_commit_alloc_ptr(bmap, &
req, dat);
141 nilfs_direct_set_ptr(bmap, key,
req.bpr_ptr);
143 if (!nilfs_bmap_dirty(bmap))
144 nilfs_bmap_set_dirty(bmap);
147 nilfs_bmap_set_target_v(bmap, key,
req.bpr_ptr);
165 req.bpr_ptr = nilfs_direct_get_ptr(bmap, key);
167 ret = nilfs_bmap_prepare_end_ptr(bmap, &
req, dat);
169 nilfs_bmap_commit_end_ptr(bmap, &
req, dat);
176 static int nilfs_direct_last_key(
const struct nilfs_bmap *direct,
__u64 *keyp)
182 if (nilfs_direct_get_ptr(direct, key) !=
194 static int nilfs_direct_check_insert(
const struct nilfs_bmap *bmap,
__u64 key)
199 static int nilfs_direct_gather_data(
struct nilfs_bmap *direct,
209 for (key = 0; key < nitems; key++) {
210 ptr = nilfs_direct_get_ptr(direct, key);
229 ret = bmap->
b_ops->bop_delete(bmap, key);
235 bmap->
b_ops->bop_clear(bmap);
238 dptrs = nilfs_direct_dptrs(bmap);
240 if ((j < n) && (i == keys[j])) {
241 dptrs[
i] = (i !=
key) ?
253 static int nilfs_direct_propagate(
struct nilfs_bmap *bmap,
254 struct buffer_head *bh)
267 ptr = nilfs_direct_get_ptr(bmap, key);
268 if (!buffer_nilfs_volatile(bh)) {
269 oldreq.pr_entry_nr =
ptr;
270 newreq.pr_entry_nr =
ptr;
276 set_buffer_nilfs_volatile(bh);
277 nilfs_direct_set_ptr(bmap, key, newreq.pr_entry_nr);
284 static int nilfs_direct_assign_v(
struct nilfs_bmap *direct,
286 struct buffer_head **bh,
304 static int nilfs_direct_assign_p(
struct nilfs_bmap *direct,
306 struct buffer_head **bh,
310 nilfs_direct_set_ptr(direct, key, blocknr);
313 binfo->
bi_dat.bi_level = 0;
318 static int nilfs_direct_assign(
struct nilfs_bmap *bmap,
319 struct buffer_head **bh,
329 (
unsigned long long)key);
332 ptr = nilfs_direct_get_ptr(bmap, key);
335 (
unsigned long long)ptr);
340 nilfs_direct_assign_v(bmap, key, ptr, bh, blocknr, binfo) :
341 nilfs_direct_assign_p(bmap, key, ptr, bh, blocknr, binfo);
345 .bop_lookup = nilfs_direct_lookup,
346 .bop_lookup_contig = nilfs_direct_lookup_contig,
347 .bop_insert = nilfs_direct_insert,
348 .bop_delete = nilfs_direct_delete,
351 .bop_propagate = nilfs_direct_propagate,
353 .bop_lookup_dirty_buffers =
NULL,
355 .bop_assign = nilfs_direct_assign,
358 .bop_last_key = nilfs_direct_last_key,
359 .bop_check_insert = nilfs_direct_check_insert,
360 .bop_check_delete =
NULL,
361 .bop_gather_data = nilfs_direct_gather_data,
367 bmap->
b_ops = &nilfs_direct_ops;