Lines Matching refs:be
26 ext_tree_prev(struct pnfs_block_extent *be) in ext_tree_prev() argument
28 struct rb_node *node = rb_prev(&be->be_node); in ext_tree_prev()
33 ext_tree_next(struct pnfs_block_extent *be) in ext_tree_next() argument
35 struct rb_node *node = rb_next(&be->be_node); in ext_tree_next()
40 ext_f_end(struct pnfs_block_extent *be) in ext_f_end() argument
42 return be->be_f_offset + be->be_length; in ext_f_end()
49 struct pnfs_block_extent *be = NULL; in __ext_tree_search() local
52 be = ext_node(node); in __ext_tree_search()
53 if (start < be->be_f_offset) in __ext_tree_search()
55 else if (start >= ext_f_end(be)) in __ext_tree_search()
58 return be; in __ext_tree_search()
61 if (be) { in __ext_tree_search()
62 if (start < be->be_f_offset) in __ext_tree_search()
63 return be; in __ext_tree_search()
65 if (start >= ext_f_end(be)) in __ext_tree_search()
66 return ext_tree_next(be); in __ext_tree_search()
95 ext_try_to_merge_left(struct rb_root *root, struct pnfs_block_extent *be) in ext_try_to_merge_left() argument
97 struct pnfs_block_extent *left = ext_tree_prev(be); in ext_try_to_merge_left()
99 if (left && ext_can_merge(left, be)) { in ext_try_to_merge_left()
100 left->be_length += be->be_length; in ext_try_to_merge_left()
101 rb_erase(&be->be_node, root); in ext_try_to_merge_left()
102 nfs4_put_deviceid_node(be->be_device); in ext_try_to_merge_left()
103 kfree(be); in ext_try_to_merge_left()
107 return be; in ext_try_to_merge_left()
111 ext_try_to_merge_right(struct rb_root *root, struct pnfs_block_extent *be) in ext_try_to_merge_right() argument
113 struct pnfs_block_extent *right = ext_tree_next(be); in ext_try_to_merge_right()
115 if (right && ext_can_merge(be, right)) { in ext_try_to_merge_right()
116 be->be_length += right->be_length; in ext_try_to_merge_right()
122 return be; in ext_try_to_merge_right()
127 struct pnfs_block_extent *be, *tmp; in __ext_put_deviceids() local
129 list_for_each_entry_safe(be, tmp, head, be_list) { in __ext_put_deviceids()
130 nfs4_put_deviceid_node(be->be_device); in __ext_put_deviceids()
131 kfree(be); in __ext_put_deviceids()
140 struct pnfs_block_extent *be; in __ext_tree_insert() local
144 be = ext_node(parent); in __ext_tree_insert()
146 if (new->be_f_offset < be->be_f_offset) { in __ext_tree_insert()
147 if (merge_ok && ext_can_merge(new, be)) { in __ext_tree_insert()
148 be->be_f_offset = new->be_f_offset; in __ext_tree_insert()
149 if (be->be_state != PNFS_BLOCK_NONE_DATA) in __ext_tree_insert()
150 be->be_v_offset = new->be_v_offset; in __ext_tree_insert()
151 be->be_length += new->be_length; in __ext_tree_insert()
152 be = ext_try_to_merge_left(root, be); in __ext_tree_insert()
156 } else if (new->be_f_offset >= ext_f_end(be)) { in __ext_tree_insert()
157 if (merge_ok && ext_can_merge(be, new)) { in __ext_tree_insert()
158 be->be_length += new->be_length; in __ext_tree_insert()
159 be = ext_try_to_merge_right(root, be); in __ext_tree_insert()
180 struct pnfs_block_extent *be; in __ext_tree_remove() local
185 be = __ext_tree_search(root, start); in __ext_tree_remove()
186 if (!be) in __ext_tree_remove()
188 if (be->be_f_offset >= end) in __ext_tree_remove()
191 orig_v_offset = be->be_v_offset; in __ext_tree_remove()
192 orig_len = be->be_length; in __ext_tree_remove()
194 if (start > be->be_f_offset) in __ext_tree_remove()
195 len1 = start - be->be_f_offset; in __ext_tree_remove()
196 if (ext_f_end(be) > end) in __ext_tree_remove()
197 len2 = ext_f_end(be) - end; in __ext_tree_remove()
207 be->be_length = len1; in __ext_tree_remove()
210 if (be->be_state != PNFS_BLOCK_NONE_DATA) { in __ext_tree_remove()
215 new->be_state = be->be_state; in __ext_tree_remove()
216 new->be_tag = be->be_tag; in __ext_tree_remove()
217 new->be_device = nfs4_get_deviceid(be->be_device); in __ext_tree_remove()
221 be->be_f_offset = end; in __ext_tree_remove()
222 if (be->be_state != PNFS_BLOCK_NONE_DATA) { in __ext_tree_remove()
223 be->be_v_offset = in __ext_tree_remove()
226 be->be_length = len2; in __ext_tree_remove()
230 be->be_length = len1; in __ext_tree_remove()
231 be = ext_tree_next(be); in __ext_tree_remove()
234 while (be && ext_f_end(be) <= end) { in __ext_tree_remove()
235 struct pnfs_block_extent *next = ext_tree_next(be); in __ext_tree_remove()
237 rb_erase(&be->be_node, root); in __ext_tree_remove()
238 list_add_tail(&be->be_list, tmp); in __ext_tree_remove()
239 be = next; in __ext_tree_remove()
242 if (be && be->be_f_offset < end) { in __ext_tree_remove()
243 len1 = ext_f_end(be) - end; in __ext_tree_remove()
244 be->be_f_offset = end; in __ext_tree_remove()
245 if (be->be_state != PNFS_BLOCK_NONE_DATA) in __ext_tree_remove()
246 be->be_v_offset += be->be_length - len1; in __ext_tree_remove()
247 be->be_length = len1; in __ext_tree_remove()
257 struct pnfs_block_extent *be; in ext_tree_insert() local
277 be = __ext_tree_search(root, new->be_f_offset); in ext_tree_insert()
278 if (!be || be->be_f_offset >= ext_f_end(new)) { in ext_tree_insert()
280 } else if (new->be_f_offset >= be->be_f_offset) { in ext_tree_insert()
281 if (ext_f_end(new) <= ext_f_end(be)) { in ext_tree_insert()
285 sector_t new_len = ext_f_end(new) - ext_f_end(be); in ext_tree_insert()
293 } else if (ext_f_end(new) <= ext_f_end(be)) { in ext_tree_insert()
294 new->be_length = be->be_f_offset - new->be_f_offset; in ext_tree_insert()
298 sector_t new_len = ext_f_end(new) - ext_f_end(be); in ext_tree_insert()
307 split->be_length = be->be_f_offset - split->be_f_offset; in ext_tree_insert()
326 struct pnfs_block_extent *be; in __ext_tree_lookup() local
330 be = ext_node(node); in __ext_tree_lookup()
331 if (isect < be->be_f_offset) in __ext_tree_lookup()
333 else if (isect >= ext_f_end(be)) in __ext_tree_lookup()
336 *ret = *be; in __ext_tree_lookup()
380 ext_tree_split(struct rb_root *root, struct pnfs_block_extent *be, in ext_tree_split() argument
384 sector_t orig_len = be->be_length; in ext_tree_split()
390 be->be_length = split - be->be_f_offset; in ext_tree_split()
393 if (be->be_state != PNFS_BLOCK_NONE_DATA) in ext_tree_split()
394 new->be_v_offset = be->be_v_offset + be->be_length; in ext_tree_split()
395 new->be_length = orig_len - be->be_length; in ext_tree_split()
396 new->be_state = be->be_state; in ext_tree_split()
397 new->be_tag = be->be_tag; in ext_tree_split()
398 new->be_device = nfs4_get_deviceid(be->be_device); in ext_tree_split()
410 struct pnfs_block_extent *be; in ext_tree_mark_written() local
425 for (be = __ext_tree_search(root, start); be; be = ext_tree_next(be)) { in ext_tree_mark_written()
426 if (be->be_f_offset >= end) in ext_tree_mark_written()
429 if (be->be_state != PNFS_BLOCK_INVALID_DATA || be->be_tag) in ext_tree_mark_written()
432 if (be->be_f_offset < start) { in ext_tree_mark_written()
433 struct pnfs_block_extent *left = ext_tree_prev(be); in ext_tree_mark_written()
435 if (left && ext_can_merge(left, be)) { in ext_tree_mark_written()
436 sector_t diff = start - be->be_f_offset; in ext_tree_mark_written()
440 be->be_f_offset += diff; in ext_tree_mark_written()
441 be->be_v_offset += diff; in ext_tree_mark_written()
442 be->be_length -= diff; in ext_tree_mark_written()
444 err = ext_tree_split(root, be, start); in ext_tree_mark_written()
450 if (ext_f_end(be) > end) { in ext_tree_mark_written()
451 struct pnfs_block_extent *right = ext_tree_next(be); in ext_tree_mark_written()
453 if (right && ext_can_merge(be, right)) { in ext_tree_mark_written()
454 sector_t diff = end - be->be_f_offset; in ext_tree_mark_written()
456 be->be_length -= diff; in ext_tree_mark_written()
462 err = ext_tree_split(root, be, end); in ext_tree_mark_written()
468 if (be->be_f_offset >= start && ext_f_end(be) <= end) { in ext_tree_mark_written()
469 be->be_tag = EXTENT_WRITTEN; in ext_tree_mark_written()
470 be = ext_try_to_merge_left(root, be); in ext_tree_mark_written()
471 be = ext_try_to_merge_right(root, be); in ext_tree_mark_written()
506 static __be32 *encode_block_extent(struct pnfs_block_extent *be, __be32 *p) in encode_block_extent() argument
508 p = xdr_encode_opaque_fixed(p, be->be_device->deviceid.data, in encode_block_extent()
510 p = xdr_encode_hyper(p, be->be_f_offset << SECTOR_SHIFT); in encode_block_extent()
511 p = xdr_encode_hyper(p, be->be_length << SECTOR_SHIFT); in encode_block_extent()
517 static __be32 *encode_scsi_range(struct pnfs_block_extent *be, __be32 *p) in encode_scsi_range() argument
519 p = xdr_encode_hyper(p, be->be_f_offset << SECTOR_SHIFT); in encode_scsi_range()
520 return xdr_encode_hyper(p, be->be_length << SECTOR_SHIFT); in encode_scsi_range()
526 struct pnfs_block_extent *be; in ext_tree_encode_commit() local
530 for (be = ext_tree_first(&bl->bl_ext_rw); be; be = ext_tree_next(be)) { in ext_tree_encode_commit()
531 if (be->be_state != PNFS_BLOCK_INVALID_DATA || in ext_tree_encode_commit()
532 be->be_tag != EXTENT_WRITTEN) in ext_tree_encode_commit()
543 p = encode_scsi_range(be, p); in ext_tree_encode_commit()
545 p = encode_block_extent(be, p); in ext_tree_encode_commit()
546 be->be_tag = EXTENT_COMMITTING; in ext_tree_encode_commit()
619 struct pnfs_block_extent *be; in ext_tree_mark_committed() local
626 for (be = ext_tree_first(root); be; be = ext_tree_next(be)) { in ext_tree_mark_committed()
627 if (be->be_state != PNFS_BLOCK_INVALID_DATA || in ext_tree_mark_committed()
628 be->be_tag != EXTENT_COMMITTING) in ext_tree_mark_committed()
637 be->be_tag = EXTENT_WRITTEN; in ext_tree_mark_committed()
639 be->be_state = PNFS_BLOCK_READWRITE_DATA; in ext_tree_mark_committed()
640 be->be_tag = 0; in ext_tree_mark_committed()
643 be = ext_try_to_merge_left(root, be); in ext_tree_mark_committed()
644 be = ext_try_to_merge_right(root, be); in ext_tree_mark_committed()