diff mbox

ext4: only call ext4_truncate when size <= isize

Message ID 1432049337-3520-1-git-send-email-jbacik@fb.com
State Accepted, archived
Headers show

Commit Message

Josef Bacik May 19, 2015, 3:28 p.m. UTC
At LSF we decided that if we truncate up from isize we shouldn't trim fallocated
blocks that were fallocated with KEEP_SIZE and are past the new i_size.  This
patch fixes ext4 to do this.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
---
 fs/ext4/inode.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Lukas Czerner June 2, 2015, 8:08 a.m. UTC | #1
On Tue, 19 May 2015, Josef Bacik wrote:

> Date: Tue, 19 May 2015 11:28:57 -0400
> From: Josef Bacik <jbacik@fb.com>
> To: tytso@mit.edu, linux-ext4@vger.kernel.org
> Subject: [PATCH] ext4: only call ext4_truncate when size <= isize
> 
> At LSF we decided that if we truncate up from isize we shouldn't trim fallocated
> blocks that were fallocated with KEEP_SIZE and are past the new i_size.  This
> patch fixes ext4 to do this.  Thanks,

Looks good, thanks!

Reviewed-by: Lukas Czerner <lczerner@redhat.com>

> 
> Signed-off-by: Josef Bacik <jbacik@fb.com>
> ---
>  fs/ext4/inode.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 0554b0b..92174dd 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -4640,6 +4640,7 @@ static void ext4_wait_for_tail_page_commit(struct inode *inode)
>  int ext4_setattr(struct dentry *dentry, struct iattr *attr)
>  {
>  	struct inode *inode = d_inode(dentry);
> +	loff_t oldsize = inode->i_size;
>  	int error, rc = 0;
>  	int orphan = 0;
>  	const unsigned int ia_valid = attr->ia_valid;
> @@ -4727,8 +4728,6 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
>  				goto err_out;
>  			}
>  		} else {
> -			loff_t oldsize = inode->i_size;
> -
>  			i_size_write(inode, attr->ia_size);
>  			pagecache_isize_extended(inode, oldsize, inode->i_size);
>  		}
> @@ -4756,7 +4755,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
>  	 * We want to call ext4_truncate() even if attr->ia_size ==
>  	 * inode->i_size for cases like truncation of fallocated space
>  	 */
> -	if (attr->ia_valid & ATTR_SIZE)
> +	if (attr->ia_valid & ATTR_SIZE && attr->ia_size <= oldsize)
>  		ext4_truncate(inode);
>  
>  	if (!rc) {
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Theodore Ts'o June 6, 2015, 8:20 p.m. UTC | #2
On Tue, Jun 02, 2015 at 10:08:18AM +0200, Lukáš Czerner wrote:
> On Tue, 19 May 2015, Josef Bacik wrote:
> 
> > Date: Tue, 19 May 2015 11:28:57 -0400
> > From: Josef Bacik <jbacik@fb.com>
> > To: tytso@mit.edu, linux-ext4@vger.kernel.org
> > Subject: [PATCH] ext4: only call ext4_truncate when size <= isize
> > 
> > At LSF we decided that if we truncate up from isize we shouldn't trim fallocated
> > blocks that were fallocated with KEEP_SIZE and are past the new i_size.  This
> > patch fixes ext4 to do this.  Thanks,
> 
> Looks good, thanks!
> 
> Reviewed-by: Lukas Czerner <lczerner@redhat.com>

Applied, thanks.

					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Theodore Ts'o June 9, 2015, 4:07 p.m. UTC | #3
On Sat, Jun 06, 2015 at 04:20:11PM -0400, Theodore Ts'o wrote:
> On Tue, Jun 02, 2015 at 10:08:18AM +0200, Lukáš Czerner wrote:
> > On Tue, 19 May 2015, Josef Bacik wrote:
> > 
> > > Date: Tue, 19 May 2015 11:28:57 -0400
> > > From: Josef Bacik <jbacik@fb.com>
> > > To: tytso@mit.edu, linux-ext4@vger.kernel.org
> > > Subject: [PATCH] ext4: only call ext4_truncate when size <= isize
> > > 
> > > At LSF we decided that if we truncate up from isize we shouldn't trim fallocated
> > > blocks that were fallocated with KEEP_SIZE and are past the new i_size.  This
> > > patch fixes ext4 to do this.  Thanks,
> > 
> > Looks good, thanks!
> > 
> > Reviewed-by: Lukas Czerner <lczerner@redhat.com>
> 
> Applied, thanks.

Unfortunately this patch is causing generic/239 to fail when run with
1k blocksizes.

I'm dropping this for now; could you take a look?

Thanks!

						- Ted

generic/239 22s ...	[11:46:25] [11:46:54] 29s
 _check_generic_filesystem: filesystem on /dev/vdd is inconsistent (see /results/results-1k/generic/239.full)
 Ran: generic/239
 Failures: generic/239
 Failed 1 of 1 tests

e2fsck 1.43-WIP (18-May-2015)
Pass 1: Checking inodes, blocks, and sizes
Inode 12, i_size is 0, should be 4096.  Fix? yes

Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/dev/vdd: ***** FILE SYSTEM WAS MODIFIED *****
/dev/vdd: 12/327680 files (0.0% non-contiguous), 120145/5242880 blocks


--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 0554b0b..92174dd 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4640,6 +4640,7 @@  static void ext4_wait_for_tail_page_commit(struct inode *inode)
 int ext4_setattr(struct dentry *dentry, struct iattr *attr)
 {
 	struct inode *inode = d_inode(dentry);
+	loff_t oldsize = inode->i_size;
 	int error, rc = 0;
 	int orphan = 0;
 	const unsigned int ia_valid = attr->ia_valid;
@@ -4727,8 +4728,6 @@  int ext4_setattr(struct dentry *dentry, struct iattr *attr)
 				goto err_out;
 			}
 		} else {
-			loff_t oldsize = inode->i_size;
-
 			i_size_write(inode, attr->ia_size);
 			pagecache_isize_extended(inode, oldsize, inode->i_size);
 		}
@@ -4756,7 +4755,7 @@  int ext4_setattr(struct dentry *dentry, struct iattr *attr)
 	 * We want to call ext4_truncate() even if attr->ia_size ==
 	 * inode->i_size for cases like truncation of fallocated space
 	 */
-	if (attr->ia_valid & ATTR_SIZE)
+	if (attr->ia_valid & ATTR_SIZE && attr->ia_size <= oldsize)
 		ext4_truncate(inode);
 
 	if (!rc) {