drivers/nvme/target/io-cmd-bdev.c
Source file repositories/reference/linux-study-clean/drivers/nvme/target/io-cmd-bdev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvme/target/io-cmd-bdev.c- Extension
.c- Size
- 12241 bytes
- Lines
- 476
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: implementation source
- Status
- source implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/blkdev.hlinux/blk-integrity.hlinux/memremap.hlinux/module.hnvmet.h
Detected Declarations
function Copyrightfunction nvmet_bdev_set_nvm_limitsfunction nvmet_bdev_ns_disablefunction nvmet_bdev_ns_enable_integrityfunction nvmet_bdev_ns_enablefunction nvmet_bdev_ns_revalidatefunction blk_to_nvme_statusfunction codefunction nvmet_bio_donefunction nvmet_bdev_alloc_bipfunction nvmet_bdev_alloc_bipfunction nvmet_bdev_execute_rwfunction for_each_sgfunction nvmet_bdev_execute_flushfunction nvmet_bdev_flushfunction nvmet_bdev_execute_discardfunction nvmet_bdev_execute_dsmfunction nvmet_bdev_execute_write_zeroesfunction nvmet_bdev_parse_io_cmd
Annotated Snippet
if (ret != -ENOTBLK) {
pr_err("failed to open block device %s: (%d)\n",
ns->device_path, ret);
}
ns->bdev_file = NULL;
return ret;
}
ns->bdev = file_bdev(ns->bdev_file);
ns->size = bdev_nr_bytes(ns->bdev);
ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev));
ns->pi_type = 0;
ns->metadata_size = 0;
if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY))
nvmet_bdev_ns_enable_integrity(ns);
if (bdev_is_zoned(ns->bdev)) {
if (!nvmet_bdev_zns_enable(ns)) {
nvmet_bdev_ns_disable(ns);
return -EINVAL;
}
ns->csi = NVME_CSI_ZNS;
}
return 0;
}
void nvmet_bdev_ns_revalidate(struct nvmet_ns *ns)
{
ns->size = bdev_nr_bytes(ns->bdev);
}
u16 blk_to_nvme_status(struct nvmet_req *req, blk_status_t blk_sts)
{
u16 status = NVME_SC_SUCCESS;
if (likely(blk_sts == BLK_STS_OK))
return status;
/*
* Right now there exists M : 1 mapping between block layer error
* to the NVMe status code (see nvme_error_status()). For consistency,
* when we reverse map we use most appropriate NVMe Status code from
* the group of the NVMe status codes used in the nvme_error_status().
*/
switch (blk_sts) {
case BLK_STS_NOSPC:
status = NVME_SC_CAP_EXCEEDED | NVME_STATUS_DNR;
req->error_loc = offsetof(struct nvme_rw_command, length);
break;
case BLK_STS_TARGET:
status = NVME_SC_LBA_RANGE | NVME_STATUS_DNR;
req->error_loc = offsetof(struct nvme_rw_command, slba);
break;
case BLK_STS_NOTSUPP:
status = NVME_SC_INVALID_OPCODE | NVME_STATUS_DNR;
req->error_loc = offsetof(struct nvme_common_command, opcode);
break;
case BLK_STS_MEDIUM:
status = NVME_SC_ACCESS_DENIED;
req->error_loc = offsetof(struct nvme_rw_command, nsid);
break;
case BLK_STS_IOERR:
default:
status = NVME_SC_INTERNAL | NVME_STATUS_DNR;
req->error_loc = offsetof(struct nvme_common_command, opcode);
}
switch (req->cmd->common.opcode) {
case nvme_cmd_read:
case nvme_cmd_write:
req->error_slba = le64_to_cpu(req->cmd->rw.slba);
break;
case nvme_cmd_write_zeroes:
req->error_slba =
le64_to_cpu(req->cmd->write_zeroes.slba);
break;
default:
req->error_slba = 0;
}
return status;
}
static void nvmet_bio_done(struct bio *bio)
{
struct nvmet_req *req = bio->bi_private;
blk_status_t blk_status = bio->bi_status;
nvmet_req_bio_put(req, bio);
nvmet_req_complete(req, blk_to_nvme_status(req, blk_status));
}
Annotation
- Immediate include surface: `linux/blkdev.h`, `linux/blk-integrity.h`, `linux/memremap.h`, `linux/module.h`, `nvmet.h`.
- Detected declarations: `function Copyright`, `function nvmet_bdev_set_nvm_limits`, `function nvmet_bdev_ns_disable`, `function nvmet_bdev_ns_enable_integrity`, `function nvmet_bdev_ns_enable`, `function nvmet_bdev_ns_revalidate`, `function blk_to_nvme_status`, `function code`, `function nvmet_bio_done`, `function nvmet_bdev_alloc_bip`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- 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.