Lines Matching refs:inode
3 * linux/fs/nfs/inode.c
7 * nfs inode and superblock handling functions
62 /* Default is to see 64-bit inode numbers */
65 static int nfs_update_inode(struct inode *, struct nfs_fattr *);
90 * nfs_compat_user_ino64 - returns the user-visible inode number
93 * This function returns a 32-bit inode number if the boot parameter
112 int nfs_drop_inode(struct inode *inode)
114 return NFS_STALE(inode) || generic_drop_inode(inode);
118 void nfs_clear_inode(struct inode *inode)
123 WARN_ON_ONCE(nfs_have_writebacks(inode));
124 WARN_ON_ONCE(!list_empty(&NFS_I(inode)->open_files));
125 nfs_zap_acl_cache(inode);
126 nfs_access_zap_cache(inode);
127 nfs_fscache_clear_inode(inode);
131 void nfs_evict_inode(struct inode *inode)
133 truncate_inode_pages_final(&inode->i_data);
134 clear_inode(inode);
135 nfs_clear_inode(inode);
138 int nfs_sync_inode(struct inode *inode)
140 inode_dio_wait(inode);
141 return nfs_wb_all(inode);
160 static int nfs_attribute_timeout(struct inode *inode)
162 struct nfs_inode *nfsi = NFS_I(inode);
167 static bool nfs_check_cache_invalid_delegated(struct inode *inode, unsigned long flags)
169 unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity);
178 static bool nfs_check_cache_invalid_not_delegated(struct inode *inode, unsigned long flags)
180 unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity);
184 if (nfs_attribute_timeout(inode))
189 bool nfs_check_cache_invalid(struct inode *inode, unsigned long flags)
191 if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
192 return nfs_check_cache_invalid_delegated(inode, flags);
194 return nfs_check_cache_invalid_not_delegated(inode, flags);
210 static void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)
212 struct nfs_inode *nfsi = NFS_I(inode);
213 bool have_delegation = NFS_PROTO(inode)->have_delegation(inode, FMODE_READ);
227 if (inode->i_mapping->nrpages == 0)
231 nfs_fscache_invalidate(inode);
237 static void nfs_zap_caches_locked(struct inode *inode)
239 struct nfs_inode *nfsi = NFS_I(inode);
240 int mode = inode->i_mode;
242 nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
244 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
247 memset(NFS_I(inode)->cookieverf, 0, sizeof(NFS_I(inode)->cookieverf));
249 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR
256 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR
264 void nfs_zap_caches(struct inode *inode)
266 spin_lock(&inode->i_lock);
267 nfs_zap_caches_locked(inode);
268 spin_unlock(&inode->i_lock);
271 void nfs_zap_mapping(struct inode *inode, struct address_space *mapping)
274 spin_lock(&inode->i_lock);
275 nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
276 spin_unlock(&inode->i_lock);
280 void nfs_zap_acl_cache(struct inode *inode)
282 void (*clear_acl_cache)(struct inode *);
284 clear_acl_cache = NFS_PROTO(inode)->clear_acl_cache;
286 clear_acl_cache(inode);
287 spin_lock(&inode->i_lock);
288 NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_ACL;
289 spin_unlock(&inode->i_lock);
293 void nfs_invalidate_atime(struct inode *inode)
295 spin_lock(&inode->i_lock);
296 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME);
297 spin_unlock(&inode->i_lock);
302 * Invalidate, but do not unhash, the inode.
303 * NB: must be called with inode->i_lock held!
305 static void nfs_set_inode_stale_locked(struct inode *inode)
307 set_bit(NFS_INO_STALE, &NFS_I(inode)->flags);
308 nfs_zap_caches_locked(inode);
309 trace_nfs_set_inode_stale(inode);
312 void nfs_set_inode_stale(struct inode *inode)
314 spin_lock(&inode->i_lock);
315 nfs_set_inode_stale_locked(inode);
316 spin_unlock(&inode->i_lock);
325 * In NFSv3 we can have 64bit inode numbers. In order to support
331 nfs_find_actor(struct inode *inode, void *opaque)
337 if (NFS_FILEID(inode) != fattr->fileid)
339 if (inode_wrong_type(inode, fattr->mode))
341 if (nfs_compare_fh(NFS_FH(inode), fh))
343 if (is_bad_inode(inode) || NFS_STALE(inode))
349 nfs_init_locked(struct inode *inode, void *opaque)
354 set_nfs_fileid(inode, fattr->fileid);
355 inode->i_mode = fattr->mode;
356 nfs_copy_fh(NFS_FH(inode), desc->fh);
361 static void nfs_clear_label_invalid(struct inode *inode)
363 spin_lock(&inode->i_lock);
364 NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_LABEL;
365 spin_unlock(&inode->i_lock);
368 void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr,
376 if ((fattr->valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL) && inode->i_security) {
377 error = security_inode_notifysecctx(inode, label->label,
385 nfs_clear_label_invalid(inode);
415 void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr,
422 /* Search for inode identified by fh, fileid and i_mode in inode cache. */
423 struct inode *
430 struct inode *inode;
438 inode = ilookup5(sb, hash, nfs_find_actor, &desc);
440 dprintk("%s: returning %p\n", __func__, inode);
441 return inode;
446 * instead of inode number.
448 struct inode *
455 struct inode *inode = ERR_PTR(-ENOENT);
469 inode = iget5_locked(sb, hash, nfs_find_actor, nfs_init_locked, &desc);
470 if (inode == NULL) {
471 inode = ERR_PTR(-ENOMEM);
475 if (inode->i_state & I_NEW) {
476 struct nfs_inode *nfsi = NFS_I(inode);
481 inode->i_ino = hash;
484 inode->i_flags |= S_NOATIME|S_NOCMTIME;
485 inode->i_mode = fattr->mode;
488 && nfs_server_capable(inode, NFS_CAP_MODE))
489 nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER);
493 inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->file_inode_ops;
494 if (S_ISREG(inode->i_mode)) {
495 inode->i_fop = NFS_SB(sb)->nfs_client->rpc_ops->file_ops;
496 inode->i_data.a_ops = &nfs_file_aops;
497 } else if (S_ISDIR(inode->i_mode)) {
498 inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->dir_inode_ops;
499 inode->i_fop = &nfs_dir_operations;
500 inode->i_data.a_ops = &nfs_dir_aops;
505 inode->i_op = &nfs_referral_inode_operations;
507 inode->i_op = &nfs_mountpoint_inode_operations;
508 inode->i_fop = NULL;
509 inode->i_flags |= S_AUTOMOUNT;
511 } else if (S_ISLNK(inode->i_mode)) {
512 inode->i_op = &nfs_symlink_inode_operations;
513 inode_nohighmem(inode);
515 init_special_inode(inode, inode->i_mode, fattr->rdev);
517 memset(&inode->i_atime, 0, sizeof(inode->i_atime));
518 memset(&inode->i_mtime, 0, sizeof(inode->i_mtime));
519 memset(&inode->i_ctime, 0, sizeof(inode->i_ctime));
520 inode_set_iversion_raw(inode, 0);
521 inode->i_size = 0;
522 clear_nlink(inode);
523 inode->i_uid = make_kuid(&init_user_ns, -2);
524 inode->i_gid = make_kgid(&init_user_ns, -2);
525 inode->i_blocks = 0;
533 inode->i_atime = fattr->atime;
534 else if (nfs_server_capable(inode, NFS_CAP_ATIME))
535 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME);
537 inode->i_mtime = fattr->mtime;
538 else if (nfs_server_capable(inode, NFS_CAP_MTIME))
539 nfs_set_cache_invalid(inode, NFS_INO_INVALID_MTIME);
541 inode->i_ctime = fattr->ctime;
542 else if (nfs_server_capable(inode, NFS_CAP_CTIME))
543 nfs_set_cache_invalid(inode, NFS_INO_INVALID_CTIME);
545 inode_set_iversion_raw(inode, fattr->change_attr);
547 nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE);
549 inode->i_size = nfs_size_to_loff_t(fattr->size);
551 nfs_set_cache_invalid(inode, NFS_INO_INVALID_SIZE);
553 set_nlink(inode, fattr->nlink);
554 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
555 nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER);
557 inode->i_uid = fattr->uid;
558 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
559 nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER);
561 inode->i_gid = fattr->gid;
562 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
563 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);
567 inode->i_blocks = fattr->du.nfs2.blocks;
572 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
578 nfs_setsecurity(inode, fattr, label);
580 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
584 nfs_fscache_init_inode(inode);
586 unlock_new_inode(inode);
588 int err = nfs_refresh_inode(inode, fattr);
590 iput(inode);
591 inode = ERR_PTR(err);
596 inode->i_sb->s_id,
597 (unsigned long long)NFS_FILEID(inode),
599 atomic_read(&inode->i_count));
602 return inode;
605 dprintk("nfs_fhget: iget failed with error %ld\n", PTR_ERR(inode));
615 struct inode *inode = d_inode(dentry);
619 nfs_inc_stats(inode, NFSIOS_VFSSETATTR);
626 BUG_ON(!S_ISREG(inode->i_mode));
628 error = inode_newsize_ok(inode, attr->ia_size);
632 if (attr->ia_size == i_size_read(inode))
641 trace_nfs_setattr_enter(inode);
644 if (S_ISREG(inode->i_mode))
645 nfs_sync_inode(inode);
653 error = NFS_PROTO(inode)->setattr(dentry, fattr, attr);
655 error = nfs_refresh_inode(inode, fattr);
658 trace_nfs_setattr_exit(inode, error);
665 * @inode: inode of the file used
670 * inode->i_size to be updated under the inode->i_lock.
671 * Note: must be called with inode->i_lock held!
673 static int nfs_vmtruncate(struct inode * inode, loff_t offset)
677 err = inode_newsize_ok(inode, offset);
681 i_size_write(inode, offset);
684 NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_DATA |
686 NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_SIZE;
688 spin_unlock(&inode->i_lock);
689 truncate_pagecache(inode, offset);
690 spin_lock(&inode->i_lock);
696 * nfs_setattr_update_inode - Update inode metadata after a setattr call.
697 * @inode: pointer to struct inode
704 void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr,
710 spin_lock(&inode->i_lock);
711 NFS_I(inode)->attr_gencount = fattr->gencount;
713 nfs_set_cache_invalid(inode, NFS_INO_INVALID_MTIME);
714 nfs_inc_stats(inode, NFSIOS_SETATTRTRUNC);
715 nfs_vmtruncate(inode, attr->ia_size);
718 NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_CTIME;
721 mode |= inode->i_mode & ~S_IALLUGO;
722 inode->i_mode = mode;
725 inode->i_uid = attr->ia_uid;
727 inode->i_gid = attr->ia_gid;
729 inode->i_ctime = fattr->ctime;
731 nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE
733 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ACCESS
737 NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_ATIME
740 inode->i_atime = fattr->atime;
742 inode->i_atime = attr->ia_atime;
744 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME);
747 inode->i_ctime = fattr->ctime;
749 nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE
753 NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_MTIME
756 inode->i_mtime = fattr->mtime;
758 inode->i_mtime = attr->ia_mtime;
760 nfs_set_cache_invalid(inode, NFS_INO_INVALID_MTIME);
763 inode->i_ctime = fattr->ctime;
765 nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE
769 nfs_update_inode(inode, fattr);
770 spin_unlock(&inode->i_lock);
796 static bool nfs_need_revalidate_inode(struct inode *inode)
798 if (NFS_I(inode)->cache_validity &
801 if (nfs_attribute_cache_expired(inode))
809 struct inode *inode = d_inode(path->dentry);
810 struct nfs_server *server = NFS_SERVER(inode);
816 trace_nfs_getattr_enter(inode);
825 S_ISREG(inode->i_mode))
826 filemap_write_and_wait(inode->i_mapping);
838 ((path->mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
848 do_update |= force_sync || nfs_attribute_cache_expired(inode);
849 cache_validity = READ_ONCE(NFS_I(inode)->cache_validity);
864 err = __nfs_revalidate_inode(server, inode);
873 generic_fillattr(inode, stat);
874 stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode));
875 if (S_ISDIR(inode->i_mode))
876 stat->blksize = NFS_SERVER(inode)->dtsize;
878 trace_nfs_getattr_exit(inode, err);
907 struct inode *inode = d_inode(ctx->dentry);
917 spin_lock(&inode->i_lock);
929 spin_unlock(&inode->i_lock);
939 struct inode *inode = d_inode(ctx->dentry);
941 if (!refcount_dec_and_lock(&l_ctx->count, &inode->i_lock))
944 spin_unlock(&inode->i_lock);
962 struct inode *inode;
969 inode = d_inode(ctx->dentry);
970 if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
972 nfsi = NFS_I(inode);
973 if (inode->i_mapping->nrpages == 0)
979 server = NFS_SERVER(inode);
982 nfs_revalidate_inode(server, inode);
1025 struct inode *inode = d_inode(ctx->dentry);
1031 spin_lock(&inode->i_lock);
1033 spin_unlock(&inode->i_lock);
1035 if (inode != NULL)
1036 NFS_PROTO(inode)->close_context(ctx, is_sync);
1062 struct inode *inode = d_inode(ctx->dentry);
1063 struct nfs_inode *nfsi = NFS_I(inode);
1065 spin_lock(&inode->i_lock);
1071 spin_unlock(&inode->i_lock);
1085 * Given an inode, search for an open context with the desired characteristics
1087 struct nfs_open_context *nfs_find_open_context(struct inode *inode, const struct cred *cred, fmode_t mode)
1089 struct nfs_inode *nfsi = NFS_I(inode);
1113 struct inode *inode = d_inode(ctx->dentry);
1121 invalidate_inode_pages2(inode->i_mapping);
1130 int nfs_open(struct inode *inode, struct file *filp)
1139 nfs_fscache_open_file(inode, filp);
1148 __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
1153 struct nfs_inode *nfsi = NFS_I(inode);
1156 inode->i_sb->s_id, (unsigned long long)NFS_FILEID(inode));
1158 trace_nfs_revalidate_inode_enter(inode);
1160 if (is_bad_inode(inode))
1162 if (NFS_STALE(inode))
1166 if (S_ISREG(inode->i_mode)) {
1167 status = pnfs_sync_inode(inode, false);
1177 nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE);
1179 label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL);
1185 status = NFS_PROTO(inode)->getattr(server, NFS_FH(inode), fattr,
1186 label, inode);
1189 inode->i_sb->s_id,
1190 (unsigned long long)NFS_FILEID(inode), status);
1198 if (!S_ISDIR(inode->i_mode))
1199 nfs_set_inode_stale(inode);
1201 nfs_zap_caches(inode);
1206 status = nfs_refresh_inode(inode, fattr);
1209 inode->i_sb->s_id,
1210 (unsigned long long)NFS_FILEID(inode), status);
1215 nfs_zap_acl_cache(inode);
1217 nfs_setsecurity(inode, fattr, label);
1220 inode->i_sb->s_id,
1221 (unsigned long long)NFS_FILEID(inode));
1227 trace_nfs_revalidate_inode_exit(inode, status);
1231 int nfs_attribute_cache_expired(struct inode *inode)
1233 if (nfs_have_delegated_attributes(inode))
1235 return nfs_attribute_timeout(inode);
1239 * nfs_revalidate_inode - Revalidate the inode attributes
1241 * @inode: pointer to inode struct
1243 * Updates inode attribute information by retrieving the data from the server.
1245 int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
1247 if (!nfs_need_revalidate_inode(inode))
1248 return NFS_STALE(inode) ? -ESTALE : 0;
1249 return __nfs_revalidate_inode(server, inode);
1253 static int nfs_invalidate_mapping(struct inode *inode, struct address_space *mapping)
1255 struct nfs_inode *nfsi = NFS_I(inode);
1259 if (S_ISREG(inode->i_mode)) {
1268 if (S_ISDIR(inode->i_mode)) {
1269 spin_lock(&inode->i_lock);
1271 spin_unlock(&inode->i_lock);
1273 nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE);
1274 nfs_fscache_wait_on_invalidate(inode);
1277 inode->i_sb->s_id,
1278 (unsigned long long)NFS_FILEID(inode));
1282 bool nfs_mapping_need_revalidate_inode(struct inode *inode)
1284 return nfs_check_cache_invalid(inode, NFS_INO_REVAL_PAGECACHE) ||
1285 NFS_STALE(inode);
1288 int nfs_revalidate_mapping_rcu(struct inode *inode)
1290 struct nfs_inode *nfsi = NFS_I(inode);
1294 if (IS_SWAPFILE(inode))
1296 if (nfs_mapping_need_revalidate_inode(inode)) {
1300 spin_lock(&inode->i_lock);
1304 spin_unlock(&inode->i_lock);
1311 * @inode: pointer to host inode
1314 int nfs_revalidate_mapping(struct inode *inode,
1317 struct nfs_inode *nfsi = NFS_I(inode);
1322 if (IS_SWAPFILE(inode))
1325 if (nfs_mapping_need_revalidate_inode(inode)) {
1326 ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
1348 spin_lock(&inode->i_lock);
1350 spin_unlock(&inode->i_lock);
1355 spin_unlock(&inode->i_lock);
1363 spin_unlock(&inode->i_lock);
1364 trace_nfs_invalidate_mapping_enter(inode);
1365 ret = nfs_invalidate_mapping(inode, mapping);
1366 trace_nfs_invalidate_mapping_exit(inode, ret);
1377 struct inode *inode = &nfsi->vfs_inode;
1379 if (!S_ISREG(inode->i_mode))
1383 return inode_is_open_for_write(inode);
1391 static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1397 && inode_eq_iversion_raw(inode, fattr->pre_change_attr)) {
1398 inode_set_iversion_raw(inode, fattr->change_attr);
1399 if (S_ISDIR(inode->i_mode))
1400 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);
1405 ts = inode->i_ctime;
1409 inode->i_ctime = fattr->ctime;
1412 ts = inode->i_mtime;
1416 inode->i_mtime = fattr->mtime;
1417 if (S_ISDIR(inode->i_mode))
1418 nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
1422 && i_size_read(inode) == nfs_size_to_loff_t(fattr->pre_size)
1423 && !nfs_have_writebacks(inode)) {
1424 i_size_write(inode, nfs_size_to_loff_t(fattr->size));
1429 * nfs_check_inode_attributes - verify consistency of the inode attribute cache
1430 * @inode: pointer to inode
1437 static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fattr)
1439 struct nfs_inode *nfsi = NFS_I(inode);
1444 if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
1451 /* Has the inode gone and changed behind our back? */
1459 if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && inode_wrong_type(inode, fattr->mode))
1465 if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) != 0 && !inode_eq_iversion_raw(inode, fattr->change_attr))
1469 ts = inode->i_mtime;
1473 ts = inode->i_ctime;
1478 cur_size = i_size_read(inode);
1487 if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
1491 if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
1495 if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
1501 if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
1504 ts = inode->i_atime;
1509 nfs_set_cache_invalid(inode, invalid);
1640 * nfs_inode_attrs_need_update - check if the inode attributes need updating
1641 * @inode: pointer to inode
1651 * or not this RPC call was started after the inode was last updated.
1655 * more recent than the ones cached in the inode.
1658 static int nfs_inode_attrs_need_update(const struct inode *inode, const struct nfs_fattr *fattr)
1660 unsigned long attr_gencount = NFS_I(inode)->attr_gencount;
1666 static int nfs_refresh_inode_locked(struct inode *inode, struct nfs_fattr *fattr)
1670 trace_nfs_refresh_inode_enter(inode);
1672 if (nfs_inode_attrs_need_update(inode, fattr))
1673 ret = nfs_update_inode(inode, fattr);
1675 ret = nfs_check_inode_attributes(inode, fattr);
1677 trace_nfs_refresh_inode_exit(inode, ret);
1682 * nfs_refresh_inode - try to update the inode attribute cache
1683 * @inode: pointer to inode
1687 * other recent updates of the inode metadata, then decide whether it is
1688 * safe to do a full update of the inode attributes, or whether just to
1691 int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
1697 spin_lock(&inode->i_lock);
1698 status = nfs_refresh_inode_locked(inode, fattr);
1699 spin_unlock(&inode->i_lock);
1705 static int nfs_post_op_update_inode_locked(struct inode *inode,
1708 if (S_ISDIR(inode->i_mode))
1710 nfs_set_cache_invalid(inode, invalid);
1713 return nfs_refresh_inode_locked(inode, fattr);
1717 * nfs_post_op_update_inode - try to update the inode attribute cache
1718 * @inode: pointer to inode
1721 * After an operation that has changed the inode metadata, mark the
1730 int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1734 spin_lock(&inode->i_lock);
1736 status = nfs_post_op_update_inode_locked(inode, fattr,
1740 spin_unlock(&inode->i_lock);
1747 * nfs_post_op_update_inode_force_wcc_locked - update the inode attribute cache
1748 * @inode: pointer to inode
1751 * After an operation that has changed the inode metadata, mark the
1757 int nfs_post_op_update_inode_force_wcc_locked(struct inode *inode, struct nfs_fattr *fattr)
1763 !nfs_inode_attrs_need_update(inode, fattr)) {
1772 fattr->pre_change_attr = inode_peek_iversion_raw(inode);
1777 fattr->pre_ctime = inode->i_ctime;
1782 fattr->pre_mtime = inode->i_mtime;
1787 fattr->pre_size = i_size_read(inode);
1791 status = nfs_post_op_update_inode_locked(inode, fattr,
1800 * nfs_post_op_update_inode_force_wcc - try to update the inode attribute cache
1801 * @inode: pointer to inode
1804 * After an operation that has changed the inode metadata, mark the
1810 int nfs_post_op_update_inode_force_wcc(struct inode *inode, struct nfs_fattr *fattr)
1814 spin_lock(&inode->i_lock);
1816 status = nfs_post_op_update_inode_force_wcc_locked(inode, fattr);
1817 spin_unlock(&inode->i_lock);
1825 * an operation. Here we update the inode to reflect the state
1826 * of the server's inode.
1835 static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1838 struct nfs_inode *nfsi = NFS_I(inode);
1849 __func__, inode->i_sb->s_id, inode->i_ino,
1850 nfs_display_fhandle_hash(NFS_FH(inode)),
1851 atomic_read(&inode->i_count), fattr->valid);
1857 /* Has the inode gone and changed behind our back? */
1865 NFS_SERVER(inode)->nfs_client->cl_hostname,
1866 inode->i_sb->s_id, (long long)nfsi->fileid,
1872 * Make sure the inode's type hasn't changed.
1874 if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && inode_wrong_type(inode, fattr->mode)) {
1876 * Big trouble! The inode has become a different object.
1878 printk(KERN_DEBUG "NFS: %s: inode %lu mode changed, %07o to %07o\n",
1879 __func__, inode->i_ino, inode->i_mode, fattr->mode);
1883 server = NFS_SERVER(inode);
1885 if (S_ISDIR(inode->i_mode) && (fattr->valid & NFS_ATTR_FATTR_FSID) &&
1887 !IS_AUTOMOUNT(inode))
1891 have_delegation = nfs_have_delegated_attributes(inode);
1906 nfs_wcc_update_inode(inode, fattr);
1908 if (pnfs_layoutcommit_outstanding(inode)) {
1919 if (!inode_eq_iversion_raw(inode, fattr->change_attr)) {
1931 if (S_ISDIR(inode->i_mode))
1932 nfs_force_lookup_revalidate(inode);
1934 inode->i_sb->s_id,
1935 inode->i_ino);
1938 inode_set_iversion_raw(inode, fattr->change_attr);
1950 inode->i_mtime = fattr->mtime;
1959 inode->i_ctime = fattr->ctime;
1970 cur_isize = i_size_read(inode);
1974 if (!nfs_have_writebacks(inode) || new_isize > cur_isize) {
1975 i_size_write(inode, new_isize);
1982 inode->i_sb->s_id,
1983 inode->i_ino,
1997 inode->i_atime = fattr->atime;
2006 if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) {
2007 umode_t newmode = inode->i_mode & S_IFMT;
2009 inode->i_mode = newmode;
2022 if (!uid_eq(inode->i_uid, fattr->uid)) {
2025 inode->i_uid = fattr->uid;
2036 if (!gid_eq(inode->i_gid, fattr->gid)) {
2039 inode->i_gid = fattr->gid;
2050 if (inode->i_nlink != fattr->nlink) {
2051 if (S_ISDIR(inode->i_mode))
2053 set_nlink(inode, fattr->nlink);
2067 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
2069 inode->i_blocks = fattr->du.nfs2.blocks;
2080 nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
2081 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
2090 if (nfsi->attrtimeo > NFS_MAXATTRTIMEO(inode))
2091 nfsi->attrtimeo = NFS_MAXATTRTIMEO(inode);
2101 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)
2102 || S_ISLNK(inode->i_mode)))
2104 nfs_set_cache_invalid(inode, invalid);
2110 * lookup validation will know that the inode is bad.
2113 nfs_set_inode_stale_locked(inode);
2117 struct inode *nfs_alloc_inode(struct super_block *sb)
2135 void nfs_free_inode(struct inode *inode)
2137 kmem_cache_free(nfs_inode_cachep, NFS_I(inode));