Lines Matching +full:- +full:- +full:valid +full:- +full:-

1 // SPDX-License-Identifier: GPL-2.0-only
12 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
62 /* Default is to see 64-bit inode numbers */
72 return nfs_fileid_to_ino_t(fattr->fileid); in nfs_fattr_to_ino_t()
79 return -ERESTARTSYS; in nfs_wait_killable()
90 * nfs_compat_user_ino64 - returns the user-visible inode number
91 * @fileid: 64-bit fileid
93 * This function returns a 32-bit inode number if the boot parameter
108 ino ^= fileid >> (sizeof(fileid)-sizeof(ino)) * 8; in nfs_compat_user_ino64()
124 WARN_ON_ONCE(!list_empty(&NFS_I(inode)->open_files)); in nfs_clear_inode()
133 truncate_inode_pages_final(&inode->i_data); in nfs_evict_inode()
146 * nfs_sync_mapping - helper to flush all mmapped dirty data to disk
153 if (mapping->nrpages != 0) { in nfs_sync_mapping()
155 ret = nfs_wb_all(mapping->host); in nfs_sync_mapping()
164 …return !time_in_range_open(jiffies, nfsi->read_cache_jiffies, nfsi->read_cache_jiffies + nfsi->att… in nfs_attribute_timeout()
169 unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); in nfs_check_cache_invalid_delegated()
180 unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); in nfs_check_cache_invalid_not_delegated()
191 if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ)) in nfs_check_cache_invalid()
201 bool have_delegation = NFS_PROTO(inode)->have_delegation(inode, FMODE_READ); in nfs_set_cache_invalid()
212 if (inode->i_mapping->nrpages == 0) in nfs_set_cache_invalid()
214 nfsi->cache_validity |= flags; in nfs_set_cache_invalid()
225 int mode = inode->i_mode; in nfs_zap_caches_locked()
229 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode); in nfs_zap_caches_locked()
230 nfsi->attrtimeo_timestamp = jiffies; in nfs_zap_caches_locked()
232 memset(NFS_I(inode)->cookieverf, 0, sizeof(NFS_I(inode)->cookieverf)); in nfs_zap_caches_locked()
251 spin_lock(&inode->i_lock); in nfs_zap_caches()
253 spin_unlock(&inode->i_lock); in nfs_zap_caches()
258 if (mapping->nrpages != 0) { in nfs_zap_mapping()
259 spin_lock(&inode->i_lock); in nfs_zap_mapping()
261 spin_unlock(&inode->i_lock); in nfs_zap_mapping()
269 clear_acl_cache = NFS_PROTO(inode)->clear_acl_cache; in nfs_zap_acl_cache()
272 spin_lock(&inode->i_lock); in nfs_zap_acl_cache()
273 NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_ACL; in nfs_zap_acl_cache()
274 spin_unlock(&inode->i_lock); in nfs_zap_acl_cache()
280 spin_lock(&inode->i_lock); in nfs_invalidate_atime()
282 spin_unlock(&inode->i_lock); in nfs_invalidate_atime()
288 * NB: must be called with inode->i_lock held!
292 set_bit(NFS_INO_STALE, &NFS_I(inode)->flags); in nfs_set_inode_stale_locked()
299 spin_lock(&inode->i_lock); in nfs_set_inode_stale()
301 spin_unlock(&inode->i_lock); in nfs_set_inode_stale()
311 * this, and re-exported directories (also seen in NFSv2)
319 struct nfs_fh *fh = desc->fh; in nfs_find_actor()
320 struct nfs_fattr *fattr = desc->fattr; in nfs_find_actor()
322 if (NFS_FILEID(inode) != fattr->fileid) in nfs_find_actor()
324 if ((S_IFMT & inode->i_mode) != (S_IFMT & fattr->mode)) in nfs_find_actor()
337 struct nfs_fattr *fattr = desc->fattr; in nfs_init_locked()
339 set_nfs_fileid(inode, fattr->fileid); in nfs_init_locked()
340 inode->i_mode = fattr->mode; in nfs_init_locked()
341 nfs_copy_fh(NFS_FH(inode), desc->fh); in nfs_init_locked()
348 spin_lock(&inode->i_lock); in nfs_clear_label_invalid()
349 NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_LABEL; in nfs_clear_label_invalid()
350 spin_unlock(&inode->i_lock); in nfs_clear_label_invalid()
361 if ((fattr->valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL) && inode->i_security) { in nfs_setsecurity()
362 error = security_inode_notifysecctx(inode, label->label, in nfs_setsecurity()
363 label->len); in nfs_setsecurity()
368 (char *)label->label, in nfs_setsecurity()
369 label->len, error); in nfs_setsecurity()
377 int minor_version = server->nfs_client->cl_minorversion; in nfs4_label_alloc()
382 if (!(server->caps & NFS_CAP_SECURITY_LABEL)) in nfs4_label_alloc()
387 return ERR_PTR(-ENOMEM); in nfs4_label_alloc()
389 label->label = kzalloc(NFS4_MAXLABELLEN, flags); in nfs4_label_alloc()
390 if (label->label == NULL) { in nfs4_label_alloc()
392 return ERR_PTR(-ENOMEM); in nfs4_label_alloc()
394 label->len = NFS4_MAXLABELLEN; in nfs4_label_alloc()
418 if (!(fattr->valid & NFS_ATTR_FATTR_FILEID) || in nfs_ilookup()
419 !(fattr->valid & NFS_ATTR_FATTR_TYPE)) in nfs_ilookup()
430 * This is our front-end to iget that looks up inodes by file handle
440 struct inode *inode = ERR_PTR(-ENOENT); in nfs_fhget()
446 fattr->fileid = fattr->mounted_on_fileid; in nfs_fhget()
447 else if ((fattr->valid & NFS_ATTR_FATTR_FILEID) == 0) in nfs_fhget()
449 if ((fattr->valid & NFS_ATTR_FATTR_TYPE) == 0) in nfs_fhget()
456 inode = ERR_PTR(-ENOMEM); in nfs_fhget()
460 if (inode->i_state & I_NEW) { in nfs_fhget()
466 inode->i_ino = hash; in nfs_fhget()
469 inode->i_flags |= S_NOATIME|S_NOCMTIME; in nfs_fhget()
470 inode->i_mode = fattr->mode; in nfs_fhget()
471 nfsi->cache_validity = 0; in nfs_fhget()
472 if ((fattr->valid & NFS_ATTR_FATTR_MODE) == 0 in nfs_fhget()
478 inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->file_inode_ops; in nfs_fhget()
479 if (S_ISREG(inode->i_mode)) { in nfs_fhget()
480 inode->i_fop = NFS_SB(sb)->nfs_client->rpc_ops->file_ops; in nfs_fhget()
481 inode->i_data.a_ops = &nfs_file_aops; in nfs_fhget()
482 } else if (S_ISDIR(inode->i_mode)) { in nfs_fhget()
483 inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->dir_inode_ops; in nfs_fhget()
484 inode->i_fop = &nfs_dir_operations; in nfs_fhget()
485 inode->i_data.a_ops = &nfs_dir_aops; in nfs_fhget()
487 if (fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT || in nfs_fhget()
488 fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) { in nfs_fhget()
489 if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) in nfs_fhget()
490 inode->i_op = &nfs_referral_inode_operations; in nfs_fhget()
492 inode->i_op = &nfs_mountpoint_inode_operations; in nfs_fhget()
493 inode->i_fop = NULL; in nfs_fhget()
494 inode->i_flags |= S_AUTOMOUNT; in nfs_fhget()
496 } else if (S_ISLNK(inode->i_mode)) { in nfs_fhget()
497 inode->i_op = &nfs_symlink_inode_operations; in nfs_fhget()
500 init_special_inode(inode, inode->i_mode, fattr->rdev); in nfs_fhget()
502 memset(&inode->i_atime, 0, sizeof(inode->i_atime)); in nfs_fhget()
503 memset(&inode->i_mtime, 0, sizeof(inode->i_mtime)); in nfs_fhget()
504 memset(&inode->i_ctime, 0, sizeof(inode->i_ctime)); in nfs_fhget()
506 inode->i_size = 0; in nfs_fhget()
508 inode->i_uid = make_kuid(&init_user_ns, -2); in nfs_fhget()
509 inode->i_gid = make_kgid(&init_user_ns, -2); in nfs_fhget()
510 inode->i_blocks = 0; in nfs_fhget()
511 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf)); in nfs_fhget()
512 nfsi->write_io = 0; in nfs_fhget()
513 nfsi->read_io = 0; in nfs_fhget()
515 nfsi->read_cache_jiffies = fattr->time_start; in nfs_fhget()
516 nfsi->attr_gencount = fattr->gencount; in nfs_fhget()
517 if (fattr->valid & NFS_ATTR_FATTR_ATIME) in nfs_fhget()
518 inode->i_atime = fattr->atime; in nfs_fhget()
521 if (fattr->valid & NFS_ATTR_FATTR_MTIME) in nfs_fhget()
522 inode->i_mtime = fattr->mtime; in nfs_fhget()
525 if (fattr->valid & NFS_ATTR_FATTR_CTIME) in nfs_fhget()
526 inode->i_ctime = fattr->ctime; in nfs_fhget()
529 if (fattr->valid & NFS_ATTR_FATTR_CHANGE) in nfs_fhget()
530 inode_set_iversion_raw(inode, fattr->change_attr); in nfs_fhget()
533 if (fattr->valid & NFS_ATTR_FATTR_SIZE) in nfs_fhget()
534 inode->i_size = nfs_size_to_loff_t(fattr->size); in nfs_fhget()
537 if (fattr->valid & NFS_ATTR_FATTR_NLINK) in nfs_fhget()
538 set_nlink(inode, fattr->nlink); in nfs_fhget()
541 if (fattr->valid & NFS_ATTR_FATTR_OWNER) in nfs_fhget()
542 inode->i_uid = fattr->uid; in nfs_fhget()
545 if (fattr->valid & NFS_ATTR_FATTR_GROUP) in nfs_fhget()
546 inode->i_gid = fattr->gid; in nfs_fhget()
551 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED) in nfs_fhget()
552 inode->i_blocks = fattr->du.nfs2.blocks; in nfs_fhget()
553 if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { in nfs_fhget()
557 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used); in nfs_fhget()
560 if (nfsi->cache_validity != 0) in nfs_fhget()
561 nfsi->cache_validity |= NFS_INO_REVAL_FORCED; in nfs_fhget()
565 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode); in nfs_fhget()
566 nfsi->attrtimeo_timestamp = now; in nfs_fhget()
567 nfsi->access_cache = RB_ROOT; in nfs_fhget()
581 inode->i_sb->s_id, in nfs_fhget()
584 atomic_read(&inode->i_count)); in nfs_fhget()
607 if (attr->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) in nfs_setattr()
608 attr->ia_valid &= ~ATTR_MODE; in nfs_setattr()
610 if (attr->ia_valid & ATTR_SIZE) { in nfs_setattr()
611 BUG_ON(!S_ISREG(inode->i_mode)); in nfs_setattr()
613 error = inode_newsize_ok(inode, attr->ia_size); in nfs_setattr()
617 if (attr->ia_size == i_size_read(inode)) in nfs_setattr()
618 attr->ia_valid &= ~ATTR_SIZE; in nfs_setattr()
622 attr->ia_valid &= NFS_VALID_ATTRS; in nfs_setattr()
623 if ((attr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) in nfs_setattr()
629 if (S_ISREG(inode->i_mode)) in nfs_setattr()
634 error = -ENOMEM; in nfs_setattr()
638 error = NFS_PROTO(inode)->setattr(dentry, fattr, attr); in nfs_setattr()
649 * nfs_vmtruncate - unmap mappings "freed" by truncate() syscall
655 * inode->i_size to be updated under the inode->i_lock.
656 * Note: must be called with inode->i_lock held!
669 NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_DATA | in nfs_vmtruncate()
671 NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_SIZE; in nfs_vmtruncate()
673 spin_unlock(&inode->i_lock); in nfs_vmtruncate()
675 spin_lock(&inode->i_lock); in nfs_vmtruncate()
681 * nfs_setattr_update_inode - Update inode metadata after a setattr call.
695 spin_lock(&inode->i_lock); in nfs_setattr_update_inode()
696 NFS_I(inode)->attr_gencount = fattr->gencount; in nfs_setattr_update_inode()
697 if ((attr->ia_valid & ATTR_SIZE) != 0) { in nfs_setattr_update_inode()
700 nfs_vmtruncate(inode, attr->ia_size); in nfs_setattr_update_inode()
702 if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) { in nfs_setattr_update_inode()
703 NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_CTIME; in nfs_setattr_update_inode()
704 if ((attr->ia_valid & ATTR_MODE) != 0) { in nfs_setattr_update_inode()
705 int mode = attr->ia_mode & S_IALLUGO; in nfs_setattr_update_inode()
706 mode |= inode->i_mode & ~S_IALLUGO; in nfs_setattr_update_inode()
707 inode->i_mode = mode; in nfs_setattr_update_inode()
709 if ((attr->ia_valid & ATTR_UID) != 0) in nfs_setattr_update_inode()
710 inode->i_uid = attr->ia_uid; in nfs_setattr_update_inode()
711 if ((attr->ia_valid & ATTR_GID) != 0) in nfs_setattr_update_inode()
712 inode->i_gid = attr->ia_gid; in nfs_setattr_update_inode()
713 if (fattr->valid & NFS_ATTR_FATTR_CTIME) in nfs_setattr_update_inode()
714 inode->i_ctime = fattr->ctime; in nfs_setattr_update_inode()
721 if (attr->ia_valid & (ATTR_ATIME_SET|ATTR_ATIME)) { in nfs_setattr_update_inode()
722 NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_ATIME in nfs_setattr_update_inode()
724 if (fattr->valid & NFS_ATTR_FATTR_ATIME) in nfs_setattr_update_inode()
725 inode->i_atime = fattr->atime; in nfs_setattr_update_inode()
726 else if (attr->ia_valid & ATTR_ATIME_SET) in nfs_setattr_update_inode()
727 inode->i_atime = attr->ia_atime; in nfs_setattr_update_inode()
731 if (fattr->valid & NFS_ATTR_FATTR_CTIME) in nfs_setattr_update_inode()
732 inode->i_ctime = fattr->ctime; in nfs_setattr_update_inode()
737 if (attr->ia_valid & (ATTR_MTIME_SET|ATTR_MTIME)) { in nfs_setattr_update_inode()
738 NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_MTIME in nfs_setattr_update_inode()
740 if (fattr->valid & NFS_ATTR_FATTR_MTIME) in nfs_setattr_update_inode()
741 inode->i_mtime = fattr->mtime; in nfs_setattr_update_inode()
742 else if (attr->ia_valid & ATTR_MTIME_SET) in nfs_setattr_update_inode()
743 inode->i_mtime = attr->ia_mtime; in nfs_setattr_update_inode()
747 if (fattr->valid & NFS_ATTR_FATTR_CTIME) in nfs_setattr_update_inode()
748 inode->i_ctime = fattr->ctime; in nfs_setattr_update_inode()
753 if (fattr->valid) in nfs_setattr_update_inode()
755 spin_unlock(&inode->i_lock); in nfs_setattr_update_inode()
783 if (NFS_I(inode)->cache_validity & in nfs_need_revalidate_inode()
794 struct inode *inode = d_inode(path->dentry); in nfs_getattr()
804 nfs_readdirplus_parent_cache_hit(path->dentry); in nfs_getattr()
810 S_ISREG(inode->i_mode)) { in nfs_getattr()
811 err = filemap_write_and_wait(inode->i_mapping); in nfs_getattr()
820 * - NFS always sets S_NOATIME by so checking it would give a in nfs_getattr()
822 * - NFS never sets SB_NOATIME or SB_NODIRATIME so there is in nfs_getattr()
825 if ((path->mnt->mnt_flags & MNT_NOATIME) || in nfs_getattr()
826 ((path->mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode))) in nfs_getattr()
837 cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); in nfs_getattr()
848 if (!(server->flags & NFS_MOUNT_NOAC)) in nfs_getattr()
849 nfs_readdirplus_parent_cache_miss(path->dentry); in nfs_getattr()
851 nfs_readdirplus_parent_cache_hit(path->dentry); in nfs_getattr()
856 nfs_readdirplus_parent_cache_hit(path->dentry); in nfs_getattr()
859 stat->result_mask &= request_mask; in nfs_getattr()
862 stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode)); in nfs_getattr()
863 if (S_ISDIR(inode->i_mode)) in nfs_getattr()
864 stat->blksize = NFS_SERVER(inode)->dtsize; in nfs_getattr()
873 refcount_set(&l_ctx->count, 1); in nfs_init_lock_context()
874 l_ctx->lockowner = current->files; in nfs_init_lock_context()
875 INIT_LIST_HEAD(&l_ctx->list); in nfs_init_lock_context()
876 atomic_set(&l_ctx->io_count, 0); in nfs_init_lock_context()
883 list_for_each_entry_rcu(pos, &ctx->lock_context.list, list) { in __nfs_find_lock_context()
884 if (pos->lockowner != current->files) in __nfs_find_lock_context()
886 if (refcount_inc_not_zero(&pos->count)) in __nfs_find_lock_context()
895 struct inode *inode = d_inode(ctx->dentry); in nfs_get_lock_context()
903 return ERR_PTR(-ENOMEM); in nfs_get_lock_context()
905 spin_lock(&inode->i_lock); in nfs_get_lock_context()
908 new->open_context = get_nfs_open_context(ctx); in nfs_get_lock_context()
909 if (new->open_context) { in nfs_get_lock_context()
910 list_add_tail_rcu(&new->list, in nfs_get_lock_context()
911 &ctx->lock_context.list); in nfs_get_lock_context()
915 res = ERR_PTR(-EBADF); in nfs_get_lock_context()
917 spin_unlock(&inode->i_lock); in nfs_get_lock_context()
926 struct nfs_open_context *ctx = l_ctx->open_context; in nfs_put_lock_context()
927 struct inode *inode = d_inode(ctx->dentry); in nfs_put_lock_context()
929 if (!refcount_dec_and_lock(&l_ctx->count, &inode->i_lock)) in nfs_put_lock_context()
931 list_del_rcu(&l_ctx->list); in nfs_put_lock_context()
932 spin_unlock(&inode->i_lock); in nfs_put_lock_context()
939 * nfs_close_context - Common close_context() routine NFSv2/v3
944 * with close-to-open semantics and we have cached data that will
953 if (!(ctx->mode & FMODE_WRITE)) in nfs_close_context()
957 inode = d_inode(ctx->dentry); in nfs_close_context()
958 if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ)) in nfs_close_context()
961 if (inode->i_mapping->nrpages == 0) in nfs_close_context()
963 if (nfsi->cache_validity & NFS_INO_INVALID_DATA) in nfs_close_context()
965 if (!list_empty(&nfsi->open_files)) in nfs_close_context()
968 if (server->flags & NFS_MOUNT_NOCTO) in nfs_close_context()
982 return ERR_PTR(-ENOMEM); in alloc_nfs_open_context()
983 nfs_sb_active(dentry->d_sb); in alloc_nfs_open_context()
984 ctx->dentry = dget(dentry); in alloc_nfs_open_context()
986 ctx->cred = get_cred(filp->f_cred); in alloc_nfs_open_context()
988 ctx->cred = get_current_cred(); in alloc_nfs_open_context()
989 ctx->ll_cred = NULL; in alloc_nfs_open_context()
990 ctx->state = NULL; in alloc_nfs_open_context()
991 ctx->mode = f_mode; in alloc_nfs_open_context()
992 ctx->flags = 0; in alloc_nfs_open_context()
993 ctx->error = 0; in alloc_nfs_open_context()
994 ctx->flock_owner = (fl_owner_t)filp; in alloc_nfs_open_context()
995 nfs_init_lock_context(&ctx->lock_context); in alloc_nfs_open_context()
996 ctx->lock_context.open_context = ctx; in alloc_nfs_open_context()
997 INIT_LIST_HEAD(&ctx->list); in alloc_nfs_open_context()
998 ctx->mdsthreshold = NULL; in alloc_nfs_open_context()
1005 if (ctx != NULL && refcount_inc_not_zero(&ctx->lock_context.count)) in get_nfs_open_context()
1013 struct inode *inode = d_inode(ctx->dentry); in __put_nfs_open_context()
1014 struct super_block *sb = ctx->dentry->d_sb; in __put_nfs_open_context()
1016 if (!refcount_dec_and_test(&ctx->lock_context.count)) in __put_nfs_open_context()
1018 if (!list_empty(&ctx->list)) { in __put_nfs_open_context()
1019 spin_lock(&inode->i_lock); in __put_nfs_open_context()
1020 list_del_rcu(&ctx->list); in __put_nfs_open_context()
1021 spin_unlock(&inode->i_lock); in __put_nfs_open_context()
1024 NFS_PROTO(inode)->close_context(ctx, is_sync); in __put_nfs_open_context()
1025 put_cred(ctx->cred); in __put_nfs_open_context()
1026 dput(ctx->dentry); in __put_nfs_open_context()
1028 put_rpccred(ctx->ll_cred); in __put_nfs_open_context()
1029 kfree(ctx->mdsthreshold); in __put_nfs_open_context()
1050 struct inode *inode = d_inode(ctx->dentry); in nfs_inode_attach_open_context()
1053 spin_lock(&inode->i_lock); in nfs_inode_attach_open_context()
1054 if (list_empty(&nfsi->open_files) && in nfs_inode_attach_open_context()
1055 (nfsi->cache_validity & NFS_INO_DATA_INVAL_DEFER)) in nfs_inode_attach_open_context()
1056 nfsi->cache_validity |= NFS_INO_INVALID_DATA | in nfs_inode_attach_open_context()
1058 list_add_tail_rcu(&ctx->list, &nfsi->open_files); in nfs_inode_attach_open_context()
1059 spin_unlock(&inode->i_lock); in nfs_inode_attach_open_context()
1065 filp->private_data = get_nfs_open_context(ctx); in nfs_file_set_open_context()
1066 if (list_empty(&ctx->list)) in nfs_file_set_open_context()
1080 list_for_each_entry_rcu(pos, &nfsi->open_files, list) { in nfs_find_open_context()
1081 if (cred != NULL && cred_fscmp(pos->cred, cred) != 0) in nfs_find_open_context()
1083 if ((pos->mode & (FMODE_READ|FMODE_WRITE)) != mode) in nfs_find_open_context()
1098 struct inode *inode = d_inode(ctx->dentry); in nfs_file_clear_open_context()
1104 if (ctx->error < 0) in nfs_file_clear_open_context()
1105 invalidate_inode_pages2(inode->i_mapping); in nfs_file_clear_open_context()
1106 filp->private_data = NULL; in nfs_file_clear_open_context()
1118 ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode, filp); in nfs_open()
1135 int status = -ESTALE; in __nfs_revalidate_inode()
1141 inode->i_sb->s_id, (unsigned long long)NFS_FILEID(inode)); in __nfs_revalidate_inode()
1151 if (S_ISREG(inode->i_mode)) { in __nfs_revalidate_inode()
1157 status = -ENOMEM; in __nfs_revalidate_inode()
1170 status = NFS_PROTO(inode)->getattr(server, NFS_FH(inode), fattr, in __nfs_revalidate_inode()
1174 inode->i_sb->s_id, in __nfs_revalidate_inode()
1177 case -ETIMEDOUT: in __nfs_revalidate_inode()
1179 if (server->flags & NFS_MOUNT_SOFTREVAL) in __nfs_revalidate_inode()
1182 case -ESTALE: in __nfs_revalidate_inode()
1183 if (!S_ISDIR(inode->i_mode)) in __nfs_revalidate_inode()
1194 inode->i_sb->s_id, in __nfs_revalidate_inode()
1199 if (nfsi->cache_validity & NFS_INO_INVALID_ACL) in __nfs_revalidate_inode()
1205 inode->i_sb->s_id, in __nfs_revalidate_inode()
1224 * nfs_revalidate_inode - Revalidate the inode attributes
1233 return NFS_STALE(inode) ? -ESTALE : 0; in nfs_revalidate_inode()
1243 if (mapping->nrpages != 0) { in nfs_invalidate_mapping()
1244 if (S_ISREG(inode->i_mode)) { in nfs_invalidate_mapping()
1253 if (S_ISDIR(inode->i_mode)) { in nfs_invalidate_mapping()
1254 spin_lock(&inode->i_lock); in nfs_invalidate_mapping()
1255 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf)); in nfs_invalidate_mapping()
1256 spin_unlock(&inode->i_lock); in nfs_invalidate_mapping()
1262 inode->i_sb->s_id, in nfs_invalidate_mapping()
1276 unsigned long *bitlock = &nfsi->flags; in nfs_revalidate_mapping_rcu()
1282 ret = -ECHILD; in nfs_revalidate_mapping_rcu()
1285 spin_lock(&inode->i_lock); in nfs_revalidate_mapping_rcu()
1287 (nfsi->cache_validity & NFS_INO_INVALID_DATA)) in nfs_revalidate_mapping_rcu()
1288 ret = -ECHILD; in nfs_revalidate_mapping_rcu()
1289 spin_unlock(&inode->i_lock); in nfs_revalidate_mapping_rcu()
1295 * nfs_revalidate_mapping - Revalidate the pagecache
1303 unsigned long *bitlock = &nfsi->flags; in nfs_revalidate_mapping()
1333 spin_lock(&inode->i_lock); in nfs_revalidate_mapping()
1335 spin_unlock(&inode->i_lock); in nfs_revalidate_mapping()
1338 if (nfsi->cache_validity & NFS_INO_INVALID_DATA) in nfs_revalidate_mapping()
1340 spin_unlock(&inode->i_lock); in nfs_revalidate_mapping()
1346 nfsi->cache_validity &= ~(NFS_INO_INVALID_DATA| in nfs_revalidate_mapping()
1348 spin_unlock(&inode->i_lock); in nfs_revalidate_mapping()
1362 struct inode *inode = &nfsi->vfs_inode; in nfs_file_has_writers()
1364 if (!S_ISREG(inode->i_mode)) in nfs_file_has_writers()
1366 if (list_empty(&nfsi->open_files)) in nfs_file_has_writers()
1380 if ((fattr->valid & NFS_ATTR_FATTR_PRECHANGE) in nfs_wcc_update_inode()
1381 && (fattr->valid & NFS_ATTR_FATTR_CHANGE) in nfs_wcc_update_inode()
1382 && inode_eq_iversion_raw(inode, fattr->pre_change_attr)) { in nfs_wcc_update_inode()
1383 inode_set_iversion_raw(inode, fattr->change_attr); in nfs_wcc_update_inode()
1384 if (S_ISDIR(inode->i_mode)) in nfs_wcc_update_inode()
1390 ts = inode->i_ctime; in nfs_wcc_update_inode()
1391 if ((fattr->valid & NFS_ATTR_FATTR_PRECTIME) in nfs_wcc_update_inode()
1392 && (fattr->valid & NFS_ATTR_FATTR_CTIME) in nfs_wcc_update_inode()
1393 && timespec64_equal(&ts, &fattr->pre_ctime)) { in nfs_wcc_update_inode()
1394 inode->i_ctime = fattr->ctime; in nfs_wcc_update_inode()
1397 ts = inode->i_mtime; in nfs_wcc_update_inode()
1398 if ((fattr->valid & NFS_ATTR_FATTR_PREMTIME) in nfs_wcc_update_inode()
1399 && (fattr->valid & NFS_ATTR_FATTR_MTIME) in nfs_wcc_update_inode()
1400 && timespec64_equal(&ts, &fattr->pre_mtime)) { in nfs_wcc_update_inode()
1401 inode->i_mtime = fattr->mtime; in nfs_wcc_update_inode()
1402 if (S_ISDIR(inode->i_mode)) in nfs_wcc_update_inode()
1405 if ((fattr->valid & NFS_ATTR_FATTR_PRESIZE) in nfs_wcc_update_inode()
1406 && (fattr->valid & NFS_ATTR_FATTR_SIZE) in nfs_wcc_update_inode()
1407 && i_size_read(inode) == nfs_size_to_loff_t(fattr->pre_size) in nfs_wcc_update_inode()
1409 i_size_write(inode, nfs_size_to_loff_t(fattr->size)); in nfs_wcc_update_inode()
1414 * nfs_check_inode_attributes - verify consistency of the inode attribute cache
1429 if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ)) in nfs_check_inode_attributes()
1432 if (!(fattr->valid & NFS_ATTR_FATTR_FILEID)) { in nfs_check_inode_attributes()
1433 /* Only a mounted-on-fileid? Just exit */ in nfs_check_inode_attributes()
1434 if (fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) in nfs_check_inode_attributes()
1437 } else if (nfsi->fileid != fattr->fileid) { in nfs_check_inode_attributes()
1438 /* Is this perhaps the mounted-on fileid? */ in nfs_check_inode_attributes()
1439 if ((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) && in nfs_check_inode_attributes()
1440 nfsi->fileid == fattr->mounted_on_fileid) in nfs_check_inode_attributes()
1442 return -ESTALE; in nfs_check_inode_attributes()
1444 if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT)) in nfs_check_inode_attributes()
1445 return -ESTALE; in nfs_check_inode_attributes()
1450 …if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) != 0 && !inode_eq_iversion_raw(inode, fattr->change_att… in nfs_check_inode_attributes()
1454 ts = inode->i_mtime; in nfs_check_inode_attributes()
1455 if ((fattr->valid & NFS_ATTR_FATTR_MTIME) && !timespec64_equal(&ts, &fattr->mtime)) in nfs_check_inode_attributes()
1458 ts = inode->i_ctime; in nfs_check_inode_attributes()
1459 if ((fattr->valid & NFS_ATTR_FATTR_CTIME) && !timespec64_equal(&ts, &fattr->ctime)) in nfs_check_inode_attributes()
1462 if (fattr->valid & NFS_ATTR_FATTR_SIZE) { in nfs_check_inode_attributes()
1464 new_isize = nfs_size_to_loff_t(fattr->size); in nfs_check_inode_attributes()
1472 …if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUG… in nfs_check_inode_attributes()
1476 if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid)) in nfs_check_inode_attributes()
1480 if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid)) in nfs_check_inode_attributes()
1486 if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink) in nfs_check_inode_attributes()
1489 ts = inode->i_atime; in nfs_check_inode_attributes()
1490 if ((fattr->valid & NFS_ATTR_FATTR_ATIME) && !timespec64_equal(&ts, &fattr->atime)) in nfs_check_inode_attributes()
1496 nfsi->read_cache_jiffies = fattr->time_start; in nfs_check_inode_attributes()
1515 fattr->valid = 0; in nfs_fattr_init()
1516 fattr->time_start = jiffies; in nfs_fattr_init()
1517 fattr->gencount = nfs_inc_attr_generation_counter(); in nfs_fattr_init()
1518 fattr->owner_name = NULL; in nfs_fattr_init()
1519 fattr->group_name = NULL; in nfs_fattr_init()
1536 fattr->gencount = nfs_inc_attr_generation_counter(); in nfs_fattr_set_barrier()
1556 fh->size = 0; in nfs_alloc_fhandle()
1563 * _nfs_display_fhandle_hash - calculate the crc32 hash for the filehandle
1572 /* wireshark uses 32-bit AUTODIN crc and does a bitwise in _nfs_display_fhandle_hash()
1579 * _nfs_display_fhandle - display an NFS file handle on the console
1590 if (fh == NULL || fh->size == 0) { in _nfs_display_fhandle()
1596 caption, fh, fh->size, _nfs_display_fhandle_hash(fh)); in _nfs_display_fhandle()
1597 for (i = 0; i < fh->size; i += 16) { in _nfs_display_fhandle()
1598 __be32 *pos = (__be32 *)&fh->data[i]; in _nfs_display_fhandle()
1600 switch ((fh->size - i - 1) >> 2) { in _nfs_display_fhandle()
1625 * nfs_inode_attrs_need_update - check if the inode attributes need updating
1647 return ((long)fattr->gencount - (long)nfsi->attr_gencount) > 0 || in nfs_inode_attrs_need_update()
1648 ((long)nfsi->attr_gencount - (long)nfs_read_attr_generation_counter() > 0); in nfs_inode_attrs_need_update()
1667 * nfs_refresh_inode - try to update the inode attribute cache
1680 if ((fattr->valid & NFS_ATTR_FATTR) == 0) in nfs_refresh_inode()
1682 spin_lock(&inode->i_lock); in nfs_refresh_inode()
1684 spin_unlock(&inode->i_lock); in nfs_refresh_inode()
1693 if (S_ISDIR(inode->i_mode)) in nfs_post_op_update_inode_locked()
1696 if ((fattr->valid & NFS_ATTR_FATTR) == 0) in nfs_post_op_update_inode_locked()
1702 * nfs_post_op_update_inode - try to update the inode attribute cache
1719 spin_lock(&inode->i_lock); in nfs_post_op_update_inode()
1725 spin_unlock(&inode->i_lock); in nfs_post_op_update_inode()
1732 * nfs_post_op_update_inode_force_wcc_locked - update the inode attribute cache
1740 * This function is mainly designed to be used by the ->write_done() functions.
1747 if ((fattr->valid & NFS_ATTR_FATTR) == 0 || in nfs_post_op_update_inode_force_wcc_locked()
1749 fattr->valid &= ~(NFS_ATTR_FATTR_PRECHANGE in nfs_post_op_update_inode_force_wcc_locked()
1755 if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) != 0 && in nfs_post_op_update_inode_force_wcc_locked()
1756 (fattr->valid & NFS_ATTR_FATTR_PRECHANGE) == 0) { in nfs_post_op_update_inode_force_wcc_locked()
1757 fattr->pre_change_attr = inode_peek_iversion_raw(inode); in nfs_post_op_update_inode_force_wcc_locked()
1758 fattr->valid |= NFS_ATTR_FATTR_PRECHANGE; in nfs_post_op_update_inode_force_wcc_locked()
1760 if ((fattr->valid & NFS_ATTR_FATTR_CTIME) != 0 && in nfs_post_op_update_inode_force_wcc_locked()
1761 (fattr->valid & NFS_ATTR_FATTR_PRECTIME) == 0) { in nfs_post_op_update_inode_force_wcc_locked()
1762 fattr->pre_ctime = inode->i_ctime; in nfs_post_op_update_inode_force_wcc_locked()
1763 fattr->valid |= NFS_ATTR_FATTR_PRECTIME; in nfs_post_op_update_inode_force_wcc_locked()
1765 if ((fattr->valid & NFS_ATTR_FATTR_MTIME) != 0 && in nfs_post_op_update_inode_force_wcc_locked()
1766 (fattr->valid & NFS_ATTR_FATTR_PREMTIME) == 0) { in nfs_post_op_update_inode_force_wcc_locked()
1767 fattr->pre_mtime = inode->i_mtime; in nfs_post_op_update_inode_force_wcc_locked()
1768 fattr->valid |= NFS_ATTR_FATTR_PREMTIME; in nfs_post_op_update_inode_force_wcc_locked()
1770 if ((fattr->valid & NFS_ATTR_FATTR_SIZE) != 0 && in nfs_post_op_update_inode_force_wcc_locked()
1771 (fattr->valid & NFS_ATTR_FATTR_PRESIZE) == 0) { in nfs_post_op_update_inode_force_wcc_locked()
1772 fattr->pre_size = i_size_read(inode); in nfs_post_op_update_inode_force_wcc_locked()
1773 fattr->valid |= NFS_ATTR_FATTR_PRESIZE; in nfs_post_op_update_inode_force_wcc_locked()
1785 * nfs_post_op_update_inode_force_wcc - try to update the inode attribute cache
1793 * This function is mainly designed to be used by the ->write_done() functions.
1799 spin_lock(&inode->i_lock); in nfs_post_op_update_inode_force_wcc()
1802 spin_unlock(&inode->i_lock); in nfs_post_op_update_inode_force_wcc()
1834 __func__, inode->i_sb->s_id, inode->i_ino, in nfs_update_inode()
1836 atomic_read(&inode->i_count), fattr->valid); in nfs_update_inode()
1838 if (!(fattr->valid & NFS_ATTR_FATTR_FILEID)) { in nfs_update_inode()
1839 /* Only a mounted-on-fileid? Just exit */ in nfs_update_inode()
1840 if (fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) in nfs_update_inode()
1843 } else if (nfsi->fileid != fattr->fileid) { in nfs_update_inode()
1844 /* Is this perhaps the mounted-on fileid? */ in nfs_update_inode()
1845 if ((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) && in nfs_update_inode()
1846 nfsi->fileid == fattr->mounted_on_fileid) in nfs_update_inode()
1850 NFS_SERVER(inode)->nfs_client->cl_hostname, in nfs_update_inode()
1851 inode->i_sb->s_id, (long long)nfsi->fileid, in nfs_update_inode()
1852 (long long)fattr->fileid); in nfs_update_inode()
1859 if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT)) { in nfs_update_inode()
1864 __func__, inode->i_ino, inode->i_mode, fattr->mode); in nfs_update_inode()
1870 if (S_ISDIR(inode->i_mode) && (fattr->valid & NFS_ATTR_FATTR_FSID) && in nfs_update_inode()
1871 !nfs_fsid_equal(&server->fsid, &fattr->fsid) && in nfs_update_inode()
1873 server->fsid = fattr->fsid; in nfs_update_inode()
1881 nfsi->read_cache_jiffies = fattr->time_start; in nfs_update_inode()
1883 save_cache_validity = nfsi->cache_validity; in nfs_update_inode()
1884 nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR in nfs_update_inode()
1894 nfsi->cache_validity |= save_cache_validity & NFS_INO_INVALID_ATTR; in nfs_update_inode()
1899 if (fattr->valid & NFS_ATTR_FATTR_CHANGE) { in nfs_update_inode()
1900 if (!inode_eq_iversion_raw(inode, fattr->change_attr)) { in nfs_update_inode()
1912 if (S_ISDIR(inode->i_mode)) in nfs_update_inode()
1915 inode->i_sb->s_id, in nfs_update_inode()
1916 inode->i_ino); in nfs_update_inode()
1918 nfsi->cache_validity |= NFS_INO_DATA_INVAL_DEFER; in nfs_update_inode()
1919 inode_set_iversion_raw(inode, fattr->change_attr); in nfs_update_inode()
1923 nfsi->cache_validity |= save_cache_validity & in nfs_update_inode()
1930 if (fattr->valid & NFS_ATTR_FATTR_MTIME) { in nfs_update_inode()
1931 inode->i_mtime = fattr->mtime; in nfs_update_inode()
1932 } else if (server->caps & NFS_CAP_MTIME) { in nfs_update_inode()
1933 nfsi->cache_validity |= save_cache_validity & in nfs_update_inode()
1939 if (fattr->valid & NFS_ATTR_FATTR_CTIME) { in nfs_update_inode()
1940 inode->i_ctime = fattr->ctime; in nfs_update_inode()
1941 } else if (server->caps & NFS_CAP_CTIME) { in nfs_update_inode()
1942 nfsi->cache_validity |= save_cache_validity & in nfs_update_inode()
1949 if (fattr->valid & NFS_ATTR_FATTR_SIZE) { in nfs_update_inode()
1950 new_isize = nfs_size_to_loff_t(fattr->size); in nfs_update_inode()
1963 inode->i_sb->s_id, in nfs_update_inode()
1964 inode->i_ino, in nfs_update_inode()
1969 nfsi->cache_validity |= save_cache_validity & in nfs_update_inode()
1977 if (fattr->valid & NFS_ATTR_FATTR_ATIME) in nfs_update_inode()
1978 inode->i_atime = fattr->atime; in nfs_update_inode()
1979 else if (server->caps & NFS_CAP_ATIME) { in nfs_update_inode()
1980 nfsi->cache_validity |= save_cache_validity & in nfs_update_inode()
1986 if (fattr->valid & NFS_ATTR_FATTR_MODE) { in nfs_update_inode()
1987 if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) { in nfs_update_inode()
1988 umode_t newmode = inode->i_mode & S_IFMT; in nfs_update_inode()
1989 newmode |= fattr->mode & S_IALLUGO; in nfs_update_inode()
1990 inode->i_mode = newmode; in nfs_update_inode()
1995 } else if (server->caps & NFS_CAP_MODE) { in nfs_update_inode()
1996 nfsi->cache_validity |= save_cache_validity & in nfs_update_inode()
2002 if (fattr->valid & NFS_ATTR_FATTR_OWNER) { in nfs_update_inode()
2003 if (!uid_eq(inode->i_uid, fattr->uid)) { in nfs_update_inode()
2006 inode->i_uid = fattr->uid; in nfs_update_inode()
2009 } else if (server->caps & NFS_CAP_OWNER) { in nfs_update_inode()
2010 nfsi->cache_validity |= save_cache_validity & in nfs_update_inode()
2016 if (fattr->valid & NFS_ATTR_FATTR_GROUP) { in nfs_update_inode()
2017 if (!gid_eq(inode->i_gid, fattr->gid)) { in nfs_update_inode()
2020 inode->i_gid = fattr->gid; in nfs_update_inode()
2023 } else if (server->caps & NFS_CAP_OWNER_GROUP) { in nfs_update_inode()
2024 nfsi->cache_validity |= save_cache_validity & in nfs_update_inode()
2030 if (fattr->valid & NFS_ATTR_FATTR_NLINK) { in nfs_update_inode()
2031 if (inode->i_nlink != fattr->nlink) { in nfs_update_inode()
2032 if (S_ISDIR(inode->i_mode)) in nfs_update_inode()
2034 set_nlink(inode, fattr->nlink); in nfs_update_inode()
2037 } else if (server->caps & NFS_CAP_NLINK) { in nfs_update_inode()
2038 nfsi->cache_validity |= save_cache_validity & in nfs_update_inode()
2044 if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { in nfs_update_inode()
2048 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used); in nfs_update_inode()
2049 } else if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED) in nfs_update_inode()
2050 inode->i_blocks = fattr->du.nfs2.blocks; in nfs_update_inode()
2052 nfsi->cache_validity |= save_cache_validity & in nfs_update_inode()
2062 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode); in nfs_update_inode()
2063 nfsi->attrtimeo_timestamp = now; in nfs_update_inode()
2065 nfsi->attr_gencount = nfs_inc_attr_generation_counter(); in nfs_update_inode()
2068 if (!time_in_range_open(now, nfsi->attrtimeo_timestamp, in nfs_update_inode()
2069 nfsi->attrtimeo_timestamp + nfsi->attrtimeo)) { in nfs_update_inode()
2070 nfsi->attrtimeo <<= 1; in nfs_update_inode()
2071 if (nfsi->attrtimeo > NFS_MAXATTRTIMEO(inode)) in nfs_update_inode()
2072 nfsi->attrtimeo = NFS_MAXATTRTIMEO(inode); in nfs_update_inode()
2074 nfsi->attrtimeo_timestamp = now; in nfs_update_inode()
2077 if ((long)fattr->gencount - (long)nfsi->attr_gencount > 0) in nfs_update_inode()
2078 nfsi->attr_gencount = fattr->gencount; in nfs_update_inode()
2082 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) in nfs_update_inode()
2083 || S_ISLNK(inode->i_mode))) in nfs_update_inode()
2095 return -ESTALE; in nfs_update_inode()
2104 nfsi->flags = 0UL; in nfs_alloc_inode()
2105 nfsi->cache_validity = 0UL; in nfs_alloc_inode()
2107 nfsi->nfs4_acl = NULL; in nfs_alloc_inode()
2110 nfsi->xattr_cache = NULL; in nfs_alloc_inode()
2112 return &nfsi->vfs_inode; in nfs_alloc_inode()
2125 INIT_LIST_HEAD(&nfsi->open_states); in nfs4_init_once()
2126 nfsi->delegation = NULL; in nfs4_init_once()
2127 init_rwsem(&nfsi->rwsem); in nfs4_init_once()
2128 nfsi->layout = NULL; in nfs4_init_once()
2136 inode_init_once(&nfsi->vfs_inode); in init_once()
2137 INIT_LIST_HEAD(&nfsi->open_files); in init_once()
2138 INIT_LIST_HEAD(&nfsi->access_cache_entry_lru); in init_once()
2139 INIT_LIST_HEAD(&nfsi->access_cache_inode_lru); in init_once()
2140 INIT_LIST_HEAD(&nfsi->commit_info.list); in init_once()
2141 atomic_long_set(&nfsi->nrequests, 0); in init_once()
2142 atomic_long_set(&nfsi->commit_info.ncommit, 0); in init_once()
2143 atomic_set(&nfsi->commit_info.rpcs_out, 0); in init_once()
2144 init_rwsem(&nfsi->rmdir_sem); in init_once()
2145 mutex_init(&nfsi->commit_mutex); in init_once()
2147 nfsi->cache_change_attribute = 0; in init_once()
2158 return -ENOMEM; in nfs_init_inodecache()
2185 return -ENOMEM; in nfsiod_start()