fs/lockd/mon.c
Source file repositories/reference/linux-study-clean/fs/lockd/mon.c
File Facts
- System
- Linux kernel
- Corpus path
fs/lockd/mon.c- Extension
.c- Size
- 14724 bytes
- Lines
- 582
- 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/types.hlinux/kernel.hlinux/ktime.hlinux/slab.hlinux/sunrpc/clnt.hlinux/sunrpc/addr.hlinux/sunrpc/xprtsock.hlinux/sunrpc/svc.hlinux/unaligned.hlockd.hnetns.h
Detected Declarations
struct nsm_argsstruct nsm_resfunction nsm_mon_unmonfunction nsm_monitorfunction nsm_unmonitorfunction nsm_init_privatefunction nsm_releasefunction encode_nsm_stringfunction encode_mon_namefunction encode_my_idfunction encode_mon_idfunction encode_privfunction nsm_xdr_enc_monfunction nsm_xdr_enc_unmonfunction nsm_xdr_dec_stat_resfunction nsm_xdr_dec_stat
Annotated Snippet
struct nsm_args {
struct nsm_private *priv;
u32 prog; /* RPC callback info */
u32 vers;
u32 proc;
char *mon_name;
const char *nodename;
};
struct nsm_res {
u32 status;
u32 state;
};
static const struct rpc_program nsm_program;
static DEFINE_SPINLOCK(nsm_lock);
/*
* Local NSM state
*/
u32 __read_mostly nsm_local_state;
bool __read_mostly nsm_use_hostnames;
static inline struct sockaddr *nsm_addr(const struct nsm_handle *nsm)
{
return (struct sockaddr *)&nsm->sm_addr;
}
static struct rpc_clnt *nsm_create(struct net *net, const char *nodename)
{
struct sockaddr_in sin = {
.sin_family = AF_INET,
.sin_addr.s_addr = htonl(INADDR_LOOPBACK),
};
struct rpc_create_args args = {
.net = net,
.protocol = XPRT_TRANSPORT_TCP,
.address = (struct sockaddr *)&sin,
.addrsize = sizeof(sin),
.servername = "rpc.statd",
.nodename = nodename,
.program = &nsm_program,
.version = NSM_VERSION,
.authflavor = RPC_AUTH_NULL,
.flags = RPC_CLNT_CREATE_NOPING,
.cred = current_cred(),
};
return rpc_create(&args);
}
static int nsm_mon_unmon(struct nsm_handle *nsm, u32 proc, struct nsm_res *res,
const struct nlm_host *host)
{
int status;
struct rpc_clnt *clnt;
struct nsm_args args = {
.priv = &nsm->sm_priv,
.prog = NLM_PROGRAM,
.vers = 3,
.proc = NLMPROC_NSM_NOTIFY,
.mon_name = nsm->sm_mon_name,
.nodename = host->nodename,
};
struct rpc_message msg = {
.rpc_argp = &args,
.rpc_resp = res,
};
memset(res, 0, sizeof(*res));
clnt = nsm_create(host->net, host->nodename);
if (IS_ERR(clnt)) {
dprintk("lockd: failed to create NSM upcall transport, "
"status=%ld, net=%x\n", PTR_ERR(clnt),
host->net->ns.inum);
return PTR_ERR(clnt);
}
msg.rpc_proc = &clnt->cl_procinfo[proc];
status = rpc_call_sync(clnt, &msg, RPC_TASK_SOFTCONN);
if (status == -ECONNREFUSED) {
dprintk("lockd: NSM upcall RPC failed, status=%d, forcing rebind\n",
status);
rpc_force_rebind(clnt);
status = rpc_call_sync(clnt, &msg, RPC_TASK_SOFTCONN);
}
if (status < 0)
dprintk("lockd: NSM upcall RPC failed, status=%d\n",
Annotation
- Immediate include surface: `linux/types.h`, `linux/kernel.h`, `linux/ktime.h`, `linux/slab.h`, `linux/sunrpc/clnt.h`, `linux/sunrpc/addr.h`, `linux/sunrpc/xprtsock.h`, `linux/sunrpc/svc.h`.
- Detected declarations: `struct nsm_args`, `struct nsm_res`, `function nsm_mon_unmon`, `function nsm_monitor`, `function nsm_unmonitor`, `function nsm_init_private`, `function nsm_release`, `function encode_nsm_string`, `function encode_mon_name`, `function encode_my_id`.
- 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.