linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] ocfs2: Let ocfs2_setattr use new truncate sequence.
@ 2010-06-11  3:27 Tao Ma
  2010-06-11  4:50 ` Nick Piggin
  2010-06-11  6:56 ` Christoph Hellwig
  0 siblings, 2 replies; 7+ messages in thread
From: Tao Ma @ 2010-06-11  3:27 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: linux-kernel, Tao Ma, Joel Becker, Christoph Hellwig, Nick Piggin

Let ocfs2 use the new truncate sequence. The changes include:
1. Move inode_change_ok into cluster lock and remove inode_newsize_ok.
2. Use truncate_setsize directly since we don't implement our
   own ->truncate and what we need is "update i_size and
   truncate_pagecache" which truncate_setsize now does.
3. Change some i_size_read to inode->i_size in ocfs2_setattr
   since we have i_muext held.
4. For direct write, ocfs2 actually don't allow write to pass
   i_size(see ocfs2_prepare_inode_for_write), so we don't have
   a chance to increase i_size. So remove the bogus check.

Cc: Joel Becker <joel.becker@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Nick Piggin <npiggin@suse.de>
Signed-off-by: Tao Ma <tao.ma@oracle.com>
---
 fs/ocfs2/file.c |   45 ++++++++++-----------------------------------
 1 files changed, 10 insertions(+), 35 deletions(-)

diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 1fb0985..6e4685e 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -960,10 +960,6 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
 		return 0;
 	}
 
-	status = inode_change_ok(inode, attr);
-	if (status)
-		return status;
-
 	if (is_quota_modification(inode, attr))
 		dquot_initialize(inode);
 	size_change = S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_SIZE;
@@ -982,12 +978,12 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
 		goto bail_unlock_rw;
 	}
 
-	if (size_change && attr->ia_size != i_size_read(inode)) {
-		status = inode_newsize_ok(inode, attr->ia_size);
-		if (status)
-			goto bail_unlock;
+	status = inode_change_ok(inode, attr);
+	if (status)
+		goto bail_unlock;
 
-		if (i_size_read(inode) > attr->ia_size) {
+	if (size_change && attr->ia_size != inode->i_size) {
+		if (inode->i_size > attr->ia_size) {
 			if (ocfs2_should_order_data(inode)) {
 				status = ocfs2_begin_ordered_truncate(inode,
 								      attr->ia_size);
@@ -1052,22 +1048,12 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
 	}
 
 	/*
-	 * This will intentionally not wind up calling truncate_setsize(),
-	 * since all the work for a size change has been done above.
-	 * Otherwise, we could get into problems with truncate as
-	 * ip_alloc_sem is used there to protect against i_size
-	 * changes.
-	 *
-	 * XXX: this means the conditional below can probably be removed.
+	 * Since all the work for a size change has been done above.
+	 * Call truncate_setsize directly to change size and truncate
+	 * pagecache.
 	 */
-	if ((attr->ia_valid & ATTR_SIZE) &&
-	    attr->ia_size != i_size_read(inode)) {
-		status = vmtruncate(inode, attr->ia_size);
-		if (status) {
-			mlog_errno(status);
-			goto bail_commit;
-		}
-	}
+	if ((attr->ia_valid & ATTR_SIZE) && attr->ia_size != inode->i_size)
+		truncate_setsize(inode, attr->ia_size);
 
 	setattr_copy(inode, attr);
 	mark_inode_dirty(inode);
@@ -2122,17 +2108,6 @@ relock:
 		written = generic_file_direct_write(iocb, iov, &nr_segs, *ppos,
 						    ppos, count, ocount);
 		if (written < 0) {
-			/*
-			 * direct write may have instantiated a few
-			 * blocks outside i_size. Trim these off again.
-			 * Don't need i_size_read because we hold i_mutex.
-			 *
-			 * XXX(truncate): this looks buggy because ocfs2 did not
-			 * actually implement ->truncate.  Take a look at
-			 * the new truncate sequence and update this accordingly
-			 */
-			if (*ppos + count > inode->i_size)
-				truncate_setsize(inode, inode->i_size);
 			ret = written;
 			goto out_dio;
 		}
-- 
1.5.5


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

* Re: [PATCH v4] ocfs2: Let ocfs2_setattr use new truncate sequence.
  2010-06-11  3:27 [PATCH v4] ocfs2: Let ocfs2_setattr use new truncate sequence Tao Ma
@ 2010-06-11  4:50 ` Nick Piggin
  2010-06-11  6:56 ` Christoph Hellwig
  1 sibling, 0 replies; 7+ messages in thread
From: Nick Piggin @ 2010-06-11  4:50 UTC (permalink / raw)
  To: Tao Ma; +Cc: linux-fsdevel, linux-kernel, Joel Becker, Christoph Hellwig

On Fri, Jun 11, 2010 at 11:27:49AM +0800, Tao Ma wrote:
> Let ocfs2 use the new truncate sequence. The changes include:
> 1. Move inode_change_ok into cluster lock and remove inode_newsize_ok.
> 2. Use truncate_setsize directly since we don't implement our
>    own ->truncate and what we need is "update i_size and
>    truncate_pagecache" which truncate_setsize now does.
> 3. Change some i_size_read to inode->i_size in ocfs2_setattr
>    since we have i_muext held.
> 4. For direct write, ocfs2 actually don't allow write to pass
>    i_size(see ocfs2_prepare_inode_for_write), so we don't have
>    a chance to increase i_size. So remove the bogus check.
> 
> Cc: Joel Becker <joel.becker@oracle.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Nick Piggin <npiggin@suse.de>

The patch looks fine to me. I really appreciate you working on truncate,
thanks.


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

* Re: [PATCH v4] ocfs2: Let ocfs2_setattr use new truncate sequence.
  2010-06-11  3:27 [PATCH v4] ocfs2: Let ocfs2_setattr use new truncate sequence Tao Ma
  2010-06-11  4:50 ` Nick Piggin
@ 2010-06-11  6:56 ` Christoph Hellwig
  2010-06-11  7:16   ` Tao Ma
  1 sibling, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2010-06-11  6:56 UTC (permalink / raw)
  To: Tao Ma
  Cc: linux-fsdevel, linux-kernel, Joel Becker, Christoph Hellwig,
	Nick Piggin

This looks correct, but still has the second if ATTR_SIZE block that
I commented on last time.  I'd really prefer if the filesystems could
move the truncate handling into a single conditional to simplify
auditing for it and possibly splitting it out into a separate method
later.

And btw, the S_ISREG check which you only have on the first ATTR_SIZE
check is superflous, the VFS only does ATTR_SIZE calls on regular files.


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

* Re: [PATCH v4] ocfs2: Let ocfs2_setattr use new truncate sequence.
  2010-06-11  6:56 ` Christoph Hellwig
@ 2010-06-11  7:16   ` Tao Ma
  2010-06-11  7:19     ` Christoph Hellwig
  0 siblings, 1 reply; 7+ messages in thread
From: Tao Ma @ 2010-06-11  7:16 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-fsdevel, linux-kernel, Joel Becker, Nick Piggin, tao.ma

Hi Christoph,

On 06/11/2010 02:56 PM, Christoph Hellwig wrote:
> This looks correct, but still has the second if ATTR_SIZE block that
> I commented on last time.  I'd really prefer if the filesystems could
> move the truncate handling into a single conditional to simplify
> auditing for it and possibly splitting it out into a separate method
> later.
oh, that would be much work for ocfs2 to do from my perspective. So I 
would really want to leave it as-is and I have add it to my to-do list.
>
> And btw, the S_ISREG check which you only have on the first ATTR_SIZE
> check is superflous, the VFS only does ATTR_SIZE calls on regular files.
yeah, I can remove it.

Regards,
Tao

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

* Re: [PATCH v4] ocfs2: Let ocfs2_setattr use new truncate sequence.
  2010-06-11  7:16   ` Tao Ma
@ 2010-06-11  7:19     ` Christoph Hellwig
  2010-06-11  7:50       ` Joel Becker
  0 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2010-06-11  7:19 UTC (permalink / raw)
  To: Tao Ma
  Cc: Christoph Hellwig, linux-fsdevel, linux-kernel, Joel Becker,
	Nick Piggin

On Fri, Jun 11, 2010 at 03:16:13PM +0800, Tao Ma wrote:
> Hi Christoph,
> 
> On 06/11/2010 02:56 PM, Christoph Hellwig wrote:
> >This looks correct, but still has the second if ATTR_SIZE block that
> >I commented on last time.  I'd really prefer if the filesystems could
> >move the truncate handling into a single conditional to simplify
> >auditing for it and possibly splitting it out into a separate method
> >later.
> oh, that would be much work for ocfs2 to do from my perspective. So I 
> would really want to leave it as-is and I have add it to my to-do list.

Oh right, you start a new transaction there.  Sorry, ignore my request
and keep it as it is for now.  I don't think doing truncatate in separate
transactions actually is correct, though but that's no change with this
patch.

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

* Re: [PATCH v4] ocfs2: Let ocfs2_setattr use new truncate sequence.
  2010-06-11  7:19     ` Christoph Hellwig
@ 2010-06-11  7:50       ` Joel Becker
  2010-06-11  7:55         ` Joel Becker
  0 siblings, 1 reply; 7+ messages in thread
From: Joel Becker @ 2010-06-11  7:50 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Tao Ma, linux-fsdevel, linux-kernel, Nick Piggin

On Fri, Jun 11, 2010 at 09:19:45AM +0200, Christoph Hellwig wrote:
> On Fri, Jun 11, 2010 at 03:16:13PM +0800, Tao Ma wrote:
> > oh, that would be much work for ocfs2 to do from my perspective. So I 
> > would really want to leave it as-is and I have add it to my to-do list.
> 
> Oh right, you start a new transaction there.  Sorry, ignore my request
> and keep it as it is for now.  I don't think doing truncatate in separate
> transactions actually is correct, though but that's no change with this
> patch.

Christoph,
	You're missing the part where actual truncate (reduce i_size)
sets i_size in ocfs2_truncate_file().  So this later code doesn't get
triggered for the truncate case.  It exists for the extend case, where
we extend the allocation in multiple clean transactions, then finally
set i_size in a final transaction.

Joel

-- 

"When choosing between two evils, I always like to try the one
 I've never tried before."
        - Mae West

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker@oracle.com
Phone: (650) 506-8127

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

* Re: [PATCH v4] ocfs2: Let ocfs2_setattr use new truncate sequence.
  2010-06-11  7:50       ` Joel Becker
@ 2010-06-11  7:55         ` Joel Becker
  0 siblings, 0 replies; 7+ messages in thread
From: Joel Becker @ 2010-06-11  7:55 UTC (permalink / raw)
  To: Christoph Hellwig, Tao Ma, linux-fsdevel, linux-kernel,
	Nick Piggin

On Fri, Jun 11, 2010 at 12:50:20AM -0700, Joel Becker wrote:
> On Fri, Jun 11, 2010 at 09:19:45AM +0200, Christoph Hellwig wrote:
> > On Fri, Jun 11, 2010 at 03:16:13PM +0800, Tao Ma wrote:
> > > oh, that would be much work for ocfs2 to do from my perspective. So I 
> > > would really want to leave it as-is and I have add it to my to-do list.
> > 
> > Oh right, you start a new transaction there.  Sorry, ignore my request
> > and keep it as it is for now.  I don't think doing truncatate in separate
> > transactions actually is correct, though but that's no change with this
> > patch.
> 
> Christoph,
> 	You're missing the part where actual truncate (reduce i_size)
> sets i_size in ocfs2_truncate_file().  So this later code doesn't get
> triggered for the truncate case.  It exists for the extend case, where
> we extend the allocation in multiple clean transactions, then finally
> set i_size in a final transaction.

	Actually, ocfs2_extend_file() appears to handle it too.  I don't
think it used to - there were places that had issues with
commit_write()'s update of i_size, etc.  But that's ancient history.  I
wonder if Mark knows.

joel

-- 

Dort wo man Bücher verbrennt, verbrennt man am Ende auch Mensch.
(Wherever they burn books, they will also end up burning people.)
	- Heinrich Heine

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker@oracle.com
Phone: (650) 506-8127

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

end of thread, other threads:[~2010-06-11  7:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-11  3:27 [PATCH v4] ocfs2: Let ocfs2_setattr use new truncate sequence Tao Ma
2010-06-11  4:50 ` Nick Piggin
2010-06-11  6:56 ` Christoph Hellwig
2010-06-11  7:16   ` Tao Ma
2010-06-11  7:19     ` Christoph Hellwig
2010-06-11  7:50       ` Joel Becker
2010-06-11  7:55         ` Joel Becker

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