Lines Matching refs:entry
21 static u64 entry_end(struct btrfs_ordered_extent *entry) in entry_end() argument
23 if (entry->file_offset + entry->len < entry->file_offset) in entry_end()
25 return entry->file_offset + entry->len; in entry_end()
36 struct btrfs_ordered_extent *entry; in tree_insert() local
40 entry = rb_entry(parent, struct btrfs_ordered_extent, rb_node); in tree_insert()
42 if (file_offset < entry->file_offset) in tree_insert()
44 else if (file_offset >= entry_end(entry)) in tree_insert()
73 struct btrfs_ordered_extent *entry; in __tree_search() local
77 entry = rb_entry(n, struct btrfs_ordered_extent, rb_node); in __tree_search()
79 prev_entry = entry; in __tree_search()
81 if (file_offset < entry->file_offset) in __tree_search()
83 else if (file_offset >= entry_end(entry)) in __tree_search()
120 static int offset_in_entry(struct btrfs_ordered_extent *entry, u64 file_offset) in offset_in_entry() argument
122 if (file_offset < entry->file_offset || in offset_in_entry()
123 entry->file_offset + entry->len <= file_offset) in offset_in_entry()
128 static int range_overlaps(struct btrfs_ordered_extent *entry, u64 file_offset, in range_overlaps() argument
131 if (file_offset + len <= entry->file_offset || in range_overlaps()
132 entry->file_offset + entry->len <= file_offset) in range_overlaps()
147 struct btrfs_ordered_extent *entry; in tree_search() local
150 entry = rb_entry(tree->last, struct btrfs_ordered_extent, in tree_search()
152 if (offset_in_entry(entry, file_offset)) in tree_search()
182 struct btrfs_ordered_extent *entry; in __btrfs_add_ordered_extent() local
185 entry = kmem_cache_zalloc(btrfs_ordered_extent_cache, GFP_NOFS); in __btrfs_add_ordered_extent()
186 if (!entry) in __btrfs_add_ordered_extent()
189 entry->file_offset = file_offset; in __btrfs_add_ordered_extent()
190 entry->start = start; in __btrfs_add_ordered_extent()
191 entry->len = len; in __btrfs_add_ordered_extent()
192 entry->disk_len = disk_len; in __btrfs_add_ordered_extent()
193 entry->bytes_left = len; in __btrfs_add_ordered_extent()
194 entry->inode = igrab(inode); in __btrfs_add_ordered_extent()
195 entry->compress_type = compress_type; in __btrfs_add_ordered_extent()
196 entry->truncated_len = (u64)-1; in __btrfs_add_ordered_extent()
198 set_bit(type, &entry->flags); in __btrfs_add_ordered_extent()
203 set_bit(BTRFS_ORDERED_DIRECT, &entry->flags); in __btrfs_add_ordered_extent()
207 refcount_set(&entry->refs, 1); in __btrfs_add_ordered_extent()
208 init_waitqueue_head(&entry->wait); in __btrfs_add_ordered_extent()
209 INIT_LIST_HEAD(&entry->list); in __btrfs_add_ordered_extent()
210 INIT_LIST_HEAD(&entry->root_extent_list); in __btrfs_add_ordered_extent()
211 INIT_LIST_HEAD(&entry->work_list); in __btrfs_add_ordered_extent()
212 init_completion(&entry->completion); in __btrfs_add_ordered_extent()
213 INIT_LIST_HEAD(&entry->log_list); in __btrfs_add_ordered_extent()
214 INIT_LIST_HEAD(&entry->trans_list); in __btrfs_add_ordered_extent()
216 trace_btrfs_ordered_extent_add(inode, entry); in __btrfs_add_ordered_extent()
220 &entry->rb_node); in __btrfs_add_ordered_extent()
226 list_add_tail(&entry->root_extent_list, in __btrfs_add_ordered_extent()
279 void btrfs_add_ordered_sum(struct btrfs_ordered_extent *entry, in btrfs_add_ordered_sum() argument
284 tree = &BTRFS_I(entry->inode)->ordered_tree; in btrfs_add_ordered_sum()
286 list_add_tail(&sum->list, &entry->list); in btrfs_add_ordered_sum()
309 struct btrfs_ordered_extent *entry = NULL; in btrfs_dec_test_first_ordered_pending() local
324 entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); in btrfs_dec_test_first_ordered_pending()
325 if (!offset_in_entry(entry, *file_offset)) { in btrfs_dec_test_first_ordered_pending()
330 dec_start = max(*file_offset, entry->file_offset); in btrfs_dec_test_first_ordered_pending()
331 dec_end = min(*file_offset + io_size, entry->file_offset + in btrfs_dec_test_first_ordered_pending()
332 entry->len); in btrfs_dec_test_first_ordered_pending()
339 if (to_dec > entry->bytes_left) { in btrfs_dec_test_first_ordered_pending()
342 entry->bytes_left, to_dec); in btrfs_dec_test_first_ordered_pending()
344 entry->bytes_left -= to_dec; in btrfs_dec_test_first_ordered_pending()
346 set_bit(BTRFS_ORDERED_IOERR, &entry->flags); in btrfs_dec_test_first_ordered_pending()
348 if (entry->bytes_left == 0) { in btrfs_dec_test_first_ordered_pending()
349 ret = test_and_set_bit(BTRFS_ORDERED_IO_DONE, &entry->flags); in btrfs_dec_test_first_ordered_pending()
351 cond_wake_up_nomb(&entry->wait); in btrfs_dec_test_first_ordered_pending()
356 if (!ret && cached && entry) { in btrfs_dec_test_first_ordered_pending()
357 *cached = entry; in btrfs_dec_test_first_ordered_pending()
358 refcount_inc(&entry->refs); in btrfs_dec_test_first_ordered_pending()
379 struct btrfs_ordered_extent *entry = NULL; in btrfs_dec_test_ordered_pending() local
386 entry = *cached; in btrfs_dec_test_ordered_pending()
396 entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); in btrfs_dec_test_ordered_pending()
398 if (!offset_in_entry(entry, file_offset)) { in btrfs_dec_test_ordered_pending()
403 if (io_size > entry->bytes_left) { in btrfs_dec_test_ordered_pending()
406 entry->bytes_left, io_size); in btrfs_dec_test_ordered_pending()
408 entry->bytes_left -= io_size; in btrfs_dec_test_ordered_pending()
410 set_bit(BTRFS_ORDERED_IOERR, &entry->flags); in btrfs_dec_test_ordered_pending()
412 if (entry->bytes_left == 0) { in btrfs_dec_test_ordered_pending()
413 ret = test_and_set_bit(BTRFS_ORDERED_IO_DONE, &entry->flags); in btrfs_dec_test_ordered_pending()
415 cond_wake_up_nomb(&entry->wait); in btrfs_dec_test_ordered_pending()
420 if (!ret && cached && entry) { in btrfs_dec_test_ordered_pending()
421 *cached = entry; in btrfs_dec_test_ordered_pending()
422 refcount_inc(&entry->refs); in btrfs_dec_test_ordered_pending()
432 void btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry) in btrfs_put_ordered_extent() argument
437 trace_btrfs_ordered_extent_put(entry->inode, entry); in btrfs_put_ordered_extent()
439 if (refcount_dec_and_test(&entry->refs)) { in btrfs_put_ordered_extent()
440 ASSERT(list_empty(&entry->log_list)); in btrfs_put_ordered_extent()
441 ASSERT(list_empty(&entry->trans_list)); in btrfs_put_ordered_extent()
442 ASSERT(list_empty(&entry->root_extent_list)); in btrfs_put_ordered_extent()
443 ASSERT(RB_EMPTY_NODE(&entry->rb_node)); in btrfs_put_ordered_extent()
444 if (entry->inode) in btrfs_put_ordered_extent()
445 btrfs_add_delayed_iput(entry->inode); in btrfs_put_ordered_extent()
446 while (!list_empty(&entry->list)) { in btrfs_put_ordered_extent()
447 cur = entry->list.next; in btrfs_put_ordered_extent()
452 kmem_cache_free(btrfs_ordered_extent_cache, entry); in btrfs_put_ordered_extent()
461 struct btrfs_ordered_extent *entry) in btrfs_remove_ordered_extent() argument
474 btrfs_delalloc_release_metadata(btrfs_inode, entry->len, false); in btrfs_remove_ordered_extent()
476 if (test_bit(BTRFS_ORDERED_DIRECT, &entry->flags)) in btrfs_remove_ordered_extent()
477 percpu_counter_add_batch(&fs_info->dio_bytes, -entry->len, in btrfs_remove_ordered_extent()
482 node = &entry->rb_node; in btrfs_remove_ordered_extent()
487 set_bit(BTRFS_ORDERED_COMPLETE, &entry->flags); in btrfs_remove_ordered_extent()
491 list_del_init(&entry->root_extent_list); in btrfs_remove_ordered_extent()
494 trace_btrfs_ordered_extent_remove(inode, entry); in btrfs_remove_ordered_extent()
503 wake_up(&entry->wait); in btrfs_remove_ordered_extent()
622 struct btrfs_ordered_extent *entry, in btrfs_start_ordered_extent() argument
625 u64 start = entry->file_offset; in btrfs_start_ordered_extent()
626 u64 end = start + entry->len - 1; in btrfs_start_ordered_extent()
628 trace_btrfs_ordered_extent_start(inode, entry); in btrfs_start_ordered_extent()
635 if (!test_bit(BTRFS_ORDERED_DIRECT, &entry->flags)) in btrfs_start_ordered_extent()
638 wait_event(entry->wait, test_bit(BTRFS_ORDERED_COMPLETE, in btrfs_start_ordered_extent()
639 &entry->flags)); in btrfs_start_ordered_extent()
712 struct btrfs_ordered_extent *entry = NULL; in btrfs_lookup_ordered_extent() local
720 entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); in btrfs_lookup_ordered_extent()
721 if (!offset_in_entry(entry, file_offset)) in btrfs_lookup_ordered_extent()
722 entry = NULL; in btrfs_lookup_ordered_extent()
723 if (entry) in btrfs_lookup_ordered_extent()
724 refcount_inc(&entry->refs); in btrfs_lookup_ordered_extent()
727 return entry; in btrfs_lookup_ordered_extent()
738 struct btrfs_ordered_extent *entry = NULL; in btrfs_lookup_ordered_range() local
750 entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); in btrfs_lookup_ordered_range()
751 if (range_overlaps(entry, file_offset, len)) in btrfs_lookup_ordered_range()
754 if (entry->file_offset >= file_offset + len) { in btrfs_lookup_ordered_range()
755 entry = NULL; in btrfs_lookup_ordered_range()
758 entry = NULL; in btrfs_lookup_ordered_range()
764 if (entry) in btrfs_lookup_ordered_range()
765 refcount_inc(&entry->refs); in btrfs_lookup_ordered_range()
767 return entry; in btrfs_lookup_ordered_range()
779 struct btrfs_ordered_extent *entry = NULL; in btrfs_lookup_first_ordered_extent() local
787 entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); in btrfs_lookup_first_ordered_extent()
788 refcount_inc(&entry->refs); in btrfs_lookup_first_ordered_extent()
791 return entry; in btrfs_lookup_first_ordered_extent()