Skip to content

Commit 4b54274

Browse files
author
Trond Myklebust
committed
NFS: Return the file btime in the statx results when appropriate
If the server supports the NFSv4.x "create_time" attribute, then return it as part of the statx results. Signed-off-by: Benjamin Coddington <bcodding@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Link: https://lore.kernel.org/r/eae27d6467e08aaa67e0ac6ae7119263a0f83349.1748515333.git.bcodding@redhat.com Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
1 parent 1c7ae2d commit 4b54274

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

fs/nfs/inode.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ static void nfs_readdirplus_parent_cache_hit(struct dentry *dentry)
937937

938938
static u32 nfs_get_valid_attrmask(struct inode *inode)
939939
{
940+
u64 fattr_valid = NFS_SERVER(inode)->fattr_valid;
940941
unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity);
941942
u32 reply_mask = STATX_INO | STATX_TYPE;
942943

@@ -956,6 +957,9 @@ static u32 nfs_get_valid_attrmask(struct inode *inode)
956957
reply_mask |= STATX_UID | STATX_GID;
957958
if (!(cache_validity & NFS_INO_INVALID_BLOCKS))
958959
reply_mask |= STATX_BLOCKS;
960+
if (!(cache_validity & NFS_INO_INVALID_BTIME) &&
961+
(fattr_valid & NFS_ATTR_FATTR_BTIME))
962+
reply_mask |= STATX_BTIME;
959963
if (!(cache_validity & NFS_INO_INVALID_CHANGE))
960964
reply_mask |= STATX_CHANGE_COOKIE;
961965
return reply_mask;
@@ -966,6 +970,7 @@ int nfs_getattr(struct mnt_idmap *idmap, const struct path *path,
966970
{
967971
struct inode *inode = d_inode(path->dentry);
968972
struct nfs_server *server = NFS_SERVER(inode);
973+
u64 fattr_valid = server->fattr_valid;
969974
unsigned long cache_validity;
970975
int err = 0;
971976
bool force_sync = query_flags & AT_STATX_FORCE_SYNC;
@@ -976,9 +981,12 @@ int nfs_getattr(struct mnt_idmap *idmap, const struct path *path,
976981

977982
request_mask &= STATX_TYPE | STATX_MODE | STATX_NLINK | STATX_UID |
978983
STATX_GID | STATX_ATIME | STATX_MTIME | STATX_CTIME |
979-
STATX_INO | STATX_SIZE | STATX_BLOCKS |
984+
STATX_INO | STATX_SIZE | STATX_BLOCKS | STATX_BTIME |
980985
STATX_CHANGE_COOKIE;
981986

987+
if (!(fattr_valid & NFS_ATTR_FATTR_BTIME))
988+
request_mask &= ~STATX_BTIME;
989+
982990
if ((query_flags & AT_STATX_DONT_SYNC) && !force_sync) {
983991
if (readdirplus_enabled)
984992
nfs_readdirplus_parent_cache_hit(path->dentry);
@@ -1010,7 +1018,7 @@ int nfs_getattr(struct mnt_idmap *idmap, const struct path *path,
10101018
/* Is the user requesting attributes that might need revalidation? */
10111019
if (!(request_mask & (STATX_MODE|STATX_NLINK|STATX_ATIME|STATX_CTIME|
10121020
STATX_MTIME|STATX_UID|STATX_GID|
1013-
STATX_SIZE|STATX_BLOCKS|
1021+
STATX_SIZE|STATX_BLOCKS|STATX_BTIME|
10141022
STATX_CHANGE_COOKIE)))
10151023
goto out_no_revalidate;
10161024

@@ -1034,6 +1042,8 @@ int nfs_getattr(struct mnt_idmap *idmap, const struct path *path,
10341042
do_update |= cache_validity & NFS_INO_INVALID_OTHER;
10351043
if (request_mask & STATX_BLOCKS)
10361044
do_update |= cache_validity & NFS_INO_INVALID_BLOCKS;
1045+
if (request_mask & STATX_BTIME)
1046+
do_update |= cache_validity & NFS_INO_INVALID_BTIME;
10371047

10381048
if (do_update) {
10391049
if (readdirplus_enabled)
@@ -1055,6 +1065,7 @@ int nfs_getattr(struct mnt_idmap *idmap, const struct path *path,
10551065
stat->attributes |= STATX_ATTR_CHANGE_MONOTONIC;
10561066
if (S_ISDIR(inode->i_mode))
10571067
stat->blksize = NFS_SERVER(inode)->dtsize;
1068+
stat->btime = NFS_I(inode)->btime;
10581069
out:
10591070
trace_nfs_getattr_exit(inode, err);
10601071
return err;

fs/nfs/nfs4trace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
{ NFS_ATTR_FATTR_CTIME, "CTIME" }, \
3131
{ NFS_ATTR_FATTR_CHANGE, "CHANGE" }, \
3232
{ NFS_ATTR_FATTR_OWNER_NAME, "OWNER_NAME" }, \
33-
{ NFS_ATTR_FATTR_GROUP_NAME, "GROUP_NAME" })
33+
{ NFS_ATTR_FATTR_GROUP_NAME, "GROUP_NAME" }, \
34+
{ NFS_ATTR_FATTR_BTIME, "BTIME" })
3435

3536
DECLARE_EVENT_CLASS(nfs4_clientid_event,
3637
TP_PROTO(

0 commit comments

Comments
 (0)