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()
161 wake_up(&root->ino_cache_wait); in start_caching()
172 ret = btrfs_find_free_objectid(root, &objectid); in start_caching()
178 tsk = kthread_run(caching_kthread, root, "btrfs-ino-cache-%llu", in start_caching()
179 root->root_key.objectid); in start_caching()
181 btrfs_warn(root->fs_info, "failed to start inode caching task"); in start_caching()
182 btrfs_clear_pending_and_info(root->fs_info, INODE_MAP_CACHE, in start_caching()
187 int btrfs_find_free_ino(struct btrfs_root *root, u64 *objectid) in btrfs_find_free_ino() argument
189 if (!btrfs_test_opt(root, INODE_MAP_CACHE)) in btrfs_find_free_ino()
190 return btrfs_find_free_objectid(root, objectid); in btrfs_find_free_ino()
193 *objectid = btrfs_find_ino_for_alloc(root); in btrfs_find_free_ino()
198 start_caching(root); in btrfs_find_free_ino()
200 wait_event(root->ino_cache_wait, in btrfs_find_free_ino()
201 root->ino_cache_state == BTRFS_CACHE_FINISHED || in btrfs_find_free_ino()
202 root->free_ino_ctl->free_space > 0); in btrfs_find_free_ino()
204 if (root->ino_cache_state == BTRFS_CACHE_FINISHED && in btrfs_find_free_ino()
205 root->free_ino_ctl->free_space == 0) in btrfs_find_free_ino()
211 void btrfs_return_ino(struct btrfs_root *root, u64 objectid) in btrfs_return_ino() argument
213 struct btrfs_free_space_ctl *pinned = root->free_ino_pinned; in btrfs_return_ino()
215 if (!btrfs_test_opt(root, INODE_MAP_CACHE)) in btrfs_return_ino()
218 if (root->ino_cache_state == BTRFS_CACHE_FINISHED) { in btrfs_return_ino()
221 down_write(&root->fs_info->commit_root_sem); in btrfs_return_ino()
222 spin_lock(&root->ino_cache_lock); in btrfs_return_ino()
223 if (root->ino_cache_state == BTRFS_CACHE_FINISHED) { in btrfs_return_ino()
224 spin_unlock(&root->ino_cache_lock); in btrfs_return_ino()
225 up_write(&root->fs_info->commit_root_sem); in btrfs_return_ino()
228 spin_unlock(&root->ino_cache_lock); in btrfs_return_ino()
230 start_caching(root); in btrfs_return_ino()
234 up_write(&root->fs_info->commit_root_sem); in btrfs_return_ino()
246 void btrfs_unpin_free_ino(struct btrfs_root *root) in btrfs_unpin_free_ino() argument
248 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in btrfs_unpin_free_ino()
249 struct rb_root *rbroot = &root->free_ino_pinned->free_space_offset; in btrfs_unpin_free_ino()
250 spinlock_t *rbroot_lock = &root->free_ino_pinned->tree_lock; in btrfs_unpin_free_ino()
255 if (!btrfs_test_opt(root, INODE_MAP_CACHE)) in btrfs_unpin_free_ino()
271 if (info->offset > root->ino_cache_progress) in btrfs_unpin_free_ino()
273 else if (info->offset + info->bytes > root->ino_cache_progress) in btrfs_unpin_free_ino()
274 count = root->ino_cache_progress - info->offset + 1; in btrfs_unpin_free_ino()
365 void btrfs_init_free_ino_ctl(struct btrfs_root *root) in btrfs_init_free_ino_ctl() argument
367 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in btrfs_init_free_ino_ctl()
368 struct btrfs_free_space_ctl *pinned = root->free_ino_pinned; in btrfs_init_free_ino_ctl()
393 int btrfs_save_ino_cache(struct btrfs_root *root, in btrfs_save_ino_cache() argument
396 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in btrfs_save_ino_cache()
407 if (root->root_key.objectid != BTRFS_FS_TREE_OBJECTID && in btrfs_save_ino_cache()
408 (root->root_key.objectid < BTRFS_FIRST_FREE_OBJECTID || in btrfs_save_ino_cache()
409 root->root_key.objectid > BTRFS_LAST_FREE_OBJECTID)) in btrfs_save_ino_cache()
413 if (btrfs_root_refs(&root->root_item) == 0) in btrfs_save_ino_cache()
416 if (!btrfs_test_opt(root, INODE_MAP_CACHE)) in btrfs_save_ino_cache()
424 trans->block_rsv = &root->fs_info->trans_block_rsv; in btrfs_save_ino_cache()
434 trans->bytes_reserved = btrfs_calc_trans_metadata_size(root, 10); in btrfs_save_ino_cache()
435 ret = btrfs_block_rsv_add(root, trans->block_rsv, in btrfs_save_ino_cache()
440 trace_btrfs_space_reservation(root->fs_info, "ino_cache", in btrfs_save_ino_cache()
443 inode = lookup_free_ino_inode(root, path); in btrfs_save_ino_cache()
453 ret = create_free_ino_inode(root, trans, path); in btrfs_save_ino_cache()
460 ret = btrfs_update_inode(trans, root, inode); in btrfs_save_ino_cache()
462 btrfs_abort_transaction(trans, root, ret); in btrfs_save_ino_cache()
467 ret = btrfs_truncate_free_space_cache(root, trans, NULL, inode); in btrfs_save_ino_cache()
470 btrfs_abort_transaction(trans, root, ret); in btrfs_save_ino_cache()
475 spin_lock(&root->ino_cache_lock); in btrfs_save_ino_cache()
476 if (root->ino_cache_state != BTRFS_CACHE_FINISHED) { in btrfs_save_ino_cache()
478 spin_unlock(&root->ino_cache_lock); in btrfs_save_ino_cache()
481 spin_unlock(&root->ino_cache_lock); in btrfs_save_ino_cache()
504 ret = btrfs_write_out_ino_cache(root, trans, path, inode); in btrfs_save_ino_cache()
508 trace_btrfs_space_reservation(root->fs_info, "ino_cache", in btrfs_save_ino_cache()
510 btrfs_block_rsv_release(root, trans->block_rsv, trans->bytes_reserved); in btrfs_save_ino_cache()
519 int btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid) in btrfs_find_highest_objectid() argument
535 ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0); in btrfs_find_highest_objectid()
554 int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid) in btrfs_find_free_objectid() argument
557 mutex_lock(&root->objectid_mutex); in btrfs_find_free_objectid()
559 if (unlikely(root->highest_objectid >= BTRFS_LAST_FREE_OBJECTID)) { in btrfs_find_free_objectid()
564 *objectid = ++root->highest_objectid; in btrfs_find_free_objectid()
567 mutex_unlock(&root->objectid_mutex); in btrfs_find_free_objectid()