Lines Matching refs:sctx

279 static void inconsistent_snapshot_error(struct send_ctx *sctx,  in inconsistent_snapshot_error()  argument
304 btrfs_err(sctx->send_root->fs_info, in inconsistent_snapshot_error()
306 result_string, what, sctx->cmp_key->objectid, in inconsistent_snapshot_error()
307 sctx->send_root->root_key.objectid, in inconsistent_snapshot_error()
308 (sctx->parent_root ? in inconsistent_snapshot_error()
309 sctx->parent_root->root_key.objectid : 0)); in inconsistent_snapshot_error()
312 static int is_waiting_for_move(struct send_ctx *sctx, u64 ino);
315 get_waiting_dir_move(struct send_ctx *sctx, u64 ino);
317 static int is_waiting_for_rm(struct send_ctx *sctx, u64 dir_ino);
319 static int need_send_hole(struct send_ctx *sctx) in need_send_hole() argument
321 return (sctx->parent_root && !sctx->cur_inode_new && in need_send_hole()
322 !sctx->cur_inode_new_gen && !sctx->cur_inode_deleted && in need_send_hole()
323 S_ISREG(sctx->cur_inode_mode)); in need_send_hole()
568 static int tlv_put(struct send_ctx *sctx, u16 attr, const void *data, int len) in tlv_put() argument
572 int left = sctx->send_max_size - sctx->send_size; in tlv_put()
577 hdr = (struct btrfs_tlv_header *) (sctx->send_buf + sctx->send_size); in tlv_put()
581 sctx->send_size += total_len; in tlv_put()
587 static int tlv_put_u##bits(struct send_ctx *sctx, \
591 return tlv_put(sctx, attr, &__tmp, sizeof(__tmp)); \
596 static int tlv_put_string(struct send_ctx *sctx, u16 attr, in tlv_put_string() argument
601 return tlv_put(sctx, attr, str, len); in tlv_put_string()
604 static int tlv_put_uuid(struct send_ctx *sctx, u16 attr, in tlv_put_uuid() argument
607 return tlv_put(sctx, attr, uuid, BTRFS_UUID_SIZE); in tlv_put_uuid()
610 static int tlv_put_btrfs_timespec(struct send_ctx *sctx, u16 attr, in tlv_put_btrfs_timespec() argument
616 return tlv_put(sctx, attr, &bts, sizeof(bts)); in tlv_put_btrfs_timespec()
620 #define TLV_PUT(sctx, attrtype, data, attrlen) \ argument
622 ret = tlv_put(sctx, attrtype, data, attrlen); \
627 #define TLV_PUT_INT(sctx, attrtype, bits, value) \ argument
629 ret = tlv_put_u##bits(sctx, attrtype, value); \
634 #define TLV_PUT_U8(sctx, attrtype, data) TLV_PUT_INT(sctx, attrtype, 8, data) argument
635 #define TLV_PUT_U16(sctx, attrtype, data) TLV_PUT_INT(sctx, attrtype, 16, data) argument
636 #define TLV_PUT_U32(sctx, attrtype, data) TLV_PUT_INT(sctx, attrtype, 32, data) argument
637 #define TLV_PUT_U64(sctx, attrtype, data) TLV_PUT_INT(sctx, attrtype, 64, data) argument
638 #define TLV_PUT_STRING(sctx, attrtype, str, len) \ argument
640 ret = tlv_put_string(sctx, attrtype, str, len); \
644 #define TLV_PUT_PATH(sctx, attrtype, p) \ argument
646 ret = tlv_put_string(sctx, attrtype, p->start, \
651 #define TLV_PUT_UUID(sctx, attrtype, uuid) \ argument
653 ret = tlv_put_uuid(sctx, attrtype, uuid); \
657 #define TLV_PUT_BTRFS_TIMESPEC(sctx, attrtype, eb, ts) \ argument
659 ret = tlv_put_btrfs_timespec(sctx, attrtype, eb, ts); \
664 static int send_header(struct send_ctx *sctx) in send_header() argument
671 return write_buf(sctx->send_filp, &hdr, sizeof(hdr), in send_header()
672 &sctx->send_off); in send_header()
678 static int begin_cmd(struct send_ctx *sctx, int cmd) in begin_cmd() argument
682 if (WARN_ON(!sctx->send_buf)) in begin_cmd()
685 BUG_ON(sctx->send_size); in begin_cmd()
687 sctx->send_size += sizeof(*hdr); in begin_cmd()
688 hdr = (struct btrfs_cmd_header *)sctx->send_buf; in begin_cmd()
694 static int send_cmd(struct send_ctx *sctx) in send_cmd() argument
700 hdr = (struct btrfs_cmd_header *)sctx->send_buf; in send_cmd()
701 hdr->len = cpu_to_le32(sctx->send_size - sizeof(*hdr)); in send_cmd()
704 crc = btrfs_crc32c(0, (unsigned char *)sctx->send_buf, sctx->send_size); in send_cmd()
707 ret = write_buf(sctx->send_filp, sctx->send_buf, sctx->send_size, in send_cmd()
708 &sctx->send_off); in send_cmd()
710 sctx->total_send_size += sctx->send_size; in send_cmd()
711 sctx->cmd_send_size[le16_to_cpu(hdr->cmd)] += sctx->send_size; in send_cmd()
712 sctx->send_size = 0; in send_cmd()
720 static int send_rename(struct send_ctx *sctx, in send_rename() argument
723 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_rename()
728 ret = begin_cmd(sctx, BTRFS_SEND_C_RENAME); in send_rename()
732 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, from); in send_rename()
733 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH_TO, to); in send_rename()
735 ret = send_cmd(sctx); in send_rename()
745 static int send_link(struct send_ctx *sctx, in send_link() argument
748 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_link()
753 ret = begin_cmd(sctx, BTRFS_SEND_C_LINK); in send_link()
757 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, path); in send_link()
758 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH_LINK, lnk); in send_link()
760 ret = send_cmd(sctx); in send_link()
770 static int send_unlink(struct send_ctx *sctx, struct fs_path *path) in send_unlink() argument
772 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_unlink()
777 ret = begin_cmd(sctx, BTRFS_SEND_C_UNLINK); in send_unlink()
781 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, path); in send_unlink()
783 ret = send_cmd(sctx); in send_unlink()
793 static int send_rmdir(struct send_ctx *sctx, struct fs_path *path) in send_rmdir() argument
795 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_rmdir()
800 ret = begin_cmd(sctx, BTRFS_SEND_C_RMDIR); in send_rmdir()
804 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, path); in send_rmdir()
806 ret = send_cmd(sctx); in send_rmdir()
1176 struct send_ctx *sctx; member
1232 found = bsearch((void *)(uintptr_t)root, bctx->sctx->clone_roots, in __iterate_backrefs()
1233 bctx->sctx->clone_roots_cnt, in __iterate_backrefs()
1239 if (found->root == bctx->sctx->send_root && in __iterate_backrefs()
1249 if (found->root == bctx->sctx->send_root) { in __iterate_backrefs()
1285 static int find_extent_clone(struct send_ctx *sctx, in find_extent_clone() argument
1291 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in find_extent_clone()
1364 for (i = 0; i < sctx->clone_roots_cnt; i++) { in find_extent_clone()
1365 cur_clone_root = sctx->clone_roots + i; in find_extent_clone()
1371 backref_ctx->sctx = sctx; in find_extent_clone()
1430 for (i = 0; i < sctx->clone_roots_cnt; i++) { in find_extent_clone()
1431 if (sctx->clone_roots[i].found_refs) { in find_extent_clone()
1433 cur_clone_root = sctx->clone_roots + i; in find_extent_clone()
1434 else if (sctx->clone_roots[i].root == sctx->send_root) in find_extent_clone()
1436 cur_clone_root = sctx->clone_roots + i; in find_extent_clone()
1514 static int gen_unique_name(struct send_ctx *sctx, in gen_unique_name() argument
1534 di = btrfs_lookup_dir_item(NULL, sctx->send_root, in gen_unique_name()
1548 if (!sctx->parent_root) { in gen_unique_name()
1554 di = btrfs_lookup_dir_item(NULL, sctx->parent_root, in gen_unique_name()
1586 static int get_cur_inode_state(struct send_ctx *sctx, u64 ino, u64 gen) in get_cur_inode_state() argument
1594 ret = get_inode_info(sctx->send_root, ino, NULL, &left_gen, NULL, NULL, in get_cur_inode_state()
1600 if (!sctx->parent_root) { in get_cur_inode_state()
1603 ret = get_inode_info(sctx->parent_root, ino, NULL, &right_gen, in get_cur_inode_state()
1614 if (ino < sctx->send_progress) in get_cur_inode_state()
1619 if (ino < sctx->send_progress) in get_cur_inode_state()
1628 if (ino < sctx->send_progress) in get_cur_inode_state()
1637 if (ino < sctx->send_progress) in get_cur_inode_state()
1652 static int is_inode_existent(struct send_ctx *sctx, u64 ino, u64 gen) in is_inode_existent() argument
1659 ret = get_cur_inode_state(sctx, ino, gen); in is_inode_existent()
1819 static int will_overwrite_ref(struct send_ctx *sctx, u64 dir, u64 dir_gen, in will_overwrite_ref() argument
1828 if (!sctx->parent_root) in will_overwrite_ref()
1831 ret = is_inode_existent(sctx, dir, dir_gen); in will_overwrite_ref()
1840 if (sctx->parent_root && dir != BTRFS_FIRST_FREE_OBJECTID) { in will_overwrite_ref()
1841 ret = get_inode_info(sctx->parent_root, dir, NULL, &gen, NULL, in will_overwrite_ref()
1853 ret = lookup_dir_item_inode(sctx->parent_root, dir, name, name_len, in will_overwrite_ref()
1867 if (other_inode > sctx->send_progress || in will_overwrite_ref()
1868 is_waiting_for_move(sctx, other_inode)) { in will_overwrite_ref()
1869 ret = get_inode_info(sctx->parent_root, other_inode, NULL, in will_overwrite_ref()
1891 static int did_overwrite_ref(struct send_ctx *sctx, in did_overwrite_ref() argument
1901 if (!sctx->parent_root) in did_overwrite_ref()
1904 ret = is_inode_existent(sctx, dir, dir_gen); in did_overwrite_ref()
1909 ret = get_inode_info(sctx->send_root, dir, NULL, &gen, NULL, in did_overwrite_ref()
1922 ret = lookup_dir_item_inode(sctx->send_root, dir, name, name_len, in did_overwrite_ref()
1932 ret = get_inode_info(sctx->send_root, ow_inode, NULL, &gen, NULL, NULL, in did_overwrite_ref()
1948 if ((ow_inode < sctx->send_progress) || in did_overwrite_ref()
1949 (ino != sctx->cur_ino && ow_inode == sctx->cur_ino && in did_overwrite_ref()
1950 gen == sctx->cur_inode_gen)) in did_overwrite_ref()
1964 static int did_overwrite_first_ref(struct send_ctx *sctx, u64 ino, u64 gen) in did_overwrite_first_ref() argument
1971 if (!sctx->parent_root) in did_overwrite_first_ref()
1978 ret = get_first_ref(sctx->parent_root, ino, &dir, &dir_gen, name); in did_overwrite_first_ref()
1982 ret = did_overwrite_ref(sctx, dir, dir_gen, ino, gen, in did_overwrite_first_ref()
1996 static int name_cache_insert(struct send_ctx *sctx, in name_cache_insert() argument
2002 nce_head = radix_tree_lookup(&sctx->name_cache, in name_cache_insert()
2012 ret = radix_tree_insert(&sctx->name_cache, nce->ino, nce_head); in name_cache_insert()
2020 list_add_tail(&nce->list, &sctx->name_cache_list); in name_cache_insert()
2021 sctx->name_cache_size++; in name_cache_insert()
2026 static void name_cache_delete(struct send_ctx *sctx, in name_cache_delete() argument
2031 nce_head = radix_tree_lookup(&sctx->name_cache, in name_cache_delete()
2034 btrfs_err(sctx->send_root->fs_info, in name_cache_delete()
2036 nce->ino, sctx->name_cache_size); in name_cache_delete()
2041 sctx->name_cache_size--; in name_cache_delete()
2047 radix_tree_delete(&sctx->name_cache, (unsigned long)nce->ino); in name_cache_delete()
2052 static struct name_cache_entry *name_cache_search(struct send_ctx *sctx, in name_cache_search() argument
2058 nce_head = radix_tree_lookup(&sctx->name_cache, (unsigned long)ino); in name_cache_search()
2073 static void name_cache_used(struct send_ctx *sctx, struct name_cache_entry *nce) in name_cache_used() argument
2076 list_add_tail(&nce->list, &sctx->name_cache_list); in name_cache_used()
2082 static void name_cache_clean_unused(struct send_ctx *sctx) in name_cache_clean_unused() argument
2086 if (sctx->name_cache_size < SEND_CTX_NAME_CACHE_CLEAN_SIZE) in name_cache_clean_unused()
2089 while (sctx->name_cache_size > SEND_CTX_MAX_NAME_CACHE_SIZE) { in name_cache_clean_unused()
2090 nce = list_entry(sctx->name_cache_list.next, in name_cache_clean_unused()
2092 name_cache_delete(sctx, nce); in name_cache_clean_unused()
2097 static void name_cache_free(struct send_ctx *sctx) in name_cache_free() argument
2101 while (!list_empty(&sctx->name_cache_list)) { in name_cache_free()
2102 nce = list_entry(sctx->name_cache_list.next, in name_cache_free()
2104 name_cache_delete(sctx, nce); in name_cache_free()
2117 static int __get_cur_name_and_parent(struct send_ctx *sctx, in __get_cur_name_and_parent() argument
2132 nce = name_cache_search(sctx, ino, gen); in __get_cur_name_and_parent()
2134 if (ino < sctx->send_progress && nce->need_later_update) { in __get_cur_name_and_parent()
2135 name_cache_delete(sctx, nce); in __get_cur_name_and_parent()
2139 name_cache_used(sctx, nce); in __get_cur_name_and_parent()
2155 ret = is_inode_existent(sctx, ino, gen); in __get_cur_name_and_parent()
2160 ret = gen_unique_name(sctx, ino, gen, dest); in __get_cur_name_and_parent()
2171 if (ino < sctx->send_progress) in __get_cur_name_and_parent()
2172 ret = get_first_ref(sctx->send_root, ino, in __get_cur_name_and_parent()
2175 ret = get_first_ref(sctx->parent_root, ino, in __get_cur_name_and_parent()
2184 ret = did_overwrite_ref(sctx, *parent_ino, *parent_gen, ino, gen, in __get_cur_name_and_parent()
2190 ret = gen_unique_name(sctx, ino, gen, dest); in __get_cur_name_and_parent()
2214 if (ino < sctx->send_progress) in __get_cur_name_and_parent()
2219 nce_ret = name_cache_insert(sctx, nce); in __get_cur_name_and_parent()
2222 name_cache_clean_unused(sctx); in __get_cur_name_and_parent()
2253 static int get_cur_path(struct send_ctx *sctx, u64 ino, u64 gen, in get_cur_path() argument
2276 if (is_waiting_for_rm(sctx, ino)) { in get_cur_path()
2277 ret = gen_unique_name(sctx, ino, gen, name); in get_cur_path()
2284 wdm = get_waiting_dir_move(sctx, ino); in get_cur_path()
2286 ret = gen_unique_name(sctx, ino, gen, name); in get_cur_path()
2289 ret = get_first_ref(sctx->parent_root, ino, in get_cur_path()
2292 ret = __get_cur_name_and_parent(sctx, ino, gen, in get_cur_path()
2320 static int send_subvol_begin(struct send_ctx *sctx) in send_subvol_begin() argument
2323 struct btrfs_root *send_root = sctx->send_root; in send_subvol_begin()
2324 struct btrfs_root *parent_root = sctx->parent_root; in send_subvol_begin()
2368 ret = begin_cmd(sctx, BTRFS_SEND_C_SNAPSHOT); in send_subvol_begin()
2372 ret = begin_cmd(sctx, BTRFS_SEND_C_SUBVOL); in send_subvol_begin()
2377 TLV_PUT_STRING(sctx, BTRFS_SEND_A_PATH, name, namelen); in send_subvol_begin()
2379 if (!btrfs_is_empty_uuid(sctx->send_root->root_item.received_uuid)) in send_subvol_begin()
2380 TLV_PUT_UUID(sctx, BTRFS_SEND_A_UUID, in send_subvol_begin()
2381 sctx->send_root->root_item.received_uuid); in send_subvol_begin()
2383 TLV_PUT_UUID(sctx, BTRFS_SEND_A_UUID, in send_subvol_begin()
2384 sctx->send_root->root_item.uuid); in send_subvol_begin()
2386 TLV_PUT_U64(sctx, BTRFS_SEND_A_CTRANSID, in send_subvol_begin()
2387 le64_to_cpu(sctx->send_root->root_item.ctransid)); in send_subvol_begin()
2390 TLV_PUT_UUID(sctx, BTRFS_SEND_A_CLONE_UUID, in send_subvol_begin()
2393 TLV_PUT_UUID(sctx, BTRFS_SEND_A_CLONE_UUID, in send_subvol_begin()
2395 TLV_PUT_U64(sctx, BTRFS_SEND_A_CLONE_CTRANSID, in send_subvol_begin()
2396 le64_to_cpu(sctx->parent_root->root_item.ctransid)); in send_subvol_begin()
2399 ret = send_cmd(sctx); in send_subvol_begin()
2408 static int send_truncate(struct send_ctx *sctx, u64 ino, u64 gen, u64 size) in send_truncate() argument
2410 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_truncate()
2420 ret = begin_cmd(sctx, BTRFS_SEND_C_TRUNCATE); in send_truncate()
2424 ret = get_cur_path(sctx, ino, gen, p); in send_truncate()
2427 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); in send_truncate()
2428 TLV_PUT_U64(sctx, BTRFS_SEND_A_SIZE, size); in send_truncate()
2430 ret = send_cmd(sctx); in send_truncate()
2438 static int send_chmod(struct send_ctx *sctx, u64 ino, u64 gen, u64 mode) in send_chmod() argument
2440 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_chmod()
2450 ret = begin_cmd(sctx, BTRFS_SEND_C_CHMOD); in send_chmod()
2454 ret = get_cur_path(sctx, ino, gen, p); in send_chmod()
2457 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); in send_chmod()
2458 TLV_PUT_U64(sctx, BTRFS_SEND_A_MODE, mode & 07777); in send_chmod()
2460 ret = send_cmd(sctx); in send_chmod()
2468 static int send_chown(struct send_ctx *sctx, u64 ino, u64 gen, u64 uid, u64 gid) in send_chown() argument
2470 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_chown()
2481 ret = begin_cmd(sctx, BTRFS_SEND_C_CHOWN); in send_chown()
2485 ret = get_cur_path(sctx, ino, gen, p); in send_chown()
2488 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); in send_chown()
2489 TLV_PUT_U64(sctx, BTRFS_SEND_A_UID, uid); in send_chown()
2490 TLV_PUT_U64(sctx, BTRFS_SEND_A_GID, gid); in send_chown()
2492 ret = send_cmd(sctx); in send_chown()
2500 static int send_utimes(struct send_ctx *sctx, u64 ino, u64 gen) in send_utimes() argument
2502 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_utimes()
2526 ret = btrfs_search_slot(NULL, sctx->send_root, &key, path, 0, 0); in send_utimes()
2536 ret = begin_cmd(sctx, BTRFS_SEND_C_UTIMES); in send_utimes()
2540 ret = get_cur_path(sctx, ino, gen, p); in send_utimes()
2543 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); in send_utimes()
2544 TLV_PUT_BTRFS_TIMESPEC(sctx, BTRFS_SEND_A_ATIME, eb, &ii->atime); in send_utimes()
2545 TLV_PUT_BTRFS_TIMESPEC(sctx, BTRFS_SEND_A_MTIME, eb, &ii->mtime); in send_utimes()
2546 TLV_PUT_BTRFS_TIMESPEC(sctx, BTRFS_SEND_A_CTIME, eb, &ii->ctime); in send_utimes()
2549 ret = send_cmd(sctx); in send_utimes()
2563 static int send_create_inode(struct send_ctx *sctx, u64 ino) in send_create_inode() argument
2565 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_create_inode()
2579 if (ino != sctx->cur_ino) { in send_create_inode()
2580 ret = get_inode_info(sctx->send_root, ino, NULL, &gen, &mode, in send_create_inode()
2585 gen = sctx->cur_inode_gen; in send_create_inode()
2586 mode = sctx->cur_inode_mode; in send_create_inode()
2587 rdev = sctx->cur_inode_rdev; in send_create_inode()
2603 btrfs_warn(sctx->send_root->fs_info, "unexpected inode type %o", in send_create_inode()
2609 ret = begin_cmd(sctx, cmd); in send_create_inode()
2613 ret = gen_unique_name(sctx, ino, gen, p); in send_create_inode()
2617 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); in send_create_inode()
2618 TLV_PUT_U64(sctx, BTRFS_SEND_A_INO, ino); in send_create_inode()
2622 ret = read_symlink(sctx->send_root, ino, p); in send_create_inode()
2625 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH_LINK, p); in send_create_inode()
2628 TLV_PUT_U64(sctx, BTRFS_SEND_A_RDEV, new_encode_dev(rdev)); in send_create_inode()
2629 TLV_PUT_U64(sctx, BTRFS_SEND_A_MODE, mode); in send_create_inode()
2632 ret = send_cmd(sctx); in send_create_inode()
2648 static int did_create_dir(struct send_ctx *sctx, u64 dir) in did_create_dir() argument
2668 ret = btrfs_search_slot(NULL, sctx->send_root, &key, path, 0, 0); in did_create_dir()
2676 ret = btrfs_next_leaf(sctx->send_root, path); in did_create_dir()
2697 di_key.objectid < sctx->send_progress) { in did_create_dir()
2716 static int send_create_inode_if_needed(struct send_ctx *sctx) in send_create_inode_if_needed() argument
2720 if (S_ISDIR(sctx->cur_inode_mode)) { in send_create_inode_if_needed()
2721 ret = did_create_dir(sctx, sctx->cur_ino); in send_create_inode_if_needed()
2730 ret = send_create_inode(sctx, sctx->cur_ino); in send_create_inode_if_needed()
2803 static void free_recorded_refs(struct send_ctx *sctx) in free_recorded_refs() argument
2805 __free_recorded_refs(&sctx->new_refs); in free_recorded_refs()
2806 __free_recorded_refs(&sctx->deleted_refs); in free_recorded_refs()
2814 static int orphanize_inode(struct send_ctx *sctx, u64 ino, u64 gen, in orphanize_inode() argument
2824 ret = gen_unique_name(sctx, ino, gen, orphan); in orphanize_inode()
2828 ret = send_rename(sctx, path, orphan); in orphanize_inode()
2836 add_orphan_dir_info(struct send_ctx *sctx, u64 dir_ino) in add_orphan_dir_info() argument
2838 struct rb_node **p = &sctx->orphan_dirs.rb_node; in add_orphan_dir_info()
2862 rb_insert_color(&odi->node, &sctx->orphan_dirs); in add_orphan_dir_info()
2867 get_orphan_dir_info(struct send_ctx *sctx, u64 dir_ino) in get_orphan_dir_info() argument
2869 struct rb_node *n = sctx->orphan_dirs.rb_node; in get_orphan_dir_info()
2884 static int is_waiting_for_rm(struct send_ctx *sctx, u64 dir_ino) in is_waiting_for_rm() argument
2886 struct orphan_dir_info *odi = get_orphan_dir_info(sctx, dir_ino); in is_waiting_for_rm()
2891 static void free_orphan_dir_info(struct send_ctx *sctx, in free_orphan_dir_info() argument
2896 rb_erase(&odi->node, &sctx->orphan_dirs); in free_orphan_dir_info()
2905 static int can_rmdir(struct send_ctx *sctx, u64 dir, u64 dir_gen, in can_rmdir() argument
2909 struct btrfs_root *root = sctx->parent_root; in can_rmdir()
2931 odi = get_orphan_dir_info(sctx, dir); in can_rmdir()
2960 dm = get_waiting_dir_move(sctx, loc.objectid); in can_rmdir()
2962 odi = add_orphan_dir_info(sctx, dir); in can_rmdir()
2975 odi = add_orphan_dir_info(sctx, dir); in can_rmdir()
2988 free_orphan_dir_info(sctx, odi); in can_rmdir()
2997 static int is_waiting_for_move(struct send_ctx *sctx, u64 ino) in is_waiting_for_move() argument
2999 struct waiting_dir_move *entry = get_waiting_dir_move(sctx, ino); in is_waiting_for_move()
3004 static int add_waiting_dir_move(struct send_ctx *sctx, u64 ino, bool orphanized) in add_waiting_dir_move() argument
3006 struct rb_node **p = &sctx->waiting_dir_moves.rb_node; in add_waiting_dir_move()
3031 rb_insert_color(&dm->node, &sctx->waiting_dir_moves); in add_waiting_dir_move()
3036 get_waiting_dir_move(struct send_ctx *sctx, u64 ino) in get_waiting_dir_move() argument
3038 struct rb_node *n = sctx->waiting_dir_moves.rb_node; in get_waiting_dir_move()
3053 static void free_waiting_dir_move(struct send_ctx *sctx, in free_waiting_dir_move() argument
3058 rb_erase(&dm->node, &sctx->waiting_dir_moves); in free_waiting_dir_move()
3062 static int add_pending_dir_move(struct send_ctx *sctx, in add_pending_dir_move() argument
3070 struct rb_node **p = &sctx->pending_dir_moves.rb_node; in add_pending_dir_move()
3111 ret = add_waiting_dir_move(sctx, pm->ino, is_orphan); in add_pending_dir_move()
3119 rb_insert_color(&pm->node, &sctx->pending_dir_moves); in add_pending_dir_move()
3130 static struct pending_dir_move *get_pending_dir_moves(struct send_ctx *sctx, in get_pending_dir_moves() argument
3133 struct rb_node *n = sctx->pending_dir_moves.rb_node; in get_pending_dir_moves()
3148 static int path_loop(struct send_ctx *sctx, struct fs_path *name, in path_loop() argument
3160 if (is_waiting_for_rm(sctx, ino)) in path_loop()
3162 if (is_waiting_for_move(sctx, ino)) { in path_loop()
3165 ret = get_first_ref(sctx->parent_root, ino, in path_loop()
3168 ret = __get_cur_name_and_parent(sctx, ino, gen, in path_loop()
3190 static int apply_dir_move(struct send_ctx *sctx, struct pending_dir_move *pm) in apply_dir_move() argument
3195 u64 orig_progress = sctx->send_progress; in apply_dir_move()
3211 dm = get_waiting_dir_move(sctx, pm->ino); in apply_dir_move()
3215 free_waiting_dir_move(sctx, dm); in apply_dir_move()
3218 ret = gen_unique_name(sctx, pm->ino, in apply_dir_move()
3221 ret = get_first_ref(sctx->parent_root, pm->ino, in apply_dir_move()
3225 ret = get_cur_path(sctx, parent_ino, parent_gen, in apply_dir_move()
3234 sctx->send_progress = sctx->cur_ino + 1; in apply_dir_move()
3235 ret = path_loop(sctx, name, pm->ino, pm->gen, &ancestor); in apply_dir_move()
3241 ret = add_pending_dir_move(sctx, pm->ino, pm->gen, ancestor, in apply_dir_move()
3247 dm = get_waiting_dir_move(sctx, pm->ino); in apply_dir_move()
3256 ret = get_cur_path(sctx, pm->ino, pm->gen, to_path); in apply_dir_move()
3260 ret = send_rename(sctx, from_path, to_path); in apply_dir_move()
3268 odi = get_orphan_dir_info(sctx, rmdir_ino); in apply_dir_move()
3275 ret = can_rmdir(sctx, rmdir_ino, gen, sctx->cur_ino); in apply_dir_move()
3286 ret = get_cur_path(sctx, rmdir_ino, gen, name); in apply_dir_move()
3289 ret = send_rmdir(sctx, name); in apply_dir_move()
3295 ret = send_utimes(sctx, pm->ino, pm->gen); in apply_dir_move()
3307 ret = get_inode_info(sctx->send_root, cur->dir, NULL, in apply_dir_move()
3316 ret = send_utimes(sctx, cur->dir, cur->dir_gen); in apply_dir_move()
3325 sctx->send_progress = orig_progress; in apply_dir_move()
3330 static void free_pending_move(struct send_ctx *sctx, struct pending_dir_move *m) in free_pending_move() argument
3335 rb_erase(&m->node, &sctx->pending_dir_moves); in free_pending_move()
3340 static void tail_append_pending_moves(struct send_ctx *sctx, in tail_append_pending_moves() argument
3353 rb_erase(&moves->node, &sctx->pending_dir_moves); in tail_append_pending_moves()
3358 static int apply_children_dir_moves(struct send_ctx *sctx) in apply_children_dir_moves() argument
3362 u64 parent_ino = sctx->cur_ino; in apply_children_dir_moves()
3365 pm = get_pending_dir_moves(sctx, parent_ino); in apply_children_dir_moves()
3370 tail_append_pending_moves(sctx, pm, &stack); in apply_children_dir_moves()
3375 ret = apply_dir_move(sctx, pm); in apply_children_dir_moves()
3376 free_pending_move(sctx, pm); in apply_children_dir_moves()
3379 pm = get_pending_dir_moves(sctx, parent_ino); in apply_children_dir_moves()
3381 tail_append_pending_moves(sctx, pm, &stack); in apply_children_dir_moves()
3388 free_pending_move(sctx, pm); in apply_children_dir_moves()
3429 static int wait_for_dest_dir_move(struct send_ctx *sctx, in wait_for_dest_dir_move() argument
3433 struct btrfs_fs_info *fs_info = sctx->parent_root->fs_info; in wait_for_dest_dir_move()
3443 if (RB_EMPTY_ROOT(&sctx->waiting_dir_moves)) in wait_for_dest_dir_move()
3454 ret = btrfs_search_slot(NULL, sctx->parent_root, &key, path, 0, 0); in wait_for_dest_dir_move()
3482 ret = get_inode_info(sctx->parent_root, di_key.objectid, NULL, in wait_for_dest_dir_move()
3486 ret = get_inode_info(sctx->send_root, di_key.objectid, NULL, in wait_for_dest_dir_move()
3500 wdm = get_waiting_dir_move(sctx, di_key.objectid); in wait_for_dest_dir_move()
3502 ret = add_pending_dir_move(sctx, in wait_for_dest_dir_move()
3503 sctx->cur_ino, in wait_for_dest_dir_move()
3504 sctx->cur_inode_gen, in wait_for_dest_dir_move()
3506 &sctx->new_refs, in wait_for_dest_dir_move()
3507 &sctx->deleted_refs, in wait_for_dest_dir_move()
3649 static int wait_for_parent_move(struct send_ctx *sctx, in wait_for_parent_move() argument
3678 if (is_waiting_for_move(sctx, ino)) { in wait_for_parent_move()
3689 ret = is_ancestor(sctx->parent_root, in wait_for_parent_move()
3690 sctx->cur_ino, sctx->cur_inode_gen, in wait_for_parent_move()
3699 ret = get_first_ref(sctx->send_root, ino, &parent_ino_after, in wait_for_parent_move()
3703 ret = get_first_ref(sctx->parent_root, ino, &parent_ino_before, in wait_for_parent_move()
3714 if (ino > sctx->cur_ino && in wait_for_parent_move()
3719 ret = get_inode_info(sctx->parent_root, ino, NULL, in wait_for_parent_move()
3738 ret = add_pending_dir_move(sctx, in wait_for_parent_move()
3739 sctx->cur_ino, in wait_for_parent_move()
3740 sctx->cur_inode_gen, in wait_for_parent_move()
3742 &sctx->new_refs, in wait_for_parent_move()
3743 &sctx->deleted_refs, in wait_for_parent_move()
3752 static int update_ref_path(struct send_ctx *sctx, struct recorded_ref *ref) in update_ref_path() argument
3765 ret = get_cur_path(sctx, ref->dir, ref->dir_gen, new_path); in update_ref_path()
3785 static int process_recorded_refs(struct send_ctx *sctx, int *pending_move) in process_recorded_refs() argument
3787 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in process_recorded_refs()
3803 btrfs_debug(fs_info, "process_recorded_refs %llu", sctx->cur_ino); in process_recorded_refs()
3809 BUG_ON(sctx->cur_ino <= BTRFS_FIRST_FREE_OBJECTID); in process_recorded_refs()
3829 if (!sctx->cur_inode_new) { in process_recorded_refs()
3830 ret = did_overwrite_first_ref(sctx, sctx->cur_ino, in process_recorded_refs()
3831 sctx->cur_inode_gen); in process_recorded_refs()
3837 if (sctx->cur_inode_new || did_overwrite) { in process_recorded_refs()
3838 ret = gen_unique_name(sctx, sctx->cur_ino, in process_recorded_refs()
3839 sctx->cur_inode_gen, valid_path); in process_recorded_refs()
3844 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, in process_recorded_refs()
3850 list_for_each_entry(cur, &sctx->new_refs, list) { in process_recorded_refs()
3858 ret = get_cur_inode_state(sctx, cur->dir, cur->dir_gen); in process_recorded_refs()
3867 list_for_each_entry(cur2, &sctx->new_refs, list) { in process_recorded_refs()
3881 ret = did_create_dir(sctx, cur->dir); in process_recorded_refs()
3885 ret = send_create_inode(sctx, cur->dir); in process_recorded_refs()
3897 ret = will_overwrite_ref(sctx, cur->dir, cur->dir_gen, in process_recorded_refs()
3903 ret = is_first_ref(sctx->parent_root, in process_recorded_refs()
3912 ret = orphanize_inode(sctx, ow_inode, ow_gen, in process_recorded_refs()
3925 if (is_waiting_for_move(sctx, ow_inode)) { in process_recorded_refs()
3926 wdm = get_waiting_dir_move(sctx, in process_recorded_refs()
3942 nce = name_cache_search(sctx, ow_inode, ow_gen); in process_recorded_refs()
3944 name_cache_delete(sctx, nce); in process_recorded_refs()
3955 ret = is_ancestor(sctx->parent_root, in process_recorded_refs()
3957 sctx->cur_ino, NULL); in process_recorded_refs()
3961 ret = get_cur_path(sctx, sctx->cur_ino, in process_recorded_refs()
3962 sctx->cur_inode_gen, in process_recorded_refs()
3968 ret = send_unlink(sctx, cur->full_path); in process_recorded_refs()
3974 if (S_ISDIR(sctx->cur_inode_mode) && sctx->parent_root) { in process_recorded_refs()
3975 ret = wait_for_dest_dir_move(sctx, cur, is_orphan); in process_recorded_refs()
3984 if (S_ISDIR(sctx->cur_inode_mode) && sctx->parent_root && in process_recorded_refs()
3986 ret = wait_for_parent_move(sctx, cur, is_orphan); in process_recorded_refs()
4001 ret = send_rename(sctx, valid_path, cur->full_path); in process_recorded_refs()
4009 if (S_ISDIR(sctx->cur_inode_mode)) { in process_recorded_refs()
4015 ret = send_rename(sctx, valid_path, in process_recorded_refs()
4031 ret = update_ref_path(sctx, cur); in process_recorded_refs()
4035 ret = send_link(sctx, cur->full_path, in process_recorded_refs()
4046 if (S_ISDIR(sctx->cur_inode_mode) && sctx->cur_inode_deleted) { in process_recorded_refs()
4053 ret = can_rmdir(sctx, sctx->cur_ino, sctx->cur_inode_gen, in process_recorded_refs()
4054 sctx->cur_ino); in process_recorded_refs()
4058 ret = send_rmdir(sctx, valid_path); in process_recorded_refs()
4062 ret = orphanize_inode(sctx, sctx->cur_ino, in process_recorded_refs()
4063 sctx->cur_inode_gen, valid_path); in process_recorded_refs()
4069 list_for_each_entry(cur, &sctx->deleted_refs, list) { in process_recorded_refs()
4074 } else if (S_ISDIR(sctx->cur_inode_mode) && in process_recorded_refs()
4075 !list_empty(&sctx->deleted_refs)) { in process_recorded_refs()
4079 cur = list_entry(sctx->deleted_refs.next, struct recorded_ref, in process_recorded_refs()
4084 } else if (!S_ISDIR(sctx->cur_inode_mode)) { in process_recorded_refs()
4090 list_for_each_entry(cur, &sctx->deleted_refs, list) { in process_recorded_refs()
4091 ret = did_overwrite_ref(sctx, cur->dir, cur->dir_gen, in process_recorded_refs()
4092 sctx->cur_ino, sctx->cur_inode_gen, in process_recorded_refs()
4105 ret = update_ref_path(sctx, cur); in process_recorded_refs()
4109 ret = send_unlink(sctx, cur->full_path); in process_recorded_refs()
4126 ret = send_unlink(sctx, valid_path); in process_recorded_refs()
4144 if (cur->dir > sctx->cur_ino) in process_recorded_refs()
4147 ret = get_cur_inode_state(sctx, cur->dir, cur->dir_gen); in process_recorded_refs()
4154 ret = send_utimes(sctx, cur->dir, cur->dir_gen); in process_recorded_refs()
4159 ret = can_rmdir(sctx, cur->dir, cur->dir_gen, in process_recorded_refs()
4160 sctx->cur_ino); in process_recorded_refs()
4164 ret = get_cur_path(sctx, cur->dir, in process_recorded_refs()
4168 ret = send_rmdir(sctx, valid_path); in process_recorded_refs()
4180 free_recorded_refs(sctx); in process_recorded_refs()
4189 struct send_ctx *sctx = ctx; in record_ref() local
4202 ret = get_cur_path(sctx, dir, gen, p); in record_ref()
4221 struct send_ctx *sctx = ctx; in __record_new_ref() local
4222 return record_ref(sctx->send_root, dir, name, ctx, &sctx->new_refs); in __record_new_ref()
4230 struct send_ctx *sctx = ctx; in __record_deleted_ref() local
4231 return record_ref(sctx->parent_root, dir, name, ctx, in __record_deleted_ref()
4232 &sctx->deleted_refs); in __record_deleted_ref()
4235 static int record_new_ref(struct send_ctx *sctx) in record_new_ref() argument
4239 ret = iterate_inode_ref(sctx->send_root, sctx->left_path, in record_new_ref()
4240 sctx->cmp_key, 0, __record_new_ref, sctx); in record_new_ref()
4249 static int record_deleted_ref(struct send_ctx *sctx) in record_deleted_ref() argument
4253 ret = iterate_inode_ref(sctx->parent_root, sctx->right_path, in record_deleted_ref()
4254 sctx->cmp_key, 0, __record_deleted_ref, sctx); in record_deleted_ref()
4327 struct send_ctx *sctx = ctx; in __record_changed_new_ref() local
4329 ret = get_inode_info(sctx->send_root, dir, NULL, &dir_gen, NULL, in __record_changed_new_ref()
4334 ret = find_iref(sctx->parent_root, sctx->right_path, in __record_changed_new_ref()
4335 sctx->cmp_key, dir, dir_gen, name); in __record_changed_new_ref()
4337 ret = __record_new_ref(num, dir, index, name, sctx); in __record_changed_new_ref()
4350 struct send_ctx *sctx = ctx; in __record_changed_deleted_ref() local
4352 ret = get_inode_info(sctx->parent_root, dir, NULL, &dir_gen, NULL, in __record_changed_deleted_ref()
4357 ret = find_iref(sctx->send_root, sctx->left_path, sctx->cmp_key, in __record_changed_deleted_ref()
4360 ret = __record_deleted_ref(num, dir, index, name, sctx); in __record_changed_deleted_ref()
4367 static int record_changed_ref(struct send_ctx *sctx) in record_changed_ref() argument
4371 ret = iterate_inode_ref(sctx->send_root, sctx->left_path, in record_changed_ref()
4372 sctx->cmp_key, 0, __record_changed_new_ref, sctx); in record_changed_ref()
4375 ret = iterate_inode_ref(sctx->parent_root, sctx->right_path, in record_changed_ref()
4376 sctx->cmp_key, 0, __record_changed_deleted_ref, sctx); in record_changed_ref()
4389 static int process_all_refs(struct send_ctx *sctx, in process_all_refs() argument
4407 root = sctx->send_root; in process_all_refs()
4410 root = sctx->parent_root; in process_all_refs()
4413 btrfs_err(sctx->send_root->fs_info, in process_all_refs()
4419 key.objectid = sctx->cmp_key->objectid; in process_all_refs()
4445 ret = iterate_inode_ref(root, path, &found_key, 0, cb, sctx); in process_all_refs()
4458 ret = process_recorded_refs(sctx, &pending_move); in process_all_refs()
4464 static int send_set_xattr(struct send_ctx *sctx, in send_set_xattr() argument
4471 ret = begin_cmd(sctx, BTRFS_SEND_C_SET_XATTR); in send_set_xattr()
4475 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, path); in send_set_xattr()
4476 TLV_PUT_STRING(sctx, BTRFS_SEND_A_XATTR_NAME, name, name_len); in send_set_xattr()
4477 TLV_PUT(sctx, BTRFS_SEND_A_XATTR_DATA, data, data_len); in send_set_xattr()
4479 ret = send_cmd(sctx); in send_set_xattr()
4486 static int send_remove_xattr(struct send_ctx *sctx, in send_remove_xattr() argument
4492 ret = begin_cmd(sctx, BTRFS_SEND_C_REMOVE_XATTR); in send_remove_xattr()
4496 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, path); in send_remove_xattr()
4497 TLV_PUT_STRING(sctx, BTRFS_SEND_A_XATTR_NAME, name, name_len); in send_remove_xattr()
4499 ret = send_cmd(sctx); in send_remove_xattr()
4512 struct send_ctx *sctx = ctx; in __process_new_xattr() local
4536 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); in __process_new_xattr()
4540 ret = send_set_xattr(sctx, p, name, name_len, data, data_len); in __process_new_xattr()
4553 struct send_ctx *sctx = ctx; in __process_deleted_xattr() local
4560 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); in __process_deleted_xattr()
4564 ret = send_remove_xattr(sctx, p, name, name_len); in __process_deleted_xattr()
4571 static int process_new_xattr(struct send_ctx *sctx) in process_new_xattr() argument
4575 ret = iterate_dir_item(sctx->send_root, sctx->left_path, in process_new_xattr()
4576 __process_new_xattr, sctx); in process_new_xattr()
4581 static int process_deleted_xattr(struct send_ctx *sctx) in process_deleted_xattr() argument
4583 return iterate_dir_item(sctx->parent_root, sctx->right_path, in process_deleted_xattr()
4584 __process_deleted_xattr, sctx); in process_deleted_xattr()
4651 struct send_ctx *sctx = ctx; in __process_changed_new_xattr() local
4655 ret = find_xattr(sctx->parent_root, sctx->right_path, in __process_changed_new_xattr()
4656 sctx->cmp_key, name, name_len, &found_data, in __process_changed_new_xattr()
4681 struct send_ctx *sctx = ctx; in __process_changed_deleted_xattr() local
4683 ret = find_xattr(sctx->send_root, sctx->left_path, sctx->cmp_key, in __process_changed_deleted_xattr()
4694 static int process_changed_xattr(struct send_ctx *sctx) in process_changed_xattr() argument
4698 ret = iterate_dir_item(sctx->send_root, sctx->left_path, in process_changed_xattr()
4699 __process_changed_new_xattr, sctx); in process_changed_xattr()
4702 ret = iterate_dir_item(sctx->parent_root, sctx->right_path, in process_changed_xattr()
4703 __process_changed_deleted_xattr, sctx); in process_changed_xattr()
4709 static int process_all_new_xattrs(struct send_ctx *sctx) in process_all_new_xattrs() argument
4723 root = sctx->send_root; in process_all_new_xattrs()
4725 key.objectid = sctx->cmp_key->objectid; in process_all_new_xattrs()
4753 ret = iterate_dir_item(root, path, __process_new_xattr, sctx); in process_all_new_xattrs()
4765 static ssize_t fill_read_buf(struct send_ctx *sctx, u64 offset, u32 len) in fill_read_buf() argument
4767 struct btrfs_root *root = sctx->send_root; in fill_read_buf()
4778 key.objectid = sctx->cur_ino; in fill_read_buf()
4798 memset(&sctx->ra, 0, sizeof(struct file_ra_state)); in fill_read_buf()
4799 file_ra_state_init(&sctx->ra, inode->i_mapping); in fill_read_buf()
4807 page_cache_sync_readahead(inode->i_mapping, &sctx->ra, in fill_read_buf()
4819 page_cache_async_readahead(inode->i_mapping, &sctx->ra, in fill_read_buf()
4835 memcpy(sctx->read_buf + ret, addr + pg_offset, cur_len); in fill_read_buf()
4853 static int send_write(struct send_ctx *sctx, u64 offset, u32 len) in send_write() argument
4855 struct btrfs_fs_info *fs_info = sctx->send_root->fs_info; in send_write()
4866 num_read = fill_read_buf(sctx, offset, len); in send_write()
4873 ret = begin_cmd(sctx, BTRFS_SEND_C_WRITE); in send_write()
4877 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); in send_write()
4881 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); in send_write()
4882 TLV_PUT_U64(sctx, BTRFS_SEND_A_FILE_OFFSET, offset); in send_write()
4883 TLV_PUT(sctx, BTRFS_SEND_A_DATA, sctx->read_buf, num_read); in send_write()
4885 ret = send_cmd(sctx); in send_write()
4898 static int send_clone(struct send_ctx *sctx, in send_clone() argument
4906 btrfs_debug(sctx->send_root->fs_info, in send_clone()
4915 ret = begin_cmd(sctx, BTRFS_SEND_C_CLONE); in send_clone()
4919 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); in send_clone()
4923 TLV_PUT_U64(sctx, BTRFS_SEND_A_FILE_OFFSET, offset); in send_clone()
4924 TLV_PUT_U64(sctx, BTRFS_SEND_A_CLONE_LEN, len); in send_clone()
4925 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); in send_clone()
4927 if (clone_root->root == sctx->send_root) { in send_clone()
4928 ret = get_inode_info(sctx->send_root, clone_root->ino, NULL, in send_clone()
4932 ret = get_cur_path(sctx, clone_root->ino, gen, p); in send_clone()
4949 TLV_PUT_UUID(sctx, BTRFS_SEND_A_CLONE_UUID, in send_clone()
4952 TLV_PUT_UUID(sctx, BTRFS_SEND_A_CLONE_UUID, in send_clone()
4954 TLV_PUT_U64(sctx, BTRFS_SEND_A_CLONE_CTRANSID, in send_clone()
4956 TLV_PUT_PATH(sctx, BTRFS_SEND_A_CLONE_PATH, p); in send_clone()
4957 TLV_PUT_U64(sctx, BTRFS_SEND_A_CLONE_OFFSET, in send_clone()
4960 ret = send_cmd(sctx); in send_clone()
4971 static int send_update_extent(struct send_ctx *sctx, in send_update_extent() argument
4981 ret = begin_cmd(sctx, BTRFS_SEND_C_UPDATE_EXTENT); in send_update_extent()
4985 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); in send_update_extent()
4989 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); in send_update_extent()
4990 TLV_PUT_U64(sctx, BTRFS_SEND_A_FILE_OFFSET, offset); in send_update_extent()
4991 TLV_PUT_U64(sctx, BTRFS_SEND_A_SIZE, len); in send_update_extent()
4993 ret = send_cmd(sctx); in send_update_extent()
5001 static int send_hole(struct send_ctx *sctx, u64 end) in send_hole() argument
5004 u64 offset = sctx->cur_inode_last_extent; in send_hole()
5014 if (offset >= sctx->cur_inode_size) in send_hole()
5021 end = min_t(u64, end, sctx->cur_inode_size); in send_hole()
5023 if (sctx->flags & BTRFS_SEND_FLAG_NO_FILE_DATA) in send_hole()
5024 return send_update_extent(sctx, offset, end - offset); in send_hole()
5029 ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); in send_hole()
5032 memset(sctx->read_buf, 0, BTRFS_SEND_READ_SIZE); in send_hole()
5036 ret = begin_cmd(sctx, BTRFS_SEND_C_WRITE); in send_hole()
5039 TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); in send_hole()
5040 TLV_PUT_U64(sctx, BTRFS_SEND_A_FILE_OFFSET, offset); in send_hole()
5041 TLV_PUT(sctx, BTRFS_SEND_A_DATA, sctx->read_buf, len); in send_hole()
5042 ret = send_cmd(sctx); in send_hole()
5047 sctx->cur_inode_next_write_offset = offset; in send_hole()
5053 static int send_extent_data(struct send_ctx *sctx, in send_extent_data() argument
5059 if (sctx->flags & BTRFS_SEND_FLAG_NO_FILE_DATA) in send_extent_data()
5060 return send_update_extent(sctx, offset, len); in send_extent_data()
5068 ret = send_write(sctx, offset + sent, size); in send_extent_data()
5078 static int clone_range(struct send_ctx *sctx, in clone_range() argument
5106 len == sctx->send_root->fs_info->sectorsize) in clone_range()
5107 return send_extent_data(sctx, offset, len); in clone_range()
5204 ret = send_extent_data(sctx, offset, hole_len); in clone_range()
5266 offset + clone_len < sctx->cur_inode_size) { in clone_range()
5272 ret = send_clone(sctx, offset, slen, in clone_range()
5277 ret = send_extent_data(sctx, offset + slen, in clone_range()
5280 ret = send_clone(sctx, offset, clone_len, in clone_range()
5284 ret = send_extent_data(sctx, offset, clone_len); in clone_range()
5301 ret = send_extent_data(sctx, offset, len); in clone_range()
5309 static int send_write_or_clone(struct send_ctx *sctx, in send_write_or_clone() argument
5319 u64 bs = sctx->send_root->fs_info->sb->s_blocksize; in send_write_or_clone()
5336 if (offset >= sctx->cur_inode_size) { in send_write_or_clone()
5340 if (offset + len > sctx->cur_inode_size) in send_write_or_clone()
5341 len = sctx->cur_inode_size - offset; in send_write_or_clone()
5353 ret = clone_range(sctx, clone_root, disk_byte, data_offset, in send_write_or_clone()
5356 ret = send_extent_data(sctx, offset, len); in send_write_or_clone()
5358 sctx->cur_inode_next_write_offset = offset + len; in send_write_or_clone()
5363 static int is_extent_unchanged(struct send_ctx *sctx, in is_extent_unchanged() argument
5428 ret = btrfs_search_slot_for_read(sctx->parent_root, &key, path, 0, 0); in is_extent_unchanged()
5518 ret = btrfs_next_item(sctx->parent_root, path); in is_extent_unchanged()
5553 static int get_last_extent(struct send_ctx *sctx, u64 offset) in get_last_extent() argument
5556 struct btrfs_root *root = sctx->send_root; in get_last_extent()
5567 sctx->cur_inode_last_extent = 0; in get_last_extent()
5569 key.objectid = sctx->cur_ino; in get_last_extent()
5577 if (key.objectid != sctx->cur_ino || key.type != BTRFS_EXTENT_DATA_KEY) in get_last_extent()
5586 sctx->send_root->fs_info->sectorsize); in get_last_extent()
5591 sctx->cur_inode_last_extent = extent_end; in get_last_extent()
5597 static int range_is_hole_in_parent(struct send_ctx *sctx, in range_is_hole_in_parent() argument
5603 struct btrfs_root *root = sctx->parent_root; in range_is_hole_in_parent()
5611 key.objectid = sctx->cur_ino; in range_is_hole_in_parent()
5636 if (key.objectid < sctx->cur_ino || in range_is_hole_in_parent()
5639 if (key.objectid > sctx->cur_ino || in range_is_hole_in_parent()
5672 static int maybe_send_hole(struct send_ctx *sctx, struct btrfs_path *path, in maybe_send_hole() argument
5680 if (sctx->cur_ino != key->objectid || !need_send_hole(sctx)) in maybe_send_hole()
5683 if (sctx->cur_inode_last_extent == (u64)-1) { in maybe_send_hole()
5684 ret = get_last_extent(sctx, key->offset - 1); in maybe_send_hole()
5695 sctx->send_root->fs_info->sectorsize); in maybe_send_hole()
5702 sctx->cur_inode_last_extent < key->offset) { in maybe_send_hole()
5710 ret = get_last_extent(sctx, key->offset - 1); in maybe_send_hole()
5715 if (sctx->cur_inode_last_extent < key->offset) { in maybe_send_hole()
5716 ret = range_is_hole_in_parent(sctx, in maybe_send_hole()
5717 sctx->cur_inode_last_extent, in maybe_send_hole()
5722 ret = send_hole(sctx, key->offset); in maybe_send_hole()
5726 sctx->cur_inode_last_extent = extent_end; in maybe_send_hole()
5730 static int process_extent(struct send_ctx *sctx, in process_extent() argument
5737 if (S_ISLNK(sctx->cur_inode_mode)) in process_extent()
5740 if (sctx->parent_root && !sctx->cur_inode_new) { in process_extent()
5741 ret = is_extent_unchanged(sctx, path, key); in process_extent()
5776 ret = find_extent_clone(sctx, path, key->objectid, key->offset, in process_extent()
5777 sctx->cur_inode_size, &found_clone); in process_extent()
5781 ret = send_write_or_clone(sctx, path, key, found_clone); in process_extent()
5785 ret = maybe_send_hole(sctx, path, key); in process_extent()
5790 static int process_all_extents(struct send_ctx *sctx) in process_all_extents() argument
5800 root = sctx->send_root; in process_all_extents()
5805 key.objectid = sctx->cmp_key->objectid; in process_all_extents()
5835 ret = process_extent(sctx, path, &found_key); in process_all_extents()
5847 static int process_recorded_refs_if_needed(struct send_ctx *sctx, int at_end, in process_recorded_refs_if_needed() argument
5853 if (sctx->cur_ino == 0) in process_recorded_refs_if_needed()
5855 if (!at_end && sctx->cur_ino == sctx->cmp_key->objectid && in process_recorded_refs_if_needed()
5856 sctx->cmp_key->type <= BTRFS_INODE_EXTREF_KEY) in process_recorded_refs_if_needed()
5858 if (list_empty(&sctx->new_refs) && list_empty(&sctx->deleted_refs)) in process_recorded_refs_if_needed()
5861 ret = process_recorded_refs(sctx, pending_move); in process_recorded_refs_if_needed()
5870 static int finish_inode_if_needed(struct send_ctx *sctx, int at_end) in finish_inode_if_needed() argument
5885 if (sctx->ignore_cur_inode) in finish_inode_if_needed()
5888 ret = process_recorded_refs_if_needed(sctx, at_end, &pending_move, in finish_inode_if_needed()
5906 sctx->send_progress = sctx->cur_ino + 1; in finish_inode_if_needed()
5908 if (sctx->cur_ino == 0 || sctx->cur_inode_deleted) in finish_inode_if_needed()
5910 if (!at_end && sctx->cmp_key->objectid == sctx->cur_ino) in finish_inode_if_needed()
5913 ret = get_inode_info(sctx->send_root, sctx->cur_ino, NULL, NULL, in finish_inode_if_needed()
5918 if (!sctx->parent_root || sctx->cur_inode_new) { in finish_inode_if_needed()
5920 if (!S_ISLNK(sctx->cur_inode_mode)) in finish_inode_if_needed()
5922 if (sctx->cur_inode_next_write_offset == sctx->cur_inode_size) in finish_inode_if_needed()
5927 ret = get_inode_info(sctx->parent_root, sctx->cur_ino, in finish_inode_if_needed()
5935 if (!S_ISLNK(sctx->cur_inode_mode) && left_mode != right_mode) in finish_inode_if_needed()
5937 if ((old_size == sctx->cur_inode_size) || in finish_inode_if_needed()
5938 (sctx->cur_inode_size > old_size && in finish_inode_if_needed()
5939 sctx->cur_inode_next_write_offset == sctx->cur_inode_size)) in finish_inode_if_needed()
5943 if (S_ISREG(sctx->cur_inode_mode)) { in finish_inode_if_needed()
5944 if (need_send_hole(sctx)) { in finish_inode_if_needed()
5945 if (sctx->cur_inode_last_extent == (u64)-1 || in finish_inode_if_needed()
5946 sctx->cur_inode_last_extent < in finish_inode_if_needed()
5947 sctx->cur_inode_size) { in finish_inode_if_needed()
5948 ret = get_last_extent(sctx, (u64)-1); in finish_inode_if_needed()
5952 if (sctx->cur_inode_last_extent < in finish_inode_if_needed()
5953 sctx->cur_inode_size) { in finish_inode_if_needed()
5954 ret = send_hole(sctx, sctx->cur_inode_size); in finish_inode_if_needed()
5960 ret = send_truncate(sctx, sctx->cur_ino, in finish_inode_if_needed()
5961 sctx->cur_inode_gen, in finish_inode_if_needed()
5962 sctx->cur_inode_size); in finish_inode_if_needed()
5969 ret = send_chown(sctx, sctx->cur_ino, sctx->cur_inode_gen, in finish_inode_if_needed()
5975 ret = send_chmod(sctx, sctx->cur_ino, sctx->cur_inode_gen, in finish_inode_if_needed()
5985 if (!is_waiting_for_move(sctx, sctx->cur_ino)) { in finish_inode_if_needed()
5986 ret = apply_children_dir_moves(sctx); in finish_inode_if_needed()
5996 sctx->send_progress = sctx->cur_ino + 1; in finish_inode_if_needed()
5997 ret = send_utimes(sctx, sctx->cur_ino, sctx->cur_inode_gen); in finish_inode_if_needed()
6008 struct send_ctx *sctx; member
6016 return record_ref(ppctx->sctx->parent_root, dir, name, ppctx->sctx, in record_parent_ref()
6024 static int btrfs_unlink_all_paths(struct send_ctx *sctx) in btrfs_unlink_all_paths() argument
6036 key.objectid = sctx->cur_ino; in btrfs_unlink_all_paths()
6039 ret = btrfs_search_slot(NULL, sctx->parent_root, &key, path, 0, 0); in btrfs_unlink_all_paths()
6044 ctx.sctx = sctx; in btrfs_unlink_all_paths()
6051 ret = btrfs_next_leaf(sctx->parent_root, path); in btrfs_unlink_all_paths()
6060 if (key.objectid != sctx->cur_ino) in btrfs_unlink_all_paths()
6066 ret = iterate_inode_ref(sctx->parent_root, path, &key, 1, in btrfs_unlink_all_paths()
6078 ret = send_unlink(sctx, ref->full_path); in btrfs_unlink_all_paths()
6093 static int changed_inode(struct send_ctx *sctx, in changed_inode() argument
6097 struct btrfs_key *key = sctx->cmp_key; in changed_inode()
6103 sctx->cur_ino = key->objectid; in changed_inode()
6104 sctx->cur_inode_new_gen = 0; in changed_inode()
6105 sctx->cur_inode_last_extent = (u64)-1; in changed_inode()
6106 sctx->cur_inode_next_write_offset = 0; in changed_inode()
6107 sctx->ignore_cur_inode = false; in changed_inode()
6114 sctx->send_progress = sctx->cur_ino; in changed_inode()
6118 left_ii = btrfs_item_ptr(sctx->left_path->nodes[0], in changed_inode()
6119 sctx->left_path->slots[0], in changed_inode()
6121 left_gen = btrfs_inode_generation(sctx->left_path->nodes[0], in changed_inode()
6124 right_ii = btrfs_item_ptr(sctx->right_path->nodes[0], in changed_inode()
6125 sctx->right_path->slots[0], in changed_inode()
6127 right_gen = btrfs_inode_generation(sctx->right_path->nodes[0], in changed_inode()
6131 right_ii = btrfs_item_ptr(sctx->right_path->nodes[0], in changed_inode()
6132 sctx->right_path->slots[0], in changed_inode()
6135 right_gen = btrfs_inode_generation(sctx->right_path->nodes[0], in changed_inode()
6144 sctx->cur_ino != BTRFS_FIRST_FREE_OBJECTID) in changed_inode()
6145 sctx->cur_inode_new_gen = 1; in changed_inode()
6166 nlinks = btrfs_inode_nlink(sctx->left_path->nodes[0], left_ii); in changed_inode()
6168 sctx->ignore_cur_inode = true; in changed_inode()
6170 ret = btrfs_unlink_all_paths(sctx); in changed_inode()
6176 sctx->cur_inode_gen = left_gen; in changed_inode()
6177 sctx->cur_inode_new = 1; in changed_inode()
6178 sctx->cur_inode_deleted = 0; in changed_inode()
6179 sctx->cur_inode_size = btrfs_inode_size( in changed_inode()
6180 sctx->left_path->nodes[0], left_ii); in changed_inode()
6181 sctx->cur_inode_mode = btrfs_inode_mode( in changed_inode()
6182 sctx->left_path->nodes[0], left_ii); in changed_inode()
6183 sctx->cur_inode_rdev = btrfs_inode_rdev( in changed_inode()
6184 sctx->left_path->nodes[0], left_ii); in changed_inode()
6185 if (sctx->cur_ino != BTRFS_FIRST_FREE_OBJECTID) in changed_inode()
6186 ret = send_create_inode_if_needed(sctx); in changed_inode()
6188 sctx->cur_inode_gen = right_gen; in changed_inode()
6189 sctx->cur_inode_new = 0; in changed_inode()
6190 sctx->cur_inode_deleted = 1; in changed_inode()
6191 sctx->cur_inode_size = btrfs_inode_size( in changed_inode()
6192 sctx->right_path->nodes[0], right_ii); in changed_inode()
6193 sctx->cur_inode_mode = btrfs_inode_mode( in changed_inode()
6194 sctx->right_path->nodes[0], right_ii); in changed_inode()
6203 if (sctx->cur_inode_new_gen) { in changed_inode()
6207 sctx->cur_inode_gen = right_gen; in changed_inode()
6208 sctx->cur_inode_new = 0; in changed_inode()
6209 sctx->cur_inode_deleted = 1; in changed_inode()
6210 sctx->cur_inode_size = btrfs_inode_size( in changed_inode()
6211 sctx->right_path->nodes[0], right_ii); in changed_inode()
6212 sctx->cur_inode_mode = btrfs_inode_mode( in changed_inode()
6213 sctx->right_path->nodes[0], right_ii); in changed_inode()
6214 ret = process_all_refs(sctx, in changed_inode()
6222 sctx->cur_inode_gen = left_gen; in changed_inode()
6223 sctx->cur_inode_new = 1; in changed_inode()
6224 sctx->cur_inode_deleted = 0; in changed_inode()
6225 sctx->cur_inode_size = btrfs_inode_size( in changed_inode()
6226 sctx->left_path->nodes[0], left_ii); in changed_inode()
6227 sctx->cur_inode_mode = btrfs_inode_mode( in changed_inode()
6228 sctx->left_path->nodes[0], left_ii); in changed_inode()
6229 sctx->cur_inode_rdev = btrfs_inode_rdev( in changed_inode()
6230 sctx->left_path->nodes[0], left_ii); in changed_inode()
6231 ret = send_create_inode_if_needed(sctx); in changed_inode()
6235 ret = process_all_refs(sctx, BTRFS_COMPARE_TREE_NEW); in changed_inode()
6242 sctx->send_progress = sctx->cur_ino + 1; in changed_inode()
6248 ret = process_all_extents(sctx); in changed_inode()
6251 ret = process_all_new_xattrs(sctx); in changed_inode()
6255 sctx->cur_inode_gen = left_gen; in changed_inode()
6256 sctx->cur_inode_new = 0; in changed_inode()
6257 sctx->cur_inode_new_gen = 0; in changed_inode()
6258 sctx->cur_inode_deleted = 0; in changed_inode()
6259 sctx->cur_inode_size = btrfs_inode_size( in changed_inode()
6260 sctx->left_path->nodes[0], left_ii); in changed_inode()
6261 sctx->cur_inode_mode = btrfs_inode_mode( in changed_inode()
6262 sctx->left_path->nodes[0], left_ii); in changed_inode()
6280 static int changed_ref(struct send_ctx *sctx, in changed_ref() argument
6285 if (sctx->cur_ino != sctx->cmp_key->objectid) { in changed_ref()
6286 inconsistent_snapshot_error(sctx, result, "reference"); in changed_ref()
6290 if (!sctx->cur_inode_new_gen && in changed_ref()
6291 sctx->cur_ino != BTRFS_FIRST_FREE_OBJECTID) { in changed_ref()
6293 ret = record_new_ref(sctx); in changed_ref()
6295 ret = record_deleted_ref(sctx); in changed_ref()
6297 ret = record_changed_ref(sctx); in changed_ref()
6308 static int changed_xattr(struct send_ctx *sctx, in changed_xattr() argument
6313 if (sctx->cur_ino != sctx->cmp_key->objectid) { in changed_xattr()
6314 inconsistent_snapshot_error(sctx, result, "xattr"); in changed_xattr()
6318 if (!sctx->cur_inode_new_gen && !sctx->cur_inode_deleted) { in changed_xattr()
6320 ret = process_new_xattr(sctx); in changed_xattr()
6322 ret = process_deleted_xattr(sctx); in changed_xattr()
6324 ret = process_changed_xattr(sctx); in changed_xattr()
6335 static int changed_extent(struct send_ctx *sctx, in changed_extent() argument
6353 if (sctx->cur_ino != sctx->cmp_key->objectid) in changed_extent()
6356 if (!sctx->cur_inode_new_gen && !sctx->cur_inode_deleted) { in changed_extent()
6358 ret = process_extent(sctx, sctx->left_path, in changed_extent()
6359 sctx->cmp_key); in changed_extent()
6365 static int dir_changed(struct send_ctx *sctx, u64 dir) in dir_changed() argument
6370 ret = get_inode_info(sctx->send_root, dir, NULL, &new_gen, NULL, NULL, in dir_changed()
6375 ret = get_inode_info(sctx->parent_root, dir, NULL, &orig_gen, NULL, in dir_changed()
6383 static int compare_refs(struct send_ctx *sctx, struct btrfs_path *path, in compare_refs() argument
6399 ret = dir_changed(sctx, dirid); in compare_refs()
6414 ret = dir_changed(sctx, dirid); in compare_refs()
6434 struct send_ctx *sctx = ctx; in changed_cb() local
6439 ret = compare_refs(sctx, left_path, key); in changed_cb()
6445 return maybe_send_hole(sctx, left_path, key); in changed_cb()
6453 sctx->left_path = left_path; in changed_cb()
6454 sctx->right_path = right_path; in changed_cb()
6455 sctx->cmp_key = key; in changed_cb()
6457 ret = finish_inode_if_needed(sctx, 0); in changed_cb()
6467 ret = changed_inode(sctx, result); in changed_cb()
6468 } else if (!sctx->ignore_cur_inode) { in changed_cb()
6471 ret = changed_ref(sctx, result); in changed_cb()
6473 ret = changed_xattr(sctx, result); in changed_cb()
6475 ret = changed_extent(sctx, result); in changed_cb()
6482 static int full_send_tree(struct send_ctx *sctx) in full_send_tree() argument
6485 struct btrfs_root *send_root = sctx->send_root; in full_send_tree()
6511 BTRFS_COMPARE_TREE_NEW, sctx); in full_send_tree()
6525 ret = finish_inode_if_needed(sctx, 1); in full_send_tree()
6892 static int send_subvol(struct send_ctx *sctx) in send_subvol() argument
6896 if (!(sctx->flags & BTRFS_SEND_FLAG_OMIT_STREAM_HEADER)) { in send_subvol()
6897 ret = send_header(sctx); in send_subvol()
6902 ret = send_subvol_begin(sctx); in send_subvol()
6906 if (sctx->parent_root) { in send_subvol()
6907 ret = btrfs_compare_trees(sctx->send_root, sctx->parent_root, in send_subvol()
6908 changed_cb, sctx); in send_subvol()
6911 ret = finish_inode_if_needed(sctx, 1); in send_subvol()
6915 ret = full_send_tree(sctx); in send_subvol()
6921 free_recorded_refs(sctx); in send_subvol()
6938 static int ensure_commit_roots_uptodate(struct send_ctx *sctx) in ensure_commit_roots_uptodate() argument
6944 if (sctx->parent_root && in ensure_commit_roots_uptodate()
6945 sctx->parent_root->node != sctx->parent_root->commit_root) in ensure_commit_roots_uptodate()
6948 for (i = 0; i < sctx->clone_roots_cnt; i++) in ensure_commit_roots_uptodate()
6949 if (sctx->clone_roots[i].root->node != in ensure_commit_roots_uptodate()
6950 sctx->clone_roots[i].root->commit_root) in ensure_commit_roots_uptodate()
6961 trans = btrfs_join_transaction(sctx->send_root); in ensure_commit_roots_uptodate()
6978 static int flush_delalloc_roots(struct send_ctx *sctx) in flush_delalloc_roots() argument
6980 struct btrfs_root *root = sctx->parent_root; in flush_delalloc_roots()
6991 for (i = 0; i < sctx->clone_roots_cnt; i++) { in flush_delalloc_roots()
6992 root = sctx->clone_roots[i].root; in flush_delalloc_roots()
7031 struct send_ctx *sctx = NULL; in btrfs_ioctl_send() local
7093 sctx = kzalloc(sizeof(struct send_ctx), GFP_KERNEL); in btrfs_ioctl_send()
7094 if (!sctx) { in btrfs_ioctl_send()
7099 INIT_LIST_HEAD(&sctx->new_refs); in btrfs_ioctl_send()
7100 INIT_LIST_HEAD(&sctx->deleted_refs); in btrfs_ioctl_send()
7101 INIT_RADIX_TREE(&sctx->name_cache, GFP_KERNEL); in btrfs_ioctl_send()
7102 INIT_LIST_HEAD(&sctx->name_cache_list); in btrfs_ioctl_send()
7104 sctx->flags = arg->flags; in btrfs_ioctl_send()
7106 sctx->send_filp = fget(arg->send_fd); in btrfs_ioctl_send()
7107 if (!sctx->send_filp) { in btrfs_ioctl_send()
7112 sctx->send_root = send_root; in btrfs_ioctl_send()
7117 if (btrfs_root_dead(sctx->send_root)) { in btrfs_ioctl_send()
7122 sctx->clone_roots_cnt = arg->clone_sources_count; in btrfs_ioctl_send()
7124 sctx->send_max_size = BTRFS_SEND_BUF_SIZE; in btrfs_ioctl_send()
7125 sctx->send_buf = kvmalloc(sctx->send_max_size, GFP_KERNEL); in btrfs_ioctl_send()
7126 if (!sctx->send_buf) { in btrfs_ioctl_send()
7131 sctx->read_buf = kvmalloc(BTRFS_SEND_READ_SIZE, GFP_KERNEL); in btrfs_ioctl_send()
7132 if (!sctx->read_buf) { in btrfs_ioctl_send()
7137 sctx->pending_dir_moves = RB_ROOT; in btrfs_ioctl_send()
7138 sctx->waiting_dir_moves = RB_ROOT; in btrfs_ioctl_send()
7139 sctx->orphan_dirs = RB_ROOT; in btrfs_ioctl_send()
7143 sctx->clone_roots = kzalloc(alloc_size, GFP_KERNEL); in btrfs_ioctl_send()
7144 if (!sctx->clone_roots) { in btrfs_ioctl_send()
7197 sctx->clone_roots[i].root = clone_root; in btrfs_ioctl_send()
7211 sctx->parent_root = btrfs_read_fs_root_no_name(fs_info, &key); in btrfs_ioctl_send()
7212 if (IS_ERR(sctx->parent_root)) { in btrfs_ioctl_send()
7214 ret = PTR_ERR(sctx->parent_root); in btrfs_ioctl_send()
7218 spin_lock(&sctx->parent_root->root_item_lock); in btrfs_ioctl_send()
7219 sctx->parent_root->send_in_progress++; in btrfs_ioctl_send()
7220 if (!btrfs_root_readonly(sctx->parent_root) || in btrfs_ioctl_send()
7221 btrfs_root_dead(sctx->parent_root)) { in btrfs_ioctl_send()
7222 spin_unlock(&sctx->parent_root->root_item_lock); in btrfs_ioctl_send()
7227 if (sctx->parent_root->dedupe_in_progress) { in btrfs_ioctl_send()
7228 dedupe_in_progress_warn(sctx->parent_root); in btrfs_ioctl_send()
7229 spin_unlock(&sctx->parent_root->root_item_lock); in btrfs_ioctl_send()
7234 spin_unlock(&sctx->parent_root->root_item_lock); in btrfs_ioctl_send()
7244 sctx->clone_roots[sctx->clone_roots_cnt++].root = sctx->send_root; in btrfs_ioctl_send()
7247 sort(sctx->clone_roots, sctx->clone_roots_cnt, in btrfs_ioctl_send()
7248 sizeof(*sctx->clone_roots), __clone_root_cmp_sort, in btrfs_ioctl_send()
7252 ret = flush_delalloc_roots(sctx); in btrfs_ioctl_send()
7256 ret = ensure_commit_roots_uptodate(sctx); in btrfs_ioctl_send()
7272 ret = send_subvol(sctx); in btrfs_ioctl_send()
7280 if (!(sctx->flags & BTRFS_SEND_FLAG_OMIT_END_CMD)) { in btrfs_ioctl_send()
7281 ret = begin_cmd(sctx, BTRFS_SEND_C_END); in btrfs_ioctl_send()
7284 ret = send_cmd(sctx); in btrfs_ioctl_send()
7290 WARN_ON(sctx && !ret && !RB_EMPTY_ROOT(&sctx->pending_dir_moves)); in btrfs_ioctl_send()
7291 while (sctx && !RB_EMPTY_ROOT(&sctx->pending_dir_moves)) { in btrfs_ioctl_send()
7295 n = rb_first(&sctx->pending_dir_moves); in btrfs_ioctl_send()
7302 free_pending_move(sctx, pm2); in btrfs_ioctl_send()
7304 free_pending_move(sctx, pm); in btrfs_ioctl_send()
7307 WARN_ON(sctx && !ret && !RB_EMPTY_ROOT(&sctx->waiting_dir_moves)); in btrfs_ioctl_send()
7308 while (sctx && !RB_EMPTY_ROOT(&sctx->waiting_dir_moves)) { in btrfs_ioctl_send()
7312 n = rb_first(&sctx->waiting_dir_moves); in btrfs_ioctl_send()
7314 rb_erase(&dm->node, &sctx->waiting_dir_moves); in btrfs_ioctl_send()
7318 WARN_ON(sctx && !ret && !RB_EMPTY_ROOT(&sctx->orphan_dirs)); in btrfs_ioctl_send()
7319 while (sctx && !RB_EMPTY_ROOT(&sctx->orphan_dirs)) { in btrfs_ioctl_send()
7323 n = rb_first(&sctx->orphan_dirs); in btrfs_ioctl_send()
7325 free_orphan_dir_info(sctx, odi); in btrfs_ioctl_send()
7329 for (i = 0; i < sctx->clone_roots_cnt; i++) in btrfs_ioctl_send()
7331 sctx->clone_roots[i].root); in btrfs_ioctl_send()
7333 for (i = 0; sctx && i < clone_sources_to_rollback; i++) in btrfs_ioctl_send()
7335 sctx->clone_roots[i].root); in btrfs_ioctl_send()
7339 if (sctx && !IS_ERR_OR_NULL(sctx->parent_root)) in btrfs_ioctl_send()
7340 btrfs_root_dec_send_in_progress(sctx->parent_root); in btrfs_ioctl_send()
7344 if (sctx) { in btrfs_ioctl_send()
7345 if (sctx->send_filp) in btrfs_ioctl_send()
7346 fput(sctx->send_filp); in btrfs_ioctl_send()
7348 kvfree(sctx->clone_roots); in btrfs_ioctl_send()
7349 kvfree(sctx->send_buf); in btrfs_ioctl_send()
7350 kvfree(sctx->read_buf); in btrfs_ioctl_send()
7352 name_cache_free(sctx); in btrfs_ioctl_send()
7354 kfree(sctx); in btrfs_ioctl_send()