Skip to content

Commit 11c5ddf

Browse files
committed
nfs: Add timecreate to nfs inode
JIRA: https://issues.redhat.com/browse/RHEL-90990 commit 1c7ae2d Author: Anne Marie Merritt <annemarie.merritt@primarydata.com> Date: Thu May 29 06:45:46 2025 -0400 nfs: Add timecreate to nfs inode Add tracking of the create time (a.k.a. btime) along with corresponding bitfields, request, and decode xdr routines. Signed-off-by: Anne Marie Merritt <annemarie.merritt@primarydata.com> Signed-off-by: Lance Shelton <lance.shelton@hammerspace.com> Signed-off-by: Benjamin Coddington <bcodding@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Link: https://lore.kernel.org/r/1e3677b0655fa2bbaba0817b41d111d94a06e5ee.1748515333.git.bcodding@redhat.com Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
1 parent ba976ef commit 11c5ddf

File tree

6 files changed

+65
-4
lines changed

6 files changed

+65
-4
lines changed

fs/nfs/inode.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)
195195
if (!(flags & NFS_INO_REVAL_FORCED))
196196
flags &= ~(NFS_INO_INVALID_MODE |
197197
NFS_INO_INVALID_OTHER |
198+
NFS_INO_INVALID_BTIME |
198199
NFS_INO_INVALID_XATTR);
199200
flags &= ~(NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_SIZE);
200201
}
@@ -519,6 +520,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
519520
memset(&inode->i_atime, 0, sizeof(inode->i_atime));
520521
memset(&inode->i_mtime, 0, sizeof(inode->i_mtime));
521522
inode_set_ctime(inode, 0, 0);
523+
memset(&nfsi->btime, 0, sizeof(nfsi->btime));
522524
inode_set_iversion_raw(inode, 0);
523525
inode->i_size = 0;
524526
clear_nlink(inode);
@@ -542,6 +544,10 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
542544
inode_set_ctime_to_ts(inode, fattr->ctime);
543545
else if (fattr_supported & NFS_ATTR_FATTR_CTIME)
544546
nfs_set_cache_invalid(inode, NFS_INO_INVALID_CTIME);
547+
if (fattr->valid & NFS_ATTR_FATTR_BTIME)
548+
nfsi->btime = fattr->btime;
549+
else if (fattr_supported & NFS_ATTR_FATTR_BTIME)
550+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_BTIME);
545551
if (fattr->valid & NFS_ATTR_FATTR_CHANGE)
546552
inode_set_iversion_raw(inode, fattr->change_attr);
547553
else
@@ -1894,7 +1900,7 @@ static int nfs_inode_finish_partial_attr_update(const struct nfs_fattr *fattr,
18941900
NFS_INO_INVALID_ATIME | NFS_INO_INVALID_CTIME |
18951901
NFS_INO_INVALID_MTIME | NFS_INO_INVALID_SIZE |
18961902
NFS_INO_INVALID_BLOCKS | NFS_INO_INVALID_OTHER |
1897-
NFS_INO_INVALID_NLINK;
1903+
NFS_INO_INVALID_NLINK | NFS_INO_INVALID_BTIME;
18981904
unsigned long cache_validity = NFS_I(inode)->cache_validity;
18991905
enum nfs4_change_attr_type ctype = NFS_SERVER(inode)->change_attr_type;
19001906

@@ -2255,7 +2261,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
22552261
| NFS_INO_INVALID_BLOCKS
22562262
| NFS_INO_INVALID_NLINK
22572263
| NFS_INO_INVALID_MODE
2258-
| NFS_INO_INVALID_OTHER;
2264+
| NFS_INO_INVALID_OTHER
2265+
| NFS_INO_INVALID_BTIME;
22592266
if (S_ISDIR(inode->i_mode))
22602267
nfs_force_lookup_revalidate(inode);
22612268
attr_changed = true;
@@ -2289,6 +2296,12 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
22892296
nfsi->cache_validity |=
22902297
save_cache_validity & NFS_INO_INVALID_CTIME;
22912298

2299+
if (fattr->valid & NFS_ATTR_FATTR_BTIME)
2300+
nfsi->btime = fattr->btime;
2301+
else if (fattr_supported & NFS_ATTR_FATTR_BTIME)
2302+
nfsi->cache_validity |=
2303+
save_cache_validity & NFS_INO_INVALID_BTIME;
2304+
22922305
/* Check if our cached file size is stale */
22932306
if (fattr->valid & NFS_ATTR_FATTR_SIZE) {
22942307
new_isize = nfs_size_to_loff_t(fattr->size);

fs/nfs/nfs4proc.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ const u32 nfs4_fattr_bitmap[3] = {
210210
| FATTR4_WORD1_RAWDEV
211211
| FATTR4_WORD1_SPACE_USED
212212
| FATTR4_WORD1_TIME_ACCESS
213+
| FATTR4_WORD1_TIME_CREATE
213214
| FATTR4_WORD1_TIME_METADATA
214215
| FATTR4_WORD1_TIME_MODIFY
215216
| FATTR4_WORD1_MOUNTED_ON_FILEID,
@@ -231,6 +232,7 @@ static const u32 nfs4_pnfs_open_bitmap[3] = {
231232
| FATTR4_WORD1_RAWDEV
232233
| FATTR4_WORD1_SPACE_USED
233234
| FATTR4_WORD1_TIME_ACCESS
235+
| FATTR4_WORD1_TIME_CREATE
234236
| FATTR4_WORD1_TIME_METADATA
235237
| FATTR4_WORD1_TIME_MODIFY,
236238
FATTR4_WORD2_MDSTHRESHOLD
@@ -311,6 +313,9 @@ static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src,
311313
if (!(cache_validity & NFS_INO_INVALID_OTHER))
312314
dst[1] &= ~(FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP);
313315

316+
if (!(cache_validity & NFS_INO_INVALID_BTIME))
317+
dst[1] &= ~FATTR4_WORD1_TIME_CREATE;
318+
314319
if (nfs_have_delegated_mtime(inode)) {
315320
if (!(cache_validity & NFS_INO_INVALID_ATIME))
316321
dst[1] &= ~FATTR4_WORD1_TIME_ACCESS;
@@ -1282,7 +1287,8 @@ nfs4_update_changeattr_locked(struct inode *inode,
12821287
NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL |
12831288
NFS_INO_INVALID_SIZE | NFS_INO_INVALID_OTHER |
12841289
NFS_INO_INVALID_BLOCKS | NFS_INO_INVALID_NLINK |
1285-
NFS_INO_INVALID_MODE | NFS_INO_INVALID_XATTR;
1290+
NFS_INO_INVALID_MODE | NFS_INO_INVALID_BTIME |
1291+
NFS_INO_INVALID_XATTR;
12861292
nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
12871293
}
12881294
nfsi->attrtimeo_timestamp = jiffies;
@@ -4020,6 +4026,10 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f
40204026
server->fattr_valid &= ~NFS_ATTR_FATTR_CTIME;
40214027
if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY))
40224028
server->fattr_valid &= ~NFS_ATTR_FATTR_MTIME;
4029+
if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY))
4030+
server->fattr_valid &= ~NFS_ATTR_FATTR_MTIME;
4031+
if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_CREATE))
4032+
server->fattr_valid &= ~NFS_ATTR_FATTR_BTIME;
40234033
memcpy(server->attr_bitmask_nl, res.attr_bitmask,
40244034
sizeof(server->attr_bitmask));
40254035
server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
@@ -5727,6 +5737,8 @@ void nfs4_bitmask_set(__u32 bitmask[], const __u32 src[],
57275737
bitmask[1] |= FATTR4_WORD1_TIME_MODIFY;
57285738
if (cache_validity & NFS_INO_INVALID_BLOCKS)
57295739
bitmask[1] |= FATTR4_WORD1_SPACE_USED;
5740+
if (cache_validity & NFS_INO_INVALID_BTIME)
5741+
bitmask[1] |= FATTR4_WORD1_TIME_CREATE;
57305742

57315743
if (cache_validity & NFS_INO_INVALID_SIZE)
57325744
bitmask[0] |= FATTR4_WORD0_SIZE;

fs/nfs/nfs4xdr.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,7 @@ static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg
16311631
| FATTR4_WORD1_RAWDEV
16321632
| FATTR4_WORD1_SPACE_USED
16331633
| FATTR4_WORD1_TIME_ACCESS
1634+
| FATTR4_WORD1_TIME_CREATE
16341635
| FATTR4_WORD1_TIME_METADATA
16351636
| FATTR4_WORD1_TIME_MODIFY;
16361637
attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
@@ -4215,6 +4216,24 @@ static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, str
42154216
return status;
42164217
}
42174218

4219+
static int decode_attr_time_create(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
4220+
{
4221+
int status = 0;
4222+
4223+
time->tv_sec = 0;
4224+
time->tv_nsec = 0;
4225+
if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_CREATE - 1U)))
4226+
return -EIO;
4227+
if (likely(bitmap[1] & FATTR4_WORD1_TIME_CREATE)) {
4228+
status = decode_attr_time(xdr, time);
4229+
if (status == 0)
4230+
status = NFS_ATTR_FATTR_BTIME;
4231+
bitmap[1] &= ~FATTR4_WORD1_TIME_CREATE;
4232+
}
4233+
dprintk("%s: btime=%lld\n", __func__, time->tv_sec);
4234+
return status;
4235+
}
4236+
42184237
static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
42194238
{
42204239
int status = 0;
@@ -4798,6 +4817,11 @@ static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
47984817
goto xdr_error;
47994818
fattr->valid |= status;
48004819

4820+
status = decode_attr_time_create(xdr, bitmap, &fattr->btime);
4821+
if (status < 0)
4822+
goto xdr_error;
4823+
fattr->valid |= status;
4824+
48014825
status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
48024826
if (status < 0)
48034827
goto xdr_error;

fs/nfs/nfstrace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
{ NFS_INO_INVALID_BLOCKS, "INVALID_BLOCKS" }, \
3333
{ NFS_INO_INVALID_XATTR, "INVALID_XATTR" }, \
3434
{ NFS_INO_INVALID_NLINK, "INVALID_NLINK" }, \
35-
{ NFS_INO_INVALID_MODE, "INVALID_MODE" })
35+
{ NFS_INO_INVALID_MODE, "INVALID_MODE" }, \
36+
{ NFS_INO_INVALID_BTIME, "INVALID_BTIME" })
3637

3738
#define nfs_show_nfsi_flags(v) \
3839
__print_flags(v, "|", \

include/linux/nfs_fs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ struct nfs_inode {
142142
unsigned long flags; /* atomic bit ops */
143143
unsigned long cache_validity; /* bit mask */
144144

145+
/*
146+
* NFS Attributes not included in struct inode
147+
*/
148+
149+
struct timespec64 btime;
150+
145151
/*
146152
* read_cache_jiffies is when we started read-caching this inode.
147153
* attrtimeo is for how long the cached information is assumed
@@ -298,10 +304,12 @@ struct nfs4_copy_state {
298304
#define NFS_INO_INVALID_XATTR BIT(15) /* xattrs are invalid */
299305
#define NFS_INO_INVALID_NLINK BIT(16) /* cached nlinks is invalid */
300306
#define NFS_INO_INVALID_MODE BIT(17) /* cached mode is invalid */
307+
#define NFS_INO_INVALID_BTIME BIT(18) /* cached btime is invalid */
301308

302309
#define NFS_INO_INVALID_ATTR (NFS_INO_INVALID_CHANGE \
303310
| NFS_INO_INVALID_CTIME \
304311
| NFS_INO_INVALID_MTIME \
312+
| NFS_INO_INVALID_BTIME \
305313
| NFS_INO_INVALID_SIZE \
306314
| NFS_INO_INVALID_NLINK \
307315
| NFS_INO_INVALID_MODE \

include/linux/nfs_xdr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct nfs_fattr {
6767
struct timespec64 atime;
6868
struct timespec64 mtime;
6969
struct timespec64 ctime;
70+
struct timespec64 btime;
7071
__u64 change_attr; /* NFSv4 change attribute */
7172
__u64 pre_change_attr;/* pre-op NFSv4 change attribute */
7273
__u64 pre_size; /* pre_op_attr.size */
@@ -106,6 +107,7 @@ struct nfs_fattr {
106107
#define NFS_ATTR_FATTR_OWNER_NAME BIT_ULL(23)
107108
#define NFS_ATTR_FATTR_GROUP_NAME BIT_ULL(24)
108109
#define NFS_ATTR_FATTR_V4_SECURITY_LABEL BIT_ULL(25)
110+
#define NFS_ATTR_FATTR_BTIME BIT_ULL(26)
109111

110112
#define NFS_ATTR_FATTR (NFS_ATTR_FATTR_TYPE \
111113
| NFS_ATTR_FATTR_MODE \
@@ -126,6 +128,7 @@ struct nfs_fattr {
126128
| NFS_ATTR_FATTR_SPACE_USED)
127129
#define NFS_ATTR_FATTR_V4 (NFS_ATTR_FATTR \
128130
| NFS_ATTR_FATTR_SPACE_USED \
131+
| NFS_ATTR_FATTR_BTIME \
129132
| NFS_ATTR_FATTR_V4_SECURITY_LABEL)
130133

131134
/*

0 commit comments

Comments
 (0)