diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 5c1d58706fa9..cab451d19547 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -5467,13 +5467,23 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans, btrfs_release_path(dst_path); if (need_log_inode_item) { err = log_inode_item(trans, log, dst_path, inode); - if (!err && !xattrs_logged) { - err = btrfs_log_all_xattrs(trans, root, inode, path, - dst_path); - btrfs_release_path(path); - } if (err) goto out_unlock; + /* + * If we are doing a fast fsync and the inode was logged before + * in this transaction, we don't need to log the xattrs because + * they were logged before. If xattrs were added, changed or + * deleted since the last time we logged the inode, then we have + * already logged them because the inode had the runtime flag + * BTRFS_INODE_COPY_EVERYTHING set. + */ + if (!xattrs_logged && inode->logged_trans < trans->transid) { + err = btrfs_log_all_xattrs(trans, root, inode, path, + dst_path); + if (err) + goto out_unlock; + btrfs_release_path(path); + } } if (fast_search) { ret = btrfs_log_changed_extents(trans, root, inode, dst_path,