Skip to content

Commit

Permalink
nfsd: encode stat->mtime for getattr instead of inode->i_mtime
Browse files Browse the repository at this point in the history
The values of stat->mtime and inode->i_mtime may differ for overlayfs
and stat->mtime is the correct value to use when encoding getattr.
This is also consistent with the fact that other attr times are also
encoded from stat values.

Both callers of lease_get_mtime() already have the value of stat->mtime,
so the only needed change is that lease_get_mtime() will not overwrite
this value with inode->i_mtime in case the inode does not have an
exclusive lease.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
  • Loading branch information
Amir Goldstein authored and J. Bruce Fields committed Feb 8, 2018
1 parent 0078117 commit 76c4794
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
6 changes: 2 additions & 4 deletions fs/locks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1554,9 +1554,9 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
EXPORT_SYMBOL(__break_lease);

/**
* lease_get_mtime - get the last modified time of an inode
* lease_get_mtime - update modified time of an inode with exclusive lease
* @inode: the inode
* @time: pointer to a timespec which will contain the last modified time
* @time: pointer to a timespec which contains the last modified time
*
* This is to force NFS clients to flush their caches for files with
* exclusive leases. The justification is that if someone has an
Expand All @@ -1580,8 +1580,6 @@ void lease_get_mtime(struct inode *inode, struct timespec *time)

if (has_lease)
*time = current_time(inode);
else
*time = inode->i_mtime;
}

EXPORT_SYMBOL(lease_get_mtime);
Expand Down
1 change: 1 addition & 0 deletions fs/nfsd/nfsxdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ encode_fattr(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp,
*p++ = htonl((u32) stat->ino);
*p++ = htonl((u32) stat->atime.tv_sec);
*p++ = htonl(stat->atime.tv_nsec ? stat->atime.tv_nsec / 1000 : 0);
time = stat->mtime;
lease_get_mtime(d_inode(dentry), &time);
*p++ = htonl((u32) time.tv_sec);
*p++ = htonl(time.tv_nsec ? time.tv_nsec / 1000 : 0);
Expand Down

0 comments on commit 76c4794

Please sign in to comment.