net/rds/loop.c
Source file repositories/reference/linux-study-clean/net/rds/loop.c
File Facts
- System
- Linux kernel
- Corpus path
net/rds/loop.c- Extension
.c- Size
- 7277 bytes
- Lines
- 255
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/in.hnet/net_namespace.hnet/netns/generic.hlinux/ipv6.hrds_single_path.hrds.hloop.h
Detected Declarations
struct rds_loop_connectionfunction rds_loop_set_unloadingfunction rds_loop_is_unloadingfunction rds_loop_xmitfunction rds_loop_xmitfunction rds_loop_recv_pathfunction rds_conn_destroyfunction rds_loop_conn_freefunction rds_loop_conn_path_connectfunction rds_loop_conn_path_shutdownfunction list_for_each_entry_safefunction rds_loop_kill_connsfunction list_for_each_entry_safefunction rds_loop_exit_netfunction rds_loop_net_initfunction rds_loop_net_exit
Annotated Snippet
struct rds_loop_connection {
struct list_head loop_node;
struct rds_connection *conn;
};
/*
* Even the loopback transport needs to keep track of its connections,
* so it can call rds_conn_destroy() on them on exit. N.B. there are
* 1+ loopback addresses (127.*.*.*) so it's not a bug to have
* multiple loopback conns allocated, although rather useless.
*/
static int rds_loop_conn_alloc(struct rds_connection *conn, gfp_t gfp)
{
struct rds_loop_connection *lc;
unsigned long flags;
lc = kzalloc_obj(struct rds_loop_connection, gfp);
if (!lc)
return -ENOMEM;
INIT_LIST_HEAD(&lc->loop_node);
lc->conn = conn;
conn->c_transport_data = lc;
spin_lock_irqsave(&loop_conns_lock, flags);
list_add_tail(&lc->loop_node, &loop_conns);
spin_unlock_irqrestore(&loop_conns_lock, flags);
return 0;
}
static void rds_loop_conn_free(void *arg)
{
struct rds_loop_connection *lc = arg;
unsigned long flags;
rdsdebug("lc %p\n", lc);
spin_lock_irqsave(&loop_conns_lock, flags);
list_del(&lc->loop_node);
spin_unlock_irqrestore(&loop_conns_lock, flags);
kfree(lc);
}
static int rds_loop_conn_path_connect(struct rds_conn_path *cp)
{
rds_connect_complete(cp->cp_conn);
return 0;
}
static void rds_loop_conn_path_shutdown(struct rds_conn_path *cp)
{
}
void rds_loop_exit(void)
{
struct rds_loop_connection *lc, *_lc;
LIST_HEAD(tmp_list);
rds_loop_set_unloading();
synchronize_rcu();
/* avoid calling conn_destroy with irqs off */
spin_lock_irq(&loop_conns_lock);
list_splice(&loop_conns, &tmp_list);
INIT_LIST_HEAD(&loop_conns);
spin_unlock_irq(&loop_conns_lock);
list_for_each_entry_safe(lc, _lc, &tmp_list, loop_node) {
WARN_ON(lc->conn->c_passive);
rds_conn_destroy(lc->conn);
}
}
static void rds_loop_kill_conns(struct net *net)
{
struct rds_loop_connection *lc, *_lc;
LIST_HEAD(tmp_list);
spin_lock_irq(&loop_conns_lock);
list_for_each_entry_safe(lc, _lc, &loop_conns, loop_node) {
struct net *c_net = read_pnet(&lc->conn->c_net);
if (net != c_net)
continue;
list_move_tail(&lc->loop_node, &tmp_list);
}
spin_unlock_irq(&loop_conns_lock);
list_for_each_entry_safe(lc, _lc, &tmp_list, loop_node) {
WARN_ON(lc->conn->c_passive);
rds_conn_destroy(lc->conn);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/slab.h`, `linux/in.h`, `net/net_namespace.h`, `net/netns/generic.h`, `linux/ipv6.h`, `rds_single_path.h`, `rds.h`.
- Detected declarations: `struct rds_loop_connection`, `function rds_loop_set_unloading`, `function rds_loop_is_unloading`, `function rds_loop_xmit`, `function rds_loop_xmit`, `function rds_loop_recv_path`, `function rds_conn_destroy`, `function rds_loop_conn_free`, `function rds_loop_conn_path_connect`, `function rds_loop_conn_path_shutdown`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.