Lines Matching +full:data +full:- +full:path

1 // SPDX-License-Identifier: GPL-2.0
12 #include "disk-io.h"
15 #include "uuid-tree.h"
20 key->type = type; in btrfs_uuid_to_key()
21 key->objectid = get_unaligned_le64(uuid); in btrfs_uuid_to_key()
22 key->offset = get_unaligned_le64(uuid + sizeof(u64)); in btrfs_uuid_to_key()
25 /* return -ENOENT for !found, < 0 for errors, or 0 if an item was found */
30 struct btrfs_path *path = NULL; in btrfs_uuid_tree_lookup() local
38 ret = -ENOENT; in btrfs_uuid_tree_lookup()
42 path = btrfs_alloc_path(); in btrfs_uuid_tree_lookup()
43 if (!path) { in btrfs_uuid_tree_lookup()
44 ret = -ENOMEM; in btrfs_uuid_tree_lookup()
49 ret = btrfs_search_slot(NULL, uuid_root, &key, path, 0, 0); in btrfs_uuid_tree_lookup()
53 ret = -ENOENT; in btrfs_uuid_tree_lookup()
57 eb = path->nodes[0]; in btrfs_uuid_tree_lookup()
58 slot = path->slots[0]; in btrfs_uuid_tree_lookup()
61 ret = -ENOENT; in btrfs_uuid_tree_lookup()
64 btrfs_warn(uuid_root->fs_info, in btrfs_uuid_tree_lookup()
70 __le64 data; in btrfs_uuid_tree_lookup() local
72 read_extent_buffer(eb, &data, offset, sizeof(data)); in btrfs_uuid_tree_lookup()
73 if (le64_to_cpu(data) == subid) { in btrfs_uuid_tree_lookup()
77 offset += sizeof(data); in btrfs_uuid_tree_lookup()
78 item_size -= sizeof(data); in btrfs_uuid_tree_lookup()
82 btrfs_free_path(path); in btrfs_uuid_tree_lookup()
89 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_uuid_tree_add()
90 struct btrfs_root *uuid_root = fs_info->uuid_root; in btrfs_uuid_tree_add()
92 struct btrfs_path *path = NULL; in btrfs_uuid_tree_add() local
100 if (ret != -ENOENT) in btrfs_uuid_tree_add()
104 ret = -EINVAL; in btrfs_uuid_tree_add()
110 path = btrfs_alloc_path(); in btrfs_uuid_tree_add()
111 if (!path) { in btrfs_uuid_tree_add()
112 ret = -ENOMEM; in btrfs_uuid_tree_add()
116 ret = btrfs_insert_empty_item(trans, uuid_root, path, &key, in btrfs_uuid_tree_add()
120 eb = path->nodes[0]; in btrfs_uuid_tree_add()
121 slot = path->slots[0]; in btrfs_uuid_tree_add()
123 } else if (ret == -EEXIST) { in btrfs_uuid_tree_add()
128 btrfs_extend_item(trans, path, sizeof(subid_le)); in btrfs_uuid_tree_add()
129 eb = path->nodes[0]; in btrfs_uuid_tree_add()
130 slot = path->slots[0]; in btrfs_uuid_tree_add()
132 offset += btrfs_item_size(eb, slot) - sizeof(subid_le); in btrfs_uuid_tree_add()
144 btrfs_free_path(path); in btrfs_uuid_tree_add()
151 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_uuid_tree_remove()
152 struct btrfs_root *uuid_root = fs_info->uuid_root; in btrfs_uuid_tree_remove()
154 struct btrfs_path *path = NULL; in btrfs_uuid_tree_remove() local
165 ret = -EINVAL; in btrfs_uuid_tree_remove()
171 path = btrfs_alloc_path(); in btrfs_uuid_tree_remove()
172 if (!path) { in btrfs_uuid_tree_remove()
173 ret = -ENOMEM; in btrfs_uuid_tree_remove()
177 ret = btrfs_search_slot(trans, uuid_root, &key, path, -1, 1); in btrfs_uuid_tree_remove()
184 ret = -ENOENT; in btrfs_uuid_tree_remove()
188 eb = path->nodes[0]; in btrfs_uuid_tree_remove()
189 slot = path->slots[0]; in btrfs_uuid_tree_remove()
195 ret = -ENOENT; in btrfs_uuid_tree_remove()
205 item_size -= sizeof(read_subid); in btrfs_uuid_tree_remove()
209 ret = -ENOENT; in btrfs_uuid_tree_remove()
215 ret = btrfs_del_item(trans, uuid_root, path); in btrfs_uuid_tree_remove()
221 move_len = item_size - (move_src - btrfs_item_ptr_offset(eb, slot)); in btrfs_uuid_tree_remove()
223 btrfs_truncate_item(trans, path, item_size - sizeof(subid), 1); in btrfs_uuid_tree_remove()
226 btrfs_free_path(path); in btrfs_uuid_tree_remove()
236 /* 1 - for the uuid item */ in btrfs_uuid_iter_rem()
271 if (ret == -ENOENT) in btrfs_check_uuid_tree_entry()
278 if (memcmp(uuid, subvol_root->root_item.uuid, BTRFS_UUID_SIZE)) in btrfs_check_uuid_tree_entry()
282 if (memcmp(uuid, subvol_root->root_item.received_uuid, in btrfs_check_uuid_tree_entry()
294 struct btrfs_root *root = fs_info->uuid_root; in btrfs_uuid_tree_iterate()
296 struct btrfs_path *path; in btrfs_uuid_tree_iterate() local
303 path = btrfs_alloc_path(); in btrfs_uuid_tree_iterate()
304 if (!path) { in btrfs_uuid_tree_iterate()
305 ret = -ENOMEM; in btrfs_uuid_tree_iterate()
314 ret = btrfs_search_forward(root, &key, path, BTRFS_OLDEST_GENERATION); in btrfs_uuid_tree_iterate()
323 ret = -EINTR; in btrfs_uuid_tree_iterate()
327 leaf = path->nodes[0]; in btrfs_uuid_tree_iterate()
328 slot = path->slots[0]; in btrfs_uuid_tree_iterate()
358 btrfs_release_path(path); in btrfs_uuid_tree_iterate()
371 if (ret < 0 && ret != -ENOENT) in btrfs_uuid_tree_iterate()
376 item_size -= sizeof(subid_le); in btrfs_uuid_tree_iterate()
381 ret = btrfs_next_item(root, path); in btrfs_uuid_tree_iterate()
390 btrfs_free_path(path); in btrfs_uuid_tree_iterate()
394 int btrfs_uuid_scan_kthread(void *data) in btrfs_uuid_scan_kthread() argument
396 struct btrfs_fs_info *fs_info = data; in btrfs_uuid_scan_kthread()
397 struct btrfs_root *root = fs_info->tree_root; in btrfs_uuid_scan_kthread()
399 struct btrfs_path *path = NULL; in btrfs_uuid_scan_kthread() local
408 path = btrfs_alloc_path(); in btrfs_uuid_scan_kthread()
409 if (!path) { in btrfs_uuid_scan_kthread()
410 ret = -ENOMEM; in btrfs_uuid_scan_kthread()
423 ret = btrfs_search_forward(root, &key, path, in btrfs_uuid_scan_kthread()
437 eb = path->nodes[0]; in btrfs_uuid_scan_kthread()
438 slot = path->slots[0]; in btrfs_uuid_scan_kthread()
454 btrfs_release_path(path); in btrfs_uuid_scan_kthread()
456 * 1 - subvol uuid item in btrfs_uuid_scan_kthread()
457 * 1 - received_subvol uuid item in btrfs_uuid_scan_kthread()
459 trans = btrfs_start_transaction(fs_info->uuid_root, 2); in btrfs_uuid_scan_kthread()
469 btrfs_release_path(path); in btrfs_uuid_scan_kthread()
494 btrfs_release_path(path); in btrfs_uuid_scan_kthread()
502 if (key.offset < (u64)-1) { in btrfs_uuid_scan_kthread()
507 } else if (key.objectid < (u64)-1) { in btrfs_uuid_scan_kthread()
518 btrfs_free_path(path); in btrfs_uuid_scan_kthread()
524 set_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags); in btrfs_uuid_scan_kthread()
525 up(&fs_info->uuid_tree_rescan_sem); in btrfs_uuid_scan_kthread()
532 struct btrfs_root *tree_root = fs_info->tree_root; in btrfs_create_uuid_tree()
538 * 1 - root node in btrfs_create_uuid_tree()
539 * 1 - root item in btrfs_create_uuid_tree()
553 fs_info->uuid_root = uuid_root; in btrfs_create_uuid_tree()
559 down(&fs_info->uuid_tree_rescan_sem); in btrfs_create_uuid_tree()
560 task = kthread_run(btrfs_uuid_scan_kthread, fs_info, "btrfs-uuid"); in btrfs_create_uuid_tree()
562 /* fs_info->update_uuid_tree_gen remains 0 in all error case */ in btrfs_create_uuid_tree()
564 up(&fs_info->uuid_tree_rescan_sem); in btrfs_create_uuid_tree()