fs/nfsd/nfs4layouts.c
Source file repositories/reference/linux-study-clean/fs/nfsd/nfs4layouts.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nfsd/nfs4layouts.c- Extension
.c- Size
- 24452 bytes
- Lines
- 957
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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/exportfs_block.hlinux/kmod.hlinux/file.hlinux/jhash.hlinux/sched.hlinux/sunrpc/addr.hpnfs.hnetns.htrace.h
Detected Declarations
struct nfs4_layoutfunction devid_hashfnfunction nfsd4_alloc_devid_mapfunction list_for_each_entryfunction nfsd4_find_devid_mapfunction nfsd4_set_deviceidfunction nfsd4_setup_layout_typefunction nfsd4_close_layoutfunction nfsd4_free_layout_stateidfunction nfsd4_layout_setleasefunction nfsd4_alloc_layout_stateidfunction nfsd4_preprocess_layout_stateidfunction nfsd4_recall_file_layoutfunction layout_endfunction layout_update_lenfunction layouts_overlappingfunction layouts_try_mergefunction nfsd4_recall_conflictfunction list_for_each_entry_safefunction nfsd4_insert_layoutfunction nfsd4_free_layoutsfunction nfsd4_return_file_layoutfunction nfsd4_return_file_layoutsfunction nfsd4_return_client_layoutsfunction list_for_each_entry_safefunction nfsd4_return_all_layoutsfunction nfsd4_return_all_client_layoutsfunction nfsd4_return_all_file_layoutsfunction nfsd4_cb_layout_failfunction nfsd4_cb_layout_preparefunction nfsd4_cb_layout_donefunction nfsd4_cb_layout_releasefunction nfsd4_layout_lm_breakfunction nfsd4_layout_lm_changefunction nfsd4_layout_lm_open_conflictfunction nfsd4_layout_fence_workerfunction nfsd4_layout_lm_breaker_timedoutfunction nfsd4_init_pnfsfunction nfsd4_exit_pnfs
Annotated Snippet
struct nfs4_layout {
struct list_head lo_perstate;
struct nfs4_layout_stateid *lo_state;
struct nfsd4_layout_seg lo_seg;
};
static struct kmem_cache *nfs4_layout_cache;
static struct kmem_cache *nfs4_layout_stateid_cache;
static const struct nfsd4_callback_ops nfsd4_cb_layout_ops;
static const struct lease_manager_operations nfsd4_layouts_lm_ops;
static void nfsd4_layout_fence_worker(struct work_struct *work);
const struct nfsd4_layout_ops *nfsd4_layout_ops[LAYOUT_TYPE_MAX] = {
#ifdef CONFIG_NFSD_FLEXFILELAYOUT
[LAYOUT_FLEX_FILES] = &ff_layout_ops,
#endif
#ifdef CONFIG_NFSD_BLOCKLAYOUT
[LAYOUT_BLOCK_VOLUME] = &bl_layout_ops,
#endif
#ifdef CONFIG_NFSD_SCSILAYOUT
[LAYOUT_SCSI] = &scsi_layout_ops,
#endif
};
/* pNFS device ID to export fsid mapping */
#define DEVID_HASH_BITS 8
#define DEVID_HASH_SIZE (1 << DEVID_HASH_BITS)
#define DEVID_HASH_MASK (DEVID_HASH_SIZE - 1)
static u64 nfsd_devid_seq = 1;
static struct list_head nfsd_devid_hash[DEVID_HASH_SIZE];
static DEFINE_SPINLOCK(nfsd_devid_lock);
static inline u32 devid_hashfn(u64 idx)
{
return jhash_2words(idx, idx >> 32, 0) & DEVID_HASH_MASK;
}
static void
nfsd4_alloc_devid_map(const struct svc_fh *fhp)
{
const struct knfsd_fh *fh = &fhp->fh_handle;
size_t fsid_len = key_len(fh->fh_fsid_type);
struct nfsd4_deviceid_map *map, *old;
int i;
map = kzalloc(sizeof(*map) + fsid_len, GFP_KERNEL);
if (!map)
return;
map->fsid_type = fh->fh_fsid_type;
memcpy(&map->fsid, fh_fsid(fh), fsid_len);
spin_lock(&nfsd_devid_lock);
if (fhp->fh_export->ex_devid_map)
goto out_unlock;
for (i = 0; i < DEVID_HASH_SIZE; i++) {
list_for_each_entry(old, &nfsd_devid_hash[i], hash) {
if (old->fsid_type != fh->fh_fsid_type)
continue;
if (memcmp(old->fsid, fh_fsid(fh),
key_len(old->fsid_type)))
continue;
fhp->fh_export->ex_devid_map = old;
goto out_unlock;
}
}
map->idx = nfsd_devid_seq++;
list_add_tail_rcu(&map->hash, &nfsd_devid_hash[devid_hashfn(map->idx)]);
fhp->fh_export->ex_devid_map = map;
map = NULL;
out_unlock:
spin_unlock(&nfsd_devid_lock);
kfree(map);
}
struct nfsd4_deviceid_map *
nfsd4_find_devid_map(int idx)
{
struct nfsd4_deviceid_map *map, *ret = NULL;
rcu_read_lock();
list_for_each_entry_rcu(map, &nfsd_devid_hash[devid_hashfn(idx)], hash)
if (map->idx == idx)
ret = map;
Annotation
- Immediate include surface: `linux/exportfs_block.h`, `linux/kmod.h`, `linux/file.h`, `linux/jhash.h`, `linux/sched.h`, `linux/sunrpc/addr.h`, `pnfs.h`, `netns.h`.
- Detected declarations: `struct nfs4_layout`, `function devid_hashfn`, `function nfsd4_alloc_devid_map`, `function list_for_each_entry`, `function nfsd4_find_devid_map`, `function nfsd4_set_deviceid`, `function nfsd4_setup_layout_type`, `function nfsd4_close_layout`, `function nfsd4_free_layout_stateid`, `function nfsd4_layout_setlease`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source 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.