nfs: update time staps on truncate
Subsystems (2)
PATCH 1/1 nfs: update time staps on truncate
The VFS handles attributes on truncate in a strange way, fix NFS to handle it properly by copying a small code sniplet from XFS.
--- fs/nfs/inode.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
fs/nfs/inode.c +21 -1
@@ -505,8 +505,28 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr) attr->ia_valid &= ~ATTR_MODE ;if (attr->ia_valid &ATTR_SIZE ) { -if (!S_ISREG (inode->i_mode) || attr->ia_size ==i_size_read (inode)) +if (!S_ISREG (inode->i_mode) || + attr->ia_size ==i_size_read (inode)) attr->ia_valid &= ~ATTR_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. +* +* The regular truncate() case without ATTR_CTIME and +* ATTR_MTIME is a special case where we need to update the +* times despite not having these flags set. For all other +* operations the VFS set these flags explicitly if it wants +* a timestamp update. +*/ +if (attr->ia_size !=i_size_read (inode) && + !(attr->ia_valid & (ATTR_CTIME |ATTR_MTIME ))) { + attr->ia_ctime = attr->ia_mtime = +current_fs_time (inode->i_sb); + attr->ia_valid |=ATTR_CTIME |ATTR_MTIME ; + } }/* Optimization: if the end result is no change, don't RPC */
Signature · 1 line
1.9.1
Hi Christoph,
Quoted 31 lines · Christoph Hellwig
The VFS handles attributes on truncate in a strange way, fix NFS to handle it properly by copying a small code sniplet from XFS.
Signed-off-by Christoph Hellwig <[email protected]>--- fs/nfs/inode.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)fs/nfs/inode.c +13
-1@@ -505,8 +505,28 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr) attr->ia_valid &= ~ATTR_MODE ;if (attr->ia_valid &ATTR_SIZE ) { -if (!S_ISREG (inode->i_mode) || attr->ia_size ==i_size_read (inode)) +if (!S_ISREG (inode->i_mode) || + attr->ia_size ==i_size_read (inode)) attr->ia_valid &= ~ATTR_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. +* +* The regular truncate() case without ATTR_CTIME and +* ATTR_MTIME is a special case where we need to update the +* times despite not having these flags set. For all other +* operations the VFS set these flags explicitly if it wants
fs/nfs/inode.c nfs_setattr(struct dentry *dentry, struct iattr *attr) · line 531
Quoted 10 lines
fs/nfs/inode.c +8
-0+* a timestamp update. +*/ +if (attr->ia_size !=i_size_read (inode) && + !(attr->ia_valid & (ATTR_CTIME |ATTR_MTIME ))) { + attr->ia_ctime = attr->ia_mtime = +current_fs_time (inode->i_sb); + attr->ia_valid |=ATTR_CTIME |ATTR_MTIME ; + } }
We shouldn't need to set attr->ia_ctime/ia_mtime above. We should set the file time to the server clock time.
Also note that instead of checking attr->ia_size != i_size_read(inode), the above should check attr->ia_valid & ATTR_SIZE due to the optimisation above.
Signature · 5 lines
Trond Myklebust Linux NFS client maintainer, PrimaryData [email protected]
Quoted 2 lines · Trond Myklebust
We shouldn't need to set attr->ia_ctime/ia_mtime above. We should set the file time to the server clock time.
True.
Quoted 3 lines
Also note that instead of checking
attr->ia_size!=i_size_read(inode), the above should checkattr->ia_valid&ATTR_SIZEdue to the optimisation above.
Or we could just make it an if/else clause. I'll send out an updated patch ASAP.