^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/fs/nfs/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1992 Rick Sladkey
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * nfs inode and superblock handling functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * experimental NFS changes. Modularisation taken straight from SYS5 fs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * J.S.Peatfield@damtp.cam.ac.uk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/sunrpc/clnt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/sunrpc/stats.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/sunrpc/metrics.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/nfs_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/nfs_mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/nfs4_mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/lockd/bind.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/vfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/nfs_xdr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/freezer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <linux/iversion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include "nfs4_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include "callback.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include "delegation.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include "iostat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include "fscache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include "pnfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include "nfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include "netns.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include "sysfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #include "nfstrace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define NFSDBG_FACILITY NFSDBG_VFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define NFS_64_BIT_INODE_NUMBERS_ENABLED 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* Default is to see 64-bit inode numbers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static bool enable_ino64 = NFS_64_BIT_INODE_NUMBERS_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static int nfs_update_inode(struct inode *, struct nfs_fattr *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static struct kmem_cache * nfs_inode_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static inline unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) nfs_fattr_to_ino_t(struct nfs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return nfs_fileid_to_ino_t(fattr->fileid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static int nfs_wait_killable(int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) freezable_schedule_unsafe();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (signal_pending_state(mode, current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) int nfs_wait_bit_killable(struct wait_bit_key *key, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return nfs_wait_killable(mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) EXPORT_SYMBOL_GPL(nfs_wait_bit_killable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * nfs_compat_user_ino64 - returns the user-visible inode number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * @fileid: 64-bit fileid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * This function returns a 32-bit inode number if the boot parameter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * nfs.enable_ino64 is zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) u64 nfs_compat_user_ino64(u64 fileid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) compat_ulong_t ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) unsigned long ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (enable_ino64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return fileid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ino = fileid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (sizeof(ino) < sizeof(fileid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ino ^= fileid >> (sizeof(fileid)-sizeof(ino)) * 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int nfs_drop_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return NFS_STALE(inode) || generic_drop_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) EXPORT_SYMBOL_GPL(nfs_drop_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) void nfs_clear_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * The following should never happen...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) WARN_ON_ONCE(nfs_have_writebacks(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) WARN_ON_ONCE(!list_empty(&NFS_I(inode)->open_files));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) nfs_zap_acl_cache(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) nfs_access_zap_cache(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) nfs_fscache_clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) EXPORT_SYMBOL_GPL(nfs_clear_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) void nfs_evict_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) truncate_inode_pages_final(&inode->i_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) nfs_clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int nfs_sync_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) inode_dio_wait(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return nfs_wb_all(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) EXPORT_SYMBOL_GPL(nfs_sync_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * nfs_sync_mapping - helper to flush all mmapped dirty data to disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * @mapping: pointer to struct address_space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) int nfs_sync_mapping(struct address_space *mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (mapping->nrpages != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) unmap_mapping_range(mapping, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ret = nfs_wb_all(mapping->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static int nfs_attribute_timeout(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return !time_in_range_open(jiffies, nfsi->read_cache_jiffies, nfsi->read_cache_jiffies + nfsi->attrtimeo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static bool nfs_check_cache_invalid_delegated(struct inode *inode, unsigned long flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* Special case for the pagecache or access cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (flags == NFS_INO_REVAL_PAGECACHE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) !(cache_validity & NFS_INO_REVAL_FORCED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return (cache_validity & flags) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static bool nfs_check_cache_invalid_not_delegated(struct inode *inode, unsigned long flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if ((cache_validity & flags) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (nfs_attribute_timeout(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) bool nfs_check_cache_invalid(struct inode *inode, unsigned long flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return nfs_check_cache_invalid_delegated(inode, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return nfs_check_cache_invalid_not_delegated(inode, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) EXPORT_SYMBOL_GPL(nfs_check_cache_invalid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #ifdef CONFIG_NFS_V4_2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static bool nfs_has_xattr_cache(const struct nfs_inode *nfsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return nfsi->xattr_cache != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static bool nfs_has_xattr_cache(const struct nfs_inode *nfsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) bool have_delegation = NFS_PROTO(inode)->have_delegation(inode, FMODE_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (have_delegation) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (!(flags & NFS_INO_REVAL_FORCED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) flags &= ~NFS_INO_INVALID_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) flags &= ~(NFS_INO_INVALID_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) | NFS_INO_INVALID_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) | NFS_INO_REVAL_PAGECACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) | NFS_INO_INVALID_XATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) } else if (flags & NFS_INO_REVAL_PAGECACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) flags |= NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (!nfs_has_xattr_cache(nfsi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) flags &= ~NFS_INO_INVALID_XATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (inode->i_mapping->nrpages == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) flags &= ~(NFS_INO_INVALID_DATA|NFS_INO_DATA_INVAL_DEFER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) nfsi->cache_validity |= flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (flags & NFS_INO_INVALID_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) nfs_fscache_invalidate(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * Invalidate the local caches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static void nfs_zap_caches_locked(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) int mode = inode->i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) nfsi->attrtimeo_timestamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) memset(NFS_I(inode)->cookieverf, 0, sizeof(NFS_I(inode)->cookieverf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) | NFS_INO_INVALID_DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) | NFS_INO_INVALID_ACCESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) | NFS_INO_INVALID_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) | NFS_INO_INVALID_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) | NFS_INO_REVAL_PAGECACHE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) | NFS_INO_INVALID_ACCESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) | NFS_INO_INVALID_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) | NFS_INO_INVALID_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) | NFS_INO_REVAL_PAGECACHE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) nfs_zap_label_cache_locked(nfsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) void nfs_zap_caches(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) nfs_zap_caches_locked(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) void nfs_zap_mapping(struct inode *inode, struct address_space *mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (mapping->nrpages != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) void nfs_zap_acl_cache(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) void (*clear_acl_cache)(struct inode *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) clear_acl_cache = NFS_PROTO(inode)->clear_acl_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (clear_acl_cache != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) clear_acl_cache(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_ACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) EXPORT_SYMBOL_GPL(nfs_zap_acl_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) void nfs_invalidate_atime(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) EXPORT_SYMBOL_GPL(nfs_invalidate_atime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * Invalidate, but do not unhash, the inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * NB: must be called with inode->i_lock held!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static void nfs_set_inode_stale_locked(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) set_bit(NFS_INO_STALE, &NFS_I(inode)->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) nfs_zap_caches_locked(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) trace_nfs_set_inode_stale(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) void nfs_set_inode_stale(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) nfs_set_inode_stale_locked(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) struct nfs_find_desc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct nfs_fh *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct nfs_fattr *fattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * In NFSv3 we can have 64bit inode numbers. In order to support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * this, and re-exported directories (also seen in NFSv2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * we are forced to allow 2 different inodes to have the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * i_ino.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) nfs_find_actor(struct inode *inode, void *opaque)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) struct nfs_find_desc *desc = (struct nfs_find_desc *)opaque;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct nfs_fh *fh = desc->fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) struct nfs_fattr *fattr = desc->fattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) if (NFS_FILEID(inode) != fattr->fileid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (inode_wrong_type(inode, fattr->mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (nfs_compare_fh(NFS_FH(inode), fh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (is_bad_inode(inode) || NFS_STALE(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) nfs_init_locked(struct inode *inode, void *opaque)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct nfs_find_desc *desc = (struct nfs_find_desc *)opaque;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) struct nfs_fattr *fattr = desc->fattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) set_nfs_fileid(inode, fattr->fileid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) inode->i_mode = fattr->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) nfs_copy_fh(NFS_FH(inode), desc->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) #ifdef CONFIG_NFS_V4_SECURITY_LABEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static void nfs_clear_label_invalid(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_LABEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct nfs4_label *label)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (label == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if ((fattr->valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL) && inode->i_security) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) error = security_inode_notifysecctx(inode, label->label,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) label->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) printk(KERN_ERR "%s() %s %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) "security_inode_notifysecctx() %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) (char *)label->label,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) label->len, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) nfs_clear_label_invalid(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) struct nfs4_label *label = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) int minor_version = server->nfs_client->cl_minorversion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (minor_version < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (!(server->caps & NFS_CAP_SECURITY_LABEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) return label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) label = kzalloc(sizeof(struct nfs4_label), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (label == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) label->label = kzalloc(NFS4_MAXLABELLEN, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (label->label == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) kfree(label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) label->len = NFS4_MAXLABELLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) return label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) EXPORT_SYMBOL_GPL(nfs4_label_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) struct nfs4_label *label)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) EXPORT_SYMBOL_GPL(nfs_setsecurity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) /* Search for inode identified by fh, fileid and i_mode in inode cache. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct inode *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) nfs_ilookup(struct super_block *sb, struct nfs_fattr *fattr, struct nfs_fh *fh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) struct nfs_find_desc desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) .fh = fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) .fattr = fattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) unsigned long hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (!(fattr->valid & NFS_ATTR_FATTR_FILEID) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) !(fattr->valid & NFS_ATTR_FATTR_TYPE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) hash = nfs_fattr_to_ino_t(fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) inode = ilookup5(sb, hash, nfs_find_actor, &desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) dprintk("%s: returning %p\n", __func__, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) * This is our front-end to iget that looks up inodes by file handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * instead of inode number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) struct inode *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, struct nfs4_label *label)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) struct nfs_find_desc desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) .fh = fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) .fattr = fattr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) struct inode *inode = ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) unsigned long hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) nfs_attr_check_mountpoint(sb, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (nfs_attr_use_mounted_on_fileid(fattr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) fattr->fileid = fattr->mounted_on_fileid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) else if ((fattr->valid & NFS_ATTR_FATTR_FILEID) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) goto out_no_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if ((fattr->valid & NFS_ATTR_FATTR_TYPE) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) goto out_no_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) hash = nfs_fattr_to_ino_t(fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) inode = iget5_locked(sb, hash, nfs_find_actor, nfs_init_locked, &desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (inode == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) inode = ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) goto out_no_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) if (inode->i_state & I_NEW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) unsigned long now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) /* We set i_ino for the few things that still rely on it,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) * such as stat(2) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) inode->i_ino = hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) /* We can't support update_atime(), since the server will reset it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) inode->i_flags |= S_NOATIME|S_NOCMTIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) inode->i_mode = fattr->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) nfsi->cache_validity = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if ((fattr->valid & NFS_ATTR_FATTR_MODE) == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) && nfs_server_capable(inode, NFS_CAP_MODE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) /* Why so? Because we want revalidate for devices/FIFOs, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) * that's precisely what we have in nfs_file_inode_operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->file_inode_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (S_ISREG(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) inode->i_fop = NFS_SB(sb)->nfs_client->rpc_ops->file_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) inode->i_data.a_ops = &nfs_file_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) } else if (S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->dir_inode_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) inode->i_fop = &nfs_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) inode->i_data.a_ops = &nfs_dir_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) /* Deal with crossing mountpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) inode->i_op = &nfs_referral_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) inode->i_op = &nfs_mountpoint_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) inode->i_fop = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) inode->i_flags |= S_AUTOMOUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) } else if (S_ISLNK(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) inode->i_op = &nfs_symlink_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) inode_nohighmem(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) init_special_inode(inode, inode->i_mode, fattr->rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) memset(&inode->i_atime, 0, sizeof(inode->i_atime));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) memset(&inode->i_mtime, 0, sizeof(inode->i_mtime));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) memset(&inode->i_ctime, 0, sizeof(inode->i_ctime));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) inode_set_iversion_raw(inode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) inode->i_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) clear_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) inode->i_uid = make_kuid(&init_user_ns, -2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) inode->i_gid = make_kgid(&init_user_ns, -2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) inode->i_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) nfsi->write_io = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) nfsi->read_io = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) nfsi->read_cache_jiffies = fattr->time_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) nfsi->attr_gencount = fattr->gencount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (fattr->valid & NFS_ATTR_FATTR_ATIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) inode->i_atime = fattr->atime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) else if (nfs_server_capable(inode, NFS_CAP_ATIME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (fattr->valid & NFS_ATTR_FATTR_MTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) inode->i_mtime = fattr->mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) else if (nfs_server_capable(inode, NFS_CAP_MTIME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) nfs_set_cache_invalid(inode, NFS_INO_INVALID_MTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (fattr->valid & NFS_ATTR_FATTR_CTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) inode->i_ctime = fattr->ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) else if (nfs_server_capable(inode, NFS_CAP_CTIME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) nfs_set_cache_invalid(inode, NFS_INO_INVALID_CTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) if (fattr->valid & NFS_ATTR_FATTR_CHANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) inode_set_iversion_raw(inode, fattr->change_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) if (fattr->valid & NFS_ATTR_FATTR_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) inode->i_size = nfs_size_to_loff_t(fattr->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) nfs_set_cache_invalid(inode, NFS_INO_INVALID_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) if (fattr->valid & NFS_ATTR_FATTR_NLINK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) set_nlink(inode, fattr->nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) else if (nfs_server_capable(inode, NFS_CAP_NLINK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if (fattr->valid & NFS_ATTR_FATTR_OWNER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) inode->i_uid = fattr->uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) else if (nfs_server_capable(inode, NFS_CAP_OWNER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) if (fattr->valid & NFS_ATTR_FATTR_GROUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) inode->i_gid = fattr->gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (nfs_server_capable(inode, NFS_CAP_XATTR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) nfs_set_cache_invalid(inode, NFS_INO_INVALID_XATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) inode->i_blocks = fattr->du.nfs2.blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) * report the blocks in 512byte units
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (nfsi->cache_validity != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) nfsi->cache_validity |= NFS_INO_REVAL_FORCED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) nfs_setsecurity(inode, fattr, label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) nfsi->attrtimeo_timestamp = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) nfsi->access_cache = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) nfs_fscache_init_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) int err = nfs_refresh_inode(inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) inode = ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) goto out_no_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) dprintk("NFS: nfs_fhget(%s/%Lu fh_crc=0x%08x ct=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) inode->i_sb->s_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) (unsigned long long)NFS_FILEID(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) nfs_display_fhandle_hash(fh),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) atomic_read(&inode->i_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) out_no_inode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) dprintk("nfs_fhget: iget failed with error %ld\n", PTR_ERR(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) EXPORT_SYMBOL_GPL(nfs_fhget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) #define NFS_VALID_ATTRS (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_ATIME|ATTR_ATIME_SET|ATTR_MTIME|ATTR_MTIME_SET|ATTR_FILE|ATTR_OPEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) nfs_setattr(struct dentry *dentry, struct iattr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) struct nfs_fattr *fattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) nfs_inc_stats(inode, NFSIOS_VFSSETATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) /* skip mode change if it's just for clearing setuid/setgid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if (attr->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) attr->ia_valid &= ~ATTR_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) if (attr->ia_valid & ATTR_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) BUG_ON(!S_ISREG(inode->i_mode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) error = inode_newsize_ok(inode, attr->ia_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (attr->ia_size == i_size_read(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) attr->ia_valid &= ~ATTR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) /* Optimization: if the end result is no change, don't RPC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) attr->ia_valid &= NFS_VALID_ATTRS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if ((attr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) trace_nfs_setattr_enter(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) /* Write all dirty data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (S_ISREG(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) nfs_sync_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) fattr = nfs_alloc_fattr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) if (fattr == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) error = NFS_PROTO(inode)->setattr(dentry, fattr, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) if (error == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) error = nfs_refresh_inode(inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) nfs_free_fattr(fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) trace_nfs_setattr_exit(inode, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) EXPORT_SYMBOL_GPL(nfs_setattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * nfs_vmtruncate - unmap mappings "freed" by truncate() syscall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) * @inode: inode of the file used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * @offset: file offset to start truncating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) * This is a copy of the common vmtruncate, but with the locking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) * corrected to take into account the fact that NFS requires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) * inode->i_size to be updated under the inode->i_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) * Note: must be called with inode->i_lock held!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) static int nfs_vmtruncate(struct inode * inode, loff_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) err = inode_newsize_ok(inode, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) i_size_write(inode, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) /* Optimisation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) if (offset == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_DATA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) NFS_INO_DATA_INVAL_DEFER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) truncate_pagecache(inode, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) * nfs_setattr_update_inode - Update inode metadata after a setattr call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) * @inode: pointer to struct inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) * @attr: pointer to struct iattr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) * @fattr: pointer to struct nfs_fattr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) * Note: we do this in the *proc.c in order to ensure that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) * it works for things like exclusive creates too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) struct nfs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) /* Barrier: bump the attribute generation count. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) nfs_fattr_set_barrier(fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) NFS_I(inode)->attr_gencount = fattr->gencount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) if ((attr->ia_valid & ATTR_SIZE) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) nfs_set_cache_invalid(inode, NFS_INO_INVALID_MTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) nfs_inc_stats(inode, NFSIOS_SETATTRTRUNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) nfs_vmtruncate(inode, attr->ia_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_CTIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if ((attr->ia_valid & ATTR_MODE) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) int mode = attr->ia_mode & S_IALLUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) mode |= inode->i_mode & ~S_IALLUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) inode->i_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if ((attr->ia_valid & ATTR_UID) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) inode->i_uid = attr->ia_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) if ((attr->ia_valid & ATTR_GID) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) inode->i_gid = attr->ia_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) if (fattr->valid & NFS_ATTR_FATTR_CTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) inode->i_ctime = fattr->ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) | NFS_INO_INVALID_CTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) nfs_set_cache_invalid(inode, NFS_INO_INVALID_ACCESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) | NFS_INO_INVALID_ACL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (attr->ia_valid & (ATTR_ATIME_SET|ATTR_ATIME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_ATIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) | NFS_INO_INVALID_CTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) if (fattr->valid & NFS_ATTR_FATTR_ATIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) inode->i_atime = fattr->atime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) else if (attr->ia_valid & ATTR_ATIME_SET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) inode->i_atime = attr->ia_atime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) if (fattr->valid & NFS_ATTR_FATTR_CTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) inode->i_ctime = fattr->ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) | NFS_INO_INVALID_CTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) if (attr->ia_valid & (ATTR_MTIME_SET|ATTR_MTIME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) NFS_I(inode)->cache_validity &= ~(NFS_INO_INVALID_MTIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) | NFS_INO_INVALID_CTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) if (fattr->valid & NFS_ATTR_FATTR_MTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) inode->i_mtime = fattr->mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) else if (attr->ia_valid & ATTR_MTIME_SET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) inode->i_mtime = attr->ia_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) nfs_set_cache_invalid(inode, NFS_INO_INVALID_MTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) if (fattr->valid & NFS_ATTR_FATTR_CTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) inode->i_ctime = fattr->ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) | NFS_INO_INVALID_CTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) if (fattr->valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) nfs_update_inode(inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) EXPORT_SYMBOL_GPL(nfs_setattr_update_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) static void nfs_readdirplus_parent_cache_miss(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) struct dentry *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) if (!nfs_server_capable(d_inode(dentry), NFS_CAP_READDIRPLUS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) parent = dget_parent(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) nfs_force_use_readdirplus(d_inode(parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) dput(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) static void nfs_readdirplus_parent_cache_hit(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) struct dentry *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) if (!nfs_server_capable(d_inode(dentry), NFS_CAP_READDIRPLUS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) parent = dget_parent(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) nfs_advise_use_readdirplus(d_inode(parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) dput(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) static bool nfs_need_revalidate_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) if (NFS_I(inode)->cache_validity &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_LABEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) if (nfs_attribute_cache_expired(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) int nfs_getattr(const struct path *path, struct kstat *stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) u32 request_mask, unsigned int query_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) struct inode *inode = d_inode(path->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) struct nfs_server *server = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) unsigned long cache_validity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) bool force_sync = query_flags & AT_STATX_FORCE_SYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) bool do_update = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) trace_nfs_getattr_enter(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) if ((query_flags & AT_STATX_DONT_SYNC) && !force_sync) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) nfs_readdirplus_parent_cache_hit(path->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) goto out_no_update;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) /* Flush out writes to the server in order to update c/mtime. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) if ((request_mask & (STATX_CTIME | STATX_MTIME)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) S_ISREG(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) filemap_write_and_wait(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) * We may force a getattr if the user cares about atime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) * Note that we only have to check the vfsmount flags here:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) * - NFS always sets S_NOATIME by so checking it would give a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) * bogus result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) * - NFS never sets SB_NOATIME or SB_NODIRATIME so there is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) * no point in checking those.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if ((path->mnt->mnt_flags & MNT_NOATIME) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) ((path->mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) request_mask &= ~STATX_ATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) /* Is the user requesting attributes that might need revalidation? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) if (!(request_mask & (STATX_MODE|STATX_NLINK|STATX_ATIME|STATX_CTIME|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) STATX_MTIME|STATX_UID|STATX_GID|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) STATX_SIZE|STATX_BLOCKS)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) goto out_no_revalidate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) /* Check whether the cached attributes are stale */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) do_update |= force_sync || nfs_attribute_cache_expired(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) cache_validity = READ_ONCE(NFS_I(inode)->cache_validity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) do_update |= cache_validity &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_LABEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) if (request_mask & STATX_ATIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) do_update |= cache_validity & NFS_INO_INVALID_ATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) if (request_mask & (STATX_CTIME|STATX_MTIME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) do_update |= cache_validity & NFS_INO_REVAL_PAGECACHE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) if (request_mask & STATX_BLOCKS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) do_update |= cache_validity & NFS_INO_INVALID_BLOCKS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (do_update) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) /* Update the attribute cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if (!(server->flags & NFS_MOUNT_NOAC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) nfs_readdirplus_parent_cache_miss(path->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) nfs_readdirplus_parent_cache_hit(path->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) err = __nfs_revalidate_inode(server, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) nfs_readdirplus_parent_cache_hit(path->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) out_no_revalidate:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) /* Only return attributes that were revalidated. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) stat->result_mask &= request_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) out_no_update:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) generic_fillattr(inode, stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) stat->blksize = NFS_SERVER(inode)->dtsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) trace_nfs_getattr_exit(inode, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) EXPORT_SYMBOL_GPL(nfs_getattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) static void nfs_init_lock_context(struct nfs_lock_context *l_ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) refcount_set(&l_ctx->count, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) l_ctx->lockowner = current->files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) INIT_LIST_HEAD(&l_ctx->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) atomic_set(&l_ctx->io_count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) static struct nfs_lock_context *__nfs_find_lock_context(struct nfs_open_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) struct nfs_lock_context *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) list_for_each_entry_rcu(pos, &ctx->lock_context.list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) if (pos->lockowner != current->files)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) if (refcount_inc_not_zero(&pos->count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) struct nfs_lock_context *res, *new = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) struct inode *inode = d_inode(ctx->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) res = __nfs_find_lock_context(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) if (res == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) new = kmalloc(sizeof(*new), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) if (new == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) nfs_init_lock_context(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) res = __nfs_find_lock_context(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) if (res == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) new->open_context = get_nfs_open_context(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) if (new->open_context) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) list_add_tail_rcu(&new->list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) &ctx->lock_context.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) res = new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) new = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) res = ERR_PTR(-EBADF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) kfree(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) EXPORT_SYMBOL_GPL(nfs_get_lock_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) void nfs_put_lock_context(struct nfs_lock_context *l_ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) struct nfs_open_context *ctx = l_ctx->open_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) struct inode *inode = d_inode(ctx->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) if (!refcount_dec_and_lock(&l_ctx->count, &inode->i_lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) list_del_rcu(&l_ctx->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) put_nfs_open_context(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) kfree_rcu(l_ctx, rcu_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) EXPORT_SYMBOL_GPL(nfs_put_lock_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) * nfs_close_context - Common close_context() routine NFSv2/v3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) * @ctx: pointer to context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) * @is_sync: is this a synchronous close
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) * Ensure that the attributes are up to date if we're mounted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) * with close-to-open semantics and we have cached data that will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) * need to be revalidated on open.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) void nfs_close_context(struct nfs_open_context *ctx, int is_sync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) struct nfs_inode *nfsi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) struct nfs_server *server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) if (!(ctx->mode & FMODE_WRITE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) if (!is_sync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) inode = d_inode(ctx->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) if (inode->i_mapping->nrpages == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) if (!list_empty(&nfsi->open_files))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) server = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) if (server->flags & NFS_MOUNT_NOCTO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) nfs_revalidate_inode(server, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) EXPORT_SYMBOL_GPL(nfs_close_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) fmode_t f_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) struct nfs_open_context *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) if (!ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) nfs_sb_active(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) ctx->dentry = dget(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) if (filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) ctx->cred = get_cred(filp->f_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) ctx->cred = get_current_cred();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) ctx->ll_cred = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) ctx->state = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) ctx->mode = f_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) ctx->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) ctx->error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) ctx->flock_owner = (fl_owner_t)filp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) nfs_init_lock_context(&ctx->lock_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) ctx->lock_context.open_context = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) INIT_LIST_HEAD(&ctx->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) ctx->mdsthreshold = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) return ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) EXPORT_SYMBOL_GPL(alloc_nfs_open_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) if (ctx != NULL && refcount_inc_not_zero(&ctx->lock_context.count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) return ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) EXPORT_SYMBOL_GPL(get_nfs_open_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) static void __put_nfs_open_context(struct nfs_open_context *ctx, int is_sync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) struct inode *inode = d_inode(ctx->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) struct super_block *sb = ctx->dentry->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) if (!refcount_dec_and_test(&ctx->lock_context.count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) if (!list_empty(&ctx->list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) list_del_rcu(&ctx->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) if (inode != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) NFS_PROTO(inode)->close_context(ctx, is_sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) put_cred(ctx->cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) dput(ctx->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) nfs_sb_deactive(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) put_rpccred(ctx->ll_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) kfree(ctx->mdsthreshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) kfree_rcu(ctx, rcu_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) void put_nfs_open_context(struct nfs_open_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) __put_nfs_open_context(ctx, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) EXPORT_SYMBOL_GPL(put_nfs_open_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) static void put_nfs_open_context_sync(struct nfs_open_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) __put_nfs_open_context(ctx, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) * Ensure that mmap has a recent RPC credential for use when writing out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) * shared pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) void nfs_inode_attach_open_context(struct nfs_open_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) struct inode *inode = d_inode(ctx->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) if (list_empty(&nfsi->open_files) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) (nfsi->cache_validity & NFS_INO_DATA_INVAL_DEFER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) nfsi->cache_validity |= NFS_INO_INVALID_DATA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) NFS_INO_REVAL_FORCED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) list_add_tail_rcu(&ctx->list, &nfsi->open_files);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) EXPORT_SYMBOL_GPL(nfs_inode_attach_open_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) filp->private_data = get_nfs_open_context(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) set_bit(NFS_CONTEXT_FILE_OPEN, &ctx->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) if (list_empty(&ctx->list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) nfs_inode_attach_open_context(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) EXPORT_SYMBOL_GPL(nfs_file_set_open_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) * Given an inode, search for an open context with the desired characteristics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) struct nfs_open_context *nfs_find_open_context(struct inode *inode, const struct cred *cred, fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) struct nfs_open_context *pos, *ctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) list_for_each_entry_rcu(pos, &nfsi->open_files, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) if (cred != NULL && cred_fscmp(pos->cred, cred) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) if ((pos->mode & (FMODE_READ|FMODE_WRITE)) != mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) if (!test_bit(NFS_CONTEXT_FILE_OPEN, &pos->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) ctx = get_nfs_open_context(pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) if (ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) return ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) void nfs_file_clear_open_context(struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) struct nfs_open_context *ctx = nfs_file_open_context(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) if (ctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) struct inode *inode = d_inode(ctx->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) clear_bit(NFS_CONTEXT_FILE_OPEN, &ctx->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) * We fatal error on write before. Try to writeback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) * every page again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) if (ctx->error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) invalidate_inode_pages2(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) filp->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) put_nfs_open_context_sync(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) * These allocate and release file read/write context information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) int nfs_open(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) struct nfs_open_context *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) if (IS_ERR(ctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) return PTR_ERR(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) nfs_file_set_open_context(filp, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) put_nfs_open_context(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) nfs_fscache_open_file(inode, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) EXPORT_SYMBOL_GPL(nfs_open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) * This function is called whenever some part of NFS notices that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) * the cached attributes have to be refreshed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) int status = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) struct nfs4_label *label = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) struct nfs_fattr *fattr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) dfprintk(PAGECACHE, "NFS: revalidating (%s/%Lu)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) inode->i_sb->s_id, (unsigned long long)NFS_FILEID(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) trace_nfs_revalidate_inode_enter(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) if (is_bad_inode(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) if (NFS_STALE(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) /* pNFS: Attributes aren't updated until we layoutcommit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) if (S_ISREG(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) status = pnfs_sync_inode(inode, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) fattr = nfs_alloc_fattr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) if (fattr == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) if (IS_ERR(label)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) status = PTR_ERR(label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) status = NFS_PROTO(inode)->getattr(server, NFS_FH(inode), fattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) label, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) if (status != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Lu) getattr failed, error=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) inode->i_sb->s_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) (unsigned long long)NFS_FILEID(inode), status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) case -ETIMEDOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) /* A soft timeout occurred. Use cached information? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) if (server->flags & NFS_MOUNT_SOFTREVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) case -ESTALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) if (!S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) nfs_set_inode_stale(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) nfs_zap_caches(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) status = nfs_refresh_inode(inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Lu) refresh failed, error=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) inode->i_sb->s_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) (unsigned long long)NFS_FILEID(inode), status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) if (nfsi->cache_validity & NFS_INO_INVALID_ACL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) nfs_zap_acl_cache(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) nfs_setsecurity(inode, fattr, label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) dfprintk(PAGECACHE, "NFS: (%s/%Lu) revalidation complete\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) inode->i_sb->s_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) (unsigned long long)NFS_FILEID(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) nfs4_label_free(label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) nfs_free_fattr(fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) trace_nfs_revalidate_inode_exit(inode, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) int nfs_attribute_cache_expired(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) if (nfs_have_delegated_attributes(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) return nfs_attribute_timeout(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) * nfs_revalidate_inode - Revalidate the inode attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) * @server: pointer to nfs_server struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) * @inode: pointer to inode struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) * Updates inode attribute information by retrieving the data from the server.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) if (!nfs_need_revalidate_inode(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) return NFS_STALE(inode) ? -ESTALE : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) return __nfs_revalidate_inode(server, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) EXPORT_SYMBOL_GPL(nfs_revalidate_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) static int nfs_invalidate_mapping(struct inode *inode, struct address_space *mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) if (mapping->nrpages != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) if (S_ISREG(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) ret = nfs_sync_mapping(mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) ret = invalidate_inode_pages2(mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) if (S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) nfs_fscache_wait_on_invalidate(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) dfprintk(PAGECACHE, "NFS: (%s/%Lu) data cache invalidated\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) inode->i_sb->s_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) (unsigned long long)NFS_FILEID(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) bool nfs_mapping_need_revalidate_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) return nfs_check_cache_invalid(inode, NFS_INO_REVAL_PAGECACHE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) NFS_STALE(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) int nfs_revalidate_mapping_rcu(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) unsigned long *bitlock = &nfsi->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) if (IS_SWAPFILE(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) if (nfs_mapping_need_revalidate_inode(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) ret = -ECHILD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) if (test_bit(NFS_INO_INVALIDATING, bitlock) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) (nfsi->cache_validity & NFS_INO_INVALID_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) ret = -ECHILD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) * nfs_revalidate_mapping - Revalidate the pagecache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) * @inode: pointer to host inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) * @mapping: pointer to mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) int nfs_revalidate_mapping(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) struct address_space *mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) unsigned long *bitlock = &nfsi->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) /* swapfiles are not supposed to be shared. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) if (IS_SWAPFILE(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) if (nfs_mapping_need_revalidate_inode(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) * We must clear NFS_INO_INVALID_DATA first to ensure that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) * invalidations that come in while we're shooting down the mappings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) * are respected. But, that leaves a race window where one revalidator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) * can clear the flag, and then another checks it before the mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) * gets invalidated. Fix that by serializing access to this part of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) * the function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) * At the same time, we need to allow other tasks to see whether we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) * might be in the middle of invalidating the pages, so we only set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) * the bit lock here if it looks like we're going to be doing that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) ret = wait_on_bit_action(bitlock, NFS_INO_INVALIDATING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) nfs_wait_bit_killable, TASK_KILLABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) if (test_bit(NFS_INO_INVALIDATING, bitlock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) set_bit(NFS_INO_INVALIDATING, bitlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) nfsi->cache_validity &= ~(NFS_INO_INVALID_DATA|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) NFS_INO_DATA_INVAL_DEFER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) trace_nfs_invalidate_mapping_enter(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) ret = nfs_invalidate_mapping(inode, mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) trace_nfs_invalidate_mapping_exit(inode, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) clear_bit_unlock(NFS_INO_INVALIDATING, bitlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) smp_mb__after_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) wake_up_bit(bitlock, NFS_INO_INVALIDATING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) static bool nfs_file_has_writers(struct nfs_inode *nfsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) struct inode *inode = &nfsi->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) if (!S_ISREG(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) if (list_empty(&nfsi->open_files))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) return inode_is_open_for_write(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) static bool nfs_file_has_buffered_writers(struct nfs_inode *nfsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) return nfs_file_has_writers(nfsi) && nfs_file_io_is_buffered(nfsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) struct timespec64 ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) if ((fattr->valid & NFS_ATTR_FATTR_PRECHANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) && (fattr->valid & NFS_ATTR_FATTR_CHANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) && inode_eq_iversion_raw(inode, fattr->pre_change_attr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) inode_set_iversion_raw(inode, fattr->change_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) else if (nfs_server_capable(inode, NFS_CAP_XATTR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) nfs_set_cache_invalid(inode, NFS_INO_INVALID_XATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) /* If we have atomic WCC data, we may update some attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) ts = inode->i_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) if ((fattr->valid & NFS_ATTR_FATTR_PRECTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) && (fattr->valid & NFS_ATTR_FATTR_CTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) && timespec64_equal(&ts, &fattr->pre_ctime)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) inode->i_ctime = fattr->ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) ts = inode->i_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) if ((fattr->valid & NFS_ATTR_FATTR_PREMTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) && (fattr->valid & NFS_ATTR_FATTR_MTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) && timespec64_equal(&ts, &fattr->pre_mtime)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) inode->i_mtime = fattr->mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) if ((fattr->valid & NFS_ATTR_FATTR_PRESIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) && (fattr->valid & NFS_ATTR_FATTR_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) && i_size_read(inode) == nfs_size_to_loff_t(fattr->pre_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) && !nfs_have_writebacks(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) i_size_write(inode, nfs_size_to_loff_t(fattr->size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) * nfs_check_inode_attributes - verify consistency of the inode attribute cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) * @inode: pointer to inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) * @fattr: updated attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) * Verifies the attribute cache. If we have just changed the attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) * so that fattr carries weak cache consistency data, then it may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) * also update the ctime/mtime/change_attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) loff_t cur_size, new_isize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) unsigned long invalid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) struct timespec64 ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) if (!(fattr->valid & NFS_ATTR_FATTR_FILEID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) /* Only a mounted-on-fileid? Just exit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) if (fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) /* Has the inode gone and changed behind our back? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) } else if (nfsi->fileid != fattr->fileid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) /* Is this perhaps the mounted-on fileid? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) if ((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) nfsi->fileid == fattr->mounted_on_fileid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) return -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && inode_wrong_type(inode, fattr->mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) return -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) if (!nfs_file_has_buffered_writers(nfsi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) /* Verify a few of the more important attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) != 0 && !inode_eq_iversion_raw(inode, fattr->change_attr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) invalid |= NFS_INO_INVALID_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) | NFS_INO_REVAL_PAGECACHE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) ts = inode->i_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) if ((fattr->valid & NFS_ATTR_FATTR_MTIME) && !timespec64_equal(&ts, &fattr->mtime))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) invalid |= NFS_INO_INVALID_MTIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) ts = inode->i_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) if ((fattr->valid & NFS_ATTR_FATTR_CTIME) && !timespec64_equal(&ts, &fattr->ctime))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) invalid |= NFS_INO_INVALID_CTIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) if (fattr->valid & NFS_ATTR_FATTR_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) cur_size = i_size_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) new_isize = nfs_size_to_loff_t(fattr->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) if (cur_size != new_isize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) invalid |= NFS_INO_INVALID_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) | NFS_INO_REVAL_PAGECACHE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) /* Have any file permissions changed? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) invalid |= NFS_INO_INVALID_ACCESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) | NFS_INO_INVALID_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) | NFS_INO_INVALID_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) invalid |= NFS_INO_INVALID_ACCESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) | NFS_INO_INVALID_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) | NFS_INO_INVALID_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) invalid |= NFS_INO_INVALID_ACCESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) | NFS_INO_INVALID_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) | NFS_INO_INVALID_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) /* Has the link count changed? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) invalid |= NFS_INO_INVALID_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) ts = inode->i_atime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) if ((fattr->valid & NFS_ATTR_FATTR_ATIME) && !timespec64_equal(&ts, &fattr->atime))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) invalid |= NFS_INO_INVALID_ATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) if (invalid != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) nfs_set_cache_invalid(inode, invalid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) nfsi->read_cache_jiffies = fattr->time_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) static atomic_long_t nfs_attr_generation_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) static unsigned long nfs_read_attr_generation_counter(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) return atomic_long_read(&nfs_attr_generation_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) unsigned long nfs_inc_attr_generation_counter(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) return atomic_long_inc_return(&nfs_attr_generation_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) EXPORT_SYMBOL_GPL(nfs_inc_attr_generation_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) void nfs_fattr_init(struct nfs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) fattr->valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) fattr->time_start = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) fattr->gencount = nfs_inc_attr_generation_counter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) fattr->owner_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) fattr->group_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) EXPORT_SYMBOL_GPL(nfs_fattr_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) * nfs_fattr_set_barrier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) * @fattr: attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) * Used to set a barrier after an attribute was updated. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) * barrier ensures that older attributes from RPC calls that may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) * have raced with our update cannot clobber these new values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) * Note that you are still responsible for ensuring that other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) * operations which change the attribute on the server do not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) * collide.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) void nfs_fattr_set_barrier(struct nfs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) fattr->gencount = nfs_inc_attr_generation_counter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) struct nfs_fattr *nfs_alloc_fattr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) struct nfs_fattr *fattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) fattr = kmalloc(sizeof(*fattr), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) if (fattr != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) nfs_fattr_init(fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) return fattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) EXPORT_SYMBOL_GPL(nfs_alloc_fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) struct nfs_fh *nfs_alloc_fhandle(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) struct nfs_fh *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) fh = kmalloc(sizeof(struct nfs_fh), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) if (fh != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) fh->size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) return fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) EXPORT_SYMBOL_GPL(nfs_alloc_fhandle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) #ifdef NFS_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) * _nfs_display_fhandle_hash - calculate the crc32 hash for the filehandle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) * in the same way that wireshark does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) * @fh: file handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) * For debugging only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) u32 _nfs_display_fhandle_hash(const struct nfs_fh *fh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) /* wireshark uses 32-bit AUTODIN crc and does a bitwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) * not on the result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) return nfs_fhandle_hash(fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) EXPORT_SYMBOL_GPL(_nfs_display_fhandle_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) * _nfs_display_fhandle - display an NFS file handle on the console
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) * @fh: file handle to display
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) * @caption: display caption
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) * For debugging only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) void _nfs_display_fhandle(const struct nfs_fh *fh, const char *caption)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) unsigned short i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) if (fh == NULL || fh->size == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) printk(KERN_DEFAULT "%s at %p is empty\n", caption, fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) printk(KERN_DEFAULT "%s at %p is %u bytes, crc: 0x%08x:\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) caption, fh, fh->size, _nfs_display_fhandle_hash(fh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) for (i = 0; i < fh->size; i += 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) __be32 *pos = (__be32 *)&fh->data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) switch ((fh->size - i - 1) >> 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) printk(KERN_DEFAULT " %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) be32_to_cpup(pos));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) printk(KERN_DEFAULT " %08x %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) be32_to_cpup(pos), be32_to_cpup(pos + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) printk(KERN_DEFAULT " %08x %08x %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) be32_to_cpup(pos), be32_to_cpup(pos + 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) be32_to_cpup(pos + 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) printk(KERN_DEFAULT " %08x %08x %08x %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) be32_to_cpup(pos), be32_to_cpup(pos + 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) be32_to_cpup(pos + 2), be32_to_cpup(pos + 3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) EXPORT_SYMBOL_GPL(_nfs_display_fhandle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) * nfs_inode_attrs_need_update - check if the inode attributes need updating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) * @inode: pointer to inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) * @fattr: attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) * Attempt to divine whether or not an RPC call reply carrying stale
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) * attributes got scheduled after another call carrying updated ones.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) * To do so, the function first assumes that a more recent ctime means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) * that the attributes in fattr are newer, however it also attempt to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) * catch the case where ctime either didn't change, or went backwards
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) * (if someone reset the clock on the server) by looking at whether
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) * or not this RPC call was started after the inode was last updated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) * Note also the check for wraparound of 'attr_gencount'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) * The function returns 'true' if it thinks the attributes in 'fattr' are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) * more recent than the ones cached in the inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) static int nfs_inode_attrs_need_update(const struct inode *inode, const struct nfs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) unsigned long attr_gencount = NFS_I(inode)->attr_gencount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) return (long)(fattr->gencount - attr_gencount) > 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) (long)(attr_gencount - nfs_read_attr_generation_counter()) > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) static int nfs_refresh_inode_locked(struct inode *inode, struct nfs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) trace_nfs_refresh_inode_enter(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) if (nfs_inode_attrs_need_update(inode, fattr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) ret = nfs_update_inode(inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) ret = nfs_check_inode_attributes(inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) trace_nfs_refresh_inode_exit(inode, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) * nfs_refresh_inode - try to update the inode attribute cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) * @inode: pointer to inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) * @fattr: updated attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) * Check that an RPC call that returned attributes has not overlapped with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) * other recent updates of the inode metadata, then decide whether it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) * safe to do a full update of the inode attributes, or whether just to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) * call nfs_check_inode_attributes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) if ((fattr->valid & NFS_ATTR_FATTR) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) status = nfs_refresh_inode_locked(inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) EXPORT_SYMBOL_GPL(nfs_refresh_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) static int nfs_post_op_update_inode_locked(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) struct nfs_fattr *fattr, unsigned int invalid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) invalid |= NFS_INO_INVALID_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) nfs_set_cache_invalid(inode, invalid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) if ((fattr->valid & NFS_ATTR_FATTR) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) return nfs_refresh_inode_locked(inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) * nfs_post_op_update_inode - try to update the inode attribute cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) * @inode: pointer to inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) * @fattr: updated attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) * After an operation that has changed the inode metadata, mark the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) * attribute cache as being invalid, then try to update it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) * NB: if the server didn't return any post op attributes, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) * function will force the retrieval of attributes before the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) * NFS request. Thus it should be used only for operations that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) * are expected to change one or more attributes, to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) * unnecessary NFS requests and trips through nfs_update_inode().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) nfs_fattr_set_barrier(fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) status = nfs_post_op_update_inode_locked(inode, fattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) NFS_INO_INVALID_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) | NFS_INO_INVALID_CTIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) | NFS_INO_REVAL_FORCED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) EXPORT_SYMBOL_GPL(nfs_post_op_update_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) * nfs_post_op_update_inode_force_wcc_locked - update the inode attribute cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) * @inode: pointer to inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) * @fattr: updated attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) * After an operation that has changed the inode metadata, mark the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) * attribute cache as being invalid, then try to update it. Fake up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) * weak cache consistency data, if none exist.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) * This function is mainly designed to be used by the ->write_done() functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) int nfs_post_op_update_inode_force_wcc_locked(struct inode *inode, struct nfs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) /* Don't do a WCC update if these attributes are already stale */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) if ((fattr->valid & NFS_ATTR_FATTR) == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) !nfs_inode_attrs_need_update(inode, fattr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) fattr->valid &= ~(NFS_ATTR_FATTR_PRECHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) | NFS_ATTR_FATTR_PRESIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) | NFS_ATTR_FATTR_PREMTIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) | NFS_ATTR_FATTR_PRECTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) goto out_noforce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) (fattr->valid & NFS_ATTR_FATTR_PRECHANGE) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) fattr->pre_change_attr = inode_peek_iversion_raw(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) fattr->valid |= NFS_ATTR_FATTR_PRECHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) if ((fattr->valid & NFS_ATTR_FATTR_CTIME) != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) (fattr->valid & NFS_ATTR_FATTR_PRECTIME) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) fattr->pre_ctime = inode->i_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) fattr->valid |= NFS_ATTR_FATTR_PRECTIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) if ((fattr->valid & NFS_ATTR_FATTR_MTIME) != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) (fattr->valid & NFS_ATTR_FATTR_PREMTIME) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) fattr->pre_mtime = inode->i_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) fattr->valid |= NFS_ATTR_FATTR_PREMTIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) if ((fattr->valid & NFS_ATTR_FATTR_SIZE) != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) (fattr->valid & NFS_ATTR_FATTR_PRESIZE) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) fattr->pre_size = i_size_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) fattr->valid |= NFS_ATTR_FATTR_PRESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) out_noforce:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) status = nfs_post_op_update_inode_locked(inode, fattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) NFS_INO_INVALID_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) | NFS_INO_INVALID_CTIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) | NFS_INO_INVALID_MTIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) | NFS_INO_INVALID_BLOCKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) * nfs_post_op_update_inode_force_wcc - try to update the inode attribute cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) * @inode: pointer to inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) * @fattr: updated attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) * After an operation that has changed the inode metadata, mark the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) * attribute cache as being invalid, then try to update it. Fake up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) * weak cache consistency data, if none exist.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) * This function is mainly designed to be used by the ->write_done() functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) int nfs_post_op_update_inode_force_wcc(struct inode *inode, struct nfs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) nfs_fattr_set_barrier(fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) status = nfs_post_op_update_inode_force_wcc_locked(inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) EXPORT_SYMBOL_GPL(nfs_post_op_update_inode_force_wcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) * Many nfs protocol calls return the new file attributes after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) * an operation. Here we update the inode to reflect the state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) * of the server's inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) * This is a bit tricky because we have to make sure all dirty pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) * have been sent off to the server before calling invalidate_inode_pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) * To make sure no other process adds more write requests while we try
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) * our best to flush them, we make them sleep during the attribute refresh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) * A very similar scenario holds for the dir cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) struct nfs_server *server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) loff_t cur_isize, new_isize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) unsigned long invalid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) unsigned long now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) unsigned long save_cache_validity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) bool have_writers = nfs_file_has_buffered_writers(nfsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) bool cache_revalidated = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) bool attr_changed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) bool have_delegation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) dfprintk(VFS, "NFS: %s(%s/%lu fh_crc=0x%08x ct=%d info=0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) __func__, inode->i_sb->s_id, inode->i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) nfs_display_fhandle_hash(NFS_FH(inode)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) atomic_read(&inode->i_count), fattr->valid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) if (!(fattr->valid & NFS_ATTR_FATTR_FILEID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) /* Only a mounted-on-fileid? Just exit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) if (fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) /* Has the inode gone and changed behind our back? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) } else if (nfsi->fileid != fattr->fileid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) /* Is this perhaps the mounted-on fileid? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) if ((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) nfsi->fileid == fattr->mounted_on_fileid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) printk(KERN_ERR "NFS: server %s error: fileid changed\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) "fsid %s: expected fileid 0x%Lx, got 0x%Lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) NFS_SERVER(inode)->nfs_client->cl_hostname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) inode->i_sb->s_id, (long long)nfsi->fileid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) (long long)fattr->fileid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) * Make sure the inode's type hasn't changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && inode_wrong_type(inode, fattr->mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) * Big trouble! The inode has become a different object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) printk(KERN_DEBUG "NFS: %s: inode %lu mode changed, %07o to %07o\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) __func__, inode->i_ino, inode->i_mode, fattr->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) server = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) /* Update the fsid? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) if (S_ISDIR(inode->i_mode) && (fattr->valid & NFS_ATTR_FATTR_FSID) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) !nfs_fsid_equal(&server->fsid, &fattr->fsid) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) !IS_AUTOMOUNT(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) server->fsid = fattr->fsid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) /* Save the delegation state before clearing cache_validity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) have_delegation = nfs_have_delegated_attributes(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) * Update the read time so we don't revalidate too often.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) nfsi->read_cache_jiffies = fattr->time_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) save_cache_validity = nfsi->cache_validity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) | NFS_INO_INVALID_ATIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) | NFS_INO_REVAL_FORCED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) | NFS_INO_REVAL_PAGECACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) | NFS_INO_INVALID_BLOCKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) /* Do atomic weak cache consistency updates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) nfs_wcc_update_inode(inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) if (pnfs_layoutcommit_outstanding(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) nfsi->cache_validity |= save_cache_validity & NFS_INO_INVALID_ATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) cache_revalidated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) /* More cache consistency checks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) if (fattr->valid & NFS_ATTR_FATTR_CHANGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) if (!inode_eq_iversion_raw(inode, fattr->change_attr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) /* Could it be a race with writeback? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) if (!(have_writers || have_delegation)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) invalid |= NFS_INO_INVALID_DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) | NFS_INO_INVALID_ACCESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) | NFS_INO_INVALID_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) | NFS_INO_INVALID_XATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) /* Force revalidate of all attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) save_cache_validity |= NFS_INO_INVALID_CTIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) | NFS_INO_INVALID_MTIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) | NFS_INO_INVALID_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) | NFS_INO_INVALID_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) nfs_force_lookup_revalidate(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) dprintk("NFS: change_attr change on server for file %s/%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) inode->i_sb->s_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) } else if (!have_delegation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) nfsi->cache_validity |= NFS_INO_DATA_INVAL_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) inode_set_iversion_raw(inode, fattr->change_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) attr_changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) nfsi->cache_validity |= save_cache_validity &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) (NFS_INO_INVALID_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) | NFS_INO_REVAL_PAGECACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) | NFS_INO_REVAL_FORCED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) cache_revalidated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) if (fattr->valid & NFS_ATTR_FATTR_MTIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) inode->i_mtime = fattr->mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) } else if (server->caps & NFS_CAP_MTIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) nfsi->cache_validity |= save_cache_validity &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) (NFS_INO_INVALID_MTIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) | NFS_INO_REVAL_FORCED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) cache_revalidated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) if (fattr->valid & NFS_ATTR_FATTR_CTIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) inode->i_ctime = fattr->ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) } else if (server->caps & NFS_CAP_CTIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) nfsi->cache_validity |= save_cache_validity &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) (NFS_INO_INVALID_CTIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) | NFS_INO_REVAL_FORCED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) cache_revalidated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) /* Check if our cached file size is stale */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) if (fattr->valid & NFS_ATTR_FATTR_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) new_isize = nfs_size_to_loff_t(fattr->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) cur_isize = i_size_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) if (new_isize != cur_isize && !have_delegation) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) /* Do we perhaps have any outstanding writes, or has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) * the file grown beyond our last write? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) if (!nfs_have_writebacks(inode) || new_isize > cur_isize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) i_size_write(inode, new_isize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) if (!have_writers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) invalid |= NFS_INO_INVALID_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) attr_changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) dprintk("NFS: isize change on server for file %s/%ld "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) "(%Ld to %Ld)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) inode->i_sb->s_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) inode->i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) (long long)cur_isize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) (long long)new_isize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) nfsi->cache_validity |= save_cache_validity &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) (NFS_INO_INVALID_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) | NFS_INO_REVAL_PAGECACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) | NFS_INO_REVAL_FORCED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) cache_revalidated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) if (fattr->valid & NFS_ATTR_FATTR_ATIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) inode->i_atime = fattr->atime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) else if (server->caps & NFS_CAP_ATIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) nfsi->cache_validity |= save_cache_validity &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) (NFS_INO_INVALID_ATIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) | NFS_INO_REVAL_FORCED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) cache_revalidated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) if (fattr->valid & NFS_ATTR_FATTR_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) umode_t newmode = inode->i_mode & S_IFMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) newmode |= fattr->mode & S_IALLUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) inode->i_mode = newmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) invalid |= NFS_INO_INVALID_ACCESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) | NFS_INO_INVALID_ACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) attr_changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) } else if (server->caps & NFS_CAP_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) nfsi->cache_validity |= save_cache_validity &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) (NFS_INO_INVALID_OTHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) | NFS_INO_REVAL_FORCED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) cache_revalidated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) if (!uid_eq(inode->i_uid, fattr->uid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) invalid |= NFS_INO_INVALID_ACCESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) | NFS_INO_INVALID_ACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) inode->i_uid = fattr->uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) attr_changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) } else if (server->caps & NFS_CAP_OWNER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) nfsi->cache_validity |= save_cache_validity &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) (NFS_INO_INVALID_OTHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) | NFS_INO_REVAL_FORCED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) cache_revalidated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) if (!gid_eq(inode->i_gid, fattr->gid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) invalid |= NFS_INO_INVALID_ACCESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) | NFS_INO_INVALID_ACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) inode->i_gid = fattr->gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) attr_changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) } else if (server->caps & NFS_CAP_OWNER_GROUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) nfsi->cache_validity |= save_cache_validity &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) (NFS_INO_INVALID_OTHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) | NFS_INO_REVAL_FORCED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) cache_revalidated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) if (inode->i_nlink != fattr->nlink) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) invalid |= NFS_INO_INVALID_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) set_nlink(inode, fattr->nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) attr_changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) } else if (server->caps & NFS_CAP_NLINK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) nfsi->cache_validity |= save_cache_validity &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) (NFS_INO_INVALID_OTHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) | NFS_INO_REVAL_FORCED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) cache_revalidated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) * report the blocks in 512byte units
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) } else if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) inode->i_blocks = fattr->du.nfs2.blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) nfsi->cache_validity |= save_cache_validity &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) (NFS_INO_INVALID_BLOCKS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) | NFS_INO_REVAL_FORCED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) cache_revalidated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) /* Update attrtimeo value if we're out of the unstable period */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) if (attr_changed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) invalid &= ~NFS_INO_INVALID_ATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) nfsi->attrtimeo_timestamp = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) /* Set barrier to be more recent than all outstanding updates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) nfsi->attr_gencount = nfs_inc_attr_generation_counter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) if (cache_revalidated) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) if (!time_in_range_open(now, nfsi->attrtimeo_timestamp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) nfsi->attrtimeo_timestamp + nfsi->attrtimeo)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) nfsi->attrtimeo <<= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) if (nfsi->attrtimeo > NFS_MAXATTRTIMEO(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) nfsi->attrtimeo = NFS_MAXATTRTIMEO(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) nfsi->attrtimeo_timestamp = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) /* Set the barrier to be more recent than this fattr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) if ((long)(fattr->gencount - nfsi->attr_gencount) > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) nfsi->attr_gencount = fattr->gencount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) /* Don't invalidate the data if we were to blame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) || S_ISLNK(inode->i_mode)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) invalid &= ~NFS_INO_INVALID_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) nfs_set_cache_invalid(inode, invalid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) * No need to worry about unhashing the dentry, as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) * lookup validation will know that the inode is bad.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) * (But we fall through to invalidate the caches.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) nfs_set_inode_stale_locked(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) return -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) struct inode *nfs_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) struct nfs_inode *nfsi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) nfsi = kmem_cache_alloc(nfs_inode_cachep, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) if (!nfsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) nfsi->flags = 0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) nfsi->cache_validity = 0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) #if IS_ENABLED(CONFIG_NFS_V4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) nfsi->nfs4_acl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) #endif /* CONFIG_NFS_V4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) #ifdef CONFIG_NFS_V4_2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) nfsi->xattr_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) return &nfsi->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) EXPORT_SYMBOL_GPL(nfs_alloc_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) void nfs_free_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) kmem_cache_free(nfs_inode_cachep, NFS_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) EXPORT_SYMBOL_GPL(nfs_free_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) static inline void nfs4_init_once(struct nfs_inode *nfsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) #if IS_ENABLED(CONFIG_NFS_V4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) INIT_LIST_HEAD(&nfsi->open_states);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) nfsi->delegation = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) init_rwsem(&nfsi->rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) nfsi->layout = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) static void init_once(void *foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) struct nfs_inode *nfsi = (struct nfs_inode *) foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) inode_init_once(&nfsi->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) INIT_LIST_HEAD(&nfsi->open_files);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) INIT_LIST_HEAD(&nfsi->access_cache_entry_lru);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) INIT_LIST_HEAD(&nfsi->access_cache_inode_lru);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) INIT_LIST_HEAD(&nfsi->commit_info.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) atomic_long_set(&nfsi->nrequests, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) atomic_long_set(&nfsi->commit_info.ncommit, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) atomic_set(&nfsi->commit_info.rpcs_out, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) init_rwsem(&nfsi->rmdir_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) mutex_init(&nfsi->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) nfs4_init_once(nfsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) nfsi->cache_change_attribute = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) static int __init nfs_init_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) nfs_inode_cachep = kmem_cache_create("nfs_inode_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) sizeof(struct nfs_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 0, (SLAB_RECLAIM_ACCOUNT|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) SLAB_MEM_SPREAD|SLAB_ACCOUNT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) if (nfs_inode_cachep == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) static void nfs_destroy_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) * Make sure all delayed rcu free inodes are flushed before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) * destroy cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) kmem_cache_destroy(nfs_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) struct workqueue_struct *nfsiod_workqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) EXPORT_SYMBOL_GPL(nfsiod_workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) * start up the nfsiod workqueue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) static int nfsiod_start(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) struct workqueue_struct *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) dprintk("RPC: creating workqueue nfsiod\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) wq = alloc_workqueue("nfsiod", WQ_MEM_RECLAIM | WQ_UNBOUND, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) if (wq == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) nfsiod_workqueue = wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) * Destroy the nfsiod workqueue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) static void nfsiod_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) struct workqueue_struct *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) wq = nfsiod_workqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) if (wq == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) nfsiod_workqueue = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) destroy_workqueue(wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) unsigned int nfs_net_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) EXPORT_SYMBOL_GPL(nfs_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) static int nfs_net_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) nfs_clients_init(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) return nfs_fs_proc_net_init(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) static void nfs_net_exit(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) nfs_fs_proc_net_exit(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) nfs_clients_exit(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) static struct pernet_operations nfs_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) .init = nfs_net_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) .exit = nfs_net_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) .id = &nfs_net_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) .size = sizeof(struct nfs_net),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) * Initialize NFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) static int __init init_nfs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) err = nfs_sysfs_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) goto out10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) err = register_pernet_subsys(&nfs_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) goto out9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) err = nfs_fscache_register();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) goto out8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) err = nfsiod_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) goto out7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) err = nfs_fs_proc_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) goto out6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) err = nfs_init_nfspagecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) goto out5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) err = nfs_init_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) goto out4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) err = nfs_init_readpagecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) goto out3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) err = nfs_init_writepagecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) err = nfs_init_directcache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) rpc_proc_register(&init_net, &nfs_rpcstat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) err = register_nfs_fs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) goto out0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) out0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) rpc_proc_unregister(&init_net, "nfs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) nfs_destroy_directcache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) nfs_destroy_writepagecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) nfs_destroy_readpagecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) out3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) nfs_destroy_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) out4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) nfs_destroy_nfspagecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) out5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) nfs_fs_proc_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) out6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) nfsiod_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) out7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) nfs_fscache_unregister();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) out8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) unregister_pernet_subsys(&nfs_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) out9:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) nfs_sysfs_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) out10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) static void __exit exit_nfs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) nfs_destroy_directcache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) nfs_destroy_writepagecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) nfs_destroy_readpagecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) nfs_destroy_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) nfs_destroy_nfspagecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) nfs_fscache_unregister();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) unregister_pernet_subsys(&nfs_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) rpc_proc_unregister(&init_net, "nfs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) unregister_nfs_fs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) nfs_fs_proc_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) nfsiod_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) nfs_sysfs_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) /* Not quite true; I just maintain it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) module_param(enable_ino64, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) module_init(init_nfs_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) module_exit(exit_nfs_fs)