net/smc/smc_core.c
Source file repositories/reference/linux-study-clean/net/smc/smc_core.c
File Facts
- System
- Linux kernel
- Corpus path
net/smc/smc_core.c- Extension
.c- Size
- 74539 bytes
- Lines
- 2787
- 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.
- 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/socket.hlinux/if_vlan.hlinux/random.hlinux/workqueue.hlinux/wait.hlinux/reboot.hlinux/mutex.hlinux/list.hlinux/smc.hnet/tcp.hnet/sock.hrdma/ib_verbs.hrdma/ib_cache.hsmc.hsmc_clc.hsmc_core.hsmc_ib.hsmc_wr.hsmc_llc.hsmc_cdc.hsmc_close.hsmc_ism.hsmc_netlink.hsmc_stats.hsmc_tracepoint.h
Detected Declarations
function smc_ibdev_cnt_incfunction smc_ibdev_cnt_decfunction smc_lgr_schedule_free_workfunction smc_lgr_add_alert_tokenfunction smcr_lgr_conn_assign_linkfunction smc_lgr_register_connfunction __smc_lgr_unregister_connfunction smc_lgr_unregister_connfunction smc_lgr_buf_list_addfunction smc_lgr_buf_list_delfunction smc_nl_get_sys_infofunction smc_nl_fill_lgr_v2_commonfunction smc_nl_fill_smcr_lgr_v2function smc_nl_fill_lgrfunction smc_nl_fill_lgr_linkfunction smc_nl_handle_lgrfunction smc_nl_fill_lgr_listfunction smc_nl_fill_smcd_lgrfunction smc_nl_handle_smcd_lgrfunction smc_nl_fill_smcd_devfunction smcr_nl_get_lgrfunction smcr_nl_get_linkfunction smcd_nl_get_lgrfunction smc_lgr_cleanup_earlyfunction smcr_lgr_link_deactivate_allfunction smc_lgr_free_workfunction smc_lgr_terminate_workfunction smcr_next_link_idfunction smcr_copy_dev_info_to_linkfunction smcr_link_initfunction smc_lgr_createfunction smc_write_spacefunction smc_switch_cursorfunction smc_switch_link_and_countfunction smcr_buf_unusefunction smcd_buf_detachfunction smc_buf_unusefunction smc_conn_freefunction smcr_buf_unmap_linkfunction smcr_buf_unmap_lgrfunction smcr_rtoken_clear_linkfunction __smcr_link_clearfunction smcr_link_clearfunction smcr_link_holdfunction smcr_link_putfunction smcr_buf_freefunction smcd_buf_freefunction smc_buf_free
Annotated Snippet
if (conn->lgr->role == SMC_CLNT) {
conn->lnk = lnk; /* temporary, SMC server assigns link*/
break;
}
if (conn->lgr->conns_num % 2) {
for (j = i + 1; j < SMC_LINKS_PER_LGR_MAX; j++) {
struct smc_link *lnk2;
lnk2 = &conn->lgr->lnk[j];
if (lnk2->state == expected &&
!lnk2->link_is_asym) {
conn->lnk = lnk2;
break;
}
}
}
if (!conn->lnk)
conn->lnk = lnk;
break;
}
if (!conn->lnk)
return SMC_CLC_DECL_NOACTLINK;
atomic_inc(&conn->lnk->conn_cnt);
return 0;
}
/* Register connection in link group by assigning an alert token
* registered in a search tree.
* Requires @conns_lock
* Note that '0' is a reserved value and not assigned.
*/
static int smc_lgr_register_conn(struct smc_connection *conn, bool first)
{
struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
static atomic_t nexttoken = ATOMIC_INIT(0);
int rc;
if (!conn->lgr->is_smcd) {
rc = smcr_lgr_conn_assign_link(conn, first);
if (rc) {
conn->lgr = NULL;
return rc;
}
}
/* find a new alert_token_local value not yet used by some connection
* in this link group
*/
sock_hold(&smc->sk); /* sock_put in smc_lgr_unregister_conn() */
while (!conn->alert_token_local) {
conn->alert_token_local = atomic_inc_return(&nexttoken);
if (smc_lgr_find_conn(conn->alert_token_local, conn->lgr))
conn->alert_token_local = 0;
}
smc_lgr_add_alert_token(conn);
conn->lgr->conns_num++;
return 0;
}
/* Unregister connection and reset the alert token of the given connection<
*/
static void __smc_lgr_unregister_conn(struct smc_connection *conn)
{
struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
struct smc_link_group *lgr = conn->lgr;
rb_erase(&conn->alert_node, &lgr->conns_all);
if (conn->lnk)
atomic_dec(&conn->lnk->conn_cnt);
lgr->conns_num--;
conn->alert_token_local = 0;
sock_put(&smc->sk); /* sock_hold in smc_lgr_register_conn() */
}
/* Unregister connection from lgr
*/
static void smc_lgr_unregister_conn(struct smc_connection *conn)
{
struct smc_link_group *lgr = conn->lgr;
if (!smc_conn_lgr_valid(conn))
return;
write_lock_bh(&lgr->conns_lock);
if (conn->alert_token_local) {
__smc_lgr_unregister_conn(conn);
}
write_unlock_bh(&lgr->conns_lock);
}
static void smc_lgr_buf_list_add(struct smc_link_group *lgr,
bool is_rmb,
Annotation
- Immediate include surface: `linux/socket.h`, `linux/if_vlan.h`, `linux/random.h`, `linux/workqueue.h`, `linux/wait.h`, `linux/reboot.h`, `linux/mutex.h`, `linux/list.h`.
- Detected declarations: `function smc_ibdev_cnt_inc`, `function smc_ibdev_cnt_dec`, `function smc_lgr_schedule_free_work`, `function smc_lgr_add_alert_token`, `function smcr_lgr_conn_assign_link`, `function smc_lgr_register_conn`, `function __smc_lgr_unregister_conn`, `function smc_lgr_unregister_conn`, `function smc_lgr_buf_list_add`, `function smc_lgr_buf_list_del`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- 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.