aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2010-05-26 10:59:53 -0400
committerChris Mason <chris.mason@oracle.com>2010-05-26 10:59:53 -0400
commit3f7c579c41a3d20af76fd6ff1f6b949edf105fd1 (patch)
tree374d50346763fb37299f5de93f48901596f21e59 /fs
parent4845e44ffdb26be9b25610664228e8ecaf949a0d (diff)
Btrfs: move O_DIRECT space reservation to btrfs_direct_IO
This moves the delalloc space reservation done for O_DIRECT into btrfs_direct_IO. This way we don't leak reserved space if the generic O_DIRECT write code errors out before it calls into btrfs_direct_IO. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/file.c5
-rw-r--r--fs/btrfs/inode.c9
2 files changed, 8 insertions, 6 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 54556cae4497..79437c5eeb1e 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -888,14 +888,9 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
888 BTRFS_I(inode)->sequence++; 888 BTRFS_I(inode)->sequence++;
889 889
890 if (unlikely(file->f_flags & O_DIRECT)) { 890 if (unlikely(file->f_flags & O_DIRECT)) {
891 ret = btrfs_delalloc_reserve_space(inode, count);
892 if (ret)
893 goto out;
894
895 num_written = generic_file_direct_write(iocb, iov, &nr_segs, 891 num_written = generic_file_direct_write(iocb, iov, &nr_segs,
896 pos, ppos, count, 892 pos, ppos, count,
897 ocount); 893 ocount);
898
899 /* 894 /*
900 * the generic O_DIRECT will update in-memory i_size after the 895 * the generic O_DIRECT will update in-memory i_size after the
901 * DIOs are done. But our endio handlers that update the on 896 * DIOs are done. But our endio handlers that update the on
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 00aefbdcc2df..ca9d5501d340 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5602,9 +5602,16 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,
5602 ssize_t ret; 5602 ssize_t ret;
5603 int writing = rw & WRITE; 5603 int writing = rw & WRITE;
5604 int write_bits = 0; 5604 int write_bits = 0;
5605 size_t count = iov_length(iov, nr_segs);
5605 5606
5606 lockstart = offset; 5607 lockstart = offset;
5607 lockend = offset + iov_length(iov, nr_segs) - 1; 5608 lockend = offset + count - 1;
5609
5610 if (writing) {
5611 ret = btrfs_delalloc_reserve_space(inode, count);
5612 if (ret)
5613 goto out;
5614 }
5608 5615
5609 while (1) { 5616 while (1) {
5610 lock_extent_bits(&BTRFS_I(inode)->io_tree, lockstart, lockend, 5617 lock_extent_bits(&BTRFS_I(inode)->io_tree, lockstart, lockend,