Lines Matching +full:- +full:- +full:root

1 // SPDX-License-Identifier: GPL-2.0
12 #include "disk-io.h"
13 #include "print-tree.h"
15 #include "space-info.h"
17 #include "root-tree.h"
21 * Read a root item from the tree. In case we detect a root item smaller then
22 * sizeof(root_item), we know it's an old version of the root structure and
24 * generation numbers as then we know the root was once mounted with an older
25 * kernel that was not aware of the root item structure change.
41 btrfs_warn(eb->fs_info, in btrfs_read_root_item()
42 …"mismatching generation and generation_v2 found in root item. This root was probably mounted with … in btrfs_read_root_item()
49 generate_random_guid(item->uuid); in btrfs_read_root_item()
54 * btrfs_find_root - lookup the root by the key.
55 * root: the root of the root tree
58 * root_item: the root item of the tree we look for
59 * root_key: the root key of the tree we look for
61 * If ->offset of 'search_key' is -1ULL, it means we are not sure the offset
62 * of the search key, just lookup the root with the highest offset for a
67 int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key, in btrfs_find_root() argument
76 ret = btrfs_search_slot(NULL, root, search_key, path, 0, 0); in btrfs_find_root()
80 if (search_key->offset != -1ULL) { /* the search key is exact */ in btrfs_find_root()
85 if (path->slots[0] == 0) in btrfs_find_root()
87 path->slots[0]--; in btrfs_find_root()
91 l = path->nodes[0]; in btrfs_find_root()
92 slot = path->slots[0]; in btrfs_find_root()
95 if (found_key.objectid != search_key->objectid || in btrfs_find_root()
113 btrfs_set_root_bytenr(item, node->start); in btrfs_set_root_node()
122 *root, struct btrfs_key *key, struct btrfs_root_item in btrfs_update_root()
125 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_update_root()
135 return -ENOMEM; in btrfs_update_root()
137 ret = btrfs_search_slot(trans, root, key, path, 0, 1); in btrfs_update_root()
143 "unable to find root key (%llu %u %llu) in tree %llu", in btrfs_update_root()
144 key->objectid, key->type, key->offset, in btrfs_update_root()
145 root->root_key.objectid); in btrfs_update_root()
146 ret = -EUCLEAN; in btrfs_update_root()
151 l = path->nodes[0]; in btrfs_update_root()
152 slot = path->slots[0]; in btrfs_update_root()
157 * If this is the first time we update the root item which originated in btrfs_update_root()
163 ret = btrfs_search_slot(trans, root, key, path, in btrfs_update_root()
164 -1, 1); in btrfs_update_root()
170 ret = btrfs_del_item(trans, root, path); in btrfs_update_root()
176 ret = btrfs_insert_empty_item(trans, root, path, in btrfs_update_root()
182 l = path->nodes[0]; in btrfs_update_root()
183 slot = path->slots[0]; in btrfs_update_root()
188 * Update generation_v2 so at the next mount we know the new root in btrfs_update_root()
194 btrfs_mark_buffer_dirty(trans, path->nodes[0]); in btrfs_update_root()
200 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, in btrfs_insert_root() argument
207 return btrfs_insert_item(trans, root, key, item, sizeof(*item)); in btrfs_insert_root()
212 struct btrfs_root *tree_root = fs_info->tree_root; in btrfs_find_orphan_roots()
216 struct btrfs_root *root; in btrfs_find_orphan_roots() local
222 return -ENOMEM; in btrfs_find_orphan_roots()
237 leaf = path->nodes[0]; in btrfs_find_orphan_roots()
238 if (path->slots[0] >= btrfs_header_nritems(leaf)) { in btrfs_find_orphan_roots()
244 leaf = path->nodes[0]; in btrfs_find_orphan_roots()
247 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); in btrfs_find_orphan_roots()
257 root = btrfs_get_fs_root(fs_info, root_objectid, false); in btrfs_find_orphan_roots()
258 err = PTR_ERR_OR_ZERO(root); in btrfs_find_orphan_roots()
259 if (err && err != -ENOENT) { in btrfs_find_orphan_roots()
261 } else if (err == -ENOENT) { in btrfs_find_orphan_roots()
278 "Failed to delete root orphan item"); in btrfs_find_orphan_roots()
284 WARN_ON(!test_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state)); in btrfs_find_orphan_roots()
285 if (btrfs_root_refs(&root->root_item) == 0) { in btrfs_find_orphan_roots()
288 btrfs_disk_key_to_cpu(&drop_key, &root->root_item.drop_progress); in btrfs_find_orphan_roots()
290 * If we have a non-zero drop_progress then we know we in btrfs_find_orphan_roots()
297 set_bit(BTRFS_FS_UNFINISHED_DROPS, &fs_info->flags); in btrfs_find_orphan_roots()
298 set_bit(BTRFS_ROOT_UNFINISHED_DROP, &root->state); in btrfs_find_orphan_roots()
301 set_bit(BTRFS_ROOT_DEAD_TREE, &root->state); in btrfs_find_orphan_roots()
302 btrfs_add_dead_root(root); in btrfs_find_orphan_roots()
304 btrfs_put_root(root); in btrfs_find_orphan_roots()
311 /* drop the root item for 'key' from the tree root */
315 struct btrfs_root *root = trans->fs_info->tree_root; in btrfs_del_root() local
321 return -ENOMEM; in btrfs_del_root()
322 ret = btrfs_search_slot(trans, root, key, path, -1, 1); in btrfs_del_root()
328 ret = btrfs_del_item(trans, root, path); in btrfs_del_root()
338 struct btrfs_root *tree_root = trans->fs_info->tree_root; in btrfs_del_root_ref()
348 return -ENOMEM; in btrfs_del_root_ref()
354 ret = btrfs_search_slot(trans, tree_root, &key, path, -1, 1); in btrfs_del_root_ref()
358 leaf = path->nodes[0]; in btrfs_del_root_ref()
359 ref = btrfs_item_ptr(leaf, path->slots[0], in btrfs_del_root_ref()
363 (btrfs_root_ref_name_len(leaf, ref) != name->len) || in btrfs_del_root_ref()
364 memcmp_extent_buffer(leaf, name->name, ptr, name->len)) { in btrfs_del_root_ref()
365 ret = -ENOENT; in btrfs_del_root_ref()
374 ret = -ENOENT; in btrfs_del_root_ref()
396 * that is referencing the root.
399 * the root and ref_id is the id of the subvol or snapshot.
404 * Will return 0, -ENOMEM, or anything from the CoW path
410 struct btrfs_root *tree_root = trans->fs_info->tree_root; in btrfs_add_root_ref()
420 return -ENOMEM; in btrfs_add_root_ref()
427 sizeof(*ref) + name->len); in btrfs_add_root_ref()
434 leaf = path->nodes[0]; in btrfs_add_root_ref()
435 ref = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_root_ref); in btrfs_add_root_ref()
438 btrfs_set_root_ref_name_len(leaf, ref, name->len); in btrfs_add_root_ref()
440 write_extent_buffer(leaf, name->name, ptr, name->len); in btrfs_add_root_ref()
456 * Old btrfs forgets to init root_item->flags and root_item->byte_limit
458 * root_item->inode_item->flags, and use it to indicate if those fields
463 u64 inode_flags = btrfs_stack_inode_flags(&root_item->inode); in btrfs_check_and_init_root_item()
467 btrfs_set_stack_inode_flags(&root_item->inode, inode_flags); in btrfs_check_and_init_root_item()
474 struct btrfs_root *root) in btrfs_update_root_times() argument
476 struct btrfs_root_item *item = &root->root_item; in btrfs_update_root_times()
480 spin_lock(&root->root_item_lock); in btrfs_update_root_times()
481 btrfs_set_root_ctransid(item, trans->transid); in btrfs_update_root_times()
482 btrfs_set_stack_timespec_sec(&item->ctime, ct.tv_sec); in btrfs_update_root_times()
483 btrfs_set_stack_timespec_nsec(&item->ctime, ct.tv_nsec); in btrfs_update_root_times()
484 spin_unlock(&root->root_item_lock); in btrfs_update_root_times()
488 * btrfs_subvolume_reserve_metadata() - reserve space for subvolume operation
489 * root: the root of the parent directory
497 * and root tree, the number of items that the qgroup reserves is
501 int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, in btrfs_subvolume_reserve_metadata() argument
508 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_subvolume_reserve_metadata()
509 struct btrfs_block_rsv *global_rsv = &fs_info->global_block_rsv; in btrfs_subvolume_reserve_metadata()
511 if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) { in btrfs_subvolume_reserve_metadata()
513 qgroup_num_bytes = 3 * fs_info->nodesize; in btrfs_subvolume_reserve_metadata()
514 ret = btrfs_qgroup_reserve_meta_prealloc(root, in btrfs_subvolume_reserve_metadata()
522 rsv->space_info = btrfs_find_space_info(fs_info, in btrfs_subvolume_reserve_metadata()
527 if (ret == -ENOSPC && use_global_rsv) in btrfs_subvolume_reserve_metadata()
531 btrfs_qgroup_free_meta_prealloc(root, qgroup_num_bytes); in btrfs_subvolume_reserve_metadata()
534 spin_lock(&rsv->lock); in btrfs_subvolume_reserve_metadata()
535 rsv->qgroup_rsv_reserved += qgroup_num_bytes; in btrfs_subvolume_reserve_metadata()
536 spin_unlock(&rsv->lock); in btrfs_subvolume_reserve_metadata()