fs/lockd/host.c
Source file repositories/reference/linux-study-clean/fs/lockd/host.c
File Facts
- System
- Linux kernel
- Corpus path
fs/lockd/host.c- Extension
.c- Size
- 18813 bytes
- Lines
- 724
- 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/types.hlinux/slab.hlinux/in.hlinux/in6.hlinux/sunrpc/clnt.hlinux/sunrpc/addr.hlinux/sunrpc/svc.hlinux/mutex.hlinux/sunrpc/svc_xprt.hnet/ipv6.hlockd.hnetns.h
Detected Declarations
struct nlm_lookup_host_infofunction __nlm_hash32function __nlm_hash_addr4function __nlm_hash_addr6function nlm_hash_addressfunction nlm_destroy_host_lockedfunction nlmclnt_release_hostfunction nlmclnt_match_allfunction nlmclnt_release_hostfunction nlm_gc_hostfunction nlm_bind_hostfunction nlm_rebind_hostfunction nlm_get_hostfunction nlm_host_rebootedfunction nlm_complain_hostsfunction for_each_hostfunction nlm_shutdown_hosts_netfunction nlm_shutdown_hostsfunction nlm_gc_hostsfunction for_each_host_safeexport nlmclnt_shutdown_rpc_clnt
Annotated Snippet
struct nlm_lookup_host_info {
const int server; /* search for server|client */
const struct sockaddr *sap; /* address to search for */
const size_t salen; /* it's length */
const unsigned short protocol; /* transport to search for*/
const u32 version; /* NLM version to search for */
const char *hostname; /* remote's hostname */
const size_t hostname_len; /* it's length */
const int noresvport; /* use non-priv port */
struct net *net; /* network namespace to bind */
const struct cred *cred;
};
/*
* Hash function must work well on big- and little-endian platforms
*/
static unsigned int __nlm_hash32(const __be32 n)
{
unsigned int hash = (__force u32)n ^ ((__force u32)n >> 16);
return hash ^ (hash >> 8);
}
static unsigned int __nlm_hash_addr4(const struct sockaddr *sap)
{
const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
return __nlm_hash32(sin->sin_addr.s_addr);
}
static unsigned int __nlm_hash_addr6(const struct sockaddr *sap)
{
const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
const struct in6_addr addr = sin6->sin6_addr;
return __nlm_hash32(addr.s6_addr32[0]) ^
__nlm_hash32(addr.s6_addr32[1]) ^
__nlm_hash32(addr.s6_addr32[2]) ^
__nlm_hash32(addr.s6_addr32[3]);
}
static unsigned int nlm_hash_address(const struct sockaddr *sap)
{
unsigned int hash;
switch (sap->sa_family) {
case AF_INET:
hash = __nlm_hash_addr4(sap);
break;
case AF_INET6:
hash = __nlm_hash_addr6(sap);
break;
default:
hash = 0;
}
return hash & (NLM_HOST_NRHASH - 1);
}
/*
* Allocate and initialize an nlm_host. Common to both client and server.
*/
static struct nlm_host *nlm_alloc_host(struct nlm_lookup_host_info *ni,
struct nsm_handle *nsm)
{
struct nlm_host *host = NULL;
unsigned long now = jiffies;
if (nsm != NULL)
refcount_inc(&nsm->sm_count);
else {
nsm = nsm_get_handle(ni->net, ni->sap, ni->salen,
ni->hostname, ni->hostname_len);
if (unlikely(nsm == NULL)) {
dprintk("lockd: %s failed; no nsm handle\n",
__func__);
goto out;
}
}
host = kmalloc_obj(*host);
if (unlikely(host == NULL)) {
dprintk("lockd: %s failed; no memory\n", __func__);
nsm_release(nsm);
goto out;
}
memcpy(nlm_addr(host), ni->sap, ni->salen);
host->h_addrlen = ni->salen;
rpc_set_port(nlm_addr(host), 0);
host->h_srcaddrlen = 0;
host->h_rpcclnt = NULL;
host->h_name = nsm->sm_name;
Annotation
- Immediate include surface: `linux/types.h`, `linux/slab.h`, `linux/in.h`, `linux/in6.h`, `linux/sunrpc/clnt.h`, `linux/sunrpc/addr.h`, `linux/sunrpc/svc.h`, `linux/mutex.h`.
- Detected declarations: `struct nlm_lookup_host_info`, `function __nlm_hash32`, `function __nlm_hash_addr4`, `function __nlm_hash_addr6`, `function nlm_hash_address`, `function nlm_destroy_host_locked`, `function nlmclnt_release_host`, `function nlmclnt_match_all`, `function nlmclnt_release_host`, `function nlm_gc_host`.
- 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.