net/netfilter/ipvs/ip_vs_sched.c
Source file repositories/reference/linux-study-clean/net/netfilter/ipvs/ip_vs_sched.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/ipvs/ip_vs_sched.c- Extension
.c- Size
- 5690 bytes
- Lines
- 250
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/spinlock.hlinux/interrupt.hasm/string.hlinux/kmod.hlinux/sysctl.hnet/ip_vs.h
Detected Declarations
function ip_vs_bind_schedulerfunction ip_vs_unbind_schedulerfunction list_for_each_entryfunction ip_vs_scheduler_putfunction ip_vs_scheduler_errfunction register_ip_vs_schedulerfunction unregister_ip_vs_schedulerexport ip_vs_scheduler_err
Annotated Snippet
if (ret) {
pr_err("%s(): init error\n", __func__);
return ret;
}
}
rcu_assign_pointer(svc->scheduler, scheduler);
return 0;
}
/*
* Unbind a service with its scheduler
*/
void ip_vs_unbind_scheduler(struct ip_vs_service *svc)
{
struct ip_vs_scheduler *sched;
sched = rcu_dereference_protected(svc->scheduler, 1);
if (!sched)
return;
/* Reset the scheduler before initiating any RCU callbacks */
rcu_assign_pointer(svc->scheduler, NULL);
smp_wmb(); /* paired with smp_rmb() in ip_vs_schedule() */
if (sched->done_service)
sched->done_service(svc);
}
/*
* Get scheduler in the scheduler list by name
*/
static struct ip_vs_scheduler *ip_vs_sched_getbyname(const char *sched_name)
{
struct ip_vs_scheduler *sched;
IP_VS_DBG(2, "%s(): sched_name \"%s\"\n", __func__, sched_name);
mutex_lock(&ip_vs_sched_mutex);
list_for_each_entry(sched, &ip_vs_schedulers, n_list) {
/*
* Test and get the modules atomically
*/
if (sched->module && !try_module_get(sched->module)) {
/*
* This scheduler is just deleted
*/
continue;
}
if (strcmp(sched_name, sched->name)==0) {
/* HIT */
mutex_unlock(&ip_vs_sched_mutex);
return sched;
}
module_put(sched->module);
}
mutex_unlock(&ip_vs_sched_mutex);
return NULL;
}
/*
* Lookup scheduler and try to load it if it doesn't exist
*/
struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name)
{
struct ip_vs_scheduler *sched;
/*
* Search for the scheduler by sched_name
*/
sched = ip_vs_sched_getbyname(sched_name);
/*
* If scheduler not found, load the module and search again
*/
if (sched == NULL) {
request_module("ip_vs_%s", sched_name);
sched = ip_vs_sched_getbyname(sched_name);
}
return sched;
}
void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler)
{
if (scheduler)
module_put(scheduler->module);
Annotation
- Immediate include surface: `linux/module.h`, `linux/spinlock.h`, `linux/interrupt.h`, `asm/string.h`, `linux/kmod.h`, `linux/sysctl.h`, `net/ip_vs.h`.
- Detected declarations: `function ip_vs_bind_scheduler`, `function ip_vs_unbind_scheduler`, `function list_for_each_entry`, `function ip_vs_scheduler_put`, `function ip_vs_scheduler_err`, `function register_ip_vs_scheduler`, `function unregister_ip_vs_scheduler`, `export ip_vs_scheduler_err`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- 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.