[PATCH 2/2] nfs: update time staps on truncate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The VFS handles attributes on truncate in a strange way, fix NFS to
properly update timestamps on truncate().

Signed-off-by: Christoph Hellwig <hch@xxxxxx>
---
 fs/nfs/inode.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 141c9f4..97bc485 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -507,8 +507,20 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
 	if (attr->ia_valid & ATTR_SIZE) {
 		BUG_ON(!S_ISREG(inode->i_mode));
 
+		/*
+		 * Calling conventions are a little "unconventional" for
+		 * truncate:
+		 *  - for truncate() the VFS does not set ATTR_CTIME and
+		 *    ATTR_MTIME, but we still need need to update the time
+		 *    stamps if we change the file size.
+		 *  - for ftruncate() the VFS sets ATTR_CTIME and ATTR_MTIME,
+		 *    and we always need to change the time stamp, even if
+		 *    the size does not change.
+		 */
 		if (attr->ia_size == i_size_read(inode))
 			attr->ia_valid &= ~ATTR_SIZE;
+		else if (!(attr->ia_valid & (ATTR_CTIME | ATTR_MTIME)))
+			attr->ia_valid |= ATTR_CTIME | ATTR_MTIME;
 	}
 
 	/* Optimization: if the end result is no change, don't RPC */
-- 
1.9.1

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




[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux