Lines Matching +full:iref +full:- +full:level

1 // SPDX-License-Identifier: GPL-2.0
13 #include <linux/radix-tree.h>
24 #include "disk-io.h"
28 #include "print-tree.h"
30 #include "dir-item.h"
31 #include "file-item.h"
71 (sizeof(struct fs_path) - offsetof(struct fs_path, inline_buf))
88 * can be satisfied from the kmalloc-192 slab, without wasting any space.
122 * at most 4096 bytes - sizeof(struct btrfs_lru_cache_entry) is 48 bytes, but
123 * the kmalloc-64 slab is used, so we get 4096 bytes (64 bytes * 64).
130 * at most 4096 bytes - sizeof(struct btrfs_lru_cache_entry) is 48 bytes, but
131 * the kmalloc-64 slab is used, so we get 4096 bytes (64 bytes * 64).
165 * don't operate on stale extent buffers for nodes (level >= 1) or on
210 * directory with lower inode number when we finish processing it - we
218 * |-- a (ino 257)
219 * |-- b (ino 258)
222 * |-- c (ino 259)
223 * | |-- d (ino 260)
225 * |-- c2 (ino 261)
230 * |-- a (ino 257)
231 * |-- b (ino 258)
232 * |-- c2 (ino 261)
233 * |-- d2 (ino 260)
234 * |-- cc (ino 259)
267 * |-- a/ (ino 257)
268 * |-- b/ (ino 258)
269 * |-- c/ (ino 259)
270 * | |-- x/ (ino 260)
272 * |-- y/ (ino 261)
277 * |-- a/ (ino 257)
278 * |-- b/ (ino 258)
279 * |-- YY/ (ino 261)
280 * |-- x/ (ino 260)
283 * rm -f /a/b/c/foo.txt
359 #define ADVANCE_ONLY_NEXT -1
394 btrfs_err(sctx->send_root->fs_info, in inconsistent_snapshot_error()
396 result_string, what, sctx->cmp_key->objectid, in inconsistent_snapshot_error()
397 btrfs_root_id(sctx->send_root), in inconsistent_snapshot_error()
398 (sctx->parent_root ? btrfs_root_id(sctx->parent_root) : 0)); in inconsistent_snapshot_error()
404 switch (sctx->proto) { in proto_cmd_ok()
421 return (sctx->parent_root && !sctx->cur_inode_new && in need_send_hole()
422 !sctx->cur_inode_new_gen && !sctx->cur_inode_deleted && in need_send_hole()
423 S_ISREG(sctx->cur_inode_mode)); in need_send_hole()
428 if (p->reversed) { in fs_path_reset()
429 p->start = p->buf + p->buf_len - 1; in fs_path_reset()
430 p->end = p->start; in fs_path_reset()
431 *p->start = 0; in fs_path_reset()
433 p->start = p->buf; in fs_path_reset()
434 p->end = p->start; in fs_path_reset()
435 *p->start = 0; in fs_path_reset()
446 p->reversed = 0; in fs_path_alloc()
447 p->buf = p->inline_buf; in fs_path_alloc()
448 p->buf_len = FS_PATH_INLINE_SIZE; in fs_path_alloc()
460 p->reversed = 1; in fs_path_alloc_reversed()
469 if (p->buf != p->inline_buf) in fs_path_free()
470 kfree(p->buf); in fs_path_free()
476 return p->end - p->start; in fs_path_len()
487 if (p->buf_len >= len) in fs_path_ensure_buf()
492 return -ENOMEM; in fs_path_ensure_buf()
495 path_len = p->end - p->start; in fs_path_ensure_buf()
496 old_buf_len = p->buf_len; in fs_path_ensure_buf()
506 if (p->buf == p->inline_buf) { in fs_path_ensure_buf()
509 memcpy(tmp_buf, p->buf, old_buf_len); in fs_path_ensure_buf()
511 tmp_buf = krealloc(p->buf, len, GFP_KERNEL); in fs_path_ensure_buf()
514 return -ENOMEM; in fs_path_ensure_buf()
515 p->buf = tmp_buf; in fs_path_ensure_buf()
516 p->buf_len = len; in fs_path_ensure_buf()
518 if (p->reversed) { in fs_path_ensure_buf()
519 tmp_buf = p->buf + old_buf_len - path_len - 1; in fs_path_ensure_buf()
520 p->end = p->buf + p->buf_len - 1; in fs_path_ensure_buf()
521 p->start = p->end - path_len; in fs_path_ensure_buf()
522 memmove(p->start, tmp_buf, path_len + 1); in fs_path_ensure_buf()
524 p->start = p->buf; in fs_path_ensure_buf()
525 p->end = p->start + path_len; in fs_path_ensure_buf()
536 new_len = p->end - p->start + name_len; in fs_path_prepare_for_add()
537 if (p->start != p->end) in fs_path_prepare_for_add()
543 if (p->reversed) { in fs_path_prepare_for_add()
544 if (p->start != p->end) in fs_path_prepare_for_add()
545 *--p->start = '/'; in fs_path_prepare_for_add()
546 p->start -= name_len; in fs_path_prepare_for_add()
547 *prepared = p->start; in fs_path_prepare_for_add()
549 if (p->start != p->end) in fs_path_prepare_for_add()
550 *p->end++ = '/'; in fs_path_prepare_for_add()
551 *prepared = p->end; in fs_path_prepare_for_add()
552 p->end += name_len; in fs_path_prepare_for_add()
553 *p->end = 0; in fs_path_prepare_for_add()
579 ret = fs_path_prepare_for_add(p, p2->end - p2->start, &prepared); in fs_path_add_path()
582 memcpy(prepared, p2->start, p2->end - p2->start); in fs_path_add_path()
607 p->reversed = from->reversed; in fs_path_copy()
618 if (!p->reversed) in fs_path_unreverse()
621 tmp = p->start; in fs_path_unreverse()
622 len = p->end - p->start; in fs_path_unreverse()
623 p->start = p->buf; in fs_path_unreverse()
624 p->end = p->start + len; in fs_path_unreverse()
625 memmove(p->start, tmp, len + 1); in fs_path_unreverse()
626 p->reversed = 0; in fs_path_unreverse()
636 path->search_commit_root = 1; in alloc_path_for_send()
637 path->skip_locking = 1; in alloc_path_for_send()
638 path->need_commit_sem = 1; in alloc_path_for_send()
648 ret = kernel_write(filp, buf + pos, len - pos, off); in write_buf()
652 return -EIO; in write_buf()
663 int left = sctx->send_max_size - sctx->send_size; in tlv_put()
665 if (WARN_ON_ONCE(sctx->put_data)) in tlv_put()
666 return -EINVAL; in tlv_put()
669 return -EOVERFLOW; in tlv_put()
671 hdr = (struct btrfs_tlv_header *) (sctx->send_buf + sctx->send_size); in tlv_put()
672 put_unaligned_le16(attr, &hdr->tlv_type); in tlv_put()
673 put_unaligned_le16(len, &hdr->tlv_len); in tlv_put()
675 sctx->send_size += total_len; in tlv_put()
695 if (len == -1) in tlv_put_string()
742 ret = tlv_put_string(sctx, attrtype, p->start, \
743 p->end - p->start); \
765 hdr.version = cpu_to_le32(sctx->proto); in send_header()
766 return write_buf(sctx->send_filp, &hdr, sizeof(hdr), in send_header()
767 &sctx->send_off); in send_header()
777 if (WARN_ON(!sctx->send_buf)) in begin_cmd()
778 return -EINVAL; in begin_cmd()
780 if (unlikely(sctx->send_size != 0)) { in begin_cmd()
781 btrfs_err(sctx->send_root->fs_info, in begin_cmd()
783 cmd, sctx->send_off); in begin_cmd()
784 return -EINVAL; in begin_cmd()
787 sctx->send_size += sizeof(*hdr); in begin_cmd()
788 hdr = (struct btrfs_cmd_header *)sctx->send_buf; in begin_cmd()
789 put_unaligned_le16(cmd, &hdr->cmd); in begin_cmd()
800 hdr = (struct btrfs_cmd_header *)sctx->send_buf; in send_cmd()
801 put_unaligned_le32(sctx->send_size - sizeof(*hdr), &hdr->len); in send_cmd()
802 put_unaligned_le32(0, &hdr->crc); in send_cmd()
804 crc = crc32c(0, (unsigned char *)sctx->send_buf, sctx->send_size); in send_cmd()
805 put_unaligned_le32(crc, &hdr->crc); in send_cmd()
807 ret = write_buf(sctx->send_filp, sctx->send_buf, sctx->send_size, in send_cmd()
808 &sctx->send_off); in send_cmd()
810 sctx->send_size = 0; in send_cmd()
811 sctx->put_data = false; in send_cmd()
822 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_rename()
825 btrfs_debug(fs_info, "send_rename %s -> %s", from->start, to->start); in send_rename()
847 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_link()
850 btrfs_debug(fs_info, "send_link %s -> %s", path->start, lnk->start); in send_link()
871 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_unlink()
874 btrfs_debug(fs_info, "send_unlink %s", path->start); in send_unlink()
894 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_rmdir()
897 btrfs_debug(fs_info, "send_rmdir %s", path->start); in send_rmdir()
936 return -ENOMEM; in get_inode_info()
944 ret = -ENOENT; in get_inode_info()
951 ii = btrfs_item_ptr(path->nodes[0], path->slots[0], in get_inode_info()
953 info->size = btrfs_inode_size(path->nodes[0], ii); in get_inode_info()
954 info->gen = btrfs_inode_generation(path->nodes[0], ii); in get_inode_info()
955 info->mode = btrfs_inode_mode(path->nodes[0], ii); in get_inode_info()
956 info->uid = btrfs_inode_uid(path->nodes[0], ii); in get_inode_info()
957 info->gid = btrfs_inode_gid(path->nodes[0], ii); in get_inode_info()
958 info->rdev = btrfs_inode_rdev(path->nodes[0], ii); in get_inode_info()
959 info->nlink = btrfs_inode_nlink(path->nodes[0], ii); in get_inode_info()
964 info->fileattr = btrfs_inode_flags(path->nodes[0], ii); in get_inode_info()
997 struct extent_buffer *eb = path->nodes[0]; in iterate_inode_ref()
998 struct btrfs_inode_ref *iref; in iterate_inode_ref() local
1004 int slot = path->slots[0]; in iterate_inode_ref()
1015 return -ENOMEM; in iterate_inode_ref()
1020 return -ENOMEM; in iterate_inode_ref()
1024 if (found_key->type == BTRFS_INODE_REF_KEY) { in iterate_inode_ref()
1028 elem_size = sizeof(*iref); in iterate_inode_ref()
1038 if (found_key->type == BTRFS_INODE_REF_KEY) { in iterate_inode_ref()
1039 iref = (struct btrfs_inode_ref *)(ptr + cur); in iterate_inode_ref()
1040 name_len = btrfs_inode_ref_name_len(eb, iref); in iterate_inode_ref()
1041 name_off = (unsigned long)(iref + 1); in iterate_inode_ref()
1042 dir = found_key->offset; in iterate_inode_ref()
1046 name_off = (unsigned long)&extref->name; in iterate_inode_ref()
1053 p->buf, p->buf_len); in iterate_inode_ref()
1058 if (start < p->buf) { in iterate_inode_ref()
1061 p->buf_len + p->buf - start); in iterate_inode_ref()
1067 p->buf, p->buf_len); in iterate_inode_ref()
1072 if (unlikely(start < p->buf)) { in iterate_inode_ref()
1073 btrfs_err(root->fs_info, in iterate_inode_ref()
1075 found_key->objectid, in iterate_inode_ref()
1076 found_key->type, in iterate_inode_ref()
1077 found_key->offset); in iterate_inode_ref()
1078 ret = -EINVAL; in iterate_inode_ref()
1082 p->start = start; in iterate_inode_ref()
1140 ret = -ENOMEM; in iterate_dir_item()
1144 eb = path->nodes[0]; in iterate_dir_item()
1145 slot = path->slots[0]; in iterate_dir_item()
1159 ret = -ENAMETOOLONG; in iterate_dir_item()
1163 BTRFS_MAX_XATTR_SIZE(root->fs_info)) { in iterate_dir_item()
1164 ret = -E2BIG; in iterate_dir_item()
1172 ret = -ENAMETOOLONG; in iterate_dir_item()
1193 ret = -ENOMEM; in iterate_dir_item()
1249 return -ENOMEM; in get_inode_path()
1264 btrfs_item_key_to_cpu(p->nodes[0], &found_key, p->slots[0]); in get_inode_path()
1268 ret = -ENOENT; in get_inode_path()
1312 if (root < btrfs_root_id(cr->root)) in __clone_root_cmp_bsearch()
1313 return -1; in __clone_root_cmp_bsearch()
1314 if (root > btrfs_root_id(cr->root)) in __clone_root_cmp_bsearch()
1324 if (btrfs_root_id(cr1->root) < btrfs_root_id(cr2->root)) in __clone_root_cmp_sort()
1325 return -1; in __clone_root_cmp_sort()
1326 if (btrfs_root_id(cr1->root) > btrfs_root_id(cr2->root)) in __clone_root_cmp_sort()
1333 * Results are collected in sctx->clone_roots->ino/offset.
1342 clone_root = bsearch((void *)(uintptr_t)root_id, bctx->sctx->clone_roots, in iterate_backrefs()
1343 bctx->sctx->clone_roots_cnt, in iterate_backrefs()
1350 if (clone_root->root == bctx->sctx->send_root && in iterate_backrefs()
1351 ino == bctx->cur_objectid && in iterate_backrefs()
1352 offset == bctx->cur_offset) in iterate_backrefs()
1359 if (clone_root->root == bctx->sctx->send_root) { in iterate_backrefs()
1365 if (ino > bctx->cur_objectid) in iterate_backrefs()
1373 if (ino == bctx->cur_objectid && in iterate_backrefs()
1374 offset + bctx->extent_len > in iterate_backrefs()
1375 bctx->sctx->cur_inode_next_write_offset) in iterate_backrefs()
1379 bctx->found++; in iterate_backrefs()
1380 clone_root->found_ref = true; in iterate_backrefs()
1386 * less exclusive, non-shared extents at the destination. in iterate_backrefs()
1388 if (num_bytes > clone_root->num_bytes) { in iterate_backrefs()
1389 clone_root->ino = ino; in iterate_backrefs()
1390 clone_root->offset = offset; in iterate_backrefs()
1391 clone_root->num_bytes = num_bytes; in iterate_backrefs()
1397 if (num_bytes >= bctx->extent_len) in iterate_backrefs()
1408 struct send_ctx *sctx = bctx->sctx; in lookup_backref_cache()
1409 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in lookup_backref_cache()
1410 const u64 key = leaf_bytenr >> fs_info->sectorsize_bits; in lookup_backref_cache()
1414 if (sctx->backref_cache.size == 0) in lookup_backref_cache()
1420 * read-only roots, their leaves and nodes may have been reallocated and in lookup_backref_cache()
1425 * transaction handle or holding fs_info->commit_root_sem, so no need in lookup_backref_cache()
1428 if (fs_info->last_reloc_trans > sctx->backref_cache_last_reloc_trans) { in lookup_backref_cache()
1429 btrfs_lru_cache_clear(&sctx->backref_cache); in lookup_backref_cache()
1433 raw_entry = btrfs_lru_cache_lookup(&sctx->backref_cache, key, 0); in lookup_backref_cache()
1438 *root_ids_ret = entry->root_ids; in lookup_backref_cache()
1439 *root_count_ret = entry->num_roots; in lookup_backref_cache()
1448 struct send_ctx *sctx = bctx->sctx; in store_backref_cache()
1449 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in store_backref_cache()
1457 * fs_info->commit_root_sem (at iterate_extent_inodes()), so must do a in store_backref_cache()
1465 new_entry->entry.key = leaf_bytenr >> fs_info->sectorsize_bits; in store_backref_cache()
1466 new_entry->entry.gen = 0; in store_backref_cache()
1467 new_entry->num_roots = 0; in store_backref_cache()
1470 const u64 root_id = node->val; in store_backref_cache()
1473 root = bsearch((void *)(uintptr_t)root_id, sctx->clone_roots, in store_backref_cache()
1474 sctx->clone_roots_cnt, sizeof(struct clone_root), in store_backref_cache()
1480 if (new_entry->num_roots >= SEND_MAX_BACKREF_CACHE_ROOTS) { in store_backref_cache()
1485 new_entry->root_ids[new_entry->num_roots] = root_id; in store_backref_cache()
1486 new_entry->num_roots++; in store_backref_cache()
1496 * handle or while holding fs_info->commit_root_sem. in store_backref_cache()
1498 ret = btrfs_lru_cache_store(&sctx->backref_cache, &new_entry->entry, in store_backref_cache()
1500 ASSERT(ret == 0 || ret == -ENOMEM); in store_backref_cache()
1509 * transaction handle or holding fs_info->commit_root_sem, so no need in store_backref_cache()
1512 if (sctx->backref_cache.size == 1) in store_backref_cache()
1513 sctx->backref_cache_last_reloc_trans = fs_info->last_reloc_trans; in store_backref_cache()
1521 const struct send_ctx *sctx = bctx->sctx; in check_extent_item()
1523 if (bytenr == bctx->bytenr) { in check_extent_item()
1527 return -EUCLEAN; in check_extent_item()
1531 * clone source - meaning no clone roots were given in the in check_extent_item()
1532 * struct btrfs_ioctl_send_args passed to the send ioctl - then in check_extent_item()
1536 if (refs == 1 && sctx->clone_roots_cnt == 1) in check_extent_item()
1537 return -ENOENT; in check_extent_item()
1548 return -ENOENT; in check_extent_item()
1557 if (ino == bctx->cur_objectid && in skip_self_data_ref()
1558 root == bctx->backref_owner && in skip_self_data_ref()
1559 offset == bctx->backref_offset) in skip_self_data_ref()
1567 * instruction. Returns -ENOENT when none could be found. The function makes
1580 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in find_extent_clone()
1587 struct extent_buffer *eb = path->nodes[0]; in find_extent_clone()
1603 fi = btrfs_item_ptr(eb, path->slots[0], struct btrfs_file_extent_item); in find_extent_clone()
1606 return -ENOENT; in find_extent_clone()
1610 return -ENOENT; in find_extent_clone()
1619 for (i = 0; i < sctx->clone_roots_cnt; i++) { in find_extent_clone()
1620 cur_clone_root = sctx->clone_roots + i; in find_extent_clone()
1621 cur_clone_root->ino = (u64)-1; in find_extent_clone()
1622 cur_clone_root->offset = 0; in find_extent_clone()
1623 cur_clone_root->num_bytes = 0; in find_extent_clone()
1624 cur_clone_root->found_ref = false; in find_extent_clone()
1636 backref_ctx.backref_offset = data_offset - btrfs_file_extent_offset(eb, fi); in find_extent_clone()
1644 backref_ctx.extent_len = ino_size - data_offset; in find_extent_clone()
1664 * since we can not use it for cloning - the source and destination in find_extent_clone()
1669 if (sctx->clone_roots_cnt == 1) in find_extent_clone()
1677 down_read(&fs_info->commit_root_sem); in find_extent_clone()
1678 if (fs_info->last_reloc_trans > sctx->last_reloc_trans) { in find_extent_clone()
1691 up_read(&fs_info->commit_root_sem); in find_extent_clone()
1692 return -ENOENT; in find_extent_clone()
1694 up_read(&fs_info->commit_root_sem); in find_extent_clone()
1702 return -ENOENT; in find_extent_clone()
1706 for (i = 0; i < sctx->clone_roots_cnt; i++) { in find_extent_clone()
1707 struct clone_root *clone_root = &sctx->clone_roots[i]; in find_extent_clone()
1709 if (!clone_root->found_ref) in find_extent_clone()
1718 clone_root->num_bytes > cur_clone_root->num_bytes) { in find_extent_clone()
1725 if (clone_root->num_bytes >= backref_ctx.extent_len) in find_extent_clone()
1734 ret = -ENOENT; in find_extent_clone()
1755 return -ENOMEM; in read_symlink()
1772 btrfs_err(root->fs_info, in read_symlink()
1775 ret = -EIO; in read_symlink()
1779 ei = btrfs_item_ptr(path->nodes[0], path->slots[0], in read_symlink()
1781 type = btrfs_file_extent_type(path->nodes[0], ei); in read_symlink()
1783 ret = -EUCLEAN; in read_symlink()
1784 btrfs_crit(root->fs_info, in read_symlink()
1789 compression = btrfs_file_extent_compression(path->nodes[0], ei); in read_symlink()
1791 ret = -EUCLEAN; in read_symlink()
1792 btrfs_crit(root->fs_info, in read_symlink()
1799 len = btrfs_file_extent_ram_bytes(path->nodes[0], ei); in read_symlink()
1801 ret = fs_path_add_from_extent_buffer(dest, path->nodes[0], off, len); in read_symlink()
1825 return -ENOMEM; in gen_unique_name()
1830 len = snprintf(tmp, sizeof(tmp), "o%llu-%llu-%llu", in gen_unique_name()
1836 di = btrfs_lookup_dir_item(NULL, sctx->send_root, in gen_unique_name()
1850 if (!sctx->parent_root) { in gen_unique_name()
1856 di = btrfs_lookup_dir_item(NULL, sctx->parent_root, in gen_unique_name()
1898 ret = get_inode_info(sctx->send_root, ino, &info); in get_cur_inode_state()
1899 if (ret < 0 && ret != -ENOENT) in get_cur_inode_state()
1901 left_ret = (info.nlink == 0) ? -ENOENT : ret; in get_cur_inode_state()
1904 *send_gen = ((left_ret == -ENOENT) ? 0 : info.gen); in get_cur_inode_state()
1906 if (!sctx->parent_root) { in get_cur_inode_state()
1907 right_ret = -ENOENT; in get_cur_inode_state()
1909 ret = get_inode_info(sctx->parent_root, ino, &info); in get_cur_inode_state()
1910 if (ret < 0 && ret != -ENOENT) in get_cur_inode_state()
1912 right_ret = (info.nlink == 0) ? -ENOENT : ret; in get_cur_inode_state()
1915 *parent_gen = ((right_ret == -ENOENT) ? 0 : info.gen); in get_cur_inode_state()
1922 if (ino < sctx->send_progress) in get_cur_inode_state()
1927 if (ino < sctx->send_progress) in get_cur_inode_state()
1932 ret = -ENOENT; in get_cur_inode_state()
1936 if (ino < sctx->send_progress) in get_cur_inode_state()
1941 ret = -ENOENT; in get_cur_inode_state()
1945 if (ino < sctx->send_progress) in get_cur_inode_state()
1950 ret = -ENOENT; in get_cur_inode_state()
1953 ret = -ENOENT; in get_cur_inode_state()
1998 return -ENOMEM; in lookup_dir_item_inode()
2002 ret = di ? PTR_ERR(di) : -ENOENT; in lookup_dir_item_inode()
2005 btrfs_dir_item_key_to_cpu(path->nodes[0], di, &key); in lookup_dir_item_inode()
2007 ret = -ENOENT; in lookup_dir_item_inode()
2033 return -ENOMEM; in get_first_ref()
2043 btrfs_item_key_to_cpu(path->nodes[0], &found_key, in get_first_ref()
2044 path->slots[0]); in get_first_ref()
2048 ret = -ENOENT; in get_first_ref()
2053 struct btrfs_inode_ref *iref; in get_first_ref() local
2054 iref = btrfs_item_ptr(path->nodes[0], path->slots[0], in get_first_ref()
2056 len = btrfs_inode_ref_name_len(path->nodes[0], iref); in get_first_ref()
2057 ret = fs_path_add_from_extent_buffer(name, path->nodes[0], in get_first_ref()
2058 (unsigned long)(iref + 1), in get_first_ref()
2063 extref = btrfs_item_ptr(path->nodes[0], path->slots[0], in get_first_ref()
2065 len = btrfs_inode_extref_name_len(path->nodes[0], extref); in get_first_ref()
2066 ret = fs_path_add_from_extent_buffer(name, path->nodes[0], in get_first_ref()
2067 (unsigned long)&extref->name, len); in get_first_ref()
2068 parent_dir = btrfs_inode_extref_parent(path->nodes[0], extref); in get_first_ref()
2097 return -ENOMEM; in is_first_ref()
2108 ret = !memcmp(tmp_name->start, name, name_len); in is_first_ref()
2134 if (!sctx->parent_root) in will_overwrite_ref()
2143 * not deleted and then re-created, if it was then we have no overwrite in will_overwrite_ref()
2149 if (sctx->parent_root && dir != BTRFS_FIRST_FREE_OBJECTID && in will_overwrite_ref()
2153 ret = lookup_dir_item_inode(sctx->parent_root, dir, name, name_len, in will_overwrite_ref()
2155 if (ret == -ENOENT) in will_overwrite_ref()
2165 if (other_inode > sctx->send_progress || in will_overwrite_ref()
2167 ret = get_inode_info(sctx->parent_root, other_inode, &info); in will_overwrite_ref()
2197 if (!sctx->parent_root) in did_overwrite_ref()
2212 ret = lookup_dir_item_inode(sctx->send_root, dir, name, name_len, in did_overwrite_ref()
2214 if (ret == -ENOENT) { in did_overwrite_ref()
2222 ret = get_inode_gen(sctx->send_root, ow_inode, &ow_gen); in did_overwrite_ref()
2237 if (ow_inode < sctx->send_progress) in did_overwrite_ref()
2240 if (ino != sctx->cur_ino && ow_inode == sctx->cur_ino) { in did_overwrite_ref()
2242 ret = get_inode_gen(sctx->send_root, ow_inode, &ow_gen); in did_overwrite_ref()
2246 if (ow_gen == sctx->cur_inode_gen) in did_overwrite_ref()
2265 if (!sctx->parent_root) in did_overwrite_first_ref()
2270 return -ENOMEM; in did_overwrite_first_ref()
2272 ret = get_first_ref(sctx->parent_root, ino, &dir, &dir_gen, name); in did_overwrite_first_ref()
2277 name->start, fs_path_len(name)); in did_overwrite_first_ref()
2289 entry = btrfs_lru_cache_lookup(&sctx->name_cache, ino, gen); in name_cache_search()
2316 * ino/gen. If yes, check if the cache entry is still up-to-date. If yes in __get_cur_name_and_parent()
2321 if (ino < sctx->send_progress && nce->need_later_update) { in __get_cur_name_and_parent()
2322 btrfs_lru_cache_remove(&sctx->name_cache, &nce->entry); in __get_cur_name_and_parent()
2325 *parent_ino = nce->parent_ino; in __get_cur_name_and_parent()
2326 *parent_gen = nce->parent_gen; in __get_cur_name_and_parent()
2327 ret = fs_path_add(dest, nce->name, nce->name_len); in __get_cur_name_and_parent()
2330 ret = nce->ret; in __get_cur_name_and_parent()
2356 if (ino < sctx->send_progress) in __get_cur_name_and_parent()
2357 ret = get_first_ref(sctx->send_root, ino, in __get_cur_name_and_parent()
2360 ret = get_first_ref(sctx->parent_root, ino, in __get_cur_name_and_parent()
2370 dest->start, dest->end - dest->start); in __get_cur_name_and_parent()
2387 ret = -ENOMEM; in __get_cur_name_and_parent()
2391 nce->entry.key = ino; in __get_cur_name_and_parent()
2392 nce->entry.gen = gen; in __get_cur_name_and_parent()
2393 nce->parent_ino = *parent_ino; in __get_cur_name_and_parent()
2394 nce->parent_gen = *parent_gen; in __get_cur_name_and_parent()
2395 nce->name_len = fs_path_len(dest); in __get_cur_name_and_parent()
2396 nce->ret = ret; in __get_cur_name_and_parent()
2397 memcpy(nce->name, dest->start, nce->name_len); in __get_cur_name_and_parent()
2399 if (ino < sctx->send_progress) in __get_cur_name_and_parent()
2400 nce->need_later_update = 0; in __get_cur_name_and_parent()
2402 nce->need_later_update = 1; in __get_cur_name_and_parent()
2404 nce_ret = btrfs_lru_cache_store(&sctx->name_cache, &nce->entry, GFP_KERNEL); in __get_cur_name_and_parent()
2436 * sctx->send_progress tells this function at which point in time receiving
2450 ret = -ENOMEM; in get_cur_path()
2454 dest->reversed = 1; in get_cur_path()
2471 if (wdm && wdm->orphanized) { in get_cur_path()
2475 ret = get_first_ref(sctx->parent_root, ino, in get_cur_path()
2509 struct btrfs_root *send_root = sctx->send_root; in send_subvol_begin()
2510 struct btrfs_root *parent_root = sctx->parent_root; in send_subvol_begin()
2520 return -ENOMEM; in send_subvol_begin()
2525 return -ENOMEM; in send_subvol_begin()
2532 ret = btrfs_search_slot_for_read(send_root->fs_info->tree_root, in send_subvol_begin()
2537 ret = -ENOENT; in send_subvol_begin()
2541 leaf = path->nodes[0]; in send_subvol_begin()
2542 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); in send_subvol_begin()
2545 ret = -ENOENT; in send_subvol_begin()
2548 ref = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_root_ref); in send_subvol_begin()
2565 if (!btrfs_is_empty_uuid(sctx->send_root->root_item.received_uuid)) in send_subvol_begin()
2567 sctx->send_root->root_item.received_uuid); in send_subvol_begin()
2570 sctx->send_root->root_item.uuid); in send_subvol_begin()
2573 btrfs_root_ctransid(&sctx->send_root->root_item)); in send_subvol_begin()
2575 if (!btrfs_is_empty_uuid(parent_root->root_item.received_uuid)) in send_subvol_begin()
2577 parent_root->root_item.received_uuid); in send_subvol_begin()
2580 parent_root->root_item.uuid); in send_subvol_begin()
2582 btrfs_root_ctransid(&sctx->parent_root->root_item)); in send_subvol_begin()
2596 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_truncate()
2604 return -ENOMEM; in send_truncate()
2626 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_chmod()
2634 return -ENOMEM; in send_chmod()
2656 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_fileattr()
2660 if (sctx->proto < 2) in send_fileattr()
2667 return -ENOMEM; in send_fileattr()
2689 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_chown()
2698 return -ENOMEM; in send_chown()
2721 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_utimes()
2734 return -ENOMEM; in send_utimes()
2738 ret = -ENOMEM; in send_utimes()
2745 ret = btrfs_search_slot(NULL, sctx->send_root, &key, path, 0, 0); in send_utimes()
2747 ret = -ENOENT; in send_utimes()
2751 eb = path->nodes[0]; in send_utimes()
2752 slot = path->slots[0]; in send_utimes()
2763 TLV_PUT_BTRFS_TIMESPEC(sctx, BTRFS_SEND_A_ATIME, eb, &ii->atime); in send_utimes()
2764 TLV_PUT_BTRFS_TIMESPEC(sctx, BTRFS_SEND_A_MTIME, eb, &ii->mtime); in send_utimes()
2765 TLV_PUT_BTRFS_TIMESPEC(sctx, BTRFS_SEND_A_CTIME, eb, &ii->ctime); in send_utimes()
2766 if (sctx->proto >= 2) in send_utimes()
2767 TLV_PUT_BTRFS_TIMESPEC(sctx, BTRFS_SEND_A_OTIME, eb, &ii->otime); in send_utimes()
2783 * full path - in which case we would generate outdated paths (pre-rename)
2793 entry = btrfs_lru_cache_lookup(&sctx->dir_utimes_cache, dir, gen); in cache_dir_utimes()
2802 entry->key = dir; in cache_dir_utimes()
2803 entry->gen = gen; in cache_dir_utimes()
2805 ret = btrfs_lru_cache_store(&sctx->dir_utimes_cache, entry, GFP_KERNEL); in cache_dir_utimes()
2806 ASSERT(ret != -EEXIST); in cache_dir_utimes()
2817 while (sctx->dir_utimes_cache.size > SEND_MAX_DIR_UTIMES_CACHE_SIZE) { in trim_dir_utimes_cache()
2821 lru = btrfs_lru_cache_lru_entry(&sctx->dir_utimes_cache); in trim_dir_utimes_cache()
2824 ret = send_utimes(sctx, lru->key, lru->gen); in trim_dir_utimes_cache()
2828 btrfs_lru_cache_remove(&sctx->dir_utimes_cache, lru); in trim_dir_utimes_cache()
2841 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_create_inode()
2854 return -ENOMEM; in send_create_inode()
2856 if (ino != sctx->cur_ino) { in send_create_inode()
2857 ret = get_inode_info(sctx->send_root, ino, &info); in send_create_inode()
2864 gen = sctx->cur_inode_gen; in send_create_inode()
2865 mode = sctx->cur_inode_mode; in send_create_inode()
2866 rdev = sctx->cur_inode_rdev; in send_create_inode()
2882 btrfs_warn(sctx->send_root->fs_info, "unexpected inode type %o", in send_create_inode()
2884 ret = -EOPNOTSUPP; in send_create_inode()
2901 ret = read_symlink(sctx->send_root, ino, p); in send_create_inode()
2932 entry->key = dir; in cache_dir_created()
2933 entry->gen = 0; in cache_dir_created()
2934 ret = btrfs_lru_cache_store(&sctx->dir_created_cache, entry, GFP_KERNEL); in cache_dir_created()
2954 if (btrfs_lru_cache_lookup(&sctx->dir_created_cache, dir, 0)) in did_create_dir()
2959 return -ENOMEM; in did_create_dir()
2965 btrfs_for_each_slot(sctx->send_root, &key, &found_key, path, iter_ret) { in did_create_dir()
2966 struct extent_buffer *eb = path->nodes[0]; in did_create_dir()
2974 di = btrfs_item_ptr(eb, path->slots[0], struct btrfs_dir_item); in did_create_dir()
2978 di_key.objectid < sctx->send_progress) { in did_create_dir()
3002 if (S_ISDIR(sctx->cur_inode_mode)) { in send_create_inode_if_needed()
3003 ret = did_create_dir(sctx, sctx->cur_ino); in send_create_inode_if_needed()
3010 ret = send_create_inode(sctx, sctx->cur_ino); in send_create_inode_if_needed()
3012 if (ret == 0 && S_ISDIR(sctx->cur_inode_mode)) in send_create_inode_if_needed()
3013 cache_dir_created(sctx, sctx->cur_ino); in send_create_inode_if_needed()
3036 RB_CLEAR_NODE(&ref->node); in recorded_ref_alloc()
3037 INIT_LIST_HEAD(&ref->list); in recorded_ref_alloc()
3045 if (!RB_EMPTY_NODE(&ref->node)) in recorded_ref_free()
3046 rb_erase(&ref->node, ref->root); in recorded_ref_free()
3047 list_del(&ref->list); in recorded_ref_free()
3048 fs_path_free(ref->full_path); in recorded_ref_free()
3054 ref->full_path = path; in set_ref_path()
3055 ref->name = (char *)kbasename(ref->full_path->start); in set_ref_path()
3056 ref->name_len = ref->full_path->end - ref->name; in set_ref_path()
3065 return -ENOMEM; in dup_ref()
3067 new->dir = ref->dir; in dup_ref()
3068 new->dir_gen = ref->dir_gen; in dup_ref()
3069 list_add_tail(&new->list, list); in dup_ref()
3078 cur = list_entry(head->next, struct recorded_ref, list); in __free_recorded_refs()
3085 __free_recorded_refs(&sctx->new_refs); in free_recorded_refs()
3086 __free_recorded_refs(&sctx->deleted_refs); in free_recorded_refs()
3102 return -ENOMEM; in orphanize_inode()
3118 struct rb_node **p = &sctx->orphan_dirs.rb_node; in add_orphan_dir_info()
3125 if (dir_ino < entry->ino) in add_orphan_dir_info()
3126 p = &(*p)->rb_left; in add_orphan_dir_info()
3127 else if (dir_ino > entry->ino) in add_orphan_dir_info()
3128 p = &(*p)->rb_right; in add_orphan_dir_info()
3129 else if (dir_gen < entry->gen) in add_orphan_dir_info()
3130 p = &(*p)->rb_left; in add_orphan_dir_info()
3131 else if (dir_gen > entry->gen) in add_orphan_dir_info()
3132 p = &(*p)->rb_right; in add_orphan_dir_info()
3139 return ERR_PTR(-ENOMEM); in add_orphan_dir_info()
3140 odi->ino = dir_ino; in add_orphan_dir_info()
3141 odi->gen = dir_gen; in add_orphan_dir_info()
3142 odi->last_dir_index_offset = 0; in add_orphan_dir_info()
3143 odi->dir_high_seq_ino = 0; in add_orphan_dir_info()
3145 rb_link_node(&odi->node, parent, p); in add_orphan_dir_info()
3146 rb_insert_color(&odi->node, &sctx->orphan_dirs); in add_orphan_dir_info()
3153 struct rb_node *n = sctx->orphan_dirs.rb_node; in get_orphan_dir_info()
3158 if (dir_ino < entry->ino) in get_orphan_dir_info()
3159 n = n->rb_left; in get_orphan_dir_info()
3160 else if (dir_ino > entry->ino) in get_orphan_dir_info()
3161 n = n->rb_right; in get_orphan_dir_info()
3162 else if (gen < entry->gen) in get_orphan_dir_info()
3163 n = n->rb_left; in get_orphan_dir_info()
3164 else if (gen > entry->gen) in get_orphan_dir_info()
3165 n = n->rb_right; in get_orphan_dir_info()
3184 rb_erase(&odi->node, &sctx->orphan_dirs); in free_orphan_dir_info()
3197 struct btrfs_root *root = sctx->parent_root; in can_rmdir()
3214 if (odi && sctx->cur_ino < odi->dir_high_seq_ino) in can_rmdir()
3219 return -ENOMEM; in can_rmdir()
3232 key.offset = (u64)-1; in can_rmdir()
3239 ASSERT(path->slots[0] > 0); in can_rmdir()
3240 if (WARN_ON(path->slots[0] == 0)) { in can_rmdir()
3241 ret = -EUCLEAN; in can_rmdir()
3244 path->slots[0]--; in can_rmdir()
3247 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); in can_rmdir()
3254 di = btrfs_item_ptr(path->nodes[0], path->slots[0], in can_rmdir()
3256 btrfs_dir_item_key_to_cpu(path->nodes[0], di, &loc); in can_rmdir()
3258 if (sctx->cur_ino < dir_high_seq_ino) { in can_rmdir()
3268 key.offset = (odi ? odi->last_dir_index_offset : 0); in can_rmdir()
3277 di = btrfs_item_ptr(path->nodes[0], path->slots[0], in can_rmdir()
3279 btrfs_dir_item_key_to_cpu(path->nodes[0], di, &loc); in can_rmdir()
3286 dm->rmdir_ino = dir; in can_rmdir()
3287 dm->rmdir_gen = dir_gen; in can_rmdir()
3292 if (loc.objectid > sctx->cur_ino) { in can_rmdir()
3316 odi->gen = dir_gen; in can_rmdir()
3319 odi->last_dir_index_offset = last_dir_index_offset; in can_rmdir()
3320 odi->dir_high_seq_ino = max(odi->dir_high_seq_ino, dir_high_seq_ino); in can_rmdir()
3334 struct rb_node **p = &sctx->waiting_dir_moves.rb_node; in add_waiting_dir_move()
3340 return -ENOMEM; in add_waiting_dir_move()
3341 dm->ino = ino; in add_waiting_dir_move()
3342 dm->rmdir_ino = 0; in add_waiting_dir_move()
3343 dm->rmdir_gen = 0; in add_waiting_dir_move()
3344 dm->orphanized = orphanized; in add_waiting_dir_move()
3349 if (ino < entry->ino) { in add_waiting_dir_move()
3350 p = &(*p)->rb_left; in add_waiting_dir_move()
3351 } else if (ino > entry->ino) { in add_waiting_dir_move()
3352 p = &(*p)->rb_right; in add_waiting_dir_move()
3355 return -EEXIST; in add_waiting_dir_move()
3359 rb_link_node(&dm->node, parent, p); in add_waiting_dir_move()
3360 rb_insert_color(&dm->node, &sctx->waiting_dir_moves); in add_waiting_dir_move()
3367 struct rb_node *n = sctx->waiting_dir_moves.rb_node; in get_waiting_dir_move()
3372 if (ino < entry->ino) in get_waiting_dir_move()
3373 n = n->rb_left; in get_waiting_dir_move()
3374 else if (ino > entry->ino) in get_waiting_dir_move()
3375 n = n->rb_right; in get_waiting_dir_move()
3387 rb_erase(&dm->node, &sctx->waiting_dir_moves); in free_waiting_dir_move()
3399 struct rb_node **p = &sctx->pending_dir_moves.rb_node; in add_pending_dir_move()
3408 return -ENOMEM; in add_pending_dir_move()
3409 pm->parent_ino = parent_ino; in add_pending_dir_move()
3410 pm->ino = ino; in add_pending_dir_move()
3411 pm->gen = ino_gen; in add_pending_dir_move()
3412 INIT_LIST_HEAD(&pm->list); in add_pending_dir_move()
3413 INIT_LIST_HEAD(&pm->update_refs); in add_pending_dir_move()
3414 RB_CLEAR_NODE(&pm->node); in add_pending_dir_move()
3419 if (parent_ino < entry->parent_ino) { in add_pending_dir_move()
3420 p = &(*p)->rb_left; in add_pending_dir_move()
3421 } else if (parent_ino > entry->parent_ino) { in add_pending_dir_move()
3422 p = &(*p)->rb_right; in add_pending_dir_move()
3430 ret = dup_ref(cur, &pm->update_refs); in add_pending_dir_move()
3435 ret = dup_ref(cur, &pm->update_refs); in add_pending_dir_move()
3440 ret = add_waiting_dir_move(sctx, pm->ino, is_orphan); in add_pending_dir_move()
3445 list_add_tail(&pm->list, &entry->list); in add_pending_dir_move()
3447 rb_link_node(&pm->node, parent, p); in add_pending_dir_move()
3448 rb_insert_color(&pm->node, &sctx->pending_dir_moves); in add_pending_dir_move()
3453 __free_recorded_refs(&pm->update_refs); in add_pending_dir_move()
3462 struct rb_node *n = sctx->pending_dir_moves.rb_node; in get_pending_dir_moves()
3467 if (parent_ino < entry->parent_ino) in get_pending_dir_moves()
3468 n = n->rb_left; in get_pending_dir_moves()
3469 else if (parent_ino > entry->parent_ino) in get_pending_dir_moves()
3470 n = n->rb_right; in get_pending_dir_moves()
3494 ret = get_first_ref(sctx->parent_root, ino, in path_loop()
3524 u64 orig_progress = sctx->send_progress; in apply_dir_move()
3537 ret = -ENOMEM; in apply_dir_move()
3541 dm = get_waiting_dir_move(sctx, pm->ino); in apply_dir_move()
3543 rmdir_ino = dm->rmdir_ino; in apply_dir_move()
3544 rmdir_gen = dm->rmdir_gen; in apply_dir_move()
3545 is_orphan = dm->orphanized; in apply_dir_move()
3549 ret = gen_unique_name(sctx, pm->ino, in apply_dir_move()
3550 pm->gen, from_path); in apply_dir_move()
3552 ret = get_first_ref(sctx->parent_root, pm->ino, in apply_dir_move()
3565 sctx->send_progress = sctx->cur_ino + 1; in apply_dir_move()
3566 ret = path_loop(sctx, name, pm->ino, pm->gen, &ancestor); in apply_dir_move()
3572 ret = add_pending_dir_move(sctx, pm->ino, pm->gen, ancestor, in apply_dir_move()
3573 &pm->update_refs, &deleted_refs, in apply_dir_move()
3578 dm = get_waiting_dir_move(sctx, pm->ino); in apply_dir_move()
3580 dm->rmdir_ino = rmdir_ino; in apply_dir_move()
3581 dm->rmdir_gen = rmdir_gen; in apply_dir_move()
3588 ret = get_cur_path(sctx, pm->ino, pm->gen, to_path); in apply_dir_move()
3605 gen = odi->gen; in apply_dir_move()
3615 ret = -ENOMEM; in apply_dir_move()
3627 ret = cache_dir_utimes(sctx, pm->ino, pm->gen); in apply_dir_move()
3635 list_for_each_entry(cur, &pm->update_refs, list) { in apply_dir_move()
3639 ret = get_inode_info(sctx->send_root, cur->dir, NULL); in apply_dir_move()
3640 if (ret == -ENOENT) { in apply_dir_move()
3647 ret = cache_dir_utimes(sctx, cur->dir, cur->dir_gen); in apply_dir_move()
3656 sctx->send_progress = orig_progress; in apply_dir_move()
3663 if (!list_empty(&m->list)) in free_pending_move()
3664 list_del(&m->list); in free_pending_move()
3665 if (!RB_EMPTY_NODE(&m->node)) in free_pending_move()
3666 rb_erase(&m->node, &sctx->pending_dir_moves); in free_pending_move()
3667 __free_recorded_refs(&m->update_refs); in free_pending_move()
3675 if (list_empty(&moves->list)) { in tail_append_pending_moves()
3676 list_add_tail(&moves->list, stack); in tail_append_pending_moves()
3679 list_splice_init(&moves->list, &list); in tail_append_pending_moves()
3680 list_add_tail(&moves->list, stack); in tail_append_pending_moves()
3683 if (!RB_EMPTY_NODE(&moves->node)) { in tail_append_pending_moves()
3684 rb_erase(&moves->node, &sctx->pending_dir_moves); in tail_append_pending_moves()
3685 RB_CLEAR_NODE(&moves->node); in tail_append_pending_moves()
3693 u64 parent_ino = sctx->cur_ino; in apply_children_dir_moves()
3704 parent_ino = pm->ino; in apply_children_dir_moves()
3725 * (in the send root) with a higher inode number than ours (sctx->cur_ino) was
3734 * |---- a/ (ino 257)
3735 * | |---- file (ino 260)
3737 * |---- b/ (ino 258)
3738 * |---- c/ (ino 259)
3742 * |---- a/ (ino 258)
3743 * |---- x/ (ino 259)
3744 * |---- y/ (ino 257)
3745 * |----- file (ino 260)
3752 * 1 - rename 259 from 'c' to 'x'
3753 * 2 - rename 257 from 'a' to 'x/y'
3754 * 3 - rename 258 from 'b' to 'a'
3756 * Returns 1 if the rename of sctx->cur_ino needs to be delayed, 0 if it can
3772 if (RB_EMPTY_ROOT(&sctx->waiting_dir_moves)) in wait_for_dest_dir_move()
3777 return -ENOMEM; in wait_for_dest_dir_move()
3779 key.objectid = parent_ref->dir; in wait_for_dest_dir_move()
3781 key.offset = btrfs_name_hash(parent_ref->name, parent_ref->name_len); in wait_for_dest_dir_move()
3783 ret = btrfs_search_slot(NULL, sctx->parent_root, &key, path, 0, 0); in wait_for_dest_dir_move()
3791 di = btrfs_match_dir_item_name(path, parent_ref->name, in wait_for_dest_dir_move()
3792 parent_ref->name_len); in wait_for_dest_dir_move()
3799 * parent directory with the same name that sctx->cur_ino is being in wait_for_dest_dir_move()
3802 * if it is, we need to delay the rename of sctx->cur_ino as well, so in wait_for_dest_dir_move()
3805 btrfs_dir_item_key_to_cpu(path->nodes[0], di, &di_key); in wait_for_dest_dir_move()
3811 ret = get_inode_gen(sctx->parent_root, di_key.objectid, &left_gen); in wait_for_dest_dir_move()
3814 ret = get_inode_gen(sctx->send_root, di_key.objectid, &right_gen); in wait_for_dest_dir_move()
3816 if (ret == -ENOENT) in wait_for_dest_dir_move()
3821 /* Different inode, no need to delay the rename of sctx->cur_ino */ in wait_for_dest_dir_move()
3828 if (wdm && !wdm->orphanized) { in wait_for_dest_dir_move()
3830 sctx->cur_ino, in wait_for_dest_dir_move()
3831 sctx->cur_inode_gen, in wait_for_dest_dir_move()
3833 &sctx->new_refs, in wait_for_dest_dir_move()
3834 &sctx->deleted_refs, in wait_for_dest_dir_move()
3896 return -ENOMEM; in is_ancestor()
3902 ret = -ENOMEM; in is_ancestor()
3911 struct extent_buffer *leaf = path->nodes[0]; in is_ancestor()
3912 int slot = path->slots[0]; in is_ancestor()
3969 u64 ino = parent_ref->dir; in wait_for_parent_move()
3970 u64 ino_gen = parent_ref->dir_gen; in wait_for_parent_move()
3979 ret = -ENOMEM; in wait_for_parent_move()
4004 ret = is_ancestor(sctx->parent_root, in wait_for_parent_move()
4005 sctx->cur_ino, sctx->cur_inode_gen, in wait_for_parent_move()
4014 ret = get_first_ref(sctx->send_root, ino, &parent_ino_after, in wait_for_parent_move()
4018 ret = get_first_ref(sctx->parent_root, ino, &parent_ino_before, in wait_for_parent_move()
4020 if (ret < 0 && ret != -ENOENT) { in wait_for_parent_move()
4022 } else if (ret == -ENOENT) { in wait_for_parent_move()
4029 if (ino > sctx->cur_ino && in wait_for_parent_move()
4031 memcmp(path_before->start, path_after->start, len1))) { in wait_for_parent_move()
4034 ret = get_inode_gen(sctx->parent_root, ino, &parent_ino_gen); in wait_for_parent_move()
4052 sctx->cur_ino, in wait_for_parent_move()
4053 sctx->cur_inode_gen, in wait_for_parent_move()
4055 &sctx->new_refs, in wait_for_parent_move()
4056 &sctx->deleted_refs, in wait_for_parent_move()
4076 return -ENOMEM; in update_ref_path()
4078 ret = get_cur_path(sctx, ref->dir, ref->dir_gen, new_path); in update_ref_path()
4083 ret = fs_path_add(new_path, ref->name, ref->name_len); in update_ref_path()
4089 fs_path_free(ref->full_path); in update_ref_path()
4100 * reference reflects the pre-orphanization name of the directory we previously
4106 * |----- f1 (ino 257)
4107 * |----- f2 (ino 258)
4108 * |----- d1/ (ino 259)
4109 * |----- d2/ (ino 260)
4114 * |----- d1 (ino 258)
4115 * |----- f2/ (ino 259)
4116 * |----- f2_link/ (ino 260)
4117 * | |----- f1 (ino 257)
4119 * |----- d2 (ino 258)
4128 * orphanize inode 260, as its old reference conflicts with ours - but for the
4130 * new reference, which is "d1/d2" and not "o259-6-0/d2" - this makes the
4132 * to "o259-6-0/" when processing the previous new reference. So in this case we
4141 name = kmemdup(ref->name, ref->name_len, GFP_KERNEL); in refresh_ref_path()
4143 return -ENOMEM; in refresh_ref_path()
4145 fs_path_reset(ref->full_path); in refresh_ref_path()
4146 ret = get_cur_path(sctx, ref->dir, ref->dir_gen, ref->full_path); in refresh_ref_path()
4150 ret = fs_path_add(ref->full_path, name, ref->name_len); in refresh_ref_path()
4155 set_ref_path(ref, ref->full_path); in refresh_ref_path()
4166 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in process_recorded_refs()
4182 btrfs_debug(fs_info, "process_recorded_refs %llu", sctx->cur_ino); in process_recorded_refs()
4188 if (unlikely(sctx->cur_ino <= BTRFS_FIRST_FREE_OBJECTID)) { in process_recorded_refs()
4191 sctx->cur_ino); in process_recorded_refs()
4192 ret = -EINVAL; in process_recorded_refs()
4198 ret = -ENOMEM; in process_recorded_refs()
4213 if (!sctx->cur_inode_new) { in process_recorded_refs()
4214 ret = did_overwrite_first_ref(sctx, sctx->cur_ino, in process_recorded_refs()
4215 sctx->cur_inode_gen); in process_recorded_refs()
4221 if (sctx->cur_inode_new || did_overwrite) { in process_recorded_refs()
4222 ret = gen_unique_name(sctx, sctx->cur_ino, in process_recorded_refs()
4223 sctx->cur_inode_gen, valid_path); in process_recorded_refs()
4228 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, in process_recorded_refs()
4248 * |----- testdir/ (ino 259) in process_recorded_refs()
4249 * | |----- a (ino 257) in process_recorded_refs()
4251 * |----- b (ino 258) in process_recorded_refs()
4256 * |----- testdir_2/ (ino 259) in process_recorded_refs()
4257 * | |----- a (ino 260) in process_recorded_refs()
4259 * |----- testdir (ino 257) in process_recorded_refs()
4260 * |----- b (ino 257) in process_recorded_refs()
4261 * |----- b2 (ino 258) in process_recorded_refs()
4272 list_for_each_entry(cur, &sctx->new_refs, list) { in process_recorded_refs()
4273 ret = get_cur_inode_state(sctx, cur->dir, cur->dir_gen, NULL, NULL); in process_recorded_refs()
4285 ret = will_overwrite_ref(sctx, cur->dir, cur->dir_gen, in process_recorded_refs()
4286 cur->name, cur->name_len, in process_recorded_refs()
4291 ret = is_first_ref(sctx->parent_root, in process_recorded_refs()
4292 ow_inode, cur->dir, cur->name, in process_recorded_refs()
4293 cur->name_len); in process_recorded_refs()
4307 cur->full_path); in process_recorded_refs()
4321 wdm->orphanized = true; in process_recorded_refs()
4329 * sctx->send_progress. We need to prevent in process_recorded_refs()
4335 btrfs_lru_cache_remove(&sctx->name_cache, in process_recorded_refs()
4336 &nce->entry); in process_recorded_refs()
4342 * might contain the pre-orphanization name of in process_recorded_refs()
4345 ret = is_ancestor(sctx->parent_root, in process_recorded_refs()
4347 sctx->cur_ino, NULL); in process_recorded_refs()
4351 ret = get_cur_path(sctx, sctx->cur_ino, in process_recorded_refs()
4352 sctx->cur_inode_gen, in process_recorded_refs()
4369 ret = send_unlink(sctx, cur->full_path); in process_recorded_refs()
4377 list_for_each_entry(cur, &sctx->new_refs, list) { in process_recorded_refs()
4385 ret = get_cur_inode_state(sctx, cur->dir, cur->dir_gen, NULL, NULL); in process_recorded_refs()
4394 list_for_each_entry(cur2, &sctx->new_refs, list) { in process_recorded_refs()
4397 if (cur2->dir == cur->dir) { in process_recorded_refs()
4408 ret = did_create_dir(sctx, cur->dir); in process_recorded_refs()
4412 ret = send_create_inode(sctx, cur->dir); in process_recorded_refs()
4415 cache_dir_created(sctx, cur->dir); in process_recorded_refs()
4419 if (S_ISDIR(sctx->cur_inode_mode) && sctx->parent_root) { in process_recorded_refs()
4429 if (S_ISDIR(sctx->cur_inode_mode) && sctx->parent_root && in process_recorded_refs()
4446 ret = send_rename(sctx, valid_path, cur->full_path); in process_recorded_refs()
4450 ret = fs_path_copy(valid_path, cur->full_path); in process_recorded_refs()
4454 if (S_ISDIR(sctx->cur_inode_mode)) { in process_recorded_refs()
4461 cur->full_path); in process_recorded_refs()
4464 cur->full_path); in process_recorded_refs()
4480 ret = send_link(sctx, cur->full_path, in process_recorded_refs()
4491 if (S_ISDIR(sctx->cur_inode_mode) && sctx->cur_inode_deleted) { in process_recorded_refs()
4498 ret = can_rmdir(sctx, sctx->cur_ino, sctx->cur_inode_gen); in process_recorded_refs()
4506 ret = orphanize_inode(sctx, sctx->cur_ino, in process_recorded_refs()
4507 sctx->cur_inode_gen, valid_path); in process_recorded_refs()
4513 list_for_each_entry(cur, &sctx->deleted_refs, list) { in process_recorded_refs()
4518 } else if (S_ISDIR(sctx->cur_inode_mode) && in process_recorded_refs()
4519 !list_empty(&sctx->deleted_refs)) { in process_recorded_refs()
4523 cur = list_entry(sctx->deleted_refs.next, struct recorded_ref, in process_recorded_refs()
4528 } else if (!S_ISDIR(sctx->cur_inode_mode)) { in process_recorded_refs()
4534 list_for_each_entry(cur, &sctx->deleted_refs, list) { in process_recorded_refs()
4535 ret = did_overwrite_ref(sctx, cur->dir, cur->dir_gen, in process_recorded_refs()
4536 sctx->cur_ino, sctx->cur_inode_gen, in process_recorded_refs()
4537 cur->name, cur->name_len); in process_recorded_refs()
4553 ret = send_unlink(sctx, cur->full_path); in process_recorded_refs()
4588 if (cur->dir > sctx->cur_ino) in process_recorded_refs()
4591 ret = get_cur_inode_state(sctx, cur->dir, cur->dir_gen, NULL, NULL); in process_recorded_refs()
4597 ret = cache_dir_utimes(sctx, cur->dir, cur->dir_gen); in process_recorded_refs()
4601 cur->dir != last_dir_ino_rm) { in process_recorded_refs()
4602 ret = can_rmdir(sctx, cur->dir, cur->dir_gen); in process_recorded_refs()
4606 ret = get_cur_path(sctx, cur->dir, in process_recorded_refs()
4607 cur->dir_gen, valid_path); in process_recorded_refs()
4613 last_dir_ino_rm = cur->dir; in process_recorded_refs()
4633 if (data->dir > ref->dir) in rbtree_ref_comp()
4635 if (data->dir < ref->dir) in rbtree_ref_comp()
4636 return -1; in rbtree_ref_comp()
4637 if (data->dir_gen > ref->dir_gen) in rbtree_ref_comp()
4639 if (data->dir_gen < ref->dir_gen) in rbtree_ref_comp()
4640 return -1; in rbtree_ref_comp()
4641 if (data->name_len > ref->name_len) in rbtree_ref_comp()
4643 if (data->name_len < ref->name_len) in rbtree_ref_comp()
4644 return -1; in rbtree_ref_comp()
4645 result = strcmp(data->name, ref->name); in rbtree_ref_comp()
4649 return -1; in rbtree_ref_comp()
4670 ret = -ENOMEM; in record_ref_in_tree()
4676 ret = -ENOMEM; in record_ref_in_tree()
4687 ref->dir = dir; in record_ref_in_tree()
4688 ref->dir_gen = dir_gen; in record_ref_in_tree()
4690 list_add_tail(&ref->list, refs); in record_ref_in_tree()
4691 rb_add(&ref->node, root, rbtree_ref_less); in record_ref_in_tree()
4692 ref->root = root; in record_ref_in_tree()
4695 if (path && (!ref || !ref->full_path)) in record_ref_in_tree()
4711 ret = get_inode_gen(sctx->send_root, dir, &dir_gen); in record_new_ref_if_needed()
4718 node = rb_find(&data, &sctx->rbtree_deleted_refs, rbtree_ref_comp); in record_new_ref_if_needed()
4723 ret = record_ref_in_tree(&sctx->rbtree_new_refs, in record_new_ref_if_needed()
4724 &sctx->new_refs, name, dir, dir_gen, in record_new_ref_if_needed()
4740 ret = get_inode_gen(sctx->parent_root, dir, &dir_gen); in record_deleted_ref_if_needed()
4747 node = rb_find(&data, &sctx->rbtree_new_refs, rbtree_ref_comp); in record_deleted_ref_if_needed()
4752 ret = record_ref_in_tree(&sctx->rbtree_deleted_refs, in record_deleted_ref_if_needed()
4753 &sctx->deleted_refs, name, dir, in record_deleted_ref_if_needed()
4764 ret = iterate_inode_ref(sctx->send_root, sctx->left_path, in record_new_ref()
4765 sctx->cmp_key, 0, record_new_ref_if_needed, sctx); in record_new_ref()
4778 ret = iterate_inode_ref(sctx->parent_root, sctx->right_path, in record_deleted_ref()
4779 sctx->cmp_key, 0, record_deleted_ref_if_needed, in record_deleted_ref()
4793 ret = iterate_inode_ref(sctx->send_root, sctx->left_path, in record_changed_ref()
4794 sctx->cmp_key, 0, record_new_ref_if_needed, sctx); in record_changed_ref()
4797 ret = iterate_inode_ref(sctx->parent_root, sctx->right_path, in record_changed_ref()
4798 sctx->cmp_key, 0, record_deleted_ref_if_needed, sctx); in record_changed_ref()
4825 return -ENOMEM; in process_all_refs()
4828 root = sctx->send_root; in process_all_refs()
4831 root = sctx->parent_root; in process_all_refs()
4834 btrfs_err(sctx->send_root->fs_info, in process_all_refs()
4836 ret = -EINVAL; in process_all_refs()
4840 key.objectid = sctx->cmp_key->objectid; in process_all_refs()
4862 * re-creating this inode and will be rename'ing it into place once we in process_all_refs()
4928 return -ENOMEM; in __process_new_xattr()
4946 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); in __process_new_xattr()
4967 return -ENOMEM; in __process_deleted_xattr()
4969 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); in __process_deleted_xattr()
4984 ret = iterate_dir_item(sctx->send_root, sctx->left_path, in process_new_xattr()
4992 return iterate_dir_item(sctx->parent_root, sctx->right_path, in process_deleted_xattr()
5009 if (name_len == ctx->name_len && in __find_xattr()
5010 strncmp(name, ctx->name, name_len) == 0) { in __find_xattr()
5011 ctx->found_idx = num; in __find_xattr()
5012 ctx->found_data_len = data_len; in __find_xattr()
5013 ctx->found_data = kmemdup(data, data_len, GFP_KERNEL); in __find_xattr()
5014 if (!ctx->found_data) in __find_xattr()
5015 return -ENOMEM; in __find_xattr()
5032 ctx.found_idx = -1; in find_xattr()
5040 if (ctx.found_idx == -1) in find_xattr()
5041 return -ENOENT; in find_xattr()
5062 ret = find_xattr(sctx->parent_root, sctx->right_path, in __process_changed_new_xattr()
5063 sctx->cmp_key, name, name_len, &found_data, in __process_changed_new_xattr()
5065 if (ret == -ENOENT) { in __process_changed_new_xattr()
5090 ret = find_xattr(sctx->send_root, sctx->left_path, sctx->cmp_key, in __process_changed_deleted_xattr()
5092 if (ret == -ENOENT) in __process_changed_deleted_xattr()
5105 ret = iterate_dir_item(sctx->send_root, sctx->left_path, in process_changed_xattr()
5109 ret = iterate_dir_item(sctx->parent_root, sctx->right_path, in process_changed_xattr()
5127 return -ENOMEM; in process_all_new_xattrs()
5129 root = sctx->send_root; in process_all_new_xattrs()
5131 key.objectid = sctx->cmp_key->objectid; in process_all_new_xattrs()
5164 le8_to_cpu(desc->hash_algorithm)); in send_verity()
5166 1U << le8_to_cpu(desc->log_blocksize)); in send_verity()
5167 TLV_PUT(sctx, BTRFS_SEND_A_VERITY_SALT_DATA, desc->salt, in send_verity()
5168 le8_to_cpu(desc->salt_size)); in send_verity()
5169 TLV_PUT(sctx, BTRFS_SEND_A_VERITY_SIG_DATA, desc->signature, in send_verity()
5170 le32_to_cpu(desc->sig_size)); in send_verity()
5185 inode = btrfs_iget(sctx->cur_ino, sctx->send_root); in process_verity()
5194 ret = -EMSGSIZE; in process_verity()
5197 if (!sctx->verity_descriptor) { in process_verity()
5198 sctx->verity_descriptor = kvmalloc(FS_VERITY_MAX_DESCRIPTOR_SIZE, in process_verity()
5200 if (!sctx->verity_descriptor) { in process_verity()
5201 ret = -ENOMEM; in process_verity()
5206 ret = btrfs_get_verity_descriptor(inode, sctx->verity_descriptor, ret); in process_verity()
5212 ret = -ENOMEM; in process_verity()
5215 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); in process_verity()
5219 ret = send_verity(sctx, p, sctx->verity_descriptor); in process_verity()
5232 return sctx->send_max_size - SZ_16K; in max_send_read_size()
5237 if (WARN_ON_ONCE(sctx->put_data)) in put_data_header()
5238 return -EINVAL; in put_data_header()
5239 sctx->put_data = true; in put_data_header()
5240 if (sctx->proto >= 2) { in put_data_header()
5245 if (sctx->send_max_size - sctx->send_size < sizeof(__le16) + len) in put_data_header()
5246 return -EOVERFLOW; in put_data_header()
5247 put_unaligned_le16(BTRFS_SEND_A_DATA, sctx->send_buf + sctx->send_size); in put_data_header()
5248 sctx->send_size += sizeof(__le16); in put_data_header()
5252 if (sctx->send_max_size - sctx->send_size < sizeof(*hdr) + len) in put_data_header()
5253 return -EOVERFLOW; in put_data_header()
5254 hdr = (struct btrfs_tlv_header *)(sctx->send_buf + sctx->send_size); in put_data_header()
5255 put_unaligned_le16(BTRFS_SEND_A_DATA, &hdr->tlv_type); in put_data_header()
5256 put_unaligned_le16(len, &hdr->tlv_len); in put_data_header()
5257 sctx->send_size += sizeof(*hdr); in put_data_header()
5264 struct btrfs_root *root = sctx->send_root; in put_file_data()
5265 struct btrfs_fs_info *fs_info = root->fs_info; in put_file_data()
5270 struct address_space *mapping = sctx->cur_inode->i_mapping; in put_file_data()
5277 last_index = (offset + len - 1) >> PAGE_SHIFT; in put_file_data()
5281 PAGE_SIZE - pg_offset); in put_file_data()
5286 &sctx->ra, NULL, index, in put_file_data()
5287 last_index + 1 - index); in put_file_data()
5299 page_cache_async_readahead(mapping, &sctx->ra, NULL, folio, in put_file_data()
5300 last_index + 1 - index); in put_file_data()
5309 folio_pos(folio), sctx->cur_ino, in put_file_data()
5310 btrfs_root_id(sctx->send_root)); in put_file_data()
5312 ret = -EIO; in put_file_data()
5317 memcpy_from_folio(sctx->send_buf + sctx->send_size, folio, in put_file_data()
5323 len -= cur_len; in put_file_data()
5324 sctx->send_size += cur_len; in put_file_data()
5336 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_write()
5342 return -ENOMEM; in send_write()
5350 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); in send_write()
5379 btrfs_debug(sctx->send_root->fs_info, in send_clone()
5381 offset, len, btrfs_root_id(clone_root->root), in send_clone()
5382 clone_root->ino, clone_root->offset); in send_clone()
5386 return -ENOMEM; in send_clone()
5392 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); in send_clone()
5400 if (clone_root->root == sctx->send_root) { in send_clone()
5401 ret = get_inode_gen(sctx->send_root, clone_root->ino, &gen); in send_clone()
5404 ret = get_cur_path(sctx, clone_root->ino, gen, p); in send_clone()
5406 ret = get_inode_path(clone_root->root, clone_root->ino, p); in send_clone()
5420 if (!btrfs_is_empty_uuid(clone_root->root->root_item.received_uuid)) in send_clone()
5422 clone_root->root->root_item.received_uuid); in send_clone()
5425 clone_root->root->root_item.uuid); in send_clone()
5427 btrfs_root_ctransid(&clone_root->root->root_item)); in send_clone()
5430 clone_root->offset); in send_clone()
5451 return -ENOMEM; in send_update_extent()
5457 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); in send_update_extent()
5477 u64 offset = sctx->cur_inode_last_extent; in send_hole()
5486 if (offset >= sctx->cur_inode_size) in send_hole()
5493 end = min_t(u64, end, sctx->cur_inode_size); in send_hole()
5495 if (sctx->flags & BTRFS_SEND_FLAG_NO_FILE_DATA) in send_hole()
5496 return send_update_extent(sctx, offset, end - offset); in send_hole()
5500 return -ENOMEM; in send_hole()
5501 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); in send_hole()
5505 u64 len = min(end - offset, read_size); in send_hole()
5515 memset(sctx->send_buf + sctx->send_size, 0, len); in send_hole()
5516 sctx->send_size += len; in send_hole()
5522 sctx->cur_inode_next_write_offset = offset; in send_hole()
5532 struct btrfs_root *root = sctx->send_root; in send_encoded_inline_extent()
5533 struct btrfs_fs_info *fs_info = root->fs_info; in send_encoded_inline_extent()
5536 struct extent_buffer *leaf = path->nodes[0]; in send_encoded_inline_extent()
5543 inode = btrfs_iget(sctx->cur_ino, root); in send_encoded_inline_extent()
5549 ret = -ENOMEM; in send_encoded_inline_extent()
5557 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, fspath); in send_encoded_inline_extent()
5561 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); in send_encoded_inline_extent()
5562 ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_file_extent_item); in send_encoded_inline_extent()
5564 inline_size = btrfs_file_extent_inline_item_len(leaf, path->slots[0]); in send_encoded_inline_extent()
5569 min(key.offset + ram_bytes - offset, len)); in send_encoded_inline_extent()
5571 TLV_PUT_U64(sctx, BTRFS_SEND_A_UNENCODED_OFFSET, offset - key.offset); in send_encoded_inline_extent()
5581 read_extent_buffer(leaf, sctx->send_buf + sctx->send_size, in send_encoded_inline_extent()
5583 sctx->send_size += inline_size; in send_encoded_inline_extent()
5597 struct btrfs_root *root = sctx->send_root; in send_encoded_extent()
5598 struct btrfs_fs_info *fs_info = root->fs_info; in send_encoded_extent()
5601 struct extent_buffer *leaf = path->nodes[0]; in send_encoded_extent()
5610 inode = btrfs_iget(sctx->cur_ino, root); in send_encoded_extent()
5616 ret = -ENOMEM; in send_encoded_extent()
5624 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, fspath); in send_encoded_extent()
5628 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); in send_encoded_extent()
5629 ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_file_extent_item); in send_encoded_extent()
5636 min(key.offset + btrfs_file_extent_num_bytes(leaf, ei) - offset, in send_encoded_extent()
5641 offset - key.offset + btrfs_file_extent_offset(leaf, ei)); in send_encoded_extent()
5658 data_offset = PAGE_ALIGN(sctx->send_size); in send_encoded_extent()
5659 if (data_offset > sctx->send_max_size || in send_encoded_extent()
5660 sctx->send_max_size - data_offset < disk_num_bytes) { in send_encoded_extent()
5661 ret = -EOVERFLOW; in send_encoded_extent()
5671 sctx->send_buf_pages + in send_encoded_extent()
5677 hdr = (struct btrfs_cmd_header *)sctx->send_buf; in send_encoded_extent()
5678 hdr->len = cpu_to_le32(sctx->send_size + disk_num_bytes - sizeof(*hdr)); in send_encoded_extent()
5679 hdr->crc = 0; in send_encoded_extent()
5680 crc = crc32c(0, sctx->send_buf, sctx->send_size); in send_encoded_extent()
5681 crc = crc32c(crc, sctx->send_buf + data_offset, disk_num_bytes); in send_encoded_extent()
5682 hdr->crc = cpu_to_le32(crc); in send_encoded_extent()
5684 ret = write_buf(sctx->send_filp, sctx->send_buf, sctx->send_size, in send_encoded_extent()
5685 &sctx->send_off); in send_encoded_extent()
5687 ret = write_buf(sctx->send_filp, sctx->send_buf + data_offset, in send_encoded_extent()
5688 disk_num_bytes, &sctx->send_off); in send_encoded_extent()
5690 sctx->send_size = 0; in send_encoded_extent()
5691 sctx->put_data = false; in send_encoded_extent()
5704 struct extent_buffer *leaf = path->nodes[0]; in send_extent_data()
5709 if (sctx->flags & BTRFS_SEND_FLAG_NO_FILE_DATA) in send_extent_data()
5712 ei = btrfs_item_ptr(leaf, path->slots[0], in send_extent_data()
5714 if ((sctx->flags & BTRFS_SEND_FLAG_COMPRESSED) && in send_extent_data()
5728 path->slots[0]) <= len) { in send_extent_data()
5737 if (sctx->cur_inode == NULL) { in send_extent_data()
5738 struct btrfs_root *root = sctx->send_root; in send_extent_data()
5740 sctx->cur_inode = btrfs_iget(sctx->cur_ino, root); in send_extent_data()
5741 if (IS_ERR(sctx->cur_inode)) { in send_extent_data()
5742 int err = PTR_ERR(sctx->cur_inode); in send_extent_data()
5744 sctx->cur_inode = NULL; in send_extent_data()
5747 memset(&sctx->ra, 0, sizeof(struct file_ra_state)); in send_extent_data()
5748 file_ra_state_init(&sctx->ra, sctx->cur_inode->i_mapping); in send_extent_data()
5769 sctx->clean_page_cache = (sctx->cur_inode->i_mapping->nrpages == 0); in send_extent_data()
5770 sctx->page_cache_clear_start = round_down(offset, PAGE_SIZE); in send_extent_data()
5774 u64 size = min(len - sent, read_size); in send_extent_data()
5783 if (sctx->clean_page_cache && PAGE_ALIGNED(end)) { in send_extent_data()
5807 truncate_inode_pages_range(&sctx->cur_inode->i_data, in send_extent_data()
5808 sctx->page_cache_clear_start, in send_extent_data()
5809 end - 1); in send_extent_data()
5810 sctx->page_cache_clear_start = end; in send_extent_data()
5817 * Search for a capability xattr related to sctx->cur_ino. If the capability is
5836 return -ENOMEM; in send_capabilities()
5838 di = btrfs_lookup_xattr(NULL, sctx->send_root, path, sctx->cur_ino, in send_capabilities()
5848 leaf = path->nodes[0]; in send_capabilities()
5854 ret = -ENOMEM; in send_capabilities()
5858 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, fspath); in send_capabilities()
5899 if (clone_root->offset == 0 && in clone_range()
5900 len == sctx->send_root->fs_info->sectorsize) in clone_range()
5905 return -ENOMEM; in clone_range()
5911 ret = get_inode_info(clone_root->root, clone_root->ino, &info); in clone_range()
5926 * mkfs.btrfs -f /dev/sda in clone_range()
5928 * xfs_io -f -c "pwrite -S 0xaa 0K 100K" /mnt/foo in clone_range()
5929 * cp --reflink=always /mnt/foo /mnt/bar in clone_range()
5930 * xfs_io -c "pwrite -S 0xbb 50K 50K" /mnt/foo in clone_range()
5931 * btrfs subvolume snapshot -r /mnt /mnt/snap in clone_range()
5936 * a file bar that matches the content of file foo - iow, doesn't match in clone_range()
5939 key.objectid = clone_root->ino; in clone_range()
5941 key.offset = clone_root->offset; in clone_range()
5942 ret = btrfs_search_slot(NULL, clone_root->root, &key, path, 0, 0); in clone_range()
5945 if (ret > 0 && path->slots[0] > 0) { in clone_range()
5946 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0] - 1); in clone_range()
5947 if (key.objectid == clone_root->ino && in clone_range()
5949 path->slots[0]--; in clone_range()
5953 struct extent_buffer *leaf = path->nodes[0]; in clone_range()
5954 int slot = path->slots[0]; in clone_range()
5963 ret = btrfs_next_leaf(clone_root->root, path); in clone_range()
5977 if (key.objectid != clone_root->ino || in clone_range()
5990 if (key.offset + ext_len <= clone_root->offset) in clone_range()
5993 if (key.offset > clone_root->offset) { in clone_range()
5995 u64 hole_len = key.offset - clone_root->offset; in clone_range()
6004 len -= hole_len; in clone_range()
6008 clone_root->offset += hole_len; in clone_range()
6012 if (key.offset >= clone_root->offset + len) in clone_range()
6019 ext_len = clone_src_i_size - key.offset; in clone_range()
6025 clone_root->offset = key.offset; in clone_range()
6030 extent_offset = data_offset - clone_data_offset; in clone_range()
6031 ext_len -= extent_offset; in clone_range()
6033 clone_root->offset += extent_offset; in clone_range()
6041 const u64 src_end = clone_root->offset + clone_len; in clone_range()
6047 * do so, the receiver will get a failure (-EINVAL) when in clone_range()
6064 offset + clone_len < sctx->cur_inode_size) { in clone_range()
6067 slen = ALIGN_DOWN(src_end - clone_root->offset, in clone_range()
6077 clone_len - slen); in clone_range()
6088 * this loop with a length of len - clone_len. in clone_range()
6098 * possible re-compression at the receiver. in clone_range()
6109 len -= clone_len; in clone_range()
6113 clone_root->offset += clone_len; in clone_range()
6124 if (clone_root->root == sctx->send_root && in clone_range()
6125 clone_root->ino == sctx->cur_ino && in clone_range()
6126 clone_root->offset >= sctx->cur_inode_next_write_offset) in clone_range()
6131 path->slots[0]++; in clone_range()
6149 u64 offset = key->offset; in send_write_or_clone()
6151 u64 bs = sctx->send_root->fs_info->sectorsize; in send_write_or_clone()
6158 end = min_t(u64, btrfs_file_extent_end(path), sctx->cur_inode_size); in send_write_or_clone()
6162 num_bytes = end - offset; in send_write_or_clone()
6173 * source inode, otherwise the clone operation fails with -EINVAL. in send_write_or_clone()
6175 if (end != sctx->cur_inode_size) in send_write_or_clone()
6178 ret = get_inode_info(clone_root->root, clone_root->ino, &info); in send_write_or_clone()
6182 if (clone_root->offset + num_bytes == info.size) { in send_write_or_clone()
6197 if (sctx->parent_root != NULL) { in send_write_or_clone()
6198 ret = send_truncate(sctx, sctx->cur_ino, in send_write_or_clone()
6199 sctx->cur_inode_gen, offset); in send_write_or_clone()
6208 sctx->cur_inode_next_write_offset = end; in send_write_or_clone()
6212 ei = btrfs_item_ptr(path->nodes[0], path->slots[0], in send_write_or_clone()
6214 disk_byte = btrfs_file_extent_disk_bytenr(path->nodes[0], ei); in send_write_or_clone()
6215 data_offset = btrfs_file_extent_offset(path->nodes[0], ei); in send_write_or_clone()
6218 sctx->cur_inode_next_write_offset = end; in send_write_or_clone()
6247 return -ENOMEM; in is_extent_unchanged()
6249 eb = left_path->nodes[0]; in is_extent_unchanged()
6250 slot = left_path->slots[0]; in is_extent_unchanged()
6265 * extents which we are checking at the moment. 1-8 are the right in is_extent_unchanged()
6268 * |-----L-----| in is_extent_unchanged()
6269 * |-1-|-2a-|-3-|-4-|-5-|-6-| in is_extent_unchanged()
6271 * |-----L-----| in is_extent_unchanged()
6272 * |--1--|-2b-|...(same as above) in is_extent_unchanged()
6275 * |-----L-----| in is_extent_unchanged()
6276 * |-----------7-----------|-6-| in is_extent_unchanged()
6279 * |-----L-----| in is_extent_unchanged()
6280 * |-8-| in is_extent_unchanged()
6284 key.objectid = ekey->objectid; in is_extent_unchanged()
6286 key.offset = ekey->offset; in is_extent_unchanged()
6287 ret = btrfs_search_slot_for_read(sctx->parent_root, &key, path, 0, 0); in is_extent_unchanged()
6298 eb = path->nodes[0]; in is_extent_unchanged()
6299 slot = path->slots[0]; in is_extent_unchanged()
6312 while (key.offset < ekey->offset + left_len) { in is_extent_unchanged()
6332 if (found_key.offset + right_len <= ekey->offset) { in is_extent_unchanged()
6356 if (key.offset < ekey->offset) { in is_extent_unchanged()
6358 right_offset += ekey->offset - key.offset; in is_extent_unchanged()
6361 left_offset_fixed += key.offset - ekey->offset; in is_extent_unchanged()
6377 ret = btrfs_next_item(sctx->parent_root, path); in is_extent_unchanged()
6381 eb = path->nodes[0]; in is_extent_unchanged()
6382 slot = path->slots[0]; in is_extent_unchanged()
6401 if (key.offset >= ekey->offset + left_len) in is_extent_unchanged()
6415 struct btrfs_root *root = sctx->send_root; in get_last_extent()
6421 return -ENOMEM; in get_last_extent()
6423 sctx->cur_inode_last_extent = 0; in get_last_extent()
6425 key.objectid = sctx->cur_ino; in get_last_extent()
6432 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); in get_last_extent()
6433 if (key.objectid != sctx->cur_ino || key.type != BTRFS_EXTENT_DATA_KEY) in get_last_extent()
6436 sctx->cur_inode_last_extent = btrfs_file_extent_end(path); in get_last_extent()
6448 struct btrfs_root *root = sctx->parent_root; in range_is_hole_in_parent()
6454 return -ENOMEM; in range_is_hole_in_parent()
6456 key.objectid = sctx->cur_ino; in range_is_hole_in_parent()
6462 if (ret > 0 && path->slots[0] > 0) in range_is_hole_in_parent()
6463 path->slots[0]--; in range_is_hole_in_parent()
6466 struct extent_buffer *leaf = path->nodes[0]; in range_is_hole_in_parent()
6467 int slot = path->slots[0]; in range_is_hole_in_parent()
6481 if (key.objectid < sctx->cur_ino || in range_is_hole_in_parent()
6484 if (key.objectid > sctx->cur_ino || in range_is_hole_in_parent()
6500 path->slots[0]++; in range_is_hole_in_parent()
6513 if (sctx->cur_ino != key->objectid || !need_send_hole(sctx)) in maybe_send_hole()
6526 if ((sctx->cur_inode_last_extent == (u64)-1) || in maybe_send_hole()
6527 (path->slots[0] == 0 && sctx->cur_inode_last_extent < key->offset)) { in maybe_send_hole()
6528 ret = get_last_extent(sctx, key->offset - 1); in maybe_send_hole()
6533 if (sctx->cur_inode_last_extent < key->offset) { in maybe_send_hole()
6535 sctx->cur_inode_last_extent, in maybe_send_hole()
6536 key->offset); in maybe_send_hole()
6540 ret = send_hole(sctx, key->offset); in maybe_send_hole()
6544 sctx->cur_inode_last_extent = btrfs_file_extent_end(path); in maybe_send_hole()
6555 if (S_ISLNK(sctx->cur_inode_mode)) in process_extent()
6558 if (sctx->parent_root && !sctx->cur_inode_new) { in process_extent()
6570 ei = btrfs_item_ptr(path->nodes[0], path->slots[0], in process_extent()
6572 type = btrfs_file_extent_type(path->nodes[0], ei); in process_extent()
6587 if (btrfs_file_extent_disk_bytenr(path->nodes[0], ei) == 0) { in process_extent()
6594 ret = find_extent_clone(sctx, path, key->objectid, key->offset, in process_extent()
6595 sctx->cur_inode_size, &found_clone); in process_extent()
6596 if (ret != -ENOENT && ret < 0) in process_extent()
6617 root = sctx->send_root; in process_all_extents()
6620 return -ENOMEM; in process_all_extents()
6622 key.objectid = sctx->cmp_key->objectid; in process_all_extents()
6650 if (sctx->cur_ino == 0) in process_recorded_refs_if_needed()
6652 if (!at_end && sctx->cur_ino == sctx->cmp_key->objectid && in process_recorded_refs_if_needed()
6653 sctx->cmp_key->type <= BTRFS_INODE_EXTREF_KEY) in process_recorded_refs_if_needed()
6655 if (list_empty(&sctx->new_refs) && list_empty(&sctx->deleted_refs)) in process_recorded_refs_if_needed()
6686 if (sctx->ignore_cur_inode) in finish_inode_if_needed()
6707 sctx->send_progress = sctx->cur_ino + 1; in finish_inode_if_needed()
6709 if (sctx->cur_ino == 0 || sctx->cur_inode_deleted) in finish_inode_if_needed()
6711 if (!at_end && sctx->cmp_key->objectid == sctx->cur_ino) in finish_inode_if_needed()
6713 ret = get_inode_info(sctx->send_root, sctx->cur_ino, &info); in finish_inode_if_needed()
6721 if (!sctx->parent_root || sctx->cur_inode_new) { in finish_inode_if_needed()
6723 if (!S_ISLNK(sctx->cur_inode_mode)) in finish_inode_if_needed()
6725 if (sctx->cur_inode_next_write_offset == sctx->cur_inode_size) in finish_inode_if_needed()
6730 ret = get_inode_info(sctx->parent_root, sctx->cur_ino, &info); in finish_inode_if_needed()
6741 if (!S_ISLNK(sctx->cur_inode_mode) && left_mode != right_mode) in finish_inode_if_needed()
6743 if (!S_ISLNK(sctx->cur_inode_mode) && left_fileattr != right_fileattr) in finish_inode_if_needed()
6745 if ((old_size == sctx->cur_inode_size) || in finish_inode_if_needed()
6746 (sctx->cur_inode_size > old_size && in finish_inode_if_needed()
6747 sctx->cur_inode_next_write_offset == sctx->cur_inode_size)) in finish_inode_if_needed()
6751 if (S_ISREG(sctx->cur_inode_mode)) { in finish_inode_if_needed()
6753 if (sctx->cur_inode_last_extent == (u64)-1 || in finish_inode_if_needed()
6754 sctx->cur_inode_last_extent < in finish_inode_if_needed()
6755 sctx->cur_inode_size) { in finish_inode_if_needed()
6756 ret = get_last_extent(sctx, (u64)-1); in finish_inode_if_needed()
6760 if (sctx->cur_inode_last_extent < sctx->cur_inode_size) { in finish_inode_if_needed()
6762 sctx->cur_inode_last_extent, in finish_inode_if_needed()
6763 sctx->cur_inode_size); in finish_inode_if_needed()
6767 ret = send_hole(sctx, sctx->cur_inode_size); in finish_inode_if_needed()
6777 ret = send_truncate(sctx, sctx->cur_ino, in finish_inode_if_needed()
6778 sctx->cur_inode_gen, in finish_inode_if_needed()
6779 sctx->cur_inode_size); in finish_inode_if_needed()
6786 ret = send_chown(sctx, sctx->cur_ino, sctx->cur_inode_gen, in finish_inode_if_needed()
6792 ret = send_chmod(sctx, sctx->cur_ino, sctx->cur_inode_gen, in finish_inode_if_needed()
6798 ret = send_fileattr(sctx, sctx->cur_ino, sctx->cur_inode_gen, in finish_inode_if_needed()
6805 && sctx->cur_inode_needs_verity) { in finish_inode_if_needed()
6819 if (!is_waiting_for_move(sctx, sctx->cur_ino)) { in finish_inode_if_needed()
6830 sctx->send_progress = sctx->cur_ino + 1; in finish_inode_if_needed()
6833 * If the current inode is a non-empty directory, delay issuing in finish_inode_if_needed()
6838 if (S_ISDIR(sctx->cur_inode_mode) && sctx->cur_inode_size > 0) in finish_inode_if_needed()
6839 ret = cache_dir_utimes(sctx, sctx->cur_ino, sctx->cur_inode_gen); in finish_inode_if_needed()
6841 ret = send_utimes(sctx, sctx->cur_ino, sctx->cur_inode_gen); in finish_inode_if_needed()
6858 if (sctx->cur_inode == NULL) in close_current_inode()
6861 i_size = i_size_read(sctx->cur_inode); in close_current_inode()
6869 if (sctx->clean_page_cache && sctx->page_cache_clear_start < i_size) in close_current_inode()
6870 truncate_inode_pages_range(&sctx->cur_inode->i_data, in close_current_inode()
6871 sctx->page_cache_clear_start, in close_current_inode()
6872 round_up(i_size, PAGE_SIZE) - 1); in close_current_inode()
6874 iput(sctx->cur_inode); in close_current_inode()
6875 sctx->cur_inode = NULL; in close_current_inode()
6882 struct btrfs_key *key = sctx->cmp_key; in changed_inode()
6890 sctx->cur_ino = key->objectid; in changed_inode()
6891 sctx->cur_inode_new_gen = false; in changed_inode()
6892 sctx->cur_inode_last_extent = (u64)-1; in changed_inode()
6893 sctx->cur_inode_next_write_offset = 0; in changed_inode()
6894 sctx->ignore_cur_inode = false; in changed_inode()
6901 sctx->send_progress = sctx->cur_ino; in changed_inode()
6905 left_ii = btrfs_item_ptr(sctx->left_path->nodes[0], in changed_inode()
6906 sctx->left_path->slots[0], in changed_inode()
6908 left_gen = btrfs_inode_generation(sctx->left_path->nodes[0], in changed_inode()
6911 right_ii = btrfs_item_ptr(sctx->right_path->nodes[0], in changed_inode()
6912 sctx->right_path->slots[0], in changed_inode()
6914 right_gen = btrfs_inode_generation(sctx->right_path->nodes[0], in changed_inode()
6918 right_ii = btrfs_item_ptr(sctx->right_path->nodes[0], in changed_inode()
6919 sctx->right_path->slots[0], in changed_inode()
6922 right_gen = btrfs_inode_generation(sctx->right_path->nodes[0], in changed_inode()
6931 sctx->cur_ino != BTRFS_FIRST_FREE_OBJECTID) in changed_inode()
6932 sctx->cur_inode_new_gen = true; in changed_inode()
6952 * -------------------------------- in changed_inode()
6957 * ---------------------------------- in changed_inode()
6963 * ----------------------------------------------------------------------- in changed_inode()
6970 if (btrfs_inode_nlink(sctx->left_path->nodes[0], left_ii) == 0) { in changed_inode()
6971 sctx->ignore_cur_inode = true; in changed_inode()
6974 sctx->cur_inode_gen = left_gen; in changed_inode()
6975 sctx->cur_inode_new = true; in changed_inode()
6976 sctx->cur_inode_deleted = false; in changed_inode()
6977 sctx->cur_inode_size = btrfs_inode_size( in changed_inode()
6978 sctx->left_path->nodes[0], left_ii); in changed_inode()
6979 sctx->cur_inode_mode = btrfs_inode_mode( in changed_inode()
6980 sctx->left_path->nodes[0], left_ii); in changed_inode()
6981 sctx->cur_inode_rdev = btrfs_inode_rdev( in changed_inode()
6982 sctx->left_path->nodes[0], left_ii); in changed_inode()
6983 if (sctx->cur_ino != BTRFS_FIRST_FREE_OBJECTID) in changed_inode()
6986 sctx->cur_inode_gen = right_gen; in changed_inode()
6987 sctx->cur_inode_new = false; in changed_inode()
6988 sctx->cur_inode_deleted = true; in changed_inode()
6989 sctx->cur_inode_size = btrfs_inode_size( in changed_inode()
6990 sctx->right_path->nodes[0], right_ii); in changed_inode()
6991 sctx->cur_inode_mode = btrfs_inode_mode( in changed_inode()
6992 sctx->right_path->nodes[0], right_ii); in changed_inode()
6996 new_nlinks = btrfs_inode_nlink(sctx->left_path->nodes[0], left_ii); in changed_inode()
6997 old_nlinks = btrfs_inode_nlink(sctx->right_path->nodes[0], right_ii); in changed_inode()
6999 sctx->ignore_cur_inode = true; in changed_inode()
7002 sctx->cur_inode_new_gen = 1; in changed_inode()
7011 if (sctx->cur_inode_new_gen) { in changed_inode()
7016 sctx->cur_inode_gen = right_gen; in changed_inode()
7017 sctx->cur_inode_new = false; in changed_inode()
7018 sctx->cur_inode_deleted = true; in changed_inode()
7019 sctx->cur_inode_size = btrfs_inode_size( in changed_inode()
7020 sctx->right_path->nodes[0], right_ii); in changed_inode()
7021 sctx->cur_inode_mode = btrfs_inode_mode( in changed_inode()
7022 sctx->right_path->nodes[0], right_ii); in changed_inode()
7033 sctx->cur_inode_gen = left_gen; in changed_inode()
7034 sctx->cur_inode_new = true; in changed_inode()
7035 sctx->cur_inode_deleted = false; in changed_inode()
7036 sctx->cur_inode_size = btrfs_inode_size( in changed_inode()
7037 sctx->left_path->nodes[0], in changed_inode()
7039 sctx->cur_inode_mode = btrfs_inode_mode( in changed_inode()
7040 sctx->left_path->nodes[0], in changed_inode()
7042 sctx->cur_inode_rdev = btrfs_inode_rdev( in changed_inode()
7043 sctx->left_path->nodes[0], in changed_inode()
7057 sctx->send_progress = sctx->cur_ino + 1; in changed_inode()
7071 sctx->cur_inode_gen = left_gen; in changed_inode()
7072 sctx->cur_inode_new = false; in changed_inode()
7073 sctx->cur_inode_new_gen = false; in changed_inode()
7074 sctx->cur_inode_deleted = false; in changed_inode()
7075 sctx->cur_inode_size = btrfs_inode_size( in changed_inode()
7076 sctx->left_path->nodes[0], left_ii); in changed_inode()
7077 sctx->cur_inode_mode = btrfs_inode_mode( in changed_inode()
7078 sctx->left_path->nodes[0], left_ii); in changed_inode()
7101 if (sctx->cur_ino != sctx->cmp_key->objectid) { in changed_ref()
7103 return -EIO; in changed_ref()
7106 if (!sctx->cur_inode_new_gen && in changed_ref()
7107 sctx->cur_ino != BTRFS_FIRST_FREE_OBJECTID) { in changed_ref()
7129 if (sctx->cur_ino != sctx->cmp_key->objectid) { in changed_xattr()
7131 return -EIO; in changed_xattr()
7134 if (!sctx->cur_inode_new_gen && !sctx->cur_inode_deleted) { in changed_xattr()
7169 if (sctx->cur_ino != sctx->cmp_key->objectid) in changed_extent()
7172 if (!sctx->cur_inode_new_gen && !sctx->cur_inode_deleted) { in changed_extent()
7174 ret = process_extent(sctx, sctx->left_path, in changed_extent()
7175 sctx->cmp_key); in changed_extent()
7183 if (!sctx->cur_inode_new_gen && !sctx->cur_inode_deleted) { in changed_verity()
7185 sctx->cur_inode_needs_verity = true; in changed_verity()
7195 ret = get_inode_gen(sctx->send_root, dir, &new_gen); in dir_changed()
7199 ret = get_inode_gen(sctx->parent_root, dir, &orig_gen); in dir_changed()
7219 if (key->type == BTRFS_INODE_REF_KEY) { in compare_refs()
7220 dirid = key->offset; in compare_refs()
7226 leaf = path->nodes[0]; in compare_refs()
7227 item_size = btrfs_item_size(leaf, path->slots[0]); in compare_refs()
7228 ptr = btrfs_item_ptr_offset(leaf, path->slots[0]); in compare_refs()
7275 * is stored in the same filesystem - when reserving space for a write in changed_cb()
7283 lockdep_assert_not_held(&sctx->send_root->fs_info->commit_root_sem); in changed_cb()
7290 if (left_path->nodes[0]) in changed_cb()
7292 &left_path->nodes[0]->bflags)); in changed_cb()
7298 if (right_path && right_path->nodes[0]) in changed_cb()
7300 &right_path->nodes[0]->bflags)); in changed_cb()
7303 if (key->type == BTRFS_INODE_REF_KEY || in changed_cb()
7304 key->type == BTRFS_INODE_EXTREF_KEY) { in changed_cb()
7310 } else if (key->type == BTRFS_EXTENT_DATA_KEY) { in changed_cb()
7319 sctx->left_path = left_path; in changed_cb()
7320 sctx->right_path = right_path; in changed_cb()
7321 sctx->cmp_key = key; in changed_cb()
7327 /* Ignore non-FS objects */ in changed_cb()
7328 if (key->objectid == BTRFS_FREE_INO_OBJECTID || in changed_cb()
7329 key->objectid == BTRFS_FREE_SPACE_OBJECTID) in changed_cb()
7332 if (key->type == BTRFS_INODE_ITEM_KEY) { in changed_cb()
7334 } else if (!sctx->ignore_cur_inode) { in changed_cb()
7335 if (key->type == BTRFS_INODE_REF_KEY || in changed_cb()
7336 key->type == BTRFS_INODE_EXTREF_KEY) in changed_cb()
7338 else if (key->type == BTRFS_XATTR_ITEM_KEY) in changed_cb()
7340 else if (key->type == BTRFS_EXTENT_DATA_KEY) in changed_cb()
7342 else if (key->type == BTRFS_VERITY_DESC_ITEM_KEY && in changed_cb()
7343 key->offset == 0) in changed_cb()
7358 if (!path->need_commit_sem) in search_key_again()
7359 lockdep_assert_held_read(&root->fs_info->commit_root_sem); in search_key_again()
7365 * readonly roots and add, update or remove keys to/from them - but at in search_key_again()
7371 btrfs_print_tree(path->nodes[path->lowest_level], false); in search_key_again()
7372 btrfs_err(root->fs_info, in search_key_again()
7374 key->objectid, key->type, key->offset, in search_key_again()
7375 (root == sctx->parent_root ? "parent" : "send"), in search_key_again()
7376 btrfs_root_id(root), path->lowest_level, in search_key_again()
7377 path->slots[path->lowest_level]); in search_key_again()
7378 return -EUCLEAN; in search_key_again()
7387 struct btrfs_root *send_root = sctx->send_root; in full_send_tree()
7389 struct btrfs_fs_info *fs_info = send_root->fs_info; in full_send_tree()
7394 return -ENOMEM; in full_send_tree()
7395 path->reada = READA_FORWARD_ALWAYS; in full_send_tree()
7401 down_read(&fs_info->commit_root_sem); in full_send_tree()
7402 sctx->last_reloc_trans = fs_info->last_reloc_trans; in full_send_tree()
7403 up_read(&fs_info->commit_root_sem); in full_send_tree()
7412 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); in full_send_tree()
7419 down_read(&fs_info->commit_root_sem); in full_send_tree()
7420 if (fs_info->last_reloc_trans > sctx->last_reloc_trans) { in full_send_tree()
7421 sctx->last_reloc_trans = fs_info->last_reloc_trans; in full_send_tree()
7422 up_read(&fs_info->commit_root_sem); in full_send_tree()
7438 up_read(&fs_info->commit_root_sem); in full_send_tree()
7458 static int replace_node_with_clone(struct btrfs_path *path, int level) in replace_node_with_clone() argument
7462 clone = btrfs_clone_extent_buffer(path->nodes[level]); in replace_node_with_clone()
7464 return -ENOMEM; in replace_node_with_clone()
7466 free_extent_buffer(path->nodes[level]); in replace_node_with_clone()
7467 path->nodes[level] = clone; in replace_node_with_clone()
7472 static int tree_move_down(struct btrfs_path *path, int *level, u64 reada_min_gen) in tree_move_down() argument
7475 struct extent_buffer *parent = path->nodes[*level]; in tree_move_down()
7476 int slot = path->slots[*level]; in tree_move_down()
7481 lockdep_assert_held_read(&parent->fs_info->commit_root_sem); in tree_move_down()
7482 ASSERT(*level != 0); in tree_move_down()
7494 reada_max = (*level == 1 ? SZ_128K : eb->fs_info->nodesize); in tree_move_down()
7499 reada_done += eb->fs_info->nodesize; in tree_move_down()
7503 path->nodes[*level - 1] = eb; in tree_move_down()
7504 path->slots[*level - 1] = 0; in tree_move_down()
7505 (*level)--; in tree_move_down()
7507 if (*level == 0) in tree_move_down()
7514 int *level, int root_level) in tree_move_next_or_upnext() argument
7518 nritems = btrfs_header_nritems(path->nodes[*level]); in tree_move_next_or_upnext()
7520 path->slots[*level]++; in tree_move_next_or_upnext()
7522 while (path->slots[*level] >= nritems) { in tree_move_next_or_upnext()
7523 if (*level == root_level) { in tree_move_next_or_upnext()
7524 path->slots[*level] = nritems - 1; in tree_move_next_or_upnext()
7525 return -1; in tree_move_next_or_upnext()
7529 path->slots[*level] = 0; in tree_move_next_or_upnext()
7530 free_extent_buffer(path->nodes[*level]); in tree_move_next_or_upnext()
7531 path->nodes[*level] = NULL; in tree_move_next_or_upnext()
7532 (*level)++; in tree_move_next_or_upnext()
7533 path->slots[*level]++; in tree_move_next_or_upnext()
7535 nritems = btrfs_header_nritems(path->nodes[*level]); in tree_move_next_or_upnext()
7546 int *level, int root_level, in tree_advance() argument
7553 if (*level == 0 || !allow_down) { in tree_advance()
7554 ret = tree_move_next_or_upnext(path, level, root_level); in tree_advance()
7556 ret = tree_move_down(path, level, reada_min_gen); in tree_advance()
7560 * Even if we have reached the end of a tree, ret is -1, update the key in tree_advance()
7565 if (*level == 0) in tree_advance()
7566 btrfs_item_key_to_cpu(path->nodes[*level], key, in tree_advance()
7567 path->slots[*level]); in tree_advance()
7569 btrfs_node_key_to_cpu(path->nodes[*level], key, in tree_advance()
7570 path->slots[*level]); in tree_advance()
7583 len1 = btrfs_item_size(left_path->nodes[0], left_path->slots[0]); in tree_compare_item()
7584 len2 = btrfs_item_size(right_path->nodes[0], right_path->slots[0]); in tree_compare_item()
7588 off1 = btrfs_item_ptr_offset(left_path->nodes[0], left_path->slots[0]); in tree_compare_item()
7589 off2 = btrfs_item_ptr_offset(right_path->nodes[0], in tree_compare_item()
7590 right_path->slots[0]); in tree_compare_item()
7592 read_extent_buffer(left_path->nodes[0], tmp_buf, off1, len1); in tree_compare_item()
7594 cmp = memcmp_extent_buffer(right_path->nodes[0], tmp_buf, off2, len1); in tree_compare_item()
7611 * 2) For leaves, level 0, we are holding copies (clones) of extent buffers, so
7630 lockdep_assert_held_read(&sctx->send_root->fs_info->commit_root_sem); in restart_after_relocation()
7641 left_path->lowest_level = left_level; in restart_after_relocation()
7642 ret = search_key_again(sctx, sctx->send_root, left_path, left_key); in restart_after_relocation()
7646 right_path->lowest_level = right_level; in restart_after_relocation()
7647 ret = search_key_again(sctx, sctx->parent_root, right_path, right_key); in restart_after_relocation()
7652 * If the lowest level nodes are leaves, clone them so that they can be in restart_after_relocation()
7674 root_level = btrfs_header_level(sctx->send_root->commit_root); in restart_after_relocation()
7681 root_level = btrfs_header_level(sctx->parent_root->commit_root); in restart_after_relocation()
7707 struct btrfs_fs_info *fs_info = left_root->fs_info; in btrfs_compare_trees()
7731 ret = -ENOMEM; in btrfs_compare_trees()
7736 ret = -ENOMEM; in btrfs_compare_trees()
7740 tmp_buf = kvmalloc(fs_info->nodesize, GFP_KERNEL); in btrfs_compare_trees()
7742 ret = -ENOMEM; in btrfs_compare_trees()
7746 left_path->search_commit_root = 1; in btrfs_compare_trees()
7747 left_path->skip_locking = 1; in btrfs_compare_trees()
7748 right_path->search_commit_root = 1; in btrfs_compare_trees()
7749 right_path->skip_locking = 1; in btrfs_compare_trees()
7754 * If both trees are at level 0 in btrfs_compare_trees()
7762 * If both trees are at the same level but not at level 0 in btrfs_compare_trees()
7767 * If they match advance both trees but stay at the same level in btrfs_compare_trees()
7775 * If we are at level 0, try to go to the next slot. If that's not in btrfs_compare_trees()
7776 * possible, go one level up and repeat. Stop when we found a level in btrfs_compare_trees()
7780 * If we are not at level 0 and not on shared tree blocks, go one in btrfs_compare_trees()
7781 * level deeper. in btrfs_compare_trees()
7783 * If we are not at level 0 and on shared tree blocks, go one slot to in btrfs_compare_trees()
7787 down_read(&fs_info->commit_root_sem); in btrfs_compare_trees()
7788 left_level = btrfs_header_level(left_root->commit_root); in btrfs_compare_trees()
7797 left_path->nodes[left_level] = in btrfs_compare_trees()
7798 btrfs_clone_extent_buffer(left_root->commit_root); in btrfs_compare_trees()
7799 if (!left_path->nodes[left_level]) { in btrfs_compare_trees()
7800 ret = -ENOMEM; in btrfs_compare_trees()
7804 right_level = btrfs_header_level(right_root->commit_root); in btrfs_compare_trees()
7806 right_path->nodes[right_level] = in btrfs_compare_trees()
7807 btrfs_clone_extent_buffer(right_root->commit_root); in btrfs_compare_trees()
7808 if (!right_path->nodes[right_level]) { in btrfs_compare_trees()
7809 ret = -ENOMEM; in btrfs_compare_trees()
7819 reada_min_gen = btrfs_header_generation(right_root->commit_root); in btrfs_compare_trees()
7822 btrfs_item_key_to_cpu(left_path->nodes[left_level], in btrfs_compare_trees()
7823 &left_key, left_path->slots[left_level]); in btrfs_compare_trees()
7825 btrfs_node_key_to_cpu(left_path->nodes[left_level], in btrfs_compare_trees()
7826 &left_key, left_path->slots[left_level]); in btrfs_compare_trees()
7828 btrfs_item_key_to_cpu(right_path->nodes[right_level], in btrfs_compare_trees()
7829 &right_key, right_path->slots[right_level]); in btrfs_compare_trees()
7831 btrfs_node_key_to_cpu(right_path->nodes[right_level], in btrfs_compare_trees()
7832 &right_key, right_path->slots[right_level]); in btrfs_compare_trees()
7834 sctx->last_reloc_trans = fs_info->last_reloc_trans; in btrfs_compare_trees()
7838 rwsem_is_contended(&fs_info->commit_root_sem)) { in btrfs_compare_trees()
7839 up_read(&fs_info->commit_root_sem); in btrfs_compare_trees()
7841 down_read(&fs_info->commit_root_sem); in btrfs_compare_trees()
7844 if (fs_info->last_reloc_trans > sctx->last_reloc_trans) { in btrfs_compare_trees()
7851 sctx->last_reloc_trans = fs_info->last_reloc_trans; in btrfs_compare_trees()
7859 if (ret == -1) in btrfs_compare_trees()
7870 if (ret == -1) in btrfs_compare_trees()
7882 up_read(&fs_info->commit_root_sem); in btrfs_compare_trees()
7889 down_read(&fs_info->commit_root_sem); in btrfs_compare_trees()
7895 up_read(&fs_info->commit_root_sem); in btrfs_compare_trees()
7902 down_read(&fs_info->commit_root_sem); in btrfs_compare_trees()
7909 up_read(&fs_info->commit_root_sem); in btrfs_compare_trees()
7926 WARN_ON(!extent_buffer_uptodate(left_path->nodes[0])); in btrfs_compare_trees()
7941 down_read(&fs_info->commit_root_sem); in btrfs_compare_trees()
7950 left_path->nodes[left_level], in btrfs_compare_trees()
7951 left_path->slots[left_level]); in btrfs_compare_trees()
7953 right_path->nodes[right_level], in btrfs_compare_trees()
7954 right_path->slots[right_level]); in btrfs_compare_trees()
7956 left_path->nodes[left_level], in btrfs_compare_trees()
7957 left_path->slots[left_level]); in btrfs_compare_trees()
7959 right_path->nodes[right_level], in btrfs_compare_trees()
7960 right_path->slots[right_level]); in btrfs_compare_trees()
7982 up_read(&fs_info->commit_root_sem); in btrfs_compare_trees()
7994 if (!(sctx->flags & BTRFS_SEND_FLAG_OMIT_STREAM_HEADER)) { in send_subvol()
8004 if (sctx->parent_root) { in send_subvol()
8005 ret = btrfs_compare_trees(sctx->send_root, sctx->parent_root, sctx); in send_subvol()
8029 * returning a -ESTALE error, and making send fail with that error. So make
8037 struct btrfs_root *root = sctx->parent_root; in ensure_commit_roots_uptodate()
8039 if (root && root->node != root->commit_root) in ensure_commit_roots_uptodate()
8042 for (int i = 0; i < sctx->clone_roots_cnt; i++) { in ensure_commit_roots_uptodate()
8043 root = sctx->clone_roots[i].root; in ensure_commit_roots_uptodate()
8044 if (root->node != root->commit_root) in ensure_commit_roots_uptodate()
8061 struct btrfs_root *root = sctx->parent_root; in flush_delalloc_roots()
8072 for (i = 0; i < sctx->clone_roots_cnt; i++) { in flush_delalloc_roots()
8073 root = sctx->clone_roots[i].root; in flush_delalloc_roots()
8085 spin_lock(&root->root_item_lock); in btrfs_root_dec_send_in_progress()
8086 root->send_in_progress--; in btrfs_root_dec_send_in_progress()
8091 if (root->send_in_progress < 0) in btrfs_root_dec_send_in_progress()
8092 btrfs_err(root->fs_info, in btrfs_root_dec_send_in_progress()
8094 root->send_in_progress, btrfs_root_id(root)); in btrfs_root_dec_send_in_progress()
8095 spin_unlock(&root->root_item_lock); in btrfs_root_dec_send_in_progress()
8100 btrfs_warn_rl(root->fs_info, in dedupe_in_progress_warn()
8102 btrfs_root_id(root), root->dedupe_in_progress); in dedupe_in_progress_warn()
8108 struct btrfs_root *send_root = inode->root; in btrfs_ioctl_send()
8109 struct btrfs_fs_info *fs_info = send_root->fs_info; in btrfs_ioctl_send()
8121 return -EPERM; in btrfs_ioctl_send()
8124 * The subvolume must remain read-only during send, protect against in btrfs_ioctl_send()
8127 spin_lock(&send_root->root_item_lock); in btrfs_ioctl_send()
8133 spin_unlock(&send_root->root_item_lock); in btrfs_ioctl_send()
8134 return -EPERM; in btrfs_ioctl_send()
8138 spin_unlock(&send_root->root_item_lock); in btrfs_ioctl_send()
8139 return -EPERM; in btrfs_ioctl_send()
8141 if (send_root->dedupe_in_progress) { in btrfs_ioctl_send()
8143 spin_unlock(&send_root->root_item_lock); in btrfs_ioctl_send()
8144 return -EAGAIN; in btrfs_ioctl_send()
8146 send_root->send_in_progress++; in btrfs_ioctl_send()
8147 spin_unlock(&send_root->root_item_lock); in btrfs_ioctl_send()
8155 if (arg->clone_sources_count > SZ_8M / sizeof(struct clone_root)) { in btrfs_ioctl_send()
8156 ret = -EINVAL; in btrfs_ioctl_send()
8160 if (arg->flags & ~BTRFS_SEND_FLAG_MASK) { in btrfs_ioctl_send()
8161 ret = -EOPNOTSUPP; in btrfs_ioctl_send()
8167 ret = -ENOMEM; in btrfs_ioctl_send()
8171 INIT_LIST_HEAD(&sctx->new_refs); in btrfs_ioctl_send()
8172 INIT_LIST_HEAD(&sctx->deleted_refs); in btrfs_ioctl_send()
8174 btrfs_lru_cache_init(&sctx->name_cache, SEND_MAX_NAME_CACHE_SIZE); in btrfs_ioctl_send()
8175 btrfs_lru_cache_init(&sctx->backref_cache, SEND_MAX_BACKREF_CACHE_SIZE); in btrfs_ioctl_send()
8176 btrfs_lru_cache_init(&sctx->dir_created_cache, in btrfs_ioctl_send()
8182 btrfs_lru_cache_init(&sctx->dir_utimes_cache, 0); in btrfs_ioctl_send()
8184 sctx->pending_dir_moves = RB_ROOT; in btrfs_ioctl_send()
8185 sctx->waiting_dir_moves = RB_ROOT; in btrfs_ioctl_send()
8186 sctx->orphan_dirs = RB_ROOT; in btrfs_ioctl_send()
8187 sctx->rbtree_new_refs = RB_ROOT; in btrfs_ioctl_send()
8188 sctx->rbtree_deleted_refs = RB_ROOT; in btrfs_ioctl_send()
8190 sctx->flags = arg->flags; in btrfs_ioctl_send()
8192 if (arg->flags & BTRFS_SEND_FLAG_VERSION) { in btrfs_ioctl_send()
8193 if (arg->version > BTRFS_SEND_STREAM_VERSION) { in btrfs_ioctl_send()
8194 ret = -EPROTO; in btrfs_ioctl_send()
8198 sctx->proto = arg->version ?: BTRFS_SEND_STREAM_VERSION; in btrfs_ioctl_send()
8200 sctx->proto = 1; in btrfs_ioctl_send()
8202 if ((arg->flags & BTRFS_SEND_FLAG_COMPRESSED) && sctx->proto < 2) { in btrfs_ioctl_send()
8203 ret = -EINVAL; in btrfs_ioctl_send()
8207 sctx->send_filp = fget(arg->send_fd); in btrfs_ioctl_send()
8208 if (!sctx->send_filp || !(sctx->send_filp->f_mode & FMODE_WRITE)) { in btrfs_ioctl_send()
8209 ret = -EBADF; in btrfs_ioctl_send()
8213 sctx->send_root = send_root; in btrfs_ioctl_send()
8214 sctx->clone_roots_cnt = arg->clone_sources_count; in btrfs_ioctl_send()
8216 if (sctx->proto >= 2) { in btrfs_ioctl_send()
8219 sctx->send_max_size = BTRFS_SEND_BUF_SIZE_V2; in btrfs_ioctl_send()
8220 sctx->send_buf = vmalloc(sctx->send_max_size); in btrfs_ioctl_send()
8221 if (!sctx->send_buf) { in btrfs_ioctl_send()
8222 ret = -ENOMEM; in btrfs_ioctl_send()
8225 send_buf_num_pages = sctx->send_max_size >> PAGE_SHIFT; in btrfs_ioctl_send()
8226 sctx->send_buf_pages = kcalloc(send_buf_num_pages, in btrfs_ioctl_send()
8227 sizeof(*sctx->send_buf_pages), in btrfs_ioctl_send()
8229 if (!sctx->send_buf_pages) { in btrfs_ioctl_send()
8230 ret = -ENOMEM; in btrfs_ioctl_send()
8234 sctx->send_buf_pages[i] = in btrfs_ioctl_send()
8235 vmalloc_to_page(sctx->send_buf + (i << PAGE_SHIFT)); in btrfs_ioctl_send()
8238 sctx->send_max_size = BTRFS_SEND_BUF_SIZE_V1; in btrfs_ioctl_send()
8239 sctx->send_buf = kvmalloc(sctx->send_max_size, GFP_KERNEL); in btrfs_ioctl_send()
8241 if (!sctx->send_buf) { in btrfs_ioctl_send()
8242 ret = -ENOMEM; in btrfs_ioctl_send()
8246 sctx->clone_roots = kvcalloc(arg->clone_sources_count + 1, in btrfs_ioctl_send()
8247 sizeof(*sctx->clone_roots), in btrfs_ioctl_send()
8249 if (!sctx->clone_roots) { in btrfs_ioctl_send()
8250 ret = -ENOMEM; in btrfs_ioctl_send()
8254 alloc_size = array_size(sizeof(*arg->clone_sources), in btrfs_ioctl_send()
8255 arg->clone_sources_count); in btrfs_ioctl_send()
8257 if (arg->clone_sources_count) { in btrfs_ioctl_send()
8260 ret = -ENOMEM; in btrfs_ioctl_send()
8264 ret = copy_from_user(clone_sources_tmp, arg->clone_sources, in btrfs_ioctl_send()
8267 ret = -EFAULT; in btrfs_ioctl_send()
8271 for (i = 0; i < arg->clone_sources_count; i++) { in btrfs_ioctl_send()
8278 spin_lock(&clone_root->root_item_lock); in btrfs_ioctl_send()
8281 spin_unlock(&clone_root->root_item_lock); in btrfs_ioctl_send()
8283 ret = -EPERM; in btrfs_ioctl_send()
8286 if (clone_root->dedupe_in_progress) { in btrfs_ioctl_send()
8288 spin_unlock(&clone_root->root_item_lock); in btrfs_ioctl_send()
8290 ret = -EAGAIN; in btrfs_ioctl_send()
8293 clone_root->send_in_progress++; in btrfs_ioctl_send()
8294 spin_unlock(&clone_root->root_item_lock); in btrfs_ioctl_send()
8296 sctx->clone_roots[i].root = clone_root; in btrfs_ioctl_send()
8303 if (arg->parent_root) { in btrfs_ioctl_send()
8304 sctx->parent_root = btrfs_get_fs_root(fs_info, arg->parent_root, in btrfs_ioctl_send()
8306 if (IS_ERR(sctx->parent_root)) { in btrfs_ioctl_send()
8307 ret = PTR_ERR(sctx->parent_root); in btrfs_ioctl_send()
8311 spin_lock(&sctx->parent_root->root_item_lock); in btrfs_ioctl_send()
8312 sctx->parent_root->send_in_progress++; in btrfs_ioctl_send()
8313 if (!btrfs_root_readonly(sctx->parent_root) || in btrfs_ioctl_send()
8314 btrfs_root_dead(sctx->parent_root)) { in btrfs_ioctl_send()
8315 spin_unlock(&sctx->parent_root->root_item_lock); in btrfs_ioctl_send()
8316 ret = -EPERM; in btrfs_ioctl_send()
8319 if (sctx->parent_root->dedupe_in_progress) { in btrfs_ioctl_send()
8320 dedupe_in_progress_warn(sctx->parent_root); in btrfs_ioctl_send()
8321 spin_unlock(&sctx->parent_root->root_item_lock); in btrfs_ioctl_send()
8322 ret = -EAGAIN; in btrfs_ioctl_send()
8325 spin_unlock(&sctx->parent_root->root_item_lock); in btrfs_ioctl_send()
8333 sctx->clone_roots[sctx->clone_roots_cnt++].root = in btrfs_ioctl_send()
8334 btrfs_grab_root(sctx->send_root); in btrfs_ioctl_send()
8337 sort(sctx->clone_roots, sctx->clone_roots_cnt, in btrfs_ioctl_send()
8338 sizeof(*sctx->clone_roots), __clone_root_cmp_sort, in btrfs_ioctl_send()
8354 btrfs_lru_cache_for_each_entry_safe(&sctx->dir_utimes_cache, entry, tmp) { in btrfs_ioctl_send()
8355 ret = send_utimes(sctx, entry->key, entry->gen); in btrfs_ioctl_send()
8358 btrfs_lru_cache_remove(&sctx->dir_utimes_cache, entry); in btrfs_ioctl_send()
8361 if (!(sctx->flags & BTRFS_SEND_FLAG_OMIT_END_CMD)) { in btrfs_ioctl_send()
8371 WARN_ON(sctx && !ret && !RB_EMPTY_ROOT(&sctx->pending_dir_moves)); in btrfs_ioctl_send()
8372 while (sctx && !RB_EMPTY_ROOT(&sctx->pending_dir_moves)) { in btrfs_ioctl_send()
8376 n = rb_first(&sctx->pending_dir_moves); in btrfs_ioctl_send()
8378 while (!list_empty(&pm->list)) { in btrfs_ioctl_send()
8381 pm2 = list_first_entry(&pm->list, in btrfs_ioctl_send()
8388 WARN_ON(sctx && !ret && !RB_EMPTY_ROOT(&sctx->waiting_dir_moves)); in btrfs_ioctl_send()
8389 while (sctx && !RB_EMPTY_ROOT(&sctx->waiting_dir_moves)) { in btrfs_ioctl_send()
8393 n = rb_first(&sctx->waiting_dir_moves); in btrfs_ioctl_send()
8395 rb_erase(&dm->node, &sctx->waiting_dir_moves); in btrfs_ioctl_send()
8399 WARN_ON(sctx && !ret && !RB_EMPTY_ROOT(&sctx->orphan_dirs)); in btrfs_ioctl_send()
8400 while (sctx && !RB_EMPTY_ROOT(&sctx->orphan_dirs)) { in btrfs_ioctl_send()
8404 n = rb_first(&sctx->orphan_dirs); in btrfs_ioctl_send()
8410 for (i = 0; i < sctx->clone_roots_cnt; i++) { in btrfs_ioctl_send()
8412 sctx->clone_roots[i].root); in btrfs_ioctl_send()
8413 btrfs_put_root(sctx->clone_roots[i].root); in btrfs_ioctl_send()
8418 sctx->clone_roots[i].root); in btrfs_ioctl_send()
8419 btrfs_put_root(sctx->clone_roots[i].root); in btrfs_ioctl_send()
8424 if (sctx && !IS_ERR_OR_NULL(sctx->parent_root)) { in btrfs_ioctl_send()
8425 btrfs_root_dec_send_in_progress(sctx->parent_root); in btrfs_ioctl_send()
8426 btrfs_put_root(sctx->parent_root); in btrfs_ioctl_send()
8432 if (sctx->send_filp) in btrfs_ioctl_send()
8433 fput(sctx->send_filp); in btrfs_ioctl_send()
8435 kvfree(sctx->clone_roots); in btrfs_ioctl_send()
8436 kfree(sctx->send_buf_pages); in btrfs_ioctl_send()
8437 kvfree(sctx->send_buf); in btrfs_ioctl_send()
8438 kvfree(sctx->verity_descriptor); in btrfs_ioctl_send()
8442 btrfs_lru_cache_clear(&sctx->name_cache); in btrfs_ioctl_send()
8443 btrfs_lru_cache_clear(&sctx->backref_cache); in btrfs_ioctl_send()
8444 btrfs_lru_cache_clear(&sctx->dir_created_cache); in btrfs_ioctl_send()
8445 btrfs_lru_cache_clear(&sctx->dir_utimes_cache); in btrfs_ioctl_send()