Lines Matching full:wc
153 struct walk_control *wc, u64 gen, int level);
171 static void do_abort_log_replay(struct walk_control *wc, const char *function, in do_abort_log_replay() argument
174 struct btrfs_fs_info *fs_info = wc->trans->fs_info; in do_abort_log_replay()
190 btrfs_abort_transaction(wc->trans, error); in do_abort_log_replay()
192 if (wc->subvol_path->nodes[0]) { in do_abort_log_replay()
195 btrfs_root_id(wc->root)); in do_abort_log_replay()
196 btrfs_print_leaf(wc->subvol_path->nodes[0]); in do_abort_log_replay()
199 if (wc->log_leaf) { in do_abort_log_replay()
202 btrfs_root_id(wc->root), wc->log_slot, in do_abort_log_replay()
203 wc->log_key.objectid, wc->log_key.type, wc->log_key.offset); in do_abort_log_replay()
204 btrfs_print_leaf(wc->log_leaf); in do_abort_log_replay()
213 function, line, btrfs_root_id(wc->root), wc->stage, error, &vaf); in do_abort_log_replay()
224 #define btrfs_abort_log_replay(wc, error, fmt, args...) \ argument
225 do_abort_log_replay((wc), __func__, __LINE__, (error), fmt, ##args)
231 static int link_to_fixup_dir(struct walk_control *wc, u64 objectid);
232 static noinline int replay_dir_deletes(struct walk_control *wc,
424 struct walk_control *wc, u64 gen, int level) in process_one_buffer() argument
426 struct btrfs_root *log = wc->log; in process_one_buffer()
427 struct btrfs_trans_handle *trans = wc->trans; in process_one_buffer()
451 if (wc->pin) { in process_one_buffer()
483 static int overwrite_item(struct walk_control *wc) in overwrite_item() argument
485 struct btrfs_trans_handle *trans = wc->trans; in overwrite_item()
486 struct btrfs_root *root = wc->root; in overwrite_item()
495 const bool is_inode_item = (wc->log_key.type == BTRFS_INODE_ITEM_KEY); in overwrite_item()
506 item_size = btrfs_item_size(wc->log_leaf, wc->log_slot); in overwrite_item()
507 src_ptr = btrfs_item_ptr_offset(wc->log_leaf, wc->log_slot); in overwrite_item()
510 ret = btrfs_search_slot(NULL, root, &wc->log_key, wc->subvol_path, 0, 0); in overwrite_item()
512 btrfs_abort_log_replay(wc, ret, in overwrite_item()
514 wc->log_key.objectid, wc->log_key.type, in overwrite_item()
515 wc->log_key.offset, btrfs_root_id(root)); in overwrite_item()
519 dst_eb = wc->subvol_path->nodes[0]; in overwrite_item()
520 dst_slot = wc->subvol_path->slots[0]; in overwrite_item()
530 btrfs_release_path(wc->subvol_path); in overwrite_item()
535 btrfs_abort_log_replay(wc, -ENOMEM, in overwrite_item()
540 read_extent_buffer(wc->log_leaf, src_copy, src_ptr, item_size); in overwrite_item()
552 btrfs_release_path(wc->subvol_path); in overwrite_item()
568 item = btrfs_item_ptr(wc->log_leaf, wc->log_slot, in overwrite_item()
570 btrfs_set_inode_nbytes(wc->log_leaf, item, nbytes); in overwrite_item()
577 mode = btrfs_inode_mode(wc->log_leaf, item); in overwrite_item()
579 btrfs_set_inode_size(wc->log_leaf, item, 0); in overwrite_item()
589 item = btrfs_item_ptr(wc->log_leaf, wc->log_slot, struct btrfs_inode_item); in overwrite_item()
590 btrfs_set_inode_nbytes(wc->log_leaf, item, 0); in overwrite_item()
597 mode = btrfs_inode_mode(wc->log_leaf, item); in overwrite_item()
599 btrfs_set_inode_size(wc->log_leaf, item, 0); in overwrite_item()
602 btrfs_release_path(wc->subvol_path); in overwrite_item()
604 wc->subvol_path->skip_release_on_error = 1; in overwrite_item()
605 ret = btrfs_insert_empty_item(trans, root, wc->subvol_path, &wc->log_key, item_size); in overwrite_item()
606 wc->subvol_path->skip_release_on_error = 0; in overwrite_item()
608 dst_eb = wc->subvol_path->nodes[0]; in overwrite_item()
609 dst_slot = wc->subvol_path->slots[0]; in overwrite_item()
616 btrfs_truncate_item(trans, wc->subvol_path, item_size, 1); in overwrite_item()
618 btrfs_extend_item(trans, wc->subvol_path, item_size - found_size); in overwrite_item()
620 btrfs_abort_log_replay(wc, ret, in overwrite_item()
622 wc->log_key.objectid, wc->log_key.type, in overwrite_item()
623 wc->log_key.offset); in overwrite_item()
644 if (btrfs_inode_generation(wc->log_leaf, src_item) == 0) { in overwrite_item()
645 const u64 ino_size = btrfs_inode_size(wc->log_leaf, src_item); in overwrite_item()
654 if (S_ISREG(btrfs_inode_mode(wc->log_leaf, src_item)) && in overwrite_item()
661 if (S_ISDIR(btrfs_inode_mode(wc->log_leaf, src_item)) && in overwrite_item()
668 copy_extent_buffer(dst_eb, wc->log_leaf, dst_ptr, src_ptr, item_size); in overwrite_item()
686 btrfs_release_path(wc->subvol_path); in overwrite_item()
717 static noinline int replay_one_extent(struct walk_control *wc) in replay_one_extent() argument
719 struct btrfs_trans_handle *trans = wc->trans; in replay_one_extent()
720 struct btrfs_root *root = wc->root; in replay_one_extent()
725 const u64 start = wc->log_key.offset; in replay_one_extent()
737 item = btrfs_item_ptr(wc->log_leaf, wc->log_slot, struct btrfs_file_extent_item); in replay_one_extent()
738 found_type = btrfs_file_extent_type(wc->log_leaf, item); in replay_one_extent()
742 extent_end = start + btrfs_file_extent_num_bytes(wc->log_leaf, item); in replay_one_extent()
744 if (btrfs_file_extent_disk_bytenr(wc->log_leaf, item) != 0) in replay_one_extent()
745 nbytes = btrfs_file_extent_num_bytes(wc->log_leaf, item); in replay_one_extent()
747 nbytes = btrfs_file_extent_ram_bytes(wc->log_leaf, item); in replay_one_extent()
750 btrfs_abort_log_replay(wc, -EUCLEAN, in replay_one_extent()
753 wc->log_key.objectid, wc->log_key.offset); in replay_one_extent()
757 inode = btrfs_iget_logging(wc->log_key.objectid, root); in replay_one_extent()
760 btrfs_abort_log_replay(wc, ret, in replay_one_extent()
762 wc->log_key.objectid, btrfs_root_id(root)); in replay_one_extent()
771 ret = btrfs_lookup_file_extent(trans, root, wc->subvol_path, in replay_one_extent()
777 struct extent_buffer *leaf = wc->subvol_path->nodes[0]; in replay_one_extent()
781 ptr = btrfs_item_ptr_offset(leaf, wc->subvol_path->slots[0]); in replay_one_extent()
788 if (memcmp_extent_buffer(wc->log_leaf, &existing, (unsigned long)item, in replay_one_extent()
790 btrfs_release_path(wc->subvol_path); in replay_one_extent()
794 btrfs_release_path(wc->subvol_path); in replay_one_extent()
800 drop_args.path = wc->subvol_path; in replay_one_extent()
803 btrfs_abort_log_replay(wc, ret, in replay_one_extent()
805 wc->log_key.objectid, start, extent_end, in replay_one_extent()
812 ret = overwrite_item(wc); in replay_one_extent()
824 if (btrfs_file_extent_disk_bytenr(wc->log_leaf, item) == 0 && in replay_one_extent()
828 ret = btrfs_insert_empty_item(trans, root, wc->subvol_path, in replay_one_extent()
829 &wc->log_key, sizeof(*item)); in replay_one_extent()
831 btrfs_abort_log_replay(wc, ret, in replay_one_extent()
833 wc->log_key.objectid, wc->log_key.type, in replay_one_extent()
834 wc->log_key.offset, btrfs_root_id(root)); in replay_one_extent()
837 dest_offset = btrfs_item_ptr_offset(wc->subvol_path->nodes[0], in replay_one_extent()
838 wc->subvol_path->slots[0]); in replay_one_extent()
839 copy_extent_buffer(wc->subvol_path->nodes[0], wc->log_leaf, dest_offset, in replay_one_extent()
848 if (btrfs_file_extent_disk_bytenr(wc->log_leaf, item) == 0) { in replay_one_extent()
849 btrfs_release_path(wc->subvol_path); in replay_one_extent()
853 ins.objectid = btrfs_file_extent_disk_bytenr(wc->log_leaf, item); in replay_one_extent()
855 ins.offset = btrfs_file_extent_disk_num_bytes(wc->log_leaf, item); in replay_one_extent()
856 offset = wc->log_key.offset - btrfs_file_extent_offset(wc->log_leaf, item); in replay_one_extent()
867 btrfs_abort_log_replay(wc, ret, in replay_one_extent()
870 wc->log_key.objectid, btrfs_root_id(root)); in replay_one_extent()
880 btrfs_abort_log_replay(wc, ret, in replay_one_extent()
883 wc->log_key.objectid, btrfs_root_id(root)); in replay_one_extent()
894 btrfs_init_data_ref(&ref, wc->log_key.objectid, offset, 0, false); in replay_one_extent()
897 btrfs_abort_log_replay(wc, ret, in replay_one_extent()
900 wc->log_key.objectid, in replay_one_extent()
907 wc->log_key.objectid, offset, &ins); in replay_one_extent()
909 btrfs_abort_log_replay(wc, ret, in replay_one_extent()
912 wc->log_key.objectid, btrfs_root_id(root)); in replay_one_extent()
917 btrfs_release_path(wc->subvol_path); in replay_one_extent()
919 if (btrfs_file_extent_compression(wc->log_leaf, item)) { in replay_one_extent()
923 csum_start = ins.objectid + btrfs_file_extent_offset(wc->log_leaf, item); in replay_one_extent()
924 csum_end = csum_start + btrfs_file_extent_num_bytes(wc->log_leaf, item); in replay_one_extent()
930 btrfs_abort_log_replay(wc, ret, in replay_one_extent()
932 csum_start, csum_end, wc->log_key.objectid, in replay_one_extent()
991 btrfs_abort_log_replay(wc, ret, in replay_one_extent()
995 wc->log_key.objectid, in replay_one_extent()
1001 btrfs_abort_log_replay(wc, ret, in replay_one_extent()
1005 wc->log_key.objectid, in replay_one_extent()
1017 btrfs_abort_log_replay(wc, ret, in replay_one_extent()
1019 start, extent_end, wc->log_key.objectid, in replay_one_extent()
1027 btrfs_abort_log_replay(wc, ret, in replay_one_extent()
1029 wc->log_key.objectid, btrfs_root_id(root)); in replay_one_extent()
1035 static int unlink_inode_for_log_replay(struct walk_control *wc, in unlink_inode_for_log_replay() argument
1040 struct btrfs_trans_handle *trans = wc->trans; in unlink_inode_for_log_replay()
1045 btrfs_abort_log_replay(wc, ret, in unlink_inode_for_log_replay()
1059 btrfs_abort_log_replay(wc, ret, in unlink_inode_for_log_replay()
1075 static noinline int drop_one_dir_item(struct walk_control *wc, in drop_one_dir_item() argument
1082 struct extent_buffer *leaf = wc->subvol_path->nodes[0]; in drop_one_dir_item()
1089 btrfs_abort_log_replay(wc, ret, in drop_one_dir_item()
1095 btrfs_release_path(wc->subvol_path); in drop_one_dir_item()
1100 btrfs_abort_log_replay(wc, ret, in drop_one_dir_item()
1108 ret = link_to_fixup_dir(wc, location.objectid); in drop_one_dir_item()
1112 ret = unlink_inode_for_log_replay(wc, dir, inode, &name); in drop_one_dir_item()
1202 static int unlink_refs_not_in_log(struct walk_control *wc, in unlink_refs_not_in_log() argument
1207 struct extent_buffer *leaf = wc->subvol_path->nodes[0]; in unlink_refs_not_in_log()
1216 ptr = btrfs_item_ptr_offset(leaf, wc->subvol_path->slots[0]); in unlink_refs_not_in_log()
1217 ptr_end = ptr + btrfs_item_size(leaf, wc->subvol_path->slots[0]); in unlink_refs_not_in_log()
1228 btrfs_abort_log_replay(wc, ret, in unlink_refs_not_in_log()
1235 ret = backref_in_log(wc->log, search_key, btrfs_ino(dir), &victim_name); in unlink_refs_not_in_log()
1238 btrfs_abort_log_replay(wc, ret, in unlink_refs_not_in_log()
1252 btrfs_release_path(wc->subvol_path); in unlink_refs_not_in_log()
1254 ret = unlink_inode_for_log_replay(wc, dir, inode, &victim_name); in unlink_refs_not_in_log()
1264 static int unlink_extrefs_not_in_log(struct walk_control *wc, in unlink_extrefs_not_in_log() argument
1269 struct extent_buffer *leaf = wc->subvol_path->nodes[0]; in unlink_extrefs_not_in_log()
1270 const unsigned long base = btrfs_item_ptr_offset(leaf, wc->subvol_path->slots[0]); in unlink_extrefs_not_in_log()
1271 const u32 item_size = btrfs_item_size(leaf, wc->subvol_path->slots[0]); in unlink_extrefs_not_in_log()
1275 struct btrfs_root *log_root = wc->log; in unlink_extrefs_not_in_log()
1289 btrfs_abort_log_replay(wc, ret, in unlink_extrefs_not_in_log()
1304 btrfs_abort_log_replay(wc, ret, in unlink_extrefs_not_in_log()
1319 btrfs_release_path(wc->subvol_path); in unlink_extrefs_not_in_log()
1321 ret = unlink_inode_for_log_replay(wc, dir, inode, &victim_name); in unlink_extrefs_not_in_log()
1331 static inline int __add_inode_ref(struct walk_control *wc, in __add_inode_ref() argument
1337 struct btrfs_trans_handle *trans = wc->trans; in __add_inode_ref()
1338 struct btrfs_root *root = wc->root; in __add_inode_ref()
1348 ret = btrfs_search_slot(NULL, root, &search_key, wc->subvol_path, 0, 0); in __add_inode_ref()
1350 btrfs_abort_log_replay(wc, ret, in __add_inode_ref()
1363 ret = unlink_refs_not_in_log(wc, &search_key, dir, inode); in __add_inode_ref()
1369 btrfs_release_path(wc->subvol_path); in __add_inode_ref()
1372 extref = btrfs_lookup_inode_extref(root, wc->subvol_path, name, in __add_inode_ref()
1377 ret = unlink_extrefs_not_in_log(wc, &search_key, dir, inode); in __add_inode_ref()
1383 btrfs_release_path(wc->subvol_path); in __add_inode_ref()
1386 di = btrfs_lookup_dir_index_item(trans, root, wc->subvol_path, btrfs_ino(dir), in __add_inode_ref()
1390 btrfs_abort_log_replay(wc, ret, in __add_inode_ref()
1396 ret = drop_one_dir_item(wc, dir, di); in __add_inode_ref()
1400 btrfs_release_path(wc->subvol_path); in __add_inode_ref()
1403 di = btrfs_lookup_dir_item(trans, root, wc->subvol_path, btrfs_ino(dir), name, 0); in __add_inode_ref()
1406 btrfs_abort_log_replay(wc, ret, in __add_inode_ref()
1412 ret = drop_one_dir_item(wc, dir, di); in __add_inode_ref()
1416 btrfs_release_path(wc->subvol_path); in __add_inode_ref()
1469 static int unlink_old_inode_refs(struct walk_control *wc, struct btrfs_inode *inode) in unlink_old_inode_refs() argument
1471 struct btrfs_root *root = wc->root; in unlink_old_inode_refs()
1478 btrfs_release_path(wc->subvol_path); in unlink_old_inode_refs()
1479 ret = btrfs_search_slot(NULL, root, &wc->log_key, wc->subvol_path, 0, 0); in unlink_old_inode_refs()
1485 btrfs_abort_log_replay(wc, ret, in unlink_old_inode_refs()
1487 wc->log_key.objectid, wc->log_key.type, in unlink_old_inode_refs()
1488 wc->log_key.offset, btrfs_root_id(root)); in unlink_old_inode_refs()
1492 eb = wc->subvol_path->nodes[0]; in unlink_old_inode_refs()
1493 ref_ptr = btrfs_item_ptr_offset(eb, wc->subvol_path->slots[0]); in unlink_old_inode_refs()
1494 ref_end = ref_ptr + btrfs_item_size(eb, wc->subvol_path->slots[0]); in unlink_old_inode_refs()
1499 if (wc->log_key.type == BTRFS_INODE_EXTREF_KEY) { in unlink_old_inode_refs()
1503 btrfs_abort_log_replay(wc, ret, in unlink_old_inode_refs()
1510 parent_id = wc->log_key.offset; in unlink_old_inode_refs()
1513 btrfs_abort_log_replay(wc, ret, in unlink_old_inode_refs()
1521 if (wc->log_key.type == BTRFS_INODE_EXTREF_KEY) in unlink_old_inode_refs()
1522 ret = !!btrfs_find_name_in_ext_backref(wc->log_leaf, wc->log_slot, in unlink_old_inode_refs()
1525 ret = !!btrfs_find_name_in_backref(wc->log_leaf, wc->log_slot, in unlink_old_inode_refs()
1531 btrfs_release_path(wc->subvol_path); in unlink_old_inode_refs()
1536 btrfs_abort_log_replay(wc, ret, in unlink_old_inode_refs()
1541 ret = unlink_inode_for_log_replay(wc, dir, inode, &name); in unlink_old_inode_refs()
1551 if (wc->log_key.type == BTRFS_INODE_EXTREF_KEY) in unlink_old_inode_refs()
1558 btrfs_release_path(wc->subvol_path); in unlink_old_inode_refs()
1566 static noinline int add_inode_ref(struct walk_control *wc) in add_inode_ref() argument
1568 struct btrfs_trans_handle *trans = wc->trans; in add_inode_ref()
1569 struct btrfs_root *root = wc->root; in add_inode_ref()
1576 const bool is_extref_item = (wc->log_key.type == BTRFS_INODE_EXTREF_KEY); in add_inode_ref()
1582 ref_ptr = btrfs_item_ptr_offset(wc->log_leaf, wc->log_slot); in add_inode_ref()
1583 ref_end = ref_ptr + btrfs_item_size(wc->log_leaf, wc->log_slot); in add_inode_ref()
1590 parent_objectid = btrfs_inode_extref_parent(wc->log_leaf, r); in add_inode_ref()
1593 parent_objectid = wc->log_key.offset; in add_inode_ref()
1595 inode_objectid = wc->log_key.objectid; in add_inode_ref()
1609 btrfs_abort_log_replay(wc, ret, in add_inode_ref()
1619 btrfs_abort_log_replay(wc, ret, in add_inode_ref()
1628 ret = extref_get_fields(wc->log_leaf, ref_ptr, &name, in add_inode_ref()
1631 btrfs_abort_log_replay(wc, ret, in add_inode_ref()
1662 btrfs_abort_log_replay(wc, ret, in add_inode_ref()
1671 ret = ref_get_fields(wc->log_leaf, ref_ptr, &name, &ref_index); in add_inode_ref()
1673 btrfs_abort_log_replay(wc, ret, in add_inode_ref()
1682 ret = inode_in_dir(root, wc->subvol_path, btrfs_ino(dir), in add_inode_ref()
1685 btrfs_abort_log_replay(wc, ret, in add_inode_ref()
1699 ret = __add_inode_ref(wc, dir, inode, ref_index, &name); in add_inode_ref()
1709 btrfs_abort_log_replay(wc, ret, in add_inode_ref()
1720 btrfs_abort_log_replay(wc, ret, in add_inode_ref()
1747 ret = unlink_old_inode_refs(wc, inode); in add_inode_ref()
1752 ret = overwrite_item(wc); in add_inode_ref()
1754 btrfs_release_path(wc->subvol_path); in add_inode_ref()
1872 static noinline int fixup_inode_link_count(struct walk_control *wc, in fixup_inode_link_count() argument
1875 struct btrfs_trans_handle *trans = wc->trans; in fixup_inode_link_count()
1881 ret = count_inode_refs(inode, wc->subvol_path); in fixup_inode_link_count()
1887 ret = count_inode_extrefs(inode, wc->subvol_path); in fixup_inode_link_count()
1906 ret = replay_dir_deletes(wc, ino, true); in fixup_inode_link_count()
1916 btrfs_release_path(wc->subvol_path); in fixup_inode_link_count()
1920 static noinline int fixup_inode_link_counts(struct walk_control *wc) in fixup_inode_link_counts() argument
1929 struct btrfs_trans_handle *trans = wc->trans; in fixup_inode_link_counts()
1930 struct btrfs_root *root = wc->root; in fixup_inode_link_counts()
1933 ret = btrfs_search_slot(trans, root, &key, wc->subvol_path, -1, 1); in fixup_inode_link_counts()
1939 if (wc->subvol_path->slots[0] == 0) in fixup_inode_link_counts()
1941 wc->subvol_path->slots[0]--; in fixup_inode_link_counts()
1944 btrfs_item_key_to_cpu(wc->subvol_path->nodes[0], &key, wc->subvol_path->slots[0]); in fixup_inode_link_counts()
1949 ret = btrfs_del_item(trans, root, wc->subvol_path); in fixup_inode_link_counts()
1953 btrfs_release_path(wc->subvol_path); in fixup_inode_link_counts()
1960 ret = fixup_inode_link_count(wc, inode); in fixup_inode_link_counts()
1972 btrfs_release_path(wc->subvol_path); in fixup_inode_link_counts()
1982 static noinline int link_to_fixup_dir(struct walk_control *wc, u64 objectid) in link_to_fixup_dir() argument
1984 struct btrfs_trans_handle *trans = wc->trans; in link_to_fixup_dir()
1985 struct btrfs_root *root = wc->root; in link_to_fixup_dir()
1994 btrfs_abort_log_replay(wc, ret, in link_to_fixup_dir()
2005 ret = btrfs_insert_empty_item(trans, root, wc->subvol_path, &key, 0); in link_to_fixup_dir()
2007 btrfs_release_path(wc->subvol_path); in link_to_fixup_dir()
2015 btrfs_abort_log_replay(wc, ret, in link_to_fixup_dir()
2021 btrfs_abort_log_replay(wc, ret, in link_to_fixup_dir()
2064 static int delete_conflicting_dir_entry(struct walk_control *wc, in delete_conflicting_dir_entry() argument
2073 btrfs_dir_item_key_to_cpu(wc->subvol_path->nodes[0], dst_di, &found_key); in delete_conflicting_dir_entry()
2078 btrfs_dir_flags(wc->subvol_path->nodes[0], dst_di) == log_flags) in delete_conflicting_dir_entry()
2088 return drop_one_dir_item(wc, dir, dst_di); in delete_conflicting_dir_entry()
2107 static noinline int replay_one_name(struct walk_control *wc, struct btrfs_dir_item *di) in replay_one_name() argument
2109 struct btrfs_trans_handle *trans = wc->trans; in replay_one_name()
2110 struct btrfs_root *root = wc->root; in replay_one_name()
2125 dir = btrfs_iget_logging(wc->log_key.objectid, root); in replay_one_name()
2128 btrfs_abort_log_replay(wc, ret, in replay_one_name()
2130 wc->log_key.objectid, btrfs_root_id(root)); in replay_one_name()
2134 ret = read_alloc_one_name(wc->log_leaf, di + 1, in replay_one_name()
2135 btrfs_dir_name_len(wc->log_leaf, di), &name); in replay_one_name()
2137 btrfs_abort_log_replay(wc, ret, in replay_one_name()
2143 log_flags = btrfs_dir_flags(wc->log_leaf, di); in replay_one_name()
2144 btrfs_dir_item_key_to_cpu(wc->log_leaf, di, &log_key); in replay_one_name()
2145 ret = btrfs_lookup_inode(trans, root, wc->subvol_path, &log_key, 0); in replay_one_name()
2146 btrfs_release_path(wc->subvol_path); in replay_one_name()
2148 btrfs_abort_log_replay(wc, ret, in replay_one_name()
2156 dir_dst_di = btrfs_lookup_dir_item(trans, root, wc->subvol_path, in replay_one_name()
2157 wc->log_key.objectid, &name, 1); in replay_one_name()
2160 btrfs_abort_log_replay(wc, ret, in replay_one_name()
2162 wc->log_key.objectid, name.len, name.name, in replay_one_name()
2166 ret = delete_conflicting_dir_entry(wc, dir, dir_dst_di, in replay_one_name()
2169 btrfs_abort_log_replay(wc, ret, in replay_one_name()
2178 btrfs_release_path(wc->subvol_path); in replay_one_name()
2180 index_dst_di = btrfs_lookup_dir_index_item(trans, root, wc->subvol_path, in replay_one_name()
2181 wc->log_key.objectid, in replay_one_name()
2182 wc->log_key.offset, &name, 1); in replay_one_name()
2185 btrfs_abort_log_replay(wc, ret, in replay_one_name()
2187 wc->log_key.objectid, name.len, name.name, in replay_one_name()
2191 ret = delete_conflicting_dir_entry(wc, dir, index_dst_di, in replay_one_name()
2194 btrfs_abort_log_replay(wc, ret, in replay_one_name()
2203 btrfs_release_path(wc->subvol_path); in replay_one_name()
2217 search_key.offset = wc->log_key.objectid; in replay_one_name()
2220 btrfs_abort_log_replay(wc, ret, in replay_one_name()
2234 search_key.offset = btrfs_extref_hash(wc->log_key.objectid, name.name, name.len); in replay_one_name()
2235 ret = backref_in_log(root->log_root, &search_key, wc->log_key.objectid, &name); in replay_one_name()
2237 btrfs_abort_log_replay(wc, ret, in replay_one_name()
2248 ret = insert_one_name(trans, root, wc->log_key.objectid, wc->log_key.offset, in replay_one_name()
2251 btrfs_abort_log_replay(wc, ret, in replay_one_name()
2267 btrfs_abort_log_replay(wc, ret, in replay_one_name()
2279 static noinline int replay_one_dir_item(struct walk_control *wc) in replay_one_dir_item() argument
2285 ASSERT(wc->log_key.type == BTRFS_DIR_INDEX_KEY); in replay_one_dir_item()
2287 di = btrfs_item_ptr(wc->log_leaf, wc->log_slot, struct btrfs_dir_item); in replay_one_dir_item()
2288 ret = replay_one_name(wc, di); in replay_one_dir_item()
2318 if (ret == 1 && btrfs_dir_ftype(wc->log_leaf, di) != BTRFS_FT_DIR) { in replay_one_dir_item()
2321 btrfs_dir_item_key_to_cpu(wc->log_leaf, di, &di_key); in replay_one_dir_item()
2322 ret = link_to_fixup_dir(wc, di_key.objectid); in replay_one_dir_item()
2415 static noinline int check_item_in_log(struct walk_control *wc, in check_item_in_log() argument
2421 struct btrfs_trans_handle *trans = wc->trans; in check_item_in_log()
2439 eb = wc->subvol_path->nodes[0]; in check_item_in_log()
2440 slot = wc->subvol_path->slots[0]; in check_item_in_log()
2444 btrfs_abort_log_replay(wc, ret, in check_item_in_log()
2454 log_di = btrfs_lookup_dir_index_item(trans, wc->log, log_path, in check_item_in_log()
2459 btrfs_abort_log_replay(wc, ret, in check_item_in_log()
2473 btrfs_release_path(wc->subvol_path); in check_item_in_log()
2479 btrfs_abort_log_replay(wc, ret, in check_item_in_log()
2485 ret = link_to_fixup_dir(wc, location.objectid); in check_item_in_log()
2490 ret = unlink_inode_for_log_replay(wc, dir, inode, &name); in check_item_in_log()
2497 btrfs_release_path(wc->subvol_path); in check_item_in_log()
2505 static int replay_xattr_deletes(struct walk_control *wc) in replay_xattr_deletes() argument
2507 struct btrfs_trans_handle *trans = wc->trans; in replay_xattr_deletes()
2508 struct btrfs_root *root = wc->root; in replay_xattr_deletes()
2509 struct btrfs_root *log = wc->log; in replay_xattr_deletes()
2512 const u64 ino = wc->log_key.objectid; in replay_xattr_deletes()
2518 btrfs_abort_log_replay(wc, -ENOMEM, "failed to allocate path"); in replay_xattr_deletes()
2526 ret = btrfs_search_slot(NULL, root, &search_key, wc->subvol_path, 0, 0); in replay_xattr_deletes()
2528 btrfs_abort_log_replay(wc, ret, in replay_xattr_deletes()
2534 nritems = btrfs_header_nritems(wc->subvol_path->nodes[0]); in replay_xattr_deletes()
2535 for (int i = wc->subvol_path->slots[0]; i < nritems; i++) { in replay_xattr_deletes()
2542 btrfs_item_key_to_cpu(wc->subvol_path->nodes[0], &key, i); in replay_xattr_deletes()
2548 di = btrfs_item_ptr(wc->subvol_path->nodes[0], i, struct btrfs_dir_item); in replay_xattr_deletes()
2549 total_size = btrfs_item_size(wc->subvol_path->nodes[0], i); in replay_xattr_deletes()
2552 u16 name_len = btrfs_dir_name_len(wc->subvol_path->nodes[0], di); in replay_xattr_deletes()
2553 u16 data_len = btrfs_dir_data_len(wc->subvol_path->nodes[0], di); in replay_xattr_deletes()
2560 btrfs_abort_log_replay(wc, ret, in replay_xattr_deletes()
2565 read_extent_buffer(wc->subvol_path->nodes[0], name, in replay_xattr_deletes()
2573 btrfs_release_path(wc->subvol_path); in replay_xattr_deletes()
2574 di = btrfs_lookup_xattr(trans, root, wc->subvol_path, ino, in replay_xattr_deletes()
2578 btrfs_abort_log_replay(wc, ret, in replay_xattr_deletes()
2587 wc->subvol_path, di); in replay_xattr_deletes()
2589 btrfs_abort_log_replay(wc, ret, in replay_xattr_deletes()
2596 btrfs_release_path(wc->subvol_path); in replay_xattr_deletes()
2603 btrfs_abort_log_replay(wc, ret, in replay_xattr_deletes()
2615 ret = btrfs_next_leaf(root, wc->subvol_path); in replay_xattr_deletes()
2621 btrfs_abort_log_replay(wc, ret, in replay_xattr_deletes()
2625 btrfs_release_path(wc->subvol_path); in replay_xattr_deletes()
2640 static noinline int replay_dir_deletes(struct walk_control *wc, in replay_dir_deletes() argument
2643 struct btrfs_root *root = wc->root; in replay_dir_deletes()
2644 struct btrfs_root *log = (del_all ? NULL : wc->log); in replay_dir_deletes()
2657 btrfs_abort_log_replay(wc, -ENOMEM, "failed to allocate path"); in replay_dir_deletes()
2672 btrfs_abort_log_replay(wc, ret, in replay_dir_deletes()
2684 ret = find_dir_range(log, wc->subvol_path, dirid, in replay_dir_deletes()
2687 btrfs_abort_log_replay(wc, ret, in replay_dir_deletes()
2700 wc->subvol_path, 0, 0); in replay_dir_deletes()
2702 btrfs_abort_log_replay(wc, ret, in replay_dir_deletes()
2710 nritems = btrfs_header_nritems(wc->subvol_path->nodes[0]); in replay_dir_deletes()
2711 if (wc->subvol_path->slots[0] >= nritems) { in replay_dir_deletes()
2712 ret = btrfs_next_leaf(root, wc->subvol_path); in replay_dir_deletes()
2716 btrfs_abort_log_replay(wc, ret, in replay_dir_deletes()
2722 btrfs_item_key_to_cpu(wc->subvol_path->nodes[0], &found_key, in replay_dir_deletes()
2723 wc->subvol_path->slots[0]); in replay_dir_deletes()
2733 ret = check_item_in_log(wc, log_path, dir, &found_key, del_all); in replay_dir_deletes()
2740 btrfs_release_path(wc->subvol_path); in replay_dir_deletes()
2747 btrfs_release_path(wc->subvol_path); in replay_dir_deletes()
2765 struct walk_control *wc, u64 gen, int level) in replay_one_buffer() argument
2772 struct btrfs_root *root = wc->root; in replay_one_buffer()
2773 struct btrfs_trans_handle *trans = wc->trans; in replay_one_buffer()
2783 wc->log_leaf = NULL; in replay_one_buffer()
2786 btrfs_abort_log_replay(wc, ret, in replay_one_buffer()
2792 ASSERT(wc->subvol_path == NULL); in replay_one_buffer()
2793 wc->subvol_path = btrfs_alloc_path(); in replay_one_buffer()
2794 if (!wc->subvol_path) { in replay_one_buffer()
2795 btrfs_abort_log_replay(wc, -ENOMEM, "failed to allocate path"); in replay_one_buffer()
2799 wc->log_leaf = eb; in replay_one_buffer()
2802 for (wc->log_slot = 0; wc->log_slot < nritems; wc->log_slot++) { in replay_one_buffer()
2805 btrfs_item_key_to_cpu(eb, &wc->log_key, wc->log_slot); in replay_one_buffer()
2807 if (wc->log_key.type == BTRFS_INODE_ITEM_KEY) { in replay_one_buffer()
2808 inode_item = btrfs_item_ptr(eb, wc->log_slot, in replay_one_buffer()
2830 wc->ignore_cur_inode = true; in replay_one_buffer()
2833 wc->ignore_cur_inode = false; in replay_one_buffer()
2838 if (wc->log_key.type == BTRFS_INODE_ITEM_KEY && in replay_one_buffer()
2839 wc->stage == LOG_WALK_REPLAY_INODES) { in replay_one_buffer()
2842 ret = replay_xattr_deletes(wc); in replay_one_buffer()
2847 ret = replay_dir_deletes(wc, wc->log_key.objectid, false); in replay_one_buffer()
2851 ret = overwrite_item(wc); in replay_one_buffer()
2868 inode = btrfs_iget_logging(wc->log_key.objectid, root); in replay_one_buffer()
2871 btrfs_abort_log_replay(wc, ret, in replay_one_buffer()
2873 wc->log_key.objectid, in replay_one_buffer()
2882 drop_args.path = wc->subvol_path; in replay_one_buffer()
2885 btrfs_abort_log_replay(wc, ret, in replay_one_buffer()
2896 btrfs_abort_log_replay(wc, ret, in replay_one_buffer()
2906 ret = link_to_fixup_dir(wc, wc->log_key.objectid); in replay_one_buffer()
2911 if (wc->ignore_cur_inode) in replay_one_buffer()
2914 if (wc->log_key.type == BTRFS_DIR_INDEX_KEY && in replay_one_buffer()
2915 wc->stage == LOG_WALK_REPLAY_DIR_INDEX) { in replay_one_buffer()
2916 ret = replay_one_dir_item(wc); in replay_one_buffer()
2921 if (wc->stage < LOG_WALK_REPLAY_ALL) in replay_one_buffer()
2925 if (wc->log_key.type == BTRFS_XATTR_ITEM_KEY) { in replay_one_buffer()
2926 ret = overwrite_item(wc); in replay_one_buffer()
2929 } else if (wc->log_key.type == BTRFS_INODE_REF_KEY || in replay_one_buffer()
2930 wc->log_key.type == BTRFS_INODE_EXTREF_KEY) { in replay_one_buffer()
2931 ret = add_inode_ref(wc); in replay_one_buffer()
2934 } else if (wc->log_key.type == BTRFS_EXTENT_DATA_KEY) { in replay_one_buffer()
2935 ret = replay_one_extent(wc); in replay_one_buffer()
2946 btrfs_free_path(wc->subvol_path); in replay_one_buffer()
2947 wc->subvol_path = NULL; in replay_one_buffer()
2991 struct walk_control *wc) in walk_down_log_tree() argument
2993 struct btrfs_trans_handle *trans = wc->trans; in walk_down_log_tree()
2994 struct btrfs_fs_info *fs_info = wc->log->fs_info; in walk_down_log_tree()
3032 ret = wc->process_func(next, wc, ptr_gen, *level - 1); in walk_down_log_tree()
3039 if (wc->free) { in walk_down_log_tree()
3083 struct walk_control *wc) in walk_up_log_tree() argument
3097 ret = wc->process_func(path->nodes[*level], wc, in walk_up_log_tree()
3103 if (wc->free) { in walk_up_log_tree()
3104 ret = clean_log_buffer(wc->trans, path->nodes[*level]); in walk_up_log_tree()
3121 static int walk_log_tree(struct walk_control *wc) in walk_log_tree() argument
3123 struct btrfs_root *log = wc->log; in walk_log_tree()
3141 wret = walk_down_log_tree(path, &level, wc); in walk_log_tree()
3147 wret = walk_up_log_tree(path, &level, wc); in walk_log_tree()
3156 ret = wc->process_func(path->nodes[orig_level], wc, in walk_log_tree()
3161 if (wc->free) in walk_log_tree()
3162 ret = clean_log_buffer(wc->trans, path->nodes[orig_level]); in walk_log_tree()
3624 struct walk_control wc = { in free_log_tree() local
3632 ret = walk_log_tree(&wc); in free_log_tree()
7610 struct walk_control wc = { in btrfs_recover_log_trees() local
7627 wc.trans = trans; in btrfs_recover_log_trees()
7628 wc.pin = true; in btrfs_recover_log_trees()
7629 wc.log = log_root_tree; in btrfs_recover_log_trees()
7631 ret = walk_log_tree(&wc); in btrfs_recover_log_trees()
7632 wc.log = NULL; in btrfs_recover_log_trees()
7663 wc.log = btrfs_read_tree_root(log_root_tree, &found_key); in btrfs_recover_log_trees()
7664 if (IS_ERR(wc.log)) { in btrfs_recover_log_trees()
7665 ret = PTR_ERR(wc.log); in btrfs_recover_log_trees()
7666 wc.log = NULL; in btrfs_recover_log_trees()
7671 wc.root = btrfs_get_fs_root(fs_info, found_key.offset, true); in btrfs_recover_log_trees()
7672 if (IS_ERR(wc.root)) { in btrfs_recover_log_trees()
7673 ret = PTR_ERR(wc.root); in btrfs_recover_log_trees()
7674 wc.root = NULL; in btrfs_recover_log_trees()
7691 ret = btrfs_pin_extent_for_log_replay(trans, wc.log->node); in btrfs_recover_log_trees()
7699 wc.root->log_root = wc.log; in btrfs_recover_log_trees()
7700 ret = btrfs_record_root_in_trans(trans, wc.root); in btrfs_recover_log_trees()
7706 ret = walk_log_tree(&wc); in btrfs_recover_log_trees()
7712 if (wc.stage == LOG_WALK_REPLAY_ALL) { in btrfs_recover_log_trees()
7713 struct btrfs_root *root = wc.root; in btrfs_recover_log_trees()
7715 wc.subvol_path = path; in btrfs_recover_log_trees()
7716 ret = fixup_inode_link_counts(&wc); in btrfs_recover_log_trees()
7717 wc.subvol_path = NULL; in btrfs_recover_log_trees()
7737 if (wc.root) { in btrfs_recover_log_trees()
7738 wc.root->log_root = NULL; in btrfs_recover_log_trees()
7739 btrfs_put_root(wc.root); in btrfs_recover_log_trees()
7741 btrfs_put_root(wc.log); in btrfs_recover_log_trees()
7742 wc.log = NULL; in btrfs_recover_log_trees()
7753 if (wc.pin) { in btrfs_recover_log_trees()
7754 wc.pin = false; in btrfs_recover_log_trees()
7755 wc.process_func = replay_one_buffer; in btrfs_recover_log_trees()
7756 wc.stage = LOG_WALK_REPLAY_INODES; in btrfs_recover_log_trees()
7760 if (wc.stage < LOG_WALK_REPLAY_ALL) { in btrfs_recover_log_trees()
7761 wc.stage++; in btrfs_recover_log_trees()
7776 if (wc.trans) in btrfs_recover_log_trees()
7777 btrfs_end_transaction(wc.trans); in btrfs_recover_log_trees()
7778 btrfs_put_root(wc.log); in btrfs_recover_log_trees()