aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/file.c
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@fusionio.com>2013-06-17 17:14:39 -0400
committerJosef Bacik <jbacik@fusionio.com>2013-07-01 08:52:33 -0400
commita71754fc68f740b7ed46bb83123c63fbbc130611 (patch)
treec39655c68a713d4707cb476ac28702bb4e302ed2 /fs/btrfs/file.c
parent0b08851fdaa5f9f74357345d7be44ea584665d5f (diff)
Btrfs: move btrfs_truncate_page to btrfs_cont_expand instead of btrfs_truncate
This has plagued us forever and I'm so over working around it. When we truncate down to a non-page aligned offset we will call btrfs_truncate_page to zero out the end of the page and write it back to disk, this will keep us from exposing stale data if we truncate back up from that point. The problem with this is it requires data space to do this, and people don't really expect to get ENOSPC from truncate() for these sort of things. This also tends to bite the orphan cleanup stuff too which keeps people from mounting. To get around this we can just move this into btrfs_cont_expand() to make sure if we are truncating up from a non-page size aligned i_size we will zero out the rest of this page so that we don't expose stale data. This will give ENOSPC if you try to truncate() up or if you try to write past the end of isize, which is much more reasonable. This fixes xfstests generic/083 failing to mount because of the orphan cleanup failing. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r--fs/btrfs/file.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 185af15ad9e4..5ffde5603686 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2173,12 +2173,6 @@ static long btrfs_fallocate(struct file *file, int mode,
2173 goto out_reserve_fail; 2173 goto out_reserve_fail;
2174 } 2174 }
2175 2175
2176 /*
2177 * wait for ordered IO before we have any locks. We'll loop again
2178 * below with the locks held.
2179 */
2180 btrfs_wait_ordered_range(inode, alloc_start, alloc_end - alloc_start);
2181
2182 mutex_lock(&inode->i_mutex); 2176 mutex_lock(&inode->i_mutex);
2183 ret = inode_newsize_ok(inode, alloc_end); 2177 ret = inode_newsize_ok(inode, alloc_end);
2184 if (ret) 2178 if (ret)
@@ -2189,8 +2183,23 @@ static long btrfs_fallocate(struct file *file, int mode,
2189 alloc_start); 2183 alloc_start);
2190 if (ret) 2184 if (ret)
2191 goto out; 2185 goto out;
2186 } else {
2187 /*
2188 * If we are fallocating from the end of the file onward we
2189 * need to zero out the end of the page if i_size lands in the
2190 * middle of a page.
2191 */
2192 ret = btrfs_truncate_page(inode, inode->i_size, 0, 0);
2193 if (ret)
2194 goto out;
2192 } 2195 }
2193 2196
2197 /*
2198 * wait for ordered IO before we have any locks. We'll loop again
2199 * below with the locks held.
2200 */
2201 btrfs_wait_ordered_range(inode, alloc_start, alloc_end - alloc_start);
2202
2194 locked_end = alloc_end - 1; 2203 locked_end = alloc_end - 1;
2195 while (1) { 2204 while (1) {
2196 struct btrfs_ordered_extent *ordered; 2205 struct btrfs_ordered_extent *ordered;