Lines Matching refs:inode

21 #include "inode-item.h"
37 * LOG_INODE_EXISTS means to log just enough to recreate the inode
48 * 1) on rename or unlink, if the inode being unlinked isn't in the fsync
64 * log. ---> check inode while renaming/linking.
68 * ---> check inode and old parent dir during rename
84 * directory tree. The inode link count fixup code takes care of the
105 struct btrfs_inode *inode,
301 * Ignore any items from the inode currently being processed. Needs
446 * We need to load the old nbytes into the inode so when we
475 * New inode, set nbytes to 0 so that the nbytes comes out
513 /* don't overwrite an existing inode if the generation number
515 * is just logging an inode to make sure it exists after recovery.
535 * logging that an inode exists, as part of a directory
536 * fsync, and the inode wasn't fsynced before. In this
537 * case don't set the size of the inode in the fs/subvol
595 * simple helper to read an inode off the disk from a given root
598 static noinline struct inode *read_one_inode(struct btrfs_root *root,
601 struct inode *inode;
603 inode = btrfs_iget(root->fs_info->sb, objectid, root);
604 if (IS_ERR(inode))
605 inode = NULL;
606 return inode;
634 struct inode *inode = NULL;
662 inode = read_one_inode(root, key->objectid);
663 if (!inode) {
674 btrfs_ino(BTRFS_I(inode)), start, 0);
708 ret = btrfs_drop_extents(trans, root, BTRFS_I(inode), &drop_args);
886 ret = btrfs_inode_set_file_extent_range(BTRFS_I(inode), start,
892 btrfs_update_inode_bytes(BTRFS_I(inode), nbytes, drop_args.bytes_found);
893 ret = btrfs_update_inode(trans, BTRFS_I(inode));
895 iput(inode);
901 struct btrfs_inode *inode,
906 ret = btrfs_unlink_inode(trans, dir, inode, name);
921 * inode back references, we may have to unlink inodes from directories.
932 struct inode *inode;
947 inode = read_one_inode(root, location.objectid);
948 if (!inode) {
957 ret = unlink_inode_for_log_replay(trans, dir, BTRFS_I(inode), &name);
960 iput(inode);
965 * See if a given name and sequence number found in an inode back reference are
966 * already in a directory and correctly point to this inode.
1010 * an inode. This is used to decide if a back reference that is
1013 * inode backreferences may have multiple refs in a single item,
1055 struct btrfs_inode *inode,
1106 inc_nlink(&inode->vfs_inode);
1109 ret = unlink_inode_for_log_replay(trans, dir, inode,
1133 struct inode *victim_parent;
1169 inc_nlink(&inode->vfs_inode);
1174 inode, &victim_name);
1257 * Take an inode reference item from the log tree and iterate all names from the
1258 * inode reference item in the subvolume tree with the same key (if it exists).
1259 * For any name that is not in the inode reference item from the log tree, do a
1260 * proper unlink of that name (that is, remove its entry from the inode
1266 struct btrfs_inode *inode,
1310 struct inode *dir;
1320 inode, &name);
1342 * replay one inode back reference item found in the log tree.
1354 struct inode *dir = NULL;
1355 struct inode *inode = NULL;
1384 * for a given inode. If we don't find the dir, just don't
1394 inode = read_one_inode(root, inode_objectid);
1395 if (!inode) {
1421 btrfs_ino(BTRFS_I(inode)), ref_index, &name);
1433 BTRFS_I(dir), BTRFS_I(inode),
1443 ret = btrfs_add_link(trans, BTRFS_I(dir), BTRFS_I(inode),
1448 ret = btrfs_update_inode(trans, BTRFS_I(inode));
1464 * Before we overwrite the inode reference item in the subvolume tree
1466 * parent directory that are in the subvolume's tree inode reference
1468 * dir index entries exist for a name but there is no inode reference
1471 ret = unlink_old_inode_refs(trans, root, path, BTRFS_I(inode), eb, slot,
1476 /* finally write the back reference in the inode */
1482 iput(inode);
1486 static int count_inode_extrefs(struct btrfs_inode *inode, struct btrfs_path *path)
1493 u64 inode_objectid = btrfs_ino(inode);
1500 ret = btrfs_find_one_extref(inode->root, inode_objectid, offset,
1529 static int count_inode_refs(struct btrfs_inode *inode, struct btrfs_path *path)
1537 u64 ino = btrfs_ino(inode);
1544 ret = btrfs_search_slot(NULL, inode->root, &key, path, 0, 0);
1591 * The scan will update the link count on the inode to reflect the
1593 * will free the inode.
1596 struct inode *inode)
1598 struct btrfs_root *root = BTRFS_I(inode)->root;
1602 u64 ino = btrfs_ino(BTRFS_I(inode));
1608 ret = count_inode_refs(BTRFS_I(inode), path);
1614 ret = count_inode_extrefs(BTRFS_I(inode), path);
1622 if (nlink != inode->i_nlink) {
1623 set_nlink(inode, nlink);
1624 ret = btrfs_update_inode(trans, BTRFS_I(inode));
1628 BTRFS_I(inode)->index_cnt = (u64)-1;
1630 if (inode->i_nlink == 0) {
1631 if (S_ISDIR(inode->i_mode)) {
1653 struct inode *inode;
1680 inode = read_one_inode(root, key.offset);
1681 if (!inode) {
1686 ret = fixup_inode_link_count(trans, inode);
1687 iput(inode);
1704 * record a given inode in the fixup dir so we can check its link
1706 * so the inode won't go away until we check it
1715 struct inode *inode;
1717 inode = read_one_inode(root, objectid);
1718 if (!inode)
1729 if (!inode->i_nlink)
1730 set_nlink(inode, 1);
1732 inc_nlink(inode);
1733 ret = btrfs_update_inode(trans, BTRFS_I(inode));
1737 iput(inode);
1753 struct inode *inode;
1754 struct inode *dir;
1757 inode = read_one_inode(root, location->objectid);
1758 if (!inode)
1763 iput(inode);
1767 ret = btrfs_add_link(trans, BTRFS_I(dir), BTRFS_I(inode), name,
1770 /* FIXME, put inode into FIXUP list */
1772 iput(inode);
1788 /* The existing dentry points to the same inode, don't delete it. */
1796 * Don't drop the conflicting directory entry if the inode for the new
1810 * the inode it points to is unlinked and put into the link count
1819 * non-existing inode) and 1 if the name was replayed.
1835 struct inode *dir;
1899 * Check if the inode reference exists in the log for the given name,
1900 * inode and parent inode
1970 * committed, make sure we fixup the link count of the inode the entry
1972 * directory pointing to an inode with a wrong link that does not account
2093 * item is not in the log, the item is removed and the inode it points
2100 struct inode *dir,
2109 struct inode *inode = NULL;
2146 inode = read_one_inode(root, location.objectid);
2147 if (!inode) {
2156 inc_nlink(inode);
2157 ret = unlink_inode_for_log_replay(trans, BTRFS_I(dir), BTRFS_I(inode),
2168 iput(inode);
2292 struct inode *dir;
2301 /* it isn't an error if the inode isn't there, that can happen
2302 * because we replay the deletes before we copy in the inode item
2381 * only in the log (references come from either directory items or inode
2415 /* inode keys are done during the first stage */
2454 * Before replaying extents, truncate the inode to its
2457 * added beyond the inode's i_size. If we did it after,
2463 struct inode *inode;
2466 inode = read_one_inode(root, key.objectid);
2467 if (!inode) {
2471 from = ALIGN(i_size_read(inode),
2477 BTRFS_I(inode),
2480 inode_sub_bytes(inode,
2482 /* Update the inode's nbytes. */
2484 BTRFS_I(inode));
2486 iput(inode);
2823 void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx, struct inode *inode)
2831 ctx->inode = inode;
2842 struct btrfs_inode *inode = BTRFS_I(ctx->inode);
2844 if (!test_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &inode->runtime_flags) &&
2845 !test_bit(BTRFS_INODE_COPY_EVERYTHING, &inode->runtime_flags))
2852 ctx->scratch_eb = alloc_dummy_extent_buffer(inode->root->fs_info, 0);
2860 ASSERT(inode_is_locked(ctx->inode));
3285 * Check if an inode was logged in the current transaction. This correctly deals
3286 * with the case where the inode was logged but has a logged_trans of 0, which
3287 * happens if the inode is evicted and loaded again, as logged_trans is an in
3290 * Returns 1 if the inode was logged before in the transaction, 0 if it was not,
3294 struct btrfs_inode *inode,
3301 if (inode->logged_trans == trans->transid)
3305 * If logged_trans is not 0, then we know the inode logged was not logged
3308 if (inode->logged_trans > 0)
3313 * the inode can not have been logged in this transaction. In that case
3318 if (!test_bit(BTRFS_ROOT_HAS_LOG_TREE, &inode->root->state)) {
3319 inode->logged_trans = trans->transid - 1;
3324 * We have a log tree and the inode's logged_trans is 0. We can't tell
3325 * for sure if the inode was logged before in this transaction by looking
3327 * that can lead to unnecessarily logging an inode during rename and link
3334 * 1) The inode was never logged since the filesystem was mounted, and may
3337 * 2) The inode was logged in a previous transaction, then evicted and
3340 * 3) The inode was logged in the current transaction, then evicted and
3344 * case 3) and return true. So we do a search in the log root for the inode
3347 key.objectid = btrfs_ino(inode);
3357 ret = btrfs_search_slot(NULL, inode->root->log_root, &key, path, 0, 0);
3365 * Logging an inode always results in logging its inode item. So if we
3366 * did not find the item we know the inode was not logged for sure.
3375 inode->logged_trans = trans->transid - 1;
3380 * The inode was previously logged and then evicted, set logged_trans to
3382 * the inode is not evicted again.
3384 inode->logged_trans = trans->transid;
3388 * maximum possible value, so that the next attempt to log the inode does
3393 * in the inode item or any other on-disk structure, so its value is lost
3394 * once the inode is evicted.
3396 if (S_ISDIR(inode->vfs_inode.i_mode))
3397 inode->last_dir_index_offset = (u64)-1;
3431 * inode item because on log replay we update the field to reflect
3450 * We solve this by removing directory entries and inode backrefs from the
3455 * This optimizations allows us to avoid relogging the entire inode
3500 struct btrfs_inode *inode, u64 dirid)
3506 ret = inode_logged(trans, inode, NULL);
3518 mutex_lock(&inode->log_mutex);
3520 ret = btrfs_del_inode_ref(trans, log, name, btrfs_ino(inode),
3522 mutex_unlock(&inode->log_mutex);
3577 struct btrfs_inode *inode,
3583 struct btrfs_root *log = inode->root->log_root;
3649 ASSERT(last_index > inode->last_dir_index_offset);
3655 if (WARN_ON(last_index <= inode->last_dir_index_offset))
3658 inode->last_dir_index_offset = last_index;
3660 if (btrfs_get_first_dir_index_to_log(inode) == 0)
3661 btrfs_set_first_dir_index_to_log(inode, batch.keys[0].offset);
3693 struct btrfs_inode *inode,
3699 struct btrfs_root *log = inode->root->log_root;
3702 const u64 ino = btrfs_ino(inode);
3753 if (key.offset <= inode->last_dir_index_offset)
3758 * corresponding inode, after log replay, has a matching link
3769 * Would result in a fsync log that when replayed, our file inode
3771 * pointing to the same inode. After removing one of the names,
3794 ret = flush_dir_items_batch(trans, inode, src, dst_path,
3809 struct btrfs_inode *inode,
3816 struct btrfs_root *root = inode->root;
3821 u64 ino = btrfs_ino(inode);
3892 * need to log the parent directory of an inode. This means a dir index
3893 * key might be deleted from the inode's root, and therefore we may not
3906 /* There are no more keys in the inode's root. */
3919 ret = process_dir_items_leaf(trans, inode, path, dst_path, ctx,
3989 * If the inode was logged before and it was evicted, then its
3991 * key offset. If that's the case, search for it and update the inode. This
3996 static int update_last_dir_index_offset(struct btrfs_inode *inode,
4000 const u64 ino = btrfs_ino(inode);
4004 lockdep_assert_held(&inode->log_mutex);
4006 if (inode->last_dir_index_offset != (u64)-1)
4010 inode->last_dir_index_offset = BTRFS_DIR_START_INDEX - 1;
4018 ret = btrfs_search_slot(NULL, inode->root->log_root, &key, path, 0, 0);
4027 inode->last_dir_index_offset = BTRFS_DIR_START_INDEX - 1;
4045 inode->last_dir_index_offset = key.offset;
4066 struct btrfs_inode *inode,
4075 ret = update_last_dir_index_offset(inode, path, ctx);
4083 ret = log_dir_items(trans, inode, path, dst_path,
4097 * inode. max_key_type indicates the highest item type to remove.
4104 struct btrfs_inode *inode,
4112 key.objectid = btrfs_ino(inode);
4156 struct btrfs_inode *inode,
4161 .ino = btrfs_ino(inode),
4172 struct inode *inode, int log_inode_only,
4183 * just to say 'this inode exists' and a logging
4184 * to say 'update this inode with these values'
4190 BTRFS_I(inode)->generation);
4191 btrfs_set_token_inode_size(&token, item, inode->i_size);
4194 btrfs_set_token_inode_uid(&token, item, i_uid_read(inode));
4195 btrfs_set_token_inode_gid(&token, item, i_gid_read(inode));
4196 btrfs_set_token_inode_mode(&token, item, inode->i_mode);
4197 btrfs_set_token_inode_nlink(&token, item, inode->i_nlink);
4200 inode_get_atime_sec(inode));
4202 inode_get_atime_nsec(inode));
4205 inode_get_mtime_sec(inode));
4207 inode_get_mtime_nsec(inode));
4210 inode_get_ctime_sec(inode));
4212 inode_get_ctime_nsec(inode));
4220 * inode item in subvolume tree as needed (see overwrite_item()).
4223 btrfs_set_token_inode_sequence(&token, item, inode_peek_iversion(inode));
4225 btrfs_set_token_inode_rdev(&token, item, inode->i_rdev);
4226 flags = btrfs_inode_combine_flags(BTRFS_I(inode)->flags,
4227 BTRFS_I(inode)->ro_flags);
4234 struct btrfs_inode *inode, bool inode_item_dropped)
4240 * If we are doing a fast fsync and the inode was logged before in the
4241 * current transaction, then we know the inode was previously logged and
4246 * same subvolume. Using btrfs_insert_empty_item() when the inode item
4249 if (!inode_item_dropped && inode->logged_trans == trans->transid) {
4250 ret = btrfs_search_slot(trans, log, &inode->location, path, 0, 1);
4257 * so the inode item is not in the log and we need to insert it.
4259 * fsync and in case an inode eviction happens after the inode was
4261 * the inode, we set BTRFS_INODE_NEEDS_FULL_SYNC on its runtime
4264 ret = btrfs_insert_empty_item(trans, log, path, &inode->location,
4272 fill_inode_item(trans, path->nodes[0], inode_item, &inode->vfs_inode,
4279 struct btrfs_inode *inode,
4288 * If this inode was not used for reflink operations in the current
4292 if (inode->last_reflink_trans < trans->transid)
4325 struct btrfs_inode *inode,
4331 struct btrfs_root *log = inode->root->log_root;
4340 const bool skip_csum = (inode->flags & BTRFS_INODE_NODATASUM);
4341 const u64 i_size = i_size_read(&inode->vfs_inode);
4353 * struct, can trigger inode eviction and finally the inode eviction
4417 * time or after the full sync flag is set on the inode. We can
4419 * generations, so we can skip them - as long as the inode has
4428 inode->last_reflink_trans < trans->transid)
4472 ret = log_csums(trans, inode, log, sums);
4523 inode->last_reflink_trans < trans->transid)
4536 &inode->vfs_inode,
4571 struct btrfs_inode *inode,
4585 if (inode->flags & BTRFS_INODE_NODATASUM ||
4638 ret = log_csums(trans, inode, log_root, sums);
4671 ret = log_csums(trans, inode, log_root, sums);
4680 struct btrfs_inode *inode,
4686 struct btrfs_root *log = inode->root->log_root;
4717 ret = log_extent_csums(trans, inode, log, em, ctx);
4722 * If this is the first time we are logging the inode in the current
4736 ret = btrfs_drop_extents(trans, log, inode, &drop_args);
4742 key.objectid = btrfs_ino(inode);
4763 * Log all prealloc extents beyond the inode's i_size to make sure we do not
4765 * subvolume's root instead of iterating the inode's extent map tree because
4771 struct btrfs_inode *inode,
4775 struct btrfs_root *root = inode->root;
4777 const u64 i_size = i_size_read(&inode->vfs_inode);
4778 const u64 ino = btrfs_ino(inode);
4788 if (!(inode->flags & BTRFS_INODE_PREALLOC))
4838 ret = copy_items(trans, inode, dst_path, path,
4872 ret = truncate_inode_items(trans, root->log_root, inode,
4893 ret = copy_items(trans, inode, dst_path, path,
4902 struct btrfs_inode *inode,
4910 struct extent_map_tree *tree = &inode->extent_tree;
4935 em->start >= i_size_read(&inode->vfs_inode))
4957 clear_em_logging(inode, em);
4964 ret = log_one_extent(trans, inode, em, path, ctx);
4966 clear_em_logging(inode, em);
4973 ret = btrfs_log_prealloc_extents(trans, inode, path, ctx);
4989 spin_lock_irq(&inode->ordered_tree_lock);
4994 spin_unlock_irq(&inode->ordered_tree_lock);
5002 static int logged_inode_size(struct btrfs_root *log, struct btrfs_inode *inode,
5008 key.objectid = btrfs_ino(inode);
5024 * If the in-memory inode's i_size is smaller then the inode
5025 * size stored in the btree, return the inode's i_size, so
5026 * that we get a correct inode size after replaying the log
5029 * Otherwise return the inode size from the btree, to avoid
5031 * write that expands the inode's size and logging a new name
5034 if (*size_ret > inode->vfs_inode.i_size)
5035 *size_ret = inode->vfs_inode.i_size;
5046 * because if a xattr is deleted, the inode is fsynced and a power failure
5052 struct btrfs_inode *inode,
5057 struct btrfs_root *root = inode->root;
5060 const u64 ino = btrfs_ino(inode);
5065 if (test_bit(BTRFS_INODE_NO_XATTRS, &inode->runtime_flags))
5083 ret = copy_items(trans, inode, dst_path, path,
5109 ret = copy_items(trans, inode, dst_path, path,
5116 set_bit(BTRFS_INODE_NO_XATTRS, &inode->runtime_flags);
5124 * that contains the inode item and references) we may end up not processing
5126 * current transaction that have extent items for our inode. So we need to find
5128 * truncate operation that changes the inode's size.
5131 struct btrfs_inode *inode,
5134 struct btrfs_root *root = inode->root;
5137 const u64 ino = btrfs_ino(inode);
5138 const u64 i_size = i_size_read(&inode->vfs_inode);
5189 * an extent item and we are holding the inode lock, the
5222 * When we are logging a new inode X, check if it doesn't have a reference that
5223 * matches the reference from some other inode Y created in a past transaction
5225 * log replay time we can lose inode Y (and all its files if it's a directory):
5238 * For the case where inode Y is not a directory we simply end up losing it:
5266 struct btrfs_inode *inode,
5326 di = btrfs_lookup_dir_item(NULL, inode->root, search_path,
5361 * Check if we need to log an inode. This is used in contexts where while
5362 * logging an inode we need to log another inode (either that it exists or in
5364 * requires the inode to be in the log and have the log transaction committed,
5366 * caller will commit the log later - and we want to avoid logging an inode
5370 struct btrfs_inode *inode)
5376 if (S_ISDIR(inode->vfs_inode.i_mode) && inode->last_trans < trans->transid)
5380 * If this inode does not have new/updated/deleted xattrs since the last
5384 * In case the inode was logged and then evicted and reloaded, its
5388 if (inode_logged(trans, inode, NULL) == 1 &&
5389 !test_bit(BTRFS_INODE_COPY_EVERYTHING, &inode->runtime_flags))
5421 * that while logging the inode new references (names) are added or removed
5422 * from the inode, leaving the logged inode item with a link count that does
5423 * not match the number of logged inode reference items. This is fine because
5425 * link count in the inode item (see replay_one_buffer() and
5429 * while logging the inode's items new index items (key type
5430 * BTRFS_DIR_INDEX_KEY) are added to fs/subvol tree and the logged inode item
5452 * of an inode and that any new parents exist.
5465 struct inode *vfs_inode;
5481 struct inode *di_inode;
5617 * We have previously found the inode through the commit root
5645 struct inode *inode;
5657 inode = btrfs_iget(root->fs_info->sb, ino, root);
5659 * If the other inode that had a conflicting dir entry was deleted in
5663 * the inode is a directory. This is because it may be a deleted
5673 * add the dentry for our inode. Like this we can avoid logging the
5676 * some inode from it to some other directory).
5678 if (IS_ERR(inode)) {
5679 int ret = PTR_ERR(inode);
5689 /* Conflicting inode is a directory, so we'll log its parent. */
5702 * If the inode was already logged skip it - otherwise we can hit an
5708 * inode 257 a directory
5709 * inode 258 with references "zz" and "zz_link" on inode 257
5710 * inode 259 with reference "a" on inode 257
5714 * inode 257 a directory, unchanged
5715 * inode 258 with references "a" and "a2" on inode 257
5716 * inode 259 with reference "zz_link" on inode 257
5717 * inode 261 with reference "zz" on inode 257
5719 * When logging inode 261 the following infinite loop could
5722 * - we detect inode 258 as a conflicting inode, with inode 261
5725 * - we detect inode 259 as a conflicting inode, with inode 258
5728 * - we detect inode 258 as a conflicting inode, with inode 259
5733 * inode in LOG_INODE_EXISTS mode and rename operations update the log,
5736 if (!need_log_inode(trans, BTRFS_I(inode))) {
5737 btrfs_add_delayed_iput(BTRFS_I(inode));
5741 btrfs_add_delayed_iput(BTRFS_I(inode));
5773 * are logging a conflicting inode, so keep iterating while the list is
5778 struct inode *inode;
5789 inode = btrfs_iget(fs_info->sb, ino, root);
5791 * If the other inode that had a conflicting dir entry was
5795 if (IS_ERR(inode)) {
5796 ret = PTR_ERR(inode);
5800 inode = btrfs_iget(fs_info->sb, parent, root);
5801 if (IS_ERR(inode)) {
5802 ret = PTR_ERR(inode);
5810 * the dir index of the conflicting inode is not in a
5814 ret = btrfs_log_inode(trans, BTRFS_I(inode),
5816 btrfs_add_delayed_iput(BTRFS_I(inode));
5824 * the inode in LOG_INODE_EXISTS mode and rename operations
5829 * it again because if some other task logged the inode after
5832 if (!need_log_inode(trans, BTRFS_I(inode))) {
5833 btrfs_add_delayed_iput(BTRFS_I(inode));
5838 * We are safe logging the other inode without acquiring its
5840 * are safe against concurrent renames of the other inode as
5844 ret = btrfs_log_inode(trans, BTRFS_I(inode), LOG_INODE_EXISTS, ctx);
5845 btrfs_add_delayed_iput(BTRFS_I(inode));
5858 struct btrfs_inode *inode,
5868 const u64 i_size = i_size_read(&inode->vfs_inode);
5869 struct btrfs_root *root = inode->root;
5902 (inode->generation == trans->transid ||
5908 path->slots[0], min_key, inode,
5913 other_ino != btrfs_ino(BTRFS_I(ctx->inode))) {
5920 ret = copy_items(trans, inode, dst_path, path,
5939 ret = copy_items(trans, inode, dst_path, path,
5957 ret = copy_items(trans, inode, dst_path, path, ins_start_slot,
5971 ret = copy_items(trans, inode, dst_path, path,
5990 * We may process many leaves full of items for our inode, so
5997 ret = copy_items(trans, inode, dst_path, path, ins_start_slot,
6003 if (inode_only == LOG_INODE_ALL && S_ISREG(inode->vfs_inode.i_mode)) {
6009 ret = btrfs_log_prealloc_extents(trans, inode, dst_path, ctx);
6044 struct btrfs_inode *inode,
6052 const u64 ino = btrfs_ino(inode);
6053 struct btrfs_root *log = inode->root->log_root;
6068 lockdep_assert_held(&inode->log_mutex);
6079 if (curr->index > inode->last_dir_index_offset) {
6131 inode->last_dir_index_offset = curr->index;
6139 struct btrfs_inode *inode,
6144 const u64 ino = btrfs_ino(inode);
6172 ret = insert_dir_log_key(trans, inode->root->log_root, path,
6183 struct btrfs_inode *inode,
6194 const u64 ino = btrfs_ino(inode);
6213 return btrfs_del_items(trans, inode->root->log_root, path,
6218 struct btrfs_inode *inode,
6223 struct btrfs_root *log = inode->root->log_root;
6229 key.objectid = btrfs_ino(inode);
6246 ret = batch_delete_dir_index_items(trans, inode, path, ctx,
6290 struct btrfs_inode *inode,
6299 lockdep_assert_held(&inode->log_mutex);
6305 return log_delayed_deletions_incremental(trans, inode, path,
6308 return log_delayed_deletions_full(trans, inode, path, delayed_del_list,
6317 struct btrfs_inode *inode,
6328 * lockdep annotations due to nesting of delayed inode mutexes and log
6331 lockdep_assert_not_held(&inode->log_mutex);
6338 struct inode *di_inode;
6348 di_inode = btrfs_iget(fs_info->sb, key.objectid, inode->root);
6380 /* log a single inode in the tree log.
6381 * At least one parent directory for this inode must exist in the tree
6384 * Any items from this inode changed by the current transaction are copied
6395 struct btrfs_inode *inode,
6403 struct btrfs_root *log = inode->root->log_root;
6406 u64 ino = btrfs_ino(inode);
6407 struct extent_map_tree *em_tree = &inode->extent_tree;
6433 if (S_ISDIR(inode->vfs_inode.i_mode) ||
6435 &inode->runtime_flags) &&
6442 if (S_ISDIR(inode->vfs_inode.i_mode) && inode_only == LOG_INODE_ALL)
6447 * delayed items of some other inode, then we need to flush the delayed
6476 ret = btrfs_commit_inode_delayed_items(trans, inode);
6481 mutex_lock(&inode->log_mutex);
6492 if (S_ISLNK(inode->vfs_inode.i_mode))
6496 * Before logging the inode item, cache the value returned by
6498 * the inode was previously logged in this transaction.
6500 ret = inode_logged(trans, inode, path);
6513 if (full_dir_logging && inode->last_unlink_trans >= trans->transid) {
6522 if (S_ISDIR(inode->vfs_inode.i_mode)) {
6523 clear_bit(BTRFS_INODE_COPY_EVERYTHING, &inode->runtime_flags);
6525 ret = drop_inode_items(trans, log, path, inode,
6530 * Make sure the new inode item we write to the log has
6537 * we use the inode's current i_size, after log replay
6542 ret = logged_inode_size(log, inode, path, &logged_isize);
6547 &inode->runtime_flags)) {
6552 inode, max_key.type);
6555 &inode->runtime_flags);
6557 &inode->runtime_flags);
6560 inode, 0, 0);
6563 &inode->runtime_flags) ||
6569 ret = drop_inode_items(trans, log, path, inode,
6589 btrfs_log_get_delayed_items(inode, &delayed_ins_list,
6592 ret = copy_inode_items_to_log(trans, inode, &min_key, &max_key,
6601 ret = btrfs_log_all_xattrs(trans, inode, path, dst_path, ctx);
6608 ret = btrfs_log_holes(trans, inode, path);
6616 ret = log_inode_item(trans, log, dst_path, inode, inode_item_dropped);
6620 * If we are doing a fast fsync and the inode was logged before
6623 * deleted since the last time we logged the inode, then we have
6624 * already logged them because the inode had the runtime flag
6627 if (!xattrs_logged && inode->logged_trans < trans->transid) {
6628 ret = btrfs_log_all_xattrs(trans, inode, path, dst_path, ctx);
6635 ret = btrfs_log_changed_extents(trans, inode, dst_path, ctx);
6648 ret = log_directory_changes(trans, inode, path, dst_path, ctx);
6651 ret = log_delayed_insertion_items(trans, inode, path,
6655 ret = log_delayed_deletion_items(trans, inode, path,
6661 spin_lock(&inode->lock);
6662 inode->logged_trans = trans->transid;
6664 * Don't update last_log_commit if we logged that an inode exists.
6667 * 1) We might have had buffered writes to this inode that were
6669 * transaction, but we did not previously log the inode with
6670 * LOG_INODE_ALL. Later the inode was evicted and after that
6673 * the inode is performed later, it logs the new extents, an
6674 * updated inode item, etc, and syncs the log. The same logic
6677 * 2) When we log the inode with LOG_INODE_EXISTS, its inode item
6679 * before. If later the i_size of the inode is increased by a
6681 * some other inode and then finally an explicit fsync against
6682 * this inode is made, we must make sure this fsync logs the
6683 * inode with the new i_size, the hole between old i_size and
6686 * 3) If we are logging that an ancestor inode exists as part of
6689 * against an ancestor, the fsync considers the inode in the log
6692 * against any other unrelated inode.
6695 inode->last_log_commit = inode->last_sub_trans;
6696 spin_unlock(&inode->lock);
6703 inode->last_reflink_trans = 0;
6706 mutex_unlock(&inode->log_mutex);
6714 ret = log_conflicting_inodes(trans, inode->root, ctx);
6718 ret = log_new_delayed_dentries(trans, inode,
6721 btrfs_log_put_delayed_items(inode, &delayed_ins_list,
6729 struct btrfs_inode *inode,
6736 struct btrfs_root *root = inode->root;
6737 const u64 ino = btrfs_ino(inode);
6777 struct inode *dir_inode;
6800 * If the parent inode was deleted, return an error to
6802 * getting an inode that was moved from one parent A to
6864 struct inode *inode;
6875 inode = btrfs_iget(fs_info->sb, ino, root);
6876 if (IS_ERR(inode))
6877 return PTR_ERR(inode);
6879 if (BTRFS_I(inode)->generation >= trans->transid &&
6880 need_log_inode(trans, BTRFS_I(inode)))
6881 ret = btrfs_log_inode(trans, BTRFS_I(inode),
6883 btrfs_add_delayed_iput(BTRFS_I(inode));
6916 struct btrfs_inode *inode,
6920 struct btrfs_root *root = inode->root;
6922 struct super_block *sb = inode->vfs_inode.i_sb;
6930 inode = BTRFS_I(d_inode(parent));
6931 if (root != inode->root)
6934 if (inode->generation >= trans->transid &&
6935 need_log_inode(trans, inode)) {
6936 ret = btrfs_log_inode(trans, inode,
6954 struct btrfs_inode *inode,
6958 struct btrfs_root *root = inode->root;
6959 const u64 ino = btrfs_ino(inode);
6968 if (inode->vfs_inode.i_nlink < 2)
6969 return log_new_ancestors_fast(trans, inode, parent, ctx);
7019 * Keep track of the last inode ref key and resume from that key
7038 * parent directories also end up in the log. A minimal inode and backref
7043 struct btrfs_inode *inode,
7048 struct btrfs_root *root = inode->root;
7068 if ((btrfs_inode_in_log(inode, trans->transid) &&
7070 inode->vfs_inode.i_nlink == 0) {
7079 ret = btrfs_log_inode(trans, inode, inode_only, ctx);
7084 * for regular files, if its inode is already on disk, we don't
7089 if (S_ISREG(inode->vfs_inode.i_mode) &&
7090 inode->generation < trans->transid &&
7091 inode->last_unlink_trans < trans->transid) {
7096 if (S_ISDIR(inode->vfs_inode.i_mode) && ctx->log_new_dentries)
7119 * directory still has an entry pointing to the file inode using the bar
7121 * the file inode has a link count of 1.
7136 * testdir still has an entry pointing to the inode file with name foo3
7137 * but the file inode does not have a matching BTRFS_INODE_REF_KEY item
7140 if (inode->last_unlink_trans >= trans->transid) {
7141 ret = btrfs_log_all_parents(trans, inode, ctx);
7146 ret = log_all_new_ancestors(trans, inode, parent, ctx);
7151 ret = log_new_dir_dentries(trans, inode, ctx);
7373 struct btrfs_inode *dir, struct btrfs_inode *inode,
7378 * or unlinked, and its inode is fully committed on disk,
7386 mutex_lock(&inode->log_mutex);
7387 inode->last_unlink_trans = trans->transid;
7388 mutex_unlock(&inode->log_mutex);
7403 * If the inode we're about to unlink was logged before, the log will be
7408 if (inode_logged(trans, inode, NULL) == 1)
7444 * Update the log after adding a new name for an inode.
7449 * @old_dir: The inode of the previous parent directory for the case
7457 * Call this after adding a new name for an inode, as a result of a link or
7464 struct btrfs_inode *inode = BTRFS_I(d_inode(old_dentry));
7465 struct btrfs_root *root = inode->root;
7474 if (!S_ISDIR(inode->vfs_inode.i_mode))
7475 inode->last_unlink_trans = trans->transid;
7478 * if this inode hasn't been logged and directory we're renaming it
7481 ret = inode_logged(trans, inode, NULL);
7488 * If the inode was not logged and we are doing a rename (old_dir is not
7504 * name of the renamed inode, so we need to make sure that after log
7520 * the inode that got renamed, so we must pin the log to prevent
7546 * as it can be triggered when logging other inode that had or
7575 btrfs_init_log_ctx(&ctx, &inode->vfs_inode);
7585 btrfs_log_inode_parent(trans, inode, parent, LOG_INODE_EXISTS, &ctx);