hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/fs/nfs/inode.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/fs/nfs/inode.c
34 *
....@@ -50,6 +51,7 @@
5051 #include "pnfs.h"
5152 #include "nfs.h"
5253 #include "netns.h"
54
+#include "sysfs.h"
5355
5456 #include "nfstrace.h"
5557
....@@ -60,7 +62,6 @@
6062 /* Default is to see 64-bit inode numbers */
6163 static bool enable_ino64 = NFS_64_BIT_INODE_NUMBERS_ENABLED;
6264
63
-static void nfs_invalidate_inode(struct inode *);
6465 static int nfs_update_inode(struct inode *, struct nfs_fattr *);
6566
6667 static struct kmem_cache * nfs_inode_cachep;
....@@ -143,6 +144,7 @@
143144
144145 /**
145146 * nfs_sync_mapping - helper to flush all mmapped dirty data to disk
147
+ * @mapping: pointer to struct address_space
146148 */
147149 int nfs_sync_mapping(struct address_space *mapping)
148150 {
....@@ -191,6 +193,19 @@
191193
192194 return nfs_check_cache_invalid_not_delegated(inode, flags);
193195 }
196
+EXPORT_SYMBOL_GPL(nfs_check_cache_invalid);
197
+
198
+#ifdef CONFIG_NFS_V4_2
199
+static bool nfs_has_xattr_cache(const struct nfs_inode *nfsi)
200
+{
201
+ return nfsi->xattr_cache != NULL;
202
+}
203
+#else
204
+static bool nfs_has_xattr_cache(const struct nfs_inode *nfsi)
205
+{
206
+ return false;
207
+}
208
+#endif
194209
195210 static void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)
196211 {
....@@ -202,11 +217,15 @@
202217 flags &= ~NFS_INO_INVALID_OTHER;
203218 flags &= ~(NFS_INO_INVALID_CHANGE
204219 | NFS_INO_INVALID_SIZE
205
- | NFS_INO_REVAL_PAGECACHE);
206
- }
220
+ | NFS_INO_REVAL_PAGECACHE
221
+ | NFS_INO_INVALID_XATTR);
222
+ } else if (flags & NFS_INO_REVAL_PAGECACHE)
223
+ flags |= NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_SIZE;
207224
225
+ if (!nfs_has_xattr_cache(nfsi))
226
+ flags &= ~NFS_INO_INVALID_XATTR;
208227 if (inode->i_mapping->nrpages == 0)
209
- flags &= ~NFS_INO_INVALID_DATA;
228
+ flags &= ~(NFS_INO_INVALID_DATA|NFS_INO_DATA_INVAL_DEFER);
210229 nfsi->cache_validity |= flags;
211230 if (flags & NFS_INO_INVALID_DATA)
212231 nfs_fscache_invalidate(inode);
....@@ -231,11 +250,13 @@
231250 | NFS_INO_INVALID_DATA
232251 | NFS_INO_INVALID_ACCESS
233252 | NFS_INO_INVALID_ACL
253
+ | NFS_INO_INVALID_XATTR
234254 | NFS_INO_REVAL_PAGECACHE);
235255 } else
236256 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR
237257 | NFS_INO_INVALID_ACCESS
238258 | NFS_INO_INVALID_ACL
259
+ | NFS_INO_INVALID_XATTR
239260 | NFS_INO_REVAL_PAGECACHE);
240261 nfs_zap_label_cache_locked(nfsi);
241262 }
....@@ -281,10 +302,18 @@
281302 * Invalidate, but do not unhash, the inode.
282303 * NB: must be called with inode->i_lock held!
283304 */
284
-static void nfs_invalidate_inode(struct inode *inode)
305
+static void nfs_set_inode_stale_locked(struct inode *inode)
285306 {
286307 set_bit(NFS_INO_STALE, &NFS_I(inode)->flags);
287308 nfs_zap_caches_locked(inode);
309
+ trace_nfs_set_inode_stale(inode);
310
+}
311
+
312
+void nfs_set_inode_stale(struct inode *inode)
313
+{
314
+ spin_lock(&inode->i_lock);
315
+ nfs_set_inode_stale_locked(inode);
316
+ spin_unlock(&inode->i_lock);
288317 }
289318
290319 struct nfs_find_desc {
....@@ -307,7 +336,7 @@
307336
308337 if (NFS_FILEID(inode) != fattr->fileid)
309338 return 0;
310
- if ((S_IFMT & inode->i_mode) != (S_IFMT & fattr->mode))
339
+ if (inode_wrong_type(inode, fattr->mode))
311340 return 0;
312341 if (nfs_compare_fh(NFS_FH(inode), fh))
313342 return 0;
....@@ -501,15 +530,15 @@
501530 nfsi->read_cache_jiffies = fattr->time_start;
502531 nfsi->attr_gencount = fattr->gencount;
503532 if (fattr->valid & NFS_ATTR_FATTR_ATIME)
504
- inode->i_atime = timespec_to_timespec64(fattr->atime);
533
+ inode->i_atime = fattr->atime;
505534 else if (nfs_server_capable(inode, NFS_CAP_ATIME))
506535 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME);
507536 if (fattr->valid & NFS_ATTR_FATTR_MTIME)
508
- inode->i_mtime = timespec_to_timespec64(fattr->mtime);
537
+ inode->i_mtime = fattr->mtime;
509538 else if (nfs_server_capable(inode, NFS_CAP_MTIME))
510539 nfs_set_cache_invalid(inode, NFS_INO_INVALID_MTIME);
511540 if (fattr->valid & NFS_ATTR_FATTR_CTIME)
512
- inode->i_ctime = timespec_to_timespec64(fattr->ctime);
541
+ inode->i_ctime = fattr->ctime;
513542 else if (nfs_server_capable(inode, NFS_CAP_CTIME))
514543 nfs_set_cache_invalid(inode, NFS_INO_INVALID_CTIME);
515544 if (fattr->valid & NFS_ATTR_FATTR_CHANGE)
....@@ -532,6 +561,8 @@
532561 inode->i_gid = fattr->gid;
533562 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
534563 nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER);
564
+ if (nfs_server_capable(inode, NFS_CAP_XATTR))
565
+ nfs_set_cache_invalid(inode, NFS_INO_INVALID_XATTR);
535566 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
536567 inode->i_blocks = fattr->du.nfs2.blocks;
537568 if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) {
....@@ -650,7 +681,8 @@
650681 i_size_write(inode, offset);
651682 /* Optimisation */
652683 if (offset == 0)
653
- NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_DATA;
684
+ NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_DATA |
685
+ NFS_INO_DATA_INVAL_DEFER);
654686 NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_SIZE;
655687
656688 spin_unlock(&inode->i_lock);
....@@ -694,7 +726,7 @@
694726 if ((attr->ia_valid & ATTR_GID) != 0)
695727 inode->i_gid = attr->ia_gid;
696728 if (fattr->valid & NFS_ATTR_FATTR_CTIME)
697
- inode->i_ctime = timespec_to_timespec64(fattr->ctime);
729
+ inode->i_ctime = fattr->ctime;
698730 else
699731 nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE
700732 | NFS_INO_INVALID_CTIME);
....@@ -705,14 +737,14 @@
705737 NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_ATIME
706738 | NFS_INO_INVALID_CTIME);
707739 if (fattr->valid & NFS_ATTR_FATTR_ATIME)
708
- inode->i_atime = timespec_to_timespec64(fattr->atime);
740
+ inode->i_atime = fattr->atime;
709741 else if (attr->ia_valid & ATTR_ATIME_SET)
710742 inode->i_atime = attr->ia_atime;
711743 else
712744 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME);
713745
714746 if (fattr->valid & NFS_ATTR_FATTR_CTIME)
715
- inode->i_ctime = timespec_to_timespec64(fattr->ctime);
747
+ inode->i_ctime = fattr->ctime;
716748 else
717749 nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE
718750 | NFS_INO_INVALID_CTIME);
....@@ -721,14 +753,14 @@
721753 NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_MTIME
722754 | NFS_INO_INVALID_CTIME);
723755 if (fattr->valid & NFS_ATTR_FATTR_MTIME)
724
- inode->i_mtime = timespec_to_timespec64(fattr->mtime);
756
+ inode->i_mtime = fattr->mtime;
725757 else if (attr->ia_valid & ATTR_MTIME_SET)
726758 inode->i_mtime = attr->ia_mtime;
727759 else
728760 nfs_set_cache_invalid(inode, NFS_INO_INVALID_MTIME);
729761
730762 if (fattr->valid & NFS_ATTR_FATTR_CTIME)
731
- inode->i_ctime = timespec_to_timespec64(fattr->ctime);
763
+ inode->i_ctime = fattr->ctime;
732764 else
733765 nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE
734766 | NFS_INO_INVALID_CTIME);
....@@ -783,8 +815,10 @@
783815
784816 trace_nfs_getattr_enter(inode);
785817
786
- if ((query_flags & AT_STATX_DONT_SYNC) && !force_sync)
818
+ if ((query_flags & AT_STATX_DONT_SYNC) && !force_sync) {
819
+ nfs_readdirplus_parent_cache_hit(path->dentry);
787820 goto out_no_update;
821
+ }
788822
789823 /* Flush out writes to the server in order to update c/mtime. */
790824 if ((request_mask & (STATX_CTIME | STATX_MTIME)) &&
....@@ -819,6 +853,8 @@
819853 do_update |= cache_validity & NFS_INO_INVALID_ATIME;
820854 if (request_mask & (STATX_CTIME|STATX_MTIME))
821855 do_update |= cache_validity & NFS_INO_REVAL_PAGECACHE;
856
+ if (request_mask & STATX_BLOCKS)
857
+ do_update |= cache_validity & NFS_INO_INVALID_BLOCKS;
822858 if (do_update) {
823859 /* Update the attribute cache */
824860 if (!(server->flags & NFS_MOUNT_NOAC))
....@@ -854,15 +890,14 @@
854890
855891 static struct nfs_lock_context *__nfs_find_lock_context(struct nfs_open_context *ctx)
856892 {
857
- struct nfs_lock_context *head = &ctx->lock_context;
858
- struct nfs_lock_context *pos = head;
893
+ struct nfs_lock_context *pos;
859894
860
- do {
895
+ list_for_each_entry_rcu(pos, &ctx->lock_context.list, list) {
861896 if (pos->lockowner != current->files)
862897 continue;
863
- refcount_inc(&pos->count);
864
- return pos;
865
- } while ((pos = list_entry(pos->list.next, typeof(*pos), list)) != head);
898
+ if (refcount_inc_not_zero(&pos->count))
899
+ return pos;
900
+ }
866901 return NULL;
867902 }
868903
....@@ -871,10 +906,10 @@
871906 struct nfs_lock_context *res, *new = NULL;
872907 struct inode *inode = d_inode(ctx->dentry);
873908
874
- spin_lock(&inode->i_lock);
909
+ rcu_read_lock();
875910 res = __nfs_find_lock_context(ctx);
911
+ rcu_read_unlock();
876912 if (res == NULL) {
877
- spin_unlock(&inode->i_lock);
878913 new = kmalloc(sizeof(*new), GFP_KERNEL);
879914 if (new == NULL)
880915 return ERR_PTR(-ENOMEM);
....@@ -882,14 +917,18 @@
882917 spin_lock(&inode->i_lock);
883918 res = __nfs_find_lock_context(ctx);
884919 if (res == NULL) {
885
- list_add_tail(&new->list, &ctx->lock_context.list);
886
- new->open_context = ctx;
887
- res = new;
888
- new = NULL;
920
+ new->open_context = get_nfs_open_context(ctx);
921
+ if (new->open_context) {
922
+ list_add_tail_rcu(&new->list,
923
+ &ctx->lock_context.list);
924
+ res = new;
925
+ new = NULL;
926
+ } else
927
+ res = ERR_PTR(-EBADF);
889928 }
929
+ spin_unlock(&inode->i_lock);
930
+ kfree(new);
890931 }
891
- spin_unlock(&inode->i_lock);
892
- kfree(new);
893932 return res;
894933 }
895934 EXPORT_SYMBOL_GPL(nfs_get_lock_context);
....@@ -901,9 +940,10 @@
901940
902941 if (!refcount_dec_and_lock(&l_ctx->count, &inode->i_lock))
903942 return;
904
- list_del(&l_ctx->list);
943
+ list_del_rcu(&l_ctx->list);
905944 spin_unlock(&inode->i_lock);
906
- kfree(l_ctx);
945
+ put_nfs_open_context(ctx);
946
+ kfree_rcu(l_ctx, rcu_head);
907947 }
908948 EXPORT_SYMBOL_GPL(nfs_put_lock_context);
909949
....@@ -948,18 +988,17 @@
948988 struct file *filp)
949989 {
950990 struct nfs_open_context *ctx;
951
- struct rpc_cred *cred = rpc_lookup_cred();
952
- if (IS_ERR(cred))
953
- return ERR_CAST(cred);
954991
955992 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
956
- if (!ctx) {
957
- put_rpccred(cred);
993
+ if (!ctx)
958994 return ERR_PTR(-ENOMEM);
959
- }
960995 nfs_sb_active(dentry->d_sb);
961996 ctx->dentry = dget(dentry);
962
- ctx->cred = cred;
997
+ if (filp)
998
+ ctx->cred = get_cred(filp->f_cred);
999
+ else
1000
+ ctx->cred = get_current_cred();
1001
+ ctx->ll_cred = NULL;
9631002 ctx->state = NULL;
9641003 ctx->mode = f_mode;
9651004 ctx->flags = 0;
....@@ -975,9 +1014,9 @@
9751014
9761015 struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx)
9771016 {
978
- if (ctx != NULL)
979
- refcount_inc(&ctx->lock_context.count);
980
- return ctx;
1017
+ if (ctx != NULL && refcount_inc_not_zero(&ctx->lock_context.count))
1018
+ return ctx;
1019
+ return NULL;
9811020 }
9821021 EXPORT_SYMBOL_GPL(get_nfs_open_context);
9831022
....@@ -986,21 +1025,21 @@
9861025 struct inode *inode = d_inode(ctx->dentry);
9871026 struct super_block *sb = ctx->dentry->d_sb;
9881027
989
- if (!list_empty(&ctx->list)) {
990
- if (!refcount_dec_and_lock(&ctx->lock_context.count, &inode->i_lock))
991
- return;
992
- list_del(&ctx->list);
993
- spin_unlock(&inode->i_lock);
994
- } else if (!refcount_dec_and_test(&ctx->lock_context.count))
1028
+ if (!refcount_dec_and_test(&ctx->lock_context.count))
9951029 return;
1030
+ if (!list_empty(&ctx->list)) {
1031
+ spin_lock(&inode->i_lock);
1032
+ list_del_rcu(&ctx->list);
1033
+ spin_unlock(&inode->i_lock);
1034
+ }
9961035 if (inode != NULL)
9971036 NFS_PROTO(inode)->close_context(ctx, is_sync);
998
- if (ctx->cred != NULL)
999
- put_rpccred(ctx->cred);
1037
+ put_cred(ctx->cred);
10001038 dput(ctx->dentry);
10011039 nfs_sb_deactive(sb);
1040
+ put_rpccred(ctx->ll_cred);
10021041 kfree(ctx->mdsthreshold);
1003
- kfree(ctx);
1042
+ kfree_rcu(ctx, rcu_head);
10041043 }
10051044
10061045 void put_nfs_open_context(struct nfs_open_context *ctx)
....@@ -1024,10 +1063,11 @@
10241063 struct nfs_inode *nfsi = NFS_I(inode);
10251064
10261065 spin_lock(&inode->i_lock);
1027
- if (ctx->mode & FMODE_WRITE)
1028
- list_add(&ctx->list, &nfsi->open_files);
1029
- else
1030
- list_add_tail(&ctx->list, &nfsi->open_files);
1066
+ if (list_empty(&nfsi->open_files) &&
1067
+ (nfsi->cache_validity & NFS_INO_DATA_INVAL_DEFER))
1068
+ nfsi->cache_validity |= NFS_INO_INVALID_DATA |
1069
+ NFS_INO_REVAL_FORCED;
1070
+ list_add_tail_rcu(&ctx->list, &nfsi->open_files);
10311071 spin_unlock(&inode->i_lock);
10321072 }
10331073 EXPORT_SYMBOL_GPL(nfs_inode_attach_open_context);
....@@ -1044,23 +1084,24 @@
10441084 /*
10451085 * Given an inode, search for an open context with the desired characteristics
10461086 */
1047
-struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, fmode_t mode)
1087
+struct nfs_open_context *nfs_find_open_context(struct inode *inode, const struct cred *cred, fmode_t mode)
10481088 {
10491089 struct nfs_inode *nfsi = NFS_I(inode);
10501090 struct nfs_open_context *pos, *ctx = NULL;
10511091
1052
- spin_lock(&inode->i_lock);
1053
- list_for_each_entry(pos, &nfsi->open_files, list) {
1054
- if (cred != NULL && pos->cred != cred)
1092
+ rcu_read_lock();
1093
+ list_for_each_entry_rcu(pos, &nfsi->open_files, list) {
1094
+ if (cred != NULL && cred_fscmp(pos->cred, cred) != 0)
10551095 continue;
10561096 if ((pos->mode & (FMODE_READ|FMODE_WRITE)) != mode)
10571097 continue;
10581098 if (!test_bit(NFS_CONTEXT_FILE_OPEN, &pos->flags))
10591099 continue;
10601100 ctx = get_nfs_open_context(pos);
1061
- break;
1101
+ if (ctx)
1102
+ break;
10621103 }
1063
- spin_unlock(&inode->i_lock);
1104
+ rcu_read_unlock();
10641105 return ctx;
10651106 }
10661107
....@@ -1079,9 +1120,6 @@
10791120 if (ctx->error < 0)
10801121 invalidate_inode_pages2(inode->i_mapping);
10811122 filp->private_data = NULL;
1082
- spin_lock(&inode->i_lock);
1083
- list_move_tail(&ctx->list, &NFS_I(inode)->open_files);
1084
- spin_unlock(&inode->i_lock);
10851123 put_nfs_open_context_sync(ctx);
10861124 }
10871125 }
....@@ -1101,7 +1139,6 @@
11011139 nfs_fscache_open_file(inode, filp);
11021140 return 0;
11031141 }
1104
-EXPORT_SYMBOL_GPL(nfs_open);
11051142
11061143 /*
11071144 * This function is called whenever some part of NFS notices that
....@@ -1151,10 +1188,17 @@
11511188 dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Lu) getattr failed, error=%d\n",
11521189 inode->i_sb->s_id,
11531190 (unsigned long long)NFS_FILEID(inode), status);
1154
- if (status == -ESTALE) {
1155
- nfs_zap_caches(inode);
1191
+ switch (status) {
1192
+ case -ETIMEDOUT:
1193
+ /* A soft timeout occurred. Use cached information? */
1194
+ if (server->flags & NFS_MOUNT_SOFTREVAL)
1195
+ status = 0;
1196
+ break;
1197
+ case -ESTALE:
11561198 if (!S_ISDIR(inode->i_mode))
1157
- set_bit(NFS_INO_STALE, &NFS_I(inode)->flags);
1199
+ nfs_set_inode_stale(inode);
1200
+ else
1201
+ nfs_zap_caches(inode);
11581202 }
11591203 goto err_out;
11601204 }
....@@ -1193,8 +1237,8 @@
11931237
11941238 /**
11951239 * nfs_revalidate_inode - Revalidate the inode attributes
1196
- * @server - pointer to nfs_server struct
1197
- * @inode - pointer to inode struct
1240
+ * @server: pointer to nfs_server struct
1241
+ * @inode: pointer to inode struct
11981242 *
11991243 * Updates inode attribute information by retrieving the data from the server.
12001244 */
....@@ -1264,8 +1308,8 @@
12641308
12651309 /**
12661310 * nfs_revalidate_mapping - Revalidate the pagecache
1267
- * @inode - pointer to host inode
1268
- * @mapping - pointer to mapping
1311
+ * @inode: pointer to host inode
1312
+ * @mapping: pointer to mapping
12691313 */
12701314 int nfs_revalidate_mapping(struct inode *inode,
12711315 struct address_space *mapping)
....@@ -1314,7 +1358,8 @@
13141358
13151359 set_bit(NFS_INO_INVALIDATING, bitlock);
13161360 smp_wmb();
1317
- nfsi->cache_validity &= ~NFS_INO_INVALID_DATA;
1361
+ nfsi->cache_validity &= ~(NFS_INO_INVALID_DATA|
1362
+ NFS_INO_DATA_INVAL_DEFER);
13181363 spin_unlock(&inode->i_lock);
13191364 trace_nfs_invalidate_mapping_enter(inode);
13201365 ret = nfs_invalidate_mapping(inode, mapping);
....@@ -1331,19 +1376,11 @@
13311376 {
13321377 struct inode *inode = &nfsi->vfs_inode;
13331378
1334
- assert_spin_locked(&inode->i_lock);
1335
-
13361379 if (!S_ISREG(inode->i_mode))
13371380 return false;
13381381 if (list_empty(&nfsi->open_files))
13391382 return false;
1340
- /* Note: This relies on nfsi->open_files being ordered with writers
1341
- * being placed at the head of the list.
1342
- * See nfs_inode_attach_open_context()
1343
- */
1344
- return (list_first_entry(&nfsi->open_files,
1345
- struct nfs_open_context,
1346
- list)->mode & FMODE_WRITE) == FMODE_WRITE;
1383
+ return inode_is_open_for_write(inode);
13471384 }
13481385
13491386 static bool nfs_file_has_buffered_writers(struct nfs_inode *nfsi)
....@@ -1353,7 +1390,7 @@
13531390
13541391 static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
13551392 {
1356
- struct timespec ts;
1393
+ struct timespec64 ts;
13571394
13581395 if ((fattr->valid & NFS_ATTR_FATTR_PRECHANGE)
13591396 && (fattr->valid & NFS_ATTR_FATTR_CHANGE)
....@@ -1361,20 +1398,22 @@
13611398 inode_set_iversion_raw(inode, fattr->change_attr);
13621399 if (S_ISDIR(inode->i_mode))
13631400 nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
1401
+ else if (nfs_server_capable(inode, NFS_CAP_XATTR))
1402
+ nfs_set_cache_invalid(inode, NFS_INO_INVALID_XATTR);
13641403 }
13651404 /* If we have atomic WCC data, we may update some attributes */
1366
- ts = timespec64_to_timespec(inode->i_ctime);
1405
+ ts = inode->i_ctime;
13671406 if ((fattr->valid & NFS_ATTR_FATTR_PRECTIME)
13681407 && (fattr->valid & NFS_ATTR_FATTR_CTIME)
1369
- && timespec_equal(&ts, &fattr->pre_ctime)) {
1370
- inode->i_ctime = timespec_to_timespec64(fattr->ctime);
1408
+ && timespec64_equal(&ts, &fattr->pre_ctime)) {
1409
+ inode->i_ctime = fattr->ctime;
13711410 }
13721411
1373
- ts = timespec64_to_timespec(inode->i_mtime);
1412
+ ts = inode->i_mtime;
13741413 if ((fattr->valid & NFS_ATTR_FATTR_PREMTIME)
13751414 && (fattr->valid & NFS_ATTR_FATTR_MTIME)
1376
- && timespec_equal(&ts, &fattr->pre_mtime)) {
1377
- inode->i_mtime = timespec_to_timespec64(fattr->mtime);
1415
+ && timespec64_equal(&ts, &fattr->pre_mtime)) {
1416
+ inode->i_mtime = fattr->mtime;
13781417 if (S_ISDIR(inode->i_mode))
13791418 nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
13801419 }
....@@ -1388,8 +1427,8 @@
13881427
13891428 /**
13901429 * nfs_check_inode_attributes - verify consistency of the inode attribute cache
1391
- * @inode - pointer to inode
1392
- * @fattr - updated attributes
1430
+ * @inode: pointer to inode
1431
+ * @fattr: updated attributes
13931432 *
13941433 * Verifies the attribute cache. If we have just changed the attributes,
13951434 * so that fattr carries weak cache consistency data, then it may
....@@ -1400,16 +1439,26 @@
14001439 struct nfs_inode *nfsi = NFS_I(inode);
14011440 loff_t cur_size, new_isize;
14021441 unsigned long invalid = 0;
1403
- struct timespec ts;
1442
+ struct timespec64 ts;
14041443
14051444 if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
14061445 return 0;
14071446
1447
+ if (!(fattr->valid & NFS_ATTR_FATTR_FILEID)) {
1448
+ /* Only a mounted-on-fileid? Just exit */
1449
+ if (fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
1450
+ return 0;
14081451 /* Has the inode gone and changed behind our back? */
1409
- if ((fattr->valid & NFS_ATTR_FATTR_FILEID) && nfsi->fileid != fattr->fileid)
1452
+ } else if (nfsi->fileid != fattr->fileid) {
1453
+ /* Is this perhaps the mounted-on fileid? */
1454
+ if ((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) &&
1455
+ nfsi->fileid == fattr->mounted_on_fileid)
1456
+ return 0;
14101457 return -ESTALE;
1411
- if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT))
1458
+ }
1459
+ if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && inode_wrong_type(inode, fattr->mode))
14121460 return -ESTALE;
1461
+
14131462
14141463 if (!nfs_file_has_buffered_writers(nfsi)) {
14151464 /* Verify a few of the more important attributes */
....@@ -1417,12 +1466,12 @@
14171466 invalid |= NFS_INO_INVALID_CHANGE
14181467 | NFS_INO_REVAL_PAGECACHE;
14191468
1420
- ts = timespec64_to_timespec(inode->i_mtime);
1421
- if ((fattr->valid & NFS_ATTR_FATTR_MTIME) && !timespec_equal(&ts, &fattr->mtime))
1469
+ ts = inode->i_mtime;
1470
+ if ((fattr->valid & NFS_ATTR_FATTR_MTIME) && !timespec64_equal(&ts, &fattr->mtime))
14221471 invalid |= NFS_INO_INVALID_MTIME;
14231472
1424
- ts = timespec64_to_timespec(inode->i_ctime);
1425
- if ((fattr->valid & NFS_ATTR_FATTR_CTIME) && !timespec_equal(&ts, &fattr->ctime))
1473
+ ts = inode->i_ctime;
1474
+ if ((fattr->valid & NFS_ATTR_FATTR_CTIME) && !timespec64_equal(&ts, &fattr->ctime))
14261475 invalid |= NFS_INO_INVALID_CTIME;
14271476
14281477 if (fattr->valid & NFS_ATTR_FATTR_SIZE) {
....@@ -1452,8 +1501,8 @@
14521501 if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
14531502 invalid |= NFS_INO_INVALID_OTHER;
14541503
1455
- ts = timespec64_to_timespec(inode->i_atime);
1456
- if ((fattr->valid & NFS_ATTR_FATTR_ATIME) && !timespec_equal(&ts, &fattr->atime))
1504
+ ts = inode->i_atime;
1505
+ if ((fattr->valid & NFS_ATTR_FATTR_ATIME) && !timespec64_equal(&ts, &fattr->atime))
14571506 invalid |= NFS_INO_INVALID_ATIME;
14581507
14591508 if (invalid != 0)
....@@ -1589,8 +1638,8 @@
15891638
15901639 /**
15911640 * nfs_inode_attrs_need_update - check if the inode attributes need updating
1592
- * @inode - pointer to inode
1593
- * @fattr - attributes
1641
+ * @inode: pointer to inode
1642
+ * @fattr: attributes
15941643 *
15951644 * Attempt to divine whether or not an RPC call reply carrying stale
15961645 * attributes got scheduled after another call carrying updated ones.
....@@ -1631,8 +1680,8 @@
16311680
16321681 /**
16331682 * nfs_refresh_inode - try to update the inode attribute cache
1634
- * @inode - pointer to inode
1635
- * @fattr - updated attributes
1683
+ * @inode: pointer to inode
1684
+ * @fattr: updated attributes
16361685 *
16371686 * Check that an RPC call that returned attributes has not overlapped with
16381687 * other recent updates of the inode metadata, then decide whether it is
....@@ -1666,8 +1715,8 @@
16661715
16671716 /**
16681717 * nfs_post_op_update_inode - try to update the inode attribute cache
1669
- * @inode - pointer to inode
1670
- * @fattr - updated attributes
1718
+ * @inode: pointer to inode
1719
+ * @fattr: updated attributes
16711720 *
16721721 * After an operation that has changed the inode metadata, mark the
16731722 * attribute cache as being invalid, then try to update it.
....@@ -1696,8 +1745,8 @@
16961745
16971746 /**
16981747 * nfs_post_op_update_inode_force_wcc_locked - update the inode attribute cache
1699
- * @inode - pointer to inode
1700
- * @fattr - updated attributes
1748
+ * @inode: pointer to inode
1749
+ * @fattr: updated attributes
17011750 *
17021751 * After an operation that has changed the inode metadata, mark the
17031752 * attribute cache as being invalid, then try to update it. Fake up
....@@ -1725,12 +1774,12 @@
17251774 }
17261775 if ((fattr->valid & NFS_ATTR_FATTR_CTIME) != 0 &&
17271776 (fattr->valid & NFS_ATTR_FATTR_PRECTIME) == 0) {
1728
- fattr->pre_ctime = timespec64_to_timespec(inode->i_ctime);
1777
+ fattr->pre_ctime = inode->i_ctime;
17291778 fattr->valid |= NFS_ATTR_FATTR_PRECTIME;
17301779 }
17311780 if ((fattr->valid & NFS_ATTR_FATTR_MTIME) != 0 &&
17321781 (fattr->valid & NFS_ATTR_FATTR_PREMTIME) == 0) {
1733
- fattr->pre_mtime = timespec64_to_timespec(inode->i_mtime);
1782
+ fattr->pre_mtime = inode->i_mtime;
17341783 fattr->valid |= NFS_ATTR_FATTR_PREMTIME;
17351784 }
17361785 if ((fattr->valid & NFS_ATTR_FATTR_SIZE) != 0 &&
....@@ -1742,14 +1791,15 @@
17421791 status = nfs_post_op_update_inode_locked(inode, fattr,
17431792 NFS_INO_INVALID_CHANGE
17441793 | NFS_INO_INVALID_CTIME
1745
- | NFS_INO_INVALID_MTIME);
1794
+ | NFS_INO_INVALID_MTIME
1795
+ | NFS_INO_INVALID_BLOCKS);
17461796 return status;
17471797 }
17481798
17491799 /**
17501800 * nfs_post_op_update_inode_force_wcc - try to update the inode attribute cache
1751
- * @inode - pointer to inode
1752
- * @fattr - updated attributes
1801
+ * @inode: pointer to inode
1802
+ * @fattr: updated attributes
17531803 *
17541804 * After an operation that has changed the inode metadata, mark the
17551805 * attribute cache as being invalid, then try to update it. Fake up
....@@ -1769,18 +1819,6 @@
17691819 }
17701820 EXPORT_SYMBOL_GPL(nfs_post_op_update_inode_force_wcc);
17711821
1772
-
1773
-static inline bool nfs_fileid_valid(struct nfs_inode *nfsi,
1774
- struct nfs_fattr *fattr)
1775
-{
1776
- bool ret1 = true, ret2 = true;
1777
-
1778
- if (fattr->valid & NFS_ATTR_FATTR_FILEID)
1779
- ret1 = (nfsi->fileid == fattr->fileid);
1780
- if (fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
1781
- ret2 = (nfsi->fileid == fattr->mounted_on_fileid);
1782
- return ret1 || ret2;
1783
-}
17841822
17851823 /*
17861824 * Many nfs protocol calls return the new file attributes after
....@@ -1812,7 +1850,16 @@
18121850 nfs_display_fhandle_hash(NFS_FH(inode)),
18131851 atomic_read(&inode->i_count), fattr->valid);
18141852
1815
- if (!nfs_fileid_valid(nfsi, fattr)) {
1853
+ if (!(fattr->valid & NFS_ATTR_FATTR_FILEID)) {
1854
+ /* Only a mounted-on-fileid? Just exit */
1855
+ if (fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
1856
+ return 0;
1857
+ /* Has the inode gone and changed behind our back? */
1858
+ } else if (nfsi->fileid != fattr->fileid) {
1859
+ /* Is this perhaps the mounted-on fileid? */
1860
+ if ((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) &&
1861
+ nfsi->fileid == fattr->mounted_on_fileid)
1862
+ return 0;
18161863 printk(KERN_ERR "NFS: server %s error: fileid changed\n"
18171864 "fsid %s: expected fileid 0x%Lx, got 0x%Lx\n",
18181865 NFS_SERVER(inode)->nfs_client->cl_hostname,
....@@ -1824,7 +1871,7 @@
18241871 /*
18251872 * Make sure the inode's type hasn't changed.
18261873 */
1827
- if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT)) {
1874
+ if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && inode_wrong_type(inode, fattr->mode)) {
18281875 /*
18291876 * Big trouble! The inode has become a different object.
18301877 */
....@@ -1852,13 +1899,18 @@
18521899 nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR
18531900 | NFS_INO_INVALID_ATIME
18541901 | NFS_INO_REVAL_FORCED
1855
- | NFS_INO_REVAL_PAGECACHE);
1902
+ | NFS_INO_REVAL_PAGECACHE
1903
+ | NFS_INO_INVALID_BLOCKS);
18561904
18571905 /* Do atomic weak cache consistency updates */
18581906 nfs_wcc_update_inode(inode, fattr);
18591907
18601908 if (pnfs_layoutcommit_outstanding(inode)) {
1861
- nfsi->cache_validity |= save_cache_validity & NFS_INO_INVALID_ATTR;
1909
+ nfsi->cache_validity |=
1910
+ save_cache_validity &
1911
+ (NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_CTIME |
1912
+ NFS_INO_INVALID_MTIME | NFS_INO_INVALID_SIZE |
1913
+ NFS_INO_REVAL_FORCED);
18621914 cache_revalidated = false;
18631915 }
18641916
....@@ -1869,7 +1921,8 @@
18691921 if (!(have_writers || have_delegation)) {
18701922 invalid |= NFS_INO_INVALID_DATA
18711923 | NFS_INO_INVALID_ACCESS
1872
- | NFS_INO_INVALID_ACL;
1924
+ | NFS_INO_INVALID_ACL
1925
+ | NFS_INO_INVALID_XATTR;
18731926 /* Force revalidate of all attributes */
18741927 save_cache_validity |= NFS_INO_INVALID_CTIME
18751928 | NFS_INO_INVALID_MTIME
....@@ -1880,7 +1933,8 @@
18801933 dprintk("NFS: change_attr change on server for file %s/%ld\n",
18811934 inode->i_sb->s_id,
18821935 inode->i_ino);
1883
- }
1936
+ } else if (!have_delegation)
1937
+ nfsi->cache_validity |= NFS_INO_DATA_INVAL_DEFER;
18841938 inode_set_iversion_raw(inode, fattr->change_attr);
18851939 attr_changed = true;
18861940 }
....@@ -1893,7 +1947,7 @@
18931947 }
18941948
18951949 if (fattr->valid & NFS_ATTR_FATTR_MTIME) {
1896
- inode->i_mtime = timespec_to_timespec64(fattr->mtime);
1950
+ inode->i_mtime = fattr->mtime;
18971951 } else if (server->caps & NFS_CAP_MTIME) {
18981952 nfsi->cache_validity |= save_cache_validity &
18991953 (NFS_INO_INVALID_MTIME
....@@ -1902,7 +1956,7 @@
19021956 }
19031957
19041958 if (fattr->valid & NFS_ATTR_FATTR_CTIME) {
1905
- inode->i_ctime = timespec_to_timespec64(fattr->ctime);
1959
+ inode->i_ctime = fattr->ctime;
19061960 } else if (server->caps & NFS_CAP_CTIME) {
19071961 nfsi->cache_validity |= save_cache_validity &
19081962 (NFS_INO_INVALID_CTIME
....@@ -1940,7 +1994,7 @@
19401994
19411995
19421996 if (fattr->valid & NFS_ATTR_FATTR_ATIME)
1943
- inode->i_atime = timespec_to_timespec64(fattr->atime);
1997
+ inode->i_atime = fattr->atime;
19441998 else if (server->caps & NFS_CAP_ATIME) {
19451999 nfsi->cache_validity |= save_cache_validity &
19462000 (NFS_INO_INVALID_ATIME
....@@ -2013,8 +2067,12 @@
20132067 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
20142068 } else if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
20152069 inode->i_blocks = fattr->du.nfs2.blocks;
2016
- else
2070
+ else {
2071
+ nfsi->cache_validity |= save_cache_validity &
2072
+ (NFS_INO_INVALID_BLOCKS
2073
+ | NFS_INO_REVAL_FORCED);
20172074 cache_revalidated = false;
2075
+ }
20182076
20192077 /* Update attrtimeo value if we're out of the unstable period */
20202078 if (attr_changed) {
....@@ -2052,7 +2110,7 @@
20522110 * lookup validation will know that the inode is bad.
20532111 * (But we fall through to invalidate the caches.)
20542112 */
2055
- nfs_invalidate_inode(inode);
2113
+ nfs_set_inode_stale_locked(inode);
20562114 return -ESTALE;
20572115 }
20582116
....@@ -2067,21 +2125,18 @@
20672125 #if IS_ENABLED(CONFIG_NFS_V4)
20682126 nfsi->nfs4_acl = NULL;
20692127 #endif /* CONFIG_NFS_V4 */
2128
+#ifdef CONFIG_NFS_V4_2
2129
+ nfsi->xattr_cache = NULL;
2130
+#endif
20702131 return &nfsi->vfs_inode;
20712132 }
20722133 EXPORT_SYMBOL_GPL(nfs_alloc_inode);
20732134
2074
-static void nfs_i_callback(struct rcu_head *head)
2135
+void nfs_free_inode(struct inode *inode)
20752136 {
2076
- struct inode *inode = container_of(head, struct inode, i_rcu);
20772137 kmem_cache_free(nfs_inode_cachep, NFS_I(inode));
20782138 }
2079
-
2080
-void nfs_destroy_inode(struct inode *inode)
2081
-{
2082
- call_rcu(&inode->i_rcu, nfs_i_callback);
2083
-}
2084
-EXPORT_SYMBOL_GPL(nfs_destroy_inode);
2139
+EXPORT_SYMBOL_GPL(nfs_free_inode);
20852140
20862141 static inline void nfs4_init_once(struct nfs_inode *nfsi)
20872142 {
....@@ -2108,6 +2163,7 @@
21082163 init_rwsem(&nfsi->rmdir_sem);
21092164 mutex_init(&nfsi->commit_mutex);
21102165 nfs4_init_once(nfsi);
2166
+ nfsi->cache_change_attribute = 0;
21112167 }
21122168
21132169 static int __init nfs_init_inodecache(void)
....@@ -2175,12 +2231,8 @@
21752231
21762232 static void nfs_net_exit(struct net *net)
21772233 {
2178
- struct nfs_net *nn = net_generic(net, nfs_net_id);
2179
-
21802234 nfs_fs_proc_net_exit(net);
2181
- nfs_cleanup_cb_ident_idr(net);
2182
- WARN_ON_ONCE(!list_empty(&nn->nfs_client_list));
2183
- WARN_ON_ONCE(!list_empty(&nn->nfs_volume_list));
2235
+ nfs_clients_exit(net);
21842236 }
21852237
21862238 static struct pernet_operations nfs_net_ops = {
....@@ -2196,6 +2248,10 @@
21962248 static int __init init_nfs_fs(void)
21972249 {
21982250 int err;
2251
+
2252
+ err = nfs_sysfs_init();
2253
+ if (err < 0)
2254
+ goto out10;
21992255
22002256 err = register_pernet_subsys(&nfs_net_ops);
22012257 if (err < 0)
....@@ -2260,6 +2316,8 @@
22602316 out8:
22612317 unregister_pernet_subsys(&nfs_net_ops);
22622318 out9:
2319
+ nfs_sysfs_exit();
2320
+out10:
22632321 return err;
22642322 }
22652323
....@@ -2276,11 +2334,13 @@
22762334 unregister_nfs_fs();
22772335 nfs_fs_proc_exit();
22782336 nfsiod_stop();
2337
+ nfs_sysfs_exit();
22792338 }
22802339
22812340 /* Not quite true; I just maintain it */
22822341 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
22832342 MODULE_LICENSE("GPL");
2343
+MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
22842344 module_param(enable_ino64, bool, 0644);
22852345
22862346 module_init(init_nfs_fs)