Browse Source

Btrfs: fix transaction leak during fsync call

If btrfs_log_dentry_safe() returns an error, we set ret to 1 and
fall through with the goal of committing the transaction. However,
in the case where the inode doesn't need a full sync, we would call
btrfs_wait_ordered_range() against the target range for our inode,
and if it returned an error, we would return without commiting or
ending the transaction.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: Chris Mason <clm@fb.com>
Filipe Manana 11 years ago
parent
commit
b05fd8742f
1 changed files with 3 additions and 1 deletions
  1. 3 1
      fs/btrfs/file.c

+ 3 - 1
fs/btrfs/file.c

@@ -2025,8 +2025,10 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
 		if (!full_sync) {
 		if (!full_sync) {
 			ret = btrfs_wait_ordered_range(inode, start,
 			ret = btrfs_wait_ordered_range(inode, start,
 						       end - start + 1);
 						       end - start + 1);
-			if (ret)
+			if (ret) {
+				btrfs_end_transaction(trans, root);
 				goto out;
 				goto out;
+			}
 		}
 		}
 		ret = btrfs_commit_transaction(trans, root);
 		ret = btrfs_commit_transaction(trans, root);
 	} else {
 	} else {