net/smc/smc_pnet.c
Source file repositories/reference/linux-study-clean/net/smc/smc_pnet.c
File Facts
- System
- Linux kernel
- Corpus path
net/smc/smc_pnet.c- Extension
.c- Size
- 31487 bytes
- Lines
- 1224
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/module.hlinux/list.hlinux/ctype.hlinux/mutex.hnet/netlink.hnet/genetlink.huapi/linux/if.huapi/linux/smc.hrdma/ib_verbs.hnet/netns/generic.hsmc_netns.hsmc_pnet.hsmc_ib.hsmc_ism.hsmc_core.h
Detected Declarations
struct smc_pnetentryenum smc_pnet_nametypefunction smc_pnet_is_pnetid_setfunction smc_pnet_matchfunction smc_pnet_remove_by_pnetidfunction smc_pnet_add_by_ndevfunction smc_pnet_remove_by_ndevfunction smc_pnet_apply_ibfunction smc_pnet_apply_smcdfunction befunction smc_pnet_add_ethfunction smc_pnet_add_ibfunction smc_pnet_enterfunction smc_pnet_set_nlafunction smc_pnet_addfunction smc_pnet_delfunction smc_pnet_dump_startfunction smc_pnet_dumpinfofunction _smc_pnet_dumpfunction smc_pnet_dumpfunction smc_pnet_getfunction smc_pnet_flushfunction smc_pnet_is_ndev_pnetidfunction smc_pnet_add_pnetidfunction smc_pnet_remove_pnetidfunction smc_pnet_add_base_pnetidfunction smc_pnet_create_pnetids_listfunction smc_pnet_destroy_pnetids_listfunction smc_pnet_netdev_eventfunction smc_pnet_net_initfunction smc_pnet_initfunction smc_pnet_net_exitfunction smc_pnet_exitfunction smc_pnet_find_ndev_pnetid_by_tablefunction smc_pnet_determine_gidfunction _smc_pnet_find_roce_by_pnetidfunction smc_pnet_find_alt_rocefunction smc_pnet_find_rdma_devfunction smc_pnet_find_roce_by_pnetidfunction smc_pnet_find_ndev_pnetid_by_tablefunction smc_pnet_find_ism_by_pnetidfunction smc_pnet_find_roce_resourcefunction smc_pnet_find_ism_resourcefunction smc_pnetid_by_table_ibfunction smc_pnetid_by_table_smcd
Annotated Snippet
struct smc_pnetentry {
struct list_head list;
char pnet_name[SMC_MAX_PNETID_LEN + 1];
enum smc_pnet_nametype type;
union {
struct {
char eth_name[IFNAMSIZ + 1];
struct net_device *ndev;
netdevice_tracker dev_tracker;
};
struct {
char ib_name[IB_DEVICE_NAME_MAX + 1];
u8 ib_port;
};
};
};
/* Check if the pnetid is set */
bool smc_pnet_is_pnetid_set(u8 *pnetid)
{
if (pnetid[0] == 0 || pnetid[0] == _S)
return false;
return true;
}
/* Check if two given pnetids match */
static bool smc_pnet_match(u8 *pnetid1, u8 *pnetid2)
{
int i;
for (i = 0; i < SMC_MAX_PNETID_LEN; i++) {
if ((pnetid1[i] == 0 || pnetid1[i] == _S) &&
(pnetid2[i] == 0 || pnetid2[i] == _S))
break;
if (pnetid1[i] != pnetid2[i])
return false;
}
return true;
}
/* Remove a pnetid from the pnet table.
*/
static int smc_pnet_remove_by_pnetid(struct net *net, char *pnet_name)
{
struct smc_pnetentry *pnetelem, *tmp_pe;
struct smc_pnettable *pnettable;
struct smc_ib_device *ibdev;
struct smcd_dev *smcd;
struct smc_net *sn;
int rc = -ENOENT;
int ibport;
/* get pnettable for namespace */
sn = net_generic(net, smc_net_id);
pnettable = &sn->pnettable;
/* remove table entry */
mutex_lock(&pnettable->lock);
list_for_each_entry_safe(pnetelem, tmp_pe, &pnettable->pnetlist,
list) {
if (!pnet_name ||
smc_pnet_match(pnetelem->pnet_name, pnet_name)) {
list_del(&pnetelem->list);
if (pnetelem->type == SMC_PNET_ETH && pnetelem->ndev) {
netdev_put(pnetelem->ndev,
&pnetelem->dev_tracker);
pr_warn_ratelimited("smc: net device %s "
"erased user defined "
"pnetid %.16s\n",
pnetelem->eth_name,
pnetelem->pnet_name);
}
kfree(pnetelem);
rc = 0;
}
}
mutex_unlock(&pnettable->lock);
/* if this is not the initial namespace, stop here */
if (net != &init_net)
return rc;
/* remove ib devices */
mutex_lock(&smc_ib_devices.mutex);
list_for_each_entry(ibdev, &smc_ib_devices.list, list) {
for (ibport = 0; ibport < SMC_MAX_PORTS; ibport++) {
if (ibdev->pnetid_by_user[ibport] &&
(!pnet_name ||
smc_pnet_match(pnet_name,
ibdev->pnetid[ibport]))) {
Annotation
- Immediate include surface: `linux/module.h`, `linux/list.h`, `linux/ctype.h`, `linux/mutex.h`, `net/netlink.h`, `net/genetlink.h`, `uapi/linux/if.h`, `uapi/linux/smc.h`.
- Detected declarations: `struct smc_pnetentry`, `enum smc_pnet_nametype`, `function smc_pnet_is_pnetid_set`, `function smc_pnet_match`, `function smc_pnet_remove_by_pnetid`, `function smc_pnet_add_by_ndev`, `function smc_pnet_remove_by_ndev`, `function smc_pnet_apply_ib`, `function smc_pnet_apply_smcd`, `function be`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.