linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: only call ext4_truncate when size <= isize
@ 2015-05-19 15:28 Josef Bacik
  2015-06-02  8:08 ` Lukáš Czerner
  0 siblings, 1 reply; 5+ messages in thread
From: Josef Bacik @ 2015-05-19 15:28 UTC (permalink / raw)
  To: tytso, linux-ext4

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(-)

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;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ext4: only call ext4_truncate when size <= isize
  2015-05-19 15:28 [PATCH] ext4: only call ext4_truncate when size <= isize Josef Bacik
@ 2015-06-02  8:08 ` Lukáš Czerner
  2015-06-06 20:20   ` Theodore Ts'o
  0 siblings, 1 reply; 5+ messages in thread
From: Lukáš Czerner @ 2015-06-02  8:08 UTC (permalink / raw)
  To: Josef Bacik; +Cc: tytso, linux-ext4

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) {
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ext4: only call ext4_truncate when size <= isize
  2015-06-02  8:08 ` Lukáš Czerner
@ 2015-06-06 20:20   ` Theodore Ts'o
  2015-06-09 16:07     ` Theodore Ts'o
  0 siblings, 1 reply; 5+ messages in thread
From: Theodore Ts'o @ 2015-06-06 20:20 UTC (permalink / raw)
  To: Lukáš Czerner; +Cc: Josef Bacik, linux-ext4

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ext4: only call ext4_truncate when size <= isize
  2015-06-06 20:20   ` Theodore Ts'o
@ 2015-06-09 16:07     ` Theodore Ts'o
  2015-06-22  4:37       ` Theodore Ts'o
  0 siblings, 1 reply; 5+ messages in thread
From: Theodore Ts'o @ 2015-06-09 16:07 UTC (permalink / raw)
  To: Lukáš Czerner; +Cc: Josef Bacik, linux-ext4

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ext4: only call ext4_truncate when size <= isize
  2015-06-09 16:07     ` Theodore Ts'o
@ 2015-06-22  4:37       ` Theodore Ts'o
  0 siblings, 0 replies; 5+ messages in thread
From: Theodore Ts'o @ 2015-06-22  4:37 UTC (permalink / raw)
  To: Lukáš Czerner; +Cc: Josef Bacik, linux-ext4

On Tue, Jun 09, 2015 at 12:07:39PM -0400, Theodore Ts'o wrote:
> 
> Unfortunately this patch is causing generic/239 to fail when run with
> 1k blocksizes.

So it turns out the original patch was completely busted; the on-disk
i_size wasn't getting updated when we were truncating up.  Part of the
problem was the original way ATTR_SIZE was handled in ext4_setattr was
a bit of a mess, and it made it hard to understand.  So I've reworked
patch completely to clean up ext4_setattr while I was it.

      		    	     		  	  - Ted

>From 0d209259066ca93548189668d1eb4c9497913932 Mon Sep 17 00:00:00 2001
From: Josef Bacik <jbacik@fb.com>
Date: Mon, 22 Jun 2015 00:31:26 -0400
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.

[ Completely reworked patch so that i_disksize would actually get set
  when truncating up.  Also reworked the code for handling truncate so
  that it's easier to handle. -- tytso ]

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Lukas Czerner <lczerner@redhat.com>
---
 fs/ext4/inode.c | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index ae93f0b..e057c6f 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4681,8 +4681,10 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
 		ext4_journal_stop(handle);
 	}
 
-	if (attr->ia_valid & ATTR_SIZE && attr->ia_size != inode->i_size) {
+	if (attr->ia_valid & ATTR_SIZE) {
 		handle_t *handle;
+		loff_t oldsize = inode->i_size;
+		int shrink = (attr->ia_size <= inode->i_size);
 
 		if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
 			struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
@@ -4690,24 +4692,26 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
 			if (attr->ia_size > sbi->s_bitmap_maxbytes)
 				return -EFBIG;
 		}
+		if (!S_ISREG(inode->i_mode))
+			return -EINVAL;
 
 		if (IS_I_VERSION(inode) && attr->ia_size != inode->i_size)
 			inode_inc_iversion(inode);
 
-		if (S_ISREG(inode->i_mode) &&
+		if (ext4_should_order_data(inode) &&
 		    (attr->ia_size < inode->i_size)) {
-			if (ext4_should_order_data(inode)) {
-				error = ext4_begin_ordered_truncate(inode,
+			error = ext4_begin_ordered_truncate(inode,
 							    attr->ia_size);
-				if (error)
-					goto err_out;
-			}
+			if (error)
+				goto err_out;
+		}
+		if (attr->ia_size != inode->i_size) {
 			handle = ext4_journal_start(inode, EXT4_HT_INODE, 3);
 			if (IS_ERR(handle)) {
 				error = PTR_ERR(handle);
 				goto err_out;
 			}
-			if (ext4_handle_valid(handle)) {
+			if (ext4_handle_valid(handle) && shrink) {
 				error = ext4_orphan_add(handle, inode);
 				orphan = 1;
 			}
@@ -4726,15 +4730,13 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
 			up_write(&EXT4_I(inode)->i_data_sem);
 			ext4_journal_stop(handle);
 			if (error) {
-				ext4_orphan_del(NULL, inode);
+				if (orphan)
+					ext4_orphan_del(NULL, inode);
 				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);
 		}
+		if (!shrink)
+			pagecache_isize_extended(inode, oldsize, inode->i_size);
 
 		/*
 		 * Blocks are going to be removed from the inode. Wait
@@ -4754,13 +4756,9 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
 		 * in data=journal mode to make pages freeable.
 		 */
 		truncate_pagecache(inode, inode->i_size);
+		if (shrink)
+			ext4_truncate(inode);
 	}
-	/*
-	 * 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)
-		ext4_truncate(inode);
 
 	if (!rc) {
 		setattr_copy(inode, attr);
-- 
2.3.0

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-22  4:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-19 15:28 [PATCH] ext4: only call ext4_truncate when size <= isize Josef Bacik
2015-06-02  8:08 ` Lukáš Czerner
2015-06-06 20:20   ` Theodore Ts'o
2015-06-09 16:07     ` Theodore Ts'o
2015-06-22  4:37       ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).