Lines Matching refs:root

17 	struct btrfs_root *root = data;  in caching_kthread()  local
18 struct btrfs_fs_info *fs_info = root->fs_info; in caching_kthread()
19 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in caching_kthread()
46 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); in caching_kthread()
57 ret = btrfs_next_leaf(root, path); in caching_kthread()
76 root->ino_cache_progress = last; in caching_kthread()
89 if (key.objectid >= root->highest_objectid) in caching_kthread()
95 wake_up(&root->ino_cache_wait); in caching_kthread()
103 if (last < root->highest_objectid - 1) { in caching_kthread()
105 root->highest_objectid - last - 1); in caching_kthread()
108 spin_lock(&root->ino_cache_lock); in caching_kthread()
109 root->ino_cache_state = BTRFS_CACHE_FINISHED; in caching_kthread()
110 spin_unlock(&root->ino_cache_lock); in caching_kthread()
112 root->ino_cache_progress = (u64)-1; in caching_kthread()
113 btrfs_unpin_free_ino(root); in caching_kthread()
115 wake_up(&root->ino_cache_wait); in caching_kthread()
123 static void start_caching(struct btrfs_root *root) in start_caching() argument
125 struct btrfs_fs_info *fs_info = root->fs_info; in start_caching()
126 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in start_caching()
134 spin_lock(&root->ino_cache_lock); in start_caching()
135 if (root->ino_cache_state != BTRFS_CACHE_NO) { in start_caching()
136 spin_unlock(&root->ino_cache_lock); in start_caching()
140 root->ino_cache_state = BTRFS_CACHE_STARTED; in start_caching()
141 spin_unlock(&root->ino_cache_lock); in start_caching()
143 ret = load_free_ino_cache(fs_info, root); in start_caching()
145 spin_lock(&root->ino_cache_lock); in start_caching()
146 root->ino_cache_state = BTRFS_CACHE_FINISHED; in start_caching()
147 spin_unlock(&root->ino_cache_lock); in start_caching()
158 ret = btrfs_find_free_objectid(root, &objectid); in start_caching()
164 tsk = kthread_run(caching_kthread, root, "btrfs-ino-cache-%llu", in start_caching()
165 root->root_key.objectid); in start_caching()
173 int btrfs_find_free_ino(struct btrfs_root *root, u64 *objectid) in btrfs_find_free_ino() argument
175 if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE)) in btrfs_find_free_ino()
176 return btrfs_find_free_objectid(root, objectid); in btrfs_find_free_ino()
179 *objectid = btrfs_find_ino_for_alloc(root); in btrfs_find_free_ino()
184 start_caching(root); in btrfs_find_free_ino()
186 wait_event(root->ino_cache_wait, in btrfs_find_free_ino()
187 root->ino_cache_state == BTRFS_CACHE_FINISHED || in btrfs_find_free_ino()
188 root->free_ino_ctl->free_space > 0); in btrfs_find_free_ino()
190 if (root->ino_cache_state == BTRFS_CACHE_FINISHED && in btrfs_find_free_ino()
191 root->free_ino_ctl->free_space == 0) in btrfs_find_free_ino()
197 void btrfs_return_ino(struct btrfs_root *root, u64 objectid) in btrfs_return_ino() argument
199 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_return_ino()
200 struct btrfs_free_space_ctl *pinned = root->free_ino_pinned; in btrfs_return_ino()
205 if (root->ino_cache_state == BTRFS_CACHE_FINISHED) { in btrfs_return_ino()
209 spin_lock(&root->ino_cache_lock); in btrfs_return_ino()
210 if (root->ino_cache_state == BTRFS_CACHE_FINISHED) { in btrfs_return_ino()
211 spin_unlock(&root->ino_cache_lock); in btrfs_return_ino()
215 spin_unlock(&root->ino_cache_lock); in btrfs_return_ino()
217 start_caching(root); in btrfs_return_ino()
233 void btrfs_unpin_free_ino(struct btrfs_root *root) in btrfs_unpin_free_ino() argument
235 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in btrfs_unpin_free_ino()
236 struct rb_root *rbroot = &root->free_ino_pinned->free_space_offset; in btrfs_unpin_free_ino()
237 spinlock_t *rbroot_lock = &root->free_ino_pinned->tree_lock; in btrfs_unpin_free_ino()
242 if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE)) in btrfs_unpin_free_ino()
256 if (info->offset > root->ino_cache_progress) in btrfs_unpin_free_ino()
259 count = min(root->ino_cache_progress - info->offset + 1, in btrfs_unpin_free_ino()
265 __btrfs_add_free_space(root->fs_info, ctl, in btrfs_unpin_free_ino()
350 void btrfs_init_free_ino_ctl(struct btrfs_root *root) in btrfs_init_free_ino_ctl() argument
352 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in btrfs_init_free_ino_ctl()
353 struct btrfs_free_space_ctl *pinned = root->free_ino_pinned; in btrfs_init_free_ino_ctl()
378 int btrfs_save_ino_cache(struct btrfs_root *root, in btrfs_save_ino_cache() argument
381 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_save_ino_cache()
382 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in btrfs_save_ino_cache()
394 if (root->root_key.objectid != BTRFS_FS_TREE_OBJECTID && in btrfs_save_ino_cache()
395 (root->root_key.objectid < BTRFS_FIRST_FREE_OBJECTID || in btrfs_save_ino_cache()
396 root->root_key.objectid > BTRFS_LAST_FREE_OBJECTID)) in btrfs_save_ino_cache()
400 if (btrfs_root_refs(&root->root_item) == 0) in btrfs_save_ino_cache()
422 ret = btrfs_block_rsv_add(root, trans->block_rsv, in btrfs_save_ino_cache()
430 inode = lookup_free_ino_inode(root, path); in btrfs_save_ino_cache()
440 ret = create_free_ino_inode(root, trans, path); in btrfs_save_ino_cache()
447 ret = btrfs_update_inode(trans, root, inode); in btrfs_save_ino_cache()
462 spin_lock(&root->ino_cache_lock); in btrfs_save_ino_cache()
463 if (root->ino_cache_state != BTRFS_CACHE_FINISHED) { in btrfs_save_ino_cache()
465 spin_unlock(&root->ino_cache_lock); in btrfs_save_ino_cache()
468 spin_unlock(&root->ino_cache_lock); in btrfs_save_ino_cache()
490 ret = btrfs_write_out_ino_cache(root, trans, path, inode); in btrfs_save_ino_cache()
508 int btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid) in btrfs_find_highest_objectid() argument
524 ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0); in btrfs_find_highest_objectid()
543 int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid) in btrfs_find_free_objectid() argument
546 mutex_lock(&root->objectid_mutex); in btrfs_find_free_objectid()
548 if (unlikely(root->highest_objectid >= BTRFS_LAST_FREE_OBJECTID)) { in btrfs_find_free_objectid()
549 btrfs_warn(root->fs_info, in btrfs_find_free_objectid()
551 root->root_key.objectid); in btrfs_find_free_objectid()
556 *objectid = ++root->highest_objectid; in btrfs_find_free_objectid()
559 mutex_unlock(&root->objectid_mutex); in btrfs_find_free_objectid()