drivers/block/sunvdc.c
Source file repositories/reference/linux-study-clean/drivers/block/sunvdc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/block/sunvdc.c- Extension
.c- Size
- 29210 bytes
- Lines
- 1253
- Domain
- Driver Families
- Bucket
- drivers/block
- 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/kernel.hlinux/types.hlinux/blk-mq.hlinux/hdreg.hlinux/cdrom.hlinux/slab.hlinux/spinlock.hlinux/completion.hlinux/delay.hlinux/init.hlinux/list.hlinux/scatterlist.hasm/vio.hasm/ldc.h
Detected Declarations
struct vdc_req_entrystruct vdc_portstruct vdc_check_port_datafunction vdc_version_supportedfunction vdc_tx_dring_availfunction vdc_getgeofunction vdc_ioctlfunction vdc_blk_queue_startfunction vdc_finishfunction vdc_handshake_completefunction vdc_handle_unknownfunction vdc_send_attrfunction vdc_handle_attrfunction vdc_end_specialfunction vdc_end_onefunction vdc_ackfunction vdc_nackfunction vdc_eventfunction __vdc_tx_triggerfunction __send_requestfunction vdc_queue_rqfunction generic_requestfunction vdc_alloc_tx_ringfunction vdc_free_tx_ringfunction vdc_port_upfunction vdc_port_downfunction probe_diskfunction print_versionfunction vdc_device_probedfunction vdc_port_mpgroup_checkfunction vdc_port_probefunction vdc_port_removefunction vdc_requeue_inflightfunction vdc_queue_drainfunction vdc_ldc_reset_timer_workfunction vdc_ldc_reset_workfunction vdc_ldc_resetfunction vdc_initfunction vdc_exitmodule init vdc_init
Annotated Snippet
static const struct blk_mq_ops vdc_mq_ops = {
.queue_rq = vdc_queue_rq,
};
static int probe_disk(struct vdc_port *port)
{
struct queue_limits lim = {
.physical_block_size = port->vdisk_phys_blksz,
.max_hw_sectors = port->max_xfer_size,
/* Each segment in a request is up to an aligned page in size. */
.seg_boundary_mask = PAGE_SIZE - 1,
.max_segment_size = PAGE_SIZE,
.max_segments = port->ring_cookies,
.features = BLK_FEAT_ROTATIONAL,
};
struct request_queue *q;
struct gendisk *g;
int err;
err = vdc_port_up(port);
if (err)
return err;
/* Using version 1.2 means vdisk_phys_blksz should be set unless the
* disk is reserved by another system.
*/
if (vdc_version_supported(port, 1, 2) && !port->vdisk_phys_blksz)
return -ENODEV;
if (vdc_version_supported(port, 1, 1)) {
/* vdisk_size should be set during the handshake, if it wasn't
* then the underlying disk is reserved by another system
*/
if (port->vdisk_size == -1)
return -ENODEV;
} else {
struct vio_disk_geom geom;
err = generic_request(port, VD_OP_GET_DISKGEOM,
&geom, sizeof(geom));
if (err < 0) {
printk(KERN_ERR PFX "VD_OP_GET_DISKGEOM returns "
"error %d\n", err);
return err;
}
port->vdisk_size = ((u64)geom.num_cyl *
(u64)geom.num_hd *
(u64)geom.num_sec);
}
err = blk_mq_alloc_sq_tag_set(&port->tag_set, &vdc_mq_ops,
VDC_TX_RING_SIZE, 0);
if (err)
return err;
g = blk_mq_alloc_disk(&port->tag_set, &lim, port);
if (IS_ERR(g)) {
printk(KERN_ERR PFX "%s: Could not allocate gendisk.\n",
port->vio.name);
err = PTR_ERR(g);
goto out_free_tag;
}
port->disk = g;
q = g->queue;
g->major = vdc_major;
g->first_minor = port->vio.vdev->dev_no << PARTITION_SHIFT;
g->minors = 1 << PARTITION_SHIFT;
strcpy(g->disk_name, port->disk_name);
g->fops = &vdc_fops;
g->queue = q;
g->private_data = port;
set_capacity(g, port->vdisk_size);
if (vdc_version_supported(port, 1, 1)) {
switch (port->vdisk_mtype) {
case VD_MEDIA_TYPE_CD:
pr_info(PFX "Virtual CDROM %s\n", port->disk_name);
g->flags |= GENHD_FL_REMOVABLE;
set_disk_ro(g, 1);
break;
case VD_MEDIA_TYPE_DVD:
pr_info(PFX "Virtual DVD %s\n", port->disk_name);
g->flags |= GENHD_FL_REMOVABLE;
set_disk_ro(g, 1);
break;
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/types.h`, `linux/blk-mq.h`, `linux/hdreg.h`, `linux/cdrom.h`, `linux/slab.h`, `linux/spinlock.h`.
- Detected declarations: `struct vdc_req_entry`, `struct vdc_port`, `struct vdc_check_port_data`, `function vdc_version_supported`, `function vdc_tx_dring_avail`, `function vdc_getgeo`, `function vdc_ioctl`, `function vdc_blk_queue_start`, `function vdc_finish`, `function vdc_handshake_complete`.
- Atlas domain: Driver Families / drivers/block.
- 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.