drivers/scsi/libfc/fc_npiv.c
Source file repositories/reference/linux-study-clean/drivers/scsi/libfc/fc_npiv.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/libfc/fc_npiv.c- Extension
.c- Size
- 3781 bytes
- Lines
- 148
- Domain
- Driver Families
- Bucket
- drivers/scsi
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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
scsi/libfc.hlinux/export.h
Detected Declarations
enum libfc_lport_mutex_classfunction Copyrightfunction fc_vport_id_lookupfunction __fc_vport_setlinkfunction fc_vport_setlinkfunction fc_vports_linkchangefunction list_for_each_entryexport libfc_vport_createexport fc_vport_id_lookupexport fc_vport_setlink
Annotated Snippet
if (vn_port->port_id == port_id) {
lport = vn_port;
break;
}
}
mutex_unlock(&n_port->lp_mutex);
return lport;
}
EXPORT_SYMBOL(fc_vport_id_lookup);
/*
* When setting the link state of vports during an lport state change, it's
* necessary to hold the lp_mutex of both the N_Port and the VN_Port.
* This tells the lockdep engine to treat the nested locking of the VN_Port
* as a different lock class.
*/
enum libfc_lport_mutex_class {
LPORT_MUTEX_NORMAL = 0,
LPORT_MUTEX_VN_PORT = 1,
};
/**
* __fc_vport_setlink() - update link and status on a VN_Port
* @n_port: parent N_Port
* @vn_port: VN_Port to update
*
* Locking: must be called with both the N_Port and VN_Port lp_mutex held
*/
static void __fc_vport_setlink(struct fc_lport *n_port,
struct fc_lport *vn_port)
{
struct fc_vport *vport = vn_port->vport;
if (vn_port->state == LPORT_ST_DISABLED)
return;
if (n_port->state == LPORT_ST_READY) {
if (n_port->npiv_enabled) {
fc_vport_set_state(vport, FC_VPORT_INITIALIZING);
__fc_linkup(vn_port);
} else {
fc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
__fc_linkdown(vn_port);
}
} else {
fc_vport_set_state(vport, FC_VPORT_LINKDOWN);
__fc_linkdown(vn_port);
}
}
/**
* fc_vport_setlink() - update link and status on a VN_Port
* @vn_port: virtual port to update
*/
void fc_vport_setlink(struct fc_lport *vn_port)
{
struct fc_vport *vport = vn_port->vport;
struct Scsi_Host *shost = vport_to_shost(vport);
struct fc_lport *n_port = shost_priv(shost);
mutex_lock(&n_port->lp_mutex);
mutex_lock_nested(&vn_port->lp_mutex, LPORT_MUTEX_VN_PORT);
__fc_vport_setlink(n_port, vn_port);
mutex_unlock(&vn_port->lp_mutex);
mutex_unlock(&n_port->lp_mutex);
}
EXPORT_SYMBOL(fc_vport_setlink);
/**
* fc_vports_linkchange() - change the link state of all vports
* @n_port: Parent N_Port that has changed state
*
* Locking: called with the n_port lp_mutex held
*/
void fc_vports_linkchange(struct fc_lport *n_port)
{
struct fc_lport *vn_port;
list_for_each_entry(vn_port, &n_port->vports, list) {
mutex_lock_nested(&vn_port->lp_mutex, LPORT_MUTEX_VN_PORT);
__fc_vport_setlink(n_port, vn_port);
mutex_unlock(&vn_port->lp_mutex);
}
}
Annotation
- Immediate include surface: `scsi/libfc.h`, `linux/export.h`.
- Detected declarations: `enum libfc_lport_mutex_class`, `function Copyright`, `function fc_vport_id_lookup`, `function __fc_vport_setlink`, `function fc_vport_setlink`, `function fc_vports_linkchange`, `function list_for_each_entry`, `export libfc_vport_create`, `export fc_vport_id_lookup`, `export fc_vport_setlink`.
- Atlas domain: Driver Families / drivers/scsi.
- 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.