net/ceph/messenger.c
Source file repositories/reference/linux-study-clean/net/ceph/messenger.c
File Facts
- System
- Linux kernel
- Corpus path
net/ceph/messenger.c- Extension
.c- Size
- 56712 bytes
- Lines
- 2222
- 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.
- 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/ceph/ceph_debug.hlinux/crc32c.hlinux/ctype.hlinux/highmem.hlinux/inet.hlinux/kthread.hlinux/net.hlinux/nsproxy.hlinux/sched/mm.hlinux/slab.hlinux/socket.hlinux/string.hlinux/bio.hlinux/dns_resolver.hnet/tcp.htrace/events/sock.hlinux/ceph/ceph_features.hlinux/ceph/libceph.hlinux/ceph/messenger.hlinux/ceph/decode.hlinux/ceph/pagelist.hlinux/export.h
Detected Declarations
function con_flag_validfunction ceph_con_flag_clearfunction ceph_con_flag_setfunction ceph_con_flag_testfunction ceph_con_flag_test_and_clearfunction ceph_con_flag_test_and_setfunction ceph_encode_my_addrfunction ceph_msgr_slab_initfunction ceph_msgr_slab_exitfunction _ceph_msgr_exitfunction ceph_msgr_initfunction ceph_msgr_exitfunction ceph_msgr_flushfunction con_sock_state_initfunction con_sock_state_connectingfunction con_sock_state_connectedfunction con_sock_state_closingfunction con_sock_state_closedfunction ceph_sock_data_readyfunction ceph_sock_write_spacefunction ceph_sock_state_changefunction set_sock_callbacksfunction ceph_tcp_connectfunction ceph_con_close_socketfunction ceph_con_reset_protocolfunction ceph_msg_removefunction ceph_msg_remove_listfunction ceph_con_reset_sessionfunction ceph_con_closefunction ceph_con_openfunction ceph_con_openedfunction ceph_con_initfunction ceph_get_global_seqfunction ceph_con_discard_sentfunction con_faultfunction ceph_msg_data_bio_cursor_initfunction ceph_msg_data_bio_advancefunction ceph_msg_data_bvecs_cursor_initfunction ceph_msg_data_bvecs_advancefunction ceph_msg_data_pages_cursor_initfunction ceph_msg_data_pages_nextfunction ceph_msg_data_pages_advancefunction ceph_msg_data_pagelist_cursor_initfunction ceph_msg_data_pagelist_nextfunction ceph_msg_data_pagelist_advancefunction ceph_msg_data_iter_cursor_initfunction ceph_msg_data_iter_advancefunction handled
Annotated Snippet
if (sk_stream_is_writeable(sk)) {
dout("%s %p queueing write work\n", __func__, con);
clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
queue_con(con);
}
} else {
dout("%s %p nothing to write\n", __func__, con);
}
}
/* socket's state has changed */
static void ceph_sock_state_change(struct sock *sk)
{
struct ceph_connection *con = sk->sk_user_data;
dout("%s %p state = %d sk_state = %u\n", __func__,
con, con->state, sk->sk_state);
switch (sk->sk_state) {
case TCP_CLOSE:
dout("%s TCP_CLOSE\n", __func__);
fallthrough;
case TCP_CLOSE_WAIT:
dout("%s TCP_CLOSE_WAIT\n", __func__);
con_sock_state_closing(con);
ceph_con_flag_set(con, CEPH_CON_F_SOCK_CLOSED);
queue_con(con);
break;
case TCP_ESTABLISHED:
dout("%s TCP_ESTABLISHED\n", __func__);
con_sock_state_connected(con);
queue_con(con);
break;
default: /* Everything else is uninteresting */
break;
}
}
/*
* set up socket callbacks
*/
static void set_sock_callbacks(struct socket *sock,
struct ceph_connection *con)
{
struct sock *sk = sock->sk;
sk->sk_user_data = con;
sk->sk_data_ready = ceph_sock_data_ready;
sk->sk_write_space = ceph_sock_write_space;
sk->sk_state_change = ceph_sock_state_change;
}
/*
* socket helpers
*/
/*
* initiate connection to a remote socket.
*/
int ceph_tcp_connect(struct ceph_connection *con)
{
struct sockaddr_storage ss = con->peer_addr.in_addr; /* align */
struct socket *sock;
unsigned int noio_flag;
int ret;
dout("%s con %p peer_addr %s\n", __func__, con,
ceph_pr_addr(&con->peer_addr));
BUG_ON(con->sock);
/* sock_create_kern() allocates with GFP_KERNEL */
noio_flag = memalloc_noio_save();
ret = sock_create_kern(read_pnet(&con->msgr->net), ss.ss_family,
SOCK_STREAM, IPPROTO_TCP, &sock);
memalloc_noio_restore(noio_flag);
if (ret)
return ret;
sock->sk->sk_allocation = GFP_NOFS;
sock->sk->sk_use_task_frag = false;
#ifdef CONFIG_LOCKDEP
lockdep_set_class(&sock->sk->sk_lock, &socket_class);
#endif
set_sock_callbacks(sock, con);
con_sock_state_connecting(con);
ret = kernel_connect(sock, (struct sockaddr_unsized *)&ss, sizeof(ss),
O_NONBLOCK);
if (ret == -EINPROGRESS) {
Annotation
- Immediate include surface: `linux/ceph/ceph_debug.h`, `linux/crc32c.h`, `linux/ctype.h`, `linux/highmem.h`, `linux/inet.h`, `linux/kthread.h`, `linux/net.h`, `linux/nsproxy.h`.
- Detected declarations: `function con_flag_valid`, `function ceph_con_flag_clear`, `function ceph_con_flag_set`, `function ceph_con_flag_test`, `function ceph_con_flag_test_and_clear`, `function ceph_con_flag_test_and_set`, `function ceph_encode_my_addr`, `function ceph_msgr_slab_init`, `function ceph_msgr_slab_exit`, `function _ceph_msgr_exit`.
- 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.