Lines Matching +full:deep +full:- +full:touch

1 // SPDX-License-Identifier: GPL-2.0
13 #include "tree-log.h"
14 #include "disk-io.h"
19 #include "block-group.h"
20 #include "space-info.h"
21 #include "inode-item.h"
24 #include "extent-tree.h"
25 #include "root-tree.h"
26 #include "dir-item.h"
27 #include "file-item.h"
30 #include "tree-checker.h"
51 * ---> record transid of last unlink/rename per directory
64 * log. ---> check inode while renaming/linking.
68 * ---> check inode and old parent dir during rename
74 * of zero and redo the rm -rf
78 * rm -rf f1/foo
82 * called on f1, only its parent dir. After a crash the rm -rf must
124 * extent tree an 4x-6x higher write load than ext3.
132 * After a crash, items are copied out of the log-tree back into the
134 * allocation tree, and the log-tree freed.
172 struct btrfs_fs_info *fs_info = root->fs_info; in start_log_trans()
173 struct btrfs_root *tree_root = fs_info->tree_root; in start_log_trans()
182 if (!test_bit(BTRFS_ROOT_HAS_LOG_TREE, &tree_root->state)) { in start_log_trans()
183 mutex_lock(&tree_root->log_mutex); in start_log_trans()
184 if (!fs_info->log_root_tree) { in start_log_trans()
187 set_bit(BTRFS_ROOT_HAS_LOG_TREE, &tree_root->state); in start_log_trans()
191 mutex_unlock(&tree_root->log_mutex); in start_log_trans()
196 mutex_lock(&root->log_mutex); in start_log_trans()
199 if (root->log_root) { in start_log_trans()
200 int index = (root->log_transid + 1) % 2; in start_log_trans()
207 if (zoned && atomic_read(&root->log_commit[index])) { in start_log_trans()
208 wait_log_commit(root, root->log_transid - 1); in start_log_trans()
212 if (!root->log_start_pid) { in start_log_trans()
213 clear_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state); in start_log_trans()
214 root->log_start_pid = current->pid; in start_log_trans()
215 } else if (root->log_start_pid != current->pid) { in start_log_trans()
216 set_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state); in start_log_trans()
220 * This means fs_info->log_root_tree was already created in start_log_trans()
234 set_bit(BTRFS_ROOT_HAS_LOG_TREE, &root->state); in start_log_trans()
235 clear_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state); in start_log_trans()
236 root->log_start_pid = current->pid; in start_log_trans()
239 atomic_inc(&root->log_writers); in start_log_trans()
240 if (!ctx->logging_new_name) { in start_log_trans()
241 int index = root->log_transid % 2; in start_log_trans()
242 list_add_tail(&ctx->list, &root->log_ctxs[index]); in start_log_trans()
243 ctx->log_transid = root->log_transid; in start_log_trans()
247 mutex_unlock(&root->log_mutex); in start_log_trans()
253 * to join, or returns -ENOENT if there were not transactions
258 const bool zoned = btrfs_is_zoned(root->fs_info); in join_running_log_trans()
259 int ret = -ENOENT; in join_running_log_trans()
261 if (!test_bit(BTRFS_ROOT_HAS_LOG_TREE, &root->state)) in join_running_log_trans()
264 mutex_lock(&root->log_mutex); in join_running_log_trans()
266 if (root->log_root) { in join_running_log_trans()
267 int index = (root->log_transid + 1) % 2; in join_running_log_trans()
270 if (zoned && atomic_read(&root->log_commit[index])) { in join_running_log_trans()
271 wait_log_commit(root, root->log_transid - 1); in join_running_log_trans()
274 atomic_inc(&root->log_writers); in join_running_log_trans()
276 mutex_unlock(&root->log_mutex); in join_running_log_trans()
287 atomic_inc(&root->log_writers); in btrfs_pin_log_trans()
296 if (atomic_dec_and_test(&root->log_writers)) { in btrfs_end_log_trans()
298 cond_wake_up_nomb(&root->log_writer_wait); in btrfs_end_log_trans()
351 struct btrfs_fs_info *fs_info = log->fs_info; in process_one_buffer()
369 if (wc->pin) { in process_one_buffer()
370 ret = btrfs_pin_extent_for_log_replay(wc->trans, eb); in process_one_buffer()
409 bool inode_item = key->type == BTRFS_INODE_ITEM_KEY; in overwrite_item()
428 dst_eb = path->nodes[0]; in overwrite_item()
429 dst_slot = path->slots[0]; in overwrite_item()
445 return -ENOMEM; in overwrite_item()
512 path->skip_release_on_error = 1; in overwrite_item()
515 path->skip_release_on_error = 0; in overwrite_item()
517 dst_eb = path->nodes[0]; in overwrite_item()
518 dst_slot = path->slots[0]; in overwrite_item()
521 if (ret == -EEXIST || ret == -EOVERFLOW) { in overwrite_item()
527 btrfs_extend_item(trans, path, item_size - found_size); in overwrite_item()
542 if (key->type == BTRFS_INODE_ITEM_KEY && ret == -EEXIST) { in overwrite_item()
583 if (key->type == BTRFS_INODE_ITEM_KEY) { in overwrite_item()
588 btrfs_set_inode_generation(dst_eb, dst_item, trans->transid); in overwrite_item()
602 return -ENOMEM; in read_alloc_one_name()
605 name->name = buf; in read_alloc_one_name()
606 name->len = len; in read_alloc_one_name()
629 struct btrfs_fs_info *fs_info = root->fs_info; in replay_one_extent()
632 u64 start = key->offset; in replay_one_extent()
657 fs_info->sectorsize); in replay_one_extent()
661 found_type, btrfs_root_id(root), key->objectid, key->offset); in replay_one_extent()
662 return -EUCLEAN; in replay_one_extent()
665 inode = btrfs_iget_logging(key->objectid, root); in replay_one_extent()
682 ptr = btrfs_item_ptr_offset(path->nodes[0], path->slots[0]); in replay_one_extent()
683 read_extent_buffer(path->nodes[0], &existing, ptr, sizeof(existing)); in replay_one_extent()
719 dest_offset = btrfs_item_ptr_offset(path->nodes[0], in replay_one_extent()
720 path->slots[0]); in replay_one_extent()
721 copy_extent_buffer(path->nodes[0], eb, dest_offset, in replay_one_extent()
727 offset = key->offset - btrfs_file_extent_offset(eb, item); in replay_one_extent()
764 btrfs_init_data_ref(&ref, key->objectid, offset, in replay_one_extent()
776 key->objectid, offset, &ins); in replay_one_extent()
792 ret = btrfs_lookup_csums_list(root->log_root, in replay_one_extent()
793 csum_start, csum_end - 1, in replay_one_extent()
831 * Which covers the 20K sub-range starting at offset 20K in replay_one_extent()
855 sums->logical); in replay_one_extent()
858 sums->logical, in replay_one_extent()
859 sums->len); in replay_one_extent()
864 list_del(&sums->list); in replay_one_extent()
879 ret = btrfs_inode_set_file_extent_range(inode, start, extent_end - start); in replay_one_extent()
887 iput(&inode->vfs_inode); in replay_one_extent()
923 struct btrfs_root *root = dir->root; in drop_one_dir_item()
930 leaf = path->nodes[0]; in drop_one_dir_item()
935 return -ENOMEM; in drop_one_dir_item()
954 iput(&inode->vfs_inode); in drop_one_dir_item()
980 btrfs_dir_item_key_to_cpu(path->nodes[0], di, &location); in inode_in_dir()
993 btrfs_dir_item_key_to_cpu(path->nodes[0], di, &location); in inode_in_dir()
1022 return -ENOMEM; in backref_in_log()
1032 if (key->type == BTRFS_INODE_EXTREF_KEY) in backref_in_log()
1033 ret = !!btrfs_find_name_in_ext_backref(path->nodes[0], in backref_in_log()
1034 path->slots[0], in backref_in_log()
1037 ret = !!btrfs_find_name_in_backref(path->nodes[0], in backref_in_log()
1038 path->slots[0], name); in backref_in_log()
1072 leaf = path->nodes[0]; in __add_inode_ref()
1084 ptr = btrfs_item_ptr_offset(leaf, path->slots[0]); in __add_inode_ref()
1085 ptr_end = ptr + btrfs_item_size(leaf, path->slots[0]); in __add_inode_ref()
1102 inc_nlink(&inode->vfs_inode); in __add_inode_ref()
1131 leaf = path->nodes[0]; in __add_inode_ref()
1133 item_size = btrfs_item_size(leaf, path->slots[0]); in __add_inode_ref()
1134 base = btrfs_item_ptr_offset(leaf, path->slots[0]); in __add_inode_ref()
1145 ret = read_alloc_one_name(leaf, &extref->name, in __add_inode_ref()
1165 inc_nlink(&inode->vfs_inode); in __add_inode_ref()
1171 iput(&victim_parent->vfs_inode); in __add_inode_ref()
1220 ret = read_alloc_one_name(eb, &extref->name, in extref_get_fields()
1282 eb = path->nodes[0]; in unlink_old_inode_refs()
1283 ref_ptr = btrfs_item_ptr_offset(eb, path->slots[0]); in unlink_old_inode_refs()
1284 ref_end = ref_ptr + btrfs_item_size(eb, path->slots[0]); in unlink_old_inode_refs()
1289 if (key->type == BTRFS_INODE_EXTREF_KEY) { in unlink_old_inode_refs()
1293 parent_id = key->offset; in unlink_old_inode_refs()
1299 if (key->type == BTRFS_INODE_EXTREF_KEY) in unlink_old_inode_refs()
1317 iput(&dir->vfs_inode); in unlink_old_inode_refs()
1325 if (key->type == BTRFS_INODE_EXTREF_KEY) in unlink_old_inode_refs()
1364 if (key->type == BTRFS_INODE_EXTREF_KEY) { in add_inode_ref()
1373 parent_objectid = key->offset; in add_inode_ref()
1375 inode_objectid = key->objectid; in add_inode_ref()
1455 iput(&dir->vfs_inode); in add_inode_ref()
1478 iput(&dir->vfs_inode); in add_inode_ref()
1480 iput(&inode->vfs_inode); in add_inode_ref()
1498 ret = btrfs_find_one_extref(inode->root, inode_objectid, offset, in count_inode_extrefs()
1503 leaf = path->nodes[0]; in count_inode_extrefs()
1504 item_size = btrfs_item_size(leaf, path->slots[0]); in count_inode_extrefs()
1505 ptr = btrfs_item_ptr_offset(leaf, path->slots[0]); in count_inode_extrefs()
1522 if (ret < 0 && ret != -ENOENT) in count_inode_extrefs()
1539 key.offset = (u64)-1; in count_inode_refs()
1542 ret = btrfs_search_slot(NULL, inode->root, &key, path, 0, 0); in count_inode_refs()
1546 if (path->slots[0] == 0) in count_inode_refs()
1548 path->slots[0]--; in count_inode_refs()
1551 btrfs_item_key_to_cpu(path->nodes[0], &key, in count_inode_refs()
1552 path->slots[0]); in count_inode_refs()
1556 ptr = btrfs_item_ptr_offset(path->nodes[0], path->slots[0]); in count_inode_refs()
1557 ptr_end = ptr + btrfs_item_size(path->nodes[0], in count_inode_refs()
1558 path->slots[0]); in count_inode_refs()
1563 name_len = btrfs_inode_ref_name_len(path->nodes[0], in count_inode_refs()
1571 if (path->slots[0] > 0) { in count_inode_refs()
1572 path->slots[0]--; in count_inode_refs()
1575 key.offset--; in count_inode_refs()
1596 struct btrfs_root *root = inode->root; in fixup_inode_link_count()
1604 return -ENOMEM; in fixup_inode_link_count()
1620 if (nlink != inode->vfs_inode.i_nlink) { in fixup_inode_link_count()
1621 set_nlink(&inode->vfs_inode, nlink); in fixup_inode_link_count()
1626 if (S_ISDIR(inode->vfs_inode.i_mode)) in fixup_inode_link_count()
1627 inode->index_cnt = (u64)-1; in fixup_inode_link_count()
1629 if (inode->vfs_inode.i_nlink == 0) { in fixup_inode_link_count()
1630 if (S_ISDIR(inode->vfs_inode.i_mode)) { in fixup_inode_link_count()
1637 if (ret == -EEXIST) in fixup_inode_link_count()
1655 key.offset = (u64)-1; in fixup_inode_link_counts()
1659 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); in fixup_inode_link_counts()
1665 if (path->slots[0] == 0) in fixup_inode_link_counts()
1667 path->slots[0]--; in fixup_inode_link_counts()
1670 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); in fixup_inode_link_counts()
1687 iput(&inode->vfs_inode); in fixup_inode_link_counts()
1696 key.offset = (u64)-1; in fixup_inode_link_counts()
1722 vfs_inode = &inode->vfs_inode; in link_to_fixup_dir()
1731 if (!vfs_inode->i_nlink) in link_to_fixup_dir()
1736 } else if (ret == -EEXIST) { in link_to_fixup_dir()
1759 inode = btrfs_iget_logging(location->objectid, root); in insert_one_name()
1765 iput(&inode->vfs_inode); in insert_one_name()
1773 iput(&inode->vfs_inode); in insert_one_name()
1774 iput(&dir->vfs_inode); in insert_one_name()
1788 btrfs_dir_item_key_to_cpu(path->nodes[0], dst_di, &found_key); in delete_conflicting_dir_entry()
1790 if (found_key.objectid == log_key->objectid && in delete_conflicting_dir_entry()
1791 found_key.type == log_key->type && in delete_conflicting_dir_entry()
1792 found_key.offset == log_key->offset && in delete_conflicting_dir_entry()
1793 btrfs_dir_flags(path->nodes[0], dst_di) == log_flags) in delete_conflicting_dir_entry()
1820 * non-existing inode) and 1 if the name was replayed.
1843 dir = btrfs_iget_logging(key->objectid, root); in replay_one_name()
1860 dir_dst_di = btrfs_lookup_dir_item(trans, root, path, key->objectid, in replay_one_name()
1876 key->objectid, key->offset, in replay_one_name()
1903 search_key.offset = key->objectid; in replay_one_name()
1904 ret = backref_in_log(root->log_root, &search_key, 0, &name); in replay_one_name()
1916 search_key.offset = key->objectid; in replay_one_name()
1917 ret = backref_in_log(root->log_root, &search_key, key->objectid, &name); in replay_one_name()
1927 ret = insert_one_name(trans, root, key->objectid, key->offset, in replay_one_name()
1929 if (ret && ret != -ENOENT && ret != -EEXIST) in replay_one_name()
1938 btrfs_i_size_write(dir, dir->vfs_inode.i_size + name.len * 2); in replay_one_name()
1942 iput(&dir->vfs_inode); in replay_one_name()
1959 ASSERT(key->type == BTRFS_DIR_INDEX_KEY); in replay_one_dir_item()
1967 * If this entry refers to a non-directory (directories can not have a in replay_one_dir_item()
1975 * touch testdir/foo in replay_one_dir_item()
1976 * touch testdir/bar in replay_one_dir_item()
1981 * xfs_io -c "fsync" testdir/bar in replay_one_dir_item()
1998 return -ENOMEM; in replay_one_dir_item()
2030 if (*start_ret == (u64)-1) in find_dir_range()
2041 if (path->slots[0] == 0) in find_dir_range()
2043 path->slots[0]--; in find_dir_range()
2046 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); in find_dir_range()
2052 item = btrfs_item_ptr(path->nodes[0], path->slots[0], in find_dir_range()
2054 found_end = btrfs_dir_log_end(path->nodes[0], item); in find_dir_range()
2065 nritems = btrfs_header_nritems(path->nodes[0]); in find_dir_range()
2066 path->slots[0]++; in find_dir_range()
2067 if (path->slots[0] >= nritems) { in find_dir_range()
2073 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); in find_dir_range()
2079 item = btrfs_item_ptr(path->nodes[0], path->slots[0], in find_dir_range()
2081 found_end = btrfs_dir_log_end(path->nodes[0], item); in find_dir_range()
2102 struct btrfs_root *root = dir->root; in check_item_in_log()
2117 ASSERT(dir_key->type == BTRFS_DIR_INDEX_KEY); in check_item_in_log()
2119 eb = path->nodes[0]; in check_item_in_log()
2120 slot = path->slots[0]; in check_item_in_log()
2130 dir_key->objectid, in check_item_in_log()
2131 dir_key->offset, &name, 0); in check_item_in_log()
2156 inc_nlink(&inode->vfs_inode); in check_item_in_log()
2168 iput(&inode->vfs_inode); in check_item_in_log()
2186 return -ENOMEM; in replay_xattr_deletes()
2196 nritems = btrfs_header_nritems(path->nodes[0]); in replay_xattr_deletes()
2197 for (i = path->slots[0]; i < nritems; i++) { in replay_xattr_deletes()
2204 btrfs_item_key_to_cpu(path->nodes[0], &key, i); in replay_xattr_deletes()
2210 di = btrfs_item_ptr(path->nodes[0], i, struct btrfs_dir_item); in replay_xattr_deletes()
2211 total_size = btrfs_item_size(path->nodes[0], i); in replay_xattr_deletes()
2214 u16 name_len = btrfs_dir_name_len(path->nodes[0], di); in replay_xattr_deletes()
2215 u16 data_len = btrfs_dir_data_len(path->nodes[0], di); in replay_xattr_deletes()
2221 ret = -ENOMEM; in replay_xattr_deletes()
2224 read_extent_buffer(path->nodes[0], name, in replay_xattr_deletes()
2234 name, name_len, -1); in replay_xattr_deletes()
2298 return -ENOMEM; in replay_dir_deletes()
2308 if (ret == -ENOENT) in replay_dir_deletes()
2317 range_end = (u64)-1; in replay_dir_deletes()
2335 nritems = btrfs_header_nritems(path->nodes[0]); in replay_dir_deletes()
2336 if (path->slots[0] >= nritems) { in replay_dir_deletes()
2343 btrfs_item_key_to_cpu(path->nodes[0], &found_key, in replay_dir_deletes()
2344 path->slots[0]); in replay_dir_deletes()
2359 if (found_key.offset == (u64)-1) in replay_dir_deletes()
2364 if (range_end == (u64)-1) in replay_dir_deletes()
2372 iput(&dir->vfs_inode); in replay_dir_deletes()
2396 struct btrfs_root *root = wc->replay_dest; in replay_one_buffer()
2412 return -ENOMEM; in replay_one_buffer()
2420 wc->stage == LOG_WALK_REPLAY_INODES) { in replay_one_buffer()
2435 wc->ignore_cur_inode = true; in replay_one_buffer()
2438 wc->ignore_cur_inode = false; in replay_one_buffer()
2440 ret = replay_xattr_deletes(wc->trans, root, log, in replay_one_buffer()
2446 ret = replay_dir_deletes(wc->trans, in replay_one_buffer()
2451 ret = overwrite_item(wc->trans, root, path, in replay_one_buffer()
2474 from = ALIGN(i_size_read(&inode->vfs_inode), in replay_one_buffer()
2475 root->fs_info->sectorsize); in replay_one_buffer()
2477 drop_args.end = (u64)-1; in replay_one_buffer()
2479 ret = btrfs_drop_extents(wc->trans, root, inode, in replay_one_buffer()
2482 inode_sub_bytes(&inode->vfs_inode, in replay_one_buffer()
2485 ret = btrfs_update_inode(wc->trans, inode); in replay_one_buffer()
2487 iput(&inode->vfs_inode); in replay_one_buffer()
2492 ret = link_to_fixup_dir(wc->trans, root, in replay_one_buffer()
2498 if (wc->ignore_cur_inode) in replay_one_buffer()
2502 wc->stage == LOG_WALK_REPLAY_DIR_INDEX) { in replay_one_buffer()
2503 ret = replay_one_dir_item(wc->trans, root, path, in replay_one_buffer()
2509 if (wc->stage < LOG_WALK_REPLAY_ALL) in replay_one_buffer()
2514 ret = overwrite_item(wc->trans, root, path, in replay_one_buffer()
2520 ret = add_inode_ref(wc->trans, root, log, path, in replay_one_buffer()
2522 if (ret && ret != -ENOENT) in replay_one_buffer()
2526 ret = replay_one_extent(wc->trans, root, path, in replay_one_buffer()
2555 spin_lock(&cache->space_info->lock); in unaccount_log_buffer()
2556 spin_lock(&cache->lock); in unaccount_log_buffer()
2557 cache->reserved -= fs_info->nodesize; in unaccount_log_buffer()
2558 cache->space_info->bytes_reserved -= fs_info->nodesize; in unaccount_log_buffer()
2559 spin_unlock(&cache->lock); in unaccount_log_buffer()
2560 spin_unlock(&cache->space_info->lock); in unaccount_log_buffer()
2580 unaccount_log_buffer(eb->fs_info, eb->start); in clean_log_buffer()
2591 struct btrfs_fs_info *fs_info = root->fs_info; in walk_down_log_tree()
2601 cur = path->nodes[*level]; in walk_down_log_tree()
2605 if (path->slots[*level] >= in walk_down_log_tree()
2609 bytenr = btrfs_node_blockptr(cur, path->slots[*level]); in walk_down_log_tree()
2610 ptr_gen = btrfs_node_ptr_generation(cur, path->slots[*level]); in walk_down_log_tree()
2612 check.level = *level - 1; in walk_down_log_tree()
2614 btrfs_node_key_to_cpu(cur, &check.first_key, path->slots[*level]); in walk_down_log_tree()
2618 *level - 1); in walk_down_log_tree()
2623 ret = wc->process_func(root, next, wc, ptr_gen, in walk_down_log_tree()
2624 *level - 1); in walk_down_log_tree()
2630 path->slots[*level]++; in walk_down_log_tree()
2631 if (wc->free) { in walk_down_log_tree()
2653 if (path->nodes[*level-1]) in walk_down_log_tree()
2654 free_extent_buffer(path->nodes[*level-1]); in walk_down_log_tree()
2655 path->nodes[*level-1] = next; in walk_down_log_tree()
2657 path->slots[*level] = 0; in walk_down_log_tree()
2660 path->slots[*level] = btrfs_header_nritems(path->nodes[*level]); in walk_down_log_tree()
2675 for (i = *level; i < BTRFS_MAX_LEVEL - 1 && path->nodes[i]; i++) { in walk_up_log_tree()
2676 slot = path->slots[i]; in walk_up_log_tree()
2677 if (slot + 1 < btrfs_header_nritems(path->nodes[i])) { in walk_up_log_tree()
2678 path->slots[i]++; in walk_up_log_tree()
2683 ret = wc->process_func(root, path->nodes[*level], wc, in walk_up_log_tree()
2684 btrfs_header_generation(path->nodes[*level]), in walk_up_log_tree()
2689 if (wc->free) { in walk_up_log_tree()
2690 ret = clean_log_buffer(trans, path->nodes[*level]); in walk_up_log_tree()
2694 free_extent_buffer(path->nodes[*level]); in walk_up_log_tree()
2695 path->nodes[*level] = NULL; in walk_up_log_tree()
2718 return -ENOMEM; in walk_log_tree()
2720 level = btrfs_header_level(log->node); in walk_log_tree()
2722 path->nodes[level] = log->node; in walk_log_tree()
2723 atomic_inc(&log->node->refs); in walk_log_tree()
2724 path->slots[level] = 0; in walk_log_tree()
2745 if (path->nodes[orig_level]) { in walk_log_tree()
2746 ret = wc->process_func(log, path->nodes[orig_level], wc, in walk_log_tree()
2747 btrfs_header_generation(path->nodes[orig_level]), in walk_log_tree()
2751 if (wc->free) in walk_log_tree()
2752 ret = clean_log_buffer(trans, path->nodes[orig_level]); in walk_log_tree()
2768 struct btrfs_fs_info *fs_info = log->fs_info; in update_log_root()
2771 if (log->log_transid == 1) { in update_log_root()
2773 ret = btrfs_insert_root(trans, fs_info->log_root_tree, in update_log_root()
2774 &log->root_key, root_item); in update_log_root()
2776 ret = btrfs_update_root(trans, fs_info->log_root_tree, in update_log_root()
2777 &log->root_key, root_item); in update_log_root()
2793 prepare_to_wait(&root->log_commit_wait[index], in wait_log_commit()
2796 if (!(root->log_transid_committed < transid && in wait_log_commit()
2797 atomic_read(&root->log_commit[index]))) in wait_log_commit()
2800 mutex_unlock(&root->log_mutex); in wait_log_commit()
2802 mutex_lock(&root->log_mutex); in wait_log_commit()
2804 finish_wait(&root->log_commit_wait[index], &wait); in wait_log_commit()
2812 prepare_to_wait(&root->log_writer_wait, &wait, in wait_for_writer()
2814 if (!atomic_read(&root->log_writers)) in wait_for_writer()
2817 mutex_unlock(&root->log_mutex); in wait_for_writer()
2819 mutex_lock(&root->log_mutex); in wait_for_writer()
2821 finish_wait(&root->log_writer_wait, &wait); in wait_for_writer()
2826 ctx->log_ret = 0; in btrfs_init_log_ctx()
2827 ctx->log_transid = 0; in btrfs_init_log_ctx()
2828 ctx->log_new_dentries = false; in btrfs_init_log_ctx()
2829 ctx->logging_new_name = false; in btrfs_init_log_ctx()
2830 ctx->logging_new_delayed_dentries = false; in btrfs_init_log_ctx()
2831 ctx->logged_before = false; in btrfs_init_log_ctx()
2832 ctx->inode = inode; in btrfs_init_log_ctx()
2833 INIT_LIST_HEAD(&ctx->list); in btrfs_init_log_ctx()
2834 INIT_LIST_HEAD(&ctx->ordered_extents); in btrfs_init_log_ctx()
2835 INIT_LIST_HEAD(&ctx->conflict_inodes); in btrfs_init_log_ctx()
2836 ctx->num_conflict_inodes = 0; in btrfs_init_log_ctx()
2837 ctx->logging_conflict_inodes = false; in btrfs_init_log_ctx()
2838 ctx->scratch_eb = NULL; in btrfs_init_log_ctx()
2843 struct btrfs_inode *inode = ctx->inode; in btrfs_init_log_ctx_scratch_eb()
2845 if (!test_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &inode->runtime_flags) && in btrfs_init_log_ctx_scratch_eb()
2846 !test_bit(BTRFS_INODE_COPY_EVERYTHING, &inode->runtime_flags)) in btrfs_init_log_ctx_scratch_eb()
2853 ctx->scratch_eb = alloc_dummy_extent_buffer(inode->root->fs_info, 0); in btrfs_init_log_ctx_scratch_eb()
2861 btrfs_assert_inode_locked(ctx->inode); in btrfs_release_log_ctx_extents()
2863 list_for_each_entry_safe(ordered, tmp, &ctx->ordered_extents, log_list) { in btrfs_release_log_ctx_extents()
2864 list_del_init(&ordered->log_list); in btrfs_release_log_ctx_extents()
2873 mutex_lock(&root->log_mutex); in btrfs_remove_log_ctx()
2874 list_del_init(&ctx->list); in btrfs_remove_log_ctx()
2875 mutex_unlock(&root->log_mutex); in btrfs_remove_log_ctx()
2888 list_for_each_entry_safe(ctx, safe, &root->log_ctxs[index], list) { in btrfs_remove_all_log_ctxs()
2889 list_del_init(&ctx->list); in btrfs_remove_all_log_ctxs()
2890 ctx->log_ret = error; in btrfs_remove_all_log_ctxs()
2902 * fsync is to commit the whole FS. When btrfs_sync_log returns -EAGAIN,
2912 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_sync_log()
2913 struct btrfs_root *log = root->log_root; in btrfs_sync_log()
2914 struct btrfs_root *log_root_tree = fs_info->log_root_tree; in btrfs_sync_log()
2922 mutex_lock(&root->log_mutex); in btrfs_sync_log()
2923 log_transid = ctx->log_transid; in btrfs_sync_log()
2924 if (root->log_transid_committed >= log_transid) { in btrfs_sync_log()
2925 mutex_unlock(&root->log_mutex); in btrfs_sync_log()
2926 return ctx->log_ret; in btrfs_sync_log()
2930 if (atomic_read(&root->log_commit[index1])) { in btrfs_sync_log()
2932 mutex_unlock(&root->log_mutex); in btrfs_sync_log()
2933 return ctx->log_ret; in btrfs_sync_log()
2935 ASSERT(log_transid == root->log_transid); in btrfs_sync_log()
2936 atomic_set(&root->log_commit[index1], 1); in btrfs_sync_log()
2939 if (atomic_read(&root->log_commit[(index1 + 1) % 2])) in btrfs_sync_log()
2940 wait_log_commit(root, log_transid - 1); in btrfs_sync_log()
2943 int batch = atomic_read(&root->log_batch); in btrfs_sync_log()
2946 test_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state)) { in btrfs_sync_log()
2947 mutex_unlock(&root->log_mutex); in btrfs_sync_log()
2949 mutex_lock(&root->log_mutex); in btrfs_sync_log()
2952 if (batch == atomic_read(&root->log_batch)) in btrfs_sync_log()
2959 mutex_unlock(&root->log_mutex); in btrfs_sync_log()
2972 ret = btrfs_write_marked_extents(fs_info, &log->dirty_log_pages, mark); in btrfs_sync_log()
2974 * -EAGAIN happens when someone, e.g., a concurrent transaction in btrfs_sync_log()
2975 * commit, writes a dirty extent in this tree-log commit. This in btrfs_sync_log()
2982 if (ret == -EAGAIN && btrfs_is_zoned(fs_info)) in btrfs_sync_log()
2987 mutex_unlock(&root->log_mutex); in btrfs_sync_log()
2992 * We _must_ update under the root->log_mutex in order to make sure we in btrfs_sync_log()
2997 * log_root_tree->log_mutex yet. This is important because when we in btrfs_sync_log()
3004 btrfs_set_root_node(&log->root_item, log->node); in btrfs_sync_log()
3005 memcpy(&new_root_item, &log->root_item, sizeof(new_root_item)); in btrfs_sync_log()
3007 btrfs_set_root_log_transid(root, root->log_transid + 1); in btrfs_sync_log()
3008 log->log_transid = root->log_transid; in btrfs_sync_log()
3009 root->log_start_pid = 0; in btrfs_sync_log()
3015 mutex_unlock(&root->log_mutex); in btrfs_sync_log()
3018 mutex_lock(&fs_info->tree_root->log_mutex); in btrfs_sync_log()
3019 if (!log_root_tree->node) { in btrfs_sync_log()
3022 mutex_unlock(&fs_info->tree_root->log_mutex); in btrfs_sync_log()
3027 mutex_unlock(&fs_info->tree_root->log_mutex); in btrfs_sync_log()
3032 mutex_lock(&log_root_tree->log_mutex); in btrfs_sync_log()
3034 index2 = log_root_tree->log_transid % 2; in btrfs_sync_log()
3035 list_add_tail(&root_log_ctx.list, &log_root_tree->log_ctxs[index2]); in btrfs_sync_log()
3036 root_log_ctx.log_transid = log_root_tree->log_transid; in btrfs_sync_log()
3048 if (ret != -ENOSPC) in btrfs_sync_log()
3053 mutex_unlock(&log_root_tree->log_mutex); in btrfs_sync_log()
3057 if (log_root_tree->log_transid_committed >= root_log_ctx.log_transid) { in btrfs_sync_log()
3060 mutex_unlock(&log_root_tree->log_mutex); in btrfs_sync_log()
3065 if (atomic_read(&log_root_tree->log_commit[index2])) { in btrfs_sync_log()
3070 mutex_unlock(&log_root_tree->log_mutex); in btrfs_sync_log()
3075 ASSERT(root_log_ctx.log_transid == log_root_tree->log_transid); in btrfs_sync_log()
3076 atomic_set(&log_root_tree->log_commit[index2], 1); in btrfs_sync_log()
3078 if (atomic_read(&log_root_tree->log_commit[(index2 + 1) % 2])) { in btrfs_sync_log()
3080 root_log_ctx.log_transid - 1); in btrfs_sync_log()
3090 mutex_unlock(&log_root_tree->log_mutex); in btrfs_sync_log()
3096 &log_root_tree->dirty_log_pages, in btrfs_sync_log()
3100 * As described above, -EAGAIN indicates a hole in the extents. We in btrfs_sync_log()
3104 if (ret == -EAGAIN && btrfs_is_zoned(fs_info)) { in btrfs_sync_log()
3107 mutex_unlock(&log_root_tree->log_mutex); in btrfs_sync_log()
3111 mutex_unlock(&log_root_tree->log_mutex); in btrfs_sync_log()
3120 mutex_unlock(&log_root_tree->log_mutex); in btrfs_sync_log()
3124 log_root_start = log_root_tree->node->start; in btrfs_sync_log()
3125 log_root_level = btrfs_header_level(log_root_tree->node); in btrfs_sync_log()
3126 log_root_tree->log_transid++; in btrfs_sync_log()
3127 mutex_unlock(&log_root_tree->log_mutex); in btrfs_sync_log()
3144 mutex_lock(&fs_info->tree_log_mutex); in btrfs_sync_log()
3154 ret = -EIO; in btrfs_sync_log()
3157 mutex_unlock(&fs_info->tree_log_mutex); in btrfs_sync_log()
3161 btrfs_set_super_log_root(fs_info->super_for_commit, log_root_start); in btrfs_sync_log()
3162 btrfs_set_super_log_root_level(fs_info->super_for_commit, log_root_level); in btrfs_sync_log()
3164 mutex_unlock(&fs_info->tree_log_mutex); in btrfs_sync_log()
3173 * root->log_commit[index1] to 0 and any task attempting to sync the in btrfs_sync_log()
3183 mutex_lock(&log_root_tree->log_mutex); in btrfs_sync_log()
3186 log_root_tree->log_transid_committed++; in btrfs_sync_log()
3187 atomic_set(&log_root_tree->log_commit[index2], 0); in btrfs_sync_log()
3188 mutex_unlock(&log_root_tree->log_mutex); in btrfs_sync_log()
3195 cond_wake_up(&log_root_tree->log_commit_wait[index2]); in btrfs_sync_log()
3197 mutex_lock(&root->log_mutex); in btrfs_sync_log()
3199 root->log_transid_committed++; in btrfs_sync_log()
3200 atomic_set(&root->log_commit[index1], 0); in btrfs_sync_log()
3201 mutex_unlock(&root->log_mutex); in btrfs_sync_log()
3208 cond_wake_up(&root->log_commit_wait[index1]); in btrfs_sync_log()
3221 if (log->node) { in free_log_tree()
3226 * typical scenario is getting an -EIO when reading an in free_log_tree()
3231 &log->fs_info->fs_state); in free_log_tree()
3241 btrfs_write_marked_extents(log->fs_info, in free_log_tree()
3242 &log->dirty_log_pages, in free_log_tree()
3250 btrfs_handle_fs_error(log->fs_info, ret, NULL); in free_log_tree()
3254 btrfs_extent_io_tree_release(&log->dirty_log_pages); in free_log_tree()
3255 btrfs_extent_io_tree_release(&log->log_csum_range); in free_log_tree()
3266 if (root->log_root) { in btrfs_free_log()
3267 free_log_tree(trans, root->log_root); in btrfs_free_log()
3268 root->log_root = NULL; in btrfs_free_log()
3269 clear_bit(BTRFS_ROOT_HAS_LOG_TREE, &root->state); in btrfs_free_log()
3277 if (fs_info->log_root_tree) { in btrfs_free_log_root_tree()
3278 free_log_tree(trans, fs_info->log_root_tree); in btrfs_free_log_root_tree()
3279 fs_info->log_root_tree = NULL; in btrfs_free_log_root_tree()
3280 clear_bit(BTRFS_ROOT_HAS_LOG_TREE, &fs_info->tree_root->state); in btrfs_free_log_root_tree()
3302 if (inode->logged_trans == trans->transid) in inode_logged()
3309 if (inode->logged_trans > 0) in inode_logged()
3319 if (!test_bit(BTRFS_ROOT_HAS_LOG_TREE, &inode->root->state)) { in inode_logged()
3320 inode->logged_trans = trans->transid - 1; in inode_logged()
3355 return -ENOMEM; in inode_logged()
3358 ret = btrfs_search_slot(NULL, inode->root->log_root, &key, path, 0, 0); in inode_logged()
3376 inode->logged_trans = trans->transid - 1; in inode_logged()
3385 inode->logged_trans = trans->transid; in inode_logged()
3393 * because last_dir_index_offset is an in-memory only field, not persisted in inode_logged()
3394 * in the inode item or any other on-disk structure, so its value is lost in inode_logged()
3397 if (S_ISDIR(inode->vfs_inode.i_mode)) in inode_logged()
3398 inode->last_dir_index_offset = (u64)-1; in inode_logged()
3424 index, name, -1); in del_logged_dentry()
3479 mutex_lock(&dir->log_mutex); in btrfs_del_dir_entries_in_log()
3483 ret = -ENOMEM; in btrfs_del_dir_entries_in_log()
3487 ret = del_logged_dentry(trans, root->log_root, path, btrfs_ino(dir), in btrfs_del_dir_entries_in_log()
3491 mutex_unlock(&dir->log_mutex); in btrfs_del_dir_entries_in_log()
3518 log = root->log_root; in btrfs_del_inode_ref_in_log()
3519 mutex_lock(&inode->log_mutex); in btrfs_del_inode_ref_in_log()
3523 mutex_unlock(&inode->log_mutex); in btrfs_del_inode_ref_in_log()
3524 if (ret < 0 && ret != -ENOENT) in btrfs_del_inode_ref_in_log()
3549 * -EEXIST is fine and can happen sporadically when we are logging a in insert_dir_log_key()
3555 if (ret && ret != -EEXIST) in insert_dir_log_key()
3558 item = btrfs_item_ptr(path->nodes[0], path->slots[0], in insert_dir_log_key()
3560 if (ret == -EEXIST) { in insert_dir_log_key()
3561 const u64 curr_end = btrfs_dir_log_end(path->nodes[0], item); in insert_dir_log_key()
3571 btrfs_set_dir_log_end(path->nodes[0], item, last_offset); in insert_dir_log_key()
3583 struct btrfs_root *log = inode->root->log_root; in flush_dir_items_batch()
3611 return -ENOMEM; in flush_dir_items_batch()
3632 dst = dst_path->nodes[0]; in flush_dir_items_batch()
3643 dst_offset = btrfs_item_ptr_offset(dst, dst_path->slots[0] + count - 1); in flush_dir_items_batch()
3644 src_offset = btrfs_item_ptr_offset(src, start_slot + count - 1); in flush_dir_items_batch()
3648 last_index = batch.keys[count - 1].offset; in flush_dir_items_batch()
3649 ASSERT(last_index > inode->last_dir_index_offset); in flush_dir_items_batch()
3655 if (WARN_ON(last_index <= inode->last_dir_index_offset)) in flush_dir_items_batch()
3658 inode->last_dir_index_offset = last_index; in flush_dir_items_batch()
3670 const int slot = path->slots[0]; in clone_leaf()
3672 if (ctx->scratch_eb) { in clone_leaf()
3673 copy_extent_buffer_full(ctx->scratch_eb, path->nodes[0]); in clone_leaf()
3675 ctx->scratch_eb = btrfs_clone_extent_buffer(path->nodes[0]); in clone_leaf()
3676 if (!ctx->scratch_eb) in clone_leaf()
3677 return -ENOMEM; in clone_leaf()
3681 path->nodes[0] = ctx->scratch_eb; in clone_leaf()
3682 path->slots[0] = slot; in clone_leaf()
3687 atomic_inc(&ctx->scratch_eb->refs); in clone_leaf()
3699 struct btrfs_root *log = inode->root->log_root; in process_dir_items_leaf()
3701 const int nritems = btrfs_header_nritems(path->nodes[0]); in process_dir_items_leaf()
3717 src = path->nodes[0]; in process_dir_items_leaf()
3719 for (int i = path->slots[0]; i < nritems; i++) { in process_dir_items_leaf()
3739 if (btrfs_dir_transid(src, di) < trans->transid) { in process_dir_items_leaf()
3743 key.offset - 1); in process_dir_items_leaf()
3753 if (key.offset <= inode->last_dir_index_offset) in process_dir_items_leaf()
3761 * touch foo in process_dir_items_leaf()
3765 * xfs_io -c "fsync" mydir in process_dir_items_leaf()
3776 * resulting in -ENOTEMPTY errors. in process_dir_items_leaf()
3778 if (!ctx->log_new_dentries) { in process_dir_items_leaf()
3783 ctx->log_new_dentries = true; in process_dir_items_leaf()
3816 struct btrfs_root *root = inode->root; in log_dir_items()
3817 struct btrfs_root *log = root->log_root; in log_dir_items()
3819 u64 last_old_dentry_offset = min_offset - 1; in log_dir_items()
3820 u64 last_offset = (u64)-1; in log_dir_items()
3827 ret = btrfs_search_forward(root, &min_key, path, trans->transid); in log_dir_items()
3837 min_key.offset = (u64)-1; in log_dir_items()
3854 btrfs_item_key_to_cpu(path->nodes[0], &tmp, in log_dir_items()
3855 path->slots[0]); in log_dir_items()
3870 btrfs_item_key_to_cpu(path->nodes[0], &tmp, path->slots[0]); in log_dir_items()
3897 * and we can end up logging a dir index range that ends at (u64)-1 in log_dir_items()
3926 path->slots[0] = btrfs_header_nritems(path->nodes[0]); in log_dir_items()
3935 last_offset = (u64)-1; in log_dir_items()
3940 btrfs_item_key_to_cpu(path->nodes[0], &min_key, path->slots[0]); in log_dir_items()
3942 last_offset = (u64)-1; in log_dir_items()
3945 if (btrfs_header_generation(path->nodes[0]) != trans->transid) { in log_dir_items()
3955 last_offset = min_key.offset - 1; in log_dir_items()
3990 * last_dir_index_offset is (u64)-1, so we don't the value of the last index
4004 lockdep_assert_held(&inode->log_mutex); in update_last_dir_index_offset()
4006 if (inode->last_dir_index_offset != (u64)-1) in update_last_dir_index_offset()
4009 if (!ctx->logged_before) { in update_last_dir_index_offset()
4010 inode->last_dir_index_offset = BTRFS_DIR_START_INDEX - 1; in update_last_dir_index_offset()
4016 key.offset = (u64)-1; in update_last_dir_index_offset()
4018 ret = btrfs_search_slot(NULL, inode->root->log_root, &key, path, 0, 0); in update_last_dir_index_offset()
4021 * value of (u64)-1. Bail out, we're done. in update_last_dir_index_offset()
4027 inode->last_dir_index_offset = BTRFS_DIR_START_INDEX - 1; in update_last_dir_index_offset()
4033 if (path->slots[0] == 0) in update_last_dir_index_offset()
4043 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0] - 1); in update_last_dir_index_offset()
4045 inode->last_dir_index_offset = key.offset; in update_last_dir_index_offset()
4087 if (max_key == (u64)-1) in log_directory_changes()
4114 key.offset = (u64)-1; in drop_inode_items()
4117 ret = btrfs_search_slot(trans, log, &key, path, -1, 1); in drop_inode_items()
4121 if (path->slots[0] == 0) in drop_inode_items()
4123 path->slots[0]--; in drop_inode_items()
4126 btrfs_item_key_to_cpu(path->nodes[0], &found_key, in drop_inode_items()
4127 path->slots[0]); in drop_inode_items()
4134 ret = btrfs_bin_search(path->nodes[0], 0, &found_key, &start_slot); in drop_inode_items()
4139 path->slots[0] - start_slot + 1); in drop_inode_items()
4141 * If start slot isn't 0 then we don't need to re-search, we've in drop_inode_items()
4190 BTRFS_I(inode)->generation); in fill_inode_item()
4191 btrfs_set_token_inode_size(&token, item, inode->i_size); in fill_inode_item()
4196 btrfs_set_token_inode_mode(&token, item, inode->i_mode); in fill_inode_item()
4197 btrfs_set_token_inode_nlink(&token, item, inode->i_nlink); in fill_inode_item()
4199 btrfs_set_token_timespec_sec(&token, &item->atime, in fill_inode_item()
4201 btrfs_set_token_timespec_nsec(&token, &item->atime, in fill_inode_item()
4204 btrfs_set_token_timespec_sec(&token, &item->mtime, in fill_inode_item()
4206 btrfs_set_token_timespec_nsec(&token, &item->mtime, in fill_inode_item()
4209 btrfs_set_token_timespec_sec(&token, &item->ctime, in fill_inode_item()
4211 btrfs_set_token_timespec_nsec(&token, &item->ctime, in fill_inode_item()
4224 btrfs_set_token_inode_transid(&token, item, trans->transid); in fill_inode_item()
4225 btrfs_set_token_inode_rdev(&token, item, inode->i_rdev); in fill_inode_item()
4226 flags = btrfs_inode_combine_flags(BTRFS_I(inode)->flags, in fill_inode_item()
4227 BTRFS_I(inode)->ro_flags); in fill_inode_item()
4251 if (!inode_item_dropped && inode->logged_trans == trans->transid) { in log_inode_item()
4255 ret = -ENOENT; in log_inode_item()
4260 * We can never get -EEXIST because we are only called for a fast in log_inode_item()
4264 * flags and set ->logged_trans to 0. in log_inode_item()
4268 ASSERT(ret != -EEXIST); in log_inode_item()
4272 inode_item = btrfs_item_ptr(path->nodes[0], path->slots[0], in log_inode_item()
4274 fill_inode_item(trans, path->nodes[0], inode_item, &inode->vfs_inode, in log_inode_item()
4285 const u64 lock_end = sums->logical + sums->len - 1; in log_csums()
4294 if (inode->last_reflink_trans < trans->transid) in log_csums()
4303 ret = btrfs_lock_extent(&log_root->log_csum_range, sums->logical, lock_end, in log_csums()
4316 ret = btrfs_del_csums(trans, log_root, sums->logical, sums->len); in log_csums()
4320 btrfs_unlock_extent(&log_root->log_csum_range, sums->logical, lock_end, in log_csums()
4333 struct btrfs_root *log = inode->root->log_root; in copy_items()
4342 const bool skip_csum = (inode->flags & BTRFS_INODE_NODATASUM); in copy_items()
4343 const u64 i_size = i_size_read(&inode->vfs_inode); in copy_items()
4364 * buffers of a subvolume tree - all this while holding a write lock in copy_items()
4377 src = src_path->nodes[0]; in copy_items()
4382 return -ENOMEM; in copy_items()
4413 trans->transid); in copy_items()
4421 * generations, so we can skip them - as long as the inode has in copy_items()
4430 inode->last_reflink_trans < trans->transid) in copy_items()
4463 csum_root = btrfs_csum_root(trans->fs_info, disk_bytenr); in copy_items()
4466 disk_bytenr + extent_num_bytes - 1, in copy_items()
4475 list_del(&sums->list); in copy_items()
4502 const int dst_slot = dst_path->slots[0] + dst_index; in copy_items()
4523 if (btrfs_file_extent_generation(src, extent) < trans->transid && in copy_items()
4525 inode->last_reflink_trans < trans->transid) in copy_items()
4529 dst_offset = btrfs_item_ptr_offset(dst_path->nodes[0], dst_slot); in copy_items()
4535 inode_item = btrfs_item_ptr(dst_path->nodes[0], dst_slot, in copy_items()
4537 fill_inode_item(trans, dst_path->nodes[0], inode_item, in copy_items()
4538 &inode->vfs_inode, in copy_items()
4542 copy_extent_buffer(dst_path->nodes[0], src, dst_offset, in copy_items()
4564 if (em1->start < em2->start) in extent_cmp()
4565 return -1; in extent_cmp()
4566 else if (em1->start > em2->start) in extent_cmp()
4582 u64 mod_start = em->start; in log_extent_csums()
4583 u64 mod_len = em->len; in log_extent_csums()
4587 if (inode->flags & BTRFS_INODE_NODATASUM || in log_extent_csums()
4588 (em->flags & EXTENT_FLAG_PREALLOC) || in log_extent_csums()
4589 em->disk_bytenr == EXTENT_MAP_HOLE) in log_extent_csums()
4592 list_for_each_entry(ordered, &ctx->ordered_extents, log_list) { in log_extent_csums()
4593 const u64 ordered_end = ordered->file_offset + ordered->num_bytes; in log_extent_csums()
4602 if (mod_end <= ordered->file_offset) in log_extent_csums()
4610 if (ordered->file_offset > mod_start) { in log_extent_csums()
4612 mod_len = ordered->file_offset - mod_start; in log_extent_csums()
4616 * |--------- logged extent ---------| in log_extent_csums()
4617 * |----- ordered extent ----| in log_extent_csums()
4625 mod_len = mod_end - ordered_end; in log_extent_csums()
4636 if (test_and_set_bit(BTRFS_ORDERED_LOGGED_CSUM, &ordered->flags)) in log_extent_csums()
4639 list_for_each_entry(sums, &ordered->list, list) { in log_extent_csums()
4653 csum_len = em->disk_num_bytes; in log_extent_csums()
4655 csum_offset = mod_start - em->start; in log_extent_csums()
4661 csum_root = btrfs_csum_root(trans->fs_info, block_start); in log_extent_csums()
4663 block_start + csum_offset + csum_len - 1, in log_extent_csums()
4675 list_del(&sums->list); in log_extent_csums()
4689 struct btrfs_root *log = inode->root->log_root; in log_one_extent()
4694 u64 extent_offset = em->offset; in log_one_extent()
4699 btrfs_set_stack_file_extent_generation(&fi, trans->transid); in log_one_extent()
4700 if (em->flags & EXTENT_FLAG_PREALLOC) in log_one_extent()
4705 block_len = em->disk_num_bytes; in log_one_extent()
4710 } else if (em->disk_bytenr < EXTENT_MAP_LAST_BYTE) { in log_one_extent()
4711 btrfs_set_stack_file_extent_disk_bytenr(&fi, block_start - extent_offset); in log_one_extent()
4716 btrfs_set_stack_file_extent_num_bytes(&fi, em->len); in log_one_extent()
4717 btrfs_set_stack_file_extent_ram_bytes(&fi, em->ram_bytes); in log_one_extent()
4733 if (ctx->logged_before) { in log_one_extent()
4735 drop_args.start = em->start; in log_one_extent()
4736 drop_args.end = em->start + em->len; in log_one_extent()
4747 key.offset = em->start; in log_one_extent()
4754 leaf = path->nodes[0]; in log_one_extent()
4756 btrfs_item_ptr_offset(leaf, path->slots[0]), in log_one_extent()
4777 struct btrfs_root *root = inode->root; in btrfs_log_prealloc_extents()
4779 const u64 i_size = i_size_read(&inode->vfs_inode); in btrfs_log_prealloc_extents()
4790 if (!(inode->flags & BTRFS_INODE_PREALLOC)) in btrfs_log_prealloc_extents()
4815 leaf = path->nodes[0]; in btrfs_log_prealloc_extents()
4816 slot = path->slots[0]; in btrfs_log_prealloc_extents()
4835 leaf = path->nodes[0]; in btrfs_log_prealloc_extents()
4836 slot = path->slots[0]; in btrfs_log_prealloc_extents()
4862 path->slots[0]++; in btrfs_log_prealloc_extents()
4874 ret = truncate_inode_items(trans, root->log_root, inode, in btrfs_log_prealloc_extents()
4885 path->slots[0]++; in btrfs_log_prealloc_extents()
4889 ret = -ENOMEM; in btrfs_log_prealloc_extents()
4912 struct extent_map_tree *tree = &inode->extent_tree; in btrfs_log_changed_extents()
4916 write_lock(&tree->lock); in btrfs_log_changed_extents()
4918 list_for_each_entry_safe(em, n, &tree->modified_extents, list) { in btrfs_log_changed_extents()
4919 list_del_init(&em->list); in btrfs_log_changed_extents()
4927 list_del_init(&tree->modified_extents); in btrfs_log_changed_extents()
4928 ret = -EFBIG; in btrfs_log_changed_extents()
4932 if (em->generation < trans->transid) in btrfs_log_changed_extents()
4936 if ((em->flags & EXTENT_FLAG_PREALLOC) && in btrfs_log_changed_extents()
4937 em->start >= i_size_read(&inode->vfs_inode)) in btrfs_log_changed_extents()
4941 refcount_inc(&em->refs); in btrfs_log_changed_extents()
4942 em->flags |= EXTENT_FLAG_LOGGING; in btrfs_log_changed_extents()
4943 list_add_tail(&em->list, &extents); in btrfs_log_changed_extents()
4952 list_del_init(&em->list); in btrfs_log_changed_extents()
4964 write_unlock(&tree->lock); in btrfs_log_changed_extents()
4967 write_lock(&tree->lock); in btrfs_log_changed_extents()
4972 write_unlock(&tree->lock); in btrfs_log_changed_extents()
4986 list_for_each_entry_safe(ordered, tmp, &ctx->ordered_extents, log_list) { in btrfs_log_changed_extents()
4987 list_del_init(&ordered->log_list); in btrfs_log_changed_extents()
4988 set_bit(BTRFS_ORDERED_LOGGED, &ordered->flags); in btrfs_log_changed_extents()
4990 if (!test_bit(BTRFS_ORDERED_COMPLETE, &ordered->flags)) { in btrfs_log_changed_extents()
4991 spin_lock_irq(&inode->ordered_tree_lock); in btrfs_log_changed_extents()
4992 if (!test_bit(BTRFS_ORDERED_COMPLETE, &ordered->flags)) { in btrfs_log_changed_extents()
4993 set_bit(BTRFS_ORDERED_PENDING, &ordered->flags); in btrfs_log_changed_extents()
4994 atomic_inc(&trans->transaction->pending_ordered); in btrfs_log_changed_extents()
4996 spin_unlock_irq(&inode->ordered_tree_lock); in btrfs_log_changed_extents()
5022 item = btrfs_item_ptr(path->nodes[0], path->slots[0], in logged_inode_size()
5024 *size_ret = btrfs_inode_size(path->nodes[0], item); in logged_inode_size()
5026 * If the in-memory inode's i_size is smaller then the inode in logged_inode_size()
5036 if (*size_ret > inode->vfs_inode.i_size) in logged_inode_size()
5037 *size_ret = inode->vfs_inode.i_size; in logged_inode_size()
5059 struct btrfs_root *root = inode->root; in btrfs_log_all_xattrs()
5067 if (test_bit(BTRFS_INODE_NO_XATTRS, &inode->runtime_flags)) in btrfs_log_all_xattrs()
5079 int slot = path->slots[0]; in btrfs_log_all_xattrs()
5080 struct extent_buffer *leaf = path->nodes[0]; in btrfs_log_all_xattrs()
5106 path->slots[0]++; in btrfs_log_all_xattrs()
5118 set_bit(BTRFS_INODE_NO_XATTRS, &inode->runtime_flags); in btrfs_log_all_xattrs()
5136 struct btrfs_root *root = inode->root; in btrfs_log_holes()
5137 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_log_holes()
5140 const u64 i_size = i_size_read(&inode->vfs_inode); in btrfs_log_holes()
5156 struct extent_buffer *leaf = path->nodes[0]; in btrfs_log_holes()
5158 if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) { in btrfs_log_holes()
5166 leaf = path->nodes[0]; in btrfs_log_holes()
5169 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); in btrfs_log_holes()
5175 const u64 hole_len = key.offset - prev_extent_end; in btrfs_log_holes()
5183 ret = btrfs_insert_hole_extent(trans, root->log_root, in btrfs_log_holes()
5200 return -ENOENT; in btrfs_log_holes()
5201 leaf = path->nodes[0]; in btrfs_log_holes()
5205 path->slots[0]++; in btrfs_log_holes()
5213 hole_len = ALIGN(i_size - prev_extent_end, fs_info->sectorsize); in btrfs_log_holes()
5214 ret = btrfs_insert_hole_extent(trans, root->log_root, ino, in btrfs_log_holes()
5233 * mkdir /mnt/x # or touch /mnt/x
5234 * xfs_io -c fsync /mnt/x
5246 * xfs_io -c fsync /mnt/foo
5281 return -ENOMEM; in btrfs_check_ref_name_override()
5282 search_path->search_commit_root = 1; in btrfs_check_ref_name_override()
5283 search_path->skip_locking = 1; in btrfs_check_ref_name_override()
5293 if (key->type == BTRFS_INODE_REF_KEY) { in btrfs_check_ref_name_override()
5297 parent = key->offset; in btrfs_check_ref_name_override()
5308 name_ptr = (unsigned long)&extref->name; in btrfs_check_ref_name_override()
5317 ret = -ENOMEM; in btrfs_check_ref_name_override()
5328 di = btrfs_lookup_dir_item(NULL, inode->root, search_path, in btrfs_check_ref_name_override()
5333 btrfs_dir_item_key_to_cpu(search_path->nodes[0], in btrfs_check_ref_name_override()
5336 if (di_key.objectid != key->objectid) { in btrfs_check_ref_name_override()
5344 ret = -EAGAIN; in btrfs_check_ref_name_override()
5367 * while here we do not care if the log transaction was already committed - our
5368 * caller will commit the log later - and we want to avoid logging an inode
5378 if (S_ISDIR(inode->vfs_inode.i_mode) && inode->last_trans < trans->transid) in need_log_inode()
5391 !test_bit(BTRFS_INODE_COPY_EVERYTHING, &inode->runtime_flags)) in need_log_inode()
5405 * This is a recursive operation - if an existing dentry corresponds to a
5412 * ---- ----
5413 * lock(&type->i_mutex_dir_key#3/2);
5415 * lock(&type->i_mutex_dir_key#3/2);
5416 * lock(&sb->s_type->i_mutex_key#14);
5434 * names - this is ok, not a problem, because at log replay time we set the
5442 struct btrfs_root *root = start_inode->root; in log_new_dir_dentries()
5455 if (ctx->logging_new_name) in log_new_dir_dentries()
5460 return -ENOMEM; in log_new_dir_dentries()
5463 ihold(&curr_inode->vfs_inode); in log_new_dir_dentries()
5477 btrfs_for_each_slot(root->log_root, &key, &found_key, path, iter_ret) { in log_new_dir_dentries()
5478 struct extent_buffer *leaf = path->nodes[0]; in log_new_dir_dentries()
5493 di = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dir_item); in log_new_dir_dentries()
5495 if (btrfs_dir_transid(leaf, di) < trans->transid) in log_new_dir_dentries()
5513 ctx->log_new_dentries = false; in log_new_dir_dentries()
5520 if (ctx->log_new_dentries) { in log_new_dir_dentries()
5523 ret = -ENOMEM; in log_new_dir_dentries()
5526 dir_elem->ino = di_key.objectid; in log_new_dir_dentries()
5527 list_add_tail(&dir_elem->list, &dir_list); in log_new_dir_dentries()
5543 if (continue_curr_inode && key.offset < (u64)-1) { in log_new_dir_dentries()
5554 ino = dir_elem->ino; in log_new_dir_dentries()
5555 list_del(&dir_elem->list); in log_new_dir_dentries()
5593 list_for_each_entry_safe(curr, next, &ctx->conflict_inodes, list) { in free_conflicting_inodes()
5594 list_del(&curr->list); in free_conflicting_inodes()
5609 path->search_commit_root = 1; in conflicting_inode_is_dir()
5610 path->skip_locking = 1; in conflicting_inode_is_dir()
5619 ret = -ENOENT; in conflicting_inode_is_dir()
5623 item = btrfs_item_ptr(path->nodes[0], path->slots[0], in conflicting_inode_is_dir()
5625 if (S_ISDIR(btrfs_inode_mode(path->nodes[0], item))) in conflicting_inode_is_dir()
5630 path->search_commit_root = 0; in conflicting_inode_is_dir()
5631 path->skip_locking = 0; in conflicting_inode_is_dir()
5652 if (ctx->num_conflict_inodes >= MAX_CONFLICT_INODES) in add_conflicting_inode()
5673 * case it has a last_unlink_trans == trans->transid, due to moving in add_conflicting_inode()
5679 if (ret != -ENOENT) in add_conflicting_inode()
5690 return -ENOMEM; in add_conflicting_inode()
5691 ino_elem->ino = ino; in add_conflicting_inode()
5692 ino_elem->parent = parent; in add_conflicting_inode()
5693 list_add_tail(&ino_elem->list, &ctx->conflict_inodes); in add_conflicting_inode()
5694 ctx->num_conflict_inodes++; in add_conflicting_inode()
5700 * If the inode was already logged skip it - otherwise we can hit an in add_conflicting_inode()
5720 * - we detect inode 258 as a conflicting inode, with inode 261 in add_conflicting_inode()
5723 * - we detect inode 259 as a conflicting inode, with inode 258 in add_conflicting_inode()
5726 * - we detect inode 258 as a conflicting inode, with inode 259 in add_conflicting_inode()
5727 * on reference "zz_link", and log it - again! After this we in add_conflicting_inode()
5743 return -ENOMEM; in add_conflicting_inode()
5744 ino_elem->ino = ino; in add_conflicting_inode()
5745 ino_elem->parent = parent; in add_conflicting_inode()
5746 list_add_tail(&ino_elem->list, &ctx->conflict_inodes); in add_conflicting_inode()
5747 ctx->num_conflict_inodes++; in add_conflicting_inode()
5763 if (ctx->logging_conflict_inodes) in log_conflicting_inodes()
5766 ctx->logging_conflict_inodes = true; in log_conflicting_inodes()
5773 while (!list_empty(&ctx->conflict_inodes)) { in log_conflicting_inodes()
5779 curr = list_first_entry(&ctx->conflict_inodes, in log_conflicting_inodes()
5781 ino = curr->ino; in log_conflicting_inodes()
5782 parent = curr->parent; in log_conflicting_inodes()
5783 list_del(&curr->list); in log_conflicting_inodes()
5794 if (ret != -ENOENT) in log_conflicting_inodes()
5846 ctx->logging_conflict_inodes = false; in log_conflicting_inodes()
5864 const u64 i_size = i_size_read(&inode->vfs_inode); in copy_inode_items_to_log()
5865 struct btrfs_root *root = inode->root; in copy_inode_items_to_log()
5871 ret = btrfs_search_forward(root, min_key, path, trans->transid); in copy_inode_items_to_log()
5880 if (min_key->objectid != max_key->objectid) in copy_inode_items_to_log()
5882 if (min_key->type > max_key->type) in copy_inode_items_to_log()
5885 if (min_key->type == BTRFS_INODE_ITEM_KEY) { in copy_inode_items_to_log()
5887 } else if (min_key->type == BTRFS_EXTENT_DATA_KEY && in copy_inode_items_to_log()
5888 min_key->offset >= i_size) { in copy_inode_items_to_log()
5896 } else if ((min_key->type == BTRFS_INODE_REF_KEY || in copy_inode_items_to_log()
5897 min_key->type == BTRFS_INODE_EXTREF_KEY) && in copy_inode_items_to_log()
5898 (inode->generation == trans->transid || in copy_inode_items_to_log()
5899 ctx->logging_conflict_inodes)) { in copy_inode_items_to_log()
5903 ret = btrfs_check_ref_name_override(path->nodes[0], in copy_inode_items_to_log()
5904 path->slots[0], min_key, inode, in copy_inode_items_to_log()
5909 other_ino != btrfs_ino(ctx->inode)) { in copy_inode_items_to_log()
5914 ins_start_slot = path->slots[0]; in copy_inode_items_to_log()
5931 } else if (min_key->type == BTRFS_XATTR_ITEM_KEY) { in copy_inode_items_to_log()
5944 if (ins_nr && ins_start_slot + ins_nr == path->slots[0]) { in copy_inode_items_to_log()
5948 ins_start_slot = path->slots[0]; in copy_inode_items_to_log()
5958 ins_start_slot = path->slots[0]; in copy_inode_items_to_log()
5960 path->slots[0]++; in copy_inode_items_to_log()
5961 if (path->slots[0] < btrfs_header_nritems(path->nodes[0])) { in copy_inode_items_to_log()
5962 btrfs_item_key_to_cpu(path->nodes[0], min_key, in copy_inode_items_to_log()
5963 path->slots[0]); in copy_inode_items_to_log()
5976 if (min_key->offset < (u64)-1) { in copy_inode_items_to_log()
5977 min_key->offset++; in copy_inode_items_to_log()
5978 } else if (min_key->type < max_key->type) { in copy_inode_items_to_log()
5979 min_key->type++; in copy_inode_items_to_log()
5980 min_key->offset = 0; in copy_inode_items_to_log()
5999 if (inode_only == LOG_INODE_ALL && S_ISREG(inode->vfs_inode.i_mode)) { in copy_inode_items_to_log()
6024 for (int i = 0; i < batch->nr; i++) { in insert_delayed_items_batch()
6027 data_ptr = btrfs_item_ptr(path->nodes[0], path->slots[0], char); in insert_delayed_items_batch()
6028 write_extent_buffer(path->nodes[0], &curr->data, in insert_delayed_items_batch()
6029 (unsigned long)data_ptr, curr->data_len); in insert_delayed_items_batch()
6031 path->slots[0]++; in insert_delayed_items_batch()
6047 const int leaf_data_size = BTRFS_LEAF_DATA_SIZE(trans->fs_info); in log_delayed_insertion_items()
6049 struct btrfs_root *log = inode->root->log_root; in log_delayed_insertion_items()
6064 lockdep_assert_held(&inode->log_mutex); in log_delayed_insertion_items()
6075 if (curr->index > inode->last_dir_index_offset) { in log_delayed_insertion_items()
6088 return -ENOMEM; in log_delayed_insertion_items()
6096 const u32 curr_size = curr->data_len + sizeof(struct btrfs_item); in log_delayed_insertion_items()
6111 ins_sizes[batch_idx] = curr->data_len; in log_delayed_insertion_items()
6114 ins_keys[batch_idx].offset = curr->index; in log_delayed_insertion_items()
6116 batch.total_data_size += curr->data_len; in log_delayed_insertion_items()
6127 inode->last_dir_index_offset = curr->index; in log_delayed_insertion_items()
6147 u64 first_dir_index = curr->index; in log_delayed_deletions_full()
6159 if (next->index != curr->index + 1) in log_delayed_deletions_full()
6165 last_dir_index = curr->index; in log_delayed_deletions_full()
6168 ret = insert_dir_log_key(trans, inode->root->log_root, path, in log_delayed_deletions_full()
6186 struct extent_buffer *leaf = path->nodes[0]; in batch_delete_dir_index_items()
6187 const int last_slot = btrfs_header_nritems(leaf) - 1; in batch_delete_dir_index_items()
6188 int slot = path->slots[0] + 1; in batch_delete_dir_index_items()
6200 key.offset != next->index) in batch_delete_dir_index_items()
6208 return btrfs_del_items(trans, inode->root->log_root, path, in batch_delete_dir_index_items()
6209 path->slots[0], slot - path->slots[0]); in batch_delete_dir_index_items()
6218 struct btrfs_root *log = inode->root->log_root; in log_delayed_deletions_incremental()
6231 u64 first_dir_index = curr->index; in log_delayed_deletions_incremental()
6236 key.offset = curr->index; in log_delayed_deletions_incremental()
6237 ret = btrfs_search_slot(trans, log, &key, path, -1, 1); in log_delayed_deletions_incremental()
6259 last_dir_index = last->index; in log_delayed_deletions_incremental()
6294 lockdep_assert_held(&inode->log_mutex); in log_delayed_deletion_items()
6299 if (ctx->logged_before) in log_delayed_deletion_items()
6316 const bool orig_log_new_dentries = ctx->log_new_dentries; in log_new_delayed_dentries()
6325 lockdep_assert_not_held(&inode->log_mutex); in log_new_delayed_dentries()
6327 ASSERT(!ctx->logging_new_delayed_dentries); in log_new_delayed_dentries()
6328 ctx->logging_new_delayed_dentries = true; in log_new_delayed_dentries()
6336 dir_item = (struct btrfs_dir_item *)item->data; in log_new_delayed_dentries()
6337 btrfs_disk_key_to_cpu(&key, &dir_item->location); in log_new_delayed_dentries()
6342 di_inode = btrfs_iget_logging(key.objectid, inode->root); in log_new_delayed_dentries()
6356 ctx->log_new_dentries = false; in log_new_delayed_dentries()
6359 if (!ret && ctx->log_new_dentries) in log_new_delayed_dentries()
6368 ctx->log_new_dentries = orig_log_new_dentries; in log_new_delayed_dentries()
6369 ctx->logging_new_delayed_dentries = false; in log_new_delayed_dentries()
6397 struct btrfs_root *log = inode->root->log_root; in btrfs_log_inode()
6401 struct extent_map_tree *em_tree = &inode->extent_tree; in btrfs_log_inode()
6412 return -ENOMEM; in btrfs_log_inode()
6416 return -ENOMEM; in btrfs_log_inode()
6427 if (S_ISDIR(inode->vfs_inode.i_mode) || in btrfs_log_inode()
6429 &inode->runtime_flags) && in btrfs_log_inode()
6433 max_key.type = (u8)-1; in btrfs_log_inode()
6434 max_key.offset = (u64)-1; in btrfs_log_inode()
6436 if (S_ISDIR(inode->vfs_inode.i_mode) && inode_only == LOG_INODE_ALL) in btrfs_log_inode()
6446 * $ mkdir -p a/b/c/d/e/f/g/h/... in btrfs_log_inode()
6447 * $ xfs_io -c "fsync" a in btrfs_log_inode()
6466 * However the limit is quite high, so lets prevent deep levels of in btrfs_log_inode()
6469 if (full_dir_logging && ctx->logging_new_delayed_dentries) { in btrfs_log_inode()
6475 mutex_lock(&inode->log_mutex); in btrfs_log_inode()
6480 * log replay, which is invalid on linux (symlink(2) returns -ENOENT if in btrfs_log_inode()
6486 if (S_ISLNK(inode->vfs_inode.i_mode)) in btrfs_log_inode()
6497 ctx->logged_before = (ret == 1); in btrfs_log_inode()
6507 if (full_dir_logging && inode->last_unlink_trans >= trans->transid) { in btrfs_log_inode()
6516 if (S_ISDIR(inode->vfs_inode.i_mode)) { in btrfs_log_inode()
6517 clear_bit(BTRFS_INODE_COPY_EVERYTHING, &inode->runtime_flags); in btrfs_log_inode()
6518 if (ctx->logged_before) in btrfs_log_inode()
6522 if (inode_only == LOG_INODE_EXISTS && ctx->logged_before) { in btrfs_log_inode()
6528 * truncate - for e.g. create file, write 4K into offset in btrfs_log_inode()
6530 * fsync some other file (to sync log), power fail - if in btrfs_log_inode()
6541 &inode->runtime_flags)) { in btrfs_log_inode()
6544 if (ctx->logged_before) in btrfs_log_inode()
6549 &inode->runtime_flags); in btrfs_log_inode()
6551 &inode->runtime_flags); in btrfs_log_inode()
6552 if (ctx->logged_before) in btrfs_log_inode()
6557 &inode->runtime_flags) || in btrfs_log_inode()
6562 if (ctx->logged_before) in btrfs_log_inode()
6582 if (full_dir_logging && !ctx->logging_new_delayed_dentries) in btrfs_log_inode()
6593 if (inode->vfs_inode.i_nlink == 0) { in btrfs_log_inode()
6634 if (!xattrs_logged && inode->logged_trans < trans->transid) { in btrfs_log_inode()
6648 write_lock(&em_tree->lock); in btrfs_log_inode()
6649 list_for_each_entry_safe(em, n, &em_tree->modified_extents, list) in btrfs_log_inode()
6650 list_del_init(&em->list); in btrfs_log_inode()
6651 write_unlock(&em_tree->lock); in btrfs_log_inode()
6668 spin_lock(&inode->lock); in btrfs_log_inode()
6669 inode->logged_trans = trans->transid; in btrfs_log_inode()
6695 * its last_log_commit - otherwise if an explicit fsync is made in btrfs_log_inode()
6702 inode->last_log_commit = inode->last_sub_trans; in btrfs_log_inode()
6703 spin_unlock(&inode->lock); in btrfs_log_inode()
6710 inode->last_reflink_trans = 0; in btrfs_log_inode()
6713 mutex_unlock(&inode->log_mutex); in btrfs_log_inode()
6721 ret = log_conflicting_inodes(trans, inode->root, ctx); in btrfs_log_inode()
6723 if (full_dir_logging && !ctx->logging_new_delayed_dentries) { in btrfs_log_inode()
6742 struct btrfs_root *root = inode->root; in btrfs_log_all_parents()
6747 return -ENOMEM; in btrfs_log_all_parents()
6748 path->skip_locking = 1; in btrfs_log_all_parents()
6749 path->search_commit_root = 1; in btrfs_log_all_parents()
6759 struct extent_buffer *leaf = path->nodes[0]; in btrfs_log_all_parents()
6760 int slot = path->slots[0]; in btrfs_log_all_parents()
6815 * touch /mnt/B/bar in btrfs_log_all_parents()
6818 * mv -T /mnt/A /mnt/B in btrfs_log_all_parents()
6837 ctx->log_new_dentries = false; in btrfs_log_all_parents()
6839 if (!ret && ctx->log_new_dentries) in btrfs_log_all_parents()
6845 path->slots[0]++; in btrfs_log_all_parents()
6860 btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]); in log_new_ancestors()
6881 if (inode->generation >= trans->transid && in log_new_ancestors()
6896 leaf = path->nodes[0]; in log_new_ancestors()
6897 slot = path->slots[0]; in log_new_ancestors()
6903 return -ENOENT; in log_new_ancestors()
6904 leaf = path->nodes[0]; in log_new_ancestors()
6905 slot = path->slots[0]; in log_new_ancestors()
6911 return -ENOENT; in log_new_ancestors()
6921 struct btrfs_root *root = inode->root; in log_new_ancestors_fast()
6923 struct super_block *sb = inode->vfs_inode.i_sb; in log_new_ancestors_fast()
6928 sb != parent->d_sb) in log_new_ancestors_fast()
6932 if (root != inode->root) in log_new_ancestors_fast()
6935 if (inode->generation >= trans->transid && in log_new_ancestors_fast()
6959 struct btrfs_root *root = inode->root; in log_all_new_ancestors()
6969 if (inode->vfs_inode.i_nlink < 2) in log_all_new_ancestors()
6974 return -ENOMEM; in log_all_new_ancestors()
6984 path->slots[0]++; in log_all_new_ancestors()
6987 struct extent_buffer *leaf = path->nodes[0]; in log_all_new_ancestors()
6988 int slot = path->slots[0]; in log_all_new_ancestors()
7013 ret = -EMLINK; in log_all_new_ancestors()
7049 struct btrfs_root *root = inode->root; in btrfs_log_inode_parent()
7050 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_log_inode_parent()
7057 if (btrfs_root_refs(&root->root_item) == 0) in btrfs_log_inode_parent()
7064 if (btrfs_root_generation(&root->root_item) == trans->transid) in btrfs_log_inode_parent()
7068 if (btrfs_inode_in_log(inode, trans->transid) && in btrfs_log_inode_parent()
7069 list_empty(&ctx->ordered_extents)) in btrfs_log_inode_parent()
7086 if (S_ISREG(inode->vfs_inode.i_mode) && in btrfs_log_inode_parent()
7087 inode->generation < trans->transid && in btrfs_log_inode_parent()
7088 inode->last_unlink_trans < trans->transid) { in btrfs_log_inode_parent()
7094 * Track if we need to log dentries because ctx->log_new_dentries can in btrfs_log_inode_parent()
7097 log_dentries = ctx->log_new_dentries; in btrfs_log_inode_parent()
7105 * error -ENOTEMPTY). in btrfs_log_inode_parent()
7110 * touch testdir/foo in btrfs_log_inode_parent()
7114 * xfs_io -c fsync testdir/foo in btrfs_log_inode_parent()
7126 * touch foo in btrfs_log_inode_parent()
7131 * xfs_io -c fsync foo in btrfs_log_inode_parent()
7140 if (inode->last_unlink_trans >= trans->transid) { in btrfs_log_inode_parent()
7197 struct btrfs_fs_info *fs_info = log_root_tree->fs_info; in btrfs_recover_log_trees()
7205 return -ENOMEM; in btrfs_recover_log_trees()
7207 set_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags); in btrfs_recover_log_trees()
7209 trans = btrfs_start_transaction(fs_info->tree_root, 0); in btrfs_recover_log_trees()
7227 key.offset = (u64)-1; in btrfs_recover_log_trees()
7237 if (path->slots[0] == 0) in btrfs_recover_log_trees()
7239 path->slots[0]--; in btrfs_recover_log_trees()
7241 btrfs_item_key_to_cpu(path->nodes[0], &found_key, in btrfs_recover_log_trees()
7242 path->slots[0]); in btrfs_recover_log_trees()
7270 if (ret == -ENOENT) in btrfs_recover_log_trees()
7271 ret = btrfs_pin_extent_for_log_replay(trans, log->node); in btrfs_recover_log_trees()
7280 wc.replay_dest->log_root = log; in btrfs_recover_log_trees()
7305 * root->objectid_mutex is not acquired as log replay in btrfs_recover_log_trees()
7313 wc.replay_dest->log_root = NULL; in btrfs_recover_log_trees()
7322 key.offset = found_key.offset - 1; in btrfs_recover_log_trees()
7346 log_root_tree->log_root = NULL; in btrfs_recover_log_trees()
7347 clear_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags); in btrfs_recover_log_trees()
7354 clear_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags); in btrfs_recover_log_trees()
7384 mutex_lock(&inode->log_mutex); in btrfs_record_unlink_dir()
7385 inode->last_unlink_trans = trans->transid; in btrfs_record_unlink_dir()
7386 mutex_unlock(&inode->log_mutex); in btrfs_record_unlink_dir()
7416 mutex_lock(&dir->log_mutex); in btrfs_record_unlink_dir()
7417 dir->last_unlink_trans = trans->transid; in btrfs_record_unlink_dir()
7418 mutex_unlock(&dir->log_mutex); in btrfs_record_unlink_dir()
7436 mutex_lock(&dir->log_mutex); in btrfs_record_snapshot_destroy()
7437 dir->last_unlink_trans = trans->transid; in btrfs_record_snapshot_destroy()
7438 mutex_unlock(&dir->log_mutex); in btrfs_record_snapshot_destroy()
7456 mutex_lock(&dir->log_mutex); in btrfs_record_new_subvolume()
7457 dir->last_unlink_trans = trans->transid; in btrfs_record_new_subvolume()
7458 mutex_unlock(&dir->log_mutex); in btrfs_record_new_subvolume()
7483 struct btrfs_root *root = inode->root; in btrfs_log_new_name()
7492 if (!S_ISDIR(inode->vfs_inode.i_mode)) in btrfs_log_new_name()
7493 inode->last_unlink_trans = trans->transid; in btrfs_log_new_name()
7507 * NULL), check if old_dir was logged - if it was not we can return and in btrfs_log_new_name()
7525 if (old_dir && old_dir->logged_trans == trans->transid) { in btrfs_log_new_name()
7526 struct btrfs_root *log = old_dir->root->log_root; in btrfs_log_new_name()
7532 ret = fscrypt_setup_filename(&old_dir->vfs_inode, in btrfs_log_new_name()
7533 &old_dentry->d_name, 0, &fname); in btrfs_log_new_name()
7557 ret = -ENOMEM; in btrfs_log_new_name()
7572 mutex_lock(&old_dir->log_mutex); in btrfs_log_new_name()
7585 mutex_unlock(&old_dir->log_mutex); in btrfs_log_new_name()