drivers/scsi/scsi_logging.c
Source file repositories/reference/linux-study-clean/drivers/scsi/scsi_logging.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/scsi_logging.c- Extension
.c- Size
- 11446 bytes
- Lines
- 439
- 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.
- 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/kernel.hlinux/atomic.hscsi/scsi.hscsi/scsi_cmnd.hscsi/scsi_device.hscsi/scsi_eh.hscsi/scsi_dbg.h
Detected Declarations
function Copyrightfunction scsi_log_release_bufferfunction sdev_format_headerfunction sdev_prefix_printkfunction scmd_printkfunction scsi_format_opcode_namefunction __scsi_format_commandfunction scsi_print_commandfunction scsi_format_extd_sensefunction scsi_format_sense_hdrfunction scsi_log_dump_sensefunction scsi_log_print_sense_hdrfunction scsi_log_print_sensefunction scsi_print_sense_hdrfunction __scsi_print_sensefunction scsi_print_sensefunction scsi_print_resultexport sdev_prefix_printkexport scmd_printkexport __scsi_format_commandexport scsi_print_commandexport scsi_print_sense_hdrexport __scsi_print_senseexport scsi_print_senseexport scsi_print_result
Annotated Snippet
if (len < 10) {
off = scnprintf(buffer, buf_len,
"short variable length command, len=%d",
len);
return off;
}
sa = (cdbp[8] << 8) + cdbp[9];
} else
sa = cdbp[1] & 0x1f;
if (!scsi_opcode_sa_name(cdb0, sa, &cdb_name, &sa_name)) {
if (cdb_name)
off = scnprintf(buffer, buf_len, "%s", cdb_name);
else {
off = scnprintf(buffer, buf_len, "opcode=0x%x", cdb0);
if (WARN_ON(off >= buf_len))
return off;
if (cdb0 >= VENDOR_SPECIFIC_CDB)
off += scnprintf(buffer + off, buf_len - off,
" (vendor)");
else if (cdb0 >= 0x60 && cdb0 < 0x7e)
off += scnprintf(buffer + off, buf_len - off,
" (reserved)");
}
} else {
if (sa_name)
off = scnprintf(buffer, buf_len, "%s", sa_name);
else if (cdb_name)
off = scnprintf(buffer, buf_len, "%s, sa=0x%x",
cdb_name, sa);
else
off = scnprintf(buffer, buf_len,
"opcode=0x%x, sa=0x%x", cdb0, sa);
}
WARN_ON(off >= buf_len);
return off;
}
size_t __scsi_format_command(char *logbuf, size_t logbuf_len,
const unsigned char *cdb, size_t cdb_len)
{
int len, k;
size_t off;
off = scsi_format_opcode_name(logbuf, logbuf_len, cdb);
if (off >= logbuf_len)
return off;
len = scsi_command_size(cdb);
if (cdb_len < len)
len = cdb_len;
/* print out all bytes in cdb */
for (k = 0; k < len; ++k) {
if (off > logbuf_len - 3)
break;
off += scnprintf(logbuf + off, logbuf_len - off,
" %02x", cdb[k]);
}
return off;
}
EXPORT_SYMBOL(__scsi_format_command);
void scsi_print_command(struct scsi_cmnd *cmd)
{
int k;
char *logbuf;
size_t off, logbuf_len;
logbuf = scsi_log_reserve_buffer(&logbuf_len);
if (!logbuf)
return;
off = sdev_format_header(logbuf, logbuf_len,
scmd_name(cmd), scsi_cmd_to_rq(cmd)->tag);
if (off >= logbuf_len)
goto out_printk;
off += scnprintf(logbuf + off, logbuf_len - off, "CDB: ");
if (WARN_ON(off >= logbuf_len))
goto out_printk;
off += scsi_format_opcode_name(logbuf + off, logbuf_len - off,
cmd->cmnd);
if (off >= logbuf_len)
goto out_printk;
/* print out all bytes in cdb */
if (cmd->cmd_len > 16) {
/* Print opcode in one line and use separate lines for CDB */
off += scnprintf(logbuf + off, logbuf_len - off, "\n");
dev_printk(KERN_INFO, &cmd->device->sdev_gendev, "%s", logbuf);
for (k = 0; k < cmd->cmd_len; k += 16) {
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/atomic.h`, `scsi/scsi.h`, `scsi/scsi_cmnd.h`, `scsi/scsi_device.h`, `scsi/scsi_eh.h`, `scsi/scsi_dbg.h`.
- Detected declarations: `function Copyright`, `function scsi_log_release_buffer`, `function sdev_format_header`, `function sdev_prefix_printk`, `function scmd_printk`, `function scsi_format_opcode_name`, `function __scsi_format_command`, `function scsi_print_command`, `function scsi_format_extd_sense`, `function scsi_format_sense_hdr`.
- Atlas domain: Driver Families / drivers/scsi.
- Implementation status: integration 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.