fs/nfs/fscache.c
Source file repositories/reference/linux-study-clean/fs/nfs/fscache.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nfs/fscache.c- Extension
.c- Size
- 10475 bytes
- Lines
- 388
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/init.hlinux/kernel.hlinux/sched.hlinux/mm.hlinux/nfs_fs.hlinux/nfs_fs_sb.hlinux/in6.hlinux/seq_file.hlinux/slab.hlinux/iversion.hlinux/xarray.hlinux/fscache.hlinux/netfs.hinternal.hiostat.hfscache.hnfstrace.h
Detected Declarations
function Copyrightfunction nfs_fscache_get_client_keyfunction nfs_fscache_get_super_cookiefunction nfs_fscache_release_super_cookiefunction nfs_fscache_init_inodefunction nfs_fscache_clear_inodefunction accessfunction nfs_fscache_release_filefunction nfs_netfs_read_foliofunction nfs_netfs_readaheadfunction nfs_netfs_init_requestfunction nfs_netfs_free_requestfunction nfs_netfs_issue_readfunction xa_for_each_rangefunction nfs_netfs_initiate_readfunction nfs_netfs_folio_unlockfunction nfs_netfs_read_completionexport nfs_fscache_open_file
Annotated Snippet
if (vcookie != ERR_PTR(-EBUSY)) {
kfree(key);
return PTR_ERR(vcookie);
}
pr_err("NFS: Cache volume key already in use (%s)\n", key);
vcookie = NULL;
}
nfss->fscache = vcookie;
out:
kfree(key);
return 0;
}
/*
* release a per-superblock cookie
*/
void nfs_fscache_release_super_cookie(struct super_block *sb)
{
struct nfs_server *nfss = NFS_SB(sb);
fscache_relinquish_volume(nfss->fscache, NULL, false);
nfss->fscache = NULL;
kfree(nfss->fscache_uniq);
}
/*
* Initialise the per-inode cache cookie pointer for an NFS inode.
*/
void nfs_fscache_init_inode(struct inode *inode)
{
struct nfs_fscache_inode_auxdata auxdata;
struct nfs_server *nfss = NFS_SERVER(inode);
struct nfs_inode *nfsi = NFS_I(inode);
netfs_inode(inode)->cache = NULL;
if (!(nfss->fscache && S_ISREG(inode->i_mode)))
return;
nfs_fscache_update_auxdata(&auxdata, inode);
netfs_inode(inode)->cache = fscache_acquire_cookie(
nfss->fscache,
0,
nfsi->fh.data, /* index_key */
nfsi->fh.size,
&auxdata, /* aux_data */
sizeof(auxdata),
i_size_read(inode));
if (netfs_inode(inode)->cache)
mapping_set_release_always(inode->i_mapping);
}
/*
* Release a per-inode cookie.
*/
void nfs_fscache_clear_inode(struct inode *inode)
{
fscache_relinquish_cookie(netfs_i_cookie(netfs_inode(inode)), false);
netfs_inode(inode)->cache = NULL;
}
/*
* Enable or disable caching for a file that is being opened as appropriate.
* The cookie is allocated when the inode is initialised, but is not enabled at
* that time. Enablement is deferred to file-open time to avoid stat() and
* access() thrashing the cache.
*
* For now, with NFS, only regular files that are open read-only will be able
* to use the cache.
*
* We enable the cache for an inode if we open it read-only and it isn't
* currently open for writing. We disable the cache if the inode is open
* write-only.
*
* The caller uses the file struct to pin i_writecount on the inode before
* calling us when a file is opened for writing, so we can make use of that.
*
* Note that this may be invoked multiple times in parallel by parallel
* nfs_open() functions.
*/
void nfs_fscache_open_file(struct inode *inode, struct file *filp)
{
struct nfs_fscache_inode_auxdata auxdata;
struct fscache_cookie *cookie = netfs_i_cookie(netfs_inode(inode));
bool open_for_write = inode_is_open_for_write(inode);
if (!fscache_cookie_valid(cookie))
return;
Annotation
- Immediate include surface: `linux/init.h`, `linux/kernel.h`, `linux/sched.h`, `linux/mm.h`, `linux/nfs_fs.h`, `linux/nfs_fs_sb.h`, `linux/in6.h`, `linux/seq_file.h`.
- Detected declarations: `function Copyright`, `function nfs_fscache_get_client_key`, `function nfs_fscache_get_super_cookie`, `function nfs_fscache_release_super_cookie`, `function nfs_fscache_init_inode`, `function nfs_fscache_clear_inode`, `function access`, `function nfs_fscache_release_file`, `function nfs_netfs_read_folio`, `function nfs_netfs_readahead`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.