drivers/nvme/host/pr.c
Source file repositories/reference/linux-study-clean/drivers/nvme/host/pr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvme/host/pr.c- Extension
.c- Size
- 8582 bytes
- Lines
- 345
- 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.
- 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/blkdev.hlinux/pr.hlinux/unaligned.hnvme.h
Detected Declarations
function Copyrightfunction block_pr_type_from_nvmefunction nvme_send_ns_head_pr_commandfunction nvme_send_ns_pr_commandfunction nvme_status_to_pr_errfunction __nvme_send_pr_commandfunction nvme_send_pr_commandfunction nvme_pr_registerfunction nvme_pr_reservefunction nvme_pr_preemptfunction nvme_pr_clearfunction nvme_pr_releasefunction nvme_pr_resv_reportfunction nvme_pr_read_keysfunction nvme_pr_read_reservation
Annotated Snippet
if (eds) {
keys_info->keys[i] =
le64_to_cpu(rse->regctl_eds[i].rkey);
} else {
struct nvme_reservation_status *rs;
rs = (struct nvme_reservation_status *)rse;
keys_info->keys[i] = le64_to_cpu(rs->regctl_ds[i].rkey);
}
}
free_rse:
kvfree(rse);
return ret;
}
static int nvme_pr_read_reservation(struct block_device *bdev,
struct pr_held_reservation *resv)
{
struct nvme_reservation_status_ext tmp_rse, *rse;
int ret, i, num_regs;
u32 rse_len;
bool eds;
get_num_regs:
/*
* Get the number of registrations so we know how big to allocate
* the response buffer.
*/
ret = nvme_pr_resv_report(bdev, &tmp_rse, sizeof(tmp_rse), &eds);
if (ret)
return ret;
num_regs = get_unaligned_le16(&tmp_rse.regctl);
if (!num_regs) {
resv->generation = le32_to_cpu(tmp_rse.gen);
return 0;
}
rse_len = struct_size(rse, regctl_eds, num_regs);
rse = kzalloc(rse_len, GFP_KERNEL);
if (!rse)
return -ENOMEM;
ret = nvme_pr_resv_report(bdev, rse, rse_len, &eds);
if (ret)
goto free_rse;
if (num_regs != get_unaligned_le16(&rse->regctl)) {
kfree(rse);
goto get_num_regs;
}
resv->generation = le32_to_cpu(rse->gen);
resv->type = block_pr_type_from_nvme(rse->rtype);
for (i = 0; i < num_regs; i++) {
if (eds) {
if (rse->regctl_eds[i].rcsts) {
resv->key = le64_to_cpu(rse->regctl_eds[i].rkey);
break;
}
} else {
struct nvme_reservation_status *rs;
rs = (struct nvme_reservation_status *)rse;
if (rs->regctl_ds[i].rcsts) {
resv->key = le64_to_cpu(rs->regctl_ds[i].rkey);
break;
}
}
}
free_rse:
kfree(rse);
return ret;
}
const struct pr_ops nvme_pr_ops = {
.pr_register = nvme_pr_register,
.pr_reserve = nvme_pr_reserve,
.pr_release = nvme_pr_release,
.pr_preempt = nvme_pr_preempt,
.pr_clear = nvme_pr_clear,
.pr_read_keys = nvme_pr_read_keys,
.pr_read_reservation = nvme_pr_read_reservation,
};
Annotation
- Immediate include surface: `linux/blkdev.h`, `linux/pr.h`, `linux/unaligned.h`, `nvme.h`.
- Detected declarations: `function Copyright`, `function block_pr_type_from_nvme`, `function nvme_send_ns_head_pr_command`, `function nvme_send_ns_pr_command`, `function nvme_status_to_pr_err`, `function __nvme_send_pr_command`, `function nvme_send_pr_command`, `function nvme_pr_register`, `function nvme_pr_reserve`, `function nvme_pr_preempt`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: source implementation candidate.
- 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.