aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r--fs/btrfs/file.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 84ecf3ab8511..58b329ddb426 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1061,7 +1061,9 @@ int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync)
1061 } 1061 }
1062 mutex_unlock(&root->fs_info->trans_mutex); 1062 mutex_unlock(&root->fs_info->trans_mutex);
1063 1063
1064 root->fs_info->tree_log_batch++;
1064 filemap_fdatawait(inode->i_mapping); 1065 filemap_fdatawait(inode->i_mapping);
1066 root->fs_info->tree_log_batch++;
1065 1067
1066 /* 1068 /*
1067 * ok we haven't committed the transaction yet, lets do a commit 1069 * ok we haven't committed the transaction yet, lets do a commit
@@ -1076,14 +1078,29 @@ int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync)
1076 } 1078 }
1077 1079
1078 ret = btrfs_log_dentry_safe(trans, root, file->f_dentry); 1080 ret = btrfs_log_dentry_safe(trans, root, file->f_dentry);
1079 if (ret < 0) 1081 if (ret < 0) {
1080 goto out; 1082 goto out;
1083 }
1084
1085 /* we've logged all the items and now have a consistent
1086 * version of the file in the log. It is possible that
1087 * someone will come in and modify the file, but that's
1088 * fine because the log is consistent on disk, and we
1089 * have references to all of the file's extents
1090 *
1091 * It is possible that someone will come in and log the
1092 * file again, but that will end up using the synchronization
1093 * inside btrfs_sync_log to keep things safe.
1094 */
1095 mutex_unlock(&file->f_dentry->d_inode->i_mutex);
1096
1081 if (ret > 0) { 1097 if (ret > 0) {
1082 ret = btrfs_commit_transaction(trans, root); 1098 ret = btrfs_commit_transaction(trans, root);
1083 } else { 1099 } else {
1084 btrfs_sync_log(trans, root); 1100 btrfs_sync_log(trans, root);
1085 ret = btrfs_end_transaction(trans, root); 1101 ret = btrfs_end_transaction(trans, root);
1086 } 1102 }
1103 mutex_lock(&file->f_dentry->d_inode->i_mutex);
1087out: 1104out:
1088 return ret > 0 ? EIO : ret; 1105 return ret > 0 ? EIO : ret;
1089} 1106}