public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] Don't change ctime in truncate is size does not change
@ 2008-02-18 23:32 David Chinner
  2008-02-18 23:37 ` Mark Goodwin
  2008-02-20 23:26 ` Christoph Hellwig
  0 siblings, 2 replies; 5+ messages in thread
From: David Chinner @ 2008-02-18 23:32 UTC (permalink / raw)
  To: xfs-dev; +Cc: xfs-oss


XFS changes the c/mtime of an inode when truncating it to the same
size. The c/mtime is only supposed to change if the size is changed.
Not to be confused with ftruncate, where the c/mtime is supposed to
be changed even if the size is not changed.

The Linux VFS encodes this semantic difference in the flags it sends
down to ->setattr, which XFS currently ignores. We need to make XFS
pay attention to the VFS flags and hence Do The Right Thing.

Signed-off-by: Dave Chinner <dgc@sgi.com>
---
 fs/xfs/xfs_vnodeops.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Index: 2.6.x-xfs-new/fs/xfs/xfs_vnodeops.c
===================================================================
--- 2.6.x-xfs-new.orig/fs/xfs/xfs_vnodeops.c	2008-01-25 16:03:23.654971763 +1100
+++ 2.6.x-xfs-new/fs/xfs/xfs_vnodeops.c	2008-01-25 16:10:30.875397129 +1100
@@ -634,6 +634,15 @@ xfs_setattr(
 	 * Truncate file.  Must have write permission and not be a directory.
 	 */
 	if (mask & XFS_AT_SIZE) {
+		/*
+		 * Only change the c/mtime if we are changing the size
+		 * or we are explicitly asked to change it. This handles
+		 * the semantic difference between truncate() and ftruncate()
+		 * as implemented in the VFS.
+		 */
+		if (vap->va_size != ip->i_size || mask & XFS_AT_CTIME)
+			timeflags |= XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG;
+
 		if (vap->va_size > ip->i_size) {
 			xfs_igrow_finish(tp, ip, vap->va_size,
 			    !(flags & ATTR_DMI));
@@ -662,10 +671,6 @@ xfs_setattr(
 			 */
 			xfs_iflags_set(ip, XFS_ITRUNCATED);
 		}
-		/*
-		 * Have to do this even if the file's size doesn't change.
-		 */
-		timeflags |= XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG;
 	}
 
 	/*

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

* Re: [patch] Don't change ctime in truncate is size does not change
  2008-02-18 23:32 [patch] Don't change ctime in truncate is size does not change David Chinner
@ 2008-02-18 23:37 ` Mark Goodwin
  2008-02-19  1:55   ` David Chinner
  2008-02-20 23:26 ` Christoph Hellwig
  1 sibling, 1 reply; 5+ messages in thread
From: Mark Goodwin @ 2008-02-18 23:37 UTC (permalink / raw)
  To: David Chinner; +Cc: xfs-dev, xfs-oss

Did we ever discover what was behind the comment:
"Have to do this even if the file's size doesn't change"

Cheers
-- Mark

David Chinner wrote:
> XFS changes the c/mtime of an inode when truncating it to the same
> size. The c/mtime is only supposed to change if the size is changed.
> Not to be confused with ftruncate, where the c/mtime is supposed to
> be changed even if the size is not changed.
> 
> The Linux VFS encodes this semantic difference in the flags it sends
> down to ->setattr, which XFS currently ignores. We need to make XFS
> pay attention to the VFS flags and hence Do The Right Thing.
> 
> Signed-off-by: Dave Chinner <dgc@sgi.com>
> ---
>  fs/xfs/xfs_vnodeops.c |   13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> Index: 2.6.x-xfs-new/fs/xfs/xfs_vnodeops.c
> ===================================================================
> --- 2.6.x-xfs-new.orig/fs/xfs/xfs_vnodeops.c	2008-01-25 16:03:23.654971763 +1100
> +++ 2.6.x-xfs-new/fs/xfs/xfs_vnodeops.c	2008-01-25 16:10:30.875397129 +1100
> @@ -634,6 +634,15 @@ xfs_setattr(
>  	 * Truncate file.  Must have write permission and not be a directory.
>  	 */
>  	if (mask & XFS_AT_SIZE) {
> +		/*
> +		 * Only change the c/mtime if we are changing the size
> +		 * or we are explicitly asked to change it. This handles
> +		 * the semantic difference between truncate() and ftruncate()
> +		 * as implemented in the VFS.
> +		 */
> +		if (vap->va_size != ip->i_size || mask & XFS_AT_CTIME)
> +			timeflags |= XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG;
> +
>  		if (vap->va_size > ip->i_size) {
>  			xfs_igrow_finish(tp, ip, vap->va_size,
>  			    !(flags & ATTR_DMI));
> @@ -662,10 +671,6 @@ xfs_setattr(
>  			 */
>  			xfs_iflags_set(ip, XFS_ITRUNCATED);
>  		}
> -		/*
> -		 * Have to do this even if the file's size doesn't change.
> -		 */
> -		timeflags |= XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG;
>  	}
>  
>  	/*

-- 

  Mark Goodwin                                  markgw@sgi.com
  Engineering Manager for XFS and PCP    Phone: +61-3-99631937
  SGI Australian Software Group           Cell: +61-4-18969583
-------------------------------------------------------------

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

* Re: [patch] Don't change ctime in truncate is size does not change
  2008-02-18 23:37 ` Mark Goodwin
@ 2008-02-19  1:55   ` David Chinner
  0 siblings, 0 replies; 5+ messages in thread
From: David Chinner @ 2008-02-19  1:55 UTC (permalink / raw)
  To: Mark Goodwin; +Cc: David Chinner, xfs-dev, xfs-oss

On Tue, Feb 19, 2008 at 10:37:48AM +1100, Mark Goodwin wrote:
> Did we ever discover what was behind the comment:
> "Have to do this even if the file's size doesn't change"

It was put there when the patch was checked in - I can only
assume that it was done this way because the old test script
that was being run didn't discriminate between the truncate
and truncate differences.

Basically, both the code and the comment are wrong and needed
to be fixed....

Cheers,

Dave.
-- 
Dave Chinner
Principal Engineer
SGI Australian Software Group

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

* Re: [patch] Don't change ctime in truncate is size does not change
  2008-02-18 23:32 [patch] Don't change ctime in truncate is size does not change David Chinner
  2008-02-18 23:37 ` Mark Goodwin
@ 2008-02-20 23:26 ` Christoph Hellwig
  2008-02-21 22:50   ` David Chinner
  1 sibling, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2008-02-20 23:26 UTC (permalink / raw)
  To: David Chinner; +Cc: xfs-dev, xfs-oss

> +		if (vap->va_size != ip->i_size || mask & XFS_AT_CTIME)

Normal Linux style is to always have braces around the 'foo & bar'
statements to avoid operator precedance problems when re-ordering the
statements.  Otherwise this one looks good.

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

* Re: [patch] Don't change ctime in truncate is size does not change
  2008-02-20 23:26 ` Christoph Hellwig
@ 2008-02-21 22:50   ` David Chinner
  0 siblings, 0 replies; 5+ messages in thread
From: David Chinner @ 2008-02-21 22:50 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: David Chinner, xfs-dev, xfs-oss

On Wed, Feb 20, 2008 at 06:26:15PM -0500, Christoph Hellwig wrote:
> > +		if (vap->va_size != ip->i_size || mask & XFS_AT_CTIME)
> 
> Normal Linux style is to always have braces around the 'foo & bar'
> statements to avoid operator precedance problems when re-ordering the
> statements.  Otherwise this one looks good.

Fixed up. Thank's for the review.

Cheers,

Dave.
-- 
Dave Chinner
Principal Engineer
SGI Australian Software Group

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

end of thread, other threads:[~2008-02-21 22:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-18 23:32 [patch] Don't change ctime in truncate is size does not change David Chinner
2008-02-18 23:37 ` Mark Goodwin
2008-02-19  1:55   ` David Chinner
2008-02-20 23:26 ` Christoph Hellwig
2008-02-21 22:50   ` David Chinner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox