Lines Matching refs:root

31 	struct btrfs_root *root = data;  in caching_kthread()  local
32 struct btrfs_fs_info *fs_info = root->fs_info; in caching_kthread()
33 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in caching_kthread()
41 if (!btrfs_test_opt(root, INODE_MAP_CACHE)) in caching_kthread()
60 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); in caching_kthread()
71 ret = btrfs_next_leaf(root, path); in caching_kthread()
90 root->ino_cache_progress = last; in caching_kthread()
103 if (key.objectid >= root->highest_objectid) in caching_kthread()
109 wake_up(&root->ino_cache_wait); in caching_kthread()
117 if (last < root->highest_objectid - 1) { in caching_kthread()
119 root->highest_objectid - last - 1); in caching_kthread()
122 spin_lock(&root->ino_cache_lock); in caching_kthread()
123 root->ino_cache_state = BTRFS_CACHE_FINISHED; in caching_kthread()
124 spin_unlock(&root->ino_cache_lock); in caching_kthread()
126 root->ino_cache_progress = (u64)-1; in caching_kthread()
127 btrfs_unpin_free_ino(root); in caching_kthread()
129 wake_up(&root->ino_cache_wait); in caching_kthread()
137 static void start_caching(struct btrfs_root *root) in start_caching() argument
139 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in start_caching()
144 if (!btrfs_test_opt(root, INODE_MAP_CACHE)) in start_caching()
147 spin_lock(&root->ino_cache_lock); in start_caching()
148 if (root->ino_cache_state != BTRFS_CACHE_NO) { in start_caching()
149 spin_unlock(&root->ino_cache_lock); in start_caching()
153 root->ino_cache_state = BTRFS_CACHE_STARTED; in start_caching()
154 spin_unlock(&root->ino_cache_lock); in start_caching()
156 ret = load_free_ino_cache(root->fs_info, root); in start_caching()
158 spin_lock(&root->ino_cache_lock); in start_caching()
159 root->ino_cache_state = BTRFS_CACHE_FINISHED; in start_caching()
160 spin_unlock(&root->ino_cache_lock); in start_caching()
171 ret = btrfs_find_free_objectid(root, &objectid); in start_caching()
177 tsk = kthread_run(caching_kthread, root, "btrfs-ino-cache-%llu", in start_caching()
178 root->root_key.objectid); in start_caching()
180 btrfs_warn(root->fs_info, "failed to start inode caching task"); in start_caching()
181 btrfs_clear_pending_and_info(root->fs_info, INODE_MAP_CACHE, in start_caching()
186 int btrfs_find_free_ino(struct btrfs_root *root, u64 *objectid) in btrfs_find_free_ino() argument
188 if (!btrfs_test_opt(root, INODE_MAP_CACHE)) in btrfs_find_free_ino()
189 return btrfs_find_free_objectid(root, objectid); in btrfs_find_free_ino()
192 *objectid = btrfs_find_ino_for_alloc(root); in btrfs_find_free_ino()
197 start_caching(root); in btrfs_find_free_ino()
199 wait_event(root->ino_cache_wait, in btrfs_find_free_ino()
200 root->ino_cache_state == BTRFS_CACHE_FINISHED || in btrfs_find_free_ino()
201 root->free_ino_ctl->free_space > 0); in btrfs_find_free_ino()
203 if (root->ino_cache_state == BTRFS_CACHE_FINISHED && in btrfs_find_free_ino()
204 root->free_ino_ctl->free_space == 0) in btrfs_find_free_ino()
210 void btrfs_return_ino(struct btrfs_root *root, u64 objectid) in btrfs_return_ino() argument
212 struct btrfs_free_space_ctl *pinned = root->free_ino_pinned; in btrfs_return_ino()
214 if (!btrfs_test_opt(root, INODE_MAP_CACHE)) in btrfs_return_ino()
217 if (root->ino_cache_state == BTRFS_CACHE_FINISHED) { in btrfs_return_ino()
220 down_write(&root->fs_info->commit_root_sem); in btrfs_return_ino()
221 spin_lock(&root->ino_cache_lock); in btrfs_return_ino()
222 if (root->ino_cache_state == BTRFS_CACHE_FINISHED) { in btrfs_return_ino()
223 spin_unlock(&root->ino_cache_lock); in btrfs_return_ino()
224 up_write(&root->fs_info->commit_root_sem); in btrfs_return_ino()
227 spin_unlock(&root->ino_cache_lock); in btrfs_return_ino()
229 start_caching(root); in btrfs_return_ino()
233 up_write(&root->fs_info->commit_root_sem); in btrfs_return_ino()
245 void btrfs_unpin_free_ino(struct btrfs_root *root) in btrfs_unpin_free_ino() argument
247 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in btrfs_unpin_free_ino()
248 struct rb_root *rbroot = &root->free_ino_pinned->free_space_offset; in btrfs_unpin_free_ino()
249 spinlock_t *rbroot_lock = &root->free_ino_pinned->tree_lock; in btrfs_unpin_free_ino()
254 if (!btrfs_test_opt(root, INODE_MAP_CACHE)) in btrfs_unpin_free_ino()
270 if (info->offset > root->ino_cache_progress) in btrfs_unpin_free_ino()
272 else if (info->offset + info->bytes > root->ino_cache_progress) in btrfs_unpin_free_ino()
273 count = root->ino_cache_progress - info->offset + 1; in btrfs_unpin_free_ino()
364 void btrfs_init_free_ino_ctl(struct btrfs_root *root) in btrfs_init_free_ino_ctl() argument
366 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in btrfs_init_free_ino_ctl()
367 struct btrfs_free_space_ctl *pinned = root->free_ino_pinned; in btrfs_init_free_ino_ctl()
392 int btrfs_save_ino_cache(struct btrfs_root *root, in btrfs_save_ino_cache() argument
395 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in btrfs_save_ino_cache()
406 if (root->root_key.objectid != BTRFS_FS_TREE_OBJECTID && in btrfs_save_ino_cache()
407 (root->root_key.objectid < BTRFS_FIRST_FREE_OBJECTID || in btrfs_save_ino_cache()
408 root->root_key.objectid > BTRFS_LAST_FREE_OBJECTID)) in btrfs_save_ino_cache()
412 if (btrfs_root_refs(&root->root_item) == 0) in btrfs_save_ino_cache()
415 if (!btrfs_test_opt(root, INODE_MAP_CACHE)) in btrfs_save_ino_cache()
423 trans->block_rsv = &root->fs_info->trans_block_rsv; in btrfs_save_ino_cache()
433 trans->bytes_reserved = btrfs_calc_trans_metadata_size(root, 10); in btrfs_save_ino_cache()
434 ret = btrfs_block_rsv_add(root, trans->block_rsv, in btrfs_save_ino_cache()
439 trace_btrfs_space_reservation(root->fs_info, "ino_cache", in btrfs_save_ino_cache()
442 inode = lookup_free_ino_inode(root, path); in btrfs_save_ino_cache()
452 ret = create_free_ino_inode(root, trans, path); in btrfs_save_ino_cache()
459 ret = btrfs_update_inode(trans, root, inode); in btrfs_save_ino_cache()
461 btrfs_abort_transaction(trans, root, ret); in btrfs_save_ino_cache()
466 ret = btrfs_truncate_free_space_cache(root, trans, NULL, inode); in btrfs_save_ino_cache()
469 btrfs_abort_transaction(trans, root, ret); in btrfs_save_ino_cache()
474 spin_lock(&root->ino_cache_lock); in btrfs_save_ino_cache()
475 if (root->ino_cache_state != BTRFS_CACHE_FINISHED) { in btrfs_save_ino_cache()
477 spin_unlock(&root->ino_cache_lock); in btrfs_save_ino_cache()
480 spin_unlock(&root->ino_cache_lock); in btrfs_save_ino_cache()
503 ret = btrfs_write_out_ino_cache(root, trans, path, inode); in btrfs_save_ino_cache()
507 trace_btrfs_space_reservation(root->fs_info, "ino_cache", in btrfs_save_ino_cache()
509 btrfs_block_rsv_release(root, trans->block_rsv, trans->bytes_reserved); in btrfs_save_ino_cache()
518 int btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid) in btrfs_find_highest_objectid() argument
534 ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0); in btrfs_find_highest_objectid()
553 int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid) in btrfs_find_free_objectid() argument
556 mutex_lock(&root->objectid_mutex); in btrfs_find_free_objectid()
558 if (unlikely(root->highest_objectid >= BTRFS_LAST_FREE_OBJECTID)) { in btrfs_find_free_objectid()
563 *objectid = ++root->highest_objectid; in btrfs_find_free_objectid()
566 mutex_unlock(&root->objectid_mutex); in btrfs_find_free_objectid()