Lines Matching full:root

16 static void fail_caching_thread(struct btrfs_root *root)  in fail_caching_thread()  argument
18 struct btrfs_fs_info *fs_info = root->fs_info; in fail_caching_thread()
23 spin_lock(&root->ino_cache_lock); in fail_caching_thread()
24 root->ino_cache_state = BTRFS_CACHE_ERROR; in fail_caching_thread()
25 spin_unlock(&root->ino_cache_lock); in fail_caching_thread()
26 wake_up(&root->ino_cache_wait); in fail_caching_thread()
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()
46 fail_caching_thread(root); in caching_kthread()
50 /* Since the commit root is read-only, we can safely skip locking. */ in caching_kthread()
62 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); in caching_kthread()
73 ret = btrfs_next_leaf(root, path); in caching_kthread()
92 root->ino_cache_progress = last; in caching_kthread()
105 if (key.objectid >= root->highest_objectid) in caching_kthread()
111 wake_up(&root->ino_cache_wait); in caching_kthread()
119 if (last < root->highest_objectid - 1) { in caching_kthread()
121 root->highest_objectid - last - 1, 0); in caching_kthread()
124 spin_lock(&root->ino_cache_lock); in caching_kthread()
125 root->ino_cache_state = BTRFS_CACHE_FINISHED; in caching_kthread()
126 spin_unlock(&root->ino_cache_lock); in caching_kthread()
128 root->ino_cache_progress = (u64)-1; in caching_kthread()
129 btrfs_unpin_free_ino(root); in caching_kthread()
131 wake_up(&root->ino_cache_wait); in caching_kthread()
139 static void start_caching(struct btrfs_root *root) in start_caching() argument
141 struct btrfs_fs_info *fs_info = root->fs_info; in start_caching()
142 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in start_caching()
150 spin_lock(&root->ino_cache_lock); in start_caching()
151 if (root->ino_cache_state != BTRFS_CACHE_NO) { in start_caching()
152 spin_unlock(&root->ino_cache_lock); in start_caching()
156 root->ino_cache_state = BTRFS_CACHE_STARTED; in start_caching()
157 spin_unlock(&root->ino_cache_lock); in start_caching()
159 ret = load_free_ino_cache(fs_info, root); in start_caching()
161 spin_lock(&root->ino_cache_lock); in start_caching()
162 root->ino_cache_state = BTRFS_CACHE_FINISHED; in start_caching()
163 spin_unlock(&root->ino_cache_lock); in start_caching()
164 wake_up(&root->ino_cache_wait); in start_caching()
175 ret = btrfs_find_free_objectid(root, &objectid); in start_caching()
180 wake_up(&root->ino_cache_wait); in start_caching()
183 tsk = kthread_run(caching_kthread, root, "btrfs-ino-cache-%llu", in start_caching()
184 root->root_key.objectid); in start_caching()
186 fail_caching_thread(root); in start_caching()
189 int btrfs_find_free_ino(struct btrfs_root *root, u64 *objectid) in btrfs_find_free_ino() argument
191 if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE)) in btrfs_find_free_ino()
192 return btrfs_find_free_objectid(root, objectid); in btrfs_find_free_ino()
195 *objectid = btrfs_find_ino_for_alloc(root); in btrfs_find_free_ino()
200 start_caching(root); in btrfs_find_free_ino()
202 wait_event(root->ino_cache_wait, in btrfs_find_free_ino()
203 root->ino_cache_state == BTRFS_CACHE_FINISHED || in btrfs_find_free_ino()
204 root->ino_cache_state == BTRFS_CACHE_ERROR || in btrfs_find_free_ino()
205 root->free_ino_ctl->free_space > 0); in btrfs_find_free_ino()
207 if (root->ino_cache_state == BTRFS_CACHE_FINISHED && in btrfs_find_free_ino()
208 root->free_ino_ctl->free_space == 0) in btrfs_find_free_ino()
210 else if (root->ino_cache_state == BTRFS_CACHE_ERROR) in btrfs_find_free_ino()
211 return btrfs_find_free_objectid(root, objectid); in btrfs_find_free_ino()
216 void btrfs_return_ino(struct btrfs_root *root, u64 objectid) in btrfs_return_ino() argument
218 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_return_ino()
219 struct btrfs_free_space_ctl *pinned = root->free_ino_pinned; in btrfs_return_ino()
224 if (root->ino_cache_state == BTRFS_CACHE_FINISHED) { in btrfs_return_ino()
228 spin_lock(&root->ino_cache_lock); in btrfs_return_ino()
229 if (root->ino_cache_state == BTRFS_CACHE_FINISHED) { in btrfs_return_ino()
230 spin_unlock(&root->ino_cache_lock); in btrfs_return_ino()
234 spin_unlock(&root->ino_cache_lock); in btrfs_return_ino()
236 start_caching(root); in btrfs_return_ino()
246 * smaller than root->ino_cache_progress from pinned tree to free_ino tree, and
247 * others will just be dropped, because the commit root we were searching has
250 * Must be called with root->fs_info->commit_root_sem held
252 void btrfs_unpin_free_ino(struct btrfs_root *root) in btrfs_unpin_free_ino() argument
254 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in btrfs_unpin_free_ino()
255 struct rb_root *rbroot = &root->free_ino_pinned->free_space_offset; in btrfs_unpin_free_ino()
256 spinlock_t *rbroot_lock = &root->free_ino_pinned->tree_lock; in btrfs_unpin_free_ino()
261 if (!btrfs_test_opt(root->fs_info, INODE_MAP_CACHE)) in btrfs_unpin_free_ino()
275 if (info->offset > root->ino_cache_progress) in btrfs_unpin_free_ino()
278 count = min(root->ino_cache_progress - info->offset + 1, in btrfs_unpin_free_ino()
284 __btrfs_add_free_space(root->fs_info, ctl, in btrfs_unpin_free_ino()
369 void btrfs_init_free_ino_ctl(struct btrfs_root *root) in btrfs_init_free_ino_ctl() argument
371 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in btrfs_init_free_ino_ctl()
372 struct btrfs_free_space_ctl *pinned = root->free_ino_pinned; in btrfs_init_free_ino_ctl()
397 int btrfs_save_ino_cache(struct btrfs_root *root, in btrfs_save_ino_cache() argument
400 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_save_ino_cache()
401 struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; in btrfs_save_ino_cache()
413 if (root->root_key.objectid != BTRFS_FS_TREE_OBJECTID && in btrfs_save_ino_cache()
414 (root->root_key.objectid < BTRFS_FIRST_FREE_OBJECTID || in btrfs_save_ino_cache()
415 root->root_key.objectid > BTRFS_LAST_FREE_OBJECTID)) in btrfs_save_ino_cache()
418 /* Don't save inode cache if we are deleting this root */ in btrfs_save_ino_cache()
419 if (btrfs_root_refs(&root->root_item) == 0) in btrfs_save_ino_cache()
441 ret = btrfs_block_rsv_add(root, trans->block_rsv, in btrfs_save_ino_cache()
449 inode = lookup_free_ino_inode(root, path); in btrfs_save_ino_cache()
459 ret = create_free_ino_inode(root, trans, path); in btrfs_save_ino_cache()
466 ret = btrfs_update_inode(trans, root, inode); in btrfs_save_ino_cache()
481 spin_lock(&root->ino_cache_lock); in btrfs_save_ino_cache()
482 if (root->ino_cache_state != BTRFS_CACHE_FINISHED) { in btrfs_save_ino_cache()
484 spin_unlock(&root->ino_cache_lock); in btrfs_save_ino_cache()
487 spin_unlock(&root->ino_cache_lock); in btrfs_save_ino_cache()
511 ret = btrfs_write_out_ino_cache(root, trans, path, inode); in btrfs_save_ino_cache()
529 int btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid) in btrfs_find_highest_objectid() argument
545 ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0); in btrfs_find_highest_objectid()
564 int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid) in btrfs_find_free_objectid() argument
567 mutex_lock(&root->objectid_mutex); in btrfs_find_free_objectid()
569 if (unlikely(root->highest_objectid >= BTRFS_LAST_FREE_OBJECTID)) { in btrfs_find_free_objectid()
570 btrfs_warn(root->fs_info, in btrfs_find_free_objectid()
571 "the objectid of root %llu reaches its highest value", in btrfs_find_free_objectid()
572 root->root_key.objectid); in btrfs_find_free_objectid()
577 *objectid = ++root->highest_objectid; in btrfs_find_free_objectid()
580 mutex_unlock(&root->objectid_mutex); in btrfs_find_free_objectid()