19 #include <linux/sched.h>
20 #include <linux/slab.h>
38 #define LOG_INODE_ALL 0
39 #define LOG_INODE_EXISTS 1
93 #define LOG_WALK_PIN_ONLY 0
94 #define LOG_WALK_REPLAY_INODES 1
95 #define LOG_WALK_REPLAY_ALL 2
160 if (!root->
fs_info->log_root_tree) {
182 static int join_running_log_trans(
struct btrfs_root *root)
316 u64 saved_i_size = 0;
317 int save_old_i_size = 0;
318 unsigned long src_ptr;
319 unsigned long dst_ptr;
320 int overwrite_root = 0;
325 item_size = btrfs_item_size_nr(eb, slot);
335 if (dst_size != item_size)
338 if (item_size == 0) {
344 if (!dst_copy || !src_copy) {
356 ret =
memcmp(dst_copy, src_copy, item_size);
375 ret = btrfs_insert_empty_item(trans, root, path,
381 found_size = btrfs_item_size_nr(path->
nodes[0],
383 if (found_size > item_size)
385 else if (found_size < item_size)
387 item_size - found_size);
410 if (btrfs_inode_generation(eb, src_item) == 0)
413 if (overwrite_root &&
414 S_ISDIR(btrfs_inode_mode(eb, src_item)) &&
417 saved_i_size = btrfs_inode_size(path->
nodes[0],
425 if (save_old_i_size) {
428 btrfs_set_inode_size(path->
nodes[0], dst_item, saved_i_size);
435 if (btrfs_inode_generation(path->
nodes[0], dst_item) == 0) {
436 btrfs_set_inode_generation(path->
nodes[0], dst_item,
493 struct inode *inode =
NULL;
498 found_type = btrfs_file_extent_type(eb, item);
502 extent_end = start + btrfs_file_extent_num_bytes(eb, item);
504 size = btrfs_file_extent_inline_len(eb, item);
505 extent_end = (start + size +
mask) & ~mask;
511 inode = read_one_inode(root, key->
objectid);
533 leaf = path->
nodes[0];
546 if (
memcmp(&cmp1, &cmp2,
sizeof(cmp1)) == 0) {
561 unsigned long dest_offset;
564 ret = btrfs_insert_empty_item(trans, root, path, key,
570 (
unsigned long)item,
sizeof(*item));
572 ins.objectid = btrfs_file_extent_disk_bytenr(eb, item);
573 ins.offset = btrfs_file_extent_disk_num_bytes(eb, item);
575 offset = key->
offset - btrfs_file_extent_offset(eb, item);
577 if (
ins.objectid > 0) {
605 if (btrfs_file_extent_compression(eb, item)) {
606 csum_start =
ins.objectid;
607 csum_end = csum_start +
ins.offset;
609 csum_start =
ins.objectid +
610 btrfs_file_extent_offset(eb, item);
611 csum_end = csum_start +
612 btrfs_file_extent_num_bytes(eb, item);
616 csum_start, csum_end - 1,
619 while (!list_empty(&ordered_sums)) {
636 ret = overwrite_item(trans, root, path, eb, slot, key);
669 leaf = path->
nodes[0];
671 btrfs_dir_item_key_to_cpu(leaf, di, &
location);
672 name_len = btrfs_dir_name_len(leaf, di);
680 inode = read_one_inode(root,
location.objectid);
686 ret = link_to_fixup_dir(trans, root, path,
location.objectid);
707 const char *name,
int name_len)
714 index, name, name_len, 0);
715 if (di && !IS_ERR(di)) {
724 if (di && !IS_ERR(di)) {
754 unsigned long ptr_end;
755 unsigned long name_ptr;
773 name, namelen,
NULL))
779 item_size = btrfs_item_size_nr(path->
nodes[0], path->
slots[0]);
781 while (ptr < ptr_end) {
783 found_name_len = btrfs_inode_ref_name_len(path->
nodes[0], ref);
784 if (found_name_len == namelen) {
785 name_ptr = (
unsigned long)(ref + 1);
793 ptr = (
unsigned long)(ref + 1) + found_name_len;
804 struct inode *dir,
struct inode *inode,
807 u64 ref_index,
char *name,
int namelen,
820 search_key.objectid = inode_objectid;
827 unsigned long ptr_end;
829 leaf = path->
nodes[0];
834 if (search_key.objectid == search_key.offset)
842 ptr_end = ptr + btrfs_item_size_nr(leaf, path->
slots[0]);
843 while (ptr < ptr_end) {
845 victim_name_len = btrfs_inode_ref_name_len(leaf,
851 (
unsigned long)(victim_ref + 1),
854 if (!backref_in_log(log_root, &search_key,
872 ptr = (
unsigned long)(victim_ref + 1) + victim_name_len;
886 inode_objectid, parent_objectid, 0,
888 if (!IS_ERR_OR_NULL(extref)) {
892 struct inode *victim_parent;
894 leaf = path->
nodes[0];
896 item_size = btrfs_item_size_nr(leaf, path->
slots[0]);
899 while (cur_offset < item_size) {
902 victim_name_len = btrfs_inode_extref_name_len(leaf, extref);
904 if (btrfs_inode_extref_parent(leaf, extref) != parent_objectid)
911 search_key.objectid = inode_objectid;
913 search_key.offset = btrfs_extref_hash(parent_objectid,
917 if (!backref_in_log(log_root, &search_key,
918 parent_objectid, victim_name,
921 victim_parent = read_one_inode(root,
943 cur_offset += victim_name_len +
sizeof(*extref);
951 ref_index, name, namelen, 0);
952 if (di && !IS_ERR(di)) {
953 ret = drop_one_dir_item(trans, root, path, dir, di);
961 if (di && !IS_ERR(di)) {
962 ret = drop_one_dir_item(trans, root, path, dir, di);
970 static int extref_get_fields(
struct extent_buffer *eb,
unsigned long ref_ptr,
971 u32 *namelen,
char **name,
u64 *index,
972 u64 *parent_objectid)
978 *namelen = btrfs_inode_extref_name_len(eb, extref);
986 *index = btrfs_inode_extref_index(eb, extref);
988 *parent_objectid = btrfs_inode_extref_parent(eb, extref);
993 static int ref_get_fields(
struct extent_buffer *eb,
unsigned long ref_ptr,
994 u32 *namelen,
char **name,
u64 *index)
1000 *namelen = btrfs_inode_ref_name_len(eb, ref);
1007 *index = btrfs_inode_ref_index(eb, ref);
1026 struct inode *
inode;
1027 unsigned long ref_ptr;
1028 unsigned long ref_end;
1032 int search_done = 0;
1033 int log_ref_ver = 0;
1037 int ref_struct_size;
1040 ref_end = ref_ptr + btrfs_item_size_nr(eb, slot);
1048 parent_objectid = btrfs_inode_extref_parent(eb, r);
1051 parent_objectid = key->
offset;
1061 dir = read_one_inode(root, parent_objectid);
1065 inode = read_one_inode(root, inode_objectid);
1071 while (ref_ptr < ref_end) {
1073 ret = extref_get_fields(eb, ref_ptr, &namelen, &name,
1074 &ref_index, &parent_objectid);
1080 dir = read_one_inode(root, parent_objectid);
1084 ret = ref_get_fields(eb, ref_ptr, &namelen, &name,
1091 if (!inode_in_dir(root, path, btrfs_ino(dir), btrfs_ino(inode),
1092 ref_index, name, namelen)) {
1102 ret = __add_inode_ref(trans, root, path, log,
1106 ref_index, name, namelen,
1121 ref_ptr = (
unsigned long)(ref_ptr + ref_struct_size) +
namelen;
1130 ret = overwrite_item(trans, root, path, eb, slot, key);
1150 static int count_inode_extrefs(
struct btrfs_root *root,
1151 struct inode *inode,
struct btrfs_path *path)
1155 unsigned int nlink = 0;
1158 u64 inode_objectid = btrfs_ino(inode);
1170 leaf = path->
nodes[0];
1171 item_size = btrfs_item_size_nr(leaf, path->
slots[0]);
1174 while (cur_offset < item_size) {
1176 name_len = btrfs_inode_extref_name_len(leaf, extref);
1180 cur_offset += name_len +
sizeof(*extref);
1193 static int count_inode_refs(
struct btrfs_root *root,
1194 struct inode *inode,
struct btrfs_path *path)
1198 unsigned int nlink = 0;
1200 unsigned long ptr_end;
1202 u64 ino = btrfs_ino(inode);
1213 if (path->
slots[0] == 0)
1217 btrfs_item_key_to_cpu(path->
nodes[0], &key,
1223 ptr_end = ptr + btrfs_item_size_nr(path->
nodes[0],
1225 while (ptr < ptr_end) {
1229 name_len = btrfs_inode_ref_name_len(path->
nodes[0],
1257 struct inode *inode)
1262 u64 ino = btrfs_ino(inode);
1268 ret = count_inode_refs(root, inode, path);
1274 ret = count_inode_extrefs(root, inode, path);
1285 if (nlink != inode->
i_nlink) {
1289 BTRFS_I(inode)->index_cnt = (
u64)-1;
1293 ret = replay_dir_deletes(trans, root,
NULL, path,
1297 ret = insert_orphan_item(trans, root, ino);
1312 struct inode *
inode;
1323 if (path->
slots[0] == 0)
1328 btrfs_item_key_to_cpu(path->
nodes[0], &key, path->
slots[0]);
1333 ret = btrfs_del_item(trans, root, path);
1338 inode = read_one_inode(root, key.
offset);
1342 ret = fixup_inode_link_count(trans, root, inode);
1373 struct inode *
inode;
1375 inode = read_one_inode(root, objectid);
1383 ret = btrfs_insert_empty_item(trans, root, path, &key, 0);
1389 }
else if (ret == -
EEXIST) {
1408 char *name,
int name_len,
u8 type,
1411 struct inode *
inode;
1415 inode = read_one_inode(root, location->
objectid);
1419 dir = read_one_inode(root, dirid);
1424 ret =
btrfs_add_link(trans, dir, inode, name, name_len, 1, index);
1463 dir = read_one_inode(root, key->
objectid);
1467 name_len = btrfs_dir_name_len(eb, di);
1472 log_type = btrfs_dir_type(eb, di);
1476 btrfs_dir_item_key_to_cpu(eb, di, &log_key);
1495 if (IS_ERR_OR_NULL(dst_di)) {
1504 btrfs_dir_item_key_to_cpu(path->
nodes[0], dst_di, &found_key);
1506 if (found_key.objectid == log_key.objectid &&
1507 found_key.type == log_key.type &&
1508 found_key.offset == log_key.offset &&
1509 btrfs_dir_type(path->
nodes[0], dst_di) == log_type) {
1520 ret = drop_one_dir_item(trans, root, path, dir, dst_di);
1533 ret = insert_one_name(trans, root, path, key->
objectid, key->
offset,
1534 name, name_len, log_type, &log_key);
1553 u32 item_size = btrfs_item_size_nr(eb, slot);
1557 unsigned long ptr_end;
1561 while (ptr < ptr_end) {
1565 name_len = btrfs_dir_name_len(eb, di);
1566 ret = replay_one_name(trans, root, path, eb, di, key);
1568 ptr = (
unsigned long)(di + 1);
1587 u64 dirid,
int key_type,
1588 u64 *start_ret,
u64 *end_ret)
1596 if (*start_ret == (
u64)-1)
1600 key.
type = key_type;
1607 if (path->
slots[0] == 0)
1612 btrfs_item_key_to_cpu(path->
nodes[0], &key, path->
slots[0]);
1620 found_end = btrfs_dir_log_end(path->
nodes[0], item);
1622 if (*start_ret >= key.
offset && *start_ret <= found_end) {
1625 *end_ret = found_end;
1631 nritems = btrfs_header_nritems(path->
nodes[0]);
1632 if (path->
slots[0] >= nritems) {
1640 btrfs_item_key_to_cpu(path->
nodes[0], &key, path->
slots[0]);
1648 found_end = btrfs_dir_log_end(path->
nodes[0], item);
1650 *end_ret = found_end;
1678 unsigned long ptr_end;
1680 struct inode *
inode;
1684 eb = path->
nodes[0];
1685 slot = path->
slots[0];
1686 item_size = btrfs_item_size_nr(eb, slot);
1689 while (ptr < ptr_end) {
1696 name_len = btrfs_dir_name_len(eb, di);
1716 if (IS_ERR_OR_NULL(log_di)) {
1717 btrfs_dir_item_key_to_cpu(eb, di, &location);
1720 inode = read_one_inode(root, location.
objectid);
1726 ret = link_to_fixup_dir(trans, root,
1752 ptr = (
unsigned long)(di + 1);
1776 u64 dirid,
int del_all)
1793 dir = read_one_inode(root, dirid);
1807 range_end = (
u64)-1;
1809 ret = find_dir_range(log, path, dirid, key_type,
1810 &range_start, &range_end);
1823 nritems = btrfs_header_nritems(path->
nodes[0]);
1824 if (path->
slots[0] >= nritems) {
1829 btrfs_item_key_to_cpu(path->
nodes[0], &found_key,
1831 if (found_key.objectid != dirid ||
1832 found_key.type != dir_key.
type)
1835 if (found_key.offset > range_end)
1838 ret = check_item_in_log(trans, root, log, path,
1842 if (found_key.offset == (
u64)-1)
1844 dir_key.
offset = found_key.offset + 1;
1847 if (range_end == (
u64)-1)
1849 range_start = range_end + 1;
1893 level = btrfs_header_level(eb);
1902 nritems = btrfs_header_nritems(eb);
1903 for (i = 0; i <
nritems; i++) {
1904 btrfs_item_key_to_cpu(eb, &key, i);
1914 mode = btrfs_inode_mode(eb, inode_item);
1916 ret = replay_dir_deletes(wc->
trans,
1920 ret = overwrite_item(wc->
trans, root, path,
1929 ret = insert_orphan_item(wc->
trans, root,
1934 ret = link_to_fixup_dir(wc->
trans, root,
1943 ret = overwrite_item(wc->
trans, root, path,
1947 ret = add_inode_ref(wc->
trans, root, log, path,
1951 ret = add_inode_ref(wc->
trans, root, log, path,
1955 ret = replay_one_extent(wc->
trans, root, path,
1960 ret = replay_one_dir_item(wc->
trans, root, path,
1986 while (*level > 0) {
1991 if (btrfs_header_level(cur) != *level)
1994 if (path->
slots[*level] >=
1995 btrfs_header_nritems(cur))
1998 bytenr = btrfs_node_blockptr(cur, path->
slots[*level]);
1999 ptr_gen = btrfs_node_ptr_generation(cur, path->
slots[*level]);
2000 blocksize = btrfs_level_size(root, *level - 1);
2003 root_owner = btrfs_header_owner(parent);
2023 btrfs_set_lock_blocking(next);
2044 if (path->
nodes[*level-1])
2047 *level = btrfs_header_level(next);
2072 if (slot + 1 < btrfs_header_nritems(path->
nodes[i])) {
2082 parent = path->
nodes[*level + 1];
2084 root_owner = btrfs_header_owner(parent);
2086 btrfs_header_generation(path->
nodes[*level]));
2096 btrfs_set_lock_blocking(next);
2103 path->
nodes[*level]->start,
2104 path->
nodes[*level]->len);
2134 level = btrfs_header_level(log->
node);
2137 extent_buffer_get(log->
node);
2141 wret = walk_down_log_tree(trans, log, path, &level, wc);
2149 wret = walk_up_log_tree(trans, log, path, &level, wc);
2159 if (path->
nodes[orig_level]) {
2161 btrfs_header_generation(path->
nodes[orig_level]));
2167 next = path->
nodes[orig_level];
2170 btrfs_set_lock_blocking(next);
2184 for (i = 0; i <= orig_level; i++) {
2185 if (path->
nodes[i]) {
2218 int index = transid % 2;
2230 if (root->
fs_info->last_trans_log_full_commit !=
2237 }
while (root->
fs_info->last_trans_log_full_commit !=
2247 while (root->
fs_info->last_trans_log_full_commit !=
2252 if (root->
fs_info->last_trans_log_full_commit !=
2294 wait_log_commit(trans, root, root->
log_transid - 1);
2303 wait_for_writer(trans, root);
2309 if (root->
fs_info->last_trans_log_full_commit == trans->
transid) {
2316 if (log_transid % 2 == 0)
2349 ret = update_log_root(trans, log);
2374 wait_log_commit(trans, log_root_tree,
2383 wait_log_commit(trans, log_root_tree,
2387 wait_for_writer(trans, log_root_tree);
2393 if (root->
fs_info->last_trans_log_full_commit == trans->
transid) {
2397 goto out_wake_log_root;
2406 goto out_wake_log_root;
2410 btrfs_set_super_log_root(root->
fs_info->super_for_commit,
2411 log_root_tree->
node->start);
2412 btrfs_set_super_log_root_level(root->
fs_info->super_for_commit,
2413 btrfs_header_level(log_root_tree->
node));
2432 goto out_wake_log_root;
2461 .process_func = process_one_buffer
2464 ret = walk_log_tree(trans, log, &wc);
2489 free_log_tree(trans, root->
log_root);
2528 const char *name,
int name_len,
2529 struct inode *dir,
u64 index)
2537 u64 dir_ino = btrfs_ino(dir);
2539 if (BTRFS_I(dir)->logged_trans < trans->transid)
2542 ret = join_running_log_trans(root);
2556 name, name_len, -1);
2568 index, name, name_len, -1);
2601 i_size = btrfs_inode_size(path->
nodes[0], item);
2602 if (i_size > bytes_del)
2603 i_size -= bytes_del;
2606 btrfs_set_inode_size(path->
nodes[0], item, i_size);
2630 const char *name,
int name_len,
2631 struct inode *inode,
u64 dirid)
2637 if (BTRFS_I(inode)->logged_trans < trans->transid)
2640 ret = join_running_log_trans(root);
2652 }
else if (ret < 0 && ret != -
ENOENT)
2667 int key_type,
u64 dirid,
2668 u64 first_offset,
u64 last_offset)
2675 key.
offset = first_offset;
2680 ret = btrfs_insert_empty_item(trans, log, path, &key,
sizeof(*item));
2686 btrfs_set_dir_log_end(path->
nodes[0], item, last_offset);
2698 struct btrfs_root *root,
struct inode *inode,
2701 u64 min_offset,
u64 *last_offset_ret)
2711 u64 first_offset = min_offset;
2712 u64 last_offset = (
u64)-1;
2713 u64 ino = btrfs_ino(inode);
2716 max_key.objectid =
ino;
2717 max_key.offset = (
u64)-1;
2718 max_key.type = key_type;
2720 min_key.objectid =
ino;
2721 min_key.type = key_type;
2722 min_key.offset = min_offset;
2733 if (ret != 0 || min_key.objectid != ino || min_key.type != key_type) {
2734 min_key.objectid =
ino;
2735 min_key.type = key_type;
2736 min_key.offset = (
u64)-1;
2752 btrfs_item_key_to_cpu(path->
nodes[0], &
tmp,
2754 if (key_type ==
tmp.type)
2755 first_offset =
max(min_offset,
tmp.offset) + 1;
2764 btrfs_item_key_to_cpu(path->
nodes[0], &
tmp, path->
slots[0]);
2765 if (key_type ==
tmp.type) {
2766 first_offset =
tmp.offset;
2767 ret = overwrite_item(trans, log, dst_path,
2791 src = path->
nodes[0];
2792 nritems = btrfs_header_nritems(src);
2793 for (i = path->
slots[0]; i < nritems; i++) {
2794 btrfs_item_key_to_cpu(src, &min_key, i);
2796 if (min_key.objectid != ino || min_key.type != key_type)
2798 ret = overwrite_item(trans, log, dst_path, src, i,
2813 last_offset = (
u64)-1;
2816 btrfs_item_key_to_cpu(path->
nodes[0], &
tmp, path->
slots[0]);
2817 if (
tmp.objectid != ino ||
tmp.type != key_type) {
2818 last_offset = (
u64)-1;
2821 if (btrfs_header_generation(path->
nodes[0]) != trans->
transid) {
2822 ret = overwrite_item(trans, log, dst_path,
2828 last_offset =
tmp.offset;
2837 *last_offset_ret = last_offset;
2842 ret = insert_dir_log_key(trans, log, path, key_type,
2843 ino, first_offset, last_offset);
2863 struct btrfs_root *root,
struct inode *inode,
2876 ret = log_dir_items(trans, root, inode, path,
2877 dst_path, key_type, min_key,
2881 if (max_key == (
u64)-1)
2883 min_key = max_key + 1;
2902 u64 objectid,
int max_key_type)
2910 key.
type = max_key_type;
2919 if (path->
slots[0] == 0)
2923 btrfs_item_key_to_cpu(path->
nodes[0], &found_key,
2926 if (found_key.objectid != objectid)
2929 found_key.offset = 0;
2935 path->
slots[0] - start_slot + 1);
2940 if (ret || start_slot != 0)
2953 struct inode *inode,
int log_inode_only)
2955 btrfs_set_inode_uid(leaf, item, i_uid_read(inode));
2956 btrfs_set_inode_gid(leaf, item, i_gid_read(inode));
2957 btrfs_set_inode_mode(leaf, item, inode->
i_mode);
2958 btrfs_set_inode_nlink(leaf, item, inode->
i_nlink);
2960 btrfs_set_timespec_sec(leaf, btrfs_inode_atime(item),
2962 btrfs_set_timespec_nsec(leaf, btrfs_inode_atime(item),
2965 btrfs_set_timespec_sec(leaf, btrfs_inode_mtime(item),
2967 btrfs_set_timespec_nsec(leaf, btrfs_inode_mtime(item),
2970 btrfs_set_timespec_sec(leaf, btrfs_inode_ctime(item),
2972 btrfs_set_timespec_nsec(leaf, btrfs_inode_ctime(item),
2977 btrfs_set_inode_sequence(leaf, item, inode->
i_version);
2978 btrfs_set_inode_transid(leaf, item, trans->
transid);
2979 btrfs_set_inode_rdev(leaf, item, inode->
i_rdev);
2980 btrfs_set_inode_flags(leaf, item, BTRFS_I(inode)->
flags);
2981 btrfs_set_inode_block_group(leaf, item, 0);
2983 if (log_inode_only) {
2989 btrfs_set_inode_generation(leaf, item, 0);
2990 btrfs_set_inode_size(leaf, item, 0);
2992 btrfs_set_inode_generation(leaf, item,
2994 btrfs_set_inode_size(leaf, item, inode->
i_size);
3000 struct inode *inode,
3003 int start_slot,
int nr,
int inode_only)
3005 unsigned long src_offset;
3006 unsigned long dst_offset;
3018 INIT_LIST_HEAD(&ordered_sums);
3025 ins_sizes = (
u32 *)ins_data;
3026 ins_keys = (
struct btrfs_key *)(ins_data + nr *
sizeof(
u32));
3028 for (i = 0; i <
nr; i++) {
3029 ins_sizes[
i] = btrfs_item_size_nr(src, i + start_slot);
3030 btrfs_item_key_to_cpu(src, ins_keys + i, i + start_slot);
3033 ins_keys, ins_sizes, nr);
3039 for (i = 0; i <
nr; i++, dst_path->
slots[0]++) {
3041 dst_path->
slots[0]);
3049 fill_inode_item(trans, dst_path->
nodes[0], inode_item,
3053 src_offset, ins_sizes[i]);
3066 if (btrfs_file_extent_generation(src, extent) < trans->
transid)
3069 found_type = btrfs_file_extent_type(src, extent);
3072 ds = btrfs_file_extent_disk_bytenr(src,
3078 dl = btrfs_file_extent_disk_num_bytes(src,
3080 cs = btrfs_file_extent_offset(src, extent);
3081 cl = btrfs_file_extent_num_bytes(src,
3083 if (btrfs_file_extent_compression(src,
3091 ds + cs, ds + cs + cl - 1,
3107 while (!list_empty(&ordered_sums)) {
3141 struct inode *inode,
struct btrfs_root *root,
3155 if (BTRFS_I(inode)->logged_trans == trans->
transid) {
3157 start + len,
NULL, 0);
3168 key.
offset = search_start;
3184 if (path->
slots[0] == 0) {
3186 if (search_start == 0)
3193 btrfs_item_key_to_cpu(path->
nodes[0], &key,
3195 if (key.
objectid != btrfs_ino(inode) ||
3200 }
while (key.
offset > start);
3204 num_bytes = btrfs_file_extent_num_bytes(path->
nodes[0],
3206 if (key.
offset + num_bytes <= start) {
3213 btrfs_item_key_to_cpu(path->
nodes[0], &key, path->
slots[0]);
3219 }
else if (args->
nr) {
3220 ret = copy_items(trans, inode, dst_path, args->
src,
3227 }
else if (!args->
nr) {
3231 nritems = btrfs_header_nritems(path->
nodes[0]);
3233 num_bytes = btrfs_file_extent_num_bytes(args->
src, fi);
3234 if (len < num_bytes) {
3249 search_start =
start;
3251 if (path->
slots[0] < nritems) {
3258 ret = copy_items(trans, inode, dst_path, args->
src,
3273 struct inode *inode,
3284 INIT_LIST_HEAD(&extents);
3286 memset(&args, 0,
sizeof(args));
3289 test_gen = root->
fs_info->last_trans_committed;
3292 list_del_init(&em->
list);
3303 while (!list_empty(&extents)) {
3306 list_del_init(&em->
list);
3326 ret = copy_items(trans, inode, dst_path, args.
src,
3338 ret = log_one_extent(trans, inode, root, em, path, dst_path, &args);
3342 WARN_ON(!list_empty(&extents));
3345 if (!ret && args.
nr)
3346 ret = copy_items(trans, inode, dst_path, args.
src,
3367 struct btrfs_root *root,
struct inode *inode,
3379 int ins_start_slot = 0;
3381 bool fast_search =
false;
3382 u64 ino = btrfs_ino(inode);
3395 min_key.objectid =
ino;
3399 max_key.objectid =
ino;
3406 max_key.type = (
u8)-1;
3407 max_key.offset = (
u64)-1;
3411 BTRFS_I(inode)->generation > root->
fs_info->last_trans_committed) {
3431 ret = drop_objectid_items(trans, log, path, ino, max_key_type);
3434 &BTRFS_I(inode)->runtime_flags)) {
3440 ret = drop_objectid_items(trans, log, path, ino,
3458 if (min_key.objectid != ino)
3460 if (min_key.type > max_key.type)
3463 src = path->
nodes[0];
3464 if (ins_nr && ins_start_slot + ins_nr == path->
slots[0]) {
3467 }
else if (!ins_nr) {
3468 ins_start_slot = path->
slots[0];
3473 ret = copy_items(trans, inode, dst_path, src, ins_start_slot,
3474 ins_nr, inode_only);
3480 ins_start_slot = path->
slots[0];
3483 nritems = btrfs_header_nritems(path->
nodes[0]);
3485 if (path->
slots[0] < nritems) {
3486 btrfs_item_key_to_cpu(path->
nodes[0], &min_key,
3491 ret = copy_items(trans, inode, dst_path, src,
3493 ins_nr, inode_only);
3502 if (min_key.offset < (
u64)-1)
3504 else if (min_key.type < (
u8)-1)
3506 else if (min_key.objectid < (
u64)-1)
3512 ret = copy_items(trans, inode, dst_path, src, ins_start_slot,
3513 ins_nr, inode_only);
3524 ret = btrfs_log_changed_extents(trans, root, inode, path,
3535 list_del_init(&em->
list);
3541 ret = log_directory_changes(trans, root, inode, path, dst_path);
3547 BTRFS_I(inode)->logged_trans = trans->
transid;
3548 BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->last_sub_trans;
3564 struct inode *inode,
3580 BTRFS_I(inode)->
generation <= last_committed &&
3581 BTRFS_I(inode)->last_unlink_trans <= last_committed)
3591 BTRFS_I(inode)->logged_trans = trans->
transid;
3594 if (BTRFS_I(inode)->last_unlink_trans > last_committed) {
3595 root = BTRFS_I(inode)->root;
3601 root->
fs_info->last_trans_log_full_commit =
3615 old_parent = parent;
3631 struct btrfs_root *root,
struct inode *inode,
3632 struct dentry *parent,
int exists_only)
3638 u64 last_committed = root->
fs_info->last_trans_committed;
3647 if (root->
fs_info->last_trans_log_full_commit >
3648 root->
fs_info->last_trans_committed) {
3653 if (root != BTRFS_I(inode)->root ||
3654 btrfs_root_refs(&root->
root_item) == 0) {
3659 ret = check_parent_dirs_for_sync(trans, inode, parent,
3660 sb, last_committed);
3664 if (btrfs_inode_in_log(inode, trans->
transid)) {
3669 ret = start_log_trans(trans, root);
3673 ret = btrfs_log_inode(trans, root, inode, inode_only);
3684 BTRFS_I(inode)->
generation <= last_committed &&
3685 BTRFS_I(inode)->last_unlink_trans <= last_committed) {
3696 if (root != BTRFS_I(inode)->root)
3700 root->
fs_info->last_trans_committed) {
3701 ret = btrfs_log_inode(trans, root, inode, inode_only);
3710 old_parent = parent;
3769 if (IS_ERR(trans)) {
3770 ret = PTR_ERR(trans);
3777 ret = walk_log_tree(trans, log_root_tree, &wc);
3779 btrfs_error(fs_info, ret,
"Failed to pin buffers while "
3780 "recovering log root tree.");
3794 "Couldn't find tree log root.");
3798 if (path->
slots[0] == 0)
3802 btrfs_item_key_to_cpu(path->
nodes[0], &found_key,
3813 "Couldn't read tree log root.");
3824 btrfs_error(fs_info, ret,
"Couldn't read target root "
3825 "for tree log recovery.");
3831 ret = walk_log_tree(trans, log, &wc);
3835 ret = fixup_inode_link_counts(trans, wc.
replay_dest,
3846 if (found_key.
offset == 0)
3873 kfree(log_root_tree);
3890 struct inode *dir,
struct inode *inode,
3904 BTRFS_I(inode)->last_unlink_trans = trans->
transid;
3911 if (BTRFS_I(dir)->logged_trans == trans->
transid)
3918 if (BTRFS_I(inode)->logged_trans == trans->
transid)
3935 BTRFS_I(dir)->last_unlink_trans = trans->
transid;
3946 struct inode *inode,
struct inode *old_dir,
3949 struct btrfs_root * root = BTRFS_I(inode)->root;
3956 BTRFS_I(inode)->last_unlink_trans = trans->
transid;
3962 if (BTRFS_I(inode)->logged_trans <=
3963 root->
fs_info->last_trans_committed &&
3964 (!old_dir || BTRFS_I(old_dir)->logged_trans <=
3965 root->
fs_info->last_trans_committed))