NFS: Further fixes to attribute delegation a/mtime changes

When asked to set both an atime and an mtime to the current system time,
ensure that the setting is atomic by calling inode_update_timestamps()
only once with the appropriate flags.

Fixes: e12912d941 ("NFSv4: Add support for delegated atime and mtime attributes")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
This commit is contained in:
Trond Myklebust 2024-10-23 17:05:48 -04:00 committed by Anna Schumaker
parent d054c5eb28
commit 40f45ab381

View File

@ -628,23 +628,35 @@ nfs_fattr_fixup_delegated(struct inode *inode, struct nfs_fattr *fattr)
} }
} }
static void nfs_update_timestamps(struct inode *inode, unsigned int ia_valid)
{
enum file_time_flags time_flags = 0;
unsigned int cache_flags = 0;
if (ia_valid & ATTR_MTIME) {
time_flags |= S_MTIME | S_CTIME;
cache_flags |= NFS_INO_INVALID_CTIME | NFS_INO_INVALID_MTIME;
}
if (ia_valid & ATTR_ATIME) {
time_flags |= S_ATIME;
cache_flags |= NFS_INO_INVALID_ATIME;
}
inode_update_timestamps(inode, time_flags);
NFS_I(inode)->cache_validity &= ~cache_flags;
}
void nfs_update_delegated_atime(struct inode *inode) void nfs_update_delegated_atime(struct inode *inode)
{ {
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
if (nfs_have_delegated_atime(inode)) { if (nfs_have_delegated_atime(inode))
inode_update_timestamps(inode, S_ATIME); nfs_update_timestamps(inode, ATTR_ATIME);
NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_ATIME;
}
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
} }
void nfs_update_delegated_mtime_locked(struct inode *inode) void nfs_update_delegated_mtime_locked(struct inode *inode)
{ {
if (nfs_have_delegated_mtime(inode)) { if (nfs_have_delegated_mtime(inode))
inode_update_timestamps(inode, S_CTIME | S_MTIME); nfs_update_timestamps(inode, ATTR_MTIME);
NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_CTIME |
NFS_INO_INVALID_MTIME);
}
} }
void nfs_update_delegated_mtime(struct inode *inode) void nfs_update_delegated_mtime(struct inode *inode)
@ -682,15 +694,16 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
attr->ia_valid &= ~ATTR_SIZE; attr->ia_valid &= ~ATTR_SIZE;
} }
if (nfs_have_delegated_mtime(inode)) { if (nfs_have_delegated_mtime(inode) && attr->ia_valid & ATTR_MTIME) {
if (attr->ia_valid & ATTR_MTIME) { spin_lock(&inode->i_lock);
nfs_update_delegated_mtime(inode); nfs_update_timestamps(inode, attr->ia_valid);
attr->ia_valid &= ~ATTR_MTIME; spin_unlock(&inode->i_lock);
} attr->ia_valid &= ~(ATTR_MTIME | ATTR_ATIME);
if (attr->ia_valid & ATTR_ATIME) { } else if (nfs_have_delegated_atime(inode) &&
nfs_update_delegated_atime(inode); attr->ia_valid & ATTR_ATIME &&
attr->ia_valid &= ~ATTR_ATIME; !(attr->ia_valid & ATTR_MTIME)) {
} nfs_update_delegated_atime(inode);
attr->ia_valid &= ~ATTR_ATIME;
} }
/* Optimization: if the end result is no change, don't RPC */ /* Optimization: if the end result is no change, don't RPC */