drivers/scsi/sd_zbc.c
Source file repositories/reference/linux-study-clean/drivers/scsi/sd_zbc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/sd_zbc.c- Extension
.c- Size
- 17899 bytes
- Lines
- 642
- Domain
- Driver Families
- Bucket
- drivers/scsi
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/blkdev.hlinux/vmalloc.hlinux/sched/mm.hlinux/mutex.hlinux/unaligned.hscsi/scsi.hscsi/scsi_cmnd.hsd.hsd_trace.h
Detected Declarations
function Copyrightfunction sd_zbc_report_zonesfunction sd_zbc_do_report_zonesfunction sd_zbc_alloc_report_bufferfunction sd_zbc_zone_sectorsfunction sd_zbc_report_zonesfunction sd_zbc_cmnd_checksfunction sd_init_commandfunction sd_donefunction sd_zbc_check_zoned_characteristicsfunction readsfunction valuefunction sd_zbc_print_zonesfunction blk_revalidate_disk_zonesfunction sd_zbc_read_zones
Annotated Snippet
if (zone.len > gran) {
sd_printk(KERN_ERR, sdkp,
"Invalid zone at LBA %llu with capacity %llu and length %llu; granularity = %llu\n",
start_lba,
sectors_to_logical(sdp, zone.capacity),
sectors_to_logical(sdp, zone.len),
sectors_to_logical(sdp, gran));
return -EINVAL;
}
/*
* Use the starting LBA granularity instead of the zone length
* obtained from the REPORT ZONES command.
*/
zone.len = gran;
}
if (zone.cond == ZBC_ZONE_COND_FULL)
zone.wp = zone.start + zone.len;
else
zone.wp = logical_to_sectors(sdp, get_unaligned_be64(&buf[24]));
return disk_report_zone(sdkp->disk, &zone, idx, args);
}
/**
* sd_zbc_do_report_zones - Issue a REPORT ZONES scsi command.
* @sdkp: The target disk
* @buf: vmalloc-ed buffer to use for the reply
* @buflen: the buffer size
* @lba: Start LBA of the report
* @partial: Do partial report
*
* For internal use during device validation.
* Using partial=true can significantly speed up execution of a report zones
* command because the disk does not have to count all possible report matching
* zones and will only report the count of zones fitting in the command reply
* buffer.
*/
static int sd_zbc_do_report_zones(struct scsi_disk *sdkp, unsigned char *buf,
unsigned int buflen, sector_t lba,
bool partial)
{
struct scsi_device *sdp = sdkp->device;
const int timeout = sdp->request_queue->rq_timeout;
struct scsi_sense_hdr sshdr;
const struct scsi_exec_args exec_args = {
.sshdr = &sshdr,
};
unsigned char cmd[16];
unsigned int rep_len;
int result;
memset(cmd, 0, 16);
cmd[0] = ZBC_IN;
cmd[1] = ZI_REPORT_ZONES;
put_unaligned_be64(lba, &cmd[2]);
put_unaligned_be32(buflen, &cmd[10]);
if (partial)
cmd[14] = ZBC_REPORT_ZONE_PARTIAL;
result = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, buf, buflen,
timeout, SD_MAX_RETRIES, &exec_args);
if (result) {
sd_printk(KERN_ERR, sdkp,
"REPORT ZONES start lba %llu failed\n", lba);
sd_print_result(sdkp, "REPORT ZONES", result);
if (result > 0 && scsi_sense_valid(&sshdr))
sd_print_sense_hdr(sdkp, &sshdr);
return -EIO;
}
rep_len = get_unaligned_be32(&buf[0]);
if (rep_len < 64) {
sd_printk(KERN_ERR, sdkp,
"REPORT ZONES report invalid length %u\n",
rep_len);
return -EIO;
}
return 0;
}
/**
* sd_zbc_alloc_report_buffer() - Allocate a buffer for report zones reply.
* @sdkp: The target disk
* @nr_zones: Maximum number of zones to report
* @buflen: Size of the buffer allocated
*
* Try to allocate a reply buffer for the number of requested zones.
* The size of the buffer allocated may be smaller than requested to
* satify the device constraint (max_hw_sectors, max_segments, etc).
Annotation
- Immediate include surface: `linux/blkdev.h`, `linux/vmalloc.h`, `linux/sched/mm.h`, `linux/mutex.h`, `linux/unaligned.h`, `scsi/scsi.h`, `scsi/scsi_cmnd.h`, `sd.h`.
- Detected declarations: `function Copyright`, `function sd_zbc_report_zones`, `function sd_zbc_do_report_zones`, `function sd_zbc_alloc_report_buffer`, `function sd_zbc_zone_sectors`, `function sd_zbc_report_zones`, `function sd_zbc_cmnd_checks`, `function sd_init_command`, `function sd_done`, `function sd_zbc_check_zoned_characteristics`.
- Atlas domain: Driver Families / drivers/scsi.
- Implementation status: source implementation candidate.
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.