Skip to content

Commit 1c7ae2d

Browse files
Anne Marie MerrittTrond Myklebust
authored andcommitted
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>
1 parent ce60ab3 commit 1c7ae2d

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
@@ -197,6 +197,7 @@ void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)
197197
if (!(flags & NFS_INO_REVAL_FORCED))
198198
flags &= ~(NFS_INO_INVALID_MODE |
199199
NFS_INO_INVALID_OTHER |
200+
NFS_INO_INVALID_BTIME |
200201
NFS_INO_INVALID_XATTR);
201202
flags &= ~(NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_SIZE);
202203
}
@@ -522,6 +523,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
522523
inode_set_atime(inode, 0, 0);
523524
inode_set_mtime(inode, 0, 0);
524525
inode_set_ctime(inode, 0, 0);
526+
memset(&nfsi->btime, 0, sizeof(nfsi->btime));
525527
inode_set_iversion_raw(inode, 0);
526528
inode->i_size = 0;
527529
clear_nlink(inode);
@@ -545,6 +547,10 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
545547
inode_set_ctime_to_ts(inode, fattr->ctime);
546548
else if (fattr_supported & NFS_ATTR_FATTR_CTIME)
547549
nfs_set_cache_invalid(inode, NFS_INO_INVALID_CTIME);
550+
if (fattr->valid & NFS_ATTR_FATTR_BTIME)
551+
nfsi->btime = fattr->btime;
552+
else if (fattr_supported & NFS_ATTR_FATTR_BTIME)
553+
nfs_set_cache_invalid(inode, NFS_INO_INVALID_BTIME);
548554
if (fattr->valid & NFS_ATTR_FATTR_CHANGE)
549555
inode_set_iversion_raw(inode, fattr->change_attr);
550556
else
@@ -1943,7 +1949,7 @@ static int nfs_inode_finish_partial_attr_update(const struct nfs_fattr *fattr,
19431949
NFS_INO_INVALID_ATIME | NFS_INO_INVALID_CTIME |
19441950
NFS_INO_INVALID_MTIME | NFS_INO_INVALID_SIZE |
19451951
NFS_INO_INVALID_BLOCKS | NFS_INO_INVALID_OTHER |
1946-
NFS_INO_INVALID_NLINK;
1952+
NFS_INO_INVALID_NLINK | NFS_INO_INVALID_BTIME;
19471953
unsigned long cache_validity = NFS_I(inode)->cache_validity;
19481954
enum nfs4_change_attr_type ctype = NFS_SERVER(inode)->change_attr_type;
19491955

@@ -2304,7 +2310,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
23042310
| NFS_INO_INVALID_BLOCKS
23052311
| NFS_INO_INVALID_NLINK
23062312
| NFS_INO_INVALID_MODE
2307-
| NFS_INO_INVALID_OTHER;
2313+
| NFS_INO_INVALID_OTHER
2314+
| NFS_INO_INVALID_BTIME;
23082315
if (S_ISDIR(inode->i_mode))
23092316
nfs_force_lookup_revalidate(inode);
23102317
attr_changed = true;
@@ -2338,6 +2345,12 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
23382345
nfsi->cache_validity |=
23392346
save_cache_validity & NFS_INO_INVALID_CTIME;
23402347

2348+
if (fattr->valid & NFS_ATTR_FATTR_BTIME)
2349+
nfsi->btime = fattr->btime;
2350+
else if (fattr_supported & NFS_ATTR_FATTR_BTIME)
2351+
nfsi->cache_validity |=
2352+
save_cache_validity & NFS_INO_INVALID_BTIME;
2353+
23412354
/* Check if our cached file size is stale */
23422355
if (fattr->valid & NFS_ATTR_FATTR_SIZE) {
23432356
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
@@ -222,6 +222,7 @@ const u32 nfs4_fattr_bitmap[3] = {
222222
| FATTR4_WORD1_RAWDEV
223223
| FATTR4_WORD1_SPACE_USED
224224
| FATTR4_WORD1_TIME_ACCESS
225+
| FATTR4_WORD1_TIME_CREATE
225226
| FATTR4_WORD1_TIME_METADATA
226227
| FATTR4_WORD1_TIME_MODIFY
227228
| FATTR4_WORD1_MOUNTED_ON_FILEID,
@@ -243,6 +244,7 @@ static const u32 nfs4_pnfs_open_bitmap[3] = {
243244
| FATTR4_WORD1_RAWDEV
244245
| FATTR4_WORD1_SPACE_USED
245246
| FATTR4_WORD1_TIME_ACCESS
247+
| FATTR4_WORD1_TIME_CREATE
246248
| FATTR4_WORD1_TIME_METADATA
247249
| FATTR4_WORD1_TIME_MODIFY,
248250
FATTR4_WORD2_MDSTHRESHOLD
@@ -323,6 +325,9 @@ static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src,
323325
if (!(cache_validity & NFS_INO_INVALID_OTHER))
324326
dst[1] &= ~(FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP);
325327

328+
if (!(cache_validity & NFS_INO_INVALID_BTIME))
329+
dst[1] &= ~FATTR4_WORD1_TIME_CREATE;
330+
326331
if (nfs_have_delegated_mtime(inode)) {
327332
if (!(cache_validity & NFS_INO_INVALID_ATIME))
328333
dst[1] &= ~(FATTR4_WORD1_TIME_ACCESS|FATTR4_WORD1_TIME_ACCESS_SET);
@@ -1307,7 +1312,8 @@ nfs4_update_changeattr_locked(struct inode *inode,
13071312
NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL |
13081313
NFS_INO_INVALID_SIZE | NFS_INO_INVALID_OTHER |
13091314
NFS_INO_INVALID_BLOCKS | NFS_INO_INVALID_NLINK |
1310-
NFS_INO_INVALID_MODE | NFS_INO_INVALID_XATTR;
1315+
NFS_INO_INVALID_MODE | NFS_INO_INVALID_BTIME |
1316+
NFS_INO_INVALID_XATTR;
13111317
nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
13121318
}
13131319
nfsi->attrtimeo_timestamp = jiffies;
@@ -4047,6 +4053,10 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f
40474053
server->fattr_valid &= ~NFS_ATTR_FATTR_CTIME;
40484054
if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY))
40494055
server->fattr_valid &= ~NFS_ATTR_FATTR_MTIME;
4056+
if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY))
4057+
server->fattr_valid &= ~NFS_ATTR_FATTR_MTIME;
4058+
if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_CREATE))
4059+
server->fattr_valid &= ~NFS_ATTR_FATTR_BTIME;
40504060
memcpy(server->attr_bitmask_nl, res.attr_bitmask,
40514061
sizeof(server->attr_bitmask));
40524062
server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
@@ -5781,6 +5791,8 @@ void nfs4_bitmask_set(__u32 bitmask[], const __u32 src[],
57815791
bitmask[1] |= FATTR4_WORD1_TIME_MODIFY;
57825792
if (cache_validity & NFS_INO_INVALID_BLOCKS)
57835793
bitmask[1] |= FATTR4_WORD1_SPACE_USED;
5794+
if (cache_validity & NFS_INO_INVALID_BTIME)
5795+
bitmask[1] |= FATTR4_WORD1_TIME_CREATE;
57845796

57855797
if (cache_validity & NFS_INO_INVALID_SIZE)
57865798
bitmask[0] |= FATTR4_WORD0_SIZE;

fs/nfs/nfs4xdr.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,7 @@ static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg
16231623
| FATTR4_WORD1_RAWDEV
16241624
| FATTR4_WORD1_SPACE_USED
16251625
| FATTR4_WORD1_TIME_ACCESS
1626+
| FATTR4_WORD1_TIME_CREATE
16261627
| FATTR4_WORD1_TIME_METADATA
16271628
| FATTR4_WORD1_TIME_MODIFY;
16281629
attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
@@ -4207,6 +4208,24 @@ static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, str
42074208
return status;
42084209
}
42094210

4211+
static int decode_attr_time_create(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
4212+
{
4213+
int status = 0;
4214+
4215+
time->tv_sec = 0;
4216+
time->tv_nsec = 0;
4217+
if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_CREATE - 1U)))
4218+
return -EIO;
4219+
if (likely(bitmap[1] & FATTR4_WORD1_TIME_CREATE)) {
4220+
status = decode_attr_time(xdr, time);
4221+
if (status == 0)
4222+
status = NFS_ATTR_FATTR_BTIME;
4223+
bitmap[1] &= ~FATTR4_WORD1_TIME_CREATE;
4224+
}
4225+
dprintk("%s: btime=%lld\n", __func__, time->tv_sec);
4226+
return status;
4227+
}
4228+
42104229
static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
42114230
{
42124231
int status = 0;
@@ -4781,6 +4800,11 @@ static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
47814800
goto xdr_error;
47824801
fattr->valid |= status;
47834802

4803+
status = decode_attr_time_create(xdr, bitmap, &fattr->btime);
4804+
if (status < 0)
4805+
goto xdr_error;
4806+
fattr->valid |= status;
4807+
47844808
status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
47854809
if (status < 0)
47864810
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
@@ -160,6 +160,12 @@ struct nfs_inode {
160160
unsigned long flags; /* atomic bit ops */
161161
unsigned long cache_validity; /* bit mask */
162162

163+
/*
164+
* NFS Attributes not included in struct inode
165+
*/
166+
167+
struct timespec64 btime;
168+
163169
/*
164170
* read_cache_jiffies is when we started read-caching this inode.
165171
* attrtimeo is for how long the cached information is assumed
@@ -316,10 +322,12 @@ struct nfs4_copy_state {
316322
#define NFS_INO_INVALID_XATTR BIT(15) /* xattrs are invalid */
317323
#define NFS_INO_INVALID_NLINK BIT(16) /* cached nlinks is invalid */
318324
#define NFS_INO_INVALID_MODE BIT(17) /* cached mode is invalid */
325+
#define NFS_INO_INVALID_BTIME BIT(18) /* cached btime is invalid */
319326

320327
#define NFS_INO_INVALID_ATTR (NFS_INO_INVALID_CHANGE \
321328
| NFS_INO_INVALID_CTIME \
322329
| NFS_INO_INVALID_MTIME \
330+
| NFS_INO_INVALID_BTIME \
323331
| NFS_INO_INVALID_SIZE \
324332
| NFS_INO_INVALID_NLINK \
325333
| 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)