fs/nfs/nfs4state.c
Source file repositories/reference/linux-study-clean/fs/nfs/nfs4state.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nfs/nfs4state.c- Extension
.c- Size
- 72417 bytes
- Lines
- 2714
- 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/kernel.hlinux/slab.hlinux/fs.hlinux/nfs_fs.hlinux/kthread.hlinux/module.hlinux/random.hlinux/ratelimit.hlinux/workqueue.hlinux/bitops.hlinux/jiffies.hlinux/sched/mm.hlinux/sunrpc/clnt.hnfs4_fs.hnfs40.hcallback.hdelegation.hinternal.hnfs4idmap.hnfs4session.hpnfs.hnetns.hnfs4trace.h
Detected Declarations
function nfs4_setup_state_renewalfunction nfs4_init_clientidfunction nfs4_root_machine_credfunction nfs4_get_renew_cred_server_lockedfunction nfs4_end_drain_slot_tablefunction nfs4_end_drain_sessionfunction nfs4_drain_slot_tblfunction nfs4_begin_drain_sessionfunction nfs41_finish_session_resetfunction nfs41_init_clientidfunction nfs41_discover_server_trunkingfunction nfs4_find_state_owner_lockedfunction nfs4_insert_state_owner_lockedfunction nfs4_remove_state_owner_lockedfunction nfs4_init_seqid_counterfunction nfs4_destroy_seqid_counterfunction nfs4_alloc_state_ownerfunction nfs4_reset_state_ownerfunction nfs4_free_state_ownerfunction nfs4_gc_state_ownersfunction list_for_each_entry_safefunction nfs4_put_state_ownerfunction nfs4_purge_state_ownersfunction nfs4_free_state_ownersfunction list_for_each_entry_safefunction nfs4_alloc_open_statefunction nfs4_state_set_mode_lockedfunction __nfs4_find_state_byownerfunction list_for_each_entry_rcufunction nfs4_free_open_statefunction nfs4_get_open_statefunction nfs4_put_open_statefunction __nfs4_closefunction nfs4_close_statefunction nfs4_close_syncfunction ownerfunction nfs4_free_lock_statefunction nfs4_put_lock_statefunction nfs4_fl_copy_lockfunction nfs4_fl_release_lockfunction nfs4_set_lock_statefunction nfs4_copy_lock_stateidfunction nfs4_copy_open_stateidfunction nfs4_select_rw_stateidfunction nfs_release_seqidfunction nfs_free_seqidfunction nfs_increment_seqidfunction nfs_increment_open_seqid
Annotated Snippet
if (state->n_rdonly == 0) {
newstate &= ~FMODE_READ;
call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
}
if (state->n_wronly == 0) {
newstate &= ~FMODE_WRITE;
call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
}
if (newstate == 0)
clear_bit(NFS_DELEGATED_STATE, &state->flags);
}
nfs4_state_set_mode_locked(state, newstate);
spin_unlock(&owner->so_lock);
if (!call_close) {
nfs4_put_open_state(state);
nfs4_put_state_owner(owner);
} else
nfs4_do_close(state, gfp_mask, wait);
}
void nfs4_close_state(struct nfs4_state *state, fmode_t fmode)
{
__nfs4_close(state, fmode, GFP_KERNEL, 0);
}
void nfs4_close_sync(struct nfs4_state *state, fmode_t fmode)
{
__nfs4_close(state, fmode, GFP_KERNEL, 1);
}
/*
* Search the state->lock_states for an existing lock_owner
* that is compatible with either of the given owners.
* If the second is non-zero, then the first refers to a Posix-lock
* owner (current->files) and the second refers to a flock/OFD
* owner (struct file*). In that case, prefer a match for the first
* owner.
* If both sorts of locks are held on the one file we cannot know
* which stateid was intended to be used, so a "correct" choice cannot
* be made. Failing that, a "consistent" choice is preferable. The
* consistent choice we make is to prefer the first owner, that of a
* Posix lock.
*/
static struct nfs4_lock_state *
__nfs4_find_lock_state(struct nfs4_state *state,
fl_owner_t owner, fl_owner_t owner2)
{
struct nfs4_lock_state *pos, *ret = NULL;
list_for_each_entry(pos, &state->lock_states, ls_locks) {
if (pos->ls_owner == owner) {
ret = pos;
break;
}
if (pos->ls_owner == owner2)
ret = pos;
}
if (ret)
refcount_inc(&ret->ls_count);
return ret;
}
/*
* Return a compatible lock_state. If no initialized lock_state structure
* exists, return an uninitialized one.
*
*/
static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t owner)
{
struct nfs4_lock_state *lsp;
struct nfs_server *server = state->owner->so_server;
lsp = kzalloc_obj(*lsp, GFP_KERNEL_ACCOUNT);
if (lsp == NULL)
return NULL;
nfs4_init_seqid_counter(&lsp->ls_seqid);
refcount_set(&lsp->ls_count, 1);
lsp->ls_state = state;
lsp->ls_owner = owner;
lsp->ls_seqid.owner_id = atomic64_inc_return(&server->owner_ctr);
INIT_LIST_HEAD(&lsp->ls_locks);
return lsp;
}
void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp)
{
nfs4_destroy_seqid_counter(&lsp->ls_seqid);
kfree(lsp);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/slab.h`, `linux/fs.h`, `linux/nfs_fs.h`, `linux/kthread.h`, `linux/module.h`, `linux/random.h`, `linux/ratelimit.h`.
- Detected declarations: `function nfs4_setup_state_renewal`, `function nfs4_init_clientid`, `function nfs4_root_machine_cred`, `function nfs4_get_renew_cred_server_locked`, `function nfs4_end_drain_slot_table`, `function nfs4_end_drain_session`, `function nfs4_drain_slot_tbl`, `function nfs4_begin_drain_session`, `function nfs41_finish_session_reset`, `function nfs41_init_clientid`.
- 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.