Lines Matching +full:root +full:- +full:node
1 // SPDX-License-Identifier: GPL-2.0
13 #include "delayed-inode.h"
14 #include "disk-io.h"
18 #include "inode-item.h"
19 #include "space-info.h"
21 #include "file-item.h"
33 return -ENOMEM; in btrfs_delayed_inode_init()
44 atomic_set(&delayed_root->items, 0); in btrfs_init_delayed_root()
45 atomic_set(&delayed_root->items_seq, 0); in btrfs_init_delayed_root()
46 delayed_root->nodes = 0; in btrfs_init_delayed_root()
47 spin_lock_init(&delayed_root->lock); in btrfs_init_delayed_root()
48 init_waitqueue_head(&delayed_root->wait); in btrfs_init_delayed_root()
49 INIT_LIST_HEAD(&delayed_root->node_list); in btrfs_init_delayed_root()
50 INIT_LIST_HEAD(&delayed_root->prepare_list); in btrfs_init_delayed_root()
55 struct btrfs_root *root, u64 inode_id) in btrfs_init_delayed_node() argument
57 delayed_node->root = root; in btrfs_init_delayed_node()
58 delayed_node->inode_id = inode_id; in btrfs_init_delayed_node()
59 refcount_set(&delayed_node->refs, 0); in btrfs_init_delayed_node()
60 delayed_node->ins_root = RB_ROOT_CACHED; in btrfs_init_delayed_node()
61 delayed_node->del_root = RB_ROOT_CACHED; in btrfs_init_delayed_node()
62 mutex_init(&delayed_node->mutex); in btrfs_init_delayed_node()
63 INIT_LIST_HEAD(&delayed_node->n_list); in btrfs_init_delayed_node()
64 INIT_LIST_HEAD(&delayed_node->p_list); in btrfs_init_delayed_node()
70 struct btrfs_root *root = btrfs_inode->root; in btrfs_get_delayed_node() local
72 struct btrfs_delayed_node *node; in btrfs_get_delayed_node() local
74 node = READ_ONCE(btrfs_inode->delayed_node); in btrfs_get_delayed_node()
75 if (node) { in btrfs_get_delayed_node()
76 refcount_inc(&node->refs); in btrfs_get_delayed_node()
77 return node; in btrfs_get_delayed_node()
80 xa_lock(&root->delayed_nodes); in btrfs_get_delayed_node()
81 node = xa_load(&root->delayed_nodes, ino); in btrfs_get_delayed_node()
83 if (node) { in btrfs_get_delayed_node()
84 if (btrfs_inode->delayed_node) { in btrfs_get_delayed_node()
85 refcount_inc(&node->refs); /* can be accessed */ in btrfs_get_delayed_node()
86 BUG_ON(btrfs_inode->delayed_node != node); in btrfs_get_delayed_node()
87 xa_unlock(&root->delayed_nodes); in btrfs_get_delayed_node()
88 return node; in btrfs_get_delayed_node()
93 * this node from the xarray. In this case, the refcount in btrfs_get_delayed_node()
103 * If this node is properly in the xarray, we want to bump the in btrfs_get_delayed_node()
107 if (refcount_inc_not_zero(&node->refs)) { in btrfs_get_delayed_node()
108 refcount_inc(&node->refs); in btrfs_get_delayed_node()
109 btrfs_inode->delayed_node = node; in btrfs_get_delayed_node()
111 node = NULL; in btrfs_get_delayed_node()
114 xa_unlock(&root->delayed_nodes); in btrfs_get_delayed_node()
115 return node; in btrfs_get_delayed_node()
117 xa_unlock(&root->delayed_nodes); in btrfs_get_delayed_node()
122 /* Will return either the node or PTR_ERR(-ENOMEM) */
126 struct btrfs_delayed_node *node; in btrfs_get_or_create_delayed_node() local
127 struct btrfs_root *root = btrfs_inode->root; in btrfs_get_or_create_delayed_node() local
133 node = btrfs_get_delayed_node(btrfs_inode); in btrfs_get_or_create_delayed_node()
134 if (node) in btrfs_get_or_create_delayed_node()
135 return node; in btrfs_get_or_create_delayed_node()
137 node = kmem_cache_zalloc(delayed_node_cache, GFP_NOFS); in btrfs_get_or_create_delayed_node()
138 if (!node) in btrfs_get_or_create_delayed_node()
139 return ERR_PTR(-ENOMEM); in btrfs_get_or_create_delayed_node()
140 btrfs_init_delayed_node(node, root, ino); in btrfs_get_or_create_delayed_node()
143 refcount_set(&node->refs, 2); in btrfs_get_or_create_delayed_node()
146 ret = xa_reserve(&root->delayed_nodes, ino, GFP_NOFS); in btrfs_get_or_create_delayed_node()
147 if (ret == -ENOMEM) { in btrfs_get_or_create_delayed_node()
148 kmem_cache_free(delayed_node_cache, node); in btrfs_get_or_create_delayed_node()
149 return ERR_PTR(-ENOMEM); in btrfs_get_or_create_delayed_node()
151 xa_lock(&root->delayed_nodes); in btrfs_get_or_create_delayed_node()
152 ptr = xa_load(&root->delayed_nodes, ino); in btrfs_get_or_create_delayed_node()
155 xa_unlock(&root->delayed_nodes); in btrfs_get_or_create_delayed_node()
156 kmem_cache_free(delayed_node_cache, node); in btrfs_get_or_create_delayed_node()
157 node = NULL; in btrfs_get_or_create_delayed_node()
160 ptr = __xa_store(&root->delayed_nodes, ino, node, GFP_ATOMIC); in btrfs_get_or_create_delayed_node()
161 ASSERT(xa_err(ptr) != -EINVAL); in btrfs_get_or_create_delayed_node()
162 ASSERT(xa_err(ptr) != -ENOMEM); in btrfs_get_or_create_delayed_node()
164 btrfs_inode->delayed_node = node; in btrfs_get_or_create_delayed_node()
165 xa_unlock(&root->delayed_nodes); in btrfs_get_or_create_delayed_node()
167 return node; in btrfs_get_or_create_delayed_node()
171 * Call it when holding delayed_node->mutex
173 * If mod = 1, add this node into the prepared list.
175 static void btrfs_queue_delayed_node(struct btrfs_delayed_root *root, in btrfs_queue_delayed_node() argument
176 struct btrfs_delayed_node *node, in btrfs_queue_delayed_node() argument
179 spin_lock(&root->lock); in btrfs_queue_delayed_node()
180 if (test_bit(BTRFS_DELAYED_NODE_IN_LIST, &node->flags)) { in btrfs_queue_delayed_node()
181 if (!list_empty(&node->p_list)) in btrfs_queue_delayed_node()
182 list_move_tail(&node->p_list, &root->prepare_list); in btrfs_queue_delayed_node()
184 list_add_tail(&node->p_list, &root->prepare_list); in btrfs_queue_delayed_node()
186 list_add_tail(&node->n_list, &root->node_list); in btrfs_queue_delayed_node()
187 list_add_tail(&node->p_list, &root->prepare_list); in btrfs_queue_delayed_node()
188 refcount_inc(&node->refs); /* inserted into list */ in btrfs_queue_delayed_node()
189 root->nodes++; in btrfs_queue_delayed_node()
190 set_bit(BTRFS_DELAYED_NODE_IN_LIST, &node->flags); in btrfs_queue_delayed_node()
192 spin_unlock(&root->lock); in btrfs_queue_delayed_node()
195 /* Call it when holding delayed_node->mutex */
196 static void btrfs_dequeue_delayed_node(struct btrfs_delayed_root *root, in btrfs_dequeue_delayed_node() argument
197 struct btrfs_delayed_node *node) in btrfs_dequeue_delayed_node() argument
199 spin_lock(&root->lock); in btrfs_dequeue_delayed_node()
200 if (test_bit(BTRFS_DELAYED_NODE_IN_LIST, &node->flags)) { in btrfs_dequeue_delayed_node()
201 root->nodes--; in btrfs_dequeue_delayed_node()
202 refcount_dec(&node->refs); /* not in the list */ in btrfs_dequeue_delayed_node()
203 list_del_init(&node->n_list); in btrfs_dequeue_delayed_node()
204 if (!list_empty(&node->p_list)) in btrfs_dequeue_delayed_node()
205 list_del_init(&node->p_list); in btrfs_dequeue_delayed_node()
206 clear_bit(BTRFS_DELAYED_NODE_IN_LIST, &node->flags); in btrfs_dequeue_delayed_node()
208 spin_unlock(&root->lock); in btrfs_dequeue_delayed_node()
215 struct btrfs_delayed_node *node = NULL; in btrfs_first_delayed_node() local
217 spin_lock(&delayed_root->lock); in btrfs_first_delayed_node()
218 if (list_empty(&delayed_root->node_list)) in btrfs_first_delayed_node()
221 p = delayed_root->node_list.next; in btrfs_first_delayed_node()
222 node = list_entry(p, struct btrfs_delayed_node, n_list); in btrfs_first_delayed_node()
223 refcount_inc(&node->refs); in btrfs_first_delayed_node()
225 spin_unlock(&delayed_root->lock); in btrfs_first_delayed_node()
227 return node; in btrfs_first_delayed_node()
231 struct btrfs_delayed_node *node) in btrfs_next_delayed_node() argument
237 delayed_root = node->root->fs_info->delayed_root; in btrfs_next_delayed_node()
238 spin_lock(&delayed_root->lock); in btrfs_next_delayed_node()
239 if (!test_bit(BTRFS_DELAYED_NODE_IN_LIST, &node->flags)) { in btrfs_next_delayed_node()
241 if (list_empty(&delayed_root->node_list)) in btrfs_next_delayed_node()
243 p = delayed_root->node_list.next; in btrfs_next_delayed_node()
244 } else if (list_is_last(&node->n_list, &delayed_root->node_list)) in btrfs_next_delayed_node()
247 p = node->n_list.next; in btrfs_next_delayed_node()
250 refcount_inc(&next->refs); in btrfs_next_delayed_node()
252 spin_unlock(&delayed_root->lock); in btrfs_next_delayed_node()
266 delayed_root = delayed_node->root->fs_info->delayed_root; in __btrfs_release_delayed_node()
268 mutex_lock(&delayed_node->mutex); in __btrfs_release_delayed_node()
269 if (delayed_node->count) in __btrfs_release_delayed_node()
273 mutex_unlock(&delayed_node->mutex); in __btrfs_release_delayed_node()
275 if (refcount_dec_and_test(&delayed_node->refs)) { in __btrfs_release_delayed_node()
276 struct btrfs_root *root = delayed_node->root; in __btrfs_release_delayed_node() local
278 xa_erase(&root->delayed_nodes, delayed_node->inode_id); in __btrfs_release_delayed_node()
283 ASSERT(refcount_read(&delayed_node->refs) == 0); in __btrfs_release_delayed_node()
288 static inline void btrfs_release_delayed_node(struct btrfs_delayed_node *node) in btrfs_release_delayed_node() argument
290 __btrfs_release_delayed_node(node, 0); in btrfs_release_delayed_node()
297 struct btrfs_delayed_node *node = NULL; in btrfs_first_prepared_delayed_node() local
299 spin_lock(&delayed_root->lock); in btrfs_first_prepared_delayed_node()
300 if (list_empty(&delayed_root->prepare_list)) in btrfs_first_prepared_delayed_node()
303 p = delayed_root->prepare_list.next; in btrfs_first_prepared_delayed_node()
305 node = list_entry(p, struct btrfs_delayed_node, p_list); in btrfs_first_prepared_delayed_node()
306 refcount_inc(&node->refs); in btrfs_first_prepared_delayed_node()
308 spin_unlock(&delayed_root->lock); in btrfs_first_prepared_delayed_node()
310 return node; in btrfs_first_prepared_delayed_node()
314 struct btrfs_delayed_node *node) in btrfs_release_prepared_delayed_node() argument
316 __btrfs_release_delayed_node(node, 1); in btrfs_release_prepared_delayed_node()
320 struct btrfs_delayed_node *node, in btrfs_alloc_delayed_item() argument
327 item->data_len = data_len; in btrfs_alloc_delayed_item()
328 item->type = type; in btrfs_alloc_delayed_item()
329 item->bytes_reserved = 0; in btrfs_alloc_delayed_item()
330 item->delayed_node = node; in btrfs_alloc_delayed_item()
331 RB_CLEAR_NODE(&item->rb_node); in btrfs_alloc_delayed_item()
332 INIT_LIST_HEAD(&item->log_list); in btrfs_alloc_delayed_item()
333 item->logged = false; in btrfs_alloc_delayed_item()
334 refcount_set(&item->refs, 1); in btrfs_alloc_delayed_item()
342 * @delayed_node: pointer to the delayed node
349 struct rb_root *root, in __btrfs_lookup_delayed_item() argument
352 struct rb_node *node = root->rb_node; in __btrfs_lookup_delayed_item() local
355 while (node) { in __btrfs_lookup_delayed_item()
356 delayed_item = rb_entry(node, struct btrfs_delayed_item, in __btrfs_lookup_delayed_item()
358 if (delayed_item->index < index) in __btrfs_lookup_delayed_item()
359 node = node->rb_right; in __btrfs_lookup_delayed_item()
360 else if (delayed_item->index > index) in __btrfs_lookup_delayed_item()
361 node = node->rb_left; in __btrfs_lookup_delayed_item()
372 struct rb_node **p, *node; in __btrfs_add_delayed_item() local
374 struct rb_root_cached *root; in __btrfs_add_delayed_item() local
378 if (ins->type == BTRFS_DELAYED_INSERTION_ITEM) in __btrfs_add_delayed_item()
379 root = &delayed_node->ins_root; in __btrfs_add_delayed_item()
381 root = &delayed_node->del_root; in __btrfs_add_delayed_item()
383 p = &root->rb_root.rb_node; in __btrfs_add_delayed_item()
384 node = &ins->rb_node; in __btrfs_add_delayed_item()
391 if (item->index < ins->index) { in __btrfs_add_delayed_item()
392 p = &(*p)->rb_right; in __btrfs_add_delayed_item()
394 } else if (item->index > ins->index) { in __btrfs_add_delayed_item()
395 p = &(*p)->rb_left; in __btrfs_add_delayed_item()
397 return -EEXIST; in __btrfs_add_delayed_item()
401 rb_link_node(node, parent_node, p); in __btrfs_add_delayed_item()
402 rb_insert_color_cached(node, root, leftmost); in __btrfs_add_delayed_item()
404 if (ins->type == BTRFS_DELAYED_INSERTION_ITEM && in __btrfs_add_delayed_item()
405 ins->index >= delayed_node->index_cnt) in __btrfs_add_delayed_item()
406 delayed_node->index_cnt = ins->index + 1; in __btrfs_add_delayed_item()
408 delayed_node->count++; in __btrfs_add_delayed_item()
409 atomic_inc(&delayed_node->root->fs_info->delayed_root->items); in __btrfs_add_delayed_item()
415 int seq = atomic_inc_return(&delayed_root->items_seq); in finish_one_item()
418 if ((atomic_dec_return(&delayed_root->items) < in finish_one_item()
420 cond_wake_up_nomb(&delayed_root->wait); in finish_one_item()
425 struct btrfs_delayed_node *delayed_node = delayed_item->delayed_node; in __btrfs_remove_delayed_item()
426 struct rb_root_cached *root; in __btrfs_remove_delayed_item() local
430 if (RB_EMPTY_NODE(&delayed_item->rb_node)) in __btrfs_remove_delayed_item()
433 /* If it's in a rbtree, then we need to have delayed node locked. */ in __btrfs_remove_delayed_item()
434 lockdep_assert_held(&delayed_node->mutex); in __btrfs_remove_delayed_item()
436 delayed_root = delayed_node->root->fs_info->delayed_root; in __btrfs_remove_delayed_item()
438 if (delayed_item->type == BTRFS_DELAYED_INSERTION_ITEM) in __btrfs_remove_delayed_item()
439 root = &delayed_node->ins_root; in __btrfs_remove_delayed_item()
441 root = &delayed_node->del_root; in __btrfs_remove_delayed_item()
443 rb_erase_cached(&delayed_item->rb_node, root); in __btrfs_remove_delayed_item()
444 RB_CLEAR_NODE(&delayed_item->rb_node); in __btrfs_remove_delayed_item()
445 delayed_node->count--; in __btrfs_remove_delayed_item()
454 if (refcount_dec_and_test(&item->refs)) in btrfs_release_delayed_item()
465 p = rb_first_cached(&delayed_node->ins_root); in __btrfs_first_delayed_insertion_item()
478 p = rb_first_cached(&delayed_node->del_root); in __btrfs_first_delayed_deletion_item()
491 p = rb_next(&item->rb_node); in __btrfs_next_delayed_item()
503 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_delayed_item_reserve_metadata()
507 if (!trans->bytes_reserved) in btrfs_delayed_item_reserve_metadata()
510 src_rsv = trans->block_rsv; in btrfs_delayed_item_reserve_metadata()
511 dst_rsv = &fs_info->delayed_block_rsv; in btrfs_delayed_item_reserve_metadata()
523 item->delayed_node->inode_id, in btrfs_delayed_item_reserve_metadata()
528 * node's curr_index_batch_size and index_item_leaves fields. in btrfs_delayed_item_reserve_metadata()
530 if (item->type == BTRFS_DELAYED_DELETION_ITEM) in btrfs_delayed_item_reserve_metadata()
531 item->bytes_reserved = num_bytes; in btrfs_delayed_item_reserve_metadata()
537 static void btrfs_delayed_item_release_metadata(struct btrfs_root *root, in btrfs_delayed_item_release_metadata() argument
541 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_delayed_item_release_metadata()
543 if (!item->bytes_reserved) in btrfs_delayed_item_release_metadata()
546 rsv = &fs_info->delayed_block_rsv; in btrfs_delayed_item_release_metadata()
552 item->delayed_node->inode_id, in btrfs_delayed_item_release_metadata()
553 item->bytes_reserved, 0); in btrfs_delayed_item_release_metadata()
554 btrfs_block_rsv_release(fs_info, rsv, item->bytes_reserved, NULL); in btrfs_delayed_item_release_metadata()
557 static void btrfs_delayed_item_release_leaves(struct btrfs_delayed_node *node, in btrfs_delayed_item_release_leaves() argument
560 struct btrfs_fs_info *fs_info = node->root->fs_info; in btrfs_delayed_item_release_leaves()
564 if (test_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags)) in btrfs_delayed_item_release_leaves()
567 trace_btrfs_space_reservation(fs_info, "delayed_item", node->inode_id, in btrfs_delayed_item_release_leaves()
569 btrfs_block_rsv_release(fs_info, &fs_info->delayed_block_rsv, bytes, NULL); in btrfs_delayed_item_release_leaves()
574 struct btrfs_root *root, in btrfs_delayed_inode_reserve_metadata() argument
575 struct btrfs_delayed_node *node) in btrfs_delayed_inode_reserve_metadata() argument
577 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_delayed_inode_reserve_metadata()
583 src_rsv = trans->block_rsv; in btrfs_delayed_inode_reserve_metadata()
584 dst_rsv = &fs_info->delayed_block_rsv; in btrfs_delayed_inode_reserve_metadata()
597 if (!src_rsv || (!trans->bytes_reserved && in btrfs_delayed_inode_reserve_metadata()
598 src_rsv->type != BTRFS_BLOCK_RSV_DELALLOC)) { in btrfs_delayed_inode_reserve_metadata()
599 ret = btrfs_qgroup_reserve_meta(root, num_bytes, in btrfs_delayed_inode_reserve_metadata()
605 /* NO_FLUSH could only fail with -ENOSPC */ in btrfs_delayed_inode_reserve_metadata()
606 ASSERT(ret == 0 || ret == -ENOSPC); in btrfs_delayed_inode_reserve_metadata()
608 btrfs_qgroup_free_meta_prealloc(root, num_bytes); in btrfs_delayed_inode_reserve_metadata()
615 node->inode_id, num_bytes, 1); in btrfs_delayed_inode_reserve_metadata()
616 node->bytes_reserved = num_bytes; in btrfs_delayed_inode_reserve_metadata()
623 struct btrfs_delayed_node *node, in btrfs_delayed_inode_release_metadata() argument
628 if (!node->bytes_reserved) in btrfs_delayed_inode_release_metadata()
631 rsv = &fs_info->delayed_block_rsv; in btrfs_delayed_inode_release_metadata()
633 node->inode_id, node->bytes_reserved, 0); in btrfs_delayed_inode_release_metadata()
634 btrfs_block_rsv_release(fs_info, rsv, node->bytes_reserved, NULL); in btrfs_delayed_inode_release_metadata()
636 btrfs_qgroup_free_meta_prealloc(node->root, in btrfs_delayed_inode_release_metadata()
637 node->bytes_reserved); in btrfs_delayed_inode_release_metadata()
639 btrfs_qgroup_convert_reserved_meta(node->root, in btrfs_delayed_inode_release_metadata()
640 node->bytes_reserved); in btrfs_delayed_inode_release_metadata()
641 node->bytes_reserved = 0; in btrfs_delayed_inode_release_metadata()
655 struct btrfs_root *root, in btrfs_insert_delayed_item() argument
659 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_insert_delayed_item()
660 struct btrfs_delayed_node *node = first_item->delayed_node; in btrfs_insert_delayed_item() local
667 const u32 first_data_size = first_item->data_len; in btrfs_insert_delayed_item()
673 lockdep_assert_held(&node->mutex); in btrfs_insert_delayed_item()
684 if (test_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags)) in btrfs_insert_delayed_item()
693 ASSERT(first_item->bytes_reserved == 0); in btrfs_insert_delayed_item()
695 list_add_tail(&first_item->tree_list, &item_list); in btrfs_insert_delayed_item()
712 if (continuous_keys_only && (next->index != curr->index + 1)) in btrfs_insert_delayed_item()
715 ASSERT(next->bytes_reserved == 0); in btrfs_insert_delayed_item()
717 next_size = next->data_len + sizeof(struct btrfs_item); in btrfs_insert_delayed_item()
721 list_add_tail(&next->tree_list, &item_list); in btrfs_insert_delayed_item()
724 batch.total_data_size += next->data_len; in btrfs_insert_delayed_item()
729 first_key.objectid = node->inode_id; in btrfs_insert_delayed_item()
731 first_key.offset = first_item->index; in btrfs_insert_delayed_item()
742 ret = -ENOMEM; in btrfs_insert_delayed_item()
750 ins_keys[i].objectid = node->inode_id; in btrfs_insert_delayed_item()
752 ins_keys[i].offset = curr->index; in btrfs_insert_delayed_item()
753 ins_sizes[i] = curr->data_len; in btrfs_insert_delayed_item()
758 ret = btrfs_insert_empty_items(trans, root, path, &batch); in btrfs_insert_delayed_item()
765 data_ptr = btrfs_item_ptr(path->nodes[0], path->slots[0], char); in btrfs_insert_delayed_item()
766 write_extent_buffer(path->nodes[0], &curr->data, in btrfs_insert_delayed_item()
767 (unsigned long)data_ptr, curr->data_len); in btrfs_insert_delayed_item()
768 path->slots[0]++; in btrfs_insert_delayed_item()
778 ASSERT(node->index_item_leaves > 0); in btrfs_insert_delayed_item()
797 btrfs_delayed_item_release_leaves(node, 1); in btrfs_insert_delayed_item()
798 node->index_item_leaves--; in btrfs_insert_delayed_item()
802 * reserved leaves > 1 here - this happens when many dir index in btrfs_insert_delayed_item()
807 btrfs_delayed_item_release_leaves(node, node->index_item_leaves); in btrfs_insert_delayed_item()
808 node->index_item_leaves = 0; in btrfs_insert_delayed_item()
812 list_del(&curr->tree_list); in btrfs_insert_delayed_item()
822 struct btrfs_root *root, in btrfs_insert_delayed_items() argument
823 struct btrfs_delayed_node *node) in btrfs_insert_delayed_items() argument
830 mutex_lock(&node->mutex); in btrfs_insert_delayed_items()
831 curr = __btrfs_first_delayed_insertion_item(node); in btrfs_insert_delayed_items()
833 mutex_unlock(&node->mutex); in btrfs_insert_delayed_items()
836 ret = btrfs_insert_delayed_item(trans, root, path, curr); in btrfs_insert_delayed_items()
837 mutex_unlock(&node->mutex); in btrfs_insert_delayed_items()
844 struct btrfs_root *root, in btrfs_batch_delete_items() argument
848 const u64 ino = item->delayed_node->inode_id; in btrfs_batch_delete_items()
849 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_batch_delete_items()
851 struct extent_buffer *leaf = path->nodes[0]; in btrfs_batch_delete_items()
855 u64 total_reserved_size = item->bytes_reserved; in btrfs_batch_delete_items()
859 slot = path->slots[0]; in btrfs_batch_delete_items()
860 last_slot = btrfs_header_nritems(leaf) - 1; in btrfs_batch_delete_items()
867 return -ENOENT; in btrfs_batch_delete_items()
871 list_add_tail(&curr->tree_list, &batch_list); in btrfs_batch_delete_items()
875 * leaf - if so, we can add it to the batch of items to delete from the in btrfs_batch_delete_items()
889 key.offset != next->index) in btrfs_batch_delete_items()
893 list_add_tail(&curr->tree_list, &batch_list); in btrfs_batch_delete_items()
894 total_reserved_size += curr->bytes_reserved; in btrfs_batch_delete_items()
897 ret = btrfs_del_items(trans, root, path, path->slots[0], nitems); in btrfs_batch_delete_items()
909 btrfs_block_rsv_release(fs_info, &fs_info->delayed_block_rsv, in btrfs_batch_delete_items()
914 list_del(&curr->tree_list); in btrfs_batch_delete_items()
923 struct btrfs_root *root, in btrfs_delete_delayed_items() argument
924 struct btrfs_delayed_node *node) in btrfs_delete_delayed_items() argument
929 key.objectid = node->inode_id; in btrfs_delete_delayed_items()
935 mutex_lock(&node->mutex); in btrfs_delete_delayed_items()
936 item = __btrfs_first_delayed_deletion_item(node); in btrfs_delete_delayed_items()
938 mutex_unlock(&node->mutex); in btrfs_delete_delayed_items()
942 key.offset = item->index; in btrfs_delete_delayed_items()
943 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); in btrfs_delete_delayed_items()
963 ret = btrfs_batch_delete_items(trans, root, path, item); in btrfs_delete_delayed_items()
972 * need to add delayed items to this delayed node. in btrfs_delete_delayed_items()
974 mutex_unlock(&node->mutex); in btrfs_delete_delayed_items()
985 test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) { in btrfs_release_delayed_inode()
986 ASSERT(delayed_node->root); in btrfs_release_delayed_inode()
987 clear_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags); in btrfs_release_delayed_inode()
988 delayed_node->count--; in btrfs_release_delayed_inode()
990 delayed_root = delayed_node->root->fs_info->delayed_root; in btrfs_release_delayed_inode()
998 if (test_and_clear_bit(BTRFS_DELAYED_NODE_DEL_IREF, &delayed_node->flags)) { in btrfs_release_delayed_iref()
1001 ASSERT(delayed_node->root); in btrfs_release_delayed_iref()
1002 delayed_node->count--; in btrfs_release_delayed_iref()
1004 delayed_root = delayed_node->root->fs_info->delayed_root; in btrfs_release_delayed_iref()
1010 struct btrfs_root *root, in __btrfs_update_delayed_inode() argument
1012 struct btrfs_delayed_node *node) in __btrfs_update_delayed_inode() argument
1014 struct btrfs_fs_info *fs_info = root->fs_info; in __btrfs_update_delayed_inode()
1021 key.objectid = node->inode_id; in __btrfs_update_delayed_inode()
1025 if (test_bit(BTRFS_DELAYED_NODE_DEL_IREF, &node->flags)) in __btrfs_update_delayed_inode()
1026 mod = -1; in __btrfs_update_delayed_inode()
1030 ret = btrfs_lookup_inode(trans, root, path, &key, mod); in __btrfs_update_delayed_inode()
1032 ret = -ENOENT; in __btrfs_update_delayed_inode()
1036 leaf = path->nodes[0]; in __btrfs_update_delayed_inode()
1037 inode_item = btrfs_item_ptr(leaf, path->slots[0], in __btrfs_update_delayed_inode()
1039 write_extent_buffer(leaf, &node->inode_item, (unsigned long)inode_item, in __btrfs_update_delayed_inode()
1043 if (!test_bit(BTRFS_DELAYED_NODE_DEL_IREF, &node->flags)) in __btrfs_update_delayed_inode()
1053 if (path->slots[0] + 1 >= btrfs_header_nritems(leaf)) { in __btrfs_update_delayed_inode()
1054 key.objectid = node->inode_id; in __btrfs_update_delayed_inode()
1056 key.offset = (u64)-1; in __btrfs_update_delayed_inode()
1059 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); in __btrfs_update_delayed_inode()
1063 ASSERT(path->slots[0] > 0); in __btrfs_update_delayed_inode()
1065 path->slots[0]--; in __btrfs_update_delayed_inode()
1066 leaf = path->nodes[0]; in __btrfs_update_delayed_inode()
1068 path->slots[0]++; in __btrfs_update_delayed_inode()
1070 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); in __btrfs_update_delayed_inode()
1071 if (key.objectid != node->inode_id) in __btrfs_update_delayed_inode()
1082 ret = btrfs_del_item(trans, root, path); in __btrfs_update_delayed_inode()
1084 btrfs_release_delayed_iref(node); in __btrfs_update_delayed_inode()
1087 btrfs_delayed_inode_release_metadata(fs_info, node, (ret < 0)); in __btrfs_update_delayed_inode()
1088 btrfs_release_delayed_inode(node); in __btrfs_update_delayed_inode()
1095 if (ret && ret != -ENOENT) in __btrfs_update_delayed_inode()
1102 struct btrfs_root *root, in btrfs_update_delayed_inode() argument
1104 struct btrfs_delayed_node *node) in btrfs_update_delayed_inode() argument
1108 mutex_lock(&node->mutex); in btrfs_update_delayed_inode()
1109 if (!test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &node->flags)) { in btrfs_update_delayed_inode()
1110 mutex_unlock(&node->mutex); in btrfs_update_delayed_inode()
1114 ret = __btrfs_update_delayed_inode(trans, root, path, node); in btrfs_update_delayed_inode()
1115 mutex_unlock(&node->mutex); in btrfs_update_delayed_inode()
1122 struct btrfs_delayed_node *node) in __btrfs_commit_inode_delayed_items() argument
1126 ret = btrfs_insert_delayed_items(trans, path, node->root, node); in __btrfs_commit_inode_delayed_items()
1130 ret = btrfs_delete_delayed_items(trans, path, node->root, node); in __btrfs_commit_inode_delayed_items()
1134 ret = btrfs_record_root_in_trans(trans, node->root); in __btrfs_commit_inode_delayed_items()
1137 ret = btrfs_update_delayed_inode(trans, node->root, path, node); in __btrfs_commit_inode_delayed_items()
1149 struct btrfs_fs_info *fs_info = trans->fs_info; in __btrfs_run_delayed_items()
1158 return -EIO; in __btrfs_run_delayed_items()
1162 return -ENOMEM; in __btrfs_run_delayed_items()
1164 block_rsv = trans->block_rsv; in __btrfs_run_delayed_items()
1165 trans->block_rsv = &fs_info->delayed_block_rsv; in __btrfs_run_delayed_items()
1167 delayed_root = fs_info->delayed_root; in __btrfs_run_delayed_items()
1170 while (curr_node && (!count || nr--)) { in __btrfs_run_delayed_items()
1182 * node. If the commit of delayed items was successful the path in __btrfs_run_delayed_items()
1186 ASSERT(path->nodes[0] == NULL); in __btrfs_run_delayed_items()
1192 * releasing the delayed node, as that requires taking the delayed node's in __btrfs_run_delayed_items()
1201 trans->block_rsv = block_rsv; in __btrfs_run_delayed_items()
1208 return __btrfs_run_delayed_items(trans, -1); in btrfs_run_delayed_items()
1227 mutex_lock(&delayed_node->mutex); in btrfs_commit_inode_delayed_items()
1228 if (!delayed_node->count) { in btrfs_commit_inode_delayed_items()
1229 mutex_unlock(&delayed_node->mutex); in btrfs_commit_inode_delayed_items()
1233 mutex_unlock(&delayed_node->mutex); in btrfs_commit_inode_delayed_items()
1238 return -ENOMEM; in btrfs_commit_inode_delayed_items()
1241 block_rsv = trans->block_rsv; in btrfs_commit_inode_delayed_items()
1242 trans->block_rsv = &delayed_node->root->fs_info->delayed_block_rsv; in btrfs_commit_inode_delayed_items()
1248 trans->block_rsv = block_rsv; in btrfs_commit_inode_delayed_items()
1255 struct btrfs_fs_info *fs_info = inode->root->fs_info; in btrfs_commit_inode_delayed_inode()
1265 mutex_lock(&delayed_node->mutex); in btrfs_commit_inode_delayed_inode()
1266 if (!test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) { in btrfs_commit_inode_delayed_inode()
1267 mutex_unlock(&delayed_node->mutex); in btrfs_commit_inode_delayed_inode()
1271 mutex_unlock(&delayed_node->mutex); in btrfs_commit_inode_delayed_inode()
1273 trans = btrfs_join_transaction(delayed_node->root); in btrfs_commit_inode_delayed_inode()
1281 ret = -ENOMEM; in btrfs_commit_inode_delayed_inode()
1285 block_rsv = trans->block_rsv; in btrfs_commit_inode_delayed_inode()
1286 trans->block_rsv = &fs_info->delayed_block_rsv; in btrfs_commit_inode_delayed_inode()
1288 mutex_lock(&delayed_node->mutex); in btrfs_commit_inode_delayed_inode()
1289 if (test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) in btrfs_commit_inode_delayed_inode()
1290 ret = __btrfs_update_delayed_inode(trans, delayed_node->root, in btrfs_commit_inode_delayed_inode()
1294 mutex_unlock(&delayed_node->mutex); in btrfs_commit_inode_delayed_inode()
1297 trans->block_rsv = block_rsv; in btrfs_commit_inode_delayed_inode()
1311 delayed_node = READ_ONCE(inode->delayed_node); in btrfs_remove_delayed_node()
1315 inode->delayed_node = NULL; in btrfs_remove_delayed_node()
1332 struct btrfs_root *root; in btrfs_async_run_delayed_root() local
1337 delayed_root = async_work->delayed_root; in btrfs_async_run_delayed_root()
1344 if (atomic_read(&delayed_root->items) < in btrfs_async_run_delayed_root()
1352 root = delayed_node->root; in btrfs_async_run_delayed_root()
1354 trans = btrfs_join_transaction(root); in btrfs_async_run_delayed_root()
1362 block_rsv = trans->block_rsv; in btrfs_async_run_delayed_root()
1363 trans->block_rsv = &root->fs_info->delayed_block_rsv; in btrfs_async_run_delayed_root()
1367 trans->block_rsv = block_rsv; in btrfs_async_run_delayed_root()
1369 btrfs_btree_balance_dirty_nodelay(root->fs_info); in btrfs_async_run_delayed_root()
1375 } while ((async_work->nr == 0 && total_done < BTRFS_DELAYED_WRITEBACK) in btrfs_async_run_delayed_root()
1376 || total_done < async_work->nr); in btrfs_async_run_delayed_root()
1380 wake_up(&delayed_root->wait); in btrfs_async_run_delayed_root()
1392 return -ENOMEM; in btrfs_wq_run_delayed_node()
1394 async_work->delayed_root = delayed_root; in btrfs_wq_run_delayed_node()
1395 btrfs_init_work(&async_work->work, btrfs_async_run_delayed_root, NULL); in btrfs_wq_run_delayed_node()
1396 async_work->nr = nr; in btrfs_wq_run_delayed_node()
1398 btrfs_queue_work(fs_info->delayed_workers, &async_work->work); in btrfs_wq_run_delayed_node()
1404 WARN_ON(btrfs_first_delayed_node(fs_info->delayed_root)); in btrfs_assert_delayed_root_empty()
1409 int val = atomic_read(&delayed_root->items_seq); in could_end_wait()
1414 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND) in could_end_wait()
1422 struct btrfs_delayed_root *delayed_root = fs_info->delayed_root; in btrfs_balance_delayed_items()
1424 if ((atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND) || in btrfs_balance_delayed_items()
1425 btrfs_workqueue_normal_congested(fs_info->delayed_workers)) in btrfs_balance_delayed_items()
1428 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) { in btrfs_balance_delayed_items()
1432 seq = atomic_read(&delayed_root->items_seq); in btrfs_balance_delayed_items()
1438 wait_event_interruptible(delayed_root->wait, in btrfs_balance_delayed_items()
1448 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_release_dir_index_item_space()
1451 if (test_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags)) in btrfs_release_dir_index_item_space()
1462 trans->transid, bytes, 0); in btrfs_release_dir_index_item_space()
1463 btrfs_block_rsv_release(fs_info, trans->block_rsv, bytes, NULL); in btrfs_release_dir_index_item_space()
1464 ASSERT(trans->bytes_reserved >= bytes); in btrfs_release_dir_index_item_space()
1465 trans->bytes_reserved -= bytes; in btrfs_release_dir_index_item_space()
1468 /* Will return 0, -ENOMEM or -EEXIST (index number collision, unexpected). */
1475 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_insert_delayed_dir_index()
1492 ret = -ENOMEM; in btrfs_insert_delayed_dir_index()
1496 delayed_item->index = index; in btrfs_insert_delayed_dir_index()
1498 dir_item = (struct btrfs_dir_item *)delayed_item->data; in btrfs_insert_delayed_dir_index()
1499 dir_item->location = *disk_key; in btrfs_insert_delayed_dir_index()
1500 btrfs_set_stack_dir_transid(dir_item, trans->transid); in btrfs_insert_delayed_dir_index()
1506 data_len = delayed_item->data_len + sizeof(struct btrfs_item); in btrfs_insert_delayed_dir_index()
1508 mutex_lock(&delayed_node->mutex); in btrfs_insert_delayed_dir_index()
1512 * handling path simpler in case we fail (-EEXIST). There's no risk of in btrfs_insert_delayed_dir_index()
1515 * delayed node's mutex and that mutex must also be locked before the in btrfs_insert_delayed_dir_index()
1516 * node's delayed items can be run. in btrfs_insert_delayed_dir_index()
1520 btrfs_err(trans->fs_info, in btrfs_insert_delayed_dir_index()
1521 …layed dir index item, name: %.*s, index: %llu, root: %llu, dir: %llu, dir->index_cnt: %llu, delaye… in btrfs_insert_delayed_dir_index()
1522 name_len, name, index, btrfs_root_id(delayed_node->root), in btrfs_insert_delayed_dir_index()
1523 delayed_node->inode_id, dir->index_cnt, in btrfs_insert_delayed_dir_index()
1524 delayed_node->index_cnt, ret); in btrfs_insert_delayed_dir_index()
1527 mutex_unlock(&delayed_node->mutex); in btrfs_insert_delayed_dir_index()
1531 if (delayed_node->index_item_leaves == 0 || in btrfs_insert_delayed_dir_index()
1532 delayed_node->curr_index_batch_size + data_len > leaf_data_size) { in btrfs_insert_delayed_dir_index()
1533 delayed_node->curr_index_batch_size = data_len; in btrfs_insert_delayed_dir_index()
1536 delayed_node->curr_index_batch_size += data_len; in btrfs_insert_delayed_dir_index()
1549 mutex_unlock(&delayed_node->mutex); in btrfs_insert_delayed_dir_index()
1553 delayed_node->index_item_leaves++; in btrfs_insert_delayed_dir_index()
1557 mutex_unlock(&delayed_node->mutex); in btrfs_insert_delayed_dir_index()
1565 struct btrfs_delayed_node *node, in btrfs_delete_delayed_insertion_item() argument
1570 mutex_lock(&node->mutex); in btrfs_delete_delayed_insertion_item()
1571 item = __btrfs_lookup_delayed_item(&node->ins_root.rb_root, index); in btrfs_delete_delayed_insertion_item()
1573 mutex_unlock(&node->mutex); in btrfs_delete_delayed_insertion_item()
1583 ASSERT(item->bytes_reserved == 0); in btrfs_delete_delayed_insertion_item()
1584 ASSERT(node->index_item_leaves > 0); in btrfs_delete_delayed_insertion_item()
1593 if (node->index_item_leaves == 1) { in btrfs_delete_delayed_insertion_item()
1594 const u32 data_len = item->data_len + sizeof(struct btrfs_item); in btrfs_delete_delayed_insertion_item()
1596 ASSERT(node->curr_index_batch_size >= data_len); in btrfs_delete_delayed_insertion_item()
1597 node->curr_index_batch_size -= data_len; in btrfs_delete_delayed_insertion_item()
1603 if (RB_EMPTY_ROOT(&node->ins_root.rb_root)) { in btrfs_delete_delayed_insertion_item()
1604 btrfs_delayed_item_release_leaves(node, node->index_item_leaves); in btrfs_delete_delayed_insertion_item()
1605 node->index_item_leaves = 0; in btrfs_delete_delayed_insertion_item()
1608 mutex_unlock(&node->mutex); in btrfs_delete_delayed_insertion_item()
1615 struct btrfs_delayed_node *node; in btrfs_delete_delayed_dir_index() local
1619 node = btrfs_get_or_create_delayed_node(dir); in btrfs_delete_delayed_dir_index()
1620 if (IS_ERR(node)) in btrfs_delete_delayed_dir_index()
1621 return PTR_ERR(node); in btrfs_delete_delayed_dir_index()
1623 ret = btrfs_delete_delayed_insertion_item(trans->fs_info, node, index); in btrfs_delete_delayed_dir_index()
1627 item = btrfs_alloc_delayed_item(0, node, BTRFS_DELAYED_DELETION_ITEM); in btrfs_delete_delayed_dir_index()
1629 ret = -ENOMEM; in btrfs_delete_delayed_dir_index()
1633 item->index = index; in btrfs_delete_delayed_dir_index()
1641 btrfs_err(trans->fs_info, in btrfs_delete_delayed_dir_index()
1647 mutex_lock(&node->mutex); in btrfs_delete_delayed_dir_index()
1648 ret = __btrfs_add_delayed_item(node, item); in btrfs_delete_delayed_dir_index()
1650 btrfs_err(trans->fs_info, in btrfs_delete_delayed_dir_index()
1651 …"err add delayed dir index item(index: %llu) into the deletion tree of the delayed node(root id: %… in btrfs_delete_delayed_dir_index()
1652 index, btrfs_root_id(node->root), in btrfs_delete_delayed_dir_index()
1653 node->inode_id, ret); in btrfs_delete_delayed_dir_index()
1654 btrfs_delayed_item_release_metadata(dir->root, item); in btrfs_delete_delayed_dir_index()
1657 mutex_unlock(&node->mutex); in btrfs_delete_delayed_dir_index()
1659 btrfs_release_delayed_node(node); in btrfs_delete_delayed_dir_index()
1668 return -ENOENT; in btrfs_inode_delayed_dir_index_count()
1672 * a new directory index is added into the delayed node and index_cnt in btrfs_inode_delayed_dir_index_count()
1673 * is updated now. So we needn't lock the delayed node. in btrfs_inode_delayed_dir_index_count()
1675 if (!delayed_node->index_cnt) { in btrfs_inode_delayed_dir_index_count()
1677 return -EINVAL; in btrfs_inode_delayed_dir_index_count()
1680 inode->index_cnt = delayed_node->index_cnt; in btrfs_inode_delayed_dir_index_count()
1699 * item->readdir_list. in btrfs_readdir_get_delayed_items()
1704 mutex_lock(&delayed_node->mutex); in btrfs_readdir_get_delayed_items()
1706 while (item && item->index <= last_index) { in btrfs_readdir_get_delayed_items()
1707 refcount_inc(&item->refs); in btrfs_readdir_get_delayed_items()
1708 list_add_tail(&item->readdir_list, ins_list); in btrfs_readdir_get_delayed_items()
1713 while (item && item->index <= last_index) { in btrfs_readdir_get_delayed_items()
1714 refcount_inc(&item->refs); in btrfs_readdir_get_delayed_items()
1715 list_add_tail(&item->readdir_list, del_list); in btrfs_readdir_get_delayed_items()
1718 mutex_unlock(&delayed_node->mutex); in btrfs_readdir_get_delayed_items()
1720 * This delayed node is still cached in the btrfs inode, so refs in btrfs_readdir_get_delayed_items()
1726 * requeue or dequeue this delayed node. in btrfs_readdir_get_delayed_items()
1728 refcount_dec(&delayed_node->refs); in btrfs_readdir_get_delayed_items()
1740 list_del(&curr->readdir_list); in btrfs_readdir_put_delayed_items()
1741 if (refcount_dec_and_test(&curr->refs)) in btrfs_readdir_put_delayed_items()
1746 list_del(&curr->readdir_list); in btrfs_readdir_put_delayed_items()
1747 if (refcount_dec_and_test(&curr->refs)) in btrfs_readdir_put_delayed_items()
1755 downgrade_write(&inode->vfs_inode.i_rwsem); in btrfs_readdir_put_delayed_items()
1765 if (curr->index > index) in btrfs_should_delete_dir_index()
1767 if (curr->index == index) { in btrfs_should_delete_dir_index()
1795 list_del(&curr->readdir_list); in btrfs_readdir_delayed_dir_index()
1797 if (curr->index < ctx->pos) { in btrfs_readdir_delayed_dir_index()
1798 if (refcount_dec_and_test(&curr->refs)) in btrfs_readdir_delayed_dir_index()
1803 ctx->pos = curr->index; in btrfs_readdir_delayed_dir_index()
1805 di = (struct btrfs_dir_item *)curr->data; in btrfs_readdir_delayed_dir_index()
1809 d_type = fs_ftype_to_dtype(btrfs_dir_flags_to_ftype(di->type)); in btrfs_readdir_delayed_dir_index()
1810 btrfs_disk_key_to_cpu(&location, &di->location); in btrfs_readdir_delayed_dir_index()
1815 if (refcount_dec_and_test(&curr->refs)) in btrfs_readdir_delayed_dir_index()
1820 ctx->pos++; in btrfs_readdir_delayed_dir_index()
1833 btrfs_set_stack_inode_size(inode_item, BTRFS_I(inode)->disk_i_size); in fill_stack_inode_item()
1834 btrfs_set_stack_inode_mode(inode_item, inode->i_mode); in fill_stack_inode_item()
1835 btrfs_set_stack_inode_nlink(inode_item, inode->i_nlink); in fill_stack_inode_item()
1838 BTRFS_I(inode)->generation); in fill_stack_inode_item()
1841 btrfs_set_stack_inode_transid(inode_item, trans->transid); in fill_stack_inode_item()
1842 btrfs_set_stack_inode_rdev(inode_item, inode->i_rdev); in fill_stack_inode_item()
1843 flags = btrfs_inode_combine_flags(BTRFS_I(inode)->flags, in fill_stack_inode_item()
1844 BTRFS_I(inode)->ro_flags); in fill_stack_inode_item()
1848 btrfs_set_stack_timespec_sec(&inode_item->atime, in fill_stack_inode_item()
1850 btrfs_set_stack_timespec_nsec(&inode_item->atime, in fill_stack_inode_item()
1853 btrfs_set_stack_timespec_sec(&inode_item->mtime, in fill_stack_inode_item()
1855 btrfs_set_stack_timespec_nsec(&inode_item->mtime, in fill_stack_inode_item()
1858 btrfs_set_stack_timespec_sec(&inode_item->ctime, in fill_stack_inode_item()
1860 btrfs_set_stack_timespec_nsec(&inode_item->ctime, in fill_stack_inode_item()
1863 btrfs_set_stack_timespec_sec(&inode_item->otime, BTRFS_I(inode)->i_otime_sec); in fill_stack_inode_item()
1864 btrfs_set_stack_timespec_nsec(&inode_item->otime, BTRFS_I(inode)->i_otime_nsec); in fill_stack_inode_item()
1869 struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info; in btrfs_fill_inode()
1875 return -ENOENT; in btrfs_fill_inode()
1877 mutex_lock(&delayed_node->mutex); in btrfs_fill_inode()
1878 if (!test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) { in btrfs_fill_inode()
1879 mutex_unlock(&delayed_node->mutex); in btrfs_fill_inode()
1881 return -ENOENT; in btrfs_fill_inode()
1884 inode_item = &delayed_node->inode_item; in btrfs_fill_inode()
1890 round_up(i_size_read(inode), fs_info->sectorsize)); in btrfs_fill_inode()
1891 inode->i_mode = btrfs_stack_inode_mode(inode_item); in btrfs_fill_inode()
1894 BTRFS_I(inode)->generation = btrfs_stack_inode_generation(inode_item); in btrfs_fill_inode()
1895 BTRFS_I(inode)->last_trans = btrfs_stack_inode_transid(inode_item); in btrfs_fill_inode()
1899 inode->i_rdev = 0; in btrfs_fill_inode()
1902 &BTRFS_I(inode)->flags, &BTRFS_I(inode)->ro_flags); in btrfs_fill_inode()
1904 inode_set_atime(inode, btrfs_stack_timespec_sec(&inode_item->atime), in btrfs_fill_inode()
1905 btrfs_stack_timespec_nsec(&inode_item->atime)); in btrfs_fill_inode()
1907 inode_set_mtime(inode, btrfs_stack_timespec_sec(&inode_item->mtime), in btrfs_fill_inode()
1908 btrfs_stack_timespec_nsec(&inode_item->mtime)); in btrfs_fill_inode()
1910 inode_set_ctime(inode, btrfs_stack_timespec_sec(&inode_item->ctime), in btrfs_fill_inode()
1911 btrfs_stack_timespec_nsec(&inode_item->ctime)); in btrfs_fill_inode()
1913 BTRFS_I(inode)->i_otime_sec = btrfs_stack_timespec_sec(&inode_item->otime); in btrfs_fill_inode()
1914 BTRFS_I(inode)->i_otime_nsec = btrfs_stack_timespec_nsec(&inode_item->otime); in btrfs_fill_inode()
1916 inode->i_generation = BTRFS_I(inode)->generation; in btrfs_fill_inode()
1917 if (S_ISDIR(inode->i_mode)) in btrfs_fill_inode()
1918 BTRFS_I(inode)->index_cnt = (u64)-1; in btrfs_fill_inode()
1920 mutex_unlock(&delayed_node->mutex); in btrfs_fill_inode()
1928 struct btrfs_root *root = inode->root; in btrfs_delayed_update_inode() local
1936 mutex_lock(&delayed_node->mutex); in btrfs_delayed_update_inode()
1937 if (test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) { in btrfs_delayed_update_inode()
1938 fill_stack_inode_item(trans, &delayed_node->inode_item, in btrfs_delayed_update_inode()
1939 &inode->vfs_inode); in btrfs_delayed_update_inode()
1943 ret = btrfs_delayed_inode_reserve_metadata(trans, root, delayed_node); in btrfs_delayed_update_inode()
1947 fill_stack_inode_item(trans, &delayed_node->inode_item, &inode->vfs_inode); in btrfs_delayed_update_inode()
1948 set_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags); in btrfs_delayed_update_inode()
1949 delayed_node->count++; in btrfs_delayed_update_inode()
1950 atomic_inc(&root->fs_info->delayed_root->items); in btrfs_delayed_update_inode()
1952 mutex_unlock(&delayed_node->mutex); in btrfs_delayed_update_inode()
1959 struct btrfs_fs_info *fs_info = inode->root->fs_info; in btrfs_delayed_delete_inode_ref()
1967 if (test_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags)) in btrfs_delayed_delete_inode_ref()
1968 return -EAGAIN; in btrfs_delayed_delete_inode_ref()
1976 * - We ONLY do async inode ref deletion for the inode who has only in btrfs_delayed_delete_inode_ref()
1982 * - If the inode ref and the inode item are not in the same leaf, in btrfs_delayed_delete_inode_ref()
1985 * - At the worst, we can steal some space from the global reservation. in btrfs_delayed_delete_inode_ref()
1988 mutex_lock(&delayed_node->mutex); in btrfs_delayed_delete_inode_ref()
1989 if (test_bit(BTRFS_DELAYED_NODE_DEL_IREF, &delayed_node->flags)) in btrfs_delayed_delete_inode_ref()
1992 set_bit(BTRFS_DELAYED_NODE_DEL_IREF, &delayed_node->flags); in btrfs_delayed_delete_inode_ref()
1993 delayed_node->count++; in btrfs_delayed_delete_inode_ref()
1994 atomic_inc(&fs_info->delayed_root->items); in btrfs_delayed_delete_inode_ref()
1996 mutex_unlock(&delayed_node->mutex); in btrfs_delayed_delete_inode_ref()
2003 struct btrfs_root *root = delayed_node->root; in __btrfs_kill_delayed_node() local
2004 struct btrfs_fs_info *fs_info = root->fs_info; in __btrfs_kill_delayed_node()
2007 mutex_lock(&delayed_node->mutex); in __btrfs_kill_delayed_node()
2015 if (delayed_node->index_item_leaves > 0) { in __btrfs_kill_delayed_node()
2017 delayed_node->index_item_leaves); in __btrfs_kill_delayed_node()
2018 delayed_node->index_item_leaves = 0; in __btrfs_kill_delayed_node()
2023 btrfs_delayed_item_release_metadata(root, curr_item); in __btrfs_kill_delayed_node()
2031 if (test_bit(BTRFS_DELAYED_NODE_INODE_DIRTY, &delayed_node->flags)) { in __btrfs_kill_delayed_node()
2035 mutex_unlock(&delayed_node->mutex); in __btrfs_kill_delayed_node()
2050 void btrfs_kill_all_delayed_nodes(struct btrfs_root *root) in btrfs_kill_all_delayed_nodes() argument
2056 struct btrfs_delayed_node *node; in btrfs_kill_all_delayed_nodes() local
2059 xa_lock(&root->delayed_nodes); in btrfs_kill_all_delayed_nodes()
2060 if (xa_empty(&root->delayed_nodes)) { in btrfs_kill_all_delayed_nodes()
2061 xa_unlock(&root->delayed_nodes); in btrfs_kill_all_delayed_nodes()
2066 xa_for_each_start(&root->delayed_nodes, index, node, index) { in btrfs_kill_all_delayed_nodes()
2068 * Don't increase refs in case the node is dead and in btrfs_kill_all_delayed_nodes()
2071 if (refcount_inc_not_zero(&node->refs)) { in btrfs_kill_all_delayed_nodes()
2072 delayed_nodes[count] = node; in btrfs_kill_all_delayed_nodes()
2078 xa_unlock(&root->delayed_nodes); in btrfs_kill_all_delayed_nodes()
2092 curr_node = btrfs_first_delayed_node(fs_info->delayed_root); in btrfs_destroy_delayed_inodes()
2106 struct btrfs_delayed_node *node; in btrfs_log_get_delayed_items() local
2109 node = btrfs_get_delayed_node(inode); in btrfs_log_get_delayed_items()
2110 if (!node) in btrfs_log_get_delayed_items()
2113 mutex_lock(&node->mutex); in btrfs_log_get_delayed_items()
2114 item = __btrfs_first_delayed_insertion_item(node); in btrfs_log_get_delayed_items()
2139 if (!item->logged && list_empty(&item->log_list)) { in btrfs_log_get_delayed_items()
2140 refcount_inc(&item->refs); in btrfs_log_get_delayed_items()
2141 list_add_tail(&item->log_list, ins_list); in btrfs_log_get_delayed_items()
2146 item = __btrfs_first_delayed_deletion_item(node); in btrfs_log_get_delayed_items()
2148 /* It may be non-empty, for the same reason mentioned above. */ in btrfs_log_get_delayed_items()
2149 if (!item->logged && list_empty(&item->log_list)) { in btrfs_log_get_delayed_items()
2150 refcount_inc(&item->refs); in btrfs_log_get_delayed_items()
2151 list_add_tail(&item->log_list, del_list); in btrfs_log_get_delayed_items()
2155 mutex_unlock(&node->mutex); in btrfs_log_get_delayed_items()
2166 ASSERT(refcount_read(&node->refs) > 1); in btrfs_log_get_delayed_items()
2167 refcount_dec(&node->refs); in btrfs_log_get_delayed_items()
2174 struct btrfs_delayed_node *node; in btrfs_log_put_delayed_items() local
2178 node = btrfs_get_delayed_node(inode); in btrfs_log_put_delayed_items()
2179 if (!node) in btrfs_log_put_delayed_items()
2182 mutex_lock(&node->mutex); in btrfs_log_put_delayed_items()
2185 item->logged = true; in btrfs_log_put_delayed_items()
2186 list_del_init(&item->log_list); in btrfs_log_put_delayed_items()
2187 if (refcount_dec_and_test(&item->refs)) in btrfs_log_put_delayed_items()
2192 item->logged = true; in btrfs_log_put_delayed_items()
2193 list_del_init(&item->log_list); in btrfs_log_put_delayed_items()
2194 if (refcount_dec_and_test(&item->refs)) in btrfs_log_put_delayed_items()
2198 mutex_unlock(&node->mutex); in btrfs_log_put_delayed_items()
2209 ASSERT(refcount_read(&node->refs) > 1); in btrfs_log_put_delayed_items()
2210 refcount_dec(&node->refs); in btrfs_log_put_delayed_items()