drivers/vhost/scsi.c
Source file repositories/reference/linux-study-clean/drivers/vhost/scsi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vhost/scsi.c- Extension
.c- Size
- 77367 bytes
- Lines
- 2994
- Domain
- Driver Families
- Bucket
- drivers/vhost
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/module.hlinux/moduleparam.hgenerated/utsrelease.hlinux/utsname.hlinux/init.hlinux/slab.hlinux/kthread.hlinux/types.hlinux/string.hlinux/configfs.hlinux/ctype.hlinux/compat.hlinux/eventfd.hlinux/fs.hlinux/vmalloc.hlinux/miscdevice.hlinux/blk_types.hlinux/bio.hlinux/unaligned.hscsi/scsi_common.hscsi/scsi_proto.htarget/target_core_base.htarget/target_core_fabric.hlinux/vhost.hlinux/virtio_scsi.hlinux/llist.hlinux/bitmap.hvhost.h
Detected Declarations
struct vhost_scsi_inflightstruct vhost_scsi_cmdstruct vhost_scsi_nexusstruct vhost_scsi_tpgstruct vhost_scsi_tportstruct vhost_scsi_evtstruct vhost_scsi_virtqueuestruct vhost_scsistruct vhost_scsi_tmfstruct vhost_scsi_ctxfunction vhost_scsi_set_inline_sg_cntfunction vhost_scsi_set_inline_sg_cntfunction vhost_scsi_get_inline_sg_cntfunction vhost_scsi_done_inflightfunction vhost_scsi_init_inflightfunction vhost_scsi_get_inflightfunction vhost_scsi_put_inflightfunction vhost_scsi_check_truefunction vhost_scsi_get_tpgtfunction vhost_scsi_check_prot_fabric_onlyfunction vhost_scsi_copy_cmd_logfunction vhost_scsi_log_writefunction vhost_scsi_release_cmd_resfunction for_each_sgtable_sgfunction vhost_scsi_release_tmf_resfunction vhost_scsi_drop_cmdsfunction vhost_scsi_release_cmdfunction vhost_scsi_write_pendingfunction vhost_scsi_queue_data_infunction vhost_scsi_queue_statusfunction vhost_scsi_queue_tm_rspfunction vhost_scsi_aborted_taskfunction vhost_scsi_free_evtfunction vhost_scsi_allocate_evtfunction vhost_scsi_check_stop_freefunction vhost_scsi_do_evt_workfunction vhost_scsi_complete_eventsfunction vhost_scsi_evt_workfunction vhost_scsi_copy_sgl_to_iovfunction for_each_sgtable_sgfunction vhost_scsi_complete_cmd_workfunction llist_for_each_entry_safefunction vhost_scsi_get_cmdfunction vhost_scsi_revert_map_iov_to_sglfunction vhost_scsi_map_to_sglfunction vhost_scsi_calc_sglsfunction vhost_scsi_copy_iov_to_sglfunction for_each_sgtable_sg
Annotated Snippet
static const struct file_operations vhost_scsi_fops = {
.owner = THIS_MODULE,
.release = vhost_scsi_release,
.unlocked_ioctl = vhost_scsi_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.open = vhost_scsi_open,
.llseek = noop_llseek,
};
static struct miscdevice vhost_scsi_misc = {
MISC_DYNAMIC_MINOR,
"vhost-scsi",
&vhost_scsi_fops,
};
static int __init vhost_scsi_register(void)
{
return misc_register(&vhost_scsi_misc);
}
static void vhost_scsi_deregister(void)
{
misc_deregister(&vhost_scsi_misc);
}
static char *vhost_scsi_dump_proto_id(struct vhost_scsi_tport *tport)
{
switch (tport->tport_proto_id) {
case SCSI_PROTOCOL_SAS:
return "SAS";
case SCSI_PROTOCOL_FCP:
return "FCP";
case SCSI_PROTOCOL_ISCSI:
return "iSCSI";
default:
break;
}
return "Unknown";
}
static void
vhost_scsi_do_plug(struct vhost_scsi_tpg *tpg,
struct se_lun *lun, bool plug)
{
struct vhost_scsi *vs = tpg->vhost_scsi;
struct vhost_virtqueue *vq;
u32 reason;
if (!vs)
return;
if (plug)
reason = VIRTIO_SCSI_EVT_RESET_RESCAN;
else
reason = VIRTIO_SCSI_EVT_RESET_REMOVED;
vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq;
mutex_lock(&vq->mutex);
/*
* We can't queue events if the backend has been cleared, because
* we could end up queueing an event after the flush.
*/
if (!vhost_vq_get_backend(vq))
goto unlock;
if (vhost_has_feature(vq, VIRTIO_SCSI_F_HOTPLUG))
vhost_scsi_send_evt(vs, vq, tpg, lun,
VIRTIO_SCSI_T_TRANSPORT_RESET, reason);
unlock:
mutex_unlock(&vq->mutex);
}
static void vhost_scsi_hotplug(struct vhost_scsi_tpg *tpg, struct se_lun *lun)
{
vhost_scsi_do_plug(tpg, lun, true);
}
static void vhost_scsi_hotunplug(struct vhost_scsi_tpg *tpg, struct se_lun *lun)
{
vhost_scsi_do_plug(tpg, lun, false);
}
static int vhost_scsi_port_link(struct se_portal_group *se_tpg,
struct se_lun *lun)
{
struct vhost_scsi_tpg *tpg = container_of(se_tpg,
struct vhost_scsi_tpg, se_tpg);
Annotation
- Immediate include surface: `linux/module.h`, `linux/moduleparam.h`, `generated/utsrelease.h`, `linux/utsname.h`, `linux/init.h`, `linux/slab.h`, `linux/kthread.h`, `linux/types.h`.
- Detected declarations: `struct vhost_scsi_inflight`, `struct vhost_scsi_cmd`, `struct vhost_scsi_nexus`, `struct vhost_scsi_tpg`, `struct vhost_scsi_tport`, `struct vhost_scsi_evt`, `struct vhost_scsi_virtqueue`, `struct vhost_scsi`, `struct vhost_scsi_tmf`, `struct vhost_scsi_ctx`.
- Atlas domain: Driver Families / drivers/vhost.
- Implementation status: pattern 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.